]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add option 'dump-config' to 'connect' and 'discover'
authorHannes Reinecke <hare@suse.de>
Mon, 15 Nov 2021 11:11:57 +0000 (12:11 +0100)
committerHannes Reinecke <hare@suse.de>
Wed, 17 Nov 2021 14:30:35 +0000 (15:30 +0100)
Add an option 'dump-config' to 'nvme connect' and 'nvme discover'
to print out the resulting JSON configuration to stdout.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Documentation/nvme-connect-all.txt
Documentation/nvme-connect.txt
Documentation/nvme-discover.txt
fabrics.c

index 1cb7822b4f5e15fd9543edb89149f2c0c180f31e..1fff8301d82e440f63c9bde4edf5e21bcf9e1335 100644 (file)
@@ -29,6 +29,7 @@ SYNOPSIS
                [--matching               | -m]
                [--persistent             | -p]
                [--quiet                  | -S]
+               [--dump-config            | -O]
 
 DESCRIPTION
 -----------
@@ -166,6 +167,10 @@ OPTIONS
 --quiet::
        Suppress error messages.
 
+-O::
+--dump-config::
+       Print out resulting JSON configuration file to stdout.
+
 
 EXAMPLES
 --------
index 45b517a9011541565f001f7253b68675e9d16f3a..ae66602196e0d30ad5ef7e96c2da1a98ff33330a 100644 (file)
@@ -28,6 +28,7 @@ SYNOPSIS
                [--disable-sqflow         | -d]
                [--hdr-digest             | -g]
                [--data-digest            | -G]
+               [--dump-config            | -O]
 
 DESCRIPTION
 -----------
@@ -140,6 +141,10 @@ OPTIONS
 --data-digest::
        Generates/verifies data digest (TCP).
 
+-O::
+--dump-config::
+       Print out resulting JSON configuration file to stdout.
+
 EXAMPLES
 --------
 * Connect to a subsystem named nqn.2014-08.com.example:nvme:nvm-subsystem-sn-d78432
index d0a281a98eb05f2d13c72e58d1e170174caeed74..dfb34fa46ab5e6f285e33fcca986c03995685ec9 100644 (file)
@@ -29,6 +29,7 @@ SYNOPSIS
                [--queue-size=<#>         | -Q <#>]
                [--persistent             | -p]
                [--quiet                  | -S]
+               [--dump-config            | -O]
                [--output-format=<fmt>    | -o <fmt>]
 
 DESCRIPTION
@@ -184,6 +185,10 @@ OPTIONS
 --quiet::
        Suppress already connected errors.
 
+-O::
+--dump-config::
+       Print out resulting JSON configuration file to stdout.
+
 -o <format>::
 --output-format=<format>::
               Set the reporting format to 'normal', 'json', or
index ee9978a08140cb40369868387f3d15113094d170..02071c2e2fa542d588e3bb8639d8dabfeef702e7 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -51,6 +51,7 @@
 static char *raw;
 static bool persistent;
 static bool quiet;
+static bool dump_config;
 
 static const char *nvmf_tport          = "transport type";
 static const char *nvmf_traddr         = "transport address";
@@ -409,6 +410,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
                OPT_FLAG("quiet",        'S', &quiet,         "suppress already connected errors"),
                OPT_STRING("config",     'C', "FILE", &config_file, nvmf_config_file),
                OPT_INCR("verbose",      'v', &verbose,       "Increase logging verbosity"),
+               OPT_FLAG("dump-config",  'O', &dump_config,   "Dump configuration file to stdout"),
                OPT_END()
        };
 
@@ -441,6 +443,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
 
        if (!strcmp(config_file, "none"))
                config_file = NULL;
+
        r = nvme_scan(config_file);
        if (persistent && !cfg.keep_alive_tmo)
                cfg.keep_alive_tmo = 30;
@@ -534,6 +537,8 @@ out_free:
                free(hnqn);
        if (hid)
                free(hid);
+       if (dump_config)
+               nvme_dump_config(r);
        nvme_free_tree(r);
 
        return ret;
@@ -559,6 +564,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
                NVMF_OPTS(cfg),
                OPT_STRING("config", 'C', "FILE", &config_file, nvmf_config_file),
                OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
+               OPT_FLAG("dump-config", 'O', &dump_config, "Dump JSON configuration to stdout"),
                OPT_END()
        };
 
@@ -604,8 +610,9 @@ int nvmf_connect(const char *desc, int argc, char **argv)
                }
        }
 
-       if (strcmp(config_file, "none"))
+       if (!strcmp(config_file, "none"))
                config_file = NULL;
+
        r = nvme_scan(config_file);
        if (!hostnqn)
                hostnqn = hnqn = nvmf_hostnqn_from_file();
@@ -632,6 +639,8 @@ out_free:
                free(hnqn);
        if (hid)
                free(hid);
+       if (dump_config)
+               nvme_dump_config(r);
        nvme_free_tree(r);
        return errno;
 }