From: Keith Busch
Date: Mon, 8 Jun 2015 18:53:09 +0000 (-0600)
Subject: Add delete namespace sub command
X-Git-Tag: v0.1~33
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3907b17750ce2317fbecf118bbabcfd391c088da;p=users%2Fsagi%2Fnvme-cli.git
Add delete namespace sub command
Signed-off-by: Keith Busch
---
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 8a8a681e..07afbf4e 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -140,6 +140,9 @@ clean:
$(RM) manpage-base-url.xsl
$(RM) *~
+clobber: clean
+ $(RM) *.html *.1
+
%.1 : %.xml
$(QUIET_XMLTO)$(RM) $@ && \
$(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
diff --git a/Documentation/cmds-main.txt b/Documentation/cmds-main.txt
index edfb3e3f..3d2134e8 100644
--- a/Documentation/cmds-main.txt
+++ b/Documentation/cmds-main.txt
@@ -43,6 +43,12 @@ linknvme:nvme-id-ctrl[1]::
linknvme:nvme-id-ns[1]::
Identify Namespace
+linknvme:nvme-create-ns[1]::
+ Create a new namespace
+
+linknvme:nvme-delete-ns[1]::
+ Delete existing namespace
+
linknvme:nvme-io-passthru[1]::
IO Passthrough Command
diff --git a/Documentation/nvme-delete-ns.1 b/Documentation/nvme-delete-ns.1
new file mode 100644
index 00000000..c8829418
--- /dev/null
+++ b/Documentation/nvme-delete-ns.1
@@ -0,0 +1,53 @@
+'\" t
+.\" Title: nvme-id-ns
+.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.76.1
+.\" Date: 06/08/2015
+.\" Manual: NVMe Manual
+.\" Source: NVMe
+.\" Language: English
+.\"
+.TH "NVME\-ID\-NS" "1" "06/08/2015" "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-delete-ns \- Send NVMe Namespace Management delete namespace command, return result\&.
+.SH "SYNOPSIS"
+.sp
+.nf
+\fInvme id\-ns\fR [\-\-namespace\-id= | \-n ]
+.fi
+.SH "DESCRIPTION"
+.sp
+For the NVMe device given, sends an nvme namespace management command to delete the requested namespace and provides the result\&.
+.sp
+The parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. The \*(Aq\-\-namespace\-id\*(Aq option is mandatory\&.
+.SH "OPTIONS"
+.PP
+\-n , \-\-namespace\-id=
+.RS 4
+The namespace identifier to delete\&.
+.RE
+.SH "EXAMPLES"
+.sp
+No examples yet\&.
+.SH "NVME"
+.sp
+Part of the nvme\-user suite
diff --git a/Documentation/nvme-delete-ns.html b/Documentation/nvme-delete-ns.html
new file mode 100644
index 00000000..a6d80194
--- /dev/null
+++ b/Documentation/nvme-delete-ns.html
@@ -0,0 +1,808 @@
+
+
+
+
+
+nvme-id-ns(1)
+
+
+
+
+
+
+
+
SYNOPSIS
+
+
+
nvme id-ns <device> [--namespace-id=<nsid> | -n <nsid>]
+
+
+
+
+
+
DESCRIPTION
+
+
For the NVMe device given, sends an nvme namespace management command
+to delete the requested namespace and provides the result.
+
The <device> parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
+The '--namespace-id' option is mandatory.
+
+
+
+
OPTIONS
+
+
+-
+-n <nsid>
+
+-
+--namespace-id=<nsid>
+
+-
+
+ The namespace identifier to delete.
+
+
+
+
+
+
+
+
NVME
+
+
Part of the nvme-user suite
+
+
+
+
+
+
+
diff --git a/Documentation/nvme-delete-ns.txt b/Documentation/nvme-delete-ns.txt
new file mode 100644
index 00000000..d22553f1
--- /dev/null
+++ b/Documentation/nvme-delete-ns.txt
@@ -0,0 +1,34 @@
+nvme-id-ns(1)
+=============
+
+NAME
+----
+nvme-delete-ns - Send NVMe Namespace Management delete namespace command, return result.
+
+SYNOPSIS
+--------
+[verse]
+'nvme id-ns' [--namespace-id= | -n ]
+
+DESCRIPTION
+-----------
+For the NVMe device given, sends an nvme namespace management command
+to delete the requested namespace and provides the result.
+
+The parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
+The `'--namespace-id'` option is mandatory.
+
+OPTIONS
+-------
+-n ::
+--namespace-id=::
+ The namespace identifier to delete.
+
+EXAMPLES
+--------
+No examples yet.
+
+NVME
+----
+Part of the nvme-user suite
diff --git a/Documentation/nvme.1 b/Documentation/nvme.1
index e8193c6d..ec4857e1 100644
--- a/Documentation/nvme.1
+++ b/Documentation/nvme.1
@@ -120,6 +120,16 @@ Identify Controller
Identify Namespace
.RE
.PP
+\fBnvme-create-ns\fR(1)
+.RS 4
+Create a new namespace
+.RE
+.PP
+\fBnvme-delete-ns\fR(1)
+.RS 4
+Delete existing namespace
+.RE
+.PP
\fBnvme-io-passthru\fR(1)
.RS 4
IO Passthrough Command
diff --git a/Documentation/nvme.html b/Documentation/nvme.html
index 997c69c7..ca7b3ab1 100644
--- a/Documentation/nvme.html
+++ b/Documentation/nvme.html
@@ -903,6 +903,22 @@ available, run "nvme help".
+nvme-create-ns(1)
+
+
+
+ Create a new namespace
+
+
+
+nvme-delete-ns(1)
+
+
+
+ Delete existing namespace
+
+
+
nvme-io-passthru(1)
diff --git a/Makefile b/Makefile
index 5fde468b..6591e218 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,7 @@ clean:
$(MAKE) -C Documentation clean
clobber: clean
+ $(MAKE) -C Documentation clobber
install: default
$(MAKE) -C Documentation install
diff --git a/nvme.c b/nvme.c
index 0accfcda..35d79988 100644
--- a/nvme.c
+++ b/nvme.c
@@ -61,7 +61,7 @@ static const char *devicename;
ENTRY(ID_NS, "id-ns", "Send NVMe Identify Namespace, display structure", id_ns) \
ENTRY(LIST_NS, "list-ns", "Send NVMe Identify List, display structure", list_ns) \
ENTRY(CREATE_NS, "create-ns", "Creates a namespace with the provided parameters", create_ns) \
- ENTRY(DELETE_NS, "create-ns", "Deletes a namespace from the controller", delete_ns) \
+ ENTRY(DELETE_NS, "delete-ns", "Deletes a namespace from the controller", delete_ns) \
ENTRY(LIST_CTRL, "list-ctrl", "Send NVMe Identify Controller List, display structure", list_ctrl) \
ENTRY(GET_NS_ID, "get-ns-id", "Retrieve the namespace ID of opened block device", get_ns_id) \
ENTRY(GET_LOG, "get-log", "Generic NVMe get log, returns log in raw format", get_log) \
@@ -1232,7 +1232,44 @@ static int list_ns(int argc, char **argv)
static int delete_ns(int argc, char **argv)
{
- return 0;
+ struct nvme_admin_cmd cmd;
+ int err;
+
+ struct config {
+ __u32 namespace_id;
+ };
+ struct config cfg;
+
+ const struct config defaults = {
+ .namespace_id = 0,
+ };
+
+ const struct argconfig_commandline_options command_line_options[] = {
+ {"namespace-id", "NUM", CFG_POSITIVE, &defaults.namespace_id, required_argument, NULL},
+ {"n", "NUM", CFG_POSITIVE, &defaults.namespace_id, required_argument, NULL},
+ };
+ argconfig_parse(argc, argv, "delete_ns", command_line_options,
+ &defaults, &cfg, sizeof(cfg));
+
+ if (!cfg.namespace_id) {
+ fprintf(stderr, "%s: namespace-id parameter required\n",
+ commands[DELETE_NS].name);
+ return EINVAL;
+ }
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = nvme_admin_ns_mgmt;
+ cmd.nsid = cfg.namespace_id;
+ cmd.cdw10 = 1;
+
+ err = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
+ if (!err)
+ printf("%s: Success, deleted nsid:%d\n", commands[DELETE_NS].name,
+ cfg.namespace_id);
+ else if (err > 0)
+ fprintf(stderr, "NVMe Status:%s(%x)\n",
+ nvme_status_to_string(err), err);
+ return err;
}
static int create_ns(int argc, char **argv)