Skip to content

Commit e2724cb

Browse files
author
Christoph Hellwig
committed
nvme: fix the check for duplicate unique identifiers
nvme_subsys_check_duplicate_ids should needs to return an error if any of the identifiers matches, not just if all of them match. But it does not need to and should not look at the CSI value for this sanity check. Rewrite the logic to be separate from nvme_ns_ids_equal and optimize it by reducing duplicate checks for non-present identifiers. Fixes: ed754e5 ("nvme: track shared namespaces") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]>
1 parent fd8099e commit e2724cb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/nvme/host/core.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,13 +1716,6 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
17161716
blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
17171717
}
17181718

1719-
static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
1720-
{
1721-
return !uuid_is_null(&ids->uuid) ||
1722-
memchr_inv(ids->nguid, 0, sizeof(ids->nguid)) ||
1723-
memchr_inv(ids->eui64, 0, sizeof(ids->eui64));
1724-
}
1725-
17261719
static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
17271720
{
17281721
return uuid_equal(&a->uuid, &b->uuid) &&
@@ -3676,12 +3669,21 @@ static struct nvme_ns_head *nvme_find_ns_head(struct nvme_subsystem *subsys,
36763669
static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys,
36773670
struct nvme_ns_ids *ids)
36783671
{
3672+
bool has_uuid = !uuid_is_null(&ids->uuid);
3673+
bool has_nguid = memchr_inv(ids->nguid, 0, sizeof(ids->nguid));
3674+
bool has_eui64 = memchr_inv(ids->eui64, 0, sizeof(ids->eui64));
36793675
struct nvme_ns_head *h;
36803676

36813677
lockdep_assert_held(&subsys->lock);
36823678

36833679
list_for_each_entry(h, &subsys->nsheads, entry) {
3684-
if (nvme_ns_ids_valid(ids) && nvme_ns_ids_equal(ids, &h->ids))
3680+
if (has_uuid && uuid_equal(&ids->uuid, &h->ids.uuid))
3681+
return -EINVAL;
3682+
if (has_nguid &&
3683+
memcmp(&ids->nguid, &h->ids.nguid, sizeof(ids->nguid)) == 0)
3684+
return -EINVAL;
3685+
if (has_eui64 &&
3686+
memcmp(&ids->eui64, &h->ids.eui64, sizeof(ids->eui64)) == 0)
36853687
return -EINVAL;
36863688
}
36873689

0 commit comments

Comments
 (0)