]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fabrics: Consider config from file when adding new controller
authorDaniel Wagner <dwagner@suse.de>
Thu, 19 May 2022 08:49:40 +0000 (10:49 +0200)
committerDaniel Wagner <dwagner@suse.de>
Thu, 19 May 2022 09:06:59 +0000 (11:06 +0200)
nvme_read_config() function is attaching the configuration
to tree. But when we create a new controller via nvme_create_ctrl()
and then call nvmf_add_ctrl() we ignore this previously read
in configuration.

Hence lookup if there exist a controller/config and merge into
the fabrics config.

Note, the order of the merge is important. For example we want
the config from the command line to have higher priority
than the one from the config file.

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

index 90ec04db07f5e28bd443187f08bae74f7b9cd740..62059f91c64881c9dc6226549bd35bcf050d38e7 100644 (file)
@@ -559,10 +559,28 @@ out_close:
 int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
                  const struct nvme_fabrics_config *cfg)
 {
+       nvme_subsystem_t s;
        char *argstr;
        int ret;
 
+       /* highest prio have configs from command line */
        cfg = merge_config(c, cfg);
+
+       /* apply configuration from config file (JSON) */
+       s = nvme_lookup_subsystem(h, NULL, nvme_ctrl_get_subsysnqn(c));
+       if (s) {
+               nvme_ctrl_t fc;
+
+               fc = __nvme_lookup_ctrl(s, nvme_ctrl_get_transport(c),
+                                       nvme_ctrl_get_traddr(c),
+                                       nvme_ctrl_get_host_traddr(c),
+                                       nvme_ctrl_get_host_iface(c),
+                                       nvme_ctrl_get_trsvcid(c),
+                                       NULL);
+               if (fc)
+                       cfg = merge_config(c, nvme_ctrl_get_config(fc));
+       }
+
        nvme_ctrl_set_discovered(c, true);
        if (traddr_is_hostname(h->r, c)) {
                char *traddr = c->traddr;