1
2
3
4
5
6
7#include "res.h"
8#include <inttypes.h>
9
10static int res_mr_line_raw(struct rd *rd, const char *name, int idx,
11 struct nlattr **nla_line)
12{
13 if (!nla_line[RDMA_NLDEV_ATTR_RES_RAW])
14 return MNL_CB_ERROR;
15
16 open_json_object(NULL);
17 print_dev(rd, idx, name);
18 print_raw_data(rd, nla_line);
19 newline(rd);
20
21 return MNL_CB_OK;
22}
23
24static int res_mr_line(struct rd *rd, const char *name, int idx,
25 struct nlattr **nla_line)
26{
27 uint32_t rkey = 0, lkey = 0;
28 uint64_t iova = 0, mrlen;
29 char *comm = NULL;
30 uint32_t pdn = 0;
31 uint32_t mrn = 0;
32 uint32_t pid = 0;
33
34 if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN])
35 return MNL_CB_ERROR;
36
37 if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
38 rkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
39 if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
40 lkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
41 if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
42 iova = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
43
44 mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
45 if (rd_is_filtered_attr(rd, "mrlen", mrlen,
46 nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]))
47 goto out;
48
49 if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
50 pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
51 comm = get_task_name(pid);
52 }
53
54 if (rd_is_filtered_attr(rd, "pid", pid,
55 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
56 goto out;
57
58 if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
59 mrn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
60 if (rd_is_filtered_attr(rd, "mrn", mrn,
61 nla_line[RDMA_NLDEV_ATTR_RES_MRN]))
62 goto out;
63
64 if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
65 pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
66 if (rd_is_filtered_attr(rd, "pdn", pdn,
67 nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
68 goto out;
69
70 if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
71
72 comm = (char *)mnl_attr_get_str(
73 nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
74 open_json_object(NULL);
75 print_dev(rd, idx, name);
76 res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
77 print_key(rd, "rkey", rkey, nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
78 print_key(rd, "lkey", lkey, nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
79 print_key(rd, "iova", iova, nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
80 res_print_uint(rd, "mrlen", mrlen, nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
81 res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
82 res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
83 print_comm(rd, comm, nla_line);
84
85 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
86 print_raw_data(rd, nla_line);
87 newline(rd);
88
89out:
90 if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
91 free(comm);
92 return MNL_CB_OK;
93}
94
95int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
96{
97 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
98 struct rd *rd = data;
99 const char *name;
100 uint32_t idx;
101
102 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
103 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
104 return MNL_CB_ERROR;
105
106 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
107 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
108
109 return (rd->show_raw) ? res_mr_line_raw(rd, name, idx, tb) :
110 res_mr_line(rd, name, idx, tb);
111}
112
113int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
114{
115 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
116 struct nlattr *nla_table, *nla_entry;
117 struct rd *rd = data;
118 int ret = MNL_CB_OK;
119 const char *name;
120 uint32_t idx;
121
122 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
123 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
124 !tb[RDMA_NLDEV_ATTR_RES_MR])
125 return MNL_CB_ERROR;
126
127 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
128 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
129 nla_table = tb[RDMA_NLDEV_ATTR_RES_MR];
130
131 mnl_attr_for_each_nested(nla_entry, nla_table) {
132 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
133
134 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
135 if (ret != MNL_CB_OK)
136 break;
137
138 ret = (rd->show_raw) ? res_mr_line_raw(rd, name, idx, nla_line) :
139 res_mr_line(rd, name, idx, nla_line);
140 if (ret != MNL_CB_OK)
141 break;
142 }
143 return ret;
144}
145