Add cwd to the list of paths to exclude from namespace cleanup.
[util-vserver.git] / kernel / context.h
1 #ifndef _VX_CONTEXT_H
2 #define _VX_CONTEXT_H
3
4 #include <linux/types.h>
5 //#include <linux/capability.h>
6
7
8 #define MAX_S_CONTEXT   65535   /* Arbitrary limit */
9
10 #ifdef  CONFIG_VSERVER_DYNAMIC_IDS
11 #define MIN_D_CONTEXT   49152   /* dynamic contexts start here */
12 #else
13 #define MIN_D_CONTEXT   65536
14 #endif
15
16 #define VX_DYNAMIC_ID   ((uint32_t)-1)          /* id for dynamic context */
17
18 /* context flags */
19
20 #define VXF_INFO_LOCK           0x00000001
21 #define VXF_INFO_SCHED          0x00000002
22 #define VXF_INFO_NPROC          0x00000004
23 #define VXF_INFO_PRIVATE        0x00000008
24
25 #define VXF_INFO_INIT           0x00000010
26 #define VXF_INFO_HIDE           0x00000020
27 #define VXF_INFO_ULIMIT         0x00000040
28 #define VXF_INFO_NSPACE         0x00000080
29
30 #define VXF_SCHED_HARD          0x00000100
31 #define VXF_SCHED_PRIO          0x00000200
32 #define VXF_SCHED_PAUSE         0x00000400
33
34 #define VXF_VIRT_MEM            0x00010000
35 #define VXF_VIRT_UPTIME         0x00020000
36 #define VXF_VIRT_CPU            0x00040000
37 #define VXF_VIRT_LOAD           0x00080000
38 #define VXF_VIRT_TIME           0x00100000
39
40 #define VXF_HIDE_MOUNT          0x01000000
41 #define VXF_HIDE_NETIF          0x02000000
42 #define VXF_HIDE_VINFO          0x04000000
43
44 #define VXF_STATE_SETUP         (1ULL<<32)
45 #define VXF_STATE_INIT          (1ULL<<33)
46 #define VXF_STATE_ADMIN         (1ULL<<34)
47
48 #define VXF_SC_HELPER           (1ULL<<36)
49 #define VXF_REBOOT_KILL         (1ULL<<37)
50 #define VXF_PERSISTENT          (1ULL<<38)
51
52 #define VXF_FORK_RSS            (1ULL<<48)
53 #define VXF_PROLIFIC            (1ULL<<49)
54
55 #define VXF_IGNEG_NICE          (1ULL<<52)
56
57 #define VXF_ONE_TIME            (0x0007ULL<<32)
58
59 #define VXF_INIT_SET            (VXF_STATE_SETUP|VXF_STATE_INIT|VXF_STATE_ADMIN)
60
61
62 /* context migration */
63
64 #define VXM_SET_INIT            0x00000001
65 #define VXM_SET_REAPER          0x00000002
66
67 /* context caps */
68
69 #define VXC_CAP_MASK            0x00000000
70
71 #define VXC_SET_UTSNAME         0x00000001
72 #define VXC_SET_RLIMIT          0x00000002
73
74 #define VXC_RAW_ICMP            0x00000100
75 #define VXC_SYSLOG              0x00001000
76
77 #define VXC_SECURE_MOUNT        0x00010000
78 #define VXC_SECURE_REMOUNT      0x00020000
79 #define VXC_BINARY_MOUNT        0x00040000
80
81 #define VXC_QUOTA_CTL           0x00100000
82 #define VXC_ADMIN_MAPPER        0x00200000
83 #define VXC_ADMIN_CLOOP         0x00400000
84
85
86 /* context state changes */
87
88 enum {
89         VSC_STARTUP = 1,
90         VSC_SHUTDOWN,
91
92         VSC_NETUP,
93         VSC_NETDOWN,
94 };
95
96
97 #ifdef  __KERNEL__
98
99 #include <linux/list.h>
100 #include <linux/spinlock.h>
101 #include <linux/rcupdate.h>
102
103 #include "limit_def.h"
104 #include "sched_def.h"
105 #include "cvirt_def.h"
106 #include "cacct_def.h"
107
108 struct _vx_info_pc {
109         struct _vx_sched_pc sched_pc;
110         struct _vx_cvirt_pc cvirt_pc;
111 };
112
113 struct vx_info {
114         struct hlist_node vx_hlist;             /* linked list of contexts */
115         xid_t vx_id;                            /* context id */
116         atomic_t vx_usecnt;                     /* usage count */
117         atomic_t vx_tasks;                      /* tasks count */
118         struct vx_info *vx_parent;              /* parent context */
119         int vx_state;                           /* context state */
120
121         struct namespace *vx_namespace;         /* private namespace */
122         struct fs_struct *vx_fs;                /* private namespace fs */
123         uint64_t vx_flags;                      /* context flags */
124         uint64_t vx_bcaps;                      /* bounding caps (system) */
125         uint64_t vx_ccaps;                      /* context caps (vserver) */
126         kernel_cap_t vx_cap_bset;               /* the guest's bset */
127
128         struct task_struct *vx_reaper;          /* guest reaper process */
129         pid_t vx_initpid;                       /* PID of guest init */
130
131         struct _vx_limit limit;                 /* vserver limits */
132         struct _vx_sched sched;                 /* vserver scheduler */
133         struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
134         struct _vx_cacct cacct;                 /* context accounting */
135
136 #ifndef CONFIG_SMP
137         struct _vx_info_pc info_pc;             /* per cpu data */
138 #else
139         struct _vx_info_pc *ptr_pc;             /* per cpu array */
140 #endif
141
142         wait_queue_head_t vx_wait;              /* context exit waitqueue */
143         int reboot_cmd;                         /* last sys_reboot() cmd */
144         int exit_code;                          /* last process exit code */
145
146         char vx_name[65];                       /* vserver name */
147 };
148
149 #ifndef CONFIG_SMP
150 #define vx_ptr_pc(vxi)          (&(vxi)->info_pc)
151 #define vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
152 #else
153 #define vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
154 #define vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
155 #endif
156
157 #define vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
158
159
160 struct vx_info_save {
161         struct vx_info *vxi;
162         xid_t xid;
163 };
164
165
166 /* status flags */
167
168 #define VXS_HASHED      0x0001
169 #define VXS_PAUSED      0x0010
170 #define VXS_SHUTDOWN    0x0100
171 #define VXS_HELPER      0x1000
172 #define VXS_RELEASED    0x8000
173
174 /* check conditions */
175
176 #define VX_ADMIN        0x0001
177 #define VX_WATCH        0x0002
178 #define VX_HIDE         0x0004
179 #define VX_HOSTID       0x0008
180
181 #define VX_IDENT        0x0010
182 #define VX_EQUIV        0x0020
183 #define VX_PARENT       0x0040
184 #define VX_CHILD        0x0080
185
186 #define VX_ARG_MASK     0x00F0
187
188 #define VX_DYNAMIC      0x0100
189 #define VX_STATIC       0x0200
190
191 #define VX_ATR_MASK     0x0F00
192
193
194 #ifdef  CONFIG_VSERVER_PRIVACY
195 #define VX_ADMIN_P      (0)
196 #define VX_WATCH_P      (0)
197 #else
198 #define VX_ADMIN_P      VX_ADMIN
199 #define VX_WATCH_P      VX_WATCH
200 #endif
201
202 extern void claim_vx_info(struct vx_info *, struct task_struct *);
203 extern void release_vx_info(struct vx_info *, struct task_struct *);
204
205 extern struct vx_info *lookup_vx_info(int);
206 extern struct vx_info *lookup_or_create_vx_info(int);
207
208 extern int get_xid_list(int, unsigned int *, int);
209 extern int xid_is_hashed(xid_t);
210
211 extern int vx_migrate_task(struct task_struct *, struct vx_info *);
212
213 extern long vs_state_change(struct vx_info *, unsigned int);
214
215
216 #endif  /* __KERNEL__ */
217 #else   /* _VX_CONTEXT_H */
218 #warning duplicate inclusion
219 #endif  /* _VX_CONTEXT_H */