2 * linux/kernel/vserver/legacy.c
4 * Virtual Server: Legacy Funtions
6 * Copyright (C) 2001-2003 Jacques Gelinas
7 * Copyright (C) 2003-2005 Herbert Pƶtzl
9 * V0.01 broken out from vcontext.c V0.05
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/vs_context.h>
16 #include <linux/vs_network.h>
17 #include <linux/vserver/legacy.h>
18 #include <linux/vserver/namespace.h>
19 #include <linux/namespace.h>
21 #include <asm/errno.h>
22 #include <asm/uaccess.h>
26 static int vx_set_initpid(struct vx_info *vxi, int pid)
31 vxi->vx_initpid = pid;
35 int vc_new_s_context(uint32_t ctx, void __user *data)
38 struct vcmd_new_s_context_v1 vc_data;
39 struct vx_info *new_vxi;
41 if (copy_from_user(&vc_data, data, sizeof(vc_data)))
44 /* legacy hack, will be removed soon */
46 /* assign flags and initpid */
47 if (!current->vx_info)
50 if (vc_data.flags & VX_INFO_INIT)
51 ret = vx_set_initpid(current->vx_info, current->tgid);
53 /* We keep the same vx_id, but lower the capabilities */
54 current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
55 ret = vx_current_xid();
56 current->vx_info->vx_flags |= vc_data.flags;
61 if (!vx_check(0, VX_ADMIN) || !capable(CAP_SYS_ADMIN)
62 /* might make sense in the future, or not ... */
63 || vx_flags(VX_INFO_LOCK, 0))
66 /* ugly hack for Spectator */
72 if (((ctx > MAX_S_CONTEXT) && (ctx != VX_DYNAMIC_ID)) ||
76 if ((ctx == VX_DYNAMIC_ID) || (ctx < MIN_D_CONTEXT))
77 new_vxi = locate_or_create_vx_info(ctx);
79 new_vxi = locate_vx_info(ctx);
85 if (!vx_info_flags(new_vxi, VXF_STATE_SETUP, 0) &&
86 vx_info_flags(new_vxi, VX_INFO_PRIVATE, 0))
89 new_vxi->vx_flags &= ~(VXF_STATE_SETUP|VXF_STATE_INIT);
91 ret = vx_migrate_task(current, new_vxi);
93 current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
94 new_vxi->vx_flags |= vc_data.flags;
95 if (vc_data.flags & VX_INFO_INIT)
96 vx_set_initpid(new_vxi, current->tgid);
97 if (vc_data.flags & VX_INFO_NAMESPACE)
98 vx_set_namespace(new_vxi,
99 current->namespace, current->fs);
100 if (vc_data.flags & VX_INFO_NPROC)
101 new_vxi->limit.rlim[RLIMIT_NPROC] =
102 current->signal->rlim[RLIMIT_NPROC].rlim_max;
103 ret = new_vxi->vx_id;
106 put_vx_info(new_vxi);