Lines Matching refs:res

21 void rdma_restrack_init(struct rdma_restrack_root *res)  in rdma_restrack_init()  argument
23 init_rwsem(&res->rwsem); in rdma_restrack_init()
24 res->fill_res_entry = fill_res_noop; in rdma_restrack_init()
40 void rdma_restrack_clean(struct rdma_restrack_root *res) in rdma_restrack_clean() argument
48 if (hash_empty(res->hash)) in rdma_restrack_clean()
51 dev = container_of(res, struct ib_device, res); in rdma_restrack_clean()
55 hash_for_each(res->hash, bkt, e, node) { in rdma_restrack_clean()
75 int rdma_restrack_count(struct rdma_restrack_root *res, in rdma_restrack_count() argument
82 down_read(&res->rwsem); in rdma_restrack_count()
83 hash_for_each_possible(res->hash, e, node, type) { in rdma_restrack_count()
89 up_read(&res->rwsem); in rdma_restrack_count()
94 static void set_kern_name(struct rdma_restrack_entry *res) in set_kern_name() argument
98 switch (res->type) { in set_kern_name()
100 pd = container_of(res, struct ib_qp, res)->pd; in set_kern_name()
104 res->kern_name = " "; in set_kern_name()
108 pd = container_of(res, struct ib_mr, res)->pd; in set_kern_name()
117 res->kern_name = pd->res.kern_name; in set_kern_name()
120 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) in res_to_dev() argument
122 switch (res->type) { in res_to_dev()
124 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
126 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
128 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
130 return container_of(res, struct rdma_id_private, in res_to_dev()
131 res)->id.device; in res_to_dev()
133 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
135 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
140 static bool res_is_user(struct rdma_restrack_entry *res) in res_is_user() argument
142 switch (res->type) { in res_is_user()
144 return container_of(res, struct ib_pd, res)->uobject; in res_is_user()
146 return container_of(res, struct ib_cq, res)->uobject; in res_is_user()
148 return container_of(res, struct ib_qp, res)->uobject; in res_is_user()
150 return !res->kern_name; in res_is_user()
152 return container_of(res, struct ib_mr, res)->pd->uobject; in res_is_user()
154 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_is_user()
159 void rdma_restrack_add(struct rdma_restrack_entry *res) in rdma_restrack_add() argument
161 struct ib_device *dev = res_to_dev(res); in rdma_restrack_add()
166 if (res->type != RDMA_RESTRACK_CM_ID || !res_is_user(res)) in rdma_restrack_add()
167 res->task = NULL; in rdma_restrack_add()
169 if (res_is_user(res)) { in rdma_restrack_add()
170 if (!res->task) in rdma_restrack_add()
171 rdma_restrack_set_task(res, current); in rdma_restrack_add()
172 res->kern_name = NULL; in rdma_restrack_add()
174 set_kern_name(res); in rdma_restrack_add()
177 kref_init(&res->kref); in rdma_restrack_add()
178 init_completion(&res->comp); in rdma_restrack_add()
179 res->valid = true; in rdma_restrack_add()
181 down_write(&dev->res.rwsem); in rdma_restrack_add()
182 hash_add(dev->res.hash, &res->node, res->type); in rdma_restrack_add()
183 up_write(&dev->res.rwsem); in rdma_restrack_add()
187 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) in rdma_restrack_get() argument
189 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
195 struct rdma_restrack_entry *res; in restrack_release() local
197 res = container_of(kref, struct rdma_restrack_entry, kref); in restrack_release()
198 complete(&res->comp); in restrack_release()
201 int rdma_restrack_put(struct rdma_restrack_entry *res) in rdma_restrack_put() argument
203 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
207 void rdma_restrack_del(struct rdma_restrack_entry *res) in rdma_restrack_del() argument
211 if (!res->valid) in rdma_restrack_del()
214 dev = res_to_dev(res); in rdma_restrack_del()
218 rdma_restrack_put(res); in rdma_restrack_del()
220 wait_for_completion(&res->comp); in rdma_restrack_del()
222 down_write(&dev->res.rwsem); in rdma_restrack_del()
223 hash_del(&res->node); in rdma_restrack_del()
224 res->valid = false; in rdma_restrack_del()
225 if (res->task) in rdma_restrack_del()
226 put_task_struct(res->task); in rdma_restrack_del()
227 up_write(&dev->res.rwsem); in rdma_restrack_del()