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/config.h>
14 #include <linux/utsname.h>
15 #include <linux/sched.h>
16 #include <linux/vs_context.h>
17 #include <linux/vserver/namespace.h>
18 #include <linux/vserver/namespace_cmd.h>
19 #include <linux/dcache.h>
20 #include <linux/mount.h>
23 #include <asm/errno.h>
24 #include <asm/uaccess.h>
27 /* namespace functions */
29 #include <linux/namespace.h>
31 int vx_set_namespace(struct vx_info *vxi, struct namespace *ns, struct fs_struct *fs)
33 struct fs_struct *fs_copy;
35 if (vxi->vx_namespace)
40 fs_copy = copy_fs_struct(fs);
45 vxi->vx_namespace = ns;
50 int vc_enter_namespace(uint32_t id, void *data)
53 struct fs_struct *old_fs, *fs;
54 struct namespace *old_ns;
57 if (!vx_check(0, VX_ADMIN))
60 vxi = locate_vx_info(id);
65 if (!vxi->vx_namespace)
69 fs = copy_fs_struct(vxi->vx_fs);
75 old_ns = current->namespace;
77 get_namespace(vxi->vx_namespace);
78 current->namespace = vxi->vx_namespace;
82 put_namespace(old_ns);
83 put_fs_struct(old_fs);
89 int vc_cleanup_namespace(uint32_t id, void *data)
91 down_write(¤t->namespace->sem);
92 spin_lock(&vfsmount_lock);
93 umount_unused(current->namespace->root, current->fs);
94 spin_unlock(&vfsmount_lock);
95 up_write(¤t->namespace->sem);
99 int vc_set_namespace(uint32_t id, void __user *data)
101 struct fs_struct *fs;
102 struct namespace *ns;
106 if (vx_check(0, VX_ADMIN|VX_WATCH))
110 vxi = get_vx_info(current->vx_info);
112 atomic_inc(&fs->count);
113 ns = current->namespace;
114 get_namespace(current->namespace);
115 task_unlock(current);
117 ret = vx_set_namespace(vxi, ns, fs);