Blame SOURCES/0012-libmulitpath-cleanup-uid_fallback-code.patch

a1c519
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a1c519
From: Benjamin Marzinski <bmarzins@redhat.com>
a1c519
Date: Wed, 27 Mar 2019 12:21:57 -0500
a1c519
Subject: [PATCH] libmulitpath: cleanup uid_fallback code
a1c519
a1c519
Instead of always calling uid_fallback() if the configured method to get
a1c519
the uid failed, get_uid now checks if the path supports fallbacks and if
a1c519
all the retriggers have occurred. If so, it calls uid_fallback(), which
a1c519
just attempts to get the uid using the appropriate fallback method. None
a1c519
of these changes should make the code function any differently.
a1c519
a1c519
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
a1c519
---
a1c519
 libmultipath/discovery.c | 85 ++++++++++++++++++++++------------------
a1c519
 1 file changed, 46 insertions(+), 39 deletions(-)
a1c519
a1c519
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
a1c519
index bece67c..3ec60d6 100644
a1c519
--- a/libmultipath/discovery.c
a1c519
+++ b/libmultipath/discovery.c
a1c519
@@ -1755,50 +1755,50 @@ get_vpd_uid(struct path * pp)
a1c519
 }
a1c519
 
a1c519
 static ssize_t uid_fallback(struct path *pp, int path_state,
a1c519
-			    const char **origin, ssize_t old_len)
a1c519
+			    const char **origin)
a1c519
 {
a1c519
-	ssize_t len = old_len;
a1c519
-	int retrigger;
a1c519
-	struct config *conf;
a1c519
-
a1c519
-	conf = get_multipath_config();
a1c519
-	retrigger = conf->retrigger_tries;
a1c519
-	put_multipath_config(conf);
a1c519
-	if (pp->retriggers >= retrigger) {
a1c519
-		if (pp->bus == SYSFS_BUS_SCSI &&
a1c519
-		    !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) {
a1c519
-			len = get_vpd_uid(pp);
a1c519
-			*origin = "sysfs";
a1c519
-			pp->uid_attribute = NULL;
a1c519
-			if (len < 0 && path_state == PATH_UP) {
a1c519
-				condlog(1, "%s: failed to get sysfs uid: %s",
a1c519
-					pp->dev, strerror(-len));
a1c519
-				len = get_vpd_sgio(pp->fd, 0x83, pp->wwid,
a1c519
+	ssize_t len = -1;
a1c519
+
a1c519
+	if (pp->bus == SYSFS_BUS_SCSI &&
a1c519
+	    !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) {
a1c519
+		len = get_vpd_uid(pp);
a1c519
+		*origin = "sysfs";
a1c519
+		pp->uid_attribute = NULL;
a1c519
+		if (len < 0 && path_state == PATH_UP) {
a1c519
+			condlog(1, "%s: failed to get sysfs uid: %s",
a1c519
+				pp->dev, strerror(-len));
a1c519
+			len = get_vpd_sgio(pp->fd, 0x83, pp->wwid,
a1c519
+					   WWID_SIZE);
a1c519
+			*origin = "sgio";
a1c519
+		}
a1c519
+	} else if (pp->bus == SYSFS_BUS_NVME) {
a1c519
+		char value[256];
a1c519
+		len = sysfs_attr_get_value(pp->udev, "wwid", value,
a1c519
+					   sizeof(value));
a1c519
+		if (len <= 0)
a1c519
+			return -1;
a1c519
+		len = strlcpy(pp->wwid, value, WWID_SIZE);
a1c519
+		if (len >= WWID_SIZE) {
a1c519
+			len = fix_broken_nvme_wwid(pp, value,
a1c519
 						   WWID_SIZE);
a1c519
-				*origin = "sgio";
a1c519
-			}
a1c519
-		} else if (pp->bus == SYSFS_BUS_NVME) {
a1c519
-			char value[256];
a1c519
-			len = sysfs_attr_get_value(pp->udev, "wwid", value,
a1c519
-						   sizeof(value));
a1c519
-			if (len <= 0)
a1c519
-				return -1;
a1c519
-			len = strlcpy(pp->wwid, value, WWID_SIZE);
a1c519
-			if (len >= WWID_SIZE) {
a1c519
-				len = fix_broken_nvme_wwid(pp, value,
a1c519
-							   WWID_SIZE);
a1c519
-				if (len > 0)
a1c519
-					return len;
a1c519
-				condlog(0, "%s: wwid overflow", pp->dev);
a1c519
-				len = WWID_SIZE;
a1c519
-			}
a1c519
-			*origin = "sysfs";
a1c519
-			pp->uid_attribute = NULL;
a1c519
+			if (len > 0)
a1c519
+				return len;
a1c519
+			condlog(0, "%s: wwid overflow", pp->dev);
a1c519
+			len = WWID_SIZE;
a1c519
 		}
a1c519
+		*origin = "sysfs";
a1c519
+		pp->uid_attribute = NULL;
a1c519
 	}
a1c519
 	return len;
a1c519
 }
a1c519
 
a1c519
+static int has_uid_fallback(struct path *pp)
a1c519
+{
a1c519
+	return ((pp->bus == SYSFS_BUS_SCSI &&
a1c519
+		 !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) ||
a1c519
+		pp->bus == SYSFS_BUS_NVME);
a1c519
+}
a1c519
+
a1c519
 int
a1c519
 get_uid (struct path * pp, int path_state, struct udev_device *udev)
a1c519
 {
a1c519
@@ -1846,8 +1846,15 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev)
a1c519
 			len = get_vpd_uid(pp);
a1c519
 			origin = "sysfs";
a1c519
 		}
a1c519
-		if (len <= 0)
a1c519
-			len = uid_fallback(pp, path_state, &origin, len);
a1c519
+		if (len <= 0 && has_uid_fallback(pp)) {
a1c519
+			int retrigger_tries;
a1c519
+
a1c519
+			conf = get_multipath_config();
a1c519
+			retrigger_tries = conf->retrigger_tries;
a1c519
+			put_multipath_config(conf);
a1c519
+			if (pp->retriggers >= retrigger_tries)
a1c519
+				len = uid_fallback(pp, path_state, &origin);
a1c519
+		}
a1c519
 	}
a1c519
 	if ( len < 0 ) {
a1c519
 		condlog(1, "%s: failed to get %s uid: %s",
a1c519
-- 
a1c519
2.17.2
a1c519