libmultipath: get_uid: check VPD pages for SCSI only
authorMartin Wilck <mwilck@suse.com>
Wed, 7 Mar 2018 23:21:49 +0000 (00:21 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Sat, 10 Mar 2018 07:23:37 +0000 (08:23 +0100)
The VPD code won't work for non-SCSI devices, anyway. For indentation
reasons, I moved the "retrigger_tries" case to a separate function,
which is also called only for SCSI devices.

Signed-off-by: Martin Wilck <mwilck@suse.com>
libmultipath/discovery.c

index 3d38a25..53182a8 100644 (file)
@@ -1807,9 +1807,38 @@ get_vpd_uid(struct path * pp)
                parent = udev_device_get_parent(parent);
        }
 
                parent = udev_device_get_parent(parent);
        }
 
+       if (!parent)
+               return -EINVAL;
+
        return get_vpd_sysfs(parent, 0x83, pp->wwid, WWID_SIZE);
 }
 
        return get_vpd_sysfs(parent, 0x83, pp->wwid, WWID_SIZE);
 }
 
+static ssize_t scsi_uid_fallback(struct path *pp, int path_state,
+                            const char **origin)
+{
+       ssize_t len = 0;
+       int retrigger;
+       struct config *conf;
+
+       conf = get_multipath_config();
+       retrigger = conf->retrigger_tries;
+       put_multipath_config(conf);
+       if (pp->retriggers >= retrigger &&
+           !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) {
+               len = get_vpd_uid(pp);
+               *origin = "sysfs";
+               pp->uid_attribute = NULL;
+               if (len < 0 && path_state == PATH_UP) {
+                       condlog(1, "%s: failed to get sysfs uid: %s",
+                               pp->dev, strerror(-len));
+                       len = get_vpd_sgio(pp->fd, 0x83, pp->wwid,
+                                          WWID_SIZE);
+                       *origin = "sgio";
+               }
+       }
+       return len;
+}
+
 int
 get_uid (struct path * pp, int path_state, struct udev_device *udev)
 {
 int
 get_uid (struct path * pp, int path_state, struct udev_device *udev)
 {
@@ -1851,7 +1880,6 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev)
                len = get_rbd_uid(pp);
                origin = "sysfs";
        } else {
                len = get_rbd_uid(pp);
                origin = "sysfs";
        } else {
-               int retrigger;
 
                if (pp->uid_attribute) {
                        len = get_udev_uid(pp, pp->uid_attribute, udev);
 
                if (pp->uid_attribute) {
                        len = get_udev_uid(pp, pp->uid_attribute, udev);
@@ -1861,26 +1889,12 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev)
                                        "%s: failed to get udev uid: %s",
                                        pp->dev, strerror(-len));
 
                                        "%s: failed to get udev uid: %s",
                                        pp->dev, strerror(-len));
 
-               } else {
+               } else if (pp->bus == SYSFS_BUS_SCSI) {
                        len = get_vpd_uid(pp);
                        origin = "sysfs";
                }
                        len = get_vpd_uid(pp);
                        origin = "sysfs";
                }
-               conf = get_multipath_config();
-               retrigger = conf->retrigger_tries;
-               put_multipath_config(conf);
-               if (len <= 0 && pp->retriggers >= retrigger &&
-                   !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) {
-                       len = get_vpd_uid(pp);
-                       origin = "sysfs";
-                       pp->uid_attribute = NULL;
-                       if (len < 0 && path_state == PATH_UP) {
-                               condlog(1, "%s: failed to get sysfs uid: %s",
-                                       pp->dev, strerror(-len));
-                               len = get_vpd_sgio(pp->fd, 0x83, pp->wwid,
-                                                  WWID_SIZE);
-                               origin = "sgio";
-                       }
-               }
+               if (len <= 0 && pp->bus == SYSFS_BUS_SCSI)
+                       len = scsi_uid_fallback(pp, path_state, &origin);
        }
        if ( len < 0 ) {
                condlog(1, "%s: failed to get %s uid: %s",
        }
        if ( len < 0 ) {
                condlog(1, "%s: failed to get %s uid: %s",