From 80b126032c7e73d273bc883e973b5f1a94aac581 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 5 Aug 2024 10:38:39 +0200 Subject: Merging upstream version 2.10. Signed-off-by: Daniel Baumann --- nvme.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'nvme.h') diff --git a/nvme.h b/nvme.h index 7e86afc..cae4345 100644 --- a/nvme.h +++ b/nvme.h @@ -33,13 +33,15 @@ #include "util/cleanup.h" enum nvme_print_flags { - NORMAL = 0, - VERBOSE = 1 << 0, /* verbosely decode complex values for humans */ - JSON = 1 << 1, /* display in json format */ - VS = 1 << 2, /* hex dump vendor specific data areas */ - BINARY = 1 << 3, /* binary dump raw bytes */ + NORMAL = 0, + VERBOSE = 1 << 0, /* verbosely decode complex values for humans */ + JSON = 1 << 1, /* display in json format */ + VS = 1 << 2, /* hex dump vendor specific data areas */ + BINARY = 1 << 3, /* binary dump raw bytes */ }; +typedef uint32_t nvme_print_flags_t; + enum nvme_cli_topo_ranking { NVME_CLI_TOPO_NAMESPACE, NVME_CLI_TOPO_CTRL, @@ -71,6 +73,25 @@ struct nvme_dev { #define dev_fd(d) __dev_fd(d, __func__, __LINE__) +struct nvme_config { + char *output_format; + int verbose; + __u32 timeout; +}; + +/* + * 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), \ + ##__VA_ARGS__, \ + OPT_UINT("timeout", 't', &nvme_cfg.timeout, timeout), \ + OPT_END() \ + } + static inline int __dev_fd(struct nvme_dev *dev, const char *func, int line) { if (dev->type != NVME_DEV_DIRECT) { @@ -107,8 +128,11 @@ static inline DEFINE_CLEANUP_FUNC( #define _cleanup_nvme_dev_ __cleanup__(cleanup_nvme_dev) extern const char *output_format; +extern const char *timeout; +extern const char *verbose; +extern struct nvme_config nvme_cfg; -int validate_output_format(const char *format, enum nvme_print_flags *flags); +int validate_output_format(const char *format, nvme_print_flags_t *flags); bool nvme_is_output_format_json(void); int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(uint8_t *vs, struct json_object *root)); -- cgit v1.2.3