From: Gollu Appalanaidu Date: Wed, 8 Sep 2021 08:49:36 +0000 (+0530) Subject: add identify endurance group list (cns 0x19) support X-Git-Tag: v2.0-rc0~53^2~12 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b28d3263f0e30c5f4f291e6f164c3217c554d7a1;p=users%2Fsagi%2Fnvme-cli.git add identify endurance group list (cns 0x19) support Signed-off-by: Gollu Appalanaidu [dwagner: ported from monolitic, removed nvme-ioctl.h/nvme.h change, part of libnvme] Signed-off-by: Daniel Wagner --- diff --git a/Documentation/nvme-list-endgrp.1 b/Documentation/nvme-list-endgrp.1 new file mode 100644 index 00000000..a83b53ea --- /dev/null +++ b/Documentation/nvme-list-endgrp.1 @@ -0,0 +1,62 @@ +'\" t +.\" Title: nvme-list-endgrp +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.79.1 +.\" Date: 09/08/2021 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-LIST\-ENDGRP" "1" "09/08/2021" "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-list-endgrp \- Send NVMe Identify Endurance Group List, return result and structure +.SH "SYNOPSIS" +.sp +.nf +\fInvme list\-endgrp\fR [\-\-endgrp\-id= | \-i ] + [\-o | \-\-output\-format=] +.fi +.SH "DESCRIPTION" +.sp +For the NVMe device given, sends an identify command for endurance group list and provides the result and returned structure\&. +.sp +The parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. An Endurance Group List of up to 2,047 Endurance Group Identifiers in increasing order is returned containing an Endurance Group Identifier greater than or equal to the value specified in the CDW11\&.ENDGID field\&. +.SH "OPTIONS" +.PP +\-i , \-\-endgrp\-id= +.RS 4 +Retrieve the identify endurance group list structure starting for the given endurance group id\&. +.RE +.PP +\-o , \-\-output\-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\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-list-endgrp.html b/Documentation/nvme-list-endgrp.html new file mode 100644 index 00000000..33ba4d16 --- /dev/null +++ b/Documentation/nvme-list-endgrp.html @@ -0,0 +1,822 @@ + + + + + + +nvme-list-endgrp(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme list-endgrp <device> [--endgrp-id=<endgrp-id> | -i <endgrp-id>]
+                        [-o <fmt> | --output-format=<fmt>]
+
+
+
+
+
+

DESCRIPTION

+
+

For the NVMe device given, sends an identify command for endurance group list +and provides the result and returned structure.

+

The <device> parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). +An Endurance Group List of up to 2,047 Endurance Group Identifiers in +increasing order is returned containing an Endurance Group Identifier greater +than or equal to the value specified in the CDW11.ENDGID field.

+
+
+
+

OPTIONS

+
+
+
+-i <endgrp-id> +
+
+--endgrp-id=<endgrp-id> +
+
+

+ Retrieve the identify endurance group list structure starting for the given + endurance group id. +

+
+
+-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.

+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-list-endgrp.txt b/Documentation/nvme-list-endgrp.txt new file mode 100644 index 00000000..157dca98 --- /dev/null +++ b/Documentation/nvme-list-endgrp.txt @@ -0,0 +1,43 @@ +nvme-list-endgrp(1) +=================== + +NAME +---- +nvme-list-endgrp - Send NVMe Identify Endurance Group List, return result and structure + +SYNOPSIS +-------- +[verse] +'nvme list-endgrp' [--endgrp-id= | -i ] + [-o | --output-format=] + +DESCRIPTION +----------- +For the NVMe device given, sends an identify command for endurance group list +and provides the result and returned structure. + +The parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). +An Endurance Group List of up to 2,047 Endurance Group Identifiers in +increasing order is returned containing an Endurance Group Identifier greater +than or equal to the value specified in the CDW11.ENDGID field. + +OPTIONS +------- +-i :: +--endgrp-id=:: + Retrieve the identify endurance group list structure starting for the given + endurance group id. + +-o :: +--output-format=:: + Set the reporting format to 'normal' or 'json'. Only one output + format can be used at a time. + +EXAMPLES +-------- +No examples yet. + +NVME +---- +Part of the nvme-user suite diff --git a/completions/_nvme b/completions/_nvme index 3ce202fd..db13f6a8 100644 --- a/completions/_nvme +++ b/completions/_nvme @@ -19,6 +19,7 @@ _nvme () { 'detach-ns:detach namespace from controller' 'list-ctrl:identify all controller(s) attached' 'nvm-id-ctrl:display information about the nvm command set' + 'list-endgrp:display information about nvme endurance group list' 'get-ns-id:get namespace id of opened block device' 'get-log:retrieve any log in raw format' 'predictable-lat-log:retrieve predictable latency per nvmset log' @@ -152,6 +153,16 @@ _nvme () { _arguments '*:: :->subcmds' _describe -t commands "nvme nvm-id-ctrl options" _nvmidctrl ;; + (list-endgrp) + local _listendgrp + _listendgrp=( + /dev/nvme':supply a device to use (required)' + --endgrp-id=':endurance group id' + -i':alias of --endgrp-id' + ) + _arguments '*:: :->subcmds' + _describe -t commands "nvme list-ns options" _listendgrp + ;; (create-ns) local _createns _createns=( diff --git a/completions/bash-nvme-completion.sh b/completions/bash-nvme-completion.sh index 76088d5b..052566d0 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -178,6 +178,9 @@ nvme_list_opts () { "id-uuid") opts+=" --output-format= -o --raw-binary -b --human-readable -H" ;; + "list-endgrp") + opts+=" --endgrp-id= -i --output-format= -o" + ;; "id-iocs") opts+=" --controller-id= -c --output-format= -o --human-readable -H" ;; diff --git a/nvme-builtin.h b/nvme-builtin.h index 72f64cf2..fe00f44f 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -23,6 +23,7 @@ COMMAND_LIST( ENTRY("id-uuid", "Send NVMe Identify UUID List, display structure", id_uuid) ENTRY("id-iocs", "Send NVMe Identify I/O Command Set, display structure", id_iocs) ENTRY("id-domain", "Send NVMe Identify Domain List, display structure", id_domain) + ENTRY("list-endgrp", "Send NVMe Identify Endurance Group List, display structure", id_endurance_grp_list) ENTRY("create-ns", "Creates a namespace with the provided parameters", create_ns) ENTRY("delete-ns", "Deletes a namespace from the controller", delete_ns) ENTRY("attach-ns", "Attaches a namespace to requested controller(s)", attach_ns) diff --git a/nvme-print.c b/nvme-print.c index bae84fd1..e8487f0e 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -4925,6 +4925,47 @@ void nvme_show_id_domain_list(struct nvme_id_domain_list *id_dom, } } +static void json_nvme_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_list) +{ + 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_endgrp_id", + le16_to_cpu(endgrp_list->num)); + + for (i = 0; i < min(le16_to_cpu(endgrp_list->num), 2047); i++) { + valid_attrs = json_create_object(); + json_object_add_value_uint(valid_attrs, "endgrp_id", + le16_to_cpu(endgrp_list->identifier[i])); + json_array_add_value_object(valid, valid_attrs); + } + + json_object_add_value_array(root, "endgrp_list", valid); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); +} + +void nvme_show_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_list, + enum nvme_print_flags flags) +{ + int i; + __u16 num = le16_to_cpu(endgrp_list->num); + + if (flags & JSON) + return json_nvme_endurance_group_list(endgrp_list); + + printf("num of endurance group ids: %u\n", num); + for (i = 0; i < min(num, 2047); i++) { + printf("[%4u]:%#x\n", i, le16_to_cpu(endgrp_list->identifier[i])); + } +} + void nvme_show_id_iocs(struct nvme_id_iocs *iocs) { __u16 i; diff --git a/nvme-print.h b/nvme-print.h index d540c036..71b1a448 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -105,6 +105,8 @@ void nvme_show_list_ctrl(struct nvme_ctrl_list *ctrl_list, enum nvme_print_flags flags); void nvme_show_id_domain_list(struct nvme_id_domain_list *id_dom, enum nvme_print_flags flags); +void nvme_show_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_list, + enum nvme_print_flags flags); void nvme_show_list_ns(struct nvme_ns_list *ns_list, enum nvme_print_flags flags); diff --git a/nvme.c b/nvme.c index 9f3aaab4..303315ce 100644 --- a/nvme.c +++ b/nvme.c @@ -1834,6 +1834,67 @@ ret: return nvme_status_to_errno(err, false); } +static int id_endurance_grp_list(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + const char *desc = "Show endurance group list information for the given endurance "\ + "group id"; + const char *endurance_grp_id = "Endurance Group ID"; + int err = -1, fd; + struct nvme_id_endurance_group_list *endgrp_list; + enum nvme_print_flags flags; + + struct config { + __u16 endgrp_id; + char *output_format; + }; + + struct config cfg = { + .endgrp_id = 0, + .output_format = "normal", + }; + + OPT_ARGS(opts) = { + OPT_SHRT("endgrp-id", 'i', &cfg.endgrp_id, endurance_grp_id), + OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + OPT_END() + }; + + err = fd = parse_and_open(argc, argv, desc, opts); + 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; + fprintf(stderr, "invalid output format\n"); + goto close_fd; + } + + if (posix_memalign((void *)&endgrp_list, getpagesize(), 0x1000)) { + fprintf(stderr, "can not allocate memory for endurance gropu list\n"); + errno = ENOMEM; + err = -1; + goto close_fd; + } + + err = nvme_identify_endurance_group_list(fd, cfg.endgrp_id, endgrp_list); + if (!err) + nvme_show_endurance_group_list(endgrp_list, flags); + else if (err > 0) + nvme_show_status(err); + else + perror("id endurance group list"); + + free(endgrp_list); +close_fd: + close(fd); +ret: + return nvme_status_to_errno(err, false); +} + static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Delete the given namespace by "\