Skip to content

Commit a01143a

Browse files
committed
nvme: move submit_io show-command and dry-run outputs into logging
Also latency output moved into logging as same. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent e1882cd commit a01143a

3 files changed

Lines changed: 46 additions & 29 deletions

File tree

nvme.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8009,7 +8009,6 @@ unsigned long long elapsed_utime(struct timeval start_time,
80098009

80108010
static int submit_io(int opcode, char *command, const char *desc, int argc, char **argv)
80118011
{
8012-
struct timeval start_time, end_time;
80138012
void *buffer;
80148013
_cleanup_free_ void *mbuffer = NULL;
80158014
int err = 0;
@@ -8285,27 +8284,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
82858284
}
82868285
}
82878286

8288-
if (cfg.show || nvme_cfg.dry_run) {
8289-
printf("opcode : %02x\n", opcode);
8290-
printf("nsid : %02x\n", cfg.namespace_id);
8291-
printf("flags : %02x\n", 0);
8292-
printf("control : %04x\n", control);
8293-
printf("nblocks : %04x\n", nblocks);
8294-
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)mbuffer);
8295-
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)buffer);
8296-
printf("slba : %"PRIx64"\n", (uint64_t)cfg.start_block);
8297-
printf("dsmgmt : %08x\n", dsmgmt);
8298-
printf("reftag : %"PRIx64"\n", (uint64_t)cfg.ref_tag);
8299-
printf("apptag : %04x\n", cfg.app_tag);
8300-
printf("appmask : %04x\n", cfg.app_tag_mask);
8301-
printf("storagetagcheck : %04x\n", cfg.storage_tag_check);
8302-
printf("storagetag : %"PRIx64"\n", (uint64_t)cfg.storage_tag);
8303-
printf("pif : %02x\n", pif);
8304-
printf("sts : %02x\n", sts);
8305-
}
8306-
if (nvme_cfg.dry_run)
8307-
return 0;
8308-
83098287
struct nvme_io_args args = {
83108288
.args_size = sizeof(args),
83118289
.fd = dev_fd(dev),
@@ -8329,16 +8307,13 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
83298307
.timeout = nvme_cfg.timeout,
83308308
.result = NULL,
83318309
};
8332-
gettimeofday(&start_time, NULL);
8333-
err = nvme_io(&args, opcode);
8334-
gettimeofday(&end_time, NULL);
8335-
if (cfg.latency)
8336-
printf(" latency: %s: %llu us\n", command, elapsed_utime(start_time, end_time));
8310+
8311+
err = nvme_submit_io(&args, opcode, cfg.show, cfg.latency);
83378312
if (err < 0) {
83388313
nvme_show_error("submit-io: %s", nvme_strerror(errno));
83398314
} else if (err) {
83408315
nvme_show_status(err);
8341-
} else {
8316+
} else if (!nvme_cfg.dry_run) {
83428317
if (!(opcode & 1) && write(dfd, (void *)buffer, buffer_size) < 0) {
83438318
nvme_show_error("write: %s: failed to write buffer to output file",
83448319
strerror(errno));

util/logging.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,45 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
150150

151151
return err;
152152
}
153+
154+
static void nvme_show_io_command(struct nvme_io_args *args, __u8 opcode)
155+
{
156+
printf("opcode : %02x\n", opcode);
157+
printf("nsid : %02x\n", args->nsid);
158+
printf("flags : %02x\n", 0);
159+
printf("control : %04x\n", args->control);
160+
printf("nblocks : %04x\n", args->nlb);
161+
printf("metadata : %"PRIx64"\n", (uint64_t)args->metadata);
162+
printf("addr : %"PRIx64"\n", (uint64_t)args->data);
163+
printf("slba : %"PRIx64"\n", (uint64_t)args->slba);
164+
printf("dsmgmt : %08x\n", args->dsm);
165+
printf("reftag : %"PRIx64"\n", (uint64_t)args->reftag_u64);
166+
printf("apptag : %04x\n", args->apptag);
167+
printf("appmask : %04x\n", args->appmask);
168+
printf("storagetagcheck : %04x\n", args->control | NVME_IO_STC ? true : false);
169+
printf("storagetag : %"PRIx64"\n", (uint64_t)args->storage_tag);
170+
printf("pif : %02x\n", args->pif);
171+
printf("sts : %02x\n", args->sts);
172+
}
173+
174+
int nvme_submit_io(struct nvme_io_args *args, __u8 opcode, bool show, bool latency)
175+
{
176+
struct timeval start_time;
177+
struct timeval end_time;
178+
int err;
179+
180+
if (show || dry_run)
181+
nvme_show_io_command(args, opcode);
182+
183+
if (dry_run)
184+
return 0;
185+
186+
gettimeofday(&start_time, NULL);
187+
err = nvme_io(args, opcode);
188+
gettimeofday(&end_time, NULL);
189+
190+
if (latency)
191+
nvme_show_latency(start_time, end_time);
192+
193+
return err;
194+
}

util/logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ extern int log_level;
2121

2222
int map_log_level(int verbose, bool quiet);
2323
void set_dry_run(bool enable);
24-
24+
int nvme_submit_io(struct nvme_io_args *args, __u8 opcode, bool show, bool latency);
2525
#endif // DEBUG_H_

0 commit comments

Comments
 (0)