Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -8009,15 +8009,13 @@ unsigned long long elapsed_utime(struct timeval start_time,

static int submit_io(int opcode, char *command, const char *desc, int argc, char **argv)
{
struct timeval start_time, end_time;
void *buffer;
_cleanup_free_ void *mbuffer = NULL;
int err = 0;
_cleanup_fd_ int dfd = -1, mfd = -1;
int flags, pi_size;
int mode = 0644;
__u16 control = 0, nblocks = 0;
__u32 dsmgmt = 0;
unsigned int logical_block_size = 0;
unsigned long long buffer_size = 0, mbuffer_size = 0;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
Expand Down Expand Up @@ -8147,7 +8145,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
if (cfg.prinfo > 0xf)
return err;

dsmgmt = cfg.dsmgmt;
control |= (cfg.prinfo << 10);
if (cfg.limited_retry)
control |= NVME_IO_LR;
Expand All @@ -8161,7 +8158,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
return -EINVAL;
}
control |= cfg.dtype << 4;
dsmgmt |= ((__u32)cfg.dspec) << 16;
}

if (opcode & 1) {
Expand Down Expand Up @@ -8285,27 +8281,6 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
}
}

if (cfg.show || nvme_cfg.dry_run) {
printf("opcode : %02x\n", opcode);
printf("nsid : %02x\n", cfg.namespace_id);
printf("flags : %02x\n", 0);
printf("control : %04x\n", control);
printf("nblocks : %04x\n", nblocks);
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)mbuffer);
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)buffer);
printf("slba : %"PRIx64"\n", (uint64_t)cfg.start_block);
printf("dsmgmt : %08x\n", dsmgmt);
printf("reftag : %"PRIx64"\n", (uint64_t)cfg.ref_tag);
printf("apptag : %04x\n", cfg.app_tag);
printf("appmask : %04x\n", cfg.app_tag_mask);
printf("storagetagcheck : %04x\n", cfg.storage_tag_check);
printf("storagetag : %"PRIx64"\n", (uint64_t)cfg.storage_tag);
printf("pif : %02x\n", pif);
printf("sts : %02x\n", sts);
}
if (nvme_cfg.dry_run)
return 0;

struct nvme_io_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
Expand All @@ -8329,16 +8304,13 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
.timeout = nvme_cfg.timeout,
.result = NULL,
};
gettimeofday(&start_time, NULL);
err = nvme_io(&args, opcode);
gettimeofday(&end_time, NULL);
if (cfg.latency)
printf(" latency: %s: %llu us\n", command, elapsed_utime(start_time, end_time));

err = nvme_submit_io(&args, opcode, cfg.show, cfg.latency);
if (err < 0) {
nvme_show_error("submit-io: %s", nvme_strerror(errno));
} else if (err) {
nvme_show_status(err);
} else {
} else if (!nvme_cfg.dry_run) {
if (!(opcode & 1) && write(dfd, (void *)buffer, buffer_size) < 0) {
nvme_show_error("write: %s: failed to write buffer to output file",
strerror(errno));
Expand Down
48 changes: 48 additions & 0 deletions util/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,51 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,

return err;
}

static void nvme_show_io_command(struct nvme_io_args *args, __u8 opcode)
{
__u32 dsmgmt = args->dsm;
__u8 dtype = (args->control >> 4) & 0xf;

if (dtype)
dsmgmt |= ((__u32)args->dspec) << 16;

printf("opcode : %02x\n", opcode);
printf("nsid : %02x\n", args->nsid);
printf("flags : %02x\n", 0);
printf("control : %04x\n", args->control);
printf("nblocks : %04x\n", args->nlb);
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)args->metadata);
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)args->data);
printf("slba : %"PRIx64"\n", (uint64_t)(uintptr_t)args->slba);
printf("dsmgmt : %08x\n", dsmgmt);
printf("reftag : %"PRIx64"\n", (uint64_t)args->reftag_u64);
printf("apptag : %04x\n", args->apptag);
printf("appmask : %04x\n", args->appmask);
printf("storagetagcheck : %04x\n", args->control & NVME_IO_STC ? true : false);
printf("storagetag : %"PRIx64"\n", (uint64_t)args->storage_tag);
printf("pif : %02x\n", args->pif);
printf("sts : %02x\n", args->sts);
}

int nvme_submit_io(struct nvme_io_args *args, __u8 opcode, bool show, bool latency)
Copy link
Copy Markdown
Collaborator

@igaw igaw Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest instead adding more indirect code for the logging, we could just look at the opcode in nvme_show_command, e.g.

static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err)
{
	switch (cmd->opcode) {
		case nvme_cmd_read:
		case nvme_cmd_write:
		case nvme_cmd_compare:
			nvme_show_io_command(cmd);
			break;
		default:
			nvme_show_common(cmd);
	}
	printf("result       : %08x\n", cmd->result);
	printf("err          : %d\n", err);
}

{
struct timeval start_time;
struct timeval end_time;
int err;

if (show || dry_run)
nvme_show_io_command(args, opcode);

if (dry_run)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then the dry_run maybe should be

int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
			 struct nvme_passthru_cmd *cmd, __u32 *result)
{
	struct timeval start;
	struct timeval end;
	int err = 0;

	if (log_level >= LOG_DEBUG)
		gettimeofday(&start, NULL);

	if (!dry_run)
		err = ioctl(fd, ioctl_cmd, cmd);

	if (log_level >= LOG_DEBUG) {
		gettimeofday(&end, NULL);
		nvme_show_command(cmd, err);
		nvme_show_latency(start, end);
	}

	if (err >= 0 && result)
		*result = cmd->result;

	return err;
}

return 0;

gettimeofday(&start_time, NULL);
err = nvme_io(args, opcode);
gettimeofday(&end_time, NULL);

if (latency)
nvme_show_latency(start_time, end_time);

return err;
}
2 changes: 1 addition & 1 deletion util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ extern int log_level;

int map_log_level(int verbose, bool quiet);
void set_dry_run(bool enable);

int nvme_submit_io(struct nvme_io_args *args, __u8 opcode, bool show, bool latency);
#endif // DEBUG_H_