Skip to content

Commit

Permalink
plugins/dapustor: dapustor smart-log-add update
Browse files Browse the repository at this point in the history
Extended Additional SMART log is optional.
If the collection fails, the command dose not stop.

Add the manual of dapustor plugin.
Update tab completion.

Signed-off-by: Xiaoyuan Zhang <[email protected]>
  • Loading branch information
xyzhang-up authored and igaw committed Aug 7, 2024
1 parent c19d90a commit 2634b41
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Documentation/cmd-plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions Documentation/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
65 changes: 65 additions & 0 deletions Documentation/nvme-dapustor-smart-log-add.txt
Original file line number Diff line number Diff line change
@@ -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' <device> [--namespace-id=<nsid> | -n <nsid>]
[--raw-binary | -b] [--json | -j]

DESCRIPTION
-----------
Retrieves the NVMe DapuStor Additional SMART log page from the device and
provides the 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).

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 <nsid>::
--namespace-id=<nsid>::
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
34 changes: 34 additions & 0 deletions completions/bash-nvme-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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"
Expand Down
25 changes: 14 additions & 11 deletions plugins/dapustor/dapustor-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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));
}
Expand Down

0 comments on commit 2634b41

Please sign in to comment.