From c4a452042f577895e765076faa66f9866d16becad7ad03531a521dcf3186fc91 Mon Sep 17 00:00:00 2001 From: Mark Post Date: Wed, 25 Oct 2017 17:52:12 +0000 Subject: [PATCH] Accepting request 536602 from home:markkp:branches:Base:System Fixing bsc#1063393 and temporarily reverting changes to *_configure scripts. OBS-URL: https://build.opensuse.org/request/show/536602 OBS-URL: https://build.opensuse.org/package/show/Base:System/s390-tools?expand=0&rev=26 --- ctc_configure | 363 +++++++++--- dasd_configure | 475 +++++++++++---- qeth_configure | 554 +++++++++++++----- ...ls-sles15-Format-devices-in-parallel.patch | 10 + s390-tools.changes | 11 +- zfcp_disk_configure | 336 +++++++++-- zfcp_host_configure | 213 +++++-- 7 files changed, 1517 insertions(+), 445 deletions(-) diff --git a/ctc_configure b/ctc_configure index 590f00b..ddaeaf0 100644 --- a/ctc_configure +++ b/ctc_configure @@ -2,127 +2,316 @@ # # ctc_configure # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. -# -# Configures a CTC device by calling the IBM-provided chzdev command. -# Whereas this script used to validate the parameters provided to it, -# we now rely on chzdev to do that instead. The script is intended only -# as a "translation layer" to provide backward compatability for older -# scripts and tools that invoke it. +# Configures a CTC device # # Usage: # ctc_configure [] # # read/write channel = 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. +# 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 -# protocol = 0 Compatibility with peers other than OS/390®, or z/OS, for -# example, a z/VM TCP service machine. This is the default. +# protocol = 0 Compatibility with peers other than OS/390®, or z/OS, for example, a z/VM TCP service machine. This is the default. # 1 Enhanced package checking for Linux peers. # 3 For compatibility with OS/390 or z/OS peers. -# 4 For MPC connections to VTAM on traditional mainframe -# operating systems. +# 4 For MPC connections to VTAM on traditional mainframe operating systems. # # Return values: -# Return codes are determined by the chzdev command. +# 1 sysfs not mounted +# 2 Invalid status for +# 3 No device found for read-channel +# 4 No device found for write-channel +# 5 Invalid device type +# 6 Device type mismatch +# 7 Could not load module +# 8 CCW devices grouped different devices +# 9 Could not group devices +# 10 Could not set device online +# 11 Could not set device offline # +if [ "${DEBUG}" != "yes" ]; then + DEBUG="no" +fi + +DATUM=$(date) + +add_channel_for_cio() { + echo "$* # $DATUM" >> /boot/zipl/active_devices.txt +} + +remove_channel_for_cio() { + [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^$1/d" /boot/zipl/active_devices.txt +} + mesg () { echo "$@" } debug_mesg () { - case "${DEBUG}" in - yes) mesg "$@" ;; - *) ;; + case "$DEBUG" in + yes) mesg "$@" ;; + *) ;; esac } -add_cio_channel() { - echo "$* # ${DATE}" >> /boot/zipl/active_devices.txt -} +# Get the mount point for sysfs +while read MNTPT MNTDIR MNTSYS MNTTYPE; do + if test "$MNTSYS" = "sysfs"; then + SYSFS="$MNTDIR" + break; + fi +done []" - echo " read/write channel = x.y.ssss where" - echo " x is always 0 until IBM creates something that" - echo " uses that number" - echo " y is the logical channel subsystem (lcss) number." - echo " Most often this is 0, but it could be non-zero" - echo " ssss is the four digit subchannel address of the" - echo " device, in hexidecimal, with leading zeros." - echo " online = 0 to take the device offline" - echo " 1 to bring the device online" - echo " protocol = 0 Compatibility with peers other than OS/390®, or z/OS, for" - echo " example, a z/VM TCP service machine. This is the default." - echo " 1 Enhanced package checking for Linux peers." - echo " 3 For compatibility with OS/390 or z/OS peers." - echo " 4 For MPC connections to VTAM on traditional mainframe" - echo " operating systems." -} - -if [ "${DEBUG}" != "yes" ]; then - DEBUG="no" +if [ -z "$SYSFS" ]; then + mesg "/sysfs not present" + exit 1 fi -DATE=$(date) - -CTC_READ_CHAN=${1} -CTC_WRITE_CHAN=${2} -ON_OFF=${3} -CTC_MODE=${4} - -if [ -z "${CTC_READ_CHAN}" ] || [ -z "${CTC_WRITE_CHAN}" ] || [ -z "${ON_OFF}" ]; then - mesg "You didn't specify all the needed parameters." - usage - exit 1 +if [ $# -lt 3 ] ; then + echo "Usage: $0 []" + echo " read/write channel = 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" + echo " protocol = 0 Compatibility with peers other than OS/390®, or z/OS, for example, a z/VM TCP service machine. This is the default." + echo " 1 Enhanced package checking for Linux peers." + echo " 3 For compatibility with OS/390 or z/OS peers." + echo " 4 For MPC connections to VTAM on traditional mainframe operating systems." + exit 1 fi -if [ -z "${CTC_MODE}" ]; then - PARM_LIST="${PARM_LIST} protocol=0" -else PARM_LIST="${PARM_LIST} protocol=${CTC_MODE}" +CTC_READ_CHAN=$1 +CTC_WRITE_CHAN=$2 +ONLINE=$3 +CTC_MODE=$4 + +[ -z "$CTC_MODE" ] && CTC_MODE=0 + +if [ -z "$ONLINE" ] || [ "$ONLINE" -ne "1" -a "$ONLINE" -ne "0" ]; then + mesg "Invalid device status $ONLINE" + exit 2 fi -if [ -f /sys/bus/ccw/devices/${CTC_READ_CHAN}/cutype ]; then - read CU_TYPE < /sys/bus/ccw/devices/${CTC_READ_CHAN}/cutype -else mesg "Psuedo file/sys/bus/ccw/devices/${CTC_READ_CHAN}/cutype doesn't exist." - mesg "Check to see if sysfs is mounted." - exit 1 +_ccw_dir=${SYSFS}/bus/ccw/devices + +debug_mesg "Configuring CTC/LCS device ${CTC_READ_CHAN}/${CTC_WRITE_CHAN}" + + +if test ! -d "$_ccw_dir/$CTC_READ_CHAN" ; then + mesg "device $_ccw_dir/$CTC_READ_CHAN does not exist" + exit 3 +fi +if test ! -d "$_ccw_dir/$CTC_WRITE_CHAN" ; then + mesg "device $_ccw_dir/$CTC_WRITE_CHAN does not exist" + exit 4 fi -if [ "${CU_TYPE}" == "3088/01" ] || [ "${CU_TYPE}" == "3088/60" ]; then - DEV_TYPE="lcs" -else DEV_TYPE="ctc" +CCW_CHAN_GROUP= +for ccw in $_ccw_dir/$CTC_READ_CHAN $_ccw_dir/$CTC_WRITE_CHAN; do + + read _cu_type < $ccw/cutype + read _dev_type < $ccw/devtype + + case "$_cu_type" in + 3088/01) + # P/390 network adapter + CCW_CHAN_NAME="cu3088" + CCW_CHAN_GROUP="lcs" + ;; + 3088/08) + # Channel To Channel + CCW_CHAN_NAME="cu3088" + CCW_CHAN_GROUP="ctcm" + ;; + 3088/1e) + # FICON adapter + CCW_CHAN_NAME="cu3088" + CCW_CHAN_GROUP="ctcm" + ;; + 3088/1f) + # ESCON adapter (I.e. hardware CTC device) + CCW_CHAN_NAME="cu3088" + CCW_CHAN_GROUP="ctcm" + ;; + 3088/60) + # Lan Channel Station + CCW_CHAN_NAME="cu3088" + CCW_CHAN_GROUP="lcs" + ;; + *) + CCW_CHAN_NAME= + ;; + esac + + if [ -z "$CCW_CHAN_NAME" ]; then + mesg "Not a valid CTC device (cu $_cutype, dev $_devtype)" + exit 5 + fi + + [ -z "$tmp_chan" ] && tmp_chan=$CCW_CHAN_GROUP +done + +if [ "$tmp_chan" != "$CCW_CHAN_GROUP" ] ; then + mesg "CTC type mismatch (read: $tmp_chan, write: $CCW_CHAN_GROUP)" + exit 6 fi -if [ "${ON_OFF}" == 0 ]; then - debug_mesg "chzdev -d ${DEV_TYPE} ${CTC_READ_CHAN}" - chzdev -d ${DEV_TYPE} ${CTC_READ_CHAN} -elif [ "${ON_OFF}" == 1 ]; then - debug_mesg "chzdev -e ${DEV_TYPE} ${CTC_READ_CHAN} ${PARM_LIST}" - chzdev -e ${DEV_TYPE} ${CTC_READ_CHAN} ${PARM_LIST} -else mesg "You must specify a 0 or a 1 for the online/offline attribute." - usage - exit 1 +_ccw_groupdir=${SYSFS}/bus/ccwgroup + +# Check for modules +if test ! -d "${_ccw_groupdir}/drivers/${CCW_CHAN_GROUP}" ; then + /sbin/modprobe $CCW_CHAN_GROUP + + # Re-check whether module loading has succeeded + if test ! -d "${_ccw_groupdir}/drivers/${CCW_CHAN_GROUP}"; then + mesg "Could not load module ${CCW_CHAN_GROUP}" + exit 7 + fi fi -RC=${?} -if [ ${RC} -ne 0 ]; then - exit ${RC} +# Check for grouping +_ccw_status_dir= +if [ -e ${_ccw_dir}/${CTC_READ_CHAN}/group_device ] ; then + _ccw_status_dir=$(cd -P ${_ccw_dir}/${CTC_READ_CHAN}/group_device; echo $PWD) +fi +if [ -e ${_ccw_dir}/${CTC_WRITE_CHAN}/group_device ] ; then + _tmp_status_dir=$(cd -P ${_ccw_dir}/${CTC_READ_CHAN}/group_device; echo $PWD) + if [ "$_ccw_status_dir" ] && [ "$_ccw_status_dir" != "$_tmp_status_dir" ] ; then + mesg "CCW devices grouped to different devices" + exit 8 + fi + _ccw_status_dir=$_tmp_status_dir +fi +# +# Addresses are free (but may be bound to the wrong driver) +# +_ccw_drivers=${SYSFS}/bus/ccw/drivers +for i in ${CTC_READ_CHAN} ${CTC_WRITE_CHAN} + do + if [ "$CCW_CHAN_GROUP" = "lcs" ] + then + if [ -e "${_ccw_drivers}/ctcm/${i}" ] ; then + echo $i > ${_ccw_drivers}/ctcm/unbind + fi + if [ ! -e "${_ccw_drivers}/lcs/${i}" ] ; then + echo $i > ${_ccw_drivers}/ctcm/bind + fi + else + if [ -e "${_ccw_drivers}/lcs/${i}" ] ; then + echo $i > ${_ccw_drivers}/lcs/unbind + fi + if [ ! -e "${_ccw_drivers}/ctcm/${i}" ] ; then + echo $i > ${_ccw_drivers}/ctcm/bind + fi + fi + done + +debug_mesg "Group is ${_ccw_groupdir}/drivers/${CCW_CHAN_GROUP}/group" +if [ -z "$_ccw_status_dir" ] ; then + echo "$CTC_READ_CHAN,$CTC_WRITE_CHAN" > ${_ccw_groupdir}/drivers/${CCW_CHAN_GROUP}/group + if [ -e ${_ccw_dir}/${CTC_READ_CHAN}/group_device ] ; then + _ccw_status_dir=$(cd -P ${_ccw_dir}/${CTC_READ_CHAN}/group_device; echo $PWD) + fi fi -if [ ${ON_OFF} == 1 ]; then - add_cio_channel "${CTC_READ_CHAN},${CTC_WRITE_CHAN}" -else remove_cio_channel "${CTC_READ_CHAN}" - remove_cio_channel "${CTC_WRITE_CHAN}" +if [ -z "$_ccw_status_dir" -o ! -e "$_ccw_status_dir" ] ; then + mesg "Could not group $CCW_CHAN_GROUP devices $CTC_READ_CHAN/$CTC_WRITE_CHAN" + exit 9 +fi + +CCW_CHAN_ID=${_ccw_status_dir##*/} + +read _ccw_dev_status < $_ccw_status_dir/online + +if [ "$ONLINE" -eq 1 ]; then + # Check whether we need to do something + if [ "$_ccw_dev_status" -eq 0 ]; then + if [ "$CTC_MODE" -gt 0 -a "$CCW_CHAN_GROUP" != "lcs" ]; then + echo $CTC_MODE > $_ccw_status_dir/protocol + fi + # Set the device online + debug_mesg "Setting device online" + echo "1" > $_ccw_status_dir/online + # Re-read device status + read _ccw_dev_status < $_ccw_status_dir/online + if [ "$_ccw_dev_status" -eq 0 ]; then + mesg "Could not set device ${CCW_CHAN_ID} online" + exit 10 + fi + else + debug_mesg "Device ${CCW_CHAN_ID} is already online" + fi +else + if [ "$_ccw_dev_status" -eq 1 ]; then + # Set the device offline + debug_mesg "Setting device offline" + echo "$ONLINE" > $_ccw_status_dir/online + + # Re-read to check whether we have succeeded + _ccw_dev_status=$(cat $_ccw_status_dir/online) + if [ "$_ccw_dev_status" -ne "$ONLINE" ]; then + mesg "Could not set device ${CCW_CHAN_ID} offline" + exit 11 + fi + else + debug_mesg "Device ${CCW_CHAN_ID} is already offline" + fi + # Always reset CTC Protocol + if [ "$CCW_CHAN_GROUP" != "lcs" ]; then + echo 0 > $_ccw_status_dir/protocol + fi +fi + +RULES_DIR=/etc/udev/rules.d +RULES_FILE=51-${CCW_CHAN_GROUP}-${CCW_CHAN_ID}.rules + +if [ -d "$RULES_DIR" ]; then + if [ -f ${RULES_DIR}/${RULES_FILE} ]; then + rm -f ${RULES_DIR}/${RULES_FILE} + fi + remove_channel_for_cio "$CTC_READ_CHAN" + remove_channel_for_cio "$CTC_WRITE_CHAN" + + if [ "$ONLINE" -eq "1" ]; then + add_channel_for_cio "$CTC_READ_CHAN,$CTC_WRITE_CHAN" + # Write a new udev rules file + cat > ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} < ] [use_diag] # -# -f Override safety checks -# -t DASD type. Must be provided if -f is used. Only dasd-eckd and -# dasd-fba are supported - Deprecated +# -f force creation of udev rules, do not check values in /sys. +# -t DASD type. Must be provided if -f is used. # 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. +# 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 # use_diag = 0 to _not_ use z/VM DIAG250 I/O, which is the default # 1 to use z/VM DIAG250 I/O # # Return values: -# Return codes are determined by the chzdev command. +# 1 If the "Usage:" line is displayed, not enough parameters specified. +# 1 sysfs not mounted (if the "Usage:" line is not displayed). +# 2 Invalid status for +# 3 No device found for +# 4 Could not change state of the device +# 5 Device is not a DASD +# 6 Could not load module +# 7 Failed to activate DASD +# 8 DASD not formatted +# 9 Only dasd-fba or dasd-eckd is supported. # +if [ "${DEBUG}" != "yes" ]; then + DEBUG="no" +fi + +exitcode=0 +DASD_FORCE=0 +DASD_TYPE="unknown" + +DATUM=$(date) + +add_channel_for_cio() { + echo "$* # $DATUM" >> /boot/zipl/active_devices.txt +} + +remove_channel_for_cio() { + [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^$1/d" /boot/zipl/active_devices.txt +} + mesg () { echo "$@" } debug_mesg () { - case "${DEBUG}" in + case "$DEBUG" in yes) mesg "$@" ;; *) ;; esac } -add_cio_channel() { - echo "$* # ${DATE}" >> /boot/zipl/active_devices.txt -} - -remove_cio_channel() { - [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^${1}/d" /boot/zipl/active_devices.txt -} - -usage(){ - echo "Usage: ${0} [-f -t ] [use_diag]" - echo - echo " -f Override safety checks" - echo " -t DASD type. Must be provided if -f is used. Only dasd-eckd and" - echo " dasd-fba are supported - Deprecated" - 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" - echo " this is 0, but it could be non-zero" - echo " ssss is the four digit subchannel address of the device, in" - echo " hexidecimal, with leading zeros." - echo " online = 0 to take the device offline" - echo " 1 to bring the device online" - echo " use_diag = 0 to _not_ use z/VM DIAG250 I/O, which is the default" - echo " 1 to use z/VM DIAG250 I/O" -} - -if [ "${DEBUG}" != "yes" ]; then - DEBUG="no" +if [ $# -lt 2 ] ; then + echo "Usage: $0 [options] [use_diag]" + echo + echo " -f force creation of udev rules, do not check values in /sys." + echo " -t DASD type. Must be provided if -f is used." + 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" + echo " use_diag = 0 to _not_ use z/VM DIAG250 I/O, which is the default" + echo " 1 to use z/VM DIAG250 I/O" + exit 1 fi -DATE=$(date) - -DASD_FORCE=0 - -############################################################ -# Parse the parameters from the command line -# -ARGS=$(getopt --options ft: -n "dasd_configure" -- "$@") -if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi - -eval set -- "${ARGS}" -debug_mesg "All the parms passed were ${ARGS}" - -while true; do - case "${1}" in - -f) debug_mesg "This used to mean udev rules will always be generated." - debug_mesg "For chzdev, it means safety checks will be overridden." - debug_mesg "Kinda sorta the same thing, really." - PARM_LIST="${PARM_LIST} -f" - DASD_FORCE=1 - shift 1 - ;; - -t) debug_mesg "This used to set the card type to ${2}" - debug_mesg "Now it gets ignored." - shift 2 - ;; - --) debug_mesg "Found the end of parms indicator: --" - shift 1 - break - ;; - *) debug_mesg "At the catch-all select entry" - debug_mesg "What was selected was ${1}" - shift 1 - ;; - esac +while [ $# -gt 0 ] ; do + case "$1" in + -f) # force creation of udev rules, do not check values in /sys + DASD_FORCE=1 + ;; + -t*) # drive type. Must be provided if -f is used. + if [ "$1" = "-t" ] ; then + if [ "$2" = "dasd-eckd" -o "$2" = "dasd-fba" ]; then + DASD_TYPE=$2 + shift + else + debug_mesg "Only dasd-eckd or dasd-fba are supported." + exit 9 + fi + fi + ;; + *) + break; + ;; + esac + shift done -CCW_CHAN_ID=${1} -ON_OFF=${2} -USE_DIAG=${3} +if [ $DASD_FORCE -eq 0 ]; then + # Get the mount point for sysfs + while read MNTPT MNTDIR MNTSYS MNTTYPE; do + if test "$MNTSYS" = "sysfs"; then + SYSFS="$MNTDIR" + break; + fi + done &1 > /dev/null + if [ -x /sbin/vmcp -a $? -eq 0 ]; then + # Unconditionally load the vmcp module, loader might be broken + [ -x /sbin/modprobe ] && /sbin/modprobe -q vmcp + # Wait until udev is settled + [ -x /sbin/udevadm ] && /sbin/udevadm settle --timeout=30 + + # Check read-only status of virtual DASDs from z/VM + if /sbin/vmcp q v dasd > /dasd_attr.lst 2> /dev/null; then + while read x dev type label attr1 attr2 rest; do + dev=`echo $dev|tr A-F a-f` + if test "$type" = "ON"; then + attr="$attr2" + else + attr="$attr1" + fi + if [ "$CCW_CHAN_ID" = "0.0.$dev" ]; then + if test "$attr" = "R/O"; then + _ccw_use_readonly="1" + fi + fi + done < /dasd_attr.lst + fi + rm -f /dasd_attr.lst + fi # if [ -x /sbin/vmcp -a $? -eq 0 ] + + if [ "$ONLINE" -eq 1 ]; then + # Check whether we need to do something + read _ccw_use_diag < $_ccw_status_dir/use_diag + + if [ "$_ccw_use_diag" -ne "$USE_DIAG" ] && + [ "$_ccw_dev_status" -eq 1 ] ; then + # We need to change the DIAG access mode + # so we have to set the device offline first + debug_mesg "Setting device offline for DIAG access" + echo "0" > $_ccw_status_dir/online + # Re-read device status + read _ccw_dev_status < $_ccw_status_dir/online + if [ "$_ccw_dev_status" -ne 0 ]; then + mesg "Could not set the device offline for DIAG access" + exit 4 + fi + fi + + if [ "$_ccw_dev_status" -eq 0 ]; then + # Set readonly access if detected + if [ "$_ccw_use_readonly" ]; then + debug_mesg "Setting device read-only" + echo 1 > $_ccw_status_dir/readonly + fi + + if [ "$USE_DIAG" -eq 1 ]; then + # Load the diag module if possible + [ -x /sbin/modprobe ] && /sbin/modprobe -q dasd_diag_mod + _has_dasd_diag=$(/bin/sed -n '/^dasd_diag_mod/p' /proc/modules) + if [ "$_has_dasd_diag" ]; then + # DIAG mode is special: + # We can only be sure if DIAG is available + # _after_ we have activated the device + debug_mesg "Activating DIAG access mode" + echo "$USE_DIAG" > $_ccw_status_dir/use_diag + read _ccw_use_diag < $_ccw_status_dir/use_diag + # Set the device online + debug_mesg "Setting device online" + echo "1" > $_ccw_status_dir/online 2>/dev/null + # Re-read device status + read _ccw_dev_status < $_ccw_status_dir/online + if [ "$_ccw_dev_status" -eq 0 ]; then + mesg "Could not activate DIAG access mode for device ${CCW_CHAN_ID}" + USE_DIAG=0 + echo "$USE_DIAG" > $_ccw_status_dir/use_diag + # Set the device online + debug_mesg "Setting device online" + echo "1" > $_ccw_status_dir/online + else + MODULE=dasd_diag_mod + fi + else + debug_mesg "DIAG mode not available" + USE_DIAG=0 + # Set the device online + debug_mesg "Setting device online" + echo "1" > $_ccw_status_dir/online + fi # if [ "$_has_dasd_diag" ]; + else + if [ "$_ccw_use_diag" -eq 1 ] ; then + debug_mesg "Deactivating DIAG access mode" + echo "0" > $_ccw_status_dir/use_diag + read _ccw_use_diag < $_ccw_status_dir/use_diag + fi + # Set the device online + debug_mesg "Setting device online" + echo "1" > $_ccw_status_dir/online + fi # if [ "$USE_DIAG" -eq 1 ] + + # Re-read device status + read _ccw_dev_status < $_ccw_status_dir/online + if [ "$_ccw_dev_status" -eq 0 ]; then + mesg "Could not set device ${CCW_CHAN_ID} online" + exit 4 + fi + + # Wait for the device to come online + read _dasd_state < $_ccw_status_dir/status + i=0 + while [ "$_dasd_state" != "online" ] ; do + if [ "$_dasd_state" = "unformatted" ] ; then + mesg "Device ${CCW_CHAN_ID} is unformatted" + exitcode=8 + break + fi + [ $i -gt 30 ] && break + i=$(expr $i + 1) + sleep .1 + read _dasd_state < $_ccw_status_dir/status + done + else + debug_mesg "Device ${CCW_CHAN_ID} is already online" + fi # if [ "$_ccw_dev_status" -eq 0 ] + + read _dasd_state < $_ccw_status_dir/status + if [ "$_dasd_state" != "online" ] && [ "$_dasd_state" != "unformatted" ] ; then + mesg "Failed to activate device ${CCW_CHAN_ID}, device in state $_dasd_state" + exit 7 + fi + else + if [ "$_ccw_dev_status" -eq 1 ]; then + # Set the device offline + debug_mesg "Setting device offline" + echo "$ONLINE" > $_ccw_status_dir/online + + # Re-read to check whether we have succeeded + _ccw_dev_status=$(cat $_ccw_status_dir/online) + if [ "$?" -ne 0 -o "$_ccw_dev_status" -ne "$ONLINE" ]; then + mesg "Could not set device ${CCW_CHAN_ID} offline" + exit 4 + fi + else + debug_mesg "Device ${CCW_CHAN_ID} is already offline" + fi + + if [ -d "$_ccw_status_dir" ] ; then + # Always disabling DIAG access + echo "0" > $_ccw_status_dir/use_diag + fi + + # Set readonly access if detected + if [ "$_ccw_use_readonly" ]; then + debug_mesg "Setting device read-only" + echo 1 > $_ccw_status_dir/readonly + fi + fi # if [ "$ONLINE" -eq 1 ] + + # Wait until udev is settled + [ -x /sbin/udevadm ] && /sbin/udevadm settle --timeout=30 + +fi # Second instance of if [ $DASD_FORCE -eq 0 ] + +if [ $DEBUG = "no" ]; then + RULES_DIR=/etc/udev/rules.d +else + RULES_DIR=. fi -if [ "${ON_OFF}" == 0 ]; then - debug_mesg "chzdev -d dasd ${CCW_CHAN_ID}" - chzdev -d dasd ${CCW_CHAN_ID} -elif [ "${ON_OFF}" == 1 ]; then - debug_mesg "chzdev -e dasd ${CCW_CHAN_ID} ${PARM_LIST}" - chzdev -e dasd ${CCW_CHAN_ID} ${PARM_LIST} -else mesg "You must specify a 0 or a 1 for the online/offline attribute." - usage - exit 1 +RULES_FILE=51-dasd-${CCW_CHAN_ID}.rules + +if [ -d "$RULES_DIR" ]; then + if [ -f ${RULES_DIR}/${RULES_FILE} ]; then + rm -f ${RULES_DIR}/${RULES_FILE} + fi + remove_channel_for_cio "${CCW_CHAN_ID}" + + if [ "$ONLINE" -eq "1" ]; then + add_channel_for_cio "${CCW_CHAN_ID}" + # Write a new hwcfg file + cat > ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} < ] [-o "Values"] -n -p # # -i Configure IP takeover # -l Configure Layer2 support -# -f Override safety checks -# -t Valid cardtypes are: qeth, hsi - Deprecated +# -f force creation of udev rules, do not check values in /sys +# -t Valid cardtypes are: qeth, hsi, osn # -o General QETH options, separated by spaces -# -n QETH port number to use, 0 or 1. Only needed for real, not virtual -# devices. -# -p QETH Portname to use - Deprecated. OSAs no longer need a port name. +# -n QETH port number to use, 0 or 1. Only needed for real, not virtual devices. +# -p QETH Portname to use. Only needed if sharing a real OSA with z/OS. # read/write/data chan = 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. +# 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 values: -# Return codes are determined by the chzdev command. +# 1 sysfs not mounted +# 2 Invalid status for +# 3 No device found for read channel +# 4 No device found for write channel +# 5 No device found for data channel +# 6 Invalid device type +# 7 Could not load module +# 8 CCW devices grouped different devices +# 9 Could not group devices +# 10 Could not set device online +# 11 Could not set device offline # -mesg () { - echo "$@" -} - -debug_mesg () { - case "${DEBUG}" in - yes) mesg "$@" ;; - *) ;; - esac -} - -add_cio_channel() { - echo "$* # ${DATE}" >> /boot/zipl/active_devices.txt -} - -remove_cio_channel() { - [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^${1}/d" /boot/zipl/active_devices.txt -} - -usage(){ - echo "Usage: ${0} [options] " - echo " -i Configure IP takeover" - echo " -l Configure Layer2 support" - echo " -f Override safety checks" - echo " -t Valid cardtypes are: qeth, hsi - Deprecated." - echo " -o General QETH options, separated by spaces" - echo " -n QETH port number to use, 0 or 1. Only needed for real, not virtual" - echo " devices." - echo " -p QETH Portname to use - Deprecated. OSAs no longer need a port name." - echo " read/write/data chan = x.y.ssss where" - echo " x is always 0 until IBM creates something that" - echo " uses that number" - echo " y is the logical channel subsystem (lcss)" - echo " number. Most often this is 0, but it could" - echo " be non-zero" - echo " ssss is the four digit subchannel address of" - echo " the device, in hexidecimal, with leading" - echo " zeros." - echo " online = 0 to take the device offline" - echo " 1 to bring the device online" -} - if [ "${DEBUG}" != "yes" ]; then DEBUG="no" fi -DATE=$(date) +QETH_FORCE=0 -############################################################ -# Parse the parameters from the command line -# -ARGS=$(getopt --options ifln:o:p:t: -n "qeth_configure" -- "$@") -if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi +mesg () { + echo "$@" +} -eval set -- "${ARGS}" -debug_mesg "All the parms passed were ${ARGS}" +DATUM=$(date) -# Set some defaults -LAYER_MODE="layer2=0" +add_channel_for_cio() { + echo "$* # $DATUM" >> /boot/zipl/active_devices.txt +} -while true; do - case "${1}" in - -i) debug_mesg "Configure IP takeover" - PARM_LIST="${PARM_LIST} ipa_takeover/enable=1" - shift 1 - ;; - -f) debug_mesg "This used to mean udev rules will always be generated." - debug_mesg "For chzdev, it means safety checks will be overridden." - debug_mesg "Kinda sorta the same thing, really." - PARM_LIST="${PARM_LIST} -f" - shift 1 - ;; - -l) debug_mesg "Configure Layer 2 support" - LAYER_MODE="layer2=1" - shift 1 - ;; - -n) debug_mesg "Set QETH port number to ${2}" - PARM_LIST="${PARM_LIST} portno=${2}" - shift 2 - ;; - -o) debug_mesg "Add the following arbitrary parms: ${2}" - PARM_LIST="${PARM_LIST} ${2}" - shift 2 - ;; - -p) debug_mesg "QETH Port name is no longer used, don't specify it: ${2}" - shift 2 - ;; - -t) debug_mesg "This used to set the card type to ${2}" - debug_mesg "Now it gets ignored." - shift 2 - ;; - --) debug_mesg "Found the end of parms indicator: --" - shift 1 - break - ;; - *) debug_mesg "At the catch-all select entry" - debug_mesg "What was selected was ${1}" - shift 1 - ;; - esac +remove_channel_for_cio() { + [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^$1/d" /boot/zipl/active_devices.txt +} + +debug_mesg () { + case "$DEBUG" in + yes) mesg "$@" ;; + *) ;; + esac +} + +while [ $# -gt 0 ] ; do + case "$1" in + -i) + # Configure IP takeover + QETH_IPA_TAKEOVER=1 + ;; + -f) # force creation of udev rules, do not check values in /sys + QETH_FORCE=1 + ;; + -l) + # Configure Layer2 support + QETH_LAYER2_SUPPORT=1 + ;; + -n*) + # QETH port number to use + if [ "$1" = "-n" ] ; then + QETH_PORTNO=$2 + shift + else + QETH_PORTNO=${1#-n} + fi + ;; + -o) + # General QETH options, separated by spaces + QETH_OPTIONS=$2 + shift + ;; + -p*) + # QETH Portname to use + if [ "$1" = "-p" ] ; then + QETH_PORTNAME=$2 + shift + else + QETH_PORTNAME=${1#-p} + fi + ;; + -t*) # Card type. Must be provided if -f is used. + if [ "$1" = "-t" ] ; then + if [ "$2" = "qeth" -o "$2" = "hsi" -o "$2" = "osn" ]; then + QETH_CARD=$2 + shift + else + mesg "Only qeth, hsi and osn are supported." + exit 6 + fi + fi + CCW_DRV="$QETH_CARD" + ;; + *) + break; + ;; + esac + shift done -QETH_READ_CHAN=${1} -QETH_WRITE_CHAN=${2} -QETH_DATA_CHAN=${3} -ON_OFF=${4} +if [ $QETH_FORCE -eq 0 ]; then +# Get the mount point for sysfs + while read MNTPT MNTDIR MNTSYS MNTTYPE; do + if test "$MNTSYS" = "sysfs"; then + SYSFS="$MNTDIR" + break; + fi + done " + echo " -i Configure IP takeover" + echo " -l Configure Layer2 support" + echo " -f force creation of udev rules, do not check values in /sys" + echo " -t Valid cardtypes are: qeth, hsi, osn" + echo " -o General QETH options, separated by spaces" + echo " -n QETH port number to use, 0 or 1. Only needed for real, not virtual devices." + echo " -p QETH Portname to use. Only needed if sharing a real OSA with z/OS." + echo " read/write/data chan = 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 -RC=${?} -if [ ${RC} -ne 0 ]; then - exit ${RC} +if [ -z "$ONLINE" ] || [ "$ONLINE" -ne "1" -a "$ONLINE" -ne "0" ]; then + mesg "Invalid device status $ONLINE" + exit 2 fi -if [ ${ON_OFF} == 1 ]; then - add_cio_channel "${QETH_READ_CHAN},${QETH_WRITE_CHAN},${QETH_DATA_CHAN}" -else remove_cio_channel "${QETH_READ_CHAN}" - remove_cio_channel "${QETH_WRITE_CHAN}" - remove_cio_channel "${QETH_DATA_CHAN}" +if [ $QETH_FORCE -eq 0 ]; then +_ccw_dir=${SYSFS}/bus/ccw/devices + +# Convert any hexidecimal numbers to lower case +QETH_READ_CHAN=$(echo ${QETH_READ_CHAN} | tr "[A-Z]" "[a-z]") +QETH_WRITE_CHAN=$(echo ${QETH_WRITE_CHAN} | tr "[A-Z]" "[a-z]") +QETH_DATA_CHAN=$(echo ${QETH_DATA_CHAN} | tr "[A-Z]" "[a-z]") + +debug_mesg "Configuring QETH device ${QETH_READ_CHAN}/${QETH_WRITE_CHAN}/${QETH_DATA_CHAN}" + + +if test ! -d "$_ccw_dir/$QETH_READ_CHAN" ; then + mesg "No device ${QETH_READ_CHAN}" + exit 3 fi +if test ! -d "$_ccw_dir/$QETH_WRITE_CHAN" ; then + mesg "No device ${QETH_WRITE_CHAN}" + exit 4 +fi +if test ! -d "$_ccw_dir/$QETH_DATA_CHAN" ; then + mesg "No device ${QETH_DATA_CHAN}" + exit 5 +fi + +CCW_CHAN_GROUP= +for ccw in $_ccw_dir/$QETH_READ_CHAN $_ccw_dir/$QETH_WRITE_CHAN $_ccw_dir/$QETH_DATA_CHAN; do + + read _cu_type < $ccw/cutype + read _dev_type < $ccw/devtype + + case "$_cu_type" in + 1731/01|1731/02) + # OSA/Express / Guest LAN + CCW_DRV="qeth" + QETH_CARD="qeth" + ;; + 1731/05) + # Hipersockets + CCW_DRV="qeth" + QETH_CARD="hsi" + ;; + 1731/06) + # OSA/N + CCW_DRV="qeth" + QETH_CARD="osn" + ;; + *) + CCW_DRV= + ;; + esac + + if [ -z "$CCW_DRV" ]; then + mesg "Not a valid QETH device (cu $_cutype, dev $_devtype)" + exit 6 + fi +done +fi # end QETH_FORCE + +# Portname is only required for OSA/Express +if [ -n "$QETH_PORTNAME" -a "$QETH_CARD" != "qeth" ] ; then + debug_mesg "No portname required for $QETH_CARD adapters" + QETH_PORTNAME= +fi + +if [ $QETH_FORCE -eq 0 ]; then +_ccw_groupdir=${SYSFS}/bus/ccwgroup + +# Check for modules +if test ! -d "${_ccw_groupdir}/drivers/${CCW_DRV}" ; then + /sbin/modprobe $CCW_DRV + + # Re-check whether module loading has succeeded + if test ! -d "${_ccw_groupdir}/drivers/${CCW_DRV}"; then + mesg "Could not load module ${CCW_DRV}" + exit 7 + fi +fi + +# Check for grouping +_ccwgroup_dir= +if [ -e ${_ccw_dir}/${QETH_READ_CHAN}/group_device ] ; then + _ccwgroup_dir=$(cd -P ${_ccw_dir}/${QETH_READ_CHAN}/group_device; echo $PWD) +fi +if [ -e ${_ccw_dir}/${QETH_WRITE_CHAN}/group_device ] ; then + _tmp_status_dir=$(cd -P ${_ccw_dir}/${QETH_READ_CHAN}/group_device; echo $PWD) + if [ "$_ccwgroup_dir" ] && [ "$_ccwgroup_dir" != "$_tmp_status_dir" ] ; then + mesg "CCW devices grouped to different devices" + exit 8 + fi + _ccwgroup_dir=$_tmp_status_dir +fi +if [ -e ${_ccw_dir}/${QETH_DATA_CHAN}/group_device ] ; then + _tmp_status_dir=$(cd -P ${_ccw_dir}/${QETH_DATA_CHAN}/group_device; echo $PWD) + if [ "$_ccwgroup_dir" ] && [ "$_ccwgroup_dir" != "$_tmp_status_dir" ] ; then + mesg "CCW devices grouped to different devices" + exit 8 + fi + _ccwgroup_dir=$_tmp_status_dir +fi +if [ -z "$_ccwgroup_dir" ] ; then + echo "$QETH_READ_CHAN,$QETH_WRITE_CHAN,$QETH_DATA_CHAN" > ${_ccw_groupdir}/drivers/${CCW_DRV}/group + if [ -e ${_ccw_dir}/${QETH_READ_CHAN}/group_device ] ; then + _ccwgroup_dir=$(cd -P ${_ccw_dir}/${QETH_READ_CHAN}/group_device; echo $PWD) + fi +fi + +if [ -z "$_ccwgroup_dir" -o ! -e "$_ccwgroup_dir" ] ; then + mesg "Could not group $CCW_DRV devices $QETH_READ_CHAN/$QETH_WRITE_CHAN/$QETH_DATA_CHAN" + exit 9 +fi + +CCW_CHAN_ID=${_ccwgroup_dir##*/} + +read _online < $_ccwgroup_dir/online + +if [ "$ONLINE" -eq 1 ]; then + # Check whether we need to do something + # We do not check for the value of CCW_CHAN_MODE, since we + # might want to switch back and forth between several modes + if test "$_online" -eq "0" ; then + # Set the portname + if [ "$QETH_PORTNAME" ]; then + mesg "(portname $QETH_PORTNAME) " + echo "$QETH_PORTNAME" > $_ccwgroup_dir/portname + fi + # Activate Layer2 support + if [ -w "$_ccwgroup_dir/layer2" ] ; then + if [ "$QETH_LAYER2_SUPPORT" = "1" ]; then + mesg "(Layer2) " + echo 1 > $_ccwgroup_dir/layer2 + else + echo 0 > $_ccwgroup_dir/layer2 + fi + else + QETH_LAYER2_SUPPORT= + fi + # Enable IP address takeover + if [ "$QETH_IPA_TAKEOVER" ]; then + if [ "$QETH_IPA_TAKEOVER" = "1" ]; then + mesg "(IP takeover) " + echo 1 > $_ccwgroup_dir/ipa_takeover/enable + fi + fi + # Relative port number + if [ -w "$_ccwgroup_dir/portno" ] ; then + if [ -n "$QETH_PORTNO" ]; then + mesg "(Port $QETH_PORTNO) " + # This may fail, but trial and error is the only way to tell. + echo "$QETH_PORTNO" > $_ccwgroup_dir/portno + fi + else + unset QETH_PORTNO + fi + # Set additional options + if [ "$QETH_OPTIONS" ]; then + for opt in $QETH_OPTIONS; do + set -- $(IFS='='; echo $opt) + opt_name=$1 + opt_val=$2 + case "$opt_name" in + portname|ipa_takeover|layer2) + # These options are set above + debug_mesg "Invalid option $opt_name" + ;; + *) + if [ "$opt_name" -a "$opt_val" ]; then + if [ -w "$_ccwgroup_dir/$opt_name" ]; then + mesg "($opt_name) " + echo "$opt_val" > $_ccwgroup_dir/$opt_name + if [ $? -eq 0 ] ; then + cur_opts="$cur_opts ${opt_name}=${opt_val}" + fi + else + # Skip invalid options + debug_mesg "Invalid option $opt_name" + fi + fi + ;; + esac + done + # Update options list + QETH_OPTIONS="$cur_opts" + fi + + echo "1" > $_ccwgroup_dir/online 2> /dev/null + # Re-read device status + read _ccw_dev_status < $_ccwgroup_dir/online + if [ "$_ccw_dev_status" -eq 0 ]; then + mesg "Could not set device ${CCW_CHAN_ID} online" + exit 10 + fi + else + debug_mesg "Device ${CCW_CHAN_ID} is already online" + fi +else + if [ "$_online" -eq 1 ]; then + # Set the device offline + debug_mesg "Setting device offline" + echo "$ONLINE" > $_ccwgroup_dir/online + + # Re-read to check whether we have succeeded + _online=$(cat $_ccwgroup_dir/online) + if [ "$_online" -ne "$ONLINE" ]; then + mesg "Could not set device ${CCW_CHAN_ID} offline" + exit 11 + fi + else + debug_mesg "Device ${CCW_CHAN_ID} is already offline" + fi + echo 1 > $_ccwgroup_dir/ungroup +fi +else + CCW_CHAN_ID=$QETH_READ_CHAN +fi # QETH_FORCE + +if [ $DEBUG = "no" ]; then + RULES_DIR=/etc/udev/rules.d +else + RULES_DIR=. +fi + +RULES_FILE=51-${QETH_CARD}-${CCW_CHAN_ID}.rules + +if [ -d "$RULES_DIR" ]; then + if [ -f ${RULES_DIR}/${RULES_FILE} ]; then + rm -f ${RULES_DIR}/${RULES_FILE} + fi + remove_channel_for_cio "${QETH_READ_CHAN}" + remove_channel_for_cio "${QETH_WRITE_CHAN}" + remove_channel_for_cio "${QETH_DATA_CHAN}" + + if [ "$ONLINE" -eq "1" ]; then + add_channel_for_cio "${QETH_READ_CHAN},${QETH_WRITE_CHAN},${QETH_DATA_CHAN}" + # Write a new udev rules file + cat > ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} <> ${RULES_DIR}/${RULES_FILE} < # # 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. +# 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 values: -# Return codes are determined by the chzdev command. +# 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 "$@" ;; - *) ;; + case "$DEBUG" in + yes) mesg "$@" ;; + *) ;; esac } -usage(){ - 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" - echo " this is 0, but it could be non-zero" - echo " ssss is the four digit subchannel address of the device, in" - echo " hexidecimal, with leading zeros." - echo " online = 0 to take the device offline" - echo " 1 to bring the device online" -} - -if [ "${DEBUG}" != "yes" ]; then - DEBUG="no" +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 -CCW_CHAN_ID=${1} -FCP_WWPN="${2}" -FCP_LUN="${3}" -ON_OFF=${4} +# 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} < # # 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. +# 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 -# Return codes are determined by the chzdev command. +# 1 sysfs not mounted +# 2 invalid value for +# 3 device does not exist +# 4 module zfcp could not be loaded +# 5 adapter status could not be changed +# 6 wwpn ports still active +# 10 adapter active but allow_lun_scan active # +if [ "${DEBUG}" != "yes" ]; then + DEBUG="no" +fi + +DATUM=$(date) + +add_channel_for_cio() { + echo "$* # $DATUM" >> /boot/zipl/active_devices.txt +} + +remove_channel_for_cio() { + [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^$1/d" /boot/zipl/active_devices.txt +} + mesg () { echo "$@" } debug_mesg () { - case "${DEBUG}" in - yes) mesg "$@" ;; - *) ;; + case "$DEBUG" in + yes) mesg "$@" ;; + *) ;; esac } -add_cio_channel() { - echo "$* # ${DATE}" >> /boot/zipl/active_devices.txt -} - -remove_cio_channel() { - [ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^${1}/d" /boot/zipl/active_devices.txt -} - -usage(){ - 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" - echo " this is 0, but it could be non-zero" - echo " ssss is the four digit subchannel address of the device, in" - echo " hexidecimal, with leading zeros." - echo " online = 0 to take the device offline" - echo " 1 to bring the device online" -} - -if [ "${DEBUG}" != "yes" ]; then - DEBUG="no" +if [ $# -ne 2 ] ; 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 -DATE=$(date) +# Get the mount point for sysfs +while read MNTPT MNTDIR MNTSYS MNTTYPE; do + if test "$MNTSYS" = "sysfs"; then + SYSFS="$MNTDIR" + break; + fi +done $_zfcp_dir/online + + # Now wait for the adapter to initialize + /sbin/udevadm settle + fi + + for loop in 1 2 3 4 5 ; do + read status < /sys/bus/ccw/devices/$CCW_CHAN_ID/status + (( $status & 0x10000000 )) && break; + done + read wwpn_status < /sys/bus/ccw/devices/$CCW_CHAN_ID/status + if !(( $wwpn_status & 0x10000000 )) ; then + echo 0 > /sys/bus/ccw/devices/$CCW_CHAN_ID/online + mesg "Could not activate adapter, status $wwpn_status" + exit 5 + fi + + # Write the configuration file + if test -d ${RULES_DIR}; then + cat > ${RULES_DIR}/${RULES_FILE} < ${_zfcp_dir}/online + # Re-read to check whether we have succeeded + _ccw_dev_status=$(cat $_zfcp_dir/online) + if [ "$_ccw_dev_status" -ne "$ONLINE" ]; then + mesg "Could not change status of device ${CCW_CHAN_ID} to $ONLINE" + exit 5 + fi + echo "${CCW_CHAN_ID}" > /sys/bus/ccw/drivers/zfcp/unbind + echo "${CCW_CHAN_ID}" > /sys/bus/ccw/drivers/zfcp/bind + remove_channel_for_cio "${CCW_CHAN_ID}" + + debug_mesg "zFCP adapter at ${CCW_CHAN_ID} deactivated" +fi + +# EOF