]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Add really pretty print for ZNS Command Set specific Identify Namespace data structure
authorMatias Bjørling <matias.bjorling@wdc.com>
Fri, 19 Jun 2020 15:24:59 +0000 (15:24 +0000)
committerKeith Busch <kbusch@kernel.org>
Fri, 19 Jun 2020 15:39:05 +0000 (08:39 -0700)
Updated the printing of the zone list to be a lot prettier.

Also added extension support.

Signed-off-by: Matias Bjørling <matias.bjorling@wdc.com>
Signed-off-by: Aravind Ramesh <aravind.ramesh@wdc.com>
nvme-print.c
plugins/zns/zns.c

index f58e4c3f9f66d0f546f89d236406a5ea47ba6e8d..7e9782e79f71b158e9f51812e7ed5ec96ae6755f 100644 (file)
@@ -2981,6 +2981,38 @@ void nvme_show_zns_changed(struct nvme_zns_changed_zone_log *log,
                printf("zid %03d: %"PRIu64"\n", i, (uint64_t)le64_to_cpu(log->zid[i]));
 }
 
+char *zone_type_to_string(__u8 cond)
+{
+       switch (cond) {
+       case NVME_ZONE_TYPE_SEQWRITE_REQ:
+               return "SEQWRITE_REQ";
+       default:
+               return "Unknown";
+       }
+}
+
+char *zone_state_to_string(__u8 state)
+{
+       switch (state) {
+       case NVME_ZNS_ZS_EMPTY:
+               return "EMPTY";
+       case NVME_ZNS_ZS_IMPL_OPEN:
+               return "IMP_OPENED";
+       case NVME_ZNS_ZS_EXPL_OPEN:
+               return "EXP_OPENED";
+       case NVME_ZNS_ZS_CLOSED:
+               return "CLOSED";
+       case NVME_ZNS_ZS_READ_ONLY:
+               return "READONLY";
+       case NVME_ZNS_ZS_FULL:
+               return "FULL";
+       case NVME_ZNS_ZS_OFFLINE:
+               return "OFFLINE";
+       default:
+               return "Unknown State";
+       }
+}
+
 void nvme_show_zns_report_zones(void *report, __u32 descs,
        __u8 ext_size, __u32 report_size, unsigned long flags)
 {
@@ -2996,19 +3028,24 @@ void nvme_show_zns_report_zones(void *report, __u32 descs,
        if (flags & BINARY)
                return d_raw((unsigned char *)report, report_size);
 
-       printf("nr_zones : %"PRIu64"\n", (uint64_t)le64_to_cpu(r->nr_zones));
+       printf("nr_zones: %"PRIu64"\n", (uint64_t)le64_to_cpu(r->nr_zones));
        for (i = 0; i < descs; i++) {
                desc = (struct nvme_zns_desc *)
                        (report + sizeof(*r) + i * (sizeof(*desc) + ext_size));
-               printf(" desc %02d:\n", i);
-               printf(".................\n");
-               printf("zt      : %x\n", desc->zt);
-               printf("zs      : %x\n", desc->zs);
-               printf("za      : %x\n", desc->za);
-               printf("zcap    : %"PRIx64"\n", le64_to_cpu(desc->zcap));
-               printf("zslba   : %"PRIx64"\n", le64_to_cpu(desc->zslba));
-               printf("wp      : %"PRIx64"\n", le64_to_cpu(desc->wp));
-               printf(".................\n");
+               printf("SLBA: 0x%-8"PRIx64" WP: 0x%-8"PRIx64"lx Cap: 0x%-8"PRIx64"lx State: %-12s Type: %-14s Attrs: 0x%-x\n",
+               (uint64_t)le64_to_cpu(desc->zslba), (uint64_t)le64_to_cpu(desc->wp),
+               (uint64_t)le64_to_cpu(desc->zcap), zone_state_to_string(desc->zs >> 4),
+               zone_type_to_string(desc->zt), desc->za);
+
+               if (ext_size) {
+                       printf("Extension Data: ");
+                       if (desc->za & NVME_ZNS_ZA_ZDEV) {
+                               d((unsigned char *)desc + sizeof(*desc), ext_size, 16, 1);
+                               printf("..\n");
+                       } else {
+                               printf(" Not valid\n");
+                       }
+               }
        }
 }
 
index 2a9fc9fe558c0103e19c32c61a61b62a9dc10d52..23244a64d48ec582c8733dd8d422b416800983a4 100644 (file)
@@ -177,7 +177,7 @@ static int zns_mgmt_send(int argc, char **argv, struct command *cmd, struct plug
                cfg.select_all, zsa, 0, NULL);
        if (!err)
                printf("%s: Success, action:%d zone:%"PRIx64" nsid:%d\n", command,
-                       zsa, (uint64_t)zslba, cfg.namespace_id);
+                       zsa, (uint64_t)cfg.zslba, cfg.namespace_id);
        else
                nvme_show_status(err);
 free: