public inbox for linux-nvme@lists.infradead.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 <keith.busch@wdc.com>,
	linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 1/3] nvmet: check for subsystem type in nvmet_find_get_subsys()
Date: Thu, 17 Mar 2022 15:26:32 +0100	[thread overview]
Message-ID: <20220317142634.49324-2-hare@suse.de> (raw)
In-Reply-To: <20220317142634.49324-1-hare@suse.de>

When looking for a subsystem we have two ways of finding the
subsystem: either looking for the subsystem NQN itself, or check
the type of the subsystem when looking for a discovery controller.
This patch implements this check, and also moves the check for
the static discovery controller to the end such that we can
return unique discovery controllers.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/target/core.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index b0dc6230d1b9..83eba511d098 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -1508,12 +1508,6 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
 	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;
-	}
-
 	down_read(&nvmet_config_sem);
 	list_for_each_entry(p, &port->subsystems, entry) {
 		if (!strncmp(p->subsys->subsysnqn, subsysnqn,
@@ -1523,8 +1517,22 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
 			up_read(&nvmet_config_sem);
 			return p->subsys;
 		}
+		if (!strcmp(NVME_DISC_SUBSYS_NAME, subsysnqn) &&
+		    nvmet_is_disc_subsys(p->subsys)) {
+			if (!kref_get_unless_zero(&p->subsys->ref))
+				break;
+			up_read(&nvmet_config_sem);
+			return p->subsys;
+		}
 	}
 	up_read(&nvmet_config_sem);
+
+	if (!strcmp(NVME_DISC_SUBSYS_NAME, subsysnqn)) {
+		if (!kref_get_unless_zero(&nvmet_disc_subsys->ref))
+			return NULL;
+		return nvmet_disc_subsys;
+	}
+
 	return NULL;
 }
 
-- 
2.29.2



  reply	other threads:[~2022-03-17 14:26 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 14:26 [PATCHv2 0/3] nvmet: unique discovery subsystem Hannes Reinecke
2022-03-17 14:26 ` Hannes Reinecke [this message]
2022-04-05  5:45   ` [PATCH 1/3] nvmet: check for subsystem type in nvmet_find_get_subsys() Christoph Hellwig
2022-04-05  5:53     ` Hannes Reinecke
2022-04-05  6:07       ` Christoph Hellwig
2022-04-05 13:06       ` John Meneghini
2022-03-17 14:26 ` [PATCH 2/3] nvmet: make the subsystem type configurable Hannes Reinecke
2022-04-05  5:47   ` Christoph Hellwig
2022-04-05  6:00     ` Hannes Reinecke
2022-04-05  6:09       ` Christoph Hellwig
2022-04-05  6:29         ` Hannes Reinecke
2022-04-05 10:35           ` Sagi Grimberg
2022-04-05 11:12             ` Hannes Reinecke
2022-04-05 15:02               ` John Meneghini
2022-04-05 13:15         ` John Meneghini
2022-03-17 14:26 ` [PATCH 3/3] nvmet: include all configured ports in discovery log page for unique discover controller Hannes Reinecke
2022-04-05  5:46   ` Christoph Hellwig
2022-04-05  6:15     ` Hannes Reinecke
2022-04-05  6:19       ` Christoph Hellwig
2022-04-05  6:35         ` Hannes Reinecke
2022-04-05  7:31           ` Christoph Hellwig
2022-04-05 10:32             ` Sagi Grimberg
2022-04-05 15:09             ` John Meneghini
2022-04-06 11:39               ` Hannes Reinecke
2022-04-05 10:41           ` Sagi Grimberg
2022-04-05 11:01             ` Hannes Reinecke
2022-04-05 14:22               ` Sagi Grimberg
  -- strict thread matches above, loose matches on Subject: below --
2022-03-17 13:18 [PATCH 0/3] nvmet: unique discovery subsystem Hannes Reinecke
2022-03-17 13:18 ` [PATCH 1/3] nvmet: check for subsystem type in nvmet_find_get_subsys() 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=20220317142634.49324-2-hare@suse.de \
    --to=hare@suse.de \
    --cc=hch@lst.de \
    --cc=keith.busch@wdc.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox