From: Martin Belanger Date: Wed, 2 Aug 2023 13:38:56 +0000 (-0400) Subject: fabrics: lookup_discovery_ctrl() must look under host and not root X-Git-Tag: v2.6~36 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=0ba431273e8a0adca558bccc63fd6e0ffd6b8bfe;p=users%2Fsagi%2Fnvme-cli.git fabrics: lookup_discovery_ctrl() must look under host and not root 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 --- diff --git a/fabrics.c b/fabrics.c index 40aef693..7fde9ba8 100644 --- 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; }