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