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

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