]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.2.9
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.2.8/Documentation/vserver/debug.txt linux-3.2.8-vs2.3.2.7/Documentation/vserver/debug.txt
2 --- linux-3.2.8/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.2.8-vs2.3.2.7/Documentation/vserver/debug.txt       2011-12-05 19:33:02.000000000 +0100
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.2.8/arch/alpha/Kconfig linux-3.2.8-vs2.3.2.7/arch/alpha/Kconfig
160 --- linux-3.2.8/arch/alpha/Kconfig      2012-01-09 16:13:54.000000000 +0100
161 +++ linux-3.2.8-vs2.3.2.7/arch/alpha/Kconfig    2011-12-05 19:33:02.000000000 +0100
162 @@ -665,6 +665,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.2.8/arch/alpha/kernel/entry.S linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/entry.S
172 --- linux-3.2.8/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/entry.S     2011-12-05 19:33:02.000000000 +0100
174 @@ -860,24 +860,15 @@ sys_getxgid:
175         .globl  sys_getxpid
176         .ent    sys_getxpid
177  sys_getxpid:
178 +       lda     $sp, -16($sp)
179 +       stq     $26, 0($sp)
180         .prologue 0
181 -       ldq     $2, TI_TASK($8)
182  
183 -       /* See linux/kernel/timer.c sys_getppid for discussion
184 -          about this loop.  */
185 -       ldq     $3, TASK_GROUP_LEADER($2)
186 -       ldq     $4, TASK_REAL_PARENT($3)
187 -       ldl     $0, TASK_TGID($2)
188 -1:     ldl     $1, TASK_TGID($4)
189 -#ifdef CONFIG_SMP
190 -       mov     $4, $5
191 -       mb
192 -       ldq     $3, TASK_GROUP_LEADER($2)
193 -       ldq     $4, TASK_REAL_PARENT($3)
194 -       cmpeq   $4, $5, $5
195 -       beq     $5, 1b
196 -#endif
197 -       stq     $1, 80($sp)
198 +       lda     $16, 96($sp)
199 +       jsr     $26, do_getxpid
200 +       ldq     $26, 0($sp)
201 +
202 +       lda     $sp, 16($sp)
203         ret
204  .end sys_getxpid
205  
206 diff -NurpP --minimal linux-3.2.8/arch/alpha/kernel/ptrace.c linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/ptrace.c
207 --- linux-3.2.8/arch/alpha/kernel/ptrace.c      2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/ptrace.c    2011-12-05 19:33:02.000000000 +0100
209 @@ -13,6 +13,7 @@
210  #include <linux/user.h>
211  #include <linux/security.h>
212  #include <linux/signal.h>
213 +#include <linux/vs_base.h>
214  
215  #include <asm/uaccess.h>
216  #include <asm/pgtable.h>
217 diff -NurpP --minimal linux-3.2.8/arch/alpha/kernel/systbls.S linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/systbls.S
218 --- linux-3.2.8/arch/alpha/kernel/systbls.S     2012-01-09 16:13:54.000000000 +0100
219 +++ linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/systbls.S   2011-12-05 19:33:02.000000000 +0100
220 @@ -446,7 +446,7 @@ sys_call_table:
221         .quad sys_stat64                        /* 425 */
222         .quad sys_lstat64
223         .quad sys_fstat64
224 -       .quad sys_ni_syscall                    /* sys_vserver */
225 +       .quad sys_vserver                       /* sys_vserver */
226         .quad sys_ni_syscall                    /* sys_mbind */
227         .quad sys_ni_syscall                    /* sys_get_mempolicy */
228         .quad sys_ni_syscall                    /* sys_set_mempolicy */
229 diff -NurpP --minimal linux-3.2.8/arch/alpha/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/traps.c
230 --- linux-3.2.8/arch/alpha/kernel/traps.c       2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.2.8-vs2.3.2.7/arch/alpha/kernel/traps.c     2011-12-05 19:33:02.000000000 +0100
232 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
233  #ifdef CONFIG_SMP
234         printk("CPU %d ", hard_smp_processor_id());
235  #endif
236 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
237 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
238 +               task_pid_nr(current), current->xid, str, err);
239         dik_show_regs(regs, r9_15);
240         add_taint(TAINT_DIE);
241         dik_show_trace((unsigned long *)(regs+1));
242 diff -NurpP --minimal linux-3.2.8/arch/arm/Kconfig linux-3.2.8-vs2.3.2.7/arch/arm/Kconfig
243 --- linux-3.2.8/arch/arm/Kconfig        2012-01-09 16:13:54.000000000 +0100
244 +++ linux-3.2.8-vs2.3.2.7/arch/arm/Kconfig      2012-01-09 16:19:31.000000000 +0100
245 @@ -2242,6 +2242,8 @@ source "fs/Kconfig"
246  
247  source "arch/arm/Kconfig.debug"
248  
249 +source "kernel/vserver/Kconfig"
250 +
251  source "security/Kconfig"
252  
253  source "crypto/Kconfig"
254 diff -NurpP --minimal linux-3.2.8/arch/arm/kernel/calls.S linux-3.2.8-vs2.3.2.7/arch/arm/kernel/calls.S
255 --- linux-3.2.8/arch/arm/kernel/calls.S 2012-01-09 16:13:54.000000000 +0100
256 +++ linux-3.2.8-vs2.3.2.7/arch/arm/kernel/calls.S       2011-12-05 19:33:02.000000000 +0100
257 @@ -322,7 +322,7 @@
258  /* 310 */      CALL(sys_request_key)
259                 CALL(sys_keyctl)
260                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
261 -/* vserver */  CALL(sys_ni_syscall)
262 +               CALL(sys_vserver)
263                 CALL(sys_ioprio_set)
264  /* 315 */      CALL(sys_ioprio_get)
265                 CALL(sys_inotify_init)
266 diff -NurpP --minimal linux-3.2.8/arch/arm/kernel/process.c linux-3.2.8-vs2.3.2.7/arch/arm/kernel/process.c
267 --- linux-3.2.8/arch/arm/kernel/process.c       2012-01-09 16:13:54.000000000 +0100
268 +++ linux-3.2.8-vs2.3.2.7/arch/arm/kernel/process.c     2011-12-05 19:33:02.000000000 +0100
269 @@ -320,7 +320,8 @@ void __show_regs(struct pt_regs *regs)
270  void show_regs(struct pt_regs * regs)
271  {
272         printk("\n");
273 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
274 +       printk("Pid: %d[#%u], comm: %20s\n",
275 +               task_pid_nr(current), current->xid, current->comm);
276         __show_regs(regs);
277         dump_stack();
278  }
279 diff -NurpP --minimal linux-3.2.8/arch/arm/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/arm/kernel/traps.c
280 --- linux-3.2.8/arch/arm/kernel/traps.c 2012-01-09 16:13:54.000000000 +0100
281 +++ linux-3.2.8-vs2.3.2.7/arch/arm/kernel/traps.c       2011-12-05 19:33:02.000000000 +0100
282 @@ -244,8 +244,8 @@ static int __die(const char *str, int er
283  
284         print_modules();
285         __show_regs(regs);
286 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
287 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
288 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
289 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
290  
291         if (!user_mode(regs) || in_interrupt()) {
292                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
293 diff -NurpP --minimal linux-3.2.8/arch/cris/Kconfig linux-3.2.8-vs2.3.2.7/arch/cris/Kconfig
294 --- linux-3.2.8/arch/cris/Kconfig       2012-01-09 16:14:01.000000000 +0100
295 +++ linux-3.2.8-vs2.3.2.7/arch/cris/Kconfig     2011-12-05 19:33:02.000000000 +0100
296 @@ -678,6 +678,8 @@ source "drivers/staging/Kconfig"
297  
298  source "arch/cris/Kconfig.debug"
299  
300 +source "kernel/vserver/Kconfig"
301 +
302  source "security/Kconfig"
303  
304  source "crypto/Kconfig"
305 diff -NurpP --minimal linux-3.2.8/arch/frv/kernel/kernel_thread.S linux-3.2.8-vs2.3.2.7/arch/frv/kernel/kernel_thread.S
306 --- linux-3.2.8/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.2.8-vs2.3.2.7/arch/frv/kernel/kernel_thread.S       2011-12-05 19:33:02.000000000 +0100
308 @@ -37,7 +37,7 @@ kernel_thread:
309  
310         # start by forking the current process, but with shared VM
311         setlos.p        #__NR_clone,gr7         ; syscall number
312 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
313 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
314         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
315         setlo           #0xe4e4,gr9
316         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
317 diff -NurpP --minimal linux-3.2.8/arch/h8300/Kconfig linux-3.2.8-vs2.3.2.7/arch/h8300/Kconfig
318 --- linux-3.2.8/arch/h8300/Kconfig      2012-01-09 16:14:01.000000000 +0100
319 +++ linux-3.2.8-vs2.3.2.7/arch/h8300/Kconfig    2011-12-05 19:33:02.000000000 +0100
320 @@ -213,6 +213,8 @@ source "fs/Kconfig"
321  
322  source "arch/h8300/Kconfig.debug"
323  
324 +source "kernel/vserver/Kconfig"
325 +
326  source "security/Kconfig"
327  
328  source "crypto/Kconfig"
329 diff -NurpP --minimal linux-3.2.8/arch/ia64/Kconfig linux-3.2.8-vs2.3.2.7/arch/ia64/Kconfig
330 --- linux-3.2.8/arch/ia64/Kconfig       2012-01-09 16:14:01.000000000 +0100
331 +++ linux-3.2.8-vs2.3.2.7/arch/ia64/Kconfig     2011-12-05 19:33:02.000000000 +0100
332 @@ -657,6 +657,8 @@ source "fs/Kconfig"
333  
334  source "arch/ia64/Kconfig.debug"
335  
336 +source "kernel/vserver/Kconfig"
337 +
338  source "security/Kconfig"
339  
340  source "crypto/Kconfig"
341 diff -NurpP --minimal linux-3.2.8/arch/ia64/kernel/entry.S linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/entry.S
342 --- linux-3.2.8/arch/ia64/kernel/entry.S        2012-01-09 16:14:02.000000000 +0100
343 +++ linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/entry.S      2011-12-05 19:33:02.000000000 +0100
344 @@ -1714,7 +1714,7 @@ sys_call_table:
345         data8 sys_mq_notify
346         data8 sys_mq_getsetattr
347         data8 sys_kexec_load
348 -       data8 sys_ni_syscall                    // reserved for vserver
349 +       data8 sys_vserver
350         data8 sys_waitid                        // 1270
351         data8 sys_add_key
352         data8 sys_request_key
353 diff -NurpP --minimal linux-3.2.8/arch/ia64/kernel/process.c linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/process.c
354 --- linux-3.2.8/arch/ia64/kernel/process.c      2011-03-15 18:06:39.000000000 +0100
355 +++ linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/process.c    2011-12-05 19:33:02.000000000 +0100
356 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
357         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
358  
359         print_modules();
360 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
361 -                       smp_processor_id(), current->comm);
362 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
363 +                       current->xid, smp_processor_id(), current->comm);
364         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
365                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
366                init_utsname()->release);
367 diff -NurpP --minimal linux-3.2.8/arch/ia64/kernel/ptrace.c linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/ptrace.c
368 --- linux-3.2.8/arch/ia64/kernel/ptrace.c       2011-01-05 21:48:59.000000000 +0100
369 +++ linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/ptrace.c     2011-12-05 19:33:02.000000000 +0100
370 @@ -21,6 +21,7 @@
371  #include <linux/regset.h>
372  #include <linux/elf.h>
373  #include <linux/tracehook.h>
374 +#include <linux/vs_base.h>
375  
376  #include <asm/pgtable.h>
377  #include <asm/processor.h>
378 diff -NurpP --minimal linux-3.2.8/arch/ia64/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/traps.c
379 --- linux-3.2.8/arch/ia64/kernel/traps.c        2010-07-07 18:31:01.000000000 +0200
380 +++ linux-3.2.8-vs2.3.2.7/arch/ia64/kernel/traps.c      2011-12-05 19:33:02.000000000 +0100
381 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
382         put_cpu();
383  
384         if (++die.lock_owner_depth < 3) {
385 -               printk("%s[%d]: %s %ld [%d]\n",
386 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
387 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
388 +                       current->comm, task_pid_nr(current), current->xid,
389 +                       str, err, ++die_counter);
390                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
391                     != NOTIFY_STOP)
392                         show_regs(regs);
393 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
394                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
395                                 last.time = current_jiffies + 5 * HZ;
396                                 printk(KERN_WARNING
397 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
398 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
399 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
400 +                                       current->comm, task_pid_nr(current), current->xid,
401 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
402                         }
403                 }
404         }
405 diff -NurpP --minimal linux-3.2.8/arch/m32r/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/m32r/kernel/traps.c
406 --- linux-3.2.8/arch/m32r/kernel/traps.c        2011-10-24 18:44:58.000000000 +0200
407 +++ linux-3.2.8-vs2.3.2.7/arch/m32r/kernel/traps.c      2011-12-05 19:33:02.000000000 +0100
408 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
409         } else {
410                 printk("SPI: %08lx\n", sp);
411         }
412 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
413 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
414 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
415 +               current->comm, task_pid_nr(current), current->xid,
416 +               0xffff & i, 4096+(unsigned long)current);
417  
418         /*
419          * When in-kernel, we also print out the stack and code at the
420 diff -NurpP --minimal linux-3.2.8/arch/m68k/Kconfig linux-3.2.8-vs2.3.2.7/arch/m68k/Kconfig
421 --- linux-3.2.8/arch/m68k/Kconfig       2012-01-09 16:14:03.000000000 +0100
422 +++ linux-3.2.8-vs2.3.2.7/arch/m68k/Kconfig     2011-12-05 19:33:02.000000000 +0100
423 @@ -135,6 +135,8 @@ source "fs/Kconfig"
424  
425  source "arch/m68k/Kconfig.debug"
426  
427 +source "kernel/vserver/Kconfig"
428 +
429  source "security/Kconfig"
430  
431  source "crypto/Kconfig"
432 diff -NurpP --minimal linux-3.2.8/arch/mips/Kconfig linux-3.2.8-vs2.3.2.7/arch/mips/Kconfig
433 --- linux-3.2.8/arch/mips/Kconfig       2012-01-09 16:14:04.000000000 +0100
434 +++ linux-3.2.8-vs2.3.2.7/arch/mips/Kconfig     2011-12-05 19:33:02.000000000 +0100
435 @@ -2478,6 +2478,8 @@ source "fs/Kconfig"
436  
437  source "arch/mips/Kconfig.debug"
438  
439 +source "kernel/vserver/Kconfig"
440 +
441  source "security/Kconfig"
442  
443  source "crypto/Kconfig"
444 diff -NurpP --minimal linux-3.2.8/arch/mips/kernel/ptrace.c linux-3.2.8-vs2.3.2.7/arch/mips/kernel/ptrace.c
445 --- linux-3.2.8/arch/mips/kernel/ptrace.c       2011-07-22 11:17:36.000000000 +0200
446 +++ linux-3.2.8-vs2.3.2.7/arch/mips/kernel/ptrace.c     2011-12-05 19:33:02.000000000 +0100
447 @@ -25,6 +25,7 @@
448  #include <linux/security.h>
449  #include <linux/audit.h>
450  #include <linux/seccomp.h>
451 +#include <linux/vs_base.h>
452  
453  #include <asm/byteorder.h>
454  #include <asm/cpu.h>
455 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
456         void __user *datavp = (void __user *) data;
457         unsigned long __user *datalp = (void __user *) data;
458  
459 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
460 +               goto out;
461 +
462         switch (request) {
463         /* when I and D space are separate, these will need to be fixed. */
464         case PTRACE_PEEKTEXT: /* read word at location addr. */
465 diff -NurpP --minimal linux-3.2.8/arch/mips/kernel/scall32-o32.S linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall32-o32.S
466 --- linux-3.2.8/arch/mips/kernel/scall32-o32.S  2012-01-09 16:14:05.000000000 +0100
467 +++ linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall32-o32.S        2011-12-05 19:33:02.000000000 +0100
468 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
469         sys     sys_mq_timedreceive     5
470         sys     sys_mq_notify           2       /* 4275 */
471         sys     sys_mq_getsetattr       3
472 -       sys     sys_ni_syscall          0       /* sys_vserver */
473 +       sys     sys_vserver             3
474         sys     sys_waitid              5
475         sys     sys_ni_syscall          0       /* available, was setaltroot */
476         sys     sys_add_key             5       /* 4280 */
477 diff -NurpP --minimal linux-3.2.8/arch/mips/kernel/scall64-64.S linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall64-64.S
478 --- linux-3.2.8/arch/mips/kernel/scall64-64.S   2012-01-09 16:14:05.000000000 +0100
479 +++ linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall64-64.S 2011-12-05 19:33:02.000000000 +0100
480 @@ -362,7 +362,7 @@ sys_call_table:
481         PTR     sys_mq_timedreceive
482         PTR     sys_mq_notify
483         PTR     sys_mq_getsetattr               /* 5235 */
484 -       PTR     sys_ni_syscall                  /* sys_vserver */
485 +       PTR     sys_vserver
486         PTR     sys_waitid
487         PTR     sys_ni_syscall                  /* available, was setaltroot */
488         PTR     sys_add_key
489 diff -NurpP --minimal linux-3.2.8/arch/mips/kernel/scall64-n32.S linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall64-n32.S
490 --- linux-3.2.8/arch/mips/kernel/scall64-n32.S  2012-01-09 16:14:05.000000000 +0100
491 +++ linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall64-n32.S        2011-12-05 19:33:02.000000000 +0100
492 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
493         PTR     compat_sys_mq_timedreceive
494         PTR     compat_sys_mq_notify
495         PTR     compat_sys_mq_getsetattr
496 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
497 +       PTR     sys32_vserver                   /* 6240 */
498         PTR     compat_sys_waitid
499         PTR     sys_ni_syscall                  /* available, was setaltroot */
500         PTR     sys_add_key
501 diff -NurpP --minimal linux-3.2.8/arch/mips/kernel/scall64-o32.S linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall64-o32.S
502 --- linux-3.2.8/arch/mips/kernel/scall64-o32.S  2012-01-09 16:14:05.000000000 +0100
503 +++ linux-3.2.8-vs2.3.2.7/arch/mips/kernel/scall64-o32.S        2011-12-05 19:33:02.000000000 +0100
504 @@ -480,7 +480,7 @@ sys_call_table:
505         PTR     compat_sys_mq_timedreceive
506         PTR     compat_sys_mq_notify            /* 4275 */
507         PTR     compat_sys_mq_getsetattr
508 -       PTR     sys_ni_syscall                  /* sys_vserver */
509 +       PTR     sys32_vserver
510         PTR     sys_32_waitid
511         PTR     sys_ni_syscall                  /* available, was setaltroot */
512         PTR     sys_add_key                     /* 4280 */
513 diff -NurpP --minimal linux-3.2.8/arch/mips/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/mips/kernel/traps.c
514 --- linux-3.2.8/arch/mips/kernel/traps.c        2012-01-09 16:14:05.000000000 +0100
515 +++ linux-3.2.8-vs2.3.2.7/arch/mips/kernel/traps.c      2011-12-05 19:33:02.000000000 +0100
516 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
517  
518         __show_regs(regs);
519         print_modules();
520 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
521 -              current->comm, current->pid, current_thread_info(), current,
522 -             field, current_thread_info()->tp_value);
523 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
524 +               current->comm, task_pid_nr(current), current->xid,
525 +               current_thread_info(), current,
526 +               field, current_thread_info()->tp_value);
527         if (cpu_has_userlocal) {
528                 unsigned long tls;
529  
530 diff -NurpP --minimal linux-3.2.8/arch/parisc/Kconfig linux-3.2.8-vs2.3.2.7/arch/parisc/Kconfig
531 --- linux-3.2.8/arch/parisc/Kconfig     2012-01-09 16:14:05.000000000 +0100
532 +++ linux-3.2.8-vs2.3.2.7/arch/parisc/Kconfig   2011-12-05 19:33:02.000000000 +0100
533 @@ -278,6 +278,8 @@ source "fs/Kconfig"
534  
535  source "arch/parisc/Kconfig.debug"
536  
537 +source "kernel/vserver/Kconfig"
538 +
539  source "security/Kconfig"
540  
541  source "crypto/Kconfig"
542 diff -NurpP --minimal linux-3.2.8/arch/parisc/kernel/syscall_table.S linux-3.2.8-vs2.3.2.7/arch/parisc/kernel/syscall_table.S
543 --- linux-3.2.8/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
544 +++ linux-3.2.8-vs2.3.2.7/arch/parisc/kernel/syscall_table.S    2011-12-05 19:33:02.000000000 +0100
545 @@ -361,7 +361,7 @@
546         ENTRY_COMP(mbind)               /* 260 */
547         ENTRY_COMP(get_mempolicy)
548         ENTRY_COMP(set_mempolicy)
549 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
550 +       ENTRY_DIFF(vserver)
551         ENTRY_SAME(add_key)
552         ENTRY_SAME(request_key)         /* 265 */
553         ENTRY_SAME(keyctl)
554 diff -NurpP --minimal linux-3.2.8/arch/parisc/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/parisc/kernel/traps.c
555 --- linux-3.2.8/arch/parisc/kernel/traps.c      2011-10-24 18:45:00.000000000 +0200
556 +++ linux-3.2.8-vs2.3.2.7/arch/parisc/kernel/traps.c    2011-12-05 19:33:02.000000000 +0100
557 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
558                 if (err == 0)
559                         return; /* STFU */
560  
561 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
562 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
563 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
564 +                       current->comm, task_pid_nr(current), current->xid,
565 +                       str, err, regs->iaoq[0]);
566  #ifdef PRINT_USER_FAULTS
567                 /* XXX for debugging only */
568                 show_regs(regs);
569 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
570                 pdc_console_restart();
571         
572         if (err)
573 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
574 -                       current->comm, task_pid_nr(current), str, err);
575 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
576 +                       current->comm, task_pid_nr(current), current->xid, str, err);
577  
578         /* Wot's wrong wif bein' racy? */
579         if (current->thread.flags & PARISC_KERNEL_DEATH) {
580 diff -NurpP --minimal linux-3.2.8/arch/parisc/mm/fault.c linux-3.2.8-vs2.3.2.7/arch/parisc/mm/fault.c
581 --- linux-3.2.8/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
582 +++ linux-3.2.8-vs2.3.2.7/arch/parisc/mm/fault.c        2011-12-05 19:33:02.000000000 +0100
583 @@ -237,8 +237,9 @@ bad_area:
584  
585  #ifdef PRINT_USER_FAULTS
586                 printk(KERN_DEBUG "\n");
587 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
588 -                   task_pid_nr(tsk), tsk->comm, code, address);
589 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
590 +                   "command='%s' type=%lu address=0x%08lx\n",
591 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
592                 if (vma) {
593                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
594                                         vma->vm_start, vma->vm_end);
595 diff -NurpP --minimal linux-3.2.8/arch/powerpc/Kconfig linux-3.2.8-vs2.3.2.7/arch/powerpc/Kconfig
596 --- linux-3.2.8/arch/powerpc/Kconfig    2012-01-09 16:14:05.000000000 +0100
597 +++ linux-3.2.8-vs2.3.2.7/arch/powerpc/Kconfig  2011-12-05 19:33:02.000000000 +0100
598 @@ -960,6 +960,8 @@ source "lib/Kconfig"
599  
600  source "arch/powerpc/Kconfig.debug"
601  
602 +source "kernel/vserver/Kconfig"
603 +
604  source "security/Kconfig"
605  
606  config KEYS_COMPAT
607 diff -NurpP --minimal linux-3.2.8/arch/powerpc/include/asm/unistd.h linux-3.2.8-vs2.3.2.7/arch/powerpc/include/asm/unistd.h
608 --- linux-3.2.8/arch/powerpc/include/asm/unistd.h       2012-01-09 16:14:05.000000000 +0100
609 +++ linux-3.2.8-vs2.3.2.7/arch/powerpc/include/asm/unistd.h     2011-12-05 19:33:02.000000000 +0100
610 @@ -275,7 +275,7 @@
611  #endif
612  #define __NR_rtas              255
613  #define __NR_sys_debug_setcontext 256
614 -/* Number 257 is reserved for vserver */
615 +#define __NR_vserver           257
616  #define __NR_migrate_pages     258
617  #define __NR_mbind             259
618  #define __NR_get_mempolicy     260
619 diff -NurpP --minimal linux-3.2.8/arch/powerpc/kernel/process.c linux-3.2.8-vs2.3.2.7/arch/powerpc/kernel/process.c
620 --- linux-3.2.8/arch/powerpc/kernel/process.c   2012-01-09 16:14:05.000000000 +0100
621 +++ linux-3.2.8-vs2.3.2.7/arch/powerpc/kernel/process.c 2011-12-05 19:33:02.000000000 +0100
622 @@ -640,8 +640,9 @@ void show_regs(struct pt_regs * regs)
623  #else
624                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
625  #endif
626 -       printk("TASK = %p[%d] '%s' THREAD: %p",
627 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
628 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
629 +              current, task_pid_nr(current), current->xid,
630 +              current->comm, task_thread_info(current));
631  
632  #ifdef CONFIG_SMP
633         printk(" CPU: %d", raw_smp_processor_id());
634 diff -NurpP --minimal linux-3.2.8/arch/powerpc/kernel/traps.c linux-3.2.8-vs2.3.2.7/arch/powerpc/kernel/traps.c
635 --- linux-3.2.8/arch/powerpc/kernel/traps.c     2012-01-09 16:14:05.000000000 +0100
636 +++ linux-3.2.8-vs2.3.2.7/arch/powerpc/kernel/traps.c   2011-12-05 19:33:02.000000000 +0100
637 @@ -1082,8 +1082,9 @@ void nonrecoverable_exception(struct pt_
638  
639  void trace_syscall(struct pt_regs *regs)
640  {
641 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
642 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
643 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
644 +              current, task_pid_nr(current), current->xid,
645 +              regs->nip, regs->link, regs->gpr[0],
646                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
647  }
648  
649 diff -NurpP --minimal linux-3.2.8/arch/s390/Kconfig linux-3.2.8-vs2.3.2.7/arch/s390/Kconfig
650 --- linux-3.2.8/arch/s390/Kconfig       2012-01-09 16:14:06.000000000 +0100
651 +++ linux-3.2.8-vs2.3.2.7/arch/s390/Kconfig     2011-12-05 19:33:02.000000000 +0100
652 @@ -641,6 +641,8 @@ source "fs/Kconfig"
653  
654  source "arch/s390/Kconfig.debug"
655  
656 +source "kernel/vserver/Kconfig"
657 +
658  source "security/Kconfig"
659  
660  source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.2.8/arch/s390/include/asm/tlb.h linux-3.2.8-vs2.3.2.7/arch/s390/include/asm/tlb.h
662 --- linux-3.2.8/arch/s390/include/asm/tlb.h     2011-07-22 11:17:41.000000000 +0200
663 +++ linux-3.2.8-vs2.3.2.7/arch/s390/include/asm/tlb.h   2011-12-15 01:52:28.000000000 +0100
664 @@ -24,6 +24,7 @@
665  #include <linux/mm.h>
666  #include <linux/pagemap.h>
667  #include <linux/swap.h>
668 +
669  #include <asm/processor.h>
670  #include <asm/pgalloc.h>
671  #include <asm/tlbflush.h>
672 diff -NurpP --minimal linux-3.2.8/arch/s390/include/asm/unistd.h linux-3.2.8-vs2.3.2.7/arch/s390/include/asm/unistd.h
673 --- linux-3.2.8/arch/s390/include/asm/unistd.h  2012-01-09 16:14:06.000000000 +0100
674 +++ linux-3.2.8-vs2.3.2.7/arch/s390/include/asm/unistd.h        2011-12-05 19:33:02.000000000 +0100
675 @@ -202,7 +202,7 @@
676  #define __NR_clock_gettime     (__NR_timer_create+6)
677  #define __NR_clock_getres      (__NR_timer_create+7)
678  #define __NR_clock_nanosleep   (__NR_timer_create+8)
679 -/* Number 263 is reserved for vserver */
680 +#define __NR_vserver           263
681  #define __NR_statfs64          265
682  #define __NR_fstatfs64         266
683  #define __NR_remap_file_pages  267
684 diff -NurpP --minimal linux-3.2.8/arch/s390/kernel/ptrace.c linux-3.2.8-vs2.3.2.7/arch/s390/kernel/ptrace.c
685 --- linux-3.2.8/arch/s390/kernel/ptrace.c       2012-01-09 16:14:06.000000000 +0100
686 +++ linux-3.2.8-vs2.3.2.7/arch/s390/kernel/ptrace.c     2011-12-15 01:11:29.000000000 +0100
687 @@ -20,6 +20,7 @@
688  #include <linux/regset.h>
689  #include <linux/tracehook.h>
690  #include <linux/seccomp.h>
691 +#include <linux/vs_base.h>
692  #include <trace/syscall.h>
693  #include <asm/compat.h>
694  #include <asm/segment.h>
695 diff -NurpP --minimal linux-3.2.8/arch/s390/kernel/syscalls.S linux-3.2.8-vs2.3.2.7/arch/s390/kernel/syscalls.S
696 --- linux-3.2.8/arch/s390/kernel/syscalls.S     2012-01-09 16:14:06.000000000 +0100
697 +++ linux-3.2.8-vs2.3.2.7/arch/s390/kernel/syscalls.S   2011-12-05 19:33:02.000000000 +0100
698 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
699  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
700  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
701  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
702 -NI_SYSCALL                                                     /* reserved for vserver */
703 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
704  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
705  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
706  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
707 diff -NurpP --minimal linux-3.2.8/arch/sh/Kconfig linux-3.2.8-vs2.3.2.7/arch/sh/Kconfig
708 --- linux-3.2.8/arch/sh/Kconfig 2012-01-09 16:14:07.000000000 +0100
709 +++ linux-3.2.8-vs2.3.2.7/arch/sh/Kconfig       2011-12-05 19:33:02.000000000 +0100
710 @@ -901,6 +901,8 @@ source "fs/Kconfig"
711  
712  source "arch/sh/Kconfig.debug"
713  
714 +source "kernel/vserver/Kconfig"
715 +
716  source "security/Kconfig"
717  
718  source "crypto/Kconfig"
719 diff -NurpP --minimal linux-3.2.8/arch/sh/kernel/irq.c linux-3.2.8-vs2.3.2.7/arch/sh/kernel/irq.c
720 --- linux-3.2.8/arch/sh/kernel/irq.c    2011-07-22 11:17:41.000000000 +0200
721 +++ linux-3.2.8-vs2.3.2.7/arch/sh/kernel/irq.c  2011-12-05 19:33:02.000000000 +0100
722 @@ -14,6 +14,7 @@
723  #include <linux/ftrace.h>
724  #include <linux/delay.h>
725  #include <linux/ratelimit.h>
726 +// #include <linux/vs_context.h>
727  #include <asm/processor.h>
728  #include <asm/machvec.h>
729  #include <asm/uaccess.h>
730 diff -NurpP --minimal linux-3.2.8/arch/sparc/Kconfig linux-3.2.8-vs2.3.2.7/arch/sparc/Kconfig
731 --- linux-3.2.8/arch/sparc/Kconfig      2012-01-09 16:14:07.000000000 +0100
732 +++ linux-3.2.8-vs2.3.2.7/arch/sparc/Kconfig    2011-12-05 19:33:02.000000000 +0100
733 @@ -595,6 +595,8 @@ source "fs/Kconfig"
734  
735  source "arch/sparc/Kconfig.debug"
736  
737 +source "kernel/vserver/Kconfig"
738 +
739  source "security/Kconfig"
740  
741  source "crypto/Kconfig"
742 diff -NurpP --minimal linux-3.2.8/arch/sparc/include/asm/unistd.h linux-3.2.8-vs2.3.2.7/arch/sparc/include/asm/unistd.h
743 --- linux-3.2.8/arch/sparc/include/asm/unistd.h 2012-01-09 16:14:07.000000000 +0100
744 +++ linux-3.2.8-vs2.3.2.7/arch/sparc/include/asm/unistd.h       2011-12-05 19:33:02.000000000 +0100
745 @@ -335,7 +335,7 @@
746  #define __NR_timer_getoverrun  264
747  #define __NR_timer_delete      265
748  #define __NR_timer_create      266
749 -/* #define __NR_vserver                267 Reserved for VSERVER */
750 +#define __NR_vserver           267
751  #define __NR_io_setup          268
752  #define __NR_io_destroy                269
753  #define __NR_io_submit         270
754 diff -NurpP --minimal linux-3.2.8/arch/sparc/kernel/systbls_32.S linux-3.2.8-vs2.3.2.7/arch/sparc/kernel/systbls_32.S
755 --- linux-3.2.8/arch/sparc/kernel/systbls_32.S  2012-01-09 16:14:09.000000000 +0100
756 +++ linux-3.2.8-vs2.3.2.7/arch/sparc/kernel/systbls_32.S        2011-12-05 19:33:02.000000000 +0100
757 @@ -70,7 +70,7 @@ sys_call_table:
758  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
759  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
760  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
761 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
762 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
763  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
764  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
765  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
766 diff -NurpP --minimal linux-3.2.8/arch/sparc/kernel/systbls_64.S linux-3.2.8-vs2.3.2.7/arch/sparc/kernel/systbls_64.S
767 --- linux-3.2.8/arch/sparc/kernel/systbls_64.S  2012-01-09 16:14:09.000000000 +0100
768 +++ linux-3.2.8-vs2.3.2.7/arch/sparc/kernel/systbls_64.S        2011-12-05 19:33:02.000000000 +0100
769 @@ -71,7 +71,7 @@ sys_call_table32:
770  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
771         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
772  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
773 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
774 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
775  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
776         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
777  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
778 @@ -148,7 +148,7 @@ sys_call_table:
779  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
780         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
781  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
782 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
783 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
784  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
785         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
786  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
787 diff -NurpP --minimal linux-3.2.8/arch/um/Kconfig.rest linux-3.2.8-vs2.3.2.7/arch/um/Kconfig.rest
788 --- linux-3.2.8/arch/um/Kconfig.rest    2012-01-09 16:14:09.000000000 +0100
789 +++ linux-3.2.8-vs2.3.2.7/arch/um/Kconfig.rest  2011-12-05 19:33:02.000000000 +0100
790 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
791  
792  source "fs/Kconfig"
793  
794 +source "kernel/vserver/Kconfig"
795 +
796  source "security/Kconfig"
797  
798  source "crypto/Kconfig"
799 diff -NurpP --minimal linux-3.2.8/arch/um/include/shared/kern_constants.h linux-3.2.8-vs2.3.2.7/arch/um/include/shared/kern_constants.h
800 --- linux-3.2.8/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
801 +++ linux-3.2.8-vs2.3.2.7/arch/um/include/shared/kern_constants.h       2011-12-05 19:33:02.000000000 +0100
802 @@ -0,0 +1 @@
803 +#include "../../../../include/generated/asm-offsets.h"
804 diff -NurpP --minimal linux-3.2.8/arch/um/include/shared/user_constants.h linux-3.2.8-vs2.3.2.7/arch/um/include/shared/user_constants.h
805 --- linux-3.2.8/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
806 +++ linux-3.2.8-vs2.3.2.7/arch/um/include/shared/user_constants.h       2011-12-05 19:33:02.000000000 +0100
807 @@ -0,0 +1,40 @@
808 +/*
809 + * DO NOT MODIFY.
810 + *
811 + * This file was generated by arch/um/Makefile
812 + *
813 + */
814 +
815 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
816 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
817 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
818 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
819 +#define HOST_RBX 5 /* RBX      # */
820 +#define HOST_RCX 11 /* RCX     # */
821 +#define HOST_RDI 14 /* RDI     # */
822 +#define HOST_RSI 13 /* RSI     # */
823 +#define HOST_RDX 12 /* RDX     # */
824 +#define HOST_RBP 4 /* RBP      # */
825 +#define HOST_RAX 10 /* RAX     # */
826 +#define HOST_R8 9 /* R8        # */
827 +#define HOST_R9 8 /* R9        # */
828 +#define HOST_R10 7 /* R10      # */
829 +#define HOST_R11 6 /* R11      # */
830 +#define HOST_R12 3 /* R12      # */
831 +#define HOST_R13 2 /* R13      # */
832 +#define HOST_R14 1 /* R14      # */
833 +#define HOST_R15 0 /* R15      # */
834 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
835 +#define HOST_CS 17 /* CS       # */
836 +#define HOST_SS 20 /* SS       # */
837 +#define HOST_EFLAGS 18 /* EFLAGS       # */
838 +#define HOST_IP 16 /* RIP      # */
839 +#define HOST_SP 19 /* RSP      # */
840 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
841 +#define UM_POLLIN 1 /* POLLIN  # */
842 +#define UM_POLLPRI 2 /* POLLPRI        # */
843 +#define UM_POLLOUT 4 /* POLLOUT        # */
844 +#define UM_PROT_READ 1 /* PROT_READ    # */
845 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
846 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
847 +
848 diff -NurpP --minimal linux-3.2.8/arch/x86/Kconfig linux-3.2.8-vs2.3.2.7/arch/x86/Kconfig
849 --- linux-3.2.8/arch/x86/Kconfig        2012-01-09 16:14:10.000000000 +0100
850 +++ linux-3.2.8-vs2.3.2.7/arch/x86/Kconfig      2011-12-15 01:11:29.000000000 +0100
851 @@ -2170,6 +2170,8 @@ source "fs/Kconfig"
852  
853  source "arch/x86/Kconfig.debug"
854  
855 +source "kernel/vserver/Kconfig"
856 +
857  source "security/Kconfig"
858  
859  source "crypto/Kconfig"
860 diff -NurpP --minimal linux-3.2.8/arch/x86/ia32/ia32entry.S linux-3.2.8-vs2.3.2.7/arch/x86/ia32/ia32entry.S
861 --- linux-3.2.8/arch/x86/ia32/ia32entry.S       2012-01-09 16:14:10.000000000 +0100
862 +++ linux-3.2.8-vs2.3.2.7/arch/x86/ia32/ia32entry.S     2011-12-05 19:33:02.000000000 +0100
863 @@ -776,7 +776,7 @@ ia32_sys_call_table:
864         .quad sys_tgkill                /* 270 */
865         .quad compat_sys_utimes
866         .quad sys32_fadvise64_64
867 -       .quad quiet_ni_syscall  /* sys_vserver */
868 +       .quad sys32_vserver
869         .quad sys_mbind
870         .quad compat_sys_get_mempolicy  /* 275 */
871         .quad sys_set_mempolicy
872 diff -NurpP --minimal linux-3.2.8/arch/x86/include/asm/unistd_64.h linux-3.2.8-vs2.3.2.7/arch/x86/include/asm/unistd_64.h
873 --- linux-3.2.8/arch/x86/include/asm/unistd_64.h        2012-01-09 16:14:11.000000000 +0100
874 +++ linux-3.2.8-vs2.3.2.7/arch/x86/include/asm/unistd_64.h      2011-12-05 19:33:02.000000000 +0100
875 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
876  #define __NR_utimes                            235
877  __SYSCALL(__NR_utimes, sys_utimes)
878  #define __NR_vserver                           236
879 -__SYSCALL(__NR_vserver, sys_ni_syscall)
880 +__SYSCALL(__NR_vserver, sys_vserver)
881  #define __NR_mbind                             237
882  __SYSCALL(__NR_mbind, sys_mbind)
883  #define __NR_set_mempolicy                     238
884 diff -NurpP --minimal linux-3.2.8/arch/x86/kernel/syscall_table_32.S linux-3.2.8-vs2.3.2.7/arch/x86/kernel/syscall_table_32.S
885 --- linux-3.2.8/arch/x86/kernel/syscall_table_32.S      2012-01-09 16:14:11.000000000 +0100
886 +++ linux-3.2.8-vs2.3.2.7/arch/x86/kernel/syscall_table_32.S    2011-12-05 19:33:02.000000000 +0100
887 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
888         .long sys_tgkill        /* 270 */
889         .long sys_utimes
890         .long sys_fadvise64_64
891 -       .long sys_ni_syscall    /* sys_vserver */
892 +       .long sys_vserver
893         .long sys_mbind
894         .long sys_get_mempolicy
895         .long sys_set_mempolicy
896 diff -NurpP --minimal linux-3.2.8/drivers/block/Kconfig linux-3.2.8-vs2.3.2.7/drivers/block/Kconfig
897 --- linux-3.2.8/drivers/block/Kconfig   2011-10-24 18:45:08.000000000 +0200
898 +++ linux-3.2.8-vs2.3.2.7/drivers/block/Kconfig 2011-12-05 19:33:02.000000000 +0100
899 @@ -288,6 +288,13 @@ config BLK_DEV_CRYPTOLOOP
900  
901  source "drivers/block/drbd/Kconfig"
902  
903 +config BLK_DEV_VROOT
904 +       tristate "Virtual Root device support"
905 +       depends on QUOTACTL
906 +       ---help---
907 +         Saying Y here will allow you to use quota/fs ioctls on a shared
908 +         partition within a virtual server without compromising security.
909 +
910  config BLK_DEV_NBD
911         tristate "Network block device support"
912         depends on NET
913 diff -NurpP --minimal linux-3.2.8/drivers/block/Makefile linux-3.2.8-vs2.3.2.7/drivers/block/Makefile
914 --- linux-3.2.8/drivers/block/Makefile  2011-07-22 11:17:44.000000000 +0200
915 +++ linux-3.2.8-vs2.3.2.7/drivers/block/Makefile        2011-12-05 19:33:02.000000000 +0100
916 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
917  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
918  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
919  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
920 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
921  
922  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
923  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
924 diff -NurpP --minimal linux-3.2.8/drivers/block/loop.c linux-3.2.8-vs2.3.2.7/drivers/block/loop.c
925 --- linux-3.2.8/drivers/block/loop.c    2012-01-09 16:14:15.000000000 +0100
926 +++ linux-3.2.8-vs2.3.2.7/drivers/block/loop.c  2012-01-09 16:19:31.000000000 +0100
927 @@ -77,6 +77,7 @@
928  #include <linux/sysfs.h>
929  #include <linux/miscdevice.h>
930  #include <linux/falloc.h>
931 +#include <linux/vs_context.h>
932  
933  #include <asm/uaccess.h>
934  
935 @@ -868,6 +869,7 @@ static int loop_set_fd(struct loop_devic
936         lo->lo_blocksize = lo_blocksize;
937         lo->lo_device = bdev;
938         lo->lo_flags = lo_flags;
939 +       lo->lo_xid = vx_current_xid();
940         lo->lo_backing_file = file;
941         lo->transfer = transfer_none;
942         lo->ioctl = NULL;
943 @@ -1000,6 +1002,7 @@ static int loop_clr_fd(struct loop_devic
944         lo->lo_sizelimit = 0;
945         lo->lo_encrypt_key_size = 0;
946         lo->lo_thread = NULL;
947 +       lo->lo_xid = 0;
948         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
949         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
950         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
951 @@ -1041,7 +1044,7 @@ loop_set_status(struct loop_device *lo, 
952  
953         if (lo->lo_encrypt_key_size &&
954             lo->lo_key_owner != uid &&
955 -           !capable(CAP_SYS_ADMIN))
956 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
957                 return -EPERM;
958         if (lo->lo_state != Lo_bound)
959                 return -ENXIO;
960 @@ -1131,7 +1134,8 @@ loop_get_status(struct loop_device *lo, 
961         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
962         info->lo_encrypt_type =
963                 lo->lo_encryption ? lo->lo_encryption->number : 0;
964 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
965 +       if (lo->lo_encrypt_key_size &&
966 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
967                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
968                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
969                        lo->lo_encrypt_key_size);
970 @@ -1491,6 +1495,11 @@ static int lo_open(struct block_device *
971                 goto out;
972         }
973  
974 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
975 +               err = -EACCES;
976 +               goto out;
977 +       }
978 +
979         mutex_lock(&lo->lo_ctl_mutex);
980         lo->lo_refcnt++;
981         mutex_unlock(&lo->lo_ctl_mutex);
982 diff -NurpP --minimal linux-3.2.8/drivers/block/vroot.c linux-3.2.8-vs2.3.2.7/drivers/block/vroot.c
983 --- linux-3.2.8/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
984 +++ linux-3.2.8-vs2.3.2.7/drivers/block/vroot.c 2011-12-07 00:05:16.000000000 +0100
985 @@ -0,0 +1,291 @@
986 +/*
987 + *  linux/drivers/block/vroot.c
988 + *
989 + *  written by Herbert Pötzl, 9/11/2002
990 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
991 + *
992 + *  based on the loop.c code by Theodore Ts'o.
993 + *
994 + * Copyright (C) 2002-2007 by Herbert Pötzl.
995 + * Redistribution of this file is permitted under the
996 + * GNU General Public License.
997 + *
998 + */
999 +
1000 +#include <linux/module.h>
1001 +#include <linux/moduleparam.h>
1002 +#include <linux/file.h>
1003 +#include <linux/major.h>
1004 +#include <linux/blkdev.h>
1005 +#include <linux/slab.h>
1006 +
1007 +#include <linux/vroot.h>
1008 +#include <linux/vs_context.h>
1009 +
1010 +
1011 +static int max_vroot = 8;
1012 +
1013 +static struct vroot_device *vroot_dev;
1014 +static struct gendisk **disks;
1015 +
1016 +
1017 +static int vroot_set_dev(
1018 +       struct vroot_device *vr,
1019 +       struct block_device *bdev,
1020 +       unsigned int arg)
1021 +{
1022 +       struct block_device *real_bdev;
1023 +       struct file *file;
1024 +       struct inode *inode;
1025 +       int error;
1026 +
1027 +       error = -EBUSY;
1028 +       if (vr->vr_state != Vr_unbound)
1029 +               goto out;
1030 +
1031 +       error = -EBADF;
1032 +       file = fget(arg);
1033 +       if (!file)
1034 +               goto out;
1035 +
1036 +       error = -EINVAL;
1037 +       inode = file->f_dentry->d_inode;
1038 +
1039 +
1040 +       if (S_ISBLK(inode->i_mode)) {
1041 +               real_bdev = inode->i_bdev;
1042 +               vr->vr_device = real_bdev;
1043 +               __iget(real_bdev->bd_inode);
1044 +       } else
1045 +               goto out_fput;
1046 +
1047 +       vxdprintk(VXD_CBIT(misc, 0),
1048 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1049 +               vr->vr_number, VXD_DEV(real_bdev));
1050 +
1051 +       vr->vr_state = Vr_bound;
1052 +       error = 0;
1053 +
1054 + out_fput:
1055 +       fput(file);
1056 + out:
1057 +       return error;
1058 +}
1059 +
1060 +static int vroot_clr_dev(
1061 +       struct vroot_device *vr,
1062 +       struct block_device *bdev)
1063 +{
1064 +       struct block_device *real_bdev;
1065 +
1066 +       if (vr->vr_state != Vr_bound)
1067 +               return -ENXIO;
1068 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1069 +               return -EBUSY;
1070 +
1071 +       real_bdev = vr->vr_device;
1072 +
1073 +       vxdprintk(VXD_CBIT(misc, 0),
1074 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1075 +               vr->vr_number, VXD_DEV(real_bdev));
1076 +
1077 +       bdput(real_bdev);
1078 +       vr->vr_state = Vr_unbound;
1079 +       vr->vr_device = NULL;
1080 +       return 0;
1081 +}
1082 +
1083 +
1084 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1085 +       unsigned int cmd, unsigned long arg)
1086 +{
1087 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1088 +       int err;
1089 +
1090 +       down(&vr->vr_ctl_mutex);
1091 +       switch (cmd) {
1092 +       case VROOT_SET_DEV:
1093 +               err = vroot_set_dev(vr, bdev, arg);
1094 +               break;
1095 +       case VROOT_CLR_DEV:
1096 +               err = vroot_clr_dev(vr, bdev);
1097 +               break;
1098 +       default:
1099 +               err = -EINVAL;
1100 +               break;
1101 +       }
1102 +       up(&vr->vr_ctl_mutex);
1103 +       return err;
1104 +}
1105 +
1106 +static int vr_open(struct block_device *bdev, fmode_t mode)
1107 +{
1108 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1109 +
1110 +       down(&vr->vr_ctl_mutex);
1111 +       vr->vr_refcnt++;
1112 +       up(&vr->vr_ctl_mutex);
1113 +       return 0;
1114 +}
1115 +
1116 +static int vr_release(struct gendisk *disk, fmode_t mode)
1117 +{
1118 +       struct vroot_device *vr = disk->private_data;
1119 +
1120 +       down(&vr->vr_ctl_mutex);
1121 +       --vr->vr_refcnt;
1122 +       up(&vr->vr_ctl_mutex);
1123 +       return 0;
1124 +}
1125 +
1126 +static struct block_device_operations vr_fops = {
1127 +       .owner =        THIS_MODULE,
1128 +       .open =         vr_open,
1129 +       .release =      vr_release,
1130 +       .ioctl =        vr_ioctl,
1131 +};
1132 +
1133 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1134 +{
1135 +       printk("vroot_make_request %p, %p\n", q, bio);
1136 +       bio_io_error(bio);
1137 +}
1138 +
1139 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1140 +{
1141 +       struct inode *inode = bdev->bd_inode;
1142 +       struct vroot_device *vr;
1143 +       struct block_device *real_bdev;
1144 +       int minor = iminor(inode);
1145 +
1146 +       vr = &vroot_dev[minor];
1147 +       real_bdev = vr->vr_device;
1148 +
1149 +       vxdprintk(VXD_CBIT(misc, 0),
1150 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1151 +               vr->vr_number, VXD_DEV(real_bdev));
1152 +
1153 +       if (vr->vr_state != Vr_bound)
1154 +               return ERR_PTR(-ENXIO);
1155 +
1156 +       __iget(real_bdev->bd_inode);
1157 +       return real_bdev;
1158 +}
1159 +
1160 +
1161 +
1162 +/*
1163 + * And now the modules code and kernel interface.
1164 + */
1165 +
1166 +module_param(max_vroot, int, 0);
1167 +
1168 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1169 +MODULE_LICENSE("GPL");
1170 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1171 +
1172 +MODULE_AUTHOR ("Herbert Pötzl");
1173 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1174 +
1175 +
1176 +int __init vroot_init(void)
1177 +{
1178 +       int err, i;
1179 +
1180 +       if (max_vroot < 1 || max_vroot > 256) {
1181 +               max_vroot = MAX_VROOT_DEFAULT;
1182 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1183 +                       "(must be between 1 and 256), "
1184 +                       "using default (%d)\n", max_vroot);
1185 +       }
1186 +
1187 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1188 +               return -EIO;
1189 +
1190 +       err = -ENOMEM;
1191 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1192 +       if (!vroot_dev)
1193 +               goto out_mem1;
1194 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1195 +
1196 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1197 +       if (!disks)
1198 +               goto out_mem2;
1199 +
1200 +       for (i = 0; i < max_vroot; i++) {
1201 +               disks[i] = alloc_disk(1);
1202 +               if (!disks[i])
1203 +                       goto out_mem3;
1204 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1205 +               if (!disks[i]->queue)
1206 +                       goto out_mem3;
1207 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1208 +       }
1209 +
1210 +       for (i = 0; i < max_vroot; i++) {
1211 +               struct vroot_device *vr = &vroot_dev[i];
1212 +               struct gendisk *disk = disks[i];
1213 +
1214 +               memset(vr, 0, sizeof(*vr));
1215 +               sema_init(&vr->vr_ctl_mutex, 1);
1216 +               vr->vr_number = i;
1217 +               disk->major = VROOT_MAJOR;
1218 +               disk->first_minor = i;
1219 +               disk->fops = &vr_fops;
1220 +               sprintf(disk->disk_name, "vroot%d", i);
1221 +               disk->private_data = vr;
1222 +       }
1223 +
1224 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1225 +       if (err)
1226 +               goto out_mem3;
1227 +
1228 +       for (i = 0; i < max_vroot; i++)
1229 +               add_disk(disks[i]);
1230 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1231 +       return 0;
1232 +
1233 +out_mem3:
1234 +       while (i--)
1235 +               put_disk(disks[i]);
1236 +       kfree(disks);
1237 +out_mem2:
1238 +       kfree(vroot_dev);
1239 +out_mem1:
1240 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1241 +       printk(KERN_ERR "vroot: ran out of memory\n");
1242 +       return err;
1243 +}
1244 +
1245 +void vroot_exit(void)
1246 +{
1247 +       int i;
1248 +
1249 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1250 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1251 +
1252 +       for (i = 0; i < max_vroot; i++) {
1253 +               del_gendisk(disks[i]);
1254 +               put_disk(disks[i]);
1255 +       }
1256 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1257 +
1258 +       kfree(disks);
1259 +       kfree(vroot_dev);
1260 +}
1261 +
1262 +module_init(vroot_init);
1263 +module_exit(vroot_exit);
1264 +
1265 +#ifndef MODULE
1266 +
1267 +static int __init max_vroot_setup(char *str)
1268 +{
1269 +       max_vroot = simple_strtol(str, NULL, 0);
1270 +       return 1;
1271 +}
1272 +
1273 +__setup("max_vroot=", max_vroot_setup);
1274 +
1275 +#endif
1276 +
1277 diff -NurpP --minimal linux-3.2.8/drivers/infiniband/Kconfig linux-3.2.8-vs2.3.2.7/drivers/infiniband/Kconfig
1278 --- linux-3.2.8/drivers/infiniband/Kconfig      2011-07-22 11:17:45.000000000 +0200
1279 +++ linux-3.2.8-vs2.3.2.7/drivers/infiniband/Kconfig    2012-02-15 03:26:22.000000000 +0100
1280 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1281  config INFINIBAND_ADDR_TRANS
1282         bool
1283         depends on INET
1284 -       depends on !(INFINIBAND = y && IPV6 = m)
1285 +       depends on !(INFINIBAND = y && IPV6 = y)
1286         default y
1287  
1288  source "drivers/infiniband/hw/mthca/Kconfig"
1289 diff -NurpP --minimal linux-3.2.8/drivers/infiniband/core/addr.c linux-3.2.8-vs2.3.2.7/drivers/infiniband/core/addr.c
1290 --- linux-3.2.8/drivers/infiniband/core/addr.c  2012-01-09 16:14:19.000000000 +0100
1291 +++ linux-3.2.8-vs2.3.2.7/drivers/infiniband/core/addr.c        2011-12-05 19:33:02.000000000 +0100
1292 @@ -255,7 +255,7 @@ static int addr6_resolve(struct sockaddr
1293  
1294         if (ipv6_addr_any(&fl6.saddr)) {
1295                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1296 -                                        &fl6.daddr, 0, &fl6.saddr);
1297 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1298                 if (ret)
1299                         goto put;
1300  
1301 diff -NurpP --minimal linux-3.2.8/drivers/md/dm-ioctl.c linux-3.2.8-vs2.3.2.7/drivers/md/dm-ioctl.c
1302 --- linux-3.2.8/drivers/md/dm-ioctl.c   2012-01-09 16:14:20.000000000 +0100
1303 +++ linux-3.2.8-vs2.3.2.7/drivers/md/dm-ioctl.c 2011-12-05 19:33:02.000000000 +0100
1304 @@ -16,6 +16,7 @@
1305  #include <linux/dm-ioctl.h>
1306  #include <linux/hdreg.h>
1307  #include <linux/compat.h>
1308 +#include <linux/vs_context.h>
1309  
1310  #include <asm/uaccess.h>
1311  
1312 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1313         unsigned int h = hash_str(str);
1314  
1315         list_for_each_entry (hc, _name_buckets + h, name_list)
1316 -               if (!strcmp(hc->name, str)) {
1317 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1318 +                       !strcmp(hc->name, str)) {
1319                         dm_get(hc->md);
1320                         return hc;
1321                 }
1322 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1323         unsigned int h = hash_str(str);
1324  
1325         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1326 -               if (!strcmp(hc->uuid, str)) {
1327 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1328 +                       !strcmp(hc->uuid, str)) {
1329                         dm_get(hc->md);
1330                         return hc;
1331                 }
1332 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1333  static struct hash_cell *__get_dev_cell(uint64_t dev)
1334  {
1335         struct mapped_device *md;
1336 -       struct hash_cell *hc;
1337 +       struct hash_cell *hc = NULL;
1338  
1339         md = dm_get_md(huge_decode_dev(dev));
1340         if (!md)
1341                 return NULL;
1342  
1343 -       hc = dm_get_mdptr(md);
1344 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1345 +               hc = dm_get_mdptr(md);
1346 +
1347         if (!hc) {
1348                 dm_put(md);
1349                 return NULL;
1350 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1351  
1352  static int remove_all(struct dm_ioctl *param, size_t param_size)
1353  {
1354 +       if (!vx_check(0, VS_ADMIN))
1355 +               return -EPERM;
1356 +
1357         dm_hash_remove_all(1);
1358         param->data_size = 0;
1359         return 0;
1360 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl 
1361          */
1362         for (i = 0; i < NUM_BUCKETS; i++) {
1363                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1364 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1365 +                               continue;
1366                         needed += sizeof(struct dm_name_list);
1367                         needed += strlen(hc->name) + 1;
1368                         needed += ALIGN_MASK;
1369 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl 
1370          */
1371         for (i = 0; i < NUM_BUCKETS; i++) {
1372                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1373 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1374 +                               continue;
1375                         if (old_nl)
1376                                 old_nl->next = (uint32_t) ((void *) nl -
1377                                                            (void *) old_nl);
1378 @@ -1615,8 +1627,8 @@ static int ctl_ioctl(uint command, struc
1379         ioctl_fn fn = NULL;
1380         size_t input_param_size;
1381  
1382 -       /* only root can play with this */
1383 -       if (!capable(CAP_SYS_ADMIN))
1384 +       /* only root and certain contexts can play with this */
1385 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1386                 return -EACCES;
1387  
1388         if (_IOC_TYPE(command) != DM_IOCTL)
1389 diff -NurpP --minimal linux-3.2.8/drivers/md/dm.c linux-3.2.8-vs2.3.2.7/drivers/md/dm.c
1390 --- linux-3.2.8/drivers/md/dm.c 2012-01-09 16:14:21.000000000 +0100
1391 +++ linux-3.2.8-vs2.3.2.7/drivers/md/dm.c       2011-12-05 19:33:02.000000000 +0100
1392 @@ -20,6 +20,7 @@
1393  #include <linux/idr.h>
1394  #include <linux/hdreg.h>
1395  #include <linux/delay.h>
1396 +#include <linux/vs_base.h>
1397  
1398  #include <trace/events/block.h>
1399  
1400 @@ -132,6 +133,7 @@ struct mapped_device {
1401         rwlock_t map_lock;
1402         atomic_t holders;
1403         atomic_t open_count;
1404 +       xid_t xid;
1405  
1406         unsigned long flags;
1407  
1408 @@ -344,6 +346,7 @@ int dm_deleting_md(struct mapped_device 
1409  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1410  {
1411         struct mapped_device *md;
1412 +       int ret = -ENXIO;
1413  
1414         spin_lock(&_minor_lock);
1415  
1416 @@ -352,18 +355,19 @@ static int dm_blk_open(struct block_devi
1417                 goto out;
1418  
1419         if (test_bit(DMF_FREEING, &md->flags) ||
1420 -           dm_deleting_md(md)) {
1421 -               md = NULL;
1422 +           dm_deleting_md(md))
1423 +               goto out;
1424 +
1425 +       ret = -EACCES;
1426 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1427                 goto out;
1428 -       }
1429  
1430         dm_get(md);
1431         atomic_inc(&md->open_count);
1432 -
1433 +       ret = 0;
1434  out:
1435         spin_unlock(&_minor_lock);
1436 -
1437 -       return md ? 0 : -ENXIO;
1438 +       return ret;
1439  }
1440  
1441  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1442 @@ -584,6 +588,14 @@ int dm_set_geometry(struct mapped_device
1443         return 0;
1444  }
1445  
1446 +/*
1447 + * Get the xid associated with a dm device
1448 + */
1449 +xid_t dm_get_xid(struct mapped_device *md)
1450 +{
1451 +       return md->xid;
1452 +}
1453 +
1454  /*-----------------------------------------------------------------
1455   * CRUD START:
1456   *   A more elegant soln is in the works that uses the queue
1457 @@ -1850,6 +1862,7 @@ static struct mapped_device *alloc_dev(i
1458         INIT_LIST_HEAD(&md->uevent_list);
1459         spin_lock_init(&md->uevent_lock);
1460  
1461 +       md->xid = vx_current_xid();
1462         md->queue = blk_alloc_queue(GFP_KERNEL);
1463         if (!md->queue)
1464                 goto bad_queue;
1465 diff -NurpP --minimal linux-3.2.8/drivers/md/dm.h linux-3.2.8-vs2.3.2.7/drivers/md/dm.h
1466 --- linux-3.2.8/drivers/md/dm.h 2012-01-09 16:14:21.000000000 +0100
1467 +++ linux-3.2.8-vs2.3.2.7/drivers/md/dm.h       2011-12-05 19:33:02.000000000 +0100
1468 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1469  struct dm_table;
1470  struct dm_md_mempools;
1471  
1472 +xid_t dm_get_xid(struct mapped_device *md);
1473 +
1474  /*-----------------------------------------------------------------
1475   * Internal table functions.
1476   *---------------------------------------------------------------*/
1477 diff -NurpP --minimal linux-3.2.8/drivers/net/tun.c linux-3.2.8-vs2.3.2.7/drivers/net/tun.c
1478 --- linux-3.2.8/drivers/net/tun.c       2012-01-09 16:14:35.000000000 +0100
1479 +++ linux-3.2.8-vs2.3.2.7/drivers/net/tun.c     2011-12-05 19:33:02.000000000 +0100
1480 @@ -64,6 +64,7 @@
1481  #include <linux/nsproxy.h>
1482  #include <linux/virtio_net.h>
1483  #include <linux/rcupdate.h>
1484 +#include <linux/vs_network.h>
1485  #include <net/net_namespace.h>
1486  #include <net/netns/generic.h>
1487  #include <net/rtnetlink.h>
1488 @@ -121,6 +122,7 @@ struct tun_struct {
1489         unsigned int            flags;
1490         uid_t                   owner;
1491         gid_t                   group;
1492 +       nid_t                   nid;
1493  
1494         struct net_device       *dev;
1495         u32                     set_features;
1496 @@ -909,6 +911,7 @@ static void tun_setup(struct net_device 
1497  
1498         tun->owner = -1;
1499         tun->group = -1;
1500 +       tun->nid = current->nid;
1501  
1502         dev->ethtool_ops = &tun_ethtool_ops;
1503         dev->destructor = tun_free_netdev;
1504 @@ -1059,7 +1062,7 @@ static int tun_set_iff(struct net *net, 
1505  
1506                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1507                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1508 -                   !capable(CAP_NET_ADMIN))
1509 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1510                         return -EPERM;
1511                 err = security_tun_dev_attach(tun->socket.sk);
1512                 if (err < 0)
1513 @@ -1073,7 +1076,7 @@ static int tun_set_iff(struct net *net, 
1514                 char *name;
1515                 unsigned long flags = 0;
1516  
1517 -               if (!capable(CAP_NET_ADMIN))
1518 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1519                         return -EPERM;
1520                 err = security_tun_dev_create();
1521                 if (err < 0)
1522 @@ -1141,6 +1144,9 @@ static int tun_set_iff(struct net *net, 
1523  
1524                 sk->sk_destruct = tun_sock_destruct;
1525  
1526 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1527 +                       return -EPERM;
1528 +
1529                 err = tun_attach(tun, file);
1530                 if (err < 0)
1531                         goto failed;
1532 @@ -1322,6 +1328,16 @@ static long __tun_chr_ioctl(struct file 
1533                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1534                 break;
1535  
1536 +       case TUNSETNID:
1537 +               if (!capable(CAP_CONTEXT))
1538 +                       return -EPERM;
1539 +
1540 +               /* Set nid owner of the device */
1541 +               tun->nid = (nid_t) arg;
1542 +
1543 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1544 +               break;
1545 +
1546         case TUNSETLINK:
1547                 /* Only allow setting the type when the interface is down */
1548                 if (tun->dev->flags & IFF_UP) {
1549 diff -NurpP --minimal linux-3.2.8/drivers/tty/sysrq.c linux-3.2.8-vs2.3.2.7/drivers/tty/sysrq.c
1550 --- linux-3.2.8/drivers/tty/sysrq.c     2011-05-22 16:17:44.000000000 +0200
1551 +++ linux-3.2.8-vs2.3.2.7/drivers/tty/sysrq.c   2011-12-05 19:33:02.000000000 +0100
1552 @@ -41,6 +41,7 @@
1553  #include <linux/oom.h>
1554  #include <linux/slab.h>
1555  #include <linux/input.h>
1556 +#include <linux/vserver/debug.h>
1557  
1558  #include <asm/ptrace.h>
1559  #include <asm/irq_regs.h>
1560 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1561         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1562  };
1563  
1564 +
1565 +#ifdef CONFIG_VSERVER_DEBUG
1566 +static void sysrq_handle_vxinfo(int key)
1567 +{
1568 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1569 +}
1570 +
1571 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1572 +       .handler        = sysrq_handle_vxinfo,
1573 +       .help_msg       = "conteXt",
1574 +       .action_msg     = "Show Context Info",
1575 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1576 +};
1577 +#endif
1578 +
1579  /* Key Operations table and lock */
1580  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1581  
1582 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1583         NULL,                           /* v */
1584         &sysrq_showstate_blocked_op,    /* w */
1585         /* x: May be registered on ppc/powerpc for xmon */
1586 +#ifdef CONFIG_VSERVER_DEBUG
1587 +       &sysrq_showvxinfo_op,           /* x */
1588 +#else
1589         NULL,                           /* x */
1590 +#endif
1591         /* y: May be registered on sparc64 for global register dump */
1592         NULL,                           /* y */
1593         &sysrq_ftrace_dump_op,          /* z */
1594 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
1595                 retval = key - '0';
1596         else if ((key >= 'a') && (key <= 'z'))
1597                 retval = key + 10 - 'a';
1598 +       else if ((key >= 'A') && (key <= 'Z'))
1599 +               retval = key + 10 - 'A';
1600         else
1601                 retval = -1;
1602         return retval;
1603 diff -NurpP --minimal linux-3.2.8/drivers/tty/tty_io.c linux-3.2.8-vs2.3.2.7/drivers/tty/tty_io.c
1604 --- linux-3.2.8/drivers/tty/tty_io.c    2012-01-09 16:14:48.000000000 +0100
1605 +++ linux-3.2.8-vs2.3.2.7/drivers/tty/tty_io.c  2011-12-05 19:33:02.000000000 +0100
1606 @@ -105,6 +105,7 @@
1607  
1608  #include <linux/kmod.h>
1609  #include <linux/nsproxy.h>
1610 +#include <linux/vs_pid.h>
1611  
1612  #undef TTY_DEBUG_HANGUP
1613  
1614 @@ -2080,7 +2081,8 @@ static int tiocsti(struct tty_struct *tt
1615         char ch, mbz = 0;
1616         struct tty_ldisc *ld;
1617  
1618 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1619 +       if (((current->signal->tty != tty) &&
1620 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1621                 return -EPERM;
1622         if (get_user(ch, p))
1623                 return -EFAULT;
1624 @@ -2368,6 +2370,7 @@ static int tiocspgrp(struct tty_struct *
1625                 return -ENOTTY;
1626         if (get_user(pgrp_nr, p))
1627                 return -EFAULT;
1628 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1629         if (pgrp_nr < 0)
1630                 return -EINVAL;
1631         rcu_read_lock();
1632 diff -NurpP --minimal linux-3.2.8/fs/attr.c linux-3.2.8-vs2.3.2.7/fs/attr.c
1633 --- linux-3.2.8/fs/attr.c       2012-01-09 16:14:53.000000000 +0100
1634 +++ linux-3.2.8-vs2.3.2.7/fs/attr.c     2011-12-05 21:16:01.000000000 +0100
1635 @@ -14,6 +14,9 @@
1636  #include <linux/fcntl.h>
1637  #include <linux/security.h>
1638  #include <linux/evm.h>
1639 +#include <linux/proc_fs.h>
1640 +#include <linux/devpts_fs.h>
1641 +#include <linux/vs_tag.h>
1642  
1643  /**
1644   * inode_change_ok - check if attribute changes to an inode are allowed
1645 @@ -74,6 +77,10 @@ int inode_change_ok(const struct inode *
1646                         return -EPERM;
1647         }
1648  
1649 +       /* check for inode tag permission */
1650 +       if (dx_permission(inode, MAY_WRITE))
1651 +               return -EACCES;
1652 +
1653         return 0;
1654  }
1655  EXPORT_SYMBOL(inode_change_ok);
1656 @@ -144,6 +151,8 @@ void setattr_copy(struct inode *inode, c
1657                 inode->i_uid = attr->ia_uid;
1658         if (ia_valid & ATTR_GID)
1659                 inode->i_gid = attr->ia_gid;
1660 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1661 +               inode->i_tag = attr->ia_tag;
1662         if (ia_valid & ATTR_ATIME)
1663                 inode->i_atime = timespec_trunc(attr->ia_atime,
1664                                                 inode->i_sb->s_time_gran);
1665 @@ -171,7 +180,8 @@ int notify_change(struct dentry * dentry
1666         struct timespec now;
1667         unsigned int ia_valid = attr->ia_valid;
1668  
1669 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1670 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1671 +               ATTR_TAG | ATTR_TIMES_SET)) {
1672                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1673                         return -EPERM;
1674         }
1675 diff -NurpP --minimal linux-3.2.8/fs/block_dev.c linux-3.2.8-vs2.3.2.7/fs/block_dev.c
1676 --- linux-3.2.8/fs/block_dev.c  2012-01-09 16:14:53.000000000 +0100
1677 +++ linux-3.2.8-vs2.3.2.7/fs/block_dev.c        2011-12-05 19:33:02.000000000 +0100
1678 @@ -25,6 +25,7 @@
1679  #include <linux/namei.h>
1680  #include <linux/log2.h>
1681  #include <linux/kmemleak.h>
1682 +#include <linux/vs_device.h>
1683  #include <asm/uaccess.h>
1684  #include "internal.h"
1685  
1686 @@ -563,6 +564,7 @@ struct block_device *bdget(dev_t dev)
1687                 bdev->bd_invalidated = 0;
1688                 inode->i_mode = S_IFBLK;
1689                 inode->i_rdev = dev;
1690 +               inode->i_mdev = dev;
1691                 inode->i_bdev = bdev;
1692                 inode->i_data.a_ops = &def_blk_aops;
1693                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1694 @@ -609,6 +611,11 @@ EXPORT_SYMBOL(bdput);
1695  static struct block_device *bd_acquire(struct inode *inode)
1696  {
1697         struct block_device *bdev;
1698 +       dev_t mdev;
1699 +
1700 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1701 +               return NULL;
1702 +       inode->i_mdev = mdev;
1703  
1704         spin_lock(&bdev_lock);
1705         bdev = inode->i_bdev;
1706 @@ -619,7 +626,7 @@ static struct block_device *bd_acquire(s
1707         }
1708         spin_unlock(&bdev_lock);
1709  
1710 -       bdev = bdget(inode->i_rdev);
1711 +       bdev = bdget(mdev);
1712         if (bdev) {
1713                 spin_lock(&bdev_lock);
1714                 if (!inode->i_bdev) {
1715 diff -NurpP --minimal linux-3.2.8/fs/btrfs/ctree.h linux-3.2.8-vs2.3.2.7/fs/btrfs/ctree.h
1716 --- linux-3.2.8/fs/btrfs/ctree.h        2012-01-09 16:14:53.000000000 +0100
1717 +++ linux-3.2.8-vs2.3.2.7/fs/btrfs/ctree.h      2012-01-09 16:19:31.000000000 +0100
1718 @@ -643,11 +643,14 @@ struct btrfs_inode_item {
1719         /* modification sequence number for NFS */
1720         __le64 sequence;
1721  
1722 +       __le16 tag;
1723         /*
1724          * a little future expansion, for more than this we can
1725          * just grow the inode item and version it
1726          */
1727 -       __le64 reserved[4];
1728 +       __le16 reserved16;
1729 +       __le32 reserved32;
1730 +       __le64 reserved[3];
1731         struct btrfs_timespec atime;
1732         struct btrfs_timespec ctime;
1733         struct btrfs_timespec mtime;
1734 @@ -1414,6 +1417,8 @@ struct btrfs_ioctl_defrag_range_args {
1735  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
1736  #define BTRFS_MOUNT_RECOVERY           (1 << 18)
1737  
1738 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1739 +
1740  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1741  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1742  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1743 @@ -1621,6 +1626,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1744  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1745  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1746  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1747 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1748  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1749  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1750  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1751 @@ -1674,6 +1680,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1752  
1753  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1754  
1755 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1756 +#define BTRFS_INODE_BARRIER            (1 << 25)
1757 +#define BTRFS_INODE_COW                        (1 << 26)
1758 +
1759  
1760  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1761  
1762 @@ -2730,6 +2740,7 @@ extern const struct dentry_operations bt
1763  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1764  void btrfs_update_iflags(struct inode *inode);
1765  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1766 +int btrfs_sync_flags(struct inode *inode, int, int);
1767  int btrfs_defrag_file(struct inode *inode, struct file *file,
1768                       struct btrfs_ioctl_defrag_range_args *range,
1769                       u64 newer_than, unsigned long max_pages);
1770 diff -NurpP --minimal linux-3.2.8/fs/btrfs/disk-io.c linux-3.2.8-vs2.3.2.7/fs/btrfs/disk-io.c
1771 --- linux-3.2.8/fs/btrfs/disk-io.c      2012-01-09 16:14:53.000000000 +0100
1772 +++ linux-3.2.8-vs2.3.2.7/fs/btrfs/disk-io.c    2012-01-09 16:19:31.000000000 +0100
1773 @@ -2103,6 +2103,9 @@ struct btrfs_root *open_ctree(struct sup
1774                 goto fail_alloc;
1775         }
1776  
1777 +       if (btrfs_test_opt(tree_root, TAGGED))
1778 +               sb->s_flags |= MS_TAGGED;
1779 +
1780         features = btrfs_super_incompat_flags(disk_super) &
1781                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1782         if (features) {
1783 diff -NurpP --minimal linux-3.2.8/fs/btrfs/inode.c linux-3.2.8-vs2.3.2.7/fs/btrfs/inode.c
1784 --- linux-3.2.8/fs/btrfs/inode.c        2012-01-09 16:14:53.000000000 +0100
1785 +++ linux-3.2.8-vs2.3.2.7/fs/btrfs/inode.c      2012-01-09 16:19:51.000000000 +0100
1786 @@ -39,6 +39,7 @@
1787  #include <linux/slab.h>
1788  #include <linux/ratelimit.h>
1789  #include <linux/mount.h>
1790 +#include <linux/vs_tag.h>
1791  #include "compat.h"
1792  #include "ctree.h"
1793  #include "disk-io.h"
1794 @@ -2332,6 +2333,8 @@ static void btrfs_read_locked_inode(stru
1795         struct btrfs_key location;
1796         int maybe_acls;
1797         u32 rdev;
1798 +       uid_t uid;
1799 +       gid_t gid;
1800         int ret;
1801         bool filled = false;
1802  
1803 @@ -2359,8 +2362,13 @@ static void btrfs_read_locked_inode(stru
1804                                     struct btrfs_inode_item);
1805         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1806         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1807 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1808 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1809 +
1810 +       uid = btrfs_inode_uid(leaf, inode_item);
1811 +       gid = btrfs_inode_gid(leaf, inode_item);
1812 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1813 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1814 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1815 +               btrfs_inode_tag(leaf, inode_item));
1816         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1817  
1818         tspec = btrfs_inode_atime(inode_item);
1819 @@ -2438,8 +2446,14 @@ static void fill_inode_item(struct btrfs
1820                             struct btrfs_inode_item *item,
1821                             struct inode *inode)
1822  {
1823 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1824 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1825 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1826 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1827 +
1828 +       btrfs_set_inode_uid(leaf, item, uid);
1829 +       btrfs_set_inode_gid(leaf, item, gid);
1830 +#ifdef CONFIG_TAGGING_INTERN
1831 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1832 +#endif
1833         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1834         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1835         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1836 @@ -7377,11 +7391,13 @@ static const struct inode_operations btr
1837         .listxattr      = btrfs_listxattr,
1838         .removexattr    = btrfs_removexattr,
1839         .permission     = btrfs_permission,
1840 +       .sync_flags     = btrfs_sync_flags,
1841         .get_acl        = btrfs_get_acl,
1842  };
1843  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1844         .lookup         = btrfs_lookup,
1845         .permission     = btrfs_permission,
1846 +       .sync_flags     = btrfs_sync_flags,
1847         .get_acl        = btrfs_get_acl,
1848  };
1849  
1850 diff -NurpP --minimal linux-3.2.8/fs/btrfs/ioctl.c linux-3.2.8-vs2.3.2.7/fs/btrfs/ioctl.c
1851 --- linux-3.2.8/fs/btrfs/ioctl.c        2012-01-09 16:14:53.000000000 +0100
1852 +++ linux-3.2.8-vs2.3.2.7/fs/btrfs/ioctl.c      2012-01-09 16:19:31.000000000 +0100
1853 @@ -71,10 +71,13 @@ static unsigned int btrfs_flags_to_ioctl
1854  {
1855         unsigned int iflags = 0;
1856  
1857 -       if (flags & BTRFS_INODE_SYNC)
1858 -               iflags |= FS_SYNC_FL;
1859         if (flags & BTRFS_INODE_IMMUTABLE)
1860                 iflags |= FS_IMMUTABLE_FL;
1861 +       if (flags & BTRFS_INODE_IXUNLINK)
1862 +               iflags |= FS_IXUNLINK_FL;
1863 +
1864 +       if (flags & BTRFS_INODE_SYNC)
1865 +               iflags |= FS_SYNC_FL;
1866         if (flags & BTRFS_INODE_APPEND)
1867                 iflags |= FS_APPEND_FL;
1868         if (flags & BTRFS_INODE_NODUMP)
1869 @@ -91,28 +94,78 @@ static unsigned int btrfs_flags_to_ioctl
1870         else if (flags & BTRFS_INODE_NOCOMPRESS)
1871                 iflags |= FS_NOCOMP_FL;
1872  
1873 +       if (flags & BTRFS_INODE_BARRIER)
1874 +               iflags |= FS_BARRIER_FL;
1875 +       if (flags & BTRFS_INODE_COW)
1876 +               iflags |= FS_COW_FL;
1877         return iflags;
1878  }
1879  
1880  /*
1881 - * Update inode->i_flags based on the btrfs internal flags.
1882 + * Update inode->i_(v)flags based on the btrfs internal flags.
1883   */
1884  void btrfs_update_iflags(struct inode *inode)
1885  {
1886         struct btrfs_inode *ip = BTRFS_I(inode);
1887  
1888 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1889 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1890 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1891  
1892 -       if (ip->flags & BTRFS_INODE_SYNC)
1893 -               inode->i_flags |= S_SYNC;
1894         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1895                 inode->i_flags |= S_IMMUTABLE;
1896 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1897 +               inode->i_flags |= S_IXUNLINK;
1898 +
1899 +       if (ip->flags & BTRFS_INODE_SYNC)
1900 +               inode->i_flags |= S_SYNC;
1901         if (ip->flags & BTRFS_INODE_APPEND)
1902                 inode->i_flags |= S_APPEND;
1903         if (ip->flags & BTRFS_INODE_NOATIME)
1904                 inode->i_flags |= S_NOATIME;
1905         if (ip->flags & BTRFS_INODE_DIRSYNC)
1906                 inode->i_flags |= S_DIRSYNC;
1907 +
1908 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1909 +
1910 +       if (ip->flags & BTRFS_INODE_BARRIER)
1911 +               inode->i_vflags |= V_BARRIER;
1912 +       if (ip->flags & BTRFS_INODE_COW)
1913 +               inode->i_vflags |= V_COW;
1914 +}
1915 +
1916 +/*
1917 + * Update btrfs internal flags from inode->i_(v)flags.
1918 + */
1919 +void btrfs_update_flags(struct inode *inode)
1920 +{
1921 +       struct btrfs_inode *ip = BTRFS_I(inode);
1922 +
1923 +       unsigned int flags = inode->i_flags;
1924 +       unsigned int vflags = inode->i_vflags;
1925 +
1926 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1927 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1928 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1929 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1930 +
1931 +       if (flags & S_IMMUTABLE)
1932 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1933 +       if (flags & S_IXUNLINK)
1934 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1935 +
1936 +       if (flags & S_SYNC)
1937 +               ip->flags |= BTRFS_INODE_SYNC;
1938 +       if (flags & S_APPEND)
1939 +               ip->flags |= BTRFS_INODE_APPEND;
1940 +       if (flags & S_NOATIME)
1941 +               ip->flags |= BTRFS_INODE_NOATIME;
1942 +       if (flags & S_DIRSYNC)
1943 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1944 +
1945 +       if (vflags & V_BARRIER)
1946 +               ip->flags |= BTRFS_INODE_BARRIER;
1947 +       if (vflags & V_COW)
1948 +               ip->flags |= BTRFS_INODE_COW;
1949  }
1950  
1951  /*
1952 @@ -128,6 +181,7 @@ void btrfs_inherit_iflags(struct inode *
1953                 return;
1954  
1955         flags = BTRFS_I(dir)->flags;
1956 +       flags &= ~BTRFS_INODE_BARRIER;
1957  
1958         if (flags & BTRFS_INODE_NOCOMPRESS) {
1959                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1960 @@ -143,6 +197,30 @@ void btrfs_inherit_iflags(struct inode *
1961         btrfs_update_iflags(inode);
1962  }
1963  
1964 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1965 +{
1966 +       struct btrfs_inode *ip = BTRFS_I(inode);
1967 +       struct btrfs_root *root = ip->root;
1968 +       struct btrfs_trans_handle *trans;
1969 +       int ret;
1970 +
1971 +       trans = btrfs_join_transaction(root);
1972 +       BUG_ON(!trans);
1973 +
1974 +       inode->i_flags = flags;
1975 +       inode->i_vflags = vflags;
1976 +       btrfs_update_flags(inode);
1977 +
1978 +       ret = btrfs_update_inode(trans, root, inode);
1979 +       BUG_ON(ret);
1980 +
1981 +       btrfs_update_iflags(inode);
1982 +       inode->i_ctime = CURRENT_TIME;
1983 +       btrfs_end_transaction(trans, root);
1984 +
1985 +       return 0;
1986 +}
1987 +
1988  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1989  {
1990         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1991 @@ -194,7 +272,8 @@ static int btrfs_ioctl_setflags(struct f
1992  
1993         flags = btrfs_mask_flags(inode->i_mode, flags);
1994         oldflags = btrfs_flags_to_ioctl(ip->flags);
1995 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1996 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1997 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1998                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1999                         ret = -EPERM;
2000                         goto out_unlock;
2001 @@ -205,14 +284,19 @@ static int btrfs_ioctl_setflags(struct f
2002         if (ret)
2003                 goto out_unlock;
2004  
2005 -       if (flags & FS_SYNC_FL)
2006 -               ip->flags |= BTRFS_INODE_SYNC;
2007 -       else
2008 -               ip->flags &= ~BTRFS_INODE_SYNC;
2009         if (flags & FS_IMMUTABLE_FL)
2010                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2011         else
2012                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2013 +       if (flags & FS_IXUNLINK_FL)
2014 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2015 +       else
2016 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2017 +
2018 +       if (flags & FS_SYNC_FL)
2019 +               ip->flags |= BTRFS_INODE_SYNC;
2020 +       else
2021 +               ip->flags &= ~BTRFS_INODE_SYNC;
2022         if (flags & FS_APPEND_FL)
2023                 ip->flags |= BTRFS_INODE_APPEND;
2024         else
2025 diff -NurpP --minimal linux-3.2.8/fs/btrfs/super.c linux-3.2.8-vs2.3.2.7/fs/btrfs/super.c
2026 --- linux-3.2.8/fs/btrfs/super.c        2012-01-09 16:14:53.000000000 +0100
2027 +++ linux-3.2.8-vs2.3.2.7/fs/btrfs/super.c      2012-01-09 16:19:31.000000000 +0100
2028 @@ -165,7 +165,8 @@ enum {
2029         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2030         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2031         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
2032 -       Opt_inode_cache, Opt_no_space_cache, Opt_recovery, Opt_err,
2033 +       Opt_inode_cache, Opt_no_space_cache, Opt_recovery,
2034 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2035  };
2036  
2037  static match_table_t tokens = {
2038 @@ -200,6 +201,9 @@ static match_table_t tokens = {
2039         {Opt_inode_cache, "inode_cache"},
2040         {Opt_no_space_cache, "nospace_cache"},
2041         {Opt_recovery, "recovery"},
2042 +       {Opt_tag, "tag"},
2043 +       {Opt_notag, "notag"},
2044 +       {Opt_tagid, "tagid=%u"},
2045         {Opt_err, NULL},
2046  };
2047  
2048 @@ -398,6 +402,22 @@ int btrfs_parse_options(struct btrfs_roo
2049                         printk(KERN_INFO "btrfs: enabling auto recovery");
2050                         btrfs_set_opt(info->mount_opt, RECOVERY);
2051                         break;
2052 +#ifndef CONFIG_TAGGING_NONE
2053 +               case Opt_tag:
2054 +                       printk(KERN_INFO "btrfs: use tagging\n");
2055 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2056 +                       break;
2057 +               case Opt_notag:
2058 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2059 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2060 +                       break;
2061 +#endif
2062 +#ifdef CONFIG_PROPAGATE
2063 +               case Opt_tagid:
2064 +                       /* use args[0] */
2065 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2066 +                       break;
2067 +#endif
2068                 case Opt_err:
2069                         printk(KERN_INFO "btrfs: unrecognized mount option "
2070                                "'%s'\n", p);
2071 @@ -985,6 +1005,12 @@ static int btrfs_remount(struct super_bl
2072         if (ret)
2073                 return -EINVAL;
2074  
2075 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2076 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2077 +                       sb->s_id);
2078 +               return -EINVAL;
2079 +       }
2080 +
2081         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2082                 return 0;
2083  
2084 diff -NurpP --minimal linux-3.2.8/fs/char_dev.c linux-3.2.8-vs2.3.2.7/fs/char_dev.c
2085 --- linux-3.2.8/fs/char_dev.c   2011-03-15 18:07:31.000000000 +0100
2086 +++ linux-3.2.8-vs2.3.2.7/fs/char_dev.c 2011-12-05 19:33:02.000000000 +0100
2087 @@ -21,6 +21,8 @@
2088  #include <linux/mutex.h>
2089  #include <linux/backing-dev.h>
2090  #include <linux/tty.h>
2091 +#include <linux/vs_context.h>
2092 +#include <linux/vs_device.h>
2093  
2094  #include "internal.h"
2095  
2096 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2097         struct cdev *p;
2098         struct cdev *new = NULL;
2099         int ret = 0;
2100 +       dev_t mdev;
2101 +
2102 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2103 +               return -EPERM;
2104 +       inode->i_mdev = mdev;
2105  
2106         spin_lock(&cdev_lock);
2107         p = inode->i_cdev;
2108         if (!p) {
2109                 struct kobject *kobj;
2110                 int idx;
2111 +
2112                 spin_unlock(&cdev_lock);
2113 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2114 +
2115 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2116                 if (!kobj)
2117                         return -ENXIO;
2118                 new = container_of(kobj, struct cdev, kobj);
2119 diff -NurpP --minimal linux-3.2.8/fs/dcache.c linux-3.2.8-vs2.3.2.7/fs/dcache.c
2120 --- linux-3.2.8/fs/dcache.c     2012-02-28 05:53:29.000000000 +0100
2121 +++ linux-3.2.8-vs2.3.2.7/fs/dcache.c   2012-01-26 08:52:10.000000000 +0100
2122 @@ -37,6 +37,7 @@
2123  #include <linux/rculist_bl.h>
2124  #include <linux/prefetch.h>
2125  #include <linux/ratelimit.h>
2126 +#include <linux/vs_limit.h>
2127  #include "internal.h"
2128  
2129  /*
2130 @@ -539,6 +540,8 @@ int d_invalidate(struct dentry * dentry)
2131                 spin_lock(&dentry->d_lock);
2132         }
2133  
2134 +       vx_dentry_dec(dentry);
2135 +
2136         /*
2137          * Somebody else still using it?
2138          *
2139 @@ -568,6 +571,7 @@ EXPORT_SYMBOL(d_invalidate);
2140  static inline void __dget_dlock(struct dentry *dentry)
2141  {
2142         dentry->d_count++;
2143 +       vx_dentry_inc(dentry);
2144  }
2145  
2146  static inline void __dget(struct dentry *dentry)
2147 @@ -1192,6 +1196,9 @@ struct dentry *__d_alloc(struct super_bl
2148         struct dentry *dentry;
2149         char *dname;
2150  
2151 +       if (!vx_dentry_avail(1))
2152 +               return NULL;
2153 +
2154         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2155         if (!dentry)
2156                 return NULL;
2157 @@ -1214,6 +1221,7 @@ struct dentry *__d_alloc(struct super_bl
2158  
2159         dentry->d_count = 1;
2160         dentry->d_flags = 0;
2161 +       vx_dentry_inc(dentry);
2162         spin_lock_init(&dentry->d_lock);
2163         seqcount_init(&dentry->d_seq);
2164         dentry->d_inode = NULL;
2165 @@ -1872,6 +1880,7 @@ struct dentry *__d_lookup(struct dentry 
2166                 }
2167  
2168                 dentry->d_count++;
2169 +               vx_dentry_inc(dentry);
2170                 found = dentry;
2171                 spin_unlock(&dentry->d_lock);
2172                 break;
2173 diff -NurpP --minimal linux-3.2.8/fs/devpts/inode.c linux-3.2.8-vs2.3.2.7/fs/devpts/inode.c
2174 --- linux-3.2.8/fs/devpts/inode.c       2012-01-09 16:14:54.000000000 +0100
2175 +++ linux-3.2.8-vs2.3.2.7/fs/devpts/inode.c     2011-12-05 21:23:19.000000000 +0100
2176 @@ -25,6 +25,7 @@
2177  #include <linux/parser.h>
2178  #include <linux/fsnotify.h>
2179  #include <linux/seq_file.h>
2180 +#include <linux/vs_base.h>
2181  
2182  #define DEVPTS_DEFAULT_MODE 0600
2183  /*
2184 @@ -36,6 +37,20 @@
2185  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2186  #define PTMX_MINOR     2
2187  
2188 +static int devpts_permission(struct inode *inode, int mask)
2189 +{
2190 +       int ret = -EACCES;
2191 +
2192 +       /* devpts is xid tagged */
2193 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2194 +               ret = generic_permission(inode, mask);
2195 +       return ret;
2196 +}
2197 +
2198 +static struct inode_operations devpts_file_inode_operations = {
2199 +       .permission     = devpts_permission,
2200 +};
2201 +
2202  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2203  static DEFINE_MUTEX(allocated_ptys_lock);
2204  
2205 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2206         return 0;
2207  }
2208  
2209 +static int devpts_filter(struct dentry *de)
2210 +{
2211 +       xid_t xid = 0;
2212 +
2213 +       /* devpts is xid tagged */
2214 +       if (de && de->d_inode)
2215 +               xid = (xid_t)de->d_inode->i_tag;
2216 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2217 +       else
2218 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2219 +                       de->d_name.len, de->d_name.name);
2220 +#endif
2221 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2222 +}
2223 +
2224 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2225 +{
2226 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2227 +}
2228 +
2229 +static struct file_operations devpts_dir_operations = {
2230 +       .open           = dcache_dir_open,
2231 +       .release        = dcache_dir_close,
2232 +       .llseek         = dcache_dir_lseek,
2233 +       .read           = generic_read_dir,
2234 +       .readdir        = devpts_readdir,
2235 +};
2236 +
2237  static const struct super_operations devpts_sops = {
2238         .statfs         = simple_statfs,
2239         .remount_fs     = devpts_remount,
2240 @@ -306,8 +349,10 @@ devpts_fill_super(struct super_block *s,
2241         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2242         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2243         inode->i_op = &simple_dir_inode_operations;
2244 -       inode->i_fop = &simple_dir_operations;
2245 +       inode->i_fop = &devpts_dir_operations;
2246         set_nlink(inode, 2);
2247 +       /* devpts is xid tagged */
2248 +       inode->i_tag = (tag_t)vx_current_xid();
2249  
2250         s->s_root = d_alloc_root(inode);
2251         if (s->s_root)
2252 @@ -494,6 +539,9 @@ int devpts_pty_new(struct inode *ptmx_in
2253         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2254         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2255         init_special_inode(inode, S_IFCHR|opts->mode, device);
2256 +       /* devpts is xid tagged */
2257 +       inode->i_tag = (tag_t)vx_current_xid();
2258 +       inode->i_op = &devpts_file_inode_operations;
2259         inode->i_private = tty;
2260         tty->driver_data = inode;
2261  
2262 diff -NurpP --minimal linux-3.2.8/fs/ext2/balloc.c linux-3.2.8-vs2.3.2.7/fs/ext2/balloc.c
2263 --- linux-3.2.8/fs/ext2/balloc.c        2012-01-09 16:14:54.000000000 +0100
2264 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/balloc.c      2011-12-05 19:33:02.000000000 +0100
2265 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2266                         start = 0;
2267                 end = EXT2_BLOCKS_PER_GROUP(sb);
2268         }
2269 -
2270         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2271  
2272  repeat:
2273 diff -NurpP --minimal linux-3.2.8/fs/ext2/ext2.h linux-3.2.8-vs2.3.2.7/fs/ext2/ext2.h
2274 --- linux-3.2.8/fs/ext2/ext2.h  2012-01-09 16:14:54.000000000 +0100
2275 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/ext2.h        2011-12-05 19:33:02.000000000 +0100
2276 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2277  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2278  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2279                        u64 start, u64 len);
2280 +extern int ext2_sync_flags(struct inode *, int, int);
2281  
2282  /* ioctl.c */
2283  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2284 diff -NurpP --minimal linux-3.2.8/fs/ext2/file.c linux-3.2.8-vs2.3.2.7/fs/ext2/file.c
2285 --- linux-3.2.8/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2286 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/file.c        2011-12-05 19:33:02.000000000 +0100
2287 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2288         .setattr        = ext2_setattr,
2289         .get_acl        = ext2_get_acl,
2290         .fiemap         = ext2_fiemap,
2291 +       .sync_flags     = ext2_sync_flags,
2292  };
2293 diff -NurpP --minimal linux-3.2.8/fs/ext2/ialloc.c linux-3.2.8-vs2.3.2.7/fs/ext2/ialloc.c
2294 --- linux-3.2.8/fs/ext2/ialloc.c        2012-01-09 16:14:54.000000000 +0100
2295 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/ialloc.c      2011-12-05 19:33:02.000000000 +0100
2296 @@ -17,6 +17,7 @@
2297  #include <linux/backing-dev.h>
2298  #include <linux/buffer_head.h>
2299  #include <linux/random.h>
2300 +#include <linux/vs_tag.h>
2301  #include "ext2.h"
2302  #include "xattr.h"
2303  #include "acl.h"
2304 @@ -549,6 +550,7 @@ got:
2305                 inode->i_mode = mode;
2306                 inode->i_uid = current_fsuid();
2307                 inode->i_gid = dir->i_gid;
2308 +               inode->i_tag = dx_current_fstag(sb);
2309         } else
2310                 inode_init_owner(inode, dir, mode);
2311  
2312 diff -NurpP --minimal linux-3.2.8/fs/ext2/inode.c linux-3.2.8-vs2.3.2.7/fs/ext2/inode.c
2313 --- linux-3.2.8/fs/ext2/inode.c 2012-01-09 16:14:54.000000000 +0100
2314 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/inode.c       2011-12-05 21:24:12.000000000 +0100
2315 @@ -32,6 +32,7 @@
2316  #include <linux/mpage.h>
2317  #include <linux/fiemap.h>
2318  #include <linux/namei.h>
2319 +#include <linux/vs_tag.h>
2320  #include "ext2.h"
2321  #include "acl.h"
2322  #include "xip.h"
2323 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
2324                 return;
2325         if (ext2_inode_is_fast_symlink(inode))
2326                 return;
2327 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2328 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2329                 return;
2330         __ext2_truncate_blocks(inode, offset);
2331  }
2332 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2333  {
2334         unsigned int flags = EXT2_I(inode)->i_flags;
2335  
2336 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2337 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2338 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2339 +
2340 +
2341 +       if (flags & EXT2_IMMUTABLE_FL)
2342 +               inode->i_flags |= S_IMMUTABLE;
2343 +       if (flags & EXT2_IXUNLINK_FL)
2344 +               inode->i_flags |= S_IXUNLINK;
2345 +
2346         if (flags & EXT2_SYNC_FL)
2347                 inode->i_flags |= S_SYNC;
2348         if (flags & EXT2_APPEND_FL)
2349                 inode->i_flags |= S_APPEND;
2350 -       if (flags & EXT2_IMMUTABLE_FL)
2351 -               inode->i_flags |= S_IMMUTABLE;
2352         if (flags & EXT2_NOATIME_FL)
2353                 inode->i_flags |= S_NOATIME;
2354         if (flags & EXT2_DIRSYNC_FL)
2355                 inode->i_flags |= S_DIRSYNC;
2356 +
2357 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2358 +
2359 +       if (flags & EXT2_BARRIER_FL)
2360 +               inode->i_vflags |= V_BARRIER;
2361 +       if (flags & EXT2_COW_FL)
2362 +               inode->i_vflags |= V_COW;
2363  }
2364  
2365  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2366  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2367  {
2368         unsigned int flags = ei->vfs_inode.i_flags;
2369 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2370 +
2371 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2372 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2373 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2374 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2375 +
2376 +       if (flags & S_IMMUTABLE)
2377 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2378 +       if (flags & S_IXUNLINK)
2379 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2380  
2381 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2382 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2383         if (flags & S_SYNC)
2384                 ei->i_flags |= EXT2_SYNC_FL;
2385         if (flags & S_APPEND)
2386                 ei->i_flags |= EXT2_APPEND_FL;
2387 -       if (flags & S_IMMUTABLE)
2388 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2389         if (flags & S_NOATIME)
2390                 ei->i_flags |= EXT2_NOATIME_FL;
2391         if (flags & S_DIRSYNC)
2392                 ei->i_flags |= EXT2_DIRSYNC_FL;
2393 +
2394 +       if (vflags & V_BARRIER)
2395 +               ei->i_flags |= EXT2_BARRIER_FL;
2396 +       if (vflags & V_COW)
2397 +               ei->i_flags |= EXT2_COW_FL;
2398  }
2399  
2400  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2401 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2402         struct ext2_inode *raw_inode;
2403         struct inode *inode;
2404         long ret = -EIO;
2405 +       uid_t uid;
2406 +       gid_t gid;
2407         int n;
2408  
2409         inode = iget_locked(sb, ino);
2410 @@ -1315,12 +1343,16 @@ struct inode *ext2_iget (struct super_bl
2411         }
2412  
2413         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2414 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2415 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2416 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2417 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2418         if (!(test_opt (inode->i_sb, NO_UID32))) {
2419 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2420 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2421 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2422 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2423         }
2424 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2425 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2426 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2427 +               le16_to_cpu(raw_inode->i_raw_tag));
2428         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2429         inode->i_size = le32_to_cpu(raw_inode->i_size);
2430         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2431 @@ -1418,8 +1450,8 @@ static int __ext2_write_inode(struct ino
2432         struct ext2_inode_info *ei = EXT2_I(inode);
2433         struct super_block *sb = inode->i_sb;
2434         ino_t ino = inode->i_ino;
2435 -       uid_t uid = inode->i_uid;
2436 -       gid_t gid = inode->i_gid;
2437 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2438 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2439         struct buffer_head * bh;
2440         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2441         int n;
2442 @@ -1455,6 +1487,9 @@ static int __ext2_write_inode(struct ino
2443                 raw_inode->i_uid_high = 0;
2444                 raw_inode->i_gid_high = 0;
2445         }
2446 +#ifdef CONFIG_TAGGING_INTERN
2447 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2448 +#endif
2449         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2450         raw_inode->i_size = cpu_to_le32(inode->i_size);
2451         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2452 @@ -1535,7 +1570,8 @@ int ext2_setattr(struct dentry *dentry, 
2453         if (is_quota_modification(inode, iattr))
2454                 dquot_initialize(inode);
2455         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2456 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2457 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2458 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2459                 error = dquot_transfer(inode, iattr);
2460                 if (error)
2461                         return error;
2462 diff -NurpP --minimal linux-3.2.8/fs/ext2/ioctl.c linux-3.2.8-vs2.3.2.7/fs/ext2/ioctl.c
2463 --- linux-3.2.8/fs/ext2/ioctl.c 2011-05-22 16:17:51.000000000 +0200
2464 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/ioctl.c       2011-12-05 19:33:02.000000000 +0100
2465 @@ -17,6 +17,16 @@
2466  #include <asm/uaccess.h>
2467  
2468  
2469 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2470 +{
2471 +       inode->i_flags = flags;
2472 +       inode->i_vflags = vflags;
2473 +       ext2_get_inode_flags(EXT2_I(inode));
2474 +       inode->i_ctime = CURRENT_TIME_SEC;
2475 +       mark_inode_dirty(inode);
2476 +       return 0;
2477 +}
2478 +
2479  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2480  {
2481         struct inode *inode = filp->f_dentry->d_inode;
2482 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2483  
2484                 flags = ext2_mask_flags(inode->i_mode, flags);
2485  
2486 +               if (IS_BARRIER(inode)) {
2487 +                       vxwprintk_task(1, "messing with the barrier.");
2488 +                       return -EACCES;
2489 +               }
2490 +
2491                 mutex_lock(&inode->i_mutex);
2492                 /* Is it quota file? Do not allow user to mess with it */
2493                 if (IS_NOQUOTA(inode)) {
2494 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2495                  *
2496                  * This test looks nicer. Thanks to Pauline Middelink
2497                  */
2498 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2499 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2500 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2501 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2502                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2503                                 mutex_unlock(&inode->i_mutex);
2504                                 ret = -EPERM;
2505 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2506                         }
2507                 }
2508  
2509 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2510 +               flags &= EXT2_FL_USER_MODIFIABLE;
2511                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2512                 ei->i_flags = flags;
2513                 mutex_unlock(&inode->i_mutex);
2514 diff -NurpP --minimal linux-3.2.8/fs/ext2/namei.c linux-3.2.8-vs2.3.2.7/fs/ext2/namei.c
2515 --- linux-3.2.8/fs/ext2/namei.c 2011-10-24 18:45:27.000000000 +0200
2516 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/namei.c       2011-12-05 19:33:02.000000000 +0100
2517 @@ -32,6 +32,7 @@
2518  
2519  #include <linux/pagemap.h>
2520  #include <linux/quotaops.h>
2521 +#include <linux/vs_tag.h>
2522  #include "ext2.h"
2523  #include "xattr.h"
2524  #include "acl.h"
2525 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2526                                         (unsigned long) ino);
2527                         return ERR_PTR(-EIO);
2528                 }
2529 +               dx_propagate_tag(nd, inode);
2530         }
2531         return d_splice_alias(inode, dentry);
2532  }
2533 @@ -408,6 +410,7 @@ const struct inode_operations ext2_dir_i
2534         .removexattr    = generic_removexattr,
2535  #endif
2536         .setattr        = ext2_setattr,
2537 +       .sync_flags     = ext2_sync_flags,
2538         .get_acl        = ext2_get_acl,
2539  };
2540  
2541 diff -NurpP --minimal linux-3.2.8/fs/ext2/super.c linux-3.2.8-vs2.3.2.7/fs/ext2/super.c
2542 --- linux-3.2.8/fs/ext2/super.c 2012-01-09 16:14:54.000000000 +0100
2543 +++ linux-3.2.8-vs2.3.2.7/fs/ext2/super.c       2011-12-05 19:33:02.000000000 +0100
2544 @@ -394,7 +394,8 @@ enum {
2545         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2546         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2547         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2548 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2549 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2550 +       Opt_tag, Opt_notag, Opt_tagid
2551  };
2552  
2553  static const match_table_t tokens = {
2554 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
2555         {Opt_acl, "acl"},
2556         {Opt_noacl, "noacl"},
2557         {Opt_xip, "xip"},
2558 +       {Opt_tag, "tag"},
2559 +       {Opt_notag, "notag"},
2560 +       {Opt_tagid, "tagid=%u"},
2561         {Opt_grpquota, "grpquota"},
2562         {Opt_ignore, "noquota"},
2563         {Opt_quota, "quota"},
2564 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
2565                 case Opt_nouid32:
2566                         set_opt (sbi->s_mount_opt, NO_UID32);
2567                         break;
2568 +#ifndef CONFIG_TAGGING_NONE
2569 +               case Opt_tag:
2570 +                       set_opt (sbi->s_mount_opt, TAGGED);
2571 +                       break;
2572 +               case Opt_notag:
2573 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2574 +                       break;
2575 +#endif
2576 +#ifdef CONFIG_PROPAGATE
2577 +               case Opt_tagid:
2578 +                       /* use args[0] */
2579 +                       set_opt (sbi->s_mount_opt, TAGGED);
2580 +                       break;
2581 +#endif
2582                 case Opt_nocheck:
2583                         clear_opt (sbi->s_mount_opt, CHECK);
2584                         break;
2585 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
2586         if (!parse_options((char *) data, sb))
2587                 goto failed_mount;
2588  
2589 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2590 +               sb->s_flags |= MS_TAGGED;
2591         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2592                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2593                  MS_POSIXACL : 0);
2594 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
2595                 goto restore_opts;
2596         }
2597  
2598 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2599 +               !(sb->s_flags & MS_TAGGED)) {
2600 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2601 +                      sb->s_id);
2602 +               err = -EINVAL;
2603 +               goto restore_opts;
2604 +       }
2605 +
2606         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2607                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2608  
2609 diff -NurpP --minimal linux-3.2.8/fs/ext3/file.c linux-3.2.8-vs2.3.2.7/fs/ext3/file.c
2610 --- linux-3.2.8/fs/ext3/file.c  2011-10-24 18:45:27.000000000 +0200
2611 +++ linux-3.2.8-vs2.3.2.7/fs/ext3/file.c        2011-12-05 19:33:02.000000000 +0100
2612 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
2613  #endif
2614         .get_acl        = ext3_get_acl,
2615         .fiemap         = ext3_fiemap,
2616 +       .sync_flags     = ext3_sync_flags,
2617  };
2618  
2619 diff -NurpP --minimal linux-3.2.8/fs/ext3/ialloc.c linux-3.2.8-vs2.3.2.7/fs/ext3/ialloc.c
2620 --- linux-3.2.8/fs/ext3/ialloc.c        2012-01-09 16:14:54.000000000 +0100
2621 +++ linux-3.2.8-vs2.3.2.7/fs/ext3/ialloc.c      2011-12-05 19:33:02.000000000 +0100
2622 @@ -23,6 +23,7 @@
2623  #include <linux/buffer_head.h>
2624  #include <linux/random.h>
2625  #include <linux/bitops.h>
2626 +#include <linux/vs_tag.h>
2627  #include <trace/events/ext3.h>
2628  
2629  #include <asm/byteorder.h>
2630 @@ -496,6 +497,7 @@ got:
2631                 inode->i_mode = mode;
2632                 inode->i_uid = current_fsuid();
2633                 inode->i_gid = dir->i_gid;
2634 +               inode->i_tag = dx_current_fstag(sb);
2635         } else
2636                 inode_init_owner(inode, dir, mode);
2637  
2638 diff -NurpP --minimal linux-3.2.8/fs/ext3/inode.c linux-3.2.8-vs2.3.2.7/fs/ext3/inode.c
2639 --- linux-3.2.8/fs/ext3/inode.c 2012-02-28 05:53:29.000000000 +0100
2640 +++ linux-3.2.8-vs2.3.2.7/fs/ext3/inode.c       2012-01-18 02:58:07.000000000 +0100
2641 @@ -38,6 +38,7 @@
2642  #include <linux/bio.h>
2643  #include <linux/fiemap.h>
2644  #include <linux/namei.h>
2645 +#include <linux/vs_tag.h>
2646  #include <trace/events/ext3.h>
2647  #include "xattr.h"
2648  #include "acl.h"
2649 @@ -2852,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2650  {
2651         unsigned int flags = EXT3_I(inode)->i_flags;
2652  
2653 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2654 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2655 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2656 +
2657 +       if (flags & EXT3_IMMUTABLE_FL)
2658 +               inode->i_flags |= S_IMMUTABLE;
2659 +       if (flags & EXT3_IXUNLINK_FL)
2660 +               inode->i_flags |= S_IXUNLINK;
2661 +
2662         if (flags & EXT3_SYNC_FL)
2663                 inode->i_flags |= S_SYNC;
2664         if (flags & EXT3_APPEND_FL)
2665                 inode->i_flags |= S_APPEND;
2666 -       if (flags & EXT3_IMMUTABLE_FL)
2667 -               inode->i_flags |= S_IMMUTABLE;
2668         if (flags & EXT3_NOATIME_FL)
2669                 inode->i_flags |= S_NOATIME;
2670         if (flags & EXT3_DIRSYNC_FL)
2671                 inode->i_flags |= S_DIRSYNC;
2672 +
2673 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2674 +
2675 +       if (flags & EXT3_BARRIER_FL)
2676 +               inode->i_vflags |= V_BARRIER;
2677 +       if (flags & EXT3_COW_FL)
2678 +               inode->i_vflags |= V_COW;
2679  }
2680  
2681  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2682  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2683  {
2684         unsigned int flags = ei->vfs_inode.i_flags;
2685 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2686 +
2687 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2688 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2689 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2690 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2691 +
2692 +       if (flags & S_IMMUTABLE)
2693 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2694 +       if (flags & S_IXUNLINK)
2695 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2696  
2697 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2698 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2699         if (flags & S_SYNC)
2700                 ei->i_flags |= EXT3_SYNC_FL;
2701         if (flags & S_APPEND)
2702                 ei->i_flags |= EXT3_APPEND_FL;
2703 -       if (flags & S_IMMUTABLE)
2704 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2705         if (flags & S_NOATIME)
2706                 ei->i_flags |= EXT3_NOATIME_FL;
2707         if (flags & S_DIRSYNC)
2708                 ei->i_flags |= EXT3_DIRSYNC_FL;
2709 +
2710 +       if (vflags & V_BARRIER)
2711 +               ei->i_flags |= EXT3_BARRIER_FL;
2712 +       if (vflags & V_COW)
2713 +               ei->i_flags |= EXT3_COW_FL;
2714  }
2715  
2716  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2717 @@ -2895,6 +2920,8 @@ struct inode *ext3_iget(struct super_blo
2718         transaction_t *transaction;
2719         long ret;
2720         int block;
2721 +       uid_t uid;
2722 +       gid_t gid;
2723  
2724         inode = iget_locked(sb, ino);
2725         if (!inode)
2726 @@ -2911,12 +2938,16 @@ struct inode *ext3_iget(struct super_blo
2727         bh = iloc.bh;
2728         raw_inode = ext3_raw_inode(&iloc);
2729         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2730 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2731 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2732 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2733 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2734         if(!(test_opt (inode->i_sb, NO_UID32))) {
2735 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2736 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2737 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2738 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2739         }
2740 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2741 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2742 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2743 +               le16_to_cpu(raw_inode->i_raw_tag));
2744         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2745         inode->i_size = le32_to_cpu(raw_inode->i_size);
2746         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2747 @@ -3071,6 +3102,8 @@ static int ext3_do_update_inode(handle_t
2748         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2749         struct ext3_inode_info *ei = EXT3_I(inode);
2750         struct buffer_head *bh = iloc->bh;
2751 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2752 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2753         int err = 0, rc, block;
2754  
2755  again:
2756 @@ -3085,29 +3118,32 @@ again:
2757         ext3_get_inode_flags(ei);
2758         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2759         if(!(test_opt(inode->i_sb, NO_UID32))) {
2760 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2761 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2762 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2763 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2764  /*
2765   * Fix up interoperability with old kernels. Otherwise, old inodes get
2766   * re-used with the upper 16 bits of the uid/gid intact
2767   */
2768                 if(!ei->i_dtime) {
2769                         raw_inode->i_uid_high =
2770 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2771 +                               cpu_to_le16(high_16_bits(uid));
2772                         raw_inode->i_gid_high =
2773 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2774 +                               cpu_to_le16(high_16_bits(gid));
2775                 } else {
2776                         raw_inode->i_uid_high = 0;
2777                         raw_inode->i_gid_high = 0;
2778                 }
2779         } else {
2780                 raw_inode->i_uid_low =
2781 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2782 +                       cpu_to_le16(fs_high2lowuid(uid));
2783                 raw_inode->i_gid_low =
2784 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2785 +                       cpu_to_le16(fs_high2lowgid(gid));
2786                 raw_inode->i_uid_high = 0;
2787                 raw_inode->i_gid_high = 0;
2788         }
2789 +#ifdef CONFIG_TAGGING_INTERN
2790 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2791 +#endif
2792         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2793         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2794         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2795 @@ -3267,7 +3303,8 @@ int ext3_setattr(struct dentry *dentry, 
2796         if (is_quota_modification(inode, attr))
2797                 dquot_initialize(inode);
2798         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2799 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2800 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2801 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2802                 handle_t *handle;
2803  
2804                 /* (user+group)*(old+new) structure, inode write (sb,
2805 @@ -3289,6 +3326,8 @@ int ext3_setattr(struct dentry *dentry, 
2806                         inode->i_uid = attr->ia_uid;
2807                 if (attr->ia_valid & ATTR_GID)
2808                         inode->i_gid = attr->ia_gid;
2809 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2810 +                       inode->i_tag = attr->ia_tag;
2811                 error = ext3_mark_inode_dirty(handle, inode);
2812                 ext3_journal_stop(handle);
2813         }
2814 diff -NurpP --minimal linux-3.2.8/fs/ext3/ioctl.c linux-3.2.8-vs2.3.2.7/fs/ext3/ioctl.c
2815 --- linux-3.2.8/fs/ext3/ioctl.c 2012-01-09 16:14:54.000000000 +0100
2816 +++ linux-3.2.8-vs2.3.2.7/fs/ext3/ioctl.c       2011-12-05 19:33:02.000000000 +0100
2817 @@ -8,6 +8,7 @@
2818   */
2819  
2820  #include <linux/fs.h>
2821 +#include <linux/mount.h>
2822  #include <linux/jbd.h>
2823  #include <linux/capability.h>
2824  #include <linux/ext3_fs.h>
2825 @@ -17,6 +18,34 @@
2826  #include <linux/compat.h>
2827  #include <asm/uaccess.h>
2828  
2829 +
2830 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2831 +{
2832 +       handle_t *handle = NULL;
2833 +       struct ext3_iloc iloc;
2834 +       int err;
2835 +
2836 +       handle = ext3_journal_start(inode, 1);
2837 +       if (IS_ERR(handle))
2838 +               return PTR_ERR(handle);
2839 +
2840 +       if (IS_SYNC(inode))
2841 +               handle->h_sync = 1;
2842 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2843 +       if (err)
2844 +               goto flags_err;
2845 +
2846 +       inode->i_flags = flags;
2847 +       inode->i_vflags = vflags;
2848 +       ext3_get_inode_flags(EXT3_I(inode));
2849 +       inode->i_ctime = CURRENT_TIME_SEC;
2850 +
2851 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2852 +flags_err:
2853 +       ext3_journal_stop(handle);
2854 +       return err;
2855 +}
2856 +
2857  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2858  {
2859         struct inode *inode = filp->f_dentry->d_inode;
2860 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
2861  
2862                 flags = ext3_mask_flags(inode->i_mode, flags);
2863  
2864 +               if (IS_BARRIER(inode)) {
2865 +                       vxwprintk_task(1, "messing with the barrier.");
2866 +                       return -EACCES;
2867 +               }
2868 +
2869                 mutex_lock(&inode->i_mutex);
2870  
2871                 /* Is it quota file? Do not allow user to mess with it */
2872 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
2873                  *
2874                  * This test looks nicer. Thanks to Pauline Middelink
2875                  */
2876 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2877 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2878 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2879 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2880                         if (!capable(CAP_LINUX_IMMUTABLE))
2881                                 goto flags_out;
2882                 }
2883 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
2884                 if (err)
2885                         goto flags_err;
2886  
2887 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2888 +               flags &= EXT3_FL_USER_MODIFIABLE;
2889                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2890                 ei->i_flags = flags;
2891  
2892 diff -NurpP --minimal linux-3.2.8/fs/ext3/namei.c linux-3.2.8-vs2.3.2.7/fs/ext3/namei.c
2893 --- linux-3.2.8/fs/ext3/namei.c 2012-01-09 16:14:54.000000000 +0100
2894 +++ linux-3.2.8-vs2.3.2.7/fs/ext3/namei.c       2011-12-05 19:33:02.000000000 +0100
2895 @@ -36,6 +36,7 @@
2896  #include <linux/quotaops.h>
2897  #include <linux/buffer_head.h>
2898  #include <linux/bio.h>
2899 +#include <linux/vs_tag.h>
2900  #include <trace/events/ext3.h>
2901  
2902  #include "namei.h"
2903 @@ -925,6 +926,7 @@ restart:
2904                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
2905                                                     1, &bh);
2906                         }
2907 +               dx_propagate_tag(nd, inode);
2908                 }
2909                 if ((bh = bh_use[ra_ptr++]) == NULL)
2910                         goto next;
2911 @@ -2535,6 +2537,7 @@ const struct inode_operations ext3_dir_i
2912         .listxattr      = ext3_listxattr,
2913         .removexattr    = generic_removexattr,
2914  #endif
2915 +       .sync_flags     = ext3_sync_flags,
2916         .get_acl        = ext3_get_acl,
2917  };
2918  
2919 diff -NurpP --minimal linux-3.2.8/fs/ext3/super.c linux-3.2.8-vs2.3.2.7/fs/ext3/super.c
2920 --- linux-3.2.8/fs/ext3/super.c 2012-01-09 16:14:54.000000000 +0100
2921 +++ linux-3.2.8-vs2.3.2.7/fs/ext3/super.c       2011-12-05 19:33:02.000000000 +0100
2922 @@ -831,7 +831,8 @@ enum {
2923         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2924         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2925         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2926 -       Opt_resize, Opt_usrquota, Opt_grpquota
2927 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2928 +       Opt_tag, Opt_notag, Opt_tagid
2929  };
2930  
2931  static const match_table_t tokens = {
2932 @@ -888,6 +889,9 @@ static const match_table_t tokens = {
2933         {Opt_barrier, "barrier"},
2934         {Opt_nobarrier, "nobarrier"},
2935         {Opt_resize, "resize"},
2936 +       {Opt_tag, "tag"},
2937 +       {Opt_notag, "notag"},
2938 +       {Opt_tagid, "tagid=%u"},
2939         {Opt_err, NULL},
2940  };
2941  
2942 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2943                 case Opt_nouid32:
2944                         set_opt (sbi->s_mount_opt, NO_UID32);
2945                         break;
2946 +#ifndef CONFIG_TAGGING_NONE
2947 +               case Opt_tag:
2948 +                       set_opt (sbi->s_mount_opt, TAGGED);
2949 +                       break;
2950 +               case Opt_notag:
2951 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2952 +                       break;
2953 +#endif
2954 +#ifdef CONFIG_PROPAGATE
2955 +               case Opt_tagid:
2956 +                       /* use args[0] */
2957 +                       set_opt (sbi->s_mount_opt, TAGGED);
2958 +                       break;
2959 +#endif
2960                 case Opt_nocheck:
2961                         clear_opt (sbi->s_mount_opt, CHECK);
2962                         break;
2963 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
2964                             NULL, 0))
2965                 goto failed_mount;
2966  
2967 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2968 +               sb->s_flags |= MS_TAGGED;
2969 +
2970         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2971                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2972  
2973 @@ -2619,6 +2640,14 @@ static int ext3_remount (struct super_bl
2974         if (test_opt(sb, ABORT))
2975                 ext3_abort(sb, __func__, "Abort forced by user");
2976  
2977 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2978 +               !(sb->s_flags & MS_TAGGED)) {
2979 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2980 +                       sb->s_id);
2981 +               err = -EINVAL;
2982 +               goto restore_opts;
2983 +       }
2984 +
2985         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2986                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2987  
2988 diff -NurpP --minimal linux-3.2.8/fs/ext4/ext4.h linux-3.2.8-vs2.3.2.7/fs/ext4/ext4.h
2989 --- linux-3.2.8/fs/ext4/ext4.h  2012-01-09 16:14:54.000000000 +0100
2990 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/ext4.h        2011-12-05 19:33:02.000000000 +0100
2991 @@ -371,8 +371,12 @@ struct flex_groups {
2992  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2993  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2994  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2995 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2996  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2997  
2998 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2999 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3000 +
3001  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3002  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3003  
3004 @@ -632,7 +636,8 @@ struct ext4_inode {
3005                         __le16  l_i_file_acl_high;
3006                         __le16  l_i_uid_high;   /* these 2 fields */
3007                         __le16  l_i_gid_high;   /* were reserved2[0] */
3008 -                       __u32   l_i_reserved2;
3009 +                       __le16  l_i_tag;        /* Context Tag */
3010 +                       __u16   l_i_reserved2;
3011                 } linux2;
3012                 struct {
3013                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3014 @@ -750,6 +755,7 @@ do {                                                                               \
3015  #define i_gid_low      i_gid
3016  #define i_uid_high     osd2.linux2.l_i_uid_high
3017  #define i_gid_high     osd2.linux2.l_i_gid_high
3018 +#define i_raw_tag      osd2.linux2.l_i_tag
3019  #define i_reserved2    osd2.linux2.l_i_reserved2
3020  
3021  #elif defined(__GNU__)
3022 @@ -926,6 +932,7 @@ struct ext4_inode_info {
3023  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3024  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3025  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3026 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3027  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3028  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3029  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3030 @@ -2270,6 +2277,7 @@ extern int ext4_map_blocks(handle_t *han
3031                            struct ext4_map_blocks *map, int flags);
3032  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3033                         __u64 start, __u64 len);
3034 +extern int ext4_sync_flags(struct inode *, int, int);
3035  /* move_extent.c */
3036  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3037                              __u64 start_orig, __u64 start_donor,
3038 diff -NurpP --minimal linux-3.2.8/fs/ext4/file.c linux-3.2.8-vs2.3.2.7/fs/ext4/file.c
3039 --- linux-3.2.8/fs/ext4/file.c  2012-01-09 16:14:54.000000000 +0100
3040 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/file.c        2011-12-05 19:33:02.000000000 +0100
3041 @@ -258,5 +258,6 @@ const struct inode_operations ext4_file_
3042  #endif
3043         .get_acl        = ext4_get_acl,
3044         .fiemap         = ext4_fiemap,
3045 +       .sync_flags     = ext4_sync_flags,
3046  };
3047  
3048 diff -NurpP --minimal linux-3.2.8/fs/ext4/ialloc.c linux-3.2.8-vs2.3.2.7/fs/ext4/ialloc.c
3049 --- linux-3.2.8/fs/ext4/ialloc.c        2012-01-09 16:14:54.000000000 +0100
3050 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/ialloc.c      2011-12-05 19:33:02.000000000 +0100
3051 @@ -22,6 +22,7 @@
3052  #include <linux/random.h>
3053  #include <linux/bitops.h>
3054  #include <linux/blkdev.h>
3055 +#include <linux/vs_tag.h>
3056  #include <asm/byteorder.h>
3057  
3058  #include "ext4.h"
3059 @@ -860,6 +861,7 @@ got:
3060                 inode->i_mode = mode;
3061                 inode->i_uid = current_fsuid();
3062                 inode->i_gid = dir->i_gid;
3063 +               inode->i_tag = dx_current_fstag(sb);
3064         } else
3065                 inode_init_owner(inode, dir, mode);
3066  
3067 diff -NurpP --minimal linux-3.2.8/fs/ext4/inode.c linux-3.2.8-vs2.3.2.7/fs/ext4/inode.c
3068 --- linux-3.2.8/fs/ext4/inode.c 2012-01-09 16:14:54.000000000 +0100
3069 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/inode.c       2012-01-09 16:19:31.000000000 +0100
3070 @@ -38,6 +38,7 @@
3071  #include <linux/printk.h>
3072  #include <linux/slab.h>
3073  #include <linux/ratelimit.h>
3074 +#include <linux/vs_tag.h>
3075  
3076  #include "ext4_jbd2.h"
3077  #include "xattr.h"
3078 @@ -3667,41 +3668,64 @@ void ext4_set_inode_flags(struct inode *
3079  {
3080         unsigned int flags = EXT4_I(inode)->i_flags;
3081  
3082 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3083 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3084 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3085 +
3086 +       if (flags & EXT4_IMMUTABLE_FL)
3087 +               inode->i_flags |= S_IMMUTABLE;
3088 +       if (flags & EXT4_IXUNLINK_FL)
3089 +               inode->i_flags |= S_IXUNLINK;
3090 +
3091         if (flags & EXT4_SYNC_FL)
3092                 inode->i_flags |= S_SYNC;
3093         if (flags & EXT4_APPEND_FL)
3094                 inode->i_flags |= S_APPEND;
3095 -       if (flags & EXT4_IMMUTABLE_FL)
3096 -               inode->i_flags |= S_IMMUTABLE;
3097         if (flags & EXT4_NOATIME_FL)
3098                 inode->i_flags |= S_NOATIME;
3099         if (flags & EXT4_DIRSYNC_FL)
3100                 inode->i_flags |= S_DIRSYNC;
3101 +
3102 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3103 +
3104 +       if (flags & EXT4_BARRIER_FL)
3105 +               inode->i_vflags |= V_BARRIER;
3106 +       if (flags & EXT4_COW_FL)
3107 +               inode->i_vflags |= V_COW;
3108  }
3109  
3110  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3111  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3112  {
3113 -       unsigned int vfs_fl;
3114 +       unsigned int vfs_fl, vfs_vf;
3115         unsigned long old_fl, new_fl;
3116  
3117         do {
3118                 vfs_fl = ei->vfs_inode.i_flags;
3119 +               vfs_vf = ei->vfs_inode.i_vflags;
3120                 old_fl = ei->i_flags;
3121                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3122                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3123 -                               EXT4_DIRSYNC_FL);
3124 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3125 +                               EXT4_COW_FL);
3126 +
3127 +               if (vfs_fl & S_IMMUTABLE)
3128 +                       new_fl |= EXT4_IMMUTABLE_FL;
3129 +               if (vfs_fl & S_IXUNLINK)
3130 +                       new_fl |= EXT4_IXUNLINK_FL;
3131 +
3132                 if (vfs_fl & S_SYNC)
3133                         new_fl |= EXT4_SYNC_FL;
3134                 if (vfs_fl & S_APPEND)
3135                         new_fl |= EXT4_APPEND_FL;
3136 -               if (vfs_fl & S_IMMUTABLE)
3137 -                       new_fl |= EXT4_IMMUTABLE_FL;
3138                 if (vfs_fl & S_NOATIME)
3139                         new_fl |= EXT4_NOATIME_FL;
3140                 if (vfs_fl & S_DIRSYNC)
3141                         new_fl |= EXT4_DIRSYNC_FL;
3142 +
3143 +               if (vfs_vf & V_BARRIER)
3144 +                       new_fl |= EXT4_BARRIER_FL;
3145 +               if (vfs_vf & V_COW)
3146 +                       new_fl |= EXT4_COW_FL;
3147         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3148  }
3149  
3150 @@ -3737,6 +3761,8 @@ struct inode *ext4_iget(struct super_blo
3151         journal_t *journal = EXT4_SB(sb)->s_journal;
3152         long ret;
3153         int block;
3154 +       uid_t uid;
3155 +       gid_t gid;
3156  
3157         inode = iget_locked(sb, ino);
3158         if (!inode)
3159 @@ -3752,12 +3778,16 @@ struct inode *ext4_iget(struct super_blo
3160                 goto bad_inode;
3161         raw_inode = ext4_raw_inode(&iloc);
3162         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3163 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3164 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3165 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3166 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3167         if (!(test_opt(inode->i_sb, NO_UID32))) {
3168 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3169 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3170 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3171 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3172         }
3173 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3174 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3175 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3176 +               le16_to_cpu(raw_inode->i_raw_tag));
3177         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3178  
3179         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3180 @@ -3976,6 +4006,8 @@ static int ext4_do_update_inode(handle_t
3181         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3182         struct ext4_inode_info *ei = EXT4_I(inode);
3183         struct buffer_head *bh = iloc->bh;
3184 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3185 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3186         int err = 0, rc, block;
3187  
3188         /* For fields not not tracking in the in-memory inode,
3189 @@ -3986,29 +4018,32 @@ static int ext4_do_update_inode(handle_t
3190         ext4_get_inode_flags(ei);
3191         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3192         if (!(test_opt(inode->i_sb, NO_UID32))) {
3193 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3194 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3195 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3196 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3197  /*
3198   * Fix up interoperability with old kernels. Otherwise, old inodes get
3199   * re-used with the upper 16 bits of the uid/gid intact
3200   */
3201                 if (!ei->i_dtime) {
3202                         raw_inode->i_uid_high =
3203 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3204 +                               cpu_to_le16(high_16_bits(uid));
3205                         raw_inode->i_gid_high =
3206 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3207 +                               cpu_to_le16(high_16_bits(gid));
3208                 } else {
3209                         raw_inode->i_uid_high = 0;
3210                         raw_inode->i_gid_high = 0;
3211                 }
3212         } else {
3213                 raw_inode->i_uid_low =
3214 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3215 +                       cpu_to_le16(fs_high2lowuid(uid));
3216                 raw_inode->i_gid_low =
3217 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3218 +                       cpu_to_le16(fs_high2lowgid(gid));
3219                 raw_inode->i_uid_high = 0;
3220                 raw_inode->i_gid_high = 0;
3221         }
3222 +#ifdef CONFIG_TAGGING_INTERN
3223 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3224 +#endif
3225         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3226  
3227         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3228 @@ -4194,7 +4229,8 @@ int ext4_setattr(struct dentry *dentry, 
3229         if (is_quota_modification(inode, attr))
3230                 dquot_initialize(inode);
3231         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3232 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3233 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3234 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3235                 handle_t *handle;
3236  
3237                 /* (user+group)*(old+new) structure, inode write (sb,
3238 @@ -4216,6 +4252,8 @@ int ext4_setattr(struct dentry *dentry, 
3239                         inode->i_uid = attr->ia_uid;
3240                 if (attr->ia_valid & ATTR_GID)
3241                         inode->i_gid = attr->ia_gid;
3242 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3243 +                       inode->i_tag = attr->ia_tag;
3244                 error = ext4_mark_inode_dirty(handle, inode);
3245                 ext4_journal_stop(handle);
3246         }
3247 diff -NurpP --minimal linux-3.2.8/fs/ext4/ioctl.c linux-3.2.8-vs2.3.2.7/fs/ext4/ioctl.c
3248 --- linux-3.2.8/fs/ext4/ioctl.c 2012-02-28 05:53:29.000000000 +0100
3249 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/ioctl.c       2012-01-26 08:52:10.000000000 +0100
3250 @@ -14,10 +14,39 @@
3251  #include <linux/compat.h>
3252  #include <linux/mount.h>
3253  #include <linux/file.h>
3254 +#include <linux/vs_tag.h>
3255  #include <asm/uaccess.h>
3256  #include "ext4_jbd2.h"
3257  #include "ext4.h"
3258  
3259 +
3260 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3261 +{
3262 +       handle_t *handle = NULL;
3263 +       struct ext4_iloc iloc;
3264 +       int err;
3265 +
3266 +       handle = ext4_journal_start(inode, 1);
3267 +       if (IS_ERR(handle))
3268 +               return PTR_ERR(handle);
3269 +
3270 +       if (IS_SYNC(inode))
3271 +               ext4_handle_sync(handle);
3272 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3273 +       if (err)
3274 +               goto flags_err;
3275 +
3276 +       inode->i_flags = flags;
3277 +       inode->i_vflags = vflags;
3278 +       ext4_get_inode_flags(EXT4_I(inode));
3279 +       inode->i_ctime = ext4_current_time(inode);
3280 +
3281 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3282 +flags_err:
3283 +       ext4_journal_stop(handle);
3284 +       return err;
3285 +}
3286 +
3287  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3288  {
3289         struct inode *inode = filp->f_dentry->d_inode;
3290 @@ -51,6 +80,11 @@ long ext4_ioctl(struct file *filp, unsig
3291  
3292                 flags = ext4_mask_flags(inode->i_mode, flags);
3293  
3294 +               if (IS_BARRIER(inode)) {
3295 +                       vxwprintk_task(1, "messing with the barrier.");
3296 +                       return -EACCES;
3297 +               }
3298 +
3299                 err = -EPERM;
3300                 mutex_lock(&inode->i_mutex);
3301                 /* Is it quota file? Do not allow user to mess with it */
3302 @@ -68,7 +102,9 @@ long ext4_ioctl(struct file *filp, unsig
3303                  *
3304                  * This test looks nicer. Thanks to Pauline Middelink
3305                  */
3306 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3307 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3308 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3309 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3310                         if (!capable(CAP_LINUX_IMMUTABLE))
3311                                 goto flags_out;
3312                 }
3313 diff -NurpP --minimal linux-3.2.8/fs/ext4/namei.c linux-3.2.8-vs2.3.2.7/fs/ext4/namei.c
3314 --- linux-3.2.8/fs/ext4/namei.c 2012-01-09 16:14:54.000000000 +0100
3315 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/namei.c       2011-12-05 19:33:02.000000000 +0100
3316 @@ -34,6 +34,7 @@
3317  #include <linux/quotaops.h>
3318  #include <linux/buffer_head.h>
3319  #include <linux/bio.h>
3320 +#include <linux/vs_tag.h>
3321  #include "ext4.h"
3322  #include "ext4_jbd2.h"
3323  
3324 @@ -925,6 +926,7 @@ restart:
3325                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3326                                                     1, &bh);
3327                         }
3328 +               dx_propagate_tag(nd, inode);
3329                 }
3330                 if ((bh = bh_use[ra_ptr++]) == NULL)
3331                         goto next;
3332 @@ -2587,6 +2589,7 @@ const struct inode_operations ext4_dir_i
3333  #endif
3334         .get_acl        = ext4_get_acl,
3335         .fiemap         = ext4_fiemap,
3336 +       .sync_flags     = ext4_sync_flags,
3337  };
3338  
3339  const struct inode_operations ext4_special_inode_operations = {
3340 diff -NurpP --minimal linux-3.2.8/fs/ext4/super.c linux-3.2.8-vs2.3.2.7/fs/ext4/super.c
3341 --- linux-3.2.8/fs/ext4/super.c 2012-02-28 05:53:29.000000000 +0100
3342 +++ linux-3.2.8-vs2.3.2.7/fs/ext4/super.c       2012-01-26 08:52:10.000000000 +0100
3343 @@ -1334,6 +1334,7 @@ enum {
3344         Opt_inode_readahead_blks, Opt_journal_ioprio,
3345         Opt_dioread_nolock, Opt_dioread_lock,
3346         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3347 +       Opt_tag, Opt_notag, Opt_tagid
3348  };
3349  
3350  static const match_table_t tokens = {
3351 @@ -1409,6 +1410,9 @@ static const match_table_t tokens = {
3352         {Opt_init_itable, "init_itable=%u"},
3353         {Opt_init_itable, "init_itable"},
3354         {Opt_noinit_itable, "noinit_itable"},
3355 +       {Opt_tag, "tag"},
3356 +       {Opt_notag, "notag"},
3357 +       {Opt_tagid, "tagid=%u"},
3358         {Opt_err, NULL},
3359  };
3360  
3361 @@ -1577,6 +1581,20 @@ static int parse_options(char *options, 
3362                 case Opt_nouid32:
3363                         set_opt(sb, NO_UID32);
3364                         break;
3365 +#ifndef CONFIG_TAGGING_NONE
3366 +               case Opt_tag:
3367 +                       set_opt(sb, TAGGED);
3368 +                       break;
3369 +               case Opt_notag:
3370 +                       clear_opt(sb, TAGGED);
3371 +                       break;
3372 +#endif
3373 +#ifdef CONFIG_PROPAGATE
3374 +               case Opt_tagid:
3375 +                       /* use args[0] */
3376 +                       set_opt(sb, TAGGED);
3377 +                       break;
3378 +#endif
3379                 case Opt_debug:
3380                         set_opt(sb, DEBUG);
3381                         break;
3382 @@ -3278,6 +3296,9 @@ static int ext4_fill_super(struct super_
3383                 }
3384         }
3385  
3386 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3387 +               sb->s_flags |= MS_TAGGED;
3388 +
3389         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3390                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3391  
3392 @@ -4427,6 +4448,14 @@ static int ext4_remount(struct super_blo
3393         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3394                 ext4_abort(sb, "Abort forced by user");
3395  
3396 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3397 +               !(sb->s_flags & MS_TAGGED)) {
3398 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3399 +                       sb->s_id);
3400 +               err = -EINVAL;
3401 +               goto restore_opts;
3402 +       }
3403 +
3404         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3405                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3406  
3407 diff -NurpP --minimal linux-3.2.8/fs/fcntl.c linux-3.2.8-vs2.3.2.7/fs/fcntl.c
3408 --- linux-3.2.8/fs/fcntl.c      2011-05-22 16:17:52.000000000 +0200
3409 +++ linux-3.2.8-vs2.3.2.7/fs/fcntl.c    2011-12-05 19:33:02.000000000 +0100
3410 @@ -20,6 +20,7 @@
3411  #include <linux/signal.h>
3412  #include <linux/rcupdate.h>
3413  #include <linux/pid_namespace.h>
3414 +#include <linux/vs_limit.h>
3415  
3416  #include <asm/poll.h>
3417  #include <asm/siginfo.h>
3418 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3419  
3420         if (tofree)
3421                 filp_close(tofree, files);
3422 +       else
3423 +               vx_openfd_inc(newfd);   /* fd was unused */
3424  
3425         return newfd;
3426  
3427 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3428         filp = fget_raw(fd);
3429         if (!filp)
3430                 goto out;
3431 +       if (!vx_files_avail(1))
3432 +               goto out;
3433  
3434         if (unlikely(filp->f_mode & FMODE_PATH)) {
3435                 if (!check_fcntl_cmd(cmd)) {
3436 diff -NurpP --minimal linux-3.2.8/fs/file.c linux-3.2.8-vs2.3.2.7/fs/file.c
3437 --- linux-3.2.8/fs/file.c       2011-05-22 16:17:52.000000000 +0200
3438 +++ linux-3.2.8-vs2.3.2.7/fs/file.c     2011-12-05 19:33:02.000000000 +0100
3439 @@ -21,6 +21,7 @@
3440  #include <linux/spinlock.h>
3441  #include <linux/rcupdate.h>
3442  #include <linux/workqueue.h>
3443 +#include <linux/vs_limit.h>
3444  
3445  struct fdtable_defer {
3446         spinlock_t lock;
3447 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
3448                 struct file *f = *old_fds++;
3449                 if (f) {
3450                         get_file(f);
3451 +                       /* TODO: sum it first for check and performance */
3452 +                       vx_openfd_inc(open_files - i);
3453                 } else {
3454                         /*
3455                          * The fd may be claimed in the fd bitmap but not yet
3456 @@ -466,6 +469,7 @@ repeat:
3457         else
3458                 FD_CLR(fd, fdt->close_on_exec);
3459         error = fd;
3460 +       vx_openfd_inc(fd);
3461  #if 1
3462         /* Sanity check */
3463         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3464 diff -NurpP --minimal linux-3.2.8/fs/file_table.c linux-3.2.8-vs2.3.2.7/fs/file_table.c
3465 --- linux-3.2.8/fs/file_table.c 2011-10-24 18:45:27.000000000 +0200
3466 +++ linux-3.2.8-vs2.3.2.7/fs/file_table.c       2011-12-05 19:33:02.000000000 +0100
3467 @@ -24,6 +24,8 @@
3468  #include <linux/percpu_counter.h>
3469  #include <linux/percpu.h>
3470  #include <linux/ima.h>
3471 +#include <linux/vs_limit.h>
3472 +#include <linux/vs_context.h>
3473  
3474  #include <linux/atomic.h>
3475  
3476 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3477         spin_lock_init(&f->f_lock);
3478         eventpoll_init_file(f);
3479         /* f->f_version: 0 */
3480 +       f->f_xid = vx_current_xid();
3481 +       vx_files_inc(f);
3482         return f;
3483  
3484  over:
3485 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
3486         }
3487         fops_put(file->f_op);
3488         put_pid(file->f_owner.pid);
3489 +       vx_files_dec(file);
3490 +       file->f_xid = 0;
3491         file_sb_list_del(file);
3492         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3493                 i_readcount_dec(inode);
3494 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
3495  {
3496         if (atomic_long_dec_and_test(&file->f_count)) {
3497                 security_file_free(file);
3498 +               vx_files_dec(file);
3499 +               file->f_xid = 0;
3500                 file_sb_list_del(file);
3501                 file_free(file);
3502         }
3503 diff -NurpP --minimal linux-3.2.8/fs/fs_struct.c linux-3.2.8-vs2.3.2.7/fs/fs_struct.c
3504 --- linux-3.2.8/fs/fs_struct.c  2011-03-15 18:07:31.000000000 +0100
3505 +++ linux-3.2.8-vs2.3.2.7/fs/fs_struct.c        2011-12-05 19:33:02.000000000 +0100
3506 @@ -4,6 +4,7 @@
3507  #include <linux/path.h>
3508  #include <linux/slab.h>
3509  #include <linux/fs_struct.h>
3510 +#include <linux/vserver/global.h>
3511  #include "internal.h"
3512  
3513  static inline void path_get_longterm(struct path *path)
3514 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
3515  {
3516         path_put_longterm(&fs->root);
3517         path_put_longterm(&fs->pwd);
3518 +       atomic_dec(&vs_global_fs);
3519         kmem_cache_free(fs_cachep, fs);
3520  }
3521  
3522 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
3523                 fs->pwd = old->pwd;
3524                 path_get_longterm(&fs->pwd);
3525                 spin_unlock(&old->lock);
3526 +               atomic_inc(&vs_global_fs);
3527         }
3528         return fs;
3529  }
3530 diff -NurpP --minimal linux-3.2.8/fs/gfs2/file.c linux-3.2.8-vs2.3.2.7/fs/gfs2/file.c
3531 --- linux-3.2.8/fs/gfs2/file.c  2012-01-09 16:14:54.000000000 +0100
3532 +++ linux-3.2.8-vs2.3.2.7/fs/gfs2/file.c        2011-12-05 19:33:02.000000000 +0100
3533 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3534         [7] = GFS2_DIF_NOATIME,
3535         [12] = GFS2_DIF_EXHASH,
3536         [14] = GFS2_DIF_INHERIT_JDATA,
3537 +       [27] = GFS2_DIF_IXUNLINK,
3538 +       [26] = GFS2_DIF_BARRIER,
3539 +       [29] = GFS2_DIF_COW,
3540  };
3541  
3542  static const u32 gfs2_to_fsflags[32] = {
3543 @@ -152,6 +155,9 @@ static const u32 gfs2_to_fsflags[32] = {
3544         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3545         [gfs2fl_ExHash] = FS_INDEX_FL,
3546         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3547 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3548 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3549 +       [gfs2fl_Cow] = FS_COW_FL,
3550  };
3551  
3552  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3553 @@ -182,12 +188,18 @@ void gfs2_set_inode_flags(struct inode *
3554  {
3555         struct gfs2_inode *ip = GFS2_I(inode);
3556         unsigned int flags = inode->i_flags;
3557 +       unsigned int vflags = inode->i_vflags;
3558 +
3559 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3560 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3561  
3562 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3563         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3564                 inode->i_flags |= S_NOSEC;
3565         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3566                 flags |= S_IMMUTABLE;
3567 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3568 +               flags |= S_IXUNLINK;
3569 +
3570         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3571                 flags |= S_APPEND;
3572         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3573 @@ -195,6 +207,43 @@ void gfs2_set_inode_flags(struct inode *
3574         if (ip->i_diskflags & GFS2_DIF_SYNC)
3575                 flags |= S_SYNC;
3576         inode->i_flags = flags;
3577 +
3578 +       vflags &= ~(V_BARRIER | V_COW);
3579 +
3580 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3581 +               vflags |= V_BARRIER;
3582 +       if (ip->i_diskflags & GFS2_DIF_COW)
3583 +               vflags |= V_COW;
3584 +       inode->i_vflags = vflags;
3585 +}
3586 +
3587 +void gfs2_get_inode_flags(struct inode *inode)
3588 +{
3589 +       struct gfs2_inode *ip = GFS2_I(inode);
3590 +       unsigned int flags = inode->i_flags;
3591 +       unsigned int vflags = inode->i_vflags;
3592 +
3593 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3594 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3595 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3596 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3597 +
3598 +       if (flags & S_IMMUTABLE)
3599 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3600 +       if (flags & S_IXUNLINK)
3601 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3602 +
3603 +       if (flags & S_APPEND)
3604 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3605 +       if (flags & S_NOATIME)
3606 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3607 +       if (flags & S_SYNC)
3608 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3609 +
3610 +       if (vflags & V_BARRIER)
3611 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3612 +       if (vflags & V_COW)
3613 +               ip->i_diskflags |= GFS2_DIF_COW;
3614  }
3615  
3616  /* Flags that can be set by user space */
3617 @@ -306,6 +355,37 @@ static int gfs2_set_flags(struct file *f
3618         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3619  }
3620  
3621 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3622 +{
3623 +       struct gfs2_inode *ip = GFS2_I(inode);
3624 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3625 +       struct buffer_head *bh;
3626 +       struct gfs2_holder gh;
3627 +       int error;
3628 +
3629 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3630 +       if (error)
3631 +               return error;
3632 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3633 +       if (error)
3634 +               goto out;
3635 +       error = gfs2_meta_inode_buffer(ip, &bh);
3636 +       if (error)
3637 +               goto out_trans_end;
3638 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3639 +       inode->i_flags = flags;
3640 +       inode->i_vflags = vflags;
3641 +       gfs2_get_inode_flags(inode);
3642 +       gfs2_dinode_out(ip, bh->b_data);
3643 +       brelse(bh);
3644 +       gfs2_set_aops(inode);
3645 +out_trans_end:
3646 +       gfs2_trans_end(sdp);
3647 +out:
3648 +       gfs2_glock_dq_uninit(&gh);
3649 +       return error;
3650 +}
3651 +
3652  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3653  {
3654         switch(cmd) {
3655 diff -NurpP --minimal linux-3.2.8/fs/gfs2/inode.h linux-3.2.8-vs2.3.2.7/fs/gfs2/inode.h
3656 --- linux-3.2.8/fs/gfs2/inode.h 2012-01-09 16:14:54.000000000 +0100
3657 +++ linux-3.2.8-vs2.3.2.7/fs/gfs2/inode.h       2011-12-05 19:33:02.000000000 +0100
3658 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3659  extern const struct file_operations gfs2_dir_fops_nolock;
3660  
3661  extern void gfs2_set_inode_flags(struct inode *inode);
3662 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3663   
3664  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3665  extern const struct file_operations gfs2_file_fops;
3666 diff -NurpP --minimal linux-3.2.8/fs/inode.c linux-3.2.8-vs2.3.2.7/fs/inode.c
3667 --- linux-3.2.8/fs/inode.c      2012-01-09 16:14:54.000000000 +0100
3668 +++ linux-3.2.8-vs2.3.2.7/fs/inode.c    2011-12-05 19:33:02.000000000 +0100
3669 @@ -26,6 +26,7 @@
3670  #include <linux/ima.h>
3671  #include <linux/cred.h>
3672  #include <linux/buffer_head.h> /* for inode_has_buffers */
3673 +#include <linux/vs_tag.h>
3674  #include "internal.h"
3675  
3676  /*
3677 @@ -137,6 +138,9 @@ int inode_init_always(struct super_block
3678         struct address_space *const mapping = &inode->i_data;
3679  
3680         inode->i_sb = sb;
3681 +
3682 +       /* essential because of inode slab reuse */
3683 +       inode->i_tag = 0;
3684         inode->i_blkbits = sb->s_blocksize_bits;
3685         inode->i_flags = 0;
3686         atomic_set(&inode->i_count, 1);
3687 @@ -158,6 +162,7 @@ int inode_init_always(struct super_block
3688         inode->i_bdev = NULL;
3689         inode->i_cdev = NULL;
3690         inode->i_rdev = 0;
3691 +       inode->i_mdev = 0;
3692         inode->dirtied_when = 0;
3693  
3694         if (security_inode_alloc(inode))
3695 @@ -399,6 +404,8 @@ void __insert_inode_hash(struct inode *i
3696  }
3697  EXPORT_SYMBOL(__insert_inode_hash);
3698  
3699 +EXPORT_SYMBOL_GPL(__iget);
3700 +
3701  /**
3702   *     __remove_inode_hash - remove an inode from the hash
3703   *     @inode: inode to unhash
3704 @@ -1626,9 +1633,11 @@ void init_special_inode(struct inode *in
3705         if (S_ISCHR(mode)) {
3706                 inode->i_fop = &def_chr_fops;
3707                 inode->i_rdev = rdev;
3708 +               inode->i_mdev = rdev;
3709         } else if (S_ISBLK(mode)) {
3710                 inode->i_fop = &def_blk_fops;
3711                 inode->i_rdev = rdev;
3712 +               inode->i_mdev = rdev;
3713         } else if (S_ISFIFO(mode))
3714                 inode->i_fop = &def_fifo_fops;
3715         else if (S_ISSOCK(mode))
3716 @@ -1657,6 +1666,7 @@ void inode_init_owner(struct inode *inod
3717         } else
3718                 inode->i_gid = current_fsgid();
3719         inode->i_mode = mode;
3720 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3721  }
3722  EXPORT_SYMBOL(inode_init_owner);
3723  
3724 diff -NurpP --minimal linux-3.2.8/fs/ioctl.c linux-3.2.8-vs2.3.2.7/fs/ioctl.c
3725 --- linux-3.2.8/fs/ioctl.c      2011-05-22 16:17:52.000000000 +0200
3726 +++ linux-3.2.8-vs2.3.2.7/fs/ioctl.c    2011-12-05 19:33:02.000000000 +0100
3727 @@ -15,6 +15,9 @@
3728  #include <linux/writeback.h>
3729  #include <linux/buffer_head.h>
3730  #include <linux/falloc.h>
3731 +#include <linux/proc_fs.h>
3732 +#include <linux/vserver/inode.h>
3733 +#include <linux/vs_tag.h>
3734  
3735  #include <asm/ioctls.h>
3736  
3737 diff -NurpP --minimal linux-3.2.8/fs/ioprio.c linux-3.2.8-vs2.3.2.7/fs/ioprio.c
3738 --- linux-3.2.8/fs/ioprio.c     2012-01-09 16:14:54.000000000 +0100
3739 +++ linux-3.2.8-vs2.3.2.7/fs/ioprio.c   2011-12-05 19:33:02.000000000 +0100
3740 @@ -28,6 +28,7 @@
3741  #include <linux/syscalls.h>
3742  #include <linux/security.h>
3743  #include <linux/pid_namespace.h>
3744 +#include <linux/vs_base.h>
3745  
3746  int set_task_ioprio(struct task_struct *task, int ioprio)
3747  {
3748 @@ -120,6 +121,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3749                         else
3750                                 pgrp = find_vpid(who);
3751                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3752 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3753 +                                       continue;
3754                                 ret = set_task_ioprio(p, ioprio);
3755                                 if (ret)
3756                                         break;
3757 @@ -209,6 +212,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3758                         else
3759                                 pgrp = find_vpid(who);
3760                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3761 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3762 +                                       continue;
3763                                 tmpio = get_task_ioprio(p);
3764                                 if (tmpio < 0)
3765                                         continue;
3766 diff -NurpP --minimal linux-3.2.8/fs/jfs/file.c linux-3.2.8-vs2.3.2.7/fs/jfs/file.c
3767 --- linux-3.2.8/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3768 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/file.c 2011-12-05 19:33:02.000000000 +0100
3769 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3770         if (is_quota_modification(inode, iattr))
3771                 dquot_initialize(inode);
3772         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3773 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3774 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3775 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3776                 rc = dquot_transfer(inode, iattr);
3777                 if (rc)
3778                         return rc;
3779 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3780  #ifdef CONFIG_JFS_POSIX_ACL
3781         .get_acl        = jfs_get_acl,
3782  #endif
3783 +       .sync_flags     = jfs_sync_flags,
3784  };
3785  
3786  const struct file_operations jfs_file_operations = {
3787 diff -NurpP --minimal linux-3.2.8/fs/jfs/ioctl.c linux-3.2.8-vs2.3.2.7/fs/jfs/ioctl.c
3788 --- linux-3.2.8/fs/jfs/ioctl.c  2011-05-22 16:17:52.000000000 +0200
3789 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/ioctl.c        2011-12-05 19:33:02.000000000 +0100
3790 @@ -11,6 +11,7 @@
3791  #include <linux/mount.h>
3792  #include <linux/time.h>
3793  #include <linux/sched.h>
3794 +#include <linux/mount.h>
3795  #include <asm/current.h>
3796  #include <asm/uaccess.h>
3797  
3798 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3799  }
3800  
3801  
3802 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3803 +{
3804 +       inode->i_flags = flags;
3805 +       inode->i_vflags = vflags;
3806 +       jfs_get_inode_flags(JFS_IP(inode));
3807 +       inode->i_ctime = CURRENT_TIME_SEC;
3808 +       mark_inode_dirty(inode);
3809 +       return 0;
3810 +}
3811 +
3812  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3813  {
3814         struct inode *inode = filp->f_dentry->d_inode;
3815 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3816                 if (!S_ISDIR(inode->i_mode))
3817                         flags &= ~JFS_DIRSYNC_FL;
3818  
3819 +               if (IS_BARRIER(inode)) {
3820 +                       vxwprintk_task(1, "messing with the barrier.");
3821 +                       return -EACCES;
3822 +               }
3823 +
3824                 /* Is it quota file? Do not allow user to mess with it */
3825                 if (IS_NOQUOTA(inode)) {
3826                         err = -EPERM;
3827 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3828                  * the relevant capability.
3829                  */
3830                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3831 -                       ((flags ^ oldflags) &
3832 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3833 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3834 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3835                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3836                                 mutex_unlock(&inode->i_mutex);
3837                                 err = -EPERM;
3838 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3839                         }
3840                 }
3841  
3842 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3843 +               flags &= JFS_FL_USER_MODIFIABLE;
3844                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3845                 jfs_inode->mode2 = flags;
3846  
3847 diff -NurpP --minimal linux-3.2.8/fs/jfs/jfs_dinode.h linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_dinode.h
3848 --- linux-3.2.8/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3849 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_dinode.h   2011-12-05 19:33:02.000000000 +0100
3850 @@ -161,9 +161,13 @@ struct dinode {
3851  
3852  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3853  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3854 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3855  
3856 -#define JFS_FL_USER_VISIBLE    0x03F80000
3857 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3858 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3859 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3860 +
3861 +#define JFS_FL_USER_VISIBLE    0x07F80000
3862 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3863  #define JFS_FL_INHERIT         0x03C80000
3864  
3865  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3866 diff -NurpP --minimal linux-3.2.8/fs/jfs/jfs_filsys.h linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_filsys.h
3867 --- linux-3.2.8/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3868 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_filsys.h   2011-12-05 19:33:02.000000000 +0100
3869 @@ -263,6 +263,7 @@
3870  #define JFS_NAME_MAX   255
3871  #define JFS_PATH_MAX   BPSIZE
3872  
3873 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3874  
3875  /*
3876   *     file system state (superblock state)
3877 diff -NurpP --minimal linux-3.2.8/fs/jfs/jfs_imap.c linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_imap.c
3878 --- linux-3.2.8/fs/jfs/jfs_imap.c       2012-01-09 16:14:54.000000000 +0100
3879 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_imap.c     2011-12-05 19:33:02.000000000 +0100
3880 @@ -46,6 +46,7 @@
3881  #include <linux/pagemap.h>
3882  #include <linux/quotaops.h>
3883  #include <linux/slab.h>
3884 +#include <linux/vs_tag.h>
3885  
3886  #include "jfs_incore.h"
3887  #include "jfs_inode.h"
3888 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3889  {
3890         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3891         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3892 +       uid_t uid;
3893 +       gid_t gid;
3894  
3895         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3896         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3897 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3898         }
3899         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3900  
3901 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3902 +       uid = le32_to_cpu(dip->di_uid);
3903 +       gid = le32_to_cpu(dip->di_gid);
3904 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3905 +
3906 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3907         if (sbi->uid == -1)
3908                 ip->i_uid = jfs_ip->saved_uid;
3909         else {
3910                 ip->i_uid = sbi->uid;
3911         }
3912  
3913 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3914 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3915         if (sbi->gid == -1)
3916                 ip->i_gid = jfs_ip->saved_gid;
3917         else {
3918 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3919         dip->di_size = cpu_to_le64(ip->i_size);
3920         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3921         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3922 -       if (sbi->uid == -1)
3923 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3924 -       else
3925 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3926 -       if (sbi->gid == -1)
3927 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3928 -       else
3929 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3930 +
3931 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3932 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3933 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3934 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3935 +
3936         jfs_get_inode_flags(jfs_ip);
3937         /*
3938          * mode2 is only needed for storing the higher order bits.
3939 diff -NurpP --minimal linux-3.2.8/fs/jfs/jfs_inode.c linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_inode.c
3940 --- linux-3.2.8/fs/jfs/jfs_inode.c      2012-01-09 16:14:54.000000000 +0100
3941 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_inode.c    2011-12-05 19:33:02.000000000 +0100
3942 @@ -18,6 +18,7 @@
3943  
3944  #include <linux/fs.h>
3945  #include <linux/quotaops.h>
3946 +#include <linux/vs_tag.h>
3947  #include "jfs_incore.h"
3948  #include "jfs_inode.h"
3949  #include "jfs_filsys.h"
3950 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3951  {
3952         unsigned int flags = JFS_IP(inode)->mode2;
3953  
3954 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3955 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3956 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3957 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3958  
3959         if (flags & JFS_IMMUTABLE_FL)
3960                 inode->i_flags |= S_IMMUTABLE;
3961 +       if (flags & JFS_IXUNLINK_FL)
3962 +               inode->i_flags |= S_IXUNLINK;
3963 +
3964 +       if (flags & JFS_SYNC_FL)
3965 +               inode->i_flags |= S_SYNC;
3966         if (flags & JFS_APPEND_FL)
3967                 inode->i_flags |= S_APPEND;
3968         if (flags & JFS_NOATIME_FL)
3969                 inode->i_flags |= S_NOATIME;
3970         if (flags & JFS_DIRSYNC_FL)
3971                 inode->i_flags |= S_DIRSYNC;
3972 -       if (flags & JFS_SYNC_FL)
3973 -               inode->i_flags |= S_SYNC;
3974 +
3975 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3976 +
3977 +       if (flags & JFS_BARRIER_FL)
3978 +               inode->i_vflags |= V_BARRIER;
3979 +       if (flags & JFS_COW_FL)
3980 +               inode->i_vflags |= V_COW;
3981  }
3982  
3983  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3984  {
3985         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3986 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3987 +
3988 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3989 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3990 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3991 +                          JFS_BARRIER_FL | JFS_COW_FL);
3992  
3993 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3994 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3995         if (flags & S_IMMUTABLE)
3996                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3997 +       if (flags & S_IXUNLINK)
3998 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3999 +
4000         if (flags & S_APPEND)
4001                 jfs_ip->mode2 |= JFS_APPEND_FL;
4002         if (flags & S_NOATIME)
4003 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4004                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4005         if (flags & S_SYNC)
4006                 jfs_ip->mode2 |= JFS_SYNC_FL;
4007 +
4008 +       if (vflags & V_BARRIER)
4009 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4010 +       if (vflags & V_COW)
4011 +               jfs_ip->mode2 |= JFS_COW_FL;
4012  }
4013  
4014  /*
4015 diff -NurpP --minimal linux-3.2.8/fs/jfs/jfs_inode.h linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_inode.h
4016 --- linux-3.2.8/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
4017 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/jfs_inode.h    2011-12-05 19:33:02.000000000 +0100
4018 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4019  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4020         int fh_len, int fh_type);
4021  extern void jfs_set_inode_flags(struct inode *);
4022 +extern int jfs_sync_flags(struct inode *, int, int);
4023  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4024  extern int jfs_setattr(struct dentry *, struct iattr *);
4025  
4026 diff -NurpP --minimal linux-3.2.8/fs/jfs/namei.c linux-3.2.8-vs2.3.2.7/fs/jfs/namei.c
4027 --- linux-3.2.8/fs/jfs/namei.c  2012-01-09 16:14:54.000000000 +0100
4028 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/namei.c        2011-12-05 19:33:02.000000000 +0100
4029 @@ -22,6 +22,7 @@
4030  #include <linux/ctype.h>
4031  #include <linux/quotaops.h>
4032  #include <linux/exportfs.h>
4033 +#include <linux/vs_tag.h>
4034  #include "jfs_incore.h"
4035  #include "jfs_superblock.h"
4036  #include "jfs_inode.h"
4037 @@ -1474,6 +1475,7 @@ static struct dentry *jfs_lookup(struct 
4038                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4039         }
4040  
4041 +       dx_propagate_tag(nd, ip);
4042         return d_splice_alias(ip, dentry);
4043  }
4044  
4045 @@ -1538,6 +1540,7 @@ const struct inode_operations jfs_dir_in
4046  #ifdef CONFIG_JFS_POSIX_ACL
4047         .get_acl        = jfs_get_acl,
4048  #endif
4049 +       .sync_flags     = jfs_sync_flags,
4050  };
4051  
4052  const struct file_operations jfs_dir_operations = {
4053 diff -NurpP --minimal linux-3.2.8/fs/jfs/super.c linux-3.2.8-vs2.3.2.7/fs/jfs/super.c
4054 --- linux-3.2.8/fs/jfs/super.c  2012-01-09 16:14:54.000000000 +0100
4055 +++ linux-3.2.8-vs2.3.2.7/fs/jfs/super.c        2011-12-05 19:33:02.000000000 +0100
4056 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4057  enum {
4058         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4059         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4060 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4061 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4062 +       Opt_tag, Opt_notag, Opt_tagid
4063  };
4064  
4065  static const match_table_t tokens = {
4066 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4067         {Opt_resize, "resize=%u"},
4068         {Opt_resize_nosize, "resize"},
4069         {Opt_errors, "errors=%s"},
4070 +       {Opt_tag, "tag"},
4071 +       {Opt_notag, "notag"},
4072 +       {Opt_tagid, "tagid=%u"},
4073 +       {Opt_tag, "tagxid"},
4074         {Opt_ignore, "noquota"},
4075         {Opt_ignore, "quota"},
4076         {Opt_usrquota, "usrquota"},
4077 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4078                         }
4079                         break;
4080                 }
4081 +#ifndef CONFIG_TAGGING_NONE
4082 +               case Opt_tag:
4083 +                       *flag |= JFS_TAGGED;
4084 +                       break;
4085 +               case Opt_notag:
4086 +                       *flag &= JFS_TAGGED;
4087 +                       break;
4088 +#endif
4089 +#ifdef CONFIG_PROPAGATE
4090 +               case Opt_tagid:
4091 +                       /* use args[0] */
4092 +                       *flag |= JFS_TAGGED;
4093 +                       break;
4094 +#endif
4095                 default:
4096                         printk("jfs: Unrecognized mount option \"%s\" "
4097                                         " or missing value\n", p);
4098 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4099                 return -EINVAL;
4100         }
4101  
4102 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4103 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4104 +                       sb->s_id);
4105 +               return -EINVAL;
4106 +       }
4107 +
4108         if (newLVSize) {
4109                 if (sb->s_flags & MS_RDONLY) {
4110                         printk(KERN_ERR
4111 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4112  #ifdef CONFIG_JFS_POSIX_ACL
4113         sb->s_flags |= MS_POSIXACL;
4114  #endif
4115 +       /* map mount option tagxid */
4116 +       if (sbi->flag & JFS_TAGGED)
4117 +               sb->s_flags |= MS_TAGGED;
4118  
4119         if (newLVSize) {
4120                 printk(KERN_ERR "resize option for remount only\n");
4121 diff -NurpP --minimal linux-3.2.8/fs/libfs.c linux-3.2.8-vs2.3.2.7/fs/libfs.c
4122 --- linux-3.2.8/fs/libfs.c      2012-01-09 16:14:54.000000000 +0100
4123 +++ linux-3.2.8-vs2.3.2.7/fs/libfs.c    2011-12-05 19:33:02.000000000 +0100
4124 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4125   * both impossible due to the lock on directory.
4126   */
4127  
4128 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4129 +static inline int do_dcache_readdir_filter(struct file *filp,
4130 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4131  {
4132         struct dentry *dentry = filp->f_path.dentry;
4133         struct dentry *cursor = filp->private_data;
4134 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4135                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4136                                 struct dentry *next;
4137                                 next = list_entry(p, struct dentry, d_u.d_child);
4138 +                               if (filter && !filter(next))
4139 +                                       continue;
4140                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4141                                 if (!simple_positive(next)) {
4142                                         spin_unlock(&next->d_lock);
4143 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4144         return 0;
4145  }
4146  
4147 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4148 +{
4149 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4150 +}
4151 +
4152 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4153 +       int (*filter)(struct dentry *))
4154 +{
4155 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4156 +}
4157 +
4158  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4159  {
4160         return -EISDIR;
4161 @@ -977,6 +991,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4162  EXPORT_SYMBOL(dcache_dir_lseek);
4163  EXPORT_SYMBOL(dcache_dir_open);
4164  EXPORT_SYMBOL(dcache_readdir);
4165 +EXPORT_SYMBOL(dcache_readdir_filter);
4166  EXPORT_SYMBOL(generic_read_dir);
4167  EXPORT_SYMBOL(mount_pseudo);
4168  EXPORT_SYMBOL(simple_write_begin);
4169 diff -NurpP --minimal linux-3.2.8/fs/locks.c linux-3.2.8-vs2.3.2.7/fs/locks.c
4170 --- linux-3.2.8/fs/locks.c      2012-01-09 16:14:54.000000000 +0100
4171 +++ linux-3.2.8-vs2.3.2.7/fs/locks.c    2012-01-09 16:19:31.000000000 +0100
4172 @@ -126,6 +126,8 @@
4173  #include <linux/time.h>
4174  #include <linux/rcupdate.h>
4175  #include <linux/pid_namespace.h>
4176 +#include <linux/vs_base.h>
4177 +#include <linux/vs_limit.h>
4178  
4179  #include <asm/uaccess.h>
4180  
4181 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4182  /* Allocate an empty lock structure. */
4183  struct file_lock *locks_alloc_lock(void)
4184  {
4185 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4186 +       struct file_lock *fl;
4187  
4188 -       if (fl)
4189 -               locks_init_lock_heads(fl);
4190 +       if (!vx_locks_avail(1))
4191 +               return NULL;
4192  
4193 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4194 +
4195 +       if (fl) {
4196 +               locks_init_lock_heads(fl);
4197 +               fl->fl_xid = -1;
4198 +       }
4199         return fl;
4200  }
4201  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4202 @@ -216,6 +224,7 @@ void locks_free_lock(struct file_lock *f
4203         BUG_ON(!list_empty(&fl->fl_block));
4204         BUG_ON(!list_empty(&fl->fl_link));
4205  
4206 +       vx_locks_dec(fl);
4207         locks_release_private(fl);
4208         kmem_cache_free(filelock_cache, fl);
4209  }
4210 @@ -225,6 +234,7 @@ void locks_init_lock(struct file_lock *f
4211  {
4212         memset(fl, 0, sizeof(struct file_lock));
4213         locks_init_lock_heads(fl);
4214 +       fl->fl_xid = -1;
4215  }
4216  
4217  EXPORT_SYMBOL(locks_init_lock);
4218 @@ -265,6 +275,7 @@ void locks_copy_lock(struct file_lock *n
4219         new->fl_file = fl->fl_file;
4220         new->fl_ops = fl->fl_ops;
4221         new->fl_lmops = fl->fl_lmops;
4222 +       new->fl_xid = fl->fl_xid;
4223  
4224         locks_copy_private(new, fl);
4225  }
4226 @@ -303,6 +314,11 @@ static int flock_make_lock(struct file *
4227         fl->fl_flags = FL_FLOCK;
4228         fl->fl_type = type;
4229         fl->fl_end = OFFSET_MAX;
4230 +
4231 +       vxd_assert(filp->f_xid == vx_current_xid(),
4232 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4233 +       fl->fl_xid = filp->f_xid;
4234 +       vx_locks_inc(fl);
4235         
4236         *lock = fl;
4237         return 0;
4238 @@ -452,6 +468,7 @@ static int lease_init(struct file *filp,
4239  
4240         fl->fl_owner = current->files;
4241         fl->fl_pid = current->tgid;
4242 +       fl->fl_xid = vx_current_xid();
4243  
4244         fl->fl_file = filp;
4245         fl->fl_flags = FL_LEASE;
4246 @@ -471,6 +488,11 @@ static struct file_lock *lease_alloc(str
4247         if (fl == NULL)
4248                 return ERR_PTR(error);
4249  
4250 +       fl->fl_xid = vx_current_xid();
4251 +       if (filp)
4252 +               vxd_assert(filp->f_xid == fl->fl_xid,
4253 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4254 +       vx_locks_inc(fl);
4255         error = lease_init(filp, type, fl);
4256         if (error) {
4257                 locks_free_lock(fl);
4258 @@ -772,6 +794,7 @@ static int flock_lock_file(struct file *
4259                 lock_flocks();
4260         }
4261  
4262 +       new_fl->fl_xid = -1;
4263  find_conflict:
4264         for_each_lock(inode, before) {
4265                 struct file_lock *fl = *before;
4266 @@ -792,6 +815,7 @@ find_conflict:
4267                 goto out;
4268         locks_copy_lock(new_fl, request);
4269         locks_insert_lock(before, new_fl);
4270 +       vx_locks_inc(new_fl);
4271         new_fl = NULL;
4272         error = 0;
4273  
4274 @@ -802,7 +826,8 @@ out:
4275         return error;
4276  }
4277  
4278 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4279 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4280 +       struct file_lock *conflock, xid_t xid)
4281  {
4282         struct file_lock *fl;
4283         struct file_lock *new_fl = NULL;
4284 @@ -812,6 +837,8 @@ static int __posix_lock_file(struct inod
4285         struct file_lock **before;
4286         int error, added = 0;
4287  
4288 +       vxd_assert(xid == vx_current_xid(),
4289 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4290         /*
4291          * We may need two file_lock structures for this operation,
4292          * so we get them in advance to avoid races.
4293 @@ -822,7 +849,11 @@ static int __posix_lock_file(struct inod
4294             (request->fl_type != F_UNLCK ||
4295              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4296                 new_fl = locks_alloc_lock();
4297 +               new_fl->fl_xid = xid;
4298 +               vx_locks_inc(new_fl);
4299                 new_fl2 = locks_alloc_lock();
4300 +               new_fl2->fl_xid = xid;
4301 +               vx_locks_inc(new_fl2);
4302         }
4303  
4304         lock_flocks();
4305 @@ -1021,7 +1052,8 @@ static int __posix_lock_file(struct inod
4306  int posix_lock_file(struct file *filp, struct file_lock *fl,
4307                         struct file_lock *conflock)
4308  {
4309 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4310 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4311 +               fl, conflock, filp->f_xid);
4312  }
4313  EXPORT_SYMBOL(posix_lock_file);
4314  
4315 @@ -1111,7 +1143,7 @@ int locks_mandatory_area(int read_write,
4316         fl.fl_end = offset + count - 1;
4317  
4318         for (;;) {
4319 -               error = __posix_lock_file(inode, &fl, NULL);
4320 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4321                 if (error != FILE_LOCK_DEFERRED)
4322                         break;
4323                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4324 @@ -1406,6 +1438,7 @@ int generic_add_lease(struct file *filp,
4325                 goto out;
4326  
4327         locks_insert_lock(before, lease);
4328 +       vx_locks_inc(lease);
4329         return 0;
4330  
4331  out:
4332 @@ -1846,6 +1879,11 @@ int fcntl_setlk(unsigned int fd, struct 
4333         if (file_lock == NULL)
4334                 return -ENOLCK;
4335  
4336 +       vxd_assert(filp->f_xid == vx_current_xid(),
4337 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4338 +       file_lock->fl_xid = filp->f_xid;
4339 +       vx_locks_inc(file_lock);
4340 +
4341         /*
4342          * This might block, so we do it before checking the inode.
4343          */
4344 @@ -1964,6 +2002,11 @@ int fcntl_setlk64(unsigned int fd, struc
4345         if (file_lock == NULL)
4346                 return -ENOLCK;
4347  
4348 +       vxd_assert(filp->f_xid == vx_current_xid(),
4349 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4350 +       file_lock->fl_xid = filp->f_xid;
4351 +       vx_locks_inc(file_lock);
4352 +
4353         /*
4354          * This might block, so we do it before checking the inode.
4355          */
4356 @@ -2229,8 +2272,11 @@ static int locks_show(struct seq_file *f
4357  
4358         lock_get_status(f, fl, *((loff_t *)f->private), "");
4359  
4360 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4361 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4362 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4363 +                       continue;
4364                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4365 +       }
4366  
4367         return 0;
4368  }
4369 diff -NurpP --minimal linux-3.2.8/fs/namei.c linux-3.2.8-vs2.3.2.7/fs/namei.c
4370 --- linux-3.2.8/fs/namei.c      2012-01-09 16:14:54.000000000 +0100
4371 +++ linux-3.2.8-vs2.3.2.7/fs/namei.c    2011-12-05 19:33:02.000000000 +0100
4372 @@ -33,6 +33,14 @@
4373  #include <linux/device_cgroup.h>
4374  #include <linux/fs_struct.h>
4375  #include <linux/posix_acl.h>
4376 +#include <linux/proc_fs.h>
4377 +#include <linux/vserver/inode.h>
4378 +#include <linux/vs_base.h>
4379 +#include <linux/vs_tag.h>
4380 +#include <linux/vs_cowbl.h>
4381 +#include <linux/vs_device.h>
4382 +#include <linux/vs_context.h>
4383 +#include <linux/pid_namespace.h>
4384  #include <asm/uaccess.h>
4385  
4386  #include "internal.h"
4387 @@ -222,6 +230,89 @@ static int check_acl(struct inode *inode
4388         return -EAGAIN;
4389  }
4390  
4391 +static inline int dx_barrier(const struct inode *inode)
4392 +{
4393 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4394 +               vxwprintk_task(1, "did hit the barrier.");
4395 +               return 1;
4396 +       }
4397 +       return 0;
4398 +}
4399 +
4400 +static int __dx_permission(const struct inode *inode, int mask)
4401 +{
4402 +       if (dx_barrier(inode))
4403 +               return -EACCES;
4404 +
4405 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4406 +               /* devpts is xid tagged */
4407 +               if (S_ISDIR(inode->i_mode) ||
4408 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4409 +                       return 0;
4410 +
4411 +               /* just pretend we didn't find anything */
4412 +               return -ENOENT;
4413 +       }
4414 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4415 +               struct proc_dir_entry *de = PDE(inode);
4416 +
4417 +               if (de && !vx_hide_check(0, de->vx_flags))
4418 +                       goto out;
4419 +
4420 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4421 +                       struct pid *pid;
4422 +                       struct task_struct *tsk;
4423 +
4424 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4425 +                           vx_flags(VXF_STATE_SETUP, 0))
4426 +                               return 0;
4427 +
4428 +                       pid = PROC_I(inode)->pid;
4429 +                       if (!pid)
4430 +                               goto out;
4431 +
4432 +                       rcu_read_lock();
4433 +                       tsk = pid_task(pid, PIDTYPE_PID);
4434 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4435 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4436 +                       if (tsk &&
4437 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4438 +                               rcu_read_unlock();
4439 +                               return 0;
4440 +                       }
4441 +                       rcu_read_unlock();
4442 +               }
4443 +               else {
4444 +                       /* FIXME: Should we block some entries here? */
4445 +                       return 0;
4446 +               }
4447 +       }
4448 +       else {
4449 +               if (dx_notagcheck(inode->i_sb) ||
4450 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4451 +                            DX_IDENT))
4452 +                       return 0;
4453 +       }
4454 +
4455 +out:
4456 +       return -EACCES;
4457 +}
4458 +
4459 +int dx_permission(const struct inode *inode, int mask)
4460 +{
4461 +       int ret = __dx_permission(inode, mask);
4462 +       if (unlikely(ret)) {
4463 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4464 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4465 +#endif
4466 +                   vxwprintk_task(1,
4467 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4468 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4469 +                       inode->i_ino);
4470 +       }
4471 +       return ret;
4472 +}
4473 +
4474  /*
4475   * This does the basic permission checking
4476   */
4477 @@ -357,10 +448,14 @@ int inode_permission(struct inode *inode
4478                 /*
4479                  * Nobody gets write access to an immutable file.
4480                  */
4481 -               if (IS_IMMUTABLE(inode))
4482 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4483                         return -EACCES;
4484         }
4485  
4486 +       retval = dx_permission(inode, mask);
4487 +       if (retval)
4488 +               return retval;
4489 +
4490         retval = do_inode_permission(inode, mask);
4491         if (retval)
4492                 return retval;
4493 @@ -1037,7 +1132,8 @@ static void follow_dotdot(struct nameida
4494  
4495                 if (nd->path.dentry == nd->root.dentry &&
4496                     nd->path.mnt == nd->root.mnt) {
4497 -                       break;
4498 +                       /* for sane '/' avoid follow_mount() */
4499 +                       return;
4500                 }
4501                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4502                         /* rare case of legitimate dget_parent()... */
4503 @@ -1146,6 +1242,9 @@ static int do_lookup(struct nameidata *n
4504                 }
4505                 if (unlikely(d_need_lookup(dentry)))
4506                         goto unlazy;
4507 +
4508 +               /* FIXME: check dx permission */
4509 +
4510                 path->mnt = mnt;
4511                 path->dentry = dentry;
4512                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4513 @@ -1207,6 +1306,8 @@ retry:
4514                 }
4515         }
4516  
4517 +       /* FIXME: check dx permission */
4518 +
4519         path->mnt = mnt;
4520         path->dentry = dentry;
4521         err = follow_managed(path, nd->flags);
4522 @@ -1901,7 +2002,7 @@ static int may_delete(struct inode *dir,
4523         if (IS_APPEND(dir))
4524                 return -EPERM;
4525         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4526 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4527 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4528                 return -EPERM;
4529         if (isdir) {
4530                 if (!S_ISDIR(victim->d_inode->i_mode))
4531 @@ -1981,19 +2082,25 @@ int vfs_create(struct inode *dir, struct
4532  {
4533         int error = may_create(dir, dentry);
4534  
4535 -       if (error)
4536 +       if (error) {
4537 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4538                 return error;
4539 +       }
4540  
4541         if (!dir->i_op->create)
4542                 return -EACCES; /* shouldn't it be ENOSYS? */
4543         mode &= S_IALLUGO;
4544         mode |= S_IFREG;
4545         error = security_inode_create(dir, dentry, mode);
4546 -       if (error)
4547 +       if (error) {
4548 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4549                 return error;
4550 +       }
4551         error = dir->i_op->create(dir, dentry, mode, nd);
4552         if (!error)
4553                 fsnotify_create(dir, dentry);
4554 +       else
4555 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4556         return error;
4557  }
4558  
4559 @@ -2028,6 +2135,15 @@ static int may_open(struct path *path, i
4560                 break;
4561         }
4562  
4563 +#ifdef CONFIG_VSERVER_COWBL
4564 +       if (IS_COW(inode) &&
4565 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4566 +               if (IS_COW_LINK(inode))
4567 +                       return -EMLINK;
4568 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4569 +               mark_inode_dirty(inode);
4570 +       }
4571 +#endif
4572         error = inode_permission(inode, acc_mode);
4573         if (error)
4574                 return error;
4575 @@ -2252,6 +2368,16 @@ ok:
4576         }
4577  common:
4578         error = may_open(&nd->path, acc_mode, open_flag);
4579 +#ifdef CONFIG_VSERVER_COWBL
4580 +       if (error == -EMLINK) {
4581 +               struct dentry *dentry;
4582 +               dentry = cow_break_link(pathname);
4583 +               if (IS_ERR(dentry))
4584 +                       error = PTR_ERR(dentry);
4585 +               else
4586 +                       dput(dentry);
4587 +       }
4588 +#endif
4589         if (error)
4590                 goto exit;
4591         filp = nameidata_to_filp(nd);
4592 @@ -2294,6 +2420,7 @@ static struct file *path_openat(int dfd,
4593         struct path path;
4594         int error;
4595  
4596 +restart:
4597         filp = get_empty_filp();
4598         if (!filp)
4599                 return ERR_PTR(-ENFILE);
4600 @@ -2331,6 +2458,17 @@ static struct file *path_openat(int dfd,
4601                         filp = do_last(nd, &path, op, pathname);
4602                 put_link(nd, &link, cookie);
4603         }
4604 +
4605 +#ifdef CONFIG_VSERVER_COWBL
4606 +       if (filp == ERR_PTR(-EMLINK)) {
4607 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4608 +                       path_put(&nd->root);
4609 +               if (base)
4610 +                       fput(base);
4611 +               release_open_intent(nd);
4612 +               goto restart;
4613 +       }
4614 +#endif
4615  out:
4616         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4617                 path_put(&nd->root);
4618 @@ -2420,6 +2558,11 @@ struct dentry *kern_path_create(int dfd,
4619                 goto fail;
4620         }
4621         *path = nd.path;
4622 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4623 +               path->dentry, path->dentry->d_name.len,
4624 +               path->dentry->d_name.name, dentry,
4625 +               dentry->d_name.len, dentry->d_name.name,
4626 +               path->dentry->d_inode);
4627         return dentry;
4628  eexist:
4629         dput(dentry);
4630 @@ -2901,7 +3044,7 @@ int vfs_link(struct dentry *old_dentry, 
4631         /*
4632          * A link to an append-only or immutable file cannot be created.
4633          */
4634 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4635 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4636                 return -EPERM;
4637         if (!dir->i_op->link)
4638                 return -EPERM;
4639 @@ -3282,6 +3425,227 @@ int vfs_follow_link(struct nameidata *nd
4640         return __vfs_follow_link(nd, link);
4641  }
4642  
4643 +
4644 +#ifdef CONFIG_VSERVER_COWBL
4645 +
4646 +static inline
4647 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4648 +{
4649 +       loff_t ppos = 0;
4650 +
4651 +       return do_splice_direct(in, &ppos, out, len, 0);
4652 +}
4653 +
4654 +struct dentry *cow_break_link(const char *pathname)
4655 +{
4656 +       int ret, mode, pathlen, redo = 0;
4657 +       struct nameidata old_nd, dir_nd;
4658 +       struct path old_path, dir_path;
4659 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4660 +       struct file *old_file;
4661 +       struct file *new_file;
4662 +       char *to, *path, pad='\251';
4663 +       loff_t size;
4664 +
4665 +       vxdprintk(VXD_CBIT(misc, 1),
4666 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4667 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4668 +       ret = -ENOMEM;
4669 +       if (!path)
4670 +               goto out;
4671 +
4672 +       /* old_nd will have refs to dentry and mnt */
4673 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4674 +       vxdprintk(VXD_CBIT(misc, 2),
4675 +               "do_path_lookup(old): %d [r=%d]",
4676 +               ret, mnt_get_count(old_nd.path.mnt));
4677 +       if (ret < 0)
4678 +               goto out_free_path;
4679 +
4680 +       old_path = old_nd.path;
4681 +       old_dentry = old_path.dentry;
4682 +       mode = old_dentry->d_inode->i_mode;
4683 +
4684 +       to = d_path(&old_path, path, PATH_MAX-2);
4685 +       pathlen = strlen(to);
4686 +       vxdprintk(VXD_CBIT(misc, 2),
4687 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4688 +               old_dentry,
4689 +               old_dentry->d_name.len, old_dentry->d_name.name,
4690 +               old_dentry->d_name.len);
4691 +
4692 +       to[pathlen + 1] = 0;
4693 +retry:
4694 +       new_dentry = NULL;
4695 +       to[pathlen] = pad--;
4696 +       ret = -ELOOP;
4697 +       if (pad <= '\240')
4698 +               goto out_rel_old;
4699 +
4700 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4701 +       /* dir_nd will have refs to dentry and mnt */
4702 +       ret = do_path_lookup(AT_FDCWD, to,
4703 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4704 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4705 +       if (ret < 0)
4706 +               goto retry;
4707 +
4708 +       /* this puppy downs the dir inode mutex if successful */
4709 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4710 +       if (!new_dentry || IS_ERR(new_dentry)) {
4711 +               path_put(&dir_nd.path);
4712 +               vxdprintk(VXD_CBIT(misc, 2),
4713 +                       "kern_path_create(new) failed with %ld",
4714 +                       PTR_ERR(new_dentry));
4715 +               goto retry;
4716 +       }
4717 +       path_put(&dir_path);
4718 +       vxdprintk(VXD_CBIT(misc, 2),
4719 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4720 +               new_dentry,
4721 +               new_dentry->d_name.len, new_dentry->d_name.name,
4722 +               new_dentry->d_name.len);
4723 +
4724 +       dir = dir_nd.path.dentry;
4725 +
4726 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4727 +       vxdprintk(VXD_CBIT(misc, 2),
4728 +               "vfs_create(new): %d", ret);
4729 +       if (ret == -EEXIST) {
4730 +               mutex_unlock(&dir->d_inode->i_mutex);
4731 +               path_put(&dir_nd.path);
4732 +               dput(new_dentry);
4733 +               goto retry;
4734 +       }
4735 +       else if (ret < 0)
4736 +               goto out_unlock_new;
4737 +
4738 +       /* drop out early, ret passes ENOENT */
4739 +       ret = -ENOENT;
4740 +       if ((redo = d_unhashed(old_dentry)))
4741 +               goto out_unlock_new;
4742 +
4743 +       path_get(&old_path);
4744 +       /* this one cleans up the dentry/mnt in case of failure */
4745 +       old_file = dentry_open(old_dentry, old_path.mnt,
4746 +               O_RDONLY, current_cred());
4747 +       vxdprintk(VXD_CBIT(misc, 2),
4748 +               "dentry_open(old): %p", old_file);
4749 +       if (IS_ERR(old_file)) {
4750 +               ret = PTR_ERR(old_file);
4751 +               goto out_unlock_new;
4752 +       }
4753 +
4754 +       dget(new_dentry);
4755 +       mntget(old_path.mnt);
4756 +       /* this one cleans up the dentry/mnt in case of failure */
4757 +       new_file = dentry_open(new_dentry, old_path.mnt,
4758 +               O_WRONLY, current_cred());
4759 +       vxdprintk(VXD_CBIT(misc, 2),
4760 +               "dentry_open(new): %p", new_file);
4761 +       if (IS_ERR(new_file)) {
4762 +               ret = PTR_ERR(new_file);
4763 +               goto out_fput_old;
4764 +       }
4765 +
4766 +       size = i_size_read(old_file->f_dentry->d_inode);
4767 +       ret = do_cow_splice(old_file, new_file, size);
4768 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4769 +       if (ret < 0) {
4770 +               goto out_fput_both;
4771 +       } else if (ret < size) {
4772 +               ret = -ENOSPC;
4773 +               goto out_fput_both;
4774 +       } else {
4775 +               struct inode *old_inode = old_dentry->d_inode;
4776 +               struct inode *new_inode = new_dentry->d_inode;
4777 +               struct iattr attr = {
4778 +                       .ia_uid = old_inode->i_uid,
4779 +                       .ia_gid = old_inode->i_gid,
4780 +                       .ia_valid = ATTR_UID | ATTR_GID
4781 +                       };
4782 +
4783 +               setattr_copy(new_inode, &attr);
4784 +               mark_inode_dirty(new_inode);
4785 +       }
4786 +
4787 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4788 +
4789 +       /* drop out late */
4790 +       ret = -ENOENT;
4791 +       if ((redo = d_unhashed(old_dentry)))
4792 +               goto out_unlock;
4793 +
4794 +       vxdprintk(VXD_CBIT(misc, 2),
4795 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4796 +               new_dentry->d_name.len, new_dentry->d_name.name,
4797 +               new_dentry->d_name.len,
4798 +               old_dentry->d_name.len, old_dentry->d_name.name,
4799 +               old_dentry->d_name.len);
4800 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4801 +               old_dentry->d_parent->d_inode, old_dentry);
4802 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4803 +
4804 +out_unlock:
4805 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4806 +
4807 +out_fput_both:
4808 +       vxdprintk(VXD_CBIT(misc, 3),
4809 +               "fput(new_file=%p[#%ld])", new_file,
4810 +               atomic_long_read(&new_file->f_count));
4811 +       fput(new_file);
4812 +
4813 +out_fput_old:
4814 +       vxdprintk(VXD_CBIT(misc, 3),
4815 +               "fput(old_file=%p[#%ld])", old_file,
4816 +               atomic_long_read(&old_file->f_count));
4817 +       fput(old_file);
4818 +
4819 +out_unlock_new:
4820 +       mutex_unlock(&dir->d_inode->i_mutex);
4821 +       if (!ret)
4822 +               goto out_redo;
4823 +
4824 +       /* error path cleanup */
4825 +       vfs_unlink(dir->d_inode, new_dentry);
4826 +
4827 +out_redo:
4828 +       if (!redo)
4829 +               goto out_rel_both;
4830 +       /* lookup dentry once again */
4831 +       /* old_nd.path is freed as old_path in out_rel_old */
4832 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4833 +       if (ret)
4834 +               goto out_rel_both;
4835 +
4836 +       dput(new_dentry);
4837 +       new_dentry = old_nd.path.dentry;
4838 +       vxdprintk(VXD_CBIT(misc, 2),
4839 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4840 +               new_dentry,
4841 +               new_dentry->d_name.len, new_dentry->d_name.name,
4842 +               new_dentry->d_name.len);
4843 +       dget(new_dentry);
4844 +
4845 +out_rel_both:
4846 +       path_put(&dir_nd.path);
4847 +out_rel_old:
4848 +       path_put(&old_path);
4849 +out_free_path:
4850 +       kfree(path);
4851 +out:
4852 +       if (ret) {
4853 +               dput(new_dentry);
4854 +               new_dentry = ERR_PTR(ret);
4855 +       }
4856 +       vxdprintk(VXD_CBIT(misc, 3),
4857 +               "cow_break_link returning with %p [r=%d]",
4858 +               new_dentry, mnt_get_count(old_nd.path.mnt));
4859 +       return new_dentry;
4860 +}
4861 +
4862 +#endif
4863 +
4864  /* get the link contents into pagecache */
4865  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4866  {
4867 diff -NurpP --minimal linux-3.2.8/fs/namespace.c linux-3.2.8-vs2.3.2.7/fs/namespace.c
4868 --- linux-3.2.8/fs/namespace.c  2012-01-09 16:14:54.000000000 +0100
4869 +++ linux-3.2.8-vs2.3.2.7/fs/namespace.c        2011-12-15 01:11:32.000000000 +0100
4870 @@ -31,6 +31,11 @@
4871  #include <linux/idr.h>
4872  #include <linux/fs_struct.h>
4873  #include <linux/fsnotify.h>
4874 +#include <linux/vs_base.h>
4875 +#include <linux/vs_context.h>
4876 +#include <linux/vs_tag.h>
4877 +#include <linux/vserver/space.h>
4878 +#include <linux/vserver/global.h>
4879  #include <asm/uaccess.h>
4880  #include <asm/unistd.h>
4881  #include "pnode.h"
4882 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
4883         if (!type)
4884                 return ERR_PTR(-ENODEV);
4885  
4886 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4887 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4888 +               return ERR_PTR(-EPERM);
4889 +
4890         mnt = alloc_vfsmnt(name);
4891         if (!mnt)
4892                 return ERR_PTR(-ENOMEM);
4893 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
4894                 mnt->mnt_root = dget(root);
4895                 mnt->mnt_mountpoint = mnt->mnt_root;
4896                 mnt->mnt_parent = mnt;
4897 +               mnt->mnt_tag = old->mnt_tag;
4898  
4899                 if (flag & CL_SLAVE) {
4900                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
4901 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
4902         seq_escape(m, s, " \t\n\\");
4903  }
4904  
4905 +static int mnt_is_reachable(struct vfsmount *mnt)
4906 +{
4907 +       struct path root;
4908 +       struct dentry *point;
4909 +       int ret;
4910 +
4911 +       if (mnt == mnt->mnt_ns->root)
4912 +               return 1;
4913 +
4914 +       br_read_lock(vfsmount_lock);
4915 +       root = current->fs->root;
4916 +       point = root.dentry;
4917 +
4918 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
4919 +               point = mnt->mnt_mountpoint;
4920 +               mnt = mnt->mnt_parent;
4921 +       }
4922 +
4923 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
4924 +
4925 +       br_read_unlock(vfsmount_lock);
4926 +
4927 +       return ret;
4928 +}
4929 +
4930  /*
4931   * Simple .show_options callback for filesystems which don't want to
4932   * implement more complex mount option showing.
4933 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
4934                 { MS_SYNCHRONOUS, ",sync" },
4935                 { MS_DIRSYNC, ",dirsync" },
4936                 { MS_MANDLOCK, ",mand" },
4937 +               { MS_TAGGED, ",tag" },
4938 +               { MS_NOTAGCHECK, ",notagcheck" },
4939                 { 0, NULL }
4940         };
4941         const struct proc_fs_info *fs_infop;
4942 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
4943         int err = 0;
4944         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
4945  
4946 -       if (mnt->mnt_sb->s_op->show_devname) {
4947 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4948 -               if (err)
4949 -                       goto out;
4950 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4951 +               return SEQ_SKIP;
4952 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4953 +               return SEQ_SKIP;
4954 +
4955 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
4956 +               mnt == current->fs->root.mnt) {
4957 +               seq_puts(m, "/dev/root / ");
4958         } else {
4959 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
4960 +               if (mnt->mnt_sb->s_op->show_devname) {
4961 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4962 +                       if (err)
4963 +                               goto out;
4964 +               } else {
4965 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
4966 +               }
4967 +               seq_putc(m, ' ');
4968 +               seq_path(m, &mnt_path, " \t\n\\");
4969 +               seq_putc(m, ' ');
4970         }
4971 -       seq_putc(m, ' ');
4972 -       seq_path(m, &mnt_path, " \t\n\\");
4973 -       seq_putc(m, ' ');
4974         show_type(m, mnt->mnt_sb);
4975         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
4976         err = show_sb_opts(m, mnt->mnt_sb);
4977 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
4978         struct path root = p->root;
4979         int err = 0;
4980  
4981 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4982 +               return SEQ_SKIP;
4983 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4984 +               return SEQ_SKIP;
4985 +
4986         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
4987                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
4988         if (sb->s_op->show_path)
4989 @@ -1104,22 +1156,32 @@ static int show_vfsstat(struct seq_file 
4990         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
4991         int err = 0;
4992  
4993 -       /* device */
4994 -       if (mnt->mnt_sb->s_op->show_devname) {
4995 -               seq_puts(m, "device ");
4996 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4997 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4998 +               return SEQ_SKIP;
4999 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5000 +               return SEQ_SKIP;
5001 +
5002 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5003 +               mnt == current->fs->root.mnt) {
5004 +               seq_puts(m, "device /dev/root mounted on / ");
5005         } else {
5006 -               if (mnt->mnt_devname) {
5007 +               /* device */
5008 +               if (mnt->mnt_sb->s_op->show_devname) {
5009                         seq_puts(m, "device ");
5010 -                       mangle(m, mnt->mnt_devname);
5011 -               } else
5012 -                       seq_puts(m, "no device");
5013 -       }
5014 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5015 +               } else {
5016 +                       if (mnt->mnt_devname) {
5017 +                               seq_puts(m, "device ");
5018 +                               mangle(m, mnt->mnt_devname);
5019 +                       } else
5020 +                               seq_puts(m, "no device");
5021 +               }
5022  
5023 -       /* mount point */
5024 -       seq_puts(m, " mounted on ");
5025 -       seq_path(m, &mnt_path, " \t\n\\");
5026 -       seq_putc(m, ' ');
5027 +               /* mount point */
5028 +               seq_puts(m, " mounted on ");
5029 +               seq_path(m, &mnt_path, " \t\n\\");
5030 +               seq_putc(m, ' ');
5031 +       }
5032  
5033         /* file system type */
5034         seq_puts(m, "with fstype ");
5035 @@ -1378,7 +1440,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5036                 goto dput_and_out;
5037  
5038         retval = -EPERM;
5039 -       if (!capable(CAP_SYS_ADMIN))
5040 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5041                 goto dput_and_out;
5042  
5043         retval = do_umount(path.mnt, flags);
5044 @@ -1404,7 +1466,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5045  
5046  static int mount_is_safe(struct path *path)
5047  {
5048 -       if (capable(CAP_SYS_ADMIN))
5049 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5050                 return 0;
5051         return -EPERM;
5052  #ifdef notyet
5053 @@ -1714,7 +1776,7 @@ static int do_change_type(struct path *p
5054         int type;
5055         int err = 0;
5056  
5057 -       if (!capable(CAP_SYS_ADMIN))
5058 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5059                 return -EPERM;
5060  
5061         if (path->dentry != path->mnt->mnt_root)
5062 @@ -1730,6 +1792,7 @@ static int do_change_type(struct path *p
5063                 if (err)
5064                         goto out_unlock;
5065         }
5066 +       // mnt->mnt_flags = mnt_flags;
5067  
5068         br_write_lock(vfsmount_lock);
5069         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5070 @@ -1745,12 +1808,14 @@ static int do_change_type(struct path *p
5071   * do loopback mount.
5072   */
5073  static int do_loopback(struct path *path, char *old_name,
5074 -                               int recurse)
5075 +       tag_t tag, unsigned long flags, int mnt_flags)
5076  {
5077         LIST_HEAD(umount_list);
5078         struct path old_path;
5079         struct vfsmount *mnt = NULL;
5080         int err = mount_is_safe(path);
5081 +       int recurse = flags & MS_REC;
5082 +
5083         if (err)
5084                 return err;
5085         if (!old_name || !*old_name)
5086 @@ -1816,12 +1881,12 @@ static int change_mount_flags(struct vfs
5087   * on it - tough luck.
5088   */
5089  static int do_remount(struct path *path, int flags, int mnt_flags,
5090 -                     void *data)
5091 +       void *data, xid_t xid)
5092  {
5093         int err;
5094         struct super_block *sb = path->mnt->mnt_sb;
5095  
5096 -       if (!capable(CAP_SYS_ADMIN))
5097 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5098                 return -EPERM;
5099  
5100         if (!check_mnt(path->mnt))
5101 @@ -1869,7 +1934,7 @@ static int do_move_mount(struct path *pa
5102         struct path old_path, parent_path;
5103         struct vfsmount *p;
5104         int err = 0;
5105 -       if (!capable(CAP_SYS_ADMIN))
5106 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5107                 return -EPERM;
5108         if (!old_name || !*old_name)
5109                 return -EINVAL;
5110 @@ -2020,7 +2085,7 @@ static int do_new_mount(struct path *pat
5111                 return -EINVAL;
5112  
5113         /* we need capabilities... */
5114 -       if (!capable(CAP_SYS_ADMIN))
5115 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5116                 return -EPERM;
5117  
5118         mnt = do_kern_mount(type, flags, name, data);
5119 @@ -2289,6 +2354,7 @@ long do_mount(char *dev_name, char *dir_
5120         struct path path;
5121         int retval = 0;
5122         int mnt_flags = 0;
5123 +       tag_t tag = 0;
5124  
5125         /* Discard magic */
5126         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5127 @@ -2316,6 +2382,12 @@ long do_mount(char *dev_name, char *dir_
5128         if (!(flags & MS_NOATIME))
5129                 mnt_flags |= MNT_RELATIME;
5130  
5131 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5132 +               /* FIXME: bind and re-mounts get the tag flag? */
5133 +               if (flags & (MS_BIND|MS_REMOUNT))
5134 +                       flags |= MS_TAGID;
5135 +       }
5136 +
5137         /* Separate the per-mountpoint flags */
5138         if (flags & MS_NOSUID)
5139                 mnt_flags |= MNT_NOSUID;
5140 @@ -2332,15 +2404,17 @@ long do_mount(char *dev_name, char *dir_
5141         if (flags & MS_RDONLY)
5142                 mnt_flags |= MNT_READONLY;
5143  
5144 +       if (!capable(CAP_SYS_ADMIN))
5145 +               mnt_flags |= MNT_NODEV;
5146         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5147                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5148                    MS_STRICTATIME);
5149  
5150         if (flags & MS_REMOUNT)
5151                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5152 -                                   data_page);
5153 +                                   data_page, tag);
5154         else if (flags & MS_BIND)
5155 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5156 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5157         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5158                 retval = do_change_type(&path, flags);
5159         else if (flags & MS_MOVE)
5160 @@ -2440,6 +2514,7 @@ static struct mnt_namespace *dup_mnt_ns(
5161                 q = next_mnt(q, new_ns->root);
5162         }
5163         up_write(&namespace_sem);
5164 +       atomic_inc(&vs_global_mnt_ns);
5165  
5166         if (rootmnt)
5167                 mntput(rootmnt);
5168 @@ -2611,9 +2686,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5169                 goto out3;
5170  
5171         error = -EINVAL;
5172 -       if (IS_MNT_SHARED(old.mnt) ||
5173 +       if ((IS_MNT_SHARED(old.mnt) ||
5174                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5175 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5176 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5177 +               !vx_flags(VXF_STATE_SETUP, 0))
5178                 goto out4;
5179         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5180                 goto out4;
5181 @@ -2745,6 +2821,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5182         br_write_unlock(vfsmount_lock);
5183         up_write(&namespace_sem);
5184         release_mounts(&umount_list);
5185 +       atomic_dec(&vs_global_mnt_ns);
5186         kfree(ns);
5187  }
5188  EXPORT_SYMBOL(put_mnt_ns);
5189 diff -NurpP --minimal linux-3.2.8/fs/nfs/client.c linux-3.2.8-vs2.3.2.7/fs/nfs/client.c
5190 --- linux-3.2.8/fs/nfs/client.c 2012-01-09 16:14:54.000000000 +0100
5191 +++ linux-3.2.8-vs2.3.2.7/fs/nfs/client.c       2011-12-05 19:33:02.000000000 +0100
5192 @@ -779,6 +779,9 @@ static int nfs_init_server_rpcclient(str
5193         if (server->flags & NFS_MOUNT_SOFT)
5194                 server->client->cl_softrtry = 1;
5195  
5196 +       server->client->cl_tag = 0;
5197 +       if (server->flags & NFS_MOUNT_TAGGED)
5198 +               server->client->cl_tag = 1;
5199         return 0;
5200  }
5201  
5202 @@ -953,6 +956,10 @@ static void nfs_server_set_fsinfo(struct
5203                 server->acdirmin = server->acdirmax = 0;
5204         }
5205  
5206 +       /* FIXME: needs fsinfo
5207 +       if (server->flags & NFS_MOUNT_TAGGED)
5208 +               sb->s_flags |= MS_TAGGED;       */
5209 +
5210         server->maxfilesize = fsinfo->maxfilesize;
5211  
5212         server->time_delta = fsinfo->time_delta;
5213 diff -NurpP --minimal linux-3.2.8/fs/nfs/dir.c linux-3.2.8-vs2.3.2.7/fs/nfs/dir.c
5214 --- linux-3.2.8/fs/nfs/dir.c    2012-01-09 16:14:54.000000000 +0100
5215 +++ linux-3.2.8-vs2.3.2.7/fs/nfs/dir.c  2011-12-05 19:33:02.000000000 +0100
5216 @@ -35,6 +35,7 @@
5217  #include <linux/sched.h>
5218  #include <linux/kmemleak.h>
5219  #include <linux/xattr.h>
5220 +#include <linux/vs_tag.h>
5221  
5222  #include "delegation.h"
5223  #include "iostat.h"
5224 @@ -1311,6 +1312,7 @@ static struct dentry *nfs_lookup(struct 
5225         if (IS_ERR(res))
5226                 goto out_unblock_sillyrename;
5227  
5228 +       dx_propagate_tag(nd, inode);
5229  no_entry:
5230         res = d_materialise_unique(dentry, inode);
5231         if (res != NULL) {
5232 diff -NurpP --minimal linux-3.2.8/fs/nfs/inode.c linux-3.2.8-vs2.3.2.7/fs/nfs/inode.c
5233 --- linux-3.2.8/fs/nfs/inode.c  2012-01-09 16:14:54.000000000 +0100
5234 +++ linux-3.2.8-vs2.3.2.7/fs/nfs/inode.c        2011-12-05 21:16:35.000000000 +0100
5235 @@ -38,6 +38,7 @@
5236  #include <linux/nfs_xdr.h>
5237  #include <linux/slab.h>
5238  #include <linux/compat.h>
5239 +#include <linux/vs_tag.h>
5240  
5241  #include <asm/system.h>
5242  #include <asm/uaccess.h>
5243 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
5244         if (inode->i_state & I_NEW) {
5245                 struct nfs_inode *nfsi = NFS_I(inode);
5246                 unsigned long now = jiffies;
5247 +               uid_t uid;
5248 +               gid_t gid;
5249  
5250                 /* We set i_ino for the few things that still rely on it,
5251                  * such as stat(2) */
5252 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
5253                 inode->i_version = 0;
5254                 inode->i_size = 0;
5255                 clear_nlink(inode);
5256 -               inode->i_uid = -2;
5257 -               inode->i_gid = -2;
5258 +               uid = -2;
5259 +               gid = -2;
5260                 inode->i_blocks = 0;
5261                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5262  
5263 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
5264                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5265                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5266                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5267 -                       inode->i_uid = fattr->uid;
5268 +                       uid = fattr->uid;
5269                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5270                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5271                                 | NFS_INO_INVALID_ACCESS
5272                                 | NFS_INO_INVALID_ACL;
5273                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5274 -                       inode->i_gid = fattr->gid;
5275 +                       gid = fattr->gid;
5276                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5277                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5278                                 | NFS_INO_INVALID_ACCESS
5279 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
5280                          */
5281                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5282                 }
5283 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5284 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5285 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5286 +                               /* maybe fattr->xid someday */
5287 +
5288                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5289                 nfsi->attrtimeo_timestamp = now;
5290                 nfsi->access_cache = RB_ROOT;
5291 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5292                         inode->i_uid = attr->ia_uid;
5293                 if ((attr->ia_valid & ATTR_GID) != 0)
5294                         inode->i_gid = attr->ia_gid;
5295 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5296 +                       inode->i_tag = attr->ia_tag;
5297                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5298                 spin_unlock(&inode->i_lock);
5299         }
5300 @@ -943,6 +953,9 @@ static int nfs_check_inode_attributes(st
5301         struct nfs_inode *nfsi = NFS_I(inode);
5302         loff_t cur_size, new_isize;
5303         unsigned long invalid = 0;
5304 +       uid_t uid;
5305 +       gid_t gid;
5306 +       tag_t tag;
5307  
5308  
5309         /* Has the inode gone and changed behind our back? */
5310 @@ -966,13 +979,18 @@ static int nfs_check_inode_attributes(st
5311                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5312         }
5313  
5314 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5315 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5316 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5317 +
5318         /* Have any file permissions changed? */
5319         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5320                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5321 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5322 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5323                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5324 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5325 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5326                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5327 +               /* maybe check for tag too? */
5328  
5329         /* Has the link count changed? */
5330         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5331 @@ -1207,6 +1225,9 @@ static int nfs_update_inode(struct inode
5332         unsigned long invalid = 0;
5333         unsigned long now = jiffies;
5334         unsigned long save_cache_validity;
5335 +       uid_t uid;
5336 +       gid_t gid;
5337 +       tag_t tag;
5338  
5339         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5340                         __func__, inode->i_sb->s_id, inode->i_ino,
5341 @@ -1314,6 +1335,9 @@ static int nfs_update_inode(struct inode
5342                                 | NFS_INO_REVAL_PAGECACHE
5343                                 | NFS_INO_REVAL_FORCED);
5344  
5345 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5346 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5347 +       tag = inode->i_tag;
5348  
5349         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5350                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5351 @@ -1335,9 +1359,9 @@ static int nfs_update_inode(struct inode
5352                                 | NFS_INO_REVAL_FORCED);
5353  
5354         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5355 -               if (inode->i_uid != fattr->uid) {
5356 +               if (uid != fattr->uid) {
5357                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5358 -                       inode->i_uid = fattr->uid;
5359 +                       uid = fattr->uid;
5360                 }
5361         } else if (server->caps & NFS_CAP_OWNER)
5362                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5363 @@ -1346,9 +1370,9 @@ static int nfs_update_inode(struct inode
5364                                 | NFS_INO_REVAL_FORCED);
5365  
5366         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5367 -               if (inode->i_gid != fattr->gid) {
5368 +               if (gid != fattr->gid) {
5369                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5370 -                       inode->i_gid = fattr->gid;
5371 +                       gid = fattr->gid;
5372                 }
5373         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5374                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5375 @@ -1356,6 +1380,10 @@ static int nfs_update_inode(struct inode
5376                                 | NFS_INO_INVALID_ACL
5377                                 | NFS_INO_REVAL_FORCED);
5378  
5379 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5380 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5381 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5382 +
5383         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5384                 if (inode->i_nlink != fattr->nlink) {
5385                         invalid |= NFS_INO_INVALID_ATTR;
5386 diff -NurpP --minimal linux-3.2.8/fs/nfs/nfs3xdr.c linux-3.2.8-vs2.3.2.7/fs/nfs/nfs3xdr.c
5387 --- linux-3.2.8/fs/nfs/nfs3xdr.c        2011-03-15 18:07:32.000000000 +0100
5388 +++ linux-3.2.8-vs2.3.2.7/fs/nfs/nfs3xdr.c      2011-12-05 19:33:02.000000000 +0100
5389 @@ -20,6 +20,7 @@
5390  #include <linux/nfs3.h>
5391  #include <linux/nfs_fs.h>
5392  #include <linux/nfsacl.h>
5393 +#include <linux/vs_tag.h>
5394  #include "internal.h"
5395  
5396  #define NFSDBG_FACILITY                NFSDBG_XDR
5397 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5398   *             set_mtime       mtime;
5399   *     };
5400   */
5401 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5402 +static void encode_sattr3(struct xdr_stream *xdr,
5403 +       const struct iattr *attr, int tag)
5404  {
5405         u32 nbytes;
5406         __be32 *p;
5407 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5408         } else
5409                 *p++ = xdr_zero;
5410  
5411 -       if (attr->ia_valid & ATTR_UID) {
5412 +       if (attr->ia_valid & ATTR_UID ||
5413 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5414                 *p++ = xdr_one;
5415 -               *p++ = cpu_to_be32(attr->ia_uid);
5416 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5417 +                       attr->ia_uid, attr->ia_tag));
5418         } else
5419                 *p++ = xdr_zero;
5420  
5421 -       if (attr->ia_valid & ATTR_GID) {
5422 +       if (attr->ia_valid & ATTR_GID ||
5423 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5424                 *p++ = xdr_one;
5425 -               *p++ = cpu_to_be32(attr->ia_gid);
5426 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5427 +                       attr->ia_gid, attr->ia_tag));
5428         } else
5429                 *p++ = xdr_zero;
5430  
5431 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5432                                       const struct nfs3_sattrargs *args)
5433  {
5434         encode_nfs_fh3(xdr, args->fh);
5435 -       encode_sattr3(xdr, args->sattr);
5436 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5437         encode_sattrguard3(xdr, args);
5438  }
5439  
5440 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5441   *     };
5442   */
5443  static void encode_createhow3(struct xdr_stream *xdr,
5444 -                             const struct nfs3_createargs *args)
5445 +       const struct nfs3_createargs *args, int tag)
5446  {
5447         encode_uint32(xdr, args->createmode);
5448         switch (args->createmode) {
5449         case NFS3_CREATE_UNCHECKED:
5450         case NFS3_CREATE_GUARDED:
5451 -               encode_sattr3(xdr, args->sattr);
5452 +               encode_sattr3(xdr, args->sattr, tag);
5453                 break;
5454         case NFS3_CREATE_EXCLUSIVE:
5455                 encode_createverf3(xdr, args->verifier);
5456 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5457                                      const struct nfs3_createargs *args)
5458  {
5459         encode_diropargs3(xdr, args->fh, args->name, args->len);
5460 -       encode_createhow3(xdr, args);
5461 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5462  }
5463  
5464  /*
5465 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5466                                     const struct nfs3_mkdirargs *args)
5467  {
5468         encode_diropargs3(xdr, args->fh, args->name, args->len);
5469 -       encode_sattr3(xdr, args->sattr);
5470 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5471  }
5472  
5473  /*
5474 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5475   *     };
5476   */
5477  static void encode_symlinkdata3(struct xdr_stream *xdr,
5478 -                               const struct nfs3_symlinkargs *args)
5479 +       const struct nfs3_symlinkargs *args, int tag)
5480  {
5481 -       encode_sattr3(xdr, args->sattr);
5482 +       encode_sattr3(xdr, args->sattr, tag);
5483         encode_nfspath3(xdr, args->pages, args->pathlen);
5484  }
5485  
5486 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5487                                       const struct nfs3_symlinkargs *args)
5488  {
5489         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5490 -       encode_symlinkdata3(xdr, args);
5491 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5492  }
5493  
5494  /*
5495 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5496   *     };
5497   */
5498  static void encode_devicedata3(struct xdr_stream *xdr,
5499 -                              const struct nfs3_mknodargs *args)
5500 +       const struct nfs3_mknodargs *args, int tag)
5501  {
5502 -       encode_sattr3(xdr, args->sattr);
5503 +       encode_sattr3(xdr, args->sattr, tag);
5504         encode_specdata3(xdr, args->rdev);
5505  }
5506  
5507  static void encode_mknoddata3(struct xdr_stream *xdr,
5508 -                             const struct nfs3_mknodargs *args)
5509 +       const struct nfs3_mknodargs *args, int tag)
5510  {
5511         encode_ftype3(xdr, args->type);
5512         switch (args->type) {
5513         case NF3CHR:
5514         case NF3BLK:
5515 -               encode_devicedata3(xdr, args);
5516 +               encode_devicedata3(xdr, args, tag);
5517                 break;
5518         case NF3SOCK:
5519         case NF3FIFO:
5520 -               encode_sattr3(xdr, args->sattr);
5521 +               encode_sattr3(xdr, args->sattr, tag);
5522                 break;
5523         case NF3REG:
5524         case NF3DIR:
5525 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5526                                     const struct nfs3_mknodargs *args)
5527  {
5528         encode_diropargs3(xdr, args->fh, args->name, args->len);
5529 -       encode_mknoddata3(xdr, args);
5530 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5531  }
5532  
5533  /*
5534 diff -NurpP --minimal linux-3.2.8/fs/nfs/super.c linux-3.2.8-vs2.3.2.7/fs/nfs/super.c
5535 --- linux-3.2.8/fs/nfs/super.c  2012-02-28 05:53:29.000000000 +0100
5536 +++ linux-3.2.8-vs2.3.2.7/fs/nfs/super.c        2012-01-26 08:52:10.000000000 +0100
5537 @@ -53,6 +53,7 @@
5538  #include <linux/nfs_xdr.h>
5539  #include <linux/magic.h>
5540  #include <linux/parser.h>
5541 +#include <linux/vs_tag.h>
5542  
5543  #include <asm/system.h>
5544  #include <asm/uaccess.h>
5545 @@ -87,6 +88,7 @@ enum {
5546         Opt_sharecache, Opt_nosharecache,
5547         Opt_resvport, Opt_noresvport,
5548         Opt_fscache, Opt_nofscache,
5549 +       Opt_tag, Opt_notag,
5550  
5551         /* Mount options that take integer arguments */
5552         Opt_port,
5553 @@ -100,6 +102,7 @@ enum {
5554         Opt_mountvers,
5555         Opt_nfsvers,
5556         Opt_minorversion,
5557 +       Opt_tagid,
5558  
5559         /* Mount options that take string arguments */
5560         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5561 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5562         { Opt_fscache_uniq, "fsc=%s" },
5563         { Opt_local_lock, "local_lock=%s" },
5564  
5565 +       { Opt_tag, "tag" },
5566 +       { Opt_notag, "notag" },
5567 +       { Opt_tagid, "tagid=%u" },
5568 +
5569         { Opt_err, NULL }
5570  };
5571  
5572 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
5573                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5574                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5575                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5576 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5577                 { 0, NULL, NULL }
5578         };
5579         const struct proc_nfs_info *nfs_infop;
5580 @@ -1217,6 +1225,14 @@ static int nfs_parse_mount_options(char 
5581                         kfree(mnt->fscache_uniq);
5582                         mnt->fscache_uniq = NULL;
5583                         break;
5584 +#ifndef CONFIG_TAGGING_NONE
5585 +               case Opt_tag:
5586 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5587 +                       break;
5588 +               case Opt_notag:
5589 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5590 +                       break;
5591 +#endif
5592  
5593                 /*
5594                  * options that take numeric values
5595 @@ -1323,6 +1339,12 @@ static int nfs_parse_mount_options(char 
5596                                 goto out_invalid_value;
5597                         mnt->minorversion = option;
5598                         break;
5599 +#ifdef CONFIG_PROPAGATE
5600 +               case Opt_tagid:
5601 +                       /* use args[0] */
5602 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5603 +                       break;
5604 +#endif
5605  
5606                 /*
5607                  * options that take text values
5608 diff -NurpP --minimal linux-3.2.8/fs/nfsd/auth.c linux-3.2.8-vs2.3.2.7/fs/nfsd/auth.c
5609 --- linux-3.2.8/fs/nfsd/auth.c  2010-02-25 11:52:05.000000000 +0100
5610 +++ linux-3.2.8-vs2.3.2.7/fs/nfsd/auth.c        2011-12-05 19:33:02.000000000 +0100
5611 @@ -1,6 +1,7 @@
5612  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5613  
5614  #include <linux/sched.h>
5615 +#include <linux/vs_tag.h>
5616  #include "nfsd.h"
5617  #include "auth.h"
5618  
5619 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5620  
5621         new->fsuid = rqstp->rq_cred.cr_uid;
5622         new->fsgid = rqstp->rq_cred.cr_gid;
5623 +       /* FIXME: this desperately needs a tag :)
5624 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5625 +                       */
5626  
5627         rqgi = rqstp->rq_cred.cr_group_info;
5628  
5629 diff -NurpP --minimal linux-3.2.8/fs/nfsd/nfs3xdr.c linux-3.2.8-vs2.3.2.7/fs/nfsd/nfs3xdr.c
5630 --- linux-3.2.8/fs/nfsd/nfs3xdr.c       2011-07-22 11:18:05.000000000 +0200
5631 +++ linux-3.2.8-vs2.3.2.7/fs/nfsd/nfs3xdr.c     2011-12-05 19:33:02.000000000 +0100
5632 @@ -7,6 +7,7 @@
5633   */
5634  
5635  #include <linux/namei.h>
5636 +#include <linux/vs_tag.h>
5637  #include "xdr3.h"
5638  #include "auth.h"
5639  
5640 @@ -95,6 +96,8 @@ static __be32 *
5641  decode_sattr3(__be32 *p, struct iattr *iap)
5642  {
5643         u32     tmp;
5644 +       uid_t   uid = 0;
5645 +       gid_t   gid = 0;
5646  
5647         iap->ia_valid = 0;
5648  
5649 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5650         }
5651         if (*p++) {
5652                 iap->ia_valid |= ATTR_UID;
5653 -               iap->ia_uid = ntohl(*p++);
5654 +               uid = ntohl(*p++);
5655         }
5656         if (*p++) {
5657                 iap->ia_valid |= ATTR_GID;
5658 -               iap->ia_gid = ntohl(*p++);
5659 +               gid = ntohl(*p++);
5660         }
5661 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5662 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5663 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5664         if (*p++) {
5665                 u64     newsize;
5666  
5667 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5668         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5669         *p++ = htonl((u32) stat->mode);
5670         *p++ = htonl((u32) stat->nlink);
5671 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5672 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5673 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5674 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5675 +               stat->uid, stat->tag)));
5676 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5677 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5678 +               stat->gid, stat->tag)));
5679         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5680                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5681         } else {
5682 diff -NurpP --minimal linux-3.2.8/fs/nfsd/nfs4xdr.c linux-3.2.8-vs2.3.2.7/fs/nfsd/nfs4xdr.c
5683 --- linux-3.2.8/fs/nfsd/nfs4xdr.c       2012-01-09 16:14:54.000000000 +0100
5684 +++ linux-3.2.8-vs2.3.2.7/fs/nfsd/nfs4xdr.c     2011-12-05 19:33:02.000000000 +0100
5685 @@ -46,6 +46,7 @@
5686  #include <linux/utsname.h>
5687  #include <linux/pagemap.h>
5688  #include <linux/sunrpc/svcauth_gss.h>
5689 +#include <linux/vs_tag.h>
5690  
5691  #include "idmap.h"
5692  #include "acl.h"
5693 @@ -2328,14 +2329,18 @@ out_acl:
5694                 WRITE32(stat.nlink);
5695         }
5696         if (bmval1 & FATTR4_WORD1_OWNER) {
5697 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5698 +               status = nfsd4_encode_user(rqstp,
5699 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5700 +                       stat.uid, stat.tag), &p, &buflen);
5701                 if (status == nfserr_resource)
5702                         goto out_resource;
5703                 if (status)
5704                         goto out;
5705         }
5706         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5707 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5708 +               status = nfsd4_encode_group(rqstp,
5709 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5710 +                       stat.gid, stat.tag), &p, &buflen);
5711                 if (status == nfserr_resource)
5712                         goto out_resource;
5713                 if (status)
5714 diff -NurpP --minimal linux-3.2.8/fs/nfsd/nfsxdr.c linux-3.2.8-vs2.3.2.7/fs/nfsd/nfsxdr.c
5715 --- linux-3.2.8/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5716 +++ linux-3.2.8-vs2.3.2.7/fs/nfsd/nfsxdr.c      2011-12-05 19:33:02.000000000 +0100
5717 @@ -6,6 +6,7 @@
5718  
5719  #include "xdr.h"
5720  #include "auth.h"
5721 +#include <linux/vs_tag.h>
5722  
5723  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5724  
5725 @@ -88,6 +89,8 @@ static __be32 *
5726  decode_sattr(__be32 *p, struct iattr *iap)
5727  {
5728         u32     tmp, tmp1;
5729 +       uid_t   uid = 0;
5730 +       gid_t   gid = 0;
5731  
5732         iap->ia_valid = 0;
5733  
5734 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5735         }
5736         if ((tmp = ntohl(*p++)) != (u32)-1) {
5737                 iap->ia_valid |= ATTR_UID;
5738 -               iap->ia_uid = tmp;
5739 +               uid = tmp;
5740         }
5741         if ((tmp = ntohl(*p++)) != (u32)-1) {
5742                 iap->ia_valid |= ATTR_GID;
5743 -               iap->ia_gid = tmp;
5744 +               gid = tmp;
5745         }
5746 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5747 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5748 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5749         if ((tmp = ntohl(*p++)) != (u32)-1) {
5750                 iap->ia_valid |= ATTR_SIZE;
5751                 iap->ia_size = tmp;
5752 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5753         *p++ = htonl(nfs_ftypes[type >> 12]);
5754         *p++ = htonl((u32) stat->mode);
5755         *p++ = htonl((u32) stat->nlink);
5756 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5757 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5758 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5759 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5760 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5761 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5762  
5763         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5764                 *p++ = htonl(NFS_MAXPATHLEN);
5765 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/dlmglue.c linux-3.2.8-vs2.3.2.7/fs/ocfs2/dlmglue.c
5766 --- linux-3.2.8/fs/ocfs2/dlmglue.c      2012-01-09 16:14:55.000000000 +0100
5767 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/dlmglue.c    2011-12-05 19:33:02.000000000 +0100
5768 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5769         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5770         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5771         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5772 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5773         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5774         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5775         lvb->lvb_iatime_packed  =
5776 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5777  
5778         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5779         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5780 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5781         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5782         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5783         ocfs2_unpack_timespec(&inode->i_atime,
5784 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/dlmglue.h linux-3.2.8-vs2.3.2.7/fs/ocfs2/dlmglue.h
5785 --- linux-3.2.8/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5786 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/dlmglue.h    2011-12-05 19:33:02.000000000 +0100
5787 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5788         __be16       lvb_inlink;
5789         __be32       lvb_iattr;
5790         __be32       lvb_igeneration;
5791 -       __be32       lvb_reserved2;
5792 +       __be16       lvb_itag;
5793 +       __be16       lvb_reserved2;
5794  };
5795  
5796  #define OCFS2_QINFO_LVB_VERSION 1
5797 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/file.c linux-3.2.8-vs2.3.2.7/fs/ocfs2/file.c
5798 --- linux-3.2.8/fs/ocfs2/file.c 2012-01-09 16:14:55.000000000 +0100
5799 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/file.c       2011-12-05 19:33:02.000000000 +0100
5800 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5801                 attr->ia_valid &= ~ATTR_SIZE;
5802  
5803  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5804 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5805 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5806         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5807                 return 0;
5808  
5809 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/inode.c linux-3.2.8-vs2.3.2.7/fs/ocfs2/inode.c
5810 --- linux-3.2.8/fs/ocfs2/inode.c        2012-01-09 16:14:55.000000000 +0100
5811 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/inode.c      2011-12-05 19:33:02.000000000 +0100
5812 @@ -28,6 +28,7 @@
5813  #include <linux/highmem.h>
5814  #include <linux/pagemap.h>
5815  #include <linux/quotaops.h>
5816 +#include <linux/vs_tag.h>
5817  
5818  #include <asm/byteorder.h>
5819  
5820 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5821  {
5822         unsigned int flags = OCFS2_I(inode)->ip_attr;
5823  
5824 -       inode->i_flags &= ~(S_IMMUTABLE |
5825 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5826                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5827  
5828         if (flags & OCFS2_IMMUTABLE_FL)
5829                 inode->i_flags |= S_IMMUTABLE;
5830 +       if (flags & OCFS2_IXUNLINK_FL)
5831 +               inode->i_flags |= S_IXUNLINK;
5832  
5833         if (flags & OCFS2_SYNC_FL)
5834                 inode->i_flags |= S_SYNC;
5835 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5836                 inode->i_flags |= S_NOATIME;
5837         if (flags & OCFS2_DIRSYNC_FL)
5838                 inode->i_flags |= S_DIRSYNC;
5839 +
5840 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5841 +
5842 +       if (flags & OCFS2_BARRIER_FL)
5843 +               inode->i_vflags |= V_BARRIER;
5844 +       if (flags & OCFS2_COW_FL)
5845 +               inode->i_vflags |= V_COW;
5846  }
5847  
5848  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5849  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5850  {
5851         unsigned int flags = oi->vfs_inode.i_flags;
5852 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5853 +
5854 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5855 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5856 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5857 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5858 +
5859 +       if (flags & S_IMMUTABLE)
5860 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5861 +       if (flags & S_IXUNLINK)
5862 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5863  
5864 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5865 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5866         if (flags & S_SYNC)
5867                 oi->ip_attr |= OCFS2_SYNC_FL;
5868         if (flags & S_APPEND)
5869                 oi->ip_attr |= OCFS2_APPEND_FL;
5870 -       if (flags & S_IMMUTABLE)
5871 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5872         if (flags & S_NOATIME)
5873                 oi->ip_attr |= OCFS2_NOATIME_FL;
5874         if (flags & S_DIRSYNC)
5875                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5876 +
5877 +       if (vflags & V_BARRIER)
5878 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5879 +       if (vflags & V_COW)
5880 +               oi->ip_attr |= OCFS2_COW_FL;
5881  }
5882  
5883  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5884 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5885         struct super_block *sb;
5886         struct ocfs2_super *osb;
5887         int use_plocks = 1;
5888 +       uid_t uid;
5889 +       gid_t gid;
5890  
5891         sb = inode->i_sb;
5892         osb = OCFS2_SB(sb);
5893 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5894         inode->i_generation = le32_to_cpu(fe->i_generation);
5895         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5896         inode->i_mode = le16_to_cpu(fe->i_mode);
5897 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5898 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5899 +       uid = le32_to_cpu(fe->i_uid);
5900 +       gid = le32_to_cpu(fe->i_gid);
5901 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5902 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5903 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5904 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5905  
5906         /* Fast symlinks will have i_size but no allocated clusters. */
5907         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5908 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/inode.h linux-3.2.8-vs2.3.2.7/fs/ocfs2/inode.h
5909 --- linux-3.2.8/fs/ocfs2/inode.h        2012-01-09 16:14:55.000000000 +0100
5910 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/inode.h      2011-12-05 19:33:02.000000000 +0100
5911 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5912  
5913  void ocfs2_set_inode_flags(struct inode *inode);
5914  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5915 +int ocfs2_sync_flags(struct inode *inode, int, int);
5916  
5917  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5918  {
5919 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/ioctl.c linux-3.2.8-vs2.3.2.7/fs/ocfs2/ioctl.c
5920 --- linux-3.2.8/fs/ocfs2/ioctl.c        2012-01-09 16:14:55.000000000 +0100
5921 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/ioctl.c      2011-12-05 19:33:02.000000000 +0100
5922 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
5923         return status;
5924  }
5925  
5926 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5927 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5928 +{
5929 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5930 +       struct buffer_head *bh = NULL;
5931 +       handle_t *handle = NULL;
5932 +       int status;
5933 +
5934 +       status = ocfs2_inode_lock(inode, &bh, 1);
5935 +       if (status < 0) {
5936 +               mlog_errno(status);
5937 +               return status;
5938 +       }
5939 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5940 +       if (IS_ERR(handle)) {
5941 +               status = PTR_ERR(handle);
5942 +               mlog_errno(status);
5943 +               goto bail_unlock;
5944 +       }
5945 +
5946 +       inode->i_flags = flags;
5947 +       inode->i_vflags = vflags;
5948 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5949 +
5950 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5951 +       if (status < 0)
5952 +               mlog_errno(status);
5953 +
5954 +       ocfs2_commit_trans(osb, handle);
5955 +bail_unlock:
5956 +       ocfs2_inode_unlock(inode, 1);
5957 +       brelse(bh);
5958 +       return status;
5959 +}
5960 +
5961 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5962                                 unsigned mask)
5963  {
5964         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5965 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
5966         if (!S_ISDIR(inode->i_mode))
5967                 flags &= ~OCFS2_DIRSYNC_FL;
5968  
5969 +       if (IS_BARRIER(inode)) {
5970 +               vxwprintk_task(1, "messing with the barrier.");
5971 +               goto bail_unlock;
5972 +       }
5973 +
5974         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5975         if (IS_ERR(handle)) {
5976                 status = PTR_ERR(handle);
5977 @@ -881,6 +920,7 @@ bail:
5978         return status;
5979  }
5980  
5981 +
5982  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5983  {
5984         struct inode *inode = filp->f_path.dentry->d_inode;
5985 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/namei.c linux-3.2.8-vs2.3.2.7/fs/ocfs2/namei.c
5986 --- linux-3.2.8/fs/ocfs2/namei.c        2012-01-09 16:14:55.000000000 +0100
5987 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/namei.c      2011-12-05 19:33:02.000000000 +0100
5988 @@ -41,6 +41,7 @@
5989  #include <linux/slab.h>
5990  #include <linux/highmem.h>
5991  #include <linux/quotaops.h>
5992 +#include <linux/vs_tag.h>
5993  
5994  #include <cluster/masklog.h>
5995  
5996 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5997         struct ocfs2_dinode *fe = NULL;
5998         struct ocfs2_extent_list *fel;
5999         u16 feat;
6000 +       tag_t tag;
6001  
6002         *new_fe_bh = NULL;
6003  
6004 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
6005         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6006         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6007         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6008 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6009 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6010 +
6011 +       tag = dx_current_fstag(osb->sb);
6012 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6013 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6014 +       inode->i_tag = tag;
6015         fe->i_mode = cpu_to_le16(inode->i_mode);
6016         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6017                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6018 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/ocfs2.h linux-3.2.8-vs2.3.2.7/fs/ocfs2/ocfs2.h
6019 --- linux-3.2.8/fs/ocfs2/ocfs2.h        2012-01-09 16:14:55.000000000 +0100
6020 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/ocfs2.h      2011-12-05 19:33:02.000000000 +0100
6021 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6022                                                      writes */
6023         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6024         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6025 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6026  };
6027  
6028  #define OCFS2_OSB_SOFT_RO                      0x0001
6029 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/ocfs2_fs.h linux-3.2.8-vs2.3.2.7/fs/ocfs2/ocfs2_fs.h
6030 --- linux-3.2.8/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
6031 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/ocfs2_fs.h   2011-12-05 19:33:02.000000000 +0100
6032 @@ -266,6 +266,11 @@
6033  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6034  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6035  
6036 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6037 +
6038 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6039 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6040 +
6041  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6042  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6043  
6044 diff -NurpP --minimal linux-3.2.8/fs/ocfs2/super.c linux-3.2.8-vs2.3.2.7/fs/ocfs2/super.c
6045 --- linux-3.2.8/fs/ocfs2/super.c        2012-01-09 16:14:55.000000000 +0100
6046 +++ linux-3.2.8-vs2.3.2.7/fs/ocfs2/super.c      2011-12-05 19:33:02.000000000 +0100
6047 @@ -185,6 +185,7 @@ enum {
6048         Opt_coherency_full,
6049         Opt_resv_level,
6050         Opt_dir_resv_level,
6051 +       Opt_tag, Opt_notag, Opt_tagid,
6052         Opt_err,
6053  };
6054  
6055 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
6056         {Opt_coherency_full, "coherency=full"},
6057         {Opt_resv_level, "resv_level=%u"},
6058         {Opt_dir_resv_level, "dir_resv_level=%u"},
6059 +       {Opt_tag, "tag"},
6060 +       {Opt_notag, "notag"},
6061 +       {Opt_tagid, "tagid=%u"},
6062         {Opt_err, NULL}
6063  };
6064  
6065 @@ -663,6 +667,13 @@ static int ocfs2_remount(struct super_bl
6066                 goto out;
6067         }
6068  
6069 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6070 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6071 +               ret = -EINVAL;
6072 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6073 +               goto out;
6074 +       }
6075 +
6076         /* We're going to/from readonly mode. */
6077         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6078                 /* Disable quota accounting before remounting RO */
6079 @@ -1178,6 +1189,9 @@ static int ocfs2_fill_super(struct super
6080  
6081         ocfs2_complete_mount_recovery(osb);
6082  
6083 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6084 +               sb->s_flags |= MS_TAGGED;
6085 +
6086         if (ocfs2_mount_local(osb))
6087                 snprintf(nodestr, sizeof(nodestr), "local");
6088         else
6089 @@ -1507,6 +1521,20 @@ static int ocfs2_parse_options(struct su
6090                             option < OCFS2_MAX_RESV_LEVEL)
6091                                 mopt->dir_resv_level = option;
6092                         break;
6093 +#ifndef CONFIG_TAGGING_NONE
6094 +               case Opt_tag:
6095 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6096 +                       break;
6097 +               case Opt_notag:
6098 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6099 +                       break;
6100 +#endif
6101 +#ifdef CONFIG_PROPAGATE
6102 +               case Opt_tagid:
6103 +                       /* use args[0] */
6104 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6105 +                       break;
6106 +#endif
6107                 default:
6108                         mlog(ML_ERROR,
6109                              "Unrecognized mount option \"%s\" "
6110 diff -NurpP --minimal linux-3.2.8/fs/open.c linux-3.2.8-vs2.3.2.7/fs/open.c
6111 --- linux-3.2.8/fs/open.c       2012-01-09 16:14:55.000000000 +0100
6112 +++ linux-3.2.8-vs2.3.2.7/fs/open.c     2011-12-05 19:33:02.000000000 +0100
6113 @@ -30,6 +30,11 @@
6114  #include <linux/fs_struct.h>
6115  #include <linux/ima.h>
6116  #include <linux/dnotify.h>
6117 +#include <linux/vs_base.h>
6118 +#include <linux/vs_limit.h>
6119 +#include <linux/vs_tag.h>
6120 +#include <linux/vs_cowbl.h>
6121 +#include <linux/vserver/dlimit.h>
6122  
6123  #include "internal.h"
6124  
6125 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6126         error = user_path(pathname, &path);
6127         if (error)
6128                 goto out;
6129 +
6130 +#ifdef CONFIG_VSERVER_COWBL
6131 +       error = cow_check_and_break(&path);
6132 +       if (error)
6133 +               goto dput_and_out;
6134 +#endif
6135         inode = path.dentry->d_inode;
6136  
6137         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6138 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6139  
6140         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6141         if (!error) {
6142 +#ifdef CONFIG_VSERVER_COWBL
6143 +               error = cow_check_and_break(&path);
6144 +               if (!error)
6145 +#endif
6146                 error = chmod_common(&path, mode);
6147                 path_put(&path);
6148         }
6149 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6150         newattrs.ia_valid =  ATTR_CTIME;
6151         if (user != (uid_t) -1) {
6152                 newattrs.ia_valid |= ATTR_UID;
6153 -               newattrs.ia_uid = user;
6154 +               newattrs.ia_uid = dx_map_uid(user);
6155         }
6156         if (group != (gid_t) -1) {
6157                 newattrs.ia_valid |= ATTR_GID;
6158 -               newattrs.ia_gid = group;
6159 +               newattrs.ia_gid = dx_map_gid(group);
6160         }
6161         if (!S_ISDIR(inode->i_mode))
6162                 newattrs.ia_valid |=
6163 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6164         error = mnt_want_write(path.mnt);
6165         if (error)
6166                 goto out_release;
6167 +#ifdef CONFIG_VSERVER_COWBL
6168 +       error = cow_check_and_break(&path);
6169 +       if (!error)
6170 +#endif
6171         error = chown_common(&path, user, group);
6172         mnt_drop_write(path.mnt);
6173  out_release:
6174 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6175         error = mnt_want_write(path.mnt);
6176         if (error)
6177                 goto out_release;
6178 +#ifdef CONFIG_VSERVER_COWBL
6179 +       error = cow_check_and_break(&path);
6180 +       if (!error)
6181 +#endif
6182         error = chown_common(&path, user, group);
6183         mnt_drop_write(path.mnt);
6184  out_release:
6185 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6186         error = mnt_want_write(path.mnt);
6187         if (error)
6188                 goto out_release;
6189 +#ifdef CONFIG_VSERVER_COWBL
6190 +       error = cow_check_and_break(&path);
6191 +       if (!error)
6192 +#endif
6193         error = chown_common(&path, user, group);
6194         mnt_drop_write(path.mnt);
6195  out_release:
6196 @@ -839,6 +866,7 @@ static void __put_unused_fd(struct files
6197         __FD_CLR(fd, fdt->open_fds);
6198         if (fd < files->next_fd)
6199                 files->next_fd = fd;
6200 +       vx_openfd_dec(fd);
6201  }
6202  
6203  void put_unused_fd(unsigned int fd)
6204 diff -NurpP --minimal linux-3.2.8/fs/proc/array.c linux-3.2.8-vs2.3.2.7/fs/proc/array.c
6205 --- linux-3.2.8/fs/proc/array.c 2011-10-24 18:45:27.000000000 +0200
6206 +++ linux-3.2.8-vs2.3.2.7/fs/proc/array.c       2011-12-05 19:33:02.000000000 +0100
6207 @@ -81,6 +81,8 @@
6208  #include <linux/pid_namespace.h>
6209  #include <linux/ptrace.h>
6210  #include <linux/tracehook.h>
6211 +#include <linux/vs_context.h>
6212 +#include <linux/vs_network.h>
6213  
6214  #include <asm/pgtable.h>
6215  #include <asm/processor.h>
6216 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6217         rcu_read_lock();
6218         ppid = pid_alive(p) ?
6219                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6220 +       if (unlikely(vx_current_initpid(p->pid)))
6221 +               ppid = 0;
6222 +
6223         tpid = 0;
6224         if (pid_alive(p)) {
6225                 struct task_struct *tracer = ptrace_parent(p);
6226 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6227  }
6228  
6229  static void render_cap_t(struct seq_file *m, const char *header,
6230 -                       kernel_cap_t *a)
6231 +                       struct vx_info *vxi, kernel_cap_t *a)
6232  {
6233         unsigned __capi;
6234  
6235 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6236         cap_bset        = cred->cap_bset;
6237         rcu_read_unlock();
6238  
6239 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6240 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6241 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6242 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6243 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6244 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6245 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6246 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6247 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6248  }
6249  
6250  static inline void task_context_switch_counts(struct seq_file *m,
6251 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6252         seq_putc(m, '\n');
6253  }
6254  
6255 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6256 +                       struct pid *pid, struct task_struct *task)
6257 +{
6258 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6259 +                       "Count:\t%u\n"
6260 +                       "uts:\t%p(%c)\n"
6261 +                       "ipc:\t%p(%c)\n"
6262 +                       "mnt:\t%p(%c)\n"
6263 +                       "pid:\t%p(%c)\n"
6264 +                       "net:\t%p(%c)\n",
6265 +                       task->nsproxy,
6266 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6267 +                       atomic_read(&task->nsproxy->count),
6268 +                       task->nsproxy->uts_ns,
6269 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6270 +                       task->nsproxy->ipc_ns,
6271 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6272 +                       task->nsproxy->mnt_ns,
6273 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6274 +                       task->nsproxy->pid_ns,
6275 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6276 +                       task->nsproxy->net_ns,
6277 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6278 +       return 0;
6279 +}
6280 +
6281 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6282 +{
6283 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6284 +               return;
6285 +
6286 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6287 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6288 +}
6289 +
6290 +
6291  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6292                         struct pid *pid, struct task_struct *task)
6293  {
6294 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6295         task_cap(m, task);
6296         task_cpus_allowed(m, task);
6297         cpuset_task_status_allowed(m, task);
6298 +       task_vs_id(m, task);
6299         task_context_switch_counts(m, task);
6300         return 0;
6301  }
6302 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6303         /* convert nsec -> ticks */
6304         start_time = nsec_to_clock_t(start_time);
6305  
6306 +       /* fixup start time for virt uptime */
6307 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6308 +               unsigned long long bias =
6309 +                       current->vx_info->cvirt.bias_clock;
6310 +
6311 +               if (start_time > bias)
6312 +                       start_time -= bias;
6313 +               else
6314 +                       start_time = 0;
6315 +       }
6316 +
6317         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6318  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6319  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6320 diff -NurpP --minimal linux-3.2.8/fs/proc/base.c linux-3.2.8-vs2.3.2.7/fs/proc/base.c
6321 --- linux-3.2.8/fs/proc/base.c  2012-02-28 05:53:29.000000000 +0100
6322 +++ linux-3.2.8-vs2.3.2.7/fs/proc/base.c        2012-02-15 03:26:56.000000000 +0100
6323 @@ -83,6 +83,8 @@
6324  #include <linux/pid_namespace.h>
6325  #include <linux/fs_struct.h>
6326  #include <linux/slab.h>
6327 +#include <linux/vs_context.h>
6328 +#include <linux/vs_network.h>
6329  #ifdef CONFIG_HARDWALL
6330  #include <asm/hardwall.h>
6331  #endif
6332 @@ -1021,11 +1023,16 @@ static ssize_t oom_adjust_write(struct f
6333                 goto err_task_lock;
6334         }
6335  
6336 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6337 +       if (oom_adjust < task->signal->oom_adj &&
6338 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6339                 err = -EACCES;
6340                 goto err_sighand;
6341         }
6342  
6343 +       /* prevent guest processes from circumventing the oom killer */
6344 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6345 +               oom_adjust = OOM_ADJUST_MIN;
6346 +
6347         /*
6348          * Warn that /proc/pid/oom_adj is deprecated, see
6349          * Documentation/feature-removal-schedule.txt.
6350 @@ -1180,7 +1187,7 @@ static ssize_t proc_loginuid_write(struc
6351         ssize_t length;
6352         uid_t loginuid;
6353  
6354 -       if (!capable(CAP_AUDIT_CONTROL))
6355 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6356                 return -EPERM;
6357  
6358         rcu_read_lock();
6359 @@ -1627,6 +1634,8 @@ struct inode *proc_pid_make_inode(struct
6360                 inode->i_gid = cred->egid;
6361                 rcu_read_unlock();
6362         }
6363 +       /* procfs is xid tagged */
6364 +       inode->i_tag = (tag_t)vx_task_xid(task);
6365         security_task_to_inode(task, inode);
6366  
6367  out:
6368 @@ -1663,6 +1672,8 @@ int pid_getattr(struct vfsmount *mnt, st
6369  
6370  /* dentry stuff */
6371  
6372 +static unsigned name_to_int(struct dentry *dentry);
6373 +
6374  /*
6375   *     Exceptional case: normally we are not allowed to unhash a busy
6376   * directory. In this case, however, we can do it - no aliasing problems
6377 @@ -1691,6 +1702,12 @@ int pid_revalidate(struct dentry *dentry
6378         task = get_proc_task(inode);
6379  
6380         if (task) {
6381 +               unsigned pid = name_to_int(dentry);
6382 +
6383 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6384 +                       put_task_struct(task);
6385 +                       goto drop;
6386 +               }
6387                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6388                     task_dumpable(task)) {
6389                         rcu_read_lock();
6390 @@ -1707,6 +1724,7 @@ int pid_revalidate(struct dentry *dentry
6391                 put_task_struct(task);
6392                 return 1;
6393         }
6394 +drop:
6395         d_drop(dentry);
6396         return 0;
6397  }
6398 @@ -2196,6 +2214,13 @@ static struct dentry *proc_pident_lookup
6399         if (!task)
6400                 goto out_no_task;
6401  
6402 +       /* TODO: maybe we can come up with a generic approach? */
6403 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6404 +               (dentry->d_name.len == 5) &&
6405 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6406 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6407 +               goto out;
6408 +
6409         /*
6410          * Yes, it does not scale. And it should not. Don't add
6411          * new entries into /proc/<tgid>/ without very good reasons.
6412 @@ -2581,7 +2606,7 @@ out_iput:
6413  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6414  {
6415         struct dentry *error;
6416 -       struct task_struct *task = get_proc_task(dir);
6417 +       struct task_struct *task = get_proc_task_real(dir);
6418         const struct pid_entry *p, *last;
6419  
6420         error = ERR_PTR(-ENOENT);
6421 @@ -2688,6 +2713,9 @@ static int proc_pid_personality(struct s
6422  static const struct file_operations proc_task_operations;
6423  static const struct inode_operations proc_task_inode_operations;
6424  
6425 +extern int proc_pid_vx_info(struct task_struct *, char *);
6426 +extern int proc_pid_nx_info(struct task_struct *, char *);
6427 +
6428  static const struct pid_entry tgid_base_stuff[] = {
6429         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6430         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6431 @@ -2751,6 +2779,8 @@ static const struct pid_entry tgid_base_
6432  #ifdef CONFIG_CGROUPS
6433         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6434  #endif
6435 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6436 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6437         INF("oom_score",  S_IRUGO, proc_oom_score),
6438         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6439         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6440 @@ -2770,6 +2800,7 @@ static const struct pid_entry tgid_base_
6441  #ifdef CONFIG_HARDWALL
6442         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6443  #endif
6444 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6445  };
6446  
6447  static int proc_tgid_base_readdir(struct file * filp,
6448 @@ -2962,7 +2993,7 @@ retry:
6449         iter.task = NULL;
6450         pid = find_ge_pid(iter.tgid, ns);
6451         if (pid) {
6452 -               iter.tgid = pid_nr_ns(pid, ns);
6453 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6454                 iter.task = pid_task(pid, PIDTYPE_PID);
6455                 /* What we to know is if the pid we have find is the
6456                  * pid of a thread_group_leader.  Testing for task
6457 @@ -2992,7 +3023,7 @@ static int proc_pid_fill_cache(struct fi
6458         struct tgid_iter iter)
6459  {
6460         char name[PROC_NUMBUF];
6461 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6462 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6463         return proc_fill_cache(filp, dirent, filldir, name, len,
6464                                 proc_pid_instantiate, iter.task, NULL);
6465  }
6466 @@ -3009,7 +3040,7 @@ int proc_pid_readdir(struct file * filp,
6467                 goto out_no_task;
6468         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6469  
6470 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6471 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6472         if (!reaper)
6473                 goto out_no_task;
6474  
6475 @@ -3026,6 +3057,8 @@ int proc_pid_readdir(struct file * filp,
6476              iter.task;
6477              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6478                 filp->f_pos = iter.tgid + TGID_OFFSET;
6479 +               if (!vx_proc_task_visible(iter.task))
6480 +                       continue;
6481                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6482                         put_task_struct(iter.task);
6483                         goto out;
6484 @@ -3179,6 +3212,8 @@ static struct dentry *proc_task_lookup(s
6485         tid = name_to_int(dentry);
6486         if (tid == ~0U)
6487                 goto out;
6488 +       if (vx_current_initpid(tid))
6489 +               goto out;
6490  
6491         ns = dentry->d_sb->s_fs_info;
6492         rcu_read_lock();
6493 diff -NurpP --minimal linux-3.2.8/fs/proc/generic.c linux-3.2.8-vs2.3.2.7/fs/proc/generic.c
6494 --- linux-3.2.8/fs/proc/generic.c       2012-01-09 16:14:55.000000000 +0100
6495 +++ linux-3.2.8-vs2.3.2.7/fs/proc/generic.c     2011-12-05 19:33:02.000000000 +0100
6496 @@ -22,6 +22,7 @@
6497  #include <linux/bitops.h>
6498  #include <linux/spinlock.h>
6499  #include <linux/completion.h>
6500 +#include <linux/vserver/inode.h>
6501  #include <asm/uaccess.h>
6502  
6503  #include "internal.h"
6504 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6505         for (de = de->subdir; de ; de = de->next) {
6506                 if (de->namelen != dentry->d_name.len)
6507                         continue;
6508 +               if (!vx_hide_check(0, de->vx_flags))
6509 +                       continue;
6510                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6511                         pde_get(de);
6512                         spin_unlock(&proc_subdir_lock);
6513                         error = -EINVAL;
6514                         inode = proc_get_inode(dir->i_sb, de);
6515 +                       /* generic proc entries belong to the host */
6516 +                       inode->i_tag = 0;
6517                         goto out_unlock;
6518                 }
6519         }
6520 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6521  
6522                                 /* filldir passes info to user space */
6523                                 pde_get(de);
6524 +                               if (!vx_hide_check(0, de->vx_flags))
6525 +                                       goto skip;
6526                                 spin_unlock(&proc_subdir_lock);
6527                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6528                                             de->low_ino, de->mode >> 12) < 0) {
6529 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6530                                         goto out;
6531                                 }
6532                                 spin_lock(&proc_subdir_lock);
6533 +                       skip:
6534                                 filp->f_pos++;
6535                                 next = de->next;
6536                                 pde_put(de);
6537 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6538         ent->nlink = nlink;
6539         atomic_set(&ent->count, 1);
6540         ent->pde_users = 0;
6541 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6542         spin_lock_init(&ent->pde_unload_lock);
6543         ent->pde_unload_completion = NULL;
6544         INIT_LIST_HEAD(&ent->pde_openers);
6545 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6546                                 kfree(ent->data);
6547                                 kfree(ent);
6548                                 ent = NULL;
6549 -                       }
6550 +                       } else
6551 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6552                 } else {
6553                         kfree(ent);
6554                         ent = NULL;
6555 diff -NurpP --minimal linux-3.2.8/fs/proc/inode.c linux-3.2.8-vs2.3.2.7/fs/proc/inode.c
6556 --- linux-3.2.8/fs/proc/inode.c 2012-01-09 16:14:55.000000000 +0100
6557 +++ linux-3.2.8-vs2.3.2.7/fs/proc/inode.c       2011-12-05 19:33:02.000000000 +0100
6558 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
6559                         inode->i_uid = de->uid;
6560                         inode->i_gid = de->gid;
6561                 }
6562 +               if (de->vx_flags)
6563 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6564                 if (de->size)
6565                         inode->i_size = de->size;
6566                 if (de->nlink)
6567 diff -NurpP --minimal linux-3.2.8/fs/proc/internal.h linux-3.2.8-vs2.3.2.7/fs/proc/internal.h
6568 --- linux-3.2.8/fs/proc/internal.h      2011-07-22 11:18:06.000000000 +0200
6569 +++ linux-3.2.8-vs2.3.2.7/fs/proc/internal.h    2011-12-05 19:33:02.000000000 +0100
6570 @@ -10,6 +10,7 @@
6571   */
6572  
6573  #include <linux/proc_fs.h>
6574 +#include <linux/vs_pid.h>
6575  
6576  extern struct proc_dir_entry proc_root;
6577  #ifdef CONFIG_PROC_SYSCTL
6578 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6579                                 struct pid *pid, struct task_struct *task);
6580  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6581                                 struct pid *pid, struct task_struct *task);
6582 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6583 +                               struct pid *pid, struct task_struct *task);
6584 +
6585  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6586  
6587  extern const struct file_operations proc_maps_operations;
6588 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6589         return PROC_I(inode)->pid;
6590  }
6591  
6592 -static inline struct task_struct *get_proc_task(struct inode *inode)
6593 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6594  {
6595         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6596  }
6597  
6598 +static inline struct task_struct *get_proc_task(struct inode *inode)
6599 +{
6600 +       return vx_get_proc_task(inode, proc_pid(inode));
6601 +}
6602 +
6603  static inline int proc_fd(struct inode *inode)
6604  {
6605         return PROC_I(inode)->fd;
6606 diff -NurpP --minimal linux-3.2.8/fs/proc/loadavg.c linux-3.2.8-vs2.3.2.7/fs/proc/loadavg.c
6607 --- linux-3.2.8/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6608 +++ linux-3.2.8-vs2.3.2.7/fs/proc/loadavg.c     2011-12-05 19:33:02.000000000 +0100
6609 @@ -12,15 +12,27 @@
6610  
6611  static int loadavg_proc_show(struct seq_file *m, void *v)
6612  {
6613 +       unsigned long running;
6614 +       unsigned int threads;
6615         unsigned long avnrun[3];
6616  
6617         get_avenrun(avnrun, FIXED_1/200, 0);
6618  
6619 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6620 +               struct vx_info *vxi = current_vx_info();
6621 +
6622 +               running = atomic_read(&vxi->cvirt.nr_running);
6623 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6624 +       } else {
6625 +               running = nr_running();
6626 +               threads = nr_threads;
6627 +       }
6628 +
6629         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6630                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6631                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6632                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6633 -               nr_running(), nr_threads,
6634 +               running, threads,
6635                 task_active_pid_ns(current)->last_pid);
6636         return 0;
6637  }
6638 diff -NurpP --minimal linux-3.2.8/fs/proc/meminfo.c linux-3.2.8-vs2.3.2.7/fs/proc/meminfo.c
6639 --- linux-3.2.8/fs/proc/meminfo.c       2012-01-09 16:14:55.000000000 +0100
6640 +++ linux-3.2.8-vs2.3.2.7/fs/proc/meminfo.c     2011-12-15 01:11:32.000000000 +0100
6641 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6642         allowed = ((totalram_pages - hugetlb_total_pages())
6643                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6644  
6645 -       cached = global_page_state(NR_FILE_PAGES) -
6646 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6647 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6648                         total_swapcache_pages - i.bufferram;
6649         if (cached < 0)
6650                 cached = 0;
6651 diff -NurpP --minimal linux-3.2.8/fs/proc/root.c linux-3.2.8-vs2.3.2.7/fs/proc/root.c
6652 --- linux-3.2.8/fs/proc/root.c  2012-01-09 16:14:55.000000000 +0100
6653 +++ linux-3.2.8-vs2.3.2.7/fs/proc/root.c        2012-01-09 16:19:31.000000000 +0100
6654 @@ -18,9 +18,14 @@
6655  #include <linux/bitops.h>
6656  #include <linux/mount.h>
6657  #include <linux/pid_namespace.h>
6658 +#include <linux/vserver/inode.h>
6659  
6660  #include "internal.h"
6661  
6662 +struct proc_dir_entry *proc_virtual;
6663 +
6664 +extern void proc_vx_init(void);
6665 +
6666  static int proc_test_super(struct super_block *sb, void *data)
6667  {
6668         return sb->s_fs_info == data;
6669 @@ -123,6 +128,7 @@ void __init proc_root_init(void)
6670  #endif
6671         proc_mkdir("bus", NULL);
6672         proc_sys_init();
6673 +       proc_vx_init();
6674  }
6675  
6676  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6677 @@ -190,6 +196,7 @@ struct proc_dir_entry proc_root = {
6678         .proc_iops      = &proc_root_inode_operations, 
6679         .proc_fops      = &proc_root_operations,
6680         .parent         = &proc_root,
6681 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6682         .name           = "/proc",
6683  };
6684  
6685 diff -NurpP --minimal linux-3.2.8/fs/proc/uptime.c linux-3.2.8-vs2.3.2.7/fs/proc/uptime.c
6686 --- linux-3.2.8/fs/proc/uptime.c        2012-02-28 05:53:29.000000000 +0100
6687 +++ linux-3.2.8-vs2.3.2.7/fs/proc/uptime.c      2012-01-26 09:03:19.000000000 +0100
6688 @@ -5,6 +5,7 @@
6689  #include <linux/seq_file.h>
6690  #include <linux/time.h>
6691  #include <linux/kernel_stat.h>
6692 +#include <linux/vserver/cvirt.h>
6693  #include <asm/cputime.h>
6694  
6695  static int uptime_proc_show(struct seq_file *m, void *v)
6696 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6697         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6698         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6699         idle.tv_nsec = rem;
6700 +
6701 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6702 +               vx_vsi_uptime(&uptime, &idle);
6703 +
6704         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6705                         (unsigned long) uptime.tv_sec,
6706                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6707 diff -NurpP --minimal linux-3.2.8/fs/quota/dquot.c linux-3.2.8-vs2.3.2.7/fs/quota/dquot.c
6708 --- linux-3.2.8/fs/quota/dquot.c        2011-07-22 11:18:06.000000000 +0200
6709 +++ linux-3.2.8-vs2.3.2.7/fs/quota/dquot.c      2011-12-05 19:33:02.000000000 +0100
6710 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
6711         int reserve = flags & DQUOT_SPACE_RESERVE;
6712         int nofail = flags & DQUOT_SPACE_NOFAIL;
6713  
6714 +       if ((ret = dl_alloc_space(inode, number)))
6715 +               return ret;
6716 +
6717         /*
6718          * First test before acquiring mutex - solves deadlocks when we
6719          * re-enter the quota code and are already holding the mutex
6720 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
6721         int cnt, ret = 0;
6722         char warntype[MAXQUOTAS];
6723  
6724 +       if ((ret = dl_alloc_inode(inode)))
6725 +               return ret;
6726 +
6727         /* First test before acquiring mutex - solves deadlocks when we
6728           * re-enter the quota code and are already holding the mutex */
6729         if (!dquot_active(inode))
6730 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
6731         char warntype[MAXQUOTAS];
6732         int reserve = flags & DQUOT_SPACE_RESERVE;
6733  
6734 +       dl_free_space(inode, number);
6735 +
6736         /* First test before acquiring mutex - solves deadlocks when we
6737           * re-enter the quota code and are already holding the mutex */
6738         if (!dquot_active(inode)) {
6739 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
6740         unsigned int cnt;
6741         char warntype[MAXQUOTAS];
6742  
6743 +       dl_free_inode(inode);
6744 +
6745         /* First test before acquiring mutex - solves deadlocks when we
6746           * re-enter the quota code and are already holding the mutex */
6747         if (!dquot_active(inode))
6748 diff -NurpP --minimal linux-3.2.8/fs/quota/quota.c linux-3.2.8-vs2.3.2.7/fs/quota/quota.c
6749 --- linux-3.2.8/fs/quota/quota.c        2012-01-09 16:14:55.000000000 +0100
6750 +++ linux-3.2.8-vs2.3.2.7/fs/quota/quota.c      2011-12-05 19:33:02.000000000 +0100
6751 @@ -8,6 +8,7 @@
6752  #include <linux/fs.h>
6753  #include <linux/namei.h>
6754  #include <linux/slab.h>
6755 +#include <linux/vs_context.h>
6756  #include <asm/current.h>
6757  #include <asm/uaccess.h>
6758  #include <linux/kernel.h>
6759 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6760                         break;
6761                 /*FALLTHROUGH*/
6762         default:
6763 -               if (!capable(CAP_SYS_ADMIN))
6764 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6765                         return -EPERM;
6766         }
6767  
6768 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
6769         }
6770  }
6771  
6772 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6773 +
6774 +#include <linux/vroot.h>
6775 +#include <linux/major.h>
6776 +#include <linux/module.h>
6777 +#include <linux/kallsyms.h>
6778 +#include <linux/vserver/debug.h>
6779 +
6780 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6781 +
6782 +static DEFINE_SPINLOCK(vroot_grb_lock);
6783 +
6784 +int register_vroot_grb(vroot_grb_func *func) {
6785 +       int ret = -EBUSY;
6786 +
6787 +       spin_lock(&vroot_grb_lock);
6788 +       if (!vroot_get_real_bdev) {
6789 +               vroot_get_real_bdev = func;
6790 +               ret = 0;
6791 +       }
6792 +       spin_unlock(&vroot_grb_lock);
6793 +       return ret;
6794 +}
6795 +EXPORT_SYMBOL(register_vroot_grb);
6796 +
6797 +int unregister_vroot_grb(vroot_grb_func *func) {
6798 +       int ret = -EINVAL;
6799 +
6800 +       spin_lock(&vroot_grb_lock);
6801 +       if (vroot_get_real_bdev) {
6802 +               vroot_get_real_bdev = NULL;
6803 +               ret = 0;
6804 +       }
6805 +       spin_unlock(&vroot_grb_lock);
6806 +       return ret;
6807 +}
6808 +EXPORT_SYMBOL(unregister_vroot_grb);
6809 +
6810 +#endif
6811 +
6812  /*
6813   * look up a superblock on which quota ops will be performed
6814   * - use the name of a block device to find the superblock thereon
6815 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
6816         putname(tmp);
6817         if (IS_ERR(bdev))
6818                 return ERR_CAST(bdev);
6819 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6820 +       if (bdev && bdev->bd_inode &&
6821 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6822 +               struct block_device *bdnew = (void *)-EINVAL;
6823 +
6824 +               if (vroot_get_real_bdev)
6825 +                       bdnew = vroot_get_real_bdev(bdev);
6826 +               else
6827 +                       vxdprintk(VXD_CBIT(misc, 0),
6828 +                                       "vroot_get_real_bdev not set");
6829 +               bdput(bdev);
6830 +               if (IS_ERR(bdnew))
6831 +                       return ERR_PTR(PTR_ERR(bdnew));
6832 +               bdev = bdnew;
6833 +       }
6834 +#endif
6835         sb = get_super(bdev);
6836         bdput(bdev);
6837         if (!sb)
6838 diff -NurpP --minimal linux-3.2.8/fs/reiserfs/file.c linux-3.2.8-vs2.3.2.7/fs/reiserfs/file.c
6839 --- linux-3.2.8/fs/reiserfs/file.c      2011-10-24 18:45:27.000000000 +0200
6840 +++ linux-3.2.8-vs2.3.2.7/fs/reiserfs/file.c    2011-12-05 19:33:02.000000000 +0100
6841 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6842         .listxattr = reiserfs_listxattr,
6843         .removexattr = reiserfs_removexattr,
6844         .permission = reiserfs_permission,
6845 +       .sync_flags = reiserfs_sync_flags,
6846         .get_acl = reiserfs_get_acl,
6847  };
6848 diff -NurpP --minimal linux-3.2.8/fs/reiserfs/inode.c linux-3.2.8-vs2.3.2.7/fs/reiserfs/inode.c
6849 --- linux-3.2.8/fs/reiserfs/inode.c     2012-01-09 16:14:55.000000000 +0100
6850 +++ linux-3.2.8-vs2.3.2.7/fs/reiserfs/inode.c   2011-12-05 21:18:16.000000000 +0100
6851 @@ -18,6 +18,7 @@
6852  #include <linux/writeback.h>
6853  #include <linux/quotaops.h>
6854  #include <linux/swap.h>
6855 +#include <linux/vs_tag.h>
6856  
6857  int reiserfs_commit_write(struct file *f, struct page *page,
6858                           unsigned from, unsigned to);
6859 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6860         struct buffer_head *bh;
6861         struct item_head *ih;
6862         __u32 rdev;
6863 +       uid_t uid;
6864 +       gid_t gid;
6865         //int version = ITEM_VERSION_1;
6866  
6867         bh = PATH_PLAST_BUFFER(path);
6868 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6869                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6870                 unsigned long blocks;
6871  
6872 +               uid = sd_v1_uid(sd);
6873 +               gid = sd_v1_gid(sd);
6874 +
6875                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6876                 set_inode_sd_version(inode, STAT_DATA_V1);
6877                 inode->i_mode = sd_v1_mode(sd);
6878                 set_nlink(inode, sd_v1_nlink(sd));
6879 -               inode->i_uid = sd_v1_uid(sd);
6880 -               inode->i_gid = sd_v1_gid(sd);
6881                 inode->i_size = sd_v1_size(sd);
6882                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6883                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6884 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6885                 // (directories and symlinks)
6886                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6887  
6888 +               uid    = sd_v2_uid(sd);
6889 +               gid    = sd_v2_gid(sd);
6890 +
6891                 inode->i_mode = sd_v2_mode(sd);
6892                 set_nlink(inode, sd_v2_nlink(sd));
6893 -               inode->i_uid = sd_v2_uid(sd);
6894                 inode->i_size = sd_v2_size(sd);
6895 -               inode->i_gid = sd_v2_gid(sd);
6896                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6897                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6898                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6899 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6900                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6901         }
6902  
6903 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6904 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6905 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6906 +
6907         pathrelse(path);
6908         if (S_ISREG(inode->i_mode)) {
6909                 inode->i_op = &reiserfs_file_inode_operations;
6910 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6911  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6912  {
6913         struct stat_data *sd_v2 = (struct stat_data *)sd;
6914 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6915 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6916         __u16 flags;
6917  
6918 +       set_sd_v2_uid(sd_v2, uid);
6919 +       set_sd_v2_gid(sd_v2, gid);
6920         set_sd_v2_mode(sd_v2, inode->i_mode);
6921         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6922 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6923         set_sd_v2_size(sd_v2, size);
6924 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6925         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6926         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6927         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6928 @@ -2868,14 +2879,19 @@ int reiserfs_commit_write(struct file *f
6929  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6930  {
6931         if (reiserfs_attrs(inode->i_sb)) {
6932 -               if (sd_attrs & REISERFS_SYNC_FL)
6933 -                       inode->i_flags |= S_SYNC;
6934 -               else
6935 -                       inode->i_flags &= ~S_SYNC;
6936                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6937                         inode->i_flags |= S_IMMUTABLE;
6938                 else
6939                         inode->i_flags &= ~S_IMMUTABLE;
6940 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6941 +                       inode->i_flags |= S_IXUNLINK;
6942 +               else
6943 +                       inode->i_flags &= ~S_IXUNLINK;
6944 +
6945 +               if (sd_attrs & REISERFS_SYNC_FL)
6946 +                       inode->i_flags |= S_SYNC;
6947 +               else
6948 +                       inode->i_flags &= ~S_SYNC;
6949                 if (sd_attrs & REISERFS_APPEND_FL)
6950                         inode->i_flags |= S_APPEND;
6951                 else
6952 @@ -2888,6 +2904,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6953                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6954                 else
6955                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6956 +
6957 +               if (sd_attrs & REISERFS_BARRIER_FL)
6958 +                       inode->i_vflags |= V_BARRIER;
6959 +               else
6960 +                       inode->i_vflags &= ~V_BARRIER;
6961 +               if (sd_attrs & REISERFS_COW_FL)
6962 +                       inode->i_vflags |= V_COW;
6963 +               else
6964 +                       inode->i_vflags &= ~V_COW;
6965         }
6966  }
6967  
6968 @@ -2898,6 +2923,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6969                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6970                 else
6971                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6972 +               if (inode->i_flags & S_IXUNLINK)
6973 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6974 +               else
6975 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6976 +
6977                 if (inode->i_flags & S_SYNC)
6978                         *sd_attrs |= REISERFS_SYNC_FL;
6979                 else
6980 @@ -2910,6 +2940,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6981                         *sd_attrs |= REISERFS_NOTAIL_FL;
6982                 else
6983                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6984 +
6985 +               if (inode->i_vflags & V_BARRIER)
6986 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6987 +               else
6988 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6989 +               if (inode->i_vflags & V_COW)
6990 +                       *sd_attrs |= REISERFS_COW_FL;
6991 +               else
6992 +                       *sd_attrs &= ~REISERFS_COW_FL;
6993         }
6994  }
6995  
6996 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
6997         }
6998  
6999         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7000 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7001 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7002 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7003                 struct reiserfs_transaction_handle th;
7004                 int jbegin_count =
7005                     2 *
7006 @@ -3184,6 +3224,9 @@ int reiserfs_setattr(struct dentry *dent
7007                         inode->i_uid = attr->ia_uid;
7008                 if (attr->ia_valid & ATTR_GID)
7009                         inode->i_gid = attr->ia_gid;
7010 +                               if ((attr->ia_valid & ATTR_TAG) &&
7011 +                                       IS_TAGGED(inode))
7012 +                                       inode->i_tag = attr->ia_tag;
7013                 mark_inode_dirty(inode);
7014                 error = journal_end(&th, inode->i_sb, jbegin_count);
7015                 if (error)
7016 diff -NurpP --minimal linux-3.2.8/fs/reiserfs/ioctl.c linux-3.2.8-vs2.3.2.7/fs/reiserfs/ioctl.c
7017 --- linux-3.2.8/fs/reiserfs/ioctl.c     2011-05-22 16:17:53.000000000 +0200
7018 +++ linux-3.2.8-vs2.3.2.7/fs/reiserfs/ioctl.c   2011-12-05 19:33:02.000000000 +0100
7019 @@ -11,6 +11,21 @@
7020  #include <linux/pagemap.h>
7021  #include <linux/compat.h>
7022  
7023 +
7024 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7025 +{
7026 +       __u16 sd_attrs = 0;
7027 +
7028 +       inode->i_flags = flags;
7029 +       inode->i_vflags = vflags;
7030 +
7031 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7032 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7033 +       inode->i_ctime = CURRENT_TIME_SEC;
7034 +       mark_inode_dirty(inode);
7035 +       return 0;
7036 +}
7037 +
7038  /*
7039   * reiserfs_ioctl - handler for ioctl for inode
7040   * supported commands:
7041 @@ -22,7 +37,7 @@
7042  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7043  {
7044         struct inode *inode = filp->f_path.dentry->d_inode;
7045 -       unsigned int flags;
7046 +       unsigned int flags, oldflags;
7047         int err = 0;
7048  
7049         reiserfs_write_lock(inode->i_sb);
7050 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7051  
7052                 flags = REISERFS_I(inode)->i_attrs;
7053                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7054 +               flags &= REISERFS_FL_USER_VISIBLE;
7055                 err = put_user(flags, (int __user *)arg);
7056                 break;
7057         case REISERFS_IOC_SETFLAGS:{
7058 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7059                                 err = -EFAULT;
7060                                 goto setflags_out;
7061                         }
7062 +                       if (IS_BARRIER(inode)) {
7063 +                               vxwprintk_task(1, "messing with the barrier.");
7064 +                               return -EACCES;
7065 +                       }
7066                         /*
7067                          * Is it quota file? Do not allow user to mess with it
7068                          */
7069 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7070                                         goto setflags_out;
7071                                 }
7072                         }
7073 +
7074 +                       oldflags = REISERFS_I(inode)->i_attrs;
7075 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7076 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7077                         sd_attrs_to_i_attrs(flags, inode);
7078                         REISERFS_I(inode)->i_attrs = flags;
7079                         inode->i_ctime = CURRENT_TIME_SEC;
7080 diff -NurpP --minimal linux-3.2.8/fs/reiserfs/namei.c linux-3.2.8-vs2.3.2.7/fs/reiserfs/namei.c
7081 --- linux-3.2.8/fs/reiserfs/namei.c     2012-01-09 16:14:55.000000000 +0100
7082 +++ linux-3.2.8-vs2.3.2.7/fs/reiserfs/namei.c   2011-12-05 19:33:02.000000000 +0100
7083 @@ -18,6 +18,7 @@
7084  #include <linux/reiserfs_acl.h>
7085  #include <linux/reiserfs_xattr.h>
7086  #include <linux/quotaops.h>
7087 +#include <linux/vs_tag.h>
7088  
7089  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); }
7090  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7091 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7092         if (retval == IO_ERROR) {
7093                 return ERR_PTR(-EIO);
7094         }
7095 +               dx_propagate_tag(nd, inode);
7096  
7097         return d_splice_alias(inode, dentry);
7098  }
7099 diff -NurpP --minimal linux-3.2.8/fs/reiserfs/super.c linux-3.2.8-vs2.3.2.7/fs/reiserfs/super.c
7100 --- linux-3.2.8/fs/reiserfs/super.c     2012-02-28 05:53:29.000000000 +0100
7101 +++ linux-3.2.8-vs2.3.2.7/fs/reiserfs/super.c   2012-01-18 02:58:07.000000000 +0100
7102 @@ -903,6 +903,14 @@ static int reiserfs_parse_options(struct
7103                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7104                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7105  #endif
7106 +#ifndef CONFIG_TAGGING_NONE
7107 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7108 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7109 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7110 +#endif
7111 +#ifdef CONFIG_PROPAGATE
7112 +               {"tag",.arg_required = 'T',.values = NULL},
7113 +#endif
7114  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7115                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7116                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7117 @@ -1213,6 +1221,14 @@ static int reiserfs_remount(struct super
7118         handle_quota_files(s, qf_names, &qfmt);
7119  #endif
7120  
7121 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7122 +               !(s->s_flags & MS_TAGGED)) {
7123 +               reiserfs_warning(s, "super-vs01",
7124 +                       "reiserfs: tagging not permitted on remount.");
7125 +               err = -EINVAL;
7126 +               goto out_err;
7127 +       }
7128 +
7129         handle_attrs(s);
7130  
7131         /* Add options that are safe here */
7132 @@ -1696,6 +1712,10 @@ static int reiserfs_fill_super(struct su
7133                 goto error;
7134         }
7135  
7136 +       /* map mount option tagxid */
7137 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7138 +               s->s_flags |= MS_TAGGED;
7139 +
7140         rs = SB_DISK_SUPER_BLOCK(s);
7141         /* Let's do basic sanity check to verify that underlying device is not
7142            smaller than the filesystem. If the check fails then abort and scream,
7143 diff -NurpP --minimal linux-3.2.8/fs/reiserfs/xattr.c linux-3.2.8-vs2.3.2.7/fs/reiserfs/xattr.c
7144 --- linux-3.2.8/fs/reiserfs/xattr.c     2011-10-24 18:45:27.000000000 +0200
7145 +++ linux-3.2.8-vs2.3.2.7/fs/reiserfs/xattr.c   2011-12-05 19:33:02.000000000 +0100
7146 @@ -40,6 +40,7 @@
7147  #include <linux/errno.h>
7148  #include <linux/gfp.h>
7149  #include <linux/fs.h>
7150 +#include <linux/mount.h>
7151  #include <linux/file.h>
7152  #include <linux/pagemap.h>
7153  #include <linux/xattr.h>
7154 diff -NurpP --minimal linux-3.2.8/fs/stat.c linux-3.2.8-vs2.3.2.7/fs/stat.c
7155 --- linux-3.2.8/fs/stat.c       2012-01-09 16:14:55.000000000 +0100
7156 +++ linux-3.2.8-vs2.3.2.7/fs/stat.c     2011-12-05 19:33:02.000000000 +0100
7157 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7158         stat->nlink = inode->i_nlink;
7159         stat->uid = inode->i_uid;
7160         stat->gid = inode->i_gid;
7161 +       stat->tag = inode->i_tag;
7162         stat->rdev = inode->i_rdev;
7163         stat->size = i_size_read(inode);
7164         stat->atime = inode->i_atime;
7165 diff -NurpP --minimal linux-3.2.8/fs/statfs.c linux-3.2.8-vs2.3.2.7/fs/statfs.c
7166 --- linux-3.2.8/fs/statfs.c     2012-01-09 16:14:55.000000000 +0100
7167 +++ linux-3.2.8-vs2.3.2.7/fs/statfs.c   2011-12-05 19:33:02.000000000 +0100
7168 @@ -7,6 +7,8 @@
7169  #include <linux/statfs.h>
7170  #include <linux/security.h>
7171  #include <linux/uaccess.h>
7172 +#include <linux/vs_base.h>
7173 +#include <linux/vs_dlimit.h>
7174  
7175  static int flags_by_mnt(int mnt_flags)
7176  {
7177 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7178         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7179         if (retval == 0 && buf->f_frsize == 0)
7180                 buf->f_frsize = buf->f_bsize;
7181 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7182 +               vx_vsi_statfs(dentry->d_sb, buf);
7183         return retval;
7184  }
7185  
7186 diff -NurpP --minimal linux-3.2.8/fs/super.c linux-3.2.8-vs2.3.2.7/fs/super.c
7187 --- linux-3.2.8/fs/super.c      2012-01-09 16:14:55.000000000 +0100
7188 +++ linux-3.2.8-vs2.3.2.7/fs/super.c    2011-12-05 19:33:02.000000000 +0100
7189 @@ -32,6 +32,9 @@
7190  #include <linux/backing-dev.h>
7191  #include <linux/rculist_bl.h>
7192  #include <linux/cleancache.h>
7193 +#include <linux/devpts_fs.h>
7194 +#include <linux/proc_fs.h>
7195 +#include <linux/vs_context.h>
7196  #include "internal.h"
7197  
7198  
7199 @@ -1100,6 +1103,13 @@ mount_fs(struct file_system_type *type, 
7200         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7201         sb->s_flags |= MS_BORN;
7202  
7203 +       error = -EPERM;
7204 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7205 +               !sb->s_bdev &&
7206 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7207 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7208 +               goto out_sb;
7209 +
7210         error = security_sb_kern_mount(sb, flags, secdata);
7211         if (error)
7212                 goto out_sb;
7213 diff -NurpP --minimal linux-3.2.8/fs/sysfs/mount.c linux-3.2.8-vs2.3.2.7/fs/sysfs/mount.c
7214 --- linux-3.2.8/fs/sysfs/mount.c        2011-07-22 11:18:06.000000000 +0200
7215 +++ linux-3.2.8-vs2.3.2.7/fs/sysfs/mount.c      2011-12-05 19:33:02.000000000 +0100
7216 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7217  
7218         sb->s_blocksize = PAGE_CACHE_SIZE;
7219         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7220 -       sb->s_magic = SYSFS_MAGIC;
7221 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7222         sb->s_op = &sysfs_ops;
7223         sb->s_time_gran = 1;
7224  
7225 diff -NurpP --minimal linux-3.2.8/fs/utimes.c linux-3.2.8-vs2.3.2.7/fs/utimes.c
7226 --- linux-3.2.8/fs/utimes.c     2011-05-22 16:17:54.000000000 +0200
7227 +++ linux-3.2.8-vs2.3.2.7/fs/utimes.c   2011-12-05 19:33:02.000000000 +0100
7228 @@ -8,6 +8,8 @@
7229  #include <linux/stat.h>
7230  #include <linux/utime.h>
7231  #include <linux/syscalls.h>
7232 +#include <linux/mount.h>
7233 +#include <linux/vs_cowbl.h>
7234  #include <asm/uaccess.h>
7235  #include <asm/unistd.h>
7236  
7237 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7238  {
7239         int error;
7240         struct iattr newattrs;
7241 -       struct inode *inode = path->dentry->d_inode;
7242 +       struct inode *inode;
7243  
7244         error = mnt_want_write(path->mnt);
7245         if (error)
7246                 goto out;
7247  
7248 +       error = cow_check_and_break(path);
7249 +       if (error)
7250 +               goto mnt_drop_write_and_out;
7251 +
7252 +       inode = path->dentry->d_inode;
7253 +
7254         if (times && times[0].tv_nsec == UTIME_NOW &&
7255                      times[1].tv_nsec == UTIME_NOW)
7256                 times = NULL;
7257 diff -NurpP --minimal linux-3.2.8/fs/xattr.c linux-3.2.8-vs2.3.2.7/fs/xattr.c
7258 --- linux-3.2.8/fs/xattr.c      2012-01-09 16:14:55.000000000 +0100
7259 +++ linux-3.2.8-vs2.3.2.7/fs/xattr.c    2011-12-05 19:33:02.000000000 +0100
7260 @@ -19,6 +19,7 @@
7261  #include <linux/module.h>
7262  #include <linux/fsnotify.h>
7263  #include <linux/audit.h>
7264 +#include <linux/mount.h>
7265  #include <asm/uaccess.h>
7266  
7267  
7268 @@ -50,7 +51,7 @@ xattr_permission(struct inode *inode, co
7269          * The trusted.* namespace can only be accessed by privileged users.
7270          */
7271         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7272 -               if (!capable(CAP_SYS_ADMIN))
7273 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7274                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7275                 return 0;
7276         }
7277 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_dinode.h linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_dinode.h
7278 --- linux-3.2.8/fs/xfs/xfs_dinode.h     2011-10-24 18:45:31.000000000 +0200
7279 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_dinode.h   2011-12-05 19:33:02.000000000 +0100
7280 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7281         __be32          di_nlink;       /* number of links to file */
7282         __be16          di_projid_lo;   /* lower part of owner's project id */
7283         __be16          di_projid_hi;   /* higher part owner's project id */
7284 -       __u8            di_pad[6];      /* unused, zeroed space */
7285 +       __u8            di_pad[2];      /* unused, zeroed space */
7286 +       __be16          di_tag;         /* context tagging */
7287 +       __be16          di_vflags;      /* vserver specific flags */
7288         __be16          di_flushiter;   /* incremented on flush */
7289         xfs_timestamp_t di_atime;       /* time last accessed */
7290         xfs_timestamp_t di_mtime;       /* time last modified */
7291 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7292  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7293  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7294  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7295 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7296 +
7297  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7298  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7299  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7300 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7301  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7302  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7303  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7304 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7305  
7306  #ifdef CONFIG_XFS_RT
7307  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7308 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7309          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7310          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7311          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7312 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7313 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7314 +        XFS_DIFLAG_IXUNLINK)
7315 +
7316 +#define XFS_DIVFLAG_BARRIER    0x01
7317 +#define XFS_DIVFLAG_COW                0x02
7318  
7319  #endif /* __XFS_DINODE_H__ */
7320 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_fs.h linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_fs.h
7321 --- linux-3.2.8/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7322 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_fs.h       2011-12-05 19:33:02.000000000 +0100
7323 @@ -67,6 +67,9 @@ struct fsxattr {
7324  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7325  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7326  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7327 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7328 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7329 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7330  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7331  
7332  /*
7333 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7334  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7335         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7336         __u16           bs_projid_hi;   /* higher part of project id    */
7337 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7338 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7339 +       __u16           bs_tag;         /* context tagging              */
7340         __u32           bs_dmevmask;    /* DMIG event mask              */
7341         __u16           bs_dmstate;     /* DMIG state info              */
7342         __u16           bs_aextents;    /* attribute number of extents  */
7343 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_ialloc.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_ialloc.c
7344 --- linux-3.2.8/fs/xfs/xfs_ialloc.c     2012-01-09 16:14:55.000000000 +0100
7345 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_ialloc.c   2011-12-05 19:33:02.000000000 +0100
7346 @@ -37,7 +37,6 @@
7347  #include "xfs_error.h"
7348  #include "xfs_bmap.h"
7349  
7350 -
7351  /*
7352   * Allocation group level functions.
7353   */
7354 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_inode.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_inode.c
7355 --- linux-3.2.8/fs/xfs/xfs_inode.c      2012-01-09 16:14:55.000000000 +0100
7356 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_inode.c    2011-12-15 01:11:32.000000000 +0100
7357 @@ -236,6 +236,7 @@ xfs_inotobp(
7358         return 0;
7359  }
7360  
7361 +#include <linux/vs_tag.h>
7362  
7363  /*
7364   * This routine is called to map an inode to the buffer containing
7365 @@ -634,15 +635,25 @@ xfs_iformat_btree(
7366  STATIC void
7367  xfs_dinode_from_disk(
7368         xfs_icdinode_t          *to,
7369 -       xfs_dinode_t            *from)
7370 +       xfs_dinode_t            *from,
7371 +       int tagged)
7372  {
7373 +       uint32_t uid, gid, tag;
7374 +
7375         to->di_magic = be16_to_cpu(from->di_magic);
7376         to->di_mode = be16_to_cpu(from->di_mode);
7377         to->di_version = from ->di_version;
7378         to->di_format = from->di_format;
7379         to->di_onlink = be16_to_cpu(from->di_onlink);
7380 -       to->di_uid = be32_to_cpu(from->di_uid);
7381 -       to->di_gid = be32_to_cpu(from->di_gid);
7382 +
7383 +       uid = be32_to_cpu(from->di_uid);
7384 +       gid = be32_to_cpu(from->di_gid);
7385 +       tag = be16_to_cpu(from->di_tag);
7386 +
7387 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7388 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7389 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7390 +
7391         to->di_nlink = be32_to_cpu(from->di_nlink);
7392         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7393         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7394 @@ -664,21 +675,26 @@ xfs_dinode_from_disk(
7395         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7396         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7397         to->di_flags    = be16_to_cpu(from->di_flags);
7398 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7399         to->di_gen      = be32_to_cpu(from->di_gen);
7400  }
7401  
7402  void
7403  xfs_dinode_to_disk(
7404         xfs_dinode_t            *to,
7405 -       xfs_icdinode_t          *from)
7406 +       xfs_icdinode_t          *from,
7407 +       int tagged)
7408  {
7409         to->di_magic = cpu_to_be16(from->di_magic);
7410         to->di_mode = cpu_to_be16(from->di_mode);
7411         to->di_version = from ->di_version;
7412         to->di_format = from->di_format;
7413         to->di_onlink = cpu_to_be16(from->di_onlink);
7414 -       to->di_uid = cpu_to_be32(from->di_uid);
7415 -       to->di_gid = cpu_to_be32(from->di_gid);
7416 +
7417 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7418 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7419 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7420 +
7421         to->di_nlink = cpu_to_be32(from->di_nlink);
7422         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7423         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7424 @@ -700,12 +716,14 @@ xfs_dinode_to_disk(
7425         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7426         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7427         to->di_flags = cpu_to_be16(from->di_flags);
7428 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7429         to->di_gen = cpu_to_be32(from->di_gen);
7430  }
7431  
7432  STATIC uint
7433  _xfs_dic2xflags(
7434 -       __uint16_t              di_flags)
7435 +       __uint16_t              di_flags,
7436 +       __uint16_t              di_vflags)
7437  {
7438         uint                    flags = 0;
7439  
7440 @@ -716,6 +734,8 @@ _xfs_dic2xflags(
7441                         flags |= XFS_XFLAG_PREALLOC;
7442                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7443                         flags |= XFS_XFLAG_IMMUTABLE;
7444 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7445 +                       flags |= XFS_XFLAG_IXUNLINK;
7446                 if (di_flags & XFS_DIFLAG_APPEND)
7447                         flags |= XFS_XFLAG_APPEND;
7448                 if (di_flags & XFS_DIFLAG_SYNC)
7449 @@ -740,6 +760,10 @@ _xfs_dic2xflags(
7450                         flags |= XFS_XFLAG_FILESTREAM;
7451         }
7452  
7453 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7454 +               flags |= FS_BARRIER_FL;
7455 +       if (di_vflags & XFS_DIVFLAG_COW)
7456 +               flags |= FS_COW_FL;
7457         return flags;
7458  }
7459  
7460 @@ -749,7 +773,7 @@ xfs_ip2xflags(
7461  {
7462         xfs_icdinode_t          *dic = &ip->i_d;
7463  
7464 -       return _xfs_dic2xflags(dic->di_flags) |
7465 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7466                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7467  }
7468  
7469 @@ -757,7 +781,8 @@ uint
7470  xfs_dic2xflags(
7471         xfs_dinode_t            *dip)
7472  {
7473 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7474 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7475 +                               be16_to_cpu(dip->di_vflags)) |
7476                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7477  }
7478  
7479 @@ -790,7 +815,6 @@ xfs_iread(
7480         if (error)
7481                 return error;
7482         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7483 -
7484         /*
7485          * If we got something that isn't an inode it means someone
7486          * (nfs or dmi) has a stale handle.
7487 @@ -813,7 +837,8 @@ xfs_iread(
7488          * Otherwise, just get the truly permanent information.
7489          */
7490         if (dip->di_mode) {
7491 -               xfs_dinode_from_disk(&ip->i_d, dip);
7492 +               xfs_dinode_from_disk(&ip->i_d, dip,
7493 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7494                 error = xfs_iformat(ip, dip);
7495                 if (error)  {
7496  #ifdef DEBUG
7497 @@ -1008,6 +1033,7 @@ xfs_ialloc(
7498         ASSERT(ip->i_d.di_nlink == nlink);
7499         ip->i_d.di_uid = current_fsuid();
7500         ip->i_d.di_gid = current_fsgid();
7501 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7502         xfs_set_projid(ip, prid);
7503         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7504  
7505 @@ -1068,6 +1094,7 @@ xfs_ialloc(
7506         ip->i_d.di_dmevmask = 0;
7507         ip->i_d.di_dmstate = 0;
7508         ip->i_d.di_flags = 0;
7509 +       ip->i_d.di_vflags = 0;
7510         flags = XFS_ILOG_CORE;
7511         switch (mode & S_IFMT) {
7512         case S_IFIFO:
7513 @@ -1842,6 +1869,7 @@ xfs_ifree(
7514         }
7515         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7516         ip->i_d.di_flags = 0;
7517 +       ip->i_d.di_vflags = 0;
7518         ip->i_d.di_dmevmask = 0;
7519         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7520         ip->i_df.if_ext_max =
7521 @@ -2723,7 +2751,8 @@ xfs_iflush_int(
7522          * because if the inode is dirty at all the core must
7523          * be.
7524          */
7525 -       xfs_dinode_to_disk(dip, &ip->i_d);
7526 +       xfs_dinode_to_disk(dip, &ip->i_d,
7527 +               mp->m_flags & XFS_MOUNT_TAGGED);
7528  
7529         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7530         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7531 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_inode.h linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_inode.h
7532 --- linux-3.2.8/fs/xfs/xfs_inode.h      2012-01-09 16:14:55.000000000 +0100
7533 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_inode.h    2011-12-15 01:11:32.000000000 +0100
7534 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
7535         __uint32_t      di_nlink;       /* number of links to file */
7536         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7537         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7538 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7539 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7540 +       __uint16_t      di_tag;         /* context tagging */
7541 +       __uint16_t      di_vflags;      /* vserver specific flags */
7542         __uint16_t      di_flushiter;   /* incremented on flush */
7543         xfs_ictimestamp_t di_atime;     /* time last accessed */
7544         xfs_ictimestamp_t di_mtime;     /* time last modified */
7545 @@ -536,7 +538,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7546  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7547                           struct xfs_inode *, uint);
7548  void           xfs_dinode_to_disk(struct xfs_dinode *,
7549 -                                  struct xfs_icdinode *);
7550 +                                  struct xfs_icdinode *, int);
7551  void           xfs_idestroy_fork(struct xfs_inode *, int);
7552  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7553  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7554 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_ioctl.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_ioctl.c
7555 --- linux-3.2.8/fs/xfs/xfs_ioctl.c      2012-01-09 16:14:55.000000000 +0100
7556 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_ioctl.c    2011-12-05 19:33:02.000000000 +0100
7557 @@ -28,7 +28,7 @@
7558  #include "xfs_bmap_btree.h"
7559  #include "xfs_dinode.h"
7560  #include "xfs_inode.h"
7561 -#include "xfs_ioctl.h"
7562 +// #include "xfs_ioctl.h"
7563  #include "xfs_rtalloc.h"
7564  #include "xfs_itable.h"
7565  #include "xfs_error.h"
7566 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7567                 xflags |= XFS_XFLAG_IMMUTABLE;
7568         else
7569                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7570 +       if (flags & FS_IXUNLINK_FL)
7571 +               xflags |= XFS_XFLAG_IXUNLINK;
7572 +       else
7573 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7574         if (flags & FS_APPEND_FL)
7575                 xflags |= XFS_XFLAG_APPEND;
7576         else
7577 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7578  
7579         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7580                 flags |= FS_IMMUTABLE_FL;
7581 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7582 +               flags |= FS_IXUNLINK_FL;
7583         if (di_flags & XFS_DIFLAG_APPEND)
7584                 flags |= FS_APPEND_FL;
7585         if (di_flags & XFS_DIFLAG_SYNC)
7586 @@ -836,6 +842,8 @@ xfs_set_diflags(
7587         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7588         if (xflags & XFS_XFLAG_IMMUTABLE)
7589                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7590 +       if (xflags & XFS_XFLAG_IXUNLINK)
7591 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7592         if (xflags & XFS_XFLAG_APPEND)
7593                 di_flags |= XFS_DIFLAG_APPEND;
7594         if (xflags & XFS_XFLAG_SYNC)
7595 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7596                 inode->i_flags |= S_IMMUTABLE;
7597         else
7598                 inode->i_flags &= ~S_IMMUTABLE;
7599 +       if (xflags & XFS_XFLAG_IXUNLINK)
7600 +               inode->i_flags |= S_IXUNLINK;
7601 +       else
7602 +               inode->i_flags &= ~S_IXUNLINK;
7603         if (xflags & XFS_XFLAG_APPEND)
7604                 inode->i_flags |= S_APPEND;
7605         else
7606 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7607         case XFS_IOC_FSGETXATTRA:
7608                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7609         case XFS_IOC_FSSETXATTR:
7610 +               if (IS_BARRIER(inode)) {
7611 +                       vxwprintk_task(1, "messing with the barrier.");
7612 +                       return -XFS_ERROR(EACCES);
7613 +               }
7614                 return xfs_ioc_fssetxattr(ip, filp, arg);
7615         case XFS_IOC_GETXFLAGS:
7616                 return xfs_ioc_getxflags(ip, arg);
7617         case XFS_IOC_SETXFLAGS:
7618 +               if (IS_BARRIER(inode)) {
7619 +                       vxwprintk_task(1, "messing with the barrier.");
7620 +                       return -XFS_ERROR(EACCES);
7621 +               }
7622                 return xfs_ioc_setxflags(ip, filp, arg);
7623  
7624         case XFS_IOC_FSSETDM: {
7625 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_ioctl.h linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_ioctl.h
7626 --- linux-3.2.8/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7627 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_ioctl.h    2011-12-05 19:33:02.000000000 +0100
7628 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7629         void __user             *uhandle,
7630         u32                     hlen);
7631  
7632 +extern int
7633 +xfs_sync_flags(
7634 +       struct inode            *inode,
7635 +       int                     flags,
7636 +       int                     vflags);
7637 +
7638  extern long
7639  xfs_file_ioctl(
7640         struct file             *filp,
7641 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_iops.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_iops.c
7642 --- linux-3.2.8/fs/xfs/xfs_iops.c       2012-01-09 16:14:55.000000000 +0100
7643 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_iops.c     2011-12-05 19:33:02.000000000 +0100
7644 @@ -30,6 +30,7 @@
7645  #include "xfs_bmap_btree.h"
7646  #include "xfs_dinode.h"
7647  #include "xfs_inode.h"
7648 +#include "xfs_ioctl.h"
7649  #include "xfs_bmap.h"
7650  #include "xfs_rtalloc.h"
7651  #include "xfs_error.h"
7652 @@ -49,6 +50,7 @@
7653  #include <linux/security.h>
7654  #include <linux/fiemap.h>
7655  #include <linux/slab.h>
7656 +#include <linux/vs_tag.h>
7657  
7658  /*
7659   * Bring the timestamps in the XFS inode uptodate.
7660 @@ -474,6 +476,7 @@ xfs_vn_getattr(
7661         stat->nlink = ip->i_d.di_nlink;
7662         stat->uid = ip->i_d.di_uid;
7663         stat->gid = ip->i_d.di_gid;
7664 +       stat->tag = ip->i_d.di_tag;
7665         stat->ino = ip->i_ino;
7666         stat->atime = inode->i_atime;
7667         stat->mtime = inode->i_mtime;
7668 @@ -1039,6 +1042,7 @@ static const struct inode_operations xfs
7669         .removexattr            = generic_removexattr,
7670         .listxattr              = xfs_vn_listxattr,
7671         .fiemap                 = xfs_vn_fiemap,
7672 +       .sync_flags             = xfs_sync_flags,
7673  };
7674  
7675  static const struct inode_operations xfs_dir_inode_operations = {
7676 @@ -1064,6 +1068,7 @@ static const struct inode_operations xfs
7677         .getxattr               = generic_getxattr,
7678         .removexattr            = generic_removexattr,
7679         .listxattr              = xfs_vn_listxattr,
7680 +       .sync_flags             = xfs_sync_flags,
7681  };
7682  
7683  static const struct inode_operations xfs_dir_ci_inode_operations = {
7684 @@ -1113,6 +1118,10 @@ xfs_diflags_to_iflags(
7685                 inode->i_flags |= S_IMMUTABLE;
7686         else
7687                 inode->i_flags &= ~S_IMMUTABLE;
7688 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7689 +               inode->i_flags |= S_IXUNLINK;
7690 +       else
7691 +               inode->i_flags &= ~S_IXUNLINK;
7692         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7693                 inode->i_flags |= S_APPEND;
7694         else
7695 @@ -1125,6 +1134,15 @@ xfs_diflags_to_iflags(
7696                 inode->i_flags |= S_NOATIME;
7697         else
7698                 inode->i_flags &= ~S_NOATIME;
7699 +
7700 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7701 +               inode->i_vflags |= V_BARRIER;
7702 +       else
7703 +               inode->i_vflags &= ~V_BARRIER;
7704 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7705 +               inode->i_vflags |= V_COW;
7706 +       else
7707 +               inode->i_vflags &= ~V_COW;
7708  }
7709  
7710  /*
7711 @@ -1156,6 +1174,7 @@ xfs_setup_inode(
7712         set_nlink(inode, ip->i_d.di_nlink);
7713         inode->i_uid    = ip->i_d.di_uid;
7714         inode->i_gid    = ip->i_d.di_gid;
7715 +       inode->i_tag    = ip->i_d.di_tag;
7716  
7717         switch (inode->i_mode & S_IFMT) {
7718         case S_IFBLK:
7719 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_itable.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_itable.c
7720 --- linux-3.2.8/fs/xfs/xfs_itable.c     2011-05-22 16:17:54.000000000 +0200
7721 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_itable.c   2011-12-05 19:33:02.000000000 +0100
7722 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
7723         buf->bs_mode = dic->di_mode;
7724         buf->bs_uid = dic->di_uid;
7725         buf->bs_gid = dic->di_gid;
7726 +       buf->bs_tag = dic->di_tag;
7727         buf->bs_size = dic->di_size;
7728  
7729         /*
7730 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_linux.h linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_linux.h
7731 --- linux-3.2.8/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7732 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_linux.h    2011-12-05 19:33:02.000000000 +0100
7733 @@ -121,6 +121,7 @@
7734  
7735  #define current_cpu()          (raw_smp_processor_id())
7736  #define current_pid()          (current->pid)
7737 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7738  #define current_test_flags(f)  (current->flags & (f))
7739  #define current_set_flags_nested(sp, f)                \
7740                 (*(sp) = current->flags, current->flags |= (f))
7741 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_log_recover.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_log_recover.c
7742 --- linux-3.2.8/fs/xfs/xfs_log_recover.c        2012-01-09 16:14:55.000000000 +0100
7743 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_log_recover.c      2011-12-05 19:33:02.000000000 +0100
7744 @@ -2344,7 +2344,8 @@ xlog_recover_inode_pass2(
7745         }
7746  
7747         /* The core is in in-core format */
7748 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7749 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7750 +               mp->m_flags & XFS_MOUNT_TAGGED);
7751  
7752         /* the rest is in on-disk format */
7753         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7754 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_mount.h linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_mount.h
7755 --- linux-3.2.8/fs/xfs/xfs_mount.h      2011-10-24 18:45:31.000000000 +0200
7756 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_mount.h    2011-12-05 19:33:02.000000000 +0100
7757 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
7758                                                    allocator */
7759  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7760  
7761 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7762  
7763  /*
7764   * Default minimum read and write sizes.
7765 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_super.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_super.c
7766 --- linux-3.2.8/fs/xfs/xfs_super.c      2012-01-09 16:14:55.000000000 +0100
7767 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_super.c    2012-01-09 16:19:31.000000000 +0100
7768 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7769  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7770  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7771  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7772 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7773 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7774 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7775  
7776  /*
7777   * Table driven mount option parser.
7778 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7779   * in the future, too.
7780   */
7781  enum {
7782 +       Opt_tag, Opt_notag,
7783         Opt_barrier, Opt_nobarrier, Opt_err
7784  };
7785  
7786  static const match_table_t tokens = {
7787 +       {Opt_tag, "tagxid"},
7788 +       {Opt_tag, "tag"},
7789 +       {Opt_notag, "notag"},
7790         {Opt_barrier, "barrier"},
7791         {Opt_nobarrier, "nobarrier"},
7792         {Opt_err, NULL}
7793 @@ -374,6 +381,19 @@ xfs_parseargs(
7794                 } else if (!strcmp(this_char, "irixsgid")) {
7795                         xfs_warn(mp,
7796         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7797 +#ifndef CONFIG_TAGGING_NONE
7798 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7799 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7800 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7801 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7802 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7803 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7804 +#endif
7805 +#ifdef CONFIG_PROPAGATE
7806 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7807 +                       /* use value */
7808 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7809 +#endif
7810                 } else {
7811                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7812                         return EINVAL;
7813 @@ -1138,6 +1158,16 @@ xfs_fs_remount(
7814                 case Opt_nobarrier:
7815                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7816                         break;
7817 +               case Opt_tag:
7818 +                       if (!(sb->s_flags & MS_TAGGED)) {
7819 +                               printk(KERN_INFO
7820 +                                       "XFS: %s: tagging not permitted on remount.\n",
7821 +                                       sb->s_id);
7822 +                               return -EINVAL;
7823 +                       }
7824 +                       break;
7825 +               case Opt_notag:
7826 +                       break;
7827                 default:
7828                         /*
7829                          * Logically we would return an error here to prevent
7830 @@ -1353,6 +1383,9 @@ xfs_fs_fill_super(
7831         if (error)
7832                 goto out_free_sb;
7833  
7834 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7835 +               sb->s_flags |= MS_TAGGED;
7836 +
7837         /*
7838          * we must configure the block size in the superblock before we run the
7839          * full mount process as the mount process can lookup and cache inodes.
7840 diff -NurpP --minimal linux-3.2.8/fs/xfs/xfs_vnodeops.c linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_vnodeops.c
7841 --- linux-3.2.8/fs/xfs/xfs_vnodeops.c   2012-02-28 05:53:29.000000000 +0100
7842 +++ linux-3.2.8-vs2.3.2.7/fs/xfs/xfs_vnodeops.c 2012-02-07 03:14:01.000000000 +0100
7843 @@ -106,6 +106,77 @@ xfs_readlink_bmap(
7844         return error;
7845  }
7846  
7847 +
7848 +STATIC void
7849 +xfs_get_inode_flags(
7850 +       xfs_inode_t     *ip)
7851 +{
7852 +       struct inode    *inode = VFS_I(ip);
7853 +       unsigned int    flags = inode->i_flags;
7854 +       unsigned int    vflags = inode->i_vflags;
7855 +
7856 +       if (flags & S_IMMUTABLE)
7857 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7858 +       else
7859 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7860 +       if (flags & S_IXUNLINK)
7861 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7862 +       else
7863 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7864 +
7865 +       if (vflags & V_BARRIER)
7866 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7867 +       else
7868 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7869 +       if (vflags & V_COW)
7870 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7871 +       else
7872 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7873 +}
7874 +
7875 +int
7876 +xfs_sync_flags(
7877 +       struct inode            *inode,
7878 +       int                     flags,
7879 +       int                     vflags)
7880 +{
7881 +       struct xfs_inode        *ip = XFS_I(inode);
7882 +       struct xfs_mount        *mp = ip->i_mount;
7883 +       struct xfs_trans        *tp;
7884 +       unsigned int            lock_flags = 0;
7885 +       int                     code;
7886 +
7887 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7888 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7889 +       if (code)
7890 +               goto error_out;
7891 +
7892 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7893 +       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
7894 +
7895 +       inode->i_flags = flags;
7896 +       inode->i_vflags = vflags;
7897 +       xfs_get_inode_flags(ip);
7898 +
7899 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7900 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7901 +
7902 +       XFS_STATS_INC(xs_ig_attrchg);
7903 +
7904 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7905 +               xfs_trans_set_sync(tp);
7906 +       code = xfs_trans_commit(tp, 0);
7907 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7908 +       return code;
7909 +
7910 +error_out:
7911 +       xfs_trans_cancel(tp, 0);
7912 +       if (lock_flags)
7913 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7914 +       return code;
7915 +}
7916 +
7917 +
7918  int
7919  xfs_readlink(
7920         xfs_inode_t     *ip,
7921 diff -NurpP --minimal linux-3.2.8/include/linux/Kbuild linux-3.2.8-vs2.3.2.7/include/linux/Kbuild
7922 --- linux-3.2.8/include/linux/Kbuild    2011-10-24 18:45:31.000000000 +0200
7923 +++ linux-3.2.8-vs2.3.2.7/include/linux/Kbuild  2011-12-05 19:33:02.000000000 +0100
7924 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
7925  header-y += netfilter_ipv4/
7926  header-y += netfilter_ipv6/
7927  header-y += usb/
7928 +header-y += vserver/
7929  header-y += wimax/
7930  
7931  objhdr-y += version.h
7932 diff -NurpP --minimal linux-3.2.8/include/linux/capability.h linux-3.2.8-vs2.3.2.7/include/linux/capability.h
7933 --- linux-3.2.8/include/linux/capability.h      2012-01-09 16:14:56.000000000 +0100
7934 +++ linux-3.2.8-vs2.3.2.7/include/linux/capability.h    2011-12-05 19:33:02.000000000 +0100
7935 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7936     arbitrary SCSI commands */
7937  /* Allow setting encryption key on loopback filesystem */
7938  /* Allow setting zone reclaim policy */
7939 +/* Allow the selection of a security context */
7940  
7941  #define CAP_SYS_ADMIN        21
7942  
7943 @@ -363,7 +364,12 @@ struct cpu_vfs_cap_data {
7944  
7945  #define CAP_LAST_CAP         CAP_WAKE_ALARM
7946  
7947 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7948 +/* Allow context manipulations */
7949 +/* Allow changing context info on files */
7950 +
7951 +#define CAP_CONTEXT         63
7952 +
7953 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7954  
7955  /*
7956   * Bit location of each capability (used by user-space library and kernel)
7957 diff -NurpP --minimal linux-3.2.8/include/linux/cred.h linux-3.2.8-vs2.3.2.7/include/linux/cred.h
7958 --- linux-3.2.8/include/linux/cred.h    2011-10-24 18:45:31.000000000 +0200
7959 +++ linux-3.2.8-vs2.3.2.7/include/linux/cred.h  2011-12-05 19:33:02.000000000 +0100
7960 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
7961  extern int copy_creds(struct task_struct *, unsigned long);
7962  extern const struct cred *get_task_cred(struct task_struct *);
7963  extern struct cred *cred_alloc_blank(void);
7964 +extern struct cred *__prepare_creds(const struct cred *);
7965  extern struct cred *prepare_creds(void);
7966  extern struct cred *prepare_exec_creds(void);
7967  extern int commit_creds(struct cred *);
7968 @@ -209,6 +210,31 @@ static inline void validate_process_cred
7969  }
7970  #endif
7971  
7972 +static inline void set_cred_subscribers(struct cred *cred, int n)
7973 +{
7974 +#ifdef CONFIG_DEBUG_CREDENTIALS
7975 +       atomic_set(&cred->subscribers, n);
7976 +#endif
7977 +}
7978 +
7979 +static inline int read_cred_subscribers(const struct cred *cred)
7980 +{
7981 +#ifdef CONFIG_DEBUG_CREDENTIALS
7982 +       return atomic_read(&cred->subscribers);
7983 +#else
7984 +       return 0;
7985 +#endif
7986 +}
7987 +
7988 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7989 +{
7990 +#ifdef CONFIG_DEBUG_CREDENTIALS
7991 +       struct cred *cred = (struct cred *) _cred;
7992 +
7993 +       atomic_add(n, &cred->subscribers);
7994 +#endif
7995 +}
7996 +
7997  /**
7998   * get_new_cred - Get a reference on a new set of credentials
7999   * @cred: The new credentials to reference
8000 diff -NurpP --minimal linux-3.2.8/include/linux/devpts_fs.h linux-3.2.8-vs2.3.2.7/include/linux/devpts_fs.h
8001 --- linux-3.2.8/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
8002 +++ linux-3.2.8-vs2.3.2.7/include/linux/devpts_fs.h     2011-12-05 19:33:02.000000000 +0100
8003 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8004  
8005  #endif
8006  
8007 -
8008  #endif /* _LINUX_DEVPTS_FS_H */
8009 diff -NurpP --minimal linux-3.2.8/include/linux/ext2_fs.h linux-3.2.8-vs2.3.2.7/include/linux/ext2_fs.h
8010 --- linux-3.2.8/include/linux/ext2_fs.h 2012-01-09 16:14:56.000000000 +0100
8011 +++ linux-3.2.8-vs2.3.2.7/include/linux/ext2_fs.h       2011-12-05 19:33:02.000000000 +0100
8012 @@ -190,8 +190,12 @@ struct ext2_group_desc
8013  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8014  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8015  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8016 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8017  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8018  
8019 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8020 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8021 +
8022  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8023  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8024  
8025 @@ -275,7 +279,8 @@ struct ext2_inode {
8026                         __u16   i_pad1;
8027                         __le16  l_i_uid_high;   /* these 2 fields    */
8028                         __le16  l_i_gid_high;   /* were reserved2[0] */
8029 -                       __u32   l_i_reserved2;
8030 +                       __le16  l_i_tag;        /* Context Tag */
8031 +                       __u16   l_i_reserved2;
8032                 } linux2;
8033                 struct {
8034                         __u8    h_i_frag;       /* Fragment number */
8035 @@ -304,6 +309,7 @@ struct ext2_inode {
8036  #define i_gid_low      i_gid
8037  #define i_uid_high     osd2.linux2.l_i_uid_high
8038  #define i_gid_high     osd2.linux2.l_i_gid_high
8039 +#define i_raw_tag      osd2.linux2.l_i_tag
8040  #define i_reserved2    osd2.linux2.l_i_reserved2
8041  #endif
8042  
8043 @@ -348,6 +354,7 @@ struct ext2_inode {
8044  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8045  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8046  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8047 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8048  
8049  
8050  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8051 diff -NurpP --minimal linux-3.2.8/include/linux/ext3_fs.h linux-3.2.8-vs2.3.2.7/include/linux/ext3_fs.h
8052 --- linux-3.2.8/include/linux/ext3_fs.h 2012-01-09 16:14:56.000000000 +0100
8053 +++ linux-3.2.8-vs2.3.2.7/include/linux/ext3_fs.h       2011-12-05 19:33:02.000000000 +0100
8054 @@ -173,10 +173,14 @@ struct ext3_group_desc
8055  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8056  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8057  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8058 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8059  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8060  
8061 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8062 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8063 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8064 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8065 +
8066 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8067 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8068  
8069  /* Flags that should be inherited by new inodes from their parent. */
8070  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8071 @@ -312,7 +316,8 @@ struct ext3_inode {
8072                         __u16   i_pad1;
8073                         __le16  l_i_uid_high;   /* these 2 fields    */
8074                         __le16  l_i_gid_high;   /* were reserved2[0] */
8075 -                       __u32   l_i_reserved2;
8076 +                       __le16  l_i_tag;        /* Context Tag */
8077 +                       __u16   l_i_reserved2;
8078                 } linux2;
8079                 struct {
8080                         __u8    h_i_frag;       /* Fragment number */
8081 @@ -343,6 +348,7 @@ struct ext3_inode {
8082  #define i_gid_low      i_gid
8083  #define i_uid_high     osd2.linux2.l_i_uid_high
8084  #define i_gid_high     osd2.linux2.l_i_gid_high
8085 +#define i_raw_tag      osd2.linux2.l_i_tag
8086  #define i_reserved2    osd2.linux2.l_i_reserved2
8087  
8088  #elif defined(__GNU__)
8089 @@ -405,6 +411,7 @@ struct ext3_inode {
8090  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8091  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8092                                                   * error in ordered mode */
8093 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8094  
8095  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8096  #ifndef _LINUX_EXT2_FS_H
8097 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8098  extern void ext3_set_aops(struct inode *inode);
8099  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8100                        u64 start, u64 len);
8101 +extern int ext3_sync_flags(struct inode *, int, int);
8102  
8103  /* ioctl.c */
8104  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8105 diff -NurpP --minimal linux-3.2.8/include/linux/fs.h linux-3.2.8-vs2.3.2.7/include/linux/fs.h
8106 --- linux-3.2.8/include/linux/fs.h      2012-01-09 16:14:57.000000000 +0100
8107 +++ linux-3.2.8-vs2.3.2.7/include/linux/fs.h    2011-12-15 01:11:32.000000000 +0100
8108 @@ -210,6 +210,9 @@ struct inodes_stat_t {
8109  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8110  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8111  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8112 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8113 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8114 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8115  #define MS_NOSEC       (1<<28)
8116  #define MS_BORN                (1<<29)
8117  #define MS_ACTIVE      (1<<30)
8118 @@ -241,6 +244,14 @@ struct inodes_stat_t {
8119  #define S_IMA          1024    /* Inode has an associated IMA struct */
8120  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8121  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8122 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8123 +
8124 +/* Linux-VServer related Inode flags */
8125 +
8126 +#define V_VALID                1
8127 +#define V_XATTR                2
8128 +#define V_BARRIER      4       /* Barrier for chroot() */
8129 +#define V_COW          8       /* Copy on Write */
8130  
8131  /*
8132   * Note that nosuid etc flags are inode-specific: setting some file-system
8133 @@ -263,12 +274,15 @@ struct inodes_stat_t {
8134  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8135                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8136  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8137 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8138 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8139 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8140 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8141 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8142  
8143  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8144  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8145  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8146 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8147 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8148  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8149  
8150  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8151 @@ -279,6 +293,16 @@ struct inodes_stat_t {
8152  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8153  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8154  
8155 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8156 +
8157 +#ifdef CONFIG_VSERVER_COWBL
8158 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8159 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8160 +#else
8161 +#  define IS_COW(inode)                (0)
8162 +#  define IS_COW_LINK(inode)   (0)
8163 +#endif
8164 +
8165  /* the read-only stuff doesn't really belong here, but any other place is
8166     probably as bad and I don't want to create yet another include file. */
8167  
8168 @@ -364,11 +388,14 @@ struct inodes_stat_t {
8169  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8170  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8171  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8172 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8173  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8174  
8175 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8176 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8177 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8178 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8179  
8180 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8181 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8182  
8183  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8184  #define SYNC_FILE_RANGE_WRITE          2
8185 @@ -449,6 +476,7 @@ typedef void (dio_iodone_t)(struct kiocb
8186  #define ATTR_KILL_PRIV (1 << 14)
8187  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8188  #define ATTR_TIMES_SET (1 << 16)
8189 +#define ATTR_TAG       (1 << 17)
8190  
8191  /*
8192   * This is the Inode Attributes structure, used for notify_change().  It
8193 @@ -464,6 +492,7 @@ struct iattr {
8194         umode_t         ia_mode;
8195         uid_t           ia_uid;
8196         gid_t           ia_gid;
8197 +       tag_t           ia_tag;
8198         loff_t          ia_size;
8199         struct timespec ia_atime;
8200         struct timespec ia_mtime;
8201 @@ -477,6 +506,9 @@ struct iattr {
8202         struct file     *ia_file;
8203  };
8204  
8205 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8206 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8207 +
8208  /*
8209   * Includes for diskquotas.
8210   */
8211 @@ -751,7 +783,9 @@ struct inode {
8212         unsigned short          i_opflags;
8213         uid_t                   i_uid;
8214         gid_t                   i_gid;
8215 -       unsigned int            i_flags;
8216 +       tag_t                   i_tag;
8217 +       unsigned short          i_flags;
8218 +       unsigned short          i_vflags;
8219  
8220  #ifdef CONFIG_FS_POSIX_ACL
8221         struct posix_acl        *i_acl;
8222 @@ -780,6 +814,7 @@ struct inode {
8223                 unsigned int __i_nlink;
8224         };
8225         dev_t                   i_rdev;
8226 +       dev_t                   i_mdev;
8227         struct timespec         i_atime;
8228         struct timespec         i_mtime;
8229         struct timespec         i_ctime;
8230 @@ -917,12 +952,12 @@ static inline void i_size_write(struct i
8231  
8232  static inline unsigned iminor(const struct inode *inode)
8233  {
8234 -       return MINOR(inode->i_rdev);
8235 +       return MINOR(inode->i_mdev);
8236  }
8237  
8238  static inline unsigned imajor(const struct inode *inode)
8239  {
8240 -       return MAJOR(inode->i_rdev);
8241 +       return MAJOR(inode->i_mdev);
8242  }
8243  
8244  extern struct block_device *I_BDEV(struct inode *inode);
8245 @@ -989,6 +1024,7 @@ struct file {
8246         loff_t                  f_pos;
8247         struct fown_struct      f_owner;
8248         const struct cred       *f_cred;
8249 +       xid_t                   f_xid;
8250         struct file_ra_state    f_ra;
8251  
8252         u64                     f_version;
8253 @@ -1135,6 +1171,7 @@ struct file_lock {
8254         struct file *fl_file;
8255         loff_t fl_start;
8256         loff_t fl_end;
8257 +       xid_t fl_xid;
8258  
8259         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8260         /* for lease breaks: */
8261 @@ -1635,6 +1672,7 @@ struct inode_operations {
8262         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8263         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8264         int (*removexattr) (struct dentry *, const char *);
8265 +       int (*sync_flags) (struct inode *, int, int);
8266         void (*truncate_range)(struct inode *, loff_t, loff_t);
8267         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8268                       u64 len);
8269 @@ -1654,6 +1692,7 @@ extern ssize_t vfs_readv(struct file *, 
8270                 unsigned long, loff_t *);
8271  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8272                 unsigned long, loff_t *);
8273 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8274  
8275  struct super_operations {
8276         struct inode *(*alloc_inode)(struct super_block *sb);
8277 @@ -2541,6 +2580,7 @@ extern int dcache_dir_open(struct inode 
8278  extern int dcache_dir_close(struct inode *, struct file *);
8279  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8280  extern int dcache_readdir(struct file *, void *, filldir_t);
8281 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8282  extern int simple_setattr(struct dentry *, struct iattr *);
8283  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8284  extern int simple_statfs(struct dentry *, struct kstatfs *);
8285 diff -NurpP --minimal linux-3.2.8/include/linux/gfs2_ondisk.h linux-3.2.8-vs2.3.2.7/include/linux/gfs2_ondisk.h
8286 --- linux-3.2.8/include/linux/gfs2_ondisk.h     2010-07-07 18:31:55.000000000 +0200
8287 +++ linux-3.2.8-vs2.3.2.7/include/linux/gfs2_ondisk.h   2011-12-05 19:33:02.000000000 +0100
8288 @@ -211,6 +211,9 @@ enum {
8289         gfs2fl_NoAtime          = 7,
8290         gfs2fl_Sync             = 8,
8291         gfs2fl_System           = 9,
8292 +       gfs2fl_IXUnlink         = 16,
8293 +       gfs2fl_Barrier          = 17,
8294 +       gfs2fl_Cow              = 18,
8295         gfs2fl_TruncInProg      = 29,
8296         gfs2fl_InheritDirectio  = 30,
8297         gfs2fl_InheritJdata     = 31,
8298 @@ -227,6 +230,9 @@ enum {
8299  #define GFS2_DIF_NOATIME               0x00000080
8300  #define GFS2_DIF_SYNC                  0x00000100
8301  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8302 +#define GFS2_DIF_IXUNLINK              0x00010000
8303 +#define GFS2_DIF_BARRIER               0x00020000
8304 +#define GFS2_DIF_COW                   0x00040000
8305  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8306  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8307  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8308 diff -NurpP --minimal linux-3.2.8/include/linux/if_tun.h linux-3.2.8-vs2.3.2.7/include/linux/if_tun.h
8309 --- linux-3.2.8/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8310 +++ linux-3.2.8-vs2.3.2.7/include/linux/if_tun.h        2011-12-05 19:33:02.000000000 +0100
8311 @@ -53,6 +53,7 @@
8312  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8313  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8314  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8315 +#define TUNSETNID     _IOW('T', 217, int)
8316  
8317  /* TUNSETIFF ifr flags */
8318  #define IFF_TUN                0x0001
8319 diff -NurpP --minimal linux-3.2.8/include/linux/init_task.h linux-3.2.8-vs2.3.2.7/include/linux/init_task.h
8320 --- linux-3.2.8/include/linux/init_task.h       2012-01-09 16:14:58.000000000 +0100
8321 +++ linux-3.2.8-vs2.3.2.7/include/linux/init_task.h     2011-12-15 01:11:32.000000000 +0100
8322 @@ -193,6 +193,10 @@ extern struct cred init_cred;
8323         INIT_FTRACE_GRAPH                                               \
8324         INIT_TRACE_RECURSION                                            \
8325         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8326 +       .xid            = 0,                                            \
8327 +       .vx_info        = NULL,                                         \
8328 +       .nid            = 0,                                            \
8329 +       .nx_info        = NULL,                                         \
8330  }
8331  
8332  
8333 diff -NurpP --minimal linux-3.2.8/include/linux/ipc.h linux-3.2.8-vs2.3.2.7/include/linux/ipc.h
8334 --- linux-3.2.8/include/linux/ipc.h     2009-12-03 20:02:55.000000000 +0100
8335 +++ linux-3.2.8-vs2.3.2.7/include/linux/ipc.h   2011-12-05 19:33:02.000000000 +0100
8336 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8337         key_t           key;
8338         uid_t           uid;
8339         gid_t           gid;
8340 +       xid_t           xid;
8341         uid_t           cuid;
8342         gid_t           cgid;
8343         mode_t          mode; 
8344 diff -NurpP --minimal linux-3.2.8/include/linux/ipc_namespace.h linux-3.2.8-vs2.3.2.7/include/linux/ipc_namespace.h
8345 --- linux-3.2.8/include/linux/ipc_namespace.h   2011-10-24 18:45:32.000000000 +0200
8346 +++ linux-3.2.8-vs2.3.2.7/include/linux/ipc_namespace.h 2011-12-05 19:33:02.000000000 +0100
8347 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8348  
8349  #if defined(CONFIG_IPC_NS)
8350  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8351 -                                      struct task_struct *tsk);
8352 +                                      struct ipc_namespace *old_ns,
8353 +                                      struct user_namespace *user_ns);
8354  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8355  {
8356         if (ns)
8357 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8358  extern void put_ipc_ns(struct ipc_namespace *ns);
8359  #else
8360  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8361 -                                             struct task_struct *tsk)
8362 +                                             struct ipc_namespace *old_ns,
8363 +                                             struct user_namespace *user_ns)
8364  {
8365         if (flags & CLONE_NEWIPC)
8366                 return ERR_PTR(-EINVAL);
8367  
8368 -       return tsk->nsproxy->ipc_ns;
8369 +       return old_ns;
8370  }
8371  
8372  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8373 diff -NurpP --minimal linux-3.2.8/include/linux/loop.h linux-3.2.8-vs2.3.2.7/include/linux/loop.h
8374 --- linux-3.2.8/include/linux/loop.h    2012-01-09 16:14:58.000000000 +0100
8375 +++ linux-3.2.8-vs2.3.2.7/include/linux/loop.h  2011-12-05 19:33:02.000000000 +0100
8376 @@ -45,6 +45,7 @@ struct loop_device {
8377         struct loop_func_table *lo_encryption;
8378         __u32           lo_init[2];
8379         uid_t           lo_key_owner;   /* Who set the key */
8380 +       xid_t           lo_xid;
8381         int             (*ioctl)(struct loop_device *, int cmd, 
8382                                  unsigned long arg); 
8383  
8384 diff -NurpP --minimal linux-3.2.8/include/linux/magic.h linux-3.2.8-vs2.3.2.7/include/linux/magic.h
8385 --- linux-3.2.8/include/linux/magic.h   2012-01-09 16:14:58.000000000 +0100
8386 +++ linux-3.2.8-vs2.3.2.7/include/linux/magic.h 2011-12-05 19:33:02.000000000 +0100
8387 @@ -3,7 +3,7 @@
8388  
8389  #define ADFS_SUPER_MAGIC       0xadf5
8390  #define AFFS_SUPER_MAGIC       0xadff
8391 -#define AFS_SUPER_MAGIC                0x5346414F
8392 +#define AFS_SUPER_MAGIC                0x5346414F
8393  #define AUTOFS_SUPER_MAGIC     0x0187
8394  #define CODA_SUPER_MAGIC       0x73757245
8395  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8396 @@ -41,6 +41,7 @@
8397  #define NFS_SUPER_MAGIC                0x6969
8398  #define OPENPROM_SUPER_MAGIC   0x9fa1
8399  #define PROC_SUPER_MAGIC       0x9fa0
8400 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8401  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8402  
8403  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8404 diff -NurpP --minimal linux-3.2.8/include/linux/major.h linux-3.2.8-vs2.3.2.7/include/linux/major.h
8405 --- linux-3.2.8/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8406 +++ linux-3.2.8-vs2.3.2.7/include/linux/major.h 2011-12-05 19:33:02.000000000 +0100
8407 @@ -15,6 +15,7 @@
8408  #define HD_MAJOR               IDE0_MAJOR
8409  #define PTY_SLAVE_MAJOR                3
8410  #define TTY_MAJOR              4
8411 +#define VROOT_MAJOR            4
8412  #define TTYAUX_MAJOR           5
8413  #define LP_MAJOR               6
8414  #define VCS_MAJOR              7
8415 diff -NurpP --minimal linux-3.2.8/include/linux/memcontrol.h linux-3.2.8-vs2.3.2.7/include/linux/memcontrol.h
8416 --- linux-3.2.8/include/linux/memcontrol.h      2012-02-28 05:53:29.000000000 +0100
8417 +++ linux-3.2.8-vs2.3.2.7/include/linux/memcontrol.h    2012-01-26 08:52:10.000000000 +0100
8418 @@ -85,6 +85,13 @@ extern struct mem_cgroup *try_get_mem_cg
8419  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8420  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
8421  
8422 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8423 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8424 +
8425 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8426 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8427 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8428 +
8429  static inline
8430  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8431  {
8432 diff -NurpP --minimal linux-3.2.8/include/linux/mm_types.h linux-3.2.8-vs2.3.2.7/include/linux/mm_types.h
8433 --- linux-3.2.8/include/linux/mm_types.h        2012-01-09 16:14:58.000000000 +0100
8434 +++ linux-3.2.8-vs2.3.2.7/include/linux/mm_types.h      2011-12-05 19:33:02.000000000 +0100
8435 @@ -344,6 +344,7 @@ struct mm_struct {
8436  
8437         /* Architecture-specific MM context */
8438         mm_context_t context;
8439 +       struct vx_info *mm_vx_info;
8440  
8441         /* Swap token stuff */
8442         /*
8443 diff -NurpP --minimal linux-3.2.8/include/linux/mmzone.h linux-3.2.8-vs2.3.2.7/include/linux/mmzone.h
8444 --- linux-3.2.8/include/linux/mmzone.h  2012-01-09 16:14:58.000000000 +0100
8445 +++ linux-3.2.8-vs2.3.2.7/include/linux/mmzone.h        2011-12-05 19:33:02.000000000 +0100
8446 @@ -673,6 +673,13 @@ typedef struct pglist_data {
8447         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8448  })
8449  
8450 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8451 +
8452 +#define node_end_pfn(nid) ({\
8453 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8454 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8455 +})
8456 +
8457  #include <linux/memory_hotplug.h>
8458  
8459  extern struct mutex zonelists_mutex;
8460 diff -NurpP --minimal linux-3.2.8/include/linux/mount.h linux-3.2.8-vs2.3.2.7/include/linux/mount.h
8461 --- linux-3.2.8/include/linux/mount.h   2011-10-24 18:45:32.000000000 +0200
8462 +++ linux-3.2.8-vs2.3.2.7/include/linux/mount.h 2011-12-05 19:33:02.000000000 +0100
8463 @@ -52,6 +52,9 @@ struct mnt_pcp {
8464         int mnt_writers;
8465  };
8466  
8467 +#define MNT_TAGID      0x10000
8468 +#define MNT_NOTAG      0x20000
8469 +
8470  struct vfsmount {
8471         struct list_head mnt_hash;
8472         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8473 @@ -86,6 +89,7 @@ struct vfsmount {
8474         int mnt_expiry_mark;            /* true if marked for expiry */
8475         int mnt_pinned;
8476         int mnt_ghosts;
8477 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8478  };
8479  
8480  struct file; /* forward dec */
8481 diff -NurpP --minimal linux-3.2.8/include/linux/net.h linux-3.2.8-vs2.3.2.7/include/linux/net.h
8482 --- linux-3.2.8/include/linux/net.h     2011-07-22 11:18:11.000000000 +0200
8483 +++ linux-3.2.8-vs2.3.2.7/include/linux/net.h   2011-12-05 19:33:02.000000000 +0100
8484 @@ -72,6 +72,7 @@ struct net;
8485  #define SOCK_NOSPACE           2
8486  #define SOCK_PASSCRED          3
8487  #define SOCK_PASSSEC           4
8488 +#define SOCK_USER_SOCKET       5
8489  
8490  #ifndef ARCH_HAS_SOCKET_TYPES
8491  /**
8492 diff -NurpP --minimal linux-3.2.8/include/linux/netdevice.h linux-3.2.8-vs2.3.2.7/include/linux/netdevice.h
8493 --- linux-3.2.8/include/linux/netdevice.h       2012-01-09 16:14:58.000000000 +0100
8494 +++ linux-3.2.8-vs2.3.2.7/include/linux/netdevice.h     2011-12-15 01:11:33.000000000 +0100
8495 @@ -1646,6 +1646,7 @@ extern void               netdev_resync_ops(struct ne
8496  
8497  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8498  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8499 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8500  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8501  extern int             dev_restart(struct net_device *dev);
8502  #ifdef CONFIG_NETPOLL_TRAP
8503 diff -NurpP --minimal linux-3.2.8/include/linux/nfs_mount.h linux-3.2.8-vs2.3.2.7/include/linux/nfs_mount.h
8504 --- linux-3.2.8/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8505 +++ linux-3.2.8-vs2.3.2.7/include/linux/nfs_mount.h     2011-12-05 19:33:02.000000000 +0100
8506 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8507  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8508  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8509  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8510 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8511 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8512 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8513  
8514  /* The following are for internal use only */
8515  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8516 diff -NurpP --minimal linux-3.2.8/include/linux/nsproxy.h linux-3.2.8-vs2.3.2.7/include/linux/nsproxy.h
8517 --- linux-3.2.8/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8518 +++ linux-3.2.8-vs2.3.2.7/include/linux/nsproxy.h       2011-12-05 19:33:02.000000000 +0100
8519 @@ -3,6 +3,7 @@
8520  
8521  #include <linux/spinlock.h>
8522  #include <linux/sched.h>
8523 +#include <linux/vserver/debug.h>
8524  
8525  struct mnt_namespace;
8526  struct uts_namespace;
8527 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8528  }
8529  
8530  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8531 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8532  void exit_task_namespaces(struct task_struct *tsk);
8533  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8534  void free_nsproxy(struct nsproxy *ns);
8535 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8536         struct fs_struct *);
8537  int __init nsproxy_cache_init(void);
8538  
8539 -static inline void put_nsproxy(struct nsproxy *ns)
8540 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8541 +
8542 +static inline void __get_nsproxy(struct nsproxy *ns,
8543 +       const char *_file, int _line)
8544  {
8545 -       if (atomic_dec_and_test(&ns->count)) {
8546 -               free_nsproxy(ns);
8547 -       }
8548 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8549 +               ns, atomic_read(&ns->count), _file, _line);
8550 +       atomic_inc(&ns->count);
8551  }
8552  
8553 -static inline void get_nsproxy(struct nsproxy *ns)
8554 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8555 +
8556 +static inline void __put_nsproxy(struct nsproxy *ns,
8557 +       const char *_file, int _line)
8558  {
8559 -       atomic_inc(&ns->count);
8560 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8561 +               ns, atomic_read(&ns->count), _file, _line);
8562 +       if (atomic_dec_and_test(&ns->count)) {
8563 +               free_nsproxy(ns);
8564 +       }
8565  }
8566  
8567  #endif
8568 diff -NurpP --minimal linux-3.2.8/include/linux/pid.h linux-3.2.8-vs2.3.2.7/include/linux/pid.h
8569 --- linux-3.2.8/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8570 +++ linux-3.2.8-vs2.3.2.7/include/linux/pid.h   2011-12-05 19:33:02.000000000 +0100
8571 @@ -8,7 +8,8 @@ enum pid_type
8572         PIDTYPE_PID,
8573         PIDTYPE_PGID,
8574         PIDTYPE_SID,
8575 -       PIDTYPE_MAX
8576 +       PIDTYPE_MAX,
8577 +       PIDTYPE_REALPID
8578  };
8579  
8580  /*
8581 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8582  }
8583  
8584  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8585 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8586  pid_t pid_vnr(struct pid *pid);
8587  
8588  #define do_each_pid_task(pid, type, task)                              \
8589 diff -NurpP --minimal linux-3.2.8/include/linux/proc_fs.h linux-3.2.8-vs2.3.2.7/include/linux/proc_fs.h
8590 --- linux-3.2.8/include/linux/proc_fs.h 2011-10-24 18:45:32.000000000 +0200
8591 +++ linux-3.2.8-vs2.3.2.7/include/linux/proc_fs.h       2011-12-05 19:33:02.000000000 +0100
8592 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8593         nlink_t nlink;
8594         uid_t uid;
8595         gid_t gid;
8596 +       int vx_flags;
8597         loff_t size;
8598         const struct inode_operations *proc_iops;
8599         /*
8600 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8601  extern const struct proc_ns_operations utsns_operations;
8602  extern const struct proc_ns_operations ipcns_operations;
8603  
8604 +struct vx_info;
8605 +struct nx_info;
8606 +
8607  union proc_op {
8608         int (*proc_get_link)(struct inode *, struct path *);
8609         int (*proc_read)(struct task_struct *task, char *page);
8610         int (*proc_show)(struct seq_file *m,
8611                 struct pid_namespace *ns, struct pid *pid,
8612                 struct task_struct *task);
8613 +       int (*proc_vs_read)(char *page);
8614 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8615 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8616  };
8617  
8618  struct ctl_table_header;
8619 @@ -265,6 +272,7 @@ struct ctl_table;
8620  
8621  struct proc_inode {
8622         struct pid *pid;
8623 +       int vx_flags;
8624         int fd;
8625         union proc_op op;
8626         struct proc_dir_entry *pde;
8627 diff -NurpP --minimal linux-3.2.8/include/linux/quotaops.h linux-3.2.8-vs2.3.2.7/include/linux/quotaops.h
8628 --- linux-3.2.8/include/linux/quotaops.h        2012-01-09 16:14:58.000000000 +0100
8629 +++ linux-3.2.8-vs2.3.2.7/include/linux/quotaops.h      2011-12-05 19:33:02.000000000 +0100
8630 @@ -8,6 +8,7 @@
8631  #define _LINUX_QUOTAOPS_
8632  
8633  #include <linux/fs.h>
8634 +#include <linux/vs_dlimit.h>
8635  
8636  #define DQUOT_SPACE_WARN       0x1
8637  #define DQUOT_SPACE_RESERVE    0x2
8638 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8639  
8640  static inline int dquot_alloc_inode(const struct inode *inode)
8641  {
8642 -       return 0;
8643 +       return dl_alloc_inode(inode);
8644  }
8645  
8646  static inline void dquot_free_inode(const struct inode *inode)
8647  {
8648 +       dl_free_inode(inode);
8649  }
8650  
8651  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8652 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8653  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8654                 int flags)
8655  {
8656 +       int ret = 0;
8657 +
8658 +       if ((ret = dl_alloc_space(inode, number)))
8659 +               return ret;
8660         if (!(flags & DQUOT_SPACE_RESERVE))
8661                 inode_add_bytes(inode, number);
8662         return 0;
8663 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8664  {
8665         if (!(flags & DQUOT_SPACE_RESERVE))
8666                 inode_sub_bytes(inode, number);
8667 +       dl_free_space(inode, number);
8668  }
8669  
8670  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8671 diff -NurpP --minimal linux-3.2.8/include/linux/reboot.h linux-3.2.8-vs2.3.2.7/include/linux/reboot.h
8672 --- linux-3.2.8/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8673 +++ linux-3.2.8-vs2.3.2.7/include/linux/reboot.h        2011-12-05 19:33:02.000000000 +0100
8674 @@ -33,6 +33,7 @@
8675  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8676  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8677  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8678 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8679  
8680  
8681  #ifdef __KERNEL__
8682 diff -NurpP --minimal linux-3.2.8/include/linux/reiserfs_fs.h linux-3.2.8-vs2.3.2.7/include/linux/reiserfs_fs.h
8683 --- linux-3.2.8/include/linux/reiserfs_fs.h     2011-10-24 18:45:32.000000000 +0200
8684 +++ linux-3.2.8-vs2.3.2.7/include/linux/reiserfs_fs.h   2011-12-05 19:33:02.000000000 +0100
8685 @@ -976,6 +976,11 @@ struct stat_data_v1 {
8686  #define REISERFS_COMPR_FL     FS_COMPR_FL
8687  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8688  
8689 +/* unfortunately reiserfs sdattr is only 16 bit */
8690 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8691 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8692 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8693 +
8694  /* persistent flags that file inherits from the parent directory */
8695  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8696                                 REISERFS_SYNC_FL |      \
8697 @@ -985,6 +990,9 @@ struct stat_data_v1 {
8698                                 REISERFS_COMPR_FL |     \
8699                                 REISERFS_NOTAIL_FL )
8700  
8701 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8702 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8703 +
8704  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8705     address blocks) */
8706  struct stat_data {
8707 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
8708  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8709  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8710  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8711 +int reiserfs_sync_flags(struct inode *inode, int, int);
8712  
8713  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
8714  
8715 diff -NurpP --minimal linux-3.2.8/include/linux/reiserfs_fs_sb.h linux-3.2.8-vs2.3.2.7/include/linux/reiserfs_fs_sb.h
8716 --- linux-3.2.8/include/linux/reiserfs_fs_sb.h  2010-02-25 11:52:07.000000000 +0100
8717 +++ linux-3.2.8-vs2.3.2.7/include/linux/reiserfs_fs_sb.h        2011-12-05 19:33:02.000000000 +0100
8718 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
8719         REISERFS_EXPOSE_PRIVROOT,
8720         REISERFS_BARRIER_NONE,
8721         REISERFS_BARRIER_FLUSH,
8722 +       REISERFS_TAGGED,
8723  
8724         /* Actions on error */
8725         REISERFS_ERROR_PANIC,
8726 diff -NurpP --minimal linux-3.2.8/include/linux/sched.h linux-3.2.8-vs2.3.2.7/include/linux/sched.h
8727 --- linux-3.2.8/include/linux/sched.h   2012-01-09 16:14:58.000000000 +0100
8728 +++ linux-3.2.8-vs2.3.2.7/include/linux/sched.h 2011-12-05 19:33:02.000000000 +0100
8729 @@ -1403,6 +1403,14 @@ struct task_struct {
8730  #endif
8731         seccomp_t seccomp;
8732  
8733 +/* vserver context data */
8734 +       struct vx_info *vx_info;
8735 +       struct nx_info *nx_info;
8736 +
8737 +       xid_t xid;
8738 +       nid_t nid;
8739 +       tag_t tag;
8740 +
8741  /* Thread group tracking */
8742         u32 parent_exec_id;
8743         u32 self_exec_id;
8744 @@ -1651,6 +1659,11 @@ struct pid_namespace;
8745  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8746                         struct pid_namespace *ns);
8747  
8748 +#include <linux/vserver/base.h>
8749 +#include <linux/vserver/context.h>
8750 +#include <linux/vserver/debug.h>
8751 +#include <linux/vserver/pid.h>
8752 +
8753  static inline pid_t task_pid_nr(struct task_struct *tsk)
8754  {
8755         return tsk->pid;
8756 @@ -1664,7 +1677,8 @@ static inline pid_t task_pid_nr_ns(struc
8757  
8758  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8759  {
8760 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8761 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8762 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8763  }
8764  
8765  
8766 @@ -1677,7 +1691,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8767  
8768  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8769  {
8770 -       return pid_vnr(task_tgid(tsk));
8771 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8772  }
8773  
8774  
8775 diff -NurpP --minimal linux-3.2.8/include/linux/shmem_fs.h linux-3.2.8-vs2.3.2.7/include/linux/shmem_fs.h
8776 --- linux-3.2.8/include/linux/shmem_fs.h        2012-02-28 05:53:29.000000000 +0100
8777 +++ linux-3.2.8-vs2.3.2.7/include/linux/shmem_fs.h      2012-01-26 08:52:10.000000000 +0100
8778 @@ -8,6 +8,9 @@
8779  
8780  /* inode in-kernel data */
8781  
8782 +#define TMPFS_SUPER_MAGIC      0x01021994
8783 +
8784 +
8785  struct shmem_inode_info {
8786         spinlock_t              lock;
8787         unsigned long           flags;
8788 diff -NurpP --minimal linux-3.2.8/include/linux/stat.h linux-3.2.8-vs2.3.2.7/include/linux/stat.h
8789 --- linux-3.2.8/include/linux/stat.h    2008-12-25 00:26:37.000000000 +0100
8790 +++ linux-3.2.8-vs2.3.2.7/include/linux/stat.h  2011-12-05 19:33:02.000000000 +0100
8791 @@ -66,6 +66,7 @@ struct kstat {
8792         unsigned int    nlink;
8793         uid_t           uid;
8794         gid_t           gid;
8795 +       tag_t           tag;
8796         dev_t           rdev;
8797         loff_t          size;
8798         struct timespec  atime;
8799 diff -NurpP --minimal linux-3.2.8/include/linux/sunrpc/auth.h linux-3.2.8-vs2.3.2.7/include/linux/sunrpc/auth.h
8800 --- linux-3.2.8/include/linux/sunrpc/auth.h     2011-10-24 18:45:32.000000000 +0200
8801 +++ linux-3.2.8-vs2.3.2.7/include/linux/sunrpc/auth.h   2011-12-05 19:33:02.000000000 +0100
8802 @@ -25,6 +25,7 @@
8803  struct auth_cred {
8804         uid_t   uid;
8805         gid_t   gid;
8806 +       tag_t   tag;
8807         struct group_info *group_info;
8808         unsigned char machine_cred : 1;
8809  };
8810 diff -NurpP --minimal linux-3.2.8/include/linux/sunrpc/clnt.h linux-3.2.8-vs2.3.2.7/include/linux/sunrpc/clnt.h
8811 --- linux-3.2.8/include/linux/sunrpc/clnt.h     2012-01-09 16:14:58.000000000 +0100
8812 +++ linux-3.2.8-vs2.3.2.7/include/linux/sunrpc/clnt.h   2011-12-05 19:33:02.000000000 +0100
8813 @@ -50,7 +50,8 @@ struct rpc_clnt {
8814         unsigned int            cl_softrtry : 1,/* soft timeouts */
8815                                 cl_discrtry : 1,/* disconnect before retry */
8816                                 cl_autobind : 1,/* use getport() */
8817 -                               cl_chatty   : 1;/* be verbose */
8818 +                               cl_chatty   : 1,/* be verbose */
8819 +                               cl_tag      : 1;/* context tagging */
8820  
8821         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8822         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8823 diff -NurpP --minimal linux-3.2.8/include/linux/syscalls.h linux-3.2.8-vs2.3.2.7/include/linux/syscalls.h
8824 --- linux-3.2.8/include/linux/syscalls.h        2012-01-09 16:14:58.000000000 +0100
8825 +++ linux-3.2.8-vs2.3.2.7/include/linux/syscalls.h      2011-12-05 19:33:02.000000000 +0100
8826 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
8827  asmlinkage long sys_unlink(const char __user *pathname);
8828  asmlinkage long sys_rename(const char __user *oldname,
8829                                 const char __user *newname);
8830 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
8831 +                               umode_t mode);
8832  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
8833  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
8834  
8835 diff -NurpP --minimal linux-3.2.8/include/linux/sysctl.h linux-3.2.8-vs2.3.2.7/include/linux/sysctl.h
8836 --- linux-3.2.8/include/linux/sysctl.h  2012-01-09 16:14:58.000000000 +0100
8837 +++ linux-3.2.8-vs2.3.2.7/include/linux/sysctl.h        2011-12-05 19:33:02.000000000 +0100
8838 @@ -60,6 +60,7 @@ enum
8839         CTL_ABI=9,              /* Binary emulation */
8840         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8841         CTL_ARLAN=254,          /* arlan wireless driver */
8842 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8843         CTL_S390DBF=5677,       /* s390 debug */
8844         CTL_SUNRPC=7249,        /* sunrpc debug */
8845         CTL_PM=9899,            /* frv power management */
8846 @@ -94,6 +95,7 @@ enum
8847  
8848         KERN_PANIC=15,          /* int: panic timeout */
8849         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8850 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8851  
8852         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8853         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8854 diff -NurpP --minimal linux-3.2.8/include/linux/sysfs.h linux-3.2.8-vs2.3.2.7/include/linux/sysfs.h
8855 --- linux-3.2.8/include/linux/sysfs.h   2012-01-09 16:14:58.000000000 +0100
8856 +++ linux-3.2.8-vs2.3.2.7/include/linux/sysfs.h 2011-12-05 19:33:02.000000000 +0100
8857 @@ -19,6 +19,8 @@
8858  #include <linux/kobject_ns.h>
8859  #include <linux/atomic.h>
8860  
8861 +#define SYSFS_SUPER_MAGIC      0x62656572
8862 +
8863  struct kobject;
8864  struct module;
8865  enum kobj_ns_type;
8866 diff -NurpP --minimal linux-3.2.8/include/linux/time.h linux-3.2.8-vs2.3.2.7/include/linux/time.h
8867 --- linux-3.2.8/include/linux/time.h    2011-07-22 11:18:11.000000000 +0200
8868 +++ linux-3.2.8-vs2.3.2.7/include/linux/time.h  2011-12-05 19:33:02.000000000 +0100
8869 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
8870         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
8871         a->tv_nsec = ns;
8872  }
8873 +
8874 +#include <linux/vs_time.h>
8875 +
8876  #endif /* __KERNEL__ */
8877  
8878  #define NFDBITS                        __NFDBITS
8879 diff -NurpP --minimal linux-3.2.8/include/linux/types.h linux-3.2.8-vs2.3.2.7/include/linux/types.h
8880 --- linux-3.2.8/include/linux/types.h   2012-01-09 16:14:59.000000000 +0100
8881 +++ linux-3.2.8-vs2.3.2.7/include/linux/types.h 2011-12-05 19:33:02.000000000 +0100
8882 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
8883  typedef __kernel_gid32_t       gid_t;
8884  typedef __kernel_uid16_t        uid16_t;
8885  typedef __kernel_gid16_t        gid16_t;
8886 +typedef unsigned int           xid_t;
8887 +typedef unsigned int           nid_t;
8888 +typedef unsigned int           tag_t;
8889  
8890  typedef unsigned long          uintptr_t;
8891  
8892 diff -NurpP --minimal linux-3.2.8/include/linux/utsname.h linux-3.2.8-vs2.3.2.7/include/linux/utsname.h
8893 --- linux-3.2.8/include/linux/utsname.h 2012-01-09 16:14:59.000000000 +0100
8894 +++ linux-3.2.8-vs2.3.2.7/include/linux/utsname.h       2011-12-05 19:33:02.000000000 +0100
8895 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8896  }
8897  
8898  extern struct uts_namespace *copy_utsname(unsigned long flags,
8899 -                                         struct task_struct *tsk);
8900 +                                         struct uts_namespace *old_ns,
8901 +                                         struct user_namespace *user_ns);
8902  extern void free_uts_ns(struct kref *kref);
8903  
8904  static inline void put_uts_ns(struct uts_namespace *ns)
8905 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8906  }
8907  
8908  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8909 -                                                struct task_struct *tsk)
8910 +                                                struct uts_namespace *old_ns,
8911 +                                                struct user_namespace *user_ns)
8912  {
8913         if (flags & CLONE_NEWUTS)
8914                 return ERR_PTR(-EINVAL);
8915  
8916 -       return tsk->nsproxy->uts_ns;
8917 +       return old_ns;
8918  }
8919  #endif
8920  
8921 diff -NurpP --minimal linux-3.2.8/include/linux/vroot.h linux-3.2.8-vs2.3.2.7/include/linux/vroot.h
8922 --- linux-3.2.8/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
8923 +++ linux-3.2.8-vs2.3.2.7/include/linux/vroot.h 2011-12-05 19:33:02.000000000 +0100
8924 @@ -0,0 +1,51 @@
8925 +
8926 +/*
8927 + * include/linux/vroot.h
8928 + *
8929 + * written by Herbert Pötzl, 9/11/2002
8930 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8931 + *
8932 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8933 + * Redistribution of this file is permitted under the
8934 + * GNU General Public License.
8935 + */
8936 +
8937 +#ifndef _LINUX_VROOT_H
8938 +#define _LINUX_VROOT_H
8939 +
8940 +
8941 +#ifdef __KERNEL__
8942 +
8943 +/* Possible states of device */
8944 +enum {
8945 +       Vr_unbound,
8946 +       Vr_bound,
8947 +};
8948 +
8949 +struct vroot_device {
8950 +       int             vr_number;
8951 +       int             vr_refcnt;
8952 +
8953 +       struct semaphore        vr_ctl_mutex;
8954 +       struct block_device    *vr_device;
8955 +       int                     vr_state;
8956 +};
8957 +
8958 +
8959 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8960 +
8961 +extern int register_vroot_grb(vroot_grb_func *);
8962 +extern int unregister_vroot_grb(vroot_grb_func *);
8963 +
8964 +#endif /* __KERNEL__ */
8965 +
8966 +#define MAX_VROOT_DEFAULT      8
8967 +
8968 +/*
8969 + * IOCTL commands --- we will commandeer 0x56 ('V')
8970 + */
8971 +
8972 +#define VROOT_SET_DEV          0x5600
8973 +#define VROOT_CLR_DEV          0x5601
8974 +
8975 +#endif /* _LINUX_VROOT_H */
8976 diff -NurpP --minimal linux-3.2.8/include/linux/vs_base.h linux-3.2.8-vs2.3.2.7/include/linux/vs_base.h
8977 --- linux-3.2.8/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8978 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_base.h       2011-12-05 19:33:02.000000000 +0100
8979 @@ -0,0 +1,10 @@
8980 +#ifndef _VS_BASE_H
8981 +#define _VS_BASE_H
8982 +
8983 +#include "vserver/base.h"
8984 +#include "vserver/check.h"
8985 +#include "vserver/debug.h"
8986 +
8987 +#else
8988 +#warning duplicate inclusion
8989 +#endif
8990 diff -NurpP --minimal linux-3.2.8/include/linux/vs_context.h linux-3.2.8-vs2.3.2.7/include/linux/vs_context.h
8991 --- linux-3.2.8/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
8992 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_context.h    2011-12-05 19:33:02.000000000 +0100
8993 @@ -0,0 +1,242 @@
8994 +#ifndef _VS_CONTEXT_H
8995 +#define _VS_CONTEXT_H
8996 +
8997 +#include "vserver/base.h"
8998 +#include "vserver/check.h"
8999 +#include "vserver/context.h"
9000 +#include "vserver/history.h"
9001 +#include "vserver/debug.h"
9002 +
9003 +#include <linux/sched.h>
9004 +
9005 +
9006 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9007 +
9008 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9009 +       const char *_file, int _line, void *_here)
9010 +{
9011 +       if (!vxi)
9012 +               return NULL;
9013 +
9014 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9015 +               vxi, vxi ? vxi->vx_id : 0,
9016 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9017 +               _file, _line);
9018 +       __vxh_get_vx_info(vxi, _here);
9019 +
9020 +       atomic_inc(&vxi->vx_usecnt);
9021 +       return vxi;
9022 +}
9023 +
9024 +
9025 +extern void free_vx_info(struct vx_info *);
9026 +
9027 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9028 +
9029 +static inline void __put_vx_info(struct vx_info *vxi,
9030 +       const char *_file, int _line, void *_here)
9031 +{
9032 +       if (!vxi)
9033 +               return;
9034 +
9035 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9036 +               vxi, vxi ? vxi->vx_id : 0,
9037 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9038 +               _file, _line);
9039 +       __vxh_put_vx_info(vxi, _here);
9040 +
9041 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9042 +               free_vx_info(vxi);
9043 +}
9044 +
9045 +
9046 +#define init_vx_info(p, i) \
9047 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9048 +
9049 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9050 +       const char *_file, int _line, void *_here)
9051 +{
9052 +       if (vxi) {
9053 +               vxlprintk(VXD_CBIT(xid, 3),
9054 +                       "init_vx_info(%p[#%d.%d])",
9055 +                       vxi, vxi ? vxi->vx_id : 0,
9056 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9057 +                       _file, _line);
9058 +               __vxh_init_vx_info(vxi, vxp, _here);
9059 +
9060 +               atomic_inc(&vxi->vx_usecnt);
9061 +       }
9062 +       *vxp = vxi;
9063 +}
9064 +
9065 +
9066 +#define set_vx_info(p, i) \
9067 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9068 +
9069 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9070 +       const char *_file, int _line, void *_here)
9071 +{
9072 +       struct vx_info *vxo;
9073 +
9074 +       if (!vxi)
9075 +               return;
9076 +
9077 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9078 +               vxi, vxi ? vxi->vx_id : 0,
9079 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9080 +               _file, _line);
9081 +       __vxh_set_vx_info(vxi, vxp, _here);
9082 +
9083 +       atomic_inc(&vxi->vx_usecnt);
9084 +       vxo = xchg(vxp, vxi);
9085 +       BUG_ON(vxo);
9086 +}
9087 +
9088 +
9089 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9090 +
9091 +static inline void __clr_vx_info(struct vx_info **vxp,
9092 +       const char *_file, int _line, void *_here)
9093 +{
9094 +       struct vx_info *vxo;
9095 +
9096 +       vxo = xchg(vxp, NULL);
9097 +       if (!vxo)
9098 +               return;
9099 +
9100 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9101 +               vxo, vxo ? vxo->vx_id : 0,
9102 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9103 +               _file, _line);
9104 +       __vxh_clr_vx_info(vxo, vxp, _here);
9105 +
9106 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9107 +               free_vx_info(vxo);
9108 +}
9109 +
9110 +
9111 +#define claim_vx_info(v, p) \
9112 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9113 +
9114 +static inline void __claim_vx_info(struct vx_info *vxi,
9115 +       struct task_struct *task,
9116 +       const char *_file, int _line, void *_here)
9117 +{
9118 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9119 +               vxi, vxi ? vxi->vx_id : 0,
9120 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9121 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9122 +               task, _file, _line);
9123 +       __vxh_claim_vx_info(vxi, task, _here);
9124 +
9125 +       atomic_inc(&vxi->vx_tasks);
9126 +}
9127 +
9128 +
9129 +extern void unhash_vx_info(struct vx_info *);
9130 +
9131 +#define release_vx_info(v, p) \
9132 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9133 +
9134 +static inline void __release_vx_info(struct vx_info *vxi,
9135 +       struct task_struct *task,
9136 +       const char *_file, int _line, void *_here)
9137 +{
9138 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9139 +               vxi, vxi ? vxi->vx_id : 0,
9140 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9141 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9142 +               task, _file, _line);
9143 +       __vxh_release_vx_info(vxi, task, _here);
9144 +
9145 +       might_sleep();
9146 +
9147 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9148 +               unhash_vx_info(vxi);
9149 +}
9150 +
9151 +
9152 +#define task_get_vx_info(p) \
9153 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9154 +
9155 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9156 +       const char *_file, int _line, void *_here)
9157 +{
9158 +       struct vx_info *vxi;
9159 +
9160 +       task_lock(p);
9161 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9162 +               p, _file, _line);
9163 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9164 +       task_unlock(p);
9165 +       return vxi;
9166 +}
9167 +
9168 +
9169 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9170 +{
9171 +       if (waitqueue_active(&vxi->vx_wait))
9172 +               wake_up_interruptible(&vxi->vx_wait);
9173 +}
9174 +
9175 +
9176 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9177 +
9178 +static inline void __enter_vx_info(struct vx_info *vxi,
9179 +       struct vx_info_save *vxis, const char *_file, int _line)
9180 +{
9181 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9182 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9183 +               current->xid, current->vx_info, _file, _line);
9184 +       vxis->vxi = xchg(&current->vx_info, vxi);
9185 +       vxis->xid = current->xid;
9186 +       current->xid = vxi ? vxi->vx_id : 0;
9187 +}
9188 +
9189 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9190 +
9191 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9192 +       const char *_file, int _line)
9193 +{
9194 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9195 +               vxis, vxis->xid, vxis->vxi, current,
9196 +               current->xid, current->vx_info, _file, _line);
9197 +       (void)xchg(&current->vx_info, vxis->vxi);
9198 +       current->xid = vxis->xid;
9199 +}
9200 +
9201 +
9202 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9203 +{
9204 +       vxis->vxi = xchg(&current->vx_info, NULL);
9205 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9206 +}
9207 +
9208 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9209 +{
9210 +       (void)xchg(&current->xid, vxis->xid);
9211 +       (void)xchg(&current->vx_info, vxis->vxi);
9212 +}
9213 +
9214 +#define task_is_init(p) \
9215 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9216 +
9217 +static inline int __task_is_init(struct task_struct *p,
9218 +       const char *_file, int _line, void *_here)
9219 +{
9220 +       int is_init = is_global_init(p);
9221 +
9222 +       task_lock(p);
9223 +       if (p->vx_info)
9224 +               is_init = p->vx_info->vx_initpid == p->pid;
9225 +       task_unlock(p);
9226 +       return is_init;
9227 +}
9228 +
9229 +extern void exit_vx_info(struct task_struct *, int);
9230 +extern void exit_vx_info_early(struct task_struct *, int);
9231 +
9232 +
9233 +#else
9234 +#warning duplicate inclusion
9235 +#endif
9236 diff -NurpP --minimal linux-3.2.8/include/linux/vs_cowbl.h linux-3.2.8-vs2.3.2.7/include/linux/vs_cowbl.h
9237 --- linux-3.2.8/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9238 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_cowbl.h      2011-12-05 19:33:02.000000000 +0100
9239 @@ -0,0 +1,48 @@
9240 +#ifndef _VS_COWBL_H
9241 +#define _VS_COWBL_H
9242 +
9243 +#include <linux/fs.h>
9244 +#include <linux/dcache.h>
9245 +#include <linux/namei.h>
9246 +#include <linux/slab.h>
9247 +
9248 +extern struct dentry *cow_break_link(const char *pathname);
9249 +
9250 +static inline int cow_check_and_break(struct path *path)
9251 +{
9252 +       struct inode *inode = path->dentry->d_inode;
9253 +       int error = 0;
9254 +
9255 +       /* do we need this check? */
9256 +       if (IS_RDONLY(inode))
9257 +               return -EROFS;
9258 +
9259 +       if (IS_COW(inode)) {
9260 +               if (IS_COW_LINK(inode)) {
9261 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9262 +                       char *pp, *buf;
9263 +
9264 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9265 +                       if (!buf) {
9266 +                               return -ENOMEM;
9267 +                       }
9268 +                       pp = d_path(path, buf, PATH_MAX);
9269 +                       new_dentry = cow_break_link(pp);
9270 +                       kfree(buf);
9271 +                       if (!IS_ERR(new_dentry)) {
9272 +                               path->dentry = new_dentry;
9273 +                               dput(old_dentry);
9274 +                       } else
9275 +                               error = PTR_ERR(new_dentry);
9276 +               } else {
9277 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9278 +                       inode->i_ctime = CURRENT_TIME;
9279 +                       mark_inode_dirty(inode);
9280 +               }
9281 +       }
9282 +       return error;
9283 +}
9284 +
9285 +#else
9286 +#warning duplicate inclusion
9287 +#endif
9288 diff -NurpP --minimal linux-3.2.8/include/linux/vs_cvirt.h linux-3.2.8-vs2.3.2.7/include/linux/vs_cvirt.h
9289 --- linux-3.2.8/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9290 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_cvirt.h      2011-12-05 19:33:02.000000000 +0100
9291 @@ -0,0 +1,50 @@
9292 +#ifndef _VS_CVIRT_H
9293 +#define _VS_CVIRT_H
9294 +
9295 +#include "vserver/cvirt.h"
9296 +#include "vserver/context.h"
9297 +#include "vserver/base.h"
9298 +#include "vserver/check.h"
9299 +#include "vserver/debug.h"
9300 +
9301 +
9302 +static inline void vx_activate_task(struct task_struct *p)
9303 +{
9304 +       struct vx_info *vxi;
9305 +
9306 +       if ((vxi = p->vx_info)) {
9307 +               vx_update_load(vxi);
9308 +               atomic_inc(&vxi->cvirt.nr_running);
9309 +       }
9310 +}
9311 +
9312 +static inline void vx_deactivate_task(struct task_struct *p)
9313 +{
9314 +       struct vx_info *vxi;
9315 +
9316 +       if ((vxi = p->vx_info)) {
9317 +               vx_update_load(vxi);
9318 +               atomic_dec(&vxi->cvirt.nr_running);
9319 +       }
9320 +}
9321 +
9322 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9323 +{
9324 +       struct vx_info *vxi;
9325 +
9326 +       if ((vxi = p->vx_info))
9327 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9328 +}
9329 +
9330 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9331 +{
9332 +       struct vx_info *vxi;
9333 +
9334 +       if ((vxi = p->vx_info))
9335 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9336 +}
9337 +
9338 +
9339 +#else
9340 +#warning duplicate inclusion
9341 +#endif
9342 diff -NurpP --minimal linux-3.2.8/include/linux/vs_device.h linux-3.2.8-vs2.3.2.7/include/linux/vs_device.h
9343 --- linux-3.2.8/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9344 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_device.h     2011-12-05 19:33:02.000000000 +0100
9345 @@ -0,0 +1,45 @@
9346 +#ifndef _VS_DEVICE_H
9347 +#define _VS_DEVICE_H
9348 +
9349 +#include "vserver/base.h"
9350 +#include "vserver/device.h"
9351 +#include "vserver/debug.h"
9352 +
9353 +
9354 +#ifdef CONFIG_VSERVER_DEVICE
9355 +
9356 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9357 +
9358 +#define vs_device_perm(v, d, m, p) \
9359 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9360 +
9361 +#else
9362 +
9363 +static inline
9364 +int vs_map_device(struct vx_info *vxi,
9365 +       dev_t device, dev_t *target, umode_t mode)
9366 +{
9367 +       if (target)
9368 +               *target = device;
9369 +       return ~0;
9370 +}
9371 +
9372 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9373 +
9374 +#endif
9375 +
9376 +
9377 +#define vs_map_chrdev(d, t, p) \
9378 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9379 +#define vs_map_blkdev(d, t, p) \
9380 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9381 +
9382 +#define vs_chrdev_perm(d, p) \
9383 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9384 +#define vs_blkdev_perm(d, p) \
9385 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9386 +
9387 +
9388 +#else
9389 +#warning duplicate inclusion
9390 +#endif
9391 diff -NurpP --minimal linux-3.2.8/include/linux/vs_dlimit.h linux-3.2.8-vs2.3.2.7/include/linux/vs_dlimit.h
9392 --- linux-3.2.8/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9393 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_dlimit.h     2011-12-05 19:33:02.000000000 +0100
9394 @@ -0,0 +1,215 @@
9395 +#ifndef _VS_DLIMIT_H
9396 +#define _VS_DLIMIT_H
9397 +
9398 +#include <linux/fs.h>
9399 +
9400 +#include "vserver/dlimit.h"
9401 +#include "vserver/base.h"
9402 +#include "vserver/debug.h"
9403 +
9404 +
9405 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9406 +
9407 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9408 +       const char *_file, int _line)
9409 +{
9410 +       if (!dli)
9411 +               return NULL;
9412 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9413 +               dli, dli ? dli->dl_tag : 0,
9414 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9415 +               _file, _line);
9416 +       atomic_inc(&dli->dl_usecnt);
9417 +       return dli;
9418 +}
9419 +
9420 +
9421 +#define free_dl_info(i) \
9422 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9423 +
9424 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9425 +
9426 +static inline void __put_dl_info(struct dl_info *dli,
9427 +       const char *_file, int _line)
9428 +{
9429 +       if (!dli)
9430 +               return;
9431 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9432 +               dli, dli ? dli->dl_tag : 0,
9433 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9434 +               _file, _line);
9435 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9436 +               free_dl_info(dli);
9437 +}
9438 +
9439 +
9440 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9441 +
9442 +static inline int __dl_alloc_space(struct super_block *sb,
9443 +       tag_t tag, dlsize_t nr, const char *file, int line)
9444 +{
9445 +       struct dl_info *dli = NULL;
9446 +       int ret = 0;
9447 +
9448 +       if (nr == 0)
9449 +               goto out;
9450 +       dli = locate_dl_info(sb, tag);
9451 +       if (!dli)
9452 +               goto out;
9453 +
9454 +       spin_lock(&dli->dl_lock);
9455 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9456 +       if (!ret)
9457 +               dli->dl_space_used += nr;
9458 +       spin_unlock(&dli->dl_lock);
9459 +       put_dl_info(dli);
9460 +out:
9461 +       vxlprintk(VXD_CBIT(dlim, 1),
9462 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9463 +               sb, tag, __dlimit_char(dli), (long long)nr,
9464 +               ret, file, line);
9465 +       return ret ? -ENOSPC : 0;
9466 +}
9467 +
9468 +static inline void __dl_free_space(struct super_block *sb,
9469 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9470 +{
9471 +       struct dl_info *dli = NULL;
9472 +
9473 +       if (nr == 0)
9474 +               goto out;
9475 +       dli = locate_dl_info(sb, tag);
9476 +       if (!dli)
9477 +               goto out;
9478 +
9479 +       spin_lock(&dli->dl_lock);
9480 +       if (dli->dl_space_used > nr)
9481 +               dli->dl_space_used -= nr;
9482 +       else
9483 +               dli->dl_space_used = 0;
9484 +       spin_unlock(&dli->dl_lock);
9485 +       put_dl_info(dli);
9486 +out:
9487 +       vxlprintk(VXD_CBIT(dlim, 1),
9488 +               "FREE  (%p,#%d)%c %lld bytes",
9489 +               sb, tag, __dlimit_char(dli), (long long)nr,
9490 +               _file, _line);
9491 +}
9492 +
9493 +static inline int __dl_alloc_inode(struct super_block *sb,
9494 +       tag_t tag, const char *_file, int _line)
9495 +{
9496 +       struct dl_info *dli;
9497 +       int ret = 0;
9498 +
9499 +       dli = locate_dl_info(sb, tag);
9500 +       if (!dli)
9501 +               goto out;
9502 +
9503 +       spin_lock(&dli->dl_lock);
9504 +       dli->dl_inodes_used++;
9505 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9506 +       spin_unlock(&dli->dl_lock);
9507 +       put_dl_info(dli);
9508 +out:
9509 +       vxlprintk(VXD_CBIT(dlim, 0),
9510 +               "ALLOC (%p,#%d)%c inode (%d)",
9511 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9512 +       return ret ? -ENOSPC : 0;
9513 +}
9514 +
9515 +static inline void __dl_free_inode(struct super_block *sb,
9516 +       tag_t tag, const char *_file, int _line)
9517 +{
9518 +       struct dl_info *dli;
9519 +
9520 +       dli = locate_dl_info(sb, tag);
9521 +       if (!dli)
9522 +               goto out;
9523 +
9524 +       spin_lock(&dli->dl_lock);
9525 +       if (dli->dl_inodes_used > 1)
9526 +               dli->dl_inodes_used--;
9527 +       else
9528 +               dli->dl_inodes_used = 0;
9529 +       spin_unlock(&dli->dl_lock);
9530 +       put_dl_info(dli);
9531 +out:
9532 +       vxlprintk(VXD_CBIT(dlim, 0),
9533 +               "FREE  (%p,#%d)%c inode",
9534 +               sb, tag, __dlimit_char(dli), _file, _line);
9535 +}
9536 +
9537 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9538 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9539 +       const char *_file, int _line)
9540 +{
9541 +       struct dl_info *dli;
9542 +       uint64_t broot, bfree;
9543 +
9544 +       dli = locate_dl_info(sb, tag);
9545 +       if (!dli)
9546 +               return;
9547 +
9548 +       spin_lock(&dli->dl_lock);
9549 +       broot = (dli->dl_space_total -
9550 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9551 +               >> sb->s_blocksize_bits;
9552 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9553 +                       >> sb->s_blocksize_bits;
9554 +       spin_unlock(&dli->dl_lock);
9555 +
9556 +       vxlprintk(VXD_CBIT(dlim, 2),
9557 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9558 +               (long long)bfree, (long long)broot,
9559 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9560 +               _file, _line);
9561 +       if (free_blocks) {
9562 +               if (*free_blocks > bfree)
9563 +                       *free_blocks = bfree;
9564 +       }
9565 +       if (root_blocks) {
9566 +               if (*root_blocks > broot)
9567 +                       *root_blocks = broot;
9568 +       }
9569 +       put_dl_info(dli);
9570 +}
9571 +
9572 +#define dl_prealloc_space(in, bytes) \
9573 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9574 +               __FILE__, __LINE__ )
9575 +
9576 +#define dl_alloc_space(in, bytes) \
9577 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9578 +               __FILE__, __LINE__ )
9579 +
9580 +#define dl_reserve_space(in, bytes) \
9581 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9582 +               __FILE__, __LINE__ )
9583 +
9584 +#define dl_claim_space(in, bytes) (0)
9585 +
9586 +#define dl_release_space(in, bytes) \
9587 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9588 +               __FILE__, __LINE__ )
9589 +
9590 +#define dl_free_space(in, bytes) \
9591 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9592 +               __FILE__, __LINE__ )
9593 +
9594 +
9595 +
9596 +#define dl_alloc_inode(in) \
9597 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9598 +
9599 +#define dl_free_inode(in) \
9600 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9601 +
9602 +
9603 +#define dl_adjust_block(sb, tag, fb, rb) \
9604 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9605 +
9606 +
9607 +#else
9608 +#warning duplicate inclusion
9609 +#endif
9610 diff -NurpP --minimal linux-3.2.8/include/linux/vs_inet.h linux-3.2.8-vs2.3.2.7/include/linux/vs_inet.h
9611 --- linux-3.2.8/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9612 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_inet.h       2012-02-15 03:03:53.000000000 +0100
9613 @@ -0,0 +1,353 @@
9614 +#ifndef _VS_INET_H
9615 +#define _VS_INET_H
9616 +
9617 +#include "vserver/base.h"
9618 +#include "vserver/network.h"
9619 +#include "vserver/debug.h"
9620 +
9621 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9622 +
9623 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9624 +                       NIPQUAD((a)->mask), (a)->type
9625 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9626 +
9627 +#define NIPQUAD(addr) \
9628 +       ((unsigned char *)&addr)[0], \
9629 +       ((unsigned char *)&addr)[1], \
9630 +       ((unsigned char *)&addr)[2], \
9631 +       ((unsigned char *)&addr)[3]
9632 +
9633 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9634 +
9635 +
9636 +static inline
9637 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9638 +{
9639 +       __be32 ip = nxa->ip[0].s_addr;
9640 +       __be32 mask = nxa->mask.s_addr;
9641 +       __be32 bcast = ip | ~mask;
9642 +       int ret = 0;
9643 +
9644 +       switch (nxa->type & tmask) {
9645 +       case NXA_TYPE_MASK:
9646 +               ret = (ip == (addr & mask));
9647 +               break;
9648 +       case NXA_TYPE_ADDR:
9649 +               ret = 3;
9650 +               if (addr == ip)
9651 +                       break;
9652 +               /* fall through to broadcast */
9653 +       case NXA_MOD_BCAST:
9654 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9655 +               break;
9656 +       case NXA_TYPE_RANGE:
9657 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9658 +                       (nxa->ip[1].s_addr > addr));
9659 +               break;
9660 +       case NXA_TYPE_ANY:
9661 +               ret = 2;
9662 +               break;
9663 +       }
9664 +
9665 +       vxdprintk(VXD_CBIT(net, 0),
9666 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9667 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9668 +       return ret;
9669 +}
9670 +
9671 +static inline
9672 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9673 +{
9674 +       struct nx_addr_v4 *nxa;
9675 +       int ret = 1;
9676 +
9677 +       if (!nxi)
9678 +               goto out;
9679 +
9680 +       ret = 2;
9681 +       /* allow 127.0.0.1 when remapping lback */
9682 +       if ((tmask & NXA_LOOPBACK) &&
9683 +               (addr == IPI_LOOPBACK) &&
9684 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9685 +               goto out;
9686 +       ret = 3;
9687 +       /* check for lback address */
9688 +       if ((tmask & NXA_MOD_LBACK) &&
9689 +               (nxi->v4_lback.s_addr == addr))
9690 +               goto out;
9691 +       ret = 4;
9692 +       /* check for broadcast address */
9693 +       if ((tmask & NXA_MOD_BCAST) &&
9694 +               (nxi->v4_bcast.s_addr == addr))
9695 +               goto out;
9696 +       ret = 5;
9697 +       /* check for v4 addresses */
9698 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9699 +               if (v4_addr_match(nxa, addr, tmask))
9700 +                       goto out;
9701 +       ret = 0;
9702 +out:
9703 +       vxdprintk(VXD_CBIT(net, 0),
9704 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9705 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9706 +       return ret;
9707 +}
9708 +
9709 +static inline
9710 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9711 +{
9712 +       /* FIXME: needs full range checks */
9713 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9714 +}
9715 +
9716 +static inline
9717 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9718 +{
9719 +       struct nx_addr_v4 *ptr;
9720 +
9721 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9722 +               if (v4_nx_addr_match(ptr, nxa, mask))
9723 +                       return 1;
9724 +       return 0;
9725 +}
9726 +
9727 +#include <net/inet_sock.h>
9728 +
9729 +/*
9730 + *     Check if a given address matches for a socket
9731 + *
9732 + *     nxi:            the socket's nx_info if any
9733 + *     addr:           to be verified address
9734 + */
9735 +static inline
9736 +int v4_sock_addr_match (
9737 +       struct nx_info *nxi,
9738 +       struct inet_sock *inet,
9739 +       __be32 addr)
9740 +{
9741 +       __be32 saddr = inet->inet_rcv_saddr;
9742 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9743 +
9744 +       if (addr && (saddr == addr || bcast == addr))
9745 +               return 1;
9746 +       if (!saddr)
9747 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9748 +       return 0;
9749 +}
9750 +
9751 +
9752 +/* inet related checks and helpers */
9753 +
9754 +
9755 +struct in_ifaddr;
9756 +struct net_device;
9757 +struct sock;
9758 +
9759 +#ifdef CONFIG_INET
9760 +
9761 +#include <linux/netdevice.h>
9762 +#include <linux/inetdevice.h>
9763 +#include <net/inet_sock.h>
9764 +#include <net/inet_timewait_sock.h>
9765 +
9766 +
9767 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9768 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9769 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9770 +
9771 +
9772 +/*
9773 + *     check if address is covered by socket
9774 + *
9775 + *     sk:     the socket to check against
9776 + *     addr:   the address in question (must be != 0)
9777 + */
9778 +
9779 +static inline
9780 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9781 +{
9782 +       struct nx_info *nxi = sk->sk_nx_info;
9783 +       __be32 saddr = sk_rcv_saddr(sk);
9784 +
9785 +       vxdprintk(VXD_CBIT(net, 5),
9786 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9787 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9788 +               (sk->sk_socket?sk->sk_socket->flags:0));
9789 +
9790 +       if (saddr) {            /* direct address match */
9791 +               return v4_addr_match(nxa, saddr, -1);
9792 +       } else if (nxi) {       /* match against nx_info */
9793 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9794 +       } else {                /* unrestricted any socket */
9795 +               return 1;
9796 +       }
9797 +}
9798 +
9799 +
9800 +
9801 +static inline
9802 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9803 +{
9804 +       vxdprintk(VXD_CBIT(net, 1),
9805 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9806 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9807 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9808 +
9809 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9810 +               return 1;
9811 +       if (dev_in_nx_info(dev, nxi))
9812 +               return 1;
9813 +       return 0;
9814 +}
9815 +
9816 +
9817 +static inline
9818 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9819 +{
9820 +       if (!nxi)
9821 +               return 1;
9822 +       if (!ifa)
9823 +               return 0;
9824 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9825 +}
9826 +
9827 +static inline
9828 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9829 +{
9830 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9831 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9832 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9833 +
9834 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9835 +               return 1;
9836 +       if (v4_ifa_in_nx_info(ifa, nxi))
9837 +               return 1;
9838 +       return 0;
9839 +}
9840 +
9841 +
9842 +struct nx_v4_sock_addr {
9843 +       __be32 saddr;   /* Address used for validation */
9844 +       __be32 baddr;   /* Address used for socket bind */
9845 +};
9846 +
9847 +static inline
9848 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9849 +       struct nx_v4_sock_addr *nsa)
9850 +{
9851 +       struct sock *sk = &inet->sk;
9852 +       struct nx_info *nxi = sk->sk_nx_info;
9853 +       __be32 saddr = addr->sin_addr.s_addr;
9854 +       __be32 baddr = saddr;
9855 +
9856 +       vxdprintk(VXD_CBIT(net, 3),
9857 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9858 +               sk, sk->sk_nx_info, sk->sk_socket,
9859 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9860 +               NIPQUAD(saddr));
9861 +
9862 +       if (nxi) {
9863 +               if (saddr == INADDR_ANY) {
9864 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9865 +                               baddr = nxi->v4.ip[0].s_addr;
9866 +               } else if (saddr == IPI_LOOPBACK) {
9867 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9868 +                               baddr = nxi->v4_lback.s_addr;
9869 +               } else if (!ipv4_is_multicast(saddr) ||
9870 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9871 +                       /* normal address bind */
9872 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9873 +                               return -EADDRNOTAVAIL;
9874 +               }
9875 +       }
9876 +
9877 +       vxdprintk(VXD_CBIT(net, 3),
9878 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9879 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9880 +
9881 +       nsa->saddr = saddr;
9882 +       nsa->baddr = baddr;
9883 +       return 0;
9884 +}
9885 +
9886 +static inline
9887 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9888 +{
9889 +       inet->inet_saddr = nsa->baddr;
9890 +       inet->inet_rcv_saddr = nsa->baddr;
9891 +}
9892 +
9893 +
9894 +/*
9895 + *      helper to simplify inet_lookup_listener
9896 + *
9897 + *      nxi:   the socket's nx_info if any
9898 + *      addr:  to be verified address
9899 + *      saddr: socket address
9900 + */
9901 +static inline int v4_inet_addr_match (
9902 +       struct nx_info *nxi,
9903 +       __be32 addr,
9904 +       __be32 saddr)
9905 +{
9906 +       if (addr && (saddr == addr))
9907 +               return 1;
9908 +       if (!saddr)
9909 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9910 +       return 0;
9911 +}
9912 +
9913 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9914 +{
9915 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9916 +               (addr == nxi->v4_lback.s_addr))
9917 +               return IPI_LOOPBACK;
9918 +       return addr;
9919 +}
9920 +
9921 +static inline
9922 +int nx_info_has_v4(struct nx_info *nxi)
9923 +{
9924 +       if (!nxi)
9925 +               return 1;
9926 +       if (NX_IPV4(nxi))
9927 +               return 1;
9928 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9929 +               return 1;
9930 +       return 0;
9931 +}
9932 +
9933 +#else /* CONFIG_INET */
9934 +
9935 +static inline
9936 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9937 +{
9938 +       return 1;
9939 +}
9940 +
9941 +static inline
9942 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9943 +{
9944 +       return 1;
9945 +}
9946 +
9947 +static inline
9948 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9949 +{
9950 +       return 1;
9951 +}
9952 +
9953 +static inline
9954 +int nx_info_has_v4(struct nx_info *nxi)
9955 +{
9956 +       return 0;
9957 +}
9958 +
9959 +#endif /* CONFIG_INET */
9960 +
9961 +#define current_nx_info_has_v4() \
9962 +       nx_info_has_v4(current_nx_info())
9963 +
9964 +#else
9965 +// #warning duplicate inclusion
9966 +#endif
9967 diff -NurpP --minimal linux-3.2.8/include/linux/vs_inet6.h linux-3.2.8-vs2.3.2.7/include/linux/vs_inet6.h
9968 --- linux-3.2.8/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
9969 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_inet6.h      2011-12-05 19:33:02.000000000 +0100
9970 @@ -0,0 +1,246 @@
9971 +#ifndef _VS_INET6_H
9972 +#define _VS_INET6_H
9973 +
9974 +#include "vserver/base.h"
9975 +#include "vserver/network.h"
9976 +#include "vserver/debug.h"
9977 +
9978 +#include <net/ipv6.h>
9979 +
9980 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9981 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9982 +
9983 +
9984 +#ifdef CONFIG_IPV6
9985 +
9986 +static inline
9987 +int v6_addr_match(struct nx_addr_v6 *nxa,
9988 +       const struct in6_addr *addr, uint16_t mask)
9989 +{
9990 +       int ret = 0;
9991 +
9992 +       switch (nxa->type & mask) {
9993 +       case NXA_TYPE_MASK:
9994 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9995 +               break;
9996 +       case NXA_TYPE_ADDR:
9997 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9998 +               break;
9999 +       case NXA_TYPE_ANY:
10000 +               ret = 1;
10001 +               break;
10002 +       }
10003 +       vxdprintk(VXD_CBIT(net, 0),
10004 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10005 +               nxa, NXAV6(nxa), addr, mask, ret);
10006 +       return ret;
10007 +}
10008 +
10009 +static inline
10010 +int v6_addr_in_nx_info(struct nx_info *nxi,
10011 +       const struct in6_addr *addr, uint16_t mask)
10012 +{
10013 +       struct nx_addr_v6 *nxa;
10014 +       int ret = 1;
10015 +
10016 +       if (!nxi)
10017 +               goto out;
10018 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10019 +               if (v6_addr_match(nxa, addr, mask))
10020 +                       goto out;
10021 +       ret = 0;
10022 +out:
10023 +       vxdprintk(VXD_CBIT(net, 0),
10024 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10025 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10026 +       return ret;
10027 +}
10028 +
10029 +static inline
10030 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10031 +{
10032 +       /* FIXME: needs full range checks */
10033 +       return v6_addr_match(nxa, &addr->ip, mask);
10034 +}
10035 +
10036 +static inline
10037 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10038 +{
10039 +       struct nx_addr_v6 *ptr;
10040 +
10041 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10042 +               if (v6_nx_addr_match(ptr, nxa, mask))
10043 +                       return 1;
10044 +       return 0;
10045 +}
10046 +
10047 +
10048 +/*
10049 + *     Check if a given address matches for a socket
10050 + *
10051 + *     nxi:            the socket's nx_info if any
10052 + *     addr:           to be verified address
10053 + */
10054 +static inline
10055 +int v6_sock_addr_match (
10056 +       struct nx_info *nxi,
10057 +       struct inet_sock *inet,
10058 +       struct in6_addr *addr)
10059 +{
10060 +       struct sock *sk = &inet->sk;
10061 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10062 +
10063 +       if (!ipv6_addr_any(addr) &&
10064 +               ipv6_addr_equal(saddr, addr))
10065 +               return 1;
10066 +       if (ipv6_addr_any(saddr))
10067 +               return v6_addr_in_nx_info(nxi, addr, -1);
10068 +       return 0;
10069 +}
10070 +
10071 +/*
10072 + *     check if address is covered by socket
10073 + *
10074 + *     sk:     the socket to check against
10075 + *     addr:   the address in question (must be != 0)
10076 + */
10077 +
10078 +static inline
10079 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10080 +{
10081 +       struct nx_info *nxi = sk->sk_nx_info;
10082 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10083 +
10084 +       vxdprintk(VXD_CBIT(net, 5),
10085 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10086 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10087 +               (sk->sk_socket?sk->sk_socket->flags:0));
10088 +
10089 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10090 +               return v6_addr_match(nxa, saddr, -1);
10091 +       } else if (nxi) {               /* match against nx_info */
10092 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10093 +       } else {                        /* unrestricted any socket */
10094 +               return 1;
10095 +       }
10096 +}
10097 +
10098 +
10099 +/* inet related checks and helpers */
10100 +
10101 +
10102 +struct in_ifaddr;
10103 +struct net_device;
10104 +struct sock;
10105 +
10106 +
10107 +#include <linux/netdevice.h>
10108 +#include <linux/inetdevice.h>
10109 +#include <net/inet_timewait_sock.h>
10110 +
10111 +
10112 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10113 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10114 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10115 +
10116 +
10117 +
10118 +static inline
10119 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10120 +{
10121 +       if (!nxi)
10122 +               return 1;
10123 +       if (!ifa)
10124 +               return 0;
10125 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10126 +}
10127 +
10128 +static inline
10129 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10130 +{
10131 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10132 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10133 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10134 +
10135 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10136 +               return 1;
10137 +       if (v6_ifa_in_nx_info(ifa, nxi))
10138 +               return 1;
10139 +       return 0;
10140 +}
10141 +
10142 +
10143 +struct nx_v6_sock_addr {
10144 +       struct in6_addr saddr;  /* Address used for validation */
10145 +       struct in6_addr baddr;  /* Address used for socket bind */
10146 +};
10147 +
10148 +static inline
10149 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10150 +       struct nx_v6_sock_addr *nsa)
10151 +{
10152 +       // struct sock *sk = &inet->sk;
10153 +       // struct nx_info *nxi = sk->sk_nx_info;
10154 +       struct in6_addr saddr = addr->sin6_addr;
10155 +       struct in6_addr baddr = saddr;
10156 +
10157 +       nsa->saddr = saddr;
10158 +       nsa->baddr = baddr;
10159 +       return 0;
10160 +}
10161 +
10162 +static inline
10163 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10164 +{
10165 +       // struct sock *sk = &inet->sk;
10166 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10167 +
10168 +       // *saddr = nsa->baddr;
10169 +       // inet->inet_saddr = nsa->baddr;
10170 +}
10171 +
10172 +static inline
10173 +int nx_info_has_v6(struct nx_info *nxi)
10174 +{
10175 +       if (!nxi)
10176 +               return 1;
10177 +       if (NX_IPV6(nxi))
10178 +               return 1;
10179 +       return 0;
10180 +}
10181 +
10182 +#else /* CONFIG_IPV6 */
10183 +
10184 +static inline
10185 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10186 +{
10187 +       return 1;
10188 +}
10189 +
10190 +
10191 +static inline
10192 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10193 +{
10194 +       return 1;
10195 +}
10196 +
10197 +static inline
10198 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10199 +{
10200 +       return 1;
10201 +}
10202 +
10203 +static inline
10204 +int nx_info_has_v6(struct nx_info *nxi)
10205 +{
10206 +       return 0;
10207 +}
10208 +
10209 +#endif /* CONFIG_IPV6 */
10210 +
10211 +#define current_nx_info_has_v6() \
10212 +       nx_info_has_v6(current_nx_info())
10213 +
10214 +#else
10215 +#warning duplicate inclusion
10216 +#endif
10217 diff -NurpP --minimal linux-3.2.8/include/linux/vs_limit.h linux-3.2.8-vs2.3.2.7/include/linux/vs_limit.h
10218 --- linux-3.2.8/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10219 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_limit.h      2011-12-05 19:33:02.000000000 +0100
10220 @@ -0,0 +1,140 @@
10221 +#ifndef _VS_LIMIT_H
10222 +#define _VS_LIMIT_H
10223 +
10224 +#include "vserver/limit.h"
10225 +#include "vserver/base.h"
10226 +#include "vserver/context.h"
10227 +#include "vserver/debug.h"
10228 +#include "vserver/context.h"
10229 +#include "vserver/limit_int.h"
10230 +
10231 +
10232 +#define vx_acc_cres(v, d, p, r) \
10233 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10234 +
10235 +#define vx_acc_cres_cond(x, d, p, r) \
10236 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10237 +       r, d, p, __FILE__, __LINE__)
10238 +
10239 +
10240 +#define vx_add_cres(v, a, p, r) \
10241 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10242 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10243 +
10244 +#define vx_add_cres_cond(x, a, p, r) \
10245 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10246 +       r, a, p, __FILE__, __LINE__)
10247 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10248 +
10249 +
10250 +/* process and file limits */
10251 +
10252 +#define vx_nproc_inc(p) \
10253 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10254 +
10255 +#define vx_nproc_dec(p) \
10256 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10257 +
10258 +#define vx_files_inc(f) \
10259 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10260 +
10261 +#define vx_files_dec(f) \
10262 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10263 +
10264 +#define vx_locks_inc(l) \
10265 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10266 +
10267 +#define vx_locks_dec(l) \
10268 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10269 +
10270 +#define vx_openfd_inc(f) \
10271 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10272 +
10273 +#define vx_openfd_dec(f) \
10274 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10275 +
10276 +
10277 +#define vx_cres_avail(v, n, r) \
10278 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10279 +
10280 +
10281 +#define vx_nproc_avail(n) \
10282 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10283 +
10284 +#define vx_files_avail(n) \
10285 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10286 +
10287 +#define vx_locks_avail(n) \
10288 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10289 +
10290 +#define vx_openfd_avail(n) \
10291 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10292 +
10293 +
10294 +/* dentry limits */
10295 +
10296 +#define vx_dentry_inc(d) do {                                          \
10297 +       if ((d)->d_count == 1)                                          \
10298 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10299 +       } while (0)
10300 +
10301 +#define vx_dentry_dec(d) do {                                          \
10302 +       if ((d)->d_count == 0)                                          \
10303 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10304 +       } while (0)
10305 +
10306 +#define vx_dentry_avail(n) \
10307 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10308 +
10309 +
10310 +/* socket limits */
10311 +
10312 +#define vx_sock_inc(s) \
10313 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10314 +
10315 +#define vx_sock_dec(s) \
10316 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10317 +
10318 +#define vx_sock_avail(n) \
10319 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10320 +
10321 +
10322 +/* ipc resource limits */
10323 +
10324 +#define vx_ipcmsg_add(v, u, a) \
10325 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10326 +
10327 +#define vx_ipcmsg_sub(v, u, a) \
10328 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10329 +
10330 +#define vx_ipcmsg_avail(v, a) \
10331 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10332 +
10333 +
10334 +#define vx_ipcshm_add(v, k, a) \
10335 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10336 +
10337 +#define vx_ipcshm_sub(v, k, a) \
10338 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10339 +
10340 +#define vx_ipcshm_avail(v, a) \
10341 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10342 +
10343 +
10344 +#define vx_semary_inc(a) \
10345 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10346 +
10347 +#define vx_semary_dec(a) \
10348 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10349 +
10350 +
10351 +#define vx_nsems_add(a,n) \
10352 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10353 +
10354 +#define vx_nsems_sub(a,n) \
10355 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10356 +
10357 +
10358 +#else
10359 +#warning duplicate inclusion
10360 +#endif
10361 diff -NurpP --minimal linux-3.2.8/include/linux/vs_network.h linux-3.2.8-vs2.3.2.7/include/linux/vs_network.h
10362 --- linux-3.2.8/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10363 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_network.h    2011-12-05 19:33:02.000000000 +0100
10364 @@ -0,0 +1,169 @@
10365 +#ifndef _NX_VS_NETWORK_H
10366 +#define _NX_VS_NETWORK_H
10367 +
10368 +#include "vserver/context.h"
10369 +#include "vserver/network.h"
10370 +#include "vserver/base.h"
10371 +#include "vserver/check.h"
10372 +#include "vserver/debug.h"
10373 +
10374 +#include <linux/sched.h>
10375 +
10376 +
10377 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10378 +
10379 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10380 +       const char *_file, int _line)
10381 +{
10382 +       if (!nxi)
10383 +               return NULL;
10384 +
10385 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10386 +               nxi, nxi ? nxi->nx_id : 0,
10387 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10388 +               _file, _line);
10389 +
10390 +       atomic_inc(&nxi->nx_usecnt);
10391 +       return nxi;
10392 +}
10393 +
10394 +
10395 +extern void free_nx_info(struct nx_info *);
10396 +
10397 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10398 +
10399 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10400 +{
10401 +       if (!nxi)
10402 +               return;
10403 +
10404 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10405 +               nxi, nxi ? nxi->nx_id : 0,
10406 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10407 +               _file, _line);
10408 +
10409 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10410 +               free_nx_info(nxi);
10411 +}
10412 +
10413 +
10414 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10415 +
10416 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10417 +               const char *_file, int _line)
10418 +{
10419 +       if (nxi) {
10420 +               vxlprintk(VXD_CBIT(nid, 3),
10421 +                       "init_nx_info(%p[#%d.%d])",
10422 +                       nxi, nxi ? nxi->nx_id : 0,
10423 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10424 +                       _file, _line);
10425 +
10426 +               atomic_inc(&nxi->nx_usecnt);
10427 +       }
10428 +       *nxp = nxi;
10429 +}
10430 +
10431 +
10432 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10433 +
10434 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10435 +       const char *_file, int _line)
10436 +{
10437 +       struct nx_info *nxo;
10438 +
10439 +       if (!nxi)
10440 +               return;
10441 +
10442 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10443 +               nxi, nxi ? nxi->nx_id : 0,
10444 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10445 +               _file, _line);
10446 +
10447 +       atomic_inc(&nxi->nx_usecnt);
10448 +       nxo = xchg(nxp, nxi);
10449 +       BUG_ON(nxo);
10450 +}
10451 +
10452 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10453 +
10454 +static inline void __clr_nx_info(struct nx_info **nxp,
10455 +       const char *_file, int _line)
10456 +{
10457 +       struct nx_info *nxo;
10458 +
10459 +       nxo = xchg(nxp, NULL);
10460 +       if (!nxo)
10461 +               return;
10462 +
10463 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10464 +               nxo, nxo ? nxo->nx_id : 0,
10465 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10466 +               _file, _line);
10467 +
10468 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10469 +               free_nx_info(nxo);
10470 +}
10471 +
10472 +
10473 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10474 +
10475 +static inline void __claim_nx_info(struct nx_info *nxi,
10476 +       struct task_struct *task, const char *_file, int _line)
10477 +{
10478 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10479 +               nxi, nxi ? nxi->nx_id : 0,
10480 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10481 +               nxi?atomic_read(&nxi->nx_tasks):0,
10482 +               task, _file, _line);
10483 +
10484 +       atomic_inc(&nxi->nx_tasks);
10485 +}
10486 +
10487 +
10488 +extern void unhash_nx_info(struct nx_info *);
10489 +
10490 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10491 +
10492 +static inline void __release_nx_info(struct nx_info *nxi,
10493 +       struct task_struct *task, const char *_file, int _line)
10494 +{
10495 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10496 +               nxi, nxi ? nxi->nx_id : 0,
10497 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10498 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10499 +               task, _file, _line);
10500 +
10501 +       might_sleep();
10502 +
10503 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10504 +               unhash_nx_info(nxi);
10505 +}
10506 +
10507 +
10508 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10509 +
10510 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10511 +       const char *_file, int _line)
10512 +{
10513 +       struct nx_info *nxi;
10514 +
10515 +       task_lock(p);
10516 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10517 +               p, _file, _line);
10518 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10519 +       task_unlock(p);
10520 +       return nxi;
10521 +}
10522 +
10523 +
10524 +static inline void exit_nx_info(struct task_struct *p)
10525 +{
10526 +       if (p->nx_info)
10527 +               release_nx_info(p->nx_info, p);
10528 +}
10529 +
10530 +
10531 +#else
10532 +#warning duplicate inclusion
10533 +#endif
10534 diff -NurpP --minimal linux-3.2.8/include/linux/vs_pid.h linux-3.2.8-vs2.3.2.7/include/linux/vs_pid.h
10535 --- linux-3.2.8/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10536 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_pid.h        2011-12-05 19:33:02.000000000 +0100
10537 @@ -0,0 +1,50 @@
10538 +#ifndef _VS_PID_H
10539 +#define _VS_PID_H
10540 +
10541 +#include "vserver/base.h"
10542 +#include "vserver/check.h"
10543 +#include "vserver/context.h"
10544 +#include "vserver/debug.h"
10545 +#include "vserver/pid.h"
10546 +#include <linux/pid_namespace.h>
10547 +
10548 +
10549 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10550 +
10551 +static inline
10552 +int vx_proc_task_visible(struct task_struct *task)
10553 +{
10554 +       if ((task->pid == 1) &&
10555 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10556 +               /* show a blend through init */
10557 +               goto visible;
10558 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10559 +               goto visible;
10560 +       return 0;
10561 +visible:
10562 +       return 1;
10563 +}
10564 +
10565 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10566 +
10567 +
10568 +static inline
10569 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10570 +{
10571 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10572 +
10573 +       if (task && !vx_proc_task_visible(task)) {
10574 +               vxdprintk(VXD_CBIT(misc, 6),
10575 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10576 +                       task, task->xid, task->pid,
10577 +                       current, current->xid, current->pid);
10578 +               put_task_struct(task);
10579 +               task = NULL;
10580 +       }
10581 +       return task;
10582 +}
10583 +
10584 +
10585 +#else
10586 +#warning duplicate inclusion
10587 +#endif
10588 diff -NurpP --minimal linux-3.2.8/include/linux/vs_sched.h linux-3.2.8-vs2.3.2.7/include/linux/vs_sched.h
10589 --- linux-3.2.8/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10590 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_sched.h      2011-12-05 19:33:02.000000000 +0100
10591 @@ -0,0 +1,40 @@
10592 +#ifndef _VS_SCHED_H
10593 +#define _VS_SCHED_H
10594 +
10595 +#include "vserver/base.h"
10596 +#include "vserver/context.h"
10597 +#include "vserver/sched.h"
10598 +
10599 +
10600 +#define MAX_PRIO_BIAS           20
10601 +#define MIN_PRIO_BIAS          -20
10602 +
10603 +static inline
10604 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10605 +{
10606 +       struct vx_info *vxi = p->vx_info;
10607 +
10608 +       if (vxi)
10609 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10610 +       return prio;
10611 +}
10612 +
10613 +static inline void vx_account_user(struct vx_info *vxi,
10614 +       cputime_t cputime, int nice)
10615 +{
10616 +       if (!vxi)
10617 +               return;
10618 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10619 +}
10620 +
10621 +static inline void vx_account_system(struct vx_info *vxi,
10622 +       cputime_t cputime, int idle)
10623 +{
10624 +       if (!vxi)
10625 +               return;
10626 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10627 +}
10628 +
10629 +#else
10630 +#warning duplicate inclusion
10631 +#endif
10632 diff -NurpP --minimal linux-3.2.8/include/linux/vs_socket.h linux-3.2.8-vs2.3.2.7/include/linux/vs_socket.h
10633 --- linux-3.2.8/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10634 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_socket.h     2011-12-05 19:33:02.000000000 +0100
10635 @@ -0,0 +1,67 @@
10636 +#ifndef _VS_SOCKET_H
10637 +#define _VS_SOCKET_H
10638 +
10639 +#include "vserver/debug.h"
10640 +#include "vserver/base.h"
10641 +#include "vserver/cacct.h"
10642 +#include "vserver/context.h"
10643 +#include "vserver/tag.h"
10644 +
10645 +
10646 +/* socket accounting */
10647 +
10648 +#include <linux/socket.h>
10649 +
10650 +static inline int vx_sock_type(int family)
10651 +{
10652 +       switch (family) {
10653 +       case PF_UNSPEC:
10654 +               return VXA_SOCK_UNSPEC;
10655 +       case PF_UNIX:
10656 +               return VXA_SOCK_UNIX;
10657 +       case PF_INET:
10658 +               return VXA_SOCK_INET;
10659 +       case PF_INET6:
10660 +               return VXA_SOCK_INET6;
10661 +       case PF_PACKET:
10662 +               return VXA_SOCK_PACKET;
10663 +       default:
10664 +               return VXA_SOCK_OTHER;
10665 +       }
10666 +}
10667 +
10668 +#define vx_acc_sock(v, f, p, s) \
10669 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10670 +
10671 +static inline void __vx_acc_sock(struct vx_info *vxi,
10672 +       int family, int pos, int size, char *file, int line)
10673 +{
10674 +       if (vxi) {
10675 +               int type = vx_sock_type(family);
10676 +
10677 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10678 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10679 +       }
10680 +}
10681 +
10682 +#define vx_sock_recv(sk, s) \
10683 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10684 +#define vx_sock_send(sk, s) \
10685 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10686 +#define vx_sock_fail(sk, s) \
10687 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10688 +
10689 +
10690 +#define sock_vx_init(s) do {           \
10691 +       (s)->sk_xid = 0;                \
10692 +       (s)->sk_vx_info = NULL;         \
10693 +       } while (0)
10694 +
10695 +#define sock_nx_init(s) do {           \
10696 +       (s)->sk_nid = 0;                \
10697 +       (s)->sk_nx_info = NULL;         \
10698 +       } while (0)
10699 +
10700 +#else
10701 +#warning duplicate inclusion
10702 +#endif
10703 diff -NurpP --minimal linux-3.2.8/include/linux/vs_tag.h linux-3.2.8-vs2.3.2.7/include/linux/vs_tag.h
10704 --- linux-3.2.8/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10705 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_tag.h        2011-12-05 19:33:02.000000000 +0100
10706 @@ -0,0 +1,47 @@
10707 +#ifndef _VS_TAG_H
10708 +#define _VS_TAG_H
10709 +
10710 +#include <linux/vserver/tag.h>
10711 +
10712 +/* check conditions */
10713 +
10714 +#define DX_ADMIN       0x0001
10715 +#define DX_WATCH       0x0002
10716 +#define DX_HOSTID      0x0008
10717 +
10718 +#define DX_IDENT       0x0010
10719 +
10720 +#define DX_ARG_MASK    0x0010
10721 +
10722 +
10723 +#define dx_task_tag(t) ((t)->tag)
10724 +
10725 +#define dx_current_tag() dx_task_tag(current)
10726 +
10727 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10728 +
10729 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10730 +
10731 +
10732 +/*
10733 + * check current context for ADMIN/WATCH and
10734 + * optionally against supplied argument
10735 + */
10736 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10737 +{
10738 +       if (mode & DX_ARG_MASK) {
10739 +               if ((mode & DX_IDENT) && (id == cid))
10740 +                       return 1;
10741 +       }
10742 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10743 +               ((mode & DX_WATCH) && (cid == 1)) ||
10744 +               ((mode & DX_HOSTID) && (id == 0)));
10745 +}
10746 +
10747 +struct inode;
10748 +int dx_permission(const struct inode *inode, int mask);
10749 +
10750 +
10751 +#else
10752 +#warning duplicate inclusion
10753 +#endif
10754 diff -NurpP --minimal linux-3.2.8/include/linux/vs_time.h linux-3.2.8-vs2.3.2.7/include/linux/vs_time.h
10755 --- linux-3.2.8/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10756 +++ linux-3.2.8-vs2.3.2.7/include/linux/vs_time.h       2011-12-05 19:33:02.000000000 +0100
10757 @@ -0,0 +1,19 @@
10758 +#ifndef _VS_TIME_H
10759 +#define _VS_TIME_H
10760 +
10761 +
10762 +/* time faking stuff */
10763 +
10764 +#ifdef CONFIG_VSERVER_VTIME
10765 +
10766 +extern void vx_adjust_timespec(struct timespec *ts);
10767 +extern int vx_settimeofday(const struct timespec *ts);
10768 +
10769 +#else
10770 +#define        vx_adjust_timespec(t)   do { } while (0)
10771 +#define        vx_settimeofday(t)      do_settimeofday(t)
10772 +#endif
10773 +
10774 +#else
10775 +#warning duplicate inclusion
10776 +#endif
10777 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/Kbuild linux-3.2.8-vs2.3.2.7/include/linux/vserver/Kbuild
10778 --- linux-3.2.8/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10779 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/Kbuild  2011-12-05 19:33:02.000000000 +0100
10780 @@ -0,0 +1,8 @@
10781 +
10782 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10783 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10784 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10785 +       debug_cmd.h device_cmd.h
10786 +
10787 +header-y += switch.h network.h monitor.h inode.h device.h
10788 +
10789 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/base.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/base.h
10790 --- linux-3.2.8/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
10791 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/base.h  2011-12-05 19:33:02.000000000 +0100
10792 @@ -0,0 +1,178 @@
10793 +#ifndef _VX_BASE_H
10794 +#define _VX_BASE_H
10795 +
10796 +
10797 +/* context state changes */
10798 +
10799 +enum {
10800 +       VSC_STARTUP = 1,
10801 +       VSC_SHUTDOWN,
10802 +
10803 +       VSC_NETUP,
10804 +       VSC_NETDOWN,
10805 +};
10806 +
10807 +
10808 +
10809 +#define vx_task_xid(t) ((t)->xid)
10810 +
10811 +#define vx_current_xid() vx_task_xid(current)
10812 +
10813 +#define current_vx_info() (current->vx_info)
10814 +
10815 +
10816 +#define nx_task_nid(t) ((t)->nid)
10817 +
10818 +#define nx_current_nid() nx_task_nid(current)
10819 +
10820 +#define current_nx_info() (current->nx_info)
10821 +
10822 +
10823 +/* generic flag merging */
10824 +
10825 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10826 +
10827 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10828 +
10829 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10830 +
10831 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10832 +
10833 +
10834 +/* context flags */
10835 +
10836 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10837 +
10838 +#define vx_current_flags()     __vx_flags(current_vx_info())
10839 +
10840 +#define vx_info_flags(v, m, f) \
10841 +       vs_check_flags(__vx_flags(v), m, f)
10842 +
10843 +#define task_vx_flags(t, m, f) \
10844 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10845 +
10846 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10847 +
10848 +
10849 +/* context caps */
10850 +
10851 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10852 +
10853 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10854 +
10855 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10856 +
10857 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10858 +
10859 +
10860 +
10861 +/* network flags */
10862 +
10863 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10864 +
10865 +#define nx_current_flags()     __nx_flags(current_nx_info())
10866 +
10867 +#define nx_info_flags(n, m, f) \
10868 +       vs_check_flags(__nx_flags(n), m, f)
10869 +
10870 +#define task_nx_flags(t, m, f) \
10871 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10872 +
10873 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10874 +
10875 +
10876 +/* network caps */
10877 +
10878 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10879 +
10880 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10881 +
10882 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10883 +
10884 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10885 +
10886 +
10887 +/* context mask capabilities */
10888 +
10889 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10890 +
10891 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10892 +
10893 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10894 +
10895 +
10896 +/* context bcap mask */
10897 +
10898 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10899 +
10900 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10901 +
10902 +
10903 +/* mask given bcaps */
10904 +
10905 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10906 +
10907 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10908 +
10909 +
10910 +/* masked cap_bset */
10911 +
10912 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10913 +
10914 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10915 +
10916 +#if 0
10917 +#define vx_info_mbcap(v, b) \
10918 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10919 +       vx_info_bcaps(v, b) : (b))
10920 +
10921 +#define task_vx_mbcap(t, b) \
10922 +       vx_info_mbcap((t)->vx_info, (t)->b)
10923 +
10924 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10925 +#endif
10926 +
10927 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10928 +
10929 +#define vx_capable(b, c) (capable(b) || \
10930 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10931 +
10932 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10933 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10934 +
10935 +#define nx_capable(b, c) (capable(b) || \
10936 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10937 +
10938 +#define vx_task_initpid(t, n) \
10939 +       ((t)->vx_info && \
10940 +       ((t)->vx_info->vx_initpid == (n)))
10941 +
10942 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10943 +
10944 +
10945 +/* context unshare mask */
10946 +
10947 +#define __vx_umask(v)          ((v)->vx_umask)
10948 +
10949 +#define vx_current_umask()     __vx_umask(current_vx_info())
10950 +
10951 +#define vx_can_unshare(b, f) (capable(b) || \
10952 +       (cap_raised(current_cap(), b) && \
10953 +       !((f) & ~vx_current_umask())))
10954 +
10955 +
10956 +#define __vx_wmask(v)          ((v)->vx_wmask)
10957 +
10958 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10959 +
10960 +
10961 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10962 +
10963 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10964 +
10965 +
10966 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10967 +
10968 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10969 +
10970 +#endif
10971 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cacct.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct.h
10972 --- linux-3.2.8/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
10973 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct.h 2011-12-05 19:33:02.000000000 +0100
10974 @@ -0,0 +1,15 @@
10975 +#ifndef _VX_CACCT_H
10976 +#define _VX_CACCT_H
10977 +
10978 +
10979 +enum sock_acc_field {
10980 +       VXA_SOCK_UNSPEC = 0,
10981 +       VXA_SOCK_UNIX,
10982 +       VXA_SOCK_INET,
10983 +       VXA_SOCK_INET6,
10984 +       VXA_SOCK_PACKET,
10985 +       VXA_SOCK_OTHER,
10986 +       VXA_SOCK_SIZE   /* array size */
10987 +};
10988 +
10989 +#endif /* _VX_CACCT_H */
10990 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cacct_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct_cmd.h
10991 --- linux-3.2.8/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
10992 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct_cmd.h     2011-12-05 19:33:02.000000000 +0100
10993 @@ -0,0 +1,23 @@
10994 +#ifndef _VX_CACCT_CMD_H
10995 +#define _VX_CACCT_CMD_H
10996 +
10997 +
10998 +/* virtual host info name commands */
10999 +
11000 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11001 +
11002 +struct vcmd_sock_stat_v0 {
11003 +       uint32_t field;
11004 +       uint32_t count[3];
11005 +       uint64_t total[3];
11006 +};
11007 +
11008 +
11009 +#ifdef __KERNEL__
11010 +
11011 +#include <linux/compiler.h>
11012 +
11013 +extern int vc_sock_stat(struct vx_info *, void __user *);
11014 +
11015 +#endif /* __KERNEL__ */
11016 +#endif /* _VX_CACCT_CMD_H */
11017 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cacct_def.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct_def.h
11018 --- linux-3.2.8/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
11019 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct_def.h     2011-12-05 19:33:02.000000000 +0100
11020 @@ -0,0 +1,43 @@
11021 +#ifndef _VX_CACCT_DEF_H
11022 +#define _VX_CACCT_DEF_H
11023 +
11024 +#include <asm/atomic.h>
11025 +#include <linux/vserver/cacct.h>
11026 +
11027 +
11028 +struct _vx_sock_acc {
11029 +       atomic_long_t count;
11030 +       atomic_long_t total;
11031 +};
11032 +
11033 +/* context sub struct */
11034 +
11035 +struct _vx_cacct {
11036 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11037 +       atomic_t slab[8];
11038 +       atomic_t page[6][8];
11039 +};
11040 +
11041 +#ifdef CONFIG_VSERVER_DEBUG
11042 +
11043 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11044 +{
11045 +       int i, j;
11046 +
11047 +       printk("\t_vx_cacct:");
11048 +       for (i = 0; i < 6; i++) {
11049 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11050 +
11051 +               printk("\t [%d] =", i);
11052 +               for (j = 0; j < 3; j++) {
11053 +                       printk(" [%d] = %8lu, %8lu", j,
11054 +                               atomic_long_read(&ptr[j].count),
11055 +                               atomic_long_read(&ptr[j].total));
11056 +               }
11057 +               printk("\n");
11058 +       }
11059 +}
11060 +
11061 +#endif
11062 +
11063 +#endif /* _VX_CACCT_DEF_H */
11064 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cacct_int.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct_int.h
11065 --- linux-3.2.8/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
11066 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cacct_int.h     2011-12-05 19:33:02.000000000 +0100
11067 @@ -0,0 +1,21 @@
11068 +#ifndef _VX_CACCT_INT_H
11069 +#define _VX_CACCT_INT_H
11070 +
11071 +
11072 +#ifdef __KERNEL__
11073 +
11074 +static inline
11075 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11076 +{
11077 +       return atomic_long_read(&cacct->sock[type][pos].count);
11078 +}
11079 +
11080 +
11081 +static inline
11082 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11083 +{
11084 +       return atomic_long_read(&cacct->sock[type][pos].total);
11085 +}
11086 +
11087 +#endif /* __KERNEL__ */
11088 +#endif /* _VX_CACCT_INT_H */
11089 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/check.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/check.h
11090 --- linux-3.2.8/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
11091 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/check.h 2011-12-05 19:33:02.000000000 +0100
11092 @@ -0,0 +1,89 @@
11093 +#ifndef _VS_CHECK_H
11094 +#define _VS_CHECK_H
11095 +
11096 +
11097 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11098 +
11099 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11100 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11101 +#else
11102 +#define MIN_D_CONTEXT  65536
11103 +#endif
11104 +
11105 +/* check conditions */
11106 +
11107 +#define VS_ADMIN       0x0001
11108 +#define VS_WATCH       0x0002
11109 +#define VS_HIDE                0x0004
11110 +#define VS_HOSTID      0x0008
11111 +
11112 +#define VS_IDENT       0x0010
11113 +#define VS_EQUIV       0x0020
11114 +#define VS_PARENT      0x0040
11115 +#define VS_CHILD       0x0080
11116 +
11117 +#define VS_ARG_MASK    0x00F0
11118 +
11119 +#define VS_DYNAMIC     0x0100
11120 +#define VS_STATIC      0x0200
11121 +
11122 +#define VS_ATR_MASK    0x0F00
11123 +
11124 +#ifdef CONFIG_VSERVER_PRIVACY
11125 +#define VS_ADMIN_P     (0)
11126 +#define VS_WATCH_P     (0)
11127 +#else
11128 +#define VS_ADMIN_P     VS_ADMIN
11129 +#define VS_WATCH_P     VS_WATCH
11130 +#endif
11131 +
11132 +#define VS_HARDIRQ     0x1000
11133 +#define VS_SOFTIRQ     0x2000
11134 +#define VS_IRQ         0x4000
11135 +
11136 +#define VS_IRQ_MASK    0xF000
11137 +
11138 +#include <linux/hardirq.h>
11139 +
11140 +/*
11141 + * check current context for ADMIN/WATCH and
11142 + * optionally against supplied argument
11143 + */
11144 +static inline int __vs_check(int cid, int id, unsigned int mode)
11145 +{
11146 +       if (mode & VS_ARG_MASK) {
11147 +               if ((mode & VS_IDENT) && (id == cid))
11148 +                       return 1;
11149 +       }
11150 +       if (mode & VS_ATR_MASK) {
11151 +               if ((mode & VS_DYNAMIC) &&
11152 +                       (id >= MIN_D_CONTEXT) &&
11153 +                       (id <= MAX_S_CONTEXT))
11154 +                       return 1;
11155 +               if ((mode & VS_STATIC) &&
11156 +                       (id > 1) && (id < MIN_D_CONTEXT))
11157 +                       return 1;
11158 +       }
11159 +       if (mode & VS_IRQ_MASK) {
11160 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11161 +                       return 1;
11162 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11163 +                       return 1;
11164 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11165 +                       return 1;
11166 +       }
11167 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11168 +               ((mode & VS_WATCH) && (cid == 1)) ||
11169 +               ((mode & VS_HOSTID) && (id == 0)));
11170 +}
11171 +
11172 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11173 +
11174 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11175 +
11176 +
11177 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11178 +
11179 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11180 +
11181 +#endif
11182 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/context.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/context.h
11183 --- linux-3.2.8/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11184 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/context.h       2011-12-05 19:33:02.000000000 +0100
11185 @@ -0,0 +1,188 @@
11186 +#ifndef _VX_CONTEXT_H
11187 +#define _VX_CONTEXT_H
11188 +
11189 +#include <linux/types.h>
11190 +#include <linux/capability.h>
11191 +
11192 +
11193 +/* context flags */
11194 +
11195 +#define VXF_INFO_SCHED         0x00000002
11196 +#define VXF_INFO_NPROC         0x00000004
11197 +#define VXF_INFO_PRIVATE       0x00000008
11198 +
11199 +#define VXF_INFO_INIT          0x00000010
11200 +#define VXF_INFO_HIDE          0x00000020
11201 +#define VXF_INFO_ULIMIT                0x00000040
11202 +#define VXF_INFO_NSPACE                0x00000080
11203 +
11204 +#define VXF_SCHED_HARD         0x00000100
11205 +#define VXF_SCHED_PRIO         0x00000200
11206 +#define VXF_SCHED_PAUSE                0x00000400
11207 +
11208 +#define VXF_VIRT_MEM           0x00010000
11209 +#define VXF_VIRT_UPTIME                0x00020000
11210 +#define VXF_VIRT_CPU           0x00040000
11211 +#define VXF_VIRT_LOAD          0x00080000
11212 +#define VXF_VIRT_TIME          0x00100000
11213 +
11214 +#define VXF_HIDE_MOUNT         0x01000000
11215 +/* was VXF_HIDE_NETIF          0x02000000 */
11216 +#define VXF_HIDE_VINFO         0x04000000
11217 +
11218 +#define VXF_STATE_SETUP                (1ULL << 32)
11219 +#define VXF_STATE_INIT         (1ULL << 33)
11220 +#define VXF_STATE_ADMIN                (1ULL << 34)
11221 +
11222 +#define VXF_SC_HELPER          (1ULL << 36)
11223 +#define VXF_REBOOT_KILL                (1ULL << 37)
11224 +#define VXF_PERSISTENT         (1ULL << 38)
11225 +
11226 +#define VXF_FORK_RSS           (1ULL << 48)
11227 +#define VXF_PROLIFIC           (1ULL << 49)
11228 +
11229 +#define VXF_IGNEG_NICE         (1ULL << 52)
11230 +
11231 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11232 +
11233 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11234 +
11235 +
11236 +/* context migration */
11237 +
11238 +#define VXM_SET_INIT           0x00000001
11239 +#define VXM_SET_REAPER         0x00000002
11240 +
11241 +/* context caps */
11242 +
11243 +#define VXC_SET_UTSNAME                0x00000001
11244 +#define VXC_SET_RLIMIT         0x00000002
11245 +#define VXC_FS_SECURITY                0x00000004
11246 +#define VXC_FS_TRUSTED         0x00000008
11247 +#define VXC_TIOCSTI            0x00000010
11248 +
11249 +/* was VXC_RAW_ICMP            0x00000100 */
11250 +#define VXC_SYSLOG             0x00001000
11251 +#define VXC_OOM_ADJUST         0x00002000
11252 +#define VXC_AUDIT_CONTROL      0x00004000
11253 +
11254 +#define VXC_SECURE_MOUNT       0x00010000
11255 +#define VXC_SECURE_REMOUNT     0x00020000
11256 +#define VXC_BINARY_MOUNT       0x00040000
11257 +
11258 +#define VXC_QUOTA_CTL          0x00100000
11259 +#define VXC_ADMIN_MAPPER       0x00200000
11260 +#define VXC_ADMIN_CLOOP                0x00400000
11261 +
11262 +#define VXC_KTHREAD            0x01000000
11263 +#define VXC_NAMESPACE          0x02000000
11264 +
11265 +
11266 +#ifdef __KERNEL__
11267 +
11268 +#include <linux/list.h>
11269 +#include <linux/spinlock.h>
11270 +#include <linux/rcupdate.h>
11271 +
11272 +#include "limit_def.h"
11273 +#include "sched_def.h"
11274 +#include "cvirt_def.h"
11275 +#include "cacct_def.h"
11276 +#include "device_def.h"
11277 +
11278 +#define VX_SPACES      2
11279 +
11280 +struct _vx_info_pc {
11281 +       struct _vx_sched_pc sched_pc;
11282 +       struct _vx_cvirt_pc cvirt_pc;
11283 +};
11284 +
11285 +struct _vx_space {
11286 +       unsigned long vx_nsmask;                /* assignment mask */
11287 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11288 +       struct fs_struct *vx_fs;                /* private namespace fs */
11289 +       const struct cred *vx_cred;             /* task credentials */
11290 +};
11291 +
11292 +struct vx_info {
11293 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11294 +       xid_t vx_id;                            /* context id */
11295 +       atomic_t vx_usecnt;                     /* usage count */
11296 +       atomic_t vx_tasks;                      /* tasks count */
11297 +       struct vx_info *vx_parent;              /* parent context */
11298 +       int vx_state;                           /* context state */
11299 +
11300 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11301 +
11302 +       uint64_t vx_flags;                      /* context flags */
11303 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11304 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11305 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11306 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11307 +
11308 +       struct task_struct *vx_reaper;          /* guest reaper process */
11309 +       pid_t vx_initpid;                       /* PID of guest init */
11310 +       int64_t vx_badness_bias;                /* OOM points bias */
11311 +
11312 +       struct _vx_limit limit;                 /* vserver limits */
11313 +       struct _vx_sched sched;                 /* vserver scheduler */
11314 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11315 +       struct _vx_cacct cacct;                 /* context accounting */
11316 +
11317 +       struct _vx_device dmap;                 /* default device map targets */
11318 +
11319 +#ifndef CONFIG_SMP
11320 +       struct _vx_info_pc info_pc;             /* per cpu data */
11321 +#else
11322 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11323 +#endif
11324 +
11325 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11326 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11327 +       int exit_code;                          /* last process exit code */
11328 +
11329 +       char vx_name[65];                       /* vserver name */
11330 +};
11331 +
11332 +#ifndef CONFIG_SMP
11333 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11334 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11335 +#else
11336 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11337 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11338 +#endif
11339 +
11340 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11341 +
11342 +
11343 +struct vx_info_save {
11344 +       struct vx_info *vxi;
11345 +       xid_t xid;
11346 +};
11347 +
11348 +
11349 +/* status flags */
11350 +
11351 +#define VXS_HASHED     0x0001
11352 +#define VXS_PAUSED     0x0010
11353 +#define VXS_SHUTDOWN   0x0100
11354 +#define VXS_HELPER     0x1000
11355 +#define VXS_RELEASED   0x8000
11356 +
11357 +
11358 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11359 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11360 +
11361 +extern struct vx_info *lookup_vx_info(int);
11362 +extern struct vx_info *lookup_or_create_vx_info(int);
11363 +
11364 +extern int get_xid_list(int, unsigned int *, int);
11365 +extern int xid_is_hashed(xid_t);
11366 +
11367 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11368 +
11369 +extern long vs_state_change(struct vx_info *, unsigned int);
11370 +
11371 +
11372 +#endif /* __KERNEL__ */
11373 +#endif /* _VX_CONTEXT_H */
11374 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/context_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/context_cmd.h
11375 --- linux-3.2.8/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11376 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/context_cmd.h   2011-12-05 19:33:02.000000000 +0100
11377 @@ -0,0 +1,162 @@
11378 +#ifndef _VX_CONTEXT_CMD_H
11379 +#define _VX_CONTEXT_CMD_H
11380 +
11381 +
11382 +/* vinfo commands */
11383 +
11384 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11385 +
11386 +#ifdef __KERNEL__
11387 +extern int vc_task_xid(uint32_t);
11388 +
11389 +#endif /* __KERNEL__ */
11390 +
11391 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11392 +
11393 +struct vcmd_vx_info_v0 {
11394 +       uint32_t xid;
11395 +       uint32_t initpid;
11396 +       /* more to come */
11397 +};
11398 +
11399 +#ifdef __KERNEL__
11400 +extern int vc_vx_info(struct vx_info *, void __user *);
11401 +
11402 +#endif /* __KERNEL__ */
11403 +
11404 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11405 +
11406 +struct vcmd_ctx_stat_v0 {
11407 +       uint32_t usecnt;
11408 +       uint32_t tasks;
11409 +       /* more to come */
11410 +};
11411 +
11412 +#ifdef __KERNEL__
11413 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11414 +
11415 +#endif /* __KERNEL__ */
11416 +
11417 +/* context commands */
11418 +
11419 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11420 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11421 +
11422 +struct vcmd_ctx_create {
11423 +       uint64_t flagword;
11424 +};
11425 +
11426 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11427 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11428 +
11429 +struct vcmd_ctx_migrate {
11430 +       uint64_t flagword;
11431 +};
11432 +
11433 +#ifdef __KERNEL__
11434 +extern int vc_ctx_create(uint32_t, void __user *);
11435 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11436 +
11437 +#endif /* __KERNEL__ */
11438 +
11439 +
11440 +/* flag commands */
11441 +
11442 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11443 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11444 +
11445 +struct vcmd_ctx_flags_v0 {
11446 +       uint64_t flagword;
11447 +       uint64_t mask;
11448 +};
11449 +
11450 +#ifdef __KERNEL__
11451 +extern int vc_get_cflags(struct vx_info *, void __user *);
11452 +extern int vc_set_cflags(struct vx_info *, void __user *);
11453 +
11454 +#endif /* __KERNEL__ */
11455 +
11456 +
11457 +/* context caps commands */
11458 +
11459 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11460 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11461 +
11462 +struct vcmd_ctx_caps_v1 {
11463 +       uint64_t ccaps;
11464 +       uint64_t cmask;
11465 +};
11466 +
11467 +#ifdef __KERNEL__
11468 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11469 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11470 +
11471 +#endif /* __KERNEL__ */
11472 +
11473 +
11474 +/* bcaps commands */
11475 +
11476 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11477 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11478 +
11479 +struct vcmd_bcaps {
11480 +       uint64_t bcaps;
11481 +       uint64_t bmask;
11482 +};
11483 +
11484 +#ifdef __KERNEL__
11485 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11486 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11487 +
11488 +#endif /* __KERNEL__ */
11489 +
11490 +
11491 +/* umask commands */
11492 +
11493 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11494 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11495 +
11496 +struct vcmd_umask {
11497 +       uint64_t umask;
11498 +       uint64_t mask;
11499 +};
11500 +
11501 +#ifdef __KERNEL__
11502 +extern int vc_get_umask(struct vx_info *, void __user *);
11503 +extern int vc_set_umask(struct vx_info *, void __user *);
11504 +
11505 +#endif /* __KERNEL__ */
11506 +
11507 +
11508 +/* wmask commands */
11509 +
11510 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11511 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11512 +
11513 +struct vcmd_wmask {
11514 +       uint64_t wmask;
11515 +       uint64_t mask;
11516 +};
11517 +
11518 +#ifdef __KERNEL__
11519 +extern int vc_get_wmask(struct vx_info *, void __user *);
11520 +extern int vc_set_wmask(struct vx_info *, void __user *);
11521 +
11522 +#endif /* __KERNEL__ */
11523 +
11524 +
11525 +/* OOM badness */
11526 +
11527 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11528 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11529 +
11530 +struct vcmd_badness_v0 {
11531 +       int64_t bias;
11532 +};
11533 +
11534 +#ifdef __KERNEL__
11535 +extern int vc_get_badness(struct vx_info *, void __user *);
11536 +extern int vc_set_badness(struct vx_info *, void __user *);
11537 +
11538 +#endif /* __KERNEL__ */
11539 +#endif /* _VX_CONTEXT_CMD_H */
11540 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cvirt.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cvirt.h
11541 --- linux-3.2.8/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11542 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cvirt.h 2011-12-05 19:33:02.000000000 +0100
11543 @@ -0,0 +1,20 @@
11544 +#ifndef _VX_CVIRT_H
11545 +#define _VX_CVIRT_H
11546 +
11547 +
11548 +#ifdef __KERNEL__
11549 +
11550 +struct timespec;
11551 +
11552 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11553 +
11554 +
11555 +struct vx_info;
11556 +
11557 +void vx_update_load(struct vx_info *);
11558 +
11559 +
11560 +int vx_do_syslog(int, char __user *, int);
11561 +
11562 +#endif /* __KERNEL__ */
11563 +#endif /* _VX_CVIRT_H */
11564 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cvirt_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cvirt_cmd.h
11565 --- linux-3.2.8/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11566 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cvirt_cmd.h     2011-12-05 19:33:02.000000000 +0100
11567 @@ -0,0 +1,53 @@
11568 +#ifndef _VX_CVIRT_CMD_H
11569 +#define _VX_CVIRT_CMD_H
11570 +
11571 +
11572 +/* virtual host info name commands */
11573 +
11574 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11575 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11576 +
11577 +struct vcmd_vhi_name_v0 {
11578 +       uint32_t field;
11579 +       char name[65];
11580 +};
11581 +
11582 +
11583 +enum vhi_name_field {
11584 +       VHIN_CONTEXT = 0,
11585 +       VHIN_SYSNAME,
11586 +       VHIN_NODENAME,
11587 +       VHIN_RELEASE,
11588 +       VHIN_VERSION,
11589 +       VHIN_MACHINE,
11590 +       VHIN_DOMAINNAME,
11591 +};
11592 +
11593 +
11594 +#ifdef __KERNEL__
11595 +
11596 +#include <linux/compiler.h>
11597 +
11598 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11599 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11600 +
11601 +#endif /* __KERNEL__ */
11602 +
11603 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11604 +
11605 +struct vcmd_virt_stat_v0 {
11606 +       uint64_t offset;
11607 +       uint64_t uptime;
11608 +       uint32_t nr_threads;
11609 +       uint32_t nr_running;
11610 +       uint32_t nr_uninterruptible;
11611 +       uint32_t nr_onhold;
11612 +       uint32_t nr_forks;
11613 +       uint32_t load[3];
11614 +};
11615 +
11616 +#ifdef __KERNEL__
11617 +extern int vc_virt_stat(struct vx_info *, void __user *);
11618 +
11619 +#endif /* __KERNEL__ */
11620 +#endif /* _VX_CVIRT_CMD_H */
11621 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/cvirt_def.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/cvirt_def.h
11622 --- linux-3.2.8/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11623 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/cvirt_def.h     2011-12-05 19:33:02.000000000 +0100
11624 @@ -0,0 +1,80 @@
11625 +#ifndef _VX_CVIRT_DEF_H
11626 +#define _VX_CVIRT_DEF_H
11627 +
11628 +#include <linux/jiffies.h>
11629 +#include <linux/spinlock.h>
11630 +#include <linux/wait.h>
11631 +#include <linux/time.h>
11632 +#include <asm/atomic.h>
11633 +
11634 +
11635 +struct _vx_usage_stat {
11636 +       uint64_t user;
11637 +       uint64_t nice;
11638 +       uint64_t system;
11639 +       uint64_t softirq;
11640 +       uint64_t irq;
11641 +       uint64_t idle;
11642 +       uint64_t iowait;
11643 +};
11644 +
11645 +struct _vx_syslog {
11646 +       wait_queue_head_t log_wait;
11647 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11648 +
11649 +       unsigned long log_start;        /* next char to be read by syslog() */
11650 +       unsigned long con_start;        /* next char to be sent to consoles */
11651 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11652 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11653 +
11654 +       char log_buf[1024];
11655 +};
11656 +
11657 +
11658 +/* context sub struct */
11659 +
11660 +struct _vx_cvirt {
11661 +       atomic_t nr_threads;            /* number of current threads */
11662 +       atomic_t nr_running;            /* number of running threads */
11663 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11664 +
11665 +       atomic_t nr_onhold;             /* processes on hold */
11666 +       uint32_t onhold_last;           /* jiffies when put on hold */
11667 +
11668 +       struct timespec bias_ts;        /* time offset to the host */
11669 +       struct timespec bias_idle;
11670 +       struct timespec bias_uptime;    /* context creation point */
11671 +       uint64_t bias_clock;            /* offset in clock_t */
11672 +
11673 +       spinlock_t load_lock;           /* lock for the load averages */
11674 +       atomic_t load_updates;          /* nr of load updates done so far */
11675 +       uint32_t load_last;             /* last time load was calculated */
11676 +       uint32_t load[3];               /* load averages 1,5,15 */
11677 +
11678 +       atomic_t total_forks;           /* number of forks so far */
11679 +
11680 +       struct _vx_syslog syslog;
11681 +};
11682 +
11683 +struct _vx_cvirt_pc {
11684 +       struct _vx_usage_stat cpustat;
11685 +};
11686 +
11687 +
11688 +#ifdef CONFIG_VSERVER_DEBUG
11689 +
11690 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11691 +{
11692 +       printk("\t_vx_cvirt:\n");
11693 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11694 +               atomic_read(&cvirt->nr_threads),
11695 +               atomic_read(&cvirt->nr_running),
11696 +               atomic_read(&cvirt->nr_uninterruptible),
11697 +               atomic_read(&cvirt->nr_onhold));
11698 +       /* add rest here */
11699 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11700 +}
11701 +
11702 +#endif
11703 +
11704 +#endif /* _VX_CVIRT_DEF_H */
11705 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/debug.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/debug.h
11706 --- linux-3.2.8/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11707 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/debug.h 2011-12-05 19:33:02.000000000 +0100
11708 @@ -0,0 +1,145 @@
11709 +#ifndef _VX_DEBUG_H
11710 +#define _VX_DEBUG_H
11711 +
11712 +
11713 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11714 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11715 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11716 +
11717 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11718 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11719 +#define VXF_DEV                "%p[%lu,%d:%d]"
11720 +
11721 +#if    defined(CONFIG_QUOTES_UTF8)
11722 +#define        VS_Q_LQM        "\xc2\xbb"
11723 +#define        VS_Q_RQM        "\xc2\xab"
11724 +#elif  defined(CONFIG_QUOTES_ASCII)
11725 +#define        VS_Q_LQM        "\x27"
11726 +#define        VS_Q_RQM        "\x27"
11727 +#else
11728 +#define        VS_Q_LQM        "\xbb"
11729 +#define        VS_Q_RQM        "\xab"
11730 +#endif
11731 +
11732 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11733 +
11734 +
11735 +#define vxd_path(p)                                            \
11736 +       ({ static char _buffer[PATH_MAX];                       \
11737 +          d_path(p, _buffer, sizeof(_buffer)); })
11738 +
11739 +#define vxd_cond_path(n)                                       \
11740 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11741 +
11742 +
11743 +#ifdef CONFIG_VSERVER_DEBUG
11744 +
11745 +extern unsigned int vs_debug_switch;
11746 +extern unsigned int vs_debug_xid;
11747 +extern unsigned int vs_debug_nid;
11748 +extern unsigned int vs_debug_tag;
11749 +extern unsigned int vs_debug_net;
11750 +extern unsigned int vs_debug_limit;
11751 +extern unsigned int vs_debug_cres;
11752 +extern unsigned int vs_debug_dlim;
11753 +extern unsigned int vs_debug_quota;
11754 +extern unsigned int vs_debug_cvirt;
11755 +extern unsigned int vs_debug_space;
11756 +extern unsigned int vs_debug_perm;
11757 +extern unsigned int vs_debug_misc;
11758 +
11759 +
11760 +#define VX_LOGLEVEL    "vxD: "
11761 +#define VX_PROC_FMT    "%p: "
11762 +#define VX_PROCESS     current
11763 +
11764 +#define vxdprintk(c, f, x...)                                  \
11765 +       do {                                                    \
11766 +               if (c)                                          \
11767 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11768 +                               VX_PROCESS , ##x);              \
11769 +       } while (0)
11770 +
11771 +#define vxlprintk(c, f, x...)                                  \
11772 +       do {                                                    \
11773 +               if (c)                                          \
11774 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11775 +       } while (0)
11776 +
11777 +#define vxfprintk(c, f, x...)                                  \
11778 +       do {                                                    \
11779 +               if (c)                                          \
11780 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11781 +       } while (0)
11782 +
11783 +
11784 +struct vx_info;
11785 +
11786 +void dump_vx_info(struct vx_info *, int);
11787 +void dump_vx_info_inactive(int);
11788 +
11789 +#else  /* CONFIG_VSERVER_DEBUG */
11790 +
11791 +#define vs_debug_switch        0
11792 +#define vs_debug_xid   0
11793 +#define vs_debug_nid   0
11794 +#define vs_debug_tag   0
11795 +#define vs_debug_net   0
11796 +#define vs_debug_limit 0
11797 +#define vs_debug_cres  0
11798 +#define vs_debug_dlim  0
11799 +#define vs_debug_quota 0
11800 +#define vs_debug_cvirt 0
11801 +#define vs_debug_space 0
11802 +#define vs_debug_perm  0
11803 +#define vs_debug_misc  0
11804 +
11805 +#define vxdprintk(x...) do { } while (0)
11806 +#define vxlprintk(x...) do { } while (0)
11807 +#define vxfprintk(x...) do { } while (0)
11808 +
11809 +#endif /* CONFIG_VSERVER_DEBUG */
11810 +
11811 +
11812 +#ifdef CONFIG_VSERVER_WARN
11813 +
11814 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11815 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11816 +#define VX_WARN_XID    "[xid #%u] "
11817 +#define VX_WARN_NID    "[nid #%u] "
11818 +#define VX_WARN_TAG    "[tag #%u] "
11819 +
11820 +#define vxwprintk(c, f, x...)                                  \
11821 +       do {                                                    \
11822 +               if (c)                                          \
11823 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11824 +       } while (0)
11825 +
11826 +#else  /* CONFIG_VSERVER_WARN */
11827 +
11828 +#define vxwprintk(x...) do { } while (0)
11829 +
11830 +#endif /* CONFIG_VSERVER_WARN */
11831 +
11832 +#define vxwprintk_task(c, f, x...)                             \
11833 +       vxwprintk(c, VX_WARN_TASK f,                            \
11834 +               current->comm, current->pid,                    \
11835 +               current->xid, current->nid, current->tag, ##x)
11836 +#define vxwprintk_xid(c, f, x...)                              \
11837 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11838 +#define vxwprintk_nid(c, f, x...)                              \
11839 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11840 +#define vxwprintk_tag(c, f, x...)                              \
11841 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11842 +
11843 +#ifdef CONFIG_VSERVER_DEBUG
11844 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11845 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11846 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11847 +#else
11848 +#define vxd_assert_lock(l)     do { } while (0)
11849 +#define vxd_assert(c, f, x...) do { } while (0)
11850 +#endif
11851 +
11852 +
11853 +#endif /* _VX_DEBUG_H */
11854 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/debug_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/debug_cmd.h
11855 --- linux-3.2.8/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
11856 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/debug_cmd.h     2011-12-05 19:33:02.000000000 +0100
11857 @@ -0,0 +1,58 @@
11858 +#ifndef _VX_DEBUG_CMD_H
11859 +#define _VX_DEBUG_CMD_H
11860 +
11861 +
11862 +/* debug commands */
11863 +
11864 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11865 +
11866 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11867 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11868 +
11869 +struct  vcmd_read_history_v0 {
11870 +       uint32_t index;
11871 +       uint32_t count;
11872 +       char __user *data;
11873 +};
11874 +
11875 +struct  vcmd_read_monitor_v0 {
11876 +       uint32_t index;
11877 +       uint32_t count;
11878 +       char __user *data;
11879 +};
11880 +
11881 +
11882 +#ifdef __KERNEL__
11883 +
11884 +#ifdef CONFIG_COMPAT
11885 +
11886 +#include <asm/compat.h>
11887 +
11888 +struct vcmd_read_history_v0_x32 {
11889 +       uint32_t index;
11890 +       uint32_t count;
11891 +       compat_uptr_t data_ptr;
11892 +};
11893 +
11894 +struct vcmd_read_monitor_v0_x32 {
11895 +       uint32_t index;
11896 +       uint32_t count;
11897 +       compat_uptr_t data_ptr;
11898 +};
11899 +
11900 +#endif  /* CONFIG_COMPAT */
11901 +
11902 +extern int vc_dump_history(uint32_t);
11903 +
11904 +extern int vc_read_history(uint32_t, void __user *);
11905 +extern int vc_read_monitor(uint32_t, void __user *);
11906 +
11907 +#ifdef CONFIG_COMPAT
11908 +
11909 +extern int vc_read_history_x32(uint32_t, void __user *);
11910 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11911 +
11912 +#endif  /* CONFIG_COMPAT */
11913 +
11914 +#endif /* __KERNEL__ */
11915 +#endif /* _VX_DEBUG_CMD_H */
11916 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/device.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/device.h
11917 --- linux-3.2.8/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
11918 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/device.h        2011-12-05 19:33:02.000000000 +0100
11919 @@ -0,0 +1,15 @@
11920 +#ifndef _VX_DEVICE_H
11921 +#define _VX_DEVICE_H
11922 +
11923 +
11924 +#define DATTR_CREATE   0x00000001
11925 +#define DATTR_OPEN     0x00000002
11926 +
11927 +#define DATTR_REMAP    0x00000010
11928 +
11929 +#define DATTR_MASK     0x00000013
11930 +
11931 +
11932 +#else  /* _VX_DEVICE_H */
11933 +#warning duplicate inclusion
11934 +#endif /* _VX_DEVICE_H */
11935 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/device_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/device_cmd.h
11936 --- linux-3.2.8/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
11937 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/device_cmd.h    2011-12-05 19:33:02.000000000 +0100
11938 @@ -0,0 +1,44 @@
11939 +#ifndef _VX_DEVICE_CMD_H
11940 +#define _VX_DEVICE_CMD_H
11941 +
11942 +
11943 +/*  device vserver commands */
11944 +
11945 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11946 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11947 +
11948 +struct vcmd_set_mapping_v0 {
11949 +       const char __user *device;
11950 +       const char __user *target;
11951 +       uint32_t flags;
11952 +};
11953 +
11954 +
11955 +#ifdef __KERNEL__
11956 +
11957 +#ifdef CONFIG_COMPAT
11958 +
11959 +#include <asm/compat.h>
11960 +
11961 +struct vcmd_set_mapping_v0_x32 {
11962 +       compat_uptr_t device_ptr;
11963 +       compat_uptr_t target_ptr;
11964 +       uint32_t flags;
11965 +};
11966 +
11967 +#endif /* CONFIG_COMPAT */
11968 +
11969 +#include <linux/compiler.h>
11970 +
11971 +extern int vc_set_mapping(struct vx_info *, void __user *);
11972 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11973 +
11974 +#ifdef CONFIG_COMPAT
11975 +
11976 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11977 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11978 +
11979 +#endif /* CONFIG_COMPAT */
11980 +
11981 +#endif /* __KERNEL__ */
11982 +#endif /* _VX_DEVICE_CMD_H */
11983 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/device_def.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/device_def.h
11984 --- linux-3.2.8/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
11985 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/device_def.h    2011-12-05 19:33:02.000000000 +0100
11986 @@ -0,0 +1,17 @@
11987 +#ifndef _VX_DEVICE_DEF_H
11988 +#define _VX_DEVICE_DEF_H
11989 +
11990 +#include <linux/types.h>
11991 +
11992 +struct vx_dmap_target {
11993 +       dev_t target;
11994 +       uint32_t flags;
11995 +};
11996 +
11997 +struct _vx_device {
11998 +#ifdef CONFIG_VSERVER_DEVICE
11999 +       struct vx_dmap_target targets[2];
12000 +#endif
12001 +};
12002 +
12003 +#endif /* _VX_DEVICE_DEF_H */
12004 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/dlimit.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/dlimit.h
12005 --- linux-3.2.8/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
12006 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/dlimit.h        2011-12-05 19:33:02.000000000 +0100
12007 @@ -0,0 +1,54 @@
12008 +#ifndef _VX_DLIMIT_H
12009 +#define _VX_DLIMIT_H
12010 +
12011 +#include "switch.h"
12012 +
12013 +
12014 +#ifdef __KERNEL__
12015 +
12016 +/*      keep in sync with CDLIM_INFINITY       */
12017 +
12018 +#define DLIM_INFINITY          (~0ULL)
12019 +
12020 +#include <linux/spinlock.h>
12021 +#include <linux/rcupdate.h>
12022 +
12023 +struct super_block;
12024 +
12025 +struct dl_info {
12026 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12027 +       struct rcu_head dl_rcu;                 /* the rcu head */
12028 +       tag_t dl_tag;                           /* context tag */
12029 +       atomic_t dl_usecnt;                     /* usage count */
12030 +       atomic_t dl_refcnt;                     /* reference count */
12031 +
12032 +       struct super_block *dl_sb;              /* associated superblock */
12033 +
12034 +       spinlock_t dl_lock;                     /* protect the values */
12035 +
12036 +       unsigned long long dl_space_used;       /* used space in bytes */
12037 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12038 +       unsigned long dl_inodes_used;           /* used inodes */
12039 +       unsigned long dl_inodes_total;          /* maximum inodes */
12040 +
12041 +       unsigned int dl_nrlmult;                /* non root limit mult */
12042 +};
12043 +
12044 +struct rcu_head;
12045 +
12046 +extern void rcu_free_dl_info(struct rcu_head *);
12047 +extern void unhash_dl_info(struct dl_info *);
12048 +
12049 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12050 +
12051 +
12052 +struct kstatfs;
12053 +
12054 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12055 +
12056 +typedef uint64_t dlsize_t;
12057 +
12058 +#endif /* __KERNEL__ */
12059 +#else  /* _VX_DLIMIT_H */
12060 +#warning duplicate inclusion
12061 +#endif /* _VX_DLIMIT_H */
12062 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/dlimit_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/dlimit_cmd.h
12063 --- linux-3.2.8/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12064 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/dlimit_cmd.h    2011-12-05 19:33:02.000000000 +0100
12065 @@ -0,0 +1,109 @@
12066 +#ifndef _VX_DLIMIT_CMD_H
12067 +#define _VX_DLIMIT_CMD_H
12068 +
12069 +
12070 +/*  dlimit vserver commands */
12071 +
12072 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12073 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12074 +
12075 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12076 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12077 +
12078 +struct vcmd_ctx_dlimit_base_v0 {
12079 +       const char __user *name;
12080 +       uint32_t flags;
12081 +};
12082 +
12083 +struct vcmd_ctx_dlimit_v0 {
12084 +       const char __user *name;
12085 +       uint32_t space_used;                    /* used space in kbytes */
12086 +       uint32_t space_total;                   /* maximum space in kbytes */
12087 +       uint32_t inodes_used;                   /* used inodes */
12088 +       uint32_t inodes_total;                  /* maximum inodes */
12089 +       uint32_t reserved;                      /* reserved for root in % */
12090 +       uint32_t flags;
12091 +};
12092 +
12093 +#define CDLIM_UNSET            ((uint32_t)0UL)
12094 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12095 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12096 +
12097 +#define DLIME_UNIT     0
12098 +#define DLIME_KILO     1
12099 +#define DLIME_MEGA     2
12100 +#define DLIME_GIGA     3
12101 +
12102 +#define DLIMF_SHIFT    0x10
12103 +
12104 +#define DLIMS_USED     0
12105 +#define DLIMS_TOTAL    2
12106 +
12107 +static inline
12108 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12109 +{
12110 +       int exp = (flags & DLIMF_SHIFT) ?
12111 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12112 +       return ((uint64_t)val) << (10 * exp);
12113 +}
12114 +
12115 +static inline
12116 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12117 +{
12118 +       int exp = 0;
12119 +
12120 +       if (*flags & DLIMF_SHIFT) {
12121 +               while (val > (1LL << 32) && (exp < 3)) {
12122 +                       val >>= 10;
12123 +                       exp++;
12124 +               }
12125 +               *flags &= ~(DLIME_GIGA << shift);
12126 +               *flags |= exp << shift;
12127 +       } else
12128 +               val >>= 10;
12129 +       return val;
12130 +}
12131 +
12132 +#ifdef __KERNEL__
12133 +
12134 +#ifdef CONFIG_COMPAT
12135 +
12136 +#include <asm/compat.h>
12137 +
12138 +struct vcmd_ctx_dlimit_base_v0_x32 {
12139 +       compat_uptr_t name_ptr;
12140 +       uint32_t flags;
12141 +};
12142 +
12143 +struct vcmd_ctx_dlimit_v0_x32 {
12144 +       compat_uptr_t name_ptr;
12145 +       uint32_t space_used;                    /* used space in kbytes */
12146 +       uint32_t space_total;                   /* maximum space in kbytes */
12147 +       uint32_t inodes_used;                   /* used inodes */
12148 +       uint32_t inodes_total;                  /* maximum inodes */
12149 +       uint32_t reserved;                      /* reserved for root in % */
12150 +       uint32_t flags;
12151 +};
12152 +
12153 +#endif /* CONFIG_COMPAT */
12154 +
12155 +#include <linux/compiler.h>
12156 +
12157 +extern int vc_add_dlimit(uint32_t, void __user *);
12158 +extern int vc_rem_dlimit(uint32_t, void __user *);
12159 +
12160 +extern int vc_set_dlimit(uint32_t, void __user *);
12161 +extern int vc_get_dlimit(uint32_t, void __user *);
12162 +
12163 +#ifdef CONFIG_COMPAT
12164 +
12165 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12166 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12167 +
12168 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12169 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12170 +
12171 +#endif /* CONFIG_COMPAT */
12172 +
12173 +#endif /* __KERNEL__ */
12174 +#endif /* _VX_DLIMIT_CMD_H */
12175 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/global.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/global.h
12176 --- linux-3.2.8/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12177 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/global.h        2011-12-05 19:33:02.000000000 +0100
12178 @@ -0,0 +1,19 @@
12179 +#ifndef _VX_GLOBAL_H
12180 +#define _VX_GLOBAL_H
12181 +
12182 +
12183 +extern atomic_t vx_global_ctotal;
12184 +extern atomic_t vx_global_cactive;
12185 +
12186 +extern atomic_t nx_global_ctotal;
12187 +extern atomic_t nx_global_cactive;
12188 +
12189 +extern atomic_t vs_global_nsproxy;
12190 +extern atomic_t vs_global_fs;
12191 +extern atomic_t vs_global_mnt_ns;
12192 +extern atomic_t vs_global_uts_ns;
12193 +extern atomic_t vs_global_user_ns;
12194 +extern atomic_t vs_global_pid_ns;
12195 +
12196 +
12197 +#endif /* _VX_GLOBAL_H */
12198 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/history.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/history.h
12199 --- linux-3.2.8/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12200 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/history.h       2011-12-05 19:33:02.000000000 +0100
12201 @@ -0,0 +1,197 @@
12202 +#ifndef _VX_HISTORY_H
12203 +#define _VX_HISTORY_H
12204 +
12205 +
12206 +enum {
12207 +       VXH_UNUSED = 0,
12208 +       VXH_THROW_OOPS = 1,
12209 +
12210 +       VXH_GET_VX_INFO,
12211 +       VXH_PUT_VX_INFO,
12212 +       VXH_INIT_VX_INFO,
12213 +       VXH_SET_VX_INFO,
12214 +       VXH_CLR_VX_INFO,
12215 +       VXH_CLAIM_VX_INFO,
12216 +       VXH_RELEASE_VX_INFO,
12217 +       VXH_ALLOC_VX_INFO,
12218 +       VXH_DEALLOC_VX_INFO,
12219 +       VXH_HASH_VX_INFO,
12220 +       VXH_UNHASH_VX_INFO,
12221 +       VXH_LOC_VX_INFO,
12222 +       VXH_LOOKUP_VX_INFO,
12223 +       VXH_CREATE_VX_INFO,
12224 +};
12225 +
12226 +struct _vxhe_vxi {
12227 +       struct vx_info *ptr;
12228 +       unsigned xid;
12229 +       unsigned usecnt;
12230 +       unsigned tasks;
12231 +};
12232 +
12233 +struct _vxhe_set_clr {
12234 +       void *data;
12235 +};
12236 +
12237 +struct _vxhe_loc_lookup {
12238 +       unsigned arg;
12239 +};
12240 +
12241 +struct _vx_hist_entry {
12242 +       void *loc;
12243 +       unsigned short seq;
12244 +       unsigned short type;
12245 +       struct _vxhe_vxi vxi;
12246 +       union {
12247 +               struct _vxhe_set_clr sc;
12248 +               struct _vxhe_loc_lookup ll;
12249 +       };
12250 +};
12251 +
12252 +#ifdef CONFIG_VSERVER_HISTORY
12253 +
12254 +extern unsigned volatile int vxh_active;
12255 +
12256 +struct _vx_hist_entry *vxh_advance(void *loc);
12257 +
12258 +
12259 +static inline
12260 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12261 +{
12262 +       entry->vxi.ptr = vxi;
12263 +       if (vxi) {
12264 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12265 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12266 +               entry->vxi.xid = vxi->vx_id;
12267 +       }
12268 +}
12269 +
12270 +
12271 +#define        __HERE__ current_text_addr()
12272 +
12273 +#define __VXH_BODY(__type, __data, __here)     \
12274 +       struct _vx_hist_entry *entry;           \
12275 +                                               \
12276 +       preempt_disable();                      \
12277 +       entry = vxh_advance(__here);            \
12278 +       __data;                                 \
12279 +       entry->type = __type;                   \
12280 +       preempt_enable();
12281 +
12282 +
12283 +       /* pass vxi only */
12284 +
12285 +#define __VXH_SMPL                             \
12286 +       __vxh_copy_vxi(entry, vxi)
12287 +
12288 +static inline
12289 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12290 +{
12291 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12292 +}
12293 +
12294 +       /* pass vxi and data (void *) */
12295 +
12296 +#define __VXH_DATA                             \
12297 +       __vxh_copy_vxi(entry, vxi);             \
12298 +       entry->sc.data = data
12299 +
12300 +static inline
12301 +void   __vxh_data(struct vx_info *vxi, void *data,
12302 +                       int __type, void *__here)
12303 +{
12304 +       __VXH_BODY(__type, __VXH_DATA, __here)
12305 +}
12306 +
12307 +       /* pass vxi and arg (long) */
12308 +
12309 +#define __VXH_LONG                             \
12310 +       __vxh_copy_vxi(entry, vxi);             \
12311 +       entry->ll.arg = arg
12312 +
12313 +static inline
12314 +void   __vxh_long(struct vx_info *vxi, long arg,
12315 +                       int __type, void *__here)
12316 +{
12317 +       __VXH_BODY(__type, __VXH_LONG, __here)
12318 +}
12319 +
12320 +
12321 +static inline
12322 +void   __vxh_throw_oops(void *__here)
12323 +{
12324 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12325 +       /* prevent further acquisition */
12326 +       vxh_active = 0;
12327 +}
12328 +
12329 +
12330 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12331 +
12332 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12333 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12334 +
12335 +#define __vxh_init_vx_info(v, d, h) \
12336 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12337 +#define __vxh_set_vx_info(v, d, h) \
12338 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12339 +#define __vxh_clr_vx_info(v, d, h) \
12340 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12341 +
12342 +#define __vxh_claim_vx_info(v, d, h) \
12343 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12344 +#define __vxh_release_vx_info(v, d, h) \
12345 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12346 +
12347 +#define vxh_alloc_vx_info(v) \
12348 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12349 +#define vxh_dealloc_vx_info(v) \
12350 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12351 +
12352 +#define vxh_hash_vx_info(v) \
12353 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12354 +#define vxh_unhash_vx_info(v) \
12355 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12356 +
12357 +#define vxh_loc_vx_info(v, l) \
12358 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12359 +#define vxh_lookup_vx_info(v, l) \
12360 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12361 +#define vxh_create_vx_info(v, l) \
12362 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12363 +
12364 +extern void vxh_dump_history(void);
12365 +
12366 +
12367 +#else  /* CONFIG_VSERVER_HISTORY */
12368 +
12369 +#define        __HERE__        0
12370 +
12371 +#define vxh_throw_oops()               do { } while (0)
12372 +
12373 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12374 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12375 +
12376 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12377 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12378 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12379 +
12380 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12381 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12382 +
12383 +#define vxh_alloc_vx_info(v)           do { } while (0)
12384 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12385 +
12386 +#define vxh_hash_vx_info(v)            do { } while (0)
12387 +#define vxh_unhash_vx_info(v)          do { } while (0)
12388 +
12389 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12390 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12391 +#define vxh_create_vx_info(v, l)       do { } while (0)
12392 +
12393 +#define vxh_dump_history()             do { } while (0)
12394 +
12395 +
12396 +#endif /* CONFIG_VSERVER_HISTORY */
12397 +
12398 +#endif /* _VX_HISTORY_H */
12399 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/inode.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/inode.h
12400 --- linux-3.2.8/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12401 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/inode.h 2011-12-05 19:33:02.000000000 +0100
12402 @@ -0,0 +1,39 @@
12403 +#ifndef _VX_INODE_H
12404 +#define _VX_INODE_H
12405 +
12406 +
12407 +#define IATTR_TAG      0x01000000
12408 +
12409 +#define IATTR_ADMIN    0x00000001
12410 +#define IATTR_WATCH    0x00000002
12411 +#define IATTR_HIDE     0x00000004
12412 +#define IATTR_FLAGS    0x00000007
12413 +
12414 +#define IATTR_BARRIER  0x00010000
12415 +#define IATTR_IXUNLINK 0x00020000
12416 +#define IATTR_IMMUTABLE 0x00040000
12417 +#define IATTR_COW      0x00080000
12418 +
12419 +#ifdef __KERNEL__
12420 +
12421 +
12422 +#ifdef CONFIG_VSERVER_PROC_SECURE
12423 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12424 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12425 +#else
12426 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12427 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12428 +#endif
12429 +
12430 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12431 +
12432 +#endif /* __KERNEL__ */
12433 +
12434 +/* inode ioctls */
12435 +
12436 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12437 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12438 +
12439 +#else  /* _VX_INODE_H */
12440 +#warning duplicate inclusion
12441 +#endif /* _VX_INODE_H */
12442 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/inode_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/inode_cmd.h
12443 --- linux-3.2.8/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12444 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/inode_cmd.h     2011-12-05 19:33:02.000000000 +0100
12445 @@ -0,0 +1,59 @@
12446 +#ifndef _VX_INODE_CMD_H
12447 +#define _VX_INODE_CMD_H
12448 +
12449 +
12450 +/*  inode vserver commands */
12451 +
12452 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12453 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12454 +
12455 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12456 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12457 +
12458 +struct vcmd_ctx_iattr_v1 {
12459 +       const char __user *name;
12460 +       uint32_t tag;
12461 +       uint32_t flags;
12462 +       uint32_t mask;
12463 +};
12464 +
12465 +struct vcmd_ctx_fiattr_v0 {
12466 +       uint32_t tag;
12467 +       uint32_t flags;
12468 +       uint32_t mask;
12469 +};
12470 +
12471 +
12472 +#ifdef __KERNEL__
12473 +
12474 +
12475 +#ifdef CONFIG_COMPAT
12476 +
12477 +#include <asm/compat.h>
12478 +
12479 +struct vcmd_ctx_iattr_v1_x32 {
12480 +       compat_uptr_t name_ptr;
12481 +       uint32_t tag;
12482 +       uint32_t flags;
12483 +       uint32_t mask;
12484 +};
12485 +
12486 +#endif /* CONFIG_COMPAT */
12487 +
12488 +#include <linux/compiler.h>
12489 +
12490 +extern int vc_get_iattr(void __user *);
12491 +extern int vc_set_iattr(void __user *);
12492 +
12493 +extern int vc_fget_iattr(uint32_t, void __user *);
12494 +extern int vc_fset_iattr(uint32_t, void __user *);
12495 +
12496 +#ifdef CONFIG_COMPAT
12497 +
12498 +extern int vc_get_iattr_x32(void __user *);
12499 +extern int vc_set_iattr_x32(void __user *);
12500 +
12501 +#endif /* CONFIG_COMPAT */
12502 +
12503 +#endif /* __KERNEL__ */
12504 +#endif /* _VX_INODE_CMD_H */
12505 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/limit.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit.h
12506 --- linux-3.2.8/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12507 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit.h 2011-12-05 19:33:02.000000000 +0100
12508 @@ -0,0 +1,71 @@
12509 +#ifndef _VX_LIMIT_H
12510 +#define _VX_LIMIT_H
12511 +
12512 +#define VLIMIT_NSOCK   16
12513 +#define VLIMIT_OPENFD  17
12514 +#define VLIMIT_ANON    18
12515 +#define VLIMIT_SHMEM   19
12516 +#define VLIMIT_SEMARY  20
12517 +#define VLIMIT_NSEMS   21
12518 +#define VLIMIT_DENTRY  22
12519 +#define VLIMIT_MAPPED  23
12520 +
12521 +
12522 +#ifdef __KERNEL__
12523 +
12524 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12525 +
12526 +/*     keep in sync with CRLIM_INFINITY */
12527 +
12528 +#define        VLIM_INFINITY   (~0ULL)
12529 +
12530 +#include <asm/atomic.h>
12531 +#include <asm/resource.h>
12532 +
12533 +#ifndef RLIM_INFINITY
12534 +#warning RLIM_INFINITY is undefined
12535 +#endif
12536 +
12537 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12538 +
12539 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12540 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12541 +
12542 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12543 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12544 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12545 +
12546 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12547 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12548 +
12549 +typedef atomic_long_t rlim_atomic_t;
12550 +typedef unsigned long rlim_t;
12551 +
12552 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12553 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12554 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12555 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12556 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12557 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12558 +
12559 +
12560 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12561 +#define        VX_VLIM(r) ((long long)(long)(r))
12562 +#define        VX_RLIM(v) ((rlim_t)(v))
12563 +#else
12564 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12565 +               ? VLIM_INFINITY : (long long)(r))
12566 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12567 +               ? RLIM_INFINITY : (rlim_t)(v))
12568 +#endif
12569 +
12570 +struct sysinfo;
12571 +
12572 +void vx_vsi_meminfo(struct sysinfo *);
12573 +void vx_vsi_swapinfo(struct sysinfo *);
12574 +long vx_vsi_cached(struct sysinfo *);
12575 +
12576 +#define NUM_LIMITS     24
12577 +
12578 +#endif /* __KERNEL__ */
12579 +#endif /* _VX_LIMIT_H */
12580 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/limit_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit_cmd.h
12581 --- linux-3.2.8/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12582 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit_cmd.h     2011-12-05 19:33:02.000000000 +0100
12583 @@ -0,0 +1,71 @@
12584 +#ifndef _VX_LIMIT_CMD_H
12585 +#define _VX_LIMIT_CMD_H
12586 +
12587 +
12588 +/*  rlimit vserver commands */
12589 +
12590 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12591 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12592 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12593 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12594 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12595 +
12596 +struct vcmd_ctx_rlimit_v0 {
12597 +       uint32_t id;
12598 +       uint64_t minimum;
12599 +       uint64_t softlimit;
12600 +       uint64_t maximum;
12601 +};
12602 +
12603 +struct vcmd_ctx_rlimit_mask_v0 {
12604 +       uint32_t minimum;
12605 +       uint32_t softlimit;
12606 +       uint32_t maximum;
12607 +};
12608 +
12609 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12610 +
12611 +struct vcmd_rlimit_stat_v0 {
12612 +       uint32_t id;
12613 +       uint32_t hits;
12614 +       uint64_t value;
12615 +       uint64_t minimum;
12616 +       uint64_t maximum;
12617 +};
12618 +
12619 +#define CRLIM_UNSET            (0ULL)
12620 +#define CRLIM_INFINITY         (~0ULL)
12621 +#define CRLIM_KEEP             (~1ULL)
12622 +
12623 +#ifdef __KERNEL__
12624 +
12625 +#ifdef CONFIG_IA32_EMULATION
12626 +
12627 +struct vcmd_ctx_rlimit_v0_x32 {
12628 +       uint32_t id;
12629 +       uint64_t minimum;
12630 +       uint64_t softlimit;
12631 +       uint64_t maximum;
12632 +} __attribute__ ((packed));
12633 +
12634 +#endif /* CONFIG_IA32_EMULATION */
12635 +
12636 +#include <linux/compiler.h>
12637 +
12638 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12639 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12640 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12641 +extern int vc_reset_hits(struct vx_info *, void __user *);
12642 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12643 +
12644 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12645 +
12646 +#ifdef CONFIG_IA32_EMULATION
12647 +
12648 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12649 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12650 +
12651 +#endif /* CONFIG_IA32_EMULATION */
12652 +
12653 +#endif /* __KERNEL__ */
12654 +#endif /* _VX_LIMIT_CMD_H */
12655 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/limit_def.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit_def.h
12656 --- linux-3.2.8/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12657 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit_def.h     2011-12-05 19:33:02.000000000 +0100
12658 @@ -0,0 +1,47 @@
12659 +#ifndef _VX_LIMIT_DEF_H
12660 +#define _VX_LIMIT_DEF_H
12661 +
12662 +#include <asm/atomic.h>
12663 +#include <asm/resource.h>
12664 +
12665 +#include "limit.h"
12666 +
12667 +
12668 +struct _vx_res_limit {
12669 +       rlim_t soft;            /* Context soft limit */
12670 +       rlim_t hard;            /* Context hard limit */
12671 +
12672 +       rlim_atomic_t rcur;     /* Current value */
12673 +       rlim_t rmin;            /* Context minimum */
12674 +       rlim_t rmax;            /* Context maximum */
12675 +
12676 +       atomic_t lhit;          /* Limit hits */
12677 +};
12678 +
12679 +/* context sub struct */
12680 +
12681 +struct _vx_limit {
12682 +       struct _vx_res_limit res[NUM_LIMITS];
12683 +};
12684 +
12685 +#ifdef CONFIG_VSERVER_DEBUG
12686 +
12687 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12688 +{
12689 +       int i;
12690 +
12691 +       printk("\t_vx_limit:");
12692 +       for (i = 0; i < NUM_LIMITS; i++) {
12693 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12694 +                       i, (unsigned long)__rlim_get(limit, i),
12695 +                       (unsigned long)__rlim_rmin(limit, i),
12696 +                       (unsigned long)__rlim_rmax(limit, i),
12697 +                       (long)__rlim_soft(limit, i),
12698 +                       (long)__rlim_hard(limit, i),
12699 +                       atomic_read(&__rlim_lhit(limit, i)));
12700 +       }
12701 +}
12702 +
12703 +#endif
12704 +
12705 +#endif /* _VX_LIMIT_DEF_H */
12706 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/limit_int.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit_int.h
12707 --- linux-3.2.8/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12708 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/limit_int.h     2011-12-05 19:33:02.000000000 +0100
12709 @@ -0,0 +1,198 @@
12710 +#ifndef _VX_LIMIT_INT_H
12711 +#define _VX_LIMIT_INT_H
12712 +
12713 +#include "context.h"
12714 +
12715 +#ifdef __KERNEL__
12716 +
12717 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12718 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12719 +
12720 +extern const char *vlimit_name[NUM_LIMITS];
12721 +
12722 +static inline void __vx_acc_cres(struct vx_info *vxi,
12723 +       int res, int dir, void *_data, char *_file, int _line)
12724 +{
12725 +       if (VXD_RCRES_COND(res))
12726 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12727 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12728 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12729 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12730 +       if (!vxi)
12731 +               return;
12732 +
12733 +       if (dir > 0)
12734 +               __rlim_inc(&vxi->limit, res);
12735 +       else
12736 +               __rlim_dec(&vxi->limit, res);
12737 +}
12738 +
12739 +static inline void __vx_add_cres(struct vx_info *vxi,
12740 +       int res, int amount, void *_data, char *_file, int _line)
12741 +{
12742 +       if (VXD_RCRES_COND(res))
12743 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12744 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12745 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12746 +                       amount, _data, _file, _line);
12747 +       if (amount == 0)
12748 +               return;
12749 +       if (!vxi)
12750 +               return;
12751 +       __rlim_add(&vxi->limit, res, amount);
12752 +}
12753 +
12754 +static inline
12755 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12756 +{
12757 +       int cond = (value > __rlim_rmax(limit, res));
12758 +
12759 +       if (cond)
12760 +               __rlim_rmax(limit, res) = value;
12761 +       return cond;
12762 +}
12763 +
12764 +static inline
12765 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12766 +{
12767 +       int cond = (value < __rlim_rmin(limit, res));
12768 +
12769 +       if (cond)
12770 +               __rlim_rmin(limit, res) = value;
12771 +       return cond;
12772 +}
12773 +
12774 +static inline
12775 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12776 +{
12777 +       if (!__vx_cres_adjust_max(limit, res, value))
12778 +               __vx_cres_adjust_min(limit, res, value);
12779 +}
12780 +
12781 +
12782 +/*     return values:
12783 +        +1 ... no limit hit
12784 +        -1 ... over soft limit
12785 +         0 ... over hard limit         */
12786 +
12787 +static inline int __vx_cres_avail(struct vx_info *vxi,
12788 +       int res, int num, char *_file, int _line)
12789 +{
12790 +       struct _vx_limit *limit;
12791 +       rlim_t value;
12792 +
12793 +       if (VXD_RLIMIT_COND(res))
12794 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12795 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12796 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12797 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12798 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12799 +                       num, _file, _line);
12800 +       if (!vxi)
12801 +               return 1;
12802 +
12803 +       limit = &vxi->limit;
12804 +       value = __rlim_get(limit, res);
12805 +
12806 +       if (!__vx_cres_adjust_max(limit, res, value))
12807 +               __vx_cres_adjust_min(limit, res, value);
12808 +
12809 +       if (num == 0)
12810 +               return 1;
12811 +
12812 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12813 +               return -1;
12814 +       if (value + num <= __rlim_soft(limit, res))
12815 +               return -1;
12816 +
12817 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12818 +               return 1;
12819 +       if (value + num <= __rlim_hard(limit, res))
12820 +               return 1;
12821 +
12822 +       __rlim_hit(limit, res);
12823 +       return 0;
12824 +}
12825 +
12826 +
12827 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12828 +
12829 +static inline
12830 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12831 +{
12832 +       rlim_t value, sum = 0;
12833 +       int res;
12834 +
12835 +       while ((res = *array++)) {
12836 +               value = __rlim_get(limit, res);
12837 +               __vx_cres_fixup(limit, res, value);
12838 +               sum += value;
12839 +       }
12840 +       return sum;
12841 +}
12842 +
12843 +static inline
12844 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12845 +{
12846 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12847 +       int res = *array;
12848 +
12849 +       if (value == __rlim_get(limit, res))
12850 +               return value;
12851 +
12852 +       __rlim_set(limit, res, value);
12853 +       /* now adjust min/max */
12854 +       if (!__vx_cres_adjust_max(limit, res, value))
12855 +               __vx_cres_adjust_min(limit, res, value);
12856 +
12857 +       return value;
12858 +}
12859 +
12860 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12861 +       const int *array, int num, char *_file, int _line)
12862 +{
12863 +       struct _vx_limit *limit;
12864 +       rlim_t value = 0;
12865 +       int res;
12866 +
12867 +       if (num == 0)
12868 +               return 1;
12869 +       if (!vxi)
12870 +               return 1;
12871 +
12872 +       limit = &vxi->limit;
12873 +       res = *array;
12874 +       value = __vx_cres_array_sum(limit, array + 1);
12875 +
12876 +       __rlim_set(limit, res, value);
12877 +       __vx_cres_fixup(limit, res, value);
12878 +
12879 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12880 +}
12881 +
12882 +
12883 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12884 +{
12885 +       rlim_t value;
12886 +       int res;
12887 +
12888 +       /* complex resources first */
12889 +       if ((id < 0) || (id == RLIMIT_RSS))
12890 +               __vx_cres_array_fixup(limit, VLA_RSS);
12891 +
12892 +       for (res = 0; res < NUM_LIMITS; res++) {
12893 +               if ((id > 0) && (res != id))
12894 +                       continue;
12895 +
12896 +               value = __rlim_get(limit, res);
12897 +               __vx_cres_fixup(limit, res, value);
12898 +
12899 +               /* not supposed to happen, maybe warn? */
12900 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12901 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12902 +       }
12903 +}
12904 +
12905 +
12906 +#endif /* __KERNEL__ */
12907 +#endif /* _VX_LIMIT_INT_H */
12908 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/monitor.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/monitor.h
12909 --- linux-3.2.8/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12910 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/monitor.h       2011-12-05 19:33:02.000000000 +0100
12911 @@ -0,0 +1,96 @@
12912 +#ifndef _VX_MONITOR_H
12913 +#define _VX_MONITOR_H
12914 +
12915 +#include <linux/types.h>
12916 +
12917 +enum {
12918 +       VXM_UNUSED = 0,
12919 +
12920 +       VXM_SYNC = 0x10,
12921 +
12922 +       VXM_UPDATE = 0x20,
12923 +       VXM_UPDATE_1,
12924 +       VXM_UPDATE_2,
12925 +
12926 +       VXM_RQINFO_1 = 0x24,
12927 +       VXM_RQINFO_2,
12928 +
12929 +       VXM_ACTIVATE = 0x40,
12930 +       VXM_DEACTIVATE,
12931 +       VXM_IDLE,
12932 +
12933 +       VXM_HOLD = 0x44,
12934 +       VXM_UNHOLD,
12935 +
12936 +       VXM_MIGRATE = 0x48,
12937 +       VXM_RESCHED,
12938 +
12939 +       /* all other bits are flags */
12940 +       VXM_SCHED = 0x80,
12941 +};
12942 +
12943 +struct _vxm_update_1 {
12944 +       uint32_t tokens_max;
12945 +       uint32_t fill_rate;
12946 +       uint32_t interval;
12947 +};
12948 +
12949 +struct _vxm_update_2 {
12950 +       uint32_t tokens_min;
12951 +       uint32_t fill_rate;
12952 +       uint32_t interval;
12953 +};
12954 +
12955 +struct _vxm_rqinfo_1 {
12956 +       uint16_t running;
12957 +       uint16_t onhold;
12958 +       uint16_t iowait;
12959 +       uint16_t uintr;
12960 +       uint32_t idle_tokens;
12961 +};
12962 +
12963 +struct _vxm_rqinfo_2 {
12964 +       uint32_t norm_time;
12965 +       uint32_t idle_time;
12966 +       uint32_t idle_skip;
12967 +};
12968 +
12969 +struct _vxm_sched {
12970 +       uint32_t tokens;
12971 +       uint32_t norm_time;
12972 +       uint32_t idle_time;
12973 +};
12974 +
12975 +struct _vxm_task {
12976 +       uint16_t pid;
12977 +       uint16_t state;
12978 +};
12979 +
12980 +struct _vxm_event {
12981 +       uint32_t jif;
12982 +       union {
12983 +               uint32_t seq;
12984 +               uint32_t sec;
12985 +       };
12986 +       union {
12987 +               uint32_t tokens;
12988 +               uint32_t nsec;
12989 +               struct _vxm_task tsk;
12990 +       };
12991 +};
12992 +
12993 +struct _vx_mon_entry {
12994 +       uint16_t type;
12995 +       uint16_t xid;
12996 +       union {
12997 +               struct _vxm_event ev;
12998 +               struct _vxm_sched sd;
12999 +               struct _vxm_update_1 u1;
13000 +               struct _vxm_update_2 u2;
13001 +               struct _vxm_rqinfo_1 q1;
13002 +               struct _vxm_rqinfo_2 q2;
13003 +       };
13004 +};
13005 +
13006 +
13007 +#endif /* _VX_MONITOR_H */
13008 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/network.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/network.h
13009 --- linux-3.2.8/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
13010 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/network.h       2011-12-05 19:33:02.000000000 +0100
13011 @@ -0,0 +1,148 @@
13012 +#ifndef _VX_NETWORK_H
13013 +#define _VX_NETWORK_H
13014 +
13015 +#include <linux/types.h>
13016 +
13017 +
13018 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13019 +
13020 +
13021 +/* network flags */
13022 +
13023 +#define NXF_INFO_PRIVATE       0x00000008
13024 +
13025 +#define NXF_SINGLE_IP          0x00000100
13026 +#define NXF_LBACK_REMAP                0x00000200
13027 +#define NXF_LBACK_ALLOW                0x00000400
13028 +
13029 +#define NXF_HIDE_NETIF         0x02000000
13030 +#define NXF_HIDE_LBACK         0x04000000
13031 +
13032 +#define NXF_STATE_SETUP                (1ULL << 32)
13033 +#define NXF_STATE_ADMIN                (1ULL << 34)
13034 +
13035 +#define NXF_SC_HELPER          (1ULL << 36)
13036 +#define NXF_PERSISTENT         (1ULL << 38)
13037 +
13038 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13039 +
13040 +
13041 +#define        NXF_INIT_SET            (__nxf_init_set())
13042 +
13043 +static inline uint64_t __nxf_init_set(void) {
13044 +       return    NXF_STATE_ADMIN
13045 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13046 +               | NXF_LBACK_REMAP
13047 +               | NXF_HIDE_LBACK
13048 +#endif
13049 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13050 +               | NXF_SINGLE_IP
13051 +#endif
13052 +               | NXF_HIDE_NETIF;
13053 +}
13054 +
13055 +
13056 +/* network caps */
13057 +
13058 +#define NXC_TUN_CREATE         0x00000001
13059 +
13060 +#define NXC_RAW_ICMP           0x00000100
13061 +
13062 +#define NXC_MULTICAST          0x00001000
13063 +
13064 +
13065 +/* address types */
13066 +
13067 +#define NXA_TYPE_IPV4          0x0001
13068 +#define NXA_TYPE_IPV6          0x0002
13069 +
13070 +#define NXA_TYPE_NONE          0x0000
13071 +#define NXA_TYPE_ANY           0x00FF
13072 +
13073 +#define NXA_TYPE_ADDR          0x0010
13074 +#define NXA_TYPE_MASK          0x0020
13075 +#define NXA_TYPE_RANGE         0x0040
13076 +
13077 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13078 +
13079 +#define NXA_MOD_BCAST          0x0100
13080 +#define NXA_MOD_LBACK          0x0200
13081 +
13082 +#define NXA_LOOPBACK           0x1000
13083 +
13084 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13085 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13086 +
13087 +#ifdef __KERNEL__
13088 +
13089 +#include <linux/list.h>
13090 +#include <linux/spinlock.h>
13091 +#include <linux/rcupdate.h>
13092 +#include <linux/in.h>
13093 +#include <linux/in6.h>
13094 +#include <asm/atomic.h>
13095 +
13096 +struct nx_addr_v4 {
13097 +       struct nx_addr_v4 *next;
13098 +       struct in_addr ip[2];
13099 +       struct in_addr mask;
13100 +       uint16_t type;
13101 +       uint16_t flags;
13102 +};
13103 +
13104 +struct nx_addr_v6 {
13105 +       struct nx_addr_v6 *next;
13106 +       struct in6_addr ip;
13107 +       struct in6_addr mask;
13108 +       uint32_t prefix;
13109 +       uint16_t type;
13110 +       uint16_t flags;
13111 +};
13112 +
13113 +struct nx_info {
13114 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13115 +       nid_t nx_id;                    /* vnet id */
13116 +       atomic_t nx_usecnt;             /* usage count */
13117 +       atomic_t nx_tasks;              /* tasks count */
13118 +       int nx_state;                   /* context state */
13119 +
13120 +       uint64_t nx_flags;              /* network flag word */
13121 +       uint64_t nx_ncaps;              /* network capabilities */
13122 +
13123 +       struct in_addr v4_lback;        /* Loopback address */
13124 +       struct in_addr v4_bcast;        /* Broadcast address */
13125 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13126 +#ifdef CONFIG_IPV6
13127 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13128 +#endif
13129 +       char nx_name[65];               /* network context name */
13130 +};
13131 +
13132 +
13133 +/* status flags */
13134 +
13135 +#define NXS_HASHED      0x0001
13136 +#define NXS_SHUTDOWN    0x0100
13137 +#define NXS_RELEASED    0x8000
13138 +
13139 +extern struct nx_info *lookup_nx_info(int);
13140 +
13141 +extern int get_nid_list(int, unsigned int *, int);
13142 +extern int nid_is_hashed(nid_t);
13143 +
13144 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13145 +
13146 +extern long vs_net_change(struct nx_info *, unsigned int);
13147 +
13148 +struct sock;
13149 +
13150 +
13151 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13152 +#ifdef  CONFIG_IPV6
13153 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13154 +#else
13155 +#define NX_IPV6(n)     (0)
13156 +#endif
13157 +
13158 +#endif /* __KERNEL__ */
13159 +#endif /* _VX_NETWORK_H */
13160 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/network_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/network_cmd.h
13161 --- linux-3.2.8/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13162 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/network_cmd.h   2011-12-05 19:33:02.000000000 +0100
13163 @@ -0,0 +1,164 @@
13164 +#ifndef _VX_NETWORK_CMD_H
13165 +#define _VX_NETWORK_CMD_H
13166 +
13167 +
13168 +/* vinfo commands */
13169 +
13170 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13171 +
13172 +#ifdef __KERNEL__
13173 +extern int vc_task_nid(uint32_t);
13174 +
13175 +#endif /* __KERNEL__ */
13176 +
13177 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13178 +
13179 +struct vcmd_nx_info_v0 {
13180 +       uint32_t nid;
13181 +       /* more to come */
13182 +};
13183 +
13184 +#ifdef __KERNEL__
13185 +extern int vc_nx_info(struct nx_info *, void __user *);
13186 +
13187 +#endif /* __KERNEL__ */
13188 +
13189 +#include <linux/in.h>
13190 +#include <linux/in6.h>
13191 +
13192 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13193 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13194 +
13195 +struct  vcmd_net_create {
13196 +       uint64_t flagword;
13197 +};
13198 +
13199 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13200 +
13201 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13202 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13203 +
13204 +struct vcmd_net_addr_v0 {
13205 +       uint16_t type;
13206 +       uint16_t count;
13207 +       struct in_addr ip[4];
13208 +       struct in_addr mask[4];
13209 +};
13210 +
13211 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13212 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13213 +
13214 +struct vcmd_net_addr_ipv4_v1 {
13215 +       uint16_t type;
13216 +       uint16_t flags;
13217 +       struct in_addr ip;
13218 +       struct in_addr mask;
13219 +};
13220 +
13221 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13222 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13223 +
13224 +struct vcmd_net_addr_ipv4_v2 {
13225 +       uint16_t type;
13226 +       uint16_t flags;
13227 +       struct in_addr ip;
13228 +       struct in_addr ip2;
13229 +       struct in_addr mask;
13230 +};
13231 +
13232 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13233 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13234 +
13235 +struct vcmd_net_addr_ipv6_v1 {
13236 +       uint16_t type;
13237 +       uint16_t flags;
13238 +       uint32_t prefix;
13239 +       struct in6_addr ip;
13240 +       struct in6_addr mask;
13241 +};
13242 +
13243 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13244 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13245 +
13246 +struct vcmd_match_ipv4_v0 {
13247 +       uint16_t type;
13248 +       uint16_t flags;
13249 +       uint16_t parent;
13250 +       uint16_t prefix;
13251 +       struct in_addr ip;
13252 +       struct in_addr ip2;
13253 +       struct in_addr mask;
13254 +};
13255 +
13256 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13257 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13258 +
13259 +struct vcmd_match_ipv6_v0 {
13260 +       uint16_t type;
13261 +       uint16_t flags;
13262 +       uint16_t parent;
13263 +       uint16_t prefix;
13264 +       struct in6_addr ip;
13265 +       struct in6_addr ip2;
13266 +       struct in6_addr mask;
13267 +};
13268 +
13269 +
13270 +#ifdef __KERNEL__
13271 +extern int vc_net_create(uint32_t, void __user *);
13272 +extern int vc_net_migrate(struct nx_info *, void __user *);
13273 +
13274 +extern int vc_net_add(struct nx_info *, void __user *);
13275 +extern int vc_net_remove(struct nx_info *, void __user *);
13276 +
13277 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13278 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13279 +
13280 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13281 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13282 +
13283 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13284 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13285 +
13286 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13287 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13288 +
13289 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13290 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13291 +
13292 +#endif /* __KERNEL__ */
13293 +
13294 +
13295 +/* flag commands */
13296 +
13297 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13298 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13299 +
13300 +struct vcmd_net_flags_v0 {
13301 +       uint64_t flagword;
13302 +       uint64_t mask;
13303 +};
13304 +
13305 +#ifdef __KERNEL__
13306 +extern int vc_get_nflags(struct nx_info *, void __user *);
13307 +extern int vc_set_nflags(struct nx_info *, void __user *);
13308 +
13309 +#endif /* __KERNEL__ */
13310 +
13311 +
13312 +/* network caps commands */
13313 +
13314 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13315 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13316 +
13317 +struct vcmd_net_caps_v0 {
13318 +       uint64_t ncaps;
13319 +       uint64_t cmask;
13320 +};
13321 +
13322 +#ifdef __KERNEL__
13323 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13324 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13325 +
13326 +#endif /* __KERNEL__ */
13327 +#endif /* _VX_CONTEXT_CMD_H */
13328 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/percpu.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/percpu.h
13329 --- linux-3.2.8/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13330 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/percpu.h        2011-12-05 19:33:02.000000000 +0100
13331 @@ -0,0 +1,14 @@
13332 +#ifndef _VX_PERCPU_H
13333 +#define _VX_PERCPU_H
13334 +
13335 +#include "cvirt_def.h"
13336 +#include "sched_def.h"
13337 +
13338 +struct _vx_percpu {
13339 +       struct _vx_cvirt_pc cvirt;
13340 +       struct _vx_sched_pc sched;
13341 +};
13342 +
13343 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13344 +
13345 +#endif /* _VX_PERCPU_H */
13346 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/pid.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/pid.h
13347 --- linux-3.2.8/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13348 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/pid.h   2011-12-05 19:33:02.000000000 +0100
13349 @@ -0,0 +1,51 @@
13350 +#ifndef _VSERVER_PID_H
13351 +#define _VSERVER_PID_H
13352 +
13353 +/* pid faking stuff */
13354 +
13355 +#define vx_info_map_pid(v, p) \
13356 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13357 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13358 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13359 +#define vx_map_tgid(p) vx_map_pid(p)
13360 +
13361 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13362 +       const char *func, const char *file, int line)
13363 +{
13364 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13365 +               vxfprintk(VXD_CBIT(cvirt, 2),
13366 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13367 +                       vxi, (long long)vxi->vx_flags, pid,
13368 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13369 +                       func, file, line);
13370 +               if (pid == 0)
13371 +                       return 0;
13372 +               if (pid == vxi->vx_initpid)
13373 +                       return 1;
13374 +       }
13375 +       return pid;
13376 +}
13377 +
13378 +#define vx_info_rmap_pid(v, p) \
13379 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13380 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13381 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13382 +
13383 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13384 +       const char *func, const char *file, int line)
13385 +{
13386 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13387 +               vxfprintk(VXD_CBIT(cvirt, 2),
13388 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13389 +                       vxi, (long long)vxi->vx_flags, pid,
13390 +                       (pid == 1) ? vxi->vx_initpid : pid,
13391 +                       func, file, line);
13392 +               if ((pid == 1) && vxi->vx_initpid)
13393 +                       return vxi->vx_initpid;
13394 +               if (pid == vxi->vx_initpid)
13395 +                       return ~0U;
13396 +       }
13397 +       return pid;
13398 +}
13399 +
13400 +#endif
13401 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/sched.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/sched.h
13402 --- linux-3.2.8/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13403 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/sched.h 2011-12-05 19:33:02.000000000 +0100
13404 @@ -0,0 +1,23 @@
13405 +#ifndef _VX_SCHED_H
13406 +#define _VX_SCHED_H
13407 +
13408 +
13409 +#ifdef __KERNEL__
13410 +
13411 +struct timespec;
13412 +
13413 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13414 +
13415 +
13416 +struct vx_info;
13417 +
13418 +void vx_update_load(struct vx_info *);
13419 +
13420 +
13421 +void vx_update_sched_param(struct _vx_sched *sched,
13422 +       struct _vx_sched_pc *sched_pc);
13423 +
13424 +#endif /* __KERNEL__ */
13425 +#else  /* _VX_SCHED_H */
13426 +#warning duplicate inclusion
13427 +#endif /* _VX_SCHED_H */
13428 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/sched_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/sched_cmd.h
13429 --- linux-3.2.8/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13430 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/sched_cmd.h     2011-12-05 19:33:02.000000000 +0100
13431 @@ -0,0 +1,21 @@
13432 +#ifndef _VX_SCHED_CMD_H
13433 +#define _VX_SCHED_CMD_H
13434 +
13435 +
13436 +struct vcmd_prio_bias {
13437 +       int32_t cpu_id;
13438 +       int32_t prio_bias;
13439 +};
13440 +
13441 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13442 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13443 +
13444 +#ifdef __KERNEL__
13445 +
13446 +#include <linux/compiler.h>
13447 +
13448 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13449 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13450 +
13451 +#endif /* __KERNEL__ */
13452 +#endif /* _VX_SCHED_CMD_H */
13453 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/sched_def.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/sched_def.h
13454 --- linux-3.2.8/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13455 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/sched_def.h     2011-12-05 19:33:02.000000000 +0100
13456 @@ -0,0 +1,38 @@
13457 +#ifndef _VX_SCHED_DEF_H
13458 +#define _VX_SCHED_DEF_H
13459 +
13460 +#include <linux/spinlock.h>
13461 +#include <linux/jiffies.h>
13462 +#include <linux/cpumask.h>
13463 +#include <asm/atomic.h>
13464 +#include <asm/param.h>
13465 +
13466 +
13467 +/* context sub struct */
13468 +
13469 +struct _vx_sched {
13470 +       int prio_bias;                  /* bias offset for priority */
13471 +
13472 +       cpumask_t update;               /* CPUs which should update */
13473 +};
13474 +
13475 +struct _vx_sched_pc {
13476 +       int prio_bias;                  /* bias offset for priority */
13477 +
13478 +       uint64_t user_ticks;            /* token tick events */
13479 +       uint64_t sys_ticks;             /* token tick events */
13480 +       uint64_t hold_ticks;            /* token ticks paused */
13481 +};
13482 +
13483 +
13484 +#ifdef CONFIG_VSERVER_DEBUG
13485 +
13486 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13487 +{
13488 +       printk("\t_vx_sched:\n");
13489 +       printk("\t priority = %4d\n", sched->prio_bias);
13490 +}
13491 +
13492 +#endif
13493 +
13494 +#endif /* _VX_SCHED_DEF_H */
13495 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/signal.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/signal.h
13496 --- linux-3.2.8/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13497 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/signal.h        2011-12-05 19:33:02.000000000 +0100
13498 @@ -0,0 +1,14 @@
13499 +#ifndef _VX_SIGNAL_H
13500 +#define _VX_SIGNAL_H
13501 +
13502 +
13503 +#ifdef __KERNEL__
13504 +
13505 +struct vx_info;
13506 +
13507 +int vx_info_kill(struct vx_info *, int, int);
13508 +
13509 +#endif /* __KERNEL__ */
13510 +#else  /* _VX_SIGNAL_H */
13511 +#warning duplicate inclusion
13512 +#endif /* _VX_SIGNAL_H */
13513 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/signal_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/signal_cmd.h
13514 --- linux-3.2.8/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13515 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/signal_cmd.h    2011-12-05 19:33:02.000000000 +0100
13516 @@ -0,0 +1,43 @@
13517 +#ifndef _VX_SIGNAL_CMD_H
13518 +#define _VX_SIGNAL_CMD_H
13519 +
13520 +
13521 +/*  signalling vserver commands */
13522 +
13523 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13524 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13525 +
13526 +struct vcmd_ctx_kill_v0 {
13527 +       int32_t pid;
13528 +       int32_t sig;
13529 +};
13530 +
13531 +struct vcmd_wait_exit_v0 {
13532 +       int32_t reboot_cmd;
13533 +       int32_t exit_code;
13534 +};
13535 +
13536 +#ifdef __KERNEL__
13537 +
13538 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13539 +extern int vc_wait_exit(struct vx_info *, void __user *);
13540 +
13541 +#endif /* __KERNEL__ */
13542 +
13543 +/*  process alteration commands */
13544 +
13545 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13546 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13547 +
13548 +struct vcmd_pflags_v0 {
13549 +       uint32_t flagword;
13550 +       uint32_t mask;
13551 +};
13552 +
13553 +#ifdef __KERNEL__
13554 +
13555 +extern int vc_get_pflags(uint32_t pid, void __user *);
13556 +extern int vc_set_pflags(uint32_t pid, void __user *);
13557 +
13558 +#endif /* __KERNEL__ */
13559 +#endif /* _VX_SIGNAL_CMD_H */
13560 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/space.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/space.h
13561 --- linux-3.2.8/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13562 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/space.h 2011-12-05 19:33:02.000000000 +0100
13563 @@ -0,0 +1,12 @@
13564 +#ifndef _VX_SPACE_H
13565 +#define _VX_SPACE_H
13566 +
13567 +#include <linux/types.h>
13568 +
13569 +struct vx_info;
13570 +
13571 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13572 +
13573 +#else  /* _VX_SPACE_H */
13574 +#warning duplicate inclusion
13575 +#endif /* _VX_SPACE_H */
13576 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/space_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/space_cmd.h
13577 --- linux-3.2.8/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13578 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/space_cmd.h     2011-12-05 19:33:02.000000000 +0100
13579 @@ -0,0 +1,38 @@
13580 +#ifndef _VX_SPACE_CMD_H
13581 +#define _VX_SPACE_CMD_H
13582 +
13583 +
13584 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13585 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13586 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13587 +
13588 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13589 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13590 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13591 +
13592 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13593 +
13594 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13595 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13596 +
13597 +
13598 +struct vcmd_space_mask_v1 {
13599 +       uint64_t mask;
13600 +};
13601 +
13602 +struct vcmd_space_mask_v2 {
13603 +       uint64_t mask;
13604 +       uint32_t index;
13605 +};
13606 +
13607 +
13608 +#ifdef __KERNEL__
13609 +
13610 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13611 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13612 +extern int vc_enter_space(struct vx_info *, void __user *);
13613 +extern int vc_set_space(struct vx_info *, void __user *);
13614 +extern int vc_get_space_mask(void __user *, int);
13615 +
13616 +#endif /* __KERNEL__ */
13617 +#endif /* _VX_SPACE_CMD_H */
13618 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/switch.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/switch.h
13619 --- linux-3.2.8/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13620 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/switch.h        2011-12-05 19:33:02.000000000 +0100
13621 @@ -0,0 +1,98 @@
13622 +#ifndef _VX_SWITCH_H
13623 +#define _VX_SWITCH_H
13624 +
13625 +#include <linux/types.h>
13626 +
13627 +
13628 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13629 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13630 +#define VC_VERSION(c)          ((c) & 0xFFF)
13631 +
13632 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13633 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13634 +
13635 +/*
13636 +
13637 +  Syscall Matrix V2.8
13638 +
13639 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13640 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13641 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13642 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13643 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13644 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13645 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13646 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13647 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13648 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13649 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13650 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13651 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13652 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13653 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13654 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13655 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13656 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13657 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13658 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13659 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13660 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13661 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13662 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13663 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13664 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13665 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13666 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13667 +
13668 +*/
13669 +
13670 +#define VC_CAT_VERSION         0
13671 +
13672 +#define VC_CAT_VSETUP          1
13673 +#define VC_CAT_VHOST           2
13674 +
13675 +#define VC_CAT_DEVICE          6
13676 +
13677 +#define VC_CAT_VPROC           9
13678 +#define VC_CAT_PROCALT         10
13679 +#define VC_CAT_PROCMIG         11
13680 +#define VC_CAT_PROCTRL         12
13681 +
13682 +#define VC_CAT_SCHED           14
13683 +#define VC_CAT_MEMCTRL         20
13684 +
13685 +#define VC_CAT_VNET            25
13686 +#define VC_CAT_NETALT          26
13687 +#define VC_CAT_NETMIG          27
13688 +#define VC_CAT_NETCTRL         28
13689 +
13690 +#define VC_CAT_TAGMIG          35
13691 +#define VC_CAT_DLIMIT          36
13692 +#define VC_CAT_INODE           38
13693 +
13694 +#define VC_CAT_VSTAT           40
13695 +#define VC_CAT_VINFO           46
13696 +#define VC_CAT_EVENT           48
13697 +
13698 +#define VC_CAT_FLAGS           52
13699 +#define VC_CAT_VSPACE          54
13700 +#define VC_CAT_DEBUG           56
13701 +#define VC_CAT_RLIMIT          60
13702 +
13703 +#define VC_CAT_SYSTEST         61
13704 +#define VC_CAT_COMPAT          63
13705 +
13706 +/*  query version */
13707 +
13708 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13709 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13710 +
13711 +
13712 +#ifdef __KERNEL__
13713 +
13714 +#include <linux/errno.h>
13715 +
13716 +#endif /* __KERNEL__ */
13717 +
13718 +#endif /* _VX_SWITCH_H */
13719 +
13720 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/tag.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/tag.h
13721 --- linux-3.2.8/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13722 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/tag.h   2011-12-05 19:33:02.000000000 +0100
13723 @@ -0,0 +1,143 @@
13724 +#ifndef _DX_TAG_H
13725 +#define _DX_TAG_H
13726 +
13727 +#include <linux/types.h>
13728 +
13729 +
13730 +#define DX_TAG(in)     (IS_TAGGED(in))
13731 +
13732 +
13733 +#ifdef CONFIG_TAG_NFSD
13734 +#define DX_TAG_NFSD    1
13735 +#else
13736 +#define DX_TAG_NFSD    0
13737 +#endif
13738 +
13739 +
13740 +#ifdef CONFIG_TAGGING_NONE
13741 +
13742 +#define MAX_UID                0xFFFFFFFF
13743 +#define MAX_GID                0xFFFFFFFF
13744 +
13745 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13746 +
13747 +#define TAGINO_UID(cond, uid, tag)     (uid)
13748 +#define TAGINO_GID(cond, gid, tag)     (gid)
13749 +
13750 +#endif
13751 +
13752 +
13753 +#ifdef CONFIG_TAGGING_GID16
13754 +
13755 +#define MAX_UID                0xFFFFFFFF
13756 +#define MAX_GID                0x0000FFFF
13757 +
13758 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13759 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13760 +
13761 +#define TAGINO_UID(cond, uid, tag)     (uid)
13762 +#define TAGINO_GID(cond, gid, tag)     \
13763 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13764 +
13765 +#endif
13766 +
13767 +
13768 +#ifdef CONFIG_TAGGING_ID24
13769 +
13770 +#define MAX_UID                0x00FFFFFF
13771 +#define MAX_GID                0x00FFFFFF
13772 +
13773 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13774 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13775 +
13776 +#define TAGINO_UID(cond, uid, tag)     \
13777 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13778 +#define TAGINO_GID(cond, gid, tag)     \
13779 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13780 +
13781 +#endif
13782 +
13783 +
13784 +#ifdef CONFIG_TAGGING_UID16
13785 +
13786 +#define MAX_UID                0x0000FFFF
13787 +#define MAX_GID                0xFFFFFFFF
13788 +
13789 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13790 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13791 +
13792 +#define TAGINO_UID(cond, uid, tag)     \
13793 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13794 +#define TAGINO_GID(cond, gid, tag)     (gid)
13795 +
13796 +#endif
13797 +
13798 +
13799 +#ifdef CONFIG_TAGGING_INTERN
13800 +
13801 +#define MAX_UID                0xFFFFFFFF
13802 +#define MAX_GID                0xFFFFFFFF
13803 +
13804 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13805 +       ((cond) ? (tag) : 0)
13806 +
13807 +#define TAGINO_UID(cond, uid, tag)     (uid)
13808 +#define TAGINO_GID(cond, gid, tag)     (gid)
13809 +
13810 +#endif
13811 +
13812 +
13813 +#ifndef CONFIG_TAGGING_NONE
13814 +#define dx_current_fstag(sb)   \
13815 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13816 +#else
13817 +#define dx_current_fstag(sb)   (0)
13818 +#endif
13819 +
13820 +#ifndef CONFIG_TAGGING_INTERN
13821 +#define TAGINO_TAG(cond, tag)  (0)
13822 +#else
13823 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13824 +#endif
13825 +
13826 +#define INOTAG_UID(cond, uid, gid)     \
13827 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13828 +#define INOTAG_GID(cond, uid, gid)     \
13829 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13830 +
13831 +
13832 +static inline uid_t dx_map_uid(uid_t uid)
13833 +{
13834 +       if ((uid > MAX_UID) && (uid != -1))
13835 +               uid = -2;
13836 +       return (uid & MAX_UID);
13837 +}
13838 +
13839 +static inline gid_t dx_map_gid(gid_t gid)
13840 +{
13841 +       if ((gid > MAX_GID) && (gid != -1))
13842 +               gid = -2;
13843 +       return (gid & MAX_GID);
13844 +}
13845 +
13846 +struct peer_tag {
13847 +       int32_t xid;
13848 +       int32_t nid;
13849 +};
13850 +
13851 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13852 +
13853 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13854 +                unsigned long *flags);
13855 +
13856 +#ifdef CONFIG_PROPAGATE
13857 +
13858 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13859 +
13860 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13861 +
13862 +#else
13863 +#define dx_propagate_tag(n, i) do { } while (0)
13864 +#endif
13865 +
13866 +#endif /* _DX_TAG_H */
13867 diff -NurpP --minimal linux-3.2.8/include/linux/vserver/tag_cmd.h linux-3.2.8-vs2.3.2.7/include/linux/vserver/tag_cmd.h
13868 --- linux-3.2.8/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13869 +++ linux-3.2.8-vs2.3.2.7/include/linux/vserver/tag_cmd.h       2011-12-05 19:33:02.000000000 +0100
13870 @@ -0,0 +1,22 @@
13871 +#ifndef _VX_TAG_CMD_H
13872 +#define _VX_TAG_CMD_H
13873 +
13874 +
13875 +/* vinfo commands */
13876 +
13877 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13878 +
13879 +#ifdef __KERNEL__
13880 +extern int vc_task_tag(uint32_t);
13881 +
13882 +#endif /* __KERNEL__ */
13883 +
13884 +/* context commands */
13885 +
13886 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13887 +
13888 +#ifdef __KERNEL__
13889 +extern int vc_tag_migrate(uint32_t);
13890 +
13891 +#endif /* __KERNEL__ */
13892 +#endif /* _VX_TAG_CMD_H */
13893 diff -NurpP --minimal linux-3.2.8/include/net/addrconf.h linux-3.2.8-vs2.3.2.7/include/net/addrconf.h
13894 --- linux-3.2.8/include/net/addrconf.h  2012-01-09 16:14:59.000000000 +0100
13895 +++ linux-3.2.8-vs2.3.2.7/include/net/addrconf.h        2011-12-05 19:33:02.000000000 +0100
13896 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13897                                                struct net_device *dev,
13898                                                const struct in6_addr *daddr,
13899                                                unsigned int srcprefs,
13900 -                                              struct in6_addr *saddr);
13901 +                                              struct in6_addr *saddr,
13902 +                                              struct nx_info *nxi);
13903  extern int                     ipv6_get_lladdr(struct net_device *dev,
13904                                                 struct in6_addr *addr,
13905                                                 unsigned char banned_flags);
13906 diff -NurpP --minimal linux-3.2.8/include/net/af_unix.h linux-3.2.8-vs2.3.2.7/include/net/af_unix.h
13907 --- linux-3.2.8/include/net/af_unix.h   2011-07-22 11:18:11.000000000 +0200
13908 +++ linux-3.2.8-vs2.3.2.7/include/net/af_unix.h 2011-12-05 19:33:02.000000000 +0100
13909 @@ -4,6 +4,7 @@
13910  #include <linux/socket.h>
13911  #include <linux/un.h>
13912  #include <linux/mutex.h>
13913 +#include <linux/vs_base.h>
13914  #include <net/sock.h>
13915  
13916  extern void unix_inflight(struct file *fp);
13917 diff -NurpP --minimal linux-3.2.8/include/net/inet_timewait_sock.h linux-3.2.8-vs2.3.2.7/include/net/inet_timewait_sock.h
13918 --- linux-3.2.8/include/net/inet_timewait_sock.h        2012-01-09 16:14:59.000000000 +0100
13919 +++ linux-3.2.8-vs2.3.2.7/include/net/inet_timewait_sock.h      2011-12-05 19:33:02.000000000 +0100
13920 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13921  #define tw_net                 __tw_common.skc_net
13922  #define tw_daddr               __tw_common.skc_daddr
13923  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13924 +#define tw_xid                 __tw_common.skc_xid
13925 +#define tw_vx_info             __tw_common.skc_vx_info
13926 +#define tw_nid                 __tw_common.skc_nid
13927 +#define tw_nx_info             __tw_common.skc_nx_info
13928         int                     tw_timeout;
13929         volatile unsigned char  tw_substate;
13930         unsigned char           tw_rcv_wscale;
13931 diff -NurpP --minimal linux-3.2.8/include/net/ip6_route.h linux-3.2.8-vs2.3.2.7/include/net/ip6_route.h
13932 --- linux-3.2.8/include/net/ip6_route.h 2011-07-22 11:18:11.000000000 +0200
13933 +++ linux-3.2.8-vs2.3.2.7/include/net/ip6_route.h       2011-12-05 19:33:02.000000000 +0100
13934 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
13935                                                     struct rt6_info *rt,
13936                                                     const struct in6_addr *daddr,
13937                                                     unsigned int prefs,
13938 -                                                   struct in6_addr *saddr);
13939 +                                                   struct in6_addr *saddr,
13940 +                                                   struct nx_info *nxi);
13941  
13942  extern struct rt6_info         *rt6_lookup(struct net *net,
13943                                             const struct in6_addr *daddr,
13944 diff -NurpP --minimal linux-3.2.8/include/net/route.h linux-3.2.8-vs2.3.2.7/include/net/route.h
13945 --- linux-3.2.8/include/net/route.h     2012-01-09 16:14:59.000000000 +0100
13946 +++ linux-3.2.8-vs2.3.2.7/include/net/route.h   2012-02-07 03:13:38.000000000 +0100
13947 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13948                 dst_release(&rt->dst);
13949  }
13950  
13951 +#include <linux/vs_base.h>
13952 +#include <linux/vs_inet.h>
13953 +
13954  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13955  
13956  extern const __u8 ip_tos2prio[16];
13957 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13958                            protocol, flow_flags, dst, src, dport, sport);
13959  }
13960  
13961 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13962 +       struct flowi4 *);
13963 +
13964  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13965                                               __be32 dst, __be32 src, u32 tos,
13966                                               int oif, u8 protocol,
13967 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13968  {
13969         struct net *net = sock_net(sk);
13970         struct rtable *rt;
13971 +       struct nx_info *nx_info = current_nx_info();
13972  
13973         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13974                               sport, dport, sk, can_sleep);
13975  
13976 -       if (!dst || !src) {
13977 +       if (sk)
13978 +               nx_info = sk->sk_nx_info;
13979 +
13980 +       vxdprintk(VXD_CBIT(net, 4),
13981 +               "ip_route_connect(%p) %p,%p;%lx",
13982 +               sk, nx_info, sk->sk_socket,
13983 +               (sk->sk_socket?sk->sk_socket->flags:0));
13984 +
13985 +       rt = ip_v4_find_src(net, nx_info, fl4);
13986 +       if (IS_ERR(rt))
13987 +               return rt;
13988 +       ip_rt_put(rt);
13989 +
13990 +       if (!fl4->daddr || !fl4->saddr) {
13991                 rt = __ip_route_output_key(net, fl4);
13992                 if (IS_ERR(rt))
13993                         return rt;
13994 diff -NurpP --minimal linux-3.2.8/include/net/sock.h linux-3.2.8-vs2.3.2.7/include/net/sock.h
13995 --- linux-3.2.8/include/net/sock.h      2012-01-09 16:14:59.000000000 +0100
13996 +++ linux-3.2.8-vs2.3.2.7/include/net/sock.h    2012-01-09 16:19:31.000000000 +0100
13997 @@ -149,6 +149,10 @@ struct sock_common {
13998  #ifdef CONFIG_NET_NS
13999         struct net              *skc_net;
14000  #endif
14001 +       xid_t                   skc_xid;
14002 +       struct vx_info          *skc_vx_info;
14003 +       nid_t                   skc_nid;
14004 +       struct nx_info          *skc_nx_info;
14005         /*
14006          * fields between dontcopy_begin/dontcopy_end
14007          * are not copied in sock_copy()
14008 @@ -256,6 +260,10 @@ struct sock {
14009  #define sk_bind_node           __sk_common.skc_bind_node
14010  #define sk_prot                        __sk_common.skc_prot
14011  #define sk_net                 __sk_common.skc_net
14012 +#define sk_xid                 __sk_common.skc_xid
14013 +#define sk_vx_info             __sk_common.skc_vx_info
14014 +#define sk_nid                 __sk_common.skc_nid
14015 +#define sk_nx_info             __sk_common.skc_nx_info
14016         socket_lock_t           sk_lock;
14017         struct sk_buff_head     sk_receive_queue;
14018         /*
14019 diff -NurpP --minimal linux-3.2.8/init/Kconfig linux-3.2.8-vs2.3.2.7/init/Kconfig
14020 --- linux-3.2.8/init/Kconfig    2012-01-09 16:14:59.000000000 +0100
14021 +++ linux-3.2.8-vs2.3.2.7/init/Kconfig  2011-12-05 19:33:02.000000000 +0100
14022 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14023  menuconfig CGROUPS
14024         boolean "Control Group support"
14025         depends on EVENTFD
14026 +       default y
14027         help
14028           This option adds support for grouping sets of processes together, for
14029           use with process control subsystems such as Cpusets, CFS, memory
14030 @@ -802,6 +803,7 @@ config IPC_NS
14031  config USER_NS
14032         bool "User namespace (EXPERIMENTAL)"
14033         depends on EXPERIMENTAL
14034 +       depends on VSERVER_DISABLED
14035         default y
14036         help
14037           This allows containers, i.e. vservers, to use user namespaces
14038 diff -NurpP --minimal linux-3.2.8/init/main.c linux-3.2.8-vs2.3.2.7/init/main.c
14039 --- linux-3.2.8/init/main.c     2012-01-09 16:14:59.000000000 +0100
14040 +++ linux-3.2.8-vs2.3.2.7/init/main.c   2011-12-05 19:33:02.000000000 +0100
14041 @@ -68,6 +68,7 @@
14042  #include <linux/shmem_fs.h>
14043  #include <linux/slab.h>
14044  #include <linux/perf_event.h>
14045 +#include <linux/vserver/percpu.h>
14046  
14047  #include <asm/io.h>
14048  #include <asm/bugs.h>
14049 diff -NurpP --minimal linux-3.2.8/ipc/mqueue.c linux-3.2.8-vs2.3.2.7/ipc/mqueue.c
14050 --- linux-3.2.8/ipc/mqueue.c    2012-01-09 16:14:59.000000000 +0100
14051 +++ linux-3.2.8-vs2.3.2.7/ipc/mqueue.c  2012-01-09 16:19:31.000000000 +0100
14052 @@ -33,6 +33,8 @@
14053  #include <linux/pid.h>
14054  #include <linux/ipc_namespace.h>
14055  #include <linux/slab.h>
14056 +#include <linux/vs_context.h>
14057 +#include <linux/vs_limit.h>
14058  
14059  #include <net/sock.h>
14060  #include "util.h"
14061 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14062         struct sigevent notify;
14063         struct pid* notify_owner;
14064         struct user_struct *user;       /* user who created, for accounting */
14065 +       struct vx_info *vxi;
14066         struct sock *notify_sock;
14067         struct sk_buff *notify_cookie;
14068  
14069 @@ -128,6 +131,7 @@ static struct inode *mqueue_get_inode(st
14070         if (S_ISREG(mode)) {
14071                 struct mqueue_inode_info *info;
14072                 struct task_struct *p = current;
14073 +               struct vx_info *vxi = p->vx_info;
14074                 unsigned long mq_bytes, mq_msg_tblsz;
14075  
14076                 inode->i_fop = &mqueue_file_operations;
14077 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14078                 info->notify_owner = NULL;
14079                 info->qsize = 0;
14080                 info->user = NULL;      /* set when all is ok */
14081 +               info->vxi = NULL;
14082                 memset(&info->attr, 0, sizeof(info->attr));
14083                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14084                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14085 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14086  
14087                 spin_lock(&mq_lock);
14088                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14089 -                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
14090 +                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE) ||
14091 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14092                         spin_unlock(&mq_lock);
14093                         /* mqueue_evict_inode() releases info->messages */
14094                         ret = -EMFILE;
14095                         goto out_inode;
14096                 }
14097                 u->mq_bytes += mq_bytes;
14098 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14099                 spin_unlock(&mq_lock);
14100  
14101                 /* all is ok */
14102                 info->user = get_uid(u);
14103 +               info->vxi = get_vx_info(vxi);
14104         } else if (S_ISDIR(mode)) {
14105                 inc_nlink(inode);
14106                 /* Some things misbehave if size == 0 on a directory */
14107 @@ -278,8 +286,11 @@ static void mqueue_evict_inode(struct in
14108             + info->attr.mq_msgsize);
14109         user = info->user;
14110         if (user) {
14111 +               struct vx_info *vxi = info->vxi;
14112 +
14113                 spin_lock(&mq_lock);
14114                 user->mq_bytes -= mq_bytes;
14115 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14116                 /*
14117                  * get_ns_from_inode() ensures that the
14118                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14119 @@ -289,6 +300,7 @@ static void mqueue_evict_inode(struct in
14120                 if (ipc_ns)
14121                         ipc_ns->mq_queues_count--;
14122                 spin_unlock(&mq_lock);
14123 +               put_vx_info(vxi);
14124                 free_uid(user);
14125         }
14126         if (ipc_ns)
14127 diff -NurpP --minimal linux-3.2.8/ipc/msg.c linux-3.2.8-vs2.3.2.7/ipc/msg.c
14128 --- linux-3.2.8/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
14129 +++ linux-3.2.8-vs2.3.2.7/ipc/msg.c     2011-12-05 19:33:02.000000000 +0100
14130 @@ -37,6 +37,7 @@
14131  #include <linux/rwsem.h>
14132  #include <linux/nsproxy.h>
14133  #include <linux/ipc_namespace.h>
14134 +#include <linux/vs_base.h>
14135  
14136  #include <asm/current.h>
14137  #include <asm/uaccess.h>
14138 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14139  
14140         msq->q_perm.mode = msgflg & S_IRWXUGO;
14141         msq->q_perm.key = key;
14142 +       msq->q_perm.xid = vx_current_xid();
14143  
14144         msq->q_perm.security = NULL;
14145         retval = security_msg_queue_alloc(msq);
14146 diff -NurpP --minimal linux-3.2.8/ipc/namespace.c linux-3.2.8-vs2.3.2.7/ipc/namespace.c
14147 --- linux-3.2.8/ipc/namespace.c 2011-07-22 11:18:12.000000000 +0200
14148 +++ linux-3.2.8-vs2.3.2.7/ipc/namespace.c       2011-12-05 19:33:02.000000000 +0100
14149 @@ -13,11 +13,12 @@
14150  #include <linux/mount.h>
14151  #include <linux/user_namespace.h>
14152  #include <linux/proc_fs.h>
14153 +#include <linux/vs_base.h>
14154 +#include <linux/vserver/global.h>
14155  
14156  #include "util.h"
14157  
14158 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14159 -                                          struct ipc_namespace *old_ns)
14160 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14161  {
14162         struct ipc_namespace *ns;
14163         int err;
14164 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14165         ipcns_notify(IPCNS_CREATED);
14166         register_ipcns_notifier(ns);
14167  
14168 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14169 +       ns->user_ns = get_user_ns(user_ns);
14170  
14171         return ns;
14172  }
14173  
14174  struct ipc_namespace *copy_ipcs(unsigned long flags,
14175 -                               struct task_struct *tsk)
14176 +                               struct ipc_namespace *old_ns,
14177 +                               struct user_namespace *user_ns)
14178  {
14179 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14180 -
14181         if (!(flags & CLONE_NEWIPC))
14182 -               return get_ipc_ns(ns);
14183 -       return create_ipc_ns(tsk, ns);
14184 +               return get_ipc_ns(old_ns);
14185 +       return create_ipc_ns(user_ns);
14186  }
14187  
14188  /*
14189 diff -NurpP --minimal linux-3.2.8/ipc/sem.c linux-3.2.8-vs2.3.2.7/ipc/sem.c
14190 --- linux-3.2.8/ipc/sem.c       2012-01-09 16:14:59.000000000 +0100
14191 +++ linux-3.2.8-vs2.3.2.7/ipc/sem.c     2011-12-05 19:33:02.000000000 +0100
14192 @@ -86,6 +86,8 @@
14193  #include <linux/rwsem.h>
14194  #include <linux/nsproxy.h>
14195  #include <linux/ipc_namespace.h>
14196 +#include <linux/vs_base.h>
14197 +#include <linux/vs_limit.h>
14198  
14199  #include <asm/uaccess.h>
14200  #include "util.h"
14201 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14202  
14203         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14204         sma->sem_perm.key = key;
14205 +       sma->sem_perm.xid = vx_current_xid();
14206  
14207         sma->sem_perm.security = NULL;
14208         retval = security_sem_alloc(sma);
14209 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14210                 return id;
14211         }
14212         ns->used_sems += nsems;
14213 +       /* FIXME: obsoleted? */
14214 +       vx_semary_inc(sma);
14215 +       vx_nsems_add(sma, nsems);
14216  
14217         sma->sem_base = (struct sem *) &sma[1];
14218  
14219 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14220  
14221         wake_up_sem_queue_do(&tasks);
14222         ns->used_sems -= sma->sem_nsems;
14223 +       /* FIXME: obsoleted? */
14224 +       vx_nsems_sub(sma, sma->sem_nsems);
14225 +       vx_semary_dec(sma);
14226         security_sem_free(sma);
14227         ipc_rcu_putref(sma);
14228  }
14229 diff -NurpP --minimal linux-3.2.8/ipc/shm.c linux-3.2.8-vs2.3.2.7/ipc/shm.c
14230 --- linux-3.2.8/ipc/shm.c       2012-02-28 05:53:29.000000000 +0100
14231 +++ linux-3.2.8-vs2.3.2.7/ipc/shm.c     2012-01-26 08:52:10.000000000 +0100
14232 @@ -39,6 +39,8 @@
14233  #include <linux/nsproxy.h>
14234  #include <linux/mount.h>
14235  #include <linux/ipc_namespace.h>
14236 +#include <linux/vs_context.h>
14237 +#include <linux/vs_limit.h>
14238  
14239  #include <asm/uaccess.h>
14240  
14241 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14242   */
14243  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14244  {
14245 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14246 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14247 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14248 +
14249 +       vx_ipcshm_sub(vxi, shp, numpages);
14250 +       ns->shm_tot -= numpages;
14251 +
14252         shm_rmid(ns, shp);
14253         shm_unlock(shp);
14254         if (!is_file_hugepages(shp->shm_file))
14255 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14256                                                 shp->mlock_user);
14257         fput (shp->shm_file);
14258         security_shm_free(shp);
14259 +       put_vx_info(vxi);
14260         ipc_rcu_putref(shp);
14261  }
14262  
14263 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14264         if (ns->shm_tot + numpages > ns->shm_ctlall)
14265                 return -ENOSPC;
14266  
14267 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14268 +               return -ENOSPC;
14269 +
14270         shp = ipc_rcu_alloc(sizeof(*shp));
14271         if (!shp)
14272                 return -ENOMEM;
14273  
14274         shp->shm_perm.key = key;
14275 +       shp->shm_perm.xid = vx_current_xid();
14276         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14277         shp->mlock_user = NULL;
14278  
14279 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
14280         ns->shm_tot += numpages;
14281         error = shp->shm_perm.id;
14282         shm_unlock(shp);
14283 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14284         return error;
14285  
14286  no_id:
14287 diff -NurpP --minimal linux-3.2.8/kernel/Makefile linux-3.2.8-vs2.3.2.7/kernel/Makefile
14288 --- linux-3.2.8/kernel/Makefile 2012-01-09 16:14:59.000000000 +0100
14289 +++ linux-3.2.8-vs2.3.2.7/kernel/Makefile       2011-12-05 19:33:02.000000000 +0100
14290 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14291  CFLAGS_REMOVE_irq_work.o = -pg
14292  endif
14293  
14294 +obj-y += vserver/
14295  obj-$(CONFIG_FREEZER) += freezer.o
14296  obj-$(CONFIG_PROFILING) += profile.o
14297  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14298 diff -NurpP --minimal linux-3.2.8/kernel/capability.c linux-3.2.8-vs2.3.2.7/kernel/capability.c
14299 --- linux-3.2.8/kernel/capability.c     2012-01-09 16:14:59.000000000 +0100
14300 +++ linux-3.2.8-vs2.3.2.7/kernel/capability.c   2011-12-05 19:33:02.000000000 +0100
14301 @@ -15,6 +15,7 @@
14302  #include <linux/syscalls.h>
14303  #include <linux/pid_namespace.h>
14304  #include <linux/user_namespace.h>
14305 +#include <linux/vs_context.h>
14306  #include <asm/uaccess.h>
14307  
14308  /*
14309 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14310         return 0;
14311  }
14312  
14313 +
14314  /*
14315   * The only thing that can change the capabilities of the current
14316   * process is the current process. As such, we can't be in this code
14317 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
14318         return (ret == 0);
14319  }
14320  
14321 +#include <linux/vserver/base.h>
14322 +
14323  /**
14324   * capable - Determine if the current task has a superior capability in effect
14325   * @cap: The capability to be tested for
14326 diff -NurpP --minimal linux-3.2.8/kernel/compat.c linux-3.2.8-vs2.3.2.7/kernel/compat.c
14327 --- linux-3.2.8/kernel/compat.c 2012-01-09 16:14:59.000000000 +0100
14328 +++ linux-3.2.8-vs2.3.2.7/kernel/compat.c       2011-12-05 19:33:02.000000000 +0100
14329 @@ -973,7 +973,7 @@ asmlinkage long compat_sys_stime(compat_
14330         if (err)
14331                 return err;
14332  
14333 -       do_settimeofday(&tv);
14334 +       vx_settimeofday(&tv);
14335         return 0;
14336  }
14337  
14338 diff -NurpP --minimal linux-3.2.8/kernel/cred.c linux-3.2.8-vs2.3.2.7/kernel/cred.c
14339 --- linux-3.2.8/kernel/cred.c   2012-01-09 16:15:00.000000000 +0100
14340 +++ linux-3.2.8-vs2.3.2.7/kernel/cred.c 2011-12-05 19:33:02.000000000 +0100
14341 @@ -61,31 +61,6 @@ struct cred init_cred = {
14342  #endif
14343  };
14344  
14345 -static inline void set_cred_subscribers(struct cred *cred, int n)
14346 -{
14347 -#ifdef CONFIG_DEBUG_CREDENTIALS
14348 -       atomic_set(&cred->subscribers, n);
14349 -#endif
14350 -}
14351 -
14352 -static inline int read_cred_subscribers(const struct cred *cred)
14353 -{
14354 -#ifdef CONFIG_DEBUG_CREDENTIALS
14355 -       return atomic_read(&cred->subscribers);
14356 -#else
14357 -       return 0;
14358 -#endif
14359 -}
14360 -
14361 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14362 -{
14363 -#ifdef CONFIG_DEBUG_CREDENTIALS
14364 -       struct cred *cred = (struct cred *) _cred;
14365 -
14366 -       atomic_add(n, &cred->subscribers);
14367 -#endif
14368 -}
14369 -
14370  /*
14371   * Dispose of the shared task group credentials
14372   */
14373 @@ -281,21 +256,16 @@ error:
14374   *
14375   * Call commit_creds() or abort_creds() to clean up.
14376   */
14377 -struct cred *prepare_creds(void)
14378 +struct cred *__prepare_creds(const struct cred *old)
14379  {
14380 -       struct task_struct *task = current;
14381 -       const struct cred *old;
14382         struct cred *new;
14383  
14384 -       validate_process_creds();
14385 -
14386         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14387         if (!new)
14388                 return NULL;
14389  
14390         kdebug("prepare_creds() alloc %p", new);
14391  
14392 -       old = task->cred;
14393         memcpy(new, old, sizeof(struct cred));
14394  
14395         atomic_set(&new->usage, 1);
14396 @@ -322,6 +292,13 @@ error:
14397         abort_creds(new);
14398         return NULL;
14399  }
14400 +
14401 +struct cred *prepare_creds(void)
14402 +{
14403 +       validate_process_creds();
14404 +
14405 +       return __prepare_creds(current->cred);
14406 +}
14407  EXPORT_SYMBOL(prepare_creds);
14408  
14409  /*
14410 diff -NurpP --minimal linux-3.2.8/kernel/exit.c linux-3.2.8-vs2.3.2.7/kernel/exit.c
14411 --- linux-3.2.8/kernel/exit.c   2012-01-09 16:15:00.000000000 +0100
14412 +++ linux-3.2.8-vs2.3.2.7/kernel/exit.c 2012-01-09 16:19:31.000000000 +0100
14413 @@ -48,6 +48,10 @@
14414  #include <linux/fs_struct.h>
14415  #include <linux/init_task.h>
14416  #include <linux/perf_event.h>
14417 +#include <linux/vs_limit.h>
14418 +#include <linux/vs_context.h>
14419 +#include <linux/vs_network.h>
14420 +#include <linux/vs_pid.h>
14421  #include <trace/events/sched.h>
14422  #include <linux/hw_breakpoint.h>
14423  #include <linux/oom.h>
14424 @@ -480,9 +484,11 @@ static void close_files(struct files_str
14425                                         filp_close(file, files);
14426                                         cond_resched();
14427                                 }
14428 +                               vx_openfd_dec(i);
14429                         }
14430                         i++;
14431                         set >>= 1;
14432 +                       cond_resched();
14433                 }
14434         }
14435  }
14436 @@ -1036,11 +1042,16 @@ NORET_TYPE void do_exit(long code)
14437  
14438         validate_creds_for_do_exit(tsk);
14439  
14440 +       /* needs to stay after exit_notify() */
14441 +       exit_vx_info(tsk, code);
14442 +       exit_nx_info(tsk);
14443 +
14444         preempt_disable();
14445         exit_rcu();
14446         /* causes final put_task_struct in finish_task_switch(). */
14447         tsk->state = TASK_DEAD;
14448         schedule();
14449 +       printk("bad task: %p [%lx]\n", current, current->state);
14450         BUG();
14451         /* Avoid "noreturn function does return".  */
14452         for (;;)
14453 diff -NurpP --minimal linux-3.2.8/kernel/fork.c linux-3.2.8-vs2.3.2.7/kernel/fork.c
14454 --- linux-3.2.8/kernel/fork.c   2012-01-09 16:15:00.000000000 +0100
14455 +++ linux-3.2.8-vs2.3.2.7/kernel/fork.c 2011-12-15 01:52:28.000000000 +0100
14456 @@ -66,6 +66,9 @@
14457  #include <linux/oom.h>
14458  #include <linux/khugepaged.h>
14459  #include <linux/signalfd.h>
14460 +#include <linux/vs_context.h>
14461 +#include <linux/vs_network.h>
14462 +#include <linux/vs_limit.h>
14463  
14464  #include <asm/pgtable.h>
14465  #include <asm/pgalloc.h>
14466 @@ -165,6 +168,8 @@ void free_task(struct task_struct *tsk)
14467         account_kernel_stack(tsk->stack, -1);
14468         free_thread_info(tsk->stack);
14469         rt_mutex_debug_task_free(tsk);
14470 +       clr_vx_info(&tsk->vx_info);
14471 +       clr_nx_info(&tsk->nx_info);
14472         ftrace_graph_exit_task(tsk);
14473         free_task_struct(tsk);
14474  }
14475 @@ -500,6 +505,7 @@ static struct mm_struct *mm_init(struct 
14476         if (likely(!mm_alloc_pgd(mm))) {
14477                 mm->def_flags = 0;
14478                 mmu_notifier_mm_init(mm);
14479 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14480                 return mm;
14481         }
14482  
14483 @@ -537,6 +543,7 @@ void __mmdrop(struct mm_struct *mm)
14484  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14485         VM_BUG_ON(mm->pmd_huge_pte);
14486  #endif
14487 +       clr_vx_info(&mm->mm_vx_info);
14488         free_mm(mm);
14489  }
14490  EXPORT_SYMBOL_GPL(__mmdrop);
14491 @@ -724,6 +731,7 @@ struct mm_struct *dup_mm(struct task_str
14492                 goto fail_nomem;
14493  
14494         memcpy(mm, oldmm, sizeof(*mm));
14495 +       mm->mm_vx_info = NULL;
14496         mm_init_cpumask(mm);
14497  
14498         /* Initializing for Swap token stuff */
14499 @@ -767,6 +775,7 @@ fail_nocontext:
14500          * If init_new_context() failed, we cannot use mmput() to free the mm
14501          * because it calls destroy_context()
14502          */
14503 +       clr_vx_info(&mm->mm_vx_info);
14504         mm_free_pgd(mm);
14505         free_mm(mm);
14506         return NULL;
14507 @@ -1050,6 +1059,8 @@ static struct task_struct *copy_process(
14508         int retval;
14509         struct task_struct *p;
14510         int cgroup_callbacks_done = 0;
14511 +       struct vx_info *vxi;
14512 +       struct nx_info *nxi;
14513  
14514         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14515                 return ERR_PTR(-EINVAL);
14516 @@ -1096,7 +1107,12 @@ static struct task_struct *copy_process(
14517         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14518         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14519  #endif
14520 +       init_vx_info(&p->vx_info, current_vx_info());
14521 +       init_nx_info(&p->nx_info, current_nx_info());
14522 +
14523         retval = -EAGAIN;
14524 +       if (!vx_nproc_avail(1))
14525 +               goto bad_fork_free;
14526         if (atomic_read(&p->real_cred->user->processes) >=
14527                         task_rlimit(p, RLIMIT_NPROC)) {
14528                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14529 @@ -1369,6 +1385,18 @@ static struct task_struct *copy_process(
14530  
14531         total_forks++;
14532         spin_unlock(&current->sighand->siglock);
14533 +
14534 +       /* p is copy of current */
14535 +       vxi = p->vx_info;
14536 +       if (vxi) {
14537 +               claim_vx_info(vxi, p);
14538 +               atomic_inc(&vxi->cvirt.nr_threads);
14539 +               atomic_inc(&vxi->cvirt.total_forks);
14540 +               vx_nproc_inc(p);
14541 +       }
14542 +       nxi = p->nx_info;
14543 +       if (nxi)
14544 +               claim_nx_info(nxi, p);
14545         write_unlock_irq(&tasklist_lock);
14546         proc_fork_connector(p);
14547         cgroup_post_fork(p);
14548 diff -NurpP --minimal linux-3.2.8/kernel/kthread.c linux-3.2.8-vs2.3.2.7/kernel/kthread.c
14549 --- linux-3.2.8/kernel/kthread.c        2012-01-09 16:15:00.000000000 +0100
14550 +++ linux-3.2.8-vs2.3.2.7/kernel/kthread.c      2011-12-05 19:33:02.000000000 +0100
14551 @@ -16,6 +16,7 @@
14552  #include <linux/mutex.h>
14553  #include <linux/slab.h>
14554  #include <linux/freezer.h>
14555 +#include <linux/vs_pid.h>
14556  #include <trace/events/sched.h>
14557  
14558  static DEFINE_SPINLOCK(kthread_create_lock);
14559 diff -NurpP --minimal linux-3.2.8/kernel/nsproxy.c linux-3.2.8-vs2.3.2.7/kernel/nsproxy.c
14560 --- linux-3.2.8/kernel/nsproxy.c        2012-01-09 16:15:00.000000000 +0100
14561 +++ linux-3.2.8-vs2.3.2.7/kernel/nsproxy.c      2011-12-05 19:33:02.000000000 +0100
14562 @@ -20,6 +20,8 @@
14563  #include <linux/mnt_namespace.h>
14564  #include <linux/utsname.h>
14565  #include <linux/pid_namespace.h>
14566 +#include <linux/vserver/global.h>
14567 +#include <linux/vserver/debug.h>
14568  #include <net/net_namespace.h>
14569  #include <linux/ipc_namespace.h>
14570  #include <linux/proc_fs.h>
14571 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
14572         struct nsproxy *nsproxy;
14573  
14574         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14575 -       if (nsproxy)
14576 +       if (nsproxy) {
14577                 atomic_set(&nsproxy->count, 1);
14578 +               atomic_inc(&vs_global_nsproxy);
14579 +       }
14580 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14581         return nsproxy;
14582  }
14583  
14584 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
14585   * Return the newly created nsproxy.  Do not attach this to the task,
14586   * leave it to the caller to do proper locking and attach it to task.
14587   */
14588 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14589 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14590 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14591 +                       struct nsproxy *orig,
14592 +                       struct fs_struct *new_fs,
14593 +                       struct user_namespace *new_user,
14594 +                       struct pid_namespace *new_pid)
14595  {
14596         struct nsproxy *new_nsp;
14597         int err;
14598 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
14599         if (!new_nsp)
14600                 return ERR_PTR(-ENOMEM);
14601  
14602 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14603 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14604         if (IS_ERR(new_nsp->mnt_ns)) {
14605                 err = PTR_ERR(new_nsp->mnt_ns);
14606                 goto out_ns;
14607         }
14608  
14609 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14610 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14611         if (IS_ERR(new_nsp->uts_ns)) {
14612                 err = PTR_ERR(new_nsp->uts_ns);
14613                 goto out_uts;
14614         }
14615  
14616 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14617 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14618         if (IS_ERR(new_nsp->ipc_ns)) {
14619                 err = PTR_ERR(new_nsp->ipc_ns);
14620                 goto out_ipc;
14621         }
14622  
14623 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14624 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14625         if (IS_ERR(new_nsp->pid_ns)) {
14626                 err = PTR_ERR(new_nsp->pid_ns);
14627                 goto out_pid;
14628         }
14629  
14630 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14631 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14632         if (IS_ERR(new_nsp->net_ns)) {
14633                 err = PTR_ERR(new_nsp->net_ns);
14634                 goto out_net;
14635 @@ -115,6 +123,40 @@ out_ns:
14636         return ERR_PTR(err);
14637  }
14638  
14639 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14640 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14641 +{
14642 +       return unshare_namespaces(flags, tsk->nsproxy,
14643 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14644 +               task_active_pid_ns(tsk));
14645 +}
14646 +
14647 +/*
14648 + * copies the nsproxy, setting refcount to 1, and grabbing a
14649 + * reference to all contained namespaces.
14650 + */
14651 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14652 +{
14653 +       struct nsproxy *ns = create_nsproxy();
14654 +
14655 +       if (ns) {
14656 +               memcpy(ns, orig, sizeof(struct nsproxy));
14657 +               atomic_set(&ns->count, 1);
14658 +
14659 +               if (ns->mnt_ns)
14660 +                       get_mnt_ns(ns->mnt_ns);
14661 +               if (ns->uts_ns)
14662 +                       get_uts_ns(ns->uts_ns);
14663 +               if (ns->ipc_ns)
14664 +                       get_ipc_ns(ns->ipc_ns);
14665 +               if (ns->pid_ns)
14666 +                       get_pid_ns(ns->pid_ns);
14667 +               if (ns->net_ns)
14668 +                       get_net(ns->net_ns);
14669 +       }
14670 +       return ns;
14671 +}
14672 +
14673  /*
14674   * called from clone.  This now handles copy for nsproxy and all
14675   * namespaces therein.
14676 @@ -122,9 +164,12 @@ out_ns:
14677  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14678  {
14679         struct nsproxy *old_ns = tsk->nsproxy;
14680 -       struct nsproxy *new_ns;
14681 +       struct nsproxy *new_ns = NULL;
14682         int err = 0;
14683  
14684 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14685 +               flags, tsk, old_ns);
14686 +
14687         if (!old_ns)
14688                 return 0;
14689  
14690 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
14691                                 CLONE_NEWPID | CLONE_NEWNET)))
14692                 return 0;
14693  
14694 -       if (!capable(CAP_SYS_ADMIN)) {
14695 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14696                 err = -EPERM;
14697                 goto out;
14698         }
14699 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
14700  
14701  out:
14702         put_nsproxy(old_ns);
14703 +       vxdprintk(VXD_CBIT(space, 3),
14704 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14705 +               flags, tsk, old_ns, err, new_ns);
14706         return err;
14707  }
14708  
14709 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
14710                 put_ipc_ns(ns->ipc_ns);
14711         if (ns->pid_ns)
14712                 put_pid_ns(ns->pid_ns);
14713 -       put_net(ns->net_ns);
14714 +       if (ns->net_ns)
14715 +               put_net(ns->net_ns);
14716 +       atomic_dec(&vs_global_nsproxy);
14717         kmem_cache_free(nsproxy_cachep, ns);
14718  }
14719  
14720 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
14721  {
14722         int err = 0;
14723  
14724 +       vxdprintk(VXD_CBIT(space, 4),
14725 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14726 +               unshare_flags, current->nsproxy);
14727 +
14728         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14729                                CLONE_NEWNET)))
14730                 return 0;
14731  
14732 -       if (!capable(CAP_SYS_ADMIN))
14733 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14734                 return -EPERM;
14735  
14736         *new_nsp = create_new_namespaces(unshare_flags, current,
14737 diff -NurpP --minimal linux-3.2.8/kernel/pid.c linux-3.2.8-vs2.3.2.7/kernel/pid.c
14738 --- linux-3.2.8/kernel/pid.c    2012-01-09 16:15:00.000000000 +0100
14739 +++ linux-3.2.8-vs2.3.2.7/kernel/pid.c  2011-12-05 19:43:14.000000000 +0100
14740 @@ -36,6 +36,7 @@
14741  #include <linux/pid_namespace.h>
14742  #include <linux/init_task.h>
14743  #include <linux/syscalls.h>
14744 +#include <linux/vs_pid.h>
14745  
14746  #define pid_hashfn(nr, ns)     \
14747         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14748 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14749  
14750  struct pid *find_vpid(int nr)
14751  {
14752 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14753 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14754  }
14755  EXPORT_SYMBOL_GPL(find_vpid);
14756  
14757 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
14758  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14759  {
14760         struct task_struct *result = NULL;
14761 +
14762 +       if (type == PIDTYPE_REALPID)
14763 +               type = PIDTYPE_PID;
14764         if (pid) {
14765                 struct hlist_node *first;
14766                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14767 @@ -421,7 +425,7 @@ struct task_struct *find_task_by_pid_ns(
14768         rcu_lockdep_assert(rcu_read_lock_held(),
14769                            "find_task_by_pid_ns() needs rcu_read_lock()"
14770                            " protection");
14771 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14772 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14773  }
14774  
14775  struct task_struct *find_task_by_vpid(pid_t vnr)
14776 @@ -465,7 +469,7 @@ struct pid *find_get_pid(pid_t nr)
14777  }
14778  EXPORT_SYMBOL_GPL(find_get_pid);
14779  
14780 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14781 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14782  {
14783         struct upid *upid;
14784         pid_t nr = 0;
14785 @@ -478,6 +482,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14786         return nr;
14787  }
14788  
14789 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14790 +{
14791 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14792 +}
14793 +
14794  pid_t pid_vnr(struct pid *pid)
14795  {
14796         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14797 diff -NurpP --minimal linux-3.2.8/kernel/pid_namespace.c linux-3.2.8-vs2.3.2.7/kernel/pid_namespace.c
14798 --- linux-3.2.8/kernel/pid_namespace.c  2011-05-22 16:17:59.000000000 +0200
14799 +++ linux-3.2.8-vs2.3.2.7/kernel/pid_namespace.c        2011-12-05 19:33:02.000000000 +0100
14800 @@ -15,6 +15,7 @@
14801  #include <linux/acct.h>
14802  #include <linux/slab.h>
14803  #include <linux/proc_fs.h>
14804 +#include <linux/vserver/global.h>
14805  
14806  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14807  
14808 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
14809                 goto out_free_map;
14810  
14811         kref_init(&ns->kref);
14812 +       atomic_inc(&vs_global_pid_ns);
14813         ns->level = level;
14814         ns->parent = get_pid_ns(parent_pid_ns);
14815  
14816 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
14817  
14818         for (i = 0; i < PIDMAP_ENTRIES; i++)
14819                 kfree(ns->pidmap[i].page);
14820 +       atomic_dec(&vs_global_pid_ns);
14821         kmem_cache_free(pid_ns_cachep, ns);
14822  }
14823  
14824 diff -NurpP --minimal linux-3.2.8/kernel/posix-timers.c linux-3.2.8-vs2.3.2.7/kernel/posix-timers.c
14825 --- linux-3.2.8/kernel/posix-timers.c   2012-01-09 16:15:00.000000000 +0100
14826 +++ linux-3.2.8-vs2.3.2.7/kernel/posix-timers.c 2011-12-05 19:44:00.000000000 +0100
14827 @@ -47,6 +47,7 @@
14828  #include <linux/wait.h>
14829  #include <linux/workqueue.h>
14830  #include <linux/export.h>
14831 +#include <linux/vs_context.h>
14832  
14833  /*
14834   * Management arrays for POSIX timers.  Timers are kept in slab memory
14835 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14836  {
14837         struct task_struct *task;
14838         int shared, ret = -1;
14839 +
14840         /*
14841          * FIXME: if ->sigq is queued we can race with
14842          * dequeue_signal()->do_schedule_next_timer().
14843 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14844         rcu_read_lock();
14845         task = pid_task(timr->it_pid, PIDTYPE_PID);
14846         if (task) {
14847 +               struct vx_info_save vxis;
14848 +               struct vx_info *vxi;
14849 +
14850 +               vxi = get_vx_info(task->vx_info);
14851 +               enter_vx_info(vxi, &vxis);
14852                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14853                 ret = send_sigqueue(timr->sigq, task, shared);
14854 +               leave_vx_info(&vxis);
14855 +               put_vx_info(vxi);
14856         }
14857         rcu_read_unlock();
14858 +
14859         /* If we failed to send the signal the timer stops. */
14860         return ret > 0;
14861  }
14862 diff -NurpP --minimal linux-3.2.8/kernel/printk.c linux-3.2.8-vs2.3.2.7/kernel/printk.c
14863 --- linux-3.2.8/kernel/printk.c 2012-01-09 16:15:00.000000000 +0100
14864 +++ linux-3.2.8-vs2.3.2.7/kernel/printk.c       2011-12-15 01:11:33.000000000 +0100
14865 @@ -41,6 +41,7 @@
14866  #include <linux/cpu.h>
14867  #include <linux/notifier.h>
14868  #include <linux/rculist.h>
14869 +#include <linux/vs_cvirt.h>
14870  
14871  #include <asm/uaccess.h>
14872  
14873 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
14874                 return 0;
14875  
14876         if (syslog_action_restricted(type)) {
14877 -               if (capable(CAP_SYSLOG))
14878 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14879                         return 0;
14880                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14881                 if (capable(CAP_SYS_ADMIN)) {
14882 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
14883         if (error)
14884                 return error;
14885  
14886 -       switch (type) {
14887 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14888 -               break;
14889 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14890 -               break;
14891 -       case SYSLOG_ACTION_READ:        /* Read from log */
14892 +       if ((type == SYSLOG_ACTION_READ) ||
14893 +           (type == SYSLOG_ACTION_READ_ALL) ||
14894 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14895                 error = -EINVAL;
14896                 if (!buf || len < 0)
14897                         goto out;
14898 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
14899                         error = -EFAULT;
14900                         goto out;
14901                 }
14902 +       }
14903 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14904 +               return vx_do_syslog(type, buf, len);
14905 +
14906 +       switch (type) {
14907 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14908 +               break;
14909 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14910 +               break;
14911 +       case SYSLOG_ACTION_READ:        /* Read from log */
14912                 error = wait_event_interruptible(log_wait,
14913                                                         (log_start - log_end));
14914                 if (error)
14915 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
14916                 /* FALL THRU */
14917         /* Read last kernel messages */
14918         case SYSLOG_ACTION_READ_ALL:
14919 -               error = -EINVAL;
14920 -               if (!buf || len < 0)
14921 -                       goto out;
14922 -               error = 0;
14923 -               if (!len)
14924 -                       goto out;
14925 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14926 -                       error = -EFAULT;
14927 -                       goto out;
14928 -               }
14929                 count = len;
14930                 if (count > log_buf_len)
14931                         count = log_buf_len;
14932 diff -NurpP --minimal linux-3.2.8/kernel/ptrace.c linux-3.2.8-vs2.3.2.7/kernel/ptrace.c
14933 --- linux-3.2.8/kernel/ptrace.c 2012-01-09 16:15:00.000000000 +0100
14934 +++ linux-3.2.8-vs2.3.2.7/kernel/ptrace.c       2012-01-09 16:19:31.000000000 +0100
14935 @@ -22,6 +22,7 @@
14936  #include <linux/syscalls.h>
14937  #include <linux/uaccess.h>
14938  #include <linux/regset.h>
14939 +#include <linux/vs_context.h>
14940  #include <linux/hw_breakpoint.h>
14941  #include <linux/cn_proc.h>
14942  
14943 @@ -209,6 +210,11 @@ ok:
14944                 dumpable = get_dumpable(task->mm);
14945         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
14946                 return -EPERM;
14947 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14948 +               return -EPERM;
14949 +       if (!vx_check(task->xid, VS_IDENT) &&
14950 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14951 +               return -EACCES;
14952  
14953         return security_ptrace_access_check(task, mode);
14954  }
14955 diff -NurpP --minimal linux-3.2.8/kernel/sched.c linux-3.2.8-vs2.3.2.7/kernel/sched.c
14956 --- linux-3.2.8/kernel/sched.c  2012-01-09 16:15:00.000000000 +0100
14957 +++ linux-3.2.8-vs2.3.2.7/kernel/sched.c        2011-12-15 01:14:00.000000000 +0100
14958 @@ -72,6 +72,8 @@
14959  #include <linux/ftrace.h>
14960  #include <linux/slab.h>
14961  #include <linux/init_task.h>
14962 +#include <linux/vs_sched.h>
14963 +#include <linux/vs_cvirt.h>
14964  
14965  #include <asm/tlb.h>
14966  #include <asm/irq_regs.h>
14967 @@ -3607,9 +3609,17 @@ static void calc_global_nohz(unsigned lo
14968   */
14969  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14970  {
14971 -       loads[0] = (avenrun[0] + offset) << shift;
14972 -       loads[1] = (avenrun[1] + offset) << shift;
14973 -       loads[2] = (avenrun[2] + offset) << shift;
14974 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14975 +               struct vx_info *vxi = current_vx_info();
14976 +
14977 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14978 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14979 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14980 +       } else {
14981 +               loads[0] = (avenrun[0] + offset) << shift;
14982 +               loads[1] = (avenrun[1] + offset) << shift;
14983 +               loads[2] = (avenrun[2] + offset) << shift;
14984 +       }
14985  }
14986  
14987  /*
14988 @@ -3868,16 +3878,19 @@ void account_user_time(struct task_struc
14989                        cputime_t cputime_scaled)
14990  {
14991         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
14992 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14993         cputime64_t tmp;
14994 +       int nice = (TASK_NICE(p) > 0);
14995  
14996         /* Add user time to process. */
14997         p->utime = cputime_add(p->utime, cputime);
14998         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
14999 +       vx_account_user(vxi, cputime, nice);
15000         account_group_user_time(p, cputime);
15001  
15002         /* Add user time to cpustat. */
15003         tmp = cputime_to_cputime64(cputime);
15004 -       if (TASK_NICE(p) > 0)
15005 +       if (nice)
15006                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15007         else
15008                 cpustat->user = cputime64_add(cpustat->user, tmp);
15009 @@ -3929,10 +3942,12 @@ void __account_system_time(struct task_s
15010                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
15011  {
15012         cputime64_t tmp = cputime_to_cputime64(cputime);
15013 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15014  
15015         /* Add system time to process. */
15016         p->stime = cputime_add(p->stime, cputime);
15017         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15018 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15019         account_group_system_time(p, cputime);
15020  
15021         /* Add system time to cpustat. */
15022 @@ -5132,7 +5147,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15023                 nice = 19;
15024  
15025         if (increment < 0 && !can_nice(current, nice))
15026 -               return -EPERM;
15027 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15028  
15029         retval = security_task_setnice(current, nice);
15030         if (retval)
15031 diff -NurpP --minimal linux-3.2.8/kernel/sched_fair.c linux-3.2.8-vs2.3.2.7/kernel/sched_fair.c
15032 --- linux-3.2.8/kernel/sched_fair.c     2012-01-09 16:15:00.000000000 +0100
15033 +++ linux-3.2.8-vs2.3.2.7/kernel/sched_fair.c   2012-01-09 16:19:31.000000000 +0100
15034 @@ -1014,6 +1014,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15035                 __enqueue_entity(cfs_rq, se);
15036         se->on_rq = 1;
15037  
15038 +       if (entity_is_task(se))
15039 +               vx_activate_task(task_of(se));
15040         if (cfs_rq->nr_running == 1) {
15041                 list_add_leaf_cfs_rq(cfs_rq);
15042                 check_enqueue_throttle(cfs_rq);
15043 @@ -1094,6 +1096,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15044         if (se != cfs_rq->curr)
15045                 __dequeue_entity(cfs_rq, se);
15046         se->on_rq = 0;
15047 +       if (entity_is_task(se))
15048 +               vx_deactivate_task(task_of(se));
15049         update_cfs_load(cfs_rq, 0);
15050         account_entity_dequeue(cfs_rq, se);
15051  
15052 diff -NurpP --minimal linux-3.2.8/kernel/signal.c linux-3.2.8-vs2.3.2.7/kernel/signal.c
15053 --- linux-3.2.8/kernel/signal.c 2012-01-09 16:15:00.000000000 +0100
15054 +++ linux-3.2.8-vs2.3.2.7/kernel/signal.c       2012-01-09 16:19:31.000000000 +0100
15055 @@ -28,6 +28,8 @@
15056  #include <linux/freezer.h>
15057  #include <linux/pid_namespace.h>
15058  #include <linux/nsproxy.h>
15059 +#include <linux/vs_context.h>
15060 +#include <linux/vs_pid.h>
15061  #define CREATE_TRACE_POINTS
15062  #include <trace/events/signal.h>
15063  
15064 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
15065         struct pid *sid;
15066         int error;
15067  
15068 +       vxdprintk(VXD_CBIT(misc, 7),
15069 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15070 +               sig, info, t, vx_task_xid(t), t->pid);
15071 +
15072         if (!valid_signal(sig))
15073                 return -EINVAL;
15074  
15075 +/*     FIXME: needed? if so, why?
15076 +       if ((info != SEND_SIG_NOINFO) &&
15077 +               (is_si_special(info) || !si_fromuser(info)))
15078 +               goto skip;      */
15079 +
15080         if (!si_fromuser(info))
15081                 return 0;
15082  
15083 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
15084                 }
15085         }
15086  
15087 +       error = -EPERM;
15088 +       if (t->pid == 1 && current->xid)
15089 +               return error;
15090 +
15091 +       error = -ESRCH;
15092 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15093 +                 loops, maybe ENOENT or EACCES? */
15094 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15095 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15096 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15097 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15098 +               return error;
15099 +       }
15100 +/* skip: */
15101         return security_task_kill(t, info, sig, 0);
15102  }
15103  
15104 @@ -1319,7 +1344,7 @@ int kill_pid_info(int sig, struct siginf
15105         rcu_read_lock();
15106  retry:
15107         p = pid_task(pid, PIDTYPE_PID);
15108 -       if (p) {
15109 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15110                 error = group_send_sig_info(sig, info, p);
15111                 if (unlikely(error == -ESRCH))
15112                         /*
15113 @@ -1369,7 +1394,7 @@ int kill_pid_info_as_cred(int sig, struc
15114  
15115         rcu_read_lock();
15116         p = pid_task(pid, PIDTYPE_PID);
15117 -       if (!p) {
15118 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15119                 ret = -ESRCH;
15120                 goto out_unlock;
15121         }
15122 @@ -1421,8 +1446,10 @@ static int kill_something_info(int sig, 
15123                 struct task_struct * p;
15124  
15125                 for_each_process(p) {
15126 -                       if (task_pid_vnr(p) > 1 &&
15127 -                                       !same_thread_group(p, current)) {
15128 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15129 +                               task_pid_vnr(p) > 1 &&
15130 +                               !same_thread_group(p, current) &&
15131 +                               !vx_current_initpid(p->pid)) {
15132                                 int err = group_send_sig_info(sig, info, p);
15133                                 ++count;
15134                                 if (err != -EPERM)
15135 @@ -2255,6 +2282,11 @@ relock:
15136                                 !sig_kernel_only(signr))
15137                         continue;
15138  
15139 +               /* virtual init is protected against user signals */
15140 +               if ((info->si_code == SI_USER) &&
15141 +                       vx_current_initpid(current->pid))
15142 +                       continue;
15143 +
15144                 if (sig_kernel_stop(signr)) {
15145                         /*
15146                          * The default action is to stop all threads in
15147 diff -NurpP --minimal linux-3.2.8/kernel/softirq.c linux-3.2.8-vs2.3.2.7/kernel/softirq.c
15148 --- linux-3.2.8/kernel/softirq.c        2012-01-09 16:15:00.000000000 +0100
15149 +++ linux-3.2.8-vs2.3.2.7/kernel/softirq.c      2011-12-05 19:33:02.000000000 +0100
15150 @@ -24,6 +24,7 @@
15151  #include <linux/ftrace.h>
15152  #include <linux/smp.h>
15153  #include <linux/tick.h>
15154 +#include <linux/vs_context.h>
15155  
15156  #define CREATE_TRACE_POINTS
15157  #include <trace/events/irq.h>
15158 diff -NurpP --minimal linux-3.2.8/kernel/sys.c linux-3.2.8-vs2.3.2.7/kernel/sys.c
15159 --- linux-3.2.8/kernel/sys.c    2012-01-09 16:15:00.000000000 +0100
15160 +++ linux-3.2.8-vs2.3.2.7/kernel/sys.c  2011-12-05 19:33:02.000000000 +0100
15161 @@ -45,6 +45,7 @@
15162  #include <linux/syscalls.h>
15163  #include <linux/kprobes.h>
15164  #include <linux/user_namespace.h>
15165 +#include <linux/vs_pid.h>
15166  
15167  #include <linux/kmsg_dump.h>
15168  /* Move somewhere else to avoid recompiling? */
15169 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15170                 goto out;
15171         }
15172         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15173 -               error = -EACCES;
15174 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15175 +                       error = 0;
15176 +               else
15177 +                       error = -EACCES;
15178                 goto out;
15179         }
15180         no_nice = security_task_setnice(p, niceval);
15181 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15182                         else
15183                                 pgrp = task_pgrp(current);
15184                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15185 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15186 +                                       continue;
15187                                 error = set_one_prio(p, niceval, error);
15188                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15189                         break;
15190 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15191                         else
15192                                 pgrp = task_pgrp(current);
15193                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15194 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15195 +                                       continue;
15196                                 niceval = 20 - task_nice(p);
15197                                 if (niceval > retval)
15198                                         retval = niceval;
15199 @@ -418,6 +426,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15200  
15201  static DEFINE_MUTEX(reboot_mutex);
15202  
15203 +long vs_reboot(unsigned int, void __user *);
15204 +
15205  /*
15206   * Reboot system call: for obvious reasons only root may call it,
15207   * and even root needs to set up some magic numbers in the registers
15208 @@ -450,6 +460,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15209         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15210                 cmd = LINUX_REBOOT_CMD_HALT;
15211  
15212 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15213 +               return vs_reboot(cmd, arg);
15214 +
15215         mutex_lock(&reboot_mutex);
15216         switch (cmd) {
15217         case LINUX_REBOOT_CMD_RESTART:
15218 @@ -1273,7 +1286,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15219         int errno;
15220         char tmp[__NEW_UTS_LEN];
15221  
15222 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15223 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15224 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15225                 return -EPERM;
15226  
15227         if (len < 0 || len > __NEW_UTS_LEN)
15228 @@ -1324,7 +1338,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15229         int errno;
15230         char tmp[__NEW_UTS_LEN];
15231  
15232 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15233 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15234 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15235                 return -EPERM;
15236         if (len < 0 || len > __NEW_UTS_LEN)
15237                 return -EINVAL;
15238 @@ -1443,7 +1458,7 @@ int do_prlimit(struct task_struct *tsk, 
15239                 /* Keep the capable check against init_user_ns until
15240                    cgroups can contain all limits */
15241                 if (new_rlim->rlim_max > rlim->rlim_max &&
15242 -                               !capable(CAP_SYS_RESOURCE))
15243 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15244                         retval = -EPERM;
15245                 if (!retval)
15246                         retval = security_task_setrlimit(tsk->group_leader,
15247 @@ -1497,7 +1512,8 @@ static int check_prlimit_permission(stru
15248              cred->gid == tcred->sgid &&
15249              cred->gid == tcred->gid))
15250                 return 0;
15251 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15252 +       if (vx_ns_capable(tcred->user->user_ns,
15253 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15254                 return 0;
15255  
15256         return -EPERM;
15257 diff -NurpP --minimal linux-3.2.8/kernel/sysctl.c linux-3.2.8-vs2.3.2.7/kernel/sysctl.c
15258 --- linux-3.2.8/kernel/sysctl.c 2012-01-09 16:15:00.000000000 +0100
15259 +++ linux-3.2.8-vs2.3.2.7/kernel/sysctl.c       2011-12-05 19:33:02.000000000 +0100
15260 @@ -76,6 +76,7 @@
15261  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15262  #include <linux/lockdep.h>
15263  #endif
15264 +extern char vshelper_path[];
15265  #ifdef CONFIG_CHR_DEV_SG
15266  #include <scsi/sg.h>
15267  #endif
15268 @@ -572,6 +573,13 @@ static struct ctl_table kern_table[] = {
15269                 .proc_handler   = proc_dostring,
15270         },
15271  #endif
15272 +       {
15273 +               .procname       = "vshelper",
15274 +               .data           = &vshelper_path,
15275 +               .maxlen         = 256,
15276 +               .mode           = 0644,
15277 +               .proc_handler   = &proc_dostring,
15278 +       },
15279  #ifdef CONFIG_CHR_DEV_SG
15280         {
15281                 .procname       = "sg-big-buff",
15282 diff -NurpP --minimal linux-3.2.8/kernel/sysctl_binary.c linux-3.2.8-vs2.3.2.7/kernel/sysctl_binary.c
15283 --- linux-3.2.8/kernel/sysctl_binary.c  2012-01-09 16:15:00.000000000 +0100
15284 +++ linux-3.2.8-vs2.3.2.7/kernel/sysctl_binary.c        2012-01-09 16:19:31.000000000 +0100
15285 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15286  
15287         { CTL_INT,      KERN_PANIC,                     "panic" },
15288         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15289 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15290  
15291         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15292         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15293 diff -NurpP --minimal linux-3.2.8/kernel/time/timekeeping.c linux-3.2.8-vs2.3.2.7/kernel/time/timekeeping.c
15294 --- linux-3.2.8/kernel/time/timekeeping.c       2012-01-09 16:15:00.000000000 +0100
15295 +++ linux-3.2.8-vs2.3.2.7/kernel/time/timekeeping.c     2011-12-05 19:33:02.000000000 +0100
15296 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15297         } while (read_seqretry(&xtime_lock, seq));
15298  
15299         timespec_add_ns(ts, nsecs);
15300 +       vx_adjust_timespec(ts);
15301  }
15302  
15303  EXPORT_SYMBOL(getnstimeofday);
15304 diff -NurpP --minimal linux-3.2.8/kernel/time.c linux-3.2.8-vs2.3.2.7/kernel/time.c
15305 --- linux-3.2.8/kernel/time.c   2012-01-09 16:15:00.000000000 +0100
15306 +++ linux-3.2.8-vs2.3.2.7/kernel/time.c 2011-12-05 19:33:02.000000000 +0100
15307 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15308         if (err)
15309                 return err;
15310  
15311 -       do_settimeofday(&tv);
15312 +       vx_settimeofday(&tv);
15313         return 0;
15314  }
15315  
15316 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15317                 /* SMP safe, again the code in arch/foo/time.c should
15318                  * globally block out interrupts when it runs.
15319                  */
15320 -               return do_settimeofday(tv);
15321 +               return vx_settimeofday(tv);
15322         }
15323         return 0;
15324  }
15325 diff -NurpP --minimal linux-3.2.8/kernel/timer.c linux-3.2.8-vs2.3.2.7/kernel/timer.c
15326 --- linux-3.2.8/kernel/timer.c  2012-01-09 16:15:00.000000000 +0100
15327 +++ linux-3.2.8-vs2.3.2.7/kernel/timer.c        2011-12-15 01:11:33.000000000 +0100
15328 @@ -40,6 +40,10 @@
15329  #include <linux/irq_work.h>
15330  #include <linux/sched.h>
15331  #include <linux/slab.h>
15332 +#include <linux/vs_base.h>
15333 +#include <linux/vs_cvirt.h>
15334 +#include <linux/vs_pid.h>
15335 +#include <linux/vserver/sched.h>
15336  
15337  #include <asm/uaccess.h>
15338  #include <asm/unistd.h>
15339 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15340  
15341  #endif
15342  
15343 -#ifndef __alpha__
15344 -
15345 -/*
15346 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15347 - * should be moved into arch/i386 instead?
15348 - */
15349  
15350  /**
15351   * sys_getpid - return the thread group id of the current process
15352 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15353         rcu_read_lock();
15354         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
15355         rcu_read_unlock();
15356 +       return vx_map_pid(pid);
15357 +}
15358  
15359 -       return pid;
15360 +#ifdef __alpha__
15361 +
15362 +/*
15363 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15364 + */
15365 +
15366 +asmlinkage long do_getxpid(long *ppid)
15367 +{
15368 +       *ppid = sys_getppid();
15369 +       return sys_getpid();
15370  }
15371  
15372 +#else /* _alpha_ */
15373 +
15374  SYSCALL_DEFINE0(getuid)
15375  {
15376         /* Only we change this so SMP safe */
15377 diff -NurpP --minimal linux-3.2.8/kernel/user_namespace.c linux-3.2.8-vs2.3.2.7/kernel/user_namespace.c
15378 --- linux-3.2.8/kernel/user_namespace.c 2012-01-09 16:15:00.000000000 +0100
15379 +++ linux-3.2.8-vs2.3.2.7/kernel/user_namespace.c       2011-12-05 19:33:02.000000000 +0100
15380 @@ -11,6 +11,7 @@
15381  #include <linux/user_namespace.h>
15382  #include <linux/highuid.h>
15383  #include <linux/cred.h>
15384 +#include <linux/vserver/global.h>
15385  
15386  static struct kmem_cache *user_ns_cachep __read_mostly;
15387  
15388 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15389                 return -ENOMEM;
15390  
15391         kref_init(&ns->kref);
15392 +       atomic_inc(&vs_global_user_ns);
15393  
15394         for (n = 0; n < UIDHASH_SZ; ++n)
15395                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15396 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15397         struct user_namespace *ns =
15398                 container_of(kref, struct user_namespace, kref);
15399  
15400 +       /* FIXME: maybe move into destroyer? */
15401 +       atomic_dec(&vs_global_user_ns);
15402         INIT_WORK(&ns->destroyer, free_user_ns_work);
15403         schedule_work(&ns->destroyer);
15404  }
15405 diff -NurpP --minimal linux-3.2.8/kernel/utsname.c linux-3.2.8-vs2.3.2.7/kernel/utsname.c
15406 --- linux-3.2.8/kernel/utsname.c        2012-01-09 16:15:00.000000000 +0100
15407 +++ linux-3.2.8-vs2.3.2.7/kernel/utsname.c      2011-12-05 19:33:02.000000000 +0100
15408 @@ -16,14 +16,17 @@
15409  #include <linux/slab.h>
15410  #include <linux/user_namespace.h>
15411  #include <linux/proc_fs.h>
15412 +#include <linux/vserver/global.h>
15413  
15414  static struct uts_namespace *create_uts_ns(void)
15415  {
15416         struct uts_namespace *uts_ns;
15417  
15418         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15419 -       if (uts_ns)
15420 +       if (uts_ns) {
15421                 kref_init(&uts_ns->kref);
15422 +               atomic_inc(&vs_global_uts_ns);
15423 +       }
15424         return uts_ns;
15425  }
15426  
15427 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15428   * @old_ns: namespace to clone
15429   * Return NULL on error (failure to kmalloc), new ns otherwise
15430   */
15431 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15432 -                                         struct uts_namespace *old_ns)
15433 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15434 +                                         struct user_namespace *old_user)
15435  {
15436         struct uts_namespace *ns;
15437  
15438 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15439  
15440         down_read(&uts_sem);
15441         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15442 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15443 +       ns->user_ns = get_user_ns(old_user);
15444         up_read(&uts_sem);
15445         return ns;
15446  }
15447 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15448   * versa.
15449   */
15450  struct uts_namespace *copy_utsname(unsigned long flags,
15451 -                                  struct task_struct *tsk)
15452 +                                  struct uts_namespace *old_ns,
15453 +                                  struct user_namespace *user_ns)
15454  {
15455 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15456         struct uts_namespace *new_ns;
15457  
15458         BUG_ON(!old_ns);
15459 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15460         if (!(flags & CLONE_NEWUTS))
15461                 return old_ns;
15462  
15463 -       new_ns = clone_uts_ns(tsk, old_ns);
15464 +       new_ns = clone_uts_ns(old_ns, user_ns);
15465  
15466         put_uts_ns(old_ns);
15467         return new_ns;
15468 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15469  
15470         ns = container_of(kref, struct uts_namespace, kref);
15471         put_user_ns(ns->user_ns);
15472 +       atomic_dec(&vs_global_uts_ns);
15473         kfree(ns);
15474  }
15475  
15476 diff -NurpP --minimal linux-3.2.8/kernel/vserver/Kconfig linux-3.2.8-vs2.3.2.7/kernel/vserver/Kconfig
15477 --- linux-3.2.8/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15478 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/Kconfig        2011-12-15 01:52:48.000000000 +0100
15479 @@ -0,0 +1,224 @@
15480 +#
15481 +# Linux VServer configuration
15482 +#
15483 +
15484 +menu "Linux VServer"
15485 +
15486 +config VSERVER_AUTO_LBACK
15487 +       bool    "Automatically Assign Loopback IP"
15488 +       default y
15489 +       help
15490 +         Automatically assign a guest specific loopback
15491 +         IP and add it to the kernel network stack on
15492 +         startup.
15493 +
15494 +config VSERVER_AUTO_SINGLE
15495 +       bool    "Automatic Single IP Special Casing"
15496 +       depends on EXPERIMENTAL
15497 +       default y
15498 +       help
15499 +         This allows network contexts with a single IP to
15500 +         automatically remap 0.0.0.0 bindings to that IP,
15501 +         avoiding further network checks and improving
15502 +         performance.
15503 +
15504 +         (note: such guests do not allow to change the ip
15505 +          on the fly and do not show loopback addresses)
15506 +
15507 +config VSERVER_COWBL
15508 +       bool    "Enable COW Immutable Link Breaking"
15509 +       default y
15510 +       help
15511 +         This enables the COW (Copy-On-Write) link break code.
15512 +         It allows you to treat unified files like normal files
15513 +         when writing to them (which will implicitely break the
15514 +         link and create a copy of the unified file)
15515 +
15516 +config VSERVER_VTIME
15517 +       bool    "Enable Virtualized Guest Time"
15518 +       depends on EXPERIMENTAL
15519 +       default n
15520 +       help
15521 +         This enables per guest time offsets to allow for
15522 +         adjusting the system clock individually per guest.
15523 +         this adds some overhead to the time functions and
15524 +         therefore should not be enabled without good reason.
15525 +
15526 +config VSERVER_DEVICE
15527 +       bool    "Enable Guest Device Mapping"
15528 +       depends on EXPERIMENTAL
15529 +       default n
15530 +       help
15531 +         This enables generic device remapping.
15532 +
15533 +config VSERVER_PROC_SECURE
15534 +       bool    "Enable Proc Security"
15535 +       depends on PROC_FS
15536 +       default y
15537 +       help
15538 +         This configures ProcFS security to initially hide
15539 +         non-process entries for all contexts except the main and
15540 +         spectator context (i.e. for all guests), which is a secure
15541 +         default.
15542 +
15543 +         (note: on 1.2x the entries were visible by default)
15544 +
15545 +choice
15546 +       prompt  "Persistent Inode Tagging"
15547 +       default TAGGING_ID24
15548 +       help
15549 +         This adds persistent context information to filesystems
15550 +         mounted with the tagxid option. Tagging is a requirement
15551 +         for per-context disk limits and per-context quota.
15552 +
15553 +
15554 +config TAGGING_NONE
15555 +       bool    "Disabled"
15556 +       help
15557 +         do not store per-context information in inodes.
15558 +
15559 +config TAGGING_UID16
15560 +       bool    "UID16/GID32"
15561 +       help
15562 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15563 +
15564 +config TAGGING_GID16
15565 +       bool    "UID32/GID16"
15566 +       help
15567 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15568 +
15569 +config TAGGING_ID24
15570 +       bool    "UID24/GID24"
15571 +       help
15572 +         uses the upper 8bit from UID and GID for XID tagging
15573 +         which leaves 24bit for UID/GID each, which should be
15574 +         more than sufficient for normal use.
15575 +
15576 +config TAGGING_INTERN
15577 +       bool    "UID32/GID32"
15578 +       help
15579 +         this uses otherwise reserved inode fields in the on
15580 +         disk representation, which limits the use to a few
15581 +         filesystems (currently ext2 and ext3)
15582 +
15583 +endchoice
15584 +
15585 +config TAG_NFSD
15586 +       bool    "Tag NFSD User Auth and Files"
15587 +       default n
15588 +       help
15589 +         Enable this if you do want the in-kernel NFS
15590 +         Server to use the tagging specified above.
15591 +         (will require patched clients too)
15592 +
15593 +config VSERVER_PRIVACY
15594 +       bool    "Honor Privacy Aspects of Guests"
15595 +       default n
15596 +       help
15597 +         When enabled, most context checks will disallow
15598 +         access to structures assigned to a specific context,
15599 +         like ptys or loop devices.
15600 +
15601 +config VSERVER_CONTEXTS
15602 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15603 +       range 1 65533
15604 +       default "768"   if 64BIT
15605 +       default "256"
15606 +       help
15607 +         This setting will optimize certain data structures
15608 +         and memory allocations according to the expected
15609 +         maximum.
15610 +
15611 +         note: this is not a strict upper limit.
15612 +
15613 +config VSERVER_WARN
15614 +       bool    "VServer Warnings"
15615 +       default y
15616 +       help
15617 +         This enables various runtime warnings, which will
15618 +         notify about potential manipulation attempts or
15619 +         resource shortage. It is generally considered to
15620 +         be a good idea to have that enabled.
15621 +
15622 +config VSERVER_WARN_DEVPTS
15623 +       bool    "VServer DevPTS Warnings"
15624 +       depends on VSERVER_WARN
15625 +       default y
15626 +       help
15627 +         This enables DevPTS related warnings, issued when a
15628 +         process inside a context tries to lookup or access
15629 +         a dynamic pts from the host or a different context.
15630 +
15631 +config VSERVER_DEBUG
15632 +       bool    "VServer Debugging Code"
15633 +       default n
15634 +       help
15635 +         Set this to yes if you want to be able to activate
15636 +         debugging output at runtime. It adds a very small
15637 +         overhead to all vserver related functions and
15638 +         increases the kernel size by about 20k.
15639 +
15640 +config VSERVER_HISTORY
15641 +       bool    "VServer History Tracing"
15642 +       depends on VSERVER_DEBUG
15643 +       default n
15644 +       help
15645 +         Set this to yes if you want to record the history of
15646 +         linux-vserver activities, so they can be replayed in
15647 +         the event of a kernel panic or oops.
15648 +
15649 +config VSERVER_HISTORY_SIZE
15650 +       int     "Per-CPU History Size (32-65536)"
15651 +       depends on VSERVER_HISTORY
15652 +       range 32 65536
15653 +       default 64
15654 +       help
15655 +         This allows you to specify the number of entries in
15656 +         the per-CPU history buffer.
15657 +
15658 +choice
15659 +       prompt  "Quotes used in debug and warn messages"
15660 +       default QUOTES_ISO8859
15661 +
15662 +config QUOTES_ISO8859
15663 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15664 +       help
15665 +         This uses the extended ASCII characters \xbb
15666 +         and \xab for quoting file and process names.
15667 +
15668 +config QUOTES_UTF8
15669 +       bool    "UTF-8 angle quotes"
15670 +       help
15671 +         This uses the the UTF-8 sequences for angle
15672 +         quotes to quote file and process names.
15673 +
15674 +config QUOTES_ASCII
15675 +       bool    "ASCII single quotes"
15676 +       help
15677 +         This uses the ASCII single quote character
15678 +         (\x27) to quote file and process names.
15679 +
15680 +endchoice
15681 +
15682 +endmenu
15683 +
15684 +
15685 +config VSERVER
15686 +       bool
15687 +       default y
15688 +       select NAMESPACES
15689 +       select UTS_NS
15690 +       select IPC_NS
15691 +#      select USER_NS
15692 +       select SYSVIPC
15693 +
15694 +config VSERVER_SECURITY
15695 +       bool
15696 +       depends on SECURITY
15697 +       default y
15698 +       select SECURITY_CAPABILITIES
15699 +
15700 +config VSERVER_DISABLED
15701 +       bool
15702 +       default n
15703 +
15704 diff -NurpP --minimal linux-3.2.8/kernel/vserver/Makefile linux-3.2.8-vs2.3.2.7/kernel/vserver/Makefile
15705 --- linux-3.2.8/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15706 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/Makefile       2011-12-05 19:33:02.000000000 +0100
15707 @@ -0,0 +1,18 @@
15708 +#
15709 +# Makefile for the Linux vserver routines.
15710 +#
15711 +
15712 +
15713 +obj-y          += vserver.o
15714 +
15715 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15716 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15717 +                  dlimit.o tag.o
15718 +
15719 +vserver-$(CONFIG_INET) += inet.o
15720 +vserver-$(CONFIG_PROC_FS) += proc.o
15721 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15722 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15723 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15724 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15725 +
15726 diff -NurpP --minimal linux-3.2.8/kernel/vserver/cacct.c linux-3.2.8-vs2.3.2.7/kernel/vserver/cacct.c
15727 --- linux-3.2.8/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15728 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/cacct.c        2011-12-05 19:33:02.000000000 +0100
15729 @@ -0,0 +1,42 @@
15730 +/*
15731 + *  linux/kernel/vserver/cacct.c
15732 + *
15733 + *  Virtual Server: Context Accounting
15734 + *
15735 + *  Copyright (C) 2006-2007 Herbert Pötzl
15736 + *
15737 + *  V0.01  added accounting stats
15738 + *
15739 + */
15740 +
15741 +#include <linux/types.h>
15742 +#include <linux/vs_context.h>
15743 +#include <linux/vserver/cacct_cmd.h>
15744 +#include <linux/vserver/cacct_int.h>
15745 +
15746 +#include <asm/errno.h>
15747 +#include <asm/uaccess.h>
15748 +
15749 +
15750 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15751 +{
15752 +       struct vcmd_sock_stat_v0 vc_data;
15753 +       int j, field;
15754 +
15755 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15756 +               return -EFAULT;
15757 +
15758 +       field = vc_data.field;
15759 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15760 +               return -EINVAL;
15761 +
15762 +       for (j = 0; j < 3; j++) {
15763 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15764 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15765 +       }
15766 +
15767 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15768 +               return -EFAULT;
15769 +       return 0;
15770 +}
15771 +
15772 diff -NurpP --minimal linux-3.2.8/kernel/vserver/cacct_init.h linux-3.2.8-vs2.3.2.7/kernel/vserver/cacct_init.h
15773 --- linux-3.2.8/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
15774 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/cacct_init.h   2011-12-05 19:33:02.000000000 +0100
15775 @@ -0,0 +1,25 @@
15776 +
15777 +
15778 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15779 +{
15780 +       int i, j;
15781 +
15782 +
15783 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15784 +               for (j = 0; j < 3; j++) {
15785 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15786 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15787 +               }
15788 +       }
15789 +       for (i = 0; i < 8; i++)
15790 +               atomic_set(&cacct->slab[i], 0);
15791 +       for (i = 0; i < 5; i++)
15792 +               for (j = 0; j < 4; j++)
15793 +                       atomic_set(&cacct->page[i][j], 0);
15794 +}
15795 +
15796 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15797 +{
15798 +       return;
15799 +}
15800 +
15801 diff -NurpP --minimal linux-3.2.8/kernel/vserver/cacct_proc.h linux-3.2.8-vs2.3.2.7/kernel/vserver/cacct_proc.h
15802 --- linux-3.2.8/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
15803 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/cacct_proc.h   2011-12-05 19:33:02.000000000 +0100
15804 @@ -0,0 +1,53 @@
15805 +#ifndef _VX_CACCT_PROC_H
15806 +#define _VX_CACCT_PROC_H
15807 +
15808 +#include <linux/vserver/cacct_int.h>
15809 +
15810 +
15811 +#define VX_SOCKA_TOP   \
15812 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15813 +
15814 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15815 +{
15816 +       int i, j, length = 0;
15817 +       static char *type[VXA_SOCK_SIZE] = {
15818 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15819 +       };
15820 +
15821 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15822 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15823 +               length += sprintf(buffer + length, "%s:", type[i]);
15824 +               for (j = 0; j < 3; j++) {
15825 +                       length += sprintf(buffer + length,
15826 +                               "\t%10lu/%-10lu",
15827 +                               vx_sock_count(cacct, i, j),
15828 +                               vx_sock_total(cacct, i, j));
15829 +               }
15830 +               buffer[length++] = '\n';
15831 +       }
15832 +
15833 +       length += sprintf(buffer + length, "\n");
15834 +       length += sprintf(buffer + length,
15835 +               "slab:\t %8u %8u %8u %8u\n",
15836 +               atomic_read(&cacct->slab[1]),
15837 +               atomic_read(&cacct->slab[4]),
15838 +               atomic_read(&cacct->slab[0]),
15839 +               atomic_read(&cacct->slab[2]));
15840 +
15841 +       length += sprintf(buffer + length, "\n");
15842 +       for (i = 0; i < 5; i++) {
15843 +               length += sprintf(buffer + length,
15844 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15845 +                       atomic_read(&cacct->page[i][0]),
15846 +                       atomic_read(&cacct->page[i][1]),
15847 +                       atomic_read(&cacct->page[i][2]),
15848 +                       atomic_read(&cacct->page[i][3]),
15849 +                       atomic_read(&cacct->page[i][4]),
15850 +                       atomic_read(&cacct->page[i][5]),
15851 +                       atomic_read(&cacct->page[i][6]),
15852 +                       atomic_read(&cacct->page[i][7]));
15853 +       }
15854 +       return length;
15855 +}
15856 +
15857 +#endif /* _VX_CACCT_PROC_H */
15858 diff -NurpP --minimal linux-3.2.8/kernel/vserver/context.c linux-3.2.8-vs2.3.2.7/kernel/vserver/context.c
15859 --- linux-3.2.8/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
15860 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/context.c      2011-12-05 19:33:02.000000000 +0100
15861 @@ -0,0 +1,1107 @@
15862 +/*
15863 + *  linux/kernel/vserver/context.c
15864 + *
15865 + *  Virtual Server: Context Support
15866 + *
15867 + *  Copyright (C) 2003-2011  Herbert Pötzl
15868 + *
15869 + *  V0.01  context helper
15870 + *  V0.02  vx_ctx_kill syscall command
15871 + *  V0.03  replaced context_info calls
15872 + *  V0.04  redesign of struct (de)alloc
15873 + *  V0.05  rlimit basic implementation
15874 + *  V0.06  task_xid and info commands
15875 + *  V0.07  context flags and caps
15876 + *  V0.08  switch to RCU based hash
15877 + *  V0.09  revert to non RCU for now
15878 + *  V0.10  and back to working RCU hash
15879 + *  V0.11  and back to locking again
15880 + *  V0.12  referenced context store
15881 + *  V0.13  separate per cpu data
15882 + *  V0.14  changed vcmds to vxi arg
15883 + *  V0.15  added context stat
15884 + *  V0.16  have __create claim() the vxi
15885 + *  V0.17  removed older and legacy stuff
15886 + *  V0.18  added user credentials
15887 + *  V0.19  added warn mask
15888 + *
15889 + */
15890 +
15891 +#include <linux/slab.h>
15892 +#include <linux/types.h>
15893 +#include <linux/security.h>
15894 +#include <linux/pid_namespace.h>
15895 +#include <linux/capability.h>
15896 +
15897 +#include <linux/vserver/context.h>
15898 +#include <linux/vserver/network.h>
15899 +#include <linux/vserver/debug.h>
15900 +#include <linux/vserver/limit.h>
15901 +#include <linux/vserver/limit_int.h>
15902 +#include <linux/vserver/space.h>
15903 +#include <linux/init_task.h>
15904 +#include <linux/fs_struct.h>
15905 +#include <linux/cred.h>
15906 +
15907 +#include <linux/vs_context.h>
15908 +#include <linux/vs_limit.h>
15909 +#include <linux/vs_pid.h>
15910 +#include <linux/vserver/context_cmd.h>
15911 +
15912 +#include "cvirt_init.h"
15913 +#include "cacct_init.h"
15914 +#include "limit_init.h"
15915 +#include "sched_init.h"
15916 +
15917 +
15918 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15919 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15920 +
15921 +
15922 +/*     now inactive context structures */
15923 +
15924 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15925 +
15926 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15927 +
15928 +
15929 +/*     __alloc_vx_info()
15930 +
15931 +       * allocate an initialized vx_info struct
15932 +       * doesn't make it visible (hash)                        */
15933 +
15934 +static struct vx_info *__alloc_vx_info(xid_t xid)
15935 +{
15936 +       struct vx_info *new = NULL;
15937 +       int cpu, index;
15938 +
15939 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15940 +
15941 +       /* would this benefit from a slab cache? */
15942 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15943 +       if (!new)
15944 +               return 0;
15945 +
15946 +       memset(new, 0, sizeof(struct vx_info));
15947 +#ifdef CONFIG_SMP
15948 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15949 +       if (!new->ptr_pc)
15950 +               goto error;
15951 +#endif
15952 +       new->vx_id = xid;
15953 +       INIT_HLIST_NODE(&new->vx_hlist);
15954 +       atomic_set(&new->vx_usecnt, 0);
15955 +       atomic_set(&new->vx_tasks, 0);
15956 +       new->vx_parent = NULL;
15957 +       new->vx_state = 0;
15958 +       init_waitqueue_head(&new->vx_wait);
15959 +
15960 +       /* prepare reaper */
15961 +       get_task_struct(init_pid_ns.child_reaper);
15962 +       new->vx_reaper = init_pid_ns.child_reaper;
15963 +       new->vx_badness_bias = 0;
15964 +
15965 +       /* rest of init goes here */
15966 +       vx_info_init_limit(&new->limit);
15967 +       vx_info_init_sched(&new->sched);
15968 +       vx_info_init_cvirt(&new->cvirt);
15969 +       vx_info_init_cacct(&new->cacct);
15970 +
15971 +       /* per cpu data structures */
15972 +       for_each_possible_cpu(cpu) {
15973 +               vx_info_init_sched_pc(
15974 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15975 +               vx_info_init_cvirt_pc(
15976 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15977 +       }
15978 +
15979 +       new->vx_flags = VXF_INIT_SET;
15980 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15981 +       new->vx_ccaps = 0;
15982 +       new->vx_umask = 0;
15983 +       new->vx_wmask = 0;
15984 +
15985 +       new->reboot_cmd = 0;
15986 +       new->exit_code = 0;
15987 +
15988 +       // preconfig spaces
15989 +       for (index = 0; index < VX_SPACES; index++) {
15990 +               struct _vx_space *space = &new->space[index];
15991 +
15992 +               // filesystem
15993 +               spin_lock(&init_fs.lock);
15994 +               init_fs.users++;
15995 +               spin_unlock(&init_fs.lock);
15996 +               space->vx_fs = &init_fs;
15997 +
15998 +               /* FIXME: do we want defaults? */
15999 +               // space->vx_real_cred = 0;
16000 +               // space->vx_cred = 0;
16001 +       }
16002 +
16003 +
16004 +       vxdprintk(VXD_CBIT(xid, 0),
16005 +               "alloc_vx_info(%d) = %p", xid, new);
16006 +       vxh_alloc_vx_info(new);
16007 +       atomic_inc(&vx_global_ctotal);
16008 +       return new;
16009 +#ifdef CONFIG_SMP
16010 +error:
16011 +       kfree(new);
16012 +       return 0;
16013 +#endif
16014 +}
16015 +
16016 +/*     __dealloc_vx_info()
16017 +
16018 +       * final disposal of vx_info                             */
16019 +
16020 +static void __dealloc_vx_info(struct vx_info *vxi)
16021 +{
16022 +#ifdef CONFIG_VSERVER_WARN
16023 +       struct vx_info_save vxis;
16024 +       int cpu;
16025 +#endif
16026 +       vxdprintk(VXD_CBIT(xid, 0),
16027 +               "dealloc_vx_info(%p)", vxi);
16028 +       vxh_dealloc_vx_info(vxi);
16029 +
16030 +#ifdef CONFIG_VSERVER_WARN
16031 +       enter_vx_info(vxi, &vxis);
16032 +       vx_info_exit_limit(&vxi->limit);
16033 +       vx_info_exit_sched(&vxi->sched);
16034 +       vx_info_exit_cvirt(&vxi->cvirt);
16035 +       vx_info_exit_cacct(&vxi->cacct);
16036 +
16037 +       for_each_possible_cpu(cpu) {
16038 +               vx_info_exit_sched_pc(
16039 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16040 +               vx_info_exit_cvirt_pc(
16041 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16042 +       }
16043 +       leave_vx_info(&vxis);
16044 +#endif
16045 +
16046 +       vxi->vx_id = -1;
16047 +       vxi->vx_state |= VXS_RELEASED;
16048 +
16049 +#ifdef CONFIG_SMP
16050 +       free_percpu(vxi->ptr_pc);
16051 +#endif
16052 +       kfree(vxi);
16053 +       atomic_dec(&vx_global_ctotal);
16054 +}
16055 +
16056 +static void __shutdown_vx_info(struct vx_info *vxi)
16057 +{
16058 +       struct nsproxy *nsproxy;
16059 +       struct fs_struct *fs;
16060 +       struct cred *cred;
16061 +       int index, kill;
16062 +
16063 +       might_sleep();
16064 +
16065 +       vxi->vx_state |= VXS_SHUTDOWN;
16066 +       vs_state_change(vxi, VSC_SHUTDOWN);
16067 +
16068 +       for (index = 0; index < VX_SPACES; index++) {
16069 +               struct _vx_space *space = &vxi->space[index];
16070 +
16071 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16072 +               if (nsproxy)
16073 +                       put_nsproxy(nsproxy);
16074 +
16075 +               fs = xchg(&space->vx_fs, NULL);
16076 +               spin_lock(&fs->lock);
16077 +               kill = !--fs->users;
16078 +               spin_unlock(&fs->lock);
16079 +               if (kill)
16080 +                       free_fs_struct(fs);
16081 +
16082 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16083 +               if (cred)
16084 +                       abort_creds(cred);
16085 +       }
16086 +}
16087 +
16088 +/* exported stuff */
16089 +
16090 +void free_vx_info(struct vx_info *vxi)
16091 +{
16092 +       unsigned long flags;
16093 +       unsigned index;
16094 +
16095 +       /* check for reference counts first */
16096 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16097 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16098 +
16099 +       /* context must not be hashed */
16100 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16101 +
16102 +       /* context shutdown is mandatory */
16103 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16104 +
16105 +       /* spaces check */
16106 +       for (index = 0; index < VX_SPACES; index++) {
16107 +               struct _vx_space *space = &vxi->space[index];
16108 +
16109 +               BUG_ON(space->vx_nsproxy);
16110 +               BUG_ON(space->vx_fs);
16111 +               // BUG_ON(space->vx_real_cred);
16112 +               // BUG_ON(space->vx_cred);
16113 +       }
16114 +
16115 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16116 +       hlist_del(&vxi->vx_hlist);
16117 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16118 +
16119 +       __dealloc_vx_info(vxi);
16120 +}
16121 +
16122 +
16123 +/*     hash table for vx_info hash */
16124 +
16125 +#define VX_HASH_SIZE   13
16126 +
16127 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16128 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16129 +
16130 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16131 +
16132 +
16133 +static inline unsigned int __hashval(xid_t xid)
16134 +{
16135 +       return (xid % VX_HASH_SIZE);
16136 +}
16137 +
16138 +
16139 +
16140 +/*     __hash_vx_info()
16141 +
16142 +       * add the vxi to the global hash table
16143 +       * requires the hash_lock to be held                     */
16144 +
16145 +static inline void __hash_vx_info(struct vx_info *vxi)
16146 +{
16147 +       struct hlist_head *head;
16148 +
16149 +       vxd_assert_lock(&vx_info_hash_lock);
16150 +       vxdprintk(VXD_CBIT(xid, 4),
16151 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16152 +       vxh_hash_vx_info(vxi);
16153 +
16154 +       /* context must not be hashed */
16155 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16156 +
16157 +       vxi->vx_state |= VXS_HASHED;
16158 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16159 +       hlist_add_head(&vxi->vx_hlist, head);
16160 +       atomic_inc(&vx_global_cactive);
16161 +}
16162 +
16163 +/*     __unhash_vx_info()
16164 +
16165 +       * remove the vxi from the global hash table
16166 +       * requires the hash_lock to be held                     */
16167 +
16168 +static inline void __unhash_vx_info(struct vx_info *vxi)
16169 +{
16170 +       unsigned long flags;
16171 +
16172 +       vxd_assert_lock(&vx_info_hash_lock);
16173 +       vxdprintk(VXD_CBIT(xid, 4),
16174 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16175 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16176 +       vxh_unhash_vx_info(vxi);
16177 +
16178 +       /* context must be hashed */
16179 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16180 +       /* but without tasks */
16181 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16182 +
16183 +       vxi->vx_state &= ~VXS_HASHED;
16184 +       hlist_del_init(&vxi->vx_hlist);
16185 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16186 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16187 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16188 +       atomic_dec(&vx_global_cactive);
16189 +}
16190 +
16191 +
16192 +/*     __lookup_vx_info()
16193 +
16194 +       * requires the hash_lock to be held
16195 +       * doesn't increment the vx_refcnt                       */
16196 +
16197 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16198 +{
16199 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16200 +       struct hlist_node *pos;
16201 +       struct vx_info *vxi;
16202 +
16203 +       vxd_assert_lock(&vx_info_hash_lock);
16204 +       hlist_for_each(pos, head) {
16205 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16206 +
16207 +               if (vxi->vx_id == xid)
16208 +                       goto found;
16209 +       }
16210 +       vxi = NULL;
16211 +found:
16212 +       vxdprintk(VXD_CBIT(xid, 0),
16213 +               "__lookup_vx_info(#%u): %p[#%u]",
16214 +               xid, vxi, vxi ? vxi->vx_id : 0);
16215 +       vxh_lookup_vx_info(vxi, xid);
16216 +       return vxi;
16217 +}
16218 +
16219 +
16220 +/*     __create_vx_info()
16221 +
16222 +       * create the requested context
16223 +       * get(), claim() and hash it                            */
16224 +
16225 +static struct vx_info *__create_vx_info(int id)
16226 +{
16227 +       struct vx_info *new, *vxi = NULL;
16228 +
16229 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16230 +
16231 +       if (!(new = __alloc_vx_info(id)))
16232 +               return ERR_PTR(-ENOMEM);
16233 +
16234 +       /* required to make dynamic xids unique */
16235 +       spin_lock(&vx_info_hash_lock);
16236 +
16237 +       /* static context requested */
16238 +       if ((vxi = __lookup_vx_info(id))) {
16239 +               vxdprintk(VXD_CBIT(xid, 0),
16240 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16241 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16242 +                       vxi = ERR_PTR(-EBUSY);
16243 +               else
16244 +                       vxi = ERR_PTR(-EEXIST);
16245 +               goto out_unlock;
16246 +       }
16247 +       /* new context */
16248 +       vxdprintk(VXD_CBIT(xid, 0),
16249 +               "create_vx_info(%d) = %p (new)", id, new);
16250 +       claim_vx_info(new, NULL);
16251 +       __hash_vx_info(get_vx_info(new));
16252 +       vxi = new, new = NULL;
16253 +
16254 +out_unlock:
16255 +       spin_unlock(&vx_info_hash_lock);
16256 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16257 +       if (new)
16258 +               __dealloc_vx_info(new);
16259 +       return vxi;
16260 +}
16261 +
16262 +
16263 +/*     exported stuff                                          */
16264 +
16265 +
16266 +void unhash_vx_info(struct vx_info *vxi)
16267 +{
16268 +       spin_lock(&vx_info_hash_lock);
16269 +       __unhash_vx_info(vxi);
16270 +       spin_unlock(&vx_info_hash_lock);
16271 +       __shutdown_vx_info(vxi);
16272 +       __wakeup_vx_info(vxi);
16273 +}
16274 +
16275 +
16276 +/*     lookup_vx_info()
16277 +
16278 +       * search for a vx_info and get() it
16279 +       * negative id means current                             */
16280 +
16281 +struct vx_info *lookup_vx_info(int id)
16282 +{
16283 +       struct vx_info *vxi = NULL;
16284 +
16285 +       if (id < 0) {
16286 +               vxi = get_vx_info(current_vx_info());
16287 +       } else if (id > 1) {
16288 +               spin_lock(&vx_info_hash_lock);
16289 +               vxi = get_vx_info(__lookup_vx_info(id));
16290 +               spin_unlock(&vx_info_hash_lock);
16291 +       }
16292 +       return vxi;
16293 +}
16294 +
16295 +/*     xid_is_hashed()
16296 +
16297 +       * verify that xid is still hashed                       */
16298 +
16299 +int xid_is_hashed(xid_t xid)
16300 +{
16301 +       int hashed;
16302 +
16303 +       spin_lock(&vx_info_hash_lock);
16304 +       hashed = (__lookup_vx_info(xid) != NULL);
16305 +       spin_unlock(&vx_info_hash_lock);
16306 +       return hashed;
16307 +}
16308 +
16309 +#ifdef CONFIG_PROC_FS
16310 +
16311 +/*     get_xid_list()
16312 +
16313 +       * get a subset of hashed xids for proc
16314 +       * assumes size is at least one                          */
16315 +
16316 +int get_xid_list(int index, unsigned int *xids, int size)
16317 +{
16318 +       int hindex, nr_xids = 0;
16319 +
16320 +       /* only show current and children */
16321 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16322 +               if (index > 0)
16323 +                       return 0;
16324 +               xids[nr_xids] = vx_current_xid();
16325 +               return 1;
16326 +       }
16327 +
16328 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16329 +               struct hlist_head *head = &vx_info_hash[hindex];
16330 +               struct hlist_node *pos;
16331 +
16332 +               spin_lock(&vx_info_hash_lock);
16333 +               hlist_for_each(pos, head) {
16334 +                       struct vx_info *vxi;
16335 +
16336 +                       if (--index > 0)
16337 +                               continue;
16338 +
16339 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16340 +                       xids[nr_xids] = vxi->vx_id;
16341 +                       if (++nr_xids >= size) {
16342 +                               spin_unlock(&vx_info_hash_lock);
16343 +                               goto out;
16344 +                       }
16345 +               }
16346 +               /* keep the lock time short */
16347 +               spin_unlock(&vx_info_hash_lock);
16348 +       }
16349 +out:
16350 +       return nr_xids;
16351 +}
16352 +#endif
16353 +
16354 +#ifdef CONFIG_VSERVER_DEBUG
16355 +
16356 +void   dump_vx_info_inactive(int level)
16357 +{
16358 +       struct hlist_node *entry, *next;
16359 +
16360 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16361 +               struct vx_info *vxi =
16362 +                       list_entry(entry, struct vx_info, vx_hlist);
16363 +
16364 +               dump_vx_info(vxi, level);
16365 +       }
16366 +}
16367 +
16368 +#endif
16369 +
16370 +#if 0
16371 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16372 +{
16373 +       struct user_struct *new_user, *old_user;
16374 +
16375 +       if (!p || !vxi)
16376 +               BUG();
16377 +
16378 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16379 +               return -EACCES;
16380 +
16381 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16382 +       if (!new_user)
16383 +               return -ENOMEM;
16384 +
16385 +       old_user = p->user;
16386 +       if (new_user != old_user) {
16387 +               atomic_inc(&new_user->processes);
16388 +               atomic_dec(&old_user->processes);
16389 +               p->user = new_user;
16390 +       }
16391 +       free_uid(old_user);
16392 +       return 0;
16393 +}
16394 +#endif
16395 +
16396 +#if 0
16397 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16398 +{
16399 +       // p->cap_effective &= vxi->vx_cap_bset;
16400 +       p->cap_effective =
16401 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16402 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16403 +       p->cap_inheritable =
16404 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16405 +       // p->cap_permitted &= vxi->vx_cap_bset;
16406 +       p->cap_permitted =
16407 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16408 +}
16409 +#endif
16410 +
16411 +
16412 +#include <linux/file.h>
16413 +#include <linux/fdtable.h>
16414 +
16415 +static int vx_openfd_task(struct task_struct *tsk)
16416 +{
16417 +       struct files_struct *files = tsk->files;
16418 +       struct fdtable *fdt;
16419 +       const unsigned long *bptr;
16420 +       int count, total;
16421 +
16422 +       /* no rcu_read_lock() because of spin_lock() */
16423 +       spin_lock(&files->file_lock);
16424 +       fdt = files_fdtable(files);
16425 +       bptr = fdt->open_fds->fds_bits;
16426 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16427 +       for (total = 0; count > 0; count--) {
16428 +               if (*bptr)
16429 +                       total += hweight_long(*bptr);
16430 +               bptr++;
16431 +       }
16432 +       spin_unlock(&files->file_lock);
16433 +       return total;
16434 +}
16435 +
16436 +
16437 +/*     for *space compatibility */
16438 +
16439 +asmlinkage long sys_unshare(unsigned long);
16440 +
16441 +/*
16442 + *     migrate task to new context
16443 + *     gets vxi, puts old_vxi on change
16444 + *     optionally unshares namespaces (hack)
16445 + */
16446 +
16447 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16448 +{
16449 +       struct vx_info *old_vxi;
16450 +       int ret = 0;
16451 +
16452 +       if (!p || !vxi)
16453 +               BUG();
16454 +
16455 +       vxdprintk(VXD_CBIT(xid, 5),
16456 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16457 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16458 +
16459 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16460 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16461 +               return -EACCES;
16462 +
16463 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16464 +               return -EFAULT;
16465 +
16466 +       old_vxi = task_get_vx_info(p);
16467 +       if (old_vxi == vxi)
16468 +               goto out;
16469 +
16470 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16471 +       {
16472 +               int openfd;
16473 +
16474 +               task_lock(p);
16475 +               openfd = vx_openfd_task(p);
16476 +
16477 +               if (old_vxi) {
16478 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16479 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16480 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16481 +                       /* FIXME: what about the struct files here? */
16482 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16483 +                       /* account for the executable */
16484 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16485 +               }
16486 +               atomic_inc(&vxi->cvirt.nr_threads);
16487 +               atomic_inc(&vxi->cvirt.nr_running);
16488 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16489 +               /* FIXME: what about the struct files here? */
16490 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16491 +               /* account for the executable */
16492 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16493 +
16494 +               if (old_vxi) {
16495 +                       release_vx_info(old_vxi, p);
16496 +                       clr_vx_info(&p->vx_info);
16497 +               }
16498 +               claim_vx_info(vxi, p);
16499 +               set_vx_info(&p->vx_info, vxi);
16500 +               p->xid = vxi->vx_id;
16501 +
16502 +               vxdprintk(VXD_CBIT(xid, 5),
16503 +                       "moved task %p into vxi:%p[#%d]",
16504 +                       p, vxi, vxi->vx_id);
16505 +
16506 +               // vx_mask_cap_bset(vxi, p);
16507 +               task_unlock(p);
16508 +
16509 +               /* hack for *spaces to provide compatibility */
16510 +               if (unshare) {
16511 +                       struct nsproxy *old_nsp, *new_nsp;
16512 +
16513 +                       ret = unshare_nsproxy_namespaces(
16514 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16515 +                               &new_nsp, NULL);
16516 +                       if (ret)
16517 +                               goto out;
16518 +
16519 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16520 +                       vx_set_space(vxi,
16521 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16522 +                       put_nsproxy(old_nsp);
16523 +               }
16524 +       }
16525 +out:
16526 +       put_vx_info(old_vxi);
16527 +       return ret;
16528 +}
16529 +
16530 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16531 +{
16532 +       struct task_struct *old_reaper;
16533 +
16534 +       if (!vxi)
16535 +               return -EINVAL;
16536 +
16537 +       vxdprintk(VXD_CBIT(xid, 6),
16538 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16539 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16540 +
16541 +       old_reaper = vxi->vx_reaper;
16542 +       if (old_reaper == p)
16543 +               return 0;
16544 +
16545 +       /* set new child reaper */
16546 +       get_task_struct(p);
16547 +       vxi->vx_reaper = p;
16548 +       put_task_struct(old_reaper);
16549 +       return 0;
16550 +}
16551 +
16552 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16553 +{
16554 +       if (!vxi)
16555 +               return -EINVAL;
16556 +
16557 +       vxdprintk(VXD_CBIT(xid, 6),
16558 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16559 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16560 +
16561 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16562 +       // vxi->vx_initpid = p->tgid;
16563 +       vxi->vx_initpid = p->pid;
16564 +       return 0;
16565 +}
16566 +
16567 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16568 +{
16569 +       vxdprintk(VXD_CBIT(xid, 6),
16570 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16571 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16572 +
16573 +       vxi->exit_code = code;
16574 +       vxi->vx_initpid = 0;
16575 +}
16576 +
16577 +
16578 +void vx_set_persistent(struct vx_info *vxi)
16579 +{
16580 +       vxdprintk(VXD_CBIT(xid, 6),
16581 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16582 +
16583 +       get_vx_info(vxi);
16584 +       claim_vx_info(vxi, NULL);
16585 +}
16586 +
16587 +void vx_clear_persistent(struct vx_info *vxi)
16588 +{
16589 +       vxdprintk(VXD_CBIT(xid, 6),
16590 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16591 +
16592 +       release_vx_info(vxi, NULL);
16593 +       put_vx_info(vxi);
16594 +}
16595 +
16596 +void vx_update_persistent(struct vx_info *vxi)
16597 +{
16598 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16599 +               vx_set_persistent(vxi);
16600 +       else
16601 +               vx_clear_persistent(vxi);
16602 +}
16603 +
16604 +
16605 +/*     task must be current or locked          */
16606 +
16607 +void   exit_vx_info(struct task_struct *p, int code)
16608 +{
16609 +       struct vx_info *vxi = p->vx_info;
16610 +
16611 +       if (vxi) {
16612 +               atomic_dec(&vxi->cvirt.nr_threads);
16613 +               vx_nproc_dec(p);
16614 +
16615 +               vxi->exit_code = code;
16616 +               release_vx_info(vxi, p);
16617 +       }
16618 +}
16619 +
16620 +void   exit_vx_info_early(struct task_struct *p, int code)
16621 +{
16622 +       struct vx_info *vxi = p->vx_info;
16623 +
16624 +       if (vxi) {
16625 +               if (vxi->vx_initpid == p->pid)
16626 +                       vx_exit_init(vxi, p, code);
16627 +               if (vxi->vx_reaper == p)
16628 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16629 +       }
16630 +}
16631 +
16632 +
16633 +/* vserver syscall commands below here */
16634 +
16635 +/* taks xid and vx_info functions */
16636 +
16637 +#include <asm/uaccess.h>
16638 +
16639 +
16640 +int vc_task_xid(uint32_t id)
16641 +{
16642 +       xid_t xid;
16643 +
16644 +       if (id) {
16645 +               struct task_struct *tsk;
16646 +
16647 +               rcu_read_lock();
16648 +               tsk = find_task_by_real_pid(id);
16649 +               xid = (tsk) ? tsk->xid : -ESRCH;
16650 +               rcu_read_unlock();
16651 +       } else
16652 +               xid = vx_current_xid();
16653 +       return xid;
16654 +}
16655 +
16656 +
16657 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16658 +{
16659 +       struct vcmd_vx_info_v0 vc_data;
16660 +
16661 +       vc_data.xid = vxi->vx_id;
16662 +       vc_data.initpid = vxi->vx_initpid;
16663 +
16664 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16665 +               return -EFAULT;
16666 +       return 0;
16667 +}
16668 +
16669 +
16670 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16671 +{
16672 +       struct vcmd_ctx_stat_v0 vc_data;
16673 +
16674 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16675 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16676 +
16677 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16678 +               return -EFAULT;
16679 +       return 0;
16680 +}
16681 +
16682 +
16683 +/* context functions */
16684 +
16685 +int vc_ctx_create(uint32_t xid, void __user *data)
16686 +{
16687 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16688 +       struct vx_info *new_vxi;
16689 +       int ret;
16690 +
16691 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16692 +               return -EFAULT;
16693 +
16694 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16695 +               return -EINVAL;
16696 +
16697 +       new_vxi = __create_vx_info(xid);
16698 +       if (IS_ERR(new_vxi))
16699 +               return PTR_ERR(new_vxi);
16700 +
16701 +       /* initial flags */
16702 +       new_vxi->vx_flags = vc_data.flagword;
16703 +
16704 +       ret = -ENOEXEC;
16705 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16706 +               goto out;
16707 +
16708 +       ret = vx_migrate_task(current, new_vxi, (!data));
16709 +       if (ret)
16710 +               goto out;
16711 +
16712 +       /* return context id on success */
16713 +       ret = new_vxi->vx_id;
16714 +
16715 +       /* get a reference for persistent contexts */
16716 +       if ((vc_data.flagword & VXF_PERSISTENT))
16717 +               vx_set_persistent(new_vxi);
16718 +out:
16719 +       release_vx_info(new_vxi, NULL);
16720 +       put_vx_info(new_vxi);
16721 +       return ret;
16722 +}
16723 +
16724 +
16725 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16726 +{
16727 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16728 +       int ret;
16729 +
16730 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16731 +               return -EFAULT;
16732 +
16733 +       ret = vx_migrate_task(current, vxi, 0);
16734 +       if (ret)
16735 +               return ret;
16736 +       if (vc_data.flagword & VXM_SET_INIT)
16737 +               ret = vx_set_init(vxi, current);
16738 +       if (ret)
16739 +               return ret;
16740 +       if (vc_data.flagword & VXM_SET_REAPER)
16741 +               ret = vx_set_reaper(vxi, current);
16742 +       return ret;
16743 +}
16744 +
16745 +
16746 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16747 +{
16748 +       struct vcmd_ctx_flags_v0 vc_data;
16749 +
16750 +       vc_data.flagword = vxi->vx_flags;
16751 +
16752 +       /* special STATE flag handling */
16753 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16754 +
16755 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16756 +               return -EFAULT;
16757 +       return 0;
16758 +}
16759 +
16760 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16761 +{
16762 +       struct vcmd_ctx_flags_v0 vc_data;
16763 +       uint64_t mask, trigger;
16764 +
16765 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16766 +               return -EFAULT;
16767 +
16768 +       /* special STATE flag handling */
16769 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16770 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16771 +
16772 +       if (vxi == current_vx_info()) {
16773 +               /* if (trigger & VXF_STATE_SETUP)
16774 +                       vx_mask_cap_bset(vxi, current); */
16775 +               if (trigger & VXF_STATE_INIT) {
16776 +                       int ret;
16777 +
16778 +                       ret = vx_set_init(vxi, current);
16779 +                       if (ret)
16780 +                               return ret;
16781 +                       ret = vx_set_reaper(vxi, current);
16782 +                       if (ret)
16783 +                               return ret;
16784 +               }
16785 +       }
16786 +
16787 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16788 +               vc_data.flagword, mask);
16789 +       if (trigger & VXF_PERSISTENT)
16790 +               vx_update_persistent(vxi);
16791 +
16792 +       return 0;
16793 +}
16794 +
16795 +
16796 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16797 +{
16798 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16799 +
16800 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16801 +       return v;
16802 +}
16803 +
16804 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16805 +{
16806 +       kernel_cap_t c = __cap_empty_set;
16807 +
16808 +       c.cap[0] = v & 0xFFFFFFFF;
16809 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16810 +
16811 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16812 +       return c;
16813 +}
16814 +
16815 +
16816 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16817 +{
16818 +       if (bcaps)
16819 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16820 +       if (ccaps)
16821 +               *ccaps = vxi->vx_ccaps;
16822 +
16823 +       return 0;
16824 +}
16825 +
16826 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16827 +{
16828 +       struct vcmd_ctx_caps_v1 vc_data;
16829 +       int ret;
16830 +
16831 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16832 +       if (ret)
16833 +               return ret;
16834 +       vc_data.cmask = ~0ULL;
16835 +
16836 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16837 +               return -EFAULT;
16838 +       return 0;
16839 +}
16840 +
16841 +static int do_set_caps(struct vx_info *vxi,
16842 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16843 +{
16844 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16845 +
16846 +#if 0
16847 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16848 +               bcaps, bmask, ccaps, cmask);
16849 +#endif
16850 +       vxi->vx_bcaps = cap_t_from_caps(
16851 +               vs_mask_flags(bcold, bcaps, bmask));
16852 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16853 +
16854 +       return 0;
16855 +}
16856 +
16857 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16858 +{
16859 +       struct vcmd_ctx_caps_v1 vc_data;
16860 +
16861 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16862 +               return -EFAULT;
16863 +
16864 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16865 +}
16866 +
16867 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16868 +{
16869 +       struct vcmd_bcaps vc_data;
16870 +       int ret;
16871 +
16872 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16873 +       if (ret)
16874 +               return ret;
16875 +       vc_data.bmask = ~0ULL;
16876 +
16877 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16878 +               return -EFAULT;
16879 +       return 0;
16880 +}
16881 +
16882 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16883 +{
16884 +       struct vcmd_bcaps vc_data;
16885 +
16886 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16887 +               return -EFAULT;
16888 +
16889 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16890 +}
16891 +
16892 +
16893 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16894 +{
16895 +       struct vcmd_umask vc_data;
16896 +
16897 +       vc_data.umask = vxi->vx_umask;
16898 +       vc_data.mask = ~0ULL;
16899 +
16900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16901 +               return -EFAULT;
16902 +       return 0;
16903 +}
16904 +
16905 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16906 +{
16907 +       struct vcmd_umask vc_data;
16908 +
16909 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16910 +               return -EFAULT;
16911 +
16912 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16913 +               vc_data.umask, vc_data.mask);
16914 +       return 0;
16915 +}
16916 +
16917 +
16918 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16919 +{
16920 +       struct vcmd_wmask vc_data;
16921 +
16922 +       vc_data.wmask = vxi->vx_wmask;
16923 +       vc_data.mask = ~0ULL;
16924 +
16925 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16926 +               return -EFAULT;
16927 +       return 0;
16928 +}
16929 +
16930 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16931 +{
16932 +       struct vcmd_wmask vc_data;
16933 +
16934 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16935 +               return -EFAULT;
16936 +
16937 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16938 +               vc_data.wmask, vc_data.mask);
16939 +       return 0;
16940 +}
16941 +
16942 +
16943 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16944 +{
16945 +       struct vcmd_badness_v0 vc_data;
16946 +
16947 +       vc_data.bias = vxi->vx_badness_bias;
16948 +
16949 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16950 +               return -EFAULT;
16951 +       return 0;
16952 +}
16953 +
16954 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16955 +{
16956 +       struct vcmd_badness_v0 vc_data;
16957 +
16958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16959 +               return -EFAULT;
16960 +
16961 +       vxi->vx_badness_bias = vc_data.bias;
16962 +       return 0;
16963 +}
16964 +
16965 +#include <linux/module.h>
16966 +
16967 +EXPORT_SYMBOL_GPL(free_vx_info);
16968 +
16969 diff -NurpP --minimal linux-3.2.8/kernel/vserver/cvirt.c linux-3.2.8-vs2.3.2.7/kernel/vserver/cvirt.c
16970 --- linux-3.2.8/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
16971 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/cvirt.c        2011-12-05 19:33:02.000000000 +0100
16972 @@ -0,0 +1,303 @@
16973 +/*
16974 + *  linux/kernel/vserver/cvirt.c
16975 + *
16976 + *  Virtual Server: Context Virtualization
16977 + *
16978 + *  Copyright (C) 2004-2007  Herbert Pötzl
16979 + *
16980 + *  V0.01  broken out from limit.c
16981 + *  V0.02  added utsname stuff
16982 + *  V0.03  changed vcmds to vxi arg
16983 + *
16984 + */
16985 +
16986 +#include <linux/types.h>
16987 +#include <linux/utsname.h>
16988 +#include <linux/vs_cvirt.h>
16989 +#include <linux/vserver/switch.h>
16990 +#include <linux/vserver/cvirt_cmd.h>
16991 +
16992 +#include <asm/uaccess.h>
16993 +
16994 +
16995 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16996 +{
16997 +       struct vx_info *vxi = current_vx_info();
16998 +
16999 +       set_normalized_timespec(uptime,
17000 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17001 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17002 +       if (!idle)
17003 +               return;
17004 +       set_normalized_timespec(idle,
17005 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17006 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17007 +       return;
17008 +}
17009 +
17010 +uint64_t vx_idle_jiffies(void)
17011 +{
17012 +       return init_task.utime + init_task.stime;
17013 +}
17014 +
17015 +
17016 +
17017 +static inline uint32_t __update_loadavg(uint32_t load,
17018 +       int wsize, int delta, int n)
17019 +{
17020 +       unsigned long long calc, prev;
17021 +
17022 +       /* just set it to n */
17023 +       if (unlikely(delta >= wsize))
17024 +               return (n << FSHIFT);
17025 +
17026 +       calc = delta * n;
17027 +       calc <<= FSHIFT;
17028 +       prev = (wsize - delta);
17029 +       prev *= load;
17030 +       calc += prev;
17031 +       do_div(calc, wsize);
17032 +       return calc;
17033 +}
17034 +
17035 +
17036 +void vx_update_load(struct vx_info *vxi)
17037 +{
17038 +       uint32_t now, last, delta;
17039 +       unsigned int nr_running, nr_uninterruptible;
17040 +       unsigned int total;
17041 +       unsigned long flags;
17042 +
17043 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17044 +
17045 +       now = jiffies;
17046 +       last = vxi->cvirt.load_last;
17047 +       delta = now - last;
17048 +
17049 +       if (delta < 5*HZ)
17050 +               goto out;
17051 +
17052 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17053 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17054 +       total = nr_running + nr_uninterruptible;
17055 +
17056 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17057 +               60*HZ, delta, total);
17058 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17059 +               5*60*HZ, delta, total);
17060 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17061 +               15*60*HZ, delta, total);
17062 +
17063 +       vxi->cvirt.load_last = now;
17064 +out:
17065 +       atomic_inc(&vxi->cvirt.load_updates);
17066 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17067 +}
17068 +
17069 +
17070 +/*
17071 + * Commands to do_syslog:
17072 + *
17073 + *      0 -- Close the log.  Currently a NOP.
17074 + *      1 -- Open the log. Currently a NOP.
17075 + *      2 -- Read from the log.
17076 + *      3 -- Read all messages remaining in the ring buffer.
17077 + *      4 -- Read and clear all messages remaining in the ring buffer
17078 + *      5 -- Clear ring buffer.
17079 + *      6 -- Disable printk's to console
17080 + *      7 -- Enable printk's to console
17081 + *      8 -- Set level of messages printed to console
17082 + *      9 -- Return number of unread characters in the log buffer
17083 + *     10 -- Return size of the log buffer
17084 + */
17085 +int vx_do_syslog(int type, char __user *buf, int len)
17086 +{
17087 +       int error = 0;
17088 +       int do_clear = 0;
17089 +       struct vx_info *vxi = current_vx_info();
17090 +       struct _vx_syslog *log;
17091 +
17092 +       if (!vxi)
17093 +               return -EINVAL;
17094 +       log = &vxi->cvirt.syslog;
17095 +
17096 +       switch (type) {
17097 +       case 0:         /* Close log */
17098 +       case 1:         /* Open log */
17099 +               break;
17100 +       case 2:         /* Read from log */
17101 +               error = wait_event_interruptible(log->log_wait,
17102 +                       (log->log_start - log->log_end));
17103 +               if (error)
17104 +                       break;
17105 +               spin_lock_irq(&log->logbuf_lock);
17106 +               spin_unlock_irq(&log->logbuf_lock);
17107 +               break;
17108 +       case 4:         /* Read/clear last kernel messages */
17109 +               do_clear = 1;
17110 +               /* fall through */
17111 +       case 3:         /* Read last kernel messages */
17112 +               return 0;
17113 +
17114 +       case 5:         /* Clear ring buffer */
17115 +               return 0;
17116 +
17117 +       case 6:         /* Disable logging to console */
17118 +       case 7:         /* Enable logging to console */
17119 +       case 8:         /* Set level of messages printed to console */
17120 +               break;
17121 +
17122 +       case 9:         /* Number of chars in the log buffer */
17123 +               return 0;
17124 +       case 10:        /* Size of the log buffer */
17125 +               return 0;
17126 +       default:
17127 +               error = -EINVAL;
17128 +               break;
17129 +       }
17130 +       return error;
17131 +}
17132 +
17133 +
17134 +/* virtual host info names */
17135 +
17136 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17137 +{
17138 +       struct nsproxy *nsproxy;
17139 +       struct uts_namespace *uts;
17140 +
17141 +       if (id == VHIN_CONTEXT)
17142 +               return vxi->vx_name;
17143 +
17144 +       nsproxy = vxi->space[0].vx_nsproxy;
17145 +       if (!nsproxy)
17146 +               return NULL;
17147 +
17148 +       uts = nsproxy->uts_ns;
17149 +       if (!uts)
17150 +               return NULL;
17151 +
17152 +       switch (id) {
17153 +       case VHIN_SYSNAME:
17154 +               return uts->name.sysname;
17155 +       case VHIN_NODENAME:
17156 +               return uts->name.nodename;
17157 +       case VHIN_RELEASE:
17158 +               return uts->name.release;
17159 +       case VHIN_VERSION:
17160 +               return uts->name.version;
17161 +       case VHIN_MACHINE:
17162 +               return uts->name.machine;
17163 +       case VHIN_DOMAINNAME:
17164 +               return uts->name.domainname;
17165 +       default:
17166 +               return NULL;
17167 +       }
17168 +       return NULL;
17169 +}
17170 +
17171 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17172 +{
17173 +       struct vcmd_vhi_name_v0 vc_data;
17174 +       char *name;
17175 +
17176 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17177 +               return -EFAULT;
17178 +
17179 +       name = vx_vhi_name(vxi, vc_data.field);
17180 +       if (!name)
17181 +               return -EINVAL;
17182 +
17183 +       memcpy(name, vc_data.name, 65);
17184 +       return 0;
17185 +}
17186 +
17187 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17188 +{
17189 +       struct vcmd_vhi_name_v0 vc_data;
17190 +       char *name;
17191 +
17192 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17193 +               return -EFAULT;
17194 +
17195 +       name = vx_vhi_name(vxi, vc_data.field);
17196 +       if (!name)
17197 +               return -EINVAL;
17198 +
17199 +       memcpy(vc_data.name, name, 65);
17200 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17201 +               return -EFAULT;
17202 +       return 0;
17203 +}
17204 +
17205 +
17206 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17207 +{
17208 +       struct vcmd_virt_stat_v0 vc_data;
17209 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17210 +       struct timespec uptime;
17211 +
17212 +       do_posix_clock_monotonic_gettime(&uptime);
17213 +       set_normalized_timespec(&uptime,
17214 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17215 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17216 +
17217 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17218 +       vc_data.uptime = timespec_to_ns(&uptime);
17219 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17220 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17221 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17222 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17223 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17224 +       vc_data.load[0] = cvirt->load[0];
17225 +       vc_data.load[1] = cvirt->load[1];
17226 +       vc_data.load[2] = cvirt->load[2];
17227 +
17228 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17229 +               return -EFAULT;
17230 +       return 0;
17231 +}
17232 +
17233 +
17234 +#ifdef CONFIG_VSERVER_VTIME
17235 +
17236 +/* virtualized time base */
17237 +
17238 +void vx_adjust_timespec(struct timespec *ts)
17239 +{
17240 +       struct vx_info *vxi;
17241 +
17242 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17243 +               return;
17244 +
17245 +       vxi = current_vx_info();
17246 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17247 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17248 +
17249 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17250 +               ts->tv_sec++;
17251 +               ts->tv_nsec -= NSEC_PER_SEC;
17252 +       } else if (ts->tv_nsec < 0) {
17253 +               ts->tv_sec--;
17254 +               ts->tv_nsec += NSEC_PER_SEC;
17255 +       }
17256 +}
17257 +
17258 +int vx_settimeofday(const struct timespec *ts)
17259 +{
17260 +       struct timespec ats, delta;
17261 +       struct vx_info *vxi;
17262 +
17263 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17264 +               return do_settimeofday(ts);
17265 +
17266 +       getnstimeofday(&ats);
17267 +       delta = timespec_sub(*ts, ats);
17268 +
17269 +       vxi = current_vx_info();
17270 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17271 +       return 0;
17272 +}
17273 +
17274 +#endif
17275 +
17276 diff -NurpP --minimal linux-3.2.8/kernel/vserver/cvirt_init.h linux-3.2.8-vs2.3.2.7/kernel/vserver/cvirt_init.h
17277 --- linux-3.2.8/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17278 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/cvirt_init.h   2011-12-05 19:33:02.000000000 +0100
17279 @@ -0,0 +1,70 @@
17280 +
17281 +
17282 +extern uint64_t vx_idle_jiffies(void);
17283 +
17284 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17285 +{
17286 +       uint64_t idle_jiffies = vx_idle_jiffies();
17287 +       uint64_t nsuptime;
17288 +
17289 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17290 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17291 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17292 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17293 +       cvirt->bias_ts.tv_sec = 0;
17294 +       cvirt->bias_ts.tv_nsec = 0;
17295 +
17296 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17297 +       atomic_set(&cvirt->nr_threads, 0);
17298 +       atomic_set(&cvirt->nr_running, 0);
17299 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17300 +       atomic_set(&cvirt->nr_onhold, 0);
17301 +
17302 +       spin_lock_init(&cvirt->load_lock);
17303 +       cvirt->load_last = jiffies;
17304 +       atomic_set(&cvirt->load_updates, 0);
17305 +       cvirt->load[0] = 0;
17306 +       cvirt->load[1] = 0;
17307 +       cvirt->load[2] = 0;
17308 +       atomic_set(&cvirt->total_forks, 0);
17309 +
17310 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17311 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17312 +       cvirt->syslog.log_start = 0;
17313 +       cvirt->syslog.log_end = 0;
17314 +       cvirt->syslog.con_start = 0;
17315 +       cvirt->syslog.logged_chars = 0;
17316 +}
17317 +
17318 +static inline
17319 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17320 +{
17321 +       // cvirt_pc->cpustat = { 0 };
17322 +}
17323 +
17324 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17325 +{
17326 +#ifdef CONFIG_VSERVER_WARN
17327 +       int value;
17328 +#endif
17329 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17330 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17331 +               cvirt, value);
17332 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17333 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17334 +               cvirt, value);
17335 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17336 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17337 +               cvirt, value);
17338 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17339 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17340 +               cvirt, value);
17341 +       return;
17342 +}
17343 +
17344 +static inline
17345 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17346 +{
17347 +       return;
17348 +}
17349 +
17350 diff -NurpP --minimal linux-3.2.8/kernel/vserver/cvirt_proc.h linux-3.2.8-vs2.3.2.7/kernel/vserver/cvirt_proc.h
17351 --- linux-3.2.8/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17352 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/cvirt_proc.h   2011-12-05 19:33:02.000000000 +0100
17353 @@ -0,0 +1,135 @@
17354 +#ifndef _VX_CVIRT_PROC_H
17355 +#define _VX_CVIRT_PROC_H
17356 +
17357 +#include <linux/nsproxy.h>
17358 +#include <linux/mnt_namespace.h>
17359 +#include <linux/ipc_namespace.h>
17360 +#include <linux/utsname.h>
17361 +#include <linux/ipc.h>
17362 +
17363 +
17364 +static inline
17365 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17366 +{
17367 +       struct mnt_namespace *ns;
17368 +       struct uts_namespace *uts;
17369 +       struct ipc_namespace *ipc;
17370 +       struct path path;
17371 +       char *pstr, *root;
17372 +       int length = 0;
17373 +
17374 +       if (!nsproxy)
17375 +               goto out;
17376 +
17377 +       length += sprintf(buffer + length,
17378 +               "NSProxy:\t%p [%p,%p,%p]\n",
17379 +               nsproxy, nsproxy->mnt_ns,
17380 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17381 +
17382 +       ns = nsproxy->mnt_ns;
17383 +       if (!ns)
17384 +               goto skip_ns;
17385 +
17386 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17387 +       if (!pstr)
17388 +               goto skip_ns;
17389 +
17390 +       path.mnt = ns->root;
17391 +       path.dentry = ns->root->mnt_root;
17392 +       root = d_path(&path, pstr, PATH_MAX - 2);
17393 +       length += sprintf(buffer + length,
17394 +               "Namespace:\t%p [#%u]\n"
17395 +               "RootPath:\t%s\n",
17396 +               ns, atomic_read(&ns->count),
17397 +               root);
17398 +       kfree(pstr);
17399 +skip_ns:
17400 +
17401 +       uts = nsproxy->uts_ns;
17402 +       if (!uts)
17403 +               goto skip_uts;
17404 +
17405 +       length += sprintf(buffer + length,
17406 +               "SysName:\t%.*s\n"
17407 +               "NodeName:\t%.*s\n"
17408 +               "Release:\t%.*s\n"
17409 +               "Version:\t%.*s\n"
17410 +               "Machine:\t%.*s\n"
17411 +               "DomainName:\t%.*s\n",
17412 +               __NEW_UTS_LEN, uts->name.sysname,
17413 +               __NEW_UTS_LEN, uts->name.nodename,
17414 +               __NEW_UTS_LEN, uts->name.release,
17415 +               __NEW_UTS_LEN, uts->name.version,
17416 +               __NEW_UTS_LEN, uts->name.machine,
17417 +               __NEW_UTS_LEN, uts->name.domainname);
17418 +skip_uts:
17419 +
17420 +       ipc = nsproxy->ipc_ns;
17421 +       if (!ipc)
17422 +               goto skip_ipc;
17423 +
17424 +       length += sprintf(buffer + length,
17425 +               "SEMS:\t\t%d %d %d %d  %d\n"
17426 +               "MSG:\t\t%d %d %d\n"
17427 +               "SHM:\t\t%lu %lu  %d %d\n",
17428 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17429 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17430 +               ipc->used_sems,
17431 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17432 +               (unsigned long)ipc->shm_ctlmax,
17433 +               (unsigned long)ipc->shm_ctlall,
17434 +               ipc->shm_ctlmni, ipc->shm_tot);
17435 +skip_ipc:
17436 +out:
17437 +       return length;
17438 +}
17439 +
17440 +
17441 +#include <linux/sched.h>
17442 +
17443 +#define LOAD_INT(x) ((x) >> FSHIFT)
17444 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17445 +
17446 +static inline
17447 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17448 +{
17449 +       int length = 0;
17450 +       int a, b, c;
17451 +
17452 +       length += sprintf(buffer + length,
17453 +               "BiasUptime:\t%lu.%02lu\n",
17454 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17455 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17456 +
17457 +       a = cvirt->load[0] + (FIXED_1 / 200);
17458 +       b = cvirt->load[1] + (FIXED_1 / 200);
17459 +       c = cvirt->load[2] + (FIXED_1 / 200);
17460 +       length += sprintf(buffer + length,
17461 +               "nr_threads:\t%d\n"
17462 +               "nr_running:\t%d\n"
17463 +               "nr_unintr:\t%d\n"
17464 +               "nr_onhold:\t%d\n"
17465 +               "load_updates:\t%d\n"
17466 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17467 +               "total_forks:\t%d\n",
17468 +               atomic_read(&cvirt->nr_threads),
17469 +               atomic_read(&cvirt->nr_running),
17470 +               atomic_read(&cvirt->nr_uninterruptible),
17471 +               atomic_read(&cvirt->nr_onhold),
17472 +               atomic_read(&cvirt->load_updates),
17473 +               LOAD_INT(a), LOAD_FRAC(a),
17474 +               LOAD_INT(b), LOAD_FRAC(b),
17475 +               LOAD_INT(c), LOAD_FRAC(c),
17476 +               atomic_read(&cvirt->total_forks));
17477 +       return length;
17478 +}
17479 +
17480 +static inline
17481 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17482 +       char *buffer, int cpu)
17483 +{
17484 +       int length = 0;
17485 +       return length;
17486 +}
17487 +
17488 +#endif /* _VX_CVIRT_PROC_H */
17489 diff -NurpP --minimal linux-3.2.8/kernel/vserver/debug.c linux-3.2.8-vs2.3.2.7/kernel/vserver/debug.c
17490 --- linux-3.2.8/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17491 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/debug.c        2011-12-05 19:33:02.000000000 +0100
17492 @@ -0,0 +1,32 @@
17493 +/*
17494 + *  kernel/vserver/debug.c
17495 + *
17496 + *  Copyright (C) 2005-2007 Herbert Pötzl
17497 + *
17498 + *  V0.01  vx_info dump support
17499 + *
17500 + */
17501 +
17502 +#include <linux/module.h>
17503 +
17504 +#include <linux/vserver/context.h>
17505 +
17506 +
17507 +void   dump_vx_info(struct vx_info *vxi, int level)
17508 +{
17509 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17510 +               atomic_read(&vxi->vx_usecnt),
17511 +               atomic_read(&vxi->vx_tasks),
17512 +               vxi->vx_state);
17513 +       if (level > 0) {
17514 +               __dump_vx_limit(&vxi->limit);
17515 +               __dump_vx_sched(&vxi->sched);
17516 +               __dump_vx_cvirt(&vxi->cvirt);
17517 +               __dump_vx_cacct(&vxi->cacct);
17518 +       }
17519 +       printk("---\n");
17520 +}
17521 +
17522 +
17523 +EXPORT_SYMBOL_GPL(dump_vx_info);
17524 +
17525 diff -NurpP --minimal linux-3.2.8/kernel/vserver/device.c linux-3.2.8-vs2.3.2.7/kernel/vserver/device.c
17526 --- linux-3.2.8/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17527 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/device.c       2011-12-05 19:33:02.000000000 +0100
17528 @@ -0,0 +1,443 @@
17529 +/*
17530 + *  linux/kernel/vserver/device.c
17531 + *
17532 + *  Linux-VServer: Device Support
17533 + *
17534 + *  Copyright (C) 2006  Herbert Pötzl
17535 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17536 + *
17537 + *  V0.01  device mapping basics
17538 + *  V0.02  added defaults
17539 + *
17540 + */
17541 +
17542 +#include <linux/slab.h>
17543 +#include <linux/rcupdate.h>
17544 +#include <linux/fs.h>
17545 +#include <linux/namei.h>
17546 +#include <linux/hash.h>
17547 +
17548 +#include <asm/errno.h>
17549 +#include <asm/uaccess.h>
17550 +#include <linux/vserver/base.h>
17551 +#include <linux/vserver/debug.h>
17552 +#include <linux/vserver/context.h>
17553 +#include <linux/vserver/device.h>
17554 +#include <linux/vserver/device_cmd.h>
17555 +
17556 +
17557 +#define DMAP_HASH_BITS 4
17558 +
17559 +
17560 +struct vs_mapping {
17561 +       union {
17562 +               struct hlist_node hlist;
17563 +               struct list_head list;
17564 +       } u;
17565 +#define dm_hlist       u.hlist
17566 +#define dm_list                u.list
17567 +       xid_t xid;
17568 +       dev_t device;
17569 +       struct vx_dmap_target target;
17570 +};
17571 +
17572 +
17573 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17574 +
17575 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17576 +
17577 +static struct vx_dmap_target dmap_defaults[2] = {
17578 +       { .flags = DATTR_OPEN },
17579 +       { .flags = DATTR_OPEN },
17580 +};
17581 +
17582 +
17583 +struct kmem_cache *dmap_cachep __read_mostly;
17584 +
17585 +int __init dmap_cache_init(void)
17586 +{
17587 +       dmap_cachep = kmem_cache_create("dmap_cache",
17588 +               sizeof(struct vs_mapping), 0,
17589 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17590 +       return 0;
17591 +}
17592 +
17593 +__initcall(dmap_cache_init);
17594 +
17595 +
17596 +static inline unsigned int __hashval(dev_t dev, int bits)
17597 +{
17598 +       return hash_long((unsigned long)dev, bits);
17599 +}
17600 +
17601 +
17602 +/*     __hash_mapping()
17603 + *     add the mapping to the hash table
17604 + */
17605 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17606 +{
17607 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17608 +       struct hlist_head *head, *hash = dmap_main_hash;
17609 +       int device = vdm->device;
17610 +
17611 +       spin_lock(hash_lock);
17612 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17613 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17614 +
17615 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17616 +       hlist_add_head(&vdm->dm_hlist, head);
17617 +       spin_unlock(hash_lock);
17618 +}
17619 +
17620 +
17621 +static inline int __mode_to_default(umode_t mode)
17622 +{
17623 +       switch (mode) {
17624 +       case S_IFBLK:
17625 +               return 0;
17626 +       case S_IFCHR:
17627 +               return 1;
17628 +       default:
17629 +               BUG();
17630 +       }
17631 +}
17632 +
17633 +
17634 +/*     __set_default()
17635 + *     set a default
17636 + */
17637 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17638 +       struct vx_dmap_target *vdmt)
17639 +{
17640 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17641 +       spin_lock(hash_lock);
17642 +
17643 +       if (vxi)
17644 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17645 +       else
17646 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17647 +
17648 +
17649 +       spin_unlock(hash_lock);
17650 +
17651 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17652 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17653 +}
17654 +
17655 +
17656 +/*     __remove_default()
17657 + *     remove a default
17658 + */
17659 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17660 +{
17661 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17662 +       spin_lock(hash_lock);
17663 +
17664 +       if (vxi)
17665 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17666 +       else    /* remove == reset */
17667 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17668 +
17669 +       spin_unlock(hash_lock);
17670 +       return 0;
17671 +}
17672 +
17673 +
17674 +/*     __find_mapping()
17675 + *     find a mapping in the hash table
17676 + *
17677 + *     caller must hold hash_lock
17678 + */
17679 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17680 +       struct vs_mapping **local, struct vs_mapping **global)
17681 +{
17682 +       struct hlist_head *hash = dmap_main_hash;
17683 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17684 +       struct hlist_node *pos;
17685 +       struct vs_mapping *vdm;
17686 +
17687 +       *local = NULL;
17688 +       if (global)
17689 +               *global = NULL;
17690 +
17691 +       hlist_for_each(pos, head) {
17692 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17693 +
17694 +               if ((vdm->device == device) &&
17695 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17696 +                       if (vdm->xid == xid) {
17697 +                               *local = vdm;
17698 +                               return 1;
17699 +                       } else if (global && vdm->xid == 0)
17700 +                               *global = vdm;
17701 +               }
17702 +       }
17703 +
17704 +       if (global && *global)
17705 +               return 0;
17706 +       else
17707 +               return -ENOENT;
17708 +}
17709 +
17710 +
17711 +/*     __lookup_mapping()
17712 + *     find a mapping and store the result in target and flags
17713 + */
17714 +static inline int __lookup_mapping(struct vx_info *vxi,
17715 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17716 +{
17717 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17718 +       struct vs_mapping *vdm, *global;
17719 +       struct vx_dmap_target *vdmt;
17720 +       int ret = 0;
17721 +       xid_t xid = vxi->vx_id;
17722 +       int index;
17723 +
17724 +       spin_lock(hash_lock);
17725 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17726 +               ret = 1;
17727 +               vdmt = &vdm->target;
17728 +               goto found;
17729 +       }
17730 +
17731 +       index = __mode_to_default(mode);
17732 +       if (vxi && vxi->dmap.targets[index].flags) {
17733 +               ret = 2;
17734 +               vdmt = &vxi->dmap.targets[index];
17735 +       } else if (global) {
17736 +               ret = 3;
17737 +               vdmt = &global->target;
17738 +               goto found;
17739 +       } else {
17740 +               ret = 4;
17741 +               vdmt = &dmap_defaults[index];
17742 +       }
17743 +
17744 +found:
17745 +       if (target && (vdmt->flags & DATTR_REMAP))
17746 +               *target = vdmt->target;
17747 +       else if (target)
17748 +               *target = device;
17749 +       if (flags)
17750 +               *flags = vdmt->flags;
17751 +
17752 +       spin_unlock(hash_lock);
17753 +
17754 +       return ret;
17755 +}
17756 +
17757 +
17758 +/*     __remove_mapping()
17759 + *     remove a mapping from the hash table
17760 + */
17761 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17762 +       umode_t mode)
17763 +{
17764 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17765 +       struct vs_mapping *vdm = NULL;
17766 +       int ret = 0;
17767 +
17768 +       spin_lock(hash_lock);
17769 +
17770 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17771 +               NULL);
17772 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17773 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17774 +       if (ret < 0)
17775 +               goto out;
17776 +       hlist_del(&vdm->dm_hlist);
17777 +
17778 +out:
17779 +       spin_unlock(hash_lock);
17780 +       if (vdm)
17781 +               kmem_cache_free(dmap_cachep, vdm);
17782 +       return ret;
17783 +}
17784 +
17785 +
17786 +
17787 +int vs_map_device(struct vx_info *vxi,
17788 +       dev_t device, dev_t *target, umode_t mode)
17789 +{
17790 +       int ret, flags = DATTR_MASK;
17791 +
17792 +       if (!vxi) {
17793 +               if (target)
17794 +                       *target = device;
17795 +               goto out;
17796 +       }
17797 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17798 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17799 +               device, target ? *target : 0, flags, mode, ret);
17800 +out:
17801 +       return (flags & DATTR_MASK);
17802 +}
17803 +
17804 +
17805 +
17806 +static int do_set_mapping(struct vx_info *vxi,
17807 +       dev_t device, dev_t target, int flags, umode_t mode)
17808 +{
17809 +       if (device) {
17810 +               struct vs_mapping *new;
17811 +
17812 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17813 +               if (!new)
17814 +                       return -ENOMEM;
17815 +
17816 +               INIT_HLIST_NODE(&new->dm_hlist);
17817 +               new->device = device;
17818 +               new->target.target = target;
17819 +               new->target.flags = flags | mode;
17820 +               new->xid = (vxi ? vxi->vx_id : 0);
17821 +
17822 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17823 +               __hash_mapping(vxi, new);
17824 +       } else {
17825 +               struct vx_dmap_target new = {
17826 +                       .target = target,
17827 +                       .flags = flags | mode,
17828 +               };
17829 +               __set_default(vxi, mode, &new);
17830 +       }
17831 +       return 0;
17832 +}
17833 +
17834 +
17835 +static int do_unset_mapping(struct vx_info *vxi,
17836 +       dev_t device, dev_t target, int flags, umode_t mode)
17837 +{
17838 +       int ret = -EINVAL;
17839 +
17840 +       if (device) {
17841 +               ret = __remove_mapping(vxi, device, mode);
17842 +               if (ret < 0)
17843 +                       goto out;
17844 +       } else {
17845 +               ret = __remove_default(vxi, mode);
17846 +               if (ret < 0)
17847 +                       goto out;
17848 +       }
17849 +
17850 +out:
17851 +       return ret;
17852 +}
17853 +
17854 +
17855 +static inline int __user_device(const char __user *name, dev_t *dev,
17856 +       umode_t *mode)
17857 +{
17858 +       struct nameidata nd;
17859 +       int ret;
17860 +
17861 +       if (!name) {
17862 +               *dev = 0;
17863 +               return 0;
17864 +       }
17865 +       ret = user_lpath(name, &nd.path);
17866 +       if (ret)
17867 +               return ret;
17868 +       if (nd.path.dentry->d_inode) {
17869 +               *dev = nd.path.dentry->d_inode->i_rdev;
17870 +               *mode = nd.path.dentry->d_inode->i_mode;
17871 +       }
17872 +       path_put(&nd.path);
17873 +       return 0;
17874 +}
17875 +
17876 +static inline int __mapping_mode(dev_t device, dev_t target,
17877 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17878 +{
17879 +       if (device)
17880 +               *mode = device_mode & S_IFMT;
17881 +       else if (target)
17882 +               *mode = target_mode & S_IFMT;
17883 +       else
17884 +               return -EINVAL;
17885 +
17886 +       /* if both given, device and target mode have to match */
17887 +       if (device && target &&
17888 +               ((device_mode ^ target_mode) & S_IFMT))
17889 +               return -EINVAL;
17890 +       return 0;
17891 +}
17892 +
17893 +
17894 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17895 +       const char __user *target_path, int flags, int set)
17896 +{
17897 +       dev_t device = ~0, target = ~0;
17898 +       umode_t device_mode = 0, target_mode = 0, mode;
17899 +       int ret;
17900 +
17901 +       ret = __user_device(device_path, &device, &device_mode);
17902 +       if (ret)
17903 +               return ret;
17904 +       ret = __user_device(target_path, &target, &target_mode);
17905 +       if (ret)
17906 +               return ret;
17907 +
17908 +       ret = __mapping_mode(device, target,
17909 +               device_mode, target_mode, &mode);
17910 +       if (ret)
17911 +               return ret;
17912 +
17913 +       if (set)
17914 +               return do_set_mapping(vxi, device, target,
17915 +                       flags, mode);
17916 +       else
17917 +               return do_unset_mapping(vxi, device, target,
17918 +                       flags, mode);
17919 +}
17920 +
17921 +
17922 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17923 +{
17924 +       struct vcmd_set_mapping_v0 vc_data;
17925 +
17926 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17927 +               return -EFAULT;
17928 +
17929 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17930 +               vc_data.flags, 1);
17931 +}
17932 +
17933 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17934 +{
17935 +       struct vcmd_set_mapping_v0 vc_data;
17936 +
17937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17938 +               return -EFAULT;
17939 +
17940 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17941 +               vc_data.flags, 0);
17942 +}
17943 +
17944 +
17945 +#ifdef CONFIG_COMPAT
17946 +
17947 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17948 +{
17949 +       struct vcmd_set_mapping_v0_x32 vc_data;
17950 +
17951 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17952 +               return -EFAULT;
17953 +
17954 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17955 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17956 +}
17957 +
17958 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17959 +{
17960 +       struct vcmd_set_mapping_v0_x32 vc_data;
17961 +
17962 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17963 +               return -EFAULT;
17964 +
17965 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17966 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17967 +}
17968 +
17969 +#endif /* CONFIG_COMPAT */
17970 +
17971 +
17972 diff -NurpP --minimal linux-3.2.8/kernel/vserver/dlimit.c linux-3.2.8-vs2.3.2.7/kernel/vserver/dlimit.c
17973 --- linux-3.2.8/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17974 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/dlimit.c       2011-12-05 19:33:02.000000000 +0100
17975 @@ -0,0 +1,531 @@
17976 +/*
17977 + *  linux/kernel/vserver/dlimit.c
17978 + *
17979 + *  Virtual Server: Context Disk Limits
17980 + *
17981 + *  Copyright (C) 2004-2009  Herbert Pötzl
17982 + *
17983 + *  V0.01  initial version
17984 + *  V0.02  compat32 splitup
17985 + *  V0.03  extended interface
17986 + *
17987 + */
17988 +
17989 +#include <linux/statfs.h>
17990 +#include <linux/sched.h>
17991 +#include <linux/namei.h>
17992 +#include <linux/vs_tag.h>
17993 +#include <linux/vs_dlimit.h>
17994 +#include <linux/vserver/dlimit_cmd.h>
17995 +#include <linux/slab.h>
17996 +// #include <linux/gfp.h>
17997 +
17998 +#include <asm/uaccess.h>
17999 +
18000 +/*     __alloc_dl_info()
18001 +
18002 +       * allocate an initialized dl_info struct
18003 +       * doesn't make it visible (hash)                        */
18004 +
18005 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18006 +{
18007 +       struct dl_info *new = NULL;
18008 +
18009 +       vxdprintk(VXD_CBIT(dlim, 5),
18010 +               "alloc_dl_info(%p,%d)*", sb, tag);
18011 +
18012 +       /* would this benefit from a slab cache? */
18013 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18014 +       if (!new)
18015 +               return 0;
18016 +
18017 +       memset(new, 0, sizeof(struct dl_info));
18018 +       new->dl_tag = tag;
18019 +       new->dl_sb = sb;
18020 +       // INIT_RCU_HEAD(&new->dl_rcu);
18021 +       INIT_HLIST_NODE(&new->dl_hlist);
18022 +       spin_lock_init(&new->dl_lock);
18023 +       atomic_set(&new->dl_refcnt, 0);
18024 +       atomic_set(&new->dl_usecnt, 0);
18025 +
18026 +       /* rest of init goes here */
18027 +
18028 +       vxdprintk(VXD_CBIT(dlim, 4),
18029 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18030 +       return new;
18031 +}
18032 +
18033 +/*     __dealloc_dl_info()
18034 +
18035 +       * final disposal of dl_info                             */
18036 +
18037 +static void __dealloc_dl_info(struct dl_info *dli)
18038 +{
18039 +       vxdprintk(VXD_CBIT(dlim, 4),
18040 +               "dealloc_dl_info(%p)", dli);
18041 +
18042 +       dli->dl_hlist.next = LIST_POISON1;
18043 +       dli->dl_tag = -1;
18044 +       dli->dl_sb = 0;
18045 +
18046 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18047 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18048 +
18049 +       kfree(dli);
18050 +}
18051 +
18052 +
18053 +/*     hash table for dl_info hash */
18054 +
18055 +#define DL_HASH_SIZE   13
18056 +
18057 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18058 +
18059 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18060 +
18061 +
18062 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18063 +{
18064 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18065 +}
18066 +
18067 +
18068 +
18069 +/*     __hash_dl_info()
18070 +
18071 +       * add the dli to the global hash table
18072 +       * requires the hash_lock to be held                     */
18073 +
18074 +static inline void __hash_dl_info(struct dl_info *dli)
18075 +{
18076 +       struct hlist_head *head;
18077 +
18078 +       vxdprintk(VXD_CBIT(dlim, 6),
18079 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18080 +       get_dl_info(dli);
18081 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18082 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18083 +}
18084 +
18085 +/*     __unhash_dl_info()
18086 +
18087 +       * remove the dli from the global hash table
18088 +       * requires the hash_lock to be held                     */
18089 +
18090 +static inline void __unhash_dl_info(struct dl_info *dli)
18091 +{
18092 +       vxdprintk(VXD_CBIT(dlim, 6),
18093 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18094 +       hlist_del_rcu(&dli->dl_hlist);
18095 +       put_dl_info(dli);
18096 +}
18097 +
18098 +
18099 +/*     __lookup_dl_info()
18100 +
18101 +       * requires the rcu_read_lock()
18102 +       * doesn't increment the dl_refcnt                       */
18103 +
18104 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18105 +{
18106 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18107 +       struct hlist_node *pos;
18108 +       struct dl_info *dli;
18109 +
18110 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18111 +
18112 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18113 +                       return dli;
18114 +               }
18115 +       }
18116 +       return NULL;
18117 +}
18118 +
18119 +
18120 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18121 +{
18122 +       struct dl_info *dli;
18123 +
18124 +       rcu_read_lock();
18125 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18126 +       vxdprintk(VXD_CBIT(dlim, 7),
18127 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18128 +       rcu_read_unlock();
18129 +       return dli;
18130 +}
18131 +
18132 +void rcu_free_dl_info(struct rcu_head *head)
18133 +{
18134 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18135 +       int usecnt, refcnt;
18136 +
18137 +       BUG_ON(!dli || !head);
18138 +
18139 +       usecnt = atomic_read(&dli->dl_usecnt);
18140 +       BUG_ON(usecnt < 0);
18141 +
18142 +       refcnt = atomic_read(&dli->dl_refcnt);
18143 +       BUG_ON(refcnt < 0);
18144 +
18145 +       vxdprintk(VXD_CBIT(dlim, 3),
18146 +               "rcu_free_dl_info(%p)", dli);
18147 +       if (!usecnt)
18148 +               __dealloc_dl_info(dli);
18149 +       else
18150 +               printk("!!! rcu didn't free\n");
18151 +}
18152 +
18153 +
18154 +
18155 +
18156 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18157 +       uint32_t flags, int add)
18158 +{
18159 +       struct path path;
18160 +       int ret;
18161 +
18162 +       ret = user_lpath(name, &path);
18163 +       if (!ret) {
18164 +               struct super_block *sb;
18165 +               struct dl_info *dli;
18166 +
18167 +               ret = -EINVAL;
18168 +               if (!path.dentry->d_inode)
18169 +                       goto out_release;
18170 +               if (!(sb = path.dentry->d_inode->i_sb))
18171 +                       goto out_release;
18172 +
18173 +               if (add) {
18174 +                       dli = __alloc_dl_info(sb, id);
18175 +                       spin_lock(&dl_info_hash_lock);
18176 +
18177 +                       ret = -EEXIST;
18178 +                       if (__lookup_dl_info(sb, id))
18179 +                               goto out_unlock;
18180 +                       __hash_dl_info(dli);
18181 +                       dli = NULL;
18182 +               } else {
18183 +                       spin_lock(&dl_info_hash_lock);
18184 +                       dli = __lookup_dl_info(sb, id);
18185 +
18186 +                       ret = -ESRCH;
18187 +                       if (!dli)
18188 +                               goto out_unlock;
18189 +                       __unhash_dl_info(dli);
18190 +               }
18191 +               ret = 0;
18192 +       out_unlock:
18193 +               spin_unlock(&dl_info_hash_lock);
18194 +               if (add && dli)
18195 +                       __dealloc_dl_info(dli);
18196 +       out_release:
18197 +               path_put(&path);
18198 +       }
18199 +       return ret;
18200 +}
18201 +
18202 +int vc_add_dlimit(uint32_t id, void __user *data)
18203 +{
18204 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18205 +
18206 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18207 +               return -EFAULT;
18208 +
18209 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18210 +}
18211 +
18212 +int vc_rem_dlimit(uint32_t id, void __user *data)
18213 +{
18214 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18215 +
18216 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18217 +               return -EFAULT;
18218 +
18219 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18220 +}
18221 +
18222 +#ifdef CONFIG_COMPAT
18223 +
18224 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18225 +{
18226 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18227 +
18228 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18229 +               return -EFAULT;
18230 +
18231 +       return do_addrem_dlimit(id,
18232 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18233 +}
18234 +
18235 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18236 +{
18237 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18238 +
18239 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18240 +               return -EFAULT;
18241 +
18242 +       return do_addrem_dlimit(id,
18243 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18244 +}
18245 +
18246 +#endif /* CONFIG_COMPAT */
18247 +
18248 +
18249 +static inline
18250 +int do_set_dlimit(uint32_t id, const char __user *name,
18251 +       uint32_t space_used, uint32_t space_total,
18252 +       uint32_t inodes_used, uint32_t inodes_total,
18253 +       uint32_t reserved, uint32_t flags)
18254 +{
18255 +       struct path path;
18256 +       int ret;
18257 +
18258 +       ret = user_lpath(name, &path);
18259 +       if (!ret) {
18260 +               struct super_block *sb;
18261 +               struct dl_info *dli;
18262 +
18263 +               ret = -EINVAL;
18264 +               if (!path.dentry->d_inode)
18265 +                       goto out_release;
18266 +               if (!(sb = path.dentry->d_inode->i_sb))
18267 +                       goto out_release;
18268 +
18269 +               /* sanity checks */
18270 +               if ((reserved != CDLIM_KEEP &&
18271 +                       reserved > 100) ||
18272 +                       (inodes_used != CDLIM_KEEP &&
18273 +                       inodes_used > inodes_total) ||
18274 +                       (space_used != CDLIM_KEEP &&
18275 +                       space_used > space_total))
18276 +                       goto out_release;
18277 +
18278 +               ret = -ESRCH;
18279 +               dli = locate_dl_info(sb, id);
18280 +               if (!dli)
18281 +                       goto out_release;
18282 +
18283 +               spin_lock(&dli->dl_lock);
18284 +
18285 +               if (inodes_used != CDLIM_KEEP)
18286 +                       dli->dl_inodes_used = inodes_used;
18287 +               if (inodes_total != CDLIM_KEEP)
18288 +                       dli->dl_inodes_total = inodes_total;
18289 +               if (space_used != CDLIM_KEEP)
18290 +                       dli->dl_space_used = dlimit_space_32to64(
18291 +                               space_used, flags, DLIMS_USED);
18292 +
18293 +               if (space_total == CDLIM_INFINITY)
18294 +                       dli->dl_space_total = DLIM_INFINITY;
18295 +               else if (space_total != CDLIM_KEEP)
18296 +                       dli->dl_space_total = dlimit_space_32to64(
18297 +                               space_total, flags, DLIMS_TOTAL);
18298 +
18299 +               if (reserved != CDLIM_KEEP)
18300 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18301 +
18302 +               spin_unlock(&dli->dl_lock);
18303 +
18304 +               put_dl_info(dli);
18305 +               ret = 0;
18306 +
18307 +       out_release:
18308 +               path_put(&path);
18309 +       }
18310 +       return ret;
18311 +}
18312 +
18313 +int vc_set_dlimit(uint32_t id, void __user *data)
18314 +{
18315 +       struct vcmd_ctx_dlimit_v0 vc_data;
18316 +
18317 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18318 +               return -EFAULT;
18319 +
18320 +       return do_set_dlimit(id, vc_data.name,
18321 +               vc_data.space_used, vc_data.space_total,
18322 +               vc_data.inodes_used, vc_data.inodes_total,
18323 +               vc_data.reserved, vc_data.flags);
18324 +}
18325 +
18326 +#ifdef CONFIG_COMPAT
18327 +
18328 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18329 +{
18330 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18331 +
18332 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18333 +               return -EFAULT;
18334 +
18335 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18336 +               vc_data.space_used, vc_data.space_total,
18337 +               vc_data.inodes_used, vc_data.inodes_total,
18338 +               vc_data.reserved, vc_data.flags);
18339 +}
18340 +
18341 +#endif /* CONFIG_COMPAT */
18342 +
18343 +
18344 +static inline
18345 +int do_get_dlimit(uint32_t id, const char __user *name,
18346 +       uint32_t *space_used, uint32_t *space_total,
18347 +       uint32_t *inodes_used, uint32_t *inodes_total,
18348 +       uint32_t *reserved, uint32_t *flags)
18349 +{
18350 +       struct path path;
18351 +       int ret;
18352 +
18353 +       ret = user_lpath(name, &path);
18354 +       if (!ret) {
18355 +               struct super_block *sb;
18356 +               struct dl_info *dli;
18357 +
18358 +               ret = -EINVAL;
18359 +               if (!path.dentry->d_inode)
18360 +                       goto out_release;
18361 +               if (!(sb = path.dentry->d_inode->i_sb))
18362 +                       goto out_release;
18363 +
18364 +               ret = -ESRCH;
18365 +               dli = locate_dl_info(sb, id);
18366 +               if (!dli)
18367 +                       goto out_release;
18368 +
18369 +               spin_lock(&dli->dl_lock);
18370 +               *inodes_used = dli->dl_inodes_used;
18371 +               *inodes_total = dli->dl_inodes_total;
18372 +
18373 +               *space_used = dlimit_space_64to32(
18374 +                       dli->dl_space_used, flags, DLIMS_USED);
18375 +
18376 +               if (dli->dl_space_total == DLIM_INFINITY)
18377 +                       *space_total = CDLIM_INFINITY;
18378 +               else
18379 +                       *space_total = dlimit_space_64to32(
18380 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18381 +
18382 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18383 +               spin_unlock(&dli->dl_lock);
18384 +
18385 +               put_dl_info(dli);
18386 +               ret = -EFAULT;
18387 +
18388 +               ret = 0;
18389 +       out_release:
18390 +               path_put(&path);
18391 +       }
18392 +       return ret;
18393 +}
18394 +
18395 +
18396 +int vc_get_dlimit(uint32_t id, void __user *data)
18397 +{
18398 +       struct vcmd_ctx_dlimit_v0 vc_data;
18399 +       int ret;
18400 +
18401 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18402 +               return -EFAULT;
18403 +
18404 +       ret = do_get_dlimit(id, vc_data.name,
18405 +               &vc_data.space_used, &vc_data.space_total,
18406 +               &vc_data.inodes_used, &vc_data.inodes_total,
18407 +               &vc_data.reserved, &vc_data.flags);
18408 +       if (ret)
18409 +               return ret;
18410 +
18411 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18412 +               return -EFAULT;
18413 +       return 0;
18414 +}
18415 +
18416 +#ifdef CONFIG_COMPAT
18417 +
18418 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18419 +{
18420 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18421 +       int ret;
18422 +
18423 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18424 +               return -EFAULT;
18425 +
18426 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18427 +               &vc_data.space_used, &vc_data.space_total,
18428 +               &vc_data.inodes_used, &vc_data.inodes_total,
18429 +               &vc_data.reserved, &vc_data.flags);
18430 +       if (ret)
18431 +               return ret;
18432 +
18433 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18434 +               return -EFAULT;
18435 +       return 0;
18436 +}
18437 +
18438 +#endif /* CONFIG_COMPAT */
18439 +
18440 +
18441 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18442 +{
18443 +       struct dl_info *dli;
18444 +       __u64 blimit, bfree, bavail;
18445 +       __u32 ifree;
18446 +
18447 +       dli = locate_dl_info(sb, dx_current_tag());
18448 +       if (!dli)
18449 +               return;
18450 +
18451 +       spin_lock(&dli->dl_lock);
18452 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18453 +               goto no_ilim;
18454 +
18455 +       /* reduce max inodes available to limit */
18456 +       if (buf->f_files > dli->dl_inodes_total)
18457 +               buf->f_files = dli->dl_inodes_total;
18458 +
18459 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18460 +       /* reduce free inodes to min */
18461 +       if (ifree < buf->f_ffree)
18462 +               buf->f_ffree = ifree;
18463 +
18464 +no_ilim:
18465 +       if (dli->dl_space_total == DLIM_INFINITY)
18466 +               goto no_blim;
18467 +
18468 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18469 +
18470 +       if (dli->dl_space_total < dli->dl_space_used)
18471 +               bfree = 0;
18472 +       else
18473 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18474 +                       >> sb->s_blocksize_bits;
18475 +
18476 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18477 +       if (bavail < dli->dl_space_used)
18478 +               bavail = 0;
18479 +       else
18480 +               bavail = (bavail - dli->dl_space_used)
18481 +                       >> sb->s_blocksize_bits;
18482 +
18483 +       /* reduce max space available to limit */
18484 +       if (buf->f_blocks > blimit)
18485 +               buf->f_blocks = blimit;
18486 +
18487 +       /* reduce free space to min */
18488 +       if (bfree < buf->f_bfree)
18489 +               buf->f_bfree = bfree;
18490 +
18491 +       /* reduce avail space to min */
18492 +       if (bavail < buf->f_bavail)
18493 +               buf->f_bavail = bavail;
18494 +
18495 +no_blim:
18496 +       spin_unlock(&dli->dl_lock);
18497 +       put_dl_info(dli);
18498 +
18499 +       return;
18500 +}
18501 +
18502 +#include <linux/module.h>
18503 +
18504 +EXPORT_SYMBOL_GPL(locate_dl_info);
18505 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18506 +
18507 diff -NurpP --minimal linux-3.2.8/kernel/vserver/helper.c linux-3.2.8-vs2.3.2.7/kernel/vserver/helper.c
18508 --- linux-3.2.8/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18509 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/helper.c       2011-12-05 19:33:02.000000000 +0100
18510 @@ -0,0 +1,223 @@
18511 +/*
18512 + *  linux/kernel/vserver/helper.c
18513 + *
18514 + *  Virtual Context Support
18515 + *
18516 + *  Copyright (C) 2004-2007  Herbert Pötzl
18517 + *
18518 + *  V0.01  basic helper
18519 + *
18520 + */
18521 +
18522 +#include <linux/kmod.h>
18523 +#include <linux/reboot.h>
18524 +#include <linux/vs_context.h>
18525 +#include <linux/vs_network.h>
18526 +#include <linux/vserver/signal.h>
18527 +
18528 +
18529 +char vshelper_path[255] = "/sbin/vshelper";
18530 +
18531 +
18532 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18533 +{
18534 +       int ret;
18535 +
18536 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18537 +               printk( KERN_WARNING
18538 +                       "%s: (%s %s) returned %s with %d\n",
18539 +                       name, argv[1], argv[2],
18540 +                       sync ? "sync" : "async", ret);
18541 +       }
18542 +       vxdprintk(VXD_CBIT(switch, 4),
18543 +               "%s: (%s %s) returned %s with %d",
18544 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18545 +       return ret;
18546 +}
18547 +
18548 +/*
18549 + *      vshelper path is set via /proc/sys
18550 + *      invoked by vserver sys_reboot(), with
18551 + *      the following arguments
18552 + *
18553 + *      argv [0] = vshelper_path;
18554 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18555 + *      argv [2] = context identifier
18556 + *
18557 + *      envp [*] = type-specific parameters
18558 + */
18559 +
18560 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18561 +{
18562 +       char id_buf[8], cmd_buf[16];
18563 +       char uid_buf[16], pid_buf[16];
18564 +       int ret;
18565 +
18566 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18567 +       char *envp[] = {"HOME=/", "TERM=linux",
18568 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18569 +                       uid_buf, pid_buf, cmd_buf, 0};
18570 +
18571 +       if (vx_info_state(vxi, VXS_HELPER))
18572 +               return -EAGAIN;
18573 +       vxi->vx_state |= VXS_HELPER;
18574 +
18575 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18576 +
18577 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18578 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18579 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18580 +
18581 +       switch (cmd) {
18582 +       case LINUX_REBOOT_CMD_RESTART:
18583 +               argv[1] = "restart";
18584 +               break;
18585 +
18586 +       case LINUX_REBOOT_CMD_HALT:
18587 +               argv[1] = "halt";
18588 +               break;
18589 +
18590 +       case LINUX_REBOOT_CMD_POWER_OFF:
18591 +               argv[1] = "poweroff";
18592 +               break;
18593 +
18594 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18595 +               argv[1] = "swsusp";
18596 +               break;
18597 +
18598 +       case LINUX_REBOOT_CMD_OOM:
18599 +               argv[1] = "oom";
18600 +               break;
18601 +
18602 +       default:
18603 +               vxi->vx_state &= ~VXS_HELPER;
18604 +               return 0;
18605 +       }
18606 +
18607 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18608 +       vxi->vx_state &= ~VXS_HELPER;
18609 +       __wakeup_vx_info(vxi);
18610 +       return (ret) ? -EPERM : 0;
18611 +}
18612 +
18613 +
18614 +long vs_reboot(unsigned int cmd, void __user *arg)
18615 +{
18616 +       struct vx_info *vxi = current_vx_info();
18617 +       long ret = 0;
18618 +
18619 +       vxdprintk(VXD_CBIT(misc, 5),
18620 +               "vs_reboot(%p[#%d],%u)",
18621 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18622 +
18623 +       ret = vs_reboot_helper(vxi, cmd, arg);
18624 +       if (ret)
18625 +               return ret;
18626 +
18627 +       vxi->reboot_cmd = cmd;
18628 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18629 +               switch (cmd) {
18630 +               case LINUX_REBOOT_CMD_RESTART:
18631 +               case LINUX_REBOOT_CMD_HALT:
18632 +               case LINUX_REBOOT_CMD_POWER_OFF:
18633 +                       vx_info_kill(vxi, 0, SIGKILL);
18634 +                       vx_info_kill(vxi, 1, SIGKILL);
18635 +               default:
18636 +                       break;
18637 +               }
18638 +       }
18639 +       return 0;
18640 +}
18641 +
18642 +long vs_oom_action(unsigned int cmd)
18643 +{
18644 +       struct vx_info *vxi = current_vx_info();
18645 +       long ret = 0;
18646 +
18647 +       vxdprintk(VXD_CBIT(misc, 5),
18648 +               "vs_oom_action(%p[#%d],%u)",
18649 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18650 +
18651 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18652 +       if (ret)
18653 +               return ret;
18654 +
18655 +       vxi->reboot_cmd = cmd;
18656 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18657 +               vx_info_kill(vxi, 0, SIGKILL);
18658 +               vx_info_kill(vxi, 1, SIGKILL);
18659 +       }
18660 +       return 0;
18661 +}
18662 +
18663 +/*
18664 + *      argv [0] = vshelper_path;
18665 + *      argv [1] = action: "startup", "shutdown"
18666 + *      argv [2] = context identifier
18667 + *
18668 + *      envp [*] = type-specific parameters
18669 + */
18670 +
18671 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18672 +{
18673 +       char id_buf[8], cmd_buf[16];
18674 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18675 +       char *envp[] = {"HOME=/", "TERM=linux",
18676 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18677 +
18678 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18679 +               return 0;
18680 +
18681 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18682 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18683 +
18684 +       switch (cmd) {
18685 +       case VSC_STARTUP:
18686 +               argv[1] = "startup";
18687 +               break;
18688 +       case VSC_SHUTDOWN:
18689 +               argv[1] = "shutdown";
18690 +               break;
18691 +       default:
18692 +               return 0;
18693 +       }
18694 +
18695 +       return do_vshelper(vshelper_path, argv, envp, 1);
18696 +}
18697 +
18698 +
18699 +/*
18700 + *      argv [0] = vshelper_path;
18701 + *      argv [1] = action: "netup", "netdown"
18702 + *      argv [2] = context identifier
18703 + *
18704 + *      envp [*] = type-specific parameters
18705 + */
18706 +
18707 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18708 +{
18709 +       char id_buf[8], cmd_buf[16];
18710 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18711 +       char *envp[] = {"HOME=/", "TERM=linux",
18712 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18713 +
18714 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18715 +               return 0;
18716 +
18717 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18718 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18719 +
18720 +       switch (cmd) {
18721 +       case VSC_NETUP:
18722 +               argv[1] = "netup";
18723 +               break;
18724 +       case VSC_NETDOWN:
18725 +               argv[1] = "netdown";
18726 +               break;
18727 +       default:
18728 +               return 0;
18729 +       }
18730 +
18731 +       return do_vshelper(vshelper_path, argv, envp, 1);
18732 +}
18733 +
18734 diff -NurpP --minimal linux-3.2.8/kernel/vserver/history.c linux-3.2.8-vs2.3.2.7/kernel/vserver/history.c
18735 --- linux-3.2.8/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18736 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/history.c      2011-12-05 19:33:02.000000000 +0100
18737 @@ -0,0 +1,258 @@
18738 +/*
18739 + *  kernel/vserver/history.c
18740 + *
18741 + *  Virtual Context History Backtrace
18742 + *
18743 + *  Copyright (C) 2004-2007  Herbert Pötzl
18744 + *
18745 + *  V0.01  basic structure
18746 + *  V0.02  hash/unhash and trace
18747 + *  V0.03  preemption fixes
18748 + *
18749 + */
18750 +
18751 +#include <linux/module.h>
18752 +#include <asm/uaccess.h>
18753 +
18754 +#include <linux/vserver/context.h>
18755 +#include <linux/vserver/debug.h>
18756 +#include <linux/vserver/debug_cmd.h>
18757 +#include <linux/vserver/history.h>
18758 +
18759 +
18760 +#ifdef CONFIG_VSERVER_HISTORY
18761 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18762 +#else
18763 +#define VXH_SIZE       64
18764 +#endif
18765 +
18766 +struct _vx_history {
18767 +       unsigned int counter;
18768 +
18769 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18770 +};
18771 +
18772 +
18773 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18774 +
18775 +unsigned volatile int vxh_active = 1;
18776 +
18777 +static atomic_t sequence = ATOMIC_INIT(0);
18778 +
18779 +
18780 +/*     vxh_advance()
18781 +
18782 +       * requires disabled preemption                          */
18783 +
18784 +struct _vx_hist_entry *vxh_advance(void *loc)
18785 +{
18786 +       unsigned int cpu = smp_processor_id();
18787 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18788 +       struct _vx_hist_entry *entry;
18789 +       unsigned int index;
18790 +
18791 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18792 +       entry = &hist->entry[index];
18793 +
18794 +       entry->seq = atomic_inc_return(&sequence);
18795 +       entry->loc = loc;
18796 +       return entry;
18797 +}
18798 +
18799 +EXPORT_SYMBOL_GPL(vxh_advance);
18800 +
18801 +
18802 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18803 +
18804 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18805 +
18806 +
18807 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18808 +
18809 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18810 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18811 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18812 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18813 +
18814 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18815 +{
18816 +       switch (e->type) {
18817 +       case VXH_THROW_OOPS:
18818 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18819 +               break;
18820 +
18821 +       case VXH_GET_VX_INFO:
18822 +       case VXH_PUT_VX_INFO:
18823 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18824 +                       VXH_LOC_ARGS(e),
18825 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18826 +                       VXH_VXI_ARGS(e));
18827 +               break;
18828 +
18829 +       case VXH_INIT_VX_INFO:
18830 +       case VXH_SET_VX_INFO:
18831 +       case VXH_CLR_VX_INFO:
18832 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18833 +                       VXH_LOC_ARGS(e),
18834 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18835 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18836 +                       VXH_VXI_ARGS(e), e->sc.data);
18837 +               break;
18838 +
18839 +       case VXH_CLAIM_VX_INFO:
18840 +       case VXH_RELEASE_VX_INFO:
18841 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18842 +                       VXH_LOC_ARGS(e),
18843 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18844 +                       VXH_VXI_ARGS(e), e->sc.data);
18845 +               break;
18846 +
18847 +       case VXH_ALLOC_VX_INFO:
18848 +       case VXH_DEALLOC_VX_INFO:
18849 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18850 +                       VXH_LOC_ARGS(e),
18851 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18852 +                       VXH_VXI_ARGS(e));
18853 +               break;
18854 +
18855 +       case VXH_HASH_VX_INFO:
18856 +       case VXH_UNHASH_VX_INFO:
18857 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18858 +                       VXH_LOC_ARGS(e),
18859 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18860 +                       VXH_VXI_ARGS(e));
18861 +               break;
18862 +
18863 +       case VXH_LOC_VX_INFO:
18864 +       case VXH_LOOKUP_VX_INFO:
18865 +       case VXH_CREATE_VX_INFO:
18866 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18867 +                       VXH_LOC_ARGS(e),
18868 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18869 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18870 +                       e->ll.arg, VXH_VXI_ARGS(e));
18871 +               break;
18872 +       }
18873 +}
18874 +
18875 +static void __vxh_dump_history(void)
18876 +{
18877 +       unsigned int i, cpu;
18878 +
18879 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18880 +               atomic_read(&sequence), NR_CPUS);
18881 +
18882 +       for (i = 0; i < VXH_SIZE; i++) {
18883 +               for_each_online_cpu(cpu) {
18884 +                       struct _vx_history *hist =
18885 +                               &per_cpu(vx_history_buffer, cpu);
18886 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18887 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18888 +
18889 +                       vxh_dump_entry(entry, cpu);
18890 +               }
18891 +       }
18892 +}
18893 +
18894 +void   vxh_dump_history(void)
18895 +{
18896 +       vxh_active = 0;
18897 +#ifdef CONFIG_SMP
18898 +       local_irq_enable();
18899 +       smp_send_stop();
18900 +       local_irq_disable();
18901 +#endif
18902 +       __vxh_dump_history();
18903 +}
18904 +
18905 +
18906 +/* vserver syscall commands below here */
18907 +
18908 +
18909 +int vc_dump_history(uint32_t id)
18910 +{
18911 +       vxh_active = 0;
18912 +       __vxh_dump_history();
18913 +       vxh_active = 1;
18914 +
18915 +       return 0;
18916 +}
18917 +
18918 +
18919 +int do_read_history(struct __user _vx_hist_entry *data,
18920 +       int cpu, uint32_t *index, uint32_t *count)
18921 +{
18922 +       int pos, ret = 0;
18923 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18924 +       int end = hist->counter;
18925 +       int start = end - VXH_SIZE + 2;
18926 +       int idx = *index;
18927 +
18928 +       /* special case: get current pos */
18929 +       if (!*count) {
18930 +               *index = end;
18931 +               return 0;
18932 +       }
18933 +
18934 +       /* have we lost some data? */
18935 +       if (idx < start)
18936 +               idx = start;
18937 +
18938 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18939 +               struct _vx_hist_entry *entry =
18940 +                       &hist->entry[idx % VXH_SIZE];
18941 +
18942 +               /* send entry to userspace */
18943 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18944 +               if (ret)
18945 +                       break;
18946 +       }
18947 +       /* save new index and count */
18948 +       *index = idx;
18949 +       *count = pos;
18950 +       return ret ? ret : (*index < end);
18951 +}
18952 +
18953 +int vc_read_history(uint32_t id, void __user *data)
18954 +{
18955 +       struct vcmd_read_history_v0 vc_data;
18956 +       int ret;
18957 +
18958 +       if (id >= NR_CPUS)
18959 +               return -EINVAL;
18960 +
18961 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18962 +               return -EFAULT;
18963 +
18964 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18965 +               id, &vc_data.index, &vc_data.count);
18966 +
18967 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18968 +               return -EFAULT;
18969 +       return ret;
18970 +}
18971 +
18972 +#ifdef CONFIG_COMPAT
18973 +
18974 +int vc_read_history_x32(uint32_t id, void __user *data)
18975 +{
18976 +       struct vcmd_read_history_v0_x32 vc_data;
18977 +       int ret;
18978 +
18979 +       if (id >= NR_CPUS)
18980 +               return -EINVAL;
18981 +
18982 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18983 +               return -EFAULT;
18984 +
18985 +       ret = do_read_history((struct __user _vx_hist_entry *)
18986 +               compat_ptr(vc_data.data_ptr),
18987 +               id, &vc_data.index, &vc_data.count);
18988 +
18989 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18990 +               return -EFAULT;
18991 +       return ret;
18992 +}
18993 +
18994 +#endif /* CONFIG_COMPAT */
18995 +
18996 diff -NurpP --minimal linux-3.2.8/kernel/vserver/inet.c linux-3.2.8-vs2.3.2.7/kernel/vserver/inet.c
18997 --- linux-3.2.8/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
18998 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/inet.c 2011-12-15 01:33:09.000000000 +0100
18999 @@ -0,0 +1,226 @@
19000 +
19001 +#include <linux/in.h>
19002 +#include <linux/inetdevice.h>
19003 +#include <linux/export.h>
19004 +#include <linux/vs_inet.h>
19005 +#include <linux/vs_inet6.h>
19006 +#include <linux/vserver/debug.h>
19007 +#include <net/route.h>
19008 +#include <net/addrconf.h>
19009 +
19010 +
19011 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19012 +{
19013 +       int ret = 0;
19014 +
19015 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19016 +               ret = 1;
19017 +       else {
19018 +               struct nx_addr_v4 *ptr;
19019 +
19020 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19021 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19022 +                               ret = 1;
19023 +                               break;
19024 +                       }
19025 +               }
19026 +       }
19027 +
19028 +       vxdprintk(VXD_CBIT(net, 2),
19029 +               "nx_v4_addr_conflict(%p,%p): %d",
19030 +               nxi1, nxi2, ret);
19031 +
19032 +       return ret;
19033 +}
19034 +
19035 +
19036 +#ifdef CONFIG_IPV6
19037 +
19038 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19039 +{
19040 +       int ret = 0;
19041 +
19042 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19043 +               ret = 1;
19044 +       else {
19045 +               struct nx_addr_v6 *ptr;
19046 +
19047 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19048 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19049 +                               ret = 1;
19050 +                               break;
19051 +                       }
19052 +               }
19053 +       }
19054 +
19055 +       vxdprintk(VXD_CBIT(net, 2),
19056 +               "nx_v6_addr_conflict(%p,%p): %d",
19057 +               nxi1, nxi2, ret);
19058 +
19059 +       return ret;
19060 +}
19061 +
19062 +#endif
19063 +
19064 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19065 +{
19066 +       struct in_device *in_dev;
19067 +       struct in_ifaddr **ifap;
19068 +       struct in_ifaddr *ifa;
19069 +       int ret = 0;
19070 +
19071 +       if (!dev)
19072 +               goto out;
19073 +       in_dev = in_dev_get(dev);
19074 +       if (!in_dev)
19075 +               goto out;
19076 +
19077 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19078 +               ifap = &ifa->ifa_next) {
19079 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19080 +                       ret = 1;
19081 +                       break;
19082 +               }
19083 +       }
19084 +       in_dev_put(in_dev);
19085 +out:
19086 +       return ret;
19087 +}
19088 +
19089 +
19090 +#ifdef CONFIG_IPV6
19091 +
19092 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19093 +{
19094 +       struct inet6_dev *in_dev;
19095 +       struct inet6_ifaddr *ifa;
19096 +       int ret = 0;
19097 +
19098 +       if (!dev)
19099 +               goto out;
19100 +       in_dev = in6_dev_get(dev);
19101 +       if (!in_dev)
19102 +               goto out;
19103 +
19104 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19105 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19106 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19107 +                       ret = 1;
19108 +                       break;
19109 +               }
19110 +       }
19111 +       in6_dev_put(in_dev);
19112 +out:
19113 +       return ret;
19114 +}
19115 +
19116 +#endif
19117 +
19118 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19119 +{
19120 +       int ret = 1;
19121 +
19122 +       if (!nxi)
19123 +               goto out;
19124 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19125 +               goto out;
19126 +#ifdef CONFIG_IPV6
19127 +       ret = 2;
19128 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19129 +               goto out;
19130 +#endif
19131 +       ret = 0;
19132 +out:
19133 +       vxdprintk(VXD_CBIT(net, 3),
19134 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19135 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19136 +       return ret;
19137 +}
19138 +
19139 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19140 +       struct flowi4 *fl4)
19141 +{
19142 +       struct rtable *rt;
19143 +
19144 +       if (!nxi)
19145 +               return NULL;
19146 +
19147 +       /* FIXME: handle lback only case */
19148 +       if (!NX_IPV4(nxi))
19149 +               return ERR_PTR(-EPERM);
19150 +
19151 +       vxdprintk(VXD_CBIT(net, 4),
19152 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19153 +               nxi, nxi ? nxi->nx_id : 0,
19154 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19155 +
19156 +       /* single IP is unconditional */
19157 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19158 +               (fl4->saddr == INADDR_ANY))
19159 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19160 +
19161 +       if (fl4->saddr == INADDR_ANY) {
19162 +               struct nx_addr_v4 *ptr;
19163 +               __be32 found = 0;
19164 +
19165 +               rt = __ip_route_output_key(net, fl4);
19166 +               if (!IS_ERR(rt)) {
19167 +                       found = fl4->saddr;
19168 +                       ip_rt_put(rt);
19169 +                       vxdprintk(VXD_CBIT(net, 4),
19170 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19171 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19172 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19173 +                               goto found;
19174 +               }
19175 +
19176 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19177 +                       __be32 primary = ptr->ip[0].s_addr;
19178 +                       __be32 mask = ptr->mask.s_addr;
19179 +                       __be32 neta = primary & mask;
19180 +
19181 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19182 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19183 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19184 +                               NIPQUAD(mask), NIPQUAD(neta));
19185 +                       if ((found & mask) != neta)
19186 +                               continue;
19187 +
19188 +                       fl4->saddr = primary;
19189 +                       rt = __ip_route_output_key(net, fl4);
19190 +                       vxdprintk(VXD_CBIT(net, 4),
19191 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19192 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19193 +                       if (!IS_ERR(rt)) {
19194 +                               found = fl4->saddr;
19195 +                               ip_rt_put(rt);
19196 +                               if (found == primary)
19197 +                                       goto found;
19198 +                       }
19199 +               }
19200 +               /* still no source ip? */
19201 +               found = ipv4_is_loopback(fl4->daddr)
19202 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19203 +       found:
19204 +               /* assign src ip to flow */
19205 +               fl4->saddr = found;
19206 +
19207 +       } else {
19208 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19209 +                       return ERR_PTR(-EPERM);
19210 +       }
19211 +
19212 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19213 +               if (ipv4_is_loopback(fl4->daddr))
19214 +                       fl4->daddr = nxi->v4_lback.s_addr;
19215 +               if (ipv4_is_loopback(fl4->saddr))
19216 +                       fl4->saddr = nxi->v4_lback.s_addr;
19217 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19218 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19219 +               return ERR_PTR(-EPERM);
19220 +
19221 +       return NULL;
19222 +}
19223 +
19224 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19225 +
19226 diff -NurpP --minimal linux-3.2.8/kernel/vserver/init.c linux-3.2.8-vs2.3.2.7/kernel/vserver/init.c
19227 --- linux-3.2.8/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19228 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/init.c 2011-12-05 19:33:02.000000000 +0100
19229 @@ -0,0 +1,45 @@
19230 +/*
19231 + *  linux/kernel/init.c
19232 + *
19233 + *  Virtual Server Init
19234 + *
19235 + *  Copyright (C) 2004-2007  Herbert Pötzl
19236 + *
19237 + *  V0.01  basic structure
19238 + *
19239 + */
19240 +
19241 +#include <linux/init.h>
19242 +
19243 +int    vserver_register_sysctl(void);
19244 +void   vserver_unregister_sysctl(void);
19245 +
19246 +
19247 +static int __init init_vserver(void)
19248 +{
19249 +       int ret = 0;
19250 +
19251 +#ifdef CONFIG_VSERVER_DEBUG
19252 +       vserver_register_sysctl();
19253 +#endif
19254 +       return ret;
19255 +}
19256 +
19257 +
19258 +static void __exit exit_vserver(void)
19259 +{
19260 +
19261 +#ifdef CONFIG_VSERVER_DEBUG
19262 +       vserver_unregister_sysctl();
19263 +#endif
19264 +       return;
19265 +}
19266 +
19267 +/* FIXME: GFP_ZONETYPES gone
19268 +long vx_slab[GFP_ZONETYPES]; */
19269 +long vx_area;
19270 +
19271 +
19272 +module_init(init_vserver);
19273 +module_exit(exit_vserver);
19274 +
19275 diff -NurpP --minimal linux-3.2.8/kernel/vserver/inode.c linux-3.2.8-vs2.3.2.7/kernel/vserver/inode.c
19276 --- linux-3.2.8/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19277 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/inode.c        2011-12-06 23:56:11.000000000 +0100
19278 @@ -0,0 +1,437 @@
19279 +/*
19280 + *  linux/kernel/vserver/inode.c
19281 + *
19282 + *  Virtual Server: File System Support
19283 + *
19284 + *  Copyright (C) 2004-2007  Herbert Pötzl
19285 + *
19286 + *  V0.01  separated from vcontext V0.05
19287 + *  V0.02  moved to tag (instead of xid)
19288 + *
19289 + */
19290 +
19291 +#include <linux/tty.h>
19292 +#include <linux/proc_fs.h>
19293 +#include <linux/devpts_fs.h>
19294 +#include <linux/fs.h>
19295 +#include <linux/file.h>
19296 +#include <linux/mount.h>
19297 +#include <linux/parser.h>
19298 +#include <linux/namei.h>
19299 +#include <linux/vserver/inode.h>
19300 +#include <linux/vserver/inode_cmd.h>
19301 +#include <linux/vs_base.h>
19302 +#include <linux/vs_tag.h>
19303 +
19304 +#include <asm/uaccess.h>
19305 +
19306 +
19307 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19308 +{
19309 +       struct proc_dir_entry *entry;
19310 +
19311 +       if (!in || !in->i_sb)
19312 +               return -ESRCH;
19313 +
19314 +       *flags = IATTR_TAG
19315 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19316 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19317 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19318 +               | (IS_COW(in) ? IATTR_COW : 0);
19319 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19320 +
19321 +       if (S_ISDIR(in->i_mode))
19322 +               *mask |= IATTR_BARRIER;
19323 +
19324 +       if (IS_TAGGED(in)) {
19325 +               *tag = in->i_tag;
19326 +               *mask |= IATTR_TAG;
19327 +       }
19328 +
19329 +       switch (in->i_sb->s_magic) {
19330 +       case PROC_SUPER_MAGIC:
19331 +               entry = PROC_I(in)->pde;
19332 +
19333 +               /* check for specific inodes? */
19334 +               if (entry)
19335 +                       *mask |= IATTR_FLAGS;
19336 +               if (entry)
19337 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19338 +               else
19339 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19340 +               break;
19341 +
19342 +       case DEVPTS_SUPER_MAGIC:
19343 +               *tag = in->i_tag;
19344 +               *mask |= IATTR_TAG;
19345 +               break;
19346 +
19347 +       default:
19348 +               break;
19349 +       }
19350 +       return 0;
19351 +}
19352 +
19353 +int vc_get_iattr(void __user *data)
19354 +{
19355 +       struct path path;
19356 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19357 +       int ret;
19358 +
19359 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19360 +               return -EFAULT;
19361 +
19362 +       ret = user_lpath(vc_data.name, &path);
19363 +       if (!ret) {
19364 +               ret = __vc_get_iattr(path.dentry->d_inode,
19365 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19366 +               path_put(&path);
19367 +       }
19368 +       if (ret)
19369 +               return ret;
19370 +
19371 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19372 +               ret = -EFAULT;
19373 +       return ret;
19374 +}
19375 +
19376 +#ifdef CONFIG_COMPAT
19377 +
19378 +int vc_get_iattr_x32(void __user *data)
19379 +{
19380 +       struct path path;
19381 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19382 +       int ret;
19383 +
19384 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19385 +               return -EFAULT;
19386 +
19387 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19388 +       if (!ret) {
19389 +               ret = __vc_get_iattr(path.dentry->d_inode,
19390 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19391 +               path_put(&path);
19392 +       }
19393 +       if (ret)
19394 +               return ret;
19395 +
19396 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19397 +               ret = -EFAULT;
19398 +       return ret;
19399 +}
19400 +
19401 +#endif /* CONFIG_COMPAT */
19402 +
19403 +
19404 +int vc_fget_iattr(uint32_t fd, void __user *data)
19405 +{
19406 +       struct file *filp;
19407 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19408 +       int ret;
19409 +
19410 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19411 +               return -EFAULT;
19412 +
19413 +       filp = fget(fd);
19414 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19415 +               return -EBADF;
19416 +
19417 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19418 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19419 +
19420 +       fput(filp);
19421 +
19422 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19423 +               ret = -EFAULT;
19424 +       return ret;
19425 +}
19426 +
19427 +
19428 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19429 +{
19430 +       struct inode *in = de->d_inode;
19431 +       int error = 0, is_proc = 0, has_tag = 0;
19432 +       struct iattr attr = { 0 };
19433 +
19434 +       if (!in || !in->i_sb)
19435 +               return -ESRCH;
19436 +
19437 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19438 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19439 +               return -EINVAL;
19440 +
19441 +       has_tag = IS_TAGGED(in) ||
19442 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19443 +       if ((*mask & IATTR_TAG) && !has_tag)
19444 +               return -EINVAL;
19445 +
19446 +       mutex_lock(&in->i_mutex);
19447 +       if (*mask & IATTR_TAG) {
19448 +               attr.ia_tag = *tag;
19449 +               attr.ia_valid |= ATTR_TAG;
19450 +       }
19451 +
19452 +       if (*mask & IATTR_FLAGS) {
19453 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19454 +               unsigned int iflags = PROC_I(in)->vx_flags;
19455 +
19456 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19457 +                       | (*flags & IATTR_FLAGS);
19458 +               PROC_I(in)->vx_flags = iflags;
19459 +               if (entry)
19460 +                       entry->vx_flags = iflags;
19461 +       }
19462 +
19463 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19464 +               IATTR_BARRIER | IATTR_COW)) {
19465 +               int iflags = in->i_flags;
19466 +               int vflags = in->i_vflags;
19467 +
19468 +               if (*mask & IATTR_IMMUTABLE) {
19469 +                       if (*flags & IATTR_IMMUTABLE)
19470 +                               iflags |= S_IMMUTABLE;
19471 +                       else
19472 +                               iflags &= ~S_IMMUTABLE;
19473 +               }
19474 +               if (*mask & IATTR_IXUNLINK) {
19475 +                       if (*flags & IATTR_IXUNLINK)
19476 +                               iflags |= S_IXUNLINK;
19477 +                       else
19478 +                               iflags &= ~S_IXUNLINK;
19479 +               }
19480 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19481 +                       if (*flags & IATTR_BARRIER)
19482 +                               vflags |= V_BARRIER;
19483 +                       else
19484 +                               vflags &= ~V_BARRIER;
19485 +               }
19486 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19487 +                       if (*flags & IATTR_COW)
19488 +                               vflags |= V_COW;
19489 +                       else
19490 +                               vflags &= ~V_COW;
19491 +               }
19492 +               if (in->i_op && in->i_op->sync_flags) {
19493 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19494 +                       if (error)
19495 +                               goto out;
19496 +               }
19497 +       }
19498 +
19499 +       if (attr.ia_valid) {
19500 +               if (in->i_op && in->i_op->setattr)
19501 +                       error = in->i_op->setattr(de, &attr);
19502 +               else {
19503 +                       error = inode_change_ok(in, &attr);
19504 +                       if (!error) {
19505 +                               setattr_copy(in, &attr);
19506 +                               mark_inode_dirty(in);
19507 +                       }
19508 +               }
19509 +       }
19510 +
19511 +out:
19512 +       mutex_unlock(&in->i_mutex);
19513 +       return error;
19514 +}
19515 +
19516 +int vc_set_iattr(void __user *data)
19517 +{
19518 +       struct path path;
19519 +       struct vcmd_ctx_iattr_v1 vc_data;
19520 +       int ret;
19521 +
19522 +       if (!capable(CAP_LINUX_IMMUTABLE))
19523 +               return -EPERM;
19524 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19525 +               return -EFAULT;
19526 +
19527 +       ret = user_lpath(vc_data.name, &path);
19528 +       if (!ret) {
19529 +               ret = __vc_set_iattr(path.dentry,
19530 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19531 +               path_put(&path);
19532 +       }
19533 +
19534 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19535 +               ret = -EFAULT;
19536 +       return ret;
19537 +}
19538 +
19539 +#ifdef CONFIG_COMPAT
19540 +
19541 +int vc_set_iattr_x32(void __user *data)
19542 +{
19543 +       struct path path;
19544 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19545 +       int ret;
19546 +
19547 +       if (!capable(CAP_LINUX_IMMUTABLE))
19548 +               return -EPERM;
19549 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19550 +               return -EFAULT;
19551 +
19552 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19553 +       if (!ret) {
19554 +               ret = __vc_set_iattr(path.dentry,
19555 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19556 +               path_put(&path);
19557 +       }
19558 +
19559 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19560 +               ret = -EFAULT;
19561 +       return ret;
19562 +}
19563 +
19564 +#endif /* CONFIG_COMPAT */
19565 +
19566 +int vc_fset_iattr(uint32_t fd, void __user *data)
19567 +{
19568 +       struct file *filp;
19569 +       struct vcmd_ctx_fiattr_v0 vc_data;
19570 +       int ret;
19571 +
19572 +       if (!capable(CAP_LINUX_IMMUTABLE))
19573 +               return -EPERM;
19574 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19575 +               return -EFAULT;
19576 +
19577 +       filp = fget(fd);
19578 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19579 +               return -EBADF;
19580 +
19581 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19582 +               &vc_data.flags, &vc_data.mask);
19583 +
19584 +       fput(filp);
19585 +
19586 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19587 +               return -EFAULT;
19588 +       return ret;
19589 +}
19590 +
19591 +
19592 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19593 +
19594 +static match_table_t tokens = {
19595 +       {Opt_notagcheck, "notagcheck"},
19596 +#ifdef CONFIG_PROPAGATE
19597 +       {Opt_notag, "notag"},
19598 +       {Opt_tag, "tag"},
19599 +       {Opt_tagid, "tagid=%u"},
19600 +#endif
19601 +       {Opt_err, NULL}
19602 +};
19603 +
19604 +
19605 +static void __dx_parse_remove(char *string, char *opt)
19606 +{
19607 +       char *p = strstr(string, opt);
19608 +       char *q = p;
19609 +
19610 +       if (p) {
19611 +               while (*q != '\0' && *q != ',')
19612 +                       q++;
19613 +               while (*q)
19614 +                       *p++ = *q++;
19615 +               while (*p)
19616 +                       *p++ = '\0';
19617 +       }
19618 +}
19619 +
19620 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19621 +                unsigned long *flags)
19622 +{
19623 +       int set = 0;
19624 +       substring_t args[MAX_OPT_ARGS];
19625 +       int token;
19626 +       char *s, *p, *opts;
19627 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19628 +       int option = 0;
19629 +#endif
19630 +
19631 +       if (!string)
19632 +               return 0;
19633 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19634 +       if (!s)
19635 +               return 0;
19636 +
19637 +       opts = s;
19638 +       while ((p = strsep(&opts, ",")) != NULL) {
19639 +               token = match_token(p, tokens, args);
19640 +
19641 +               switch (token) {
19642 +#ifdef CONFIG_PROPAGATE
19643 +               case Opt_tag:
19644 +                       if (tag)
19645 +                               *tag = 0;
19646 +                       if (remove)
19647 +                               __dx_parse_remove(s, "tag");
19648 +                       *mnt_flags |= MNT_TAGID;
19649 +                       set |= MNT_TAGID;
19650 +                       break;
19651 +               case Opt_notag:
19652 +                       if (remove)
19653 +                               __dx_parse_remove(s, "notag");
19654 +                       *mnt_flags |= MNT_NOTAG;
19655 +                       set |= MNT_NOTAG;
19656 +                       break;
19657 +               case Opt_tagid:
19658 +                       if (tag && !match_int(args, &option))
19659 +                               *tag = option;
19660 +                       if (remove)
19661 +                               __dx_parse_remove(s, "tagid");
19662 +                       *mnt_flags |= MNT_TAGID;
19663 +                       set |= MNT_TAGID;
19664 +                       break;
19665 +#endif /* CONFIG_PROPAGATE */
19666 +               case Opt_notagcheck:
19667 +                       if (remove)
19668 +                               __dx_parse_remove(s, "notagcheck");
19669 +                       *flags |= MS_NOTAGCHECK;
19670 +                       set |= MS_NOTAGCHECK;
19671 +                       break;
19672 +               }
19673 +               vxdprintk(VXD_CBIT(tag, 7),
19674 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19675 +                       p, token, option);
19676 +       }
19677 +       if (set)
19678 +               strcpy(string, s);
19679 +       kfree(s);
19680 +       return set;
19681 +}
19682 +
19683 +#ifdef CONFIG_PROPAGATE
19684 +
19685 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19686 +{
19687 +       tag_t new_tag = 0;
19688 +       struct vfsmount *mnt;
19689 +       int propagate;
19690 +
19691 +       if (!nd)
19692 +               return;
19693 +       mnt = nd->path.mnt;
19694 +       if (!mnt)
19695 +               return;
19696 +
19697 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19698 +       if (propagate)
19699 +               new_tag = mnt->mnt_tag;
19700 +
19701 +       vxdprintk(VXD_CBIT(tag, 7),
19702 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19703 +               inode, inode->i_ino, inode->i_tag,
19704 +               new_tag, (propagate) ? 1 : 0);
19705 +
19706 +       if (propagate)
19707 +               inode->i_tag = new_tag;
19708 +}
19709 +
19710 +#include <linux/module.h>
19711 +
19712 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19713 +
19714 +#endif /* CONFIG_PROPAGATE */
19715 +
19716 diff -NurpP --minimal linux-3.2.8/kernel/vserver/limit.c linux-3.2.8-vs2.3.2.7/kernel/vserver/limit.c
19717 --- linux-3.2.8/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19718 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/limit.c        2011-12-15 01:52:48.000000000 +0100
19719 @@ -0,0 +1,330 @@
19720 +/*
19721 + *  linux/kernel/vserver/limit.c
19722 + *
19723 + *  Virtual Server: Context Limits
19724 + *
19725 + *  Copyright (C) 2004-2010  Herbert Pötzl
19726 + *
19727 + *  V0.01  broken out from vcontext V0.05
19728 + *  V0.02  changed vcmds to vxi arg
19729 + *  V0.03  added memory cgroup support
19730 + *
19731 + */
19732 +
19733 +#include <linux/sched.h>
19734 +#include <linux/module.h>
19735 +#include <linux/memcontrol.h>
19736 +#include <linux/res_counter.h>
19737 +#include <linux/vs_limit.h>
19738 +#include <linux/vserver/limit.h>
19739 +#include <linux/vserver/limit_cmd.h>
19740 +
19741 +#include <asm/uaccess.h>
19742 +
19743 +
19744 +const char *vlimit_name[NUM_LIMITS] = {
19745 +       [RLIMIT_CPU]            = "CPU",
19746 +       [RLIMIT_NPROC]          = "NPROC",
19747 +       [RLIMIT_NOFILE]         = "NOFILE",
19748 +       [RLIMIT_LOCKS]          = "LOCKS",
19749 +       [RLIMIT_SIGPENDING]     = "SIGP",
19750 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19751 +
19752 +       [VLIMIT_NSOCK]          = "NSOCK",
19753 +       [VLIMIT_OPENFD]         = "OPENFD",
19754 +       [VLIMIT_SHMEM]          = "SHMEM",
19755 +       [VLIMIT_DENTRY]         = "DENTRY",
19756 +};
19757 +
19758 +EXPORT_SYMBOL_GPL(vlimit_name);
19759 +
19760 +#define MASK_ENTRY(x)  (1 << (x))
19761 +
19762 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19763 +               /* minimum */
19764 +       0
19765 +       ,       /* softlimit */
19766 +       0
19767 +       ,       /* maximum */
19768 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19769 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19770 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19771 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19772 +
19773 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19774 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19775 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19776 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19777 +       0
19778 +};
19779 +               /* accounting only */
19780 +uint32_t account_mask =
19781 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19782 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19783 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19784 +       0;
19785 +
19786 +
19787 +static int is_valid_vlimit(int id)
19788 +{
19789 +       uint32_t mask = vlimit_mask.minimum |
19790 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19791 +       return mask & (1 << id);
19792 +}
19793 +
19794 +static int is_accounted_vlimit(int id)
19795 +{
19796 +       if (is_valid_vlimit(id))
19797 +               return 1;
19798 +       return account_mask & (1 << id);
19799 +}
19800 +
19801 +
19802 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19803 +{
19804 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19805 +       return VX_VLIM(limit);
19806 +}
19807 +
19808 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19809 +{
19810 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19811 +       return VX_VLIM(limit);
19812 +}
19813 +
19814 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19815 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19816 +{
19817 +       if (!is_valid_vlimit(id))
19818 +               return -EINVAL;
19819 +
19820 +       if (minimum)
19821 +               *minimum = CRLIM_UNSET;
19822 +       if (softlimit)
19823 +               *softlimit = vc_get_soft(vxi, id);
19824 +       if (maximum)
19825 +               *maximum = vc_get_hard(vxi, id);
19826 +       return 0;
19827 +}
19828 +
19829 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19830 +{
19831 +       struct vcmd_ctx_rlimit_v0 vc_data;
19832 +       int ret;
19833 +
19834 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19835 +               return -EFAULT;
19836 +
19837 +       ret = do_get_rlimit(vxi, vc_data.id,
19838 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19839 +       if (ret)
19840 +               return ret;
19841 +
19842 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19843 +               return -EFAULT;
19844 +       return 0;
19845 +}
19846 +
19847 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19848 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19849 +{
19850 +       if (!is_valid_vlimit(id))
19851 +               return -EINVAL;
19852 +
19853 +       if (maximum != CRLIM_KEEP)
19854 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19855 +       if (softlimit != CRLIM_KEEP)
19856 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19857 +
19858 +       /* clamp soft limit */
19859 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19860 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19861 +
19862 +       return 0;
19863 +}
19864 +
19865 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19866 +{
19867 +       struct vcmd_ctx_rlimit_v0 vc_data;
19868 +
19869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19870 +               return -EFAULT;
19871 +
19872 +       return do_set_rlimit(vxi, vc_data.id,
19873 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19874 +}
19875 +
19876 +#ifdef CONFIG_IA32_EMULATION
19877 +
19878 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19879 +{
19880 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19881 +
19882 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19883 +               return -EFAULT;
19884 +
19885 +       return do_set_rlimit(vxi, vc_data.id,
19886 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19887 +}
19888 +
19889 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19890 +{
19891 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19892 +       int ret;
19893 +
19894 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19895 +               return -EFAULT;
19896 +
19897 +       ret = do_get_rlimit(vxi, vc_data.id,
19898 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19899 +       if (ret)
19900 +               return ret;
19901 +
19902 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19903 +               return -EFAULT;
19904 +       return 0;
19905 +}
19906 +
19907 +#endif /* CONFIG_IA32_EMULATION */
19908 +
19909 +
19910 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19911 +{
19912 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19913 +               return -EFAULT;
19914 +       return 0;
19915 +}
19916 +
19917 +
19918 +static inline void vx_reset_hits(struct _vx_limit *limit)
19919 +{
19920 +       int lim;
19921 +
19922 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19923 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19924 +       }
19925 +}
19926 +
19927 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19928 +{
19929 +       vx_reset_hits(&vxi->limit);
19930 +       return 0;
19931 +}
19932 +
19933 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19934 +{
19935 +       rlim_t value;
19936 +       int lim;
19937 +
19938 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19939 +               value = __rlim_get(limit, lim);
19940 +               __rlim_rmax(limit, lim) = value;
19941 +               __rlim_rmin(limit, lim) = value;
19942 +       }
19943 +}
19944 +
19945 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19946 +{
19947 +       vx_reset_minmax(&vxi->limit);
19948 +       return 0;
19949 +}
19950 +
19951 +
19952 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19953 +{
19954 +       struct vcmd_rlimit_stat_v0 vc_data;
19955 +       struct _vx_limit *limit = &vxi->limit;
19956 +       int id;
19957 +
19958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19959 +               return -EFAULT;
19960 +
19961 +       id = vc_data.id;
19962 +       if (!is_accounted_vlimit(id))
19963 +               return -EINVAL;
19964 +
19965 +       vx_limit_fixup(limit, id);
19966 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19967 +       vc_data.value = __rlim_get(limit, id);
19968 +       vc_data.minimum = __rlim_rmin(limit, id);
19969 +       vc_data.maximum = __rlim_rmax(limit, id);
19970 +
19971 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19972 +               return -EFAULT;
19973 +       return 0;
19974 +}
19975 +
19976 +
19977 +void vx_vsi_meminfo(struct sysinfo *val)
19978 +{
19979 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19980 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
19981 +       u64 res_limit, res_usage;
19982 +
19983 +       if (!mcg)
19984 +               return;
19985 +
19986 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19987 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19988 +
19989 +       if (res_limit != RESOURCE_MAX)
19990 +               val->totalram = (res_limit >> PAGE_SHIFT);
19991 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19992 +       val->bufferram = 0;
19993 +       val->totalhigh = 0;
19994 +       val->freehigh = 0;
19995 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19996 +       return;
19997 +}
19998 +
19999 +void vx_vsi_swapinfo(struct sysinfo *val)
20000 +{
20001 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20002 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20003 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20004 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20005 +       s64 swap_limit, swap_usage;
20006 +
20007 +       if (!mcg)
20008 +               return;
20009 +
20010 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20011 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20012 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20013 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20014 +
20015 +       /* memory unlimited */
20016 +       if (res_limit == RESOURCE_MAX)
20017 +               return;
20018 +
20019 +       swap_limit = memsw_limit - res_limit;
20020 +       /* we have a swap limit? */
20021 +       if (memsw_limit != RESOURCE_MAX)
20022 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20023 +
20024 +       /* calculate swap part */
20025 +       swap_usage = (memsw_usage > res_usage) ?
20026 +               memsw_usage - res_usage : 0;
20027 +
20028 +       /* total shown minus usage gives free swap */
20029 +       val->freeswap = (swap_usage < swap_limit) ?
20030 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20031 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20032 +       val->totalswap = 0;
20033 +       val->freeswap = 0;
20034 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20035 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20036 +       return;
20037 +}
20038 +
20039 +long vx_vsi_cached(struct sysinfo *val)
20040 +{
20041 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20042 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20043 +
20044 +       return mem_cgroup_stat_read_cache(mcg);
20045 +#else
20046 +       return 0;
20047 +#endif
20048 +}
20049 +
20050 diff -NurpP --minimal linux-3.2.8/kernel/vserver/limit_init.h linux-3.2.8-vs2.3.2.7/kernel/vserver/limit_init.h
20051 --- linux-3.2.8/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
20052 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/limit_init.h   2011-12-05 19:33:02.000000000 +0100
20053 @@ -0,0 +1,31 @@
20054 +
20055 +
20056 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20057 +{
20058 +       int lim;
20059 +
20060 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20061 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20062 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20063 +               __rlim_set(limit, lim, 0);
20064 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20065 +               __rlim_rmin(limit, lim) = 0;
20066 +               __rlim_rmax(limit, lim) = 0;
20067 +       }
20068 +}
20069 +
20070 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20071 +{
20072 +       rlim_t value;
20073 +       int lim;
20074 +
20075 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20076 +               if ((1 << lim) & VLIM_NOCHECK)
20077 +                       continue;
20078 +               value = __rlim_get(limit, lim);
20079 +               vxwprintk_xid(value,
20080 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20081 +                       limit, vlimit_name[lim], lim, (long)value);
20082 +       }
20083 +}
20084 +
20085 diff -NurpP --minimal linux-3.2.8/kernel/vserver/limit_proc.h linux-3.2.8-vs2.3.2.7/kernel/vserver/limit_proc.h
20086 --- linux-3.2.8/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20087 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/limit_proc.h   2011-12-05 19:33:02.000000000 +0100
20088 @@ -0,0 +1,57 @@
20089 +#ifndef _VX_LIMIT_PROC_H
20090 +#define _VX_LIMIT_PROC_H
20091 +
20092 +#include <linux/vserver/limit_int.h>
20093 +
20094 +
20095 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20096 +#define VX_LIMIT_TOP   \
20097 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20098 +
20099 +#define VX_LIMIT_ARG(r)                                \
20100 +       (unsigned long)__rlim_get(limit, r),    \
20101 +       (unsigned long)__rlim_rmin(limit, r),   \
20102 +       (unsigned long)__rlim_rmax(limit, r),   \
20103 +       VX_VLIM(__rlim_soft(limit, r)),         \
20104 +       VX_VLIM(__rlim_hard(limit, r)),         \
20105 +       atomic_read(&__rlim_lhit(limit, r))
20106 +
20107 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20108 +{
20109 +       vx_limit_fixup(limit, -1);
20110 +       return sprintf(buffer, VX_LIMIT_TOP
20111 +               "PROC"  VX_LIMIT_FMT
20112 +               "VM"    VX_LIMIT_FMT
20113 +               "VML"   VX_LIMIT_FMT
20114 +               "RSS"   VX_LIMIT_FMT
20115 +               "ANON"  VX_LIMIT_FMT
20116 +               "RMAP"  VX_LIMIT_FMT
20117 +               "FILES" VX_LIMIT_FMT
20118 +               "OFD"   VX_LIMIT_FMT
20119 +               "LOCKS" VX_LIMIT_FMT
20120 +               "SOCK"  VX_LIMIT_FMT
20121 +               "MSGQ"  VX_LIMIT_FMT
20122 +               "SHM"   VX_LIMIT_FMT
20123 +               "SEMA"  VX_LIMIT_FMT
20124 +               "SEMS"  VX_LIMIT_FMT
20125 +               "DENT"  VX_LIMIT_FMT,
20126 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20127 +               VX_LIMIT_ARG(RLIMIT_AS),
20128 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20129 +               VX_LIMIT_ARG(RLIMIT_RSS),
20130 +               VX_LIMIT_ARG(VLIMIT_ANON),
20131 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20132 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20133 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20134 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20135 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20136 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20137 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20138 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20139 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20140 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20141 +}
20142 +
20143 +#endif /* _VX_LIMIT_PROC_H */
20144 +
20145 +
20146 diff -NurpP --minimal linux-3.2.8/kernel/vserver/network.c linux-3.2.8-vs2.3.2.7/kernel/vserver/network.c
20147 --- linux-3.2.8/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20148 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/network.c      2011-12-05 19:33:02.000000000 +0100
20149 @@ -0,0 +1,912 @@
20150 +/*
20151 + *  linux/kernel/vserver/network.c
20152 + *
20153 + *  Virtual Server: Network Support
20154 + *
20155 + *  Copyright (C) 2003-2007  Herbert Pötzl
20156 + *
20157 + *  V0.01  broken out from vcontext V0.05
20158 + *  V0.02  cleaned up implementation
20159 + *  V0.03  added equiv nx commands
20160 + *  V0.04  switch to RCU based hash
20161 + *  V0.05  and back to locking again
20162 + *  V0.06  changed vcmds to nxi arg
20163 + *  V0.07  have __create claim() the nxi
20164 + *
20165 + */
20166 +
20167 +#include <linux/err.h>
20168 +#include <linux/slab.h>
20169 +#include <linux/rcupdate.h>
20170 +
20171 +#include <linux/vs_network.h>
20172 +#include <linux/vs_pid.h>
20173 +#include <linux/vserver/network_cmd.h>
20174 +
20175 +
20176 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20177 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20178 +
20179 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20180 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20181 +
20182 +
20183 +static int __init init_network(void)
20184 +{
20185 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20186 +               sizeof(struct nx_addr_v4), 0,
20187 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20188 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20189 +               sizeof(struct nx_addr_v6), 0,
20190 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20191 +       return 0;
20192 +}
20193 +
20194 +
20195 +/*     __alloc_nx_addr_v4()                                    */
20196 +
20197 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20198 +{
20199 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20200 +               nx_addr_v4_cachep, GFP_KERNEL);
20201 +
20202 +       if (!IS_ERR(nxa))
20203 +               memset(nxa, 0, sizeof(*nxa));
20204 +       return nxa;
20205 +}
20206 +
20207 +/*     __dealloc_nx_addr_v4()                                  */
20208 +
20209 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20210 +{
20211 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20212 +}
20213 +
20214 +/*     __dealloc_nx_addr_v4_all()                              */
20215 +
20216 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20217 +{
20218 +       while (nxa) {
20219 +               struct nx_addr_v4 *next = nxa->next;
20220 +
20221 +               __dealloc_nx_addr_v4(nxa);
20222 +               nxa = next;
20223 +       }
20224 +}
20225 +
20226 +
20227 +#ifdef CONFIG_IPV6
20228 +
20229 +/*     __alloc_nx_addr_v6()                                    */
20230 +
20231 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20232 +{
20233 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20234 +               nx_addr_v6_cachep, GFP_KERNEL);
20235 +
20236 +       if (!IS_ERR(nxa))
20237 +               memset(nxa, 0, sizeof(*nxa));
20238 +       return nxa;
20239 +}
20240 +
20241 +/*     __dealloc_nx_addr_v6()                                  */
20242 +
20243 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20244 +{
20245 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20246 +}
20247 +
20248 +/*     __dealloc_nx_addr_v6_all()                              */
20249 +
20250 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20251 +{
20252 +       while (nxa) {
20253 +               struct nx_addr_v6 *next = nxa->next;
20254 +
20255 +               __dealloc_nx_addr_v6(nxa);
20256 +               nxa = next;
20257 +       }
20258 +}
20259 +
20260 +#endif /* CONFIG_IPV6 */
20261 +
20262 +/*     __alloc_nx_info()
20263 +
20264 +       * allocate an initialized nx_info struct
20265 +       * doesn't make it visible (hash)                        */
20266 +
20267 +static struct nx_info *__alloc_nx_info(nid_t nid)
20268 +{
20269 +       struct nx_info *new = NULL;
20270 +
20271 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20272 +
20273 +       /* would this benefit from a slab cache? */
20274 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20275 +       if (!new)
20276 +               return 0;
20277 +
20278 +       memset(new, 0, sizeof(struct nx_info));
20279 +       new->nx_id = nid;
20280 +       INIT_HLIST_NODE(&new->nx_hlist);
20281 +       atomic_set(&new->nx_usecnt, 0);
20282 +       atomic_set(&new->nx_tasks, 0);
20283 +       new->nx_state = 0;
20284 +
20285 +       new->nx_flags = NXF_INIT_SET;
20286 +
20287 +       /* rest of init goes here */
20288 +
20289 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20290 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20291 +
20292 +       vxdprintk(VXD_CBIT(nid, 0),
20293 +               "alloc_nx_info(%d) = %p", nid, new);
20294 +       atomic_inc(&nx_global_ctotal);
20295 +       return new;
20296 +}
20297 +
20298 +/*     __dealloc_nx_info()
20299 +
20300 +       * final disposal of nx_info                             */
20301 +
20302 +static void __dealloc_nx_info(struct nx_info *nxi)
20303 +{
20304 +       vxdprintk(VXD_CBIT(nid, 0),
20305 +               "dealloc_nx_info(%p)", nxi);
20306 +
20307 +       nxi->nx_hlist.next = LIST_POISON1;
20308 +       nxi->nx_id = -1;
20309 +
20310 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20311 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20312 +
20313 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20314 +
20315 +       nxi->nx_state |= NXS_RELEASED;
20316 +       kfree(nxi);
20317 +       atomic_dec(&nx_global_ctotal);
20318 +}
20319 +
20320 +static void __shutdown_nx_info(struct nx_info *nxi)
20321 +{
20322 +       nxi->nx_state |= NXS_SHUTDOWN;
20323 +       vs_net_change(nxi, VSC_NETDOWN);
20324 +}
20325 +
20326 +/*     exported stuff                                          */
20327 +
20328 +void free_nx_info(struct nx_info *nxi)
20329 +{
20330 +       /* context shutdown is mandatory */
20331 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20332 +
20333 +       /* context must not be hashed */
20334 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20335 +
20336 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20337 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20338 +
20339 +       __dealloc_nx_info(nxi);
20340 +}
20341 +
20342 +
20343 +void __nx_set_lback(struct nx_info *nxi)
20344 +{
20345 +       int nid = nxi->nx_id;
20346 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20347 +
20348 +       nxi->v4_lback.s_addr = lback;
20349 +}
20350 +
20351 +extern int __nx_inet_add_lback(__be32 addr);
20352 +extern int __nx_inet_del_lback(__be32 addr);
20353 +
20354 +
20355 +/*     hash table for nx_info hash */
20356 +
20357 +#define NX_HASH_SIZE   13
20358 +
20359 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20360 +
20361 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20362 +
20363 +
20364 +static inline unsigned int __hashval(nid_t nid)
20365 +{
20366 +       return (nid % NX_HASH_SIZE);
20367 +}
20368 +
20369 +
20370 +
20371 +/*     __hash_nx_info()
20372 +
20373 +       * add the nxi to the global hash table
20374 +       * requires the hash_lock to be held                     */
20375 +
20376 +static inline void __hash_nx_info(struct nx_info *nxi)
20377 +{
20378 +       struct hlist_head *head;
20379 +
20380 +       vxd_assert_lock(&nx_info_hash_lock);
20381 +       vxdprintk(VXD_CBIT(nid, 4),
20382 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20383 +
20384 +       /* context must not be hashed */
20385 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20386 +
20387 +       nxi->nx_state |= NXS_HASHED;
20388 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20389 +       hlist_add_head(&nxi->nx_hlist, head);
20390 +       atomic_inc(&nx_global_cactive);
20391 +}
20392 +
20393 +/*     __unhash_nx_info()
20394 +
20395 +       * remove the nxi from the global hash table
20396 +       * requires the hash_lock to be held                     */
20397 +
20398 +static inline void __unhash_nx_info(struct nx_info *nxi)
20399 +{
20400 +       vxd_assert_lock(&nx_info_hash_lock);
20401 +       vxdprintk(VXD_CBIT(nid, 4),
20402 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20403 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20404 +
20405 +       /* context must be hashed */
20406 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20407 +       /* but without tasks */
20408 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20409 +
20410 +       nxi->nx_state &= ~NXS_HASHED;
20411 +       hlist_del(&nxi->nx_hlist);
20412 +       atomic_dec(&nx_global_cactive);
20413 +}
20414 +
20415 +
20416 +/*     __lookup_nx_info()
20417 +
20418 +       * requires the hash_lock to be held
20419 +       * doesn't increment the nx_refcnt                       */
20420 +
20421 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20422 +{
20423 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20424 +       struct hlist_node *pos;
20425 +       struct nx_info *nxi;
20426 +
20427 +       vxd_assert_lock(&nx_info_hash_lock);
20428 +       hlist_for_each(pos, head) {
20429 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20430 +
20431 +               if (nxi->nx_id == nid)
20432 +                       goto found;
20433 +       }
20434 +       nxi = NULL;
20435 +found:
20436 +       vxdprintk(VXD_CBIT(nid, 0),
20437 +               "__lookup_nx_info(#%u): %p[#%u]",
20438 +               nid, nxi, nxi ? nxi->nx_id : 0);
20439 +       return nxi;
20440 +}
20441 +
20442 +
20443 +/*     __create_nx_info()
20444 +
20445 +       * create the requested context
20446 +       * get(), claim() and hash it                            */
20447 +
20448 +static struct nx_info *__create_nx_info(int id)
20449 +{
20450 +       struct nx_info *new, *nxi = NULL;
20451 +
20452 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20453 +
20454 +       if (!(new = __alloc_nx_info(id)))
20455 +               return ERR_PTR(-ENOMEM);
20456 +
20457 +       /* required to make dynamic xids unique */
20458 +       spin_lock(&nx_info_hash_lock);
20459 +
20460 +       /* static context requested */
20461 +       if ((nxi = __lookup_nx_info(id))) {
20462 +               vxdprintk(VXD_CBIT(nid, 0),
20463 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20464 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20465 +                       nxi = ERR_PTR(-EBUSY);
20466 +               else
20467 +                       nxi = ERR_PTR(-EEXIST);
20468 +               goto out_unlock;
20469 +       }
20470 +       /* new context */
20471 +       vxdprintk(VXD_CBIT(nid, 0),
20472 +               "create_nx_info(%d) = %p (new)", id, new);
20473 +       claim_nx_info(new, NULL);
20474 +       __nx_set_lback(new);
20475 +       __hash_nx_info(get_nx_info(new));
20476 +       nxi = new, new = NULL;
20477 +
20478 +out_unlock:
20479 +       spin_unlock(&nx_info_hash_lock);
20480 +       if (new)
20481 +               __dealloc_nx_info(new);
20482 +       return nxi;
20483 +}
20484 +
20485 +
20486 +
20487 +/*     exported stuff                                          */
20488 +
20489 +
20490 +void unhash_nx_info(struct nx_info *nxi)
20491 +{
20492 +       __shutdown_nx_info(nxi);
20493 +       spin_lock(&nx_info_hash_lock);
20494 +       __unhash_nx_info(nxi);
20495 +       spin_unlock(&nx_info_hash_lock);
20496 +}
20497 +
20498 +/*     lookup_nx_info()
20499 +
20500 +       * search for a nx_info and get() it
20501 +       * negative id means current                             */
20502 +
20503 +struct nx_info *lookup_nx_info(int id)
20504 +{
20505 +       struct nx_info *nxi = NULL;
20506 +
20507 +       if (id < 0) {
20508 +               nxi = get_nx_info(current_nx_info());
20509 +       } else if (id > 1) {
20510 +               spin_lock(&nx_info_hash_lock);
20511 +               nxi = get_nx_info(__lookup_nx_info(id));
20512 +               spin_unlock(&nx_info_hash_lock);
20513 +       }
20514 +       return nxi;
20515 +}
20516 +
20517 +/*     nid_is_hashed()
20518 +
20519 +       * verify that nid is still hashed                       */
20520 +
20521 +int nid_is_hashed(nid_t nid)
20522 +{
20523 +       int hashed;
20524 +
20525 +       spin_lock(&nx_info_hash_lock);
20526 +       hashed = (__lookup_nx_info(nid) != NULL);
20527 +       spin_unlock(&nx_info_hash_lock);
20528 +       return hashed;
20529 +}
20530 +
20531 +
20532 +#ifdef CONFIG_PROC_FS
20533 +
20534 +/*     get_nid_list()
20535 +
20536 +       * get a subset of hashed nids for proc
20537 +       * assumes size is at least one                          */
20538 +
20539 +int get_nid_list(int index, unsigned int *nids, int size)
20540 +{
20541 +       int hindex, nr_nids = 0;
20542 +
20543 +       /* only show current and children */
20544 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20545 +               if (index > 0)
20546 +                       return 0;
20547 +               nids[nr_nids] = nx_current_nid();
20548 +               return 1;
20549 +       }
20550 +
20551 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20552 +               struct hlist_head *head = &nx_info_hash[hindex];
20553 +               struct hlist_node *pos;
20554 +
20555 +               spin_lock(&nx_info_hash_lock);
20556 +               hlist_for_each(pos, head) {
20557 +                       struct nx_info *nxi;
20558 +
20559 +                       if (--index > 0)
20560 +                               continue;
20561 +
20562 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20563 +                       nids[nr_nids] = nxi->nx_id;
20564 +                       if (++nr_nids >= size) {
20565 +                               spin_unlock(&nx_info_hash_lock);
20566 +                               goto out;
20567 +                       }
20568 +               }
20569 +               /* keep the lock time short */
20570 +               spin_unlock(&nx_info_hash_lock);
20571 +       }
20572 +out:
20573 +       return nr_nids;
20574 +}
20575 +#endif
20576 +
20577 +
20578 +/*
20579 + *     migrate task to new network
20580 + *     gets nxi, puts old_nxi on change
20581 + */
20582 +
20583 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20584 +{
20585 +       struct nx_info *old_nxi;
20586 +       int ret = 0;
20587 +
20588 +       if (!p || !nxi)
20589 +               BUG();
20590 +
20591 +       vxdprintk(VXD_CBIT(nid, 5),
20592 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20593 +               p, nxi, nxi->nx_id,
20594 +               atomic_read(&nxi->nx_usecnt),
20595 +               atomic_read(&nxi->nx_tasks));
20596 +
20597 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20598 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20599 +               return -EACCES;
20600 +
20601 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20602 +               return -EFAULT;
20603 +
20604 +       /* maybe disallow this completely? */
20605 +       old_nxi = task_get_nx_info(p);
20606 +       if (old_nxi == nxi)
20607 +               goto out;
20608 +
20609 +       task_lock(p);
20610 +       if (old_nxi)
20611 +               clr_nx_info(&p->nx_info);
20612 +       claim_nx_info(nxi, p);
20613 +       set_nx_info(&p->nx_info, nxi);
20614 +       p->nid = nxi->nx_id;
20615 +       task_unlock(p);
20616 +
20617 +       vxdprintk(VXD_CBIT(nid, 5),
20618 +               "moved task %p into nxi:%p[#%d]",
20619 +               p, nxi, nxi->nx_id);
20620 +
20621 +       if (old_nxi)
20622 +               release_nx_info(old_nxi, p);
20623 +       ret = 0;
20624 +out:
20625 +       put_nx_info(old_nxi);
20626 +       return ret;
20627 +}
20628 +
20629 +
20630 +void nx_set_persistent(struct nx_info *nxi)
20631 +{
20632 +       vxdprintk(VXD_CBIT(nid, 6),
20633 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20634 +
20635 +       get_nx_info(nxi);
20636 +       claim_nx_info(nxi, NULL);
20637 +}
20638 +
20639 +void nx_clear_persistent(struct nx_info *nxi)
20640 +{
20641 +       vxdprintk(VXD_CBIT(nid, 6),
20642 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20643 +
20644 +       release_nx_info(nxi, NULL);
20645 +       put_nx_info(nxi);
20646 +}
20647 +
20648 +void nx_update_persistent(struct nx_info *nxi)
20649 +{
20650 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20651 +               nx_set_persistent(nxi);
20652 +       else
20653 +               nx_clear_persistent(nxi);
20654 +}
20655 +
20656 +/* vserver syscall commands below here */
20657 +
20658 +/* taks nid and nx_info functions */
20659 +
20660 +#include <asm/uaccess.h>
20661 +
20662 +
20663 +int vc_task_nid(uint32_t id)
20664 +{
20665 +       nid_t nid;
20666 +
20667 +       if (id) {
20668 +               struct task_struct *tsk;
20669 +
20670 +               rcu_read_lock();
20671 +               tsk = find_task_by_real_pid(id);
20672 +               nid = (tsk) ? tsk->nid : -ESRCH;
20673 +               rcu_read_unlock();
20674 +       } else
20675 +               nid = nx_current_nid();
20676 +       return nid;
20677 +}
20678 +
20679 +
20680 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20681 +{
20682 +       struct vcmd_nx_info_v0 vc_data;
20683 +
20684 +       vc_data.nid = nxi->nx_id;
20685 +
20686 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20687 +               return -EFAULT;
20688 +       return 0;
20689 +}
20690 +
20691 +
20692 +/* network functions */
20693 +
20694 +int vc_net_create(uint32_t nid, void __user *data)
20695 +{
20696 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20697 +       struct nx_info *new_nxi;
20698 +       int ret;
20699 +
20700 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20701 +               return -EFAULT;
20702 +
20703 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20704 +               return -EINVAL;
20705 +
20706 +       new_nxi = __create_nx_info(nid);
20707 +       if (IS_ERR(new_nxi))
20708 +               return PTR_ERR(new_nxi);
20709 +
20710 +       /* initial flags */
20711 +       new_nxi->nx_flags = vc_data.flagword;
20712 +
20713 +       ret = -ENOEXEC;
20714 +       if (vs_net_change(new_nxi, VSC_NETUP))
20715 +               goto out;
20716 +
20717 +       ret = nx_migrate_task(current, new_nxi);
20718 +       if (ret)
20719 +               goto out;
20720 +
20721 +       /* return context id on success */
20722 +       ret = new_nxi->nx_id;
20723 +
20724 +       /* get a reference for persistent contexts */
20725 +       if ((vc_data.flagword & NXF_PERSISTENT))
20726 +               nx_set_persistent(new_nxi);
20727 +out:
20728 +       release_nx_info(new_nxi, NULL);
20729 +       put_nx_info(new_nxi);
20730 +       return ret;
20731 +}
20732 +
20733 +
20734 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20735 +{
20736 +       return nx_migrate_task(current, nxi);
20737 +}
20738 +
20739 +
20740 +
20741 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20742 +       uint16_t type, uint16_t flags)
20743 +{
20744 +       struct nx_addr_v4 *nxa = &nxi->v4;
20745 +
20746 +       if (NX_IPV4(nxi)) {
20747 +               /* locate last entry */
20748 +               for (; nxa->next; nxa = nxa->next);
20749 +               nxa->next = __alloc_nx_addr_v4();
20750 +               nxa = nxa->next;
20751 +
20752 +               if (IS_ERR(nxa))
20753 +                       return PTR_ERR(nxa);
20754 +       }
20755 +
20756 +       if (nxi->v4.next)
20757 +               /* remove single ip for ip list */
20758 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20759 +
20760 +       nxa->ip[0].s_addr = ip;
20761 +       nxa->ip[1].s_addr = ip2;
20762 +       nxa->mask.s_addr = mask;
20763 +       nxa->type = type;
20764 +       nxa->flags = flags;
20765 +       return 0;
20766 +}
20767 +
20768 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20769 +       uint16_t type, uint16_t flags)
20770 +{
20771 +       struct nx_addr_v4 *nxa = &nxi->v4;
20772 +
20773 +       switch (type) {
20774 +/*     case NXA_TYPE_ADDR:
20775 +               break;          */
20776 +
20777 +       case NXA_TYPE_ANY:
20778 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20779 +               memset(nxa, 0, sizeof(*nxa));
20780 +               break;
20781 +
20782 +       default:
20783 +               return -EINVAL;
20784 +       }
20785 +       return 0;
20786 +}
20787 +
20788 +
20789 +int vc_net_add(struct nx_info *nxi, void __user *data)
20790 +{
20791 +       struct vcmd_net_addr_v0 vc_data;
20792 +       int index, ret = 0;
20793 +
20794 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20795 +               return -EFAULT;
20796 +
20797 +       switch (vc_data.type) {
20798 +       case NXA_TYPE_IPV4:
20799 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20800 +                       return -EINVAL;
20801 +
20802 +               index = 0;
20803 +               while (index < vc_data.count) {
20804 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20805 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20806 +                       if (ret)
20807 +                               return ret;
20808 +                       index++;
20809 +               }
20810 +               ret = index;
20811 +               break;
20812 +
20813 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20814 +               nxi->v4_bcast = vc_data.ip[0];
20815 +               ret = 1;
20816 +               break;
20817 +
20818 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20819 +               nxi->v4_lback = vc_data.ip[0];
20820 +               ret = 1;
20821 +               break;
20822 +
20823 +       default:
20824 +               ret = -EINVAL;
20825 +               break;
20826 +       }
20827 +       return ret;
20828 +}
20829 +
20830 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20831 +{
20832 +       struct vcmd_net_addr_v0 vc_data;
20833 +
20834 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20835 +               return -EFAULT;
20836 +
20837 +       switch (vc_data.type) {
20838 +       case NXA_TYPE_ANY:
20839 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20840 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20841 +               break;
20842 +
20843 +       default:
20844 +               return -EINVAL;
20845 +       }
20846 +       return 0;
20847 +}
20848 +
20849 +
20850 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20851 +{
20852 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20853 +
20854 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20855 +               return -EFAULT;
20856 +
20857 +       switch (vc_data.type) {
20858 +       case NXA_TYPE_ADDR:
20859 +       case NXA_TYPE_MASK:
20860 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20861 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20862 +
20863 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20864 +               nxi->v4_bcast = vc_data.ip;
20865 +               break;
20866 +
20867 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20868 +               nxi->v4_lback = vc_data.ip;
20869 +               break;
20870 +
20871 +       default:
20872 +               return -EINVAL;
20873 +       }
20874 +       return 0;
20875 +}
20876 +
20877 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20878 +{
20879 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20880 +
20881 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20882 +               return -EFAULT;
20883 +
20884 +       switch (vc_data.type) {
20885 +       case NXA_TYPE_ADDR:
20886 +       case NXA_TYPE_MASK:
20887 +       case NXA_TYPE_RANGE:
20888 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20889 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20890 +
20891 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20892 +               nxi->v4_bcast = vc_data.ip;
20893 +               break;
20894 +
20895 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20896 +               nxi->v4_lback = vc_data.ip;
20897 +               break;
20898 +
20899 +       default:
20900 +               return -EINVAL;
20901 +       }
20902 +       return 0;
20903 +}
20904 +
20905 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20906 +{
20907 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20908 +
20909 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20910 +               return -EFAULT;
20911 +
20912 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20913 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20914 +}
20915 +
20916 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20917 +{
20918 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20919 +
20920 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20921 +               return -EFAULT;
20922 +
20923 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20924 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20925 +}
20926 +
20927 +#ifdef CONFIG_IPV6
20928 +
20929 +int do_add_v6_addr(struct nx_info *nxi,
20930 +       struct in6_addr *ip, struct in6_addr *mask,
20931 +       uint32_t prefix, uint16_t type, uint16_t flags)
20932 +{
20933 +       struct nx_addr_v6 *nxa = &nxi->v6;
20934 +
20935 +       if (NX_IPV6(nxi)) {
20936 +               /* locate last entry */
20937 +               for (; nxa->next; nxa = nxa->next);
20938 +               nxa->next = __alloc_nx_addr_v6();
20939 +               nxa = nxa->next;
20940 +
20941 +               if (IS_ERR(nxa))
20942 +                       return PTR_ERR(nxa);
20943 +       }
20944 +
20945 +       nxa->ip = *ip;
20946 +       nxa->mask = *mask;
20947 +       nxa->prefix = prefix;
20948 +       nxa->type = type;
20949 +       nxa->flags = flags;
20950 +       return 0;
20951 +}
20952 +
20953 +
20954 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20955 +{
20956 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20957 +
20958 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20959 +               return -EFAULT;
20960 +
20961 +       switch (vc_data.type) {
20962 +       case NXA_TYPE_ADDR:
20963 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20964 +               /* fallthrough */
20965 +       case NXA_TYPE_MASK:
20966 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20967 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20968 +       default:
20969 +               return -EINVAL;
20970 +       }
20971 +       return 0;
20972 +}
20973 +
20974 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20975 +{
20976 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20977 +
20978 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20979 +               return -EFAULT;
20980 +
20981 +       switch (vc_data.type) {
20982 +       case NXA_TYPE_ANY:
20983 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20984 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20985 +               break;
20986 +
20987 +       default:
20988 +               return -EINVAL;
20989 +       }
20990 +       return 0;
20991 +}
20992 +
20993 +#endif /* CONFIG_IPV6 */
20994 +
20995 +
20996 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20997 +{
20998 +       struct vcmd_net_flags_v0 vc_data;
20999 +
21000 +       vc_data.flagword = nxi->nx_flags;
21001 +
21002 +       /* special STATE flag handling */
21003 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21004 +
21005 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21006 +               return -EFAULT;
21007 +       return 0;
21008 +}
21009 +
21010 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21011 +{
21012 +       struct vcmd_net_flags_v0 vc_data;
21013 +       uint64_t mask, trigger;
21014 +
21015 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21016 +               return -EFAULT;
21017 +
21018 +       /* special STATE flag handling */
21019 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21020 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21021 +
21022 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21023 +               vc_data.flagword, mask);
21024 +       if (trigger & NXF_PERSISTENT)
21025 +               nx_update_persistent(nxi);
21026 +
21027 +       return 0;
21028 +}
21029 +
21030 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21031 +{
21032 +       struct vcmd_net_caps_v0 vc_data;
21033 +
21034 +       vc_data.ncaps = nxi->nx_ncaps;
21035 +       vc_data.cmask = ~0ULL;
21036 +
21037 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21038 +               return -EFAULT;
21039 +       return 0;
21040 +}
21041 +
21042 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21043 +{
21044 +       struct vcmd_net_caps_v0 vc_data;
21045 +
21046 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21047 +               return -EFAULT;
21048 +
21049 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21050 +               vc_data.ncaps, vc_data.cmask);
21051 +       return 0;
21052 +}
21053 +
21054 +
21055 +#include <linux/module.h>
21056 +
21057 +module_init(init_network);
21058 +
21059 +EXPORT_SYMBOL_GPL(free_nx_info);
21060 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21061 +
21062 diff -NurpP --minimal linux-3.2.8/kernel/vserver/proc.c linux-3.2.8-vs2.3.2.7/kernel/vserver/proc.c
21063 --- linux-3.2.8/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21064 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/proc.c 2011-12-06 23:19:52.000000000 +0100
21065 @@ -0,0 +1,1103 @@
21066 +/*
21067 + *  linux/kernel/vserver/proc.c
21068 + *
21069 + *  Virtual Context Support
21070 + *
21071 + *  Copyright (C) 2003-2011  Herbert Pötzl
21072 + *
21073 + *  V0.01  basic structure
21074 + *  V0.02  adaptation vs1.3.0
21075 + *  V0.03  proc permissions
21076 + *  V0.04  locking/generic
21077 + *  V0.05  next generation procfs
21078 + *  V0.06  inode validation
21079 + *  V0.07  generic rewrite vid
21080 + *  V0.08  remove inode type
21081 + *  V0.09  added u/wmask info
21082 + *
21083 + */
21084 +
21085 +#include <linux/proc_fs.h>
21086 +#include <linux/fs_struct.h>
21087 +#include <linux/mount.h>
21088 +#include <asm/unistd.h>
21089 +
21090 +#include <linux/vs_context.h>
21091 +#include <linux/vs_network.h>
21092 +#include <linux/vs_cvirt.h>
21093 +
21094 +#include <linux/in.h>
21095 +#include <linux/inetdevice.h>
21096 +#include <linux/vs_inet.h>
21097 +#include <linux/vs_inet6.h>
21098 +
21099 +#include <linux/vserver/global.h>
21100 +
21101 +#include "cvirt_proc.h"
21102 +#include "cacct_proc.h"
21103 +#include "limit_proc.h"
21104 +#include "sched_proc.h"
21105 +#include "vci_config.h"
21106 +
21107 +
21108 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21109 +{
21110 +       unsigned __capi;
21111 +
21112 +       CAP_FOR_EACH_U32(__capi) {
21113 +               buffer += sprintf(buffer, "%08x",
21114 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21115 +       }
21116 +       return buffer;
21117 +}
21118 +
21119 +
21120 +static struct proc_dir_entry *proc_virtual;
21121 +
21122 +static struct proc_dir_entry *proc_virtnet;
21123 +
21124 +
21125 +/* first the actual feeds */
21126 +
21127 +
21128 +static int proc_vci(char *buffer)
21129 +{
21130 +       return sprintf(buffer,
21131 +               "VCIVersion:\t%04x:%04x\n"
21132 +               "VCISyscall:\t%d\n"
21133 +               "VCIKernel:\t%08x\n",
21134 +               VCI_VERSION >> 16,
21135 +               VCI_VERSION & 0xFFFF,
21136 +               __NR_vserver,
21137 +               vci_kernel_config());
21138 +}
21139 +
21140 +static int proc_virtual_info(char *buffer)
21141 +{
21142 +       return proc_vci(buffer);
21143 +}
21144 +
21145 +static int proc_virtual_status(char *buffer)
21146 +{
21147 +       return sprintf(buffer,
21148 +               "#CTotal:\t%d\n"
21149 +               "#CActive:\t%d\n"
21150 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21151 +               "#InitTask:\t%d\t%d %d\n",
21152 +               atomic_read(&vx_global_ctotal),
21153 +               atomic_read(&vx_global_cactive),
21154 +               atomic_read(&vs_global_nsproxy),
21155 +               atomic_read(&vs_global_fs),
21156 +               atomic_read(&vs_global_mnt_ns),
21157 +               atomic_read(&vs_global_uts_ns),
21158 +               atomic_read(&nr_ipc_ns),
21159 +               atomic_read(&vs_global_user_ns),
21160 +               atomic_read(&vs_global_pid_ns),
21161 +               atomic_read(&init_task.usage),
21162 +               atomic_read(&init_task.nsproxy->count),
21163 +               init_task.fs->users);
21164 +}
21165 +
21166 +
21167 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21168 +{
21169 +       int length;
21170 +
21171 +       length = sprintf(buffer,
21172 +               "ID:\t%d\n"
21173 +               "Info:\t%p\n"
21174 +               "Init:\t%d\n"
21175 +               "OOM:\t%lld\n",
21176 +               vxi->vx_id,
21177 +               vxi,
21178 +               vxi->vx_initpid,
21179 +               vxi->vx_badness_bias);
21180 +       return length;
21181 +}
21182 +
21183 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21184 +{
21185 +       char *orig = buffer;
21186 +
21187 +       buffer += sprintf(buffer,
21188 +               "UseCnt:\t%d\n"
21189 +               "Tasks:\t%d\n"
21190 +               "Flags:\t%016llx\n",
21191 +               atomic_read(&vxi->vx_usecnt),
21192 +               atomic_read(&vxi->vx_tasks),
21193 +               (unsigned long long)vxi->vx_flags);
21194 +
21195 +       buffer += sprintf(buffer, "BCaps:\t");
21196 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21197 +       buffer += sprintf(buffer, "\n");
21198 +
21199 +       buffer += sprintf(buffer,
21200 +               "CCaps:\t%016llx\n"
21201 +               "Umask:\t%16llx\n"
21202 +               "Wmask:\t%16llx\n"
21203 +               "Spaces:\t%08lx %08lx\n",
21204 +               (unsigned long long)vxi->vx_ccaps,
21205 +               (unsigned long long)vxi->vx_umask,
21206 +               (unsigned long long)vxi->vx_wmask,
21207 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21208 +       return buffer - orig;
21209 +}
21210 +
21211 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21212 +{
21213 +       return vx_info_proc_limit(&vxi->limit, buffer);
21214 +}
21215 +
21216 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21217 +{
21218 +       int cpu, length;
21219 +
21220 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21221 +       for_each_online_cpu(cpu) {
21222 +               length += vx_info_proc_sched_pc(
21223 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21224 +                       buffer + length, cpu);
21225 +       }
21226 +       return length;
21227 +}
21228 +
21229 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21230 +{
21231 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21232 +}
21233 +
21234 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21235 +{
21236 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21237 +}
21238 +
21239 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21240 +{
21241 +       int cpu, length;
21242 +
21243 +       vx_update_load(vxi);
21244 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21245 +       for_each_online_cpu(cpu) {
21246 +               length += vx_info_proc_cvirt_pc(
21247 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21248 +                       buffer + length, cpu);
21249 +       }
21250 +       return length;
21251 +}
21252 +
21253 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21254 +{
21255 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21256 +}
21257 +
21258 +
21259 +static int proc_virtnet_info(char *buffer)
21260 +{
21261 +       return proc_vci(buffer);
21262 +}
21263 +
21264 +static int proc_virtnet_status(char *buffer)
21265 +{
21266 +       return sprintf(buffer,
21267 +               "#CTotal:\t%d\n"
21268 +               "#CActive:\t%d\n",
21269 +               atomic_read(&nx_global_ctotal),
21270 +               atomic_read(&nx_global_cactive));
21271 +}
21272 +
21273 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21274 +{
21275 +       struct nx_addr_v4 *v4a;
21276 +#ifdef CONFIG_IPV6
21277 +       struct nx_addr_v6 *v6a;
21278 +#endif
21279 +       int length, i;
21280 +
21281 +       length = sprintf(buffer,
21282 +               "ID:\t%d\n"
21283 +               "Info:\t%p\n"
21284 +               "Bcast:\t" NIPQUAD_FMT "\n"
21285 +               "Lback:\t" NIPQUAD_FMT "\n",
21286 +               nxi->nx_id,
21287 +               nxi,
21288 +               NIPQUAD(nxi->v4_bcast.s_addr),
21289 +               NIPQUAD(nxi->v4_lback.s_addr));
21290 +
21291 +       if (!NX_IPV4(nxi))
21292 +               goto skip_v4;
21293 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21294 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21295 +                       i, NXAV4(v4a));
21296 +skip_v4:
21297 +#ifdef CONFIG_IPV6
21298 +       if (!NX_IPV6(nxi))
21299 +               goto skip_v6;
21300 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21301 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21302 +                       i, NXAV6(v6a));
21303 +skip_v6:
21304 +#endif
21305 +       return length;
21306 +}
21307 +
21308 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21309 +{
21310 +       int length;
21311 +
21312 +       length = sprintf(buffer,
21313 +               "UseCnt:\t%d\n"
21314 +               "Tasks:\t%d\n"
21315 +               "Flags:\t%016llx\n"
21316 +               "NCaps:\t%016llx\n",
21317 +               atomic_read(&nxi->nx_usecnt),
21318 +               atomic_read(&nxi->nx_tasks),
21319 +               (unsigned long long)nxi->nx_flags,
21320 +               (unsigned long long)nxi->nx_ncaps);
21321 +       return length;
21322 +}
21323 +
21324 +
21325 +
21326 +/* here the inode helpers */
21327 +
21328 +struct vs_entry {
21329 +       int len;
21330 +       char *name;
21331 +       mode_t mode;
21332 +       struct inode_operations *iop;
21333 +       struct file_operations *fop;
21334 +       union proc_op op;
21335 +};
21336 +
21337 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21338 +{
21339 +       struct inode *inode = new_inode(sb);
21340 +
21341 +       if (!inode)
21342 +               goto out;
21343 +
21344 +       inode->i_mode = p->mode;
21345 +       if (p->iop)
21346 +               inode->i_op = p->iop;
21347 +       if (p->fop)
21348 +               inode->i_fop = p->fop;
21349 +
21350 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21351 +       inode->i_flags |= S_IMMUTABLE;
21352 +
21353 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21354 +
21355 +       inode->i_uid = 0;
21356 +       inode->i_gid = 0;
21357 +       inode->i_tag = 0;
21358 +out:
21359 +       return inode;
21360 +}
21361 +
21362 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21363 +       struct dentry *dentry, int id, void *ptr)
21364 +{
21365 +       struct vs_entry *p = ptr;
21366 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21367 +       struct dentry *error = ERR_PTR(-EINVAL);
21368 +
21369 +       if (!inode)
21370 +               goto out;
21371 +
21372 +       PROC_I(inode)->op = p->op;
21373 +       PROC_I(inode)->fd = id;
21374 +       d_add(dentry, inode);
21375 +       error = NULL;
21376 +out:
21377 +       return error;
21378 +}
21379 +
21380 +/* Lookups */
21381 +
21382 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21383 +
21384 +/*
21385 + * Fill a directory entry.
21386 + *
21387 + * If possible create the dcache entry and derive our inode number and
21388 + * file type from dcache entry.
21389 + *
21390 + * Since all of the proc inode numbers are dynamically generated, the inode
21391 + * numbers do not exist until the inode is cache.  This means creating the
21392 + * the dcache entry in readdir is necessary to keep the inode numbers
21393 + * reported by readdir in sync with the inode numbers reported
21394 + * by stat.
21395 + */
21396 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21397 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21398 +{
21399 +       struct dentry *child, *dir = filp->f_dentry;
21400 +       struct inode *inode;
21401 +       struct qstr qname;
21402 +       ino_t ino = 0;
21403 +       unsigned type = DT_UNKNOWN;
21404 +
21405 +       qname.name = name;
21406 +       qname.len  = len;
21407 +       qname.hash = full_name_hash(name, len);
21408 +
21409 +       child = d_lookup(dir, &qname);
21410 +       if (!child) {
21411 +               struct dentry *new;
21412 +               new = d_alloc(dir, &qname);
21413 +               if (new) {
21414 +                       child = instantiate(dir->d_inode, new, id, ptr);
21415 +                       if (child)
21416 +                               dput(new);
21417 +                       else
21418 +                               child = new;
21419 +               }
21420 +       }
21421 +       if (!child || IS_ERR(child) || !child->d_inode)
21422 +               goto end_instantiate;
21423 +       inode = child->d_inode;
21424 +       if (inode) {
21425 +               ino = inode->i_ino;
21426 +               type = inode->i_mode >> 12;
21427 +       }
21428 +       dput(child);
21429 +end_instantiate:
21430 +       if (!ino)
21431 +               ino = find_inode_number(dir, &qname);
21432 +       if (!ino)
21433 +               ino = 1;
21434 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21435 +}
21436 +
21437 +
21438 +
21439 +/* get and revalidate vx_info/xid */
21440 +
21441 +static inline
21442 +struct vx_info *get_proc_vx_info(struct inode *inode)
21443 +{
21444 +       return lookup_vx_info(PROC_I(inode)->fd);
21445 +}
21446 +
21447 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21448 +{
21449 +       struct inode *inode = dentry->d_inode;
21450 +       xid_t xid = PROC_I(inode)->fd;
21451 +
21452 +       if (!xid || xid_is_hashed(xid))
21453 +               return 1;
21454 +       d_drop(dentry);
21455 +       return 0;
21456 +}
21457 +
21458 +
21459 +/* get and revalidate nx_info/nid */
21460 +
21461 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21462 +{
21463 +       struct inode *inode = dentry->d_inode;
21464 +       nid_t nid = PROC_I(inode)->fd;
21465 +
21466 +       if (!nid || nid_is_hashed(nid))
21467 +               return 1;
21468 +       d_drop(dentry);
21469 +       return 0;
21470 +}
21471 +
21472 +
21473 +
21474 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21475 +
21476 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21477 +                         size_t count, loff_t *ppos)
21478 +{
21479 +       struct inode *inode = file->f_dentry->d_inode;
21480 +       unsigned long page;
21481 +       ssize_t length = 0;
21482 +
21483 +       if (count > PROC_BLOCK_SIZE)
21484 +               count = PROC_BLOCK_SIZE;
21485 +
21486 +       /* fade that out as soon as stable */
21487 +       WARN_ON(PROC_I(inode)->fd);
21488 +
21489 +       if (!(page = __get_free_page(GFP_KERNEL)))
21490 +               return -ENOMEM;
21491 +
21492 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21493 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21494 +
21495 +       if (length >= 0)
21496 +               length = simple_read_from_buffer(buf, count, ppos,
21497 +                       (char *)page, length);
21498 +
21499 +       free_page(page);
21500 +       return length;
21501 +}
21502 +
21503 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21504 +                         size_t count, loff_t *ppos)
21505 +{
21506 +       struct inode *inode = file->f_dentry->d_inode;
21507 +       struct vx_info *vxi = NULL;
21508 +       xid_t xid = PROC_I(inode)->fd;
21509 +       unsigned long page;
21510 +       ssize_t length = 0;
21511 +
21512 +       if (count > PROC_BLOCK_SIZE)
21513 +               count = PROC_BLOCK_SIZE;
21514 +
21515 +       /* fade that out as soon as stable */
21516 +       WARN_ON(!xid);
21517 +       vxi = lookup_vx_info(xid);
21518 +       if (!vxi)
21519 +               goto out;
21520 +
21521 +       length = -ENOMEM;
21522 +       if (!(page = __get_free_page(GFP_KERNEL)))
21523 +               goto out_put;
21524 +
21525 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21526 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21527 +
21528 +       if (length >= 0)
21529 +               length = simple_read_from_buffer(buf, count, ppos,
21530 +                       (char *)page, length);
21531 +
21532 +       free_page(page);
21533 +out_put:
21534 +       put_vx_info(vxi);
21535 +out:
21536 +       return length;
21537 +}
21538 +
21539 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21540 +                         size_t count, loff_t *ppos)
21541 +{
21542 +       struct inode *inode = file->f_dentry->d_inode;
21543 +       struct nx_info *nxi = NULL;
21544 +       nid_t nid = PROC_I(inode)->fd;
21545 +       unsigned long page;
21546 +       ssize_t length = 0;
21547 +
21548 +       if (count > PROC_BLOCK_SIZE)
21549 +               count = PROC_BLOCK_SIZE;
21550 +
21551 +       /* fade that out as soon as stable */
21552 +       WARN_ON(!nid);
21553 +       nxi = lookup_nx_info(nid);
21554 +       if (!nxi)
21555 +               goto out;
21556 +
21557 +       length = -ENOMEM;
21558 +       if (!(page = __get_free_page(GFP_KERNEL)))
21559 +               goto out_put;
21560 +
21561 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21562 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21563 +
21564 +       if (length >= 0)
21565 +               length = simple_read_from_buffer(buf, count, ppos,
21566 +                       (char *)page, length);
21567 +
21568 +       free_page(page);
21569 +out_put:
21570 +       put_nx_info(nxi);
21571 +out:
21572 +       return length;
21573 +}
21574 +
21575 +
21576 +
21577 +/* here comes the lower level */
21578 +
21579 +
21580 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21581 +       .len  = sizeof(NAME) - 1,       \
21582 +       .name = (NAME),                 \
21583 +       .mode = MODE,                   \
21584 +       .iop  = IOP,                    \
21585 +       .fop  = FOP,                    \
21586 +       .op   = OP,                     \
21587 +}
21588 +
21589 +
21590 +#define DIR(NAME, MODE, OTYPE)                         \
21591 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21592 +               &proc_ ## OTYPE ## _inode_operations,   \
21593 +               &proc_ ## OTYPE ## _file_operations, { } )
21594 +
21595 +#define INF(NAME, MODE, OTYPE)                         \
21596 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21597 +               &proc_vs_info_file_operations,          \
21598 +               { .proc_vs_read = &proc_##OTYPE } )
21599 +
21600 +#define VINF(NAME, MODE, OTYPE)                                \
21601 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21602 +               &proc_vx_info_file_operations,          \
21603 +               { .proc_vxi_read = &proc_##OTYPE } )
21604 +
21605 +#define NINF(NAME, MODE, OTYPE)                                \
21606 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21607 +               &proc_nx_info_file_operations,          \
21608 +               { .proc_nxi_read = &proc_##OTYPE } )
21609 +
21610 +
21611 +static struct file_operations proc_vs_info_file_operations = {
21612 +       .read =         proc_vs_info_read,
21613 +};
21614 +
21615 +static struct file_operations proc_vx_info_file_operations = {
21616 +       .read =         proc_vx_info_read,
21617 +};
21618 +
21619 +static struct dentry_operations proc_xid_dentry_operations = {
21620 +       .d_revalidate = proc_xid_revalidate,
21621 +};
21622 +
21623 +static struct vs_entry vx_base_stuff[] = {
21624 +       VINF("info",    S_IRUGO, vxi_info),
21625 +       VINF("status",  S_IRUGO, vxi_status),
21626 +       VINF("limit",   S_IRUGO, vxi_limit),
21627 +       VINF("sched",   S_IRUGO, vxi_sched),
21628 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21629 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21630 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21631 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21632 +       {}
21633 +};
21634 +
21635 +
21636 +
21637 +
21638 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21639 +       struct dentry *dentry, int id, void *ptr)
21640 +{
21641 +       dentry->d_op = &proc_xid_dentry_operations;
21642 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21643 +}
21644 +
21645 +static struct dentry *proc_xid_lookup(struct inode *dir,
21646 +       struct dentry *dentry, struct nameidata *nd)
21647 +{
21648 +       struct vs_entry *p = vx_base_stuff;
21649 +       struct dentry *error = ERR_PTR(-ENOENT);
21650 +
21651 +       for (; p->name; p++) {
21652 +               if (p->len != dentry->d_name.len)
21653 +                       continue;
21654 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21655 +                       break;
21656 +       }
21657 +       if (!p->name)
21658 +               goto out;
21659 +
21660 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21661 +out:
21662 +       return error;
21663 +}
21664 +
21665 +static int proc_xid_readdir(struct file *filp,
21666 +       void *dirent, filldir_t filldir)
21667 +{
21668 +       struct dentry *dentry = filp->f_dentry;
21669 +       struct inode *inode = dentry->d_inode;
21670 +       struct vs_entry *p = vx_base_stuff;
21671 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21672 +       int pos, index;
21673 +       u64 ino;
21674 +
21675 +       pos = filp->f_pos;
21676 +       switch (pos) {
21677 +       case 0:
21678 +               ino = inode->i_ino;
21679 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21680 +                       goto out;
21681 +               pos++;
21682 +               /* fall through */
21683 +       case 1:
21684 +               ino = parent_ino(dentry);
21685 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21686 +                       goto out;
21687 +               pos++;
21688 +               /* fall through */
21689 +       default:
21690 +               index = pos - 2;
21691 +               if (index >= size)
21692 +                       goto out;
21693 +               for (p += index; p->name; p++) {
21694 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21695 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21696 +                               goto out;
21697 +                       pos++;
21698 +               }
21699 +       }
21700 +out:
21701 +       filp->f_pos = pos;
21702 +       return 1;
21703 +}
21704 +
21705 +
21706 +
21707 +static struct file_operations proc_nx_info_file_operations = {
21708 +       .read =         proc_nx_info_read,
21709 +};
21710 +
21711 +static struct dentry_operations proc_nid_dentry_operations = {
21712 +       .d_revalidate = proc_nid_revalidate,
21713 +};
21714 +
21715 +static struct vs_entry nx_base_stuff[] = {
21716 +       NINF("info",    S_IRUGO, nxi_info),
21717 +       NINF("status",  S_IRUGO, nxi_status),
21718 +       {}
21719 +};
21720 +
21721 +
21722 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21723 +       struct dentry *dentry, int id, void *ptr)
21724 +{
21725 +       dentry->d_op = &proc_nid_dentry_operations;
21726 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21727 +}
21728 +
21729 +static struct dentry *proc_nid_lookup(struct inode *dir,
21730 +       struct dentry *dentry, struct nameidata *nd)
21731 +{
21732 +       struct vs_entry *p = nx_base_stuff;
21733 +       struct dentry *error = ERR_PTR(-ENOENT);
21734 +
21735 +       for (; p->name; p++) {
21736 +               if (p->len != dentry->d_name.len)
21737 +                       continue;
21738 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21739 +                       break;
21740 +       }
21741 +       if (!p->name)
21742 +               goto out;
21743 +
21744 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21745 +out:
21746 +       return error;
21747 +}
21748 +
21749 +static int proc_nid_readdir(struct file *filp,
21750 +       void *dirent, filldir_t filldir)
21751 +{
21752 +       struct dentry *dentry = filp->f_dentry;
21753 +       struct inode *inode = dentry->d_inode;
21754 +       struct vs_entry *p = nx_base_stuff;
21755 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21756 +       int pos, index;
21757 +       u64 ino;
21758 +
21759 +       pos = filp->f_pos;
21760 +       switch (pos) {
21761 +       case 0:
21762 +               ino = inode->i_ino;
21763 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21764 +                       goto out;
21765 +               pos++;
21766 +               /* fall through */
21767 +       case 1:
21768 +               ino = parent_ino(dentry);
21769 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21770 +                       goto out;
21771 +               pos++;
21772 +               /* fall through */
21773 +       default:
21774 +               index = pos - 2;
21775 +               if (index >= size)
21776 +                       goto out;
21777 +               for (p += index; p->name; p++) {
21778 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21779 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21780 +                               goto out;
21781 +                       pos++;
21782 +               }
21783 +       }
21784 +out:
21785 +       filp->f_pos = pos;
21786 +       return 1;
21787 +}
21788 +
21789 +
21790 +#define MAX_MULBY10    ((~0U - 9) / 10)
21791 +
21792 +static inline int atovid(const char *str, int len)
21793 +{
21794 +       int vid, c;
21795 +
21796 +       vid = 0;
21797 +       while (len-- > 0) {
21798 +               c = *str - '0';
21799 +               str++;
21800 +               if (c > 9)
21801 +                       return -1;
21802 +               if (vid >= MAX_MULBY10)
21803 +                       return -1;
21804 +               vid *= 10;
21805 +               vid += c;
21806 +               if (!vid)
21807 +                       return -1;
21808 +       }
21809 +       return vid;
21810 +}
21811 +
21812 +/* now the upper level (virtual) */
21813 +
21814 +
21815 +static struct file_operations proc_xid_file_operations = {
21816 +       .read =         generic_read_dir,
21817 +       .readdir =      proc_xid_readdir,
21818 +};
21819 +
21820 +static struct inode_operations proc_xid_inode_operations = {
21821 +       .lookup =       proc_xid_lookup,
21822 +};
21823 +
21824 +static struct vs_entry vx_virtual_stuff[] = {
21825 +       INF("info",     S_IRUGO, virtual_info),
21826 +       INF("status",   S_IRUGO, virtual_status),
21827 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21828 +};
21829 +
21830 +
21831 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21832 +       struct dentry *dentry, struct nameidata *nd)
21833 +{
21834 +       struct vs_entry *p = vx_virtual_stuff;
21835 +       struct dentry *error = ERR_PTR(-ENOENT);
21836 +       int id = 0;
21837 +
21838 +       for (; p->name; p++) {
21839 +               if (p->len != dentry->d_name.len)
21840 +                       continue;
21841 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21842 +                       break;
21843 +       }
21844 +       if (p->name)
21845 +               goto instantiate;
21846 +
21847 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21848 +       if ((id < 0) || !xid_is_hashed(id))
21849 +               goto out;
21850 +
21851 +instantiate:
21852 +       error = proc_xid_instantiate(dir, dentry, id, p);
21853 +out:
21854 +       return error;
21855 +}
21856 +
21857 +static struct file_operations proc_nid_file_operations = {
21858 +       .read =         generic_read_dir,
21859 +       .readdir =      proc_nid_readdir,
21860 +};
21861 +
21862 +static struct inode_operations proc_nid_inode_operations = {
21863 +       .lookup =       proc_nid_lookup,
21864 +};
21865 +
21866 +static struct vs_entry nx_virtnet_stuff[] = {
21867 +       INF("info",     S_IRUGO, virtnet_info),
21868 +       INF("status",   S_IRUGO, virtnet_status),
21869 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21870 +};
21871 +
21872 +
21873 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21874 +       struct dentry *dentry, struct nameidata *nd)
21875 +{
21876 +       struct vs_entry *p = nx_virtnet_stuff;
21877 +       struct dentry *error = ERR_PTR(-ENOENT);
21878 +       int id = 0;
21879 +
21880 +       for (; p->name; p++) {
21881 +               if (p->len != dentry->d_name.len)
21882 +                       continue;
21883 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21884 +                       break;
21885 +       }
21886 +       if (p->name)
21887 +               goto instantiate;
21888 +
21889 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21890 +       if ((id < 0) || !nid_is_hashed(id))
21891 +               goto out;
21892 +
21893 +instantiate:
21894 +       error = proc_nid_instantiate(dir, dentry, id, p);
21895 +out:
21896 +       return error;
21897 +}
21898 +
21899 +
21900 +#define PROC_MAXVIDS 32
21901 +
21902 +int proc_virtual_readdir(struct file *filp,
21903 +       void *dirent, filldir_t filldir)
21904 +{
21905 +       struct dentry *dentry = filp->f_dentry;
21906 +       struct inode *inode = dentry->d_inode;
21907 +       struct vs_entry *p = vx_virtual_stuff;
21908 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21909 +       int pos, index;
21910 +       unsigned int xid_array[PROC_MAXVIDS];
21911 +       char buf[PROC_NUMBUF];
21912 +       unsigned int nr_xids, i;
21913 +       u64 ino;
21914 +
21915 +       pos = filp->f_pos;
21916 +       switch (pos) {
21917 +       case 0:
21918 +               ino = inode->i_ino;
21919 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21920 +                       goto out;
21921 +               pos++;
21922 +               /* fall through */
21923 +       case 1:
21924 +               ino = parent_ino(dentry);
21925 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21926 +                       goto out;
21927 +               pos++;
21928 +               /* fall through */
21929 +       default:
21930 +               index = pos - 2;
21931 +               if (index >= size)
21932 +                       goto entries;
21933 +               for (p += index; p->name; p++) {
21934 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21935 +                               vs_proc_instantiate, 0, p))
21936 +                               goto out;
21937 +                       pos++;
21938 +               }
21939 +       entries:
21940 +               index = pos - size;
21941 +               p = &vx_virtual_stuff[size - 1];
21942 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21943 +               for (i = 0; i < nr_xids; i++) {
21944 +                       int n, xid = xid_array[i];
21945 +                       unsigned int j = PROC_NUMBUF;
21946 +
21947 +                       n = xid;
21948 +                       do
21949 +                               buf[--j] = '0' + (n % 10);
21950 +                       while (n /= 10);
21951 +
21952 +                       if (proc_fill_cache(filp, dirent, filldir,
21953 +                               buf + j, PROC_NUMBUF - j,
21954 +                               vs_proc_instantiate, xid, p))
21955 +                               goto out;
21956 +                       pos++;
21957 +               }
21958 +       }
21959 +out:
21960 +       filp->f_pos = pos;
21961 +       return 0;
21962 +}
21963 +
21964 +static int proc_virtual_getattr(struct vfsmount *mnt,
21965 +       struct dentry *dentry, struct kstat *stat)
21966 +{
21967 +       struct inode *inode = dentry->d_inode;
21968 +
21969 +       generic_fillattr(inode, stat);
21970 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21971 +       return 0;
21972 +}
21973 +
21974 +static struct file_operations proc_virtual_dir_operations = {
21975 +       .read =         generic_read_dir,
21976 +       .readdir =      proc_virtual_readdir,
21977 +};
21978 +
21979 +static struct inode_operations proc_virtual_dir_inode_operations = {
21980 +       .getattr =      proc_virtual_getattr,
21981 +       .lookup =       proc_virtual_lookup,
21982 +};
21983 +
21984 +
21985 +
21986 +
21987 +
21988 +int proc_virtnet_readdir(struct file *filp,
21989 +       void *dirent, filldir_t filldir)
21990 +{
21991 +       struct dentry *dentry = filp->f_dentry;
21992 +       struct inode *inode = dentry->d_inode;
21993 +       struct vs_entry *p = nx_virtnet_stuff;
21994 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21995 +       int pos, index;
21996 +       unsigned int nid_array[PROC_MAXVIDS];
21997 +       char buf[PROC_NUMBUF];
21998 +       unsigned int nr_nids, i;
21999 +       u64 ino;
22000 +
22001 +       pos = filp->f_pos;
22002 +       switch (pos) {
22003 +       case 0:
22004 +               ino = inode->i_ino;
22005 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22006 +                       goto out;
22007 +               pos++;
22008 +               /* fall through */
22009 +       case 1:
22010 +               ino = parent_ino(dentry);
22011 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22012 +                       goto out;
22013 +               pos++;
22014 +               /* fall through */
22015 +       default:
22016 +               index = pos - 2;
22017 +               if (index >= size)
22018 +                       goto entries;
22019 +               for (p += index; p->name; p++) {
22020 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22021 +                               vs_proc_instantiate, 0, p))
22022 +                               goto out;
22023 +                       pos++;
22024 +               }
22025 +       entries:
22026 +               index = pos - size;
22027 +               p = &nx_virtnet_stuff[size - 1];
22028 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22029 +               for (i = 0; i < nr_nids; i++) {
22030 +                       int n, nid = nid_array[i];
22031 +                       unsigned int j = PROC_NUMBUF;
22032 +
22033 +                       n = nid;
22034 +                       do
22035 +                               buf[--j] = '0' + (n % 10);
22036 +                       while (n /= 10);
22037 +
22038 +                       if (proc_fill_cache(filp, dirent, filldir,
22039 +                               buf + j, PROC_NUMBUF - j,
22040 +                               vs_proc_instantiate, nid, p))
22041 +                               goto out;
22042 +                       pos++;
22043 +               }
22044 +       }
22045 +out:
22046 +       filp->f_pos = pos;
22047 +       return 0;
22048 +}
22049 +
22050 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22051 +       struct dentry *dentry, struct kstat *stat)
22052 +{
22053 +       struct inode *inode = dentry->d_inode;
22054 +
22055 +       generic_fillattr(inode, stat);
22056 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22057 +       return 0;
22058 +}
22059 +
22060 +static struct file_operations proc_virtnet_dir_operations = {
22061 +       .read =         generic_read_dir,
22062 +       .readdir =      proc_virtnet_readdir,
22063 +};
22064 +
22065 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22066 +       .getattr =      proc_virtnet_getattr,
22067 +       .lookup =       proc_virtnet_lookup,
22068 +};
22069 +
22070 +
22071 +
22072 +void proc_vx_init(void)
22073 +{
22074 +       struct proc_dir_entry *ent;
22075 +
22076 +       ent = proc_mkdir("virtual", 0);
22077 +       if (ent) {
22078 +               ent->proc_fops = &proc_virtual_dir_operations;
22079 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22080 +       }
22081 +       proc_virtual = ent;
22082 +
22083 +       ent = proc_mkdir("virtnet", 0);
22084 +       if (ent) {
22085 +               ent->proc_fops = &proc_virtnet_dir_operations;
22086 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22087 +       }
22088 +       proc_virtnet = ent;
22089 +}
22090 +
22091 +
22092 +
22093 +
22094 +/* per pid info */
22095 +
22096 +
22097 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22098 +{
22099 +       struct vx_info *vxi;
22100 +       char *orig = buffer;
22101 +
22102 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22103 +
22104 +       vxi = task_get_vx_info(p);
22105 +       if (!vxi)
22106 +               goto out;
22107 +
22108 +       buffer += sprintf(buffer, "BCaps:\t");
22109 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22110 +       buffer += sprintf(buffer, "\n");
22111 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22112 +               (unsigned long long)vxi->vx_ccaps);
22113 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22114 +               (unsigned long long)vxi->vx_flags);
22115 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22116 +
22117 +       put_vx_info(vxi);
22118 +out:
22119 +       return buffer - orig;
22120 +}
22121 +
22122 +
22123 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22124 +{
22125 +       struct nx_info *nxi;
22126 +       struct nx_addr_v4 *v4a;
22127 +#ifdef CONFIG_IPV6
22128 +       struct nx_addr_v6 *v6a;
22129 +#endif
22130 +       char *orig = buffer;
22131 +       int i;
22132 +
22133 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22134 +
22135 +       nxi = task_get_nx_info(p);
22136 +       if (!nxi)
22137 +               goto out;
22138 +
22139 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22140 +               (unsigned long long)nxi->nx_ncaps);
22141 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22142 +               (unsigned long long)nxi->nx_flags);
22143 +
22144 +       buffer += sprintf(buffer,
22145 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22146 +               NIPQUAD(nxi->v4_bcast.s_addr));
22147 +       buffer += sprintf (buffer,
22148 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22149 +               NIPQUAD(nxi->v4_lback.s_addr));
22150 +       if (!NX_IPV4(nxi))
22151 +               goto skip_v4;
22152 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22153 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22154 +                       i, NXAV4(v4a));
22155 +skip_v4:
22156 +#ifdef CONFIG_IPV6
22157 +       if (!NX_IPV6(nxi))
22158 +               goto skip_v6;
22159 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22160 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22161 +                       i, NXAV6(v6a));
22162 +skip_v6:
22163 +#endif
22164 +       put_nx_info(nxi);
22165 +out:
22166 +       return buffer - orig;
22167 +}
22168 +
22169 diff -NurpP --minimal linux-3.2.8/kernel/vserver/sched.c linux-3.2.8-vs2.3.2.7/kernel/vserver/sched.c
22170 --- linux-3.2.8/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22171 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/sched.c        2011-12-05 19:33:02.000000000 +0100
22172 @@ -0,0 +1,82 @@
22173 +/*
22174 + *  linux/kernel/vserver/sched.c
22175 + *
22176 + *  Virtual Server: Scheduler Support
22177 + *
22178 + *  Copyright (C) 2004-2010  Herbert Pötzl
22179 + *
22180 + *  V0.01  adapted Sam Vilains version to 2.6.3
22181 + *  V0.02  removed legacy interface
22182 + *  V0.03  changed vcmds to vxi arg
22183 + *  V0.04  removed older and legacy interfaces
22184 + *  V0.05  removed scheduler code/commands
22185 + *
22186 + */
22187 +
22188 +#include <linux/vs_context.h>
22189 +#include <linux/vs_sched.h>
22190 +#include <linux/vserver/sched_cmd.h>
22191 +
22192 +#include <asm/uaccess.h>
22193 +
22194 +
22195 +void vx_update_sched_param(struct _vx_sched *sched,
22196 +       struct _vx_sched_pc *sched_pc)
22197 +{
22198 +       sched_pc->prio_bias = sched->prio_bias;
22199 +}
22200 +
22201 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22202 +{
22203 +       int cpu;
22204 +
22205 +       if (data->prio_bias > MAX_PRIO_BIAS)
22206 +               data->prio_bias = MAX_PRIO_BIAS;
22207 +       if (data->prio_bias < MIN_PRIO_BIAS)
22208 +               data->prio_bias = MIN_PRIO_BIAS;
22209 +
22210 +       if (data->cpu_id != ~0) {
22211 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22212 +               cpus_and(vxi->sched.update, cpu_online_map,
22213 +                       vxi->sched.update);
22214 +       } else
22215 +               vxi->sched.update = cpu_online_map;
22216 +
22217 +       for_each_cpu_mask(cpu, vxi->sched.update)
22218 +               vx_update_sched_param(&vxi->sched,
22219 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22220 +       return 0;
22221 +}
22222 +
22223 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22224 +{
22225 +       struct vcmd_prio_bias vc_data;
22226 +
22227 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22228 +               return -EFAULT;
22229 +
22230 +       return do_set_prio_bias(vxi, &vc_data);
22231 +}
22232 +
22233 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22234 +{
22235 +       struct vcmd_prio_bias vc_data;
22236 +       struct _vx_sched_pc *pcd;
22237 +       int cpu;
22238 +
22239 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22240 +               return -EFAULT;
22241 +
22242 +       cpu = vc_data.cpu_id;
22243 +
22244 +       if (!cpu_possible(cpu))
22245 +               return -EINVAL;
22246 +
22247 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22248 +       vc_data.prio_bias = pcd->prio_bias;
22249 +
22250 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22251 +               return -EFAULT;
22252 +       return 0;
22253 +}
22254 +
22255 diff -NurpP --minimal linux-3.2.8/kernel/vserver/sched_init.h linux-3.2.8-vs2.3.2.7/kernel/vserver/sched_init.h
22256 --- linux-3.2.8/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22257 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/sched_init.h   2011-12-05 19:33:02.000000000 +0100
22258 @@ -0,0 +1,27 @@
22259 +
22260 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22261 +{
22262 +       /* scheduling; hard code starting values as constants */
22263 +       sched->prio_bias = 0;
22264 +}
22265 +
22266 +static inline
22267 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22268 +{
22269 +       sched_pc->prio_bias = 0;
22270 +
22271 +       sched_pc->user_ticks = 0;
22272 +       sched_pc->sys_ticks = 0;
22273 +       sched_pc->hold_ticks = 0;
22274 +}
22275 +
22276 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22277 +{
22278 +       return;
22279 +}
22280 +
22281 +static inline
22282 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22283 +{
22284 +       return;
22285 +}
22286 diff -NurpP --minimal linux-3.2.8/kernel/vserver/sched_proc.h linux-3.2.8-vs2.3.2.7/kernel/vserver/sched_proc.h
22287 --- linux-3.2.8/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22288 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/sched_proc.h   2011-12-05 19:33:02.000000000 +0100
22289 @@ -0,0 +1,32 @@
22290 +#ifndef _VX_SCHED_PROC_H
22291 +#define _VX_SCHED_PROC_H
22292 +
22293 +
22294 +static inline
22295 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22296 +{
22297 +       int length = 0;
22298 +
22299 +       length += sprintf(buffer,
22300 +               "PrioBias:\t%8d\n",
22301 +               sched->prio_bias);
22302 +       return length;
22303 +}
22304 +
22305 +static inline
22306 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22307 +       char *buffer, int cpu)
22308 +{
22309 +       int length = 0;
22310 +
22311 +       length += sprintf(buffer + length,
22312 +               "cpu %d: %lld %lld %lld", cpu,
22313 +               (unsigned long long)sched_pc->user_ticks,
22314 +               (unsigned long long)sched_pc->sys_ticks,
22315 +               (unsigned long long)sched_pc->hold_ticks);
22316 +       length += sprintf(buffer + length,
22317 +               " %d\n", sched_pc->prio_bias);
22318 +       return length;
22319 +}
22320 +
22321 +#endif /* _VX_SCHED_PROC_H */
22322 diff -NurpP --minimal linux-3.2.8/kernel/vserver/signal.c linux-3.2.8-vs2.3.2.7/kernel/vserver/signal.c
22323 --- linux-3.2.8/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22324 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/signal.c       2011-12-05 19:33:02.000000000 +0100
22325 @@ -0,0 +1,134 @@
22326 +/*
22327 + *  linux/kernel/vserver/signal.c
22328 + *
22329 + *  Virtual Server: Signal Support
22330 + *
22331 + *  Copyright (C) 2003-2007  Herbert Pötzl
22332 + *
22333 + *  V0.01  broken out from vcontext V0.05
22334 + *  V0.02  changed vcmds to vxi arg
22335 + *  V0.03  adjusted siginfo for kill
22336 + *
22337 + */
22338 +
22339 +#include <asm/uaccess.h>
22340 +
22341 +#include <linux/vs_context.h>
22342 +#include <linux/vs_pid.h>
22343 +#include <linux/vserver/signal_cmd.h>
22344 +
22345 +
22346 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22347 +{
22348 +       int retval, count = 0;
22349 +       struct task_struct *p;
22350 +       struct siginfo *sip = SEND_SIG_PRIV;
22351 +
22352 +       retval = -ESRCH;
22353 +       vxdprintk(VXD_CBIT(misc, 4),
22354 +               "vx_info_kill(%p[#%d],%d,%d)*",
22355 +               vxi, vxi->vx_id, pid, sig);
22356 +       read_lock(&tasklist_lock);
22357 +       switch (pid) {
22358 +       case  0:
22359 +       case -1:
22360 +               for_each_process(p) {
22361 +                       int err = 0;
22362 +
22363 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22364 +                               (pid && vxi->vx_initpid == p->pid))
22365 +                               continue;
22366 +
22367 +                       err = group_send_sig_info(sig, sip, p);
22368 +                       ++count;
22369 +                       if (err != -EPERM)
22370 +                               retval = err;
22371 +               }
22372 +               break;
22373 +
22374 +       case 1:
22375 +               if (vxi->vx_initpid) {
22376 +                       pid = vxi->vx_initpid;
22377 +                       /* for now, only SIGINT to private init ... */
22378 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22379 +                               /* ... as long as there are tasks left */
22380 +                               (atomic_read(&vxi->vx_tasks) > 1))
22381 +                               sig = SIGINT;
22382 +               }
22383 +               /* fallthrough */
22384 +       default:
22385 +               rcu_read_lock();
22386 +               p = find_task_by_real_pid(pid);
22387 +               rcu_read_unlock();
22388 +               if (p) {
22389 +                       if (vx_task_xid(p) == vxi->vx_id)
22390 +                               retval = group_send_sig_info(sig, sip, p);
22391 +               }
22392 +               break;
22393 +       }
22394 +       read_unlock(&tasklist_lock);
22395 +       vxdprintk(VXD_CBIT(misc, 4),
22396 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22397 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22398 +       return retval;
22399 +}
22400 +
22401 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22402 +{
22403 +       struct vcmd_ctx_kill_v0 vc_data;
22404 +
22405 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22406 +               return -EFAULT;
22407 +
22408 +       /* special check to allow guest shutdown */
22409 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22410 +               /* forbid killall pid=0 when init is present */
22411 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22412 +               (vc_data.pid > 1)))
22413 +               return -EACCES;
22414 +
22415 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22416 +}
22417 +
22418 +
22419 +static int __wait_exit(struct vx_info *vxi)
22420 +{
22421 +       DECLARE_WAITQUEUE(wait, current);
22422 +       int ret = 0;
22423 +
22424 +       add_wait_queue(&vxi->vx_wait, &wait);
22425 +       set_current_state(TASK_INTERRUPTIBLE);
22426 +
22427 +wait:
22428 +       if (vx_info_state(vxi,
22429 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22430 +               goto out;
22431 +       if (signal_pending(current)) {
22432 +               ret = -ERESTARTSYS;
22433 +               goto out;
22434 +       }
22435 +       schedule();
22436 +       goto wait;
22437 +
22438 +out:
22439 +       set_current_state(TASK_RUNNING);
22440 +       remove_wait_queue(&vxi->vx_wait, &wait);
22441 +       return ret;
22442 +}
22443 +
22444 +
22445 +
22446 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22447 +{
22448 +       struct vcmd_wait_exit_v0 vc_data;
22449 +       int ret;
22450 +
22451 +       ret = __wait_exit(vxi);
22452 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22453 +       vc_data.exit_code = vxi->exit_code;
22454 +
22455 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22456 +               ret = -EFAULT;
22457 +       return ret;
22458 +}
22459 +
22460 diff -NurpP --minimal linux-3.2.8/kernel/vserver/space.c linux-3.2.8-vs2.3.2.7/kernel/vserver/space.c
22461 --- linux-3.2.8/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22462 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/space.c        2011-12-05 19:33:02.000000000 +0100
22463 @@ -0,0 +1,435 @@
22464 +/*
22465 + *  linux/kernel/vserver/space.c
22466 + *
22467 + *  Virtual Server: Context Space Support
22468 + *
22469 + *  Copyright (C) 2003-2010  Herbert Pötzl
22470 + *
22471 + *  V0.01  broken out from context.c 0.07
22472 + *  V0.02  added task locking for namespace
22473 + *  V0.03  broken out vx_enter_namespace
22474 + *  V0.04  added *space support and commands
22475 + *  V0.05  added credential support
22476 + *
22477 + */
22478 +
22479 +#include <linux/utsname.h>
22480 +#include <linux/nsproxy.h>
22481 +#include <linux/err.h>
22482 +#include <linux/fs_struct.h>
22483 +#include <linux/cred.h>
22484 +#include <asm/uaccess.h>
22485 +
22486 +#include <linux/vs_context.h>
22487 +#include <linux/vserver/space.h>
22488 +#include <linux/vserver/space_cmd.h>
22489 +
22490 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22491 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22492 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22493 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22494 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22495 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22496 +
22497 +
22498 +/* namespace functions */
22499 +
22500 +#include <linux/mnt_namespace.h>
22501 +#include <linux/user_namespace.h>
22502 +#include <linux/pid_namespace.h>
22503 +#include <linux/ipc_namespace.h>
22504 +#include <net/net_namespace.h>
22505 +
22506 +
22507 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22508 +       .mask = CLONE_FS |
22509 +               CLONE_NEWNS |
22510 +#ifdef CONFIG_UTS_NS
22511 +               CLONE_NEWUTS |
22512 +#endif
22513 +#ifdef CONFIG_IPC_NS
22514 +               CLONE_NEWIPC |
22515 +#endif
22516 +#ifdef CONFIG_USER_NS
22517 +               CLONE_NEWUSER |
22518 +#endif
22519 +               0
22520 +};
22521 +
22522 +static const struct vcmd_space_mask_v1 space_mask = {
22523 +       .mask = CLONE_FS |
22524 +               CLONE_NEWNS |
22525 +#ifdef CONFIG_UTS_NS
22526 +               CLONE_NEWUTS |
22527 +#endif
22528 +#ifdef CONFIG_IPC_NS
22529 +               CLONE_NEWIPC |
22530 +#endif
22531 +#ifdef CONFIG_USER_NS
22532 +               CLONE_NEWUSER |
22533 +#endif
22534 +#ifdef CONFIG_PID_NS
22535 +               CLONE_NEWPID |
22536 +#endif
22537 +#ifdef CONFIG_NET_NS
22538 +               CLONE_NEWNET |
22539 +#endif
22540 +               0
22541 +};
22542 +
22543 +static const struct vcmd_space_mask_v1 default_space_mask = {
22544 +       .mask = CLONE_FS |
22545 +               CLONE_NEWNS |
22546 +#ifdef CONFIG_UTS_NS
22547 +               CLONE_NEWUTS |
22548 +#endif
22549 +#ifdef CONFIG_IPC_NS
22550 +               CLONE_NEWIPC |
22551 +#endif
22552 +#ifdef CONFIG_USER_NS
22553 +               CLONE_NEWUSER |
22554 +#endif
22555 +#ifdef CONFIG_PID_NS
22556 +//             CLONE_NEWPID |
22557 +#endif
22558 +               0
22559 +};
22560 +
22561 +/*
22562 + *     build a new nsproxy mix
22563 + *      assumes that both proxies are 'const'
22564 + *     does not touch nsproxy refcounts
22565 + *     will hold a reference on the result.
22566 + */
22567 +
22568 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22569 +       struct nsproxy *new_nsproxy, unsigned long mask)
22570 +{
22571 +       struct mnt_namespace *old_ns;
22572 +       struct uts_namespace *old_uts;
22573 +       struct ipc_namespace *old_ipc;
22574 +#ifdef CONFIG_PID_NS
22575 +       struct pid_namespace *old_pid;
22576 +#endif
22577 +#ifdef CONFIG_NET_NS
22578 +       struct net *old_net;
22579 +#endif
22580 +       struct nsproxy *nsproxy;
22581 +
22582 +       nsproxy = copy_nsproxy(old_nsproxy);
22583 +       if (!nsproxy)
22584 +               goto out;
22585 +
22586 +       if (mask & CLONE_NEWNS) {
22587 +               old_ns = nsproxy->mnt_ns;
22588 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22589 +               if (nsproxy->mnt_ns)
22590 +                       get_mnt_ns(nsproxy->mnt_ns);
22591 +       } else
22592 +               old_ns = NULL;
22593 +
22594 +       if (mask & CLONE_NEWUTS) {
22595 +               old_uts = nsproxy->uts_ns;
22596 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22597 +               if (nsproxy->uts_ns)
22598 +                       get_uts_ns(nsproxy->uts_ns);
22599 +       } else
22600 +               old_uts = NULL;
22601 +
22602 +       if (mask & CLONE_NEWIPC) {
22603 +               old_ipc = nsproxy->ipc_ns;
22604 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22605 +               if (nsproxy->ipc_ns)
22606 +                       get_ipc_ns(nsproxy->ipc_ns);
22607 +       } else
22608 +               old_ipc = NULL;
22609 +
22610 +#ifdef CONFIG_PID_NS
22611 +       if (mask & CLONE_NEWPID) {
22612 +               old_pid = nsproxy->pid_ns;
22613 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22614 +               if (nsproxy->pid_ns)
22615 +                       get_pid_ns(nsproxy->pid_ns);
22616 +       } else
22617 +               old_pid = NULL;
22618 +#endif
22619 +#ifdef CONFIG_NET_NS
22620 +       if (mask & CLONE_NEWNET) {
22621 +               old_net = nsproxy->net_ns;
22622 +               nsproxy->net_ns = new_nsproxy->net_ns;
22623 +               if (nsproxy->net_ns)
22624 +                       get_net(nsproxy->net_ns);
22625 +       } else
22626 +               old_net = NULL;
22627 +#endif
22628 +       if (old_ns)
22629 +               put_mnt_ns(old_ns);
22630 +       if (old_uts)
22631 +               put_uts_ns(old_uts);
22632 +       if (old_ipc)
22633 +               put_ipc_ns(old_ipc);
22634 +#ifdef CONFIG_PID_NS
22635 +       if (old_pid)
22636 +               put_pid_ns(old_pid);
22637 +#endif
22638 +#ifdef CONFIG_NET_NS
22639 +       if (old_net)
22640 +               put_net(old_net);
22641 +#endif
22642 +out:
22643 +       return nsproxy;
22644 +}
22645 +
22646 +
22647 +/*
22648 + *     merge two nsproxy structs into a new one.
22649 + *     will hold a reference on the result.
22650 + */
22651 +
22652 +static inline
22653 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22654 +       struct nsproxy *proxy, unsigned long mask)
22655 +{
22656 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22657 +
22658 +       if (!proxy)
22659 +               return NULL;
22660 +
22661 +       if (mask) {
22662 +               /* vs_mix_nsproxy returns with reference */
22663 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22664 +                       proxy, mask);
22665 +       }
22666 +       get_nsproxy(proxy);
22667 +       return proxy;
22668 +}
22669 +
22670 +
22671 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22672 +{
22673 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22674 +       struct fs_struct *fs_cur, *fs = NULL;
22675 +       struct _vx_space *space;
22676 +       int ret, kill = 0;
22677 +
22678 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22679 +               vxi, vxi->vx_id, mask, index);
22680 +
22681 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22682 +               return -EACCES;
22683 +
22684 +       if (index >= VX_SPACES)
22685 +               return -EINVAL;
22686 +
22687 +       space = &vxi->space[index];
22688 +
22689 +       if (!mask)
22690 +               mask = space->vx_nsmask;
22691 +
22692 +       if ((mask & space->vx_nsmask) != mask)
22693 +               return -EINVAL;
22694 +
22695 +       if (mask & CLONE_FS) {
22696 +               fs = copy_fs_struct(space->vx_fs);
22697 +               if (!fs)
22698 +                       return -ENOMEM;
22699 +       }
22700 +       proxy = space->vx_nsproxy;
22701 +
22702 +       vxdprintk(VXD_CBIT(space, 9),
22703 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22704 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22705 +
22706 +       task_lock(current);
22707 +       fs_cur = current->fs;
22708 +
22709 +       if (mask & CLONE_FS) {
22710 +               spin_lock(&fs_cur->lock);
22711 +               current->fs = fs;
22712 +               kill = !--fs_cur->users;
22713 +               spin_unlock(&fs_cur->lock);
22714 +       }
22715 +
22716 +       proxy_cur = current->nsproxy;
22717 +       get_nsproxy(proxy_cur);
22718 +       task_unlock(current);
22719 +
22720 +       if (kill)
22721 +               free_fs_struct(fs_cur);
22722 +
22723 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22724 +       if (IS_ERR(proxy_new)) {
22725 +               ret = PTR_ERR(proxy_new);
22726 +               goto out_put;
22727 +       }
22728 +
22729 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22730 +
22731 +       if (mask & CLONE_NEWUSER) {
22732 +               struct cred *cred;
22733 +
22734 +               vxdprintk(VXD_CBIT(space, 10),
22735 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22736 +                       vxi, vxi->vx_id, space->vx_cred,
22737 +                       current->real_cred, current->cred);
22738 +
22739 +               if (space->vx_cred) {
22740 +                       cred = __prepare_creds(space->vx_cred);
22741 +                       if (cred)
22742 +                               commit_creds(cred);
22743 +               }
22744 +       }
22745 +
22746 +       ret = 0;
22747 +
22748 +       if (proxy_new)
22749 +               put_nsproxy(proxy_new);
22750 +out_put:
22751 +       if (proxy_cur)
22752 +               put_nsproxy(proxy_cur);
22753 +       return ret;
22754 +}
22755 +
22756 +
22757 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22758 +{
22759 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22760 +       struct fs_struct *fs_vxi, *fs;
22761 +       struct _vx_space *space;
22762 +       int ret, kill = 0;
22763 +
22764 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22765 +               vxi, vxi->vx_id, mask, index);
22766 +
22767 +       if ((mask & space_mask.mask) != mask)
22768 +               return -EINVAL;
22769 +
22770 +       if (index >= VX_SPACES)
22771 +               return -EINVAL;
22772 +
22773 +       space = &vxi->space[index];
22774 +
22775 +       proxy_vxi = space->vx_nsproxy;
22776 +       fs_vxi = space->vx_fs;
22777 +
22778 +       if (mask & CLONE_FS) {
22779 +               fs = copy_fs_struct(current->fs);
22780 +               if (!fs)
22781 +                       return -ENOMEM;
22782 +       }
22783 +
22784 +       task_lock(current);
22785 +
22786 +       if (mask & CLONE_FS) {
22787 +               spin_lock(&fs_vxi->lock);
22788 +               space->vx_fs = fs;
22789 +               kill = !--fs_vxi->users;
22790 +               spin_unlock(&fs_vxi->lock);
22791 +       }
22792 +
22793 +       proxy_cur = current->nsproxy;
22794 +       get_nsproxy(proxy_cur);
22795 +       task_unlock(current);
22796 +
22797 +       if (kill)
22798 +               free_fs_struct(fs_vxi);
22799 +
22800 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22801 +       if (IS_ERR(proxy_new)) {
22802 +               ret = PTR_ERR(proxy_new);
22803 +               goto out_put;
22804 +       }
22805 +
22806 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22807 +       space->vx_nsmask |= mask;
22808 +
22809 +       if (mask & CLONE_NEWUSER) {
22810 +               struct cred *cred;
22811 +
22812 +               vxdprintk(VXD_CBIT(space, 10),
22813 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22814 +                       vxi, vxi->vx_id, space->vx_cred,
22815 +                       current->real_cred, current->cred);
22816 +
22817 +               cred = prepare_creds();
22818 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22819 +               if (cred)
22820 +                       abort_creds(cred);
22821 +       }
22822 +
22823 +       ret = 0;
22824 +
22825 +       if (proxy_new)
22826 +               put_nsproxy(proxy_new);
22827 +out_put:
22828 +       if (proxy_cur)
22829 +               put_nsproxy(proxy_cur);
22830 +       return ret;
22831 +}
22832 +
22833 +
22834 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22835 +{
22836 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22837 +
22838 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22839 +               return -EFAULT;
22840 +
22841 +       return vx_enter_space(vxi, vc_data.mask, 0);
22842 +}
22843 +
22844 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22845 +{
22846 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22847 +
22848 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22849 +               return -EFAULT;
22850 +
22851 +       if (vc_data.index >= VX_SPACES)
22852 +               return -EINVAL;
22853 +
22854 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22855 +}
22856 +
22857 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22858 +{
22859 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22860 +
22861 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22862 +               return -EFAULT;
22863 +
22864 +       return vx_set_space(vxi, vc_data.mask, 0);
22865 +}
22866 +
22867 +int vc_set_space(struct vx_info *vxi, void __user *data)
22868 +{
22869 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22870 +
22871 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22872 +               return -EFAULT;
22873 +
22874 +       if (vc_data.index >= VX_SPACES)
22875 +               return -EINVAL;
22876 +
22877 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22878 +}
22879 +
22880 +int vc_get_space_mask(void __user *data, int type)
22881 +{
22882 +       const struct vcmd_space_mask_v1 *mask;
22883 +
22884 +       if (type == 0)
22885 +               mask = &space_mask_v0;
22886 +       else if (type == 1)
22887 +               mask = &space_mask;
22888 +       else
22889 +               mask = &default_space_mask;
22890 +
22891 +       vxdprintk(VXD_CBIT(space, 10),
22892 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22893 +
22894 +       if (copy_to_user(data, mask, sizeof(*mask)))
22895 +               return -EFAULT;
22896 +       return 0;
22897 +}
22898 +
22899 diff -NurpP --minimal linux-3.2.8/kernel/vserver/switch.c linux-3.2.8-vs2.3.2.7/kernel/vserver/switch.c
22900 --- linux-3.2.8/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22901 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/switch.c       2011-12-05 19:33:02.000000000 +0100
22902 @@ -0,0 +1,556 @@
22903 +/*
22904 + *  linux/kernel/vserver/switch.c
22905 + *
22906 + *  Virtual Server: Syscall Switch
22907 + *
22908 + *  Copyright (C) 2003-2011  Herbert Pötzl
22909 + *
22910 + *  V0.01  syscall switch
22911 + *  V0.02  added signal to context
22912 + *  V0.03  added rlimit functions
22913 + *  V0.04  added iattr, task/xid functions
22914 + *  V0.05  added debug/history stuff
22915 + *  V0.06  added compat32 layer
22916 + *  V0.07  vcmd args and perms
22917 + *  V0.08  added status commands
22918 + *  V0.09  added tag commands
22919 + *  V0.10  added oom bias
22920 + *  V0.11  added device commands
22921 + *  V0.12  added warn mask
22922 + *
22923 + */
22924 +
22925 +#include <linux/vs_context.h>
22926 +#include <linux/vs_network.h>
22927 +#include <linux/vserver/switch.h>
22928 +
22929 +#include "vci_config.h"
22930 +
22931 +
22932 +static inline
22933 +int vc_get_version(uint32_t id)
22934 +{
22935 +       return VCI_VERSION;
22936 +}
22937 +
22938 +static inline
22939 +int vc_get_vci(uint32_t id)
22940 +{
22941 +       return vci_kernel_config();
22942 +}
22943 +
22944 +#include <linux/vserver/context_cmd.h>
22945 +#include <linux/vserver/cvirt_cmd.h>
22946 +#include <linux/vserver/cacct_cmd.h>
22947 +#include <linux/vserver/limit_cmd.h>
22948 +#include <linux/vserver/network_cmd.h>
22949 +#include <linux/vserver/sched_cmd.h>
22950 +#include <linux/vserver/debug_cmd.h>
22951 +#include <linux/vserver/inode_cmd.h>
22952 +#include <linux/vserver/dlimit_cmd.h>
22953 +#include <linux/vserver/signal_cmd.h>
22954 +#include <linux/vserver/space_cmd.h>
22955 +#include <linux/vserver/tag_cmd.h>
22956 +#include <linux/vserver/device_cmd.h>
22957 +
22958 +#include <linux/vserver/inode.h>
22959 +#include <linux/vserver/dlimit.h>
22960 +
22961 +
22962 +#ifdef CONFIG_COMPAT
22963 +#define __COMPAT(name, id, data, compat)       \
22964 +       (compat) ? name ## _x32(id, data) : name(id, data)
22965 +#define __COMPAT_NO_ID(name, data, compat)     \
22966 +       (compat) ? name ## _x32(data) : name(data)
22967 +#else
22968 +#define __COMPAT(name, id, data, compat)       \
22969 +       name(id, data)
22970 +#define __COMPAT_NO_ID(name, data, compat)     \
22971 +       name(data)
22972 +#endif
22973 +
22974 +
22975 +static inline
22976 +long do_vcmd(uint32_t cmd, uint32_t id,
22977 +       struct vx_info *vxi, struct nx_info *nxi,
22978 +       void __user *data, int compat)
22979 +{
22980 +       switch (cmd) {
22981 +
22982 +       case VCMD_get_version:
22983 +               return vc_get_version(id);
22984 +       case VCMD_get_vci:
22985 +               return vc_get_vci(id);
22986 +
22987 +       case VCMD_task_xid:
22988 +               return vc_task_xid(id);
22989 +       case VCMD_vx_info:
22990 +               return vc_vx_info(vxi, data);
22991 +
22992 +       case VCMD_task_nid:
22993 +               return vc_task_nid(id);
22994 +       case VCMD_nx_info:
22995 +               return vc_nx_info(nxi, data);
22996 +
22997 +       case VCMD_task_tag:
22998 +               return vc_task_tag(id);
22999 +
23000 +       case VCMD_set_space_v1:
23001 +               return vc_set_space_v1(vxi, data);
23002 +       /* this is version 2 */
23003 +       case VCMD_set_space:
23004 +               return vc_set_space(vxi, data);
23005 +
23006 +       case VCMD_get_space_mask_v0:
23007 +               return vc_get_space_mask(data, 0);
23008 +       /* this is version 1 */
23009 +       case VCMD_get_space_mask:
23010 +               return vc_get_space_mask(data, 1);
23011 +
23012 +       case VCMD_get_space_default:
23013 +               return vc_get_space_mask(data, -1);
23014 +
23015 +       case VCMD_set_umask:
23016 +               return vc_set_umask(vxi, data);
23017 +
23018 +       case VCMD_get_umask:
23019 +               return vc_get_umask(vxi, data);
23020 +
23021 +       case VCMD_set_wmask:
23022 +               return vc_set_wmask(vxi, data);
23023 +
23024 +       case VCMD_get_wmask:
23025 +               return vc_get_wmask(vxi, data);
23026 +#ifdef CONFIG_IA32_EMULATION
23027 +       case VCMD_get_rlimit:
23028 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23029 +       case VCMD_set_rlimit:
23030 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23031 +#else
23032 +       case VCMD_get_rlimit:
23033 +               return vc_get_rlimit(vxi, data);
23034 +       case VCMD_set_rlimit:
23035 +               return vc_set_rlimit(vxi, data);
23036 +#endif
23037 +       case VCMD_get_rlimit_mask:
23038 +               return vc_get_rlimit_mask(id, data);
23039 +       case VCMD_reset_hits:
23040 +               return vc_reset_hits(vxi, data);
23041 +       case VCMD_reset_minmax:
23042 +               return vc_reset_minmax(vxi, data);
23043 +
23044 +       case VCMD_get_vhi_name:
23045 +               return vc_get_vhi_name(vxi, data);
23046 +       case VCMD_set_vhi_name:
23047 +               return vc_set_vhi_name(vxi, data);
23048 +
23049 +       case VCMD_ctx_stat:
23050 +               return vc_ctx_stat(vxi, data);
23051 +       case VCMD_virt_stat:
23052 +               return vc_virt_stat(vxi, data);
23053 +       case VCMD_sock_stat:
23054 +               return vc_sock_stat(vxi, data);
23055 +       case VCMD_rlimit_stat:
23056 +               return vc_rlimit_stat(vxi, data);
23057 +
23058 +       case VCMD_set_cflags:
23059 +               return vc_set_cflags(vxi, data);
23060 +       case VCMD_get_cflags:
23061 +               return vc_get_cflags(vxi, data);
23062 +
23063 +       /* this is version 1 */
23064 +       case VCMD_set_ccaps:
23065 +               return vc_set_ccaps(vxi, data);
23066 +       /* this is version 1 */
23067 +       case VCMD_get_ccaps:
23068 +               return vc_get_ccaps(vxi, data);
23069 +       case VCMD_set_bcaps:
23070 +               return vc_set_bcaps(vxi, data);
23071 +       case VCMD_get_bcaps:
23072 +               return vc_get_bcaps(vxi, data);
23073 +
23074 +       case VCMD_set_badness:
23075 +               return vc_set_badness(vxi, data);
23076 +       case VCMD_get_badness:
23077 +               return vc_get_badness(vxi, data);
23078 +
23079 +       case VCMD_set_nflags:
23080 +               return vc_set_nflags(nxi, data);
23081 +       case VCMD_get_nflags:
23082 +               return vc_get_nflags(nxi, data);
23083 +
23084 +       case VCMD_set_ncaps:
23085 +               return vc_set_ncaps(nxi, data);
23086 +       case VCMD_get_ncaps:
23087 +               return vc_get_ncaps(nxi, data);
23088 +
23089 +       case VCMD_set_prio_bias:
23090 +               return vc_set_prio_bias(vxi, data);
23091 +       case VCMD_get_prio_bias:
23092 +               return vc_get_prio_bias(vxi, data);
23093 +       case VCMD_add_dlimit:
23094 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23095 +       case VCMD_rem_dlimit:
23096 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23097 +       case VCMD_set_dlimit:
23098 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23099 +       case VCMD_get_dlimit:
23100 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23101 +
23102 +       case VCMD_ctx_kill:
23103 +               return vc_ctx_kill(vxi, data);
23104 +
23105 +       case VCMD_wait_exit:
23106 +               return vc_wait_exit(vxi, data);
23107 +
23108 +       case VCMD_get_iattr:
23109 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23110 +       case VCMD_set_iattr:
23111 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23112 +
23113 +       case VCMD_fget_iattr:
23114 +               return vc_fget_iattr(id, data);
23115 +       case VCMD_fset_iattr:
23116 +               return vc_fset_iattr(id, data);
23117 +
23118 +       case VCMD_enter_space_v0:
23119 +               return vc_enter_space_v1(vxi, NULL);
23120 +       case VCMD_enter_space_v1:
23121 +               return vc_enter_space_v1(vxi, data);
23122 +       /* this is version 2 */
23123 +       case VCMD_enter_space:
23124 +               return vc_enter_space(vxi, data);
23125 +
23126 +       case VCMD_ctx_create_v0:
23127 +               return vc_ctx_create(id, NULL);
23128 +       case VCMD_ctx_create:
23129 +               return vc_ctx_create(id, data);
23130 +       case VCMD_ctx_migrate_v0:
23131 +               return vc_ctx_migrate(vxi, NULL);
23132 +       case VCMD_ctx_migrate:
23133 +               return vc_ctx_migrate(vxi, data);
23134 +
23135 +       case VCMD_net_create_v0:
23136 +               return vc_net_create(id, NULL);
23137 +       case VCMD_net_create:
23138 +               return vc_net_create(id, data);
23139 +       case VCMD_net_migrate:
23140 +               return vc_net_migrate(nxi, data);
23141 +
23142 +       case VCMD_tag_migrate:
23143 +               return vc_tag_migrate(id);
23144 +
23145 +       case VCMD_net_add:
23146 +               return vc_net_add(nxi, data);
23147 +       case VCMD_net_remove:
23148 +               return vc_net_remove(nxi, data);
23149 +
23150 +       case VCMD_net_add_ipv4_v1:
23151 +               return vc_net_add_ipv4_v1(nxi, data);
23152 +       /* this is version 2 */
23153 +       case VCMD_net_add_ipv4:
23154 +               return vc_net_add_ipv4(nxi, data);
23155 +
23156 +       case VCMD_net_rem_ipv4_v1:
23157 +               return vc_net_rem_ipv4_v1(nxi, data);
23158 +       /* this is version 2 */
23159 +       case VCMD_net_rem_ipv4:
23160 +               return vc_net_rem_ipv4(nxi, data);
23161 +#ifdef CONFIG_IPV6
23162 +       case VCMD_net_add_ipv6:
23163 +               return vc_net_add_ipv6(nxi, data);
23164 +       case VCMD_net_remove_ipv6:
23165 +               return vc_net_remove_ipv6(nxi, data);
23166 +#endif
23167 +/*     case VCMD_add_match_ipv4:
23168 +               return vc_add_match_ipv4(nxi, data);
23169 +       case VCMD_get_match_ipv4:
23170 +               return vc_get_match_ipv4(nxi, data);
23171 +#ifdef CONFIG_IPV6
23172 +       case VCMD_add_match_ipv6:
23173 +               return vc_add_match_ipv6(nxi, data);
23174 +       case VCMD_get_match_ipv6:
23175 +               return vc_get_match_ipv6(nxi, data);
23176 +#endif */
23177 +
23178 +#ifdef CONFIG_VSERVER_DEVICE
23179 +       case VCMD_set_mapping:
23180 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23181 +       case VCMD_unset_mapping:
23182 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23183 +#endif
23184 +#ifdef CONFIG_VSERVER_HISTORY
23185 +       case VCMD_dump_history:
23186 +               return vc_dump_history(id);
23187 +       case VCMD_read_history:
23188 +               return __COMPAT(vc_read_history, id, data, compat);
23189 +#endif
23190 +       default:
23191 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23192 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23193 +       }
23194 +       return -ENOSYS;
23195 +}
23196 +
23197 +
23198 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23199 +       case VCMD_ ## vcmd: perm = _perm;               \
23200 +               args = _args; flags = _flags; break
23201 +
23202 +
23203 +#define VCA_NONE       0x00
23204 +#define VCA_VXI                0x01
23205 +#define VCA_NXI                0x02
23206 +
23207 +#define VCF_NONE       0x00
23208 +#define VCF_INFO       0x01
23209 +#define VCF_ADMIN      0x02
23210 +#define VCF_ARES       0x06    /* includes admin */
23211 +#define VCF_SETUP      0x08
23212 +
23213 +#define VCF_ZIDOK      0x10    /* zero id okay */
23214 +
23215 +
23216 +static inline
23217 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23218 +{
23219 +       long ret;
23220 +       int permit = -1, state = 0;
23221 +       int perm = -1, args = 0, flags = 0;
23222 +       struct vx_info *vxi = NULL;
23223 +       struct nx_info *nxi = NULL;
23224 +
23225 +       switch (cmd) {
23226 +       /* unpriviledged commands */
23227 +       __VCMD(get_version,      0, VCA_NONE,   0);
23228 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23229 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23230 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23231 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23232 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23233 +
23234 +       /* info commands */
23235 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23236 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23237 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23238 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23239 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23240 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23241 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23242 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23243 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23244 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23245 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23246 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23247 +
23248 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23249 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23250 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23251 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23252 +
23253 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23254 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23255 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23256 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23257 +
23258 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23259 +
23260 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23261 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23262 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23263 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23264 +
23265 +       /* lower admin commands */
23266 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23267 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23268 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23269 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23270 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23271 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23272 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23273 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23274 +
23275 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23276 +       __VCMD(net_create,       5, VCA_NONE,   0);
23277 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23278 +
23279 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23280 +
23281 +       /* higher admin commands */
23282 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23283 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23284 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23285 +
23286 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23287 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23288 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23289 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23290 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23291 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23292 +
23293 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23294 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23295 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23296 +
23297 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23298 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23299 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23300 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23301 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23302 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23303 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23304 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23305 +#ifdef CONFIG_IPV6
23306 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23307 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23308 +#endif
23309 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23310 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23311 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23312 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23313 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23314 +
23315 +#ifdef CONFIG_VSERVER_DEVICE
23316 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23317 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23318 +#endif
23319 +       /* debug level admin commands */
23320 +#ifdef CONFIG_VSERVER_HISTORY
23321 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23322 +       __VCMD(read_history,     9, VCA_NONE,   0);
23323 +#endif
23324 +
23325 +       default:
23326 +               perm = -1;
23327 +       }
23328 +
23329 +       vxdprintk(VXD_CBIT(switch, 0),
23330 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23331 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23332 +               VC_VERSION(cmd), id, data, compat,
23333 +               perm, args, flags);
23334 +
23335 +       ret = -ENOSYS;
23336 +       if (perm < 0)
23337 +               goto out;
23338 +
23339 +       state = 1;
23340 +       if (!capable(CAP_CONTEXT))
23341 +               goto out;
23342 +
23343 +       state = 2;
23344 +       /* moved here from the individual commands */
23345 +       ret = -EPERM;
23346 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23347 +               goto out;
23348 +
23349 +       state = 3;
23350 +       /* vcmd involves resource management  */
23351 +       ret = -EPERM;
23352 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23353 +               goto out;
23354 +
23355 +       state = 4;
23356 +       /* various legacy exceptions */
23357 +       switch (cmd) {
23358 +       /* will go away when spectator is a cap */
23359 +       case VCMD_ctx_migrate_v0:
23360 +       case VCMD_ctx_migrate:
23361 +               if (id == 1) {
23362 +                       current->xid = 1;
23363 +                       ret = 1;
23364 +                       goto out;
23365 +               }
23366 +               break;
23367 +
23368 +       /* will go away when spectator is a cap */
23369 +       case VCMD_net_migrate:
23370 +               if (id == 1) {
23371 +                       current->nid = 1;
23372 +                       ret = 1;
23373 +                       goto out;
23374 +               }
23375 +               break;
23376 +       }
23377 +
23378 +       /* vcmds are fine by default */
23379 +       permit = 1;
23380 +
23381 +       /* admin type vcmds require admin ... */
23382 +       if (flags & VCF_ADMIN)
23383 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23384 +
23385 +       /* ... but setup type vcmds override that */
23386 +       if (!permit && (flags & VCF_SETUP))
23387 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23388 +
23389 +       state = 5;
23390 +       ret = -EPERM;
23391 +       if (!permit)
23392 +               goto out;
23393 +
23394 +       state = 6;
23395 +       if (!id && (flags & VCF_ZIDOK))
23396 +               goto skip_id;
23397 +
23398 +       ret = -ESRCH;
23399 +       if (args & VCA_VXI) {
23400 +               vxi = lookup_vx_info(id);
23401 +               if (!vxi)
23402 +                       goto out;
23403 +
23404 +               if ((flags & VCF_ADMIN) &&
23405 +                       /* special case kill for shutdown */
23406 +                       (cmd != VCMD_ctx_kill) &&
23407 +                       /* can context be administrated? */
23408 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23409 +                       ret = -EACCES;
23410 +                       goto out_vxi;
23411 +               }
23412 +       }
23413 +       state = 7;
23414 +       if (args & VCA_NXI) {
23415 +               nxi = lookup_nx_info(id);
23416 +               if (!nxi)
23417 +                       goto out_vxi;
23418 +
23419 +               if ((flags & VCF_ADMIN) &&
23420 +                       /* can context be administrated? */
23421 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23422 +                       ret = -EACCES;
23423 +                       goto out_nxi;
23424 +               }
23425 +       }
23426 +skip_id:
23427 +       state = 8;
23428 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23429 +
23430 +out_nxi:
23431 +       if ((args & VCA_NXI) && nxi)
23432 +               put_nx_info(nxi);
23433 +out_vxi:
23434 +       if ((args & VCA_VXI) && vxi)
23435 +               put_vx_info(vxi);
23436 +out:
23437 +       vxdprintk(VXD_CBIT(switch, 1),
23438 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23439 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23440 +               VC_VERSION(cmd), ret, ret, state, permit);
23441 +       return ret;
23442 +}
23443 +
23444 +asmlinkage long
23445 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23446 +{
23447 +       return do_vserver(cmd, id, data, 0);
23448 +}
23449 +
23450 +#ifdef CONFIG_COMPAT
23451 +
23452 +asmlinkage long
23453 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23454 +{
23455 +       return do_vserver(cmd, id, data, 1);
23456 +}
23457 +
23458 +#endif /* CONFIG_COMPAT */
23459 diff -NurpP --minimal linux-3.2.8/kernel/vserver/sysctl.c linux-3.2.8-vs2.3.2.7/kernel/vserver/sysctl.c
23460 --- linux-3.2.8/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23461 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/sysctl.c       2011-12-05 19:33:02.000000000 +0100
23462 @@ -0,0 +1,247 @@
23463 +/*
23464 + *  kernel/vserver/sysctl.c
23465 + *
23466 + *  Virtual Context Support
23467 + *
23468 + *  Copyright (C) 2004-2007  Herbert Pötzl
23469 + *
23470 + *  V0.01  basic structure
23471 + *
23472 + */
23473 +
23474 +#include <linux/module.h>
23475 +#include <linux/ctype.h>
23476 +#include <linux/sysctl.h>
23477 +#include <linux/parser.h>
23478 +#include <asm/uaccess.h>
23479 +
23480 +enum {
23481 +       CTL_DEBUG_ERROR         = 0,
23482 +       CTL_DEBUG_SWITCH        = 1,
23483 +       CTL_DEBUG_XID,
23484 +       CTL_DEBUG_NID,
23485 +       CTL_DEBUG_TAG,
23486 +       CTL_DEBUG_NET,
23487 +       CTL_DEBUG_LIMIT,
23488 +       CTL_DEBUG_CRES,
23489 +       CTL_DEBUG_DLIM,
23490 +       CTL_DEBUG_QUOTA,
23491 +       CTL_DEBUG_CVIRT,
23492 +       CTL_DEBUG_SPACE,
23493 +       CTL_DEBUG_PERM,
23494 +       CTL_DEBUG_MISC,
23495 +};
23496 +
23497 +
23498 +unsigned int vs_debug_switch   = 0;
23499 +unsigned int vs_debug_xid      = 0;
23500 +unsigned int vs_debug_nid      = 0;
23501 +unsigned int vs_debug_tag      = 0;
23502 +unsigned int vs_debug_net      = 0;
23503 +unsigned int vs_debug_limit    = 0;
23504 +unsigned int vs_debug_cres     = 0;
23505 +unsigned int vs_debug_dlim     = 0;
23506 +unsigned int vs_debug_quota    = 0;
23507 +unsigned int vs_debug_cvirt    = 0;
23508 +unsigned int vs_debug_space    = 0;
23509 +unsigned int vs_debug_perm     = 0;
23510 +unsigned int vs_debug_misc     = 0;
23511 +
23512 +
23513 +static struct ctl_table_header *vserver_table_header;
23514 +static ctl_table vserver_root_table[];
23515 +
23516 +
23517 +void vserver_register_sysctl(void)
23518 +{
23519 +       if (!vserver_table_header) {
23520 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23521 +       }
23522 +
23523 +}
23524 +
23525 +void vserver_unregister_sysctl(void)
23526 +{
23527 +       if (vserver_table_header) {
23528 +               unregister_sysctl_table(vserver_table_header);
23529 +               vserver_table_header = NULL;
23530 +       }
23531 +}
23532 +
23533 +
23534 +static int proc_dodebug(ctl_table *table, int write,
23535 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23536 +{
23537 +       char            tmpbuf[20], *p, c;
23538 +       unsigned int    value;
23539 +       size_t          left, len;
23540 +
23541 +       if ((*ppos && !write) || !*lenp) {
23542 +               *lenp = 0;
23543 +               return 0;
23544 +       }
23545 +
23546 +       left = *lenp;
23547 +
23548 +       if (write) {
23549 +               if (!access_ok(VERIFY_READ, buffer, left))
23550 +                       return -EFAULT;
23551 +               p = (char *)buffer;
23552 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23553 +                       left--, p++;
23554 +               if (!left)
23555 +                       goto done;
23556 +
23557 +               if (left > sizeof(tmpbuf) - 1)
23558 +                       return -EINVAL;
23559 +               if (copy_from_user(tmpbuf, p, left))
23560 +                       return -EFAULT;
23561 +               tmpbuf[left] = '\0';
23562 +
23563 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23564 +                       value = 10 * value + (*p - '0');
23565 +               if (*p && !isspace(*p))
23566 +                       return -EINVAL;
23567 +               while (left && isspace(*p))
23568 +                       left--, p++;
23569 +               *(unsigned int *)table->data = value;
23570 +       } else {
23571 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23572 +                       return -EFAULT;
23573 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23574 +               if (len > left)
23575 +                       len = left;
23576 +               if (__copy_to_user(buffer, tmpbuf, len))
23577 +                       return -EFAULT;
23578 +               if ((left -= len) > 0) {
23579 +                       if (put_user('\n', (char *)buffer + len))
23580 +                               return -EFAULT;
23581 +                       left--;
23582 +               }
23583 +       }
23584 +
23585 +done:
23586 +       *lenp -= left;
23587 +       *ppos += *lenp;
23588 +       return 0;
23589 +}
23590 +
23591 +static int zero;
23592 +
23593 +#define        CTL_ENTRY(ctl, name)                            \
23594 +       {                                               \
23595 +               .procname       = #name,                \
23596 +               .data           = &vs_ ## name,         \
23597 +               .maxlen         = sizeof(int),          \
23598 +               .mode           = 0644,                 \
23599 +               .proc_handler   = &proc_dodebug,        \
23600 +               .extra1         = &zero,                \
23601 +               .extra2         = &zero,                \
23602 +       }
23603 +
23604 +static ctl_table vserver_debug_table[] = {
23605 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23606 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23607 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23608 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23609 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23610 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23611 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23612 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23613 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23614 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23615 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23616 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23617 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23618 +       { 0 }
23619 +};
23620 +
23621 +static ctl_table vserver_root_table[] = {
23622 +       {
23623 +               .procname       = "vserver",
23624 +               .mode           = 0555,
23625 +               .child          = vserver_debug_table
23626 +       },
23627 +       { 0 }
23628 +};
23629 +
23630 +
23631 +static match_table_t tokens = {
23632 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23633 +       { CTL_DEBUG_XID,        "xid=%x"        },
23634 +       { CTL_DEBUG_NID,        "nid=%x"        },
23635 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23636 +       { CTL_DEBUG_NET,        "net=%x"        },
23637 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23638 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23639 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23640 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23641 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23642 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23643 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23644 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23645 +       { CTL_DEBUG_ERROR,      NULL            }
23646 +};
23647 +
23648 +#define        HANDLE_CASE(id, name, val)                              \
23649 +       case CTL_DEBUG_ ## id:                                  \
23650 +               vs_debug_ ## name = val;                        \
23651 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23652 +               break
23653 +
23654 +
23655 +static int __init vs_debug_setup(char *str)
23656 +{
23657 +       char *p;
23658 +       int token;
23659 +
23660 +       printk("vs_debug_setup(%s)\n", str);
23661 +       while ((p = strsep(&str, ",")) != NULL) {
23662 +               substring_t args[MAX_OPT_ARGS];
23663 +               unsigned int value;
23664 +
23665 +               if (!*p)
23666 +                       continue;
23667 +
23668 +               token = match_token(p, tokens, args);
23669 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23670 +
23671 +               switch (token) {
23672 +               HANDLE_CASE(SWITCH, switch, value);
23673 +               HANDLE_CASE(XID,    xid,    value);
23674 +               HANDLE_CASE(NID,    nid,    value);
23675 +               HANDLE_CASE(TAG,    tag,    value);
23676 +               HANDLE_CASE(NET,    net,    value);
23677 +               HANDLE_CASE(LIMIT,  limit,  value);
23678 +               HANDLE_CASE(CRES,   cres,   value);
23679 +               HANDLE_CASE(DLIM,   dlim,   value);
23680 +               HANDLE_CASE(QUOTA,  quota,  value);
23681 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23682 +               HANDLE_CASE(SPACE,  space,  value);
23683 +               HANDLE_CASE(PERM,   perm,   value);
23684 +               HANDLE_CASE(MISC,   misc,   value);
23685 +               default:
23686 +                       return -EINVAL;
23687 +                       break;
23688 +               }
23689 +       }
23690 +       return 1;
23691 +}
23692 +
23693 +__setup("vsdebug=", vs_debug_setup);
23694 +
23695 +
23696 +
23697 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23698 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23699 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23700 +EXPORT_SYMBOL_GPL(vs_debug_net);
23701 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23702 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23703 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23704 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23705 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23706 +EXPORT_SYMBOL_GPL(vs_debug_space);
23707 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23708 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23709 +
23710 diff -NurpP --minimal linux-3.2.8/kernel/vserver/tag.c linux-3.2.8-vs2.3.2.7/kernel/vserver/tag.c
23711 --- linux-3.2.8/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23712 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/tag.c  2011-12-05 19:33:02.000000000 +0100
23713 @@ -0,0 +1,63 @@
23714 +/*
23715 + *  linux/kernel/vserver/tag.c
23716 + *
23717 + *  Virtual Server: Shallow Tag Space
23718 + *
23719 + *  Copyright (C) 2007  Herbert Pötzl
23720 + *
23721 + *  V0.01  basic implementation
23722 + *
23723 + */
23724 +
23725 +#include <linux/sched.h>
23726 +#include <linux/vserver/debug.h>
23727 +#include <linux/vs_pid.h>
23728 +#include <linux/vs_tag.h>
23729 +
23730 +#include <linux/vserver/tag_cmd.h>
23731 +
23732 +
23733 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23734 +{
23735 +       if (!p)
23736 +               BUG();
23737 +
23738 +       vxdprintk(VXD_CBIT(tag, 5),
23739 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23740 +
23741 +       task_lock(p);
23742 +       p->tag = tag;
23743 +       task_unlock(p);
23744 +
23745 +       vxdprintk(VXD_CBIT(tag, 5),
23746 +               "moved task %p into [#%d]", p, tag);
23747 +       return 0;
23748 +}
23749 +
23750 +/* vserver syscall commands below here */
23751 +
23752 +/* taks xid and vx_info functions */
23753 +
23754 +
23755 +int vc_task_tag(uint32_t id)
23756 +{
23757 +       tag_t tag;
23758 +
23759 +       if (id) {
23760 +               struct task_struct *tsk;
23761 +               rcu_read_lock();
23762 +               tsk = find_task_by_real_pid(id);
23763 +               tag = (tsk) ? tsk->tag : -ESRCH;
23764 +               rcu_read_unlock();
23765 +       } else
23766 +               tag = dx_current_tag();
23767 +       return tag;
23768 +}
23769 +
23770 +
23771 +int vc_tag_migrate(uint32_t tag)
23772 +{
23773 +       return dx_migrate_task(current, tag & 0xFFFF);
23774 +}
23775 +
23776 +
23777 diff -NurpP --minimal linux-3.2.8/kernel/vserver/vci_config.h linux-3.2.8-vs2.3.2.7/kernel/vserver/vci_config.h
23778 --- linux-3.2.8/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
23779 +++ linux-3.2.8-vs2.3.2.7/kernel/vserver/vci_config.h   2011-12-05 19:33:02.000000000 +0100
23780 @@ -0,0 +1,76 @@
23781 +
23782 +/*  interface version */
23783 +
23784 +#define VCI_VERSION            0x00020308
23785 +
23786 +
23787 +enum {
23788 +       VCI_KCBIT_NO_DYNAMIC = 0,
23789 +
23790 +       VCI_KCBIT_PROC_SECURE = 4,
23791 +       /* VCI_KCBIT_HARDCPU = 5, */
23792 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23793 +       /* VCI_KCBIT_IDLETIME = 7, */
23794 +
23795 +       VCI_KCBIT_COWBL = 8,
23796 +       VCI_KCBIT_FULLCOWBL = 9,
23797 +       VCI_KCBIT_SPACES = 10,
23798 +       VCI_KCBIT_NETV2 = 11,
23799 +       VCI_KCBIT_MEMCG = 12,
23800 +
23801 +       VCI_KCBIT_DEBUG = 16,
23802 +       VCI_KCBIT_HISTORY = 20,
23803 +       VCI_KCBIT_TAGGED = 24,
23804 +       VCI_KCBIT_PPTAG = 28,
23805 +
23806 +       VCI_KCBIT_MORE = 31,
23807 +};
23808 +
23809 +
23810 +static inline uint32_t vci_kernel_config(void)
23811 +{
23812 +       return
23813 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23814 +
23815 +       /* configured features */
23816 +#ifdef CONFIG_VSERVER_PROC_SECURE
23817 +       (1 << VCI_KCBIT_PROC_SECURE) |
23818 +#endif
23819 +#ifdef CONFIG_VSERVER_COWBL
23820 +       (1 << VCI_KCBIT_COWBL) |
23821 +       (1 << VCI_KCBIT_FULLCOWBL) |
23822 +#endif
23823 +       (1 << VCI_KCBIT_SPACES) |
23824 +       (1 << VCI_KCBIT_NETV2) |
23825 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23826 +       (1 << VCI_KCBIT_MEMCG) |
23827 +#endif
23828 +
23829 +       /* debug options */
23830 +#ifdef CONFIG_VSERVER_DEBUG
23831 +       (1 << VCI_KCBIT_DEBUG) |
23832 +#endif
23833 +#ifdef CONFIG_VSERVER_HISTORY
23834 +       (1 << VCI_KCBIT_HISTORY) |
23835 +#endif
23836 +
23837 +       /* inode context tagging */
23838 +#if    defined(CONFIG_TAGGING_NONE)
23839 +       (0 << VCI_KCBIT_TAGGED) |
23840 +#elif  defined(CONFIG_TAGGING_UID16)
23841 +       (1 << VCI_KCBIT_TAGGED) |
23842 +#elif  defined(CONFIG_TAGGING_GID16)
23843 +       (2 << VCI_KCBIT_TAGGED) |
23844 +#elif  defined(CONFIG_TAGGING_ID24)
23845 +       (3 << VCI_KCBIT_TAGGED) |
23846 +#elif  defined(CONFIG_TAGGING_INTERN)
23847 +       (4 << VCI_KCBIT_TAGGED) |
23848 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23849 +       (5 << VCI_KCBIT_TAGGED) |
23850 +#else
23851 +       (7 << VCI_KCBIT_TAGGED) |
23852 +#endif
23853 +       (1 << VCI_KCBIT_PPTAG) |
23854 +       0;
23855 +}
23856 +
23857 diff -NurpP --minimal linux-3.2.8/mm/memcontrol.c linux-3.2.8-vs2.3.2.7/mm/memcontrol.c
23858 --- linux-3.2.8/mm/memcontrol.c 2012-02-28 05:53:29.000000000 +0100
23859 +++ linux-3.2.8-vs2.3.2.7/mm/memcontrol.c       2012-01-26 08:52:10.000000000 +0100
23860 @@ -766,6 +766,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23861                                 struct mem_cgroup, css);
23862  }
23863  
23864 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23865 +{
23866 +       return res_counter_read_u64(&mem->res, member);
23867 +}
23868 +
23869 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23870 +{
23871 +       return res_counter_read_u64(&mem->memsw, member);
23872 +}
23873 +
23874 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23875 +{
23876 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23877 +}
23878 +
23879 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23880 +{
23881 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23882 +}
23883 +
23884 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23885 +{
23886 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23887 +}
23888 +
23889  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23890  {
23891         struct mem_cgroup *memcg = NULL;
23892 diff -NurpP --minimal linux-3.2.8/mm/oom_kill.c linux-3.2.8-vs2.3.2.7/mm/oom_kill.c
23893 --- linux-3.2.8/mm/oom_kill.c   2012-01-09 16:15:00.000000000 +0100
23894 +++ linux-3.2.8-vs2.3.2.7/mm/oom_kill.c 2012-01-09 16:19:31.000000000 +0100
23895 @@ -33,6 +33,8 @@
23896  #include <linux/security.h>
23897  #include <linux/ptrace.h>
23898  #include <linux/freezer.h>
23899 +#include <linux/reboot.h>
23900 +#include <linux/vs_context.h>
23901  
23902  int sysctl_panic_on_oom;
23903  int sysctl_oom_kill_allocating_task;
23904 @@ -148,11 +150,18 @@ struct task_struct *find_lock_task_mm(st
23905  static bool oom_unkillable_task(struct task_struct *p,
23906                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
23907  {
23908 -       if (is_global_init(p))
23909 +       unsigned xid = vx_current_xid();
23910 +
23911 +       /* skip the init task, global and per guest */
23912 +       if (task_is_init(p))
23913                 return true;
23914         if (p->flags & PF_KTHREAD)
23915                 return true;
23916  
23917 +       /* skip other guest and host processes if oom in guest */
23918 +       if (xid && vx_task_xid(p) != xid)
23919 +               return true;
23920 +
23921         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23922         if (mem && !task_in_mem_cgroup(p, mem))
23923                 return true;
23924 @@ -440,8 +449,8 @@ static int oom_kill_task(struct task_str
23925         /* mm cannot be safely dereferenced after task_unlock(p) */
23926         mm = p->mm;
23927  
23928 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23929 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
23930 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23931 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
23932                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
23933                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
23934         task_unlock(p);
23935 @@ -499,8 +508,8 @@ static int oom_kill_process(struct task_
23936         }
23937  
23938         task_lock(p);
23939 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23940 -               message, task_pid_nr(p), p->comm, points);
23941 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23942 +               message, task_pid_nr(p), p->xid, p->comm, points);
23943         task_unlock(p);
23944  
23945         /*
23946 @@ -601,6 +610,8 @@ int unregister_oom_notifier(struct notif
23947  }
23948  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23949  
23950 +long vs_oom_action(unsigned int);
23951 +
23952  /*
23953   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23954   * if a parallel OOM killing is already taking place that includes a zone in
23955 @@ -759,7 +770,12 @@ retry:
23956         if (!p) {
23957                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23958                 read_unlock(&tasklist_lock);
23959 -               panic("Out of memory and no killable processes...\n");
23960 +
23961 +               /* avoid panic for guest OOM */
23962 +               if (current->xid)
23963 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23964 +               else
23965 +                       panic("Out of memory and no killable processes...\n");
23966         }
23967  
23968         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23969 diff -NurpP --minimal linux-3.2.8/mm/page_alloc.c linux-3.2.8-vs2.3.2.7/mm/page_alloc.c
23970 --- linux-3.2.8/mm/page_alloc.c 2012-02-28 05:53:29.000000000 +0100
23971 +++ linux-3.2.8-vs2.3.2.7/mm/page_alloc.c       2012-01-26 08:52:10.000000000 +0100
23972 @@ -57,6 +57,8 @@
23973  #include <linux/ftrace_event.h>
23974  #include <linux/memcontrol.h>
23975  #include <linux/prefetch.h>
23976 +#include <linux/vs_base.h>
23977 +#include <linux/vs_limit.h>
23978  
23979  #include <asm/tlbflush.h>
23980  #include <asm/div64.h>
23981 @@ -2491,6 +2493,9 @@ void si_meminfo(struct sysinfo *val)
23982         val->totalhigh = totalhigh_pages;
23983         val->freehigh = nr_free_highpages();
23984         val->mem_unit = PAGE_SIZE;
23985 +
23986 +       if (vx_flags(VXF_VIRT_MEM, 0))
23987 +               vx_vsi_meminfo(val);
23988  }
23989  
23990  EXPORT_SYMBOL(si_meminfo);
23991 @@ -2511,6 +2516,9 @@ void si_meminfo_node(struct sysinfo *val
23992         val->freehigh = 0;
23993  #endif
23994         val->mem_unit = PAGE_SIZE;
23995 +
23996 +       if (vx_flags(VXF_VIRT_MEM, 0))
23997 +               vx_vsi_meminfo(val);
23998  }
23999  #endif
24000  
24001 diff -NurpP --minimal linux-3.2.8/mm/pgtable-generic.c linux-3.2.8-vs2.3.2.7/mm/pgtable-generic.c
24002 --- linux-3.2.8/mm/pgtable-generic.c    2011-03-15 18:07:42.000000000 +0100
24003 +++ linux-3.2.8-vs2.3.2.7/mm/pgtable-generic.c  2011-12-05 19:33:02.000000000 +0100
24004 @@ -6,6 +6,8 @@
24005   *  Copyright (C) 2010  Linus Torvalds
24006   */
24007  
24008 +#include <linux/mm.h>
24009 +
24010  #include <linux/pagemap.h>
24011  #include <asm/tlb.h>
24012  #include <asm-generic/pgtable.h>
24013 diff -NurpP --minimal linux-3.2.8/mm/shmem.c linux-3.2.8-vs2.3.2.7/mm/shmem.c
24014 --- linux-3.2.8/mm/shmem.c      2012-02-28 05:53:29.000000000 +0100
24015 +++ linux-3.2.8-vs2.3.2.7/mm/shmem.c    2012-01-26 08:52:10.000000000 +0100
24016 @@ -1460,7 +1460,7 @@ static int shmem_statfs(struct dentry *d
24017  {
24018         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24019  
24020 -       buf->f_type = TMPFS_MAGIC;
24021 +       buf->f_type = TMPFS_SUPER_MAGIC;
24022         buf->f_bsize = PAGE_CACHE_SIZE;
24023         buf->f_namelen = NAME_MAX;
24024         if (sbinfo->max_blocks) {
24025 @@ -2217,7 +2217,7 @@ int shmem_fill_super(struct super_block 
24026         sb->s_maxbytes = MAX_LFS_FILESIZE;
24027         sb->s_blocksize = PAGE_CACHE_SIZE;
24028         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24029 -       sb->s_magic = TMPFS_MAGIC;
24030 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24031         sb->s_op = &shmem_ops;
24032         sb->s_time_gran = 1;
24033  #ifdef CONFIG_TMPFS_XATTR
24034 diff -NurpP --minimal linux-3.2.8/mm/slab.c linux-3.2.8-vs2.3.2.7/mm/slab.c
24035 --- linux-3.2.8/mm/slab.c       2012-01-09 16:15:00.000000000 +0100
24036 +++ linux-3.2.8-vs2.3.2.7/mm/slab.c     2011-12-15 01:11:34.000000000 +0100
24037 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24038  #define STATS_INC_FREEMISS(x)  do { } while (0)
24039  #endif
24040  
24041 +#include "slab_vs.h"
24042 +
24043  #if DEBUG
24044  
24045  /*
24046 @@ -3397,6 +3399,7 @@ retry:
24047  
24048         obj = slab_get_obj(cachep, slabp, nodeid);
24049         check_slabp(cachep, slabp);
24050 +       vx_slab_alloc(cachep, flags);
24051         l3->free_objects--;
24052         /* move slabp to correct slabp list: */
24053         list_del(&slabp->list);
24054 @@ -3474,6 +3477,7 @@ __cache_alloc_node(struct kmem_cache *ca
24055         /* ___cache_alloc_node can fall back to other nodes */
24056         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24057    out:
24058 +       vx_slab_alloc(cachep, flags);
24059         local_irq_restore(save_flags);
24060         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24061         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24062 @@ -3661,6 +3665,7 @@ static inline void __cache_free(struct k
24063         check_irq_off();
24064         kmemleak_free_recursive(objp, cachep->flags);
24065         objp = cache_free_debugcheck(cachep, objp, caller);
24066 +       vx_slab_free(cachep);
24067  
24068         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24069  
24070 diff -NurpP --minimal linux-3.2.8/mm/slab_vs.h linux-3.2.8-vs2.3.2.7/mm/slab_vs.h
24071 --- linux-3.2.8/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24072 +++ linux-3.2.8-vs2.3.2.7/mm/slab_vs.h  2011-12-05 19:33:02.000000000 +0100
24073 @@ -0,0 +1,29 @@
24074 +
24075 +#include <linux/vserver/context.h>
24076 +
24077 +#include <linux/vs_context.h>
24078 +
24079 +static inline
24080 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24081 +{
24082 +       int what = gfp_zone(cachep->gfpflags);
24083 +       struct vx_info *vxi = current_vx_info();
24084 +
24085 +       if (!vxi)
24086 +               return;
24087 +
24088 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24089 +}
24090 +
24091 +static inline
24092 +void vx_slab_free(struct kmem_cache *cachep)
24093 +{
24094 +       int what = gfp_zone(cachep->gfpflags);
24095 +       struct vx_info *vxi = current_vx_info();
24096 +
24097 +       if (!vxi)
24098 +               return;
24099 +
24100 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24101 +}
24102 +
24103 diff -NurpP --minimal linux-3.2.8/mm/swapfile.c linux-3.2.8-vs2.3.2.7/mm/swapfile.c
24104 --- linux-3.2.8/mm/swapfile.c   2012-01-09 16:15:00.000000000 +0100
24105 +++ linux-3.2.8-vs2.3.2.7/mm/swapfile.c 2011-12-15 01:52:28.000000000 +0100
24106 @@ -36,6 +36,7 @@
24107  #include <asm/tlbflush.h>
24108  #include <linux/swapops.h>
24109  #include <linux/page_cgroup.h>
24110 +#include <linux/vs_base.h>
24111  
24112  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24113                                  unsigned char);
24114 @@ -1753,6 +1754,16 @@ static int swap_show(struct seq_file *sw
24115  
24116         if (si == SEQ_START_TOKEN) {
24117                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24118 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24119 +                       struct sysinfo si;
24120 +
24121 +                       vx_vsi_swapinfo(&si);
24122 +                       if (si.totalswap < (1 << 10))
24123 +                               return 0;
24124 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24125 +                               "hdv0", "partition", si.totalswap >> 10,
24126 +                               (si.totalswap - si.freeswap) >> 10, -1);
24127 +               }
24128                 return 0;
24129         }
24130  
24131 @@ -2176,6 +2187,8 @@ void si_swapinfo(struct sysinfo *val)
24132         val->freeswap = nr_swap_pages + nr_to_be_unused;
24133         val->totalswap = total_swap_pages + nr_to_be_unused;
24134         spin_unlock(&swap_lock);
24135 +       if (vx_flags(VXF_VIRT_MEM, 0))
24136 +               vx_vsi_swapinfo(val);
24137  }
24138  
24139  /*
24140 diff -NurpP --minimal linux-3.2.8/net/bridge/br_multicast.c linux-3.2.8-vs2.3.2.7/net/bridge/br_multicast.c
24141 --- linux-3.2.8/net/bridge/br_multicast.c       2012-01-09 16:15:03.000000000 +0100
24142 +++ linux-3.2.8-vs2.3.2.7/net/bridge/br_multicast.c     2011-12-05 19:33:02.000000000 +0100
24143 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24144         ip6h->hop_limit = 1;
24145         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24146         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24147 -                          &ip6h->saddr);
24148 +                          &ip6h->saddr, NULL);
24149         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24150  
24151         hopopt = (u8 *)(ip6h + 1);
24152 diff -NurpP --minimal linux-3.2.8/net/core/dev.c linux-3.2.8-vs2.3.2.7/net/core/dev.c
24153 --- linux-3.2.8/net/core/dev.c  2012-01-09 16:15:03.000000000 +0100
24154 +++ linux-3.2.8-vs2.3.2.7/net/core/dev.c        2011-12-15 01:11:36.000000000 +0100
24155 @@ -127,6 +127,7 @@
24156  #include <linux/in.h>
24157  #include <linux/jhash.h>
24158  #include <linux/random.h>
24159 +#include <linux/vs_inet.h>
24160  #include <trace/events/napi.h>
24161  #include <trace/events/net.h>
24162  #include <trace/events/skb.h>
24163 @@ -623,7 +624,8 @@ struct net_device *__dev_get_by_name(str
24164         struct hlist_head *head = dev_name_hash(net, name);
24165  
24166         hlist_for_each_entry(dev, p, head, name_hlist)
24167 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24168 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24169 +                   nx_dev_visible(current_nx_info(), dev))
24170                         return dev;
24171  
24172         return NULL;
24173 @@ -649,7 +651,8 @@ struct net_device *dev_get_by_name_rcu(s
24174         struct hlist_head *head = dev_name_hash(net, name);
24175  
24176         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24177 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24178 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24179 +                   nx_dev_visible(current_nx_info(), dev))
24180                         return dev;
24181  
24182         return NULL;
24183 @@ -700,7 +703,8 @@ struct net_device *__dev_get_by_index(st
24184         struct hlist_head *head = dev_index_hash(net, ifindex);
24185  
24186         hlist_for_each_entry(dev, p, head, index_hlist)
24187 -               if (dev->ifindex == ifindex)
24188 +               if ((dev->ifindex == ifindex) &&
24189 +                   nx_dev_visible(current_nx_info(), dev))
24190                         return dev;
24191  
24192         return NULL;
24193 @@ -718,7 +722,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24194   *     about locking. The caller must hold RCU lock.
24195   */
24196  
24197 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24198 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24199  {
24200         struct hlist_node *p;
24201         struct net_device *dev;
24202 @@ -730,6 +734,16 @@ struct net_device *dev_get_by_index_rcu(
24203  
24204         return NULL;
24205  }
24206 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24207 +
24208 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24209 +{
24210 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24211 +
24212 +       if (nx_dev_visible(current_nx_info(), dev))
24213 +               return dev;
24214 +       return NULL;
24215 +}
24216  EXPORT_SYMBOL(dev_get_by_index_rcu);
24217  
24218  
24219 @@ -778,7 +792,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24220  
24221         for_each_netdev_rcu(net, dev)
24222                 if (dev->type == type &&
24223 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24224 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24225 +                   nx_dev_visible(current_nx_info(), dev))
24226                         return dev;
24227  
24228         return NULL;
24229 @@ -790,9 +805,11 @@ struct net_device *__dev_getfirstbyhwtyp
24230         struct net_device *dev;
24231  
24232         ASSERT_RTNL();
24233 -       for_each_netdev(net, dev)
24234 -               if (dev->type == type)
24235 +       for_each_netdev(net, dev) {
24236 +               if ((dev->type == type) &&
24237 +                   nx_dev_visible(current_nx_info(), dev))
24238                         return dev;
24239 +       }
24240  
24241         return NULL;
24242  }
24243 @@ -910,6 +927,8 @@ static int __dev_alloc_name(struct net *
24244                                 continue;
24245                         if (i < 0 || i >= max_netdevices)
24246                                 continue;
24247 +                       if (!nx_dev_visible(current_nx_info(), d))
24248 +                               continue;
24249  
24250                         /*  avoid cases where sscanf is not exact inverse of printf */
24251                         snprintf(buf, IFNAMSIZ, name, i);
24252 @@ -4067,6 +4086,8 @@ static int dev_ifconf(struct net *net, c
24253  
24254         total = 0;
24255         for_each_netdev(net, dev) {
24256 +               if (!nx_dev_visible(current_nx_info(), dev))
24257 +                       continue;
24258                 for (i = 0; i < NPROTO; i++) {
24259                         if (gifconf_list[i]) {
24260                                 int done;
24261 @@ -4195,6 +4216,10 @@ static void dev_seq_printf_stats(struct 
24262         struct rtnl_link_stats64 temp;
24263         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24264  
24265 +       /* device visible inside network context? */
24266 +       if (!nx_dev_visible(current_nx_info(), dev))
24267 +               return;
24268 +
24269         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24270                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24271                    dev->name, stats->rx_bytes, stats->rx_packets,
24272 diff -NurpP --minimal linux-3.2.8/net/core/rtnetlink.c linux-3.2.8-vs2.3.2.7/net/core/rtnetlink.c
24273 --- linux-3.2.8/net/core/rtnetlink.c    2012-01-09 16:15:03.000000000 +0100
24274 +++ linux-3.2.8-vs2.3.2.7/net/core/rtnetlink.c  2011-12-05 19:33:02.000000000 +0100
24275 @@ -1058,6 +1058,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24276                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24277                         if (idx < s_idx)
24278                                 goto cont;
24279 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24280 +                               continue;
24281                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24282                                              NETLINK_CB(cb->skb).pid,
24283                                              cb->nlh->nlmsg_seq, 0,
24284 @@ -1907,6 +1909,9 @@ void rtmsg_ifinfo(int type, struct net_d
24285         int err = -ENOBUFS;
24286         size_t if_info_size;
24287  
24288 +       if (!nx_dev_visible(current_nx_info(), dev))
24289 +               return;
24290 +
24291         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev)), GFP_KERNEL);
24292         if (skb == NULL)
24293                 goto errout;
24294 diff -NurpP --minimal linux-3.2.8/net/core/sock.c linux-3.2.8-vs2.3.2.7/net/core/sock.c
24295 --- linux-3.2.8/net/core/sock.c 2012-01-09 16:15:03.000000000 +0100
24296 +++ linux-3.2.8-vs2.3.2.7/net/core/sock.c       2012-01-09 16:19:31.000000000 +0100
24297 @@ -127,6 +127,10 @@
24298  #include <net/cls_cgroup.h>
24299  
24300  #include <linux/filter.h>
24301 +#include <linux/vs_socket.h>
24302 +#include <linux/vs_limit.h>
24303 +#include <linux/vs_context.h>
24304 +#include <linux/vs_network.h>
24305  
24306  #include <trace/events/sock.h>
24307  
24308 @@ -1066,6 +1070,8 @@ static struct sock *sk_prot_alloc(struct
24309                         goto out_free_sec;
24310                 sk_tx_queue_clear(sk);
24311         }
24312 +               sock_vx_init(sk);
24313 +               sock_nx_init(sk);
24314  
24315         return sk;
24316  
24317 @@ -1165,6 +1171,11 @@ static void __sk_free(struct sock *sk)
24318                 put_cred(sk->sk_peer_cred);
24319         put_pid(sk->sk_peer_pid);
24320         put_net(sock_net(sk));
24321 +       vx_sock_dec(sk);
24322 +       clr_vx_info(&sk->sk_vx_info);
24323 +       sk->sk_xid = -1;
24324 +       clr_nx_info(&sk->sk_nx_info);
24325 +       sk->sk_nid = -1;
24326         sk_prot_free(sk->sk_prot_creator, sk);
24327  }
24328  
24329 @@ -1212,6 +1223,8 @@ struct sock *sk_clone(const struct sock 
24330  
24331                 /* SANITY */
24332                 get_net(sock_net(newsk));
24333 +               sock_vx_init(newsk);
24334 +               sock_nx_init(newsk);
24335                 sk_node_init(&newsk->sk_node);
24336                 sock_lock_init(newsk);
24337                 bh_lock_sock(newsk);
24338 @@ -1268,6 +1281,12 @@ struct sock *sk_clone(const struct sock 
24339                 smp_wmb();
24340                 atomic_set(&newsk->sk_refcnt, 2);
24341  
24342 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24343 +               newsk->sk_xid = sk->sk_xid;
24344 +               vx_sock_inc(newsk);
24345 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24346 +               newsk->sk_nid = sk->sk_nid;
24347 +
24348                 /*
24349                  * Increment the counter in the same struct proto as the master
24350                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24351 @@ -2014,6 +2033,12 @@ void sock_init_data(struct socket *sock,
24352  
24353         sk->sk_stamp = ktime_set(-1L, 0);
24354  
24355 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24356 +       sk->sk_xid = vx_current_xid();
24357 +       vx_sock_inc(sk);
24358 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24359 +       sk->sk_nid = nx_current_nid();
24360 +
24361         /*
24362          * Before updating sk_refcnt, we must commit prior changes to memory
24363          * (Documentation/RCU/rculist_nulls.txt for details)
24364 diff -NurpP --minimal linux-3.2.8/net/ipv4/af_inet.c linux-3.2.8-vs2.3.2.7/net/ipv4/af_inet.c
24365 --- linux-3.2.8/net/ipv4/af_inet.c      2012-01-09 16:15:03.000000000 +0100
24366 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/af_inet.c    2012-02-15 03:03:53.000000000 +0100
24367 @@ -117,6 +117,7 @@
24368  #ifdef CONFIG_IP_MROUTE
24369  #include <linux/mroute.h>
24370  #endif
24371 +#include <linux/vs_limit.h>
24372  
24373  
24374  /* The inetsw table contains everything that inet_create needs to
24375 @@ -326,9 +327,13 @@ lookup_protocol:
24376         }
24377  
24378         err = -EPERM;
24379 +       if ((protocol == IPPROTO_ICMP) &&
24380 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24381 +               goto override;
24382 +
24383         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24384                 goto out_rcu_unlock;
24385 -
24386 +override:
24387         err = -EAFNOSUPPORT;
24388         if (!inet_netns_ok(net, protocol))
24389                 goto out_rcu_unlock;
24390 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24391         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24392         struct sock *sk = sock->sk;
24393         struct inet_sock *inet = inet_sk(sk);
24394 +       struct nx_v4_sock_addr nsa;
24395         unsigned short snum;
24396         int chk_addr_ret;
24397         int err;
24398 @@ -475,7 +481,11 @@ int inet_bind(struct socket *sock, struc
24399                         goto out;
24400         }
24401  
24402 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24403 +       err = v4_map_sock_addr(inet, addr, &nsa);
24404 +       if (err)
24405 +               goto out;
24406 +
24407 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24408  
24409         /* Not specified by any standard per-se, however it breaks too
24410          * many applications when removed.  It is unfortunate since
24411 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
24412         err = -EADDRNOTAVAIL;
24413         if (!sysctl_ip_nonlocal_bind &&
24414             !(inet->freebind || inet->transparent) &&
24415 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24416 +           nsa.saddr != htonl(INADDR_ANY) &&
24417             chk_addr_ret != RTN_LOCAL &&
24418             chk_addr_ret != RTN_MULTICAST &&
24419             chk_addr_ret != RTN_BROADCAST)
24420 @@ -512,7 +522,7 @@ int inet_bind(struct socket *sock, struc
24421         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24422                 goto out_release_sock;
24423  
24424 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24425 +       v4_set_sock_addr(inet, &nsa);
24426         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24427                 inet->inet_saddr = 0;  /* Use device */
24428  
24429 @@ -715,11 +725,13 @@ int inet_getname(struct socket *sock, st
24430                      peer == 1))
24431                         return -ENOTCONN;
24432                 sin->sin_port = inet->inet_dport;
24433 -               sin->sin_addr.s_addr = inet->inet_daddr;
24434 +               sin->sin_addr.s_addr =
24435 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24436         } else {
24437                 __be32 addr = inet->inet_rcv_saddr;
24438                 if (!addr)
24439                         addr = inet->inet_saddr;
24440 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24441                 sin->sin_port = inet->inet_sport;
24442                 sin->sin_addr.s_addr = addr;
24443         }
24444 diff -NurpP --minimal linux-3.2.8/net/ipv4/arp.c linux-3.2.8-vs2.3.2.7/net/ipv4/arp.c
24445 --- linux-3.2.8/net/ipv4/arp.c  2011-10-24 18:45:34.000000000 +0200
24446 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/arp.c        2012-02-07 03:13:38.000000000 +0100
24447 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24448         struct net_device *dev = n->dev;
24449         int hatype = dev->type;
24450  
24451 +       /* FIXME: check for network context */
24452         read_lock(&n->lock);
24453         /* Convert hardware address to XX:XX:XX:XX ... form. */
24454  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
24455 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24456         int hatype = dev ? dev->type : 0;
24457         char tbuf[16];
24458  
24459 +       /* FIXME: check for network context */
24460         sprintf(tbuf, "%pI4", n->key);
24461         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24462                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24463 diff -NurpP --minimal linux-3.2.8/net/ipv4/devinet.c linux-3.2.8-vs2.3.2.7/net/ipv4/devinet.c
24464 --- linux-3.2.8/net/ipv4/devinet.c      2012-02-28 05:53:29.000000000 +0100
24465 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/devinet.c    2012-02-07 03:14:01.000000000 +0100
24466 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24467  }
24468  EXPORT_SYMBOL(inetdev_by_index);
24469  
24470 +
24471  /* Called only from RTNL semaphored context. No locks. */
24472  
24473  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24474 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24475  
24476         in_dev = __in_dev_get_rtnl(dev);
24477         if (in_dev) {
24478 +               struct nx_info *nxi = current_nx_info();
24479 +
24480                 if (tryaddrmatch) {
24481                         /* Matthias Andree */
24482                         /* compare label and address (4.4BSD style) */
24483 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24484                            This is checked above. */
24485                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24486                              ifap = &ifa->ifa_next) {
24487 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24488 +                                       continue;
24489                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24490                                     sin_orig.sin_addr.s_addr ==
24491                                                         ifa->ifa_local) {
24492 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24493                    comparing just the label */
24494                 if (!ifa) {
24495                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24496 -                            ifap = &ifa->ifa_next)
24497 +                            ifap = &ifa->ifa_next) {
24498 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24499 +                                       continue;
24500                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24501                                         break;
24502 +                       }
24503                 }
24504         }
24505  
24506 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24507                 goto out;
24508  
24509         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24510 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24511 +                       continue;
24512                 if (!buf) {
24513                         done += sizeof(ifr);
24514                         continue;
24515 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24516         struct net_device *dev;
24517         struct in_device *in_dev;
24518         struct in_ifaddr *ifa;
24519 +       struct sock *sk = skb->sk;
24520         struct hlist_head *head;
24521         struct hlist_node *node;
24522  
24523 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24524  
24525                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24526                              ifa = ifa->ifa_next, ip_idx++) {
24527 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24528 +                               continue;
24529                                 if (ip_idx < s_ip_idx)
24530                                         continue;
24531                                 if (inet_fill_ifaddr(skb, ifa,
24532 diff -NurpP --minimal linux-3.2.8/net/ipv4/fib_trie.c linux-3.2.8-vs2.3.2.7/net/ipv4/fib_trie.c
24533 --- linux-3.2.8/net/ipv4/fib_trie.c     2012-02-28 05:53:29.000000000 +0100
24534 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/fib_trie.c   2012-02-07 03:14:01.000000000 +0100
24535 @@ -2555,6 +2555,7 @@ static int fib_route_seq_show(struct seq
24536                             || fa->fa_type == RTN_MULTICAST)
24537                                 continue;
24538  
24539 +                       /* FIXME: check for network context? */
24540                         if (fi)
24541                                 seq_printf(seq,
24542                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24543 diff -NurpP --minimal linux-3.2.8/net/ipv4/inet_connection_sock.c linux-3.2.8-vs2.3.2.7/net/ipv4/inet_connection_sock.c
24544 --- linux-3.2.8/net/ipv4/inet_connection_sock.c 2011-07-22 11:18:13.000000000 +0200
24545 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/inet_connection_sock.c       2012-02-07 03:13:38.000000000 +0100
24546 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24547  }
24548  EXPORT_SYMBOL(inet_get_local_port_range);
24549  
24550 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24551 +{
24552 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24553 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24554 +
24555 +       if (inet_v6_ipv6only(sk2))
24556 +               return 0;
24557 +
24558 +       if (sk1_rcv_saddr &&
24559 +           sk2_rcv_saddr &&
24560 +           sk1_rcv_saddr == sk2_rcv_saddr)
24561 +               return 1;
24562 +
24563 +       if (sk1_rcv_saddr &&
24564 +           !sk2_rcv_saddr &&
24565 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24566 +               return 1;
24567 +
24568 +       if (sk2_rcv_saddr &&
24569 +           !sk1_rcv_saddr &&
24570 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24571 +               return 1;
24572 +
24573 +       if (!sk1_rcv_saddr &&
24574 +           !sk2_rcv_saddr &&
24575 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24576 +               return 1;
24577 +
24578 +       return 0;
24579 +}
24580 +
24581  int inet_csk_bind_conflict(const struct sock *sk,
24582                            const struct inet_bind_bucket *tb)
24583  {
24584 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
24585                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24586                         if (!reuse || !sk2->sk_reuse ||
24587                             sk2->sk_state == TCP_LISTEN) {
24588 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24589 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24590 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24591 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24592                                         break;
24593                         }
24594                 }
24595 diff -NurpP --minimal linux-3.2.8/net/ipv4/inet_diag.c linux-3.2.8-vs2.3.2.7/net/ipv4/inet_diag.c
24596 --- linux-3.2.8/net/ipv4/inet_diag.c    2012-01-09 16:15:03.000000000 +0100
24597 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/inet_diag.c  2012-02-15 03:03:53.000000000 +0100
24598 @@ -33,6 +33,8 @@
24599  #include <linux/stddef.h>
24600  
24601  #include <linux/inet_diag.h>
24602 +#include <linux/vs_network.h>
24603 +#include <linux/vs_inet.h>
24604  
24605  static const struct inet_diag_handler **inet_diag_table;
24606  
24607 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
24608  
24609         r->id.idiag_sport = inet->inet_sport;
24610         r->id.idiag_dport = inet->inet_dport;
24611 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24612 -       r->id.idiag_dst[0] = inet->inet_daddr;
24613 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24614 +               inet->inet_rcv_saddr);
24615 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24616 +               inet->inet_daddr);
24617  
24618         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24619          * hence this needs to be included regardless of socket family.
24620 @@ -214,8 +218,8 @@ static int inet_twsk_diag_fill(struct in
24621         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
24622         r->id.idiag_sport     = tw->tw_sport;
24623         r->id.idiag_dport     = tw->tw_dport;
24624 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24625 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24626 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24627 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24628         r->idiag_state        = tw->tw_substate;
24629         r->idiag_timer        = 3;
24630         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24631 @@ -272,6 +276,7 @@ static int inet_diag_get_exact(struct sk
24632         err = -EINVAL;
24633  
24634         if (req->idiag_family == AF_INET) {
24635 +               /* TODO: lback */
24636                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24637                                  req->id.idiag_dport, req->id.idiag_src[0],
24638                                  req->id.idiag_sport, req->id.idiag_if);
24639 @@ -514,6 +519,7 @@ static int inet_csk_diag_dump(struct soc
24640                 } else
24641  #endif
24642                 {
24643 +                       /* TODO: lback */
24644                         entry.saddr = &inet->inet_rcv_saddr;
24645                         entry.daddr = &inet->inet_daddr;
24646                 }
24647 @@ -552,6 +558,7 @@ static int inet_twsk_diag_dump(struct in
24648                 } else
24649  #endif
24650                 {
24651 +                       /* TODO: lback */
24652                         entry.saddr = &tw->tw_rcv_saddr;
24653                         entry.daddr = &tw->tw_daddr;
24654                 }
24655 @@ -598,8 +605,8 @@ static int inet_diag_fill_req(struct sk_
24656  
24657         r->id.idiag_sport = inet->inet_sport;
24658         r->id.idiag_dport = ireq->rmt_port;
24659 -       r->id.idiag_src[0] = ireq->loc_addr;
24660 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24661 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24662 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24663         r->idiag_expires = jiffies_to_msecs(tmo);
24664         r->idiag_rqueue = 0;
24665         r->idiag_wqueue = 0;
24666 @@ -670,6 +677,7 @@ static int inet_diag_dump_reqs(struct sk
24667                                 continue;
24668  
24669                         if (bc) {
24670 +                               /* TODO: lback */
24671                                 entry.saddr =
24672  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
24673                                         (entry.family == AF_INET6) ?
24674 @@ -740,6 +748,8 @@ static int inet_diag_dump(struct sk_buff
24675                         sk_nulls_for_each(sk, node, &ilb->head) {
24676                                 struct inet_sock *inet = inet_sk(sk);
24677  
24678 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24679 +                                       continue;
24680                                 if (num < s_num) {
24681                                         num++;
24682                                         continue;
24683 @@ -806,6 +816,8 @@ skip_listen_ht:
24684                 sk_nulls_for_each(sk, node, &head->chain) {
24685                         struct inet_sock *inet = inet_sk(sk);
24686  
24687 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24688 +                               continue;
24689                         if (num < s_num)
24690                                 goto next_normal;
24691                         if (!(r->idiag_states & (1 << sk->sk_state)))
24692 @@ -830,6 +842,8 @@ next_normal:
24693                         inet_twsk_for_each(tw, node,
24694                                     &head->twchain) {
24695  
24696 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24697 +                                       continue;
24698                                 if (num < s_num)
24699                                         goto next_dying;
24700                                 if (r->id.idiag_sport != tw->tw_sport &&
24701 diff -NurpP --minimal linux-3.2.8/net/ipv4/inet_hashtables.c linux-3.2.8-vs2.3.2.7/net/ipv4/inet_hashtables.c
24702 --- linux-3.2.8/net/ipv4/inet_hashtables.c      2011-10-24 18:45:34.000000000 +0200
24703 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/inet_hashtables.c    2011-12-05 19:33:02.000000000 +0100
24704 @@ -22,6 +22,7 @@
24705  #include <net/inet_connection_sock.h>
24706  #include <net/inet_hashtables.h>
24707  #include <net/secure_seq.h>
24708 +#include <net/route.h>
24709  #include <net/ip.h>
24710  
24711  /*
24712 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24713                         if (rcv_saddr != daddr)
24714                                 return -1;
24715                         score += 2;
24716 +               } else {
24717 +                       /* block non nx_info ips */
24718 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24719 +                               daddr, NXA_MASK_BIND))
24720 +                               return -1;
24721                 }
24722                 if (sk->sk_bound_dev_if) {
24723                         if (sk->sk_bound_dev_if != dif)
24724 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24725   * wildcarded during the search since they can never be otherwise.
24726   */
24727  
24728 -
24729  struct sock *__inet_lookup_listener(struct net *net,
24730                                     struct inet_hashinfo *hashinfo,
24731                                     const __be32 daddr, const unsigned short hnum,
24732 @@ -196,6 +201,7 @@ begin:
24733                         hiscore = score;
24734                 }
24735         }
24736 +
24737         /*
24738          * if the nulls value we got at the end of this lookup is
24739          * not the expected one, we must restart lookup.
24740 diff -NurpP --minimal linux-3.2.8/net/ipv4/netfilter/nf_nat_helper.c linux-3.2.8-vs2.3.2.7/net/ipv4/netfilter/nf_nat_helper.c
24741 --- linux-3.2.8/net/ipv4/netfilter/nf_nat_helper.c      2011-07-22 11:18:13.000000000 +0200
24742 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/netfilter/nf_nat_helper.c    2011-12-05 19:33:02.000000000 +0100
24743 @@ -20,6 +20,7 @@
24744  #include <net/route.h>
24745  
24746  #include <linux/netfilter_ipv4.h>
24747 +#include <net/route.h>
24748  #include <net/netfilter/nf_conntrack.h>
24749  #include <net/netfilter/nf_conntrack_helper.h>
24750  #include <net/netfilter/nf_conntrack_ecache.h>
24751 diff -NurpP --minimal linux-3.2.8/net/ipv4/netfilter.c linux-3.2.8-vs2.3.2.7/net/ipv4/netfilter.c
24752 --- linux-3.2.8/net/ipv4/netfilter.c    2012-01-09 16:15:03.000000000 +0100
24753 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/netfilter.c  2012-02-07 03:13:38.000000000 +0100
24754 @@ -6,7 +6,7 @@
24755  #include <linux/skbuff.h>
24756  #include <linux/gfp.h>
24757  #include <linux/export.h>
24758 -#include <net/route.h>
24759 +// #include <net/route.h>
24760  #include <net/xfrm.h>
24761  #include <net/ip.h>
24762  #include <net/netfilter/nf_queue.h>
24763 diff -NurpP --minimal linux-3.2.8/net/ipv4/raw.c linux-3.2.8-vs2.3.2.7/net/ipv4/raw.c
24764 --- linux-3.2.8/net/ipv4/raw.c  2012-01-09 16:15:04.000000000 +0100
24765 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/raw.c        2012-02-15 03:03:53.000000000 +0100
24766 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24767  
24768                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24769                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24770 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24771 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24772                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24773                         goto found; /* gotcha */
24774         }
24775 @@ -386,6 +386,12 @@ static int raw_send_hdrinc(struct sock *
24776                 icmp_out_count(net, ((struct icmphdr *)
24777                         skb_transport_header(skb))->type);
24778  
24779 +       err = -EPERM;
24780 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24781 +               sk->sk_nx_info &&
24782 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24783 +               goto error_free;
24784 +
24785         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24786                       rt->dst.dev, dst_output);
24787         if (err > 0)
24788 @@ -573,6 +579,16 @@ static int raw_sendmsg(struct kiocb *ioc
24789                         goto done;
24790         }
24791  
24792 +       if (sk->sk_nx_info) {
24793 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24794 +               if (IS_ERR(rt)) {
24795 +                       err = PTR_ERR(rt);
24796 +                       rt = NULL;
24797 +                       goto done;
24798 +               }
24799 +               ip_rt_put(rt);
24800 +       }
24801 +
24802         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24803         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24804         if (IS_ERR(rt)) {
24805 @@ -649,17 +665,19 @@ static int raw_bind(struct sock *sk, str
24806  {
24807         struct inet_sock *inet = inet_sk(sk);
24808         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24809 +       struct nx_v4_sock_addr nsa = { 0 };
24810         int ret = -EINVAL;
24811         int chk_addr_ret;
24812  
24813         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24814                 goto out;
24815 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24816 +       v4_map_sock_addr(inet, addr, &nsa);
24817 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24818         ret = -EADDRNOTAVAIL;
24819 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24820 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24821             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24822                 goto out;
24823 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24824 +       v4_set_sock_addr(inet, &nsa);
24825         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24826                 inet->inet_saddr = 0;  /* Use device */
24827         sk_dst_reset(sk);
24828 @@ -711,7 +729,8 @@ static int raw_recvmsg(struct kiocb *ioc
24829         /* Copy the address. */
24830         if (sin) {
24831                 sin->sin_family = AF_INET;
24832 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24833 +               sin->sin_addr.s_addr =
24834 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24835                 sin->sin_port = 0;
24836                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24837         }
24838 @@ -907,7 +926,8 @@ static struct sock *raw_get_first(struct
24839                 struct hlist_node *node;
24840  
24841                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24842 -                       if (sock_net(sk) == seq_file_net(seq))
24843 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24844 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24845                                 goto found;
24846         }
24847         sk = NULL;
24848 @@ -923,7 +943,8 @@ static struct sock *raw_get_next(struct 
24849                 sk = sk_next(sk);
24850  try_again:
24851                 ;
24852 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24853 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24854 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24855  
24856         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24857                 sk = sk_head(&state->h->ht[state->bucket]);
24858 diff -NurpP --minimal linux-3.2.8/net/ipv4/route.c linux-3.2.8-vs2.3.2.7/net/ipv4/route.c
24859 --- linux-3.2.8/net/ipv4/route.c        2012-01-09 16:15:04.000000000 +0100
24860 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/route.c      2012-02-07 03:13:38.000000000 +0100
24861 @@ -2709,7 +2709,7 @@ static struct rtable *ip_route_output_sl
24862  
24863  
24864         if (fl4->flowi4_oif) {
24865 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24866 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24867                 rth = ERR_PTR(-ENODEV);
24868                 if (dev_out == NULL)
24869                         goto out;
24870 diff -NurpP --minimal linux-3.2.8/net/ipv4/tcp.c linux-3.2.8-vs2.3.2.7/net/ipv4/tcp.c
24871 --- linux-3.2.8/net/ipv4/tcp.c  2012-01-09 16:15:04.000000000 +0100
24872 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/tcp.c        2011-12-05 19:33:02.000000000 +0100
24873 @@ -266,6 +266,7 @@
24874  #include <linux/crypto.h>
24875  #include <linux/time.h>
24876  #include <linux/slab.h>
24877 +#include <linux/in.h>
24878  
24879  #include <net/icmp.h>
24880  #include <net/tcp.h>
24881 diff -NurpP --minimal linux-3.2.8/net/ipv4/tcp_ipv4.c linux-3.2.8-vs2.3.2.7/net/ipv4/tcp_ipv4.c
24882 --- linux-3.2.8/net/ipv4/tcp_ipv4.c     2012-02-28 05:53:29.000000000 +0100
24883 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/tcp_ipv4.c   2012-02-15 03:03:53.000000000 +0100
24884 @@ -2023,6 +2023,12 @@ static void *listening_get_next(struct s
24885                 req = req->dl_next;
24886                 while (1) {
24887                         while (req) {
24888 +                               vxdprintk(VXD_CBIT(net, 6),
24889 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24890 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24891 +                               if (req->sk &&
24892 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24893 +                                       continue;
24894                                 if (req->rsk_ops->family == st->family) {
24895                                         cur = req;
24896                                         goto out;
24897 @@ -2047,6 +2053,10 @@ get_req:
24898         }
24899  get_sk:
24900         sk_nulls_for_each_from(sk, node) {
24901 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24902 +                       sk, sk->sk_nid, nx_current_nid());
24903 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24904 +                       continue;
24905                 if (!net_eq(sock_net(sk), net))
24906                         continue;
24907                 if (sk->sk_family == st->family) {
24908 @@ -2123,6 +2133,11 @@ static void *established_get_first(struc
24909  
24910                 spin_lock_bh(lock);
24911                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24912 +                       vxdprintk(VXD_CBIT(net, 6),
24913 +                               "sk,egf: %p [#%d] (from %d)",
24914 +                               sk, sk->sk_nid, nx_current_nid());
24915 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24916 +                               continue;
24917                         if (sk->sk_family != st->family ||
24918                             !net_eq(sock_net(sk), net)) {
24919                                 continue;
24920 @@ -2133,6 +2148,11 @@ static void *established_get_first(struc
24921                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24922                 inet_twsk_for_each(tw, node,
24923                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24924 +                       vxdprintk(VXD_CBIT(net, 6),
24925 +                               "tw: %p [#%d] (from %d)",
24926 +                               tw, tw->tw_nid, nx_current_nid());
24927 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24928 +                               continue;
24929                         if (tw->tw_family != st->family ||
24930                             !net_eq(twsk_net(tw), net)) {
24931                                 continue;
24932 @@ -2162,7 +2182,9 @@ static void *established_get_next(struct
24933                 tw = cur;
24934                 tw = tw_next(tw);
24935  get_tw:
24936 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24937 +               while (tw && (tw->tw_family != st->family ||
24938 +                       !net_eq(twsk_net(tw), net) ||
24939 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24940                         tw = tw_next(tw);
24941                 }
24942                 if (tw) {
24943 @@ -2186,6 +2208,11 @@ get_tw:
24944                 sk = sk_nulls_next(sk);
24945  
24946         sk_nulls_for_each_from(sk, node) {
24947 +               vxdprintk(VXD_CBIT(net, 6),
24948 +                       "sk,egn: %p [#%d] (from %d)",
24949 +                       sk, sk->sk_nid, nx_current_nid());
24950 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24951 +                       continue;
24952                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24953                         goto found;
24954         }
24955 @@ -2391,9 +2418,9 @@ static void get_openreq4(const struct so
24956         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24957                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24958                 i,
24959 -               ireq->loc_addr,
24960 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24961                 ntohs(inet_sk(sk)->inet_sport),
24962 -               ireq->rmt_addr,
24963 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24964                 ntohs(ireq->rmt_port),
24965                 TCP_SYN_RECV,
24966                 0, 0, /* could print option size, but that is af dependent. */
24967 @@ -2415,8 +2442,8 @@ static void get_tcp4_sock(struct sock *s
24968         const struct tcp_sock *tp = tcp_sk(sk);
24969         const struct inet_connection_sock *icsk = inet_csk(sk);
24970         const struct inet_sock *inet = inet_sk(sk);
24971 -       __be32 dest = inet->inet_daddr;
24972 -       __be32 src = inet->inet_rcv_saddr;
24973 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24974 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24975         __u16 destp = ntohs(inet->inet_dport);
24976         __u16 srcp = ntohs(inet->inet_sport);
24977         int rx_queue;
24978 @@ -2473,8 +2500,8 @@ static void get_timewait4_sock(const str
24979         if (ttd < 0)
24980                 ttd = 0;
24981  
24982 -       dest  = tw->tw_daddr;
24983 -       src   = tw->tw_rcv_saddr;
24984 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24985 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24986         destp = ntohs(tw->tw_dport);
24987         srcp  = ntohs(tw->tw_sport);
24988  
24989 diff -NurpP --minimal linux-3.2.8/net/ipv4/tcp_minisocks.c linux-3.2.8-vs2.3.2.7/net/ipv4/tcp_minisocks.c
24990 --- linux-3.2.8/net/ipv4/tcp_minisocks.c        2012-01-09 16:15:04.000000000 +0100
24991 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/tcp_minisocks.c      2011-12-05 19:33:02.000000000 +0100
24992 @@ -23,6 +23,9 @@
24993  #include <linux/slab.h>
24994  #include <linux/sysctl.h>
24995  #include <linux/workqueue.h>
24996 +#include <linux/vs_limit.h>
24997 +#include <linux/vs_socket.h>
24998 +#include <linux/vs_context.h>
24999  #include <net/tcp.h>
25000  #include <net/inet_common.h>
25001  #include <net/xfrm.h>
25002 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
25003                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25004                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25005  
25006 +               tw->tw_xid              = sk->sk_xid;
25007 +               tw->tw_vx_info          = NULL;
25008 +               tw->tw_nid              = sk->sk_nid;
25009 +               tw->tw_nx_info          = NULL;
25010 +
25011  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25012                 if (tw->tw_family == PF_INET6) {
25013                         struct ipv6_pinfo *np = inet6_sk(sk);
25014 diff -NurpP --minimal linux-3.2.8/net/ipv4/udp.c linux-3.2.8-vs2.3.2.7/net/ipv4/udp.c
25015 --- linux-3.2.8/net/ipv4/udp.c  2012-01-09 16:15:04.000000000 +0100
25016 +++ linux-3.2.8-vs2.3.2.7/net/ipv4/udp.c        2012-02-15 03:03:53.000000000 +0100
25017 @@ -297,14 +297,7 @@ fail:
25018  }
25019  EXPORT_SYMBOL(udp_lib_get_port);
25020  
25021 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25022 -{
25023 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25024 -
25025 -       return  (!ipv6_only_sock(sk2)  &&
25026 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25027 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25028 -}
25029 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25030  
25031  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25032                                        unsigned int port)
25033 @@ -339,6 +332,11 @@ static inline int compute_score(struct s
25034                         if (inet->inet_rcv_saddr != daddr)
25035                                 return -1;
25036                         score += 2;
25037 +               } else {
25038 +                       /* block non nx_info ips */
25039 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25040 +                               daddr, NXA_MASK_BIND))
25041 +                               return -1;
25042                 }
25043                 if (inet->inet_daddr) {
25044                         if (inet->inet_daddr != saddr)
25045 @@ -442,6 +440,7 @@ exact_match:
25046         return result;
25047  }
25048  
25049 +
25050  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25051   * harder than this. -DaveM
25052   */
25053 @@ -487,6 +486,11 @@ begin:
25054         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25055                 score = compute_score(sk, net, saddr, hnum, sport,
25056                                       daddr, dport, dif);
25057 +               /* FIXME: disabled?
25058 +               if (score == 9) {
25059 +                       result = sk;
25060 +                       break;
25061 +               } else */
25062                 if (score > badness) {
25063                         result = sk;
25064                         badness = score;
25065 @@ -500,6 +504,7 @@ begin:
25066         if (get_nulls_value(node) != slot)
25067                 goto begin;
25068  
25069 +
25070         if (result) {
25071                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25072                         result = NULL;
25073 @@ -509,6 +514,7 @@ begin:
25074                         goto begin;
25075                 }
25076         }
25077 +
25078         rcu_read_unlock();
25079         return result;
25080  }
25081 @@ -551,8 +557,7 @@ static inline struct sock *udp_v4_mcast_
25082                     udp_sk(s)->udp_port_hash != hnum ||
25083                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25084                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25085 -                   (inet->inet_rcv_saddr &&
25086 -                    inet->inet_rcv_saddr != loc_addr) ||
25087 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25088                     ipv6_only_sock(s) ||
25089                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25090                         continue;
25091 @@ -930,6 +935,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25092                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25093                                    faddr, saddr, dport, inet->inet_sport);
25094  
25095 +               if (sk->sk_nx_info) {
25096 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25097 +                       if (IS_ERR(rt)) {
25098 +                               err = PTR_ERR(rt);
25099 +                               rt = NULL;
25100 +                               goto out;
25101 +                       }
25102 +                       ip_rt_put(rt);
25103 +               }
25104 +
25105                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25106                 rt = ip_route_output_flow(net, fl4, sk);
25107                 if (IS_ERR(rt)) {
25108 @@ -1228,7 +1243,8 @@ try_again:
25109         if (sin) {
25110                 sin->sin_family = AF_INET;
25111                 sin->sin_port = udp_hdr(skb)->source;
25112 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25113 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25114 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25115                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25116         }
25117         if (inet->cmsg_flags)
25118 @@ -1974,6 +1990,8 @@ static struct sock *udp_get_first(struct
25119                 sk_nulls_for_each(sk, node, &hslot->head) {
25120                         if (!net_eq(sock_net(sk), net))
25121                                 continue;
25122 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25123 +                               continue;
25124                         if (sk->sk_family == state->family)
25125                                 goto found;
25126                 }
25127 @@ -1991,7 +2009,9 @@ static struct sock *udp_get_next(struct 
25128  
25129         do {
25130                 sk = sk_nulls_next(sk);
25131 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25132 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25133 +               sk->sk_family != state->family ||
25134 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25135  
25136         if (!sk) {
25137                 if (state->bucket <= state->udp_table->mask)
25138 diff -NurpP --minimal linux-3.2.8/net/ipv6/Kconfig linux-3.2.8-vs2.3.2.7/net/ipv6/Kconfig
25139 --- linux-3.2.8/net/ipv6/Kconfig        2010-08-02 16:52:59.000000000 +0200
25140 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/Kconfig      2011-12-05 19:33:02.000000000 +0100
25141 @@ -4,8 +4,8 @@
25142  
25143  #   IPv6 as module will cause a CRASH if you try to unload it
25144  menuconfig IPV6
25145 -       tristate "The IPv6 protocol"
25146 -       default m
25147 +       bool "The IPv6 protocol"
25148 +       default n
25149         ---help---
25150           This is complemental support for the IP version 6.
25151           You will still be able to do traditional IPv4 networking as well.
25152 diff -NurpP --minimal linux-3.2.8/net/ipv6/addrconf.c linux-3.2.8-vs2.3.2.7/net/ipv6/addrconf.c
25153 --- linux-3.2.8/net/ipv6/addrconf.c     2012-02-28 05:53:29.000000000 +0100
25154 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/addrconf.c   2012-02-07 03:14:01.000000000 +0100
25155 @@ -88,6 +88,8 @@
25156  #include <linux/proc_fs.h>
25157  #include <linux/seq_file.h>
25158  #include <linux/export.h>
25159 +#include <linux/vs_network.h>
25160 +#include <linux/vs_inet6.h>
25161  
25162  /* Set to 3 to get tracing... */
25163  #define ACONF_DEBUG 2
25164 @@ -1109,7 +1111,7 @@ out:
25165  
25166  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25167                        const struct in6_addr *daddr, unsigned int prefs,
25168 -                      struct in6_addr *saddr)
25169 +                      struct in6_addr *saddr, struct nx_info *nxi)
25170  {
25171         struct ipv6_saddr_score scores[2],
25172                                 *score = &scores[0], *hiscore = &scores[1];
25173 @@ -1181,6 +1183,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25174                                                dev->name);
25175                                 continue;
25176                         }
25177 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25178 +                               continue;
25179  
25180                         score->rule = -1;
25181                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25182 @@ -3153,7 +3157,10 @@ static void if6_seq_stop(struct seq_file
25183  static int if6_seq_show(struct seq_file *seq, void *v)
25184  {
25185         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25186 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25187 +
25188 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25189 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25190 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25191                    &ifp->addr,
25192                    ifp->idev->dev->ifindex,
25193                    ifp->prefix_len,
25194 @@ -3659,6 +3666,11 @@ static int in6_dump_addrs(struct inet6_d
25195         struct ifacaddr6 *ifaca;
25196         int err = 1;
25197         int ip_idx = *p_ip_idx;
25198 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25199 +
25200 +       /* disable ipv6 on non v6 guests */
25201 +       if (nxi && !nx_info_has_v6(nxi))
25202 +               return skb->len;
25203  
25204         read_lock_bh(&idev->lock);
25205         switch (type) {
25206 @@ -3669,6 +3681,8 @@ static int in6_dump_addrs(struct inet6_d
25207                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25208                         if (++ip_idx < s_ip_idx)
25209                                 continue;
25210 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25211 +                                       continue;
25212                         err = inet6_fill_ifaddr(skb, ifa,
25213                                                 NETLINK_CB(cb->skb).pid,
25214                                                 cb->nlh->nlmsg_seq,
25215 @@ -3685,6 +3699,8 @@ static int in6_dump_addrs(struct inet6_d
25216                      ifmca = ifmca->next, ip_idx++) {
25217                         if (ip_idx < s_ip_idx)
25218                                 continue;
25219 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25220 +                                       continue;
25221                         err = inet6_fill_ifmcaddr(skb, ifmca,
25222                                                   NETLINK_CB(cb->skb).pid,
25223                                                   cb->nlh->nlmsg_seq,
25224 @@ -3700,6 +3716,8 @@ static int in6_dump_addrs(struct inet6_d
25225                      ifaca = ifaca->aca_next, ip_idx++) {
25226                         if (ip_idx < s_ip_idx)
25227                                 continue;
25228 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25229 +                                       continue;
25230                         err = inet6_fill_ifacaddr(skb, ifaca,
25231                                                   NETLINK_CB(cb->skb).pid,
25232                                                   cb->nlh->nlmsg_seq,
25233 @@ -4085,6 +4103,11 @@ static int inet6_dump_ifinfo(struct sk_b
25234         struct inet6_dev *idev;
25235         struct hlist_head *head;
25236         struct hlist_node *node;
25237 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25238 +
25239 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25240 +       if (skb->sk && skb->sk->sk_vx_info)
25241 +               return skb->len; */
25242  
25243         s_h = cb->args[0];
25244         s_idx = cb->args[1];
25245 @@ -4096,6 +4119,8 @@ static int inet6_dump_ifinfo(struct sk_b
25246                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25247                         if (idx < s_idx)
25248                                 goto cont;
25249 +                       if (!v6_dev_in_nx_info(dev, nxi))
25250 +                               goto cont;
25251                         idev = __in6_dev_get(dev);
25252                         if (!idev)
25253                                 goto cont;
25254 diff -NurpP --minimal linux-3.2.8/net/ipv6/af_inet6.c linux-3.2.8-vs2.3.2.7/net/ipv6/af_inet6.c
25255 --- linux-3.2.8/net/ipv6/af_inet6.c     2011-10-24 18:45:34.000000000 +0200
25256 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/af_inet6.c   2011-12-05 19:33:02.000000000 +0100
25257 @@ -42,6 +42,8 @@
25258  #include <linux/netdevice.h>
25259  #include <linux/icmpv6.h>
25260  #include <linux/netfilter_ipv6.h>
25261 +#include <linux/vs_inet.h>
25262 +#include <linux/vs_inet6.h>
25263  
25264  #include <net/ip.h>
25265  #include <net/ipv6.h>
25266 @@ -160,9 +162,12 @@ lookup_protocol:
25267         }
25268  
25269         err = -EPERM;
25270 +       if ((protocol == IPPROTO_ICMPV6) &&
25271 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25272 +               goto override;
25273         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25274                 goto out_rcu_unlock;
25275 -
25276 +override:
25277         sock->ops = answer->ops;
25278         answer_prot = answer->prot;
25279         answer_no_check = answer->no_check;
25280 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25281         struct inet_sock *inet = inet_sk(sk);
25282         struct ipv6_pinfo *np = inet6_sk(sk);
25283         struct net *net = sock_net(sk);
25284 +       struct nx_v6_sock_addr nsa;
25285         __be32 v4addr = 0;
25286         unsigned short snum;
25287         int addr_type = 0;
25288 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25289         if (addr->sin6_family != AF_INET6)
25290                 return -EAFNOSUPPORT;
25291  
25292 +       err = v6_map_sock_addr(inet, addr, &nsa);
25293 +       if (err)
25294 +               return err;
25295 +
25296         addr_type = ipv6_addr_type(&addr->sin6_addr);
25297         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25298                 return -EINVAL;
25299 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25300                 /* Reproduce AF_INET checks to make the bindings consistent */
25301                 v4addr = addr->sin6_addr.s6_addr32[3];
25302                 chk_addr_ret = inet_addr_type(net, v4addr);
25303 +
25304                 if (!sysctl_ip_nonlocal_bind &&
25305                     !(inet->freebind || inet->transparent) &&
25306                     v4addr != htonl(INADDR_ANY) &&
25307 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25308                         err = -EADDRNOTAVAIL;
25309                         goto out;
25310                 }
25311 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25312 +                       err = -EADDRNOTAVAIL;
25313 +                       goto out;
25314 +               }
25315         } else {
25316                 if (addr_type != IPV6_ADDR_ANY) {
25317                         struct net_device *dev = NULL;
25318 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25319                                 }
25320                         }
25321  
25322 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25323 +                               err = -EADDRNOTAVAIL;
25324 +                               goto out;
25325 +                       }
25326 +
25327                         /* ipv4 addr of the socket is invalid.  Only the
25328                          * unspecified and mapped address have a v4 equivalent.
25329                          */
25330 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25331                 }
25332         }
25333  
25334 +       /* what's that for? */
25335 +       v6_set_sock_addr(inet, &nsa);
25336 +
25337         inet->inet_rcv_saddr = v4addr;
25338         inet->inet_saddr = v4addr;
25339  
25340 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25341                         return -ENOTCONN;
25342                 sin->sin6_port = inet->inet_dport;
25343                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25344 +               /* FIXME: remap lback? */
25345                 if (np->sndflow)
25346                         sin->sin6_flowinfo = np->flow_label;
25347         } else {
25348 +               /* FIXME: remap lback? */
25349                 if (ipv6_addr_any(&np->rcv_saddr))
25350                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25351                 else
25352 diff -NurpP --minimal linux-3.2.8/net/ipv6/datagram.c linux-3.2.8-vs2.3.2.7/net/ipv6/datagram.c
25353 --- linux-3.2.8/net/ipv6/datagram.c     2012-01-09 16:15:04.000000000 +0100
25354 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/datagram.c   2011-12-05 19:33:02.000000000 +0100
25355 @@ -642,7 +642,7 @@ int datagram_send_ctl(struct net *net, s
25356  
25357                         rcu_read_lock();
25358                         if (fl6->flowi6_oif) {
25359 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25360 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25361                                 if (!dev) {
25362                                         rcu_read_unlock();
25363                                         return -ENODEV;
25364 diff -NurpP --minimal linux-3.2.8/net/ipv6/fib6_rules.c linux-3.2.8-vs2.3.2.7/net/ipv6/fib6_rules.c
25365 --- linux-3.2.8/net/ipv6/fib6_rules.c   2012-01-09 16:15:04.000000000 +0100
25366 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/fib6_rules.c 2011-12-05 19:33:02.000000000 +0100
25367 @@ -91,7 +91,7 @@ static int fib6_rule_action(struct fib_r
25368                                                ip6_dst_idev(&rt->dst)->dev,
25369                                                &flp6->daddr,
25370                                                rt6_flags2srcprefs(flags),
25371 -                                              &saddr))
25372 +                                              &saddr, NULL))
25373                                 goto again;
25374                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25375                                                r->src.plen))
25376 diff -NurpP --minimal linux-3.2.8/net/ipv6/inet6_hashtables.c linux-3.2.8-vs2.3.2.7/net/ipv6/inet6_hashtables.c
25377 --- linux-3.2.8/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25378 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/inet6_hashtables.c   2011-12-05 19:33:02.000000000 +0100
25379 @@ -16,6 +16,7 @@
25380  
25381  #include <linux/module.h>
25382  #include <linux/random.h>
25383 +#include <linux/vs_inet6.h>
25384  
25385  #include <net/inet_connection_sock.h>
25386  #include <net/inet_hashtables.h>
25387 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25388         unsigned int slot = hash & hashinfo->ehash_mask;
25389         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25390  
25391 -
25392         rcu_read_lock();
25393  begin:
25394         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25395 @@ -95,7 +95,7 @@ begin:
25396                                 sock_put(sk);
25397                                 goto begin;
25398                         }
25399 -               goto out;
25400 +                       goto out;
25401                 }
25402         }
25403         if (get_nulls_value(node) != slot)
25404 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25405                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25406                                 return -1;
25407                         score++;
25408 +               } else {
25409 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25410 +                               return -1;
25411                 }
25412                 if (sk->sk_bound_dev_if) {
25413                         if (sk->sk_bound_dev_if != dif)
25414 diff -NurpP --minimal linux-3.2.8/net/ipv6/ip6_output.c linux-3.2.8-vs2.3.2.7/net/ipv6/ip6_output.c
25415 --- linux-3.2.8/net/ipv6/ip6_output.c   2012-01-09 16:15:04.000000000 +0100
25416 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/ip6_output.c 2012-01-09 16:19:31.000000000 +0100
25417 @@ -963,7 +963,8 @@ static int ip6_dst_lookup_tail(struct so
25418                 struct rt6_info *rt = (struct rt6_info *) *dst;
25419                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25420                                           sk ? inet6_sk(sk)->srcprefs : 0,
25421 -                                         &fl6->saddr);
25422 +                                         &fl6->saddr,
25423 +                                         sk ? sk->sk_nx_info : NULL);
25424                 if (err)
25425                         goto out_err_release;
25426         }
25427 diff -NurpP --minimal linux-3.2.8/net/ipv6/ndisc.c linux-3.2.8-vs2.3.2.7/net/ipv6/ndisc.c
25428 --- linux-3.2.8/net/ipv6/ndisc.c        2012-01-09 16:15:04.000000000 +0100
25429 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/ndisc.c      2011-12-15 01:11:37.000000000 +0100
25430 @@ -588,7 +588,7 @@ static void ndisc_send_na(struct net_dev
25431         } else {
25432                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25433                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25434 -                                      &tmpaddr))
25435 +                                      &tmpaddr, NULL))
25436                         return;
25437                 src_addr = &tmpaddr;
25438         }
25439 diff -NurpP --minimal linux-3.2.8/net/ipv6/raw.c linux-3.2.8-vs2.3.2.7/net/ipv6/raw.c
25440 --- linux-3.2.8/net/ipv6/raw.c  2012-02-28 05:53:29.000000000 +0100
25441 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/raw.c        2012-02-07 03:14:01.000000000 +0100
25442 @@ -30,6 +30,7 @@
25443  #include <linux/icmpv6.h>
25444  #include <linux/netfilter.h>
25445  #include <linux/netfilter_ipv6.h>
25446 +#include <linux/vs_inet6.h>
25447  #include <linux/skbuff.h>
25448  #include <linux/compat.h>
25449  #include <asm/uaccess.h>
25450 @@ -285,6 +286,13 @@ static int rawv6_bind(struct sock *sk, s
25451                                 goto out_unlock;
25452                 }
25453  
25454 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25455 +                       err = -EADDRNOTAVAIL;
25456 +                       if (dev)
25457 +                               dev_put(dev);
25458 +                       goto out;
25459 +               }
25460 +
25461                 /* ipv4 addr of the socket is invalid.  Only the
25462                  * unspecified and mapped address have a v4 equivalent.
25463                  */
25464 diff -NurpP --minimal linux-3.2.8/net/ipv6/route.c linux-3.2.8-vs2.3.2.7/net/ipv6/route.c
25465 --- linux-3.2.8/net/ipv6/route.c        2012-01-09 16:15:04.000000000 +0100
25466 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/route.c      2012-01-09 16:19:31.000000000 +0100
25467 @@ -55,6 +55,7 @@
25468  #include <net/xfrm.h>
25469  #include <net/netevent.h>
25470  #include <net/netlink.h>
25471 +#include <linux/vs_inet6.h>
25472  
25473  #include <asm/uaccess.h>
25474  
25475 @@ -2093,15 +2094,17 @@ int ip6_route_get_saddr(struct net *net,
25476                         struct rt6_info *rt,
25477                         const struct in6_addr *daddr,
25478                         unsigned int prefs,
25479 -                       struct in6_addr *saddr)
25480 +                       struct in6_addr *saddr,
25481 +                       struct nx_info *nxi)
25482  {
25483         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25484         int err = 0;
25485 -       if (rt->rt6i_prefsrc.plen)
25486 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25487 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25488                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25489         else
25490                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25491 -                                        daddr, prefs, saddr);
25492 +                                        daddr, prefs, saddr, nxi);
25493         return err;
25494  }
25495  
25496 @@ -2431,7 +2434,8 @@ static int rt6_fill_node(struct net *net
25497                         NLA_PUT_U32(skb, RTA_IIF, iif);
25498         } else if (dst) {
25499                 struct in6_addr saddr_buf;
25500 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25501 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25502 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25503                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25504         }
25505  
25506 @@ -2634,6 +2638,7 @@ static int rt6_info_route(struct rt6_inf
25507         struct seq_file *m = p_arg;
25508         struct neighbour *n;
25509  
25510 +       /* FIXME: check for network context? */
25511         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25512  
25513  #ifdef CONFIG_IPV6_SUBTREES
25514 diff -NurpP --minimal linux-3.2.8/net/ipv6/tcp_ipv6.c linux-3.2.8-vs2.3.2.7/net/ipv6/tcp_ipv6.c
25515 --- linux-3.2.8/net/ipv6/tcp_ipv6.c     2012-02-28 05:53:29.000000000 +0100
25516 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/tcp_ipv6.c   2012-02-07 03:14:01.000000000 +0100
25517 @@ -70,6 +70,7 @@
25518  
25519  #include <linux/crypto.h>
25520  #include <linux/scatterlist.h>
25521 +#include <linux/vs_inet6.h>
25522  
25523  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25524  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25525 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
25526          *      connect() to INADDR_ANY means loopback (BSD'ism).
25527          */
25528  
25529 -       if(ipv6_addr_any(&usin->sin6_addr))
25530 -               usin->sin6_addr.s6_addr[15] = 0x1;
25531 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25532 +               struct nx_info *nxi =  sk->sk_nx_info;
25533 +
25534 +               if (nxi && nx_info_has_v6(nxi))
25535 +                       /* FIXME: remap lback? */
25536 +                       usin->sin6_addr = nxi->v6.ip;
25537 +               else
25538 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25539 +       }
25540  
25541         addr_type = ipv6_addr_type(&usin->sin6_addr);
25542  
25543 diff -NurpP --minimal linux-3.2.8/net/ipv6/udp.c linux-3.2.8-vs2.3.2.7/net/ipv6/udp.c
25544 --- linux-3.2.8/net/ipv6/udp.c  2012-01-09 16:15:04.000000000 +0100
25545 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/udp.c        2011-12-15 01:11:37.000000000 +0100
25546 @@ -45,41 +45,67 @@
25547  #include <net/tcp_states.h>
25548  #include <net/ip6_checksum.h>
25549  #include <net/xfrm.h>
25550 +#include <linux/vs_inet6.h>
25551  
25552  #include <linux/proc_fs.h>
25553  #include <linux/seq_file.h>
25554  #include "udp_impl.h"
25555  
25556 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25557 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25558  {
25559 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25560 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25561         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25562 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25563 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25564         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25565 -       int sk_ipv6only = ipv6_only_sock(sk);
25566 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25567         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25568 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25569 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25570         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25571  
25572         /* if both are mapped, treat as IPv4 */
25573 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25574 -               return (!sk2_ipv6only &&
25575 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25576 +               if (!sk2_ipv6only &&
25577                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25578 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25579 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25580 +                       goto vs_v4;
25581 +               else
25582 +                       return 0;
25583 +       }
25584  
25585         if (addr_type2 == IPV6_ADDR_ANY &&
25586             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25587 -               return 1;
25588 +               goto vs;
25589  
25590         if (addr_type == IPV6_ADDR_ANY &&
25591 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25592 -               return 1;
25593 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25594 +               goto vs;
25595  
25596         if (sk2_rcv_saddr6 &&
25597 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25598 -               return 1;
25599 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25600 +               goto vs;
25601  
25602         return 0;
25603 +
25604 +vs_v4:
25605 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25606 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25607 +       if (!sk2_rcv_saddr)
25608 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25609 +       if (!sk1_rcv_saddr)
25610 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25611 +       return 1;
25612 +vs:
25613 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25614 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25615 +       else if (addr_type2 == IPV6_ADDR_ANY)
25616 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25617 +       else if (addr_type == IPV6_ADDR_ANY) {
25618 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25619 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25620 +               else
25621 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25622 +       }
25623 +       return 1;
25624  }
25625  
25626  static unsigned int udp6_portaddr_hash(struct net *net,
25627 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25628                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25629                                 return -1;
25630                         score++;
25631 +               } else {
25632 +                       /* block non nx_info ips */
25633 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25634 +                               return -1;
25635                 }
25636                 if (!ipv6_addr_any(&np->daddr)) {
25637                         if (!ipv6_addr_equal(&np->daddr, saddr))
25638 diff -NurpP --minimal linux-3.2.8/net/ipv6/xfrm6_policy.c linux-3.2.8-vs2.3.2.7/net/ipv6/xfrm6_policy.c
25639 --- linux-3.2.8/net/ipv6/xfrm6_policy.c 2011-07-22 11:18:13.000000000 +0200
25640 +++ linux-3.2.8-vs2.3.2.7/net/ipv6/xfrm6_policy.c       2011-12-05 19:33:02.000000000 +0100
25641 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25642         dev = ip6_dst_idev(dst)->dev;
25643         ipv6_dev_get_saddr(dev_net(dev), dev,
25644                            (struct in6_addr *)&daddr->a6, 0,
25645 -                          (struct in6_addr *)&saddr->a6);
25646 +                          (struct in6_addr *)&saddr->a6, NULL);
25647         dst_release(dst);
25648         return 0;
25649  }
25650 diff -NurpP --minimal linux-3.2.8/net/netfilter/ipvs/ip_vs_xmit.c linux-3.2.8-vs2.3.2.7/net/netfilter/ipvs/ip_vs_xmit.c
25651 --- linux-3.2.8/net/netfilter/ipvs/ip_vs_xmit.c 2012-01-09 16:15:04.000000000 +0100
25652 +++ linux-3.2.8-vs2.3.2.7/net/netfilter/ipvs/ip_vs_xmit.c       2012-02-07 03:13:38.000000000 +0100
25653 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25654                 return dst;
25655         if (ipv6_addr_any(&fl6.saddr) &&
25656             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25657 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25658 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25659                 goto out_err;
25660         if (do_xfrm) {
25661                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25662 diff -NurpP --minimal linux-3.2.8/net/netlink/af_netlink.c linux-3.2.8-vs2.3.2.7/net/netlink/af_netlink.c
25663 --- linux-3.2.8/net/netlink/af_netlink.c        2012-01-09 16:15:04.000000000 +0100
25664 +++ linux-3.2.8-vs2.3.2.7/net/netlink/af_netlink.c      2011-12-05 19:33:02.000000000 +0100
25665 @@ -55,6 +55,9 @@
25666  #include <linux/types.h>
25667  #include <linux/audit.h>
25668  #include <linux/mutex.h>
25669 +#include <linux/vs_context.h>
25670 +#include <linux/vs_network.h>
25671 +#include <linux/vs_limit.h>
25672  
25673  #include <net/net_namespace.h>
25674  #include <net/sock.h>
25675 @@ -1912,6 +1915,8 @@ static struct sock *netlink_seq_socket_i
25676                         sk_for_each(s, node, &hash->table[j]) {
25677                                 if (sock_net(s) != seq_file_net(seq))
25678                                         continue;
25679 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25680 +                                       continue;
25681                                 if (off == pos) {
25682                                         iter->link = i;
25683                                         iter->hash_idx = j;
25684 @@ -1946,7 +1951,8 @@ static void *netlink_seq_next(struct seq
25685         s = v;
25686         do {
25687                 s = sk_next(s);
25688 -       } while (s && sock_net(s) != seq_file_net(seq));
25689 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25690 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25691         if (s)
25692                 return s;
25693  
25694 @@ -1958,7 +1964,8 @@ static void *netlink_seq_next(struct seq
25695  
25696                 for (; j <= hash->mask; j++) {
25697                         s = sk_head(&hash->table[j]);
25698 -                       while (s && sock_net(s) != seq_file_net(seq))
25699 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25700 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25701                                 s = sk_next(s);
25702                         if (s) {
25703                                 iter->link = i;
25704 diff -NurpP --minimal linux-3.2.8/net/socket.c linux-3.2.8-vs2.3.2.7/net/socket.c
25705 --- linux-3.2.8/net/socket.c    2012-02-28 05:53:30.000000000 +0100
25706 +++ linux-3.2.8-vs2.3.2.7/net/socket.c  2012-02-07 03:14:01.000000000 +0100
25707 @@ -98,6 +98,10 @@
25708  
25709  #include <net/sock.h>
25710  #include <linux/netfilter.h>
25711 +#include <linux/vs_base.h>
25712 +#include <linux/vs_socket.h>
25713 +#include <linux/vs_inet.h>
25714 +#include <linux/vs_inet6.h>
25715  
25716  #include <linux/if_tun.h>
25717  #include <linux/ipv6_route.h>
25718 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
25719                                        struct msghdr *msg, size_t size)
25720  {
25721         struct sock_iocb *si = kiocb_to_siocb(iocb);
25722 +       size_t len;
25723  
25724         sock_update_classid(sock->sk);
25725  
25726 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
25727         si->msg = msg;
25728         si->size = size;
25729  
25730 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25731 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25732 +       if (sock->sk) {
25733 +               if (len == size)
25734 +                       vx_sock_send(sock->sk, size);
25735 +               else
25736 +                       vx_sock_fail(sock->sk, size);
25737 +       }
25738 +       vxdprintk(VXD_CBIT(net, 7),
25739 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25740 +               sock, sock->sk,
25741 +               (sock->sk)?sock->sk->sk_nx_info:0,
25742 +               (sock->sk)?sock->sk->sk_vx_info:0,
25743 +               (sock->sk)?sock->sk->sk_xid:0,
25744 +               (sock->sk)?sock->sk->sk_nid:0,
25745 +               (unsigned int)size, len);
25746 +       return len;
25747  }
25748  
25749  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25750 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
25751                                        struct msghdr *msg, size_t size, int flags)
25752  {
25753         struct sock_iocb *si = kiocb_to_siocb(iocb);
25754 +       int len;
25755  
25756         sock_update_classid(sock->sk);
25757  
25758 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
25759         si->size = size;
25760         si->flags = flags;
25761  
25762 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25763 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25764 +       if ((len >= 0) && sock->sk)
25765 +               vx_sock_recv(sock->sk, len);
25766 +       vxdprintk(VXD_CBIT(net, 7),
25767 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25768 +               sock, sock->sk,
25769 +               (sock->sk)?sock->sk->sk_nx_info:0,
25770 +               (sock->sk)?sock->sk->sk_vx_info:0,
25771 +               (sock->sk)?sock->sk->sk_xid:0,
25772 +               (sock->sk)?sock->sk->sk_nid:0,
25773 +               (unsigned int)size, len);
25774 +       return len;
25775  }
25776  
25777  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25778 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
25779         if (type < 0 || type >= SOCK_MAX)
25780                 return -EINVAL;
25781  
25782 +       if (!nx_check(0, VS_ADMIN)) {
25783 +               if (family == PF_INET && !current_nx_info_has_v4())
25784 +                       return -EAFNOSUPPORT;
25785 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25786 +                       return -EAFNOSUPPORT;
25787 +       }
25788 +
25789         /* Compatibility.
25790  
25791            This uglymoron is moved from INET layer to here to avoid
25792 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25793         if (retval < 0)
25794                 goto out;
25795  
25796 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25797         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25798         if (retval < 0)
25799                 goto out_release;
25800 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25801         err = sock_create(family, type, protocol, &sock1);
25802         if (err < 0)
25803                 goto out;
25804 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25805  
25806         err = sock_create(family, type, protocol, &sock2);
25807         if (err < 0)
25808                 goto out_release_1;
25809 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25810  
25811         err = sock1->ops->socketpair(sock1, sock2);
25812         if (err < 0)
25813 diff -NurpP --minimal linux-3.2.8/net/sunrpc/auth.c linux-3.2.8-vs2.3.2.7/net/sunrpc/auth.c
25814 --- linux-3.2.8/net/sunrpc/auth.c       2011-10-24 18:45:34.000000000 +0200
25815 +++ linux-3.2.8-vs2.3.2.7/net/sunrpc/auth.c     2011-12-05 19:33:02.000000000 +0100
25816 @@ -14,6 +14,7 @@
25817  #include <linux/hash.h>
25818  #include <linux/sunrpc/clnt.h>
25819  #include <linux/spinlock.h>
25820 +#include <linux/vs_tag.h>
25821  
25822  #ifdef RPC_DEBUG
25823  # define RPCDBG_FACILITY       RPCDBG_AUTH
25824 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25825         memset(&acred, 0, sizeof(acred));
25826         acred.uid = cred->fsuid;
25827         acred.gid = cred->fsgid;
25828 +       acred.tag = dx_current_tag();
25829         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25830  
25831         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25832 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25833         struct auth_cred acred = {
25834                 .uid = 0,
25835                 .gid = 0,
25836 +               .tag = dx_current_tag(),
25837         };
25838  
25839         dprintk("RPC: %5u looking up %s cred\n",
25840 diff -NurpP --minimal linux-3.2.8/net/sunrpc/auth_unix.c linux-3.2.8-vs2.3.2.7/net/sunrpc/auth_unix.c
25841 --- linux-3.2.8/net/sunrpc/auth_unix.c  2012-01-09 16:15:04.000000000 +0100
25842 +++ linux-3.2.8-vs2.3.2.7/net/sunrpc/auth_unix.c        2011-12-05 19:33:02.000000000 +0100
25843 @@ -12,12 +12,14 @@
25844  #include <linux/module.h>
25845  #include <linux/sunrpc/clnt.h>
25846  #include <linux/sunrpc/auth.h>
25847 +#include <linux/vs_tag.h>
25848  
25849  #define NFS_NGROUPS    16
25850  
25851  struct unx_cred {
25852         struct rpc_cred         uc_base;
25853         gid_t                   uc_gid;
25854 +       tag_t                   uc_tag;
25855         gid_t                   uc_gids[NFS_NGROUPS];
25856  };
25857  #define uc_uid                 uc_base.cr_uid
25858 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
25859                 groups = NFS_NGROUPS;
25860  
25861         cred->uc_gid = acred->gid;
25862 +       cred->uc_tag = acred->tag;
25863         for (i = 0; i < groups; i++)
25864                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25865         if (i < NFS_NGROUPS)
25866 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
25867         unsigned int i;
25868  
25869  
25870 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25871 +       if (cred->uc_uid != acred->uid ||
25872 +               cred->uc_gid != acred->gid ||
25873 +               cred->uc_tag != acred->tag)
25874                 return 0;
25875  
25876         if (acred->group_info != NULL)
25877 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
25878         struct rpc_clnt *clnt = task->tk_client;
25879         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25880         __be32          *base, *hold;
25881 -       int             i;
25882 +       int             i, tag;
25883  
25884         *p++ = htonl(RPC_AUTH_UNIX);
25885         base = p++;
25886 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
25887          * Copy the UTS nodename captured when the client was created.
25888          */
25889         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25890 +       tag = task->tk_client->cl_tag;
25891  
25892 -       *p++ = htonl((u32) cred->uc_uid);
25893 -       *p++ = htonl((u32) cred->uc_gid);
25894 +       *p++ = htonl((u32) TAGINO_UID(tag,
25895 +               cred->uc_uid, cred->uc_tag));
25896 +       *p++ = htonl((u32) TAGINO_GID(tag,
25897 +               cred->uc_gid, cred->uc_tag));
25898         hold = p++;
25899         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25900                 *p++ = htonl((u32) cred->uc_gids[i]);
25901 diff -NurpP --minimal linux-3.2.8/net/sunrpc/clnt.c linux-3.2.8-vs2.3.2.7/net/sunrpc/clnt.c
25902 --- linux-3.2.8/net/sunrpc/clnt.c       2012-01-09 16:15:04.000000000 +0100
25903 +++ linux-3.2.8-vs2.3.2.7/net/sunrpc/clnt.c     2011-12-05 19:33:02.000000000 +0100
25904 @@ -31,6 +31,7 @@
25905  #include <linux/in.h>
25906  #include <linux/in6.h>
25907  #include <linux/un.h>
25908 +#include <linux/vs_cvirt.h>
25909  
25910  #include <linux/sunrpc/clnt.h>
25911  #include <linux/sunrpc/rpc_pipe_fs.h>
25912 @@ -361,6 +362,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25913         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25914                 clnt->cl_chatty = 1;
25915  
25916 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25917 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25918 +               clnt->cl_tag = 1; */
25919         return clnt;
25920  }
25921  EXPORT_SYMBOL_GPL(rpc_create);
25922 diff -NurpP --minimal linux-3.2.8/net/unix/af_unix.c linux-3.2.8-vs2.3.2.7/net/unix/af_unix.c
25923 --- linux-3.2.8/net/unix/af_unix.c      2012-02-28 05:53:30.000000000 +0100
25924 +++ linux-3.2.8-vs2.3.2.7/net/unix/af_unix.c    2012-02-07 03:14:01.000000000 +0100
25925 @@ -114,6 +114,8 @@
25926  #include <linux/mount.h>
25927  #include <net/checksum.h>
25928  #include <linux/security.h>
25929 +#include <linux/vs_context.h>
25930 +#include <linux/vs_limit.h>
25931  
25932  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
25933  static DEFINE_SPINLOCK(unix_table_lock);
25934 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
25935                 if (!net_eq(sock_net(s), net))
25936                         continue;
25937  
25938 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25939 +                       continue;
25940                 if (u->addr->len == len &&
25941                     !memcmp(u->addr->name, sunname, len))
25942                         goto found;
25943 @@ -2219,6 +2223,8 @@ static struct sock *unix_seq_idx(struct 
25944         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
25945                 if (sock_net(s) != seq_file_net(seq))
25946                         continue;
25947 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25948 +                       continue;
25949                 if (off == pos)
25950                         return s;
25951                 ++off;
25952 @@ -2243,7 +2249,8 @@ static void *unix_seq_next(struct seq_fi
25953                 sk = first_unix_socket(&iter->i);
25954         else
25955                 sk = next_unix_socket(&iter->i, sk);
25956 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
25957 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
25958 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
25959                 sk = next_unix_socket(&iter->i, sk);
25960         return sk;
25961  }
25962 diff -NurpP --minimal linux-3.2.8/scripts/checksyscalls.sh linux-3.2.8-vs2.3.2.7/scripts/checksyscalls.sh
25963 --- linux-3.2.8/scripts/checksyscalls.sh        2011-03-15 18:07:46.000000000 +0100
25964 +++ linux-3.2.8-vs2.3.2.7/scripts/checksyscalls.sh      2011-12-05 19:33:02.000000000 +0100
25965 @@ -193,7 +193,6 @@ cat << EOF
25966  #define __IGNORE_afs_syscall
25967  #define __IGNORE_getpmsg
25968  #define __IGNORE_putpmsg
25969 -#define __IGNORE_vserver
25970  EOF
25971  }
25972  
25973 diff -NurpP --minimal linux-3.2.8/security/commoncap.c linux-3.2.8-vs2.3.2.7/security/commoncap.c
25974 --- linux-3.2.8/security/commoncap.c    2012-01-09 16:15:05.000000000 +0100
25975 +++ linux-3.2.8-vs2.3.2.7/security/commoncap.c  2011-12-05 19:33:02.000000000 +0100
25976 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
25977                 return -EPERM;
25978         return 0;
25979  }
25980 +
25981  EXPORT_SYMBOL(cap_netlink_recv);
25982  
25983  /**
25984 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
25985  int cap_capable(struct task_struct *tsk, const struct cred *cred,
25986                 struct user_namespace *targ_ns, int cap, int audit)
25987  {
25988 +       struct vx_info *vxi = tsk->vx_info;
25989 +
25990         for (;;) {
25991                 /* The creator of the user namespace has all caps. */
25992                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
25993                         return 0;
25994  
25995                 /* Do we have the necessary capabilities? */
25996 -               if (targ_ns == cred->user->user_ns)
25997 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25998 +               if (targ_ns == cred->user->user_ns) {
25999 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26000 +                           cap_raised(cred->cap_effective, cap))
26001 +                               return 0;
26002 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26003 +               }
26004  
26005                 /* Have we tried all of the parent namespaces? */
26006                 if (targ_ns == &init_user_ns)
26007 @@ -615,7 +622,7 @@ int cap_inode_setxattr(struct dentry *de
26008  
26009         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26010                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26011 -           !capable(CAP_SYS_ADMIN))
26012 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26013                 return -EPERM;
26014         return 0;
26015  }
26016 @@ -641,7 +648,7 @@ int cap_inode_removexattr(struct dentry 
26017  
26018         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26019                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26020 -           !capable(CAP_SYS_ADMIN))
26021 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26022                 return -EPERM;
26023         return 0;
26024  }
26025 diff -NurpP --minimal linux-3.2.8/security/selinux/hooks.c linux-3.2.8-vs2.3.2.7/security/selinux/hooks.c
26026 --- linux-3.2.8/security/selinux/hooks.c        2012-01-09 16:15:05.000000000 +0100
26027 +++ linux-3.2.8-vs2.3.2.7/security/selinux/hooks.c      2011-12-05 19:33:02.000000000 +0100
26028 @@ -67,7 +67,6 @@
26029  #include <linux/dccp.h>
26030  #include <linux/quota.h>
26031  #include <linux/un.h>          /* for Unix socket types */
26032 -#include <net/af_unix.h>       /* for Unix socket types */
26033  #include <linux/parser.h>
26034  #include <linux/nfs_mount.h>
26035  #include <net/ipv6.h>
This page took 2.152502 seconds and 4 git commands to generate.