This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / kernel / vserver / switch.c
1 /*
2  *  linux/kernel/vserver/switch.c
3  *
4  *  Virtual Server: Syscall Switch
5  *
6  *  Copyright (C) 2003-2005  Herbert Pƶtzl
7  *
8  *  V0.01  syscall switch
9  *  V0.02  added signal to context
10  *  V0.03  added rlimit functions
11  *  V0.04  added iattr, task/xid functions
12  *  V0.05  added debug/history stuff
13  *
14  */
15
16 #include <linux/config.h>
17 #include <linux/linkage.h>
18 #include <linux/sched.h>
19 #include <asm/errno.h>
20
21 #include <linux/vserver/network.h>
22 #include <linux/vserver/switch.h>
23 #include <linux/vserver/debug.h>
24
25
26 static inline int
27 vc_get_version(uint32_t id)
28 {
29         return VCI_VERSION;
30 }
31
32 #include <linux/vserver/context_cmd.h>
33 #include <linux/vserver/cvirt_cmd.h>
34 #include <linux/vserver/limit_cmd.h>
35 #include <linux/vserver/network_cmd.h>
36 #include <linux/vserver/sched_cmd.h>
37 #include <linux/vserver/debug_cmd.h>
38
39 #include <linux/vserver/legacy.h>
40 #include <linux/vserver/namespace.h>
41 #include <linux/vserver/inode.h>
42 #include <linux/vserver/signal.h>
43 #include <linux/vserver/dlimit.h>
44
45
46 extern asmlinkage long
47 sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
48 {
49         vxdprintk(VXD_CBIT(switch, 0),
50                 "vc: VCMD_%02d_%d[%d], %d",
51                 VC_CATEGORY(cmd), VC_COMMAND(cmd),
52                 VC_VERSION(cmd), id);
53
54 #ifdef  CONFIG_VSERVER_LEGACY
55         if (!capable(CAP_CONTEXT) &&
56                 /* dirty hack for capremove */
57                 !(cmd==VCMD_new_s_context && id==-2))
58                 return -EPERM;
59 #else
60         if (!capable(CAP_CONTEXT))
61                 return -EPERM;
62 #endif
63
64         switch (cmd) {
65         case VCMD_get_version:
66                 return vc_get_version(id);
67
68         case VCMD_dump_history:
69 #ifdef  CONFIG_VSERVER_HISTORY
70                 return vc_dump_history(id);
71 #else
72                 return -ENOSYS;
73 #endif
74
75 #ifdef  CONFIG_VSERVER_LEGACY
76         case VCMD_new_s_context:
77                 return vc_new_s_context(id, data);
78         case VCMD_set_ipv4root:
79                 return vc_set_ipv4root(id, data);
80 #endif
81
82         case VCMD_task_xid:
83                 return vc_task_xid(id, data);
84         case VCMD_vx_info:
85                 return vc_vx_info(id, data);
86
87         case VCMD_task_nid:
88                 return vc_task_nid(id, data);
89         case VCMD_nx_info:
90                 return vc_nx_info(id, data);
91
92         case VCMD_set_namespace:
93                 return vc_set_namespace(id, data);
94         case VCMD_cleanup_namespace:
95                 return vc_cleanup_namespace(id, data);
96         }
97
98         /* those are allowed while in setup too */
99         if (!vx_check(0, VX_ADMIN|VX_WATCH) &&
100                 !vx_flags(VXF_STATE_SETUP,0))
101                 return -EPERM;
102
103 #ifdef  CONFIG_VSERVER_LEGACY
104         switch (cmd) {
105         case VCMD_set_cflags:
106         case VCMD_set_ccaps:
107                 if (vx_check(0, VX_WATCH))
108                         return 0;
109         }
110 #endif
111
112         switch (cmd) {
113         case VCMD_get_rlimit:
114                 return vc_get_rlimit(id, data);
115         case VCMD_set_rlimit:
116                 return vc_set_rlimit(id, data);
117         case VCMD_get_rlimit_mask:
118                 return vc_get_rlimit_mask(id, data);
119
120         case VCMD_vx_get_vhi_name:
121                 return vc_get_vhi_name(id, data);
122         case VCMD_vx_set_vhi_name:
123                 return vc_set_vhi_name(id, data);
124
125         case VCMD_set_cflags:
126                 return vc_set_cflags(id, data);
127         case VCMD_get_cflags:
128                 return vc_get_cflags(id, data);
129
130         case VCMD_set_ccaps:
131                 return vc_set_ccaps(id, data);
132         case VCMD_get_ccaps:
133                 return vc_get_ccaps(id, data);
134
135         case VCMD_set_nflags:
136                 return vc_set_nflags(id, data);
137         case VCMD_get_nflags:
138                 return vc_get_nflags(id, data);
139
140         case VCMD_set_ncaps:
141                 return vc_set_ncaps(id, data);
142         case VCMD_get_ncaps:
143                 return vc_get_ncaps(id, data);
144
145         case VCMD_set_sched_v2:
146                 return vc_set_sched_v2(id, data);
147         /* this is version 3 */
148         case VCMD_set_sched:
149                 return vc_set_sched(id, data);
150
151         case VCMD_add_dlimit:
152                 return vc_add_dlimit(id, data);
153         case VCMD_rem_dlimit:
154                 return vc_rem_dlimit(id, data);
155         case VCMD_set_dlimit:
156                 return vc_set_dlimit(id, data);
157         case VCMD_get_dlimit:
158                 return vc_get_dlimit(id, data);
159         }
160
161         /* below here only with VX_ADMIN */
162         if (!vx_check(0, VX_ADMIN|VX_WATCH))
163                 return -EPERM;
164
165         switch (cmd) {
166         case VCMD_ctx_kill:
167                 return vc_ctx_kill(id, data);
168
169         case VCMD_wait_exit:
170                 return vc_wait_exit(id, data);
171
172         case VCMD_create_context:
173 #ifdef  CONFIG_VSERVER_LEGACY
174                 return vc_ctx_create(id, data);
175 #else
176                 return -ENOSYS;
177 #endif
178
179         case VCMD_get_iattr:
180                 return vc_get_iattr(id, data);
181         case VCMD_set_iattr:
182                 return vc_set_iattr(id, data);
183
184         case VCMD_enter_namespace:
185                 return vc_enter_namespace(id, data);
186
187         case VCMD_ctx_create:
188 #ifdef  CONFIG_VSERVER_LEGACY
189                 if (id == 1) {
190                         current->xid = 1;
191                         return 1;
192                 }
193 #endif
194                 return vc_ctx_create(id, data);
195         case VCMD_ctx_migrate:
196                 return vc_ctx_migrate(id, data);
197
198         case VCMD_net_create:
199                 return vc_net_create(id, data);
200         case VCMD_net_migrate:
201                 return vc_net_migrate(id, data);
202
203         }
204         return -ENOSYS;
205 }
206