From 1b042ebe12ca598436f17365fe3ddc0a9f837060 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 3 Jul 2023 11:17:48 +0200 Subject: [PATCH] fabrics: Consider also all hosts settings for context match It's not enough to iterate over all subsystem of one host. We need to iterate over all hosts as well to find a match. Signed-off-by: Daniel Wagner --- src/nvme/fabrics.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index f0a06e8a..800293e2 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -818,6 +818,27 @@ out_close: return ret; } +static const char *lookup_context(nvme_root_t r, nvme_ctrl_t c) +{ + + nvme_host_t h; + nvme_subsystem_t s; + + nvme_for_each_host(r, h) { + nvme_for_each_subsystem(h, s) { + if (__nvme_lookup_ctrl(s, nvme_ctrl_get_transport(c), + nvme_ctrl_get_traddr(c), + NULL, + NULL, + nvme_ctrl_get_trsvcid(c), + NULL)) + return nvme_subsystem_get_application(s); + } + } + + return NULL; +} + int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, const struct nvme_fabrics_config *cfg) { @@ -862,24 +883,9 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, root_app = nvme_root_get_application(h->r); if (root_app) { app = nvme_subsystem_get_application(s); - if (!app && nvme_ctrl_is_discovery_ctrl(c)) { - nvme_subsystem_t s; - nvme_ctrl_t fc; - - nvme_for_each_subsystem(h, s) { - fc = __nvme_lookup_ctrl(s, nvme_ctrl_get_transport(c), - nvme_ctrl_get_traddr(c), - NULL, - NULL, - nvme_ctrl_get_trsvcid(c), - NULL); - - if (fc) { - app = nvme_subsystem_get_application(s); - break; - } - } - } + if (!app && nvme_ctrl_is_discovery_ctrl(c)) + app = lookup_context(h->r, c); + /* * configuration is managed by an application, * refuse to act on subsystems which either have -- 2.51.0