2 * linux/kernel/vserver/namespace.c
4 * Virtual Server: Context Namespace Support
6 * Copyright (C) 2003-2005 Herbert Pƶtzl
8 * V0.01 broken out from context.c 0.07
9 * V0.02 added task locking for namespace
13 #include <linux/utsname.h>
14 #include <linux/sched.h>
15 #include <linux/vs_context.h>
16 #include <linux/vserver/namespace.h>
17 #include <linux/vserver/namespace_cmd.h>
18 #include <linux/dcache.h>
19 #include <linux/mount.h>
22 #include <asm/errno.h>
23 #include <asm/uaccess.h>
26 /* namespace functions */
28 #include <linux/namespace.h>
30 int vx_set_namespace(struct vx_info *vxi, struct namespace *ns, struct fs_struct *fs)
32 struct fs_struct *fs_copy;
34 if (vxi->vx_namespace)
39 fs_copy = copy_fs_struct(fs);
44 vxi->vx_namespace = ns;
49 int vc_enter_namespace(uint32_t id, void __user *data)
52 struct fs_struct *old_fs, *fs;
53 struct namespace *old_ns;
56 if (!vx_check(0, VX_ADMIN))
59 vxi = lookup_vx_info(id);
64 if (!vxi->vx_namespace)
68 fs = copy_fs_struct(vxi->vx_fs);
74 old_ns = current->namespace;
76 get_namespace(vxi->vx_namespace);
77 current->namespace = vxi->vx_namespace;
81 put_namespace(old_ns);
82 put_fs_struct(old_fs);
88 int vc_cleanup_namespace(uint32_t id, void __user *data)
90 // down_write(¤t->namespace->sem);
91 spin_lock(&vfsmount_lock);
92 umount_unused(current->namespace->root, current->fs);
93 spin_unlock(&vfsmount_lock);
94 // up_write(¤t->namespace->sem);
98 int vc_set_namespace(uint32_t id, void __user *data)
100 struct fs_struct *fs;
101 struct namespace *ns;
105 vxi = lookup_vx_info(id);
111 atomic_inc(&fs->count);
112 ns = current->namespace;
113 get_namespace(current->namespace);
114 task_unlock(current);
116 ret = vx_set_namespace(vxi, ns, fs);