[PATCH 5/8] introduce find_get_task_by_vpid()

From: Oleg Nesterov
Date: Wed Jul 27 2011 - 12:36:38 EST


Introduce the new helper, find_get_task_by_vpid(), which simply
does find_task_by_vpid() + get_task_struct() under rcu_read_lock().

It has several potential users which currently do this by hand,
and we are going to add clone_vfork_restart() which needs it too.

Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
---

include/linux/sched.h | 1 +
kernel/pid.c | 13 +++++++++++++
2 files changed, 14 insertions(+)

--- 3.1/include/linux/sched.h~5_find_get_task 2011-07-26 20:35:55.000000000 +0200
+++ 3.1/include/linux/sched.h 2011-07-26 20:36:10.000000000 +0200
@@ -2107,6 +2107,7 @@ extern struct pid_namespace init_pid_ns;
*/

extern struct task_struct *find_task_by_vpid(pid_t nr);
+extern struct task_struct *find_get_task_by_vpid(pid_t vnr);
extern struct task_struct *find_task_by_pid_ns(pid_t nr,
struct pid_namespace *ns);

--- 3.1/kernel/pid.c~5_find_get_task 2011-07-26 15:50:15.000000000 +0200
+++ 3.1/kernel/pid.c 2011-07-26 20:33:18.000000000 +0200
@@ -427,6 +427,19 @@ struct task_struct *find_task_by_vpid(pi
return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
}

+struct task_struct *find_get_task_by_vpid(pid_t vnr)
+{
+ struct task_struct *task;
+
+ rcu_read_lock();
+ task = find_task_by_vpid(vnr);
+ if (task)
+ get_task_struct(task);
+ rcu_read_unlock();
+
+ return task;
+}
+
struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
{
struct pid *pid;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/