From: Martin George Date: Tue, 4 Apr 2023 09:29:09 +0000 (+0530) Subject: fabrics: fix fc config JSON file handling X-Git-Tag: v2.5~191 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3ea32db40c6c3ca278c09b5c8623268fafbb8052;p=users%2Fsagi%2Fnvme-cli.git fabrics: fix fc config JSON file handling Unlike other nvme transports, nvme/fc connection requires a valid host_traddr in addition to traddr and transport type. Current fc config JSON handling is broken due to the host_traddr not getting updated even if explicitly listed in the JSON file, as shown below: nvme connect-all -J /usr/local/etc/nvme/config.json Failed to write to /dev/nvme-fabrics: Invalid argument And the below error is logged in the messages file for the same: nvme_fabrics: missing parameter 'host_traddr=%s' Fix this by ensuring the relevant host_traddr string is appropriately passed to the respective nvme controller structure. And while we are at it, ensure the host_iface string is updated too but noting that it is only applicable to tcp alone, and not rdma or fc. Signed-off-by: Martin George --- diff --git a/fabrics.c b/fabrics.c index 087a56ce..f8078e59 100644 --- a/fabrics.c +++ b/fabrics.c @@ -630,7 +630,7 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h, enum nvme_print_flags flags, bool force) { - const char *transport, *traddr, *trsvcid, *subsysnqn; + const char *transport, *traddr, *host_traddr, *host_iface, *trsvcid, *subsysnqn; nvme_subsystem_t s; nvme_ctrl_t c, cn; struct nvme_fabrics_config cfg; @@ -640,6 +640,8 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h, nvme_subsystem_for_each_ctrl(s, c) { transport = nvme_ctrl_get_transport(c); traddr = nvme_ctrl_get_traddr(c); + host_traddr = nvme_ctrl_get_host_traddr(c); + host_iface = nvme_ctrl_get_host_iface(c); if (!transport && !traddr) continue; @@ -650,6 +652,22 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h, strcmp(transport, "fc")) continue; + /* ignore if no host_traddr for fc */ + if (!strcmp(transport, "fc")) { + if (!host_traddr) { + fprintf(stderr, "host_traddr required for fc\n"); + continue; + } + } + + /* ignore if host_iface set for any transport other than tcp */ + if (!strcmp(transport, "rdma") || !strcmp(transport, "fc")) { + if (host_iface) { + fprintf(stderr, "host_iface not permitted for rdma or fc\n"); + continue; + } + } + trsvcid = nvme_ctrl_get_trsvcid(c); if (!trsvcid || !strcmp(trsvcid, "")) trsvcid = get_default_trsvcid(transport, true); @@ -668,8 +686,8 @@ static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h, .subsysnqn = subsysnqn, .transport = transport, .traddr = traddr, - .host_traddr = cfg.host_traddr, - .host_iface = cfg.host_iface, + .host_traddr = host_traddr, + .host_iface = host_iface, .trsvcid = trsvcid, };