Skip to content

Commit 86495e8

Browse files
ikegami-tigaw
authored andcommitted
nvme: add reachability-associations-log command
Since added the NVMe 2.1 log page. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 18e2eb9 commit 86495e8

File tree

9 files changed

+182
-0
lines changed

9 files changed

+182
-0
lines changed

nvme-builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ COMMAND_LIST(
6363
ENTRY("changed-alloc-ns-list-log", "Retrieve Changed Allocated Namespace List, show it", get_changed_alloc_ns_list_log)
6464
ENTRY("dispersed-ns-participating-nss-log", "Retrieve Dispersed Namespace Participating NVM Subsystems Log, show it", get_dispersed_ns_participating_nss_log)
6565
ENTRY("reachability-groups-log", "Retrieve Reachability Groups Log, show it", get_reachability_groups_log)
66+
ENTRY("reachability-associations-log", "Retrieve Reachability Associations Log, show it", get_reachability_associations_log)
6667
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6768
ENTRY("set-property", "Set a property and show the resulting value", set_property)
6869
ENTRY("get-property", "Get a property and show the resulting value", get_property)

nvme-print-binary.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ static void binary_reachability_groups_log(struct nvme_reachability_groups_log *
326326
d_raw((unsigned char *)log, sizeof(*log));
327327
}
328328

329+
static void binary_reachability_associations_log(struct nvme_reachability_associations_log *log)
330+
{
331+
d_raw((unsigned char *)log, sizeof(*log));
332+
}
333+
329334
static struct print_ops binary_print_ops = {
330335
/* libnvme types.h print functions */
331336
.ana_log = binary_ana_log,
@@ -396,6 +401,7 @@ static struct print_ops binary_print_ops = {
396401
.rotational_media_info_log = binary_rotational_media_info_log,
397402
.dispersed_ns_psub_log = binary_dispersed_ns_psub_log,
398403
.reachability_groups_log = binary_reachability_groups_log,
404+
.reachability_associations_log = binary_reachability_associations_log,
399405

400406
/* libnvme tree print functions */
401407
.list_item = NULL,

nvme-print-json.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,6 +4701,31 @@ static void json_reachability_groups_log(struct nvme_reachability_groups_log *lo
47014701
json_print(r);
47024702
}
47034703

4704+
static void json_reachability_associations_log(struct nvme_reachability_associations_log *log)
4705+
{
4706+
struct json_object *r = json_create_object();
4707+
__u16 i;
4708+
__u32 j;
4709+
char json_str[STR_LEN];
4710+
struct json_object *rad;
4711+
4712+
obj_add_uint64(r, "chngc", le64_to_cpu(log->chngc));
4713+
obj_add_uint(r, "nrad", le16_to_cpu(log->nrad));
4714+
4715+
for (i = 0; i < le16_to_cpu(log->nrad); i++) {
4716+
snprintf(json_str, sizeof(json_str), "rasid: %u", le32_to_cpu(log->rad[i].rasid));
4717+
rad = json_create_object();
4718+
obj_add_uint(rad, "nrid", le32_to_cpu(log->rad[i].nrid));
4719+
obj_add_uint64(rad, "chngc", le64_to_cpu(log->rad[i].chngc));
4720+
obj_add_uint(rad, "rac", log->rad[i].rac);
4721+
for (j = 0; j < le32_to_cpu(log->rad[i].nrid); j++)
4722+
obj_add_uint(rad, "rgid", le32_to_cpu(log->rad[i].rgid[j]));
4723+
obj_add_obj(r, json_str, rad);
4724+
}
4725+
4726+
json_print(r);
4727+
}
4728+
47044729
static struct print_ops json_print_ops = {
47054730
/* libnvme types.h print functions */
47064731
.ana_log = json_ana_log,
@@ -4772,6 +4797,7 @@ static struct print_ops json_print_ops = {
47724797
.rotational_media_info_log = json_rotational_media_info_log,
47734798
.dispersed_ns_psub_log = json_dispersed_ns_psub_log,
47744799
.reachability_groups_log = json_reachability_groups_log,
4800+
.reachability_associations_log = json_reachability_associations_log,
47754801

47764802
/* libnvme tree print functions */
47774803
.list_item = json_list_item,

nvme-print-stdout.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5655,6 +5655,24 @@ static void stdout_reachability_groups_log(struct nvme_reachability_groups_log *
56555655
}
56565656
}
56575657

5658+
static void stdout_reachability_associations_log(struct nvme_reachability_associations_log *log)
5659+
{
5660+
__u16 i;
5661+
__u32 j;
5662+
5663+
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->chngc));
5664+
printf("nrad: %u\n", le16_to_cpu(log->nrad));
5665+
5666+
for (i = 0; i < le16_to_cpu(log->nrad); i++) {
5667+
printf("rasid: %u\n", le32_to_cpu(log->rad[i].rasid));
5668+
printf("nrid: %u\n", le32_to_cpu(log->rad[i].nrid));
5669+
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->rad[i].chngc));
5670+
printf("rac: %u\n", log->rad[i].rac);
5671+
for (j = 0; j < le32_to_cpu(log->rad[i].nrid); j++)
5672+
printf("rgid%u: %u\n", j, le32_to_cpu(log->rad[i].rgid[j]));
5673+
}
5674+
}
5675+
56585676
static struct print_ops stdout_print_ops = {
56595677
/* libnvme types.h print functions */
56605678
.ana_log = stdout_ana_log,
@@ -5726,6 +5744,7 @@ static struct print_ops stdout_print_ops = {
57265744
.rotational_media_info_log = stdout_rotational_media_info_log,
57275745
.dispersed_ns_psub_log = stdout_dispersed_ns_psub_log,
57285746
.reachability_groups_log = stdout_reachability_groups_log,
5747+
.reachability_associations_log = stdout_reachability_associations_log,
57295748

57305749
/* libnvme tree print functions */
57315750
.list_item = stdout_list_item,

nvme-print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,3 +1514,9 @@ void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
15141514
{
15151515
nvme_print(reachability_groups_log, flags, log);
15161516
}
1517+
1518+
void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
1519+
nvme_print_flags_t flags)
1520+
{
1521+
nvme_print(reachability_associations_log, flags, log);
1522+
}

nvme-print.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ 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);
9596

