[PATCH 3/8] nvme: allocate a new namespace if validation fail

Max Gurtovoy mgurtovoy at nvidia.com
Mon Jan 22 06:56:54 PST 2024


Namespace validation can fail in case some of the namespace identifiers
were changed. In this case, we will give up and remove the namespace.
Add a mechanism to retry the allocation of a new namespace instance that
will be setup according to the new namespace identifiers.

Reviewed-by: Israel Rukshin <israelr at nvidia.com>
Signed-off-by: Max Gurtovoy <mgurtovoy at nvidia.com>
---
 drivers/nvme/host/core.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9d46acf5b6cb..4fd3612b7570 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3857,7 +3857,14 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)
 	}
 }
 
-static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)
+/*
+ * Validate the namespace according to the updated namespace info.
+ * Remove the namespace from the controller in case of a mismatch with previous
+ * identifiers.
+ *
+ * Returns true if namespace was removed, false otherwise.
+ */
+static bool nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)
 {
 	int ret = NVME_SC_INVALID_NS | NVME_SC_DNR;
 
@@ -3886,10 +3893,13 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)
 	 * 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.
+	 * Caller should probably retry namespace allocation.
 	 */
-	if (ret > 0 && (ret & NVME_SC_DNR))
+	if (ret > 0 && (ret & NVME_SC_DNR)) {
 		nvme_ns_remove(ns);
+		return true;
+	}
+	return false;
 }
 
 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
@@ -3930,8 +3940,10 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 
 	ns = nvme_find_get_ns(ctrl, nsid);
 	if (ns) {
-		nvme_validate_ns(ns, &info);
+		bool removed = nvme_validate_ns(ns, &info);
 		nvme_put_ns(ns);
+		if (removed)
+			nvme_alloc_ns(ctrl, &info);
 	} else {
 		nvme_alloc_ns(ctrl, &info);
 	}
-- 
2.18.1




More information about the Linux-nvme mailing list