From 9fcc74fd3e8e196a1634d80e751d4b20594859e0 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 3 Sep 2007 12:16:53 +0000 Subject: [PATCH] Fix schX/sgX/stX etc symlink creation. Vastly improve handling of scsi_generic, scsi_changer, and scsi_tape symlinks in the /dev/{disk,tape} tree. Most it the previous code was broken because tape stuff are not block devices! This code should now support every variety of tape device in the mainstream kernel: st, osst, ht, pt; Also no-rewind and mode flags where applicable. This patch also exposes the need for locking on scsi_id actions. Doing scsi_id on both nst0 and st0 at the same time will result in one of them getting bad or missing data! The lock should be taken on the tuple. The data might also be cached for given tuples, but expiry of cache could present problems. --- etc/udev/rules.d/60-persistent-storage.rules | 18 ++----- etc/udev/rules.d/61-persistent-scsi-generic.rules | 30 ++++++++++++ etc/udev/rules.d/61-persistent-storage-tape.rules | 52 +++++++++++++++++++++ extras/path_id/path_id | 8 +++ 4 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 etc/udev/rules.d/61-persistent-scsi-generic.rules create mode 100644 etc/udev/rules.d/61-persistent-storage-tape.rules diff --git a/etc/udev/rules.d/60-persistent-storage.rules b/etc/udev/rules.d/60-persistent-storage.rules index 63e715d..c83e7ea 100644 --- a/etc/udev/rules.d/60-persistent-storage.rules +++ b/etc/udev/rules.d/60-persistent-storage.rules @@ -1,15 +1,9 @@ # do not edit this file, it will be overwritten on update -# persistent storage links: /dev/{disk,tape}/{by-id,by-uuid,by-label,by-path,by-name} +# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path,by-name} # scheme based on "Linux persistent device names", 2004, Hannes Reinecke ACTION!="add", GOTO="persistent_storage_end" - -KERNEL=="nst[0-9]", SUBSYSTEMS=="scsi", IMPORT{program}="scsi_id --export --whitelisted --fallback-to-sysfs -s %p -d $tempnode", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-nst" - -# type 8 devices are "Medium Changers" -KERNEL=="sg*", SUBSYSTEMS=="scsi", ATTRS{type}=="8", IMPORT{program}="scsi_id --export --whitelisted --fallback-to-sysfs -s %p -d $tempnode", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}" - SUBSYSTEM!="block", GOTO="persistent_storage_end" # skip rules for inappropriate block devices @@ -34,13 +28,12 @@ KERNEL=="hd*[!0-9]", IMPORT{program}="ata_id --export $tempnode" KERNEL=="hd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}" KERNEL=="hd*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}-part%n" -KERNEL=="sd*[!0-9]|sr*|st*", ATTRS{ieee1394_id}=="?*", ENV{ID_SERIAL}="$attr{ieee1394_id}", ENV{ID_BUS}="ieee1394" -KERNEL=="sd*[!0-9]|sr*|st*", ENV{ID_SERIAL}!="?*", IMPORT{program}="usb_id --export %p" -KERNEL=="sd*[!0-9]|sr*|st*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted --fallback-to-sysfs -s %p -d $tempnode" +KERNEL=="sd*[!0-9]|sr*", ATTRS{ieee1394_id}=="?*", ENV{ID_SERIAL}="$attr{ieee1394_id}", ENV{ID_BUS}="ieee1394" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", IMPORT{program}="usb_id --export %p" +KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted --fallback-to-sysfs -s %p -d $tempnode" KERNEL=="cciss?c[0-9]d[0-9]", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted --ignore-sysfs -s %p -d $tempnode", ENV{ID_BUS}="cciss" KERNEL=="sd*[!0-9]|sr*|cciss?c[0-9]d[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}" KERNEL=="sd*[0-9]|cciss*p[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n" -KERNEL=="st*", ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}" # libata compat (links like hd*) KERNEL=="sd*[!0-9]|sr*", ENV{ID_VENDOR}=="ATA", PROGRAM="ata_id $tempnode", RESULT=="?*", ENV{ID_ATA_COMPAT}="$result", SYMLINK+="disk/by-id/ata-$env{ID_ATA_COMPAT}" @@ -53,9 +46,8 @@ KERNEL=="mmcblk[0-9]p[0-9]", ENV{ID_NAME}=="?*", ENV{ID_SERIAL}=="?*", SYMLINK+= ENV{DEVTYPE}=="disk", IMPORT{program}="path_id %p" ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}" ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n" -KERNEL=="st*", ENV{ID_PATH}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH}" -KERNEL=="sr*|st*", GOTO="persistent_storage_end" +KERNEL=="sr*", GOTO="persistent_storage_end" KERNEL=="hd*[!0-9]", ATTR{removable}=="1", GOTO="persistent_storage_end" # by-label/by-uuid (filesystem properties) diff --git a/etc/udev/rules.d/61-persistent-scsi-generic.rules b/etc/udev/rules.d/61-persistent-scsi-generic.rules new file mode 100644 index 0000000..53cefc7 --- /dev/null +++ b/etc/udev/rules.d/61-persistent-scsi-generic.rules @@ -0,0 +1,30 @@ +# do not edit this file, it will be overwritten on update +ACTION!="add", GOTO="persistent_scsi_generic_end" +KERNEL!="sg*", GOTO="persistent_scsi_generic_end" + +# Types 1 and 8 are handled by the tape code +ATTRS{type}=="[18]", GOTO="persistent_scsi_generic_end" + +# The commented types are not directly supported in Linux presently +# Maybe have a generic place to put them? +ATTRS{type}=="0", ENV{GENERIC_TYPE}="disk" +#ATTRS{type}=="2", ENV{GENERIC_TYPE}="printer" +#ATTRS{type}=="3", ENV{GENERIC_TYPE}="processor" # HP scanners, SCSI enclosure management chips like GEM359 +ATTRS{type}=="4", ENV{GENERIC_TYPE}="disk" # WORM, but treat as cdrom/disk in linux +ATTRS{type}=="5", ENV{GENERIC_TYPE}="disk" # ROM, but treat as cdrom/disk in linux +ATTRS{type}=="6", ENV{GENERIC_TYPE}="disk" # magento-optical, but treat as disk in linux +#ATTRS{type}=="9", ENV{GENERIC_TYPE}="comm" +#ATTRS{type}=="12", ENV{GENERIC_TYPE}="raid" +#ATTRS{type}=="13", ENV{GENERIC_TYPE}="enc" +#ATTRS{type}=="14", ENV{GENERIC_TYPE}="rbc" + +# if GENERIC_TYPE is not set, exit now +ENV{GENERIC_TYPE}!="?*", GOTO="persistent_scsi_generic_end" + +IMPORT{program}="path_id %p" +ENV{ID_PATH}=="?*", SYMLINK+="$env{GENERIC_TYPE}/by-path/$env{ID_PATH}" + +IMPORT{program}="scsi_id --export --whitelisted --fallback-to-sysfs -s %p -d $tempnode" +ENV{ID_SERIAL}=="?*", SYMLINK+="$env{GENERIC_TYPE}/by-id/$env{ID_BUS}-$env{ID_SERIAL}-sg" + +LABEL="persistent_scsi_generic_end" diff --git a/etc/udev/rules.d/61-persistent-storage-tape.rules b/etc/udev/rules.d/61-persistent-storage-tape.rules new file mode 100644 index 0000000..886ffce --- /dev/null +++ b/etc/udev/rules.d/61-persistent-storage-tape.rules @@ -0,0 +1,52 @@ +# do not edit this file, it will be overwritten on update + +# persistent storage links: /dev/tape/{by-id,by-uuid,by-label,by-path,by-name} +# scheme based on "Linux persistent device names", 2004, Hannes Reinecke +# Was originally part of 60-persistent-storage.rules +# But the tape stuff was broken out for complexity by Robin H. Johnson + +ACTION!="add", GOTO="persistent_storage_tape_end" + +# Now tape time +# st0 = scsi tape +# ht0 = IDE tape +# pt0 = parallel-port tape +# All 3 have non-rewinding variants + +KERNEL=="st[0-9]*|nst[0-9]*", ENV{DEVTYPE}="tape", ENV{TAPE_TYPE}="st" +KERNEL=="ht[0-9]*|nht[0-9]*", ENV{DEVTYPE}="tape", ENV{TAPE_TYPE}="ht" +KERNEL=="pt[0-9]*|npt[0-9]*", ENV{DEVTYPE}="tape", ENV{TAPE_TYPE}="pt" +KERNEL=="osst[0-9]*|nosst[0-9]*", ENV{DEVTYPE}="tape", ENV{TAPE_TYPE}="osst" + +ENV{DEVTYPE}=="tape", KERNEL=="n*", ENV{TAPE_PREFIX}="n" +ENV{DEVTYPE}=="tape", KERNEL=="*a", ENV{TAPE_SUFFIX}="a", ENV{DEVTYPE}="tapesuffix" +ENV{DEVTYPE}=="tape", KERNEL=="*l", ENV{TAPE_SUFFIX}="l", ENV{DEVTYPE}="tapesuffix" +ENV{DEVTYPE}=="tape", KERNEL=="*m", ENV{TAPE_SUFFIX}="m", ENV{DEVTYPE}="tapesuffix" + +# scsi-generic, type 8 devices are "Medium Changers" +KERNEL=="sg[0-9]*|sch[0-9]*", SUBSYSTEMS=="scsi", ATTRS{type}=="8", ENV{DEVTYPE}="tapechanger" +# scsi-generic, type 1 devices are "Tapes" +KERNEL=="sg[0-9]*", SUBSYSTEMS=="scsi", ATTRS{type}=="1", ENV{DEVTYPE}="tape" + +# Speed up processing now +ENV{DEVTYPE}!="tape*", GOTO="persistent_storage_tape_end" + +KERNEL=="sch[0-9]*", SUBSYSTEMS=="scsi", ATTRS{type}=="8", ENV{TAPE_TYPE}="sch" +KERNEL=="sg[0-9]*", SUBSYSTEMS=="scsi", ATTRS{type}=="[18]", ENV{TAPE_TYPE}="sg" + +ENV{TAPE_SHORTNAME}="$env{TAPE_PREFIX}$env{TAPE_TYPE}$env{TAPE_SUFFIX}" + +# Try to find a serial number if applicable +ENV{DEVTYPE}=="tape*", KERNEL=="ht[0-9]*", IMPORT{program}="ata_id --export $tempnode" +ENV{DEVTYPE}=="tape*", KERNEL=="nht[0-9]*", IMPORT{program}="ata_id --export $tempnode" +ENV{DEVTYPE}=="tape*", ATTRS{ieee1394_id}=="?*", ENV{ID_SERIAL}="$attr{ieee1394_id}", ENV{ID_BUS}="ieee1394" +ENV{DEVTYPE}=="tape*", ENV{ID_SERIAL}!="?*", IMPORT{program}="usb_id --export %p" +ENV{DEVTYPE}=="tape*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted --fallback-to-sysfs -s %p -d $tempnode" +# Now use it +ENV{DEVTYPE}=="tape", ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-$env{TAPE_SHORTNAME}" + +# All types should have useful path values, and path_id includes the tape_type already +ENV{DEVTYPE}=="tape*", IMPORT{program}="path_id %p" +ENV{DEVTYPE}=="tape*", ENV{ID_PATH}=="?*", SYMLINK+="tape/by-path/$env{ID_PATH}" + +LABEL="persistent_storage_tape_end" diff --git a/extras/path_id/path_id b/extras/path_id/path_id index 57879b5..bed728e 100755 --- a/extras/path_id/path_id +++ b/extras/path_id/path_id @@ -562,6 +562,14 @@ case "$TYPE" in handle_device echo "ID_PATH=$d" ;; + scsi_generic) + handle_device + echo "ID_PATH=$d-sg" + ;; + scsi_changer) + handle_device + echo "ID_PATH=$d-sch" + ;; input) handle_device echo "ID_PATH=$d" -- 1.5.1.3