All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
	linux-nvme@lists.infradead.org, Hannes Reinecke <hare@kernel.org>,
	Lennart Poettering <lennart@poettering.net>
Subject: [PATCH 1/2] nvmet: make 'readonly' setting configurable
Date: Thu,  3 Apr 2025 16:47:46 +0200	[thread overview]
Message-ID: <20250403144747.43043-2-hare@kernel.org> (raw)
In-Reply-To: <20250403144747.43043-1-hare@kernel.org>

The namespace already has a 'readonly' setting, which is controlled
by the 'write protect' feature. This patch introduces a namespace
configfs attribute 'readonly' to make it settable by the admin.

Suggested-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
 drivers/nvme/target/configfs.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 00fd6ab046dd..cb03b448ae6d 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -820,6 +820,32 @@ static ssize_t nvmet_ns_resv_enable_store(struct config_item *item,
 }
 CONFIGFS_ATTR(nvmet_ns_, resv_enable);
 
+static ssize_t nvmet_ns_readonly_show(struct config_item *item, char *page)
+{
+	return sysfs_emit(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 (kstrtobool(page, &val))
+		return -EINVAL;
+
+	mutex_lock(&ns->subsys->lock);
+	if (ns->enabled) {
+		pr_err("the ns:%d is already enabled.\n", ns->nsid);
+		mutex_unlock(&ns->subsys->lock);
+		return -EINVAL;
+	}
+	ns->readonly = val;
+	mutex_unlock(&ns->subsys->lock);
+	return count;
+}
+CONFIGFS_ATTR(nvmet_ns_, readonly);
+
 static struct configfs_attribute *nvmet_ns_attrs[] = {
 	&nvmet_ns_attr_device_path,
 	&nvmet_ns_attr_device_nguid,
@@ -830,6 +856,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = {
 	&nvmet_ns_attr_buffered_io,
 	&nvmet_ns_attr_revalidate_size,
 	&nvmet_ns_attr_resv_enable,
+	&nvmet_ns_attr_readonly,
 #ifdef CONFIG_PCI_P2PDMA
 	&nvmet_ns_attr_p2pmem,
 #endif
-- 
2.35.3



  reply	other threads:[~2025-04-03 14:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 14:47 [PATCH 0/2] nvmet: improve 'read-only' handling Hannes Reinecke
2025-04-03 14:47 ` Hannes Reinecke [this message]
2025-04-03 15:44   ` [PATCH 1/2] nvmet: make 'readonly' setting configurable Keith Busch
2025-04-03 15:51     ` Hannes Reinecke
2025-04-04  6:21     ` Christoph Hellwig
2025-04-08 14:24       ` Keith Busch
2025-04-04  6:25   ` Christoph Hellwig
2025-04-03 14:47 ` [PATCH 2/2] nvmet: implement persistent read-only namespace feature Hannes Reinecke
2025-04-04  6:26   ` Christoph Hellwig
2025-04-04  9:36     ` Hannes Reinecke
2025-04-04  6:19 ` [PATCH 0/2] nvmet: improve 'read-only' handling Christoph Hellwig
2025-04-04  6:25   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250403144747.43043-2-hare@kernel.org \
    --to=hare@kernel.org \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=lennart@poettering.net \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.