Commit 2079f41e authored by Christoph Hellwig's avatar Christoph Hellwig

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
parent e2d77d2e
...@@ -3810,12 +3810,45 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, ...@@ -3810,12 +3810,45 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static int nvme_global_check_duplicate_ids(struct nvme_subsystem *this,
struct nvme_ns_ids *ids)
{
struct nvme_subsystem *s;
int ret = 0;
/*
* Note that this check is racy as we try to avoid holding the global
* lock over the whole ns_head creation. But it is only intended as
* a sanity check anyway.
*/
mutex_lock(&nvme_subsystems_lock);
list_for_each_entry(s, &nvme_subsystems, entry) {
if (s == this)
continue;
mutex_lock(&s->lock);
ret = nvme_subsys_check_duplicate_ids(s, ids);
mutex_unlock(&s->lock);
if (ret)
break;
}
mutex_unlock(&nvme_subsystems_lock);
return ret;
}
static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
struct nvme_ns_ids *ids, bool is_shared) struct nvme_ns_ids *ids, bool is_shared)
{ {
struct nvme_ctrl *ctrl = ns->ctrl; struct nvme_ctrl *ctrl = ns->ctrl;
struct nvme_ns_head *head = NULL; struct nvme_ns_head *head = NULL;
int ret = 0; int ret;
ret = nvme_global_check_duplicate_ids(ctrl->subsys, ids);
if (ret) {
dev_err(ctrl->device,
"globally duplicate IDs for nsid %d\n", nsid);
return ret;
}
mutex_lock(&ctrl->subsys->lock); mutex_lock(&ctrl->subsys->lock);
head = nvme_find_ns_head(ctrl->subsys, nsid); head = nvme_find_ns_head(ctrl->subsys, nsid);
...@@ -3823,7 +3856,8 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, ...@@ -3823,7 +3856,8 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, ids); ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, ids);
if (ret) { if (ret) {
dev_err(ctrl->device, dev_err(ctrl->device,
"duplicate IDs for nsid %d\n", nsid); "duplicate IDs in subsystem for nsid %d\n",
nsid);
goto out_unlock; goto out_unlock;
} }
head = nvme_alloc_ns_head(ctrl, nsid, ids); head = nvme_alloc_ns_head(ctrl, nsid, ids);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment