-
Notifications
You must be signed in to change notification settings - Fork 710
nvme: add dry-run NVME_ARGS default option #2751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| #include "logging.h" | ||
|
|
||
| int log_level; | ||
| static bool dry_run; | ||
|
|
||
| int map_log_level(int verbose, bool quiet) | ||
| { | ||
|
|
@@ -44,6 +45,11 @@ int map_log_level(int verbose, bool quiet) | |
| return log_level; | ||
| } | ||
|
|
||
| void set_dry_run(bool enable) | ||
| { | ||
| dry_run = enable; | ||
| } | ||
|
|
||
| static void nvme_show_common(struct nvme_passthru_cmd *cmd) | ||
| { | ||
| printf("opcode : %02x\n", cmd->opcode); | ||
|
|
@@ -93,6 +99,11 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, | |
| struct timeval end; | ||
| int err; | ||
|
|
||
| if (dry_run) { | ||
| nvme_show_common(cmd); | ||
| return 0; | ||
| } | ||
|
|
||
| if (log_level >= LOG_DEBUG) | ||
| gettimeofday(&start, NULL); | ||
|
|
||
|
|
@@ -116,12 +127,16 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, | |
| { | ||
| struct timeval start; | ||
| struct timeval end; | ||
| int err; | ||
| int err = 0; | ||
|
|
||
| if (dry_run) { | ||
| nvme_show_common((struct nvme_passthru_cmd *)cmd); | ||
| return 0; | ||
| } | ||
|
|
||
| if (log_level >= LOG_DEBUG) | ||
| gettimeofday(&start, NULL); | ||
|
|
||
|
|
||
| err = ioctl(fd, ioctl_cmd, cmd); | ||
|
|
||
| if (log_level >= LOG_DEBUG) { | ||
|
|
@@ -135,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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and then the 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; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the
-wshort hand here, to stay compatible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as mentioned.