From 745959b8ed4e48a25f9448aecedd236afaebe291 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Sun, 23 Oct 2022 11:13:00 +0800 Subject: [PATCH] nvme-print: decode status types With the new nvme_status_get_type/nvme_status_get_value() accessors in libnvme, restructure nvme_show_status to allow type-specific deciding in future. Signed-off-by: Jeremy Kerr --- nvme-print.c | 26 ++++++++++++++++++++++---- nvme-print.h | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index b16bccf7..898d43f3 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -3255,10 +3255,28 @@ void d_raw(unsigned char *buf, unsigned len) putchar(*(buf+i)); } -void nvme_show_status(__u16 status) -{ - fprintf(stderr, "NVMe status: %s(%#x)\n", - nvme_status_to_string(status, false), status); +void nvme_show_status(int status) +{ + int val = nvme_status_get_value(status); + int type = nvme_status_get_type(status); + + /* Callers should be checking for negative values first, but provide a + * sensible fallback anyway + */ + if (status < 0) { + fprintf(stderr, "Error: %s\n", nvme_strerror(errno)); + return; + } + + switch (type) { + case NVME_STATUS_TYPE_NVME: + fprintf(stderr, "NVMe status: %s(%#x)\n", + nvme_status_to_string(val, false), val); + break; + default: + fprintf(stderr, "Unknown status type %d, value %#x\n", + type, val); + } } static void nvme_show_id_ctrl_cmic(__u8 cmic) diff --git a/nvme-print.h b/nvme-print.h index 50ef5b63..f30f63eb 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -16,7 +16,7 @@ typedef struct nvme_effects_log_node { void d(unsigned char *buf, int len, int width, int group); void d_raw(unsigned char *buf, unsigned len); -void nvme_show_status(__u16 status); +void nvme_show_status(int status); void nvme_show_lba_status_info(__u32 result); void nvme_show_relatives(const char *name); -- 2.50.1