home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20120305.etc.tar.gz / bradford.20120305.etc.tar / etc / sysconfig / hardware / scripts / hwdown-zfcp < prev    next >
Text File  |  2006-06-02  |  2KB  |  109 lines

  1. #!/bin/bash
  2. #
  3. # Deconfigures a zfcp lun.
  4. #
  5. # Should be called after the SCSI id
  6. # has been removed
  7. #
  8. # Following steps are required:
  9. #
  10. # 1.) remove the LUN corresponding to the scsi id
  11. # 2.) Check if the port corresponding to the scsi id
  12. #     has no other ports open
  13. #     -> If so, remove the port
  14. # 3.) Check if the device has no other ports open
  15. #     -> If so, deactivate the device
  16. #     -> hotplug event scsi_host
  17.  
  18. SCRIPTNAME=${0##*/}
  19. HWDESC=$1
  20.  
  21. # Read in common functions
  22. . ./scripts/functions
  23. test -r ./config && . ./config
  24.  
  25. # Check for variables
  26. if test -z "$SYSFS"; then
  27.     message "sysfs not mounted, aborting."
  28.     exit 1
  29. fi
  30.  
  31. # Set defaults
  32. if [ -z "$HWD_DEVICEPATH" ]; then
  33.     HWD_DEVICEPATH=${SYSFS}/bus/ccw/devices/${HWD_BUSID}
  34. fi
  35.  
  36. # Set sysfs paths
  37. _zfcp_dir=${HWD_DEVICEPATH}
  38.  
  39. # Find corresponding fcp wwpn:lun
  40. scsi_id=${_zfcp_dir##*/}
  41. saved_IFS="$IFS"
  42. IFS=":"
  43. set -- $scsi_id
  44. scsi_host_num=$1
  45. scsi_target_num=$3
  46. scsi_lun_num=$4
  47. IFS="$saved_IFS"
  48.  
  49. path=`echo $_zfcp_dir | sed "s@/host[0-9]\{1,\}/.*@@"`
  50.  
  51. # Find the fcp port corresponding to the scsi target
  52. for tmp_wwpn in ${path}/0x*; do
  53.     if [ -d $tmp_wwpn ]; then
  54.     read tmp_target_num < $tmp_wwpn/scsi_id
  55.     if (($tmp_target_num == $scsi_target_num)); then
  56.         wwpn=${tmp_wwpn##*/}
  57.         break;
  58.     fi
  59.     fi
  60. done
  61.  
  62. if [ "$wwpn" ]; then
  63.     # Find the fcp lun corresponding to the scsi lun
  64.     for tmp_lun in ${path}/$wwpn/0x*; do
  65.     if [ -d $tmp_lun ]; then
  66.         read tmp_lun_num < $tmp_lun/scsi_lun
  67.         if (($tmp_lun_num == $scsi_lun_num)); then
  68.         lun=${tmp_lun##*/}
  69.         break;
  70.         fi
  71.     fi
  72.     done
  73.     # Remove if found
  74.     if [ "$lun" ]; then
  75.     message "Removing fcp unit $wwpn:$lun"
  76.     echo "$lun" > ${path}/$wwpn/unit_remove
  77.     fi
  78.     # Recheck if the port still has luns open
  79.     num_luns=0
  80.     for tmp_lun in ${path}/$wwpn/0x*; do
  81.     if [ -d $tmp_lun ]; then
  82.         num_luns=$(expr $num_luns + 1)
  83.     fi
  84.     done
  85.     if (($num_luns == 0)); then
  86.     # No, remove the fcp port
  87.     echo "$wwpn" > ${path}/port_remove
  88.     message "Removing fcp port $wwpn"
  89.     fi
  90. fi
  91.  
  92. # Recheck for open ports
  93. num_ports=0
  94. for tmp_wwpn in ${path}/0x*; do
  95.     if [ -d $tmp_wwpn ]; then
  96.     num_ports=$(expr $num_ports + 1)
  97.     fi
  98. done
  99. if (($num_ports == 0)); then
  100.     # Deactivate this adapter
  101.     echo "0" > ${path}/online
  102.     message "Deactivating adapter $HWD_BUSID"
  103. else
  104.     debug "Could not deactivate adapter $HWD_BUSID: $num_ports ports open"
  105. fi
  106.  
  107. # EOF
  108.