From 89008c03a4b491d01b9dbcc9305020a514d6a5f7 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 11 Jul 2024 10:49:23 +0200 Subject: [PATCH] fabrics: first read config before topology scanning 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 --- fabrics.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fabrics.c b/fabrics.c index 7cf59486..d42bdc19 100644 --- 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; -- 2.50.1