nvmet: unique discovery subsystem
Subsystems (2)
v3 cover nvmet: unique discovery subsystem
Hi all,
here's my third attempt to support unique discovery subsystems, heavily modified from the previous two attempts.
The main idea is to not create the discovery subsystem per default, but rather require the admin to create one.
As this is an incompatible change I've added a module parameter 'expose_discovery_subsys' to switch to the new behaviour. The admin then need to configure the subsystem as normal by linking it into the ports where the discovery subsystem should be visible. And the discovery log then includes all configured ports to all configured subsystems, as usual modified by whether the host may access this subsystem or not.
Currently, there is no restriction on the number of discovery subsystems; technically one can create any number of them. But this is primarily because I'm too lazy to check (and we don't have a global enumeration for subsystems) and not due to a design decision.
As usual, comments and reviews are welcome.
Changes to v2:
- Heavily rework after discussion on the mailing list
Changes to the original submission:
- Include all subsystems in the discovery log output
Hannes Reinecke (3):
nvmet: make the subsystem type configurable
nvmet: expose discovery subsystems
nvmet: include all configured port in the discovery log page
drivers/nvme/target/configfs.c | 80 ++++++++++++++++++- drivers/nvme/target/core.c | 19 ++++- drivers/nvme/target/discovery.c | 133 ++++++++++++++++++++++++++------ drivers/nvme/target/nvmet.h | 2 + 4 files changed, 205 insertions(+), 29 deletions(-)
Signature · 1 line
2.29.2
PATCH v3 1/3 nvmet: make the subsystem type configurable
Make the subsystem type configurable to allow for unique discovery subsystems by changing the subsystem type to 'discovery'.
--- drivers/nvme/target/configfs.c | 54 +++++++++++++++++++++++++++++++++ drivers/nvme/target/discovery.c | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-)
drivers/nvme/target/configfs.c +54 -0
@@ -1234,6 +1234,59 @@ 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 (nvmet_subsys_type_map[i].type ==NVME_NQN_CURR ) { +if (!xa_empty (&subsys->namespaces)) { +pr_err ("discovery subsystem cannot have namespaces\n" ); +return -EINVAL ; + } + } + 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 +1316,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
drivers/nvme/target/discovery.c +1 -1
@@ -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++; }
Signature · 1 line
2.29.2
PATCH v3 2/3 nvmet: expose discovery subsystems
In reply to Hannes ReineckeAdd a module parameter 'expose_discovery_subsys' to allow creation of discovery subsystems through configfs.
If the option is enabled no default discovery subsystem is created per default, and the user is required to create one via configfs.
--- drivers/nvme/target/configfs.c | 26 ++++++++++++-- drivers/nvme/target/core.c | 19 ++++++++-- drivers/nvme/target/discovery.c | 63 ++++++++++++++++++++++++++------- drivers/nvme/target/nvmet.h | 2 ++ 4 files changed, 91 insertions(+), 19 deletions(-)
drivers/nvme/target/configfs.c +23 -3
@@ -20,6 +20,16 @@ static const struct config_item_type nvmet_subsys_type;static LIST_HEAD (nvmet_ports_list);struct list_head *nvmet_ports = &nvmet_ports_list; +static int expose_discovery_subsys; +module_param (expose_discovery_subsys, int,0644 ); +MODULE_PARM_DESC (expose_discovery_subsys, +"Expose discovery subsytem in configfs" ); + +bool nvmet_expose_discovery_subsys (void ) +{ +return expose_discovery_subsys; +} +struct nvmet_type_name_map {u8 type;const char *name;
@@ -1264,6 +1274,11 @@ static ssize_t nvmet_subsys_attr_type_store(struct config_item *item,if (subsys->subsys_discovered)return -EACCES ; +if (!expose_discovery_subsys) { +pr_err ("Unique discovery subsystem NQNs are not enabled\n" ); +return -EINVAL ; + } +for (i =0 ; i <ARRAY_SIZE (nvmet_subsys_type_map); i++) {if (sysfs_streq (page, nvmet_subsys_type_map[i].name)) goto found;
@@ -1348,13 +1363,18 @@ static struct config_group *nvmet_subsys_make(struct config_group *group, const char *name) {struct nvmet_subsys *subsys; +enum nvme_subsys_type subsys_type =NVME_NQN_NVME ;if (sysfs_streq (name,NVME_DISC_SUBSYS_NAME )) { -pr_err ("can't create discovery subsystem through configfs\n" ); -return ERR_PTR (-EINVAL ); +if (expose_discovery_subsys) + subsys_type =NVME_NQN_CURR ; +else { +pr_err ("can't create discovery subsystem through configfs\n" ); +return ERR_PTR (-EINVAL ); + } } - subsys =nvmet_subsys_alloc (name,NVME_NQN_NVME ); + subsys =nvmet_subsys_alloc (name, subsys_type);if (IS_ERR (subsys))return ERR_CAST (subsys);
drivers/nvme/target/core.c +16 -3
@@ -1491,14 +1491,19 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port, const char *subsysnqn) {struct nvmet_subsys_link *p; +enum nvme_subsys_type subsys_type =NVME_NQN_NVME ;if (!port)return NULL ;if (!strcmp (NVME_DISC_SUBSYS_NAME , subsysnqn)) { -if (!kref_get_unless_zero (&nvmet_disc_subsys->ref)) -return NULL ; -return nvmet_disc_subsys; +if (nvmet_expose_discovery_subsys ()) + subsys_type =NVME_NQN_CURR ; +else { +if (!kref_get_unless_zero (&nvmet_disc_subsys->ref)) +return NULL ; +return nvmet_disc_subsys; + } }down_read (&nvmet_config_sem);
@@ -1510,6 +1515,13 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,up_read (&nvmet_config_sem);return p->subsys; } +if (subsys_type ==NVME_NQN_CURR && + p->subsys->type == subsys_type) { +if (!kref_get_unless_zero (&p->subsys->ref)) +break ; +up_read (&nvmet_config_sem); +return p->subsys; + } }up_read (&nvmet_config_sem);return NULL ;
@@ -1544,6 +1556,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,case NVME_NQN_DISC :case NVME_NQN_CURR : subsys->max_qid =0 ; + subsys->allow_any_host =1 ;break ;default :pr_err ("%s: Unknown Subsystem type - %d\n" , __func__, type);
drivers/nvme/target/discovery.c +50 -13
122 lines not on this page · raw message
drivers/nvme/target/nvmet.h +2 -0
@@ -532,6 +532,8 @@ extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS + 1];extern u64 nvmet_ana_chgcnt;extern struct rw_semaphore nvmet_ana_sem; +bool nvmet_expose_discovery_subsys (void ); +bool nvmet_host_allowed (struct nvmet_subsys *subsys,const char *hostnqn);int nvmet_bdev_ns_enable (struct nvmet_ns *ns);
Signature · 1 line
2.29.2
Christoph Hellwig
maintainerRe: [PATCH 2/3] nvmet: expose discovery subsystems
Quoted 4 lines · Hannes Reinecke
Add a module parameter '
expose_discovery_subsys' to allow creation of discovery subsystems through configfs.
If the option is enabled no default discovery subsystem is created per default, and the user is required to create one via configfs.
I'm not fan of module parameters. Can we do this using configfs on a per-port basis?
Re: [PATCH 2/3] nvmet: expose discovery subsystems
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Hannes Reinecke
Add a module parameter '
expose_discovery_subsys' to allow creation of discovery subsystems through configfs.
If the option is enabled no default discovery subsystem is created per default, and the user is required to create one via configfs.I'm not fan of module parameters. Can we do this using configfs on a per-port basis?
configfs: yes.
per-port: we could, but then we cannot configure the default discovery subsystem. But we can't do that anyway. I'll give it a shot.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
PATCH v3 3/3 nvmet: include all configured port in the discovery log page
In reply to Hannes ReineckeWhen exposed discovery subsystems are enabled we should include all configured ports in the discovery log page, not just those through which the controller was connected.
--- drivers/nvme/target/discovery.c | 72 ++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 11 deletions(-)
drivers/nvme/target/discovery.c +61 -11
@@ -172,6 +172,7 @@ static void nvmet_set_disc_traddr(struct nvmet_req *req, struct nvmet_port *portstatic size_t discovery_log_entries (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl; +struct nvmet_subsys *disc_subsys = ctrl->subsys;struct nvmet_subsys_link *p;struct nvmet_port *r;size_t entries =0 ;
@@ -179,10 +180,27 @@ static size_t discovery_log_entries(struct nvmet_req *req)if (!nvmet_expose_discovery_subsys ()) entries++; -list_for_each_entry (p, &req->port->subsystems, entry) { -if (!nvmet_host_allowed (p->subsys, ctrl->hostnqn)) -continue ; - entries++; +list_for_each_entry (r, nvmet_ports, global_entry) { +if (!nvmet_expose_discovery_subsys ()) { +if (r != req->port) +continue ; + }else { +bool linked = false; + +list_for_each_entry (p, &r->subsystems, entry) { +if (p->subsys == disc_subsys) { + linked = true; +break ; + } + } +if (!linked) +continue ; + } +list_for_each_entry (p, &r->subsystems, entry) { +if (!nvmet_host_allowed (p->subsys, ctrl->hostnqn)) +continue ; + entries++; + } }list_for_each_entry (r, &req->port->referrals, entry) entries++;
@@ -193,6 +211,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req) {const int entry_size =sizeof (struct nvmf_disc_rsp_page_entry );struct nvmet_ctrl *ctrl = req->sq->ctrl; +struct nvmet_subsys *disc_subsys = ctrl->subsys;struct nvmf_disc_rsp_page_hdr *hdr;u64 offset =nvmet_get_log_page_offset (req->cmd);size_t data_len =nvmet_get_log_page_len (req->cmd);
@@ -246,14 +265,45 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req) numrec++; } -list_for_each_entry (p, &req->port->subsystems, entry) { -if (!nvmet_host_allowed (p->subsys, ctrl->hostnqn)) -continue ; +list_for_each_entry (r, nvmet_ports, global_entry) { +nvmet_set_disc_traddr (req, r, traddr); + +if (!nvmet_expose_discovery_subsys ()) { +/* +* If the discovery subsystem is not exposed fall +* back to the original design of only presenting +* information about the port to which the controller +* is connected. +*/ +if (r != req->port) +continue ; + }else { +bool linked = false; + +/* +* If the discovery subsystem is exposed present +* information about all ports into which the +* discovery subsystem is linked. +*/ +list_for_each_entry (p, &r->subsystems, entry) { +if (p->subsys == disc_subsys) { + linked = true; +break ; + } + } +if (!linked) +continue ; + } -nvmet_format_discovery_entry (hdr, req->port, - p->subsys->subsysnqn, traddr, - p->subsys->type, numrec); - numrec++; +list_for_each_entry (p, &r->subsystems, entry) { +if (!nvmet_host_allowed (p->subsys, ctrl->hostnqn)) +continue ; + +nvmet_format_discovery_entry (hdr, r, + p->subsys->subsysnqn, traddr, + p->subsys->type, numrec); + numrec++; + } }list_for_each_entry (r, &req->port->referrals, entry) {
Signature · 1 line
2.29.2