Linux-NVME Archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] nvmet: implement unique discovery NQN
@ 2023-12-15 12:39 hare
  2023-12-15 16:59 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: hare @ 2023-12-15 12:39 UTC (permalink / raw
  To: Christoph Hellwig; +Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke

From: Hannes Reinecke <hare@suse.de>

Add a configfs attribute 'discovery_nqn' in the 'nvmet' configfs
directory to specify the unique discovery NQN.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/target/configfs.c | 46 ++++++++++++++++++++++++++++++++++
 drivers/nvme/target/core.c     |  7 ++++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index d937fe05129e..456aa5e009cd 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -1587,6 +1587,11 @@ static struct config_group *nvmet_subsys_make(struct config_group *group,
 		return ERR_PTR(-EINVAL);
 	}
 
+	if (sysfs_streq(name, nvmet_disc_subsys->subsysnqn)) {
+		pr_err("can't create subsystem using unique discovery NQN\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	subsys = nvmet_subsys_alloc(name, NVME_NQN_NVME);
 	if (IS_ERR(subsys))
 		return ERR_CAST(subsys);
@@ -2131,7 +2136,48 @@ static const struct config_item_type nvmet_hosts_type = {
 
 static struct config_group nvmet_hosts_group;
 
+static ssize_t nvmet_root_discovery_nqn_show(struct config_item *item,
+					     char *page)
+{
+	return sprintf(page, "%s\n", nvmet_disc_subsys->subsysnqn);
+}
+
+static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct list_head *entry;
+	size_t len;
+
+	len = strcspn(page, "\n");
+	if (!len || len > NVMF_NQN_FIELD_LEN - 1)
+		return -EINVAL;
+
+	down_write(&nvmet_config_sem);
+	list_for_each(entry, &nvmet_subsystems_group.cg_children) {
+		struct config_item *item =
+			container_of(entry, struct config_item, ci_entry);
+		if (!strncmp(config_item_name(item), page, len)) {
+			pr_err("duplicate NQN %s\n", config_item_name(item));
+			up_write(&nvmet_config_sem);
+			return -EINVAL;
+		}
+	}
+	memset(nvmet_disc_subsys->subsysnqn, 0, NVMF_NQN_FIELD_LEN);
+	memcpy(nvmet_disc_subsys->subsysnqn, page, len);
+	up_write(&nvmet_config_sem);
+
+	return len;
+}
+
+CONFIGFS_ATTR(nvmet_root_, discovery_nqn);
+
+static struct configfs_attribute *nvmet_root_attrs[] = {
+	&nvmet_root_attr_discovery_nqn,
+	NULL,
+};
+
 static const struct config_item_type nvmet_root_type = {
+	.ct_attrs		= nvmet_root_attrs,
 	.ct_owner		= THIS_MODULE,
 };
 
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 3935165048e7..9c028bbedb45 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1530,6 +1530,13 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
 	}
 
 	down_read(&nvmet_config_sem);
+	if (!strncmp(nvmet_disc_subsys->subsysnqn, subsysnqn,
+				NVMF_NQN_SIZE)) {
+		if (kref_get_unless_zero(&nvmet_disc_subsys->ref)) {
+			up_read(&nvmet_config_sem);
+			return nvmet_disc_subsys;
+		}
+	}
 	list_for_each_entry(p, &port->subsystems, entry) {
 		if (!strncmp(p->subsys->subsysnqn, subsysnqn,
 				NVMF_NQN_SIZE)) {
-- 
2.35.3



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

* Re: [PATCHv2] nvmet: implement unique discovery NQN
  2023-12-15 12:39 [PATCHv2] nvmet: implement unique discovery NQN hare
@ 2023-12-15 16:59 ` Christoph Hellwig
  2023-12-19 14:17   ` Sagi Grimberg
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2023-12-15 16:59 UTC (permalink / raw
  To: hare
  Cc: Christoph Hellwig, Sagi Grimberg, Keith Busch, linux-nvme,
	Hannes Reinecke

On Fri, Dec 15, 2023 at 01:39:29PM +0100, hare@kernel.org wrote:
> From: Hannes Reinecke <hare@suse.de>
> 
> Add a configfs attribute 'discovery_nqn' in the 'nvmet' configfs
> directory to specify the unique discovery NQN.

That's a bit of a sparse commit log.  What do  unique discovery NQN do?
Please include a reference and a bit of an explnation.  And tell us
why this feature is useful for Linux to have.



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

* Re: [PATCHv2] nvmet: implement unique discovery NQN
  2023-12-15 16:59 ` Christoph Hellwig
@ 2023-12-19 14:17   ` Sagi Grimberg
  2023-12-20  7:41     ` Hannes Reinecke
  0 siblings, 1 reply; 4+ messages in thread
From: Sagi Grimberg @ 2023-12-19 14:17 UTC (permalink / raw
  To: Christoph Hellwig, hare; +Cc: Keith Busch, linux-nvme, Hannes Reinecke


>> Add a configfs attribute 'discovery_nqn' in the 'nvmet' configfs
>> directory to specify the unique discovery NQN.
> 
> That's a bit of a sparse commit log.  What do  unique discovery NQN do?
> Please include a reference and a bit of an explnation.  And tell us
> why this feature is useful for Linux to have.

I think that a unique NQN is better to authenticate against. That would
be the motivation in my mind here.


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

* Re: [PATCHv2] nvmet: implement unique discovery NQN
  2023-12-19 14:17   ` Sagi Grimberg
@ 2023-12-20  7:41     ` Hannes Reinecke
  0 siblings, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2023-12-20  7:41 UTC (permalink / raw
  To: Sagi Grimberg, Christoph Hellwig, hare; +Cc: Keith Busch, linux-nvme

On 12/19/23 15:17, Sagi Grimberg wrote:
> 
>>> Add a configfs attribute 'discovery_nqn' in the 'nvmet' configfs
>>> directory to specify the unique discovery NQN.
>>
>> That's a bit of a sparse commit log.  What do  unique discovery NQN do?
>> Please include a reference and a bit of an explnation.  And tell us
>> why this feature is useful for Linux to have.
> 
> I think that a unique NQN is better to authenticate against. That would
> be the motivation in my mind here.

Correct; unique NQN is actually a requirement for authentication.
I guess there is even a TPAR out there to make it so.

But my main driver here is to test persistent discovery controllers
as this impacts far more than 'just' the nvme subsystem. Most notably
it requires enablement from the OS side, and possibly modifications
in various areas (udev, systemd, dracut, etc).
All of which need to be tested.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Ivo Totev, Andrew McDonald,
Werner Knoblich



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

end of thread, other threads:[~2023-12-20  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-15 12:39 [PATCHv2] nvmet: implement unique discovery NQN hare
2023-12-15 16:59 ` Christoph Hellwig
2023-12-19 14:17   ` Sagi Grimberg
2023-12-20  7:41     ` Hannes Reinecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).