Subject: [PATCH] [BZ 122927] dbginfo.sh: Extend data collection for libvirt and multipath
From: Sa Liu <saliu@de.ibm.com>

Description:  dbginfo.sh: Extend data collection for libvirt and multipath 
Symptom:      This update covers various symptoms on dbginfo.sh data 
              collection:
              - There is no data collected for libvirt
              - The data collected for multipath does not cover current states
              - Error message occurs when loading vmcp module
              - dbginfo.sh doesn't collect trace_pipes correctly but clears
                the trace_pipe after exection
Problem:      Following problems exist:
              - No analysis is possible for libvirt files
              - Missing current state data of multipath 
              - Confusing error messages
              - trace_pipes data corruption 
Solution:     - Extend the data collection to collect libvirt information:
                - /etc/libvirt
                - /var/log/libvirt
                The files in the directory /etc/libvirt/qemu can contain
                passwords. Therefore a postprocessing has been introduced
                to replace the passwords with asterisks.
              - Add commands to collect the current state data of multipath
              - Avoid loading the vmcp module in case it is built-in, to avoid
                a confusing error message.
              - Ignore trace_pipes from sysfs collection.
Reproduction: Run this script and verify the output
Upstream-ID:  -
Problem-ID:   122927

Signed-off-by: Sa Liu <saliu@de.ibm.com>
---
 scripts/dbginfo.sh   |  117 ++++++++++++++++++++++++++++++++++++---------------
 scripts/dbginfo.sh.1 |   22 +++++----
 2 files changed, 95 insertions(+), 44 deletions(-)

--- a/scripts/dbginfo.sh
+++ b/scripts/dbginfo.sh
@@ -2,7 +2,7 @@
 #
 # dbginfo.sh - Tool to collect runtime, configuration, and trace information
 #
-# Copyright IBM Corp. 2002, 2014
+# Copyright IBM Corp. 2002, 2015
 #
 
 # Switching to neutral locale
@@ -18,7 +18,7 @@ readonly SCRIPTNAME="${0##*/}"
 print_version() {
     cat <<EOF
 ${SCRIPTNAME}: Debug information script version %S390_TOOLS_VERSION%
-Copyright IBM Corp. 2002, 2014
+Copyright IBM Corp. 2002, 2015
 EOF
 }
 
@@ -51,10 +51,10 @@ identification.
 
 Options:
 
-        -d|--directory     specify the directory where the data collection
-                           stores the temporary data and the final archive.
-        -h|--help          print this help
-        -v|--version       print version information
+	-d|--directory     specify the directory where the data collection
+			   stores the temporary data and the final archive.
+	-h|--help          print this help
+	-v|--version       print version information
 
 
 Please report bugs to: linux390@de.ibm.com
@@ -77,25 +77,25 @@ paramWORKDIR_BASE="/tmp/"
 
 while [ ${#} -gt 0 ]; do
     case ${1} in
-        --help|-h)
-            print_usage
-            exit 0
-            ;;
-        --version|-v)
-            print_version
-            exit 0
-            ;;
-        --directory|-d)
-            paramWORKDIR_BASE=${2}
-            shift
-            ;;
-        -*|--*|*)
-            echo
-            echo "${SCRIPTNAME}: invalid option \"${1}\""
-            echo "Try '${SCRIPTNAME} --help' for more information"
-            echo
-            exit 1
-            ;;
+	--help|-h)
+	    print_usage
+	    exit 0
+	    ;;
+	--version|-v)
+	    print_version
+	    exit 0
+	    ;;
+	--directory|-d)
+	    paramWORKDIR_BASE=${2}
+	    shift
+	    ;;
+	-*|--*|*)
+	    echo
+	    echo "${SCRIPTNAME}: invalid option \"${1}\""
+	    echo "Try '${SCRIPTNAME} --help' for more information"
+	    echo
+	    exit 1
+	    ;;
     esac
     shift
 done
@@ -175,7 +175,7 @@ readonly OUTPUT_FILE_JOURNALCTL="${WORKP
 readonly MOUNT_POINT_DEBUGFS="/sys/kernel/debug"
 
 # The amount of steps running the whole collections