9697
/* libnvme tree print functions */
9798
void (*list_item)(nvme_ns_t n);
@@ -341,4 +342,6 @@ void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_
341342
nvme_print_flags_t flags);
342343
void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
343344
nvme_print_flags_t flags);
345+
void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
346+
nvme_print_flags_t flags);
344347
#endif /* NVME_PRINT_H */

nvme-wrap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,9 @@ int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool ra
463463
{
464464
return do_admin_op(get_log_reachability_groups, dev, rgo, rae, len, log);
465465
}
466+
467+
int nvme_cli_get_log_reachability_associations(struct nvme_dev *dev, bool rao, bool rae, __u32 len,
468+
struct nvme_reachability_associations_log *log)
469+
{
470+
return do_admin_op(get_log_reachability_associations, dev, len, rao, rae, log);
471+
}

nvme-wrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,7 @@ int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32
159159

160160
int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
161161
struct nvme_reachability_groups_log *log);
162+
163+
int nvme_cli_get_log_reachability_associations(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
164+
struct nvme_reachability_associations_log *log);
162165
#endif /* _NVME_WRAP_H */

nvme.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10334,6 +10334,118 @@ static int get_reachability_groups_log(int argc, char **argv, struct command *cm
1033410334
return err;
1033510335
}
1033610336

10337+
static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
10338+
__u64 offset,
10339+
struct nvme_reachability_associations_log **logp)
10340+
{
10341+
int err;
10342+
struct nvme_reachability_associations_log *log = *logp;
10343+
__u16 i;
10344+
__u32 len;
10345+
10346+
for (i = 0; i < le16_to_cpu(log->nrad); i++) {
10347+
len = sizeof(*log->rad);
10348+
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10349+
if (err)
10350+
goto err_free;
10351+
len = le32_to_cpu(log->rad[i].nrid) * sizeof(*log->rad[i].rgid);
10352+
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10353+
if (err)
10354+
goto err_free;
10355+
}
10356+
10357+
*logp = log;
10358+
return 0;
10359+
10360+
err_free:
10361+
free(log);
10362+
*logp = NULL;
10363+
return err;
10364+
}
10365+
10366+
static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool rae,
10367+
struct nvme_reachability_associations_log **logp)
10368+
{
10369+
int err;
10370+
struct nvme_reachability_associations_log *log;
10371+
__u64 log_len = sizeof(*log);
10372+
struct nvme_get_log_args args = {
10373+
.args_size = sizeof(args),
10374+
.fd = dev_fd(dev),
10375+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10376+
.lid = NVME_LOG_LID_REACHABILITY_ASSOCIATIONS,
10377+
.nsid = NVME_NSID_ALL,
10378+
.lsp = rao,
10379+
.rae = rae,
10380+
};
10381+
10382+
log = nvme_alloc(log_len);
10383+
if (!log)
10384+
return -ENOMEM;
10385+
10386+
err = nvme_cli_get_log_reachability_associations(dev, rao, rae, log_len, log);
10387+
if (err)
10388+
goto err_free;
10389+
10390+
err = get_reachability_association_desc(dev, &args, log_len, &log);
10391+
if (err)
10392+
goto err_free;
10393+
10394+
*logp = log;
10395+
return 0;
10396+
10397+
err_free:
10398+
free(log);
10399+
return err;
10400+
}
10401+
10402+
static int get_reachability_associations_log(int argc, char **argv, struct command *cmd,
10403+
struct plugin *plugin)
10404+
{
10405+
const char *desc = "Retrieve Reachability Associations Log, show it";
10406+
const char *rao = "Return Associations Only";
10407+
nvme_print_flags_t flags;
10408+
int err;
10409+
10410+
_cleanup_free_ struct nvme_reachability_associations_log *log = NULL;
10411+
10412+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
10413+
10414+
struct config {
10415+
bool rao;
10416+
bool rae;
10417+
};
10418+
10419+
struct config cfg = {
10420+
.rao = false,
10421+
.rae = false,
10422+
};
10423+
10424+
NVME_ARGS(opts,
10425+
OPT_FLAG("associations-only", 'a', &cfg.rao, rao),
10426+
OPT_FLAG("rae", 'r', &cfg.rae, rae));
10427+
10428+
err = parse_and_open(&dev, argc, argv, desc, opts);
10429+
if (err)
10430+
return err;
10431+
10432+
err = validate_output_format(nvme_cfg.output_format, &flags);
10433+
if (err < 0) {
10434+
nvme_show_error("Invalid output format");
10435+
return err;
10436+
}
10437+
10438+
err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log);
10439+
if (!err)
10440+
nvme_show_reachability_associations_log(log, flags);
10441+
else if (err > 0)
10442+
nvme_show_status(err);
10443+
else
10444+
nvme_show_perror("reachability associations log");
10445+
10446+
return err;
10447+
}
10448+
1033710449
void register_extension(struct plugin *plugin)
1033810450
{
1033910451
plugin->parent = &nvme;

0 commit comments

Comments
 (0)