]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: first read config before topology scanning
authorDaniel Wagner <dwagner@suse.de>
Thu, 11 Jul 2024 08:49:23 +0000 (10:49 +0200)
committerDaniel Wagner <wagi@monom.org>
Fri, 12 Jul 2024 08:24:32 +0000 (10:24 +0200)
The topology scanning will create nodes in the internal libnvme tree. As
we rely on the order of the nodes in the tree, we need to read the
config before we scan. This makes sure the first node is the one we have
defined in the config.json. This is important because the first node
provides default hosnqn configuration in absents of /etc/nvme/hostnqn.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
fabrics.c

index 7cf594865bde2f2e55d4a685ace5cfaf4f2b872f..d42bdc19d28bc984953d3a6281d001b4c14adfd6 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -690,6 +690,12 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
        }
        if (context)
                nvme_root_set_application(r, context);
+
+       if (!nvme_read_config(r, config_file))
+               json_config = true;
+       if (!nvme_read_volatile_config(r))
+               json_config = true;
+
        nvme_root_skip_namespaces(r);
        ret = nvme_scan_topology(r, NULL, NULL);
        if (ret < 0) {
@@ -699,11 +705,6 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
                return ret;
        }
 
-       if (!nvme_read_config(r, config_file))
-               json_config = true;
-       if (!nvme_read_volatile_config(r))
-               json_config = true;
-
        ret = nvme_host_get_ids(r, hostnqn, hostid, &hnqn, &hid);
        if (ret < 0)
                return -errno;
@@ -911,6 +912,10 @@ int nvmf_connect(const char *desc, int argc, char **argv)
        }
        if (context)
                nvme_root_set_application(r, context);
+
+       nvme_read_config(r, config_file);
+       nvme_read_volatile_config(r);
+
        nvme_root_skip_namespaces(r);
        ret = nvme_scan_topology(r, NULL, NULL);
        if (ret < 0) {
@@ -919,8 +924,6 @@ int nvmf_connect(const char *desc, int argc, char **argv)
                                nvme_strerror(errno));
                return ret;
        }
-       nvme_read_config(r, config_file);
-       nvme_read_volatile_config(r);
 
        ret = nvme_host_get_ids(r, hostnqn, hostid, &hnqn, &hid);
        if (ret < 0)
@@ -1206,6 +1209,9 @@ int nvmf_config(const char *desc, int argc, char **argv)
                        nvme_strerror(errno));
                return -errno;
        }
+
+       nvme_read_config(r, config_file);
+
        if (scan_tree) {
                nvme_root_skip_namespaces(r);
                ret = nvme_scan_topology(r, NULL, NULL);
@@ -1217,7 +1223,6 @@ int nvmf_config(const char *desc, int argc, char **argv)
                        return ret;
                }
        }
-       nvme_read_config(r, config_file);
 
        if (modify_config) {
                nvme_host_t h;