Allow cloning of new namespace
Subsystems (3)
PATCH 14/20 Allow cloning of new namespace
When clone() is invoked with CLONE_NEWPID, create a new pid namespace and then create a new struct pid for the new process. Allocate pid_t's for the new process in the new pid namespace and all ancestor pid namespaces. Make the newly cloned process the session and process group leader.
Since the active pid namespace is special and expected to be the first entry in pid->upid_list, preserve the order of pid namespaces.
The size of 'struct pid' is dependent on the the number of pid namespaces the process exists in, so we use multiple pid-caches'. Only one pid cache is created during system startup and this used by processes that exist only in init_pid_ns.
When a process clones its pid namespace, we create additional pid caches as necessary and use the pid cache to allocate 'struct pids' for that depth.
Note, that with this patch the newly created namespace won't work, since the rest of the kernel still uses global pids, but this is to be fixed soon. Init pid namespace still works.
---
include/linux/sched.h | 1 kernel/fork.c | 48 +++++++++++++++++--------- kernel/nsproxy.c | 3 + kernel/pid.c | 91 +++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 118 insertions(+), 25 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h.ve14 +1 -0
@@ -27,6 +27,7 @@#define CLONE_NEWUTS 0x04000000/* New utsname group? */ #define CLONE_NEWIPC 0x08000000/* New ipcs */ #define CLONE_NEWUSER 0x10000000/* New user namespace */ +#define CLONE_NEWPID 0x20000000/* New pids */ /* * Scheduling policies
kernel/nsproxy.c renamed from kernel/nsproxy.c.ve14 +2 -1
@@ -132,7 +132,8 @@ int copy_namespaces(unsigned long flags,get_nsproxy (old_ns); -if (!(flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC |CLONE_NEWUSER ))) +if (!(flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC | +CLONE_NEWUSER |CLONE_NEWPID )))return 0 ;if (!capable (CAP_SYS_ADMIN )) {
kernel/pid.c renamed from kernel/pid.c.ve14 +83 -8
116 lines not on this page · raw message
kernel/fork.c renamed from kernel/fork.c.ve12 +32 -16
84 lines not on this page · raw message
A message that is not in the archive (sent off-list or not yet received): [email protected]
Pavel Emelianov [[email protected]] wrote:
| When clone() is invoked with CLONE_NEWPID, create a new pid namespace | and then create a new struct pid for the new process. Allocate pid_t's | for the new process in the new pid namespace and all ancestor pid | namespaces. Make the newly cloned process the session and process group | leader. | | Since the active pid namespace is special and expected to be the first
active pid ns is the *last entry* in this patchset (not first) right ?
| entry in pid->upid_list, preserve the order of pid namespaces. | | The size of 'struct pid' is dependent on the the number of pid namespaces | the process exists in, so we use multiple pid-caches'. Only one pid cache | is created during system startup and this used by processes that exist | only in init_pid_ns. | | When a process clones its pid namespace, we create additional pid caches | as necessary and use the pid cache to allocate 'struct pids' for that depth. | | Note, that with this patch the newly created namespace won't work, since | the rest of the kernel still uses global pids, but this is to be fixed | soon. Init pid namespace still works. | | Signed-off-by: Pavel Emelyanov <[email protected]> | Signed-off-by: Sukadev Bhattiprolu <sukadev-r/[email protected]> | | --- | | include/linux/sched.h | 1 | kernel/fork.c | 48 +++++++++++++++++--------- | kernel/nsproxy.c | 3 + | kernel/pid.c | 91 +++++++++++++++++++++++++++++++++++++++++++++----- | 4 files changed, 118 insertions(+), 25 deletions(-) | | --- ./include/linux/sched.h.ve14 2007-08-06 15:00:09.000000000 +0400 | +++ ./include/linux/sched.h 2007-08-06 15:00:09.000000000 +0400 | @@ -27,6 +27,7 @@ | #define CLONE_NEWUTS 0x04000000 /* New utsname group? */ | #define CLONE_NEWIPC 0x08000000 /* New ipcs */ | #define CLONE_NEWUSER 0x10000000 /* New user namespace */ | +#define CLONE_NEWPID 0x20000000 /* New pids */
Nit. I think "New pid namespace" would be a better comment.
Suka
A message that is not in the archive (sent off-list or not yet received): 20070807224827.GA2375-r/[email protected]
Quoted 9 lines · sukadev-r/[email protected] wrote:
Pavel Emelianov [[email protected]] wrote:
| When clone() is invoked with CLONE_NEWPID, create a new pid namespace | and then create a new struct pid for the new process. Allocate pid_t's | for the new process in the new pid namespace and all ancestor pid | namespaces. Make the newly cloned process the session and process group | leader. | | Since the active pid namespace is special and expected to be the firstactive pid ns is the *last entry* in this patchset (not first) right ?
yes. thanks.
Quoted 25 lines
| entry in pid->upid_list, preserve the order of pid namespaces. | | The size of 'struct pid' is dependent on the the number of pid namespaces | the process exists in, so we use multiple pid-caches'. Only one pid cache | is created during system startup and this used by processes that exist | only in init_pid_ns. | | When a process clones its pid namespace, we create additional pid caches | as necessary and use the pid cache to allocate 'struct pids' for that depth. | | Note, that with this patch the newly created namespace won't work, since | the rest of the kernel still uses global pids, but this is to be fixed | soon. Init pid namespace still works. | | Signed-off-by: Pavel Emelyanov <[email protected]> | Signed-off-by: Sukadev Bhattiprolu <sukadev-r/[email protected]> | | --- | | include/linux/sched.h | 1 | kernel/fork.c | 48 +++++++++++++++++--------- | kernel/nsproxy.c | 3 + | kernel/pid.c | 91 +++++++++++++++++++++++++++++++++++++++++++++----- | 4 files changed, 118 insertions(+), 25 deletions(-) | | --- ./include/linux/sched.h.ve14 2007-08-06 15:00:09.000000000 +0400 | +++ ./include/linux/sched.h 2007-08-06 15:00:09.000000000 +0400 | @@ -27,6 +27,7 @@ | #define CLONE_NEWUTS 0x04000000 /* New utsname group? */ | #define CLONE_NEWIPC 0x08000000 /* New ipcs */ | #define CLONE_NEWUSER 0x10000000 /* New user namespace */ | +#define CLONE_NEWPID 0x20000000 /* New pids */
Quoted 1 line
Nit. I think "New pid namespace" would be a better comment.
ok.
Quoted 2 lines
Suka
Thanks,
Pavel