From: Matias Bjørling Date: Fri, 19 Jun 2020 15:24:59 +0000 (+0000) Subject: Add really pretty print for ZNS Command Set specific Identify Namespace data structure X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=68bb51ae69e5b375545e9003a07b9159a878e793;p=users%2Fhch%2Fnvme-cli.git Add really pretty print for ZNS Command Set specific Identify Namespace data structure Updated the printing of the zone list to be a lot prettier. Also added extension support. Signed-off-by: Matias Bjørling Signed-off-by: Aravind Ramesh --- diff --git a/nvme-print.c b/nvme-print.c index f58e4c3..7e9782e 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -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"); + } + } } } diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 2a9fc9f..23244a6 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -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: