Skip to content

Commit 4053eff

Browse files
ikegami-tigaw
authored andcommitted
nvme: add reachability-groups-log command
Since added the NVMe 2.1 log page. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 724836d commit 4053eff

9 files changed

+191
-0
lines changed

nvme-builtin.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ COMMAND_LIST(
6262
ENTRY("rotational-media-info-log", "Retrieve Rotational Media Information Log, show it", get_rotational_media_info_log)
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)
65+
ENTRY("reachability-groups-log", "Retrieve Reachability Groups Log, show it", get_reachability_groups_log)
6566
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6667
ENTRY("set-property", "Set a property and show the resulting value", set_property)
6768
ENTRY("get-property", "Get a property and show the resulting value", get_property)

nvme-print-binary.c

+6
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ static void binary_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_
321321
d_raw((unsigned char *)log, sizeof(*log));
322322
}
323323

324+
static void binary_reachability_groups_log(struct nvme_reachability_groups_log *log)
325+
{
326+
d_raw((unsigned char *)log, sizeof(*log));
327+
}
328+
324329
static struct print_ops binary_print_ops = {
325330
/* libnvme types.h print functions */
326331
.ana_log = binary_ana_log,
@@ -390,6 +395,7 @@ static struct print_ops binary_print_ops = {
390395
.mgmt_addr_list_log = binary_mgmt_addr_list_log,
391396
.rotational_media_info_log = binary_rotational_media_info_log,
392397
.dispersed_ns_psub_log = binary_dispersed_ns_psub_log,
398+
.reachability_groups_log = binary_reachability_groups_log,
393399

394400
/* libnvme tree print functions */
395401
.list_item = NULL,

nvme-print-json.c

+25
Original file line numberDiff line numberDiff line change
@@ -4677,6 +4677,30 @@ static void json_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_ns
46774677
json_print(r);
46784678
}
46794679

4680+
static void json_reachability_groups_log(struct nvme_reachability_groups_log *log)
4681+
{
4682+
struct json_object *r = json_create_object();
4683+
__u16 i;
4684+
__u32 j;
4685+
char json_str[STR_LEN];
4686+
struct json_object *rgd;
4687+
4688+
obj_add_uint64(r, "chngc", le64_to_cpu(log->chngc));
4689+
obj_add_uint(r, "nrgd", le16_to_cpu(log->nrgd));
4690+
4691+
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
4692+
snprintf(json_str, sizeof(json_str), "rgid: %u", le32_to_cpu(log->rgd[i].rgid));
4693+
rgd = json_create_object();
4694+
obj_add_uint(rgd, "nnid", le32_to_cpu(log->rgd[i].nnid));
4695+
obj_add_uint64(rgd, "chngc", le64_to_cpu(log->rgd[i].chngc));
4696+
for (j = 0; j < le32_to_cpu(log->rgd[i].nnid); j++)
4697+
obj_add_uint(rgd, "nnid", le32_to_cpu(log->rgd[i].nsid[j]));
4698+
obj_add_obj(r, json_str, rgd);
4699+
}
4700+
4701+
json_print(r);
4702+
}
4703+
46804704
static struct print_ops json_print_ops = {
46814705
/* libnvme types.h print functions */
46824706
.ana_log = json_ana_log,
@@ -4747,6 +4771,7 @@ static struct print_ops json_print_ops = {
47474771
.mgmt_addr_list_log = json_mgmt_addr_list_log,
47484772
.rotational_media_info_log = json_rotational_media_info_log,
47494773
.dispersed_ns_psub_log = json_dispersed_ns_psub_log,
4774+
.reachability_groups_log = json_reachability_groups_log,
47504775

47514776
/* libnvme tree print functions */
47524777
.list_item = json_list_item,

nvme-print-stdout.c

+18
Original file line numberDiff line numberDiff line change
@@ -5638,6 +5638,23 @@ static void stdout_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_
56385638
&log->participating_nss[i * NVME_NQN_LENGTH]);
56395639
}
56405640

