]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 2.3.6; rel 1; updated vserver, unionfs, aufs. NOTE/WARNING: grsecurity is...
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.2.5/Documentation/vserver/debug.txt linux-3.2.5-vs2.3.2.6/Documentation/vserver/debug.txt
2 --- linux-3.2.5/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/alpha/Kconfig linux-3.2.5-vs2.3.2.6/arch/alpha/Kconfig
160 --- linux-3.2.5/arch/alpha/Kconfig      2012-01-09 16:13:54.000000000 +0100
161 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/alpha/kernel/entry.S linux-3.2.5-vs2.3.2.6/arch/alpha/kernel/entry.S
172 --- linux-3.2.5/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/alpha/kernel/ptrace.c linux-3.2.5-vs2.3.2.6/arch/alpha/kernel/ptrace.c
207 --- linux-3.2.5/arch/alpha/kernel/ptrace.c      2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/alpha/kernel/systbls.S linux-3.2.5-vs2.3.2.6/arch/alpha/kernel/systbls.S
218 --- linux-3.2.5/arch/alpha/kernel/systbls.S     2012-01-09 16:13:54.000000000 +0100
219 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/alpha/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/alpha/kernel/traps.c
230 --- linux-3.2.5/arch/alpha/kernel/traps.c       2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/arm/Kconfig linux-3.2.5-vs2.3.2.6/arch/arm/Kconfig
243 --- linux-3.2.5/arch/arm/Kconfig        2012-01-09 16:13:54.000000000 +0100
244 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/arm/kernel/calls.S linux-3.2.5-vs2.3.2.6/arch/arm/kernel/calls.S
255 --- linux-3.2.5/arch/arm/kernel/calls.S 2012-01-09 16:13:54.000000000 +0100
256 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/arm/kernel/process.c linux-3.2.5-vs2.3.2.6/arch/arm/kernel/process.c
267 --- linux-3.2.5/arch/arm/kernel/process.c       2012-01-09 16:13:54.000000000 +0100
268 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/arm/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/arm/kernel/traps.c
280 --- linux-3.2.5/arch/arm/kernel/traps.c 2012-01-09 16:13:54.000000000 +0100
281 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/cris/Kconfig linux-3.2.5-vs2.3.2.6/arch/cris/Kconfig
294 --- linux-3.2.5/arch/cris/Kconfig       2012-01-09 16:14:01.000000000 +0100
295 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/frv/kernel/kernel_thread.S linux-3.2.5-vs2.3.2.6/arch/frv/kernel/kernel_thread.S
306 --- linux-3.2.5/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/h8300/Kconfig linux-3.2.5-vs2.3.2.6/arch/h8300/Kconfig
318 --- linux-3.2.5/arch/h8300/Kconfig      2012-01-09 16:14:01.000000000 +0100
319 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/ia64/Kconfig linux-3.2.5-vs2.3.2.6/arch/ia64/Kconfig
330 --- linux-3.2.5/arch/ia64/Kconfig       2012-01-09 16:14:01.000000000 +0100
331 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/ia64/kernel/entry.S linux-3.2.5-vs2.3.2.6/arch/ia64/kernel/entry.S
342 --- linux-3.2.5/arch/ia64/kernel/entry.S        2012-01-09 16:14:02.000000000 +0100
343 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/ia64/kernel/process.c linux-3.2.5-vs2.3.2.6/arch/ia64/kernel/process.c
354 --- linux-3.2.5/arch/ia64/kernel/process.c      2011-03-15 18:06:39.000000000 +0100
355 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/ia64/kernel/ptrace.c linux-3.2.5-vs2.3.2.6/arch/ia64/kernel/ptrace.c
368 --- linux-3.2.5/arch/ia64/kernel/ptrace.c       2011-01-05 21:48:59.000000000 +0100
369 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/ia64/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/ia64/kernel/traps.c
379 --- linux-3.2.5/arch/ia64/kernel/traps.c        2010-07-07 18:31:01.000000000 +0200
380 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/m32r/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/m32r/kernel/traps.c
406 --- linux-3.2.5/arch/m32r/kernel/traps.c        2011-10-24 18:44:58.000000000 +0200
407 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/m68k/Kconfig linux-3.2.5-vs2.3.2.6/arch/m68k/Kconfig
421 --- linux-3.2.5/arch/m68k/Kconfig       2012-01-09 16:14:03.000000000 +0100
422 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/Kconfig linux-3.2.5-vs2.3.2.6/arch/mips/Kconfig
433 --- linux-3.2.5/arch/mips/Kconfig       2012-01-09 16:14:04.000000000 +0100
434 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/kernel/ptrace.c linux-3.2.5-vs2.3.2.6/arch/mips/kernel/ptrace.c
445 --- linux-3.2.5/arch/mips/kernel/ptrace.c       2011-07-22 11:17:36.000000000 +0200
446 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/kernel/scall32-o32.S linux-3.2.5-vs2.3.2.6/arch/mips/kernel/scall32-o32.S
466 --- linux-3.2.5/arch/mips/kernel/scall32-o32.S  2012-01-09 16:14:05.000000000 +0100
467 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/kernel/scall64-64.S linux-3.2.5-vs2.3.2.6/arch/mips/kernel/scall64-64.S
478 --- linux-3.2.5/arch/mips/kernel/scall64-64.S   2012-01-09 16:14:05.000000000 +0100
479 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/kernel/scall64-n32.S linux-3.2.5-vs2.3.2.6/arch/mips/kernel/scall64-n32.S
490 --- linux-3.2.5/arch/mips/kernel/scall64-n32.S  2012-01-09 16:14:05.000000000 +0100
491 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/kernel/scall64-o32.S linux-3.2.5-vs2.3.2.6/arch/mips/kernel/scall64-o32.S
502 --- linux-3.2.5/arch/mips/kernel/scall64-o32.S  2012-01-09 16:14:05.000000000 +0100
503 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/mips/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/mips/kernel/traps.c
514 --- linux-3.2.5/arch/mips/kernel/traps.c        2012-01-09 16:14:05.000000000 +0100
515 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/parisc/Kconfig linux-3.2.5-vs2.3.2.6/arch/parisc/Kconfig
531 --- linux-3.2.5/arch/parisc/Kconfig     2012-01-09 16:14:05.000000000 +0100
532 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/parisc/kernel/syscall_table.S linux-3.2.5-vs2.3.2.6/arch/parisc/kernel/syscall_table.S
543 --- linux-3.2.5/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
544 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/parisc/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/parisc/kernel/traps.c
555 --- linux-3.2.5/arch/parisc/kernel/traps.c      2011-10-24 18:45:00.000000000 +0200
556 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/parisc/mm/fault.c linux-3.2.5-vs2.3.2.6/arch/parisc/mm/fault.c
581 --- linux-3.2.5/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
582 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/powerpc/Kconfig linux-3.2.5-vs2.3.2.6/arch/powerpc/Kconfig
596 --- linux-3.2.5/arch/powerpc/Kconfig    2012-01-09 16:14:05.000000000 +0100
597 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/powerpc/include/asm/unistd.h linux-3.2.5-vs2.3.2.6/arch/powerpc/include/asm/unistd.h
608 --- linux-3.2.5/arch/powerpc/include/asm/unistd.h       2012-01-09 16:14:05.000000000 +0100
609 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/powerpc/kernel/process.c linux-3.2.5-vs2.3.2.6/arch/powerpc/kernel/process.c
620 --- linux-3.2.5/arch/powerpc/kernel/process.c   2012-01-09 16:14:05.000000000 +0100
621 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/powerpc/kernel/traps.c linux-3.2.5-vs2.3.2.6/arch/powerpc/kernel/traps.c
635 --- linux-3.2.5/arch/powerpc/kernel/traps.c     2012-01-09 16:14:05.000000000 +0100
636 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/s390/Kconfig linux-3.2.5-vs2.3.2.6/arch/s390/Kconfig
650 --- linux-3.2.5/arch/s390/Kconfig       2012-01-09 16:14:06.000000000 +0100
651 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/s390/include/asm/tlb.h linux-3.2.5-vs2.3.2.6/arch/s390/include/asm/tlb.h
662 --- linux-3.2.5/arch/s390/include/asm/tlb.h     2011-07-22 11:17:41.000000000 +0200
663 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/s390/include/asm/unistd.h linux-3.2.5-vs2.3.2.6/arch/s390/include/asm/unistd.h
673 --- linux-3.2.5/arch/s390/include/asm/unistd.h  2012-01-09 16:14:06.000000000 +0100
674 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/s390/kernel/ptrace.c linux-3.2.5-vs2.3.2.6/arch/s390/kernel/ptrace.c
685 --- linux-3.2.5/arch/s390/kernel/ptrace.c       2012-01-09 16:14:06.000000000 +0100
686 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/s390/kernel/syscalls.S linux-3.2.5-vs2.3.2.6/arch/s390/kernel/syscalls.S
696 --- linux-3.2.5/arch/s390/kernel/syscalls.S     2012-01-09 16:14:06.000000000 +0100
697 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/sh/Kconfig linux-3.2.5-vs2.3.2.6/arch/sh/Kconfig
708 --- linux-3.2.5/arch/sh/Kconfig 2012-01-09 16:14:07.000000000 +0100
709 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/sh/kernel/irq.c linux-3.2.5-vs2.3.2.6/arch/sh/kernel/irq.c
720 --- linux-3.2.5/arch/sh/kernel/irq.c    2011-07-22 11:17:41.000000000 +0200
721 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/sparc/Kconfig linux-3.2.5-vs2.3.2.6/arch/sparc/Kconfig
731 --- linux-3.2.5/arch/sparc/Kconfig      2012-01-09 16:14:07.000000000 +0100
732 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/sparc/include/asm/unistd.h linux-3.2.5-vs2.3.2.6/arch/sparc/include/asm/unistd.h
743 --- linux-3.2.5/arch/sparc/include/asm/unistd.h 2012-01-09 16:14:07.000000000 +0100
744 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/sparc/kernel/systbls_32.S linux-3.2.5-vs2.3.2.6/arch/sparc/kernel/systbls_32.S
755 --- linux-3.2.5/arch/sparc/kernel/systbls_32.S  2012-01-09 16:14:09.000000000 +0100
756 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/sparc/kernel/systbls_64.S linux-3.2.5-vs2.3.2.6/arch/sparc/kernel/systbls_64.S
767 --- linux-3.2.5/arch/sparc/kernel/systbls_64.S  2012-01-09 16:14:09.000000000 +0100
768 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/um/Kconfig.rest linux-3.2.5-vs2.3.2.6/arch/um/Kconfig.rest
788 --- linux-3.2.5/arch/um/Kconfig.rest    2012-01-09 16:14:09.000000000 +0100
789 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/um/include/shared/kern_constants.h linux-3.2.5-vs2.3.2.6/arch/um/include/shared/kern_constants.h
800 --- linux-3.2.5/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
801 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/um/include/shared/user_constants.h linux-3.2.5-vs2.3.2.6/arch/um/include/shared/user_constants.h
805 --- linux-3.2.5/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
806 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/x86/Kconfig linux-3.2.5-vs2.3.2.6/arch/x86/Kconfig
849 --- linux-3.2.5/arch/x86/Kconfig        2012-01-09 16:14:10.000000000 +0100
850 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/x86/ia32/ia32entry.S linux-3.2.5-vs2.3.2.6/arch/x86/ia32/ia32entry.S
861 --- linux-3.2.5/arch/x86/ia32/ia32entry.S       2012-01-09 16:14:10.000000000 +0100
862 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/x86/include/asm/unistd_64.h linux-3.2.5-vs2.3.2.6/arch/x86/include/asm/unistd_64.h
873 --- linux-3.2.5/arch/x86/include/asm/unistd_64.h        2012-01-09 16:14:11.000000000 +0100
874 +++ linux-3.2.5-vs2.3.2.6/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.5/arch/x86/kernel/syscall_table_32.S linux-3.2.5-vs2.3.2.6/arch/x86/kernel/syscall_table_32.S
885 --- linux-3.2.5/arch/x86/kernel/syscall_table_32.S      2012-01-09 16:14:11.000000000 +0100
886 +++ linux-3.2.5-vs2.3.2.6/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.5/drivers/block/Kconfig linux-3.2.5-vs2.3.2.6/drivers/block/Kconfig
897 --- linux-3.2.5/drivers/block/Kconfig   2011-10-24 18:45:08.000000000 +0200
898 +++ linux-3.2.5-vs2.3.2.6/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.5/drivers/block/Makefile linux-3.2.5-vs2.3.2.6/drivers/block/Makefile
914 --- linux-3.2.5/drivers/block/Makefile  2011-07-22 11:17:44.000000000 +0200
915 +++ linux-3.2.5-vs2.3.2.6/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.5/drivers/block/loop.c linux-3.2.5-vs2.3.2.6/drivers/block/loop.c
925 --- linux-3.2.5/drivers/block/loop.c    2012-01-09 16:14:15.000000000 +0100
926 +++ linux-3.2.5-vs2.3.2.6/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.5/drivers/block/vroot.c linux-3.2.5-vs2.3.2.6/drivers/block/vroot.c
983 --- linux-3.2.5/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
984 +++ linux-3.2.5-vs2.3.2.6/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.5/drivers/infiniband/core/addr.c linux-3.2.5-vs2.3.2.6/drivers/infiniband/core/addr.c
1278 --- linux-3.2.5/drivers/infiniband/core/addr.c  2012-01-09 16:14:19.000000000 +0100
1279 +++ linux-3.2.5-vs2.3.2.6/drivers/infiniband/core/addr.c        2011-12-05 19:33:02.000000000 +0100
1280 @@ -255,7 +255,7 @@ static int addr6_resolve(struct sockaddr
1281  
1282         if (ipv6_addr_any(&fl6.saddr)) {
1283                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1284 -                                        &fl6.daddr, 0, &fl6.saddr);
1285 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1286                 if (ret)
1287                         goto put;
1288  
1289 diff -NurpP --minimal linux-3.2.5/drivers/md/dm-ioctl.c linux-3.2.5-vs2.3.2.6/drivers/md/dm-ioctl.c
1290 --- linux-3.2.5/drivers/md/dm-ioctl.c   2012-01-09 16:14:20.000000000 +0100
1291 +++ linux-3.2.5-vs2.3.2.6/drivers/md/dm-ioctl.c 2011-12-05 19:33:02.000000000 +0100
1292 @@ -16,6 +16,7 @@
1293  #include <linux/dm-ioctl.h>
1294  #include <linux/hdreg.h>
1295  #include <linux/compat.h>
1296 +#include <linux/vs_context.h>
1297  
1298  #include <asm/uaccess.h>
1299  
1300 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1301         unsigned int h = hash_str(str);
1302  
1303         list_for_each_entry (hc, _name_buckets + h, name_list)
1304 -               if (!strcmp(hc->name, str)) {
1305 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1306 +                       !strcmp(hc->name, str)) {
1307                         dm_get(hc->md);
1308                         return hc;
1309                 }
1310 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1311         unsigned int h = hash_str(str);
1312  
1313         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1314 -               if (!strcmp(hc->uuid, str)) {
1315 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1316 +                       !strcmp(hc->uuid, str)) {
1317                         dm_get(hc->md);
1318                         return hc;
1319                 }
1320 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1321  static struct hash_cell *__get_dev_cell(uint64_t dev)
1322  {
1323         struct mapped_device *md;
1324 -       struct hash_cell *hc;
1325 +       struct hash_cell *hc = NULL;
1326  
1327         md = dm_get_md(huge_decode_dev(dev));
1328         if (!md)
1329                 return NULL;
1330  
1331 -       hc = dm_get_mdptr(md);
1332 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1333 +               hc = dm_get_mdptr(md);
1334 +
1335         if (!hc) {
1336                 dm_put(md);
1337                 return NULL;
1338 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1339  
1340  static int remove_all(struct dm_ioctl *param, size_t param_size)
1341  {
1342 +       if (!vx_check(0, VS_ADMIN))
1343 +               return -EPERM;
1344 +
1345         dm_hash_remove_all(1);
1346         param->data_size = 0;
1347         return 0;
1348 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl 
1349          */
1350         for (i = 0; i < NUM_BUCKETS; i++) {
1351                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1352 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1353 +                               continue;
1354                         needed += sizeof(struct dm_name_list);
1355                         needed += strlen(hc->name) + 1;
1356                         needed += ALIGN_MASK;
1357 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl 
1358          */
1359         for (i = 0; i < NUM_BUCKETS; i++) {
1360                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1361 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1362 +                               continue;
1363                         if (old_nl)
1364                                 old_nl->next = (uint32_t) ((void *) nl -
1365                                                            (void *) old_nl);
1366 @@ -1615,8 +1627,8 @@ static int ctl_ioctl(uint command, struc
1367         ioctl_fn fn = NULL;
1368         size_t input_param_size;
1369  
1370 -       /* only root can play with this */
1371 -       if (!capable(CAP_SYS_ADMIN))
1372 +       /* only root and certain contexts can play with this */
1373 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1374                 return -EACCES;
1375  
1376         if (_IOC_TYPE(command) != DM_IOCTL)
1377 diff -NurpP --minimal linux-3.2.5/drivers/md/dm.c linux-3.2.5-vs2.3.2.6/drivers/md/dm.c
1378 --- linux-3.2.5/drivers/md/dm.c 2012-01-09 16:14:21.000000000 +0100
1379 +++ linux-3.2.5-vs2.3.2.6/drivers/md/dm.c       2011-12-05 19:33:02.000000000 +0100
1380 @@ -20,6 +20,7 @@
1381  #include <linux/idr.h>
1382  #include <linux/hdreg.h>
1383  #include <linux/delay.h>
1384 +#include <linux/vs_base.h>
1385  
1386  #include <trace/events/block.h>
1387  
1388 @@ -132,6 +133,7 @@ struct mapped_device {
1389         rwlock_t map_lock;
1390         atomic_t holders;
1391         atomic_t open_count;
1392 +       xid_t xid;
1393  
1394         unsigned long flags;
1395  
1396 @@ -344,6 +346,7 @@ int dm_deleting_md(struct mapped_device 
1397  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1398  {
1399         struct mapped_device *md;
1400 +       int ret = -ENXIO;
1401  
1402         spin_lock(&_minor_lock);
1403  
1404 @@ -352,18 +355,19 @@ static int dm_blk_open(struct block_devi
1405                 goto out;
1406  
1407         if (test_bit(DMF_FREEING, &md->flags) ||
1408 -           dm_deleting_md(md)) {
1409 -               md = NULL;
1410 +           dm_deleting_md(md))
1411 +               goto out;
1412 +
1413 +       ret = -EACCES;
1414 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1415                 goto out;
1416 -       }
1417  
1418         dm_get(md);
1419         atomic_inc(&md->open_count);
1420 -
1421 +       ret = 0;
1422  out:
1423         spin_unlock(&_minor_lock);
1424 -
1425 -       return md ? 0 : -ENXIO;
1426 +       return ret;
1427  }
1428  
1429  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1430 @@ -584,6 +588,14 @@ int dm_set_geometry(struct mapped_device
1431         return 0;
1432  }
1433  
1434 +/*
1435 + * Get the xid associated with a dm device
1436 + */
1437 +xid_t dm_get_xid(struct mapped_device *md)
1438 +{
1439 +       return md->xid;
1440 +}
1441 +
1442  /*-----------------------------------------------------------------
1443   * CRUD START:
1444   *   A more elegant soln is in the works that uses the queue
1445 @@ -1850,6 +1862,7 @@ static struct mapped_device *alloc_dev(i
1446         INIT_LIST_HEAD(&md->uevent_list);
1447         spin_lock_init(&md->uevent_lock);
1448  
1449 +       md->xid = vx_current_xid();
1450         md->queue = blk_alloc_queue(GFP_KERNEL);
1451         if (!md->queue)
1452                 goto bad_queue;
1453 diff -NurpP --minimal linux-3.2.5/drivers/md/dm.h linux-3.2.5-vs2.3.2.6/drivers/md/dm.h
1454 --- linux-3.2.5/drivers/md/dm.h 2012-01-09 16:14:21.000000000 +0100
1455 +++ linux-3.2.5-vs2.3.2.6/drivers/md/dm.h       2011-12-05 19:33:02.000000000 +0100
1456 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1457  struct dm_table;
1458  struct dm_md_mempools;
1459  
1460 +xid_t dm_get_xid(struct mapped_device *md);
1461 +
1462  /*-----------------------------------------------------------------
1463   * Internal table functions.
1464   *---------------------------------------------------------------*/
1465 diff -NurpP --minimal linux-3.2.5/drivers/net/tun.c linux-3.2.5-vs2.3.2.6/drivers/net/tun.c
1466 --- linux-3.2.5/drivers/net/tun.c       2012-01-09 16:14:35.000000000 +0100
1467 +++ linux-3.2.5-vs2.3.2.6/drivers/net/tun.c     2011-12-05 19:33:02.000000000 +0100
1468 @@ -64,6 +64,7 @@
1469  #include <linux/nsproxy.h>
1470  #include <linux/virtio_net.h>
1471  #include <linux/rcupdate.h>
1472 +#include <linux/vs_network.h>
1473  #include <net/net_namespace.h>
1474  #include <net/netns/generic.h>
1475  #include <net/rtnetlink.h>
1476 @@ -121,6 +122,7 @@ struct tun_struct {
1477         unsigned int            flags;
1478         uid_t                   owner;
1479         gid_t                   group;
1480 +       nid_t                   nid;
1481  
1482         struct net_device       *dev;
1483         u32                     set_features;
1484 @@ -909,6 +911,7 @@ static void tun_setup(struct net_device 
1485  
1486         tun->owner = -1;
1487         tun->group = -1;
1488 +       tun->nid = current->nid;
1489  
1490         dev->ethtool_ops = &tun_ethtool_ops;
1491         dev->destructor = tun_free_netdev;
1492 @@ -1059,7 +1062,7 @@ static int tun_set_iff(struct net *net, 
1493  
1494                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1495                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1496 -                   !capable(CAP_NET_ADMIN))
1497 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1498                         return -EPERM;
1499                 err = security_tun_dev_attach(tun->socket.sk);
1500                 if (err < 0)
1501 @@ -1073,7 +1076,7 @@ static int tun_set_iff(struct net *net, 
1502                 char *name;
1503                 unsigned long flags = 0;
1504  
1505 -               if (!capable(CAP_NET_ADMIN))
1506 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1507                         return -EPERM;
1508                 err = security_tun_dev_create();
1509                 if (err < 0)
1510 @@ -1141,6 +1144,9 @@ static int tun_set_iff(struct net *net, 
1511  
1512                 sk->sk_destruct = tun_sock_destruct;
1513  
1514 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1515 +                       return -EPERM;
1516 +
1517                 err = tun_attach(tun, file);
1518                 if (err < 0)
1519                         goto failed;
1520 @@ -1322,6 +1328,16 @@ static long __tun_chr_ioctl(struct file 
1521                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1522                 break;
1523  
1524 +       case TUNSETNID:
1525 +               if (!capable(CAP_CONTEXT))
1526 +                       return -EPERM;
1527 +
1528 +               /* Set nid owner of the device */
1529 +               tun->nid = (nid_t) arg;
1530 +
1531 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1532 +               break;
1533 +
1534         case TUNSETLINK:
1535                 /* Only allow setting the type when the interface is down */
1536                 if (tun->dev->flags & IFF_UP) {
1537 diff -NurpP --minimal linux-3.2.5/drivers/tty/sysrq.c linux-3.2.5-vs2.3.2.6/drivers/tty/sysrq.c
1538 --- linux-3.2.5/drivers/tty/sysrq.c     2011-05-22 16:17:44.000000000 +0200
1539 +++ linux-3.2.5-vs2.3.2.6/drivers/tty/sysrq.c   2011-12-05 19:33:02.000000000 +0100
1540 @@ -41,6 +41,7 @@
1541  #include <linux/oom.h>
1542  #include <linux/slab.h>
1543  #include <linux/input.h>
1544 +#include <linux/vserver/debug.h>
1545  
1546  #include <asm/ptrace.h>
1547  #include <asm/irq_regs.h>
1548 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1549         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1550  };
1551  
1552 +
1553 +#ifdef CONFIG_VSERVER_DEBUG
1554 +static void sysrq_handle_vxinfo(int key)
1555 +{
1556 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1557 +}
1558 +
1559 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1560 +       .handler        = sysrq_handle_vxinfo,
1561 +       .help_msg       = "conteXt",
1562 +       .action_msg     = "Show Context Info",
1563 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1564 +};
1565 +#endif
1566 +
1567  /* Key Operations table and lock */
1568  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1569  
1570 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1571         NULL,                           /* v */
1572         &sysrq_showstate_blocked_op,    /* w */
1573         /* x: May be registered on ppc/powerpc for xmon */
1574 +#ifdef CONFIG_VSERVER_DEBUG
1575 +       &sysrq_showvxinfo_op,           /* x */
1576 +#else
1577         NULL,                           /* x */
1578 +#endif
1579         /* y: May be registered on sparc64 for global register dump */
1580         NULL,                           /* y */
1581         &sysrq_ftrace_dump_op,          /* z */
1582 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
1583                 retval = key - '0';
1584         else if ((key >= 'a') && (key <= 'z'))
1585                 retval = key + 10 - 'a';
1586 +       else if ((key >= 'A') && (key <= 'Z'))
1587 +               retval = key + 10 - 'A';
1588         else
1589                 retval = -1;
1590         return retval;
1591 diff -NurpP --minimal linux-3.2.5/drivers/tty/tty_io.c linux-3.2.5-vs2.3.2.6/drivers/tty/tty_io.c
1592 --- linux-3.2.5/drivers/tty/tty_io.c    2012-01-09 16:14:48.000000000 +0100
1593 +++ linux-3.2.5-vs2.3.2.6/drivers/tty/tty_io.c  2011-12-05 19:33:02.000000000 +0100
1594 @@ -105,6 +105,7 @@
1595  
1596  #include <linux/kmod.h>
1597  #include <linux/nsproxy.h>
1598 +#include <linux/vs_pid.h>
1599  
1600  #undef TTY_DEBUG_HANGUP
1601  
1602 @@ -2080,7 +2081,8 @@ static int tiocsti(struct tty_struct *tt
1603         char ch, mbz = 0;
1604         struct tty_ldisc *ld;
1605  
1606 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1607 +       if (((current->signal->tty != tty) &&
1608 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1609                 return -EPERM;
1610         if (get_user(ch, p))
1611                 return -EFAULT;
1612 @@ -2368,6 +2370,7 @@ static int tiocspgrp(struct tty_struct *
1613                 return -ENOTTY;
1614         if (get_user(pgrp_nr, p))
1615                 return -EFAULT;
1616 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1617         if (pgrp_nr < 0)
1618                 return -EINVAL;
1619         rcu_read_lock();
1620 diff -NurpP --minimal linux-3.2.5/fs/attr.c linux-3.2.5-vs2.3.2.6/fs/attr.c
1621 --- linux-3.2.5/fs/attr.c       2012-01-09 16:14:53.000000000 +0100
1622 +++ linux-3.2.5-vs2.3.2.6/fs/attr.c     2011-12-05 21:16:01.000000000 +0100
1623 @@ -14,6 +14,9 @@
1624  #include <linux/fcntl.h>
1625  #include <linux/security.h>
1626  #include <linux/evm.h>
1627 +#include <linux/proc_fs.h>
1628 +#include <linux/devpts_fs.h>
1629 +#include <linux/vs_tag.h>
1630  
1631  /**
1632   * inode_change_ok - check if attribute changes to an inode are allowed
1633 @@ -74,6 +77,10 @@ int inode_change_ok(const struct inode *
1634                         return -EPERM;
1635         }
1636  
1637 +       /* check for inode tag permission */
1638 +       if (dx_permission(inode, MAY_WRITE))
1639 +               return -EACCES;
1640 +
1641         return 0;
1642  }
1643  EXPORT_SYMBOL(inode_change_ok);
1644 @@ -144,6 +151,8 @@ void setattr_copy(struct inode *inode, c
1645                 inode->i_uid = attr->ia_uid;
1646         if (ia_valid & ATTR_GID)
1647                 inode->i_gid = attr->ia_gid;
1648 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1649 +               inode->i_tag = attr->ia_tag;
1650         if (ia_valid & ATTR_ATIME)
1651                 inode->i_atime = timespec_trunc(attr->ia_atime,
1652                                                 inode->i_sb->s_time_gran);
1653 @@ -171,7 +180,8 @@ int notify_change(struct dentry * dentry
1654         struct timespec now;
1655         unsigned int ia_valid = attr->ia_valid;
1656  
1657 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1658 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1659 +               ATTR_TAG | ATTR_TIMES_SET)) {
1660                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1661                         return -EPERM;
1662         }
1663 diff -NurpP --minimal linux-3.2.5/fs/block_dev.c linux-3.2.5-vs2.3.2.6/fs/block_dev.c
1664 --- linux-3.2.5/fs/block_dev.c  2012-01-09 16:14:53.000000000 +0100
1665 +++ linux-3.2.5-vs2.3.2.6/fs/block_dev.c        2011-12-05 19:33:02.000000000 +0100
1666 @@ -25,6 +25,7 @@
1667  #include <linux/namei.h>
1668  #include <linux/log2.h>
1669  #include <linux/kmemleak.h>
1670 +#include <linux/vs_device.h>
1671  #include <asm/uaccess.h>
1672  #include "internal.h"
1673  
1674 @@ -563,6 +564,7 @@ struct block_device *bdget(dev_t dev)
1675                 bdev->bd_invalidated = 0;
1676                 inode->i_mode = S_IFBLK;
1677                 inode->i_rdev = dev;
1678 +               inode->i_mdev = dev;
1679                 inode->i_bdev = bdev;
1680                 inode->i_data.a_ops = &def_blk_aops;
1681                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1682 @@ -609,6 +611,11 @@ EXPORT_SYMBOL(bdput);
1683  static struct block_device *bd_acquire(struct inode *inode)
1684  {
1685         struct block_device *bdev;
1686 +       dev_t mdev;
1687 +
1688 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1689 +               return NULL;
1690 +       inode->i_mdev = mdev;
1691  
1692         spin_lock(&bdev_lock);
1693         bdev = inode->i_bdev;
1694 @@ -619,7 +626,7 @@ static struct block_device *bd_acquire(s
1695         }
1696         spin_unlock(&bdev_lock);
1697  
1698 -       bdev = bdget(inode->i_rdev);
1699 +       bdev = bdget(mdev);
1700         if (bdev) {
1701                 spin_lock(&bdev_lock);
1702                 if (!inode->i_bdev) {
1703 diff -NurpP --minimal linux-3.2.5/fs/btrfs/ctree.h linux-3.2.5-vs2.3.2.6/fs/btrfs/ctree.h
1704 --- linux-3.2.5/fs/btrfs/ctree.h        2012-01-09 16:14:53.000000000 +0100
1705 +++ linux-3.2.5-vs2.3.2.6/fs/btrfs/ctree.h      2012-01-09 16:19:31.000000000 +0100
1706 @@ -643,11 +643,14 @@ struct btrfs_inode_item {
1707         /* modification sequence number for NFS */
1708         __le64 sequence;
1709  
1710 +       __le16 tag;
1711         /*
1712          * a little future expansion, for more than this we can
1713          * just grow the inode item and version it
1714          */
1715 -       __le64 reserved[4];
1716 +       __le16 reserved16;
1717 +       __le32 reserved32;
1718 +       __le64 reserved[3];
1719         struct btrfs_timespec atime;
1720         struct btrfs_timespec ctime;
1721         struct btrfs_timespec mtime;
1722 @@ -1414,6 +1417,8 @@ struct btrfs_ioctl_defrag_range_args {
1723  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
1724  #define BTRFS_MOUNT_RECOVERY           (1 << 18)
1725  
1726 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1727 +
1728  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1729  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1730  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1731 @@ -1621,6 +1626,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1732  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1733  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1734  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1735 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1736  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1737  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1738  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1739 @@ -1674,6 +1680,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1740  
1741  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1742  
1743 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1744 +#define BTRFS_INODE_BARRIER            (1 << 25)
1745 +#define BTRFS_INODE_COW                        (1 << 26)
1746 +
1747  
1748  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1749  
1750 @@ -2730,6 +2740,7 @@ extern const struct dentry_operations bt
1751  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1752  void btrfs_update_iflags(struct inode *inode);
1753  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1754 +int btrfs_sync_flags(struct inode *inode, int, int);
1755  int btrfs_defrag_file(struct inode *inode, struct file *file,
1756                       struct btrfs_ioctl_defrag_range_args *range,
1757                       u64 newer_than, unsigned long max_pages);
1758 diff -NurpP --minimal linux-3.2.5/fs/btrfs/disk-io.c linux-3.2.5-vs2.3.2.6/fs/btrfs/disk-io.c
1759 --- linux-3.2.5/fs/btrfs/disk-io.c      2012-01-09 16:14:53.000000000 +0100
1760 +++ linux-3.2.5-vs2.3.2.6/fs/btrfs/disk-io.c    2012-01-09 16:19:31.000000000 +0100
1761 @@ -2103,6 +2103,9 @@ struct btrfs_root *open_ctree(struct sup
1762                 goto fail_alloc;
1763         }
1764  
1765 +       if (btrfs_test_opt(tree_root, TAGGED))
1766 +               sb->s_flags |= MS_TAGGED;
1767 +
1768         features = btrfs_super_incompat_flags(disk_super) &
1769                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1770         if (features) {
1771 diff -NurpP --minimal linux-3.2.5/fs/btrfs/inode.c linux-3.2.5-vs2.3.2.6/fs/btrfs/inode.c
1772 --- linux-3.2.5/fs/btrfs/inode.c        2012-01-09 16:14:53.000000000 +0100
1773 +++ linux-3.2.5-vs2.3.2.6/fs/btrfs/inode.c      2012-01-09 16:19:51.000000000 +0100
1774 @@ -39,6 +39,7 @@
1775  #include <linux/slab.h>
1776  #include <linux/ratelimit.h>
1777  #include <linux/mount.h>
1778 +#include <linux/vs_tag.h>
1779  #include "compat.h"
1780  #include "ctree.h"
1781  #include "disk-io.h"
1782 @@ -2332,6 +2333,8 @@ static void btrfs_read_locked_inode(stru
1783         struct btrfs_key location;
1784         int maybe_acls;
1785         u32 rdev;
1786 +       uid_t uid;
1787 +       gid_t gid;
1788         int ret;
1789         bool filled = false;
1790  
1791 @@ -2359,8 +2362,13 @@ static void btrfs_read_locked_inode(stru
1792                                     struct btrfs_inode_item);
1793         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1794         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1795 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1796 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1797 +
1798 +       uid = btrfs_inode_uid(leaf, inode_item);
1799 +       gid = btrfs_inode_gid(leaf, inode_item);
1800 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1801 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1802 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1803 +               btrfs_inode_tag(leaf, inode_item));
1804         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1805  
1806         tspec = btrfs_inode_atime(inode_item);
1807 @@ -2438,8 +2446,14 @@ static void fill_inode_item(struct btrfs
1808                             struct btrfs_inode_item *item,
1809                             struct inode *inode)
1810  {
1811 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1812 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1813 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1814 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1815 +
1816 +       btrfs_set_inode_uid(leaf, item, uid);
1817 +       btrfs_set_inode_gid(leaf, item, gid);
1818 +#ifdef CONFIG_TAGGING_INTERN
1819 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1820 +#endif
1821         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1822         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1823         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1824 @@ -7377,11 +7391,13 @@ static const struct inode_operations btr
1825         .listxattr      = btrfs_listxattr,
1826         .removexattr    = btrfs_removexattr,
1827         .permission     = btrfs_permission,
1828 +       .sync_flags     = btrfs_sync_flags,
1829         .get_acl        = btrfs_get_acl,
1830  };
1831  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1832         .lookup         = btrfs_lookup,
1833         .permission     = btrfs_permission,
1834 +       .sync_flags     = btrfs_sync_flags,
1835         .get_acl        = btrfs_get_acl,
1836  };
1837  
1838 diff -NurpP --minimal linux-3.2.5/fs/btrfs/ioctl.c linux-3.2.5-vs2.3.2.6/fs/btrfs/ioctl.c
1839 --- linux-3.2.5/fs/btrfs/ioctl.c        2012-01-09 16:14:53.000000000 +0100
1840 +++ linux-3.2.5-vs2.3.2.6/fs/btrfs/ioctl.c      2012-01-09 16:19:31.000000000 +0100
1841 @@ -71,10 +71,13 @@ static unsigned int btrfs_flags_to_ioctl
1842  {
1843         unsigned int iflags = 0;
1844  
1845 -       if (flags & BTRFS_INODE_SYNC)
1846 -               iflags |= FS_SYNC_FL;
1847         if (flags & BTRFS_INODE_IMMUTABLE)
1848                 iflags |= FS_IMMUTABLE_FL;
1849 +       if (flags & BTRFS_INODE_IXUNLINK)
1850 +               iflags |= FS_IXUNLINK_FL;
1851 +
1852 +       if (flags & BTRFS_INODE_SYNC)
1853 +               iflags |= FS_SYNC_FL;
1854         if (flags & BTRFS_INODE_APPEND)
1855                 iflags |= FS_APPEND_FL;
1856         if (flags & BTRFS_INODE_NODUMP)
1857 @@ -91,28 +94,78 @@ static unsigned int btrfs_flags_to_ioctl
1858         else if (flags & BTRFS_INODE_NOCOMPRESS)
1859                 iflags |= FS_NOCOMP_FL;
1860  
1861 +       if (flags & BTRFS_INODE_BARRIER)
1862 +               iflags |= FS_BARRIER_FL;
1863 +       if (flags & BTRFS_INODE_COW)
1864 +               iflags |= FS_COW_FL;
1865         return iflags;
1866  }
1867  
1868  /*
1869 - * Update inode->i_flags based on the btrfs internal flags.
1870 + * Update inode->i_(v)flags based on the btrfs internal flags.
1871   */
1872  void btrfs_update_iflags(struct inode *inode)
1873  {
1874         struct btrfs_inode *ip = BTRFS_I(inode);
1875  
1876 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1877 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1878 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1879  
1880 -       if (ip->flags & BTRFS_INODE_SYNC)
1881 -               inode->i_flags |= S_SYNC;
1882         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1883                 inode->i_flags |= S_IMMUTABLE;
1884 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1885 +               inode->i_flags |= S_IXUNLINK;
1886 +
1887 +       if (ip->flags & BTRFS_INODE_SYNC)
1888 +               inode->i_flags |= S_SYNC;
1889         if (ip->flags & BTRFS_INODE_APPEND)
1890                 inode->i_flags |= S_APPEND;
1891         if (ip->flags & BTRFS_INODE_NOATIME)
1892                 inode->i_flags |= S_NOATIME;
1893         if (ip->flags & BTRFS_INODE_DIRSYNC)
1894                 inode->i_flags |= S_DIRSYNC;
1895 +
1896 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1897 +
1898 +       if (ip->flags & BTRFS_INODE_BARRIER)
1899 +               inode->i_vflags |= V_BARRIER;
1900 +       if (ip->flags & BTRFS_INODE_COW)
1901 +               inode->i_vflags |= V_COW;
1902 +}
1903 +
1904 +/*
1905 + * Update btrfs internal flags from inode->i_(v)flags.
1906 + */
1907 +void btrfs_update_flags(struct inode *inode)
1908 +{
1909 +       struct btrfs_inode *ip = BTRFS_I(inode);
1910 +
1911 +       unsigned int flags = inode->i_flags;
1912 +       unsigned int vflags = inode->i_vflags;
1913 +
1914 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1915 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1916 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1917 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1918 +
1919 +       if (flags & S_IMMUTABLE)
1920 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1921 +       if (flags & S_IXUNLINK)
1922 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1923 +
1924 +       if (flags & S_SYNC)
1925 +               ip->flags |= BTRFS_INODE_SYNC;
1926 +       if (flags & S_APPEND)
1927 +               ip->flags |= BTRFS_INODE_APPEND;
1928 +       if (flags & S_NOATIME)
1929 +               ip->flags |= BTRFS_INODE_NOATIME;
1930 +       if (flags & S_DIRSYNC)
1931 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1932 +
1933 +       if (vflags & V_BARRIER)
1934 +               ip->flags |= BTRFS_INODE_BARRIER;
1935 +       if (vflags & V_COW)
1936 +               ip->flags |= BTRFS_INODE_COW;
1937  }
1938  
1939  /*
1940 @@ -128,6 +181,7 @@ void btrfs_inherit_iflags(struct inode *
1941                 return;
1942  
1943         flags = BTRFS_I(dir)->flags;
1944 +       flags &= ~BTRFS_INODE_BARRIER;
1945  
1946         if (flags & BTRFS_INODE_NOCOMPRESS) {
1947                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1948 @@ -143,6 +197,30 @@ void btrfs_inherit_iflags(struct inode *
1949         btrfs_update_iflags(inode);
1950  }
1951  
1952 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1953 +{
1954 +       struct btrfs_inode *ip = BTRFS_I(inode);
1955 +       struct btrfs_root *root = ip->root;
1956 +       struct btrfs_trans_handle *trans;
1957 +       int ret;
1958 +
1959 +       trans = btrfs_join_transaction(root);
1960 +       BUG_ON(!trans);
1961 +
1962 +       inode->i_flags = flags;
1963 +       inode->i_vflags = vflags;
1964 +       btrfs_update_flags(inode);
1965 +
1966 +       ret = btrfs_update_inode(trans, root, inode);
1967 +       BUG_ON(ret);
1968 +
1969 +       btrfs_update_iflags(inode);
1970 +       inode->i_ctime = CURRENT_TIME;
1971 +       btrfs_end_transaction(trans, root);
1972 +
1973 +       return 0;
1974 +}
1975 +
1976  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1977  {
1978         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1979 @@ -194,7 +272,8 @@ static int btrfs_ioctl_setflags(struct f
1980  
1981         flags = btrfs_mask_flags(inode->i_mode, flags);
1982         oldflags = btrfs_flags_to_ioctl(ip->flags);
1983 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1984 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1985 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1986                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1987                         ret = -EPERM;
1988                         goto out_unlock;
1989 @@ -205,14 +284,19 @@ static int btrfs_ioctl_setflags(struct f
1990         if (ret)
1991                 goto out_unlock;
1992  
1993 -       if (flags & FS_SYNC_FL)
1994 -               ip->flags |= BTRFS_INODE_SYNC;
1995 -       else
1996 -               ip->flags &= ~BTRFS_INODE_SYNC;
1997         if (flags & FS_IMMUTABLE_FL)
1998                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1999         else
2000                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2001 +       if (flags & FS_IXUNLINK_FL)
2002 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2003 +       else
2004 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2005 +
2006 +       if (flags & FS_SYNC_FL)
2007 +               ip->flags |= BTRFS_INODE_SYNC;
2008 +       else
2009 +               ip->flags &= ~BTRFS_INODE_SYNC;
2010         if (flags & FS_APPEND_FL)
2011                 ip->flags |= BTRFS_INODE_APPEND;
2012         else
2013 diff -NurpP --minimal linux-3.2.5/fs/btrfs/super.c linux-3.2.5-vs2.3.2.6/fs/btrfs/super.c
2014 --- linux-3.2.5/fs/btrfs/super.c        2012-01-09 16:14:53.000000000 +0100
2015 +++ linux-3.2.5-vs2.3.2.6/fs/btrfs/super.c      2012-01-09 16:19:31.000000000 +0100
2016 @@ -165,7 +165,8 @@ enum {
2017         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2018         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2019         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
2020 -       Opt_inode_cache, Opt_no_space_cache, Opt_recovery, Opt_err,
2021 +       Opt_inode_cache, Opt_no_space_cache, Opt_recovery,
2022 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2023  };
2024  
2025  static match_table_t tokens = {
2026 @@ -200,6 +201,9 @@ static match_table_t tokens = {
2027         {Opt_inode_cache, "inode_cache"},
2028         {Opt_no_space_cache, "nospace_cache"},
2029         {Opt_recovery, "recovery"},
2030 +       {Opt_tag, "tag"},
2031 +       {Opt_notag, "notag"},
2032 +       {Opt_tagid, "tagid=%u"},
2033         {Opt_err, NULL},
2034  };
2035  
2036 @@ -398,6 +402,22 @@ int btrfs_parse_options(struct btrfs_roo
2037                         printk(KERN_INFO "btrfs: enabling auto recovery");
2038                         btrfs_set_opt(info->mount_opt, RECOVERY);
2039                         break;
2040 +#ifndef CONFIG_TAGGING_NONE
2041 +               case Opt_tag:
2042 +                       printk(KERN_INFO "btrfs: use tagging\n");
2043 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2044 +                       break;
2045 +               case Opt_notag:
2046 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2047 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2048 +                       break;
2049 +#endif
2050 +#ifdef CONFIG_PROPAGATE
2051 +               case Opt_tagid:
2052 +                       /* use args[0] */
2053 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2054 +                       break;
2055 +#endif
2056                 case Opt_err:
2057                         printk(KERN_INFO "btrfs: unrecognized mount option "
2058                                "'%s'\n", p);
2059 @@ -985,6 +1005,12 @@ static int btrfs_remount(struct super_bl
2060         if (ret)
2061                 return -EINVAL;
2062  
2063 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2064 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2065 +                       sb->s_id);
2066 +               return -EINVAL;
2067 +       }
2068 +
2069         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2070                 return 0;
2071  
2072 diff -NurpP --minimal linux-3.2.5/fs/char_dev.c linux-3.2.5-vs2.3.2.6/fs/char_dev.c
2073 --- linux-3.2.5/fs/char_dev.c   2011-03-15 18:07:31.000000000 +0100
2074 +++ linux-3.2.5-vs2.3.2.6/fs/char_dev.c 2011-12-05 19:33:02.000000000 +0100
2075 @@ -21,6 +21,8 @@
2076  #include <linux/mutex.h>
2077  #include <linux/backing-dev.h>
2078  #include <linux/tty.h>
2079 +#include <linux/vs_context.h>
2080 +#include <linux/vs_device.h>
2081  
2082  #include "internal.h"
2083  
2084 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2085         struct cdev *p;
2086         struct cdev *new = NULL;
2087         int ret = 0;
2088 +       dev_t mdev;
2089 +
2090 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2091 +               return -EPERM;
2092 +       inode->i_mdev = mdev;
2093  
2094         spin_lock(&cdev_lock);
2095         p = inode->i_cdev;
2096         if (!p) {
2097                 struct kobject *kobj;
2098                 int idx;
2099 +
2100                 spin_unlock(&cdev_lock);
2101 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2102 +
2103 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2104                 if (!kobj)
2105                         return -ENXIO;
2106                 new = container_of(kobj, struct cdev, kobj);
2107 diff -NurpP --minimal linux-3.2.5/fs/dcache.c linux-3.2.5-vs2.3.2.6/fs/dcache.c
2108 --- linux-3.2.5/fs/dcache.c     2012-02-07 01:57:54.000000000 +0100
2109 +++ linux-3.2.5-vs2.3.2.6/fs/dcache.c   2012-01-26 08:52:10.000000000 +0100
2110 @@ -37,6 +37,7 @@
2111  #include <linux/rculist_bl.h>
2112  #include <linux/prefetch.h>
2113  #include <linux/ratelimit.h>
2114 +#include <linux/vs_limit.h>
2115  #include "internal.h"
2116  
2117  /*
2118 @@ -539,6 +540,8 @@ int d_invalidate(struct dentry * dentry)
2119                 spin_lock(&dentry->d_lock);
2120         }
2121  
2122 +       vx_dentry_dec(dentry);
2123 +
2124         /*
2125          * Somebody else still using it?
2126          *
2127 @@ -568,6 +571,7 @@ EXPORT_SYMBOL(d_invalidate);
2128  static inline void __dget_dlock(struct dentry *dentry)
2129  {
2130         dentry->d_count++;
2131 +       vx_dentry_inc(dentry);
2132  }
2133  
2134  static inline void __dget(struct dentry *dentry)
2135 @@ -1192,6 +1196,9 @@ struct dentry *__d_alloc(struct super_bl
2136         struct dentry *dentry;
2137         char *dname;
2138  
2139 +       if (!vx_dentry_avail(1))
2140 +               return NULL;
2141 +
2142         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2143         if (!dentry)
2144                 return NULL;
2145 @@ -1214,6 +1221,7 @@ struct dentry *__d_alloc(struct super_bl
2146  
2147         dentry->d_count = 1;
2148         dentry->d_flags = 0;
2149 +       vx_dentry_inc(dentry);
2150         spin_lock_init(&dentry->d_lock);
2151         seqcount_init(&dentry->d_seq);
2152         dentry->d_inode = NULL;
2153 @@ -1872,6 +1880,7 @@ struct dentry *__d_lookup(struct dentry 
2154                 }
2155  
2156                 dentry->d_count++;
2157 +               vx_dentry_inc(dentry);
2158                 found = dentry;
2159                 spin_unlock(&dentry->d_lock);
2160                 break;
2161 diff -NurpP --minimal linux-3.2.5/fs/devpts/inode.c linux-3.2.5-vs2.3.2.6/fs/devpts/inode.c
2162 --- linux-3.2.5/fs/devpts/inode.c       2012-01-09 16:14:54.000000000 +0100
2163 +++ linux-3.2.5-vs2.3.2.6/fs/devpts/inode.c     2011-12-05 21:23:19.000000000 +0100
2164 @@ -25,6 +25,7 @@
2165  #include <linux/parser.h>
2166  #include <linux/fsnotify.h>
2167  #include <linux/seq_file.h>
2168 +#include <linux/vs_base.h>
2169  
2170  #define DEVPTS_DEFAULT_MODE 0600
2171  /*
2172 @@ -36,6 +37,20 @@
2173  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2174  #define PTMX_MINOR     2
2175  
2176 +static int devpts_permission(struct inode *inode, int mask)
2177 +{
2178 +       int ret = -EACCES;
2179 +
2180 +       /* devpts is xid tagged */
2181 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2182 +               ret = generic_permission(inode, mask);
2183 +       return ret;
2184 +}
2185 +
2186 +static struct inode_operations devpts_file_inode_operations = {
2187 +       .permission     = devpts_permission,
2188 +};
2189 +
2190  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2191  static DEFINE_MUTEX(allocated_ptys_lock);
2192  
2193 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2194         return 0;
2195  }
2196  
2197 +static int devpts_filter(struct dentry *de)
2198 +{
2199 +       xid_t xid = 0;
2200 +
2201 +       /* devpts is xid tagged */
2202 +       if (de && de->d_inode)
2203 +               xid = (xid_t)de->d_inode->i_tag;
2204 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2205 +       else
2206 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2207 +                       de->d_name.len, de->d_name.name);
2208 +#endif
2209 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2210 +}
2211 +
2212 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2213 +{
2214 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2215 +}
2216 +
2217 +static struct file_operations devpts_dir_operations = {
2218 +       .open           = dcache_dir_open,
2219 +       .release        = dcache_dir_close,
2220 +       .llseek         = dcache_dir_lseek,
2221 +       .read           = generic_read_dir,
2222 +       .readdir        = devpts_readdir,
2223 +};
2224 +
2225  static const struct super_operations devpts_sops = {
2226         .statfs         = simple_statfs,
2227         .remount_fs     = devpts_remount,
2228 @@ -306,8 +349,10 @@ devpts_fill_super(struct super_block *s,
2229         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2230         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2231         inode->i_op = &simple_dir_inode_operations;
2232 -       inode->i_fop = &simple_dir_operations;
2233 +       inode->i_fop = &devpts_dir_operations;
2234         set_nlink(inode, 2);
2235 +       /* devpts is xid tagged */
2236 +       inode->i_tag = (tag_t)vx_current_xid();
2237  
2238         s->s_root = d_alloc_root(inode);
2239         if (s->s_root)
2240 @@ -494,6 +539,9 @@ int devpts_pty_new(struct inode *ptmx_in
2241         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2242         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2243         init_special_inode(inode, S_IFCHR|opts->mode, device);
2244 +       /* devpts is xid tagged */
2245 +       inode->i_tag = (tag_t)vx_current_xid();
2246 +       inode->i_op = &devpts_file_inode_operations;
2247         inode->i_private = tty;
2248         tty->driver_data = inode;
2249  
2250 diff -NurpP --minimal linux-3.2.5/fs/ext2/balloc.c linux-3.2.5-vs2.3.2.6/fs/ext2/balloc.c
2251 --- linux-3.2.5/fs/ext2/balloc.c        2012-01-09 16:14:54.000000000 +0100
2252 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/balloc.c      2011-12-05 19:33:02.000000000 +0100
2253 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2254                         start = 0;
2255                 end = EXT2_BLOCKS_PER_GROUP(sb);
2256         }
2257 -
2258         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2259  
2260  repeat:
2261 diff -NurpP --minimal linux-3.2.5/fs/ext2/ext2.h linux-3.2.5-vs2.3.2.6/fs/ext2/ext2.h
2262 --- linux-3.2.5/fs/ext2/ext2.h  2012-01-09 16:14:54.000000000 +0100
2263 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/ext2.h        2011-12-05 19:33:02.000000000 +0100
2264 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2265  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2266  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2267                        u64 start, u64 len);
2268 +extern int ext2_sync_flags(struct inode *, int, int);
2269  
2270  /* ioctl.c */
2271  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2272 diff -NurpP --minimal linux-3.2.5/fs/ext2/file.c linux-3.2.5-vs2.3.2.6/fs/ext2/file.c
2273 --- linux-3.2.5/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2274 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/file.c        2011-12-05 19:33:02.000000000 +0100
2275 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2276         .setattr        = ext2_setattr,
2277         .get_acl        = ext2_get_acl,
2278         .fiemap         = ext2_fiemap,
2279 +       .sync_flags     = ext2_sync_flags,
2280  };
2281 diff -NurpP --minimal linux-3.2.5/fs/ext2/ialloc.c linux-3.2.5-vs2.3.2.6/fs/ext2/ialloc.c
2282 --- linux-3.2.5/fs/ext2/ialloc.c        2012-01-09 16:14:54.000000000 +0100
2283 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/ialloc.c      2011-12-05 19:33:02.000000000 +0100
2284 @@ -17,6 +17,7 @@
2285  #include <linux/backing-dev.h>
2286  #include <linux/buffer_head.h>
2287  #include <linux/random.h>
2288 +#include <linux/vs_tag.h>
2289  #include "ext2.h"
2290  #include "xattr.h"
2291  #include "acl.h"
2292 @@ -549,6 +550,7 @@ got:
2293                 inode->i_mode = mode;
2294                 inode->i_uid = current_fsuid();
2295                 inode->i_gid = dir->i_gid;
2296 +               inode->i_tag = dx_current_fstag(sb);
2297         } else
2298                 inode_init_owner(inode, dir, mode);
2299  
2300 diff -NurpP --minimal linux-3.2.5/fs/ext2/inode.c linux-3.2.5-vs2.3.2.6/fs/ext2/inode.c
2301 --- linux-3.2.5/fs/ext2/inode.c 2012-01-09 16:14:54.000000000 +0100
2302 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/inode.c       2011-12-05 21:24:12.000000000 +0100
2303 @@ -32,6 +32,7 @@
2304  #include <linux/mpage.h>
2305  #include <linux/fiemap.h>
2306  #include <linux/namei.h>
2307 +#include <linux/vs_tag.h>
2308  #include "ext2.h"
2309  #include "acl.h"
2310  #include "xip.h"
2311 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
2312                 return;
2313         if (ext2_inode_is_fast_symlink(inode))
2314                 return;
2315 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2316 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2317                 return;
2318         __ext2_truncate_blocks(inode, offset);
2319  }
2320 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2321  {
2322         unsigned int flags = EXT2_I(inode)->i_flags;
2323  
2324 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2325 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2326 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2327 +
2328 +
2329 +       if (flags & EXT2_IMMUTABLE_FL)
2330 +               inode->i_flags |= S_IMMUTABLE;
2331 +       if (flags & EXT2_IXUNLINK_FL)
2332 +               inode->i_flags |= S_IXUNLINK;
2333 +
2334         if (flags & EXT2_SYNC_FL)
2335                 inode->i_flags |= S_SYNC;
2336         if (flags & EXT2_APPEND_FL)
2337                 inode->i_flags |= S_APPEND;
2338 -       if (flags & EXT2_IMMUTABLE_FL)
2339 -               inode->i_flags |= S_IMMUTABLE;
2340         if (flags & EXT2_NOATIME_FL)
2341                 inode->i_flags |= S_NOATIME;
2342         if (flags & EXT2_DIRSYNC_FL)
2343                 inode->i_flags |= S_DIRSYNC;
2344 +
2345 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2346 +
2347 +       if (flags & EXT2_BARRIER_FL)
2348 +               inode->i_vflags |= V_BARRIER;
2349 +       if (flags & EXT2_COW_FL)
2350 +               inode->i_vflags |= V_COW;
2351  }
2352  
2353  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2354  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2355  {
2356         unsigned int flags = ei->vfs_inode.i_flags;
2357 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2358 +
2359 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2360 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2361 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2362 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2363 +
2364 +       if (flags & S_IMMUTABLE)
2365 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2366 +       if (flags & S_IXUNLINK)
2367 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2368  
2369 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2370 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2371         if (flags & S_SYNC)
2372                 ei->i_flags |= EXT2_SYNC_FL;
2373         if (flags & S_APPEND)
2374                 ei->i_flags |= EXT2_APPEND_FL;
2375 -       if (flags & S_IMMUTABLE)
2376 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2377         if (flags & S_NOATIME)
2378                 ei->i_flags |= EXT2_NOATIME_FL;
2379         if (flags & S_DIRSYNC)
2380                 ei->i_flags |= EXT2_DIRSYNC_FL;
2381 +
2382 +       if (vflags & V_BARRIER)
2383 +               ei->i_flags |= EXT2_BARRIER_FL;
2384 +       if (vflags & V_COW)
2385 +               ei->i_flags |= EXT2_COW_FL;
2386  }
2387  
2388  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2389 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2390         struct ext2_inode *raw_inode;
2391         struct inode *inode;
2392         long ret = -EIO;
2393 +       uid_t uid;
2394 +       gid_t gid;
2395         int n;
2396  
2397         inode = iget_locked(sb, ino);
2398 @@ -1315,12 +1343,16 @@ struct inode *ext2_iget (struct super_bl
2399         }
2400  
2401         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2402 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2403 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2404 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2405 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2406         if (!(test_opt (inode->i_sb, NO_UID32))) {
2407 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2408 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2409 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2410 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2411         }
2412 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2413 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2414 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2415 +               le16_to_cpu(raw_inode->i_raw_tag));
2416         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2417         inode->i_size = le32_to_cpu(raw_inode->i_size);
2418         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2419 @@ -1418,8 +1450,8 @@ static int __ext2_write_inode(struct ino
2420         struct ext2_inode_info *ei = EXT2_I(inode);
2421         struct super_block *sb = inode->i_sb;
2422         ino_t ino = inode->i_ino;
2423 -       uid_t uid = inode->i_uid;
2424 -       gid_t gid = inode->i_gid;
2425 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2426 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2427         struct buffer_head * bh;
2428         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2429         int n;
2430 @@ -1455,6 +1487,9 @@ static int __ext2_write_inode(struct ino
2431                 raw_inode->i_uid_high = 0;
2432                 raw_inode->i_gid_high = 0;
2433         }
2434 +#ifdef CONFIG_TAGGING_INTERN
2435 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2436 +#endif
2437         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2438         raw_inode->i_size = cpu_to_le32(inode->i_size);
2439         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2440 @@ -1535,7 +1570,8 @@ int ext2_setattr(struct dentry *dentry, 
2441         if (is_quota_modification(inode, iattr))
2442                 dquot_initialize(inode);
2443         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2444 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2445 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2446 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2447                 error = dquot_transfer(inode, iattr);
2448                 if (error)
2449                         return error;
2450 diff -NurpP --minimal linux-3.2.5/fs/ext2/ioctl.c linux-3.2.5-vs2.3.2.6/fs/ext2/ioctl.c
2451 --- linux-3.2.5/fs/ext2/ioctl.c 2011-05-22 16:17:51.000000000 +0200
2452 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/ioctl.c       2011-12-05 19:33:02.000000000 +0100
2453 @@ -17,6 +17,16 @@
2454  #include <asm/uaccess.h>
2455  
2456  
2457 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2458 +{
2459 +       inode->i_flags = flags;
2460 +       inode->i_vflags = vflags;
2461 +       ext2_get_inode_flags(EXT2_I(inode));
2462 +       inode->i_ctime = CURRENT_TIME_SEC;
2463 +       mark_inode_dirty(inode);
2464 +       return 0;
2465 +}
2466 +
2467  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2468  {
2469         struct inode *inode = filp->f_dentry->d_inode;
2470 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2471  
2472                 flags = ext2_mask_flags(inode->i_mode, flags);
2473  
2474 +               if (IS_BARRIER(inode)) {
2475 +                       vxwprintk_task(1, "messing with the barrier.");
2476 +                       return -EACCES;
2477 +               }
2478 +
2479                 mutex_lock(&inode->i_mutex);
2480                 /* Is it quota file? Do not allow user to mess with it */
2481                 if (IS_NOQUOTA(inode)) {
2482 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2483                  *
2484                  * This test looks nicer. Thanks to Pauline Middelink
2485                  */
2486 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2487 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2488 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2489 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2490                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2491                                 mutex_unlock(&inode->i_mutex);
2492                                 ret = -EPERM;
2493 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2494                         }
2495                 }
2496  
2497 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2498 +               flags &= EXT2_FL_USER_MODIFIABLE;
2499                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2500                 ei->i_flags = flags;
2501                 mutex_unlock(&inode->i_mutex);
2502 diff -NurpP --minimal linux-3.2.5/fs/ext2/namei.c linux-3.2.5-vs2.3.2.6/fs/ext2/namei.c
2503 --- linux-3.2.5/fs/ext2/namei.c 2011-10-24 18:45:27.000000000 +0200
2504 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/namei.c       2011-12-05 19:33:02.000000000 +0100
2505 @@ -32,6 +32,7 @@
2506  
2507  #include <linux/pagemap.h>
2508  #include <linux/quotaops.h>
2509 +#include <linux/vs_tag.h>
2510  #include "ext2.h"
2511  #include "xattr.h"
2512  #include "acl.h"
2513 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2514                                         (unsigned long) ino);
2515                         return ERR_PTR(-EIO);
2516                 }
2517 +               dx_propagate_tag(nd, inode);
2518         }
2519         return d_splice_alias(inode, dentry);
2520  }
2521 @@ -408,6 +410,7 @@ const struct inode_operations ext2_dir_i
2522         .removexattr    = generic_removexattr,
2523  #endif
2524         .setattr        = ext2_setattr,
2525 +       .sync_flags     = ext2_sync_flags,
2526         .get_acl        = ext2_get_acl,
2527  };
2528  
2529 diff -NurpP --minimal linux-3.2.5/fs/ext2/super.c linux-3.2.5-vs2.3.2.6/fs/ext2/super.c
2530 --- linux-3.2.5/fs/ext2/super.c 2012-01-09 16:14:54.000000000 +0100
2531 +++ linux-3.2.5-vs2.3.2.6/fs/ext2/super.c       2011-12-05 19:33:02.000000000 +0100
2532 @@ -394,7 +394,8 @@ enum {
2533         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2534         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2535         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2536 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2537 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2538 +       Opt_tag, Opt_notag, Opt_tagid
2539  };
2540  
2541  static const match_table_t tokens = {
2542 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
2543         {Opt_acl, "acl"},
2544         {Opt_noacl, "noacl"},
2545         {Opt_xip, "xip"},
2546 +       {Opt_tag, "tag"},
2547 +       {Opt_notag, "notag"},
2548 +       {Opt_tagid, "tagid=%u"},
2549         {Opt_grpquota, "grpquota"},
2550         {Opt_ignore, "noquota"},
2551         {Opt_quota, "quota"},
2552 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
2553                 case Opt_nouid32:
2554                         set_opt (sbi->s_mount_opt, NO_UID32);
2555                         break;
2556 +#ifndef CONFIG_TAGGING_NONE
2557 +               case Opt_tag:
2558 +                       set_opt (sbi->s_mount_opt, TAGGED);
2559 +                       break;
2560 +               case Opt_notag:
2561 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2562 +                       break;
2563 +#endif
2564 +#ifdef CONFIG_PROPAGATE
2565 +               case Opt_tagid:
2566 +                       /* use args[0] */
2567 +                       set_opt (sbi->s_mount_opt, TAGGED);
2568 +                       break;
2569 +#endif
2570                 case Opt_nocheck:
2571                         clear_opt (sbi->s_mount_opt, CHECK);
2572                         break;
2573 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
2574         if (!parse_options((char *) data, sb))
2575                 goto failed_mount;
2576  
2577 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2578 +               sb->s_flags |= MS_TAGGED;
2579         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2580                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2581                  MS_POSIXACL : 0);
2582 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
2583                 goto restore_opts;
2584         }
2585  
2586 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2587 +               !(sb->s_flags & MS_TAGGED)) {
2588 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2589 +                      sb->s_id);
2590 +               err = -EINVAL;
2591 +               goto restore_opts;
2592 +       }
2593 +
2594         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2595                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2596  
2597 diff -NurpP --minimal linux-3.2.5/fs/ext3/file.c linux-3.2.5-vs2.3.2.6/fs/ext3/file.c
2598 --- linux-3.2.5/fs/ext3/file.c  2011-10-24 18:45:27.000000000 +0200
2599 +++ linux-3.2.5-vs2.3.2.6/fs/ext3/file.c        2011-12-05 19:33:02.000000000 +0100
2600 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
2601  #endif
2602         .get_acl        = ext3_get_acl,
2603         .fiemap         = ext3_fiemap,
2604 +       .sync_flags     = ext3_sync_flags,
2605  };
2606  
2607 diff -NurpP --minimal linux-3.2.5/fs/ext3/ialloc.c linux-3.2.5-vs2.3.2.6/fs/ext3/ialloc.c
2608 --- linux-3.2.5/fs/ext3/ialloc.c        2012-01-09 16:14:54.000000000 +0100
2609 +++ linux-3.2.5-vs2.3.2.6/fs/ext3/ialloc.c      2011-12-05 19:33:02.000000000 +0100
2610 @@ -23,6 +23,7 @@
2611  #include <linux/buffer_head.h>
2612  #include <linux/random.h>
2613  #include <linux/bitops.h>
2614 +#include <linux/vs_tag.h>
2615  #include <trace/events/ext3.h>
2616  
2617  #include <asm/byteorder.h>
2618 @@ -496,6 +497,7 @@ got:
2619                 inode->i_mode = mode;
2620                 inode->i_uid = current_fsuid();
2621                 inode->i_gid = dir->i_gid;
2622 +               inode->i_tag = dx_current_fstag(sb);
2623         } else
2624                 inode_init_owner(inode, dir, mode);
2625  
2626 diff -NurpP --minimal linux-3.2.5/fs/ext3/inode.c linux-3.2.5-vs2.3.2.6/fs/ext3/inode.c
2627 --- linux-3.2.5/fs/ext3/inode.c 2012-02-07 01:57:54.000000000 +0100
2628 +++ linux-3.2.5-vs2.3.2.6/fs/ext3/inode.c       2012-01-18 02:58:07.000000000 +0100
2629 @@ -38,6 +38,7 @@
2630  #include <linux/bio.h>
2631  #include <linux/fiemap.h>
2632  #include <linux/namei.h>
2633 +#include <linux/vs_tag.h>
2634  #include <trace/events/ext3.h>
2635  #include "xattr.h"
2636  #include "acl.h"
2637 @@ -2852,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2638  {
2639         unsigned int flags = EXT3_I(inode)->i_flags;
2640  
2641 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2642 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2643 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2644 +
2645 +       if (flags & EXT3_IMMUTABLE_FL)
2646 +               inode->i_flags |= S_IMMUTABLE;
2647 +       if (flags & EXT3_IXUNLINK_FL)
2648 +               inode->i_flags |= S_IXUNLINK;
2649 +
2650         if (flags & EXT3_SYNC_FL)
2651                 inode->i_flags |= S_SYNC;
2652         if (flags & EXT3_APPEND_FL)
2653                 inode->i_flags |= S_APPEND;
2654 -       if (flags & EXT3_IMMUTABLE_FL)
2655 -               inode->i_flags |= S_IMMUTABLE;
2656         if (flags & EXT3_NOATIME_FL)
2657                 inode->i_flags |= S_NOATIME;
2658         if (flags & EXT3_DIRSYNC_FL)
2659                 inode->i_flags |= S_DIRSYNC;
2660 +
2661 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2662 +
2663 +       if (flags & EXT3_BARRIER_FL)
2664 +               inode->i_vflags |= V_BARRIER;
2665 +       if (flags & EXT3_COW_FL)
2666 +               inode->i_vflags |= V_COW;
2667  }
2668  
2669  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2670  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2671  {
2672         unsigned int flags = ei->vfs_inode.i_flags;
2673 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2674 +
2675 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2676 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2677 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2678 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2679 +
2680 +       if (flags & S_IMMUTABLE)
2681 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2682 +       if (flags & S_IXUNLINK)
2683 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2684  
2685 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2686 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2687         if (flags & S_SYNC)
2688                 ei->i_flags |= EXT3_SYNC_FL;
2689         if (flags & S_APPEND)
2690                 ei->i_flags |= EXT3_APPEND_FL;
2691 -       if (flags & S_IMMUTABLE)
2692 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2693         if (flags & S_NOATIME)
2694                 ei->i_flags |= EXT3_NOATIME_FL;
2695         if (flags & S_DIRSYNC)
2696                 ei->i_flags |= EXT3_DIRSYNC_FL;
2697 +
2698 +       if (vflags & V_BARRIER)
2699 +               ei->i_flags |= EXT3_BARRIER_FL;
2700 +       if (vflags & V_COW)
2701 +               ei->i_flags |= EXT3_COW_FL;
2702  }
2703  
2704  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2705 @@ -2895,6 +2920,8 @@ struct inode *ext3_iget(struct super_blo
2706         transaction_t *transaction;
2707         long ret;
2708         int block;
2709 +       uid_t uid;
2710 +       gid_t gid;
2711  
2712         inode = iget_locked(sb, ino);
2713         if (!inode)
2714 @@ -2911,12 +2938,16 @@ struct inode *ext3_iget(struct super_blo
2715         bh = iloc.bh;
2716         raw_inode = ext3_raw_inode(&iloc);
2717         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2718 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2719 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2720 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2721 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2722         if(!(test_opt (inode->i_sb, NO_UID32))) {
2723 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2724 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2725 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2726 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2727         }
2728 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2729 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2730 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2731 +               le16_to_cpu(raw_inode->i_raw_tag));
2732         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2733         inode->i_size = le32_to_cpu(raw_inode->i_size);
2734         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2735 @@ -3071,6 +3102,8 @@ static int ext3_do_update_inode(handle_t
2736         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2737         struct ext3_inode_info *ei = EXT3_I(inode);
2738         struct buffer_head *bh = iloc->bh;
2739 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2740 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2741         int err = 0, rc, block;
2742  
2743  again:
2744 @@ -3085,29 +3118,32 @@ again:
2745         ext3_get_inode_flags(ei);
2746         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2747         if(!(test_opt(inode->i_sb, NO_UID32))) {
2748 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2749 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2750 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2751 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2752  /*
2753   * Fix up interoperability with old kernels. Otherwise, old inodes get
2754   * re-used with the upper 16 bits of the uid/gid intact
2755   */
2756                 if(!ei->i_dtime) {
2757                         raw_inode->i_uid_high =
2758 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2759 +                               cpu_to_le16(high_16_bits(uid));
2760                         raw_inode->i_gid_high =
2761 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2762 +                               cpu_to_le16(high_16_bits(gid));
2763                 } else {
2764                         raw_inode->i_uid_high = 0;
2765                         raw_inode->i_gid_high = 0;
2766                 }
2767         } else {
2768                 raw_inode->i_uid_low =
2769 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2770 +                       cpu_to_le16(fs_high2lowuid(uid));
2771                 raw_inode->i_gid_low =
2772 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2773 +                       cpu_to_le16(fs_high2lowgid(gid));
2774                 raw_inode->i_uid_high = 0;
2775                 raw_inode->i_gid_high = 0;
2776         }
2777 +#ifdef CONFIG_TAGGING_INTERN
2778 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2779 +#endif
2780         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2781         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2782         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2783 @@ -3267,7 +3303,8 @@ int ext3_setattr(struct dentry *dentry, 
2784         if (is_quota_modification(inode, attr))
2785                 dquot_initialize(inode);
2786         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2787 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2788 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2789 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2790                 handle_t *handle;
2791  
2792                 /* (user+group)*(old+new) structure, inode write (sb,
2793 @@ -3289,6 +3326,8 @@ int ext3_setattr(struct dentry *dentry, 
2794                         inode->i_uid = attr->ia_uid;
2795                 if (attr->ia_valid & ATTR_GID)
2796                         inode->i_gid = attr->ia_gid;
2797 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2798 +                       inode->i_tag = attr->ia_tag;
2799                 error = ext3_mark_inode_dirty(handle, inode);
2800                 ext3_journal_stop(handle);
2801         }
2802 diff -NurpP --minimal linux-3.2.5/fs/ext3/ioctl.c linux-3.2.5-vs2.3.2.6/fs/ext3/ioctl.c
2803 --- linux-3.2.5/fs/ext3/ioctl.c 2012-01-09 16:14:54.000000000 +0100
2804 +++ linux-3.2.5-vs2.3.2.6/fs/ext3/ioctl.c       2011-12-05 19:33:02.000000000 +0100
2805 @@ -8,6 +8,7 @@
2806   */
2807  
2808  #include <linux/fs.h>
2809 +#include <linux/mount.h>
2810  #include <linux/jbd.h>
2811  #include <linux/capability.h>
2812  #include <linux/ext3_fs.h>
2813 @@ -17,6 +18,34 @@
2814  #include <linux/compat.h>
2815  #include <asm/uaccess.h>
2816  
2817 +
2818 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2819 +{
2820 +       handle_t *handle = NULL;
2821 +       struct ext3_iloc iloc;
2822 +       int err;
2823 +
2824 +       handle = ext3_journal_start(inode, 1);
2825 +       if (IS_ERR(handle))
2826 +               return PTR_ERR(handle);
2827 +
2828 +       if (IS_SYNC(inode))
2829 +               handle->h_sync = 1;
2830 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2831 +       if (err)
2832 +               goto flags_err;
2833 +
2834 +       inode->i_flags = flags;
2835 +       inode->i_vflags = vflags;
2836 +       ext3_get_inode_flags(EXT3_I(inode));
2837 +       inode->i_ctime = CURRENT_TIME_SEC;
2838 +
2839 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2840 +flags_err:
2841 +       ext3_journal_stop(handle);
2842 +       return err;
2843 +}
2844 +
2845  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2846  {
2847         struct inode *inode = filp->f_dentry->d_inode;
2848 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
2849  
2850                 flags = ext3_mask_flags(inode->i_mode, flags);
2851  
2852 +               if (IS_BARRIER(inode)) {
2853 +                       vxwprintk_task(1, "messing with the barrier.");
2854 +                       return -EACCES;
2855 +               }
2856 +
2857                 mutex_lock(&inode->i_mutex);
2858  
2859                 /* Is it quota file? Do not allow user to mess with it */
2860 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
2861                  *
2862                  * This test looks nicer. Thanks to Pauline Middelink
2863                  */
2864 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2865 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2866 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2867 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2868                         if (!capable(CAP_LINUX_IMMUTABLE))
2869                                 goto flags_out;
2870                 }
2871 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
2872                 if (err)
2873                         goto flags_err;
2874  
2875 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2876 +               flags &= EXT3_FL_USER_MODIFIABLE;
2877                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2878                 ei->i_flags = flags;
2879  
2880 diff -NurpP --minimal linux-3.2.5/fs/ext3/namei.c linux-3.2.5-vs2.3.2.6/fs/ext3/namei.c
2881 --- linux-3.2.5/fs/ext3/namei.c 2012-01-09 16:14:54.000000000 +0100
2882 +++ linux-3.2.5-vs2.3.2.6/fs/ext3/namei.c       2011-12-05 19:33:02.000000000 +0100
2883 @@ -36,6 +36,7 @@
2884  #include <linux/quotaops.h>
2885  #include <linux/buffer_head.h>
2886  #include <linux/bio.h>
2887 +#include <linux/vs_tag.h>
2888  #include <trace/events/ext3.h>
2889  
2890  #include "namei.h"
2891 @@ -925,6 +926,7 @@ restart:
2892                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
2893                                                     1, &bh);
2894                         }
2895 +               dx_propagate_tag(nd, inode);
2896                 }
2897                 if ((bh = bh_use[ra_ptr++]) == NULL)
2898                         goto next;
2899 @@ -2535,6 +2537,7 @@ const struct inode_operations ext3_dir_i
2900         .listxattr      = ext3_listxattr,
2901         .removexattr    = generic_removexattr,
2902  #endif
2903 +       .sync_flags     = ext3_sync_flags,
2904         .get_acl        = ext3_get_acl,
2905  };
2906  
2907 diff -NurpP --minimal linux-3.2.5/fs/ext3/super.c linux-3.2.5-vs2.3.2.6/fs/ext3/super.c
2908 --- linux-3.2.5/fs/ext3/super.c 2012-01-09 16:14:54.000000000 +0100
2909 +++ linux-3.2.5-vs2.3.2.6/fs/ext3/super.c       2011-12-05 19:33:02.000000000 +0100
2910 @@ -831,7 +831,8 @@ enum {
2911         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2912         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2913         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2914 -       Opt_resize, Opt_usrquota, Opt_grpquota
2915 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2916 +       Opt_tag, Opt_notag, Opt_tagid
2917  };
2918  
2919  static const match_table_t tokens = {
2920 @@ -888,6 +889,9 @@ static const match_table_t tokens = {
2921         {Opt_barrier, "barrier"},
2922         {Opt_nobarrier, "nobarrier"},
2923         {Opt_resize, "resize"},
2924 +       {Opt_tag, "tag"},
2925 +       {Opt_notag, "notag"},
2926 +       {Opt_tagid, "tagid=%u"},
2927         {Opt_err, NULL},
2928  };
2929  
2930 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2931                 case Opt_nouid32:
2932                         set_opt (sbi->s_mount_opt, NO_UID32);
2933                         break;
2934 +#ifndef CONFIG_TAGGING_NONE
2935 +               case Opt_tag:
2936 +                       set_opt (sbi->s_mount_opt, TAGGED);
2937 +                       break;
2938 +               case Opt_notag:
2939 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2940 +                       break;
2941 +#endif
2942 +#ifdef CONFIG_PROPAGATE
2943 +               case Opt_tagid:
2944 +                       /* use args[0] */
2945 +                       set_opt (sbi->s_mount_opt, TAGGED);
2946 +                       break;
2947 +#endif
2948                 case Opt_nocheck:
2949                         clear_opt (sbi->s_mount_opt, CHECK);
2950                         break;
2951 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
2952                             NULL, 0))
2953                 goto failed_mount;
2954  
2955 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2956 +               sb->s_flags |= MS_TAGGED;
2957 +
2958         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2959                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2960  
2961 @@ -2619,6 +2640,14 @@ static int ext3_remount (struct super_bl
2962         if (test_opt(sb, ABORT))
2963                 ext3_abort(sb, __func__, "Abort forced by user");
2964  
2965 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2966 +               !(sb->s_flags & MS_TAGGED)) {
2967 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2968 +                       sb->s_id);
2969 +               err = -EINVAL;
2970 +               goto restore_opts;
2971 +       }
2972 +
2973         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2974                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2975  
2976 diff -NurpP --minimal linux-3.2.5/fs/ext4/ext4.h linux-3.2.5-vs2.3.2.6/fs/ext4/ext4.h
2977 --- linux-3.2.5/fs/ext4/ext4.h  2012-01-09 16:14:54.000000000 +0100
2978 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/ext4.h        2011-12-05 19:33:02.000000000 +0100
2979 @@ -371,8 +371,12 @@ struct flex_groups {
2980  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2981  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2982  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2983 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2984  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2985  
2986 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2987 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2988 +
2989  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2990  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
2991  
2992 @@ -632,7 +636,8 @@ struct ext4_inode {
2993                         __le16  l_i_file_acl_high;
2994                         __le16  l_i_uid_high;   /* these 2 fields */
2995                         __le16  l_i_gid_high;   /* were reserved2[0] */
2996 -                       __u32   l_i_reserved2;
2997 +                       __le16  l_i_tag;        /* Context Tag */
2998 +                       __u16   l_i_reserved2;
2999                 } linux2;
3000                 struct {
3001                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3002 @@ -750,6 +755,7 @@ do {                                                                               \
3003  #define i_gid_low      i_gid
3004  #define i_uid_high     osd2.linux2.l_i_uid_high
3005  #define i_gid_high     osd2.linux2.l_i_gid_high
3006 +#define i_raw_tag      osd2.linux2.l_i_tag
3007  #define i_reserved2    osd2.linux2.l_i_reserved2
3008  
3009  #elif defined(__GNU__)
3010 @@ -926,6 +932,7 @@ struct ext4_inode_info {
3011  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3012  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3013  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3014 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3015  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3016  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3017  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3018 @@ -2270,6 +2277,7 @@ extern int ext4_map_blocks(handle_t *han
3019                            struct ext4_map_blocks *map, int flags);
3020  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3021                         __u64 start, __u64 len);
3022 +extern int ext4_sync_flags(struct inode *, int, int);
3023  /* move_extent.c */
3024  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3025                              __u64 start_orig, __u64 start_donor,
3026 diff -NurpP --minimal linux-3.2.5/fs/ext4/file.c linux-3.2.5-vs2.3.2.6/fs/ext4/file.c
3027 --- linux-3.2.5/fs/ext4/file.c  2012-01-09 16:14:54.000000000 +0100
3028 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/file.c        2011-12-05 19:33:02.000000000 +0100
3029 @@ -258,5 +258,6 @@ const struct inode_operations ext4_file_
3030  #endif
3031         .get_acl        = ext4_get_acl,
3032         .fiemap         = ext4_fiemap,
3033 +       .sync_flags     = ext4_sync_flags,
3034  };
3035  
3036 diff -NurpP --minimal linux-3.2.5/fs/ext4/ialloc.c linux-3.2.5-vs2.3.2.6/fs/ext4/ialloc.c
3037 --- linux-3.2.5/fs/ext4/ialloc.c        2012-01-09 16:14:54.000000000 +0100
3038 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/ialloc.c      2011-12-05 19:33:02.000000000 +0100
3039 @@ -22,6 +22,7 @@
3040  #include <linux/random.h>
3041  #include <linux/bitops.h>
3042  #include <linux/blkdev.h>
3043 +#include <linux/vs_tag.h>
3044  #include <asm/byteorder.h>
3045  
3046  #include "ext4.h"
3047 @@ -860,6 +861,7 @@ got:
3048                 inode->i_mode = mode;
3049                 inode->i_uid = current_fsuid();
3050                 inode->i_gid = dir->i_gid;
3051 +               inode->i_tag = dx_current_fstag(sb);
3052         } else
3053                 inode_init_owner(inode, dir, mode);
3054  
3055 diff -NurpP --minimal linux-3.2.5/fs/ext4/inode.c linux-3.2.5-vs2.3.2.6/fs/ext4/inode.c
3056 --- linux-3.2.5/fs/ext4/inode.c 2012-01-09 16:14:54.000000000 +0100
3057 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/inode.c       2012-01-09 16:19:31.000000000 +0100
3058 @@ -38,6 +38,7 @@
3059  #include <linux/printk.h>
3060  #include <linux/slab.h>
3061  #include <linux/ratelimit.h>
3062 +#include <linux/vs_tag.h>
3063  
3064  #include "ext4_jbd2.h"
3065  #include "xattr.h"
3066 @@ -3667,41 +3668,64 @@ void ext4_set_inode_flags(struct inode *
3067  {
3068         unsigned int flags = EXT4_I(inode)->i_flags;
3069  
3070 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3071 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3072 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3073 +
3074 +       if (flags & EXT4_IMMUTABLE_FL)
3075 +               inode->i_flags |= S_IMMUTABLE;
3076 +       if (flags & EXT4_IXUNLINK_FL)
3077 +               inode->i_flags |= S_IXUNLINK;
3078 +
3079         if (flags & EXT4_SYNC_FL)
3080                 inode->i_flags |= S_SYNC;
3081         if (flags & EXT4_APPEND_FL)
3082                 inode->i_flags |= S_APPEND;
3083 -       if (flags & EXT4_IMMUTABLE_FL)
3084 -               inode->i_flags |= S_IMMUTABLE;
3085         if (flags & EXT4_NOATIME_FL)
3086                 inode->i_flags |= S_NOATIME;
3087         if (flags & EXT4_DIRSYNC_FL)
3088                 inode->i_flags |= S_DIRSYNC;
3089 +
3090 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3091 +
3092 +       if (flags & EXT4_BARRIER_FL)
3093 +               inode->i_vflags |= V_BARRIER;
3094 +       if (flags & EXT4_COW_FL)
3095 +               inode->i_vflags |= V_COW;
3096  }
3097  
3098  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3099  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3100  {
3101 -       unsigned int vfs_fl;
3102 +       unsigned int vfs_fl, vfs_vf;
3103         unsigned long old_fl, new_fl;
3104  
3105         do {
3106                 vfs_fl = ei->vfs_inode.i_flags;
3107 +               vfs_vf = ei->vfs_inode.i_vflags;
3108                 old_fl = ei->i_flags;
3109                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3110                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3111 -                               EXT4_DIRSYNC_FL);
3112 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3113 +                               EXT4_COW_FL);
3114 +
3115 +               if (vfs_fl & S_IMMUTABLE)
3116 +                       new_fl |= EXT4_IMMUTABLE_FL;
3117 +               if (vfs_fl & S_IXUNLINK)
3118 +                       new_fl |= EXT4_IXUNLINK_FL;
3119 +
3120                 if (vfs_fl & S_SYNC)
3121                         new_fl |= EXT4_SYNC_FL;
3122                 if (vfs_fl & S_APPEND)
3123                         new_fl |= EXT4_APPEND_FL;
3124 -               if (vfs_fl & S_IMMUTABLE)
3125 -                       new_fl |= EXT4_IMMUTABLE_FL;
3126                 if (vfs_fl & S_NOATIME)
3127                         new_fl |= EXT4_NOATIME_FL;
3128                 if (vfs_fl & S_DIRSYNC)
3129                         new_fl |= EXT4_DIRSYNC_FL;
3130 +
3131 +               if (vfs_vf & V_BARRIER)
3132 +                       new_fl |= EXT4_BARRIER_FL;
3133 +               if (vfs_vf & V_COW)
3134 +                       new_fl |= EXT4_COW_FL;
3135         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3136  }
3137  
3138 @@ -3737,6 +3761,8 @@ struct inode *ext4_iget(struct super_blo
3139         journal_t *journal = EXT4_SB(sb)->s_journal;
3140         long ret;
3141         int block;
3142 +       uid_t uid;
3143 +       gid_t gid;
3144  
3145         inode = iget_locked(sb, ino);
3146         if (!inode)
3147 @@ -3752,12 +3778,16 @@ struct inode *ext4_iget(struct super_blo
3148                 goto bad_inode;
3149         raw_inode = ext4_raw_inode(&iloc);
3150         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3151 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3152 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3153 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3154 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3155         if (!(test_opt(inode->i_sb, NO_UID32))) {
3156 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3157 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3158 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3159 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3160         }
3161 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3162 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3163 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3164 +               le16_to_cpu(raw_inode->i_raw_tag));
3165         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3166  
3167         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3168 @@ -3976,6 +4006,8 @@ static int ext4_do_update_inode(handle_t
3169         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3170         struct ext4_inode_info *ei = EXT4_I(inode);
3171         struct buffer_head *bh = iloc->bh;
3172 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3173 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3174         int err = 0, rc, block;
3175  
3176         /* For fields not not tracking in the in-memory inode,
3177 @@ -3986,29 +4018,32 @@ static int ext4_do_update_inode(handle_t
3178         ext4_get_inode_flags(ei);
3179         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3180         if (!(test_opt(inode->i_sb, NO_UID32))) {
3181 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3182 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3183 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3184 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3185  /*
3186   * Fix up interoperability with old kernels. Otherwise, old inodes get
3187   * re-used with the upper 16 bits of the uid/gid intact
3188   */
3189                 if (!ei->i_dtime) {
3190                         raw_inode->i_uid_high =
3191 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3192 +                               cpu_to_le16(high_16_bits(uid));
3193                         raw_inode->i_gid_high =
3194 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3195 +                               cpu_to_le16(high_16_bits(gid));
3196                 } else {
3197                         raw_inode->i_uid_high = 0;
3198                         raw_inode->i_gid_high = 0;
3199                 }
3200         } else {
3201                 raw_inode->i_uid_low =
3202 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3203 +                       cpu_to_le16(fs_high2lowuid(uid));
3204                 raw_inode->i_gid_low =
3205 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3206 +                       cpu_to_le16(fs_high2lowgid(gid));
3207                 raw_inode->i_uid_high = 0;
3208                 raw_inode->i_gid_high = 0;
3209         }
3210 +#ifdef CONFIG_TAGGING_INTERN
3211 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3212 +#endif
3213         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3214  
3215         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3216 @@ -4194,7 +4229,8 @@ int ext4_setattr(struct dentry *dentry, 
3217         if (is_quota_modification(inode, attr))
3218                 dquot_initialize(inode);
3219         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3220 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3221 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3222 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3223                 handle_t *handle;
3224  
3225                 /* (user+group)*(old+new) structure, inode write (sb,
3226 @@ -4216,6 +4252,8 @@ int ext4_setattr(struct dentry *dentry, 
3227                         inode->i_uid = attr->ia_uid;
3228                 if (attr->ia_valid & ATTR_GID)
3229                         inode->i_gid = attr->ia_gid;
3230 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3231 +                       inode->i_tag = attr->ia_tag;
3232                 error = ext4_mark_inode_dirty(handle, inode);
3233                 ext4_journal_stop(handle);
3234         }
3235 diff -NurpP --minimal linux-3.2.5/fs/ext4/ioctl.c linux-3.2.5-vs2.3.2.6/fs/ext4/ioctl.c
3236 --- linux-3.2.5/fs/ext4/ioctl.c 2012-02-07 01:57:54.000000000 +0100
3237 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/ioctl.c       2012-01-26 08:52:10.000000000 +0100
3238 @@ -14,10 +14,39 @@
3239  #include <linux/compat.h>
3240  #include <linux/mount.h>
3241  #include <linux/file.h>
3242 +#include <linux/vs_tag.h>
3243  #include <asm/uaccess.h>
3244  #include "ext4_jbd2.h"
3245  #include "ext4.h"
3246  
3247 +
3248 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3249 +{
3250 +       handle_t *handle = NULL;
3251 +       struct ext4_iloc iloc;
3252 +       int err;
3253 +
3254 +       handle = ext4_journal_start(inode, 1);
3255 +       if (IS_ERR(handle))
3256 +               return PTR_ERR(handle);
3257 +
3258 +       if (IS_SYNC(inode))
3259 +               ext4_handle_sync(handle);
3260 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3261 +       if (err)
3262 +               goto flags_err;
3263 +
3264 +       inode->i_flags = flags;
3265 +       inode->i_vflags = vflags;
3266 +       ext4_get_inode_flags(EXT4_I(inode));
3267 +       inode->i_ctime = ext4_current_time(inode);
3268 +
3269 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3270 +flags_err:
3271 +       ext4_journal_stop(handle);
3272 +       return err;
3273 +}
3274 +
3275  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3276  {
3277         struct inode *inode = filp->f_dentry->d_inode;
3278 @@ -51,6 +80,11 @@ long ext4_ioctl(struct file *filp, unsig
3279  
3280                 flags = ext4_mask_flags(inode->i_mode, flags);
3281  
3282 +               if (IS_BARRIER(inode)) {
3283 +                       vxwprintk_task(1, "messing with the barrier.");
3284 +                       return -EACCES;
3285 +               }
3286 +
3287                 err = -EPERM;
3288                 mutex_lock(&inode->i_mutex);
3289                 /* Is it quota file? Do not allow user to mess with it */
3290 @@ -68,7 +102,9 @@ long ext4_ioctl(struct file *filp, unsig
3291                  *
3292                  * This test looks nicer. Thanks to Pauline Middelink
3293                  */
3294 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3295 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3296 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3297 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3298                         if (!capable(CAP_LINUX_IMMUTABLE))
3299                                 goto flags_out;
3300                 }
3301 diff -NurpP --minimal linux-3.2.5/fs/ext4/namei.c linux-3.2.5-vs2.3.2.6/fs/ext4/namei.c
3302 --- linux-3.2.5/fs/ext4/namei.c 2012-01-09 16:14:54.000000000 +0100
3303 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/namei.c       2011-12-05 19:33:02.000000000 +0100
3304 @@ -34,6 +34,7 @@
3305  #include <linux/quotaops.h>
3306  #include <linux/buffer_head.h>
3307  #include <linux/bio.h>
3308 +#include <linux/vs_tag.h>
3309  #include "ext4.h"
3310  #include "ext4_jbd2.h"
3311  
3312 @@ -925,6 +926,7 @@ restart:
3313                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3314                                                     1, &bh);
3315                         }
3316 +               dx_propagate_tag(nd, inode);
3317                 }
3318                 if ((bh = bh_use[ra_ptr++]) == NULL)
3319                         goto next;
3320 @@ -2587,6 +2589,7 @@ const struct inode_operations ext4_dir_i
3321  #endif
3322         .get_acl        = ext4_get_acl,
3323         .fiemap         = ext4_fiemap,
3324 +       .sync_flags     = ext4_sync_flags,
3325  };
3326  
3327  const struct inode_operations ext4_special_inode_operations = {
3328 diff -NurpP --minimal linux-3.2.5/fs/ext4/super.c linux-3.2.5-vs2.3.2.6/fs/ext4/super.c
3329 --- linux-3.2.5/fs/ext4/super.c 2012-02-07 01:57:54.000000000 +0100
3330 +++ linux-3.2.5-vs2.3.2.6/fs/ext4/super.c       2012-01-26 08:52:10.000000000 +0100
3331 @@ -1334,6 +1334,7 @@ enum {
3332         Opt_inode_readahead_blks, Opt_journal_ioprio,
3333         Opt_dioread_nolock, Opt_dioread_lock,
3334         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3335 +       Opt_tag, Opt_notag, Opt_tagid
3336  };
3337  
3338  static const match_table_t tokens = {
3339 @@ -1409,6 +1410,9 @@ static const match_table_t tokens = {
3340         {Opt_init_itable, "init_itable=%u"},
3341         {Opt_init_itable, "init_itable"},
3342         {Opt_noinit_itable, "noinit_itable"},
3343 +       {Opt_tag, "tag"},
3344 +       {Opt_notag, "notag"},
3345 +       {Opt_tagid, "tagid=%u"},
3346         {Opt_err, NULL},
3347  };
3348  
3349 @@ -1577,6 +1581,20 @@ static int parse_options(char *options, 
3350                 case Opt_nouid32:
3351                         set_opt(sb, NO_UID32);
3352                         break;
3353 +#ifndef CONFIG_TAGGING_NONE
3354 +               case Opt_tag:
3355 +                       set_opt(sb, TAGGED);
3356 +                       break;
3357 +               case Opt_notag:
3358 +                       clear_opt(sb, TAGGED);
3359 +                       break;
3360 +#endif
3361 +#ifdef CONFIG_PROPAGATE
3362 +               case Opt_tagid:
3363 +                       /* use args[0] */
3364 +                       set_opt(sb, TAGGED);
3365 +                       break;
3366 +#endif
3367                 case Opt_debug:
3368                         set_opt(sb, DEBUG);
3369                         break;
3370 @@ -3278,6 +3296,9 @@ static int ext4_fill_super(struct super_
3371                 }
3372         }
3373  
3374 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3375 +               sb->s_flags |= MS_TAGGED;
3376 +
3377         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3378                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3379  
3380 @@ -4427,6 +4448,14 @@ static int ext4_remount(struct super_blo
3381         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3382                 ext4_abort(sb, "Abort forced by user");
3383  
3384 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3385 +               !(sb->s_flags & MS_TAGGED)) {
3386 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3387 +                       sb->s_id);
3388 +               err = -EINVAL;
3389 +               goto restore_opts;
3390 +       }
3391 +
3392         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3393                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3394  
3395 diff -NurpP --minimal linux-3.2.5/fs/fcntl.c linux-3.2.5-vs2.3.2.6/fs/fcntl.c
3396 --- linux-3.2.5/fs/fcntl.c      2011-05-22 16:17:52.000000000 +0200
3397 +++ linux-3.2.5-vs2.3.2.6/fs/fcntl.c    2011-12-05 19:33:02.000000000 +0100
3398 @@ -20,6 +20,7 @@
3399  #include <linux/signal.h>
3400  #include <linux/rcupdate.h>
3401  #include <linux/pid_namespace.h>
3402 +#include <linux/vs_limit.h>
3403  
3404  #include <asm/poll.h>
3405  #include <asm/siginfo.h>
3406 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3407  
3408         if (tofree)
3409                 filp_close(tofree, files);
3410 +       else
3411 +               vx_openfd_inc(newfd);   /* fd was unused */
3412  
3413         return newfd;
3414  
3415 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3416         filp = fget_raw(fd);
3417         if (!filp)
3418                 goto out;
3419 +       if (!vx_files_avail(1))
3420 +               goto out;
3421  
3422         if (unlikely(filp->f_mode & FMODE_PATH)) {
3423                 if (!check_fcntl_cmd(cmd)) {
3424 diff -NurpP --minimal linux-3.2.5/fs/file.c linux-3.2.5-vs2.3.2.6/fs/file.c
3425 --- linux-3.2.5/fs/file.c       2011-05-22 16:17:52.000000000 +0200
3426 +++ linux-3.2.5-vs2.3.2.6/fs/file.c     2011-12-05 19:33:02.000000000 +0100
3427 @@ -21,6 +21,7 @@
3428  #include <linux/spinlock.h>
3429  #include <linux/rcupdate.h>
3430  #include <linux/workqueue.h>
3431 +#include <linux/vs_limit.h>
3432  
3433  struct fdtable_defer {
3434         spinlock_t lock;
3435 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
3436                 struct file *f = *old_fds++;
3437                 if (f) {
3438                         get_file(f);
3439 +                       /* TODO: sum it first for check and performance */
3440 +                       vx_openfd_inc(open_files - i);
3441                 } else {
3442                         /*
3443                          * The fd may be claimed in the fd bitmap but not yet
3444 @@ -466,6 +469,7 @@ repeat:
3445         else
3446                 FD_CLR(fd, fdt->close_on_exec);
3447         error = fd;
3448 +       vx_openfd_inc(fd);
3449  #if 1
3450         /* Sanity check */
3451         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3452 diff -NurpP --minimal linux-3.2.5/fs/file_table.c linux-3.2.5-vs2.3.2.6/fs/file_table.c
3453 --- linux-3.2.5/fs/file_table.c 2011-10-24 18:45:27.000000000 +0200
3454 +++ linux-3.2.5-vs2.3.2.6/fs/file_table.c       2011-12-05 19:33:02.000000000 +0100
3455 @@ -24,6 +24,8 @@
3456  #include <linux/percpu_counter.h>
3457  #include <linux/percpu.h>
3458  #include <linux/ima.h>
3459 +#include <linux/vs_limit.h>
3460 +#include <linux/vs_context.h>
3461  
3462  #include <linux/atomic.h>
3463  
3464 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3465         spin_lock_init(&f->f_lock);
3466         eventpoll_init_file(f);
3467         /* f->f_version: 0 */
3468 +       f->f_xid = vx_current_xid();
3469 +       vx_files_inc(f);
3470         return f;
3471  
3472  over:
3473 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
3474         }
3475         fops_put(file->f_op);
3476         put_pid(file->f_owner.pid);
3477 +       vx_files_dec(file);
3478 +       file->f_xid = 0;
3479         file_sb_list_del(file);
3480         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3481                 i_readcount_dec(inode);
3482 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
3483  {
3484         if (atomic_long_dec_and_test(&file->f_count)) {
3485                 security_file_free(file);
3486 +               vx_files_dec(file);
3487 +               file->f_xid = 0;
3488                 file_sb_list_del(file);
3489                 file_free(file);
3490         }
3491 diff -NurpP --minimal linux-3.2.5/fs/fs_struct.c linux-3.2.5-vs2.3.2.6/fs/fs_struct.c
3492 --- linux-3.2.5/fs/fs_struct.c  2011-03-15 18:07:31.000000000 +0100
3493 +++ linux-3.2.5-vs2.3.2.6/fs/fs_struct.c        2011-12-05 19:33:02.000000000 +0100
3494 @@ -4,6 +4,7 @@
3495  #include <linux/path.h>
3496  #include <linux/slab.h>
3497  #include <linux/fs_struct.h>
3498 +#include <linux/vserver/global.h>
3499  #include "internal.h"
3500  
3501  static inline void path_get_longterm(struct path *path)
3502 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
3503  {
3504         path_put_longterm(&fs->root);
3505         path_put_longterm(&fs->pwd);
3506 +       atomic_dec(&vs_global_fs);
3507         kmem_cache_free(fs_cachep, fs);
3508  }
3509  
3510 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
3511                 fs->pwd = old->pwd;
3512                 path_get_longterm(&fs->pwd);
3513                 spin_unlock(&old->lock);
3514 +               atomic_inc(&vs_global_fs);
3515         }
3516         return fs;
3517  }
3518 diff -NurpP --minimal linux-3.2.5/fs/gfs2/file.c linux-3.2.5-vs2.3.2.6/fs/gfs2/file.c
3519 --- linux-3.2.5/fs/gfs2/file.c  2012-01-09 16:14:54.000000000 +0100
3520 +++ linux-3.2.5-vs2.3.2.6/fs/gfs2/file.c        2011-12-05 19:33:02.000000000 +0100
3521 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3522         [7] = GFS2_DIF_NOATIME,
3523         [12] = GFS2_DIF_EXHASH,
3524         [14] = GFS2_DIF_INHERIT_JDATA,
3525 +       [27] = GFS2_DIF_IXUNLINK,
3526 +       [26] = GFS2_DIF_BARRIER,
3527 +       [29] = GFS2_DIF_COW,
3528  };
3529  
3530  static const u32 gfs2_to_fsflags[32] = {
3531 @@ -152,6 +155,9 @@ static const u32 gfs2_to_fsflags[32] = {
3532         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3533         [gfs2fl_ExHash] = FS_INDEX_FL,
3534         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3535 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3536 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3537 +       [gfs2fl_Cow] = FS_COW_FL,
3538  };
3539  
3540  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3541 @@ -182,12 +188,18 @@ void gfs2_set_inode_flags(struct inode *
3542  {
3543         struct gfs2_inode *ip = GFS2_I(inode);
3544         unsigned int flags = inode->i_flags;
3545 +       unsigned int vflags = inode->i_vflags;
3546 +
3547 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3548 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3549  
3550 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3551         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3552                 inode->i_flags |= S_NOSEC;
3553         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3554                 flags |= S_IMMUTABLE;
3555 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3556 +               flags |= S_IXUNLINK;
3557 +
3558         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3559                 flags |= S_APPEND;
3560         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3561 @@ -195,6 +207,43 @@ void gfs2_set_inode_flags(struct inode *
3562         if (ip->i_diskflags & GFS2_DIF_SYNC)
3563                 flags |= S_SYNC;
3564         inode->i_flags = flags;
3565 +
3566 +       vflags &= ~(V_BARRIER | V_COW);
3567 +
3568 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3569 +               vflags |= V_BARRIER;
3570 +       if (ip->i_diskflags & GFS2_DIF_COW)
3571 +               vflags |= V_COW;
3572 +       inode->i_vflags = vflags;
3573 +}
3574 +
3575 +void gfs2_get_inode_flags(struct inode *inode)
3576 +{
3577 +       struct gfs2_inode *ip = GFS2_I(inode);
3578 +       unsigned int flags = inode->i_flags;
3579 +       unsigned int vflags = inode->i_vflags;
3580 +
3581 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3582 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3583 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3584 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3585 +
3586 +       if (flags & S_IMMUTABLE)
3587 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3588 +       if (flags & S_IXUNLINK)
3589 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3590 +
3591 +       if (flags & S_APPEND)
3592 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3593 +       if (flags & S_NOATIME)
3594 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3595 +       if (flags & S_SYNC)
3596 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3597 +
3598 +       if (vflags & V_BARRIER)
3599 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3600 +       if (vflags & V_COW)
3601 +               ip->i_diskflags |= GFS2_DIF_COW;
3602  }
3603  
3604  /* Flags that can be set by user space */
3605 @@ -306,6 +355,37 @@ static int gfs2_set_flags(struct file *f
3606         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3607  }
3608  
3609 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3610 +{
3611 +       struct gfs2_inode *ip = GFS2_I(inode);
3612 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3613 +       struct buffer_head *bh;
3614 +       struct gfs2_holder gh;
3615 +       int error;
3616 +
3617 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3618 +       if (error)
3619 +               return error;
3620 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3621 +       if (error)
3622 +               goto out;
3623 +       error = gfs2_meta_inode_buffer(ip, &bh);
3624 +       if (error)
3625 +               goto out_trans_end;
3626 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3627 +       inode->i_flags = flags;
3628 +       inode->i_vflags = vflags;
3629 +       gfs2_get_inode_flags(inode);
3630 +       gfs2_dinode_out(ip, bh->b_data);
3631 +       brelse(bh);
3632 +       gfs2_set_aops(inode);
3633 +out_trans_end:
3634 +       gfs2_trans_end(sdp);
3635 +out:
3636 +       gfs2_glock_dq_uninit(&gh);
3637 +       return error;
3638 +}
3639 +
3640  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3641  {
3642         switch(cmd) {
3643 diff -NurpP --minimal linux-3.2.5/fs/gfs2/inode.h linux-3.2.5-vs2.3.2.6/fs/gfs2/inode.h
3644 --- linux-3.2.5/fs/gfs2/inode.h 2012-01-09 16:14:54.000000000 +0100
3645 +++ linux-3.2.5-vs2.3.2.6/fs/gfs2/inode.h       2011-12-05 19:33:02.000000000 +0100
3646 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3647  extern const struct file_operations gfs2_dir_fops_nolock;
3648  
3649  extern void gfs2_set_inode_flags(struct inode *inode);
3650 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3651   
3652  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3653  extern const struct file_operations gfs2_file_fops;
3654 diff -NurpP --minimal linux-3.2.5/fs/inode.c linux-3.2.5-vs2.3.2.6/fs/inode.c
3655 --- linux-3.2.5/fs/inode.c      2012-01-09 16:14:54.000000000 +0100
3656 +++ linux-3.2.5-vs2.3.2.6/fs/inode.c    2011-12-05 19:33:02.000000000 +0100
3657 @@ -26,6 +26,7 @@
3658  #include <linux/ima.h>
3659  #include <linux/cred.h>
3660  #include <linux/buffer_head.h> /* for inode_has_buffers */
3661 +#include <linux/vs_tag.h>
3662  #include "internal.h"
3663  
3664  /*
3665 @@ -137,6 +138,9 @@ int inode_init_always(struct super_block
3666         struct address_space *const mapping = &inode->i_data;
3667  
3668         inode->i_sb = sb;
3669 +
3670 +       /* essential because of inode slab reuse */
3671 +       inode->i_tag = 0;
3672         inode->i_blkbits = sb->s_blocksize_bits;
3673         inode->i_flags = 0;
3674         atomic_set(&inode->i_count, 1);
3675 @@ -158,6 +162,7 @@ int inode_init_always(struct super_block
3676         inode->i_bdev = NULL;
3677         inode->i_cdev = NULL;
3678         inode->i_rdev = 0;
3679 +       inode->i_mdev = 0;
3680         inode->dirtied_when = 0;
3681  
3682         if (security_inode_alloc(inode))
3683 @@ -399,6 +404,8 @@ void __insert_inode_hash(struct inode *i
3684  }
3685  EXPORT_SYMBOL(__insert_inode_hash);
3686  
3687 +EXPORT_SYMBOL_GPL(__iget);
3688 +
3689  /**
3690   *     __remove_inode_hash - remove an inode from the hash
3691   *     @inode: inode to unhash
3692 @@ -1626,9 +1633,11 @@ void init_special_inode(struct inode *in
3693         if (S_ISCHR(mode)) {
3694                 inode->i_fop = &def_chr_fops;
3695                 inode->i_rdev = rdev;
3696 +               inode->i_mdev = rdev;
3697         } else if (S_ISBLK(mode)) {
3698                 inode->i_fop = &def_blk_fops;
3699                 inode->i_rdev = rdev;
3700 +               inode->i_mdev = rdev;
3701         } else if (S_ISFIFO(mode))
3702                 inode->i_fop = &def_fifo_fops;
3703         else if (S_ISSOCK(mode))
3704 @@ -1657,6 +1666,7 @@ void inode_init_owner(struct inode *inod
3705         } else
3706                 inode->i_gid = current_fsgid();
3707         inode->i_mode = mode;
3708 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3709  }
3710  EXPORT_SYMBOL(inode_init_owner);
3711  
3712 diff -NurpP --minimal linux-3.2.5/fs/ioctl.c linux-3.2.5-vs2.3.2.6/fs/ioctl.c
3713 --- linux-3.2.5/fs/ioctl.c      2011-05-22 16:17:52.000000000 +0200
3714 +++ linux-3.2.5-vs2.3.2.6/fs/ioctl.c    2011-12-05 19:33:02.000000000 +0100
3715 @@ -15,6 +15,9 @@
3716  #include <linux/writeback.h>
3717  #include <linux/buffer_head.h>
3718  #include <linux/falloc.h>
3719 +#include <linux/proc_fs.h>
3720 +#include <linux/vserver/inode.h>
3721 +#include <linux/vs_tag.h>
3722  
3723  #include <asm/ioctls.h>
3724  
3725 diff -NurpP --minimal linux-3.2.5/fs/ioprio.c linux-3.2.5-vs2.3.2.6/fs/ioprio.c
3726 --- linux-3.2.5/fs/ioprio.c     2012-01-09 16:14:54.000000000 +0100
3727 +++ linux-3.2.5-vs2.3.2.6/fs/ioprio.c   2011-12-05 19:33:02.000000000 +0100
3728 @@ -28,6 +28,7 @@
3729  #include <linux/syscalls.h>
3730  #include <linux/security.h>
3731  #include <linux/pid_namespace.h>
3732 +#include <linux/vs_base.h>
3733  
3734  int set_task_ioprio(struct task_struct *task, int ioprio)
3735  {
3736 @@ -120,6 +121,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3737                         else
3738                                 pgrp = find_vpid(who);
3739                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3740 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3741 +                                       continue;
3742                                 ret = set_task_ioprio(p, ioprio);
3743                                 if (ret)
3744                                         break;
3745 @@ -209,6 +212,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3746                         else
3747                                 pgrp = find_vpid(who);
3748                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3749 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3750 +                                       continue;
3751                                 tmpio = get_task_ioprio(p);
3752                                 if (tmpio < 0)
3753                                         continue;
3754 diff -NurpP --minimal linux-3.2.5/fs/jfs/file.c linux-3.2.5-vs2.3.2.6/fs/jfs/file.c
3755 --- linux-3.2.5/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3756 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/file.c 2011-12-05 19:33:02.000000000 +0100
3757 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3758         if (is_quota_modification(inode, iattr))
3759                 dquot_initialize(inode);
3760         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3761 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3762 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3763 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3764                 rc = dquot_transfer(inode, iattr);
3765                 if (rc)
3766                         return rc;
3767 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3768  #ifdef CONFIG_JFS_POSIX_ACL
3769         .get_acl        = jfs_get_acl,
3770  #endif
3771 +       .sync_flags     = jfs_sync_flags,
3772  };
3773  
3774  const struct file_operations jfs_file_operations = {
3775 diff -NurpP --minimal linux-3.2.5/fs/jfs/ioctl.c linux-3.2.5-vs2.3.2.6/fs/jfs/ioctl.c
3776 --- linux-3.2.5/fs/jfs/ioctl.c  2011-05-22 16:17:52.000000000 +0200
3777 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/ioctl.c        2011-12-05 19:33:02.000000000 +0100
3778 @@ -11,6 +11,7 @@
3779  #include <linux/mount.h>
3780  #include <linux/time.h>
3781  #include <linux/sched.h>
3782 +#include <linux/mount.h>
3783  #include <asm/current.h>
3784  #include <asm/uaccess.h>
3785  
3786 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3787  }
3788  
3789  
3790 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3791 +{
3792 +       inode->i_flags = flags;
3793 +       inode->i_vflags = vflags;
3794 +       jfs_get_inode_flags(JFS_IP(inode));
3795 +       inode->i_ctime = CURRENT_TIME_SEC;
3796 +       mark_inode_dirty(inode);
3797 +       return 0;
3798 +}
3799 +
3800  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3801  {
3802         struct inode *inode = filp->f_dentry->d_inode;
3803 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3804                 if (!S_ISDIR(inode->i_mode))
3805                         flags &= ~JFS_DIRSYNC_FL;
3806  
3807 +               if (IS_BARRIER(inode)) {
3808 +                       vxwprintk_task(1, "messing with the barrier.");
3809 +                       return -EACCES;
3810 +               }
3811 +
3812                 /* Is it quota file? Do not allow user to mess with it */
3813                 if (IS_NOQUOTA(inode)) {
3814                         err = -EPERM;
3815 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3816                  * the relevant capability.
3817                  */
3818                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3819 -                       ((flags ^ oldflags) &
3820 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3821 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3822 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3823                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3824                                 mutex_unlock(&inode->i_mutex);
3825                                 err = -EPERM;
3826 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3827                         }
3828                 }
3829  
3830 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3831 +               flags &= JFS_FL_USER_MODIFIABLE;
3832                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3833                 jfs_inode->mode2 = flags;
3834  
3835 diff -NurpP --minimal linux-3.2.5/fs/jfs/jfs_dinode.h linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_dinode.h
3836 --- linux-3.2.5/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3837 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_dinode.h   2011-12-05 19:33:02.000000000 +0100
3838 @@ -161,9 +161,13 @@ struct dinode {
3839  
3840  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3841  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3842 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3843  
3844 -#define JFS_FL_USER_VISIBLE    0x03F80000
3845 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3846 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3847 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3848 +
3849 +#define JFS_FL_USER_VISIBLE    0x07F80000
3850 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3851  #define JFS_FL_INHERIT         0x03C80000
3852  
3853  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3854 diff -NurpP --minimal linux-3.2.5/fs/jfs/jfs_filsys.h linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_filsys.h
3855 --- linux-3.2.5/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3856 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_filsys.h   2011-12-05 19:33:02.000000000 +0100
3857 @@ -263,6 +263,7 @@
3858  #define JFS_NAME_MAX   255
3859  #define JFS_PATH_MAX   BPSIZE
3860  
3861 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3862  
3863  /*
3864   *     file system state (superblock state)
3865 diff -NurpP --minimal linux-3.2.5/fs/jfs/jfs_imap.c linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_imap.c
3866 --- linux-3.2.5/fs/jfs/jfs_imap.c       2012-01-09 16:14:54.000000000 +0100
3867 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_imap.c     2011-12-05 19:33:02.000000000 +0100
3868 @@ -46,6 +46,7 @@
3869  #include <linux/pagemap.h>
3870  #include <linux/quotaops.h>
3871  #include <linux/slab.h>
3872 +#include <linux/vs_tag.h>
3873  
3874  #include "jfs_incore.h"
3875  #include "jfs_inode.h"
3876 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3877  {
3878         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3879         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3880 +       uid_t uid;
3881 +       gid_t gid;
3882  
3883         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3884         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3885 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3886         }
3887         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3888  
3889 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3890 +       uid = le32_to_cpu(dip->di_uid);
3891 +       gid = le32_to_cpu(dip->di_gid);
3892 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3893 +
3894 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3895         if (sbi->uid == -1)
3896                 ip->i_uid = jfs_ip->saved_uid;
3897         else {
3898                 ip->i_uid = sbi->uid;
3899         }
3900  
3901 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3902 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3903         if (sbi->gid == -1)
3904                 ip->i_gid = jfs_ip->saved_gid;
3905         else {
3906 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3907         dip->di_size = cpu_to_le64(ip->i_size);
3908         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3909         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3910 -       if (sbi->uid == -1)
3911 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3912 -       else
3913 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3914 -       if (sbi->gid == -1)
3915 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3916 -       else
3917 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3918 +
3919 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3920 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3921 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3922 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3923 +
3924         jfs_get_inode_flags(jfs_ip);
3925         /*
3926          * mode2 is only needed for storing the higher order bits.
3927 diff -NurpP --minimal linux-3.2.5/fs/jfs/jfs_inode.c linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_inode.c
3928 --- linux-3.2.5/fs/jfs/jfs_inode.c      2012-01-09 16:14:54.000000000 +0100
3929 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_inode.c    2011-12-05 19:33:02.000000000 +0100
3930 @@ -18,6 +18,7 @@
3931  
3932  #include <linux/fs.h>
3933  #include <linux/quotaops.h>
3934 +#include <linux/vs_tag.h>
3935  #include "jfs_incore.h"
3936  #include "jfs_inode.h"
3937  #include "jfs_filsys.h"
3938 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3939  {
3940         unsigned int flags = JFS_IP(inode)->mode2;
3941  
3942 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3943 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3944 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3945 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3946  
3947         if (flags & JFS_IMMUTABLE_FL)
3948                 inode->i_flags |= S_IMMUTABLE;
3949 +       if (flags & JFS_IXUNLINK_FL)
3950 +               inode->i_flags |= S_IXUNLINK;
3951 +
3952 +       if (flags & JFS_SYNC_FL)
3953 +               inode->i_flags |= S_SYNC;
3954         if (flags & JFS_APPEND_FL)
3955                 inode->i_flags |= S_APPEND;
3956         if (flags & JFS_NOATIME_FL)
3957                 inode->i_flags |= S_NOATIME;
3958         if (flags & JFS_DIRSYNC_FL)
3959                 inode->i_flags |= S_DIRSYNC;
3960 -       if (flags & JFS_SYNC_FL)
3961 -               inode->i_flags |= S_SYNC;
3962 +
3963 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3964 +
3965 +       if (flags & JFS_BARRIER_FL)
3966 +               inode->i_vflags |= V_BARRIER;
3967 +       if (flags & JFS_COW_FL)
3968 +               inode->i_vflags |= V_COW;
3969  }
3970  
3971  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3972  {
3973         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3974 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3975 +
3976 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3977 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3978 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3979 +                          JFS_BARRIER_FL | JFS_COW_FL);
3980  
3981 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3982 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3983         if (flags & S_IMMUTABLE)
3984                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3985 +       if (flags & S_IXUNLINK)
3986 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3987 +
3988         if (flags & S_APPEND)
3989                 jfs_ip->mode2 |= JFS_APPEND_FL;
3990         if (flags & S_NOATIME)
3991 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3992                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3993         if (flags & S_SYNC)
3994                 jfs_ip->mode2 |= JFS_SYNC_FL;
3995 +
3996 +       if (vflags & V_BARRIER)
3997 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3998 +       if (vflags & V_COW)
3999 +               jfs_ip->mode2 |= JFS_COW_FL;
4000  }
4001  
4002  /*
4003 diff -NurpP --minimal linux-3.2.5/fs/jfs/jfs_inode.h linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_inode.h
4004 --- linux-3.2.5/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
4005 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/jfs_inode.h    2011-12-05 19:33:02.000000000 +0100
4006 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4007  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4008         int fh_len, int fh_type);
4009  extern void jfs_set_inode_flags(struct inode *);
4010 +extern int jfs_sync_flags(struct inode *, int, int);
4011  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4012  extern int jfs_setattr(struct dentry *, struct iattr *);
4013  
4014 diff -NurpP --minimal linux-3.2.5/fs/jfs/namei.c linux-3.2.5-vs2.3.2.6/fs/jfs/namei.c
4015 --- linux-3.2.5/fs/jfs/namei.c  2012-01-09 16:14:54.000000000 +0100
4016 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/namei.c        2011-12-05 19:33:02.000000000 +0100
4017 @@ -22,6 +22,7 @@
4018  #include <linux/ctype.h>
4019  #include <linux/quotaops.h>
4020  #include <linux/exportfs.h>
4021 +#include <linux/vs_tag.h>
4022  #include "jfs_incore.h"
4023  #include "jfs_superblock.h"
4024  #include "jfs_inode.h"
4025 @@ -1474,6 +1475,7 @@ static struct dentry *jfs_lookup(struct 
4026                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4027         }
4028  
4029 +       dx_propagate_tag(nd, ip);
4030         return d_splice_alias(ip, dentry);
4031  }
4032  
4033 @@ -1538,6 +1540,7 @@ const struct inode_operations jfs_dir_in
4034  #ifdef CONFIG_JFS_POSIX_ACL
4035         .get_acl        = jfs_get_acl,
4036  #endif
4037 +       .sync_flags     = jfs_sync_flags,
4038  };
4039  
4040  const struct file_operations jfs_dir_operations = {
4041 diff -NurpP --minimal linux-3.2.5/fs/jfs/super.c linux-3.2.5-vs2.3.2.6/fs/jfs/super.c
4042 --- linux-3.2.5/fs/jfs/super.c  2012-01-09 16:14:54.000000000 +0100
4043 +++ linux-3.2.5-vs2.3.2.6/fs/jfs/super.c        2011-12-05 19:33:02.000000000 +0100
4044 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4045  enum {
4046         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4047         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4048 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4049 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4050 +       Opt_tag, Opt_notag, Opt_tagid
4051  };
4052  
4053  static const match_table_t tokens = {
4054 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4055         {Opt_resize, "resize=%u"},
4056         {Opt_resize_nosize, "resize"},
4057         {Opt_errors, "errors=%s"},
4058 +       {Opt_tag, "tag"},
4059 +       {Opt_notag, "notag"},
4060 +       {Opt_tagid, "tagid=%u"},
4061 +       {Opt_tag, "tagxid"},
4062         {Opt_ignore, "noquota"},
4063         {Opt_ignore, "quota"},
4064         {Opt_usrquota, "usrquota"},
4065 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4066                         }
4067                         break;
4068                 }
4069 +#ifndef CONFIG_TAGGING_NONE
4070 +               case Opt_tag:
4071 +                       *flag |= JFS_TAGGED;
4072 +                       break;
4073 +               case Opt_notag:
4074 +                       *flag &= JFS_TAGGED;
4075 +                       break;
4076 +#endif
4077 +#ifdef CONFIG_PROPAGATE
4078 +               case Opt_tagid:
4079 +                       /* use args[0] */
4080 +                       *flag |= JFS_TAGGED;
4081 +                       break;
4082 +#endif
4083                 default:
4084                         printk("jfs: Unrecognized mount option \"%s\" "
4085                                         " or missing value\n", p);
4086 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4087                 return -EINVAL;
4088         }
4089  
4090 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4091 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4092 +                       sb->s_id);
4093 +               return -EINVAL;
4094 +       }
4095 +
4096         if (newLVSize) {
4097                 if (sb->s_flags & MS_RDONLY) {
4098                         printk(KERN_ERR
4099 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4100  #ifdef CONFIG_JFS_POSIX_ACL
4101         sb->s_flags |= MS_POSIXACL;
4102  #endif
4103 +       /* map mount option tagxid */
4104 +       if (sbi->flag & JFS_TAGGED)
4105 +               sb->s_flags |= MS_TAGGED;
4106  
4107         if (newLVSize) {
4108                 printk(KERN_ERR "resize option for remount only\n");
4109 diff -NurpP --minimal linux-3.2.5/fs/libfs.c linux-3.2.5-vs2.3.2.6/fs/libfs.c
4110 --- linux-3.2.5/fs/libfs.c      2012-01-09 16:14:54.000000000 +0100
4111 +++ linux-3.2.5-vs2.3.2.6/fs/libfs.c    2011-12-05 19:33:02.000000000 +0100
4112 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4113   * both impossible due to the lock on directory.
4114   */
4115  
4116 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4117 +static inline int do_dcache_readdir_filter(struct file *filp,
4118 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4119  {
4120         struct dentry *dentry = filp->f_path.dentry;
4121         struct dentry *cursor = filp->private_data;
4122 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4123                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4124                                 struct dentry *next;
4125                                 next = list_entry(p, struct dentry, d_u.d_child);
4126 +                               if (filter && !filter(next))
4127 +                                       continue;
4128                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4129                                 if (!simple_positive(next)) {
4130                                         spin_unlock(&next->d_lock);
4131 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4132         return 0;
4133  }
4134  
4135 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4136 +{
4137 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4138 +}
4139 +
4140 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4141 +       int (*filter)(struct dentry *))
4142 +{
4143 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4144 +}
4145 +
4146  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4147  {
4148         return -EISDIR;
4149 @@ -977,6 +991,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4150  EXPORT_SYMBOL(dcache_dir_lseek);
4151  EXPORT_SYMBOL(dcache_dir_open);
4152  EXPORT_SYMBOL(dcache_readdir);
4153 +EXPORT_SYMBOL(dcache_readdir_filter);
4154  EXPORT_SYMBOL(generic_read_dir);
4155  EXPORT_SYMBOL(mount_pseudo);
4156  EXPORT_SYMBOL(simple_write_begin);
4157 diff -NurpP --minimal linux-3.2.5/fs/locks.c linux-3.2.5-vs2.3.2.6/fs/locks.c
4158 --- linux-3.2.5/fs/locks.c      2012-01-09 16:14:54.000000000 +0100
4159 +++ linux-3.2.5-vs2.3.2.6/fs/locks.c    2012-01-09 16:19:31.000000000 +0100
4160 @@ -126,6 +126,8 @@
4161  #include <linux/time.h>
4162  #include <linux/rcupdate.h>
4163  #include <linux/pid_namespace.h>
4164 +#include <linux/vs_base.h>
4165 +#include <linux/vs_limit.h>
4166  
4167  #include <asm/uaccess.h>
4168  
4169 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4170  /* Allocate an empty lock structure. */
4171  struct file_lock *locks_alloc_lock(void)
4172  {
4173 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4174 +       struct file_lock *fl;
4175  
4176 -       if (fl)
4177 -               locks_init_lock_heads(fl);
4178 +       if (!vx_locks_avail(1))
4179 +               return NULL;
4180  
4181 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4182 +
4183 +       if (fl) {
4184 +               locks_init_lock_heads(fl);
4185 +               fl->fl_xid = -1;
4186 +       }
4187         return fl;
4188  }
4189  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4190 @@ -216,6 +224,7 @@ void locks_free_lock(struct file_lock *f
4191         BUG_ON(!list_empty(&fl->fl_block));
4192         BUG_ON(!list_empty(&fl->fl_link));
4193  
4194 +       vx_locks_dec(fl);
4195         locks_release_private(fl);
4196         kmem_cache_free(filelock_cache, fl);
4197  }
4198 @@ -225,6 +234,7 @@ void locks_init_lock(struct file_lock *f
4199  {
4200         memset(fl, 0, sizeof(struct file_lock));
4201         locks_init_lock_heads(fl);
4202 +       fl->fl_xid = -1;
4203  }
4204  
4205  EXPORT_SYMBOL(locks_init_lock);
4206 @@ -265,6 +275,7 @@ void locks_copy_lock(struct file_lock *n
4207         new->fl_file = fl->fl_file;
4208         new->fl_ops = fl->fl_ops;
4209         new->fl_lmops = fl->fl_lmops;
4210 +       new->fl_xid = fl->fl_xid;
4211  
4212         locks_copy_private(new, fl);
4213  }
4214 @@ -303,6 +314,11 @@ static int flock_make_lock(struct file *
4215         fl->fl_flags = FL_FLOCK;
4216         fl->fl_type = type;
4217         fl->fl_end = OFFSET_MAX;
4218 +
4219 +       vxd_assert(filp->f_xid == vx_current_xid(),
4220 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4221 +       fl->fl_xid = filp->f_xid;
4222 +       vx_locks_inc(fl);
4223         
4224         *lock = fl;
4225         return 0;
4226 @@ -452,6 +468,7 @@ static int lease_init(struct file *filp,
4227  
4228         fl->fl_owner = current->files;
4229         fl->fl_pid = current->tgid;
4230 +       fl->fl_xid = vx_current_xid();
4231  
4232         fl->fl_file = filp;
4233         fl->fl_flags = FL_LEASE;
4234 @@ -471,6 +488,11 @@ static struct file_lock *lease_alloc(str
4235         if (fl == NULL)
4236                 return ERR_PTR(error);
4237  
4238 +       fl->fl_xid = vx_current_xid();
4239 +       if (filp)
4240 +               vxd_assert(filp->f_xid == fl->fl_xid,
4241 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4242 +       vx_locks_inc(fl);
4243         error = lease_init(filp, type, fl);
4244         if (error) {
4245                 locks_free_lock(fl);
4246 @@ -772,6 +794,7 @@ static int flock_lock_file(struct file *
4247                 lock_flocks();
4248         }
4249  
4250 +       new_fl->fl_xid = -1;
4251  find_conflict:
4252         for_each_lock(inode, before) {
4253                 struct file_lock *fl = *before;
4254 @@ -792,6 +815,7 @@ find_conflict:
4255                 goto out;
4256         locks_copy_lock(new_fl, request);
4257         locks_insert_lock(before, new_fl);
4258 +       vx_locks_inc(new_fl);
4259         new_fl = NULL;
4260         error = 0;
4261  
4262 @@ -802,7 +826,8 @@ out:
4263         return error;
4264  }
4265  
4266 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4267 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4268 +       struct file_lock *conflock, xid_t xid)
4269  {
4270         struct file_lock *fl;
4271         struct file_lock *new_fl = NULL;
4272 @@ -812,6 +837,8 @@ static int __posix_lock_file(struct inod
4273         struct file_lock **before;
4274         int error, added = 0;
4275  
4276 +       vxd_assert(xid == vx_current_xid(),
4277 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4278         /*
4279          * We may need two file_lock structures for this operation,
4280          * so we get them in advance to avoid races.
4281 @@ -822,7 +849,11 @@ static int __posix_lock_file(struct inod
4282             (request->fl_type != F_UNLCK ||
4283              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4284                 new_fl = locks_alloc_lock();
4285 +               new_fl->fl_xid = xid;
4286 +               vx_locks_inc(new_fl);
4287                 new_fl2 = locks_alloc_lock();
4288 +               new_fl2->fl_xid = xid;
4289 +               vx_locks_inc(new_fl2);
4290         }
4291  
4292         lock_flocks();
4293 @@ -1021,7 +1052,8 @@ static int __posix_lock_file(struct inod
4294  int posix_lock_file(struct file *filp, struct file_lock *fl,
4295                         struct file_lock *conflock)
4296  {
4297 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4298 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4299 +               fl, conflock, filp->f_xid);
4300  }
4301  EXPORT_SYMBOL(posix_lock_file);
4302  
4303 @@ -1111,7 +1143,7 @@ int locks_mandatory_area(int read_write,
4304         fl.fl_end = offset + count - 1;
4305  
4306         for (;;) {
4307 -               error = __posix_lock_file(inode, &fl, NULL);
4308 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4309                 if (error != FILE_LOCK_DEFERRED)
4310                         break;
4311                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4312 @@ -1406,6 +1438,7 @@ int generic_add_lease(struct file *filp,
4313                 goto out;
4314  
4315         locks_insert_lock(before, lease);
4316 +       vx_locks_inc(lease);
4317         return 0;
4318  
4319  out:
4320 @@ -1846,6 +1879,11 @@ int fcntl_setlk(unsigned int fd, struct 
4321         if (file_lock == NULL)
4322                 return -ENOLCK;
4323  
4324 +       vxd_assert(filp->f_xid == vx_current_xid(),
4325 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4326 +       file_lock->fl_xid = filp->f_xid;
4327 +       vx_locks_inc(file_lock);
4328 +
4329         /*
4330          * This might block, so we do it before checking the inode.
4331          */
4332 @@ -1964,6 +2002,11 @@ int fcntl_setlk64(unsigned int fd, struc
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 @@ -2229,8 +2272,11 @@ static int locks_show(struct seq_file *f
4345  
4346         lock_get_status(f, fl, *((loff_t *)f->private), "");
4347  
4348 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4349 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4350 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4351 +                       continue;
4352                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4353 +       }
4354  
4355         return 0;
4356  }
4357 diff -NurpP --minimal linux-3.2.5/fs/namei.c linux-3.2.5-vs2.3.2.6/fs/namei.c
4358 --- linux-3.2.5/fs/namei.c      2012-01-09 16:14:54.000000000 +0100
4359 +++ linux-3.2.5-vs2.3.2.6/fs/namei.c    2011-12-05 19:33:02.000000000 +0100
4360 @@ -33,6 +33,14 @@
4361  #include <linux/device_cgroup.h>
4362  #include <linux/fs_struct.h>
4363  #include <linux/posix_acl.h>
4364 +#include <linux/proc_fs.h>
4365 +#include <linux/vserver/inode.h>
4366 +#include <linux/vs_base.h>
4367 +#include <linux/vs_tag.h>
4368 +#include <linux/vs_cowbl.h>
4369 +#include <linux/vs_device.h>
4370 +#include <linux/vs_context.h>
4371 +#include <linux/pid_namespace.h>
4372  #include <asm/uaccess.h>
4373  
4374  #include "internal.h"
4375 @@ -222,6 +230,89 @@ static int check_acl(struct inode *inode
4376         return -EAGAIN;
4377  }
4378  
4379 +static inline int dx_barrier(const struct inode *inode)
4380 +{
4381 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4382 +               vxwprintk_task(1, "did hit the barrier.");
4383 +               return 1;
4384 +       }
4385 +       return 0;
4386 +}
4387 +
4388 +static int __dx_permission(const struct inode *inode, int mask)
4389 +{
4390 +       if (dx_barrier(inode))
4391 +               return -EACCES;
4392 +
4393 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4394 +               /* devpts is xid tagged */
4395 +               if (S_ISDIR(inode->i_mode) ||
4396 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4397 +                       return 0;
4398 +
4399 +               /* just pretend we didn't find anything */
4400 +               return -ENOENT;
4401 +       }
4402 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4403 +               struct proc_dir_entry *de = PDE(inode);
4404 +
4405 +               if (de && !vx_hide_check(0, de->vx_flags))
4406 +                       goto out;
4407 +
4408 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4409 +                       struct pid *pid;
4410 +                       struct task_struct *tsk;
4411 +
4412 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4413 +                           vx_flags(VXF_STATE_SETUP, 0))
4414 +                               return 0;
4415 +
4416 +                       pid = PROC_I(inode)->pid;
4417 +                       if (!pid)
4418 +                               goto out;
4419 +
4420 +                       rcu_read_lock();
4421 +                       tsk = pid_task(pid, PIDTYPE_PID);
4422 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4423 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4424 +                       if (tsk &&
4425 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4426 +                               rcu_read_unlock();
4427 +                               return 0;
4428 +                       }
4429 +                       rcu_read_unlock();
4430 +               }
4431 +               else {
4432 +                       /* FIXME: Should we block some entries here? */
4433 +                       return 0;
4434 +               }
4435 +       }
4436 +       else {
4437 +               if (dx_notagcheck(inode->i_sb) ||
4438 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4439 +                            DX_IDENT))
4440 +                       return 0;
4441 +       }
4442 +
4443 +out:
4444 +       return -EACCES;
4445 +}
4446 +
4447 +int dx_permission(const struct inode *inode, int mask)
4448 +{
4449 +       int ret = __dx_permission(inode, mask);
4450 +       if (unlikely(ret)) {
4451 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4452 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4453 +#endif
4454 +                   vxwprintk_task(1,
4455 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4456 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4457 +                       inode->i_ino);
4458 +       }
4459 +       return ret;
4460 +}
4461 +
4462  /*
4463   * This does the basic permission checking
4464   */
4465 @@ -357,10 +448,14 @@ int inode_permission(struct inode *inode
4466                 /*
4467                  * Nobody gets write access to an immutable file.
4468                  */
4469 -               if (IS_IMMUTABLE(inode))
4470 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4471                         return -EACCES;
4472         }
4473  
4474 +       retval = dx_permission(inode, mask);
4475 +       if (retval)
4476 +               return retval;
4477 +
4478         retval = do_inode_permission(inode, mask);
4479         if (retval)
4480                 return retval;
4481 @@ -1037,7 +1132,8 @@ static void follow_dotdot(struct nameida
4482  
4483                 if (nd->path.dentry == nd->root.dentry &&
4484                     nd->path.mnt == nd->root.mnt) {
4485 -                       break;
4486 +                       /* for sane '/' avoid follow_mount() */
4487 +                       return;
4488                 }
4489                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4490                         /* rare case of legitimate dget_parent()... */
4491 @@ -1146,6 +1242,9 @@ static int do_lookup(struct nameidata *n
4492                 }
4493                 if (unlikely(d_need_lookup(dentry)))
4494                         goto unlazy;
4495 +
4496 +               /* FIXME: check dx permission */
4497 +
4498                 path->mnt = mnt;
4499                 path->dentry = dentry;
4500                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4501 @@ -1207,6 +1306,8 @@ retry:
4502                 }
4503         }
4504  
4505 +       /* FIXME: check dx permission */
4506 +
4507         path->mnt = mnt;
4508         path->dentry = dentry;
4509         err = follow_managed(path, nd->flags);
4510 @@ -1901,7 +2002,7 @@ static int may_delete(struct inode *dir,
4511         if (IS_APPEND(dir))
4512                 return -EPERM;
4513         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4514 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4515 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4516                 return -EPERM;
4517         if (isdir) {
4518                 if (!S_ISDIR(victim->d_inode->i_mode))
4519 @@ -1981,19 +2082,25 @@ int vfs_create(struct inode *dir, struct
4520  {
4521         int error = may_create(dir, dentry);
4522  
4523 -       if (error)
4524 +       if (error) {
4525 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4526                 return error;
4527 +       }
4528  
4529         if (!dir->i_op->create)
4530                 return -EACCES; /* shouldn't it be ENOSYS? */
4531         mode &= S_IALLUGO;
4532         mode |= S_IFREG;
4533         error = security_inode_create(dir, dentry, mode);
4534 -       if (error)
4535 +       if (error) {
4536 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4537                 return error;
4538 +       }
4539         error = dir->i_op->create(dir, dentry, mode, nd);
4540         if (!error)
4541                 fsnotify_create(dir, dentry);
4542 +       else
4543 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4544         return error;
4545  }
4546  
4547 @@ -2028,6 +2135,15 @@ static int may_open(struct path *path, i
4548                 break;
4549         }
4550  
4551 +#ifdef CONFIG_VSERVER_COWBL
4552 +       if (IS_COW(inode) &&
4553 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4554 +               if (IS_COW_LINK(inode))
4555 +                       return -EMLINK;
4556 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4557 +               mark_inode_dirty(inode);
4558 +       }
4559 +#endif
4560         error = inode_permission(inode, acc_mode);
4561         if (error)
4562                 return error;
4563 @@ -2252,6 +2368,16 @@ ok:
4564         }
4565  common:
4566         error = may_open(&nd->path, acc_mode, open_flag);
4567 +#ifdef CONFIG_VSERVER_COWBL
4568 +       if (error == -EMLINK) {
4569 +               struct dentry *dentry;
4570 +               dentry = cow_break_link(pathname);
4571 +               if (IS_ERR(dentry))
4572 +                       error = PTR_ERR(dentry);
4573 +               else
4574 +                       dput(dentry);
4575 +       }
4576 +#endif
4577         if (error)
4578                 goto exit;
4579         filp = nameidata_to_filp(nd);
4580 @@ -2294,6 +2420,7 @@ static struct file *path_openat(int dfd,
4581         struct path path;
4582         int error;
4583  
4584 +restart:
4585         filp = get_empty_filp();
4586         if (!filp)
4587                 return ERR_PTR(-ENFILE);
4588 @@ -2331,6 +2458,17 @@ static struct file *path_openat(int dfd,
4589                         filp = do_last(nd, &path, op, pathname);
4590                 put_link(nd, &link, cookie);
4591         }
4592 +
4593 +#ifdef CONFIG_VSERVER_COWBL
4594 +       if (filp == ERR_PTR(-EMLINK)) {
4595 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4596 +                       path_put(&nd->root);
4597 +               if (base)
4598 +                       fput(base);
4599 +               release_open_intent(nd);
4600 +               goto restart;
4601 +       }
4602 +#endif
4603  out:
4604         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4605                 path_put(&nd->root);
4606 @@ -2420,6 +2558,11 @@ struct dentry *kern_path_create(int dfd,
4607                 goto fail;
4608         }
4609         *path = nd.path;
4610 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4611 +               path->dentry, path->dentry->d_name.len,
4612 +               path->dentry->d_name.name, dentry,
4613 +               dentry->d_name.len, dentry->d_name.name,
4614 +               path->dentry->d_inode);
4615         return dentry;
4616  eexist:
4617         dput(dentry);
4618 @@ -2901,7 +3044,7 @@ int vfs_link(struct dentry *old_dentry, 
4619         /*
4620          * A link to an append-only or immutable file cannot be created.
4621          */
4622 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4623 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4624                 return -EPERM;
4625         if (!dir->i_op->link)
4626                 return -EPERM;
4627 @@ -3282,6 +3425,227 @@ int vfs_follow_link(struct nameidata *nd
4628         return __vfs_follow_link(nd, link);
4629  }
4630  
4631 +
4632 +#ifdef CONFIG_VSERVER_COWBL
4633 +
4634 +static inline
4635 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4636 +{
4637 +       loff_t ppos = 0;
4638 +
4639 +       return do_splice_direct(in, &ppos, out, len, 0);
4640 +}
4641 +
4642 +struct dentry *cow_break_link(const char *pathname)
4643 +{
4644 +       int ret, mode, pathlen, redo = 0;
4645 +       struct nameidata old_nd, dir_nd;
4646 +       struct path old_path, dir_path;
4647 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4648 +       struct file *old_file;
4649 +       struct file *new_file;
4650 +       char *to, *path, pad='\251';
4651 +       loff_t size;
4652 +
4653 +       vxdprintk(VXD_CBIT(misc, 1),
4654 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4655 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4656 +       ret = -ENOMEM;
4657 +       if (!path)
4658 +               goto out;
4659 +
4660 +       /* old_nd will have refs to dentry and mnt */
4661 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4662 +       vxdprintk(VXD_CBIT(misc, 2),
4663 +               "do_path_lookup(old): %d [r=%d]",
4664 +               ret, mnt_get_count(old_nd.path.mnt));
4665 +       if (ret < 0)
4666 +               goto out_free_path;
4667 +
4668 +       old_path = old_nd.path;
4669 +       old_dentry = old_path.dentry;
4670 +       mode = old_dentry->d_inode->i_mode;
4671 +
4672 +       to = d_path(&old_path, path, PATH_MAX-2);
4673 +       pathlen = strlen(to);
4674 +       vxdprintk(VXD_CBIT(misc, 2),
4675 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4676 +               old_dentry,
4677 +               old_dentry->d_name.len, old_dentry->d_name.name,
4678 +               old_dentry->d_name.len);
4679 +
4680 +       to[pathlen + 1] = 0;
4681 +retry:
4682 +       new_dentry = NULL;
4683 +       to[pathlen] = pad--;
4684 +       ret = -ELOOP;
4685 +       if (pad <= '\240')
4686 +               goto out_rel_old;
4687 +
4688 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4689 +       /* dir_nd will have refs to dentry and mnt */
4690 +       ret = do_path_lookup(AT_FDCWD, to,
4691 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4692 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4693 +       if (ret < 0)
4694 +               goto retry;
4695 +
4696 +       /* this puppy downs the dir inode mutex if successful */
4697 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4698 +       if (!new_dentry || IS_ERR(new_dentry)) {
4699 +               path_put(&dir_nd.path);
4700 +               vxdprintk(VXD_CBIT(misc, 2),
4701 +                       "kern_path_create(new) failed with %ld",
4702 +                       PTR_ERR(new_dentry));
4703 +               goto retry;
4704 +       }
4705 +       path_put(&dir_path);
4706 +       vxdprintk(VXD_CBIT(misc, 2),
4707 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4708 +               new_dentry,
4709 +               new_dentry->d_name.len, new_dentry->d_name.name,
4710 +               new_dentry->d_name.len);
4711 +
4712 +       dir = dir_nd.path.dentry;
4713 +
4714 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4715 +       vxdprintk(VXD_CBIT(misc, 2),
4716 +               "vfs_create(new): %d", ret);
4717 +       if (ret == -EEXIST) {
4718 +               mutex_unlock(&dir->d_inode->i_mutex);
4719 +               path_put(&dir_nd.path);
4720 +               dput(new_dentry);
4721 +               goto retry;
4722 +       }
4723 +       else if (ret < 0)
4724 +               goto out_unlock_new;
4725 +
4726 +       /* drop out early, ret passes ENOENT */
4727 +       ret = -ENOENT;
4728 +       if ((redo = d_unhashed(old_dentry)))
4729 +               goto out_unlock_new;
4730 +
4731 +       path_get(&old_path);
4732 +       /* this one cleans up the dentry/mnt in case of failure */
4733 +       old_file = dentry_open(old_dentry, old_path.mnt,
4734 +               O_RDONLY, current_cred());
4735 +       vxdprintk(VXD_CBIT(misc, 2),
4736 +               "dentry_open(old): %p", old_file);
4737 +       if (IS_ERR(old_file)) {
4738 +               ret = PTR_ERR(old_file);
4739 +               goto out_unlock_new;
4740 +       }
4741 +
4742 +       dget(new_dentry);
4743 +       mntget(old_path.mnt);
4744 +       /* this one cleans up the dentry/mnt in case of failure */
4745 +       new_file = dentry_open(new_dentry, old_path.mnt,
4746 +               O_WRONLY, current_cred());
4747 +       vxdprintk(VXD_CBIT(misc, 2),
4748 +               "dentry_open(new): %p", new_file);
4749 +       if (IS_ERR(new_file)) {
4750 +               ret = PTR_ERR(new_file);
4751 +               goto out_fput_old;
4752 +       }
4753 +
4754 +       size = i_size_read(old_file->f_dentry->d_inode);
4755 +       ret = do_cow_splice(old_file, new_file, size);
4756 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4757 +       if (ret < 0) {
4758 +               goto out_fput_both;
4759 +       } else if (ret < size) {
4760 +               ret = -ENOSPC;
4761 +               goto out_fput_both;
4762 +       } else {
4763 +               struct inode *old_inode = old_dentry->d_inode;
4764 +               struct inode *new_inode = new_dentry->d_inode;
4765 +               struct iattr attr = {
4766 +                       .ia_uid = old_inode->i_uid,
4767 +                       .ia_gid = old_inode->i_gid,
4768 +                       .ia_valid = ATTR_UID | ATTR_GID
4769 +                       };
4770 +
4771 +               setattr_copy(new_inode, &attr);
4772 +               mark_inode_dirty(new_inode);
4773 +       }
4774 +
4775 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4776 +
4777 +       /* drop out late */
4778 +       ret = -ENOENT;
4779 +       if ((redo = d_unhashed(old_dentry)))
4780 +               goto out_unlock;
4781 +
4782 +       vxdprintk(VXD_CBIT(misc, 2),
4783 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4784 +               new_dentry->d_name.len, new_dentry->d_name.name,
4785 +               new_dentry->d_name.len,
4786 +               old_dentry->d_name.len, old_dentry->d_name.name,
4787 +               old_dentry->d_name.len);
4788 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4789 +               old_dentry->d_parent->d_inode, old_dentry);
4790 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4791 +
4792 +out_unlock:
4793 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4794 +
4795 +out_fput_both:
4796 +       vxdprintk(VXD_CBIT(misc, 3),
4797 +               "fput(new_file=%p[#%ld])", new_file,
4798 +               atomic_long_read(&new_file->f_count));
4799 +       fput(new_file);
4800 +
4801 +out_fput_old:
4802 +       vxdprintk(VXD_CBIT(misc, 3),
4803 +               "fput(old_file=%p[#%ld])", old_file,
4804 +               atomic_long_read(&old_file->f_count));
4805 +       fput(old_file);
4806 +
4807 +out_unlock_new:
4808 +       mutex_unlock(&dir->d_inode->i_mutex);
4809 +       if (!ret)
4810 +               goto out_redo;
4811 +
4812 +       /* error path cleanup */
4813 +       vfs_unlink(dir->d_inode, new_dentry);
4814 +
4815 +out_redo:
4816 +       if (!redo)
4817 +               goto out_rel_both;
4818 +       /* lookup dentry once again */
4819 +       /* old_nd.path is freed as old_path in out_rel_old */
4820 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4821 +       if (ret)
4822 +               goto out_rel_both;
4823 +
4824 +       dput(new_dentry);
4825 +       new_dentry = old_nd.path.dentry;
4826 +       vxdprintk(VXD_CBIT(misc, 2),
4827 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4828 +               new_dentry,
4829 +               new_dentry->d_name.len, new_dentry->d_name.name,
4830 +               new_dentry->d_name.len);
4831 +       dget(new_dentry);
4832 +
4833 +out_rel_both:
4834 +       path_put(&dir_nd.path);
4835 +out_rel_old:
4836 +       path_put(&old_path);
4837 +out_free_path:
4838 +       kfree(path);
4839 +out:
4840 +       if (ret) {
4841 +               dput(new_dentry);
4842 +               new_dentry = ERR_PTR(ret);
4843 +       }
4844 +       vxdprintk(VXD_CBIT(misc, 3),
4845 +               "cow_break_link returning with %p [r=%d]",
4846 +               new_dentry, mnt_get_count(old_nd.path.mnt));
4847 +       return new_dentry;
4848 +}
4849 +
4850 +#endif
4851 +
4852  /* get the link contents into pagecache */
4853  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4854  {
4855 diff -NurpP --minimal linux-3.2.5/fs/namespace.c linux-3.2.5-vs2.3.2.6/fs/namespace.c
4856 --- linux-3.2.5/fs/namespace.c  2012-01-09 16:14:54.000000000 +0100
4857 +++ linux-3.2.5-vs2.3.2.6/fs/namespace.c        2011-12-15 01:11:32.000000000 +0100
4858 @@ -31,6 +31,11 @@
4859  #include <linux/idr.h>
4860  #include <linux/fs_struct.h>
4861  #include <linux/fsnotify.h>
4862 +#include <linux/vs_base.h>
4863 +#include <linux/vs_context.h>
4864 +#include <linux/vs_tag.h>
4865 +#include <linux/vserver/space.h>
4866 +#include <linux/vserver/global.h>
4867  #include <asm/uaccess.h>
4868  #include <asm/unistd.h>
4869  #include "pnode.h"
4870 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
4871         if (!type)
4872                 return ERR_PTR(-ENODEV);
4873  
4874 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4875 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4876 +               return ERR_PTR(-EPERM);
4877 +
4878         mnt = alloc_vfsmnt(name);
4879         if (!mnt)
4880                 return ERR_PTR(-ENOMEM);
4881 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
4882                 mnt->mnt_root = dget(root);
4883                 mnt->mnt_mountpoint = mnt->mnt_root;
4884                 mnt->mnt_parent = mnt;
4885 +               mnt->mnt_tag = old->mnt_tag;
4886  
4887                 if (flag & CL_SLAVE) {
4888                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
4889 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
4890         seq_escape(m, s, " \t\n\\");
4891  }
4892  
4893 +static int mnt_is_reachable(struct vfsmount *mnt)
4894 +{
4895 +       struct path root;
4896 +       struct dentry *point;
4897 +       int ret;
4898 +
4899 +       if (mnt == mnt->mnt_ns->root)
4900 +               return 1;
4901 +
4902 +       br_read_lock(vfsmount_lock);
4903 +       root = current->fs->root;
4904 +       point = root.dentry;
4905 +
4906 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
4907 +               point = mnt->mnt_mountpoint;
4908 +               mnt = mnt->mnt_parent;
4909 +       }
4910 +
4911 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
4912 +
4913 +       br_read_unlock(vfsmount_lock);
4914 +
4915 +       return ret;
4916 +}
4917 +
4918  /*
4919   * Simple .show_options callback for filesystems which don't want to
4920   * implement more complex mount option showing.
4921 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
4922                 { MS_SYNCHRONOUS, ",sync" },
4923                 { MS_DIRSYNC, ",dirsync" },
4924                 { MS_MANDLOCK, ",mand" },
4925 +               { MS_TAGGED, ",tag" },
4926 +               { MS_NOTAGCHECK, ",notagcheck" },
4927                 { 0, NULL }
4928         };
4929         const struct proc_fs_info *fs_infop;
4930 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
4931         int err = 0;
4932         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
4933  
4934 -       if (mnt->mnt_sb->s_op->show_devname) {
4935 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4936 -               if (err)
4937 -                       goto out;
4938 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4939 +               return SEQ_SKIP;
4940 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4941 +               return SEQ_SKIP;
4942 +
4943 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
4944 +               mnt == current->fs->root.mnt) {
4945 +               seq_puts(m, "/dev/root / ");
4946         } else {
4947 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
4948 +               if (mnt->mnt_sb->s_op->show_devname) {
4949 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4950 +                       if (err)
4951 +                               goto out;
4952 +               } else {
4953 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
4954 +               }
4955 +               seq_putc(m, ' ');
4956 +               seq_path(m, &mnt_path, " \t\n\\");
4957 +               seq_putc(m, ' ');
4958         }
4959 -       seq_putc(m, ' ');
4960 -       seq_path(m, &mnt_path, " \t\n\\");
4961 -       seq_putc(m, ' ');
4962         show_type(m, mnt->mnt_sb);
4963         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
4964         err = show_sb_opts(m, mnt->mnt_sb);
4965 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
4966         struct path root = p->root;
4967         int err = 0;
4968  
4969 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4970 +               return SEQ_SKIP;
4971 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4972 +               return SEQ_SKIP;
4973 +
4974         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
4975                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
4976         if (sb->s_op->show_path)
4977 @@ -1104,22 +1156,32 @@ static int show_vfsstat(struct seq_file 
4978         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
4979         int err = 0;
4980  
4981 -       /* device */
4982 -       if (mnt->mnt_sb->s_op->show_devname) {
4983 -               seq_puts(m, "device ");
4984 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4985 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4986 +               return SEQ_SKIP;
4987 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4988 +               return SEQ_SKIP;
4989 +
4990 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
4991 +               mnt == current->fs->root.mnt) {
4992 +               seq_puts(m, "device /dev/root mounted on / ");
4993         } else {
4994 -               if (mnt->mnt_devname) {
4995 +               /* device */
4996 +               if (mnt->mnt_sb->s_op->show_devname) {
4997                         seq_puts(m, "device ");
4998 -                       mangle(m, mnt->mnt_devname);
4999 -               } else
5000 -                       seq_puts(m, "no device");
5001 -       }
5002 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5003 +               } else {
5004 +                       if (mnt->mnt_devname) {
5005 +                               seq_puts(m, "device ");
5006 +                               mangle(m, mnt->mnt_devname);
5007 +                       } else
5008 +                               seq_puts(m, "no device");
5009 +               }
5010  
5011 -       /* mount point */
5012 -       seq_puts(m, " mounted on ");
5013 -       seq_path(m, &mnt_path, " \t\n\\");
5014 -       seq_putc(m, ' ');
5015 +               /* mount point */
5016 +               seq_puts(m, " mounted on ");
5017 +               seq_path(m, &mnt_path, " \t\n\\");
5018 +               seq_putc(m, ' ');
5019 +       }
5020  
5021         /* file system type */
5022         seq_puts(m, "with fstype ");
5023 @@ -1378,7 +1440,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5024                 goto dput_and_out;
5025  
5026         retval = -EPERM;
5027 -       if (!capable(CAP_SYS_ADMIN))
5028 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5029                 goto dput_and_out;
5030  
5031         retval = do_umount(path.mnt, flags);
5032 @@ -1404,7 +1466,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5033  
5034  static int mount_is_safe(struct path *path)
5035  {
5036 -       if (capable(CAP_SYS_ADMIN))
5037 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5038                 return 0;
5039         return -EPERM;
5040  #ifdef notyet
5041 @@ -1714,7 +1776,7 @@ static int do_change_type(struct path *p
5042         int type;
5043         int err = 0;
5044  
5045 -       if (!capable(CAP_SYS_ADMIN))
5046 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5047                 return -EPERM;
5048  
5049         if (path->dentry != path->mnt->mnt_root)
5050 @@ -1730,6 +1792,7 @@ static int do_change_type(struct path *p
5051                 if (err)
5052                         goto out_unlock;
5053         }
5054 +       // mnt->mnt_flags = mnt_flags;
5055  
5056         br_write_lock(vfsmount_lock);
5057         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5058 @@ -1745,12 +1808,14 @@ static int do_change_type(struct path *p
5059   * do loopback mount.
5060   */
5061  static int do_loopback(struct path *path, char *old_name,
5062 -                               int recurse)
5063 +       tag_t tag, unsigned long flags, int mnt_flags)
5064  {
5065         LIST_HEAD(umount_list);
5066         struct path old_path;
5067         struct vfsmount *mnt = NULL;
5068         int err = mount_is_safe(path);
5069 +       int recurse = flags & MS_REC;
5070 +
5071         if (err)
5072                 return err;
5073         if (!old_name || !*old_name)
5074 @@ -1816,12 +1881,12 @@ static int change_mount_flags(struct vfs
5075   * on it - tough luck.
5076   */
5077  static int do_remount(struct path *path, int flags, int mnt_flags,
5078 -                     void *data)
5079 +       void *data, xid_t xid)
5080  {
5081         int err;
5082         struct super_block *sb = path->mnt->mnt_sb;
5083  
5084 -       if (!capable(CAP_SYS_ADMIN))
5085 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5086                 return -EPERM;
5087  
5088         if (!check_mnt(path->mnt))
5089 @@ -1869,7 +1934,7 @@ static int do_move_mount(struct path *pa
5090         struct path old_path, parent_path;
5091         struct vfsmount *p;
5092         int err = 0;
5093 -       if (!capable(CAP_SYS_ADMIN))
5094 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5095                 return -EPERM;
5096         if (!old_name || !*old_name)
5097                 return -EINVAL;
5098 @@ -2020,7 +2085,7 @@ static int do_new_mount(struct path *pat
5099                 return -EINVAL;
5100  
5101         /* we need capabilities... */
5102 -       if (!capable(CAP_SYS_ADMIN))
5103 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5104                 return -EPERM;
5105  
5106         mnt = do_kern_mount(type, flags, name, data);
5107 @@ -2289,6 +2354,7 @@ long do_mount(char *dev_name, char *dir_
5108         struct path path;
5109         int retval = 0;
5110         int mnt_flags = 0;
5111 +       tag_t tag = 0;
5112  
5113         /* Discard magic */
5114         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5115 @@ -2316,6 +2382,12 @@ long do_mount(char *dev_name, char *dir_
5116         if (!(flags & MS_NOATIME))
5117                 mnt_flags |= MNT_RELATIME;
5118  
5119 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5120 +               /* FIXME: bind and re-mounts get the tag flag? */
5121 +               if (flags & (MS_BIND|MS_REMOUNT))
5122 +                       flags |= MS_TAGID;
5123 +       }
5124 +
5125         /* Separate the per-mountpoint flags */
5126         if (flags & MS_NOSUID)
5127                 mnt_flags |= MNT_NOSUID;
5128 @@ -2332,15 +2404,17 @@ long do_mount(char *dev_name, char *dir_
5129         if (flags & MS_RDONLY)
5130                 mnt_flags |= MNT_READONLY;
5131  
5132 +       if (!capable(CAP_SYS_ADMIN))
5133 +               mnt_flags |= MNT_NODEV;
5134         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5135                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5136                    MS_STRICTATIME);
5137  
5138         if (flags & MS_REMOUNT)
5139                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5140 -                                   data_page);
5141 +                                   data_page, tag);
5142         else if (flags & MS_BIND)
5143 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5144 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5145         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5146                 retval = do_change_type(&path, flags);
5147         else if (flags & MS_MOVE)
5148 @@ -2440,6 +2514,7 @@ static struct mnt_namespace *dup_mnt_ns(
5149                 q = next_mnt(q, new_ns->root);
5150         }
5151         up_write(&namespace_sem);
5152 +       atomic_inc(&vs_global_mnt_ns);
5153  
5154         if (rootmnt)
5155                 mntput(rootmnt);
5156 @@ -2611,9 +2686,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5157                 goto out3;
5158  
5159         error = -EINVAL;
5160 -       if (IS_MNT_SHARED(old.mnt) ||
5161 +       if ((IS_MNT_SHARED(old.mnt) ||
5162                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5163 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5164 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5165 +               !vx_flags(VXF_STATE_SETUP, 0))
5166                 goto out4;
5167         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5168                 goto out4;
5169 @@ -2745,6 +2821,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5170         br_write_unlock(vfsmount_lock);
5171         up_write(&namespace_sem);
5172         release_mounts(&umount_list);
5173 +       atomic_dec(&vs_global_mnt_ns);
5174         kfree(ns);
5175  }
5176  EXPORT_SYMBOL(put_mnt_ns);
5177 diff -NurpP --minimal linux-3.2.5/fs/nfs/client.c linux-3.2.5-vs2.3.2.6/fs/nfs/client.c
5178 --- linux-3.2.5/fs/nfs/client.c 2012-01-09 16:14:54.000000000 +0100
5179 +++ linux-3.2.5-vs2.3.2.6/fs/nfs/client.c       2011-12-05 19:33:02.000000000 +0100
5180 @@ -779,6 +779,9 @@ static int nfs_init_server_rpcclient(str
5181         if (server->flags & NFS_MOUNT_SOFT)
5182                 server->client->cl_softrtry = 1;
5183  
5184 +       server->client->cl_tag = 0;
5185 +       if (server->flags & NFS_MOUNT_TAGGED)
5186 +               server->client->cl_tag = 1;
5187         return 0;
5188  }
5189  
5190 @@ -953,6 +956,10 @@ static void nfs_server_set_fsinfo(struct
5191                 server->acdirmin = server->acdirmax = 0;
5192         }
5193  
5194 +       /* FIXME: needs fsinfo
5195 +       if (server->flags & NFS_MOUNT_TAGGED)
5196 +               sb->s_flags |= MS_TAGGED;       */
5197 +
5198         server->maxfilesize = fsinfo->maxfilesize;
5199  
5200         server->time_delta = fsinfo->time_delta;
5201 diff -NurpP --minimal linux-3.2.5/fs/nfs/dir.c linux-3.2.5-vs2.3.2.6/fs/nfs/dir.c
5202 --- linux-3.2.5/fs/nfs/dir.c    2012-01-09 16:14:54.000000000 +0100
5203 +++ linux-3.2.5-vs2.3.2.6/fs/nfs/dir.c  2011-12-05 19:33:02.000000000 +0100
5204 @@ -35,6 +35,7 @@
5205  #include <linux/sched.h>
5206  #include <linux/kmemleak.h>
5207  #include <linux/xattr.h>
5208 +#include <linux/vs_tag.h>
5209  
5210  #include "delegation.h"
5211  #include "iostat.h"
5212 @@ -1311,6 +1312,7 @@ static struct dentry *nfs_lookup(struct 
5213         if (IS_ERR(res))
5214                 goto out_unblock_sillyrename;
5215  
5216 +       dx_propagate_tag(nd, inode);
5217  no_entry:
5218         res = d_materialise_unique(dentry, inode);
5219         if (res != NULL) {
5220 diff -NurpP --minimal linux-3.2.5/fs/nfs/inode.c linux-3.2.5-vs2.3.2.6/fs/nfs/inode.c
5221 --- linux-3.2.5/fs/nfs/inode.c  2012-01-09 16:14:54.000000000 +0100
5222 +++ linux-3.2.5-vs2.3.2.6/fs/nfs/inode.c        2011-12-05 21:16:35.000000000 +0100
5223 @@ -38,6 +38,7 @@
5224  #include <linux/nfs_xdr.h>
5225  #include <linux/slab.h>
5226  #include <linux/compat.h>
5227 +#include <linux/vs_tag.h>
5228  
5229  #include <asm/system.h>
5230  #include <asm/uaccess.h>
5231 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
5232         if (inode->i_state & I_NEW) {
5233                 struct nfs_inode *nfsi = NFS_I(inode);
5234                 unsigned long now = jiffies;
5235 +               uid_t uid;
5236 +               gid_t gid;
5237  
5238                 /* We set i_ino for the few things that still rely on it,
5239                  * such as stat(2) */
5240 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
5241                 inode->i_version = 0;
5242                 inode->i_size = 0;
5243                 clear_nlink(inode);
5244 -               inode->i_uid = -2;
5245 -               inode->i_gid = -2;
5246 +               uid = -2;
5247 +               gid = -2;
5248                 inode->i_blocks = 0;
5249                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5250  
5251 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
5252                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5253                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5254                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5255 -                       inode->i_uid = fattr->uid;
5256 +                       uid = fattr->uid;
5257                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5258                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5259                                 | NFS_INO_INVALID_ACCESS
5260                                 | NFS_INO_INVALID_ACL;
5261                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5262 -                       inode->i_gid = fattr->gid;
5263 +                       gid = fattr->gid;
5264                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5265                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5266                                 | NFS_INO_INVALID_ACCESS
5267 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
5268                          */
5269                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5270                 }
5271 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5272 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5273 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5274 +                               /* maybe fattr->xid someday */
5275 +
5276                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5277                 nfsi->attrtimeo_timestamp = now;
5278                 nfsi->access_cache = RB_ROOT;
5279 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5280                         inode->i_uid = attr->ia_uid;
5281                 if ((attr->ia_valid & ATTR_GID) != 0)
5282                         inode->i_gid = attr->ia_gid;
5283 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5284 +                       inode->i_tag = attr->ia_tag;
5285                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5286                 spin_unlock(&inode->i_lock);
5287         }
5288 @@ -943,6 +953,9 @@ static int nfs_check_inode_attributes(st
5289         struct nfs_inode *nfsi = NFS_I(inode);
5290         loff_t cur_size, new_isize;
5291         unsigned long invalid = 0;
5292 +       uid_t uid;
5293 +       gid_t gid;
5294 +       tag_t tag;
5295  
5296  
5297         /* Has the inode gone and changed behind our back? */
5298 @@ -966,13 +979,18 @@ static int nfs_check_inode_attributes(st
5299                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5300         }
5301  
5302 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5303 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5304 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5305 +
5306         /* Have any file permissions changed? */
5307         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5308                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5309 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5310 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5311                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5312 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5313 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5314                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5315 +               /* maybe check for tag too? */
5316  
5317         /* Has the link count changed? */
5318         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5319 @@ -1207,6 +1225,9 @@ static int nfs_update_inode(struct inode
5320         unsigned long invalid = 0;
5321         unsigned long now = jiffies;
5322         unsigned long save_cache_validity;
5323 +       uid_t uid;
5324 +       gid_t gid;
5325 +       tag_t tag;
5326  
5327         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5328                         __func__, inode->i_sb->s_id, inode->i_ino,
5329 @@ -1314,6 +1335,9 @@ static int nfs_update_inode(struct inode
5330                                 | NFS_INO_REVAL_PAGECACHE
5331                                 | NFS_INO_REVAL_FORCED);
5332  
5333 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5334 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5335 +       tag = inode->i_tag;
5336  
5337         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5338                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5339 @@ -1335,9 +1359,9 @@ static int nfs_update_inode(struct inode
5340                                 | NFS_INO_REVAL_FORCED);
5341  
5342         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5343 -               if (inode->i_uid != fattr->uid) {
5344 +               if (uid != fattr->uid) {
5345                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5346 -                       inode->i_uid = fattr->uid;
5347 +                       uid = fattr->uid;
5348                 }
5349         } else if (server->caps & NFS_CAP_OWNER)
5350                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5351 @@ -1346,9 +1370,9 @@ static int nfs_update_inode(struct inode
5352                                 | NFS_INO_REVAL_FORCED);
5353  
5354         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5355 -               if (inode->i_gid != fattr->gid) {
5356 +               if (gid != fattr->gid) {
5357                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5358 -                       inode->i_gid = fattr->gid;
5359 +                       gid = fattr->gid;
5360                 }
5361         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5362                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5363 @@ -1356,6 +1380,10 @@ static int nfs_update_inode(struct inode
5364                                 | NFS_INO_INVALID_ACL
5365                                 | NFS_INO_REVAL_FORCED);
5366  
5367 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5368 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5369 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5370 +
5371         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5372                 if (inode->i_nlink != fattr->nlink) {
5373                         invalid |= NFS_INO_INVALID_ATTR;
5374 diff -NurpP --minimal linux-3.2.5/fs/nfs/nfs3xdr.c linux-3.2.5-vs2.3.2.6/fs/nfs/nfs3xdr.c
5375 --- linux-3.2.5/fs/nfs/nfs3xdr.c        2011-03-15 18:07:32.000000000 +0100
5376 +++ linux-3.2.5-vs2.3.2.6/fs/nfs/nfs3xdr.c      2011-12-05 19:33:02.000000000 +0100
5377 @@ -20,6 +20,7 @@
5378  #include <linux/nfs3.h>
5379  #include <linux/nfs_fs.h>
5380  #include <linux/nfsacl.h>
5381 +#include <linux/vs_tag.h>
5382  #include "internal.h"
5383  
5384  #define NFSDBG_FACILITY                NFSDBG_XDR
5385 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5386   *             set_mtime       mtime;
5387   *     };
5388   */
5389 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5390 +static void encode_sattr3(struct xdr_stream *xdr,
5391 +       const struct iattr *attr, int tag)
5392  {
5393         u32 nbytes;
5394         __be32 *p;
5395 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5396         } else
5397                 *p++ = xdr_zero;
5398  
5399 -       if (attr->ia_valid & ATTR_UID) {
5400 +       if (attr->ia_valid & ATTR_UID ||
5401 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5402                 *p++ = xdr_one;
5403 -               *p++ = cpu_to_be32(attr->ia_uid);
5404 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5405 +                       attr->ia_uid, attr->ia_tag));
5406         } else
5407                 *p++ = xdr_zero;
5408  
5409 -       if (attr->ia_valid & ATTR_GID) {
5410 +       if (attr->ia_valid & ATTR_GID ||
5411 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5412                 *p++ = xdr_one;
5413 -               *p++ = cpu_to_be32(attr->ia_gid);
5414 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5415 +                       attr->ia_gid, attr->ia_tag));
5416         } else
5417                 *p++ = xdr_zero;
5418  
5419 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5420                                       const struct nfs3_sattrargs *args)
5421  {
5422         encode_nfs_fh3(xdr, args->fh);
5423 -       encode_sattr3(xdr, args->sattr);
5424 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5425         encode_sattrguard3(xdr, args);
5426  }
5427  
5428 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5429   *     };
5430   */
5431  static void encode_createhow3(struct xdr_stream *xdr,
5432 -                             const struct nfs3_createargs *args)
5433 +       const struct nfs3_createargs *args, int tag)
5434  {
5435         encode_uint32(xdr, args->createmode);
5436         switch (args->createmode) {
5437         case NFS3_CREATE_UNCHECKED:
5438         case NFS3_CREATE_GUARDED:
5439 -               encode_sattr3(xdr, args->sattr);
5440 +               encode_sattr3(xdr, args->sattr, tag);
5441                 break;
5442         case NFS3_CREATE_EXCLUSIVE:
5443                 encode_createverf3(xdr, args->verifier);
5444 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5445                                      const struct nfs3_createargs *args)
5446  {
5447         encode_diropargs3(xdr, args->fh, args->name, args->len);
5448 -       encode_createhow3(xdr, args);
5449 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5450  }
5451  
5452  /*
5453 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5454                                     const struct nfs3_mkdirargs *args)
5455  {
5456         encode_diropargs3(xdr, args->fh, args->name, args->len);
5457 -       encode_sattr3(xdr, args->sattr);
5458 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5459  }
5460  
5461  /*
5462 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5463   *     };
5464   */
5465  static void encode_symlinkdata3(struct xdr_stream *xdr,
5466 -                               const struct nfs3_symlinkargs *args)
5467 +       const struct nfs3_symlinkargs *args, int tag)
5468  {
5469 -       encode_sattr3(xdr, args->sattr);
5470 +       encode_sattr3(xdr, args->sattr, tag);
5471         encode_nfspath3(xdr, args->pages, args->pathlen);
5472  }
5473  
5474 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5475                                       const struct nfs3_symlinkargs *args)
5476  {
5477         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5478 -       encode_symlinkdata3(xdr, args);
5479 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5480  }
5481  
5482  /*
5483 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5484   *     };
5485   */
5486  static void encode_devicedata3(struct xdr_stream *xdr,
5487 -                              const struct nfs3_mknodargs *args)
5488 +       const struct nfs3_mknodargs *args, int tag)
5489  {
5490 -       encode_sattr3(xdr, args->sattr);
5491 +       encode_sattr3(xdr, args->sattr, tag);
5492         encode_specdata3(xdr, args->rdev);
5493  }
5494  
5495  static void encode_mknoddata3(struct xdr_stream *xdr,
5496 -                             const struct nfs3_mknodargs *args)
5497 +       const struct nfs3_mknodargs *args, int tag)
5498  {
5499         encode_ftype3(xdr, args->type);
5500         switch (args->type) {
5501         case NF3CHR:
5502         case NF3BLK:
5503 -               encode_devicedata3(xdr, args);
5504 +               encode_devicedata3(xdr, args, tag);
5505                 break;
5506         case NF3SOCK:
5507         case NF3FIFO:
5508 -               encode_sattr3(xdr, args->sattr);
5509 +               encode_sattr3(xdr, args->sattr, tag);
5510                 break;
5511         case NF3REG:
5512         case NF3DIR:
5513 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5514                                     const struct nfs3_mknodargs *args)
5515  {
5516         encode_diropargs3(xdr, args->fh, args->name, args->len);
5517 -       encode_mknoddata3(xdr, args);
5518 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5519  }
5520  
5521  /*
5522 diff -NurpP --minimal linux-3.2.5/fs/nfs/super.c linux-3.2.5-vs2.3.2.6/fs/nfs/super.c
5523 --- linux-3.2.5/fs/nfs/super.c  2012-02-07 01:57:54.000000000 +0100
5524 +++ linux-3.2.5-vs2.3.2.6/fs/nfs/super.c        2012-01-26 08:52:10.000000000 +0100
5525 @@ -53,6 +53,7 @@
5526  #include <linux/nfs_xdr.h>
5527  #include <linux/magic.h>
5528  #include <linux/parser.h>
5529 +#include <linux/vs_tag.h>
5530  
5531  #include <asm/system.h>
5532  #include <asm/uaccess.h>
5533 @@ -87,6 +88,7 @@ enum {
5534         Opt_sharecache, Opt_nosharecache,
5535         Opt_resvport, Opt_noresvport,
5536         Opt_fscache, Opt_nofscache,
5537 +       Opt_tag, Opt_notag,
5538  
5539         /* Mount options that take integer arguments */
5540         Opt_port,
5541 @@ -100,6 +102,7 @@ enum {
5542         Opt_mountvers,
5543         Opt_nfsvers,
5544         Opt_minorversion,
5545 +       Opt_tagid,
5546  
5547         /* Mount options that take string arguments */
5548         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5549 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5550         { Opt_fscache_uniq, "fsc=%s" },
5551         { Opt_local_lock, "local_lock=%s" },
5552  
5553 +       { Opt_tag, "tag" },
5554 +       { Opt_notag, "notag" },
5555 +       { Opt_tagid, "tagid=%u" },
5556 +
5557         { Opt_err, NULL }
5558  };
5559  
5560 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
5561                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5562                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5563                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5564 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5565                 { 0, NULL, NULL }
5566         };
5567         const struct proc_nfs_info *nfs_infop;
5568 @@ -1217,6 +1225,14 @@ static int nfs_parse_mount_options(char 
5569                         kfree(mnt->fscache_uniq);
5570                         mnt->fscache_uniq = NULL;
5571                         break;
5572 +#ifndef CONFIG_TAGGING_NONE
5573 +               case Opt_tag:
5574 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5575 +                       break;
5576 +               case Opt_notag:
5577 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5578 +                       break;
5579 +#endif
5580  
5581                 /*
5582                  * options that take numeric values
5583 @@ -1323,6 +1339,12 @@ static int nfs_parse_mount_options(char 
5584                                 goto out_invalid_value;
5585                         mnt->minorversion = option;
5586                         break;
5587 +#ifdef CONFIG_PROPAGATE
5588 +               case Opt_tagid:
5589 +                       /* use args[0] */
5590 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5591 +                       break;
5592 +#endif
5593  
5594                 /*
5595                  * options that take text values
5596 diff -NurpP --minimal linux-3.2.5/fs/nfsd/auth.c linux-3.2.5-vs2.3.2.6/fs/nfsd/auth.c
5597 --- linux-3.2.5/fs/nfsd/auth.c  2010-02-25 11:52:05.000000000 +0100
5598 +++ linux-3.2.5-vs2.3.2.6/fs/nfsd/auth.c        2011-12-05 19:33:02.000000000 +0100
5599 @@ -1,6 +1,7 @@
5600  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5601  
5602  #include <linux/sched.h>
5603 +#include <linux/vs_tag.h>
5604  #include "nfsd.h"
5605  #include "auth.h"
5606  
5607 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5608  
5609         new->fsuid = rqstp->rq_cred.cr_uid;
5610         new->fsgid = rqstp->rq_cred.cr_gid;
5611 +       /* FIXME: this desperately needs a tag :)
5612 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5613 +                       */
5614  
5615         rqgi = rqstp->rq_cred.cr_group_info;
5616  
5617 diff -NurpP --minimal linux-3.2.5/fs/nfsd/nfs3xdr.c linux-3.2.5-vs2.3.2.6/fs/nfsd/nfs3xdr.c
5618 --- linux-3.2.5/fs/nfsd/nfs3xdr.c       2011-07-22 11:18:05.000000000 +0200
5619 +++ linux-3.2.5-vs2.3.2.6/fs/nfsd/nfs3xdr.c     2011-12-05 19:33:02.000000000 +0100
5620 @@ -7,6 +7,7 @@
5621   */
5622  
5623  #include <linux/namei.h>
5624 +#include <linux/vs_tag.h>
5625  #include "xdr3.h"
5626  #include "auth.h"
5627  
5628 @@ -95,6 +96,8 @@ static __be32 *
5629  decode_sattr3(__be32 *p, struct iattr *iap)
5630  {
5631         u32     tmp;
5632 +       uid_t   uid = 0;
5633 +       gid_t   gid = 0;
5634  
5635         iap->ia_valid = 0;
5636  
5637 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5638         }
5639         if (*p++) {
5640                 iap->ia_valid |= ATTR_UID;
5641 -               iap->ia_uid = ntohl(*p++);
5642 +               uid = ntohl(*p++);
5643         }
5644         if (*p++) {
5645                 iap->ia_valid |= ATTR_GID;
5646 -               iap->ia_gid = ntohl(*p++);
5647 +               gid = ntohl(*p++);
5648         }
5649 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5650 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5651 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5652         if (*p++) {
5653                 u64     newsize;
5654  
5655 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5656         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5657         *p++ = htonl((u32) stat->mode);
5658         *p++ = htonl((u32) stat->nlink);
5659 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5660 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5661 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5662 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5663 +               stat->uid, stat->tag)));
5664 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5665 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5666 +               stat->gid, stat->tag)));
5667         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5668                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5669         } else {
5670 diff -NurpP --minimal linux-3.2.5/fs/nfsd/nfs4xdr.c linux-3.2.5-vs2.3.2.6/fs/nfsd/nfs4xdr.c
5671 --- linux-3.2.5/fs/nfsd/nfs4xdr.c       2012-01-09 16:14:54.000000000 +0100
5672 +++ linux-3.2.5-vs2.3.2.6/fs/nfsd/nfs4xdr.c     2011-12-05 19:33:02.000000000 +0100
5673 @@ -46,6 +46,7 @@
5674  #include <linux/utsname.h>
5675  #include <linux/pagemap.h>
5676  #include <linux/sunrpc/svcauth_gss.h>
5677 +#include <linux/vs_tag.h>
5678  
5679  #include "idmap.h"
5680  #include "acl.h"
5681 @@ -2328,14 +2329,18 @@ out_acl:
5682                 WRITE32(stat.nlink);
5683         }
5684         if (bmval1 & FATTR4_WORD1_OWNER) {
5685 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5686 +               status = nfsd4_encode_user(rqstp,
5687 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5688 +                       stat.uid, stat.tag), &p, &buflen);
5689                 if (status == nfserr_resource)
5690                         goto out_resource;
5691                 if (status)
5692                         goto out;
5693         }
5694         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5695 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5696 +               status = nfsd4_encode_group(rqstp,
5697 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5698 +                       stat.gid, stat.tag), &p, &buflen);
5699                 if (status == nfserr_resource)
5700                         goto out_resource;
5701                 if (status)
5702 diff -NurpP --minimal linux-3.2.5/fs/nfsd/nfsxdr.c linux-3.2.5-vs2.3.2.6/fs/nfsd/nfsxdr.c
5703 --- linux-3.2.5/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5704 +++ linux-3.2.5-vs2.3.2.6/fs/nfsd/nfsxdr.c      2011-12-05 19:33:02.000000000 +0100
5705 @@ -6,6 +6,7 @@
5706  
5707  #include "xdr.h"
5708  #include "auth.h"
5709 +#include <linux/vs_tag.h>
5710  
5711  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5712  
5713 @@ -88,6 +89,8 @@ static __be32 *
5714  decode_sattr(__be32 *p, struct iattr *iap)
5715  {
5716         u32     tmp, tmp1;
5717 +       uid_t   uid = 0;
5718 +       gid_t   gid = 0;
5719  
5720         iap->ia_valid = 0;
5721  
5722 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5723         }
5724         if ((tmp = ntohl(*p++)) != (u32)-1) {
5725                 iap->ia_valid |= ATTR_UID;
5726 -               iap->ia_uid = tmp;
5727 +               uid = tmp;
5728         }
5729         if ((tmp = ntohl(*p++)) != (u32)-1) {
5730                 iap->ia_valid |= ATTR_GID;
5731 -               iap->ia_gid = tmp;
5732 +               gid = tmp;
5733         }
5734 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5735 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5736 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5737         if ((tmp = ntohl(*p++)) != (u32)-1) {
5738                 iap->ia_valid |= ATTR_SIZE;
5739                 iap->ia_size = tmp;
5740 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5741         *p++ = htonl(nfs_ftypes[type >> 12]);
5742         *p++ = htonl((u32) stat->mode);
5743         *p++ = htonl((u32) stat->nlink);
5744 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5745 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5746 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5747 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5748 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5749 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5750  
5751         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5752                 *p++ = htonl(NFS_MAXPATHLEN);
5753 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/dlmglue.c linux-3.2.5-vs2.3.2.6/fs/ocfs2/dlmglue.c
5754 --- linux-3.2.5/fs/ocfs2/dlmglue.c      2012-01-09 16:14:55.000000000 +0100
5755 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/dlmglue.c    2011-12-05 19:33:02.000000000 +0100
5756 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5757         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5758         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5759         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5760 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5761         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5762         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5763         lvb->lvb_iatime_packed  =
5764 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5765  
5766         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5767         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5768 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5769         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5770         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5771         ocfs2_unpack_timespec(&inode->i_atime,
5772 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/dlmglue.h linux-3.2.5-vs2.3.2.6/fs/ocfs2/dlmglue.h
5773 --- linux-3.2.5/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5774 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/dlmglue.h    2011-12-05 19:33:02.000000000 +0100
5775 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5776         __be16       lvb_inlink;
5777         __be32       lvb_iattr;
5778         __be32       lvb_igeneration;
5779 -       __be32       lvb_reserved2;
5780 +       __be16       lvb_itag;
5781 +       __be16       lvb_reserved2;
5782  };
5783  
5784  #define OCFS2_QINFO_LVB_VERSION 1
5785 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/file.c linux-3.2.5-vs2.3.2.6/fs/ocfs2/file.c
5786 --- linux-3.2.5/fs/ocfs2/file.c 2012-01-09 16:14:55.000000000 +0100
5787 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/file.c       2011-12-05 19:33:02.000000000 +0100
5788 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5789                 attr->ia_valid &= ~ATTR_SIZE;
5790  
5791  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5792 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5793 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5794         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5795                 return 0;
5796  
5797 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/inode.c linux-3.2.5-vs2.3.2.6/fs/ocfs2/inode.c
5798 --- linux-3.2.5/fs/ocfs2/inode.c        2012-01-09 16:14:55.000000000 +0100
5799 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/inode.c      2011-12-05 19:33:02.000000000 +0100
5800 @@ -28,6 +28,7 @@
5801  #include <linux/highmem.h>
5802  #include <linux/pagemap.h>
5803  #include <linux/quotaops.h>
5804 +#include <linux/vs_tag.h>
5805  
5806  #include <asm/byteorder.h>
5807  
5808 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5809  {
5810         unsigned int flags = OCFS2_I(inode)->ip_attr;
5811  
5812 -       inode->i_flags &= ~(S_IMMUTABLE |
5813 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5814                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5815  
5816         if (flags & OCFS2_IMMUTABLE_FL)
5817                 inode->i_flags |= S_IMMUTABLE;
5818 +       if (flags & OCFS2_IXUNLINK_FL)
5819 +               inode->i_flags |= S_IXUNLINK;
5820  
5821         if (flags & OCFS2_SYNC_FL)
5822                 inode->i_flags |= S_SYNC;
5823 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5824                 inode->i_flags |= S_NOATIME;
5825         if (flags & OCFS2_DIRSYNC_FL)
5826                 inode->i_flags |= S_DIRSYNC;
5827 +
5828 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5829 +
5830 +       if (flags & OCFS2_BARRIER_FL)
5831 +               inode->i_vflags |= V_BARRIER;
5832 +       if (flags & OCFS2_COW_FL)
5833 +               inode->i_vflags |= V_COW;
5834  }
5835  
5836  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5837  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5838  {
5839         unsigned int flags = oi->vfs_inode.i_flags;
5840 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5841 +
5842 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5843 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5844 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5845 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5846 +
5847 +       if (flags & S_IMMUTABLE)
5848 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5849 +       if (flags & S_IXUNLINK)
5850 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5851  
5852 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5853 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5854         if (flags & S_SYNC)
5855                 oi->ip_attr |= OCFS2_SYNC_FL;
5856         if (flags & S_APPEND)
5857                 oi->ip_attr |= OCFS2_APPEND_FL;
5858 -       if (flags & S_IMMUTABLE)
5859 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5860         if (flags & S_NOATIME)
5861                 oi->ip_attr |= OCFS2_NOATIME_FL;
5862         if (flags & S_DIRSYNC)
5863                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5864 +
5865 +       if (vflags & V_BARRIER)
5866 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5867 +       if (vflags & V_COW)
5868 +               oi->ip_attr |= OCFS2_COW_FL;
5869  }
5870  
5871  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5872 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5873         struct super_block *sb;
5874         struct ocfs2_super *osb;
5875         int use_plocks = 1;
5876 +       uid_t uid;
5877 +       gid_t gid;
5878  
5879         sb = inode->i_sb;
5880         osb = OCFS2_SB(sb);
5881 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5882         inode->i_generation = le32_to_cpu(fe->i_generation);
5883         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5884         inode->i_mode = le16_to_cpu(fe->i_mode);
5885 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5886 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5887 +       uid = le32_to_cpu(fe->i_uid);
5888 +       gid = le32_to_cpu(fe->i_gid);
5889 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5890 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5891 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5892 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5893  
5894         /* Fast symlinks will have i_size but no allocated clusters. */
5895         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5896 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/inode.h linux-3.2.5-vs2.3.2.6/fs/ocfs2/inode.h
5897 --- linux-3.2.5/fs/ocfs2/inode.h        2012-01-09 16:14:55.000000000 +0100
5898 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/inode.h      2011-12-05 19:33:02.000000000 +0100
5899 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5900  
5901  void ocfs2_set_inode_flags(struct inode *inode);
5902  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5903 +int ocfs2_sync_flags(struct inode *inode, int, int);
5904  
5905  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5906  {
5907 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/ioctl.c linux-3.2.5-vs2.3.2.6/fs/ocfs2/ioctl.c
5908 --- linux-3.2.5/fs/ocfs2/ioctl.c        2012-01-09 16:14:55.000000000 +0100
5909 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/ioctl.c      2011-12-05 19:33:02.000000000 +0100
5910 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
5911         return status;
5912  }
5913  
5914 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5915 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5916 +{
5917 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5918 +       struct buffer_head *bh = NULL;
5919 +       handle_t *handle = NULL;
5920 +       int status;
5921 +
5922 +       status = ocfs2_inode_lock(inode, &bh, 1);
5923 +       if (status < 0) {
5924 +               mlog_errno(status);
5925 +               return status;
5926 +       }
5927 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5928 +       if (IS_ERR(handle)) {
5929 +               status = PTR_ERR(handle);
5930 +               mlog_errno(status);
5931 +               goto bail_unlock;
5932 +       }
5933 +
5934 +       inode->i_flags = flags;
5935 +       inode->i_vflags = vflags;
5936 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5937 +
5938 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5939 +       if (status < 0)
5940 +               mlog_errno(status);
5941 +
5942 +       ocfs2_commit_trans(osb, handle);
5943 +bail_unlock:
5944 +       ocfs2_inode_unlock(inode, 1);
5945 +       brelse(bh);
5946 +       return status;
5947 +}
5948 +
5949 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5950                                 unsigned mask)
5951  {
5952         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5953 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
5954         if (!S_ISDIR(inode->i_mode))
5955                 flags &= ~OCFS2_DIRSYNC_FL;
5956  
5957 +       if (IS_BARRIER(inode)) {
5958 +               vxwprintk_task(1, "messing with the barrier.");
5959 +               goto bail_unlock;
5960 +       }
5961 +
5962         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5963         if (IS_ERR(handle)) {
5964                 status = PTR_ERR(handle);
5965 @@ -881,6 +920,7 @@ bail:
5966         return status;
5967  }
5968  
5969 +
5970  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5971  {
5972         struct inode *inode = filp->f_path.dentry->d_inode;
5973 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/namei.c linux-3.2.5-vs2.3.2.6/fs/ocfs2/namei.c
5974 --- linux-3.2.5/fs/ocfs2/namei.c        2012-01-09 16:14:55.000000000 +0100
5975 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/namei.c      2011-12-05 19:33:02.000000000 +0100
5976 @@ -41,6 +41,7 @@
5977  #include <linux/slab.h>
5978  #include <linux/highmem.h>
5979  #include <linux/quotaops.h>
5980 +#include <linux/vs_tag.h>
5981  
5982  #include <cluster/masklog.h>
5983  
5984 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5985         struct ocfs2_dinode *fe = NULL;
5986         struct ocfs2_extent_list *fel;
5987         u16 feat;
5988 +       tag_t tag;
5989  
5990         *new_fe_bh = NULL;
5991  
5992 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5993         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5994         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5995         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5996 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5997 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5998 +
5999 +       tag = dx_current_fstag(osb->sb);
6000 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6001 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6002 +       inode->i_tag = tag;
6003         fe->i_mode = cpu_to_le16(inode->i_mode);
6004         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6005                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6006 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/ocfs2.h linux-3.2.5-vs2.3.2.6/fs/ocfs2/ocfs2.h
6007 --- linux-3.2.5/fs/ocfs2/ocfs2.h        2012-01-09 16:14:55.000000000 +0100
6008 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/ocfs2.h      2011-12-05 19:33:02.000000000 +0100
6009 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6010                                                      writes */
6011         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6012         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6013 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6014  };
6015  
6016  #define OCFS2_OSB_SOFT_RO                      0x0001
6017 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/ocfs2_fs.h linux-3.2.5-vs2.3.2.6/fs/ocfs2/ocfs2_fs.h
6018 --- linux-3.2.5/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
6019 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/ocfs2_fs.h   2011-12-05 19:33:02.000000000 +0100
6020 @@ -266,6 +266,11 @@
6021  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6022  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6023  
6024 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6025 +
6026 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6027 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6028 +
6029  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6030  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6031  
6032 diff -NurpP --minimal linux-3.2.5/fs/ocfs2/super.c linux-3.2.5-vs2.3.2.6/fs/ocfs2/super.c
6033 --- linux-3.2.5/fs/ocfs2/super.c        2012-01-09 16:14:55.000000000 +0100
6034 +++ linux-3.2.5-vs2.3.2.6/fs/ocfs2/super.c      2011-12-05 19:33:02.000000000 +0100
6035 @@ -185,6 +185,7 @@ enum {
6036         Opt_coherency_full,
6037         Opt_resv_level,
6038         Opt_dir_resv_level,
6039 +       Opt_tag, Opt_notag, Opt_tagid,
6040         Opt_err,
6041  };
6042  
6043 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
6044         {Opt_coherency_full, "coherency=full"},
6045         {Opt_resv_level, "resv_level=%u"},
6046         {Opt_dir_resv_level, "dir_resv_level=%u"},
6047 +       {Opt_tag, "tag"},
6048 +       {Opt_notag, "notag"},
6049 +       {Opt_tagid, "tagid=%u"},
6050         {Opt_err, NULL}
6051  };
6052  
6053 @@ -663,6 +667,13 @@ static int ocfs2_remount(struct super_bl
6054                 goto out;
6055         }
6056  
6057 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6058 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6059 +               ret = -EINVAL;
6060 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6061 +               goto out;
6062 +       }
6063 +
6064         /* We're going to/from readonly mode. */
6065         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6066                 /* Disable quota accounting before remounting RO */
6067 @@ -1178,6 +1189,9 @@ static int ocfs2_fill_super(struct super
6068  
6069         ocfs2_complete_mount_recovery(osb);
6070  
6071 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6072 +               sb->s_flags |= MS_TAGGED;
6073 +
6074         if (ocfs2_mount_local(osb))
6075                 snprintf(nodestr, sizeof(nodestr), "local");
6076         else
6077 @@ -1507,6 +1521,20 @@ static int ocfs2_parse_options(struct su
6078                             option < OCFS2_MAX_RESV_LEVEL)
6079                                 mopt->dir_resv_level = option;
6080                         break;
6081 +#ifndef CONFIG_TAGGING_NONE
6082 +               case Opt_tag:
6083 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6084 +                       break;
6085 +               case Opt_notag:
6086 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6087 +                       break;
6088 +#endif
6089 +#ifdef CONFIG_PROPAGATE
6090 +               case Opt_tagid:
6091 +                       /* use args[0] */
6092 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6093 +                       break;
6094 +#endif
6095                 default:
6096                         mlog(ML_ERROR,
6097                              "Unrecognized mount option \"%s\" "
6098 diff -NurpP --minimal linux-3.2.5/fs/open.c linux-3.2.5-vs2.3.2.6/fs/open.c
6099 --- linux-3.2.5/fs/open.c       2012-01-09 16:14:55.000000000 +0100
6100 +++ linux-3.2.5-vs2.3.2.6/fs/open.c     2011-12-05 19:33:02.000000000 +0100
6101 @@ -30,6 +30,11 @@
6102  #include <linux/fs_struct.h>
6103  #include <linux/ima.h>
6104  #include <linux/dnotify.h>
6105 +#include <linux/vs_base.h>
6106 +#include <linux/vs_limit.h>
6107 +#include <linux/vs_tag.h>
6108 +#include <linux/vs_cowbl.h>
6109 +#include <linux/vserver/dlimit.h>
6110  
6111  #include "internal.h"
6112  
6113 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6114         error = user_path(pathname, &path);
6115         if (error)
6116                 goto out;
6117 +
6118 +#ifdef CONFIG_VSERVER_COWBL
6119 +       error = cow_check_and_break(&path);
6120 +       if (error)
6121 +               goto dput_and_out;
6122 +#endif
6123         inode = path.dentry->d_inode;
6124  
6125         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6126 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6127  
6128         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6129         if (!error) {
6130 +#ifdef CONFIG_VSERVER_COWBL
6131 +               error = cow_check_and_break(&path);
6132 +               if (!error)
6133 +#endif
6134                 error = chmod_common(&path, mode);
6135                 path_put(&path);
6136         }
6137 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6138         newattrs.ia_valid =  ATTR_CTIME;
6139         if (user != (uid_t) -1) {
6140                 newattrs.ia_valid |= ATTR_UID;
6141 -               newattrs.ia_uid = user;
6142 +               newattrs.ia_uid = dx_map_uid(user);
6143         }
6144         if (group != (gid_t) -1) {
6145                 newattrs.ia_valid |= ATTR_GID;
6146 -               newattrs.ia_gid = group;
6147 +               newattrs.ia_gid = dx_map_gid(group);
6148         }
6149         if (!S_ISDIR(inode->i_mode))
6150                 newattrs.ia_valid |=
6151 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6152         error = mnt_want_write(path.mnt);
6153         if (error)
6154                 goto out_release;
6155 +#ifdef CONFIG_VSERVER_COWBL
6156 +       error = cow_check_and_break(&path);
6157 +       if (!error)
6158 +#endif
6159         error = chown_common(&path, user, group);
6160         mnt_drop_write(path.mnt);
6161  out_release:
6162 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6163         error = mnt_want_write(path.mnt);
6164         if (error)
6165                 goto out_release;
6166 +#ifdef CONFIG_VSERVER_COWBL
6167 +       error = cow_check_and_break(&path);
6168 +       if (!error)
6169 +#endif
6170         error = chown_common(&path, user, group);
6171         mnt_drop_write(path.mnt);
6172  out_release:
6173 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6174         error = mnt_want_write(path.mnt);
6175         if (error)
6176                 goto out_release;
6177 +#ifdef CONFIG_VSERVER_COWBL
6178 +       error = cow_check_and_break(&path);
6179 +       if (!error)
6180 +#endif
6181         error = chown_common(&path, user, group);
6182         mnt_drop_write(path.mnt);
6183  out_release:
6184 @@ -839,6 +866,7 @@ static void __put_unused_fd(struct files
6185         __FD_CLR(fd, fdt->open_fds);
6186         if (fd < files->next_fd)
6187                 files->next_fd = fd;
6188 +       vx_openfd_dec(fd);
6189  }
6190  
6191  void put_unused_fd(unsigned int fd)
6192 diff -NurpP --minimal linux-3.2.5/fs/proc/array.c linux-3.2.5-vs2.3.2.6/fs/proc/array.c
6193 --- linux-3.2.5/fs/proc/array.c 2011-10-24 18:45:27.000000000 +0200
6194 +++ linux-3.2.5-vs2.3.2.6/fs/proc/array.c       2011-12-05 19:33:02.000000000 +0100
6195 @@ -81,6 +81,8 @@
6196  #include <linux/pid_namespace.h>
6197  #include <linux/ptrace.h>
6198  #include <linux/tracehook.h>
6199 +#include <linux/vs_context.h>
6200 +#include <linux/vs_network.h>
6201  
6202  #include <asm/pgtable.h>
6203  #include <asm/processor.h>
6204 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6205         rcu_read_lock();
6206         ppid = pid_alive(p) ?
6207                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6208 +       if (unlikely(vx_current_initpid(p->pid)))
6209 +               ppid = 0;
6210 +
6211         tpid = 0;
6212         if (pid_alive(p)) {
6213                 struct task_struct *tracer = ptrace_parent(p);
6214 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6215  }
6216  
6217  static void render_cap_t(struct seq_file *m, const char *header,
6218 -                       kernel_cap_t *a)
6219 +                       struct vx_info *vxi, kernel_cap_t *a)
6220  {
6221         unsigned __capi;
6222  
6223 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6224         cap_bset        = cred->cap_bset;
6225         rcu_read_unlock();
6226  
6227 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6228 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6229 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6230 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6231 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6232 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6233 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6234 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6235 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6236  }
6237  
6238  static inline void task_context_switch_counts(struct seq_file *m,
6239 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6240         seq_putc(m, '\n');
6241  }
6242  
6243 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6244 +                       struct pid *pid, struct task_struct *task)
6245 +{
6246 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6247 +                       "Count:\t%u\n"
6248 +                       "uts:\t%p(%c)\n"
6249 +                       "ipc:\t%p(%c)\n"
6250 +                       "mnt:\t%p(%c)\n"
6251 +                       "pid:\t%p(%c)\n"
6252 +                       "net:\t%p(%c)\n",
6253 +                       task->nsproxy,
6254 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6255 +                       atomic_read(&task->nsproxy->count),
6256 +                       task->nsproxy->uts_ns,
6257 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6258 +                       task->nsproxy->ipc_ns,
6259 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6260 +                       task->nsproxy->mnt_ns,
6261 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6262 +                       task->nsproxy->pid_ns,
6263 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6264 +                       task->nsproxy->net_ns,
6265 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6266 +       return 0;
6267 +}
6268 +
6269 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6270 +{
6271 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6272 +               return;
6273 +
6274 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6275 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6276 +}
6277 +
6278 +
6279  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6280                         struct pid *pid, struct task_struct *task)
6281  {
6282 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6283         task_cap(m, task);
6284         task_cpus_allowed(m, task);
6285         cpuset_task_status_allowed(m, task);
6286 +       task_vs_id(m, task);
6287         task_context_switch_counts(m, task);
6288         return 0;
6289  }
6290 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6291         /* convert nsec -> ticks */
6292         start_time = nsec_to_clock_t(start_time);
6293  
6294 +       /* fixup start time for virt uptime */
6295 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6296 +               unsigned long long bias =
6297 +                       current->vx_info->cvirt.bias_clock;
6298 +
6299 +               if (start_time > bias)
6300 +                       start_time -= bias;
6301 +               else
6302 +                       start_time = 0;
6303 +       }
6304 +
6305         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6306  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6307  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6308 diff -NurpP --minimal linux-3.2.5/fs/proc/base.c linux-3.2.5-vs2.3.2.6/fs/proc/base.c
6309 --- linux-3.2.5/fs/proc/base.c  2012-02-07 01:57:54.000000000 +0100
6310 +++ linux-3.2.5-vs2.3.2.6/fs/proc/base.c        2012-01-26 08:52:10.000000000 +0100
6311 @@ -83,6 +83,8 @@
6312  #include <linux/pid_namespace.h>
6313  #include <linux/fs_struct.h>
6314  #include <linux/slab.h>
6315 +#include <linux/vs_context.h>
6316 +#include <linux/vs_network.h>
6317  #ifdef CONFIG_HARDWALL
6318  #include <asm/hardwall.h>
6319  #endif
6320 @@ -1035,11 +1037,16 @@ static ssize_t oom_adjust_write(struct f
6321                 goto err_task_lock;
6322         }
6323  
6324 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6325 +       if (oom_adjust < task->signal->oom_adj &&
6326 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6327                 err = -EACCES;
6328                 goto err_sighand;
6329         }
6330  
6331 +       /* prevent guest processes from circumventing the oom killer */
6332 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6333 +               oom_adjust = OOM_ADJUST_MIN;
6334 +
6335         /*
6336          * Warn that /proc/pid/oom_adj is deprecated, see
6337          * Documentation/feature-removal-schedule.txt.
6338 @@ -1194,7 +1201,7 @@ static ssize_t proc_loginuid_write(struc
6339         ssize_t length;
6340         uid_t loginuid;
6341  
6342 -       if (!capable(CAP_AUDIT_CONTROL))
6343 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6344                 return -EPERM;
6345  
6346         rcu_read_lock();
6347 @@ -1641,6 +1648,8 @@ struct inode *proc_pid_make_inode(struct
6348                 inode->i_gid = cred->egid;
6349                 rcu_read_unlock();
6350         }
6351 +       /* procfs is xid tagged */
6352 +       inode->i_tag = (tag_t)vx_task_xid(task);
6353         security_task_to_inode(task, inode);
6354  
6355  out:
6356 @@ -1677,6 +1686,8 @@ int pid_getattr(struct vfsmount *mnt, st
6357  
6358  /* dentry stuff */
6359  
6360 +static unsigned name_to_int(struct dentry *dentry);
6361 +
6362  /*
6363   *     Exceptional case: normally we are not allowed to unhash a busy
6364   * directory. In this case, however, we can do it - no aliasing problems
6365 @@ -1705,6 +1716,12 @@ int pid_revalidate(struct dentry *dentry
6366         task = get_proc_task(inode);
6367  
6368         if (task) {
6369 +               unsigned pid = name_to_int(dentry);
6370 +
6371 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6372 +                       put_task_struct(task);
6373 +                       goto drop;
6374 +               }
6375                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6376                     task_dumpable(task)) {
6377                         rcu_read_lock();
6378 @@ -1721,6 +1738,7 @@ int pid_revalidate(struct dentry *dentry
6379                 put_task_struct(task);
6380                 return 1;
6381         }
6382 +drop:
6383         d_drop(dentry);
6384         return 0;
6385  }
6386 @@ -2210,6 +2228,13 @@ static struct dentry *proc_pident_lookup
6387         if (!task)
6388                 goto out_no_task;
6389  
6390 +       /* TODO: maybe we can come up with a generic approach? */
6391 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6392 +               (dentry->d_name.len == 5) &&
6393 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6394 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6395 +               goto out;
6396 +
6397         /*
6398          * Yes, it does not scale. And it should not. Don't add
6399          * new entries into /proc/<tgid>/ without very good reasons.
6400 @@ -2595,7 +2620,7 @@ out_iput:
6401  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6402  {
6403         struct dentry *error;
6404 -       struct task_struct *task = get_proc_task(dir);
6405 +       struct task_struct *task = get_proc_task_real(dir);
6406         const struct pid_entry *p, *last;
6407  
6408         error = ERR_PTR(-ENOENT);
6409 @@ -2702,6 +2727,9 @@ static int proc_pid_personality(struct s
6410  static const struct file_operations proc_task_operations;
6411  static const struct inode_operations proc_task_inode_operations;
6412  
6413 +extern int proc_pid_vx_info(struct task_struct *, char *);
6414 +extern int proc_pid_nx_info(struct task_struct *, char *);
6415 +
6416  static const struct pid_entry tgid_base_stuff[] = {
6417         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6418         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6419 @@ -2765,6 +2793,8 @@ static const struct pid_entry tgid_base_
6420  #ifdef CONFIG_CGROUPS
6421         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6422  #endif
6423 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6424 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6425         INF("oom_score",  S_IRUGO, proc_oom_score),
6426         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6427         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6428 @@ -2784,6 +2814,7 @@ static const struct pid_entry tgid_base_
6429  #ifdef CONFIG_HARDWALL
6430         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6431  #endif
6432 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6433  };
6434  
6435  static int proc_tgid_base_readdir(struct file * filp,
6436 @@ -2976,7 +3007,7 @@ retry:
6437         iter.task = NULL;
6438         pid = find_ge_pid(iter.tgid, ns);
6439         if (pid) {
6440 -               iter.tgid = pid_nr_ns(pid, ns);
6441 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6442                 iter.task = pid_task(pid, PIDTYPE_PID);
6443                 /* What we to know is if the pid we have find is the
6444                  * pid of a thread_group_leader.  Testing for task
6445 @@ -3006,7 +3037,7 @@ static int proc_pid_fill_cache(struct fi
6446         struct tgid_iter iter)
6447  {
6448         char name[PROC_NUMBUF];
6449 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6450 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6451         return proc_fill_cache(filp, dirent, filldir, name, len,
6452                                 proc_pid_instantiate, iter.task, NULL);
6453  }
6454 @@ -3023,7 +3054,7 @@ int proc_pid_readdir(struct file * filp,
6455                 goto out_no_task;
6456         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6457  
6458 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6459 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6460         if (!reaper)
6461                 goto out_no_task;
6462  
6463 @@ -3040,6 +3071,8 @@ int proc_pid_readdir(struct file * filp,
6464              iter.task;
6465              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6466                 filp->f_pos = iter.tgid + TGID_OFFSET;
6467 +               if (!vx_proc_task_visible(iter.task))
6468 +                       continue;
6469                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6470                         put_task_struct(iter.task);
6471                         goto out;
6472 @@ -3193,6 +3226,8 @@ static struct dentry *proc_task_lookup(s
6473         tid = name_to_int(dentry);
6474         if (tid == ~0U)
6475                 goto out;
6476 +       if (vx_current_initpid(tid))
6477 +               goto out;
6478  
6479         ns = dentry->d_sb->s_fs_info;
6480         rcu_read_lock();
6481 diff -NurpP --minimal linux-3.2.5/fs/proc/generic.c linux-3.2.5-vs2.3.2.6/fs/proc/generic.c
6482 --- linux-3.2.5/fs/proc/generic.c       2012-01-09 16:14:55.000000000 +0100
6483 +++ linux-3.2.5-vs2.3.2.6/fs/proc/generic.c     2011-12-05 19:33:02.000000000 +0100
6484 @@ -22,6 +22,7 @@
6485  #include <linux/bitops.h>
6486  #include <linux/spinlock.h>
6487  #include <linux/completion.h>
6488 +#include <linux/vserver/inode.h>
6489  #include <asm/uaccess.h>
6490  
6491  #include "internal.h"
6492 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6493         for (de = de->subdir; de ; de = de->next) {
6494                 if (de->namelen != dentry->d_name.len)
6495                         continue;
6496 +               if (!vx_hide_check(0, de->vx_flags))
6497 +                       continue;
6498                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6499                         pde_get(de);
6500                         spin_unlock(&proc_subdir_lock);
6501                         error = -EINVAL;
6502                         inode = proc_get_inode(dir->i_sb, de);
6503 +                       /* generic proc entries belong to the host */
6504 +                       inode->i_tag = 0;
6505                         goto out_unlock;
6506                 }
6507         }
6508 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6509  
6510                                 /* filldir passes info to user space */
6511                                 pde_get(de);
6512 +                               if (!vx_hide_check(0, de->vx_flags))
6513 +                                       goto skip;
6514                                 spin_unlock(&proc_subdir_lock);
6515                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6516                                             de->low_ino, de->mode >> 12) < 0) {
6517 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6518                                         goto out;
6519                                 }
6520                                 spin_lock(&proc_subdir_lock);
6521 +                       skip:
6522                                 filp->f_pos++;
6523                                 next = de->next;
6524                                 pde_put(de);
6525 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6526         ent->nlink = nlink;
6527         atomic_set(&ent->count, 1);
6528         ent->pde_users = 0;
6529 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6530         spin_lock_init(&ent->pde_unload_lock);
6531         ent->pde_unload_completion = NULL;
6532         INIT_LIST_HEAD(&ent->pde_openers);
6533 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6534                                 kfree(ent->data);
6535                                 kfree(ent);
6536                                 ent = NULL;
6537 -                       }
6538 +                       } else
6539 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6540                 } else {
6541                         kfree(ent);
6542                         ent = NULL;
6543 diff -NurpP --minimal linux-3.2.5/fs/proc/inode.c linux-3.2.5-vs2.3.2.6/fs/proc/inode.c
6544 --- linux-3.2.5/fs/proc/inode.c 2012-01-09 16:14:55.000000000 +0100
6545 +++ linux-3.2.5-vs2.3.2.6/fs/proc/inode.c       2011-12-05 19:33:02.000000000 +0100
6546 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
6547                         inode->i_uid = de->uid;
6548                         inode->i_gid = de->gid;
6549                 }
6550 +               if (de->vx_flags)
6551 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6552                 if (de->size)
6553                         inode->i_size = de->size;
6554                 if (de->nlink)
6555 diff -NurpP --minimal linux-3.2.5/fs/proc/internal.h linux-3.2.5-vs2.3.2.6/fs/proc/internal.h
6556 --- linux-3.2.5/fs/proc/internal.h      2011-07-22 11:18:06.000000000 +0200
6557 +++ linux-3.2.5-vs2.3.2.6/fs/proc/internal.h    2011-12-05 19:33:02.000000000 +0100
6558 @@ -10,6 +10,7 @@
6559   */
6560  
6561  #include <linux/proc_fs.h>
6562 +#include <linux/vs_pid.h>
6563  
6564  extern struct proc_dir_entry proc_root;
6565  #ifdef CONFIG_PROC_SYSCTL
6566 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6567                                 struct pid *pid, struct task_struct *task);
6568  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6569                                 struct pid *pid, struct task_struct *task);
6570 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6571 +                               struct pid *pid, struct task_struct *task);
6572 +
6573  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6574  
6575  extern const struct file_operations proc_maps_operations;
6576 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6577         return PROC_I(inode)->pid;
6578  }
6579  
6580 -static inline struct task_struct *get_proc_task(struct inode *inode)
6581 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6582  {
6583         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6584  }
6585  
6586 +static inline struct task_struct *get_proc_task(struct inode *inode)
6587 +{
6588 +       return vx_get_proc_task(inode, proc_pid(inode));
6589 +}
6590 +
6591  static inline int proc_fd(struct inode *inode)
6592  {
6593         return PROC_I(inode)->fd;
6594 diff -NurpP --minimal linux-3.2.5/fs/proc/loadavg.c linux-3.2.5-vs2.3.2.6/fs/proc/loadavg.c
6595 --- linux-3.2.5/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6596 +++ linux-3.2.5-vs2.3.2.6/fs/proc/loadavg.c     2011-12-05 19:33:02.000000000 +0100
6597 @@ -12,15 +12,27 @@
6598  
6599  static int loadavg_proc_show(struct seq_file *m, void *v)
6600  {
6601 +       unsigned long running;
6602 +       unsigned int threads;
6603         unsigned long avnrun[3];
6604  
6605         get_avenrun(avnrun, FIXED_1/200, 0);
6606  
6607 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6608 +               struct vx_info *vxi = current_vx_info();
6609 +
6610 +               running = atomic_read(&vxi->cvirt.nr_running);
6611 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6612 +       } else {
6613 +               running = nr_running();
6614 +               threads = nr_threads;
6615 +       }
6616 +
6617         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6618                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6619                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6620                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6621 -               nr_running(), nr_threads,
6622 +               running, threads,
6623                 task_active_pid_ns(current)->last_pid);
6624         return 0;
6625  }
6626 diff -NurpP --minimal linux-3.2.5/fs/proc/meminfo.c linux-3.2.5-vs2.3.2.6/fs/proc/meminfo.c
6627 --- linux-3.2.5/fs/proc/meminfo.c       2012-01-09 16:14:55.000000000 +0100
6628 +++ linux-3.2.5-vs2.3.2.6/fs/proc/meminfo.c     2011-12-15 01:11:32.000000000 +0100
6629 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6630         allowed = ((totalram_pages - hugetlb_total_pages())
6631                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6632  
6633 -       cached = global_page_state(NR_FILE_PAGES) -
6634 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6635 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6636                         total_swapcache_pages - i.bufferram;
6637         if (cached < 0)
6638                 cached = 0;
6639 diff -NurpP --minimal linux-3.2.5/fs/proc/root.c linux-3.2.5-vs2.3.2.6/fs/proc/root.c
6640 --- linux-3.2.5/fs/proc/root.c  2012-01-09 16:14:55.000000000 +0100
6641 +++ linux-3.2.5-vs2.3.2.6/fs/proc/root.c        2012-01-09 16:19:31.000000000 +0100
6642 @@ -18,9 +18,14 @@
6643  #include <linux/bitops.h>
6644  #include <linux/mount.h>
6645  #include <linux/pid_namespace.h>
6646 +#include <linux/vserver/inode.h>
6647  
6648  #include "internal.h"
6649  
6650 +struct proc_dir_entry *proc_virtual;
6651 +
6652 +extern void proc_vx_init(void);
6653 +
6654  static int proc_test_super(struct super_block *sb, void *data)
6655  {
6656         return sb->s_fs_info == data;
6657 @@ -123,6 +128,7 @@ void __init proc_root_init(void)
6658  #endif
6659         proc_mkdir("bus", NULL);
6660         proc_sys_init();
6661 +       proc_vx_init();
6662  }
6663  
6664  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6665 @@ -190,6 +196,7 @@ struct proc_dir_entry proc_root = {
6666         .proc_iops      = &proc_root_inode_operations, 
6667         .proc_fops      = &proc_root_operations,
6668         .parent         = &proc_root,
6669 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6670         .name           = "/proc",
6671  };
6672  
6673 diff -NurpP --minimal linux-3.2.5/fs/proc/uptime.c linux-3.2.5-vs2.3.2.6/fs/proc/uptime.c
6674 --- linux-3.2.5/fs/proc/uptime.c        2012-02-07 01:57:54.000000000 +0100
6675 +++ linux-3.2.5-vs2.3.2.6/fs/proc/uptime.c      2012-01-26 09:03:19.000000000 +0100
6676 @@ -5,6 +5,7 @@
6677  #include <linux/seq_file.h>
6678  #include <linux/time.h>
6679  #include <linux/kernel_stat.h>
6680 +#include <linux/vserver/cvirt.h>
6681  #include <asm/cputime.h>
6682  
6683  static int uptime_proc_show(struct seq_file *m, void *v)
6684 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6685         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6686         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6687         idle.tv_nsec = rem;
6688 +
6689 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6690 +               vx_vsi_uptime(&uptime, &idle);
6691 +
6692         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6693                         (unsigned long) uptime.tv_sec,
6694                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6695 diff -NurpP --minimal linux-3.2.5/fs/quota/dquot.c linux-3.2.5-vs2.3.2.6/fs/quota/dquot.c
6696 --- linux-3.2.5/fs/quota/dquot.c        2011-07-22 11:18:06.000000000 +0200
6697 +++ linux-3.2.5-vs2.3.2.6/fs/quota/dquot.c      2011-12-05 19:33:02.000000000 +0100
6698 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
6699         int reserve = flags & DQUOT_SPACE_RESERVE;
6700         int nofail = flags & DQUOT_SPACE_NOFAIL;
6701  
6702 +       if ((ret = dl_alloc_space(inode, number)))
6703 +               return ret;
6704 +
6705         /*
6706          * First test before acquiring mutex - solves deadlocks when we
6707          * re-enter the quota code and are already holding the mutex
6708 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
6709         int cnt, ret = 0;
6710         char warntype[MAXQUOTAS];
6711  
6712 +       if ((ret = dl_alloc_inode(inode)))
6713 +               return ret;
6714 +
6715         /* First test before acquiring mutex - solves deadlocks when we
6716           * re-enter the quota code and are already holding the mutex */
6717         if (!dquot_active(inode))
6718 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
6719         char warntype[MAXQUOTAS];
6720         int reserve = flags & DQUOT_SPACE_RESERVE;
6721  
6722 +       dl_free_space(inode, number);
6723 +
6724         /* First test before acquiring mutex - solves deadlocks when we
6725           * re-enter the quota code and are already holding the mutex */
6726         if (!dquot_active(inode)) {
6727 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
6728         unsigned int cnt;
6729         char warntype[MAXQUOTAS];
6730  
6731 +       dl_free_inode(inode);
6732 +
6733         /* First test before acquiring mutex - solves deadlocks when we
6734           * re-enter the quota code and are already holding the mutex */
6735         if (!dquot_active(inode))
6736 diff -NurpP --minimal linux-3.2.5/fs/quota/quota.c linux-3.2.5-vs2.3.2.6/fs/quota/quota.c
6737 --- linux-3.2.5/fs/quota/quota.c        2012-01-09 16:14:55.000000000 +0100
6738 +++ linux-3.2.5-vs2.3.2.6/fs/quota/quota.c      2011-12-05 19:33:02.000000000 +0100
6739 @@ -8,6 +8,7 @@
6740  #include <linux/fs.h>
6741  #include <linux/namei.h>
6742  #include <linux/slab.h>
6743 +#include <linux/vs_context.h>
6744  #include <asm/current.h>
6745  #include <asm/uaccess.h>
6746  #include <linux/kernel.h>
6747 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6748                         break;
6749                 /*FALLTHROUGH*/
6750         default:
6751 -               if (!capable(CAP_SYS_ADMIN))
6752 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6753                         return -EPERM;
6754         }
6755  
6756 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
6757         }
6758  }
6759  
6760 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6761 +
6762 +#include <linux/vroot.h>
6763 +#include <linux/major.h>
6764 +#include <linux/module.h>
6765 +#include <linux/kallsyms.h>
6766 +#include <linux/vserver/debug.h>
6767 +
6768 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6769 +
6770 +static DEFINE_SPINLOCK(vroot_grb_lock);
6771 +
6772 +int register_vroot_grb(vroot_grb_func *func) {
6773 +       int ret = -EBUSY;
6774 +
6775 +       spin_lock(&vroot_grb_lock);
6776 +       if (!vroot_get_real_bdev) {
6777 +               vroot_get_real_bdev = func;
6778 +               ret = 0;
6779 +       }
6780 +       spin_unlock(&vroot_grb_lock);
6781 +       return ret;
6782 +}
6783 +EXPORT_SYMBOL(register_vroot_grb);
6784 +
6785 +int unregister_vroot_grb(vroot_grb_func *func) {
6786 +       int ret = -EINVAL;
6787 +
6788 +       spin_lock(&vroot_grb_lock);
6789 +       if (vroot_get_real_bdev) {
6790 +               vroot_get_real_bdev = NULL;
6791 +               ret = 0;
6792 +       }
6793 +       spin_unlock(&vroot_grb_lock);
6794 +       return ret;
6795 +}
6796 +EXPORT_SYMBOL(unregister_vroot_grb);
6797 +
6798 +#endif
6799 +
6800  /*
6801   * look up a superblock on which quota ops will be performed
6802   * - use the name of a block device to find the superblock thereon
6803 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
6804         putname(tmp);
6805         if (IS_ERR(bdev))
6806                 return ERR_CAST(bdev);
6807 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6808 +       if (bdev && bdev->bd_inode &&
6809 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6810 +               struct block_device *bdnew = (void *)-EINVAL;
6811 +
6812 +               if (vroot_get_real_bdev)
6813 +                       bdnew = vroot_get_real_bdev(bdev);
6814 +               else
6815 +                       vxdprintk(VXD_CBIT(misc, 0),
6816 +                                       "vroot_get_real_bdev not set");
6817 +               bdput(bdev);
6818 +               if (IS_ERR(bdnew))
6819 +                       return ERR_PTR(PTR_ERR(bdnew));
6820 +               bdev = bdnew;
6821 +       }
6822 +#endif
6823         sb = get_super(bdev);
6824         bdput(bdev);
6825         if (!sb)
6826 diff -NurpP --minimal linux-3.2.5/fs/reiserfs/file.c linux-3.2.5-vs2.3.2.6/fs/reiserfs/file.c
6827 --- linux-3.2.5/fs/reiserfs/file.c      2011-10-24 18:45:27.000000000 +0200
6828 +++ linux-3.2.5-vs2.3.2.6/fs/reiserfs/file.c    2011-12-05 19:33:02.000000000 +0100
6829 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6830         .listxattr = reiserfs_listxattr,
6831         .removexattr = reiserfs_removexattr,
6832         .permission = reiserfs_permission,
6833 +       .sync_flags = reiserfs_sync_flags,
6834         .get_acl = reiserfs_get_acl,
6835  };
6836 diff -NurpP --minimal linux-3.2.5/fs/reiserfs/inode.c linux-3.2.5-vs2.3.2.6/fs/reiserfs/inode.c
6837 --- linux-3.2.5/fs/reiserfs/inode.c     2012-01-09 16:14:55.000000000 +0100
6838 +++ linux-3.2.5-vs2.3.2.6/fs/reiserfs/inode.c   2011-12-05 21:18:16.000000000 +0100
6839 @@ -18,6 +18,7 @@
6840  #include <linux/writeback.h>
6841  #include <linux/quotaops.h>
6842  #include <linux/swap.h>
6843 +#include <linux/vs_tag.h>
6844  
6845  int reiserfs_commit_write(struct file *f, struct page *page,
6846                           unsigned from, unsigned to);
6847 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6848         struct buffer_head *bh;
6849         struct item_head *ih;
6850         __u32 rdev;
6851 +       uid_t uid;
6852 +       gid_t gid;
6853         //int version = ITEM_VERSION_1;
6854  
6855         bh = PATH_PLAST_BUFFER(path);
6856 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6857                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6858                 unsigned long blocks;
6859  
6860 +               uid = sd_v1_uid(sd);
6861 +               gid = sd_v1_gid(sd);
6862 +
6863                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6864                 set_inode_sd_version(inode, STAT_DATA_V1);
6865                 inode->i_mode = sd_v1_mode(sd);
6866                 set_nlink(inode, sd_v1_nlink(sd));
6867 -               inode->i_uid = sd_v1_uid(sd);
6868 -               inode->i_gid = sd_v1_gid(sd);
6869                 inode->i_size = sd_v1_size(sd);
6870                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6871                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6872 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6873                 // (directories and symlinks)
6874                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6875  
6876 +               uid    = sd_v2_uid(sd);
6877 +               gid    = sd_v2_gid(sd);
6878 +
6879                 inode->i_mode = sd_v2_mode(sd);
6880                 set_nlink(inode, sd_v2_nlink(sd));
6881 -               inode->i_uid = sd_v2_uid(sd);
6882                 inode->i_size = sd_v2_size(sd);
6883 -               inode->i_gid = sd_v2_gid(sd);
6884                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6885                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6886                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6887 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6888                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6889         }
6890  
6891 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6892 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6893 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6894 +
6895         pathrelse(path);
6896         if (S_ISREG(inode->i_mode)) {
6897                 inode->i_op = &reiserfs_file_inode_operations;
6898 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6899  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6900  {
6901         struct stat_data *sd_v2 = (struct stat_data *)sd;
6902 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6903 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6904         __u16 flags;
6905  
6906 +       set_sd_v2_uid(sd_v2, uid);
6907 +       set_sd_v2_gid(sd_v2, gid);
6908         set_sd_v2_mode(sd_v2, inode->i_mode);
6909         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6910 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6911         set_sd_v2_size(sd_v2, size);
6912 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6913         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6914         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6915         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6916 @@ -2868,14 +2879,19 @@ int reiserfs_commit_write(struct file *f
6917  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6918  {
6919         if (reiserfs_attrs(inode->i_sb)) {
6920 -               if (sd_attrs & REISERFS_SYNC_FL)
6921 -                       inode->i_flags |= S_SYNC;
6922 -               else
6923 -                       inode->i_flags &= ~S_SYNC;
6924                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6925                         inode->i_flags |= S_IMMUTABLE;
6926                 else
6927                         inode->i_flags &= ~S_IMMUTABLE;
6928 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6929 +                       inode->i_flags |= S_IXUNLINK;
6930 +               else
6931 +                       inode->i_flags &= ~S_IXUNLINK;
6932 +
6933 +               if (sd_attrs & REISERFS_SYNC_FL)
6934 +                       inode->i_flags |= S_SYNC;
6935 +               else
6936 +                       inode->i_flags &= ~S_SYNC;
6937                 if (sd_attrs & REISERFS_APPEND_FL)
6938                         inode->i_flags |= S_APPEND;
6939                 else
6940 @@ -2888,6 +2904,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6941                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6942                 else
6943                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6944 +
6945 +               if (sd_attrs & REISERFS_BARRIER_FL)
6946 +                       inode->i_vflags |= V_BARRIER;
6947 +               else
6948 +                       inode->i_vflags &= ~V_BARRIER;
6949 +               if (sd_attrs & REISERFS_COW_FL)
6950 +                       inode->i_vflags |= V_COW;
6951 +               else
6952 +                       inode->i_vflags &= ~V_COW;
6953         }
6954  }
6955  
6956 @@ -2898,6 +2923,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6957                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6958                 else
6959                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6960 +               if (inode->i_flags & S_IXUNLINK)
6961 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6962 +               else
6963 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6964 +
6965                 if (inode->i_flags & S_SYNC)
6966                         *sd_attrs |= REISERFS_SYNC_FL;
6967                 else
6968 @@ -2910,6 +2940,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6969                         *sd_attrs |= REISERFS_NOTAIL_FL;
6970                 else
6971                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6972 +
6973 +               if (inode->i_vflags & V_BARRIER)
6974 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6975 +               else
6976 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6977 +               if (inode->i_vflags & V_COW)
6978 +                       *sd_attrs |= REISERFS_COW_FL;
6979 +               else
6980 +                       *sd_attrs &= ~REISERFS_COW_FL;
6981         }
6982  }
6983  
6984 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
6985         }
6986  
6987         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
6988 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
6989 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
6990 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
6991                 struct reiserfs_transaction_handle th;
6992                 int jbegin_count =
6993                     2 *
6994 @@ -3184,6 +3224,9 @@ int reiserfs_setattr(struct dentry *dent
6995                         inode->i_uid = attr->ia_uid;
6996                 if (attr->ia_valid & ATTR_GID)
6997                         inode->i_gid = attr->ia_gid;
6998 +                               if ((attr->ia_valid & ATTR_TAG) &&
6999 +                                       IS_TAGGED(inode))
7000 +                                       inode->i_tag = attr->ia_tag;
7001                 mark_inode_dirty(inode);
7002                 error = journal_end(&th, inode->i_sb, jbegin_count);
7003                 if (error)
7004 diff -NurpP --minimal linux-3.2.5/fs/reiserfs/ioctl.c linux-3.2.5-vs2.3.2.6/fs/reiserfs/ioctl.c
7005 --- linux-3.2.5/fs/reiserfs/ioctl.c     2011-05-22 16:17:53.000000000 +0200
7006 +++ linux-3.2.5-vs2.3.2.6/fs/reiserfs/ioctl.c   2011-12-05 19:33:02.000000000 +0100
7007 @@ -11,6 +11,21 @@
7008  #include <linux/pagemap.h>
7009  #include <linux/compat.h>
7010  
7011 +
7012 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7013 +{
7014 +       __u16 sd_attrs = 0;
7015 +
7016 +       inode->i_flags = flags;
7017 +       inode->i_vflags = vflags;
7018 +
7019 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7020 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7021 +       inode->i_ctime = CURRENT_TIME_SEC;
7022 +       mark_inode_dirty(inode);
7023 +       return 0;
7024 +}
7025 +
7026  /*
7027   * reiserfs_ioctl - handler for ioctl for inode
7028   * supported commands:
7029 @@ -22,7 +37,7 @@
7030  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7031  {
7032         struct inode *inode = filp->f_path.dentry->d_inode;
7033 -       unsigned int flags;
7034 +       unsigned int flags, oldflags;
7035         int err = 0;
7036  
7037         reiserfs_write_lock(inode->i_sb);
7038 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7039  
7040                 flags = REISERFS_I(inode)->i_attrs;
7041                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7042 +               flags &= REISERFS_FL_USER_VISIBLE;
7043                 err = put_user(flags, (int __user *)arg);
7044                 break;
7045         case REISERFS_IOC_SETFLAGS:{
7046 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7047                                 err = -EFAULT;
7048                                 goto setflags_out;
7049                         }
7050 +                       if (IS_BARRIER(inode)) {
7051 +                               vxwprintk_task(1, "messing with the barrier.");
7052 +                               return -EACCES;
7053 +                       }
7054                         /*
7055                          * Is it quota file? Do not allow user to mess with it
7056                          */
7057 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7058                                         goto setflags_out;
7059                                 }
7060                         }
7061 +
7062 +                       oldflags = REISERFS_I(inode)->i_attrs;
7063 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7064 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7065                         sd_attrs_to_i_attrs(flags, inode);
7066                         REISERFS_I(inode)->i_attrs = flags;
7067                         inode->i_ctime = CURRENT_TIME_SEC;
7068 diff -NurpP --minimal linux-3.2.5/fs/reiserfs/namei.c linux-3.2.5-vs2.3.2.6/fs/reiserfs/namei.c
7069 --- linux-3.2.5/fs/reiserfs/namei.c     2012-01-09 16:14:55.000000000 +0100
7070 +++ linux-3.2.5-vs2.3.2.6/fs/reiserfs/namei.c   2011-12-05 19:33:02.000000000 +0100
7071 @@ -18,6 +18,7 @@
7072  #include <linux/reiserfs_acl.h>
7073  #include <linux/reiserfs_xattr.h>
7074  #include <linux/quotaops.h>
7075 +#include <linux/vs_tag.h>
7076  
7077  #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); }
7078  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7079 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7080         if (retval == IO_ERROR) {
7081                 return ERR_PTR(-EIO);
7082         }
7083 +               dx_propagate_tag(nd, inode);
7084  
7085         return d_splice_alias(inode, dentry);
7086  }
7087 diff -NurpP --minimal linux-3.2.5/fs/reiserfs/super.c linux-3.2.5-vs2.3.2.6/fs/reiserfs/super.c
7088 --- linux-3.2.5/fs/reiserfs/super.c     2012-02-07 01:57:54.000000000 +0100
7089 +++ linux-3.2.5-vs2.3.2.6/fs/reiserfs/super.c   2012-01-18 02:58:07.000000000 +0100
7090 @@ -903,6 +903,14 @@ static int reiserfs_parse_options(struct
7091                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7092                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7093  #endif
7094 +#ifndef CONFIG_TAGGING_NONE
7095 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7096 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7097 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7098 +#endif
7099 +#ifdef CONFIG_PROPAGATE
7100 +               {"tag",.arg_required = 'T',.values = NULL},
7101 +#endif
7102  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7103                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7104                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7105 @@ -1213,6 +1221,14 @@ static int reiserfs_remount(struct super
7106         handle_quota_files(s, qf_names, &qfmt);
7107  #endif
7108  
7109 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7110 +               !(s->s_flags & MS_TAGGED)) {
7111 +               reiserfs_warning(s, "super-vs01",
7112 +                       "reiserfs: tagging not permitted on remount.");
7113 +               err = -EINVAL;
7114 +               goto out_err;
7115 +       }
7116 +
7117         handle_attrs(s);
7118  
7119         /* Add options that are safe here */
7120 @@ -1696,6 +1712,10 @@ static int reiserfs_fill_super(struct su
7121                 goto error;
7122         }
7123  
7124 +       /* map mount option tagxid */
7125 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7126 +               s->s_flags |= MS_TAGGED;
7127 +
7128         rs = SB_DISK_SUPER_BLOCK(s);
7129         /* Let's do basic sanity check to verify that underlying device is not
7130            smaller than the filesystem. If the check fails then abort and scream,
7131 diff -NurpP --minimal linux-3.2.5/fs/reiserfs/xattr.c linux-3.2.5-vs2.3.2.6/fs/reiserfs/xattr.c
7132 --- linux-3.2.5/fs/reiserfs/xattr.c     2011-10-24 18:45:27.000000000 +0200
7133 +++ linux-3.2.5-vs2.3.2.6/fs/reiserfs/xattr.c   2011-12-05 19:33:02.000000000 +0100
7134 @@ -40,6 +40,7 @@
7135  #include <linux/errno.h>
7136  #include <linux/gfp.h>
7137  #include <linux/fs.h>
7138 +#include <linux/mount.h>
7139  #include <linux/file.h>
7140  #include <linux/pagemap.h>
7141  #include <linux/xattr.h>
7142 diff -NurpP --minimal linux-3.2.5/fs/stat.c linux-3.2.5-vs2.3.2.6/fs/stat.c
7143 --- linux-3.2.5/fs/stat.c       2012-01-09 16:14:55.000000000 +0100
7144 +++ linux-3.2.5-vs2.3.2.6/fs/stat.c     2011-12-05 19:33:02.000000000 +0100
7145 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7146         stat->nlink = inode->i_nlink;
7147         stat->uid = inode->i_uid;
7148         stat->gid = inode->i_gid;
7149 +       stat->tag = inode->i_tag;
7150         stat->rdev = inode->i_rdev;
7151         stat->size = i_size_read(inode);
7152         stat->atime = inode->i_atime;
7153 diff -NurpP --minimal linux-3.2.5/fs/statfs.c linux-3.2.5-vs2.3.2.6/fs/statfs.c
7154 --- linux-3.2.5/fs/statfs.c     2012-01-09 16:14:55.000000000 +0100
7155 +++ linux-3.2.5-vs2.3.2.6/fs/statfs.c   2011-12-05 19:33:02.000000000 +0100
7156 @@ -7,6 +7,8 @@
7157  #include <linux/statfs.h>
7158  #include <linux/security.h>
7159  #include <linux/uaccess.h>
7160 +#include <linux/vs_base.h>
7161 +#include <linux/vs_dlimit.h>
7162  
7163  static int flags_by_mnt(int mnt_flags)
7164  {
7165 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7166         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7167         if (retval == 0 && buf->f_frsize == 0)
7168                 buf->f_frsize = buf->f_bsize;
7169 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7170 +               vx_vsi_statfs(dentry->d_sb, buf);
7171         return retval;
7172  }
7173  
7174 diff -NurpP --minimal linux-3.2.5/fs/super.c linux-3.2.5-vs2.3.2.6/fs/super.c
7175 --- linux-3.2.5/fs/super.c      2012-01-09 16:14:55.000000000 +0100
7176 +++ linux-3.2.5-vs2.3.2.6/fs/super.c    2011-12-05 19:33:02.000000000 +0100
7177 @@ -32,6 +32,9 @@
7178  #include <linux/backing-dev.h>
7179  #include <linux/rculist_bl.h>
7180  #include <linux/cleancache.h>
7181 +#include <linux/devpts_fs.h>
7182 +#include <linux/proc_fs.h>
7183 +#include <linux/vs_context.h>
7184  #include "internal.h"
7185  
7186  
7187 @@ -1100,6 +1103,13 @@ mount_fs(struct file_system_type *type, 
7188         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7189         sb->s_flags |= MS_BORN;
7190  
7191 +       error = -EPERM;
7192 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7193 +               !sb->s_bdev &&
7194 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7195 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7196 +               goto out_sb;
7197 +
7198         error = security_sb_kern_mount(sb, flags, secdata);
7199         if (error)
7200                 goto out_sb;
7201 diff -NurpP --minimal linux-3.2.5/fs/sysfs/mount.c linux-3.2.5-vs2.3.2.6/fs/sysfs/mount.c
7202 --- linux-3.2.5/fs/sysfs/mount.c        2011-07-22 11:18:06.000000000 +0200
7203 +++ linux-3.2.5-vs2.3.2.6/fs/sysfs/mount.c      2011-12-05 19:33:02.000000000 +0100
7204 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7205  
7206         sb->s_blocksize = PAGE_CACHE_SIZE;
7207         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7208 -       sb->s_magic = SYSFS_MAGIC;
7209 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7210         sb->s_op = &sysfs_ops;
7211         sb->s_time_gran = 1;
7212  
7213 diff -NurpP --minimal linux-3.2.5/fs/utimes.c linux-3.2.5-vs2.3.2.6/fs/utimes.c
7214 --- linux-3.2.5/fs/utimes.c     2011-05-22 16:17:54.000000000 +0200
7215 +++ linux-3.2.5-vs2.3.2.6/fs/utimes.c   2011-12-05 19:33:02.000000000 +0100
7216 @@ -8,6 +8,8 @@
7217  #include <linux/stat.h>
7218  #include <linux/utime.h>
7219  #include <linux/syscalls.h>
7220 +#include <linux/mount.h>
7221 +#include <linux/vs_cowbl.h>
7222  #include <asm/uaccess.h>
7223  #include <asm/unistd.h>
7224  
7225 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7226  {
7227         int error;
7228         struct iattr newattrs;
7229 -       struct inode *inode = path->dentry->d_inode;
7230 +       struct inode *inode;
7231  
7232         error = mnt_want_write(path->mnt);
7233         if (error)
7234                 goto out;
7235  
7236 +       error = cow_check_and_break(path);
7237 +       if (error)
7238 +               goto mnt_drop_write_and_out;
7239 +
7240 +       inode = path->dentry->d_inode;
7241 +
7242         if (times && times[0].tv_nsec == UTIME_NOW &&
7243                      times[1].tv_nsec == UTIME_NOW)
7244                 times = NULL;
7245 diff -NurpP --minimal linux-3.2.5/fs/xattr.c linux-3.2.5-vs2.3.2.6/fs/xattr.c
7246 --- linux-3.2.5/fs/xattr.c      2012-01-09 16:14:55.000000000 +0100
7247 +++ linux-3.2.5-vs2.3.2.6/fs/xattr.c    2011-12-05 19:33:02.000000000 +0100
7248 @@ -19,6 +19,7 @@
7249  #include <linux/module.h>
7250  #include <linux/fsnotify.h>
7251  #include <linux/audit.h>
7252 +#include <linux/mount.h>
7253  #include <asm/uaccess.h>
7254  
7255  
7256 @@ -50,7 +51,7 @@ xattr_permission(struct inode *inode, co
7257          * The trusted.* namespace can only be accessed by privileged users.
7258          */
7259         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7260 -               if (!capable(CAP_SYS_ADMIN))
7261 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7262                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7263                 return 0;
7264         }
7265 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_dinode.h linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_dinode.h
7266 --- linux-3.2.5/fs/xfs/xfs_dinode.h     2011-10-24 18:45:31.000000000 +0200
7267 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_dinode.h   2011-12-05 19:33:02.000000000 +0100
7268 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7269         __be32          di_nlink;       /* number of links to file */
7270         __be16          di_projid_lo;   /* lower part of owner's project id */
7271         __be16          di_projid_hi;   /* higher part owner's project id */
7272 -       __u8            di_pad[6];      /* unused, zeroed space */
7273 +       __u8            di_pad[2];      /* unused, zeroed space */
7274 +       __be16          di_tag;         /* context tagging */
7275 +       __be16          di_vflags;      /* vserver specific flags */
7276         __be16          di_flushiter;   /* incremented on flush */
7277         xfs_timestamp_t di_atime;       /* time last accessed */
7278         xfs_timestamp_t di_mtime;       /* time last modified */
7279 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7280  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7281  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7282  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7283 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7284 +
7285  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7286  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7287  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7288 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7289  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7290  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7291  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7292 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7293  
7294  #ifdef CONFIG_XFS_RT
7295  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7296 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7297          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7298          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7299          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7300 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7301 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7302 +        XFS_DIFLAG_IXUNLINK)
7303 +
7304 +#define XFS_DIVFLAG_BARRIER    0x01
7305 +#define XFS_DIVFLAG_COW                0x02
7306  
7307  #endif /* __XFS_DINODE_H__ */
7308 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_fs.h linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_fs.h
7309 --- linux-3.2.5/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7310 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_fs.h       2011-12-05 19:33:02.000000000 +0100
7311 @@ -67,6 +67,9 @@ struct fsxattr {
7312  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7313  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7314  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7315 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7316 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7317 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7318  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7319  
7320  /*
7321 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7322  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7323         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7324         __u16           bs_projid_hi;   /* higher part of project id    */
7325 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7326 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7327 +       __u16           bs_tag;         /* context tagging              */
7328         __u32           bs_dmevmask;    /* DMIG event mask              */
7329         __u16           bs_dmstate;     /* DMIG state info              */
7330         __u16           bs_aextents;    /* attribute number of extents  */
7331 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_ialloc.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_ialloc.c
7332 --- linux-3.2.5/fs/xfs/xfs_ialloc.c     2012-01-09 16:14:55.000000000 +0100
7333 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_ialloc.c   2011-12-05 19:33:02.000000000 +0100
7334 @@ -37,7 +37,6 @@
7335  #include "xfs_error.h"
7336  #include "xfs_bmap.h"
7337  
7338 -
7339  /*
7340   * Allocation group level functions.
7341   */
7342 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_inode.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_inode.c
7343 --- linux-3.2.5/fs/xfs/xfs_inode.c      2012-01-09 16:14:55.000000000 +0100
7344 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_inode.c    2011-12-15 01:11:32.000000000 +0100
7345 @@ -236,6 +236,7 @@ xfs_inotobp(
7346         return 0;
7347  }
7348  
7349 +#include <linux/vs_tag.h>
7350  
7351  /*
7352   * This routine is called to map an inode to the buffer containing
7353 @@ -634,15 +635,25 @@ xfs_iformat_btree(
7354  STATIC void
7355  xfs_dinode_from_disk(
7356         xfs_icdinode_t          *to,
7357 -       xfs_dinode_t            *from)
7358 +       xfs_dinode_t            *from,
7359 +       int tagged)
7360  {
7361 +       uint32_t uid, gid, tag;
7362 +
7363         to->di_magic = be16_to_cpu(from->di_magic);
7364         to->di_mode = be16_to_cpu(from->di_mode);
7365         to->di_version = from ->di_version;
7366         to->di_format = from->di_format;
7367         to->di_onlink = be16_to_cpu(from->di_onlink);
7368 -       to->di_uid = be32_to_cpu(from->di_uid);
7369 -       to->di_gid = be32_to_cpu(from->di_gid);
7370 +
7371 +       uid = be32_to_cpu(from->di_uid);
7372 +       gid = be32_to_cpu(from->di_gid);
7373 +       tag = be16_to_cpu(from->di_tag);
7374 +
7375 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7376 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7377 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7378 +
7379         to->di_nlink = be32_to_cpu(from->di_nlink);
7380         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7381         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7382 @@ -664,21 +675,26 @@ xfs_dinode_from_disk(
7383         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7384         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7385         to->di_flags    = be16_to_cpu(from->di_flags);
7386 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7387         to->di_gen      = be32_to_cpu(from->di_gen);
7388  }
7389  
7390  void
7391  xfs_dinode_to_disk(
7392         xfs_dinode_t            *to,
7393 -       xfs_icdinode_t          *from)
7394 +       xfs_icdinode_t          *from,
7395 +       int tagged)
7396  {
7397         to->di_magic = cpu_to_be16(from->di_magic);
7398         to->di_mode = cpu_to_be16(from->di_mode);
7399         to->di_version = from ->di_version;
7400         to->di_format = from->di_format;
7401         to->di_onlink = cpu_to_be16(from->di_onlink);
7402 -       to->di_uid = cpu_to_be32(from->di_uid);
7403 -       to->di_gid = cpu_to_be32(from->di_gid);
7404 +
7405 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7406 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7407 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7408 +
7409         to->di_nlink = cpu_to_be32(from->di_nlink);
7410         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7411         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7412 @@ -700,12 +716,14 @@ xfs_dinode_to_disk(
7413         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7414         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7415         to->di_flags = cpu_to_be16(from->di_flags);
7416 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7417         to->di_gen = cpu_to_be32(from->di_gen);
7418  }
7419  
7420  STATIC uint
7421  _xfs_dic2xflags(
7422 -       __uint16_t              di_flags)
7423 +       __uint16_t              di_flags,
7424 +       __uint16_t              di_vflags)
7425  {
7426         uint                    flags = 0;
7427  
7428 @@ -716,6 +734,8 @@ _xfs_dic2xflags(
7429                         flags |= XFS_XFLAG_PREALLOC;
7430                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7431                         flags |= XFS_XFLAG_IMMUTABLE;
7432 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7433 +                       flags |= XFS_XFLAG_IXUNLINK;
7434                 if (di_flags & XFS_DIFLAG_APPEND)
7435                         flags |= XFS_XFLAG_APPEND;
7436                 if (di_flags & XFS_DIFLAG_SYNC)
7437 @@ -740,6 +760,10 @@ _xfs_dic2xflags(
7438                         flags |= XFS_XFLAG_FILESTREAM;
7439         }
7440  
7441 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7442 +               flags |= FS_BARRIER_FL;
7443 +       if (di_vflags & XFS_DIVFLAG_COW)
7444 +               flags |= FS_COW_FL;
7445         return flags;
7446  }
7447  
7448 @@ -749,7 +773,7 @@ xfs_ip2xflags(
7449  {
7450         xfs_icdinode_t          *dic = &ip->i_d;
7451  
7452 -       return _xfs_dic2xflags(dic->di_flags) |
7453 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7454                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7455  }
7456  
7457 @@ -757,7 +781,8 @@ uint
7458  xfs_dic2xflags(
7459         xfs_dinode_t            *dip)
7460  {
7461 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7462 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7463 +                               be16_to_cpu(dip->di_vflags)) |
7464                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7465  }
7466  
7467 @@ -790,7 +815,6 @@ xfs_iread(
7468         if (error)
7469                 return error;
7470         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7471 -
7472         /*
7473          * If we got something that isn't an inode it means someone
7474          * (nfs or dmi) has a stale handle.
7475 @@ -813,7 +837,8 @@ xfs_iread(
7476          * Otherwise, just get the truly permanent information.
7477          */
7478         if (dip->di_mode) {
7479 -               xfs_dinode_from_disk(&ip->i_d, dip);
7480 +               xfs_dinode_from_disk(&ip->i_d, dip,
7481 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7482                 error = xfs_iformat(ip, dip);
7483                 if (error)  {
7484  #ifdef DEBUG
7485 @@ -1008,6 +1033,7 @@ xfs_ialloc(
7486         ASSERT(ip->i_d.di_nlink == nlink);
7487         ip->i_d.di_uid = current_fsuid();
7488         ip->i_d.di_gid = current_fsgid();
7489 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7490         xfs_set_projid(ip, prid);
7491         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7492  
7493 @@ -1068,6 +1094,7 @@ xfs_ialloc(
7494         ip->i_d.di_dmevmask = 0;
7495         ip->i_d.di_dmstate = 0;
7496         ip->i_d.di_flags = 0;
7497 +       ip->i_d.di_vflags = 0;
7498         flags = XFS_ILOG_CORE;
7499         switch (mode & S_IFMT) {
7500         case S_IFIFO:
7501 @@ -1842,6 +1869,7 @@ xfs_ifree(
7502         }
7503         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7504         ip->i_d.di_flags = 0;
7505 +       ip->i_d.di_vflags = 0;
7506         ip->i_d.di_dmevmask = 0;
7507         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7508         ip->i_df.if_ext_max =
7509 @@ -2723,7 +2751,8 @@ xfs_iflush_int(
7510          * because if the inode is dirty at all the core must
7511          * be.
7512          */
7513 -       xfs_dinode_to_disk(dip, &ip->i_d);
7514 +       xfs_dinode_to_disk(dip, &ip->i_d,
7515 +               mp->m_flags & XFS_MOUNT_TAGGED);
7516  
7517         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7518         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7519 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_inode.h linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_inode.h
7520 --- linux-3.2.5/fs/xfs/xfs_inode.h      2012-01-09 16:14:55.000000000 +0100
7521 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_inode.h    2011-12-15 01:11:32.000000000 +0100
7522 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
7523         __uint32_t      di_nlink;       /* number of links to file */
7524         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7525         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7526 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7527 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7528 +       __uint16_t      di_tag;         /* context tagging */
7529 +       __uint16_t      di_vflags;      /* vserver specific flags */
7530         __uint16_t      di_flushiter;   /* incremented on flush */
7531         xfs_ictimestamp_t di_atime;     /* time last accessed */
7532         xfs_ictimestamp_t di_mtime;     /* time last modified */
7533 @@ -536,7 +538,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7534  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7535                           struct xfs_inode *, uint);
7536  void           xfs_dinode_to_disk(struct xfs_dinode *,
7537 -                                  struct xfs_icdinode *);
7538 +                                  struct xfs_icdinode *, int);
7539  void           xfs_idestroy_fork(struct xfs_inode *, int);
7540  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7541  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7542 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_ioctl.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_ioctl.c
7543 --- linux-3.2.5/fs/xfs/xfs_ioctl.c      2012-01-09 16:14:55.000000000 +0100
7544 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_ioctl.c    2011-12-05 19:33:02.000000000 +0100
7545 @@ -28,7 +28,7 @@
7546  #include "xfs_bmap_btree.h"
7547  #include "xfs_dinode.h"
7548  #include "xfs_inode.h"
7549 -#include "xfs_ioctl.h"
7550 +// #include "xfs_ioctl.h"
7551  #include "xfs_rtalloc.h"
7552  #include "xfs_itable.h"
7553  #include "xfs_error.h"
7554 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7555                 xflags |= XFS_XFLAG_IMMUTABLE;
7556         else
7557                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7558 +       if (flags & FS_IXUNLINK_FL)
7559 +               xflags |= XFS_XFLAG_IXUNLINK;
7560 +       else
7561 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7562         if (flags & FS_APPEND_FL)
7563                 xflags |= XFS_XFLAG_APPEND;
7564         else
7565 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7566  
7567         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7568                 flags |= FS_IMMUTABLE_FL;
7569 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7570 +               flags |= FS_IXUNLINK_FL;
7571         if (di_flags & XFS_DIFLAG_APPEND)
7572                 flags |= FS_APPEND_FL;
7573         if (di_flags & XFS_DIFLAG_SYNC)
7574 @@ -836,6 +842,8 @@ xfs_set_diflags(
7575         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7576         if (xflags & XFS_XFLAG_IMMUTABLE)
7577                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7578 +       if (xflags & XFS_XFLAG_IXUNLINK)
7579 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7580         if (xflags & XFS_XFLAG_APPEND)
7581                 di_flags |= XFS_DIFLAG_APPEND;
7582         if (xflags & XFS_XFLAG_SYNC)
7583 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7584                 inode->i_flags |= S_IMMUTABLE;
7585         else
7586                 inode->i_flags &= ~S_IMMUTABLE;
7587 +       if (xflags & XFS_XFLAG_IXUNLINK)
7588 +               inode->i_flags |= S_IXUNLINK;
7589 +       else
7590 +               inode->i_flags &= ~S_IXUNLINK;
7591         if (xflags & XFS_XFLAG_APPEND)
7592                 inode->i_flags |= S_APPEND;
7593         else
7594 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7595         case XFS_IOC_FSGETXATTRA:
7596                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7597         case XFS_IOC_FSSETXATTR:
7598 +               if (IS_BARRIER(inode)) {
7599 +                       vxwprintk_task(1, "messing with the barrier.");
7600 +                       return -XFS_ERROR(EACCES);
7601 +               }
7602                 return xfs_ioc_fssetxattr(ip, filp, arg);
7603         case XFS_IOC_GETXFLAGS:
7604                 return xfs_ioc_getxflags(ip, arg);
7605         case XFS_IOC_SETXFLAGS:
7606 +               if (IS_BARRIER(inode)) {
7607 +                       vxwprintk_task(1, "messing with the barrier.");
7608 +                       return -XFS_ERROR(EACCES);
7609 +               }
7610                 return xfs_ioc_setxflags(ip, filp, arg);
7611  
7612         case XFS_IOC_FSSETDM: {
7613 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_ioctl.h linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_ioctl.h
7614 --- linux-3.2.5/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7615 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_ioctl.h    2011-12-05 19:33:02.000000000 +0100
7616 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7617         void __user             *uhandle,
7618         u32                     hlen);
7619  
7620 +extern int
7621 +xfs_sync_flags(
7622 +       struct inode            *inode,
7623 +       int                     flags,
7624 +       int                     vflags);
7625 +
7626  extern long
7627  xfs_file_ioctl(
7628         struct file             *filp,
7629 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_iops.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_iops.c
7630 --- linux-3.2.5/fs/xfs/xfs_iops.c       2012-01-09 16:14:55.000000000 +0100
7631 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_iops.c     2011-12-05 19:33:02.000000000 +0100
7632 @@ -30,6 +30,7 @@
7633  #include "xfs_bmap_btree.h"
7634  #include "xfs_dinode.h"
7635  #include "xfs_inode.h"
7636 +#include "xfs_ioctl.h"
7637  #include "xfs_bmap.h"
7638  #include "xfs_rtalloc.h"
7639  #include "xfs_error.h"
7640 @@ -49,6 +50,7 @@
7641  #include <linux/security.h>
7642  #include <linux/fiemap.h>
7643  #include <linux/slab.h>
7644 +#include <linux/vs_tag.h>
7645  
7646  /*
7647   * Bring the timestamps in the XFS inode uptodate.
7648 @@ -474,6 +476,7 @@ xfs_vn_getattr(
7649         stat->nlink = ip->i_d.di_nlink;
7650         stat->uid = ip->i_d.di_uid;
7651         stat->gid = ip->i_d.di_gid;
7652 +       stat->tag = ip->i_d.di_tag;
7653         stat->ino = ip->i_ino;
7654         stat->atime = inode->i_atime;
7655         stat->mtime = inode->i_mtime;
7656 @@ -1039,6 +1042,7 @@ static const struct inode_operations xfs
7657         .removexattr            = generic_removexattr,
7658         .listxattr              = xfs_vn_listxattr,
7659         .fiemap                 = xfs_vn_fiemap,
7660 +       .sync_flags             = xfs_sync_flags,
7661  };
7662  
7663  static const struct inode_operations xfs_dir_inode_operations = {
7664 @@ -1064,6 +1068,7 @@ static const struct inode_operations xfs
7665         .getxattr               = generic_getxattr,
7666         .removexattr            = generic_removexattr,
7667         .listxattr              = xfs_vn_listxattr,
7668 +       .sync_flags             = xfs_sync_flags,
7669  };
7670  
7671  static const struct inode_operations xfs_dir_ci_inode_operations = {
7672 @@ -1113,6 +1118,10 @@ xfs_diflags_to_iflags(
7673                 inode->i_flags |= S_IMMUTABLE;
7674         else
7675                 inode->i_flags &= ~S_IMMUTABLE;
7676 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7677 +               inode->i_flags |= S_IXUNLINK;
7678 +       else
7679 +               inode->i_flags &= ~S_IXUNLINK;
7680         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7681                 inode->i_flags |= S_APPEND;
7682         else
7683 @@ -1125,6 +1134,15 @@ xfs_diflags_to_iflags(
7684                 inode->i_flags |= S_NOATIME;
7685         else
7686                 inode->i_flags &= ~S_NOATIME;
7687 +
7688 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7689 +               inode->i_vflags |= V_BARRIER;
7690 +       else
7691 +               inode->i_vflags &= ~V_BARRIER;
7692 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7693 +               inode->i_vflags |= V_COW;
7694 +       else
7695 +               inode->i_vflags &= ~V_COW;
7696  }
7697  
7698  /*
7699 @@ -1156,6 +1174,7 @@ xfs_setup_inode(
7700         set_nlink(inode, ip->i_d.di_nlink);
7701         inode->i_uid    = ip->i_d.di_uid;
7702         inode->i_gid    = ip->i_d.di_gid;
7703 +       inode->i_tag    = ip->i_d.di_tag;
7704  
7705         switch (inode->i_mode & S_IFMT) {
7706         case S_IFBLK:
7707 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_itable.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_itable.c
7708 --- linux-3.2.5/fs/xfs/xfs_itable.c     2011-05-22 16:17:54.000000000 +0200
7709 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_itable.c   2011-12-05 19:33:02.000000000 +0100
7710 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
7711         buf->bs_mode = dic->di_mode;
7712         buf->bs_uid = dic->di_uid;
7713         buf->bs_gid = dic->di_gid;
7714 +       buf->bs_tag = dic->di_tag;
7715         buf->bs_size = dic->di_size;
7716  
7717         /*
7718 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_linux.h linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_linux.h
7719 --- linux-3.2.5/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7720 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_linux.h    2011-12-05 19:33:02.000000000 +0100
7721 @@ -121,6 +121,7 @@
7722  
7723  #define current_cpu()          (raw_smp_processor_id())
7724  #define current_pid()          (current->pid)
7725 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7726  #define current_test_flags(f)  (current->flags & (f))
7727  #define current_set_flags_nested(sp, f)                \
7728                 (*(sp) = current->flags, current->flags |= (f))
7729 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_log_recover.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_log_recover.c
7730 --- linux-3.2.5/fs/xfs/xfs_log_recover.c        2012-01-09 16:14:55.000000000 +0100
7731 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_log_recover.c      2011-12-05 19:33:02.000000000 +0100
7732 @@ -2344,7 +2344,8 @@ xlog_recover_inode_pass2(
7733         }
7734  
7735         /* The core is in in-core format */
7736 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7737 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7738 +               mp->m_flags & XFS_MOUNT_TAGGED);
7739  
7740         /* the rest is in on-disk format */
7741         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7742 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_mount.h linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_mount.h
7743 --- linux-3.2.5/fs/xfs/xfs_mount.h      2011-10-24 18:45:31.000000000 +0200
7744 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_mount.h    2011-12-05 19:33:02.000000000 +0100
7745 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
7746                                                    allocator */
7747  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7748  
7749 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7750  
7751  /*
7752   * Default minimum read and write sizes.
7753 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_super.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_super.c
7754 --- linux-3.2.5/fs/xfs/xfs_super.c      2012-01-09 16:14:55.000000000 +0100
7755 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_super.c    2012-01-09 16:19:31.000000000 +0100
7756 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7757  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7758  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7759  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7760 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7761 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7762 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7763  
7764  /*
7765   * Table driven mount option parser.
7766 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7767   * in the future, too.
7768   */
7769  enum {
7770 +       Opt_tag, Opt_notag,
7771         Opt_barrier, Opt_nobarrier, Opt_err
7772  };
7773  
7774  static const match_table_t tokens = {
7775 +       {Opt_tag, "tagxid"},
7776 +       {Opt_tag, "tag"},
7777 +       {Opt_notag, "notag"},
7778         {Opt_barrier, "barrier"},
7779         {Opt_nobarrier, "nobarrier"},
7780         {Opt_err, NULL}
7781 @@ -374,6 +381,19 @@ xfs_parseargs(
7782                 } else if (!strcmp(this_char, "irixsgid")) {
7783                         xfs_warn(mp,
7784         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7785 +#ifndef CONFIG_TAGGING_NONE
7786 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7787 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7788 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7789 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7790 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7791 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7792 +#endif
7793 +#ifdef CONFIG_PROPAGATE
7794 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7795 +                       /* use value */
7796 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7797 +#endif
7798                 } else {
7799                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7800                         return EINVAL;
7801 @@ -1138,6 +1158,16 @@ xfs_fs_remount(
7802                 case Opt_nobarrier:
7803                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7804                         break;
7805 +               case Opt_tag:
7806 +                       if (!(sb->s_flags & MS_TAGGED)) {
7807 +                               printk(KERN_INFO
7808 +                                       "XFS: %s: tagging not permitted on remount.\n",
7809 +                                       sb->s_id);
7810 +                               return -EINVAL;
7811 +                       }
7812 +                       break;
7813 +               case Opt_notag:
7814 +                       break;
7815                 default:
7816                         /*
7817                          * Logically we would return an error here to prevent
7818 @@ -1353,6 +1383,9 @@ xfs_fs_fill_super(
7819         if (error)
7820                 goto out_free_sb;
7821  
7822 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7823 +               sb->s_flags |= MS_TAGGED;
7824 +
7825         /*
7826          * we must configure the block size in the superblock before we run the
7827          * full mount process as the mount process can lookup and cache inodes.
7828 diff -NurpP --minimal linux-3.2.5/fs/xfs/xfs_vnodeops.c linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_vnodeops.c
7829 --- linux-3.2.5/fs/xfs/xfs_vnodeops.c   2012-02-07 01:57:54.000000000 +0100
7830 +++ linux-3.2.5-vs2.3.2.6/fs/xfs/xfs_vnodeops.c 2012-02-07 03:14:01.000000000 +0100
7831 @@ -106,6 +106,77 @@ xfs_readlink_bmap(
7832         return error;
7833  }
7834  
7835 +
7836 +STATIC void
7837 +xfs_get_inode_flags(
7838 +       xfs_inode_t     *ip)
7839 +{
7840 +       struct inode    *inode = VFS_I(ip);
7841 +       unsigned int    flags = inode->i_flags;
7842 +       unsigned int    vflags = inode->i_vflags;
7843 +
7844 +       if (flags & S_IMMUTABLE)
7845 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7846 +       else
7847 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7848 +       if (flags & S_IXUNLINK)
7849 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7850 +       else
7851 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7852 +
7853 +       if (vflags & V_BARRIER)
7854 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7855 +       else
7856 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7857 +       if (vflags & V_COW)
7858 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7859 +       else
7860 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7861 +}
7862 +
7863 +int
7864 +xfs_sync_flags(
7865 +       struct inode            *inode,
7866 +       int                     flags,
7867 +       int                     vflags)
7868 +{
7869 +       struct xfs_inode        *ip = XFS_I(inode);
7870 +       struct xfs_mount        *mp = ip->i_mount;
7871 +       struct xfs_trans        *tp;
7872 +       unsigned int            lock_flags = 0;
7873 +       int                     code;
7874 +
7875 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7876 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7877 +       if (code)
7878 +               goto error_out;
7879 +
7880 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7881 +       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
7882 +
7883 +       inode->i_flags = flags;
7884 +       inode->i_vflags = vflags;
7885 +       xfs_get_inode_flags(ip);
7886 +
7887 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7888 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7889 +
7890 +       XFS_STATS_INC(xs_ig_attrchg);
7891 +
7892 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7893 +               xfs_trans_set_sync(tp);
7894 +       code = xfs_trans_commit(tp, 0);
7895 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7896 +       return code;
7897 +
7898 +error_out:
7899 +       xfs_trans_cancel(tp, 0);
7900 +       if (lock_flags)
7901 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7902 +       return code;
7903 +}
7904 +
7905 +
7906  int
7907  xfs_readlink(
7908         xfs_inode_t     *ip,
7909 diff -NurpP --minimal linux-3.2.5/include/linux/Kbuild linux-3.2.5-vs2.3.2.6/include/linux/Kbuild
7910 --- linux-3.2.5/include/linux/Kbuild    2011-10-24 18:45:31.000000000 +0200
7911 +++ linux-3.2.5-vs2.3.2.6/include/linux/Kbuild  2011-12-05 19:33:02.000000000 +0100
7912 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
7913  header-y += netfilter_ipv4/
7914  header-y += netfilter_ipv6/
7915  header-y += usb/
7916 +header-y += vserver/
7917  header-y += wimax/
7918  
7919  objhdr-y += version.h
7920 diff -NurpP --minimal linux-3.2.5/include/linux/capability.h linux-3.2.5-vs2.3.2.6/include/linux/capability.h
7921 --- linux-3.2.5/include/linux/capability.h      2012-01-09 16:14:56.000000000 +0100
7922 +++ linux-3.2.5-vs2.3.2.6/include/linux/capability.h    2011-12-05 19:33:02.000000000 +0100
7923 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7924     arbitrary SCSI commands */
7925  /* Allow setting encryption key on loopback filesystem */
7926  /* Allow setting zone reclaim policy */
7927 +/* Allow the selection of a security context */
7928  
7929  #define CAP_SYS_ADMIN        21
7930  
7931 @@ -363,7 +364,12 @@ struct cpu_vfs_cap_data {
7932  
7933  #define CAP_LAST_CAP         CAP_WAKE_ALARM
7934  
7935 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7936 +/* Allow context manipulations */
7937 +/* Allow changing context info on files */
7938 +
7939 +#define CAP_CONTEXT         63
7940 +
7941 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7942  
7943  /*
7944   * Bit location of each capability (used by user-space library and kernel)
7945 diff -NurpP --minimal linux-3.2.5/include/linux/cred.h linux-3.2.5-vs2.3.2.6/include/linux/cred.h
7946 --- linux-3.2.5/include/linux/cred.h    2011-10-24 18:45:31.000000000 +0200
7947 +++ linux-3.2.5-vs2.3.2.6/include/linux/cred.h  2011-12-05 19:33:02.000000000 +0100
7948 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
7949  extern int copy_creds(struct task_struct *, unsigned long);
7950  extern const struct cred *get_task_cred(struct task_struct *);
7951  extern struct cred *cred_alloc_blank(void);
7952 +extern struct cred *__prepare_creds(const struct cred *);
7953  extern struct cred *prepare_creds(void);
7954  extern struct cred *prepare_exec_creds(void);
7955  extern int commit_creds(struct cred *);
7956 @@ -209,6 +210,31 @@ static inline void validate_process_cred
7957  }
7958  #endif
7959  
7960 +static inline void set_cred_subscribers(struct cred *cred, int n)
7961 +{
7962 +#ifdef CONFIG_DEBUG_CREDENTIALS
7963 +       atomic_set(&cred->subscribers, n);
7964 +#endif
7965 +}
7966 +
7967 +static inline int read_cred_subscribers(const struct cred *cred)
7968 +{
7969 +#ifdef CONFIG_DEBUG_CREDENTIALS
7970 +       return atomic_read(&cred->subscribers);
7971 +#else
7972 +       return 0;
7973 +#endif
7974 +}
7975 +
7976 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7977 +{
7978 +#ifdef CONFIG_DEBUG_CREDENTIALS
7979 +       struct cred *cred = (struct cred *) _cred;
7980 +
7981 +       atomic_add(n, &cred->subscribers);
7982 +#endif
7983 +}
7984 +
7985  /**
7986   * get_new_cred - Get a reference on a new set of credentials
7987   * @cred: The new credentials to reference
7988 diff -NurpP --minimal linux-3.2.5/include/linux/devpts_fs.h linux-3.2.5-vs2.3.2.6/include/linux/devpts_fs.h
7989 --- linux-3.2.5/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
7990 +++ linux-3.2.5-vs2.3.2.6/include/linux/devpts_fs.h     2011-12-05 19:33:02.000000000 +0100
7991 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7992  
7993  #endif
7994  
7995 -
7996  #endif /* _LINUX_DEVPTS_FS_H */
7997 diff -NurpP --minimal linux-3.2.5/include/linux/ext2_fs.h linux-3.2.5-vs2.3.2.6/include/linux/ext2_fs.h
7998 --- linux-3.2.5/include/linux/ext2_fs.h 2012-01-09 16:14:56.000000000 +0100
7999 +++ linux-3.2.5-vs2.3.2.6/include/linux/ext2_fs.h       2011-12-05 19:33:02.000000000 +0100
8000 @@ -190,8 +190,12 @@ struct ext2_group_desc
8001  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8002  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8003  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8004 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8005  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8006  
8007 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8008 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8009 +
8010  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8011  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8012  
8013 @@ -275,7 +279,8 @@ struct ext2_inode {
8014                         __u16   i_pad1;
8015                         __le16  l_i_uid_high;   /* these 2 fields    */
8016                         __le16  l_i_gid_high;   /* were reserved2[0] */
8017 -                       __u32   l_i_reserved2;
8018 +                       __le16  l_i_tag;        /* Context Tag */
8019 +                       __u16   l_i_reserved2;
8020                 } linux2;
8021                 struct {
8022                         __u8    h_i_frag;       /* Fragment number */
8023 @@ -304,6 +309,7 @@ struct ext2_inode {
8024  #define i_gid_low      i_gid
8025  #define i_uid_high     osd2.linux2.l_i_uid_high
8026  #define i_gid_high     osd2.linux2.l_i_gid_high
8027 +#define i_raw_tag      osd2.linux2.l_i_tag
8028  #define i_reserved2    osd2.linux2.l_i_reserved2
8029  #endif
8030  
8031 @@ -348,6 +354,7 @@ struct ext2_inode {
8032  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8033  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8034  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8035 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8036  
8037  
8038  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8039 diff -NurpP --minimal linux-3.2.5/include/linux/ext3_fs.h linux-3.2.5-vs2.3.2.6/include/linux/ext3_fs.h
8040 --- linux-3.2.5/include/linux/ext3_fs.h 2012-01-09 16:14:56.000000000 +0100
8041 +++ linux-3.2.5-vs2.3.2.6/include/linux/ext3_fs.h       2011-12-05 19:33:02.000000000 +0100
8042 @@ -173,10 +173,14 @@ struct ext3_group_desc
8043  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8044  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8045  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8046 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8047  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8048  
8049 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8050 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8051 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8052 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8053 +
8054 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8055 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8056  
8057  /* Flags that should be inherited by new inodes from their parent. */
8058  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8059 @@ -312,7 +316,8 @@ struct ext3_inode {
8060                         __u16   i_pad1;
8061                         __le16  l_i_uid_high;   /* these 2 fields    */
8062                         __le16  l_i_gid_high;   /* were reserved2[0] */
8063 -                       __u32   l_i_reserved2;
8064 +                       __le16  l_i_tag;        /* Context Tag */
8065 +                       __u16   l_i_reserved2;
8066                 } linux2;
8067                 struct {
8068                         __u8    h_i_frag;       /* Fragment number */
8069 @@ -343,6 +348,7 @@ struct ext3_inode {
8070  #define i_gid_low      i_gid
8071  #define i_uid_high     osd2.linux2.l_i_uid_high
8072  #define i_gid_high     osd2.linux2.l_i_gid_high
8073 +#define i_raw_tag      osd2.linux2.l_i_tag
8074  #define i_reserved2    osd2.linux2.l_i_reserved2
8075  
8076  #elif defined(__GNU__)
8077 @@ -405,6 +411,7 @@ struct ext3_inode {
8078  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8079  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8080                                                   * error in ordered mode */
8081 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8082  
8083  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8084  #ifndef _LINUX_EXT2_FS_H
8085 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8086  extern void ext3_set_aops(struct inode *inode);
8087  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8088                        u64 start, u64 len);
8089 +extern int ext3_sync_flags(struct inode *, int, int);
8090  
8091  /* ioctl.c */
8092  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8093 diff -NurpP --minimal linux-3.2.5/include/linux/fs.h linux-3.2.5-vs2.3.2.6/include/linux/fs.h
8094 --- linux-3.2.5/include/linux/fs.h      2012-01-09 16:14:57.000000000 +0100
8095 +++ linux-3.2.5-vs2.3.2.6/include/linux/fs.h    2011-12-15 01:11:32.000000000 +0100
8096 @@ -210,6 +210,9 @@ struct inodes_stat_t {
8097  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8098  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8099  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8100 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8101 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8102 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8103  #define MS_NOSEC       (1<<28)
8104  #define MS_BORN                (1<<29)
8105  #define MS_ACTIVE      (1<<30)
8106 @@ -241,6 +244,14 @@ struct inodes_stat_t {
8107  #define S_IMA          1024    /* Inode has an associated IMA struct */
8108  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8109  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8110 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8111 +
8112 +/* Linux-VServer related Inode flags */
8113 +
8114 +#define V_VALID                1
8115 +#define V_XATTR                2
8116 +#define V_BARRIER      4       /* Barrier for chroot() */
8117 +#define V_COW          8       /* Copy on Write */
8118  
8119  /*
8120   * Note that nosuid etc flags are inode-specific: setting some file-system
8121 @@ -263,12 +274,15 @@ struct inodes_stat_t {
8122  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8123                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8124  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8125 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8126 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8127 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8128 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8129 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8130  
8131  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8132  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8133  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8134 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8135 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8136  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8137  
8138  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8139 @@ -279,6 +293,16 @@ struct inodes_stat_t {
8140  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8141  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8142  
8143 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8144 +
8145 +#ifdef CONFIG_VSERVER_COWBL
8146 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8147 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8148 +#else
8149 +#  define IS_COW(inode)                (0)
8150 +#  define IS_COW_LINK(inode)   (0)
8151 +#endif
8152 +
8153  /* the read-only stuff doesn't really belong here, but any other place is
8154     probably as bad and I don't want to create yet another include file. */
8155  
8156 @@ -364,11 +388,14 @@ struct inodes_stat_t {
8157  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8158  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8159  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8160 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8161  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8162  
8163 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8164 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8165 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8166 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8167  
8168 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8169 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8170  
8171  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8172  #define SYNC_FILE_RANGE_WRITE          2
8173 @@ -449,6 +476,7 @@ typedef void (dio_iodone_t)(struct kiocb
8174  #define ATTR_KILL_PRIV (1 << 14)
8175  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8176  #define ATTR_TIMES_SET (1 << 16)
8177 +#define ATTR_TAG       (1 << 17)
8178  
8179  /*
8180   * This is the Inode Attributes structure, used for notify_change().  It
8181 @@ -464,6 +492,7 @@ struct iattr {
8182         umode_t         ia_mode;
8183         uid_t           ia_uid;
8184         gid_t           ia_gid;
8185 +       tag_t           ia_tag;
8186         loff_t          ia_size;
8187         struct timespec ia_atime;
8188         struct timespec ia_mtime;
8189 @@ -477,6 +506,9 @@ struct iattr {
8190         struct file     *ia_file;
8191  };
8192  
8193 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8194 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8195 +
8196  /*
8197   * Includes for diskquotas.
8198   */
8199 @@ -751,7 +783,9 @@ struct inode {
8200         unsigned short          i_opflags;
8201         uid_t                   i_uid;
8202         gid_t                   i_gid;
8203 -       unsigned int            i_flags;
8204 +       tag_t                   i_tag;
8205 +       unsigned short          i_flags;
8206 +       unsigned short          i_vflags;
8207  
8208  #ifdef CONFIG_FS_POSIX_ACL
8209         struct posix_acl        *i_acl;
8210 @@ -780,6 +814,7 @@ struct inode {
8211                 unsigned int __i_nlink;
8212         };
8213         dev_t                   i_rdev;
8214 +       dev_t                   i_mdev;
8215         struct timespec         i_atime;
8216         struct timespec         i_mtime;
8217         struct timespec         i_ctime;
8218 @@ -917,12 +952,12 @@ static inline void i_size_write(struct i
8219  
8220  static inline unsigned iminor(const struct inode *inode)
8221  {
8222 -       return MINOR(inode->i_rdev);
8223 +       return MINOR(inode->i_mdev);
8224  }
8225  
8226  static inline unsigned imajor(const struct inode *inode)
8227  {
8228 -       return MAJOR(inode->i_rdev);
8229 +       return MAJOR(inode->i_mdev);
8230  }
8231  
8232  extern struct block_device *I_BDEV(struct inode *inode);
8233 @@ -989,6 +1024,7 @@ struct file {
8234         loff_t                  f_pos;
8235         struct fown_struct      f_owner;
8236         const struct cred       *f_cred;
8237 +       xid_t                   f_xid;
8238         struct file_ra_state    f_ra;
8239  
8240         u64                     f_version;
8241 @@ -1135,6 +1171,7 @@ struct file_lock {
8242         struct file *fl_file;
8243         loff_t fl_start;
8244         loff_t fl_end;
8245 +       xid_t fl_xid;
8246  
8247         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8248         /* for lease breaks: */
8249 @@ -1635,6 +1672,7 @@ struct inode_operations {
8250         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8251         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8252         int (*removexattr) (struct dentry *, const char *);
8253 +       int (*sync_flags) (struct inode *, int, int);
8254         void (*truncate_range)(struct inode *, loff_t, loff_t);
8255         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8256                       u64 len);
8257 @@ -1654,6 +1692,7 @@ extern ssize_t vfs_readv(struct file *, 
8258                 unsigned long, loff_t *);
8259  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8260                 unsigned long, loff_t *);
8261 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8262  
8263  struct super_operations {
8264         struct inode *(*alloc_inode)(struct super_block *sb);
8265 @@ -2541,6 +2580,7 @@ extern int dcache_dir_open(struct inode 
8266  extern int dcache_dir_close(struct inode *, struct file *);
8267  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8268  extern int dcache_readdir(struct file *, void *, filldir_t);
8269 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8270  extern int simple_setattr(struct dentry *, struct iattr *);
8271  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8272  extern int simple_statfs(struct dentry *, struct kstatfs *);
8273 diff -NurpP --minimal linux-3.2.5/include/linux/gfs2_ondisk.h linux-3.2.5-vs2.3.2.6/include/linux/gfs2_ondisk.h
8274 --- linux-3.2.5/include/linux/gfs2_ondisk.h     2010-07-07 18:31:55.000000000 +0200
8275 +++ linux-3.2.5-vs2.3.2.6/include/linux/gfs2_ondisk.h   2011-12-05 19:33:02.000000000 +0100
8276 @@ -211,6 +211,9 @@ enum {
8277         gfs2fl_NoAtime          = 7,
8278         gfs2fl_Sync             = 8,
8279         gfs2fl_System           = 9,
8280 +       gfs2fl_IXUnlink         = 16,
8281 +       gfs2fl_Barrier          = 17,
8282 +       gfs2fl_Cow              = 18,
8283         gfs2fl_TruncInProg      = 29,
8284         gfs2fl_InheritDirectio  = 30,
8285         gfs2fl_InheritJdata     = 31,
8286 @@ -227,6 +230,9 @@ enum {
8287  #define GFS2_DIF_NOATIME               0x00000080
8288  #define GFS2_DIF_SYNC                  0x00000100
8289  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8290 +#define GFS2_DIF_IXUNLINK              0x00010000
8291 +#define GFS2_DIF_BARRIER               0x00020000
8292 +#define GFS2_DIF_COW                   0x00040000
8293  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8294  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8295  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8296 diff -NurpP --minimal linux-3.2.5/include/linux/if_tun.h linux-3.2.5-vs2.3.2.6/include/linux/if_tun.h
8297 --- linux-3.2.5/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8298 +++ linux-3.2.5-vs2.3.2.6/include/linux/if_tun.h        2011-12-05 19:33:02.000000000 +0100
8299 @@ -53,6 +53,7 @@
8300  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8301  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8302  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8303 +#define TUNSETNID     _IOW('T', 217, int)
8304  
8305  /* TUNSETIFF ifr flags */
8306  #define IFF_TUN                0x0001
8307 diff -NurpP --minimal linux-3.2.5/include/linux/init_task.h linux-3.2.5-vs2.3.2.6/include/linux/init_task.h
8308 --- linux-3.2.5/include/linux/init_task.h       2012-01-09 16:14:58.000000000 +0100
8309 +++ linux-3.2.5-vs2.3.2.6/include/linux/init_task.h     2011-12-15 01:11:32.000000000 +0100
8310 @@ -193,6 +193,10 @@ extern struct cred init_cred;
8311         INIT_FTRACE_GRAPH                                               \
8312         INIT_TRACE_RECURSION                                            \
8313         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8314 +       .xid            = 0,                                            \
8315 +       .vx_info        = NULL,                                         \
8316 +       .nid            = 0,                                            \
8317 +       .nx_info        = NULL,                                         \
8318  }
8319  
8320  
8321 diff -NurpP --minimal linux-3.2.5/include/linux/ipc.h linux-3.2.5-vs2.3.2.6/include/linux/ipc.h
8322 --- linux-3.2.5/include/linux/ipc.h     2009-12-03 20:02:55.000000000 +0100
8323 +++ linux-3.2.5-vs2.3.2.6/include/linux/ipc.h   2011-12-05 19:33:02.000000000 +0100
8324 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8325         key_t           key;
8326         uid_t           uid;
8327         gid_t           gid;
8328 +       xid_t           xid;
8329         uid_t           cuid;
8330         gid_t           cgid;
8331         mode_t          mode; 
8332 diff -NurpP --minimal linux-3.2.5/include/linux/ipc_namespace.h linux-3.2.5-vs2.3.2.6/include/linux/ipc_namespace.h
8333 --- linux-3.2.5/include/linux/ipc_namespace.h   2011-10-24 18:45:32.000000000 +0200
8334 +++ linux-3.2.5-vs2.3.2.6/include/linux/ipc_namespace.h 2011-12-05 19:33:02.000000000 +0100
8335 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8336  
8337  #if defined(CONFIG_IPC_NS)
8338  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8339 -                                      struct task_struct *tsk);
8340 +                                      struct ipc_namespace *old_ns,
8341 +                                      struct user_namespace *user_ns);
8342  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8343  {
8344         if (ns)
8345 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8346  extern void put_ipc_ns(struct ipc_namespace *ns);
8347  #else
8348  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8349 -                                             struct task_struct *tsk)
8350 +                                             struct ipc_namespace *old_ns,
8351 +                                             struct user_namespace *user_ns)
8352  {
8353         if (flags & CLONE_NEWIPC)
8354                 return ERR_PTR(-EINVAL);
8355  
8356 -       return tsk->nsproxy->ipc_ns;
8357 +       return old_ns;
8358  }
8359  
8360  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8361 diff -NurpP --minimal linux-3.2.5/include/linux/loop.h linux-3.2.5-vs2.3.2.6/include/linux/loop.h
8362 --- linux-3.2.5/include/linux/loop.h    2012-01-09 16:14:58.000000000 +0100
8363 +++ linux-3.2.5-vs2.3.2.6/include/linux/loop.h  2011-12-05 19:33:02.000000000 +0100
8364 @@ -45,6 +45,7 @@ struct loop_device {
8365         struct loop_func_table *lo_encryption;
8366         __u32           lo_init[2];
8367         uid_t           lo_key_owner;   /* Who set the key */
8368 +       xid_t           lo_xid;
8369         int             (*ioctl)(struct loop_device *, int cmd, 
8370                                  unsigned long arg); 
8371  
8372 diff -NurpP --minimal linux-3.2.5/include/linux/magic.h linux-3.2.5-vs2.3.2.6/include/linux/magic.h
8373 --- linux-3.2.5/include/linux/magic.h   2012-01-09 16:14:58.000000000 +0100
8374 +++ linux-3.2.5-vs2.3.2.6/include/linux/magic.h 2011-12-05 19:33:02.000000000 +0100
8375 @@ -3,7 +3,7 @@
8376  
8377  #define ADFS_SUPER_MAGIC       0xadf5
8378  #define AFFS_SUPER_MAGIC       0xadff
8379 -#define AFS_SUPER_MAGIC                0x5346414F
8380 +#define AFS_SUPER_MAGIC                0x5346414F
8381  #define AUTOFS_SUPER_MAGIC     0x0187
8382  #define CODA_SUPER_MAGIC       0x73757245
8383  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8384 @@ -41,6 +41,7 @@
8385  #define NFS_SUPER_MAGIC                0x6969
8386  #define OPENPROM_SUPER_MAGIC   0x9fa1
8387  #define PROC_SUPER_MAGIC       0x9fa0
8388 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8389  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8390  
8391  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8392 diff -NurpP --minimal linux-3.2.5/include/linux/major.h linux-3.2.5-vs2.3.2.6/include/linux/major.h
8393 --- linux-3.2.5/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8394 +++ linux-3.2.5-vs2.3.2.6/include/linux/major.h 2011-12-05 19:33:02.000000000 +0100
8395 @@ -15,6 +15,7 @@
8396  #define HD_MAJOR               IDE0_MAJOR
8397  #define PTY_SLAVE_MAJOR                3
8398  #define TTY_MAJOR              4
8399 +#define VROOT_MAJOR            4
8400  #define TTYAUX_MAJOR           5
8401  #define LP_MAJOR               6
8402  #define VCS_MAJOR              7
8403 diff -NurpP --minimal linux-3.2.5/include/linux/memcontrol.h linux-3.2.5-vs2.3.2.6/include/linux/memcontrol.h
8404 --- linux-3.2.5/include/linux/memcontrol.h      2012-02-07 01:57:55.000000000 +0100
8405 +++ linux-3.2.5-vs2.3.2.6/include/linux/memcontrol.h    2012-01-26 08:52:10.000000000 +0100
8406 @@ -85,6 +85,13 @@ extern struct mem_cgroup *try_get_mem_cg
8407  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8408  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
8409  
8410 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8411 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8412 +
8413 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8414 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8415 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8416 +
8417  static inline
8418  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8419  {
8420 diff -NurpP --minimal linux-3.2.5/include/linux/mm_types.h linux-3.2.5-vs2.3.2.6/include/linux/mm_types.h
8421 --- linux-3.2.5/include/linux/mm_types.h        2012-01-09 16:14:58.000000000 +0100
8422 +++ linux-3.2.5-vs2.3.2.6/include/linux/mm_types.h      2011-12-05 19:33:02.000000000 +0100
8423 @@ -344,6 +344,7 @@ struct mm_struct {
8424  
8425         /* Architecture-specific MM context */
8426         mm_context_t context;
8427 +       struct vx_info *mm_vx_info;
8428  
8429         /* Swap token stuff */
8430         /*
8431 diff -NurpP --minimal linux-3.2.5/include/linux/mmzone.h linux-3.2.5-vs2.3.2.6/include/linux/mmzone.h
8432 --- linux-3.2.5/include/linux/mmzone.h  2012-01-09 16:14:58.000000000 +0100
8433 +++ linux-3.2.5-vs2.3.2.6/include/linux/mmzone.h        2011-12-05 19:33:02.000000000 +0100
8434 @@ -673,6 +673,13 @@ typedef struct pglist_data {
8435         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8436  })
8437  
8438 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8439 +
8440 +#define node_end_pfn(nid) ({\
8441 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8442 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8443 +})
8444 +
8445  #include <linux/memory_hotplug.h>
8446  
8447  extern struct mutex zonelists_mutex;
8448 diff -NurpP --minimal linux-3.2.5/include/linux/mount.h linux-3.2.5-vs2.3.2.6/include/linux/mount.h
8449 --- linux-3.2.5/include/linux/mount.h   2011-10-24 18:45:32.000000000 +0200
8450 +++ linux-3.2.5-vs2.3.2.6/include/linux/mount.h 2011-12-05 19:33:02.000000000 +0100
8451 @@ -52,6 +52,9 @@ struct mnt_pcp {
8452         int mnt_writers;
8453  };
8454  
8455 +#define MNT_TAGID      0x10000
8456 +#define MNT_NOTAG      0x20000
8457 +
8458  struct vfsmount {
8459         struct list_head mnt_hash;
8460         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8461 @@ -86,6 +89,7 @@ struct vfsmount {
8462         int mnt_expiry_mark;            /* true if marked for expiry */
8463         int mnt_pinned;
8464         int mnt_ghosts;
8465 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8466  };
8467  
8468  struct file; /* forward dec */
8469 diff -NurpP --minimal linux-3.2.5/include/linux/net.h linux-3.2.5-vs2.3.2.6/include/linux/net.h
8470 --- linux-3.2.5/include/linux/net.h     2011-07-22 11:18:11.000000000 +0200
8471 +++ linux-3.2.5-vs2.3.2.6/include/linux/net.h   2011-12-05 19:33:02.000000000 +0100
8472 @@ -72,6 +72,7 @@ struct net;
8473  #define SOCK_NOSPACE           2
8474  #define SOCK_PASSCRED          3
8475  #define SOCK_PASSSEC           4
8476 +#define SOCK_USER_SOCKET       5
8477  
8478  #ifndef ARCH_HAS_SOCKET_TYPES
8479  /**
8480 diff -NurpP --minimal linux-3.2.5/include/linux/netdevice.h linux-3.2.5-vs2.3.2.6/include/linux/netdevice.h
8481 --- linux-3.2.5/include/linux/netdevice.h       2012-01-09 16:14:58.000000000 +0100
8482 +++ linux-3.2.5-vs2.3.2.6/include/linux/netdevice.h     2011-12-15 01:11:33.000000000 +0100
8483 @@ -1646,6 +1646,7 @@ extern void               netdev_resync_ops(struct ne
8484  
8485  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8486  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8487 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8488  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8489  extern int             dev_restart(struct net_device *dev);
8490  #ifdef CONFIG_NETPOLL_TRAP
8491 diff -NurpP --minimal linux-3.2.5/include/linux/nfs_mount.h linux-3.2.5-vs2.3.2.6/include/linux/nfs_mount.h
8492 --- linux-3.2.5/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8493 +++ linux-3.2.5-vs2.3.2.6/include/linux/nfs_mount.h     2011-12-05 19:33:02.000000000 +0100
8494 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8495  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8496  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8497  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8498 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8499 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8500 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8501  
8502  /* The following are for internal use only */
8503  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8504 diff -NurpP --minimal linux-3.2.5/include/linux/nsproxy.h linux-3.2.5-vs2.3.2.6/include/linux/nsproxy.h
8505 --- linux-3.2.5/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8506 +++ linux-3.2.5-vs2.3.2.6/include/linux/nsproxy.h       2011-12-05 19:33:02.000000000 +0100
8507 @@ -3,6 +3,7 @@
8508  
8509  #include <linux/spinlock.h>
8510  #include <linux/sched.h>
8511 +#include <linux/vserver/debug.h>
8512  
8513  struct mnt_namespace;
8514  struct uts_namespace;
8515 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8516  }
8517  
8518  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8519 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8520  void exit_task_namespaces(struct task_struct *tsk);
8521  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8522  void free_nsproxy(struct nsproxy *ns);
8523 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8524         struct fs_struct *);
8525  int __init nsproxy_cache_init(void);
8526  
8527 -static inline void put_nsproxy(struct nsproxy *ns)
8528 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8529 +
8530 +static inline void __get_nsproxy(struct nsproxy *ns,
8531 +       const char *_file, int _line)
8532  {
8533 -       if (atomic_dec_and_test(&ns->count)) {
8534 -               free_nsproxy(ns);
8535 -       }
8536 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8537 +               ns, atomic_read(&ns->count), _file, _line);
8538 +       atomic_inc(&ns->count);
8539  }
8540  
8541 -static inline void get_nsproxy(struct nsproxy *ns)
8542 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8543 +
8544 +static inline void __put_nsproxy(struct nsproxy *ns,
8545 +       const char *_file, int _line)
8546  {
8547 -       atomic_inc(&ns->count);
8548 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8549 +               ns, atomic_read(&ns->count), _file, _line);
8550 +       if (atomic_dec_and_test(&ns->count)) {
8551 +               free_nsproxy(ns);
8552 +       }
8553  }
8554  
8555  #endif
8556 diff -NurpP --minimal linux-3.2.5/include/linux/pid.h linux-3.2.5-vs2.3.2.6/include/linux/pid.h
8557 --- linux-3.2.5/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8558 +++ linux-3.2.5-vs2.3.2.6/include/linux/pid.h   2011-12-05 19:33:02.000000000 +0100
8559 @@ -8,7 +8,8 @@ enum pid_type
8560         PIDTYPE_PID,
8561         PIDTYPE_PGID,
8562         PIDTYPE_SID,
8563 -       PIDTYPE_MAX
8564 +       PIDTYPE_MAX,
8565 +       PIDTYPE_REALPID
8566  };
8567  
8568  /*
8569 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8570  }
8571  
8572  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8573 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8574  pid_t pid_vnr(struct pid *pid);
8575  
8576  #define do_each_pid_task(pid, type, task)                              \
8577 diff -NurpP --minimal linux-3.2.5/include/linux/proc_fs.h linux-3.2.5-vs2.3.2.6/include/linux/proc_fs.h
8578 --- linux-3.2.5/include/linux/proc_fs.h 2011-10-24 18:45:32.000000000 +0200
8579 +++ linux-3.2.5-vs2.3.2.6/include/linux/proc_fs.h       2011-12-05 19:33:02.000000000 +0100
8580 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8581         nlink_t nlink;
8582         uid_t uid;
8583         gid_t gid;
8584 +       int vx_flags;
8585         loff_t size;
8586         const struct inode_operations *proc_iops;
8587         /*
8588 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8589  extern const struct proc_ns_operations utsns_operations;
8590  extern const struct proc_ns_operations ipcns_operations;
8591  
8592 +struct vx_info;
8593 +struct nx_info;
8594 +
8595  union proc_op {
8596         int (*proc_get_link)(struct inode *, struct path *);
8597         int (*proc_read)(struct task_struct *task, char *page);
8598         int (*proc_show)(struct seq_file *m,
8599                 struct pid_namespace *ns, struct pid *pid,
8600                 struct task_struct *task);
8601 +       int (*proc_vs_read)(char *page);
8602 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8603 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8604  };
8605  
8606  struct ctl_table_header;
8607 @@ -265,6 +272,7 @@ struct ctl_table;
8608  
8609  struct proc_inode {
8610         struct pid *pid;
8611 +       int vx_flags;
8612         int fd;
8613         union proc_op op;
8614         struct proc_dir_entry *pde;
8615 diff -NurpP --minimal linux-3.2.5/include/linux/quotaops.h linux-3.2.5-vs2.3.2.6/include/linux/quotaops.h
8616 --- linux-3.2.5/include/linux/quotaops.h        2012-01-09 16:14:58.000000000 +0100
8617 +++ linux-3.2.5-vs2.3.2.6/include/linux/quotaops.h      2011-12-05 19:33:02.000000000 +0100
8618 @@ -8,6 +8,7 @@
8619  #define _LINUX_QUOTAOPS_
8620  
8621  #include <linux/fs.h>
8622 +#include <linux/vs_dlimit.h>
8623  
8624  #define DQUOT_SPACE_WARN       0x1
8625  #define DQUOT_SPACE_RESERVE    0x2
8626 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8627  
8628  static inline int dquot_alloc_inode(const struct inode *inode)
8629  {
8630 -       return 0;
8631 +       return dl_alloc_inode(inode);
8632  }
8633  
8634  static inline void dquot_free_inode(const struct inode *inode)
8635  {
8636 +       dl_free_inode(inode);
8637  }
8638  
8639  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8640 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8641  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8642                 int flags)
8643  {
8644 +       int ret = 0;
8645 +
8646 +       if ((ret = dl_alloc_space(inode, number)))
8647 +               return ret;
8648         if (!(flags & DQUOT_SPACE_RESERVE))
8649                 inode_add_bytes(inode, number);
8650         return 0;
8651 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8652  {
8653         if (!(flags & DQUOT_SPACE_RESERVE))
8654                 inode_sub_bytes(inode, number);
8655 +       dl_free_space(inode, number);
8656  }
8657  
8658  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8659 diff -NurpP --minimal linux-3.2.5/include/linux/reboot.h linux-3.2.5-vs2.3.2.6/include/linux/reboot.h
8660 --- linux-3.2.5/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8661 +++ linux-3.2.5-vs2.3.2.6/include/linux/reboot.h        2011-12-05 19:33:02.000000000 +0100
8662 @@ -33,6 +33,7 @@
8663  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8664  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8665  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8666 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8667  
8668  
8669  #ifdef __KERNEL__
8670 diff -NurpP --minimal linux-3.2.5/include/linux/reiserfs_fs.h linux-3.2.5-vs2.3.2.6/include/linux/reiserfs_fs.h
8671 --- linux-3.2.5/include/linux/reiserfs_fs.h     2011-10-24 18:45:32.000000000 +0200
8672 +++ linux-3.2.5-vs2.3.2.6/include/linux/reiserfs_fs.h   2011-12-05 19:33:02.000000000 +0100
8673 @@ -976,6 +976,11 @@ struct stat_data_v1 {
8674  #define REISERFS_COMPR_FL     FS_COMPR_FL
8675  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8676  
8677 +/* unfortunately reiserfs sdattr is only 16 bit */
8678 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8679 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8680 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8681 +
8682  /* persistent flags that file inherits from the parent directory */
8683  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8684                                 REISERFS_SYNC_FL |      \
8685 @@ -985,6 +990,9 @@ struct stat_data_v1 {
8686                                 REISERFS_COMPR_FL |     \
8687                                 REISERFS_NOTAIL_FL )
8688  
8689 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8690 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8691 +
8692  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8693     address blocks) */
8694  struct stat_data {
8695 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
8696  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8697  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8698  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8699 +int reiserfs_sync_flags(struct inode *inode, int, int);
8700  
8701  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
8702  
8703 diff -NurpP --minimal linux-3.2.5/include/linux/reiserfs_fs_sb.h linux-3.2.5-vs2.3.2.6/include/linux/reiserfs_fs_sb.h
8704 --- linux-3.2.5/include/linux/reiserfs_fs_sb.h  2010-02-25 11:52:07.000000000 +0100
8705 +++ linux-3.2.5-vs2.3.2.6/include/linux/reiserfs_fs_sb.h        2011-12-05 19:33:02.000000000 +0100
8706 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
8707         REISERFS_EXPOSE_PRIVROOT,
8708         REISERFS_BARRIER_NONE,
8709         REISERFS_BARRIER_FLUSH,
8710 +       REISERFS_TAGGED,
8711  
8712         /* Actions on error */
8713         REISERFS_ERROR_PANIC,
8714 diff -NurpP --minimal linux-3.2.5/include/linux/sched.h linux-3.2.5-vs2.3.2.6/include/linux/sched.h
8715 --- linux-3.2.5/include/linux/sched.h   2012-01-09 16:14:58.000000000 +0100
8716 +++ linux-3.2.5-vs2.3.2.6/include/linux/sched.h 2011-12-05 19:33:02.000000000 +0100
8717 @@ -1403,6 +1403,14 @@ struct task_struct {
8718  #endif
8719         seccomp_t seccomp;
8720  
8721 +/* vserver context data */
8722 +       struct vx_info *vx_info;
8723 +       struct nx_info *nx_info;
8724 +
8725 +       xid_t xid;
8726 +       nid_t nid;
8727 +       tag_t tag;
8728 +
8729  /* Thread group tracking */
8730         u32 parent_exec_id;
8731         u32 self_exec_id;
8732 @@ -1651,6 +1659,11 @@ struct pid_namespace;
8733  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8734                         struct pid_namespace *ns);
8735  
8736 +#include <linux/vserver/base.h>
8737 +#include <linux/vserver/context.h>
8738 +#include <linux/vserver/debug.h>
8739 +#include <linux/vserver/pid.h>
8740 +
8741  static inline pid_t task_pid_nr(struct task_struct *tsk)
8742  {
8743         return tsk->pid;
8744 @@ -1664,7 +1677,8 @@ static inline pid_t task_pid_nr_ns(struc
8745  
8746  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8747  {
8748 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8749 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8750 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8751  }
8752  
8753  
8754 @@ -1677,7 +1691,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8755  
8756  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8757  {
8758 -       return pid_vnr(task_tgid(tsk));
8759 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8760  }
8761  
8762  
8763 diff -NurpP --minimal linux-3.2.5/include/linux/shmem_fs.h linux-3.2.5-vs2.3.2.6/include/linux/shmem_fs.h
8764 --- linux-3.2.5/include/linux/shmem_fs.h        2012-02-07 01:57:55.000000000 +0100
8765 +++ linux-3.2.5-vs2.3.2.6/include/linux/shmem_fs.h      2012-01-26 08:52:10.000000000 +0100
8766 @@ -8,6 +8,9 @@
8767  
8768  /* inode in-kernel data */
8769  
8770 +#define TMPFS_SUPER_MAGIC      0x01021994
8771 +
8772 +
8773  struct shmem_inode_info {
8774         spinlock_t              lock;
8775         unsigned long           flags;
8776 diff -NurpP --minimal linux-3.2.5/include/linux/stat.h linux-3.2.5-vs2.3.2.6/include/linux/stat.h
8777 --- linux-3.2.5/include/linux/stat.h    2008-12-25 00:26:37.000000000 +0100
8778 +++ linux-3.2.5-vs2.3.2.6/include/linux/stat.h  2011-12-05 19:33:02.000000000 +0100
8779 @@ -66,6 +66,7 @@ struct kstat {
8780         unsigned int    nlink;
8781         uid_t           uid;
8782         gid_t           gid;
8783 +       tag_t           tag;
8784         dev_t           rdev;
8785         loff_t          size;
8786         struct timespec  atime;
8787 diff -NurpP --minimal linux-3.2.5/include/linux/sunrpc/auth.h linux-3.2.5-vs2.3.2.6/include/linux/sunrpc/auth.h
8788 --- linux-3.2.5/include/linux/sunrpc/auth.h     2011-10-24 18:45:32.000000000 +0200
8789 +++ linux-3.2.5-vs2.3.2.6/include/linux/sunrpc/auth.h   2011-12-05 19:33:02.000000000 +0100
8790 @@ -25,6 +25,7 @@
8791  struct auth_cred {
8792         uid_t   uid;
8793         gid_t   gid;
8794 +       tag_t   tag;
8795         struct group_info *group_info;
8796         unsigned char machine_cred : 1;
8797  };
8798 diff -NurpP --minimal linux-3.2.5/include/linux/sunrpc/clnt.h linux-3.2.5-vs2.3.2.6/include/linux/sunrpc/clnt.h
8799 --- linux-3.2.5/include/linux/sunrpc/clnt.h     2012-01-09 16:14:58.000000000 +0100
8800 +++ linux-3.2.5-vs2.3.2.6/include/linux/sunrpc/clnt.h   2011-12-05 19:33:02.000000000 +0100
8801 @@ -50,7 +50,8 @@ struct rpc_clnt {
8802         unsigned int            cl_softrtry : 1,/* soft timeouts */
8803                                 cl_discrtry : 1,/* disconnect before retry */
8804                                 cl_autobind : 1,/* use getport() */
8805 -                               cl_chatty   : 1;/* be verbose */
8806 +                               cl_chatty   : 1,/* be verbose */
8807 +                               cl_tag      : 1;/* context tagging */
8808  
8809         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8810         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8811 diff -NurpP --minimal linux-3.2.5/include/linux/syscalls.h linux-3.2.5-vs2.3.2.6/include/linux/syscalls.h
8812 --- linux-3.2.5/include/linux/syscalls.h        2012-01-09 16:14:58.000000000 +0100
8813 +++ linux-3.2.5-vs2.3.2.6/include/linux/syscalls.h      2011-12-05 19:33:02.000000000 +0100
8814 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
8815  asmlinkage long sys_unlink(const char __user *pathname);
8816  asmlinkage long sys_rename(const char __user *oldname,
8817                                 const char __user *newname);
8818 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
8819 +                               umode_t mode);
8820  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
8821  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
8822  
8823 diff -NurpP --minimal linux-3.2.5/include/linux/sysctl.h linux-3.2.5-vs2.3.2.6/include/linux/sysctl.h
8824 --- linux-3.2.5/include/linux/sysctl.h  2012-01-09 16:14:58.000000000 +0100
8825 +++ linux-3.2.5-vs2.3.2.6/include/linux/sysctl.h        2011-12-05 19:33:02.000000000 +0100
8826 @@ -60,6 +60,7 @@ enum
8827         CTL_ABI=9,              /* Binary emulation */
8828         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8829         CTL_ARLAN=254,          /* arlan wireless driver */
8830 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8831         CTL_S390DBF=5677,       /* s390 debug */
8832         CTL_SUNRPC=7249,        /* sunrpc debug */
8833         CTL_PM=9899,            /* frv power management */
8834 @@ -94,6 +95,7 @@ enum
8835  
8836         KERN_PANIC=15,          /* int: panic timeout */
8837         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8838 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8839  
8840         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8841         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8842 diff -NurpP --minimal linux-3.2.5/include/linux/sysfs.h linux-3.2.5-vs2.3.2.6/include/linux/sysfs.h
8843 --- linux-3.2.5/include/linux/sysfs.h   2012-01-09 16:14:58.000000000 +0100
8844 +++ linux-3.2.5-vs2.3.2.6/include/linux/sysfs.h 2011-12-05 19:33:02.000000000 +0100
8845 @@ -19,6 +19,8 @@
8846  #include <linux/kobject_ns.h>
8847  #include <linux/atomic.h>
8848  
8849 +#define SYSFS_SUPER_MAGIC      0x62656572
8850 +
8851  struct kobject;
8852  struct module;
8853  enum kobj_ns_type;
8854 diff -NurpP --minimal linux-3.2.5/include/linux/time.h linux-3.2.5-vs2.3.2.6/include/linux/time.h
8855 --- linux-3.2.5/include/linux/time.h    2011-07-22 11:18:11.000000000 +0200
8856 +++ linux-3.2.5-vs2.3.2.6/include/linux/time.h  2011-12-05 19:33:02.000000000 +0100
8857 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
8858         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
8859         a->tv_nsec = ns;
8860  }
8861 +
8862 +#include <linux/vs_time.h>
8863 +
8864  #endif /* __KERNEL__ */
8865  
8866  #define NFDBITS                        __NFDBITS
8867 diff -NurpP --minimal linux-3.2.5/include/linux/types.h linux-3.2.5-vs2.3.2.6/include/linux/types.h
8868 --- linux-3.2.5/include/linux/types.h   2012-01-09 16:14:59.000000000 +0100
8869 +++ linux-3.2.5-vs2.3.2.6/include/linux/types.h 2011-12-05 19:33:02.000000000 +0100
8870 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
8871  typedef __kernel_gid32_t       gid_t;
8872  typedef __kernel_uid16_t        uid16_t;
8873  typedef __kernel_gid16_t        gid16_t;
8874 +typedef unsigned int           xid_t;
8875 +typedef unsigned int           nid_t;
8876 +typedef unsigned int           tag_t;
8877  
8878  typedef unsigned long          uintptr_t;
8879  
8880 diff -NurpP --minimal linux-3.2.5/include/linux/utsname.h linux-3.2.5-vs2.3.2.6/include/linux/utsname.h
8881 --- linux-3.2.5/include/linux/utsname.h 2012-01-09 16:14:59.000000000 +0100
8882 +++ linux-3.2.5-vs2.3.2.6/include/linux/utsname.h       2011-12-05 19:33:02.000000000 +0100
8883 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8884  }
8885  
8886  extern struct uts_namespace *copy_utsname(unsigned long flags,
8887 -                                         struct task_struct *tsk);
8888 +                                         struct uts_namespace *old_ns,
8889 +                                         struct user_namespace *user_ns);
8890  extern void free_uts_ns(struct kref *kref);
8891  
8892  static inline void put_uts_ns(struct uts_namespace *ns)
8893 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8894  }
8895  
8896  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8897 -                                                struct task_struct *tsk)
8898 +                                                struct uts_namespace *old_ns,
8899 +                                                struct user_namespace *user_ns)
8900  {
8901         if (flags & CLONE_NEWUTS)
8902                 return ERR_PTR(-EINVAL);
8903  
8904 -       return tsk->nsproxy->uts_ns;
8905 +       return old_ns;
8906  }
8907  #endif
8908  
8909 diff -NurpP --minimal linux-3.2.5/include/linux/vroot.h linux-3.2.5-vs2.3.2.6/include/linux/vroot.h
8910 --- linux-3.2.5/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
8911 +++ linux-3.2.5-vs2.3.2.6/include/linux/vroot.h 2011-12-05 19:33:02.000000000 +0100
8912 @@ -0,0 +1,51 @@
8913 +
8914 +/*
8915 + * include/linux/vroot.h
8916 + *
8917 + * written by Herbert Pötzl, 9/11/2002
8918 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8919 + *
8920 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8921 + * Redistribution of this file is permitted under the
8922 + * GNU General Public License.
8923 + */
8924 +
8925 +#ifndef _LINUX_VROOT_H
8926 +#define _LINUX_VROOT_H
8927 +
8928 +
8929 +#ifdef __KERNEL__
8930 +
8931 +/* Possible states of device */
8932 +enum {
8933 +       Vr_unbound,
8934 +       Vr_bound,
8935 +};
8936 +
8937 +struct vroot_device {
8938 +       int             vr_number;
8939 +       int             vr_refcnt;
8940 +
8941 +       struct semaphore        vr_ctl_mutex;
8942 +       struct block_device    *vr_device;
8943 +       int                     vr_state;
8944 +};
8945 +
8946 +
8947 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8948 +
8949 +extern int register_vroot_grb(vroot_grb_func *);
8950 +extern int unregister_vroot_grb(vroot_grb_func *);
8951 +
8952 +#endif /* __KERNEL__ */
8953 +
8954 +#define MAX_VROOT_DEFAULT      8
8955 +
8956 +/*
8957 + * IOCTL commands --- we will commandeer 0x56 ('V')
8958 + */
8959 +
8960 +#define VROOT_SET_DEV          0x5600
8961 +#define VROOT_CLR_DEV          0x5601
8962 +
8963 +#endif /* _LINUX_VROOT_H */
8964 diff -NurpP --minimal linux-3.2.5/include/linux/vs_base.h linux-3.2.5-vs2.3.2.6/include/linux/vs_base.h
8965 --- linux-3.2.5/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8966 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_base.h       2011-12-05 19:33:02.000000000 +0100
8967 @@ -0,0 +1,10 @@
8968 +#ifndef _VS_BASE_H
8969 +#define _VS_BASE_H
8970 +
8971 +#include "vserver/base.h"
8972 +#include "vserver/check.h"
8973 +#include "vserver/debug.h"
8974 +
8975 +#else
8976 +#warning duplicate inclusion
8977 +#endif
8978 diff -NurpP --minimal linux-3.2.5/include/linux/vs_context.h linux-3.2.5-vs2.3.2.6/include/linux/vs_context.h
8979 --- linux-3.2.5/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
8980 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_context.h    2011-12-05 19:33:02.000000000 +0100
8981 @@ -0,0 +1,242 @@
8982 +#ifndef _VS_CONTEXT_H
8983 +#define _VS_CONTEXT_H
8984 +
8985 +#include "vserver/base.h"
8986 +#include "vserver/check.h"
8987 +#include "vserver/context.h"
8988 +#include "vserver/history.h"
8989 +#include "vserver/debug.h"
8990 +
8991 +#include <linux/sched.h>
8992 +
8993 +
8994 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8995 +
8996 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8997 +       const char *_file, int _line, void *_here)
8998 +{
8999 +       if (!vxi)
9000 +               return NULL;
9001 +
9002 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9003 +               vxi, vxi ? vxi->vx_id : 0,
9004 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9005 +               _file, _line);
9006 +       __vxh_get_vx_info(vxi, _here);
9007 +
9008 +       atomic_inc(&vxi->vx_usecnt);
9009 +       return vxi;
9010 +}
9011 +
9012 +
9013 +extern void free_vx_info(struct vx_info *);
9014 +
9015 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9016 +
9017 +static inline void __put_vx_info(struct vx_info *vxi,
9018 +       const char *_file, int _line, void *_here)
9019 +{
9020 +       if (!vxi)
9021 +               return;
9022 +
9023 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9024 +               vxi, vxi ? vxi->vx_id : 0,
9025 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9026 +               _file, _line);
9027 +       __vxh_put_vx_info(vxi, _here);
9028 +
9029 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9030 +               free_vx_info(vxi);
9031 +}
9032 +
9033 +
9034 +#define init_vx_info(p, i) \
9035 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9036 +
9037 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9038 +       const char *_file, int _line, void *_here)
9039 +{
9040 +       if (vxi) {
9041 +               vxlprintk(VXD_CBIT(xid, 3),
9042 +                       "init_vx_info(%p[#%d.%d])",
9043 +                       vxi, vxi ? vxi->vx_id : 0,
9044 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9045 +                       _file, _line);
9046 +               __vxh_init_vx_info(vxi, vxp, _here);
9047 +
9048 +               atomic_inc(&vxi->vx_usecnt);
9049 +       }
9050 +       *vxp = vxi;
9051 +}
9052 +
9053 +
9054 +#define set_vx_info(p, i) \
9055 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9056 +
9057 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9058 +       const char *_file, int _line, void *_here)
9059 +{
9060 +       struct vx_info *vxo;
9061 +
9062 +       if (!vxi)
9063 +               return;
9064 +
9065 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9066 +               vxi, vxi ? vxi->vx_id : 0,
9067 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9068 +               _file, _line);
9069 +       __vxh_set_vx_info(vxi, vxp, _here);
9070 +
9071 +       atomic_inc(&vxi->vx_usecnt);
9072 +       vxo = xchg(vxp, vxi);
9073 +       BUG_ON(vxo);
9074 +}
9075 +
9076 +
9077 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9078 +
9079 +static inline void __clr_vx_info(struct vx_info **vxp,
9080 +       const char *_file, int _line, void *_here)
9081 +{
9082 +       struct vx_info *vxo;
9083 +
9084 +       vxo = xchg(vxp, NULL);
9085 +       if (!vxo)
9086 +               return;
9087 +
9088 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9089 +               vxo, vxo ? vxo->vx_id : 0,
9090 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9091 +               _file, _line);
9092 +       __vxh_clr_vx_info(vxo, vxp, _here);
9093 +
9094 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9095 +               free_vx_info(vxo);
9096 +}
9097 +
9098 +
9099 +#define claim_vx_info(v, p) \
9100 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9101 +
9102 +static inline void __claim_vx_info(struct vx_info *vxi,
9103 +       struct task_struct *task,
9104 +       const char *_file, int _line, void *_here)
9105 +{
9106 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9107 +               vxi, vxi ? vxi->vx_id : 0,
9108 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9109 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9110 +               task, _file, _line);
9111 +       __vxh_claim_vx_info(vxi, task, _here);
9112 +
9113 +       atomic_inc(&vxi->vx_tasks);
9114 +}
9115 +
9116 +
9117 +extern void unhash_vx_info(struct vx_info *);
9118 +
9119 +#define release_vx_info(v, p) \
9120 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9121 +
9122 +static inline void __release_vx_info(struct vx_info *vxi,
9123 +       struct task_struct *task,
9124 +       const char *_file, int _line, void *_here)
9125 +{
9126 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9127 +               vxi, vxi ? vxi->vx_id : 0,
9128 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9129 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9130 +               task, _file, _line);
9131 +       __vxh_release_vx_info(vxi, task, _here);
9132 +
9133 +       might_sleep();
9134 +
9135 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9136 +               unhash_vx_info(vxi);
9137 +}
9138 +
9139 +
9140 +#define task_get_vx_info(p) \
9141 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9142 +
9143 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9144 +       const char *_file, int _line, void *_here)
9145 +{
9146 +       struct vx_info *vxi;
9147 +
9148 +       task_lock(p);
9149 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9150 +               p, _file, _line);
9151 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9152 +       task_unlock(p);
9153 +       return vxi;
9154 +}
9155 +
9156 +
9157 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9158 +{
9159 +       if (waitqueue_active(&vxi->vx_wait))
9160 +               wake_up_interruptible(&vxi->vx_wait);
9161 +}
9162 +
9163 +
9164 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9165 +
9166 +static inline void __enter_vx_info(struct vx_info *vxi,
9167 +       struct vx_info_save *vxis, const char *_file, int _line)
9168 +{
9169 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9170 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9171 +               current->xid, current->vx_info, _file, _line);
9172 +       vxis->vxi = xchg(&current->vx_info, vxi);
9173 +       vxis->xid = current->xid;
9174 +       current->xid = vxi ? vxi->vx_id : 0;
9175 +}
9176 +
9177 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9178 +
9179 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9180 +       const char *_file, int _line)
9181 +{
9182 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9183 +               vxis, vxis->xid, vxis->vxi, current,
9184 +               current->xid, current->vx_info, _file, _line);
9185 +       (void)xchg(&current->vx_info, vxis->vxi);
9186 +       current->xid = vxis->xid;
9187 +}
9188 +
9189 +
9190 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9191 +{
9192 +       vxis->vxi = xchg(&current->vx_info, NULL);
9193 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9194 +}
9195 +
9196 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9197 +{
9198 +       (void)xchg(&current->xid, vxis->xid);
9199 +       (void)xchg(&current->vx_info, vxis->vxi);
9200 +}
9201 +
9202 +#define task_is_init(p) \
9203 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9204 +
9205 +static inline int __task_is_init(struct task_struct *p,
9206 +       const char *_file, int _line, void *_here)
9207 +{
9208 +       int is_init = is_global_init(p);
9209 +
9210 +       task_lock(p);
9211 +       if (p->vx_info)
9212 +               is_init = p->vx_info->vx_initpid == p->pid;
9213 +       task_unlock(p);
9214 +       return is_init;
9215 +}
9216 +
9217 +extern void exit_vx_info(struct task_struct *, int);
9218 +extern void exit_vx_info_early(struct task_struct *, int);
9219 +
9220 +
9221 +#else
9222 +#warning duplicate inclusion
9223 +#endif
9224 diff -NurpP --minimal linux-3.2.5/include/linux/vs_cowbl.h linux-3.2.5-vs2.3.2.6/include/linux/vs_cowbl.h
9225 --- linux-3.2.5/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9226 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_cowbl.h      2011-12-05 19:33:02.000000000 +0100
9227 @@ -0,0 +1,48 @@
9228 +#ifndef _VS_COWBL_H
9229 +#define _VS_COWBL_H
9230 +
9231 +#include <linux/fs.h>
9232 +#include <linux/dcache.h>
9233 +#include <linux/namei.h>
9234 +#include <linux/slab.h>
9235 +
9236 +extern struct dentry *cow_break_link(const char *pathname);
9237 +
9238 +static inline int cow_check_and_break(struct path *path)
9239 +{
9240 +       struct inode *inode = path->dentry->d_inode;
9241 +       int error = 0;
9242 +
9243 +       /* do we need this check? */
9244 +       if (IS_RDONLY(inode))
9245 +               return -EROFS;
9246 +
9247 +       if (IS_COW(inode)) {
9248 +               if (IS_COW_LINK(inode)) {
9249 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9250 +                       char *pp, *buf;
9251 +
9252 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9253 +                       if (!buf) {
9254 +                               return -ENOMEM;
9255 +                       }
9256 +                       pp = d_path(path, buf, PATH_MAX);
9257 +                       new_dentry = cow_break_link(pp);
9258 +                       kfree(buf);
9259 +                       if (!IS_ERR(new_dentry)) {
9260 +                               path->dentry = new_dentry;
9261 +                               dput(old_dentry);
9262 +                       } else
9263 +                               error = PTR_ERR(new_dentry);
9264 +               } else {
9265 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9266 +                       inode->i_ctime = CURRENT_TIME;
9267 +                       mark_inode_dirty(inode);
9268 +               }
9269 +       }
9270 +       return error;
9271 +}
9272 +
9273 +#else
9274 +#warning duplicate inclusion
9275 +#endif
9276 diff -NurpP --minimal linux-3.2.5/include/linux/vs_cvirt.h linux-3.2.5-vs2.3.2.6/include/linux/vs_cvirt.h
9277 --- linux-3.2.5/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9278 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_cvirt.h      2011-12-05 19:33:02.000000000 +0100
9279 @@ -0,0 +1,50 @@
9280 +#ifndef _VS_CVIRT_H
9281 +#define _VS_CVIRT_H
9282 +
9283 +#include "vserver/cvirt.h"
9284 +#include "vserver/context.h"
9285 +#include "vserver/base.h"
9286 +#include "vserver/check.h"
9287 +#include "vserver/debug.h"
9288 +
9289 +
9290 +static inline void vx_activate_task(struct task_struct *p)
9291 +{
9292 +       struct vx_info *vxi;
9293 +
9294 +       if ((vxi = p->vx_info)) {
9295 +               vx_update_load(vxi);
9296 +               atomic_inc(&vxi->cvirt.nr_running);
9297 +       }
9298 +}
9299 +
9300 +static inline void vx_deactivate_task(struct task_struct *p)
9301 +{
9302 +       struct vx_info *vxi;
9303 +
9304 +       if ((vxi = p->vx_info)) {
9305 +               vx_update_load(vxi);
9306 +               atomic_dec(&vxi->cvirt.nr_running);
9307 +       }
9308 +}
9309 +
9310 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9311 +{
9312 +       struct vx_info *vxi;
9313 +
9314 +       if ((vxi = p->vx_info))
9315 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9316 +}
9317 +
9318 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9319 +{
9320 +       struct vx_info *vxi;
9321 +
9322 +       if ((vxi = p->vx_info))
9323 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9324 +}
9325 +
9326 +
9327 +#else
9328 +#warning duplicate inclusion
9329 +#endif
9330 diff -NurpP --minimal linux-3.2.5/include/linux/vs_device.h linux-3.2.5-vs2.3.2.6/include/linux/vs_device.h
9331 --- linux-3.2.5/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9332 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_device.h     2011-12-05 19:33:02.000000000 +0100
9333 @@ -0,0 +1,45 @@
9334 +#ifndef _VS_DEVICE_H
9335 +#define _VS_DEVICE_H
9336 +
9337 +#include "vserver/base.h"
9338 +#include "vserver/device.h"
9339 +#include "vserver/debug.h"
9340 +
9341 +
9342 +#ifdef CONFIG_VSERVER_DEVICE
9343 +
9344 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9345 +
9346 +#define vs_device_perm(v, d, m, p) \
9347 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9348 +
9349 +#else
9350 +
9351 +static inline
9352 +int vs_map_device(struct vx_info *vxi,
9353 +       dev_t device, dev_t *target, umode_t mode)
9354 +{
9355 +       if (target)
9356 +               *target = device;
9357 +       return ~0;
9358 +}
9359 +
9360 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9361 +
9362 +#endif
9363 +
9364 +
9365 +#define vs_map_chrdev(d, t, p) \
9366 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9367 +#define vs_map_blkdev(d, t, p) \
9368 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9369 +
9370 +#define vs_chrdev_perm(d, p) \
9371 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9372 +#define vs_blkdev_perm(d, p) \
9373 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9374 +
9375 +
9376 +#else
9377 +#warning duplicate inclusion
9378 +#endif
9379 diff -NurpP --minimal linux-3.2.5/include/linux/vs_dlimit.h linux-3.2.5-vs2.3.2.6/include/linux/vs_dlimit.h
9380 --- linux-3.2.5/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9381 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_dlimit.h     2011-12-05 19:33:02.000000000 +0100
9382 @@ -0,0 +1,215 @@
9383 +#ifndef _VS_DLIMIT_H
9384 +#define _VS_DLIMIT_H
9385 +
9386 +#include <linux/fs.h>
9387 +
9388 +#include "vserver/dlimit.h"
9389 +#include "vserver/base.h"
9390 +#include "vserver/debug.h"
9391 +
9392 +
9393 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9394 +
9395 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9396 +       const char *_file, int _line)
9397 +{
9398 +       if (!dli)
9399 +               return NULL;
9400 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9401 +               dli, dli ? dli->dl_tag : 0,
9402 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9403 +               _file, _line);
9404 +       atomic_inc(&dli->dl_usecnt);
9405 +       return dli;
9406 +}
9407 +
9408 +
9409 +#define free_dl_info(i) \
9410 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9411 +
9412 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9413 +
9414 +static inline void __put_dl_info(struct dl_info *dli,
9415 +       const char *_file, int _line)
9416 +{
9417 +       if (!dli)
9418 +               return;
9419 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9420 +               dli, dli ? dli->dl_tag : 0,
9421 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9422 +               _file, _line);
9423 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9424 +               free_dl_info(dli);
9425 +}
9426 +
9427 +
9428 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9429 +
9430 +static inline int __dl_alloc_space(struct super_block *sb,
9431 +       tag_t tag, dlsize_t nr, const char *file, int line)
9432 +{
9433 +       struct dl_info *dli = NULL;
9434 +       int ret = 0;
9435 +
9436 +       if (nr == 0)
9437 +               goto out;
9438 +       dli = locate_dl_info(sb, tag);
9439 +       if (!dli)
9440 +               goto out;
9441 +
9442 +       spin_lock(&dli->dl_lock);
9443 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9444 +       if (!ret)
9445 +               dli->dl_space_used += nr;
9446 +       spin_unlock(&dli->dl_lock);
9447 +       put_dl_info(dli);
9448 +out:
9449 +       vxlprintk(VXD_CBIT(dlim, 1),
9450 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9451 +               sb, tag, __dlimit_char(dli), (long long)nr,
9452 +               ret, file, line);
9453 +       return ret ? -ENOSPC : 0;
9454 +}
9455 +
9456 +static inline void __dl_free_space(struct super_block *sb,
9457 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9458 +{
9459 +       struct dl_info *dli = NULL;
9460 +
9461 +       if (nr == 0)
9462 +               goto out;
9463 +       dli = locate_dl_info(sb, tag);
9464 +       if (!dli)
9465 +               goto out;
9466 +
9467 +       spin_lock(&dli->dl_lock);
9468 +       if (dli->dl_space_used > nr)
9469 +               dli->dl_space_used -= nr;
9470 +       else
9471 +               dli->dl_space_used = 0;
9472 +       spin_unlock(&dli->dl_lock);
9473 +       put_dl_info(dli);
9474 +out:
9475 +       vxlprintk(VXD_CBIT(dlim, 1),
9476 +               "FREE  (%p,#%d)%c %lld bytes",
9477 +               sb, tag, __dlimit_char(dli), (long long)nr,
9478 +               _file, _line);
9479 +}
9480 +
9481 +static inline int __dl_alloc_inode(struct super_block *sb,
9482 +       tag_t tag, const char *_file, int _line)
9483 +{
9484 +       struct dl_info *dli;
9485 +       int ret = 0;
9486 +
9487 +       dli = locate_dl_info(sb, tag);
9488 +       if (!dli)
9489 +               goto out;
9490 +
9491 +       spin_lock(&dli->dl_lock);
9492 +       dli->dl_inodes_used++;
9493 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9494 +       spin_unlock(&dli->dl_lock);
9495 +       put_dl_info(dli);
9496 +out:
9497 +       vxlprintk(VXD_CBIT(dlim, 0),
9498 +               "ALLOC (%p,#%d)%c inode (%d)",
9499 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9500 +       return ret ? -ENOSPC : 0;
9501 +}
9502 +
9503 +static inline void __dl_free_inode(struct super_block *sb,
9504 +       tag_t tag, const char *_file, int _line)
9505 +{
9506 +       struct dl_info *dli;
9507 +
9508 +       dli = locate_dl_info(sb, tag);
9509 +       if (!dli)
9510 +               goto out;
9511 +
9512 +       spin_lock(&dli->dl_lock);
9513 +       if (dli->dl_inodes_used > 1)
9514 +               dli->dl_inodes_used--;
9515 +       else
9516 +               dli->dl_inodes_used = 0;
9517 +       spin_unlock(&dli->dl_lock);
9518 +       put_dl_info(dli);
9519 +out:
9520 +       vxlprintk(VXD_CBIT(dlim, 0),
9521 +               "FREE  (%p,#%d)%c inode",
9522 +               sb, tag, __dlimit_char(dli), _file, _line);
9523 +}
9524 +
9525 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9526 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9527 +       const char *_file, int _line)
9528 +{
9529 +       struct dl_info *dli;
9530 +       uint64_t broot, bfree;
9531 +
9532 +       dli = locate_dl_info(sb, tag);
9533 +       if (!dli)
9534 +               return;
9535 +
9536 +       spin_lock(&dli->dl_lock);
9537 +       broot = (dli->dl_space_total -
9538 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9539 +               >> sb->s_blocksize_bits;
9540 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9541 +                       >> sb->s_blocksize_bits;
9542 +       spin_unlock(&dli->dl_lock);
9543 +
9544 +       vxlprintk(VXD_CBIT(dlim, 2),
9545 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9546 +               (long long)bfree, (long long)broot,
9547 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9548 +               _file, _line);
9549 +       if (free_blocks) {
9550 +               if (*free_blocks > bfree)
9551 +                       *free_blocks = bfree;
9552 +       }
9553 +       if (root_blocks) {
9554 +               if (*root_blocks > broot)
9555 +                       *root_blocks = broot;
9556 +       }
9557 +       put_dl_info(dli);
9558 +}
9559 +
9560 +#define dl_prealloc_space(in, bytes) \
9561 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9562 +               __FILE__, __LINE__ )
9563 +
9564 +#define dl_alloc_space(in, bytes) \
9565 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9566 +               __FILE__, __LINE__ )
9567 +
9568 +#define dl_reserve_space(in, bytes) \
9569 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9570 +               __FILE__, __LINE__ )
9571 +
9572 +#define dl_claim_space(in, bytes) (0)
9573 +
9574 +#define dl_release_space(in, bytes) \
9575 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9576 +               __FILE__, __LINE__ )
9577 +
9578 +#define dl_free_space(in, bytes) \
9579 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9580 +               __FILE__, __LINE__ )
9581 +
9582 +
9583 +
9584 +#define dl_alloc_inode(in) \
9585 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9586 +
9587 +#define dl_free_inode(in) \
9588 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9589 +
9590 +
9591 +#define dl_adjust_block(sb, tag, fb, rb) \
9592 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9593 +
9594 +
9595 +#else
9596 +#warning duplicate inclusion
9597 +#endif
9598 diff -NurpP --minimal linux-3.2.5/include/linux/vs_inet.h linux-3.2.5-vs2.3.2.6/include/linux/vs_inet.h
9599 --- linux-3.2.5/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9600 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_inet.h       2011-12-05 19:33:02.000000000 +0100
9601 @@ -0,0 +1,353 @@
9602 +#ifndef _VS_INET_H
9603 +#define _VS_INET_H
9604 +
9605 +#include "vserver/base.h"
9606 +#include "vserver/network.h"
9607 +#include "vserver/debug.h"
9608 +
9609 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9610 +
9611 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9612 +                       NIPQUAD((a)->mask), (a)->type
9613 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9614 +
9615 +#define NIPQUAD(addr) \
9616 +       ((unsigned char *)&addr)[0], \
9617 +       ((unsigned char *)&addr)[1], \
9618 +       ((unsigned char *)&addr)[2], \
9619 +       ((unsigned char *)&addr)[3]
9620 +
9621 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9622 +
9623 +
9624 +static inline
9625 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9626 +{
9627 +       __be32 ip = nxa->ip[0].s_addr;
9628 +       __be32 mask = nxa->mask.s_addr;
9629 +       __be32 bcast = ip | ~mask;
9630 +       int ret = 0;
9631 +
9632 +       switch (nxa->type & tmask) {
9633 +       case NXA_TYPE_MASK:
9634 +               ret = (ip == (addr & mask));
9635 +               break;
9636 +       case NXA_TYPE_ADDR:
9637 +               ret = 3;
9638 +               if (addr == ip)
9639 +                       break;
9640 +               /* fall through to broadcast */
9641 +       case NXA_MOD_BCAST:
9642 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9643 +               break;
9644 +       case NXA_TYPE_RANGE:
9645 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9646 +                       (nxa->ip[1].s_addr > addr));
9647 +               break;
9648 +       case NXA_TYPE_ANY:
9649 +               ret = 2;
9650 +               break;
9651 +       }
9652 +
9653 +       vxdprintk(VXD_CBIT(net, 0),
9654 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9655 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9656 +       return ret;
9657 +}
9658 +
9659 +static inline
9660 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9661 +{
9662 +       struct nx_addr_v4 *nxa;
9663 +       int ret = 1;
9664 +
9665 +       if (!nxi)
9666 +               goto out;
9667 +
9668 +       ret = 2;
9669 +       /* allow 127.0.0.1 when remapping lback */
9670 +       if ((tmask & NXA_LOOPBACK) &&
9671 +               (addr == IPI_LOOPBACK) &&
9672 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9673 +               goto out;
9674 +       ret = 3;
9675 +       /* check for lback address */
9676 +       if ((tmask & NXA_MOD_LBACK) &&
9677 +               (nxi->v4_lback.s_addr == addr))
9678 +               goto out;
9679 +       ret = 4;
9680 +       /* check for broadcast address */
9681 +       if ((tmask & NXA_MOD_BCAST) &&
9682 +               (nxi->v4_bcast.s_addr == addr))
9683 +               goto out;
9684 +       ret = 5;
9685 +       /* check for v4 addresses */
9686 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9687 +               if (v4_addr_match(nxa, addr, tmask))
9688 +                       goto out;
9689 +       ret = 0;
9690 +out:
9691 +       vxdprintk(VXD_CBIT(net, 0),
9692 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9693 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9694 +       return ret;
9695 +}
9696 +
9697 +static inline
9698 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9699 +{
9700 +       /* FIXME: needs full range checks */
9701 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9702 +}
9703 +
9704 +static inline
9705 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9706 +{
9707 +       struct nx_addr_v4 *ptr;
9708 +
9709 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9710 +               if (v4_nx_addr_match(ptr, nxa, mask))
9711 +                       return 1;
9712 +       return 0;
9713 +}
9714 +
9715 +#include <net/inet_sock.h>
9716 +
9717 +/*
9718 + *     Check if a given address matches for a socket
9719 + *
9720 + *     nxi:            the socket's nx_info if any
9721 + *     addr:           to be verified address
9722 + */
9723 +static inline
9724 +int v4_sock_addr_match (
9725 +       struct nx_info *nxi,
9726 +       struct inet_sock *inet,
9727 +       __be32 addr)
9728 +{
9729 +       __be32 saddr = inet->inet_rcv_saddr;
9730 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9731 +
9732 +       if (addr && (saddr == addr || bcast == addr))
9733 +               return 1;
9734 +       if (!saddr)
9735 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9736 +       return 0;
9737 +}
9738 +
9739 +
9740 +/* inet related checks and helpers */
9741 +
9742 +
9743 +struct in_ifaddr;
9744 +struct net_device;
9745 +struct sock;
9746 +
9747 +#ifdef CONFIG_INET
9748 +
9749 +#include <linux/netdevice.h>
9750 +#include <linux/inetdevice.h>
9751 +#include <net/inet_sock.h>
9752 +#include <net/inet_timewait_sock.h>
9753 +
9754 +
9755 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9756 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9757 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9758 +
9759 +
9760 +/*
9761 + *     check if address is covered by socket
9762 + *
9763 + *     sk:     the socket to check against
9764 + *     addr:   the address in question (must be != 0)
9765 + */
9766 +
9767 +static inline
9768 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9769 +{
9770 +       struct nx_info *nxi = sk->sk_nx_info;
9771 +       __be32 saddr = sk_rcv_saddr(sk);
9772 +
9773 +       vxdprintk(VXD_CBIT(net, 5),
9774 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9775 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9776 +               (sk->sk_socket?sk->sk_socket->flags:0));
9777 +
9778 +       if (saddr) {            /* direct address match */
9779 +               return v4_addr_match(nxa, saddr, -1);
9780 +       } else if (nxi) {       /* match against nx_info */
9781 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9782 +       } else {                /* unrestricted any socket */
9783 +               return 1;
9784 +       }
9785 +}
9786 +
9787 +
9788 +
9789 +static inline
9790 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9791 +{
9792 +       vxdprintk(VXD_CBIT(net, 1),
9793 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9794 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9795 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9796 +
9797 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9798 +               return 1;
9799 +       if (dev_in_nx_info(dev, nxi))
9800 +               return 1;
9801 +       return 0;
9802 +}
9803 +
9804 +
9805 +static inline
9806 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9807 +{
9808 +       if (!nxi)
9809 +               return 1;
9810 +       if (!ifa)
9811 +               return 0;
9812 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9813 +}
9814 +
9815 +static inline
9816 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9817 +{
9818 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9819 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9820 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9821 +
9822 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9823 +               return 1;
9824 +       if (v4_ifa_in_nx_info(ifa, nxi))
9825 +               return 1;
9826 +       return 0;
9827 +}
9828 +
9829 +
9830 +struct nx_v4_sock_addr {
9831 +       __be32 saddr;   /* Address used for validation */
9832 +       __be32 baddr;   /* Address used for socket bind */
9833 +};
9834 +
9835 +static inline
9836 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9837 +       struct nx_v4_sock_addr *nsa)
9838 +{
9839 +       struct sock *sk = &inet->sk;
9840 +       struct nx_info *nxi = sk->sk_nx_info;
9841 +       __be32 saddr = addr->sin_addr.s_addr;
9842 +       __be32 baddr = saddr;
9843 +
9844 +       vxdprintk(VXD_CBIT(net, 3),
9845 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9846 +               sk, sk->sk_nx_info, sk->sk_socket,
9847 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9848 +               NIPQUAD(saddr));
9849 +
9850 +       if (nxi) {
9851 +               if (saddr == INADDR_ANY) {
9852 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9853 +                               baddr = nxi->v4.ip[0].s_addr;
9854 +               } else if (saddr == IPI_LOOPBACK) {
9855 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9856 +                               baddr = nxi->v4_lback.s_addr;
9857 +               } else if (!ipv4_is_multicast(saddr) ||
9858 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9859 +                       /* normal address bind */
9860 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9861 +                               return -EADDRNOTAVAIL;
9862 +               }
9863 +       }
9864 +
9865 +       vxdprintk(VXD_CBIT(net, 3),
9866 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9867 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9868 +
9869 +       nsa->saddr = saddr;
9870 +       nsa->baddr = baddr;
9871 +       return 0;
9872 +}
9873 +
9874 +static inline
9875 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9876 +{
9877 +       inet->inet_saddr = nsa->baddr;
9878 +       inet->inet_rcv_saddr = nsa->baddr;
9879 +}
9880 +
9881 +
9882 +/*
9883 + *      helper to simplify inet_lookup_listener
9884 + *
9885 + *      nxi:   the socket's nx_info if any
9886 + *      addr:  to be verified address
9887 + *      saddr: socket address
9888 + */
9889 +static inline int v4_inet_addr_match (
9890 +       struct nx_info *nxi,
9891 +       __be32 addr,
9892 +       __be32 saddr)
9893 +{
9894 +       if (addr && (saddr == addr))
9895 +               return 1;
9896 +       if (!saddr)
9897 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9898 +       return 0;
9899 +}
9900 +
9901 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9902 +{
9903 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9904 +               (addr == nxi->v4_lback.s_addr))
9905 +               return IPI_LOOPBACK;
9906 +       return addr;
9907 +}
9908 +
9909 +static inline
9910 +int nx_info_has_v4(struct nx_info *nxi)
9911 +{
9912 +       if (!nxi)
9913 +               return 1;
9914 +       if (NX_IPV4(nxi))
9915 +               return 1;
9916 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9917 +               return 1;
9918 +       return 0;
9919 +}
9920 +
9921 +#else /* CONFIG_INET */
9922 +
9923 +static inline
9924 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9925 +{
9926 +       return 1;
9927 +}
9928 +
9929 +static inline
9930 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9931 +{
9932 +       return 1;
9933 +}
9934 +
9935 +static inline
9936 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9937 +{
9938 +       return 1;
9939 +}
9940 +
9941 +static inline
9942 +int nx_info_has_v4(struct nx_info *nxi)
9943 +{
9944 +       return 0;
9945 +}
9946 +
9947 +#endif /* CONFIG_INET */
9948 +
9949 +#define current_nx_info_has_v4() \
9950 +       nx_info_has_v4(current_nx_info())
9951 +
9952 +#else
9953 +// #warning duplicate inclusion
9954 +#endif
9955 diff -NurpP --minimal linux-3.2.5/include/linux/vs_inet6.h linux-3.2.5-vs2.3.2.6/include/linux/vs_inet6.h
9956 --- linux-3.2.5/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
9957 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_inet6.h      2011-12-05 19:33:02.000000000 +0100
9958 @@ -0,0 +1,246 @@
9959 +#ifndef _VS_INET6_H
9960 +#define _VS_INET6_H
9961 +
9962 +#include "vserver/base.h"
9963 +#include "vserver/network.h"
9964 +#include "vserver/debug.h"
9965 +
9966 +#include <net/ipv6.h>
9967 +
9968 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9969 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9970 +
9971 +
9972 +#ifdef CONFIG_IPV6
9973 +
9974 +static inline
9975 +int v6_addr_match(struct nx_addr_v6 *nxa,
9976 +       const struct in6_addr *addr, uint16_t mask)
9977 +{
9978 +       int ret = 0;
9979 +
9980 +       switch (nxa->type & mask) {
9981 +       case NXA_TYPE_MASK:
9982 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9983 +               break;
9984 +       case NXA_TYPE_ADDR:
9985 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9986 +               break;
9987 +       case NXA_TYPE_ANY:
9988 +               ret = 1;
9989 +               break;
9990 +       }
9991 +       vxdprintk(VXD_CBIT(net, 0),
9992 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9993 +               nxa, NXAV6(nxa), addr, mask, ret);
9994 +       return ret;
9995 +}
9996 +
9997 +static inline
9998 +int v6_addr_in_nx_info(struct nx_info *nxi,
9999 +       const struct in6_addr *addr, uint16_t mask)
10000 +{
10001 +       struct nx_addr_v6 *nxa;
10002 +       int ret = 1;
10003 +
10004 +       if (!nxi)
10005 +               goto out;
10006 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10007 +               if (v6_addr_match(nxa, addr, mask))
10008 +                       goto out;
10009 +       ret = 0;
10010 +out:
10011 +       vxdprintk(VXD_CBIT(net, 0),
10012 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10013 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10014 +       return ret;
10015 +}
10016 +
10017 +static inline
10018 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10019 +{
10020 +       /* FIXME: needs full range checks */
10021 +       return v6_addr_match(nxa, &addr->ip, mask);
10022 +}
10023 +
10024 +static inline
10025 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10026 +{
10027 +       struct nx_addr_v6 *ptr;
10028 +
10029 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10030 +               if (v6_nx_addr_match(ptr, nxa, mask))
10031 +                       return 1;
10032 +       return 0;
10033 +}
10034 +
10035 +
10036 +/*
10037 + *     Check if a given address matches for a socket
10038 + *
10039 + *     nxi:            the socket's nx_info if any
10040 + *     addr:           to be verified address
10041 + */
10042 +static inline
10043 +int v6_sock_addr_match (
10044 +       struct nx_info *nxi,
10045 +       struct inet_sock *inet,
10046 +       struct in6_addr *addr)
10047 +{
10048 +       struct sock *sk = &inet->sk;
10049 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10050 +
10051 +       if (!ipv6_addr_any(addr) &&
10052 +               ipv6_addr_equal(saddr, addr))
10053 +               return 1;
10054 +       if (ipv6_addr_any(saddr))
10055 +               return v6_addr_in_nx_info(nxi, addr, -1);
10056 +       return 0;
10057 +}
10058 +
10059 +/*
10060 + *     check if address is covered by socket
10061 + *
10062 + *     sk:     the socket to check against
10063 + *     addr:   the address in question (must be != 0)
10064 + */
10065 +
10066 +static inline
10067 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10068 +{
10069 +       struct nx_info *nxi = sk->sk_nx_info;
10070 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10071 +
10072 +       vxdprintk(VXD_CBIT(net, 5),
10073 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10074 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10075 +               (sk->sk_socket?sk->sk_socket->flags:0));
10076 +
10077 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10078 +               return v6_addr_match(nxa, saddr, -1);
10079 +       } else if (nxi) {               /* match against nx_info */
10080 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10081 +       } else {                        /* unrestricted any socket */
10082 +               return 1;
10083 +       }
10084 +}
10085 +
10086 +
10087 +/* inet related checks and helpers */
10088 +
10089 +
10090 +struct in_ifaddr;
10091 +struct net_device;
10092 +struct sock;
10093 +
10094 +
10095 +#include <linux/netdevice.h>
10096 +#include <linux/inetdevice.h>
10097 +#include <net/inet_timewait_sock.h>
10098 +
10099 +
10100 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10101 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10102 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10103 +
10104 +
10105 +
10106 +static inline
10107 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10108 +{
10109 +       if (!nxi)
10110 +               return 1;
10111 +       if (!ifa)
10112 +               return 0;
10113 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10114 +}
10115 +
10116 +static inline
10117 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10118 +{
10119 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10120 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10121 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10122 +
10123 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10124 +               return 1;
10125 +       if (v6_ifa_in_nx_info(ifa, nxi))
10126 +               return 1;
10127 +       return 0;
10128 +}
10129 +
10130 +
10131 +struct nx_v6_sock_addr {
10132 +       struct in6_addr saddr;  /* Address used for validation */
10133 +       struct in6_addr baddr;  /* Address used for socket bind */
10134 +};
10135 +
10136 +static inline
10137 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10138 +       struct nx_v6_sock_addr *nsa)
10139 +{
10140 +       // struct sock *sk = &inet->sk;
10141 +       // struct nx_info *nxi = sk->sk_nx_info;
10142 +       struct in6_addr saddr = addr->sin6_addr;
10143 +       struct in6_addr baddr = saddr;
10144 +
10145 +       nsa->saddr = saddr;
10146 +       nsa->baddr = baddr;
10147 +       return 0;
10148 +}
10149 +
10150 +static inline
10151 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10152 +{
10153 +       // struct sock *sk = &inet->sk;
10154 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10155 +
10156 +       // *saddr = nsa->baddr;
10157 +       // inet->inet_saddr = nsa->baddr;
10158 +}
10159 +
10160 +static inline
10161 +int nx_info_has_v6(struct nx_info *nxi)
10162 +{
10163 +       if (!nxi)
10164 +               return 1;
10165 +       if (NX_IPV6(nxi))
10166 +               return 1;
10167 +       return 0;
10168 +}
10169 +
10170 +#else /* CONFIG_IPV6 */
10171 +
10172 +static inline
10173 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10174 +{
10175 +       return 1;
10176 +}
10177 +
10178 +
10179 +static inline
10180 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10181 +{
10182 +       return 1;
10183 +}
10184 +
10185 +static inline
10186 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10187 +{
10188 +       return 1;
10189 +}
10190 +
10191 +static inline
10192 +int nx_info_has_v6(struct nx_info *nxi)
10193 +{
10194 +       return 0;
10195 +}
10196 +
10197 +#endif /* CONFIG_IPV6 */
10198 +
10199 +#define current_nx_info_has_v6() \
10200 +       nx_info_has_v6(current_nx_info())
10201 +
10202 +#else
10203 +#warning duplicate inclusion
10204 +#endif
10205 diff -NurpP --minimal linux-3.2.5/include/linux/vs_limit.h linux-3.2.5-vs2.3.2.6/include/linux/vs_limit.h
10206 --- linux-3.2.5/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10207 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_limit.h      2011-12-05 19:33:02.000000000 +0100
10208 @@ -0,0 +1,140 @@
10209 +#ifndef _VS_LIMIT_H
10210 +#define _VS_LIMIT_H
10211 +
10212 +#include "vserver/limit.h"
10213 +#include "vserver/base.h"
10214 +#include "vserver/context.h"
10215 +#include "vserver/debug.h"
10216 +#include "vserver/context.h"
10217 +#include "vserver/limit_int.h"
10218 +
10219 +
10220 +#define vx_acc_cres(v, d, p, r) \
10221 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10222 +
10223 +#define vx_acc_cres_cond(x, d, p, r) \
10224 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10225 +       r, d, p, __FILE__, __LINE__)
10226 +
10227 +
10228 +#define vx_add_cres(v, a, p, r) \
10229 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10230 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10231 +
10232 +#define vx_add_cres_cond(x, a, p, r) \
10233 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10234 +       r, a, p, __FILE__, __LINE__)
10235 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10236 +
10237 +
10238 +/* process and file limits */
10239 +
10240 +#define vx_nproc_inc(p) \
10241 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10242 +
10243 +#define vx_nproc_dec(p) \
10244 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10245 +
10246 +#define vx_files_inc(f) \
10247 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10248 +
10249 +#define vx_files_dec(f) \
10250 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10251 +
10252 +#define vx_locks_inc(l) \
10253 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10254 +
10255 +#define vx_locks_dec(l) \
10256 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10257 +
10258 +#define vx_openfd_inc(f) \
10259 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10260 +
10261 +#define vx_openfd_dec(f) \
10262 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10263 +
10264 +
10265 +#define vx_cres_avail(v, n, r) \
10266 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10267 +
10268 +
10269 +#define vx_nproc_avail(n) \
10270 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10271 +
10272 +#define vx_files_avail(n) \
10273 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10274 +
10275 +#define vx_locks_avail(n) \
10276 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10277 +
10278 +#define vx_openfd_avail(n) \
10279 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10280 +
10281 +
10282 +/* dentry limits */
10283 +
10284 +#define vx_dentry_inc(d) do {                                          \
10285 +       if ((d)->d_count == 1)                                          \
10286 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10287 +       } while (0)
10288 +
10289 +#define vx_dentry_dec(d) do {                                          \
10290 +       if ((d)->d_count == 0)                                          \
10291 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10292 +       } while (0)
10293 +
10294 +#define vx_dentry_avail(n) \
10295 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10296 +
10297 +
10298 +/* socket limits */
10299 +
10300 +#define vx_sock_inc(s) \
10301 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10302 +
10303 +#define vx_sock_dec(s) \
10304 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10305 +
10306 +#define vx_sock_avail(n) \
10307 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10308 +
10309 +
10310 +/* ipc resource limits */
10311 +
10312 +#define vx_ipcmsg_add(v, u, a) \
10313 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10314 +
10315 +#define vx_ipcmsg_sub(v, u, a) \
10316 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10317 +
10318 +#define vx_ipcmsg_avail(v, a) \
10319 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10320 +
10321 +
10322 +#define vx_ipcshm_add(v, k, a) \
10323 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10324 +
10325 +#define vx_ipcshm_sub(v, k, a) \
10326 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10327 +
10328 +#define vx_ipcshm_avail(v, a) \
10329 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10330 +
10331 +
10332 +#define vx_semary_inc(a) \
10333 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10334 +
10335 +#define vx_semary_dec(a) \
10336 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10337 +
10338 +
10339 +#define vx_nsems_add(a,n) \
10340 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10341 +
10342 +#define vx_nsems_sub(a,n) \
10343 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10344 +
10345 +
10346 +#else
10347 +#warning duplicate inclusion
10348 +#endif
10349 diff -NurpP --minimal linux-3.2.5/include/linux/vs_network.h linux-3.2.5-vs2.3.2.6/include/linux/vs_network.h
10350 --- linux-3.2.5/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10351 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_network.h    2011-12-05 19:33:02.000000000 +0100
10352 @@ -0,0 +1,169 @@
10353 +#ifndef _NX_VS_NETWORK_H
10354 +#define _NX_VS_NETWORK_H
10355 +
10356 +#include "vserver/context.h"
10357 +#include "vserver/network.h"
10358 +#include "vserver/base.h"
10359 +#include "vserver/check.h"
10360 +#include "vserver/debug.h"
10361 +
10362 +#include <linux/sched.h>
10363 +
10364 +
10365 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10366 +
10367 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10368 +       const char *_file, int _line)
10369 +{
10370 +       if (!nxi)
10371 +               return NULL;
10372 +
10373 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10374 +               nxi, nxi ? nxi->nx_id : 0,
10375 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10376 +               _file, _line);
10377 +
10378 +       atomic_inc(&nxi->nx_usecnt);
10379 +       return nxi;
10380 +}
10381 +
10382 +
10383 +extern void free_nx_info(struct nx_info *);
10384 +
10385 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10386 +
10387 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10388 +{
10389 +       if (!nxi)
10390 +               return;
10391 +
10392 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10393 +               nxi, nxi ? nxi->nx_id : 0,
10394 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10395 +               _file, _line);
10396 +
10397 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10398 +               free_nx_info(nxi);
10399 +}
10400 +
10401 +
10402 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10403 +
10404 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10405 +               const char *_file, int _line)
10406 +{
10407 +       if (nxi) {
10408 +               vxlprintk(VXD_CBIT(nid, 3),
10409 +                       "init_nx_info(%p[#%d.%d])",
10410 +                       nxi, nxi ? nxi->nx_id : 0,
10411 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10412 +                       _file, _line);
10413 +
10414 +               atomic_inc(&nxi->nx_usecnt);
10415 +       }
10416 +       *nxp = nxi;
10417 +}
10418 +
10419 +
10420 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10421 +
10422 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10423 +       const char *_file, int _line)
10424 +{
10425 +       struct nx_info *nxo;
10426 +
10427 +       if (!nxi)
10428 +               return;
10429 +
10430 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10431 +               nxi, nxi ? nxi->nx_id : 0,
10432 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10433 +               _file, _line);
10434 +
10435 +       atomic_inc(&nxi->nx_usecnt);
10436 +       nxo = xchg(nxp, nxi);
10437 +       BUG_ON(nxo);
10438 +}
10439 +
10440 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10441 +
10442 +static inline void __clr_nx_info(struct nx_info **nxp,
10443 +       const char *_file, int _line)
10444 +{
10445 +       struct nx_info *nxo;
10446 +
10447 +       nxo = xchg(nxp, NULL);
10448 +       if (!nxo)
10449 +               return;
10450 +
10451 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10452 +               nxo, nxo ? nxo->nx_id : 0,
10453 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10454 +               _file, _line);
10455 +
10456 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10457 +               free_nx_info(nxo);
10458 +}
10459 +
10460 +
10461 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10462 +
10463 +static inline void __claim_nx_info(struct nx_info *nxi,
10464 +       struct task_struct *task, const char *_file, int _line)
10465 +{
10466 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10467 +               nxi, nxi ? nxi->nx_id : 0,
10468 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10469 +               nxi?atomic_read(&nxi->nx_tasks):0,
10470 +               task, _file, _line);
10471 +
10472 +       atomic_inc(&nxi->nx_tasks);
10473 +}
10474 +
10475 +
10476 +extern void unhash_nx_info(struct nx_info *);
10477 +
10478 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10479 +
10480 +static inline void __release_nx_info(struct nx_info *nxi,
10481 +       struct task_struct *task, const char *_file, int _line)
10482 +{
10483 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10484 +               nxi, nxi ? nxi->nx_id : 0,
10485 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10486 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10487 +               task, _file, _line);
10488 +
10489 +       might_sleep();
10490 +
10491 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10492 +               unhash_nx_info(nxi);
10493 +}
10494 +
10495 +
10496 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10497 +
10498 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10499 +       const char *_file, int _line)
10500 +{
10501 +       struct nx_info *nxi;
10502 +
10503 +       task_lock(p);
10504 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10505 +               p, _file, _line);
10506 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10507 +       task_unlock(p);
10508 +       return nxi;
10509 +}
10510 +
10511 +
10512 +static inline void exit_nx_info(struct task_struct *p)
10513 +{
10514 +       if (p->nx_info)
10515 +               release_nx_info(p->nx_info, p);
10516 +}
10517 +
10518 +
10519 +#else
10520 +#warning duplicate inclusion
10521 +#endif
10522 diff -NurpP --minimal linux-3.2.5/include/linux/vs_pid.h linux-3.2.5-vs2.3.2.6/include/linux/vs_pid.h
10523 --- linux-3.2.5/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10524 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_pid.h        2011-12-05 19:33:02.000000000 +0100
10525 @@ -0,0 +1,50 @@
10526 +#ifndef _VS_PID_H
10527 +#define _VS_PID_H
10528 +
10529 +#include "vserver/base.h"
10530 +#include "vserver/check.h"
10531 +#include "vserver/context.h"
10532 +#include "vserver/debug.h"
10533 +#include "vserver/pid.h"
10534 +#include <linux/pid_namespace.h>
10535 +
10536 +
10537 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10538 +
10539 +static inline
10540 +int vx_proc_task_visible(struct task_struct *task)
10541 +{
10542 +       if ((task->pid == 1) &&
10543 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10544 +               /* show a blend through init */
10545 +               goto visible;
10546 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10547 +               goto visible;
10548 +       return 0;
10549 +visible:
10550 +       return 1;
10551 +}
10552 +
10553 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10554 +
10555 +
10556 +static inline
10557 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10558 +{
10559 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10560 +
10561 +       if (task && !vx_proc_task_visible(task)) {
10562 +               vxdprintk(VXD_CBIT(misc, 6),
10563 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10564 +                       task, task->xid, task->pid,
10565 +                       current, current->xid, current->pid);
10566 +               put_task_struct(task);
10567 +               task = NULL;
10568 +       }
10569 +       return task;
10570 +}
10571 +
10572 +
10573 +#else
10574 +#warning duplicate inclusion
10575 +#endif
10576 diff -NurpP --minimal linux-3.2.5/include/linux/vs_sched.h linux-3.2.5-vs2.3.2.6/include/linux/vs_sched.h
10577 --- linux-3.2.5/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10578 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_sched.h      2011-12-05 19:33:02.000000000 +0100
10579 @@ -0,0 +1,40 @@
10580 +#ifndef _VS_SCHED_H
10581 +#define _VS_SCHED_H
10582 +
10583 +#include "vserver/base.h"
10584 +#include "vserver/context.h"
10585 +#include "vserver/sched.h"
10586 +
10587 +
10588 +#define MAX_PRIO_BIAS           20
10589 +#define MIN_PRIO_BIAS          -20
10590 +
10591 +static inline
10592 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10593 +{
10594 +       struct vx_info *vxi = p->vx_info;
10595 +
10596 +       if (vxi)
10597 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10598 +       return prio;
10599 +}
10600 +
10601 +static inline void vx_account_user(struct vx_info *vxi,
10602 +       cputime_t cputime, int nice)
10603 +{
10604 +       if (!vxi)
10605 +               return;
10606 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10607 +}
10608 +
10609 +static inline void vx_account_system(struct vx_info *vxi,
10610 +       cputime_t cputime, int idle)
10611 +{
10612 +       if (!vxi)
10613 +               return;
10614 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10615 +}
10616 +
10617 +#else
10618 +#warning duplicate inclusion
10619 +#endif
10620 diff -NurpP --minimal linux-3.2.5/include/linux/vs_socket.h linux-3.2.5-vs2.3.2.6/include/linux/vs_socket.h
10621 --- linux-3.2.5/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10622 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_socket.h     2011-12-05 19:33:02.000000000 +0100
10623 @@ -0,0 +1,67 @@
10624 +#ifndef _VS_SOCKET_H
10625 +#define _VS_SOCKET_H
10626 +
10627 +#include "vserver/debug.h"
10628 +#include "vserver/base.h"
10629 +#include "vserver/cacct.h"
10630 +#include "vserver/context.h"
10631 +#include "vserver/tag.h"
10632 +
10633 +
10634 +/* socket accounting */
10635 +
10636 +#include <linux/socket.h>
10637 +
10638 +static inline int vx_sock_type(int family)
10639 +{
10640 +       switch (family) {
10641 +       case PF_UNSPEC:
10642 +               return VXA_SOCK_UNSPEC;
10643 +       case PF_UNIX:
10644 +               return VXA_SOCK_UNIX;
10645 +       case PF_INET:
10646 +               return VXA_SOCK_INET;
10647 +       case PF_INET6:
10648 +               return VXA_SOCK_INET6;
10649 +       case PF_PACKET:
10650 +               return VXA_SOCK_PACKET;
10651 +       default:
10652 +               return VXA_SOCK_OTHER;
10653 +       }
10654 +}
10655 +
10656 +#define vx_acc_sock(v, f, p, s) \
10657 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10658 +
10659 +static inline void __vx_acc_sock(struct vx_info *vxi,
10660 +       int family, int pos, int size, char *file, int line)
10661 +{
10662 +       if (vxi) {
10663 +               int type = vx_sock_type(family);
10664 +
10665 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10666 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10667 +       }
10668 +}
10669 +
10670 +#define vx_sock_recv(sk, s) \
10671 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10672 +#define vx_sock_send(sk, s) \
10673 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10674 +#define vx_sock_fail(sk, s) \
10675 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10676 +
10677 +
10678 +#define sock_vx_init(s) do {           \
10679 +       (s)->sk_xid = 0;                \
10680 +       (s)->sk_vx_info = NULL;         \
10681 +       } while (0)
10682 +
10683 +#define sock_nx_init(s) do {           \
10684 +       (s)->sk_nid = 0;                \
10685 +       (s)->sk_nx_info = NULL;         \
10686 +       } while (0)
10687 +
10688 +#else
10689 +#warning duplicate inclusion
10690 +#endif
10691 diff -NurpP --minimal linux-3.2.5/include/linux/vs_tag.h linux-3.2.5-vs2.3.2.6/include/linux/vs_tag.h
10692 --- linux-3.2.5/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10693 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_tag.h        2011-12-05 19:33:02.000000000 +0100
10694 @@ -0,0 +1,47 @@
10695 +#ifndef _VS_TAG_H
10696 +#define _VS_TAG_H
10697 +
10698 +#include <linux/vserver/tag.h>
10699 +
10700 +/* check conditions */
10701 +
10702 +#define DX_ADMIN       0x0001
10703 +#define DX_WATCH       0x0002
10704 +#define DX_HOSTID      0x0008
10705 +
10706 +#define DX_IDENT       0x0010
10707 +
10708 +#define DX_ARG_MASK    0x0010
10709 +
10710 +
10711 +#define dx_task_tag(t) ((t)->tag)
10712 +
10713 +#define dx_current_tag() dx_task_tag(current)
10714 +
10715 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10716 +
10717 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10718 +
10719 +
10720 +/*
10721 + * check current context for ADMIN/WATCH and
10722 + * optionally against supplied argument
10723 + */
10724 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10725 +{
10726 +       if (mode & DX_ARG_MASK) {
10727 +               if ((mode & DX_IDENT) && (id == cid))
10728 +                       return 1;
10729 +       }
10730 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10731 +               ((mode & DX_WATCH) && (cid == 1)) ||
10732 +               ((mode & DX_HOSTID) && (id == 0)));
10733 +}
10734 +
10735 +struct inode;
10736 +int dx_permission(const struct inode *inode, int mask);
10737 +
10738 +
10739 +#else
10740 +#warning duplicate inclusion
10741 +#endif
10742 diff -NurpP --minimal linux-3.2.5/include/linux/vs_time.h linux-3.2.5-vs2.3.2.6/include/linux/vs_time.h
10743 --- linux-3.2.5/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10744 +++ linux-3.2.5-vs2.3.2.6/include/linux/vs_time.h       2011-12-05 19:33:02.000000000 +0100
10745 @@ -0,0 +1,19 @@
10746 +#ifndef _VS_TIME_H
10747 +#define _VS_TIME_H
10748 +
10749 +
10750 +/* time faking stuff */
10751 +
10752 +#ifdef CONFIG_VSERVER_VTIME
10753 +
10754 +extern void vx_adjust_timespec(struct timespec *ts);
10755 +extern int vx_settimeofday(const struct timespec *ts);
10756 +
10757 +#else
10758 +#define        vx_adjust_timespec(t)   do { } while (0)
10759 +#define        vx_settimeofday(t)      do_settimeofday(t)
10760 +#endif
10761 +
10762 +#else
10763 +#warning duplicate inclusion
10764 +#endif
10765 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/Kbuild linux-3.2.5-vs2.3.2.6/include/linux/vserver/Kbuild
10766 --- linux-3.2.5/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10767 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/Kbuild  2011-12-05 19:33:02.000000000 +0100
10768 @@ -0,0 +1,8 @@
10769 +
10770 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10771 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10772 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10773 +       debug_cmd.h device_cmd.h
10774 +
10775 +header-y += switch.h network.h monitor.h inode.h device.h
10776 +
10777 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/base.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/base.h
10778 --- linux-3.2.5/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
10779 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/base.h  2011-12-05 19:33:02.000000000 +0100
10780 @@ -0,0 +1,178 @@
10781 +#ifndef _VX_BASE_H
10782 +#define _VX_BASE_H
10783 +
10784 +
10785 +/* context state changes */
10786 +
10787 +enum {
10788 +       VSC_STARTUP = 1,
10789 +       VSC_SHUTDOWN,
10790 +
10791 +       VSC_NETUP,
10792 +       VSC_NETDOWN,
10793 +};
10794 +
10795 +
10796 +
10797 +#define vx_task_xid(t) ((t)->xid)
10798 +
10799 +#define vx_current_xid() vx_task_xid(current)
10800 +
10801 +#define current_vx_info() (current->vx_info)
10802 +
10803 +
10804 +#define nx_task_nid(t) ((t)->nid)
10805 +
10806 +#define nx_current_nid() nx_task_nid(current)
10807 +
10808 +#define current_nx_info() (current->nx_info)
10809 +
10810 +
10811 +/* generic flag merging */
10812 +
10813 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10814 +
10815 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10816 +
10817 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10818 +
10819 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10820 +
10821 +
10822 +/* context flags */
10823 +
10824 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10825 +
10826 +#define vx_current_flags()     __vx_flags(current_vx_info())
10827 +
10828 +#define vx_info_flags(v, m, f) \
10829 +       vs_check_flags(__vx_flags(v), m, f)
10830 +
10831 +#define task_vx_flags(t, m, f) \
10832 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10833 +
10834 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10835 +
10836 +
10837 +/* context caps */
10838 +
10839 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10840 +
10841 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10842 +
10843 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10844 +
10845 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10846 +
10847 +
10848 +
10849 +/* network flags */
10850 +
10851 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10852 +
10853 +#define nx_current_flags()     __nx_flags(current_nx_info())
10854 +
10855 +#define nx_info_flags(n, m, f) \
10856 +       vs_check_flags(__nx_flags(n), m, f)
10857 +
10858 +#define task_nx_flags(t, m, f) \
10859 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10860 +
10861 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10862 +
10863 +
10864 +/* network caps */
10865 +
10866 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10867 +
10868 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10869 +
10870 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10871 +
10872 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10873 +
10874 +
10875 +/* context mask capabilities */
10876 +
10877 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10878 +
10879 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10880 +
10881 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10882 +
10883 +
10884 +/* context bcap mask */
10885 +
10886 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10887 +
10888 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10889 +
10890 +
10891 +/* mask given bcaps */
10892 +
10893 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10894 +
10895 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10896 +
10897 +
10898 +/* masked cap_bset */
10899 +
10900 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10901 +
10902 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10903 +
10904 +#if 0
10905 +#define vx_info_mbcap(v, b) \
10906 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10907 +       vx_info_bcaps(v, b) : (b))
10908 +
10909 +#define task_vx_mbcap(t, b) \
10910 +       vx_info_mbcap((t)->vx_info, (t)->b)
10911 +
10912 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10913 +#endif
10914 +
10915 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10916 +
10917 +#define vx_capable(b, c) (capable(b) || \
10918 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10919 +
10920 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10921 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10922 +
10923 +#define nx_capable(b, c) (capable(b) || \
10924 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10925 +
10926 +#define vx_task_initpid(t, n) \
10927 +       ((t)->vx_info && \
10928 +       ((t)->vx_info->vx_initpid == (n)))
10929 +
10930 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10931 +
10932 +
10933 +/* context unshare mask */
10934 +
10935 +#define __vx_umask(v)          ((v)->vx_umask)
10936 +
10937 +#define vx_current_umask()     __vx_umask(current_vx_info())
10938 +
10939 +#define vx_can_unshare(b, f) (capable(b) || \
10940 +       (cap_raised(current_cap(), b) && \
10941 +       !((f) & ~vx_current_umask())))
10942 +
10943 +
10944 +#define __vx_wmask(v)          ((v)->vx_wmask)
10945 +
10946 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10947 +
10948 +
10949 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10950 +
10951 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10952 +
10953 +
10954 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10955 +
10956 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10957 +
10958 +#endif
10959 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cacct.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct.h
10960 --- linux-3.2.5/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
10961 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct.h 2011-12-05 19:33:02.000000000 +0100
10962 @@ -0,0 +1,15 @@
10963 +#ifndef _VX_CACCT_H
10964 +#define _VX_CACCT_H
10965 +
10966 +
10967 +enum sock_acc_field {
10968 +       VXA_SOCK_UNSPEC = 0,
10969 +       VXA_SOCK_UNIX,
10970 +       VXA_SOCK_INET,
10971 +       VXA_SOCK_INET6,
10972 +       VXA_SOCK_PACKET,
10973 +       VXA_SOCK_OTHER,
10974 +       VXA_SOCK_SIZE   /* array size */
10975 +};
10976 +
10977 +#endif /* _VX_CACCT_H */
10978 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cacct_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct_cmd.h
10979 --- linux-3.2.5/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
10980 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct_cmd.h     2011-12-05 19:33:02.000000000 +0100
10981 @@ -0,0 +1,23 @@
10982 +#ifndef _VX_CACCT_CMD_H
10983 +#define _VX_CACCT_CMD_H
10984 +
10985 +
10986 +/* virtual host info name commands */
10987 +
10988 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10989 +
10990 +struct vcmd_sock_stat_v0 {
10991 +       uint32_t field;
10992 +       uint32_t count[3];
10993 +       uint64_t total[3];
10994 +};
10995 +
10996 +
10997 +#ifdef __KERNEL__
10998 +
10999 +#include <linux/compiler.h>
11000 +
11001 +extern int vc_sock_stat(struct vx_info *, void __user *);
11002 +
11003 +#endif /* __KERNEL__ */
11004 +#endif /* _VX_CACCT_CMD_H */
11005 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cacct_def.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct_def.h
11006 --- linux-3.2.5/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
11007 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct_def.h     2011-12-05 19:33:02.000000000 +0100
11008 @@ -0,0 +1,43 @@
11009 +#ifndef _VX_CACCT_DEF_H
11010 +#define _VX_CACCT_DEF_H
11011 +
11012 +#include <asm/atomic.h>
11013 +#include <linux/vserver/cacct.h>
11014 +
11015 +
11016 +struct _vx_sock_acc {
11017 +       atomic_long_t count;
11018 +       atomic_long_t total;
11019 +};
11020 +
11021 +/* context sub struct */
11022 +
11023 +struct _vx_cacct {
11024 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11025 +       atomic_t slab[8];
11026 +       atomic_t page[6][8];
11027 +};
11028 +
11029 +#ifdef CONFIG_VSERVER_DEBUG
11030 +
11031 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11032 +{
11033 +       int i, j;
11034 +
11035 +       printk("\t_vx_cacct:");
11036 +       for (i = 0; i < 6; i++) {
11037 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11038 +
11039 +               printk("\t [%d] =", i);
11040 +               for (j = 0; j < 3; j++) {
11041 +                       printk(" [%d] = %8lu, %8lu", j,
11042 +                               atomic_long_read(&ptr[j].count),
11043 +                               atomic_long_read(&ptr[j].total));
11044 +               }
11045 +               printk("\n");
11046 +       }
11047 +}
11048 +
11049 +#endif
11050 +
11051 +#endif /* _VX_CACCT_DEF_H */
11052 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cacct_int.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct_int.h
11053 --- linux-3.2.5/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
11054 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cacct_int.h     2011-12-05 19:33:02.000000000 +0100
11055 @@ -0,0 +1,21 @@
11056 +#ifndef _VX_CACCT_INT_H
11057 +#define _VX_CACCT_INT_H
11058 +
11059 +
11060 +#ifdef __KERNEL__
11061 +
11062 +static inline
11063 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11064 +{
11065 +       return atomic_long_read(&cacct->sock[type][pos].count);
11066 +}
11067 +
11068 +
11069 +static inline
11070 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11071 +{
11072 +       return atomic_long_read(&cacct->sock[type][pos].total);
11073 +}
11074 +
11075 +#endif /* __KERNEL__ */
11076 +#endif /* _VX_CACCT_INT_H */
11077 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/check.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/check.h
11078 --- linux-3.2.5/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
11079 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/check.h 2011-12-05 19:33:02.000000000 +0100
11080 @@ -0,0 +1,89 @@
11081 +#ifndef _VS_CHECK_H
11082 +#define _VS_CHECK_H
11083 +
11084 +
11085 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11086 +
11087 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11088 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11089 +#else
11090 +#define MIN_D_CONTEXT  65536
11091 +#endif
11092 +
11093 +/* check conditions */
11094 +
11095 +#define VS_ADMIN       0x0001
11096 +#define VS_WATCH       0x0002
11097 +#define VS_HIDE                0x0004
11098 +#define VS_HOSTID      0x0008
11099 +
11100 +#define VS_IDENT       0x0010
11101 +#define VS_EQUIV       0x0020
11102 +#define VS_PARENT      0x0040
11103 +#define VS_CHILD       0x0080
11104 +
11105 +#define VS_ARG_MASK    0x00F0
11106 +
11107 +#define VS_DYNAMIC     0x0100
11108 +#define VS_STATIC      0x0200
11109 +
11110 +#define VS_ATR_MASK    0x0F00
11111 +
11112 +#ifdef CONFIG_VSERVER_PRIVACY
11113 +#define VS_ADMIN_P     (0)
11114 +#define VS_WATCH_P     (0)
11115 +#else
11116 +#define VS_ADMIN_P     VS_ADMIN
11117 +#define VS_WATCH_P     VS_WATCH
11118 +#endif
11119 +
11120 +#define VS_HARDIRQ     0x1000
11121 +#define VS_SOFTIRQ     0x2000
11122 +#define VS_IRQ         0x4000
11123 +
11124 +#define VS_IRQ_MASK    0xF000
11125 +
11126 +#include <linux/hardirq.h>
11127 +
11128 +/*
11129 + * check current context for ADMIN/WATCH and
11130 + * optionally against supplied argument
11131 + */
11132 +static inline int __vs_check(int cid, int id, unsigned int mode)
11133 +{
11134 +       if (mode & VS_ARG_MASK) {
11135 +               if ((mode & VS_IDENT) && (id == cid))
11136 +                       return 1;
11137 +       }
11138 +       if (mode & VS_ATR_MASK) {
11139 +               if ((mode & VS_DYNAMIC) &&
11140 +                       (id >= MIN_D_CONTEXT) &&
11141 +                       (id <= MAX_S_CONTEXT))
11142 +                       return 1;
11143 +               if ((mode & VS_STATIC) &&
11144 +                       (id > 1) && (id < MIN_D_CONTEXT))
11145 +                       return 1;
11146 +       }
11147 +       if (mode & VS_IRQ_MASK) {
11148 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11149 +                       return 1;
11150 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11151 +                       return 1;
11152 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11153 +                       return 1;
11154 +       }
11155 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11156 +               ((mode & VS_WATCH) && (cid == 1)) ||
11157 +               ((mode & VS_HOSTID) && (id == 0)));
11158 +}
11159 +
11160 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11161 +
11162 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11163 +
11164 +
11165 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11166 +
11167 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11168 +
11169 +#endif
11170 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/context.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/context.h
11171 --- linux-3.2.5/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11172 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/context.h       2011-12-05 19:33:02.000000000 +0100
11173 @@ -0,0 +1,188 @@
11174 +#ifndef _VX_CONTEXT_H
11175 +#define _VX_CONTEXT_H
11176 +
11177 +#include <linux/types.h>
11178 +#include <linux/capability.h>
11179 +
11180 +
11181 +/* context flags */
11182 +
11183 +#define VXF_INFO_SCHED         0x00000002
11184 +#define VXF_INFO_NPROC         0x00000004
11185 +#define VXF_INFO_PRIVATE       0x00000008
11186 +
11187 +#define VXF_INFO_INIT          0x00000010
11188 +#define VXF_INFO_HIDE          0x00000020
11189 +#define VXF_INFO_ULIMIT                0x00000040
11190 +#define VXF_INFO_NSPACE                0x00000080
11191 +
11192 +#define VXF_SCHED_HARD         0x00000100
11193 +#define VXF_SCHED_PRIO         0x00000200
11194 +#define VXF_SCHED_PAUSE                0x00000400
11195 +
11196 +#define VXF_VIRT_MEM           0x00010000
11197 +#define VXF_VIRT_UPTIME                0x00020000
11198 +#define VXF_VIRT_CPU           0x00040000
11199 +#define VXF_VIRT_LOAD          0x00080000
11200 +#define VXF_VIRT_TIME          0x00100000
11201 +
11202 +#define VXF_HIDE_MOUNT         0x01000000
11203 +/* was VXF_HIDE_NETIF          0x02000000 */
11204 +#define VXF_HIDE_VINFO         0x04000000
11205 +
11206 +#define VXF_STATE_SETUP                (1ULL << 32)
11207 +#define VXF_STATE_INIT         (1ULL << 33)
11208 +#define VXF_STATE_ADMIN                (1ULL << 34)
11209 +
11210 +#define VXF_SC_HELPER          (1ULL << 36)
11211 +#define VXF_REBOOT_KILL                (1ULL << 37)
11212 +#define VXF_PERSISTENT         (1ULL << 38)
11213 +
11214 +#define VXF_FORK_RSS           (1ULL << 48)
11215 +#define VXF_PROLIFIC           (1ULL << 49)
11216 +
11217 +#define VXF_IGNEG_NICE         (1ULL << 52)
11218 +
11219 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11220 +
11221 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11222 +
11223 +
11224 +/* context migration */
11225 +
11226 +#define VXM_SET_INIT           0x00000001
11227 +#define VXM_SET_REAPER         0x00000002
11228 +
11229 +/* context caps */
11230 +
11231 +#define VXC_SET_UTSNAME                0x00000001
11232 +#define VXC_SET_RLIMIT         0x00000002
11233 +#define VXC_FS_SECURITY                0x00000004
11234 +#define VXC_FS_TRUSTED         0x00000008
11235 +#define VXC_TIOCSTI            0x00000010
11236 +
11237 +/* was VXC_RAW_ICMP            0x00000100 */
11238 +#define VXC_SYSLOG             0x00001000
11239 +#define VXC_OOM_ADJUST         0x00002000
11240 +#define VXC_AUDIT_CONTROL      0x00004000
11241 +
11242 +#define VXC_SECURE_MOUNT       0x00010000
11243 +#define VXC_SECURE_REMOUNT     0x00020000
11244 +#define VXC_BINARY_MOUNT       0x00040000
11245 +
11246 +#define VXC_QUOTA_CTL          0x00100000
11247 +#define VXC_ADMIN_MAPPER       0x00200000
11248 +#define VXC_ADMIN_CLOOP                0x00400000
11249 +
11250 +#define VXC_KTHREAD            0x01000000
11251 +#define VXC_NAMESPACE          0x02000000
11252 +
11253 +
11254 +#ifdef __KERNEL__
11255 +
11256 +#include <linux/list.h>
11257 +#include <linux/spinlock.h>
11258 +#include <linux/rcupdate.h>
11259 +
11260 +#include "limit_def.h"
11261 +#include "sched_def.h"
11262 +#include "cvirt_def.h"
11263 +#include "cacct_def.h"
11264 +#include "device_def.h"
11265 +
11266 +#define VX_SPACES      2
11267 +
11268 +struct _vx_info_pc {
11269 +       struct _vx_sched_pc sched_pc;
11270 +       struct _vx_cvirt_pc cvirt_pc;
11271 +};
11272 +
11273 +struct _vx_space {
11274 +       unsigned long vx_nsmask;                /* assignment mask */
11275 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11276 +       struct fs_struct *vx_fs;                /* private namespace fs */
11277 +       const struct cred *vx_cred;             /* task credentials */
11278 +};
11279 +
11280 +struct vx_info {
11281 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11282 +       xid_t vx_id;                            /* context id */
11283 +       atomic_t vx_usecnt;                     /* usage count */
11284 +       atomic_t vx_tasks;                      /* tasks count */
11285 +       struct vx_info *vx_parent;              /* parent context */
11286 +       int vx_state;                           /* context state */
11287 +
11288 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11289 +
11290 +       uint64_t vx_flags;                      /* context flags */
11291 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11292 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11293 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11294 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11295 +
11296 +       struct task_struct *vx_reaper;          /* guest reaper process */
11297 +       pid_t vx_initpid;                       /* PID of guest init */
11298 +       int64_t vx_badness_bias;                /* OOM points bias */
11299 +
11300 +       struct _vx_limit limit;                 /* vserver limits */
11301 +       struct _vx_sched sched;                 /* vserver scheduler */
11302 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11303 +       struct _vx_cacct cacct;                 /* context accounting */
11304 +
11305 +       struct _vx_device dmap;                 /* default device map targets */
11306 +
11307 +#ifndef CONFIG_SMP
11308 +       struct _vx_info_pc info_pc;             /* per cpu data */
11309 +#else
11310 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11311 +#endif
11312 +
11313 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11314 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11315 +       int exit_code;                          /* last process exit code */
11316 +
11317 +       char vx_name[65];                       /* vserver name */
11318 +};
11319 +
11320 +#ifndef CONFIG_SMP
11321 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11322 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11323 +#else
11324 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11325 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11326 +#endif
11327 +
11328 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11329 +
11330 +
11331 +struct vx_info_save {
11332 +       struct vx_info *vxi;
11333 +       xid_t xid;
11334 +};
11335 +
11336 +
11337 +/* status flags */
11338 +
11339 +#define VXS_HASHED     0x0001
11340 +#define VXS_PAUSED     0x0010
11341 +#define VXS_SHUTDOWN   0x0100
11342 +#define VXS_HELPER     0x1000
11343 +#define VXS_RELEASED   0x8000
11344 +
11345 +
11346 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11347 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11348 +
11349 +extern struct vx_info *lookup_vx_info(int);
11350 +extern struct vx_info *lookup_or_create_vx_info(int);
11351 +
11352 +extern int get_xid_list(int, unsigned int *, int);
11353 +extern int xid_is_hashed(xid_t);
11354 +
11355 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11356 +
11357 +extern long vs_state_change(struct vx_info *, unsigned int);
11358 +
11359 +
11360 +#endif /* __KERNEL__ */
11361 +#endif /* _VX_CONTEXT_H */
11362 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/context_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/context_cmd.h
11363 --- linux-3.2.5/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11364 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/context_cmd.h   2011-12-05 19:33:02.000000000 +0100
11365 @@ -0,0 +1,162 @@
11366 +#ifndef _VX_CONTEXT_CMD_H
11367 +#define _VX_CONTEXT_CMD_H
11368 +
11369 +
11370 +/* vinfo commands */
11371 +
11372 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11373 +
11374 +#ifdef __KERNEL__
11375 +extern int vc_task_xid(uint32_t);
11376 +
11377 +#endif /* __KERNEL__ */
11378 +
11379 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11380 +
11381 +struct vcmd_vx_info_v0 {
11382 +       uint32_t xid;
11383 +       uint32_t initpid;
11384 +       /* more to come */
11385 +};
11386 +
11387 +#ifdef __KERNEL__
11388 +extern int vc_vx_info(struct vx_info *, void __user *);
11389 +
11390 +#endif /* __KERNEL__ */
11391 +
11392 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11393 +
11394 +struct vcmd_ctx_stat_v0 {
11395 +       uint32_t usecnt;
11396 +       uint32_t tasks;
11397 +       /* more to come */
11398 +};
11399 +
11400 +#ifdef __KERNEL__
11401 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11402 +
11403 +#endif /* __KERNEL__ */
11404 +
11405 +/* context commands */
11406 +
11407 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11408 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11409 +
11410 +struct vcmd_ctx_create {
11411 +       uint64_t flagword;
11412 +};
11413 +
11414 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11415 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11416 +
11417 +struct vcmd_ctx_migrate {
11418 +       uint64_t flagword;
11419 +};
11420 +
11421 +#ifdef __KERNEL__
11422 +extern int vc_ctx_create(uint32_t, void __user *);
11423 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11424 +
11425 +#endif /* __KERNEL__ */
11426 +
11427 +
11428 +/* flag commands */
11429 +
11430 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11431 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11432 +
11433 +struct vcmd_ctx_flags_v0 {
11434 +       uint64_t flagword;
11435 +       uint64_t mask;
11436 +};
11437 +
11438 +#ifdef __KERNEL__
11439 +extern int vc_get_cflags(struct vx_info *, void __user *);
11440 +extern int vc_set_cflags(struct vx_info *, void __user *);
11441 +
11442 +#endif /* __KERNEL__ */
11443 +
11444 +
11445 +/* context caps commands */
11446 +
11447 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11448 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11449 +
11450 +struct vcmd_ctx_caps_v1 {
11451 +       uint64_t ccaps;
11452 +       uint64_t cmask;
11453 +};
11454 +
11455 +#ifdef __KERNEL__
11456 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11457 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11458 +
11459 +#endif /* __KERNEL__ */
11460 +
11461 +
11462 +/* bcaps commands */
11463 +
11464 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11465 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11466 +
11467 +struct vcmd_bcaps {
11468 +       uint64_t bcaps;
11469 +       uint64_t bmask;
11470 +};
11471 +
11472 +#ifdef __KERNEL__
11473 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11474 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11475 +
11476 +#endif /* __KERNEL__ */
11477 +
11478 +
11479 +/* umask commands */
11480 +
11481 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11482 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11483 +
11484 +struct vcmd_umask {
11485 +       uint64_t umask;
11486 +       uint64_t mask;
11487 +};
11488 +
11489 +#ifdef __KERNEL__
11490 +extern int vc_get_umask(struct vx_info *, void __user *);
11491 +extern int vc_set_umask(struct vx_info *, void __user *);
11492 +
11493 +#endif /* __KERNEL__ */
11494 +
11495 +
11496 +/* wmask commands */
11497 +
11498 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11499 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11500 +
11501 +struct vcmd_wmask {
11502 +       uint64_t wmask;
11503 +       uint64_t mask;
11504 +};
11505 +
11506 +#ifdef __KERNEL__
11507 +extern int vc_get_wmask(struct vx_info *, void __user *);
11508 +extern int vc_set_wmask(struct vx_info *, void __user *);
11509 +
11510 +#endif /* __KERNEL__ */
11511 +
11512 +
11513 +/* OOM badness */
11514 +
11515 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11516 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11517 +
11518 +struct vcmd_badness_v0 {
11519 +       int64_t bias;
11520 +};
11521 +
11522 +#ifdef __KERNEL__
11523 +extern int vc_get_badness(struct vx_info *, void __user *);
11524 +extern int vc_set_badness(struct vx_info *, void __user *);
11525 +
11526 +#endif /* __KERNEL__ */
11527 +#endif /* _VX_CONTEXT_CMD_H */
11528 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cvirt.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cvirt.h
11529 --- linux-3.2.5/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11530 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cvirt.h 2011-12-05 19:33:02.000000000 +0100
11531 @@ -0,0 +1,20 @@
11532 +#ifndef _VX_CVIRT_H
11533 +#define _VX_CVIRT_H
11534 +
11535 +
11536 +#ifdef __KERNEL__
11537 +
11538 +struct timespec;
11539 +
11540 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11541 +
11542 +
11543 +struct vx_info;
11544 +
11545 +void vx_update_load(struct vx_info *);
11546 +
11547 +
11548 +int vx_do_syslog(int, char __user *, int);
11549 +
11550 +#endif /* __KERNEL__ */
11551 +#endif /* _VX_CVIRT_H */
11552 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cvirt_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cvirt_cmd.h
11553 --- linux-3.2.5/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11554 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cvirt_cmd.h     2011-12-05 19:33:02.000000000 +0100
11555 @@ -0,0 +1,53 @@
11556 +#ifndef _VX_CVIRT_CMD_H
11557 +#define _VX_CVIRT_CMD_H
11558 +
11559 +
11560 +/* virtual host info name commands */
11561 +
11562 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11563 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11564 +
11565 +struct vcmd_vhi_name_v0 {
11566 +       uint32_t field;
11567 +       char name[65];
11568 +};
11569 +
11570 +
11571 +enum vhi_name_field {
11572 +       VHIN_CONTEXT = 0,
11573 +       VHIN_SYSNAME,
11574 +       VHIN_NODENAME,
11575 +       VHIN_RELEASE,
11576 +       VHIN_VERSION,
11577 +       VHIN_MACHINE,
11578 +       VHIN_DOMAINNAME,
11579 +};
11580 +
11581 +
11582 +#ifdef __KERNEL__
11583 +
11584 +#include <linux/compiler.h>
11585 +
11586 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11587 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11588 +
11589 +#endif /* __KERNEL__ */
11590 +
11591 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11592 +
11593 +struct vcmd_virt_stat_v0 {
11594 +       uint64_t offset;
11595 +       uint64_t uptime;
11596 +       uint32_t nr_threads;
11597 +       uint32_t nr_running;
11598 +       uint32_t nr_uninterruptible;
11599 +       uint32_t nr_onhold;
11600 +       uint32_t nr_forks;
11601 +       uint32_t load[3];
11602 +};
11603 +
11604 +#ifdef __KERNEL__
11605 +extern int vc_virt_stat(struct vx_info *, void __user *);
11606 +
11607 +#endif /* __KERNEL__ */
11608 +#endif /* _VX_CVIRT_CMD_H */
11609 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/cvirt_def.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/cvirt_def.h
11610 --- linux-3.2.5/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11611 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/cvirt_def.h     2011-12-05 19:33:02.000000000 +0100
11612 @@ -0,0 +1,80 @@
11613 +#ifndef _VX_CVIRT_DEF_H
11614 +#define _VX_CVIRT_DEF_H
11615 +
11616 +#include <linux/jiffies.h>
11617 +#include <linux/spinlock.h>
11618 +#include <linux/wait.h>
11619 +#include <linux/time.h>
11620 +#include <asm/atomic.h>
11621 +
11622 +
11623 +struct _vx_usage_stat {
11624 +       uint64_t user;
11625 +       uint64_t nice;
11626 +       uint64_t system;
11627 +       uint64_t softirq;
11628 +       uint64_t irq;
11629 +       uint64_t idle;
11630 +       uint64_t iowait;
11631 +};
11632 +
11633 +struct _vx_syslog {
11634 +       wait_queue_head_t log_wait;
11635 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11636 +
11637 +       unsigned long log_start;        /* next char to be read by syslog() */
11638 +       unsigned long con_start;        /* next char to be sent to consoles */
11639 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11640 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11641 +
11642 +       char log_buf[1024];
11643 +};
11644 +
11645 +
11646 +/* context sub struct */
11647 +
11648 +struct _vx_cvirt {
11649 +       atomic_t nr_threads;            /* number of current threads */
11650 +       atomic_t nr_running;            /* number of running threads */
11651 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11652 +
11653 +       atomic_t nr_onhold;             /* processes on hold */
11654 +       uint32_t onhold_last;           /* jiffies when put on hold */
11655 +
11656 +       struct timespec bias_ts;        /* time offset to the host */
11657 +       struct timespec bias_idle;
11658 +       struct timespec bias_uptime;    /* context creation point */
11659 +       uint64_t bias_clock;            /* offset in clock_t */
11660 +
11661 +       spinlock_t load_lock;           /* lock for the load averages */
11662 +       atomic_t load_updates;          /* nr of load updates done so far */
11663 +       uint32_t load_last;             /* last time load was calculated */
11664 +       uint32_t load[3];               /* load averages 1,5,15 */
11665 +
11666 +       atomic_t total_forks;           /* number of forks so far */
11667 +
11668 +       struct _vx_syslog syslog;
11669 +};
11670 +
11671 +struct _vx_cvirt_pc {
11672 +       struct _vx_usage_stat cpustat;
11673 +};
11674 +
11675 +
11676 +#ifdef CONFIG_VSERVER_DEBUG
11677 +
11678 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11679 +{
11680 +       printk("\t_vx_cvirt:\n");
11681 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11682 +               atomic_read(&cvirt->nr_threads),
11683 +               atomic_read(&cvirt->nr_running),
11684 +               atomic_read(&cvirt->nr_uninterruptible),
11685 +               atomic_read(&cvirt->nr_onhold));
11686 +       /* add rest here */
11687 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11688 +}
11689 +
11690 +#endif
11691 +
11692 +#endif /* _VX_CVIRT_DEF_H */
11693 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/debug.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/debug.h
11694 --- linux-3.2.5/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11695 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/debug.h 2011-12-05 19:33:02.000000000 +0100
11696 @@ -0,0 +1,145 @@
11697 +#ifndef _VX_DEBUG_H
11698 +#define _VX_DEBUG_H
11699 +
11700 +
11701 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11702 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11703 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11704 +
11705 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11706 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11707 +#define VXF_DEV                "%p[%lu,%d:%d]"
11708 +
11709 +#if    defined(CONFIG_QUOTES_UTF8)
11710 +#define        VS_Q_LQM        "\xc2\xbb"
11711 +#define        VS_Q_RQM        "\xc2\xab"
11712 +#elif  defined(CONFIG_QUOTES_ASCII)
11713 +#define        VS_Q_LQM        "\x27"
11714 +#define        VS_Q_RQM        "\x27"
11715 +#else
11716 +#define        VS_Q_LQM        "\xbb"
11717 +#define        VS_Q_RQM        "\xab"
11718 +#endif
11719 +
11720 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11721 +
11722 +
11723 +#define vxd_path(p)                                            \
11724 +       ({ static char _buffer[PATH_MAX];                       \
11725 +          d_path(p, _buffer, sizeof(_buffer)); })
11726 +
11727 +#define vxd_cond_path(n)                                       \
11728 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11729 +
11730 +
11731 +#ifdef CONFIG_VSERVER_DEBUG
11732 +
11733 +extern unsigned int vs_debug_switch;
11734 +extern unsigned int vs_debug_xid;
11735 +extern unsigned int vs_debug_nid;
11736 +extern unsigned int vs_debug_tag;
11737 +extern unsigned int vs_debug_net;
11738 +extern unsigned int vs_debug_limit;
11739 +extern unsigned int vs_debug_cres;
11740 +extern unsigned int vs_debug_dlim;
11741 +extern unsigned int vs_debug_quota;
11742 +extern unsigned int vs_debug_cvirt;
11743 +extern unsigned int vs_debug_space;
11744 +extern unsigned int vs_debug_perm;
11745 +extern unsigned int vs_debug_misc;
11746 +
11747 +
11748 +#define VX_LOGLEVEL    "vxD: "
11749 +#define VX_PROC_FMT    "%p: "
11750 +#define VX_PROCESS     current
11751 +
11752 +#define vxdprintk(c, f, x...)                                  \
11753 +       do {                                                    \
11754 +               if (c)                                          \
11755 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11756 +                               VX_PROCESS , ##x);              \
11757 +       } while (0)
11758 +
11759 +#define vxlprintk(c, f, x...)                                  \
11760 +       do {                                                    \
11761 +               if (c)                                          \
11762 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11763 +       } while (0)
11764 +
11765 +#define vxfprintk(c, f, x...)                                  \
11766 +       do {                                                    \
11767 +               if (c)                                          \
11768 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11769 +       } while (0)
11770 +
11771 +
11772 +struct vx_info;
11773 +
11774 +void dump_vx_info(struct vx_info *, int);
11775 +void dump_vx_info_inactive(int);
11776 +
11777 +#else  /* CONFIG_VSERVER_DEBUG */
11778 +
11779 +#define vs_debug_switch        0
11780 +#define vs_debug_xid   0
11781 +#define vs_debug_nid   0
11782 +#define vs_debug_tag   0
11783 +#define vs_debug_net   0
11784 +#define vs_debug_limit 0
11785 +#define vs_debug_cres  0
11786 +#define vs_debug_dlim  0
11787 +#define vs_debug_quota 0
11788 +#define vs_debug_cvirt 0
11789 +#define vs_debug_space 0
11790 +#define vs_debug_perm  0
11791 +#define vs_debug_misc  0
11792 +
11793 +#define vxdprintk(x...) do { } while (0)
11794 +#define vxlprintk(x...) do { } while (0)
11795 +#define vxfprintk(x...) do { } while (0)
11796 +
11797 +#endif /* CONFIG_VSERVER_DEBUG */
11798 +
11799 +
11800 +#ifdef CONFIG_VSERVER_WARN
11801 +
11802 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11803 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11804 +#define VX_WARN_XID    "[xid #%u] "
11805 +#define VX_WARN_NID    "[nid #%u] "
11806 +#define VX_WARN_TAG    "[tag #%u] "
11807 +
11808 +#define vxwprintk(c, f, x...)                                  \
11809 +       do {                                                    \
11810 +               if (c)                                          \
11811 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11812 +       } while (0)
11813 +
11814 +#else  /* CONFIG_VSERVER_WARN */
11815 +
11816 +#define vxwprintk(x...) do { } while (0)
11817 +
11818 +#endif /* CONFIG_VSERVER_WARN */
11819 +
11820 +#define vxwprintk_task(c, f, x...)                             \
11821 +       vxwprintk(c, VX_WARN_TASK f,                            \
11822 +               current->comm, current->pid,                    \
11823 +               current->xid, current->nid, current->tag, ##x)
11824 +#define vxwprintk_xid(c, f, x...)                              \
11825 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11826 +#define vxwprintk_nid(c, f, x...)                              \
11827 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11828 +#define vxwprintk_tag(c, f, x...)                              \
11829 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11830 +
11831 +#ifdef CONFIG_VSERVER_DEBUG
11832 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11833 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11834 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11835 +#else
11836 +#define vxd_assert_lock(l)     do { } while (0)
11837 +#define vxd_assert(c, f, x...) do { } while (0)
11838 +#endif
11839 +
11840 +
11841 +#endif /* _VX_DEBUG_H */
11842 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/debug_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/debug_cmd.h
11843 --- linux-3.2.5/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
11844 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/debug_cmd.h     2011-12-05 19:33:02.000000000 +0100
11845 @@ -0,0 +1,58 @@
11846 +#ifndef _VX_DEBUG_CMD_H
11847 +#define _VX_DEBUG_CMD_H
11848 +
11849 +
11850 +/* debug commands */
11851 +
11852 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11853 +
11854 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11855 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11856 +
11857 +struct  vcmd_read_history_v0 {
11858 +       uint32_t index;
11859 +       uint32_t count;
11860 +       char __user *data;
11861 +};
11862 +
11863 +struct  vcmd_read_monitor_v0 {
11864 +       uint32_t index;
11865 +       uint32_t count;
11866 +       char __user *data;
11867 +};
11868 +
11869 +
11870 +#ifdef __KERNEL__
11871 +
11872 +#ifdef CONFIG_COMPAT
11873 +
11874 +#include <asm/compat.h>
11875 +
11876 +struct vcmd_read_history_v0_x32 {
11877 +       uint32_t index;
11878 +       uint32_t count;
11879 +       compat_uptr_t data_ptr;
11880 +};
11881 +
11882 +struct vcmd_read_monitor_v0_x32 {
11883 +       uint32_t index;
11884 +       uint32_t count;
11885 +       compat_uptr_t data_ptr;
11886 +};
11887 +
11888 +#endif  /* CONFIG_COMPAT */
11889 +
11890 +extern int vc_dump_history(uint32_t);
11891 +
11892 +extern int vc_read_history(uint32_t, void __user *);
11893 +extern int vc_read_monitor(uint32_t, void __user *);
11894 +
11895 +#ifdef CONFIG_COMPAT
11896 +
11897 +extern int vc_read_history_x32(uint32_t, void __user *);
11898 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11899 +
11900 +#endif  /* CONFIG_COMPAT */
11901 +
11902 +#endif /* __KERNEL__ */
11903 +#endif /* _VX_DEBUG_CMD_H */
11904 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/device.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/device.h
11905 --- linux-3.2.5/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
11906 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/device.h        2011-12-05 19:33:02.000000000 +0100
11907 @@ -0,0 +1,15 @@
11908 +#ifndef _VX_DEVICE_H
11909 +#define _VX_DEVICE_H
11910 +
11911 +
11912 +#define DATTR_CREATE   0x00000001
11913 +#define DATTR_OPEN     0x00000002
11914 +
11915 +#define DATTR_REMAP    0x00000010
11916 +
11917 +#define DATTR_MASK     0x00000013
11918 +
11919 +
11920 +#else  /* _VX_DEVICE_H */
11921 +#warning duplicate inclusion
11922 +#endif /* _VX_DEVICE_H */
11923 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/device_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/device_cmd.h
11924 --- linux-3.2.5/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
11925 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/device_cmd.h    2011-12-05 19:33:02.000000000 +0100
11926 @@ -0,0 +1,44 @@
11927 +#ifndef _VX_DEVICE_CMD_H
11928 +#define _VX_DEVICE_CMD_H
11929 +
11930 +
11931 +/*  device vserver commands */
11932 +
11933 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11934 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11935 +
11936 +struct vcmd_set_mapping_v0 {
11937 +       const char __user *device;
11938 +       const char __user *target;
11939 +       uint32_t flags;
11940 +};
11941 +
11942 +
11943 +#ifdef __KERNEL__
11944 +
11945 +#ifdef CONFIG_COMPAT
11946 +
11947 +#include <asm/compat.h>
11948 +
11949 +struct vcmd_set_mapping_v0_x32 {
11950 +       compat_uptr_t device_ptr;
11951 +       compat_uptr_t target_ptr;
11952 +       uint32_t flags;
11953 +};
11954 +
11955 +#endif /* CONFIG_COMPAT */
11956 +
11957 +#include <linux/compiler.h>
11958 +
11959 +extern int vc_set_mapping(struct vx_info *, void __user *);
11960 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11961 +
11962 +#ifdef CONFIG_COMPAT
11963 +
11964 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11965 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11966 +
11967 +#endif /* CONFIG_COMPAT */
11968 +
11969 +#endif /* __KERNEL__ */
11970 +#endif /* _VX_DEVICE_CMD_H */
11971 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/device_def.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/device_def.h
11972 --- linux-3.2.5/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
11973 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/device_def.h    2011-12-05 19:33:02.000000000 +0100
11974 @@ -0,0 +1,17 @@
11975 +#ifndef _VX_DEVICE_DEF_H
11976 +#define _VX_DEVICE_DEF_H
11977 +
11978 +#include <linux/types.h>
11979 +
11980 +struct vx_dmap_target {
11981 +       dev_t target;
11982 +       uint32_t flags;
11983 +};
11984 +
11985 +struct _vx_device {
11986 +#ifdef CONFIG_VSERVER_DEVICE
11987 +       struct vx_dmap_target targets[2];
11988 +#endif
11989 +};
11990 +
11991 +#endif /* _VX_DEVICE_DEF_H */
11992 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/dlimit.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/dlimit.h
11993 --- linux-3.2.5/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
11994 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/dlimit.h        2011-12-05 19:33:02.000000000 +0100
11995 @@ -0,0 +1,54 @@
11996 +#ifndef _VX_DLIMIT_H
11997 +#define _VX_DLIMIT_H
11998 +
11999 +#include "switch.h"
12000 +
12001 +
12002 +#ifdef __KERNEL__
12003 +
12004 +/*      keep in sync with CDLIM_INFINITY       */
12005 +
12006 +#define DLIM_INFINITY          (~0ULL)
12007 +
12008 +#include <linux/spinlock.h>
12009 +#include <linux/rcupdate.h>
12010 +
12011 +struct super_block;
12012 +
12013 +struct dl_info {
12014 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12015 +       struct rcu_head dl_rcu;                 /* the rcu head */
12016 +       tag_t dl_tag;                           /* context tag */
12017 +       atomic_t dl_usecnt;                     /* usage count */
12018 +       atomic_t dl_refcnt;                     /* reference count */
12019 +
12020 +       struct super_block *dl_sb;              /* associated superblock */
12021 +
12022 +       spinlock_t dl_lock;                     /* protect the values */
12023 +
12024 +       unsigned long long dl_space_used;       /* used space in bytes */
12025 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12026 +       unsigned long dl_inodes_used;           /* used inodes */
12027 +       unsigned long dl_inodes_total;          /* maximum inodes */
12028 +
12029 +       unsigned int dl_nrlmult;                /* non root limit mult */
12030 +};
12031 +
12032 +struct rcu_head;
12033 +
12034 +extern void rcu_free_dl_info(struct rcu_head *);
12035 +extern void unhash_dl_info(struct dl_info *);
12036 +
12037 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12038 +
12039 +
12040 +struct kstatfs;
12041 +
12042 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12043 +
12044 +typedef uint64_t dlsize_t;
12045 +
12046 +#endif /* __KERNEL__ */
12047 +#else  /* _VX_DLIMIT_H */
12048 +#warning duplicate inclusion
12049 +#endif /* _VX_DLIMIT_H */
12050 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/dlimit_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/dlimit_cmd.h
12051 --- linux-3.2.5/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12052 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/dlimit_cmd.h    2011-12-05 19:33:02.000000000 +0100
12053 @@ -0,0 +1,109 @@
12054 +#ifndef _VX_DLIMIT_CMD_H
12055 +#define _VX_DLIMIT_CMD_H
12056 +
12057 +
12058 +/*  dlimit vserver commands */
12059 +
12060 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12061 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12062 +
12063 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12064 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12065 +
12066 +struct vcmd_ctx_dlimit_base_v0 {
12067 +       const char __user *name;
12068 +       uint32_t flags;
12069 +};
12070 +
12071 +struct vcmd_ctx_dlimit_v0 {
12072 +       const char __user *name;
12073 +       uint32_t space_used;                    /* used space in kbytes */
12074 +       uint32_t space_total;                   /* maximum space in kbytes */
12075 +       uint32_t inodes_used;                   /* used inodes */
12076 +       uint32_t inodes_total;                  /* maximum inodes */
12077 +       uint32_t reserved;                      /* reserved for root in % */
12078 +       uint32_t flags;
12079 +};
12080 +
12081 +#define CDLIM_UNSET            ((uint32_t)0UL)
12082 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12083 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12084 +
12085 +#define DLIME_UNIT     0
12086 +#define DLIME_KILO     1
12087 +#define DLIME_MEGA     2
12088 +#define DLIME_GIGA     3
12089 +
12090 +#define DLIMF_SHIFT    0x10
12091 +
12092 +#define DLIMS_USED     0
12093 +#define DLIMS_TOTAL    2
12094 +
12095 +static inline
12096 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12097 +{
12098 +       int exp = (flags & DLIMF_SHIFT) ?
12099 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12100 +       return ((uint64_t)val) << (10 * exp);
12101 +}
12102 +
12103 +static inline
12104 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12105 +{
12106 +       int exp = 0;
12107 +
12108 +       if (*flags & DLIMF_SHIFT) {
12109 +               while (val > (1LL << 32) && (exp < 3)) {
12110 +                       val >>= 10;
12111 +                       exp++;
12112 +               }
12113 +               *flags &= ~(DLIME_GIGA << shift);
12114 +               *flags |= exp << shift;
12115 +       } else
12116 +               val >>= 10;
12117 +       return val;
12118 +}
12119 +
12120 +#ifdef __KERNEL__
12121 +
12122 +#ifdef CONFIG_COMPAT
12123 +
12124 +#include <asm/compat.h>
12125 +
12126 +struct vcmd_ctx_dlimit_base_v0_x32 {
12127 +       compat_uptr_t name_ptr;
12128 +       uint32_t flags;
12129 +};
12130 +
12131 +struct vcmd_ctx_dlimit_v0_x32 {
12132 +       compat_uptr_t name_ptr;
12133 +       uint32_t space_used;                    /* used space in kbytes */
12134 +       uint32_t space_total;                   /* maximum space in kbytes */
12135 +       uint32_t inodes_used;                   /* used inodes */
12136 +       uint32_t inodes_total;                  /* maximum inodes */
12137 +       uint32_t reserved;                      /* reserved for root in % */
12138 +       uint32_t flags;
12139 +};
12140 +
12141 +#endif /* CONFIG_COMPAT */
12142 +
12143 +#include <linux/compiler.h>
12144 +
12145 +extern int vc_add_dlimit(uint32_t, void __user *);
12146 +extern int vc_rem_dlimit(uint32_t, void __user *);
12147 +
12148 +extern int vc_set_dlimit(uint32_t, void __user *);
12149 +extern int vc_get_dlimit(uint32_t, void __user *);
12150 +
12151 +#ifdef CONFIG_COMPAT
12152 +
12153 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12154 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12155 +
12156 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12157 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12158 +
12159 +#endif /* CONFIG_COMPAT */
12160 +
12161 +#endif /* __KERNEL__ */
12162 +#endif /* _VX_DLIMIT_CMD_H */
12163 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/global.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/global.h
12164 --- linux-3.2.5/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12165 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/global.h        2011-12-05 19:33:02.000000000 +0100
12166 @@ -0,0 +1,19 @@
12167 +#ifndef _VX_GLOBAL_H
12168 +#define _VX_GLOBAL_H
12169 +
12170 +
12171 +extern atomic_t vx_global_ctotal;
12172 +extern atomic_t vx_global_cactive;
12173 +
12174 +extern atomic_t nx_global_ctotal;
12175 +extern atomic_t nx_global_cactive;
12176 +
12177 +extern atomic_t vs_global_nsproxy;
12178 +extern atomic_t vs_global_fs;
12179 +extern atomic_t vs_global_mnt_ns;
12180 +extern atomic_t vs_global_uts_ns;
12181 +extern atomic_t vs_global_user_ns;
12182 +extern atomic_t vs_global_pid_ns;
12183 +
12184 +
12185 +#endif /* _VX_GLOBAL_H */
12186 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/history.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/history.h
12187 --- linux-3.2.5/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12188 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/history.h       2011-12-05 19:33:02.000000000 +0100
12189 @@ -0,0 +1,197 @@
12190 +#ifndef _VX_HISTORY_H
12191 +#define _VX_HISTORY_H
12192 +
12193 +
12194 +enum {
12195 +       VXH_UNUSED = 0,
12196 +       VXH_THROW_OOPS = 1,
12197 +
12198 +       VXH_GET_VX_INFO,
12199 +       VXH_PUT_VX_INFO,
12200 +       VXH_INIT_VX_INFO,
12201 +       VXH_SET_VX_INFO,
12202 +       VXH_CLR_VX_INFO,
12203 +       VXH_CLAIM_VX_INFO,
12204 +       VXH_RELEASE_VX_INFO,
12205 +       VXH_ALLOC_VX_INFO,
12206 +       VXH_DEALLOC_VX_INFO,
12207 +       VXH_HASH_VX_INFO,
12208 +       VXH_UNHASH_VX_INFO,
12209 +       VXH_LOC_VX_INFO,
12210 +       VXH_LOOKUP_VX_INFO,
12211 +       VXH_CREATE_VX_INFO,
12212 +};
12213 +
12214 +struct _vxhe_vxi {
12215 +       struct vx_info *ptr;
12216 +       unsigned xid;
12217 +       unsigned usecnt;
12218 +       unsigned tasks;
12219 +};
12220 +
12221 +struct _vxhe_set_clr {
12222 +       void *data;
12223 +};
12224 +
12225 +struct _vxhe_loc_lookup {
12226 +       unsigned arg;
12227 +};
12228 +
12229 +struct _vx_hist_entry {
12230 +       void *loc;
12231 +       unsigned short seq;
12232 +       unsigned short type;
12233 +       struct _vxhe_vxi vxi;
12234 +       union {
12235 +               struct _vxhe_set_clr sc;
12236 +               struct _vxhe_loc_lookup ll;
12237 +       };
12238 +};
12239 +
12240 +#ifdef CONFIG_VSERVER_HISTORY
12241 +
12242 +extern unsigned volatile int vxh_active;
12243 +
12244 +struct _vx_hist_entry *vxh_advance(void *loc);
12245 +
12246 +
12247 +static inline
12248 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12249 +{
12250 +       entry->vxi.ptr = vxi;
12251 +       if (vxi) {
12252 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12253 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12254 +               entry->vxi.xid = vxi->vx_id;
12255 +       }
12256 +}
12257 +
12258 +
12259 +#define        __HERE__ current_text_addr()
12260 +
12261 +#define __VXH_BODY(__type, __data, __here)     \
12262 +       struct _vx_hist_entry *entry;           \
12263 +                                               \
12264 +       preempt_disable();                      \
12265 +       entry = vxh_advance(__here);            \
12266 +       __data;                                 \
12267 +       entry->type = __type;                   \
12268 +       preempt_enable();
12269 +
12270 +
12271 +       /* pass vxi only */
12272 +
12273 +#define __VXH_SMPL                             \
12274 +       __vxh_copy_vxi(entry, vxi)
12275 +
12276 +static inline
12277 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12278 +{
12279 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12280 +}
12281 +
12282 +       /* pass vxi and data (void *) */
12283 +
12284 +#define __VXH_DATA                             \
12285 +       __vxh_copy_vxi(entry, vxi);             \
12286 +       entry->sc.data = data
12287 +
12288 +static inline
12289 +void   __vxh_data(struct vx_info *vxi, void *data,
12290 +                       int __type, void *__here)
12291 +{
12292 +       __VXH_BODY(__type, __VXH_DATA, __here)
12293 +}
12294 +
12295 +       /* pass vxi and arg (long) */
12296 +
12297 +#define __VXH_LONG                             \
12298 +       __vxh_copy_vxi(entry, vxi);             \
12299 +       entry->ll.arg = arg
12300 +
12301 +static inline
12302 +void   __vxh_long(struct vx_info *vxi, long arg,
12303 +                       int __type, void *__here)
12304 +{
12305 +       __VXH_BODY(__type, __VXH_LONG, __here)
12306 +}
12307 +
12308 +
12309 +static inline
12310 +void   __vxh_throw_oops(void *__here)
12311 +{
12312 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12313 +       /* prevent further acquisition */
12314 +       vxh_active = 0;
12315 +}
12316 +
12317 +
12318 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12319 +
12320 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12321 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12322 +
12323 +#define __vxh_init_vx_info(v, d, h) \
12324 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12325 +#define __vxh_set_vx_info(v, d, h) \
12326 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12327 +#define __vxh_clr_vx_info(v, d, h) \
12328 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12329 +
12330 +#define __vxh_claim_vx_info(v, d, h) \
12331 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12332 +#define __vxh_release_vx_info(v, d, h) \
12333 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12334 +
12335 +#define vxh_alloc_vx_info(v) \
12336 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12337 +#define vxh_dealloc_vx_info(v) \
12338 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12339 +
12340 +#define vxh_hash_vx_info(v) \
12341 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12342 +#define vxh_unhash_vx_info(v) \
12343 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12344 +
12345 +#define vxh_loc_vx_info(v, l) \
12346 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12347 +#define vxh_lookup_vx_info(v, l) \
12348 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12349 +#define vxh_create_vx_info(v, l) \
12350 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12351 +
12352 +extern void vxh_dump_history(void);
12353 +
12354 +
12355 +#else  /* CONFIG_VSERVER_HISTORY */
12356 +
12357 +#define        __HERE__        0
12358 +
12359 +#define vxh_throw_oops()               do { } while (0)
12360 +
12361 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12362 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12363 +
12364 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12365 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12366 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12367 +
12368 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12369 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12370 +
12371 +#define vxh_alloc_vx_info(v)           do { } while (0)
12372 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12373 +
12374 +#define vxh_hash_vx_info(v)            do { } while (0)
12375 +#define vxh_unhash_vx_info(v)          do { } while (0)
12376 +
12377 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12378 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12379 +#define vxh_create_vx_info(v, l)       do { } while (0)
12380 +
12381 +#define vxh_dump_history()             do { } while (0)
12382 +
12383 +
12384 +#endif /* CONFIG_VSERVER_HISTORY */
12385 +
12386 +#endif /* _VX_HISTORY_H */
12387 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/inode.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/inode.h
12388 --- linux-3.2.5/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12389 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/inode.h 2011-12-05 19:33:02.000000000 +0100
12390 @@ -0,0 +1,39 @@
12391 +#ifndef _VX_INODE_H
12392 +#define _VX_INODE_H
12393 +
12394 +
12395 +#define IATTR_TAG      0x01000000
12396 +
12397 +#define IATTR_ADMIN    0x00000001
12398 +#define IATTR_WATCH    0x00000002
12399 +#define IATTR_HIDE     0x00000004
12400 +#define IATTR_FLAGS    0x00000007
12401 +
12402 +#define IATTR_BARRIER  0x00010000
12403 +#define IATTR_IXUNLINK 0x00020000
12404 +#define IATTR_IMMUTABLE 0x00040000
12405 +#define IATTR_COW      0x00080000
12406 +
12407 +#ifdef __KERNEL__
12408 +
12409 +
12410 +#ifdef CONFIG_VSERVER_PROC_SECURE
12411 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12412 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12413 +#else
12414 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12415 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12416 +#endif
12417 +
12418 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12419 +
12420 +#endif /* __KERNEL__ */
12421 +
12422 +/* inode ioctls */
12423 +
12424 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12425 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12426 +
12427 +#else  /* _VX_INODE_H */
12428 +#warning duplicate inclusion
12429 +#endif /* _VX_INODE_H */
12430 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/inode_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/inode_cmd.h
12431 --- linux-3.2.5/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12432 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/inode_cmd.h     2011-12-05 19:33:02.000000000 +0100
12433 @@ -0,0 +1,59 @@
12434 +#ifndef _VX_INODE_CMD_H
12435 +#define _VX_INODE_CMD_H
12436 +
12437 +
12438 +/*  inode vserver commands */
12439 +
12440 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12441 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12442 +
12443 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12444 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12445 +
12446 +struct vcmd_ctx_iattr_v1 {
12447 +       const char __user *name;
12448 +       uint32_t tag;
12449 +       uint32_t flags;
12450 +       uint32_t mask;
12451 +};
12452 +
12453 +struct vcmd_ctx_fiattr_v0 {
12454 +       uint32_t tag;
12455 +       uint32_t flags;
12456 +       uint32_t mask;
12457 +};
12458 +
12459 +
12460 +#ifdef __KERNEL__
12461 +
12462 +
12463 +#ifdef CONFIG_COMPAT
12464 +
12465 +#include <asm/compat.h>
12466 +
12467 +struct vcmd_ctx_iattr_v1_x32 {
12468 +       compat_uptr_t name_ptr;
12469 +       uint32_t tag;
12470 +       uint32_t flags;
12471 +       uint32_t mask;
12472 +};
12473 +
12474 +#endif /* CONFIG_COMPAT */
12475 +
12476 +#include <linux/compiler.h>
12477 +
12478 +extern int vc_get_iattr(void __user *);
12479 +extern int vc_set_iattr(void __user *);
12480 +
12481 +extern int vc_fget_iattr(uint32_t, void __user *);
12482 +extern int vc_fset_iattr(uint32_t, void __user *);
12483 +
12484 +#ifdef CONFIG_COMPAT
12485 +
12486 +extern int vc_get_iattr_x32(void __user *);
12487 +extern int vc_set_iattr_x32(void __user *);
12488 +
12489 +#endif /* CONFIG_COMPAT */
12490 +
12491 +#endif /* __KERNEL__ */
12492 +#endif /* _VX_INODE_CMD_H */
12493 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/limit.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit.h
12494 --- linux-3.2.5/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12495 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit.h 2011-12-05 19:33:02.000000000 +0100
12496 @@ -0,0 +1,71 @@
12497 +#ifndef _VX_LIMIT_H
12498 +#define _VX_LIMIT_H
12499 +
12500 +#define VLIMIT_NSOCK   16
12501 +#define VLIMIT_OPENFD  17
12502 +#define VLIMIT_ANON    18
12503 +#define VLIMIT_SHMEM   19
12504 +#define VLIMIT_SEMARY  20
12505 +#define VLIMIT_NSEMS   21
12506 +#define VLIMIT_DENTRY  22
12507 +#define VLIMIT_MAPPED  23
12508 +
12509 +
12510 +#ifdef __KERNEL__
12511 +
12512 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12513 +
12514 +/*     keep in sync with CRLIM_INFINITY */
12515 +
12516 +#define        VLIM_INFINITY   (~0ULL)
12517 +
12518 +#include <asm/atomic.h>
12519 +#include <asm/resource.h>
12520 +
12521 +#ifndef RLIM_INFINITY
12522 +#warning RLIM_INFINITY is undefined
12523 +#endif
12524 +
12525 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12526 +
12527 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12528 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12529 +
12530 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12531 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12532 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12533 +
12534 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12535 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12536 +
12537 +typedef atomic_long_t rlim_atomic_t;
12538 +typedef unsigned long rlim_t;
12539 +
12540 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12541 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12542 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12543 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12544 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12545 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12546 +
12547 +
12548 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12549 +#define        VX_VLIM(r) ((long long)(long)(r))
12550 +#define        VX_RLIM(v) ((rlim_t)(v))
12551 +#else
12552 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12553 +               ? VLIM_INFINITY : (long long)(r))
12554 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12555 +               ? RLIM_INFINITY : (rlim_t)(v))
12556 +#endif
12557 +
12558 +struct sysinfo;
12559 +
12560 +void vx_vsi_meminfo(struct sysinfo *);
12561 +void vx_vsi_swapinfo(struct sysinfo *);
12562 +long vx_vsi_cached(struct sysinfo *);
12563 +
12564 +#define NUM_LIMITS     24
12565 +
12566 +#endif /* __KERNEL__ */
12567 +#endif /* _VX_LIMIT_H */
12568 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/limit_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit_cmd.h
12569 --- linux-3.2.5/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12570 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit_cmd.h     2011-12-05 19:33:02.000000000 +0100
12571 @@ -0,0 +1,71 @@
12572 +#ifndef _VX_LIMIT_CMD_H
12573 +#define _VX_LIMIT_CMD_H
12574 +
12575 +
12576 +/*  rlimit vserver commands */
12577 +
12578 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12579 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12580 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12581 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12582 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12583 +
12584 +struct vcmd_ctx_rlimit_v0 {
12585 +       uint32_t id;
12586 +       uint64_t minimum;
12587 +       uint64_t softlimit;
12588 +       uint64_t maximum;
12589 +};
12590 +
12591 +struct vcmd_ctx_rlimit_mask_v0 {
12592 +       uint32_t minimum;
12593 +       uint32_t softlimit;
12594 +       uint32_t maximum;
12595 +};
12596 +
12597 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12598 +
12599 +struct vcmd_rlimit_stat_v0 {
12600 +       uint32_t id;
12601 +       uint32_t hits;
12602 +       uint64_t value;
12603 +       uint64_t minimum;
12604 +       uint64_t maximum;
12605 +};
12606 +
12607 +#define CRLIM_UNSET            (0ULL)
12608 +#define CRLIM_INFINITY         (~0ULL)
12609 +#define CRLIM_KEEP             (~1ULL)
12610 +
12611 +#ifdef __KERNEL__
12612 +
12613 +#ifdef CONFIG_IA32_EMULATION
12614 +
12615 +struct vcmd_ctx_rlimit_v0_x32 {
12616 +       uint32_t id;
12617 +       uint64_t minimum;
12618 +       uint64_t softlimit;
12619 +       uint64_t maximum;
12620 +} __attribute__ ((packed));
12621 +
12622 +#endif /* CONFIG_IA32_EMULATION */
12623 +
12624 +#include <linux/compiler.h>
12625 +
12626 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12627 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12628 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12629 +extern int vc_reset_hits(struct vx_info *, void __user *);
12630 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12631 +
12632 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12633 +
12634 +#ifdef CONFIG_IA32_EMULATION
12635 +
12636 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12637 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12638 +
12639 +#endif /* CONFIG_IA32_EMULATION */
12640 +
12641 +#endif /* __KERNEL__ */
12642 +#endif /* _VX_LIMIT_CMD_H */
12643 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/limit_def.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit_def.h
12644 --- linux-3.2.5/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12645 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit_def.h     2011-12-05 19:33:02.000000000 +0100
12646 @@ -0,0 +1,47 @@
12647 +#ifndef _VX_LIMIT_DEF_H
12648 +#define _VX_LIMIT_DEF_H
12649 +
12650 +#include <asm/atomic.h>
12651 +#include <asm/resource.h>
12652 +
12653 +#include "limit.h"
12654 +
12655 +
12656 +struct _vx_res_limit {
12657 +       rlim_t soft;            /* Context soft limit */
12658 +       rlim_t hard;            /* Context hard limit */
12659 +
12660 +       rlim_atomic_t rcur;     /* Current value */
12661 +       rlim_t rmin;            /* Context minimum */
12662 +       rlim_t rmax;            /* Context maximum */
12663 +
12664 +       atomic_t lhit;          /* Limit hits */
12665 +};
12666 +
12667 +/* context sub struct */
12668 +
12669 +struct _vx_limit {
12670 +       struct _vx_res_limit res[NUM_LIMITS];
12671 +};
12672 +
12673 +#ifdef CONFIG_VSERVER_DEBUG
12674 +
12675 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12676 +{
12677 +       int i;
12678 +
12679 +       printk("\t_vx_limit:");
12680 +       for (i = 0; i < NUM_LIMITS; i++) {
12681 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12682 +                       i, (unsigned long)__rlim_get(limit, i),
12683 +                       (unsigned long)__rlim_rmin(limit, i),
12684 +                       (unsigned long)__rlim_rmax(limit, i),
12685 +                       (long)__rlim_soft(limit, i),
12686 +                       (long)__rlim_hard(limit, i),
12687 +                       atomic_read(&__rlim_lhit(limit, i)));
12688 +       }
12689 +}
12690 +
12691 +#endif
12692 +
12693 +#endif /* _VX_LIMIT_DEF_H */
12694 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/limit_int.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit_int.h
12695 --- linux-3.2.5/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12696 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/limit_int.h     2011-12-05 19:33:02.000000000 +0100
12697 @@ -0,0 +1,198 @@
12698 +#ifndef _VX_LIMIT_INT_H
12699 +#define _VX_LIMIT_INT_H
12700 +
12701 +#include "context.h"
12702 +
12703 +#ifdef __KERNEL__
12704 +
12705 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12706 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12707 +
12708 +extern const char *vlimit_name[NUM_LIMITS];
12709 +
12710 +static inline void __vx_acc_cres(struct vx_info *vxi,
12711 +       int res, int dir, void *_data, char *_file, int _line)
12712 +{
12713 +       if (VXD_RCRES_COND(res))
12714 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12715 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12716 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12717 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12718 +       if (!vxi)
12719 +               return;
12720 +
12721 +       if (dir > 0)
12722 +               __rlim_inc(&vxi->limit, res);
12723 +       else
12724 +               __rlim_dec(&vxi->limit, res);
12725 +}
12726 +
12727 +static inline void __vx_add_cres(struct vx_info *vxi,
12728 +       int res, int amount, void *_data, char *_file, int _line)
12729 +{
12730 +       if (VXD_RCRES_COND(res))
12731 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12732 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12733 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12734 +                       amount, _data, _file, _line);
12735 +       if (amount == 0)
12736 +               return;
12737 +       if (!vxi)
12738 +               return;
12739 +       __rlim_add(&vxi->limit, res, amount);
12740 +}
12741 +
12742 +static inline
12743 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12744 +{
12745 +       int cond = (value > __rlim_rmax(limit, res));
12746 +
12747 +       if (cond)
12748 +               __rlim_rmax(limit, res) = value;
12749 +       return cond;
12750 +}
12751 +
12752 +static inline
12753 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12754 +{
12755 +       int cond = (value < __rlim_rmin(limit, res));
12756 +
12757 +       if (cond)
12758 +               __rlim_rmin(limit, res) = value;
12759 +       return cond;
12760 +}
12761 +
12762 +static inline
12763 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12764 +{
12765 +       if (!__vx_cres_adjust_max(limit, res, value))
12766 +               __vx_cres_adjust_min(limit, res, value);
12767 +}
12768 +
12769 +
12770 +/*     return values:
12771 +        +1 ... no limit hit
12772 +        -1 ... over soft limit
12773 +         0 ... over hard limit         */
12774 +
12775 +static inline int __vx_cres_avail(struct vx_info *vxi,
12776 +       int res, int num, char *_file, int _line)
12777 +{
12778 +       struct _vx_limit *limit;
12779 +       rlim_t value;
12780 +
12781 +       if (VXD_RLIMIT_COND(res))
12782 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12783 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12784 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12785 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12786 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12787 +                       num, _file, _line);
12788 +       if (!vxi)
12789 +               return 1;
12790 +
12791 +       limit = &vxi->limit;
12792 +       value = __rlim_get(limit, res);
12793 +
12794 +       if (!__vx_cres_adjust_max(limit, res, value))
12795 +               __vx_cres_adjust_min(limit, res, value);
12796 +
12797 +       if (num == 0)
12798 +               return 1;
12799 +
12800 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12801 +               return -1;
12802 +       if (value + num <= __rlim_soft(limit, res))
12803 +               return -1;
12804 +
12805 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12806 +               return 1;
12807 +       if (value + num <= __rlim_hard(limit, res))
12808 +               return 1;
12809 +
12810 +       __rlim_hit(limit, res);
12811 +       return 0;
12812 +}
12813 +
12814 +
12815 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12816 +
12817 +static inline
12818 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12819 +{
12820 +       rlim_t value, sum = 0;
12821 +       int res;
12822 +
12823 +       while ((res = *array++)) {
12824 +               value = __rlim_get(limit, res);
12825 +               __vx_cres_fixup(limit, res, value);
12826 +               sum += value;
12827 +       }
12828 +       return sum;
12829 +}
12830 +
12831 +static inline
12832 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12833 +{
12834 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12835 +       int res = *array;
12836 +
12837 +       if (value == __rlim_get(limit, res))
12838 +               return value;
12839 +
12840 +       __rlim_set(limit, res, value);
12841 +       /* now adjust min/max */
12842 +       if (!__vx_cres_adjust_max(limit, res, value))
12843 +               __vx_cres_adjust_min(limit, res, value);
12844 +
12845 +       return value;
12846 +}
12847 +
12848 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12849 +       const int *array, int num, char *_file, int _line)
12850 +{
12851 +       struct _vx_limit *limit;
12852 +       rlim_t value = 0;
12853 +       int res;
12854 +
12855 +       if (num == 0)
12856 +               return 1;
12857 +       if (!vxi)
12858 +               return 1;
12859 +
12860 +       limit = &vxi->limit;
12861 +       res = *array;
12862 +       value = __vx_cres_array_sum(limit, array + 1);
12863 +
12864 +       __rlim_set(limit, res, value);
12865 +       __vx_cres_fixup(limit, res, value);
12866 +
12867 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12868 +}
12869 +
12870 +
12871 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12872 +{
12873 +       rlim_t value;
12874 +       int res;
12875 +
12876 +       /* complex resources first */
12877 +       if ((id < 0) || (id == RLIMIT_RSS))
12878 +               __vx_cres_array_fixup(limit, VLA_RSS);
12879 +
12880 +       for (res = 0; res < NUM_LIMITS; res++) {
12881 +               if ((id > 0) && (res != id))
12882 +                       continue;
12883 +
12884 +               value = __rlim_get(limit, res);
12885 +               __vx_cres_fixup(limit, res, value);
12886 +
12887 +               /* not supposed to happen, maybe warn? */
12888 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12889 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12890 +       }
12891 +}
12892 +
12893 +
12894 +#endif /* __KERNEL__ */
12895 +#endif /* _VX_LIMIT_INT_H */
12896 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/monitor.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/monitor.h
12897 --- linux-3.2.5/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12898 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/monitor.h       2011-12-05 19:33:02.000000000 +0100
12899 @@ -0,0 +1,96 @@
12900 +#ifndef _VX_MONITOR_H
12901 +#define _VX_MONITOR_H
12902 +
12903 +#include <linux/types.h>
12904 +
12905 +enum {
12906 +       VXM_UNUSED = 0,
12907 +
12908 +       VXM_SYNC = 0x10,
12909 +
12910 +       VXM_UPDATE = 0x20,
12911 +       VXM_UPDATE_1,
12912 +       VXM_UPDATE_2,
12913 +
12914 +       VXM_RQINFO_1 = 0x24,
12915 +       VXM_RQINFO_2,
12916 +
12917 +       VXM_ACTIVATE = 0x40,
12918 +       VXM_DEACTIVATE,
12919 +       VXM_IDLE,
12920 +
12921 +       VXM_HOLD = 0x44,
12922 +       VXM_UNHOLD,
12923 +
12924 +       VXM_MIGRATE = 0x48,
12925 +       VXM_RESCHED,
12926 +
12927 +       /* all other bits are flags */
12928 +       VXM_SCHED = 0x80,
12929 +};
12930 +
12931 +struct _vxm_update_1 {
12932 +       uint32_t tokens_max;
12933 +       uint32_t fill_rate;
12934 +       uint32_t interval;
12935 +};
12936 +
12937 +struct _vxm_update_2 {
12938 +       uint32_t tokens_min;
12939 +       uint32_t fill_rate;
12940 +       uint32_t interval;
12941 +};
12942 +
12943 +struct _vxm_rqinfo_1 {
12944 +       uint16_t running;
12945 +       uint16_t onhold;
12946 +       uint16_t iowait;
12947 +       uint16_t uintr;
12948 +       uint32_t idle_tokens;
12949 +};
12950 +
12951 +struct _vxm_rqinfo_2 {
12952 +       uint32_t norm_time;
12953 +       uint32_t idle_time;
12954 +       uint32_t idle_skip;
12955 +};
12956 +
12957 +struct _vxm_sched {
12958 +       uint32_t tokens;
12959 +       uint32_t norm_time;
12960 +       uint32_t idle_time;
12961 +};
12962 +
12963 +struct _vxm_task {
12964 +       uint16_t pid;
12965 +       uint16_t state;
12966 +};
12967 +
12968 +struct _vxm_event {
12969 +       uint32_t jif;
12970 +       union {
12971 +               uint32_t seq;
12972 +               uint32_t sec;
12973 +       };
12974 +       union {
12975 +               uint32_t tokens;
12976 +               uint32_t nsec;
12977 +               struct _vxm_task tsk;
12978 +       };
12979 +};
12980 +
12981 +struct _vx_mon_entry {
12982 +       uint16_t type;
12983 +       uint16_t xid;
12984 +       union {
12985 +               struct _vxm_event ev;
12986 +               struct _vxm_sched sd;
12987 +               struct _vxm_update_1 u1;
12988 +               struct _vxm_update_2 u2;
12989 +               struct _vxm_rqinfo_1 q1;
12990 +               struct _vxm_rqinfo_2 q2;
12991 +       };
12992 +};
12993 +
12994 +
12995 +#endif /* _VX_MONITOR_H */
12996 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/network.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/network.h
12997 --- linux-3.2.5/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
12998 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/network.h       2011-12-05 19:33:02.000000000 +0100
12999 @@ -0,0 +1,148 @@
13000 +#ifndef _VX_NETWORK_H
13001 +#define _VX_NETWORK_H
13002 +
13003 +#include <linux/types.h>
13004 +
13005 +
13006 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13007 +
13008 +
13009 +/* network flags */
13010 +
13011 +#define NXF_INFO_PRIVATE       0x00000008
13012 +
13013 +#define NXF_SINGLE_IP          0x00000100
13014 +#define NXF_LBACK_REMAP                0x00000200
13015 +#define NXF_LBACK_ALLOW                0x00000400
13016 +
13017 +#define NXF_HIDE_NETIF         0x02000000
13018 +#define NXF_HIDE_LBACK         0x04000000
13019 +
13020 +#define NXF_STATE_SETUP                (1ULL << 32)
13021 +#define NXF_STATE_ADMIN                (1ULL << 34)
13022 +
13023 +#define NXF_SC_HELPER          (1ULL << 36)
13024 +#define NXF_PERSISTENT         (1ULL << 38)
13025 +
13026 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13027 +
13028 +
13029 +#define        NXF_INIT_SET            (__nxf_init_set())
13030 +
13031 +static inline uint64_t __nxf_init_set(void) {
13032 +       return    NXF_STATE_ADMIN
13033 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13034 +               | NXF_LBACK_REMAP
13035 +               | NXF_HIDE_LBACK
13036 +#endif
13037 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13038 +               | NXF_SINGLE_IP
13039 +#endif
13040 +               | NXF_HIDE_NETIF;
13041 +}
13042 +
13043 +
13044 +/* network caps */
13045 +
13046 +#define NXC_TUN_CREATE         0x00000001
13047 +
13048 +#define NXC_RAW_ICMP           0x00000100
13049 +
13050 +#define NXC_MULTICAST          0x00001000
13051 +
13052 +
13053 +/* address types */
13054 +
13055 +#define NXA_TYPE_IPV4          0x0001
13056 +#define NXA_TYPE_IPV6          0x0002
13057 +
13058 +#define NXA_TYPE_NONE          0x0000
13059 +#define NXA_TYPE_ANY           0x00FF
13060 +
13061 +#define NXA_TYPE_ADDR          0x0010
13062 +#define NXA_TYPE_MASK          0x0020
13063 +#define NXA_TYPE_RANGE         0x0040
13064 +
13065 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13066 +
13067 +#define NXA_MOD_BCAST          0x0100
13068 +#define NXA_MOD_LBACK          0x0200
13069 +
13070 +#define NXA_LOOPBACK           0x1000
13071 +
13072 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13073 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13074 +
13075 +#ifdef __KERNEL__
13076 +
13077 +#include <linux/list.h>
13078 +#include <linux/spinlock.h>
13079 +#include <linux/rcupdate.h>
13080 +#include <linux/in.h>
13081 +#include <linux/in6.h>
13082 +#include <asm/atomic.h>
13083 +
13084 +struct nx_addr_v4 {
13085 +       struct nx_addr_v4 *next;
13086 +       struct in_addr ip[2];
13087 +       struct in_addr mask;
13088 +       uint16_t type;
13089 +       uint16_t flags;
13090 +};
13091 +
13092 +struct nx_addr_v6 {
13093 +       struct nx_addr_v6 *next;
13094 +       struct in6_addr ip;
13095 +       struct in6_addr mask;
13096 +       uint32_t prefix;
13097 +       uint16_t type;
13098 +       uint16_t flags;
13099 +};
13100 +
13101 +struct nx_info {
13102 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13103 +       nid_t nx_id;                    /* vnet id */
13104 +       atomic_t nx_usecnt;             /* usage count */
13105 +       atomic_t nx_tasks;              /* tasks count */
13106 +       int nx_state;                   /* context state */
13107 +
13108 +       uint64_t nx_flags;              /* network flag word */
13109 +       uint64_t nx_ncaps;              /* network capabilities */
13110 +
13111 +       struct in_addr v4_lback;        /* Loopback address */
13112 +       struct in_addr v4_bcast;        /* Broadcast address */
13113 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13114 +#ifdef CONFIG_IPV6
13115 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13116 +#endif
13117 +       char nx_name[65];               /* network context name */
13118 +};
13119 +
13120 +
13121 +/* status flags */
13122 +
13123 +#define NXS_HASHED      0x0001
13124 +#define NXS_SHUTDOWN    0x0100
13125 +#define NXS_RELEASED    0x8000
13126 +
13127 +extern struct nx_info *lookup_nx_info(int);
13128 +
13129 +extern int get_nid_list(int, unsigned int *, int);
13130 +extern int nid_is_hashed(nid_t);
13131 +
13132 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13133 +
13134 +extern long vs_net_change(struct nx_info *, unsigned int);
13135 +
13136 +struct sock;
13137 +
13138 +
13139 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13140 +#ifdef  CONFIG_IPV6
13141 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13142 +#else
13143 +#define NX_IPV6(n)     (0)
13144 +#endif
13145 +
13146 +#endif /* __KERNEL__ */
13147 +#endif /* _VX_NETWORK_H */
13148 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/network_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/network_cmd.h
13149 --- linux-3.2.5/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13150 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/network_cmd.h   2011-12-05 19:33:02.000000000 +0100
13151 @@ -0,0 +1,164 @@
13152 +#ifndef _VX_NETWORK_CMD_H
13153 +#define _VX_NETWORK_CMD_H
13154 +
13155 +
13156 +/* vinfo commands */
13157 +
13158 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13159 +
13160 +#ifdef __KERNEL__
13161 +extern int vc_task_nid(uint32_t);
13162 +
13163 +#endif /* __KERNEL__ */
13164 +
13165 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13166 +
13167 +struct vcmd_nx_info_v0 {
13168 +       uint32_t nid;
13169 +       /* more to come */
13170 +};
13171 +
13172 +#ifdef __KERNEL__
13173 +extern int vc_nx_info(struct nx_info *, void __user *);
13174 +
13175 +#endif /* __KERNEL__ */
13176 +
13177 +#include <linux/in.h>
13178 +#include <linux/in6.h>
13179 +
13180 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13181 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13182 +
13183 +struct  vcmd_net_create {
13184 +       uint64_t flagword;
13185 +};
13186 +
13187 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13188 +
13189 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13190 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13191 +
13192 +struct vcmd_net_addr_v0 {
13193 +       uint16_t type;
13194 +       uint16_t count;
13195 +       struct in_addr ip[4];
13196 +       struct in_addr mask[4];
13197 +};
13198 +
13199 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13200 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13201 +
13202 +struct vcmd_net_addr_ipv4_v1 {
13203 +       uint16_t type;
13204 +       uint16_t flags;
13205 +       struct in_addr ip;
13206 +       struct in_addr mask;
13207 +};
13208 +
13209 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13210 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13211 +
13212 +struct vcmd_net_addr_ipv4_v2 {
13213 +       uint16_t type;
13214 +       uint16_t flags;
13215 +       struct in_addr ip;
13216 +       struct in_addr ip2;
13217 +       struct in_addr mask;
13218 +};
13219 +
13220 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13221 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13222 +
13223 +struct vcmd_net_addr_ipv6_v1 {
13224 +       uint16_t type;
13225 +       uint16_t flags;
13226 +       uint32_t prefix;
13227 +       struct in6_addr ip;
13228 +       struct in6_addr mask;
13229 +};
13230 +
13231 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13232 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13233 +
13234 +struct vcmd_match_ipv4_v0 {
13235 +       uint16_t type;
13236 +       uint16_t flags;
13237 +       uint16_t parent;
13238 +       uint16_t prefix;
13239 +       struct in_addr ip;
13240 +       struct in_addr ip2;
13241 +       struct in_addr mask;
13242 +};
13243 +
13244 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13245 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13246 +
13247 +struct vcmd_match_ipv6_v0 {
13248 +       uint16_t type;
13249 +       uint16_t flags;
13250 +       uint16_t parent;
13251 +       uint16_t prefix;
13252 +       struct in6_addr ip;
13253 +       struct in6_addr ip2;
13254 +       struct in6_addr mask;
13255 +};
13256 +
13257 +
13258 +#ifdef __KERNEL__
13259 +extern int vc_net_create(uint32_t, void __user *);
13260 +extern int vc_net_migrate(struct nx_info *, void __user *);
13261 +
13262 +extern int vc_net_add(struct nx_info *, void __user *);
13263 +extern int vc_net_remove(struct nx_info *, void __user *);
13264 +
13265 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13266 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13267 +
13268 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13269 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13270 +
13271 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13272 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13273 +
13274 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13275 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13276 +
13277 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13278 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13279 +
13280 +#endif /* __KERNEL__ */
13281 +
13282 +
13283 +/* flag commands */
13284 +
13285 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13286 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13287 +
13288 +struct vcmd_net_flags_v0 {
13289 +       uint64_t flagword;
13290 +       uint64_t mask;
13291 +};
13292 +
13293 +#ifdef __KERNEL__
13294 +extern int vc_get_nflags(struct nx_info *, void __user *);
13295 +extern int vc_set_nflags(struct nx_info *, void __user *);
13296 +
13297 +#endif /* __KERNEL__ */
13298 +
13299 +
13300 +/* network caps commands */
13301 +
13302 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13303 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13304 +
13305 +struct vcmd_net_caps_v0 {
13306 +       uint64_t ncaps;
13307 +       uint64_t cmask;
13308 +};
13309 +
13310 +#ifdef __KERNEL__
13311 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13312 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13313 +
13314 +#endif /* __KERNEL__ */
13315 +#endif /* _VX_CONTEXT_CMD_H */
13316 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/percpu.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/percpu.h
13317 --- linux-3.2.5/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13318 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/percpu.h        2011-12-05 19:33:02.000000000 +0100
13319 @@ -0,0 +1,14 @@
13320 +#ifndef _VX_PERCPU_H
13321 +#define _VX_PERCPU_H
13322 +
13323 +#include "cvirt_def.h"
13324 +#include "sched_def.h"
13325 +
13326 +struct _vx_percpu {
13327 +       struct _vx_cvirt_pc cvirt;
13328 +       struct _vx_sched_pc sched;
13329 +};
13330 +
13331 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13332 +
13333 +#endif /* _VX_PERCPU_H */
13334 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/pid.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/pid.h
13335 --- linux-3.2.5/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13336 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/pid.h   2011-12-05 19:33:02.000000000 +0100
13337 @@ -0,0 +1,51 @@
13338 +#ifndef _VSERVER_PID_H
13339 +#define _VSERVER_PID_H
13340 +
13341 +/* pid faking stuff */
13342 +
13343 +#define vx_info_map_pid(v, p) \
13344 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13345 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13346 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13347 +#define vx_map_tgid(p) vx_map_pid(p)
13348 +
13349 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13350 +       const char *func, const char *file, int line)
13351 +{
13352 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13353 +               vxfprintk(VXD_CBIT(cvirt, 2),
13354 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13355 +                       vxi, (long long)vxi->vx_flags, pid,
13356 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13357 +                       func, file, line);
13358 +               if (pid == 0)
13359 +                       return 0;
13360 +               if (pid == vxi->vx_initpid)
13361 +                       return 1;
13362 +       }
13363 +       return pid;
13364 +}
13365 +
13366 +#define vx_info_rmap_pid(v, p) \
13367 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13368 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13369 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13370 +
13371 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13372 +       const char *func, const char *file, int line)
13373 +{
13374 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13375 +               vxfprintk(VXD_CBIT(cvirt, 2),
13376 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13377 +                       vxi, (long long)vxi->vx_flags, pid,
13378 +                       (pid == 1) ? vxi->vx_initpid : pid,
13379 +                       func, file, line);
13380 +               if ((pid == 1) && vxi->vx_initpid)
13381 +                       return vxi->vx_initpid;
13382 +               if (pid == vxi->vx_initpid)
13383 +                       return ~0U;
13384 +       }
13385 +       return pid;
13386 +}
13387 +
13388 +#endif
13389 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/sched.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/sched.h
13390 --- linux-3.2.5/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13391 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/sched.h 2011-12-05 19:33:02.000000000 +0100
13392 @@ -0,0 +1,23 @@
13393 +#ifndef _VX_SCHED_H
13394 +#define _VX_SCHED_H
13395 +
13396 +
13397 +#ifdef __KERNEL__
13398 +
13399 +struct timespec;
13400 +
13401 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13402 +
13403 +
13404 +struct vx_info;
13405 +
13406 +void vx_update_load(struct vx_info *);
13407 +
13408 +
13409 +void vx_update_sched_param(struct _vx_sched *sched,
13410 +       struct _vx_sched_pc *sched_pc);
13411 +
13412 +#endif /* __KERNEL__ */
13413 +#else  /* _VX_SCHED_H */
13414 +#warning duplicate inclusion
13415 +#endif /* _VX_SCHED_H */
13416 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/sched_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/sched_cmd.h
13417 --- linux-3.2.5/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13418 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/sched_cmd.h     2011-12-05 19:33:02.000000000 +0100
13419 @@ -0,0 +1,21 @@
13420 +#ifndef _VX_SCHED_CMD_H
13421 +#define _VX_SCHED_CMD_H
13422 +
13423 +
13424 +struct vcmd_prio_bias {
13425 +       int32_t cpu_id;
13426 +       int32_t prio_bias;
13427 +};
13428 +
13429 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13430 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13431 +
13432 +#ifdef __KERNEL__
13433 +
13434 +#include <linux/compiler.h>
13435 +
13436 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13437 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13438 +
13439 +#endif /* __KERNEL__ */
13440 +#endif /* _VX_SCHED_CMD_H */
13441 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/sched_def.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/sched_def.h
13442 --- linux-3.2.5/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13443 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/sched_def.h     2011-12-05 19:33:02.000000000 +0100
13444 @@ -0,0 +1,38 @@
13445 +#ifndef _VX_SCHED_DEF_H
13446 +#define _VX_SCHED_DEF_H
13447 +
13448 +#include <linux/spinlock.h>
13449 +#include <linux/jiffies.h>
13450 +#include <linux/cpumask.h>
13451 +#include <asm/atomic.h>
13452 +#include <asm/param.h>
13453 +
13454 +
13455 +/* context sub struct */
13456 +
13457 +struct _vx_sched {
13458 +       int prio_bias;                  /* bias offset for priority */
13459 +
13460 +       cpumask_t update;               /* CPUs which should update */
13461 +};
13462 +
13463 +struct _vx_sched_pc {
13464 +       int prio_bias;                  /* bias offset for priority */
13465 +
13466 +       uint64_t user_ticks;            /* token tick events */
13467 +       uint64_t sys_ticks;             /* token tick events */
13468 +       uint64_t hold_ticks;            /* token ticks paused */
13469 +};
13470 +
13471 +
13472 +#ifdef CONFIG_VSERVER_DEBUG
13473 +
13474 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13475 +{
13476 +       printk("\t_vx_sched:\n");
13477 +       printk("\t priority = %4d\n", sched->prio_bias);
13478 +}
13479 +
13480 +#endif
13481 +
13482 +#endif /* _VX_SCHED_DEF_H */
13483 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/signal.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/signal.h
13484 --- linux-3.2.5/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13485 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/signal.h        2011-12-05 19:33:02.000000000 +0100
13486 @@ -0,0 +1,14 @@
13487 +#ifndef _VX_SIGNAL_H
13488 +#define _VX_SIGNAL_H
13489 +
13490 +
13491 +#ifdef __KERNEL__
13492 +
13493 +struct vx_info;
13494 +
13495 +int vx_info_kill(struct vx_info *, int, int);
13496 +
13497 +#endif /* __KERNEL__ */
13498 +#else  /* _VX_SIGNAL_H */
13499 +#warning duplicate inclusion
13500 +#endif /* _VX_SIGNAL_H */
13501 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/signal_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/signal_cmd.h
13502 --- linux-3.2.5/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13503 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/signal_cmd.h    2011-12-05 19:33:02.000000000 +0100
13504 @@ -0,0 +1,43 @@
13505 +#ifndef _VX_SIGNAL_CMD_H
13506 +#define _VX_SIGNAL_CMD_H
13507 +
13508 +
13509 +/*  signalling vserver commands */
13510 +
13511 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13512 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13513 +
13514 +struct vcmd_ctx_kill_v0 {
13515 +       int32_t pid;
13516 +       int32_t sig;
13517 +};
13518 +
13519 +struct vcmd_wait_exit_v0 {
13520 +       int32_t reboot_cmd;
13521 +       int32_t exit_code;
13522 +};
13523 +
13524 +#ifdef __KERNEL__
13525 +
13526 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13527 +extern int vc_wait_exit(struct vx_info *, void __user *);
13528 +
13529 +#endif /* __KERNEL__ */
13530 +
13531 +/*  process alteration commands */
13532 +
13533 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13534 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13535 +
13536 +struct vcmd_pflags_v0 {
13537 +       uint32_t flagword;
13538 +       uint32_t mask;
13539 +};
13540 +
13541 +#ifdef __KERNEL__
13542 +
13543 +extern int vc_get_pflags(uint32_t pid, void __user *);
13544 +extern int vc_set_pflags(uint32_t pid, void __user *);
13545 +
13546 +#endif /* __KERNEL__ */
13547 +#endif /* _VX_SIGNAL_CMD_H */
13548 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/space.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/space.h
13549 --- linux-3.2.5/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13550 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/space.h 2011-12-05 19:33:02.000000000 +0100
13551 @@ -0,0 +1,12 @@
13552 +#ifndef _VX_SPACE_H
13553 +#define _VX_SPACE_H
13554 +
13555 +#include <linux/types.h>
13556 +
13557 +struct vx_info;
13558 +
13559 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13560 +
13561 +#else  /* _VX_SPACE_H */
13562 +#warning duplicate inclusion
13563 +#endif /* _VX_SPACE_H */
13564 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/space_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/space_cmd.h
13565 --- linux-3.2.5/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13566 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/space_cmd.h     2011-12-05 19:33:02.000000000 +0100
13567 @@ -0,0 +1,38 @@
13568 +#ifndef _VX_SPACE_CMD_H
13569 +#define _VX_SPACE_CMD_H
13570 +
13571 +
13572 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13573 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13574 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13575 +
13576 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13577 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13578 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13579 +
13580 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13581 +
13582 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13583 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13584 +
13585 +
13586 +struct vcmd_space_mask_v1 {
13587 +       uint64_t mask;
13588 +};
13589 +
13590 +struct vcmd_space_mask_v2 {
13591 +       uint64_t mask;
13592 +       uint32_t index;
13593 +};
13594 +
13595 +
13596 +#ifdef __KERNEL__
13597 +
13598 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13599 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13600 +extern int vc_enter_space(struct vx_info *, void __user *);
13601 +extern int vc_set_space(struct vx_info *, void __user *);
13602 +extern int vc_get_space_mask(void __user *, int);
13603 +
13604 +#endif /* __KERNEL__ */
13605 +#endif /* _VX_SPACE_CMD_H */
13606 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/switch.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/switch.h
13607 --- linux-3.2.5/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13608 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/switch.h        2011-12-05 19:33:02.000000000 +0100
13609 @@ -0,0 +1,98 @@
13610 +#ifndef _VX_SWITCH_H
13611 +#define _VX_SWITCH_H
13612 +
13613 +#include <linux/types.h>
13614 +
13615 +
13616 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13617 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13618 +#define VC_VERSION(c)          ((c) & 0xFFF)
13619 +
13620 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13621 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13622 +
13623 +/*
13624 +
13625 +  Syscall Matrix V2.8
13626 +
13627 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13628 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13629 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13630 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13631 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13632 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13633 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13634 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13635 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13636 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13637 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13638 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13639 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13640 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13641 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13642 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13643 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13644 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13645 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13646 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13647 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13648 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13649 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13650 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13651 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13652 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13653 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13654 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13655 +
13656 +*/
13657 +
13658 +#define VC_CAT_VERSION         0
13659 +
13660 +#define VC_CAT_VSETUP          1
13661 +#define VC_CAT_VHOST           2
13662 +
13663 +#define VC_CAT_DEVICE          6
13664 +
13665 +#define VC_CAT_VPROC           9
13666 +#define VC_CAT_PROCALT         10
13667 +#define VC_CAT_PROCMIG         11
13668 +#define VC_CAT_PROCTRL         12
13669 +
13670 +#define VC_CAT_SCHED           14
13671 +#define VC_CAT_MEMCTRL         20
13672 +
13673 +#define VC_CAT_VNET            25
13674 +#define VC_CAT_NETALT          26
13675 +#define VC_CAT_NETMIG          27
13676 +#define VC_CAT_NETCTRL         28
13677 +
13678 +#define VC_CAT_TAGMIG          35
13679 +#define VC_CAT_DLIMIT          36
13680 +#define VC_CAT_INODE           38
13681 +
13682 +#define VC_CAT_VSTAT           40
13683 +#define VC_CAT_VINFO           46
13684 +#define VC_CAT_EVENT           48
13685 +
13686 +#define VC_CAT_FLAGS           52
13687 +#define VC_CAT_VSPACE          54
13688 +#define VC_CAT_DEBUG           56
13689 +#define VC_CAT_RLIMIT          60
13690 +
13691 +#define VC_CAT_SYSTEST         61
13692 +#define VC_CAT_COMPAT          63
13693 +
13694 +/*  query version */
13695 +
13696 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13697 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13698 +
13699 +
13700 +#ifdef __KERNEL__
13701 +
13702 +#include <linux/errno.h>
13703 +
13704 +#endif /* __KERNEL__ */
13705 +
13706 +#endif /* _VX_SWITCH_H */
13707 +
13708 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/tag.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/tag.h
13709 --- linux-3.2.5/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13710 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/tag.h   2011-12-05 19:33:02.000000000 +0100
13711 @@ -0,0 +1,143 @@
13712 +#ifndef _DX_TAG_H
13713 +#define _DX_TAG_H
13714 +
13715 +#include <linux/types.h>
13716 +
13717 +
13718 +#define DX_TAG(in)     (IS_TAGGED(in))
13719 +
13720 +
13721 +#ifdef CONFIG_TAG_NFSD
13722 +#define DX_TAG_NFSD    1
13723 +#else
13724 +#define DX_TAG_NFSD    0
13725 +#endif
13726 +
13727 +
13728 +#ifdef CONFIG_TAGGING_NONE
13729 +
13730 +#define MAX_UID                0xFFFFFFFF
13731 +#define MAX_GID                0xFFFFFFFF
13732 +
13733 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13734 +
13735 +#define TAGINO_UID(cond, uid, tag)     (uid)
13736 +#define TAGINO_GID(cond, gid, tag)     (gid)
13737 +
13738 +#endif
13739 +
13740 +
13741 +#ifdef CONFIG_TAGGING_GID16
13742 +
13743 +#define MAX_UID                0xFFFFFFFF
13744 +#define MAX_GID                0x0000FFFF
13745 +
13746 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13747 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13748 +
13749 +#define TAGINO_UID(cond, uid, tag)     (uid)
13750 +#define TAGINO_GID(cond, gid, tag)     \
13751 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13752 +
13753 +#endif
13754 +
13755 +
13756 +#ifdef CONFIG_TAGGING_ID24
13757 +
13758 +#define MAX_UID                0x00FFFFFF
13759 +#define MAX_GID                0x00FFFFFF
13760 +
13761 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13762 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13763 +
13764 +#define TAGINO_UID(cond, uid, tag)     \
13765 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13766 +#define TAGINO_GID(cond, gid, tag)     \
13767 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13768 +
13769 +#endif
13770 +
13771 +
13772 +#ifdef CONFIG_TAGGING_UID16
13773 +
13774 +#define MAX_UID                0x0000FFFF
13775 +#define MAX_GID                0xFFFFFFFF
13776 +
13777 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13778 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13779 +
13780 +#define TAGINO_UID(cond, uid, tag)     \
13781 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13782 +#define TAGINO_GID(cond, gid, tag)     (gid)
13783 +
13784 +#endif
13785 +
13786 +
13787 +#ifdef CONFIG_TAGGING_INTERN
13788 +
13789 +#define MAX_UID                0xFFFFFFFF
13790 +#define MAX_GID                0xFFFFFFFF
13791 +
13792 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13793 +       ((cond) ? (tag) : 0)
13794 +
13795 +#define TAGINO_UID(cond, uid, tag)     (uid)
13796 +#define TAGINO_GID(cond, gid, tag)     (gid)
13797 +
13798 +#endif
13799 +
13800 +
13801 +#ifndef CONFIG_TAGGING_NONE
13802 +#define dx_current_fstag(sb)   \
13803 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13804 +#else
13805 +#define dx_current_fstag(sb)   (0)
13806 +#endif
13807 +
13808 +#ifndef CONFIG_TAGGING_INTERN
13809 +#define TAGINO_TAG(cond, tag)  (0)
13810 +#else
13811 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13812 +#endif
13813 +
13814 +#define INOTAG_UID(cond, uid, gid)     \
13815 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13816 +#define INOTAG_GID(cond, uid, gid)     \
13817 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13818 +
13819 +
13820 +static inline uid_t dx_map_uid(uid_t uid)
13821 +{
13822 +       if ((uid > MAX_UID) && (uid != -1))
13823 +               uid = -2;
13824 +       return (uid & MAX_UID);
13825 +}
13826 +
13827 +static inline gid_t dx_map_gid(gid_t gid)
13828 +{
13829 +       if ((gid > MAX_GID) && (gid != -1))
13830 +               gid = -2;
13831 +       return (gid & MAX_GID);
13832 +}
13833 +
13834 +struct peer_tag {
13835 +       int32_t xid;
13836 +       int32_t nid;
13837 +};
13838 +
13839 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13840 +
13841 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13842 +                unsigned long *flags);
13843 +
13844 +#ifdef CONFIG_PROPAGATE
13845 +
13846 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13847 +
13848 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13849 +
13850 +#else
13851 +#define dx_propagate_tag(n, i) do { } while (0)
13852 +#endif
13853 +
13854 +#endif /* _DX_TAG_H */
13855 diff -NurpP --minimal linux-3.2.5/include/linux/vserver/tag_cmd.h linux-3.2.5-vs2.3.2.6/include/linux/vserver/tag_cmd.h
13856 --- linux-3.2.5/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13857 +++ linux-3.2.5-vs2.3.2.6/include/linux/vserver/tag_cmd.h       2011-12-05 19:33:02.000000000 +0100
13858 @@ -0,0 +1,22 @@
13859 +#ifndef _VX_TAG_CMD_H
13860 +#define _VX_TAG_CMD_H
13861 +
13862 +
13863 +/* vinfo commands */
13864 +
13865 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13866 +
13867 +#ifdef __KERNEL__
13868 +extern int vc_task_tag(uint32_t);
13869 +
13870 +#endif /* __KERNEL__ */
13871 +
13872 +/* context commands */
13873 +
13874 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13875 +
13876 +#ifdef __KERNEL__
13877 +extern int vc_tag_migrate(uint32_t);
13878 +
13879 +#endif /* __KERNEL__ */
13880 +#endif /* _VX_TAG_CMD_H */
13881 diff -NurpP --minimal linux-3.2.5/include/net/addrconf.h linux-3.2.5-vs2.3.2.6/include/net/addrconf.h
13882 --- linux-3.2.5/include/net/addrconf.h  2012-01-09 16:14:59.000000000 +0100
13883 +++ linux-3.2.5-vs2.3.2.6/include/net/addrconf.h        2011-12-05 19:33:02.000000000 +0100
13884 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13885                                                struct net_device *dev,
13886                                                const struct in6_addr *daddr,
13887                                                unsigned int srcprefs,
13888 -                                              struct in6_addr *saddr);
13889 +                                              struct in6_addr *saddr,
13890 +                                              struct nx_info *nxi);
13891  extern int                     ipv6_get_lladdr(struct net_device *dev,
13892                                                 struct in6_addr *addr,
13893                                                 unsigned char banned_flags);
13894 diff -NurpP --minimal linux-3.2.5/include/net/af_unix.h linux-3.2.5-vs2.3.2.6/include/net/af_unix.h
13895 --- linux-3.2.5/include/net/af_unix.h   2011-07-22 11:18:11.000000000 +0200
13896 +++ linux-3.2.5-vs2.3.2.6/include/net/af_unix.h 2011-12-05 19:33:02.000000000 +0100
13897 @@ -4,6 +4,7 @@
13898  #include <linux/socket.h>
13899  #include <linux/un.h>
13900  #include <linux/mutex.h>
13901 +#include <linux/vs_base.h>
13902  #include <net/sock.h>
13903  
13904  extern void unix_inflight(struct file *fp);
13905 diff -NurpP --minimal linux-3.2.5/include/net/inet_timewait_sock.h linux-3.2.5-vs2.3.2.6/include/net/inet_timewait_sock.h
13906 --- linux-3.2.5/include/net/inet_timewait_sock.h        2012-01-09 16:14:59.000000000 +0100
13907 +++ linux-3.2.5-vs2.3.2.6/include/net/inet_timewait_sock.h      2011-12-05 19:33:02.000000000 +0100
13908 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13909  #define tw_net                 __tw_common.skc_net
13910  #define tw_daddr               __tw_common.skc_daddr
13911  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13912 +#define tw_xid                 __tw_common.skc_xid
13913 +#define tw_vx_info             __tw_common.skc_vx_info
13914 +#define tw_nid                 __tw_common.skc_nid
13915 +#define tw_nx_info             __tw_common.skc_nx_info
13916         int                     tw_timeout;
13917         volatile unsigned char  tw_substate;
13918         unsigned char           tw_rcv_wscale;
13919 diff -NurpP --minimal linux-3.2.5/include/net/ip6_route.h linux-3.2.5-vs2.3.2.6/include/net/ip6_route.h
13920 --- linux-3.2.5/include/net/ip6_route.h 2011-07-22 11:18:11.000000000 +0200
13921 +++ linux-3.2.5-vs2.3.2.6/include/net/ip6_route.h       2011-12-05 19:33:02.000000000 +0100
13922 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
13923                                                     struct rt6_info *rt,
13924                                                     const struct in6_addr *daddr,
13925                                                     unsigned int prefs,
13926 -                                                   struct in6_addr *saddr);
13927 +                                                   struct in6_addr *saddr,
13928 +                                                   struct nx_info *nxi);
13929  
13930  extern struct rt6_info         *rt6_lookup(struct net *net,
13931                                             const struct in6_addr *daddr,
13932 diff -NurpP --minimal linux-3.2.5/include/net/route.h linux-3.2.5-vs2.3.2.6/include/net/route.h
13933 --- linux-3.2.5/include/net/route.h     2012-01-09 16:14:59.000000000 +0100
13934 +++ linux-3.2.5-vs2.3.2.6/include/net/route.h   2012-02-07 03:13:38.000000000 +0100
13935 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13936                 dst_release(&rt->dst);
13937  }
13938  
13939 +#include <linux/vs_base.h>
13940 +#include <linux/vs_inet.h>
13941 +
13942  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13943  
13944  extern const __u8 ip_tos2prio[16];
13945 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13946                            protocol, flow_flags, dst, src, dport, sport);
13947  }
13948  
13949 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13950 +       struct flowi4 *);
13951 +
13952  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13953                                               __be32 dst, __be32 src, u32 tos,
13954                                               int oif, u8 protocol,
13955 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13956  {
13957         struct net *net = sock_net(sk);
13958         struct rtable *rt;
13959 +       struct nx_info *nx_info = current_nx_info();
13960  
13961         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13962                               sport, dport, sk, can_sleep);
13963  
13964 -       if (!dst || !src) {
13965 +       if (sk)
13966 +               nx_info = sk->sk_nx_info;
13967 +
13968 +       vxdprintk(VXD_CBIT(net, 4),
13969 +               "ip_route_connect(%p) %p,%p;%lx",
13970 +               sk, nx_info, sk->sk_socket,
13971 +               (sk->sk_socket?sk->sk_socket->flags:0));
13972 +
13973 +       rt = ip_v4_find_src(net, nx_info, fl4);
13974 +       if (IS_ERR(rt))
13975 +               return rt;
13976 +       ip_rt_put(rt);
13977 +
13978 +       if (!fl4->daddr || !fl4->saddr) {
13979                 rt = __ip_route_output_key(net, fl4);
13980                 if (IS_ERR(rt))
13981                         return rt;
13982 diff -NurpP --minimal linux-3.2.5/include/net/sock.h linux-3.2.5-vs2.3.2.6/include/net/sock.h
13983 --- linux-3.2.5/include/net/sock.h      2012-01-09 16:14:59.000000000 +0100
13984 +++ linux-3.2.5-vs2.3.2.6/include/net/sock.h    2012-01-09 16:19:31.000000000 +0100
13985 @@ -149,6 +149,10 @@ struct sock_common {
13986  #ifdef CONFIG_NET_NS
13987         struct net              *skc_net;
13988  #endif
13989 +       xid_t                   skc_xid;
13990 +       struct vx_info          *skc_vx_info;
13991 +       nid_t                   skc_nid;
13992 +       struct nx_info          *skc_nx_info;
13993         /*
13994          * fields between dontcopy_begin/dontcopy_end
13995          * are not copied in sock_copy()
13996 @@ -256,6 +260,10 @@ struct sock {
13997  #define sk_bind_node           __sk_common.skc_bind_node
13998  #define sk_prot                        __sk_common.skc_prot
13999  #define sk_net                 __sk_common.skc_net
14000 +#define sk_xid                 __sk_common.skc_xid
14001 +#define sk_vx_info             __sk_common.skc_vx_info
14002 +#define sk_nid                 __sk_common.skc_nid
14003 +#define sk_nx_info             __sk_common.skc_nx_info
14004         socket_lock_t           sk_lock;
14005         struct sk_buff_head     sk_receive_queue;
14006         /*
14007 diff -NurpP --minimal linux-3.2.5/init/Kconfig linux-3.2.5-vs2.3.2.6/init/Kconfig
14008 --- linux-3.2.5/init/Kconfig    2012-01-09 16:14:59.000000000 +0100
14009 +++ linux-3.2.5-vs2.3.2.6/init/Kconfig  2011-12-05 19:33:02.000000000 +0100
14010 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14011  menuconfig CGROUPS
14012         boolean "Control Group support"
14013         depends on EVENTFD
14014 +       default y
14015         help
14016           This option adds support for grouping sets of processes together, for
14017           use with process control subsystems such as Cpusets, CFS, memory
14018 @@ -802,6 +803,7 @@ config IPC_NS
14019  config USER_NS
14020         bool "User namespace (EXPERIMENTAL)"
14021         depends on EXPERIMENTAL
14022 +       depends on VSERVER_DISABLED
14023         default y
14024         help
14025           This allows containers, i.e. vservers, to use user namespaces
14026 diff -NurpP --minimal linux-3.2.5/init/main.c linux-3.2.5-vs2.3.2.6/init/main.c
14027 --- linux-3.2.5/init/main.c     2012-01-09 16:14:59.000000000 +0100
14028 +++ linux-3.2.5-vs2.3.2.6/init/main.c   2011-12-05 19:33:02.000000000 +0100
14029 @@ -68,6 +68,7 @@
14030  #include <linux/shmem_fs.h>
14031  #include <linux/slab.h>
14032  #include <linux/perf_event.h>
14033 +#include <linux/vserver/percpu.h>
14034  
14035  #include <asm/io.h>
14036  #include <asm/bugs.h>
14037 diff -NurpP --minimal linux-3.2.5/ipc/mqueue.c linux-3.2.5-vs2.3.2.6/ipc/mqueue.c
14038 --- linux-3.2.5/ipc/mqueue.c    2012-01-09 16:14:59.000000000 +0100
14039 +++ linux-3.2.5-vs2.3.2.6/ipc/mqueue.c  2012-01-09 16:19:31.000000000 +0100
14040 @@ -33,6 +33,8 @@
14041  #include <linux/pid.h>
14042  #include <linux/ipc_namespace.h>
14043  #include <linux/slab.h>
14044 +#include <linux/vs_context.h>
14045 +#include <linux/vs_limit.h>
14046  
14047  #include <net/sock.h>
14048  #include "util.h"
14049 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14050         struct sigevent notify;
14051         struct pid* notify_owner;
14052         struct user_struct *user;       /* user who created, for accounting */
14053 +       struct vx_info *vxi;
14054         struct sock *notify_sock;
14055         struct sk_buff *notify_cookie;
14056  
14057 @@ -128,6 +131,7 @@ static struct inode *mqueue_get_inode(st
14058         if (S_ISREG(mode)) {
14059                 struct mqueue_inode_info *info;
14060                 struct task_struct *p = current;
14061 +               struct vx_info *vxi = p->vx_info;
14062                 unsigned long mq_bytes, mq_msg_tblsz;
14063  
14064                 inode->i_fop = &mqueue_file_operations;
14065 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14066                 info->notify_owner = NULL;
14067                 info->qsize = 0;
14068                 info->user = NULL;      /* set when all is ok */
14069 +               info->vxi = NULL;
14070                 memset(&info->attr, 0, sizeof(info->attr));
14071                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14072                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14073 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14074  
14075                 spin_lock(&mq_lock);
14076                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14077 -                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
14078 +                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE) ||
14079 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14080                         spin_unlock(&mq_lock);
14081                         /* mqueue_evict_inode() releases info->messages */
14082                         ret = -EMFILE;
14083                         goto out_inode;
14084                 }
14085                 u->mq_bytes += mq_bytes;
14086 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14087                 spin_unlock(&mq_lock);
14088  
14089                 /* all is ok */
14090                 info->user = get_uid(u);
14091 +               info->vxi = get_vx_info(vxi);
14092         } else if (S_ISDIR(mode)) {
14093                 inc_nlink(inode);
14094                 /* Some things misbehave if size == 0 on a directory */
14095 @@ -278,8 +286,11 @@ static void mqueue_evict_inode(struct in
14096             + info->attr.mq_msgsize);
14097         user = info->user;
14098         if (user) {
14099 +               struct vx_info *vxi = info->vxi;
14100 +
14101                 spin_lock(&mq_lock);
14102                 user->mq_bytes -= mq_bytes;
14103 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14104                 /*
14105                  * get_ns_from_inode() ensures that the
14106                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14107 @@ -289,6 +300,7 @@ static void mqueue_evict_inode(struct in
14108                 if (ipc_ns)
14109                         ipc_ns->mq_queues_count--;
14110                 spin_unlock(&mq_lock);
14111 +               put_vx_info(vxi);
14112                 free_uid(user);
14113         }
14114         if (ipc_ns)
14115 diff -NurpP --minimal linux-3.2.5/ipc/msg.c linux-3.2.5-vs2.3.2.6/ipc/msg.c
14116 --- linux-3.2.5/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
14117 +++ linux-3.2.5-vs2.3.2.6/ipc/msg.c     2011-12-05 19:33:02.000000000 +0100
14118 @@ -37,6 +37,7 @@
14119  #include <linux/rwsem.h>
14120  #include <linux/nsproxy.h>
14121  #include <linux/ipc_namespace.h>
14122 +#include <linux/vs_base.h>
14123  
14124  #include <asm/current.h>
14125  #include <asm/uaccess.h>
14126 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14127  
14128         msq->q_perm.mode = msgflg & S_IRWXUGO;
14129         msq->q_perm.key = key;
14130 +       msq->q_perm.xid = vx_current_xid();
14131  
14132         msq->q_perm.security = NULL;
14133         retval = security_msg_queue_alloc(msq);
14134 diff -NurpP --minimal linux-3.2.5/ipc/namespace.c linux-3.2.5-vs2.3.2.6/ipc/namespace.c
14135 --- linux-3.2.5/ipc/namespace.c 2011-07-22 11:18:12.000000000 +0200
14136 +++ linux-3.2.5-vs2.3.2.6/ipc/namespace.c       2011-12-05 19:33:02.000000000 +0100
14137 @@ -13,11 +13,12 @@
14138  #include <linux/mount.h>
14139  #include <linux/user_namespace.h>
14140  #include <linux/proc_fs.h>
14141 +#include <linux/vs_base.h>
14142 +#include <linux/vserver/global.h>
14143  
14144  #include "util.h"
14145  
14146 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14147 -                                          struct ipc_namespace *old_ns)
14148 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14149  {
14150         struct ipc_namespace *ns;
14151         int err;
14152 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14153         ipcns_notify(IPCNS_CREATED);
14154         register_ipcns_notifier(ns);
14155  
14156 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14157 +       ns->user_ns = get_user_ns(user_ns);
14158  
14159         return ns;
14160  }
14161  
14162  struct ipc_namespace *copy_ipcs(unsigned long flags,
14163 -                               struct task_struct *tsk)
14164 +                               struct ipc_namespace *old_ns,
14165 +                               struct user_namespace *user_ns)
14166  {
14167 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14168 -
14169         if (!(flags & CLONE_NEWIPC))
14170 -               return get_ipc_ns(ns);
14171 -       return create_ipc_ns(tsk, ns);
14172 +               return get_ipc_ns(old_ns);
14173 +       return create_ipc_ns(user_ns);
14174  }
14175  
14176  /*
14177 diff -NurpP --minimal linux-3.2.5/ipc/sem.c linux-3.2.5-vs2.3.2.6/ipc/sem.c
14178 --- linux-3.2.5/ipc/sem.c       2012-01-09 16:14:59.000000000 +0100
14179 +++ linux-3.2.5-vs2.3.2.6/ipc/sem.c     2011-12-05 19:33:02.000000000 +0100
14180 @@ -86,6 +86,8 @@
14181  #include <linux/rwsem.h>
14182  #include <linux/nsproxy.h>
14183  #include <linux/ipc_namespace.h>
14184 +#include <linux/vs_base.h>
14185 +#include <linux/vs_limit.h>
14186  
14187  #include <asm/uaccess.h>
14188  #include "util.h"
14189 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14190  
14191         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14192         sma->sem_perm.key = key;
14193 +       sma->sem_perm.xid = vx_current_xid();
14194  
14195         sma->sem_perm.security = NULL;
14196         retval = security_sem_alloc(sma);
14197 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14198                 return id;
14199         }
14200         ns->used_sems += nsems;
14201 +       /* FIXME: obsoleted? */
14202 +       vx_semary_inc(sma);
14203 +       vx_nsems_add(sma, nsems);
14204  
14205         sma->sem_base = (struct sem *) &sma[1];
14206  
14207 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14208  
14209         wake_up_sem_queue_do(&tasks);
14210         ns->used_sems -= sma->sem_nsems;
14211 +       /* FIXME: obsoleted? */
14212 +       vx_nsems_sub(sma, sma->sem_nsems);
14213 +       vx_semary_dec(sma);
14214         security_sem_free(sma);
14215         ipc_rcu_putref(sma);
14216  }
14217 diff -NurpP --minimal linux-3.2.5/ipc/shm.c linux-3.2.5-vs2.3.2.6/ipc/shm.c
14218 --- linux-3.2.5/ipc/shm.c       2012-02-07 01:57:55.000000000 +0100
14219 +++ linux-3.2.5-vs2.3.2.6/ipc/shm.c     2012-01-26 08:52:10.000000000 +0100
14220 @@ -39,6 +39,8 @@
14221  #include <linux/nsproxy.h>
14222  #include <linux/mount.h>
14223  #include <linux/ipc_namespace.h>
14224 +#include <linux/vs_context.h>
14225 +#include <linux/vs_limit.h>
14226  
14227  #include <asm/uaccess.h>
14228  
14229 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14230   */
14231  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14232  {
14233 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14234 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14235 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14236 +
14237 +       vx_ipcshm_sub(vxi, shp, numpages);
14238 +       ns->shm_tot -= numpages;
14239 +
14240         shm_rmid(ns, shp);
14241         shm_unlock(shp);
14242         if (!is_file_hugepages(shp->shm_file))
14243 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14244                                                 shp->mlock_user);
14245         fput (shp->shm_file);
14246         security_shm_free(shp);
14247 +       put_vx_info(vxi);
14248         ipc_rcu_putref(shp);
14249  }
14250  
14251 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14252         if (ns->shm_tot + numpages > ns->shm_ctlall)
14253                 return -ENOSPC;
14254  
14255 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14256 +               return -ENOSPC;
14257 +
14258         shp = ipc_rcu_alloc(sizeof(*shp));
14259         if (!shp)
14260                 return -ENOMEM;
14261  
14262         shp->shm_perm.key = key;
14263 +       shp->shm_perm.xid = vx_current_xid();
14264         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14265         shp->mlock_user = NULL;
14266  
14267 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
14268         ns->shm_tot += numpages;
14269         error = shp->shm_perm.id;
14270         shm_unlock(shp);
14271 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14272         return error;
14273  
14274  no_id:
14275 diff -NurpP --minimal linux-3.2.5/kernel/Makefile linux-3.2.5-vs2.3.2.6/kernel/Makefile
14276 --- linux-3.2.5/kernel/Makefile 2012-01-09 16:14:59.000000000 +0100
14277 +++ linux-3.2.5-vs2.3.2.6/kernel/Makefile       2011-12-05 19:33:02.000000000 +0100
14278 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14279  CFLAGS_REMOVE_irq_work.o = -pg
14280  endif
14281  
14282 +obj-y += vserver/
14283  obj-$(CONFIG_FREEZER) += freezer.o
14284  obj-$(CONFIG_PROFILING) += profile.o
14285  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14286 diff -NurpP --minimal linux-3.2.5/kernel/capability.c linux-3.2.5-vs2.3.2.6/kernel/capability.c
14287 --- linux-3.2.5/kernel/capability.c     2012-01-09 16:14:59.000000000 +0100
14288 +++ linux-3.2.5-vs2.3.2.6/kernel/capability.c   2011-12-05 19:33:02.000000000 +0100
14289 @@ -15,6 +15,7 @@
14290  #include <linux/syscalls.h>
14291  #include <linux/pid_namespace.h>
14292  #include <linux/user_namespace.h>
14293 +#include <linux/vs_context.h>
14294  #include <asm/uaccess.h>
14295  
14296  /*
14297 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14298         return 0;
14299  }
14300  
14301 +
14302  /*
14303   * The only thing that can change the capabilities of the current
14304   * process is the current process. As such, we can't be in this code
14305 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
14306         return (ret == 0);
14307  }
14308  
14309 +#include <linux/vserver/base.h>
14310 +
14311  /**
14312   * capable - Determine if the current task has a superior capability in effect
14313   * @cap: The capability to be tested for
14314 diff -NurpP --minimal linux-3.2.5/kernel/compat.c linux-3.2.5-vs2.3.2.6/kernel/compat.c
14315 --- linux-3.2.5/kernel/compat.c 2012-01-09 16:14:59.000000000 +0100
14316 +++ linux-3.2.5-vs2.3.2.6/kernel/compat.c       2011-12-05 19:33:02.000000000 +0100
14317 @@ -973,7 +973,7 @@ asmlinkage long compat_sys_stime(compat_
14318         if (err)
14319                 return err;
14320  
14321 -       do_settimeofday(&tv);
14322 +       vx_settimeofday(&tv);
14323         return 0;
14324  }
14325  
14326 diff -NurpP --minimal linux-3.2.5/kernel/cred.c linux-3.2.5-vs2.3.2.6/kernel/cred.c
14327 --- linux-3.2.5/kernel/cred.c   2012-01-09 16:15:00.000000000 +0100
14328 +++ linux-3.2.5-vs2.3.2.6/kernel/cred.c 2011-12-05 19:33:02.000000000 +0100
14329 @@ -61,31 +61,6 @@ struct cred init_cred = {
14330  #endif
14331  };
14332  
14333 -static inline void set_cred_subscribers(struct cred *cred, int n)
14334 -{
14335 -#ifdef CONFIG_DEBUG_CREDENTIALS
14336 -       atomic_set(&cred->subscribers, n);
14337 -#endif
14338 -}
14339 -
14340 -static inline int read_cred_subscribers(const struct cred *cred)
14341 -{
14342 -#ifdef CONFIG_DEBUG_CREDENTIALS
14343 -       return atomic_read(&cred->subscribers);
14344 -#else
14345 -       return 0;
14346 -#endif
14347 -}
14348 -
14349 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14350 -{
14351 -#ifdef CONFIG_DEBUG_CREDENTIALS
14352 -       struct cred *cred = (struct cred *) _cred;
14353 -
14354 -       atomic_add(n, &cred->subscribers);
14355 -#endif
14356 -}
14357 -
14358  /*
14359   * Dispose of the shared task group credentials
14360   */
14361 @@ -281,21 +256,16 @@ error:
14362   *
14363   * Call commit_creds() or abort_creds() to clean up.
14364   */
14365 -struct cred *prepare_creds(void)
14366 +struct cred *__prepare_creds(const struct cred *old)
14367  {
14368 -       struct task_struct *task = current;
14369 -       const struct cred *old;
14370         struct cred *new;
14371  
14372 -       validate_process_creds();
14373 -
14374         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14375         if (!new)
14376                 return NULL;
14377  
14378         kdebug("prepare_creds() alloc %p", new);
14379  
14380 -       old = task->cred;
14381         memcpy(new, old, sizeof(struct cred));
14382  
14383         atomic_set(&new->usage, 1);
14384 @@ -322,6 +292,13 @@ error:
14385         abort_creds(new);
14386         return NULL;
14387  }
14388 +
14389 +struct cred *prepare_creds(void)
14390 +{
14391 +       validate_process_creds();
14392 +
14393 +       return __prepare_creds(current->cred);
14394 +}
14395  EXPORT_SYMBOL(prepare_creds);
14396  
14397  /*
14398 diff -NurpP --minimal linux-3.2.5/kernel/exit.c linux-3.2.5-vs2.3.2.6/kernel/exit.c
14399 --- linux-3.2.5/kernel/exit.c   2012-01-09 16:15:00.000000000 +0100
14400 +++ linux-3.2.5-vs2.3.2.6/kernel/exit.c 2012-01-09 16:19:31.000000000 +0100
14401 @@ -48,6 +48,10 @@
14402  #include <linux/fs_struct.h>
14403  #include <linux/init_task.h>
14404  #include <linux/perf_event.h>
14405 +#include <linux/vs_limit.h>
14406 +#include <linux/vs_context.h>
14407 +#include <linux/vs_network.h>
14408 +#include <linux/vs_pid.h>
14409  #include <trace/events/sched.h>
14410  #include <linux/hw_breakpoint.h>
14411  #include <linux/oom.h>
14412 @@ -480,9 +484,11 @@ static void close_files(struct files_str
14413                                         filp_close(file, files);
14414                                         cond_resched();
14415                                 }
14416 +                               vx_openfd_dec(i);
14417                         }
14418                         i++;
14419                         set >>= 1;
14420 +                       cond_resched();
14421                 }
14422         }
14423  }
14424 @@ -1036,11 +1042,16 @@ NORET_TYPE void do_exit(long code)
14425  
14426         validate_creds_for_do_exit(tsk);
14427  
14428 +       /* needs to stay after exit_notify() */
14429 +       exit_vx_info(tsk, code);
14430 +       exit_nx_info(tsk);
14431 +
14432         preempt_disable();
14433         exit_rcu();
14434         /* causes final put_task_struct in finish_task_switch(). */
14435         tsk->state = TASK_DEAD;
14436         schedule();
14437 +       printk("bad task: %p [%lx]\n", current, current->state);
14438         BUG();
14439         /* Avoid "noreturn function does return".  */
14440         for (;;)
14441 diff -NurpP --minimal linux-3.2.5/kernel/fork.c linux-3.2.5-vs2.3.2.6/kernel/fork.c
14442 --- linux-3.2.5/kernel/fork.c   2012-01-09 16:15:00.000000000 +0100
14443 +++ linux-3.2.5-vs2.3.2.6/kernel/fork.c 2011-12-15 01:52:28.000000000 +0100
14444 @@ -66,6 +66,9 @@
14445  #include <linux/user-return-notifier.h>
14446  #include <linux/oom.h>
14447  #include <linux/khugepaged.h>
14448 +#include <linux/vs_context.h>
14449 +#include <linux/vs_network.h>
14450 +#include <linux/vs_limit.h>
14451  
14452  #include <asm/pgtable.h>
14453  #include <asm/pgalloc.h>
14454 @@ -165,6 +168,8 @@ void free_task(struct task_struct *tsk)
14455         account_kernel_stack(tsk->stack, -1);
14456         free_thread_info(tsk->stack);
14457         rt_mutex_debug_task_free(tsk);
14458 +       clr_vx_info(&tsk->vx_info);
14459 +       clr_nx_info(&tsk->nx_info);
14460         ftrace_graph_exit_task(tsk);
14461         free_task_struct(tsk);
14462  }
14463 @@ -500,6 +505,7 @@ static struct mm_struct *mm_init(struct 
14464         if (likely(!mm_alloc_pgd(mm))) {
14465                 mm->def_flags = 0;
14466                 mmu_notifier_mm_init(mm);
14467 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14468                 return mm;
14469         }
14470  
14471 @@ -537,6 +543,7 @@ void __mmdrop(struct mm_struct *mm)
14472  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14473         VM_BUG_ON(mm->pmd_huge_pte);
14474  #endif
14475 +       clr_vx_info(&mm->mm_vx_info);
14476         free_mm(mm);
14477  }
14478  EXPORT_SYMBOL_GPL(__mmdrop);
14479 @@ -724,6 +731,7 @@ struct mm_struct *dup_mm(struct task_str
14480                 goto fail_nomem;
14481  
14482         memcpy(mm, oldmm, sizeof(*mm));
14483 +       mm->mm_vx_info = NULL;
14484         mm_init_cpumask(mm);
14485  
14486         /* Initializing for Swap token stuff */
14487 @@ -767,6 +775,7 @@ fail_nocontext:
14488          * If init_new_context() failed, we cannot use mmput() to free the mm
14489          * because it calls destroy_context()
14490          */
14491 +       clr_vx_info(&mm->mm_vx_info);
14492         mm_free_pgd(mm);
14493         free_mm(mm);
14494         return NULL;
14495 @@ -1050,6 +1059,8 @@ static struct task_struct *copy_process(
14496         int retval;
14497         struct task_struct *p;
14498         int cgroup_callbacks_done = 0;
14499 +       struct vx_info *vxi;
14500 +       struct nx_info *nxi;
14501  
14502         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14503                 return ERR_PTR(-EINVAL);
14504 @@ -1096,7 +1107,12 @@ static struct task_struct *copy_process(
14505         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14506         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14507  #endif
14508 +       init_vx_info(&p->vx_info, current_vx_info());
14509 +       init_nx_info(&p->nx_info, current_nx_info());
14510 +
14511         retval = -EAGAIN;
14512 +       if (!vx_nproc_avail(1))
14513 +               goto bad_fork_free;
14514         if (atomic_read(&p->real_cred->user->processes) >=
14515                         task_rlimit(p, RLIMIT_NPROC)) {
14516                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14517 @@ -1369,6 +1385,18 @@ static struct task_struct *copy_process(
14518  
14519         total_forks++;
14520         spin_unlock(&current->sighand->siglock);
14521 +
14522 +       /* p is copy of current */
14523 +       vxi = p->vx_info;
14524 +       if (vxi) {
14525 +               claim_vx_info(vxi, p);
14526 +               atomic_inc(&vxi->cvirt.nr_threads);
14527 +               atomic_inc(&vxi->cvirt.total_forks);
14528 +               vx_nproc_inc(p);
14529 +       }
14530 +       nxi = p->nx_info;
14531 +       if (nxi)
14532 +               claim_nx_info(nxi, p);
14533         write_unlock_irq(&tasklist_lock);
14534         proc_fork_connector(p);
14535         cgroup_post_fork(p);
14536 diff -NurpP --minimal linux-3.2.5/kernel/kthread.c linux-3.2.5-vs2.3.2.6/kernel/kthread.c
14537 --- linux-3.2.5/kernel/kthread.c        2012-01-09 16:15:00.000000000 +0100
14538 +++ linux-3.2.5-vs2.3.2.6/kernel/kthread.c      2011-12-05 19:33:02.000000000 +0100
14539 @@ -16,6 +16,7 @@
14540  #include <linux/mutex.h>
14541  #include <linux/slab.h>
14542  #include <linux/freezer.h>
14543 +#include <linux/vs_pid.h>
14544  #include <trace/events/sched.h>
14545  
14546  static DEFINE_SPINLOCK(kthread_create_lock);
14547 diff -NurpP --minimal linux-3.2.5/kernel/nsproxy.c linux-3.2.5-vs2.3.2.6/kernel/nsproxy.c
14548 --- linux-3.2.5/kernel/nsproxy.c        2012-01-09 16:15:00.000000000 +0100
14549 +++ linux-3.2.5-vs2.3.2.6/kernel/nsproxy.c      2011-12-05 19:33:02.000000000 +0100
14550 @@ -20,6 +20,8 @@
14551  #include <linux/mnt_namespace.h>
14552  #include <linux/utsname.h>
14553  #include <linux/pid_namespace.h>
14554 +#include <linux/vserver/global.h>
14555 +#include <linux/vserver/debug.h>
14556  #include <net/net_namespace.h>
14557  #include <linux/ipc_namespace.h>
14558  #include <linux/proc_fs.h>
14559 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
14560         struct nsproxy *nsproxy;
14561  
14562         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14563 -       if (nsproxy)
14564 +       if (nsproxy) {
14565                 atomic_set(&nsproxy->count, 1);
14566 +               atomic_inc(&vs_global_nsproxy);
14567 +       }
14568 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14569         return nsproxy;
14570  }
14571  
14572 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
14573   * Return the newly created nsproxy.  Do not attach this to the task,
14574   * leave it to the caller to do proper locking and attach it to task.
14575   */
14576 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14577 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14578 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14579 +                       struct nsproxy *orig,
14580 +                       struct fs_struct *new_fs,
14581 +                       struct user_namespace *new_user,
14582 +                       struct pid_namespace *new_pid)
14583  {
14584         struct nsproxy *new_nsp;
14585         int err;
14586 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
14587         if (!new_nsp)
14588                 return ERR_PTR(-ENOMEM);
14589  
14590 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14591 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14592         if (IS_ERR(new_nsp->mnt_ns)) {
14593                 err = PTR_ERR(new_nsp->mnt_ns);
14594                 goto out_ns;
14595         }
14596  
14597 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14598 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14599         if (IS_ERR(new_nsp->uts_ns)) {
14600                 err = PTR_ERR(new_nsp->uts_ns);
14601                 goto out_uts;
14602         }
14603  
14604 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14605 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14606         if (IS_ERR(new_nsp->ipc_ns)) {
14607                 err = PTR_ERR(new_nsp->ipc_ns);
14608                 goto out_ipc;
14609         }
14610  
14611 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14612 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14613         if (IS_ERR(new_nsp->pid_ns)) {
14614                 err = PTR_ERR(new_nsp->pid_ns);
14615                 goto out_pid;
14616         }
14617  
14618 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14619 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14620         if (IS_ERR(new_nsp->net_ns)) {
14621                 err = PTR_ERR(new_nsp->net_ns);
14622                 goto out_net;
14623 @@ -115,6 +123,40 @@ out_ns:
14624         return ERR_PTR(err);
14625  }
14626  
14627 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14628 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14629 +{
14630 +       return unshare_namespaces(flags, tsk->nsproxy,
14631 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14632 +               task_active_pid_ns(tsk));
14633 +}
14634 +
14635 +/*
14636 + * copies the nsproxy, setting refcount to 1, and grabbing a
14637 + * reference to all contained namespaces.
14638 + */
14639 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14640 +{
14641 +       struct nsproxy *ns = create_nsproxy();
14642 +
14643 +       if (ns) {
14644 +               memcpy(ns, orig, sizeof(struct nsproxy));
14645 +               atomic_set(&ns->count, 1);
14646 +
14647 +               if (ns->mnt_ns)
14648 +                       get_mnt_ns(ns->mnt_ns);
14649 +               if (ns->uts_ns)
14650 +                       get_uts_ns(ns->uts_ns);
14651 +               if (ns->ipc_ns)
14652 +                       get_ipc_ns(ns->ipc_ns);
14653 +               if (ns->pid_ns)
14654 +                       get_pid_ns(ns->pid_ns);
14655 +               if (ns->net_ns)
14656 +                       get_net(ns->net_ns);
14657 +       }
14658 +       return ns;
14659 +}
14660 +
14661  /*
14662   * called from clone.  This now handles copy for nsproxy and all
14663   * namespaces therein.
14664 @@ -122,9 +164,12 @@ out_ns:
14665  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14666  {
14667         struct nsproxy *old_ns = tsk->nsproxy;
14668 -       struct nsproxy *new_ns;
14669 +       struct nsproxy *new_ns = NULL;
14670         int err = 0;
14671  
14672 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14673 +               flags, tsk, old_ns);
14674 +
14675         if (!old_ns)
14676                 return 0;
14677  
14678 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
14679                                 CLONE_NEWPID | CLONE_NEWNET)))
14680                 return 0;
14681  
14682 -       if (!capable(CAP_SYS_ADMIN)) {
14683 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14684                 err = -EPERM;
14685                 goto out;
14686         }
14687 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
14688  
14689  out:
14690         put_nsproxy(old_ns);
14691 +       vxdprintk(VXD_CBIT(space, 3),
14692 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14693 +               flags, tsk, old_ns, err, new_ns);
14694         return err;
14695  }
14696  
14697 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
14698                 put_ipc_ns(ns->ipc_ns);
14699         if (ns->pid_ns)
14700                 put_pid_ns(ns->pid_ns);
14701 -       put_net(ns->net_ns);
14702 +       if (ns->net_ns)
14703 +               put_net(ns->net_ns);
14704 +       atomic_dec(&vs_global_nsproxy);
14705         kmem_cache_free(nsproxy_cachep, ns);
14706  }
14707  
14708 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
14709  {
14710         int err = 0;
14711  
14712 +       vxdprintk(VXD_CBIT(space, 4),
14713 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14714 +               unshare_flags, current->nsproxy);
14715 +
14716         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14717                                CLONE_NEWNET)))
14718                 return 0;
14719  
14720 -       if (!capable(CAP_SYS_ADMIN))
14721 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14722                 return -EPERM;
14723  
14724         *new_nsp = create_new_namespaces(unshare_flags, current,
14725 diff -NurpP --minimal linux-3.2.5/kernel/pid.c linux-3.2.5-vs2.3.2.6/kernel/pid.c
14726 --- linux-3.2.5/kernel/pid.c    2012-01-09 16:15:00.000000000 +0100
14727 +++ linux-3.2.5-vs2.3.2.6/kernel/pid.c  2011-12-05 19:43:14.000000000 +0100
14728 @@ -36,6 +36,7 @@
14729  #include <linux/pid_namespace.h>
14730  #include <linux/init_task.h>
14731  #include <linux/syscalls.h>
14732 +#include <linux/vs_pid.h>
14733  
14734  #define pid_hashfn(nr, ns)     \
14735         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14736 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14737  
14738  struct pid *find_vpid(int nr)
14739  {
14740 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14741 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14742  }
14743  EXPORT_SYMBOL_GPL(find_vpid);
14744  
14745 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
14746  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14747  {
14748         struct task_struct *result = NULL;
14749 +
14750 +       if (type == PIDTYPE_REALPID)
14751 +               type = PIDTYPE_PID;
14752         if (pid) {
14753                 struct hlist_node *first;
14754                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14755 @@ -421,7 +425,7 @@ struct task_struct *find_task_by_pid_ns(
14756         rcu_lockdep_assert(rcu_read_lock_held(),
14757                            "find_task_by_pid_ns() needs rcu_read_lock()"
14758                            " protection");
14759 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14760 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14761  }
14762  
14763  struct task_struct *find_task_by_vpid(pid_t vnr)
14764 @@ -465,7 +469,7 @@ struct pid *find_get_pid(pid_t nr)
14765  }
14766  EXPORT_SYMBOL_GPL(find_get_pid);
14767  
14768 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14769 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14770  {
14771         struct upid *upid;
14772         pid_t nr = 0;
14773 @@ -478,6 +482,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14774         return nr;
14775  }
14776  
14777 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14778 +{
14779 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14780 +}
14781 +
14782  pid_t pid_vnr(struct pid *pid)
14783  {
14784         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14785 diff -NurpP --minimal linux-3.2.5/kernel/pid_namespace.c linux-3.2.5-vs2.3.2.6/kernel/pid_namespace.c
14786 --- linux-3.2.5/kernel/pid_namespace.c  2011-05-22 16:17:59.000000000 +0200
14787 +++ linux-3.2.5-vs2.3.2.6/kernel/pid_namespace.c        2011-12-05 19:33:02.000000000 +0100
14788 @@ -15,6 +15,7 @@
14789  #include <linux/acct.h>
14790  #include <linux/slab.h>
14791  #include <linux/proc_fs.h>
14792 +#include <linux/vserver/global.h>
14793  
14794  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14795  
14796 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
14797                 goto out_free_map;
14798  
14799         kref_init(&ns->kref);
14800 +       atomic_inc(&vs_global_pid_ns);
14801         ns->level = level;
14802         ns->parent = get_pid_ns(parent_pid_ns);
14803  
14804 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
14805  
14806         for (i = 0; i < PIDMAP_ENTRIES; i++)
14807                 kfree(ns->pidmap[i].page);
14808 +       atomic_dec(&vs_global_pid_ns);
14809         kmem_cache_free(pid_ns_cachep, ns);
14810  }
14811  
14812 diff -NurpP --minimal linux-3.2.5/kernel/posix-timers.c linux-3.2.5-vs2.3.2.6/kernel/posix-timers.c
14813 --- linux-3.2.5/kernel/posix-timers.c   2012-01-09 16:15:00.000000000 +0100
14814 +++ linux-3.2.5-vs2.3.2.6/kernel/posix-timers.c 2011-12-05 19:44:00.000000000 +0100
14815 @@ -47,6 +47,7 @@
14816  #include <linux/wait.h>
14817  #include <linux/workqueue.h>
14818  #include <linux/export.h>
14819 +#include <linux/vs_context.h>
14820  
14821  /*
14822   * Management arrays for POSIX timers.  Timers are kept in slab memory
14823 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14824  {
14825         struct task_struct *task;
14826         int shared, ret = -1;
14827 +
14828         /*
14829          * FIXME: if ->sigq is queued we can race with
14830          * dequeue_signal()->do_schedule_next_timer().
14831 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14832         rcu_read_lock();
14833         task = pid_task(timr->it_pid, PIDTYPE_PID);
14834         if (task) {
14835 +               struct vx_info_save vxis;
14836 +               struct vx_info *vxi;
14837 +
14838 +               vxi = get_vx_info(task->vx_info);
14839 +               enter_vx_info(vxi, &vxis);
14840                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14841                 ret = send_sigqueue(timr->sigq, task, shared);
14842 +               leave_vx_info(&vxis);
14843 +               put_vx_info(vxi);
14844         }
14845         rcu_read_unlock();
14846 +
14847         /* If we failed to send the signal the timer stops. */
14848         return ret > 0;
14849  }
14850 diff -NurpP --minimal linux-3.2.5/kernel/printk.c linux-3.2.5-vs2.3.2.6/kernel/printk.c
14851 --- linux-3.2.5/kernel/printk.c 2012-01-09 16:15:00.000000000 +0100
14852 +++ linux-3.2.5-vs2.3.2.6/kernel/printk.c       2011-12-15 01:11:33.000000000 +0100
14853 @@ -41,6 +41,7 @@
14854  #include <linux/cpu.h>
14855  #include <linux/notifier.h>
14856  #include <linux/rculist.h>
14857 +#include <linux/vs_cvirt.h>
14858  
14859  #include <asm/uaccess.h>
14860  
14861 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
14862                 return 0;
14863  
14864         if (syslog_action_restricted(type)) {
14865 -               if (capable(CAP_SYSLOG))
14866 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14867                         return 0;
14868                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14869                 if (capable(CAP_SYS_ADMIN)) {
14870 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
14871         if (error)
14872                 return error;
14873  
14874 -       switch (type) {
14875 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14876 -               break;
14877 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14878 -               break;
14879 -       case SYSLOG_ACTION_READ:        /* Read from log */
14880 +       if ((type == SYSLOG_ACTION_READ) ||
14881 +           (type == SYSLOG_ACTION_READ_ALL) ||
14882 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14883                 error = -EINVAL;
14884                 if (!buf || len < 0)
14885                         goto out;
14886 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
14887                         error = -EFAULT;
14888                         goto out;
14889                 }
14890 +       }
14891 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14892 +               return vx_do_syslog(type, buf, len);
14893 +
14894 +       switch (type) {
14895 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14896 +               break;
14897 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14898 +               break;
14899 +       case SYSLOG_ACTION_READ:        /* Read from log */
14900                 error = wait_event_interruptible(log_wait,
14901                                                         (log_start - log_end));
14902                 if (error)
14903 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
14904                 /* FALL THRU */
14905         /* Read last kernel messages */
14906         case SYSLOG_ACTION_READ_ALL:
14907 -               error = -EINVAL;
14908 -               if (!buf || len < 0)
14909 -                       goto out;
14910 -               error = 0;
14911 -               if (!len)
14912 -                       goto out;
14913 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14914 -                       error = -EFAULT;
14915 -                       goto out;
14916 -               }
14917                 count = len;
14918                 if (count > log_buf_len)
14919                         count = log_buf_len;
14920 diff -NurpP --minimal linux-3.2.5/kernel/ptrace.c linux-3.2.5-vs2.3.2.6/kernel/ptrace.c
14921 --- linux-3.2.5/kernel/ptrace.c 2012-01-09 16:15:00.000000000 +0100
14922 +++ linux-3.2.5-vs2.3.2.6/kernel/ptrace.c       2012-01-09 16:19:31.000000000 +0100
14923 @@ -22,6 +22,7 @@
14924  #include <linux/syscalls.h>
14925  #include <linux/uaccess.h>
14926  #include <linux/regset.h>
14927 +#include <linux/vs_context.h>
14928  #include <linux/hw_breakpoint.h>
14929  #include <linux/cn_proc.h>
14930  
14931 @@ -209,6 +210,11 @@ ok:
14932                 dumpable = get_dumpable(task->mm);
14933         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
14934                 return -EPERM;
14935 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14936 +               return -EPERM;
14937 +       if (!vx_check(task->xid, VS_IDENT) &&
14938 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14939 +               return -EACCES;
14940  
14941         return security_ptrace_access_check(task, mode);
14942  }
14943 diff -NurpP --minimal linux-3.2.5/kernel/sched.c linux-3.2.5-vs2.3.2.6/kernel/sched.c
14944 --- linux-3.2.5/kernel/sched.c  2012-01-09 16:15:00.000000000 +0100
14945 +++ linux-3.2.5-vs2.3.2.6/kernel/sched.c        2011-12-15 01:14:00.000000000 +0100
14946 @@ -72,6 +72,8 @@
14947  #include <linux/ftrace.h>
14948  #include <linux/slab.h>
14949  #include <linux/init_task.h>
14950 +#include <linux/vs_sched.h>
14951 +#include <linux/vs_cvirt.h>
14952  
14953  #include <asm/tlb.h>
14954  #include <asm/irq_regs.h>
14955 @@ -3607,9 +3609,17 @@ static void calc_global_nohz(unsigned lo
14956   */
14957  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14958  {
14959 -       loads[0] = (avenrun[0] + offset) << shift;
14960 -       loads[1] = (avenrun[1] + offset) << shift;
14961 -       loads[2] = (avenrun[2] + offset) << shift;
14962 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14963 +               struct vx_info *vxi = current_vx_info();
14964 +
14965 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14966 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14967 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14968 +       } else {
14969 +               loads[0] = (avenrun[0] + offset) << shift;
14970 +               loads[1] = (avenrun[1] + offset) << shift;
14971 +               loads[2] = (avenrun[2] + offset) << shift;
14972 +       }
14973  }
14974  
14975  /*
14976 @@ -3868,16 +3878,19 @@ void account_user_time(struct task_struc
14977                        cputime_t cputime_scaled)
14978  {
14979         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
14980 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14981         cputime64_t tmp;
14982 +       int nice = (TASK_NICE(p) > 0);
14983  
14984         /* Add user time to process. */
14985         p->utime = cputime_add(p->utime, cputime);
14986         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
14987 +       vx_account_user(vxi, cputime, nice);
14988         account_group_user_time(p, cputime);
14989  
14990         /* Add user time to cpustat. */
14991         tmp = cputime_to_cputime64(cputime);
14992 -       if (TASK_NICE(p) > 0)
14993 +       if (nice)
14994                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
14995         else
14996                 cpustat->user = cputime64_add(cpustat->user, tmp);
14997 @@ -3929,10 +3942,12 @@ void __account_system_time(struct task_s
14998                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
14999  {
15000         cputime64_t tmp = cputime_to_cputime64(cputime);
15001 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15002  
15003         /* Add system time to process. */
15004         p->stime = cputime_add(p->stime, cputime);
15005         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15006 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15007         account_group_system_time(p, cputime);
15008  
15009         /* Add system time to cpustat. */
15010 @@ -5132,7 +5147,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15011                 nice = 19;
15012  
15013         if (increment < 0 && !can_nice(current, nice))
15014 -               return -EPERM;
15015 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15016  
15017         retval = security_task_setnice(current, nice);
15018         if (retval)
15019 diff -NurpP --minimal linux-3.2.5/kernel/sched_fair.c linux-3.2.5-vs2.3.2.6/kernel/sched_fair.c
15020 --- linux-3.2.5/kernel/sched_fair.c     2012-01-09 16:15:00.000000000 +0100
15021 +++ linux-3.2.5-vs2.3.2.6/kernel/sched_fair.c   2012-01-09 16:19:31.000000000 +0100
15022 @@ -1014,6 +1014,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15023                 __enqueue_entity(cfs_rq, se);
15024         se->on_rq = 1;
15025  
15026 +       if (entity_is_task(se))
15027 +               vx_activate_task(task_of(se));
15028         if (cfs_rq->nr_running == 1) {
15029                 list_add_leaf_cfs_rq(cfs_rq);
15030                 check_enqueue_throttle(cfs_rq);
15031 @@ -1094,6 +1096,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15032         if (se != cfs_rq->curr)
15033                 __dequeue_entity(cfs_rq, se);
15034         se->on_rq = 0;
15035 +       if (entity_is_task(se))
15036 +               vx_deactivate_task(task_of(se));
15037         update_cfs_load(cfs_rq, 0);
15038         account_entity_dequeue(cfs_rq, se);
15039  
15040 diff -NurpP --minimal linux-3.2.5/kernel/signal.c linux-3.2.5-vs2.3.2.6/kernel/signal.c
15041 --- linux-3.2.5/kernel/signal.c 2012-01-09 16:15:00.000000000 +0100
15042 +++ linux-3.2.5-vs2.3.2.6/kernel/signal.c       2012-01-09 16:19:31.000000000 +0100
15043 @@ -28,6 +28,8 @@
15044  #include <linux/freezer.h>
15045  #include <linux/pid_namespace.h>
15046  #include <linux/nsproxy.h>
15047 +#include <linux/vs_context.h>
15048 +#include <linux/vs_pid.h>
15049  #define CREATE_TRACE_POINTS
15050  #include <trace/events/signal.h>
15051  
15052 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
15053         struct pid *sid;
15054         int error;
15055  
15056 +       vxdprintk(VXD_CBIT(misc, 7),
15057 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15058 +               sig, info, t, vx_task_xid(t), t->pid);
15059 +
15060         if (!valid_signal(sig))
15061                 return -EINVAL;
15062  
15063 +/*     FIXME: needed? if so, why?
15064 +       if ((info != SEND_SIG_NOINFO) &&
15065 +               (is_si_special(info) || !si_fromuser(info)))
15066 +               goto skip;      */
15067 +
15068         if (!si_fromuser(info))
15069                 return 0;
15070  
15071 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
15072                 }
15073         }
15074  
15075 +       error = -EPERM;
15076 +       if (t->pid == 1 && current->xid)
15077 +               return error;
15078 +
15079 +       error = -ESRCH;
15080 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15081 +                 loops, maybe ENOENT or EACCES? */
15082 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15083 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15084 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15085 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15086 +               return error;
15087 +       }
15088 +/* skip: */
15089         return security_task_kill(t, info, sig, 0);
15090  }
15091  
15092 @@ -1319,7 +1344,7 @@ int kill_pid_info(int sig, struct siginf
15093         rcu_read_lock();
15094  retry:
15095         p = pid_task(pid, PIDTYPE_PID);
15096 -       if (p) {
15097 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15098                 error = group_send_sig_info(sig, info, p);
15099                 if (unlikely(error == -ESRCH))
15100                         /*
15101 @@ -1369,7 +1394,7 @@ int kill_pid_info_as_cred(int sig, struc
15102  
15103         rcu_read_lock();
15104         p = pid_task(pid, PIDTYPE_PID);
15105 -       if (!p) {
15106 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15107                 ret = -ESRCH;
15108                 goto out_unlock;
15109         }
15110 @@ -1421,8 +1446,10 @@ static int kill_something_info(int sig, 
15111                 struct task_struct * p;
15112  
15113                 for_each_process(p) {
15114 -                       if (task_pid_vnr(p) > 1 &&
15115 -                                       !same_thread_group(p, current)) {
15116 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15117 +                               task_pid_vnr(p) > 1 &&
15118 +                               !same_thread_group(p, current) &&
15119 +                               !vx_current_initpid(p->pid)) {
15120                                 int err = group_send_sig_info(sig, info, p);
15121                                 ++count;
15122                                 if (err != -EPERM)
15123 @@ -2255,6 +2282,11 @@ relock:
15124                                 !sig_kernel_only(signr))
15125                         continue;
15126  
15127 +               /* virtual init is protected against user signals */
15128 +               if ((info->si_code == SI_USER) &&
15129 +                       vx_current_initpid(current->pid))
15130 +                       continue;
15131 +
15132                 if (sig_kernel_stop(signr)) {
15133                         /*
15134                          * The default action is to stop all threads in
15135 diff -NurpP --minimal linux-3.2.5/kernel/softirq.c linux-3.2.5-vs2.3.2.6/kernel/softirq.c
15136 --- linux-3.2.5/kernel/softirq.c        2012-01-09 16:15:00.000000000 +0100
15137 +++ linux-3.2.5-vs2.3.2.6/kernel/softirq.c      2011-12-05 19:33:02.000000000 +0100
15138 @@ -24,6 +24,7 @@
15139  #include <linux/ftrace.h>
15140  #include <linux/smp.h>
15141  #include <linux/tick.h>
15142 +#include <linux/vs_context.h>
15143  
15144  #define CREATE_TRACE_POINTS
15145  #include <trace/events/irq.h>
15146 diff -NurpP --minimal linux-3.2.5/kernel/sys.c linux-3.2.5-vs2.3.2.6/kernel/sys.c
15147 --- linux-3.2.5/kernel/sys.c    2012-01-09 16:15:00.000000000 +0100
15148 +++ linux-3.2.5-vs2.3.2.6/kernel/sys.c  2011-12-05 19:33:02.000000000 +0100
15149 @@ -45,6 +45,7 @@
15150  #include <linux/syscalls.h>
15151  #include <linux/kprobes.h>
15152  #include <linux/user_namespace.h>
15153 +#include <linux/vs_pid.h>
15154  
15155  #include <linux/kmsg_dump.h>
15156  /* Move somewhere else to avoid recompiling? */
15157 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15158                 goto out;
15159         }
15160         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15161 -               error = -EACCES;
15162 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15163 +                       error = 0;
15164 +               else
15165 +                       error = -EACCES;
15166                 goto out;
15167         }
15168         no_nice = security_task_setnice(p, niceval);
15169 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15170                         else
15171                                 pgrp = task_pgrp(current);
15172                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15173 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15174 +                                       continue;
15175                                 error = set_one_prio(p, niceval, error);
15176                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15177                         break;
15178 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15179                         else
15180                                 pgrp = task_pgrp(current);
15181                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15182 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15183 +                                       continue;
15184                                 niceval = 20 - task_nice(p);
15185                                 if (niceval > retval)
15186                                         retval = niceval;
15187 @@ -418,6 +426,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15188  
15189  static DEFINE_MUTEX(reboot_mutex);
15190  
15191 +long vs_reboot(unsigned int, void __user *);
15192 +
15193  /*
15194   * Reboot system call: for obvious reasons only root may call it,
15195   * and even root needs to set up some magic numbers in the registers
15196 @@ -450,6 +460,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15197         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15198                 cmd = LINUX_REBOOT_CMD_HALT;
15199  
15200 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15201 +               return vs_reboot(cmd, arg);
15202 +
15203         mutex_lock(&reboot_mutex);
15204         switch (cmd) {
15205         case LINUX_REBOOT_CMD_RESTART:
15206 @@ -1273,7 +1286,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15207         int errno;
15208         char tmp[__NEW_UTS_LEN];
15209  
15210 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15211 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15212 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15213                 return -EPERM;
15214  
15215         if (len < 0 || len > __NEW_UTS_LEN)
15216 @@ -1324,7 +1338,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15217         int errno;
15218         char tmp[__NEW_UTS_LEN];
15219  
15220 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15221 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15222 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15223                 return -EPERM;
15224         if (len < 0 || len > __NEW_UTS_LEN)
15225                 return -EINVAL;
15226 @@ -1443,7 +1458,7 @@ int do_prlimit(struct task_struct *tsk, 
15227                 /* Keep the capable check against init_user_ns until
15228                    cgroups can contain all limits */
15229                 if (new_rlim->rlim_max > rlim->rlim_max &&
15230 -                               !capable(CAP_SYS_RESOURCE))
15231 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15232                         retval = -EPERM;
15233                 if (!retval)
15234                         retval = security_task_setrlimit(tsk->group_leader,
15235 @@ -1497,7 +1512,8 @@ static int check_prlimit_permission(stru
15236              cred->gid == tcred->sgid &&
15237              cred->gid == tcred->gid))
15238                 return 0;
15239 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15240 +       if (vx_ns_capable(tcred->user->user_ns,
15241 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15242                 return 0;
15243  
15244         return -EPERM;
15245 diff -NurpP --minimal linux-3.2.5/kernel/sysctl.c linux-3.2.5-vs2.3.2.6/kernel/sysctl.c
15246 --- linux-3.2.5/kernel/sysctl.c 2012-01-09 16:15:00.000000000 +0100
15247 +++ linux-3.2.5-vs2.3.2.6/kernel/sysctl.c       2011-12-05 19:33:02.000000000 +0100
15248 @@ -76,6 +76,7 @@
15249  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15250  #include <linux/lockdep.h>
15251  #endif
15252 +extern char vshelper_path[];
15253  #ifdef CONFIG_CHR_DEV_SG
15254  #include <scsi/sg.h>
15255  #endif
15256 @@ -572,6 +573,13 @@ static struct ctl_table kern_table[] = {
15257                 .proc_handler   = proc_dostring,
15258         },
15259  #endif
15260 +       {
15261 +               .procname       = "vshelper",
15262 +               .data           = &vshelper_path,
15263 +               .maxlen         = 256,
15264 +               .mode           = 0644,
15265 +               .proc_handler   = &proc_dostring,
15266 +       },
15267  #ifdef CONFIG_CHR_DEV_SG
15268         {
15269                 .procname       = "sg-big-buff",
15270 diff -NurpP --minimal linux-3.2.5/kernel/sysctl_binary.c linux-3.2.5-vs2.3.2.6/kernel/sysctl_binary.c
15271 --- linux-3.2.5/kernel/sysctl_binary.c  2012-01-09 16:15:00.000000000 +0100
15272 +++ linux-3.2.5-vs2.3.2.6/kernel/sysctl_binary.c        2012-01-09 16:19:31.000000000 +0100
15273 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15274  
15275         { CTL_INT,      KERN_PANIC,                     "panic" },
15276         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15277 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15278  
15279         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15280         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15281 diff -NurpP --minimal linux-3.2.5/kernel/time/timekeeping.c linux-3.2.5-vs2.3.2.6/kernel/time/timekeeping.c
15282 --- linux-3.2.5/kernel/time/timekeeping.c       2012-01-09 16:15:00.000000000 +0100
15283 +++ linux-3.2.5-vs2.3.2.6/kernel/time/timekeeping.c     2011-12-05 19:33:02.000000000 +0100
15284 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15285         } while (read_seqretry(&xtime_lock, seq));
15286  
15287         timespec_add_ns(ts, nsecs);
15288 +       vx_adjust_timespec(ts);
15289  }
15290  
15291  EXPORT_SYMBOL(getnstimeofday);
15292 diff -NurpP --minimal linux-3.2.5/kernel/time.c linux-3.2.5-vs2.3.2.6/kernel/time.c
15293 --- linux-3.2.5/kernel/time.c   2012-01-09 16:15:00.000000000 +0100
15294 +++ linux-3.2.5-vs2.3.2.6/kernel/time.c 2011-12-05 19:33:02.000000000 +0100
15295 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15296         if (err)
15297                 return err;
15298  
15299 -       do_settimeofday(&tv);
15300 +       vx_settimeofday(&tv);
15301         return 0;
15302  }
15303  
15304 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15305                 /* SMP safe, again the code in arch/foo/time.c should
15306                  * globally block out interrupts when it runs.
15307                  */
15308 -               return do_settimeofday(tv);
15309 +               return vx_settimeofday(tv);
15310         }
15311         return 0;
15312  }
15313 diff -NurpP --minimal linux-3.2.5/kernel/timer.c linux-3.2.5-vs2.3.2.6/kernel/timer.c
15314 --- linux-3.2.5/kernel/timer.c  2012-01-09 16:15:00.000000000 +0100
15315 +++ linux-3.2.5-vs2.3.2.6/kernel/timer.c        2011-12-15 01:11:33.000000000 +0100
15316 @@ -40,6 +40,10 @@
15317  #include <linux/irq_work.h>
15318  #include <linux/sched.h>
15319  #include <linux/slab.h>
15320 +#include <linux/vs_base.h>
15321 +#include <linux/vs_cvirt.h>
15322 +#include <linux/vs_pid.h>
15323 +#include <linux/vserver/sched.h>
15324  
15325  #include <asm/uaccess.h>
15326  #include <asm/unistd.h>
15327 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15328  
15329  #endif
15330  
15331 -#ifndef __alpha__
15332 -
15333 -/*
15334 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15335 - * should be moved into arch/i386 instead?
15336 - */
15337  
15338  /**
15339   * sys_getpid - return the thread group id of the current process
15340 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15341         rcu_read_lock();
15342         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
15343         rcu_read_unlock();
15344 +       return vx_map_pid(pid);
15345 +}
15346  
15347 -       return pid;
15348 +#ifdef __alpha__
15349 +
15350 +/*
15351 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15352 + */
15353 +
15354 +asmlinkage long do_getxpid(long *ppid)
15355 +{
15356 +       *ppid = sys_getppid();
15357 +       return sys_getpid();
15358  }
15359  
15360 +#else /* _alpha_ */
15361 +
15362  SYSCALL_DEFINE0(getuid)
15363  {
15364         /* Only we change this so SMP safe */
15365 diff -NurpP --minimal linux-3.2.5/kernel/user_namespace.c linux-3.2.5-vs2.3.2.6/kernel/user_namespace.c
15366 --- linux-3.2.5/kernel/user_namespace.c 2012-01-09 16:15:00.000000000 +0100
15367 +++ linux-3.2.5-vs2.3.2.6/kernel/user_namespace.c       2011-12-05 19:33:02.000000000 +0100
15368 @@ -11,6 +11,7 @@
15369  #include <linux/user_namespace.h>
15370  #include <linux/highuid.h>
15371  #include <linux/cred.h>
15372 +#include <linux/vserver/global.h>
15373  
15374  static struct kmem_cache *user_ns_cachep __read_mostly;
15375  
15376 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15377                 return -ENOMEM;
15378  
15379         kref_init(&ns->kref);
15380 +       atomic_inc(&vs_global_user_ns);
15381  
15382         for (n = 0; n < UIDHASH_SZ; ++n)
15383                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15384 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15385         struct user_namespace *ns =
15386                 container_of(kref, struct user_namespace, kref);
15387  
15388 +       /* FIXME: maybe move into destroyer? */
15389 +       atomic_dec(&vs_global_user_ns);
15390         INIT_WORK(&ns->destroyer, free_user_ns_work);
15391         schedule_work(&ns->destroyer);
15392  }
15393 diff -NurpP --minimal linux-3.2.5/kernel/utsname.c linux-3.2.5-vs2.3.2.6/kernel/utsname.c
15394 --- linux-3.2.5/kernel/utsname.c        2012-01-09 16:15:00.000000000 +0100
15395 +++ linux-3.2.5-vs2.3.2.6/kernel/utsname.c      2011-12-05 19:33:02.000000000 +0100
15396 @@ -16,14 +16,17 @@
15397  #include <linux/slab.h>
15398  #include <linux/user_namespace.h>
15399  #include <linux/proc_fs.h>
15400 +#include <linux/vserver/global.h>
15401  
15402  static struct uts_namespace *create_uts_ns(void)
15403  {
15404         struct uts_namespace *uts_ns;
15405  
15406         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15407 -       if (uts_ns)
15408 +       if (uts_ns) {
15409                 kref_init(&uts_ns->kref);
15410 +               atomic_inc(&vs_global_uts_ns);
15411 +       }
15412         return uts_ns;
15413  }
15414  
15415 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15416   * @old_ns: namespace to clone
15417   * Return NULL on error (failure to kmalloc), new ns otherwise
15418   */
15419 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15420 -                                         struct uts_namespace *old_ns)
15421 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15422 +                                         struct user_namespace *old_user)
15423  {
15424         struct uts_namespace *ns;
15425  
15426 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15427  
15428         down_read(&uts_sem);
15429         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15430 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15431 +       ns->user_ns = get_user_ns(old_user);
15432         up_read(&uts_sem);
15433         return ns;
15434  }
15435 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15436   * versa.
15437   */
15438  struct uts_namespace *copy_utsname(unsigned long flags,
15439 -                                  struct task_struct *tsk)
15440 +                                  struct uts_namespace *old_ns,
15441 +                                  struct user_namespace *user_ns)
15442  {
15443 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15444         struct uts_namespace *new_ns;
15445  
15446         BUG_ON(!old_ns);
15447 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15448         if (!(flags & CLONE_NEWUTS))
15449                 return old_ns;
15450  
15451 -       new_ns = clone_uts_ns(tsk, old_ns);
15452 +       new_ns = clone_uts_ns(old_ns, user_ns);
15453  
15454         put_uts_ns(old_ns);
15455         return new_ns;
15456 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15457  
15458         ns = container_of(kref, struct uts_namespace, kref);
15459         put_user_ns(ns->user_ns);
15460 +       atomic_dec(&vs_global_uts_ns);
15461         kfree(ns);
15462  }
15463  
15464 diff -NurpP --minimal linux-3.2.5/kernel/vserver/Kconfig linux-3.2.5-vs2.3.2.6/kernel/vserver/Kconfig
15465 --- linux-3.2.5/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15466 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/Kconfig        2011-12-15 01:52:48.000000000 +0100
15467 @@ -0,0 +1,224 @@
15468 +#
15469 +# Linux VServer configuration
15470 +#
15471 +
15472 +menu "Linux VServer"
15473 +
15474 +config VSERVER_AUTO_LBACK
15475 +       bool    "Automatically Assign Loopback IP"
15476 +       default y
15477 +       help
15478 +         Automatically assign a guest specific loopback
15479 +         IP and add it to the kernel network stack on
15480 +         startup.
15481 +
15482 +config VSERVER_AUTO_SINGLE
15483 +       bool    "Automatic Single IP Special Casing"
15484 +       depends on EXPERIMENTAL
15485 +       default y
15486 +       help
15487 +         This allows network contexts with a single IP to
15488 +         automatically remap 0.0.0.0 bindings to that IP,
15489 +         avoiding further network checks and improving
15490 +         performance.
15491 +
15492 +         (note: such guests do not allow to change the ip
15493 +          on the fly and do not show loopback addresses)
15494 +
15495 +config VSERVER_COWBL
15496 +       bool    "Enable COW Immutable Link Breaking"
15497 +       default y
15498 +       help
15499 +         This enables the COW (Copy-On-Write) link break code.
15500 +         It allows you to treat unified files like normal files
15501 +         when writing to them (which will implicitely break the
15502 +         link and create a copy of the unified file)
15503 +
15504 +config VSERVER_VTIME
15505 +       bool    "Enable Virtualized Guest Time"
15506 +       depends on EXPERIMENTAL
15507 +       default n
15508 +       help
15509 +         This enables per guest time offsets to allow for
15510 +         adjusting the system clock individually per guest.
15511 +         this adds some overhead to the time functions and
15512 +         therefore should not be enabled without good reason.
15513 +
15514 +config VSERVER_DEVICE
15515 +       bool    "Enable Guest Device Mapping"
15516 +       depends on EXPERIMENTAL
15517 +       default n
15518 +       help
15519 +         This enables generic device remapping.
15520 +
15521 +config VSERVER_PROC_SECURE
15522 +       bool    "Enable Proc Security"
15523 +       depends on PROC_FS
15524 +       default y
15525 +       help
15526 +         This configures ProcFS security to initially hide
15527 +         non-process entries for all contexts except the main and
15528 +         spectator context (i.e. for all guests), which is a secure
15529 +         default.
15530 +
15531 +         (note: on 1.2x the entries were visible by default)
15532 +
15533 +choice
15534 +       prompt  "Persistent Inode Tagging"
15535 +       default TAGGING_ID24
15536 +       help
15537 +         This adds persistent context information to filesystems
15538 +         mounted with the tagxid option. Tagging is a requirement
15539 +         for per-context disk limits and per-context quota.
15540 +
15541 +
15542 +config TAGGING_NONE
15543 +       bool    "Disabled"
15544 +       help
15545 +         do not store per-context information in inodes.
15546 +
15547 +config TAGGING_UID16
15548 +       bool    "UID16/GID32"
15549 +       help
15550 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15551 +
15552 +config TAGGING_GID16
15553 +       bool    "UID32/GID16"
15554 +       help
15555 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15556 +
15557 +config TAGGING_ID24
15558 +       bool    "UID24/GID24"
15559 +       help
15560 +         uses the upper 8bit from UID and GID for XID tagging
15561 +         which leaves 24bit for UID/GID each, which should be
15562 +         more than sufficient for normal use.
15563 +
15564 +config TAGGING_INTERN
15565 +       bool    "UID32/GID32"
15566 +       help
15567 +         this uses otherwise reserved inode fields in the on
15568 +         disk representation, which limits the use to a few
15569 +         filesystems (currently ext2 and ext3)
15570 +
15571 +endchoice
15572 +
15573 +config TAG_NFSD
15574 +       bool    "Tag NFSD User Auth and Files"
15575 +       default n
15576 +       help
15577 +         Enable this if you do want the in-kernel NFS
15578 +         Server to use the tagging specified above.
15579 +         (will require patched clients too)
15580 +
15581 +config VSERVER_PRIVACY
15582 +       bool    "Honor Privacy Aspects of Guests"
15583 +       default n
15584 +       help
15585 +         When enabled, most context checks will disallow
15586 +         access to structures assigned to a specific context,
15587 +         like ptys or loop devices.
15588 +
15589 +config VSERVER_CONTEXTS
15590 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15591 +       range 1 65533
15592 +       default "768"   if 64BIT
15593 +       default "256"
15594 +       help
15595 +         This setting will optimize certain data structures
15596 +         and memory allocations according to the expected
15597 +         maximum.
15598 +
15599 +         note: this is not a strict upper limit.
15600 +
15601 +config VSERVER_WARN
15602 +       bool    "VServer Warnings"
15603 +       default y
15604 +       help
15605 +         This enables various runtime warnings, which will
15606 +         notify about potential manipulation attempts or
15607 +         resource shortage. It is generally considered to
15608 +         be a good idea to have that enabled.
15609 +
15610 +config VSERVER_WARN_DEVPTS
15611 +       bool    "VServer DevPTS Warnings"
15612 +       depends on VSERVER_WARN
15613 +       default y
15614 +       help
15615 +         This enables DevPTS related warnings, issued when a
15616 +         process inside a context tries to lookup or access
15617 +         a dynamic pts from the host or a different context.
15618 +
15619 +config VSERVER_DEBUG
15620 +       bool    "VServer Debugging Code"
15621 +       default n
15622 +       help
15623 +         Set this to yes if you want to be able to activate
15624 +         debugging output at runtime. It adds a very small
15625 +         overhead to all vserver related functions and
15626 +         increases the kernel size by about 20k.
15627 +
15628 +config VSERVER_HISTORY
15629 +       bool    "VServer History Tracing"
15630 +       depends on VSERVER_DEBUG
15631 +       default n
15632 +       help
15633 +         Set this to yes if you want to record the history of
15634 +         linux-vserver activities, so they can be replayed in
15635 +         the event of a kernel panic or oops.
15636 +
15637 +config VSERVER_HISTORY_SIZE
15638 +       int     "Per-CPU History Size (32-65536)"
15639 +       depends on VSERVER_HISTORY
15640 +       range 32 65536
15641 +       default 64
15642 +       help
15643 +         This allows you to specify the number of entries in
15644 +         the per-CPU history buffer.
15645 +
15646 +choice
15647 +       prompt  "Quotes used in debug and warn messages"
15648 +       default QUOTES_ISO8859
15649 +
15650 +config QUOTES_ISO8859
15651 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15652 +       help
15653 +         This uses the extended ASCII characters \xbb
15654 +         and \xab for quoting file and process names.
15655 +
15656 +config QUOTES_UTF8
15657 +       bool    "UTF-8 angle quotes"
15658 +       help
15659 +         This uses the the UTF-8 sequences for angle
15660 +         quotes to quote file and process names.
15661 +
15662 +config QUOTES_ASCII
15663 +       bool    "ASCII single quotes"
15664 +       help
15665 +         This uses the ASCII single quote character
15666 +         (\x27) to quote file and process names.
15667 +
15668 +endchoice
15669 +
15670 +endmenu
15671 +
15672 +
15673 +config VSERVER
15674 +       bool
15675 +       default y
15676 +       select NAMESPACES
15677 +       select UTS_NS
15678 +       select IPC_NS
15679 +#      select USER_NS
15680 +       select SYSVIPC
15681 +
15682 +config VSERVER_SECURITY
15683 +       bool
15684 +       depends on SECURITY
15685 +       default y
15686 +       select SECURITY_CAPABILITIES
15687 +
15688 +config VSERVER_DISABLED
15689 +       bool
15690 +       default n
15691 +
15692 diff -NurpP --minimal linux-3.2.5/kernel/vserver/Makefile linux-3.2.5-vs2.3.2.6/kernel/vserver/Makefile
15693 --- linux-3.2.5/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15694 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/Makefile       2011-12-05 19:33:02.000000000 +0100
15695 @@ -0,0 +1,18 @@
15696 +#
15697 +# Makefile for the Linux vserver routines.
15698 +#
15699 +
15700 +
15701 +obj-y          += vserver.o
15702 +
15703 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15704 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15705 +                  dlimit.o tag.o
15706 +
15707 +vserver-$(CONFIG_INET) += inet.o
15708 +vserver-$(CONFIG_PROC_FS) += proc.o
15709 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15710 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15711 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15712 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15713 +
15714 diff -NurpP --minimal linux-3.2.5/kernel/vserver/cacct.c linux-3.2.5-vs2.3.2.6/kernel/vserver/cacct.c
15715 --- linux-3.2.5/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15716 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/cacct.c        2011-12-05 19:33:02.000000000 +0100
15717 @@ -0,0 +1,42 @@
15718 +/*
15719 + *  linux/kernel/vserver/cacct.c
15720 + *
15721 + *  Virtual Server: Context Accounting
15722 + *
15723 + *  Copyright (C) 2006-2007 Herbert Pötzl
15724 + *
15725 + *  V0.01  added accounting stats
15726 + *
15727 + */
15728 +
15729 +#include <linux/types.h>
15730 +#include <linux/vs_context.h>
15731 +#include <linux/vserver/cacct_cmd.h>
15732 +#include <linux/vserver/cacct_int.h>
15733 +
15734 +#include <asm/errno.h>
15735 +#include <asm/uaccess.h>
15736 +
15737 +
15738 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15739 +{
15740 +       struct vcmd_sock_stat_v0 vc_data;
15741 +       int j, field;
15742 +
15743 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15744 +               return -EFAULT;
15745 +
15746 +       field = vc_data.field;
15747 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15748 +               return -EINVAL;
15749 +
15750 +       for (j = 0; j < 3; j++) {
15751 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15752 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15753 +       }
15754 +
15755 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15756 +               return -EFAULT;
15757 +       return 0;
15758 +}
15759 +
15760 diff -NurpP --minimal linux-3.2.5/kernel/vserver/cacct_init.h linux-3.2.5-vs2.3.2.6/kernel/vserver/cacct_init.h
15761 --- linux-3.2.5/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
15762 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/cacct_init.h   2011-12-05 19:33:02.000000000 +0100
15763 @@ -0,0 +1,25 @@
15764 +
15765 +
15766 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15767 +{
15768 +       int i, j;
15769 +
15770 +
15771 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15772 +               for (j = 0; j < 3; j++) {
15773 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15774 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15775 +               }
15776 +       }
15777 +       for (i = 0; i < 8; i++)
15778 +               atomic_set(&cacct->slab[i], 0);
15779 +       for (i = 0; i < 5; i++)
15780 +               for (j = 0; j < 4; j++)
15781 +                       atomic_set(&cacct->page[i][j], 0);
15782 +}
15783 +
15784 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15785 +{
15786 +       return;
15787 +}
15788 +
15789 diff -NurpP --minimal linux-3.2.5/kernel/vserver/cacct_proc.h linux-3.2.5-vs2.3.2.6/kernel/vserver/cacct_proc.h
15790 --- linux-3.2.5/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
15791 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/cacct_proc.h   2011-12-05 19:33:02.000000000 +0100
15792 @@ -0,0 +1,53 @@
15793 +#ifndef _VX_CACCT_PROC_H
15794 +#define _VX_CACCT_PROC_H
15795 +
15796 +#include <linux/vserver/cacct_int.h>
15797 +
15798 +
15799 +#define VX_SOCKA_TOP   \
15800 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15801 +
15802 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15803 +{
15804 +       int i, j, length = 0;
15805 +       static char *type[VXA_SOCK_SIZE] = {
15806 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15807 +       };
15808 +
15809 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15810 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15811 +               length += sprintf(buffer + length, "%s:", type[i]);
15812 +               for (j = 0; j < 3; j++) {
15813 +                       length += sprintf(buffer + length,
15814 +                               "\t%10lu/%-10lu",
15815 +                               vx_sock_count(cacct, i, j),
15816 +                               vx_sock_total(cacct, i, j));
15817 +               }
15818 +               buffer[length++] = '\n';
15819 +       }
15820 +
15821 +       length += sprintf(buffer + length, "\n");
15822 +       length += sprintf(buffer + length,
15823 +               "slab:\t %8u %8u %8u %8u\n",
15824 +               atomic_read(&cacct->slab[1]),
15825 +               atomic_read(&cacct->slab[4]),
15826 +               atomic_read(&cacct->slab[0]),
15827 +               atomic_read(&cacct->slab[2]));
15828 +
15829 +       length += sprintf(buffer + length, "\n");
15830 +       for (i = 0; i < 5; i++) {
15831 +               length += sprintf(buffer + length,
15832 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15833 +                       atomic_read(&cacct->page[i][0]),
15834 +                       atomic_read(&cacct->page[i][1]),
15835 +                       atomic_read(&cacct->page[i][2]),
15836 +                       atomic_read(&cacct->page[i][3]),
15837 +                       atomic_read(&cacct->page[i][4]),
15838 +                       atomic_read(&cacct->page[i][5]),
15839 +                       atomic_read(&cacct->page[i][6]),
15840 +                       atomic_read(&cacct->page[i][7]));
15841 +       }
15842 +       return length;
15843 +}
15844 +
15845 +#endif /* _VX_CACCT_PROC_H */
15846 diff -NurpP --minimal linux-3.2.5/kernel/vserver/context.c linux-3.2.5-vs2.3.2.6/kernel/vserver/context.c
15847 --- linux-3.2.5/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
15848 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/context.c      2011-12-05 19:33:02.000000000 +0100
15849 @@ -0,0 +1,1107 @@
15850 +/*
15851 + *  linux/kernel/vserver/context.c
15852 + *
15853 + *  Virtual Server: Context Support
15854 + *
15855 + *  Copyright (C) 2003-2011  Herbert Pötzl
15856 + *
15857 + *  V0.01  context helper
15858 + *  V0.02  vx_ctx_kill syscall command
15859 + *  V0.03  replaced context_info calls
15860 + *  V0.04  redesign of struct (de)alloc
15861 + *  V0.05  rlimit basic implementation
15862 + *  V0.06  task_xid and info commands
15863 + *  V0.07  context flags and caps
15864 + *  V0.08  switch to RCU based hash
15865 + *  V0.09  revert to non RCU for now
15866 + *  V0.10  and back to working RCU hash
15867 + *  V0.11  and back to locking again
15868 + *  V0.12  referenced context store
15869 + *  V0.13  separate per cpu data
15870 + *  V0.14  changed vcmds to vxi arg
15871 + *  V0.15  added context stat
15872 + *  V0.16  have __create claim() the vxi
15873 + *  V0.17  removed older and legacy stuff
15874 + *  V0.18  added user credentials
15875 + *  V0.19  added warn mask
15876 + *
15877 + */
15878 +
15879 +#include <linux/slab.h>
15880 +#include <linux/types.h>
15881 +#include <linux/security.h>
15882 +#include <linux/pid_namespace.h>
15883 +#include <linux/capability.h>
15884 +
15885 +#include <linux/vserver/context.h>
15886 +#include <linux/vserver/network.h>
15887 +#include <linux/vserver/debug.h>
15888 +#include <linux/vserver/limit.h>
15889 +#include <linux/vserver/limit_int.h>
15890 +#include <linux/vserver/space.h>
15891 +#include <linux/init_task.h>
15892 +#include <linux/fs_struct.h>
15893 +#include <linux/cred.h>
15894 +
15895 +#include <linux/vs_context.h>
15896 +#include <linux/vs_limit.h>
15897 +#include <linux/vs_pid.h>
15898 +#include <linux/vserver/context_cmd.h>
15899 +
15900 +#include "cvirt_init.h"
15901 +#include "cacct_init.h"
15902 +#include "limit_init.h"
15903 +#include "sched_init.h"
15904 +
15905 +
15906 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15907 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15908 +
15909 +
15910 +/*     now inactive context structures */
15911 +
15912 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15913 +
15914 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15915 +
15916 +
15917 +/*     __alloc_vx_info()
15918 +
15919 +       * allocate an initialized vx_info struct
15920 +       * doesn't make it visible (hash)                        */
15921 +
15922 +static struct vx_info *__alloc_vx_info(xid_t xid)
15923 +{
15924 +       struct vx_info *new = NULL;
15925 +       int cpu, index;
15926 +
15927 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15928 +
15929 +       /* would this benefit from a slab cache? */
15930 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15931 +       if (!new)
15932 +               return 0;
15933 +
15934 +       memset(new, 0, sizeof(struct vx_info));
15935 +#ifdef CONFIG_SMP
15936 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15937 +       if (!new->ptr_pc)
15938 +               goto error;
15939 +#endif
15940 +       new->vx_id = xid;
15941 +       INIT_HLIST_NODE(&new->vx_hlist);
15942 +       atomic_set(&new->vx_usecnt, 0);
15943 +       atomic_set(&new->vx_tasks, 0);
15944 +       new->vx_parent = NULL;
15945 +       new->vx_state = 0;
15946 +       init_waitqueue_head(&new->vx_wait);
15947 +
15948 +       /* prepare reaper */
15949 +       get_task_struct(init_pid_ns.child_reaper);
15950 +       new->vx_reaper = init_pid_ns.child_reaper;
15951 +       new->vx_badness_bias = 0;
15952 +
15953 +       /* rest of init goes here */
15954 +       vx_info_init_limit(&new->limit);
15955 +       vx_info_init_sched(&new->sched);
15956 +       vx_info_init_cvirt(&new->cvirt);
15957 +       vx_info_init_cacct(&new->cacct);
15958 +
15959 +       /* per cpu data structures */
15960 +       for_each_possible_cpu(cpu) {
15961 +               vx_info_init_sched_pc(
15962 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15963 +               vx_info_init_cvirt_pc(
15964 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15965 +       }
15966 +
15967 +       new->vx_flags = VXF_INIT_SET;
15968 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15969 +       new->vx_ccaps = 0;
15970 +       new->vx_umask = 0;
15971 +       new->vx_wmask = 0;
15972 +
15973 +       new->reboot_cmd = 0;
15974 +       new->exit_code = 0;
15975 +
15976 +       // preconfig spaces
15977 +       for (index = 0; index < VX_SPACES; index++) {
15978 +               struct _vx_space *space = &new->space[index];
15979 +
15980 +               // filesystem
15981 +               spin_lock(&init_fs.lock);
15982 +               init_fs.users++;
15983 +               spin_unlock(&init_fs.lock);
15984 +               space->vx_fs = &init_fs;
15985 +
15986 +               /* FIXME: do we want defaults? */
15987 +               // space->vx_real_cred = 0;
15988 +               // space->vx_cred = 0;
15989 +       }
15990 +
15991 +
15992 +       vxdprintk(VXD_CBIT(xid, 0),
15993 +               "alloc_vx_info(%d) = %p", xid, new);
15994 +       vxh_alloc_vx_info(new);
15995 +       atomic_inc(&vx_global_ctotal);
15996 +       return new;
15997 +#ifdef CONFIG_SMP
15998 +error:
15999 +       kfree(new);
16000 +       return 0;
16001 +#endif
16002 +}
16003 +
16004 +/*     __dealloc_vx_info()
16005 +
16006 +       * final disposal of vx_info                             */
16007 +
16008 +static void __dealloc_vx_info(struct vx_info *vxi)
16009 +{
16010 +#ifdef CONFIG_VSERVER_WARN
16011 +       struct vx_info_save vxis;
16012 +       int cpu;
16013 +#endif
16014 +       vxdprintk(VXD_CBIT(xid, 0),
16015 +               "dealloc_vx_info(%p)", vxi);
16016 +       vxh_dealloc_vx_info(vxi);
16017 +
16018 +#ifdef CONFIG_VSERVER_WARN
16019 +       enter_vx_info(vxi, &vxis);
16020 +       vx_info_exit_limit(&vxi->limit);
16021 +       vx_info_exit_sched(&vxi->sched);
16022 +       vx_info_exit_cvirt(&vxi->cvirt);
16023 +       vx_info_exit_cacct(&vxi->cacct);
16024 +
16025 +       for_each_possible_cpu(cpu) {
16026 +               vx_info_exit_sched_pc(
16027 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16028 +               vx_info_exit_cvirt_pc(
16029 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16030 +       }
16031 +       leave_vx_info(&vxis);
16032 +#endif
16033 +
16034 +       vxi->vx_id = -1;
16035 +       vxi->vx_state |= VXS_RELEASED;
16036 +
16037 +#ifdef CONFIG_SMP
16038 +       free_percpu(vxi->ptr_pc);
16039 +#endif
16040 +       kfree(vxi);
16041 +       atomic_dec(&vx_global_ctotal);
16042 +}
16043 +
16044 +static void __shutdown_vx_info(struct vx_info *vxi)
16045 +{
16046 +       struct nsproxy *nsproxy;
16047 +       struct fs_struct *fs;
16048 +       struct cred *cred;
16049 +       int index, kill;
16050 +
16051 +       might_sleep();
16052 +
16053 +       vxi->vx_state |= VXS_SHUTDOWN;
16054 +       vs_state_change(vxi, VSC_SHUTDOWN);
16055 +
16056 +       for (index = 0; index < VX_SPACES; index++) {
16057 +               struct _vx_space *space = &vxi->space[index];
16058 +
16059 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16060 +               if (nsproxy)
16061 +                       put_nsproxy(nsproxy);
16062 +
16063 +               fs = xchg(&space->vx_fs, NULL);
16064 +               spin_lock(&fs->lock);
16065 +               kill = !--fs->users;
16066 +               spin_unlock(&fs->lock);
16067 +               if (kill)
16068 +                       free_fs_struct(fs);
16069 +
16070 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16071 +               if (cred)
16072 +                       abort_creds(cred);
16073 +       }
16074 +}
16075 +
16076 +/* exported stuff */
16077 +
16078 +void free_vx_info(struct vx_info *vxi)
16079 +{
16080 +       unsigned long flags;
16081 +       unsigned index;
16082 +
16083 +       /* check for reference counts first */
16084 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16085 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16086 +
16087 +       /* context must not be hashed */
16088 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16089 +
16090 +       /* context shutdown is mandatory */
16091 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16092 +
16093 +       /* spaces check */
16094 +       for (index = 0; index < VX_SPACES; index++) {
16095 +               struct _vx_space *space = &vxi->space[index];
16096 +
16097 +               BUG_ON(space->vx_nsproxy);
16098 +               BUG_ON(space->vx_fs);
16099 +               // BUG_ON(space->vx_real_cred);
16100 +               // BUG_ON(space->vx_cred);
16101 +       }
16102 +
16103 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16104 +       hlist_del(&vxi->vx_hlist);
16105 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16106 +
16107 +       __dealloc_vx_info(vxi);
16108 +}
16109 +
16110 +
16111 +/*     hash table for vx_info hash */
16112 +
16113 +#define VX_HASH_SIZE   13
16114 +
16115 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16116 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16117 +
16118 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16119 +
16120 +
16121 +static inline unsigned int __hashval(xid_t xid)
16122 +{
16123 +       return (xid % VX_HASH_SIZE);
16124 +}
16125 +
16126 +
16127 +
16128 +/*     __hash_vx_info()
16129 +
16130 +       * add the vxi to the global hash table
16131 +       * requires the hash_lock to be held                     */
16132 +
16133 +static inline void __hash_vx_info(struct vx_info *vxi)
16134 +{
16135 +       struct hlist_head *head;
16136 +
16137 +       vxd_assert_lock(&vx_info_hash_lock);
16138 +       vxdprintk(VXD_CBIT(xid, 4),
16139 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16140 +       vxh_hash_vx_info(vxi);
16141 +
16142 +       /* context must not be hashed */
16143 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16144 +
16145 +       vxi->vx_state |= VXS_HASHED;
16146 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16147 +       hlist_add_head(&vxi->vx_hlist, head);
16148 +       atomic_inc(&vx_global_cactive);
16149 +}
16150 +
16151 +/*     __unhash_vx_info()
16152 +
16153 +       * remove the vxi from the global hash table
16154 +       * requires the hash_lock to be held                     */
16155 +
16156 +static inline void __unhash_vx_info(struct vx_info *vxi)
16157 +{
16158 +       unsigned long flags;
16159 +
16160 +       vxd_assert_lock(&vx_info_hash_lock);
16161 +       vxdprintk(VXD_CBIT(xid, 4),
16162 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16163 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16164 +       vxh_unhash_vx_info(vxi);
16165 +
16166 +       /* context must be hashed */
16167 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16168 +       /* but without tasks */
16169 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16170 +
16171 +       vxi->vx_state &= ~VXS_HASHED;
16172 +       hlist_del_init(&vxi->vx_hlist);
16173 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16174 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16175 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16176 +       atomic_dec(&vx_global_cactive);
16177 +}
16178 +
16179 +
16180 +/*     __lookup_vx_info()
16181 +
16182 +       * requires the hash_lock to be held
16183 +       * doesn't increment the vx_refcnt                       */
16184 +
16185 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16186 +{
16187 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16188 +       struct hlist_node *pos;
16189 +       struct vx_info *vxi;
16190 +
16191 +       vxd_assert_lock(&vx_info_hash_lock);
16192 +       hlist_for_each(pos, head) {
16193 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16194 +
16195 +               if (vxi->vx_id == xid)
16196 +                       goto found;
16197 +       }
16198 +       vxi = NULL;
16199 +found:
16200 +       vxdprintk(VXD_CBIT(xid, 0),
16201 +               "__lookup_vx_info(#%u): %p[#%u]",
16202 +               xid, vxi, vxi ? vxi->vx_id : 0);
16203 +       vxh_lookup_vx_info(vxi, xid);
16204 +       return vxi;
16205 +}
16206 +
16207 +
16208 +/*     __create_vx_info()
16209 +
16210 +       * create the requested context
16211 +       * get(), claim() and hash it                            */
16212 +
16213 +static struct vx_info *__create_vx_info(int id)
16214 +{
16215 +       struct vx_info *new, *vxi = NULL;
16216 +
16217 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16218 +
16219 +       if (!(new = __alloc_vx_info(id)))
16220 +               return ERR_PTR(-ENOMEM);
16221 +
16222 +       /* required to make dynamic xids unique */
16223 +       spin_lock(&vx_info_hash_lock);
16224 +
16225 +       /* static context requested */
16226 +       if ((vxi = __lookup_vx_info(id))) {
16227 +               vxdprintk(VXD_CBIT(xid, 0),
16228 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16229 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16230 +                       vxi = ERR_PTR(-EBUSY);
16231 +               else
16232 +                       vxi = ERR_PTR(-EEXIST);
16233 +               goto out_unlock;
16234 +       }
16235 +       /* new context */
16236 +       vxdprintk(VXD_CBIT(xid, 0),
16237 +               "create_vx_info(%d) = %p (new)", id, new);
16238 +       claim_vx_info(new, NULL);
16239 +       __hash_vx_info(get_vx_info(new));
16240 +       vxi = new, new = NULL;
16241 +
16242 +out_unlock:
16243 +       spin_unlock(&vx_info_hash_lock);
16244 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16245 +       if (new)
16246 +               __dealloc_vx_info(new);
16247 +       return vxi;
16248 +}
16249 +
16250 +
16251 +/*     exported stuff                                          */
16252 +
16253 +
16254 +void unhash_vx_info(struct vx_info *vxi)
16255 +{
16256 +       spin_lock(&vx_info_hash_lock);
16257 +       __unhash_vx_info(vxi);
16258 +       spin_unlock(&vx_info_hash_lock);
16259 +       __shutdown_vx_info(vxi);
16260 +       __wakeup_vx_info(vxi);
16261 +}
16262 +
16263 +
16264 +/*     lookup_vx_info()
16265 +
16266 +       * search for a vx_info and get() it
16267 +       * negative id means current                             */
16268 +
16269 +struct vx_info *lookup_vx_info(int id)
16270 +{
16271 +       struct vx_info *vxi = NULL;
16272 +
16273 +       if (id < 0) {
16274 +               vxi = get_vx_info(current_vx_info());
16275 +       } else if (id > 1) {
16276 +               spin_lock(&vx_info_hash_lock);
16277 +               vxi = get_vx_info(__lookup_vx_info(id));
16278 +               spin_unlock(&vx_info_hash_lock);
16279 +       }
16280 +       return vxi;
16281 +}
16282 +
16283 +/*     xid_is_hashed()
16284 +
16285 +       * verify that xid is still hashed                       */
16286 +
16287 +int xid_is_hashed(xid_t xid)
16288 +{
16289 +       int hashed;
16290 +
16291 +       spin_lock(&vx_info_hash_lock);
16292 +       hashed = (__lookup_vx_info(xid) != NULL);
16293 +       spin_unlock(&vx_info_hash_lock);
16294 +       return hashed;
16295 +}
16296 +
16297 +#ifdef CONFIG_PROC_FS
16298 +
16299 +/*     get_xid_list()
16300 +
16301 +       * get a subset of hashed xids for proc
16302 +       * assumes size is at least one                          */
16303 +
16304 +int get_xid_list(int index, unsigned int *xids, int size)
16305 +{
16306 +       int hindex, nr_xids = 0;
16307 +
16308 +       /* only show current and children */
16309 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16310 +               if (index > 0)
16311 +                       return 0;
16312 +               xids[nr_xids] = vx_current_xid();
16313 +               return 1;
16314 +       }
16315 +
16316 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16317 +               struct hlist_head *head = &vx_info_hash[hindex];
16318 +               struct hlist_node *pos;
16319 +
16320 +               spin_lock(&vx_info_hash_lock);
16321 +               hlist_for_each(pos, head) {
16322 +                       struct vx_info *vxi;
16323 +
16324 +                       if (--index > 0)
16325 +                               continue;
16326 +
16327 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16328 +                       xids[nr_xids] = vxi->vx_id;
16329 +                       if (++nr_xids >= size) {
16330 +                               spin_unlock(&vx_info_hash_lock);
16331 +                               goto out;
16332 +                       }
16333 +               }
16334 +               /* keep the lock time short */
16335 +               spin_unlock(&vx_info_hash_lock);
16336 +       }
16337 +out:
16338 +       return nr_xids;
16339 +}
16340 +#endif
16341 +
16342 +#ifdef CONFIG_VSERVER_DEBUG
16343 +
16344 +void   dump_vx_info_inactive(int level)
16345 +{
16346 +       struct hlist_node *entry, *next;
16347 +
16348 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16349 +               struct vx_info *vxi =
16350 +                       list_entry(entry, struct vx_info, vx_hlist);
16351 +
16352 +               dump_vx_info(vxi, level);
16353 +       }
16354 +}
16355 +
16356 +#endif
16357 +
16358 +#if 0
16359 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16360 +{
16361 +       struct user_struct *new_user, *old_user;
16362 +
16363 +       if (!p || !vxi)
16364 +               BUG();
16365 +
16366 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16367 +               return -EACCES;
16368 +
16369 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16370 +       if (!new_user)
16371 +               return -ENOMEM;
16372 +
16373 +       old_user = p->user;
16374 +       if (new_user != old_user) {
16375 +               atomic_inc(&new_user->processes);
16376 +               atomic_dec(&old_user->processes);
16377 +               p->user = new_user;
16378 +       }
16379 +       free_uid(old_user);
16380 +       return 0;
16381 +}
16382 +#endif
16383 +
16384 +#if 0
16385 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16386 +{
16387 +       // p->cap_effective &= vxi->vx_cap_bset;
16388 +       p->cap_effective =
16389 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16390 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16391 +       p->cap_inheritable =
16392 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16393 +       // p->cap_permitted &= vxi->vx_cap_bset;
16394 +       p->cap_permitted =
16395 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16396 +}
16397 +#endif
16398 +
16399 +
16400 +#include <linux/file.h>
16401 +#include <linux/fdtable.h>
16402 +
16403 +static int vx_openfd_task(struct task_struct *tsk)
16404 +{
16405 +       struct files_struct *files = tsk->files;
16406 +       struct fdtable *fdt;
16407 +       const unsigned long *bptr;
16408 +       int count, total;
16409 +
16410 +       /* no rcu_read_lock() because of spin_lock() */
16411 +       spin_lock(&files->file_lock);
16412 +       fdt = files_fdtable(files);
16413 +       bptr = fdt->open_fds->fds_bits;
16414 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16415 +       for (total = 0; count > 0; count--) {
16416 +               if (*bptr)
16417 +                       total += hweight_long(*bptr);
16418 +               bptr++;
16419 +       }
16420 +       spin_unlock(&files->file_lock);
16421 +       return total;
16422 +}
16423 +
16424 +
16425 +/*     for *space compatibility */
16426 +
16427 +asmlinkage long sys_unshare(unsigned long);
16428 +
16429 +/*
16430 + *     migrate task to new context
16431 + *     gets vxi, puts old_vxi on change
16432 + *     optionally unshares namespaces (hack)
16433 + */
16434 +
16435 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16436 +{
16437 +       struct vx_info *old_vxi;
16438 +       int ret = 0;
16439 +
16440 +       if (!p || !vxi)
16441 +               BUG();
16442 +
16443 +       vxdprintk(VXD_CBIT(xid, 5),
16444 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16445 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16446 +
16447 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16448 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16449 +               return -EACCES;
16450 +
16451 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16452 +               return -EFAULT;
16453 +
16454 +       old_vxi = task_get_vx_info(p);
16455 +       if (old_vxi == vxi)
16456 +               goto out;
16457 +
16458 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16459 +       {
16460 +               int openfd;
16461 +
16462 +               task_lock(p);
16463 +               openfd = vx_openfd_task(p);
16464 +
16465 +               if (old_vxi) {
16466 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16467 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16468 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16469 +                       /* FIXME: what about the struct files here? */
16470 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16471 +                       /* account for the executable */
16472 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16473 +               }
16474 +               atomic_inc(&vxi->cvirt.nr_threads);
16475 +               atomic_inc(&vxi->cvirt.nr_running);
16476 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16477 +               /* FIXME: what about the struct files here? */
16478 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16479 +               /* account for the executable */
16480 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16481 +
16482 +               if (old_vxi) {
16483 +                       release_vx_info(old_vxi, p);
16484 +                       clr_vx_info(&p->vx_info);
16485 +               }
16486 +               claim_vx_info(vxi, p);
16487 +               set_vx_info(&p->vx_info, vxi);
16488 +               p->xid = vxi->vx_id;
16489 +
16490 +               vxdprintk(VXD_CBIT(xid, 5),
16491 +                       "moved task %p into vxi:%p[#%d]",
16492 +                       p, vxi, vxi->vx_id);
16493 +
16494 +               // vx_mask_cap_bset(vxi, p);
16495 +               task_unlock(p);
16496 +
16497 +               /* hack for *spaces to provide compatibility */
16498 +               if (unshare) {
16499 +                       struct nsproxy *old_nsp, *new_nsp;
16500 +
16501 +                       ret = unshare_nsproxy_namespaces(
16502 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16503 +                               &new_nsp, NULL);
16504 +                       if (ret)
16505 +                               goto out;
16506 +
16507 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16508 +                       vx_set_space(vxi,
16509 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16510 +                       put_nsproxy(old_nsp);
16511 +               }
16512 +       }
16513 +out:
16514 +       put_vx_info(old_vxi);
16515 +       return ret;
16516 +}
16517 +
16518 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16519 +{
16520 +       struct task_struct *old_reaper;
16521 +
16522 +       if (!vxi)
16523 +               return -EINVAL;
16524 +
16525 +       vxdprintk(VXD_CBIT(xid, 6),
16526 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16527 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16528 +
16529 +       old_reaper = vxi->vx_reaper;
16530 +       if (old_reaper == p)
16531 +               return 0;
16532 +
16533 +       /* set new child reaper */
16534 +       get_task_struct(p);
16535 +       vxi->vx_reaper = p;
16536 +       put_task_struct(old_reaper);
16537 +       return 0;
16538 +}
16539 +
16540 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16541 +{
16542 +       if (!vxi)
16543 +               return -EINVAL;
16544 +
16545 +       vxdprintk(VXD_CBIT(xid, 6),
16546 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16547 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16548 +
16549 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16550 +       // vxi->vx_initpid = p->tgid;
16551 +       vxi->vx_initpid = p->pid;
16552 +       return 0;
16553 +}
16554 +
16555 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16556 +{
16557 +       vxdprintk(VXD_CBIT(xid, 6),
16558 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16559 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16560 +
16561 +       vxi->exit_code = code;
16562 +       vxi->vx_initpid = 0;
16563 +}
16564 +
16565 +
16566 +void vx_set_persistent(struct vx_info *vxi)
16567 +{
16568 +       vxdprintk(VXD_CBIT(xid, 6),
16569 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16570 +
16571 +       get_vx_info(vxi);
16572 +       claim_vx_info(vxi, NULL);
16573 +}
16574 +
16575 +void vx_clear_persistent(struct vx_info *vxi)
16576 +{
16577 +       vxdprintk(VXD_CBIT(xid, 6),
16578 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16579 +
16580 +       release_vx_info(vxi, NULL);
16581 +       put_vx_info(vxi);
16582 +}
16583 +
16584 +void vx_update_persistent(struct vx_info *vxi)
16585 +{
16586 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16587 +               vx_set_persistent(vxi);
16588 +       else
16589 +               vx_clear_persistent(vxi);
16590 +}
16591 +
16592 +
16593 +/*     task must be current or locked          */
16594 +
16595 +void   exit_vx_info(struct task_struct *p, int code)
16596 +{
16597 +       struct vx_info *vxi = p->vx_info;
16598 +
16599 +       if (vxi) {
16600 +               atomic_dec(&vxi->cvirt.nr_threads);
16601 +               vx_nproc_dec(p);
16602 +
16603 +               vxi->exit_code = code;
16604 +               release_vx_info(vxi, p);
16605 +       }
16606 +}
16607 +
16608 +void   exit_vx_info_early(struct task_struct *p, int code)
16609 +{
16610 +       struct vx_info *vxi = p->vx_info;
16611 +
16612 +       if (vxi) {
16613 +               if (vxi->vx_initpid == p->pid)
16614 +                       vx_exit_init(vxi, p, code);
16615 +               if (vxi->vx_reaper == p)
16616 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16617 +       }
16618 +}
16619 +
16620 +
16621 +/* vserver syscall commands below here */
16622 +
16623 +/* taks xid and vx_info functions */
16624 +
16625 +#include <asm/uaccess.h>
16626 +
16627 +
16628 +int vc_task_xid(uint32_t id)
16629 +{
16630 +       xid_t xid;
16631 +
16632 +       if (id) {
16633 +               struct task_struct *tsk;
16634 +
16635 +               rcu_read_lock();
16636 +               tsk = find_task_by_real_pid(id);
16637 +               xid = (tsk) ? tsk->xid : -ESRCH;
16638 +               rcu_read_unlock();
16639 +       } else
16640 +               xid = vx_current_xid();
16641 +       return xid;
16642 +}
16643 +
16644 +
16645 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16646 +{
16647 +       struct vcmd_vx_info_v0 vc_data;
16648 +
16649 +       vc_data.xid = vxi->vx_id;
16650 +       vc_data.initpid = vxi->vx_initpid;
16651 +
16652 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16653 +               return -EFAULT;
16654 +       return 0;
16655 +}
16656 +
16657 +
16658 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16659 +{
16660 +       struct vcmd_ctx_stat_v0 vc_data;
16661 +
16662 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16663 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16664 +
16665 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16666 +               return -EFAULT;
16667 +       return 0;
16668 +}
16669 +
16670 +
16671 +/* context functions */
16672 +
16673 +int vc_ctx_create(uint32_t xid, void __user *data)
16674 +{
16675 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16676 +       struct vx_info *new_vxi;
16677 +       int ret;
16678 +
16679 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16680 +               return -EFAULT;
16681 +
16682 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16683 +               return -EINVAL;
16684 +
16685 +       new_vxi = __create_vx_info(xid);
16686 +       if (IS_ERR(new_vxi))
16687 +               return PTR_ERR(new_vxi);
16688 +
16689 +       /* initial flags */
16690 +       new_vxi->vx_flags = vc_data.flagword;
16691 +
16692 +       ret = -ENOEXEC;
16693 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16694 +               goto out;
16695 +
16696 +       ret = vx_migrate_task(current, new_vxi, (!data));
16697 +       if (ret)
16698 +               goto out;
16699 +
16700 +       /* return context id on success */
16701 +       ret = new_vxi->vx_id;
16702 +
16703 +       /* get a reference for persistent contexts */
16704 +       if ((vc_data.flagword & VXF_PERSISTENT))
16705 +               vx_set_persistent(new_vxi);
16706 +out:
16707 +       release_vx_info(new_vxi, NULL);
16708 +       put_vx_info(new_vxi);
16709 +       return ret;
16710 +}
16711 +
16712 +
16713 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16714 +{
16715 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16716 +       int ret;
16717 +
16718 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16719 +               return -EFAULT;
16720 +
16721 +       ret = vx_migrate_task(current, vxi, 0);
16722 +       if (ret)
16723 +               return ret;
16724 +       if (vc_data.flagword & VXM_SET_INIT)
16725 +               ret = vx_set_init(vxi, current);
16726 +       if (ret)
16727 +               return ret;
16728 +       if (vc_data.flagword & VXM_SET_REAPER)
16729 +               ret = vx_set_reaper(vxi, current);
16730 +       return ret;
16731 +}
16732 +
16733 +
16734 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16735 +{
16736 +       struct vcmd_ctx_flags_v0 vc_data;
16737 +
16738 +       vc_data.flagword = vxi->vx_flags;
16739 +
16740 +       /* special STATE flag handling */
16741 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16742 +
16743 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16744 +               return -EFAULT;
16745 +       return 0;
16746 +}
16747 +
16748 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16749 +{
16750 +       struct vcmd_ctx_flags_v0 vc_data;
16751 +       uint64_t mask, trigger;
16752 +
16753 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16754 +               return -EFAULT;
16755 +
16756 +       /* special STATE flag handling */
16757 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16758 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16759 +
16760 +       if (vxi == current_vx_info()) {
16761 +               /* if (trigger & VXF_STATE_SETUP)
16762 +                       vx_mask_cap_bset(vxi, current); */
16763 +               if (trigger & VXF_STATE_INIT) {
16764 +                       int ret;
16765 +
16766 +                       ret = vx_set_init(vxi, current);
16767 +                       if (ret)
16768 +                               return ret;
16769 +                       ret = vx_set_reaper(vxi, current);
16770 +                       if (ret)
16771 +                               return ret;
16772 +               }
16773 +       }
16774 +
16775 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16776 +               vc_data.flagword, mask);
16777 +       if (trigger & VXF_PERSISTENT)
16778 +               vx_update_persistent(vxi);
16779 +
16780 +       return 0;
16781 +}
16782 +
16783 +
16784 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16785 +{
16786 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16787 +
16788 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16789 +       return v;
16790 +}
16791 +
16792 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16793 +{
16794 +       kernel_cap_t c = __cap_empty_set;
16795 +
16796 +       c.cap[0] = v & 0xFFFFFFFF;
16797 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16798 +
16799 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16800 +       return c;
16801 +}
16802 +
16803 +
16804 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16805 +{
16806 +       if (bcaps)
16807 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16808 +       if (ccaps)
16809 +               *ccaps = vxi->vx_ccaps;
16810 +
16811 +       return 0;
16812 +}
16813 +
16814 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16815 +{
16816 +       struct vcmd_ctx_caps_v1 vc_data;
16817 +       int ret;
16818 +
16819 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16820 +       if (ret)
16821 +               return ret;
16822 +       vc_data.cmask = ~0ULL;
16823 +
16824 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16825 +               return -EFAULT;
16826 +       return 0;
16827 +}
16828 +
16829 +static int do_set_caps(struct vx_info *vxi,
16830 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16831 +{
16832 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16833 +
16834 +#if 0
16835 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16836 +               bcaps, bmask, ccaps, cmask);
16837 +#endif
16838 +       vxi->vx_bcaps = cap_t_from_caps(
16839 +               vs_mask_flags(bcold, bcaps, bmask));
16840 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16841 +
16842 +       return 0;
16843 +}
16844 +
16845 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16846 +{
16847 +       struct vcmd_ctx_caps_v1 vc_data;
16848 +
16849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16850 +               return -EFAULT;
16851 +
16852 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16853 +}
16854 +
16855 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16856 +{
16857 +       struct vcmd_bcaps vc_data;
16858 +       int ret;
16859 +
16860 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16861 +       if (ret)
16862 +               return ret;
16863 +       vc_data.bmask = ~0ULL;
16864 +
16865 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16866 +               return -EFAULT;
16867 +       return 0;
16868 +}
16869 +
16870 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16871 +{
16872 +       struct vcmd_bcaps vc_data;
16873 +
16874 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16875 +               return -EFAULT;
16876 +
16877 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16878 +}
16879 +
16880 +
16881 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16882 +{
16883 +       struct vcmd_umask vc_data;
16884 +
16885 +       vc_data.umask = vxi->vx_umask;
16886 +       vc_data.mask = ~0ULL;
16887 +
16888 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16889 +               return -EFAULT;
16890 +       return 0;
16891 +}
16892 +
16893 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16894 +{
16895 +       struct vcmd_umask vc_data;
16896 +
16897 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16898 +               return -EFAULT;
16899 +
16900 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16901 +               vc_data.umask, vc_data.mask);
16902 +       return 0;
16903 +}
16904 +
16905 +
16906 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16907 +{
16908 +       struct vcmd_wmask vc_data;
16909 +
16910 +       vc_data.wmask = vxi->vx_wmask;
16911 +       vc_data.mask = ~0ULL;
16912 +
16913 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16914 +               return -EFAULT;
16915 +       return 0;
16916 +}
16917 +
16918 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16919 +{
16920 +       struct vcmd_wmask vc_data;
16921 +
16922 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16923 +               return -EFAULT;
16924 +
16925 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16926 +               vc_data.wmask, vc_data.mask);
16927 +       return 0;
16928 +}
16929 +
16930 +
16931 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16932 +{
16933 +       struct vcmd_badness_v0 vc_data;
16934 +
16935 +       vc_data.bias = vxi->vx_badness_bias;
16936 +
16937 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16938 +               return -EFAULT;
16939 +       return 0;
16940 +}
16941 +
16942 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16943 +{
16944 +       struct vcmd_badness_v0 vc_data;
16945 +
16946 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16947 +               return -EFAULT;
16948 +
16949 +       vxi->vx_badness_bias = vc_data.bias;
16950 +       return 0;
16951 +}
16952 +
16953 +#include <linux/module.h>
16954 +
16955 +EXPORT_SYMBOL_GPL(free_vx_info);
16956 +
16957 diff -NurpP --minimal linux-3.2.5/kernel/vserver/cvirt.c linux-3.2.5-vs2.3.2.6/kernel/vserver/cvirt.c
16958 --- linux-3.2.5/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
16959 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/cvirt.c        2011-12-05 19:33:02.000000000 +0100
16960 @@ -0,0 +1,303 @@
16961 +/*
16962 + *  linux/kernel/vserver/cvirt.c
16963 + *
16964 + *  Virtual Server: Context Virtualization
16965 + *
16966 + *  Copyright (C) 2004-2007  Herbert Pötzl
16967 + *
16968 + *  V0.01  broken out from limit.c
16969 + *  V0.02  added utsname stuff
16970 + *  V0.03  changed vcmds to vxi arg
16971 + *
16972 + */
16973 +
16974 +#include <linux/types.h>
16975 +#include <linux/utsname.h>
16976 +#include <linux/vs_cvirt.h>
16977 +#include <linux/vserver/switch.h>
16978 +#include <linux/vserver/cvirt_cmd.h>
16979 +
16980 +#include <asm/uaccess.h>
16981 +
16982 +
16983 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16984 +{
16985 +       struct vx_info *vxi = current_vx_info();
16986 +
16987 +       set_normalized_timespec(uptime,
16988 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16989 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16990 +       if (!idle)
16991 +               return;
16992 +       set_normalized_timespec(idle,
16993 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16994 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16995 +       return;
16996 +}
16997 +
16998 +uint64_t vx_idle_jiffies(void)
16999 +{
17000 +       return init_task.utime + init_task.stime;
17001 +}
17002 +
17003 +
17004 +
17005 +static inline uint32_t __update_loadavg(uint32_t load,
17006 +       int wsize, int delta, int n)
17007 +{
17008 +       unsigned long long calc, prev;
17009 +
17010 +       /* just set it to n */
17011 +       if (unlikely(delta >= wsize))
17012 +               return (n << FSHIFT);
17013 +
17014 +       calc = delta * n;
17015 +       calc <<= FSHIFT;
17016 +       prev = (wsize - delta);
17017 +       prev *= load;
17018 +       calc += prev;
17019 +       do_div(calc, wsize);
17020 +       return calc;
17021 +}
17022 +
17023 +
17024 +void vx_update_load(struct vx_info *vxi)
17025 +{
17026 +       uint32_t now, last, delta;
17027 +       unsigned int nr_running, nr_uninterruptible;
17028 +       unsigned int total;
17029 +       unsigned long flags;
17030 +
17031 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17032 +
17033 +       now = jiffies;
17034 +       last = vxi->cvirt.load_last;
17035 +       delta = now - last;
17036 +
17037 +       if (delta < 5*HZ)
17038 +               goto out;
17039 +
17040 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17041 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17042 +       total = nr_running + nr_uninterruptible;
17043 +
17044 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17045 +               60*HZ, delta, total);
17046 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17047 +               5*60*HZ, delta, total);
17048 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17049 +               15*60*HZ, delta, total);
17050 +
17051 +       vxi->cvirt.load_last = now;
17052 +out:
17053 +       atomic_inc(&vxi->cvirt.load_updates);
17054 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17055 +}
17056 +
17057 +
17058 +/*
17059 + * Commands to do_syslog:
17060 + *
17061 + *      0 -- Close the log.  Currently a NOP.
17062 + *      1 -- Open the log. Currently a NOP.
17063 + *      2 -- Read from the log.
17064 + *      3 -- Read all messages remaining in the ring buffer.
17065 + *      4 -- Read and clear all messages remaining in the ring buffer
17066 + *      5 -- Clear ring buffer.
17067 + *      6 -- Disable printk's to console
17068 + *      7 -- Enable printk's to console
17069 + *      8 -- Set level of messages printed to console
17070 + *      9 -- Return number of unread characters in the log buffer
17071 + *     10 -- Return size of the log buffer
17072 + */
17073 +int vx_do_syslog(int type, char __user *buf, int len)
17074 +{
17075 +       int error = 0;
17076 +       int do_clear = 0;
17077 +       struct vx_info *vxi = current_vx_info();
17078 +       struct _vx_syslog *log;
17079 +
17080 +       if (!vxi)
17081 +               return -EINVAL;
17082 +       log = &vxi->cvirt.syslog;
17083 +
17084 +       switch (type) {
17085 +       case 0:         /* Close log */
17086 +       case 1:         /* Open log */
17087 +               break;
17088 +       case 2:         /* Read from log */
17089 +               error = wait_event_interruptible(log->log_wait,
17090 +                       (log->log_start - log->log_end));
17091 +               if (error)
17092 +                       break;
17093 +               spin_lock_irq(&log->logbuf_lock);
17094 +               spin_unlock_irq(&log->logbuf_lock);
17095 +               break;
17096 +       case 4:         /* Read/clear last kernel messages */
17097 +               do_clear = 1;
17098 +               /* fall through */
17099 +       case 3:         /* Read last kernel messages */
17100 +               return 0;
17101 +
17102 +       case 5:         /* Clear ring buffer */
17103 +               return 0;
17104 +
17105 +       case 6:         /* Disable logging to console */
17106 +       case 7:         /* Enable logging to console */
17107 +       case 8:         /* Set level of messages printed to console */
17108 +               break;
17109 +
17110 +       case 9:         /* Number of chars in the log buffer */
17111 +               return 0;
17112 +       case 10:        /* Size of the log buffer */
17113 +               return 0;
17114 +       default:
17115 +               error = -EINVAL;
17116 +               break;
17117 +       }
17118 +       return error;
17119 +}
17120 +
17121 +
17122 +/* virtual host info names */
17123 +
17124 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17125 +{
17126 +       struct nsproxy *nsproxy;
17127 +       struct uts_namespace *uts;
17128 +
17129 +       if (id == VHIN_CONTEXT)
17130 +               return vxi->vx_name;
17131 +
17132 +       nsproxy = vxi->space[0].vx_nsproxy;
17133 +       if (!nsproxy)
17134 +               return NULL;
17135 +
17136 +       uts = nsproxy->uts_ns;
17137 +       if (!uts)
17138 +               return NULL;
17139 +
17140 +       switch (id) {
17141 +       case VHIN_SYSNAME:
17142 +               return uts->name.sysname;
17143 +       case VHIN_NODENAME:
17144 +               return uts->name.nodename;
17145 +       case VHIN_RELEASE:
17146 +               return uts->name.release;
17147 +       case VHIN_VERSION:
17148 +               return uts->name.version;
17149 +       case VHIN_MACHINE:
17150 +               return uts->name.machine;
17151 +       case VHIN_DOMAINNAME:
17152 +               return uts->name.domainname;
17153 +       default:
17154 +               return NULL;
17155 +       }
17156 +       return NULL;
17157 +}
17158 +
17159 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17160 +{
17161 +       struct vcmd_vhi_name_v0 vc_data;
17162 +       char *name;
17163 +
17164 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17165 +               return -EFAULT;
17166 +
17167 +       name = vx_vhi_name(vxi, vc_data.field);
17168 +       if (!name)
17169 +               return -EINVAL;
17170 +
17171 +       memcpy(name, vc_data.name, 65);
17172 +       return 0;
17173 +}
17174 +
17175 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17176 +{
17177 +       struct vcmd_vhi_name_v0 vc_data;
17178 +       char *name;
17179 +
17180 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17181 +               return -EFAULT;
17182 +
17183 +       name = vx_vhi_name(vxi, vc_data.field);
17184 +       if (!name)
17185 +               return -EINVAL;
17186 +
17187 +       memcpy(vc_data.name, name, 65);
17188 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17189 +               return -EFAULT;
17190 +       return 0;
17191 +}
17192 +
17193 +
17194 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17195 +{
17196 +       struct vcmd_virt_stat_v0 vc_data;
17197 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17198 +       struct timespec uptime;
17199 +
17200 +       do_posix_clock_monotonic_gettime(&uptime);
17201 +       set_normalized_timespec(&uptime,
17202 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17203 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17204 +
17205 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17206 +       vc_data.uptime = timespec_to_ns(&uptime);
17207 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17208 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17209 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17210 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17211 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17212 +       vc_data.load[0] = cvirt->load[0];
17213 +       vc_data.load[1] = cvirt->load[1];
17214 +       vc_data.load[2] = cvirt->load[2];
17215 +
17216 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17217 +               return -EFAULT;
17218 +       return 0;
17219 +}
17220 +
17221 +
17222 +#ifdef CONFIG_VSERVER_VTIME
17223 +
17224 +/* virtualized time base */
17225 +
17226 +void vx_adjust_timespec(struct timespec *ts)
17227 +{
17228 +       struct vx_info *vxi;
17229 +
17230 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17231 +               return;
17232 +
17233 +       vxi = current_vx_info();
17234 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17235 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17236 +
17237 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17238 +               ts->tv_sec++;
17239 +               ts->tv_nsec -= NSEC_PER_SEC;
17240 +       } else if (ts->tv_nsec < 0) {
17241 +               ts->tv_sec--;
17242 +               ts->tv_nsec += NSEC_PER_SEC;
17243 +       }
17244 +}
17245 +
17246 +int vx_settimeofday(const struct timespec *ts)
17247 +{
17248 +       struct timespec ats, delta;
17249 +       struct vx_info *vxi;
17250 +
17251 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17252 +               return do_settimeofday(ts);
17253 +
17254 +       getnstimeofday(&ats);
17255 +       delta = timespec_sub(*ts, ats);
17256 +
17257 +       vxi = current_vx_info();
17258 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17259 +       return 0;
17260 +}
17261 +
17262 +#endif
17263 +
17264 diff -NurpP --minimal linux-3.2.5/kernel/vserver/cvirt_init.h linux-3.2.5-vs2.3.2.6/kernel/vserver/cvirt_init.h
17265 --- linux-3.2.5/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17266 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/cvirt_init.h   2011-12-05 19:33:02.000000000 +0100
17267 @@ -0,0 +1,70 @@
17268 +
17269 +
17270 +extern uint64_t vx_idle_jiffies(void);
17271 +
17272 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17273 +{
17274 +       uint64_t idle_jiffies = vx_idle_jiffies();
17275 +       uint64_t nsuptime;
17276 +
17277 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17278 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17279 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17280 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17281 +       cvirt->bias_ts.tv_sec = 0;
17282 +       cvirt->bias_ts.tv_nsec = 0;
17283 +
17284 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17285 +       atomic_set(&cvirt->nr_threads, 0);
17286 +       atomic_set(&cvirt->nr_running, 0);
17287 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17288 +       atomic_set(&cvirt->nr_onhold, 0);
17289 +
17290 +       spin_lock_init(&cvirt->load_lock);
17291 +       cvirt->load_last = jiffies;
17292 +       atomic_set(&cvirt->load_updates, 0);
17293 +       cvirt->load[0] = 0;
17294 +       cvirt->load[1] = 0;
17295 +       cvirt->load[2] = 0;
17296 +       atomic_set(&cvirt->total_forks, 0);
17297 +
17298 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17299 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17300 +       cvirt->syslog.log_start = 0;
17301 +       cvirt->syslog.log_end = 0;
17302 +       cvirt->syslog.con_start = 0;
17303 +       cvirt->syslog.logged_chars = 0;
17304 +}
17305 +
17306 +static inline
17307 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17308 +{
17309 +       // cvirt_pc->cpustat = { 0 };
17310 +}
17311 +
17312 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17313 +{
17314 +#ifdef CONFIG_VSERVER_WARN
17315 +       int value;
17316 +#endif
17317 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17318 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17319 +               cvirt, value);
17320 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17321 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17322 +               cvirt, value);
17323 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17324 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17325 +               cvirt, value);
17326 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17327 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17328 +               cvirt, value);
17329 +       return;
17330 +}
17331 +
17332 +static inline
17333 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17334 +{
17335 +       return;
17336 +}
17337 +
17338 diff -NurpP --minimal linux-3.2.5/kernel/vserver/cvirt_proc.h linux-3.2.5-vs2.3.2.6/kernel/vserver/cvirt_proc.h
17339 --- linux-3.2.5/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17340 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/cvirt_proc.h   2011-12-05 19:33:02.000000000 +0100
17341 @@ -0,0 +1,135 @@
17342 +#ifndef _VX_CVIRT_PROC_H
17343 +#define _VX_CVIRT_PROC_H
17344 +
17345 +#include <linux/nsproxy.h>
17346 +#include <linux/mnt_namespace.h>
17347 +#include <linux/ipc_namespace.h>
17348 +#include <linux/utsname.h>
17349 +#include <linux/ipc.h>
17350 +
17351 +
17352 +static inline
17353 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17354 +{
17355 +       struct mnt_namespace *ns;
17356 +       struct uts_namespace *uts;
17357 +       struct ipc_namespace *ipc;
17358 +       struct path path;
17359 +       char *pstr, *root;
17360 +       int length = 0;
17361 +
17362 +       if (!nsproxy)
17363 +               goto out;
17364 +
17365 +       length += sprintf(buffer + length,
17366 +               "NSProxy:\t%p [%p,%p,%p]\n",
17367 +               nsproxy, nsproxy->mnt_ns,
17368 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17369 +
17370 +       ns = nsproxy->mnt_ns;
17371 +       if (!ns)
17372 +               goto skip_ns;
17373 +
17374 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17375 +       if (!pstr)
17376 +               goto skip_ns;
17377 +
17378 +       path.mnt = ns->root;
17379 +       path.dentry = ns->root->mnt_root;
17380 +       root = d_path(&path, pstr, PATH_MAX - 2);
17381 +       length += sprintf(buffer + length,
17382 +               "Namespace:\t%p [#%u]\n"
17383 +               "RootPath:\t%s\n",
17384 +               ns, atomic_read(&ns->count),
17385 +               root);
17386 +       kfree(pstr);
17387 +skip_ns:
17388 +
17389 +       uts = nsproxy->uts_ns;
17390 +       if (!uts)
17391 +               goto skip_uts;
17392 +
17393 +       length += sprintf(buffer + length,
17394 +               "SysName:\t%.*s\n"
17395 +               "NodeName:\t%.*s\n"
17396 +               "Release:\t%.*s\n"
17397 +               "Version:\t%.*s\n"
17398 +               "Machine:\t%.*s\n"
17399 +               "DomainName:\t%.*s\n",
17400 +               __NEW_UTS_LEN, uts->name.sysname,
17401 +               __NEW_UTS_LEN, uts->name.nodename,
17402 +               __NEW_UTS_LEN, uts->name.release,
17403 +               __NEW_UTS_LEN, uts->name.version,
17404 +               __NEW_UTS_LEN, uts->name.machine,
17405 +               __NEW_UTS_LEN, uts->name.domainname);
17406 +skip_uts:
17407 +
17408 +       ipc = nsproxy->ipc_ns;
17409 +       if (!ipc)
17410 +               goto skip_ipc;
17411 +
17412 +       length += sprintf(buffer + length,
17413 +               "SEMS:\t\t%d %d %d %d  %d\n"
17414 +               "MSG:\t\t%d %d %d\n"
17415 +               "SHM:\t\t%lu %lu  %d %d\n",
17416 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17417 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17418 +               ipc->used_sems,
17419 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17420 +               (unsigned long)ipc->shm_ctlmax,
17421 +               (unsigned long)ipc->shm_ctlall,
17422 +               ipc->shm_ctlmni, ipc->shm_tot);
17423 +skip_ipc:
17424 +out:
17425 +       return length;
17426 +}
17427 +
17428 +
17429 +#include <linux/sched.h>
17430 +
17431 +#define LOAD_INT(x) ((x) >> FSHIFT)
17432 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17433 +
17434 +static inline
17435 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17436 +{
17437 +       int length = 0;
17438 +       int a, b, c;
17439 +
17440 +       length += sprintf(buffer + length,
17441 +               "BiasUptime:\t%lu.%02lu\n",
17442 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17443 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17444 +
17445 +       a = cvirt->load[0] + (FIXED_1 / 200);
17446 +       b = cvirt->load[1] + (FIXED_1 / 200);
17447 +       c = cvirt->load[2] + (FIXED_1 / 200);
17448 +       length += sprintf(buffer + length,
17449 +               "nr_threads:\t%d\n"
17450 +               "nr_running:\t%d\n"
17451 +               "nr_unintr:\t%d\n"
17452 +               "nr_onhold:\t%d\n"
17453 +               "load_updates:\t%d\n"
17454 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17455 +               "total_forks:\t%d\n",
17456 +               atomic_read(&cvirt->nr_threads),
17457 +               atomic_read(&cvirt->nr_running),
17458 +               atomic_read(&cvirt->nr_uninterruptible),
17459 +               atomic_read(&cvirt->nr_onhold),
17460 +               atomic_read(&cvirt->load_updates),
17461 +               LOAD_INT(a), LOAD_FRAC(a),
17462 +               LOAD_INT(b), LOAD_FRAC(b),
17463 +               LOAD_INT(c), LOAD_FRAC(c),
17464 +               atomic_read(&cvirt->total_forks));
17465 +       return length;
17466 +}
17467 +
17468 +static inline
17469 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17470 +       char *buffer, int cpu)
17471 +{
17472 +       int length = 0;
17473 +       return length;
17474 +}
17475 +
17476 +#endif /* _VX_CVIRT_PROC_H */
17477 diff -NurpP --minimal linux-3.2.5/kernel/vserver/debug.c linux-3.2.5-vs2.3.2.6/kernel/vserver/debug.c
17478 --- linux-3.2.5/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17479 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/debug.c        2011-12-05 19:33:02.000000000 +0100
17480 @@ -0,0 +1,32 @@
17481 +/*
17482 + *  kernel/vserver/debug.c
17483 + *
17484 + *  Copyright (C) 2005-2007 Herbert Pötzl
17485 + *
17486 + *  V0.01  vx_info dump support
17487 + *
17488 + */
17489 +
17490 +#include <linux/module.h>
17491 +
17492 +#include <linux/vserver/context.h>
17493 +
17494 +
17495 +void   dump_vx_info(struct vx_info *vxi, int level)
17496 +{
17497 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17498 +               atomic_read(&vxi->vx_usecnt),
17499 +               atomic_read(&vxi->vx_tasks),
17500 +               vxi->vx_state);
17501 +       if (level > 0) {
17502 +               __dump_vx_limit(&vxi->limit);
17503 +               __dump_vx_sched(&vxi->sched);
17504 +               __dump_vx_cvirt(&vxi->cvirt);
17505 +               __dump_vx_cacct(&vxi->cacct);
17506 +       }
17507 +       printk("---\n");
17508 +}
17509 +
17510 +
17511 +EXPORT_SYMBOL_GPL(dump_vx_info);
17512 +
17513 diff -NurpP --minimal linux-3.2.5/kernel/vserver/device.c linux-3.2.5-vs2.3.2.6/kernel/vserver/device.c
17514 --- linux-3.2.5/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17515 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/device.c       2011-12-05 19:33:02.000000000 +0100
17516 @@ -0,0 +1,443 @@
17517 +/*
17518 + *  linux/kernel/vserver/device.c
17519 + *
17520 + *  Linux-VServer: Device Support
17521 + *
17522 + *  Copyright (C) 2006  Herbert Pötzl
17523 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17524 + *
17525 + *  V0.01  device mapping basics
17526 + *  V0.02  added defaults
17527 + *
17528 + */
17529 +
17530 +#include <linux/slab.h>
17531 +#include <linux/rcupdate.h>
17532 +#include <linux/fs.h>
17533 +#include <linux/namei.h>
17534 +#include <linux/hash.h>
17535 +
17536 +#include <asm/errno.h>
17537 +#include <asm/uaccess.h>
17538 +#include <linux/vserver/base.h>
17539 +#include <linux/vserver/debug.h>
17540 +#include <linux/vserver/context.h>
17541 +#include <linux/vserver/device.h>
17542 +#include <linux/vserver/device_cmd.h>
17543 +
17544 +
17545 +#define DMAP_HASH_BITS 4
17546 +
17547 +
17548 +struct vs_mapping {
17549 +       union {
17550 +               struct hlist_node hlist;
17551 +               struct list_head list;
17552 +       } u;
17553 +#define dm_hlist       u.hlist
17554 +#define dm_list                u.list
17555 +       xid_t xid;
17556 +       dev_t device;
17557 +       struct vx_dmap_target target;
17558 +};
17559 +
17560 +
17561 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17562 +
17563 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17564 +
17565 +static struct vx_dmap_target dmap_defaults[2] = {
17566 +       { .flags = DATTR_OPEN },
17567 +       { .flags = DATTR_OPEN },
17568 +};
17569 +
17570 +
17571 +struct kmem_cache *dmap_cachep __read_mostly;
17572 +
17573 +int __init dmap_cache_init(void)
17574 +{
17575 +       dmap_cachep = kmem_cache_create("dmap_cache",
17576 +               sizeof(struct vs_mapping), 0,
17577 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17578 +       return 0;
17579 +}
17580 +
17581 +__initcall(dmap_cache_init);
17582 +
17583 +
17584 +static inline unsigned int __hashval(dev_t dev, int bits)
17585 +{
17586 +       return hash_long((unsigned long)dev, bits);
17587 +}
17588 +
17589 +
17590 +/*     __hash_mapping()
17591 + *     add the mapping to the hash table
17592 + */
17593 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17594 +{
17595 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17596 +       struct hlist_head *head, *hash = dmap_main_hash;
17597 +       int device = vdm->device;
17598 +
17599 +       spin_lock(hash_lock);
17600 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17601 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17602 +
17603 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17604 +       hlist_add_head(&vdm->dm_hlist, head);
17605 +       spin_unlock(hash_lock);
17606 +}
17607 +
17608 +
17609 +static inline int __mode_to_default(umode_t mode)
17610 +{
17611 +       switch (mode) {
17612 +       case S_IFBLK:
17613 +               return 0;
17614 +       case S_IFCHR:
17615 +               return 1;
17616 +       default:
17617 +               BUG();
17618 +       }
17619 +}
17620 +
17621 +
17622 +/*     __set_default()
17623 + *     set a default
17624 + */
17625 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17626 +       struct vx_dmap_target *vdmt)
17627 +{
17628 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17629 +       spin_lock(hash_lock);
17630 +
17631 +       if (vxi)
17632 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17633 +       else
17634 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17635 +
17636 +
17637 +       spin_unlock(hash_lock);
17638 +
17639 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17640 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17641 +}
17642 +
17643 +
17644 +/*     __remove_default()
17645 + *     remove a default
17646 + */
17647 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17648 +{
17649 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17650 +       spin_lock(hash_lock);
17651 +
17652 +       if (vxi)
17653 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17654 +       else    /* remove == reset */
17655 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17656 +
17657 +       spin_unlock(hash_lock);
17658 +       return 0;
17659 +}
17660 +
17661 +
17662 +/*     __find_mapping()
17663 + *     find a mapping in the hash table
17664 + *
17665 + *     caller must hold hash_lock
17666 + */
17667 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17668 +       struct vs_mapping **local, struct vs_mapping **global)
17669 +{
17670 +       struct hlist_head *hash = dmap_main_hash;
17671 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17672 +       struct hlist_node *pos;
17673 +       struct vs_mapping *vdm;
17674 +
17675 +       *local = NULL;
17676 +       if (global)
17677 +               *global = NULL;
17678 +
17679 +       hlist_for_each(pos, head) {
17680 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17681 +
17682 +               if ((vdm->device == device) &&
17683 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17684 +                       if (vdm->xid == xid) {
17685 +                               *local = vdm;
17686 +                               return 1;
17687 +                       } else if (global && vdm->xid == 0)
17688 +                               *global = vdm;
17689 +               }
17690 +       }
17691 +
17692 +       if (global && *global)
17693 +               return 0;
17694 +       else
17695 +               return -ENOENT;
17696 +}
17697 +
17698 +
17699 +/*     __lookup_mapping()
17700 + *     find a mapping and store the result in target and flags
17701 + */
17702 +static inline int __lookup_mapping(struct vx_info *vxi,
17703 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17704 +{
17705 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17706 +       struct vs_mapping *vdm, *global;
17707 +       struct vx_dmap_target *vdmt;
17708 +       int ret = 0;
17709 +       xid_t xid = vxi->vx_id;
17710 +       int index;
17711 +
17712 +       spin_lock(hash_lock);
17713 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17714 +               ret = 1;
17715 +               vdmt = &vdm->target;
17716 +               goto found;
17717 +       }
17718 +
17719 +       index = __mode_to_default(mode);
17720 +       if (vxi && vxi->dmap.targets[index].flags) {
17721 +               ret = 2;
17722 +               vdmt = &vxi->dmap.targets[index];
17723 +       } else if (global) {
17724 +               ret = 3;
17725 +               vdmt = &global->target;
17726 +               goto found;
17727 +       } else {
17728 +               ret = 4;
17729 +               vdmt = &dmap_defaults[index];
17730 +       }
17731 +
17732 +found:
17733 +       if (target && (vdmt->flags & DATTR_REMAP))
17734 +               *target = vdmt->target;
17735 +       else if (target)
17736 +               *target = device;
17737 +       if (flags)
17738 +               *flags = vdmt->flags;
17739 +
17740 +       spin_unlock(hash_lock);
17741 +
17742 +       return ret;
17743 +}
17744 +
17745 +
17746 +/*     __remove_mapping()
17747 + *     remove a mapping from the hash table
17748 + */
17749 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17750 +       umode_t mode)
17751 +{
17752 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17753 +       struct vs_mapping *vdm = NULL;
17754 +       int ret = 0;
17755 +
17756 +       spin_lock(hash_lock);
17757 +
17758 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17759 +               NULL);
17760 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17761 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17762 +       if (ret < 0)
17763 +               goto out;
17764 +       hlist_del(&vdm->dm_hlist);
17765 +
17766 +out:
17767 +       spin_unlock(hash_lock);
17768 +       if (vdm)
17769 +               kmem_cache_free(dmap_cachep, vdm);
17770 +       return ret;
17771 +}
17772 +
17773 +
17774 +
17775 +int vs_map_device(struct vx_info *vxi,
17776 +       dev_t device, dev_t *target, umode_t mode)
17777 +{
17778 +       int ret, flags = DATTR_MASK;
17779 +
17780 +       if (!vxi) {
17781 +               if (target)
17782 +                       *target = device;
17783 +               goto out;
17784 +       }
17785 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17786 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17787 +               device, target ? *target : 0, flags, mode, ret);
17788 +out:
17789 +       return (flags & DATTR_MASK);
17790 +}
17791 +
17792 +
17793 +
17794 +static int do_set_mapping(struct vx_info *vxi,
17795 +       dev_t device, dev_t target, int flags, umode_t mode)
17796 +{
17797 +       if (device) {
17798 +               struct vs_mapping *new;
17799 +
17800 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17801 +               if (!new)
17802 +                       return -ENOMEM;
17803 +
17804 +               INIT_HLIST_NODE(&new->dm_hlist);
17805 +               new->device = device;
17806 +               new->target.target = target;
17807 +               new->target.flags = flags | mode;
17808 +               new->xid = (vxi ? vxi->vx_id : 0);
17809 +
17810 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17811 +               __hash_mapping(vxi, new);
17812 +       } else {
17813 +               struct vx_dmap_target new = {
17814 +                       .target = target,
17815 +                       .flags = flags | mode,
17816 +               };
17817 +               __set_default(vxi, mode, &new);
17818 +       }
17819 +       return 0;
17820 +}
17821 +
17822 +
17823 +static int do_unset_mapping(struct vx_info *vxi,
17824 +       dev_t device, dev_t target, int flags, umode_t mode)
17825 +{
17826 +       int ret = -EINVAL;
17827 +
17828 +       if (device) {
17829 +               ret = __remove_mapping(vxi, device, mode);
17830 +               if (ret < 0)
17831 +                       goto out;
17832 +       } else {
17833 +               ret = __remove_default(vxi, mode);
17834 +               if (ret < 0)
17835 +                       goto out;
17836 +       }
17837 +
17838 +out:
17839 +       return ret;
17840 +}
17841 +
17842 +
17843 +static inline int __user_device(const char __user *name, dev_t *dev,
17844 +       umode_t *mode)
17845 +{
17846 +       struct nameidata nd;
17847 +       int ret;
17848 +
17849 +       if (!name) {
17850 +               *dev = 0;
17851 +               return 0;
17852 +       }
17853 +       ret = user_lpath(name, &nd.path);
17854 +       if (ret)
17855 +               return ret;
17856 +       if (nd.path.dentry->d_inode) {
17857 +               *dev = nd.path.dentry->d_inode->i_rdev;
17858 +               *mode = nd.path.dentry->d_inode->i_mode;
17859 +       }
17860 +       path_put(&nd.path);
17861 +       return 0;
17862 +}
17863 +
17864 +static inline int __mapping_mode(dev_t device, dev_t target,
17865 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17866 +{
17867 +       if (device)
17868 +               *mode = device_mode & S_IFMT;
17869 +       else if (target)
17870 +               *mode = target_mode & S_IFMT;
17871 +       else
17872 +               return -EINVAL;
17873 +
17874 +       /* if both given, device and target mode have to match */
17875 +       if (device && target &&
17876 +               ((device_mode ^ target_mode) & S_IFMT))
17877 +               return -EINVAL;
17878 +       return 0;
17879 +}
17880 +
17881 +
17882 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17883 +       const char __user *target_path, int flags, int set)
17884 +{
17885 +       dev_t device = ~0, target = ~0;
17886 +       umode_t device_mode = 0, target_mode = 0, mode;
17887 +       int ret;
17888 +
17889 +       ret = __user_device(device_path, &device, &device_mode);
17890 +       if (ret)
17891 +               return ret;
17892 +       ret = __user_device(target_path, &target, &target_mode);
17893 +       if (ret)
17894 +               return ret;
17895 +
17896 +       ret = __mapping_mode(device, target,
17897 +               device_mode, target_mode, &mode);
17898 +       if (ret)
17899 +               return ret;
17900 +
17901 +       if (set)
17902 +               return do_set_mapping(vxi, device, target,
17903 +                       flags, mode);
17904 +       else
17905 +               return do_unset_mapping(vxi, device, target,
17906 +                       flags, mode);
17907 +}
17908 +
17909 +
17910 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17911 +{
17912 +       struct vcmd_set_mapping_v0 vc_data;
17913 +
17914 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17915 +               return -EFAULT;
17916 +
17917 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17918 +               vc_data.flags, 1);
17919 +}
17920 +
17921 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17922 +{
17923 +       struct vcmd_set_mapping_v0 vc_data;
17924 +
17925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17926 +               return -EFAULT;
17927 +
17928 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17929 +               vc_data.flags, 0);
17930 +}
17931 +
17932 +
17933 +#ifdef CONFIG_COMPAT
17934 +
17935 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17936 +{
17937 +       struct vcmd_set_mapping_v0_x32 vc_data;
17938 +
17939 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17940 +               return -EFAULT;
17941 +
17942 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17943 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17944 +}
17945 +
17946 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17947 +{
17948 +       struct vcmd_set_mapping_v0_x32 vc_data;
17949 +
17950 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17951 +               return -EFAULT;
17952 +
17953 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17954 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17955 +}
17956 +
17957 +#endif /* CONFIG_COMPAT */
17958 +
17959 +
17960 diff -NurpP --minimal linux-3.2.5/kernel/vserver/dlimit.c linux-3.2.5-vs2.3.2.6/kernel/vserver/dlimit.c
17961 --- linux-3.2.5/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17962 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/dlimit.c       2011-12-05 19:33:02.000000000 +0100
17963 @@ -0,0 +1,531 @@
17964 +/*
17965 + *  linux/kernel/vserver/dlimit.c
17966 + *
17967 + *  Virtual Server: Context Disk Limits
17968 + *
17969 + *  Copyright (C) 2004-2009  Herbert Pötzl
17970 + *
17971 + *  V0.01  initial version
17972 + *  V0.02  compat32 splitup
17973 + *  V0.03  extended interface
17974 + *
17975 + */
17976 +
17977 +#include <linux/statfs.h>
17978 +#include <linux/sched.h>
17979 +#include <linux/namei.h>
17980 +#include <linux/vs_tag.h>
17981 +#include <linux/vs_dlimit.h>
17982 +#include <linux/vserver/dlimit_cmd.h>
17983 +#include <linux/slab.h>
17984 +// #include <linux/gfp.h>
17985 +
17986 +#include <asm/uaccess.h>
17987 +
17988 +/*     __alloc_dl_info()
17989 +
17990 +       * allocate an initialized dl_info struct
17991 +       * doesn't make it visible (hash)                        */
17992 +
17993 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17994 +{
17995 +       struct dl_info *new = NULL;
17996 +
17997 +       vxdprintk(VXD_CBIT(dlim, 5),
17998 +               "alloc_dl_info(%p,%d)*", sb, tag);
17999 +
18000 +       /* would this benefit from a slab cache? */
18001 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18002 +       if (!new)
18003 +               return 0;
18004 +
18005 +       memset(new, 0, sizeof(struct dl_info));
18006 +       new->dl_tag = tag;
18007 +       new->dl_sb = sb;
18008 +       // INIT_RCU_HEAD(&new->dl_rcu);
18009 +       INIT_HLIST_NODE(&new->dl_hlist);
18010 +       spin_lock_init(&new->dl_lock);
18011 +       atomic_set(&new->dl_refcnt, 0);
18012 +       atomic_set(&new->dl_usecnt, 0);
18013 +
18014 +       /* rest of init goes here */
18015 +
18016 +       vxdprintk(VXD_CBIT(dlim, 4),
18017 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18018 +       return new;
18019 +}
18020 +
18021 +/*     __dealloc_dl_info()
18022 +
18023 +       * final disposal of dl_info                             */
18024 +
18025 +static void __dealloc_dl_info(struct dl_info *dli)
18026 +{
18027 +       vxdprintk(VXD_CBIT(dlim, 4),
18028 +               "dealloc_dl_info(%p)", dli);
18029 +
18030 +       dli->dl_hlist.next = LIST_POISON1;
18031 +       dli->dl_tag = -1;
18032 +       dli->dl_sb = 0;
18033 +
18034 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18035 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18036 +
18037 +       kfree(dli);
18038 +}
18039 +
18040 +
18041 +/*     hash table for dl_info hash */
18042 +
18043 +#define DL_HASH_SIZE   13
18044 +
18045 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18046 +
18047 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18048 +
18049 +
18050 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18051 +{
18052 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18053 +}
18054 +
18055 +
18056 +
18057 +/*     __hash_dl_info()
18058 +
18059 +       * add the dli to the global hash table
18060 +       * requires the hash_lock to be held                     */
18061 +
18062 +static inline void __hash_dl_info(struct dl_info *dli)
18063 +{
18064 +       struct hlist_head *head;
18065 +
18066 +       vxdprintk(VXD_CBIT(dlim, 6),
18067 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18068 +       get_dl_info(dli);
18069 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18070 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18071 +}
18072 +
18073 +/*     __unhash_dl_info()
18074 +
18075 +       * remove the dli from the global hash table
18076 +       * requires the hash_lock to be held                     */
18077 +
18078 +static inline void __unhash_dl_info(struct dl_info *dli)
18079 +{
18080 +       vxdprintk(VXD_CBIT(dlim, 6),
18081 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18082 +       hlist_del_rcu(&dli->dl_hlist);
18083 +       put_dl_info(dli);
18084 +}
18085 +
18086 +
18087 +/*     __lookup_dl_info()
18088 +
18089 +       * requires the rcu_read_lock()
18090 +       * doesn't increment the dl_refcnt                       */
18091 +
18092 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18093 +{
18094 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18095 +       struct hlist_node *pos;
18096 +       struct dl_info *dli;
18097 +
18098 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18099 +
18100 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18101 +                       return dli;
18102 +               }
18103 +       }
18104 +       return NULL;
18105 +}
18106 +
18107 +
18108 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18109 +{
18110 +       struct dl_info *dli;
18111 +
18112 +       rcu_read_lock();
18113 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18114 +       vxdprintk(VXD_CBIT(dlim, 7),
18115 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18116 +       rcu_read_unlock();
18117 +       return dli;
18118 +}
18119 +
18120 +void rcu_free_dl_info(struct rcu_head *head)
18121 +{
18122 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18123 +       int usecnt, refcnt;
18124 +
18125 +       BUG_ON(!dli || !head);
18126 +
18127 +       usecnt = atomic_read(&dli->dl_usecnt);
18128 +       BUG_ON(usecnt < 0);
18129 +
18130 +       refcnt = atomic_read(&dli->dl_refcnt);
18131 +       BUG_ON(refcnt < 0);
18132 +
18133 +       vxdprintk(VXD_CBIT(dlim, 3),
18134 +               "rcu_free_dl_info(%p)", dli);
18135 +       if (!usecnt)
18136 +               __dealloc_dl_info(dli);
18137 +       else
18138 +               printk("!!! rcu didn't free\n");
18139 +}
18140 +
18141 +
18142 +
18143 +
18144 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18145 +       uint32_t flags, int add)
18146 +{
18147 +       struct path path;
18148 +       int ret;
18149 +
18150 +       ret = user_lpath(name, &path);
18151 +       if (!ret) {
18152 +               struct super_block *sb;
18153 +               struct dl_info *dli;
18154 +
18155 +               ret = -EINVAL;
18156 +               if (!path.dentry->d_inode)
18157 +                       goto out_release;
18158 +               if (!(sb = path.dentry->d_inode->i_sb))
18159 +                       goto out_release;
18160 +
18161 +               if (add) {
18162 +                       dli = __alloc_dl_info(sb, id);
18163 +                       spin_lock(&dl_info_hash_lock);
18164 +
18165 +                       ret = -EEXIST;
18166 +                       if (__lookup_dl_info(sb, id))
18167 +                               goto out_unlock;
18168 +                       __hash_dl_info(dli);
18169 +                       dli = NULL;
18170 +               } else {
18171 +                       spin_lock(&dl_info_hash_lock);
18172 +                       dli = __lookup_dl_info(sb, id);
18173 +
18174 +                       ret = -ESRCH;
18175 +                       if (!dli)
18176 +                               goto out_unlock;
18177 +                       __unhash_dl_info(dli);
18178 +               }
18179 +               ret = 0;
18180 +       out_unlock:
18181 +               spin_unlock(&dl_info_hash_lock);
18182 +               if (add && dli)
18183 +                       __dealloc_dl_info(dli);
18184 +       out_release:
18185 +               path_put(&path);
18186 +       }
18187 +       return ret;
18188 +}
18189 +
18190 +int vc_add_dlimit(uint32_t id, void __user *data)
18191 +{
18192 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18193 +
18194 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18195 +               return -EFAULT;
18196 +
18197 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18198 +}
18199 +
18200 +int vc_rem_dlimit(uint32_t id, void __user *data)
18201 +{
18202 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18203 +
18204 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18205 +               return -EFAULT;
18206 +
18207 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18208 +}
18209 +
18210 +#ifdef CONFIG_COMPAT
18211 +
18212 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18213 +{
18214 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18215 +
18216 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18217 +               return -EFAULT;
18218 +
18219 +       return do_addrem_dlimit(id,
18220 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18221 +}
18222 +
18223 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18224 +{
18225 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18226 +
18227 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18228 +               return -EFAULT;
18229 +
18230 +       return do_addrem_dlimit(id,
18231 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18232 +}
18233 +
18234 +#endif /* CONFIG_COMPAT */
18235 +
18236 +
18237 +static inline
18238 +int do_set_dlimit(uint32_t id, const char __user *name,
18239 +       uint32_t space_used, uint32_t space_total,
18240 +       uint32_t inodes_used, uint32_t inodes_total,
18241 +       uint32_t reserved, uint32_t flags)
18242 +{
18243 +       struct path path;
18244 +       int ret;
18245 +
18246 +       ret = user_lpath(name, &path);
18247 +       if (!ret) {
18248 +               struct super_block *sb;
18249 +               struct dl_info *dli;
18250 +
18251 +               ret = -EINVAL;
18252 +               if (!path.dentry->d_inode)
18253 +                       goto out_release;
18254 +               if (!(sb = path.dentry->d_inode->i_sb))
18255 +                       goto out_release;
18256 +
18257 +               /* sanity checks */
18258 +               if ((reserved != CDLIM_KEEP &&
18259 +                       reserved > 100) ||
18260 +                       (inodes_used != CDLIM_KEEP &&
18261 +                       inodes_used > inodes_total) ||
18262 +                       (space_used != CDLIM_KEEP &&
18263 +                       space_used > space_total))
18264 +                       goto out_release;
18265 +
18266 +               ret = -ESRCH;
18267 +               dli = locate_dl_info(sb, id);
18268 +               if (!dli)
18269 +                       goto out_release;
18270 +
18271 +               spin_lock(&dli->dl_lock);
18272 +
18273 +               if (inodes_used != CDLIM_KEEP)
18274 +                       dli->dl_inodes_used = inodes_used;
18275 +               if (inodes_total != CDLIM_KEEP)
18276 +                       dli->dl_inodes_total = inodes_total;
18277 +               if (space_used != CDLIM_KEEP)
18278 +                       dli->dl_space_used = dlimit_space_32to64(
18279 +                               space_used, flags, DLIMS_USED);
18280 +
18281 +               if (space_total == CDLIM_INFINITY)
18282 +                       dli->dl_space_total = DLIM_INFINITY;
18283 +               else if (space_total != CDLIM_KEEP)
18284 +                       dli->dl_space_total = dlimit_space_32to64(
18285 +                               space_total, flags, DLIMS_TOTAL);
18286 +
18287 +               if (reserved != CDLIM_KEEP)
18288 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18289 +
18290 +               spin_unlock(&dli->dl_lock);
18291 +
18292 +               put_dl_info(dli);
18293 +               ret = 0;
18294 +
18295 +       out_release:
18296 +               path_put(&path);
18297 +       }
18298 +       return ret;
18299 +}
18300 +
18301 +int vc_set_dlimit(uint32_t id, void __user *data)
18302 +{
18303 +       struct vcmd_ctx_dlimit_v0 vc_data;
18304 +
18305 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18306 +               return -EFAULT;
18307 +
18308 +       return do_set_dlimit(id, vc_data.name,
18309 +               vc_data.space_used, vc_data.space_total,
18310 +               vc_data.inodes_used, vc_data.inodes_total,
18311 +               vc_data.reserved, vc_data.flags);
18312 +}
18313 +
18314 +#ifdef CONFIG_COMPAT
18315 +
18316 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18317 +{
18318 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18319 +
18320 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18321 +               return -EFAULT;
18322 +
18323 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18324 +               vc_data.space_used, vc_data.space_total,
18325 +               vc_data.inodes_used, vc_data.inodes_total,
18326 +               vc_data.reserved, vc_data.flags);
18327 +}
18328 +
18329 +#endif /* CONFIG_COMPAT */
18330 +
18331 +
18332 +static inline
18333 +int do_get_dlimit(uint32_t id, const char __user *name,
18334 +       uint32_t *space_used, uint32_t *space_total,
18335 +       uint32_t *inodes_used, uint32_t *inodes_total,
18336 +       uint32_t *reserved, uint32_t *flags)
18337 +{
18338 +       struct path path;
18339 +       int ret;
18340 +
18341 +       ret = user_lpath(name, &path);
18342 +       if (!ret) {
18343 +               struct super_block *sb;
18344 +               struct dl_info *dli;
18345 +
18346 +               ret = -EINVAL;
18347 +               if (!path.dentry->d_inode)
18348 +                       goto out_release;
18349 +               if (!(sb = path.dentry->d_inode->i_sb))
18350 +                       goto out_release;
18351 +
18352 +               ret = -ESRCH;
18353 +               dli = locate_dl_info(sb, id);
18354 +               if (!dli)
18355 +                       goto out_release;
18356 +
18357 +               spin_lock(&dli->dl_lock);
18358 +               *inodes_used = dli->dl_inodes_used;
18359 +               *inodes_total = dli->dl_inodes_total;
18360 +
18361 +               *space_used = dlimit_space_64to32(
18362 +                       dli->dl_space_used, flags, DLIMS_USED);
18363 +
18364 +               if (dli->dl_space_total == DLIM_INFINITY)
18365 +                       *space_total = CDLIM_INFINITY;
18366 +               else
18367 +                       *space_total = dlimit_space_64to32(
18368 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18369 +
18370 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18371 +               spin_unlock(&dli->dl_lock);
18372 +
18373 +               put_dl_info(dli);
18374 +               ret = -EFAULT;
18375 +
18376 +               ret = 0;
18377 +       out_release:
18378 +               path_put(&path);
18379 +       }
18380 +       return ret;
18381 +}
18382 +
18383 +
18384 +int vc_get_dlimit(uint32_t id, void __user *data)
18385 +{
18386 +       struct vcmd_ctx_dlimit_v0 vc_data;
18387 +       int ret;
18388 +
18389 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18390 +               return -EFAULT;
18391 +
18392 +       ret = do_get_dlimit(id, vc_data.name,
18393 +               &vc_data.space_used, &vc_data.space_total,
18394 +               &vc_data.inodes_used, &vc_data.inodes_total,
18395 +               &vc_data.reserved, &vc_data.flags);
18396 +       if (ret)
18397 +               return ret;
18398 +
18399 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18400 +               return -EFAULT;
18401 +       return 0;
18402 +}
18403 +
18404 +#ifdef CONFIG_COMPAT
18405 +
18406 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18407 +{
18408 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18409 +       int ret;
18410 +
18411 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18412 +               return -EFAULT;
18413 +
18414 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18415 +               &vc_data.space_used, &vc_data.space_total,
18416 +               &vc_data.inodes_used, &vc_data.inodes_total,
18417 +               &vc_data.reserved, &vc_data.flags);
18418 +       if (ret)
18419 +               return ret;
18420 +
18421 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18422 +               return -EFAULT;
18423 +       return 0;
18424 +}
18425 +
18426 +#endif /* CONFIG_COMPAT */
18427 +
18428 +
18429 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18430 +{
18431 +       struct dl_info *dli;
18432 +       __u64 blimit, bfree, bavail;
18433 +       __u32 ifree;
18434 +
18435 +       dli = locate_dl_info(sb, dx_current_tag());
18436 +       if (!dli)
18437 +               return;
18438 +
18439 +       spin_lock(&dli->dl_lock);
18440 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18441 +               goto no_ilim;
18442 +
18443 +       /* reduce max inodes available to limit */
18444 +       if (buf->f_files > dli->dl_inodes_total)
18445 +               buf->f_files = dli->dl_inodes_total;
18446 +
18447 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18448 +       /* reduce free inodes to min */
18449 +       if (ifree < buf->f_ffree)
18450 +               buf->f_ffree = ifree;
18451 +
18452 +no_ilim:
18453 +       if (dli->dl_space_total == DLIM_INFINITY)
18454 +               goto no_blim;
18455 +
18456 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18457 +
18458 +       if (dli->dl_space_total < dli->dl_space_used)
18459 +               bfree = 0;
18460 +       else
18461 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18462 +                       >> sb->s_blocksize_bits;
18463 +
18464 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18465 +       if (bavail < dli->dl_space_used)
18466 +               bavail = 0;
18467 +       else
18468 +               bavail = (bavail - dli->dl_space_used)
18469 +                       >> sb->s_blocksize_bits;
18470 +
18471 +       /* reduce max space available to limit */
18472 +       if (buf->f_blocks > blimit)
18473 +               buf->f_blocks = blimit;
18474 +
18475 +       /* reduce free space to min */
18476 +       if (bfree < buf->f_bfree)
18477 +               buf->f_bfree = bfree;
18478 +
18479 +       /* reduce avail space to min */
18480 +       if (bavail < buf->f_bavail)
18481 +               buf->f_bavail = bavail;
18482 +
18483 +no_blim:
18484 +       spin_unlock(&dli->dl_lock);
18485 +       put_dl_info(dli);
18486 +
18487 +       return;
18488 +}
18489 +
18490 +#include <linux/module.h>
18491 +
18492 +EXPORT_SYMBOL_GPL(locate_dl_info);
18493 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18494 +
18495 diff -NurpP --minimal linux-3.2.5/kernel/vserver/helper.c linux-3.2.5-vs2.3.2.6/kernel/vserver/helper.c
18496 --- linux-3.2.5/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18497 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/helper.c       2011-12-05 19:33:02.000000000 +0100
18498 @@ -0,0 +1,223 @@
18499 +/*
18500 + *  linux/kernel/vserver/helper.c
18501 + *
18502 + *  Virtual Context Support
18503 + *
18504 + *  Copyright (C) 2004-2007  Herbert Pötzl
18505 + *
18506 + *  V0.01  basic helper
18507 + *
18508 + */
18509 +
18510 +#include <linux/kmod.h>
18511 +#include <linux/reboot.h>
18512 +#include <linux/vs_context.h>
18513 +#include <linux/vs_network.h>
18514 +#include <linux/vserver/signal.h>
18515 +
18516 +
18517 +char vshelper_path[255] = "/sbin/vshelper";
18518 +
18519 +
18520 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18521 +{
18522 +       int ret;
18523 +
18524 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18525 +               printk( KERN_WARNING
18526 +                       "%s: (%s %s) returned %s with %d\n",
18527 +                       name, argv[1], argv[2],
18528 +                       sync ? "sync" : "async", ret);
18529 +       }
18530 +       vxdprintk(VXD_CBIT(switch, 4),
18531 +               "%s: (%s %s) returned %s with %d",
18532 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18533 +       return ret;
18534 +}
18535 +
18536 +/*
18537 + *      vshelper path is set via /proc/sys
18538 + *      invoked by vserver sys_reboot(), with
18539 + *      the following arguments
18540 + *
18541 + *      argv [0] = vshelper_path;
18542 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18543 + *      argv [2] = context identifier
18544 + *
18545 + *      envp [*] = type-specific parameters
18546 + */
18547 +
18548 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18549 +{
18550 +       char id_buf[8], cmd_buf[16];
18551 +       char uid_buf[16], pid_buf[16];
18552 +       int ret;
18553 +
18554 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18555 +       char *envp[] = {"HOME=/", "TERM=linux",
18556 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18557 +                       uid_buf, pid_buf, cmd_buf, 0};
18558 +
18559 +       if (vx_info_state(vxi, VXS_HELPER))
18560 +               return -EAGAIN;
18561 +       vxi->vx_state |= VXS_HELPER;
18562 +
18563 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18564 +
18565 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18566 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18567 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18568 +
18569 +       switch (cmd) {
18570 +       case LINUX_REBOOT_CMD_RESTART:
18571 +               argv[1] = "restart";
18572 +               break;
18573 +
18574 +       case LINUX_REBOOT_CMD_HALT:
18575 +               argv[1] = "halt";
18576 +               break;
18577 +
18578 +       case LINUX_REBOOT_CMD_POWER_OFF:
18579 +               argv[1] = "poweroff";
18580 +               break;
18581 +
18582 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18583 +               argv[1] = "swsusp";
18584 +               break;
18585 +
18586 +       case LINUX_REBOOT_CMD_OOM:
18587 +               argv[1] = "oom";
18588 +               break;
18589 +
18590 +       default:
18591 +               vxi->vx_state &= ~VXS_HELPER;
18592 +               return 0;
18593 +       }
18594 +
18595 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18596 +       vxi->vx_state &= ~VXS_HELPER;
18597 +       __wakeup_vx_info(vxi);
18598 +       return (ret) ? -EPERM : 0;
18599 +}
18600 +
18601 +
18602 +long vs_reboot(unsigned int cmd, void __user *arg)
18603 +{
18604 +       struct vx_info *vxi = current_vx_info();
18605 +       long ret = 0;
18606 +
18607 +       vxdprintk(VXD_CBIT(misc, 5),
18608 +               "vs_reboot(%p[#%d],%u)",
18609 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18610 +
18611 +       ret = vs_reboot_helper(vxi, cmd, arg);
18612 +       if (ret)
18613 +               return ret;
18614 +
18615 +       vxi->reboot_cmd = cmd;
18616 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18617 +               switch (cmd) {
18618 +               case LINUX_REBOOT_CMD_RESTART:
18619 +               case LINUX_REBOOT_CMD_HALT:
18620 +               case LINUX_REBOOT_CMD_POWER_OFF:
18621 +                       vx_info_kill(vxi, 0, SIGKILL);
18622 +                       vx_info_kill(vxi, 1, SIGKILL);
18623 +               default:
18624 +                       break;
18625 +               }
18626 +       }
18627 +       return 0;
18628 +}
18629 +
18630 +long vs_oom_action(unsigned int cmd)
18631 +{
18632 +       struct vx_info *vxi = current_vx_info();
18633 +       long ret = 0;
18634 +
18635 +       vxdprintk(VXD_CBIT(misc, 5),
18636 +               "vs_oom_action(%p[#%d],%u)",
18637 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18638 +
18639 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18640 +       if (ret)
18641 +               return ret;
18642 +
18643 +       vxi->reboot_cmd = cmd;
18644 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18645 +               vx_info_kill(vxi, 0, SIGKILL);
18646 +               vx_info_kill(vxi, 1, SIGKILL);
18647 +       }
18648 +       return 0;
18649 +}
18650 +
18651 +/*
18652 + *      argv [0] = vshelper_path;
18653 + *      argv [1] = action: "startup", "shutdown"
18654 + *      argv [2] = context identifier
18655 + *
18656 + *      envp [*] = type-specific parameters
18657 + */
18658 +
18659 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18660 +{
18661 +       char id_buf[8], cmd_buf[16];
18662 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18663 +       char *envp[] = {"HOME=/", "TERM=linux",
18664 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18665 +
18666 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18667 +               return 0;
18668 +
18669 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18670 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18671 +
18672 +       switch (cmd) {
18673 +       case VSC_STARTUP:
18674 +               argv[1] = "startup";
18675 +               break;
18676 +       case VSC_SHUTDOWN:
18677 +               argv[1] = "shutdown";
18678 +               break;
18679 +       default:
18680 +               return 0;
18681 +       }
18682 +
18683 +       return do_vshelper(vshelper_path, argv, envp, 1);
18684 +}
18685 +
18686 +
18687 +/*
18688 + *      argv [0] = vshelper_path;
18689 + *      argv [1] = action: "netup", "netdown"
18690 + *      argv [2] = context identifier
18691 + *
18692 + *      envp [*] = type-specific parameters
18693 + */
18694 +
18695 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18696 +{
18697 +       char id_buf[8], cmd_buf[16];
18698 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18699 +       char *envp[] = {"HOME=/", "TERM=linux",
18700 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18701 +
18702 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18703 +               return 0;
18704 +
18705 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18706 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18707 +
18708 +       switch (cmd) {
18709 +       case VSC_NETUP:
18710 +               argv[1] = "netup";
18711 +               break;
18712 +       case VSC_NETDOWN:
18713 +               argv[1] = "netdown";
18714 +               break;
18715 +       default:
18716 +               return 0;
18717 +       }
18718 +
18719 +       return do_vshelper(vshelper_path, argv, envp, 1);
18720 +}
18721 +
18722 diff -NurpP --minimal linux-3.2.5/kernel/vserver/history.c linux-3.2.5-vs2.3.2.6/kernel/vserver/history.c
18723 --- linux-3.2.5/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18724 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/history.c      2011-12-05 19:33:02.000000000 +0100
18725 @@ -0,0 +1,258 @@
18726 +/*
18727 + *  kernel/vserver/history.c
18728 + *
18729 + *  Virtual Context History Backtrace
18730 + *
18731 + *  Copyright (C) 2004-2007  Herbert Pötzl
18732 + *
18733 + *  V0.01  basic structure
18734 + *  V0.02  hash/unhash and trace
18735 + *  V0.03  preemption fixes
18736 + *
18737 + */
18738 +
18739 +#include <linux/module.h>
18740 +#include <asm/uaccess.h>
18741 +
18742 +#include <linux/vserver/context.h>
18743 +#include <linux/vserver/debug.h>
18744 +#include <linux/vserver/debug_cmd.h>
18745 +#include <linux/vserver/history.h>
18746 +
18747 +
18748 +#ifdef CONFIG_VSERVER_HISTORY
18749 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18750 +#else
18751 +#define VXH_SIZE       64
18752 +#endif
18753 +
18754 +struct _vx_history {
18755 +       unsigned int counter;
18756 +
18757 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18758 +};
18759 +
18760 +
18761 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18762 +
18763 +unsigned volatile int vxh_active = 1;
18764 +
18765 +static atomic_t sequence = ATOMIC_INIT(0);
18766 +
18767 +
18768 +/*     vxh_advance()
18769 +
18770 +       * requires disabled preemption                          */
18771 +
18772 +struct _vx_hist_entry *vxh_advance(void *loc)
18773 +{
18774 +       unsigned int cpu = smp_processor_id();
18775 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18776 +       struct _vx_hist_entry *entry;
18777 +       unsigned int index;
18778 +
18779 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18780 +       entry = &hist->entry[index];
18781 +
18782 +       entry->seq = atomic_inc_return(&sequence);
18783 +       entry->loc = loc;
18784 +       return entry;
18785 +}
18786 +
18787 +EXPORT_SYMBOL_GPL(vxh_advance);
18788 +
18789 +
18790 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18791 +
18792 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18793 +
18794 +
18795 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18796 +
18797 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18798 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18799 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18800 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18801 +
18802 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18803 +{
18804 +       switch (e->type) {
18805 +       case VXH_THROW_OOPS:
18806 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18807 +               break;
18808 +
18809 +       case VXH_GET_VX_INFO:
18810 +       case VXH_PUT_VX_INFO:
18811 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18812 +                       VXH_LOC_ARGS(e),
18813 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18814 +                       VXH_VXI_ARGS(e));
18815 +               break;
18816 +
18817 +       case VXH_INIT_VX_INFO:
18818 +       case VXH_SET_VX_INFO:
18819 +       case VXH_CLR_VX_INFO:
18820 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18821 +                       VXH_LOC_ARGS(e),
18822 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18823 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18824 +                       VXH_VXI_ARGS(e), e->sc.data);
18825 +               break;
18826 +
18827 +       case VXH_CLAIM_VX_INFO:
18828 +       case VXH_RELEASE_VX_INFO:
18829 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18830 +                       VXH_LOC_ARGS(e),
18831 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18832 +                       VXH_VXI_ARGS(e), e->sc.data);
18833 +               break;
18834 +
18835 +       case VXH_ALLOC_VX_INFO:
18836 +       case VXH_DEALLOC_VX_INFO:
18837 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18838 +                       VXH_LOC_ARGS(e),
18839 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18840 +                       VXH_VXI_ARGS(e));
18841 +               break;
18842 +
18843 +       case VXH_HASH_VX_INFO:
18844 +       case VXH_UNHASH_VX_INFO:
18845 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18846 +                       VXH_LOC_ARGS(e),
18847 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18848 +                       VXH_VXI_ARGS(e));
18849 +               break;
18850 +
18851 +       case VXH_LOC_VX_INFO:
18852 +       case VXH_LOOKUP_VX_INFO:
18853 +       case VXH_CREATE_VX_INFO:
18854 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18855 +                       VXH_LOC_ARGS(e),
18856 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18857 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18858 +                       e->ll.arg, VXH_VXI_ARGS(e));
18859 +               break;
18860 +       }
18861 +}
18862 +
18863 +static void __vxh_dump_history(void)
18864 +{
18865 +       unsigned int i, cpu;
18866 +
18867 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18868 +               atomic_read(&sequence), NR_CPUS);
18869 +
18870 +       for (i = 0; i < VXH_SIZE; i++) {
18871 +               for_each_online_cpu(cpu) {
18872 +                       struct _vx_history *hist =
18873 +                               &per_cpu(vx_history_buffer, cpu);
18874 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18875 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18876 +
18877 +                       vxh_dump_entry(entry, cpu);
18878 +               }
18879 +       }
18880 +}
18881 +
18882 +void   vxh_dump_history(void)
18883 +{
18884 +       vxh_active = 0;
18885 +#ifdef CONFIG_SMP
18886 +       local_irq_enable();
18887 +       smp_send_stop();
18888 +       local_irq_disable();
18889 +#endif
18890 +       __vxh_dump_history();
18891 +}
18892 +
18893 +
18894 +/* vserver syscall commands below here */
18895 +
18896 +
18897 +int vc_dump_history(uint32_t id)
18898 +{
18899 +       vxh_active = 0;
18900 +       __vxh_dump_history();
18901 +       vxh_active = 1;
18902 +
18903 +       return 0;
18904 +}
18905 +
18906 +
18907 +int do_read_history(struct __user _vx_hist_entry *data,
18908 +       int cpu, uint32_t *index, uint32_t *count)
18909 +{
18910 +       int pos, ret = 0;
18911 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18912 +       int end = hist->counter;
18913 +       int start = end - VXH_SIZE + 2;
18914 +       int idx = *index;
18915 +
18916 +       /* special case: get current pos */
18917 +       if (!*count) {
18918 +               *index = end;
18919 +               return 0;
18920 +       }
18921 +
18922 +       /* have we lost some data? */
18923 +       if (idx < start)
18924 +               idx = start;
18925 +
18926 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18927 +               struct _vx_hist_entry *entry =
18928 +                       &hist->entry[idx % VXH_SIZE];
18929 +
18930 +               /* send entry to userspace */
18931 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18932 +               if (ret)
18933 +                       break;
18934 +       }
18935 +       /* save new index and count */
18936 +       *index = idx;
18937 +       *count = pos;
18938 +       return ret ? ret : (*index < end);
18939 +}
18940 +
18941 +int vc_read_history(uint32_t id, void __user *data)
18942 +{
18943 +       struct vcmd_read_history_v0 vc_data;
18944 +       int ret;
18945 +
18946 +       if (id >= NR_CPUS)
18947 +               return -EINVAL;
18948 +
18949 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18950 +               return -EFAULT;
18951 +
18952 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18953 +               id, &vc_data.index, &vc_data.count);
18954 +
18955 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18956 +               return -EFAULT;
18957 +       return ret;
18958 +}
18959 +
18960 +#ifdef CONFIG_COMPAT
18961 +
18962 +int vc_read_history_x32(uint32_t id, void __user *data)
18963 +{
18964 +       struct vcmd_read_history_v0_x32 vc_data;
18965 +       int ret;
18966 +
18967 +       if (id >= NR_CPUS)
18968 +               return -EINVAL;
18969 +
18970 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18971 +               return -EFAULT;
18972 +
18973 +       ret = do_read_history((struct __user _vx_hist_entry *)
18974 +               compat_ptr(vc_data.data_ptr),
18975 +               id, &vc_data.index, &vc_data.count);
18976 +
18977 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18978 +               return -EFAULT;
18979 +       return ret;
18980 +}
18981 +
18982 +#endif /* CONFIG_COMPAT */
18983 +
18984 diff -NurpP --minimal linux-3.2.5/kernel/vserver/inet.c linux-3.2.5-vs2.3.2.6/kernel/vserver/inet.c
18985 --- linux-3.2.5/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
18986 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/inet.c 2011-12-15 01:33:09.000000000 +0100
18987 @@ -0,0 +1,226 @@
18988 +
18989 +#include <linux/in.h>
18990 +#include <linux/inetdevice.h>
18991 +#include <linux/export.h>
18992 +#include <linux/vs_inet.h>
18993 +#include <linux/vs_inet6.h>
18994 +#include <linux/vserver/debug.h>
18995 +#include <net/route.h>
18996 +#include <net/addrconf.h>
18997 +
18998 +
18999 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19000 +{
19001 +       int ret = 0;
19002 +
19003 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19004 +               ret = 1;
19005 +       else {
19006 +               struct nx_addr_v4 *ptr;
19007 +
19008 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19009 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19010 +                               ret = 1;
19011 +                               break;
19012 +                       }
19013 +               }
19014 +       }
19015 +
19016 +       vxdprintk(VXD_CBIT(net, 2),
19017 +               "nx_v4_addr_conflict(%p,%p): %d",
19018 +               nxi1, nxi2, ret);
19019 +
19020 +       return ret;
19021 +}
19022 +
19023 +
19024 +#ifdef CONFIG_IPV6
19025 +
19026 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19027 +{
19028 +       int ret = 0;
19029 +
19030 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19031 +               ret = 1;
19032 +       else {
19033 +               struct nx_addr_v6 *ptr;
19034 +
19035 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19036 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19037 +                               ret = 1;
19038 +                               break;
19039 +                       }
19040 +               }
19041 +       }
19042 +
19043 +       vxdprintk(VXD_CBIT(net, 2),
19044 +               "nx_v6_addr_conflict(%p,%p): %d",
19045 +               nxi1, nxi2, ret);
19046 +
19047 +       return ret;
19048 +}
19049 +
19050 +#endif
19051 +
19052 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19053 +{
19054 +       struct in_device *in_dev;
19055 +       struct in_ifaddr **ifap;
19056 +       struct in_ifaddr *ifa;
19057 +       int ret = 0;
19058 +
19059 +       if (!dev)
19060 +               goto out;
19061 +       in_dev = in_dev_get(dev);
19062 +       if (!in_dev)
19063 +               goto out;
19064 +
19065 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19066 +               ifap = &ifa->ifa_next) {
19067 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19068 +                       ret = 1;
19069 +                       break;
19070 +               }
19071 +       }
19072 +       in_dev_put(in_dev);
19073 +out:
19074 +       return ret;
19075 +}
19076 +
19077 +
19078 +#ifdef CONFIG_IPV6
19079 +
19080 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19081 +{
19082 +       struct inet6_dev *in_dev;
19083 +       struct inet6_ifaddr *ifa;
19084 +       int ret = 0;
19085 +
19086 +       if (!dev)
19087 +               goto out;
19088 +       in_dev = in6_dev_get(dev);
19089 +       if (!in_dev)
19090 +               goto out;
19091 +
19092 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19093 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19094 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19095 +                       ret = 1;
19096 +                       break;
19097 +               }
19098 +       }
19099 +       in6_dev_put(in_dev);
19100 +out:
19101 +       return ret;
19102 +}
19103 +
19104 +#endif
19105 +
19106 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19107 +{
19108 +       int ret = 1;
19109 +
19110 +       if (!nxi)
19111 +               goto out;
19112 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19113 +               goto out;
19114 +#ifdef CONFIG_IPV6
19115 +       ret = 2;
19116 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19117 +               goto out;
19118 +#endif
19119 +       ret = 0;
19120 +out:
19121 +       vxdprintk(VXD_CBIT(net, 3),
19122 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19123 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19124 +       return ret;
19125 +}
19126 +
19127 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19128 +       struct flowi4 *fl4)
19129 +{
19130 +       struct rtable *rt;
19131 +
19132 +       if (!nxi)
19133 +               return NULL;
19134 +
19135 +       /* FIXME: handle lback only case */
19136 +       if (!NX_IPV4(nxi))
19137 +               return ERR_PTR(-EPERM);
19138 +
19139 +       vxdprintk(VXD_CBIT(net, 4),
19140 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19141 +               nxi, nxi ? nxi->nx_id : 0,
19142 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19143 +
19144 +       /* single IP is unconditional */
19145 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19146 +               (fl4->saddr == INADDR_ANY))
19147 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19148 +
19149 +       if (fl4->saddr == INADDR_ANY) {
19150 +               struct nx_addr_v4 *ptr;
19151 +               __be32 found = 0;
19152 +
19153 +               rt = __ip_route_output_key(net, fl4);
19154 +               if (!IS_ERR(rt)) {
19155 +                       found = fl4->saddr;
19156 +                       ip_rt_put(rt);
19157 +                       vxdprintk(VXD_CBIT(net, 4),
19158 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19159 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19160 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19161 +                               goto found;
19162 +               }
19163 +
19164 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19165 +                       __be32 primary = ptr->ip[0].s_addr;
19166 +                       __be32 mask = ptr->mask.s_addr;
19167 +                       __be32 neta = primary & mask;
19168 +
19169 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19170 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19171 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19172 +                               NIPQUAD(mask), NIPQUAD(neta));
19173 +                       if ((found & mask) != neta)
19174 +                               continue;
19175 +
19176 +                       fl4->saddr = primary;
19177 +                       rt = __ip_route_output_key(net, fl4);
19178 +                       vxdprintk(VXD_CBIT(net, 4),
19179 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19180 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19181 +                       if (!IS_ERR(rt)) {
19182 +                               found = fl4->saddr;
19183 +                               ip_rt_put(rt);
19184 +                               if (found == primary)
19185 +                                       goto found;
19186 +                       }
19187 +               }
19188 +               /* still no source ip? */
19189 +               found = ipv4_is_loopback(fl4->daddr)
19190 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19191 +       found:
19192 +               /* assign src ip to flow */
19193 +               fl4->saddr = found;
19194 +
19195 +       } else {
19196 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19197 +                       return ERR_PTR(-EPERM);
19198 +       }
19199 +
19200 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19201 +               if (ipv4_is_loopback(fl4->daddr))
19202 +                       fl4->daddr = nxi->v4_lback.s_addr;
19203 +               if (ipv4_is_loopback(fl4->saddr))
19204 +                       fl4->saddr = nxi->v4_lback.s_addr;
19205 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19206 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19207 +               return ERR_PTR(-EPERM);
19208 +
19209 +       return NULL;
19210 +}
19211 +
19212 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19213 +
19214 diff -NurpP --minimal linux-3.2.5/kernel/vserver/init.c linux-3.2.5-vs2.3.2.6/kernel/vserver/init.c
19215 --- linux-3.2.5/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19216 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/init.c 2011-12-05 19:33:02.000000000 +0100
19217 @@ -0,0 +1,45 @@
19218 +/*
19219 + *  linux/kernel/init.c
19220 + *
19221 + *  Virtual Server Init
19222 + *
19223 + *  Copyright (C) 2004-2007  Herbert Pötzl
19224 + *
19225 + *  V0.01  basic structure
19226 + *
19227 + */
19228 +
19229 +#include <linux/init.h>
19230 +
19231 +int    vserver_register_sysctl(void);
19232 +void   vserver_unregister_sysctl(void);
19233 +
19234 +
19235 +static int __init init_vserver(void)
19236 +{
19237 +       int ret = 0;
19238 +
19239 +#ifdef CONFIG_VSERVER_DEBUG
19240 +       vserver_register_sysctl();
19241 +#endif
19242 +       return ret;
19243 +}
19244 +
19245 +
19246 +static void __exit exit_vserver(void)
19247 +{
19248 +
19249 +#ifdef CONFIG_VSERVER_DEBUG
19250 +       vserver_unregister_sysctl();
19251 +#endif
19252 +       return;
19253 +}
19254 +
19255 +/* FIXME: GFP_ZONETYPES gone
19256 +long vx_slab[GFP_ZONETYPES]; */
19257 +long vx_area;
19258 +
19259 +
19260 +module_init(init_vserver);
19261 +module_exit(exit_vserver);
19262 +
19263 diff -NurpP --minimal linux-3.2.5/kernel/vserver/inode.c linux-3.2.5-vs2.3.2.6/kernel/vserver/inode.c
19264 --- linux-3.2.5/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19265 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/inode.c        2011-12-06 23:56:11.000000000 +0100
19266 @@ -0,0 +1,437 @@
19267 +/*
19268 + *  linux/kernel/vserver/inode.c
19269 + *
19270 + *  Virtual Server: File System Support
19271 + *
19272 + *  Copyright (C) 2004-2007  Herbert Pötzl
19273 + *
19274 + *  V0.01  separated from vcontext V0.05
19275 + *  V0.02  moved to tag (instead of xid)
19276 + *
19277 + */
19278 +
19279 +#include <linux/tty.h>
19280 +#include <linux/proc_fs.h>
19281 +#include <linux/devpts_fs.h>
19282 +#include <linux/fs.h>
19283 +#include <linux/file.h>
19284 +#include <linux/mount.h>
19285 +#include <linux/parser.h>
19286 +#include <linux/namei.h>
19287 +#include <linux/vserver/inode.h>
19288 +#include <linux/vserver/inode_cmd.h>
19289 +#include <linux/vs_base.h>
19290 +#include <linux/vs_tag.h>
19291 +
19292 +#include <asm/uaccess.h>
19293 +
19294 +
19295 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19296 +{
19297 +       struct proc_dir_entry *entry;
19298 +
19299 +       if (!in || !in->i_sb)
19300 +               return -ESRCH;
19301 +
19302 +       *flags = IATTR_TAG
19303 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19304 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19305 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19306 +               | (IS_COW(in) ? IATTR_COW : 0);
19307 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19308 +
19309 +       if (S_ISDIR(in->i_mode))
19310 +               *mask |= IATTR_BARRIER;
19311 +
19312 +       if (IS_TAGGED(in)) {
19313 +               *tag = in->i_tag;
19314 +               *mask |= IATTR_TAG;
19315 +       }
19316 +
19317 +       switch (in->i_sb->s_magic) {
19318 +       case PROC_SUPER_MAGIC:
19319 +               entry = PROC_I(in)->pde;
19320 +
19321 +               /* check for specific inodes? */
19322 +               if (entry)
19323 +                       *mask |= IATTR_FLAGS;
19324 +               if (entry)
19325 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19326 +               else
19327 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19328 +               break;
19329 +
19330 +       case DEVPTS_SUPER_MAGIC:
19331 +               *tag = in->i_tag;
19332 +               *mask |= IATTR_TAG;
19333 +               break;
19334 +
19335 +       default:
19336 +               break;
19337 +       }
19338 +       return 0;
19339 +}
19340 +
19341 +int vc_get_iattr(void __user *data)
19342 +{
19343 +       struct path path;
19344 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19345 +       int ret;
19346 +
19347 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19348 +               return -EFAULT;
19349 +
19350 +       ret = user_lpath(vc_data.name, &path);
19351 +       if (!ret) {
19352 +               ret = __vc_get_iattr(path.dentry->d_inode,
19353 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19354 +               path_put(&path);
19355 +       }
19356 +       if (ret)
19357 +               return ret;
19358 +
19359 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19360 +               ret = -EFAULT;
19361 +       return ret;
19362 +}
19363 +
19364 +#ifdef CONFIG_COMPAT
19365 +
19366 +int vc_get_iattr_x32(void __user *data)
19367 +{
19368 +       struct path path;
19369 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19370 +       int ret;
19371 +
19372 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19373 +               return -EFAULT;
19374 +
19375 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19376 +       if (!ret) {
19377 +               ret = __vc_get_iattr(path.dentry->d_inode,
19378 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19379 +               path_put(&path);
19380 +       }
19381 +       if (ret)
19382 +               return ret;
19383 +
19384 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19385 +               ret = -EFAULT;
19386 +       return ret;
19387 +}
19388 +
19389 +#endif /* CONFIG_COMPAT */
19390 +
19391 +
19392 +int vc_fget_iattr(uint32_t fd, void __user *data)
19393 +{
19394 +       struct file *filp;
19395 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19396 +       int ret;
19397 +
19398 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19399 +               return -EFAULT;
19400 +
19401 +       filp = fget(fd);
19402 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19403 +               return -EBADF;
19404 +
19405 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19406 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19407 +
19408 +       fput(filp);
19409 +
19410 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19411 +               ret = -EFAULT;
19412 +       return ret;
19413 +}
19414 +
19415 +
19416 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19417 +{
19418 +       struct inode *in = de->d_inode;
19419 +       int error = 0, is_proc = 0, has_tag = 0;
19420 +       struct iattr attr = { 0 };
19421 +
19422 +       if (!in || !in->i_sb)
19423 +               return -ESRCH;
19424 +
19425 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19426 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19427 +               return -EINVAL;
19428 +
19429 +       has_tag = IS_TAGGED(in) ||
19430 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19431 +       if ((*mask & IATTR_TAG) && !has_tag)
19432 +               return -EINVAL;
19433 +
19434 +       mutex_lock(&in->i_mutex);
19435 +       if (*mask & IATTR_TAG) {
19436 +               attr.ia_tag = *tag;
19437 +               attr.ia_valid |= ATTR_TAG;
19438 +       }
19439 +
19440 +       if (*mask & IATTR_FLAGS) {
19441 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19442 +               unsigned int iflags = PROC_I(in)->vx_flags;
19443 +
19444 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19445 +                       | (*flags & IATTR_FLAGS);
19446 +               PROC_I(in)->vx_flags = iflags;
19447 +               if (entry)
19448 +                       entry->vx_flags = iflags;
19449 +       }
19450 +
19451 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19452 +               IATTR_BARRIER | IATTR_COW)) {
19453 +               int iflags = in->i_flags;
19454 +               int vflags = in->i_vflags;
19455 +
19456 +               if (*mask & IATTR_IMMUTABLE) {
19457 +                       if (*flags & IATTR_IMMUTABLE)
19458 +                               iflags |= S_IMMUTABLE;
19459 +                       else
19460 +                               iflags &= ~S_IMMUTABLE;
19461 +               }
19462 +               if (*mask & IATTR_IXUNLINK) {
19463 +                       if (*flags & IATTR_IXUNLINK)
19464 +                               iflags |= S_IXUNLINK;
19465 +                       else
19466 +                               iflags &= ~S_IXUNLINK;
19467 +               }
19468 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19469 +                       if (*flags & IATTR_BARRIER)
19470 +                               vflags |= V_BARRIER;
19471 +                       else
19472 +                               vflags &= ~V_BARRIER;
19473 +               }
19474 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19475 +                       if (*flags & IATTR_COW)
19476 +                               vflags |= V_COW;
19477 +                       else
19478 +                               vflags &= ~V_COW;
19479 +               }
19480 +               if (in->i_op && in->i_op->sync_flags) {
19481 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19482 +                       if (error)
19483 +                               goto out;
19484 +               }
19485 +       }
19486 +
19487 +       if (attr.ia_valid) {
19488 +               if (in->i_op && in->i_op->setattr)
19489 +                       error = in->i_op->setattr(de, &attr);
19490 +               else {
19491 +                       error = inode_change_ok(in, &attr);
19492 +                       if (!error) {
19493 +                               setattr_copy(in, &attr);
19494 +                               mark_inode_dirty(in);
19495 +                       }
19496 +               }
19497 +       }
19498 +
19499 +out:
19500 +       mutex_unlock(&in->i_mutex);
19501 +       return error;
19502 +}
19503 +
19504 +int vc_set_iattr(void __user *data)
19505 +{
19506 +       struct path path;
19507 +       struct vcmd_ctx_iattr_v1 vc_data;
19508 +       int ret;
19509 +
19510 +       if (!capable(CAP_LINUX_IMMUTABLE))
19511 +               return -EPERM;
19512 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19513 +               return -EFAULT;
19514 +
19515 +       ret = user_lpath(vc_data.name, &path);
19516 +       if (!ret) {
19517 +               ret = __vc_set_iattr(path.dentry,
19518 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19519 +               path_put(&path);
19520 +       }
19521 +
19522 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19523 +               ret = -EFAULT;
19524 +       return ret;
19525 +}
19526 +
19527 +#ifdef CONFIG_COMPAT
19528 +
19529 +int vc_set_iattr_x32(void __user *data)
19530 +{
19531 +       struct path path;
19532 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19533 +       int ret;
19534 +
19535 +       if (!capable(CAP_LINUX_IMMUTABLE))
19536 +               return -EPERM;
19537 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19538 +               return -EFAULT;
19539 +
19540 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19541 +       if (!ret) {
19542 +               ret = __vc_set_iattr(path.dentry,
19543 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19544 +               path_put(&path);
19545 +       }
19546 +
19547 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19548 +               ret = -EFAULT;
19549 +       return ret;
19550 +}
19551 +
19552 +#endif /* CONFIG_COMPAT */
19553 +
19554 +int vc_fset_iattr(uint32_t fd, void __user *data)
19555 +{
19556 +       struct file *filp;
19557 +       struct vcmd_ctx_fiattr_v0 vc_data;
19558 +       int ret;
19559 +
19560 +       if (!capable(CAP_LINUX_IMMUTABLE))
19561 +               return -EPERM;
19562 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19563 +               return -EFAULT;
19564 +
19565 +       filp = fget(fd);
19566 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19567 +               return -EBADF;
19568 +
19569 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19570 +               &vc_data.flags, &vc_data.mask);
19571 +
19572 +       fput(filp);
19573 +
19574 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19575 +               return -EFAULT;
19576 +       return ret;
19577 +}
19578 +
19579 +
19580 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19581 +
19582 +static match_table_t tokens = {
19583 +       {Opt_notagcheck, "notagcheck"},
19584 +#ifdef CONFIG_PROPAGATE
19585 +       {Opt_notag, "notag"},
19586 +       {Opt_tag, "tag"},
19587 +       {Opt_tagid, "tagid=%u"},
19588 +#endif
19589 +       {Opt_err, NULL}
19590 +};
19591 +
19592 +
19593 +static void __dx_parse_remove(char *string, char *opt)
19594 +{
19595 +       char *p = strstr(string, opt);
19596 +       char *q = p;
19597 +
19598 +       if (p) {
19599 +               while (*q != '\0' && *q != ',')
19600 +                       q++;
19601 +               while (*q)
19602 +                       *p++ = *q++;
19603 +               while (*p)
19604 +                       *p++ = '\0';
19605 +       }
19606 +}
19607 +
19608 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19609 +                unsigned long *flags)
19610 +{
19611 +       int set = 0;
19612 +       substring_t args[MAX_OPT_ARGS];
19613 +       int token;
19614 +       char *s, *p, *opts;
19615 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19616 +       int option = 0;
19617 +#endif
19618 +
19619 +       if (!string)
19620 +               return 0;
19621 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19622 +       if (!s)
19623 +               return 0;
19624 +
19625 +       opts = s;
19626 +       while ((p = strsep(&opts, ",")) != NULL) {
19627 +               token = match_token(p, tokens, args);
19628 +
19629 +               switch (token) {
19630 +#ifdef CONFIG_PROPAGATE
19631 +               case Opt_tag:
19632 +                       if (tag)
19633 +                               *tag = 0;
19634 +                       if (remove)
19635 +                               __dx_parse_remove(s, "tag");
19636 +                       *mnt_flags |= MNT_TAGID;
19637 +                       set |= MNT_TAGID;
19638 +                       break;
19639 +               case Opt_notag:
19640 +                       if (remove)
19641 +                               __dx_parse_remove(s, "notag");
19642 +                       *mnt_flags |= MNT_NOTAG;
19643 +                       set |= MNT_NOTAG;
19644 +                       break;
19645 +               case Opt_tagid:
19646 +                       if (tag && !match_int(args, &option))
19647 +                               *tag = option;
19648 +                       if (remove)
19649 +                               __dx_parse_remove(s, "tagid");
19650 +                       *mnt_flags |= MNT_TAGID;
19651 +                       set |= MNT_TAGID;
19652 +                       break;
19653 +#endif /* CONFIG_PROPAGATE */
19654 +               case Opt_notagcheck:
19655 +                       if (remove)
19656 +                               __dx_parse_remove(s, "notagcheck");
19657 +                       *flags |= MS_NOTAGCHECK;
19658 +                       set |= MS_NOTAGCHECK;
19659 +                       break;
19660 +               }
19661 +               vxdprintk(VXD_CBIT(tag, 7),
19662 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19663 +                       p, token, option);
19664 +       }
19665 +       if (set)
19666 +               strcpy(string, s);
19667 +       kfree(s);
19668 +       return set;
19669 +}
19670 +
19671 +#ifdef CONFIG_PROPAGATE
19672 +
19673 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19674 +{
19675 +       tag_t new_tag = 0;
19676 +       struct vfsmount *mnt;
19677 +       int propagate;
19678 +
19679 +       if (!nd)
19680 +               return;
19681 +       mnt = nd->path.mnt;
19682 +       if (!mnt)
19683 +               return;
19684 +
19685 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19686 +       if (propagate)
19687 +               new_tag = mnt->mnt_tag;
19688 +
19689 +       vxdprintk(VXD_CBIT(tag, 7),
19690 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19691 +               inode, inode->i_ino, inode->i_tag,
19692 +               new_tag, (propagate) ? 1 : 0);
19693 +
19694 +       if (propagate)
19695 +               inode->i_tag = new_tag;
19696 +}
19697 +
19698 +#include <linux/module.h>
19699 +
19700 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19701 +
19702 +#endif /* CONFIG_PROPAGATE */
19703 +
19704 diff -NurpP --minimal linux-3.2.5/kernel/vserver/limit.c linux-3.2.5-vs2.3.2.6/kernel/vserver/limit.c
19705 --- linux-3.2.5/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19706 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/limit.c        2011-12-15 01:52:48.000000000 +0100
19707 @@ -0,0 +1,330 @@
19708 +/*
19709 + *  linux/kernel/vserver/limit.c
19710 + *
19711 + *  Virtual Server: Context Limits
19712 + *
19713 + *  Copyright (C) 2004-2010  Herbert Pötzl
19714 + *
19715 + *  V0.01  broken out from vcontext V0.05
19716 + *  V0.02  changed vcmds to vxi arg
19717 + *  V0.03  added memory cgroup support
19718 + *
19719 + */
19720 +
19721 +#include <linux/sched.h>
19722 +#include <linux/module.h>
19723 +#include <linux/memcontrol.h>
19724 +#include <linux/res_counter.h>
19725 +#include <linux/vs_limit.h>
19726 +#include <linux/vserver/limit.h>
19727 +#include <linux/vserver/limit_cmd.h>
19728 +
19729 +#include <asm/uaccess.h>
19730 +
19731 +
19732 +const char *vlimit_name[NUM_LIMITS] = {
19733 +       [RLIMIT_CPU]            = "CPU",
19734 +       [RLIMIT_NPROC]          = "NPROC",
19735 +       [RLIMIT_NOFILE]         = "NOFILE",
19736 +       [RLIMIT_LOCKS]          = "LOCKS",
19737 +       [RLIMIT_SIGPENDING]     = "SIGP",
19738 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19739 +
19740 +       [VLIMIT_NSOCK]          = "NSOCK",
19741 +       [VLIMIT_OPENFD]         = "OPENFD",
19742 +       [VLIMIT_SHMEM]          = "SHMEM",
19743 +       [VLIMIT_DENTRY]         = "DENTRY",
19744 +};
19745 +
19746 +EXPORT_SYMBOL_GPL(vlimit_name);
19747 +
19748 +#define MASK_ENTRY(x)  (1 << (x))
19749 +
19750 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19751 +               /* minimum */
19752 +       0
19753 +       ,       /* softlimit */
19754 +       0
19755 +       ,       /* maximum */
19756 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19757 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19758 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19759 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19760 +
19761 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19762 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19763 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19764 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19765 +       0
19766 +};
19767 +               /* accounting only */
19768 +uint32_t account_mask =
19769 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19770 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19771 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19772 +       0;
19773 +
19774 +
19775 +static int is_valid_vlimit(int id)
19776 +{
19777 +       uint32_t mask = vlimit_mask.minimum |
19778 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19779 +       return mask & (1 << id);
19780 +}
19781 +
19782 +static int is_accounted_vlimit(int id)
19783 +{
19784 +       if (is_valid_vlimit(id))
19785 +               return 1;
19786 +       return account_mask & (1 << id);
19787 +}
19788 +
19789 +
19790 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19791 +{
19792 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19793 +       return VX_VLIM(limit);
19794 +}
19795 +
19796 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19797 +{
19798 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19799 +       return VX_VLIM(limit);
19800 +}
19801 +
19802 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19803 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19804 +{
19805 +       if (!is_valid_vlimit(id))
19806 +               return -EINVAL;
19807 +
19808 +       if (minimum)
19809 +               *minimum = CRLIM_UNSET;
19810 +       if (softlimit)
19811 +               *softlimit = vc_get_soft(vxi, id);
19812 +       if (maximum)
19813 +               *maximum = vc_get_hard(vxi, id);
19814 +       return 0;
19815 +}
19816 +
19817 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19818 +{
19819 +       struct vcmd_ctx_rlimit_v0 vc_data;
19820 +       int ret;
19821 +
19822 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19823 +               return -EFAULT;
19824 +
19825 +       ret = do_get_rlimit(vxi, vc_data.id,
19826 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19827 +       if (ret)
19828 +               return ret;
19829 +
19830 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19831 +               return -EFAULT;
19832 +       return 0;
19833 +}
19834 +
19835 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19836 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19837 +{
19838 +       if (!is_valid_vlimit(id))
19839 +               return -EINVAL;
19840 +
19841 +       if (maximum != CRLIM_KEEP)
19842 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19843 +       if (softlimit != CRLIM_KEEP)
19844 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19845 +
19846 +       /* clamp soft limit */
19847 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19848 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19849 +
19850 +       return 0;
19851 +}
19852 +
19853 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19854 +{
19855 +       struct vcmd_ctx_rlimit_v0 vc_data;
19856 +
19857 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19858 +               return -EFAULT;
19859 +
19860 +       return do_set_rlimit(vxi, vc_data.id,
19861 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19862 +}
19863 +
19864 +#ifdef CONFIG_IA32_EMULATION
19865 +
19866 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19867 +{
19868 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19869 +
19870 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19871 +               return -EFAULT;
19872 +
19873 +       return do_set_rlimit(vxi, vc_data.id,
19874 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19875 +}
19876 +
19877 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19878 +{
19879 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19880 +       int ret;
19881 +
19882 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19883 +               return -EFAULT;
19884 +
19885 +       ret = do_get_rlimit(vxi, vc_data.id,
19886 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19887 +       if (ret)
19888 +               return ret;
19889 +
19890 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19891 +               return -EFAULT;
19892 +       return 0;
19893 +}
19894 +
19895 +#endif /* CONFIG_IA32_EMULATION */
19896 +
19897 +
19898 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19899 +{
19900 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19901 +               return -EFAULT;
19902 +       return 0;
19903 +}
19904 +
19905 +
19906 +static inline void vx_reset_hits(struct _vx_limit *limit)
19907 +{
19908 +       int lim;
19909 +
19910 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19911 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19912 +       }
19913 +}
19914 +
19915 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19916 +{
19917 +       vx_reset_hits(&vxi->limit);
19918 +       return 0;
19919 +}
19920 +
19921 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19922 +{
19923 +       rlim_t value;
19924 +       int lim;
19925 +
19926 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19927 +               value = __rlim_get(limit, lim);
19928 +               __rlim_rmax(limit, lim) = value;
19929 +               __rlim_rmin(limit, lim) = value;
19930 +       }
19931 +}
19932 +
19933 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19934 +{
19935 +       vx_reset_minmax(&vxi->limit);
19936 +       return 0;
19937 +}
19938 +
19939 +
19940 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19941 +{
19942 +       struct vcmd_rlimit_stat_v0 vc_data;
19943 +       struct _vx_limit *limit = &vxi->limit;
19944 +       int id;
19945 +
19946 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19947 +               return -EFAULT;
19948 +
19949 +       id = vc_data.id;
19950 +       if (!is_accounted_vlimit(id))
19951 +               return -EINVAL;
19952 +
19953 +       vx_limit_fixup(limit, id);
19954 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19955 +       vc_data.value = __rlim_get(limit, id);
19956 +       vc_data.minimum = __rlim_rmin(limit, id);
19957 +       vc_data.maximum = __rlim_rmax(limit, id);
19958 +
19959 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19960 +               return -EFAULT;
19961 +       return 0;
19962 +}
19963 +
19964 +
19965 +void vx_vsi_meminfo(struct sysinfo *val)
19966 +{
19967 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19968 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
19969 +       u64 res_limit, res_usage;
19970 +
19971 +       if (!mcg)
19972 +               return;
19973 +
19974 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19975 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19976 +
19977 +       if (res_limit != RESOURCE_MAX)
19978 +               val->totalram = (res_limit >> PAGE_SHIFT);
19979 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19980 +       val->bufferram = 0;
19981 +       val->totalhigh = 0;
19982 +       val->freehigh = 0;
19983 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19984 +       return;
19985 +}
19986 +
19987 +void vx_vsi_swapinfo(struct sysinfo *val)
19988 +{
19989 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19990 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19991 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
19992 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19993 +       s64 swap_limit, swap_usage;
19994 +
19995 +       if (!mcg)
19996 +               return;
19997 +
19998 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19999 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20000 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20001 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20002 +
20003 +       /* memory unlimited */
20004 +       if (res_limit == RESOURCE_MAX)
20005 +               return;
20006 +
20007 +       swap_limit = memsw_limit - res_limit;
20008 +       /* we have a swap limit? */
20009 +       if (memsw_limit != RESOURCE_MAX)
20010 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20011 +
20012 +       /* calculate swap part */
20013 +       swap_usage = (memsw_usage > res_usage) ?
20014 +               memsw_usage - res_usage : 0;
20015 +
20016 +       /* total shown minus usage gives free swap */
20017 +       val->freeswap = (swap_usage < swap_limit) ?
20018 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20019 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20020 +       val->totalswap = 0;
20021 +       val->freeswap = 0;
20022 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20023 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20024 +       return;
20025 +}
20026 +
20027 +long vx_vsi_cached(struct sysinfo *val)
20028 +{
20029 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20030 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20031 +
20032 +       return mem_cgroup_stat_read_cache(mcg);
20033 +#else
20034 +       return 0;
20035 +#endif
20036 +}
20037 +
20038 diff -NurpP --minimal linux-3.2.5/kernel/vserver/limit_init.h linux-3.2.5-vs2.3.2.6/kernel/vserver/limit_init.h
20039 --- linux-3.2.5/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
20040 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/limit_init.h   2011-12-05 19:33:02.000000000 +0100
20041 @@ -0,0 +1,31 @@
20042 +
20043 +
20044 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20045 +{
20046 +       int lim;
20047 +
20048 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20049 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20050 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20051 +               __rlim_set(limit, lim, 0);
20052 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20053 +               __rlim_rmin(limit, lim) = 0;
20054 +               __rlim_rmax(limit, lim) = 0;
20055 +       }
20056 +}
20057 +
20058 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20059 +{
20060 +       rlim_t value;
20061 +       int lim;
20062 +
20063 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20064 +               if ((1 << lim) & VLIM_NOCHECK)
20065 +                       continue;
20066 +               value = __rlim_get(limit, lim);
20067 +               vxwprintk_xid(value,
20068 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20069 +                       limit, vlimit_name[lim], lim, (long)value);
20070 +       }
20071 +}
20072 +
20073 diff -NurpP --minimal linux-3.2.5/kernel/vserver/limit_proc.h linux-3.2.5-vs2.3.2.6/kernel/vserver/limit_proc.h
20074 --- linux-3.2.5/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20075 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/limit_proc.h   2011-12-05 19:33:02.000000000 +0100
20076 @@ -0,0 +1,57 @@
20077 +#ifndef _VX_LIMIT_PROC_H
20078 +#define _VX_LIMIT_PROC_H
20079 +
20080 +#include <linux/vserver/limit_int.h>
20081 +
20082 +
20083 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20084 +#define VX_LIMIT_TOP   \
20085 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20086 +
20087 +#define VX_LIMIT_ARG(r)                                \
20088 +       (unsigned long)__rlim_get(limit, r),    \
20089 +       (unsigned long)__rlim_rmin(limit, r),   \
20090 +       (unsigned long)__rlim_rmax(limit, r),   \
20091 +       VX_VLIM(__rlim_soft(limit, r)),         \
20092 +       VX_VLIM(__rlim_hard(limit, r)),         \
20093 +       atomic_read(&__rlim_lhit(limit, r))
20094 +
20095 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20096 +{
20097 +       vx_limit_fixup(limit, -1);
20098 +       return sprintf(buffer, VX_LIMIT_TOP
20099 +               "PROC"  VX_LIMIT_FMT
20100 +               "VM"    VX_LIMIT_FMT
20101 +               "VML"   VX_LIMIT_FMT
20102 +               "RSS"   VX_LIMIT_FMT
20103 +               "ANON"  VX_LIMIT_FMT
20104 +               "RMAP"  VX_LIMIT_FMT
20105 +               "FILES" VX_LIMIT_FMT
20106 +               "OFD"   VX_LIMIT_FMT
20107 +               "LOCKS" VX_LIMIT_FMT
20108 +               "SOCK"  VX_LIMIT_FMT
20109 +               "MSGQ"  VX_LIMIT_FMT
20110 +               "SHM"   VX_LIMIT_FMT
20111 +               "SEMA"  VX_LIMIT_FMT
20112 +               "SEMS"  VX_LIMIT_FMT
20113 +               "DENT"  VX_LIMIT_FMT,
20114 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20115 +               VX_LIMIT_ARG(RLIMIT_AS),
20116 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20117 +               VX_LIMIT_ARG(RLIMIT_RSS),
20118 +               VX_LIMIT_ARG(VLIMIT_ANON),
20119 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20120 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20121 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20122 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20123 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20124 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20125 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20126 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20127 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20128 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20129 +}
20130 +
20131 +#endif /* _VX_LIMIT_PROC_H */
20132 +
20133 +
20134 diff -NurpP --minimal linux-3.2.5/kernel/vserver/network.c linux-3.2.5-vs2.3.2.6/kernel/vserver/network.c
20135 --- linux-3.2.5/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20136 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/network.c      2011-12-05 19:33:02.000000000 +0100
20137 @@ -0,0 +1,912 @@
20138 +/*
20139 + *  linux/kernel/vserver/network.c
20140 + *
20141 + *  Virtual Server: Network Support
20142 + *
20143 + *  Copyright (C) 2003-2007  Herbert Pötzl
20144 + *
20145 + *  V0.01  broken out from vcontext V0.05
20146 + *  V0.02  cleaned up implementation
20147 + *  V0.03  added equiv nx commands
20148 + *  V0.04  switch to RCU based hash
20149 + *  V0.05  and back to locking again
20150 + *  V0.06  changed vcmds to nxi arg
20151 + *  V0.07  have __create claim() the nxi
20152 + *
20153 + */
20154 +
20155 +#include <linux/err.h>
20156 +#include <linux/slab.h>
20157 +#include <linux/rcupdate.h>
20158 +
20159 +#include <linux/vs_network.h>
20160 +#include <linux/vs_pid.h>
20161 +#include <linux/vserver/network_cmd.h>
20162 +
20163 +
20164 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20165 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20166 +
20167 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20168 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20169 +
20170 +
20171 +static int __init init_network(void)
20172 +{
20173 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20174 +               sizeof(struct nx_addr_v4), 0,
20175 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20176 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20177 +               sizeof(struct nx_addr_v6), 0,
20178 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20179 +       return 0;
20180 +}
20181 +
20182 +
20183 +/*     __alloc_nx_addr_v4()                                    */
20184 +
20185 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20186 +{
20187 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20188 +               nx_addr_v4_cachep, GFP_KERNEL);
20189 +
20190 +       if (!IS_ERR(nxa))
20191 +               memset(nxa, 0, sizeof(*nxa));
20192 +       return nxa;
20193 +}
20194 +
20195 +/*     __dealloc_nx_addr_v4()                                  */
20196 +
20197 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20198 +{
20199 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20200 +}
20201 +
20202 +/*     __dealloc_nx_addr_v4_all()                              */
20203 +
20204 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20205 +{
20206 +       while (nxa) {
20207 +               struct nx_addr_v4 *next = nxa->next;
20208 +
20209 +               __dealloc_nx_addr_v4(nxa);
20210 +               nxa = next;
20211 +       }
20212 +}
20213 +
20214 +
20215 +#ifdef CONFIG_IPV6
20216 +
20217 +/*     __alloc_nx_addr_v6()                                    */
20218 +
20219 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20220 +{
20221 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20222 +               nx_addr_v6_cachep, GFP_KERNEL);
20223 +
20224 +       if (!IS_ERR(nxa))
20225 +               memset(nxa, 0, sizeof(*nxa));
20226 +       return nxa;
20227 +}
20228 +
20229 +/*     __dealloc_nx_addr_v6()                                  */
20230 +
20231 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20232 +{
20233 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20234 +}
20235 +
20236 +/*     __dealloc_nx_addr_v6_all()                              */
20237 +
20238 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20239 +{
20240 +       while (nxa) {
20241 +               struct nx_addr_v6 *next = nxa->next;
20242 +
20243 +               __dealloc_nx_addr_v6(nxa);
20244 +               nxa = next;
20245 +       }
20246 +}
20247 +
20248 +#endif /* CONFIG_IPV6 */
20249 +
20250 +/*     __alloc_nx_info()
20251 +
20252 +       * allocate an initialized nx_info struct
20253 +       * doesn't make it visible (hash)                        */
20254 +
20255 +static struct nx_info *__alloc_nx_info(nid_t nid)
20256 +{
20257 +       struct nx_info *new = NULL;
20258 +
20259 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20260 +
20261 +       /* would this benefit from a slab cache? */
20262 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20263 +       if (!new)
20264 +               return 0;
20265 +
20266 +       memset(new, 0, sizeof(struct nx_info));
20267 +       new->nx_id = nid;
20268 +       INIT_HLIST_NODE(&new->nx_hlist);
20269 +       atomic_set(&new->nx_usecnt, 0);
20270 +       atomic_set(&new->nx_tasks, 0);
20271 +       new->nx_state = 0;
20272 +
20273 +       new->nx_flags = NXF_INIT_SET;
20274 +
20275 +       /* rest of init goes here */
20276 +
20277 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20278 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20279 +
20280 +       vxdprintk(VXD_CBIT(nid, 0),
20281 +               "alloc_nx_info(%d) = %p", nid, new);
20282 +       atomic_inc(&nx_global_ctotal);
20283 +       return new;
20284 +}
20285 +
20286 +/*     __dealloc_nx_info()
20287 +
20288 +       * final disposal of nx_info                             */
20289 +
20290 +static void __dealloc_nx_info(struct nx_info *nxi)
20291 +{
20292 +       vxdprintk(VXD_CBIT(nid, 0),
20293 +               "dealloc_nx_info(%p)", nxi);
20294 +
20295 +       nxi->nx_hlist.next = LIST_POISON1;
20296 +       nxi->nx_id = -1;
20297 +
20298 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20299 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20300 +
20301 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20302 +
20303 +       nxi->nx_state |= NXS_RELEASED;
20304 +       kfree(nxi);
20305 +       atomic_dec(&nx_global_ctotal);
20306 +}
20307 +
20308 +static void __shutdown_nx_info(struct nx_info *nxi)
20309 +{
20310 +       nxi->nx_state |= NXS_SHUTDOWN;
20311 +       vs_net_change(nxi, VSC_NETDOWN);
20312 +}
20313 +
20314 +/*     exported stuff                                          */
20315 +
20316 +void free_nx_info(struct nx_info *nxi)
20317 +{
20318 +       /* context shutdown is mandatory */
20319 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20320 +
20321 +       /* context must not be hashed */
20322 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20323 +
20324 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20325 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20326 +
20327 +       __dealloc_nx_info(nxi);
20328 +}
20329 +
20330 +
20331 +void __nx_set_lback(struct nx_info *nxi)
20332 +{
20333 +       int nid = nxi->nx_id;
20334 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20335 +
20336 +       nxi->v4_lback.s_addr = lback;
20337 +}
20338 +
20339 +extern int __nx_inet_add_lback(__be32 addr);
20340 +extern int __nx_inet_del_lback(__be32 addr);
20341 +
20342 +
20343 +/*     hash table for nx_info hash */
20344 +
20345 +#define NX_HASH_SIZE   13
20346 +
20347 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20348 +
20349 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20350 +
20351 +
20352 +static inline unsigned int __hashval(nid_t nid)
20353 +{
20354 +       return (nid % NX_HASH_SIZE);
20355 +}
20356 +
20357 +
20358 +
20359 +/*     __hash_nx_info()
20360 +
20361 +       * add the nxi to the global hash table
20362 +       * requires the hash_lock to be held                     */
20363 +
20364 +static inline void __hash_nx_info(struct nx_info *nxi)
20365 +{
20366 +       struct hlist_head *head;
20367 +
20368 +       vxd_assert_lock(&nx_info_hash_lock);
20369 +       vxdprintk(VXD_CBIT(nid, 4),
20370 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20371 +
20372 +       /* context must not be hashed */
20373 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20374 +
20375 +       nxi->nx_state |= NXS_HASHED;
20376 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20377 +       hlist_add_head(&nxi->nx_hlist, head);
20378 +       atomic_inc(&nx_global_cactive);
20379 +}
20380 +
20381 +/*     __unhash_nx_info()
20382 +
20383 +       * remove the nxi from the global hash table
20384 +       * requires the hash_lock to be held                     */
20385 +
20386 +static inline void __unhash_nx_info(struct nx_info *nxi)
20387 +{
20388 +       vxd_assert_lock(&nx_info_hash_lock);
20389 +       vxdprintk(VXD_CBIT(nid, 4),
20390 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20391 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20392 +
20393 +       /* context must be hashed */
20394 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20395 +       /* but without tasks */
20396 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20397 +
20398 +       nxi->nx_state &= ~NXS_HASHED;
20399 +       hlist_del(&nxi->nx_hlist);
20400 +       atomic_dec(&nx_global_cactive);
20401 +}
20402 +
20403 +
20404 +/*     __lookup_nx_info()
20405 +
20406 +       * requires the hash_lock to be held
20407 +       * doesn't increment the nx_refcnt                       */
20408 +
20409 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20410 +{
20411 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20412 +       struct hlist_node *pos;
20413 +       struct nx_info *nxi;
20414 +
20415 +       vxd_assert_lock(&nx_info_hash_lock);
20416 +       hlist_for_each(pos, head) {
20417 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20418 +
20419 +               if (nxi->nx_id == nid)
20420 +                       goto found;
20421 +       }
20422 +       nxi = NULL;
20423 +found:
20424 +       vxdprintk(VXD_CBIT(nid, 0),
20425 +               "__lookup_nx_info(#%u): %p[#%u]",
20426 +               nid, nxi, nxi ? nxi->nx_id : 0);
20427 +       return nxi;
20428 +}
20429 +
20430 +
20431 +/*     __create_nx_info()
20432 +
20433 +       * create the requested context
20434 +       * get(), claim() and hash it                            */
20435 +
20436 +static struct nx_info *__create_nx_info(int id)
20437 +{
20438 +       struct nx_info *new, *nxi = NULL;
20439 +
20440 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20441 +
20442 +       if (!(new = __alloc_nx_info(id)))
20443 +               return ERR_PTR(-ENOMEM);
20444 +
20445 +       /* required to make dynamic xids unique */
20446 +       spin_lock(&nx_info_hash_lock);
20447 +
20448 +       /* static context requested */
20449 +       if ((nxi = __lookup_nx_info(id))) {
20450 +               vxdprintk(VXD_CBIT(nid, 0),
20451 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20452 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20453 +                       nxi = ERR_PTR(-EBUSY);
20454 +               else
20455 +                       nxi = ERR_PTR(-EEXIST);
20456 +               goto out_unlock;
20457 +       }
20458 +       /* new context */
20459 +       vxdprintk(VXD_CBIT(nid, 0),
20460 +               "create_nx_info(%d) = %p (new)", id, new);
20461 +       claim_nx_info(new, NULL);
20462 +       __nx_set_lback(new);
20463 +       __hash_nx_info(get_nx_info(new));
20464 +       nxi = new, new = NULL;
20465 +
20466 +out_unlock:
20467 +       spin_unlock(&nx_info_hash_lock);
20468 +       if (new)
20469 +               __dealloc_nx_info(new);
20470 +       return nxi;
20471 +}
20472 +
20473 +
20474 +
20475 +/*     exported stuff                                          */
20476 +
20477 +
20478 +void unhash_nx_info(struct nx_info *nxi)
20479 +{
20480 +       __shutdown_nx_info(nxi);
20481 +       spin_lock(&nx_info_hash_lock);
20482 +       __unhash_nx_info(nxi);
20483 +       spin_unlock(&nx_info_hash_lock);
20484 +}
20485 +
20486 +/*     lookup_nx_info()
20487 +
20488 +       * search for a nx_info and get() it
20489 +       * negative id means current                             */
20490 +
20491 +struct nx_info *lookup_nx_info(int id)
20492 +{
20493 +       struct nx_info *nxi = NULL;
20494 +
20495 +       if (id < 0) {
20496 +               nxi = get_nx_info(current_nx_info());
20497 +       } else if (id > 1) {
20498 +               spin_lock(&nx_info_hash_lock);
20499 +               nxi = get_nx_info(__lookup_nx_info(id));
20500 +               spin_unlock(&nx_info_hash_lock);
20501 +       }
20502 +       return nxi;
20503 +}
20504 +
20505 +/*     nid_is_hashed()
20506 +
20507 +       * verify that nid is still hashed                       */
20508 +
20509 +int nid_is_hashed(nid_t nid)
20510 +{
20511 +       int hashed;
20512 +
20513 +       spin_lock(&nx_info_hash_lock);
20514 +       hashed = (__lookup_nx_info(nid) != NULL);
20515 +       spin_unlock(&nx_info_hash_lock);
20516 +       return hashed;
20517 +}
20518 +
20519 +
20520 +#ifdef CONFIG_PROC_FS
20521 +
20522 +/*     get_nid_list()
20523 +
20524 +       * get a subset of hashed nids for proc
20525 +       * assumes size is at least one                          */
20526 +
20527 +int get_nid_list(int index, unsigned int *nids, int size)
20528 +{
20529 +       int hindex, nr_nids = 0;
20530 +
20531 +       /* only show current and children */
20532 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20533 +               if (index > 0)
20534 +                       return 0;
20535 +               nids[nr_nids] = nx_current_nid();
20536 +               return 1;
20537 +       }
20538 +
20539 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20540 +               struct hlist_head *head = &nx_info_hash[hindex];
20541 +               struct hlist_node *pos;
20542 +
20543 +               spin_lock(&nx_info_hash_lock);
20544 +               hlist_for_each(pos, head) {
20545 +                       struct nx_info *nxi;
20546 +
20547 +                       if (--index > 0)
20548 +                               continue;
20549 +
20550 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20551 +                       nids[nr_nids] = nxi->nx_id;
20552 +                       if (++nr_nids >= size) {
20553 +                               spin_unlock(&nx_info_hash_lock);
20554 +                               goto out;
20555 +                       }
20556 +               }
20557 +               /* keep the lock time short */
20558 +               spin_unlock(&nx_info_hash_lock);
20559 +       }
20560 +out:
20561 +       return nr_nids;
20562 +}
20563 +#endif
20564 +
20565 +
20566 +/*
20567 + *     migrate task to new network
20568 + *     gets nxi, puts old_nxi on change
20569 + */
20570 +
20571 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20572 +{
20573 +       struct nx_info *old_nxi;
20574 +       int ret = 0;
20575 +
20576 +       if (!p || !nxi)
20577 +               BUG();
20578 +
20579 +       vxdprintk(VXD_CBIT(nid, 5),
20580 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20581 +               p, nxi, nxi->nx_id,
20582 +               atomic_read(&nxi->nx_usecnt),
20583 +               atomic_read(&nxi->nx_tasks));
20584 +
20585 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20586 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20587 +               return -EACCES;
20588 +
20589 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20590 +               return -EFAULT;
20591 +
20592 +       /* maybe disallow this completely? */
20593 +       old_nxi = task_get_nx_info(p);
20594 +       if (old_nxi == nxi)
20595 +               goto out;
20596 +
20597 +       task_lock(p);
20598 +       if (old_nxi)
20599 +               clr_nx_info(&p->nx_info);
20600 +       claim_nx_info(nxi, p);
20601 +       set_nx_info(&p->nx_info, nxi);
20602 +       p->nid = nxi->nx_id;
20603 +       task_unlock(p);
20604 +
20605 +       vxdprintk(VXD_CBIT(nid, 5),
20606 +               "moved task %p into nxi:%p[#%d]",
20607 +               p, nxi, nxi->nx_id);
20608 +
20609 +       if (old_nxi)
20610 +               release_nx_info(old_nxi, p);
20611 +       ret = 0;
20612 +out:
20613 +       put_nx_info(old_nxi);
20614 +       return ret;
20615 +}
20616 +
20617 +
20618 +void nx_set_persistent(struct nx_info *nxi)
20619 +{
20620 +       vxdprintk(VXD_CBIT(nid, 6),
20621 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20622 +
20623 +       get_nx_info(nxi);
20624 +       claim_nx_info(nxi, NULL);
20625 +}
20626 +
20627 +void nx_clear_persistent(struct nx_info *nxi)
20628 +{
20629 +       vxdprintk(VXD_CBIT(nid, 6),
20630 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20631 +
20632 +       release_nx_info(nxi, NULL);
20633 +       put_nx_info(nxi);
20634 +}
20635 +
20636 +void nx_update_persistent(struct nx_info *nxi)
20637 +{
20638 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20639 +               nx_set_persistent(nxi);
20640 +       else
20641 +               nx_clear_persistent(nxi);
20642 +}
20643 +
20644 +/* vserver syscall commands below here */
20645 +
20646 +/* taks nid and nx_info functions */
20647 +
20648 +#include <asm/uaccess.h>
20649 +
20650 +
20651 +int vc_task_nid(uint32_t id)
20652 +{
20653 +       nid_t nid;
20654 +
20655 +       if (id) {
20656 +               struct task_struct *tsk;
20657 +
20658 +               rcu_read_lock();
20659 +               tsk = find_task_by_real_pid(id);
20660 +               nid = (tsk) ? tsk->nid : -ESRCH;
20661 +               rcu_read_unlock();
20662 +       } else
20663 +               nid = nx_current_nid();
20664 +       return nid;
20665 +}
20666 +
20667 +
20668 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20669 +{
20670 +       struct vcmd_nx_info_v0 vc_data;
20671 +
20672 +       vc_data.nid = nxi->nx_id;
20673 +
20674 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20675 +               return -EFAULT;
20676 +       return 0;
20677 +}
20678 +
20679 +
20680 +/* network functions */
20681 +
20682 +int vc_net_create(uint32_t nid, void __user *data)
20683 +{
20684 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20685 +       struct nx_info *new_nxi;
20686 +       int ret;
20687 +
20688 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20689 +               return -EFAULT;
20690 +
20691 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20692 +               return -EINVAL;
20693 +
20694 +       new_nxi = __create_nx_info(nid);
20695 +       if (IS_ERR(new_nxi))
20696 +               return PTR_ERR(new_nxi);
20697 +
20698 +       /* initial flags */
20699 +       new_nxi->nx_flags = vc_data.flagword;
20700 +
20701 +       ret = -ENOEXEC;
20702 +       if (vs_net_change(new_nxi, VSC_NETUP))
20703 +               goto out;
20704 +
20705 +       ret = nx_migrate_task(current, new_nxi);
20706 +       if (ret)
20707 +               goto out;
20708 +
20709 +       /* return context id on success */
20710 +       ret = new_nxi->nx_id;
20711 +
20712 +       /* get a reference for persistent contexts */
20713 +       if ((vc_data.flagword & NXF_PERSISTENT))
20714 +               nx_set_persistent(new_nxi);
20715 +out:
20716 +       release_nx_info(new_nxi, NULL);
20717 +       put_nx_info(new_nxi);
20718 +       return ret;
20719 +}
20720 +
20721 +
20722 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20723 +{
20724 +       return nx_migrate_task(current, nxi);
20725 +}
20726 +
20727 +
20728 +
20729 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20730 +       uint16_t type, uint16_t flags)
20731 +{
20732 +       struct nx_addr_v4 *nxa = &nxi->v4;
20733 +
20734 +       if (NX_IPV4(nxi)) {
20735 +               /* locate last entry */
20736 +               for (; nxa->next; nxa = nxa->next);
20737 +               nxa->next = __alloc_nx_addr_v4();
20738 +               nxa = nxa->next;
20739 +
20740 +               if (IS_ERR(nxa))
20741 +                       return PTR_ERR(nxa);
20742 +       }
20743 +
20744 +       if (nxi->v4.next)
20745 +               /* remove single ip for ip list */
20746 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20747 +
20748 +       nxa->ip[0].s_addr = ip;
20749 +       nxa->ip[1].s_addr = ip2;
20750 +       nxa->mask.s_addr = mask;
20751 +       nxa->type = type;
20752 +       nxa->flags = flags;
20753 +       return 0;
20754 +}
20755 +
20756 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20757 +       uint16_t type, uint16_t flags)
20758 +{
20759 +       struct nx_addr_v4 *nxa = &nxi->v4;
20760 +
20761 +       switch (type) {
20762 +/*     case NXA_TYPE_ADDR:
20763 +               break;          */
20764 +
20765 +       case NXA_TYPE_ANY:
20766 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20767 +               memset(nxa, 0, sizeof(*nxa));
20768 +               break;
20769 +
20770 +       default:
20771 +               return -EINVAL;
20772 +       }
20773 +       return 0;
20774 +}
20775 +
20776 +
20777 +int vc_net_add(struct nx_info *nxi, void __user *data)
20778 +{
20779 +       struct vcmd_net_addr_v0 vc_data;
20780 +       int index, ret = 0;
20781 +
20782 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20783 +               return -EFAULT;
20784 +
20785 +       switch (vc_data.type) {
20786 +       case NXA_TYPE_IPV4:
20787 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20788 +                       return -EINVAL;
20789 +
20790 +               index = 0;
20791 +               while (index < vc_data.count) {
20792 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20793 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20794 +                       if (ret)
20795 +                               return ret;
20796 +                       index++;
20797 +               }
20798 +               ret = index;
20799 +               break;
20800 +
20801 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20802 +               nxi->v4_bcast = vc_data.ip[0];
20803 +               ret = 1;
20804 +               break;
20805 +
20806 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20807 +               nxi->v4_lback = vc_data.ip[0];
20808 +               ret = 1;
20809 +               break;
20810 +
20811 +       default:
20812 +               ret = -EINVAL;
20813 +               break;
20814 +       }
20815 +       return ret;
20816 +}
20817 +
20818 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20819 +{
20820 +       struct vcmd_net_addr_v0 vc_data;
20821 +
20822 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20823 +               return -EFAULT;
20824 +
20825 +       switch (vc_data.type) {
20826 +       case NXA_TYPE_ANY:
20827 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20828 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20829 +               break;
20830 +
20831 +       default:
20832 +               return -EINVAL;
20833 +       }
20834 +       return 0;
20835 +}
20836 +
20837 +
20838 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20839 +{
20840 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20841 +
20842 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20843 +               return -EFAULT;
20844 +
20845 +       switch (vc_data.type) {
20846 +       case NXA_TYPE_ADDR:
20847 +       case NXA_TYPE_MASK:
20848 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20849 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20850 +
20851 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20852 +               nxi->v4_bcast = vc_data.ip;
20853 +               break;
20854 +
20855 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20856 +               nxi->v4_lback = vc_data.ip;
20857 +               break;
20858 +
20859 +       default:
20860 +               return -EINVAL;
20861 +       }
20862 +       return 0;
20863 +}
20864 +
20865 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20866 +{
20867 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20868 +
20869 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20870 +               return -EFAULT;
20871 +
20872 +       switch (vc_data.type) {
20873 +       case NXA_TYPE_ADDR:
20874 +       case NXA_TYPE_MASK:
20875 +       case NXA_TYPE_RANGE:
20876 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20877 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20878 +
20879 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20880 +               nxi->v4_bcast = vc_data.ip;
20881 +               break;
20882 +
20883 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20884 +               nxi->v4_lback = vc_data.ip;
20885 +               break;
20886 +
20887 +       default:
20888 +               return -EINVAL;
20889 +       }
20890 +       return 0;
20891 +}
20892 +
20893 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20894 +{
20895 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20896 +
20897 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20898 +               return -EFAULT;
20899 +
20900 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20901 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20902 +}
20903 +
20904 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20905 +{
20906 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20907 +
20908 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20909 +               return -EFAULT;
20910 +
20911 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20912 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20913 +}
20914 +
20915 +#ifdef CONFIG_IPV6
20916 +
20917 +int do_add_v6_addr(struct nx_info *nxi,
20918 +       struct in6_addr *ip, struct in6_addr *mask,
20919 +       uint32_t prefix, uint16_t type, uint16_t flags)
20920 +{
20921 +       struct nx_addr_v6 *nxa = &nxi->v6;
20922 +
20923 +       if (NX_IPV6(nxi)) {
20924 +               /* locate last entry */
20925 +               for (; nxa->next; nxa = nxa->next);
20926 +               nxa->next = __alloc_nx_addr_v6();
20927 +               nxa = nxa->next;
20928 +
20929 +               if (IS_ERR(nxa))
20930 +                       return PTR_ERR(nxa);
20931 +       }
20932 +
20933 +       nxa->ip = *ip;
20934 +       nxa->mask = *mask;
20935 +       nxa->prefix = prefix;
20936 +       nxa->type = type;
20937 +       nxa->flags = flags;
20938 +       return 0;
20939 +}
20940 +
20941 +
20942 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20943 +{
20944 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20945 +
20946 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20947 +               return -EFAULT;
20948 +
20949 +       switch (vc_data.type) {
20950 +       case NXA_TYPE_ADDR:
20951 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20952 +               /* fallthrough */
20953 +       case NXA_TYPE_MASK:
20954 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20955 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20956 +       default:
20957 +               return -EINVAL;
20958 +       }
20959 +       return 0;
20960 +}
20961 +
20962 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20963 +{
20964 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20965 +
20966 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20967 +               return -EFAULT;
20968 +
20969 +       switch (vc_data.type) {
20970 +       case NXA_TYPE_ANY:
20971 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20972 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20973 +               break;
20974 +
20975 +       default:
20976 +               return -EINVAL;
20977 +       }
20978 +       return 0;
20979 +}
20980 +
20981 +#endif /* CONFIG_IPV6 */
20982 +
20983 +
20984 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20985 +{
20986 +       struct vcmd_net_flags_v0 vc_data;
20987 +
20988 +       vc_data.flagword = nxi->nx_flags;
20989 +
20990 +       /* special STATE flag handling */
20991 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20992 +
20993 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20994 +               return -EFAULT;
20995 +       return 0;
20996 +}
20997 +
20998 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20999 +{
21000 +       struct vcmd_net_flags_v0 vc_data;
21001 +       uint64_t mask, trigger;
21002 +
21003 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21004 +               return -EFAULT;
21005 +
21006 +       /* special STATE flag handling */
21007 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21008 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21009 +
21010 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21011 +               vc_data.flagword, mask);
21012 +       if (trigger & NXF_PERSISTENT)
21013 +               nx_update_persistent(nxi);
21014 +
21015 +       return 0;
21016 +}
21017 +
21018 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21019 +{
21020 +       struct vcmd_net_caps_v0 vc_data;
21021 +
21022 +       vc_data.ncaps = nxi->nx_ncaps;
21023 +       vc_data.cmask = ~0ULL;
21024 +
21025 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21026 +               return -EFAULT;
21027 +       return 0;
21028 +}
21029 +
21030 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21031 +{
21032 +       struct vcmd_net_caps_v0 vc_data;
21033 +
21034 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21035 +               return -EFAULT;
21036 +
21037 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21038 +               vc_data.ncaps, vc_data.cmask);
21039 +       return 0;
21040 +}
21041 +
21042 +
21043 +#include <linux/module.h>
21044 +
21045 +module_init(init_network);
21046 +
21047 +EXPORT_SYMBOL_GPL(free_nx_info);
21048 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21049 +
21050 diff -NurpP --minimal linux-3.2.5/kernel/vserver/proc.c linux-3.2.5-vs2.3.2.6/kernel/vserver/proc.c
21051 --- linux-3.2.5/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21052 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/proc.c 2011-12-06 23:19:52.000000000 +0100
21053 @@ -0,0 +1,1103 @@
21054 +/*
21055 + *  linux/kernel/vserver/proc.c
21056 + *
21057 + *  Virtual Context Support
21058 + *
21059 + *  Copyright (C) 2003-2011  Herbert Pötzl
21060 + *
21061 + *  V0.01  basic structure
21062 + *  V0.02  adaptation vs1.3.0
21063 + *  V0.03  proc permissions
21064 + *  V0.04  locking/generic
21065 + *  V0.05  next generation procfs
21066 + *  V0.06  inode validation
21067 + *  V0.07  generic rewrite vid
21068 + *  V0.08  remove inode type
21069 + *  V0.09  added u/wmask info
21070 + *
21071 + */
21072 +
21073 +#include <linux/proc_fs.h>
21074 +#include <linux/fs_struct.h>
21075 +#include <linux/mount.h>
21076 +#include <asm/unistd.h>
21077 +
21078 +#include <linux/vs_context.h>
21079 +#include <linux/vs_network.h>
21080 +#include <linux/vs_cvirt.h>
21081 +
21082 +#include <linux/in.h>
21083 +#include <linux/inetdevice.h>
21084 +#include <linux/vs_inet.h>
21085 +#include <linux/vs_inet6.h>
21086 +
21087 +#include <linux/vserver/global.h>
21088 +
21089 +#include "cvirt_proc.h"
21090 +#include "cacct_proc.h"
21091 +#include "limit_proc.h"
21092 +#include "sched_proc.h"
21093 +#include "vci_config.h"
21094 +
21095 +
21096 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21097 +{
21098 +       unsigned __capi;
21099 +
21100 +       CAP_FOR_EACH_U32(__capi) {
21101 +               buffer += sprintf(buffer, "%08x",
21102 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21103 +       }
21104 +       return buffer;
21105 +}
21106 +
21107 +
21108 +static struct proc_dir_entry *proc_virtual;
21109 +
21110 +static struct proc_dir_entry *proc_virtnet;
21111 +
21112 +
21113 +/* first the actual feeds */
21114 +
21115 +
21116 +static int proc_vci(char *buffer)
21117 +{
21118 +       return sprintf(buffer,
21119 +               "VCIVersion:\t%04x:%04x\n"
21120 +               "VCISyscall:\t%d\n"
21121 +               "VCIKernel:\t%08x\n",
21122 +               VCI_VERSION >> 16,
21123 +               VCI_VERSION & 0xFFFF,
21124 +               __NR_vserver,
21125 +               vci_kernel_config());
21126 +}
21127 +
21128 +static int proc_virtual_info(char *buffer)
21129 +{
21130 +       return proc_vci(buffer);
21131 +}
21132 +
21133 +static int proc_virtual_status(char *buffer)
21134 +{
21135 +       return sprintf(buffer,
21136 +               "#CTotal:\t%d\n"
21137 +               "#CActive:\t%d\n"
21138 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21139 +               "#InitTask:\t%d\t%d %d\n",
21140 +               atomic_read(&vx_global_ctotal),
21141 +               atomic_read(&vx_global_cactive),
21142 +               atomic_read(&vs_global_nsproxy),
21143 +               atomic_read(&vs_global_fs),
21144 +               atomic_read(&vs_global_mnt_ns),
21145 +               atomic_read(&vs_global_uts_ns),
21146 +               atomic_read(&nr_ipc_ns),
21147 +               atomic_read(&vs_global_user_ns),
21148 +               atomic_read(&vs_global_pid_ns),
21149 +               atomic_read(&init_task.usage),
21150 +               atomic_read(&init_task.nsproxy->count),
21151 +               init_task.fs->users);
21152 +}
21153 +
21154 +
21155 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21156 +{
21157 +       int length;
21158 +
21159 +       length = sprintf(buffer,
21160 +               "ID:\t%d\n"
21161 +               "Info:\t%p\n"
21162 +               "Init:\t%d\n"
21163 +               "OOM:\t%lld\n",
21164 +               vxi->vx_id,
21165 +               vxi,
21166 +               vxi->vx_initpid,
21167 +               vxi->vx_badness_bias);
21168 +       return length;
21169 +}
21170 +
21171 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21172 +{
21173 +       char *orig = buffer;
21174 +
21175 +       buffer += sprintf(buffer,
21176 +               "UseCnt:\t%d\n"
21177 +               "Tasks:\t%d\n"
21178 +               "Flags:\t%016llx\n",
21179 +               atomic_read(&vxi->vx_usecnt),
21180 +               atomic_read(&vxi->vx_tasks),
21181 +               (unsigned long long)vxi->vx_flags);
21182 +
21183 +       buffer += sprintf(buffer, "BCaps:\t");
21184 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21185 +       buffer += sprintf(buffer, "\n");
21186 +
21187 +       buffer += sprintf(buffer,
21188 +               "CCaps:\t%016llx\n"
21189 +               "Umask:\t%16llx\n"
21190 +               "Wmask:\t%16llx\n"
21191 +               "Spaces:\t%08lx %08lx\n",
21192 +               (unsigned long long)vxi->vx_ccaps,
21193 +               (unsigned long long)vxi->vx_umask,
21194 +               (unsigned long long)vxi->vx_wmask,
21195 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21196 +       return buffer - orig;
21197 +}
21198 +
21199 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21200 +{
21201 +       return vx_info_proc_limit(&vxi->limit, buffer);
21202 +}
21203 +
21204 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21205 +{
21206 +       int cpu, length;
21207 +
21208 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21209 +       for_each_online_cpu(cpu) {
21210 +               length += vx_info_proc_sched_pc(
21211 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21212 +                       buffer + length, cpu);
21213 +       }
21214 +       return length;
21215 +}
21216 +
21217 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21218 +{
21219 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21220 +}
21221 +
21222 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21223 +{
21224 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21225 +}
21226 +
21227 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21228 +{
21229 +       int cpu, length;
21230 +
21231 +       vx_update_load(vxi);
21232 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21233 +       for_each_online_cpu(cpu) {
21234 +               length += vx_info_proc_cvirt_pc(
21235 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21236 +                       buffer + length, cpu);
21237 +       }
21238 +       return length;
21239 +}
21240 +
21241 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21242 +{
21243 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21244 +}
21245 +
21246 +
21247 +static int proc_virtnet_info(char *buffer)
21248 +{
21249 +       return proc_vci(buffer);
21250 +}
21251 +
21252 +static int proc_virtnet_status(char *buffer)
21253 +{
21254 +       return sprintf(buffer,
21255 +               "#CTotal:\t%d\n"
21256 +               "#CActive:\t%d\n",
21257 +               atomic_read(&nx_global_ctotal),
21258 +               atomic_read(&nx_global_cactive));
21259 +}
21260 +
21261 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21262 +{
21263 +       struct nx_addr_v4 *v4a;
21264 +#ifdef CONFIG_IPV6
21265 +       struct nx_addr_v6 *v6a;
21266 +#endif
21267 +       int length, i;
21268 +
21269 +       length = sprintf(buffer,
21270 +               "ID:\t%d\n"
21271 +               "Info:\t%p\n"
21272 +               "Bcast:\t" NIPQUAD_FMT "\n"
21273 +               "Lback:\t" NIPQUAD_FMT "\n",
21274 +               nxi->nx_id,
21275 +               nxi,
21276 +               NIPQUAD(nxi->v4_bcast.s_addr),
21277 +               NIPQUAD(nxi->v4_lback.s_addr));
21278 +
21279 +       if (!NX_IPV4(nxi))
21280 +               goto skip_v4;
21281 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21282 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21283 +                       i, NXAV4(v4a));
21284 +skip_v4:
21285 +#ifdef CONFIG_IPV6
21286 +       if (!NX_IPV6(nxi))
21287 +               goto skip_v6;
21288 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21289 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21290 +                       i, NXAV6(v6a));
21291 +skip_v6:
21292 +#endif
21293 +       return length;
21294 +}
21295 +
21296 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21297 +{
21298 +       int length;
21299 +
21300 +       length = sprintf(buffer,
21301 +               "UseCnt:\t%d\n"
21302 +               "Tasks:\t%d\n"
21303 +               "Flags:\t%016llx\n"
21304 +               "NCaps:\t%016llx\n",
21305 +               atomic_read(&nxi->nx_usecnt),
21306 +               atomic_read(&nxi->nx_tasks),
21307 +               (unsigned long long)nxi->nx_flags,
21308 +               (unsigned long long)nxi->nx_ncaps);
21309 +       return length;
21310 +}
21311 +
21312 +
21313 +
21314 +/* here the inode helpers */
21315 +
21316 +struct vs_entry {
21317 +       int len;
21318 +       char *name;
21319 +       mode_t mode;
21320 +       struct inode_operations *iop;
21321 +       struct file_operations *fop;
21322 +       union proc_op op;
21323 +};
21324 +
21325 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21326 +{
21327 +       struct inode *inode = new_inode(sb);
21328 +
21329 +       if (!inode)
21330 +               goto out;
21331 +
21332 +       inode->i_mode = p->mode;
21333 +       if (p->iop)
21334 +               inode->i_op = p->iop;
21335 +       if (p->fop)
21336 +               inode->i_fop = p->fop;
21337 +
21338 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21339 +       inode->i_flags |= S_IMMUTABLE;
21340 +
21341 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21342 +
21343 +       inode->i_uid = 0;
21344 +       inode->i_gid = 0;
21345 +       inode->i_tag = 0;
21346 +out:
21347 +       return inode;
21348 +}
21349 +
21350 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21351 +       struct dentry *dentry, int id, void *ptr)
21352 +{
21353 +       struct vs_entry *p = ptr;
21354 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21355 +       struct dentry *error = ERR_PTR(-EINVAL);
21356 +
21357 +       if (!inode)
21358 +               goto out;
21359 +
21360 +       PROC_I(inode)->op = p->op;
21361 +       PROC_I(inode)->fd = id;
21362 +       d_add(dentry, inode);
21363 +       error = NULL;
21364 +out:
21365 +       return error;
21366 +}
21367 +
21368 +/* Lookups */
21369 +
21370 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21371 +
21372 +/*
21373 + * Fill a directory entry.
21374 + *
21375 + * If possible create the dcache entry and derive our inode number and
21376 + * file type from dcache entry.
21377 + *
21378 + * Since all of the proc inode numbers are dynamically generated, the inode
21379 + * numbers do not exist until the inode is cache.  This means creating the
21380 + * the dcache entry in readdir is necessary to keep the inode numbers
21381 + * reported by readdir in sync with the inode numbers reported
21382 + * by stat.
21383 + */
21384 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21385 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21386 +{
21387 +       struct dentry *child, *dir = filp->f_dentry;
21388 +       struct inode *inode;
21389 +       struct qstr qname;
21390 +       ino_t ino = 0;
21391 +       unsigned type = DT_UNKNOWN;
21392 +
21393 +       qname.name = name;
21394 +       qname.len  = len;
21395 +       qname.hash = full_name_hash(name, len);
21396 +
21397 +       child = d_lookup(dir, &qname);
21398 +       if (!child) {
21399 +               struct dentry *new;
21400 +               new = d_alloc(dir, &qname);
21401 +               if (new) {
21402 +                       child = instantiate(dir->d_inode, new, id, ptr);
21403 +                       if (child)
21404 +                               dput(new);
21405 +                       else
21406 +                               child = new;
21407 +               }
21408 +       }
21409 +       if (!child || IS_ERR(child) || !child->d_inode)
21410 +               goto end_instantiate;
21411 +       inode = child->d_inode;
21412 +       if (inode) {
21413 +               ino = inode->i_ino;
21414 +               type = inode->i_mode >> 12;
21415 +       }
21416 +       dput(child);
21417 +end_instantiate:
21418 +       if (!ino)
21419 +               ino = find_inode_number(dir, &qname);
21420 +       if (!ino)
21421 +               ino = 1;
21422 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21423 +}
21424 +
21425 +
21426 +
21427 +/* get and revalidate vx_info/xid */
21428 +
21429 +static inline
21430 +struct vx_info *get_proc_vx_info(struct inode *inode)
21431 +{
21432 +       return lookup_vx_info(PROC_I(inode)->fd);
21433 +}
21434 +
21435 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21436 +{
21437 +       struct inode *inode = dentry->d_inode;
21438 +       xid_t xid = PROC_I(inode)->fd;
21439 +
21440 +       if (!xid || xid_is_hashed(xid))
21441 +               return 1;
21442 +       d_drop(dentry);
21443 +       return 0;
21444 +}
21445 +
21446 +
21447 +/* get and revalidate nx_info/nid */
21448 +
21449 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21450 +{
21451 +       struct inode *inode = dentry->d_inode;
21452 +       nid_t nid = PROC_I(inode)->fd;
21453 +
21454 +       if (!nid || nid_is_hashed(nid))
21455 +               return 1;
21456 +       d_drop(dentry);
21457 +       return 0;
21458 +}
21459 +
21460 +
21461 +
21462 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21463 +
21464 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21465 +                         size_t count, loff_t *ppos)
21466 +{
21467 +       struct inode *inode = file->f_dentry->d_inode;
21468 +       unsigned long page;
21469 +       ssize_t length = 0;
21470 +
21471 +       if (count > PROC_BLOCK_SIZE)
21472 +               count = PROC_BLOCK_SIZE;
21473 +
21474 +       /* fade that out as soon as stable */
21475 +       WARN_ON(PROC_I(inode)->fd);
21476 +
21477 +       if (!(page = __get_free_page(GFP_KERNEL)))
21478 +               return -ENOMEM;
21479 +
21480 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21481 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21482 +
21483 +       if (length >= 0)
21484 +               length = simple_read_from_buffer(buf, count, ppos,
21485 +                       (char *)page, length);
21486 +
21487 +       free_page(page);
21488 +       return length;
21489 +}
21490 +
21491 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21492 +                         size_t count, loff_t *ppos)
21493 +{
21494 +       struct inode *inode = file->f_dentry->d_inode;
21495 +       struct vx_info *vxi = NULL;
21496 +       xid_t xid = PROC_I(inode)->fd;
21497 +       unsigned long page;
21498 +       ssize_t length = 0;
21499 +
21500 +       if (count > PROC_BLOCK_SIZE)
21501 +               count = PROC_BLOCK_SIZE;
21502 +
21503 +       /* fade that out as soon as stable */
21504 +       WARN_ON(!xid);
21505 +       vxi = lookup_vx_info(xid);
21506 +       if (!vxi)
21507 +               goto out;
21508 +
21509 +       length = -ENOMEM;
21510 +       if (!(page = __get_free_page(GFP_KERNEL)))
21511 +               goto out_put;
21512 +
21513 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21514 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21515 +
21516 +       if (length >= 0)
21517 +               length = simple_read_from_buffer(buf, count, ppos,
21518 +                       (char *)page, length);
21519 +
21520 +       free_page(page);
21521 +out_put:
21522 +       put_vx_info(vxi);
21523 +out:
21524 +       return length;
21525 +}
21526 +
21527 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21528 +                         size_t count, loff_t *ppos)
21529 +{
21530 +       struct inode *inode = file->f_dentry->d_inode;
21531 +       struct nx_info *nxi = NULL;
21532 +       nid_t nid = PROC_I(inode)->fd;
21533 +       unsigned long page;
21534 +       ssize_t length = 0;
21535 +
21536 +       if (count > PROC_BLOCK_SIZE)
21537 +               count = PROC_BLOCK_SIZE;
21538 +
21539 +       /* fade that out as soon as stable */
21540 +       WARN_ON(!nid);
21541 +       nxi = lookup_nx_info(nid);
21542 +       if (!nxi)
21543 +               goto out;
21544 +
21545 +       length = -ENOMEM;
21546 +       if (!(page = __get_free_page(GFP_KERNEL)))
21547 +               goto out_put;
21548 +
21549 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21550 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21551 +
21552 +       if (length >= 0)
21553 +               length = simple_read_from_buffer(buf, count, ppos,
21554 +                       (char *)page, length);
21555 +
21556 +       free_page(page);
21557 +out_put:
21558 +       put_nx_info(nxi);
21559 +out:
21560 +       return length;
21561 +}
21562 +
21563 +
21564 +
21565 +/* here comes the lower level */
21566 +
21567 +
21568 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21569 +       .len  = sizeof(NAME) - 1,       \
21570 +       .name = (NAME),                 \
21571 +       .mode = MODE,                   \
21572 +       .iop  = IOP,                    \
21573 +       .fop  = FOP,                    \
21574 +       .op   = OP,                     \
21575 +}
21576 +
21577 +
21578 +#define DIR(NAME, MODE, OTYPE)                         \
21579 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21580 +               &proc_ ## OTYPE ## _inode_operations,   \
21581 +               &proc_ ## OTYPE ## _file_operations, { } )
21582 +
21583 +#define INF(NAME, MODE, OTYPE)                         \
21584 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21585 +               &proc_vs_info_file_operations,          \
21586 +               { .proc_vs_read = &proc_##OTYPE } )
21587 +
21588 +#define VINF(NAME, MODE, OTYPE)                                \
21589 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21590 +               &proc_vx_info_file_operations,          \
21591 +               { .proc_vxi_read = &proc_##OTYPE } )
21592 +
21593 +#define NINF(NAME, MODE, OTYPE)                                \
21594 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21595 +               &proc_nx_info_file_operations,          \
21596 +               { .proc_nxi_read = &proc_##OTYPE } )
21597 +
21598 +
21599 +static struct file_operations proc_vs_info_file_operations = {
21600 +       .read =         proc_vs_info_read,
21601 +};
21602 +
21603 +static struct file_operations proc_vx_info_file_operations = {
21604 +       .read =         proc_vx_info_read,
21605 +};
21606 +
21607 +static struct dentry_operations proc_xid_dentry_operations = {
21608 +       .d_revalidate = proc_xid_revalidate,
21609 +};
21610 +
21611 +static struct vs_entry vx_base_stuff[] = {
21612 +       VINF("info",    S_IRUGO, vxi_info),
21613 +       VINF("status",  S_IRUGO, vxi_status),
21614 +       VINF("limit",   S_IRUGO, vxi_limit),
21615 +       VINF("sched",   S_IRUGO, vxi_sched),
21616 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21617 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21618 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21619 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21620 +       {}
21621 +};
21622 +
21623 +
21624 +
21625 +
21626 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21627 +       struct dentry *dentry, int id, void *ptr)
21628 +{
21629 +       dentry->d_op = &proc_xid_dentry_operations;
21630 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21631 +}
21632 +
21633 +static struct dentry *proc_xid_lookup(struct inode *dir,
21634 +       struct dentry *dentry, struct nameidata *nd)
21635 +{
21636 +       struct vs_entry *p = vx_base_stuff;
21637 +       struct dentry *error = ERR_PTR(-ENOENT);
21638 +
21639 +       for (; p->name; p++) {
21640 +               if (p->len != dentry->d_name.len)
21641 +                       continue;
21642 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21643 +                       break;
21644 +       }
21645 +       if (!p->name)
21646 +               goto out;
21647 +
21648 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21649 +out:
21650 +       return error;
21651 +}
21652 +
21653 +static int proc_xid_readdir(struct file *filp,
21654 +       void *dirent, filldir_t filldir)
21655 +{
21656 +       struct dentry *dentry = filp->f_dentry;
21657 +       struct inode *inode = dentry->d_inode;
21658 +       struct vs_entry *p = vx_base_stuff;
21659 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21660 +       int pos, index;
21661 +       u64 ino;
21662 +
21663 +       pos = filp->f_pos;
21664 +       switch (pos) {
21665 +       case 0:
21666 +               ino = inode->i_ino;
21667 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21668 +                       goto out;
21669 +               pos++;
21670 +               /* fall through */
21671 +       case 1:
21672 +               ino = parent_ino(dentry);
21673 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21674 +                       goto out;
21675 +               pos++;
21676 +               /* fall through */
21677 +       default:
21678 +               index = pos - 2;
21679 +               if (index >= size)
21680 +                       goto out;
21681 +               for (p += index; p->name; p++) {
21682 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21683 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21684 +                               goto out;
21685 +                       pos++;
21686 +               }
21687 +       }
21688 +out:
21689 +       filp->f_pos = pos;
21690 +       return 1;
21691 +}
21692 +
21693 +
21694 +
21695 +static struct file_operations proc_nx_info_file_operations = {
21696 +       .read =         proc_nx_info_read,
21697 +};
21698 +
21699 +static struct dentry_operations proc_nid_dentry_operations = {
21700 +       .d_revalidate = proc_nid_revalidate,
21701 +};
21702 +
21703 +static struct vs_entry nx_base_stuff[] = {
21704 +       NINF("info",    S_IRUGO, nxi_info),
21705 +       NINF("status",  S_IRUGO, nxi_status),
21706 +       {}
21707 +};
21708 +
21709 +
21710 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21711 +       struct dentry *dentry, int id, void *ptr)
21712 +{
21713 +       dentry->d_op = &proc_nid_dentry_operations;
21714 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21715 +}
21716 +
21717 +static struct dentry *proc_nid_lookup(struct inode *dir,
21718 +       struct dentry *dentry, struct nameidata *nd)
21719 +{
21720 +       struct vs_entry *p = nx_base_stuff;
21721 +       struct dentry *error = ERR_PTR(-ENOENT);
21722 +
21723 +       for (; p->name; p++) {
21724 +               if (p->len != dentry->d_name.len)
21725 +                       continue;
21726 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21727 +                       break;
21728 +       }
21729 +       if (!p->name)
21730 +               goto out;
21731 +
21732 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21733 +out:
21734 +       return error;
21735 +}
21736 +
21737 +static int proc_nid_readdir(struct file *filp,
21738 +       void *dirent, filldir_t filldir)
21739 +{
21740 +       struct dentry *dentry = filp->f_dentry;
21741 +       struct inode *inode = dentry->d_inode;
21742 +       struct vs_entry *p = nx_base_stuff;
21743 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21744 +       int pos, index;
21745 +       u64 ino;
21746 +
21747 +       pos = filp->f_pos;
21748 +       switch (pos) {
21749 +       case 0:
21750 +               ino = inode->i_ino;
21751 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21752 +                       goto out;
21753 +               pos++;
21754 +               /* fall through */
21755 +       case 1:
21756 +               ino = parent_ino(dentry);
21757 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21758 +                       goto out;
21759 +               pos++;
21760 +               /* fall through */
21761 +       default:
21762 +               index = pos - 2;
21763 +               if (index >= size)
21764 +                       goto out;
21765 +               for (p += index; p->name; p++) {
21766 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21767 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21768 +                               goto out;
21769 +                       pos++;
21770 +               }
21771 +       }
21772 +out:
21773 +       filp->f_pos = pos;
21774 +       return 1;
21775 +}
21776 +
21777 +
21778 +#define MAX_MULBY10    ((~0U - 9) / 10)
21779 +
21780 +static inline int atovid(const char *str, int len)
21781 +{
21782 +       int vid, c;
21783 +
21784 +       vid = 0;
21785 +       while (len-- > 0) {
21786 +               c = *str - '0';
21787 +               str++;
21788 +               if (c > 9)
21789 +                       return -1;
21790 +               if (vid >= MAX_MULBY10)
21791 +                       return -1;
21792 +               vid *= 10;
21793 +               vid += c;
21794 +               if (!vid)
21795 +                       return -1;
21796 +       }
21797 +       return vid;
21798 +}
21799 +
21800 +/* now the upper level (virtual) */
21801 +
21802 +
21803 +static struct file_operations proc_xid_file_operations = {
21804 +       .read =         generic_read_dir,
21805 +       .readdir =      proc_xid_readdir,
21806 +};
21807 +
21808 +static struct inode_operations proc_xid_inode_operations = {
21809 +       .lookup =       proc_xid_lookup,
21810 +};
21811 +
21812 +static struct vs_entry vx_virtual_stuff[] = {
21813 +       INF("info",     S_IRUGO, virtual_info),
21814 +       INF("status",   S_IRUGO, virtual_status),
21815 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21816 +};
21817 +
21818 +
21819 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21820 +       struct dentry *dentry, struct nameidata *nd)
21821 +{
21822 +       struct vs_entry *p = vx_virtual_stuff;
21823 +       struct dentry *error = ERR_PTR(-ENOENT);
21824 +       int id = 0;
21825 +
21826 +       for (; p->name; p++) {
21827 +               if (p->len != dentry->d_name.len)
21828 +                       continue;
21829 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21830 +                       break;
21831 +       }
21832 +       if (p->name)
21833 +               goto instantiate;
21834 +
21835 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21836 +       if ((id < 0) || !xid_is_hashed(id))
21837 +               goto out;
21838 +
21839 +instantiate:
21840 +       error = proc_xid_instantiate(dir, dentry, id, p);
21841 +out:
21842 +       return error;
21843 +}
21844 +
21845 +static struct file_operations proc_nid_file_operations = {
21846 +       .read =         generic_read_dir,
21847 +       .readdir =      proc_nid_readdir,
21848 +};
21849 +
21850 +static struct inode_operations proc_nid_inode_operations = {
21851 +       .lookup =       proc_nid_lookup,
21852 +};
21853 +
21854 +static struct vs_entry nx_virtnet_stuff[] = {
21855 +       INF("info",     S_IRUGO, virtnet_info),
21856 +       INF("status",   S_IRUGO, virtnet_status),
21857 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21858 +};
21859 +
21860 +
21861 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21862 +       struct dentry *dentry, struct nameidata *nd)
21863 +{
21864 +       struct vs_entry *p = nx_virtnet_stuff;
21865 +       struct dentry *error = ERR_PTR(-ENOENT);
21866 +       int id = 0;
21867 +
21868 +       for (; p->name; p++) {
21869 +               if (p->len != dentry->d_name.len)
21870 +                       continue;
21871 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21872 +                       break;
21873 +       }
21874 +       if (p->name)
21875 +               goto instantiate;
21876 +
21877 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21878 +       if ((id < 0) || !nid_is_hashed(id))
21879 +               goto out;
21880 +
21881 +instantiate:
21882 +       error = proc_nid_instantiate(dir, dentry, id, p);
21883 +out:
21884 +       return error;
21885 +}
21886 +
21887 +
21888 +#define PROC_MAXVIDS 32
21889 +
21890 +int proc_virtual_readdir(struct file *filp,
21891 +       void *dirent, filldir_t filldir)
21892 +{
21893 +       struct dentry *dentry = filp->f_dentry;
21894 +       struct inode *inode = dentry->d_inode;
21895 +       struct vs_entry *p = vx_virtual_stuff;
21896 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21897 +       int pos, index;
21898 +       unsigned int xid_array[PROC_MAXVIDS];
21899 +       char buf[PROC_NUMBUF];
21900 +       unsigned int nr_xids, i;
21901 +       u64 ino;
21902 +
21903 +       pos = filp->f_pos;
21904 +       switch (pos) {
21905 +       case 0:
21906 +               ino = inode->i_ino;
21907 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21908 +                       goto out;
21909 +               pos++;
21910 +               /* fall through */
21911 +       case 1:
21912 +               ino = parent_ino(dentry);
21913 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21914 +                       goto out;
21915 +               pos++;
21916 +               /* fall through */
21917 +       default:
21918 +               index = pos - 2;
21919 +               if (index >= size)
21920 +                       goto entries;
21921 +               for (p += index; p->name; p++) {
21922 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21923 +                               vs_proc_instantiate, 0, p))
21924 +                               goto out;
21925 +                       pos++;
21926 +               }
21927 +       entries:
21928 +               index = pos - size;
21929 +               p = &vx_virtual_stuff[size - 1];
21930 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21931 +               for (i = 0; i < nr_xids; i++) {
21932 +                       int n, xid = xid_array[i];
21933 +                       unsigned int j = PROC_NUMBUF;
21934 +
21935 +                       n = xid;
21936 +                       do
21937 +                               buf[--j] = '0' + (n % 10);
21938 +                       while (n /= 10);
21939 +
21940 +                       if (proc_fill_cache(filp, dirent, filldir,
21941 +                               buf + j, PROC_NUMBUF - j,
21942 +                               vs_proc_instantiate, xid, p))
21943 +                               goto out;
21944 +                       pos++;
21945 +               }
21946 +       }
21947 +out:
21948 +       filp->f_pos = pos;
21949 +       return 0;
21950 +}
21951 +
21952 +static int proc_virtual_getattr(struct vfsmount *mnt,
21953 +       struct dentry *dentry, struct kstat *stat)
21954 +{
21955 +       struct inode *inode = dentry->d_inode;
21956 +
21957 +       generic_fillattr(inode, stat);
21958 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21959 +       return 0;
21960 +}
21961 +
21962 +static struct file_operations proc_virtual_dir_operations = {
21963 +       .read =         generic_read_dir,
21964 +       .readdir =      proc_virtual_readdir,
21965 +};
21966 +
21967 +static struct inode_operations proc_virtual_dir_inode_operations = {
21968 +       .getattr =      proc_virtual_getattr,
21969 +       .lookup =       proc_virtual_lookup,
21970 +};
21971 +
21972 +
21973 +
21974 +
21975 +
21976 +int proc_virtnet_readdir(struct file *filp,
21977 +       void *dirent, filldir_t filldir)
21978 +{
21979 +       struct dentry *dentry = filp->f_dentry;
21980 +       struct inode *inode = dentry->d_inode;
21981 +       struct vs_entry *p = nx_virtnet_stuff;
21982 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21983 +       int pos, index;
21984 +       unsigned int nid_array[PROC_MAXVIDS];
21985 +       char buf[PROC_NUMBUF];
21986 +       unsigned int nr_nids, i;
21987 +       u64 ino;
21988 +
21989 +       pos = filp->f_pos;
21990 +       switch (pos) {
21991 +       case 0:
21992 +               ino = inode->i_ino;
21993 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21994 +                       goto out;
21995 +               pos++;
21996 +               /* fall through */
21997 +       case 1:
21998 +               ino = parent_ino(dentry);
21999 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22000 +                       goto out;
22001 +               pos++;
22002 +               /* fall through */
22003 +       default:
22004 +               index = pos - 2;
22005 +               if (index >= size)
22006 +                       goto entries;
22007 +               for (p += index; p->name; p++) {
22008 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22009 +                               vs_proc_instantiate, 0, p))
22010 +                               goto out;
22011 +                       pos++;
22012 +               }
22013 +       entries:
22014 +               index = pos - size;
22015 +               p = &nx_virtnet_stuff[size - 1];
22016 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22017 +               for (i = 0; i < nr_nids; i++) {
22018 +                       int n, nid = nid_array[i];
22019 +                       unsigned int j = PROC_NUMBUF;
22020 +
22021 +                       n = nid;
22022 +                       do
22023 +                               buf[--j] = '0' + (n % 10);
22024 +                       while (n /= 10);
22025 +
22026 +                       if (proc_fill_cache(filp, dirent, filldir,
22027 +                               buf + j, PROC_NUMBUF - j,
22028 +                               vs_proc_instantiate, nid, p))
22029 +                               goto out;
22030 +                       pos++;
22031 +               }
22032 +       }
22033 +out:
22034 +       filp->f_pos = pos;
22035 +       return 0;
22036 +}
22037 +
22038 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22039 +       struct dentry *dentry, struct kstat *stat)
22040 +{
22041 +       struct inode *inode = dentry->d_inode;
22042 +
22043 +       generic_fillattr(inode, stat);
22044 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22045 +       return 0;
22046 +}
22047 +
22048 +static struct file_operations proc_virtnet_dir_operations = {
22049 +       .read =         generic_read_dir,
22050 +       .readdir =      proc_virtnet_readdir,
22051 +};
22052 +
22053 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22054 +       .getattr =      proc_virtnet_getattr,
22055 +       .lookup =       proc_virtnet_lookup,
22056 +};
22057 +
22058 +
22059 +
22060 +void proc_vx_init(void)
22061 +{
22062 +       struct proc_dir_entry *ent;
22063 +
22064 +       ent = proc_mkdir("virtual", 0);
22065 +       if (ent) {
22066 +               ent->proc_fops = &proc_virtual_dir_operations;
22067 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22068 +       }
22069 +       proc_virtual = ent;
22070 +
22071 +       ent = proc_mkdir("virtnet", 0);
22072 +       if (ent) {
22073 +               ent->proc_fops = &proc_virtnet_dir_operations;
22074 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22075 +       }
22076 +       proc_virtnet = ent;
22077 +}
22078 +
22079 +
22080 +
22081 +
22082 +/* per pid info */
22083 +
22084 +
22085 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22086 +{
22087 +       struct vx_info *vxi;
22088 +       char *orig = buffer;
22089 +
22090 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22091 +
22092 +       vxi = task_get_vx_info(p);
22093 +       if (!vxi)
22094 +               goto out;
22095 +
22096 +       buffer += sprintf(buffer, "BCaps:\t");
22097 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22098 +       buffer += sprintf(buffer, "\n");
22099 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22100 +               (unsigned long long)vxi->vx_ccaps);
22101 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22102 +               (unsigned long long)vxi->vx_flags);
22103 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22104 +
22105 +       put_vx_info(vxi);
22106 +out:
22107 +       return buffer - orig;
22108 +}
22109 +
22110 +
22111 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22112 +{
22113 +       struct nx_info *nxi;
22114 +       struct nx_addr_v4 *v4a;
22115 +#ifdef CONFIG_IPV6
22116 +       struct nx_addr_v6 *v6a;
22117 +#endif
22118 +       char *orig = buffer;
22119 +       int i;
22120 +
22121 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22122 +
22123 +       nxi = task_get_nx_info(p);
22124 +       if (!nxi)
22125 +               goto out;
22126 +
22127 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22128 +               (unsigned long long)nxi->nx_ncaps);
22129 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22130 +               (unsigned long long)nxi->nx_flags);
22131 +
22132 +       buffer += sprintf(buffer,
22133 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22134 +               NIPQUAD(nxi->v4_bcast.s_addr));
22135 +       buffer += sprintf (buffer,
22136 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22137 +               NIPQUAD(nxi->v4_lback.s_addr));
22138 +       if (!NX_IPV4(nxi))
22139 +               goto skip_v4;
22140 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22141 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22142 +                       i, NXAV4(v4a));
22143 +skip_v4:
22144 +#ifdef CONFIG_IPV6
22145 +       if (!NX_IPV6(nxi))
22146 +               goto skip_v6;
22147 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22148 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22149 +                       i, NXAV6(v6a));
22150 +skip_v6:
22151 +#endif
22152 +       put_nx_info(nxi);
22153 +out:
22154 +       return buffer - orig;
22155 +}
22156 +
22157 diff -NurpP --minimal linux-3.2.5/kernel/vserver/sched.c linux-3.2.5-vs2.3.2.6/kernel/vserver/sched.c
22158 --- linux-3.2.5/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22159 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/sched.c        2011-12-05 19:33:02.000000000 +0100
22160 @@ -0,0 +1,82 @@
22161 +/*
22162 + *  linux/kernel/vserver/sched.c
22163 + *
22164 + *  Virtual Server: Scheduler Support
22165 + *
22166 + *  Copyright (C) 2004-2010  Herbert Pötzl
22167 + *
22168 + *  V0.01  adapted Sam Vilains version to 2.6.3
22169 + *  V0.02  removed legacy interface
22170 + *  V0.03  changed vcmds to vxi arg
22171 + *  V0.04  removed older and legacy interfaces
22172 + *  V0.05  removed scheduler code/commands
22173 + *
22174 + */
22175 +
22176 +#include <linux/vs_context.h>
22177 +#include <linux/vs_sched.h>
22178 +#include <linux/vserver/sched_cmd.h>
22179 +
22180 +#include <asm/uaccess.h>
22181 +
22182 +
22183 +void vx_update_sched_param(struct _vx_sched *sched,
22184 +       struct _vx_sched_pc *sched_pc)
22185 +{
22186 +       sched_pc->prio_bias = sched->prio_bias;
22187 +}
22188 +
22189 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22190 +{
22191 +       int cpu;
22192 +
22193 +       if (data->prio_bias > MAX_PRIO_BIAS)
22194 +               data->prio_bias = MAX_PRIO_BIAS;
22195 +       if (data->prio_bias < MIN_PRIO_BIAS)
22196 +               data->prio_bias = MIN_PRIO_BIAS;
22197 +
22198 +       if (data->cpu_id != ~0) {
22199 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22200 +               cpus_and(vxi->sched.update, cpu_online_map,
22201 +                       vxi->sched.update);
22202 +       } else
22203 +               vxi->sched.update = cpu_online_map;
22204 +
22205 +       for_each_cpu_mask(cpu, vxi->sched.update)
22206 +               vx_update_sched_param(&vxi->sched,
22207 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22208 +       return 0;
22209 +}
22210 +
22211 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22212 +{
22213 +       struct vcmd_prio_bias vc_data;
22214 +
22215 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22216 +               return -EFAULT;
22217 +
22218 +       return do_set_prio_bias(vxi, &vc_data);
22219 +}
22220 +
22221 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22222 +{
22223 +       struct vcmd_prio_bias vc_data;
22224 +       struct _vx_sched_pc *pcd;
22225 +       int cpu;
22226 +
22227 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22228 +               return -EFAULT;
22229 +
22230 +       cpu = vc_data.cpu_id;
22231 +
22232 +       if (!cpu_possible(cpu))
22233 +               return -EINVAL;
22234 +
22235 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22236 +       vc_data.prio_bias = pcd->prio_bias;
22237 +
22238 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22239 +               return -EFAULT;
22240 +       return 0;
22241 +}
22242 +
22243 diff -NurpP --minimal linux-3.2.5/kernel/vserver/sched_init.h linux-3.2.5-vs2.3.2.6/kernel/vserver/sched_init.h
22244 --- linux-3.2.5/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22245 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/sched_init.h   2011-12-05 19:33:02.000000000 +0100
22246 @@ -0,0 +1,27 @@
22247 +
22248 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22249 +{
22250 +       /* scheduling; hard code starting values as constants */
22251 +       sched->prio_bias = 0;
22252 +}
22253 +
22254 +static inline
22255 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22256 +{
22257 +       sched_pc->prio_bias = 0;
22258 +
22259 +       sched_pc->user_ticks = 0;
22260 +       sched_pc->sys_ticks = 0;
22261 +       sched_pc->hold_ticks = 0;
22262 +}
22263 +
22264 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22265 +{
22266 +       return;
22267 +}
22268 +
22269 +static inline
22270 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22271 +{
22272 +       return;
22273 +}
22274 diff -NurpP --minimal linux-3.2.5/kernel/vserver/sched_proc.h linux-3.2.5-vs2.3.2.6/kernel/vserver/sched_proc.h
22275 --- linux-3.2.5/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22276 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/sched_proc.h   2011-12-05 19:33:02.000000000 +0100
22277 @@ -0,0 +1,32 @@
22278 +#ifndef _VX_SCHED_PROC_H
22279 +#define _VX_SCHED_PROC_H
22280 +
22281 +
22282 +static inline
22283 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22284 +{
22285 +       int length = 0;
22286 +
22287 +       length += sprintf(buffer,
22288 +               "PrioBias:\t%8d\n",
22289 +               sched->prio_bias);
22290 +       return length;
22291 +}
22292 +
22293 +static inline
22294 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22295 +       char *buffer, int cpu)
22296 +{
22297 +       int length = 0;
22298 +
22299 +       length += sprintf(buffer + length,
22300 +               "cpu %d: %lld %lld %lld", cpu,
22301 +               (unsigned long long)sched_pc->user_ticks,
22302 +               (unsigned long long)sched_pc->sys_ticks,
22303 +               (unsigned long long)sched_pc->hold_ticks);
22304 +       length += sprintf(buffer + length,
22305 +               " %d\n", sched_pc->prio_bias);
22306 +       return length;
22307 +}
22308 +
22309 +#endif /* _VX_SCHED_PROC_H */
22310 diff -NurpP --minimal linux-3.2.5/kernel/vserver/signal.c linux-3.2.5-vs2.3.2.6/kernel/vserver/signal.c
22311 --- linux-3.2.5/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22312 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/signal.c       2011-12-05 19:33:02.000000000 +0100
22313 @@ -0,0 +1,134 @@
22314 +/*
22315 + *  linux/kernel/vserver/signal.c
22316 + *
22317 + *  Virtual Server: Signal Support
22318 + *
22319 + *  Copyright (C) 2003-2007  Herbert Pötzl
22320 + *
22321 + *  V0.01  broken out from vcontext V0.05
22322 + *  V0.02  changed vcmds to vxi arg
22323 + *  V0.03  adjusted siginfo for kill
22324 + *
22325 + */
22326 +
22327 +#include <asm/uaccess.h>
22328 +
22329 +#include <linux/vs_context.h>
22330 +#include <linux/vs_pid.h>
22331 +#include <linux/vserver/signal_cmd.h>
22332 +
22333 +
22334 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22335 +{
22336 +       int retval, count = 0;
22337 +       struct task_struct *p;
22338 +       struct siginfo *sip = SEND_SIG_PRIV;
22339 +
22340 +       retval = -ESRCH;
22341 +       vxdprintk(VXD_CBIT(misc, 4),
22342 +               "vx_info_kill(%p[#%d],%d,%d)*",
22343 +               vxi, vxi->vx_id, pid, sig);
22344 +       read_lock(&tasklist_lock);
22345 +       switch (pid) {
22346 +       case  0:
22347 +       case -1:
22348 +               for_each_process(p) {
22349 +                       int err = 0;
22350 +
22351 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22352 +                               (pid && vxi->vx_initpid == p->pid))
22353 +                               continue;
22354 +
22355 +                       err = group_send_sig_info(sig, sip, p);
22356 +                       ++count;
22357 +                       if (err != -EPERM)
22358 +                               retval = err;
22359 +               }
22360 +               break;
22361 +
22362 +       case 1:
22363 +               if (vxi->vx_initpid) {
22364 +                       pid = vxi->vx_initpid;
22365 +                       /* for now, only SIGINT to private init ... */
22366 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22367 +                               /* ... as long as there are tasks left */
22368 +                               (atomic_read(&vxi->vx_tasks) > 1))
22369 +                               sig = SIGINT;
22370 +               }
22371 +               /* fallthrough */
22372 +       default:
22373 +               rcu_read_lock();
22374 +               p = find_task_by_real_pid(pid);
22375 +               rcu_read_unlock();
22376 +               if (p) {
22377 +                       if (vx_task_xid(p) == vxi->vx_id)
22378 +                               retval = group_send_sig_info(sig, sip, p);
22379 +               }
22380 +               break;
22381 +       }
22382 +       read_unlock(&tasklist_lock);
22383 +       vxdprintk(VXD_CBIT(misc, 4),
22384 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22385 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22386 +       return retval;
22387 +}
22388 +
22389 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22390 +{
22391 +       struct vcmd_ctx_kill_v0 vc_data;
22392 +
22393 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22394 +               return -EFAULT;
22395 +
22396 +       /* special check to allow guest shutdown */
22397 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22398 +               /* forbid killall pid=0 when init is present */
22399 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22400 +               (vc_data.pid > 1)))
22401 +               return -EACCES;
22402 +
22403 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22404 +}
22405 +
22406 +
22407 +static int __wait_exit(struct vx_info *vxi)
22408 +{
22409 +       DECLARE_WAITQUEUE(wait, current);
22410 +       int ret = 0;
22411 +
22412 +       add_wait_queue(&vxi->vx_wait, &wait);
22413 +       set_current_state(TASK_INTERRUPTIBLE);
22414 +
22415 +wait:
22416 +       if (vx_info_state(vxi,
22417 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22418 +               goto out;
22419 +       if (signal_pending(current)) {
22420 +               ret = -ERESTARTSYS;
22421 +               goto out;
22422 +       }
22423 +       schedule();
22424 +       goto wait;
22425 +
22426 +out:
22427 +       set_current_state(TASK_RUNNING);
22428 +       remove_wait_queue(&vxi->vx_wait, &wait);
22429 +       return ret;
22430 +}
22431 +
22432 +
22433 +
22434 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22435 +{
22436 +       struct vcmd_wait_exit_v0 vc_data;
22437 +       int ret;
22438 +
22439 +       ret = __wait_exit(vxi);
22440 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22441 +       vc_data.exit_code = vxi->exit_code;
22442 +
22443 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22444 +               ret = -EFAULT;
22445 +       return ret;
22446 +}
22447 +
22448 diff -NurpP --minimal linux-3.2.5/kernel/vserver/space.c linux-3.2.5-vs2.3.2.6/kernel/vserver/space.c
22449 --- linux-3.2.5/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22450 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/space.c        2011-12-05 19:33:02.000000000 +0100
22451 @@ -0,0 +1,435 @@
22452 +/*
22453 + *  linux/kernel/vserver/space.c
22454 + *
22455 + *  Virtual Server: Context Space Support
22456 + *
22457 + *  Copyright (C) 2003-2010  Herbert Pötzl
22458 + *
22459 + *  V0.01  broken out from context.c 0.07
22460 + *  V0.02  added task locking for namespace
22461 + *  V0.03  broken out vx_enter_namespace
22462 + *  V0.04  added *space support and commands
22463 + *  V0.05  added credential support
22464 + *
22465 + */
22466 +
22467 +#include <linux/utsname.h>
22468 +#include <linux/nsproxy.h>
22469 +#include <linux/err.h>
22470 +#include <linux/fs_struct.h>
22471 +#include <linux/cred.h>
22472 +#include <asm/uaccess.h>
22473 +
22474 +#include <linux/vs_context.h>
22475 +#include <linux/vserver/space.h>
22476 +#include <linux/vserver/space_cmd.h>
22477 +
22478 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22479 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22480 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22481 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22482 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22483 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22484 +
22485 +
22486 +/* namespace functions */
22487 +
22488 +#include <linux/mnt_namespace.h>
22489 +#include <linux/user_namespace.h>
22490 +#include <linux/pid_namespace.h>
22491 +#include <linux/ipc_namespace.h>
22492 +#include <net/net_namespace.h>
22493 +
22494 +
22495 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22496 +       .mask = CLONE_FS |
22497 +               CLONE_NEWNS |
22498 +#ifdef CONFIG_UTS_NS
22499 +               CLONE_NEWUTS |
22500 +#endif
22501 +#ifdef CONFIG_IPC_NS
22502 +               CLONE_NEWIPC |
22503 +#endif
22504 +#ifdef CONFIG_USER_NS
22505 +               CLONE_NEWUSER |
22506 +#endif
22507 +               0
22508 +};
22509 +
22510 +static const struct vcmd_space_mask_v1 space_mask = {
22511 +       .mask = CLONE_FS |
22512 +               CLONE_NEWNS |
22513 +#ifdef CONFIG_UTS_NS
22514 +               CLONE_NEWUTS |
22515 +#endif
22516 +#ifdef CONFIG_IPC_NS
22517 +               CLONE_NEWIPC |
22518 +#endif
22519 +#ifdef CONFIG_USER_NS
22520 +               CLONE_NEWUSER |
22521 +#endif
22522 +#ifdef CONFIG_PID_NS
22523 +               CLONE_NEWPID |
22524 +#endif
22525 +#ifdef CONFIG_NET_NS
22526 +               CLONE_NEWNET |
22527 +#endif
22528 +               0
22529 +};
22530 +
22531 +static const struct vcmd_space_mask_v1 default_space_mask = {
22532 +       .mask = CLONE_FS |
22533 +               CLONE_NEWNS |
22534 +#ifdef CONFIG_UTS_NS
22535 +               CLONE_NEWUTS |
22536 +#endif
22537 +#ifdef CONFIG_IPC_NS
22538 +               CLONE_NEWIPC |
22539 +#endif
22540 +#ifdef CONFIG_USER_NS
22541 +               CLONE_NEWUSER |
22542 +#endif
22543 +#ifdef CONFIG_PID_NS
22544 +//             CLONE_NEWPID |
22545 +#endif
22546 +               0
22547 +};
22548 +
22549 +/*
22550 + *     build a new nsproxy mix
22551 + *      assumes that both proxies are 'const'
22552 + *     does not touch nsproxy refcounts
22553 + *     will hold a reference on the result.
22554 + */
22555 +
22556 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22557 +       struct nsproxy *new_nsproxy, unsigned long mask)
22558 +{
22559 +       struct mnt_namespace *old_ns;
22560 +       struct uts_namespace *old_uts;
22561 +       struct ipc_namespace *old_ipc;
22562 +#ifdef CONFIG_PID_NS
22563 +       struct pid_namespace *old_pid;
22564 +#endif
22565 +#ifdef CONFIG_NET_NS
22566 +       struct net *old_net;
22567 +#endif
22568 +       struct nsproxy *nsproxy;
22569 +
22570 +       nsproxy = copy_nsproxy(old_nsproxy);
22571 +       if (!nsproxy)
22572 +               goto out;
22573 +
22574 +       if (mask & CLONE_NEWNS) {
22575 +               old_ns = nsproxy->mnt_ns;
22576 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22577 +               if (nsproxy->mnt_ns)
22578 +                       get_mnt_ns(nsproxy->mnt_ns);
22579 +       } else
22580 +               old_ns = NULL;
22581 +
22582 +       if (mask & CLONE_NEWUTS) {
22583 +               old_uts = nsproxy->uts_ns;
22584 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22585 +               if (nsproxy->uts_ns)
22586 +                       get_uts_ns(nsproxy->uts_ns);
22587 +       } else
22588 +               old_uts = NULL;
22589 +
22590 +       if (mask & CLONE_NEWIPC) {
22591 +               old_ipc = nsproxy->ipc_ns;
22592 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22593 +               if (nsproxy->ipc_ns)
22594 +                       get_ipc_ns(nsproxy->ipc_ns);
22595 +       } else
22596 +               old_ipc = NULL;
22597 +
22598 +#ifdef CONFIG_PID_NS
22599 +       if (mask & CLONE_NEWPID) {
22600 +               old_pid = nsproxy->pid_ns;
22601 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22602 +               if (nsproxy->pid_ns)
22603 +                       get_pid_ns(nsproxy->pid_ns);
22604 +       } else
22605 +               old_pid = NULL;
22606 +#endif
22607 +#ifdef CONFIG_NET_NS
22608 +       if (mask & CLONE_NEWNET) {
22609 +               old_net = nsproxy->net_ns;
22610 +               nsproxy->net_ns = new_nsproxy->net_ns;
22611 +               if (nsproxy->net_ns)
22612 +                       get_net(nsproxy->net_ns);
22613 +       } else
22614 +               old_net = NULL;
22615 +#endif
22616 +       if (old_ns)
22617 +               put_mnt_ns(old_ns);
22618 +       if (old_uts)
22619 +               put_uts_ns(old_uts);
22620 +       if (old_ipc)
22621 +               put_ipc_ns(old_ipc);
22622 +#ifdef CONFIG_PID_NS
22623 +       if (old_pid)
22624 +               put_pid_ns(old_pid);
22625 +#endif
22626 +#ifdef CONFIG_NET_NS
22627 +       if (old_net)
22628 +               put_net(old_net);
22629 +#endif
22630 +out:
22631 +       return nsproxy;
22632 +}
22633 +
22634 +
22635 +/*
22636 + *     merge two nsproxy structs into a new one.
22637 + *     will hold a reference on the result.
22638 + */
22639 +
22640 +static inline
22641 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22642 +       struct nsproxy *proxy, unsigned long mask)
22643 +{
22644 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22645 +
22646 +       if (!proxy)
22647 +               return NULL;
22648 +
22649 +       if (mask) {
22650 +               /* vs_mix_nsproxy returns with reference */
22651 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22652 +                       proxy, mask);
22653 +       }
22654 +       get_nsproxy(proxy);
22655 +       return proxy;
22656 +}
22657 +
22658 +
22659 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22660 +{
22661 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22662 +       struct fs_struct *fs_cur, *fs = NULL;
22663 +       struct _vx_space *space;
22664 +       int ret, kill = 0;
22665 +
22666 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22667 +               vxi, vxi->vx_id, mask, index);
22668 +
22669 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22670 +               return -EACCES;
22671 +
22672 +       if (index >= VX_SPACES)
22673 +               return -EINVAL;
22674 +
22675 +       space = &vxi->space[index];
22676 +
22677 +       if (!mask)
22678 +               mask = space->vx_nsmask;
22679 +
22680 +       if ((mask & space->vx_nsmask) != mask)
22681 +               return -EINVAL;
22682 +
22683 +       if (mask & CLONE_FS) {
22684 +               fs = copy_fs_struct(space->vx_fs);
22685 +               if (!fs)
22686 +                       return -ENOMEM;
22687 +       }
22688 +       proxy = space->vx_nsproxy;
22689 +
22690 +       vxdprintk(VXD_CBIT(space, 9),
22691 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22692 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22693 +
22694 +       task_lock(current);
22695 +       fs_cur = current->fs;
22696 +
22697 +       if (mask & CLONE_FS) {
22698 +               spin_lock(&fs_cur->lock);
22699 +               current->fs = fs;
22700 +               kill = !--fs_cur->users;
22701 +               spin_unlock(&fs_cur->lock);
22702 +       }
22703 +
22704 +       proxy_cur = current->nsproxy;
22705 +       get_nsproxy(proxy_cur);
22706 +       task_unlock(current);
22707 +
22708 +       if (kill)
22709 +               free_fs_struct(fs_cur);
22710 +
22711 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22712 +       if (IS_ERR(proxy_new)) {
22713 +               ret = PTR_ERR(proxy_new);
22714 +               goto out_put;
22715 +       }
22716 +
22717 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22718 +
22719 +       if (mask & CLONE_NEWUSER) {
22720 +               struct cred *cred;
22721 +
22722 +               vxdprintk(VXD_CBIT(space, 10),
22723 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22724 +                       vxi, vxi->vx_id, space->vx_cred,
22725 +                       current->real_cred, current->cred);
22726 +
22727 +               if (space->vx_cred) {
22728 +                       cred = __prepare_creds(space->vx_cred);
22729 +                       if (cred)
22730 +                               commit_creds(cred);
22731 +               }
22732 +       }
22733 +
22734 +       ret = 0;
22735 +
22736 +       if (proxy_new)
22737 +               put_nsproxy(proxy_new);
22738 +out_put:
22739 +       if (proxy_cur)
22740 +               put_nsproxy(proxy_cur);
22741 +       return ret;
22742 +}
22743 +
22744 +
22745 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22746 +{
22747 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22748 +       struct fs_struct *fs_vxi, *fs;
22749 +       struct _vx_space *space;
22750 +       int ret, kill = 0;
22751 +
22752 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22753 +               vxi, vxi->vx_id, mask, index);
22754 +
22755 +       if ((mask & space_mask.mask) != mask)
22756 +               return -EINVAL;
22757 +
22758 +       if (index >= VX_SPACES)
22759 +               return -EINVAL;
22760 +
22761 +       space = &vxi->space[index];
22762 +
22763 +       proxy_vxi = space->vx_nsproxy;
22764 +       fs_vxi = space->vx_fs;
22765 +
22766 +       if (mask & CLONE_FS) {
22767 +               fs = copy_fs_struct(current->fs);
22768 +               if (!fs)
22769 +                       return -ENOMEM;
22770 +       }
22771 +
22772 +       task_lock(current);
22773 +
22774 +       if (mask & CLONE_FS) {
22775 +               spin_lock(&fs_vxi->lock);
22776 +               space->vx_fs = fs;
22777 +               kill = !--fs_vxi->users;
22778 +               spin_unlock(&fs_vxi->lock);
22779 +       }
22780 +
22781 +       proxy_cur = current->nsproxy;
22782 +       get_nsproxy(proxy_cur);
22783 +       task_unlock(current);
22784 +
22785 +       if (kill)
22786 +               free_fs_struct(fs_vxi);
22787 +
22788 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22789 +       if (IS_ERR(proxy_new)) {
22790 +               ret = PTR_ERR(proxy_new);
22791 +               goto out_put;
22792 +       }
22793 +
22794 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22795 +       space->vx_nsmask |= mask;
22796 +
22797 +       if (mask & CLONE_NEWUSER) {
22798 +               struct cred *cred;
22799 +
22800 +               vxdprintk(VXD_CBIT(space, 10),
22801 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22802 +                       vxi, vxi->vx_id, space->vx_cred,
22803 +                       current->real_cred, current->cred);
22804 +
22805 +               cred = prepare_creds();
22806 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22807 +               if (cred)
22808 +                       abort_creds(cred);
22809 +       }
22810 +
22811 +       ret = 0;
22812 +
22813 +       if (proxy_new)
22814 +               put_nsproxy(proxy_new);
22815 +out_put:
22816 +       if (proxy_cur)
22817 +               put_nsproxy(proxy_cur);
22818 +       return ret;
22819 +}
22820 +
22821 +
22822 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22823 +{
22824 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22825 +
22826 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22827 +               return -EFAULT;
22828 +
22829 +       return vx_enter_space(vxi, vc_data.mask, 0);
22830 +}
22831 +
22832 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22833 +{
22834 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22835 +
22836 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22837 +               return -EFAULT;
22838 +
22839 +       if (vc_data.index >= VX_SPACES)
22840 +               return -EINVAL;
22841 +
22842 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22843 +}
22844 +
22845 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22846 +{
22847 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22848 +
22849 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22850 +               return -EFAULT;
22851 +
22852 +       return vx_set_space(vxi, vc_data.mask, 0);
22853 +}
22854 +
22855 +int vc_set_space(struct vx_info *vxi, void __user *data)
22856 +{
22857 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22858 +
22859 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22860 +               return -EFAULT;
22861 +
22862 +       if (vc_data.index >= VX_SPACES)
22863 +               return -EINVAL;
22864 +
22865 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22866 +}
22867 +
22868 +int vc_get_space_mask(void __user *data, int type)
22869 +{
22870 +       const struct vcmd_space_mask_v1 *mask;
22871 +
22872 +       if (type == 0)
22873 +               mask = &space_mask_v0;
22874 +       else if (type == 1)
22875 +               mask = &space_mask;
22876 +       else
22877 +               mask = &default_space_mask;
22878 +
22879 +       vxdprintk(VXD_CBIT(space, 10),
22880 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22881 +
22882 +       if (copy_to_user(data, mask, sizeof(*mask)))
22883 +               return -EFAULT;
22884 +       return 0;
22885 +}
22886 +
22887 diff -NurpP --minimal linux-3.2.5/kernel/vserver/switch.c linux-3.2.5-vs2.3.2.6/kernel/vserver/switch.c
22888 --- linux-3.2.5/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22889 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/switch.c       2011-12-05 19:33:02.000000000 +0100
22890 @@ -0,0 +1,556 @@
22891 +/*
22892 + *  linux/kernel/vserver/switch.c
22893 + *
22894 + *  Virtual Server: Syscall Switch
22895 + *
22896 + *  Copyright (C) 2003-2011  Herbert Pötzl
22897 + *
22898 + *  V0.01  syscall switch
22899 + *  V0.02  added signal to context
22900 + *  V0.03  added rlimit functions
22901 + *  V0.04  added iattr, task/xid functions
22902 + *  V0.05  added debug/history stuff
22903 + *  V0.06  added compat32 layer
22904 + *  V0.07  vcmd args and perms
22905 + *  V0.08  added status commands
22906 + *  V0.09  added tag commands
22907 + *  V0.10  added oom bias
22908 + *  V0.11  added device commands
22909 + *  V0.12  added warn mask
22910 + *
22911 + */
22912 +
22913 +#include <linux/vs_context.h>
22914 +#include <linux/vs_network.h>
22915 +#include <linux/vserver/switch.h>
22916 +
22917 +#include "vci_config.h"
22918 +
22919 +
22920 +static inline
22921 +int vc_get_version(uint32_t id)
22922 +{
22923 +       return VCI_VERSION;
22924 +}
22925 +
22926 +static inline
22927 +int vc_get_vci(uint32_t id)
22928 +{
22929 +       return vci_kernel_config();
22930 +}
22931 +
22932 +#include <linux/vserver/context_cmd.h>
22933 +#include <linux/vserver/cvirt_cmd.h>
22934 +#include <linux/vserver/cacct_cmd.h>
22935 +#include <linux/vserver/limit_cmd.h>
22936 +#include <linux/vserver/network_cmd.h>
22937 +#include <linux/vserver/sched_cmd.h>
22938 +#include <linux/vserver/debug_cmd.h>
22939 +#include <linux/vserver/inode_cmd.h>
22940 +#include <linux/vserver/dlimit_cmd.h>
22941 +#include <linux/vserver/signal_cmd.h>
22942 +#include <linux/vserver/space_cmd.h>
22943 +#include <linux/vserver/tag_cmd.h>
22944 +#include <linux/vserver/device_cmd.h>
22945 +
22946 +#include <linux/vserver/inode.h>
22947 +#include <linux/vserver/dlimit.h>
22948 +
22949 +
22950 +#ifdef CONFIG_COMPAT
22951 +#define __COMPAT(name, id, data, compat)       \
22952 +       (compat) ? name ## _x32(id, data) : name(id, data)
22953 +#define __COMPAT_NO_ID(name, data, compat)     \
22954 +       (compat) ? name ## _x32(data) : name(data)
22955 +#else
22956 +#define __COMPAT(name, id, data, compat)       \
22957 +       name(id, data)
22958 +#define __COMPAT_NO_ID(name, data, compat)     \
22959 +       name(data)
22960 +#endif
22961 +
22962 +
22963 +static inline
22964 +long do_vcmd(uint32_t cmd, uint32_t id,
22965 +       struct vx_info *vxi, struct nx_info *nxi,
22966 +       void __user *data, int compat)
22967 +{
22968 +       switch (cmd) {
22969 +
22970 +       case VCMD_get_version:
22971 +               return vc_get_version(id);
22972 +       case VCMD_get_vci:
22973 +               return vc_get_vci(id);
22974 +
22975 +       case VCMD_task_xid:
22976 +               return vc_task_xid(id);
22977 +       case VCMD_vx_info:
22978 +               return vc_vx_info(vxi, data);
22979 +
22980 +       case VCMD_task_nid:
22981 +               return vc_task_nid(id);
22982 +       case VCMD_nx_info:
22983 +               return vc_nx_info(nxi, data);
22984 +
22985 +       case VCMD_task_tag:
22986 +               return vc_task_tag(id);
22987 +
22988 +       case VCMD_set_space_v1:
22989 +               return vc_set_space_v1(vxi, data);
22990 +       /* this is version 2 */
22991 +       case VCMD_set_space:
22992 +               return vc_set_space(vxi, data);
22993 +
22994 +       case VCMD_get_space_mask_v0:
22995 +               return vc_get_space_mask(data, 0);
22996 +       /* this is version 1 */
22997 +       case VCMD_get_space_mask:
22998 +               return vc_get_space_mask(data, 1);
22999 +
23000 +       case VCMD_get_space_default:
23001 +               return vc_get_space_mask(data, -1);
23002 +
23003 +       case VCMD_set_umask:
23004 +               return vc_set_umask(vxi, data);
23005 +
23006 +       case VCMD_get_umask:
23007 +               return vc_get_umask(vxi, data);
23008 +
23009 +       case VCMD_set_wmask:
23010 +               return vc_set_wmask(vxi, data);
23011 +
23012 +       case VCMD_get_wmask:
23013 +               return vc_get_wmask(vxi, data);
23014 +#ifdef CONFIG_IA32_EMULATION
23015 +       case VCMD_get_rlimit:
23016 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23017 +       case VCMD_set_rlimit:
23018 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23019 +#else
23020 +       case VCMD_get_rlimit:
23021 +               return vc_get_rlimit(vxi, data);
23022 +       case VCMD_set_rlimit:
23023 +               return vc_set_rlimit(vxi, data);
23024 +#endif
23025 +       case VCMD_get_rlimit_mask:
23026 +               return vc_get_rlimit_mask(id, data);
23027 +       case VCMD_reset_hits:
23028 +               return vc_reset_hits(vxi, data);
23029 +       case VCMD_reset_minmax:
23030 +               return vc_reset_minmax(vxi, data);
23031 +
23032 +       case VCMD_get_vhi_name:
23033 +               return vc_get_vhi_name(vxi, data);
23034 +       case VCMD_set_vhi_name:
23035 +               return vc_set_vhi_name(vxi, data);
23036 +
23037 +       case VCMD_ctx_stat:
23038 +               return vc_ctx_stat(vxi, data);
23039 +       case VCMD_virt_stat:
23040 +               return vc_virt_stat(vxi, data);
23041 +       case VCMD_sock_stat:
23042 +               return vc_sock_stat(vxi, data);
23043 +       case VCMD_rlimit_stat:
23044 +               return vc_rlimit_stat(vxi, data);
23045 +
23046 +       case VCMD_set_cflags:
23047 +               return vc_set_cflags(vxi, data);
23048 +       case VCMD_get_cflags:
23049 +               return vc_get_cflags(vxi, data);
23050 +
23051 +       /* this is version 1 */
23052 +       case VCMD_set_ccaps:
23053 +               return vc_set_ccaps(vxi, data);
23054 +       /* this is version 1 */
23055 +       case VCMD_get_ccaps:
23056 +               return vc_get_ccaps(vxi, data);
23057 +       case VCMD_set_bcaps:
23058 +               return vc_set_bcaps(vxi, data);
23059 +       case VCMD_get_bcaps:
23060 +               return vc_get_bcaps(vxi, data);
23061 +
23062 +       case VCMD_set_badness:
23063 +               return vc_set_badness(vxi, data);
23064 +       case VCMD_get_badness:
23065 +               return vc_get_badness(vxi, data);
23066 +
23067 +       case VCMD_set_nflags:
23068 +               return vc_set_nflags(nxi, data);
23069 +       case VCMD_get_nflags:
23070 +               return vc_get_nflags(nxi, data);
23071 +
23072 +       case VCMD_set_ncaps:
23073 +               return vc_set_ncaps(nxi, data);
23074 +       case VCMD_get_ncaps:
23075 +               return vc_get_ncaps(nxi, data);
23076 +
23077 +       case VCMD_set_prio_bias:
23078 +               return vc_set_prio_bias(vxi, data);
23079 +       case VCMD_get_prio_bias:
23080 +               return vc_get_prio_bias(vxi, data);
23081 +       case VCMD_add_dlimit:
23082 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23083 +       case VCMD_rem_dlimit:
23084 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23085 +       case VCMD_set_dlimit:
23086 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23087 +       case VCMD_get_dlimit:
23088 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23089 +
23090 +       case VCMD_ctx_kill:
23091 +               return vc_ctx_kill(vxi, data);
23092 +
23093 +       case VCMD_wait_exit:
23094 +               return vc_wait_exit(vxi, data);
23095 +
23096 +       case VCMD_get_iattr:
23097 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23098 +       case VCMD_set_iattr:
23099 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23100 +
23101 +       case VCMD_fget_iattr:
23102 +               return vc_fget_iattr(id, data);
23103 +       case VCMD_fset_iattr:
23104 +               return vc_fset_iattr(id, data);
23105 +
23106 +       case VCMD_enter_space_v0:
23107 +               return vc_enter_space_v1(vxi, NULL);
23108 +       case VCMD_enter_space_v1:
23109 +               return vc_enter_space_v1(vxi, data);
23110 +       /* this is version 2 */
23111 +       case VCMD_enter_space:
23112 +               return vc_enter_space(vxi, data);
23113 +
23114 +       case VCMD_ctx_create_v0:
23115 +               return vc_ctx_create(id, NULL);
23116 +       case VCMD_ctx_create:
23117 +               return vc_ctx_create(id, data);
23118 +       case VCMD_ctx_migrate_v0:
23119 +               return vc_ctx_migrate(vxi, NULL);
23120 +       case VCMD_ctx_migrate:
23121 +               return vc_ctx_migrate(vxi, data);
23122 +
23123 +       case VCMD_net_create_v0:
23124 +               return vc_net_create(id, NULL);
23125 +       case VCMD_net_create:
23126 +               return vc_net_create(id, data);
23127 +       case VCMD_net_migrate:
23128 +               return vc_net_migrate(nxi, data);
23129 +
23130 +       case VCMD_tag_migrate:
23131 +               return vc_tag_migrate(id);
23132 +
23133 +       case VCMD_net_add:
23134 +               return vc_net_add(nxi, data);
23135 +       case VCMD_net_remove:
23136 +               return vc_net_remove(nxi, data);
23137 +
23138 +       case VCMD_net_add_ipv4_v1:
23139 +               return vc_net_add_ipv4_v1(nxi, data);
23140 +       /* this is version 2 */
23141 +       case VCMD_net_add_ipv4:
23142 +               return vc_net_add_ipv4(nxi, data);
23143 +
23144 +       case VCMD_net_rem_ipv4_v1:
23145 +               return vc_net_rem_ipv4_v1(nxi, data);
23146 +       /* this is version 2 */
23147 +       case VCMD_net_rem_ipv4:
23148 +               return vc_net_rem_ipv4(nxi, data);
23149 +#ifdef CONFIG_IPV6
23150 +       case VCMD_net_add_ipv6:
23151 +               return vc_net_add_ipv6(nxi, data);
23152 +       case VCMD_net_remove_ipv6:
23153 +               return vc_net_remove_ipv6(nxi, data);
23154 +#endif
23155 +/*     case VCMD_add_match_ipv4:
23156 +               return vc_add_match_ipv4(nxi, data);
23157 +       case VCMD_get_match_ipv4:
23158 +               return vc_get_match_ipv4(nxi, data);
23159 +#ifdef CONFIG_IPV6
23160 +       case VCMD_add_match_ipv6:
23161 +               return vc_add_match_ipv6(nxi, data);
23162 +       case VCMD_get_match_ipv6:
23163 +               return vc_get_match_ipv6(nxi, data);
23164 +#endif */
23165 +
23166 +#ifdef CONFIG_VSERVER_DEVICE
23167 +       case VCMD_set_mapping:
23168 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23169 +       case VCMD_unset_mapping:
23170 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23171 +#endif
23172 +#ifdef CONFIG_VSERVER_HISTORY
23173 +       case VCMD_dump_history:
23174 +               return vc_dump_history(id);
23175 +       case VCMD_read_history:
23176 +               return __COMPAT(vc_read_history, id, data, compat);
23177 +#endif
23178 +       default:
23179 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23180 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23181 +       }
23182 +       return -ENOSYS;
23183 +}
23184 +
23185 +
23186 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23187 +       case VCMD_ ## vcmd: perm = _perm;               \
23188 +               args = _args; flags = _flags; break
23189 +
23190 +
23191 +#define VCA_NONE       0x00
23192 +#define VCA_VXI                0x01
23193 +#define VCA_NXI                0x02
23194 +
23195 +#define VCF_NONE       0x00
23196 +#define VCF_INFO       0x01
23197 +#define VCF_ADMIN      0x02
23198 +#define VCF_ARES       0x06    /* includes admin */
23199 +#define VCF_SETUP      0x08
23200 +
23201 +#define VCF_ZIDOK      0x10    /* zero id okay */
23202 +
23203 +
23204 +static inline
23205 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23206 +{
23207 +       long ret;
23208 +       int permit = -1, state = 0;
23209 +       int perm = -1, args = 0, flags = 0;
23210 +       struct vx_info *vxi = NULL;
23211 +       struct nx_info *nxi = NULL;
23212 +
23213 +       switch (cmd) {
23214 +       /* unpriviledged commands */
23215 +       __VCMD(get_version,      0, VCA_NONE,   0);
23216 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23217 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23218 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23219 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23220 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23221 +
23222 +       /* info commands */
23223 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23224 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23225 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23226 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23227 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23228 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23229 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23230 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23231 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23232 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23233 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23234 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23235 +
23236 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23237 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23238 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23239 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23240 +
23241 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23242 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23243 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23244 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23245 +
23246 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23247 +
23248 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23249 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23250 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23251 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23252 +
23253 +       /* lower admin commands */
23254 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23255 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23256 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23257 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23258 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23259 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23260 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23261 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23262 +
23263 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23264 +       __VCMD(net_create,       5, VCA_NONE,   0);
23265 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23266 +
23267 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23268 +
23269 +       /* higher admin commands */
23270 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23271 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23272 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23273 +
23274 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23275 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23276 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23277 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23278 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23279 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23280 +
23281 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23282 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23283 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23284 +
23285 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23286 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23287 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23288 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23289 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23290 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23291 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23292 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23293 +#ifdef CONFIG_IPV6
23294 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23295 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23296 +#endif
23297 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23298 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23299 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23300 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23301 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23302 +
23303 +#ifdef CONFIG_VSERVER_DEVICE
23304 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23305 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23306 +#endif
23307 +       /* debug level admin commands */
23308 +#ifdef CONFIG_VSERVER_HISTORY
23309 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23310 +       __VCMD(read_history,     9, VCA_NONE,   0);
23311 +#endif
23312 +
23313 +       default:
23314 +               perm = -1;
23315 +       }
23316 +
23317 +       vxdprintk(VXD_CBIT(switch, 0),
23318 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23319 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23320 +               VC_VERSION(cmd), id, data, compat,
23321 +               perm, args, flags);
23322 +
23323 +       ret = -ENOSYS;
23324 +       if (perm < 0)
23325 +               goto out;
23326 +
23327 +       state = 1;
23328 +       if (!capable(CAP_CONTEXT))
23329 +               goto out;
23330 +
23331 +       state = 2;
23332 +       /* moved here from the individual commands */
23333 +       ret = -EPERM;
23334 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23335 +               goto out;
23336 +
23337 +       state = 3;
23338 +       /* vcmd involves resource management  */
23339 +       ret = -EPERM;
23340 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23341 +               goto out;
23342 +
23343 +       state = 4;
23344 +       /* various legacy exceptions */
23345 +       switch (cmd) {
23346 +       /* will go away when spectator is a cap */
23347 +       case VCMD_ctx_migrate_v0:
23348 +       case VCMD_ctx_migrate:
23349 +               if (id == 1) {
23350 +                       current->xid = 1;
23351 +                       ret = 1;
23352 +                       goto out;
23353 +               }
23354 +               break;
23355 +
23356 +       /* will go away when spectator is a cap */
23357 +       case VCMD_net_migrate:
23358 +               if (id == 1) {
23359 +                       current->nid = 1;
23360 +                       ret = 1;
23361 +                       goto out;
23362 +               }
23363 +               break;
23364 +       }
23365 +
23366 +       /* vcmds are fine by default */
23367 +       permit = 1;
23368 +
23369 +       /* admin type vcmds require admin ... */
23370 +       if (flags & VCF_ADMIN)
23371 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23372 +
23373 +       /* ... but setup type vcmds override that */
23374 +       if (!permit && (flags & VCF_SETUP))
23375 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23376 +
23377 +       state = 5;
23378 +       ret = -EPERM;
23379 +       if (!permit)
23380 +               goto out;
23381 +
23382 +       state = 6;
23383 +       if (!id && (flags & VCF_ZIDOK))
23384 +               goto skip_id;
23385 +
23386 +       ret = -ESRCH;
23387 +       if (args & VCA_VXI) {
23388 +               vxi = lookup_vx_info(id);
23389 +               if (!vxi)
23390 +                       goto out;
23391 +
23392 +               if ((flags & VCF_ADMIN) &&
23393 +                       /* special case kill for shutdown */
23394 +                       (cmd != VCMD_ctx_kill) &&
23395 +                       /* can context be administrated? */
23396 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23397 +                       ret = -EACCES;
23398 +                       goto out_vxi;
23399 +               }
23400 +       }
23401 +       state = 7;
23402 +       if (args & VCA_NXI) {
23403 +               nxi = lookup_nx_info(id);
23404 +               if (!nxi)
23405 +                       goto out_vxi;
23406 +
23407 +               if ((flags & VCF_ADMIN) &&
23408 +                       /* can context be administrated? */
23409 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23410 +                       ret = -EACCES;
23411 +                       goto out_nxi;
23412 +               }
23413 +       }
23414 +skip_id:
23415 +       state = 8;
23416 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23417 +
23418 +out_nxi:
23419 +       if ((args & VCA_NXI) && nxi)
23420 +               put_nx_info(nxi);
23421 +out_vxi:
23422 +       if ((args & VCA_VXI) && vxi)
23423 +               put_vx_info(vxi);
23424 +out:
23425 +       vxdprintk(VXD_CBIT(switch, 1),
23426 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23427 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23428 +               VC_VERSION(cmd), ret, ret, state, permit);
23429 +       return ret;
23430 +}
23431 +
23432 +asmlinkage long
23433 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23434 +{
23435 +       return do_vserver(cmd, id, data, 0);
23436 +}
23437 +
23438 +#ifdef CONFIG_COMPAT
23439 +
23440 +asmlinkage long
23441 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23442 +{
23443 +       return do_vserver(cmd, id, data, 1);
23444 +}
23445 +
23446 +#endif /* CONFIG_COMPAT */
23447 diff -NurpP --minimal linux-3.2.5/kernel/vserver/sysctl.c linux-3.2.5-vs2.3.2.6/kernel/vserver/sysctl.c
23448 --- linux-3.2.5/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23449 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/sysctl.c       2011-12-05 19:33:02.000000000 +0100
23450 @@ -0,0 +1,247 @@
23451 +/*
23452 + *  kernel/vserver/sysctl.c
23453 + *
23454 + *  Virtual Context Support
23455 + *
23456 + *  Copyright (C) 2004-2007  Herbert Pötzl
23457 + *
23458 + *  V0.01  basic structure
23459 + *
23460 + */
23461 +
23462 +#include <linux/module.h>
23463 +#include <linux/ctype.h>
23464 +#include <linux/sysctl.h>
23465 +#include <linux/parser.h>
23466 +#include <asm/uaccess.h>
23467 +
23468 +enum {
23469 +       CTL_DEBUG_ERROR         = 0,
23470 +       CTL_DEBUG_SWITCH        = 1,
23471 +       CTL_DEBUG_XID,
23472 +       CTL_DEBUG_NID,
23473 +       CTL_DEBUG_TAG,
23474 +       CTL_DEBUG_NET,
23475 +       CTL_DEBUG_LIMIT,
23476 +       CTL_DEBUG_CRES,
23477 +       CTL_DEBUG_DLIM,
23478 +       CTL_DEBUG_QUOTA,
23479 +       CTL_DEBUG_CVIRT,
23480 +       CTL_DEBUG_SPACE,
23481 +       CTL_DEBUG_PERM,
23482 +       CTL_DEBUG_MISC,
23483 +};
23484 +
23485 +
23486 +unsigned int vs_debug_switch   = 0;
23487 +unsigned int vs_debug_xid      = 0;
23488 +unsigned int vs_debug_nid      = 0;
23489 +unsigned int vs_debug_tag      = 0;
23490 +unsigned int vs_debug_net      = 0;
23491 +unsigned int vs_debug_limit    = 0;
23492 +unsigned int vs_debug_cres     = 0;
23493 +unsigned int vs_debug_dlim     = 0;
23494 +unsigned int vs_debug_quota    = 0;
23495 +unsigned int vs_debug_cvirt    = 0;
23496 +unsigned int vs_debug_space    = 0;
23497 +unsigned int vs_debug_perm     = 0;
23498 +unsigned int vs_debug_misc     = 0;
23499 +
23500 +
23501 +static struct ctl_table_header *vserver_table_header;
23502 +static ctl_table vserver_root_table[];
23503 +
23504 +
23505 +void vserver_register_sysctl(void)
23506 +{
23507 +       if (!vserver_table_header) {
23508 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23509 +       }
23510 +
23511 +}
23512 +
23513 +void vserver_unregister_sysctl(void)
23514 +{
23515 +       if (vserver_table_header) {
23516 +               unregister_sysctl_table(vserver_table_header);
23517 +               vserver_table_header = NULL;
23518 +       }
23519 +}
23520 +
23521 +
23522 +static int proc_dodebug(ctl_table *table, int write,
23523 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23524 +{
23525 +       char            tmpbuf[20], *p, c;
23526 +       unsigned int    value;
23527 +       size_t          left, len;
23528 +
23529 +       if ((*ppos && !write) || !*lenp) {
23530 +               *lenp = 0;
23531 +               return 0;
23532 +       }
23533 +
23534 +       left = *lenp;
23535 +
23536 +       if (write) {
23537 +               if (!access_ok(VERIFY_READ, buffer, left))
23538 +                       return -EFAULT;
23539 +               p = (char *)buffer;
23540 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23541 +                       left--, p++;
23542 +               if (!left)
23543 +                       goto done;
23544 +
23545 +               if (left > sizeof(tmpbuf) - 1)
23546 +                       return -EINVAL;
23547 +               if (copy_from_user(tmpbuf, p, left))
23548 +                       return -EFAULT;
23549 +               tmpbuf[left] = '\0';
23550 +
23551 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23552 +                       value = 10 * value + (*p - '0');
23553 +               if (*p && !isspace(*p))
23554 +                       return -EINVAL;
23555 +               while (left && isspace(*p))
23556 +                       left--, p++;
23557 +               *(unsigned int *)table->data = value;
23558 +       } else {
23559 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23560 +                       return -EFAULT;
23561 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23562 +               if (len > left)
23563 +                       len = left;
23564 +               if (__copy_to_user(buffer, tmpbuf, len))
23565 +                       return -EFAULT;
23566 +               if ((left -= len) > 0) {
23567 +                       if (put_user('\n', (char *)buffer + len))
23568 +                               return -EFAULT;
23569 +                       left--;
23570 +               }
23571 +       }
23572 +
23573 +done:
23574 +       *lenp -= left;
23575 +       *ppos += *lenp;
23576 +       return 0;
23577 +}
23578 +
23579 +static int zero;
23580 +
23581 +#define        CTL_ENTRY(ctl, name)                            \
23582 +       {                                               \
23583 +               .procname       = #name,                \
23584 +               .data           = &vs_ ## name,         \
23585 +               .maxlen         = sizeof(int),          \
23586 +               .mode           = 0644,                 \
23587 +               .proc_handler   = &proc_dodebug,        \
23588 +               .extra1         = &zero,                \
23589 +               .extra2         = &zero,                \
23590 +       }
23591 +
23592 +static ctl_table vserver_debug_table[] = {
23593 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23594 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23595 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23596 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23597 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23598 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23599 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23600 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23601 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23602 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23603 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23604 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23605 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23606 +       { 0 }
23607 +};
23608 +
23609 +static ctl_table vserver_root_table[] = {
23610 +       {
23611 +               .procname       = "vserver",
23612 +               .mode           = 0555,
23613 +               .child          = vserver_debug_table
23614 +       },
23615 +       { 0 }
23616 +};
23617 +
23618 +
23619 +static match_table_t tokens = {
23620 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23621 +       { CTL_DEBUG_XID,        "xid=%x"        },
23622 +       { CTL_DEBUG_NID,        "nid=%x"        },
23623 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23624 +       { CTL_DEBUG_NET,        "net=%x"        },
23625 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23626 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23627 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23628 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23629 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23630 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23631 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23632 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23633 +       { CTL_DEBUG_ERROR,      NULL            }
23634 +};
23635 +
23636 +#define        HANDLE_CASE(id, name, val)                              \
23637 +       case CTL_DEBUG_ ## id:                                  \
23638 +               vs_debug_ ## name = val;                        \
23639 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23640 +               break
23641 +
23642 +
23643 +static int __init vs_debug_setup(char *str)
23644 +{
23645 +       char *p;
23646 +       int token;
23647 +
23648 +       printk("vs_debug_setup(%s)\n", str);
23649 +       while ((p = strsep(&str, ",")) != NULL) {
23650 +               substring_t args[MAX_OPT_ARGS];
23651 +               unsigned int value;
23652 +
23653 +               if (!*p)
23654 +                       continue;
23655 +
23656 +               token = match_token(p, tokens, args);
23657 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23658 +
23659 +               switch (token) {
23660 +               HANDLE_CASE(SWITCH, switch, value);
23661 +               HANDLE_CASE(XID,    xid,    value);
23662 +               HANDLE_CASE(NID,    nid,    value);
23663 +               HANDLE_CASE(TAG,    tag,    value);
23664 +               HANDLE_CASE(NET,    net,    value);
23665 +               HANDLE_CASE(LIMIT,  limit,  value);
23666 +               HANDLE_CASE(CRES,   cres,   value);
23667 +               HANDLE_CASE(DLIM,   dlim,   value);
23668 +               HANDLE_CASE(QUOTA,  quota,  value);
23669 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23670 +               HANDLE_CASE(SPACE,  space,  value);
23671 +               HANDLE_CASE(PERM,   perm,   value);
23672 +               HANDLE_CASE(MISC,   misc,   value);
23673 +               default:
23674 +                       return -EINVAL;
23675 +                       break;
23676 +               }
23677 +       }
23678 +       return 1;
23679 +}
23680 +
23681 +__setup("vsdebug=", vs_debug_setup);
23682 +
23683 +
23684 +
23685 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23686 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23687 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23688 +EXPORT_SYMBOL_GPL(vs_debug_net);
23689 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23690 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23691 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23692 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23693 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23694 +EXPORT_SYMBOL_GPL(vs_debug_space);
23695 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23696 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23697 +
23698 diff -NurpP --minimal linux-3.2.5/kernel/vserver/tag.c linux-3.2.5-vs2.3.2.6/kernel/vserver/tag.c
23699 --- linux-3.2.5/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23700 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/tag.c  2011-12-05 19:33:02.000000000 +0100
23701 @@ -0,0 +1,63 @@
23702 +/*
23703 + *  linux/kernel/vserver/tag.c
23704 + *
23705 + *  Virtual Server: Shallow Tag Space
23706 + *
23707 + *  Copyright (C) 2007  Herbert Pötzl
23708 + *
23709 + *  V0.01  basic implementation
23710 + *
23711 + */
23712 +
23713 +#include <linux/sched.h>
23714 +#include <linux/vserver/debug.h>
23715 +#include <linux/vs_pid.h>
23716 +#include <linux/vs_tag.h>
23717 +
23718 +#include <linux/vserver/tag_cmd.h>
23719 +
23720 +
23721 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23722 +{
23723 +       if (!p)
23724 +               BUG();
23725 +
23726 +       vxdprintk(VXD_CBIT(tag, 5),
23727 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23728 +
23729 +       task_lock(p);
23730 +       p->tag = tag;
23731 +       task_unlock(p);
23732 +
23733 +       vxdprintk(VXD_CBIT(tag, 5),
23734 +               "moved task %p into [#%d]", p, tag);
23735 +       return 0;
23736 +}
23737 +
23738 +/* vserver syscall commands below here */
23739 +
23740 +/* taks xid and vx_info functions */
23741 +
23742 +
23743 +int vc_task_tag(uint32_t id)
23744 +{
23745 +       tag_t tag;
23746 +
23747 +       if (id) {
23748 +               struct task_struct *tsk;
23749 +               rcu_read_lock();
23750 +               tsk = find_task_by_real_pid(id);
23751 +               tag = (tsk) ? tsk->tag : -ESRCH;
23752 +               rcu_read_unlock();
23753 +       } else
23754 +               tag = dx_current_tag();
23755 +       return tag;
23756 +}
23757 +
23758 +
23759 +int vc_tag_migrate(uint32_t tag)
23760 +{
23761 +       return dx_migrate_task(current, tag & 0xFFFF);
23762 +}
23763 +
23764 +
23765 diff -NurpP --minimal linux-3.2.5/kernel/vserver/vci_config.h linux-3.2.5-vs2.3.2.6/kernel/vserver/vci_config.h
23766 --- linux-3.2.5/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
23767 +++ linux-3.2.5-vs2.3.2.6/kernel/vserver/vci_config.h   2011-12-05 19:33:02.000000000 +0100
23768 @@ -0,0 +1,76 @@
23769 +
23770 +/*  interface version */
23771 +
23772 +#define VCI_VERSION            0x00020308
23773 +
23774 +
23775 +enum {
23776 +       VCI_KCBIT_NO_DYNAMIC = 0,
23777 +
23778 +       VCI_KCBIT_PROC_SECURE = 4,
23779 +       /* VCI_KCBIT_HARDCPU = 5, */
23780 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23781 +       /* VCI_KCBIT_IDLETIME = 7, */
23782 +
23783 +       VCI_KCBIT_COWBL = 8,
23784 +       VCI_KCBIT_FULLCOWBL = 9,
23785 +       VCI_KCBIT_SPACES = 10,
23786 +       VCI_KCBIT_NETV2 = 11,
23787 +       VCI_KCBIT_MEMCG = 12,
23788 +
23789 +       VCI_KCBIT_DEBUG = 16,
23790 +       VCI_KCBIT_HISTORY = 20,
23791 +       VCI_KCBIT_TAGGED = 24,
23792 +       VCI_KCBIT_PPTAG = 28,
23793 +
23794 +       VCI_KCBIT_MORE = 31,
23795 +};
23796 +
23797 +
23798 +static inline uint32_t vci_kernel_config(void)
23799 +{
23800 +       return
23801 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23802 +
23803 +       /* configured features */
23804 +#ifdef CONFIG_VSERVER_PROC_SECURE
23805 +       (1 << VCI_KCBIT_PROC_SECURE) |
23806 +#endif
23807 +#ifdef CONFIG_VSERVER_COWBL
23808 +       (1 << VCI_KCBIT_COWBL) |
23809 +       (1 << VCI_KCBIT_FULLCOWBL) |
23810 +#endif
23811 +       (1 << VCI_KCBIT_SPACES) |
23812 +       (1 << VCI_KCBIT_NETV2) |
23813 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23814 +       (1 << VCI_KCBIT_MEMCG) |
23815 +#endif
23816 +
23817 +       /* debug options */
23818 +#ifdef CONFIG_VSERVER_DEBUG
23819 +       (1 << VCI_KCBIT_DEBUG) |
23820 +#endif
23821 +#ifdef CONFIG_VSERVER_HISTORY
23822 +       (1 << VCI_KCBIT_HISTORY) |
23823 +#endif
23824 +
23825 +       /* inode context tagging */
23826 +#if    defined(CONFIG_TAGGING_NONE)
23827 +       (0 << VCI_KCBIT_TAGGED) |
23828 +#elif  defined(CONFIG_TAGGING_UID16)
23829 +       (1 << VCI_KCBIT_TAGGED) |
23830 +#elif  defined(CONFIG_TAGGING_GID16)
23831 +       (2 << VCI_KCBIT_TAGGED) |
23832 +#elif  defined(CONFIG_TAGGING_ID24)
23833 +       (3 << VCI_KCBIT_TAGGED) |
23834 +#elif  defined(CONFIG_TAGGING_INTERN)
23835 +       (4 << VCI_KCBIT_TAGGED) |
23836 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23837 +       (5 << VCI_KCBIT_TAGGED) |
23838 +#else
23839 +       (7 << VCI_KCBIT_TAGGED) |
23840 +#endif
23841 +       (1 << VCI_KCBIT_PPTAG) |
23842 +       0;
23843 +}
23844 +
23845 diff -NurpP --minimal linux-3.2.5/mm/memcontrol.c linux-3.2.5-vs2.3.2.6/mm/memcontrol.c
23846 --- linux-3.2.5/mm/memcontrol.c 2012-02-07 01:57:55.000000000 +0100
23847 +++ linux-3.2.5-vs2.3.2.6/mm/memcontrol.c       2012-01-26 08:52:10.000000000 +0100
23848 @@ -766,6 +766,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23849                                 struct mem_cgroup, css);
23850  }
23851  
23852 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23853 +{
23854 +       return res_counter_read_u64(&mem->res, member);
23855 +}
23856 +
23857 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23858 +{
23859 +       return res_counter_read_u64(&mem->memsw, member);
23860 +}
23861 +
23862 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23863 +{
23864 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23865 +}
23866 +
23867 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23868 +{
23869 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23870 +}
23871 +
23872 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23873 +{
23874 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23875 +}
23876 +
23877  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23878  {
23879         struct mem_cgroup *memcg = NULL;
23880 diff -NurpP --minimal linux-3.2.5/mm/oom_kill.c linux-3.2.5-vs2.3.2.6/mm/oom_kill.c
23881 --- linux-3.2.5/mm/oom_kill.c   2012-01-09 16:15:00.000000000 +0100
23882 +++ linux-3.2.5-vs2.3.2.6/mm/oom_kill.c 2012-01-09 16:19:31.000000000 +0100
23883 @@ -33,6 +33,8 @@
23884  #include <linux/security.h>
23885  #include <linux/ptrace.h>
23886  #include <linux/freezer.h>
23887 +#include <linux/reboot.h>
23888 +#include <linux/vs_context.h>
23889  
23890  int sysctl_panic_on_oom;
23891  int sysctl_oom_kill_allocating_task;
23892 @@ -148,11 +150,18 @@ struct task_struct *find_lock_task_mm(st
23893  static bool oom_unkillable_task(struct task_struct *p,
23894                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
23895  {
23896 -       if (is_global_init(p))
23897 +       unsigned xid = vx_current_xid();
23898 +
23899 +       /* skip the init task, global and per guest */
23900 +       if (task_is_init(p))
23901                 return true;
23902         if (p->flags & PF_KTHREAD)
23903                 return true;
23904  
23905 +       /* skip other guest and host processes if oom in guest */
23906 +       if (xid && vx_task_xid(p) != xid)
23907 +               return true;
23908 +
23909         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23910         if (mem && !task_in_mem_cgroup(p, mem))
23911                 return true;
23912 @@ -440,8 +449,8 @@ static int oom_kill_task(struct task_str
23913         /* mm cannot be safely dereferenced after task_unlock(p) */
23914         mm = p->mm;
23915  
23916 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23917 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
23918 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23919 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
23920                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
23921                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
23922         task_unlock(p);
23923 @@ -499,8 +508,8 @@ static int oom_kill_process(struct task_
23924         }
23925  
23926         task_lock(p);
23927 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23928 -               message, task_pid_nr(p), p->comm, points);
23929 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23930 +               message, task_pid_nr(p), p->xid, p->comm, points);
23931         task_unlock(p);
23932  
23933         /*
23934 @@ -601,6 +610,8 @@ int unregister_oom_notifier(struct notif
23935  }
23936  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23937  
23938 +long vs_oom_action(unsigned int);
23939 +
23940  /*
23941   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23942   * if a parallel OOM killing is already taking place that includes a zone in
23943 @@ -759,7 +770,12 @@ retry:
23944         if (!p) {
23945                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23946                 read_unlock(&tasklist_lock);
23947 -               panic("Out of memory and no killable processes...\n");
23948 +
23949 +               /* avoid panic for guest OOM */
23950 +               if (current->xid)
23951 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23952 +               else
23953 +                       panic("Out of memory and no killable processes...\n");
23954         }
23955  
23956         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23957 diff -NurpP --minimal linux-3.2.5/mm/page_alloc.c linux-3.2.5-vs2.3.2.6/mm/page_alloc.c
23958 --- linux-3.2.5/mm/page_alloc.c 2012-02-07 01:57:55.000000000 +0100
23959 +++ linux-3.2.5-vs2.3.2.6/mm/page_alloc.c       2012-01-26 08:52:10.000000000 +0100
23960 @@ -57,6 +57,8 @@
23961  #include <linux/ftrace_event.h>
23962  #include <linux/memcontrol.h>
23963  #include <linux/prefetch.h>
23964 +#include <linux/vs_base.h>
23965 +#include <linux/vs_limit.h>
23966  
23967  #include <asm/tlbflush.h>
23968  #include <asm/div64.h>
23969 @@ -2491,6 +2493,9 @@ void si_meminfo(struct sysinfo *val)
23970         val->totalhigh = totalhigh_pages;
23971         val->freehigh = nr_free_highpages();
23972         val->mem_unit = PAGE_SIZE;
23973 +
23974 +       if (vx_flags(VXF_VIRT_MEM, 0))
23975 +               vx_vsi_meminfo(val);
23976  }
23977  
23978  EXPORT_SYMBOL(si_meminfo);
23979 @@ -2511,6 +2516,9 @@ void si_meminfo_node(struct sysinfo *val
23980         val->freehigh = 0;
23981  #endif
23982         val->mem_unit = PAGE_SIZE;
23983 +
23984 +       if (vx_flags(VXF_VIRT_MEM, 0))
23985 +               vx_vsi_meminfo(val);
23986  }
23987  #endif
23988  
23989 diff -NurpP --minimal linux-3.2.5/mm/pgtable-generic.c linux-3.2.5-vs2.3.2.6/mm/pgtable-generic.c
23990 --- linux-3.2.5/mm/pgtable-generic.c    2011-03-15 18:07:42.000000000 +0100
23991 +++ linux-3.2.5-vs2.3.2.6/mm/pgtable-generic.c  2011-12-05 19:33:02.000000000 +0100
23992 @@ -6,6 +6,8 @@
23993   *  Copyright (C) 2010  Linus Torvalds
23994   */
23995  
23996 +#include <linux/mm.h>
23997 +
23998  #include <linux/pagemap.h>
23999  #include <asm/tlb.h>
24000  #include <asm-generic/pgtable.h>
24001 diff -NurpP --minimal linux-3.2.5/mm/shmem.c linux-3.2.5-vs2.3.2.6/mm/shmem.c
24002 --- linux-3.2.5/mm/shmem.c      2012-02-07 01:57:55.000000000 +0100
24003 +++ linux-3.2.5-vs2.3.2.6/mm/shmem.c    2012-01-26 08:52:10.000000000 +0100
24004 @@ -1460,7 +1460,7 @@ static int shmem_statfs(struct dentry *d
24005  {
24006         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24007  
24008 -       buf->f_type = TMPFS_MAGIC;
24009 +       buf->f_type = TMPFS_SUPER_MAGIC;
24010         buf->f_bsize = PAGE_CACHE_SIZE;
24011         buf->f_namelen = NAME_MAX;
24012         if (sbinfo->max_blocks) {
24013 @@ -2217,7 +2217,7 @@ int shmem_fill_super(struct super_block 
24014         sb->s_maxbytes = MAX_LFS_FILESIZE;
24015         sb->s_blocksize = PAGE_CACHE_SIZE;
24016         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24017 -       sb->s_magic = TMPFS_MAGIC;
24018 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24019         sb->s_op = &shmem_ops;
24020         sb->s_time_gran = 1;
24021  #ifdef CONFIG_TMPFS_XATTR
24022 diff -NurpP --minimal linux-3.2.5/mm/slab.c linux-3.2.5-vs2.3.2.6/mm/slab.c
24023 --- linux-3.2.5/mm/slab.c       2012-01-09 16:15:00.000000000 +0100
24024 +++ linux-3.2.5-vs2.3.2.6/mm/slab.c     2011-12-15 01:11:34.000000000 +0100
24025 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24026  #define STATS_INC_FREEMISS(x)  do { } while (0)
24027  #endif
24028  
24029 +#include "slab_vs.h"
24030 +
24031  #if DEBUG
24032  
24033  /*
24034 @@ -3397,6 +3399,7 @@ retry:
24035  
24036         obj = slab_get_obj(cachep, slabp, nodeid);
24037         check_slabp(cachep, slabp);
24038 +       vx_slab_alloc(cachep, flags);
24039         l3->free_objects--;
24040         /* move slabp to correct slabp list: */
24041         list_del(&slabp->list);
24042 @@ -3474,6 +3477,7 @@ __cache_alloc_node(struct kmem_cache *ca
24043         /* ___cache_alloc_node can fall back to other nodes */
24044         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24045    out:
24046 +       vx_slab_alloc(cachep, flags);
24047         local_irq_restore(save_flags);
24048         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24049         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24050 @@ -3661,6 +3665,7 @@ static inline void __cache_free(struct k
24051         check_irq_off();
24052         kmemleak_free_recursive(objp, cachep->flags);
24053         objp = cache_free_debugcheck(cachep, objp, caller);
24054 +       vx_slab_free(cachep);
24055  
24056         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24057  
24058 diff -NurpP --minimal linux-3.2.5/mm/slab_vs.h linux-3.2.5-vs2.3.2.6/mm/slab_vs.h
24059 --- linux-3.2.5/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24060 +++ linux-3.2.5-vs2.3.2.6/mm/slab_vs.h  2011-12-05 19:33:02.000000000 +0100
24061 @@ -0,0 +1,29 @@
24062 +
24063 +#include <linux/vserver/context.h>
24064 +
24065 +#include <linux/vs_context.h>
24066 +
24067 +static inline
24068 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24069 +{
24070 +       int what = gfp_zone(cachep->gfpflags);
24071 +       struct vx_info *vxi = current_vx_info();
24072 +
24073 +       if (!vxi)
24074 +               return;
24075 +
24076 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24077 +}
24078 +
24079 +static inline
24080 +void vx_slab_free(struct kmem_cache *cachep)
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_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24089 +}
24090 +
24091 diff -NurpP --minimal linux-3.2.5/mm/swapfile.c linux-3.2.5-vs2.3.2.6/mm/swapfile.c
24092 --- linux-3.2.5/mm/swapfile.c   2012-01-09 16:15:00.000000000 +0100
24093 +++ linux-3.2.5-vs2.3.2.6/mm/swapfile.c 2011-12-15 01:52:28.000000000 +0100
24094 @@ -36,6 +36,7 @@
24095  #include <asm/tlbflush.h>
24096  #include <linux/swapops.h>
24097  #include <linux/page_cgroup.h>
24098 +#include <linux/vs_base.h>
24099  
24100  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24101                                  unsigned char);
24102 @@ -1753,6 +1754,16 @@ static int swap_show(struct seq_file *sw
24103  
24104         if (si == SEQ_START_TOKEN) {
24105                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24106 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24107 +                       struct sysinfo si;
24108 +
24109 +                       vx_vsi_swapinfo(&si);
24110 +                       if (si.totalswap < (1 << 10))
24111 +                               return 0;
24112 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24113 +                               "hdv0", "partition", si.totalswap >> 10,
24114 +                               (si.totalswap - si.freeswap) >> 10, -1);
24115 +               }
24116                 return 0;
24117         }
24118  
24119 @@ -2176,6 +2187,8 @@ void si_swapinfo(struct sysinfo *val)
24120         val->freeswap = nr_swap_pages + nr_to_be_unused;
24121         val->totalswap = total_swap_pages + nr_to_be_unused;
24122         spin_unlock(&swap_lock);
24123 +       if (vx_flags(VXF_VIRT_MEM, 0))
24124 +               vx_vsi_swapinfo(val);
24125  }
24126  
24127  /*
24128 diff -NurpP --minimal linux-3.2.5/net/bridge/br_multicast.c linux-3.2.5-vs2.3.2.6/net/bridge/br_multicast.c
24129 --- linux-3.2.5/net/bridge/br_multicast.c       2012-01-09 16:15:03.000000000 +0100
24130 +++ linux-3.2.5-vs2.3.2.6/net/bridge/br_multicast.c     2011-12-05 19:33:02.000000000 +0100
24131 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24132         ip6h->hop_limit = 1;
24133         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24134         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24135 -                          &ip6h->saddr);
24136 +                          &ip6h->saddr, NULL);
24137         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24138  
24139         hopopt = (u8 *)(ip6h + 1);
24140 diff -NurpP --minimal linux-3.2.5/net/core/dev.c linux-3.2.5-vs2.3.2.6/net/core/dev.c
24141 --- linux-3.2.5/net/core/dev.c  2012-01-09 16:15:03.000000000 +0100
24142 +++ linux-3.2.5-vs2.3.2.6/net/core/dev.c        2011-12-15 01:11:36.000000000 +0100
24143 @@ -127,6 +127,7 @@
24144  #include <linux/in.h>
24145  #include <linux/jhash.h>
24146  #include <linux/random.h>
24147 +#include <linux/vs_inet.h>
24148  #include <trace/events/napi.h>
24149  #include <trace/events/net.h>
24150  #include <trace/events/skb.h>
24151 @@ -623,7 +624,8 @@ struct net_device *__dev_get_by_name(str
24152         struct hlist_head *head = dev_name_hash(net, name);
24153  
24154         hlist_for_each_entry(dev, p, head, name_hlist)
24155 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24156 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24157 +                   nx_dev_visible(current_nx_info(), dev))
24158                         return dev;
24159  
24160         return NULL;
24161 @@ -649,7 +651,8 @@ struct net_device *dev_get_by_name_rcu(s
24162         struct hlist_head *head = dev_name_hash(net, name);
24163  
24164         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24165 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24166 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24167 +                   nx_dev_visible(current_nx_info(), dev))
24168                         return dev;
24169  
24170         return NULL;
24171 @@ -700,7 +703,8 @@ struct net_device *__dev_get_by_index(st
24172         struct hlist_head *head = dev_index_hash(net, ifindex);
24173  
24174         hlist_for_each_entry(dev, p, head, index_hlist)
24175 -               if (dev->ifindex == ifindex)
24176 +               if ((dev->ifindex == ifindex) &&
24177 +                   nx_dev_visible(current_nx_info(), dev))
24178                         return dev;
24179  
24180         return NULL;
24181 @@ -718,7 +722,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24182   *     about locking. The caller must hold RCU lock.
24183   */
24184  
24185 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24186 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24187  {
24188         struct hlist_node *p;
24189         struct net_device *dev;
24190 @@ -730,6 +734,16 @@ struct net_device *dev_get_by_index_rcu(
24191  
24192         return NULL;
24193  }
24194 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24195 +
24196 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24197 +{
24198 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24199 +
24200 +       if (nx_dev_visible(current_nx_info(), dev))
24201 +               return dev;
24202 +       return NULL;
24203 +}
24204  EXPORT_SYMBOL(dev_get_by_index_rcu);
24205  
24206  
24207 @@ -778,7 +792,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24208  
24209         for_each_netdev_rcu(net, dev)
24210                 if (dev->type == type &&
24211 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24212 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24213 +                   nx_dev_visible(current_nx_info(), dev))
24214                         return dev;
24215  
24216         return NULL;
24217 @@ -790,9 +805,11 @@ struct net_device *__dev_getfirstbyhwtyp
24218         struct net_device *dev;
24219  
24220         ASSERT_RTNL();
24221 -       for_each_netdev(net, dev)
24222 -               if (dev->type == type)
24223 +       for_each_netdev(net, dev) {
24224 +               if ((dev->type == type) &&
24225 +                   nx_dev_visible(current_nx_info(), dev))
24226                         return dev;
24227 +       }
24228  
24229         return NULL;
24230  }
24231 @@ -910,6 +927,8 @@ static int __dev_alloc_name(struct net *
24232                                 continue;
24233                         if (i < 0 || i >= max_netdevices)
24234                                 continue;
24235 +                       if (!nx_dev_visible(current_nx_info(), d))
24236 +                               continue;
24237  
24238                         /*  avoid cases where sscanf is not exact inverse of printf */
24239                         snprintf(buf, IFNAMSIZ, name, i);
24240 @@ -4067,6 +4086,8 @@ static int dev_ifconf(struct net *net, c
24241  
24242         total = 0;
24243         for_each_netdev(net, dev) {
24244 +               if (!nx_dev_visible(current_nx_info(), dev))
24245 +                       continue;
24246                 for (i = 0; i < NPROTO; i++) {
24247                         if (gifconf_list[i]) {
24248                                 int done;
24249 @@ -4195,6 +4216,10 @@ static void dev_seq_printf_stats(struct 
24250         struct rtnl_link_stats64 temp;
24251         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24252  
24253 +       /* device visible inside network context? */
24254 +       if (!nx_dev_visible(current_nx_info(), dev))
24255 +               return;
24256 +
24257         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24258                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24259                    dev->name, stats->rx_bytes, stats->rx_packets,
24260 diff -NurpP --minimal linux-3.2.5/net/core/rtnetlink.c linux-3.2.5-vs2.3.2.6/net/core/rtnetlink.c
24261 --- linux-3.2.5/net/core/rtnetlink.c    2012-01-09 16:15:03.000000000 +0100
24262 +++ linux-3.2.5-vs2.3.2.6/net/core/rtnetlink.c  2011-12-05 19:33:02.000000000 +0100
24263 @@ -1058,6 +1058,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24264                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24265                         if (idx < s_idx)
24266                                 goto cont;
24267 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24268 +                               continue;
24269                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24270                                              NETLINK_CB(cb->skb).pid,
24271                                              cb->nlh->nlmsg_seq, 0,
24272 @@ -1907,6 +1909,9 @@ void rtmsg_ifinfo(int type, struct net_d
24273         int err = -ENOBUFS;
24274         size_t if_info_size;
24275  
24276 +       if (!nx_dev_visible(current_nx_info(), dev))
24277 +               return;
24278 +
24279         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev)), GFP_KERNEL);
24280         if (skb == NULL)
24281                 goto errout;
24282 diff -NurpP --minimal linux-3.2.5/net/core/sock.c linux-3.2.5-vs2.3.2.6/net/core/sock.c
24283 --- linux-3.2.5/net/core/sock.c 2012-01-09 16:15:03.000000000 +0100
24284 +++ linux-3.2.5-vs2.3.2.6/net/core/sock.c       2012-01-09 16:19:31.000000000 +0100
24285 @@ -127,6 +127,10 @@
24286  #include <net/cls_cgroup.h>
24287  
24288  #include <linux/filter.h>
24289 +#include <linux/vs_socket.h>
24290 +#include <linux/vs_limit.h>
24291 +#include <linux/vs_context.h>
24292 +#include <linux/vs_network.h>
24293  
24294  #include <trace/events/sock.h>
24295  
24296 @@ -1066,6 +1070,8 @@ static struct sock *sk_prot_alloc(struct
24297                         goto out_free_sec;
24298                 sk_tx_queue_clear(sk);
24299         }
24300 +               sock_vx_init(sk);
24301 +               sock_nx_init(sk);
24302  
24303         return sk;
24304  
24305 @@ -1165,6 +1171,11 @@ static void __sk_free(struct sock *sk)
24306                 put_cred(sk->sk_peer_cred);
24307         put_pid(sk->sk_peer_pid);
24308         put_net(sock_net(sk));
24309 +       vx_sock_dec(sk);
24310 +       clr_vx_info(&sk->sk_vx_info);
24311 +       sk->sk_xid = -1;
24312 +       clr_nx_info(&sk->sk_nx_info);
24313 +       sk->sk_nid = -1;
24314         sk_prot_free(sk->sk_prot_creator, sk);
24315  }
24316  
24317 @@ -1212,6 +1223,8 @@ struct sock *sk_clone(const struct sock 
24318  
24319                 /* SANITY */
24320                 get_net(sock_net(newsk));
24321 +               sock_vx_init(newsk);
24322 +               sock_nx_init(newsk);
24323                 sk_node_init(&newsk->sk_node);
24324                 sock_lock_init(newsk);
24325                 bh_lock_sock(newsk);
24326 @@ -1268,6 +1281,12 @@ struct sock *sk_clone(const struct sock 
24327                 smp_wmb();
24328                 atomic_set(&newsk->sk_refcnt, 2);
24329  
24330 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24331 +               newsk->sk_xid = sk->sk_xid;
24332 +               vx_sock_inc(newsk);
24333 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24334 +               newsk->sk_nid = sk->sk_nid;
24335 +
24336                 /*
24337                  * Increment the counter in the same struct proto as the master
24338                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24339 @@ -2014,6 +2033,12 @@ void sock_init_data(struct socket *sock,
24340  
24341         sk->sk_stamp = ktime_set(-1L, 0);
24342  
24343 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24344 +       sk->sk_xid = vx_current_xid();
24345 +       vx_sock_inc(sk);
24346 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24347 +       sk->sk_nid = nx_current_nid();
24348 +
24349         /*
24350          * Before updating sk_refcnt, we must commit prior changes to memory
24351          * (Documentation/RCU/rculist_nulls.txt for details)
24352 diff -NurpP --minimal linux-3.2.5/net/ipv4/af_inet.c linux-3.2.5-vs2.3.2.6/net/ipv4/af_inet.c
24353 --- linux-3.2.5/net/ipv4/af_inet.c      2012-01-09 16:15:03.000000000 +0100
24354 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/af_inet.c    2011-12-05 19:33:02.000000000 +0100
24355 @@ -117,6 +117,7 @@
24356  #ifdef CONFIG_IP_MROUTE
24357  #include <linux/mroute.h>
24358  #endif
24359 +#include <linux/vs_limit.h>
24360  
24361  
24362  /* The inetsw table contains everything that inet_create needs to
24363 @@ -326,9 +327,13 @@ lookup_protocol:
24364         }
24365  
24366         err = -EPERM;
24367 +       if ((protocol == IPPROTO_ICMP) &&
24368 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24369 +               goto override;
24370 +
24371         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24372                 goto out_rcu_unlock;
24373 -
24374 +override:
24375         err = -EAFNOSUPPORT;
24376         if (!inet_netns_ok(net, protocol))
24377                 goto out_rcu_unlock;
24378 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24379         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24380         struct sock *sk = sock->sk;
24381         struct inet_sock *inet = inet_sk(sk);
24382 +       struct nx_v4_sock_addr nsa;
24383         unsigned short snum;
24384         int chk_addr_ret;
24385         int err;
24386 @@ -475,7 +481,11 @@ int inet_bind(struct socket *sock, struc
24387                         goto out;
24388         }
24389  
24390 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24391 +       err = v4_map_sock_addr(inet, addr, &nsa);
24392 +       if (err)
24393 +               goto out;
24394 +
24395 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24396  
24397         /* Not specified by any standard per-se, however it breaks too
24398          * many applications when removed.  It is unfortunate since
24399 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
24400         err = -EADDRNOTAVAIL;
24401         if (!sysctl_ip_nonlocal_bind &&
24402             !(inet->freebind || inet->transparent) &&
24403 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24404 +           nsa.saddr != htonl(INADDR_ANY) &&
24405             chk_addr_ret != RTN_LOCAL &&
24406             chk_addr_ret != RTN_MULTICAST &&
24407             chk_addr_ret != RTN_BROADCAST)
24408 @@ -512,7 +522,7 @@ int inet_bind(struct socket *sock, struc
24409         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24410                 goto out_release_sock;
24411  
24412 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24413 +       v4_set_sock_addr(inet, &nsa);
24414         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24415                 inet->inet_saddr = 0;  /* Use device */
24416  
24417 @@ -715,11 +725,13 @@ int inet_getname(struct socket *sock, st
24418                      peer == 1))
24419                         return -ENOTCONN;
24420                 sin->sin_port = inet->inet_dport;
24421 -               sin->sin_addr.s_addr = inet->inet_daddr;
24422 +               sin->sin_addr.s_addr =
24423 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24424         } else {
24425                 __be32 addr = inet->inet_rcv_saddr;
24426                 if (!addr)
24427                         addr = inet->inet_saddr;
24428 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24429                 sin->sin_port = inet->inet_sport;
24430                 sin->sin_addr.s_addr = addr;
24431         }
24432 diff -NurpP --minimal linux-3.2.5/net/ipv4/arp.c linux-3.2.5-vs2.3.2.6/net/ipv4/arp.c
24433 --- linux-3.2.5/net/ipv4/arp.c  2011-10-24 18:45:34.000000000 +0200
24434 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/arp.c        2012-02-07 03:13:38.000000000 +0100
24435 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24436         struct net_device *dev = n->dev;
24437         int hatype = dev->type;
24438  
24439 +       /* FIXME: check for network context */
24440         read_lock(&n->lock);
24441         /* Convert hardware address to XX:XX:XX:XX ... form. */
24442  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
24443 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24444         int hatype = dev ? dev->type : 0;
24445         char tbuf[16];
24446  
24447 +       /* FIXME: check for network context */
24448         sprintf(tbuf, "%pI4", n->key);
24449         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24450                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24451 diff -NurpP --minimal linux-3.2.5/net/ipv4/devinet.c linux-3.2.5-vs2.3.2.6/net/ipv4/devinet.c
24452 --- linux-3.2.5/net/ipv4/devinet.c      2012-02-07 01:57:55.000000000 +0100
24453 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/devinet.c    2012-02-07 03:14:01.000000000 +0100
24454 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24455  }
24456  EXPORT_SYMBOL(inetdev_by_index);
24457  
24458 +
24459  /* Called only from RTNL semaphored context. No locks. */
24460  
24461  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24462 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24463  
24464         in_dev = __in_dev_get_rtnl(dev);
24465         if (in_dev) {
24466 +               struct nx_info *nxi = current_nx_info();
24467 +
24468                 if (tryaddrmatch) {
24469                         /* Matthias Andree */
24470                         /* compare label and address (4.4BSD style) */
24471 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24472                            This is checked above. */
24473                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24474                              ifap = &ifa->ifa_next) {
24475 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24476 +                                       continue;
24477                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24478                                     sin_orig.sin_addr.s_addr ==
24479                                                         ifa->ifa_local) {
24480 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24481                    comparing just the label */
24482                 if (!ifa) {
24483                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24484 -                            ifap = &ifa->ifa_next)
24485 +                            ifap = &ifa->ifa_next) {
24486 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24487 +                                       continue;
24488                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24489                                         break;
24490 +                       }
24491                 }
24492         }
24493  
24494 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24495                 goto out;
24496  
24497         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24498 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24499 +                       continue;
24500                 if (!buf) {
24501                         done += sizeof(ifr);
24502                         continue;
24503 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24504         struct net_device *dev;
24505         struct in_device *in_dev;
24506         struct in_ifaddr *ifa;
24507 +       struct sock *sk = skb->sk;
24508         struct hlist_head *head;
24509         struct hlist_node *node;
24510  
24511 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24512  
24513                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24514                              ifa = ifa->ifa_next, ip_idx++) {
24515 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24516 +                               continue;
24517                                 if (ip_idx < s_ip_idx)
24518                                         continue;
24519                                 if (inet_fill_ifaddr(skb, ifa,
24520 diff -NurpP --minimal linux-3.2.5/net/ipv4/fib_trie.c linux-3.2.5-vs2.3.2.6/net/ipv4/fib_trie.c
24521 --- linux-3.2.5/net/ipv4/fib_trie.c     2012-02-07 01:57:55.000000000 +0100
24522 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/fib_trie.c   2012-02-07 03:14:01.000000000 +0100
24523 @@ -2555,6 +2555,7 @@ static int fib_route_seq_show(struct seq
24524                             || fa->fa_type == RTN_MULTICAST)
24525                                 continue;
24526  
24527 +                       /* FIXME: check for network context? */
24528                         if (fi)
24529                                 seq_printf(seq,
24530                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24531 diff -NurpP --minimal linux-3.2.5/net/ipv4/inet_connection_sock.c linux-3.2.5-vs2.3.2.6/net/ipv4/inet_connection_sock.c
24532 --- linux-3.2.5/net/ipv4/inet_connection_sock.c 2011-07-22 11:18:13.000000000 +0200
24533 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/inet_connection_sock.c       2012-02-07 03:13:38.000000000 +0100
24534 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24535  }
24536  EXPORT_SYMBOL(inet_get_local_port_range);
24537  
24538 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24539 +{
24540 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24541 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24542 +
24543 +       if (inet_v6_ipv6only(sk2))
24544 +               return 0;
24545 +
24546 +       if (sk1_rcv_saddr &&
24547 +           sk2_rcv_saddr &&
24548 +           sk1_rcv_saddr == sk2_rcv_saddr)
24549 +               return 1;
24550 +
24551 +       if (sk1_rcv_saddr &&
24552 +           !sk2_rcv_saddr &&
24553 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24554 +               return 1;
24555 +
24556 +       if (sk2_rcv_saddr &&
24557 +           !sk1_rcv_saddr &&
24558 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24559 +               return 1;
24560 +
24561 +       if (!sk1_rcv_saddr &&
24562 +           !sk2_rcv_saddr &&
24563 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24564 +               return 1;
24565 +
24566 +       return 0;
24567 +}
24568 +
24569  int inet_csk_bind_conflict(const struct sock *sk,
24570                            const struct inet_bind_bucket *tb)
24571  {
24572 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
24573                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24574                         if (!reuse || !sk2->sk_reuse ||
24575                             sk2->sk_state == TCP_LISTEN) {
24576 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24577 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24578 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24579 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24580                                         break;
24581                         }
24582                 }
24583 diff -NurpP --minimal linux-3.2.5/net/ipv4/inet_diag.c linux-3.2.5-vs2.3.2.6/net/ipv4/inet_diag.c
24584 --- linux-3.2.5/net/ipv4/inet_diag.c    2012-01-09 16:15:03.000000000 +0100
24585 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/inet_diag.c  2011-12-15 01:11:37.000000000 +0100
24586 @@ -33,6 +33,8 @@
24587  #include <linux/stddef.h>
24588  
24589  #include <linux/inet_diag.h>
24590 +#include <linux/vs_network.h>
24591 +#include <linux/vs_inet.h>
24592  
24593  static const struct inet_diag_handler **inet_diag_table;
24594  
24595 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
24596  
24597         r->id.idiag_sport = inet->inet_sport;
24598         r->id.idiag_dport = inet->inet_dport;
24599 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24600 -       r->id.idiag_dst[0] = inet->inet_daddr;
24601 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24602 +               inet->inet_rcv_saddr);
24603 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24604 +               inet->inet_daddr);
24605  
24606         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24607          * hence this needs to be included regardless of socket family.
24608 @@ -214,8 +218,8 @@ static int inet_twsk_diag_fill(struct in
24609         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
24610         r->id.idiag_sport     = tw->tw_sport;
24611         r->id.idiag_dport     = tw->tw_dport;
24612 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24613 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24614 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24615 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24616         r->idiag_state        = tw->tw_substate;
24617         r->idiag_timer        = 3;
24618         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24619 @@ -272,6 +276,7 @@ static int inet_diag_get_exact(struct sk
24620         err = -EINVAL;
24621  
24622         if (req->idiag_family == AF_INET) {
24623 +               /* TODO: lback */
24624                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24625                                  req->id.idiag_dport, req->id.idiag_src[0],
24626                                  req->id.idiag_sport, req->id.idiag_if);
24627 @@ -514,6 +519,7 @@ static int inet_csk_diag_dump(struct soc
24628                 } else
24629  #endif
24630                 {
24631 +                       /* TODO: lback */
24632                         entry.saddr = &inet->inet_rcv_saddr;
24633                         entry.daddr = &inet->inet_daddr;
24634                 }
24635 @@ -552,6 +558,7 @@ static int inet_twsk_diag_dump(struct in
24636                 } else
24637  #endif
24638                 {
24639 +                       /* TODO: lback */
24640                         entry.saddr = &tw->tw_rcv_saddr;
24641                         entry.daddr = &tw->tw_daddr;
24642                 }
24643 @@ -598,8 +605,8 @@ static int inet_diag_fill_req(struct sk_
24644  
24645         r->id.idiag_sport = inet->inet_sport;
24646         r->id.idiag_dport = ireq->rmt_port;
24647 -       r->id.idiag_src[0] = ireq->loc_addr;
24648 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24649 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24650 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24651         r->idiag_expires = jiffies_to_msecs(tmo);
24652         r->idiag_rqueue = 0;
24653         r->idiag_wqueue = 0;
24654 @@ -670,6 +677,7 @@ static int inet_diag_dump_reqs(struct sk
24655                                 continue;
24656  
24657                         if (bc) {
24658 +                               /* TODO: lback */
24659                                 entry.saddr =
24660  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
24661                                         (entry.family == AF_INET6) ?
24662 @@ -740,6 +748,8 @@ static int inet_diag_dump(struct sk_buff
24663                         sk_nulls_for_each(sk, node, &ilb->head) {
24664                                 struct inet_sock *inet = inet_sk(sk);
24665  
24666 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24667 +                                       continue;
24668                                 if (num < s_num) {
24669                                         num++;
24670                                         continue;
24671 @@ -806,6 +816,8 @@ skip_listen_ht:
24672                 sk_nulls_for_each(sk, node, &head->chain) {
24673                         struct inet_sock *inet = inet_sk(sk);
24674  
24675 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24676 +                               continue;
24677                         if (num < s_num)
24678                                 goto next_normal;
24679                         if (!(r->idiag_states & (1 << sk->sk_state)))
24680 @@ -830,6 +842,8 @@ next_normal:
24681                         inet_twsk_for_each(tw, node,
24682                                     &head->twchain) {
24683  
24684 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24685 +                                       continue;
24686                                 if (num < s_num)
24687                                         goto next_dying;
24688                                 if (r->id.idiag_sport != tw->tw_sport &&
24689 diff -NurpP --minimal linux-3.2.5/net/ipv4/inet_hashtables.c linux-3.2.5-vs2.3.2.6/net/ipv4/inet_hashtables.c
24690 --- linux-3.2.5/net/ipv4/inet_hashtables.c      2011-10-24 18:45:34.000000000 +0200
24691 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/inet_hashtables.c    2011-12-05 19:33:02.000000000 +0100
24692 @@ -22,6 +22,7 @@
24693  #include <net/inet_connection_sock.h>
24694  #include <net/inet_hashtables.h>
24695  #include <net/secure_seq.h>
24696 +#include <net/route.h>
24697  #include <net/ip.h>
24698  
24699  /*
24700 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24701                         if (rcv_saddr != daddr)
24702                                 return -1;
24703                         score += 2;
24704 +               } else {
24705 +                       /* block non nx_info ips */
24706 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24707 +                               daddr, NXA_MASK_BIND))
24708 +                               return -1;
24709                 }
24710                 if (sk->sk_bound_dev_if) {
24711                         if (sk->sk_bound_dev_if != dif)
24712 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24713   * wildcarded during the search since they can never be otherwise.
24714   */
24715  
24716 -
24717  struct sock *__inet_lookup_listener(struct net *net,
24718                                     struct inet_hashinfo *hashinfo,
24719                                     const __be32 daddr, const unsigned short hnum,
24720 @@ -196,6 +201,7 @@ begin:
24721                         hiscore = score;
24722                 }
24723         }
24724 +
24725         /*
24726          * if the nulls value we got at the end of this lookup is
24727          * not the expected one, we must restart lookup.
24728 diff -NurpP --minimal linux-3.2.5/net/ipv4/netfilter/nf_nat_helper.c linux-3.2.5-vs2.3.2.6/net/ipv4/netfilter/nf_nat_helper.c
24729 --- linux-3.2.5/net/ipv4/netfilter/nf_nat_helper.c      2011-07-22 11:18:13.000000000 +0200
24730 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/netfilter/nf_nat_helper.c    2011-12-05 19:33:02.000000000 +0100
24731 @@ -20,6 +20,7 @@
24732  #include <net/route.h>
24733  
24734  #include <linux/netfilter_ipv4.h>
24735 +#include <net/route.h>
24736  #include <net/netfilter/nf_conntrack.h>
24737  #include <net/netfilter/nf_conntrack_helper.h>
24738  #include <net/netfilter/nf_conntrack_ecache.h>
24739 diff -NurpP --minimal linux-3.2.5/net/ipv4/netfilter.c linux-3.2.5-vs2.3.2.6/net/ipv4/netfilter.c
24740 --- linux-3.2.5/net/ipv4/netfilter.c    2012-01-09 16:15:03.000000000 +0100
24741 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/netfilter.c  2012-02-07 03:13:38.000000000 +0100
24742 @@ -6,7 +6,7 @@
24743  #include <linux/skbuff.h>
24744  #include <linux/gfp.h>
24745  #include <linux/export.h>
24746 -#include <net/route.h>
24747 +// #include <net/route.h>
24748  #include <net/xfrm.h>
24749  #include <net/ip.h>
24750  #include <net/netfilter/nf_queue.h>
24751 diff -NurpP --minimal linux-3.2.5/net/ipv4/raw.c linux-3.2.5-vs2.3.2.6/net/ipv4/raw.c
24752 --- linux-3.2.5/net/ipv4/raw.c  2012-01-09 16:15:04.000000000 +0100
24753 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/raw.c        2012-02-07 03:13:38.000000000 +0100
24754 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24755  
24756                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24757                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24758 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24759 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24760                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24761                         goto found; /* gotcha */
24762         }
24763 @@ -386,6 +386,12 @@ static int raw_send_hdrinc(struct sock *
24764                 icmp_out_count(net, ((struct icmphdr *)
24765                         skb_transport_header(skb))->type);
24766  
24767 +       err = -EPERM;
24768 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24769 +               sk->sk_nx_info &&
24770 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24771 +               goto error_free;
24772 +
24773         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24774                       rt->dst.dev, dst_output);
24775         if (err > 0)
24776 @@ -573,6 +579,16 @@ static int raw_sendmsg(struct kiocb *ioc
24777                         goto done;
24778         }
24779  
24780 +       if (sk->sk_nx_info) {
24781 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24782 +               if (IS_ERR(rt)) {
24783 +                       err = PTR_ERR(rt);
24784 +                       rt = NULL;
24785 +                       goto done;
24786 +               }
24787 +               ip_rt_put(rt);
24788 +       }
24789 +
24790         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24791         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24792         if (IS_ERR(rt)) {
24793 @@ -649,17 +665,19 @@ static int raw_bind(struct sock *sk, str
24794  {
24795         struct inet_sock *inet = inet_sk(sk);
24796         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24797 +       struct nx_v4_sock_addr nsa = { 0 };
24798         int ret = -EINVAL;
24799         int chk_addr_ret;
24800  
24801         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24802                 goto out;
24803 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24804 +       v4_map_sock_addr(inet, addr, &nsa);
24805 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24806         ret = -EADDRNOTAVAIL;
24807 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24808 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24809             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24810                 goto out;
24811 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24812 +       v4_set_sock_addr(inet, &nsa);
24813         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24814                 inet->inet_saddr = 0;  /* Use device */
24815         sk_dst_reset(sk);
24816 @@ -711,7 +729,8 @@ static int raw_recvmsg(struct kiocb *ioc
24817         /* Copy the address. */
24818         if (sin) {
24819                 sin->sin_family = AF_INET;
24820 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24821 +               sin->sin_addr.s_addr =
24822 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24823                 sin->sin_port = 0;
24824                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24825         }
24826 @@ -907,7 +926,8 @@ static struct sock *raw_get_first(struct
24827                 struct hlist_node *node;
24828  
24829                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24830 -                       if (sock_net(sk) == seq_file_net(seq))
24831 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24832 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24833                                 goto found;
24834         }
24835         sk = NULL;
24836 @@ -923,7 +943,8 @@ static struct sock *raw_get_next(struct 
24837                 sk = sk_next(sk);
24838  try_again:
24839                 ;
24840 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24841 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24842 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24843  
24844         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24845                 sk = sk_head(&state->h->ht[state->bucket]);
24846 diff -NurpP --minimal linux-3.2.5/net/ipv4/route.c linux-3.2.5-vs2.3.2.6/net/ipv4/route.c
24847 --- linux-3.2.5/net/ipv4/route.c        2012-01-09 16:15:04.000000000 +0100
24848 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/route.c      2012-02-07 03:13:38.000000000 +0100
24849 @@ -2709,7 +2709,7 @@ static struct rtable *ip_route_output_sl
24850  
24851  
24852         if (fl4->flowi4_oif) {
24853 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24854 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24855                 rth = ERR_PTR(-ENODEV);
24856                 if (dev_out == NULL)
24857                         goto out;
24858 diff -NurpP --minimal linux-3.2.5/net/ipv4/tcp.c linux-3.2.5-vs2.3.2.6/net/ipv4/tcp.c
24859 --- linux-3.2.5/net/ipv4/tcp.c  2012-01-09 16:15:04.000000000 +0100
24860 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/tcp.c        2011-12-05 19:33:02.000000000 +0100
24861 @@ -266,6 +266,7 @@
24862  #include <linux/crypto.h>
24863  #include <linux/time.h>
24864  #include <linux/slab.h>
24865 +#include <linux/in.h>
24866  
24867  #include <net/icmp.h>
24868  #include <net/tcp.h>
24869 diff -NurpP --minimal linux-3.2.5/net/ipv4/tcp_ipv4.c linux-3.2.5-vs2.3.2.6/net/ipv4/tcp_ipv4.c
24870 --- linux-3.2.5/net/ipv4/tcp_ipv4.c     2012-02-07 01:57:55.000000000 +0100
24871 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/tcp_ipv4.c   2012-02-07 03:14:01.000000000 +0100
24872 @@ -2023,6 +2023,12 @@ static void *listening_get_next(struct s
24873                 req = req->dl_next;
24874                 while (1) {
24875                         while (req) {
24876 +                               vxdprintk(VXD_CBIT(net, 6),
24877 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24878 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24879 +                               if (req->sk &&
24880 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24881 +                                       continue;
24882                                 if (req->rsk_ops->family == st->family) {
24883                                         cur = req;
24884                                         goto out;
24885 @@ -2047,6 +2053,10 @@ get_req:
24886         }
24887  get_sk:
24888         sk_nulls_for_each_from(sk, node) {
24889 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24890 +                       sk, sk->sk_nid, nx_current_nid());
24891 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24892 +                       continue;
24893                 if (!net_eq(sock_net(sk), net))
24894                         continue;
24895                 if (sk->sk_family == st->family) {
24896 @@ -2123,6 +2133,11 @@ static void *established_get_first(struc
24897  
24898                 spin_lock_bh(lock);
24899                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24900 +                       vxdprintk(VXD_CBIT(net, 6),
24901 +                               "sk,egf: %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 (sk->sk_family != st->family ||
24906                             !net_eq(sock_net(sk), net)) {
24907                                 continue;
24908 @@ -2133,6 +2148,11 @@ static void *established_get_first(struc
24909                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24910                 inet_twsk_for_each(tw, node,
24911                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24912 +                       vxdprintk(VXD_CBIT(net, 6),
24913 +                               "tw: %p [#%d] (from %d)",
24914 +                               tw, tw->tw_nid, nx_current_nid());
24915 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24916 +                               continue;
24917                         if (tw->tw_family != st->family ||
24918                             !net_eq(twsk_net(tw), net)) {
24919                                 continue;
24920 @@ -2162,7 +2182,9 @@ static void *established_get_next(struct
24921                 tw = cur;
24922                 tw = tw_next(tw);
24923  get_tw:
24924 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24925 +               while (tw && (tw->tw_family != st->family ||
24926 +                       !net_eq(twsk_net(tw), net) ||
24927 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24928                         tw = tw_next(tw);
24929                 }
24930                 if (tw) {
24931 @@ -2186,6 +2208,11 @@ get_tw:
24932                 sk = sk_nulls_next(sk);
24933  
24934         sk_nulls_for_each_from(sk, node) {
24935 +               vxdprintk(VXD_CBIT(net, 6),
24936 +                       "sk,egn: %p [#%d] (from %d)",
24937 +                       sk, sk->sk_nid, nx_current_nid());
24938 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24939 +                       continue;
24940                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24941                         goto found;
24942         }
24943 @@ -2391,9 +2418,9 @@ static void get_openreq4(const struct so
24944         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24945                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24946                 i,
24947 -               ireq->loc_addr,
24948 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24949                 ntohs(inet_sk(sk)->inet_sport),
24950 -               ireq->rmt_addr,
24951 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24952                 ntohs(ireq->rmt_port),
24953                 TCP_SYN_RECV,
24954                 0, 0, /* could print option size, but that is af dependent. */
24955 @@ -2415,8 +2442,8 @@ static void get_tcp4_sock(struct sock *s
24956         const struct tcp_sock *tp = tcp_sk(sk);
24957         const struct inet_connection_sock *icsk = inet_csk(sk);
24958         const struct inet_sock *inet = inet_sk(sk);
24959 -       __be32 dest = inet->inet_daddr;
24960 -       __be32 src = inet->inet_rcv_saddr;
24961 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24962 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24963         __u16 destp = ntohs(inet->inet_dport);
24964         __u16 srcp = ntohs(inet->inet_sport);
24965         int rx_queue;
24966 @@ -2473,8 +2500,8 @@ static void get_timewait4_sock(const str
24967         if (ttd < 0)
24968                 ttd = 0;
24969  
24970 -       dest  = tw->tw_daddr;
24971 -       src   = tw->tw_rcv_saddr;
24972 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24973 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24974         destp = ntohs(tw->tw_dport);
24975         srcp  = ntohs(tw->tw_sport);
24976  
24977 diff -NurpP --minimal linux-3.2.5/net/ipv4/tcp_minisocks.c linux-3.2.5-vs2.3.2.6/net/ipv4/tcp_minisocks.c
24978 --- linux-3.2.5/net/ipv4/tcp_minisocks.c        2012-01-09 16:15:04.000000000 +0100
24979 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/tcp_minisocks.c      2011-12-05 19:33:02.000000000 +0100
24980 @@ -23,6 +23,9 @@
24981  #include <linux/slab.h>
24982  #include <linux/sysctl.h>
24983  #include <linux/workqueue.h>
24984 +#include <linux/vs_limit.h>
24985 +#include <linux/vs_socket.h>
24986 +#include <linux/vs_context.h>
24987  #include <net/tcp.h>
24988  #include <net/inet_common.h>
24989  #include <net/xfrm.h>
24990 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
24991                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
24992                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24993  
24994 +               tw->tw_xid              = sk->sk_xid;
24995 +               tw->tw_vx_info          = NULL;
24996 +               tw->tw_nid              = sk->sk_nid;
24997 +               tw->tw_nx_info          = NULL;
24998 +
24999  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25000                 if (tw->tw_family == PF_INET6) {
25001                         struct ipv6_pinfo *np = inet6_sk(sk);
25002 diff -NurpP --minimal linux-3.2.5/net/ipv4/udp.c linux-3.2.5-vs2.3.2.6/net/ipv4/udp.c
25003 --- linux-3.2.5/net/ipv4/udp.c  2012-01-09 16:15:04.000000000 +0100
25004 +++ linux-3.2.5-vs2.3.2.6/net/ipv4/udp.c        2012-02-07 03:13:38.000000000 +0100
25005 @@ -297,14 +297,7 @@ fail:
25006  }
25007  EXPORT_SYMBOL(udp_lib_get_port);
25008  
25009 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25010 -{
25011 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25012 -
25013 -       return  (!ipv6_only_sock(sk2)  &&
25014 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25015 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25016 -}
25017 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25018  
25019  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25020                                        unsigned int port)
25021 @@ -339,6 +332,11 @@ static inline int compute_score(struct s
25022                         if (inet->inet_rcv_saddr != daddr)
25023                                 return -1;
25024                         score += 2;
25025 +               } else {
25026 +                       /* block non nx_info ips */
25027 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25028 +                               daddr, NXA_MASK_BIND))
25029 +                               return -1;
25030                 }
25031                 if (inet->inet_daddr) {
25032                         if (inet->inet_daddr != saddr)
25033 @@ -442,6 +440,7 @@ exact_match:
25034         return result;
25035  }
25036  
25037 +
25038  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25039   * harder than this. -DaveM
25040   */
25041 @@ -487,6 +486,11 @@ begin:
25042         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25043                 score = compute_score(sk, net, saddr, hnum, sport,
25044                                       daddr, dport, dif);
25045 +               /* FIXME: disabled?
25046 +               if (score == 9) {
25047 +                       result = sk;
25048 +                       break;
25049 +               } else */
25050                 if (score > badness) {
25051                         result = sk;
25052                         badness = score;
25053 @@ -500,6 +504,7 @@ begin:
25054         if (get_nulls_value(node) != slot)
25055                 goto begin;
25056  
25057 +
25058         if (result) {
25059                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25060                         result = NULL;
25061 @@ -509,6 +514,7 @@ begin:
25062                         goto begin;
25063                 }
25064         }
25065 +
25066         rcu_read_unlock();
25067         return result;
25068  }
25069 @@ -551,8 +557,7 @@ static inline struct sock *udp_v4_mcast_
25070                     udp_sk(s)->udp_port_hash != hnum ||
25071                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25072                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25073 -                   (inet->inet_rcv_saddr &&
25074 -                    inet->inet_rcv_saddr != loc_addr) ||
25075 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25076                     ipv6_only_sock(s) ||
25077                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25078                         continue;
25079 @@ -930,6 +935,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25080                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25081                                    faddr, saddr, dport, inet->inet_sport);
25082  
25083 +               if (sk->sk_nx_info) {
25084 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25085 +                       if (IS_ERR(rt)) {
25086 +                               err = PTR_ERR(rt);
25087 +                               rt = NULL;
25088 +                               goto out;
25089 +                       }
25090 +                       ip_rt_put(rt);
25091 +               }
25092 +
25093                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25094                 rt = ip_route_output_flow(net, fl4, sk);
25095                 if (IS_ERR(rt)) {
25096 @@ -1228,7 +1243,8 @@ try_again:
25097         if (sin) {
25098                 sin->sin_family = AF_INET;
25099                 sin->sin_port = udp_hdr(skb)->source;
25100 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25101 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25102 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25103                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25104         }
25105         if (inet->cmsg_flags)
25106 @@ -1974,6 +1990,8 @@ static struct sock *udp_get_first(struct
25107                 sk_nulls_for_each(sk, node, &hslot->head) {
25108                         if (!net_eq(sock_net(sk), net))
25109                                 continue;
25110 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25111 +                               continue;
25112                         if (sk->sk_family == state->family)
25113                                 goto found;
25114                 }
25115 @@ -1991,7 +2009,9 @@ static struct sock *udp_get_next(struct 
25116  
25117         do {
25118                 sk = sk_nulls_next(sk);
25119 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25120 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25121 +               sk->sk_family != state->family ||
25122 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25123  
25124         if (!sk) {
25125                 if (state->bucket <= state->udp_table->mask)
25126 diff -NurpP --minimal linux-3.2.5/net/ipv6/Kconfig linux-3.2.5-vs2.3.2.6/net/ipv6/Kconfig
25127 --- linux-3.2.5/net/ipv6/Kconfig        2010-08-02 16:52:59.000000000 +0200
25128 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/Kconfig      2011-12-05 19:33:02.000000000 +0100
25129 @@ -4,8 +4,8 @@
25130  
25131  #   IPv6 as module will cause a CRASH if you try to unload it
25132  menuconfig IPV6
25133 -       tristate "The IPv6 protocol"
25134 -       default m
25135 +       bool "The IPv6 protocol"
25136 +       default n
25137         ---help---
25138           This is complemental support for the IP version 6.
25139           You will still be able to do traditional IPv4 networking as well.
25140 diff -NurpP --minimal linux-3.2.5/net/ipv6/addrconf.c linux-3.2.5-vs2.3.2.6/net/ipv6/addrconf.c
25141 --- linux-3.2.5/net/ipv6/addrconf.c     2012-02-07 01:57:55.000000000 +0100
25142 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/addrconf.c   2012-02-07 03:14:01.000000000 +0100
25143 @@ -88,6 +88,8 @@
25144  #include <linux/proc_fs.h>
25145  #include <linux/seq_file.h>
25146  #include <linux/export.h>
25147 +#include <linux/vs_network.h>
25148 +#include <linux/vs_inet6.h>
25149  
25150  /* Set to 3 to get tracing... */
25151  #define ACONF_DEBUG 2
25152 @@ -1109,7 +1111,7 @@ out:
25153  
25154  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25155                        const struct in6_addr *daddr, unsigned int prefs,
25156 -                      struct in6_addr *saddr)
25157 +                      struct in6_addr *saddr, struct nx_info *nxi)
25158  {
25159         struct ipv6_saddr_score scores[2],
25160                                 *score = &scores[0], *hiscore = &scores[1];
25161 @@ -1181,6 +1183,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25162                                                dev->name);
25163                                 continue;
25164                         }
25165 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25166 +                               continue;
25167  
25168                         score->rule = -1;
25169                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25170 @@ -3153,7 +3157,10 @@ static void if6_seq_stop(struct seq_file
25171  static int if6_seq_show(struct seq_file *seq, void *v)
25172  {
25173         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25174 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25175 +
25176 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25177 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25178 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25179                    &ifp->addr,
25180                    ifp->idev->dev->ifindex,
25181                    ifp->prefix_len,
25182 @@ -3659,6 +3666,11 @@ static int in6_dump_addrs(struct inet6_d
25183         struct ifacaddr6 *ifaca;
25184         int err = 1;
25185         int ip_idx = *p_ip_idx;
25186 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25187 +
25188 +       /* disable ipv6 on non v6 guests */
25189 +       if (nxi && !nx_info_has_v6(nxi))
25190 +               return skb->len;
25191  
25192         read_lock_bh(&idev->lock);
25193         switch (type) {
25194 @@ -3669,6 +3681,8 @@ static int in6_dump_addrs(struct inet6_d
25195                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25196                         if (++ip_idx < s_ip_idx)
25197                                 continue;
25198 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25199 +                                       continue;
25200                         err = inet6_fill_ifaddr(skb, ifa,
25201                                                 NETLINK_CB(cb->skb).pid,
25202                                                 cb->nlh->nlmsg_seq,
25203 @@ -3685,6 +3699,8 @@ static int in6_dump_addrs(struct inet6_d
25204                      ifmca = ifmca->next, ip_idx++) {
25205                         if (ip_idx < s_ip_idx)
25206                                 continue;
25207 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25208 +                                       continue;
25209                         err = inet6_fill_ifmcaddr(skb, ifmca,
25210                                                   NETLINK_CB(cb->skb).pid,
25211                                                   cb->nlh->nlmsg_seq,
25212 @@ -3700,6 +3716,8 @@ static int in6_dump_addrs(struct inet6_d
25213                      ifaca = ifaca->aca_next, ip_idx++) {
25214                         if (ip_idx < s_ip_idx)
25215                                 continue;
25216 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25217 +                                       continue;
25218                         err = inet6_fill_ifacaddr(skb, ifaca,
25219                                                   NETLINK_CB(cb->skb).pid,
25220                                                   cb->nlh->nlmsg_seq,
25221 @@ -4085,6 +4103,11 @@ static int inet6_dump_ifinfo(struct sk_b
25222         struct inet6_dev *idev;
25223         struct hlist_head *head;
25224         struct hlist_node *node;
25225 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25226 +
25227 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25228 +       if (skb->sk && skb->sk->sk_vx_info)
25229 +               return skb->len; */
25230  
25231         s_h = cb->args[0];
25232         s_idx = cb->args[1];
25233 @@ -4096,6 +4119,8 @@ static int inet6_dump_ifinfo(struct sk_b
25234                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25235                         if (idx < s_idx)
25236                                 goto cont;
25237 +                       if (!v6_dev_in_nx_info(dev, nxi))
25238 +                               goto cont;
25239                         idev = __in6_dev_get(dev);
25240                         if (!idev)
25241                                 goto cont;
25242 diff -NurpP --minimal linux-3.2.5/net/ipv6/af_inet6.c linux-3.2.5-vs2.3.2.6/net/ipv6/af_inet6.c
25243 --- linux-3.2.5/net/ipv6/af_inet6.c     2011-10-24 18:45:34.000000000 +0200
25244 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/af_inet6.c   2011-12-05 19:33:02.000000000 +0100
25245 @@ -42,6 +42,8 @@
25246  #include <linux/netdevice.h>
25247  #include <linux/icmpv6.h>
25248  #include <linux/netfilter_ipv6.h>
25249 +#include <linux/vs_inet.h>
25250 +#include <linux/vs_inet6.h>
25251  
25252  #include <net/ip.h>
25253  #include <net/ipv6.h>
25254 @@ -160,9 +162,12 @@ lookup_protocol:
25255         }
25256  
25257         err = -EPERM;
25258 +       if ((protocol == IPPROTO_ICMPV6) &&
25259 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25260 +               goto override;
25261         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25262                 goto out_rcu_unlock;
25263 -
25264 +override:
25265         sock->ops = answer->ops;
25266         answer_prot = answer->prot;
25267         answer_no_check = answer->no_check;
25268 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25269         struct inet_sock *inet = inet_sk(sk);
25270         struct ipv6_pinfo *np = inet6_sk(sk);
25271         struct net *net = sock_net(sk);
25272 +       struct nx_v6_sock_addr nsa;
25273         __be32 v4addr = 0;
25274         unsigned short snum;
25275         int addr_type = 0;
25276 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25277         if (addr->sin6_family != AF_INET6)
25278                 return -EAFNOSUPPORT;
25279  
25280 +       err = v6_map_sock_addr(inet, addr, &nsa);
25281 +       if (err)
25282 +               return err;
25283 +
25284         addr_type = ipv6_addr_type(&addr->sin6_addr);
25285         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25286                 return -EINVAL;
25287 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25288                 /* Reproduce AF_INET checks to make the bindings consistent */
25289                 v4addr = addr->sin6_addr.s6_addr32[3];
25290                 chk_addr_ret = inet_addr_type(net, v4addr);
25291 +
25292                 if (!sysctl_ip_nonlocal_bind &&
25293                     !(inet->freebind || inet->transparent) &&
25294                     v4addr != htonl(INADDR_ANY) &&
25295 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25296                         err = -EADDRNOTAVAIL;
25297                         goto out;
25298                 }
25299 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25300 +                       err = -EADDRNOTAVAIL;
25301 +                       goto out;
25302 +               }
25303         } else {
25304                 if (addr_type != IPV6_ADDR_ANY) {
25305                         struct net_device *dev = NULL;
25306 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25307                                 }
25308                         }
25309  
25310 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25311 +                               err = -EADDRNOTAVAIL;
25312 +                               goto out;
25313 +                       }
25314 +
25315                         /* ipv4 addr of the socket is invalid.  Only the
25316                          * unspecified and mapped address have a v4 equivalent.
25317                          */
25318 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25319                 }
25320         }
25321  
25322 +       /* what's that for? */
25323 +       v6_set_sock_addr(inet, &nsa);
25324 +
25325         inet->inet_rcv_saddr = v4addr;
25326         inet->inet_saddr = v4addr;
25327  
25328 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25329                         return -ENOTCONN;
25330                 sin->sin6_port = inet->inet_dport;
25331                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25332 +               /* FIXME: remap lback? */
25333                 if (np->sndflow)
25334                         sin->sin6_flowinfo = np->flow_label;
25335         } else {
25336 +               /* FIXME: remap lback? */
25337                 if (ipv6_addr_any(&np->rcv_saddr))
25338                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25339                 else
25340 diff -NurpP --minimal linux-3.2.5/net/ipv6/datagram.c linux-3.2.5-vs2.3.2.6/net/ipv6/datagram.c
25341 --- linux-3.2.5/net/ipv6/datagram.c     2012-01-09 16:15:04.000000000 +0100
25342 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/datagram.c   2011-12-05 19:33:02.000000000 +0100
25343 @@ -642,7 +642,7 @@ int datagram_send_ctl(struct net *net, s
25344  
25345                         rcu_read_lock();
25346                         if (fl6->flowi6_oif) {
25347 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25348 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25349                                 if (!dev) {
25350                                         rcu_read_unlock();
25351                                         return -ENODEV;
25352 diff -NurpP --minimal linux-3.2.5/net/ipv6/fib6_rules.c linux-3.2.5-vs2.3.2.6/net/ipv6/fib6_rules.c
25353 --- linux-3.2.5/net/ipv6/fib6_rules.c   2012-01-09 16:15:04.000000000 +0100
25354 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/fib6_rules.c 2011-12-05 19:33:02.000000000 +0100
25355 @@ -91,7 +91,7 @@ static int fib6_rule_action(struct fib_r
25356                                                ip6_dst_idev(&rt->dst)->dev,
25357                                                &flp6->daddr,
25358                                                rt6_flags2srcprefs(flags),
25359 -                                              &saddr))
25360 +                                              &saddr, NULL))
25361                                 goto again;
25362                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25363                                                r->src.plen))
25364 diff -NurpP --minimal linux-3.2.5/net/ipv6/inet6_hashtables.c linux-3.2.5-vs2.3.2.6/net/ipv6/inet6_hashtables.c
25365 --- linux-3.2.5/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25366 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/inet6_hashtables.c   2011-12-05 19:33:02.000000000 +0100
25367 @@ -16,6 +16,7 @@
25368  
25369  #include <linux/module.h>
25370  #include <linux/random.h>
25371 +#include <linux/vs_inet6.h>
25372  
25373  #include <net/inet_connection_sock.h>
25374  #include <net/inet_hashtables.h>
25375 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25376         unsigned int slot = hash & hashinfo->ehash_mask;
25377         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25378  
25379 -
25380         rcu_read_lock();
25381  begin:
25382         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25383 @@ -95,7 +95,7 @@ begin:
25384                                 sock_put(sk);
25385                                 goto begin;
25386                         }
25387 -               goto out;
25388 +                       goto out;
25389                 }
25390         }
25391         if (get_nulls_value(node) != slot)
25392 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25393                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25394                                 return -1;
25395                         score++;
25396 +               } else {
25397 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25398 +                               return -1;
25399                 }
25400                 if (sk->sk_bound_dev_if) {
25401                         if (sk->sk_bound_dev_if != dif)
25402 diff -NurpP --minimal linux-3.2.5/net/ipv6/ip6_output.c linux-3.2.5-vs2.3.2.6/net/ipv6/ip6_output.c
25403 --- linux-3.2.5/net/ipv6/ip6_output.c   2012-01-09 16:15:04.000000000 +0100
25404 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/ip6_output.c 2012-01-09 16:19:31.000000000 +0100
25405 @@ -963,7 +963,8 @@ static int ip6_dst_lookup_tail(struct so
25406                 struct rt6_info *rt = (struct rt6_info *) *dst;
25407                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25408                                           sk ? inet6_sk(sk)->srcprefs : 0,
25409 -                                         &fl6->saddr);
25410 +                                         &fl6->saddr,
25411 +                                         sk ? sk->sk_nx_info : NULL);
25412                 if (err)
25413                         goto out_err_release;
25414         }
25415 diff -NurpP --minimal linux-3.2.5/net/ipv6/ndisc.c linux-3.2.5-vs2.3.2.6/net/ipv6/ndisc.c
25416 --- linux-3.2.5/net/ipv6/ndisc.c        2012-01-09 16:15:04.000000000 +0100
25417 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/ndisc.c      2011-12-15 01:11:37.000000000 +0100
25418 @@ -588,7 +588,7 @@ static void ndisc_send_na(struct net_dev
25419         } else {
25420                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25421                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25422 -                                      &tmpaddr))
25423 +                                      &tmpaddr, NULL))
25424                         return;
25425                 src_addr = &tmpaddr;
25426         }
25427 diff -NurpP --minimal linux-3.2.5/net/ipv6/raw.c linux-3.2.5-vs2.3.2.6/net/ipv6/raw.c
25428 --- linux-3.2.5/net/ipv6/raw.c  2012-02-07 01:57:55.000000000 +0100
25429 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/raw.c        2012-02-07 03:14:01.000000000 +0100
25430 @@ -30,6 +30,7 @@
25431  #include <linux/icmpv6.h>
25432  #include <linux/netfilter.h>
25433  #include <linux/netfilter_ipv6.h>
25434 +#include <linux/vs_inet6.h>
25435  #include <linux/skbuff.h>
25436  #include <linux/compat.h>
25437  #include <asm/uaccess.h>
25438 @@ -285,6 +286,13 @@ static int rawv6_bind(struct sock *sk, s
25439                                 goto out_unlock;
25440                 }
25441  
25442 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25443 +                       err = -EADDRNOTAVAIL;
25444 +                       if (dev)
25445 +                               dev_put(dev);
25446 +                       goto out;
25447 +               }
25448 +
25449                 /* ipv4 addr of the socket is invalid.  Only the
25450                  * unspecified and mapped address have a v4 equivalent.
25451                  */
25452 diff -NurpP --minimal linux-3.2.5/net/ipv6/route.c linux-3.2.5-vs2.3.2.6/net/ipv6/route.c
25453 --- linux-3.2.5/net/ipv6/route.c        2012-01-09 16:15:04.000000000 +0100
25454 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/route.c      2012-01-09 16:19:31.000000000 +0100
25455 @@ -55,6 +55,7 @@
25456  #include <net/xfrm.h>
25457  #include <net/netevent.h>
25458  #include <net/netlink.h>
25459 +#include <linux/vs_inet6.h>
25460  
25461  #include <asm/uaccess.h>
25462  
25463 @@ -2093,15 +2094,17 @@ int ip6_route_get_saddr(struct net *net,
25464                         struct rt6_info *rt,
25465                         const struct in6_addr *daddr,
25466                         unsigned int prefs,
25467 -                       struct in6_addr *saddr)
25468 +                       struct in6_addr *saddr,
25469 +                       struct nx_info *nxi)
25470  {
25471         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25472         int err = 0;
25473 -       if (rt->rt6i_prefsrc.plen)
25474 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25475 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25476                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25477         else
25478                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25479 -                                        daddr, prefs, saddr);
25480 +                                        daddr, prefs, saddr, nxi);
25481         return err;
25482  }
25483  
25484 @@ -2431,7 +2434,8 @@ static int rt6_fill_node(struct net *net
25485                         NLA_PUT_U32(skb, RTA_IIF, iif);
25486         } else if (dst) {
25487                 struct in6_addr saddr_buf;
25488 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25489 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25490 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25491                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25492         }
25493  
25494 @@ -2634,6 +2638,7 @@ static int rt6_info_route(struct rt6_inf
25495         struct seq_file *m = p_arg;
25496         struct neighbour *n;
25497  
25498 +       /* FIXME: check for network context? */
25499         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25500  
25501  #ifdef CONFIG_IPV6_SUBTREES
25502 diff -NurpP --minimal linux-3.2.5/net/ipv6/tcp_ipv6.c linux-3.2.5-vs2.3.2.6/net/ipv6/tcp_ipv6.c
25503 --- linux-3.2.5/net/ipv6/tcp_ipv6.c     2012-02-07 01:57:55.000000000 +0100
25504 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/tcp_ipv6.c   2012-02-07 03:14:01.000000000 +0100
25505 @@ -70,6 +70,7 @@
25506  
25507  #include <linux/crypto.h>
25508  #include <linux/scatterlist.h>
25509 +#include <linux/vs_inet6.h>
25510  
25511  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25512  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25513 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
25514          *      connect() to INADDR_ANY means loopback (BSD'ism).
25515          */
25516  
25517 -       if(ipv6_addr_any(&usin->sin6_addr))
25518 -               usin->sin6_addr.s6_addr[15] = 0x1;
25519 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25520 +               struct nx_info *nxi =  sk->sk_nx_info;
25521 +
25522 +               if (nxi && nx_info_has_v6(nxi))
25523 +                       /* FIXME: remap lback? */
25524 +                       usin->sin6_addr = nxi->v6.ip;
25525 +               else
25526 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25527 +       }
25528  
25529         addr_type = ipv6_addr_type(&usin->sin6_addr);
25530  
25531 diff -NurpP --minimal linux-3.2.5/net/ipv6/udp.c linux-3.2.5-vs2.3.2.6/net/ipv6/udp.c
25532 --- linux-3.2.5/net/ipv6/udp.c  2012-01-09 16:15:04.000000000 +0100
25533 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/udp.c        2011-12-15 01:11:37.000000000 +0100
25534 @@ -45,41 +45,67 @@
25535  #include <net/tcp_states.h>
25536  #include <net/ip6_checksum.h>
25537  #include <net/xfrm.h>
25538 +#include <linux/vs_inet6.h>
25539  
25540  #include <linux/proc_fs.h>
25541  #include <linux/seq_file.h>
25542  #include "udp_impl.h"
25543  
25544 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25545 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25546  {
25547 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25548 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25549         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25550 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25551 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25552         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25553 -       int sk_ipv6only = ipv6_only_sock(sk);
25554 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25555         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25556 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25557 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25558         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25559  
25560         /* if both are mapped, treat as IPv4 */
25561 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25562 -               return (!sk2_ipv6only &&
25563 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25564 +               if (!sk2_ipv6only &&
25565                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25566 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25567 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25568 +                       goto vs_v4;
25569 +               else
25570 +                       return 0;
25571 +       }
25572  
25573         if (addr_type2 == IPV6_ADDR_ANY &&
25574             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25575 -               return 1;
25576 +               goto vs;
25577  
25578         if (addr_type == IPV6_ADDR_ANY &&
25579 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25580 -               return 1;
25581 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25582 +               goto vs;
25583  
25584         if (sk2_rcv_saddr6 &&
25585 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25586 -               return 1;
25587 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25588 +               goto vs;
25589  
25590         return 0;
25591 +
25592 +vs_v4:
25593 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25594 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25595 +       if (!sk2_rcv_saddr)
25596 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25597 +       if (!sk1_rcv_saddr)
25598 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25599 +       return 1;
25600 +vs:
25601 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25602 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25603 +       else if (addr_type2 == IPV6_ADDR_ANY)
25604 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25605 +       else if (addr_type == IPV6_ADDR_ANY) {
25606 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25607 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25608 +               else
25609 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25610 +       }
25611 +       return 1;
25612  }
25613  
25614  static unsigned int udp6_portaddr_hash(struct net *net,
25615 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25616                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25617                                 return -1;
25618                         score++;
25619 +               } else {
25620 +                       /* block non nx_info ips */
25621 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25622 +                               return -1;
25623                 }
25624                 if (!ipv6_addr_any(&np->daddr)) {
25625                         if (!ipv6_addr_equal(&np->daddr, saddr))
25626 diff -NurpP --minimal linux-3.2.5/net/ipv6/xfrm6_policy.c linux-3.2.5-vs2.3.2.6/net/ipv6/xfrm6_policy.c
25627 --- linux-3.2.5/net/ipv6/xfrm6_policy.c 2011-07-22 11:18:13.000000000 +0200
25628 +++ linux-3.2.5-vs2.3.2.6/net/ipv6/xfrm6_policy.c       2011-12-05 19:33:02.000000000 +0100
25629 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25630         dev = ip6_dst_idev(dst)->dev;
25631         ipv6_dev_get_saddr(dev_net(dev), dev,
25632                            (struct in6_addr *)&daddr->a6, 0,
25633 -                          (struct in6_addr *)&saddr->a6);
25634 +                          (struct in6_addr *)&saddr->a6, NULL);
25635         dst_release(dst);
25636         return 0;
25637  }
25638 diff -NurpP --minimal linux-3.2.5/net/netfilter/ipvs/ip_vs_xmit.c linux-3.2.5-vs2.3.2.6/net/netfilter/ipvs/ip_vs_xmit.c
25639 --- linux-3.2.5/net/netfilter/ipvs/ip_vs_xmit.c 2012-01-09 16:15:04.000000000 +0100
25640 +++ linux-3.2.5-vs2.3.2.6/net/netfilter/ipvs/ip_vs_xmit.c       2012-02-07 03:13:38.000000000 +0100
25641 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25642                 return dst;
25643         if (ipv6_addr_any(&fl6.saddr) &&
25644             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25645 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25646 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25647                 goto out_err;
25648         if (do_xfrm) {
25649                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25650 diff -NurpP --minimal linux-3.2.5/net/netlink/af_netlink.c linux-3.2.5-vs2.3.2.6/net/netlink/af_netlink.c
25651 --- linux-3.2.5/net/netlink/af_netlink.c        2012-01-09 16:15:04.000000000 +0100
25652 +++ linux-3.2.5-vs2.3.2.6/net/netlink/af_netlink.c      2011-12-05 19:33:02.000000000 +0100
25653 @@ -55,6 +55,9 @@
25654  #include <linux/types.h>
25655  #include <linux/audit.h>
25656  #include <linux/mutex.h>
25657 +#include <linux/vs_context.h>
25658 +#include <linux/vs_network.h>
25659 +#include <linux/vs_limit.h>
25660  
25661  #include <net/net_namespace.h>
25662  #include <net/sock.h>
25663 @@ -1912,6 +1915,8 @@ static struct sock *netlink_seq_socket_i
25664                         sk_for_each(s, node, &hash->table[j]) {
25665                                 if (sock_net(s) != seq_file_net(seq))
25666                                         continue;
25667 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25668 +                                       continue;
25669                                 if (off == pos) {
25670                                         iter->link = i;
25671                                         iter->hash_idx = j;
25672 @@ -1946,7 +1951,8 @@ static void *netlink_seq_next(struct seq
25673         s = v;
25674         do {
25675                 s = sk_next(s);
25676 -       } while (s && sock_net(s) != seq_file_net(seq));
25677 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25678 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25679         if (s)
25680                 return s;
25681  
25682 @@ -1958,7 +1964,8 @@ static void *netlink_seq_next(struct seq
25683  
25684                 for (; j <= hash->mask; j++) {
25685                         s = sk_head(&hash->table[j]);
25686 -                       while (s && sock_net(s) != seq_file_net(seq))
25687 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25688 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25689                                 s = sk_next(s);
25690                         if (s) {
25691                                 iter->link = i;
25692 diff -NurpP --minimal linux-3.2.5/net/socket.c linux-3.2.5-vs2.3.2.6/net/socket.c
25693 --- linux-3.2.5/net/socket.c    2012-02-07 01:57:55.000000000 +0100
25694 +++ linux-3.2.5-vs2.3.2.6/net/socket.c  2012-02-07 03:14:01.000000000 +0100
25695 @@ -98,6 +98,10 @@
25696  
25697  #include <net/sock.h>
25698  #include <linux/netfilter.h>
25699 +#include <linux/vs_base.h>
25700 +#include <linux/vs_socket.h>
25701 +#include <linux/vs_inet.h>
25702 +#include <linux/vs_inet6.h>
25703  
25704  #include <linux/if_tun.h>
25705  #include <linux/ipv6_route.h>
25706 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
25707                                        struct msghdr *msg, size_t size)
25708  {
25709         struct sock_iocb *si = kiocb_to_siocb(iocb);
25710 +       size_t len;
25711  
25712         sock_update_classid(sock->sk);
25713  
25714 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
25715         si->msg = msg;
25716         si->size = size;
25717  
25718 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25719 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25720 +       if (sock->sk) {
25721 +               if (len == size)
25722 +                       vx_sock_send(sock->sk, size);
25723 +               else
25724 +                       vx_sock_fail(sock->sk, size);
25725 +       }
25726 +       vxdprintk(VXD_CBIT(net, 7),
25727 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25728 +               sock, sock->sk,
25729 +               (sock->sk)?sock->sk->sk_nx_info:0,
25730 +               (sock->sk)?sock->sk->sk_vx_info:0,
25731 +               (sock->sk)?sock->sk->sk_xid:0,
25732 +               (sock->sk)?sock->sk->sk_nid:0,
25733 +               (unsigned int)size, len);
25734 +       return len;
25735  }
25736  
25737  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25738 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
25739                                        struct msghdr *msg, size_t size, int flags)
25740  {
25741         struct sock_iocb *si = kiocb_to_siocb(iocb);
25742 +       int len;
25743  
25744         sock_update_classid(sock->sk);
25745  
25746 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
25747         si->size = size;
25748         si->flags = flags;
25749  
25750 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25751 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25752 +       if ((len >= 0) && sock->sk)
25753 +               vx_sock_recv(sock->sk, len);
25754 +       vxdprintk(VXD_CBIT(net, 7),
25755 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25756 +               sock, sock->sk,
25757 +               (sock->sk)?sock->sk->sk_nx_info:0,
25758 +               (sock->sk)?sock->sk->sk_vx_info:0,
25759 +               (sock->sk)?sock->sk->sk_xid:0,
25760 +               (sock->sk)?sock->sk->sk_nid:0,
25761 +               (unsigned int)size, len);
25762 +       return len;
25763  }
25764  
25765  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25766 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
25767         if (type < 0 || type >= SOCK_MAX)
25768                 return -EINVAL;
25769  
25770 +       if (!nx_check(0, VS_ADMIN)) {
25771 +               if (family == PF_INET && !current_nx_info_has_v4())
25772 +                       return -EAFNOSUPPORT;
25773 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25774 +                       return -EAFNOSUPPORT;
25775 +       }
25776 +
25777         /* Compatibility.
25778  
25779            This uglymoron is moved from INET layer to here to avoid
25780 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25781         if (retval < 0)
25782                 goto out;
25783  
25784 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25785         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25786         if (retval < 0)
25787                 goto out_release;
25788 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25789         err = sock_create(family, type, protocol, &sock1);
25790         if (err < 0)
25791                 goto out;
25792 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25793  
25794         err = sock_create(family, type, protocol, &sock2);
25795         if (err < 0)
25796                 goto out_release_1;
25797 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25798  
25799         err = sock1->ops->socketpair(sock1, sock2);
25800         if (err < 0)
25801 diff -NurpP --minimal linux-3.2.5/net/sunrpc/auth.c linux-3.2.5-vs2.3.2.6/net/sunrpc/auth.c
25802 --- linux-3.2.5/net/sunrpc/auth.c       2011-10-24 18:45:34.000000000 +0200
25803 +++ linux-3.2.5-vs2.3.2.6/net/sunrpc/auth.c     2011-12-05 19:33:02.000000000 +0100
25804 @@ -14,6 +14,7 @@
25805  #include <linux/hash.h>
25806  #include <linux/sunrpc/clnt.h>
25807  #include <linux/spinlock.h>
25808 +#include <linux/vs_tag.h>
25809  
25810  #ifdef RPC_DEBUG
25811  # define RPCDBG_FACILITY       RPCDBG_AUTH
25812 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25813         memset(&acred, 0, sizeof(acred));
25814         acred.uid = cred->fsuid;
25815         acred.gid = cred->fsgid;
25816 +       acred.tag = dx_current_tag();
25817         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25818  
25819         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25820 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25821         struct auth_cred acred = {
25822                 .uid = 0,
25823                 .gid = 0,
25824 +               .tag = dx_current_tag(),
25825         };
25826  
25827         dprintk("RPC: %5u looking up %s cred\n",
25828 diff -NurpP --minimal linux-3.2.5/net/sunrpc/auth_unix.c linux-3.2.5-vs2.3.2.6/net/sunrpc/auth_unix.c
25829 --- linux-3.2.5/net/sunrpc/auth_unix.c  2012-01-09 16:15:04.000000000 +0100
25830 +++ linux-3.2.5-vs2.3.2.6/net/sunrpc/auth_unix.c        2011-12-05 19:33:02.000000000 +0100
25831 @@ -12,12 +12,14 @@
25832  #include <linux/module.h>
25833  #include <linux/sunrpc/clnt.h>
25834  #include <linux/sunrpc/auth.h>
25835 +#include <linux/vs_tag.h>
25836  
25837  #define NFS_NGROUPS    16
25838  
25839  struct unx_cred {
25840         struct rpc_cred         uc_base;
25841         gid_t                   uc_gid;
25842 +       tag_t                   uc_tag;
25843         gid_t                   uc_gids[NFS_NGROUPS];
25844  };
25845  #define uc_uid                 uc_base.cr_uid
25846 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
25847                 groups = NFS_NGROUPS;
25848  
25849         cred->uc_gid = acred->gid;
25850 +       cred->uc_tag = acred->tag;
25851         for (i = 0; i < groups; i++)
25852                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25853         if (i < NFS_NGROUPS)
25854 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
25855         unsigned int i;
25856  
25857  
25858 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25859 +       if (cred->uc_uid != acred->uid ||
25860 +               cred->uc_gid != acred->gid ||
25861 +               cred->uc_tag != acred->tag)
25862                 return 0;
25863  
25864         if (acred->group_info != NULL)
25865 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
25866         struct rpc_clnt *clnt = task->tk_client;
25867         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25868         __be32          *base, *hold;
25869 -       int             i;
25870 +       int             i, tag;
25871  
25872         *p++ = htonl(RPC_AUTH_UNIX);
25873         base = p++;
25874 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
25875          * Copy the UTS nodename captured when the client was created.
25876          */
25877         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25878 +       tag = task->tk_client->cl_tag;
25879  
25880 -       *p++ = htonl((u32) cred->uc_uid);
25881 -       *p++ = htonl((u32) cred->uc_gid);
25882 +       *p++ = htonl((u32) TAGINO_UID(tag,
25883 +               cred->uc_uid, cred->uc_tag));
25884 +       *p++ = htonl((u32) TAGINO_GID(tag,
25885 +               cred->uc_gid, cred->uc_tag));
25886         hold = p++;
25887         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25888                 *p++ = htonl((u32) cred->uc_gids[i]);
25889 diff -NurpP --minimal linux-3.2.5/net/sunrpc/clnt.c linux-3.2.5-vs2.3.2.6/net/sunrpc/clnt.c
25890 --- linux-3.2.5/net/sunrpc/clnt.c       2012-01-09 16:15:04.000000000 +0100
25891 +++ linux-3.2.5-vs2.3.2.6/net/sunrpc/clnt.c     2011-12-05 19:33:02.000000000 +0100
25892 @@ -31,6 +31,7 @@
25893  #include <linux/in.h>
25894  #include <linux/in6.h>
25895  #include <linux/un.h>
25896 +#include <linux/vs_cvirt.h>
25897  
25898  #include <linux/sunrpc/clnt.h>
25899  #include <linux/sunrpc/rpc_pipe_fs.h>
25900 @@ -361,6 +362,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25901         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25902                 clnt->cl_chatty = 1;
25903  
25904 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25905 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25906 +               clnt->cl_tag = 1; */
25907         return clnt;
25908  }
25909  EXPORT_SYMBOL_GPL(rpc_create);
25910 diff -NurpP --minimal linux-3.2.5/net/unix/af_unix.c linux-3.2.5-vs2.3.2.6/net/unix/af_unix.c
25911 --- linux-3.2.5/net/unix/af_unix.c      2012-02-07 01:57:55.000000000 +0100
25912 +++ linux-3.2.5-vs2.3.2.6/net/unix/af_unix.c    2012-02-07 03:14:01.000000000 +0100
25913 @@ -114,6 +114,8 @@
25914  #include <linux/mount.h>
25915  #include <net/checksum.h>
25916  #include <linux/security.h>
25917 +#include <linux/vs_context.h>
25918 +#include <linux/vs_limit.h>
25919  
25920  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
25921  static DEFINE_SPINLOCK(unix_table_lock);
25922 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
25923                 if (!net_eq(sock_net(s), net))
25924                         continue;
25925  
25926 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25927 +                       continue;
25928                 if (u->addr->len == len &&
25929                     !memcmp(u->addr->name, sunname, len))
25930                         goto found;
25931 @@ -2219,6 +2223,8 @@ static struct sock *unix_seq_idx(struct 
25932         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
25933                 if (sock_net(s) != seq_file_net(seq))
25934                         continue;
25935 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25936 +                       continue;
25937                 if (off == pos)
25938                         return s;
25939                 ++off;
25940 @@ -2243,7 +2249,8 @@ static void *unix_seq_next(struct seq_fi
25941                 sk = first_unix_socket(&iter->i);
25942         else
25943                 sk = next_unix_socket(&iter->i, sk);
25944 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
25945 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
25946 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
25947                 sk = next_unix_socket(&iter->i, sk);
25948         return sk;
25949  }
25950 diff -NurpP --minimal linux-3.2.5/scripts/checksyscalls.sh linux-3.2.5-vs2.3.2.6/scripts/checksyscalls.sh
25951 --- linux-3.2.5/scripts/checksyscalls.sh        2011-03-15 18:07:46.000000000 +0100
25952 +++ linux-3.2.5-vs2.3.2.6/scripts/checksyscalls.sh      2011-12-05 19:33:02.000000000 +0100
25953 @@ -193,7 +193,6 @@ cat << EOF
25954  #define __IGNORE_afs_syscall
25955  #define __IGNORE_getpmsg
25956  #define __IGNORE_putpmsg
25957 -#define __IGNORE_vserver
25958  EOF
25959  }
25960  
25961 diff -NurpP --minimal linux-3.2.5/security/commoncap.c linux-3.2.5-vs2.3.2.6/security/commoncap.c
25962 --- linux-3.2.5/security/commoncap.c    2012-01-09 16:15:05.000000000 +0100
25963 +++ linux-3.2.5-vs2.3.2.6/security/commoncap.c  2011-12-05 19:33:02.000000000 +0100
25964 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
25965                 return -EPERM;
25966         return 0;
25967  }
25968 +
25969  EXPORT_SYMBOL(cap_netlink_recv);
25970  
25971  /**
25972 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
25973  int cap_capable(struct task_struct *tsk, const struct cred *cred,
25974                 struct user_namespace *targ_ns, int cap, int audit)
25975  {
25976 +       struct vx_info *vxi = tsk->vx_info;
25977 +
25978         for (;;) {
25979                 /* The creator of the user namespace has all caps. */
25980                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
25981                         return 0;
25982  
25983                 /* Do we have the necessary capabilities? */
25984 -               if (targ_ns == cred->user->user_ns)
25985 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25986 +               if (targ_ns == cred->user->user_ns) {
25987 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25988 +                           cap_raised(cred->cap_effective, cap))
25989 +                               return 0;
25990 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25991 +               }
25992  
25993                 /* Have we tried all of the parent namespaces? */
25994                 if (targ_ns == &init_user_ns)
25995 @@ -615,7 +622,7 @@ int cap_inode_setxattr(struct dentry *de
25996  
25997         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25998                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25999 -           !capable(CAP_SYS_ADMIN))
26000 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26001                 return -EPERM;
26002         return 0;
26003  }
26004 @@ -641,7 +648,7 @@ int cap_inode_removexattr(struct dentry 
26005  
26006         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26007                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26008 -           !capable(CAP_SYS_ADMIN))
26009 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26010                 return -EPERM;
26011         return 0;
26012  }
26013 diff -NurpP --minimal linux-3.2.5/security/selinux/hooks.c linux-3.2.5-vs2.3.2.6/security/selinux/hooks.c
26014 --- linux-3.2.5/security/selinux/hooks.c        2012-01-09 16:15:05.000000000 +0100
26015 +++ linux-3.2.5-vs2.3.2.6/security/selinux/hooks.c      2011-12-05 19:33:02.000000000 +0100
26016 @@ -67,7 +67,6 @@
26017  #include <linux/dccp.h>
26018  #include <linux/quota.h>
26019  #include <linux/un.h>          /* for Unix socket types */
26020 -#include <net/af_unix.h>       /* for Unix socket types */
26021  #include <linux/parser.h>
26022  #include <linux/nfs_mount.h>
26023  #include <net/ipv6.h>
This page took 2.245319 seconds and 4 git commands to generate.