Blame SOURCES/0011-libmultipath-add-get_uid-fallback-code-for-NVMe-devi.patch

a1c519
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a1c519
From: Benjamin Marzinski <bmarzins@redhat.com>
a1c519
Date: Thu, 7 Mar 2019 16:14:35 -0600
a1c519
Subject: [PATCH] libmultipath: add get_uid fallback code for NVMe devices
a1c519
a1c519
If multipath can't get the uid for NVMe devices from udev, it can get it
a1c519
directly from sysfs.
a1c519
a1c519
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
a1c519
---
a1c519
 libmultipath/discovery.c | 49 ++++++++++++++++++++++++++++------------
a1c519
 1 file changed, 34 insertions(+), 15 deletions(-)
a1c519
a1c519
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
a1c519
index 28c00e5..bece67c 100644
a1c519
--- a/libmultipath/discovery.c
a1c519
+++ b/libmultipath/discovery.c
a1c519
@@ -1754,8 +1754,8 @@ get_vpd_uid(struct path * pp)
a1c519
 	return get_vpd_sysfs(parent, 0x83, pp->wwid, WWID_SIZE);
a1c519
 }
a1c519
 
a1c519
-static ssize_t scsi_uid_fallback(struct path *pp, int path_state,
a1c519
-			     const char **origin, ssize_t old_len)
a1c519
+static ssize_t uid_fallback(struct path *pp, int path_state,
a1c519
+			    const char **origin, ssize_t old_len)
a1c519
 {
a1c519
 	ssize_t len = old_len;
a1c519
 	int retrigger;
a1c519
@@ -1764,17 +1764,36 @@ static ssize_t scsi_uid_fallback(struct path *pp, int path_state,
a1c519
 	conf = get_multipath_config();
a1c519
 	retrigger = conf->retrigger_tries;
a1c519
 	put_multipath_config(conf);
a1c519
-	if (pp->retriggers >= retrigger &&
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
+	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
+						   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
 		}
a1c519
 	}
a1c519
 	return len;
a1c519
@@ -1827,8 +1846,8 @@ 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 && pp->bus == SYSFS_BUS_SCSI)
a1c519
-			len = scsi_uid_fallback(pp, path_state, &origin, len);
a1c519
+		if (len <= 0)
a1c519
+			len = uid_fallback(pp, path_state, &origin, len);
a1c519
 	}
a1c519
 	if ( len < 0 ) {
a1c519
 		condlog(1, "%s: failed to get %s uid: %s",
a1c519
-- 
a1c519
2.17.2
a1c519