From: Keith Busch Date: Wed, 4 Feb 2015 17:36:49 +0000 (-0700) Subject: NVMe: Provide easy read and write commands X-Git-Tag: v0.1~79 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=bb131aa7268b7fe06bf3198d4816c6a2391a7172;p=users%2Fsagi%2Fnvme-cli.git NVMe: Provide easy read and write commands This adds convienience functions for read and write. They are similar to compare in that they use the helpful NVME_SUBMIT_IO IOCTL instead of the passthru version that requires more setup. Signed-off-by: Keith Busch --- diff --git a/Documentation/nvme-read.1 b/Documentation/nvme-read.1 new file mode 100644 index 00000000..abbb03be --- /dev/null +++ b/Documentation/nvme-read.1 @@ -0,0 +1,60 @@ +'\" t +.\" Title: nvme-compare +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Date: 02/04/2015 +.\" Manual: \ \& +.\" Source: \ \& +.\" Language: English +.\" +.TH "NVME\-COMPARE" "1" "02/04/2015" "\ \&" "\ \&" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +nvme-read \- Send an NVMe Read command, provide results +.SH "SYNOPSIS" +.sp +.nf +\fInvme\-read\fR [\-\-start\-block= | \-s ] + [\-\-block\-count= | \-c ] + [\-\-data\-size= | \-z ] + [\-\-ref\-tag= | \-r ] + [\-\-data= | \-d ] + [\-\-prinfo= | \-p ] + [\-\-app\-tag\-mask= | \-m ] + [\-\-app\-tag= | \-a ] + [\-\-limited\-retry | \-l] + [\-\-force\-unit\-access | \-f] +.fi +.SH "DESCRIPTION" +.sp +The Read command reads the logical blocks specified by the command from the medium and copies to the data data buffer provided\&. Will use stdout by default if you don\(cqt provide a file\&. +.SH "OPTIONS" +.PP +\-\-start\-block=, \-s +.RS 4 +Start block\&. +.RE +.SH "EXAMPLES" +.sp +No examples yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-write.1 b/Documentation/nvme-write.1 new file mode 100644 index 00000000..728b8f09 --- /dev/null +++ b/Documentation/nvme-write.1 @@ -0,0 +1,60 @@ +'\" t +.\" Title: nvme-compare +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Date: 02/04/2015 +.\" Manual: \ \& +.\" Source: \ \& +.\" Language: English +.\" +.TH "NVME\-COMPARE" "1" "02/04/2015" "\ \&" "\ \&" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +nvme-write \- Send an NVMe write command, provide results +.SH "SYNOPSIS" +.sp +.nf +\fInvme\-write\fR [\-\-start\-block= | \-s ] + [\-\-block\-count= | \-c ] + [\-\-data\-size= | \-z ] + [\-\-ref\-tag= | \-r ] + [\-\-data= | \-d ] + [\-\-prinfo= | \-p ] + [\-\-app\-tag\-mask= | \-m ] + [\-\-app\-tag= | \-a ] + [\-\-limited\-retry | \-l] + [\-\-force\-unit\-access | \-f] +.fi +.SH "DESCRIPTION" +.sp +The Write command writes the logical blocks specified by the command to the medium from the data data buffer provided\&. Will use stdin by default if you don\(cqt provide a file\&. +.SH "OPTIONS" +.PP +\-\-start\-block=, \-s +.RS 4 +Start block\&. +.RE +.SH "EXAMPLES" +.sp +No examples yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme.1 b/Documentation/nvme.1 index 3455f7f3..7c74531c 100644 --- a/Documentation/nvme.1 +++ b/Documentation/nvme.1 @@ -2,12 +2,12 @@ .\" Title: nvme .\" Author: [see the "Authors" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 02/03/2015 +.\" Date: 02/04/2015 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "NVME" "1" "02/03/2015" "\ \&" "\ \&" +.TH "NVME" "1" "02/04/2015" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -44,7 +44,7 @@ This \fInvme\fR program is a user space utility to provide standards compliant t The utility has sub\-commands for all admin and io commands defined in the specification and for displaying controller registers\&. There is also an option to submit completely arbitrary commands\&. For a list of commands available, run "nvme help"\&. .SH "FURTHER DOCUMENTATION" .sp -See the freely available references on \m[blue]\fBOffical NVM\-Express Site\fR\m[]\&\s-2\u[1]\d\s+2\&. +See the freely available references on the \m[blue]\fBOffical NVM\-Express Site\fR\m[]\&\s-2\u[1]\d\s+2\&. .SH "AUTHORS" .sp This is written and maintained by \m[blue]\fBKeith Busch\fR\m[]\&\s-2\u[2]\d\s+2\&. diff --git a/nvme.c b/nvme.c index 1e16cb9d..cfad3bf0 100644 --- a/nvme.c +++ b/nvme.c @@ -68,6 +68,8 @@ static const char *devicename; ENTRY(RESV_REPORT, "resv-report", "Submit a Reservation Report, return results", resv_report) \ ENTRY(FLUSH, "flush", "Submit a Flush command, return results", flush) \ ENTRY(COMPARE, "compare", "Submit a Comapre command, return results", compare) \ + ENTRY(READ, "read", "Submit a read command, return results", read_cmd) \ + ENTRY(WRITE, "write", "Submit a write command, return results", write_cmd) \ ENTRY(REGISTERS, "show-regs", "Shows the controller registers. Requires admin character device", show_registers) \ ENTRY(HELP, "help", "Display this help", help) @@ -1671,13 +1673,16 @@ static int resv_report(int argc, char **argv) return 0; } -static int compare(int argc, char **argv) +static int submit_io(int opcode, char *command, int argc, char **argv) { struct nvme_user_io io; void *buffer; - int err, opt, dfd = STDIN_FILENO, long_index = 0; + int err, opt, dfd = opcode & 1 ? STDIN_FILENO : STDOUT_FILENO, + long_index = 0; unsigned int data_size = 0; __u8 prinfo = 0; + + /* XXX: metadata ? */ static struct option opts[] = { {"start-block", required_argument, 0, 's'}, {"block-count", required_argument, 0, 'c'}, @@ -1732,21 +1737,43 @@ static int compare(int argc, char **argv) return EINVAL; } buffer = malloc(data_size); - if (read(dfd, (void *)buffer, data_size) < 0) { - fprintf(stderr, "failed to read compare buffer\n"); + if ((opcode & 1) && read(dfd, (void *)buffer, data_size) < 0) { + fprintf(stderr, "failed to read buffer from input file\n"); return EINVAL; } - io.opcode = nvme_cmd_compare; + io.opcode = opcode; io.addr = (__u64)buffer; err = ioctl(fd, NVME_IOCTL_SUBMIT_IO, &io); if (err < 0) perror("ioctl"); - else - printf("compare:%s(%04x)\n", nvme_status_to_string(err), err); + else if (err) + printf("%s:%s(%04x)\n", command, nvme_status_to_string(err), err); + else { + if (!(opcode & 1) && write(dfd, (void *)buffer, data_size) < 0) { + fprintf(stderr, "failed to write buffer to output file\n"); + return EINVAL; + } else + printf("%s: success\n", command); + } return 0; } +static int compare(int argc, char **argv) +{ + return submit_io(nvme_cmd_compare, "compare", argc, argv); +} + +static int read_cmd(int argc, char **argv) +{ + return submit_io(nvme_cmd_read, "read", argc, argv); +} + +static int write_cmd(int argc, char **argv) +{ + return submit_io(nvme_cmd_write, "write", argc, argv); +} + static int sec_recv(int argc, char **argv) { struct nvme_admin_cmd cmd;