Skip to content

Commit abe29d0

Browse files
committed
nvme: replace OPT_ARGS with NVME_ARGS
The global command lines arguments should be used for every command, so that we have a consistent user experience. Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 438ea90 commit abe29d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+488
-1019
lines changed

nvme-rpmb.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,17 +855,15 @@ int rpmb_cmd_option(int argc, char **argv, struct command *acmd, struct plugin *
855855
.target = 0,
856856
};
857857

858-
OPT_ARGS(opts) = {
858+
NVME_ARGS(opts,
859859
OPT_STRING("cmd", 'c', "command", &cfg.cmd, opt),
860860
OPT_STRING("msgfile", 'f', "FILE", &cfg.msgfile, mfile),
861861
OPT_STRING("keyfile", 'g', "FILE", &cfg.keyfile, kfile),
862862
OPT_STRING("key", 'k', "key", &cfg.key, key),
863863
OPT_STRING("msg", 'd', "data", &cfg.msg, msg),
864864
OPT_UINT("address", 'o', &cfg.address, address),
865865
OPT_UINT("blocks", 'b', &cfg.blocks, blocks),
866-
OPT_UINT("target", 't', &cfg.target, target),
867-
OPT_END()
868-
};
866+
OPT_UINT("target", 't', &cfg.target, target));
869867

870868
_cleanup_free_ unsigned char *key_buf = NULL;
871869
_cleanup_free_ unsigned char *msg_buf = NULL;

nvme.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,6 @@ static struct program nvme = {
183183
.extensions = &builtin,
184184
};
185185

186-
#ifdef CONFIG_JSONC
187-
const char *output_format = "Output format: normal|json|binary";
188-
#else /* CONFIG_JSONC */
189-
const char *output_format = "Output format: normal|binary";
190-
#endif /* CONFIG_JSONC */
191-
const char *timeout = "timeout value, in milliseconds";
192-
const char *verbose = "Increase output verbosity";
193-
const char *dry_run = "show command instead of sending";
194186
const char *uuid_index = "UUID index";
195187

196188
static const char *app_tag = "app tag for end-to-end PI";
@@ -8434,7 +8426,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
84348426
OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec),
84358427
OPT_BYTE("dsm", 'D', &cfg.dsmgmt, dsm),
84368428
OPT_FLAG("show-command", 'V', &cfg.show, show),
8437-
OPT_FLAG("dry-run", 'w', &nvme_args.dry_run, dry_run),
84388429
OPT_FLAG("latency", 't', &cfg.latency, latency),
84398430
OPT_FLAG("force", 0, &cfg.force, force));
84408431

@@ -9351,7 +9342,6 @@ static int passthru(int argc, char **argv, bool admin,
93519342
OPT_FILE("metadata", 'M', &cfg.metadata, metadata),
93529343
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump),
93539344
OPT_FLAG("show-command", 's', &cfg.show_command, show),
9354-
OPT_FLAG("dry-run", 'd', &nvme_args.dry_run, dry_run),
93559345
OPT_FLAG("read", 'r', &cfg.read, re),
93569346
OPT_FLAG("write", 'w', &cfg.write, wr),
93579347
OPT_FLAG("latency", 'T', &cfg.latency, latency));
@@ -10352,7 +10342,6 @@ static int tls_key(int argc, char **argv, struct command *acmd, struct plugin *p
1035210342
static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct plugin *plugin)
1035310343
{
1035410344
const char *desc = "Show the topology\n";
10355-
const char *output_format = "Output format: normal|json|binary|tabular";
1035610345
const char *ranking = "Ranking order: namespace|ctrl|multipath";
1035710346
nvme_print_flags_t flags;
1035810347
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;

nvme.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,27 @@ struct nvme_args {
6262
unsigned int output_format_ver;
6363
};
6464

65+
#ifdef CONFIG_JSONC
66+
#define DESC_OUTPUT_FORMAT "Output format: normal|json|binary|tabular"
67+
#else /* CONFIG_JSONC */
68+
#define DESC_OUTPUT_FORMAT "Output format: normal|binary|tabular"
69+
#endif /* CONFIG_JSONC */
70+
6571
/*
6672
* the ordering of the arguments matters, as the argument parser uses the first match, thus any
6773
* command which defines -t shorthand will match first.
6874
*/
6975
#define NVME_ARGS(n, ...) \
7076
struct argconfig_commandline_options n[] = { \
71-
OPT_INCR("verbose", 'v', &nvme_args.verbose, verbose), \
72-
OPT_FMT("output-format", 'o', &nvme_args.output_format, output_format), \
77+
OPT_INCR("verbose", 'v', &nvme_args.verbose, \
78+
"Increase output verbosity"), \
79+
OPT_FMT("output-format", 'o', &nvme_args.output_format, \
80+
DESC_OUTPUT_FORMAT), \
7381
##__VA_ARGS__, \
74-
OPT_UINT("timeout", 't', &nvme_args.timeout, timeout), \
75-
OPT_FLAG("dry-run", 0, &nvme_args.dry_run, dry_run), \
82+
OPT_UINT("timeout", 't', &nvme_args.timeout, \
83+
"timeout value, in milliseconds"), \
84+
OPT_FLAG("dry-run", 0, &nvme_args.dry_run, \
85+
"show command instead of executing"), \
7686
OPT_FLAG("no-retries", 0, &nvme_args.no_retries, \
7787
"disable retry logic on errors"), \
7888
OPT_FLAG("no-ioctl-probing", 0, &nvme_args.no_ioctl_probing, \
@@ -108,10 +118,6 @@ static inline DEFINE_CLEANUP_FUNC(
108118
cleanup_nvme_transport_handle, struct nvme_transport_handle *, nvme_close)
109119
#define _cleanup_nvme_transport_handle_ __cleanup__(cleanup_nvme_transport_handle)
110120

111-
extern const char *output_format;
112-
extern const char *timeout;
113-
extern const char *verbose;
114-
extern const char *dry_run;
115121
extern const char *uuid_index;
116122
extern struct nvme_args nvme_args;
117123

plugins/amzn/amzn-nvme.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,8 @@ static int get_stats(int argc, char **argv, struct command *acmd,
485485
.output_format = "normal",
486486
};
487487

488-
OPT_ARGS(opts) = {
489-
OPT_FMT("output-format", 'o', &cfg.output_format,
490-
"Output Format: normal|json"),
491-
OPT_FLAG("details", 'd', &detail, "Detail IO histogram of each block size ranges"),
492-
OPT_END()};
488+
NVME_ARGS(opts,
489+
OPT_FLAG("details", 'd', &detail, "Detail IO histogram of each block size ranges"));
493490

494491
rc = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
495492
if (rc)

plugins/dapustor/dapustor-nvme.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command *
513513
struct nvme_extended_additional_smart_log ext_smart_log;
514514
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
515515
struct nvme_additional_smart_log smart_log;
516+
nvme_print_flags_t flags;
516517
bool has_ext = false;
517518
int err;
518519

@@ -526,21 +527,25 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command *
526527
.namespace_id = NVME_NSID_ALL,
527528
};
528529

529-
OPT_ARGS(opts) = {
530+
NVME_ARGS(opts,
530531
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace),
531532
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
532-
OPT_FLAG_JSON("json", 'j', &cfg.json, json),
533-
OPT_END()
534-
};
533+
OPT_FLAG_JSON("json", 'j', &cfg.json, json));
535534

536535
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
537536
if (err)
538537
return err;
539538

539+
err = validate_output_format(nvme_args.output_format, &flags);
540+
if (err < 0) {
541+
nvme_show_error("Invalid output format");
542+
return err;
543+
}
544+
540545
err = dapustor_additional_smart_log_data(hdl, &smart_log,
541546
&ext_smart_log, &has_ext);
542547
if (!err) {
543-
if (cfg.json)
548+
if (flags & JSON || cfg.json)
544549
show_dapustor_smart_log_jsn(&smart_log, &ext_smart_log,
545550
cfg.namespace_id,
546551
nvme_transport_handle_get_name(hdl),

plugins/dera/dera-nvme.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ static int get_status(int argc, char **argv, struct command *acmd, struct plugin
123123
struct nvme_dera_smart_info_log log;
124124
int err;
125125

126-
OPT_ARGS(opts) = {
127-
OPT_END()
128-
};
126+
NVME_ARGS(opts);
129127

130128
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
131129
if (err)

plugins/fdp/fdp.c

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,25 @@ static int fdp_configs(int argc, char **argv, struct command *acmd,
3434

3535
struct config {
3636
__u16 egid;
37-
char *output_format;
3837
bool human_readable;
3938
bool raw_binary;
4039
};
4140

4241
struct config cfg = {
4342
.egid = 0,
44-
.output_format = "normal",
4543
.raw_binary = false,
4644
};
4745

48-
OPT_ARGS(opts) = {
46+
NVME_ARGS(opts,
4947
OPT_UINT("endgrp-id", 'e', &cfg.egid, egid),
50-
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
5148
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
52-
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable),
53-
OPT_END()
54-
};
49+
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable));
5550

5651
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
5752
if (err)
5853
return err;
5954

60-
err = validate_output_format(cfg.output_format, &flags);
55+
err = validate_output_format(nvme_args.output_format, &flags);
6156
if (err < 0)
6257
return err;
6358

@@ -116,22 +111,18 @@ static int fdp_usage(int argc, char **argv, struct command *acmd, struct plugin
116111

117112
struct config cfg = {
118113
.egid = 0,
119-
.output_format = "normal",
120114
.raw_binary = false,
121115
};
122116

123-
OPT_ARGS(opts) = {
117+
NVME_ARGS(opts,
124118
OPT_UINT("endgrp-id", 'e', &cfg.egid, egid),
125-
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
126-
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
127-
OPT_END()
128-
};
119+
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw));
129120

130121
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
131122
if (err)
132123
return err;
133124

134-
err = validate_output_format(cfg.output_format, &flags);
125+
err = validate_output_format(nvme_args.output_format, &flags);
135126
if (err < 0)
136127
return err;
137128

@@ -186,12 +177,9 @@ static int fdp_stats(int argc, char **argv, struct command *acmd, struct plugin
186177
.raw_binary = false,
187178
};
188179

189-
OPT_ARGS(opts) = {
180+
NVME_ARGS(opts,
190181
OPT_UINT("endgrp-id", 'e', &cfg.egid, egid),
191-
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
192-
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
193-
OPT_END()
194-
};
182+
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw));
195183

196184
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
197185
if (err)
@@ -238,30 +226,25 @@ static int fdp_events(int argc, char **argv, struct command *acmd, struct plugin
238226
struct config {
239227
__u16 egid;
240228
bool host_events;
241-
char *output_format;
242229
bool raw_binary;
243230
};
244231

245232
struct config cfg = {
246233
.egid = 0,
247234
.host_events = false,
248-
.output_format = "normal",
249235
.raw_binary = false,
250236
};
251237

252-
OPT_ARGS(opts) = {
238+
NVME_ARGS(opts,
253239
OPT_UINT("endgrp-id", 'e', &cfg.egid, egid),
254240
OPT_FLAG("host-events", 'E', &cfg.host_events, host_events),
255-
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
256-
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
257-
OPT_END()
258-
};
241+
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw));
259242

260243
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
261244
if (err)
262245
return err;
263246

264-
err = validate_output_format(cfg.output_format, &flags);
247+
err = validate_output_format(nvme_args.output_format, &flags);
265248
if (err < 0)
266249
return err;
267250

@@ -304,27 +287,22 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin
304287

305288
struct config {
306289
__u32 nsid;
307-
char *output_format;
308290
bool raw_binary;
309291
};
310292

311293
struct config cfg = {
312-
.output_format = "normal",
313294
.raw_binary = false,
314295
};
315296

316-
OPT_ARGS(opts) = {
317-
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id),
318-
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
319-
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
320-
OPT_END()
321-
};
297+
NVME_ARGS(opts,
298+
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id),
299+
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw));
322300

