nvme-cli: add options to set/get property of NVMf
Subsystems (2)
v2 cover nvme-cli: add options to set/get property of NVMf
Hi all,
To make it easy to use, this two patches add the support to set/get the properties for NVMe over Fabric.
Patch 1/2 makes use of show-regs option which only supports PCIe previously to support NVMf.
Patch 2/2 adds new option named set-property to support setting the property of NVMf. IMO, it is the responsibility of kernel to try to avoid malicious operation such as setting NRSS from the user space. So I ignore this in the nvme-cli.
Welcome any comments.
Thanks
Changes since V1:
* return nagative -EINVAL and set errno to distinguish positive NVMe error status code (Minwoo)
* remove uncecessary initialization for local variable _is64bit_ (Minwoo)
* rebase on latest master
Guan Junxiong (2):
nvme-cli: add support to get properties for NVMe over Fabric
nvme-cli: support to set the property for NVMe over Fabric
Documentation/nvme-set-property.1 | 51 +++ Documentation/nvme-set-property.html | 814 +++++++++++++++++++++++++++++++++++ Documentation/nvme-set-property.txt | 34 ++ Documentation/nvme-show-regs.1 | 13 +- Documentation/nvme-show-regs.txt | 23 +- nvme-builtin.h | 3 +- nvme-ioctl.c | 94 ++++ nvme-ioctl.h | 2 + nvme-print.c | 134 +++--- nvme-print.h | 3 +- nvme.c | 77 +++- 11 files changed, 1173 insertions(+), 75 deletions(-) create mode 100644 Documentation/nvme-set-property.1 create mode 100644 Documentation/nvme-set-property.html create mode 100644 Documentation/nvme-set-property.txt
Signature · 1 line
2.11.1
PATCH v2 1/2 nvme-cli: add support to get properties for NVMe over Fabric
--- Documentation/nvme-show-regs.1 | 13 +++-- Documentation/nvme-show-regs.html | 24 +++++--- Documentation/nvme-show-regs.txt | 23 +++++--- nvme-builtin.h | 2 +- nvme-ioctl.c | 79 ++++++++++++++++++++++++++ nvme-ioctl.h | 1 + nvme-print.c | 115 +++++++++++++++++++++----------------- nvme-print.h | 2 +- nvme.c | 25 ++++++--- 9 files changed, 200 insertions(+), 84 deletions(-)
Documentation/nvme-show-regs.1 +7 -6
@@ -28,7 +28,7 @@ .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" -nvme-show-regs \- Reads and shows the defined NVMe controller registers\&. +nvme-show-regs \- Reads and shows the defined NVMe controller registers for NVMe over PCIe or the controller properties for NVMe over Fabrics\&. .SH "SYNOPSIS" .sp .nf
@@ -36,14 +36,15 @@ nvme-show-regs \- Reads and shows the defined NVMe controller registers\&. .fi .SH "DESCRIPTION" .sp -For the NVMe device given, sends an identify namespace command and provides the result and returned structure\&. +For the NVMe over PCIe device given, sends an identify namespace command and provides the result and returned structure\&. For the NVMe over Fabrics device given, sends a fabric command and provides the result and returned structure\&. .sp -The <device> parameter is mandatory and must be the nvme admin character device (ex: /dev/nvme0)\&. The program uses knowledge of the sysfs layout to map the device to the pci resource stored there and mmaps the memory to get access to the registers\&. +The <device> parameter is mandatory and must be the nvme admin character device (ex: /dev/nvme0)\&.For the NVMe over PCIe, the program uses knowledge of the sysfs layout to map the device to the pci resource stored there and mmaps the memory to get access to the registers\&. For NVMe over Fabrics, the programs sends a fabric command to get the properties of the target NVMe controller\&. Only the supported properties are displayed\&. + .SH "OPTIONS" .PP \-H, \-\-human\-readable .RS 4 -Display registers in human readable format\&. +Display registers or supported properties in human readable format\&. .RE .SH "EXAMPLES" .sp
@@ -55,7 +56,7 @@ Display registers in human readable format\&. .sp -1 .IP \(bu 2.3 .\} -Show the nvme pci controller registers in a binary format: +Show the NVMe over PCIe controller registers or the NVMe over Fabric controller properties in a binary format: .sp .if n \{\ .RS 4
@@ -76,7 +77,7 @@ Show the nvme pci controller registers in a binary format: .sp -1 .IP \(bu 2.3 .\} -Show the nvme pci controller registers in a human readable format: +Show the NVMe over PCIe controller registers or the NVMe over Fabric controller properties in a human readable format: .sp .if n \{\ .RS 4
Documentation/nvme-show-regs.html +15 -9
@@ -737,7 +737,7 @@ nvme-id-ns(1) Manual Page <h2>NAME</h2> <div class="sectionbody"> <p>nvme-show-regs - - Reads and shows the defined NVMe controller registers. + Reads and shows the defined NVMe controller registers for NVMe over PCIe or the contrller properties for NVMe over Fabrics. </p> </div> </div>
@@ -754,12 +754,16 @@ nvme-id-ns(1) Manual Page <div class="sect1"> <h2 id="_description">DESCRIPTION</h2> <div class="sectionbody"> -<div class="paragraph"><p>For the NVMe device given, sends an identify namespace command and -provides the result and returned structure.</p></div> +<div class="paragraph"><p>For the NVMe over PCIe device given, sends an identify +namespace command and provides the result and returned structure. For the NVMe +over Fabrics device given, sends a fabric command and provides the result and +returned structure.</p></div> <div class="paragraph"><p>The <device> parameter is mandatory and must be the nvme admin character -device (ex: /dev/nvme0). The program uses knowledge of the sysfs layout -to map the device to the pci resource stored there and mmaps the memory -to get access to the registers.</p></div> +device (ex: /dev/nvme0). For NVMe over PCIe, the program uses knowledge of the +sysfs layout to map the device to the pci resource stored there and mmaps the +memory to get access to the registers. For NVMe over Fabrics, the programs +sends a fabric command to get the properties of the target NVMe controller. +Only the supported properties are displayed.</p></div> </div> </div> <div class="sect1">
@@ -774,7 +778,7 @@ to get access to the registers.</p></div> </dt> <dd> <p> - Display registers in human readable format. + Display registers or supported properties in human readable format. </p> </dd> </dl></div>
@@ -786,7 +790,8 @@ to get access to the registers.</p></div> <div class="ulist"><ul> <li> <p> -Show the nvme pci controller registers in a binary format: +Show the NVMe over PCIe controller registers or the NVMe over Fabric controller +properties in a binary format: </p> <div class="listingblock"> <div class="content">
@@ -795,7 +800,8 @@ Show the nvme pci controller registers in a binary format: </li> <li> <p> -Show the nvme pci controller registers in a human readable format: +Show the NVMe over PCIe controller registers or the NVMe over Fabric controller +properties in a human readable format: </p> <div class="listingblock"> <div class="content">
Documentation/nvme-show-regs.txt +15 -8
@@ -3,7 +3,8 @@ nvme-id-ns(1) NAME ---- -nvme-show-regs - Reads and shows the defined NVMe controller registers. +nvme-show-regs - Reads and shows the defined NVMe controller registers for +NVMe over PCIe or the controller properties for NVMe over Fabrics. SYNOPSIS --------
@@ -12,29 +13,35 @@ SYNOPSIS DESCRIPTION ----------- -For the NVMe device given, sends an identify namespace command and +For the NVMe over PCIe device given, sends an identify namespace command and provides the result and returned structure. +For the NVMe over Fabrics device given, sends a fabric command and provides +the result and returned structure. The <device> parameter is mandatory and must be the nvme admin character -device (ex: /dev/nvme0). The program uses knowledge of the sysfs layout -to map the device to the pci resource stored there and mmaps the memory -to get access to the registers. +device (ex: /dev/nvme0). For NVMe over PCIe, the program uses knowledge of the +sysfs layout to map the device to the pci resource stored there and mmaps the +memory to get access to the registers. For NVMe over Fabrics, the programs +sends a fabric command to get the properties of the target NVMe controller. +Only the supported properties are displayed. OPTIONS ------- -H:: --human-readable:: - Display registers in human readable format. + Display registers or supported properties in human readable format. EXAMPLES -------- -* Show the nvme pci controller registers in a binary format: +* Show the NVMe over PCIe controller registers or the NVMe over Fabric controller +properties in a binary format: + ------------ # nvme show-regs /dev/nvme0 ------------ -* Show the nvme pci controller registers in a human readable format: +* Show the NVMe over PCIe controller registers or the NVMe over Fabric controller +properties in a human readable format: + ------------ # nvme show-regs /dev/nvme0 -H
nvme-builtin.h +1 -1
@@ -47,7 +47,7 @@ COMMAND_LIST( ENTRY("reset", "Resets the controller", reset) ENTRY("subsystem-reset", "Resets the controller", subsystem_reset) ENTRY("ns-rescan", "Rescans the NVME namespaces", ns_rescan) - ENTRY("show-regs", "Shows the controller registers. Requires admin character device", show_registers) + ENTRY("show-regs", "Shows the controller registers or properties. Requires character device", show_registers) ENTRY("discover", "Discover NVMeoF subsystems", discover_cmd) ENTRY("connect-all", "Discover and Connect to NVMeoF subsystems", connect_all_cmd)ENTRY ("connect" ,"Connect to NVMeoF subsystem" , connect_cmd)
nvme-ioctl.c +79 -0
85 lines not on this page · raw message
nvme-ioctl.h +1 -0
@@ -121,5 +121,6 @@ int nvme_dir_send(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper, __u32 data_len, __u32 dw12, void *data, __u32 *result);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);#endif /* _NVME_LIB_H */
nvme-print.c +65 -50
127 lines not on this page · raw message
nvme-print.h +1 -1
@@ -25,7 +25,7 @@ void show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges);void show_error_log (struct nvme_error_log_page *err_log,int entries,const char *devname);void show_smart_log (struct nvme_smart_log *smart,unsigned int nsid,const char *devname);void show_fw_log (struct nvme_firmware_log_page *fw_log,const char *devname); -void show_ctrl_registers (void *bar,unsigned int mode); +void show_ctrl_registers (void *bar,unsigned int mode,bool fabrics);void show_nvme_id_ns_descs (void *data);void nvme_feature_show_fields (__u32 fid,unsigned int result,unsigned char *buf);
nvme.c +16 -9
@@ -762,23 +762,23 @@ static char *nvme_char_from_block(char *block)static void *get_registers (void ) { -int pci_fd; +int fd;char *base, path[512 ];void *membase; base =nvme_char_from_block ((char *)devicename);sprintf (path,"/sys/class/nvme/%s/device/resource0" , base); - pci_fd =open (path,O_RDONLY ); -if (pci_fd <0 ) { + fd =open (path,O_RDONLY ); +if (fd <0 ) {sprintf (path,"/sys/class/misc/%s/device/resource0" , base); - pci_fd =open (path,O_RDONLY ); + fd =open (path,O_RDONLY ); } -if (pci_fd <0 ) { +if (fd <0 ) {fprintf (stderr,"%s did not find a pci resource\n" , base);return NULL ; } - membase =mmap (NULL ,getpagesize (),PROT_READ ,MAP_SHARED , pci_fd,0 ); + membase =mmap (NULL ,getpagesize (),PROT_READ ,MAP_SHARED , fd,0 );if (membase ==MAP_FAILED ) {fprintf (stderr,"%s failed to map\n" , base);return NULL ;
@@ -1620,7 +1620,8 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu"in binary or human-readable format" ;const char *human_readable ="show info in readable format" ;void *bar; -int fd; +int fd, err; +bool fabrics = true;struct config {int human_readable;
@@ -1639,11 +1640,17 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct pluif (fd <0 )return fd; - bar =get_registers (); + err =nvme_get_properties (fd, &bar); +if (err) { + bar =get_registers (); + fabrics = false; + }if (!bar)return ENODEV ; +show_ctrl_registers (bar, cfg.human_readable ?HUMAN :0 , fabrics); -show_ctrl_registers (bar, cfg.human_readable ?HUMAN :0 ); +if (fabrics) +free (bar);return 0 ; }
Signature · 1 line
2.11.1
PATCH v2 2/2 nvme-cli: support to set the property for NVMe over Fabric
In reply to 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
Documentation/nvme-set-property.1 new file +51 -0
@@ -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 <http://docbook.sf.net/> +.\" 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 <device> [\-\-offset=<offset> | \-n <nsid>] + [\-\-value=<val> | \-v <val>] +.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>, \-\-offset=<offset> +.RS 4 +The offset of the property\&. +.RE +.SH "EXAMPLES" +.RE +.SH "NVME" +.sp +Part of the nvme\-user suite
Documentation/nvme-set-property.html new file +814 -0
814 lines not on this page · raw message
Documentation/nvme-set-property.txt new file +34 -0
@@ -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' <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
nvme-builtin.h +1 -0
@@ -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
nvme-ioctl.c +20 -0
@@ -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) {
nvme-ioctl.h +1 -0
@@ -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 */
nvme-print.c +19 -0
@@ -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) {
nvme-print.h +1 -0
@@ -33,6 +33,7 @@ void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unschar *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);
nvme.c +52 -0
58 lines not on this page · raw message
Signature · 1 line
2.11.1
v2 cover nvme-cli: add options to set/get property of NVMf
In reply to Guan JunxiongQuoted 5 lines · Guan Junxiong
Hi all,
To make it easy to use, this two patches add the support to set/get the properties for NVMe over Fabric.
Quoted 8 lines
Patch 1/2 makes use of show-regs option which only supports PCIe previously to support NVMf.
Patch 2/2 adds new option named set-property to support setting the property of NVMf. IMO, it is the responsibility of kernel to try to avoid malicious operation such as setting NRSS from the user space. So I ignore this in the nvme-cli.Welcome any comments.
Thanks, I've applied both with some merge and asciidoc fixups.