From c5e47f7148b99ecbc359a8ba3814fa77503bff03 Mon Sep 17 00:00:00 2001 From: Klaus Jensen Date: Thu, 26 Jan 2023 09:38:40 +0100 Subject: [PATCH] nvme-print: prettify the fdp event printing The default human readable printing of FDP events does not have to print the event flags since they are only used to indicate the validity of some of the fields. Remove the flags from printing and use it to conditionally print valid fields. Signed-off-by: Klaus Jensen --- nvme-print.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index 53b7223d..11b370e8 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -2522,6 +2522,20 @@ static void json_nvme_fdp_events(struct nvme_fdp_events_log *log) json_free_object(root); } +static const char *nvme_fdp_event_to_string(enum nvme_fdp_event_type event) +{ + switch (event) { + case NVME_FDP_EVENT_RUNFW: return "Reclaim Unit Not Fully Written"; + case NVME_FDP_EVENT_RUTLE: return "Reclaim Unit Active Time Limit Exceeded"; + case NVME_FDP_EVENT_RESET: return "Controller Level Reset Modified Reclaim Unit Handles"; + case NVME_FDP_EVENT_PID: return "Invalid Placement Identifier"; + case NVME_FDP_EVENT_REALLOC: return "Media Reallocated"; + case NVME_FDP_EVENT_MODIFY: return "Implicitly Modified Reclaim Unit Handle"; + } + + return "Unknown"; +} + void nvme_show_fdp_events(struct nvme_fdp_events_log *log, enum nvme_print_flags flags) { @@ -2536,11 +2550,14 @@ void nvme_show_fdp_events(struct nvme_fdp_events_log *log, struct nvme_fdp_event *event = &log->events[i]; printf("Event[%u]\n", i); - printf(" Event Type: 0x%"PRIx8"\n", event->type); - printf(" FDP Event Flags (FDPEF): 0x%"PRIx8"\n", event->flags); - printf(" Placement Identifier (PID): 0x%"PRIx16"\n", le16_to_cpu(event->pid)); + printf(" Event Type: 0x%"PRIx8" (%s)\n", event->type, nvme_fdp_event_to_string(event->type)); printf(" Event Timestamp: %"PRIu64"\n", le64_to_cpu(event->timestamp)); - printf(" Namespace Identifier (NSID): %"PRIu32"\n", le32_to_cpu(event->nsid)); + + if (event->flags & NVME_FDP_EVENT_F_PIV) + printf(" Placement Identifier (PID): 0x%"PRIx16"\n", le16_to_cpu(event->pid)); + + if (event->flags & NVME_FDP_EVENT_F_NSIDV) + printf(" Namespace Identifier (NSID): %"PRIu32"\n", le32_to_cpu(event->nsid)); if (event->type == NVME_FDP_EVENT_REALLOC) { struct nvme_fdp_event_realloc *mr; @@ -2553,8 +2570,10 @@ void nvme_show_fdp_events(struct nvme_fdp_events_log *log, } } - printf(" Reclaim Group Identifier: %"PRIu16"\n", le16_to_cpu(event->rgid)); - printf(" Reclaim Unit Handle Identifier %"PRIu8"\n", event->ruhid); + if (event->flags & NVME_FDP_EVENT_F_LV) { + printf(" Reclaim Group Identifier: %"PRIu16"\n", le16_to_cpu(event->rgid)); + printf(" Reclaim Unit Handle Identifier %"PRIu8"\n", event->ruhid); + } printf("\n"); } @@ -6852,20 +6871,6 @@ void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize, le32_to_cpu(sanitize->etcend)); } -static const char *nvme_fdp_event_to_string(enum nvme_fdp_event_type event) -{ - switch (event) { - case NVME_FDP_EVENT_RUNFW: return "Reclaim Unit Not Fully Written"; - case NVME_FDP_EVENT_RUTLE: return "Reclaim Unit Active Time Limit Exceeded"; - case NVME_FDP_EVENT_RESET: return "Controller Level Reset Modified Reclaim Unit Handles"; - case NVME_FDP_EVENT_PID: return "Invalid Placement Identifier"; - case NVME_FDP_EVENT_REALLOC: return "Media Reallocated"; - case NVME_FDP_EVENT_MODIFY: return "Implicitly Modified Reclaim Unit Handle"; - } - - return "Unknown"; -} - const char *nvme_feature_to_string(enum nvme_features_id feature) { switch (feature) { -- 2.50.1