Skip to content

Commit 1571543

Browse files
ikegami-tigaw
authored andcommitted
nvme: add ave-discovery-log command
Since added the NVMe 2.1 log page. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent ef47838 commit 1571543

9 files changed

+219
-2
lines changed

nvme-builtin.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ COMMAND_LIST(
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)
6767
ENTRY("host-discovery-log", "Retrieve Host Discovery Log, show it", get_host_discovery_log)
68+
ENTRY("ave-discovery-log", "Retrieve AVE Discovery Log, show it", get_ave_discovery_log)
6869
ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
6970
ENTRY("set-property", "Set a property and show the resulting value", set_property)
7071
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
@@ -337,6 +337,11 @@ static void binary_host_discovery_log(struct nvme_host_discover_log *log)
337337
d_raw((unsigned char *)log, le32_to_cpu(log->thdlpl));
338338
}
339339

340+
static void binary_ave_discovery_log(struct nvme_ave_discover_log *log)
341+
{
342+
d_raw((unsigned char *)log, le32_to_cpu(log->tadlpl));
343+
}
344+
340345
static struct print_ops binary_print_ops = {
341346
/* libnvme types.h print functions */
342347
.ana_log = binary_ana_log,
@@ -409,6 +414,7 @@ static struct print_ops binary_print_ops = {
409414
.reachability_groups_log = binary_reachability_groups_log,
410415
.reachability_associations_log = binary_reachability_associations_log,
411416
.host_discovery_log = binary_host_discovery_log,
417+
.ave_discovery_log = binary_ave_discovery_log,
412418

413419
/* libnvme tree print functions */
414420
.list_item = NULL,

nvme-print-json.c

+63-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <assert.h>
44
#include <errno.h>
55
#include <time.h>
6-
6+
#include <sys/types.h>
7+
#include <sys/socket.h>
8+
#include <arpa/inet.h>
79
#include <ccan/ccan/compiler/compiler.h>
810

911
#include "nvme-print.h"
@@ -4820,6 +4822,65 @@ static void json_host_discovery_log(struct nvme_host_discover_log *log)
48204822
}
48214823
}
48224824

4825+
static void obj_add_traddr(struct json_object *o, const char *k, __u8 adrfam, __u8 *traddr)
4826+
{
4827+
int af = AF_INET;
4828+
socklen_t size = INET_ADDRSTRLEN;
4829+
char dst[INET6_ADDRSTRLEN];
4830+
4831+
if (adrfam == NVMF_ADDR_FAMILY_IP6) {
4832+
af = AF_INET6;
4833+
size = INET6_ADDRSTRLEN;
4834+
}
4835+
4836+
if (inet_ntop(af, nvmf_adrfam_str(adrfam), dst, size))
4837+
obj_add_str(o, k, dst);
4838+
}
4839+
4840+
static void json_ave_discovery_log(struct nvme_ave_discover_log *log)
4841+
{
4842+
struct json_object *r = json_create_object();
4843+
__u32 i;
4844+
__u8 j;
4845+
struct nvme_ave_discover_log_entry *adlpe;
4846+
struct nvme_ave_tr_record *atr;
4847+
__u32 tadlpl = le32_to_cpu(log->tadlpl);
4848+
__u32 tel;
4849+
__u8 numatr;
4850+
int n = 0;
4851+
char json_str[STR_LEN];
4852+
struct json_object *adlpe_o;
4853+
struct json_object *atr_o;
4854+
4855+
obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr));
4856+
obj_add_uint64(r, "numrec", le64_to_cpu(log->numrec));
4857+
obj_add_uint(r, "recfmt", le16_to_cpu(log->recfmt));
4858+
obj_add_uint(r, "thdlpl", tadlpl);
4859+
4860+
for (i = sizeof(*log); i < le32_to_cpu(log->tadlpl); i += tel) {
4861+
adlpe_o = json_create_object();
4862+
adlpe = (void *)log + i;
4863+
tel = le32_to_cpu(adlpe->tel);
4864+
numatr = adlpe->numatr;
4865+
obj_add_uint(adlpe_o, "tel", tel);
4866+
obj_add_str(adlpe_o, "avenqn", adlpe->avenqn);
4867+
obj_add_uint(adlpe_o, "numatr", numatr);
4868+
4869+
atr = adlpe->atr;
4870+
for (j = 0; j < numatr; j++) {
4871+
atr_o = json_create_object();
4872+
snprintf(json_str, sizeof(json_str), "atr: %d", j);
4873+
obj_add_str(atr_o, "aveadrfam", nvmf_adrfam_str(atr->aveadrfam));
4874+
obj_add_uint(atr_o, "avetrsvcid", le16_to_cpu(atr->avetrsvcid));
4875+
obj_add_traddr(atr_o, "avetraddr", atr->aveadrfam, atr->avetraddr);
4876+
obj_add_obj(adlpe_o, json_str, atr_o);
4877+
atr++;
4878+
}
4879+
snprintf(json_str, sizeof(json_str), "adlpe: %d", n++);
4880+
obj_add_obj(r, json_str, adlpe_o);
4881+
}
4882+
}
4883+
48234884
static struct print_ops json_print_ops = {
48244885
/* libnvme types.h print functions */
48254886
.ana_log = json_ana_log,
@@ -4893,6 +4954,7 @@ static struct print_ops json_print_ops = {
48934954
.reachability_groups_log = json_reachability_groups_log,
48944955
.reachability_associations_log = json_reachability_associations_log,
48954956
.host_discovery_log = json_host_discovery_log,
4957+
.ave_discovery_log = json_ave_discovery_log,
48964958

48974959
/* libnvme tree print functions */
48984960
.list_item = json_list_item,

nvme-print-stdout.c

+55-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include <stdlib.h>
77
#include <time.h>
88
#include <sys/stat.h>
9-
9+
#include <sys/types.h>
10+
#include <sys/socket.h>
11+
#include <arpa/inet.h>
1012
#include <ccan/ccan/strset/strset.h>
1113
#include <ccan/ccan/htable/htable_type.h>
1214
#include <ccan/ccan/htable/htable.h>
@@ -5759,6 +5761,57 @@ static void stdout_host_discovery_log(struct nvme_host_discover_log *log)
57595761
}
57605762
}
57615763