5641+
static void stdout_reachability_groups_log(struct nvme_reachability_groups_log *log)
5642+
{
5643+
__u16 i;
5644+
__u32 j;
5645+
5646+
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->chngc));
5647+
printf("nrgd: %u\n", le16_to_cpu(log->nrgd));
5648+
5649+
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
5650+
printf("rgid: %u\n", le32_to_cpu(log->rgd[i].rgid));
5651+
printf("nnid: %u\n", le32_to_cpu(log->rgd[i].nnid));
5652+
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->rgd[i].chngc));
5653+
for (j = 0; j < le32_to_cpu(log->rgd[i].nnid); j++)
5654+
printf("nsid%u: %u\n", j, le32_to_cpu(log->rgd[i].nsid[j]));
5655+
}
5656+
}
5657+
56415658
static struct print_ops stdout_print_ops = {
56425659
/* libnvme types.h print functions */
56435660
.ana_log = stdout_ana_log,
@@ -5708,6 +5725,7 @@ static struct print_ops stdout_print_ops = {
57085725
.mgmt_addr_list_log = stdout_mgmt_addr_list_log,
57095726
.rotational_media_info_log = stdout_rotational_media_info_log,
57105727
.dispersed_ns_psub_log = stdout_dispersed_ns_psub_log,
5728+
.reachability_groups_log = stdout_reachability_groups_log,
57115729

57125730
/* libnvme tree print functions */
57135731
.list_item = stdout_list_item,

nvme-print.c

+6
Original file line numberDiff line numberDiff line change
@@ -1508,3 +1508,9 @@ void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_
15081508
{
15091509
nvme_print(dispersed_ns_psub_log, flags, log);
15101510
}
1511+
1512+
void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
1513+
nvme_print_flags_t flags)
1514+
{
1515+
nvme_print(reachability_groups_log, flags, log);
1516+
}

nvme-print.h

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct print_ops {
9191
void (*mgmt_addr_list_log)(struct nvme_mgmt_addr_list_log *ma_log);
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);
94+
void (*reachability_groups_log)(struct nvme_reachability_groups_log *log);
9495

9596
/* libnvme tree print functions */
9697
void (*list_item)(nvme_ns_t n);
@@ -338,4 +339,6 @@ void nvme_show_rotational_media_info_log(struct nvme_rotational_media_info_log *
338339
nvme_print_flags_t flags);
339340
void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log,
340341
nvme_print_flags_t flags);
342+
void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
343+
nvme_print_flags_t flags);
341344
#endif /* NVME_PRINT_H */

nvme-wrap.c

+6
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,9 @@ int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32
457457
{
458458
return do_admin_op(get_log_dispersed_ns_participating_nss, dev, nsid, len, log);
459459
}
460+
461+
int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
462+
struct nvme_reachability_groups_log *log)
463+
{
464+
return do_admin_op(get_log_reachability_groups, dev, len, rgo, rae, log);
465+
}

nvme-wrap.h

+2
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,6 @@ int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, _
157157
int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32 nsid, __u32 len,
158158
struct nvme_dispersed_ns_participating_nss_log *log);
159159

160+
int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
161+
struct nvme_reachability_groups_log *log);
160162
#endif /* _NVME_WRAP_H */

nvme.c

+124
Original file line numberDiff line numberDiff line change
@@ -10256,6 +10256,130 @@ static int get_dispersed_ns_participating_nss_log(int argc, char **argv, struct
1025610256
return err;
1025710257
}
1025810258

