Nils Carlson
2012-04-03 08:04:22 UTC
Changes since v1:
* Remove the number of phys from the output
* Extract the phy identifier from the symlink, less code.
When path_id was converted to C code the enumeration of SAS
devices by phy disappeared. This patch reintroduces enumeration
of the form
pci-0000:05:00.0-sas-phy0-0x500000e114de2b42:0-lun0
where phy0 is the reintroduced substring where 0 corresponds
to the lowest phy identifier on the port to which the device
is connected.
Please test this patch thoroughly as it has only been tested
with an older version of udev.
Signed-off-by: Nils Carlson <***@ericsson.com>
---
src/udev-builtin-path_id.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/udev-builtin-path_id.c b/src/udev-builtin-path_id.c
index a8559d2..54b22c4 100644
--- a/src/udev-builtin-path_id.c
+++ b/src/udev-builtin-path_id.c
@@ -127,7 +127,10 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
struct udev_device *targetdev;
struct udev_device *target_parent;
struct udev_device *sasdev;
+ struct udev_device *portdev;
+ struct udev_list_entry *list_entry;
const char *sas_address;
+ int tmp_phy_id, phy_id = 255;
char *lun = NULL;
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
@@ -138,6 +141,31 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
if (target_parent == NULL)
return NULL;
+ portdev = udev_device_get_parent(target_parent);
+ if (target_parent == NULL)
+ return NULL;
+
+ udev_list_entry_foreach(list_entry,
+ udev_device_get_sysattr_list_entry(portdev)) {
+ const char *name = udev_list_entry_get_name(list_entry);
+ char *phy_id_str;
+
+ if (strncmp(name, "phy", 3) != 0)
+ continue;
+
+ phy_id_str = strstr(name, ":");
+ if (phy_id_str == NULL)
+ continue;
+
+ phy_id_str++;
+
+ tmp_phy_id = atoi(phy_id_str);
+ if (tmp_phy_id >= 0 && tmp_phy_id < phy_id)
+ phy_id = tmp_phy_id;
+ }
+ if (phy_id == 255)
+ return NULL;
+
sasdev = udev_device_new_from_subsystem_sysname(udev, "sas_device",
udev_device_get_sysname(target_parent));
if (sasdev == NULL)
@@ -150,7 +178,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
}
format_lun_number(parent, &lun);
- path_prepend(path, "sas-%s-%s", sas_address, lun);
+ path_prepend(path, "sas-phy%d-%s-%s", phy_id, sas_address, lun);
if (lun)
free(lun);
out:
* Remove the number of phys from the output
* Extract the phy identifier from the symlink, less code.
When path_id was converted to C code the enumeration of SAS
devices by phy disappeared. This patch reintroduces enumeration
of the form
pci-0000:05:00.0-sas-phy0-0x500000e114de2b42:0-lun0
where phy0 is the reintroduced substring where 0 corresponds
to the lowest phy identifier on the port to which the device
is connected.
Please test this patch thoroughly as it has only been tested
with an older version of udev.
Signed-off-by: Nils Carlson <***@ericsson.com>
---
src/udev-builtin-path_id.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/udev-builtin-path_id.c b/src/udev-builtin-path_id.c
index a8559d2..54b22c4 100644
--- a/src/udev-builtin-path_id.c
+++ b/src/udev-builtin-path_id.c
@@ -127,7 +127,10 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
struct udev_device *targetdev;
struct udev_device *target_parent;
struct udev_device *sasdev;
+ struct udev_device *portdev;
+ struct udev_list_entry *list_entry;
const char *sas_address;
+ int tmp_phy_id, phy_id = 255;
char *lun = NULL;
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
@@ -138,6 +141,31 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
if (target_parent == NULL)
return NULL;
+ portdev = udev_device_get_parent(target_parent);
+ if (target_parent == NULL)
+ return NULL;
+
+ udev_list_entry_foreach(list_entry,
+ udev_device_get_sysattr_list_entry(portdev)) {
+ const char *name = udev_list_entry_get_name(list_entry);
+ char *phy_id_str;
+
+ if (strncmp(name, "phy", 3) != 0)
+ continue;
+
+ phy_id_str = strstr(name, ":");
+ if (phy_id_str == NULL)
+ continue;
+
+ phy_id_str++;
+
+ tmp_phy_id = atoi(phy_id_str);
+ if (tmp_phy_id >= 0 && tmp_phy_id < phy_id)
+ phy_id = tmp_phy_id;
+ }
+ if (phy_id == 255)
+ return NULL;
+
sasdev = udev_device_new_from_subsystem_sysname(udev, "sas_device",
udev_device_get_sysname(target_parent));
if (sasdev == NULL)
@@ -150,7 +178,7 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
}
format_lun_number(parent, &lun);
- path_prepend(path, "sas-%s-%s", sas_address, lun);
+ path_prepend(path, "sas-phy%d-%s-%s", phy_id, sas_address, lun);
if (lun)
free(lun);
out:
--
1.7.9.4
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
1.7.9.4
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html