Blob Blame History Raw
From: Hannes Reinecke <hare@suse.de>
Date: Fri, 26 Feb 2021 08:17:25 +0100
Subject: nvme: simplify error logic in nvme_validate_ns()
Patch-mainline: v5.12-rc3
Git-commit: d95c1f4179a7f3ea8aa728ed00252a8ed0f8158f
References: bsc#1184259

We only should remove namespaces when we get fatal error back from
the device or when the namespace IDs have changed.
So instead of painfully masking out error numbers which might indicate
that the error should be ignored we could use an NVME status code
to indicated when the namespace should be removed.
That simplifies the final logic and makes it less error-prone.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
[dwagner: adapt to missing refactoring code]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 drivers/nvme/host/core.c |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1949,11 +1949,11 @@ static int nvme_revalidate_disk(struct g
 	struct nvme_ctrl *ctrl = ns->ctrl;
 	struct nvme_id_ns *id;
 	struct nvme_ns_ids ids;
-	int ret = 0;
+	int ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
 
 	if (test_bit(NVME_NS_DEAD, &ns->flags)) {
 		set_capacity(disk, 0);
-		return -ENODEV;
+		goto out;
 	}
 
 	ret = nvme_identify_ns(ctrl, ns->head->ns_id, &id);
@@ -1961,7 +1961,7 @@ static int nvme_revalidate_disk(struct g
 		goto out;
 
 	if (id->ncap == 0) {
-		ret = -ENODEV;
+		ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
 		goto free_id;
 	}
 
@@ -1972,7 +1972,7 @@ static int nvme_revalidate_disk(struct g
 	if (!nvme_ns_ids_equal(&ns->head->ids, &ids)) {
 		dev_err(ctrl->device,
 			"identifiers changed for nsid %d\n", ns->head->ns_id);
-		ret = -ENODEV;
+		ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
 		goto free_id;
 	}
 
@@ -1981,13 +1981,17 @@ static int nvme_revalidate_disk(struct g
 	kfree(id);
 out:
 	/*
-	 * Only fail the function if we got a fatal error back from the
+	 * Only remove the namespace if we got a fatal error back from the
 	 * device, otherwise ignore the error and just move on.
+	 *
+	 * TODO: we should probably schedule a delayed retry here.
 	 */
-	if (ret == -ENOMEM || (ret > 0 && !(ret & NVME_SC_DNR)))
-		ret = 0;
-	else if (ret > 0)
-		ret = blk_status_to_errno(nvme_error_status(ret));
+	if (ret > 0) {
+		if (ret & NVME_SC_DNR)
+			ret = blk_status_to_errno(nvme_error_status(ret));
+		else
+			ret = 0;
+	}
 	return ret;
 }