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()
65 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_count()
78 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) in res_to_dev() argument
80 switch (res->type) { in res_to_dev()
82 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
84 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
86 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
88 return container_of(res, struct rdma_id_private, in res_to_dev()
89 res)->id.device; in res_to_dev()
91 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
93 return container_of(res, struct ib_ucontext, res)->device; in res_to_dev()
95 return container_of(res, struct rdma_counter, res)->device; in res_to_dev()
97 return container_of(res, struct ib_srq, res)->device; in res_to_dev()
99 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
110 static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, in rdma_restrack_attach_task() argument
116 if (res->task) in rdma_restrack_attach_task()
117 put_task_struct(res->task); in rdma_restrack_attach_task()
119 res->task = task; in rdma_restrack_attach_task()
120 res->user = true; in rdma_restrack_attach_task()
128 void rdma_restrack_set_name(struct rdma_restrack_entry *res, const char *caller) in rdma_restrack_set_name() argument
131 res->kern_name = caller; in rdma_restrack_set_name()
135 rdma_restrack_attach_task(res, current); in rdma_restrack_set_name()
161 void rdma_restrack_new(struct rdma_restrack_entry *res, in rdma_restrack_new() argument
164 kref_init(&res->kref); in rdma_restrack_new()
165 init_completion(&res->comp); in rdma_restrack_new()
166 res->type = type; in rdma_restrack_new()
174 void rdma_restrack_add(struct rdma_restrack_entry *res) in rdma_restrack_add() argument
176 struct ib_device *dev = res_to_dev(res); in rdma_restrack_add()
183 if (res->no_track) in rdma_restrack_add()
186 rt = &dev->res[res->type]; in rdma_restrack_add()
188 if (res->type == RDMA_RESTRACK_QP) { in rdma_restrack_add()
190 struct ib_qp *qp = container_of(res, struct ib_qp, res); in rdma_restrack_add()
195 res->id = qp->qp_num; in rdma_restrack_add()
197 res->id |= qp->port << 24; in rdma_restrack_add()
198 ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL); in rdma_restrack_add()
200 res->id = 0; in rdma_restrack_add()
201 } else if (res->type == RDMA_RESTRACK_COUNTER) { in rdma_restrack_add()
205 counter = container_of(res, struct rdma_counter, res); in rdma_restrack_add()
206 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL); in rdma_restrack_add()
207 res->id = ret ? 0 : counter->id; in rdma_restrack_add()
209 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b, in rdma_restrack_add()
216 res->valid = true; in rdma_restrack_add()
220 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) in rdma_restrack_get() argument
222 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
238 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_get_byid()
239 struct rdma_restrack_entry *res; in rdma_restrack_get_byid() local
242 res = xa_load(&rt->xa, id); in rdma_restrack_get_byid()
243 if (!res || !rdma_restrack_get(res)) in rdma_restrack_get_byid()
244 res = ERR_PTR(-ENOENT); in rdma_restrack_get_byid()
247 return res; in rdma_restrack_get_byid()
253 struct rdma_restrack_entry *res; in restrack_release() local
255 res = container_of(kref, struct rdma_restrack_entry, kref); in restrack_release()
256 if (res->task) { in restrack_release()
257 put_task_struct(res->task); in restrack_release()
258 res->task = NULL; in restrack_release()
260 complete(&res->comp); in restrack_release()
263 int rdma_restrack_put(struct rdma_restrack_entry *res) in rdma_restrack_put() argument
265 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
273 void rdma_restrack_del(struct rdma_restrack_entry *res) in rdma_restrack_del() argument
279 if (!res->valid) { in rdma_restrack_del()
280 if (res->task) { in rdma_restrack_del()
281 put_task_struct(res->task); in rdma_restrack_del()
282 res->task = NULL; in rdma_restrack_del()
287 if (res->no_track) in rdma_restrack_del()
290 dev = res_to_dev(res); in rdma_restrack_del()
294 rt = &dev->res[res->type]; in rdma_restrack_del()
296 old = xa_erase(&rt->xa, res->id); in rdma_restrack_del()
297 WARN_ON(old != res); in rdma_restrack_del()
300 res->valid = false; in rdma_restrack_del()
301 rdma_restrack_put(res); in rdma_restrack_del()
302 wait_for_completion(&res->comp); in rdma_restrack_del()