diff --git a/nvme-print-json.c b/nvme-print-json.c index cac9e25aad..bb94dad670 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -4719,7 +4719,7 @@ static void json_simple_list(nvme_root_t t) json_print(r); } -static void json_list_item(nvme_ns_t n) +static void json_list_item(nvme_ns_t n, struct table *t) { struct json_object *r = json_list_item_obj(n); diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 1c28e166ea..6a3572e62c 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -33,7 +33,6 @@ enum simple_list_col { SIMPLE_LIST_COL_USAGE, SIMPLE_LIST_COL_FORMAT, SIMPLE_LIST_COL_FW_REV, - SIMPLE_LIST_COL_NUM, }; static const uint8_t zero_uuid[16] = { 0 }; @@ -5395,14 +5394,6 @@ static void list_item(nvme_ns_t n, struct table *t) stdout_dev_full_path(n, devname, sizeof(devname)); stdout_generic_full_path(n, genname, sizeof(genname)); - if (!t) { - printf("%-21s %-21s %-20s %-40s %#-10x %-26s %-16s %-8s\n", - devname, genname, nvme_ns_get_serial(n), - nvme_ns_get_model(n), nvme_ns_get_nsid(n), usage, format, - nvme_ns_get_firmware(n)); - return; - } - row = table_get_row_id(t); if (row < 0) { printf("Failed to add row\n"); @@ -5447,9 +5438,9 @@ static void list_item(nvme_ns_t n, struct table *t) table_add_row(t, row); } -static void stdout_list_item(nvme_ns_t n) +static void stdout_list_item(nvme_ns_t n, struct table *t) { - list_item(n, NULL); + list_item(n, t); } static void stdout_list_item_table(nvme_ns_t n, struct table *t) @@ -5472,7 +5463,7 @@ static bool stdout_simple_ns(const char *name, void *arg) static void stdout_simple_list(nvme_root_t r) { struct nvme_resources res; - struct table_column columns[SIMPLE_LIST_COL_NUM] = { + struct table_column columns[] = { { "Node", LEFT, 21 }, { "Generic", LEFT, 21 }, { "SN", LEFT, 20 }, diff --git a/nvme-print.c b/nvme-print.c index f0dddf513d..d1448348e7 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1504,9 +1504,9 @@ void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len) snprintf(path, len, "ng%dn%d", instance, head_instance); } -void nvme_show_list_item(nvme_ns_t n) +void nvme_show_list_item(nvme_ns_t n, struct table *t) { - nvme_print(list_item, NORMAL, n); + nvme_print(list_item, NORMAL, n, t); } void nvme_show_list_items(nvme_root_t r, nvme_print_flags_t flags) diff --git a/nvme-print.h b/nvme-print.h index a598dc8f92..6c09bfbdb3 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -3,6 +3,7 @@ #define NVME_PRINT_H #include "nvme.h" +#include "util/table.h" #include #include @@ -101,7 +102,7 @@ struct print_ops { void (*log)(const char *devname, struct nvme_get_log_args *args); /* libnvme tree print functions */ - void (*list_item)(nvme_ns_t n); + void (*list_item)(nvme_ns_t n, struct table *t); void (*list_items)(nvme_root_t t); void (*print_nvme_subsystem_list)(nvme_root_t r, bool show_ana); void (*topology_ctrl)(nvme_root_t r); @@ -281,7 +282,7 @@ void nvme_show_zns_report_zones(void *report, __u32 descs, nvme_print_flags_t flags); void json_nvme_finish_zone_list(__u64 nr_zones, struct json_object *zone_list); -void nvme_show_list_item(nvme_ns_t n); +void nvme_show_list_item(nvme_ns_t n, struct table *t); void nvme_show_fdp_configs(struct nvme_fdp_config_log *configs, size_t len, nvme_print_flags_t flags); diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 94336d781b..6cf54bba4d 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -18,7 +18,6 @@ #include "zns.h" static const char *namespace_id = "Namespace identifier to use"; -static const char dash[100] = { [0 ... 99] = '-' }; static int detect_zns(nvme_ns_t ns, int *out_supported) { @@ -39,7 +38,7 @@ static int detect_zns(nvme_ns_t ns, int *out_supported) return err; } -static int print_zns_list_ns(nvme_ns_t ns) +static int print_zns_list_ns(nvme_ns_t ns, struct table *t) { int supported; int err = 0; @@ -51,12 +50,12 @@ static int print_zns_list_ns(nvme_ns_t ns) } if (supported) - nvme_show_list_item(ns); + nvme_show_list_item(ns, t); return err; } -static int print_zns_list(nvme_root_t nvme_root) +static int print_zns_list(nvme_root_t nvme_root, struct table *t) { int err = 0; nvme_host_t h; @@ -67,14 +66,14 @@ static int print_zns_list(nvme_root_t nvme_root) nvme_for_each_host(nvme_root, h) { nvme_for_each_subsystem(h, s) { nvme_subsystem_for_each_ns(s, n) { - err = print_zns_list_ns(n); + err = print_zns_list_ns(n, t); if (err) return err; } nvme_subsystem_for_each_ctrl(s, c) { nvme_ctrl_for_each_ns(c, n) { - err = print_zns_list_ns(n); + err = print_zns_list_ns(n, t); if (err) return err; } @@ -90,21 +89,31 @@ static int list(int argc, char **argv, struct command *cmd, { int err = 0; nvme_root_t nvme_root; - - printf("%-21s %-20s %-40s %-9s %-26s %-16s %-8s\n", "Node", "SN", - "Model", "Namespace", "Usage", "Format", "FW Rev"); - printf("%-.21s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s\n", dash, dash, - dash, dash, dash, dash, dash); + struct table_column columns[] = { + { "Node", LEFT, 21 }, + { "Generic", LEFT, 21 }, + { "SN", LEFT, 20 }, + { "Model", LEFT, 40 }, + { "Namespace", LEFT, 10 }, + { "Usage", LEFT, 26 }, + { "Format", LEFT, 16 }, + { "FW Rev", LEFT, 8 }, + }; + struct table *t = table_init_with_columns(columns, ARRAY_SIZE(columns)); nvme_root = nvme_scan(NULL); - if (nvme_root) { - err = print_zns_list(nvme_root); - nvme_free_tree(nvme_root); - } else { + if (!nvme_root) { fprintf(stderr, "Failed to scan nvme subsystems\n"); - err = -errno; + return -errno; } + err = print_zns_list(nvme_root, t); + nvme_free_tree(nvme_root); + + table_print(t); + + table_free(t); + return err; }