Skip to contentSkip to conversation

nvmet: discovery controller discovery support

PATCH Applied Hannes Reinecke 3 participants 7 messages Oct 18, 2021 – Oct 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover nvmet: discovery controller discovery support

TPAR 8014 (discovery controller discovery) adds a new discovery log page entry type '3' to describe the current discovery controller. This patchset adds support for this to the nvme target.

As usual, comments and reviews are welcome.

Changes to v1:
- Rebased to nvme-5.16

Hannes Reinecke (3):
nvmet: switch check for subsystem type
nvme: add new discovery log page entry definitions
nvmet: register discovery subsystem as 'current'

 drivers/nvme/target/core.c      |  2 ++
 drivers/nvme/target/discovery.c | 13 ++++++++-----
 drivers/nvme/target/nvmet.h     |  2 +-
 include/linux/nvme.h            | 12 ++++++++++--
 4 files changed, 21 insertions(+), 8 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH v2 1/3 nvmet: switch check for subsystem type

Invert the check for discovery subsystem type to allow for additional discovery subsystem types.

---
 drivers/nvme/target/nvmet.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/nvmet.h +1 -1
index f31dcc4fb1a2..af193423c10b 100644
@@ -579,7 +579,7 @@ static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req)
 
 static inline bool nvmet_is_disc_subsys(struct nvmet_subsys *subsys)
 {
-    return subsys->type == NVME_NQN_DISC;
+    return subsys->type != NVME_NQN_NVME;
 }
 
 #ifdef CONFIG_NVME_TARGET_PASSTHRU
Signature · 1 line
2.29.2
#4 lore raw

PATCH v2 2/3 nvme: add new discovery log page entry definitions

In reply to Hannes Reinecke

TP8014 adds a new SUBTYPE value and a new field EFLAGS for the discovery log page entry.

---
 include/linux/nvme.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
