From: Hannes Reinecke <hare@kernel.org>
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@kernel.org>
Subject: [PATCH 1/3] nvme-multipath: simplify loop in nvme_update_ana_state()
Date: Mon, 7 Oct 2024 12:01:32 +0200 [thread overview]
Message-ID: <20241007100134.21104-2-hare@kernel.org> (raw)
In-Reply-To: <20241007100134.21104-1-hare@kernel.org>
Currently nvme_update_ana_state() iterates over all namespaces
with the srcu lock held, and calls the 'cb' function if a
match on the list of namespaces from the ANA log is found.
This assumes that the iteration itself is relatively quick,
and the namespace state itself doesn't change during iteration.
For more complex functions (eg if the 'cb' function triggers
mpath_set_live() which then kicks off a partition scan) the
namespace state might change while iterating, and the rcu-protected
area becomes really long.
So change the loop to iterated over the entries in the ANA log,
and call nvme_find_get_ns() on each entry.
With that the 'cb' function is executed outside of the RCU
protected area, and normal reference counting rules apply.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/nvme/host/multipath.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index f72c5a6a2d8e..61f8ae199288 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -745,7 +745,6 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
u32 nr_nsids = le32_to_cpu(desc->nnsids), n = 0;
unsigned *nr_change_groups = data;
struct nvme_ns *ns;
- int srcu_idx;
dev_dbg(ctrl->device, "ANA group %d: %s.\n",
le32_to_cpu(desc->grpid),
@@ -757,21 +756,16 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
if (!nr_nsids)
return 0;
- srcu_idx = srcu_read_lock(&ctrl->srcu);
- list_for_each_entry_rcu(ns, &ctrl->namespaces, list) {
+ for(n = 0; n < nr_nsids; n++) {
unsigned nsid;
-again:
+
nsid = le32_to_cpu(desc->nsids[n]);
- if (ns->head->ns_id < nsid)
- continue;
- if (ns->head->ns_id == nsid)
+ ns = nvme_find_get_ns(ctrl, nsid);
+ if (ns) {
nvme_update_ns_ana_state(desc, ns);
- if (++n == nr_nsids)
- break;
- if (ns->head->ns_id > nsid)
- goto again;
+ nvme_put_ns(ns);
+ }
}
- srcu_read_unlock(&ctrl->srcu, srcu_idx);
return 0;
}
--
2.35.3
next prev parent reply other threads:[~2024-10-07 10:02 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 10:01 [PATCH 0/3] nvme-multipath: fix deadlock in device_add_disk() Hannes Reinecke
2024-10-07 10:01 ` Hannes Reinecke [this message]
2024-10-07 15:46 ` [PATCH 1/3] nvme-multipath: simplify loop in nvme_update_ana_state() Keith Busch
2024-10-08 6:39 ` Christoph Hellwig
2024-10-20 23:33 ` Sagi Grimberg
2024-10-07 10:01 ` [PATCH 2/3] nvme-multipath: cannot disconnect controller on stuck partition scan Hannes Reinecke
2024-10-07 18:19 ` Keith Busch
2024-10-08 6:43 ` Christoph Hellwig
2024-10-08 7:17 ` Hannes Reinecke
2024-10-08 20:41 ` Keith Busch
2024-10-09 6:23 ` Hannes Reinecke
2024-10-09 16:33 ` Keith Busch
2024-10-09 17:10 ` Keith Busch
2024-10-09 17:32 ` Keith Busch
2024-10-10 6:16 ` Hannes Reinecke
2024-10-10 7:18 ` Hannes Reinecke
2024-10-10 8:17 ` Christoph Hellwig
2024-10-10 8:57 ` Hannes Reinecke
2024-10-15 14:33 ` Keith Busch
2024-10-15 14:56 ` Hannes Reinecke
2024-10-15 15:10 ` Keith Busch
2024-10-20 23:37 ` Sagi Grimberg
2024-10-07 10:01 ` [PATCH 3/3] nvme-multipath: skip failed paths during " Hannes Reinecke
2024-10-08 6:40 ` Christoph Hellwig
2024-10-20 23:38 ` Sagi Grimberg
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=20241007100134.21104-2-hare@kernel.org \
--to=hare@kernel.org \
--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.