nvme-cli/SOURCES/0012-nvme-cli-Adds-readable-firmware-level-in-persistent.patch
2022-11-08 13:58:41 +00:00

114 lines
4.4 KiB
Diff

From 7e858ab53eb23083205d75f590ca2c2b256c2a7b Mon Sep 17 00:00:00 2001
From: Maurizio Lombardi <mlombard@redhat.com>
Date: Thu, 30 Jun 2022 16:37:40 +0200
Subject: [PATCH 5/7] nvme-cli: Adds readable firmware level in persistent
For example, In Firmware Commit Event:
Old Firmware Revision: 3617604718875264338
New Firmware Revision: 3833777500989048146
changes to
Old Firmware Revision: 3617604718875264338 (REV.SP42)
New Firmware Revision: 3833777500989048146 (REV.SP45)
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
nvme-print.c | 43 ++++++++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/nvme-print.c b/nvme-print.c
index 3b82b174..74ecd95a 100755
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -104,12 +104,15 @@ const char *nvme_cmd_to_string(int admin, __u8 opcode)
return "Unknown";
}
-static char *fw_to_string(__u8 fw[])
+static const char *fw_to_string(char *c)
{
- static char frs[9];
+ static char ret[9];
+ int i;
- snprintf(frs, sizeof(frs), "%-.*s", 8, fw);
- return frs;
+ for (i = 0; i < 8; i++)
+ ret[i] = c[i] >= '!' && c[i] <= '~' ? c[i] : '.';
+ ret[i] = '\0';
+ return ret;
}
static const char *get_sanitize_log_sstat_status_str(__u16 status)
@@ -1094,6 +1097,7 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
__u32 offset, por_info_len, por_info_list;
__u64 *fw_rev;
char key[128];
+ char fw_str[50];
struct nvme_smart_log *smart_event;
struct nvme_fw_commit_event *fw_commit_event;
struct nvme_time_stamp_change_event *ts_change_event;
@@ -1266,10 +1270,14 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
break;
case NVME_FW_COMMIT_EVENT:
fw_commit_event = pevent_log_info + offset;
- json_object_add_value_uint(valid_attrs, "old_fw_rev",
- le64_to_cpu(fw_commit_event->old_fw_rev));
- json_object_add_value_uint(valid_attrs, "new_fw_rev",
- le64_to_cpu(fw_commit_event->new_fw_rev));
+ snprintf(fw_str, sizeof(fw_str), "%"PRIu64" (%s)",
+ le64_to_cpu(fw_commit_event->old_fw_rev),
+ fw_to_string((char *)&fw_commit_event->old_fw_rev));
+ json_object_add_value_string(valid_attrs, "old_fw_rev", fw_str);
+ snprintf(fw_str, sizeof(fw_str), "%"PRIu64" (%s)",
+ le64_to_cpu(fw_commit_event->new_fw_rev),
+ fw_to_string((char *)&fw_commit_event->new_fw_rev));
+ json_object_add_value_string(valid_attrs, "new_fw_rev", fw_str);
json_object_add_value_uint(valid_attrs, "fw_commit_action",
fw_commit_event->fw_commit_action);
json_object_add_value_uint(valid_attrs, "fw_slot",
@@ -1297,8 +1305,10 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
por_info_list = por_info_len / sizeof(*por_event);
fw_rev = pevent_log_info + offset;
- json_object_add_value_uint(valid_attrs, "fw_rev",
- le64_to_cpu(*fw_rev));
+ snprintf(fw_str, sizeof(fw_str), "%"PRIu64" (%s)",
+ le64_to_cpu(*fw_rev),
+ fw_to_string((char *)fw_rev));
+ json_object_add_value_string(valid_attrs, "fw_rev", fw_str);
for (int i = 0; i < por_info_list; i++) {
por_event = pevent_log_info + offset +
sizeof(*fw_rev) + i * sizeof(*por_event);
@@ -1529,10 +1539,12 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
case NVME_FW_COMMIT_EVENT:
fw_commit_event = pevent_log_info + offset;
printf("FW Commit Event Entry: \n");
- printf("Old Firmware Revision: %"PRIu64"\n",
- le64_to_cpu(fw_commit_event->old_fw_rev));
- printf("New Firmware Revision: %"PRIu64"\n",
- le64_to_cpu(fw_commit_event->new_fw_rev));
+ printf("Old Firmware Revision: %"PRIu64" (%s)\n",
+ le64_to_cpu(fw_commit_event->old_fw_rev),
+ fw_to_string((char *)&fw_commit_event->old_fw_rev));
+ printf("New Firmware Revision: %"PRIu64" (%s)\n",
+ le64_to_cpu(fw_commit_event->new_fw_rev),
+ fw_to_string((char *)&fw_commit_event->new_fw_rev));
printf("FW Commit Action: %u\n",
fw_commit_event->fw_commit_action);
printf("FW Slot: %u\n", fw_commit_event->fw_slot);
@@ -1559,7 +1571,8 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
printf("Power On Reset Event Entry: \n");
fw_rev = pevent_log_info + offset;
- printf("Firmware Revision: %"PRIu64"\n", le64_to_cpu(*fw_rev));
+ printf("Firmware Revision: %"PRIu64" (%s)\n", le64_to_cpu(*fw_rev),
+ fw_to_string((char *)fw_rev));
printf("Reset Information List: \n");
for (int i = 0; i < por_info_list; i++) {
--
2.31.1