Lines Matching refs:res

28 	dev->res = kcalloc(RDMA_RESTRACK_MAX, sizeof(*rt), GFP_KERNEL);
29 if (!dev->res)
32 rt = dev->res;
46 struct rdma_restrack_root *rt = dev->res;
50 struct xarray *xa = &dev->res[i].xa;
67 struct rdma_restrack_root *rt = &dev->res[type];
83 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
85 switch (res->type) {
87 return container_of(res, struct ib_pd, res)->device;
89 return container_of(res, struct ib_cq, res)->device;
91 return container_of(res, struct ib_qp, res)->device;
93 return container_of(res, struct rdma_id_private,
94 res)->id.device;
96 return container_of(res, struct ib_mr, res)->device;
98 return container_of(res, struct ib_ucontext, res)->device;
100 return container_of(res, struct rdma_counter, res)->device;
102 return container_of(res, struct ib_srq, res)->device;
104 return container_of(res, struct ib_dmah, res)->device;
106 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
114 * @res: resource entry
117 static void rdma_restrack_attach_task(struct rdma_restrack_entry *res,
123 if (res->task)
124 put_task_struct(res->task);
126 res->task = task;
127 res->user = true;
132 * @res: resource entry
135 void rdma_restrack_set_name(struct rdma_restrack_entry *res, const char *caller)
138 res->kern_name = caller;
142 rdma_restrack_attach_task(res, current);
165 * @res: Entry to initialize
168 void rdma_restrack_new(struct rdma_restrack_entry *res,
171 kref_init(&res->kref);
172 init_completion(&res->comp);
173 res->type = type;
179 * @res: resource entry
181 void rdma_restrack_add(struct rdma_restrack_entry *res)
183 struct ib_device *dev = res_to_dev(res);
190 if (res->no_track)
193 rt = &dev->res[res->type];
195 if (res->type == RDMA_RESTRACK_QP) {
197 struct ib_qp *qp = container_of(res, struct ib_qp, res);
202 res->id = qp->qp_num;
204 res->id |= qp->port << 24;
205 ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL);
207 res->id = 0;
210 xa_set_mark(&rt->xa, res->id, RESTRACK_DD);
211 } else if (res->type == RDMA_RESTRACK_COUNTER) {
215 counter = container_of(res, struct rdma_counter, res);
216 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL);
217 res->id = ret ? 0 : counter->id;
219 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b,
226 res->valid = true;
230 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res)
232 return kref_get_unless_zero(&res->kref);
248 struct rdma_restrack_root *rt = &dev->res[type];
249 struct rdma_restrack_entry *res;
252 res = xa_load(&rt->xa, id);
253 if (!res || !rdma_restrack_get(res))
254 res = ERR_PTR(-ENOENT);
257 return res;
263 struct rdma_restrack_entry *res;
265 res = container_of(kref, struct rdma_restrack_entry, kref);
266 if (res->task) {
267 put_task_struct(res->task);
268 res->task = NULL;
270 complete(&res->comp);
273 int rdma_restrack_put(struct rdma_restrack_entry *res)
275 return kref_put(&res->kref, restrack_release);
281 * @res: resource entry
283 void rdma_restrack_del(struct rdma_restrack_entry *res)
289 if (!res->valid) {
290 if (res->task) {
291 put_task_struct(res->task);
292 res->task = NULL;
297 if (res->no_track)
300 dev = res_to_dev(res);
304 rt = &dev->res[res->type];
306 old = xa_erase(&rt->xa, res->id);
307 WARN_ON(old != res);
310 res->valid = false;
311 rdma_restrack_put(res);
312 wait_for_completion(&res->comp);