All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] teach set_special_pids() to use struct pid
@ 2007-11-26 14:25 Oleg Nesterov
  2007-11-26 15:02 ` Pavel Emelyanov
  2007-11-26 18:51 ` Eric W. Biederman
  0 siblings, 2 replies; 5+ messages in thread
From: Oleg Nesterov @ 2007-11-26 14:25 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Eric W. Biederman, Pavel Emelyanov, linux-kernel

Change set_special_pids() to work with struct pid, not pid_t from global name
space. This again speedups and imho cleanups the code.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- PT/include/linux/sched.h~2_set_special_pids	2007-11-26 15:52:15.000000000 +0300
+++ PT/include/linux/sched.h	2007-11-26 16:47:35.000000000 +0300
@@ -1568,7 +1568,7 @@ extern struct task_struct *find_task_by_
 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
 		struct pid_namespace *ns);
 
-extern void __set_special_pids(pid_t session, pid_t pgrp);
+extern void __set_special_pids(struct pid *pid);
 
 /* per-UID process charging. */
 extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
--- PT/kernel/exit.c~2_set_special_pids	2007-11-26 15:52:15.000000000 +0300
+++ PT/kernel/exit.c	2007-11-26 16:47:35.000000000 +0300
@@ -295,26 +295,27 @@ static void reparent_to_kthreadd(void)
 	switch_uid(INIT_USER);
 }
 
-void __set_special_pids(pid_t session, pid_t pgrp)
+void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
+	pid_t nr = pid_nr(pid);
 
