]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: lookup_discovery_ctrl() must look under host and not root
authorMartin Belanger <martin.belanger@dell.com>
Wed, 2 Aug 2023 13:38:56 +0000 (09:38 -0400)
committerDaniel Wagner <wagi@monom.org>
Thu, 7 Sep 2023 16:11:32 +0000 (18:11 +0200)
lookup_discovery_ctrl() was scanning the whole root looking for any
matching discovery controller (DC). Instead, it must look under the
host object. The problem happens when there are more than one Host
NQN used to connect to the same DC. In this case, we will have more
than 1 host object and it is important to search for existing DCs
under the right host object.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
fabrics.c

index 40aef693206007c287253670f8e3cec59f172a44..7fde9ba870a9a4c1c07e9ec88ec113f0e552c6fb 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -193,24 +193,9 @@ static nvme_ctrl_t __lookup_host_ctrl(nvme_host_t h, struct tr_config *trcfg,
        return NULL;
 }
 
-static nvme_ctrl_t __lookup_ctrl(nvme_root_t r, struct tr_config *trcfg,
-                                ctrl_match_fn_t filter)
+static nvme_ctrl_t lookup_discovery_ctrl(nvme_host_t h, struct tr_config *trcfg)
 {
-       nvme_host_t h;
-       nvme_ctrl_t c;
-
-       nvme_for_each_host(r, h) {
-               c = __lookup_host_ctrl(h, trcfg, filter);
-               if (c)
-                       return c;
-       }
-
-       return NULL;
-}
-
-static nvme_ctrl_t lookup_discovery_ctrl(nvme_root_t r, struct tr_config *trcfg)
-{
-       return __lookup_ctrl(r, trcfg, disc_ctrl_config_match);
+       return __lookup_host_ctrl(h, trcfg, disc_ctrl_config_match);
 }
 
 nvme_ctrl_t lookup_ctrl(nvme_host_t h, struct tr_config *trcfg)
@@ -539,7 +524,7 @@ static int discover_from_conf_file(nvme_root_t r, nvme_host_t h,
                };
 
                if (!force) {
-                       c = lookup_discovery_ctrl(r, &trcfg);
+                       c = lookup_discovery_ctrl(h, &trcfg);
                        if (c) {
                                __discover(c, &cfg, raw, connect,
                                           true, flags);
@@ -633,7 +618,7 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h,
                        };
 
                        if (!force) {
-                               cn = lookup_discovery_ctrl(r, &trcfg);
+                               cn = lookup_discovery_ctrl(h, &trcfg);
                                if (cn) {
                                        __discover(cn, &cfg, raw, connect,
                                                   true, flags);
@@ -907,7 +892,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
                }
        }
        if (!c && !force) {
-               c = lookup_discovery_ctrl(r, &trcfg);
+               c = lookup_discovery_ctrl(h, &trcfg);
                if (c)
                        persistent = true;
        }