File 0006-fabrics-Consider-config-from-file-when-adding-new-co.patch of Package libnvme.26472

From: Daniel Wagner <dwagner@suse.de>
Date: Thu, 19 May 2022 10:49:40 +0200
Subject: fabrics: Consider config from file when adding new controller
Git-commit: 2e5d70c848e714642bff7af11cb772fa3b819d13
References: bsc#1199503

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 |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -574,10 +574,28 @@ static int __nvmf_add_ctrl(nvme_root_t r
 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;
openSUSE Build Service is sponsored by