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()
62 struct rdma_restrack_root *rt = dev->res; in rdma_restrack_clean()
70 struct xarray *xa = &dev->res[i].xa; in rdma_restrack_clean()
114 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_count()
127 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) in res_to_dev() argument
129 switch (res->type) { in res_to_dev()
131 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
133 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
135 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
137 return container_of(res, struct rdma_id_private, in res_to_dev()
138 res)->id.device; in res_to_dev()
140 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
142 return container_of(res, struct ib_ucontext, res)->device; in res_to_dev()
144 return container_of(res, struct rdma_counter, res)->device; in res_to_dev()
146 return container_of(res, struct ib_srq, res)->device; in res_to_dev()
148 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
159 static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, in rdma_restrack_attach_task() argument
165 if (res->task) in rdma_restrack_attach_task()
166 put_task_struct(res->task); in rdma_restrack_attach_task()
168 res->task = task; in rdma_restrack_attach_task()
169 res->user = true; in rdma_restrack_attach_task()
177 void rdma_restrack_set_name(struct rdma_restrack_entry *res, const char *caller) in rdma_restrack_set_name() argument
180 res->kern_name = caller; in rdma_restrack_set_name()
184 rdma_restrack_attach_task(res, current); in rdma_restrack_set_name()
210 void rdma_restrack_new(struct rdma_restrack_entry *res, in rdma_restrack_new() argument
213 kref_init(&res->kref); in rdma_restrack_new()
214 init_completion(&res->comp); in rdma_restrack_new()
215 res->type = type; in rdma_restrack_new()
223 void rdma_restrack_add(struct rdma_restrack_entry *res) in rdma_restrack_add() argument
225 struct ib_device *dev = res_to_dev(res); in rdma_restrack_add()
232 if (res->no_track) in rdma_restrack_add()
235 rt = &dev->res[res->type]; in rdma_restrack_add()
237 if (res->type == RDMA_RESTRACK_QP) { in rdma_restrack_add()
239 struct ib_qp *qp = container_of(res, struct ib_qp, res); in rdma_restrack_add()
244 res->id = qp->qp_num; in rdma_restrack_add()
246 res->id |= qp->port << 24; in rdma_restrack_add()
247 ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL); in rdma_restrack_add()
249 res->id = 0; in rdma_restrack_add()
250 } else if (res->type == RDMA_RESTRACK_COUNTER) { in rdma_restrack_add()
254 counter = container_of(res, struct rdma_counter, res); in rdma_restrack_add()
255 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL); in rdma_restrack_add()
256 res->id = ret ? 0 : counter->id; in rdma_restrack_add()
258 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b, in rdma_restrack_add()
265 res->valid = true; in rdma_restrack_add()
269 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) in rdma_restrack_get() argument
271 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
287 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_get_byid()
288 struct rdma_restrack_entry *res; in rdma_restrack_get_byid() local
291 res = xa_load(&rt->xa, id); in rdma_restrack_get_byid()
292 if (!res || !rdma_restrack_get(res)) in rdma_restrack_get_byid()
293 res = ERR_PTR(-ENOENT); in rdma_restrack_get_byid()
296 return res; in rdma_restrack_get_byid()
302 struct rdma_restrack_entry *res; in restrack_release() local
304 res = container_of(kref, struct rdma_restrack_entry, kref); in restrack_release()
305 if (res->task) { in restrack_release()
306 put_task_struct(res->task); in restrack_release()
307 res->task = NULL; in restrack_release()
309 complete(&res->comp); in restrack_release()
312 int rdma_restrack_put(struct rdma_restrack_entry *res) in rdma_restrack_put() argument
314 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
322 void rdma_restrack_del(struct rdma_restrack_entry *res) in rdma_restrack_del() argument
328 if (!res->valid) { in rdma_restrack_del()
329 if (res->task) { in rdma_restrack_del()
330 put_task_struct(res->task); in rdma_restrack_del()
331 res->task = NULL; in rdma_restrack_del()
336 if (res->no_track) in rdma_restrack_del()
339 dev = res_to_dev(res); in rdma_restrack_del()
343 rt = &dev->res[res->type]; in rdma_restrack_del()
345 old = xa_erase(&rt->xa, res->id); in rdma_restrack_del()
346 if (res->type == RDMA_RESTRACK_MR) in rdma_restrack_del()
348 WARN_ON(old != res); in rdma_restrack_del()
351 res->valid = false; in rdma_restrack_del()
352 rdma_restrack_put(res); in rdma_restrack_del()
353 wait_for_completion(&res->comp); in rdma_restrack_del()