|
3 | 3 | #include <assert.h>
|
4 | 4 | #include <errno.h>
|
5 | 5 | #include <time.h>
|
6 |
| - |
| 6 | +#include <sys/types.h> |
| 7 | +#include <sys/socket.h> |
| 8 | +#include <arpa/inet.h> |
7 | 9 | #include <ccan/ccan/compiler/compiler.h>
|
8 | 10 |
|
9 | 11 | #include "nvme-print.h"
|
@@ -4820,6 +4822,65 @@ static void json_host_discovery_log(struct nvme_host_discover_log *log)
|
4820 | 4822 | }
|
4821 | 4823 | }
|
4822 | 4824 |
|
| 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 | + |
4823 | 4884 | static struct print_ops json_print_ops = {
|
4824 | 4885 | /* libnvme types.h print functions */
|
4825 | 4886 | .ana_log = json_ana_log,
|
@@ -4893,6 +4954,7 @@ static struct print_ops json_print_ops = {
|
4893 | 4954 | .reachability_groups_log = json_reachability_groups_log,
|
4894 | 4955 | .reachability_associations_log = json_reachability_associations_log,
|
4895 | 4956 | .host_discovery_log = json_host_discovery_log,
|
| 4957 | + .ave_discovery_log = json_ave_discovery_log, |
4896 | 4958 |
|
4897 | 4959 | /* libnvme tree print functions */
|
4898 | 4960 | .list_item = json_list_item,
|
|
0 commit comments