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

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