#!/bin/sh # # zfcp_disk_configure # # Configures a zfcp disk # # Usage: # zfcp_disk_configure # # ccwid = x.y.ssss where # x is always 0 until IBM creates something that uses that number # y is the logical channel subsystem (lcss) number. Most often this is 0, but it could be non-zero # ssss is the four digit subchannel address of the device, in hexidecimal, with leading zeros. # online = 0 to take the device offline # 1 to bring the device online # # Return codes # 1 sysfs not mounted # 2 invalid value for # 3 device does not exist # 4 WWPN invalid # 5 Could not activate WWPN for adapter # 6 Could not activate zFCP disk # 7 SCSI disk could not be deactivated # 8 zFCP LUN could not be deregistered # 9 zFCP WWPN could not be deregistered # if [ "${DEBUG}" != "yes" ]; then DEBUG="no" fi mesg () { echo "$@" } debug_mesg () { case "$DEBUG" in yes) mesg "$@" ;; *) ;; esac } if [ $# -ne 4 ] ; then echo "Usage: $0 " echo " ccwid = x.y.ssss where" echo " x is always 0 until IBM creates something that uses that number" echo " y is the logical channel subsystem (lcss) number. Most often this is 0, but it could be non-zero" echo " ssss is the four digit subchannel address of the device, in hexidecimal, with leading zeros." echo " online = 0 to take the device offline" echo " 1 to bring the device online" exit 1 fi # Get the mount point for sysfs while read MNTPT MNTDIR MNTSYS MNTTYPE; do if test "$MNTSYS" = "sysfs"; then SYSFS="$MNTDIR" break; fi done ${_zfcp_wwpn_dir}/unit_add /sbin/udevadm settle fi # Re-check whether the disk could be activated if [ ! -d "${_zfcp_wwpn_dir}/0x${FCP_LUN}" ] ; then mesg "Could not activate FCP disk ${FCP_WWPN}:${FCP_LUN}" exit 6 fi # Check for failed disks read wwpn_status < ${_zfcp_wwpn_dir}/0x${FCP_LUN}/status while [ "$wwpn_status" != 0 ] ; do sleep 1 read wwpn_status < ${_zfcp_wwpn_dir}/0x${FCP_LUN}/in_recovery [ "$wwpn_status" = 0 ] && break done read wwpn_status < ${_zfcp_wwpn_dir}/0x${FCP_LUN}/failed if [ "$wwpn_status" = 1 ] ; then debug_mesg "ERP failed on FCP disk ${FCP_WWPN}:${FCP_LUN}" exit 7 fi fi else # Deconfigure SCSI disk debug_mesg "Deconfiguring FCP disk ${FCP_WWPN}:${FCP_LUN}" _zfcp_wwpn_dir="${_zfcp_dir}/0x${FCP_WWPN}" # Find the correspondig SCSI disk for host_dir in $_zfcp_dir/host*; do if [ -d $host_dir ] ; then _zfcp_scsi_host_dir=$host_dir break; fi done if [ -d "$_zfcp_scsi_host_dir" ] ; then # Deregister the disk from SCSI layer for target in $_zfcp_scsi_host_dir/rport-*/target*/* ; do [ "$target" != "${target##*/fc_transport}" ] && continue if [ -d "$target" ] && [ -d "$target/scsi_device" ] ; then _zfcp_scsi_id=${target##*/} read _zfcp_tmp_hba < ${target}/hba_id read _zfcp_tmp_wwpn < ${target}/wwpn read _zfcp_tmp_lun < ${target}/fcp_lun if [ "0x${FCP_LUN}" = "$_zfcp_tmp_lun" -a "0x${FCP_WWPN}" = "$_zfcp_tmp_wwpn" ] ; then if [ "$auto_lun_scan" = 1 ] ; then mesg "Could not deactivate SCSI disk ${_zfcp_scsi_id}" exit 7 else echo 1 > $target/delete _zfcp_scsi_dir=$target fi break; fi fi done /sbin/udevadm settle else debug_mesg "No SCSI disk found for FCP disk ${FCP_WWPN}:${FCP_LUN}" fi # Re-check whether the SCSI disk is gone num=$udev_timeout while [ $num -gt 0 ] ; do [ -d "${_zfcp_scsi_dir}" ] || break let num=$num-1 sleep 1 done if [ -d "${_zfcp_scsi_dir}" ]; then mesg "Could not deactivate SCSI disk ${_zfcp_scsi_id}" exit 7 fi # Wait for udev to catch up /sbin/udevadm settle # check multipathing _zfcp_scsi_dev=$(multipathd -k'show paths' 2> /dev/null | sed -n "s/$_zfcp_scsi_id \(sd[a-z]*\).*/\1/p") [ "$_zfcp_scsi_dev" ] && multipathd -k"del path $_zfcp_scsi_dev" # Deconfigure the FCP_LUN : ${_zfcp_wwpn_dir} echo "0x${FCP_LUN}" > ${_zfcp_wwpn_dir}/unit_remove if [ -d "${_zfcp_wwpn_dir}/0x${FCP_LUN}" ]; then mesg "Could not deregister FCP LUN ${FCP_LUN}" exit 8 fi # Find all remaining activated disks ZFCP_LUNS= for _tmp_wwpn_dir in ${_zfcp_dir}/0x*; do if [ -d "$_tmp_wwpn_dir" ]; then tmp_wwpn=$(basename $_tmp_wwpn_dir) # Find all luns for _tmp_lun_dir in ${_tmp_wwpn_dir}/0x*; do if [ -d "$_tmp_lun_dir" ]; then tmp_lun=$(basename $_tmp_lun_dir) tmp_port="${tmp_wwpn}:${tmp_lun}" ZFCP_LUNS="$ZFCP_LUNS $tmp_port" fi done fi done fi # And now update the rules file if test -d ${RULES_DIR}; then # Find all WWPNs read online < ${_zfcp_dir}/online; if [ $online -eq 0 ] ; then exit 0 fi for port in ${_zfcp_dir}/0x* ; do [ -d $port ] || continue; [ -w $port/unit_remove ] || continue; port_list="$port_list ${port##*/}" done cat > ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <