Skip to content

Commit 0dd6fff

Browse files
author
Christoph Hellwig
committed
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: 1a893c2 ("nvme: refactor namespace probing") Reported-by: Nils Hanke <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Tested-by: Nils Hanke <[email protected]>
1 parent c0c33b9 commit 0dd6fff

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

drivers/nvme/host/core.c

+18-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct nvme_ns_info {
3838
bool is_shared;
3939
bool is_readonly;
4040
bool is_ready;
41+
bool is_removed;
4142
};
4243

4344
unsigned int admin_timeout = 60;
@@ -1402,16 +1403,8 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,
14021403
error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id));
14031404
if (error) {
14041405
dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error);
1405-
goto out_free_id;
1406+
kfree(*id);
14061407
}
1407-
1408-
error = NVME_SC_INVALID_NS | NVME_SC_DNR;
1409-
if ((*id)->ncap == 0) /* namespace not allocated or attached */
1410-
goto out_free_id;
1411-
return 0;
1412-
1413-
out_free_id:
1414-
kfree(*id);
14151408
return error;
14161409
}
14171410

@@ -1425,6 +1418,13 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
14251418
ret = nvme_identify_ns(ctrl, info->nsid, &id);
14261419
if (ret)
14271420
return ret;
1421+
1422+
if (id->ncap == 0) {
1423+
/* namespace not allocated or attached */
1424+
info->is_removed = true;
1425+
return -ENODEV;
1426+
}
1427+
14281428
info->anagrpid = id->anagrpid;
14291429
info->is_shared = id->nmic & NVME_NS_NMIC_SHARED;
14301430
info->is_readonly = id->nsattr & NVME_NS_ATTR_RO;
@@ -4429,6 +4429,7 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
44294429
{
44304430
struct nvme_ns_info info = { .nsid = nsid };
44314431
struct nvme_ns *ns;
4432+
int ret;
44324433

44334434
if (nvme_identify_ns_descs(ctrl, &info))
44344435
return;
@@ -4445,19 +4446,19 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
44454446
* set up a namespace. If not fall back to the legacy version.
44464447
*/
44474448
if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) ||
4448-
(info.ids.csi != NVME_CSI_NVM && info.ids.csi != NVME_CSI_ZNS)) {
4449-
if (nvme_ns_info_from_id_cs_indep(ctrl, &info))
4450-
return;
4451-
} else {
4452-
if (nvme_ns_info_from_identify(ctrl, &info))
4453-
return;
4454-
}
4449+
(info.ids.csi != NVME_CSI_NVM && info.ids.csi != NVME_CSI_ZNS))
4450+
ret = nvme_ns_info_from_id_cs_indep(ctrl, &info);
4451+
else
4452+
ret = nvme_ns_info_from_identify(ctrl, &info);
4453+
4454+
if (info.is_removed)
4455+
nvme_ns_remove_by_nsid(ctrl, nsid);
44554456

44564457
/*
44574458
* Ignore the namespace if it is not ready. We will get an AEN once it
44584459
* becomes ready and restart the scan.
44594460
*/
4460-
if (!info.is_ready)
4461+
if (ret || !info.is_ready)
44614462
return;
44624463

44634464
ns = nvme_find_get_ns(ctrl, nsid);

0 commit comments

Comments
 (0)