]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-cli: add --quiet option
authorSagi Grimberg <sagi@grimberg.me>
Thu, 1 Aug 2019 23:13:47 +0000 (16:13 -0700)
committerKeith Busch <kbusch@kernel.org>
Fri, 2 Aug 2019 15:43:09 +0000 (09:43 -0600)
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 <sagi@grimberg.me>
Reviewed-by: James Smart <jsmart2021@gmail.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
fabrics.c

index f1a5ad2efe67e86ce90dd745ebb6ccdf4f3dea20..333669f84846792222197d1c65c930d1e4e4d51a 100644 (file)
--- 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},
        };