]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print-binary: fix to output reachability associations log length
authorTokunori Ikegami <ikegami.t@gmail.com>
Sun, 16 Feb 2025 02:25:42 +0000 (11:25 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 17 Feb 2025 14:39:11 +0000 (15:39 +0100)
Previously only the log header output since the log length is changeable.
The changes to output the changeable log length correctly.

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

index a1e4885a6e382b44c71dc38288b6efa236f20214..fb2e087a00782a4d8e2005f7c9076d53f8b31367 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
 #include "nvme-print.h"
+#include "util/logging.h"
 
 static struct print_ops binary_print_ops;
 
@@ -326,9 +327,10 @@ static void binary_reachability_groups_log(struct nvme_reachability_groups_log *
        d_raw((unsigned char *)log, sizeof(*log));
 }
 
-static void binary_reachability_associations_log(struct nvme_reachability_associations_log *log)
+static void binary_reachability_associations_log(struct nvme_reachability_associations_log *log,
+                                                __u64 len)
 {
-       d_raw((unsigned char *)log, sizeof(*log));
+       d_raw((unsigned char *)log, len);
 }
 
 static struct print_ops binary_print_ops = {
index 4bd6a650d7ba4c505491e9ae96f3079e94253d20..fe01ca4666240870edd253dadd2bccc0214fa6dc 100644 (file)
@@ -4,9 +4,12 @@
 #include <errno.h>
 #include <time.h>
 
+#include <ccan/ccan/compiler/compiler.h>
+
 #include "nvme-print.h"
 
 #include "util/json.h"
+#include "util/logging.h"
 #include "nvme.h"
 #include "common.h"
 
@@ -4705,7 +4708,8 @@ static void json_reachability_groups_log(struct nvme_reachability_groups_log *lo
        json_print(r);
 }
 
-static void json_reachability_associations_log(struct nvme_reachability_associations_log *log)
+static void json_reachability_associations_log(struct nvme_reachability_associations_log *log,
+                                              __u64 len UNUSED)
 {
        struct json_object *r = json_create_object();
        __u16 i;
index 929984b2b266b48fdd02f74a6b9f7f2370a2e3b9..3481369d6d47014a5cecde2ac6022aaae348f708 100644 (file)
@@ -18,6 +18,7 @@
 #include "nvme-models.h"
 #include "util/suffix.h"
 #include "util/types.h"
+#include "util/logging.h"
 #include "common.h"
 
 static const uint8_t zero_uuid[16] = { 0 };
@@ -5673,11 +5674,13 @@ static void stdout_reachability_groups_log(struct nvme_reachability_groups_log *
        }
 }
 
-static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log)
+static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log,
+                                                __u64 len)
 {
        __u16 i;
        __u32 j;
 
+       print_debug("len: %"PRIu64"\n", (uint64_t)len);
        printf("chngc: %"PRIu64"\n", le64_to_cpu(log->chngc));
        printf("nrad: %u\n", le16_to_cpu(log->nrad));
 
index 5c0f7ca52569edfdd8a4f15df3304c68b7ec843b..69cdeb2354fb0c4c0bef0b6d5d4ab58dd6989d9f 100644 (file)
@@ -1516,7 +1516,7 @@ void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
 }
 
 void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
-                                            nvme_print_flags_t flags)
+                                            __u64 len, nvme_print_flags_t flags)
 {
-       nvme_print(reachability_associations_log, flags, log);
+       nvme_print(reachability_associations_log, flags, log, len);
 }
index 5e6663adcc695cdb937daa72fa85af7599bdc59e..e43883e4fe96fcb5061fa17c7d72f495e4f64862 100644 (file)
@@ -92,7 +92,8 @@ struct print_ops {
        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);
        void (*reachability_groups_log)(struct nvme_reachability_groups_log *log);
-       void (*reachability_associations_log)(struct nvme_reachability_associations_log *log);
+       void (*reachability_associations_log)(struct nvme_reachability_associations_log *log,
+                                             __u64 len);
 
        /* libnvme tree print functions */
        void (*list_item)(nvme_ns_t n);
@@ -343,5 +344,5 @@ void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_
 void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
                                       nvme_print_flags_t flags);
 void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
-                                            nvme_print_flags_t flags);
+                                            __u64 len, nvme_print_flags_t flags);
 #endif /* NVME_PRINT_H */
diff --git a/nvme.c b/nvme.c
index f4d5e0e86a80d33069de74a5d7fabe6d485b9095..c6a0515d7875822412e15133f2e959a115f2f2c0 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -10501,7 +10501,7 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *cm
 }
 
 static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
-                                            __u64 offset,
+                                            __u64 *offset,
                                             struct nvme_reachability_associations_log **logp)
 {
        int err;
@@ -10511,11 +10511,11 @@ static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_g
 
        for (i = 0; i < le16_to_cpu(log->nrad); i++) {
                len = sizeof(*log->rad);
-               err = get_log_offset(dev, args, &offset, len, (void **)&log);
+               err = get_log_offset(dev, args, offset, len, (void **)&log);
                if (err)
                        goto err_free;
                len = le32_to_cpu(log->rad[i].nrid) * sizeof(*log->rad[i].rgid);
-               err = get_log_offset(dev, args, &offset, len, (void **)&log);
+               err = get_log_offset(dev, args, offset, len, (void **)&log);
                if (err)
                        goto err_free;
        }
@@ -10530,7 +10530,8 @@ err_free:
 }
 
 static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool rae,
-                                        struct nvme_reachability_associations_log **logp)
+                                        struct nvme_reachability_associations_log **logp,
+                                        __u64 *lenp)
 {
        int err;
        struct nvme_reachability_associations_log *log;
@@ -10553,11 +10554,12 @@ static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool ra
        if (err)
                goto err_free;
 
-       err = get_reachability_association_desc(dev, &args, log_len, &log);
+       err = get_reachability_association_desc(dev, &args, &log_len, &log);
        if (err)
                goto err_free;
 
        *logp = log;
+       *lenp = log_len;
        return 0;
 
 err_free:
@@ -10572,6 +10574,7 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
        const char *rao = "Return Associations Only";
        nvme_print_flags_t flags;
        int err;
+       __u64 len = 0;
 
        _cleanup_free_ struct nvme_reachability_associations_log *log = NULL;
 
@@ -10601,9 +10604,9 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
                return err;
        }
 
-       err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log);
+       err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log, &len);
        if (!err)
-               nvme_show_reachability_associations_log(log, flags);
+               nvme_show_reachability_associations_log(log, len, flags);
        else if (err > 0)
                nvme_show_status(err);
        else