323301
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
324302
if (err)
325303
return err;
326304

327-
err = validate_output_format(cfg.output_format, &flags);
305+
err = validate_output_format(nvme_args.output_format, &flags);
328306
if (err < 0)
329307
return err;
330308

@@ -388,11 +366,9 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin
388366
.pids = "",
389367
};
390368

391-
OPT_ARGS(opts) = {
369+
NVME_ARGS(opts,
392370
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id),
393-
OPT_LIST("pids", 'p', &cfg.pids, _pids),
394-
OPT_END()
395-
};
371+
OPT_LIST("pids", 'p', &cfg.pids, _pids));
396372

397373
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
398374
if (err)
@@ -459,14 +435,12 @@ static int fdp_set_events(int argc, char **argv, struct command *acmd, struct pl
459435
.sv = false,
460436
};
461437

462-
OPT_ARGS(opts) = {
438+
NVME_ARGS(opts,
463439
OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid),
464440
OPT_SHRT("placement-handle", 'p', &cfg.ph, ph),
465441
OPT_FLAG("enable", 'e', &cfg.enable, enable),
466442
OPT_FLAG("save", 's', &cfg.sv, sv),
467-
OPT_LIST("event-types", 't', &cfg.event_types, event_types),
468-
OPT_END()
469-
};
443+
OPT_LIST("event-types", 't', &cfg.event_types, event_types));
470444

471445
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
472446
if (err)
@@ -537,13 +511,10 @@ static int fdp_feature(int argc, char **argv, struct command *acmd, struct plugi
537511
.endgid = 0,
538512
};
539513

540-
OPT_ARGS(opts) = {
514+
NVME_ARGS(opts,
541515
OPT_SHRT("endgrp-id", 'e', &cfg.endgid, endurance_group),
542516
OPT_BYTE("enable-conf-idx", 'c', &cfg.fdpcidx, enable_conf_idx),
543-
OPT_FLAG("disable", 'd', &cfg.disable, disable),
544-
OPT_INCR("verbose", 'v', &nvme_args.verbose, verbose),
545-
OPT_END()
546-
};
517+
OPT_FLAG("disable", 'd', &cfg.disable, disable));
547518

548519
err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
549520
if (err)

plugins/huawei/huawei-nvme.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,8 @@ static int huawei_list(int argc, char **argv, struct command *acmd,
303303
unsigned int huawei_num = 0;
304304
nvme_print_flags_t fmt;
305305
const char *desc = "Retrieve basic information for the given huawei device";
306-
struct config {
307-
char *output_format;
308-
};
309306

310-
struct config cfg = {
311-
.output_format = "normal",
312-
};
313-
314-
OPT_ARGS(opts) = {
315-
OPT_FMT("output-format", 'o', &cfg.output_format, "Output Format: normal|json"),
316-
OPT_END()
317-
};
307+
NVME_ARGS(opts);
318308

319309
if (!ctx)
320310
return -ENOMEM;
@@ -323,7 +313,7 @@ static int huawei_list(int argc, char **argv, struct command *acmd,
323313
if (ret)
324314
return ret;
325315

326-
ret = validate_output_format(cfg.output_format, &fmt);
316+
ret = validate_output_format(nvme_args.output_format, &fmt);
327317
if (ret < 0 || (fmt != JSON && fmt != NORMAL))
328318
return ret;
329319

0 commit comments

Comments
 (0)