teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0144-Persistent-by_path-links-for-ata-devices.patch

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