From d5291eed1c46e1c97831e771b2975575ba268992 Mon Sep 17 00:00:00 2001 From: Steffen Maier Date: Wed, 20 Jun 2018 17:59:53 +0200 Subject: [PATCH] lstape: fix SCSI HBA CCW device bus-ID e.g. for virtio-scsi-ccw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Get the SCSI HBA device bus-ID in general for HBAs on the CCW bus. Signed-off-by: Steffen Maier Reviewed-by: Fedor Loshakov Reviewed-by: Jens Remus Signed-off-by: Jan Höppner --- zconf/lstape | 25 +++++++++++++++++++++++-- zconf/lstape.8 | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/zconf/lstape b/zconf/lstape index 3c779751..e2410e1b 100755 --- a/zconf/lstape +++ b/zconf/lstape @@ -223,6 +223,24 @@ function SysfsCreateListCCW() { ' | sort } +# handle SCSI device not necessarily zfcp-attached, e.g. virtio-scsi-ccw +function SCSISearchCCWBusid() +{ + local SCSI_DEV=$1 + local SDEVCAN=$(readlink -e $SCSI_DEV) + while [ -n "$SDEVCAN" ]; do + # ascend to parent: strip last path part + SDEVCAN=${SDEVCAN%/*} + [ -h $SDEVCAN/subsystem ] || continue + local SUBSYSTEM=$(readlink -e $SDEVCAN/subsystem) + if [ "${SUBSYSTEM##*/}" = "ccw" ]; then + echo ${SDEVCAN##*/} + return + fi + done + echo "N/A" +} + function SysfsCreateListSCSI() { for SCSI_DEV in $1/bus/scsi/devices/*:*:*:*; do @@ -335,8 +353,11 @@ function SysfsCreateListSCSI() $STATE if $VERBOSE; then - HBA_ID="N/A" - [ -r $SCSI_DEV/hba_id ] && HBA_ID=$(cat $SCSI_DEV/hba_id) + if [ -r $SCSI_DEV/hba_id ]; then + HBA_ID=$(cat $SCSI_DEV/hba_id) + else + HBA_ID=$(SCSISearchCCWBusid $SCSI_DEV) + fi WWPN="N/A" [ -r $SCSI_DEV/wwpn ] && WWPN=$(cat $SCSI_DEV/wwpn) printf "$SCSIVFORMAT" \ diff --git a/zconf/lstape.8 b/zconf/lstape.8 index 4d9f83a5..019b6e58 100644 --- a/zconf/lstape.8 +++ b/zconf/lstape.8 @@ -112,8 +112,9 @@ For SCSI devices, the --verbose option additionally displays: .TP .B HBA The device bus-ID of the FCP device +or of the virtio-scsi-ccw virtual HBA through which the tape drive is attached. -"N/A" if device is not attached through zfcp. +"N/A" if the device does not have a sysfs ancestor with subsystem ccw. .TP .B WWPN The WWPN (worldwide port name) of the tape drive in the SAN.