]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fabrics: Consider also all hosts settings for context match
authorDaniel Wagner <dwagner@suse.de>
Mon, 3 Jul 2023 09:17:48 +0000 (11:17 +0200)
committerDaniel Wagner <wagi@monom.org>
Thu, 20 Jul 2023 09:01:41 +0000 (11:01 +0200)
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 <dwagner@suse.de>
src/nvme/fabrics.c

index f0a06e8aacea84e236c069ba5acf97de8bd90e0d..800293e2a8e7750856119d2b2e12fe4fe3de3bad 100644 (file)
@@ -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