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()
61 struct rdma_restrack_root *rt = dev->res; in rdma_restrack_clean()
69 struct xarray *xa = &dev->res[i].xa; in rdma_restrack_clean()
113 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_count()
126 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) in res_to_dev() argument
128 switch (res->type) { in res_to_dev()
130 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
132 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
134 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
136 return container_of(res, struct rdma_id_private, in res_to_dev()
137 res)->id.device; in res_to_dev()
139 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
141 return container_of(res, struct ib_ucontext, res)->device; in res_to_dev()
143 return container_of(res, struct rdma_counter, res)->device; in res_to_dev()
145 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
156 static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, in rdma_restrack_attach_task() argument
162 if (res->task) in rdma_restrack_attach_task()
163 put_task_struct(res->task); in rdma_restrack_attach_task()
165 res->task = task; in rdma_restrack_attach_task()
166 res->user = true; in rdma_restrack_attach_task()
174 void rdma_restrack_set_name(struct rdma_restrack_entry *res, const char *caller) in rdma_restrack_set_name() argument
177 res->kern_name = caller; in rdma_restrack_set_name()
181 rdma_restrack_attach_task(res, current); in rdma_restrack_set_name()
207 void rdma_restrack_new(struct rdma_restrack_entry *res, in rdma_restrack_new() argument
210 kref_init(&res->kref); in rdma_restrack_new()
211 init_completion(&res->comp); in rdma_restrack_new()
212 res->type = type; in rdma_restrack_new()
220 void rdma_restrack_add(struct rdma_restrack_entry *res) in rdma_restrack_add() argument
222 struct ib_device *dev = res_to_dev(res); in rdma_restrack_add()
229 rt = &dev->res[res->type]; in rdma_restrack_add()
231 if (res->type == RDMA_RESTRACK_QP) { in rdma_restrack_add()
233 struct ib_qp *qp = container_of(res, struct ib_qp, res); in rdma_restrack_add()
235 ret = xa_insert(&rt->xa, qp->qp_num, res, GFP_KERNEL); in rdma_restrack_add()
236 res->id = ret ? 0 : qp->qp_num; in rdma_restrack_add()
237 } else if (res->type == RDMA_RESTRACK_COUNTER) { in rdma_restrack_add()
241 counter = container_of(res, struct rdma_counter, res); in rdma_restrack_add()
242 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL); in rdma_restrack_add()
243 res->id = ret ? 0 : counter->id; in rdma_restrack_add()
245 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b, in rdma_restrack_add()
250 res->valid = true; in rdma_restrack_add()
254 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) in rdma_restrack_get() argument
256 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
272 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_get_byid()
273 struct rdma_restrack_entry *res; in rdma_restrack_get_byid() local
276 res = xa_load(&rt->xa, id); in rdma_restrack_get_byid()
277 if (!res || !rdma_restrack_get(res)) in rdma_restrack_get_byid()
278 res = ERR_PTR(-ENOENT); in rdma_restrack_get_byid()
281 return res; in rdma_restrack_get_byid()
287 struct rdma_restrack_entry *res; in restrack_release() local
289 res = container_of(kref, struct rdma_restrack_entry, kref); in restrack_release()
290 if (res->task) { in restrack_release()
291 put_task_struct(res->task); in restrack_release()
292 res->task = NULL; in restrack_release()
294 complete(&res->comp); in restrack_release()
297 int rdma_restrack_put(struct rdma_restrack_entry *res) in rdma_restrack_put() argument
299 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
307 void rdma_restrack_del(struct rdma_restrack_entry *res) in rdma_restrack_del() argument
313 if (!res->valid) { in rdma_restrack_del()
314 if (res->task) { in rdma_restrack_del()
315 put_task_struct(res->task); in rdma_restrack_del()
316 res->task = NULL; in rdma_restrack_del()
321 dev = res_to_dev(res); in rdma_restrack_del()
325 rt = &dev->res[res->type]; in rdma_restrack_del()
327 old = xa_erase(&rt->xa, res->id); in rdma_restrack_del()
328 if (res->type == RDMA_RESTRACK_MR || res->type == RDMA_RESTRACK_QP) in rdma_restrack_del()
330 WARN_ON(old != res); in rdma_restrack_del()
331 res->valid = false; in rdma_restrack_del()
333 rdma_restrack_put(res); in rdma_restrack_del()
334 wait_for_completion(&res->comp); in rdma_restrack_del()