ATA devices should use the ATA ids like port number and (possibly) master/slave or multiplier id, not the generic SCSI ID. Currently only port number is included in the link. With this patch the link would be able to support more cases, which are a) when the device is behind a port multiplexer b) the distinction between master and slave (distinguished by target id). It also creates a compatible link for the old format in rules file 60-persistent-storage.rules. Signed-off-by: Lidong Zhong <lidong.zhong@xxxxxxxx> --- rules.d/60-persistent-storage.rules | 3 +++ src/udev/udev-builtin-path_id.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rules.d/60-persistent-storage.rules b/rules.d/60-persistent-storage.rules index 01586690bd..633b3dbfbe 100644 --- a/rules.d/60-persistent-storage.rules +++ b/rules.d/60-persistent-storage.rules @@ -93,6 +93,9 @@ ENV{DEVTYPE}=="disk", DEVPATH!="*/virtual/*", IMPORT{builtin}="path_id" KERNEL=="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-boot%n" KERNEL!="mmcblk[0-9]boot[0-9]", 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" +# ATA device compatible links +KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="*ata*", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | /bin/sed s/\(^.*ata-[0-9]*\)/\1/g'",ENV{ID_PATH_ATA_COMPAT}="%c", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}" +ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="*ata*", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | /bin/sed s/\(^.*ata-[0-9]*\)/\1/g'", ENV{ID_PATH_ATA_COMPAT}="%c", SYMLINK+="disk/by-path/${$env{ID_PATH_ATA_COMPAT}-part%n" # legacy virtio-pci by-path links (deprecated) KERNEL=="vd*[!0-9]", ENV{ID_PATH}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH}" diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index ca38f56087..fb12539781 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -256,11 +256,16 @@ static sd_device *handle_scsi_iscsi(sd_device *parent, char **path) { static sd_device *handle_scsi_ata(sd_device *parent, char **path) { sd_device *targetdev, *target_parent; _cleanup_(sd_device_unrefp) sd_device *atadev = NULL; - const char *port_no, *sysname; + const char *port_no, *sysname, *name; + int host, bus, target, lun; assert(parent); assert(path); + name = udev_device_get_sysname(parent); + if (sscanf(name, "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4) + return NULL; + if (sd_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host", &targetdev) < 0) return NULL; @@ -275,7 +280,13 @@ static sd_device *handle_scsi_ata(sd_device *parent, char **path) { if (sd_device_get_sysattr_value(atadev, "port_no", &port_no) < 0) return NULL; - path_prepend(path, "ata-%s", port_no); + if (bus != 0) + /* Devices behind port multiplier have a bus != 0*/ + path_prepend(path, "ata-%s.%u.0", port_no, bus); + else + /* Master/slave are distinguished by target id */ + path_prepend(path, "ata-%s.%u", port_no, target); + return parent; } -- 2.16.4 _______________________________________________ systemd-devel mailing list systemd-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/systemd-devel