]>
Commit | Line | Data |
---|---|---|
42ed283e LR |
1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
2 | /* | |
3 | * res-mr.c RDMA tool | |
4 | * Authors: Leon Romanovsky <leonro@mellanox.com> | |
5 | */ | |
6 | ||
7 | #include "res.h" | |
8 | #include <inttypes.h> | |
9 | ||
10 | int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data) | |
11 | { | |
12 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
13 | struct nlattr *nla_table, *nla_entry; | |
14 | struct rd *rd = data; | |
15 | const char *name; | |
16 | uint32_t idx; | |
17 | ||
18 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
19 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
20 | !tb[RDMA_NLDEV_ATTR_RES_MR]) | |
21 | return MNL_CB_ERROR; | |
22 | ||
23 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
24 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
25 | nla_table = tb[RDMA_NLDEV_ATTR_RES_MR]; | |
26 | ||
27 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
28 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; | |
29 | uint32_t rkey = 0, lkey = 0; | |
30 | uint64_t iova = 0, mrlen; | |
31 | char *comm = NULL; | |
32 | uint32_t pdn = 0; | |
33 | uint32_t mrn = 0; | |
34 | uint32_t pid = 0; | |
35 | int err; | |
36 | ||
37 | err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
38 | if (err != MNL_CB_OK) | |
39 | return MNL_CB_ERROR; | |
40 | ||
41 | if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN] || | |
42 | (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && | |
43 | !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { | |
44 | return MNL_CB_ERROR; | |
45 | } | |
46 | ||
47 | if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY]) | |
48 | rkey = mnl_attr_get_u32( | |
49 | nla_line[RDMA_NLDEV_ATTR_RES_RKEY]); | |
50 | if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY]) | |
51 | lkey = mnl_attr_get_u32( | |
52 | nla_line[RDMA_NLDEV_ATTR_RES_LKEY]); | |
53 | if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA]) | |
54 | iova = mnl_attr_get_u64( | |
55 | nla_line[RDMA_NLDEV_ATTR_RES_IOVA]); | |
56 | ||
57 | mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]); | |
58 | if (rd_check_is_filtered(rd, "mrlen", mrlen)) | |
59 | continue; | |
60 | ||
61 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
62 | pid = mnl_attr_get_u32( | |
63 | nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
64 | comm = get_task_name(pid); | |
65 | } | |
66 | ||
67 | if (rd_check_is_filtered(rd, "pid", pid)) { | |
68 | free(comm); | |
69 | continue; | |
70 | } | |
71 | ||
72 | if (nla_line[RDMA_NLDEV_ATTR_RES_MRN]) | |
73 | mrn = mnl_attr_get_u32( | |
74 | nla_line[RDMA_NLDEV_ATTR_RES_MRN]); | |
75 | if (rd_check_is_filtered(rd, "mrn", mrn)) | |
76 | continue; | |
77 | ||
78 | if (nla_line[RDMA_NLDEV_ATTR_RES_PDN]) | |
79 | pdn = mnl_attr_get_u32( | |
80 | nla_line[RDMA_NLDEV_ATTR_RES_PDN]); | |
81 | if (rd_check_is_filtered(rd, "pdn", pdn)) | |
82 | continue; | |
83 | ||
84 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
85 | /* discard const from mnl_attr_get_str */ | |
86 | comm = (char *)mnl_attr_get_str( | |
87 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
88 | ||
89 | if (rd->json_output) | |
90 | jsonw_start_array(rd->jw); | |
91 | ||
92 | print_dev(rd, idx, name); | |
93 | if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY]) | |
94 | print_key(rd, "rkey", rkey); | |
95 | if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY]) | |
96 | print_key(rd, "lkey", lkey); | |
97 | if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA]) | |
98 | print_key(rd, "iova", iova); | |
99 | res_print_uint(rd, "mrlen", mrlen); | |
05846c9c | 100 | res_print_uint(rd, "pid", pid); |
42ed283e LR |
101 | print_comm(rd, comm, nla_line); |
102 | ||
103 | if (nla_line[RDMA_NLDEV_ATTR_RES_MRN]) | |
104 | res_print_uint(rd, "mrn", mrn); | |
105 | ||
106 | if (nla_line[RDMA_NLDEV_ATTR_RES_PDN]) | |
107 | res_print_uint(rd, "pdn", pdn); | |
108 | ||
109 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
110 | free(comm); | |
111 | ||
112 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); | |
113 | newline(rd); | |
114 | } | |
115 | return MNL_CB_OK; | |
116 | } | |
117 |