nvme: check duplicate unique identifiers in order
PATCH v2 1/1 nvme: check duplicate unique identifiers in order
The identifier check in nvme_subsys_check_duplicate_ids currently returns an error if any of the identifiers match; however, this causes problems with PCI-Express NVMe devices that may otherwise have unique identifiers of higher precedent (for example, a NGUIDs but common EUI64).
Rather than enforcing a policy that requires all identifiers reported by the nvme device to be unique we return success if we find at least one unique identifier. We zero out any non-unque identifier we find before returning, thus preventing non-unque identifiers from being reported in sysfs.
This allows nvme device that return multiple non-unque identifiers to work as long as one or more unique identifier is reported by the device.
--- drivers/nvme/host/core.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
drivers/nvme/host/core.c +27 -10
@@ -3797,18 +3797,35 @@ static int nvme_subsys_check_duplicate_ids(struct nvme_subsystem *subsys,lockdep_assert_held (&subsys->lock); -list_for_each_entry (h, &subsys->nsheads, entry) { -if (has_uuid &&uuid_equal (&ids->uuid, &h->ids.uuid)) -return -EINVAL ; -if (has_nguid && -memcmp (&ids->nguid, &h->ids.nguid,sizeof (ids->nguid)) ==0 ) -return -EINVAL ; -if (has_eui64 && -memcmp (&ids->eui64, &h->ids.eui64,sizeof (ids->eui64)) ==0 ) -return -EINVAL ; +if (has_uuid) { +list_for_each_entry (h, &subsys->nsheads, entry) +if (uuid_equal (&ids->uuid, &h->ids.uuid)) { +memset (&ids->uuid,0 ,sizeof (ids->uuid)); + has_uuid = false; + } } -return 0 ; +if (has_nguid) { +list_for_each_entry (h, &subsys->nsheads, entry) +if (memcmp (&ids->nguid, + &h->ids.nguid, +sizeof (ids->nguid)) ==0 ) { +memset (ids->nguid,0 ,sizeof (ids->nguid)); + has_nguid = false; + } + } + +if (has_eui64) { +list_for_each_entry (h, &subsys->nsheads, entry) +if (memcmp (&ids->eui64, + &h->ids.eui64, +sizeof (ids->eui64)) ==0 ) { +memset (ids->eui64,0 ,sizeof (ids->eui64)); + has_eui64 = false; + } + } + +return (has_uuid || has_nguid || has_eui64) ?0 : -EINVAL ; }static void nvme_cdev_rel (struct device *dev)
Signature · 1 line
2.51.0