'\" 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
.\" -----------------------------------------------------------------
.sp
.nf
\fInvme list\-ctrl\fR <device> [\-\-cntid=<cntid> | \-c <cntid>]
- [\-\-namespace\-id=<nsid> | \-n <nsid>]
+ [\-\-namespace\-id=<nsid> | \-n <nsid>] [\-o <fmt> | \-\-output\-format=<fmt>]
DESCRIPTION
.fi
.sp
.RS 4
If provided, will request the controllers attached to the specified namespace\&. If no namespace is given, or set to 0, the command requests the controller list for the entire subsystem, whether or not they are attached to namespace(s)\&.
.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\&.
+<?xml version="1.0" encoding="UTF-8"?>\r
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
<head>\r
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />\r
-<meta name="generator" content="AsciiDoc 8.6.8" />\r
+<meta name="generator" content="AsciiDoc 8.6.10" />\r
<title>nvme-id-ns(1)</title>\r
<style type="text/css">\r
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */\r
padding: 0;\r
margin: 0;\r
}\r
-\r
+pre {\r
+ white-space: pre-wrap;\r
+}\r
\r
#author {\r
color: #527bbd;\r
}\r
\r
div.imageblock div.content { padding-left: 0; }\r
-span.image img { border-style: none; }\r
+span.image img { border-style: none; vertical-align: text-bottom; }\r
a.image:visited { color: white; }\r
\r
dl {\r
p.table {\r
margin-top: 0;\r
}\r
-/* Because the table frame attribute is overridden by CSS in most browsers. */\r
+/* Because the table frame attribute is overriden by CSS in most browsers. */\r
div.tableblock > table[frame="void"] {\r
border-style: none;\r
}\r
<div class="sectionbody">\r
<div class="verseblock">\r
<pre class="content"><em>nvme list-ctrl</em> <device> [--cntid=<cntid> | -c <cntid>]\r
- [--namespace-id=<nsid> | -n <nsid>]\r
+ [--namespace-id=<nsid> | -n <nsid>] [-o <fmt> | --output-format=<fmt>]\r
DESCRIPTION</pre>\r
<div class="attribution">\r
</div></div>\r
whether or not they are attached to namespace(s).\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>. Only one output\r
+ format can be used at a time.\r
+</p>\r
+</dd>\r
</dl></div>\r
</div>\r
</div>\r
<div id="footnotes"><hr /></div>\r
<div id="footer">\r
<div id="footer-text">\r
-Last updated 2016-05-16 12:47:42 EDT\r
+Last updated\r
+ 2021-05-16 13:00:43 IST\r
</div>\r
</div>\r
</body>\r
--------
[verse]
'nvme list-ctrl' <device> [--cntid=<cntid> | -c <cntid>]
- [--namespace-id=<nsid> | -n <nsid>]
+ [--namespace-id=<nsid> | -n <nsid>] [-o <fmt> | --output-format=<fmt>]
DESCRIPTION
-----------
For the NVMe device given, sends an identify command for controller list
command requests the controller list for the entire subsystem,
whether or not they are attached to namespace(s).
+-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.
}
}
+static void json_nvme_list_ctrl(struct nvme_controller_list *ctrl_list, __u16 num)
+{
+ struct json_object *root;
+ struct json_object *valid_attrs;
+ struct json_object *valid;
+ int i;
+
+ root = json_create_object();
+ valid = json_create_array();
+
+ json_object_add_value_uint(root, "num_ctrl",
+ le16_to_cpu(ctrl_list->num));
+
+ for (i = 0; i < min(num, 2047); i++) {
+
+ valid_attrs = json_create_object();
+ json_object_add_value_uint(valid_attrs, "ctrl_id",
+ le16_to_cpu(ctrl_list->identifier[i]));
+ json_array_add_value_object(valid, valid_attrs);
+ }
+
+ json_object_add_value_array(root, "ctrl_list", valid);
+ json_print_object(root, NULL);
+ printf("\n");
+ json_free_object(root);
+}
+
+void nvme_show_list_ctrl(struct nvme_controller_list *ctrl_list,
+ enum nvme_print_flags flags)
+{
+ int i;
+ __u16 num = le16_to_cpu(ctrl_list->num);
+
+ if (flags & JSON)
+ return json_nvme_list_ctrl(ctrl_list, num);
+
+ printf("num of ctrls present: %u\n", num);
+ for (i = 0; i < min(num, 2047); i++) {
+ printf("[%4u]:%#x\n", i, le16_to_cpu(ctrl_list->identifier[i]));
+ }
+}
+
static void json_nvme_id_nvmset(struct nvme_id_nvmset *nvmset)
{
__u32 nent = nvmset->nid;
void nvme_show_id_uuid_list(const struct nvme_id_uuid_list *uuid_list,
enum nvme_print_flags 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_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,
"given device is part of, or optionally controllers attached to a specific namespace.";
const char *controller = "controller to display";
const char *namespace_id = "optional namespace attached to controller";
- int err, i, fd;
+ int err, fd;
struct nvme_controller_list *cntlist;
+ enum nvme_print_flags flags;
struct config {
__u16 cntid;
__u32 namespace_id;
+ char *output_format;
};
struct config cfg = {
.cntid = 0,
+ .output_format = "normal",
};
OPT_ARGS(opts) = {
- OPT_SHRT("cntid", 'c', &cfg.cntid, controller),
- OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
+ OPT_SHRT("cntid", 'c', &cfg.cntid, controller),
+ OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
+ OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
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 (posix_memalign((void *)&cntlist, getpagesize(), 0x1000)) {
fprintf(stderr, "can not allocate controller list payload\n");
err = -ENOMEM;
}
err = nvme_identify_ctrl_list(fd, cfg.namespace_id, cfg.cntid, cntlist);
- if (!err) {
- __u16 num = le16_to_cpu(cntlist->num);
-
- for (i = 0; i < (min(num, 2048)); i++)
- printf("[%4u]:%#x\n", i, le16_to_cpu(cntlist->identifier[i]));
- } else if (err > 0)
+ if (!err)
+ nvme_show_list_ctrl(cntlist, flags);
+ else if (err > 0)
nvme_show_status(err);
else
perror("id controller list");