Skip to content

Commit a65a601

Browse files
committed
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 944f8d3 commit a65a601

File tree

9 files changed

+191
-0
lines changed

9 files changed

+191
-0
lines changed

nvme-builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ COMMAND_LIST(
6060
ENTRY("supported-cap-config-log", "Retrieve the list of Supported Capacity Configuration Descriptors", get_supp_cap_config_log)
6161
ENTRY("mgmt-addr-list-log", "Retrieve Management Address List Log, show it", get_mgmt_addr_list_log)
6262
ENTRY("rotational-media-info-log", "Retrieve Rotational Media Information Log, show it", get_rotational_media_info_log)
63+
ENTRY("reachability-groups-log", "Retrieve Reachability Groups Log, show it", get_reachability_groups_log)
6364
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6465
ENTRY("set-property", "Set a property and show the resulting value", set_property)
6566
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
@@ -317,6 +317,11 @@ static void binary_rotational_media_info_log(struct nvme_rotational_media_info_l
317317
d_raw((unsigned char *)info, sizeof(*info));
318318
}
319319

320+
static void binary_reachability_groups_log(struct nvme_reachability_groups_log *log)
321+
{
322+
d_raw((unsigned char *)log, sizeof(*log));
323+
}
324+
320325
static struct print_ops binary_print_ops = {
321326
/* libnvme types.h print functions */
322327
.ana_log = binary_ana_log,
@@ -385,6 +390,7 @@ static struct print_ops binary_print_ops = {
385390
.show_finish = NULL,
386391
.mgmt_addr_list_log = binary_mgmt_addr_list_log,
387392
.rotational_media_info_log = binary_rotational_media_info_log,
393+
.reachability_groups_log = binary_reachability_groups_log,
388394

389395
/* libnvme tree print functions */
390396
.list_item = NULL,

nvme-print-json.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,6 +4655,30 @@ static void json_rotational_media_info_log(struct nvme_rotational_media_info_log
46554655
json_print(r);
46564656
}
46574657

4658+
static void json_reachability_groups_log(struct nvme_reachability_groups_log *log)
4659+
{
4660+
struct json_object *r = json_create_object();
4661+
__u16 i;
4662+
__u32 j;
4663+
char json_str[STR_LEN];
4664+
struct json_object *rgd;
4665+
4666+
obj_add_uint64(r, "chngc", le64_to_cpu(log->chngc));
4667+
obj_add_uint(r, "nrgd", le16_to_cpu(log->nrgd));
4668+
4669+
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
4670+
snprintf(json_str, sizeof(json_str), "rgid: %u", le32_to_cpu(log->rgd[i].rgid));
4671+
rgd = json_create_object();
4672+
obj_add_uint(rgd, "nnid", le32_to_cpu(log->rgd[i].nnid));
4673+
obj_add_uint64(rgd, "chngc", le64_to_cpu(log->rgd[i].chngc));
4674+
for (j = 0; j < le32_to_cpu(log->rgd[i].nnid); j++)
4675+
obj_add_uint(rgd, "nnid", le32_to_cpu(log->rgd[i].nsid[j]));
4676+
obj_add_obj(r, json_str, rgd);
4677+
}
4678+
4679+
json_print(r);
4680+
}
4681+
46584682
static struct print_ops json_print_ops = {
46594683
/* libnvme types.h print functions */
46604684
.ana_log = json_ana_log,
@@ -4724,6 +4748,7 @@ static struct print_ops json_print_ops = {
47244748
.show_finish = json_show_finish,
47254749
.mgmt_addr_list_log = json_mgmt_addr_list_log,
47264750
.rotational_media_info_log = json_rotational_media_info_log,
4751+
.reachability_groups_log = json_reachability_groups_log,
47274752

47284753
/* libnvme tree print functions */
47294754
.list_item = json_list_item,

nvme-print-stdout.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,6 +5604,23 @@ static void stdout_rotational_media_info_log(struct nvme_rotational_media_info_l
56045604
printf("fldc: %u\n", le32_to_cpu(info->fldc));
56055605
}
56065606

5607+
static void stdout_reachability_groups_log(struct nvme_reachability_groups_log *log)
5608+
{
5609+
__u16 i;
5610+
__u32 j;
5611+
5612+
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->chngc));
5613+
printf("nrgd: %u\n", le16_to_cpu(log->nrgd));
5614+
5615+
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
5616+
printf("rgid: %u\n", le32_to_cpu(log->rgd[i].rgid));
5617+
printf("nnid: %u\n", le32_to_cpu(log->rgd[i].nnid));
5618+
printf("chngc: %"PRIu64"\n", le64_to_cpu(log->rgd[i].chngc));
5619+
for (j = 0; j < le32_to_cpu(log->rgd[i].nnid); j++)
5620+
printf("nsid%u: %u\n", j, le32_to_cpu(log->rgd[i].nsid[j]));
5621+
}
5622+
}
5623+
56075624
static struct print_ops stdout_print_ops = {
56085625
/* libnvme types.h print functions */
56095626
.ana_log = stdout_ana_log,
@@ -5673,6 +5690,7 @@ static struct print_ops stdout_print_ops = {
56735690
.show_finish = NULL,
56745691
.mgmt_addr_list_log = stdout_mgmt_addr_list_log,
56755692
.rotational_media_info_log = stdout_rotational_media_info_log,
5693+
.reachability_groups_log = stdout_reachability_groups_log,
56765694

56775695
/* libnvme tree print functions */
56785696
.list_item = stdout_list_item,

nvme-print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,3 +1503,9 @@ void nvme_show_rotational_media_info_log(struct nvme_rotational_media_info_log *
15031503
{
15041504
nvme_print(rotational_media_info_log, flags, info);
15051505
}
1506+
1507+
void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
1508+
nvme_print_flags_t flags)
1509+
{
1510+
nvme_print(reachability_groups_log, flags, log);
1511+
}

nvme-print.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct print_ops {
9090
void (*show_finish)(void);
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);
93+
void (*reachability_groups_log)(struct nvme_reachability_groups_log *log);
9394

9495
/* libnvme tree print functions */
9596
void (*list_item)(nvme_ns_t n);
@@ -335,4 +336,6 @@ void nvme_show_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list,
335336
nvme_print_flags_t flags);
336337
void nvme_show_rotational_media_info_log(struct nvme_rotational_media_info_log *info,
337338
nvme_print_flags_t flags);
339+
void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
340+
nvme_print_flags_t flags);
338341
#endif /* NVME_PRINT_H */

nvme-wrap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,9 @@ int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, _
442442
{
443443
return do_admin_op(get_log_rotational_media_info, dev, endgid, len, info);
444444
}
445+
446+
int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
447+
struct nvme_reachability_groups_log *log)
448+
{
449+
return do_admin_op(get_log_reachability_groups, dev, len, rgo, rae, log);
450+
}

