Skip to content

Commit b5bb01a

Browse files
ikegami-tigaw
authored andcommitted
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 <[email protected]>
1 parent 68c6ad7 commit b5bb01a

6 files changed

Lines changed: 28 additions & 15 deletions

File tree

nvme-print-binary.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0-or-later */
22

33
#include "nvme-print.h"
4+
#include "util/logging.h"
45

56
static struct print_ops binary_print_ops;
67

@@ -326,9 +327,10 @@ static void binary_reachability_groups_log(struct nvme_reachability_groups_log *
326327
d_raw((unsigned char *)log, sizeof(*log));
327328
}
328329

329-
static void binary_reachability_associations_log(struct nvme_reachability_associations_log *log)
330+
static void binary_reachability_associations_log(struct nvme_reachability_associations_log *log,
331+
__u64 len)
330332
{
331-
d_raw((unsigned char *)log, sizeof(*log));
333+
d_raw((unsigned char *)log, len);
332334
}
333335

334336
static struct print_ops binary_print_ops = {

nvme-print-json.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#include <errno.h>
55
#include <time.h>
66

7+
#include <ccan/ccan/compiler/compiler.h>
8+
79
#include "nvme-print.h"
810

911
#include "util/json.h"
12+
#include "util/logging.h"
1013
#include "nvme.h"
1114
#include "common.h"
1215

@@ -4705,7 +4708,8 @@ static void json_reachability_groups_log(struct nvme_reachability_groups_log *lo
47054708
json_print(r);
47064709
}
47074710

4708-
static void json_reachability_associations_log(struct nvme_reachability_associations_log *log)
4711+
static void json_reachability_associations_log(struct nvme_reachability_associations_log *log,
4712+
__u64 len UNUSED)
47094713
{
47104714
struct json_object *r = json_create_object();
47114715
__u16 i;

nvme-print-stdout.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "nvme-models.h"
1919
#include "util/suffix.h"
2020
#include "util/types.h"
21+
#include "util/logging.h"
2122
#include "common.h"
2223

2324
static const uint8_t zero_uuid[16] = { 0 };
@@ -5673,11 +5674,13 @@ static void stdout_reachability_groups_log(struct nvme_reachability_groups_log *
56735674
}
56745675
}
56755676

5676-
static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log)
5677+
static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log,
5678+
__u64 len)
56775679
{
56785680
__u16 i;
56795681
__u32 j;
56805682

5683+
print_debug("len: %"PRIu64"\n", (uint64_t)len);
56815684
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->chngc));
56825685
printf("nrad: %u\n", le16_to_cpu(log->nrad));
56835686

nvme-print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
15161516
}
15171517

15181518
void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
1519-
nvme_print_flags_t flags)
1519+
__u64 len, nvme_print_flags_t flags)
15201520
{
1521-
nvme_print(reachability_associations_log, flags, log);
1521+
nvme_print(reachability_associations_log, flags, log, len);
15221522
}

nvme-print.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ struct print_ops {
9292
void (*rotational_media_info_log)(struct nvme_rotational_media_info_log *info);
9393
void (*dispersed_ns_psub_log)(struct nvme_dispersed_ns_participating_nss_log *log);
9494
void (*reachability_groups_log)(struct nvme_reachability_groups_log *log);
95-
void (*reachability_associations_log)(struct nvme_reachability_associations_log *log);
95+
void (*reachability_associations_log)(struct nvme_reachability_associations_log *log,
96+
__u64 len);
9697

9798
/* libnvme tree print functions */
9899
void (*list_item)(nvme_ns_t n);
@@ -343,5 +344,5 @@ void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_
343344
void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
344345
nvme_print_flags_t flags);
345346
void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
346-
nvme_print_flags_t flags);
347+
__u64 len, nvme_print_flags_t flags);
347348
#endif /* NVME_PRINT_H */

nvme.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10501,7 +10501,7 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *cm
1050110501
}
1050210502

1050310503
static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
10504-
__u64 offset,
10504+
__u64 *offset,
1050510505
struct nvme_reachability_associations_log **logp)
1050610506
{
1050710507
int err;
@@ -10511,11 +10511,11 @@ static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_g
1051110511

1051210512
for (i = 0; i < le16_to_cpu(log->nrad); i++) {
1051310513
len = sizeof(*log->rad);
10514-
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10514+
err = get_log_offset(dev, args, offset, len, (void **)&log);
1051510515
if (err)
1051610516
goto err_free;
1051710517
len = le32_to_cpu(log->rad[i].nrid) * sizeof(*log->rad[i].rgid);
10518-
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10518+
err = get_log_offset(dev, args, offset, len, (void **)&log);
1051910519
if (err)
1052010520
goto err_free;
1052110521
}
@@ -10530,7 +10530,8 @@ static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_g
1053010530
}
1053110531

1053210532
static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool rae,
10533-
struct nvme_reachability_associations_log **logp)
10533+
struct nvme_reachability_associations_log **logp,
10534+
__u64 *lenp)
1053410535
{
1053510536
int err;
1053610537
struct nvme_reachability_associations_log *log;
@@ -10553,11 +10554,12 @@ static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool ra
1055310554
if (err)
1055410555
goto err_free;
1055510556

10556-
err = get_reachability_association_desc(dev, &args, log_len, &log);
10557+
err = get_reachability_association_desc(dev, &args, &log_len, &log);
1055710558
if (err)
1055810559
goto err_free;
1055910560

1056010561
*logp = log;
10562+
*lenp = log_len;
1056110563
return 0;
1056210564

1056310565
err_free:
@@ -10572,6 +10574,7 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
1057210574
const char *rao = "Return Associations Only";
1057310575
nvme_print_flags_t flags;
1057410576
int err;
10577+
__u64 len = 0;
1057510578

1057610579
_cleanup_free_ struct nvme_reachability_associations_log *log = NULL;
1057710580

@@ -10601,9 +10604,9 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
1060110604
return err;
1060210605
}
1060310606

10604-
err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log);
10607+
err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log, &len);
1060510608
if (!err)
10606-
nvme_show_reachability_associations_log(log, flags);
10609+
nvme_show_reachability_associations_log(log, len, flags);
1060710610
else if (err > 0)
1060810611
nvme_show_status(err);
1060910612
else

0 commit comments

Comments
 (0)