From 4babc9e8b3723d60ef21538d68db7d4e6e85f08b Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Tue, 2 Dec 2014 13:31:09 -0700 Subject: [PATCH] NVMe: Add support for Flush command Signed-off-by: Keith Busch --- Documentation/nvme-flush.txt | 34 +++++++++++++++++++++++++++++++++ nvme.c | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Documentation/nvme-flush.txt diff --git a/Documentation/nvme-flush.txt b/Documentation/nvme-flush.txt new file mode 100644 index 00000000..28cfa63b --- /dev/null +++ b/Documentation/nvme-flush.txt @@ -0,0 +1,34 @@ +nvme-flush(1) +============= + +NAME +---- +nvme-flush - Flush command. + +SYNOPSIS +-------- +[verse] +'nvme flush' [--namespace-id= | -n ] + +DESCRIPTION +----------- +The Flush command shall commit data and metadata associated with the +specified namespace(s) to nonvolatile media. The flush applies to +all commands completed prior to the submission of the Flush command. +The controller may also flush additional data and/or metadata from +any namespace. + +OPTIONS +------- +-n :: +--namespace-id=:: + Specify the optional namespace id for this command. Defaults to + 0xffffffff, indicating flush for all namespaces. + +EXAMPLES +-------- +No examples yet. + +NVME +---- +Part of the nvme-user suite diff --git a/nvme.c b/nvme.c index 941df724..1f8c9a70 100644 --- a/nvme.c +++ b/nvme.c @@ -65,6 +65,7 @@ static const char *devicename; ENTRY(RESV_REGISTER, "resv-register", "Submit a Reservation Register, return results", resv_register) \ ENTRY(RESV_RELEASE, "resv-release", "Submit a Reservation Release, return results", resv_release) \ ENTRY(RESV_REPORT, "resv-report", "Submit a Reservation Report, return results", resv_report) \ + ENTRY(FLUSH, "flush", "Submit a Flush command, return results", flush) \ ENTRY(HELP, "help", "Display this help", help) #define ENTRY(i, n, h, f) \ @@ -1280,6 +1281,42 @@ static int sec_send(int argc, char **argv) return err; } +static int flush(int argc, char **argv) +{ + struct nvme_passthru_cmd cmd; + unsigned int nsid = 0xffffffff; + int err, opt, long_index = 0; + + static struct option opts[] = { + {"namespace-id", required_argument, 0, 'n'}, + { 0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, (char **)argv, "n:", opts, + &long_index)) != -1) { + switch(opt) { + case 'n': get_int(optarg, &nsid); break; + default: + return EINVAL; + } + } + get_dev(optind, argc, argv); + + memset(&cmd, 0, sizeof(cmd)); + cmd.opcode = nvme_cmd_flush; + cmd.nsid = nsid; + + err = ioctl(fd, NVME_IOCTL_IO_CMD, &cmd); + if (err < 0) + return errno; + else if (err != 0) + fprintf(stderr, "NVME IO command error:%s(%d)\n", + nvme_status_to_string(err), err); + else + printf("NVMe Flush: success\n"); + return 0; +} + static int resv_acquire(int argc, char **argv) { struct nvme_passthru_cmd cmd; -- 2.50.1