Skip to contentSkip to conversation

nvme-cli : Sanitize and Sanitize Log command support.

PATCH New Chaitanya Kulkarni 2 participants 7 messages Jun 29, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

HI,

This adds Sanitize and Sanitize-Log command support for nvme-cli. These four patches include command implementation, documentation, status codes and opcodes for the overall sanitize implementation.

For sanitize command specific option I've tested "-a <action>, --sanact=<action>" for block erase sanitize, overwrite sanitize on a real device, rest of the code I've added for the completeness.

Regards,
Chaitanya

#1 lore raw

PATCH 1/4 nvme-cli : add support for sanitize command.

This adds support for NVMe sanitize command execution including NVMe status codes, command opcode and help text.

For more details please refer to NVM Express 1.3 specification.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at hgst.com>
---
 linux/nvme.h   | 16 ++++++++++
 nvme-builtin.h |  1 +
 nvme-print.c   |  2 ++
 nvme.c         | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 111 insertions(+)
linux/nvme.h +16 -0
index c05d819..28ab9b8 100644
@@ -660,6 +660,7 @@ enum nvme_admin_opcode {
 	nvme_admin_format_nvm		= 0x80,
 	nvme_admin_security_send	= 0x81,
 	nvme_admin_security_recv	= 0x82,
+	nvme_admin_sanitize			= 0x84,
 };
 
 enum {
@@ -697,6 +698,18 @@ enum {
 	NVME_FWACT_ACTV		= (2 << 3),
 };
 
+/* Sanitize */
+enum {
+	NVME_SANITIZE_NO_DEALLOC		= 0x00000200,
+	NVME_SANITIZE_OIPBP				= 0x00000100,
+	NVME_SANITIZE_OWPASS_SHIFT		= 0x00000004,
+	NVME_SANITIZE_AUSE				= 0x00000008,
+	NVME_SANITIZE_ACT_CRYPTO_ERASE	= 0x00000004,
+	NVME_SANITIZE_ACT_OVERWRITE		= 0x00000003,
+	NVME_SANITIZE_ACT_BLOCK_ERASE	= 0x00000002,
+	NVME_SANITIZE_ACT_EXIT			= 0x00000001,
+};
+
 struct nvme_identify {
 	__u8			opcode;
 	__u8			flags;
@@ -1010,6 +1023,9 @@ enum {
 	NVME_SC_SGL_INVALID_OFFSET	= 0x16,
 	NVME_SC_SGL_INVALID_SUBTYPE	= 0x17,
 
+	NVME_SC_SANITIZE_FAILED			= 0x1C,
+	NVME_SC_SANITIZE_IN_PROGRESS	= 0x1D,
+
 	NVME_SC_LBA_RANGE		= 0x80,
 	NVME_SC_CAP_EXCEEDED		= 0x81,
 	NVME_SC_NS_NOT_READY		= 0x82,
nvme-builtin.h +1 -0
index 2bb01cb..b4cd3ba 100644
@@ -42,6 +42,7 @@ COMMAND_LIST(
 	ENTRY("write", "Submit a write command, return results", write_cmd)
 	ENTRY("write-zeroes", "Submit a write zeroes command, return results", write_zeroes)
 	ENTRY("write-uncor", "Submit a write uncorrectable command, return results", write_uncor)
+	ENTRY("sanitize", "Submit a sanitize command", sanitize)
 	ENTRY("reset", "Resets the controller", reset)
 	ENTRY("subsystem-reset", "Resets the controller", subsystem_reset)
 	ENTRY("show-regs", "Shows the controller registers. Requires admin character device", show_registers)
nvme-print.c +2 -0
index bf78d4a..f03382f 100644
@@ -1102,6 +1102,8 @@ char *nvme_status_to_string(__u32 status)
 	case NVME_SC_FUSED_MISSING:		return "FUSED_MISSING";
 	case NVME_SC_INVALID_NS:		return "INVALID_NS";
 	case NVME_SC_CMD_SEQ_ERROR:		return "CMD_SEQ_ERROR";
+	case NVME_SC_SANITIZE_FAILED:		return "SANITIZE_FAILED";
+	case NVME_SC_SANITIZE_IN_PROGRESS:	return "SANITIZE_IN_PROGRESS";
 	case NVME_SC_LBA_RANGE:			return "LBA_RANGE";
 	case NVME_SC_CAP_EXCEEDED:		return "CAP_EXCEEDED";
 	case NVME_SC_NS_NOT_READY:		return "NS_NOT_READY";
nvme.c +92 -0

98 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/4 nvme-cli : add support for sanitize command.

nvme.c static int reset(int argc, char **argv, struct command *cmd, struct plugin *plug · line 1467

Quoted 2 lines · Chaitanya Kulkarni
nvme.c +2 -0
+	const struct argconfig_commandline_options command_line_options[] = {
+		{"no_dealloc", 'd', "", CFG_NONE, &cfg.no_dealloc, no_argument, no_dealloc_desc},

Just a minor request, this tool uses '-' instead of '_' for compound word long options, and I think keeping that consistency is a good thing.

Otherwise, this looks great.

#3 lore raw

PATCH 1/4 nvme-cli : add support for sanitize command.

Quoted 6 lines · Keith Busch

nvme.c static int reset(int argc, char **argv, struct command *cmd, struct plugin *plug · line 1467

Quoted 2 lines · Chaitanya Kulkarni
nvme.c +2 -0
+	const struct argconfig_commandline_options command_line_options[] = {
+		{"no_dealloc", 'd', "", CFG_NONE, &cfg.no_dealloc, no_argument, no_dealloc_desc},

Just a minor request, this tool uses '-' instead of '_' for compound word long options, and I think keeping that consistency is a good thing.

Ah, it was just this one that used '_'. The documentation used '-' already. I made the fix in this patch and applied all of them.

Thanks!

#4 lore raw

PATCH 2/4 nvme-cli : add sanitize command documentation.

In reply to Chaitanya Kulkarni
Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at hgst.com>
---
 Documentation/nvme-sanitize.1    | 105 +++++
 Documentation/nvme-sanitize.html | 903 +++++++++++++++++++++++++++++++++++++++
 Documentation/nvme-sanitize.txt  |  93 ++++
 3 files changed, 1101 insertions(+)
 create mode 100644 Documentation/nvme-sanitize.1
 create mode 100644 Documentation/nvme-sanitize.html
 create mode 100644 Documentation/nvme-sanitize.txt
Documentation/nvme-sanitize.1 new file +105 -0
new file mode 100644
index 0000000..d984acd
@@ -0,0 +1,105 @@
+'\" t
+.\"     Title: nvme-sanitize
+.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
+.\"      Date: 06/28/2017
+.\"    Manual: NVMe Manual
+.\"    Source: NVMe
+.\"  Language: English
+.\"
+.TH "NVME\-SANITIZE" "1" "06/28/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-sanitize \- Send NVMe Sanitize Command, return result
+.SH "SYNOPSIS"
+.sp
+.nf
+\fInvme sanitize\fR <device> [\-\-no\-dealloc | \-d]
+              [\-\-oipbp | \-i]
+              [\-\-owpass=<overwrite\-pass\-count> | \-n <overwrite\-pass\-count>]
+              [\-\-ause | \-u]
+              [\-\-sanact=<action> | \-a <action>]
+              [\-\-ovrpat=<overwrite\-pattern> | \-p <overwrite\-pattern>]
+.fi
+.SH "DESCRIPTION"
+.sp
+For the NVMe device given, sends a Sanitize command and provides the result\&.
+.sp
+The <device> parameter is mandatory NVMe character device (ex: /dev/nvme0)\&.
+.sp
+On success it returns 0, error code otherwise\&.
+.SH "OPTIONS"
+.PP
+\-d, \-\-no\-delloc
+.RS 4
+No Deallocate After Sanitize: If set, then the controller shall not deallocate any logical blocks as a result of successfully completing the sanitize operation\&. If cleared, then the controller should deallocate logical blocks as a result of successfully completing the sanitize operation\&. This bit shall be ignored if the Sanitize Action field is set to 001b (i\&.e\&., Exit Failure Mode)\&.
+.RE
+.PP
+\-i, \-\-oipbp
+.RS 4
+Overwrite Invert Pattern Between Passes: If set, then the Overwrite Pattern shall be inverted between passes\&. If cleared, then the overwrite pattern shall not be inverted between passes\&. This bit shall be ignored unless the Sanitize Action field is set to 011b (i\&.e\&., Overwrite)\&.
+.RE
+.PP
+\-n <overwrite\-pass\-count>, \-\-owpass=<overwrite\-pass\-count>
+.RS 4
+Overwrite Pass Count: This field specifies the number of overwrite passes (i\&.e\&., how many times the media is to be overwritten) using the data from the Overwrite Pattern field of this command\&. A value of 0 specifies 16 overwrite passes\&. This field shall be ignored unless the Sanitize Action field is set to 011b (i\&.e\&., Overwrite)\&.
+.RE
+.PP
+\-u, \-\-ause
+.RS 4
+Allow Unrestricted Sanitize Exit: If set, then the sanitize operation is performed in unrestricted completion mode\&. If cleared then the sanitize operation is performed in restricted completion mode\&. This bit shall be ignored if the Sanitize Action field is set to 001b (i\&.e\&., Exit Failure Mode)\&.
+.RE
+.PP
+\-a <action>, \-\-sanact=<action>
+.RS 4
+Sanitize Action: 000b \- Reserved 001b \- Exit Failure Mode 010b \- Start a Block Erase sanitize operation 011b \- Start an Overwrite sanitize operation 100b \- Start a Crypto Erase sanitize operation
+.RE
+.PP
+\-p <overwrite\-pattern>, \-\-ovrpat=<overwrite\-pattern>
+.RS 4
+Overwrite Pattern: This field is ignored unless the Sanitize Action field in Command Dword 10 is set to 011b (i\&.e\&., Overwrite)\&. This field specifies a 32\-bit pattern that is used for the Overwrite sanitize operation\&.
+.RE
+.SH "EXAMPLES"
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Has the program issue Sanitize Command :
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme sanitize /dev/nvme0n1 \-a 0x02
+# nvme sanitize /dev/nvme0n1 \-\-sanact=0x01
+.fi
+.if n \{\
+.RE
+.\}
+.RE
+.SH "NVME"
+.sp
+Part of the nvme\-user suite\&.
Documentation/nvme-sanitize.html new file +903 -0

903 lines not on this page · raw message

Documentation/nvme-sanitize.txt new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/4 nvme-cli : add support for retrieving sanitize log.

In reply to Chaitanya Kulkarni

This adds support for retrieving and printing NVMe sanitize log page. For more details please look into NVM Express 1.3 specification.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at hgst.com>
---
 linux/nvme.h   | 23 +++++++++++++++++++++-
 nvme-builtin.h |  1 +
 nvme.c         | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 1 deletion(-)
linux/nvme.h +22 -1
index 28ab9b8..19354a5 100644
@@ -693,13 +693,15 @@ enum {
 	NVME_LOG_FW_SLOT	= 0x03,
 	NVME_LOG_DISC		= 0x70,
 	NVME_LOG_RESERVATION	= 0x80,
+	NVME_LOG_SANITIZE	= 0x81,
 	NVME_FWACT_REPL		= (0 << 3),
 	NVME_FWACT_REPL_ACTV	= (1 << 3),
 	NVME_FWACT_ACTV		= (2 << 3),
 };
 
-/* Sanitize */
+/* Sanitize and Sanitize Monitor/Log */
 enum {
+	/* Sanitize */
 	NVME_SANITIZE_NO_DEALLOC		= 0x00000200,
 	NVME_SANITIZE_OIPBP				= 0x00000100,
 	NVME_SANITIZE_OWPASS_SHIFT		= 0x00000004,
@@ -708,6 +710,15 @@ enum {
 	NVME_SANITIZE_ACT_OVERWRITE		= 0x00000003,
 	NVME_SANITIZE_ACT_BLOCK_ERASE	= 0x00000002,
 	NVME_SANITIZE_ACT_EXIT			= 0x00000001,
+
+	/* Sanitize Monitor/Log */
+	NVME_SANITIZE_LOG_DATA_LEN				= 0x0014,
+	NVME_SANITIZE_LOG_GLOBAL_DATA_ERASED	= 0x0100,
+	NVME_SANITIZE_LOG_STATUS_MASK			= 0x0007,
+	NVME_SANITIZE_LOG_NEVER_SANITIZED		= 0x0000,
+	NVME_SANITIZE_LOG_COMPLETED_SUCCESS		= 0x0001,
+	NVME_SANITIZE_LOG_IN_PROGESS			= 0x0002,
+	NVME_SANITIZE_LOG_COMPLETED_FAILED		= 0x0003,
 };
 
 struct nvme_identify {
@@ -832,6 +843,16 @@ struct nvme_get_log_page_command {
 	__u32			rsvd14[2];
 };
 
+/* Sanitize Log Page */
+struct nvme_sanitize_log_page {
+	__le16			progress;
+	__le16			status;
+	__le32			cdw10_info;
+	__le32			est_ovrwrt_time;
+	__le32			est_blk_erase_time;
+	__le32			est_crypto_erase_time;
+};
+
 /*
  * Fabrics subcommands.
  */
nvme-builtin.h +1 -0
index b4cd3ba..2143ffd 100644
@@ -43,6 +43,7 @@ COMMAND_LIST(
 	ENTRY("write-zeroes", "Submit a write zeroes command, return results", write_zeroes)
 	ENTRY("write-uncor", "Submit a write uncorrectable command, return results", write_uncor)
 	ENTRY("sanitize", "Submit a sanitize command", sanitize)
+	ENTRY("sanitize-log", "Retrive sanitize log, show it", sanitize_log)
 	ENTRY("reset", "Resets the controller", reset)
 	ENTRY("subsystem-reset", "Resets the controller", subsystem_reset)
 	ENTRY("show-regs", "Shows the controller registers. Requires admin character device", show_registers)
nvme.c +62 -0

68 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

PATCH 4/4 nvme-cli : add sanitize-log command documentation.

In reply to Chaitanya Kulkarni
Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at hgst.com>
---
 Documentation/nvme-sanitize-log.1    | 126 ++++++
 Documentation/nvme-sanitize-log.html | 848 +++++++++++++++++++++++++++++++++++
 Documentation/nvme-sanitize-log.txt  |  67 +++
 3 files changed, 1041 insertions(+)
 create mode 100644 Documentation/nvme-sanitize-log.1
 create mode 100644 Documentation/nvme-sanitize-log.html
 create mode 100644 Documentation/nvme-sanitize-log.txt
Documentation/nvme-sanitize-log.1 new file +126 -0
new file mode 100644
index 0000000..d31dc69
@@ -0,0 +1,126 @@
+'\" t
+.\"     Title: nvme-sanitize-log
+.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
+.\"      Date: 06/28/2017
+.\"    Manual: NVMe Manual
+.\"    Source: NVMe
+.\"  Language: English
+.\"
+.TH "NVME\-SANITIZE\-LOG" "1" "06/28/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-sanitize-log \- Send NVMe sanitize\-log Command, return result
+.SH "SYNOPSIS"
+.sp
+.nf
+\fInvme sanitize\-log\fR <device>
+.fi
+.SH "DESCRIPTION"
+.sp
+Retrieves the NVMe Sanitize log page from an NVMe device and provides the status of sanitize command\&.
+.sp
+The <device> parameter is mandatory NVMe character device (ex: /dev/nvme0)\&.
+.sp
+Expected status and description :\-
+.TS
+allbox tab(:);
+ltB ltB.
+T{
+Status Code
+T}:T{
+Description
+T}
+.T&
+lt lt
+lt lt
+lt lt
+lt lt
+lt lt.
+T{
+.sp
+0x0000
+T}:T{
+.sp
+NVM subsystem has never been sanitized\&.
+T}
+T{
+.sp
+0x0001
+T}:T{
+.sp
+The most recent sanitize operation completed successfully\&.
+T}
+T{
+.sp
+0x0002
+T}:T{
+.sp
+A sanitize operation is currently in progress\&.
+T}
+T{
+.sp
+0x0003
+T}:T{
+.sp
+The most recent sanitize operation failed\&.
+T}
+T{
+.sp
+0x0100
+T}:T{
+.sp
+Global Data Erased bit If set to 1 then non\-volatile storage in the NVM subsystem has not been written to: a) since being manufactured and the NVM subsystem has never been sanitized; or b) since the most recent successful sanitize operation\&. If cleared to 0, then non\-volatile storage in the NVM subsystem has been written to: a) since being manufactured and the NVM subsystem has never been sanitized; or b) since the most recent successful sanitize operation of the NVM subsystem\&.
+T}
+.TE
+.sp 1
+.sp
+Sanitize Progress \- percentage complete
+.sp
+On success it returns 0, error code otherwise\&.
+.SH "OPTIONS"
+.sp
+No options yet\&.
+.SH "EXAMPLES"
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Has the program issue Sanitize\-log Command :
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme sanitize\-log /dev/nvme0
+.fi
+.if n \{\
+.RE
+.\}
+.RE
+.SH "NVME"
+.sp
+Part of the nvme\-user suite\&.
Documentation/nvme-sanitize-log.html new file +848 -0

848 lines not on this page · raw message

Documentation/nvme-sanitize-log.txt new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.7.4