]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
connect-all: add -m/--matching option
authorMartin Wilck <mwilck@suse.com>
Wed, 29 Apr 2020 17:03:57 +0000 (19:03 +0200)
committerKeith Busch <kbusch@kernel.org>
Thu, 30 Apr 2020 18:13:30 +0000 (12:13 -0600)
Discovery controllers often return discovery records that belong
to a different traddr than the discovery controller itself, like here:

nvme discover -t fc \
   --host-traddr=nn-0x20000090fae06325:pn-0x10000090fae06325 \
   --traddr=nn-0x200900a09890f5bf:pn-0x200a00a09890f5bf

Discovery Log Number of Records 2, Generation counter 25
=====Discovery Log Entry 0======
trtype:  fc
adrfam:  fibre-channel
subtype: nvme subsystem
treq:    not specified
portid:  0
trsvcid: none
subnqn:  nqn...
traddr:  nn-0x200900a09890f5bf:pn-0x200b00a09890f5bf
=====Discovery Log Entry 1======
trtype:  fc
adrfam:  fibre-channel
subtype: nvme subsystem
treq:    not specified
portid:  1
trsvcid: none
subnqn:  nqn...
traddr:  nn-0x200900a09890f5bf:pn-0x200a00a09890f5bf

Note that the traddr of record 0 matches the traddr used for the
discovery, while that of record 1 does not.

For NVMeoF-autoconnect, this means that connection attempts will
be made multiple times (the two records above will also be returned
for a discovery on nn-0x200900a09890f5bf:pn-0x200b00a09890f5bf),
which is unnecessary and leads to lots of confusing error messages
in the system log.

Add an option "-m / --matching" to the "nvme connect-all" command
that causes nvme to connect only those discovery entries that match
the traddr given on the command line.

fabrics.c

index e73d6ad18a2e1f373a10437c8e6b9886983af651..b3e717fedad1bf8c37605555874ba7ee6eccddb8 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -84,6 +84,7 @@ static struct config {
        int  data_digest;
        bool persistent;
        bool quiet;
+       bool matching_only;
 } cfg = { NULL };
 
 struct connect_args {
@@ -1103,6 +1104,17 @@ retry:
        return ret;
 }
 
+static bool should_connect(struct nvmf_disc_rsp_page_entry *entry)
+{
+       int len;
+
+       if (!cfg.matching_only || !cfg.traddr)
+               return true;
+
+       len = space_strip_len(NVMF_TRADDR_SIZE, entry->traddr);
+       return !strncmp(cfg.traddr, entry->traddr, len);
+}
+
 static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec)
 {
        int i;
@@ -1110,6 +1122,9 @@ static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec)
        int ret = 0;
 
        for (i = 0; i < numrec; i++) {
+               if (!should_connect(&log->entries[i]))
+                       continue;
+
                instance = connect_ctrl(&log->entries[i]);
 
                /* clean success */
@@ -1343,6 +1358,7 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect)
                OPT_INT("queue-size",      'Q', &cfg.queue_size,      "number of io queue elements to use (default 128)"),
                OPT_FLAG("persistent",     'p', &cfg.persistent,      "persistent discovery connection"),
                OPT_FLAG("quiet",          'S', &cfg.quiet,           "suppress already connected errors"),
+               OPT_FLAG("matching",       'm', &cfg.matching_only,   "connect only records matching the traddr"),
                OPT_END()
        };