Skip to content

Commit 4d17bf7

Browse files
ikegami-tigaw
authored andcommitted
zns: replace zns list with generic table
Use the generic table code added instead of hard coded table. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 26302ea commit 4d17bf7

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

nvme-print-json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4719,7 +4719,7 @@ static void json_simple_list(nvme_root_t t)
47194719
json_print(r);
47204720
}
47214721

4722-
static void json_list_item(nvme_ns_t n)
4722+
static void json_list_item(nvme_ns_t n, struct table *t)
47234723
{
47244724
struct json_object *r = json_list_item_obj(n);
47254725

nvme-print-stdout.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ enum simple_list_col {
3333
SIMPLE_LIST_COL_USAGE,
3434
SIMPLE_LIST_COL_FORMAT,
3535
SIMPLE_LIST_COL_FW_REV,
36-
SIMPLE_LIST_COL_NUM,
3736
};
3837

3938
static const uint8_t zero_uuid[16] = { 0 };
@@ -5395,14 +5394,6 @@ static void list_item(nvme_ns_t n, struct table *t)
53955394
stdout_dev_full_path(n, devname, sizeof(devname));
53965395
stdout_generic_full_path(n, genname, sizeof(genname));
53975396

5398-
if (!t) {
5399-
printf("%-21s %-21s %-20s %-40s %#-10x %-26s %-16s %-8s\n",
5400-
devname, genname, nvme_ns_get_serial(n),
5401-
nvme_ns_get_model(n), nvme_ns_get_nsid(n), usage, format,
5402-
nvme_ns_get_firmware(n));
5403-
return;
5404-
}
5405-
54065397
row = table_get_row_id(t);
54075398
if (row < 0) {
54085399
printf("Failed to add row\n");
@@ -5447,9 +5438,9 @@ static void list_item(nvme_ns_t n, struct table *t)
54475438
table_add_row(t, row);
54485439
}
54495440

5450-
static void stdout_list_item(nvme_ns_t n)
5441+
static void stdout_list_item(nvme_ns_t n, struct table *t)
54515442
{
5452-
list_item(n, NULL);
5443+
list_item(n, t);
54535444
}
54545445

54555446
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)
54725463
static void stdout_simple_list(nvme_root_t r)
54735464
{
54745465
struct nvme_resources res;
5475-
struct table_column columns[SIMPLE_LIST_COL_NUM] = {
5466+
struct table_column columns[] = {
54765467
{ "Node", LEFT, 21 },
54775468
{ "Generic", LEFT, 21 },
54785469
{ "SN", LEFT, 20 },

nvme-print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,9 +1504,9 @@ void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len)
15041504
snprintf(path, len, "ng%dn%d", instance, head_instance);
15051505
}
15061506

1507-
void nvme_show_list_item(nvme_ns_t n)
1507+
void nvme_show_list_item(nvme_ns_t n, struct table *t)
15081508
{
1509-
nvme_print(list_item, NORMAL, n);
1509+
nvme_print(list_item, NORMAL, n, t);
15101510
}
15111511

15121512
void nvme_show_list_items(nvme_root_t r, nvme_print_flags_t flags)

nvme-print.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define NVME_PRINT_H
44

55
#include "nvme.h"
6+
#include "util/table.h"
67
#include <inttypes.h>
78

89
#include <ccan/list/list.h>
@@ -101,7 +102,7 @@ struct print_ops {
101102
void (*log)(const char *devname, struct nvme_get_log_args *args);
102103

103104
/* libnvme tree print functions */
104-
void (*list_item)(nvme_ns_t n);
105+
void (*list_item)(nvme_ns_t n, struct table *t);
105106
void (*list_items)(nvme_root_t t);
106107
void (*print_nvme_subsystem_list)(nvme_root_t r, bool show_ana);
107108
void (*topology_ctrl)(nvme_root_t r);
@@ -281,7 +282,7 @@ void nvme_show_zns_report_zones(void *report, __u32 descs,
281282
nvme_print_flags_t flags);
282283
void json_nvme_finish_zone_list(__u64 nr_zones,
283284
struct json_object *zone_list);
284-
void nvme_show_list_item(nvme_ns_t n);
285+
void nvme_show_list_item(nvme_ns_t n, struct table *t);
285286

286287
void nvme_show_fdp_configs(struct nvme_fdp_config_log *configs, size_t len,
287288
nvme_print_flags_t flags);

plugins/zns/zns.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "zns.h"
1919

2020
static const char *namespace_id = "Namespace identifier to use";
21-
static const char dash[100] = { [0 ... 99] = '-' };
2221

2322
static int detect_zns(nvme_ns_t ns, int *out_supported)
2423
{
@@ -39,7 +38,7 @@ static int detect_zns(nvme_ns_t ns, int *out_supported)
3938
return err;
4039
}
4140

42-
static int print_zns_list_ns(nvme_ns_t ns)
41+
static int print_zns_list_ns(nvme_ns_t ns, struct table *t)
4342
{
4443
int supported;
4544
int err = 0;
@@ -51,12 +50,12 @@ static int print_zns_list_ns(nvme_ns_t ns)
5150
}
5251

5352
if (supported)
54-
nvme_show_list_item(ns);
53+
nvme_show_list_item(ns, t);
5554

5655
return err;
5756
}
5857

59-
static int print_zns_list(nvme_root_t nvme_root)
58+
static int print_zns_list(nvme_root_t nvme_root, struct table *t)
6059
{
6160
int err = 0;
6261
nvme_host_t h;
@@ -67,14 +66,14 @@ static int print_zns_list(nvme_root_t nvme_root)
6766
nvme_for_each_host(nvme_root, h) {
6867
nvme_for_each_subsystem(h, s) {
6968
nvme_subsystem_for_each_ns(s, n) {
70-
err = print_zns_list_ns(n);
69+
err = print_zns_list_ns(n, t);
7170
if (err)
7271
return err;
7372
}
7473

7574
nvme_subsystem_for_each_ctrl(s, c) {
7675
nvme_ctrl_for_each_ns(c, n) {
77-
err = print_zns_list_ns(n);
76+
err = print_zns_list_ns(n, t);
7877
if (err)
7978
return err;
8079
}
@@ -90,21 +89,31 @@ static int list(int argc, char **argv, struct command *cmd,
9089
{
9190
int err = 0;
9291
nvme_root_t nvme_root;
93-
94-
printf("%-21s %-20s %-40s %-9s %-26s %-16s %-8s\n", "Node", "SN",
95-
"Model", "Namespace", "Usage", "Format", "FW Rev");
96-
printf("%-.21s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s\n", dash, dash,
97-
dash, dash, dash, dash, dash);
92+
struct table_column columns[] = {
93+
{ "Node", LEFT, 21 },
94+
{ "Generic", LEFT, 21 },
95+
{ "SN", LEFT, 20 },
96+
{ "Model", LEFT, 40 },
97+
{ "Namespace", LEFT, 10 },
98+
{ "Usage", LEFT, 26 },
99+
{ "Format", LEFT, 16 },
100+
{ "FW Rev", LEFT, 8 },
101+
};
102+
struct table *t = table_init_with_columns(columns, ARRAY_SIZE(columns));
98103

99104
nvme_root = nvme_scan(NULL);
100-
if (nvme_root) {
101-
err = print_zns_list(nvme_root);
102-
nvme_free_tree(nvme_root);
103-
} else {
105+
if (!nvme_root) {
104106
fprintf(stderr, "Failed to scan nvme subsystems\n");
105-
err = -errno;
107+
return -errno;
106108
}
107109

110+
err = print_zns_list(nvme_root, t);
111+
nvme_free_tree(nvme_root);
112+
113+
table_print(t);
114+
115+
table_free(t);
116+
108117
return err;
109118
}
110119

0 commit comments

Comments
 (0)