]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Added Vendor Unique Solidigm Garbage Collect Log.
authorda Cunha, Leonardo <leonardo.da.cunha@solidigmtechnology.com>
Fri, 6 May 2022 23:34:56 +0000 (19:34 -0400)
committerDaniel Wagner <dwagner@suse.de>
Fri, 27 May 2022 15:26:35 +0000 (17:26 +0200)
plugins/meson.build
plugins/solidigm/meson.build [new file with mode: 0644]
plugins/solidigm/solidigm-garbage-collection.c [new file with mode: 0644]
plugins/solidigm/solidigm-garbage-collection.h [new file with mode: 0644]
plugins/solidigm/solidigm-nvme.c [new file with mode: 0644]
plugins/solidigm/solidigm-nvme.h
plugins/solidigm/solidigm-smart.c
plugins/solidigm/solidigm-smart.h [new file with mode: 0644]

index 72a68bf5602cd8ac42a8223db8751b071ebc3c89..5c892d913d2d75e21c5e2f91ce26034d020e28ba 100644 (file)
@@ -12,7 +12,7 @@ sources += [
   'plugins/scaleflux/sfx-nvme.c',
   'plugins/seagate/seagate-nvme.c',
   'plugins/shannon/shannon-nvme.c',
-  'plugins/solidigm/solidigm-smart.c',
+  'plugins/solidigm/solidigm-nvme.c',
   'plugins/toshiba/toshiba-nvme.c',
   'plugins/transcend/transcend-nvme.c',
   'plugins/virtium/virtium-nvme.c',
@@ -22,3 +22,4 @@ sources += [
   'plugins/zns/zns.c',
   'plugins/ocp/ocp-nvme.c',
 ]
+subdir('solidigm')
diff --git a/plugins/solidigm/meson.build b/plugins/solidigm/meson.build
new file mode 100644 (file)
index 0000000..2b0c6ce
--- /dev/null
@@ -0,0 +1,4 @@
+sources += [
+  'plugins/solidigm/solidigm-smart.c',
+  'plugins/solidigm/solidigm-garbage-collection.c',
+]
diff --git a/plugins/solidigm/solidigm-garbage-collection.c b/plugins/solidigm/solidigm-garbage-collection.c
new file mode 100644 (file)
index 0000000..8ef79e1
--- /dev/null
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Solidigm.
+ *
+ * Author: leonardo.da.cunha@solidigm.com
+ */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "common.h"
+#include "nvme.h"
+#include "libnvme.h"
+#include "plugin.h"
+#include "linux/types.h"
+#include "nvme-print.h"
+#include "solidigm-garbage-collection.h"
+
+typedef struct __attribute__((packed)) gc_item {
+       __le32 timer_type;
+       __le64 timestamp;
+} gc_item_t;
+
+#define VU_GC_MAX_ITEMS 100
+typedef struct garbage_control_collection_log {
+       __le16 version_major;
+       __le16 version_minor;
+       gc_item_t item[VU_GC_MAX_ITEMS];
+       __u8 reserved[2892];
+} garbage_control_collection_log_t;
+
+static void vu_gc_log_show_json(garbage_control_collection_log_t *payload, const char *devname)
+{
+       struct json_object *gc_entries = json_create_array();
+
+       for (int i = 0; i < VU_GC_MAX_ITEMS; i++) {
+               gc_item_t item = payload->item[i];
+               struct json_object *entry = json_create_object();
+               json_object_add_value_int(entry, "timestamp", le64_to_cpu(item.timestamp));
+               json_object_add_value_int(entry, "timer_type", le32_to_cpu(item.timer_type));
+               json_array_add_value_object(gc_entries, entry);
+       }
+
+       json_print_object(gc_entries, NULL);
+       json_free_object(gc_entries);
+}
+
+static void vu_gc_log_show(garbage_control_collection_log_t *payload, const char *devname)
+{
+       printf("Solidigm Garbage Collection Log for NVME device: %s\n", devname);
+       printf("Timestamp     Timer Type\n");
+
+       for (int i = 0; i < VU_GC_MAX_ITEMS; i++) {
+               gc_item_t item = payload->item[i];
+               printf("%-13lu %d\n",le64_to_cpu(item.timestamp), le32_to_cpu(item.timer_type));
+       }
+}
+
+int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       const char *desc = "Get and parse Solidigm vendor specific garbage collection event log.";
+
+       struct config {
+               char    *output_format;
+               int     raw_binary;
+       };
+
+       struct config cfg = {
+               .output_format  = "normal",
+               .raw_binary     = 0
+       };
+
+       OPT_ARGS(opts) = {
+               OPT_FMT("output-format",   'o', &cfg.output_format,  output_format),
+               OPT_FLAG("raw-binary",     'b', &cfg.raw_binary,     "Dump output in binary format"),
+               OPT_END()
+       };
+
+       int fd = parse_and_open(argc, argv, desc, opts);
+       if (fd < 0)     {
+               return fd;
+       }
+
+       enum nvme_print_flags flags = validate_output_format(cfg.output_format);
+       if (flags == -EINVAL) {
+               fprintf(stderr, "Invalid output format '%s'\n", cfg.output_format);
+               close(fd);
+               return fd;
+       }
+       
+       if (cfg.raw_binary)     {
+               flags = BINARY;
+       }
+
+       garbage_control_collection_log_t gc_log;
+       const int solidigm_vu_gc_log_id = 0xfd;
+
+       int err = nvme_get_log_simple(fd, solidigm_vu_gc_log_id, sizeof(gc_log), &gc_log);
+       if (!err) {
+               if (flags & BINARY)     {
+                       d_raw((unsigned char *)&gc_log, sizeof(gc_log));
+               } else if (flags & JSON) {
+                       vu_gc_log_show_json(&gc_log, devicename);
+               } else {
+                       vu_gc_log_show(&gc_log, devicename);
+               }
+       }
+       else if (err > 0) {
+               nvme_show_status(err);
+       }
+       
+       close(fd);
+       return err;
+}
diff --git a/plugins/solidigm/solidigm-garbage-collection.h b/plugins/solidigm/solidigm-garbage-collection.h
new file mode 100644 (file)
index 0000000..a3e34b2
--- /dev/null
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Solidigm.
+ *
+ * Author: leonardo.da.cunha@solidigm.com
+ */
+
+int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *cmd, struct plugin *plugin);
diff --git a/plugins/solidigm/solidigm-nvme.c b/plugins/solidigm/solidigm-nvme.c
new file mode 100644 (file)
index 0000000..b573c5e
--- /dev/null
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Solidigm.
+ *
+ * Author: leonardo.da.cunha@solidigm.com
+ */
+
+#include "nvme.h"
+
+#define CREATE_CMD
+#include "solidigm-nvme.h"
+
+#include "solidigm-smart.h"
+#include "solidigm-garbage-collection.h"
+
+static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       return solidigm_get_additional_smart_log(argc, argv, cmd, plugin);
+}
+
+static int get_garbage_collection_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       return solidigm_get_garbage_collection_log(argc, argv, cmd, plugin);
+}
index d7035cf73a76f17fe064f27d0cd52603cfeb1094..52189d9a1b7626c001725c9db682ad746087433d 100644 (file)
@@ -1,22 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2022 Solidigm.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- *   Author: leonardo.da.cunha@solidigm.com
+ * Author: leonardo.da.cunha@solidigm.com
  */
 
 #undef CMD_INC_FILE
 
 #include "cmd.h"
 
