#!/bin/bash -u
#*****************************************************************************
# Copyright 2004-2007 LSI Logic Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation,  version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#*****************************************************************************

#  Script %name:	mppsupport26p %
#  Instance:		WIC_1
#  %version:		4 %
#  Description:		
#  %created_by:		sdachepa %
#  %date_created:	Thu Sep 13 15:44:15 2007 %
#############################################################################
#Description: This script file collects information useful for Engenio Linux MPP Driver
# support purpose. Only a root user can run this script. The information collected 
# will be saved in a compressed tar file under the /tmp/directory.
#
# Reference: OLBS 349-1040010 Linux MPP Driver Information Collection for Support
#
#############################################################################
#############################################################################
#  set up the global variables
#
##############################################################################
initialize_fn()
{
    if [ ! -f /usr/sbin/mppUtil ]
    then
        #the mpp driver is not installed
        MPPLNX_VERSION="no_linux_mpp_driver"
    else
        MPPLNX_VERSION=$(/usr/sbin/mppUtil -V|/bin/awk -F":" '{print $2}'|/bin/sed -e 's/\./_/g;s/ //g')
    fi

    TMP_DIR=/tmp/mppSupport_$$
    TOP_DIR=${TMP_DIR}/$(hostname)_${MPPLNX_VERSION}	
    HARDWARE_INFO_DIR=${TOP_DIR}/hardware_info
    KERNEL_INFO_DIR=${TOP_DIR}/kernel_info
    KERNEL_CONFIG_INFO_DIR=${TOP_DIR}/kernel_config_info
    COMPILER_INFO_DIR=${TOP_DIR}/compiler_info
    BOOT_CONFIG_INFO_DIR=${TOP_DIR}/boot_config_info
    SCSI_HBA_INFO_DIR=${TOP_DIR}/scsi_hba_info
    LINUXMPP_INFO_DIR=${TOP_DIR}/linuxmpp_info
    FINAL_TAR=/tmp/mppSupportdata_$(hostname)_${MPPLNX_VERSION}_$(date +%m%d%y%H%M%S).tar.gz
}
#############################################################################
# Collect hardware information of the target system.
#
##############################################################################
hardware_info_fn()
{
    /bin/mkdir -p ${HARDWARE_INFO_DIR}
    /bin/cat /proc/cpuinfo >${HARDWARE_INFO_DIR}/cpuinfo.txt
    /bin/cat /proc/interrupts >${HARDWARE_INFO_DIR}/interrupts.txt
    /bin/cat /proc/partitions >${HARDWARE_INFO_DIR}/partitions.txt
    /bin/cat /proc/ioports >${HARDWARE_INFO_DIR}/ioports.txt
    echo "Output of the lspci -vv ">${HARDWARE_INFO_DIR}/pciinfo.txt
    echo "##############################################">>${HARDWARE_INFO_DIR}/pciinfo.txt
    /sbin/lspci -vv >>${HARDWARE_INFO_DIR}/pciinfo.txt
    echo "##############################################">>${HARDWARE_INFO_DIR}/pciinfo.txt
    echo "Output of the lspci -x ">>${HARDWARE_INFO_DIR}/pciinfo.txt
    echo "##############################################">>${HARDWARE_INFO_DIR}/pciinfo.txt
    /sbin/lspci -x >>${HARDWARE_INFO_DIR}/pciinfo.txt
    /bin/cat /proc/meminfo -v >${HARDWARE_INFO_DIR}/meminfo.txt
}
#############################################################################
# Collect kernel information of the target system.
#
##############################################################################
kernel_info_fn()
{
    /bin/mkdir -p ${KERNEL_INFO_DIR}

    echo "Current Running Kernel Version" >${KERNEL_INFO_DIR}/kernel_version.txt
    /bin/uname  -a >>${KERNEL_INFO_DIR}/kernel_version.txt

    /bin/cat /etc/*release >>${KERNEL_INFO_DIR}/kernel_version.txt

    /sbin/lsmod >${KERNEL_INFO_DIR}/modules.txt

    echo "printk log levels from \"cat /proc/sys/kernel/printk\" ">${KERNEL_INFO_DIR}/printk.txt
    /bin/cat /proc/sys/kernel/printk >>${KERNEL_INFO_DIR}/printk.txt

	
    echo "Process status list" > ${KERNEL_INFO_DIR}/ps.txt
    /bin/ps -leaf >> ${KERNEL_INFO_DIR}/ps.txt   

    if [ -f /usr/bin/pstree ]
    then
	/usr/bin/pstree > ${KERNEL_INFO_DIR}/pstree.txt
    else
	echo "binary /usr/bin/pstree not installed." > ${KERNEL_INFO_DIR}/pstree.txt
    fi

    if [ -f /proc/kallsyms ]
    then
	cat /proc/kallsyms > ${KERNEL_INFO_DIR}/kallsyms.txt
    else
	echo "kallsyms not found in proc." > ${KERNEL_INFO_DIR}/kallsyms.txt
    fi

    if [ -f /bin/rpm ]
    then
    echo "Rpm packages installed in the system ( rpm -qa command output ) " > ${KERNEL_INFO_DIR}/rpm_packages.txt 2>/dev/null
    /bin/rpm -qa >> ${KERNEL_INFO_DIR}/rpm_packages.txt 2>/dev/null
    else
	echo "rpm not installed in the system." > ${KERNEL_INFO_DIR}/rpm_packages.txt
    fi

    if [ -f /usr/bin/uptime ]
    then
	/usr/bin/uptime > ${KERNEL_INFO_DIR}/uptime.txt
    else
	echo "binary /usr/bin/uptime not installed." > ${KERNEL_INFO_DIR}/uptime.txt
    fi

    if [ -f /usr/bin/sar ] 
    then
        echo "System Activity Report " > ${KERNEL_INFO_DIR}/sar.txt 2>/dev/null
    	/usr/bin/sar -A >> ${KERNEL_INFO_DIR}/sar.txt 2>/dev/null
    else
	    echo "sar package not installed in the system." >> ${KERNEL_INFO_DIR}/sar.txt
    fi

    if [ -f /bin/df ]
    then
        echo "output of df -al" > ${KERNEL_INFO_DIR}/df.txt
	df -al >> ${KERNEL_INFO_DIR}/df.txt
    else
	echo "df binary package not installed in the system" > ${KERNEL_INFO_DIR}/df.txt
    fi
    
    /bin/cat /proc/slabinfo > ${KERNEL_INFO_DIR}/slabinfo.txt

    if [ -f /usr/bin/free ]
    then
	/usr/bin/free > ${KERNEL_INFO_DIR}/free.txt
    else
	echo "/usr/bin/free binary not installed." > ${KERNEL_INFO_DIR}/free.txt
    fi
}
#############################################################################
# Collect Kernel configuration information
#
##############################################################################
kernel_config_info_fn()
{
    /bin/mkdir -p ${KERNEL_CONFIG_INFO_DIR}
    AUTOCONF_H=/lib/modules/$(uname -r)/build/include/linux/autoconf.h 
    if [ -f ${AUTOCONF_H} ]
    then
        /bin/cp ${AUTOCONF_H} ${KERNEL_CONFIG_INFO_DIR}/autoconf.h
    else
        echo "${AUTOCONF_H} doesn't exist" > ${KERNEL_CONFIG_INFO_DIR}/autoconf.h
    fi

    LINUX_VERSION_H=/lib/modules/$(uname -r)/build/include/linux/version.h
    if [ -f ${LINUX_VERSION_H} ]
    then
        /bin/cp ${LINUX_VERSION_H} ${KERNEL_CONFIG_INFO_DIR}/UTS_version.h
    else
        echo "${LINUX_VERSION_H} doesn't exist" > ${KERNEL_CONFIG_INFO_DIR}/UTS_version.h
    fi

     #############################################
     #the system map file and config file of the kernel
     #############################################
     SYSTEM_MAP_FILE=System.map-$(uname -r)
     /bin/cp /boot/${SYSTEM_MAP_FILE} ${KERNEL_CONFIG_INFO_DIR}/${SYSTEM_MAP_FILE}.txt

     CONFIGURE_FILE=config-$(uname -r)
    /bin/cp /boot/${CONFIGURE_FILE} ${KERNEL_CONFIG_INFO_DIR}/${CONFIGURE_FILE}.txt


    /bin/ls -l /usr/src > ${KERNEL_CONFIG_INFO_DIR}/kernel_src_dir_list.txt
}
#############################################################################
#Collect compiler and related environment information
#
##############################################################################
compiler_info_fn()
{
    /bin/mkdir -p ${COMPILER_INFO_DIR}
    COMPILER_INFO_FILE=${COMPILER_INFO_DIR}/compiler_info.txt
    echo "gcc version ----" >${COMPILER_INFO_FILE}
    gcc --version  >> ${COMPILER_INFO_FILE}
    echo "make version ---">>${COMPILER_INFO_FILE}
    make --version >> ${COMPILER_INFO_FILE}
    echo "awk version ---" >>${COMPILER_INFO_FILE}
    /bin/awk --version >>${COMPILER_INFO_FILE}
    echo "ld version ---" >>${COMPILER_INFO_FILE}
    ld --version >>${COMPILER_INFO_FILE}
    echo " libc version --" >>${COMPILER_INFO_FILE}
        /bin/ls -l `ldd /bin/sh | /bin/awk '/libc/{print $3}'` | sed \
              -e 's/\.so$//' | /bin/awk -F'[.-]'   '{print "Linux C Library        " \
             $(NF-2)"."$(NF-1)"."$NF}' >>${COMPILER_INFO_FILE}
    echo " bash version---" >>${COMPILER_INFO_FILE}
    /bin/bash --version >>${COMPILER_INFO_FILE}

}

#############################################################################
#Collect boot loader information
#
##############################################################################
boot_config_info_fn()
{
    /bin/mkdir -p ${BOOT_CONFIG_INFO_DIR}

    echo "Output of  /bin/ls -lR /boot" > ${BOOT_CONFIG_INFO_DIR}/boot_files.txt
    echo "###########################################" >> ${BOOT_CONFIG_INFO_DIR}/boot_files.txt
    /bin/ls -lR /boot >> ${BOOT_CONFIG_INFO_DIR}/boot_files.txt

    if [ `uname -m` == "ia64" ]; then 
    	LILO_CONFIG="/boot/efi/efi/redhat/elilo.conf"
    else
        LILO_CONFIG="/etc/lilo.conf"
    fi

    YABOOT_CONFIG="/etc/yaboot.conf"

    GRUB_CONFIG="/boot/grub/menu.lst"

    if [ -f ${LILO_CONFIG} ]
    then
        /bin/cp ${LILO_CONFIG} ${BOOT_CONFIG_INFO_DIR}/$(basename ${LILO_CONFIG})
    fi

    if [ -f ${YABOOT_CONFIG} ]
    then
        /bin/cp ${YABOOT_CONFIG} ${BOOT_CONFIG_INFO_DIR}/$(basename ${YABOOT_CONFIG})
    fi

    if [ -f ${GRUB_CONFIG} ]
    then
        /bin/cp ${GRUB_CONFIG} ${BOOT_CONFIG_INFO_DIR}/$(basename ${GRUB_CONFIG} )
	if [ -f /boot/grub/device.map ]
	then
		/bin/cp /boot/grub/device.map ${BOOT_CONFIG_INFO_DIR}/device.map
	fi
    fi

    echo "kernel boot command line options" >${BOOT_CONFIG_INFO_DIR}/cmdline.txt
    /bin/cat /proc/cmdline >>${BOOT_CONFIG_INFO_DIR}/cmdline.txt
}
#############################################################################
#Collect HBA driver info
#
##############################################################################
scsi_hba_info_fn()
{
    /bin/mkdir -p ${SCSI_HBA_INFO_DIR}
    if [ -f /proc/scsi/scsi ]
    then
    /bin/cat /proc/scsi/scsi >${SCSI_HBA_INFO_DIR}/scsi_device.txt
    else
        echo "Linux Scsi module sd_mod is not loaded" \
            ${SCSI_HBA_INFO_DIR}/scsi_device.txt
    fi
    
    if [ -d /proc/scsi ]
    then
        echo "Output of ls -R /proc/scsi" >${SCSI_HBA_INFO_DIR}/scsi_hosts.txt
        /bin/ls -R /proc/scsi >>${SCSI_HBA_INFO_DIR}/scsi_hosts.txt
    else
        echo "Linux Scsi module sd_mod is not loaded " \
        >${SCSI_HBA_INFO_DIR}/scsi_hosts.txt
    fi


    for hba in $(/bin/ls /proc/scsi/)
    do
        if [ -d /proc/scsi/$hba ]
        then
        if [ $hba != "sg" ]
        then
            for host in $(/bin/ls /proc/scsi/${hba})
                do
                    if [ $host  -ge 0 ] && [ $host -le 100 ]
                    then
                        /bin/cat /proc/scsi/$hba/$host > ${SCSI_HBA_INFO_DIR}/${hba}_$host.txt
                    fi
                done
            fi
        fi
    done 2>/dev/null
    #if it is lsi driver
    if [ -d /proc/mpt ]
    then
        /usr/bin/find /proc/mpt -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/lsi_mpt_proc_info.txt 2> /dev/null
    fi
    ###################
    #module info
    ###################
    if [ -d /proc/scsi/qla2xxx ]
    then
        /sbin/modinfo qla2xxx >${SCSI_HBA_INFO_DIR}/qla2xxx_modinfo.txt
    fi

    if [ -d /proc/scsi/lpfc ]
    then
        /sbin/modinfo lpfc >${SCSI_HBA_INFO_DIR}/lpfc_modinfo.txt
    fi


    if [ -d /proc/scsi/mptscsih ]
    then
        /sbin/modinfo mptbase >${SCSI_HBA_INFO_DIR}/mpt_modinfo.txt
        /sbin/modinfo mptscsih >>${SCSI_HBA_INFO_DIR}/mpt_modinfo.txt
    fi

    if [ -d /proc/scsi/mptsas ]
    then
        /sbin/modinfo mptsas >> ${SCSI_HBA_INFO_DIR}/mpt_modinfo.txt
    fi

    if [ -d /proc/scsi/srp ]
    then

        # cisco and mellanox have the same /proc directory
        cisco_ib_modinfo=`/sbin/modinfo ts_srp_host 2> /dev/null`
        if [ "XX${cisco_ib_modinfo}" = "XX" ]
        then

            # this is mellanox HCA driver
        /sbin/modinfo ib_srp >${SCSI_HBA_INFO_DIR}/ib_srp_modinfo.txt
	    /usr/bin/vstat >${SCSI_HBA_INFO_DIR}/mellanox_vstat.txt

        else

            # this is cisco HCA driver
            /sbin/modinfo ts_srp_host >${SCSI_HBA_INFO_DIR}/ts_srp_host_modinfo.txt
            if [ -f /usr/local/topspin/bin/vstat ]
            then
	        /usr/local/topspin/bin/vstat >${SCSI_HBA_INFO_DIR}/cisco_vstat.txt
    fi

        fi
    fi

    #silverstorm debug capture
    if [ -d /proc/driver/ics_srp ]
    then
        /sbin/modinfo ics_srp >${SCSI_HBA_INFO_DIR}/ics_srp_modinfo.txt
    fi
    if [ -f /sbin/p1info ]
    then
	/sbin/p1info >${SCSI_HBA_INFO_DIR}/ics_p1info.txt
    fi
    if [ -f /sbin/p2info ]
    then
	/sbin/p2info >${SCSI_HBA_INFO_DIR}/ics_p2info.txt
    fi

    #ofed debug capture
    if [ -f /usr/local/ofed/bin/ibhosts ]
    then
        /usr/local/ofed/bin/ibhosts >${SCSI_HBA_INFO_DIR}/ofed_ibhosts.txt
    fi
    if [ -f /usr/local/ofed/bin/ibstat ]
    then
        /usr/local/ofed/bin/ibstat >${SCSI_HBA_INFO_DIR}/ofed_ibstat.txt
    fi
    if [ -f /usr/local/ofed/bin/ibstatus ]
    then
        /usr/local/ofed/bin/ibstatus >${SCSI_HBA_INFO_DIR}/ofed_ibstatus.txt
    fi
    if [ -f /usr/local/ofed/bin/ibv_devices ]
    then
        /usr/local/ofed/bin/ibv_devices >${SCSI_HBA_INFO_DIR}/ofed_ibv_devices.txt
    fi
    if [ -f /usr/local/ofed/bin/ibv_devinfo ]
    then
        /usr/local/ofed/bin/ibv_devinfo >${SCSI_HBA_INFO_DIR}/ofed_ibv_devinfo.txt
    fi
    if [ -f /usr/local/ofed/bin/ibswitches ]
    then
        /usr/local/ofed/bin/ibswitches >${SCSI_HBA_INFO_DIR}/ofed_ibswitches.txt
    fi
    if [ -f /usr/local/ofed/bin/ofed_info ]
    then
        /usr/local/ofed/bin/ofed_info >${SCSI_HBA_INFO_DIR}/ofed_info.txt
    fi
    if [ -f /usr/local/ofed/bin/perfquery ]
    then
        /usr/local/ofed/bin/perfquery >${SCSI_HBA_INFO_DIR}/ofed_perfquery.txt
    fi
    if [ -f /usr/local/ofed/bin/saquery ]
    then
        /usr/local/ofed/bin/saquery >${SCSI_HBA_INFO_DIR}/ofed_saquery.txt
    fi
    if [ -f /usr/local/ofed/bin/sminfo ]
    then
        /usr/local/ofed/bin/sminfo >${SCSI_HBA_INFO_DIR}/ofed_sminfo.txt
    fi

    #################
    # block device mapping
    ###################
    /opt/mpp/lsvdev >${SCSI_HBA_INFO_DIR}/lsvdev_out.txt 2>/dev/null
    ##################
    #sysfs output
    ###################
    /bin/ls -lR /sys/class/scsi_device >${SCSI_HBA_INFO_DIR}/sys_scsi_devices.txt
    /bin/ls -lR /sys/class/scsi_host >${SCSI_HBA_INFO_DIR}/sys_scsi_host.txt

    ##################
    #fc_transport output
    ###################
    if [ -d /sys/class/fc_transport ]
    then
       echo "List of Physical Scsi Devices and their fc_transport information" > ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       echo "ls -l /sys/class/fc_transport/" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       /bin/ls -l /sys/class/fc_transport >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       echo "" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       echo "" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       echo "#################################################" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       echo "PortName, PortId and NodeName of each Scsi device" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       echo "#################################################" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       for entry in $(/bin/ls /sys/class/fc_transport)
       do
          echo "/sys/class/fc_transport/"$entry >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt

          PORT_NAME=$(/bin/cat /sys/class/fc_transport/${entry}/port_name)
          echo "port_name: ${PORT_NAME}" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
          PORT_ID=$(/bin/cat /sys/class/fc_transport/${entry}/port_id)
          echo "port_id: ${PORT_ID}" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
          NODE_NAME=$(/bin/cat /sys/class/fc_transport/${entry}/node_name)
          echo "node_name: ${NODE_NAME}" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
          echo "" >> ${SCSI_HBA_INFO_DIR}/sys_fc_transport.txt
       done
    fi
    if [ -d /sys/class/fc_host ]
    then
        /usr/bin/find /sys/class/fc_host -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_fc_host.txt 2> /dev/null
    fi
    if [ -d /sys/class/fc_remote_ports ]
    then
        /usr/bin/find /sys/class/fc_remote_ports -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_fc_remote_ports.txt 2> /dev/null
    fi

    ######################################################
    #Capture scsi_host information from /sys file system
    ######################################################
    if [ -d /sys/class/scsi_host ]
    then
        /usr/bin/find /sys/class/scsi_host -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_class_scsihost_info.txt 2> /dev/null
    fi
 

    ##################
    #Mellanox infiniband output
    ###################
    if [ -d /proc/infiniband ]
    then
        /usr/bin/find /proc/infiniband -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/mellanox_proc_info.txt 2> /dev/null
    fi

    ##################
    #SilverStorm infiniband output
    ###################
    if [ -d /proc/driver/ics_dsc ]
    then
        /usr/bin/find /proc/driver/ics_dsc -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/silverstorm_proc_info.txt 2> /dev/null
    fi
    if [ -d /proc/driver/ics_srp ]
    then
        /usr/bin/find /proc/driver/ics_srp -type f  -print -exec /bin/cat {} \; \
        >>${SCSI_HBA_INFO_DIR}/silverstorm_proc_info.txt 2> /dev/null
    fi
    if [ -f /etc/sysconfig/ics_srp.cfg ]
    then
        /usr/bin/find /etc/sysconfig/ics_srp.cfg -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/silverstorm_ics_srp_cfg.txt 2> /dev/null
    fi

    ##################
    #iscsi 
    ###################
    if [ -d /sys/class/iscsi_connection ]
    then
        /usr/bin/find /sys/class/iscsi_connection -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_iscsi_connection.txt 2> /dev/null
    fi
    if [ -d /sys/class/iscsi_session ]
    then
        /usr/bin/find /sys/class/iscsi_session -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_iscsi_session.txt 2> /dev/null
    fi
    if [ -d /sys/class/iscsi_transport ]
    then
        /usr/bin/find /sys/class/iscsi_transport -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_iscsi_transport.txt 2> /dev/null
    fi
    if [ -d /sys/class/iscsi_host ]
    then
        /usr/bin/find /sys/class/iscsi_host -type f  -print -exec /bin/cat {} \; \
        >${SCSI_HBA_INFO_DIR}/sys_iscsi_host.txt 2> /dev/null
    fi
    if [ -f /sbin/iscsiadm ]
    then
	    echo "Output of iscsiadm -m session" >${SCSI_HBA_INFO_DIR}/iscsiadm_output.txt 2> /dev/null
	    /sbin/iscsiadm -m session >>${SCSI_HBA_INFO_DIR}/iscsiadm_output.txt 2> /dev/null
	    echo "#######################################" >>${SCSI_HBA_INFO_DIR}/iscsiadm_output.txt 2> /dev/null
	    echo "Output of iscsiadm -m session -i" >>${SCSI_HBA_INFO_DIR}/iscsiadm_output.txt 2> /dev/null
	    /sbin/iscsiadm -m session -i >>${SCSI_HBA_INFO_DIR}/iscsiadm_output.txt 2> /dev/null
    fi
	if [ -f /etc/iscsi/initiatorname.iscsi ]
	then
		/bin/cp /etc/iscsi/initiatorname.iscsi ${SCSI_HBA_INFO_DIR}/initiatorname.iscsi
	fi

	if [ -f /etc/iscsi/iscsid.conf ]
	then
		/bin/cp /etc/iscsi/iscsid.conf ${SCSI_HBA_INFO_DIR}/iscsid.conf
	fi


    
}
#############################################################################
#Collect Engenio MPP driver info
#
##############################################################################
linuxmpp_info_fn()
{

    /bin/mkdir -p ${LINUXMPP_INFO_DIR}

    if [ -f /usr/sbin/mppUtil ]
    then
        /usr/sbin/mppUtil -C >${LINUXMPP_INFO_DIR}/mppLnx_source_versions.txt
    else
        echo "Linux MPP driver is not installed on the system "\
                >${LINUXMPP_INFO_DIR}/mppLnx_source_versions.txt
    fi

    if [ `uname -m` == "ia64" ]; then
    	MPP_IMAGE=/boot/efi/efi/redhat/mpp-`uname -r`.img
    else
    	MPP_IMAGE=/boot/mpp-`uname -r`.img
	
    fi

    if [ -f $MPP_IMAGE ]
    then
	/bin/cp $MPP_IMAGE ${LINUXMPP_INFO_DIR}/mpp-`uname -r`.img.gz
    else
	echo "Did not find $MPP_IMAGE file.." \
	>${LINUXMPP_INFO_DIR}/mpp-`uname -r`.img.gz
    fi

    if [ -d /proc/mpp ]
    then
        /bin/ls -R /proc/mpp >${LINUXMPP_INFO_DIR}/device_topology.txt
    else
        echo "Linux MPP driver is not loaded...">${LINUXMPP_INFO_DIR}/device_topology.txt
    fi

    if [ -f /etc/mpp.conf ]
    then
        /bin/cp /etc/mpp.conf ${LINUXMPP_INFO_DIR}/mpp.conf
    else
        echo "Did not find /etc/mpp.conf file..." \
            >${LINUXMPP_INFO_DIR}/mpp.conf
    fi

    if [ -f /etc/syslog.conf ]
    then
        /bin/cp /etc/syslog.conf ${LINUXMPP_INFO_DIR}/syslog.conf
    else
        echo "Did not find /etc/syslog.conf file..." \
            >${LINUXMPP_INFO_DIR}/syslog.conf
    fi

    if [ -f /etc/modprobe.conf ]
    then
        /bin/cp /etc/modprobe.conf ${LINUXMPP_INFO_DIR}/modprobe.conf
    else
        echo "Did not find /etc/modprobe.conf file..." \
            >${LINUXMPP_INFO_DIR}/modprobe.conf
    fi

    if [ -f /etc/modprobe.conf.local ]
    then
        /bin/cp /etc/modprobe.conf.local ${LINUXMPP_INFO_DIR}/modprobe.conf.local
    else
        echo "Did not find /etc/modprobe.conf.local file..." \
            >${LINUXMPP_INFO_DIR}/modprobe.conf.local
    fi
    
    if [ -f /etc/modprobe-openib.conf ]
    then
        /bin/cp /etc/modprobe-openib.conf ${LINUXMPP_INFO_DIR}/modprobe-openib.conf
    fi

    if [ -f /var/mpp/devicemapping ]
    then
        /bin/cp /var/mpp/devicemapping ${LINUXMPP_INFO_DIR}/devicemapping.txt
    else
        echo "Did not find /var/mpp/devicemapping file..." \
            >${LINUXMPP_INFO_DIR}/devicemapping.conf
    fi

    if [ -f /usr/sbin/mppUtil ]
    then
        MAX_ARRAY=$(/usr/sbin/mppUtil -m|/bin/awk -F"=" '{print $2}' |/bin/sed -e 's/ //g')
        declare -i index=0
        while [ $index -lt ${MAX_ARRAY} ]
        do
            /usr/sbin/mppUtil -g $index 2>/dev/null
            let index+=1
        done >${LINUXMPP_INFO_DIR}/array_info.txt
    else
        echo "Linux MPP driver is not installed" >${LINUXMPP_INFO_DIR}/array_info.txt
    fi

    if [ $MPPLNX_DOIO -eq 1 ]
    then
        if [ -d /proc/mpp ]
        then
            /usr/bin/find /proc/mpp -name "LUN*" -print -exec /bin/cat {} \; >${LINUXMPP_INFO_DIR}/io_statistics.txt
            /usr/bin/find /proc/mpp -name "virtualLun*" -print -exec /bin/cat {} \; >>${LINUXMPP_INFO_DIR}/io_statistics.txt
        else
            echo "Linux MPP driver is not installed" >${LINUXMPP_INFO_DIR}/io_statistics.txt
        fi
    else
		echo " Does not collect io statistics info">${LINUXMPP_INFO_DIR}/io_statistics.txt
    fi

    if [ -f /usr/sbin/mppUtil ]
    then
		if [ $MPPLNX_DOIO -eq 1 ]
		then 
			/usr/sbin/mppUtil -S >${LINUXMPP_INFO_DIR}/mppUtil_S_out.txt
		else
			echo " Does not collect mppUtil -S info">${LINUXMPP_INFO_DIR}/mppUtil_S_out.txt
		fi
    fi
    #######
	####### check whether or not we can do a read to all virtual devices
	#######
	if [ $MPPLNX_DOIO -eq 1 ]
	then
		/opt/mpp/lsvdev| while read line
		do
			lsi_array_dev=$(echo $line |egrep "\/dev\/sd" |awk '{print $4}')
			if [ "XX$lsi_array_dev" != "XX" ]
			then
                echo "Read 1 block from $line"
                dd if=$lsi_array_dev count=1 of=/dev/null >/dev/null 2>&1
                if [ $? -eq 0 ]
                        then
                                echo "     Test Passed."
                        else
                                echo "     Test Failed. Error code $?"
                fi
			fi
		done >${LINUXMPP_INFO_DIR}/virtual_device_io_status.txt
	fi

    if [ -f /var/lock/subsys/mpp ]
    then
        /bin/cat /var/lock/subsys/mpp >${LINUXMPP_INFO_DIR}/var_lock_subsys_mpp.txt
    fi

    #################
    # boot time message
    ################

    if [ -f /var/log/dmesg ]
    then
        /bin/cp /var/log/dmesg   ${LINUXMPP_INFO_DIR}/dmesg.txt
    fi

    if [ -f /var/log/boot.msg ]
    then
        /bin/cp /var/log/boot.msg ${LINUXMPP_INFO_DIR}/boot_msg.txt
    fi

    ##################
    #modprobe appended file
    ####################
    if [ -f /opt/mpp/modprobe.conf.mppappend ]
    then
        /bin/cp /opt/mpp/modprobe.conf.mppappend ${LINUXMPP_INFO_DIR}/modprobe.conf.mppappend.txt
    fi

    if [ -f /opt/mpp/mppmkinitrd ]
    then
        /bin/cp /opt/mpp/mppmkinitrd ${LINUXMPP_INFO_DIR}/mppmkintrd
    fi

    tail -5500 /var/log/messages >${LINUXMPP_INFO_DIR}/log_messages.txt
}
#############################################################################
# create summary file
#
##############################################################################
summary_fn()
{
    /bin/cat <<EOF >>${TOP_DIR}/summary.txt
The files in this directory contain support information related to the Linux MPP driver. 
Each directory contains information for a specific area. Please refer to OLBS 349-1044010 
"Linux MPP Driver Information Collection for Support" for details.

EOF
    echo "This support data is collected at $(date) on host $(hostname)" >>${TOP_DIR}/summary.txt
    echo "The network identification of the system:">>${TOP_DIR}/summary.txt
    echo "$(/sbin/ifconfig -a)" >>${TOP_DIR}/summary.txt
}
#############################################################################
# create tar ball
#
##############################################################################
tar_compress_fn()
{
    cd ${TMP_DIR}
    /bin/tar -zcf ${FINAL_TAR} *
    /bin/rm -rf ${TMP_DIR}
}
############################################################################
# mppSupport Usage
#
##############################################################################
mppSupport_usage()
{
	echo "Usage: $0 [-a][-h]" >&2
	exit 2;
}
#############################################################################
# Do all things we need
#
##############################################################################
work_horse()
{
    hardware_info_fn
    kernel_info_fn
    kernel_config_info_fn
    compiler_info_fn
    boot_config_info_fn
    scsi_hba_info_fn
    linuxmpp_info_fn
    summary_fn
    tar_compress_fn
    echo "The collected support data is saved in ${FINAL_TAR}."
}
#########################
# The is the script entry
############################
MPPLNX_DOIO=0
if [ $# -gt 1 ]
then
        mppSupport_usage
elif [ $# -eq 1 ]
then
	while getopts ah op 2>/dev/null
	do
		case "$op" in
			a) MPPLNX_DOIO=1;;
			h) mppSupport_usage;;
			\?) mppSupport_usage;;
		esac
	done
	#####
	#the option must be -a or -h
	######
	if [ $MPPLNX_DOIO -ne 1 ]
	then
		mppSupport_usage
	fi
fi

initialize_fn
work_horse
