All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>, Keith Busch <kbusch@kernel.org>,
	linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 3/3] nvmet: include all configured port in the discovery log page
Date: Wed,  6 Apr 2022 16:22:10 +0200	[thread overview]
Message-ID: <20220406142210.71248-4-hare@suse.de> (raw)
In-Reply-To: <20220406142210.71248-1-hare@suse.de>

When 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.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/target/discovery.c | 72 ++++++++++++++++++++++++++++-----
 1 file changed, 61 insertions(+), 11 deletions(-)

diff --git a/drivers/nvme/target/discovery.c b/drivers/nvme/target/discovery.c
index 13fda8f9d60c..d23353a750dd 100644
--- a/drivers/nvme/target/discovery.c
+++ b/drivers/nvme/target/discovery.c
@@ -172,6 +172,7 @@ static void nvmet_set_disc_traddr(struct nvmet_req *req, struct nvmet_port *port
 static 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) {
-- 
2.29.2



      parent reply	other threads:[~2022-04-06 14:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2022-04-06 14:22 ` [PATCH 2/3] nvmet: expose discovery subsystems Hannes Reinecke
2022-04-07  9:45   ` Christoph Hellwig
2022-04-07 10:13     ` Hannes Reinecke
2022-04-06 14:22 ` Hannes Reinecke [this message]

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=20220406142210.71248-4-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.