A mulitpath device can only be reloaded read/write when all paths are read/write. Also, whenever a read-only scsi device is rescanned, the scsi subsystem will first unconditionally issue a uevent with DISK_RO=0 before checking the read-only status, and if it the device is still read-only, issuing another uevent with DISK_RO=1. These uevents cause pointless reloads when read-only paths are rescanned. To avoid this, first check if the path is being changed to the existing multipath read-only state. If the state is the same, do nothing. If it's different, check to see if all paths are read/write before changing a multipath device from read-only to read/write. If the multipath device read-only state is unknown, assume that it needs to be reloaded. Signed-off-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> --- multipathd/main.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index 2e99a266..009a99d9 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1440,6 +1440,52 @@ finish_path_init(struct path *pp, struct vectors * vecs) return -1; } +static int +sysfs_get_ro (struct path *pp) +{ + int ro; + char buff[3]; /* Either "0\n\0" or "1\n\0" */ + + if (!pp->udev) + return -1; + + if (sysfs_attr_get_value(pp->udev, "ro", buff, sizeof(buff)) <= 0) { + condlog(3, "%s: Cannot read ro attribute in sysfs", pp->dev); + return -1; + } + + if (sscanf(buff, "%d\n", &ro) != 1 || ro < 0 || ro > 1) { + condlog(3, "%s: Cannot parse ro attribute", pp->dev); + return -1; + } + + return ro; +} + +static bool +needs_ro_update(struct multipath *mpp, int ro) +{ + struct pathgroup * pgp; + struct path * pp; + unsigned int i, j; + + if (!mpp || ro < 0) + return false; + if (!has_dm_info(mpp)) + return true; + if (mpp->dmi.read_only == ro) + return false; + if (ro == 1) + return true; + vector_foreach_slot (mpp->pg, pgp, i) { + vector_foreach_slot (pgp->paths, pp, j) { + if (sysfs_get_ro(pp) == 1) + return false; + } + } + return true; +} + static int uev_update_path (struct uevent *uev, struct vectors * vecs) { @@ -1512,7 +1558,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) } ro = uevent_get_disk_ro(uev); - if (mpp && ro >= 0) { + if (needs_ro_update(mpp, ro)) { condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro); if (mpp->wait_for_udev) -- 2.17.2 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel