nvme/mpath: fix missed namespaces in ana state update
cover nvme/mpath: fix missed namespaces in ana state update
Fixed two issues in nvme_update_ana_state() that caused ana_work to miss existing namespaces and consequently a failure to update the namespace ANA state based on the ANA log page.
1) A plain bug: we skipped an nsid in desc->nsids in a certain combination of nsids present and nsids reports in the ANA log, and failed to match this nsid to an existing namespace.
2) Unhandled situation when scan_work appended new namespaces to ctrl->namespaces and did not sort the list yet.
In such transient state ana_work would fail to match nsids to those new namespaces.
Both issues potentially caused some namespaces to get stuck in an incorrect ANA state, e.g. to never become live.
Anton Eidelman (3):
nvme/multipath: fix failure to update ns ana state nvme/multipath: cosmetic: keep ns nsid locally nvme/multipath: fix stale ana state for namespaces just added by scan
work
drivers/nvme/host/multipath.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
Signature · 31 lines
2.25.1 -- *Lightbits Labs** *Lead the cloud-native data center transformation by delivering *scalable *and *efficient *software defined storage that is *easy *to consume. *This message is sent in confidence for the addressee only. It may contain legally privileged information. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to preserve this confidentiality, advise the sender immediately of any error in transmission and delete the email from their systems.* _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 1/3 nvme/multipath: fix failure to update ns ana state
nvme_update_ana_state() has a deficiency that results in failure to update the ana state for a namespace in the following case:
nsid's in ctrl->namespaces: 1, 3, 4
nsid's in desc->nsids: 1, 2, 3, 4
Loop iteration 0:
ns index = 0, n = 0, ns->head->ns_id = 1, nsid = 1, MATCH.
Loop iteration 1:
ns index = 1, n = 1, ns->head->ns_id = 3, nsid = 2, NO MATCH.
Loop iteration 2:
ns index = 2, n = 2, ns->head->ns_id = 4, nsid = 4, MATCH.Result: missed nsid=3 and did not update its ana state.
Solution: when ns->head->ns_id is higher than nsid, increment n and RETRY with the SAME ns.
--- drivers/nvme/host/multipath.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/nvme/host/multipath.c +5 -2
@@ -600,14 +600,17 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,down_read (&ctrl->namespaces_rwsem);list_for_each_entry (ns, &ctrl->namespaces, list) { -unsigned nsid =le32_to_cpu (desc->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)nvme_update_ns_ana_state (desc, ns);if (++n == nr_nsids)break ; +if (ns->head->ns_id > nsid) + goto again; }up_read (&ctrl->namespaces_rwsem);return 0 ;
Signature · 31 lines
2.25.1 -- *Lightbits Labs** *Lead the cloud-native data center transformation by delivering *scalable *and *efficient *software defined storage that is *easy *to consume. *This message is sent in confidence for the addressee only. It may contain legally privileged information. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to preserve this confidentiality, advise the sender immediately of any error in transmission and delete the email from their systems.* _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 2/3 nvme/multipath: cosmetic: keep ns nsid locally
In reply to Anton EidelmanKeep the nsid of the current namespace in a local variable. Change the type to unsigned int to make checkpatch happy.
--- drivers/nvme/host/multipath.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/nvme/host/multipath.c +6 -4
@@ -600,16 +600,18 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,down_read (&ctrl->namespaces_rwsem);list_for_each_entry (ns, &ctrl->namespaces, list) { -unsigned nsid; +unsigned int nsid; +unsigned int ns_nsid = ns->head->ns_id; + again: nsid =le32_to_cpu (desc->nsids[n]); -if (ns->head->ns_id < nsid) +if (ns_nsid < nsid)continue ; -if (ns->head->ns_id == nsid) +if (ns_nsid == nsid)nvme_update_ns_ana_state (desc, ns);if (++n == nr_nsids)break ; -if (ns->head->ns_id > nsid) +if (ns_nsid > nsid) goto again; }up_read (&ctrl->namespaces_rwsem);
Signature · 31 lines
2.25.1 -- *Lightbits Labs** *Lead the cloud-native data center transformation by delivering *scalable *and *efficient *software defined storage that is *easy *to consume. *This message is sent in confidence for the addressee only. It may contain legally privileged information. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to preserve this confidentiality, advise the sender immediately of any error in transmission and delete the email from their systems.* _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 3/3 nvme/multipath: fix stale ana state for namespaces just added by scan work
In reply to Anton EidelmanScan 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 Inaccessibleana_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.
--- drivers/nvme/host/multipath.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/nvme/host/multipath.c +6 -0
@@ -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 int 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 int nsid;unsigned int ns_nsid = ns->head->ns_id; +if (ns_nsid < last_ns_nsid) { +/* Detected unsorted ctrl->namespaces: re-scan desc->nsids */ + last_ns_nsid = ns_nsid; + n =0 ; + } again: nsid =le32_to_cpu (desc->nsids[n]);if (ns_nsid < nsid)
Signature · 31 lines
2.25.1 -- *Lightbits Labs** *Lead the cloud-native data center transformation by delivering *scalable *and *efficient *software defined storage that is *easy *to consume. *This message is sent in confidence for the addressee only. It may contain legally privileged information. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to preserve this confidentiality, advise the sender immediately of any error in transmission and delete the email from their systems.* _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Please, ignore this thread - will resend with correct formatting.
Signature · 7 lines
2.25.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PLEASE, IGNORE THIS THREAD - BAD FORMATTING
In reply to Anton EidelmanPlease, ignore this thread - will resend with correct formatting.
Signature · 7 lines
2.25.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme