[PATCH 3/3] nvmet: allow readonly file-ns to be configured

Chaitanya Kulkarni chaitanya.kulkarni at wdc.com
Wed Sep 30 22:44:27 EDT 2020


Right now we open file-ns in read-write mode. This doesn't allow us to
export the file which is marked read-only.

Allow user to export the readonly file by considering the ns->readonly
configfs attribute when opening the file. Use O_RDWR when ns->readonly
is not set.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 drivers/nvme/target/io-cmd-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 0abbefd9925e..46f3ac3eae8e 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -41,7 +41,7 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns)
 
 int nvmet_file_ns_enable(struct nvmet_ns *ns)
 {
-	int flags = O_RDWR | O_LARGEFILE;
+	int flags = (ns->readonly ? O_RDONLY : O_RDWR) | O_LARGEFILE;
 	int ret;
 
 	if (!ns->buffered_io)
-- 
2.22.1




More information about the Linux-nvme mailing list