From: sukadev@us.ibm.com
To: Pavel Emelianov <xemul@openvz.org>
Cc: Andrew Morton <akpm@osdl.org>, Serge Hallyn <serue@us.ibm.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Linux Containers <containers@lists.osdl.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Kirill Korotaev <dev@openvz.org>
Subject: Re: [PATCH 10/16] Changes in copy_process() to work with pid namespaces
Date: Wed, 11 Jul 2007 17:21:02 -0700 [thread overview]
Message-ID: <20070712002102.GA11489@us.ibm.com> (raw)
In-Reply-To: <468DF888.8090408@openvz.org>
Pavel Emelianov [xemul@openvz.org] wrote:
| We must pass the namespace pointer to the alloc_pid() to
| show what namespace to allocate the pid from and we should
| call this *after* the namespace is copied.
|
| Essentially, the task->pid etc initialization is done after
| the alloc_pid().
|
| To do so I move the alloc_pid() inside copy_process() and
| introduce an argument to the alloc_pid() function.
|
| Signed-off-by: Pavel Emelianov <xemul@openvz.org>
|
| ---
|
| include/linux/pid.h | 2 +-
| kernel/fork.c | 29 +++++++++++++++++------------
| kernel/pid.c | 2 +-
| 3 files changed, 19 insertions(+), 14 deletions(-)
|
| --- ./include/linux/pid.h.ve9 2007-07-06 11:03:55.000000000 +0400
| +++ ./include/linux/pid.h 2007-07-06 11:03:55.000000000 +0400
| @@ -116,7 +116,7 @@ extern struct pid *FASTCALL(find_pid_ns(
| extern struct pid *find_get_pid(int nr);
| extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
|
| -extern struct pid *alloc_pid(void);
| +extern struct pid *alloc_pid(struct pid_namespace *ns);
| extern void FASTCALL(free_pid(struct pid *pid));
|
| /*
| --- ./kernel/fork.c.ve9 2007-07-06 11:03:55.000000000 +0400
| +++ ./kernel/fork.c 2007-07-06 11:04:07.000000000 +0400
| @@ -50,6 +50,7 @@
| #include <linux/taskstats_kern.h>
| #include <linux/random.h>
| #include <linux/tty.h>
| +#include <linux/pid.h>
|
| #include <asm/pgtable.h>
| #include <asm/pgalloc.h>
| @@ -1032,7 +1033,6 @@ static struct task_struct *copy_process(
| p->did_exec = 0;
| delayacct_tsk_init(p); /* Must remain after dup_task_struct() */
| copy_flags(clone_flags, p);
| - p->pid = pid_nr(pid);
| INIT_LIST_HEAD(&p->children);
| INIT_LIST_HEAD(&p->sibling);
| p->vfork_done = NULL;
| @@ -1107,10 +1107,6 @@ static struct task_struct *copy_process(
| p->blocked_on = NULL; /* not blocked yet */
| #endif
|
| - p->tgid = p->pid;
| - if (clone_flags & CLONE_THREAD)
| - p->tgid = current->tgid;
| -
| if ((retval = security_task_alloc(p)))
| goto bad_fork_cleanup_policy;
| if ((retval = audit_alloc(p)))
| @@ -1132,9 +1128,14 @@ static struct task_struct *copy_process(
| goto bad_fork_cleanup_mm;
| if ((retval = copy_namespaces(clone_flags, p)))
| goto bad_fork_cleanup_keys;
| + if (likely(pid == NULL)) {
| + pid = alloc_pid(p->nsproxy->pid_ns);
| + if (pid == NULL)
| + goto bad_fork_cleanup_namespaces;
| + }
| retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
| if (retval)
| - goto bad_fork_cleanup_namespaces;
| + goto bad_fork_cleanup_pid;
|
| p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
| /*
| @@ -1255,6 +1256,11 @@ static struct task_struct *copy_process(
| }
| }
|
| + p->pid = pid_nr(pid);
| + p->tgid = p->pid;
| + if (clone_flags & CLONE_THREAD)
| + p->tgid = current->tgid;
| +
| if (likely(p->pid)) {
| add_parent(p);
| if (unlikely(p->ptrace & PT_PTRACED))
| @@ -1288,6 +1294,8 @@ static struct task_struct *copy_process(
| proc_fork_connector(p);
| return p;
|
| +bad_fork_cleanup_pid:
| + free_pid(pid);
If copy_process() was called from fork_idle(), pid would refer
to &init_struct_pid. Don't you need something like:
if (pid == &init_struct_pid)
return;
in free_pid() to not do anything in that case ?
| bad_fork_cleanup_namespaces:
| exit_task_namespaces(p);
| bad_fork_cleanup_keys:
| @@ -1380,19 +1388,16 @@ long do_fork(unsigned long clone_flags,
| {
| struct task_struct *p;
| int trace = 0;
| - struct pid *pid = alloc_pid();
| long nr;
|
| - if (!pid)
| - return -EAGAIN;
| - nr = pid->nr;
| if (unlikely(current->ptrace)) {
| trace = fork_traceflag (clone_flags);
| if (trace)
| clone_flags |= CLONE_PTRACE;
| }
|
| - p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, pid);
| + p = copy_process(clone_flags, stack_start, regs, stack_size,
| + parent_tidptr, child_tidptr, NULL);
| /*
| * Do this prior waking up the new thread - the thread pointer
| * might get invalid after that point, if the thread exits quickly.
| @@ -1418,6 +1423,7 @@ long do_fork(unsigned long clone_flags,
| else
| p->state = TASK_STOPPED;
|
| + nr = pid_vnr(task_pid(p));
| if (unlikely (trace)) {
| current->ptrace_message = nr;
| ptrace_notify ((trace << 8) | SIGTRAP);
| @@ -1433,7 +1439,6 @@ long do_fork(unsigned long clone_flags,
| }
| }
| } else {
| - free_pid(pid);
| nr = PTR_ERR(p);
| }
| return nr;
| --- ./kernel/pid.c.ve9 2007-07-06 11:03:55.000000000 +0400
| +++ ./kernel/pid.c 2007-07-06 11:03:55.000000000 +0400
| @@ -206,7 +206,7 @@ fastcall void free_pid(struct pid *pid)
| call_rcu(&pid->rcu, delayed_put_pid);
| }
|
| -struct pid *alloc_pid(void)
| +struct pid *alloc_pid(struct pid_namespace *pid_ns)
| {
| struct pid *pid;
| enum pid_type type;
next prev parent reply other threads:[~2007-07-12 0:32 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-06 8:01 [PATCH 0/16] Pid namespaces Pavel Emelianov
2007-07-06 8:03 ` [PATCH 1/16] Round up the API Pavel Emelianov
2007-07-09 20:18 ` Cedric Le Goater
2007-07-10 6:40 ` Pavel Emelianov
2007-07-10 7:34 ` Andrew Morton
2007-07-06 8:03 ` [PATCH 2/16] Miscelaneous preparations for namespaces Pavel Emelianov
2007-07-09 20:22 ` Cedric Le Goater
2007-07-10 6:42 ` Pavel Emelianov
2007-07-06 8:04 ` [PATCH 3/16] Introduce MS_KERNMOUNT flag Pavel Emelianov
2007-07-06 8:05 ` [PATCH 4/16] Change data structures for pid namespaces Pavel Emelianov
2007-07-09 20:25 ` Cedric Le Goater
2007-07-10 4:32 ` sukadev
2007-07-10 7:04 ` Pavel Emelianov
2007-07-10 12:07 ` Cedric Le Goater
2007-07-06 8:05 ` [PATCH 5/16] Make proc be mountable from different " Pavel Emelianov
2007-07-06 8:06 ` [PATCH 6/16] Helpers to obtain pid numbers Pavel Emelianov
2007-07-10 5:18 ` sukadev
2007-07-10 6:49 ` Pavel Emelianov
2007-07-06 8:07 ` [PATCH 7/16] Helpers to find the task by its numerical ids Pavel Emelianov
2007-07-10 4:00 ` sukadev
2007-07-10 6:47 ` Pavel Emelianov
2007-07-06 8:07 ` [PATCH 8/16] Masquerade the siginfo when sending a pid to a foreign namespace Pavel Emelianov
2007-07-10 4:18 ` sukadev
2007-07-10 6:56 ` Pavel Emelianov
2007-07-06 8:08 ` [PATCH 9/16] Make proc_flust_task to flush entries from multiple proc trees Pavel Emelianov
2007-07-06 8:08 ` [PATCH 10/16] Changes in copy_process() to work with pid namespaces Pavel Emelianov
2007-07-12 0:21 ` sukadev [this message]
2007-07-06 8:09 ` [PATCH 11/16] Add support for multiple kmem caches for pids Pavel Emelianov
2007-07-06 8:10 ` [PATCH 12/16] Reference counting of pid naspaces by pids Pavel Emelianov
2007-07-06 8:10 ` [PATCH 13/16] Switch to operating with pid_numbers instead of pids Pavel Emelianov
2007-07-25 0:36 ` sukadev
2007-07-25 10:07 ` Pavel Emelyanov
2007-07-25 19:13 ` sukadev
2007-07-26 6:42 ` Pavel Emelyanov
2007-07-06 8:11 ` [PATCH 14/16] Make pid namespaces clonnable Pavel Emelianov
2007-07-06 8:13 ` [PATCH 15/16] Changes to show virtual ids to user Pavel Emelianov
2007-07-06 8:16 ` [PATCH 16/16] Remove already unneeded memners from struct pid Pavel Emelianov
2007-07-06 16:26 ` [PATCH 0/16] Pid namespaces Dave Hansen
2007-07-09 5:58 ` Pavel Emelianov
2007-07-09 19:58 ` Dave Hansen
2007-07-09 12:02 ` Herbert Poetzl
2007-07-09 13:16 ` Pavel Emelianov
2007-07-09 19:52 ` Herbert Poetzl
2007-07-09 20:12 ` Cedric Le Goater
2007-07-10 6:59 ` Pavel Emelianov
2007-07-09 17:46 ` Badari Pulavarty
2007-07-09 20:06 ` Cedric Le Goater
2007-07-09 23:00 ` Badari Pulavarty
2007-07-10 7:05 ` Pavel Emelianov
2007-07-10 11:30 ` Pavel Emelianov
2007-07-10 12:05 ` Daniel Lezcano
2007-07-10 13:03 ` Pavel Emelianov
2007-07-10 20:34 ` Badari Pulavarty
2007-07-10 13:06 ` Pavel Emelianov
2007-07-10 20:33 ` Badari Pulavarty
2007-07-09 21:42 ` sukadev
2007-07-10 0:29 ` sukadev
2007-07-10 9:41 ` Pavel Emelianov
2007-07-10 13:08 ` Pavel Emelianov
2007-07-10 4:26 ` sukadev
2007-07-10 7:02 ` Pavel Emelianov
2007-07-11 1:16 ` Matt Mackall
2007-07-11 6:39 ` Pavel Emelianov
2007-07-11 15:14 ` Matt Mackall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070712002102.GA11489@us.ibm.com \
--to=sukadev@us.ibm.com \
--cc=akpm@osdl.org \
--cc=containers@lists.osdl.org \
--cc=dev@openvz.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=serue@us.ibm.com \
--cc=xemul@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox