Blame SOURCES/0033-multipathd-avoid-unnecessary-path-read-only-reloads.patch

e65fa3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e65fa3
From: Benjamin Marzinski <bmarzins@redhat.com>
e65fa3
Date: Mon, 15 Nov 2021 10:54:35 -0600
e65fa3
Subject: [PATCH] multipathd: avoid unnecessary path read-only reloads
e65fa3
e65fa3
A mulitpath device can only be reloaded read/write when all paths are
e65fa3
read/write. Also, whenever a read-only device is rescanned, the scsi
e65fa3
subsystem will first unconditionally issue a uevent with DISK_RO=0
e65fa3
before checking the read-only status, and if it the device is still
e65fa3
read-only, issuing another uevent with DISK_RO=1. These uevents cause
e65fa3
pointless reloads when read-only paths are rescanned. To avoid this,
e65fa3
check to see if all paths are read/write before changing a multipath
e65fa3
device from read-only to read/write.
e65fa3
e65fa3
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
e65fa3
---
e65fa3
 libmultipath/libmultipath.version |  5 +++++
e65fa3
 libmultipath/sysfs.c              | 22 ++++++++++++++++++++++
e65fa3
 libmultipath/sysfs.h              |  1 +
e65fa3
 multipathd/main.c                 | 31 ++++++++++++++++++++++++++++++-
e65fa3
 4 files changed, 58 insertions(+), 1 deletion(-)
e65fa3
e65fa3
diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version
e65fa3
index eb5b5b55..dd1b4122 100644
e65fa3
--- a/libmultipath/libmultipath.version
e65fa3
+++ b/libmultipath/libmultipath.version
e65fa3
@@ -287,3 +287,8 @@ global:
e65fa3
 local:
e65fa3
 	*;
e65fa3
 };
e65fa3
+
e65fa3
+LIBMULTIPATH_9.1.0 {
e65fa3
+global:
e65fa3
+	sysfs_get_ro;
e65fa3
+} LIBMULTIPATH_9.0.0;
e65fa3
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
e65fa3
index 9ff145f2..24c12b6a 100644
e65fa3
--- a/libmultipath/sysfs.c
e65fa3
+++ b/libmultipath/sysfs.c
e65fa3
@@ -236,6 +236,28 @@ sysfs_get_size (struct path *pp, unsigned long long * size)
e65fa3
 	return 0;
e65fa3
 }
e65fa3
 
e65fa3
+int
e65fa3
+sysfs_get_ro (struct path *pp)
e65fa3
+{
e65fa3
+	int ro;
e65fa3
+	char buff[3]; /* Either "0\n\0" or "1\n\0" */
e65fa3
+
e65fa3
+	if (!pp->udev)
e65fa3
+		return -1;
e65fa3
+
e65fa3
+	if (sysfs_attr_get_value(pp->udev, "ro", buff, sizeof(buff)) <= 0) {
e65fa3
+		condlog(3, "%s: Cannot read ro attribute in sysfs", pp->dev);
e65fa3
+		return -1;
e65fa3
+	}
e65fa3
+
e65fa3
+	if (sscanf(buff, "%d\n", &ro) != 1 || ro < 0 || ro > 1) {
e65fa3
+		condlog(3, "%s: Cannot parse ro attribute", pp->dev);
e65fa3
+		return -1;
e65fa3
+	}
e65fa3
+
e65fa3
+	return ro;
e65fa3
+}
e65fa3
+
e65fa3
 int sysfs_check_holders(char * check_devt, char * new_devt)
e65fa3
 {
e65fa3
 	unsigned int major, new_minor, table_minor;
e65fa3
diff --git a/libmultipath/sysfs.h b/libmultipath/sysfs.h
e65fa3
index 72b39ab2..c948c467 100644
e65fa3
--- a/libmultipath/sysfs.h
e65fa3
+++ b/libmultipath/sysfs.h
e65fa3
@@ -13,6 +13,7 @@ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
e65fa3
 ssize_t sysfs_bin_attr_get_value(struct udev_device *dev, const char *attr_name,
e65fa3
 				 unsigned char * value, size_t value_len);
e65fa3
 int sysfs_get_size (struct path *pp, unsigned long long * size);
e65fa3
+int sysfs_get_ro(struct path *pp);
e65fa3
 int sysfs_check_holders(char * check_devt, char * new_devt);
e65fa3
 bool sysfs_is_multipathed(struct path *pp, bool set_wwid);
e65fa3
 #endif
e65fa3
diff --git a/multipathd/main.c b/multipathd/main.c
e65fa3
index 1defeaf1..6145e512 100644
e65fa3
--- a/multipathd/main.c
e65fa3
+++ b/multipathd/main.c
e65fa3
@@ -1324,6 +1324,35 @@ fail:
e65fa3
 	return REMOVE_PATH_MAP_ERROR;
e65fa3
 }
e65fa3
 
e65fa3
+static bool
e65fa3
+needs_ro_update(struct multipath *mpp, int ro)
e65fa3
+{
e65fa3
+	struct pathgroup * pgp;
e65fa3
+	struct path * pp;
e65fa3
+	unsigned int i, j;
e65fa3
+	struct dm_info *dmi = NULL;
e65fa3
+
e65fa3
+	if (!mpp || ro < 0)
e65fa3
+		return false;
e65fa3
+	dm_get_info(mpp->alias, &dmi);
e65fa3
+	if (!dmi) /* assume we do need to reload the device */
e65fa3
+		return true;
e65fa3
+	if (dmi->read_only == ro) {
e65fa3
+		free(dmi);
e65fa3
+		return false;
e65fa3
+	}
e65fa3
+	free(dmi);
e65fa3
+	if (ro == 1)
e65fa3
+		return true;
e65fa3
+	vector_foreach_slot (mpp->pg, pgp, i) {
e65fa3
+		vector_foreach_slot (pgp->paths, pp, j) {
e65fa3
+			if (sysfs_get_ro(pp) == 1)
e65fa3
+				return false;
e65fa3
+		}
e65fa3
+	}
e65fa3
+	return true;
e65fa3
+}
e65fa3
+
e65fa3
 static int
e65fa3
 uev_update_path (struct uevent *uev, struct vectors * vecs)
e65fa3
 {
e65fa3
@@ -1388,7 +1417,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
e65fa3
 		}
e65fa3
 
e65fa3
 		ro = uevent_get_disk_ro(uev);
e65fa3
-		if (mpp && ro >= 0) {
e65fa3
+		if (needs_ro_update(mpp, ro)) {
e65fa3
 			condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro);
e65fa3
 
e65fa3
 			if (mpp->wait_for_udev)