In scsi_sysfs_pathinfo() we should just look for the parent that we want, instead of checking all the parents. Signed-off-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> --- libmultipath/discovery.c | 27 ++++++++++----------------- tests/test-lib.c | 1 - 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index cc4efbfc..3d4da127 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1527,23 +1527,16 @@ scsi_sysfs_pathinfo (struct path *pp, const struct vector_s *hwtable) const char *attr_path = NULL; static const char unknown[] = "UNKNOWN"; - parent = pp->udev; - while (parent) { - const char *subsys = udev_device_get_subsystem(parent); - if (subsys && !strncmp(subsys, "scsi", 4)) { - attr_path = udev_device_get_sysname(parent); - if (!attr_path) - break; - if (sscanf(attr_path, "%i:%i:%i:%" SCNu64, - &pp->sg_id.host_no, - &pp->sg_id.channel, - &pp->sg_id.scsi_id, - &pp->sg_id.lun) == 4) - break; - } - parent = udev_device_get_parent(parent); - } - if (!attr_path || pp->sg_id.host_no == -1) + parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", + "scsi_device"); + if (!parent) + return PATHINFO_FAILED; + attr_path = udev_device_get_sysname(parent); + if (!attr_path) + return PATHINFO_FAILED; + if (sscanf(attr_path, "%i:%i:%i:%" SCNu64, + &pp->sg_id.host_no, + &pp->sg_id.channel, &pp->sg_id.scsi_id, &pp->sg_id.lun) != 4) return PATHINFO_FAILED; if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE) <= 0) { diff --git a/tests/test-lib.c b/tests/test-lib.c index 99becccd..bb1d8cdd 100644 --- a/tests/test-lib.c +++ b/tests/test-lib.c @@ -282,7 +282,6 @@ struct mocked_path *mocked_path_from_path(struct mocked_path *mp, static const char hbtl[] = "4:0:3:1"; static void mock_sysfs_pathinfo(const struct mocked_path *mp) { - will_return(__wrap_udev_device_get_subsystem, "scsi"); will_return(__wrap_udev_device_get_sysname, hbtl); will_return(__wrap_udev_device_get_sysname, hbtl); will_return(__wrap_udev_device_get_sysattr_value, mp->vendor); -- 2.46.2