]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: fix fc config JSON file handling
authorMartin George <marting@netapp.com>
Tue, 4 Apr 2023 09:29:09 +0000 (14:59 +0530)
committerDaniel Wagner <wagi@monom.org>
Wed, 5 Apr 2023 10:17:52 +0000 (12:17 +0200)
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 <marting@netapp.com>
fabrics.c

index 087a56ce4e1eed3fa9df76f97ded8a934d6485a1..f8078e597087bd2f53469739a0a6c62c9904fb77 100644 (file)
--- 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,
                        };