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/dcache.h>
19 #include <linux/mount.h>
22 #include <asm/errno.h>
23 #include <asm/uaccess.h>
26 /* virtual host info names */
28 static char * vx_vhi_name(struct vx_info *vxi, int id)
34 return vxi->cvirt.utsname.sysname;
36 return vxi->cvirt.utsname.nodename;
38 return vxi->cvirt.utsname.release;
40 return vxi->cvirt.utsname.version;
42 return vxi->cvirt.utsname.machine;
44 return vxi->cvirt.utsname.domainname;
51 int vc_set_vhi_name(uint32_t id, void __user *data)
54 struct vcmd_vx_vhi_name_v0 vc_data;
57 if (!capable(CAP_SYS_ADMIN))
59 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
62 vxi = locate_vx_info(id);
66 name = vx_vhi_name(vxi, vc_data.field);
68 memcpy(name, vc_data.name, 65);
70 return (name ? 0 : -EFAULT);
73 int vc_get_vhi_name(uint32_t id, void __user *data)
76 struct vcmd_vx_vhi_name_v0 vc_data;
79 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
82 vxi = locate_vx_info(id);
86 name = vx_vhi_name(vxi, vc_data.field);
90 memcpy(vc_data.name, name, 65);
91 if (copy_to_user (data, &vc_data, sizeof(vc_data)))
95 return (name ? 0 : -EFAULT);
98 /* namespace functions */
100 #include <linux/namespace.h>
102 int vx_set_namespace(struct vx_info *vxi, struct namespace *ns, struct fs_struct *fs)
104 struct fs_struct *fs_copy;
106 if (vxi->vx_namespace)
111 fs_copy = copy_fs_struct(fs);
116 vxi->vx_namespace = ns;
117 vxi->vx_fs = fs_copy;
121 int vc_enter_namespace(uint32_t id, void *data)
124 struct fs_struct *old_fs, *fs;
125 struct namespace *old_ns;
128 if (!vx_check(0, VX_ADMIN))
131 vxi = locate_vx_info(id);
136 if (!vxi->vx_namespace)
140 fs = copy_fs_struct(vxi->vx_fs);
146 old_ns = current->namespace;
147 old_fs = current->fs;
148 get_namespace(vxi->vx_namespace);
149 current->namespace = vxi->vx_namespace;
151 task_unlock(current);
153 put_namespace(old_ns);
154 put_fs_struct(old_fs);
160 int vc_cleanup_namespace(uint32_t id, void *data)
162 down_write(¤t->namespace->sem);
163 spin_lock(&vfsmount_lock);
164 umount_unused(current->namespace->root, current->fs);
165 spin_unlock(&vfsmount_lock);
166 up_write(¤t->namespace->sem);
170 int vc_set_namespace(uint32_t id, void __user *data)
172 struct fs_struct *fs;
173 struct namespace *ns;
177 if (vx_check(0, VX_ADMIN|VX_WATCH))
181 vxi = get_vx_info(current->vx_info);
183 atomic_inc(&fs->count);
184 ns = current->namespace;
185 get_namespace(current->namespace);
186 task_unlock(current);
188 ret = vx_set_namespace(vxi, ns, fs);