From e5dc5ef6bf11ad13049d57c193cf3f284f55af8e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 30 May 2023 10:08:10 +0200 Subject: [PATCH] nvme-print: Split add_bitmap implementation Instead a common function for printing the bitmaps just split it into the corresponding implementation. Signed-off-by: Daniel Wagner --- nvme-print-json.c | 21 +++++++-------------- nvme-print-json.h | 2 -- nvme-print.c | 14 +++++++++++++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/nvme-print-json.c b/nvme-print-json.c index d978a508..48e4be71 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -871,25 +871,18 @@ void json_predictable_latency_event_agg_log( json_free_object(root); } -void add_bitmap(int i, __u8 seb, struct json_object *root, int json_flag) +static void json_add_bitmap(int i, __u8 seb, struct json_object *root) { char evt_str[50]; char key[128]; for (int bit = 0; bit < 8; bit++) { if (nvme_pel_event_to_string(bit + i * 8)) { - if (json_flag == 1) { - sprintf(key, "bitmap_%x", (bit + i * 8)); - if ((seb >> bit) & 0x1) - snprintf(evt_str, sizeof(evt_str), "Support %s", - nvme_pel_event_to_string(bit + i * 8)); - json_object_add_value_string(root, key, evt_str); - } else { - if (nvme_pel_event_to_string(bit + i * 8)) - if ((seb >> bit) & 0x1) - printf(" Support %s\n", - nvme_pel_event_to_string(bit + i * 8)); - } + sprintf(key, "bitmap_%x", (bit + i * 8)); + if ((seb >> bit) & 0x1) + snprintf(evt_str, sizeof(evt_str), "Support %s", + nvme_pel_event_to_string(bit + i * 8)); + json_object_add_value_string(root, key, evt_str); } } } @@ -965,7 +958,7 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size) for (int i = 0; i < 32; i++) { if (pevent_log_head->seb[i] == 0) continue; - add_bitmap(i, pevent_log_head->seb[i], root, 1); + json_add_bitmap(i, pevent_log_head->seb[i], root); } } else { printf("No log data can be shown with this log len at least " \ diff --git a/nvme-print-json.h b/nvme-print-json.h index 40aebfa8..f65653b1 100644 --- a/nvme-print-json.h +++ b/nvme-print-json.h @@ -73,7 +73,6 @@ void json_endurance_group_event_agg_log( struct nvme_aggregate_predictable_lat_event *endurance_log, __u64 log_entries); void json_lba_status_log(void *lba_status); -void add_bitmap(int i, __u8 seb, struct json_object *root, int json_flag); void json_persistent_event_log(void *pevent_log_info, __u32 size); void json_predictable_latency_event_agg_log( struct nvme_aggregate_predictable_lat_event *pea_log, @@ -138,7 +137,6 @@ void json_connect_msg(nvme_ctrl_t c); #define json_resv_notif_log(resv) #define json_endurance_group_event_agg_log(endurance_log, log_entries) #define json_lba_status_log(lba_status) -#define add_bitmap(i, seb, root, json_flag) #define json_persistent_event_log(pevent_log_info, size) #define json_predictable_latency_event_agg_log(pea_log, log_entries) #define json_predictable_latency_per_nvmset(plpns_log, nvmset_id) diff --git a/nvme-print.c b/nvme-print.c index 1530036b..c58792e2 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -267,6 +267,18 @@ static void nvme_show_persistent_event_entry_ehai(__u8 ehai) "Event not associated with any port and PELPID does not apply"); } +static void add_bitmap(int i, __u8 seb) +{ + for (int bit = 0; bit < 8; bit++) { + if (nvme_pel_event_to_string(bit + i * 8)) { + if (nvme_pel_event_to_string(bit + i * 8)) + if ((seb >> bit) & 0x1) + printf(" Support %s\n", + nvme_pel_event_to_string(bit + i * 8)); + } + } +} + void nvme_show_persistent_event_log(void *pevent_log_info, __u8 action, __u32 size, const char *devname, enum nvme_print_flags flags) @@ -336,7 +348,7 @@ void nvme_show_persistent_event_log(void *pevent_log_info, for (int i = 0; i < 32; i++) { if (pevent_log_head->seb[i] == 0) continue; - add_bitmap(i, pevent_log_head->seb[i], NULL, 0); + add_bitmap(i, pevent_log_head->seb[i]); } } else { printf("No log data can be shown with this log len at least " \ -- 2.49.0