5764+
static void print_traddr(char *field, __u8 adrfam, __u8 *traddr)
5765+
{
5766+
int af = AF_INET;
5767+
socklen_t size = INET_ADDRSTRLEN;
5768+
char dst[INET6_ADDRSTRLEN];
5769+
5770+
if (adrfam == NVMF_ADDR_FAMILY_IP6) {
5771+
af = AF_INET6;
5772+
size = INET6_ADDRSTRLEN;
5773+
}
5774+
5775+
if (inet_ntop(af, nvmf_adrfam_str(adrfam), dst, size))
5776+
printf("%s: %s\n", field, dst);
5777+
}
5778+
5779+
static void stdout_ave_discovery_log(struct nvme_ave_discover_log *log)
5780+
{
5781+
__u32 i;
5782+
__u8 j;
5783+
struct nvme_ave_discover_log_entry *adlpe;
5784+
struct nvme_ave_tr_record *atr;
5785+
__u32 tadlpl = le32_to_cpu(log->tadlpl);
5786+
__u32 tel;
5787+
__u8 numatr;
5788+
int n = 0;
5789+
5790+
printf("genctr: %"PRIu64"\n", le64_to_cpu(log->genctr));
5791+
printf("numrec: %"PRIu64"\n", le64_to_cpu(log->numrec));
5792+
printf("recfmt: %u\n", le16_to_cpu(log->recfmt));
5793+
printf("tadlpl: %u\n", tadlpl);
5794+
5795+
for (i = sizeof(*log); i < le32_to_cpu(log->tadlpl); i += tel) {
5796+
printf("adlpe: %d\n", n++);
5797+
adlpe = (void *)log + i;
5798+
tel = le32_to_cpu(adlpe->tel);
5799+
numatr = adlpe->numatr;
5800+
printf("tel: %u\n", tel);
5801+
printf("avenqn: %s\n", adlpe->avenqn);
5802+
printf("numatr: %u\n", numatr);
5803+
5804+
atr = adlpe->atr;
5805+
for (j = 0; j < numatr; j++) {
5806+
printf("atr: %d\n", j);
5807+
printf("aveadrfam: %s\n", nvmf_adrfam_str(atr->aveadrfam));
5808+
printf("avetrsvcid: %u\n", le16_to_cpu(atr->avetrsvcid));
5809+
print_traddr("avetraddr", atr->aveadrfam, atr->avetraddr);
5810+
atr++;
5811+
}
5812+
}
5813+
}
5814+
57625815
static struct print_ops stdout_print_ops = {
57635816
/* libnvme types.h print functions */
57645817
.ana_log = stdout_ana_log,
@@ -5832,6 +5885,7 @@ static struct print_ops stdout_print_ops = {
58325885
.reachability_groups_log = stdout_reachability_groups_log,
58335886
.reachability_associations_log = stdout_reachability_associations_log,
58345887
.host_discovery_log = stdout_host_discovery_log,
5888+
.ave_discovery_log = stdout_ave_discovery_log,
58355889

58365890
/* libnvme tree print functions */
58375891
.list_item = stdout_list_item,

nvme-print.c

+5
Original file line numberDiff line numberDiff line change
@@ -1525,3 +1525,8 @@ void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print
15251525
{
15261526
nvme_print(host_discovery_log, flags, log);
15271527
}
1528+
1529+
void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_flags_t flags)
1530+
{
1531+
nvme_print(ave_discovery_log, flags, log);
1532+
}

nvme-print.h

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct print_ops {
9595
void (*reachability_associations_log)(struct nvme_reachability_associations_log *log,
9696
__u64 len);
9797
void (*host_discovery_log)(struct nvme_host_discover_log *log);
98+
void (*ave_discovery_log)(struct nvme_ave_discover_log *log);
9899

99100
/* libnvme tree print functions */
100101
void (*list_item)(nvme_ns_t n);
@@ -347,4 +348,5 @@ void nvme_show_reachability_groups_log(struct nvme_reachability_groups_log *log,
347348
void nvme_show_reachability_associations_log(struct nvme_reachability_associations_log *log,
348349
__u64 len, nvme_print_flags_t flags);
349350
void nvme_show_host_discovery_log(struct nvme_host_discover_log *log, nvme_print_flags_t flags);
351+
void nvme_show_ave_discovery_log(struct nvme_ave_discover_log *log, nvme_print_flags_t flags);
350352
#endif /* NVME_PRINT_H */

nvme-wrap.c

+6
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,9 @@ int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool ra
475475
{
476476
return do_admin_op(get_log_host_discover, dev, allhoste, rae, len, log);
477477
}
478+
479+
int nvme_cli_get_log_ave_discovery(struct nvme_dev *dev, bool rae, __u32 len,
480+
struct nvme_ave_discover_log *log)
481+
{
482+
return do_admin_op(get_log_ave_discover, dev, rae, len, log);
483+
}

nvme-wrap.h

+3
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,7 @@ int nvme_cli_get_log_reachability_associations(struct nvme_dev *dev, bool rgo, b
165165

166166
int nvme_cli_get_log_host_discovery(struct nvme_dev *dev, bool allhoste, bool rae, __u32 len,
167167
struct nvme_host_discover_log *log);
168+
169+
int nvme_cli_get_log_ave_discovery(struct nvme_dev *dev, bool rae, __u32 len,
170+
struct nvme_ave_discover_log *log);
168171
#endif /* _NVME_WRAP_H */

nvme.c

+78
Original file line numberDiff line numberDiff line change
@@ -10710,6 +10710,84 @@ static int get_host_discovery_log(int argc, char **argv, struct command *cmd, st
1071010710
return err;
1071110711
}
1071210712

10713+
static int get_ave_discovery(struct nvme_dev *dev, bool rae,
10714+
struct nvme_ave_discover_log **logp)
10715+
{
10716+
int err;
10717+
struct nvme_ave_discover_log *log;
10718+
__u64 log_len = sizeof(*log);
10719+
struct nvme_get_log_args args = {
10720+
.args_size = sizeof(args),
10721+
.fd = dev_fd(dev),
10722+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10723+
.lid = NVME_LOG_LID_HOST_DISCOVER,
10724+
.nsid = NVME_NSID_ALL,
10725+
.rae = rae,
10726+
};
10727+
10728+
log = nvme_alloc(log_len);
10729+
if (!log)
10730+
return -ENOMEM;
10731+
10732+
err = nvme_cli_get_log_ave_discovery(dev, rae, log_len, log);
10733+
if (err)
10734+
goto err_free;
10735+
10736+
log_len = le32_to_cpu(log->tadlpl);
10737+
err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->tadlpl) - log_len,
10738+
(void **)&log);
10739+
if (err)
10740+
goto err_free;
10741+
10742+
*logp = log;
10743+
return 0;
10744+
10745+
err_free:
10746+
free(log);
10747+
return err;
10748+
}
10749+
10750+
static int get_ave_discovery_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
10751+
{
10752+
const char *desc = "Retrieve AVE Discovery Log, show it";
10753+
nvme_print_flags_t flags;
10754+
int err;
10755+
10756+
_cleanup_free_ struct nvme_ave_discover_log *log = NULL;
10757+
10758+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
10759+
10760+
struct config {
10761+
bool rae;
10762+
};
10763+
10764+
struct config cfg = {
10765+
.rae = false,
10766+
};
10767+
10768+
NVME_ARGS(opts, OPT_FLAG("rae", 'r', &cfg.rae, rae));
10769+
10770+
err = parse_and_open(&dev, argc, argv, desc, opts);
10771+
if (err)
10772+
return err;
10773+
10774+
err = validate_output_format(nvme_cfg.output_format, &flags);
10775+
if (err < 0) {
10776+
nvme_show_error("Invalid output format");
10777+
return err;
10778+
}
10779+
10780+
err = get_ave_discovery(dev, cfg.rae, &log);
10781+
if (!err)
10782+
nvme_show_ave_discovery_log(log, flags);
10783+
else if (err > 0)
10784+
nvme_show_status(err);
10785+
else
10786+
nvme_show_perror("ave discovery log");
10787+
10788+
return err;
10789+
}
10790+
1071310791
void register_extension(struct plugin *plugin)
1071410792
{
1071510793
plugin->parent = &nvme;

0 commit comments

Comments
 (0)