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