]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add ave-discovery-log command
authorTokunori Ikegami <ikegami.t@gmail.com>
Wed, 26 Feb 2025 16:18:46 +0000 (01:18 +0900)
committerDaniel Wagner <wagi@monom.org>
Wed, 26 Feb 2025 18:49:52 +0000 (19:49 +0100)
Since added the NVMe 2.1 log page.

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

index 0b41c8bf041f0ec95e529da5332032bec5f00352..beec920019baded18ffdb33c8fa03d86262f1e44 100644 (file)
@@ -65,6 +65,7 @@ COMMAND_LIST(
        ENTRY("reachability-groups-log", "Retrieve Reachability Groups Log, show it", get_reachability_groups_log)
        ENTRY("reachability-associations-log", "Retrieve Reachability Associations Log, show it", get_reachability_associations_log)
        ENTRY("host-discovery-log", "Retrieve Host Discovery Log, show it", get_host_discovery_log)
+       ENTRY("ave-discovery-log", "Retrieve AVE Discovery Log, show it", get_ave_discovery_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 0bbf1dc180208dbf1de3f4632c9c3d1cc0e97b22..bd425f31b06c6434ed392ce850c5ad09f06742c0 100644 (file)
@@ -337,6 +337,11 @@ static void binary_host_discovery_log(struct nvme_host_discover_log *log)
        d_raw((unsigned char *)log, le32_to_cpu(log->thdlpl));
 }
 
+static void binary_ave_discovery_log(struct nvme_ave_discover_log *log)
+{
+       d_raw((unsigned char *)log, le32_to_cpu(log->tadlpl));
+}
+
 static struct print_ops binary_print_ops = {
        /* libnvme types.h print functions */
        .ana_log                        = binary_ana_log,
@@ -409,6 +414,7 @@ static struct print_ops binary_print_ops = {
        .reachability_groups_log        = binary_reachability_groups_log,
        .reachability_associations_log  = binary_reachability_associations_log,
        .host_discovery_log             = binary_host_discovery_log,
+       .ave_discovery_log              = binary_ave_discovery_log,
 
        /* libnvme tree print functions */
        .list_item                      = NULL,
index fdb970e13e8c1b3c936a0c77b60328a0bc0cfa17..5b3c36296055a7bdfcc0c01ba0b48fbace65abfd 100644 (file)
@@ -3,7 +3,9 @@
 #include <assert.h>
 #include <errno.h>
 #include <time.h>
-
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
 #include <ccan/ccan/compiler/compiler.h>
 
 #include "nvme-print.h"
@@ -4820,6 +4822,65 @@ static void json_host_discovery_log(struct nvme_host_discover_log *log)
        }
 }
 
+static void obj_add_traddr(struct json_object *o, const char *k, __u8 adrfam, __u8 *traddr)
+{
+       int af = AF_INET;
+       socklen_t size = INET_ADDRSTRLEN;
+       char dst[INET6_ADDRSTRLEN];
+
+       if (adrfam == NVMF_ADDR_FAMILY_IP6) {
+               af = AF_INET6;
+               size = INET6_ADDRSTRLEN;
+       }
+
+       if (inet_ntop(af, nvmf_adrfam_str(adrfam), dst, size))
+               obj_add_str(o, k, dst);
+}
+
+static void json_ave_discovery_log(struct nvme_ave_discover_log *log)
+{
+       struct json_object *r = json_create_object();
+       __u32 i;
+       __u8 j;
+       struct nvme_ave_discover_log_entry *adlpe;
+       struct nvme_ave_tr_record *atr;
+       __u32 tadlpl = le32_to_cpu(log->tadlpl);
+       __u32 tel;
+       __u8 numatr;
+       int n = 0;
+       char json_str[STR_LEN];
+       struct json_object *adlpe_o;
+       struct json_object *atr_o;
+
+       obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr));
+       obj_add_uint64(r, "numrec", le64_to_cpu(log->numrec));
+       obj_add_uint(r, "recfmt", le16_to_cpu(log->recfmt));
+       obj_add_uint(r, "thdlpl", tadlpl);
+
+       for (i = sizeof(*log); i < le32_to_cpu(log->tadlpl); i += tel) {
+               adlpe_o = json_create_object();
+               adlpe = (void *)log + i;
+               tel = le32_to_cpu(adlpe->tel);
+               numatr = adlpe->numatr;
+               obj_add_uint(adlpe_o, "tel", tel);
+               obj_add_str(adlpe_o, "avenqn", adlpe->avenqn);
+               obj_add_uint(adlpe_o, "numatr", numatr);
+
+               atr = adlpe->atr;
+               for (j = 0; j < numatr; j++) {
+                       atr_o = json_create_object();
+                       snprintf(json_str, sizeof(json_str), "atr: %d", j);
+                       obj_add_str(atr_o, "aveadrfam", nvmf_adrfam_str(atr->aveadrfam));
+                       obj_add_uint(atr_o, "avetrsvcid", le16_to_cpu(atr->avetrsvcid));
+                       obj_add_traddr(atr_o, "avetraddr", atr->aveadrfam, atr->avetraddr);
+                       obj_add_obj(adlpe_o, json_str, atr_o);
+                       atr++;
+               }
+               snprintf(json_str, sizeof(json_str), "adlpe: %d", n++);
+               obj_add_obj(r, json_str, adlpe_o);
+       }
+}
+
 static struct print_ops json_print_ops = {
        /* libnvme types.h print functions */
        .ana_log                        = json_ana_log,
@@ -4893,6 +4954,7 @@ static struct print_ops json_print_ops = {
        .reachability_groups_log        = json_reachability_groups_log,
        .reachability_associations_log  = json_reachability_associations_log,
        .host_discovery_log             = json_host_discovery_log,
+       .ave_discovery_log              = json_ave_discovery_log,
 
        /* libnvme tree print functions */
        .list_item                      = json_list_item,
index ed0bcc55b0704a3cd753c970502329513e213d25..2e4acf252da8526fc576300354fda3d665afe936 100644 (file)
@@ -6,7 +6,9 @@
 #include <stdlib.h>
 #include <time.h>
 #include <sys/stat.h>
-
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
 #include <ccan/ccan/strset/strset.h>
 #include <ccan/ccan/htable/htable_type.h>
 #include <ccan/ccan/htable/htable.h>
@@ -5759,6 +5761,57 @@ static void stdout_host_discovery_log(struct nvme_host_discover_log *log)
        }
 }
 
+static void print_traddr(char *field, __u8 adrfam, __u8 *traddr)
+{
+       int af = AF_INET;
+       socklen_t size = INET_ADDRSTRLEN;
+       char dst[INET6_ADDRSTRLEN];
+
+       if (adrfam == NVMF_ADDR_FAMILY_IP6) {
+               af = AF_INET6;
+               size = INET6_ADDRSTRLEN;
+       }
+
+       if (inet_ntop(af, nvmf_adrfam_str(adrfam), dst, size))
+               printf("%s: %s\n", field, dst);
+}
+
+static void stdout_ave_discovery_log(struct nvme_ave_discover_log *log)
+{
+       __u32 i;
+       __u8 j;
+       struct nvme_ave_discover_log_entry *adlpe;
+       struct nvme_ave_tr_record *atr;
+       __u32 tadlpl = le32_to_cpu(log->tadlpl);
+       __u32 tel;
+       __u8 numatr;
+       int n = 0;
+
+       printf("genctr: %"PRIu64"\n", le64_to_cpu(log->genctr));
+       printf("numrec: %"PRIu64"\n", le64_to_cpu(log->numrec));
+       printf("recfmt: %u\n", le16_to_cpu(log->recfmt));
+       printf("tadlpl: %u\n", tadlpl);
+
+       for (i = sizeof(*log); i < le32_to_cpu(log->tadlpl); i += tel) {
+               printf("adlpe: %d\n", n++);
+               adlpe = (void *)log + i;
+               tel = le32_to_cpu(adlpe->tel);
+               numatr = adlpe->numatr;
+               printf("tel: %u\n", tel);
+               printf("avenqn: %s\n", adlpe->avenqn);
+               printf("numatr: %u\n", numatr);
+
+               atr = adlpe->atr;
+               for (j = 0; j < numatr; j++) {
+                       printf("atr: %d\n", j);
+                       printf("aveadrfam: %s\n", nvmf_adrfam_str(atr->aveadrfam));
+                       printf("avetrsvcid: %u\n", le16_to_cpu(atr->avetrsvcid));
+                       print_traddr("avetraddr", atr->aveadrfam, atr->avetraddr);
+                       atr++;
+               }
+       }
+}
+
 static struct print_ops stdout_print_ops = {
        /* libnvme types.h print functions */
        .ana_log                        = stdout_ana_log,
@@ -5832,6 +5885,7 @@ static struct print_ops stdout_print_ops = {
        .reachability_groups_log        = stdout_reachability_groups_log,
        .reachability_associations_log  = stdout_reachability_associations_log,
        .host_discovery_log             = stdout_host_discovery_log,
+       .ave_discovery_log              = stdout_ave_discovery_log,
 
        /* libnvme tree print functions */
        .list_item                      = stdout_list_item,
index 65516e930fd599e943da6d61ad78a0170415d7da..a025fa2216ea3b8bfa964ba41ff7a423b7f57c0a 100644 (file)
@@ -1525,3 +1525,8 @@ void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print
 {
        nvme_print(host_discovery_log, flags, log);
 }
+
+void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_flags_t flags)
+{
+       nvme_print(ave_discovery_log, flags, log);
+}
index 2073b27c055baad186a3b0942c30a627fa5437eb..93c6fc8e2d5a14f9a90d1ab73b9caf58509d8820 100644 (file)
@@ -95,6 +95,7 @@ struct print_ops {
        void (*reachability_associations_log)(struct nvme_reachability_associations_log *log,
                                              __u64 len);
        void (*host_discovery_log)(struct nvme_host_discover_log *log);
+       void (*ave_discovery_log)(struct nvme_ave_discover_log *log);
 
        /* libnvme tree print functions */
        void (*list_item)(nvme_ns_t n);
@@ -347,4 +348,5 @@ void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
 void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
                                             __u64 len, nvme_print_flags_t flags);
 void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print_flags_t flags);
+void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_flags_t flags);
 #endif /* NVME_PRINT_H */
index bbf4264f33db3dbca263af0c3bc71394e04d2d1d..64b71eaa6d4964ece8b5aa9ee7005712c3343361 100644 (file)
@@ -475,3 +475,9 @@ int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool ra
 {
        return do_admin_op(get_log_host_discover, dev, allhoste, rae, len, log);
 }
+
+int nvme_cli_get_log_ave_discovery(struct nvme_dev *dev, bool rae, __u32 len,
+                                  struct nvme_ave_discover_log *log)
+{
+       return do_admin_op(get_log_ave_discover, dev, rae, len, log);
+}
index d5317a1378171185c5e6788a4d04faf46b89e687..d82bbd919a6db3d276aef52e6fc3da32745d1026 100644 (file)
@@ -165,4 +165,7 @@ int nvme_cli_get_log_reachability_associations(struct nvme_dev *dev, bool rgo, b
 
 int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool rae, __u32 len,
                                    struct nvme_host_discover_log *log);
+
+int nvme_cli_get_log_ave_discovery(struct nvme_dev *dev, bool rae, __u32 len,
+                                  struct nvme_ave_discover_log *log);
 #endif /* _NVME_WRAP_H */
diff --git a/nvme.c b/nvme.c
index 875a094bd78113e80f7226ba2b35dfd7719997e6..6d6e76fdf3130a0b32142632a001bf0ea9cbbc6a 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -10710,6 +10710,84 @@ static int get_host_discovery_log(int argc, char **argv, struct command *cmd, st
        return err;
 }
 
+static int get_ave_discovery(struct nvme_dev *dev, bool rae,
+                            struct nvme_ave_discover_log **logp)
+{
+       int err;
+       struct nvme_ave_discover_log *log;
+       __u64 log_len = sizeof(*log);
+       struct nvme_get_log_args args = {
+               .args_size = sizeof(args),
+               .fd = dev_fd(dev),
+               .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+               .lid = NVME_LOG_LID_HOST_DISCOVER,
+               .nsid = NVME_NSID_ALL,
+               .rae = rae,
+       };
+
+       log = nvme_alloc(log_len);
+       if (!log)
+               return -ENOMEM;
+
+       err = nvme_cli_get_log_ave_discovery(dev, rae, log_len, log);
+       if (err)
+               goto err_free;
+
+       log_len = le32_to_cpu(log->tadlpl);
+       err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->tadlpl) - log_len,
+                            (void **)&log);
+       if (err)
+               goto err_free;
+
+       *logp = log;
+       return 0;
+
+err_free:
+       free(log);
+       return err;
+}
+
+static int get_ave_discovery_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       const char *desc = "Retrieve AVE Discovery Log, show it";
+       nvme_print_flags_t flags;
+       int err;
+
+       _cleanup_free_ struct nvme_ave_discover_log *log = NULL;
+
+       _cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
+
+       struct config {
+               bool rae;
+       };
+
+       struct config cfg = {
+               .rae = false,
+       };
+
+       NVME_ARGS(opts, OPT_FLAG("rae", 'r', &cfg.rae, rae));
+
+       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;
+       }
+
+       err = get_ave_discovery(dev, cfg.rae, &log);
+       if (!err)
+               nvme_show_ave_discovery_log(log, flags);
+       else if (err > 0)
+               nvme_show_status(err);
+       else
+               nvme_show_perror("ave discovery log");
+
+       return err;
+}
+
 void register_extension(struct plugin *plugin)
 {
        plugin->parent = &nvme;