]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
ocp: move ocp telemetry log print function into ocp-print
authorTokunori Ikegami <ikegami.t@gmail.com>
Sun, 6 Oct 2024 01:22:10 +0000 (10:22 +0900)
committerDaniel Wagner <wagi@monom.org>
Wed, 23 Oct 2024 12:24:49 +0000 (14:24 +0200)
Still the ocp-telemetry-decode used by print functions combined json code.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
plugins/ocp/ocp-nvme.c
plugins/ocp/ocp-print-json.c
plugins/ocp/ocp-print-stdout.c
plugins/ocp/ocp-print.c
plugins/ocp/ocp-print.h
plugins/ocp/ocp-telemetry-decode.h

index f6ed1e1435ef28f1e2ac55f28f436b3fd31119c7..815d065becd3a6177f377165495b6b7604d81c4e 100644 (file)
@@ -31,6 +31,7 @@
 #include "ocp-fw-activation-history.h"
 #include "ocp-telemetry-decode.h"
 #include "ocp-hardware-component-log.h"
+#include "ocp-print.h"
 
 #define CREATE_CMD
 #include "ocp-nvme.h"
@@ -1742,16 +1743,7 @@ int parse_ocp_telemetry_log(struct ocp_telemetry_parse_options *options)
                return status;
        }
 
-       switch (fmt) {
-       case NORMAL:
-               print_ocp_telemetry_normal(options);
-               break;
-       case JSON:
-               print_ocp_telemetry_json(options);
-               break;
-       default:
-               break;
-       }
+       ocp_show_telemetry_log(options, fmt);
 
        return 0;
 }
index d2a691bff1705ef5347995d0ef1566ee10b5cb1e..568d6c9227365d23277d0d9e92ae084ac56b911b 100644 (file)
@@ -6,6 +6,7 @@
 #include "ocp-hardware-component-log.h"
 #include "ocp-fw-activation-history.h"
 #include "ocp-smart-extended-log.h"
+#include "ocp-telemetry-decode.h"
 
 static void print_hwcomp_desc_json(struct hwcomp_desc_entry *e, struct json_object *r)
 {
@@ -244,10 +245,16 @@ static void json_smart_extended_log(void *data)
        json_free_object(root);
 }
 
+static void json_telemetry_log(struct ocp_telemetry_parse_options *options)
+{
+       print_ocp_telemetry_json(options);
+}
+
 static struct ocp_print_ops json_print_ops = {
        .hwcomp_log = json_hwcomp_log,
        .fw_act_history = json_fw_activation_history,
        .smart_extended_log = json_smart_extended_log,
+       .telemetry_log = json_telemetry_log,
 };
 
 struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t flags)
index 6aac2579237f4e67013278f87ea7b36bb5639cca..a09cd89413bc8c7ad3f486f050c6fdda7ad3ffdc 100644 (file)
@@ -6,6 +6,7 @@
 #include "ocp-hardware-component-log.h"
 #include "ocp-fw-activation-history.h"
 #include "ocp-smart-extended-log.h"
+#include "ocp-telemetry-decode.h"
 
 static void print_hwcomp_desc(struct hwcomp_desc_entry *e, bool list, int num)
 {
@@ -192,10 +193,18 @@ static void stdout_smart_extended_log(void *data)
        printf("\n");
 }
 
+static void stdout_telemetry_log(struct ocp_telemetry_parse_options *options)
+{
+#ifdef CONFIG_JSONC
+       print_ocp_telemetry_normal(options);
+#endif /* CONFIG_JSONC */
+}
+
 static struct ocp_print_ops stdout_print_ops = {
        .hwcomp_log = stdout_hwcomp_log,
        .fw_act_history = stdout_fw_activation_history,
        .smart_extended_log = stdout_smart_extended_log,
+       .telemetry_log = stdout_telemetry_log,
 };
 
 struct ocp_print_ops *ocp_get_stdout_print_ops(nvme_print_flags_t flags)
index 4cdd50899fbde5ed3fdda9b2870a6b38db3d2f4c..3155b2857877d9a7f7a22053d87c6936c764cba0 100644 (file)
@@ -38,3 +38,8 @@ void ocp_smart_extended_log(void *data, nvme_print_flags_t flags)
 {
        ocp_print(smart_extended_log, flags, data);
 }
+
+void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags)
+{
+       ocp_print(telemetry_log, flags, options);
+}
index 38ae93e85a8a2e0ca30a7454f959420d3fd7519a..5603e501bfef30774059ab030cc86ae9cf4f534b 100644 (file)
@@ -4,11 +4,13 @@
 
 #include "ocp-hardware-component-log.h"
 #include "ocp-fw-activation-history.h"
+#include "ocp-telemetry-decode.h"
 
 struct ocp_print_ops {
        void (*hwcomp_log)(struct hwcomp_log *log, __u32 id, bool list);
        void (*fw_act_history)(const struct fw_activation_history *fw_history);
        void (*smart_extended_log)(void *data);
+       void (*telemetry_log)(struct ocp_telemetry_parse_options *options);
        nvme_print_flags_t flags;
 };
 
@@ -27,4 +29,5 @@ static inline struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t fl
 void ocp_show_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list, nvme_print_flags_t flags);
 void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_print_flags_t flags);
 void ocp_smart_extended_log(void *data, nvme_print_flags_t flags);
+void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags);
 #endif /* OCP_PRINT_H */
index 9f1a39ad15e77ae9bd51baa65eafc3784997b61d..0ce7a419b03593e95a2cfcfae6ac99335d8c32ee 100644 (file)
@@ -3,6 +3,8 @@
  *
  * Authors: Jeff Lien <jeff.lien@wdc.com>,
  */
+#ifndef OCP_TELEMETRY_DECODE_H
+#define OCP_TELEMETRY_DECODE_H
 
 #include "nvme.h"
 #include "nvme-print.h"
@@ -1225,3 +1227,4 @@ void parse_common_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descr
 void parse_media_wear_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
                            struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
                            struct json_object *pevent_fifos_object, FILE *fp);
+#endif /* OCP_TELEMETRY_DECODE_H */