From f320596ca3e8f61ba47c686c2b6c379cf912295d Mon Sep 17 00:00:00 2001 From: Stephen Bates Date: Sat, 7 Feb 2015 02:48:33 +0000 Subject: [PATCH] Added dry-run (-d) option to nvme-io-passthru Added the option to dry-run the nvme-io-passthru command. Use with the show option. The plan is to add this to other commands in due course. --- Documentation/nvme-io-passthru.1 | 15 ++++++++++----- Documentation/nvme-io-passthru.txt | 9 ++++++--- nvme.c | 10 ++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Documentation/nvme-io-passthru.1 b/Documentation/nvme-io-passthru.1 index 43b8601f..29a696e5 100644 --- a/Documentation/nvme-io-passthru.1 +++ b/Documentation/nvme-io-passthru.1 @@ -2,12 +2,12 @@ .\" Title: nvme-io-passthru .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 02/02/2015 +.\" Date: 02/06/2015 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "NVME\-IO\-PASSTHRU" "1" "02/02/2015" "\ \&" "\ \&" +.TH "NVME\-IO\-PASSTHRU" "1" "02/06/2015" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -101,9 +101,14 @@ The data length for the buffer used for this command\&. The metadata length for the buffer used for this command\&. .RE .PP -\-s, \-\-show\-cmd, \-\-dry\-run +\-s, \-\-show\-cmd .RS 4 -Do not actually send the command; print out the command that would be sent\&. +Print out the command to be sent\&. +.RE +.PP +\-d, \-\-dry\-run +.RS 4 +Do not actually send the command\&. .RE .PP \-b, \-\-raw\-binary @@ -112,7 +117,7 @@ Print the raw returned buffer to stdout if the command returns data or a structu .RE .SH "EXAMPLES" .sp -No examples yet\&. +nvme io\-passthru /dev/nvme0n1 \-\-opcode=2 \-\-namespace\-id=1 \-\-data\-len=4096 \-\-read \-\-cdw10=0 \-\-cdw11=0 \-\-cdw12=0x70000 \-\-raw\-binary .SH "NVME" .sp Part of the nvme\-user suite diff --git a/Documentation/nvme-io-passthru.txt b/Documentation/nvme-io-passthru.txt index ac97e866..08ac19e7 100644 --- a/Documentation/nvme-io-passthru.txt +++ b/Documentation/nvme-io-passthru.txt @@ -83,9 +83,11 @@ OPTIONS -s:: --show-cmd:: + Print out the command to be sent. + +-d:: --dry-run:: - Do not actually send the command; print out the command that - would be sent. + Do not actually send the command. -b:: --raw-binary:: @@ -94,7 +96,8 @@ OPTIONS EXAMPLES -------- -No examples yet. + +nvme io-passthru /dev/nvme0n1 --opcode=2 --namespace-id=1 --data-len=4096 --read --cdw10=0 --cdw11=0 --cdw12=0x70000 --raw-binary NVME ---- diff --git a/nvme.c b/nvme.c index d39aae4b..bfe60e30 100644 --- a/nvme.c +++ b/nvme.c @@ -1872,7 +1872,7 @@ static int sec_recv(int argc, char **argv) static int nvme_passthru(int argc, char **argv, int ioctl_cmd) { int r = 0, w = 0; - int opt, err, raw = 0, show = 0, long_index = 0, wfd = STDIN_FILENO; + int opt, err, raw = 0, show = 0, dry_run = 0, long_index = 0, wfd = STDIN_FILENO; struct nvme_passthru_cmd cmd; static struct option opts[] = { {"opcode", required_argument, 0, 'o'}, @@ -1892,7 +1892,7 @@ static int nvme_passthru(int argc, char **argv, int ioctl_cmd) {"cdw15", required_argument, 0, '9'}, {"raw-binary", no_argument, 0, 'b'}, {"show-command", no_argument, 0, 's'}, - {"dry-run", no_argument, 0, 's'}, + {"dry-run", no_argument, 0, 'd'}, {"read", no_argument, 0, 'r'}, {"write", no_argument, 0, 'w'}, {"input-file", no_argument, 0, 'i'}, @@ -1900,7 +1900,7 @@ static int nvme_passthru(int argc, char **argv, int ioctl_cmd) }; memset(&cmd, 0, sizeof(cmd)); - while ((opt = getopt_long(argc, (char **)argv, "o:n:f:l:R:m:t:i:bsrw", opts, + while ((opt = getopt_long(argc, (char **)argv, "o:n:f:l:R:m:t:i:bsdrw", opts, &long_index)) != -1) { switch (opt) { case '2': get_int(optarg, &cmd.cdw2); break; @@ -1920,6 +1920,7 @@ static int nvme_passthru(int argc, char **argv, int ioctl_cmd) case 't': get_int(optarg, &cmd.timeout_ms); break; case 'b': raw = 1; break; case 's': show = 1; break; + case 'd': dry_run = 1; break; case 'r': r = 1; break; case 'w': w = 1; break; case 'i': @@ -1971,7 +1972,8 @@ static int nvme_passthru(int argc, char **argv, int ioctl_cmd) printf("cdw14 : %08x\n", cmd.cdw14); printf("cdw15 : %08x\n", cmd.cdw15); printf("timeout_ms : %08x\n", cmd.timeout_ms); - return 0; + if (dry_run) + return 0; } err = ioctl(fd, ioctl_cmd, &cmd); if (err >= 0) { -- 2.50.1