linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Wellnitz <Jamie.Wellnitz@emulex.com>
To: linux-hotplug@vger.kernel.org
Subject: persistent SCSI tape names
Date: Mon, 29 Jan 2007 19:34:27 +0000	[thread overview]
Message-ID: <20070129193427.GA15808@ma.emulex.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2167 bytes --]

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:

diff --git a/etc/udev/redhat/50-udev.rules b/etc/udev/redhat/50-udev.rules
index d72cb83..b7e7cc6 100644
--- a/etc/udev/redhat/50-udev.rules
+++ b/etc/udev/redhat/50-udev.rules
@@ -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
Jamie.Wellnitz@emulex.com

[-- Attachment #2: tape-name.sh --]
[-- Type: text/plain, Size: 935 bytes --]

#!/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"

[-- Attachment #3: Type: text/plain, Size: 347 bytes --]

-------------------------------------------------------------------------
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

[-- Attachment #4: Type: text/plain, Size: 226 bytes --]

_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

                 reply	other threads:[~2007-01-29 19:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070129193427.GA15808@ma.emulex.com \
    --to=jamie.wellnitz@emulex.com \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).