]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add dispersed-ns-participating-nss-log command
authorTokunori Ikegami <ikegami.t@gmail.com>
Sun, 2 Feb 2025 11:20:46 +0000 (20:20 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 10 Feb 2025 13:00:05 +0000 (14:00 +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 486b1e5a80aae1d6c74b650e1da7da822e8ae109..caa60721eae804f810b58cd127d511e3bfe22471 100644 (file)
@@ -61,6 +61,7 @@ COMMAND_LIST(
        ENTRY("mgmt-addr-list-log", "Retrieve Management Address List Log, show it", get_mgmt_addr_list_log)
        ENTRY("rotational-media-info-log", "Retrieve Rotational Media Information Log, show it", get_rotational_media_info_log)
        ENTRY("changed-alloc-ns-list-log", "Retrieve Changed Allocated Namespace List, show it", get_changed_alloc_ns_list_log)
+       ENTRY("dispersed-ns-participating-nss-log", "Retrieve Dispersed Namespace Participating NVM Subsystems Log, show it", get_dispersed_ns_participating_nss_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 2c5135a7b2886b630eeb171e68a3a143be946f6a..e9aa5688b045cbd3bc7cc8da75c1e1cb35c79002 100644 (file)
@@ -316,6 +316,11 @@ static void binary_rotational_media_info_log(struct nvme_rotational_media_info_l
        d_raw((unsigned char *)info, sizeof(*info));
 }
 
+static void binary_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
+{
+       d_raw((unsigned char *)log, sizeof(*log));
+}
+
 static struct print_ops binary_print_ops = {
        /* libnvme types.h print functions */
        .ana_log                        = binary_ana_log,
@@ -384,6 +389,7 @@ static struct print_ops binary_print_ops = {
        .show_finish                    = NULL,
        .mgmt_addr_list_log             = binary_mgmt_addr_list_log,
        .rotational_media_info_log      = binary_rotational_media_info_log,
+       .dispersed_ns_psub_log          = binary_dispersed_ns_psub_log,
 
        /* libnvme tree print functions */
        .list_item                      = NULL,
index ee4338aae22d97101462bb83c8e0252015cd18d9..57110c1539ad11a313b6c1b14650f73cc226b145 100644 (file)
@@ -4657,6 +4657,26 @@ static void json_rotational_media_info_log(struct nvme_rotational_media_info_log
        json_print(r);
 }
 
+static void json_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
+{
+       struct json_object *r = json_create_object();
+       __u64 numpsub = le64_to_cpu(log->numpsub);
+       __u64 i;
+       char json_str[STR_LEN];
+       char psub[NVME_NQN_LENGTH + 1];
+
+       obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr));
+       obj_add_uint64(r, "numpsub", numpsub);
+       for (i = 0; i < numpsub; i++) {
+               snprintf(json_str, sizeof(json_str), "participating_nss %"PRIu64"", (uint64_t)i);
+               snprintf(psub, sizeof(psub), "%-.*s", NVME_NQN_LENGTH,
+                        &log->participating_nss[i * NVME_NQN_LENGTH]);
+               obj_add_str(r, json_str, psub);
+       }
+
+       json_print(r);
+}
+
 static struct print_ops json_print_ops = {
        /* libnvme types.h print functions */
        .ana_log                        = json_ana_log,
@@ -4726,6 +4746,7 @@ static struct print_ops json_print_ops = {
        .show_finish                    = json_show_finish,
        .mgmt_addr_list_log             = json_mgmt_addr_list_log,
        .rotational_media_info_log      = json_rotational_media_info_log,
+       .dispersed_ns_psub_log          = json_dispersed_ns_psub_log,
 
        /* libnvme tree print functions */
        .list_item                      = json_list_item,
index cc4d1fcdae05d3511f1749988a8b5ec88dfe7e87..9faf8466a89ef28b9258f98c3c484371b753b96a 100644 (file)
@@ -5603,6 +5603,18 @@ static void stdout_rotational_media_info_log(struct nvme_rotational_media_info_l
        printf("fldc: %u\n", le32_to_cpu(info->fldc));
 }
 
+static void stdout_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
+{
+       __u64 numpsub = le64_to_cpu(log->numpsub);
+       __u64 i;
+
+       printf("genctr: %"PRIu64"\n", le64_to_cpu(log->genctr));
+       printf("numpsub: %"PRIu64"\n", (uint64_t)numpsub);
+       for (i = 0; i < numpsub; i++)
+               printf("participating_nss %"PRIu64": %-.*s\n", (uint64_t)i, NVME_NQN_LENGTH,
+                      &log->participating_nss[i * NVME_NQN_LENGTH]);
+}
+
 static struct print_ops stdout_print_ops = {
        /* libnvme types.h print functions */
        .ana_log                        = stdout_ana_log,
@@ -5672,6 +5684,7 @@ static struct print_ops stdout_print_ops = {
        .show_finish                    = NULL,
        .mgmt_addr_list_log             = stdout_mgmt_addr_list_log,
        .rotational_media_info_log      = stdout_rotational_media_info_log,
+       .dispersed_ns_psub_log          = stdout_dispersed_ns_psub_log,
 
        /* libnvme tree print functions */
        .list_item                      = stdout_list_item,
index bb41543b402dac1f6d710ef73542c77448a4baf8..77f4b17ed59ec625df758b529b5435d6351c8525 100644 (file)
@@ -1502,3 +1502,9 @@ void nvme_show_rotational_media_info_log(struct nvme_rotational_media_info_log *
 {
        nvme_print(rotational_media_info_log, flags, info);
 }
+
+void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log,
+                                    nvme_print_flags_t flags)
+{
+       nvme_print(dispersed_ns_psub_log, flags, log);
+}
index 55616279a3a90893760f947a5b464da6a880ad34..e446c07ea6ab95c48aa5d5a02b58ad3d4a1df5b3 100644 (file)
@@ -90,6 +90,7 @@ struct print_ops {
        void (*show_finish)(void);
        void (*mgmt_addr_list_log)(struct nvme_mgmt_addr_list_log *ma_log);
        void (*rotational_media_info_log)(struct nvme_rotational_media_info_log *info);
+       void (*dispersed_ns_psub_log)(struct nvme_dispersed_ns_participating_nss_log *log);
 
        /* libnvme tree print functions */
        void (*list_item)(nvme_ns_t n);
@@ -335,4 +336,6 @@ void nvme_show_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list,
                                  nvme_print_flags_t flags);
 void nvme_show_rotational_media_info_log(struct nvme_rotational_media_info_log *info,
                                         nvme_print_flags_t flags);
+void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log,
+                                    nvme_print_flags_t flags);
 #endif /* NVME_PRINT_H */
index 0b1039a6829de38da4ca2959154ba1bd65971e43..2cc5204f9327e787b3a31b19e76ce5626d6e5c68 100644 (file)
@@ -451,3 +451,9 @@ int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, _
 
        return -ENODEV;
 }
+
+int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32 nsid, __u32 len,
+       struct nvme_dispersed_ns_participating_nss_log *log)
+{
+       return do_admin_op(get_log_dispersed_ns_participating_nss, dev, nsid, len, log);
+}
index bde7d720abd2f00c5d0dc5582a71f52014638e28..b675f4f0daff2e6700e5a64e960ec7ef34f22f74 100644 (file)
@@ -154,4 +154,7 @@ int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len,
 int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, __u32 len,
                                           struct nvme_rotational_media_info_log *info);
 
+int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32 nsid, __u32 len,
+       struct nvme_dispersed_ns_participating_nss_log *log);
+
 #endif /* _NVME_WRAP_H */
diff --git a/nvme.c b/nvme.c
index 06deeaeb56f2a948053029f6ca3b66676e5d4475..a50ffab60e4e03b1db43f73f257aefde95135f18 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -10165,6 +10165,94 @@ static int get_rotational_media_info_log(int argc, char **argv, struct command *
        return err;
 }
 
+static int get_dispersed_ns_psub(struct nvme_dev *dev, __u32 nsid,
+                                struct nvme_dispersed_ns_participating_nss_log **logp)
+{
+       int err;
+       __u64 header_len = sizeof(**logp);
+       __u64 psub_list_len;
+       struct nvme_get_log_args args = {
+               .args_size = sizeof(args),
+               .fd = dev_fd(dev),
+               .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+               .lid = NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS,
+               .nsid = nsid,
+               .lpo = header_len,
+       };
+       struct nvme_dispersed_ns_participating_nss_log *log = nvme_alloc(header_len);
+
+       if (!log)
+               return -ENOMEM;
+
+       err = nvme_cli_get_log_dispersed_ns_participating_nss(dev, nsid, header_len, log);
+       if (err)
+               goto err_free;
+
+       psub_list_len = le64_to_cpu(log->numpsub) * NVME_NQN_LENGTH;
+
+       log = nvme_realloc(log, header_len + psub_list_len);
+       if (!log) {
+               err = -ENOMEM;
+               goto err_free;
+       }
+
+       args.log = log->participating_nss,
+       args.len = psub_list_len;
+
+       err = nvme_cli_get_log_page(dev, NVME_LOG_PAGE_PDU_SIZE, &args);
+       if (err)
+               goto err_free;
+
+       *logp = log;
+       return 0;
+
+err_free:
+       free(log);
+       return err;
+}
+
+static int get_dispersed_ns_participating_nss_log(int argc, char **argv, struct command *cmd,
+                                                 struct plugin *plugin)
+{
+       const char *desc = "Retrieve Dispersed Namespace Participating NVM Subsystems Log, show it";
+       nvme_print_flags_t flags;
+       int err;
+
+       _cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
+
+       _cleanup_free_ struct nvme_dispersed_ns_participating_nss_log *log = NULL;
+
+       struct config {
+               __u32 namespace_id;
+       };
+
+       struct config cfg = {
+               .namespace_id = 1,
+       };
+
+       NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired));
+
+       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_dispersed_ns_psub(dev, cfg.namespace_id, &log);
+       if (!err)
+               nvme_show_dispersed_ns_psub_log(log, flags);
+       else if (err > 0)
+               nvme_show_status(err);
+       else
+               nvme_show_perror("dispersed ns participating nss log");
+
+       return err;
+}
+
 void register_extension(struct plugin *plugin)
 {
        plugin->parent = &nvme;