Skip to content

Commit 2079f41

Browse files
author
Christoph Hellwig
committed
nvme: check that EUI/GUID/UUID are globally unique
Add a check to verify that the unique identifiers are unique globally in addition to the existing check that verifies that they are unique inside a single subsystem. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]>
1 parent e2d77d2 commit 2079f41

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3810,20 +3810,54 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
38103810
return ERR_PTR(ret);
38113811
}
38123812

3813+
static int nvme_global_check_duplicate_ids(struct nvme_subsystem *this,
3814+
struct nvme_ns_ids *ids)
3815+
{
3816+
struct nvme_subsystem *s;
3817+
int ret = 0;
3818+
3819+
/*
3820+
* Note that this check is racy as we try to avoid holding the global
3821+
* lock over the whole ns_head creation. But it is only intended as
3822+
* a sanity check anyway.
3823+
*/
3824+
mutex_lock(&nvme_subsystems_lock);
3825+
list_for_each_entry(s, &nvme_subsystems, entry) {
3826+
if (s == this)
3827+
continue;
3828+
mutex_lock(&s->lock);
3829+
ret = nvme_subsys_check_duplicate_ids(s, ids);
3830+
mutex_unlock(&s->lock);
3831+
if (ret)
3832+
break;
3833+
}
3834+
mutex_unlock(&nvme_subsystems_lock);
3835+
3836+
return ret;
3837+
}
3838+
38133839
static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
38143840
struct nvme_ns_ids *ids, bool is_shared)
38153841
{
38163842
struct nvme_ctrl *ctrl = ns->ctrl;
38173843
struct nvme_ns_head *head = NULL;
3818-
int ret = 0;
3844+
int ret;
3845+
3846+
ret = nvme_global_check_duplicate_ids(ctrl->subsys, ids);
3847+
if (ret) {
3848+
dev_err(ctrl->device,
3849+
"globally duplicate IDs for nsid %d\n", nsid);
3850+
return ret;
3851+
}
38193852

38203853
mutex_lock(&ctrl->subsys->lock);
38213854
head = nvme_find_ns_head(ctrl->subsys, nsid);
38223855
if (!head) {
38233856
ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, ids);
38243857
if (ret) {
38253858
dev_err(ctrl->device,
3826-
"duplicate IDs for nsid %d\n", nsid);
3859+
"duplicate IDs in subsystem for nsid %d\n",
3860+
nsid);
38273861
goto out_unlock;
38283862
}
38293863
head = nvme_alloc_ns_head(ctrl, nsid, ids);

0 commit comments

Comments
 (0)