aboutsummaryrefslogtreecommitdiffstats
path: root/fs/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 /fs/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 'fs/namespace.c')
-rw-r--r--fs/namespace.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index cab78a74aca3..c1bbe86f4920 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2301,6 +2301,7 @@ dput_out:
2301 2301
2302static void free_mnt_ns(struct mnt_namespace *ns) 2302static void free_mnt_ns(struct mnt_namespace *ns)
2303{ 2303{
2304 proc_free_inum(ns->proc_inum);
2304 put_user_ns(ns->user_ns); 2305 put_user_ns(ns->user_ns);
2305 kfree(ns); 2306 kfree(ns);
2306} 2307}
@@ -2317,10 +2318,16 @@ static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
2317static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns) 2318static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
2318{ 2319{
2319 struct mnt_namespace *new_ns; 2320 struct mnt_namespace *new_ns;
2321 int ret;
2320 2322
2321 new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL); 2323 new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
2322 if (!new_ns) 2324 if (!new_ns)
2323 return ERR_PTR(-ENOMEM); 2325 return ERR_PTR(-ENOMEM);
2326 ret = proc_alloc_inum(&new_ns->proc_inum);
2327 if (ret) {
2328 kfree(new_ns);
2329 return ERR_PTR(ret);
2330 }
2324 new_ns->seq = atomic64_add_return(1, &mnt_ns_seq); 2331 new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
2325 atomic_set(&new_ns->count, 1); 2332 atomic_set(&new_ns->count, 1);
2326 new_ns->root = NULL; 2333 new_ns->root = NULL;
@@ -2799,10 +2806,17 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
2799 return 0; 2806 return 0;
2800} 2807}
2801 2808
2809static unsigned int mntns_inum(void *ns)
2810{
2811 struct mnt_namespace *mnt_ns = ns;
2812 return mnt_ns->proc_inum;
2813}
2814
2802const struct proc_ns_operations mntns_operations = { 2815const struct proc_ns_operations mntns_operations = {
2803 .name = "mnt", 2816 .name = "mnt",
2804 .type = CLONE_NEWNS, 2817 .type = CLONE_NEWNS,
2805 .get = mntns_get, 2818 .get = mntns_get,
2806 .put = mntns_put, 2819 .put = mntns_put,
2807 .install = mntns_install, 2820 .install = mntns_install,
2821 .inum = mntns_inum,
2808}; 2822};