diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3ad77062c..95b6c9b39f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,7 @@ jobs: steps: - uses: actions/checkout@v5 - name: enable foreign arch - uses: dbhi/qus/action@main + uses: docker/setup-qemu-action@v3 - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: diff --git a/fabrics.c b/fabrics.c index 9a1f0a0e98..6f60cee894 100644 --- a/fabrics.c +++ b/fabrics.c @@ -94,7 +94,7 @@ static const char *nvmf_concat = "enable secure concatenation"; static const char *nvmf_config_file = "Use specified JSON configuration file or 'none' to disable"; static const char *nvmf_context = "execution context identification string"; -struct fabric_args { +struct nvmf_args { const char *subsysnqn; const char *transport; const char *traddr; @@ -111,7 +111,7 @@ struct fabric_args { }; #define NVMF_ARGS(n, f, c, ...) \ - struct argconfig_commandline_options n[] = { \ + NVME_ARGS(n, \ OPT_STRING("transport", 't', "STR", &f.transport, nvmf_tport), \ OPT_STRING("nqn", 'n', "STR", &f.subsysnqn, nvmf_nqn), \ OPT_STRING("traddr", 'a', "STR", &f.traddr, nvmf_traddr), \ @@ -141,9 +141,9 @@ struct fabric_args { OPT_FLAG("data-digest", 'G', &c.data_digest, nvmf_data_digest), \ OPT_FLAG("tls", 0, &c.tls, nvmf_tls), \ OPT_FLAG("concat", 0, &c.concat, nvmf_concat), \ - __VA_ARGS__, \ - OPT_END() \ - } + ##__VA_ARGS__ \ + ) + static void save_discovery_log(char *raw, struct nvmf_discovery_log *log) { @@ -169,7 +169,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log) } static int setup_common_context(struct nvmf_context *fctx, - struct fabric_args *fa); + struct nvmf_args *fa); struct cb_fabrics_data { struct nvme_fabrics_config *cfg; @@ -272,7 +272,7 @@ static int cb_parser_next_line(struct nvmf_context *fctx, void *user_data) { struct cb_fabrics_data *cfd = user_data; struct nvme_fabrics_config cfg; - struct fabric_args fa = {}; + struct nvmf_args fa = {}; char *ptr, *p, line[4096]; int argc, ret = 0; bool force = false; @@ -317,7 +317,7 @@ static int cb_parser_next_line(struct nvmf_context *fctx, void *user_data) } static int setup_common_context(struct nvmf_context *fctx, - struct fabric_args *fa) + struct nvmf_args *fa) { int err; @@ -344,7 +344,7 @@ static int setup_common_context(struct nvmf_context *fctx, } static int create_common_context(struct nvme_global_ctx *ctx, - bool persistent, struct fabric_args *fa, + bool persistent, struct nvmf_args *fa, struct nvme_fabrics_config *cfg, void *user_data, struct nvmf_context **fctxp) { @@ -390,7 +390,7 @@ static int create_common_context(struct nvme_global_ctx *ctx, static int create_discovery_context(struct nvme_global_ctx *ctx, bool persistent, const char *device, - struct fabric_args *fa, + struct nvmf_args *fa, struct nvme_fabrics_config *cfg, void *user_data, struct nvmf_context **fctxp) { @@ -476,11 +476,9 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) nvme_print_flags_t flags; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_free_ struct nvmf_context *fctx = NULL; - unsigned int verbose = 0; int ret; - char *format = "normal"; struct nvme_fabrics_config cfg; - struct fabric_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME }; + struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME }; char *device = NULL; bool force = false; bool json_config = false; @@ -489,12 +487,10 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) NVMF_ARGS(opts, fa, cfg, OPT_STRING("device", 'd', "DEV", &device, "use existing discovery controller device"), - OPT_FMT("output-format", 'o', &format, output_format), OPT_FILE("raw", 'r', &raw, "save raw output to file"), OPT_FLAG("persistent", 'p', &persistent, "persistent discovery connection"), OPT_FLAG("quiet", 0, &quiet, "suppress already connected errors"), OPT_STRING("config", 'J', "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_FLAG("force", 0, &force, "Force persistent discovery controller creation"), OPT_FLAG("nbft", 0, &nbft, "Only look at NBFT tables"), @@ -508,7 +504,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) if (ret) return ret; - ret = validate_output_format(format, &flags); + ret = validate_output_format(nvme_args.output_format, &flags); if (ret < 0) { nvme_show_error("Invalid output format"); return ret; @@ -517,7 +513,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect) if (!strcmp(config_file, "none")) config_file = NULL; - log_level = map_log_level(verbose, quiet); + log_level = map_log_level(nvme_args.verbose, quiet); ctx = nvme_create_global_ctx(stderr, log_level); if (!ctx) { @@ -590,21 +586,17 @@ int fabrics_connect(const char *desc, int argc, char **argv) _cleanup_free_ char *hid = NULL; char *config_file = NULL; char *context = NULL; - unsigned int verbose = 0; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_free_ struct nvmf_context *fctx = NULL; _cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL; int ret; nvme_print_flags_t flags; struct nvme_fabrics_config cfg = { 0 }; - struct fabric_args fa = { 0 }; - char *format = "normal"; + struct nvmf_args fa = { 0 }; NVMF_ARGS(opts, fa, cfg, OPT_STRING("config", 'J', "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_FMT("output-format", 'o', &format, "Output format: normal|json"), OPT_STRING("context", 0, "STR", &context, nvmf_context)); nvmf_default_config(&cfg); @@ -613,7 +605,7 @@ int fabrics_connect(const char *desc, int argc, char **argv) if (ret) return ret; - ret = validate_output_format(format, &flags); + ret = validate_output_format(nvme_args.output_format, &flags); if (ret < 0) { nvme_show_error("Invalid output format"); return ret; @@ -644,7 +636,7 @@ int fabrics_connect(const char *desc, int argc, char **argv) } do_connect: - log_level = map_log_level(verbose, quiet); + log_level = map_log_level(nvme_args.verbose, quiet); ctx = nvme_create_global_ctx(stderr, log_level); if (!ctx) { @@ -746,17 +738,13 @@ int fabrics_disconnect(const char *desc, int argc, char **argv) struct config { char *nqn; char *device; - unsigned int verbose; }; struct config cfg = { 0 }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, nvmf_nqn), - OPT_STRING("device", 'd', "DEV", &cfg.device, device), - OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"), - OPT_END() - }; + OPT_STRING("device", 'd', "DEV", &cfg.device, device)); ret = argconfig_parse(argc, argv, desc, opts); if (ret) @@ -773,7 +761,7 @@ int fabrics_disconnect(const char *desc, int argc, char **argv) return -EINVAL; } - log_level = map_log_level(cfg.verbose, false); + log_level = map_log_level(nvme_args.verbose, false); ctx = nvme_create_global_ctx(stderr, log_level); if (!ctx) { @@ -834,22 +822,18 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv) struct config { char *transport; - unsigned int verbose; }; struct config cfg = { 0 }; - OPT_ARGS(opts) = { - OPT_STRING("transport", 'r', "STR", (char *)&cfg.transport, nvmf_tport), - OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"), - OPT_END() - }; + NVME_ARGS(opts, + OPT_STRING("transport", 'r', "STR", (char *)&cfg.transport, nvmf_tport)); ret = argconfig_parse(argc, argv, desc, opts); if (ret) return ret; - log_level = map_log_level(cfg.verbose, false); + log_level = map_log_level(nvme_args.verbose, false); ctx = nvme_create_global_ctx(stderr, log_level); if (!ctx) { @@ -900,13 +884,11 @@ int fabrics_config(const char *desc, int argc, char **argv) _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; char *config_file = PATH_NVMF_CONFIG; struct nvme_fabrics_config cfg; - struct fabric_args fa = { }; - unsigned int verbose = 0; + struct nvmf_args fa = { }; int ret; NVMF_ARGS(opts, fa, cfg, OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file), - OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"), OPT_FLAG("scan", 'R', &scan_tree, "Scan current NVMeoF topology"), OPT_FLAG("modify", 'M', &modify_config, "Modify JSON configuration file"), OPT_FLAG("dump", 'O', &dump_config, "Dump JSON configuration to stdout"), @@ -921,7 +903,7 @@ int fabrics_config(const char *desc, int argc, char **argv) if (!strcmp(config_file, "none")) config_file = NULL; - log_level = map_log_level(verbose, quiet); + log_level = map_log_level(nvme_args.verbose, quiet); ctx = nvme_create_global_ctx(stderr, log_level); if (!ctx) { @@ -1015,16 +997,12 @@ int fabrics_dim(const char *desc, int argc, char **argv) char *nqn; char *device; char *tas; - unsigned int verbose; } cfg = { 0 }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, "Comma-separated list of DC nqn"), OPT_STRING("device", 'd', "DEV", &cfg.device, "Comma-separated list of DC nvme device handle."), - OPT_STRING("task", 't', "TASK", &cfg.tas, "[register|deregister]"), - OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"), - OPT_END() - }; + OPT_STRING("task", 't', "TASK", &cfg.tas, "[register|deregister]")); ret = argconfig_parse(argc, argv, desc, opts); if (ret) @@ -1052,7 +1030,7 @@ int fabrics_dim(const char *desc, int argc, char **argv) return -EINVAL; } - log_level = map_log_level(cfg.verbose, false); + log_level = map_log_level(nvme_args.verbose, false); ctx = nvme_create_global_ctx(stderr, log_level); if (!ctx) { diff --git a/libnvme/src/libnvme.ld b/libnvme/src/libnvme.ld index ce97672ee0..7ea480a57f 100644 --- a/libnvme/src/libnvme.ld +++ b/libnvme/src/libnvme.ld @@ -229,6 +229,7 @@ LIBNVME_2_0 { nvme_set_application; nvme_set_dry_run; nvme_set_etdas; + nvme_set_ioctl_probing; nvme_set_keyring; nvme_set_property; nvme_set_root; diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index ec52f0d94b..45af12c31b 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -46,6 +46,11 @@ void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable) ctx->dry_run = enable; } +void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable) +{ + ctx->ioctl_probing = enable; +} + void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl, void *(*submit_entry)(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd)) @@ -108,9 +113,11 @@ static int __nvme_transport_handle_open_direct(struct nvme_transport_handle *hdl return -EINVAL; } - ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy); - if (ret > 0) - hdl->ioctl64 = true; + if (hdl->ctx->ioctl_probing) { + ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy); + if (ret > 0) + hdl->ioctl64 = true; + } return 0; } diff --git a/libnvme/src/nvme/linux.h b/libnvme/src/nvme/linux.h index 10e2205034..36df2d78cf 100644 --- a/libnvme/src/nvme/linux.h +++ b/libnvme/src/nvme/linux.h @@ -742,4 +742,16 @@ int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx, */ void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable); +/** + * nvme_set_ioctl_probing() - Enable/disable 64-bit IOCTL probing + * @ctx: struct nvme_global_ctx object + * @enable: Enable/disable 64-bit IOCTL probing + * + * When IOCTL probing is enabled, a 64-bit IOCTL command is issued to + * figure out if the passthru interface supports it. + * + * IOCTL probing is enabled per default. + */ +void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable); + #endif /* _LIBNVME_LINUX_H */ diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 7a984f28fc..1e4036bcfa 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -272,6 +272,7 @@ struct nvme_global_ctx { struct list_head hosts; struct nvme_log log; bool mi_probe_enabled; + bool ioctl_probing; bool create_only; bool dry_run; struct nvme_fabric_options *options; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 9b59b19825..4d3f9396f2 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -335,7 +335,7 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level) int fd; ctx = calloc(1, sizeof(*ctx)); - if (!ctx) + if (!ctx) return NULL; if (fp) { @@ -353,6 +353,8 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level) list_head_init(&ctx->hosts); list_head_init(&ctx->endpoints); + ctx->ioctl_probing = true; + return ctx; } diff --git a/logging.c b/logging.c index dcb8e7638b..4469795084 100644 --- a/logging.c +++ b/logging.c @@ -30,7 +30,7 @@ static struct submit_data sb; bool is_printable_at_level(int level) { return ((log_level >= level) && - (strcmp(nvme_cfg.output_format, "normal") == 0)); + (strcmp(nvme_args.output_format, "normal") == 0)); } int map_log_level(int verbose, bool quiet) @@ -132,7 +132,7 @@ void nvme_submit_exit(struct nvme_transport_handle *hdl, bool nvme_decide_retry(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd, int err) { - if (!nvme_cfg.no_retries) + if (!nvme_args.no_retries) return false; if (err != -EAGAIN || diff --git a/nvme-print-json.c b/nvme-print-json.c index 73b0c52e0a..045e62a568 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -202,7 +202,7 @@ static void json_id_iocs_iocsc(struct json_object *obj_iocsc, __u64 iocsc) static bool verbose_mode(void) { - return json_print_ops.flags & VERBOSE || nvme_cfg.output_format_ver == 2; + return json_print_ops.flags & VERBOSE || nvme_args.output_format_ver == 2; } static void json_id_iocs(struct nvme_id_iocs *iocs) @@ -4893,7 +4893,7 @@ static void json_list_item(nvme_ns_t n, struct table *t) static void json_print_list_items(struct nvme_global_ctx *ctx) { if (json_print_ops.flags & VERBOSE) { - if (nvme_cfg.output_format_ver == 2) + if (nvme_args.output_format_ver == 2) json_detail_list_v2(ctx); else json_detail_list(ctx); diff --git a/nvme-print.c b/nvme-print.c index 5776b020db..b388ff0880 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -20,7 +20,7 @@ #define nvme_print(name, flags, ...) \ do { \ struct print_ops *ops = nvme_print_ops(flags); \ - if (ops && ops->name && !nvme_cfg.dry_run) \ + if (ops && ops->name && !nvme_args.dry_run) \ ops->name(__VA_ARGS__); \ } while (false) diff --git a/nvme-rpmb.c b/nvme-rpmb.c index 5e955846c7..42a67c6b4a 100644 --- a/nvme-rpmb.c +++ b/nvme-rpmb.c @@ -855,7 +855,7 @@ int rpmb_cmd_option(int argc, char **argv, struct command *acmd, struct plugin * .target = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("cmd", 'c', "command", &cfg.cmd, opt), OPT_STRING("msgfile", 'f', "FILE", &cfg.msgfile, mfile), OPT_STRING("keyfile", 'g', "FILE", &cfg.keyfile, kfile), @@ -863,9 +863,7 @@ int rpmb_cmd_option(int argc, char **argv, struct command *acmd, struct plugin * OPT_STRING("msg", 'd', "data", &cfg.msg, msg), OPT_UINT("address", 'o', &cfg.address, address), OPT_UINT("blocks", 'b', &cfg.blocks, blocks), - OPT_UINT("target", 't', &cfg.target, target), - OPT_END() - }; + OPT_UINT("target", 't', &cfg.target, target)); _cleanup_free_ unsigned char *key_buf = NULL; _cleanup_free_ unsigned char *msg_buf = NULL; diff --git a/nvme.c b/nvme.c index f229b7447b..20bf54aabf 100644 --- a/nvme.c +++ b/nvme.c @@ -183,14 +183,6 @@ static struct program nvme = { .extensions = &builtin, }; -#ifdef CONFIG_JSONC -const char *output_format = "Output format: normal|json|binary"; -#else /* CONFIG_JSONC */ -const char *output_format = "Output format: normal|binary"; -#endif /* CONFIG_JSONC */ -const char *timeout = "timeout value, in milliseconds"; -const char *verbose = "Increase output verbosity"; -const char *dry_run = "show command instead of sending"; const char *uuid_index = "UUID index"; static const char *app_tag = "app tag for end-to-end PI"; @@ -260,7 +252,7 @@ static const char *pmrmscl = "PMRMSCL=0xe14 register offset"; static const char *pmrmscu = "PMRMSCU=0xe18 register offset"; static const char *ish = "Ignore Shutdown (for NVMe-MI command)"; -struct nvme_config nvme_cfg = { +struct nvme_args nvme_args = { .output_format = "normal", .output_format_ver = 1, .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, @@ -375,7 +367,7 @@ static int parse_args(int argc, char *argv[], const char *desc, if (ret) return ret; - log_level = map_log_level(nvme_cfg.verbose, false); + log_level = map_log_level(nvme_args.verbose, false); return 0; } @@ -396,6 +388,9 @@ int parse_and_open(struct nvme_global_ctx **ctx, if (!ctx_new) return -ENOMEM; + nvme_set_ioctl_probing(ctx_new, + !argconfig_parse_seen(opts, "no-ioctl-probing")); + ret = get_transport_handle(ctx_new, argc, argv, O_RDONLY, &hdl_new); if (ret) { nvme_free_global_ctx(ctx_new); @@ -505,7 +500,7 @@ bool nvme_is_output_format_json(void) { nvme_print_flags_t flags; - if (validate_output_format(nvme_cfg.output_format, &flags)) + if (validate_output_format(nvme_args.output_format, &flags)) return false; return flags == JSON; @@ -545,7 +540,7 @@ static int get_smart_log(int argc, char **argv, struct command *acmd, struct plu if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -605,7 +600,7 @@ static int get_ana_log(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -885,7 +880,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1028,7 +1023,7 @@ static int get_endurance_log(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1108,7 +1103,7 @@ static int get_effects_log(int argc, char **argv, struct command *acmd, struct p if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1183,7 +1178,7 @@ static int get_supported_log_pages(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1241,7 +1236,7 @@ static int get_error_log(int argc, char **argv, struct command *acmd, struct plu if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1307,7 +1302,7 @@ static int get_fw_log(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1360,7 +1355,7 @@ static int get_changed_ns_list_log(int argc, char **argv, bool alloc) if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1436,7 +1431,7 @@ static int get_pred_lat_per_nvmset_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1499,7 +1494,7 @@ static int get_pred_lat_event_agg_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1583,7 +1578,7 @@ static int get_persistent_event_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1695,7 +1690,7 @@ static int get_endurance_event_agg_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1771,7 +1766,7 @@ static int get_lba_status_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1819,7 +1814,7 @@ static int get_resv_notif_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1876,7 +1871,7 @@ static int get_boot_part_log(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1966,7 +1961,7 @@ static int get_phy_rx_eom_log(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2051,7 +2046,7 @@ static int get_media_unit_stat_log(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2104,7 +2099,7 @@ static int get_supp_cap_config_log(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2405,7 +2400,7 @@ static int get_log(int argc, char **argv, struct command *acmd, struct plugin *p if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2529,7 +2524,7 @@ static int sanitize_log(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2583,7 +2578,7 @@ static int get_fid_support_effects_log(int argc, char **argv, struct command *ac if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2635,7 +2630,7 @@ static int get_mi_cmd_support_effects_log(int argc, char **argv, struct command if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2691,7 +2686,7 @@ static int list_ctrl(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0 || (flags != JSON && flags != NORMAL)) { nvme_show_error("Invalid output format"); return err; @@ -2754,7 +2749,7 @@ static int list_ns(int argc, char **argv, struct command *acmd, struct plugin *p if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0 || (flags != JSON && flags != NORMAL)) { nvme_show_error("Invalid output format"); return -EINVAL; @@ -2823,7 +2818,7 @@ static int id_ns_lba_format(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -2878,7 +2873,7 @@ static int id_endurance_grp_list(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0 || (flags != JSON && flags != NORMAL)) { nvme_show_error("invalid output format"); return -EINVAL; @@ -2972,7 +2967,7 @@ static int delete_ns(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3034,7 +3029,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3309,7 +3304,7 @@ static int create_ns(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3508,7 +3503,7 @@ static int list_subsys(int argc, char **argv, struct command *acmd, if (optind < argc) devname = basename(argv[optind++]); - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0 || (flags != JSON && flags != NORMAL)) { nvme_show_error("Invalid output format"); return -EINVAL; @@ -3560,7 +3555,7 @@ static int list(int argc, char **argv, struct command *acmd, struct plugin *plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0 || (flags != JSON && flags != NORMAL)) { nvme_show_error("Invalid output format"); return -EINVAL; @@ -3622,7 +3617,7 @@ int __id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3677,7 +3672,7 @@ static int nvm_id_ctrl(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3734,7 +3729,7 @@ static int nvm_id_ns(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3808,7 +3803,7 @@ static int nvm_id_ns_lba_format(int argc, char **argv, struct command *acmd, str if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3876,7 +3871,7 @@ static int ns_descs(int argc, char **argv, struct command *acmd, struct plugin * if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -3954,7 +3949,7 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4033,7 +4028,7 @@ static int cmd_set_independent_id_ns(int argc, char **argv, struct command *acmd if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4089,7 +4084,7 @@ static int id_ns_granularity(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4140,7 +4135,7 @@ static int id_nvmset(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4195,7 +4190,7 @@ static int id_uuid(int argc, char **argv, struct command *acmd, struct plugin *p if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4251,7 +4246,7 @@ static int id_iocs(int argc, char **argv, struct command *acmd, struct plugin *p if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4306,7 +4301,7 @@ static int id_domain(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4346,7 +4341,7 @@ static int get_ns_id(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4455,7 +4450,7 @@ static int primary_ctrl_caps(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4513,7 +4508,7 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *acmd, stru if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4686,7 +4681,7 @@ static int device_self_test(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4777,7 +4772,7 @@ static int self_test_log(int argc, char **argv, struct command *acmd, struct plu if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -4845,7 +4840,7 @@ static void get_feature_id_print(struct feat_cfg cfg, int err, __u64 result, nvme_feature_show(cfg.feature_id, cfg.sel, result); if (NVME_CHECK(cfg.sel, GET_FEATURES_SEL, SUPPORTED)) nvme_show_select_result(cfg.feature_id, result); - else if (verbose || !strcmp(nvme_cfg.output_format, "json")) + else if (verbose || !strcmp(nvme_args.output_format, "json")) nvme_feature_show_fields(cfg.feature_id, result, buf); else if (buf) d(buf, cfg.data_len, 16, 1); @@ -4986,7 +4981,7 @@ static int get_feature(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -5174,7 +5169,7 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -5386,7 +5381,7 @@ static int fw_commit(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -5516,7 +5511,7 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin return -EINVAL; } - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -5594,7 +5589,7 @@ static int sanitize_cmd(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -5702,7 +5697,7 @@ static int sanitize_ns_cmd(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -5879,7 +5874,7 @@ static int show_registers(int argc, char **argv, struct command *acmd, struct pl return -EINVAL; } - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -6156,7 +6151,7 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug return -EINVAL; } - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -6502,7 +6497,7 @@ static int get_property(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -6548,7 +6543,7 @@ static int set_property(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -6638,8 +6633,8 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin .bs = 0, }; - if (nvme_cfg.timeout != NVME_DEFAULT_IOCTL_TIMEOUT) - timeout_ms = nvme_cfg.timeout; + if (nvme_args.timeout != NVME_DEFAULT_IOCTL_TIMEOUT) + timeout_ms = nvme_args.timeout; NVME_ARGS(opts, OPT_FLAG("ish", 'I', &cfg.ish, ish), @@ -6670,7 +6665,7 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin return err; } - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -6914,7 +6909,7 @@ static int set_feature(int argc, char **argv, struct command *acmd, struct plugi if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -7057,7 +7052,7 @@ static int sec_send(int argc, char **argv, struct command *acmd, struct plugin * if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -7666,7 +7661,7 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -8031,7 +8026,7 @@ static int resv_acquire(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -8107,7 +8102,7 @@ static int resv_register(int argc, char **argv, struct command *acmd, struct plu if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -8190,7 +8185,7 @@ static int resv_release(int argc, char **argv, struct command *acmd, struct plug if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -8262,7 +8257,7 @@ static int resv_report(int argc, char **argv, struct command *acmd, struct plugi if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -8431,7 +8426,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec), OPT_BYTE("dsm", 'D', &cfg.dsmgmt, dsm), OPT_FLAG("show-command", 'V', &cfg.show, show), - OPT_FLAG("dry-run", 'w', &nvme_cfg.dry_run, dry_run), OPT_FLAG("latency", 't', &cfg.latency, latency), OPT_FLAG("force", 0, &cfg.force, force)); @@ -8586,7 +8580,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char } } - if (cfg.show || nvme_cfg.dry_run) { + if (cfg.show || nvme_args.dry_run) { printf("opcode : %02x\n", opcode); printf("nsid : %02x\n", cfg.nsid); printf("flags : %02x\n", 0); @@ -8604,7 +8598,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char printf("pif : %02x\n", pif); printf("sts : %02x\n", sts); } - if (nvme_cfg.dry_run) + if (nvme_args.dry_run) return 0; nvme_init_io(&cmd, opcode, cfg.nsid, cfg.start_block, buffer, @@ -8834,7 +8828,7 @@ static int sec_recv(int argc, char **argv, struct command *acmd, struct plugin * if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -8921,7 +8915,7 @@ static int get_lba_status(int argc, char **argv, struct command *acmd, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -9003,7 +8997,7 @@ static int capacity_mgmt(int argc, char **argv, struct command *acmd, struct plu if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -9348,7 +9342,6 @@ static int passthru(int argc, char **argv, bool admin, OPT_FILE("metadata", 'M', &cfg.metadata, metadata), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump), OPT_FLAG("show-command", 's', &cfg.show_command, show), - OPT_FLAG("dry-run", 'd', &nvme_cfg.dry_run, dry_run), OPT_FLAG("read", 'r', &cfg.read, re), OPT_FLAG("write", 'w', &cfg.write, wr), OPT_FLAG("latency", 'T', &cfg.latency, latency)); @@ -9357,7 +9350,7 @@ static int passthru(int argc, char **argv, bool admin, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags_t); + err = validate_output_format(nvme_args.output_format, &flags_t); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -9432,7 +9425,7 @@ static int passthru(int argc, char **argv, bool admin, } } - if (cfg.show_command || nvme_cfg.dry_run) { + if (cfg.show_command || nvme_args.dry_run) { printf("opcode : %02x\n", cfg.opcode); printf("flags : %02x\n", cfg.flags); printf("rsvd1 : %04x\n", cfg.rsvd); @@ -9449,9 +9442,9 @@ static int passthru(int argc, char **argv, bool admin, printf("cdw13 : %08x\n", cfg.cdw13); printf("cdw14 : %08x\n", cfg.cdw14); printf("cdw15 : %08x\n", cfg.cdw15); - printf("timeout_ms : %08x\n", nvme_cfg.timeout); + printf("timeout_ms : %08x\n", nvme_args.timeout); } - if (nvme_cfg.dry_run) + if (nvme_args.dry_run) return 0; gettimeofday(&start_time, NULL); @@ -9472,7 +9465,7 @@ static int passthru(int argc, char **argv, bool admin, .cdw13 = cfg.cdw13, .cdw14 = cfg.cdw14, .cdw15 = cfg.cdw15, - .timeout_ms = nvme_cfg.timeout, + .timeout_ms = nvme_args.timeout, }; if (admin) err = nvme_submit_admin_passthru(hdl, &cmd); @@ -10349,7 +10342,6 @@ static int tls_key(int argc, char **argv, struct command *acmd, struct plugin *p static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Show the topology\n"; - const char *output_format = "Output format: normal|json|binary|tabular"; const char *ranking = "Ranking order: namespace|ctrl|multipath"; nvme_print_flags_t flags; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; @@ -10373,7 +10365,7 @@ static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -10634,7 +10626,7 @@ static int get_mgmt_addr_list_log(int argc, char **argv, struct command *acmd, s if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -10681,7 +10673,7 @@ static int get_rotational_media_info_log(int argc, char **argv, struct command * if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -10767,7 +10759,7 @@ static int get_dispersed_ns_participating_nss_log(int argc, char **argv, struct if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -10916,7 +10908,7 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *ac if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -11027,7 +11019,7 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -11108,7 +11100,7 @@ static int get_host_discovery_log(int argc, char **argv, struct command *acmd, s if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -11182,7 +11174,7 @@ static int get_ave_discovery_log(int argc, char **argv, struct command *acmd, st if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -11258,7 +11250,7 @@ static int get_pull_model_ddc_req_log(int argc, char **argv, struct command *acm if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; diff --git a/nvme.h b/nvme.h index 9670959460..d5b301a860 100644 --- a/nvme.h +++ b/nvme.h @@ -52,29 +52,42 @@ enum nvme_cli_topo_ranking { #define SYS_NVME "/sys/class/nvme" -struct nvme_config { +struct nvme_args { char *output_format; int verbose; __u32 timeout; bool dry_run; bool no_retries; + bool no_ioctl_probing; unsigned int output_format_ver; }; +#ifdef CONFIG_JSONC +#define DESC_OUTPUT_FORMAT "Output format: normal|json|binary|tabular" +#else /* CONFIG_JSONC */ +#define DESC_OUTPUT_FORMAT "Output format: normal|binary|tabular" +#endif /* CONFIG_JSONC */ + /* * the ordering of the arguments matters, as the argument parser uses the first match, thus any * command which defines -t shorthand will match first. */ #define NVME_ARGS(n, ...) \ struct argconfig_commandline_options n[] = { \ - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose), \ - OPT_FMT("output-format", 'o', &nvme_cfg.output_format, output_format), \ + OPT_INCR("verbose", 'v', &nvme_args.verbose, \ + "Increase output verbosity"), \ + OPT_FMT("output-format", 'o', &nvme_args.output_format, \ + DESC_OUTPUT_FORMAT), \ ##__VA_ARGS__, \ - OPT_UINT("timeout", 't', &nvme_cfg.timeout, timeout), \ - OPT_FLAG("dry-run", 0, &nvme_cfg.dry_run, dry_run), \ - OPT_FLAG("no-retries", 0, &nvme_cfg.no_retries, \ - "disable retry logic on errors\n"), \ - OPT_UINT("output-format-version", 0, &nvme_cfg.output_format_ver, \ + OPT_UINT("timeout", 't', &nvme_args.timeout, \ + "timeout value, in milliseconds"), \ + OPT_FLAG("dry-run", 0, &nvme_args.dry_run, \ + "show command instead of executing"), \ + OPT_FLAG("no-retries", 0, &nvme_args.no_retries, \ + "disable retry logic on errors"), \ + OPT_FLAG("no-ioctl-probing", 0, &nvme_args.no_ioctl_probing, \ + "disable 64-bit IOCTL support probing"), \ + OPT_UINT("output-format-version", 0, &nvme_args.output_format_ver, \ "output format version: 1|2"), \ OPT_END() \ } @@ -105,12 +118,8 @@ static inline DEFINE_CLEANUP_FUNC( cleanup_nvme_transport_handle, struct nvme_transport_handle *, nvme_close) #define _cleanup_nvme_transport_handle_ __cleanup__(cleanup_nvme_transport_handle) -extern const char *output_format; -extern const char *timeout; -extern const char *verbose; -extern const char *dry_run; extern const char *uuid_index; -extern struct nvme_config nvme_cfg; +extern struct nvme_args nvme_args; int validate_output_format(const char *format, nvme_print_flags_t *flags); bool nvme_is_output_format_json(void); diff --git a/plugins/amzn/amzn-nvme.c b/plugins/amzn/amzn-nvme.c index 014a3c3ad8..fdb48b2a71 100644 --- a/plugins/amzn/amzn-nvme.c +++ b/plugins/amzn/amzn-nvme.c @@ -485,11 +485,8 @@ static int get_stats(int argc, char **argv, struct command *acmd, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, - "Output Format: normal|json"), - OPT_FLAG("details", 'd', &detail, "Detail IO histogram of each block size ranges"), - OPT_END()}; + NVME_ARGS(opts, + OPT_FLAG("details", 'd', &detail, "Detail IO histogram of each block size ranges")); rc = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (rc) diff --git a/plugins/dapustor/dapustor-nvme.c b/plugins/dapustor/dapustor-nvme.c index 268f45c101..894c9f7d17 100644 --- a/plugins/dapustor/dapustor-nvme.c +++ b/plugins/dapustor/dapustor-nvme.c @@ -513,6 +513,7 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command * struct nvme_extended_additional_smart_log ext_smart_log; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; struct nvme_additional_smart_log smart_log; + nvme_print_flags_t flags; bool has_ext = false; int err; @@ -526,21 +527,25 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command * .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_FLAG_JSON("json", 'j', &cfg.json, json), - OPT_END() - }; + OPT_FLAG_JSON("json", 'j', &cfg.json, json)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + err = dapustor_additional_smart_log_data(hdl, &smart_log, &ext_smart_log, &has_ext); if (!err) { - if (cfg.json) + if (flags & JSON || cfg.json) show_dapustor_smart_log_jsn(&smart_log, &ext_smart_log, cfg.namespace_id, nvme_transport_handle_get_name(hdl), diff --git a/plugins/dera/dera-nvme.c b/plugins/dera/dera-nvme.c index 7a0d54ea8a..8db1847012 100644 --- a/plugins/dera/dera-nvme.c +++ b/plugins/dera/dera-nvme.c @@ -123,9 +123,7 @@ static int get_status(int argc, char **argv, struct command *acmd, struct plugin struct nvme_dera_smart_info_log log; int err; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/fdp/fdp.c b/plugins/fdp/fdp.c index 445a68ccce..208a6878f6 100644 --- a/plugins/fdp/fdp.c +++ b/plugins/fdp/fdp.c @@ -34,30 +34,25 @@ static int fdp_configs(int argc, char **argv, struct command *acmd, struct config { __u16 egid; - char *output_format; bool human_readable; bool raw_binary; }; struct config cfg = { .egid = 0, - .output_format = "normal", .raw_binary = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("endgrp-id", 'e', &cfg.egid, egid), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable), - OPT_END() - }; + OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; @@ -116,22 +111,18 @@ static int fdp_usage(int argc, char **argv, struct command *acmd, struct plugin struct config cfg = { .egid = 0, - .output_format = "normal", .raw_binary = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("endgrp-id", 'e', &cfg.egid, egid), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; @@ -186,12 +177,9 @@ static int fdp_stats(int argc, char **argv, struct command *acmd, struct plugin .raw_binary = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("endgrp-id", 'e', &cfg.egid, egid), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -238,30 +226,25 @@ static int fdp_events(int argc, char **argv, struct command *acmd, struct plugin struct config { __u16 egid; bool host_events; - char *output_format; bool raw_binary; }; struct config cfg = { .egid = 0, .host_events = false, - .output_format = "normal", .raw_binary = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("endgrp-id", 'e', &cfg.egid, egid), OPT_FLAG("host-events", 'E', &cfg.host_events, host_events), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; @@ -304,27 +287,22 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin struct config { __u32 nsid; - char *output_format; bool raw_binary; }; struct config cfg = { - .output_format = "normal", .raw_binary = false, }; - OPT_ARGS(opts) = { - OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id), + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; @@ -388,11 +366,9 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin .pids = "", }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id), - OPT_LIST("pids", 'p', &cfg.pids, _pids), - OPT_END() - }; + OPT_LIST("pids", 'p', &cfg.pids, _pids)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -459,14 +435,12 @@ static int fdp_set_events(int argc, char **argv, struct command *acmd, struct pl .sv = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid), OPT_SHRT("placement-handle", 'p', &cfg.ph, ph), OPT_FLAG("enable", 'e', &cfg.enable, enable), OPT_FLAG("save", 's', &cfg.sv, sv), - OPT_LIST("event-types", 't', &cfg.event_types, event_types), - OPT_END() - }; + OPT_LIST("event-types", 't', &cfg.event_types, event_types)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -537,13 +511,10 @@ static int fdp_feature(int argc, char **argv, struct command *acmd, struct plugi .endgid = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_SHRT("endgrp-id", 'e', &cfg.endgid, endurance_group), OPT_BYTE("enable-conf-idx", 'c', &cfg.fdpcidx, enable_conf_idx), - OPT_FLAG("disable", 'd', &cfg.disable, disable), - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose), - OPT_END() - }; + OPT_FLAG("disable", 'd', &cfg.disable, disable)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c index 8ae01c49c1..8f55909386 100644 --- a/plugins/huawei/huawei-nvme.c +++ b/plugins/huawei/huawei-nvme.c @@ -303,18 +303,8 @@ static int huawei_list(int argc, char **argv, struct command *acmd, unsigned int huawei_num = 0; nvme_print_flags_t fmt; const char *desc = "Retrieve basic information for the given huawei device"; - struct config { - char *output_format; - }; - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); if (!ctx) return -ENOMEM; @@ -323,7 +313,7 @@ static int huawei_list(int argc, char **argv, struct command *acmd, if (ret) return ret; - ret = validate_output_format(cfg.output_format, &fmt); + ret = validate_output_format(nvme_args.output_format, &fmt); if (ret < 0 || (fmt != JSON && fmt != NORMAL)) return ret; diff --git a/plugins/ibm/ibm-nvme.c b/plugins/ibm/ibm-nvme.c index d0c2107ce9..2407049a76 100644 --- a/plugins/ibm/ibm-nvme.c +++ b/plugins/ibm/ibm-nvme.c @@ -4,6 +4,7 @@ #include #include "common.h" +#include "nvme.h" #include "nvme-print.h" #include "plugin.h" @@ -236,10 +237,8 @@ static int get_ibm_addi_smart_log(int argc, char **argv, struct command *cmd, st .raw_binary = 0, }; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -368,10 +367,8 @@ static int get_ibm_vpd_log(int argc, char **argv, struct command *cmd, struct pl .raw_binary = 0, }; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err < 0) @@ -549,13 +546,10 @@ static int get_ibm_persistent_event_log(int argc, char **argv, .raw_binary = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("action", 'a', &cfg.action, action), OPT_UINT("log_len", 'l', &cfg.log_len, log_len), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/innogrit/innogrit-nvme.c b/plugins/innogrit/innogrit-nvme.c index 6b7fe4206a..957a2fc9d4 100644 --- a/plugins/innogrit/innogrit-nvme.c +++ b/plugins/innogrit/innogrit-nvme.c @@ -181,9 +181,7 @@ static int innogrit_geteventlog(int argc, char **argv, time_t timep; int ret = -1; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -228,9 +226,7 @@ static int innogrit_vsc_getcdump(int argc, char **argv, struct command *acmd, time_t timep; int ret = -1; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) diff --git a/plugins/inspur/inspur-nvme.c b/plugins/inspur/inspur-nvme.c index 041a0dede8..b4bf161e14 100644 --- a/plugins/inspur/inspur-nvme.c +++ b/plugins/inspur/inspur-nvme.c @@ -212,7 +212,7 @@ static int nvme_get_vendor_log(int argc, char **argv, struct command *acmd, stru __u8 local_mem[BYTE_OF_4K]; int err; - OPT_ARGS(opts) = { OPT_END() }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/intel/intel-nvme.c b/plugins/intel/intel-nvme.c index 545f44a615..3c8a92e395 100644 --- a/plugins/intel/intel-nvme.c +++ b/plugins/intel/intel-nvme.c @@ -344,6 +344,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, struct nvme_additional_smart_log smart_log; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + nvme_print_flags_t flags; int err; struct config { @@ -356,20 +357,24 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_FLAG_JSON("json", 'j', &cfg.json, json), - OPT_END() - }; + OPT_FLAG_JSON("json", 'j', &cfg.json, json)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + err = nvme_get_log_simple(hdl, 0xca, &smart_log, sizeof(smart_log)); if (!err) { - if (cfg.json) + if (flags & JSON || cfg.json) show_intel_smart_log_jsn(&smart_log, cfg.namespace_id, nvme_transport_handle_get_name(hdl)); else if (!cfg.raw_binary) @@ -399,10 +404,8 @@ static int get_market_log(int argc, char **argv, struct command *acmd, struct pl struct config cfg = { }; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -461,10 +464,8 @@ static int get_temp_stats_log(int argc, char **argv, struct command *acmd, struc struct config cfg = { }; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1030,6 +1031,7 @@ static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct __u8 data[NAND_LAT_STATS_LEN]; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + nvme_print_flags_t flags; int err; const char *desc = "Get Intel Latency Statistics log and show it."; @@ -1048,17 +1050,21 @@ static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct struct config cfg = { }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("write", 'w', &cfg.write, write), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_FLAG_JSON("json", 'j', &cfg.json, json), - OPT_END() - }; + OPT_FLAG_JSON("json", 'j', &cfg.json, json)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + /* For optate, latency stats are deleted every time their LID is pulled. * Therefore, we query the longest lat_stats log page first. */ @@ -1105,7 +1111,7 @@ static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct sizeof(struct intel_lat_stats)); } - if (cfg.json) + if (flags & JSON || cfg.json) json_lat_stats(cfg.write); else if (!cfg.raw_binary) show_lat_stats(cfg.write); @@ -1367,15 +1373,13 @@ static int get_internal_log(int argc, char **argv, struct command *acmd, .core = -1 }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("log", 'l', &cfg.log, log), OPT_INT("region", 'r', &cfg.core, core), OPT_INT("nlognum", 'm', &cfg.lnum, nlognum), OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_FILE("output-file", 'o', &cfg.file, file), - OPT_FLAG("verbose-nlog", 'v', &cfg.verbose, verbose), - OPT_END() - }; + OPT_FLAG("verbose-nlog", 'v', &cfg.verbose, verbose)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -1633,12 +1637,10 @@ static int set_lat_stats_thresholds(int argc, char **argv, .bucket_thresholds = "", }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("write", 'w', &cfg.write, write), OPT_LIST("bucket-thresholds", 't', &cfg.bucket_thresholds, - bucket_thresholds), - OPT_END() - }; + bucket_thresholds)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); diff --git a/plugins/lm/lm-nvme.c b/plugins/lm/lm-nvme.c index 6f65f6b3d8..769c5a3c4e 100644 --- a/plugins/lm/lm-nvme.c +++ b/plugins/lm/lm-nvme.c @@ -80,13 +80,11 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu .file = NULL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("size", 's', &cfg.sz, sz), OPT_SHRT("cntlid", 'c', &cfg.cntlid, cntlid), OPT_BYTE("queue-type", 'q', &cfg.qt, qt), - OPT_FLAG("consent", 0, &cfg.consent, consent), - OPT_END() - }; + OPT_FLAG("consent", 0, &cfg.consent, consent)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -138,10 +136,8 @@ static int lm_delete_cdq(int argc, char **argv, struct command *acmd, struct plu .cdqid = 0 }; - OPT_ARGS(opts) = { - OPT_SHRT("cdqid", 'C', &cfg.cdqid, cdqid), - OPT_END() - }; + NVME_ARGS(opts, + OPT_SHRT("cdqid", 'C', &cfg.cdqid, cdqid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -198,14 +194,12 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu .stop = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_BYTE("mos", 'm', &cfg.mos, mos), OPT_SHRT("cdqid", 'C', &cfg.cdqid, cdqid), OPT_FLAG("start", 0, &cfg.start, start), - OPT_FLAG("stop", 0, &cfg.stop, stop), - OPT_END() - }; + OPT_FLAG("stop", 0, &cfg.stop, stop)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -313,7 +307,7 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct .dudmq = false }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_SHRT("cntlid", 'c', &cfg.cntlid, cntlid), OPT_BYTE("stype", 't', &cfg.stype, stype), @@ -324,9 +318,7 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct OPT_BYTE("uidx", 'u', &cfg.uidx, uidx), OPT_LONG("offset", 'o', &cfg.offset, offset), OPT_UINT("numd", 'n', &cfg.numd, numd), - OPT_FILE("input-file", 'f', &cfg.input, input), - OPT_END() - }; + OPT_FILE("input-file", 'f', &cfg.input, input)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -431,7 +423,6 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct __u64 offset; __u32 numd; char *output; - char *output_format; bool human_readable; }; @@ -444,11 +435,10 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct .offset = 0, .numd = 0, .output = NULL, - .output_format = "normal", .human_readable = false }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_SHRT("cntlid", 'c', &cfg.cntlid, cntlid), OPT_BYTE("csuuidi", 'U', &cfg.csuuidi, csuuidi), @@ -457,22 +447,19 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct OPT_LONG("offset", 'o', &cfg.offset, offset), OPT_UINT("numd", 'n', &cfg.numd, numd), OPT_FILE("output-file", 'f', &cfg.output, output), - OPT_FMT("output-format", 0, &cfg.output_format, output_format), - OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_info), - OPT_END() - }; + OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_info)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; } - if (cfg.output_format && cfg.offset != 0 && !(flags & BINARY)) { + if (nvme_args.output_format && cfg.offset != 0 && !(flags & BINARY)) { nvme_show_error("cannot parse non-zero offset"); return -EINVAL; } @@ -552,12 +539,10 @@ static int lm_set_cdq(int argc, char **argv, struct command *acmd, struct plugin .tpt = -1, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_SHRT("cdqid", 'C', &cfg.cdqid, cdqid), OPT_UINT("hp", 'H', &cfg.hp, hp), - OPT_UINT("tpt", 'T', &cfg.tpt, tpt), - OPT_END() - }; + OPT_UINT("tpt", 'T', &cfg.tpt, tpt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -589,25 +574,20 @@ static int lm_get_cdq(int argc, char **argv, struct command *acmd, struct plugin struct config { __u16 cdqid; - char *output_format; }; struct config cfg = { .cdqid = 0, - .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_SHRT("cdqid", 'C', &cfg.cdqid, cdqid), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts, + OPT_SHRT("cdqid", 'C', &cfg.cdqid, cdqid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; diff --git a/plugins/memblaze/memblaze-nvme.c b/plugins/memblaze/memblaze-nvme.c index 57c6d5bd1d..ba6b45aa13 100644 --- a/plugins/memblaze/memblaze-nvme.c +++ b/plugins/memblaze/memblaze-nvme.c @@ -432,11 +432,9 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *ac .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -482,9 +480,7 @@ static int mb_get_powermanager_status(int argc, char **argv, struct command *acm _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; int err; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -525,11 +521,9 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *acm .save = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("value", 'v', &cfg.value, value), - OPT_FLAG("save", 's', &cfg.save, save), - OPT_END() - }; + OPT_FLAG("save", 's', &cfg.save, save)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -578,10 +572,8 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *acmd, .value = 0, }; - OPT_ARGS(opts) = { - OPT_LIST("param", 'p', &cfg.param, param), - OPT_END() - }; + NVME_ARGS(opts, + OPT_LIST("param", 'p', &cfg.param, param)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -708,9 +700,7 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *acmd FILE *fdi = NULL; int err; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -780,11 +770,9 @@ static int mb_selective_download(int argc, char **argv, struct command *acmd, st .select = "\0", }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("fw", 'f', "FILE", &cfg.fw, fw), - OPT_STRING("select", 's', "flag", &cfg.select, select), - OPT_END() - }; + OPT_STRING("select", 's', "flag", &cfg.select, select)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -984,10 +972,8 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *acmd, s .write = 0, }; - OPT_ARGS(opts) = { - OPT_FLAG("write", 'w', &cfg.write, write), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("write", 'w', &cfg.write, write)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1027,9 +1013,7 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *acmd, .save = 0, }; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1563,9 +1547,8 @@ static int mb_get_smart_log_add(int argc, char **argv, struct command *acmd, str struct config cfg = {0}; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, "dump the whole log buffer in binary format"), - OPT_END()}; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, "dump the whole log buffer in binary format")); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; @@ -1710,7 +1693,7 @@ static int mb_set_latency_feature(int argc, char **argv, struct command *acmd, s struct config cfg = {0}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("sel-perf-log", 's', &cfg.perf_monitor, "Select features to turn on, default: Disable\n" " bit 0: latency statistics\n" @@ -1726,8 +1709,7 @@ static int mb_set_latency_feature(int argc, char **argv, struct command *acmd, s OPT_UINT("set-write-threshold", 'w', &cfg.write_threshold, "set write high latency log threshold, it's a 0-based value and unit is 10ms"), OPT_UINT("set-trim-threshold", 't', &cfg.de_allocate_trim_threshold, - "set trim high latency log threshold, it's a 0-based value and unit is 10ms"), - OPT_END()}; + "set trim high latency log threshold, it's a 0-based value and unit is 10ms")); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; @@ -1766,8 +1748,7 @@ static int mb_get_latency_feature(int argc, char **argv, struct command *acmd, s // Get the configuration - OPT_ARGS(opts) = { - OPT_END()}; + NVME_ARGS(opts); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; @@ -1914,12 +1895,11 @@ static int mb_get_latency_stats(int argc, char **argv, struct command *acmd, str struct config cfg = {0}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, - "dump the whole log buffer in binary format"), - OPT_END()}; + "dump the whole log buffer in binary format")); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; @@ -2020,12 +2000,11 @@ static int mb_get_high_latency_log(int argc, char **argv, struct command *acmd, struct config cfg = {0}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, - "dump the whole log buffer in binary format"), - OPT_END()}; + "dump the whole log buffer in binary format")); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; @@ -2263,7 +2242,7 @@ static int mb_get_performance_stats(int argc, char **argv, struct command *acmd, struct config cfg = {.duration = 1, .raw_binary = false}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("duration", 'd', &cfg.duration, @@ -2271,8 +2250,7 @@ static int mb_get_performance_stats(int argc, char **argv, struct command *acmd, OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, - "dump the whole log buffer in binary format"), - OPT_END()}; + "dump the whole log buffer in binary format")); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; diff --git a/plugins/micron/micron-nvme.c b/plugins/micron/micron-nvme.c index 08d1e98257..0585331702 100644 --- a/plugins/micron/micron-nvme.c +++ b/plugins/micron/micron-nvme.c @@ -592,11 +592,9 @@ static int micron_selective_download(int argc, char **argv, .select = "\0", }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("fw", 'f', "FILE", &cfg.fw, fw), - OPT_STRING("select", 's', "flag", &cfg.select, select), - OPT_END() - }; + OPT_STRING("select", 's', "flag", &cfg.select, select)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -717,12 +715,10 @@ static int micron_smbus_option(int argc, char **argv, .status = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("option", 'o', "option", &opt.option, option), OPT_UINT("value", 'v', &opt.value, value), - OPT_UINT("save", 's', &opt.save, save), - OPT_END() - }; + OPT_UINT("save", 's', &opt.save, save)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err < 0) @@ -775,6 +771,7 @@ static int micron_temp_stats(int argc, char **argv, struct command *acmd, unsigned int tempSensors[SensorCount] = { 0 }; const char *desc = "Retrieve Micron temperature info for the given device "; const char *fmt = "output format normal|json"; + nvme_print_flags_t flags; struct format { char *fmt; }; @@ -786,10 +783,8 @@ static int micron_temp_stats(int argc, char **argv, struct command *acmd, struct json_object *logPages; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -797,7 +792,13 @@ static int micron_temp_stats(int argc, char **argv, struct command *acmd, return -1; } - if (!strcmp(cfg.fmt, "json")) + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + + if (!strcmp(cfg.fmt, "json") || flags & JSON) is_json = true; err = nvme_get_log_smart(hdl, NVME_NSID_ALL, &smart_log); @@ -907,6 +908,7 @@ static int micron_pcie_stats(int argc, char **argv, char strTempFile[1024], strTempFile2[1024], cmdbuf[1024]; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + nvme_print_flags_t flags; char *businfo = NULL; char *devicename = NULL; char tdevice[NAME_MAX] = { 0 }; @@ -931,10 +933,8 @@ static int micron_pcie_stats(int argc, char **argv, __u32 correctable_errors; __u32 uncorrectable_errors; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -942,6 +942,12 @@ static int micron_pcie_stats(int argc, char **argv, return -1; } + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + /* pull log details based on the model name */ if (sscanf(argv[optind], "/dev/nvme%d", &ctrlIdx) != 1) ctrlIdx = 0; @@ -951,7 +957,7 @@ static int micron_pcie_stats(int argc, char **argv, goto out; } - if (!strcmp(cfg.fmt, "normal")) + if (!strcmp(cfg.fmt, "normal") || flags & NORMAL) is_json = false; if (eModel == M5407) { @@ -1104,9 +1110,7 @@ static int micron_clear_pcie_correctable_errors(int argc, char **argv, __u64 result = 0; __u8 fid = MICRON_FEATURE_CLEAR_PCI_CORRECTABLE_ERRORS; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err < 0) @@ -1818,10 +1822,8 @@ static int micron_nand_stats(int argc, char **argv, .fmt = "json", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -1963,10 +1965,8 @@ static int micron_smart_ext_log(int argc, char **argv, struct format cfg = { .fmt = "json", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -2016,10 +2016,8 @@ static int micron_work_load_log(int argc, char **argv, struct command *acmd, str struct format cfg = { .fmt = "json", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -2068,10 +2066,8 @@ static int micron_vendor_telemetry_log(int argc, char **argv, struct format cfg = { .fmt = "json", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -2475,10 +2471,8 @@ static int micron_drive_info(int argc, char **argv, struct command *acmd, .fmt = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err < 0) @@ -2794,10 +2788,8 @@ static int micron_fw_activation_history(int argc, char **argv, struct command *a .fmt = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &eModel); if (err < 0) @@ -2902,12 +2894,10 @@ static int micron_latency_stats_track(int argc, char **argv, struct command *acm .threshold = 0 }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("option", 'o', "option", &opt.option, option), OPT_STRING("command", 'c', "command", &opt.command, cmdstr), - OPT_UINT("threshold", 't', &opt.threshold, thrtime), - OPT_END() - }; + OPT_UINT("threshold", 't', &opt.threshold, thrtime)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); @@ -3034,9 +3024,7 @@ static int micron_latency_stats_logs(int argc, char **argv, struct command *acmd int err = -1; const char *desc = "Display Latency tracking log information"; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err) @@ -3106,10 +3094,8 @@ static int micron_latency_stats_info(int argc, char **argv, struct command *acmd uint64_t *cmd_stats = &log.all_cmds[0]; char *cmd_str = "All"; - OPT_ARGS(opts) = { - OPT_STRING("command", 'c', "command", &opt.command, cmdstr), - OPT_END() - }; + NVME_ARGS(opts, + OPT_STRING("command", 'c', "command", &opt.command, cmdstr)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err < 0) @@ -3178,10 +3164,8 @@ static int micron_ocp_smart_health_logs(int argc, char **argv, struct command *a }; int err = 0; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &eModel); if (err < 0) @@ -3240,9 +3224,7 @@ static int micron_clr_fw_activation_history(int argc, char **argv, _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); int err = 0; err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); @@ -3289,11 +3271,9 @@ static int micron_telemetry_cntrl_option(int argc, char **argv, .select = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("option", 'o', "option", &opt.option, option), - OPT_UINT("select", 's', &opt.select, select), - OPT_END() - }; + OPT_UINT("select", 's', &opt.select, select)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err < 0) @@ -3683,12 +3663,10 @@ static int micron_internal_logs(int argc, char **argv, struct command *acmd, .log = 0x07, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("type", 't', "log type", &cfg.type, type), OPT_STRING("package", 'p', "FILE", &cfg.package, package), - OPT_UINT("data_area", 'd', &cfg.data_area, data_area), - OPT_END() - }; + OPT_UINT("data_area", 'd', &cfg.data_area, data_area)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -3968,9 +3946,7 @@ static int micron_logpage_dir(int argc, char **argv, struct command *acmd, _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; int i; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &model); if (err < 0) @@ -4042,10 +4018,8 @@ static int micron_cloud_boot_SSD_version(int argc, char **argv, .fmt = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &eModel); if (err < 0) @@ -4106,10 +4080,8 @@ static int micron_device_waf(int argc, char **argv, struct command *acmd, .fmt = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &eModel); if (err < 0) @@ -4167,10 +4139,8 @@ static int micron_cloud_log(int argc, char **argv, struct command *acmd, .fmt = "json", }; - OPT_ARGS(opts) = { - OPT_FMT("format", 'f', &cfg.fmt, fmt), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FMT("format", 'f', &cfg.fmt, fmt)); err = micron_parse_options(&ctx, &hdl, argc, argv, desc, opts, &eModel); if (err < 0) diff --git a/plugins/nbft/nbft-plugin.c b/plugins/nbft/nbft-plugin.c index 4f21689e91..41ae9103f9 100644 --- a/plugins/nbft/nbft-plugin.c +++ b/plugins/nbft/nbft-plugin.c @@ -538,29 +538,23 @@ int show_nbft(int argc, char **argv, struct command *acmd, struct plugin *plugin _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; struct nbft_file_entry *head = NULL; struct list_head nbft_list; - char *format = "normal"; char *nbft_path = NBFT_SYSFS_PATH; nvme_print_flags_t flags; int ret; - unsigned int verbose = 0; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &format, "Output format: normal|json"), + NVME_ARGS(opts, OPT_FLAG("subsystem", 's', &show_subsys, "show NBFT subsystems"), OPT_FLAG("hfi", 'H', &show_hfi, "show NBFT HFIs"), OPT_FLAG("discovery", 'd', &show_discovery, "show NBFT discovery controllers"), - OPT_STRING("nbft-path", 0, "STR", &nbft_path, "user-defined path for NBFT tables"), - OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"), - OPT_END() - }; + OPT_STRING("nbft-path", 0, "STR", &nbft_path, "user-defined path for NBFT tables")); ret = argconfig_parse(argc, argv, desc, opts); if (ret) return ret; - log_level = map_log_level(verbose, false /* quiet */); + log_level = map_log_level(nvme_args.verbose, false /* quiet */); - ret = validate_output_format(format, &flags); + ret = validate_output_format(nvme_args.output_format, &flags); if (ret < 0) return ret; diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index 05ee21cd57..a736d1ae05 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -901,20 +901,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, int num_smdevices = 0; struct nvme_transport_handle *hdl; - struct config { - bool verbose; - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FLAG("verbose", 'v', &cfg.verbose, "Increase output verbosity"), - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|column"), - OPT_END() - }; + NVME_ARGS(opts); if (!ctx) return -ENOMEM; @@ -923,9 +910,10 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, if (ret < 0) return ret; - fmt = netapp_output_format(cfg.output_format); + fmt = netapp_output_format(nvme_args.output_format); if (fmt != NNORMAL && fmt != NCOLUMN && fmt != NJSON) { - fprintf(stderr, "Unrecognized output format: %s\n", cfg.output_format); + fprintf(stderr, "Unrecognized output format: %s\n", + nvme_args.output_format); return -EINVAL; } @@ -1012,20 +1000,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, int num_ontapdevices = 0; struct nvme_transport_handle *hdl; - struct config { - bool verbose; - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FLAG("verbose", 'v', &cfg.verbose, "Increase output verbosity"), - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|column"), - OPT_END() - }; + NVME_ARGS(opts); if (!ctx) return -ENOMEM; @@ -1034,9 +1009,10 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, if (ret < 0) return ret; - fmt = netapp_output_format(cfg.output_format); + fmt = netapp_output_format(nvme_args.output_format); if (fmt != NNORMAL && fmt != NCOLUMN && fmt != NJSON) { - fprintf(stderr, "Unrecognized output format: %s\n", cfg.output_format); + fprintf(stderr, "Unrecognized output format: %s\n", + nvme_args.output_format); return -EINVAL; } diff --git a/plugins/ocp/ocp-clear-features.c b/plugins/ocp/ocp-clear-features.c index 2b5b8cb046..76cb35f3ad 100644 --- a/plugins/ocp/ocp-clear-features.c +++ b/plugins/ocp/ocp-clear-features.c @@ -22,11 +22,9 @@ static int ocp_clear_feature(int argc, char **argv, const char *desc, const __u8 bool uuid = true; int err; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("no-uuid", 'n', NULL, - "Skip UUID index search (UUID index not required for OCP 1.0)"), - OPT_END() - }; + "Skip UUID index search (UUID index not required for OCP 1.0)")); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -82,12 +80,10 @@ int get_ocp_error_counters(int argc, char **argv, struct command *acmd, .nsid = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid), - OPT_FLAG("no-uuid", 'u', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'u', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/ocp/ocp-fw-activation-history.c b/plugins/ocp/ocp-fw-activation-history.c index efe64528b9..f7a2707bc2 100644 --- a/plugins/ocp/ocp-fw-activation-history.c +++ b/plugins/ocp/ocp-fw-activation-history.c @@ -29,12 +29,7 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *acmd, { const char *desc = "Retrieves the OCP firmware activation history log."; - char *format = "normal"; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &format, "output format : normal | json"), - OPT_END() - }; + NVME_ARGS(opts); _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; @@ -74,7 +69,8 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *acmd, if (!err) { nvme_print_flags_t print_flag; - err = validate_output_format(format, &print_flag); + err = validate_output_format(nvme_args.output_format, + &print_flag); if (err < 0) { fprintf(stderr, "Error: Invalid output format.\n"); return err; diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index 8339a11d84..2c76c7dafa 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -248,7 +248,7 @@ static int get_hwcomp_log(struct nvme_transport_handle *hdl, __u32 id, bool list .desc = NULL, }; - ret = validate_output_format(nvme_cfg.output_format, &fmt); + ret = validate_output_format(nvme_args.output_format, &fmt); if (ret < 0) { fprintf(stderr, "error: ocp: invalid output format\n"); return ret; diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 288293d070..d4db801215 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -267,25 +267,13 @@ static int ocp_latency_monitor_log(int argc, char **argv, _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; int ret = 0; - struct config { - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, - "output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) return ret; - ret = get_c3_log_page(hdl, cfg.output_format); + ret = get_c3_log_page(hdl, nvme_args.output_format); if (ret) fprintf(stderr, "ERROR : OCP : Failure reading the C3 Log Page, ret = %d\n", @@ -343,7 +331,7 @@ int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, .latency_monitor_feature_enable = 0x1, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("active_bucket_timer_threshold", 't', &cfg.active_bucket_timer_threshold, active_bucket_timer_threshold), OPT_UINT("active_threshold_a", 'a', &cfg.active_threshold_a, active_threshold_a), OPT_UINT("active_threshold_b", 'b', &cfg.active_threshold_b, active_threshold_b), @@ -353,9 +341,7 @@ int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, OPT_UINT("active_latency_minimum_window", 'w', &cfg.active_latency_minimum_window, active_latency_minimum_window), OPT_UINT("debug_log_trigger_enable", 'r', &cfg.debug_log_trigger_enable, debug_log_trigger_enable), OPT_UINT("discard_debug_log", 'l', &cfg.discard_debug_log, discard_debug_log), - OPT_UINT("latency_monitor_feature_enable", 'e', &cfg.latency_monitor_feature_enable, latency_monitor_feature_enable), - OPT_END() - }; + OPT_UINT("latency_monitor_feature_enable", 'e', &cfg.latency_monitor_feature_enable, latency_monitor_feature_enable)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -438,12 +424,10 @@ static int ocp_get_latency_monitor_feature(int argc, char **argv, struct command .nsid = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid), - OPT_FLAG("no-uuid", 'u', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'u', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1431,7 +1415,6 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct const char *output_file = "Output file name with path;\n" "e.g. '-f ./path/name'\n'-f ./path1/path2/';\n" "If requested path does not exist, the directory will be newly created."; - const char *output_format = "output format normal|json"; const char *data_area = "Telemetry Data Area; 1, 2, 3, or 4;\n" "e.g. '-a 1 for Data Area 1.'\n" "e.g. '-a 2 for Data Areas 1 and 2.'\n" @@ -1456,15 +1439,12 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct const char *tele_log_suffix = "telemetry.bin"; bool host_behavior_changed = false; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STR("telemetry-log", 'l', &opt.telemetry_log, telemetry_log), OPT_STR("string-log", 's', &opt.string_log, string_log), OPT_FILE("output-file", 'f', &opt.output_file, output_file), - OPT_FMT("output-format", 'o', &opt.output_format, output_format), OPT_INT("data-area", 'a', &opt.data_area, data_area), - OPT_STR("telemetry-type", 't', &opt.telemetry_type, telemetry_type), - OPT_END() - }; + OPT_STR("telemetry-type", 't', &opt.telemetry_type, telemetry_type)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1708,10 +1688,7 @@ static int ocp_unsupported_requirements_log(int argc, char **argv, struct comman .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -1812,10 +1789,7 @@ static int ocp_error_recovery_log(int argc, char **argv, struct command *acmd, s .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json|binary"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -1915,10 +1889,7 @@ static int ocp_device_capabilities_log(int argc, char **argv, struct command *ac .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json|binary"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -1982,10 +1953,8 @@ static int ocp_set_telemetry_profile_feature(int argc, char **argv, struct comma .tps = 0, }; - OPT_ARGS(opts) = { - OPT_BYTE("telemetry-profile-select", 't', &cfg.tps, tps), - OPT_END() - }; + NVME_ARGS(opts, + OPT_BYTE("telemetry-profile-select", 't', &cfg.tps, tps)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2029,12 +1998,10 @@ static int ocp_get_telemetry_profile_feature(int argc, char **argv, struct comma .nsid = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid), - OPT_FLAG("no-uuid", 'u', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'u', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2128,12 +2095,10 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *a .save = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("power-state", 'p', &cfg.power_state, power_state), OPT_FLAG("save", 's', &cfg.save, save), - OPT_FLAG("no-uuid", 'n', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'n', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2204,12 +2169,10 @@ static int get_dssd_power_state_feature(int argc, char **argv, struct command *a .all = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 'S', &cfg.sel, sel), OPT_FLAG("all", 'a', NULL, all), - OPT_FLAG("no-uuid", 'n', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'n', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2261,12 +2224,10 @@ static int set_plp_health_check_interval(int argc, char **argv, struct command * .sv = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("plp_health_interval", 'p', &cfg.plp_health_interval, plp_health_interval), OPT_FLAG("save", 's', &cfg.sv, sv), - OPT_FLAG("no-uuid", 'n', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'n', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2318,10 +2279,8 @@ static int get_plp_health_check_interval(int argc, char **argv, struct command * .sel = 0, }; - OPT_ARGS(opts) = { - OPT_BYTE("sel", 'S', &cfg.sel, sel), - OPT_END() - }; + NVME_ARGS(opts, + OPT_BYTE("sel", 'S', &cfg.sel, sel)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2372,11 +2331,9 @@ static int set_dssd_async_event_config(int argc, char **argv, struct command *ac .sv = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("enable-panic-notices", 'e', &cfg.epn, epn), - OPT_FLAG("save", 's', &cfg.sv, sv), - OPT_END() - }; + OPT_FLAG("save", 's', &cfg.sv, sv)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2425,10 +2382,8 @@ static int get_dssd_async_event_config(int argc, char **argv, struct command *ac .sel = 0, }; - OPT_ARGS(opts) = { - OPT_BYTE("sel", 'S', &cfg.sel, sel), - OPT_END() - }; + NVME_ARGS(opts, + OPT_BYTE("sel", 'S', &cfg.sel, sel)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2505,12 +2460,8 @@ static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *a .output_file = NULL, }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, - "output Format:normal|json|binary"), - OPT_FILE("output-file", 'f', &cfg.output_file, output_file), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FILE("output-file", 'f', &cfg.output_file, output_file)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -2619,10 +2570,7 @@ static int ocp_tcg_configuration_log(int argc, char **argv, struct command *acmd .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -2734,12 +2682,10 @@ static int get_error_injection(int argc, char **argv, struct command *acmd, stru struct config cfg = { 0 }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_FLAG("no-uuid", 'n', NULL, no_uuid), - OPT_FLAG("all-ns", 'a', NULL, all_ns), - OPT_END() - }; + OPT_FLAG("all-ns", 'a', NULL, all_ns)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2897,11 +2843,9 @@ static int get_enable_ieee1667_silo(int argc, char **argv, struct command *acmd, _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("sel", 's', &cfg.sel, sel), - OPT_FLAG("no-uuid", 'n', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'n', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -2957,12 +2901,10 @@ static int set_enable_ieee1667_silo(int argc, char **argv, struct command *acmd, _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("enable", 'e', NULL, no_uuid), OPT_FLAG("save", 's', NULL, save), - OPT_FLAG("no-uuid", 'n', NULL, no_uuid), - OPT_END() - }; + OPT_FLAG("no-uuid", 'n', NULL, no_uuid)); err = parse_and_open(&ctx, &hdl, argc, argv, enable_ieee1667_silo, opts); if (err) @@ -3016,7 +2958,7 @@ static int ocp_get_persistent_event_log(int argc, char **argv, if (err) return err; - err = validate_output_format(nvme_cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; diff --git a/plugins/ocp/ocp-smart-extended-log.c b/plugins/ocp/ocp-smart-extended-log.c index 3eef14a9a7..d4625d5d8e 100644 --- a/plugins/ocp/ocp-smart-extended-log.c +++ b/plugins/ocp/ocp-smart-extended-log.c @@ -103,28 +103,14 @@ int ocp_smart_add_log(int argc, char **argv, struct command *acmd, _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; int ret = 0; - struct config { - char *output_format; - unsigned int output_format_version; - }; - - struct config cfg = { - .output_format = "normal", - .output_format_version = 1, - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json"), - OPT_UINT("output-format-version", 0, &cfg.output_format_version, "output Format version: 1|2"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) return ret; - ret = get_c0_log_page(hdl, cfg.output_format, - cfg.output_format_version); + ret = get_c0_log_page(hdl, nvme_args.output_format, + nvme_args.output_format_ver); if (ret) fprintf(stderr, "ERROR : OCP : Failure reading the C0 Log Page, ret = %d\n", ret); diff --git a/plugins/sandisk/sandisk-nvme.c b/plugins/sandisk/sandisk-nvme.c index aa73b25771..c021fa5634 100644 --- a/plugins/sandisk/sandisk-nvme.c +++ b/plugins/sandisk/sandisk-nvme.c @@ -320,7 +320,6 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, " NONE - Default, capture without using NVMe telemetry.\n" \ " HOST - Host-initiated telemetry.\n" \ " CONTROLLER - Controller-initiated telemetry."; - const char *verbose = "Display more debug messages."; char f[PATH_MAX] = {0}; char fileSuffix[PATH_MAX] = {0}; __u32 xfer_size = 0; @@ -340,7 +339,6 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, __u64 file_size; __u64 offset; char *type; - bool verbose; }; struct config cfg = { @@ -350,19 +348,15 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, .file_size = 0, .offset = 0, .type = NULL, - .verbose = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FILE("output-file", 'o', &cfg.file, file), OPT_UINT("transfer-size", 's', &cfg.xfer_size, size), OPT_UINT("data-area", 'd', &cfg.data_area, data_area), OPT_LONG("file-size", 'f', &cfg.file_size, file_size), OPT_LONG("offset", 'e', &cfg.offset, offset), - OPT_FILE("type", 't', &cfg.type, type), - OPT_FLAG("verbose", 'v', &cfg.verbose, verbose), - OPT_END() - }; + OPT_FILE("type", 't', &cfg.type, type)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -473,7 +467,7 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, goto out; } else { ret = sndk_do_cap_udui(hdl, f, xfer_size, - cfg.verbose, cfg.file_size, + nvme_args.verbose, cfg.file_size, cfg.offset); goto out; } @@ -569,10 +563,8 @@ static int sndk_drive_resize(int argc, char **argv, .size = 0, }; - OPT_ARGS(opts) = { - OPT_UINT("size", 's', &cfg.size, size), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("size", 's', &cfg.size, size)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -920,10 +912,7 @@ static int sndk_vs_fw_activate_history(int argc, char **argv, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -971,9 +960,7 @@ static int sndk_clear_fw_activate_history(int argc, char **argv, __u64 capabilities = 0; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -1043,9 +1030,7 @@ static int sndk_capabilities(int argc, char **argv, uint64_t capabilities = 0; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c index 23783a5c60..ff8c3aa003 100644 --- a/plugins/scaleflux/sfx-nvme.c +++ b/plugins/scaleflux/sfx-nvme.c @@ -336,6 +336,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, #endif /* CONFIG_JSONC */ _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + nvme_print_flags_t flags; struct config { __u32 namespace_id; bool raw_binary; @@ -347,21 +348,25 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_FLAG_JSON("json", 'j', &cfg.json, json), - OPT_END() - }; + OPT_FLAG_JSON("json", 'j', &cfg.json, json)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + err = nvme_get_nsid_log(hdl, cfg.namespace_id, false, 0xca, (void *)&smart_log, sizeof(smart_log)); if (!err) { - if (cfg.json) + if (flags & JSON || cfg.json) show_sfx_smart_log_jsn(&smart_log, cfg.namespace_id, nvme_transport_handle_get_name(hdl)); else if (!cfg.raw_binary) @@ -513,11 +518,9 @@ static int get_lat_stats_log(int argc, char **argv, struct command *acmd, struct struct config cfg = { }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("write", 'w', &cfg.write, write), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -654,9 +657,7 @@ static int sfx_get_bad_block(int argc, char **argv, struct command *acmd, struct char *desc = "Get bad block table of sfx block device."; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -710,10 +711,8 @@ static int query_cap_info(int argc, char **argv, struct command *acmd, struct pl struct config cfg; int err = 0; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -840,12 +839,10 @@ static int change_cap(int argc, char **argv, struct command *acmd, struct plugin .force = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("cap", 'c', &cfg.capacity_in_gb, cap_gb), OPT_SUFFIX("cap-byte", 'z', &cfg.cap_in_byte, cap_byte), - OPT_FLAG("force", 'f', &cfg.force, force), - OPT_END() - }; + OPT_FLAG("force", 'f', &cfg.force, force)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -952,13 +949,11 @@ static int sfx_set_feature(int argc, char **argv, struct command *acmd, struct p .force = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_UINT("feature-id", 'f', &cfg.feature_id, feature_id), OPT_UINT("value", 'v', &cfg.value, value), - OPT_FLAG("force", 's', &cfg.force, force), - OPT_END() - }; + OPT_FLAG("force", 's', &cfg.force, force)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1046,11 +1041,9 @@ static int sfx_get_feature(int argc, char **argv, struct command *acmd, struct p .feature_id = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_UINT("feature-id", 'f', &cfg.feature_id, feature_id), - OPT_END() - }; + OPT_UINT("feature-id", 'f', &cfg.feature_id, feature_id)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1379,14 +1372,12 @@ static int sfx_dump_evtlog(int argc, char **argv, struct command *acmd, struct p .output = NULL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FILE("file", 'f', &cfg.file, file), OPT_UINT("namespace_id", 'n', &cfg.namespace_id, namespace_id), OPT_UINT("storage_medium", 's', &cfg.storage_medium, storage_medium), OPT_FLAG("parse", 'p', &cfg.parse, parse), - OPT_FILE("output", 'o', &cfg.output, output), - OPT_END() - }; + OPT_FILE("output", 'o', &cfg.output, output)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1502,14 +1493,12 @@ static int sfx_expand_cap(int argc, char **argv, struct command *acmd, struct pl .units = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace_id", 'n', &cfg.namespace_id, namespace_id), OPT_LONG("namespace_size", 's', &cfg.namespace_size, namespace_size), OPT_LONG("namespace_cap", 'c', &cfg.namespace_cap, namespace_cap), OPT_UINT("lbaf", 'l', &cfg.lbaf, lbaf), - OPT_UINT("units", 'u', &cfg.units, units), - OPT_END() - }; + OPT_UINT("units", 'u', &cfg.units, units)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1562,6 +1551,7 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin char path[512], numa_node[5], vendor[10], form_factor[15], temperature[10], io_speed[15]; char chr_dev[8], serial_number[21], model_number[41], firmware_revision[9], pcie_status[9]; struct json_object *root, *dev_stats, *link_stats, *crit_stats; + nvme_print_flags_t flags; __u64 get_feat_result; double write_amp; @@ -1572,15 +1562,19 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin .json = false }; - OPT_ARGS(opts) = { - OPT_FLAG("json-print", 'j', &cfg.json, json_desc), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("json-print", 'j', &cfg.json, json_desc)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + //Calculate formatted capacity, not concerned with errors, we may have a char device memset(&path, 0, 512); snprintf(path, 512, "/dev/%s", nvme_transport_handle_get_name(hdl)); @@ -1905,7 +1899,7 @@ static int sfx_status(int argc, char **argv, struct command *acmd, struct plugin return err; } - if (cfg.json) { + if (flags & JSON || cfg.json) { root = json_create_object(); json_object_add_value_string(root, "ScaleFlux Status", nvme_transport_handle_get_name(hdl)); diff --git a/plugins/seagate/seagate-nvme.c b/plugins/seagate/seagate-nvme.c index 44956c5d09..740171cf4a 100644 --- a/plugins/seagate/seagate-nvme.c +++ b/plugins/seagate/seagate-nvme.c @@ -150,30 +150,26 @@ static int log_pages_supp(int argc, char **argv, struct command *acmd, __u32 i = 0; log_page_map logPageMap; const char *desc = "Retrieve Seagate Supported Log-Page information for the given device "; - const char *output_format = "output in binary format"; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + nvme_print_flags_t flags; int fmt; - struct config { - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; + + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + err = nvme_get_log_simple(hdl, 0xc5, &logPageMap, sizeof(logPageMap)); if (!err) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { printf("Seagate Supported Log-pages count :%d\n", le32_to_cpu(logPageMap.NumLogPages)); printf("%-15s %-30s\n", "LogPage-Id", "LogPage-Name"); @@ -181,11 +177,11 @@ static int log_pages_supp(int argc, char **argv, struct command *acmd, for (fmt = 0; fmt < 45; fmt++) printf("-"); printf("\n"); - } else + } else if (flags & JSON) json_log_pages_supp(&logPageMap); for (i = 0; i < le32_to_cpu(logPageMap.NumLogPages); i++) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { printf("0x%-15X", le32_to_cpu(logPageMap.LogPageEntry[i].LogPageID)); printf("%-30s\n", @@ -897,22 +893,12 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug struct json_object *lbafs_ExtSmart, *lbafs_DramSmart; const char *desc = "Retrieve the Firmware Activation History for Seagate NVMe drives"; - const char *output_format = "output in binary format"; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + nvme_print_flags_t flags; int err, index = 0; - struct config { - char *output_format; - }; - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -920,7 +906,13 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug return -1; } - if (strcmp(cfg.output_format, "json")) + err = validate_output_format(nvme_args.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + + if (flags & JSON) printf("Seagate Extended SMART Information :\n"); @@ -941,7 +933,7 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug if (!stx_is_jag_pan(modelNo)) { err = nvme_get_log_simple(hdl, 0xC4, &ExtdSMARTInfo, sizeof(ExtdSMARTInfo)); if (!err) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { printf("%-39s %-15s %-19s\n", "Description", "Ext-Smart-Id", "Ext-Smart-Value"); for (index = 0; index < 80; index++) printf("-"); @@ -949,7 +941,7 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug for (index = 0; index < NUMBER_EXTENDED_SMART_ATTRIBUTES; index++) print_smart_log(ExtdSMARTInfo.Version, ExtdSMARTInfo.vendorData[index], index == (NUMBER_EXTENDED_SMART_ATTRIBUTES - 1)); - } else { + } else if (flags & JSON){ lbafs_ExtSmart = json_create_object(); json_print_smart_log(lbafs_ExtSmart, &ExtdSMARTInfo); @@ -963,15 +955,15 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug err = nvme_get_log_simple(hdl, 0xCF, &logPageCF, sizeof(logPageCF)); if (!err) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { print_smart_log_CF(&logPageCF); - } else { + } else if (flags & JSON) { lbafs_DramSmart = json_create_object(); json_print_smart_log_CF(lbafs_DramSmart, &logPageCF); json_array_add_value_object(lbafs, lbafs_DramSmart); json_print_object(root, NULL); } - } else if (!strcmp(cfg.output_format, "json")) { + } else if (flags & JSON) { json_print_object(root, NULL); json_free_object(root); } @@ -982,9 +974,9 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug err = nvme_get_log_simple(hdl, 0xC0, &ehExtSmart, sizeof(ehExtSmart)); if (!err) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { print_stx_smart_log_C0(&ehExtSmart); - } else { + } else if (flags & JSON){ lbafs_ExtSmart = json_create_object(); json_print_stx_smart_log_C0(lbafs_ExtSmart, &ehExtSmart); @@ -1003,7 +995,7 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug err = nvme_get_log_simple(hdl, 0xC4, &ExtdSMARTInfo, sizeof(ExtdSMARTInfo)); if (!err) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { printf("%-39s %-15s %-19s\n", "Description", "Ext-Smart-Id", "Ext-Smart-Value"); for (index = 0; index < 80; index++) printf("-"); @@ -1011,7 +1003,7 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug for (index = 0; index < NUMBER_EXTENDED_SMART_ATTRIBUTES; index++) print_smart_log(ExtdSMARTInfo.Version, ExtdSMARTInfo.vendorData[index], index == (NUMBER_EXTENDED_SMART_ATTRIBUTES - 1)); - } else { + } else if (flags & JSON) { lbafs_ExtSmart = json_create_object(); json_print_smart_log(lbafs_ExtSmart, &ExtdSMARTInfo); @@ -1026,15 +1018,15 @@ static int vs_smart_log(int argc, char **argv, struct command *acmd, struct plug err = nvme_get_log_simple(hdl, 0xCF, &logPageCF, sizeof(logPageCF)); if (!err) { - if (strcmp(cfg.output_format, "json")) { + if (flags & NORMAL) { print_smart_log_CF(&logPageCF); - } else { + } else if (flags & JSON) { lbafs_DramSmart = json_create_object(); json_print_smart_log_CF(lbafs_DramSmart, &logPageCF); json_array_add_value_object(lbafs, lbafs_DramSmart); json_print_object(root, NULL); } - } else if (!strcmp(cfg.output_format, "json")) { + } else if (flags & JSON) { json_print_object(root, NULL); } } else if (err > 0) { @@ -1077,24 +1069,13 @@ static int temp_stats(int argc, char **argv, struct command *acmd, struct plugin int err, cf_err; int index; const char *desc = "Retrieve Seagate Temperature Stats information for the given device "; - const char *output_format = "output in binary format"; nvme_print_flags_t flags; unsigned int temperature = 0, PcbTemp = 0, SocTemp = 0, scCurrentTemp = 0, scMaxTemp = 0; unsigned long long maxTemperature = 0, MaxSocTemp = 0; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; - struct config { - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -1102,7 +1083,7 @@ static int temp_stats(int argc, char **argv, struct command *acmd, struct plugin return -1; } - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1254,21 +1235,10 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *acmd, struct _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; const char *desc = "Retrieve Seagate PCIe error counters for the given device "; - const char *output_format = "output in binary format"; int err; nvme_print_flags_t flags; - struct config { - char *output_format; - }; - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -1276,7 +1246,7 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *acmd, struct return -1; } - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1400,21 +1370,10 @@ static int stx_vs_fw_activate_history(int argc, char **argv, struct command *acm _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; const char *desc = "Retrieve FW Activate History for Seagate device "; - const char *output_format = "output in binary format"; int err; nvme_print_flags_t flags; - struct config { - char *output_format; - }; - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err < 0) { @@ -1422,7 +1381,7 @@ static int stx_vs_fw_activate_history(int argc, char **argv, struct command *acm return -1; } - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); return err; @@ -1465,10 +1424,8 @@ static int clear_fw_activate_history(int argc, char **argv, struct command *acmd .save = 0, }; - OPT_ARGS(opts) = { - OPT_FLAG("save", 's', &cfg.save, save), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("save", 's', &cfg.save, save)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err < 0) { @@ -1525,10 +1482,8 @@ static int vs_clr_pcie_correctable_errs(int argc, char **argv, struct command *a .save = 0, }; - OPT_ARGS(opts) = { - OPT_FLAG("save", 's', &cfg.save, save), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("save", 's', &cfg.save, save)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -1593,12 +1548,10 @@ static int get_host_tele(int argc, char **argv, struct command *acmd, struct plu .log_id = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_UINT("log_specific", 'i', &cfg.log_id, log_specific), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1703,11 +1656,9 @@ static int get_ctrl_tele(int argc, char **argv, struct command *acmd, struct plu .namespace_id = 0xffffffff, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1821,11 +1772,9 @@ static int vs_internal_log(int argc, char **argv, struct command *acmd, struct p .file = "", }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_FILE("dump-file", 'f', &cfg.file, file), - OPT_END() - }; + OPT_FILE("dump-file", 'f', &cfg.file, file)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/shannon/shannon-nvme.c b/plugins/shannon/shannon-nvme.c index 3c43602778..8882b4ce72 100644 --- a/plugins/shannon/shannon-nvme.c +++ b/plugins/shannon/shannon-nvme.c @@ -132,11 +132,9 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -201,16 +199,14 @@ static int get_additional_feature(int argc, char **argv, struct command *acmd, s .data_len = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_UINT("feature-id", 'f', &cfg.feature_id, feature_id), OPT_BYTE("sel", 's', &cfg.sel, sel), OPT_UINT("data-len", 'l', &cfg.data_len, data_len), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), OPT_UINT("cdw11", 'c', &cfg.cdw11, cdw11), - OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable), - OPT_END() - }; + OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -282,15 +278,13 @@ static int set_additional_feature(int argc, char **argv, struct command *acmd, s .save = 0, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_UINT("feature-id", 'f', &cfg.feature_id, feature_id), OPT_UINT("value", 'v', &cfg.value, value), OPT_UINT("data-len", 'l', &cfg.data_len, data_len), OPT_FILE("data", 'd', &cfg.file, data), - OPT_FLAG("save", 's', &cfg.save, save), - OPT_END() - }; + OPT_FLAG("save", 's', &cfg.save, save)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/solidigm/solidigm-garbage-collection.c b/plugins/solidigm/solidigm-garbage-collection.c index 3146823175..f3d39bdb4b 100644 --- a/plugins/solidigm/solidigm-garbage-collection.c +++ b/plugins/solidigm/solidigm-garbage-collection.c @@ -75,26 +75,16 @@ int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *a int err; __u8 uuid_index; - struct config { - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err) { - fprintf(stderr, "Invalid output format '%s'\n", cfg.output_format); + fprintf(stderr, "Invalid output format '%s'\n", + nvme_args.output_format); return -EINVAL; } diff --git a/plugins/solidigm/solidigm-get-drive-info.c b/plugins/solidigm/solidigm-get-drive-info.c index 9e044b987a..729904578e 100644 --- a/plugins/solidigm/solidigm-get-drive-info.c +++ b/plugins/solidigm/solidigm-get-drive-info.c @@ -13,7 +13,6 @@ int sldgm_get_drive_info(int argc, char **argv, struct command *acmd, struct plu { const char *desc = "Get drive HW information"; const char *FTL_unit_size_str = "FTL_unit_size"; - char *output_format = "normal"; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; nvme_print_flags_t flags; @@ -25,16 +24,13 @@ int sldgm_get_drive_info(int argc, char **argv, struct command *acmd, struct plu __u16 ftl_unit_size; int err; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &output_format, "normal|json"), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if ((err < 0) || !(flags == NORMAL || flags == JSON)) { nvme_show_error("Invalid output format"); return err; diff --git a/plugins/solidigm/solidigm-internal-logs.c b/plugins/solidigm/solidigm-internal-logs.c index 49700353ab..78d3e5b0b6 100644 --- a/plugins/solidigm/solidigm-internal-logs.c +++ b/plugins/solidigm/solidigm-internal-logs.c @@ -846,19 +846,15 @@ int solidigm_get_internal_log(int argc, char **argv, struct command *acmd, const char *desc = "Get Debug Firmware Logs and save them."; const char *type = "Log type; Defaults to ALL."; const char *out_dir = "Output directory; defaults to current working directory."; - const char *verbose = "To print out verbose info."; struct config cfg = { .out_dir = ".", .type = type_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_STRING("type", 't', "ALL|CIT|HIT|NLOG|ASSERT|EVENT|EXTENDED", &cfg.type, type), - OPT_STRING("dir-name", 'd', "DIRECTORY", &cfg.out_dir, out_dir), - OPT_FLAG("verbose", 'v', &cfg.verbose, verbose), - OPT_END() - }; + OPT_STRING("dir-name", 'd', "DIRECTORY", &cfg.out_dir, out_dir)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -969,7 +965,7 @@ int solidigm_get_internal_log(int argc, char **argv, struct command *acmd, if (ilog.count > 0) { int ret_cmd; _cleanup_free_ char *cmd = NULL; - char *quiet = cfg.verbose ? "" : " -q"; + char *quiet = nvme_args.verbose ? "" : " -q"; if (asprintf(&zip_name, "%s.zip", unique_folder) < 0) return -errno; diff --git a/plugins/solidigm/solidigm-latency-tracking.c b/plugins/solidigm/solidigm-latency-tracking.c index f6142ea9e1..e6baff174f 100644 --- a/plugins/solidigm/solidigm-latency-tracking.c +++ b/plugins/solidigm/solidigm-latency-tracking.c @@ -38,7 +38,6 @@ struct config { bool read; bool write; unsigned char type; - char *output_format; }; struct latency_tracker { @@ -355,23 +354,17 @@ int solidigm_get_latency_tracking_log(int argc, char **argv, struct command *acm struct latency_tracker lt = { .uuid_index = 0, - .cfg = { - .output_format = "normal", - }, .base_range_bits = BASE_RANGE_BITS_4_1, .bucket_list_size = BUCKET_LIST_SIZE_4_1, .has_average_latency_field = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("enable", 'e', <.cfg.enable, "Enable Latency Tracking"), OPT_FLAG("disable", 'd', <.cfg.disable, "Disable Latency Tracking"), OPT_FLAG("read", 'r', <.cfg.read, "Get read statistics"), OPT_FLAG("write", 'w', <.cfg.write, "Get write statistics"), - OPT_BYTE("type", 't', <.cfg.type, "Log type to get"), - OPT_FMT("output-format", 'o', <.cfg.output_format, output_format), - OPT_END() - }; + OPT_BYTE("type", 't', <.cfg.type, "Log type to get")); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -379,9 +372,10 @@ int solidigm_get_latency_tracking_log(int argc, char **argv, struct command *acm lt.hdl = hdl; - err = validate_output_format(lt.cfg.output_format, <.print_flags); + err = validate_output_format(nvme_args.output_format, <.print_flags); if (err < 0) { - fprintf(stderr, "Invalid output format '%s'\n", lt.cfg.output_format); + fprintf(stderr, "Invalid output format '%s'\n", + nvme_args.output_format); return -EINVAL; } diff --git a/plugins/solidigm/solidigm-log-page-dir.c b/plugins/solidigm/solidigm-log-page-dir.c index bffd7361fb..aed7ffdac7 100644 --- a/plugins/solidigm/solidigm-log-page-dir.c +++ b/plugins/solidigm/solidigm-log-page-dir.c @@ -184,16 +184,11 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *a const int NO_UUID_INDEX = 0; const char *description = "Retrieves list of supported log pages for each UUID index."; - OPT_ARGS(options) = { - OPT_FMT("output-format", 'o', &nvme_cfg.output_format, - "output format : normal | json"), - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose), - OPT_END() - }; - _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; + NVME_ARGS(options); + int err = parse_and_open(&ctx, &hdl, argc, argv, description, options); if (err) return err; @@ -241,10 +236,10 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *a if (!err) { nvme_print_flags_t print_flag; - err = validate_output_format(nvme_cfg.output_format, &print_flag); + err = validate_output_format(nvme_args.output_format, &print_flag); if (err) { nvme_show_error("Error: Invalid output format specified: %s.\n", - nvme_cfg.output_format); + nvme_args.output_format); return err; } diff --git a/plugins/solidigm/solidigm-market-log.c b/plugins/solidigm/solidigm-market-log.c index 37173cf4b9..cd6efdeef9 100644 --- a/plugins/solidigm/solidigm-market-log.c +++ b/plugins/solidigm/solidigm-market-log.c @@ -36,11 +36,8 @@ int sldgm_get_market_log(int argc, char **argv, struct command *acmd, __u8 uuid_idx; bool raw_binary = false; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &raw_binary, raw), - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/solidigm/solidigm-ocp-version.c b/plugins/solidigm/solidigm-ocp-version.c index 5904f87c6b..ccd1a391e8 100644 --- a/plugins/solidigm/solidigm-ocp-version.c +++ b/plugins/solidigm/solidigm-ocp-version.c @@ -12,9 +12,7 @@ int sldgm_ocp_version(int argc, char **argv, struct command *acmd, struct plugin { const char *desc = "Prints OCP extensions version of Solidigm plugin"; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); int err = argconfig_parse(argc, argv, desc, opts); diff --git a/plugins/solidigm/solidigm-smart.c b/plugins/solidigm/solidigm-smart.c index ae12d0cb89..469c465599 100644 --- a/plugins/solidigm/solidigm-smart.c +++ b/plugins/solidigm/solidigm-smart.c @@ -241,28 +241,24 @@ int solidigm_get_additional_smart_log(int argc, char **argv, struct command *acm struct config { __u32 namespace_id; - char *output_format; }; struct config cfg = { .namespace_id = NVME_NSID_ALL, - .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, "(optional) desired namespace"), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("namespace-id", 'n', &cfg.namespace_id, + "(optional) desired namespace")); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return err; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) { - fprintf(stderr, "Invalid output format '%s'\n", cfg.output_format); + fprintf(stderr, "Invalid output format '%s'\n", + nvme_args.output_format); return err; } diff --git a/plugins/solidigm/solidigm-telemetry.c b/plugins/solidigm/solidigm-telemetry.c index 53b468043b..ee8f430816 100644 --- a/plugins/solidigm/solidigm-telemetry.c +++ b/plugins/solidigm/solidigm-telemetry.c @@ -89,16 +89,13 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *acmd, stru .ctrl_init = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("host-generate", 'g', &cfg.host_gen, hgen), OPT_FLAG("controller-init", 'c', &cfg.ctrl_init, cgen), OPT_BYTE("data-area", 'd', &cfg.data_area, dgen), OPT_FILE("config-file", 'j', &cfg.cfg_file, cfile), OPT_FILE("source-file", 's', &cfg.binary_file, sfile), - OPT_STR("jq-filter", 'q', &cfg.jq_filter, jqfilt), - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, verbose), - OPT_END() - }; + OPT_STR("jq-filter", 'q', &cfg.jq_filter, jqfilt)); int err = argconfig_parse(argc, argv, desc, opts); diff --git a/plugins/solidigm/solidigm-temp-stats.c b/plugins/solidigm/solidigm-temp-stats.c index dd22af2eaf..8ea758b1ce 100644 --- a/plugins/solidigm/solidigm-temp-stats.c +++ b/plugins/solidigm/solidigm-temp-stats.c @@ -57,10 +57,8 @@ int sldgm_get_temp_stats_log(int argc, char **argv, struct command *acmd, struct .raw_binary = false, }; - OPT_ARGS(opts) = { - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/solidigm/solidigm-workload-tracker.c b/plugins/solidigm/solidigm-workload-tracker.c index 6f16b06974..324755b1ff 100644 --- a/plugins/solidigm/solidigm-workload-tracker.c +++ b/plugins/solidigm/solidigm-workload-tracker.c @@ -229,7 +229,7 @@ static void wltracker_print_field_names(struct wltracker *wlt) if (wlt->show_wall_timestamp) printf("%-*s", (int)sizeof("YYYY-MM-DD-hh:mm:ss.uuuuuu"), "wall-time"); - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("%s", "entry# "); printf("\n"); @@ -250,7 +250,7 @@ static void wltracker_print_header(struct wltracker *wlt) printf("%-24s %s\n", "Tracker Type:", trk_types[log->config.contentGroup]); printf("%-24s %u\n", "Total log page entries:", le32_to_cpu(log->workloadLogCount)); printf("%-24s %u\n", "Trigger count:", log->triggeredEvents); - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("%-24s %ld\n", "Poll count:", wlt->poll_count); if (wlt->poll_count != 0) wltracker_print_field_names(wlt); @@ -302,7 +302,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) if (err < 0) return err; - if (nvme_cfg.verbose) + if (nvme_args.verbose) wltracker_print_header(wlt); cnt = log->workloadLogCount; @@ -330,7 +330,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) // retrieve fresh timestamp to reconstruct wall time union WorkloadLogEnable we = log->config; - if (nvme_cfg.verbose > 1) { + if (nvme_args.verbose > 1) { printf("Temporarily enabling tracker to find current timestamp\n"); printf("Original config value: 0x%08x\n", we.dword); } @@ -338,7 +338,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) we.triggerEnable = false; we.sampleTime = 1; - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("Modified config value: 0x%08x\n", we.dword); err = wltracker_config(wlt, &we); @@ -356,7 +356,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) we = log->config; we.triggerEnable = false; err = wltracker_config(wlt, &we); - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("Restored config value: 0x%08x\n", we.dword); } @@ -394,7 +394,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) (uint64_t)(epoch_ts_us % 1000000ULL)); } - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("%-*i", (int)sizeof("entry#"), i); printf("\n"); @@ -430,7 +430,7 @@ static int wltracker_show_newer_entries(struct wltracker *wlt) void wltracker_run_time_update(struct wltracker *wlt) { wlt->run_time_us = micros() - wlt->start_time_us; - if (nvme_cfg.verbose > 0) + if (nvme_args.verbose > 0) printf("run_time: %lluus\n", wlt->run_time_us); } @@ -525,7 +525,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru join_options(type_options, trk_types, ARRAY_SIZE(trk_types)); join_options(sample_options, samplet, ARRAY_SIZE(samplet)); - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_BYTE("uuid-index", 'U', &wlt.uuid_index, "specify uuid index"), OPT_FLAG("enable", 'e', &cfg.enable, "tracker enable"), OPT_FLAG("disable", 'd', &cfg.disable, "tracker disable"), @@ -541,10 +541,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru OPT_FLAG("trigger-on-delta", 'D', &cfg.trigger_on_delta, "Trigger on delta to stop sampling"), OPT_FLAG("trigger-on-latency", 'L', &cfg.trigger_on_latency, - "Use latency tracker to trigger stop sampling"), - OPT_INCR("verbose", 'v', &nvme_cfg.verbose, "Increase logging verbosity"), - OPT_END() - }; + "Use latency tracker to trigger stop sampling")); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -656,7 +653,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru if (interval > elapsed) { __u64 period_us = min(next_sample_us - wlt.run_time_us, stop_time_us - wlt.run_time_us); - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("Sleeping %lluus..\n", period_us); usleep(period_us); wltracker_run_time_update(&wlt); @@ -671,7 +668,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru if (cfg.disable) { union WorkloadLogEnable we2 = wlt.workload_log.config; - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("Original config value: 0x%08x\n", we2.dword); we2.trackerEnable = false; @@ -684,7 +681,7 @@ int sldgm_get_workload_tracker(int argc, char **argv, struct command *acmd, stru nvme_show_status(err); return err; } - if (nvme_cfg.verbose > 1) + if (nvme_args.verbose > 1) printf("Modified config value: 0x%08x\n", we2.dword); printf("Tracker disabled\n"); return 0; diff --git a/plugins/ssstc/ssstc-nvme.c b/plugins/ssstc/ssstc-nvme.c index 90571f7b1f..0a2468b9d6 100644 --- a/plugins/ssstc/ssstc-nvme.c +++ b/plugins/ssstc/ssstc-nvme.c @@ -402,12 +402,10 @@ int ssstc_get_add_smart_log(int argc, char **argv, struct command *acmd, struct .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_FLAG_JSON("json", 'j', &cfg.json, json), - OPT_END() - }; + OPT_FLAG_JSON("json", 'j', &cfg.json, json)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/toshiba/toshiba-nvme.c b/plugins/toshiba/toshiba-nvme.c index d4b783bbb8..2b0fd926aa 100644 --- a/plugins/toshiba/toshiba-nvme.c +++ b/plugins/toshiba/toshiba-nvme.c @@ -436,12 +436,10 @@ static int vendor_log(int argc, char **argv, struct command *acmd, struct plugin .log = 0xca }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), OPT_FILE("output-file", 'o', &cfg.output_file, output_file), - OPT_UINT("log", 'l', &cfg.log, log), - OPT_END() - }; + OPT_UINT("log", 'l', &cfg.log, log)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -485,11 +483,9 @@ static int internal_log(int argc, char **argv, struct command *acmd, struct plug .prev_log = false }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FILE("output-file", 'o', &cfg.output_file, output_file), - OPT_FLAG("prev-log", 'p', &cfg.prev_log, prev_log), - OPT_END() - }; + OPT_FLAG("prev-log", 'p', &cfg.prev_log, prev_log)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { @@ -526,9 +522,7 @@ static int clear_correctable_errors(int argc, char **argv, struct command *acmd, __u64 result; int err; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { diff --git a/plugins/transcend/transcend-nvme.c b/plugins/transcend/transcend-nvme.c index bd088ed526..e62115fc27 100644 --- a/plugins/transcend/transcend-nvme.c +++ b/plugins/transcend/transcend-nvme.c @@ -26,9 +26,7 @@ static int getHealthValue(int argc, char **argv, struct command *acmd, struct pl _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; int result; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); result = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (result) { @@ -61,9 +59,7 @@ static int getBadblock(int argc, char **argv, struct command *acmd, struct plugi unsigned char data[1] = {0}; int result; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); result = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (result) { diff --git a/plugins/virtium/virtium-nvme.c b/plugins/virtium/virtium-nvme.c index 88ec40db2c..f3fc93251c 100644 --- a/plugins/virtium/virtium-nvme.c +++ b/plugins/virtium/virtium-nvme.c @@ -957,13 +957,11 @@ static int vt_save_smart_to_vtview_log(int argc, char **argv, .test_name = NULL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_DOUBLE("run-time", 'r', &cfg.run_time_hrs, run_time), OPT_DOUBLE("freq", 'f', &cfg.log_record_frequency_hrs, freq), OPT_FILE("output-file", 'o', &cfg.output_file, output_file), - OPT_STRING("test-name", 'n', "NAME", &cfg.test_name, test_name), - OPT_END() - }; + OPT_STRING("test-name", 'n', "NAME", &cfg.test_name, test_name)); vt_generate_vtview_log_file_name(vt_default_log_file_name); @@ -1031,9 +1029,7 @@ static int vt_show_identify(int argc, char **argv, struct command *acmd, struct struct nvme_id_ctrl ctrl; int ret, err = 0; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) { diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index bd4510e1c0..43c363c94f 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -3912,11 +3912,9 @@ static int wdc_cap_diag(int argc, char **argv, struct command *acmd, .xfer_size = 0x10000 }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FILE("output-file", 'o', &cfg.file, file), - OPT_UINT("transfer-size", 's', &cfg.xfer_size, size), - OPT_END() - }; + OPT_UINT("transfer-size", 's', &cfg.xfer_size, size)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -4306,7 +4304,6 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, " NONE - Default, capture without using NVMe telemetry.\n" \ " HOST - Host-initiated telemetry.\n" \ " CONTROLLER - Controller-initiated telemetry."; - const char *verbose = "Display more debug messages."; char f[PATH_MAX] = {0}; char fb[PATH_MAX/2] = {0}; char fileSuffix[PATH_MAX] = {0}; @@ -4329,7 +4326,6 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, __u64 file_size; __u64 offset; char *type; - bool verbose; }; struct config cfg = { @@ -4339,19 +4335,15 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, .file_size = 0, .offset = 0, .type = NULL, - .verbose = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FILE("output-file", 'o', &cfg.file, file), OPT_UINT("transfer-size", 's', &cfg.xfer_size, size), OPT_UINT("data-area", 'd', &cfg.data_area, data_area), OPT_LONG("file-size", 'f', &cfg.file_size, file_size), OPT_LONG("offset", 'e', &cfg.offset, offset), - OPT_FILE("type", 't', &cfg.type, type), - OPT_FLAG("verbose", 'v', &cfg.verbose, verbose), - OPT_END() - }; + OPT_FILE("type", 't', &cfg.type, type)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -4485,7 +4477,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, ret = wdc_do_cap_diag(ctx, hdl, f, xfer_size, telemetry_type, telemetry_data_area); } else { - if (cfg.verbose) + if (nvme_args.verbose) printf("Creating temp directory...\n"); ret = mkdir(fb, 0666); @@ -4494,11 +4486,11 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, goto out; } - ret = dump_internal_logs(hdl, fb, cfg.verbose); + ret = dump_internal_logs(hdl, fb, nvme_args.verbose); if (ret < 0) perror("vs-internal-log"); - if (cfg.verbose) + if (nvme_args.verbose) printf("Archiving...\n"); if (snprintf(cmd_buf, PATH_MAX, @@ -4536,7 +4528,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, xfer_size = 0x40000; ret = wdc_do_cap_dui(hdl, f, xfer_size, cfg.data_area, - cfg.verbose, cfg.file_size, + nvme_args.verbose, cfg.file_size, cfg.offset); goto out; } @@ -4555,7 +4547,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, } else { ret = wdc_do_cap_dui(hdl, f, xfer_size, WDC_NVME_DUI_MAX_DATA_AREA, - cfg.verbose, 0, 0); + nvme_args.verbose, 0, 0); goto out; } } @@ -4719,10 +4711,8 @@ static int wdc_drive_log(int argc, char **argv, struct command *acmd, .file = NULL }; - OPT_ARGS(opts) = { - OPT_FILE("output-file", 'o', &cfg.file, file), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FILE("output-file", 'o', &cfg.file, file)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -4767,10 +4757,8 @@ static int wdc_get_crash_dump(int argc, char **argv, struct command *acmd, .file = NULL, }; - OPT_ARGS(opts) = { - OPT_FILE("output-file", 'o', &cfg.file, file), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FILE("output-file", 'o', &cfg.file, file)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -4810,10 +4798,8 @@ static int wdc_get_pfail_dump(int argc, char **argv, struct command *acmd, .file = NULL, }; - OPT_ARGS(opts) = { - OPT_FILE("output-file", 'o', &cfg.file, file), - OPT_END() - }; + NVME_ARGS(opts, + OPT_FILE("output-file", 'o', &cfg.file, file)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -4892,9 +4878,7 @@ static int wdc_purge(int argc, char **argv, char *err_str; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -4946,9 +4930,7 @@ static int wdc_purge_monitor(int argc, char **argv, __u64 capabilities; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8310,7 +8292,6 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, struct config { uint8_t interval; - char *output_format; __u8 log_page_version; char *log_page_mask; __u32 namespace_id; @@ -8318,20 +8299,16 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, struct config cfg = { .interval = 14, - .output_format = "normal", .log_page_version = 0, .log_page_mask = "", .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("interval", 'i', &cfg.interval, interval), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), OPT_BYTE("log-page-version", 'l', &cfg.log_page_version, log_page_version), OPT_LIST("log-page-mask", 'p', &cfg.log_page_mask, log_page_mask), - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_END() - }; + OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8390,16 +8367,19 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, (page_mask & WDC_C0_PAGE_MASK)) { /* Get 0xC0 log page if possible. */ if (!wdc_is_sn861(device_id)) { - ret = wdc_get_c0_log_page(ctx, hdl, cfg.output_format, - uuid_index, cfg.namespace_id); + ret = wdc_get_c0_log_page(ctx, hdl, + nvme_args.output_format, + uuid_index, cfg.namespace_id); if (ret) fprintf(stderr, "ERROR: WDC: Failure reading the C0 Log Page, ret = %d\n", ret); } else { - ret = validate_output_format(cfg.output_format, &fmt); + ret = validate_output_format(nvme_args.output_format, + &fmt); if (ret < 0) { - fprintf(stderr, "Invalid output format: %s\n", cfg.output_format); + fprintf(stderr, "Invalid output format: %s\n", + nvme_args.output_format); goto out; } @@ -8413,14 +8393,14 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, (page_mask & WDC_CA_PAGE_MASK) && (!wdc_is_sn861(device_id))) { /* Get the CA Log Page */ - ret = wdc_get_ca_log_page(ctx, hdl, cfg.output_format); + ret = wdc_get_ca_log_page(ctx, hdl, nvme_args.output_format); if (ret) fprintf(stderr, "ERROR: WDC: Failure reading the CA Log Page, ret = %d\n", ret); } if (((capabilities & WDC_DRIVE_CAP_C1_LOG_PAGE) == WDC_DRIVE_CAP_C1_LOG_PAGE) && (page_mask & WDC_C1_PAGE_MASK)) { /* Get the C1 Log Page */ - ret = wdc_get_c1_log_page(ctx, hdl, cfg.output_format, + ret = wdc_get_c1_log_page(ctx, hdl, nvme_args.output_format, cfg.interval); if (ret) fprintf(stderr, "ERROR: WDC: Failure reading the C1 Log Page, ret = %d\n", ret); @@ -8428,7 +8408,7 @@ static int wdc_vs_smart_add_log(int argc, char **argv, struct command *acmd, if (((capabilities & WDC_DRIVE_CAP_D0_LOG_PAGE) == WDC_DRIVE_CAP_D0_LOG_PAGE) && (page_mask & WDC_D0_PAGE_MASK)) { /* Get the D0 Log Page */ - ret = wdc_get_d0_log_page(ctx, hdl, cfg.output_format); + ret = wdc_get_d0_log_page(ctx, hdl, nvme_args.output_format); if (ret) fprintf(stderr, "ERROR: WDC: Failure reading the D0 Log Page, ret = %d\n", ret); } @@ -8452,20 +8432,15 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, __u8 *data; struct config { - char *output_format; int uuid_index; }; struct config cfg = { - .output_format = "normal", .uuid_index = 0, }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_UINT("uuid-index", 'u', &cfg.uuid_index, uuid_index), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("uuid-index", 'u', &cfg.uuid_index, uuid_index)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8486,7 +8461,7 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, if (!wdc_check_device(ctx, hdl)) return -1; - ret = validate_output_format(cfg.output_format, &fmt); + ret = validate_output_format(nvme_args.output_format, &fmt); if (ret < 0) { fprintf(stderr, "ERROR: WDC: invalid output format\n"); @@ -8524,7 +8499,7 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, ret = nvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); - if (strcmp(cfg.output_format, "json")) + if (strcmp(nvme_args.output_format, "json")) nvme_show_status(ret); if (!ret) { @@ -8572,11 +8547,8 @@ static int wdc_vs_cloud_log(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8642,11 +8614,8 @@ static int wdc_vs_hw_rev_log(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8733,11 +8702,8 @@ static int wdc_vs_device_waf(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8841,10 +8807,7 @@ static int wdc_get_latency_monitor_log(int argc, char **argv, struct command *ac .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8886,10 +8849,7 @@ static int wdc_get_error_recovery_log(int argc, char **argv, struct command *acm .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8932,10 +8892,7 @@ static int wdc_get_dev_capabilities_log(int argc, char **argv, struct command *a .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -8978,10 +8935,7 @@ static int wdc_get_unsupported_reqs_log(int argc, char **argv, struct command *a .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -9057,9 +9011,7 @@ static int wdc_clear_pcie_correctable_errors(int argc, char **argv, struct comma __u64 capabilities = 0; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -9105,9 +9057,7 @@ static int wdc_drive_status(int argc, char **argv, struct command *acmd, __u64 capabilities = 0; struct nvme_id_uuid_list uuid_list; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -9251,9 +9201,7 @@ static int wdc_clear_assert_dump(int argc, char **argv, struct command *acmd, __u64 capabilities = 0; struct nvme_passthru_cmd admin_cmd; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -9476,10 +9424,7 @@ static int wdc_vs_fw_activate_history(int argc, char **argv, struct command *acm .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -9562,9 +9507,7 @@ static int wdc_clear_fw_activate_history(int argc, char **argv, struct command * _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -9617,12 +9560,10 @@ static int wdc_vs_telemetry_controller_option(int argc, char **argv, struct comm .status = false, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FLAG("disable", 'd', &cfg.disable, disable), OPT_FLAG("enable", 'e', &cfg.enable, enable), - OPT_FLAG("status", 's', &cfg.status, status), - OPT_END() - }; + OPT_FLAG("status", 's', &cfg.status, status)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -10410,10 +10351,8 @@ static int wdc_drive_essentials(int argc, char **argv, struct command *acmd, .dirName = NULL, }; - OPT_ARGS(opts) = { - OPT_STRING("dir-name", 'd', "DIRECTORY", &cfg.dirName, dirName), - OPT_END() - }; + NVME_ARGS(opts, + OPT_STRING("dir-name", 'd', "DIRECTORY", &cfg.dirName, dirName)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); @@ -10509,10 +10448,8 @@ static int wdc_drive_resize(int argc, char **argv, .size = 0, }; - OPT_ARGS(opts) = { - OPT_UINT("size", 's', &cfg.size, size), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("size", 's', &cfg.size, size)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -10559,11 +10496,9 @@ static int wdc_namespace_resize(int argc, char **argv, .op_option = 0xF, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_UINT("op-option", 'o', &cfg.op_option, op_option), - OPT_END() - }; + OPT_UINT("op-option", 'o', &cfg.op_option, op_option)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -10621,11 +10556,9 @@ static int wdc_reason_identifier(int argc, char **argv, .file = NULL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("log-id", 'i', &cfg.log_id, log_id), - OPT_FILE("file", 'o', &cfg.file, fname), - OPT_END() - }; + OPT_FILE("file", 'o', &cfg.file, fname)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); @@ -10883,10 +10816,7 @@ static int wdc_log_page_directory(int argc, char **argv, struct command *acmd, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json|binary"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -11636,10 +11566,7 @@ static int wdc_vs_nand_stats(int argc, char **argv, struct command *acmd, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -11716,10 +11643,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *acmd, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -11806,10 +11730,7 @@ static int wdc_vs_drive_info(int argc, char **argv, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -12059,10 +11980,7 @@ static int wdc_vs_temperature_stats(int argc, char **argv, .output_format = "normal", }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"), - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -12164,9 +12082,7 @@ static int wdc_capabilities(int argc, char **argv, struct command *acmd, struct uint64_t capabilities = 0; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -12271,9 +12187,7 @@ static int wdc_cloud_ssd_plugin_version(int argc, char **argv, struct command *a uint64_t capabilities = 0; int ret; - OPT_ARGS(opts) = { - OPT_END() - }; + NVME_ARGS(opts); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -12317,10 +12231,8 @@ static int wdc_cloud_boot_SSD_version(int argc, char **argv, struct command *acm .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { - OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_END() - }; + NVME_ARGS(opts, + OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (ret) @@ -12383,12 +12295,10 @@ static int wdc_enc_get_log(int argc, char **argv, struct command *acmd, struct p .log_id = 0xffffffff, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_FILE("output-file", 'o', &cfg.file, file), OPT_UINT("transfer-size", 's', &cfg.xfer_size, size), - OPT_UINT("log-id", 'l', &cfg.log_id, log), - OPT_END() - }; + OPT_UINT("log-id", 'l', &cfg.log_id, log)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -12679,7 +12589,7 @@ int wdc_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, .latency_monitor_feature_enable = 0x7, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("active_bucket_timer_threshold", 't', &cfg.active_bucket_timer_threshold, active_bucket_timer_threshold), @@ -12702,9 +12612,7 @@ int wdc_set_latency_monitor_feature(int argc, char **argv, struct command *acmd, discard_debug_log), OPT_UINT("latency_monitor_feature_enable", 'e', &cfg.latency_monitor_feature_enable, - latency_monitor_feature_enable), - OPT_END() - }; + latency_monitor_feature_enable)); ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); diff --git a/plugins/ymtc/ymtc-nvme.c b/plugins/ymtc/ymtc-nvme.c index 945b2315bf..b461e7371d 100644 --- a/plugins/ymtc/ymtc-nvme.c +++ b/plugins/ymtc/ymtc-nvme.c @@ -135,11 +135,9 @@ static int get_additional_smart_log(int argc, char **argv, struct command *acmd, .namespace_id = NVME_NSID_ALL, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace), - OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), - OPT_END() - }; + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index bac0ad4aa4..9c1c1155ae 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -136,24 +136,13 @@ static int id_ctrl(int argc, char **argv, struct command *acmd, struct plugin *p nvme_print_flags_t flags; int err = -1; - struct config { - char *output_format; - }; - - struct config cfg = { - .output_format = "normal", - }; - - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_END() - }; + NVME_ARGS(opts); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return errno; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; @@ -185,29 +174,23 @@ static int id_ns(int argc, char **argv, struct command *acmd, struct plugin *plu int err = -1; struct config { - char *output_format; __u32 namespace_id; bool human_readable; bool vendor_specific; }; - struct config cfg = { - .output_format = "normal", - }; + struct config cfg = { }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_FLAG("vendor-specific", 'v', &cfg.vendor_specific, vendor_specific), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable), - OPT_END() - }; + OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return errno; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; if (cfg.vendor_specific) @@ -245,7 +228,6 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu { const char *zslba = "starting LBA of the zone for this command"; const char *select_all = "send command to all zones"; - const char *timeout = "timeout value, in milliseconds"; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; struct nvme_passthru_cmd cmd; @@ -256,18 +238,14 @@ static int zns_mgmt_send(int argc, char **argv, struct command *acmd, struct plu __u64 zslba; __u32 namespace_id; bool select_all; - __u32 timeout; }; struct config cfg = {}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("start-lba", 's', &cfg.zslba, zslba), - OPT_FLAG("select-all", 'a', &cfg.select_all, select_all), - OPT_UINT("timeout", 't', &cfg.timeout, timeout), - OPT_END() - }; + OPT_FLAG("select-all", 'a', &cfg.select_all, select_all)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -344,7 +322,6 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl const char *zsa = "zone send action"; const char *data_len = "buffer length if data required"; const char *data = "optional file for data (default stdin)"; - const char *timeout = "timeout value, in milliseconds"; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; @@ -360,22 +337,18 @@ static int zone_mgmt_send(int argc, char **argv, struct command *acmd, struct pl __u8 zsa; int data_len; char *file; - __u32 timeout; }; struct config cfg = {}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("start-lba", 's', &cfg.zslba, zslba), OPT_FLAG("zsaso", 'o', &cfg.zsaso, zsaso), OPT_FLAG("select-all", 'a', &cfg.select_all, select_all), OPT_BYTE("zsa", 'z', &cfg.zsa, zsa), OPT_UINT("data-len", 'l', &cfg.data_len, data_len), - OPT_FILE("data", 'd', &cfg.file, data), - OPT_UINT("timeout", 't', &cfg.timeout, timeout), - OPT_END() - }; + OPT_FILE("data", 'd', &cfg.file, data)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -473,7 +446,6 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin const char *zslba = "starting LBA of the zone for this command"; const char *zrwaa = "Allocate Zone Random Write Area to zone"; const char *select_all = "send command to all zones"; - const char *timeout = "timeout value, in milliseconds"; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; struct nvme_passthru_cmd cmd; @@ -484,20 +456,16 @@ static int open_zone(int argc, char **argv, struct command *acmd, struct plugin __u32 namespace_id; bool zrwaa; bool select_all; - __u32 timeout; }; struct config cfg = { }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("start-lba", 's', &cfg.zslba, zslba), OPT_FLAG("zrwaa", 'r', &cfg.zrwaa, zrwaa), - OPT_FLAG("select-all", 'a', &cfg.select_all, select_all), - OPT_UINT("timeout", 't', &cfg.timeout, timeout), - OPT_END() - }; + OPT_FLAG("select-all", 'a', &cfg.select_all, select_all)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -546,7 +514,6 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu const char *zslba = "starting LBA of the zone for this command"; const char *zrwaa = "Allocate Zone Random Write Area to zone"; const char *data = "optional file for zone extension data (default stdin)"; - const char *timeout = "timeout value, in milliseconds"; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; @@ -560,19 +527,15 @@ static int set_zone_desc(int argc, char **argv, struct command *acmd, struct plu bool zrwaa; __u32 namespace_id; char *file; - __u32 timeout; }; struct config cfg = {}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("start-lba", 's', &cfg.zslba, zslba), OPT_FLAG("zrwaa", 'r', &cfg.zrwaa, zrwaa), - OPT_FILE("data", 'd', &cfg.file, data), - OPT_UINT("timeout", 't', &cfg.timeout, timeout), - OPT_END() - }; + OPT_FILE("data", 'd', &cfg.file, data)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -640,7 +603,6 @@ static int zrwa_flush_zone(int argc, char **argv, struct command *acmd, struct p { const char *desc = "Flush Explicit ZRWA Range"; const char *slba = "LBA to flush up to"; - const char *timeout = "timeout value, in milliseconds"; _cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL; _cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL; struct nvme_passthru_cmd cmd; @@ -649,17 +611,13 @@ static int zrwa_flush_zone(int argc, char **argv, struct command *acmd, struct p struct config { __u64 lba; __u32 namespace_id; - __u32 timeout; }; struct config cfg = {}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_SUFFIX("lba", 'l', &cfg.lba, slba), - OPT_UINT("timeout", 't', &cfg.timeout, timeout), - OPT_END() - }; + OPT_SUFFIX("lba", 'l', &cfg.lba, slba)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -704,7 +662,6 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *acmd, struct pl int err = -1; struct config { - char *output_format; __u64 zslba; __u32 namespace_id; __u8 zra; @@ -713,26 +670,21 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *acmd, struct pl __u32 data_len; }; - struct config cfg = { - .output_format = "normal", - }; + struct config cfg = { }; - OPT_ARGS(opts) = { - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("start-lba", 's', &cfg.zslba, zslba), OPT_BYTE("zra", 'z', &cfg.zra, zra), OPT_BYTE("zrasf", 'S', &cfg.zrasf, zrasf), OPT_FLAG("partial", 'p', &cfg.partial, partial), - OPT_UINT("data-len", 'l', &cfg.data_len, data_len), - OPT_END() - }; + OPT_UINT("data-len", 'l', &cfg.data_len, data_len)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return errno; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; @@ -804,7 +756,6 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug struct json_object *zone_list = NULL; struct config { - char *output_format; __u64 zslba; __u32 namespace_id; int num_descs; @@ -815,27 +766,23 @@ static int report_zones(int argc, char **argv, struct command *acmd, struct plug }; struct config cfg = { - .output_format = "normal", .num_descs = -1, }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("start-lba", 's', &cfg.zslba, zslba), OPT_UINT("descs", 'd', &cfg.num_descs, num_descs), OPT_UINT("state", 'S', &cfg.state, state), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), OPT_FLAG("verbose", 'v', &cfg.verbose, verbose), OPT_FLAG("extended", 'e', &cfg.extended, ext), - OPT_FLAG("partial", 'p', &cfg.partial, part), - OPT_END() - }; + OPT_FLAG("partial", 'p', &cfg.partial, part)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return errno; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err; if (cfg.verbose) @@ -992,7 +939,7 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi struct config cfg = {}; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), OPT_SUFFIX("zslba", 's', &cfg.zslba, zslba), OPT_SUFFIX("data-size", 'z', &cfg.data_size, data_size), @@ -1003,9 +950,7 @@ static int zone_append(int argc, char **argv, struct command *acmd, struct plugi OPT_FLAG("force-unit-access", 'f', &cfg.fua, fua), OPT_BYTE("prinfo", 'p', &cfg.prinfo, prinfo), OPT_FLAG("piremap", 'P', &cfg.piremap, piremap), - OPT_FLAG("latency", 't', &cfg.latency, latency), - OPT_END() - }; + OPT_FLAG("latency", 't', &cfg.latency, latency)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) @@ -1152,27 +1097,21 @@ static int changed_zone_list(int argc, char **argv, struct command *acmd, struct int err = -1; struct config { - char *output_format; __u32 namespace_id; bool rae; }; - struct config cfg = { - .output_format = "normal", - }; + struct config cfg = { }; - OPT_ARGS(opts) = { + NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id), - OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("rae", 'r', &cfg.rae, rae), - OPT_END() - }; + OPT_FLAG("rae", 'r', &cfg.rae, rae)); err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts); if (err) return errno; - err = validate_output_format(cfg.output_format, &flags); + err = validate_output_format(nvme_args.output_format, &flags); if (err < 0) return err;