Skip to content

Commit a78d4e3

Browse files
committed
nvme: add host-discovery-log command
Since added the NVMe 2.1 log page. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 3e512dd commit a78d4e3

File tree

9 files changed

+238
-0
lines changed

9 files changed

+238
-0
lines changed

nvme-builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ COMMAND_LIST(
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)
6666
ENTRY("reachability-associations-log", "Retrieve Reachability Associations Log, show it", get_reachability_associations_log)
67+
ENTRY("host-discovery-log", "Retrieve Host Discovery Log, show it", get_host_discovery_log)
6768
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6869
ENTRY("set-property", "Set a property and show the resulting value", set_property)
6970
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
@@ -332,6 +332,11 @@ static void binary_reachability_associations_log(struct nvme_reachability_associ
332332
d_raw((unsigned char *)log, len);
333333
}
334334

335+
static void binary_host_discovery_log(struct nvme_host_discover_log *log)
336+
{
337+
d_raw((unsigned char *)log, le32_to_cpu(log->thdlpl));
338+
}
339+
335340
static struct print_ops binary_print_ops = {
336341
/* libnvme types.h print functions */
337342
.ana_log = binary_ana_log,
@@ -403,6 +408,7 @@ static struct print_ops binary_print_ops = {
403408
.dispersed_ns_psub_log = binary_dispersed_ns_psub_log,
404409
.reachability_groups_log = binary_reachability_groups_log,
405410
.reachability_associations_log = binary_reachability_associations_log,
411+
.host_discovery_log = binary_host_discovery_log,
406412

407413
/* libnvme tree print functions */
408414
.list_item = NULL,

nvme-print-json.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4734,6 +4734,76 @@ static void json_reachability_associations_log(struct nvme_reachability_associat
47344734
json_print(r);
47354735
}
47364736

4737+
static void json_host_discovery_log(struct nvme_host_discover_log *log)
4738+
{
4739+
struct json_object *r = json_create_object();
4740+
__u32 i;
4741+
__u16 j;
4742+
struct nvme_host_ext_discover_log *hedlpe;
4743+
struct nvmf_ext_attr *exat;
4744+
__u32 thdlpl = le32_to_cpu(log->thdlpl);
4745+
__u32 tel;
4746+
__u16 numexat;
4747+
char json_str[STR_LEN];
4748+
struct json_object *hedlpe_o;
4749+
struct json_object *tsas_o;
4750+
struct json_object *exat_o;
4751+
int n = 0;
4752+
4753+
obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr));
4754+
obj_add_uint64(r, "numrec", le64_to_cpu(log->numrec));
4755+
obj_add_uint(r, "recfmt", le16_to_cpu(log->recfmt));
4756+
obj_add_uint_02x(r, "hdlpf", log->hdlpf);
4757+
obj_add_uint(r, "thdlpl", thdlpl);
4758+
4759+
for (i = sizeof(*log); i < le32_to_cpu(log->thdlpl); i += tel) {
4760+
hedlpe_o = json_create_object();
4761+
hedlpe = (void *)log + i;
4762+
tel = le32_to_cpu(hedlpe->tel);
4763+
numexat = le16_to_cpu(hedlpe->numexat);
4764+
obj_add_str(hedlpe_o, "trtype", nvmf_trtype_str(hedlpe->trtype));
4765+
obj_add_str(hedlpe_o, "adrfam",
4766+
strlen(hedlpe->traddr) ? nvmf_adrfam_str(hedlpe->adrfam) : "");
4767+
obj_add_str(hedlpe_o, "eflags", nvmf_eflags_str(le16_to_cpu(hedlpe->eflags)));
4768+
obj_add_str(hedlpe_o, "hostnqn", hedlpe->hostnqn);
4769+
obj_add_str(hedlpe_o, "traddr", hedlpe->traddr);
4770+
tsas_o = json_create_object();
4771+
switch (hedlpe->trtype) {
4772+
case NVMF_TRTYPE_RDMA:
4773+
obj_add_str(tsas_o, "prtype", nvmf_prtype_str(hedlpe->tsas.rdma.prtype));
4774+
obj_add_str(tsas_o, "qptype", nvmf_qptype_str(hedlpe->tsas.rdma.qptype));
4775+
obj_add_str(tsas_o, "cms", nvmf_cms_str(hedlpe->tsas.rdma.cms));
4776+
obj_add_uint_0nx(tsas_o, "pkey", le16_to_cpu(hedlpe->tsas.rdma.pkey), 4);
4777+
break;
4778+
case NVMF_TRTYPE_TCP:
4779+
obj_add_str(tsas_o, "sectype", nvmf_sectype_str(hedlpe->tsas.tcp.sectype));
4780+
break;
4781+
default:
4782+
obj_d(tsas_o, "common", (unsigned char *)hedlpe->tsas.common,
4783+
sizeof(hedlpe->tsas.common), 16, 1);
4784+
break;
4785+
}
4786+
obj_add_obj(hedlpe_o, "tsas", tsas_o);
4787+
obj_add_uint(hedlpe_o, "tel", tel);
4788+
obj_add_uint(hedlpe_o, "numexat", numexat);
4789+
4790+
exat = hedlpe->exat;
4791+
for (j = 0; j < numexat; j++) {
4792+
exat_o = json_create_object();
4793+
snprintf(json_str, sizeof(json_str), "exat: %d", j);
4794+
obj_add_uint(exat_o, "exattype", le16_to_cpu(exat->exattype));
4795+
obj_add_uint(exat_o, "exatlen", le16_to_cpu(exat->exatlen));
4796+
printf(":\n");
4797+
obj_d(exat_o, "exatval", (unsigned char *)exat->exatval,
4798+
le16_to_cpu(exat->exatlen), 16, 1);
4799+
obj_add_obj(hedlpe_o, json_str, exat_o);
4800+
exat = nvmf_exat_ptr_next(exat);
4801+
}
4802+
snprintf(json_str, sizeof(json_str), "hedlpe: %d", n++);
4803+
obj_add_obj(r, json_str, hedlpe_o);
4804+
}
4805+
}
4806+
47374807
static struct print_ops json_print_ops = {
47384808
/* libnvme types.h print functions */
47394809
.ana_log = json_ana_log,
@@ -4806,6 +4876,7 @@ static struct print_ops json_print_ops = {
48064876
.dispersed_ns_psub_log = json_dispersed_ns_psub_log,
48074877
.reachability_groups_log = json_reachability_groups_log,
48084878
.reachability_associations_log = json_reachability_associations_log,
4879+
.host_discovery_log = json_host_discovery_log,
48094880

48104881
/* libnvme tree print functions */
48114882
.list_item = json_list_item,

nvme-print-stdout.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,6 +5695,66 @@ static void stdout_reachability_associations_log(struct nvme_reachability_associ
56955695
}
56965696
}
56975697

5698+
static void stdout_host_discovery_log(struct nvme_host_discover_log *log)
5699+
{
5700+
__u32 i;
5701+
__u16 j;
5702+
struct nvme_host_ext_discover_log *hedlpe;
5703+
struct nvmf_ext_attr *exat;
5704+
__u32 thdlpl = le32_to_cpu(log->thdlpl);
5705+
__u32 tel;
5706+
__u16 numexat;
5707+
int n = 0;
5708+
5709+
printf("genctr: %"PRIu64"\n", le64_to_cpu(log->genctr));
5710+
printf("numrec: %"PRIu64"\n", le64_to_cpu(log->numrec));
5711+
printf("recfmt: %u\n", le16_to_cpu(log->recfmt));
5712+
printf("hdlpf: %02x\n", log->hdlpf);
5713+
printf("thdlpl: %u\n", thdlpl);
5714+
5715+
for (i = sizeof(*log); i < le32_to_cpu(log->thdlpl); i += tel) {
5716+
printf("hedlpe: %d\n", n++);
5717+
hedlpe = (void *)log + i;
5718+
tel = le32_to_cpu(hedlpe->tel);
5719+
numexat = le16_to_cpu(hedlpe->numexat);
5720+
printf("trtype: %s\n", nvmf_trtype_str(hedlpe->trtype));
5721+
printf("adrfam: %s\n",
5722+
strlen(hedlpe->traddr) ? nvmf_adrfam_str(hedlpe->adrfam) : "");
5723+
printf("eflags: %s\n", nvmf_eflags_str(le16_to_cpu(hedlpe->eflags)));
5724+
printf("hostnqn: %s\n", hedlpe->hostnqn);
5725+
printf("traddr: %s\n", hedlpe->traddr);
5726+
printf("tsas: ");
5727+
switch (hedlpe->trtype) {
5728+
case NVMF_TRTYPE_RDMA:
5729+
printf("prtype: %s, qptype: %s, cms: %s, pkey: 0x%04x\n",
5730+
nvmf_prtype_str(hedlpe->tsas.rdma.prtype),
5731+
nvmf_qptype_str(hedlpe->tsas.rdma.qptype),
5732+
nvmf_cms_str(hedlpe->tsas.rdma.cms),
5733+
le16_to_cpu(hedlpe->tsas.rdma.pkey));
5734+
break;
5735+
case NVMF_TRTYPE_TCP:
5736+
printf("sectype: %s\n", nvmf_sectype_str(hedlpe->tsas.tcp.sectype));
5737+
break;
5738+
default:
5739+
printf("common:\n");
5740+
d((unsigned char *)hedlpe->tsas.common, sizeof(hedlpe->tsas.common), 16, 1);
5741+
break;
5742+
}
5743+
printf("tel: %u\n", tel);
5744+
printf("numexat: %u\n", numexat);
5745+
5746+
exat = hedlpe->exat;
5747+
for (j = 0; j < numexat; j++) {
5748+
printf("exat: %d\n", j);
5749+
printf("exattype: %u\n", le16_to_cpu(exat->exattype));
5750+
printf("exatlen: %u\n", le16_to_cpu(exat->exatlen));
5751+
printf("exatval:\n");
5752+
d((unsigned char *)exat->exatval, le16_to_cpu(exat->exatlen), 16, 1);
5753+
exat = nvmf_exat_ptr_next(exat);
5754+
}
5755+
}
5756+
}
5757+
56985758
static struct print_ops stdout_print_ops = {
56995759
/* libnvme types.h print functions */
57005760
.ana_log = stdout_ana_log,
@@ -5767,6 +5827,7 @@ static struct print_ops stdout_print_ops = {
57675827
.dispersed_ns_psub_log = stdout_dispersed_ns_psub_log,
57685828
.reachability_groups_log = stdout_reachability_groups_log,
57695829
.reachability_associations_log = stdout_reachability_associations_log,
5830+
.host_discovery_log = stdout_host_discovery_log,
57705831

57715832
/* libnvme tree print functions */
57725833
.list_item = stdout_list_item,

nvme-print.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,3 +1520,8 @@ void nvme_show_reachability_associations_log(struct nvme_reachability_associatio
15201520
{
15211521
nvme_print(reachability_associations_log, flags, log, len);
15221522
}
1523+
1524+
void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print_flags_t flags)
1525+
{
1526+
nvme_print(host_discovery_log, flags, log);
1527+
}

nvme-print.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct print_ops {
9494
void (*reachability_groups_log)(struct nvme_reachability_groups_log *log, __u64 len);
9595
void (*reachability_associations_log)(struct nvme_reachability_associations_log *log,
9696
__u64 len);
97+
void (*host_discovery_log)(struct nvme_host_discover_log *log);
9798

9899
/* libnvme tree print functions */
99100
void (*list_item)(nvme_ns_t n);
@@ -345,4 +346,5 @@ void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
345346
__u64 len, nvme_print_flags_t flags);
346347
void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
347348
__u64 len, nvme_print_flags_t flags);
349+
void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print_flags_t flags);
348350
#endif /* NVME_PRINT_H */

nvme-wrap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,9 @@ int nvme_cli_get_log_reachability_associations(struct nvme_dev *dev, bool rao, b
469469
{
470470
return do_admin_op(get_log_reachability_associations, dev, rao, rae, len, log);
471471
}
472+
473+
int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool rae, __u32 len,
474+
struct nvme_host_discover_log *log)
475+
{
476+
return do_admin_op(get_log_host_discover, dev, allhoste, rae, len, log);
477+
}

nvme-wrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,7 @@ int nvme_cli_get_log_reachability_groups(struct nvme_dev *dev, bool rgo, bool ra
162162

163163
int nvme_cli_get_log_reachability_associations(struct nvme_dev *dev, bool rgo, bool rae, __u32 len,
164164
struct nvme_reachability_associations_log *log);
165+
166+
int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool rae, __u32 len,
167+
struct nvme_host_discover_log *log);
165168
#endif /* _NVME_WRAP_H */

nvme.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10618,6 +10618,89 @@ static int get_reachability_associations_log(int argc, char **argv, struct comma
1061810618
return err;
1061910619
}
1062010620

10621+
static int get_host_discovery(struct nvme_dev *dev, bool allhoste, bool rae,
10622+
struct nvme_host_discover_log **logp)
10623+
{
10624+
int err;
10625+
struct nvme_host_discover_log *log;
10626+
__u64 log_len = sizeof(*log);
10627+
struct nvme_get_log_args args = {
10628+
.args_size = sizeof(args),
10629+
.fd = dev_fd(dev),
10630+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10631+
.lid = NVME_LOG_LID_HOST_DISCOVER,
10632+
.nsid = NVME_NSID_ALL,
10633+
.lsp = allhoste,
10634+
.rae = rae,
10635+
};
10636+
10637+
log = nvme_alloc(log_len);
10638+
if (!log)
10639+
return -ENOMEM;
10640+
10641+
err = nvme_cli_get_log_host_discovery(dev, allhoste, rae, log_len, log);
10642+
if (err)
10643+
goto err_free;
10644+
10645+
log_len = le32_to_cpu(log->thdlpl);
10646+
err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->thdlpl) - log_len, (void **)&log);
10647+
if (err)
10648+
goto err_free;
10649+
10650+
*logp = log;
10651+
return 0;
10652+
10653+
err_free:
10654+
free(log);
10655+
return err;
10656+
}
10657+
10658+
static int get_host_discovery_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
10659+
{
10660+
const char *desc = "Retrieve Host Discovery Log, show it";
10661+
const char *allhoste = "All Host Entries";
10662+
nvme_print_flags_t flags;
10663+
int err;
10664+
10665+
_cleanup_free_ struct nvme_host_discover_log *log = NULL;
10666+
10667+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
10668+
10669+
struct config {
10670+
bool allhoste;
10671+
bool rae;
10672+
};
10673+
10674+
struct config cfg = {
10675+
.allhoste = false,
10676+
.rae = false,
10677+
};
10678+
10679+
NVME_ARGS(opts,
10680+
OPT_FLAG("all-host-entries", 'a', &cfg.allhoste, allhoste),
10681+
OPT_FLAG("rae", 'r', &cfg.rae, rae));
10682+
10683+
err = parse_and_open(&dev, argc, argv, desc, opts);
10684+
if (err)
10685+
return err;
10686+
10687+
err = validate_output_format(nvme_cfg.output_format, &flags);
10688+
if (err < 0) {
10689+
nvme_show_error("Invalid output format");
10690+
return err;
10691+
}
10692+
10693+
err = get_host_discovery(dev, cfg.allhoste, cfg.rae, &log);
10694+
if (!err)
10695+
nvme_show_host_discovery_log(log, flags);
10696+
else if (err > 0)
10697+
nvme_show_status(err);
10698+
else
10699+
nvme_show_perror("host discovery log");
10700+
10701+
return err;
10702+
}
10703+
1062110704
void register_extension(struct plugin *plugin)
1062210705
{
1062310706
plugin->parent = &nvme;

0 commit comments

Comments
 (0)