chiark / gitweb /
Run ata_id on non-removable USB devices
authorDavid Zeuthen <davidz@redhat.com>
Wed, 30 Mar 2011 12:11:03 +0000 (08:11 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 30 Mar 2011 14:28:24 +0000 (10:28 -0400)
If a USB device is marked as removable, it is often a SATA/PATA disk
in an enclosure (note that flash card readers and usb storage sticks
are always marked as removable). In this case, try running ata_id
(which sends ATA commands wrapped in SCSI ATA PASS THROUGH commands)
to get information about the disk. If this fails, just fall back to
running usb_id since it could be the device isn't an ATA device at
all or the device doesn't have a SAT layer.

This extra information is nice to have as it indicates if it is
suitable to send e.g. SMART commands to the disk, whether the disk
supports power management and so on. Additionally, the VPD and serial
number returned by ata_id is usually more accurate as it stems from
the disk itself instead of the enclosure.

Note that udisks has been doing this for a while

 KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="disk", IMPORT{program}="udisks-probe-ata-smart $tempnode"

so this change shouldn't be too disruptive (udisks-probe-ata-smart
also sends ATA commands via the ATA PASS THROUGH command).

Signed-off-by: David Zeuthen <davidz@redhat.com>
rules/rules.d/60-persistent-storage.rules

index 6a9abdd369daa4851e9af750d8ee7ab5cb6f8a33..12fabeff0ead7f61f5d6883cf182f9f9d419c9ff 100644 (file)
@@ -22,14 +22,18 @@ ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*"
 KERNEL=="vd*[!0-9]", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/virtio-$env{ID_SERIAL}"
 KERNEL=="vd*[0-9]", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/virtio-$env{ID_SERIAL}-part%n"
 
-# USB devices use their own serial number
-KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", IMPORT{program}="usb_id --export %p"
 # ATA devices with their own "ata" kernel subsystem
 KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="ata", IMPORT{program}="ata_id --export $tempnode"
 # ATA devices using the "scsi" subsystem
 KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", IMPORT{program}="ata_id --export $tempnode"
 # ATA/ATAPI devices (SPC-3 or later) using the "scsi" subsystem
 KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="scsi", ATTRS{type}=="5", ATTRS{scsi_level}=="[6-9]*", IMPORT{program}="ata_id --export $tempnode"
+
+# Run ata_id on non-removable USB Mass Storage (SATA/PATA disks in enclosures)
+KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", ATTR{removable}=="0", SUBSYSTEMS=="usb", IMPORT{program}="ata_id --export $tempnode"
+# Otherwise fall back to using usb_id for USB devices
+KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", IMPORT{program}="usb_id --export %p"
+
 # scsi devices
 KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", ENV{ID_BUS}="scsi"
 KERNEL=="cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $tempnode", ENV{ID_BUS}="cciss"