Lines Matching refs:res

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