Skip to contentSkip to conversation

nvme-cli: add support for directive command

PATCH New [email protected] 2 participants 6 messages Aug 11, 2017 – Aug 17, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20170811025053epcas2p1ec98081d04a0488a2c08836c909f368c@epcas2p1.samsung.com

#1 lore raw

PATCH 1/1 nvme-cli: add support for directive command

Directive is a feature introduced in NVMe v1.3 that allows host and NVM subsystem or controller information exchange, namely data lifetime hint for example. Information is transmitted using the Directive Send and Directive Receive commands.

This patch set allows control of the directive resources of a directive-enabled nvme device.

#2 lore raw

PATCH 1/2 nvme-cli: add nvme directive command support

From: "Kwan (Hingkwan) Huen-SSI" <[email protected]>

Signed-off-by Kwan (Hingkwan) Huen-SSI <kwan.huen at samsung.com>
---
 linux/nvme.h   |  35 ++++++++
 nvme-builtin.h |   2 +
 nvme-ioctl.c   |  41 +++++++++
 nvme-ioctl.h   |   5 ++
 nvme-print.c   |  59 ++++++++++++-
 nvme-print.h   |   1 +
 nvme.c         | 260 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 402 insertions(+), 1 deletion(-)
linux/nvme.h +35 -0
index 19354a5..44b8bd0 100644
@@ -253,6 +253,7 @@ enum {
 	NVME_CTRL_ONCS_WRITE_ZEROES		= 1 << 3,
 	NVME_CTRL_VWC_PRESENT			= 1 << 0,
 	NVME_CTRL_OACS_SEC_SUPP                 = 1 << 0,
+	NVME_CTRL_OACS_DIRECTIVES		= 1 << 5,
 	NVME_CTRL_OACS_DBBUF_SUPP		= 1 << 7,
 };
 
@@ -304,6 +305,19 @@ enum {
 };
 
 enum {
+	NVME_DIR_IDENTIFY		= 0x00,
+	NVME_DIR_STREAMS		= 0x01,
+	NVME_DIR_SND_ID_OP_ENABLE	= 0x01,
+	NVME_DIR_SND_ST_OP_REL_ID	= 0x01,
+	NVME_DIR_SND_ST_OP_REL_RSC	= 0x02,
+	NVME_DIR_RCV_ID_OP_PARAM	= 0x01,
+	NVME_DIR_RCV_ST_OP_PARAM	= 0x01,
+	NVME_DIR_RCV_ST_OP_STATUS	= 0x02,
+	NVME_DIR_RCV_ST_OP_RESOURCE	= 0x03,
+	NVME_DIR_ENDIR			= 0x01,
+};
+
+enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_META_EXT	= 0x10,
@@ -582,6 +596,7 @@ enum {
 	NVME_RW_PRINFO_PRCHK_APP	= 1 << 11,
 	NVME_RW_PRINFO_PRCHK_GUARD	= 1 << 12,
 	NVME_RW_PRINFO_PRACT		= 1 << 13,
+	NVME_RW_DTYPE_STREAMS		= 1 << 4,
 };
 
 struct nvme_dsm_cmd {
@@ -656,6 +671,8 @@ enum nvme_admin_opcode {
 	nvme_admin_download_fw		= 0x11,
 	nvme_admin_ns_attach		= 0x15,
 	nvme_admin_keep_alive		= 0x18,
+	nvme_admin_directive_send       = 0x19,
+	nvme_admin_directive_recv       = 0x1a,
 	nvme_admin_dbbuf		= 0x7C,
 	nvme_admin_format_nvm		= 0x80,
 	nvme_admin_security_send	= 0x81,
@@ -983,6 +1000,23 @@ struct nvme_dbbuf {
 	__u32			rsvd12[6];
 };
 
+struct nvme_directive_cmd {
+	__u8			opcode;
+	__u8			flags;
+	__u16			command_id;
+	__le32			nsid;
+	__u64			rsvd2[2];
+	union nvme_data_ptr	dptr;
+	__le32			numd;
+	__u8			doper;
+	__u8			dtype;
+	__le16			dspec;
+	__u8			endir;
+	__u8			tdtype;
+	__u16			rsvd15;
+	__u32			rsvd16[3];
+};
+
 struct nvme_command {
 	union {
 		struct nvme_common_command common;
@@ -1003,6 +1037,7 @@ struct nvme_command {
 		struct nvmf_property_set_command prop_set;
 		struct nvmf_property_get_command prop_get;
 		struct nvme_dbbuf dbbuf;
+		struct nvme_directive_cmd directive;
 	};
 };
 
nvme-builtin.h +2 -0
index 2143ffd..b24c25b 100644
@@ -52,6 +52,8 @@ COMMAND_LIST(
 	ENTRY("connect", "Connect to NVMeoF subsystem", connect_cmd)
 	ENTRY("disconnect", "Disconnect from NVMeoF subsystem", disconnect_cmd)
 	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)
 );
 
 #endif
nvme-ioctl.c +41 -0

44 lines not on this page · raw message

nvme-ioctl.h +5 -0
index 7818721..4aee90a 100644
@@ -116,4 +116,9 @@ int nvme_sec_recv(int fd, __u32 nsid, __u8 nssf, __u16 spsp,
 int nvme_subsystem_reset(int fd);
 int nvme_reset_controller(int fd);
 
+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);
+
 #endif				/* _NVME_LIB_H */
nvme-print.c +58 -1

77 lines not on this page · raw message

nvme-print.h +1 -0
index fd89c96..4cdcb95 100644
@@ -29,6 +29,7 @@ void show_ctrl_registers(void *bar, unsigned int mode);
 void show_nvme_id_ns_descs(void *data);
 
 void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf);
+void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf);
 char *nvme_status_to_string(__u32 status);
 char *nvme_select_to_string(int sel);
 char *nvme_feature_to_string(int feature);
