]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/dapustor: dapustor smart-log-add update
authorXiaoyuan Zhang <zhxiaoy2024@gmail.com>
Wed, 7 Aug 2024 10:24:58 +0000 (18:24 +0800)
committerDaniel Wagner <wagi@monom.org>
Wed, 7 Aug 2024 12:15:26 +0000 (14:15 +0200)
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 <zhxiaoy2024@gmail.com>
Documentation/cmd-plugins.txt
Documentation/meson.build
Documentation/nvme-dapustor-smart-log-add.txt [new file with mode: 0644]
completions/bash-nvme-completion.sh
plugins/dapustor/dapustor-nvme.c

index 338425efaaa80c8369e63733f57f18c08af37093..2e80bfc98edff75b3de2526c357419b05a381cef 100644 (file)
@@ -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
index 14781341752dd71c261c788bb32a677fb8b8679f..4e8ffcad2609c45e26046df3a35a28bf1e742a8e 100644 (file)
@@ -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 (file)
index 0000000..0c67a21
--- /dev/null
@@ -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
index 9e2e2770bd26008cf84380065157b51d9cd39a72..10f3ccde93132acbcd688cbc0007e38c457d2ad0 100644 (file)
@@ -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"
index 57c59dc6a5a9ed0f3e266c62fce08f32ccab8986..678ba99239f4eeb550f14bda1efe75922aeb2d08 100644 (file)
@@ -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));
        }