nvme-wrap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len,
152152
int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, __u32 len,
153153
struct nvme_rotational_media_info_log *info);
154154

155+
int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
156+
struct nvme_reachability_groups_log *log);
155157
#endif /* _NVME_WRAP_H */

nvme.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10144,6 +10144,130 @@ static int get_rotational_media_info_log(int argc, char **argv, struct command *
1014410144
return err;
1014510145
}
1014610146

10147+
static int get_log_offset(struct nvme_dev *dev, struct nvme_get_log_args *args, __u64 *offset,
10148+
__u32 len, void **log)
10149+
{
10150+
args->lpo = *offset,
10151+
args->log = *log + *offset,
10152+
args->len = len;
10153+
*offset += args->len;
10154+
*log = nvme_realloc(*log, *offset);
10155+
if (!*log)
10156+
return -ENOMEM;
10157+
return nvme_cli_get_log_page(dev, NVME_LOG_PAGE_PDU_SIZE, args);
10158+
}
10159+
10160+
static int get_reachability_group_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
10161+
__u64 offset, struct nvme_reachability_groups_log **logp)
10162+
{
10163+
int err;
10164+
struct nvme_reachability_groups_log *log = *logp;
10165+
__u16 i;
10166+
__u32 len;
10167+
10168+
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
10169+
len = sizeof(*log->rgd);
10170+
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10171+
if (err)
10172+
goto err_free;
10173+
len = le32_to_cpu(log->rgd[i].nnid) * sizeof(*log->rgd[i].nsid);
10174+
err = get_log_offset(dev, args, &offset, len, (void **)&log);
10175+
if (err)
10176+
goto err_free;
10177+
}
10178+
10179+
*logp = log;
10180+
return 0;
10181+
10182+
err_free:
10183+
free(log);
10184+
*logp = NULL;
10185+
return err;
10186+
}
10187+
10188+
static int get_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae,
10189+
struct nvme_reachability_groups_log **logp)
10190+
{
10191+
int err;
10192+
struct nvme_reachability_groups_log *log;
10193+
__u64 log_len = sizeof(*log);
10194+
struct nvme_get_log_args args = {
10195+
.args_size = sizeof(args),
10196+
.fd = dev_fd(dev),
10197+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10198+
.lid = NVME_LOG_LID_REACHABILITY_GROUPS,
10199+
.nsid = NVME_NSID_ALL,
10200+
.lsp = rgo,
10201+
.rae = rae,
10202+
};
10203+
10204+
log = nvme_alloc(log_len);
10205+
if (!log)
10206+
return -ENOMEM;
10207+
10208+
err = nvme_cli_get_log_reachability_groups(dev, rgo, rae, log_len, log);
10209+
if (err)
10210+
goto err_free;
10211+
10212+
err = get_reachability_group_desc(dev, &args, log_len, &log);
10213+
if (err)
10214+
goto err_free;
10215+
10216+
*logp = log;
10217+
return 0;
10218+
10219+
err_free:
10220+
free(log);
10221+
return err;
10222+
}
10223+
10224+
static int get_reachability_groups_log(int argc, char **argv, struct command *cmd,
10225+
struct plugin *plugin)
10226+
{
10227+
const char *desc = "Retrieve Reachability Groups Log, show it";
10228+
const char *rgo = "Return Groups Only";
10229+
nvme_print_flags_t flags;
10230+
int err;
10231+
10232+
_cleanup_free_ struct nvme_reachability_groups_log *log = NULL;
10233+
10234+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
10235+
10236+
struct config {
10237+
bool rgo;
10238+
bool rae;
10239+
};
10240+
10241+
struct config cfg = {
10242+
.rgo = false,
10243+
.rae = false,
10244+
};
10245+
10246+
NVME_ARGS(opts,
10247+
OPT_FLAG("groups-only", 'g', &cfg.rgo, rgo),
10248+
OPT_FLAG("rae", 'r', &cfg.rae, rae));
10249+
10250+
err = parse_and_open(&dev, argc, argv, desc, opts);
10251+
if (err)
10252+
return err;
10253+
10254+
err = validate_output_format(nvme_cfg.output_format, &flags);
10255+
if (err < 0) {
10256+
nvme_show_error("Invalid output format");
10257+
return err;
10258+
}
10259+
10260+
err = get_reachability_groups(dev, cfg.rgo, cfg.rae, &log);
10261+
if (!err)
10262+
nvme_show_reachability_groups_log(log, flags);
10263+
else if (err > 0)
10264+
nvme_show_status(err);
10265+
else
10266+
nvme_show_perror("rotational media info log");
10267+
10268+
return err;
10269+
}
10270+
1014710271
void register_extension(struct plugin *plugin)
1014810272
{
1014910273
plugin->parent = &nvme;

0 commit comments

Comments
 (0)