Skip to content

Commit 6961b5e

Browse files
israelruChristoph Hellwig
authored andcommitted
nvme: fix block device naming collision
The issue exists when multipath is enabled and the namespace is shared, but all the other controller checks at nvme_is_unique_nsid() are false. The reason for this issue is that nvme_is_unique_nsid() returns false when is called from nvme_mpath_alloc_disk() due to an uninitialized value of head->shared. The patch fixes it by setting head->shared before nvme_mpath_alloc_disk() is called. Fixes: 5974ea7 ("nvme: allow duplicate NSIDs for private namespaces") Signed-off-by: Israel Rukshin <israelr@nvidia.com> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 081f5e7 commit 6961b5e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/nvme/host/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,7 @@ static int nvme_add_ns_cdev(struct nvme_ns *ns)
37863786
}
37873787

37883788
static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
3789-
unsigned nsid, struct nvme_ns_ids *ids)
3789+
unsigned nsid, struct nvme_ns_ids *ids, bool is_shared)
37903790
{
37913791
struct nvme_ns_head *head;
37923792
size_t size = sizeof(*head);
@@ -3810,6 +3810,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
38103810
head->subsys = ctrl->subsys;
38113811
head->ns_id = nsid;
38123812
head->ids = *ids;
3813+
head->shared = is_shared;
38133814
kref_init(&head->ref);
38143815

38153816
if (head->ids.csi) {
@@ -3891,12 +3892,11 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
38913892
nsid);
38923893
goto out_unlock;
38933894
}
3894-
head = nvme_alloc_ns_head(ctrl, nsid, ids);
3895+
head = nvme_alloc_ns_head(ctrl, nsid, ids, is_shared);
38953896
if (IS_ERR(head)) {
38963897
ret = PTR_ERR(head);
38973898
goto out_unlock;
38983899
}
3899-
head->shared = is_shared;
39003900
} else {
39013901
ret = -EINVAL;
39023902
if (!is_shared || !head->shared) {

0 commit comments

Comments
 (0)