From: Martin Wilck Date: Wed, 29 Apr 2020 17:03:57 +0000 (+0200) Subject: connect-all: add -m/--matching option X-Git-Tag: v1.12~33 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a58556cc3022ec443f0db4a5218d8e2bfb3be481;p=users%2Fhch%2Fnvme-cli.git connect-all: add -m/--matching option 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. --- diff --git a/fabrics.c b/fabrics.c index e73d6ad..b3e717f 100644 --- 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() };