Skip to contentSkip to conversation

nvme: bring back auto-removal of deleted namespaces during sequential scan

PATCH In review Christoph Hellwig 5 participants 6 messages Feb 21, 2023 – Mar 2, 2023 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme: bring back auto-removal of deleted namespaces during sequential scan

Bring back the check of the Identify Namespace return value for the legacy NVMe 1.0-style sequential scanning. While NVMe 1.0 does not support namespace management, there are "modern" cloud solutions like Google Cloud Platform that claim the obsolete 1.0 compliance for no good reason while supporting proprietary sideband namespace management.

Fixes 1a893c2bfef4 ("nvme: refactor namespace probing")

---

Nils, this is a slightly different variant from the one you tested earlier, can you retest it?

 drivers/nvme/host/core.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/nvme/host/core.c +18 -17
index 8b64211411626b..fbed8d1a02ef42 100644
@@ -38,6 +38,7 @@ struct nvme_ns_info {
 	bool is_shared;
 	bool is_readonly;
 	bool is_ready;
+	bool is_removed;
 };
 
 unsigned int admin_timeout = 60;
@@ -1445,16 +1446,8 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,
 	error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id));
 	if (error) {
 		dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error);
-		goto out_free_id;
+		kfree(*id);
 	}
-
-	error = NVME_SC_INVALID_NS | NVME_SC_DNR;
-	if ((*id)->ncap == 0) /* namespace not allocated or attached */
-		goto out_free_id;
-	return 0;
-
-out_free_id:
-	kfree(*id);
 	return error;
 }
 
@@ -1468,6 +1461,13 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
 	ret = nvme_identify_ns(ctrl, info->nsid, &id);
 	if (ret)
 		return ret;
+
+	if (id->ncap == 0) {
+		/* namespace not allocated or attached */
+		info->is_removed = true;
+		return -ENODEV;
+	}
+
 	info->anagrpid = id->anagrpid;
 	info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
 	info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
@@ -4418,6 +4418,7 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 {
 	struct nvme_ns_info info = { .nsid = nsid };
 	struct nvme_ns *ns;
+	int ret;
 
 	if (nvme_identify_ns_descs(ctrl, &info))
 		return;
@@ -4434,19 +4435,19 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	 * set up a namespace.  If not fall back to the legacy version.
 	 */
 	if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) ||
-	    (info.ids.csi != NVME_CSI_NVM && info.ids.csi != NVME_CSI_ZNS)) {
-		if (nvme_ns_info_from_id_cs_indep(ctrl, &info))
-			return;
-	} else {
-		if (nvme_ns_info_from_identify(ctrl, &info))
-			return;
-	}
+	    (info.ids.csi != NVME_CSI_NVM && info.ids.csi != NVME_CSI_ZNS))
+		ret = nvme_ns_info_from_id_cs_indep(ctrl, &info);
+	else
+		ret = nvme_ns_info_from_identify(ctrl, &info);
+
+	if (info.is_removed)
+		nvme_ns_remove_by_nsid(ctrl, nsid);
 
 	/*
 	 * Ignore the namespace if it is not ready. We will get an AEN once it
 	 * becomes ready and restart the scan.
 	 */
-	if (!info.is_ready)
+	if (ret || !info.is_ready)
 		return;
 
 	ns = nvme_find_get_ns(ctrl, nsid);
Signature · 1 line
2.39.1
Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Christoph Hellwig

Nils, this is a slightly different variant from the one you tested earlier, can you retest it?

Retested it, also seems to work fine on GCP.
Namespaces are cleaned up correctly.
Attaching multiple disks and detaching them again in random order also works as expected. Thanks!

Tested-by Nils Hanke <[email protected] <mailto:[email protected]>>
Tested-by Tested-by
#2 lore raw
Quoted 1 line
Tested-by Nils Hanke <[email protected] <mailto:[email protected]>>

My mail client messed that up.

________________________________________
From: Nils Hanke <[email protected]>
Sent: Wednesday, February 22, 2023 11:45 AM
To: Christoph Hellwig
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] nvme: bring back auto-removal of deleted namespaces during sequential scan

Quoted 4 lines · Christoph Hellwig

Nils, this is a slightly different variant from the one you tested earlier, can you retest it?

Retested it, also seems to work fine on GCP.
Namespaces are cleaned up correctly.
Attaching multiple disks and detaching them again in random order also works as expected. Thanks!

Tested-by Nils Hanke <[email protected] <mailto:[email protected]>>
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

Bring back the check of the Identify Namespace return value for the legacy NVMe 1.0-style sequential scanning. While NVMe 1.0 does not support namespace management, there are "modern" cloud solutions like Google Cloud Platform that claim the obsolete 1.0 compliance for no good reason while supporting proprietary sideband namespace management.

Fixes 1a893c2bfef4 ("nvme: refactor namespace probing")

Looks good.

Reviewed-by on v1 1/1
#5 lore raw
In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Bring back the check of the Identify Namespace return value for the legacy NVMe 1.0-style sequential scanning. While NVMe 1.0 does not support namespace management, there are "modern" cloud solutions like Google Cloud Platform that claim the obsolete 1.0 compliance for no good reason while supporting proprietary sideband namespace management.

Quoted 8 lines
Fixes 1a893c2bfef4 ("nvme: refactor namespace probing")

---

Nils, this is a slightly different variant from the one you tested earlier, can you retest it?

It did pass the Nils test, looks good.

-ck