1ff636
From 8572638ab99090b016ccc28ac1f69aa7759e43cf Mon Sep 17 00:00:00 2001
1ff636
From: Robert Milasan <rmilasan@suse.com>
1ff636
Date: Thu, 12 Jul 2012 15:56:34 +0000
1ff636
Subject: [PATCH] Persistent by_path links for ata devices
1ff636
1ff636
With newer kernel we have the 'port_no' attribute,
1ff636
which allows us to construct a valid ata by-path link.
1ff636
1ff636
With this patch ATA links of the form
1ff636
1ff636
ata-<port>.[01]
1ff636
1ff636
(for master/slave devices) or
1ff636
1ff636
ata-<port>.<pmp>.0
1ff636
1ff636
(for devices behind port multipliers)
1ff636
are generated.
1ff636
1ff636
References: bnc#770910,FATE#317063
1ff636
1ff636
Signed-off-by: Robert Milasan <rmilasan@suse.com>
1ff636
Signed-off-by: Hannes Reinecke <hare@suse.de>
1ff636
1ff636
Downstream patch
1ff636
https://build.opensuse.org/package/view_file/Base:System/systemd/1001-re-enable-by_path-links-for-ata-devices.patch
1ff636
1ff636
Resolves: #1045498
1ff636
---
23b3cf
 src/udev/udev-builtin-path_id.c | 53 +++++++++++++++++++++++++--------
1ff636
 1 file changed, 41 insertions(+), 12 deletions(-)
1ff636
1ff636
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
c62b8e
index b6749aab76..bb0a6242ac 100644
1ff636
--- a/src/udev/udev-builtin-path_id.c
1ff636
+++ b/src/udev/udev-builtin-path_id.c
1ff636
@@ -426,6 +426,46 @@ static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char *
1ff636
         return parent;
1ff636
 }
1ff636
 
1ff636
+static struct udev_device *handle_ata(struct udev_device *parent, char **path)
1ff636
+{
1ff636
+        struct udev *udev  = udev_device_get_udev(parent);
1ff636
+        struct udev_device *hostdev, *portdev;
1ff636
+        int host, bus, target, lun, port_no;
1ff636
+        const char *name, *atahost, *port;
1ff636
+
1ff636
+        hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
1ff636
+        if (hostdev == NULL)
1ff636
+                return NULL;
1ff636
+
1ff636
+        name = udev_device_get_sysname(parent);
1ff636
+        if (sscanf(name, "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4)
1ff636
+                return NULL;
1ff636
+
1ff636
+        /* The ata port is the parent of the SCSI host */
1ff636
+        hostdev = udev_device_get_parent(hostdev);
1ff636
+        atahost = udev_device_get_sysname(hostdev);
1ff636
+        if (strncmp(atahost, "ata", 3))
1ff636
+                return NULL;
1ff636
+
1ff636
+        /* ATA port number is found in 'port_no' attribute */
1ff636
+        portdev = udev_device_new_from_subsystem_sysname(udev, "ata_port",
1ff636
+                                                         atahost);
1ff636
+        port = udev_device_get_sysattr_value(portdev, "port_no");
1ff636
+        if (!port || sscanf(port, "%d", &port_no) != 1) {
1ff636
+                hostdev = NULL;
1ff636
+                goto out;
1ff636
+        }
1ff636
+        if (bus != 0)
1ff636
+                /* Devices behind port multiplier have a bus != 0*/
1ff636
+                path_prepend(path, "ata-%u.%u.0", port_no, bus);
1ff636
+        else
1ff636
+                /* Master/slave are distinguished by target id */
1ff636
+                path_prepend(path, "ata-%u.%u", port_no, target);
1ff636
+out:
1ff636
+        udev_device_unref(portdev);
1ff636
+        return hostdev;
1ff636
+}
1ff636
+
1ff636
 static struct udev_device *handle_scsi(struct udev_device *parent, char **path, bool *supported_parent) {
1ff636
         const char *devtype;
1ff636
         const char *name;
1ff636
@@ -465,19 +505,8 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path,
1ff636
                 goto out;
1ff636
         }
1ff636
 
1ff636
-        /*
1ff636
-         * We do not support the ATA transport class, it uses global counters
1ff636
-         * to name the ata devices which numbers spread across multiple
1ff636
-         * controllers.
1ff636
-         *
1ff636
-         * The real link numbers are not exported. Also, possible chains of ports
1ff636
-         * behind port multipliers cannot be composed that way.
1ff636
-         *
1ff636
-         * Until all that is solved at the kernel level, there are no by-path/
1ff636
-         * links for ATA devices.
1ff636
-         */
1ff636
         if (strstr(name, "/ata") != NULL) {
1ff636
-                parent = NULL;
1ff636
+                parent = handle_ata(parent, path);
1ff636
                 goto out;
1ff636
         }
1ff636