From mboxrd@z Thu Jan 1 00:00:00 1970 From: guanjunxiong@huawei.com (Guan Junxiong) Date: Wed, 13 Dec 2017 10:11:31 +0800 Subject: [PATCH V2 2/2] nvme-cli: support to set the property for NVMe over Fabric In-Reply-To: <1513131091-15840-1-git-send-email-guanjunxiong@huawei.com> References: <1513131091-15840-1-git-send-email-guanjunxiong@huawei.com> Message-ID: <1513131091-15840-3-git-send-email-guanjunxiong@huawei.com> Signed-off-by: Guan Junxiong --- Documentation/nvme-set-property.1 | 51 +++ Documentation/nvme-set-property.html | 814 +++++++++++++++++++++++++++++++++++ Documentation/nvme-set-property.txt | 34 ++ nvme-builtin.h | 1 + nvme-ioctl.c | 20 + nvme-ioctl.h | 1 + nvme-print.c | 19 + nvme-print.h | 1 + nvme.c | 52 +++ 9 files changed, 993 insertions(+) create mode 100644 Documentation/nvme-set-property.1 create mode 100644 Documentation/nvme-set-property.html create mode 100644 Documentation/nvme-set-property.txt diff --git a/Documentation/nvme-set-property.1 b/Documentation/nvme-set-property.1 new file mode 100644 index 0000000..0ade108 --- /dev/null +++ b/Documentation/nvme-set-property.1 @@ -0,0 +1,51 @@ +'\" t +.\" Title: nvme-set-property +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.78.1 +.\" Date: 06/28/2017 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-SET\-PROPERTY" "1" "11/24/2017" "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-set-propery \- Writes and shows the defined NVMe controller property for NVMe ove Fabric +.SH "SYNOPSIS" +.sp +.nf +\fInvme set\-property\fR [\-\-offset= | \-n ] + [\-\-value= | \-v ] +.fi +.SH "DESCRIPTION" +.sp +Writes and shows the defined NVMe controller property for NVMe ove Fabric\&. Please use it carefully\&. +.SH "OPTIONS" +.PP +\-o , \-\-offset= +.RS 4 +The offset of the property\&. +.RE +.SH "EXAMPLES" +.RE +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-set-property.html b/Documentation/nvme-set-property.html new file mode 100644 index 0000000..e365b3a --- /dev/null +++ b/Documentation/nvme-set-property.html @@ -0,0 +1,814 @@ + + + + + +nvme-set-property(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme set-property <device> [--offset=<offset> | -o <offset> ]
+	 					[--value=<val> | -v <val> ]
+
+
+
+
+
+

DESCRIPTION

+
+

Writes and shows the defined NVMe controller property for NVMe ove Fabric.

+
+
+
+

OPTIONS

+
+
+
+-o +
+
+--offset +
+
+

+ The offset of the property +

+
+
+
+-v +
+
+--value +
+
+

+ The value of the property to be set +

+
+
+
+
+
+

EXAMPLES

+
+
    +
  • +
    +
    +
    +
    +
    +

    NVME

    +
    +

    Part of the nvme-user suite

    +
    +
    +
+

