Lines Matching refs:res

28 	dev->res = kcalloc(RDMA_RESTRACK_MAX, sizeof(*rt), GFP_KERNEL);  in rdma_restrack_init()
29 if (!dev->res) in rdma_restrack_init()
32 rt = dev->res; in rdma_restrack_init()
46 struct rdma_restrack_root *rt = dev->res; in rdma_restrack_clean()
50 struct xarray *xa = &dev->res[i].xa; in rdma_restrack_clean()
67 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_count()
83 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) in res_to_dev() argument
85 switch (res->type) { in res_to_dev()
87 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
89 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
91 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
93 return container_of(res, struct rdma_id_private, in res_to_dev()
94 res)->id.device; in res_to_dev()
96 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
98 return container_of(res, struct ib_ucontext, res)->device; in res_to_dev()
100 return container_of(res, struct rdma_counter, res)->device; in res_to_dev()
102 return container_of(res, struct ib_srq, res)->device; in res_to_dev()
104 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
115 static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, in rdma_restrack_attach_task() argument
121 if (res->task) in rdma_restrack_attach_task()
122 put_task_struct(res->task); in rdma_restrack_attach_task()
124 res->task = task; in rdma_restrack_attach_task()
125 res->user = true; in rdma_restrack_attach_task()
133 void rdma_restrack_set_name(struct rdma_restrack_entry *res, const char *caller) in rdma_restrack_set_name() argument
136 res->kern_name = caller; in rdma_restrack_set_name()
140 rdma_restrack_attach_task(res, current); in rdma_restrack_set_name()
166 void rdma_restrack_new(struct rdma_restrack_entry *res, in rdma_restrack_new() argument
169 kref_init(&res->kref); in rdma_restrack_new()
170 init_completion(&res->comp); in rdma_restrack_new()
171 res->type = type; in rdma_restrack_new()
179 void rdma_restrack_add(struct rdma_restrack_entry *res) in rdma_restrack_add() argument
181 struct ib_device *dev = res_to_dev(res); in rdma_restrack_add()
188 if (res->no_track) in rdma_restrack_add()
191 rt = &dev->res[res->type]; in rdma_restrack_add()
193 if (res->type == RDMA_RESTRACK_QP) { in rdma_restrack_add()
195 struct ib_qp *qp = container_of(res, struct ib_qp, res); in rdma_restrack_add()
200 res->id = qp->qp_num; in rdma_restrack_add()
202 res->id |= qp->port << 24; in rdma_restrack_add()
203 ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL); in rdma_restrack_add()
205 res->id = 0; in rdma_restrack_add()
208 xa_set_mark(&rt->xa, res->id, RESTRACK_DD); in rdma_restrack_add()
209 } else if (res->type == RDMA_RESTRACK_COUNTER) { in rdma_restrack_add()
213 counter = container_of(res, struct rdma_counter, res); in rdma_restrack_add()
214 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL); in rdma_restrack_add()
215 res->id = ret ? 0 : counter->id; in rdma_restrack_add()
217 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b, in rdma_restrack_add()
224 res->valid = true; in rdma_restrack_add()
228 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) in rdma_restrack_get() argument
230 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
246 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_get_byid()
247 struct rdma_restrack_entry *res; in rdma_restrack_get_byid() local
250 res = xa_load(&rt->xa, id); in rdma_restrack_get_byid()
251 if (!res || !rdma_restrack_get(res)) in rdma_restrack_get_byid()
252 res = ERR_PTR(-ENOENT); in rdma_restrack_get_byid()
255 return res; in rdma_restrack_get_byid()
261 struct rdma_restrack_entry *res; in restrack_release() local
263 res = container_of(kref, struct rdma_restrack_entry, kref); in restrack_release()
264 if (res->task) { in restrack_release()
265 put_task_struct(res->task); in restrack_release()
266 res->task = NULL; in restrack_release()
268 complete(&res->comp); in restrack_release()
271 int rdma_restrack_put(struct rdma_restrack_entry *res) in rdma_restrack_put() argument
273 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
281 void rdma_restrack_del(struct rdma_restrack_entry *res) in rdma_restrack_del() argument
287 if (!res->valid) { in rdma_restrack_del()
288 if (res->task) { in rdma_restrack_del()
289 put_task_struct(res->task); in rdma_restrack_del()
290 res->task = NULL; in rdma_restrack_del()
295 if (res->no_track) in rdma_restrack_del()
298 dev = res_to_dev(res); in rdma_restrack_del()
302 rt = &dev->res[res->type]; in rdma_restrack_del()
304 old = xa_erase(&rt->xa, res->id); in rdma_restrack_del()
305 WARN_ON(old != res); in rdma_restrack_del()
308 res->valid = false; in rdma_restrack_del()
309 rdma_restrack_put(res); in rdma_restrack_del()
310 wait_for_completion(&res->comp); in rdma_restrack_del()