]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: decode status types
authorJeremy Kerr <jk@codeconstruct.com.au>
Sun, 23 Oct 2022 03:13:00 +0000 (11:13 +0800)
committerJeremy Kerr <jk@codeconstruct.com.au>
Fri, 28 Oct 2022 05:20:05 +0000 (13:20 +0800)
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 <jk@codeconstruct.com.au>
nvme-print.c
nvme-print.h

index b16bccf7df7888ce355415fa4a993d6f0002b569..898d43f30f8608daac0faafc5de806662f1586a7 100644 (file)
@@ -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)
index 50ef5b6310d253ff72324c83afbc2b7c3b3e1e5c..f30f63eb1c86c87f95c1d203f3548430b9765fa3 100644 (file)
@@ -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);