#!/bin/ksh function get_hba_vendor_code { host=$1 pci_loc=$(ls -l /sys/class/scsi_host/host${host} \ | awk -F '/' '{i=NF-3; print $i}' ) hba_vendor_code=$(lspci -nvms $pci_loc | awk '/^Vendor/ {print $2}') print $hba_vendor_code } function get_hba_wwpn { host=$1 hba_vendor_code=$(get_hba_vendor_code $host) case $hba_vendor_code in 1077) wwpn=$(get_qla_wwpn $host);; 10df) wwpn=$(cat /sys/class/fc_host/host${host}/port_name);; 1000) wwpn=$(cat /sys/class/fc_host/host${host}/port_name);; esac print $wwpn } function get_qla_wwpn { host=$1 wwpn='' file=/sys/class/fc_host/host${host}/port_name if [ -r $file ] then wwpn=$(cat $file) else file=/sys/class/scsi_host/host${host}/proc_name if [ -r $file ] then proc_name=$(cat $file) file=/proc/scsi/$proc_name/$host if [ -r $file ] then wwpn=$(grep 'adapter-port' /proc/scsi/$proc_name/$host \ | awk -F '=' '{print $2}' \ | tr -d ';') else return 2 fi else return 1 fi fi print $wwpn } function get_host_targets { host=$1 ls /sys/class/scsi_host/host${host}/device | sed -ne 's/^target//p' set -A rports $(ls /sys/class/scsi_host/host${host}/device | sed -ne '/^rport/p') for r in ${rports[@]} do ls /sys/class/scsi_host/host${host}/device/$r done | sed -ne 's/^target//p' } function get_target_wwpn { host=$1 target=$2 target_id=$(echo $target | awk -F ':' '{print $NF}') #echo get_target_wwpn $host $target target_id=$target_id wwpn='tgt-wwpn???' vendor_code=$(get_hba_vendor_code $host) case $vendor_code in 1077) wwpn=$(get_qla_tgt_wwpn $host $target);; 10df | 1000) wwpn=$(cat /sys/class/fc_transport/target${target}/port_name);; esac print $wwpn } function get_qla_tgt_wwpn { host=$1 tgt=$2 wwpn='' file=/sys/class/fc_transport/target${tgt}/port_name if [ -r $file ] then wwpn=$(cat $file) else file=/sys/class/scsi_host/host${host}/proc_name if [ -r $file ] then proc_name=$(cat /sys/class/scsi_host/host${host}/proc_name) file=/proc/scsi/$proc_name/$host if [ -r $file ] then wwpn=$(grep "scsi-qla.-target-$target_id" $file \ | awk -F '=' '{print $2}' \ | tr -d ';' ) else return 2 fi else return 1 fi fi print $wwpn } function array_merge_numeric { for i in $@; do echo $i; done | sort -nu } function array_merge { for i in $@; do echo $i; done | sort -u } #set -x # Check for host hba's set -A list1 [[ -d /sys/class/fc_host ]] && \ set -A list1 $(ls /sys/class/fc_host | sed -e 's/host//') # Check for host hba's another way set -A list2 [[ -d /sys/class/scsi_host ]] && \ for i in /sys/class/scsi_host/host* do proc=$(cat $i/proc_name) case $proc in qla2* | lpfc | mptfc) host=$(basename $i | sed -e 's/host//') list2[${#list2[@]}]=$host esac done set -A hbas $(array_merge_numeric ${list1[@]} ${list2[@]}) # FOREACH HBA for hba in "${hbas[@]}" do # hba wwpn hba_wwpn=$(get_hba_wwpn $hba) print "HBA $hba_wwpn host$hba" # get list of targets for this hba set -A targets $(get_host_targets $hba) # FOREACH TARGET for target in "${targets[@]}" do # get target wwpn target_wwpn=$(get_target_wwpn $hba $target) # get list of luns for this hba:target set -A luns $( ls /sys/class/fc_transport/target${target}/device \ | sed -ne "s/${target}://p") # FOREACH LUN for lun in "${luns[@]}" do unset lun_scsi_dev lun_uniq_id # get local scsi dev this lun is mapped to file=$(ls /sys/class/fc_transport/target${target}/device/${target}:${lun} | sed -ne '/^block/p') if [ -n "${file}" ] then #lun_scsi_dev=$(basename $(ls -l /sys/class/fc_transport/target${target}/device/${target}:${lun}/block* | awk '{print $NF}') ) lun_scsi_dev=$(ls /sys/class/fc_transport/target${target}/device/${target}:${lun}/block* ) # get unique lun id lun_uniq_id=$(/lib/udev/scsi_id --page=0x83 --whitelisted --device=/dev/${lun_scsi_dev}) fi lun_timeout=`cat /sys/class/scsi_device/${target}:${lun}/device/timeout` # PRINT print $hba_wwpn $target_wwpn "$target:$lun" $lun_scsi_dev $lun_uniq_id $lun_timeout done done done