From f8d754dd9d6a9f9c2149d7dd0fe2e9ee0badaf6e Mon Sep 17 00:00:00 2001 From: Arunpandian J Date: Thu, 20 Jan 2022 14:27:07 +0530 Subject: [PATCH] nvme: Add Media Unit Status log page(LID: 0x10) Reviewed-by: Steven Seungcheol Lee Signed-off-by: Arunpandian J --- Documentation/nvme-media-unit-stat-log.1 | 67 ++ Documentation/nvme-media-unit-stat-log.html | 831 ++++++++++++++++++++ Documentation/nvme-media-unit-stat-log.txt | 47 ++ completions/_nvme | 15 +- completions/bash-nvme-completion.sh | 6 +- nvme-builtin.h | 1 + nvme-print.c | 67 ++ nvme-print.h | 2 + nvme.c | 54 ++ 9 files changed, 1088 insertions(+), 2 deletions(-) create mode 100644 Documentation/nvme-media-unit-stat-log.1 create mode 100644 Documentation/nvme-media-unit-stat-log.html create mode 100644 Documentation/nvme-media-unit-stat-log.txt diff --git a/Documentation/nvme-media-unit-stat-log.1 b/Documentation/nvme-media-unit-stat-log.1 new file mode 100644 index 00000000..21d49d81 --- /dev/null +++ b/Documentation/nvme-media-unit-stat-log.1 @@ -0,0 +1,67 @@ +'\" t +.\" Title: nvme-media-unit-stat-log +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.79.1 +.\" Date: 11/11/2021 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-MEDIA\-LOG" "1" "11/11/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-media-unit-stat-log \- Send NVMe Media unit status log pages request, returns result and log +.SH "SYNOPSIS" +.sp +.nf +\fInvme media\-log\-pages\fR [\-d | \-\-dom\-id] + [\-\-output\-format= | \-o ] + [\-\-raw\-binary | \-b] +.fi +.SH "DESCRIPTION" +.sp +Retrieves the NVMe Media unit status log pages details from an NVMe device and provides the returned structure\&. +.sp +The parameter is mandatory and should be the NVMe character device (ex: /dev/nvme0)\&. +.sp +On success, the returned Media unit status log pages log structure will be printed \&. +.SH "OPTIONS" +.PP +\-o , \-\-output\-format= +.RS 4 +This option will set the reporting format to normal, json, or binary\&. Only one output format can be used at a time\&. +.RE +.PP +\-d, \-\-dom\-id +.RS 4 +This option is to get the domain ID\&. +.RE +.PP +\-b, \-\-raw\-binary +.RS 4 +This option is to get raw binary data\&. +.RE +.SH "EXAMPLES" +.sp +No examples provided yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite \ No newline at end of file diff --git a/Documentation/nvme-media-unit-stat-log.html b/Documentation/nvme-media-unit-stat-log.html new file mode 100644 index 00000000..5042ba9f --- /dev/null +++ b/Documentation/nvme-media-unit-stat-log.html @@ -0,0 +1,831 @@ + + + + + + +nvme-media-unit-stat-log(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme supported-log-pages <device> [--output-format=<fmt> | -o <fmt>]
+                            [-b | --raw-binary]
+
+
+
+
+
+

DESCRIPTION

+
+

Retrieves the NVMe supportd log pages details from an NVMe device and provides +the returned structure.

+

The <device> parameter is mandatory and should be the NVMe character +device (ex: /dev/nvme0).

+

On success, the returned supportd log pages log structure will be printed +for each command that is supported.

+
+
+
+

OPTIONS

+
+
+
+-o <format> +
+
+--output-format=<format> +
+
+

+ This option will set the reporting format to normal, json, or binary. + Only one output format can be used at a time. +

+
+
+ -b +
+
+ --raw-binary +
+
+

+ This option will get the data in raw binary format. +

+
+
+ -d +
+
+ --dom-id +
+
+

+ This option is to get the domain ID. +

+
+
+
+
+
+

EXAMPLES

+
+

No examples provided yet.

+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + \ No newline at end of file diff --git a/Documentation/nvme-media-unit-stat-log.txt b/Documentation/nvme-media-unit-stat-log.txt new file mode 100644 index 00000000..427b77cf --- /dev/null +++ b/Documentation/nvme-media-unit-stat-log.txt @@ -0,0 +1,47 @@ +nvme-media-unit-stat-log(1) +=========================== + +NAME +---- +nvme-media-unit-stat-log - Send NVMe Media unit status Log pages +request, returns result and log. + +SYNOPSIS +-------- +[verse] +'nvme media-unit-stat-log' [--dom-id | -d ] + [--output-format= | -o ] + [--raw-binary | -b] + +DESCRIPTION +----------- +Retrieves the NVMe Media unit status log pages details from +an NVMe device and provides the returned structure. + +The parameter is mandatory and should be the NVMe character +device (ex: /dev/nvme0). + +On success, the returned Media unit status log pages log structure will be printed. + +OPTIONS +------- + +-o :: +--output-format=:: + This option will set the reporting format to normal, json, or binary. + Only one output format can be used at a time. + +-d:: +--dom-id:: + To get the domain ID. +-b:: +--raw-binary:: + To show raw binary data. + +EXAMPLES +-------- +No examples provided yet. + +NVME +---- +Part of the nvme-user suite \ No newline at end of file diff --git a/completions/_nvme b/completions/_nvme index 0de72851..b2836158 100644 --- a/completions/_nvme +++ b/completions/_nvme @@ -56,6 +56,7 @@ _nvme () { 'fid-support-effects-log:retrieve fid support and effects log' 'supported-log-pages: retrieve support log pages details' 'lockdown:submit a lockdown command' + 'media-unit-stat-log: retrieve media unit status log pages details' 'help:print brief descriptions of all nvme commands' ) @@ -516,6 +517,18 @@ _nvme () { _arguments '*:: :->subcmds' _describe -t commands "nvme supported-log-pages options" _support ;; + (media-unit-stat-log) + local _medialog + _medialog=( + /dev/nvme':supply a device to use (required)' + --dom-id=':show infos for domain id' + -d':alias of --dom-id' + --raw-binary':dump infos in binary format' + -b':alias of --raw-binary' + ) + _arguments '*:: :->subcmds' + _describe -t commands "nvme media-unit-stat-log" _medialog + ;; (admin-passthru) local _admin _admin=( @@ -901,7 +914,7 @@ _nvme () { resv-report flush compare read write copy show-regs persistent-event-log pred-lat-event-agg-log nvm-id-ctrl endurance-event-agg-log lba-status-log resv-notif-log capacity-mgmt id-domain boot-part-log fid-support-effects-log - supported-log-pages lockdown + supported-log-pages lockdown media-unit-stat-log ) _arguments '*:: :->subcmds' _describe -t commands "help: infos on a specific nvme command, or provide no option to see a synopsis of all nvme commands" _h diff --git a/completions/bash-nvme-completion.sh b/completions/bash-nvme-completion.sh index 7c849326..469dfb5e 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -98,7 +98,7 @@ _cmds="list list-subsys id-ctrl id-ns \ connect disconnect disconnect-all gen-hostnqn \ show-hostnqn dir-receive dir-send virt-mgmt \ rpmb boot-part-log fid-support-effects-log \ - supported-log-pages lockdown" + supported-log-pages lockdown media-unit-stat-log" # Add plugins: for plugin in "${!_plugin_subcmds[@]}"; do @@ -264,6 +264,10 @@ nvme_list_opts () { opts+=" --lsp -s --output-file= -f \ --output-format= -o" ;; + "media-unit-stat-log") + opts+=" --dom-id= -d --output-format= -o \ + --raw-binary -b" + ;; "get-feature") opts+=" --namespace-id= -n --feature-id= -f --sel= -s \ --data-len= -l --cdw11= --c -uuid-index= -U --raw-binary -b \ diff --git a/nvme-builtin.h b/nvme-builtin.h index e53a2dfb..f64ac24b 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -50,6 +50,7 @@ COMMAND_LIST( ENTRY("self-test-log", "Retrieve the SELF-TEST Log, show it", self_test_log) ENTRY("supported-log-pages", "Retrieve the Supported Log pages details, show it", get_supported_log_pages) ENTRY("fid-support-effects-log", "Retrieve FID Support and Effects log and show it", get_fid_support_effects_log) + ENTRY("media-unit-stat-log", "Retrieve the configuration and wear of media units, show it", get_media_unit_stat_log) ENTRY("set-feature", "Set a feature and show the resulting value", set_feature) ENTRY("set-property", "Set a property and show the resulting value", set_property) ENTRY("get-property", "Get a property and show the resulting value", get_property) diff --git a/nvme-print.c b/nvme-print.c index 1c8cb6c8..f7231e01 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -2050,6 +2050,73 @@ void nvme_show_boot_part_log(void *bp_log, const char *devname, printf("Active BPID: %u\n", (le32_to_cpu(hdr->bpinfo) >> 31) & 0x1); } +static void json_media_unit_stat_log(struct nvme_media_unit_stat_log *mus) +{ + struct json_object *root; + struct json_object *entries; + struct json_object *entry; + int i; + + root = json_create_object(); + entries = json_create_array(); + + json_object_add_value_uint(root, "nmu", le16_to_cpu(mus->nmu)); + json_object_add_value_uint(root, "cchans", le16_to_cpu(mus->cchans)); + json_object_add_value_uint(root, "sel_config", le16_to_cpu(mus->sel_config)); + + for (i = 0; i < mus->nmu; i++) { + entry = json_create_object(); + json_object_add_value_uint(entry, "muid", le16_to_cpu(mus->mus_desc[i].muid)); + json_object_add_value_uint(entry, "domainid", le16_to_cpu(mus->mus_desc[i].domainid)); + json_object_add_value_uint(entry, "endgid", le16_to_cpu(mus->mus_desc[i].endgid)); + json_object_add_value_uint(entry, "nvmsetid", le16_to_cpu(mus->mus_desc[i].nvmsetid)); + json_object_add_value_uint(entry, "cap_adj_fctr", le16_to_cpu(mus->mus_desc[i].cap_adj_fctr)); + json_object_add_value_uint(entry, "avl_spare", mus->mus_desc[i].avl_spare); + json_object_add_value_uint(entry, "percent_used", mus->mus_desc[i].percent_used); + json_object_add_value_uint(entry, "mucs", mus->mus_desc[i].mucs); + json_object_add_value_uint(entry, "cio", mus->mus_desc[i].cio); + json_array_add_value_object(entries, entry); + } + + json_object_add_value_array(root, "mus_list", entries); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); +} + +void nvme_show_media_unit_stat_log(struct nvme_media_unit_stat_log *mus_log, + enum nvme_print_flags flags) +{ + int i; + int nmu = le16_to_cpu(mus_log->nmu); + + if (flags & BINARY) + return d_raw((unsigned char *)mus_log, sizeof(*mus_log)); + else if (flags & JSON) + return json_media_unit_stat_log(mus_log); + + printf("Number of Media Unit Status Descriptors: %u\n", nmu); + printf("Number of Channels: %u\n", le16_to_cpu(mus_log->cchans)); + printf("Selected Configuration: %u\n", le16_to_cpu(mus_log->sel_config)); + for (i = 0; i < nmu; i++) { + printf("Media Unit Status Descriptor: %u\n", i); + printf("Media Unit Identifier: %u\n", + le16_to_cpu(mus_log->mus_desc[i].muid)); + printf("Domain Identifier: %u\n", + le16_to_cpu(mus_log->mus_desc[i].domainid)); + printf("Endurance Group Identifier: %u\n", + le16_to_cpu(mus_log->mus_desc[i].endgid)); + printf("NVM Set Identifier: %u\n", + le16_to_cpu(mus_log->mus_desc[i].nvmsetid)); + printf("Capacity Adjustment Factor: %u\n", + le16_to_cpu(mus_log->mus_desc[i].cap_adj_fctr)); + printf("Available Spare: %u\n", mus_log->mus_desc[i].avl_spare); + printf("Percentage Used: %u\n", mus_log->mus_desc[i].percent_used); + printf("Number of Channels: %u\n", mus_log->mus_desc[i].mucs); + printf("Channel Identifiers Offset: %u\n", mus_log->mus_desc[i].cio); + } +} + static void nvme_show_subsystem(nvme_root_t r) { nvme_host_t h; diff --git a/nvme-print.h b/nvme-print.h index 92cb7f20..ea2d7e88 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -76,6 +76,8 @@ void nvme_show_boot_part_log(void *bp_log, const char *devname, __u32 size, enum nvme_print_flags flags); void nvme_show_fid_support_effects_log(struct nvme_fid_supported_effects_log *fid_log, const char *devname, enum nvme_print_flags flags); +void nvme_show_media_unit_stat_log(struct nvme_media_unit_stat_log *mus, + enum nvme_print_flags flags); void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags); void nvme_show_single_property(int offset, uint64_t prop, int human); void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags); diff --git a/nvme.c b/nvme.c index b307c0f8..95b14b7c 100644 --- a/nvme.c +++ b/nvme.c @@ -1536,6 +1536,60 @@ ret: return nvme_status_to_errno(err, false); } +static int get_media_unit_stat_log(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + const char *desc = "Retrieve the configuration and wear of media units and print it"; + const char *domainid = "Domain Identifier"; + const char *raw = "use binary output"; + struct nvme_media_unit_stat_log mus; + + int err = -1, fd; + enum nvme_print_flags flags; + + struct config { + int raw_binary; + char *output_format; + __u16 domainid; + }; + + struct config cfg = { + .output_format = "normal", + .domainid = 0 + }; + + OPT_ARGS(opts) = { + OPT_UINT("domain-id", 'd', &cfg.domainid, domainid), + OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), + 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 (cfg.raw_binary) + flags = BINARY; + + err = nvme_get_log_media_unit_stat(fd, cfg.domainid, &mus); + if (!err) + nvme_show_media_unit_stat_log(&mus, flags); + else if (err > 0) + nvme_show_status(err); + else + perror("media unit status log"); + +close_fd: + close(fd); +ret: + return nvme_status_to_errno(err, false); +} + static int get_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Retrieve desired number of bytes "\ -- 2.50.1