+ + + diff --git a/Documentation/nvme-set-property.txt b/Documentation/nvme-set-property.txt new file mode 100644 index 0000000..7c49058 --- /dev/null +++ b/Documentation/nvme-set-property.txt @@ -0,0 +1,34 @@ +nvme-set-property(1) +============= + +NAME +---- +nvme-set-property - Writes and shows the defined NVMe controller property +for NVMe ove Fabric + +SYNOPSIS +-------- +[verse] +'nvme set-property' [--offset= | -o ] [--value= | -v ] + + +DESCRIPTION +----------- +Writes and shows the defined NVMe controller property for NVMe ove Fabric + +OPTIONS +------- +-o:: +--offset:: + The offset of the property + +-v:: +--value: + The value of the property to be set + +EXAMPLES +-------- + +NVME +---- +Part of the nvme-user suite diff --git a/nvme-builtin.h b/nvme-builtin.h index 432d79c..aa395bf 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -55,6 +55,7 @@ COMMAND_LIST( ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd) ENTRY("dir-receive", "Submit a Directive Receive command, return results", dir_receive) ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send) + ENTRY("set-property", "Set a property and show the resulting value", set_property) ); #endif diff --git a/nvme-ioctl.c b/nvme-ioctl.c index cf93340..3945824 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -526,6 +526,26 @@ int nvme_get_properties(int fd, void **pbar) return ret; } +int nvme_set_property(int fd, int offset, int value) +{ + __le64 val = cpu_to_le64(value); + __le32 off = cpu_to_le32(offset); + bool is64bit; + + switch (off) { + case NVME_REG_CAP: + case NVME_REG_ASQ: + case NVME_REG_ACQ: + is64bit = true; + break; + default: + is64bit = false; + } + + return nvme_property(fd, nvme_fabrics_type_property_set, + off, &val, is64bit ? 1: 0); +} + int nvme_get_feature(int fd, __u32 nsid, __u8 fid, __u8 sel, __u32 cdw11, __u32 data_len, void *data, __u32 *result) { diff --git a/nvme-ioctl.h b/nvme-ioctl.h index 90e2e18..7cc80c8 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -122,5 +122,6 @@ int nvme_dir_send(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper, int nvme_dir_recv(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper, __u32 data_len, __u32 dw12, void *data, __u32 *result); int nvme_get_properties(int fd, void **pbar); +int nvme_set_property(int fd, int offset, int value); #endif /* _NVME_LIB_H */ diff --git a/nvme-print.c b/nvme-print.c index 78945b3..ab0c2a2 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1092,6 +1092,25 @@ char *nvme_feature_to_string(int feature) } } +char *nvme_register_to_string(int reg) +{ + switch (reg) { + case NVME_REG_CAP: return "Controller Capabilities"; + case NVME_REG_VS: return "Version"; + case NVME_REG_INTMS: return "Interrupt Vector Mask Set"; + case NVME_REG_INTMC: return "Interrupt Vector Mask Clear"; + case NVME_REG_CC: return "Controller Configuration"; + case NVME_REG_CSTS: return "Controller Status"; + case NVME_REG_NSSR: return "NVM Subsystem Reset"; + case NVME_REG_AQA: return "Admin Queue Attributes"; + case NVME_REG_ASQ: return "Admin Submission Queue Base Address"; + case NVME_REG_ACQ: return "Admin Completion Queue Base Address"; + case NVME_REG_CMBLOC: return "Controller Memory Buffer Location"; + case NVME_REG_CMBSZ: return "Controller Memory Buffer Size"; + default: return "Unknown"; + } +} + char* nvme_select_to_string(int sel) { switch (sel) { diff --git a/nvme-print.h b/nvme-print.h index bae4929..f71c88f 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -33,6 +33,7 @@ void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, uns char *nvme_status_to_string(__u32 status); char *nvme_select_to_string(int sel); char *nvme_feature_to_string(int feature); +char *nvme_register_to_string(int reg); void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root)); void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags); diff --git a/nvme.c b/nvme.c index dd674c3..e1faec9 100644 --- a/nvme.c +++ b/nvme.c @@ -1654,6 +1654,58 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu return 0; } +static int set_property(int argc, char **argv, struct command *cmd, struct plugin *plugin) +{ + const char *desc = "Writes and shows the defined NVMe controller property "\ + "for NVMe ove Fabric"; + const char *offset = "the offset of the property"; + const char *value = "the value of the property to be set"; + int fd, err; + + struct config { + int offset; + int value; + }; + + struct config cfg = { + .offset = -1, + .value = -1, + }; + + const struct argconfig_commandline_options command_line_options[] = { + {"offset", 'o', "NUM", CFG_POSITIVE, &cfg.offset, required_argument, offset}, + {"value", 'v', "NUM", CFG_POSITIVE, &cfg.value, required_argument, value}, + {NULL} + }; + + fd = parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg)); + if (fd < 0) + return fd; + + if (cfg.offset == -1) { + fprintf(stderr, "offset required param"); + return EINVAL; + } + if (cfg.value == -1) { + fprintf(stderr, "value required param"); + return EINVAL; + } + + err = nvme_set_property(fd, cfg.offset, cfg.value); + if (err < 0) { + perror("set-property"); + return errno; + } else if (!err) { + printf("set-property: %02x (%s), value: %#08x\n", cfg.offset, + nvme_register_to_string(cfg.offset), cfg.value); + } else if (err > 0) { + fprintf(stderr, "NVMe Status: %s(%x)\n", + nvme_status_to_string(err), err); + } + + return err; +} + static int format(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Re-format a specified namespace on the "\ -- 2.11.1