libmultipath: get_uid: straighten the fallback logic
authorMartin Wilck <mwilck@suse.com>
Mon, 24 Jun 2019 09:27:51 +0000 (11:27 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 3 Jul 2019 06:32:06 +0000 (08:32 +0200)
The code had two distinct fallback paths, with non-obvious logic.
Try to straighten it out. The "allow_fallback" logic from
ffaf9477d115 "multipathd: Don't use fallback code after getting wwid"
should only apply in the case where get_udev_uid() failed, not
if it wasn't even tried. Moreover, uid_attribute is hardly ever NULL
since ffaf9477; allow the user to set it to the empty string to
skip udev-based WWID determination. This is rather not meant for
production, but it's useful for testing. Finally, only set "origin"
to "udev" if a WWID was actually retrieved from udev.

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

index b10afde..d7eaee6 100644 (file)
@@ -1876,20 +1876,20 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev,
                        len = strlen(pp->wwid);
                origin = "callout";
        } else {
+               bool udev_available = udev && pp->uid_attribute
+                       && *pp->uid_attribute;
 
-               if (udev && pp->uid_attribute) {
+               if (udev_available) {
                        len = get_udev_uid(pp, pp->uid_attribute, udev);
-                       origin = "udev";
                        if (len <= 0)
                                condlog(1,
                                        "%s: failed to get udev uid: %s",
                                        pp->dev, strerror(-len));
-
-               } else if (pp->bus == SYSFS_BUS_SCSI) {
-                       len = get_vpd_uid(pp);
-                       origin = "sysfs";
+                       else
+                               origin = "udev";
                }
-               if (len <= 0 && allow_fallback && has_uid_fallback(pp)) {
+               if ((!udev_available || (len <= 0 && allow_fallback))
+                   && has_uid_fallback(pp)) {
                        used_fallback = 1;
                        len = uid_fallback(pp, path_state, &origin);
                }