anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame 0013-test-libndctl-Use-ndctl_region_set_ro-to-change-disk.patch

Jeff Moyer 2c91dc
From 43e48c0d2f271cba4237f6eefc3e4912a74c102b Mon Sep 17 00:00:00 2001
Jeff Moyer 2c91dc
From: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Date: Tue, 9 Mar 2021 22:09:49 -0800
Jeff Moyer 2c91dc
Subject: [PATCH 013/217] test/libndctl: Use ndctl_region_set_ro() to change
Jeff Moyer 2c91dc
 disk read-only state
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Kernel commit 52f019d43c22 ("block: add a hard-readonly flag to struct
Jeff Moyer 2c91dc
gendisk") broke the read-only management test, by fixing the broken
Jeff Moyer 2c91dc
behavior that BLKROSET could make a block device read-write even when the
Jeff Moyer 2c91dc
disk is read-only. The fix [1] propagates changes of the region
Jeff Moyer 2c91dc
read-only state to the underlying disk. Add ndctl_region_set_ro() ahead of
Jeff Moyer 2c91dc
BLKROSET so that BLKROSET does not conflict the block_device state with the
Jeff Moyer 2c91dc
disk state.
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
[1]: http://lore.kernel.org/r/161534060720.528671.2341213328968989192.stgit@dwillia2-desk3.amr.corp.intel.com
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Reported-by: kernel test robot <lkp@intel.com>
Jeff Moyer 2c91dc
Reported-by: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
Link: https://lore.kernel.org/r/161535658913.530219.12194565167385663385.stgit@dwillia2-desk3.amr.corp.intel.com
Jeff Moyer 2c91dc
---
Jeff Moyer 2c91dc
 test/libndctl.c | 18 +++++++++++++++++-
Jeff Moyer 2c91dc
 1 file changed, 17 insertions(+), 1 deletion(-)
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
diff --git a/test/libndctl.c b/test/libndctl.c
Jeff Moyer 2c91dc
index fc65149..c42f785 100644
Jeff Moyer 2c91dc
--- a/test/libndctl.c
Jeff Moyer 2c91dc
+++ b/test/libndctl.c
Jeff Moyer 2c91dc
@@ -1541,6 +1541,7 @@ static int validate_bdev(const char *devname, struct ndctl_btt *btt,
Jeff Moyer 2c91dc
 		struct ndctl_pfn *pfn, struct ndctl_namespace *ndns,
Jeff Moyer 2c91dc
 		struct namespace *namespace, void *buf)
Jeff Moyer 2c91dc
 {
Jeff Moyer 2c91dc
+	struct ndctl_region *region = ndctl_namespace_get_region(ndns);
Jeff Moyer 2c91dc
 	char bdevpath[50];
Jeff Moyer 2c91dc
 	int fd, rc, ro;
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
@@ -1578,6 +1579,13 @@ static int validate_bdev(const char *devname, struct ndctl_btt *btt,
Jeff Moyer 2c91dc
 	}
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 	ro = 0;
Jeff Moyer 2c91dc
+	rc = ndctl_region_set_ro(region, ro);
Jeff Moyer 2c91dc
+	if (rc < 0) {
Jeff Moyer 2c91dc
+		fprintf(stderr, "%s: ndctl_region_set_ro failed\n", devname);
Jeff Moyer 2c91dc
+		rc = -errno;
Jeff Moyer 2c91dc
+		goto out;
Jeff Moyer 2c91dc
+	}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
 	rc = ioctl(fd, BLKROSET, &ro);
Jeff Moyer 2c91dc
 	if (rc < 0) {
Jeff Moyer 2c91dc
 		fprintf(stderr, "%s: BLKROSET failed\n",
Jeff Moyer 2c91dc
@@ -1605,8 +1613,16 @@ static int validate_bdev(const char *devname, struct ndctl_btt *btt,
Jeff Moyer 2c91dc
 		rc = -ENXIO;
Jeff Moyer 2c91dc
 		goto out;
Jeff Moyer 2c91dc
 	}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = ndctl_region_set_ro(region, namespace->ro);
Jeff Moyer 2c91dc
+	if (rc < 0) {
Jeff Moyer 2c91dc
+		fprintf(stderr, "%s: ndctl_region_set_ro reset failed\n", devname);
Jeff Moyer 2c91dc
+		rc = -errno;
Jeff Moyer 2c91dc
+		goto out;
Jeff Moyer 2c91dc
+	}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
 	rc = 0;
Jeff Moyer 2c91dc
- out:
Jeff Moyer 2c91dc
+out:
Jeff Moyer 2c91dc
 	close(fd);
Jeff Moyer 2c91dc
 	return rc;
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
-- 
Jeff Moyer 2c91dc
2.27.0
Jeff Moyer 2c91dc