From: Hannes Reinecke Date: Mon, 15 Nov 2021 11:11:57 +0000 (+0100) Subject: nvme: add option 'dump-config' to 'connect' and 'discover' X-Git-Tag: v2.0-rc0~49^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f602d4f33cd6fd519ce0c354f72643e62feca838;p=users%2Fsagi%2Fnvme-cli.git nvme: add option 'dump-config' to 'connect' and 'discover' 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 --- diff --git a/Documentation/nvme-connect-all.txt b/Documentation/nvme-connect-all.txt index 1cb7822b..1fff8301 100644 --- a/Documentation/nvme-connect-all.txt +++ b/Documentation/nvme-connect-all.txt @@ -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 -------- diff --git a/Documentation/nvme-connect.txt b/Documentation/nvme-connect.txt index 45b517a9..ae666021 100644 --- a/Documentation/nvme-connect.txt +++ b/Documentation/nvme-connect.txt @@ -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 diff --git a/Documentation/nvme-discover.txt b/Documentation/nvme-discover.txt index d0a281a9..dfb34fa4 100644 --- a/Documentation/nvme-discover.txt +++ b/Documentation/nvme-discover.txt @@ -29,6 +29,7 @@ SYNOPSIS [--queue-size=<#> | -Q <#>] [--persistent | -p] [--quiet | -S] + [--dump-config | -O] [--output-format= | -o ] DESCRIPTION @@ -184,6 +185,10 @@ OPTIONS --quiet:: Suppress already connected errors. +-O:: +--dump-config:: + Print out resulting JSON configuration file to stdout. + -o :: --output-format=:: Set the reporting format to 'normal', 'json', or diff --git a/fabrics.c b/fabrics.c index ee9978a0..02071c2e 100644 --- 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; }