From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>,
Keith Busch <keith.busch@wdc.com>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 2/3] nvmet: restrict setting of discovery_nqn to discovery subsystem
Date: Mon, 14 Mar 2022 11:53:32 +0100 [thread overview]
Message-ID: <20220314105333.56714-3-hare@suse.de> (raw)
In-Reply-To: <20220314105333.56714-1-hare@suse.de>
Changing the discovery NQN only makes sense for the discovery subsystem,
as any other subsystem can only have one (fixed) subsystem NQN.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/target/configfs.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 9b94af2444b2..58124abdbf62 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -1310,6 +1310,12 @@ CONFIGFS_ATTR(nvmet_subsys_, attr_model);
static ssize_t nvmet_subsys_attr_discovery_nqn_show(struct config_item *item,
char *page)
{
+ struct nvmet_subsys *subsys = to_subsys(item);
+
+ /* Only the discovery subsystem can have a different subsystem NQN */
+ if (subsys != nvmet_disc_subsys)
+ return -EBUSY;
+
return snprintf(page, PAGE_SIZE, "%s\n",
nvmet_disc_subsys->subsysnqn);
}
@@ -1318,9 +1324,17 @@ static ssize_t nvmet_subsys_attr_discovery_nqn_store(struct config_item *item,
const char *page, size_t count)
{
struct nvmet_subsys *subsys = to_subsys(item);
+ struct nvmet_port *port;
+ struct nvmet_subsys_link *p;
char *subsysnqn;
int len;
+ /*
+ * Can only change the discovery NQN for the discovery subsystem
+ */
+ if (subsys != nvmet_disc_subsys)
+ return -EBUSY;
+
len = strcspn(page, "\n");
if (!len)
return -EINVAL;
@@ -1330,13 +1344,21 @@ static ssize_t nvmet_subsys_attr_discovery_nqn_store(struct config_item *item,
return -ENOMEM;
/*
- * The discovery NQN must be different from subsystem NQN.
+ * The discovery NQN must be different from other subsystem NQNs.
+ *
+ * This is a tad convoluted, but avoids having to do a
+ * listdir() from the kernel.
*/
- if (!strcmp(subsysnqn, subsys->subsysnqn)) {
- kfree(subsysnqn);
- return -EBUSY;
- }
down_write(&nvmet_config_sem);
+ list_for_each_entry(port, &nvmet_ports_list, global_entry) {
+ list_for_each_entry(p, &port->subsystems, entry) {
+ if (!strcmp(subsysnqn, p->subsys->subsysnqn)) {
+ up_write(&nvmet_config_sem);
+ kfree(subsysnqn);
+ return -EBUSY;
+ }
+ }
+ }
kfree(nvmet_disc_subsys->subsysnqn);
nvmet_disc_subsys->subsysnqn = subsysnqn;
up_write(&nvmet_config_sem);
--
2.29.2
next prev parent reply other threads:[~2022-03-14 10:53 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 10:53 [RFC PATCH 0/3] nvmet: export discovery subsystem Hannes Reinecke
2022-03-14 10:53 ` [PATCH 1/3] nvmet: expose discovery subsystem in sysfs Hannes Reinecke
2022-03-15 8:06 ` Christoph Hellwig
2022-03-15 8:40 ` Sagi Grimberg
2022-03-15 9:06 ` Hannes Reinecke
2022-03-15 9:49 ` Christoph Hellwig
2022-03-15 10:23 ` Sagi Grimberg
2022-03-15 10:38 ` Hannes Reinecke
2022-03-15 10:49 ` Sagi Grimberg
2022-03-15 11:09 ` Hannes Reinecke
2022-03-15 11:15 ` Sagi Grimberg
2022-03-15 12:51 ` Hannes Reinecke
2022-03-15 13:48 ` Sagi Grimberg
2022-03-23 17:17 ` John Meneghini
2022-03-23 17:23 ` Christoph Hellwig
2022-03-23 17:52 ` John Meneghini
2022-03-23 17:34 ` Knight, Frederick
2022-03-23 18:03 ` John Meneghini
2022-03-23 18:07 ` Knight, Frederick
2022-03-14 10:53 ` Hannes Reinecke [this message]
2022-03-15 8:09 ` [PATCH 2/3] nvmet: restrict setting of discovery_nqn to discovery subsystem Christoph Hellwig
2022-03-15 8:57 ` Sagi Grimberg
2022-03-15 9:00 ` Christoph Hellwig
2022-03-24 0:52 ` John Meneghini
2022-03-24 1:46 ` John Meneghini
2022-03-14 10:53 ` [PATCH 3/3] nvmet: do not allow to create a subsystem with the discovery NQN Hannes Reinecke
2022-03-15 8:10 ` Christoph Hellwig
2022-03-15 8:45 ` 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=20220314105333.56714-3-hare@suse.de \
--to=hare@suse.de \
--cc=hch@lst.de \
--cc=keith.busch@wdc.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox