Mapping /dev/*st0* to fixed names using scsi_id
Hi all,
I've been pounding my head against this issue for a while, and cursing the lack of comments in the example rules for udev. Basically, I've got a tape library with two drives and a robot on a Debian system, with a bunch of SCSI devices including disks and tapes. The robot is easy, I just use the following snippet:
# SCSI ATL P1000 Autoloader - make if /dev/changer
BUS="scsi", SYSFS{model}="P1000 6220051",SYSFS{vendor}="ATL",SYMLINK="changer"
And it works fine. Now I want to map the two tape drives to some fixed names:
/dev/nst?a -> /dev/dlt7k-{left,right}easily. I used to do this with the script I posted way back in 2008 to list this, found at:
http://article.gmane.org/gmane.linux.hotplug.devel/12579
But I never followed up on it. Lately, it's been taking multiple invocations of 'udevadm trigger' after each reboot to make my tape devices show up properly. So now I'm trying to figure out what I can do.
Right now, I've got a rule which looks like this, which works, but maps to /dev/sg# instead of the proper /dev/nst#a device:
SUBSYSTEM="scsi_generic", PROGRAM="/lib/udev/scsi_id --replace-whitespace --whitelisted /dev/%k",RESULT="SQUANTUM_DLT7000_CX752S1059", SYMLINK="dlt7k-left"
I've looked at the /lib/udev/rules.d/60-persistent-storage-tape.rules but I honestly can't make heads or tails of the ${DEV_BSG} stuff, since it's not documented to explan what's really going on here.
I think I need to add the --whitelisted arg to the scsi_id command to make this section work properly:
KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", \
SUBSYSTEMS="scsi", KERNELS="[0-9]*:*[0-9]", \
ENV{BSG_DEV}="$root/bsg/$id"
KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", \
WAIT_FOR="$env{BSG_DEV}", \
ENV{ID_BUS}="scsi", \
IMPORT{program}="scsi_id --export --device=$env{BSG_DEV}"
KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}="?*", \
SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
KERNEL="st*[0-9]|nst*[0-9]", \
IMPORT{program}="path_id $devpath"
KERNEL="st*[0-9]", ENV{ID_PATH}="?*", \
SYMLINK+="tape/by-path/$env{ID_PATH}"
KERNEL="nst*[0-9]", ENV{ID_PATH}="?*", \
SYMLINK+="tape/by-path/$env{ID_PATH}-nst"But the path_id script called here is poorly documented and hard to follow. Sorry for sounding whiny, but it's a pain to figure out without well documented examples.
Can anyone point me in the right direction here?
Thanks,
John
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"John" = John Stoffel <[email protected]> writes:
John> I've been pounding my head against this issue for a while, and John> cursing the lack of comments in the example rules for udev.
I'm still cursing, but I've been reading the docs over and over again and I've come up with some ideas.
Basically, I need to map my tape device to a scsi_generic device, so I can then run '/lib/udev/scsi_id --whitelisted --export --device=%k' on the generic device, to get back a useable $ID_SERIAL that I can use to match.
I hit upon the idea of using the following as a basic match:
# Find SCSI_TAPE devices, export SCSI_ID env in "#:#:#:#" format
SUBSYSYEMS="scsi",ATTRS{type}="1",ENV{SCSI_ID}="%k"
# Wait for SCSI_ID, then get the /dev/sg# for this tape
SUBSYSYEMS="scsi",ATTRS{type}="1",WAIT_FOR="$env{SCSI_ID}", \
IMPORT{program}="/lib/udev/sg_dev $env{SCSI_ID}"
# Wait for SG_DEV, then get the /dev/sg# for this tape
SUBSYSYEMS="scsi",ATTRS{type}="1",WAIT_FOR="$env{SG_DEV}", \
IMPORT{program}="/lib/udev/scsi_id --replace-whitespace
--whitelisted --export --device=$env{SG_DEV}"
# Wait for ID_SERIAL and then name the tape device
SUBSYSYEMS="scsi",ATTRS{type}="1",WAIT_FOR="$env{ID_SERIAL}", \
ENV{ID_SERIAL}="SQUANTUM_DLT7000_CX752S1059", SYMLINK="dlt7k-left"And the /lib/udev/sg_dev script is just the trivially simple, but hard to do (to me at least) in udev script:
#!/bin/sh
lsscsi -g $1 | awk '{print "SG_DEV=" $NF}'BUT! This doesn't quite address all the issues, since I really need to have some way to create symlinks to a bunch of /dev/st#[alm ] devices, and I'm not sure how to do this.
Any hints?
I've also tried looking at the output of
udevadm info -a -p /sys/class/scsi_tape/st0 > /tmp/st0 udevadm info -a -p /sys/class/scsi_tape/st0a > /tmp/st0a
and diffing it, but I only see the following, which doesn't help me. Is there a way to view the minor number(s) of a device from within UDEV easily?
# diff -u /tmp/st0* |less
--- /tmp/st0 2009-06-04 16:58:44.000000000 -0400
+++ /tmp/st0a 2009-06-04 16:58:14.000000000 -0400
@@ -5,11 +5,11 @@
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device. - looking at device '/class/scsi_tape/st0':
- KERNEL="st0"
+ looking at device '/class/scsi_tape/st0a':
+ KERNEL="st0a"
SUBSYSTEM="scsi_tape"
DRIVER=""
- ATTR{defined}="1"
+ ATTR{defined}="0"
ATTR{default_blksize}="-1"
ATTR{default_density}="-1"
ATTR{default_compression}="-1"
So I would suspect that Udev knows about the major/minor device numbers, but the docs on
http://reactivated.net/writing_udev_rules.html
don't talk about them at all to any useful degree.
Can anyone tell me if I'm on the right track here?
Thanks,
John
Hi,
I had similar issues with my collection of scsi tape drives, not all of which may be powered up.
the --page=0x80 does the trick.
my kernel is compiled with the SG version4 block device option enabled.
this is my 60-persistent-storage-tape.rules, hope it helps
ACTION!="add|change", GOTO="persistent_storage_tape_end"
# type 8 devices are "Medium Changers"
KERNEL="sg[0-9]*", SUBSYSTEMS="scsi", ATTRS{type}="8",
IMPORT{program}="scsi_id --sg-version=3 --page=0x80 --export
--whitelisted -d $tempnode",
SYMLINK+="tape/by-id/$env{ID_VENDOR}-$env{ID_MODEL}-$env{ID_SERIAL_SHORT}"SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end"
KERNEL="st*[0-9]|nst*[0-9]", ATTRS{ieee1394_id}="?*", ENV{ID_SERIAL}="$attr{ieee1394_id}", ENV{ID_BUS}="ieee1394" KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", SUBSYSTEMS="usb", IMPORT{program}="usb_id --export %p"
KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", SUBSYSTEMS="scsi", KERNELS="[0-9]*:*[0-9]", ENV{BSG_DEV}="$root/bsg/$id" KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", WAIT_FOR="$env{BSG_DEV}", IMPORT="scsi_id --page=0x80 --whitelisted --export --device=$env{BSG_DEV}", ENV{ID_BUS}="scsi"
KERNEL="st*[0-9]", ENV{ID_SERIAL}="?*", SYMLINK+="tape/by-id/$env{ID_VENDOR}-$env{ID_MODEL}-$env{ID_SERIAL_SHORT}" KERNEL="nst*[0-9]", ENV{ID_SERIAL}="?*", SYMLINK+="tape/by-id/$env{ID_VENDOR}-$env{ID_MODEL}-$env{ID_SERIAL_SHORT}-nst"
# by-path (shortest physical path)
KERNEL="st*[0-9]", IMPORT{program}="path_id %p"
KERNEL="st*[0-9]", ENV{ID_PATH}="?*",
SYMLINK+="tape/by-path/$env{ID_PATH}"LABEL="persistent_storage_tape_end"
John> I had similar issues with my collection of scsi tape drives, not John> all of which may be powered up. the --page=0x80 does the trick.
Interesting. I'll try this out today if I get a chance.
John> my kernel is compiled with the SG version4 block device option enabled.
I think mine is too.
John> this is my 60-persistent-storage-tape.rules, hope it helps
John> ACTION!="add|change", GOTO="persistent_storage_tape_end"
John> # type 8 devices are "Medium Changers"
John> KERNEL="sg[0-9]*", SUBSYSTEMS="scsi", ATTRS{type}="8",
John> IMPORT{program}="scsi_id --sg-version=3 --page=0x80 --export John> --whitelisted -d $tempnode",
John> SYMLINK+="tape/by-id/$env{ID_VENDOR}-$env{ID_MODEL}-$env{ID_SERIAL_SHORT}"
John> SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end"
John> KERNEL="st*[0-9]|nst*[0-9]", ATTRS{ieee1394_id}="?*", John> ENV{ID_SERIAL}="$attr{ieee1394_id}", ENV{ID_BUS}="ieee1394" John> KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", SUBSYSTEMS="usb", John> IMPORT{program}="usb_id --export %p"
John> KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*", SUBSYSTEMS="scsi", John> KERNELS="[0-9]*:*[0-9]", ENV{BSG_DEV}="$root/bsg/$id" John> KERNEL="st*[0-9]|nst*[0-9]", ENV{ID_SERIAL}!="?*",
John> WAIT_FOR="$env{BSG_DEV}", IMPORT="scsi_id --page=0x80 --whitelisted John> --export --device=$env{BSG_DEV}", ENV{ID_BUS}="scsi"
John> KERNEL="st*[0-9]", ENV{ID_SERIAL}="?*",
John> SYMLINK+="tape/by-id/$env{ID_VENDOR}-$env{ID_MODEL}-$env{ID_SERIAL_SHORT}" John> KERNEL="nst*[0-9]", ENV{ID_SERIAL}="?*",
John> SYMLINK+="tape/by-id/$env{ID_VENDOR}-$env{ID_MODEL}-$env{ID_SERIAL_SHORT}-nst"
John> # by-path (shortest physical path) John> KERNEL="st*[0-9]", IMPORT{program}="path_id %p" John> KERNEL="st*[0-9]", ENV{ID_PATH}="?*", John> SYMLINK+="tape/by-path/$env{ID_PATH}"
John> LABEL="persistent_storage_tape_end"
John> --
John> To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in John> the body of a message to [email protected]
John> More majordomo info at http://vger.kernel.org/majordomo-info.html