]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: allow 'nqn' as argument to connect and discover
authorHannes Reinecke <hare@suse.de>
Tue, 16 Nov 2021 08:46:57 +0000 (09:46 +0100)
committerHannes Reinecke <hare@suse.de>
Wed, 17 Nov 2021 17:38:00 +0000 (18:38 +0100)
With TP8013 a discovery controller can provide a unique subsystem
NQN, so we should be able to pass in that NQN when calling 'nvme discover'.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Documentation/nvme-connect-all.txt
Documentation/nvme-discover.txt
fabrics.c

index e673ede567cc5e3db7b142103cfb5230361a9f04..3d3587ffcb39b85b40ded0276c932e7b708e4edd 100644 (file)
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'nvme connect-all'
                [--transport=<trtype>     | -t <trtype>]
+               [--nqn=<subnqn>           | -n <subnqn>]
                [--traddr=<traddr>        | -a <traddr>]
                [--trsvcid=<trsvcid>      | -s <trsvcid>]
                [--host-traddr=<traddr>   | -w <traddr>]
@@ -65,6 +66,10 @@ OPTIONS
 |loop|Connect to a NVMe over Fabrics target on the local host
 |=================
 
+-n <subnqn>::
+--nqn <subnqn>::
+       This field specifies the name for the NVMe subsystem to connect to.
+
 -a <traddr>::
 --traddr=<traddr>::
        This field specifies the network address of the Discovery Controller.
index cb81a67449df474f4102dcc5528665ebdcdabc09..b7311aa9214ae09427fcfb4899ccdd23e1db6b7f 100644 (file)
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'nvme discover'
                [--transport=<trtype>     | -t <trtype>]
+               [--nqn=<subnqn>           | -n <subnqn>]
                [--traddr=<traddr>        | -a <traddr>]
                [--trsvcid=<trsvcid>      | -s <trsvcid>]
                [--host-traddr=<traddr>   | -w <traddr>]
@@ -87,6 +88,10 @@ OPTIONS
 |loop|Connect to a NVMe over Fabrics target on the local host
 |=================
 
+-n <subnqn>::
+--nqn <subnqn>::
+       This field specifies the name for the NVMe subsystem to connect to.
+
 -a <traddr>::
 --traddr=<traddr>::
        This field specifies the network address of the Discovery Controller.
index 02071c2e2fa542d588e3bb8639d8dabfeef702e7..e947ced53ebc358e54e5618f6a985404127afc80 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -83,6 +83,7 @@ static const char *nvmf_config_file   = "Use specified JSON configuration file or
        OPT_STRING("host-iface",      'f', "STR", &host_iface,  nvmf_hiface), \
        OPT_STRING("hostnqn",         'q', "STR", &hostnqn,     nvmf_hostnqn), \
        OPT_STRING("hostid",          'I', "STR", &hostid,      nvmf_hostid), \
+       OPT_STRING("nqn",             'n', "STR", &subsysnqn,   nvmf_nqn), \
        OPT_INT("nr-io-queues",       'i', &c.nr_io_queues,       nvmf_nr_io_queues),   \
        OPT_INT("nr-write-queues",    'W', &c.nr_write_queues,    nvmf_nr_write_queues),\
        OPT_INT("nr-poll-queues",     'P', &c.nr_poll_queues,     nvmf_nr_poll_queues), \
@@ -302,6 +303,7 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
        char *transport = NULL, *traddr = NULL, *trsvcid = NULL;
        char *host_traddr = NULL, *host_iface = NULL;
        char *hostnqn = NULL, *hostid = NULL;
+       char *subsysnqn = NULL;
        char *ptr, **argv, *p, line[4096];
        int argc, ret = 0;
        unsigned int verbose = 0;
@@ -353,6 +355,7 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
                argv[argc] = NULL;
 
                memcpy(&cfg, defcfg, sizeof(cfg));
+               subsysnqn = NVME_DISC_SUBSYS_NAME;
                ret = argconfig_parse(argc, argv, desc, opts);
                if (ret)
                        goto next;
@@ -361,7 +364,7 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
                if (!transport && !traddr)
                        goto next;
 
-               c = nvme_create_ctrl(NVME_DISC_SUBSYS_NAME, transport,
+               c = nvme_create_ctrl(subsysnqn, transport,
                                     traddr, host_traddr, host_iface, trsvcid);
                if (!c)
                        goto next;
@@ -385,7 +388,7 @@ out:
 
 int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
 {
-       char *nqn = NVME_DISC_SUBSYS_NAME;
+       char *subsysnqn = NVME_DISC_SUBSYS_NAME;
        char *hostnqn = NULL, *hostid = NULL;
        char *host_traddr = NULL, *host_iface = NULL;
        char *transport = NULL, *traddr = NULL, *trsvcid = NULL;
@@ -472,7 +475,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
                c = nvme_scan_ctrl(r, device);
                if (c) {
                        /* Check if device matches command-line options */
-                       if (strcmp(nvme_ctrl_get_subsysnqn(c), nqn) ||
+                       if (strcmp(nvme_ctrl_get_subsysnqn(c), subsysnqn) ||
                            strcmp(nvme_ctrl_get_transport(c), transport) ||
                            strcmp(nvme_ctrl_get_traddr(c), traddr) ||
                            (host_traddr && nvme_ctrl_get_host_traddr(c) &&
@@ -510,7 +513,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
        }
        if (!c) {
                /* No device or non-matching device, create a new controller */
-               c = nvme_create_ctrl(nqn, transport, traddr,
+               c = nvme_create_ctrl(subsysnqn, transport, traddr,
                                     host_traddr, host_iface, trsvcid);
                if (!c) {
                        ret = errno;
@@ -560,7 +563,6 @@ int nvmf_connect(const char *desc, int argc, char **argv)
        struct nvme_fabrics_config cfg;
 
        OPT_ARGS(opts) = {
-               OPT_STRING("nqn", 'n', "NAME", &subsysnqn, nvmf_nqn),
                NVMF_OPTS(cfg),
                OPT_STRING("config", 'C', "FILE", &config_file, nvmf_config_file),
                OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),