include/linux/nvme.h +10 -2
index 357482dedb59..4bd1c30715f9 100644
@@ -27,8 +27,9 @@
 #define NVME_NSID_ALL		0xffffffff
 
 enum nvme_subsys_type {
-	NVME_NQN_DISC	= 1,		/* Discovery type target subsystem */
+	NVME_NQN_DISC	= 1,		/* Referral to another discovery type target subsystem */
 	NVME_NQN_NVME	= 2,		/* NVME type target subsystem */
+	NVME_NQN_CURR	= 3,		/* Current discovery type target subsystem */
 };
 
 enum nvme_ctrl_type {
@@ -1312,6 +1313,12 @@ struct nvmf_common_command {
 
 #define MAX_DISC_LOGS	255
 
+/* Discovery log page entry flags (EFLAGS): */
+enum {
+	NVME_DISC_EFLAGS_EPCSD		= (1 << 1),
+	NVME_DISC_EFLAGS_DUPRETINFO	= (1 << 0),
+};
+
 /* Discovery log page entry */
 struct nvmf_disc_rsp_page_entry {
 	__u8		trtype;
@@ -1321,7 +1328,8 @@ struct nvmf_disc_rsp_page_entry {
 	__le16		portid;
 	__le16		cntlid;
 	__le16		asqsz;
-	__u8		resv8[22];
+	__le16		eflags;
+	__u8		resv10[20];
 	char		trsvcid[NVMF_TRSVCID_SIZE];
 	__u8		resv64[192];
 	char		subnqn[NVMF_NQN_FIELD_LEN];
Signature · 1 line
2.29.2
#5 lore raw

PATCH v2 3/3 nvmet: register discovery subsystem as 'current'

In reply to Hannes Reinecke

Register the discovery subsystem as the 'current' discovery subsystem, and add a new discovery log page entry for it.

---
 drivers/nvme/target/core.c      |  2 ++
 drivers/nvme/target/discovery.c | 13 ++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/nvme/target/core.c +2 -0
index d844fb9ef2eb..fd3d01b4b3d1 100644
@@ -1541,6 +1541,8 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
 		subsys->max_qid = NVMET_NR_QUEUES;
 		break;
 	case NVME_NQN_DISC:
+		fallthrough;
+	case NVME_NQN_CURR:
 		subsys->max_qid = 0;
 		break;
 	default:
drivers/nvme/target/discovery.c +8 -5
index 7b360f8d07e9..a2f08c49f07c 100644
@@ -146,7 +146,7 @@ static size_t discovery_log_entries(struct nvmet_req *req)
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
 	struct nvmet_subsys_link *p;
 	struct nvmet_port *r;
-	size_t entries = 0;
+	size_t entries = 1;
 
 	list_for_each_entry(p, &req->port->subsystems, entry) {
 		if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
@@ -171,6 +171,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
 	u32 numrec = 0;
 	u16 status = 0;
 	void *buffer;
+	char traddr[NVMF_TRADDR_SIZE];
 
 	if (!nvmet_check_transfer_len(req, data_len))
 		return;
@@ -204,14 +205,16 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
 		goto out;
 	}
 
+	nvmet_set_disc_traddr(req, req->port, traddr);
 	hdr = buffer;
+	nvmet_format_discovery_entry(hdr, req->port,
+				     nvmet_disc_subsys->subsysnqn,
+				     traddr, NVME_NQN_CURR, numrec);
+	numrec++;
 	list_for_each_entry(p, &req->port->subsystems, entry) {
-		char traddr[NVMF_TRADDR_SIZE];
-
 		if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
 			continue;
 
-		nvmet_set_disc_traddr(req, req->port, traddr);
 		nvmet_format_discovery_entry(hdr, req->port,
 				p->subsys->subsysnqn, traddr,
 				NVME_NQN_NVME, numrec);
@@ -389,7 +392,7 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
 int __init nvmet_init_discovery(void)
 {
 	nvmet_disc_subsys =
-		nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_DISC);
+		nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_CURR);
 	return PTR_ERR_OR_ZERO(nvmet_disc_subsys);
 }
 
Signature · 1 line
2.29.2
#2 lore raw

Re: [PATCH 1/3] nvmet: switch check for subsystem type

In reply to Hannes Reinecke
Quoted 13 lines · Hannes Reinecke

Invert the check for discovery subsystem type to allow for additional discovery subsystem types.

---
  drivers/nvme/target/nvmet.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/nvmet.h +0 -0
index f31dcc4fb1a2..af193423c10b 100644

drivers/nvme/target/nvmet.h static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req) · line 582

Quoted 5 lines
drivers/nvme/target/nvmet.h +1 -1
@@ -579,7 +579,7 @@ static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req)
 
  static inline bool nvmet_is_disc_subsys(struct nvmet_subsys *subsys)
  {
-    return subsys->type == NVME_NQN_DISC;
+    return subsys->type != NVME_NQN_NVME;

shouldn't we use switch and make code more readable for allowed subsys->type values ? unless there is a reason ..

Quoted 4 lines
drivers/nvme/target/nvmet.h +0 -0
  }
 
  #ifdef CONFIG_NVME_TARGET_PASSTHRU
#3 lore raw

Re: [PATCH 1/3] nvmet: switch check for subsystem type

Quoted 15 lines · Chaitanya Kulkarni
Quoted 14 lines · Hannes Reinecke

Invert the check for discovery subsystem type to allow for additional discovery subsystem types.

---
   drivers/nvme/target/nvmet.h | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/nvmet.h +0 -0
index f31dcc4fb1a2..af193423c10b 100644
@@ -579,7 +579,7 @@ static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req)
 
Quoted 8 lines

drivers/nvme/target/nvmet.h static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req) · line 582

Quoted 4 lines
drivers/nvme/target/nvmet.h +1 -1
   static inline bool nvmet_is_disc_subsys(struct nvmet_subsys *subsys)
   {
-    return subsys->type == NVME_NQN_DISC;
+    return subsys->type != NVME_NQN_NVME;

shouldn't we use switch and make code more readable for allowed subsys->type values ? unless there is a reason ..

Well, with this patch we still have only two values; introducing a switch for this feels a bit silly.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer