diff --git a/Documentation/cmd-plugins.txt b/Documentation/cmd-plugins.txt index 338425efa..2e80bfc98 100644 --- a/Documentation/cmd-plugins.txt +++ b/Documentation/cmd-plugins.txt @@ -204,3 +204,6 @@ linknvme:nvme-zns-zrwa-flush-zone[1]:: linknvme:nvme-inspur-nvme-vendor-log[1]:: NVMe Inspur Device Vendor log page request + +linknvme:nvme-dapustor-smart-log-add[1]:: + NVMe DapuStor Additional SMART log page diff --git a/Documentation/meson.build b/Documentation/meson.build index 147813417..4e8ffcad2 100644 --- a/Documentation/meson.build +++ b/Documentation/meson.build @@ -14,6 +14,7 @@ adoc_sources = [ 'nvme-connect-all', 'nvme-copy', 'nvme-create-ns', + 'nvme-dapustor-smart-log-add', 'nvme-delete-ns', 'nvme-dera-stat', 'nvme-detach-ns', diff --git a/Documentation/nvme-dapustor-smart-log-add.txt b/Documentation/nvme-dapustor-smart-log-add.txt new file mode 100644 index 000000000..0c67a21dc --- /dev/null +++ b/Documentation/nvme-dapustor-smart-log-add.txt @@ -0,0 +1,65 @@ +nvme-dapustor-smart-log-add(1) +============================== + +NAME +---- +nvme-dapustor-smart-log-add - Send NVMe DapuStor Additional SMART log page request, +returns result and log + +SYNOPSIS +-------- +[verse] +'nvme dapustor smart-log-add' [--namespace-id= | -n ] + [--raw-binary | -b] [--json | -j] + +DESCRIPTION +----------- +Retrieves the NVMe DapuStor Additional SMART log page from the device and +provides the 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). + +On success, the returned smart log structure may be returned in one of +several ways depending on the option flags; the structure may parsed by +the program and printed in a readable format or the raw buffer may be +printed to stdout for another program to parse. + +OPTIONS +------- +-n :: +--namespace-id=:: + Retrieve the Additional SMART log for the given nsid. This is + optional and its success may depend on the device's capabilities + to provide this log on a per-namespace basis (see the NVMe + Identify Controller for this capability). The default nsid to + use is 0xffffffff for the device global SMART log. + +-b:: +--raw-binary:: + Print the raw DapuStor Additional SMART log buffer to stdout. + +-j:: +--json:: + Dump output in json format. + +EXAMPLES +-------- +* Print the DapuStor Additional SMART log page in a human readable format: ++ +------------ +# nvme dapustor smart-log-add /dev/nvme0 +------------ ++ + +* Print the raw DapuStor Additional SMART log to a file: ++ +------------ +# nvme dapustor smart-log-add /dev/nvme0 --raw-binary > smart_log.raw +------------ ++ +It is probably a bad idea to not redirect stdout when using this mode. + +NVME +---- +Part of the nvme-user suite diff --git a/completions/bash-nvme-completion.sh b/completions/bash-nvme-completion.sh index 9e2e2770b..10f3ccde9 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -1228,6 +1228,38 @@ plugin_transcend_opts () { return 0 } +plugin_dapustor_opts () { + local opts="" + local compargs="" + + local nonopt_args=0 + for (( i=0; i < ${#words[@]}-1; i++ )); do + if [[ ${words[i]} != -* ]]; then + let nonopt_args+=1 + fi + done + + if [ $nonopt_args -eq 3 ]; then + opts="/dev/nvme* " + fi + + opts+=" " + + case "$1" in + "smart-log-add") + opts+=" --namespace-id= -n --raw-binary -b \ + --json -j" + ;; + "help") + opts+=$NO_OPTS + ;; + esac + + COMPREPLY+=( $( compgen $compargs -W "$opts" -- $cur ) ) + + return 0 +} + plugin_zns_opts () { local opts="" local compargs="" @@ -1554,6 +1586,7 @@ _nvme_subcmds () { vs-drive-info cloud-SSDplugin-version market-log \ smart-log-add temp-stats version help" [transcend]="healthvalue badblock" + [dapustor]="smart-log-add" [zns]="id-ctrl id-ns zone-mgmt-recv \ zone-mgmt-send report-zones close-zone \ finish-zone open-zone reset-zone offline-zone \ @@ -1588,6 +1621,7 @@ _nvme_subcmds () { [sfx]="plugin_sfx_opts" [solidigm]="plugin_solidigm_opts" [transcend]="plugin_transcend_opts" + [dapustor]="plugin_dapustor_opts" [zns]="plugin_zns_opts" [nvidia]="plugin_nvidia_opts" [ymtc]="plugin_ymtc_opts" diff --git a/plugins/dapustor/dapustor-nvme.c b/plugins/dapustor/dapustor-nvme.c index 57c59dc6a..678ba9923 100644 --- a/plugins/dapustor/dapustor-nvme.c +++ b/plugins/dapustor/dapustor-nvme.c @@ -332,7 +332,7 @@ static void show_dapustor_ext_add_smart_log_jsn(struct nvme_extended_additional_ static void show_dapustor_smart_log_jsn(struct nvme_additional_smart_log *smart, struct nvme_extended_additional_smart_log *ext_smart, - unsigned int nsid, const char *devname) + unsigned int nsid, const char *devname, bool has_ext) { struct json_object *root, *dev_stats; @@ -341,7 +341,8 @@ static void show_dapustor_smart_log_jsn(struct nvme_additional_smart_log *smart, dev_stats = json_create_object(); show_dapustor_add_smart_log_jsn(smart, dev_stats); - show_dapustor_ext_add_smart_log_jsn(ext_smart, dev_stats); + if (has_ext) + show_dapustor_ext_add_smart_log_jsn(ext_smart, dev_stats); json_object_add_value_object(root, "Device stats", dev_stats); json_print_object(root, NULL); @@ -470,19 +471,21 @@ static void show_dapustor_ext_add_smart_log(struct nvme_extended_additional_smar static void show_dapustor_smart_log(struct nvme_additional_smart_log *smart, struct nvme_extended_additional_smart_log *ext_smart, - unsigned int nsid, const char *devname) + unsigned int nsid, const char *devname, bool has_ext) { printf("Additional Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid); printf("key normalized raw\n"); show_dapustor_add_smart_log(smart); - show_dapustor_ext_add_smart_log(ext_smart); + if (has_ext) + show_dapustor_ext_add_smart_log(ext_smart); } static int dapustor_additional_smart_log_data( int dev_fd, struct nvme_additional_smart_log *smart_log, - struct nvme_extended_additional_smart_log *ext_smart_log) + struct nvme_extended_additional_smart_log *ext_smart_log, + bool *has_ext) { int err; @@ -492,9 +495,8 @@ static int dapustor_additional_smart_log_data( return err; } err = nvme_get_log_simple(dev_fd, 0xcb, sizeof(*ext_smart_log), ext_smart_log); - if (err) - nvme_show_status(err); - return err; + *has_ext = !err; + return 0; } static int dapustor_additional_smart_log(int argc, char **argv, struct command *cmd, @@ -509,6 +511,7 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command * struct nvme_extended_additional_smart_log ext_smart_log; struct nvme_dev *dev; int err; + bool has_ext = false; struct config { uint32_t namespace_id; @@ -531,14 +534,14 @@ static int dapustor_additional_smart_log(int argc, char **argv, struct command * if (err) return err; - err = dapustor_additional_smart_log_data(dev_fd(dev), &smart_log, &ext_smart_log); + err = dapustor_additional_smart_log_data(dev_fd(dev), &smart_log, &ext_smart_log, &has_ext); if (!err) { if (cfg.json) show_dapustor_smart_log_jsn(&smart_log, &ext_smart_log, - cfg.namespace_id, dev->name); + cfg.namespace_id, dev->name, has_ext); else if (!cfg.raw_binary) show_dapustor_smart_log(&smart_log, &ext_smart_log, - cfg.namespace_id, dev->name); + cfg.namespace_id, dev->name, has_ext); else d_raw((unsigned char *)&smart_log, sizeof(smart_log)); }