Blame SOURCES/0461-udev-path_id-improve-and-enhance-bus-detection-for-L.patch

17b0f1
From b9146e4dab45e2f76ceca3772564c0f01e227a9f Mon Sep 17 00:00:00 2001
17b0f1
From: Liu Yuan Yuan <bjyyliu@linux.vnet.ibm.com>
17b0f1
Date: Fri, 13 Nov 2015 11:50:42 +0100
17b0f1
Subject: [PATCH] udev/path_id: improve and enhance bus detection for Linux on
17b0f1
 z Systems
17b0f1
17b0f1
Improve and enhance the path_id udev builtin to correctly handle bus'
17b0f1
available on Linux on z Systems (s390).
17b0f1
17b0f1
Previously, the CCW bus and, in particular, any FCP devices on it, have
17b0f1
been treated separately.  This commit integrates the CCW bus into the
17b0f1
device chain loop.  FCP devices and their associated SCSI disks are now
17b0f1
handled through the common SCSI handling functions in path_id.
17b0f1
17b0f1
This implies also a change in the naming of the symbolic links created
17b0f1
by udev.  So any backports of this commit to existing Linux distribution
17b0f1
must be done with care.  If a backport is required, a udev rule must be
17b0f1
created to also create the "old-style" symbolic links.
17b0f1
17b0f1
Apart from the CCW bus, this commit adds bus support for the:
17b0f1
17b0f1
- ccwgroup bus which manages network devices, and
17b0f1
- ap bus which manages cryptographic adapters
17b0f1
- iucv bus which manages IUCV devices on z/VM
17b0f1
17b0f1
Cherry-picked from: e7eb5a8d88367a755944fdda3023a308e5272953
17b0f1
Resolves: #1274401
17b0f1
---
17b0f1
 rules/40-redhat.rules           | 25 +++++++++++++
17b0f1
 src/udev/udev-builtin-path_id.c | 63 ++++++++++++++++++---------------
17b0f1
 2 files changed, 60 insertions(+), 28 deletions(-)
17b0f1
17b0f1
diff --git a/rules/40-redhat.rules b/rules/40-redhat.rules
17b0f1
index 0164dc9214..c928d412b7 100644
17b0f1
--- a/rules/40-redhat.rules
17b0f1
+++ b/rules/40-redhat.rules
17b0f1
@@ -15,3 +15,28 @@ SUBSYSTEM=="scsi", ENV{DEVTYPE}=="scsi_target", TEST!="[module/sg]", RUN+="/sbin
17b0f1
 
17b0f1
 # Rule for prandom character device node permissions
17b0f1
 KERNEL=="prandom", MODE="0644"
17b0f1
+
17b0f1
+
17b0f1
+# Rules for creating the ID_PATH for SCSI devices based on the CCW bus
17b0f1
+# using the form: ccw-<BUS_ID>-zfcp-<WWPN>:<LUN>
17b0f1
+#
17b0f1
+ACTION=="remove", GOTO="zfcp_scsi_device_end"
17b0f1
+
17b0f1
+#
17b0f1
+# Set environment variable "ID_ZFCP_BUS" to "1" if the devices
17b0f1
+# (both disk and partition) are SCSI devices based on FCP devices
17b0f1
+#
17b0f1
+KERNEL=="sd*", SUBSYSTEMS=="ccw", DRIVERS=="zfcp", ENV{.ID_ZFCP_BUS}="1"
17b0f1
+
17b0f1
+# For SCSI disks
17b0f1
+KERNEL=="sd*[!0-9]", SUBSYSTEMS=="scsi",
17b0f1
+        ENV{.ID_ZFCP_BUS}=="1", ENV{DEVTYPE}=="disk",
17b0f1
+        SYMLINK+="disk/by-path/ccw-$attr{hba_id}-zfcp-$attr{wwpn}:$attr{fcp_lun}"
17b0f1
+
17b0f1
+
17b0f1
+# For partitions on a SCSI disk
17b0f1
+KERNEL=="sd*[0-9]", SUBSYSTEMS=="scsi",
17b0f1
+        ENV{.ID_ZFCP_BUS}=="1", ENV{DEVTYPE}=="partition",
17b0f1
+        SYMLINK+="disk/by-path/ccw-$attr{hba_id}-zfcp-$attr{wwpn}:$attr{fcp_lun}-part%n"
17b0f1
+
17b0f1
+LABEL="zfcp_scsi_device_end"
17b0f1
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
17b0f1
index 88a812ff53..19447201b4 100644
17b0f1
--- a/src/udev/udev-builtin-path_id.c
17b0f1
+++ b/src/udev/udev-builtin-path_id.c
17b0f1
@@ -615,27 +615,23 @@ static struct udev_device *handle_bcma(struct udev_device *parent, char **path)
17b0f1
         return parent;
17b0f1
 }
