From efdb01cc9b5998e51007060a100bae3e53715ed0 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 13 Jan 2025 14:28:06 +0900 Subject: [PATCH] nvme: add mgmt-addr-list-log command Since added the NVMe 2.1 log page. Signed-off-by: Tokunori Ikegami --- nvme-builtin.h | 1 + nvme-print-stdout.c | 28 ++++++++++++++++++++++++++++ nvme-print.c | 5 +++++ nvme-print.h | 3 +++ nvme-wrap.c | 6 ++++++ nvme-wrap.h | 3 +++ nvme.c | 37 +++++++++++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+) diff --git a/nvme-builtin.h b/nvme-builtin.h index 00e361cea7..5b1af6939d 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -58,6 +58,7 @@ COMMAND_LIST( ENTRY("mi-cmd-support-effects-log", "Retrieve MI Command Support and Effects log and show it", get_mi_cmd_support_effects_log) ENTRY("media-unit-stat-log", "Retrieve the configuration and wear of media units, show it", get_media_unit_stat_log) ENTRY("supported-cap-config-log", "Retrieve the list of Supported Capacity Configuration Descriptors", get_supp_cap_config_log) + ENTRY("mgmt-addr-list-log", "Retrieve Management Address List Log, show it", get_mgmt_addr_list_log) ENTRY("set-feature", "Set a feature and show the resulting value", set_feature) ENTRY("set-property", "Set a property and show the resulting value", set_property) ENTRY("get-property", "Get a property and show the resulting value", get_property) diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 484696a23e..2336c7e4af 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -5509,6 +5509,33 @@ static void stdout_connect_msg(nvme_ctrl_t c) printf("connecting to device: %s\n", nvme_ctrl_get_name(c)); } +static void stdout_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list) +{ + int i; + bool reserved = true; + + printf("Management Address List:\n"); + for (i = 0; i < ARRAY_SIZE(ma_list->mad); i++) { + switch (ma_list->mad[i].mat) { + case 1: + case 2: + printf("Descriptor: %d, Type: %d (%s), Address: %s\n", i, + ma_list->mad[i].mat, + ma_list->mad[i].mat == 1 ? "NVM subsystem management agent" : + "fabric interface manager", ma_list->mad[i].madrs); + reserved = false; + break; + case 0xff: + goto out; + default: + break; + } + } +out: + if (reserved) + printf("All management address descriptors reserved\n"); +} + static struct print_ops stdout_print_ops = { /* libnvme types.h print functions */ .ana_log = stdout_ana_log, @@ -5576,6 +5603,7 @@ static struct print_ops stdout_print_ops = { .d = stdout_d, .show_init = NULL, .show_finish = NULL, + .mgmt_addr_list_log = stdout_mgmt_addr_list_log, /* libnvme tree print functions */ .list_item = stdout_list_item, diff --git a/nvme-print.c b/nvme-print.c index 303ffd8545..0c8f423afa 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1440,3 +1440,8 @@ void nvme_show_finish(void) { nvme_print_output_format(show_finish); } + +void nvme_show_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list, nvme_print_flags_t flags) +{ + nvme_print(mgmt_addr_list_log, flags, ma_list); +} diff --git a/nvme-print.h b/nvme-print.h index 00f19947c8..5508ea8737 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -88,6 +88,7 @@ struct print_ops { void (*d)(unsigned char *buf, int len, int width, int group); void (*show_init)(void); void (*show_finish)(void); + void (*mgmt_addr_list_log)(struct nvme_mgmt_addr_list_log *ma_log); /* libnvme tree print functions */ void (*list_item)(nvme_ns_t n); @@ -327,4 +328,6 @@ const char *nvme_degrees_string(long t); void print_array(char *name, __u8 *data, int size); void json_print(struct json_object *r); struct json_object *obj_create_array_obj(struct json_object *o, const char *k); +void nvme_show_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list, + nvme_print_flags_t flags); #endif /* NVME_PRINT_H */ diff --git a/nvme-wrap.c b/nvme-wrap.c index 4fcbee7250..9b4aecd433 100644 --- a/nvme-wrap.c +++ b/nvme-wrap.c @@ -430,3 +430,9 @@ int nvme_cli_security_receive(struct nvme_dev *dev, return -ENODEV; } + +int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len, + struct nvme_mgmt_addr_list_log *ma_list) +{ + return do_admin_op(get_log_mgmt_addr_list, dev, len, ma_list); +} diff --git a/nvme-wrap.h b/nvme-wrap.h index 5328acb9b7..c9d861b6ae 100644 --- a/nvme-wrap.h +++ b/nvme-wrap.h @@ -146,4 +146,7 @@ int nvme_cli_security_send(struct nvme_dev *dev, int nvme_cli_security_receive(struct nvme_dev *dev, struct nvme_security_receive_args* args); +int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len, + struct nvme_mgmt_addr_list_log *ma_list); + #endif /* _NVME_WRAP_H */ diff --git a/nvme.c b/nvme.c index 36a9b7a98c..065550ae28 100644 --- a/nvme.c +++ b/nvme.c @@ -9962,6 +9962,43 @@ static int nmi_send(int argc, char **argv, struct command *cmd, struct plugin *p return nvme_mi(argc, argv, nvme_admin_nvme_mi_send, desc); } +static int get_mgmt_addr_list_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) +{ + const char *desc = "Retrieve Management Address List Log, show it"; + nvme_print_flags_t flags; + int err = -1; + + _cleanup_free_ struct nvme_mgmt_addr_list_log *ma_log = NULL; + + _cleanup_nvme_dev_ struct nvme_dev *dev = NULL; + + NVME_ARGS(opts); + + err = parse_and_open(&dev, argc, argv, desc, opts); + if (err) + return err; + + err = validate_output_format(nvme_cfg.output_format, &flags); + if (err < 0) { + nvme_show_error("Invalid output format"); + return err; + } + + ma_log = nvme_alloc(sizeof(*ma_log)); + if (!ma_log) + return -ENOMEM; + + err = nvme_cli_get_log_mgmt_addr_list(dev, sizeof(struct nvme_mgmt_addr_list_log), ma_log); + if (!err) + nvme_show_mgmt_addr_list_log(ma_log, flags); + else if (err > 0) + nvme_show_status(err); + else + nvme_show_perror("management address list log"); + + return err; +} + void register_extension(struct plugin *plugin) { plugin->parent = &nvme;