From e045379d4db96d45ace98c59fb66492e49db8994 Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Thu, 16 Sep 2021 16:51:22 +0900 Subject: [PATCH] zns: report zones add verbose option functionality Addtional data will be printed for ZA, ZAI on report-zones Zone Attributes (ZA), Zone Attributes Information (ZAI) Signed-off-by: Steven Seungcheol Lee [dwagner: updated context] Signed-off-by: Daniel Wagner --- nvme-print.c | 53 +++++++++++++++++++++++++++++++++-------------- plugins/zns/zns.c | 8 +++---- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index e9fb0af3..5e867257 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -4427,7 +4427,7 @@ 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) +static char *zone_type_to_string(__u8 cond) { switch (cond) { case NVME_ZONE_TYPE_SEQWRITE_REQ: @@ -4437,7 +4437,7 @@ char *zone_type_to_string(__u8 cond) } } -char *zone_state_to_string(__u8 state) +static char *zone_state_to_string(__u8 state) { switch (state) { case NVME_ZNS_ZS_EMPTY: @@ -4488,6 +4488,7 @@ static void json_nvme_zns_report_zones(void *report, __u32 descs, json_object_add_value_string(zone, "type", zone_type_to_string(desc->zt)); json_object_add_value_uint(zone, "attrs", desc->za); + json_object_add_value_uint(zone, "attrs", desc->zai); if (ext_size) { if (desc->za & NVME_ZNS_ZA_ZDEV) { @@ -4510,13 +4511,30 @@ static void json_nvme_zns_report_zones(void *report, __u32 descs, json_free_object(root); } +static void nvme_show_zns_report_zone_attributes(__u8 za, __u8 zai) +{ + const char *const recommanded_limit[4] = {"","1","2","3"}; + printf("Attrs: Zone Descriptor Extension is %sVaild\n", + (za & NVME_ZNS_ZA_ZDEV)? "" : "Not "); + if(za & NVME_ZNS_ZA_RZR) { + printf(" Reset Zone Recommended with Reset Recommended Limit%s\n", + recommanded_limit[(zai&0xd)>>2]); + } + if (za & NVME_ZNS_ZA_FZR) { + printf(" Finish Zone Recommended with Finish Recommended Limit%s\n", + recommanded_limit[zai&0x3]); + } + if (za & NVME_ZNS_ZA_ZFC) { + printf(" Zone Finished by Controller\n"); + } +} + void nvme_show_zns_report_zones(void *report, __u32 descs, __u8 ext_size, __u32 report_size, unsigned long flags) { struct nvme_zone_report *r = report; struct nvme_zns_desc *desc; - int i; - + int i, verbose = flags & VERBOSE; __u64 nr_zones = le64_to_cpu(r->nr_zones); if (nr_zones < descs) @@ -4532,19 +4550,24 @@ void nvme_show_zns_report_zones(void *report, __u32 descs, for (i = 0; i < descs; i++) { desc = (struct nvme_zns_desc *) (report + sizeof(*r) + i * (sizeof(*desc) + ext_size)); - printf("SLBA: 0x%-8"PRIx64" WP: 0x%-8"PRIx64" Cap: 0x%-8"PRIx64" 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(verbose) { + printf("SLBA: %#-10"PRIx64" WP: %#-10"PRIx64" Cap: %#-10"PRIx64" State: %-12s Type: %-14s\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)); + nvme_show_zns_report_zone_attributes(desc->za, desc->zai); + } + else { + printf("SLBA: %#-10"PRIx64" WP: %#-10"PRIx64" Cap: %#-10"PRIx64" State: %#-4x Type: %#-4x Attrs: %#-4x AttrsInfo: %#-4x\n", + (uint64_t)le64_to_cpu(desc->zslba), (uint64_t)le64_to_cpu(desc->wp), + (uint64_t)le64_to_cpu(desc->zcap), desc->zs, desc->zt, + desc->za, desc->zai); + } - if (ext_size) { + if (ext_size && (desc->za & NVME_ZNS_ZA_ZDEV)) { 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"); - } + d((unsigned char *)desc + sizeof(*desc), ext_size, 16, 1); + printf("..\n"); } } } diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index a8ec6767..de576099 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -663,7 +663,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi const char *state = "state of zones to list"; const char *ext = "set to use the extended report zones"; const char *part = "set to use the partial report"; - const char *human_readable = "show report zones in readable format"; + const char *verbose = "show report zones verbosity"; enum nvme_print_flags flags; int fd, zdes = 0, err = -1; @@ -677,7 +677,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi __u32 namespace_id; int num_descs; int state; - int human_readable; + int verbose; bool extended; bool partial; }; @@ -693,7 +693,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi OPT_UINT("descs", 'd', &cfg.num_descs, num_descs), OPT_UINT("state", 'S', &cfg.state, state), OPT_FMT("output-format", 'o', &cfg.output_format, output_format), - OPT_FLAG("human-readable",'H', &cfg.human_readable, human_readable), + OPT_FLAG("verbose", 'v', &cfg.verbose, verbose), OPT_FLAG("extended", 'e', &cfg.extended, ext), OPT_FLAG("partial", 'p', &cfg.partial, part), OPT_END() @@ -706,7 +706,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi flags = validate_output_format(cfg.output_format); if (flags < 0) goto close_fd; - if (cfg.human_readable) + if (cfg.verbose) flags |= VERBOSE; if (!cfg.namespace_id) { -- 2.50.1