Skip to content

Commit 6dba527

Browse files
ikegami-tigaw
authored andcommitted
nvme: add dispersed-ns-participating-nss-log command
Since added the NVMe 2.1 log page. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 3711526 commit 6dba527

9 files changed

Lines changed: 147 additions & 0 deletions

nvme-builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ COMMAND_LIST(
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)
6363
ENTRY("changed-alloc-ns-list-log", "Retrieve Changed Allocated Namespace List, show it", get_changed_alloc_ns_list_log)
64+
ENTRY("dispersed-ns-participating-nss-log", "Retrieve Dispersed Namespace Participating NVM Subsystems Log, show it", get_dispersed_ns_participating_nss_log)
6465
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6566
ENTRY("set-property", "Set a property and show the resulting value", set_property)
6667
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
@@ -316,6 +316,11 @@ static void binary_rotational_media_info_log(struct nvme_rotational_media_info_l
316316
d_raw((unsigned char *)info, sizeof(*info));
317317
}
318318

319+
static void binary_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
320+
{
321+
d_raw((unsigned char *)log, sizeof(*log));
322+
}
323+
319324
static struct print_ops binary_print_ops = {
320325
/* libnvme types.h print functions */
321326
.ana_log = binary_ana_log,
@@ -384,6 +389,7 @@ static struct print_ops binary_print_ops = {
384389
.show_finish = NULL,
385390
.mgmt_addr_list_log = binary_mgmt_addr_list_log,
386391
.rotational_media_info_log = binary_rotational_media_info_log,
392+
.dispersed_ns_psub_log = binary_dispersed_ns_psub_log,
387393

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

nvme-print-json.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,6 +4657,26 @@ static void json_rotational_media_info_log(struct nvme_rotational_media_info_log
46574657
json_print(r);
46584658
}
46594659

4660+
static void json_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
4661+
{
4662+
struct json_object *r = json_create_object();
4663+
__u64 numpsub = le64_to_cpu(log->numpsub);
4664+
__u64 i;
4665+
char json_str[STR_LEN];
4666+
char psub[NVME_NQN_LENGTH + 1];
4667+
4668+
obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr));
4669+
obj_add_uint64(r, "numpsub", numpsub);
4670+
for (i = 0; i < numpsub; i++) {
4671+
snprintf(json_str, sizeof(json_str), "participating_nss %"PRIu64"", (uint64_t)i);
4672+
snprintf(psub, sizeof(psub), "%-.*s", NVME_NQN_LENGTH,
4673+
&log->participating_nss[i * NVME_NQN_LENGTH]);
4674+
obj_add_str(r, json_str, psub);
4675+
}
4676+
4677+
json_print(r);
4678+
}
4679+
46604680
static struct print_ops json_print_ops = {
46614681
/* libnvme types.h print functions */
46624682
.ana_log = json_ana_log,
@@ -4726,6 +4746,7 @@ static struct print_ops json_print_ops = {
47264746
.show_finish = json_show_finish,
47274747
.mgmt_addr_list_log = json_mgmt_addr_list_log,
47284748
.rotational_media_info_log = json_rotational_media_info_log,
4749+
.dispersed_ns_psub_log = json_dispersed_ns_psub_log,
47294750

47304751
/* libnvme tree print functions */
47314752
.list_item = json_list_item,

nvme-print-stdout.c

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

5606+
static void stdout_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
5607+
{
5608+
__u64 numpsub = le64_to_cpu(log->numpsub);
5609+
__u64 i;
5610+
5611+
printf("genctr: %"PRIu64"\n", le64_to_cpu(log->genctr));
5612+
printf("numpsub: %"PRIu64"\n", (uint64_t)numpsub);
5613+
for (i = 0; i < numpsub; i++)
5614+
printf("participating_nss %"PRIu64": %-.*s\n", (uint64_t)i, NVME_NQN_LENGTH,
5615+
&log->participating_nss[i * NVME_NQN_LENGTH]);
5616+
}
5617+
56065618
static struct print_ops stdout_print_ops = {
56075619
/* libnvme types.h print functions */
56085620
.ana_log = stdout_ana_log,
@@ -5672,6 +5684,7 @@ static struct print_ops stdout_print_ops = {
56725684
.show_finish = NULL,
56735685
.mgmt_addr_list_log = stdout_mgmt_addr_list_log,
56745686
.rotational_media_info_log = stdout_rotational_media_info_log,
5687+
.dispersed_ns_psub_log = stdout_dispersed_ns_psub_log,
56755688

56765689
/* libnvme tree print functions */
56775690
.list_item = stdout_list_item,

nvme-print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,3 +1502,9 @@ void nvme_show_rotational_media_info_log(struct nvme_rotational_media_info_log *
15021502
{
15031503
nvme_print(rotational_media_info_log, flags, info);
15041504
}
1505+
1506+
void nvme_show_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log,
1507+
nvme_print_flags_t flags)
1508+
{
1509+
nvme_print(dispersed_ns_psub_log, flags, log);
1510+
}

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 (*dispersed_ns_psub_log)(struct nvme_dispersed_ns_participating_nss_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_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_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
@@ -451,3 +451,9 @@ int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, _
451451

452452
return -ENODEV;
453453
}
454+
455+
int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32 nsid, __u32 len,
456+
struct nvme_dispersed_ns_participating_nss_log *log)
457+
{
458+
return do_admin_op(get_log_dispersed_ns_participating_nss, dev, nsid, len, log);
459+
}

nvme-wrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,7 @@ int nvme_cli_get_log_mgmt_addr_list(struct nvme_dev *dev, __u32 len,
154154
int nvme_cli_get_log_rotational_media_info(struct nvme_dev *dev, __u16 endgid, __u32 len,
155155
struct nvme_rotational_media_info_log *info);
156156

157+
int nvme_cli_get_log_dispersed_ns_participating_nss(struct nvme_dev *dev, __u32 nsid, __u32 len,
158+
struct nvme_dispersed_ns_participating_nss_log *log);
159+
157160
#endif /* _NVME_WRAP_H */

nvme.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10165,6 +10165,94 @@ static int get_rotational_media_info_log(int argc, char **argv, struct command *
1016510165
return err;
1016610166
}
1016710167

10168+
static int get_dispersed_ns_psub(struct nvme_dev *dev, __u32 nsid,
10169+
struct nvme_dispersed_ns_participating_nss_log **logp)
10170+
{
10171+
int err;
10172+
__u64 header_len = sizeof(**logp);
10173+
__u64 psub_list_len;
10174+
struct nvme_get_log_args args = {
10175+
.args_size = sizeof(args),
10176+
.fd = dev_fd(dev),
10177+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10178+
.lid = NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS,
10179+
.nsid = nsid,
10180+
.lpo = header_len,
10181+
};
10182+
struct nvme_dispersed_ns_participating_nss_log *log = nvme_alloc(header_len);
10183+
10184+
if (!log)
10185+
return -ENOMEM;
10186+
10187+
err = nvme_cli_get_log_dispersed_ns_participating_nss(dev, nsid, header_len, log);
10188+
if (err)
10189+
goto err_free;
10190+
10191+
psub_list_len = le64_to_cpu(log->numpsub) * NVME_NQN_LENGTH;
10192+
10193+
log = nvme_realloc(log, header_len + psub_list_len);
10194+
if (!log) {
10195+
err = -ENOMEM;
10196+
goto err_free;
10197+
}
10198+
10199+
args.log = log->participating_nss,
10200+
args.len = psub_list_len;
10201+
10202+
err = nvme_cli_get_log_page(dev, NVME_LOG_PAGE_PDU_SIZE, &args);
10203+
if (err)
10204+
goto err_free;
10205+
10206+
*logp = log;
10207+
return 0;
10208+
10209+
err_free:
10210+
free(log);
10211+
return err;
10212+
}
10213+
10214+
static int get_dispersed_ns_participating_nss_log(int argc, char **argv, struct command *cmd,
10215+
struct plugin *plugin)
10216+
{
10217+
const char *desc = "Retrieve Dispersed Namespace Participating NVM Subsystems Log, show it";
10218+
nvme_print_flags_t flags;
10219+
int err;
10220+
10221+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
10222+
10223+
_cleanup_free_ struct nvme_dispersed_ns_participating_nss_log *log = NULL;
10224+
10225+
struct config {
10226+
__u32 namespace_id;
10227+
};
10228+
10229+
struct config cfg = {
10230+
.namespace_id = 1,
10231+
};
10232+
10233+
NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired));
10234+
10235+
err = parse_and_open(&dev, argc, argv, desc, opts);
10236+
if (err)
10237+
return err;
10238+
10239+
err = validate_output_format(nvme_cfg.output_format, &flags);
10240+
if (err < 0) {
10241+
nvme_show_error("Invalid output format");
10242+
return err;
10243+
}
10244+
10245+
err = get_dispersed_ns_psub(dev, cfg.namespace_id, &log);
10246+
if (!err)
10247+
nvme_show_dispersed_ns_psub_log(log, flags);
10248+
else if (err > 0)
10249+
nvme_show_status(err);
10250+
else
10251+
nvme_show_perror("dispersed ns participating nss log");
10252+
10253+
return err;
10254+
}
10255+
1016810256
void register_extension(struct plugin *plugin)
1016910257
{
1017010258
plugin->parent = &nvme;

0 commit comments

Comments
 (0)