RDMA/restrack: Add an API to attach a task to a resource
authorMark Zhang <markz@mellanox.com>
Tue, 2 Jul 2019 10:02:32 +0000 (13:02 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Fri, 5 Jul 2019 13:22:54 +0000 (10:22 -0300)
Add rdma_restrack_attach_task() which is able to attach a task other then
"current" to a resource.

Signed-off-by: Mark Zhang <markz@mellanox.com>
Reviewed-by: Majd Dibbiny <majd@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/restrack.c
drivers/infiniband/core/restrack.h

index 95573f292aae11c61a6849af7cf501144f9639ce..3714634ae2967a7b58d62eb12b0d73eb6fdaa7ef 100644 (file)
@@ -194,6 +194,20 @@ void rdma_restrack_set_task(struct rdma_restrack_entry *res,
 }
 EXPORT_SYMBOL(rdma_restrack_set_task);
 
+/**
+ * rdma_restrack_attach_task() - attach the task onto this resource
+ * @res:  resource entry
+ * @task: the task to attach, the current task will be used if it is NULL.
+ */
+void rdma_restrack_attach_task(struct rdma_restrack_entry *res,
+                              struct task_struct *task)
+{
+       if (res->task)
+               put_task_struct(res->task);
+       get_task_struct(task);
+       res->task = task;
+}
+
 static void rdma_restrack_add(struct rdma_restrack_entry *res)
 {
        struct ib_device *dev = res_to_dev(res);
index 09a1fbdf578ed1a87d61ecb9aeca9b314b15424a..d084e5f8984911460399af83df0a2447171c42b2 100644 (file)
@@ -25,4 +25,6 @@ struct rdma_restrack_root {
 
 int rdma_restrack_init(struct ib_device *dev);
 void rdma_restrack_clean(struct ib_device *dev);
+void rdma_restrack_attach_task(struct rdma_restrack_entry *res,
+                              struct task_struct *task);
 #endif /* _RDMA_CORE_RESTRACK_H_ */