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

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