Skip to contentSkip to conversation

nvme: multipath: round-robin fixes

PATCH In review [email protected] 4 participants 7 messages Aug 6, 2020 – Aug 7, 2020 NVMe

lore
Share & tools
lore
#0 lore raw

cover nvme: multipath: round-robin fixes

From: Martin Wilck <[email protected]>

Hello Christoph, Sagi, Hannes,

The version of the patch set "nvme-multipath: fixes for non-optimized paths" that was eventually merged fails for the case where just a single, non-optimized path is available.
This mini-series fixes it, and simplifies the code somewhat.

Regards,
Martin

Martin Wilck (2):
nvme: multipath: round-robin: fix single non-optimized path case
nvme: multipath: round-robin: eliminate "fallback" variable

 drivers/nvme/host/multipath.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
Signature · 7 lines
2.28.0


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#1 lore raw

PATCH 1/2 nvme: multipath: round-robin: fix single non-optimized path case

From: Martin Wilck <[email protected]>

If there's only one usable, non-optimized path, nvme_round_robin_path() returns NULL, which is wrong. Fix it by falling back to "old", like in the single optimized path case. Also, if the active path isn't changed, there's no need to re-assign the pointer.

Fixes 3f6e3246db0e ("nvme-multipath: fix logic for non-optimized paths")
---
 drivers/nvme/host/multipath.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/nvme/host/multipath.c +10 -5
index 3ded54d2c9c6..a64dfff0d0ce 100644
@@ -255,12 +255,17 @@ static struct nvme_ns *nvme_round_robin_path(struct nvme_ns_head *head,
 			fallback = ns;
 	}
 
-	/* No optimized path found, re-check the current path */
+	/*
+	 * The loop above skips the current path for round-robin semantics.
+	 * Fall back to the current path if either:
+	 *  - no other optimized path found and current is optimized,
+	 *  - no other usable path found and current is usable.
+	 */
 	if (!nvme_path_is_disabled(old) &&
-	    old->ana_state == NVME_ANA_OPTIMIZED) {
-		found = old;
-		goto out;
-	}
+	    (old->ana_state == NVME_ANA_OPTIMIZED ||
+	     (!fallback && old->ana_state == NVME_ANA_NONOPTIMIZED)))
+		return old;
+
 	if (!fallback)
 		return NULL;
 	found = fallback;
Signature · 7 lines
2.28.0


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#2 lore raw

Re: [PATCH 1/2] nvme: multipath: round-robin: fix single non-optimized path case

Quoted 10 lines · On Thu, 2020-08-06 at 15:19 +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

If there's only one usable, non-optimized path, nvme_round_robin_path()
returns NULL, which is wrong. Fix it by falling back to "old", like in
the single optimized path case. Also, if the active path isn't changed,
there's no need to re-assign the pointer.

Quoted 4 lines
Fixes 3f6e3246db0e ("nvme-multipath: fix logic for non-optimized

paths")

I made a mistake here. It should be

because Martin G. provided the initial idea for the fix.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Tested-by Martin George
#3 lore raw

Re: [PATCH 1/2] nvme: multipath: round-robin: fix single non-optimized path case

Quoted 16 lines · Martin Wilck
Quoted 10 lines · On Thu, 2020-08-06 at 15:19 +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

If there's only one usable, non-optimized path, nvme_round_robin_path()
returns NULL, which is wrong. Fix it by falling back to "old", like in
the single optimized path case. Also, if the active path isn't changed,
there's no need to re-assign the pointer.

Quoted 4 lines
Fixes 3f6e3246db0e ("nvme-multipath: fix logic for non-optimized

paths")

Quoted 6 lines

I made a mistake here. It should be

because Martin G. provided the initial idea for the fix.

Thanks MartinW.

I've also tested this patch and verified that it works fine for all scenarios including the single ANA non-optimized path scenario. So in addition to MartinW's Signed-off-by tag, please add

as well for this patch. Thank you.

-Martin George
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#4 lore raw

PATCH 2/2 nvme: multipath: round-robin: eliminate "fallback" variable

In reply to [email protected]

From: Martin Wilck <[email protected]>

If we find an optimized path, we quit the loop immediately. Thus we can use just one variable for the next path, slighly simplifying the code.

---
 drivers/nvme/host/multipath.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/nvme/host/multipath.c +4 -5
index a64dfff0d0ce..760f625cefc8 100644
@@ -233,7 +233,7 @@ static struct nvme_ns *nvme_next_ns(struct nvme_ns_head *head,
 static struct nvme_ns *nvme_round_robin_path(struct nvme_ns_head *head,
 		int node, struct nvme_ns *old)
 {
-	struct nvme_ns *ns, *found, *fallback = NULL;
+	struct nvme_ns *ns, *found = NULL;
 
 	if (list_is_singular(&head->list)) {
 		if (nvme_path_is_disabled(old))
@@ -252,7 +252,7 @@ static struct nvme_ns *nvme_round_robin_path(struct nvme_ns_head *head,
 			goto out;
 		}
 		if (ns->ana_state == NVME_ANA_NONOPTIMIZED)
-			fallback = ns;
+			found = ns;
 	}
 
 	/*
@@ -263,12 +263,11 @@ static struct nvme_ns *nvme_round_robin_path(struct nvme_ns_head *head,
 	 */
 	if (!nvme_path_is_disabled(old) &&
 	    (old->ana_state == NVME_ANA_OPTIMIZED ||
-	     (!fallback && old->ana_state == NVME_ANA_NONOPTIMIZED)))
+	     (!found && old->ana_state == NVME_ANA_NONOPTIMIZED)))
 		return old;
 
-	if (!fallback)
+	if (!found)
 		return NULL;
-	found = fallback;
 out:
 	rcu_assign_pointer(head->current_path[node], found);
 	return found;
Signature · 7 lines
2.28.0


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme