initial checkin
[util-vserver.git] / util-vserver / kernel / context.h
1 #ifndef _VX_CONTEXT_H
2 #define _VX_CONTEXT_H
3
4 #include <linux/types.h>
5
6
7 #define MAX_S_CONTEXT   65535   /* Arbitrary limit */
8 #define MIN_D_CONTEXT   49152   /* dynamic contexts start here */
9
10 #define VX_DYNAMIC_ID   ((uint32_t)-1)          /* id for dynamic context */
11
12 #ifdef  __KERNEL__
13
14 #include <linux/utsname.h>
15
16 struct _vx_virt {
17         int nr_threads;
18         int nr_running;
19         int max_threads;
20         unsigned long total_forks;
21
22         unsigned int bias_cswtch;
23         long bias_jiffies;
24         long bias_idle;
25
26         struct new_utsname utsname;
27 };
28
29
30 #include <linux/list.h>
31 #include <linux/spinlock.h>
32 #include <asm/atomic.h>
33
34 #define _VX_INFO_DEF_
35 #include "limit.h"
36 #include "sched.h"
37 #undef  _VX_INFO_DEF_
38
39 struct vx_info {
40         struct list_head vx_list;               /* linked list of contexts */
41         xid_t vx_id;                            /* context id */
42         atomic_t vx_refcount;                   /* refcount */
43         struct vx_info *vx_parent;              /* parent context */
44
45         struct namespace *vx_namespace;         /* private namespace */
46         struct fs_struct *vx_fs;                /* private namespace fs */
47         uint64_t vx_flags;                      /* VX_INFO_xxx */
48         uint64_t vx_bcaps;                      /* bounding caps (system) */
49         uint64_t vx_ccaps;                      /* context caps (vserver) */
50
51         pid_t vx_initpid;                       /* PID of fake init process */
52
53         struct _vx_virt virt;                   /* virtual/bias stuff */
54         struct _vx_limit limit;                 /* vserver limits */
55         struct _vx_sched sched;                 /* vserver scheduler */
56
57         char vx_name[65];                       /* vserver name */
58 };
59
60
61 extern spinlock_t vxlist_lock;
62 extern struct list_head vx_infos;
63
64
65 #define VX_ADMIN        0x0001
66 #define VX_WATCH        0x0002
67 #define VX_DUMMY        0x0008
68
69 #define VX_IDENT        0x0010
70 #define VX_EQUIV        0x0020
71 #define VX_PARENT       0x0040
72 #define VX_CHILD        0x0080
73
74 #define VX_ARG_MASK     0x00F0
75
76 #define VX_DYNAMIC      0x0100
77 #define VX_STATIC       0x0200
78
79 #define VX_ATR_MASK     0x0F00
80
81
82 void free_vx_info(struct vx_info *);
83
84 extern struct vx_info *find_vx_info(int);
85 extern struct vx_info *find_or_create_vx_info(int);
86
87 extern int vx_migrate_task(struct task_struct *, struct vx_info *);
88
89 #endif  /* __KERNEL__ */
90
91 #include "switch.h"
92
93 /* vinfo commands */
94
95 #define VCMD_task_xid           VC_CMD(VINFO, 1, 0)
96 #define VCMD_task_nid           VC_CMD(VINFO, 2, 0)
97
98 #ifdef  __KERNEL__
99 extern int vc_task_xid(uint32_t, void *);
100
101 #endif  /* __KERNEL__ */
102
103 #define VCMD_vx_info            VC_CMD(VINFO, 5, 0)
104 #define VCMD_nx_info            VC_CMD(VINFO, 6, 0)
105
106 struct  vcmd_vx_info_v0 {
107         uint32_t xid;
108         uint32_t initpid;
109         /* more to come */      
110 };
111
112 #ifdef  __KERNEL__
113 extern int vc_vx_info(uint32_t, void *);
114
115 #endif  /* __KERNEL__ */
116
117 #define VCMD_create_context     VC_CMD(VSETUP, 1, 0)
118 #define VCMD_migrate_context    VC_CMD(PROCMIG, 1, 0)
119
120 #ifdef  __KERNEL__
121 extern int vc_create_context(uint32_t, void *);
122 extern int vc_migrate_context(uint32_t, void *);
123
124 #endif  /* __KERNEL__ */
125
126 #define VCMD_get_flags          VC_CMD(FLAGS, 1, 0)
127 #define VCMD_set_flags          VC_CMD(FLAGS, 2, 0)
128
129 struct  vcmd_ctx_flags_v0 {
130         uint64_t flagword;
131         uint64_t mask;
132 };
133
134 #ifdef  __KERNEL__
135 extern int vc_get_flags(uint32_t, void *);
136 extern int vc_set_flags(uint32_t, void *);
137
138 #endif  /* __KERNEL__ */
139
140 #define VXF_INFO_LOCK           0x00000001
141 #define VXF_INFO_NPROC          0x00000002
142 #define VXF_INFO_PRIVATE        0x00000004
143 #define VXF_INFO_INIT           0x00000008
144
145 #define VXF_INFO_HIDE           0x00000010
146 #define VXF_INFO_ULIMIT         0x00000020
147 #define VXF_INFO_NSPACE         0x00000040
148
149 #define VXF_SCHED_HARD          0x00000100
150 #define VXF_SCHED_PRIO          0x00000200
151 #define VXF_SCHED_PAUSE         0x00000400
152
153 #define VXF_VIRT_MEM            0x00010000
154 #define VXF_VIRT_UPTIME         0x00020000
155
156 #define VXF_STATE_SETUP         (1ULL<<32)
157 #define VXF_STATE_INIT          (1ULL<<33)
158
159 #define VCMD_get_ccaps          VC_CMD(FLAGS, 3, 0)
160 #define VCMD_set_ccaps          VC_CMD(FLAGS, 4, 0)
161
162 struct  vcmd_ctx_caps_v0 {
163         uint64_t bcaps;
164         uint64_t ccaps;
165         uint64_t cmask;
166 };
167
168 #ifdef  __KERNEL__
169 extern int vc_get_ccaps(uint32_t, void *);
170 extern int vc_set_ccaps(uint32_t, void *);
171
172 #endif  /* __KERNEL__ */
173
174 #define VXC_SET_UTSNAME         0x00000001
175 #define VXC_SET_RLIMIT          0x00000002
176
177 #define VXC_ICMP_PING           0x00000100
178
179 #define VXC_SECURE_MOUNT        0x00010000
180
181
182 #endif  /* _VX_CONTEXT_H */