[PATCH V2 3/4] nvmet: allow readonly bdev-ns to be configured
Chaitanya Kulkarni
chaitanya.kulkarni at wdc.com
Thu Oct 1 22:56:48 EDT 2020
Right now we open bdev-ns in read-write mode. This doesn't allow us to
export the bdev which is marked read-only using blockdev --setro.
Allow user to export the readonly bdev by considering the
ns->write_protect configfs attribute when opening the bdev. Use
FMODE_WRITE when ns->write_protect is not set.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
drivers/nvme/target/io-cmd-bdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 125dde3f410e..0e6b5312ad1e 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -65,10 +65,10 @@ static void nvmet_bdev_ns_enable_integrity(struct nvmet_ns *ns)
int nvmet_bdev_ns_enable(struct nvmet_ns *ns)
{
+ fmode_t mode = (ns->write_protect ? 0 : FMODE_WRITE) | FMODE_READ;
int ret;
- ns->bdev = blkdev_get_by_path(ns->device_path,
- FMODE_READ | FMODE_WRITE, NULL);
+ ns->bdev = blkdev_get_by_path(ns->device_path, mode, NULL);
if (IS_ERR(ns->bdev)) {
ret = PTR_ERR(ns->bdev);
if (ret != -ENOTBLK) {
--
2.22.1
More information about the Linux-nvme
mailing list