nvme.c +260 -0

272 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH 2/2 nvme-cli: add documentation for directive commands

In reply to [email protected]

From: "Kwan (Hingkwan) Huen-SSI" <[email protected]>

Signed-off-by Kwan (Hingkwan) Huen-SSI <kwan.huen at samsung.com>
---
 Documentation/nvme-dir-receive.1    | 235 +++++++++
 Documentation/nvme-dir-receive.html | 975 +++++++++++++++++++++++++++++++++++
 Documentation/nvme-dir-receive.txt  | 118 +++++
 Documentation/nvme-dir-send.1       | 241 +++++++++
 Documentation/nvme-dir-send.html    | 988 ++++++++++++++++++++++++++++++++++++
 Documentation/nvme-dir-send.txt     | 124 +++++
 6 files changed, 2681 insertions(+)
 create mode 100644 Documentation/nvme-dir-receive.1
 create mode 100644 Documentation/nvme-dir-receive.html
 create mode 100644 Documentation/nvme-dir-receive.txt
 create mode 100644 Documentation/nvme-dir-send.1
 create mode 100644 Documentation/nvme-dir-send.html
 create mode 100644 Documentation/nvme-dir-send.txt
Documentation/nvme-dir-receive.1 new file +235 -0
new file mode 100644
index 0000000..7b6c1db
@@ -0,0 +1,235 @@
+'\" t
+.\"     Title: nvme-dir-receive
+.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
+.\"      Date: 08/10/2017
+.\"    Manual: NVMe Manual
+.\"    Source: NVMe
+.\"  Language: English
+.\"
+.TH "NVME\-DIR\-RECEIVE" "1" "08/10/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-dir-receive \- Send a directive receive command, returns applicable results
+.SH "SYNOPSIS"
+.sp
+.nf
+\fInvme dir\-receive\fR <device> [\-\-namespace\-id=<nsid> | \-n <nsid>]
+                          [\-\-data\-len=<data\-len> | \-l <data\-len>]
+                          [\-\-dir\-type=<dtype> | \-D <dtype>]
+                          [\-\-dir\-spec=<dspec> | \-S <dspec>]
+                          [\-\-dir\-oper=<doper> | \-O <doper>]
+                          [\-\-req\-resource=<nsr> | \-r <nsr>]
+                          [\-\-human\-readable | \-H]
+                          [\-\-raw\-binary | \-b]
+.fi
+.SH "DESCRIPTION"
+.sp
+Submits an NVMe Directive Receive admin command and returns the applicable results\&. This may be the combination of directive type, and operation, as well as number of requested resource if specific operation needs it\&.
+.sp
+The <device> parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&.
+.sp
+On success, the returned directive\(cqs parameter structure (if applicable) is returned in one of several ways depending on the option flags; the structure may parsed by the program and printed in a readable format if it is a known structure, displayed in hex, or the raw buffer may be printed to stdout for another program to parse\&.
+.SH "OPTIONS"
+.PP
+\-n <nsid>, \-\-namespace\-id=<nsid>
+.RS 4
+Retrieve the feature for the given nsid\&. This is optional and most features do not use this value\&.
+.RE
+.PP
+\-D <dtype>, \-\-dir\-type=<dtype>
+.RS 4
+Directive type
+.RE
+.PP
+\-S <dspec>, \-\-dir\-spec=<dspec>
+.RS 4
+Directive specific
+.RE
+.PP
+\-O <doper>, \-\-dir\-oper=<doper>
+.RS 4
+Directive operation
+.RE
+.PP
+\-r <nsr>, \-\-req\-resource=<nsr>
+.RS 4
+Directive requested resource count
+.RE
+.sp
++
+.TS
+allbox tab(:);
+lt lt
+lt lt
+lt lt
+lt lt
+lt lt
+lt lt.
+T{
+.sp
+Select
+T}:T{
+.sp
+Description
+T}
+T{
+.sp
+0
+T}:T{
+.sp
+Current
+T}
+T{
+.sp
+1
+T}:T{
+.sp
+Default
+T}
+T{
+.sp
+2
+T}:T{
+.sp
+Saved
+T}
+T{
+.sp
+3
+T}:T{
+.sp
+Supported capabilities
+T}
+T{
+.sp
+4\(en7
+T}:T{
+.sp
+Reserved
+T}
+.TE
+.sp 1
+.PP
+\-l <data\-len>, \-\-data\-len=<data\-len>
+.RS 4
+The data length for the buffer returned for this feature\&. Most known features do not use this value\&. The exception is LBA Range Type
+.RE
+.PP
+\-b, \-\-raw\-binary
+.RS 4
+Print the raw receive buffer to stdout if the command returns a structure\&.
+.RE
+.PP
+\-H, \-\-human\-readable
+.RS 4
+Print the decoded receive buffer to stdout if the command returns a structure\&.
+.RE
+.SH "EXAMPLES"
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Identify directive type supported :
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme dir\-receive /dev/nvme0 \-\-dir\-type 0 \-\-dir\-oper 1 \-\-human\-readable
+.fi
+.if n \{\
+.RE
+.\}
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Get stream directive parameters :
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme dir\-receive /dev/nvme0 \-\-dir\-type 1 \-\-dir\-oper 1 \-\-human\-readable
+.fi
+.if n \{\
+.RE
+.\}
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Allocate 3 streams for namespace 1
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme dir\-receive /dev/nvme0n1 \-\-dir\-type 1 \-\-dir\-oper 3 \-\-req\-resource 3 \-\-human\-readable
+.fi
+.if n \{\
+.RE
+.\}
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Get streams directive status :
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme dir\-receive /dev/nvme0 \-\-dir\-type 1 \-\-dir\-oper 2 \-\-human\-readable
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+It is probably a bad idea to not redirect stdout when using this mode\&.
+.RE
+.SH "NVME"
+.sp
+Part of the nvme\-user suite
Documentation/nvme-dir-receive.html new file +975 -0

975 lines not on this page · raw message

Documentation/nvme-dir-receive.txt new file +118 -0

118 lines not on this page · raw message

Documentation/nvme-dir-send.1 new file +241 -0

241 lines not on this page · raw message

Documentation/nvme-dir-send.html new file +988 -0

988 lines not on this page · raw message

Documentation/nvme-dir-send.txt new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH 1/1 nvme-cli: add support for directive command

In reply to [email protected]
Quoted 7 lines · On Thu, Aug 10, 2017@07:54:09PM -0700, [email protected] wrote:

Directive is a feature introduced in NVMe v1.3 that allows host and NVM subsystem or controller information exchange, namely data lifetime hint for example. Information is transmitted using the Directive Send and Directive Receive commands.

This patch set allows control of the directive resources of a directive-enabled nvme device.

The patches themselves look great, but I didn't realize this was a feature user-space should be accessing. Providing this could mess up the streams the kernel believes are set up, right?

#5 lore raw

PATCH 1/1 nvme-cli: add support for directive command

Quoted 13 lines

From: Keith Busch [mailto:keith.busch at intel.com]
Sent: Friday, August 11, 2017 10:03 AM
To: Kwan (Hingkwan) Huen <kwan.huen at samsung.com>
Cc: linux-nvme at lists.infradead.org; axboe at kernel.dk; Changho Choi <changho.c at samsung.com>; Vijay Balakrishnan <vijay.bala at samsung.com>
Subject: Re: [PATCH] nvme-cli: add support for directive command

Quoted 5 lines · On Thu, Aug 10, 2017@07:54:09PM -0700, [email protected] wrote:

Directive is a feature introduced in NVMe v1.3 that allows host and NVM subsystem or controller information exchange, namely data lifetime hint for example. Information is transmitted using the Directive Send and Directive Receive commands.

Quoted 6 lines
Quoted 2 lines

This patch set allows control of the directive resources of a directive-enabled nvme device.

The patches themselves look great, but I didn't realize this was a feature user- space should be accessing. Providing this could mess up the streams the kernel believes are set up, right?

Hi Keith,
Sorry for late!
That's a valid concern. But the only thing I can see, which potentially cause problem, is the stream directive enable/disable. With kernel enables and manages the streams, if the tool can disable it, it'll cause IO error because the device no longer takes stream write commands. I think we can disable this directive enable/disable in this patch for now to avoid this problem, until we have a better way to coordinate this with the driver.
Besides that, I think it is still valuable for the tool that allows users to quickly check the directive functionalities and get status. In addition, the patch also enables other features, e.g., users can allocate stream resources dedicated to namespace.
Regards,
kwan

#6 lore raw

PATCH 1/1 nvme-cli: add support for directive command

Quoted 20 lines · Kwan (Hingkwan) Huen
Quoted 13 lines

From: Keith Busch [mailto:keith.busch at intel.com]
Sent: Friday, August 11, 2017 10:03 AM
To: Kwan (Hingkwan) Huen <kwan.huen at samsung.com>
Cc: linux-nvme at lists.infradead.org; axboe at kernel.dk; Changho Choi <changho.c at samsung.com>; Vijay Balakrishnan <vijay.bala at samsung.com>
Subject: Re: [PATCH] nvme-cli: add support for directive command

Quoted 5 lines · On Thu, Aug 10, 2017@07:54:09PM -0700, [email protected] wrote:

Directive is a feature introduced in NVMe v1.3 that allows host and NVM subsystem or controller information exchange, namely data lifetime hint for example. Information is transmitted using the Directive Send and Directive Receive commands.

Quoted 6 lines
Quoted 2 lines

This patch set allows control of the directive resources of a directive-enabled nvme device.

The patches themselves look great, but I didn't realize this was a feature user- space should be accessing. Providing this could mess up the streams the kernel believes are set up, right?

Quoted 12 lines

Hi Keith,
Sorry for late!
That's a valid concern. But the only thing I can see, which potentially cause problem, is the stream directive enable/disable. With kernel enables and manages the streams, if the tool can disable it, it'll cause IO error because the device no longer takes stream write commands. I think we can disable this directive enable/disable in this patch for now to avoid this problem, until we have a better way to coordinate this with the driver.
Besides that, I think it is still valuable for the tool that allows users to quickly check the directive functionalities and get status. In addition, the patch also enables other features, e.g., users can allocate stream resources dedicated to namespace.

Okay, that sounds reasonable, and I've applied the patch as-is. The tool has always provided a means to break stuff anyway, so it's always been assumed that you're a responsible root user when executing it. :)

Thanks for the patches.