persistent SCSI tape names
Hi,
I'm trying to add persistent SCSI tape names to the etc/udev/redhat/50-udev.rules file. The easiest implementation seems to be something like:
etc/udev/redhat/50-udev.rules +11 -0
@@ -109,6 +109,17 @@ KERNEL=="nst*", GROUP="disk", MODE="0660" KERNEL=="osst*", GROUP="disk", MODE="0660" KERNEL=="nosst*", GROUP="disk", MODE="0660" +ACTION!="add", GOTO="persistent_tape_end" + +KERNEL=="nst[0-9]", BUS=="scsi", ENV{ID_SERIAL}=="", IMPORT{program}="/lib/udev/scsi_id -g -x -s %p -d $tempnode" +KERNEL=="nst[0-9]", BUS=="scsi", ENV{ID_SERIAL}=="?*", SYMLINK+="tapes/by-id/$env{ID_BUS}-$env{ID_SERIAL}" + +# type 8 devices are "Medium Changers" +KERNEL=="sg*", BUS=="scsi", SYSFS{type}=="8", ENV{ID_SERIAL}=="", IMPORT{program}="/lib/udev/scsi_id -g -x -s %p -d $tempnode" +KERNEL=="sg*", BUS=="scsi", SYSFS{type}=="8", ENV{ID_SERIAL}=="?*", SYMLINK+="tapes/by-id/$env{ID_BUS}-$env{ID_SERIAL}" + +LABEL="persistent_tape_end" + # diskonkey devices KERNEL=="diskonkey*", GROUP="disk", MODE="0640"
However this only supports 1 of the 8 names each tape device is assigned (e.g. st0, st0a, st0l, st0m, nst0, nst0a, nst0l, nst0m).
To provide a persistent name for each of the 8 names, I have to resort to having the udev rule invoke a shell script (called tape-names.sh - attached). The script handles 2 issues:
1. the device names ending in [alm] apparently do not support the page 0x83 inquiry to get a persistent ID, and
2. if udev sends multiple inquiries to a device at the same time, only one of them gets a response.
The script is invoked by these rules:
KERNEL=="st*", BUS=="scsi", PROGRAM="/etc/udev/scripts/tape-name.sh %k", SYMLINK+="tapes/by-id/%c" KERNEL=="nst*", BUS=="scsi", PROGRAM="/etc/udev/scripts/tape-name.sh %k", SYMLINK+="tapes/by-id/%c"
Is it better to use the simple naming method (and provide persistence for only one set of tape names) or to have a script bashing away with retry logic?
Thanks,
Jamie
[email protected]
#!/bin/bash
# this script is intended to be called by udev to provide a unique # persistent name for SCSI tape devices
#LOG=/etc/udev/tape-name.log
function log_text {
if [ -n "$LOG" ] ; then
echo "$*" >> $LOG
fi
}SCSI_ID="/lib/udev/scsi_id -g -u"
DEVICE=$1
SYSFS_TOP=/class/scsi_tape
PREFIX=${DEVICE%%st*}
SUFFIX=${DEVICE##${PREFIX}st[0-9]}
# remove prefix and suffix from device name
BASE_DEVICE=${DEVICE#${PREFIX}}
BASE_DEVICE=${BASE_DEVICE%${SUFFIX}}SYSFS=$SYSFS_TOP/$BASE_DEVICE
retries=7
ID=$($SCSI_ID -s $SYSFS)
while [ $? -ne 0 -a $retries -gt 0 ] ; do
((retries--))
if [ $retries -gt 0 ] ; then
log_text "$SCSI_ID failed for $DEVICE, retries left $retries" sleep 2
ID=$($SCSI_ID -s $SYSFS)
else
log_text "$SCSI_ID failed for $DEVICE, retries exhausted"
fi
done
log_text "For $DEVICE Using $BASE_DEVICE, id $ID"
# this echo produces the device's persistent name echo "$PREFIX$ID$SUFFIX"
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel