From b5bb01a2ea290a53fb4b3417829b7cb1b417d1ca Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 16 Feb 2025 11:25:42 +0900 Subject: [PATCH] nvme-print-binary: fix to output reachability associations log length 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 --- nvme-print-binary.c | 6 ++++-- nvme-print-json.c | 6 +++++- nvme-print-stdout.c | 5 ++++- nvme-print.c | 4 ++-- nvme-print.h | 5 +++-- nvme.c | 17 ++++++++++------- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/nvme-print-binary.c b/nvme-print-binary.c index a1e4885a..fb2e087a 100644 --- a/nvme-print-binary.c +++ b/nvme-print-binary.c @@ -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 = { diff --git a/nvme-print-json.c b/nvme-print-json.c index 4bd6a650..fe01ca46 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -4,9 +4,12 @@ #include #include +#include + #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; diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 929984b2..3481369d 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -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)); diff --git a/nvme-print.c b/nvme-print.c index 5c0f7ca5..69cdeb23 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -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); } diff --git a/nvme-print.h b/nvme-print.h index 5e6663ad..e43883e4 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -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 f4d5e0e8..c6a0515d 100644 --- 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 -- 2.50.1