Skip to content

Commit 00ff400

Browse files
author
Christoph Hellwig
committed
nvme: add a quirk to disable namespace identifiers
Add a quirk to disable using and exporting namespace identifiers for controllers where they are broken beyond repair. The most directly visible problem with non-unique namespace identifiers is that they break the /dev/disk/by-id/ links, with the link for a supposedly unique identifier now pointing to one of multiple possible namespaces that share the same ID, and a somewhat random selection of which one actually shows up. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
1 parent b42b6f4 commit 00ff400

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

drivers/nvme/host/core.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
12881288
warn_str, cur->nidl);
12891289
return -1;
12901290
}
1291+
if (ctrl->quirks & NVME_QUIRK_BOGUS_NID)
1292+
return NVME_NIDT_EUI64_LEN;
12911293
memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN);
12921294
return NVME_NIDT_EUI64_LEN;
12931295
case NVME_NIDT_NGUID:
@@ -1296,6 +1298,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
12961298
warn_str, cur->nidl);
12971299
return -1;
12981300
}
1301+
if (ctrl->quirks & NVME_QUIRK_BOGUS_NID)
1302+
return NVME_NIDT_NGUID_LEN;
12991303
memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN);
13001304
return NVME_NIDT_NGUID_LEN;
13011305
case NVME_NIDT_UUID:
@@ -1304,6 +1308,8 @@ static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
13041308
warn_str, cur->nidl);
13051309
return -1;
13061310
}
1311+
if (ctrl->quirks & NVME_QUIRK_BOGUS_NID)
1312+
return NVME_NIDT_UUID_LEN;
13071313
uuid_copy(&ids->uuid, data + sizeof(*cur));
13081314
return NVME_NIDT_UUID_LEN;
13091315
case NVME_NIDT_CSI:
@@ -1400,12 +1406,18 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,
14001406
if ((*id)->ncap == 0) /* namespace not allocated or attached */
14011407
goto out_free_id;
14021408

1403-
if (ctrl->vs >= NVME_VS(1, 1, 0) &&
1404-
!memchr_inv(ids->eui64, 0, sizeof(ids->eui64)))
1405-
memcpy(ids->eui64, (*id)->eui64, sizeof(ids->eui64));
1406-
if (ctrl->vs >= NVME_VS(1, 2, 0) &&
1407-
!memchr_inv(ids->nguid, 0, sizeof(ids->nguid)))
1408-
memcpy(ids->nguid, (*id)->nguid, sizeof(ids->nguid));
1409+
1410+
if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) {
1411+
dev_info(ctrl->device,
1412+
"Ignoring bogus Namespace Identifiers\n");
1413+
} else {
1414+
if (ctrl->vs >= NVME_VS(1, 1, 0) &&
1415+
!memchr_inv(ids->eui64, 0, sizeof(ids->eui64)))
1416+
memcpy(ids->eui64, (*id)->eui64, sizeof(ids->eui64));
1417+
if (ctrl->vs >= NVME_VS(1, 2, 0) &&
1418+
!memchr_inv(ids->nguid, 0, sizeof(ids->nguid)))
1419+
memcpy(ids->nguid, (*id)->nguid, sizeof(ids->nguid));
1420+
}
14091421

14101422
return 0;
14111423

drivers/nvme/host/nvme.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ enum nvme_quirks {
144144
* encoding the generation sequence number.
145145
*/
146146
NVME_QUIRK_SKIP_CID_GEN = (1 << 17),
147+
148+
/*
149+
* Reports garbage in the namespace identifiers (eui64, nguid, uuid).
150+
*/
151+
NVME_QUIRK_BOGUS_NID = (1 << 18),
147152
};
148153

149154
/*

0 commit comments

Comments
 (0)