All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] nvmet: allow target to export readonly ns
@ 2020-10-01  2:44 Chaitanya Kulkarni
  2020-10-01  2:44 ` [PATCH 1/3] nvmet: allow user to set the ns readonly Chaitanya Kulkarni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2020-10-01  2:44 UTC (permalink / raw)
  To: linux-nvme; +Cc: mruijter, hch, Chaitanya Kulkarni, sagi

Hi,

This patch series allows target to export the read-only ns. The first
patch adds the new ns readonly configfs attr which user can set to make
ns read-only.

Last two patches allows user to open the ns in the read-only mode since
by default we open the ns in read-write mode which will fail if ns
device is set to read-only.

Regards,
Chaitanya

Chaitanya Kulkarni (2):
  nvmet: allow readonly bdev-ns to be configured
  nvmet: allow readonly file-ns to be configured

mruijter@primelogic.nl (1):
  nvmet: allow user to set the ns readonly

 drivers/nvme/target/configfs.c    | 29 +++++++++++++++++++++++++++++
 drivers/nvme/target/io-cmd-bdev.c |  4 ++--
 drivers/nvme/target/io-cmd-file.c |  2 +-
 3 files changed, 32 insertions(+), 3 deletions(-)

-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] nvmet: allow user to set the ns readonly
  2020-10-01  2:44 [PATCH 0/3] nvmet: allow target to export readonly ns Chaitanya Kulkarni
@ 2020-10-01  2:44 ` Chaitanya Kulkarni
  2020-10-01 17:24   ` Christoph Hellwig
  2020-10-01  2:44 ` [PATCH 2/3] nvmet: allow readonly bdev-ns to be configured Chaitanya Kulkarni
  2020-10-01  2:44 ` [PATCH 3/3] nvmet: allow readonly file-ns " Chaitanya Kulkarni
  2 siblings, 1 reply; 5+ messages in thread
From: Chaitanya Kulkarni @ 2020-10-01  2:44 UTC (permalink / raw)
  To: linux-nvme; +Cc: mruijter, hch, Chaitanya Kulkarni, sagi

From: "Mark Ruijter" <mruijter@primelogic.nl>

User may want to export readonly ns to host in order to export
read-only snapshots. Right now we don't have configfs attribute to
allow user to mark readonly & export ns.

Add a configfs attribute such that user can set the ns and export ns
readonly when it is not enabled.

Signed-off-by: Mark Ruijter <mruijter@primelogic.nl>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/configfs.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 37e1d7784e17..90c55ffab802 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -570,6 +570,34 @@ static ssize_t nvmet_ns_buffered_io_store(struct config_item *item,
 
 CONFIGFS_ATTR(nvmet_ns_, buffered_io);
 
+static ssize_t nvmet_ns_readonly_show(struct config_item *item, char *page)
+{
+	return sprintf(page, "%d\n", to_nvmet_ns(item)->readonly);
+}
+
+static ssize_t nvmet_ns_readonly_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct nvmet_ns *ns = to_nvmet_ns(item);
+	bool val;
+
+	if (strtobool(page, &val))
+		return -EINVAL;
+
+	mutex_lock(&ns->subsys->lock);
+	if (ns->enabled) {
+		pr_err("disable ns before setting readonly value.\n");
+		mutex_unlock(&ns->subsys->lock);
+		return -EINVAL;
+	}
+
+	ns->readonly = val;
+	mutex_unlock(&ns->subsys->lock);
+	return count;
+}
+
+CONFIGFS_ATTR(nvmet_ns_, readonly);
+
 static ssize_t nvmet_ns_revalidate_size_store(struct config_item *item,
 		const char *page, size_t count)
 {
@@ -602,6 +630,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = {
 	&nvmet_ns_attr_ana_grpid,
 	&nvmet_ns_attr_enable,
 	&nvmet_ns_attr_buffered_io,
+	&nvmet_ns_attr_readonly,
 	&nvmet_ns_attr_revalidate_size,
 #ifdef CONFIG_PCI_P2PDMA
 	&nvmet_ns_attr_p2pmem,
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] nvmet: allow readonly bdev-ns to be configured
  2020-10-01  2:44 [PATCH 0/3] nvmet: allow target to export readonly ns Chaitanya Kulkarni
  2020-10-01  2:44 ` [PATCH 1/3] nvmet: allow user to set the ns readonly Chaitanya Kulkarni
@ 2020-10-01  2:44 ` Chaitanya Kulkarni
  2020-10-01  2:44 ` [PATCH 3/3] nvmet: allow readonly file-ns " Chaitanya Kulkarni
  2 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2020-10-01  2:44 UTC (permalink / raw)
  To: linux-nvme; +Cc: mruijter, hch, Chaitanya Kulkarni, sagi

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->readonly
configfs attribute when opening the bdev. Use FMODE_WRITE when
ns->readonly is not set.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@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..781705f671b5 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 = FMODE_READ | ns->readonly ? 0 : FMODE_WRITE;
 	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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] nvmet: allow readonly file-ns to be configured
  2020-10-01  2:44 [PATCH 0/3] nvmet: allow target to export readonly ns Chaitanya Kulkarni
  2020-10-01  2:44 ` [PATCH 1/3] nvmet: allow user to set the ns readonly Chaitanya Kulkarni
  2020-10-01  2:44 ` [PATCH 2/3] nvmet: allow readonly bdev-ns to be configured Chaitanya Kulkarni
@ 2020-10-01  2:44 ` Chaitanya Kulkarni
  2 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2020-10-01  2:44 UTC (permalink / raw)
  To: linux-nvme; +Cc: mruijter, hch, Chaitanya Kulkarni, sagi

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@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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] nvmet: allow user to set the ns readonly
  2020-10-01  2:44 ` [PATCH 1/3] nvmet: allow user to set the ns readonly Chaitanya Kulkarni
@ 2020-10-01 17:24   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2020-10-01 17:24 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: mruijter, hch, linux-nvme, sagi

On Wed, Sep 30, 2020 at 07:44:25PM -0700, Chaitanya Kulkarni wrote:
> From: "Mark Ruijter" <mruijter@primelogic.nl>
> 
> User may want to export readonly ns to host in order to export
> read-only snapshots. Right now we don't have configfs attribute to
> allow user to mark readonly & export ns.
> 
> Add a configfs attribute such that user can set the ns and export ns
> readonly when it is not enabled.

I thin kwe also need to expose this as permantently write protected
throught the write protection feature on the get side, and ensure
a set features can't change the setting.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-01 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01  2:44 [PATCH 0/3] nvmet: allow target to export readonly ns Chaitanya Kulkarni
2020-10-01  2:44 ` [PATCH 1/3] nvmet: allow user to set the ns readonly Chaitanya Kulkarni
2020-10-01 17:24   ` Christoph Hellwig
2020-10-01  2:44 ` [PATCH 2/3] nvmet: allow readonly bdev-ns to be configured Chaitanya Kulkarni
2020-10-01  2:44 ` [PATCH 3/3] nvmet: allow readonly file-ns " Chaitanya Kulkarni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.