10259+
static int get_log_offset(struct nvme_dev *dev, struct nvme_get_log_args *args, __u64 *offset,
10260+
__u32 len, void **log)
10261+
{
10262+
args->lpo = *offset,
10263+
args->log = *log + *offset,
10264+
args->len = len;
10265+
*offset += args->len;
10266+
*log = nvme_realloc(*log, *offset);
10267+
if (!*log)
10268+
return -ENOMEM;
10269+
return nvme_cli_get_log_page(dev, NVME_LOG_PAGE_PDU_SIZE, args);
10270+
}
10271+
10272+
static int get_reachability_group_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
10273+
__u64 offset, struct nvme_reachability_groups_log **logp)
10274+
{
10275+
int err;
10276+
struct nvme_reachability_groups_log *log = *logp;
10277+
__u16 i;
10278+
__u32 len;
10279+
10280+
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
10281+
len = sizeof(*log->rgd);
10282+
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10283+
if (err)
10284+
goto err_free;
10285+
len = le32_to_cpu(log->rgd[i].nnid) * sizeof(*log->rgd[i].nsid);
10286+
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10287+
if (err)
10288+
goto err_free;
10289+
}
10290+
10291+
*logp = log;
10292+
return 0;
10293+
10294+
err_free:
10295+
free(log);
10296+
*logp = NULL;
10297+
return err;
10298+
}
10299+
10300+
static int get_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae,
10301+
struct nvme_reachability_groups_log **logp)
10302+
{
10303+
int err;
10304+
struct nvme_reachability_groups_log *log;
10305+
__u64 log_len = sizeof(*log);
10306+
struct nvme_get_log_args args = {
10307+
.args_size = sizeof(args),
10308+
.fd = dev_fd(dev),
10309+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10310+
.lid = NVME_LOG_LID_REACHABILITY_GROUPS,
10311+
.nsid = NVME_NSID_ALL,
10312+
.lsp = rgo,
10313+
.rae = rae,
10314+
};
10315+
10316+
log = nvme_alloc(log_len);
10317+
if (!log)
10318+
return -ENOMEM;
10319+
10320+
err = nvme_cli_get_log_reachability_groups(dev, rgo, rae, log_len, log);
10321+
if (err)
10322+
goto err_free;
10323+
10324+
err = get_reachability_group_desc(dev, &args, log_len, &log);
10325+
if (err)
10326+
goto err_free;
10327+
10328+
*logp = log;
10329+
return 0;
10330+
10331+
err_free:
10332+
free(log);
10333+
return err;
10334+
}
10335+
10336+
static int get_reachability_groups_log(int argc, char **argv, struct command *cmd,
10337+
struct plugin *plugin)
10338+
{
10339+
const char *desc = "Retrieve Reachability Groups Log, show it";
10340+
const char *rgo = "Return Groups Only";
10341+
nvme_print_flags_t flags;
10342+
int err;
10343+
10344+
_cleanup_free_ struct nvme_reachability_groups_log *log = NULL;
10345+
10346+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
10347+
10348+
struct config {
10349+
bool rgo;
10350+
bool rae;
10351+
};
10352+
10353+
struct config cfg = {
10354+
.rgo = false,
10355+
.rae = false,
10356+
};
10357+
10358+
NVME_ARGS(opts,
10359+
OPT_FLAG("groups-only", 'g', &cfg.rgo, rgo),
10360+
OPT_FLAG("rae", 'r', &cfg.rae, rae));
10361+
10362+
err = parse_and_open(&dev, argc, argv, desc, opts);
10363+
if (err)
10364+
return err;
10365+
10366+
err = validate_output_format(nvme_cfg.output_format, &flags);
10367+
if (err < 0) {
10368+
nvme_show_error("Invalid output format");
10369+
return err;
10370+
}
10371+
10372+
err = get_reachability_groups(dev, cfg.rgo, cfg.rae, &log);
10373+
if (!err)
10374+
nvme_show_reachability_groups_log(log, flags);
10375+
else if (err > 0)
10376+
nvme_show_status(err);
10377+
else
10378+
nvme_show_perror("rotational media info log");
10379+
10380+
return err;
10381+
}
10382+
1025910383
void register_extension(struct plugin *plugin)
1026010384
{
1026110385
plugin->parent = &nvme;

0 commit comments

Comments
 (0)