Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 30 additions & 3 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const char *output_format = "Output format: normal|binary";
const char *timeout = "timeout value, in milliseconds";
const char *verbose = "Increase output verbosity";
const char *dry_run = "show command instead of sending";
const char *delay = "iterative delay as SECS [.TENTHS]";

static const char *app_tag = "app tag for end-to-end PI";
static const char *app_tag_mask = "app tag mask for end-to-end PI";
Expand Down Expand Up @@ -262,6 +263,7 @@ struct nvme_config nvme_cfg = {
.output_format = "normal",
.output_format_ver = 1,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.delay = 0,
};

static void *mmap_registers(struct nvme_transport_handle *hdl, bool writable);
Expand Down Expand Up @@ -11011,6 +11013,29 @@ void register_extension(struct plugin *plugin)
nvme.extensions->tail = plugin;
}

static bool handle_delay(int err)
{
struct timespec ts;
double delay_f;
double delay_i;

if (err || !nvme_cfg.delay)
return false;

delay_f = modf(nvme_cfg.delay, &delay_i);
ts.tv_sec = delay_i;
ts.tv_nsec = delay_f * 1000000000;
err = pselect(0, NULL, NULL, NULL, &ts, NULL);
if (err < 0)
return false;

err = system("clear");
if (err < 0)
return false;

return true;
}

int main(int argc, char **argv)
{
int err;
Expand All @@ -11026,9 +11051,11 @@ int main(int argc, char **argv)
if (err)
return err;

err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
if (err == -ENOTTY)
general_help(&builtin, NULL);
do {
err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
if (err == -ENOTTY)
general_help(&builtin, NULL);
} while (handle_delay(err));

return err ? 1 : 0;
}
3 changes: 3 additions & 0 deletions nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct nvme_config {
bool dry_run;
bool no_retries;
unsigned int output_format_ver;
double delay;
};

/*
Expand All @@ -76,6 +77,7 @@ struct nvme_config {
"disable retry logic on errors\n"), \
OPT_UINT("output-format-version", 0, &nvme_cfg.output_format_ver, \
"output format version: 1|2"), \
OPT_DOUBLE("delay", 'd', &nvme_cfg.delay, delay), \
OPT_END() \
}

Expand Down Expand Up @@ -109,6 +111,7 @@ extern const char *output_format;
extern const char *timeout;
extern const char *verbose;
extern const char *dry_run;
extern const char *delay;
extern struct nvme_config nvme_cfg;

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