17b0f1
 
17b0f1
-static struct udev_device *handle_ccw(struct udev_device *parent, struct udev_device *dev, char **path) {
17b0f1
-        struct udev_device *scsi_dev;
17b0f1
-
17b0f1
-        scsi_dev = udev_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device");
17b0f1
-        if (scsi_dev != NULL) {
17b0f1
-                const char *wwpn;
17b0f1
-                const char *lun;
17b0f1
-                const char *hba_id;
17b0f1
-
17b0f1
-                hba_id = udev_device_get_sysattr_value(scsi_dev, "hba_id");
17b0f1
-                wwpn = udev_device_get_sysattr_value(scsi_dev, "wwpn");
17b0f1
-                lun = udev_device_get_sysattr_value(scsi_dev, "fcp_lun");
17b0f1
-                if (hba_id != NULL && lun != NULL && wwpn != NULL) {
17b0f1
-                        path_prepend(path, "ccw-%s-zfcp-%s:%s", hba_id, wwpn, lun);
17b0f1
-                        goto out;
17b0f1
-                }
17b0f1
-        }
17b0f1
+/* Handle devices of AP bus in System z platform. */
17b0f1
+static struct udev_device *handle_ap(struct udev_device *parent, char **path) {
17b0f1
+        const char *type, *func;
17b0f1
+
17b0f1
+        assert(parent);
17b0f1
+        assert(path);
17b0f1
+
17b0f1
+        type = udev_device_get_sysattr_value(parent, "type");
17b0f1
+        func = udev_device_get_sysattr_value(parent, "ap_functions");
17b0f1
 
17b0f1
-        path_prepend(path, "ccw-%s", udev_device_get_sysname(parent));
17b0f1
+        if (type != NULL && func != NULL) {
17b0f1
+                path_prepend(path, "ap-%s-%s", type, func);
17b0f1
+                goto out;
17b0f1
+        }
17b0f1
+        path_prepend(path, "ap-%s", udev_device_get_sysname(parent));
17b0f1
 out:
17b0f1
-        parent = skip_subsystem(parent, "ccw");
17b0f1
+        parent = skip_subsystem(parent, "ap");
17b0f1
         return parent;
17b0f1
 }
17b0f1
 
17b0f1
@@ -647,15 +643,8 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
17b0f1
         bool new_sas_path = false;
17b0f1
         bool enable_new_sas_path = true;
17b0f1
 
17b0f1
-        /* S390 ccw bus */
17b0f1
-        parent = udev_device_get_parent_with_subsystem_devtype(dev, "ccw", NULL);
17b0f1
-        if (parent != NULL) {
17b0f1
-                handle_ccw(parent, dev, &path);
17b0f1
-                goto out;
17b0f1
-        }
17b0f1
-
17b0f1
 restart:
17b0f1
-        ;
17b0f1
+
17b0f1
         /* walk up the chain of devices and compose path */
17b0f1
         parent = dev;
17b0f1
         while (parent != NULL) {
17b0f1
@@ -718,6 +707,25 @@ restart:
17b0f1
                                 supported_parent = true;
17b0f1
                                 supported_transport = true;
17b0f1
                         }
17b0f1
+                } else if (streq(subsys, "ccw")) {
17b0f1
+                        path_prepend(&path, "ccw-%s", udev_device_get_sysname(parent));
17b0f1
+                        parent = skip_subsystem(parent, "ccw");
17b0f1
+                        supported_transport = true;
17b0f1
+                        supported_parent = true;
17b0f1
+                } else if (streq(subsys, "ccwgroup")) {
17b0f1
+                        path_prepend(&path, "ccwgroup-%s", udev_device_get_sysname(parent));
17b0f1
+                        parent = skip_subsystem(parent, "ccwgroup");
17b0f1
+                        supported_transport = true;
17b0f1
+                        supported_parent = true;
17b0f1
+                } else if (streq(subsys, "ap")) {
17b0f1
+                        parent = handle_ap(parent, &path);
17b0f1
+                        supported_transport = true;
17b0f1
+                        supported_parent = true;
17b0f1
+                } else if (streq(subsys, "iucv")) {
17b0f1
+                        path_prepend(&path, "iucv-%s", udev_device_get_sysname(parent));
17b0f1
+                        parent = skip_subsystem(parent, "iucv");
17b0f1
+                        supported_transport = true;
17b0f1
+                        supported_parent = true;
17b0f1
                 }
17b0f1
 
17b0f1
                 parent = udev_device_get_parent(parent);
17b0f1
@@ -743,7 +751,6 @@ restart:
17b0f1
                 path = NULL;
17b0f1
         }
17b0f1
 
17b0f1
-out:
17b0f1
         if (path != NULL) {
17b0f1
                 char tag[UTIL_NAME_SIZE];
17b0f1
                 size_t i;