aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/pid_namespace.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2011-06-15 13:21:48 -0400
committerEric W. Biederman <ebiederm@xmission.com>2012-11-20 07:19:49 -0500
commit98f842e675f96ffac96e6c50315790912b2812be (patch)
treeed4dee9a6e54e3443e9f3f1614c8a2fcf9b31e0a /kernel/pid_namespace.c
parentbf056bfa80596a5d14b26b17276a56a0dcb080e5 (diff)
proc: Usable inode numbers for the namespace file descriptors.
Assign a unique proc inode to each namespace, and use that inode number to ensure we only allocate at most one proc inode for every namespace in proc. A single proc inode per namespace allows userspace to test to see if two processes are in the same namespace. This has been a long requested feature and only blocked because a naive implementation would put the id in a global space and would ultimately require having a namespace for the names of namespaces, making migration and certain virtualization tricks impossible. We still don't have per superblock inode numbers for proc, which appears necessary for application unaware checkpoint/restart and migrations (if the application is using namespace file descriptors) but that is now allowd by the design if it becomes important. I have preallocated the ipc and uts initial proc inode numbers so their structures can be statically initialized. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'kernel/pid_namespace.c')
-rw-r--r--kernel/pid_namespace.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 68508d330634..560da0dab230 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -107,6 +107,10 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
107 if (ns->pid_cachep == NULL) 107 if (ns->pid_cachep == NULL)
108 goto out_free_map; 108 goto out_free_map;
109 109
110 err = proc_alloc_inum(&ns->proc_inum);
111 if (err)
112 goto out_free_map;
113
110 kref_init(&ns->kref); 114 kref_init(&ns->kref);
111 ns->level = level; 115 ns->level = level;
112 ns->parent = get_pid_ns(parent_pid_ns); 116 ns->parent = get_pid_ns(parent_pid_ns);
@@ -133,6 +137,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
133{ 137{
134 int i; 138 int i;
135 139
140 proc_free_inum(ns->proc_inum);
136 for (i = 0; i < PIDMAP_ENTRIES; i++) 141 for (i = 0; i < PIDMAP_ENTRIES; i++)
137 kfree(ns->pidmap[i].page); 142 kfree(ns->pidmap[i].page);
138 put_user_ns(ns->user_ns); 143 put_user_ns(ns->user_ns);
@@ -345,12 +350,19 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns)
345 return 0; 350 return 0;
346} 351}
347 352
353static unsigned int pidns_inum(void *ns)
354{
355 struct pid_namespace *pid_ns = ns;
356 return pid_ns->proc_inum;
357}
358
348const struct proc_ns_operations pidns_operations = { 359const struct proc_ns_operations pidns_operations = {
349 .name = "pid", 360 .name = "pid",
350 .type = CLONE_NEWPID, 361 .type = CLONE_NEWPID,
351 .get = pidns_get, 362 .get = pidns_get,
352 .put = pidns_put, 363 .put = pidns_put,
353 .install = pidns_install, 364 .install = pidns_install,
365 .inum = pidns_inum,
354}; 366};
355 367
356static __init int pid_namespaces_init(void) 368static __init int pid_namespaces_init(void)