2 * linux/kernel/vserver/namespace.c
4 * Virtual Server: Context Namespace Support
6 * Copyright (C) 2003-2004 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/vserver/namespace.h>
16 #include <linux/vinline.h>
17 #include <linux/namespace.h>
18 #include <linux/dcache.h>
20 #include <asm/errno.h>
21 #include <asm/uaccess.h>
24 /* virtual host info names */
26 static char * vx_vhi_name(struct vx_info *vxi, int id)
32 return vxi->cvirt.utsname.sysname;
34 return vxi->cvirt.utsname.nodename;
36 return vxi->cvirt.utsname.release;
38 return vxi->cvirt.utsname.version;
40 return vxi->cvirt.utsname.machine;
42 return vxi->cvirt.utsname.domainname;
49 int vc_set_vhi_name(uint32_t id, void __user *data)
52 struct vcmd_vx_vhi_name_v0 vc_data;
55 if (!capable(CAP_SYS_ADMIN))
57 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
60 vxi = locate_vx_info(id);
64 name = vx_vhi_name(vxi, vc_data.field);
66 memcpy(name, vc_data.name, 65);
68 return (name ? 0 : -EFAULT);
71 int vc_get_vhi_name(uint32_t id, void __user *data)
74 struct vcmd_vx_vhi_name_v0 vc_data;
77 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
80 vxi = locate_vx_info(id);
84 name = vx_vhi_name(vxi, vc_data.field);
88 memcpy(vc_data.name, name, 65);
89 if (copy_to_user (data, &vc_data, sizeof(vc_data)))
93 return (name ? 0 : -EFAULT);
96 /* namespace functions */
98 #include <linux/namespace.h>
100 int vx_set_namespace(struct vx_info *vxi, struct namespace *ns, struct fs_struct *fs)
102 struct fs_struct *fs_copy;
104 if (vxi->vx_namespace)
109 fs_copy = copy_fs_struct(fs);
114 vxi->vx_namespace = ns;
115 vxi->vx_fs = fs_copy;
119 int vc_enter_namespace(uint32_t id, void *data)
122 struct fs_struct *old_fs, *fs;
123 struct namespace *old_ns;
126 if (!vx_check(0, VX_ADMIN))
129 vxi = locate_vx_info(id);
134 if (!vxi->vx_namespace)
138 fs = copy_fs_struct(vxi->vx_fs);
144 old_ns = current->namespace;
145 old_fs = current->fs;
146 get_namespace(vxi->vx_namespace);
147 current->namespace = vxi->vx_namespace;
149 task_unlock(current);
151 put_namespace(old_ns);
152 put_fs_struct(old_fs);
158 int vc_cleanup_namespace(uint32_t id, void *data)
160 down_write(¤t->namespace->sem);
161 spin_lock(&vfsmount_lock);
162 umount_unused(current->namespace->root, current->fs);
163 spin_unlock(&vfsmount_lock);
164 up_write(¤t->namespace->sem);
168 int vc_set_namespace(uint32_t id, void __user *data)
170 struct fs_struct *fs;
171 struct namespace *ns;
175 if (vx_check(0, VX_ADMIN|VX_WATCH))
179 vxi = get_vx_info(current->vx_info);
181 atomic_inc(&fs->count);
182 ns = current->namespace;
183 get_namespace(current->namespace);
184 task_unlock(current);
186 ret = vx_set_namespace(vxi, ns, fs);