Skip to contentSkip to conversation

NVMe: Fix removal in case of active namespace list scanning method

PATCH Superseded Sunad Bhandary S 2 participants 2 messages May 26, 2016 – May 27, 2016 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NVMe: Fix removal in case of active namespace list scanning method

From: Sunad Bhandary <[email protected]>

In case of the active namespace list scanning method, a namespace that is detached is not removed from the host if it was the last entry in the list. Fix this by adding a scan to validate namespaces greater than the value of prev.

This also handles the case of removing namespaces whose value exceed the device's reported number of namespaces.

Signed-off-by Sunad Bhandary S <sunad.s at samsung.com>
---
 drivers/nvme/host/core.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +16 -6
index 2de248b..3ad5abd 100644
@@ -1483,6 +1483,18 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 		nvme_alloc_ns(ctrl, nsid);
 }
 
+static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
+					unsigned nsid)
+{
+	struct nvme_ns *ns, *next;
+
+	list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
+		if (ns->ns_id > nsid) {
+			nvme_ns_remove(ns);
+		}
+	}
+}
+
 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
 {
 	struct nvme_ns *ns;
@@ -1497,7 +1509,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
 	for (i = 0; i < num_lists; i++) {
 		ret = nvme_identify_ns_list(ctrl, prev, ns_list);
 		if (ret)
-			goto out;
+			goto free;
 
 		for (j = 0; j < min(nn, 1024U); j++) {
 			nsid = le32_to_cpu(ns_list[j]);
@@ -1515,13 +1527,14 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
 		nn -= j;
 	}
  out:
+	nvme_remove_invalid_namespaces(ctrl, prev);
+ free:
 	kfree(ns_list);
 	return ret;
 }
 
 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
 {
-	struct nvme_ns *ns, *next;
 	unsigned i;
 
 	lockdep_assert_held(&ctrl->namespaces_mutex);
@@ -1529,10 +1542,7 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
 	for (i = 1; i <= nn; i++)
 		nvme_validate_ns(ctrl, i);
 
-	list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
-		if (ns->ns_id > nn)
-			nvme_ns_remove(ns);
-	}
+	nvme_remove_invalid_namespaces(ctrl, nn);
 }
 
 static void nvme_scan_work(struct work_struct *work)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 NVMe: Fix removal in case of active namespace list scanning method

drivers/nvme/host/core.c static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid) · line 1494

Quoted 3 lines
drivers/nvme/host/core.c +3 -0
+		if (ns->ns_id > nsid) {
+			nvme_ns_remove(ns);
+		}

no need for this set of curly braces.

Otherwise looks fine:

Reviewed-by Christoph Hellwig <hch at lst.de>