From 80e0c41b896e1eeffc594416b4c2787ed29363b6 Mon Sep 17 00:00:00 2001 From: Steffen Maier Date: Fri, 15 Jun 2018 20:09:13 +0200 Subject: [PATCH] lstape: fix output without SCSI generic (sg) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default bash setting have nullglob disabled so if $SCSI_DEV/scsi_generic* aka /sys/bus/scsi/devices/*:*:*:*/scsi_generic* does not match anything, it leaves the glob pattern unmodified and SG_DEV=$(basename $SG_DEV/*) results in the literal: * If $SG_INQ exists, it invoked sg_inq with more than the one allowed positional argument for a SCSI generic device node: sg_inq /dev/* Causing error messages and the usage of sg_inq to land in $TAPE_SERIAL. To not have to rely on the nullglob setting, explicitly check for the existence of $SCSI_DEV/scsi_generic before evaluating SG_DEV=$(basename $SG_DEV/*). Also handle availability of sg_inq but absence of scsi_generic individually to provide the user with a hint if only sg is missing. Suggested-by: Eric Farman Signed-off-by: Steffen Maier Reviewed-by: Jens Remus Cc: Eric Farman Signed-off-by: Jan Höppner --- zconf/lstape | 12 ++++++++++-- zconf/lstape.8 | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/zconf/lstape b/zconf/lstape index 5501cb11..91609fbb 100755 --- a/zconf/lstape +++ b/zconf/lstape @@ -48,6 +48,9 @@ function PrintUsage() { : -v|--version : Display the version of the tools package and : the lstape command. + : + :$(basename $0) without the --ccw-only option causes extra SAN traffic + :for each SCSI tape or changer device by invoking the sg_inq command. EOD } @@ -249,11 +252,16 @@ function SysfsCreateListSCSI() if [ -h $SG_DEV ]; then # deprecated sysfs layout SG_DEV=$(echo $SG_DEV | awk -F: '{print $NF}') - else + elif [ -d $SCSI_DEV/scsi_generic ]; then SG_DEV=$(basename $SG_DEV/*) + else + SG_DEV="" fi - if [ "$SG_INQ" != "" ]; then + if [ -z "$SG_DEV" ]; then + SG_DEV="N/A" + TAPE_SERIAL="NO/SG" + elif [ "$SG_INQ" != "" ]; then TAPE_SERIAL=$( sg_inq /dev/$SG_DEV | awk '/serial/{print $NF}' diff --git a/zconf/lstape.8 b/zconf/lstape.8 index 069a8588..80d54e53 100644 --- a/zconf/lstape.8 +++ b/zconf/lstape.8 @@ -36,7 +36,13 @@ IBM tape driver this would be "IBMtape" or "IBMchanger". If "N/A" is shown, the correct driver could not be obtained. The serial number of a SCSI tape can be displayed with the --verbose option. If -there is no sg_inq command available "NO/INQ" is shown as the tape's serial. +there is no sg_inq command available "NO/INQ" is shown as the serial number +of the tape. +If no SCSI generic (sg) kernel support is available, "NO/SG" is shown +as the serial number of the tape and "N/A" for the "Generic" column. + +The lstape command without the --ccw-only option causes extra SAN traffic +for each SCSI tape or changer device by invoking the sg_inq command. .SH OPTIONS .TP 8