1ff636
From 956212c9a226d9192e4b3c085e917fe59f6d5cb9 Mon Sep 17 00:00:00 2001
1ff636
From: Maurizio Lombardi <mlombard@redhat.com>
1ff636
Date: Tue, 2 Jun 2015 17:26:25 +0200
1ff636
Subject: [PATCH] udev: also create old sas paths
1ff636
1ff636
RHEL-only
1ff636
1ff636
Resolves: #957112
1ff636
---
1ff636
 rules/60-persistent-storage.rules |  2 ++
23b3cf
 src/udev/udev-builtin-path_id.c   | 33 ++++++++++++++++++++++++-------
1ff636
 2 files changed, 28 insertions(+), 7 deletions(-)
1ff636
1ff636
diff --git a/rules/60-persistent-storage.rules b/rules/60-persistent-storage.rules
181b3f
index 25b44a55c..71ab97484 100644
1ff636
--- a/rules/60-persistent-storage.rules
1ff636
+++ b/rules/60-persistent-storage.rules
1ff636
@@ -54,7 +54,9 @@ KERNEL=="mspblk[0-9]p[0-9]", ENV{ID_NAME}=="?*", ENV{ID_SERIAL}=="?*", SYMLINK+=
1ff636
 # by-path (parent device path)
1ff636
 ENV{DEVTYPE}=="disk", DEVPATH!="*/virtual/*", IMPORT{builtin}="path_id"
1ff636
 ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}"
1ff636
+ENV{DEVTYPE}=="disk", ENV{ID_SAS_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_SAS_PATH}"
1ff636
 ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"
1ff636
+ENV{DEVTYPE}=="partition", ENV{ID_SAS_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_SAS_PATH}-part%n"
1ff636
 
1ff636
 # skip unpartitioned removable media devices from drivers which do not send "change" events
1ff636
 ENV{DEVTYPE}=="disk", KERNEL!="sd*|sr*", ATTR{removable}=="1", GOTO="persistent_storage_end"
1ff636
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
181b3f
index bb0a6242a..025392df5 100644
1ff636
--- a/src/udev/udev-builtin-path_id.c
1ff636
+++ b/src/udev/udev-builtin-path_id.c
1ff636
@@ -154,7 +154,7 @@ out:
1ff636
         return parent;
1ff636
 }
1ff636
 
1ff636
-static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
1ff636
+static struct udev_device *handle_scsi_sas(struct udev_device *parent, bool enable_new_sas_path, char **path, bool *new_sas_path)
1ff636
 {
1ff636
         struct udev *udev  = udev_device_get_udev(parent);
1ff636
         struct udev_device *targetdev;
1ff636
@@ -169,6 +169,8 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
1ff636
         const char *phy_count;
1ff636
         char *lun = NULL;
1ff636
 
1ff636
+        *new_sas_path = false;
1ff636
+
1ff636
         targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
1ff636
         if (targetdev == NULL)
1ff636
                 return NULL;
1ff636
@@ -201,7 +203,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
1ff636
         }
1ff636
 
1ff636
         /* Check if we are simple disk */
1ff636
-        if (strncmp(phy_count, "1", 2) != 0) {
1ff636
+        if (strncmp(phy_count, "1", 2) != 0 || !enable_new_sas_path) {
1ff636
                  parent = handle_scsi_sas_wide_port(parent, path);
1ff636
                  goto out;
1ff636
         }
1ff636
@@ -241,6 +243,8 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
1ff636
 
1ff636
         if (lun)
1ff636
                 free(lun);
1ff636
+
1ff636
+        *new_sas_path = true;
1ff636
 out:
1ff636
         udev_device_unref(target_sasdev);
1ff636
         udev_device_unref(expander_sasdev);
1ff636
@@ -466,7 +470,7 @@ out:
1ff636
         return hostdev;
1ff636
 }
1ff636
 
1ff636
-static struct udev_device *handle_scsi(struct udev_device *parent, char **path, bool *supported_parent) {
1ff636
+static struct udev_device *handle_scsi(struct udev_device *parent, bool enable_new_sas_path, char **path, bool *supported_parent, bool *new_sas_path) {
1ff636
         const char *devtype;
1ff636
         const char *name;
1ff636
         const char *id;
1ff636
@@ -494,7 +498,7 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path,
1ff636
         }
1ff636
 
1ff636
         if (strstr(name, "/end_device-") != NULL) {
1ff636
-                parent = handle_scsi_sas(parent, path);
1ff636
+                parent = handle_scsi_sas(parent, enable_new_sas_path, path, new_sas_path);
1ff636
                 *supported_parent = true;
1ff636
                 goto out;
1ff636
         }
1ff636
@@ -610,6 +614,8 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
1ff636
         char *path = NULL;
1ff636
         bool supported_transport = false;
1ff636
         bool supported_parent = false;
1ff636
+        bool new_sas_path = false;
1ff636
+        bool enable_new_sas_path = true;
1ff636
 
1ff636
         /* S390 ccw bus */
1ff636
         parent = udev_device_get_parent_with_subsystem_devtype(dev, "ccw", NULL);
1ff636
@@ -618,6 +624,8 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
1ff636
                 goto out;
1ff636
         }
1ff636
 
1ff636
+restart:
1ff636
+        ;
1ff636
         /* walk up the chain of devices and compose path */
1ff636
         parent = dev;
1ff636
         while (parent != NULL) {
1ff636
@@ -629,7 +637,7 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
1ff636
                 } else if (streq(subsys, "scsi_tape")) {
1ff636
                         handle_scsi_tape(parent, &path);
1ff636
                 } else if (streq(subsys, "scsi")) {
1ff636
-                        parent = handle_scsi(parent, &path, &supported_parent);
1ff636
+                        parent = handle_scsi(parent, enable_new_sas_path, &path, &supported_parent, &new_sas_path);
1ff636
                         supported_transport = true;
1ff636
                 } else if (streq(subsys, "cciss")) {
1ff636
                         parent = handle_cciss(parent, &path);
1ff636
@@ -721,9 +729,20 @@ out:
1ff636
                         i--;
1ff636
                 tag[i] = '\0';
1ff636
 
1ff636
-                udev_builtin_add_property(dev, test, "ID_PATH", path);
1ff636
-                udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
1ff636
+                if (new_sas_path) {
1ff636
+                        udev_builtin_add_property(dev, test, "ID_SAS_PATH", path);
1ff636
+                } else {
1ff636
+                        udev_builtin_add_property(dev, test, "ID_PATH", path);
1ff636
+                        udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
1ff636
+                }
1ff636
+
1ff636
                 free(path);
1ff636
+
1ff636
+                if (new_sas_path) {
1ff636
+                        enable_new_sas_path = false;
1ff636
+                        goto restart;
1ff636
+                }
1ff636
+
1ff636
                 return EXIT_SUCCESS;
1ff636
         }
1ff636
         return EXIT_FAILURE;