From: Hannes Reinecke <hare@suse.de>
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@suse.de>
Subject: [PATCH 1/3] nvmet: make the subsystem type configurable
Date: Fri, 8 Apr 2022 08:59:28 +0200 [thread overview]
Message-ID: <20220408065930.123015-2-hare@suse.de> (raw)
In-Reply-To: <20220408065930.123015-1-hare@suse.de>
Make the subsystem type configurable to allow for unique
discovery subsystems by changing the subsystem type to
'discovery'.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/target/configfs.c | 60 +++++++++++++++++++++++++++++++++
drivers/nvme/target/discovery.c | 2 +-
drivers/nvme/target/nvmet.h | 1 +
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index e44b2988759e..38b0ab9fb721 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -834,6 +834,7 @@ static int nvmet_port_subsys_allow_link(struct config_item *parent,
}
list_add_tail(&link->entry, &port->subsystems);
+ subsys->port_count++;
nvmet_port_disc_changed(port, subsys);
up_write(&nvmet_config_sem);
@@ -862,6 +863,7 @@ static void nvmet_port_subsys_drop_link(struct config_item *parent,
found:
list_del(&p->entry);
+ subsys->port_count--;
nvmet_port_del_ctrls(port, subsys);
nvmet_port_disc_changed(port, subsys);
@@ -1234,6 +1236,63 @@ static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
}
CONFIGFS_ATTR(nvmet_subsys_, attr_model);
+static const struct nvmet_type_name_map nvmet_subsys_type_map[] = {
+ { NVME_NQN_DISC, "referral" },
+ { NVME_NQN_NVME, "nvme" },
+ { NVME_NQN_CURR, "discovery" },
+};
+
+static ssize_t nvmet_subsys_attr_type_show(struct config_item *item,
+ char *page)
+{
+ u8 type = to_subsys(item)->type;
+ int i;
+
+ for (i = 1; i < ARRAY_SIZE(nvmet_subsys_type_map); i++) {
+ if (nvmet_subsys_type_map[i].type == type)
+ return snprintf(page, PAGE_SIZE, "%s\n",
+ nvmet_subsys_type_map[i].name);
+ }
+
+ return snprintf(page, PAGE_SIZE, "\n");
+}
+
+static ssize_t nvmet_subsys_attr_type_store(struct config_item *item,
+ const char *page, size_t count)
+{
+ struct nvmet_subsys *subsys = to_subsys(item);
+ int i;
+
+ if (subsys->subsys_discovered)
+ return -EACCES;
+
+ for (i = 0; i < ARRAY_SIZE(nvmet_subsys_type_map); i++) {
+ if (sysfs_streq(page, nvmet_subsys_type_map[i].name))
+ goto found;
+ }
+
+ pr_err("Invalid value '%s' for subsystem type\n", page);
+ return -EINVAL;
+
+found:
+ down_write(&nvmet_config_sem);
+ if (subsys->port_count) {
+ pr_err("cannot change type when linked to ports\n");
+ up_write(&nvmet_config_sem);
+ return -EACCES;
+ }
+ if (!xa_empty(&subsys->namespaces)) {
+ pr_err("cannot change type when namespaces are configured\n");
+ up_write(&nvmet_config_sem);
+ return -EACCES;
+ }
+ subsys->type = nvmet_subsys_type_map[i].type;
+ up_write(&nvmet_config_sem);
+
+ return count;
+}
+CONFIGFS_ATTR(nvmet_subsys_, attr_type);
+
#ifdef CONFIG_BLK_DEV_INTEGRITY
static ssize_t nvmet_subsys_attr_pi_enable_show(struct config_item *item,
char *page)
@@ -1263,6 +1322,7 @@ static struct configfs_attribute *nvmet_subsys_attrs[] = {
&nvmet_subsys_attr_attr_cntlid_min,
&nvmet_subsys_attr_attr_cntlid_max,
&nvmet_subsys_attr_attr_model,
+ &nvmet_subsys_attr_attr_type,
#ifdef CONFIG_BLK_DEV_INTEGRITY
&nvmet_subsys_attr_attr_pi_enable,
#endif
diff --git a/drivers/nvme/target/discovery.c b/drivers/nvme/target/discovery.c
index c2162eef8ce1..b5012df790d5 100644
--- a/drivers/nvme/target/discovery.c
+++ b/drivers/nvme/target/discovery.c
@@ -219,7 +219,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
nvmet_format_discovery_entry(hdr, req->port,
p->subsys->subsysnqn, traddr,
- NVME_NQN_NVME, numrec);
+ p->subsys->type, numrec);
numrec++;
}
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 69818752a33a..ecba3890ce65 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -216,6 +216,7 @@ struct nvmet_subsys {
struct mutex lock;
struct kref ref;
+ unsigned int port_count;
struct xarray namespaces;
unsigned int nr_namespaces;
--
2.29.2
next prev parent reply other threads:[~2022-04-08 6:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 6:59 [PATCHv5 0/3] nvmet: unique discovery subsystems Hannes Reinecke
2022-04-08 6:59 ` Hannes Reinecke [this message]
2022-04-11 10:32 ` [PATCH 1/3] nvmet: make the subsystem type configurable Sagi Grimberg
2022-04-11 10:52 ` Hannes Reinecke
2022-04-11 10:36 ` Sagi Grimberg
2022-04-08 6:59 ` [PATCH 2/3] nvmet: per-port discovery subsystem Hannes Reinecke
2022-04-11 10:45 ` Sagi Grimberg
2022-04-11 12:07 ` Hannes Reinecke
2022-04-12 10:40 ` Sagi Grimberg
2022-04-12 11:51 ` Hannes Reinecke
2022-04-12 12:21 ` Sagi Grimberg
2022-04-08 6:59 ` [PATCH 3/3] nvmet: include all configured ports in the discovery log page Hannes Reinecke
2022-04-11 10:54 ` Sagi Grimberg
2022-04-11 12:27 ` Hannes Reinecke
2022-04-12 10:49 ` Sagi Grimberg
2022-04-12 12:08 ` Hannes Reinecke
2022-04-12 12:29 ` Sagi Grimberg
-- strict thread matches above, loose matches on Subject: below --
2022-04-07 10:48 [PATCHv4 0/3] nvmet: unique discovery subsystems Hannes Reinecke
2022-04-07 10:48 ` [PATCH 1/3] nvmet: make the subsystem type configurable Hannes Reinecke
2022-04-07 15:44 ` Christoph Hellwig
2022-04-07 16:55 ` Hannes Reinecke
2022-04-08 5:46 ` Christoph Hellwig
2022-04-06 14:22 [PATCHv3 0/3] nvmet: unique discovery subsystem Hannes Reinecke
2022-04-06 14:22 ` [PATCH 1/3] nvmet: make the subsystem type configurable 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=20220408065930.123015-2-hare@suse.de \
--to=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--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.