Daniel Wagner 927c00
From: Hannes Reinecke <hare@suse.de>
Daniel Wagner 927c00
Date: Fri, 26 Feb 2021 08:17:25 +0100
Daniel Wagner 927c00
Subject: nvme: simplify error logic in nvme_validate_ns()
Daniel Wagner 927c00
Patch-mainline: v5.12-rc3
Daniel Wagner 927c00
Git-commit: d95c1f4179a7f3ea8aa728ed00252a8ed0f8158f
Daniel Wagner 927c00
References: bsc#1184259
Daniel Wagner 927c00
Daniel Wagner 927c00
We only should remove namespaces when we get fatal error back from
Daniel Wagner 927c00
the device or when the namespace IDs have changed.
Daniel Wagner 927c00
So instead of painfully masking out error numbers which might indicate
Daniel Wagner 927c00
that the error should be ignored we could use an NVME status code
Daniel Wagner 927c00
to indicated when the namespace should be removed.
Daniel Wagner 927c00
That simplifies the final logic and makes it less error-prone.
Daniel Wagner 927c00
Daniel Wagner 927c00
Signed-off-by: Hannes Reinecke <hare@suse.de>
Daniel Wagner 927c00
Reviewed-by: Keith Busch <kbusch@kernel.org>
Daniel Wagner 927c00
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Daniel Wagner 927c00
Reviewed-by: Daniel Wagner <dwagner@suse.de>
Daniel Wagner 927c00
Signed-off-by: Christoph Hellwig <hch@lst.de>
Daniel Wagner 927c00
[dwagner: adapt to missing refactoring code]
Daniel Wagner 927c00
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Daniel Wagner 927c00
---
Daniel Wagner 927c00
 drivers/nvme/host/core.c |   22 +++++++++++++---------
Daniel Wagner 927c00
 1 file changed, 13 insertions(+), 9 deletions(-)
Daniel Wagner 927c00
Daniel Wagner 927c00
--- a/drivers/nvme/host/core.c
Daniel Wagner 927c00
+++ b/drivers/nvme/host/core.c
Daniel Wagner 927c00
@@ -1949,11 +1949,11 @@ static int nvme_revalidate_disk(struct g
Daniel Wagner 927c00
 	struct nvme_ctrl *ctrl = ns->ctrl;
Daniel Wagner 927c00
 	struct nvme_id_ns *id;
Daniel Wagner 927c00
 	struct nvme_ns_ids ids;
Daniel Wagner 927c00
-	int ret = 0;
Daniel Wagner 927c00
+	int ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
Daniel Wagner 927c00
 
Daniel Wagner 927c00
 	if (test_bit(NVME_NS_DEAD, &ns->flags)) {
Daniel Wagner 927c00
 		set_capacity(disk, 0);
Daniel Wagner 927c00
-		return -ENODEV;
Daniel Wagner 927c00
+		goto out;
Daniel Wagner 927c00
 	}
Daniel Wagner 927c00
 
Daniel Wagner 927c00
 	ret = nvme_identify_ns(ctrl, ns->head->ns_id, &id;;
Daniel Wagner 927c00
@@ -1961,7 +1961,7 @@ static int nvme_revalidate_disk(struct g
Daniel Wagner 927c00
 		goto out;
Daniel Wagner 927c00
 
Daniel Wagner 927c00
 	if (id->ncap == 0) {
Daniel Wagner 927c00
-		ret = -ENODEV;
Daniel Wagner 927c00
+		ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
Daniel Wagner 927c00
 		goto free_id;
Daniel Wagner 927c00
 	}
Daniel Wagner 927c00
 
Daniel Wagner 927c00
@@ -1972,7 +1972,7 @@ static int nvme_revalidate_disk(struct g
Daniel Wagner 927c00
 	if (!nvme_ns_ids_equal(&ns->head->ids, &ids)) {
Daniel Wagner 927c00
 		dev_err(ctrl->device,
Daniel Wagner 927c00
 			"identifiers changed for nsid %d\n", ns->head->ns_id);
Daniel Wagner 927c00
-		ret = -ENODEV;
Daniel Wagner 927c00
+		ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
Daniel Wagner 927c00
 		goto free_id;
Daniel Wagner 927c00
 	}
Daniel Wagner 927c00
 
Daniel Wagner 927c00
@@ -1981,13 +1981,17 @@ static int nvme_revalidate_disk(struct g
Daniel Wagner 927c00
 	kfree(id);
Daniel Wagner 927c00
 out:
Daniel Wagner 927c00
 	/*
Daniel Wagner 927c00
-	 * Only fail the function if we got a fatal error back from the
Daniel Wagner 927c00
+	 * Only remove the namespace if we got a fatal error back from the
Daniel Wagner 927c00
 	 * device, otherwise ignore the error and just move on.
Daniel Wagner 927c00
+	 *
Daniel Wagner 927c00
+	 * TODO: we should probably schedule a delayed retry here.
Daniel Wagner 927c00
 	 */
Daniel Wagner 927c00
-	if (ret == -ENOMEM || (ret > 0 && !(ret & NVME_SC_DNR)))
Daniel Wagner 927c00
-		ret = 0;
Daniel Wagner 927c00
-	else if (ret > 0)
Daniel Wagner 927c00
-		ret = blk_status_to_errno(nvme_error_status(ret));
Daniel Wagner 927c00
+	if (ret > 0) {
Daniel Wagner 927c00
+		if (ret & NVME_SC_DNR)
Daniel Wagner 927c00
+			ret = blk_status_to_errno(nvme_error_status(ret));
Daniel Wagner 927c00
+		else
Daniel Wagner 927c00
+			ret = 0;
Daniel Wagner 927c00
+	}
Daniel Wagner 927c00
 	return ret;
Daniel Wagner 927c00
 }
Daniel Wagner 927c00