Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 3 additions & 12 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -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 },
Expand Down
4 changes: 2 additions & 2 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define NVME_PRINT_H

#include "nvme.h"
#include "util/table.h"
#include <inttypes.h>

#include <ccan/list/list.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 25 additions & 16 deletions plugins/zns/zns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down