-readonly COLLECTION_COUNT=7
+readonly COLLECTION_COUNT=8
 
 # The kernel version (e.g. '2' from 2.6.32 or '3' from 3.2.1)
 readonly KERNEL_VERSION=$(uname -r 2>/dev/null | cut -d'.' -f1)
@@ -271,8 +271,8 @@ fi
 if test "${LINUX_SUPPORT_SYSFSDBF}" -eq 1; then
     if test -e /proc/s390dbf; then
 	PROCFILES="${PROCFILES}\
-          $(find /proc/s390dbf -type f -not -path "*/raw" -not -path "*/flush" 2>/dev/null)\
-          "
+	  $(find /proc/s390dbf -type f -not -path "*/raw" -not -path "*/flush" 2>/dev/null)\
+	  "
     fi
 fi
 
@@ -287,6 +287,7 @@ LOGFILES="\
   /var/log/dracut.log*\
   /var/log/IBMtape.trace\
   /var/log/IBMtape.errorlog\
+  /var/log/libvirt\
   /var/log/lin_tape.trace\
   /var/log/lin_tape.errorlog\
   /var/log/messages*\
@@ -297,20 +298,26 @@ LOGFILES="\
 ########################################
 
 CONFIGFILES="\
+  /boot/grub2/grub.cfg\
+  /boot/zipl/active_devices.txt\
+  /boot/zipl/config\
   /etc/*.conf\
   /etc/anacrontab\
   /etc/auto.*\
   /etc/cron.*\
   /etc/crontab\
   /etc/crypttab\
+  /etc/default\
   /etc/depmod.d\
   /etc/dracut.conf.d\
   /etc/exports\
   /etc/fstab\
   /etc/groups\
+  /etc/grub.d\
   /etc/hosts*\
   /etc/iscsi\
   /etc/inittab\
+  /etc/libvirt\
   /etc/logrotate.d\
   /etc/lvm\
   /etc/modprobe.conf*\
@@ -366,6 +373,16 @@ CMDS="uname -a\
   :dmsetup table\
   :dmsetup table --target multipath\
   :dmsetup status\
+  :multipathd -k'show config'\
+  :multipathd -k'show maps'\
+  :multipathd -k'show topo'\
+  :multipathd -k'show paths'\
+  :multipathd -k'show maps stats'\
+  :multipathd -k'show maps status'\
+  :multipathd -k'show status'\
+  :multipathd -k'show daemon'\
+  :multipathd -k'show blacklist'\
+  :multipathd -k'show devices'\
   :multipath -v6 -ll\
   :multipath -d\
   :multipath -t\
@@ -503,7 +520,7 @@ collect_vmcmdsout() {
 
 	if which vmcp >/dev/null 2>&1; then
 	    cp_command="vmcp"
-	    if ! lsmod 2>/dev/null | grep -q vmcp; then
+	    if ! lsmod 2>/dev/null | grep -q vmcp && modinfo vmcp >/dev/null 2>&1; then
 		modprobe vmcp && module_loaded=0 && sleep 2
 	    fi
 	elif which hcp >/dev/null 2>&1; then
@@ -568,8 +585,8 @@ collect_procfs() {
 ########################################
 collect_sysfs() {
     local debugfs_mounted=0
+    local dir_name
     local file_name
-    local file_names
     local rc_mount
 
     # Requires kernel version newer then 2.4
@@ -593,7 +610,9 @@ collect_sysfs() {
 	    mkdir -p "${WORKPATH}${dir_name}"
 	done
 
-	find /sys -noleaf -type f -perm /444 2>/dev/null | while IFS= read -r file_name; do
+	find /sys -noleaf -type f -perm /444\
+		  -a -not -name "*trace_pipe*"\
+		  2>/dev/null | while IFS= read -r file_name; do
 	    echo " ${file_name}"
 	    if ! dd if="${file_name}" status=noxfer iflag=nonblock of="${WORKPATH}${file_name}" >/dev/null 2>&1; then
 		echo "${SCRIPTNAME}: Warning: failed to copy \"${file_name}\""
@@ -663,6 +682,34 @@ collect_osaoat() {
 
 
 ########################################
+post_processing() {
+    local file_mtime
+    local file_mtime_epoche
+    local tmp_file
+    local file_name
+
+    pr_syslog_stdout "8 of ${COLLECTION_COUNT}: Postprocessing"
+
+    find "${WORKPATH}etc/libvirt/qemu/" -maxdepth 1 -name "*.xml" 2>/dev/null | while IFS= read -r file_name; do
+	file_mtime_epoche=$(stat --format=%Y "${file_name}")
+	file_mtime=$(date +%Y%m%d%H%M.%S --date="@${file_mtime_epoche}")
+	tmp_file=${file_name}.$$
+
+	echo " ${file_name}"
+	if ! sed "s/\( \+passwd='\).*\('\)/\1********\2/g" "${file_name}" > "${tmp_file}"; then
+	    echo "${SCRIPTNAME}: Warning: Postprocessing failed on ${file_name}"
+	    echo
+	fi
+
+	mv "${tmp_file}" "${file_name}"
+	touch --time=mtime -t "${file_mtime}" "${file_name}"
+    done
+
+    pr_log_stdout " "
+}
+
+
+########################################
 # Be aware that this output must be
 # redirected into a separate logfile
 call_run_command() {
@@ -675,7 +722,7 @@ call_run_command() {
 
     # check if command exists
     if ! which "${raw_cmd}" >/dev/null 2>&1; then
-        # check if command is a builtin
+	# check if command is a builtin
 	if ! command -v "${raw_cmd}" >/dev/null 2>&1; then
 	    echo "${SCRIPTNAME}: Warning: Command \"${raw_cmd}\" not available" >> "${logfile}"
 	    echo >> "${logfile}"
@@ -745,10 +792,10 @@ environment_setup()
 
     if test -e "${LOCKFILE}"; then
 	print_alreadyrunning
-        exit 1
+	exit 1
     else
 	touch "${LOCKFILE}"
-        echo "${DATETIME}" > "${LOCKFILE}"
+	echo "${DATETIME}" > "${LOCKFILE}"
     fi
 
     if ! mkdir "${WORKPATH}" 2>/dev/null; then
@@ -880,6 +927,8 @@ collect_configfiles
 
 collect_osaoat
 
+post_processing
+
 create_package
 
 environment_cleanup
--- a/scripts/dbginfo.sh.1
+++ b/scripts/dbginfo.sh.1
@@ -1,4 +1,4 @@
-.TH DBGINFO.SH  1 "October 2013" "s390-tools"
+.TH DBGINFO.SH  1 "February 2015" "s390-tools"
 
 .SH NAME
 dbginfo.sh \- collect runtime, configuration and trace information
@@ -52,7 +52,7 @@ Sample invocation:
 .br
 dbginfo.sh: Debug information script version %S390_TOOLS_VERSION%
 .br
-Copyright IBM Corp. 2002, 2013
+Copyright IBM Corp. 2002, 2015
 .PP
 Hardware platform     = s390x
 .br
@@ -60,25 +60,27 @@ Kernel version        = <kernel\-version
 .br
 Runtime environment   = z/VM
 .PP
-1 of 7: Collecting command output
+1 of 8: Collecting command output
 .PP
-2 of 7: Collecting z/VM command output
+2 of 8: Collecting z/VM command output
 .PP
-3 of 7: Collecting procfs
+3 of 8: Collecting procfs
 .PP
-4 of 7: Collecting sysfs
+4 of 8: Collecting sysfs
 .PP
-5 of 7: Collecting log files
+5 of 8: Collecting log files
 .PP
-6 of 7: Collecting config files
+6 of 8: Collecting config files
 .PP
-7 of 7: Collecting osa oat output skipped \- not available
+7 of 8: Collecting osa oat output skipped \- not available
+.PP
+8 of 8: Postprocessing
 .PP
 Finalizing: Creating archive with collected data
 .PP
 Collected data was saved to:
 .br
- >>  /data\-collection/DBGINFO\-2013\-10\-08\-10\-43\-16\-host\-012345.tgz  <<
+ >>  /data\-collection/DBGINFO\-2015\-02\-26\-21\-39\-16\-host\-012345.tgz  <<
 .SH HINTS
 Run the script with root authority.
 .br
