Skip to content

Commit 405f649

Browse files
committed
nvme: add dry-run NVME_ARGS default option
The option is to show command instead of sending. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 71fa5d9 commit 405f649

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

nvme-print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define nvme_print(name, flags, ...) \
2020
do { \
2121
struct print_ops *ops = nvme_print_ops(flags); \
22-
if (ops && ops->name) \
22+
if (ops && ops->name && !nvme_cfg.dry_run) \
2323
ops->name(__VA_ARGS__); \
2424
} while (false)
2525

nvme.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ struct passthru_config {
102102
char *metadata;
103103
bool raw_binary;
104104
bool show_command;
105-
bool dry_run;
106105
bool read;
107106
bool write;
108107
__u8 prefill;
@@ -192,6 +191,7 @@ const char *output_format = "Output format: normal|binary";
192191
#endif /* CONFIG_JSONC */
193192
const char *timeout = "timeout value, in milliseconds";
194193
const char *verbose = "Increase output verbosity";
194+
const char *dry_run = "show command instead of sending";
195195

196196
static const char *app_tag = "app tag for end-to-end PI";
197197
static const char *app_tag_mask = "app tag mask for end-to-end PI";
@@ -201,7 +201,6 @@ static const char *csi = "command set identifier";
201201
static const char *buf_len = "buffer len (if) data is sent or received";
202202
static const char *domainid = "Domain Identifier";
203203
static const char *doper = "directive operation";
204-
static const char *dry = "show command instead of sending";
205204
static const char *dspec_w_dtype = "directive specification associated with directive type";
206205
static const char *dtype = "directive type";
207206
static const char *endgid = "Endurance Group Identifier (ENDGID)";
@@ -445,6 +444,8 @@ static int parse_args(int argc, char *argv[], const char *desc,
445444
log_level = map_log_level(nvme_cfg.verbose, false);
446445
nvme_init_default_logging(stderr, log_level, false, false);
447446

447+
set_dry_run(nvme_cfg.dry_run);
448+
448449
return 0;
449450
}
450451

@@ -8051,7 +8052,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
80518052
__u16 dspec;
80528053
__u8 dsmgmt;
80538054
bool show;
8054-
bool dry_run;
80558055
bool latency;
80568056
bool force;
80578057
};
@@ -8076,7 +8076,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
80768076
.dspec = 0,
80778077
.dsmgmt = 0,
80788078
.show = false,
8079-
.dry_run = false,
80808079
.latency = false,
80818080
.force = false,
80828081
};
@@ -8101,7 +8100,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
81018100
OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec),
81028101
OPT_BYTE("dsm", 'D', &cfg.dsmgmt, dsm),
81038102
OPT_FLAG("show-command", 'V', &cfg.show, show),
8104-
OPT_FLAG("dry-run", 'w', &cfg.dry_run, dry),
81058103
OPT_FLAG("latency", 't', &cfg.latency, latency),
81068104
OPT_FLAG("force", 0, &cfg.force, force));
81078105

@@ -8277,7 +8275,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82778275
}
82788276
}
82798277

