From: Keith Busch Date: Thu, 17 Mar 2016 22:30:26 +0000 (-0600) Subject: Add reset and subsystem reset commands X-Git-Tag: v0.5~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=94fd04399b488eff32a26a5edb03620ee27035ee;p=users%2Fsagi%2Fnvme-cli.git Add reset and subsystem reset commands Signed-off-by: Keith Busch --- diff --git a/Documentation/nvme-reset.1 b/Documentation/nvme-reset.1 new file mode 100644 index 00000000..b2017a69 --- /dev/null +++ b/Documentation/nvme-reset.1 @@ -0,0 +1,67 @@ +'\" t +.\" Title: nvme-reset +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Date: 03/17/2016 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-RESET" "1" "03/17/2016" "NVMe" "NVMe Manual" +.\" ----------------------------------------------------------------- +.\" * 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-reset \- Reset the nvme controller\&. +.SH "SYNOPSIS" +.sp +.nf +\fInvme reset\fR +.fi +.SH "DESCRIPTION" +.sp +Requests NVMe controller reset\&. The param is mandatory and must be an NVMe character device (ex: /dev/nvme0)\&. +.SH "OPTIONS" +.sp +None +.SH "EXAMPLES" +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +Resets the controller\&. +.sp +.if n \{\ +.RS 4 +.\} +.nf +# nvme reset /dev/nvme0 +.fi +.if n \{\ +.RE +.\} +.RE +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-reset.html b/Documentation/nvme-reset.html new file mode 100644 index 00000000..352a35d5 --- /dev/null +++ b/Documentation/nvme-reset.html @@ -0,0 +1,803 @@ + + + + + +nvme-reset(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme reset <device>
+
+
+
+
+
+

DESCRIPTION

+
+

Requests NVMe controller reset. The <device> param is mandatory and must +be an NVMe character device (ex: /dev/nvme0).

+
+
+
+

OPTIONS

+
+

None

+
+
+
+

EXAMPLES

+
+
    +
  • +

    +Resets the controller. +

    +
    +
    +
    # nvme reset /dev/nvme0
    +
    +
  • +
+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-reset.txt b/Documentation/nvme-reset.txt new file mode 100644 index 00000000..d1a282bc --- /dev/null +++ b/Documentation/nvme-reset.txt @@ -0,0 +1,32 @@ +nvme-reset(1) +============= + +NAME +---- +nvme-reset - Reset the nvme controller. + +SYNOPSIS +-------- +[verse] +'nvme reset' + +DESCRIPTION +----------- +Requests NVMe controller reset. The param is mandatory and must +be an NVMe character device (ex: /dev/nvme0). + +OPTIONS +------- +None + +EXAMPLES +-------- +* Resets the controller. ++ +------------ +# nvme reset /dev/nvme0 +------------ + +NVME +---- +Part of the nvme-user suite diff --git a/Documentation/nvme-security-recv.1 b/Documentation/nvme-security-recv.1 index f08ad635..291d247a 100644 --- a/Documentation/nvme-security-recv.1 +++ b/Documentation/nvme-security-recv.1 @@ -2,12 +2,12 @@ .\" Title: nvme-security-recv .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 03/03/2016 +.\" Date: 03/17/2016 .\" Manual: NVMe Manual .\" Source: NVMe .\" Language: English .\" -.TH "NVME\-SECURITY\-RECV" "1" "03/03/2016" "NVMe" "NVMe Manual" +.TH "NVME\-SECURITY\-RECV" "1" "03/17/2016" "NVMe" "NVMe Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- diff --git a/Documentation/nvme-subsystem-reset.1 b/Documentation/nvme-subsystem-reset.1 new file mode 100644 index 00000000..f467342e --- /dev/null +++ b/Documentation/nvme-subsystem-reset.1 @@ -0,0 +1,67 @@ +'\" t +.\" Title: nvme-subsystem-reset +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Date: 03/17/2016 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-SUBSYSTEM\-RES" "1" "03/17/2016" "NVMe" "NVMe Manual" +.\" ----------------------------------------------------------------- +.\" * 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-subsystem-reset \- Reset the nvme subsystem\&. +.SH "SYNOPSIS" +.sp +.nf +\fInvme subsystem\-reset\fR +.fi +.SH "DESCRIPTION" +.sp +Requests NVMe subsystem reset\&. The param is mandatory and must be an NVMe character device (ex: /dev/nvme0)\&. +.SH "OPTIONS" +.sp +None +.SH "EXAMPLES" +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +Resets the subsystem\&. +.sp +.if n \{\ +.RS 4 +.\} +.nf +# nvme subsystem\-reset /dev/nvme0 +.fi +.if n \{\ +.RE +.\} +.RE +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-subsystem-reset.html b/Documentation/nvme-subsystem-reset.html new file mode 100644 index 00000000..a7604e7b --- /dev/null +++ b/Documentation/nvme-subsystem-reset.html @@ -0,0 +1,803 @@ + + + + + +nvme-subsystem-reset(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme subsystem-reset <device>
+
+
+
+
+
+

DESCRIPTION

+
+

Requests NVMe subsystem reset. The <device> param is mandatory and must +be an NVMe character device (ex: /dev/nvme0).

+
+
+
+

OPTIONS

+
+

None

+
+
+
+

EXAMPLES

+
+
    +
  • +

    +Resets the subsystem. +

    +
    +
    +
    # nvme subsystem-reset /dev/nvme0
    +
    +
  • +
+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-subsystem-reset.txt b/Documentation/nvme-subsystem-reset.txt new file mode 100644 index 00000000..2267acdd --- /dev/null +++ b/Documentation/nvme-subsystem-reset.txt @@ -0,0 +1,32 @@ +nvme-subsystem-reset(1) +======================= + +NAME +---- +nvme-subsystem-reset - Reset the nvme subsystem. + +SYNOPSIS +-------- +[verse] +'nvme subsystem-reset' + +DESCRIPTION +----------- +Requests NVMe subsystem reset. The param is mandatory and must +be an NVMe character device (ex: /dev/nvme0). + +OPTIONS +------- +None + +EXAMPLES +-------- +* Resets the subsystem. ++ +------------ +# nvme subsystem-reset /dev/nvme0 +------------ + +NVME +---- +Part of the nvme-user suite diff --git a/nvme-ioctl.c b/nvme-ioctl.c index 7669a0cf..950f579c 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -21,6 +21,36 @@ #include "nvme-ioctl.h" +int nvme_subsystem_reset(int fd) +{ + static struct stat nvme_stat; + int err = fstat(fd, &nvme_stat); + + if (err < 0) + return err; + if (!S_ISCHR(nvme_stat.st_mode)) { + fprintf(stderr, + "Error: requesting subsystem reset on non-controller handle\n"); + exit(ENOTBLK); + } + return ioctl(fd, NVME_IOCTL_SUBSYS_RESET); +} + +int nvme_reset_controller(int fd) +{ + static struct stat nvme_stat; + int err = fstat(fd, &nvme_stat); + + if (err < 0) + return err; + if (!S_ISCHR(nvme_stat.st_mode)) { + fprintf(stderr, + "Error: requesting reset on non-controller handle\n"); + exit(ENOTBLK); + } + return ioctl(fd, NVME_IOCTL_RESET); +} + int nvme_get_nsid(int fd) { static struct stat nvme_stat; @@ -31,7 +61,7 @@ int nvme_get_nsid(int fd) if (!S_ISBLK(nvme_stat.st_mode)) { fprintf(stderr, - "requesting namespace-id from non-block device\n"); + "Error: requesting namespace-id from non-block device\n"); exit(ENOTBLK); } return ioctl(fd, NVME_IOCTL_ID); diff --git a/nvme-ioctl.h b/nvme-ioctl.h index 0c6607df..240f8dd9 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -112,4 +112,7 @@ int nvme_sec_send(int fd, __u32 nsid, __u8 nssf, __u16 spsp, int nvme_sec_recv(int fd, __u32 nsid, __u8 nssf, __u16 spsp, __u8 secp, __u32 al, __u32 data_len, void *data, __u32 *result); +int nvme_subsystem_reset(int fd); +int nvme_reset_controller(int fd); + #endif /* _NVME_LIB_H */ diff --git a/nvme.c b/nvme.c index a4420c7a..9a7e4b34 100644 --- a/nvme.c +++ b/nvme.c @@ -99,6 +99,8 @@ static const char nvme_version_string[] = NVME_VERSION; ENTRY(WRITE_CMD, "write", "Submit a write command, return results", write_cmd) \ ENTRY(WRITE_ZEROES_CMD, "write-zeroes", "Submit a write zeroes command, return results", write_zeroes) \ ENTRY(WRITE_UNCOR_CMD, "write-uncor", "Submit a write uncorrectable command, return results", write_uncor) \ + ENTRY(RESET, "reset", "Resets the controller", reset) \ + ENTRY(SUBSYS_RESET, "subsystem-reset", "Resets the controller", subsystem_reset) \ ENTRY(REGISTERS, "show-regs", "Shows the controller registers. Requires admin character device", show_registers) \ ENTRY(VERSION, "version", "Shows the program version", version) \ ENTRY(HELP, "help", "Display this help", help) @@ -1227,6 +1229,26 @@ static int fw_activate(int argc, char **argv) return err; } +static void clear_args(int argc, char **argv) +{ + int opt, long_index; + while ((opt = getopt_long(argc, (char **)argv, "", NULL, + &long_index)) != -1); + get_dev(argc, argv); +} + +static int subsystem_reset(int argc, char **argv) +{ + clear_args(argc, argv); + return nvme_subsystem_reset(fd); +} + +static int reset(int argc, char **argv) +{ + clear_args(argc, argv); + return nvme_reset_controller(fd); +} + static void print_lo_hi_64(uint32_t *val) { printf("%x%08x\n", val[1], val[0]);