examples/nvme/identify: add a limit to the zns zone report dump option

Add an optional limit, -z N, to the zone report dump option -z.

The variable g_zone_report_limit replaces the MAX_ZONE_DESC_ENTRIES such
that the maximum-number of zone-descriptors is overwritable. It also
replaces g_zone_report_full as it is represented by the limit-value 0,
e.g. "no limit" dump the full report.

The print of the section-header now includes the total amount of zones
and the limit. With this information, the header's width varies. A
helper-function, print_uline(), for printing an "underline" using a
given marker, is also added.

Signed-off-by: Simon A. F. Lund <simon.lund@samsung.com>
Change-Id: Ic8abead693ed83bb8612eef1f35605098ccade84
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6036
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
Simon A. F. Lund 2021-01-21 21:51:50 +01:00 committed by Tomasz Zawadzki
parent 1b0134e0a9
commit a587d90dcb

View File

@ -50,7 +50,6 @@
#define MAX_DISCOVERY_LOG_ENTRIES ((uint64_t)1000)
#define NUM_CHUNK_INFO_ENTRIES 8
#define MAX_ZONE_DESC_ENTRIES 8
static int outstanding_commands;
@ -87,7 +86,7 @@ static struct spdk_ocssd_geometry_data geometry_data;
static struct spdk_ocssd_chunk_information_entry g_ocssd_chunk_info_page[NUM_CHUNK_INFO_ENTRIES ];
static bool g_zone_report_full = false;
static int64_t g_zone_report_limit = 8;
static bool g_hex_dump = false;
@ -648,6 +647,16 @@ print_ascii_string(const void *buf, size_t size)
}
}
/* Underline a "line" with the given marker, e.g. print_uline("=", printf(...)); */
static void
print_uline(char marker, int line_len)
{
for (int i = 1; i < line_len; ++i) {
putchar(marker);
}
putchar('\n');
}
static void
print_ocssd_chunk_info(struct spdk_ocssd_chunk_information_entry *chk_info, int chk_num)
{
@ -742,15 +751,10 @@ get_and_print_zns_zone_report(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *q
exit(1);
}
if (g_zone_report_full) {
zones_to_print = total_zones;
printf("NVMe ZNS Zone Report\n");
printf("====================\n");
} else {
zones_to_print = spdk_min(total_zones, MAX_ZONE_DESC_ENTRIES);
printf("NVMe ZNS Zone Report Glance\n");
printf("===========================\n");
}
zones_to_print = g_zone_report_limit ? spdk_min(total_zones, (uint64_t)g_zone_report_limit) : \
total_zones;
print_uline('=', printf("NVMe ZNS Zone Report (first %zu of %zu)\n", zones_to_print, total_zones));
while (handled_zones < zones_to_print) {
memset(report_buf, 0, report_bufsize);
@ -1951,7 +1955,7 @@ usage(const char *program_name)
printf(" -d DPDK huge memory size in MB\n");
printf(" -g use single file descriptor for DPDK memory segments\n");
printf(" -x print hex dump of raw data\n");
printf(" -z For NVMe Zoned Namespaces, dump the full zone report\n");
printf(" -z For NVMe Zoned Namespaces, dump the full zone report (-z) or the first N entries (-z N)\n");
printf(" -v verbose (enable warnings)\n");
printf(" -V enumerate VMD\n");
printf(" -H show this usage\n");
@ -1966,7 +1970,7 @@ parse_args(int argc, char **argv)
spdk_nvme_trid_populate_transport(&g_trid, SPDK_NVME_TRANSPORT_PCIE);
snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
while ((op = getopt(argc, argv, "d:gi:p:r:xzHL:V")) != -1) {
while ((op = getopt(argc, argv, "d:gi:p:r:xz::HL:V")) != -1) {
switch (op) {
case 'd':
g_dpdk_mem = spdk_strtol(optarg, 10);
@ -2020,7 +2024,18 @@ parse_args(int argc, char **argv)
g_hex_dump = true;
break;
case 'z':
g_zone_report_full = true;
if (optarg == NULL && argv[optind] != NULL && argv[optind][0] != '-') {
g_zone_report_limit = spdk_strtol(argv[optind], 10);
++optind;
} else if (optarg) {
g_zone_report_limit = spdk_strtol(optarg, 10);
} else {
g_zone_report_limit = 0;
}
if (g_zone_report_limit < 0) {
fprintf(stderr, "Invalid Zone Report limit\n");
return g_zone_report_limit;
}
break;
case 'L':
rc = spdk_log_set_flag(optarg);