8280-
if (cfg.show || cfg.dry_run) {
8278+
if (cfg.show || nvme_cfg.dry_run) {
82818279
printf("opcode : %02x\n", opcode);
82828280
printf("nsid : %02x\n", cfg.namespace_id);
82838281
printf("flags : %02x\n", 0);
@@ -8295,7 +8293,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82958293
printf("pif : %02x\n", pif);
82968294
printf("sts : %02x\n", sts);
82978295
}
8298-
if (cfg.dry_run)
8296+
if (nvme_cfg.dry_run)
82998297
return 0;
83008298

83018299
struct nvme_io_args args = {
@@ -9058,7 +9056,6 @@ static int passthru(int argc, char **argv, bool admin,
90589056
.metadata = "",
90599057
.raw_binary = false,
90609058
.show_command = false,
9061-
.dry_run = false,
90629059
.read = false,
90639060
.write = false,
90649061
.latency = false,
@@ -9084,7 +9081,6 @@ static int passthru(int argc, char **argv, bool admin,
90849081
OPT_FILE("metadata", 'M', &cfg.metadata, metadata),
90859082
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump),
90869083
OPT_FLAG("show-command", 's', &cfg.show_command, show),
9087-
OPT_FLAG("dry-run", 'd', &cfg.dry_run, dry),
90889084
OPT_FLAG("read", 'r', &cfg.read, re),
90899085
OPT_FLAG("write", 'w', &cfg.write, wr),
90909086
OPT_FLAG("latency", 'T', &cfg.latency, latency));
@@ -9161,7 +9157,7 @@ static int passthru(int argc, char **argv, bool admin,
91619157
}
91629158
}
91639159

9164-
if (cfg.show_command || cfg.dry_run) {
9160+
if (cfg.show_command || nvme_cfg.dry_run) {
91659161
printf("opcode : %02x\n", cfg.opcode);
91669162
printf("flags : %02x\n", cfg.flags);
91679163
printf("rsvd1 : %04x\n", cfg.rsvd);
@@ -9180,7 +9176,7 @@ static int passthru(int argc, char **argv, bool admin,
91809176
printf("cdw15 : %08x\n", cfg.cdw15);
91819177
printf("timeout_ms : %08x\n", nvme_cfg.timeout);
91829178
}
9183-
if (cfg.dry_run)
9179+
if (nvme_cfg.dry_run)
91849180
return 0;
91859181

91869182
gettimeofday(&start_time, NULL);

nvme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct nvme_config {
7878
char *output_format;
7979
int verbose;
8080
__u32 timeout;
81+
bool dry_run;
8182
};
8283

8384
/*
@@ -90,6 +91,7 @@ struct nvme_config {
9091
OPT_FMT("output-format", 'o', &nvme_cfg.output_format, output_format), \
9192
##__VA_ARGS__, \
9293
OPT_UINT("timeout", 't', &nvme_cfg.timeout, timeout), \
94+
OPT_FLAG("dry-run", 'd', &nvme_cfg.dry_run, dry_run), \
9395
OPT_END() \
9496
}
9597

@@ -131,6 +133,7 @@ static inline DEFINE_CLEANUP_FUNC(
131133
extern const char *output_format;
132134
extern const char *timeout;
133135
extern const char *verbose;
136+
extern const char *dry_run;
134137
extern struct nvme_config nvme_cfg;
135138

136139
int validate_output_format(const char *format, nvme_print_flags_t *flags);

util/logging.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "logging.h"
1414

1515
int log_level;
16+
static bool dry_run;
1617

1718
int map_log_level(int verbose, bool quiet)
1819
{
@@ -44,6 +45,11 @@ int map_log_level(int verbose, bool quiet)
4445
return log_level;
4546
}
4647

48+
void set_dry_run(bool enable)
49+
{
50+
dry_run = enable;
51+
}
52+
4753
static void nvme_show_common(struct nvme_passthru_cmd *cmd)
4854
{
4955
printf("opcode : %02x\n", cmd->opcode);
@@ -91,14 +97,17 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
9197
{
9298
struct timeval start;
9399
struct timeval end;
94-
int err;
100+
int err = 0;
95101

96-
if (log_level >= LOG_DEBUG)
102+
if (log_level >= LOG_DEBUG || dry_run)
97103
gettimeofday(&start, NULL);
98104

99-
err = ioctl(fd, ioctl_cmd, cmd);
105+
if (dry_run)
106+
cmd->result = 0;
107+
else
108+
err = ioctl(fd, ioctl_cmd, cmd);
100109

101-
if (log_level >= LOG_DEBUG) {
110+
if (log_level >= LOG_DEBUG || dry_run) {
102111
gettimeofday(&end, NULL);
103112
nvme_show_command(cmd, err);
104113
nvme_show_latency(start, end);
@@ -116,15 +125,17 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
116125
{
117126
struct timeval start;
118127
struct timeval end;
119-
int err;
128+
int err = 0;
120129

121-
if (log_level >= LOG_DEBUG)
130+
if (log_level >= LOG_DEBUG || dry_run)
122131
gettimeofday(&start, NULL);
123132

133+
if (dry_run)
134+
cmd->result = 0;
135+
else
136+
err = ioctl(fd, ioctl_cmd, cmd);
124137

125-
err = ioctl(fd, ioctl_cmd, cmd);
126-
127-
if (log_level >= LOG_DEBUG) {
138+
if (log_level >= LOG_DEBUG || dry_run) {
128139
gettimeofday(&end, NULL);
129140
nvme_show_command64(cmd, err);
130141
nvme_show_latency(start, end);

util/logging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
extern int log_level;
2121

2222
int map_log_level(int verbose, bool quiet);
23+
void set_dry_run(bool enable);
2324

2425
#endif // DEBUG_H_

0 commit comments

Comments
 (0)