Skip to content

Commit 32fd90c

Browse files
author
Christoph Hellwig
committed
nvme: change locking for the per-subsystem controller list
Life becomes a lot simpler if we just use the global nvme_subsystems_lock to protect this list. Given that it is only accessed during controller probing and removal that isn't a scalability problem either. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]>
1 parent 521cfb8 commit 32fd90c

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

drivers/nvme/host/core.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,13 +2346,13 @@ static int nvme_active_ctrls(struct nvme_subsystem *subsys)
23462346
int count = 0;
23472347
struct nvme_ctrl *ctrl;
23482348

2349-
mutex_lock(&subsys->lock);
2349+
lockdep_assert_held(&nvme_subsystems_lock);
2350+
23502351
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
23512352
if (ctrl->state != NVME_CTRL_DELETING &&
23522353
ctrl->state != NVME_CTRL_DEAD)
23532354
count++;
23542355
}
2355-
mutex_unlock(&subsys->lock);
23562356

23572357
return count;
23582358
}
@@ -2394,6 +2394,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
23942394
mutex_lock(&nvme_subsystems_lock);
23952395
found = __nvme_find_get_subsystem(subsys->subnqn);
23962396
if (found) {
2397+
__nvme_release_subsystem(subsys);
2398+
subsys = found;
2399+
23972400
/*
23982401
* Verify that the subsystem actually supports multiple
23992402
* controllers, else bail out.
@@ -2402,14 +2405,10 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
24022405
nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
24032406
dev_err(ctrl->device,
24042407
"ignoring ctrl due to duplicate subnqn (%s).\n",
2405-
found->subnqn);
2406-
nvme_put_subsystem(found);
2408+
subsys->subnqn);
24072409
ret = -EINVAL;
2408-
goto out_unlock;
2410+
goto out_put_subsystem;
24092411
}
2410-
2411-
__nvme_release_subsystem(subsys);
2412-
subsys = found;
24132412
} else {
24142413
ret = device_add(&subsys->dev);
24152414
if (ret) {
@@ -2421,23 +2420,20 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
24212420
list_add_tail(&subsys->entry, &nvme_subsystems);
24222421
}
24232422

2424-
ctrl->subsys = subsys;
2425-
mutex_unlock(&nvme_subsystems_lock);
2426-
24272423
if (sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj,
24282424
dev_name(ctrl->device))) {
24292425
dev_err(ctrl->device,
24302426
"failed to create sysfs link from subsystem.\n");
2431-
/* the transport driver will eventually put the subsystem */
2432-
return -EINVAL;
2427+
goto out_put_subsystem;
24332428
}
24342429

2435-
mutex_lock(&subsys->lock);
2430+
ctrl->subsys = subsys;
24362431
list_add_tail(&ctrl->subsys_entry, &subsys->ctrls);
2437-
mutex_unlock(&subsys->lock);
2438-
2432+
mutex_unlock(&nvme_subsystems_lock);
24392433
return 0;
24402434

2435+
out_put_subsystem:
2436+
nvme_put_subsystem(subsys);
24412437
out_unlock:
24422438
mutex_unlock(&nvme_subsystems_lock);
24432439
put_device(&subsys->dev);
@@ -3694,10 +3690,10 @@ static void nvme_free_ctrl(struct device *dev)
36943690
__free_page(ctrl->discard_page);
36953691

36963692
if (subsys) {
3697-
mutex_lock(&subsys->lock);
3693+
mutex_lock(&nvme_subsystems_lock);
36983694
list_del(&ctrl->subsys_entry);
3699-
mutex_unlock(&subsys->lock);
37003695
sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device));
3696+
mutex_unlock(&nvme_subsystems_lock);
37013697
}
37023698

37033699
ctrl->ops->free_ctrl(ctrl);

0 commit comments

Comments
 (0)