'\" t
.\" Title: nvme-id-ns
-.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
-.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\" Date: 10/20/2020
+.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
+.\" Date: 05/16/2021
.\" Manual: NVMe Manual
.\" Source: NVMe
.\" Language: English
.\"
-.TH "NVME\-ID\-NS" "1" "10/20/2020" "NVMe" "NVMe Manual"
+.TH "NVME\-ID\-NS" "1" "05/16/2021" "NVMe" "NVMe Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.nf
\fInvme list\-ns\fR <device> [\-\-namespace\-id=<nsid> | \-n <nsid>]
[\-\-csi=<command_set_identifier> | \-y <command_set_identifier>]
- [\-\-all | \-a]
+ [\-\-all | \-a] [\-\-output\-format=<fmt> | \-o <fmt>]
.fi
.SH "DESCRIPTION"
.sp
.RS 4
Retrieve the identify list structure for all namespaces in the subsystem, whether attached or inactive\&.
.RE
+.PP
+\-o <format>, \-\-output\-format=<format>
+.RS 4
+Set the reporting format to
+\fInormal\fR, or
+\fIjson\fR\&. Only one output format can be used at a time\&.
+.RE
.SH "EXAMPLES"
.sp
-No examples yet\&.
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Print the namespaces present for zoned command set in JSON format
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme list\-ns /dev/nvme0 \-y 2 \-a \-o json
+.fi
+.if n \{\
+.RE
+.\}
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Print the namespaces present for NVM Command Set in normal format
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+# nvme list\-ns /dev/nvme0
+.fi
+.if n \{\
+.RE
+.\}
+.RE
.SH "NVME"
.sp
Part of the nvme\-user suite
<div class="verseblock">\r
<pre class="content"><em>nvme list-ns</em> <device> [--namespace-id=<nsid> | -n <nsid>]\r
[--csi=<command_set_identifier> | -y <command_set_identifier>]\r
- [--all | -a]</pre>\r
+ [--all | -a] [--output-format=<fmt> | -o <fmt>]</pre>\r
<div class="attribution">\r
</div></div>\r
</div>\r
subsystem, whether attached or inactive.\r
</p>\r
</dd>\r
+<dt class="hdlist1">\r
+-o <format>\r
+</dt>\r
+<dt class="hdlist1">\r
+--output-format=<format>\r
+</dt>\r
+<dd>\r
+<p>\r
+ Set the reporting format to <em>normal</em>, or <em>json</em>.\r
+ Only one output format can be used at a time.\r
+</p>\r
+</dd>\r
</dl></div>\r
</div>\r
</div>\r
<div class="sect1">\r
<h2 id="_examples">EXAMPLES</h2>\r
<div class="sectionbody">\r
-<div class="paragraph"><p>No examples yet.</p></div>\r
+<div class="ulist"><ul>\r
+<li>\r
+<p>\r
+Print the namespaces present for zoned command set in JSON format\r
+</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><code># nvme list-ns /dev/nvme0 -y 2 -a -o json</code></pre>\r
+</div></div>\r
+</li>\r
+<li>\r
+<p>\r
+Print the namespaces present for NVM Command Set in normal format\r
+</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><code># nvme list-ns /dev/nvme0</code></pre>\r
+</div></div>\r
+</li>\r
+</ul></div>\r
</div>\r
</div>\r
<div class="sect1">\r
<div id="footer">\r
<div id="footer-text">\r
Last updated\r
- 2020-05-06 10:35:44 CEST\r
+ 2021-05-16 10:13:29 IST\r
</div>\r
</div>\r
</body>\r
[verse]
'nvme list-ns' <device> [--namespace-id=<nsid> | -n <nsid>]
[--csi=<command_set_identifier> | -y <command_set_identifier>]
- [--all | -a]
+ [--all | -a] [--output-format=<fmt> | -o <fmt>]
DESCRIPTION
-----------
Retrieve the identify list structure for all namespaces in the
subsystem, whether attached or inactive.
+-o <format>::
+--output-format=<format>::
+ Set the reporting format to 'normal', or 'json'.
+ Only one output format can be used at a time.
+
EXAMPLES
--------
-No examples yet.
+* Print the namespaces present for zoned command set in JSON format
++
+------------
+# nvme list-ns /dev/nvme0 -y 2 -a -o json
+------------
+
+* Print the namespaces present for NVM Command Set in normal format
++
+------------
+# nvme list-ns /dev/nvme0
+------------
NVME
----
}
}
+static void json_nvme_list_ns(__u32 *ns_list)
+{
+ struct json_object *root;
+ struct json_object *valid_attrs;
+ struct json_object *valid;
+ int i;
+
+ root = json_create_object();
+ valid = json_create_array();
+
+ for (i = 0; i < 1024; i++) {
+ if (ns_list[i]) {
+ valid_attrs = json_create_object();
+ json_object_add_value_uint(valid_attrs, "nsid",
+ le32_to_cpu(ns_list[i]));
+ json_array_add_value_object(valid, valid_attrs);
+ }
+ }
+ json_object_add_value_array(root, "nsid_list", valid);
+ json_print_object(root, NULL);
+ printf("\n");
+ json_free_object(root);
+}
+
+void nvme_show_list_ns(__u32 *ns_list, enum nvme_print_flags flags)
+{
+ int i;
+ if (flags & JSON)
+ return json_nvme_list_ns(ns_list);
+
+ for (i = 0; i < 1024; i++) {
+ if (ns_list[i])
+ printf("[%4u]:%#x\n", i, le32_to_cpu(ns_list[i]));
+ }
+}
+
void nvme_show_zns_changed(struct nvme_zns_changed_zone_log *log,
unsigned long flags)
{
void nvme_show_id_iocs(struct nvme_id_iocs *iocs);
void nvme_show_list_ctrl(struct nvme_controller_list *ctrl_list,
enum nvme_print_flags flags);
+void nvme_show_list_ns(__u32 *ns_list, enum nvme_print_flags flags);
void nvme_feature_show_fields(enum nvme_feat fid, unsigned int result, unsigned char *buf);
void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result,
const char *namespace_id = "first nsid returned list should start from";
const char *csi = "I/O command set identifier";
const char *all = "show all namespaces in the subsystem, whether attached or inactive";
- int err, i, fd;
+ int err, fd;
__le32 ns_list[1024];
+ enum nvme_print_flags flags;
struct config {
__u32 namespace_id;
int all;
__u8 csi;
+ char *output_format;
};
struct config cfg = {
.namespace_id = 1,
+ .output_format = "normal",
};
OPT_ARGS(opts) = {
- OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
- OPT_BYTE("csi", 'y', &cfg.csi, csi),
- OPT_FLAG("all", 'a', &cfg.all, all),
+ OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
+ OPT_BYTE("csi", 'y', &cfg.csi, csi),
+ OPT_FLAG("all", 'a', &cfg.all, all),
+ OPT_FMT("output-format", 'o', &cfg.output_format, output_format_no_binary),
OPT_END()
};
if (fd < 0)
goto ret;
+ err = flags = validate_output_format(cfg.output_format);
+ if (flags < 0)
+ goto close_fd;
+ if (flags != JSON && flags != NORMAL) {
+ err = -EINVAL;
+ goto close_fd;
+ }
+
if (!cfg.namespace_id) {
err = -EINVAL;
fprintf(stderr, "invalid nsid parameter\n");
err = nvme_identify_ns_list_csi(fd, cfg.namespace_id - 1, cfg.csi,
!!cfg.all, ns_list);
- if (!err) {
- for (i = 0; i < 1024; i++)
- if (ns_list[i])
- printf("[%4u]:%#x\n", i, le32_to_cpu(ns_list[i]));
- } else if (err > 0)
+ if (!err)
+ nvme_show_list_ns(ns_list, flags);
+ else if (err > 0)
nvme_show_status(err);
else
perror("id namespace list");