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

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