From bcb99b0ecfc6cac8b0778a83278466b76654bb6d Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 4 Jun 2023 19:21:26 +0900 Subject: [PATCH] plugins/solidigm: Fix linux kernel check patch errors and warnings Signed-off-by: Tokunori Ikegami --- .../solidigm/solidigm-garbage-collection.c | 35 ++++---- plugins/solidigm/solidigm-internal-logs.c | 6 +- plugins/solidigm/solidigm-latency-tracking.c | 69 +++++++-------- plugins/solidigm/solidigm-log-page-dir.c | 33 ++++--- plugins/solidigm/solidigm-smart.c | 58 ++++++------- plugins/solidigm/solidigm-telemetry.c | 2 +- plugins/solidigm/solidigm-telemetry/cod.c | 87 +++++++++---------- .../solidigm/solidigm-telemetry/data-area.c | 68 +++++++-------- plugins/solidigm/solidigm-telemetry/header.c | 32 +++---- 9 files changed, 187 insertions(+), 203 deletions(-) diff --git a/plugins/solidigm/solidigm-garbage-collection.c b/plugins/solidigm/solidigm-garbage-collection.c index 3828b9e6..b26d7542 100644 --- a/plugins/solidigm/solidigm-garbage-collection.c +++ b/plugins/solidigm/solidigm-garbage-collection.c @@ -21,26 +21,27 @@ #include "solidigm-garbage-collection.h" #include "solidigm-util.h" -typedef struct __attribute__((packed)) gc_item { +struct __packed gc_item { __le32 timer_type; __le64 timestamp; -} gc_item_t; +}; #define VU_GC_MAX_ITEMS 100 -typedef struct garbage_control_collection_log { +struct garbage_control_collection_log { __le16 version_major; __le16 version_minor; - gc_item_t item[VU_GC_MAX_ITEMS]; + struct __packed gc_item 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) +static void vu_gc_log_show_json(struct garbage_control_collection_log *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 __packed gc_item 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); @@ -50,7 +51,7 @@ static void vu_gc_log_show_json(garbage_control_collection_log_t *payload, const json_free_object(gc_entries); } -static void vu_gc_log_show(garbage_control_collection_log_t *payload, const char *devname, +static void vu_gc_log_show(struct garbage_control_collection_log *payload, const char *devname, __u8 uuid_index) { printf("Solidigm Garbage Collection Log for NVME device:%s UUID-idx:%d\n", devname, @@ -58,7 +59,8 @@ static void vu_gc_log_show(garbage_control_collection_log_t *payload, const char printf("Timestamp Timer Type\n"); for (int i = 0; i < VU_GC_MAX_ITEMS; i++) { - gc_item_t item = payload->item[i]; + struct __packed gc_item item = payload->item[i]; + printf("%-13" PRIu64 " %d\n", le64_to_cpu(item.timestamp), le32_to_cpu(item.timer_type)); } } @@ -88,15 +90,16 @@ int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *c return err; enum nvme_print_flags flags = validate_output_format(cfg.output_format); + if (flags == -EINVAL) { fprintf(stderr, "Invalid output format '%s'\n", cfg.output_format); dev_close(dev); - return EINVAL; + return -EINVAL; } uuid_index = solidigm_get_vu_uuid_index(dev); - garbage_control_collection_log_t gc_log; + struct garbage_control_collection_log gc_log; const int solidigm_vu_gc_log_id = 0xfd; struct nvme_get_log_args args = { .lpo = 0, @@ -118,15 +121,13 @@ int solidigm_get_garbage_collection_log(int argc, char **argv, struct command *c err = nvme_get_log(&args); if (!err) { - if (flags & BINARY) { + if (flags & BINARY) d_raw((unsigned char *)&gc_log, sizeof(gc_log)); - } else if (flags & JSON) { + else if (flags & JSON) vu_gc_log_show_json(&gc_log, dev->name); - } else { + else vu_gc_log_show(&gc_log, dev->name, uuid_index); - } - } - else if (err > 0) { + } else if (err > 0) { nvme_show_status(err); } diff --git a/plugins/solidigm/solidigm-internal-logs.c b/plugins/solidigm/solidigm-internal-logs.c index 0519f61a..47304438 100644 --- a/plugins/solidigm/solidigm-internal-logs.c +++ b/plugins/solidigm/solidigm-internal-logs.c @@ -285,7 +285,7 @@ static int dump_event_logs(struct nvme_dev *dev, struct config cfg) .cdw13 = 0, }; int output; - int core_num,err; + int core_num, err; err = read_header(&cmd, dev_fd(dev)); if (err) @@ -500,8 +500,8 @@ int solidigm_get_internal_log(int argc, char **argv, struct command *command, bool all = false; const char *desc = "Get Debug Firmware Logs and save them."; - const char *type = "Log type: ALL, CONTROLLERINITTELEMETRY, HOSTINITTELEMETRY, " - "HOSTINITTELEMETRYNOGEN, NLOG, ASSERT, EVENT. Defaults to ALL."; + const char *type = + "Log type: ALL, CONTROLLERINITTELEMETRY, HOSTINITTELEMETRY, HOSTINITTELEMETRYNOGEN, NLOG, ASSERT, EVENT. Defaults to ALL."; const char *prefix = "Output file prefix; defaults to device serial number."; const char *verbose = "To print out verbose info."; const char *namespace_id = "Namespace to get logs from."; diff --git a/plugins/solidigm/solidigm-latency-tracking.c b/plugins/solidigm/solidigm-latency-tracking.c index 40edcfa0..481a8314 100644 --- a/plugins/solidigm/solidigm-latency-tracking.c +++ b/plugins/solidigm/solidigm-latency-tracking.c @@ -94,7 +94,6 @@ static void latency_tracker_bucket_parse(const struct latency_tracker *lt, int i __u32 bucket_data = le32_to_cpu(lt->stats.data[id]); if (lt->print_flags == NORMAL) { - printf("%-*d", COL_WIDTH, id); get_time_unit_label(buffer, lower_us, true); @@ -137,12 +136,10 @@ static void latency_tracker_parse_linear(const struct latency_tracker *lt, __u32 bytes_per, __u32 us_step, bool nonzero_print) { - for (int i = (start_offset / bytes_per) - 1; - i < end_offset / bytes_per; i++) { - if (nonzero_print && lt->stats.data[i] == 0) + for (int i = (start_offset / bytes_per) - 1; i < end_offset / bytes_per; i++) { + if (nonzero_print && !lt->stats.data[i]) continue; - latency_tracker_bucket_parse(lt, i, us_step * i, - us_step * (i + 1), true); + latency_tracker_bucket_parse(lt, i, us_step * i, us_step * (i + 1), true); } } @@ -153,6 +150,7 @@ static void latency_tracker_parse_linear(const struct latency_tracker *lt, static int latency_tracker_bucket_pos2us(const struct latency_tracker *lt, int i) { __u32 base_val = 1 << lt->base_range_bits; + if (i < (base_val << 1)) return i; @@ -171,15 +169,15 @@ static int latency_tracker_bucket_pos2us(const struct latency_tracker *lt, int i * "values" : { */ static void latency_tracker_populate_json_root(const struct latency_tracker *lt, - struct json_object *root) + struct json_object *root) { struct json_object *subroot = json_create_object(); json_object_add_value_object(root, "latstats", subroot); json_object_add_value_string(subroot, "type", lt->cfg.write ? "write" : "read"); - if (lt->has_average_latency_field) { - json_object_add_value_uint64(subroot, "average_latency", le64_to_cpu(lt->stats.average_latency)); - } + if (lt->has_average_latency_field) + json_object_add_value_uint64(subroot, "average_latency", + le64_to_cpu(lt->stats.average_latency)); json_object_add_value_object(subroot, "values", lt->bucket_list); } @@ -199,13 +197,12 @@ static void latency_tracker_parse_4_0(const struct latency_tracker *lt) int lower_us = latency_tracker_bucket_pos2us(lt, i); int upper_us = latency_tracker_bucket_pos2us(lt, i + 1); - latency_tracker_bucket_parse(lt, i, lower_us, - upper_us, + latency_tracker_bucket_parse(lt, i, lower_us, upper_us, i < (lt->bucket_list_size - 1)); } } -static void print_dash_separator() +static void print_dash_separator(void) { printf("--------------------------------------------------\n"); } @@ -218,16 +215,14 @@ static void latency_tracker_pre_parse(struct latency_tracker *lt) printf("UUID-idx: %d\n", lt->uuid_index); printf("Major Revision: %u\nMinor Revision: %u\n", le16_to_cpu(lt->stats.version_major), le16_to_cpu(lt->stats.version_minor)); - if (lt->has_average_latency_field) { + if (lt->has_average_latency_field) printf("Average Latency: %" PRIu64 "\n", le64_to_cpu(lt->stats.average_latency)); - } print_dash_separator(); printf("%-12s%-12s%-12s%-20s\n", "Bucket", "Start", "End", "Value"); print_dash_separator(); } - if (lt->print_flags == JSON) { + if (lt->print_flags == JSON) lt->bucket_list = json_object_new_array(); - } } static void latency_tracker_post_parse(struct latency_tracker *lt) @@ -253,11 +248,10 @@ static void latency_tracker_parse(struct latency_tracker *lt) latency_tracker_parse_3_0(lt); break; case 4: - if (version_minor >= 8){ + if (version_minor >= 8) lt->has_average_latency_field = true; - } latency_tracker_pre_parse(lt); - if (version_minor == 0){ + if (!version_minor) { lt->base_range_bits = BASE_RANGE_BITS_4_0; lt->bucket_list_size = BUCKET_LIST_SIZE_4_0; } @@ -275,7 +269,7 @@ static void latency_tracker_parse(struct latency_tracker *lt) #define LATENCY_TRACKING_FID 0xe2 #define LATENCY_TRACKING_FID_DATA_LEN 32 -static int latency_tracking_is_enable(struct latency_tracker *lt, __u32 * enabled) +static int latency_tracking_is_enable(struct latency_tracker *lt, __u32 *enabled) { struct nvme_get_features_args args_get = { .args_size = sizeof(args_get), @@ -298,13 +292,12 @@ static int latency_tracking_enable(struct latency_tracker *lt) __u32 result; int err; - if (!(lt->cfg.enable || lt->cfg.disable)){ + if (!(lt->cfg.enable || lt->cfg.disable)) return 0; - } - if (lt->cfg.enable && lt->cfg.disable){ - fprintf(stderr,"Cannot enable and disable simultaneously.\n"); - return EINVAL; + if (lt->cfg.enable && lt->cfg.disable) { + fprintf(stderr, "Cannot enable and disable simultaneously.\n"); + return -EINVAL; } struct nvme_set_features_args args_set = { @@ -345,9 +338,9 @@ static int latency_tracker_get_log(struct latency_tracker *lt) { int err; - if (lt->cfg.read && lt->cfg.write){ - fprintf(stderr,"Cannot capture read and write logs simultaneously.\n"); - return EINVAL; + if (lt->cfg.read && lt->cfg.write) { + fprintf(stderr, "Cannot capture read and write logs simultaneously.\n"); + return -EINVAL; } if (!(lt->cfg.read || lt->cfg.write)) @@ -422,31 +415,31 @@ int solidigm_get_latency_tracking_log(int argc, char **argv, struct command *cmd if (lt.print_flags == -EINVAL) { fprintf(stderr, "Invalid output format '%s'\n", lt.cfg.output_format); dev_close(dev); - return EINVAL; + return -EINVAL; } if (lt.cfg.type > 0xf) { fprintf(stderr, "Invalid Log type value '%d'\n", lt.cfg.type); dev_close(dev); - return EINVAL; + return -EINVAL; } if (lt.cfg.type && !(lt.cfg.read || lt.cfg.write)) { fprintf(stderr, "Log type option valid only when retrieving statistics\n"); dev_close(dev); - return EINVAL; + return -EINVAL; } lt.uuid_index = solidigm_get_vu_uuid_index(dev); err = latency_tracking_enable(<); - if (err){ + if (err) { dev_close(dev); return err; } err = latency_tracker_get_log(<); - if (err){ + if (err) { dev_close(dev); return err; } @@ -460,16 +453,16 @@ int solidigm_get_latency_tracking_log(int argc, char **argv, struct command *cmd if (!err) { if (lt.print_flags == JSON) { struct json_object *root = json_create_object(); - json_object_add_value_int(root,"enabled", enabled); + + json_object_add_value_int(root, "enabled", enabled); json_print_object(root, NULL); json_free_object(root); printf("\n"); } else if (lt.print_flags == BINARY) { putchar(enabled); } else { - printf( - "Latency Statistics Tracking (UUID-idx:%d, FID:0x%X) is currently %i.\n", - lt.uuid_index, LATENCY_TRACKING_FID, enabled); + printf("Latency Statistics Tracking (UUID-idx:%d, FID:0x%X) is currently %i.\n", + lt.uuid_index, LATENCY_TRACKING_FID, enabled); } } else { fprintf(stderr, "Could not read feature id 0xE2.\n"); diff --git a/plugins/solidigm/solidigm-log-page-dir.c b/plugins/solidigm/solidigm-log-page-dir.c index 72d7f827..4972b888 100644 --- a/plugins/solidigm/solidigm-log-page-dir.c +++ b/plugins/solidigm/solidigm-log-page-dir.c @@ -19,7 +19,7 @@ #define SOLIDIGM_MAX_UUID 2 struct lid_dir { - struct __attribute__((packed)) { + struct __packed { bool supported; const char *str; } lid[NVME_LOG_SUPPORTED_LOG_PAGES_MAX]; @@ -38,8 +38,8 @@ static void init_lid_dir(struct lid_dir *lid_dir) static bool is_invalid_uuid(const struct nvme_id_uuid_list_entry entry) { static const unsigned char ALL_ZERO_UUID[NVME_UUID_LEN] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; return memcmp(ALL_ZERO_UUID, entry.uuid, NVME_UUID_LEN) == 0; @@ -68,7 +68,7 @@ static bool is_ocp_uuid(const struct nvme_id_uuid_list_entry entry) static int get_supported_log_pages_log(struct nvme_dev *dev, int uuid_index, struct nvme_supported_log_pages *supported) { - static const __u8 LID = 0x00; + static const __u8 LID; memset(supported, 0, sizeof(*supported)); struct nvme_get_log_args args = { @@ -92,7 +92,7 @@ static int get_supported_log_pages_log(struct nvme_dev *dev, int uuid_index, return nvme_get_log(&args); } -static struct lid_dir* get_standard_lids(struct nvme_supported_log_pages *supported) +static struct lid_dir *get_standard_lids(struct nvme_supported_log_pages *supported) { static struct lid_dir standard_dir = { 0 }; @@ -135,17 +135,17 @@ static struct lid_dir* get_standard_lids(struct nvme_supported_log_pages *suppor } static void update_vendor_lid_supported(struct nvme_supported_log_pages *supported, - struct lid_dir* lid_dir) + struct lid_dir *lid_dir) { for (int lid = 0; lid < NVME_LOG_SUPPORTED_LOG_PAGES_MAX; lid++) { - if (!supported->lid_support[lid]|| lid < MIN_VENDOR_LID) + if (!supported->lid_support[lid] || lid < MIN_VENDOR_LID) continue; lid_dir->lid[lid].supported = true; } } -static struct lid_dir* get_solidigm_lids(struct nvme_supported_log_pages *supported) +static struct lid_dir *get_solidigm_lids(struct nvme_supported_log_pages *supported) { static struct lid_dir solidigm_dir = { 0 }; @@ -161,7 +161,7 @@ static struct lid_dir* get_solidigm_lids(struct nvme_supported_log_pages *suppor return &solidigm_dir; } -static struct lid_dir* get_ocp_lids(struct nvme_supported_log_pages *supported) +static struct lid_dir *get_ocp_lids(struct nvme_supported_log_pages *supported) { static struct lid_dir ocp_dir = { 0 }; @@ -253,7 +253,7 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *c struct lid_dir *lid_dirs[SOLIDIGM_MAX_UUID + 1] = { 0 }; struct nvme_id_uuid_list uuid_list = { 0 }; struct nvme_supported_log_pages supported = { 0 }; - + err = get_supported_log_pages_log(dev, NO_UUID_INDEX, &supported); if (!err) { @@ -268,30 +268,29 @@ int solidigm_get_log_page_directory_log(int argc, char **argv, struct command *c if (solidigm_lid_dir->lid[lid].supported) lid_dirs[NO_UUID_INDEX]->lid[lid] = solidigm_lid_dir->lid[lid]; } - } - else { + } else { for (int uuid_index = 1; uuid_index <= SOLIDIGM_MAX_UUID; uuid_index++) { if (is_invalid_uuid(uuid_list.entry[uuid_index - 1])) break; else if (get_supported_log_pages_log(dev, uuid_index, &supported)) continue; - + if (is_solidigm_uuid(uuid_list.entry[uuid_index - 1])) lid_dirs[uuid_index] = get_solidigm_lids(&supported); else if (is_ocp_uuid(uuid_list.entry[uuid_index - 1])) lid_dirs[uuid_index] = get_ocp_lids(&supported); } } - } - else + } else { nvme_show_status(err); + } if (!err) { const enum nvme_print_flags print_flag = validate_output_format(format); - if (print_flag == NORMAL) + if (print_flag == NORMAL) { supported_log_pages_normal(lid_dirs); - else if (print_flag == JSON) { + } else if (print_flag == JSON) { supported_log_pages_json(lid_dirs); } else { fprintf(stderr, "Error: Invalid output format specified: %s.\n", format); diff --git a/plugins/solidigm/solidigm-smart.c b/plugins/solidigm/solidigm-smart.c index 568d3abf..e3d468a6 100644 --- a/plugins/solidigm/solidigm-smart.c +++ b/plugins/solidigm/solidigm-smart.c @@ -21,32 +21,31 @@ #include "solidigm-smart.h" #include "solidigm-util.h" -struct __attribute__((packed)) nvme_additional_smart_log_item { +struct __packed nvme_additional_smart_log_item { __u8 id; __u8 _kp[2]; __u8 normalized; __u8 _np; - union __attribute__((packed)) { + union __packed { __u8 raw[6]; - struct __attribute__((packed)) wear_level { + struct __packed wear_level { __le16 min; __le16 max; __le16 avg; } wear_level; - struct __attribute__((packed)) thermal_throttle { + struct __packed thermal_throttle { __u8 pct; __u32 count; } thermal_throttle; - } ; + }; __u8 _rp; -} ; -typedef struct nvme_additional_smart_log_item smart_log_item_t; +}; #define VU_SMART_PAGE_SIZE 512 -#define VU_SMART_MAX_ITEMS VU_SMART_PAGE_SIZE / sizeof(smart_log_item_t) -typedef struct vu_smart_log { - smart_log_item_t item[VU_SMART_MAX_ITEMS]; -} vu_smart_log_t; +#define VU_SMART_MAX_ITEMS (VU_SMART_PAGE_SIZE / sizeof(struct nvme_additional_smart_log_item)) +struct vu_smart_log { + struct nvme_additional_smart_log_item item[VU_SMART_MAX_ITEMS]; +}; static char *id_to_name(__u8 id) { @@ -110,11 +109,10 @@ static char *id_to_name(__u8 id) } } -static void smart_log_item_print(smart_log_item_t *item) +static void smart_log_item_print(struct nvme_additional_smart_log_item *item) { - if (!item->id) { + if (!item->id) return; - } printf("%#x %-45s %3d ", item->id, id_to_name(item->id), item->normalized); @@ -136,13 +134,12 @@ static void smart_log_item_print(smart_log_item_t *item) } } -static void smart_log_item_add_json(smart_log_item_t *item, struct json_object *dev_stats) +static void smart_log_item_add_json(struct nvme_additional_smart_log_item *item, struct json_object *dev_stats) { struct json_object *entry_stats = json_create_object(); - if (!item->id) { + if (!item->id) return; - } json_object_add_value_int(entry_stats, "normalized", item->normalized); @@ -162,15 +159,14 @@ static void smart_log_item_add_json(smart_log_item_t *item, struct json_object * json_object_add_value_object(dev_stats, id_to_name(item->id), entry_stats); } -static void vu_smart_log_show_json(vu_smart_log_t *payload, unsigned int nsid, const char *devname) +static void vu_smart_log_show_json(struct vu_smart_log *payload, unsigned int nsid, const char *devname) { struct json_object *dev_stats = json_create_object(); - smart_log_item_t *item = payload->item; + struct nvme_additional_smart_log_item *item = payload->item; struct json_object *root; - for (int i = 0; i < VU_SMART_MAX_ITEMS; i++) { + for (int i = 0; i < VU_SMART_MAX_ITEMS; i++) smart_log_item_add_json(&item[i], dev_stats); - } root = json_create_object(); json_object_add_value_string(root, "Solidigm SMART log", devname); @@ -180,26 +176,25 @@ static void vu_smart_log_show_json(vu_smart_log_t *payload, unsigned int nsid, c json_free_object(root); } -static void vu_smart_log_show(vu_smart_log_t *payload, unsigned int nsid, const char *devname, +static void vu_smart_log_show(struct vu_smart_log *payload, unsigned int nsid, const char *devname, __u8 uuid_index) { - smart_log_item_t *item = payload->item; + struct nvme_additional_smart_log_item *item = payload->item; printf("Additional Smart Log for NVMe device:%s namespace-id:%x UUID-idx:%d\n", devname, nsid, uuid_index); printf("ID KEY Normalized Raw\n"); - for (int i = 0; i < VU_SMART_MAX_ITEMS; i++) { + for (int i = 0; i < VU_SMART_MAX_ITEMS; i++) smart_log_item_print(&item[i]); - } } 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."; + const char *desc = + "Get Solidigm vendor specific smart log (optionally, for the specified namespace), and show it."; const int solidigm_vu_smart_log_id = 0xCA; - vu_smart_log_t smart_log_payload; + struct vu_smart_log smart_log_payload; enum nvme_print_flags flags; struct nvme_dev *dev; int err; @@ -254,15 +249,14 @@ int solidigm_get_additional_smart_log(int argc, char **argv, struct command *cmd err = nvme_get_log(&args); if (!err) { - if (flags & JSON) { + if (flags & JSON) vu_smart_log_show_json(&smart_log_payload, cfg.namespace_id, dev->name); - } else if (flags & BINARY) { + else if (flags & BINARY) d_raw((unsigned char *)&smart_log_payload, sizeof(smart_log_payload)); - } else { + else vu_smart_log_show(&smart_log_payload, cfg.namespace_id, dev->name, uuid_index); - } } else if (err > 0) { nvme_show_status(err); } diff --git a/plugins/solidigm/solidigm-telemetry.c b/plugins/solidigm/solidigm-telemetry.c index 061e60da..472284a1 100644 --- a/plugins/solidigm/solidigm-telemetry.c +++ b/plugins/solidigm/solidigm-telemetry.c @@ -121,7 +121,7 @@ int solidigm_get_telemetry_log(int argc, char **argv, struct command *cmd, struc cfg.cfg_file, strerror(err)); goto close_fd; } - struct json_tokener * jstok = json_tokener_new(); + struct json_tokener *jstok = json_tokener_new(); tl.configuration = json_tokener_parse_ex(jstok, conf_str, length); free(conf_str); diff --git a/plugins/solidigm/solidigm-telemetry/cod.c b/plugins/solidigm/solidigm-telemetry/cod.c index 58a6e709..363822a5 100644 --- a/plugins/solidigm/solidigm-telemetry/cod.c +++ b/plugins/solidigm/solidigm-telemetry/cod.c @@ -56,17 +56,15 @@ const char *oemDataMapDesc[] = { static const char *getOemDataMapDescription(uint32_t id) { - if (id < (sizeof(oemDataMapDesc) / sizeof(oemDataMapDesc[0]))) { + if (id < ARRAY_SIZE(oemDataMapDesc)) return oemDataMapDesc[id]; - } return "unknown"; } #define OEMSIGNATURE 0x504D4443 #pragma pack(push, cod, 1) -struct cod_header -{ +struct cod_header { uint32_t versionMajor; uint32_t versionMinor; uint32_t Signature; //!Fixed signature value (0x504D4443) for identification and validation @@ -75,8 +73,7 @@ struct cod_header uint8_t Reserved[12]; }; -struct cod_item -{ +struct cod_item { uint32_t DataFieldMapUid; //!The data field unique identifier value uint32_t reserved1 : 8; uint32_t dataFieldType : 8; @@ -90,8 +87,7 @@ struct cod_item uint8_t Reserved2[8]; }; -struct cod_map -{ +struct cod_map { struct cod_header header; struct cod_item items[]; }; @@ -100,8 +96,7 @@ struct cod_map void solidigm_telemetry_log_cod_parse(struct telemetry_log *tl) { - enum cod_field_type - { + enum cod_field_type { INTEGER, FLOAT, STRING, @@ -123,9 +118,8 @@ void solidigm_telemetry_log_cod_parse(struct telemetry_log *tl) uint64_t offset = json_object_get_int(COD_offset); - if (offset == 0) { + if (!offset) return; - } if ((offset + sizeof(struct cod_header)) > tl->log_size) { SOLIDIGM_LOG_WARNING("Warning: COD map header out of bounds."); @@ -135,61 +129,62 @@ void solidigm_telemetry_log_cod_parse(struct telemetry_log *tl) const struct cod_map *data = (struct cod_map *) (((uint8_t *)tl->log) + offset); uint32_t signature = be32_to_cpu(data->header.Signature); - if ( signature != OEMSIGNATURE){ + + if (signature != OEMSIGNATURE) { SOLIDIGM_LOG_WARNING("Warning: Unsupported COD data signature %x!", signature); return; } - if ((offset + data->header.MapSizeInBytes) > tl->log_size){ + if ((offset + data->header.MapSizeInBytes) > tl->log_size) { SOLIDIGM_LOG_WARNING("Warning: COD map data out of bounds."); return; } struct json_object *cod = json_create_object(); + json_object_object_add(tl->root, "cod", cod); for (uint64_t i = 0; i < data->header.EntryCount; i++) { if ((offset + sizeof(struct cod_header) + (i + 1) * sizeof(struct cod_item)) > - tl->log_size){ + tl->log_size) { SOLIDIGM_LOG_WARNING("Warning: COD data out of bounds at item %"PRIu64"!", i); return; } struct cod_item item = data->items[i]; - if (item.DataFieldOffset + item.DataFieldOffset > tl->log_size) { + + if (item.DataFieldOffset + item.DataFieldOffset > tl->log_size) continue; - } - if (item.dataInvalid) { + if (item.dataInvalid) continue; - } - uint8_t *val = ((uint8_t *)tl->log )+ item.DataFieldOffset; + uint8_t *val = ((uint8_t *)tl->log) + item.DataFieldOffset; const char *key = getOemDataMapDescription(item.DataFieldMapUid); - switch(item.dataFieldType){ - case(INTEGER): - if (item.issigned) { - json_object_object_add(cod, key, - json_object_new_int64(le64_to_cpu(*(uint64_t *)val))); - } else { - json_object_add_value_uint64(cod, key, le64_to_cpu(*(uint64_t *)val)); - } - break; - case(FLOAT): - json_object_add_value_float(cod, key, *(float *) val); - break; - case(STRING): - json_object_object_add(cod, key, - json_object_new_string_len((const char *)val, item.DataFieldSizeInBytes)); - break; - case(TWO_BYTE_ASCII): - json_object_object_add(cod, key, - json_object_new_string_len((const char *)val,2)); - break; - case(FOUR_BYTE_ASCII): + + switch (item.dataFieldType) { + case INTEGER: + if (item.issigned) json_object_object_add(cod, key, - json_object_new_string_len((const char *)val, 4)); - break; - default: - SOLIDIGM_LOG_WARNING("Warning: Unknown COD field type (%d)", item.DataFieldMapUid); - + json_object_new_int64(le64_to_cpu(*(uint64_t *)val))); + else + json_object_add_value_uint64(cod, key, le64_to_cpu(*(uint64_t *)val)); + break; + case FLOAT: + json_object_add_value_float(cod, key, *(float *)val); + break; + case STRING: + json_object_object_add(cod, key, + json_object_new_string_len((const char *)val, item.DataFieldSizeInBytes)); + break; + case TWO_BYTE_ASCII: + json_object_object_add(cod, key, + json_object_new_string_len((const char *)val, 2)); + break; + case FOUR_BYTE_ASCII: + json_object_object_add(cod, key, + json_object_new_string_len((const char *)val, 4)); + break; + default: + SOLIDIGM_LOG_WARNING("Warning: Unknown COD field type (%d)", item.DataFieldMapUid); + break; } } } diff --git a/plugins/solidigm/solidigm-telemetry/data-area.c b/plugins/solidigm/solidigm-telemetry/data-area.c index 93ea0fff..0cfa56c5 100644 --- a/plugins/solidigm/solidigm-telemetry/data-area.c +++ b/plugins/solidigm/solidigm-telemetry/data-area.c @@ -28,7 +28,7 @@ static bool telemetry_log_get_value(const struct telemetry_log *tl, uint32_t offset_byte; uint64_t val; - if (size_bit == 0) { + if (!size_bit) { char err_msg[MAX_WARNING_SIZE]; snprintf(err_msg, MAX_WARNING_SIZE, @@ -57,9 +57,8 @@ static bool telemetry_log_get_value(const struct telemetry_log *tl, char err_msg[MAX_WARNING_SIZE]; snprintf(err_msg, MAX_WARNING_SIZE, - "Value crossing 64 bit, byte aligned bounday, " - "not supported. size_bit=%u, offset_bit_from_byte=%u.", - size_bit, offset_bit_from_byte); + "Value crossing 64 bit, byte aligned bounday, not supported. size_bit=%u, offset_bit_from_byte=%u.", + size_bit, offset_bit_from_byte); *val_obj = json_object_new_string(err_msg); return false; @@ -118,18 +117,18 @@ static int telemetry_log_structure_parse(const struct telemetry_log *tl, type = json_object_get_string(obj); if (!json_object_object_get_ex(struct_def, "offsetBit", &obj)) { - SOLIDIGM_LOG_WARNING("Warning: Structure definition missing " - "property 'offsetBit': %s", - json_object_to_json_string(struct_def)); + SOLIDIGM_LOG_WARNING( + "Warning: Structure definition missing property 'offsetBit': %s", + json_object_to_json_string(struct_def)); return -1; } offset_bit = json_object_get_uint64(obj); if (!json_object_object_get_ex(struct_def, "sizeBit", &obj)) { - SOLIDIGM_LOG_WARNING("Warning: Structure definition missing " - "property 'sizeBit': %s", - json_object_to_json_string(struct_def)); + SOLIDIGM_LOG_WARNING( + "Warning: Structure definition missing property 'sizeBit': %s", + json_object_to_json_string(struct_def)); return -1; } @@ -144,23 +143,23 @@ static int telemetry_log_structure_parse(const struct telemetry_log *tl, if (!json_object_object_get_ex(struct_def, "arraySize", &obj_arraySizeArray)) { - SOLIDIGM_LOG_WARNING("Warning: Structure definition missing " - "property 'arraySize': %s", - json_object_to_json_string(struct_def)); + SOLIDIGM_LOG_WARNING( + "Warning: Structure definition missing property 'arraySize': %s", + json_object_to_json_string(struct_def)); return -1; } array_rank = json_object_array_length(obj_arraySizeArray); - if (array_rank == 0) { - SOLIDIGM_LOG_WARNING("Warning: Structure property 'arraySize' " - "don't support flexible array: %s", - json_object_to_json_string(struct_def)); + if (!array_rank) { + SOLIDIGM_LOG_WARNING( + "Warning: Structure property 'arraySize' don't support flexible array: %s", + json_object_to_json_string(struct_def)); return -1; } if (array_rank > MAX_ARRAY_RANK) { - SOLIDIGM_LOG_WARNING("Warning: Structure property 'arraySize' " - "don't support more than %d dimensions: %s", MAX_ARRAY_RANK, - json_object_to_json_string(struct_def)); + SOLIDIGM_LOG_WARNING( + "Warning: Structure property 'arraySize' don't support more than %d dimensions: %s", + MAX_ARRAY_RANK, json_object_to_json_string(struct_def)); return -1; } @@ -233,10 +232,10 @@ static int telemetry_log_structure_parse(const struct telemetry_log *tl, else json_object_object_add(sub_output, name, val_obj); } else { - SOLIDIGM_LOG_WARNING("Warning: %s From property '%s', " - "array index %u, structure definition: %s", - json_object_get_string(val_obj), - name, j, json_object_to_json_string(struct_def)); + SOLIDIGM_LOG_WARNING( + "Warning: %s From property '%s', array index %u, structure definition: %s", + json_object_get_string(val_obj), name, j, + json_object_to_json_string(struct_def)); json_free_object(val_obj); } } else { @@ -378,17 +377,18 @@ static void telemetry_log_data_area_toc_parse(const struct telemetry_log *tl, const char *nlog_name = NULL; uint32_t header_offset = sizeof(const struct telemetry_object_header); - if ((char *)&toc->items[i] > (((char *)toc) + da_size - sizeof(const struct toc_item))) { - SOLIDIGM_LOG_WARNING("Warning: Data Area %d, " - "Table of Contents item %d " - "crossed Data Area size.", da, i); + if ((char *)&toc->items[i] > + (((char *)toc) + da_size - sizeof(const struct toc_item))) { + SOLIDIGM_LOG_WARNING( + "Warning: Data Area %d, Table of Contents item %d crossed Data Area size.", + da, i); return; } obj_offset = toc->items[i].OffsetBytes; if ((obj_offset + sizeof(const struct telemetry_object_header)) > da_size) { - SOLIDIGM_LOG_WARNING("Warning: Data Area %d, item %d " - "data, crossed Data Area size.", da, i); + SOLIDIGM_LOG_WARNING( + "Warning: Data Area %d, item %d data, crossed Data Area size.", da, i); continue; } @@ -407,10 +407,10 @@ static void telemetry_log_data_area_toc_parse(const struct telemetry_log *tl, json_object_add_value_uint(toc_item, "mediaBankId", header->CoreId); has_struct = solidigm_config_get_struct_by_token_version(tl->configuration, - header->Token, - header->versionMajor, - header->versionMinor, - &structure_definition); + header->Token, + header->versionMajor, + header->versionMinor, + &structure_definition); if (!has_struct) { if (!nlog_formats) continue; diff --git a/plugins/solidigm/solidigm-telemetry/header.c b/plugins/solidigm/solidigm-telemetry/header.c index bd488ae5..866ebfff 100644 --- a/plugins/solidigm/solidigm-telemetry/header.c +++ b/plugins/solidigm/solidigm-telemetry/header.c @@ -9,8 +9,7 @@ #include "header.h" #pragma pack(push, reason_indentifier, 1) -struct reason_indentifier_1_0 -{ +struct reason_indentifier_1_0 { uint16_t versionMajor; uint16_t versionMinor; uint32_t reasonCode; //! 0 denotes no issue. All other values denote a potential issue. @@ -24,8 +23,7 @@ static_assert(sizeof(const struct reason_indentifier_1_0) == MEMBER_SIZE(struct nvme_telemetry_log, rsnident), "Size mismatch for reason_indentifier_1_0"); -struct reason_indentifier_1_1 -{ +struct reason_indentifier_1_1 { uint16_t versionMajor; uint16_t versionMinor; uint32_t reasonCode; //! 0 denotes no issue. All other values denote a potential issue. @@ -42,8 +40,7 @@ static_assert(sizeof(const struct reason_indentifier_1_1) == MEMBER_SIZE(struct nvme_telemetry_log, rsnident), "Size mismatch for reason_indentifier_1_1"); -struct reason_indentifier_1_2 -{ +struct reason_indentifier_1_2 { uint16_t versionMajor; uint16_t versionMinor; uint32_t reasonCode; //! 0 denotes no issue. All other values denote a potential issue. @@ -81,8 +78,9 @@ static void telemetry_log_reason_id_parse1_0_ext(const struct telemetry_log *tl, reserved = json_create_array(); json_object_add_value_array(reason_id, "reserved", reserved); - for ( int i=0; i < sizeof(ri->Reserved); i++) { + for (int i = 0; i < sizeof(ri->Reserved); i++) { struct json_object *val = json_object_new_int(ri->Reserved[i]); + json_object_array_add(reserved, val); } } @@ -114,6 +112,7 @@ static void telemetry_log_reason_id_parse1_1_ext(const struct telemetry_log *tl, json_object_add_value_array(reason_id, "reserved", reserved); for (int i = 0; i < sizeof(ri->Reserved); i++) { struct json_object *val = json_object_new_int(ri->Reserved[i]); + json_object_array_add(reserved, val); } } @@ -142,6 +141,7 @@ static void telemetry_log_reason_id_parse1_2_ext(const struct telemetry_log *tl, json_object_add_value_array(reason_id, "reserved2", reserved); for (int i = 0; i < sizeof(ri->Reserved2); i++) { struct json_object *val = json_object_new_int(ri->Reserved2[i]); + json_object_array_add(reserved, val); } @@ -149,6 +149,7 @@ static void telemetry_log_reason_id_parse1_2_ext(const struct telemetry_log *tl, json_object_add_value_array(reason_id, "dualPortReserved", dp_reserved); for (int i = 0; i < sizeof(ri->DualPortReserved); i++) { struct json_object *val = json_object_new_int(ri->DualPortReserved[i]); + json_object_array_add(dp_reserved, val); } } @@ -168,14 +169,15 @@ static void solidigm_telemetry_log_reason_id_parse(const struct telemetry_log *t sizeof(ri1_0->DriveStatus))); if (version_major == 1) { switch (version_minor) { - case 0: - telemetry_log_reason_id_parse1_0_ext(tl, reason_id); - break; - case 1: - telemetry_log_reason_id_parse1_1_ext(tl, reason_id); - break; - default: - telemetry_log_reason_id_parse1_2_ext(tl, reason_id); + case 0: + telemetry_log_reason_id_parse1_0_ext(tl, reason_id); + break; + case 1: + telemetry_log_reason_id_parse1_1_ext(tl, reason_id); + break; + default: + telemetry_log_reason_id_parse1_2_ext(tl, reason_id); + break; } } } -- 2.49.0