From: Gollu Appalanaidu Date: Sun, 22 Aug 2021 17:55:03 +0000 (+0530) Subject: nvme: add support for fid supported and effects log(lid = 0x12) X-Git-Tag: v2.0-rc0~53^2~21 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fde1f8cfb142fbaddc2ec83194eb1fddf4f86926;p=users%2Fsagi%2Fnvme-cli.git nvme: add support for fid supported and effects log(lid = 0x12) 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-fid-support-effects-log.1 b/Documentation/nvme-fid-support-effects-log.1 new file mode 100644 index 00000000..d5b64ad6 --- /dev/null +++ b/Documentation/nvme-fid-support-effects-log.1 @@ -0,0 +1,63 @@ +'\" t +.\" Title: nvme-fid-support-effects-log +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.79.1 +.\" Date: 08/26/2021 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-FID\-SUPPORT\-" "1" "08/26/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-fid-support-effects-log \- Send NVMe FID Support and Effects log, return result and structure +.SH "SYNOPSIS" +.sp +.nf +\fInvme fid\-support\-effects\-log\fR [\-o | \-\-output\-format=] +.fi +.SH "DESCRIPTION" +.sp +For the NVMe device given, sends an FID Support and Effects log and provides the result and returned logstructure\&. +.sp +The parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. +.sp +On success, the structure may be returned in one of several ways depending on the option flags; the structure may be parsed by the program or the raw buffer may be printed to stdout\&. +.SH "OPTIONS" +.PP +\-o , \-\-output\-format= +.RS 4 +Set the reporting format to +\fInormal\fR, +\fIjson\fR, or +\fIbinary\fR\&. 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 human\-readable formats\&. +.RE +.SH "EXAMPLES" +.sp +No examples yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-fid-support-effects-log.html b/Documentation/nvme-fid-support-effects-log.html new file mode 100644 index 00000000..b6171000 --- /dev/null +++ b/Documentation/nvme-fid-support-effects-log.html @@ -0,0 +1,821 @@ + + + + + + +nvme-fid-support-effects-log(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme fid-support-effects-log <device> [-o <fmt> | --output-format=<fmt>]
+
+
+
+
+
+

DESCRIPTION

+
+

For the NVMe device given, sends an FID Support and Effects log and +provides the result and returned logstructure.

+

The <device> parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).

+

On success, the structure may be returned in one of several ways depending +on the option flags; the structure may be parsed by the program or the +raw buffer may be printed to stdout.

+
+
+
+

OPTIONS

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

+ 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 human-readable formats. +

+
+
+
+
+
+

EXAMPLES

+
+

No examples yet.

+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-fid-support-effects-log.txt b/Documentation/nvme-fid-support-effects-log.txt new file mode 100644 index 00000000..d2702eb2 --- /dev/null +++ b/Documentation/nvme-fid-support-effects-log.txt @@ -0,0 +1,43 @@ +nvme-fid-support-effects-log(1) +=============================== + +NAME +---- +nvme-fid-support-effects-log - Send NVMe FID Support and Effects log, return result and structure + +SYNOPSIS +-------- +[verse] +'nvme fid-support-effects-log' [-o | --output-format=] + +DESCRIPTION +----------- +For the NVMe device given, sends an FID Support and Effects log and +provides the result and returned logstructure. + +The parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). + +On success, the structure may be returned in one of several ways depending +on the option flags; the structure may be parsed by the program or the +raw buffer may be printed to stdout. + +OPTIONS +------- +-o :: +--output-format=:: + 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 human-readable formats. + +EXAMPLES +-------- +No examples yet. + +NVME +---- +Part of the nvme-user suite \ No newline at end of file diff --git a/completions/_nvme b/completions/_nvme index 2cf6b30f..e83df73c 100644 --- a/completions/_nvme +++ b/completions/_nvme @@ -52,6 +52,7 @@ _nvme () { 'capacity-mgmt: submit capacity management command' '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' 'help:print brief descriptions of all nvme commands' ) @@ -842,6 +843,14 @@ _nvme () { _arguments '*:: :->subcmds' _describe -t commands "nvme show-regs options" _shor ;; + (fid-support-effects-log) + local _fidsupporteffectslog + _fidsupporteffectslog=( + /dev/nvme':supply a device to use (required)' + ) + _arguments '*:: :->subcmds' + _describe -t commands "nvme fid-support-effects-log options" _fidsupporteffectslog + ;; (help) local _h _h=( id-ctrl id-ns list-ns id-iocs create-ns delete-ns attach-ns detach-ns @@ -850,7 +859,11 @@ _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) ) _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 207c705b..93059d90 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -100,7 +100,7 @@ _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" + rpmb boot-part-log fid-support-effects-log" # Add plugins: for plugin in "${!_plugin_subcmds[@]}"; do @@ -218,6 +218,9 @@ nvme_list_opts () { --output-format= -o" ;; "ana-log") + opts+=" --output-format -o" + ;; + "fid-support-effects-log") opts+=" --output-format -o" ;; "error-log") diff --git a/nvme-builtin.h b/nvme-builtin.h index a45b632f..85870715 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -89,6 +89,7 @@ COMMAND_LIST( ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send) ENTRY("virt-mgmt", "Manage Flexible Resources between Primary and Secondary Controller ", virtual_mgmt) ENTRY("rpmb", "Replay Protection Memory Block commands", rpmb_cmd) + ENTRY("fid-support-effects-log", "Submit Feature ID Support and Effects Log, Return result", get_fid_support_effects_log) ); #endif diff --git a/nvme-print.c b/nvme-print.c index 3580cd7c..a843c3ad 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1863,6 +1863,82 @@ void nvme_show_resv_notif_log(struct nvme_resv_notification_log *resv, le32_to_cpu(resv->nsid)); } +static void json_fid_support_effects_log(struct nvme_fid_supported_effects_log *fid_log) +{ + struct json_object *root; + struct json_object *fids; + struct json_object *fids_list; + unsigned int fid; + char key[128]; + __u32 fid_support; + + root = json_create_object(); + fids_list = json_create_array(); + for (fid = 0; fid < 256; fid++) { + fid_support = le32_to_cpu(fid_log->fid_support[fid]); + if (fid_support & NVME_FID_SUPPORTED_EFFECTS_FSUPP) { + fids = json_create_object(); + sprintf(key, "fid_%u", fid); + json_object_add_value_uint(fids, key, fid_support); + json_array_add_value_object(fids_list, fids); + } + } + + json_object_add_value_object(root, "fid_support", fids_list); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); +} + +static void nvme_show_fid_support_effects_log_human(__u32 fid_support) +{ + const char *set = "+"; + const char *clr = "-"; + __u16 fsp; + + printf(" FSUPP+"); + printf(" UDCC%s", (fid_support & NVME_FID_SUPPORTED_EFFECTS_UDCC) ? set : clr); + printf(" NCC%s", (fid_support & NVME_FID_SUPPORTED_EFFECTS_NCC) ? set : clr); + printf(" NIC%s", (fid_support & NVME_FID_SUPPORTED_EFFECTS_NIC) ? set : clr); + printf(" CCC%s", (fid_support & NVME_FID_SUPPORTED_EFFECTS_CCC) ? set : clr); + printf(" USS%s", (fid_support & NVME_FID_SUPPORTED_EFFECTS_UUID_SEL) ? set : clr); + + fsp = (fid_support >> NVME_FID_SUPPORTED_EFFECTS_SCOPE_SHIFT) & NVME_FID_SUPPORTED_EFFECTS_SCOPE_MASK; + + printf(" NAMESPACE SCOPE%s", (fsp & NVME_FID_SUPPORTED_EFFECTS_SCOPE_NS) ? set : clr); + printf(" CONTROLLER SCOPE%s", (fsp & NVME_FID_SUPPORTED_EFFECTS_SCOPE_CTRL) ? set : clr); + printf(" NVM SET SCOPE%s", (fsp & NVME_FID_SUPPORTED_EFFECTS_SCOPE_NVM_SET) ? set : clr); + printf(" ENDURANCE GROUP SCOPE%s", (fsp & NVME_FID_SUPPORTED_EFFECTS_SCOPE_ENDGRP) ? set : clr); + printf(" DOMAIN SCOPE%s", (fsp & NVME_FID_SUPPORTED_EFFECTS_SCOPE_DOMAIN) ? set : clr); + printf(" NVM Subsystem SCOPE%s", (fsp & NVME_FID_SUPPORTED_EFFECTS_SCOPE_NSS) ? set : clr); +} + +void nvme_show_fid_support_effects_log(struct nvme_fid_supported_effects_log *fid_log, + const char *devname, enum nvme_print_flags flags) +{ + __u32 fid_effect; + int i, human = flags & VERBOSE; + + if (flags & BINARY) + return d_raw((unsigned char *)fid_log, sizeof(*fid_log)); + if (flags & JSON) + return json_fid_support_effects_log(fid_log); + + printf("FID Supports Effects Log for device: %s\n", devname); + printf("Admin Command Set\n"); + for (i = 0; i < 256; i++) { + fid_effect = le32_to_cpu(fid_log->fid_support[i]); + if (fid_effect & NVME_FID_SUPPORTED_EFFECTS_FSUPP) { + printf("FID %02x -> Support Effects Log: %08x", i, + fid_effect); + if (human) + nvme_show_fid_support_effects_log_human(fid_effect); + else + printf("\n"); + } + } +} + static void json_boot_part_log(void *bp_log) { struct nvme_boot_partition *hdr; diff --git a/nvme-print.h b/nvme-print.h index 05d992f7..496fe4ae 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -80,6 +80,8 @@ void nvme_show_resv_notif_log(struct nvme_resv_notification_log *resv, const char *devname, enum nvme_print_flags flags); 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_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 5f94dbf5..552fd9a3 100644 --- a/nvme.c +++ b/nvme.c @@ -1566,6 +1566,53 @@ ret: return nvme_status_to_errno(err, false); } +static int get_fid_support_effects_log(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + const char *desc = "Retrieve FID Support and Effects log and show it."; + const char *human_readable = "show log in readable format"; + struct nvme_fid_supported_effects_log fid_support_log; + enum nvme_print_flags flags; + int fd, err = -1; + + struct config { + int human_readable; + char *output_format; + }; + + struct config cfg = { + .output_format = "normal", + }; + + OPT_ARGS(opts) = { + OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + OPT_FLAG("human-readable",'H', &cfg.human_readable, human_readable), + 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.human_readable) + flags |= VERBOSE; + + err = nvme_get_log_fid_supported_effects(fd, false, &fid_support_log); + if (!err) + nvme_show_fid_support_effects_log(&fid_support_log, devicename, flags); + else if (err > 0) + nvme_show_status(err); + else + perror("fid support effects log"); +close_fd: + close(fd); +ret: + return nvme_status_to_errno(err, false); +} + static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Show controller list information for the subsystem the "\