mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@fb.com,
	martin.petersen@oracle.com,
	james.bottomley@hansenpartnership.com, hare@suse.com
Cc: jmeneghi@redhat.com, linux-nvme@lists.infradead.org,
	linux-scsi@vger.kernel.org, michael.christie@oracle.com,
	snitzer@kernel.org, bmarzins@redhat.com,
	dm-devel@lists.linux.dev, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	John Garry <john.g.garry@oracle.com>
Subject: [PATCH 02/19] nvme: introduce a namespace count in the ns head structure
Date: Wed, 25 Feb 2026 15:39:50 +0000	[thread overview]
Message-ID: <20260225154007.1033735-3-john.g.garry@oracle.com> (raw)
In-Reply-To: <20260225154007.1033735-1-john.g.garry@oracle.com>

For switching to use libmultipath, the per-namespace sibling list entry in
nvme_ns.sibling will be replaced with multipath_device.sibling list
pointer.

For when CONFIG_LIBMULTIPATH is disabled, that list of namespaces would no
longer be maintained.

However the core code checks in many places whether there is any
namespace in the head list, like in nvme_ns_remove().

Introduce a separate count of the number of namespaces for the namespace
head and use that count for the places where the per-namespace head list
of namespaces is checked to be empty.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/nvme/host/core.c      | 10 +++++++---
 drivers/nvme/host/multipath.c |  4 ++--
 drivers/nvme/host/nvme.h      |  1 +
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 37e30caff4149..76249871dd7c2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4024,7 +4024,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
 	} else {
 		ret = -EINVAL;
 		if ((!info->is_shared || !head->shared) &&
-		    !list_empty(&head->list)) {
+		    head->ns_count) {
 			dev_err(ctrl->device,
 				"Duplicate unshared namespace %d\n",
 				info->nsid);
@@ -4047,6 +4047,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
 	}
 
 	list_add_tail_rcu(&ns->siblings, &head->list);
+	head->ns_count++;
 	ns->head = head;
 	mutex_unlock(&ctrl->subsys->lock);
 
@@ -4192,7 +4193,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
  out_unlink_ns:
 	mutex_lock(&ctrl->subsys->lock);
 	list_del_rcu(&ns->siblings);
-	if (list_empty(&ns->head->list)) {
+	ns->head->ns_count--;
+	if (!ns->head->ns_count) {
 		list_del_init(&ns->head->entry);
 		/*
 		 * If multipath is not configured, we still create a namespace
@@ -4217,6 +4219,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 
 static void nvme_ns_remove(struct nvme_ns *ns)
 {
+	struct nvme_ns_head *head = ns->head;
 	bool last_path = false;
 
 	if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
@@ -4238,7 +4241,8 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 
 	mutex_lock(&ns->ctrl->subsys->lock);
 	list_del_rcu(&ns->siblings);
-	if (list_empty(&ns->head->list)) {
+	head->ns_count--;
+	if (!head->ns_count) {
 		if (!nvme_mpath_queue_if_no_path(ns->head))
 			list_del_init(&ns->head->entry);
 		last_path = true;
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index c70fff58b5698..0d540749b16ee 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -703,7 +703,7 @@ static void nvme_remove_head_work(struct work_struct *work)
 	bool remove = false;
 
 	mutex_lock(&head->subsys->lock);
-	if (list_empty(&head->list)) {
+	if (!head->ns_count) {
 		list_del_init(&head->entry);
 		remove = true;
 	}
@@ -1307,7 +1307,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
 	 * head->list here. If it is no longer empty then we skip enqueuing the
 	 * delayed head removal work.
 	 */
-	if (!list_empty(&head->list))
+	if (head->ns_count)
 		goto out;
 
 	if (head->delayed_removal_secs) {
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 057d051ef925d..397e8685f6c38 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -539,6 +539,7 @@ struct nvme_ns_head {
 	struct nvme_effects_log *effects;
 	u64			nuse;
 	unsigned		ns_id;
+	int			ns_count;
 	int			instance;
 #ifdef CONFIG_BLK_DEV_ZONED
 	u64			zsze;
-- 
2.43.5


  parent reply	other threads:[~2026-02-25 15:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 15:39 [PATCH 00/19] nvme: switch to libmultipath John Garry
2026-02-25 15:39 ` [PATCH 01/19] nvme-multipath: pass NS head to nvme_mpath_revalidate_paths() John Garry
2026-02-25 15:39 ` John Garry [this message]
2026-03-02 12:46   ` [PATCH 02/19] nvme: introduce a namespace count in the ns head structure Nilay Shroff
2026-03-02 15:57     ` John Garry
2026-02-25 15:39 ` [PATCH 03/19] nvme-multipath: add nvme_is_mpath_request() John Garry
2026-02-25 15:39 ` [PATCH 04/19] nvme-multipath: add initial support for using libmultipath John Garry
2026-02-25 15:39 ` [PATCH 05/19] nvme-multipath: add nvme_mpath_available_path() John Garry
2026-02-25 15:39 ` [PATCH 06/19] nvme-multipath: add nvme_mpath_{add, remove}_cdev() John Garry
2026-02-25 15:39 ` [PATCH 07/19] nvme-multipath: add nvme_mpath_is_{disabled, optimised} John Garry
2026-02-25 15:39 ` [PATCH 08/19] nvme-multipath: add nvme_mpath_get_access_state() John Garry
2026-02-25 15:39 ` [PATCH 09/19] nvme-multipath: add nvme_mpath_{bdev, cdev}_ioctl() John Garry
2026-02-25 15:39 ` [PATCH 10/19] nvme-multipath: add uring_cmd support John Garry
2026-02-25 15:39 ` [PATCH 11/19] nvme-multipath: add nvme_mpath_get_iopolicy() John Garry
2026-02-25 15:40 ` [PATCH 12/19] nvme-multipath: add PR support for libmultipath John Garry
2026-02-25 15:40 ` [PATCH 13/19] nvme-multipath: add nvme_mpath_report_zones() John Garry
2026-02-25 15:40 ` [PATCH 14/19] nvme-multipath: add nvme_mpath_get_unique_id() John Garry
2026-02-25 15:40 ` [PATCH 15/19] nvme-multipath: add nvme_mpath_synchronize() John Garry
2026-02-25 15:40 ` [PATCH 16/19] nvme-multipath: add nvme_mpath_{add,delete}_ns() John Garry
2026-03-02 12:48   ` Nilay Shroff
2026-03-02 15:59     ` John Garry
2026-02-25 15:40 ` [PATCH 17/19] nvme-multipath: add nvme_mpath_head_queue_if_no_path() John Garry
2026-02-25 15:40 ` [PATCH 18/19] nvme-multipath: set mpath_head_template.device_groups John Garry
2026-02-25 15:40 ` [PATCH 19/19] nvme-multipath: switch to use libmultipath John Garry
2026-03-02 12:57   ` Nilay Shroff
2026-03-02 16:13     ` John Garry
2026-03-02 14:12 ` [PATCH 00/19] nvme: switch to libmultipath Christoph Hellwig
2026-03-02 14:58   ` John Garry
2026-03-31  8:25     ` John Garry

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=20260225154007.1033735-3-john.g.garry@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=axboe@fb.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=jmeneghi@redhat.com \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=sagi@grimberg.me \
    --cc=snitzer@kernel.org \
    /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

all inboxes | Powered by JetHome®