This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / vserver / base.h
1 #ifndef _VX_BASE_H
2 #define _VX_BASE_H
3
4
5 /* context state changes */
6
7 enum {
8         VSC_STARTUP = 1,
9         VSC_SHUTDOWN,
10
11         VSC_NETUP,
12         VSC_NETDOWN,
13 };
14
15
16 #define MAX_S_CONTEXT   65535   /* Arbitrary limit */
17
18 #ifdef  CONFIG_VSERVER_DYNAMIC_IDS
19 #define MIN_D_CONTEXT   49152   /* dynamic contexts start here */
20 #else
21 #define MIN_D_CONTEXT   65536
22 #endif
23
24 /* check conditions */
25
26 #define VS_ADMIN        0x0001
27 #define VS_WATCH        0x0002
28 #define VS_HIDE         0x0004
29 #define VS_HOSTID       0x0008
30
31 #define VS_IDENT        0x0010
32 #define VS_EQUIV        0x0020
33 #define VS_PARENT       0x0040
34 #define VS_CHILD        0x0080
35
36 #define VS_ARG_MASK     0x00F0
37
38 #define VS_DYNAMIC      0x0100
39 #define VS_STATIC       0x0200
40
41 #define VS_ATR_MASK     0x0F00
42
43 #ifdef  CONFIG_VSERVER_PRIVACY
44 #define VS_ADMIN_P      (0)
45 #define VS_WATCH_P      (0)
46 #else
47 #define VS_ADMIN_P      VS_ADMIN
48 #define VS_WATCH_P      VS_WATCH
49 #endif
50
51 #define VS_HARDIRQ      0x1000
52 #define VS_SOFTIRQ      0x2000
53 #define VS_IRQ          0x4000
54
55 #define VS_IRQ_MASK     0xF000
56
57 #include <linux/hardirq.h>
58
59 /*
60  * check current context for ADMIN/WATCH and
61  * optionally against supplied argument
62  */
63 static inline int __vs_check(int cid, int id, unsigned int mode)
64 {
65         if (mode & VS_ARG_MASK) {
66                 if ((mode & VS_IDENT) &&
67                         (id == cid))
68                         return 1;
69         }
70         if (mode & VS_ATR_MASK) {
71                 if ((mode & VS_DYNAMIC) &&
72                         (id >= MIN_D_CONTEXT) &&
73                         (id <= MAX_S_CONTEXT))
74                         return 1;
75                 if ((mode & VS_STATIC) &&
76                         (id > 1) && (id < MIN_D_CONTEXT))
77                         return 1;
78         }
79         if (mode & VS_IRQ_MASK) {
80                 if ((mode & VS_IRQ) && unlikely(in_interrupt()))
81                         return 1;
82                 if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
83                         return 1;
84                 if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
85                         return 1;
86         }
87         return (((mode & VS_ADMIN) && (cid == 0)) ||
88                 ((mode & VS_WATCH) && (cid == 1)) ||
89                 ((mode & VS_HOSTID) && (id == 0)));
90 }
91
92 #define vx_task_xid(t)  ((t)->xid)
93
94 #define vx_current_xid() vx_task_xid(current)
95
96 #define current_vx_info() (current->vx_info)
97
98
99 #define vx_check(c,m)   __vs_check(vx_current_xid(),c,(m)|VS_IRQ)
100
101 #define vx_weak_check(c,m)      ((m) ? vx_check(c,m) : 1)
102
103
104 #define nx_task_nid(t)  ((t)->nid)
105
106 #define nx_current_nid() nx_task_nid(current)
107
108 #define current_nx_info() (current->nx_info)
109
110
111 #define nx_check(c,m)   __vs_check(nx_current_nid(),c,m)
112
113 #define nx_weak_check(c,m)      ((m) ? nx_check(c,m) : 1)
114
115
116
117 /* generic flag merging */
118
119 #define vs_check_flags(v,m,f)   (((v) & (m)) ^ (f))
120
121 #define vs_mask_flags(v,f,m)    (((v) & ~(m)) | ((f) & (m)))
122
123 #define vs_mask_mask(v,f,m)     (((v) & ~(m)) | ((v) & (f) & (m)))
124
125 #define vs_check_bit(v,n)       ((v) & (1LL << (n)))
126
127
128 /* context flags */
129
130 #define __vx_flags(v)   ((v) ? (v)->vx_flags : 0)
131
132 #define vx_current_flags()      __vx_flags(current->vx_info)
133
134 #define vx_info_flags(v,m,f) \
135         vs_check_flags(__vx_flags(v),(m),(f))
136
137 #define task_vx_flags(t,m,f) \
138         ((t) && vx_info_flags((t)->vx_info, (m), (f)))
139
140 #define vx_flags(m,f)   vx_info_flags(current->vx_info,(m),(f))
141
142
143 /* context caps */
144
145 #define __vx_ccaps(v)   ((v) ? (v)->vx_ccaps : 0)
146
147 #define vx_current_ccaps()      __vx_ccaps(current->vx_info)
148
149 #define vx_info_ccaps(v,c)      (__vx_ccaps(v) & (c))
150
151 #define vx_ccaps(c)     vx_info_ccaps(current->vx_info,(c))
152
153
154
155 /* network flags */
156
157 #define __nx_flags(v)   ((v) ? (v)->nx_flags : 0)
158
159 #define nx_current_flags()      __nx_flags(current->nx_info)
160
161 #define nx_info_flags(v,m,f) \
162         vs_check_flags(__nx_flags(v),(m),(f))
163
164 #define task_nx_flags(t,m,f) \
165         ((t) && nx_info_flags((t)->nx_info, (m), (f)))
166
167 #define nx_flags(m,f)   nx_info_flags(current->nx_info,(m),(f))
168
169
170 /* network caps */
171
172 #define __nx_ncaps(v)   ((v) ? (v)->nx_ncaps : 0)
173
174 #define nx_current_ncaps()      __nx_ncaps(current->nx_info)
175
176 #define nx_info_ncaps(v,c)      (__nx_ncaps(v) & (c))
177
178 #define nx_ncaps(c)     nx_info_ncaps(current->nx_info,(c))
179
180
181 /* context mask capabilities */
182
183 #define __vx_mcaps(v)   ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
184
185 #define vx_info_mcaps(v,c)      (__vx_mcaps(v) & (c))
186
187 #define vx_mcaps(c)     vx_info_mcaps(current->vx_info,(c))
188
189
190 /* context bcap mask */
191
192 #define __vx_bcaps(v)   ((v) ? (v)->vx_bcaps : ~0 )
193
194 #define vx_current_bcaps()      __vx_bcaps(current->vx_info)
195
196 #define vx_info_bcaps(v,c)      (__vx_bcaps(v) & (c))
197
198 #define vx_bcaps(c)     vx_info_bcaps(current->vx_info,(c))
199
200
201 #define vx_info_cap_bset(v)     ((v) ? (v)->vx_cap_bset : cap_bset)
202
203 #define vx_current_cap_bset()   vx_info_cap_bset(current->vx_info)
204
205
206 #define __vx_info_mbcap(v,b) \
207         (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
208         vx_info_bcaps(v, b) : (b))
209
210 #define vx_info_mbcap(v,b)      __vx_info_mbcap(v,cap_t(b))
211
212 #define task_vx_mbcap(t,b) \
213         vx_info_mbcap((t)->vx_info, (t)->b)
214
215 #define vx_mbcap(b)     task_vx_mbcap(current,b)
216
217 #define vx_cap_raised(v,c,f)    (vx_info_mbcap(v,c) & CAP_TO_MASK(f))
218
219 #define vx_capable(b,c) (capable(b) || \
220         (cap_raised(current->cap_effective,b) && vx_ccaps(c)))
221
222
223 #define vx_current_initpid(n) \
224         (current->vx_info && \
225         (current->vx_info->vx_initpid == (n)))
226
227
228 #define __vx_state(v)   ((v) ? ((v)->vx_state) : 0)
229
230 #define vx_info_state(v,m)      (__vx_state(v) & (m))
231
232
233 #define __nx_state(v)   ((v) ? ((v)->nx_state) : 0)
234
235 #define nx_info_state(v,m)      (__nx_state(v) & (m))
236
237 #endif