Skip to content

Commit 24e9d69

Browse files
committed
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 <ikegami.t@gmail.com>
1 parent ecb2e26 commit 24e9d69

File tree

6 files changed

+34
-15
lines changed

6 files changed

+34
-15
lines changed

nvme-print-binary.c

Lines changed: 5 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,11 @@ 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+
print_debug("len: %"PRIu64"\n", (uint64_t)len);
334+
d_raw((unsigned char *)log, len);
332335
}
333336

334337
static struct print_ops binary_print_ops = {

nvme-print-json.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nvme-print.h"
88

99
#include "util/json.h"
10+
#include "util/logging.h"
1011
#include "nvme.h"
1112
#include "common.h"
1213

@@ -36,6 +37,12 @@
3637
#define obj_add_uint_0nx json_object_add_uint_0nx
3738
#define obj_add_0nprix64 json_object_add_0nprix64
3839

40+
#define obj_add_debug(type, ...) \
41+
do { \
42+
if (log_level >= LOG_DEBUG) \
43+
obj_add_ ## type(__VA_ARGS__); \
44+
} while (false)
45+
3946
static const uint8_t zero_uuid[16] = { 0 };
4047
static struct print_ops json_print_ops;
4148
static struct json_object *json_r;
@@ -4701,14 +4708,16 @@ static void json_reachability_groups_log(struct nvme_reachability_groups_log *lo
47014708
json_print(r);
47024709
}
47034710

4704-
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)
47054713
{
47064714
struct json_object *r = json_create_object();
47074715
__u16 i;
47084716
__u32 j;
47094717
char json_str[STR_LEN];
47104718
struct json_object *rad;
47114719

4720+
obj_add_debug(uint64, r, "len", len);
47124721
obj_add_uint64(r, "chngc", le64_to_cpu(log->chngc));
47134722
obj_add_uint(r, "nrad", le16_to_cpu(log->nrad));
47144723

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 };
@@ -5655,11 +5656,13 @@ static void stdout_reachability_groups_log(struct nvme_reachability_groups_log *
56555656
}
56565657
}
56575658

5658-
static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log)
5659+
static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log,
5660+
__u64 len)
56595661
{
56605662
__u16 i;
56615663
__u32 j;
56625664

5665+
print_debug("len: %"PRIu64"\n", (uint64_t)len);
56635666
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->chngc));
56645667
printf("nrad: %u\n", le16_to_cpu(log->nrad));
56655668

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
@@ -10335,7 +10335,7 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *cm
1033510335
}
1033610336

1033710337
static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
10338-
__u64 offset,
10338+
__u64 *offset,
1033910339
struct nvme_reachability_associations_log **logp)
1034010340
{
1034110341
int err;
@@ -10345,11 +10345,11 @@ static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_g
1034510345

1034610346
for (i = 0; i < le16_to_cpu(log->nrad); i++) {
1034710347
len = sizeof(*log->rad);
10348-
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10348+
err = get_log_offset(dev, args, offset, len, (void **)&log);
1034910349
if (err)
1035010350
goto err_free;
1035110351
len = le32_to_cpu(log->rad[i].nrid) * sizeof(*log->rad[i].rgid);
10352-
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10352+
err = get_log_offset(dev, args, offset, len, (void **)&log);
1035310353
if (err)
1035410354
goto err_free;
1035510355
}
@@ -10364,7 +10364,8 @@ static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_g
1036410364
}
1036510365

1036610366
static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool rae,
10367-
struct nvme_reachability_associations_log **logp)
10367+
struct nvme_reachability_associations_log **logp,
10368+
__u64 *lenp)
1036810369
{
1036910370
int err;
1037010371
struct nvme_reachability_associations_log *log;
@@ -10387,11 +10388,12 @@ static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool ra
1038710388
if (err)
1038810389
goto err_free;
1038910390

10390-
err = get_reachability_association_desc(dev, &args, log_len, &log);
10391+
err = get_reachability_association_desc(dev, &args, &log_len, &log);
1039110392
if (err)
1039210393
goto err_free;
1039310394

1039410395
*logp = log;
10396+
*lenp = log_len;
1039510397
return 0;
1039610398

1039710399
err_free:
@@ -10406,6 +10408,7 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
1040610408
const char *rao = "Return Associations Only";
1040710409
nvme_print_flags_t flags;
1040810410
int err;
10411+
__u64 len = 0;
1040910412

1041010413
_cleanup_free_ struct nvme_reachability_associations_log *log = NULL;
1041110414

@@ -10435,9 +10438,9 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
1043510438
return err;
1043610439
}
1043710440

10438-
err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log);
10441+
err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log, &len);
1043910442
if (!err)
10440-
nvme_show_reachability_associations_log(log, flags);
10443+
nvme_show_reachability_associations_log(log, len, flags);
1044110444
else if (err > 0)
1044210445
nvme_show_status(err);
1044310446
else

0 commit comments

Comments
 (0)