From 882155d6e7aefabde7ad64098874dafe070cc63b Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 6 Oct 2024 10:22:10 +0900 Subject: [PATCH] ocp: move ocp telemetry log print function into ocp-print Still the ocp-telemetry-decode used by print functions combined json code. Signed-off-by: Tokunori Ikegami --- plugins/ocp/ocp-nvme.c | 12 ++---------- plugins/ocp/ocp-print-json.c | 7 +++++++ plugins/ocp/ocp-print-stdout.c | 9 +++++++++ plugins/ocp/ocp-print.c | 5 +++++ plugins/ocp/ocp-print.h | 3 +++ plugins/ocp/ocp-telemetry-decode.h | 3 +++ 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index f6ed1e14..815d065b 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -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; } diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index d2a691bf..568d6c92 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -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) diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index 6aac2579..a09cd894 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -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) diff --git a/plugins/ocp/ocp-print.c b/plugins/ocp/ocp-print.c index 4cdd5089..3155b285 100644 --- a/plugins/ocp/ocp-print.c +++ b/plugins/ocp/ocp-print.c @@ -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); +} diff --git a/plugins/ocp/ocp-print.h b/plugins/ocp/ocp-print.h index 38ae93e8..5603e501 100644 --- a/plugins/ocp/ocp-print.h +++ b/plugins/ocp/ocp-print.h @@ -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 */ diff --git a/plugins/ocp/ocp-telemetry-decode.h b/plugins/ocp/ocp-telemetry-decode.h index 9f1a39ad..0ce7a419 100644 --- a/plugins/ocp/ocp-telemetry-decode.h +++ b/plugins/ocp/ocp-telemetry-decode.h @@ -3,6 +3,8 @@ * * Authors: Jeff Lien , */ +#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 */ -- 2.50.1