diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2010-03-07 18:17:03 -0800 |
---|---|---|
committer | Eric W. Biederman <ebiederm@aristanetworks.com> | 2011-08-08 13:51:16 -0500 |
commit | f8dd549a036db91f59c7edc81760a5d08fee0d2f (patch) | |
tree | 57322173c2dfd45f57f352e88f32d5de5bbdc7b9 | |
parent | b619360f585cdcff4d4b89f5aae8c2e66b264d97 (diff) | |
download | linux-namespace-control-devel-f8dd549a036db91f59c7edc81760a5d08fee0d2f.tar.gz |
ns proc: Add support for the pid namespace
Add the basic namespace file support, but do not
add support for setns.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
-rw-r--r-- | fs/proc/namespaces.c | 3 | ||||
-rw-r--r-- | include/linux/pid_namespace.h | 1 | ||||
-rw-r--r-- | include/linux/proc_fs.h | 2 | ||||
-rw-r--r-- | kernel/pid.c | 1 | ||||
-rw-r--r-- | kernel/pid_namespace.c | 50 |
5 files changed, 56 insertions, 1 deletions
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index f500ed94e58ed..1ba939f5cf840 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -29,6 +29,9 @@ static const struct proc_ns_operations *ns_entries[] = { #ifdef CONFIG_USER_NS &userns_operations, #endif +#ifdef CONFIG_PID_NS + &pidns_operations, +#endif }; static const struct file_operations ns_file_operations = { diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 38d10326246af..8e0bee8c26739 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -23,6 +23,7 @@ struct pid_namespace { struct task_struct *child_reaper; struct kmem_cache *pid_cachep; unsigned int level; + unsigned int proc_inum; struct pid_namespace *parent; #ifdef CONFIG_PROC_FS struct vfsmount *proc_mnt; diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index 86d4b399bc3e3..5f2f381b87fda 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -32,6 +32,7 @@ enum { PROC_IPC_INIT_INO = 0xEFFFFFFFU, PROC_UTS_INIT_INO = 0xEFFFFFFEU, PROC_USER_INIT_INO = 0xEFFFFFFDU, + PROC_PID_INIT_INO = 0xEFFFFFFCU, }; @@ -274,6 +275,7 @@ extern const struct proc_ns_operations utsns_operations; extern const struct proc_ns_operations ipcns_operations; extern const struct proc_ns_operations mntns_operations; extern const struct proc_ns_operations userns_operations; +extern const struct proc_ns_operations pidns_operations; union proc_op { int (*proc_get_link)(struct inode *, struct path *); diff --git a/kernel/pid.c b/kernel/pid.c index 57a8346a270e0..29d34a1117584 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -78,6 +78,7 @@ struct pid_namespace init_pid_ns = { .last_pid = 0, .level = 0, .child_reaper = &init_task, + .proc_inum = PROC_PID_INIT_INO, }; EXPORT_SYMBOL_GPL(init_pid_ns); diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index e9c9adc84ca6e..54dd62b3e3d78 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -97,12 +97,18 @@ static struct pid_namespace *create_pid_namespace(struct pid_namespace *parent_p for (i = 1; i < PIDMAP_ENTRIES; i++) atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE); - err = pid_ns_prepare_proc(ns); + err = proc_alloc_inum(&ns->proc_inum); if (err) goto out_put_parent_pid_ns; + err = pid_ns_prepare_proc(ns); + if (err) + goto out_free_proc_inum; + return ns; +out_free_proc_inum: + proc_free_inum(ns->proc_inum); out_put_parent_pid_ns: put_pid_ns(parent_pid_ns); out_free_map: @@ -117,6 +123,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) { int i; + proc_free_inum(ns->proc_inum); for (i = 0; i < PIDMAP_ENTRIES; i++) kfree(ns->pidmap[i].page); kmem_cache_free(pid_ns_cachep, ns); @@ -191,6 +198,47 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) return; } +static void *pidns_get(struct task_struct *task) +{ + struct pid_namespace *ns; + + rcu_read_lock(); + ns = get_pid_ns(task_active_pid_ns(task)); + rcu_read_unlock(); + + return ns; +} + +static void pidns_put(void *ns) +{ + put_pid_ns(ns); +} + +static int pidns_install(struct nsproxy *nsproxy, void *ns) +{ + return -EINVAL; +#ifdef notyet + put_pid_ns(nsproxy->pid_ns); + nsproxy->pid_ns = get_pid_ns(ns); + return 0; +#endif +} + +static unsigned int pidns_inum(void *vns) +{ + struct pid_namespace *ns = vns; + return ns->proc_inum; +} + +const struct proc_ns_operations pidns_operations = { + .name = "pid", + .type = CLONE_NEWPID, + .get = pidns_get, + .put = pidns_put, + .install = pidns_install, + .inum = pidns_inum, +}; + static __init int pid_namespaces_init(void) { pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC); |