pid namespace and namespace cleanups
Subsystems (11)
cover pid namespace and namespace cleanups
Hi,
The next serie contains some cleanups on namespaces that have been lying in our container patchset for a while. The patches seem stable enough and not too controversial to be good candidates for a -mm merge.
Here's a short summary of what they are doing :
* add a process_session() helper routine
* rename 'struct namespace' to 'struct mnt_namespace'
* add pid namespace framework to nsproxy but without the unshare feature
* add a child_reaper per pid namespace
* add an id to nsproxy for a future syscall bind_ns
A next serie should follow soon, which depends on the above.
* net namespace framework, empty object without any dependency on the layer
* unshare_ns syscall (unshare dedicated to namespaces with its own flags)
* bind_ns syscall enabling a process to switch nsproxy
* more cleanups for the pid namespace
Pending patches we are still working on :
* layer 3 net namespace providing a simple and fast isolation of a net interface
* full pid namespace, this is quite complex.
Thanks,
C.
PATCH 1/7 add process_session() helper routine
This patch replaces occurences of task->signal->session by a new process_session() helper routine.
It will be useful for pid namespaces to abstract the session pid number.
This is a refreshed version for -mm of a patch previously sent
--- arch/mips/kernel/irixelf.c | 2 +- drivers/char/mxser.c | 2 +- drivers/char/rocket.c | 2 +- drivers/char/tty_io.c | 18 +++++++++--------- fs/binfmt_elf.c | 4 ++-- fs/binfmt_elf_fdpic.c | 4 ++-- include/linux/sched.h | 5 +++++ kernel/exit.c | 19 ++++++++++--------- kernel/fork.c | 4 ++-- kernel/signal.c | 2 +- kernel/sys.c | 8 ++++---- 11 files changed, 38 insertions(+), 32 deletions(-)
arch/mips/kernel/irixelf.c +1 -1
@@ -1149,7 +1149,7 @@ static int irix_core_dump(long signr, st psinfo.pr_pid = prstatus.pr_pid = current->pid; psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid; psinfo.pr_pgrp = prstatus.pr_pgrp =process_group (current); - psinfo.pr_sid = prstatus.pr_sid = current->signal->session; + psinfo.pr_sid = prstatus.pr_sid =process_session (current);if (current->pid == current->tgid) {/* * This is the record for the group leader. Add in the
drivers/char/mxser.c +1 -1
@@ -997,7 +997,7 @@ static int mxser_open(struct tty_structmxser_change_speed (info,NULL ); } - info->session = current->signal->session; + info->session =process_session (current); info->pgrp =process_group (current);/*
drivers/char/rocket.c +1 -1
@@ -1017,7 +1017,7 @@ static int rp_open(struct tty_struct *tt/* * Info->count is now 1; so it's safe to sleep now. */ - info->session = current->signal->session; + info->session =process_session (current); info->pgrp =process_group (current);if ((info->flags &ROCKET_INITIALIZED ) ==0 ) {
drivers/char/tty_io.c +9 -9
@@ -1512,9 +1512,9 @@ void disassociate_ctty(int on_exit)/* Now clear signal->tty under the lock */ read_lock (&tasklist_lock); - do_each_task_pid(current->signal->session, PIDTYPE_SID, p) { + do_each_task_pid(process_session(current), PIDTYPE_SID, p) { p->signal->tty =NULL ; - }while_each_task_pid (current->signal->session,PIDTYPE_SID , p); + }while_each_task_pid (process_session (current),PIDTYPE_SID , p);read_unlock (&tasklist_lock);mutex_unlock (&tty_mutex);unlock_kernel ();
@@ -2554,7 +2554,7 @@ got_driver: current->signal->tty = tty;task_unlock (current); current->signal->tty_old_pgrp =0 ; - tty->session = current->signal->session; + tty->session =process_session (current); tty->pgrp =process_group (current); }return 0 ;
@@ -2890,7 +2890,7 @@ static int tiocsctty(struct tty_struct *struct task_struct *p;if (current->signal->leader && - (current->signal->session == tty->session)) + (process_session (current) == tty->session))return 0 ;/* * The process must be a session leader and
@@ -2922,7 +2922,7 @@ static int tiocsctty(struct tty_struct *task_unlock (current);mutex_unlock (&tty_mutex); current->signal->tty_old_pgrp =0 ; - tty->session = current->signal->session; + tty->session =process_session (current); tty->pgrp =process_group (current);return 0 ; }
@@ -2973,13 +2973,13 @@ static int tiocspgrp(struct tty_struct *return retval;if (!current->signal->tty || (current->signal->tty != real_tty) || - (real_tty->session != current->signal->session)) + (real_tty->session !=process_session (current)))return -ENOTTY ;if (get_user (pgrp, p))return -EFAULT ;if (pgrp <0 )return -EINVAL ; -if (session_of_pgrp (pgrp) != current->signal->session) +if (session_of_pgrp (pgrp) !=process_session (current))return -EPERM ; real_tty->pgrp = pgrp;return 0 ;
@@ -3334,7 +3334,7 @@ static void __do_SAK(void *arg)/* Kill the entire session */ do_each_task_pid(session, PIDTYPE_SID, p) {printk (KERN_NOTICE "SAK: killed process %d" -" (%s): p->signal->session==tty->session\n" , +" (%s): process_session(p)==tty->session\n" , p->pid, p->comm);send_sig (SIGKILL , p,1 ); }while_each_task_pid (session,PIDTYPE_SID , p);
@@ -3344,7 +3344,7 @@ static void __do_SAK(void *arg) do_each_thread(g, p) {if (p->signal->tty == tty) {printk (KERN_NOTICE "SAK: killed process %d" -" (%s): p->signal->session==tty->session\n" , +" (%s): process_session(p)==tty->session\n" , p->pid, p->comm);send_sig (SIGKILL , p,1 );continue ;
fs/binfmt_elf.c +2 -2
@@ -1313,7 +1313,7 @@ static void fill_prstatus(struct elf_prs prstatus->pr_pid = p->pid; prstatus->pr_ppid = p->parent->pid; prstatus->pr_pgrp =process_group (p); - prstatus->pr_sid = p->signal->session; + prstatus->pr_sid =process_session (p);if (thread_group_leader (p)) {/* * This is the record for the group leader. Add in the
@@ -1359,7 +1359,7 @@ static int fill_psinfo(struct elf_prpsin psinfo->pr_pid = p->pid; psinfo->pr_ppid = p->parent->pid; psinfo->pr_pgrp =process_group (p); - psinfo->pr_sid = p->signal->session; + psinfo->pr_sid =process_session (p); i = p->state ?ffz (~p->state) +1 :0 ; psinfo->pr_state = i;
fs/binfmt_elf_fdpic.c +2 -2
@@ -1325,7 +1325,7 @@ static void fill_prstatus(struct elf_prs prstatus->pr_pid = p->pid; prstatus->pr_ppid = p->parent->pid; prstatus->pr_pgrp =process_group (p); - prstatus->pr_sid = p->signal->session; + prstatus->pr_sid =process_session (p);if (thread_group_leader (p)) {/* * This is the record for the group leader. Add in the
@@ -1374,7 +1374,7 @@ static int fill_psinfo(struct elf_prpsin psinfo->pr_pid = p->pid; psinfo->pr_ppid = p->parent->pid; psinfo->pr_pgrp =process_group (p); - psinfo->pr_sid = p->signal->session; + psinfo->pr_sid =process_session (p); i = p->state ?ffz (~p->state) +1 :0 ; psinfo->pr_state = i;
include/linux/sched.h +5 -0
@@ -1067,6 +1067,11 @@ static inline pid_t process_group(structreturn tsk->signal->pgrp; } +static inline pid_t process_session (struct task_struct *tsk) +{ +return tsk->signal->session; +} +static inline struct pid *task_pid (struct task_struct *task) {return task->pids[PIDTYPE_PID ].pid;
kernel/exit.c +10 -9
@@ -192,14 +192,14 @@ int session_of_pgrp(int pgrp)read_lock (&tasklist_lock); do_each_task_pid(pgrp, PIDTYPE_PGID, p) { -if (p->signal->session >0 ) { - sid = p->signal->session; +if (process_session (p) >0 ) { + sid =process_session (p); goto out; } }while_each_task_pid (pgrp,PIDTYPE_PGID , p); p =find_task_by_pid (pgrp);if (p) - sid = p->signal->session; + sid =process_session (p); out:read_unlock (&tasklist_lock);
@@ -224,8 +224,8 @@ static int will_become_orphaned_pgrp(int || p->exit_state || is_init(p->real_parent))continue ; -if (process_group (p->real_parent) != pgrp - && p->real_parent->signal->session == p->signal->session) { +if (process_group (p->real_parent) != pgrp && +process_session (p->real_parent) ==process_session (p)) { ret =0 ;break ; }
@@ -301,7 +301,7 @@ void __set_special_pids(pid_t session, p {struct task_struct *curr = current->group_leader; -if (curr->signal->session != session) { +if (process_session (curr) != session) {detach_pid (curr,PIDTYPE_SID ); curr->signal->session = session;attach_pid (curr,PIDTYPE_SID , session);
@@ -646,10 +646,11 @@ reparent_thread(struct task_struct *p, s* outside, so the child pgrp is now orphaned. */ if ((process_group (p) !=process_group (father)) && - (p->signal->session == father->signal->session)) { + (process_session (p) ==process_session (father))) {int pgrp =process_group (p); -if (will_become_orphaned_pgrp (pgrp,NULL ) &&has_stopped_jobs (pgrp)) { +if (will_become_orphaned_pgrp (pgrp,NULL ) && +has_stopped_jobs (pgrp)) {__kill_pg_info (SIGHUP ,SEND_SIG_PRIV , pgrp);__kill_pg_info (SIGCONT ,SEND_SIG_PRIV , pgrp); }
@@ -783,7 +784,7 @@ static void exit_notify(struct task_stru t = tsk->real_parent;if ((process_group (t) !=process_group (tsk)) && - (t->signal->session == tsk->signal->session) && + (process_session (t) ==process_session (tsk)) &&will_become_orphaned_pgrp (process_group (tsk), tsk) &&has_stopped_jobs (process_group (tsk))) {__kill_pg_info (SIGHUP ,SEND_SIG_PRIV ,process_group (tsk));
kernel/fork.c +2 -2
@@ -1236,9 +1236,9 @@ static struct task_struct *copy_process(if (thread_group_leader (p)) { p->signal->tty = current->signal->tty; p->signal->pgrp =process_group (current); - p->signal->session = current->signal->session; + p->signal->session =process_session (current);attach_pid (p,PIDTYPE_PGID ,process_group (p)); -attach_pid (p,PIDTYPE_SID , p->signal->session); +attach_pid (p,PIDTYPE_SID ,process_session (p));list_add_tail_rcu (&p->tasks, &init_task.tasks);__get_cpu_var (process_counts)++;
kernel/signal.c +1 -1
@@ -576,7 +576,7 @@ static int check_kill_permission(int sig error = -EPERM ;if ((info ==SEND_SIG_NOINFO || (!is_si_special (info) &&SI_FROMUSER (info))) && ((sig !=SIGCONT ) || - (current->signal->session != t->signal->session)) + (process_session (current) !=process_session (t))) && (current->euid ^ t->suid) && (current->euid ^ t->uid) && (current->uid ^ t->suid) && (current->uid ^ t->uid) && !capable (CAP_KILL ))
kernel/sys.c +4 -4
@@ -1381,7 +1381,7 @@ asmlinkage long sys_setpgid(pid_t pid, pif (p->real_parent == group_leader) { err = -EPERM ; -if (p->signal->session != group_leader->signal->session) +if (process_session (p) !=process_session (group_leader)) goto out; err = -EACCES ;if (p->did_exec)
@@ -1400,7 +1400,7 @@ asmlinkage long sys_setpgid(pid_t pid, pstruct task_struct *p; do_each_task_pid(pgid, PIDTYPE_PGID, p) { -if (p->signal->session == group_leader->signal->session) +if (process_session (p) ==process_session (group_leader)) goto ok_pgid; }while_each_task_pid (pgid,PIDTYPE_PGID , p); goto out;
@@ -1459,7 +1459,7 @@ asmlinkage long sys_getpgrp(void)asmlinkage long sys_getsid (pid_t pid) {if (!pid) -return current->signal->session; +return process_session (current);else {int retval;struct task_struct *p;
@@ -1471,7 +1471,7 @@ asmlinkage long sys_getsid(pid_t pid)if (p) { retval =security_task_getsid (p);if (!retval) - retval = p->signal->session; + retval =process_session (p); }read_unlock (&tasklist_lock);return retval;
--
PATCH 2/7 rename struct namespace to struct mnt_namespace
In reply to Cedric Le Goaterthis patch renames 'struct namespace' to 'struct mnt_namespace' to avoid confusion with other namespaces being developped for the containers : pid, uts, ipc, etc. 'namespace' variables and attributes are also renamed to 'mnt_ns'
--- fs/afs/mntpt.c | 2 fs/cachefiles/cf-bind.c | 2 fs/cachefiles/cf-proc.c | 3 - fs/namespace.c | 109 +++++++++++++++++++++--------------------- fs/nfs/getroot.c | 2 fs/pnode.c | 2 fs/pnode.h | 2 fs/proc/base.c | 36 ++++++------- fs/reiserfs/super.c | 2 include/linux/init_task.h | 2 include/linux/mnt_namespace.h | 42 ++++++++++++++++ include/linux/mount.h | 4 - include/linux/namespace.h | 42 ---------------- include/linux/nsproxy.h | 4 - kernel/exit.c | 2 kernel/fork.c | 21 ++++---- kernel/kmod.c | 2 kernel/nsproxy.c | 16 +++--- 18 files changed, 148 insertions(+), 147 deletions(-)
fs/afs/mntpt.c +1 -1
@@ -18,7 +18,7 @@#include <linux/pagemap.h> #include <linux/mount.h> #include <linux/namei.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include "super.h" #include "cell.h" #include "volume.h"
fs/namespace.c +55 -54
280 lines not on this page · raw message
fs/pnode.c +1 -1
@@ -6,7 +6,7 @@* Author : Ram Pai ([email protected]) * */ -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/mount.h> #include <linux/fs.h> #include "pnode.h"
fs/pnode.h +1 -1
@@ -13,7 +13,7 @@#define IS_MNT_SHARED (mnt) (mnt->mnt_flags & MNT_SHARED)#define IS_MNT_SLAVE (mnt) (mnt->mnt_master) -#define IS_MNT_NEW (mnt) (!mnt->mnt_namespace) +#define IS_MNT_NEW (mnt) (!mnt->mnt_ns)#define CLEAR_MNT_SHARED (mnt) (mnt->mnt_flags &= ~MNT_SHARED)#define IS_MNT_UNBINDABLE (mnt) (mnt->mnt_flags & MNT_UNBINDABLE)
fs/proc/base.c +18 -18
@@ -59,7 +59,7 @@#include <linux/string.h> #include <linux/seq_file.h> #include <linux/namei.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/mm.h> #include <linux/smp_lock.h> #include <linux/rcupdate.h>
@@ -364,33 +364,33 @@ struct proc_mounts {static int mounts_open (struct inode *inode,struct file *file) {struct task_struct *task =get_proc_task (inode); -struct namespace *namespace =NULL ; +struct mnt_namespace *ns =NULL ;struct proc_mounts *p;int ret = -EINVAL ;if (task) {task_lock (task); - namespace = task->nsproxy->namespace; -if (namespace) -get_namespace (namespace); + ns = task->nsproxy->mnt_ns; +if (ns) +get_mnt_ns (ns);task_unlock (task);put_task_struct (task); } -if (namespace) { +if (ns) { ret = -ENOMEM ; p =kmalloc (sizeof (struct proc_mounts ),GFP_KERNEL );if (p) { file->private_data = &p->m; ret =seq_open (file, &mounts_op);if (!ret) { - p->m.private = namespace; - p->event = namespace->event; + p->m.private = ns; + p->event = ns->event;return 0 ; }kfree (p); } -put_namespace (namespace); +put_mnt_ns (ns); }return ret; }
@@ -398,15 +398,15 @@ static int mounts_open(struct inode *inostatic int mounts_release (struct inode *inode,struct file *file) {struct seq_file *m = file->private_data; -struct namespace *namespace = m->private; -put_namespace (namespace); +struct mnt_namespace *ns = m->private; +put_mnt_ns (ns);return seq_release (inode, file); }static unsigned mounts_poll (struct file *file,poll_table *wait) {struct proc_mounts *p = file->private_data; -struct namespace *ns = p->m.private; +struct mnt_namespace *ns = p->m.private;unsigned res =0 ;poll_wait (file, &ns->poll, wait);
@@ -436,20 +436,20 @@ static int mountstats_open(struct inodeif (!ret) {struct seq_file *m = file->private_data; -struct namespace *namespace =NULL ; +struct mnt_namespace *mnt_ns =NULL ;struct task_struct *task =get_proc_task (inode);if (task) {task_lock (task); - namespace = task->nsproxy->namespace; -if (namespace) -get_namespace (namespace); + mnt_ns = task->nsproxy->mnt_ns; +if (mnt_ns) +get_mnt_ns (mnt_ns);task_unlock (task);put_task_struct (task); } -if (namespace) - m->private = namespace; +if (mnt_ns) + m->private = mnt_ns;else {seq_release (inode, file); ret = -EINVAL ;
fs/reiserfs/super.c +1 -1
@@ -23,7 +23,7 @@#include <linux/blkdev.h> #include <linux/buffer_head.h> #include <linux/vfs.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/mount.h> #include <linux/namei.h> #include <linux/quotaops.h>
include/linux/init_task.h +1 -1
@@ -75,7 +75,7 @@ extern struct nsproxy init_nsproxy; .count = ATOMIC_INIT(1), \ .nslock = SPIN_LOCK_UNLOCKED, \ .uts_ns = &init_uts_ns, \ - .namespace = NULL, \ + .mnt_ns = NULL, \ INIT_IPC_NS(ipc_ns) \ }
include/linux/mnt_namespace.h new file +42 -0
42 lines not on this page · raw message
include/linux/mount.h +2 -2
@@ -20,7 +20,7 @@struct super_block ;struct vfsmount ;struct dentry ; -struct namespace ; +struct mnt_namespace ;#define MNT_NOSUID 0x01#define MNT_NODEV 0x02
@@ -52,7 +52,7 @@ struct vfsmount {struct list_head mnt_slave_list;/* list of slave mounts */ struct list_head mnt_slave;/* slave list entry */ struct vfsmount *mnt_master;/* slave is on master->mnt_slave_list */ -struct namespace *mnt_namespace;/* containing namespace */ +struct mnt_namespace *mnt_ns;/* containing namespace */ int mnt_pinned; };
include/linux/namespace.h deleted +0 -42
42 lines not on this page · raw message
include/linux/nsproxy.h +2 -2
@@ -4,7 +4,7 @@#include <linux/spinlock.h> #include <linux/sched.h> -struct namespace ; +struct mnt_namespace ;struct uts_namespace ;struct ipc_namespace ;
@@ -25,7 +25,7 @@ struct nsproxy {spinlock_t nslock;struct uts_namespace *uts_ns;struct ipc_namespace *ipc_ns; -struct namespace *namespace; +struct mnt_namespace *mnt_ns; };extern struct nsproxy init_nsproxy;
kernel/exit.c +1 -1
@@ -13,7 +13,7 @@#include <linux/completion.h> #include <linux/personality.h> #include <linux/tty.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/key.h> #include <linux/security.h> #include <linux/cpu.h>
kernel/fork.c +11 -10
@@ -18,7 +18,7 @@#include <linux/module.h> #include <linux/vmalloc.h> #include <linux/completion.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/personality.h> #include <linux/mempolicy.h> #include <linux/sem.h>
@@ -1507,17 +1507,18 @@ static int unshare_fs(unsigned long unsh }/* -* Unshare the namespace structure if it is being shared +* Unshare the mnt_namespace structure if it is being shared */ -static int unshare_namespace (unsigned long unshare_flags,struct namespace **new_nsp,struct fs_struct *new_fs) +static int unshare_mnt_namespace (unsigned long unshare_flags, +struct mnt_namespace **new_nsp,struct fs_struct *new_fs) { -struct namespace *ns = current->nsproxy->namespace; +struct mnt_namespace *ns = current->nsproxy->mnt_ns;if ((unshare_flags &CLONE_NEWNS ) && ns) {if (!capable (CAP_SYS_ADMIN ))return -EPERM ; - *new_nsp =dup_namespace (current, new_fs ? new_fs : current->fs); + *new_nsp =dup_mnt_ns (current, new_fs ? new_fs : current->fs);if (!*new_nsp)return -ENOMEM ; }
@@ -1607,7 +1608,7 @@ asmlinkage long sys_unshare(unsigned lon {int err =0 ;struct fs_struct *fs, *new_fs =NULL ; -struct namespace *ns, *new_ns =NULL ; +struct mnt_namespace *ns, *new_ns =NULL ;struct sighand_struct *sigh, *new_sigh =NULL ;struct mm_struct *mm, *new_mm =NULL , *active_mm =NULL ;struct files_struct *fd, *new_fd =NULL ;
@@ -1629,7 +1630,7 @@ asmlinkage long sys_unshare(unsigned lon goto bad_unshare_out;if ((err =unshare_fs (unshare_flags, &new_fs))) goto bad_unshare_cleanup_thread; -if ((err =unshare_namespace (unshare_flags, &new_ns, new_fs))) +if ((err =unshare_mnt_namespace (unshare_flags, &new_ns, new_fs))) goto bad_unshare_cleanup_fs;if ((err =unshare_sighand (unshare_flags, &new_sigh))) goto bad_unshare_cleanup_ns;
@@ -1670,8 +1671,8 @@ asmlinkage long sys_unshare(unsigned lon }if (new_ns) { - ns = current->nsproxy->namespace; - current->nsproxy->namespace = new_ns; + ns = current->nsproxy->mnt_ns; + current->nsproxy->mnt_ns = new_ns; new_ns = ns; }
@@ -1738,7 +1739,7 @@ bad_unshare_cleanup_sigh: bad_unshare_cleanup_ns:if (new_ns) -put_namespace (new_ns); +put_mnt_ns (new_ns); bad_unshare_cleanup_fs:if (new_fs)
kernel/kmod.c +1 -1
@@ -25,7 +25,7 @@#include <linux/kmod.h> #include <linux/smp_lock.h> #include <linux/slab.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/completion.h> #include <linux/file.h> #include <linux/workqueue.h>
kernel/nsproxy.c +8 -8
@@ -17,7 +17,7 @@#include <linux/version.h> #include <linux/nsproxy.h> #include <linux/init_task.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/utsname.h> struct nsproxy init_nsproxy =INIT_NSPROXY (init_nsproxy);
@@ -62,8 +62,8 @@ struct nsproxy *dup_namespaces(struct nsstruct nsproxy *ns =clone_namespaces (orig);if (ns) { -if (ns->namespace) -get_namespace (ns->namespace); +if (ns->mnt_ns) +get_mnt_ns (ns->mnt_ns);if (ns->uts_ns)get_uts_ns (ns->uts_ns);if (ns->ipc_ns)
@@ -99,7 +99,7 @@ int copy_namespaces(int flags, struct ta tsk->nsproxy = new_ns; - err =copy_namespace (flags, tsk); + err =copy_mnt_ns (flags, tsk);if (err) goto out_ns;
@@ -119,8 +119,8 @@ out_ipc:if (new_ns->uts_ns)put_uts_ns (new_ns->uts_ns); out_uts: -if (new_ns->namespace) -put_namespace (new_ns->namespace); +if (new_ns->mnt_ns) +put_mnt_ns (new_ns->mnt_ns); out_ns: tsk->nsproxy = old_ns;kfree (new_ns);
@@ -129,8 +129,8 @@ out_ns:void free_nsproxy (struct nsproxy *ns) { -if (ns->namespace) -put_namespace (ns->namespace); +if (ns->mnt_ns) +put_mnt_ns (ns->mnt_ns);if (ns->uts_ns)put_uts_ns (ns->uts_ns);if (ns->ipc_ns)
fs/cachefiles/cf-bind.c +1 -1
@@ -18,7 +18,7 @@#include <linux/file.h> #include <linux/namei.h> #include <linux/mount.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/statfs.h> #include <linux/proc_fs.h> #include <linux/ctype.h>
fs/cachefiles/cf-proc.c +1 -2
@@ -18,7 +18,7 @@#include <linux/file.h> #include <linux/namei.h> #include <linux/mount.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/statfs.h> #include <linux/proc_fs.h> #include <linux/ctype.h>
@@ -70,7 +70,6 @@ static const struct cachefiles_proc_cmd { "", NULL } }; -/*****************************************************************************/ /* * do various checks
fs/nfs/getroot.c +1 -1
@@ -31,7 +31,7 @@#include <linux/nfs_idmap.h> #include <linux/vfs.h> #include <linux/namei.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/security.h> #include <asm/system.h>
--
Re: [patch -mm 2/7] rename struct namespace to struct mnt_namespace
My mailer or quilt (i have to check) didn't respect the initial From: I had in my patch, again.
here's the real patch.
C.
From: Kirill Korotaev <[email protected]>
Subject: rename struct namespace to struct mnt_namespace
this patch renames 'struct namespace' to 'struct mnt_namespace' to avoid confusion with other namespaces being developped for the containers : pid, uts, ipc, etc. 'namespace' variables and attributes are also renamed to 'mnt_ns'
--- fs/afs/mntpt.c | 2 fs/cachefiles/cf-bind.c | 2 fs/cachefiles/cf-proc.c | 3 - fs/namespace.c | 109 +++++++++++++++++++++--------------------- fs/nfs/getroot.c | 2 fs/pnode.c | 2 fs/pnode.h | 2 fs/proc/base.c | 36 ++++++------- fs/reiserfs/super.c | 2 include/linux/init_task.h | 2 include/linux/mnt_namespace.h | 42 ++++++++++++++++ include/linux/mount.h | 4 - include/linux/namespace.h | 42 ---------------- include/linux/nsproxy.h | 4 - kernel/exit.c | 2 kernel/fork.c | 21 ++++---- kernel/kmod.c | 2 kernel/nsproxy.c | 16 +++--- 18 files changed, 148 insertions(+), 147 deletions(-)
fs/afs/mntpt.c +1 -1
@@ -18,7 +18,7 @@#include <linux/pagemap.h> #include <linux/mount.h> #include <linux/namei.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include "super.h" #include "cell.h" #include "volume.h"
fs/namespace.c +55 -54
280 lines not on this page · raw message
fs/pnode.c +1 -1
@@ -6,7 +6,7 @@* Author : Ram Pai ([email protected]) * */ -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/mount.h> #include <linux/fs.h> #include "pnode.h"
fs/pnode.h +1 -1
@@ -13,7 +13,7 @@#define IS_MNT_SHARED (mnt) (mnt->mnt_flags & MNT_SHARED)#define IS_MNT_SLAVE (mnt) (mnt->mnt_master) -#define IS_MNT_NEW (mnt) (!mnt->mnt_namespace) +#define IS_MNT_NEW (mnt) (!mnt->mnt_ns)#define CLEAR_MNT_SHARED (mnt) (mnt->mnt_flags &= ~MNT_SHARED)#define IS_MNT_UNBINDABLE (mnt) (mnt->mnt_flags & MNT_UNBINDABLE)
fs/proc/base.c +18 -18
@@ -59,7 +59,7 @@#include <linux/string.h> #include <linux/seq_file.h> #include <linux/namei.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/mm.h> #include <linux/smp_lock.h> #include <linux/rcupdate.h>
@@ -364,33 +364,33 @@ struct proc_mounts {static int mounts_open (struct inode *inode,struct file *file) {struct task_struct *task =get_proc_task (inode); -struct namespace *namespace =NULL ; +struct mnt_namespace *ns =NULL ;struct proc_mounts *p;int ret = -EINVAL ;if (task) {task_lock (task); - namespace = task->nsproxy->namespace; -if (namespace) -get_namespace (namespace); + ns = task->nsproxy->mnt_ns; +if (ns) +get_mnt_ns (ns);task_unlock (task);put_task_struct (task); } -if (namespace) { +if (ns) { ret = -ENOMEM ; p =kmalloc (sizeof (struct proc_mounts ),GFP_KERNEL );if (p) { file->private_data = &p->m; ret =seq_open (file, &mounts_op);if (!ret) { - p->m.private = namespace; - p->event = namespace->event; + p->m.private = ns; + p->event = ns->event;return 0 ; }kfree (p); } -put_namespace (namespace); +put_mnt_ns (ns); }return ret; }
@@ -398,15 +398,15 @@ static int mounts_open(struct inode *inostatic int mounts_release (struct inode *inode,struct file *file) {struct seq_file *m = file->private_data; -struct namespace *namespace = m->private; -put_namespace (namespace); +struct mnt_namespace *ns = m->private; +put_mnt_ns (ns);return seq_release (inode, file); }static unsigned mounts_poll (struct file *file,poll_table *wait) {struct proc_mounts *p = file->private_data; -struct namespace *ns = p->m.private; +struct mnt_namespace *ns = p->m.private;unsigned res =0 ;poll_wait (file, &ns->poll, wait);
@@ -436,20 +436,20 @@ static int mountstats_open(struct inodeif (!ret) {struct seq_file *m = file->private_data; -struct namespace *namespace =NULL ; +struct mnt_namespace *mnt_ns =NULL ;struct task_struct *task =get_proc_task (inode);if (task) {task_lock (task); - namespace = task->nsproxy->namespace; -if (namespace) -get_namespace (namespace); + mnt_ns = task->nsproxy->mnt_ns; +if (mnt_ns) +get_mnt_ns (mnt_ns);task_unlock (task);put_task_struct (task); } -if (namespace) - m->private = namespace; +if (mnt_ns) + m->private = mnt_ns;else {seq_release (inode, file); ret = -EINVAL ;
fs/reiserfs/super.c +1 -1
@@ -23,7 +23,7 @@#include <linux/blkdev.h> #include <linux/buffer_head.h> #include <linux/vfs.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/mount.h> #include <linux/namei.h> #include <linux/quotaops.h>
include/linux/init_task.h +1 -1
@@ -75,7 +75,7 @@ extern struct nsproxy init_nsproxy; .count = ATOMIC_INIT(1), \ .nslock = SPIN_LOCK_UNLOCKED, \ .uts_ns = &init_uts_ns, \ - .namespace = NULL, \ + .mnt_ns = NULL, \ INIT_IPC_NS(ipc_ns) \ }
include/linux/mnt_namespace.h new file +42 -0
42 lines not on this page · raw message
include/linux/mount.h +2 -2
@@ -20,7 +20,7 @@struct super_block ;struct vfsmount ;struct dentry ; -struct namespace ; +struct mnt_namespace ;#define MNT_NOSUID 0x01#define MNT_NODEV 0x02
@@ -52,7 +52,7 @@ struct vfsmount {struct list_head mnt_slave_list;/* list of slave mounts */ struct list_head mnt_slave;/* slave list entry */ struct vfsmount *mnt_master;/* slave is on master->mnt_slave_list */ -struct namespace *mnt_namespace;/* containing namespace */ +struct mnt_namespace *mnt_ns;/* containing namespace */ int mnt_pinned; };
include/linux/namespace.h deleted +0 -42
42 lines not on this page · raw message
include/linux/nsproxy.h +2 -2
@@ -4,7 +4,7 @@#include <linux/spinlock.h> #include <linux/sched.h> -struct namespace ; +struct mnt_namespace ;struct uts_namespace ;struct ipc_namespace ;
@@ -25,7 +25,7 @@ struct nsproxy {spinlock_t nslock;struct uts_namespace *uts_ns;struct ipc_namespace *ipc_ns; -struct namespace *namespace; +struct mnt_namespace *mnt_ns; };extern struct nsproxy init_nsproxy;
kernel/exit.c +1 -1
@@ -13,7 +13,7 @@#include <linux/completion.h> #include <linux/personality.h> #include <linux/tty.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/key.h> #include <linux/security.h> #include <linux/cpu.h>
kernel/fork.c +11 -10
@@ -18,7 +18,7 @@#include <linux/module.h> #include <linux/vmalloc.h> #include <linux/completion.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/personality.h> #include <linux/mempolicy.h> #include <linux/sem.h>
@@ -1507,17 +1507,18 @@ static int unshare_fs(unsigned long unsh }/* -* Unshare the namespace structure if it is being shared +* Unshare the mnt_namespace structure if it is being shared */ -static int unshare_namespace (unsigned long unshare_flags,struct namespace **new_nsp,struct fs_struct *new_fs) +static int unshare_mnt_namespace (unsigned long unshare_flags, +struct mnt_namespace **new_nsp,struct fs_struct *new_fs) { -struct namespace *ns = current->nsproxy->namespace; +struct mnt_namespace *ns = current->nsproxy->mnt_ns;if ((unshare_flags &CLONE_NEWNS ) && ns) {if (!capable (CAP_SYS_ADMIN ))return -EPERM ; - *new_nsp =dup_namespace (current, new_fs ? new_fs : current->fs); + *new_nsp =dup_mnt_ns (current, new_fs ? new_fs : current->fs);if (!*new_nsp)return -ENOMEM ; }
@@ -1607,7 +1608,7 @@ asmlinkage long sys_unshare(unsigned lon {int err =0 ;struct fs_struct *fs, *new_fs =NULL ; -struct namespace *ns, *new_ns =NULL ; +struct mnt_namespace *ns, *new_ns =NULL ;struct sighand_struct *sigh, *new_sigh =NULL ;struct mm_struct *mm, *new_mm =NULL , *active_mm =NULL ;struct files_struct *fd, *new_fd =NULL ;
@@ -1629,7 +1630,7 @@ asmlinkage long sys_unshare(unsigned lon goto bad_unshare_out;if ((err =unshare_fs (unshare_flags, &new_fs))) goto bad_unshare_cleanup_thread; -if ((err =unshare_namespace (unshare_flags, &new_ns, new_fs))) +if ((err =unshare_mnt_namespace (unshare_flags, &new_ns, new_fs))) goto bad_unshare_cleanup_fs;if ((err =unshare_sighand (unshare_flags, &new_sigh))) goto bad_unshare_cleanup_ns;
@@ -1670,8 +1671,8 @@ asmlinkage long sys_unshare(unsigned lon }if (new_ns) { - ns = current->nsproxy->namespace; - current->nsproxy->namespace = new_ns; + ns = current->nsproxy->mnt_ns; + current->nsproxy->mnt_ns = new_ns; new_ns = ns; }
@@ -1738,7 +1739,7 @@ bad_unshare_cleanup_sigh: bad_unshare_cleanup_ns:if (new_ns) -put_namespace (new_ns); +put_mnt_ns (new_ns); bad_unshare_cleanup_fs:if (new_fs)
kernel/kmod.c +1 -1
@@ -25,7 +25,7 @@#include <linux/kmod.h> #include <linux/smp_lock.h> #include <linux/slab.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/completion.h> #include <linux/file.h> #include <linux/workqueue.h>
kernel/nsproxy.c +8 -8
@@ -17,7 +17,7 @@#include <linux/version.h> #include <linux/nsproxy.h> #include <linux/init_task.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/utsname.h> struct nsproxy init_nsproxy =INIT_NSPROXY (init_nsproxy);
@@ -62,8 +62,8 @@ struct nsproxy *dup_namespaces(struct nsstruct nsproxy *ns =clone_namespaces (orig);if (ns) { -if (ns->namespace) -get_namespace (ns->namespace); +if (ns->mnt_ns) +get_mnt_ns (ns->mnt_ns);if (ns->uts_ns)get_uts_ns (ns->uts_ns);if (ns->ipc_ns)
@@ -99,7 +99,7 @@ int copy_namespaces(int flags, struct ta tsk->nsproxy = new_ns; - err =copy_namespace (flags, tsk); + err =copy_mnt_ns (flags, tsk);if (err) goto out_ns;
@@ -119,8 +119,8 @@ out_ipc:if (new_ns->uts_ns)put_uts_ns (new_ns->uts_ns); out_uts: -if (new_ns->namespace) -put_namespace (new_ns->namespace); +if (new_ns->mnt_ns) +put_mnt_ns (new_ns->mnt_ns); out_ns: tsk->nsproxy = old_ns;kfree (new_ns);
@@ -129,8 +129,8 @@ out_ns:void free_nsproxy (struct nsproxy *ns) { -if (ns->namespace) -put_namespace (ns->namespace); +if (ns->mnt_ns) +put_mnt_ns (ns->mnt_ns);if (ns->uts_ns)put_uts_ns (ns->uts_ns);if (ns->ipc_ns)
fs/cachefiles/cf-bind.c +1 -1
@@ -18,7 +18,7 @@#include <linux/file.h> #include <linux/namei.h> #include <linux/mount.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/statfs.h> #include <linux/proc_fs.h> #include <linux/ctype.h>
fs/cachefiles/cf-proc.c +1 -2
@@ -18,7 +18,7 @@#include <linux/file.h> #include <linux/namei.h> #include <linux/mount.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/statfs.h> #include <linux/proc_fs.h> #include <linux/ctype.h>
@@ -70,7 +70,6 @@ static const struct cachefiles_proc_cmd { "", NULL } }; -/*****************************************************************************/ /* * do various checks
fs/nfs/getroot.c +1 -1
@@ -31,7 +31,7 @@#include <linux/nfs_idmap.h> #include <linux/vfs.h> #include <linux/namei.h> -#include <linux/namespace.h> +#include <linux/mnt_namespace.h> #include <linux/security.h> #include <asm/system.h>
PATCH 3/7 add an identifier to nsproxy
In reply to Cedric Le GoaterThis patch adds an identifier to nsproxy. The default init_ns_proxy has identifier 0 and allocated nsproxies are given -1.
This identifier will be used by a new syscall sys_bind_ns.
--- include/linux/init_task.h | 1 + include/linux/nsproxy.h | 1 + kernel/nsproxy.c | 1 + 3 files changed, 3 insertions(+)
include/linux/init_task.h +1 -0
@@ -72,6 +72,7 @@ extern struct nsproxy init_nsproxy;#define INIT_NSPROXY (nsproxy) { \ .count = ATOMIC_INIT(1), \ .nslock = SPIN_LOCK_UNLOCKED, \ + .id = 0, \ .uts_ns = &init_uts_ns, \ .mnt_ns = NULL, \ INIT_IPC_NS(ipc_ns) \
include/linux/nsproxy.h +1 -0
@@ -23,6 +23,7 @@ struct ipc_namespace;struct nsproxy {atomic_t count;spinlock_t nslock; +unsigned long id;struct uts_namespace *uts_ns;struct ipc_namespace *ipc_ns;struct mnt_namespace *mnt_ns;
kernel/nsproxy.c +1 -0
@@ -48,6 +48,7 @@ static inline struct nsproxy *clone_nameif (ns) {memcpy (ns, orig,sizeof (struct nsproxy ));atomic_set (&ns->count,1 ); + ns->id =-1 ; }return ns; }
--
PATCH 4/7 rename struct pspace to struct pid_namespace
In reply to Cedric Le GoaterRename struct pspace to struct pid_namespace for consistency with other namespaces (uts_namespace and ipc_namespace). Also rename include/linux/pspace.h to include/linux/pid_namespace.h and variables from pspace to pid_ns.
--- fs/proc/proc_misc.c | 4 +-- include/linux/pid_namespace.h | 23 +++++++++++++++++++ include/linux/pspace.h | 23 ------------------- kernel/pid.c | 49 +++++++++++++++++++++--------------------- 4 files changed, 50 insertions(+), 49 deletions(-)
include/linux/pid_namespace.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef _LINUX_PID_NS_H +#define _LINUX_PID_NS_H + +#include <linux/sched.h> +#include <linux/mm.h> +#include <linux/threads.h> +#include <linux/pid.h> + +struct pidmap { +atomic_t nr_free; +void *page; +}; + +#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8) + +struct pid_namespace { +struct pidmap pidmap[PIDMAP_ENTRIES ]; +int last_pid; +}; + +extern struct pid_namespace init_pid_ns; + +#endif /* _LINUX_PID_NS_H */
include/linux/pspace.h deleted +0 -23
@@ -1,23 +0,0 @@ -#ifndef _LINUX_PSPACE_H -#define _LINUX_PSPACE_H - -#include <linux/sched.h> -#include <linux/mm.h> -#include <linux/threads.h> -#include <linux/pid.h> - -struct pidmap { -atomic_t nr_free; -void *page; -}; - -#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8) - -struct pspace { -struct pidmap pidmap[PIDMAP_ENTRIES ]; -int last_pid; -}; - -extern struct pspace init_pspace; - -#endif /* _LINUX_PSPACE_H */
kernel/pid.c +25 -24
149 lines not on this page · raw message
fs/proc/proc_misc.c +2 -2
@@ -45,7 +45,7 @@#include <linux/sysrq.h> #include <linux/vmalloc.h> #include <linux/crash_dump.h> -#include <linux/pspace.h> +#include <linux/pid_namespace.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/io.h>
@@ -92,7 +92,7 @@ static int loadavg_read_proc(char *page,LOAD_INT (a),LOAD_FRAC (a),LOAD_INT (b),LOAD_FRAC (b),LOAD_INT (c),LOAD_FRAC (c), - nr_running(), nr_threads, init_pspace.last_pid); + nr_running(), nr_threads, init_pid_ns.last_pid);return proc_calc_metrics (page, start, off, count, eof, len); }
--
Re: [patch -mm 4/7] rename struct pspace to struct pid_namespace
the From: got stripped. resending ...
C.
From: Sukadev Bhattiprolu <[email protected]>
Subject: [pid namespace] rename struct pspace to struct pid_namespace
Rename struct pspace to struct pid_namespace for consistency with other namespaces (uts_namespace and ipc_namespace). Also rename include/linux/pspace.h to include/linux/pid_namespace.h and variables from pspace to pid_ns.
--- fs/proc/proc_misc.c | 4 +-- include/linux/pid_namespace.h | 23 +++++++++++++++++++ include/linux/pspace.h | 23 ------------------- kernel/pid.c | 49 +++++++++++++++++++++--------------------- 4 files changed, 50 insertions(+), 49 deletions(-)
include/linux/pid_namespace.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef _LINUX_PID_NS_H +#define _LINUX_PID_NS_H + +#include <linux/sched.h> +#include <linux/mm.h> +#include <linux/threads.h> +#include <linux/pid.h> + +struct pidmap { +atomic_t nr_free; +void *page; +}; + +#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8) + +struct pid_namespace { +struct pidmap pidmap[PIDMAP_ENTRIES ]; +int last_pid; +}; + +extern struct pid_namespace init_pid_ns; + +#endif /* _LINUX_PID_NS_H */
include/linux/pspace.h deleted +0 -23
@@ -1,23 +0,0 @@ -#ifndef _LINUX_PSPACE_H -#define _LINUX_PSPACE_H - -#include <linux/sched.h> -#include <linux/mm.h> -#include <linux/threads.h> -#include <linux/pid.h> - -struct pidmap { -atomic_t nr_free; -void *page; -}; - -#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8) - -struct pspace { -struct pidmap pidmap[PIDMAP_ENTRIES ]; -int last_pid; -}; - -extern struct pspace init_pspace; - -#endif /* _LINUX_PSPACE_H */
kernel/pid.c +25 -24
149 lines not on this page · raw message
fs/proc/proc_misc.c +2 -2
@@ -45,7 +45,7 @@#include <linux/sysrq.h> #include <linux/vmalloc.h> #include <linux/crash_dump.h> -#include <linux/pspace.h> +#include <linux/pid_namespace.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/io.h>
@@ -92,7 +92,7 @@ static int loadavg_read_proc(char *page,LOAD_INT (a),LOAD_FRAC (a),LOAD_INT (b),LOAD_FRAC (b),LOAD_INT (c),LOAD_FRAC (c), - nr_running(), nr_threads, init_pspace.last_pid); + nr_running(), nr_threads, init_pid_ns.last_pid);return proc_calc_metrics (page, start, off, count, eof, len); }
PATCH 5/7 add pid_namespace to nsproxy
In reply to Cedric Le GoaterThis patch adds the pid namespace framework to the nsproxy object. The copy of the pid namespace only increases the refcount on the global pid namespace, init_pid_ns, and unshare is not implemented.
There is no configuration option to activate or deactivate this feature because this not relevant for the moment.
--- include/linux/init_task.h | 2 ++ include/linux/nsproxy.h | 2 ++ include/linux/pid_namespace.h | 20 ++++++++++++++++++-- kernel/nsproxy.c | 26 +++++++++++++++++++------- kernel/pid.c | 23 +++++++++++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-)
include/linux/init_task.h +2 -0
@@ -7,6 +7,7 @@#include <linux/utsname.h> #include <linux/lockdep.h> #include <linux/ipc.h> +#include <linux/pid_namespace.h> #define INIT_FDTABLE \ { \
@@ -70,6 +71,7 @@extern struct nsproxy init_nsproxy;#define INIT_NSPROXY (nsproxy) { \ + .pid_ns = &init_pid_ns, \ .count = ATOMIC_INIT(1), \ .nslock = SPIN_LOCK_UNLOCKED, \ .id = 0, \
include/linux/nsproxy.h +2 -0
@@ -7,6 +7,7 @@struct mnt_namespace ;struct uts_namespace ;struct ipc_namespace ; +struct pid_namespace ;/* * A structure to contain pointers to all per-process
@@ -27,6 +28,7 @@ struct nsproxy {struct uts_namespace *uts_ns;struct ipc_namespace *ipc_ns;struct mnt_namespace *mnt_ns; +struct pid_namespace *pid_ns; };extern struct nsproxy init_nsproxy;
include/linux/pid_namespace.h +18 -2
@@ -5,6 +5,8 @@#include <linux/mm.h> #include <linux/threads.h> #include <linux/pid.h> +#include <linux/nsproxy.h> +#include <linux/kref.h> struct pidmap {atomic_t nr_free;
@@ -14,10 +16,24 @@ struct pidmap {#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)struct pid_namespace { -struct pidmap pidmap[PIDMAP_ENTRIES ]; -int last_pid; +struct kref kref; +struct pidmap pidmap[PIDMAP_ENTRIES ]; +int last_pid; };extern struct pid_namespace init_pid_ns; +static inline void get_pid_ns (struct pid_namespace *ns) +{ +kref_get (&ns->kref); +} + +extern int copy_pid_ns (int flags,struct task_struct *tsk); +extern void free_pid_ns (struct kref *kref); + +static inline void put_pid_ns (struct pid_namespace *ns) +{ +kref_put (&ns->kref, free_pid_ns); +} +#endif /* _LINUX_PID_NS_H */
kernel/nsproxy.c +19 -7
@@ -19,6 +19,7 @@#include <linux/init_task.h> #include <linux/mnt_namespace.h> #include <linux/utsname.h> +#include <linux/pid_namespace.h> struct nsproxy init_nsproxy =INIT_NSPROXY (init_nsproxy);
@@ -69,6 +70,8 @@ struct nsproxy *dup_namespaces(struct nsget_uts_ns (ns->uts_ns);if (ns->ipc_ns)get_ipc_ns (ns->ipc_ns); +if (ns->pid_ns) +get_pid_ns (ns->pid_ns); }return ns;
@@ -112,10 +115,17 @@ int copy_namespaces(int flags, struct taif (err) goto out_ipc; + err =copy_pid_ns (flags, tsk); +if (err) + goto out_pid; + out:put_nsproxy (old_ns);return err; +out_pid: +if (new_ns->ipc_ns) +put_ipc_ns (new_ns->ipc_ns); out_ipc:if (new_ns->uts_ns)put_uts_ns (new_ns->uts_ns);
@@ -130,11 +140,13 @@ out_ns:void free_nsproxy (struct nsproxy *ns) { -if (ns->mnt_ns) -put_mnt_ns (ns->mnt_ns); -if (ns->uts_ns) -put_uts_ns (ns->uts_ns); -if (ns->ipc_ns) -put_ipc_ns (ns->ipc_ns); -kfree (ns); +if (ns->mnt_ns) +put_mnt_ns (ns->mnt_ns); +if (ns->uts_ns) +put_uts_ns (ns->uts_ns); +if (ns->ipc_ns) +put_ipc_ns (ns->ipc_ns); +if (ns->pid_ns) +put_pid_ns (ns->pid_ns); +kfree (ns); }
kernel/pid.c +23 -0
@@ -59,6 +59,9 @@ static inline int mk_pid(struct pid_name* the scheme scales to up to 4 million PIDs, runtime. */ struct pid_namespace init_pid_ns = { + .kref = { + .refcount =ATOMIC_INIT (2 ), + }, .pidmap = { [0 ...PIDMAP_ENTRIES -1 ] = {ATOMIC_INIT (BITS_PER_PAGE ),NULL } },
@@ -357,6 +360,26 @@ struct pid *find_ge_pid(int nr) }EXPORT_SYMBOL_GPL (find_get_pid); +int copy_pid_ns (int flags,struct task_struct *tsk) +{ +struct pid_namespace *old_ns = tsk->nsproxy->pid_ns; +int err =0 ; + +if (!old_ns) +return 0 ; + +get_pid_ns (old_ns); +return err; +} + +void free_pid_ns (struct kref *kref) +{ +struct pid_namespace *ns; + + ns = container_of(kref, struct pid_namespace, kref); +kfree (ns); +} +/* * The pid hash table is scaled according to the amount of memory in the * machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or
--
PATCH 6/7 use current->nsproxy->pid_ns
In reply to Cedric Le Goater--- fs/proc/proc_misc.c | 2 +- kernel/pid.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/proc/proc_misc.c +1 -1
@@ -92,7 +92,7 @@ static int loadavg_read_proc(char *page,LOAD_INT (a),LOAD_FRAC (a),LOAD_INT (b),LOAD_FRAC (b),LOAD_INT (c),LOAD_FRAC (c), - nr_running(), nr_threads, init_pid_ns.last_pid); + nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);return proc_calc_metrics (page, start, off, count, eof, len); }
kernel/pid.c +3 -3
@@ -196,7 +196,7 @@ fastcall void free_pid(struct pid *pid)hlist_del_rcu (&pid->pid_chain);spin_unlock_irqrestore (&pidmap_lock, flags); -free_pidmap (&init_pid_ns, pid->nr); +free_pidmap (current->nsproxy->pid_ns, pid->nr);call_rcu (&pid->rcu, delayed_put_pid); }
@@ -210,7 +210,7 @@ struct pid *alloc_pid(void)if (!pid) goto out; - nr =alloc_pidmap (&init_pid_ns); + nr =alloc_pidmap (current->nsproxy->pid_ns);if (nr <0 ) goto out_free;
@@ -353,7 +353,7 @@ struct pid *find_ge_pid(int nr) pid =find_pid (nr);if (pid)break ; - nr =next_pidmap (&init_pid_ns, nr); + nr =next_pidmap (current->nsproxy->pid_ns, nr); }while (nr >0 );return pid;
--
PATCH 7/7 add child reaper to pid_namespace
In reply to Cedric Le GoaterAdd a per pid_namespace child-reaper. This is needed so processes are reaped within the same pid space and do not spill over to the parent pid space. Its also needed so containers preserve existing semantic that pid == 1 would reap orphaned children.
This is based on Eric Biederman's patch: http://lkml.org/lkml/2006/2/6/285
--- fs/exec.c | 5 +++-- include/linux/pid.h | 5 +++-- include/linux/pid_namespace.h | 6 ++++++ include/linux/sched.h | 1 - init/main.c | 5 ++--- kernel/exit.c | 23 +++++++++++++++-------- kernel/pid.c | 3 ++- kernel/signal.c | 10 ++++++++-- 8 files changed, 39 insertions(+), 19 deletions(-)
init/main.c +2 -3
@@ -50,6 +50,7 @@#include <linux/buffer_head.h> #include <linux/debug_locks.h> #include <linux/lockdep.h> +#include <linux/pid_namespace.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -620,8 +621,6 @@ static int __init initcall_debug_setup(c }__setup ("initcall_debug" , initcall_debug_setup); -struct task_struct *child_reaper = &init_task; -extern initcall_t __initcall_start[], __initcall_end[];static void __init do_initcalls (void )
@@ -721,7 +720,7 @@ static int init(void * unused)* assumptions about where in the task array this * can be found. */ - child_reaper = current; + init_pid_ns.child_reaper = current; cad_pid =task_pid (current);
fs/exec.c +3 -2
@@ -38,6 +38,7 @@#include <linux/binfmts.h> #include <linux/swap.h> #include <linux/utsname.h> +#include <linux/pid_namespace.h> #include <linux/module.h> #include <linux/namei.h> #include <linux/proc_fs.h>
@@ -620,8 +621,8 @@ static int de_thread(struct task_struct* Reparenting needs write_lock on tasklist_lock, * so it is safe to do it under read_lock. */ -if (unlikely (tsk->group_leader == child_reaper)) - child_reaper = tsk; +if (unlikely (tsk->group_leader ==child_reaper (tsk))) + tsk->nsproxy->pid_ns->child_reaper = tsk;zap_other_threads (tsk);read_unlock (&tasklist_lock);
include/linux/pid.h +3 -2
@@ -35,8 +35,9 @@ enum pid_type* * Holding a reference to struct pid solves both of these problems. * It is small so holding a reference does not consume a lot of -* resources, and since a new struct pid is allocated when the numeric -* pid value is reused we don't mistakenly refer to new processes. +* resources, and since a new struct pid is allocated when the numeric pid +* value is reused (when pids wrap around) we don't mistakenly refer to new +* processes. */ struct pid
include/linux/sched.h +0 -1
@@ -1407,7 +1407,6 @@ extern NORET_TYPE void do_group_exit(intextern void daemonize (const char *, ...);extern int allow_signal (int );extern int disallow_signal (int ); -extern struct task_struct *child_reaper;extern int do_execve (char *,char __user *__user *,char __user *__user *,struct pt_regs *);extern long do_fork (unsigned long ,unsigned long ,struct pt_regs *,unsigned long ,int __user *,int __user *);
kernel/exit.c +15 -8
@@ -22,6 +22,7 @@#include <linux/file.h> #include <linux/binfmts.h> #include <linux/nsproxy.h> +#include <linux/pid_namespace.h> #include <linux/ptrace.h> #include <linux/profile.h> #include <linux/mount.h>
@@ -48,7 +49,6 @@#include <asm/mmu_context.h> extern void sem_exit (void ); -extern struct task_struct *child_reaper;static void exit_mm (struct task_struct * tsk);
@@ -259,7 +259,8 @@ static int has_stopped_jobs(int pgrp) }/** -* reparent_to_init - Reparent the calling kernel thread to the init task. +* reparent_to_init - Reparent the calling kernel thread to the init task +* of the pid space that the thread belongs to. * * If a kernel thread is launched as a result of a system call, or if * it ever exits, it should generally reparent itself to init so that
@@ -277,8 +278,8 @@ static void reparent_to_init(void)ptrace_unlink (current);/* Reparent to init */ remove_parent (current); - current->parent = child_reaper; - current->real_parent = child_reaper; + current->parent =child_reaper (current); + current->real_parent =child_reaper (current);add_parent (current);/* Set the exit signal to SIGCHLD so we signal init on exit */
@@ -661,7 +662,8 @@ reparent_thread(struct task_struct *p, s* When we die, we re-parent all our children. * Try to give them to another thread in our thread * group, and if no such member exists, give it to -* the global child reaper process (ie "init") +* the child reaper process (ie "init") in our pid +* space. */ static void forget_original_parent (struct task_struct *father,struct list_head *to_release)
@@ -672,7 +674,7 @@ forget_original_parent(struct task_strucdo { reaper =next_thread (reaper);if (reaper == father) { - reaper = child_reaper; + reaper =child_reaper (father);break ; } }while (reaper->exit_state);
@@ -860,8 +862,13 @@ fastcall NORET_TYPE void do_exit(long copanic ("Aiee, killing interrupt handler!" );if (unlikely (!tsk->pid))panic ("Attempted to kill the idle task!" ); -if (unlikely (tsk == child_reaper)) -panic ("Attempted to kill init!" ); +if (unlikely (tsk ==child_reaper (tsk))) { +if (tsk->nsproxy->pid_ns != &init_pid_ns) + tsk->nsproxy->pid_ns->child_reaper = init_pid_ns.child_reaper; +else +panic ("Attempted to kill init!" ); + } +if (unlikely (current->ptrace &PT_TRACE_EXIT )) { current->ptrace_message = code;
kernel/signal.c +8 -2
@@ -24,6 +24,8 @@#include <linux/ptrace.h> #include <linux/signal.h> #include <linux/capability.h> +#include <linux/pid_namespace.h> +#include <linux/nsproxy.h> #include <asm/param.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -1994,8 +1996,12 @@ relock:if (sig_kernel_ignore (signr))/* Default is nothing. */ continue ; -/* Init gets no signals it doesn't want. */ -if (current == child_reaper) +/* +* Init of a pid space gets no signals it doesn't want from +* within that pid space. It can of course get signals from +* its parent pid space. +*/ +if (current ==child_reaper (current))continue ;if (sig_kernel_stop (signr)) {
include/linux/pid_namespace.h +6 -0
@@ -19,6 +19,7 @@ struct pid_namespace {struct kref kref;struct pidmap pidmap[PIDMAP_ENTRIES ];int last_pid; +struct task_struct *child_reaper; };extern struct pid_namespace init_pid_ns;
@@ -36,4 +37,9 @@ static inline void put_pid_ns(struct pid kref_put(&ns->kref, free_pid_ns); } +static inline struct task_struct *child_reaper (struct task_struct *tsk) +{ +return tsk->nsproxy->pid_ns->child_reaper; +} +#endif /* _LINUX_PID_NS_H */
kernel/pid.c +2 -1
@@ -65,7 +65,8 @@ struct pid_namespace init_pid_ns = { .pidmap = { [ 0 ... PIDMAP_ENTRIES-1] = { ATOMIC_INIT(BITS_PER_PAGE), NULL } }, - .last_pid = 0 + .last_pid = 0, + .child_reaper = &init_task };/*
--
Re: [patch -mm 7/7] add child reaper to pid_namespace
Again bad From:. grr. here's the patch.
C.
From: Sukadev Bhattiprolu <[email protected]>
Subject: [pid namespace] add child reaper to pid_namespace
Add a per pid_namespace child-reaper. This is needed so processes are reaped within the same pid space and do not spill over to the parent pid space. Its also needed so containers preserve existing semantic that pid == 1 would reap orphaned children.
This is based on Eric Biederman's patch: http://lkml.org/lkml/2006/2/6/285
--- fs/exec.c | 5 +++-- include/linux/pid.h | 5 +++-- include/linux/pid_namespace.h | 6 ++++++ include/linux/sched.h | 1 - init/main.c | 5 ++--- kernel/exit.c | 23 +++++++++++++++-------- kernel/pid.c | 3 ++- kernel/signal.c | 10 ++++++++-- 8 files changed, 39 insertions(+), 19 deletions(-)
init/main.c +2 -3
@@ -50,6 +50,7 @@#include <linux/buffer_head.h> #include <linux/debug_locks.h> #include <linux/lockdep.h> +#include <linux/pid_namespace.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -620,8 +621,6 @@ static int __init initcall_debug_setup(c }__setup ("initcall_debug" , initcall_debug_setup); -struct task_struct *child_reaper = &init_task; -extern initcall_t __initcall_start[], __initcall_end[];static void __init do_initcalls (void )
@@ -721,7 +720,7 @@ static int init(void * unused)* assumptions about where in the task array this * can be found. */ - child_reaper = current; + init_pid_ns.child_reaper = current; cad_pid =task_pid (current);
fs/exec.c +3 -2
@@ -38,6 +38,7 @@#include <linux/binfmts.h> #include <linux/swap.h> #include <linux/utsname.h> +#include <linux/pid_namespace.h> #include <linux/module.h> #include <linux/namei.h> #include <linux/proc_fs.h>
@@ -620,8 +621,8 @@ static int de_thread(struct task_struct* Reparenting needs write_lock on tasklist_lock, * so it is safe to do it under read_lock. */ -if (unlikely (tsk->group_leader == child_reaper)) - child_reaper = tsk; +if (unlikely (tsk->group_leader ==child_reaper (tsk))) + tsk->nsproxy->pid_ns->child_reaper = tsk;zap_other_threads (tsk);read_unlock (&tasklist_lock);
include/linux/pid.h +3 -2
@@ -35,8 +35,9 @@ enum pid_type* * Holding a reference to struct pid solves both of these problems. * It is small so holding a reference does not consume a lot of -* resources, and since a new struct pid is allocated when the numeric -* pid value is reused we don't mistakenly refer to new processes. +* resources, and since a new struct pid is allocated when the numeric pid +* value is reused (when pids wrap around) we don't mistakenly refer to new +* processes. */ struct pid
include/linux/sched.h +0 -1
@@ -1407,7 +1407,6 @@ extern NORET_TYPE void do_group_exit(intextern void daemonize (const char *, ...);extern int allow_signal (int );extern int disallow_signal (int ); -extern struct task_struct *child_reaper;extern int do_execve (char *,char __user *__user *,char __user *__user *,struct pt_regs *);extern long do_fork (unsigned long ,unsigned long ,struct pt_regs *,unsigned long ,int __user *,int __user *);
kernel/exit.c +15 -8
@@ -22,6 +22,7 @@#include <linux/file.h> #include <linux/binfmts.h> #include <linux/nsproxy.h> +#include <linux/pid_namespace.h> #include <linux/ptrace.h> #include <linux/profile.h> #include <linux/mount.h>
@@ -48,7 +49,6 @@#include <asm/mmu_context.h> extern void sem_exit (void ); -extern struct task_struct *child_reaper;static void exit_mm (struct task_struct * tsk);
@@ -259,7 +259,8 @@ static int has_stopped_jobs(int pgrp) }/** -* reparent_to_init - Reparent the calling kernel thread to the init task. +* reparent_to_init - Reparent the calling kernel thread to the init task +* of the pid space that the thread belongs to. * * If a kernel thread is launched as a result of a system call, or if * it ever exits, it should generally reparent itself to init so that
@@ -277,8 +278,8 @@ static void reparent_to_init(void)ptrace_unlink (current);/* Reparent to init */ remove_parent (current); - current->parent = child_reaper; - current->real_parent = child_reaper; + current->parent =child_reaper (current); + current->real_parent =child_reaper (current);add_parent (current);/* Set the exit signal to SIGCHLD so we signal init on exit */
@@ -661,7 +662,8 @@ reparent_thread(struct task_struct *p, s* When we die, we re-parent all our children. * Try to give them to another thread in our thread * group, and if no such member exists, give it to -* the global child reaper process (ie "init") +* the child reaper process (ie "init") in our pid +* space. */ static void forget_original_parent (struct task_struct *father,struct list_head *to_release)
@@ -672,7 +674,7 @@ forget_original_parent(struct task_strucdo { reaper =next_thread (reaper);if (reaper == father) { - reaper = child_reaper; + reaper =child_reaper (father);break ; } }while (reaper->exit_state);
@@ -860,8 +862,13 @@ fastcall NORET_TYPE void do_exit(long copanic ("Aiee, killing interrupt handler!" );if (unlikely (!tsk->pid))panic ("Attempted to kill the idle task!" ); -if (unlikely (tsk == child_reaper)) -panic ("Attempted to kill init!" ); +if (unlikely (tsk ==child_reaper (tsk))) { +if (tsk->nsproxy->pid_ns != &init_pid_ns) + tsk->nsproxy->pid_ns->child_reaper = init_pid_ns.child_reaper; +else +panic ("Attempted to kill init!" ); + } +if (unlikely (current->ptrace &PT_TRACE_EXIT )) { current->ptrace_message = code;
kernel/signal.c +8 -2
@@ -24,6 +24,8 @@#include <linux/ptrace.h> #include <linux/signal.h> #include <linux/capability.h> +#include <linux/pid_namespace.h> +#include <linux/nsproxy.h> #include <asm/param.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -1994,8 +1996,12 @@ relock:if (sig_kernel_ignore (signr))/* Default is nothing. */ continue ; -/* Init gets no signals it doesn't want. */ -if (current == child_reaper) +/* +* Init of a pid space gets no signals it doesn't want from +* within that pid space. It can of course get signals from +* its parent pid space. +*/ +if (current ==child_reaper (current))continue ;if (sig_kernel_stop (signr)) {
include/linux/pid_namespace.h +6 -0
@@ -19,6 +19,7 @@ struct pid_namespace {struct kref kref;struct pidmap pidmap[PIDMAP_ENTRIES ];int last_pid; +struct task_struct *child_reaper; };extern struct pid_namespace init_pid_ns;
@@ -36,4 +37,9 @@ static inline void put_pid_ns(struct pid kref_put(&ns->kref, free_pid_ns); } +static inline struct task_struct *child_reaper (struct task_struct *tsk) +{ +return tsk->nsproxy->pid_ns->child_reaper; +} +#endif /* _LINUX_PID_NS_H */
kernel/pid.c +2 -1
@@ -65,7 +65,8 @@ struct pid_namespace init_pid_ns = { .pidmap = { [ 0 ... PIDMAP_ENTRIES-1] = { ATOMIC_INIT(BITS_PER_PAGE), NULL } }, - .last_pid = 0 + .last_pid = 0, + .child_reaper = &init_task };/*