OpenVZ Forum


Home » Mailing lists » Devel » [RFC][PATCH 09/14] Save leaders struct pid before detach_pid()
[RFC][PATCH 09/14] Save leaders struct pid before detach_pid() [message #17915] Wed, 21 March 2007 03:21 Go to next message
Sukadev Bhattiprolu is currently offline  Sukadev Bhattiprolu
Messages: 413
Registered: August 2006
Senior Member
From: Sukadev Bhattiprolu <sukadev@us.ibm.com>
Subject: [RFC][PATCH 09/14] Save leaders struct pid before detach_pid()

Save the struct pid of the thread group leader before detaching
our pid. See comments in the code below for more details.

Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com>
---
 fs/exec.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Index: lx26-21-rc3-mm2/fs/exec.c
===================================================================
--- lx26-21-rc3-mm2.orig/fs/exec.c	2007-03-20 15:55:52.000000000 -0700
+++ lx26-21-rc3-mm2/fs/exec.c	2007-03-20 17:17:38.000000000 -0700
@@ -578,6 +578,7 @@ static int de_thread(struct task_struct 
 	struct sighand_struct *newsighand, *oldsighand = tsk->sighand;
 	spinlock_t *lock = &oldsighand->siglock;
 	struct task_struct *leader = NULL;
+	struct pid *leader_pid;
 	int count;
 
 	/*
@@ -698,10 +699,24 @@ static int de_thread(struct task_struct 
 		 * The old leader becomes a thread of the this thread group.
 		 * Note: The old leader also uses this pid until release_task
 		 *       is called.  Odd but simple and correct.
+		 * Note: Support for multiple pid namespaces implies that there
+		 * 	 can be multiple processes with a given pid_t value,
+		 * 	 and so, find_pid() needs/uses a notion of "current"
+		 * 	 pid namespace to select the appropriate process to
+		 * 	 return.
+		 *
+		 * 	 Since the current pid namespace of a process is stored
+		 * 	 in its pid->pid_nrs list, if we detach/free our struct
+		 * 	 pid, we would have no way of finding our current pid
+		 * 	 namespace and so no way of finding the leader pid.
+		 *
+		 * 	 To work around, find the leader pid, before detaching
+		 * 	 our pid from the task.
 		 */
+		leader_pid = find_pid(leader->pid);
 		detach_pid(tsk, PIDTYPE_PID);
 		tsk->pid = leader->pid;
-		attach_pid(tsk, PIDTYPE_PID,  find_pid(tsk->pid));
+		attach_pid(tsk, PIDTYPE_PID,  leader_pid);
 		transfer_pid(leader, tsk, PIDTYPE_PGID);
 		transfer_pid(leader, tsk, PIDTYPE_SID);
 		list_replace_rcu(&leader->tasks, &tsk->tasks);
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Re: [RFC][PATCH 09/14] Save leaders struct pid before detach_pid() [message #17925 is a reply to message #17915] Wed, 21 March 2007 07:31 Go to previous message
ebiederm is currently offline  ebiederm
Messages: 1354
Registered: February 2006
Senior Member
sukadev@us.ibm.com writes:

> From: Sukadev Bhattiprolu <sukadev@us.ibm.com>
> Subject: [RFC][PATCH 09/14] Save leaders struct pid before detach_pid()
>
> Save the struct pid of the thread group leader before detaching
> our pid. See comments in the code below for more details.
>
> Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com>
> ---
>  fs/exec.c |   17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> Index: lx26-21-rc3-mm2/fs/exec.c
> ===================================================================
> --- lx26-21-rc3-mm2.orig/fs/exec.c	2007-03-20 15:55:52.000000000 -0700
> +++ lx26-21-rc3-mm2/fs/exec.c	2007-03-20 17:17:38.000000000 -0700
> @@ -578,6 +578,7 @@ static int de_thread(struct task_struct 
>  	struct sighand_struct *newsighand, *oldsighand = tsk->sighand;
>  	spinlock_t *lock = &oldsighand->siglock;
>  	struct task_struct *leader = NULL;
> +	struct pid *leader_pid;
>  	int count;
>  
>  	/*
> @@ -698,10 +699,24 @@ static int de_thread(struct task_struct 
>  		 * The old leader becomes a thread of the this thread group.
>  		 * Note: The old leader also uses this pid until release_task
>  		 *       is called.  Odd but simple and correct.
> +		 * Note: Support for multiple pid namespaces implies that there
> +		 * 	 can be multiple processes with a given pid_t value,
> +		 * 	 and so, find_pid() needs/uses a notion of "current"
> +		 * 	 pid namespace to select the appropriate process to
> +		 * 	 return.
> +		 *
> +		 * 	 Since the current pid namespace of a process is stored
> +		 * 	 in its pid->pid_nrs list, if we detach/free our struct
> +		 * 	 pid, we would have no way of finding our current pid
> +		 * 	 namespace and so no way of finding the leader pid.
> +		 *
> +		 * 	 To work around, find the leader pid, before detaching
> +		 * 	 our pid from the task.
>  		 */
> +		leader_pid = find_pid(leader->pid);
>  		detach_pid(tsk, PIDTYPE_PID);
>  		tsk->pid = leader->pid;
> -		attach_pid(tsk, PIDTYPE_PID,  find_pid(tsk->pid));
> +		attach_pid(tsk, PIDTYPE_PID,  leader_pid);
How about just:
		attach_pid(tsk, PIDTYPE_PID, task_pid(leader));
>  		transfer_pid(leader, tsk, PIDTYPE_PGID);
>  		transfer_pid(leader, tsk, PIDTYPE_SID);
>  		list_replace_rcu(&leader->tasks, &tsk->tasks);

Eric
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Previous Topic: [RFC][PATCH 02/14] Move alloc_pid call to copy_process
Next Topic: [RFC][PATCH 12/14] Remove copy_pid_ns function
Goto Forum:
  


Current Time: Thu Aug 21 19:51:40 GMT 2025

Total time taken to generate the page: 0.06762 seconds