-	if (task_session_nr(curr) != session) {
+	if (task_session(curr) != pid) {
 		detach_pid(curr, PIDTYPE_SID);
-		set_task_session(curr, session);
-		attach_pid(curr, PIDTYPE_SID, find_pid(session));
+		attach_pid(curr, PIDTYPE_SID, pid);
+		set_task_session(curr, nr);
 	}
-	if (task_pgrp_nr(curr) != pgrp) {
+	if (task_pgrp(curr) != pid) {
 		detach_pid(curr, PIDTYPE_PGID);
-		set_task_pgrp(curr, pgrp);
-		attach_pid(curr, PIDTYPE_PGID, find_pid(pgrp));
+		attach_pid(curr, PIDTYPE_PGID, pid);
+		set_task_pgrp(curr, nr);
 	}
 }
 
-static void set_special_pids(pid_t session, pid_t pgrp)
+static void set_special_pids(struct pid *pid)
 {
 	write_lock_irq(&tasklist_lock);
-	__set_special_pids(session, pgrp);
+	__set_special_pids(pid);
 	write_unlock_irq(&tasklist_lock);
 }
 
@@ -385,7 +386,11 @@ void daemonize(const char *name, ...)
 	 */
 	current->flags |= PF_NOFREEZE;
 
-	set_special_pids(1, 1);
+	if (current->nsproxy != &init_nsproxy) {
+		get_nsproxy(&init_nsproxy);
+		switch_task_namespaces(current, &init_nsproxy);
+	}
+	set_special_pids(find_pid(1));
 	proc_clear_tty(current);
 
 	/* Block and flush all signals */
@@ -400,11 +405,6 @@ void daemonize(const char *name, ...)
 	current->fs = fs;
 	atomic_inc(&fs->count);
 
-	if (current->nsproxy != init_task.nsproxy) {
-		get_nsproxy(init_task.nsproxy);
-		switch_task_namespaces(current, init_task.nsproxy);
-	}
-
 	exit_files(current);
 	current->files = init_task.files;
 	atomic_inc(&current->files->count);
--- PT/kernel/sys.c~2_set_special_pids	2007-11-26 16:10:43.000000000 +0300
+++ PT/kernel/sys.c	2007-11-26 16:48:02.000000000 +0300
@@ -1065,7 +1065,7 @@ asmlinkage long sys_setsid(void)
 		goto out;
 
 	group_leader->signal->leader = 1;
-	__set_special_pids(pid_nr(sid), pid_nr(sid));
+	__set_special_pids(sid);
 
 	spin_lock(&group_leader->sighand->siglock);
 	group_leader->signal->tty = NULL;
--- PT/init/main.c~2_set_special_pids	2007-11-26 15:52:15.000000000 +0300
+++ PT/init/main.c	2007-11-26 16:56:24.000000000 +0300
@@ -829,7 +829,7 @@ static int __init kernel_init(void * unu
 	 */
 	init_pid_ns.child_reaper = current;
 
-	__set_special_pids(1, 1);
+	__set_special_pids(task_pid(current));
 	cad_pid = task_pid(current);
 
 	smp_prepare_cpus(max_cpus);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] teach set_special_pids() to use struct pid
  2007-11-26 14:25 [PATCH 2/3] teach set_special_pids() to use struct pid Oleg Nesterov
@ 2007-11-26 15:02 ` Pavel Emelyanov
  2007-11-26 18:51 ` Eric W. Biederman
  1 sibling, 0 replies; 5+ messages in thread
From: Pavel Emelyanov @ 2007-11-26 15:02 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, Eric W. Biederman, linux-kernel

Oleg Nesterov wrote:
> Change set_special_pids() to work with struct pid, not pid_t from global name
> space. This again speedups and imho cleanups the code.
> 
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

Acked-by: Pavel Emelyanov <xemul@openvz.org>

> --- PT/include/linux/sched.h~2_set_special_pids	2007-11-26 15:52:15.000000000 +0300
> +++ PT/include/linux/sched.h	2007-11-26 16:47:35.000000000 +0300
> @@ -1568,7 +1568,7 @@ extern struct task_struct *find_task_by_
>  extern struct task_struct *find_task_by_pid_ns(pid_t nr,
>  		struct pid_namespace *ns);
>  
> -extern void __set_special_pids(pid_t session, pid_t pgrp);
> +extern void __set_special_pids(struct pid *pid);
>  
>  /* per-UID process charging. */
>  extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
> --- PT/kernel/exit.c~2_set_special_pids	2007-11-26 15:52:15.000000000 +0300
> +++ PT/kernel/exit.c	2007-11-26 16:47:35.000000000 +0300
> @@ -295,26 +295,27 @@ static void reparent_to_kthreadd(void)
>  	switch_uid(INIT_USER);
>  }
>  
> -void __set_special_pids(pid_t session, pid_t pgrp)
> +void __set_special_pids(struct pid *pid)
>  {
>  	struct task_struct *curr = current->group_leader;
> +	pid_t nr = pid_nr(pid);
>  
> -	if (task_session_nr(curr) != session) {
> +	if (task_session(curr) != pid) {
>  		detach_pid(curr, PIDTYPE_SID);
> -		set_task_session(curr, session);
> -		attach_pid(curr, PIDTYPE_SID, find_pid(session));
> +		attach_pid(curr, PIDTYPE_SID, pid);
> +		set_task_session(curr, nr);
>  	}
> -	if (task_pgrp_nr(curr) != pgrp) {
> +	if (task_pgrp(curr) != pid) {
>  		detach_pid(curr, PIDTYPE_PGID);
> -		set_task_pgrp(curr, pgrp);
> -		attach_pid(curr, PIDTYPE_PGID, find_pid(pgrp));
> +		attach_pid(curr, PIDTYPE_PGID, pid);
> +		set_task_pgrp(curr, nr);
>  	}
>  }
>  
> -static void set_special_pids(pid_t session, pid_t pgrp)
> +static void set_special_pids(struct pid *pid)
>  {
>  	write_lock_irq(&tasklist_lock);
> -	__set_special_pids(session, pgrp);
> +	__set_special_pids(pid);
>  	write_unlock_irq(&tasklist_lock);
>  }
>  
> @@ -385,7 +386,11 @@ void daemonize(const char *name, ...)
>  	 */
>  	current->flags |= PF_NOFREEZE;
>  
> -	set_special_pids(1, 1);
> +	if (current->nsproxy != &init_nsproxy) {
> +		get_nsproxy(&init_nsproxy);
> +		switch_task_namespaces(current, &init_nsproxy);
> +	}
> +	set_special_pids(find_pid(1));
>  	proc_clear_tty(current);
>  
>  	/* Block and flush all signals */
> @@ -400,11 +405,6 @@ void daemonize(const char *name, ...)
>  	current->fs = fs;
>  	atomic_inc(&fs->count);
>  
> -	if (current->nsproxy != init_task.nsproxy) {
> -		get_nsproxy(init_task.nsproxy);
> -		switch_task_namespaces(current, init_task.nsproxy);
> -	}
> -
>  	exit_files(current);
>  	current->files = init_task.files;
>  	atomic_inc(&current->files->count);
> --- PT/kernel/sys.c~2_set_special_pids	2007-11-26 16:10:43.000000000 +0300
> +++ PT/kernel/sys.c	2007-11-26 16:48:02.000000000 +0300
> @@ -1065,7 +1065,7 @@ asmlinkage long sys_setsid(void)
>  		goto out;
>  
>  	group_leader->signal->leader = 1;
> -	__set_special_pids(pid_nr(sid), pid_nr(sid));
> +	__set_special_pids(sid);
>  
>  	spin_lock(&group_leader->sighand->siglock);
>  	group_leader->signal->tty = NULL;
> --- PT/init/main.c~2_set_special_pids	2007-11-26 15:52:15.000000000 +0300
> +++ PT/init/main.c	2007-11-26 16:56:24.000000000 +0300
> @@ -829,7 +829,7 @@ static int __init kernel_init(void * unu
>  	 */
>  	init_pid_ns.child_reaper = current;
>  
> -	__set_special_pids(1, 1);
> +	__set_special_pids(task_pid(current));
>  	cad_pid = task_pid(current);
>  
>  	smp_prepare_cpus(max_cpus);
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] teach set_special_pids() to use struct pid
  2007-11-26 14:25 [PATCH 2/3] teach set_special_pids() to use struct pid Oleg Nesterov
  2007-11-26 15:02 ` Pavel Emelyanov
@ 2007-11-26 18:51 ` Eric W. Biederman
  2007-11-26 20:17   ` Oleg Nesterov
  1 sibling, 1 reply; 5+ messages in thread
From: Eric W. Biederman @ 2007-11-26 18:51 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, Pavel Emelyanov, linux-kernel

Oleg Nesterov <oleg@tv-sign.ru> writes:

> Change set_special_pids() to work with struct pid, not pid_t from global name
> space. This again speedups and imho cleanups the code.
>
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

Overall I like it, and the version I keep meaning to send missed
the fact we only need a single argument.

> -static void set_special_pids(pid_t session, pid_t pgrp)
> +static void set_special_pids(struct pid *pid)
>  {
>  	write_lock_irq(&tasklist_lock);
> -	__set_special_pids(session, pgrp);
> +	__set_special_pids(pid);
>  	write_unlock_irq(&tasklist_lock);
>  }
>  
> @@ -385,7 +386,11 @@ void daemonize(const char *name, ...)
>  	 */
>  	current->flags |= PF_NOFREEZE;
>  
> -	set_special_pids(1, 1);
> +	if (current->nsproxy != &init_nsproxy) {
> +		get_nsproxy(&init_nsproxy);
> +		switch_task_namespaces(current, &init_nsproxy);
> +	}

Is there a reason for moving this hunk of code?

I don't see one as set_special_pids does everything with either
struct pid or global pid values.  And attach_pid and detach_pid
don't care.

Eric

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] teach set_special_pids() to use struct pid
  2007-11-26 18:51 ` Eric W. Biederman
@ 2007-11-26 20:17   ` Oleg Nesterov
  2007-11-26 21:42     ` Eric W. Biederman
  0 siblings, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2007-11-26 20:17 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Andrew Morton, Pavel Emelyanov, linux-kernel

On 11/26, Eric W. Biederman wrote:
>
> Oleg Nesterov <oleg@tv-sign.ru> writes:
> 
> > -	set_special_pids(1, 1);
> > +	if (current->nsproxy != &init_nsproxy) {
> > +		get_nsproxy(&init_nsproxy);
> > +		switch_task_namespaces(current, &init_nsproxy);
> > +	}
> 
> Is there a reason for moving this hunk of code?
> 
> I don't see one as set_special_pids does everything with either
> struct pid or global pid values.  And attach_pid and detach_pid
> don't care.

No particular reason, except "keep related code together".

There was another minor reason. Without the next patch we are doing find_pid(1).
This is correct, we scan the global namespace, but still it looks a bit tidier
to switch namespace first, so we could use find_vpid() in unlikely case we need
it.

Oleg.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] teach set_special_pids() to use struct pid
  2007-11-26 20:17   ` Oleg Nesterov
@ 2007-11-26 21:42     ` Eric W. Biederman
  0 siblings, 0 replies; 5+ messages in thread
From: Eric W. Biederman @ 2007-11-26 21:42 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, Pavel Emelyanov, linux-kernel

Oleg Nesterov <oleg@tv-sign.ru> writes:

> On 11/26, Eric W. Biederman wrote:
>>
>> Oleg Nesterov <oleg@tv-sign.ru> writes:
>> 
>> > -	set_special_pids(1, 1);
>> > +	if (current->nsproxy != &init_nsproxy) {
>> > +		get_nsproxy(&init_nsproxy);
>> > +		switch_task_namespaces(current, &init_nsproxy);
>> > +	}
>> 
>> Is there a reason for moving this hunk of code?
>> 
>> I don't see one as set_special_pids does everything with either
>> struct pid or global pid values.  And attach_pid and detach_pid
>> don't care.
>
> No particular reason, except "keep related code together".
>
> There was another minor reason. Without the next patch we are doing find_pid(1).
> This is correct, we scan the global namespace, but still it looks a bit tidier
> to switch namespace first, so we could use find_vpid() in unlikely case we need
> it.

True.  I just pointed it out because it seemed an unnecessary chunk.
Regardless it is harmless either way.

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>

Eric

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-11-26 21:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-26 14:25 [PATCH 2/3] teach set_special_pids() to use struct pid Oleg Nesterov
2007-11-26 15:02 ` Pavel Emelyanov
2007-11-26 18:51 ` Eric W. Biederman
2007-11-26 20:17   ` Oleg Nesterov
2007-11-26 21:42     ` Eric W. Biederman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.