aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/nvme/host/core.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index d2d8e6088c46..d7de0642c832 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2341,20 +2341,35 @@ static const struct attribute_group *nvme_subsys_attrs_groups[] = {
2341 NULL, 2341 NULL,
2342}; 2342};
2343 2343
2344static int nvme_active_ctrls(struct nvme_subsystem *subsys) 2344static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
2345 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
2345{ 2346{
2346 int count = 0; 2347 struct nvme_ctrl *tmp;
2347 struct nvme_ctrl *ctrl;
2348 2348
2349 lockdep_assert_held(&nvme_subsystems_lock); 2349 lockdep_assert_held(&nvme_subsystems_lock);
2350 2350
2351 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { 2351 list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
2352 if (ctrl->state != NVME_CTRL_DELETING && 2352 if (ctrl->state == NVME_CTRL_DELETING ||
2353 ctrl->state != NVME_CTRL_DEAD) 2353 ctrl->state == NVME_CTRL_DEAD)
2354 count++; 2354 continue;
2355
2356 if (tmp->cntlid == ctrl->cntlid) {
2357 dev_err(ctrl->device,
2358 "Duplicate cntlid %u with %s, rejecting\n",
2359 ctrl->cntlid, dev_name(tmp->device));
2360 return false;
2361 }
2362
2363 if ((id->cmic & (1 << 1)) ||
2364 (ctrl->opts && ctrl->opts->discovery_nqn))
2365 continue;
2366
2367 dev_err(ctrl->device,
2368 "Subsystem does not support multiple controllers\n");
2369 return false;
2355 } 2370 }
2356 2371
2357 return count; 2372 return true;
2358} 2373}
2359 2374
2360static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) 2375static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
@@ -2397,15 +2412,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
2397 __nvme_release_subsystem(subsys); 2412 __nvme_release_subsystem(subsys);
2398 subsys = found; 2413 subsys = found;
2399 2414
2400 /* 2415 if (!nvme_validate_cntlid(subsys, ctrl, id)) {
2401 * Verify that the subsystem actually supports multiple
2402 * controllers, else bail out.
2403 */
2404 if (!(ctrl->opts && ctrl->opts->discovery_nqn) &&
2405 nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) {
2406 dev_err(ctrl->device,
2407 "ignoring ctrl due to duplicate subnqn (%s).\n",
2408 subsys->subnqn);
2409 ret = -EINVAL; 2416 ret = -EINVAL;
2410 goto out_put_subsystem; 2417 goto out_put_subsystem;
2411 } 2418 }