-#define SOLIDIGM_PLUGIN_VERSION "0.1"
+#define SOLIDIGM_PLUGIN_VERSION "0.2"
 
 PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_VERSION),
        COMMAND_LIST(
                ENTRY("smart-log-add", "Retrieve Solidigm SMART Log", get_additional_smart_log)
+               ENTRY("garbage-collect-log", "Retrieve Garbage Collection Log", get_garbage_collection_log)
        )
 );
 
index d056369d9bb6cdc90eaaced9b61e8a714d240427..748904a5bef782498c03dd5d6ab2aca91616782a 100644 (file)
@@ -1,22 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2022 Solidigm.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- *   Author: leonardo.da.cunha@solidigm.com
+ * Author: leonardo.da.cunha@solidigm.com
  */
 
 #include <fcntl.h>
@@ -25,6 +11,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <inttypes.h>
+#include <endian.h>
 
 #include "common.h"
 #include "nvme.h"
@@ -33,8 +20,7 @@
 #include "linux/types.h"
 #include "nvme-print.h"
 
-#define CREATE_CMD
-#include "solidigm-nvme.h"
+#include "solidigm-smart.h"
 
 struct  __attribute__((packed)) nvme_additional_smart_log_item {
        __u8                    id;
@@ -208,7 +194,7 @@ static void vu_smart_log_show(vu_smart_log_t *payload, unsigned int nsid, const
        }
 }
 
-static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+int solidigm_get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        const char *desc = "Get Solidigm vendor specific smart log (optionally, "\
                      "for the specified namespace), and show it.";
diff --git a/plugins/solidigm/solidigm-smart.h b/plugins/solidigm/solidigm-smart.h
new file mode 100644 (file)
index 0000000..e19ebe5
--- /dev/null
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Solidigm.
+ *
+ * Author: leonardo.da.cunha@solidigm.com
+ */
+
+int solidigm_get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin);