linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Anton Eidelman <anton.eidelman@gmail.com>
To: linux-nvme@lists.infradead.org, hch@lst.de, kbusch@kernel.org,
	sagi@grimberg.me, axboe@fb.com
Cc: Anton Eidelman <anton@lightbitslabs.com>
Subject: [PATCH v3 3/3] nvme/multipath: fix stale ana state for namespaces just added by scan work
Date: Mon, 13 Sep 2021 15:46:32 -0600	[thread overview]
Message-ID: <20210913214632.88294-4-anton@lightbitslabs.com> (raw)
In-Reply-To: <20210913214632.88294-1-anton@lightbitslabs.com>

Scan work initially adds new namespaces to ctrl->namespaces TAIL.
They make the list unordered temporarily until nvme_scan_work()
finally sorts the list.

In case nvme_update_ana_state() runs while the list is unsorted,
the recently added namespaces are missed and their ana state
may remain not updated forever if timing between scan work and ana work
is unfortunate, e.g.
Initial state: namespaces = {2, 3}
scan_work: adds nsid=1: namespaces = {2, 3, 1}
scan_work: finds nsid=1 is still Inaccessible
ana_work: log page has nsids = {1, 2, 3, 4}, all Optimized.
ana_work: updates nsids {2, 3} but fails to find nsid=1 in namespaces.
scan_work: adds nsid=4: namespaces = {2, 3, 1, 4}
scan_work: finds nsid=4 is Optimized: sets it live.
scan_work: completes an sorts namespaces = {1, 2, 3, 4}
Result: nsid=1 will remain in Inaccessible state.

Solution:
In order to preserve the way ctrl->namespaces is updated and sorted,
make nvme_update_ana_state() deal with the case where ctrl->namespaces
is not fully sorted and has new namespaces appended with potentially
lower nsids.
nvme_update_ana_state() keeps track of the nsid seen in the list,
detects the unsorted case (rare), and restarts scanning of desc->nsids.

Signed-off-by: Anton Eidelman <anton@lightbitslabs.com>
---
 drivers/nvme/host/multipath.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index e1ce80c12815..14504a71711c 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -587,6 +587,7 @@ 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;
+	unsigned last_ns_nsid = 0;
 
 	dev_dbg(ctrl->device, "ANA group %d: %s.\n",
 			le32_to_cpu(desc->grpid),
@@ -603,6 +604,11 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
 		unsigned nsid;
 		unsigned ns_nsid = ns->head->ns_id;
 
+		if (ns_nsid < last_ns_nsid) {
+			/* Unsorted ctrl->namespaces: re-scan desc->nsids */
+			n = 0;
+		}
+		last_ns_nsid = ns_nsid;
 again:
 		nsid = le32_to_cpu(desc->nsids[n]);
 		if (ns_nsid < nsid)
-- 
2.25.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

      parent reply	other threads:[~2021-09-13 21:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12 18:54 [PATCH RESEND 0/3] nvme/mpath: fix missed namespaces in ana state update Anton Eidelman
2021-09-12 18:54 ` [PATCH 1/3] nvme/multipath: fix failure to update ns ana state Anton Eidelman
2021-09-12 18:54 ` [PATCH 2/3] nvme/multipath: cosmetic: keep ns nsid locally Anton Eidelman
2021-09-12 18:54 ` [PATCH 3/3] nvme/multipath: fix stale ana state for namespaces just added by scan work Anton Eidelman
2021-09-13 15:30   ` [PATCH v2 0/3] nvme/mpath: fix missed namespaces in ana state update Anton Eidelman
2021-09-13 15:30     ` [PATCH v2 1/3] nvme/multipath: fix failure to update ns ana state Anton Eidelman
2021-09-13 16:01       ` Christoph Hellwig
2021-09-13 19:29       ` Sagi Grimberg
2021-09-14  8:27       ` Christoph Hellwig
2021-09-13 15:30     ` [PATCH v2 2/3] nvme/multipath: cosmetic: keep ns nsid locally Anton Eidelman
2021-09-13 16:02       ` Christoph Hellwig
2021-09-13 20:19         ` Anton Eidelman
2021-09-13 20:57           ` Keith Busch
2021-09-14  5:44             ` Christoph Hellwig
2021-09-13 15:30     ` [PATCH v2 3/3] nvme/multipath: fix stale ana state for namespaces just added by scan work Anton Eidelman
2021-09-13 16:03       ` Christoph Hellwig
2021-09-13 16:08         ` Keith Busch
2021-09-14  6:24           ` Sagi Grimberg
2021-09-14  6:30             ` Christoph Hellwig
2021-09-14  6:40               ` Christoph Hellwig
2021-09-14  7:09               ` Sagi Grimberg
2021-09-14  7:32                 ` Christoph Hellwig
2021-09-14 16:45                   ` Anton Eidelman
2021-09-15  9:32                     ` Sagi Grimberg
2021-09-14 14:24               ` Keith Busch
2021-09-13 16:07       ` Keith Busch
2021-09-13 16:11         ` Christoph Hellwig
2021-09-13 16:24           ` Keith Busch
2021-09-13 16:46           ` Anton Eidelman
2021-09-13 15:32     ` [PATCH v2 0/3] nvme/mpath: fix missed namespaces in ana state update Christoph Hellwig
2021-09-13 15:42     ` [PATCH v2 0/3] nvme/mpath: fix missed namespaces in ana state update FIXED Anton Eidelman
2021-09-13 21:46       ` [PATCH v3 0/3] nvme/mpath: fix missed namespaces in ana state update Anton Eidelman
2021-09-13 21:46         ` [PATCH v3 1/3] nvme/multipath: fix failure to update ns ana state Anton Eidelman
2021-09-13 21:46         ` [PATCH v3 2/3] nvme/multipath: cosmetic: keep ns nsid locally Anton Eidelman
2021-09-13 21:46         ` Anton Eidelman [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=20210913214632.88294-4-anton@lightbitslabs.com \
    --to=anton.eidelman@gmail.com \
    --cc=anton@lightbitslabs.com \
    --cc=axboe@fb.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).