From: Gollu Appalanaidu Date: Fri, 13 Aug 2021 17:18:52 +0000 (+0530) Subject: nvme: add supported log pages log page (lid = 0x00) X-Git-Tag: v2.0-rc0~53^2~17 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=37ba7b216d48433f2b50ceb9b21f56e9ba9d3934;p=users%2Fsagi%2Fnvme-cli.git nvme: add supported log pages log page (lid = 0x00) Signed-off-by: Gollu Appalanaidu [dwagner: ported from monolithic, droped nvme-ioctl changes, part of libnvme] Signed-off-by: Daniel Wagner --- diff --git a/Documentation/nvme-supported-log-pages.1 b/Documentation/nvme-supported-log-pages.1 new file mode 100644 index 00000000..e050cef1 --- /dev/null +++ b/Documentation/nvme-supported-log-pages.1 @@ -0,0 +1,61 @@ +'\" t +.\" Title: nvme-supported-log-pages +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.79.1 +.\" Date: 08/13/2021 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-SUPPORTED\-LOG" "1" "08/13/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-supported-log-pages \- Send NVMe Supported Log pages request, returns result and log +.SH "SYNOPSIS" +.sp +.nf +\fInvme supported\-log\-pages\fR [\-\-output\-format= | \-o ] + [\-\-human\-readable | \-H] +.fi +.SH "DESCRIPTION" +.sp +Retrieves the NVMe supportd 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 supportd log pages log structure will be printed for each command that is supported\&. +.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 +\-H, \-\-human\-readable +.RS 4 +This option will parse and format many of the bit fields into a human\-readable format\&. +.RE +.SH "EXAMPLES" +.sp +No examples provided yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-supported-log-pages.html b/Documentation/nvme-supported-log-pages.html new file mode 100644 index 00000000..b64a635e --- /dev/null +++ b/Documentation/nvme-supported-log-pages.html @@ -0,0 +1,821 @@ + + + + + + +nvme-supported-log-pages(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme supported-log-pages <device> [--output-format=<fmt> | -o <fmt>]
+                            [--human-readable | -H]
+
+
+
+
+
+

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

+
+
+-H +
+
+--human-readable +
+
+

+ This option will parse and format many of the bit fields into a + human-readable format. +

+
+
+
+
+
+

EXAMPLES

+
+

No examples provided yet.

+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-supported-log-pages.txt b/Documentation/nvme-supported-log-pages.txt new file mode 100644 index 00000000..3e9d37a9 --- /dev/null +++ b/Documentation/nvme-supported-log-pages.txt @@ -0,0 +1,44 @@ +nvme-supported-log-pages(1) +=========================== + +NAME +---- +nvme-supported-log-pages - Send NVMe Supported Log pages request, returns result and log + +SYNOPSIS +-------- +[verse] +'nvme supported-log-pages' [--output-format= | -o ] + [--human-readable | -H] + +DESCRIPTION +----------- +Retrieves the NVMe supportd 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 supportd log pages log structure will be printed +for each command that is supported. + +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. + +-H:: +--human-readable:: + This option will parse and format many of the bit fields into a + human-readable format. + +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 e83df73c..17fc994c 100644 --- a/completions/_nvme +++ b/completions/_nvme @@ -53,6 +53,7 @@ _nvme () { 'show-regs:shows the controller registers; requires admin character device' 'boot-part-log: retrieve boot partition log' 'fid-support-effects-log:retrieve fid support and effects log' + 'supported-log-pages: retrieve support log pages details' 'help:print brief descriptions of all nvme commands' ) @@ -475,6 +476,16 @@ _nvme () { _arguments '*:: :->subcmds' _describe -t commands "nvme capacity-mgmt options" _fwd ;; + (supported-log-pages) + local _support + _support=( + /dev/nvme':supply a device to use (required)' + --human-readable':show infos in readable format' + -H':alias of --human-readable' + ) + _arguments '*:: :->subcmds' + _describe -t commands "nvme supported-log-pages options" _support + ;; (admin-passthru) local _admin _admin=( @@ -859,11 +870,8 @@ _nvme () { security-send security-recv resv-acquire resv-register resv-release 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 -<<<<<<< HEAD - resv-notif-log capacity-mgmt id-domain boot-part-log -======= - resv-notif-log capacity-mgmt id-domain fid-support-effects-log ->>>>>>> nvme: add support for fid supported and effects log(lid = 0x12) + resv-notif-log capacity-mgmt id-domain boot-part-log fid-support-effects-log + supported-log-pages ) _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 93059d90..ba219e35 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -100,7 +100,8 @@ _cmds="list list-subsys id-ctrl id-ns \ ns-rescan show-regs discover connect-all \ connect disconnect disconnect-all gen-hostnqn \ show-hostnqn dir-receive dir-send virt-mgmt \ - rpmb boot-part-log fid-support-effects-log" + rpmb boot-part-log fid-support-effects-log \ + supported-log-pages" # Add plugins: for plugin in "${!_plugin_subcmds[@]}"; do @@ -203,6 +204,9 @@ nvme_list_opts () { --rae -r --uuid-index= -U --csi= -y --ot -O \ --raw-binary -b" ;; + "supported-log-pages") + opts+=" --output-format= -o --human-readable -H" + ;; "telemetry-log") opts+=" --output-file= -o --host-generate= -g \ --controller-init -c --data-area= -d" diff --git a/nvme-builtin.h b/nvme-builtin.h index 85870715..a4954886 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -47,6 +47,7 @@ COMMAND_LIST( ENTRY("get-feature", "Get feature and show the resulting value", get_feature) ENTRY("device-self-test", "Perform the necessary tests to observe the performance", device_self_test) 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("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 a843c3ad..2743acb4 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -5195,6 +5195,101 @@ void nvme_print_effects_log_pages(struct list_head *list, } } +const char *nvme_log_to_string(__u8 lid) +{ + switch (lid) { + case NVME_LOG_LID_SUPPORTED_LOG_PAGES: return "Supported Log Pages"; + case NVME_LOG_LID_ERROR: return "Error Information"; + case NVME_LOG_LID_SMART: return "SMART Information"; + case NVME_LOG_LID_FW_SLOT: return "Firmware Slot Information"; + case NVME_LOG_LID_CHANGED_NS: return "Changed Namespace List"; + case NVME_LOG_LID_CMD_EFFECTS: return "Commands Supported and Effects"; + case NVME_LOG_LID_DEVICE_SELF_TEST: return "Device Self-test"; + case NVME_LOG_LID_TELEMETRY_HOST: return "Telemetry Host-Initiated"; + case NVME_LOG_LID_TELEMETRY_CTRL: return "Telemetry Controller-Initiated"; + case NVME_LOG_LID_ENDURANCE_GROUP: return "Endurance Group Information"; + case NVME_LOG_LID_PREDICTABLE_LAT_NVMSET: return "Predictable Latency Per NVM Set"; + case NVME_LOG_LID_ANA: return "Asymmetric Namespace Access"; + case NVME_LOG_LID_PREDICTABLE_LAT_AGG: return "Predictable Latency Event Aggregate"; + case NVME_LOG_LID_PERSISTENT_EVENT: return "Persistent Event Log"; + case NVME_LOG_LID_LBA_STATUS: return "LBA Status Information"; + case NVME_LOG_LID_ENDURANCE_GRP_EVT: return "Endurance Group Event Aggregate"; + case NVME_LOG_LID_BOOT_PARTITION: return "Boot Partition"; + case NVME_LOG_LID_FID_SUPPORTED_EFFECTS: return "FID Supported and Effects"; + case NVME_LOG_LID_DISCOVER: return "Discovery"; + case NVME_LOG_LID_RESERVATION: return "Reservation Notification"; + case NVME_LOG_LID_SANITIZE: return "Sanitize Status"; + case NVME_LOG_LID_ZNS_CHANGED_ZONES: return "Host Identifier"; + default: return "Unknown"; + } +} + +static void nvme_show_support_log_human(__u32 support, __u8 lid) +{ + const char *set = "supported"; + const char *clr = "not supported"; + + printf(" LSUPP is %s\n", (support & 0x1) ? set : clr); + printf(" IOS is %s\n", ((support >> 0x1) & 0x1) ? set : clr); + if (lid == NVME_LOG_LID_PERSISTENT_EVENT) { + printf(" Establish Context and Read 512 Bytes of Header is %s\n", + ((support >> 0x16) & 0x1) ? set : clr); + } +} + +static void json_support_log(struct nvme_supported_log_pages *support_log) +{ + struct json_object *root; + struct json_object *valid; + struct json_object *valid_attrs; + unsigned int lid; + char key[128]; + __u32 support; + + root = json_create_object(); + valid = json_create_object(); + + for (lid = 0; lid < 256; lid++) { + support = le32_to_cpu(support_log->lid_support[lid]); + if (support & 0x1) { + valid_attrs = json_create_object(); + sprintf(key, "lid_0x%x ", lid); + json_object_add_value_uint(valid_attrs, key, support); + json_array_add_value_object(valid, valid_attrs); + } + } + + json_object_add_value_object(root, "supported_logs", valid); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); +} + +void nvme_show_supported_log(struct nvme_supported_log_pages *support_log, + const char *devname, enum nvme_print_flags flags) +{ + int lid, human = flags & VERBOSE; + __u32 support = 0; + + if (flags & BINARY) + return d_raw((unsigned char *)support_log, sizeof(*support_log)); + else if (flags & JSON) + return json_support_log(support_log); + + printf("Support Log Pages Deatils for %s:\n", devname); + for (lid = 0; lid < 256; lid++) { + support = le32_to_cpu(support_log->lid_support[lid]); + if (support & 0x1) { + printf("LID 0x%x (%s), supports 0x%x\n", lid, nvme_log_to_string(lid), + support); + if (human) + nvme_show_support_log_human(support, lid); + else + printf("\n"); + } + } +} + uint64_t int48_to_long(__u8 *data) { int i; diff --git a/nvme-print.h b/nvme-print.h index 496fe4ae..d540c036 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -32,6 +32,8 @@ void nvme_show_cmd_set_independent_id_ns( void nvme_show_resv_report(struct nvme_resv_status *status, int bytes, bool eds, enum nvme_print_flags flags); void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges); +void nvme_show_supported_log(struct nvme_supported_log_pages *support, + const char *devname, enum nvme_print_flags flags); void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname, enum nvme_print_flags flags); void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, diff --git a/nvme.c b/nvme.c index 552fd9a3..164d592b 100644 --- a/nvme.c +++ b/nvme.c @@ -632,6 +632,56 @@ ret: return nvme_status_to_errno(err, false); } +static int get_supported_log_pages(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + const char *desc = "Retrieve supported logs and print the table."; + const char *verbose = "Increase output verbosity"; + struct nvme_supported_log_pages supports; + + int err = -1, fd; + enum nvme_print_flags flags; + + struct config { + int verbose; + char *output_format; + }; + + struct config cfg = { + .output_format = "normal", + }; + + OPT_ARGS(opts) = { + OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + OPT_FLAG("verbose", 'v', &cfg.verbose, verbose), + 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.verbose) + flags |= VERBOSE; + + err = nvme_get_log_supported_log_pages(fd, false, &supports); + if (!err) + nvme_show_supported_log(&supports, devicename, flags); + else if (err > 0) + nvme_show_status(err); + else + perror("supported log pages"); + +close_fd: + close(fd); +ret: + return nvme_status_to_errno(err, false); +} + static int get_error_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Retrieve specified number of "\