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/vs_base.h>
17 #include <linux/vs_context.h>
18 #include <linux/namespace.h>
19 #include <linux/dcache.h>
21 #include <asm/errno.h>
22 #include <asm/uaccess.h>
25 /* virtual host info names */
27 static char * vx_vhi_name(struct vx_info *vxi, int id)
33 return vxi->cvirt.utsname.sysname;
35 return vxi->cvirt.utsname.nodename;
37 return vxi->cvirt.utsname.release;
39 return vxi->cvirt.utsname.version;
41 return vxi->cvirt.utsname.machine;
43 return vxi->cvirt.utsname.domainname;
50 int vc_set_vhi_name(uint32_t id, void __user *data)
53 struct vcmd_vx_vhi_name_v0 vc_data;
56 if (!capable(CAP_SYS_ADMIN))
58 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
61 vxi = locate_vx_info(id);
65 name = vx_vhi_name(vxi, vc_data.field);
67 memcpy(name, vc_data.name, 65);
69 return (name ? 0 : -EFAULT);
72 int vc_get_vhi_name(uint32_t id, void __user *data)
75 struct vcmd_vx_vhi_name_v0 vc_data;
78 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
81 vxi = locate_vx_info(id);
85 name = vx_vhi_name(vxi, vc_data.field);
89 memcpy(vc_data.name, name, 65);
90 if (copy_to_user (data, &vc_data, sizeof(vc_data)))
94 return (name ? 0 : -EFAULT);
97 /* namespace functions */
99 #include <linux/namespace.h>
101 int vx_set_namespace(struct vx_info *vxi, struct namespace *ns, struct fs_struct *fs)
103 struct fs_struct *fs_copy;
105 if (vxi->vx_namespace)
110 fs_copy = copy_fs_struct(fs);
115 vxi->vx_namespace = ns;
116 vxi->vx_fs = fs_copy;
120 int vc_enter_namespace(uint32_t id, void *data)
123 struct fs_struct *old_fs, *fs;
124 struct namespace *old_ns;
127 if (!vx_check(0, VX_ADMIN))
130 vxi = locate_vx_info(id);
135 if (!vxi->vx_namespace)
139 fs = copy_fs_struct(vxi->vx_fs);
145 old_ns = current->namespace;
146 old_fs = current->fs;
147 get_namespace(vxi->vx_namespace);
148 current->namespace = vxi->vx_namespace;
150 task_unlock(current);
152 put_namespace(old_ns);
153 put_fs_struct(old_fs);
159 int vc_cleanup_namespace(uint32_t id, void *data)
161 down_write(¤t->namespace->sem);
162 spin_lock(&vfsmount_lock);
163 umount_unused(current->namespace->root, current->fs);
164 spin_unlock(&vfsmount_lock);
165 up_write(¤t->namespace->sem);
169 int vc_set_namespace(uint32_t id, void __user *data)
171 struct fs_struct *fs;
172 struct namespace *ns;
176 if (vx_check(0, VX_ADMIN|VX_WATCH))
180 vxi = get_vx_info(current->vx_info);
182 atomic_inc(&fs->count);
183 ns = current->namespace;
184 get_namespace(current->namespace);
185 task_unlock(current);
187 ret = vx_set_namespace(vxi, ns, fs);