From 547f4b752c49b144304b1e33d63d9325e02ca50a Mon Sep 17 00:00:00 2001 From: Sagi Grimberg Date: Thu, 1 Aug 2019 16:13:47 -0700 Subject: [PATCH] nvme-cli: add --quiet option Now we are going to have discovery log change events, so instead of trying to figure out which NVM subsystem ports are already connected, we let the driver do that and only suppress the failure messages. Example: nvme connect-all ... --quiet This option will be used by the discovery log change corresponding udev rule. Signed-off-by: Sagi Grimberg Reviewed-by: James Smart Reviewed-by: Hannes Reinecke Reviewed-by: Minwoo Im --- fabrics.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fabrics.c b/fabrics.c index f1a5ad2e..333669f8 100644 --- a/fabrics.c +++ b/fabrics.c @@ -67,6 +67,7 @@ static struct config { int hdr_digest; int data_digest; bool persistent; + bool quiet; } cfg = { NULL }; #define BUF_SIZE 4096 @@ -218,9 +219,11 @@ static int add_ctrl(const char *argstr) goto out; } - if (write(fd, argstr, len) != len) { - fprintf(stderr, "Failed to write to %s: %s\n", - PATH_NVME_FABRICS, strerror(errno)); + ret = write(fd, argstr, len); + if (ret != len) { + if (errno != EALREADY || !cfg.quiet) + fprintf(stderr, "Failed to write to %s: %s\n", + PATH_NVME_FABRICS, strerror(errno)); ret = -errno; goto out_close; } @@ -858,10 +861,13 @@ static int connect_ctrls(struct nvmf_disc_rsp_page_hdr *log, int numrec) /* already connected print message */ if (instance == -EALREADY) { const char *traddr = log->entries[i].traddr; - fprintf(stderr, - "traddr=%.*s is already connected\n", - space_strip_len(NVMF_TRADDR_SIZE, traddr), - traddr); + + if (!cfg.quiet) + fprintf(stderr, + "traddr=%.*s is already connected\n", + space_strip_len(NVMF_TRADDR_SIZE, + traddr), + traddr); continue; } @@ -1066,6 +1072,7 @@ int discover(const char *desc, int argc, char **argv, bool connect) {"nr-poll-queues", 'P', "LIST", CFG_INT, &cfg.nr_poll_queues, required_argument, "number of poll queues to use (default 0)" }, {"queue-size", 'Q', "LIST", CFG_INT, &cfg.queue_size, required_argument, "number of io queue elements to use (default 128)" }, {"persistent", 'p', "LIST", CFG_NONE, &cfg.persistent, no_argument, "persistent discovery connection" }, + {"quiet", 'Q', "LIST", CFG_NONE, &cfg.quiet, no_argument, "suppress already connected errors" }, {NULL}, }; -- 2.50.1