]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add mgmt-addr-list-log command
authorTokunori Ikegami <ikegami.t@gmail.com>
Mon, 13 Jan 2025 05:28:06 +0000 (14:28 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 13 Jan 2025 16:43:29 +0000 (17:43 +0100)
Since added the NVMe 2.1 log page.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme-builtin.h
nvme-print-stdout.c
nvme-print.c
nvme-print.h
nvme-wrap.c
nvme-wrap.h
nvme.c

index 00e361cea7d53c3d70697da506031959443f6c7d..5b1af6939d8e8c498c5bb8f8da2d5ef8728bf703 100644 (file)
@@ -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)
index 63117864098d33b57507cf7937035e117ac02f36..fe3c971e319ed2f3b6091e0de6418ad48766f5d3 100644 (file)
@@ -5535,6 +5535,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,
@@ -5602,6 +5629,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,
index 77311e6cf5563db97e795ec7a812631dcc7d52e8..b94d2356ff7a0eaad4ddc4f7b3fef873b58ed765 100644 (file)
@@ -1476,3 +1476,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);
+}
index b88149a94c3cb8581612ae248b00e13bc685d109..f6096a87737c5cd4659d66ec006d24ad7bd5cc75 100644 (file)
@@ -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);
@@ -328,4 +329,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 */
index 4fcbee725034de2200a8da8916981d5d4e926a98..9b4aecd43339cdd0321713d8c4527ac53e65fefa 100644 (file)
@@ -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);
+}
index 5328acb9b7ceaf623c102f22d1cde614e11f9b00..c9d861b6aee4803209ae6b309ac15c4befae5820 100644 (file)
@@ -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 36a9b7a98c851bb6ede476ec43a8850fa51589cd..8a5756777f7bd9bee6087c79f82ddc99e5f06e9c 100644 (file)
--- 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(*ma_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;