From cdc787db1ba17dd2c0ed841fd7443bc32be63b65 Mon Sep 17 00:00:00 2001 From: Steffen Maier Date: Fri, 22 Jun 2018 19:44:05 +0200 Subject: [PATCH] lstape: fix to prefer sysfs to find lin_tape device name for SCSI device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should be more stable than parsing the IBM lin_tape proc-fs output. If sysfs is not available or provides no match, fall back to proc-fs. An alternative to "ls -1d ... | head -n1" would have been to use "shopt -s extglob; ls -d $SCSI_DEV/lin_tape/$DEV_NAME+([0-9])" but I did not want to have to rely on extglob potentially influencing other old code of lstape. Signed-off-by: Steffen Maier Reviewed-by: Jens Remus Signed-off-by: Jan Höppner --- zconf/lstape | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zconf/lstape b/zconf/lstape index cacd8923..5501cb11 100755 --- a/zconf/lstape +++ b/zconf/lstape @@ -291,6 +291,23 @@ function SysfsCreateListSCSI() if [ "$CHG_IDX" != "" ]; then TAPE_DEV=$CHG_IDX fi + elif [ "$(echo "$SCSI_LIST"|grep lin_tape)" != "" ]; then + # bash glob sorts so IBMtape0 comes before IBMtape0n + local IBM_PATH=$( + ls -1d $SCSI_DEV/lin_tape/$DEV_NAME[0-9]* | + head -n 1) + if [ -d "$IBM_PATH" ]; then + IBM_IDX=${IBM_PATH##*/} + else + # deprecated sysfs layout + IBM_IDX=$( + echo "$SCSI_LIST" | + awk -F: '/lin_tape\:'"$DEV_NAME"'[0-9]+$/{print $NF}' + ) + fi + if [ "$IBM_IDX" != "" ]; then + TAPE_DEV=$IBM_IDX + fi elif [ -r /proc/scsi/$DEV_NAME ]; then IBM_IDX=$( grep -wF "$SCSI_ID" /proc/scsi/$DEV_NAME |