lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211027120937.1163744-2-huaisheng.ye@intel.com>
Date:   Wed, 27 Oct 2021 20:09:34 +0800
From:   Huaisheng Ye <huaisheng.ye@...el.com>
To:     dan.j.williams@...el.com, hch@....de, vishal.l.verma@...el.com,
        dave.jiang@...el.com, ira.weiny@...el.com
Cc:     nvdimm@...ts.linux.dev, linux-kernel@...r.kernel.org,
        Huaisheng Ye <huaisheng.ye@...el.com>
Subject: [PATCH 1/4] libnvdimm: add a ro state control function for nvdimm

libndctl failed to pass when writing pmem disk.
Here is the error message below,

    namespace6.0: failed to write /dev/pmem6
    check_namespaces: namespace6.0 validate_bdev failed
    ndctl-test1 failed: -6

Commit 98f49b63e84d4ee1a5c327d0b5f4e8699f6c70fe removes set_device_ro and
e00adcadf3af7a8335026d71ab9f0e0a922191ac adds a new set_read_only method
to allow for driver-specific processing when changing the block device's
read-only state.

Current drivers nd_pmem, nd_blk and nd_btt don't have the capability to
enable or disable write protect (read-only) state. Without that,
blkdev_roset just modifies the value of bd_read_only of struct block_device
and returns success to ioctl of block device. Error would happen when writing
read-only disk next.

Add ro state control function in libnvdimm for this purpose.

Signed-off-by: Huaisheng Ye <huaisheng.ye@...el.com>
---
 drivers/nvdimm/bus.c | 17 +++++++++++++++++
 drivers/nvdimm/nd.h  |  1 +
 2 files changed, 18 insertions(+)

diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 9dc7f3edd42b..299dd5e11ae7 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -636,6 +636,23 @@ void nvdimm_check_and_set_ro(struct gendisk *disk)
 }
 EXPORT_SYMBOL(nvdimm_check_and_set_ro);
 
+int nd_set_ro(struct block_device *bdev, bool ro)
+{
+	struct gendisk *disk = bdev->bd_disk;
+	struct device *dev = disk_to_dev(disk)->parent;
+	int disk_ro = get_disk_ro(disk);
+
+	/* nothing to change with ro state */
+	if (disk_ro == ro)
+		return 0;
+
+	dev_info(dev, "set %s to read-%s\n",
+		 disk->disk_name, ro ? "only" : "write");
+	set_disk_ro(disk, ro);
+	return 0;
+}
+EXPORT_SYMBOL(nd_set_ro);
+
 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
 		char *buf)
 {
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 5467ebbb4a6b..f1cf3eb21292 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -512,6 +512,7 @@ void nvdimm_bus_lock(struct device *dev);
 void nvdimm_bus_unlock(struct device *dev);
 bool is_nvdimm_bus_locked(struct device *dev);
 void nvdimm_check_and_set_ro(struct gendisk *disk);
+int nd_set_ro(struct block_device *bdev, bool ro);
 void nvdimm_drvdata_release(struct kref *kref);
 void put_ndd(struct nvdimm_drvdata *ndd);
 int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd);
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