From f113d31427d1984f993d2ac3e5ba9713473ebe4a Mon Sep 17 00:00:00 2001 From: Ameer Hamza Date: Tue, 21 May 2024 18:55:48 +0500 Subject: [PATCH] nvme: acquire a new subsystem if no valid controllers assigned --- drivers/nvme/host/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8ec72aa7b58f..f554170bf10c 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2704,6 +2704,8 @@ static void nvme_put_subsystem(struct nvme_subsystem *subsys) static struct nvme_subsystem *__nvme_find_get_subsystem(const char *subsysnqn) { struct nvme_subsystem *subsys; + struct nvme_ctrl *ctrl; + bool active_ctrls = false; lockdep_assert_held(&nvme_subsystems_lock); @@ -2721,6 +2723,16 @@ static struct nvme_subsystem *__nvme_find_get_subsystem(const char *subsysnqn) list_for_each_entry(subsys, &nvme_subsystems, entry) { if (strcmp(subsys->subnqn, subsysnqn)) continue; + if (!list_empty(&subsys->ctrls)) { + list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { + if (!nvme_state_terminal(ctrl)) { + active_ctrls = true; + break; + } + } + } + if (!active_ctrls) + continue; if (!kref_get_unless_zero(&subsys->ref)) continue; return subsys;