]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add '--groups' option to nvme ana-log
authorHannes Reinecke <hare@suse.de>
Fri, 22 Apr 2022 11:22:39 +0000 (13:22 +0200)
committerHannes Reinecke <hare@suse.de>
Fri, 22 Apr 2022 11:22:39 +0000 (13:22 +0200)
Coverity complained that the 'groups' variable was never changed,
so implement a '--groups' option to 'nvme ana-log'.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Documentation/nvme-ana-log.txt
nvme.c

index fdd412ee79b825907e80883ba6f2e73afc0f918c..b6dc9c5861aaf1a50084d22ae880a46efca75af9 100644 (file)
@@ -24,6 +24,10 @@ printed to stdout for another program to parse.
 
 OPTIONS
 -------
+-g::
+--groups::
+              Return the list of ANA groups without the namespace listing.
+
 -o <format>::
 --output-format=<format>::
               Set the reporting format to 'normal', 'json', or
diff --git a/nvme.c b/nvme.c
index cfee960c0be07d01597a6c820b3bdcc3b50cc6c2..07102738df58d8137ac6a75bae8df4374d98024b 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -369,23 +369,26 @@ static int get_ana_log(int argc, char **argv, struct command *cmd,
 {
        const char *desc = "Retrieve ANA log for the given device in " \
                            "decoded format (default), json or binary.";
+       const char *groups = "Return ANA groups only.";
        void *ana_log;
        int err = -1, fd;
-       int groups = 0; /* Right now get all the per ANA group NSIDS */
        size_t ana_log_len;
        struct nvme_id_ctrl ctrl;
        enum nvme_print_flags flags;
        enum nvme_log_ana_lsp lsp;
 
        struct config {
+               bool    groups;
                char    *output_format;
        };
 
        struct config cfg = {
+               .groups = false,
                .output_format = "normal",
        };
 
        OPT_ARGS(opts) = {
+               OPT_FLAG("groups", 'g', &cfg.groups, groups),
                OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
                OPT_END()
        };
@@ -416,8 +419,8 @@ static int get_ana_log(int argc, char **argv, struct command *cmd,
                goto close_fd;
        }
 
-       lsp = groups ? NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY :
-                       NVME_LOG_ANA_LSP_RGO_NAMESPACES;
+       lsp = cfg.groups ? NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY :
+               NVME_LOG_ANA_LSP_RGO_NAMESPACES;
 
        err = nvme_get_log_ana(fd, lsp, true, 0, ana_log_len, ana_log);
        if (!err) {