Blame SOURCES/0045-multipath-tools-update-mpp-force_readonly-in-ev_add_.patch

aebebb
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
aebebb
From: Uday Shankar <ushankar@purestorage.com>
aebebb
Date: Wed, 9 Mar 2022 13:03:26 -0700
aebebb
Subject: [PATCH] multipath-tools: update mpp->force_readonly in ev_add_path
aebebb
aebebb
When NVMe disks are added to the system, no uevent containing the
aebebb
DISK_RO property is generated. As a result, dm-* nodes backed by
aebebb
readonly NVMe disks will not have their RO state set properly. The
aebebb
result looks like this:
aebebb
aebebb
$ multipath -l
aebebb
eui.00c92c091fd6564424a9376600011bd1 dm-3 NVME,Pure Storage FlashArray
aebebb
size=1.0T features='0' hwhandler='0' wp=rw
aebebb
|-+- policy='service-time 0' prio=0 status=active
aebebb
| `- 0:2:2:72657 nvme0n2 259:4 active undef running
aebebb
`-+- policy='service-time 0' prio=0 status=enabled
aebebb
  `- 1:0:2:72657 nvme1n2 259:1 active undef running
aebebb
$ cat /sys/block/dm-3/ro
aebebb
0
aebebb
$ cat /sys/block/nvme*n2/ro
aebebb
1
aebebb
1
aebebb
aebebb
This is not a problem for SCSI disks, since the kernel will emit change
aebebb
uevents containing the DISK_RO property when the disk is added to the
aebebb
system. See the following thread for my initial attempt to fix this
aebebb
issue at the kernel level:
aebebb
https://lore.kernel.org/linux-block/Yib8GqCA5e3SQYty@infradead.org/T/#t
aebebb
aebebb
Fix the issue by picking up the path ro state from sysfs in ev_add_path,
aebebb
setting the mpp->force_readonly accordingly, and changing
aebebb
dm_addmap_create to be aware of mpp->force_readonly.
aebebb
aebebb
Signed-off-by: Uday Shankar <ushankar@purestorage.com>
aebebb
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
aebebb
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
aebebb
---
aebebb
 libmultipath/devmapper.c | 2 +-
aebebb
 multipathd/main.c        | 6 ++++++
aebebb
 2 files changed, 7 insertions(+), 1 deletion(-)
aebebb
aebebb
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
aebebb
index c05dc201..1ff75c81 100644
aebebb
--- a/libmultipath/devmapper.c
aebebb
+++ b/libmultipath/devmapper.c
aebebb
@@ -542,7 +542,7 @@ int dm_addmap_create (struct multipath *mpp, char * params)
aebebb
 	int ro;
aebebb
 	uint16_t udev_flags = build_udev_flags(mpp, 0);
aebebb
 
aebebb
-	for (ro = 0; ro <= 1; ro++) {
aebebb
+	for (ro = mpp->force_readonly ? 1 : 0; ro <= 1; ro++) {
aebebb
 		int err;
aebebb
 
aebebb
 		if (dm_addmap(DM_DEVICE_CREATE, TGT_MPATH, mpp, params, ro,
aebebb
diff --git a/multipathd/main.c b/multipathd/main.c
aebebb
index 45b9572f..ed2515e5 100644
aebebb
--- a/multipathd/main.c
aebebb
+++ b/multipathd/main.c
aebebb
@@ -1048,6 +1048,7 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
aebebb
 	int retries = 3;
aebebb
 	int start_waiter = 0;
aebebb
 	int ret;
aebebb
+	int ro;
aebebb
 
aebebb
 	/*
aebebb
 	 * need path UID to go any further
aebebb
@@ -1112,6 +1113,11 @@ rescan:
aebebb
 	/* persistent reservation check*/
aebebb
 	mpath_pr_event_handle(pp);
aebebb
 
aebebb
+	/* ro check - if new path is ro, force map to be ro as well */
aebebb
+	ro = sysfs_get_ro(pp);
aebebb
+	if (ro == 1)
aebebb
+		mpp->force_readonly = 1;
aebebb
+
aebebb
 	if (!need_do_map)
aebebb
 		return 0;
aebebb