Skip to content

Commit

Permalink
55-scsi-sg3_id.rules: Support tapes and medium changers
Browse files Browse the repository at this point in the history
In order to replace scsi_id functionality in udev's
60-persistent-storage.rules, add support for some non-block devices.

These rules have been tested using the emulated virtual tape library
mhVTL (https://github.com/markh794/mhvtl). It turns out that preferring
sysfs attributes for inquiry is even more beneficial for those than
for disks.
  • Loading branch information
mwilck committed Jan 25, 2018
1 parent 7cd64b5 commit 69dceaa
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions scripts/55-scsi-sg3_id.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@

ACTION=="remove", GOTO="sg3_utils_id_end"

SUBSYSTEM!="block", GOTO="sg3_utils_id_end"
SUBSYSTEM=="block", GOTO="block_dev"

# SCSI devices other than "block"
# This code used to live in 60-persistent-storage-tape.rules.

# type 8 devices are "Medium Changers"
SUBSYSTEM=="scsi_generic", KERNEL=="sg*[0-9]", ATTRS{type}=="8", \
GOTO="scsi_inquiry"
SUBSYSTEM=="scsi_changer", KERNEL=="sch*[0-9]", ATTRS{type}=="8", \
ENV{.INQUIRY_DEV}="$root/bsg/$id", GOTO="scsi_inquiry"

# tapes need to be accessed through their bsg device
KERNEL=="st*[0-9]|nst*[0-9]", SUBSYSTEMS=="scsi", KERNELS=="[0-9]*:*[0-9]", \
ENV{.INQUIRY_DEV}="$root/bsg/$id", GOTO="scsi_inquiry"

GOTO="sg3_utils_id_end"

LABEL="block_dev"

# Import values for partitions
ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_SCSI", IMPORT{parent}="SCSI_*"
Expand All @@ -22,25 +39,32 @@ KERNEL!="sd*[!0-9]|sr*", GOTO="sg3_utils_id_end"
# Set 'ID_SCSI_INQUIRY=0' in an earlier udev rule if the kernel
# fails to scan VPD pages correctly; the rules will then fall
# back to calling sg_vpd directly.
LABEL="scsi_inquiry"
ENV{ID_SCSI_INQUIRY}=="0", GOTO="sg_inquiry"
ATTRS{inquiry}!="*", GOTO="sg_inquiry"
# "inquiry" is an attribute of the scsi_device in sysfs,
# we obtain it by using $id after an ATTRS match.
SUBSYSTEMS=="scsi", ATTRS{inquiry}=="*", KERNELS=="[0-9]*:*[0-9]", \
ENV{.SYSFS_PATH}="$sys/class/scsi_device/$id/device"
ENV{.SYSFS_PATH}=="", GOTO="sg_inquiry"

IMPORT{program}="/usr/bin/sg_inq --export --inhex=/sys/block/$kernel/device/inquiry --raw", \
IMPORT{program}="/usr/bin/sg_inq --export --inhex=$env{.SYSFS_PATH}/inquiry --raw", \
ENV{ID_SCSI}="1", ENV{ID_SCSI_INQUIRY}="1"
# If inquiry sysfs attribute reading it failed, fallback to sg
ENV{ID_SCSI}!="1", GOTO="sg_inquiry"
# Read VPD pages 80 (sn) and 83 (di)
IMPORT{program}="/usr/bin/sg_inq --export --inhex=/sys/block/$kernel/device/vpd_pg80 --raw"
IMPORT{program}="/usr/bin/sg_inq --export --inhex=/sys/block/$kernel/device/vpd_pg83 --raw"
IMPORT{program}="/usr/bin/sg_inq --export --inhex=$env{.SYSFS_PATH}/vpd_pg80 --raw"
IMPORT{program}="/usr/bin/sg_inq --export --inhex=$env{.SYSFS_PATH}/vpd_pg83 --raw"
GOTO="compat"

LABEL="sg_inquiry"
# Handle devices that have no inquiry attributes in sysfs
IMPORT{program}="/usr/bin/sg_inq --export $tempnode", ENV{ID_SCSI}="1"
ENV{.INQUIRY_DEV}=="", ENV{.INQUIRY_DEV}="$tempnode"

IMPORT{program}="/usr/bin/sg_inq --export $env{.INQUIRY_DEV}", ENV{ID_SCSI}="1"
# Give up if this fails, too
ENV{ID_SCSI}!="1", GOTO="sg3_utils_id_end"
IMPORT{program}="/usr/bin/sg_inq --export --page=sn $tempnode"
IMPORT{program}="/usr/bin/sg_inq --export --page=di $tempnode"
IMPORT{program}="/usr/bin/sg_inq --export --page=sn $env{.INQUIRY_DEV}"
IMPORT{program}="/usr/bin/sg_inq --export --page=di $env{.INQUIRY_DEV}"

LABEL="compat"

Expand Down

0 comments on commit 69dceaa

Please sign in to comment.