nvmet: implement unique discovery NQN
Subsystems (2)
PATCH v4 1/1 nvmet: implement unique discovery NQN
From: Hannes Reinecke <[email protected]>
Unique discovery NQNs allow to differentiate between discovery services from (typically physically separate) NVMe-oF subsystems. This is required for establishing secured connections as otherwise the credentials won't be unique and the integrity of the connection cannot be guaranteed.
This patch adda a configfs attribute 'discovery_nqn' in the 'nvmet' configfs directory to specify the unique discovery NQN.
--- drivers/nvme/target/configfs.c | 46 ++++++++++++++++++++++++++++++++++ drivers/nvme/target/core.c | 7 ++++++ 2 files changed, 53 insertions(+)
drivers/nvme/target/configfs.c +46 -0
@@ -1613,6 +1613,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);
@@ -2159,7 +2164,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 , };
drivers/nvme/target/core.c +7 -0
@@ -1552,6 +1552,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 )) {
Signature · 1 line
2.35.3
Quoted 10 lines · Hannes Reinecke
From: Hannes Reinecke <[email protected]>
Unique discovery NQNs allow to differentiate between discovery services from (typically physically separate) NVMe-oF subsystems. This is required for establishing secured connections as otherwise the credentials won't be unique and the integrity of the connection cannot be guaranteed.
This patch adda a configfs attribute 'discovery_nqn' in the 'nvmet' configfs directory to specify the unique discovery NQN.
Quoted 2 lines
Signed-off-by Hannes Reinecke <[email protected]>---
umm change log ?
Quoted 21 lines
drivers/nvme/target/configfs.c | 46 ++++++++++++++++++++++++++++++++++ drivers/nvme/target/core.c | 7 ++++++ 2 files changed, 53 insertions(+)drivers/nvme/target/configfs.c +5
-0@@ -1613,6 +1613,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);
drivers/nvme/target/configfs.c static const struct config_item_type nvmet_hosts_type = { · line 2172
Quoted 9 lines
drivers/nvme/target/configfs.c +6
-0@@ -2159,7 +2164,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); +} +
snprintf() with PAGE_SIZE ?
Quoted 4 lines
drivers/nvme/target/configfs.c +4
-0+static ssize_t nvmet_root_discovery_nqn_store (struct config_item *item, +const char *page,size_t count) +{ +struct list_head *entry;
drivers/nvme/target/configfs.c static const struct config_item_type nvmet_hosts_type = { · line 2186
Quoted 10 lines
drivers/nvme/target/configfs.c +10
-0+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);
newline here ?
drivers/nvme/target/configfs.c static const struct config_item_type nvmet_hosts_type = { · line 2198
Quoted 12 lines
drivers/nvme/target/configfs.c +12
-0+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; +}
-ck
Quoted 11 lines · Chaitanya Kulkarni
Quoted 10 lines · Hannes Reinecke
From: Hannes Reinecke <[email protected]>
Unique discovery NQNs allow to differentiate between discovery services from (typically physically separate) NVMe-oF subsystems. This is required for establishing secured connections as otherwise the credentials won't be unique and the integrity of the connection cannot be guaranteed.
This patch adda a configfs attribute 'discovery_nqn' in the 'nvmet' configfs directory to specify the unique discovery NQN.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Hannes Reinecke <[email protected]>---
umm change log ?
Just a rebase to latest head and modified the commit message slightly. Not sure if that warranted a change log.
Quoted 24 lines
Quoted 24 lines
drivers/nvme/target/configfs.c | 46 ++++++++++++++++++++++++++++++++++ drivers/nvme/target/core.c | 7 ++++++ 2 files changed, 53 insertions(+)drivers/nvme/target/configfs.c +5
-0@@ -1613,6 +1613,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);@@ -2159,7 +2164,48 @@ static const struct config_item_type nvmet_hosts_type = {static struct config_group nvmet_hosts_group;
Quoted 9 lines
drivers/nvme/target/configfs.c static const struct config_item_type nvmet_hosts_type = { · line 2172
Quoted 6 lines
drivers/nvme/target/configfs.c +6
-0+static ssize_t nvmet_root_discovery_nqn_show (struct config_item *item, +char *page) +{ +return sprintf (page,"%s\n" , nvmet_disc_subsys->subsysnqn); +} +
snprintf()withPAGE_SIZE?
Ok.
Quoted 8 lines
Quoted 8 lines
drivers/nvme/target/configfs.c +8
-0+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 )
Quoted 9 lines
drivers/nvme/target/configfs.c static const struct config_item_type nvmet_hosts_type = { · line 2186
Quoted 6 lines
drivers/nvme/target/configfs.c +6
-0+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);newline here ?
Blasted configfs always eats into the line length limitation. I see what I can do.
Thanks for the review.
Cheers,
Hannes
I think I gave you a review back in the last iteration, but if not this looks good to me, outside of the review by Chaitanya