]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.3.1; updated vserver patch to vs2.3.3.2; drop scsi workaround
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.3.1/Documentation/vserver/debug.txt linux-3.3.1-vs2.3.3.2/Documentation/vserver/debug.txt
2 --- linux-3.3.1/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.3.1-vs2.3.3.2/Documentation/vserver/debug.txt       2012-02-24 03:55:06.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.3.1/arch/alpha/Kconfig linux-3.3.1-vs2.3.3.2/arch/alpha/Kconfig
160 --- linux-3.3.1/arch/alpha/Kconfig      2012-03-19 19:46:27.000000000 +0100
161 +++ linux-3.3.1-vs2.3.3.2/arch/alpha/Kconfig    2012-02-24 03:55:06.000000000 +0100
162 @@ -662,6 +662,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.3.1/arch/alpha/kernel/entry.S linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/entry.S
172 --- linux-3.3.1/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/entry.S     2012-02-24 03:55:06.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.3.1/arch/alpha/kernel/ptrace.c linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/ptrace.c
207 --- linux-3.3.1/arch/alpha/kernel/ptrace.c      2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/ptrace.c    2012-02-24 03:55:06.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.3.1/arch/alpha/kernel/systbls.S linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/systbls.S
218 --- linux-3.3.1/arch/alpha/kernel/systbls.S     2012-01-09 16:13:54.000000000 +0100
219 +++ linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/systbls.S   2012-02-24 03:55:06.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.3.1/arch/alpha/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/traps.c
230 --- linux-3.3.1/arch/alpha/kernel/traps.c       2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.3.1-vs2.3.3.2/arch/alpha/kernel/traps.c     2012-02-24 03:55:06.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.3.1/arch/arm/Kconfig linux-3.3.1-vs2.3.3.2/arch/arm/Kconfig
243 --- linux-3.3.1/arch/arm/Kconfig        2012-03-19 19:46:27.000000000 +0100
244 +++ linux-3.3.1-vs2.3.3.2/arch/arm/Kconfig      2012-03-19 20:52:09.000000000 +0100
245 @@ -2266,6 +2266,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.3.1/arch/arm/kernel/calls.S linux-3.3.1-vs2.3.3.2/arch/arm/kernel/calls.S
255 --- linux-3.3.1/arch/arm/kernel/calls.S 2012-01-09 16:13:54.000000000 +0100
256 +++ linux-3.3.1-vs2.3.3.2/arch/arm/kernel/calls.S       2012-02-24 03:55:06.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.3.1/arch/arm/kernel/process.c linux-3.3.1-vs2.3.3.2/arch/arm/kernel/process.c
267 --- linux-3.3.1/arch/arm/kernel/process.c       2012-03-19 19:46:28.000000000 +0100
268 +++ linux-3.3.1-vs2.3.3.2/arch/arm/kernel/process.c     2012-02-24 03:55:06.000000000 +0100
269 @@ -353,7 +353,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.3.1/arch/arm/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/arm/kernel/traps.c
280 --- linux-3.3.1/arch/arm/kernel/traps.c 2012-03-19 19:46:28.000000000 +0100
281 +++ linux-3.3.1-vs2.3.3.2/arch/arm/kernel/traps.c       2012-02-24 03:55:06.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.3.1/arch/cris/Kconfig linux-3.3.1-vs2.3.3.2/arch/cris/Kconfig
294 --- linux-3.3.1/arch/cris/Kconfig       2012-03-19 19:46:39.000000000 +0100
295 +++ linux-3.3.1-vs2.3.3.2/arch/cris/Kconfig     2012-02-24 03:55:06.000000000 +0100
296 @@ -675,6 +675,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.3.1/arch/frv/kernel/kernel_thread.S linux-3.3.1-vs2.3.3.2/arch/frv/kernel/kernel_thread.S
306 --- linux-3.3.1/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.3.1-vs2.3.3.2/arch/frv/kernel/kernel_thread.S       2012-02-24 03:55:06.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.3.1/arch/h8300/Kconfig linux-3.3.1-vs2.3.3.2/arch/h8300/Kconfig
318 --- linux-3.3.1/arch/h8300/Kconfig      2012-03-19 19:46:39.000000000 +0100
319 +++ linux-3.3.1-vs2.3.3.2/arch/h8300/Kconfig    2012-02-24 03:55:06.000000000 +0100
320 @@ -214,6 +214,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.3.1/arch/ia64/Kconfig linux-3.3.1-vs2.3.3.2/arch/ia64/Kconfig
330 --- linux-3.3.1/arch/ia64/Kconfig       2012-03-19 19:46:39.000000000 +0100
331 +++ linux-3.3.1-vs2.3.3.2/arch/ia64/Kconfig     2012-02-24 03:55:06.000000000 +0100
332 @@ -654,6 +654,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.3.1/arch/ia64/kernel/entry.S linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/entry.S
342 --- linux-3.3.1/arch/ia64/kernel/entry.S        2012-03-19 19:46:40.000000000 +0100
343 +++ linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/entry.S      2012-02-24 03:55:06.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.3.1/arch/ia64/kernel/process.c linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/process.c
354 --- linux-3.3.1/arch/ia64/kernel/process.c      2011-03-15 18:06:39.000000000 +0100
355 +++ linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/process.c    2012-02-24 03:55:06.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.3.1/arch/ia64/kernel/ptrace.c linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/ptrace.c
368 --- linux-3.3.1/arch/ia64/kernel/ptrace.c       2012-03-19 19:46:40.000000000 +0100
369 +++ linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/ptrace.c     2012-02-24 03:55:06.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.3.1/arch/ia64/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/traps.c
379 --- linux-3.3.1/arch/ia64/kernel/traps.c        2010-07-07 18:31:01.000000000 +0200
380 +++ linux-3.3.1-vs2.3.3.2/arch/ia64/kernel/traps.c      2012-02-24 03:55:06.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.3.1/arch/m32r/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/m32r/kernel/traps.c
406 --- linux-3.3.1/arch/m32r/kernel/traps.c        2011-10-24 18:44:58.000000000 +0200
407 +++ linux-3.3.1-vs2.3.3.2/arch/m32r/kernel/traps.c      2012-02-24 03:55:06.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.3.1/arch/m68k/Kconfig linux-3.3.1-vs2.3.3.2/arch/m68k/Kconfig
421 --- linux-3.3.1/arch/m68k/Kconfig       2012-03-19 19:46:40.000000000 +0100
422 +++ linux-3.3.1-vs2.3.3.2/arch/m68k/Kconfig     2012-02-24 03:55:06.000000000 +0100
423 @@ -145,6 +145,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.3.1/arch/mips/Kconfig linux-3.3.1-vs2.3.3.2/arch/mips/Kconfig
433 --- linux-3.3.1/arch/mips/Kconfig       2012-03-19 19:46:41.000000000 +0100
434 +++ linux-3.3.1-vs2.3.3.2/arch/mips/Kconfig     2012-02-24 03:55:06.000000000 +0100
435 @@ -2514,6 +2514,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.3.1/arch/mips/kernel/ptrace.c linux-3.3.1-vs2.3.3.2/arch/mips/kernel/ptrace.c
445 --- linux-3.3.1/arch/mips/kernel/ptrace.c       2012-03-19 19:46:43.000000000 +0100
446 +++ linux-3.3.1-vs2.3.3.2/arch/mips/kernel/ptrace.c     2012-02-24 03:55:06.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.3.1/arch/mips/kernel/scall32-o32.S linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall32-o32.S
466 --- linux-3.3.1/arch/mips/kernel/scall32-o32.S  2012-01-09 16:14:05.000000000 +0100
467 +++ linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall32-o32.S        2012-02-24 03:55:06.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.3.1/arch/mips/kernel/scall64-64.S linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall64-64.S
478 --- linux-3.3.1/arch/mips/kernel/scall64-64.S   2012-01-09 16:14:05.000000000 +0100
479 +++ linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall64-64.S 2012-02-24 03:55:06.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.3.1/arch/mips/kernel/scall64-n32.S linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall64-n32.S
490 --- linux-3.3.1/arch/mips/kernel/scall64-n32.S  2012-01-09 16:14:05.000000000 +0100
491 +++ linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall64-n32.S        2012-02-24 03:55:06.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.3.1/arch/mips/kernel/scall64-o32.S linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall64-o32.S
502 --- linux-3.3.1/arch/mips/kernel/scall64-o32.S  2012-01-09 16:14:05.000000000 +0100
503 +++ linux-3.3.1-vs2.3.3.2/arch/mips/kernel/scall64-o32.S        2012-02-24 03:55:06.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.3.1/arch/mips/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/mips/kernel/traps.c
514 --- linux-3.3.1/arch/mips/kernel/traps.c        2012-03-19 19:46:43.000000000 +0100
515 +++ linux-3.3.1-vs2.3.3.2/arch/mips/kernel/traps.c      2012-03-19 20:52:09.000000000 +0100
516 @@ -344,9 +344,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.3.1/arch/parisc/Kconfig linux-3.3.1-vs2.3.3.2/arch/parisc/Kconfig
531 --- linux-3.3.1/arch/parisc/Kconfig     2012-03-19 19:46:44.000000000 +0100
532 +++ linux-3.3.1-vs2.3.3.2/arch/parisc/Kconfig   2012-02-24 03:55:06.000000000 +0100
533 @@ -279,6 +279,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.3.1/arch/parisc/kernel/syscall_table.S linux-3.3.1-vs2.3.3.2/arch/parisc/kernel/syscall_table.S
543 --- linux-3.3.1/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
544 +++ linux-3.3.1-vs2.3.3.2/arch/parisc/kernel/syscall_table.S    2012-02-24 03:55:06.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.3.1/arch/parisc/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/parisc/kernel/traps.c
555 --- linux-3.3.1/arch/parisc/kernel/traps.c      2011-10-24 18:45:00.000000000 +0200
556 +++ linux-3.3.1-vs2.3.3.2/arch/parisc/kernel/traps.c    2012-02-24 03:55:06.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.3.1/arch/parisc/mm/fault.c linux-3.3.1-vs2.3.3.2/arch/parisc/mm/fault.c
581 --- linux-3.3.1/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
582 +++ linux-3.3.1-vs2.3.3.2/arch/parisc/mm/fault.c        2012-02-24 03:55:06.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.3.1/arch/powerpc/Kconfig linux-3.3.1-vs2.3.3.2/arch/powerpc/Kconfig
596 --- linux-3.3.1/arch/powerpc/Kconfig    2012-03-19 19:46:44.000000000 +0100
597 +++ linux-3.3.1-vs2.3.3.2/arch/powerpc/Kconfig  2012-02-24 03:55:06.000000000 +0100
598 @@ -997,6 +997,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.3.1/arch/powerpc/include/asm/unistd.h linux-3.3.1-vs2.3.3.2/arch/powerpc/include/asm/unistd.h
608 --- linux-3.3.1/arch/powerpc/include/asm/unistd.h       2012-01-09 16:14:05.000000000 +0100
609 +++ linux-3.3.1-vs2.3.3.2/arch/powerpc/include/asm/unistd.h     2012-02-24 03:55:06.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.3.1/arch/powerpc/kernel/process.c linux-3.3.1-vs2.3.3.2/arch/powerpc/kernel/process.c
620 --- linux-3.3.1/arch/powerpc/kernel/process.c   2012-03-19 19:46:45.000000000 +0100
621 +++ linux-3.3.1-vs2.3.3.2/arch/powerpc/kernel/process.c 2012-02-24 03:55:06.000000000 +0100
622 @@ -656,8 +656,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.3.1/arch/powerpc/kernel/traps.c linux-3.3.1-vs2.3.3.2/arch/powerpc/kernel/traps.c
635 --- linux-3.3.1/arch/powerpc/kernel/traps.c     2012-03-19 19:46:45.000000000 +0100
636 +++ linux-3.3.1-vs2.3.3.2/arch/powerpc/kernel/traps.c   2012-02-24 03:55:06.000000000 +0100
637 @@ -1105,8 +1105,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.3.1/arch/s390/Kconfig linux-3.3.1-vs2.3.3.2/arch/s390/Kconfig
650 --- linux-3.3.1/arch/s390/Kconfig       2012-03-19 19:46:48.000000000 +0100
651 +++ linux-3.3.1-vs2.3.3.2/arch/s390/Kconfig     2012-03-19 20:52:09.000000000 +0100
652 @@ -638,6 +638,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.3.1/arch/s390/include/asm/tlb.h linux-3.3.1-vs2.3.3.2/arch/s390/include/asm/tlb.h
662 --- linux-3.3.1/arch/s390/include/asm/tlb.h     2011-07-22 11:17:41.000000000 +0200
663 +++ linux-3.3.1-vs2.3.3.2/arch/s390/include/asm/tlb.h   2012-02-24 03:55:06.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.3.1/arch/s390/include/asm/unistd.h linux-3.3.1-vs2.3.3.2/arch/s390/include/asm/unistd.h
673 --- linux-3.3.1/arch/s390/include/asm/unistd.h  2012-03-19 19:46:48.000000000 +0100
674 +++ linux-3.3.1-vs2.3.3.2/arch/s390/include/asm/unistd.h        2012-02-24 03:55:06.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.3.1/arch/s390/kernel/ptrace.c linux-3.3.1-vs2.3.3.2/arch/s390/kernel/ptrace.c
685 --- linux-3.3.1/arch/s390/kernel/ptrace.c       2012-03-19 19:46:48.000000000 +0100
686 +++ linux-3.3.1-vs2.3.3.2/arch/s390/kernel/ptrace.c     2012-03-19 20:53:54.000000000 +0100
687 @@ -21,6 +21,7 @@
688  #include <linux/tracehook.h>
689  #include <linux/seccomp.h>
690  #include <linux/compat.h>
691 +#include <linux/vs_base.h>
692  #include <trace/syscall.h>
693  #include <asm/segment.h>
694  #include <asm/page.h>
695 diff -NurpP --minimal linux-3.3.1/arch/s390/kernel/syscalls.S linux-3.3.1-vs2.3.3.2/arch/s390/kernel/syscalls.S
696 --- linux-3.3.1/arch/s390/kernel/syscalls.S     2012-01-09 16:14:06.000000000 +0100
697 +++ linux-3.3.1-vs2.3.3.2/arch/s390/kernel/syscalls.S   2012-02-24 03:55:06.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.3.1/arch/sh/Kconfig linux-3.3.1-vs2.3.3.2/arch/sh/Kconfig
708 --- linux-3.3.1/arch/sh/Kconfig 2012-03-19 19:46:49.000000000 +0100
709 +++ linux-3.3.1-vs2.3.3.2/arch/sh/Kconfig       2012-02-24 03:55:06.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.3.1/arch/sh/kernel/irq.c linux-3.3.1-vs2.3.3.2/arch/sh/kernel/irq.c
720 --- linux-3.3.1/arch/sh/kernel/irq.c    2011-07-22 11:17:41.000000000 +0200
721 +++ linux-3.3.1-vs2.3.3.2/arch/sh/kernel/irq.c  2012-02-24 03:55:06.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.3.1/arch/sparc/Kconfig linux-3.3.1-vs2.3.3.2/arch/sparc/Kconfig
731 --- linux-3.3.1/arch/sparc/Kconfig      2012-03-19 19:46:49.000000000 +0100
732 +++ linux-3.3.1-vs2.3.3.2/arch/sparc/Kconfig    2012-02-24 03:55:06.000000000 +0100
733 @@ -594,6 +594,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.3.1/arch/sparc/include/asm/unistd.h linux-3.3.1-vs2.3.3.2/arch/sparc/include/asm/unistd.h
743 --- linux-3.3.1/arch/sparc/include/asm/unistd.h 2012-01-09 16:14:07.000000000 +0100
744 +++ linux-3.3.1-vs2.3.3.2/arch/sparc/include/asm/unistd.h       2012-02-24 03:55:06.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.3.1/arch/sparc/kernel/systbls_32.S linux-3.3.1-vs2.3.3.2/arch/sparc/kernel/systbls_32.S
755 --- linux-3.3.1/arch/sparc/kernel/systbls_32.S  2012-01-09 16:14:09.000000000 +0100
756 +++ linux-3.3.1-vs2.3.3.2/arch/sparc/kernel/systbls_32.S        2012-02-24 03:55:06.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.3.1/arch/sparc/kernel/systbls_64.S linux-3.3.1-vs2.3.3.2/arch/sparc/kernel/systbls_64.S
767 --- linux-3.3.1/arch/sparc/kernel/systbls_64.S  2012-01-09 16:14:09.000000000 +0100
768 +++ linux-3.3.1-vs2.3.3.2/arch/sparc/kernel/systbls_64.S        2012-02-24 03:55:06.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.3.1/arch/um/Kconfig.rest linux-3.3.1-vs2.3.3.2/arch/um/Kconfig.rest
788 --- linux-3.3.1/arch/um/Kconfig.rest    2012-01-09 16:14:09.000000000 +0100
789 +++ linux-3.3.1-vs2.3.3.2/arch/um/Kconfig.rest  2012-02-24 03:55:06.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.3.1/arch/um/include/shared/kern_constants.h linux-3.3.1-vs2.3.3.2/arch/um/include/shared/kern_constants.h
800 --- linux-3.3.1/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
801 +++ linux-3.3.1-vs2.3.3.2/arch/um/include/shared/kern_constants.h       2012-02-24 03:55:06.000000000 +0100
802 @@ -0,0 +1 @@
803 +#include "../../../../include/generated/asm-offsets.h"
804 diff -NurpP --minimal linux-3.3.1/arch/um/include/shared/user_constants.h linux-3.3.1-vs2.3.3.2/arch/um/include/shared/user_constants.h
805 --- linux-3.3.1/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
806 +++ linux-3.3.1-vs2.3.3.2/arch/um/include/shared/user_constants.h       2012-02-24 03:55:06.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.3.1/arch/x86/Kconfig linux-3.3.1-vs2.3.3.2/arch/x86/Kconfig
849 --- linux-3.3.1/arch/x86/Kconfig        2012-03-19 19:46:49.000000000 +0100
850 +++ linux-3.3.1-vs2.3.3.2/arch/x86/Kconfig      2012-02-24 03:55:06.000000000 +0100
851 @@ -2213,6 +2213,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.3.1/arch/x86/syscalls/syscall_32.tbl linux-3.3.1-vs2.3.3.2/arch/x86/syscalls/syscall_32.tbl
861 --- linux-3.3.1/arch/x86/syscalls/syscall_32.tbl        2012-04-03 03:01:24.000000000 +0200
862 +++ linux-3.3.1-vs2.3.3.2/arch/x86/syscalls/syscall_32.tbl      2012-04-03 03:02:12.000000000 +0200
863 @@ -279,7 +279,7 @@
864  270    i386    tgkill                  sys_tgkill
865  271    i386    utimes                  sys_utimes                      compat_sys_utimes
866  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
867 -273    i386    vserver
868 +273    i386    vserver                 sys_vserver                     sys32_vserver
869  274    i386    mbind                   sys_mbind
870  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
871  276    i386    set_mempolicy           sys_set_mempolicy
872 diff -NurpP --minimal linux-3.3.1/arch/x86/syscalls/syscall_64.tbl linux-3.3.1-vs2.3.3.2/arch/x86/syscalls/syscall_64.tbl
873 --- linux-3.3.1/arch/x86/syscalls/syscall_64.tbl        2012-03-19 19:46:51.000000000 +0100
874 +++ linux-3.3.1-vs2.3.3.2/arch/x86/syscalls/syscall_64.tbl      2012-02-24 16:29:25.000000000 +0100
875 @@ -242,7 +242,7 @@
876  233    64      epoll_ctl               sys_epoll_ctl
877  234    64      tgkill                  sys_tgkill
878  235    64      utimes                  sys_utimes
879 -236    64      vserver
880 +236    64      vserver                 sys_vserver
881  237    64      mbind                   sys_mbind
882  238    64      set_mempolicy           sys_set_mempolicy
883  239    64      get_mempolicy           sys_get_mempolicy
884 diff -NurpP --minimal linux-3.3.1/drivers/block/Kconfig linux-3.3.1-vs2.3.3.2/drivers/block/Kconfig
885 --- linux-3.3.1/drivers/block/Kconfig   2012-03-19 19:46:52.000000000 +0100
886 +++ linux-3.3.1-vs2.3.3.2/drivers/block/Kconfig 2012-02-24 03:55:06.000000000 +0100
887 @@ -290,6 +290,13 @@ config BLK_DEV_CRYPTOLOOP
888  
889  source "drivers/block/drbd/Kconfig"
890  
891 +config BLK_DEV_VROOT
892 +       tristate "Virtual Root device support"
893 +       depends on QUOTACTL
894 +       ---help---
895 +         Saying Y here will allow you to use quota/fs ioctls on a shared
896 +         partition within a virtual server without compromising security.
897 +
898  config BLK_DEV_NBD
899         tristate "Network block device support"
900         depends on NET
901 diff -NurpP --minimal linux-3.3.1/drivers/block/Makefile linux-3.3.1-vs2.3.3.2/drivers/block/Makefile
902 --- linux-3.3.1/drivers/block/Makefile  2012-03-19 19:46:52.000000000 +0100
903 +++ linux-3.3.1-vs2.3.3.2/drivers/block/Makefile        2012-02-24 03:55:06.000000000 +0100
904 @@ -35,6 +35,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
905  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
906  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
907  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
908 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
909  
910  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
911  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
912 diff -NurpP --minimal linux-3.3.1/drivers/block/loop.c linux-3.3.1-vs2.3.3.2/drivers/block/loop.c
913 --- linux-3.3.1/drivers/block/loop.c    2012-03-19 19:46:52.000000000 +0100
914 +++ linux-3.3.1-vs2.3.3.2/drivers/block/loop.c  2012-02-24 03:55:06.000000000 +0100
915 @@ -76,6 +76,7 @@
916  #include <linux/sysfs.h>
917  #include <linux/miscdevice.h>
918  #include <linux/falloc.h>
919 +#include <linux/vs_context.h>
920  
921  #include <asm/uaccess.h>
922  
923 @@ -869,6 +870,7 @@ static int loop_set_fd(struct loop_devic
924         lo->lo_blocksize = lo_blocksize;
925         lo->lo_device = bdev;
926         lo->lo_flags = lo_flags;
927 +       lo->lo_xid = vx_current_xid();
928         lo->lo_backing_file = file;
929         lo->transfer = transfer_none;
930         lo->ioctl = NULL;
931 @@ -1001,6 +1003,7 @@ static int loop_clr_fd(struct loop_devic
932         lo->lo_sizelimit = 0;
933         lo->lo_encrypt_key_size = 0;
934         lo->lo_thread = NULL;
935 +       lo->lo_xid = 0;
936         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
937         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
938         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
939 @@ -1042,7 +1045,7 @@ loop_set_status(struct loop_device *lo, 
940  
941         if (lo->lo_encrypt_key_size &&
942             lo->lo_key_owner != uid &&
943 -           !capable(CAP_SYS_ADMIN))
944 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
945                 return -EPERM;
946         if (lo->lo_state != Lo_bound)
947                 return -ENXIO;
948 @@ -1132,7 +1135,8 @@ loop_get_status(struct loop_device *lo, 
949         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
950         info->lo_encrypt_type =
951                 lo->lo_encryption ? lo->lo_encryption->number : 0;
952 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
953 +       if (lo->lo_encrypt_key_size &&
954 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
955                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
956                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
957                        lo->lo_encrypt_key_size);
958 @@ -1492,6 +1496,11 @@ static int lo_open(struct block_device *
959                 goto out;
960         }
961  
962 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
963 +               err = -EACCES;
964 +               goto out;
965 +       }
966 +
967         mutex_lock(&lo->lo_ctl_mutex);
968         lo->lo_refcnt++;
969         mutex_unlock(&lo->lo_ctl_mutex);
970 diff -NurpP --minimal linux-3.3.1/drivers/block/vroot.c linux-3.3.1-vs2.3.3.2/drivers/block/vroot.c
971 --- linux-3.3.1/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
972 +++ linux-3.3.1-vs2.3.3.2/drivers/block/vroot.c 2012-02-24 03:55:06.000000000 +0100
973 @@ -0,0 +1,291 @@
974 +/*
975 + *  linux/drivers/block/vroot.c
976 + *
977 + *  written by Herbert Pötzl, 9/11/2002
978 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
979 + *
980 + *  based on the loop.c code by Theodore Ts'o.
981 + *
982 + * Copyright (C) 2002-2007 by Herbert Pötzl.
983 + * Redistribution of this file is permitted under the
984 + * GNU General Public License.
985 + *
986 + */
987 +
988 +#include <linux/module.h>
989 +#include <linux/moduleparam.h>
990 +#include <linux/file.h>
991 +#include <linux/major.h>
992 +#include <linux/blkdev.h>
993 +#include <linux/slab.h>
994 +
995 +#include <linux/vroot.h>
996 +#include <linux/vs_context.h>
997 +
998 +
999 +static int max_vroot = 8;
1000 +
1001 +static struct vroot_device *vroot_dev;
1002 +static struct gendisk **disks;
1003 +
1004 +
1005 +static int vroot_set_dev(
1006 +       struct vroot_device *vr,
1007 +       struct block_device *bdev,
1008 +       unsigned int arg)
1009 +{
1010 +       struct block_device *real_bdev;
1011 +       struct file *file;
1012 +       struct inode *inode;
1013 +       int error;
1014 +
1015 +       error = -EBUSY;
1016 +       if (vr->vr_state != Vr_unbound)
1017 +               goto out;
1018 +
1019 +       error = -EBADF;
1020 +       file = fget(arg);
1021 +       if (!file)
1022 +               goto out;
1023 +
1024 +       error = -EINVAL;
1025 +       inode = file->f_dentry->d_inode;
1026 +
1027 +
1028 +       if (S_ISBLK(inode->i_mode)) {
1029 +               real_bdev = inode->i_bdev;
1030 +               vr->vr_device = real_bdev;
1031 +               __iget(real_bdev->bd_inode);
1032 +       } else
1033 +               goto out_fput;
1034 +
1035 +       vxdprintk(VXD_CBIT(misc, 0),
1036 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1037 +               vr->vr_number, VXD_DEV(real_bdev));
1038 +
1039 +       vr->vr_state = Vr_bound;
1040 +       error = 0;
1041 +
1042 + out_fput:
1043 +       fput(file);
1044 + out:
1045 +       return error;
1046 +}
1047 +
1048 +static int vroot_clr_dev(
1049 +       struct vroot_device *vr,
1050 +       struct block_device *bdev)
1051 +{
1052 +       struct block_device *real_bdev;
1053 +
1054 +       if (vr->vr_state != Vr_bound)
1055 +               return -ENXIO;
1056 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1057 +               return -EBUSY;
1058 +
1059 +       real_bdev = vr->vr_device;
1060 +
1061 +       vxdprintk(VXD_CBIT(misc, 0),
1062 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1063 +               vr->vr_number, VXD_DEV(real_bdev));
1064 +
1065 +       bdput(real_bdev);
1066 +       vr->vr_state = Vr_unbound;
1067 +       vr->vr_device = NULL;
1068 +       return 0;
1069 +}
1070 +
1071 +
1072 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1073 +       unsigned int cmd, unsigned long arg)
1074 +{
1075 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1076 +       int err;
1077 +
1078 +       down(&vr->vr_ctl_mutex);
1079 +       switch (cmd) {
1080 +       case VROOT_SET_DEV:
1081 +               err = vroot_set_dev(vr, bdev, arg);
1082 +               break;
1083 +       case VROOT_CLR_DEV:
1084 +               err = vroot_clr_dev(vr, bdev);
1085 +               break;
1086 +       default:
1087 +               err = -EINVAL;
1088 +               break;
1089 +       }
1090 +       up(&vr->vr_ctl_mutex);
1091 +       return err;
1092 +}
1093 +
1094 +static int vr_open(struct block_device *bdev, fmode_t mode)
1095 +{
1096 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1097 +
1098 +       down(&vr->vr_ctl_mutex);
1099 +       vr->vr_refcnt++;
1100 +       up(&vr->vr_ctl_mutex);
1101 +       return 0;
1102 +}
1103 +
1104 +static int vr_release(struct gendisk *disk, fmode_t mode)
1105 +{
1106 +       struct vroot_device *vr = disk->private_data;
1107 +
1108 +       down(&vr->vr_ctl_mutex);
1109 +       --vr->vr_refcnt;
1110 +       up(&vr->vr_ctl_mutex);
1111 +       return 0;
1112 +}
1113 +
1114 +static struct block_device_operations vr_fops = {
1115 +       .owner =        THIS_MODULE,
1116 +       .open =         vr_open,
1117 +       .release =      vr_release,
1118 +       .ioctl =        vr_ioctl,
1119 +};
1120 +
1121 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1122 +{
1123 +       printk("vroot_make_request %p, %p\n", q, bio);
1124 +       bio_io_error(bio);
1125 +}
1126 +
1127 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1128 +{
1129 +       struct inode *inode = bdev->bd_inode;
1130 +       struct vroot_device *vr;
1131 +       struct block_device *real_bdev;
1132 +       int minor = iminor(inode);
1133 +
1134 +       vr = &vroot_dev[minor];
1135 +       real_bdev = vr->vr_device;
1136 +
1137 +       vxdprintk(VXD_CBIT(misc, 0),
1138 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1139 +               vr->vr_number, VXD_DEV(real_bdev));
1140 +
1141 +       if (vr->vr_state != Vr_bound)
1142 +               return ERR_PTR(-ENXIO);
1143 +
1144 +       __iget(real_bdev->bd_inode);
1145 +       return real_bdev;
1146 +}
1147 +
1148 +
1149 +
1150 +/*
1151 + * And now the modules code and kernel interface.
1152 + */
1153 +
1154 +module_param(max_vroot, int, 0);
1155 +
1156 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1157 +MODULE_LICENSE("GPL");
1158 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1159 +
1160 +MODULE_AUTHOR ("Herbert Pötzl");
1161 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1162 +
1163 +
1164 +int __init vroot_init(void)
1165 +{
1166 +       int err, i;
1167 +
1168 +       if (max_vroot < 1 || max_vroot > 256) {
1169 +               max_vroot = MAX_VROOT_DEFAULT;
1170 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1171 +                       "(must be between 1 and 256), "
1172 +                       "using default (%d)\n", max_vroot);
1173 +       }
1174 +
1175 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1176 +               return -EIO;
1177 +
1178 +       err = -ENOMEM;
1179 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1180 +       if (!vroot_dev)
1181 +               goto out_mem1;
1182 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1183 +
1184 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1185 +       if (!disks)
1186 +               goto out_mem2;
1187 +
1188 +       for (i = 0; i < max_vroot; i++) {
1189 +               disks[i] = alloc_disk(1);
1190 +               if (!disks[i])
1191 +                       goto out_mem3;
1192 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1193 +               if (!disks[i]->queue)
1194 +                       goto out_mem3;
1195 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1196 +       }
1197 +
1198 +       for (i = 0; i < max_vroot; i++) {
1199 +               struct vroot_device *vr = &vroot_dev[i];
1200 +               struct gendisk *disk = disks[i];
1201 +
1202 +               memset(vr, 0, sizeof(*vr));
1203 +               sema_init(&vr->vr_ctl_mutex, 1);
1204 +               vr->vr_number = i;
1205 +               disk->major = VROOT_MAJOR;
1206 +               disk->first_minor = i;
1207 +               disk->fops = &vr_fops;
1208 +               sprintf(disk->disk_name, "vroot%d", i);
1209 +               disk->private_data = vr;
1210 +       }
1211 +
1212 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1213 +       if (err)
1214 +               goto out_mem3;
1215 +
1216 +       for (i = 0; i < max_vroot; i++)
1217 +               add_disk(disks[i]);
1218 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1219 +       return 0;
1220 +
1221 +out_mem3:
1222 +       while (i--)
1223 +               put_disk(disks[i]);
1224 +       kfree(disks);
1225 +out_mem2:
1226 +       kfree(vroot_dev);
1227 +out_mem1:
1228 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1229 +       printk(KERN_ERR "vroot: ran out of memory\n");
1230 +       return err;
1231 +}
1232 +
1233 +void vroot_exit(void)
1234 +{
1235 +       int i;
1236 +
1237 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1238 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1239 +
1240 +       for (i = 0; i < max_vroot; i++) {
1241 +               del_gendisk(disks[i]);
1242 +               put_disk(disks[i]);
1243 +       }
1244 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1245 +
1246 +       kfree(disks);
1247 +       kfree(vroot_dev);
1248 +}
1249 +
1250 +module_init(vroot_init);
1251 +module_exit(vroot_exit);
1252 +
1253 +#ifndef MODULE
1254 +
1255 +static int __init max_vroot_setup(char *str)
1256 +{
1257 +       max_vroot = simple_strtol(str, NULL, 0);
1258 +       return 1;
1259 +}
1260 +
1261 +__setup("max_vroot=", max_vroot_setup);
1262 +
1263 +#endif
1264 +
1265 diff -NurpP --minimal linux-3.3.1/drivers/infiniband/Kconfig linux-3.3.1-vs2.3.3.2/drivers/infiniband/Kconfig
1266 --- linux-3.3.1/drivers/infiniband/Kconfig      2012-03-19 19:46:54.000000000 +0100
1267 +++ linux-3.3.1-vs2.3.3.2/drivers/infiniband/Kconfig    2012-02-24 03:55:06.000000000 +0100
1268 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1269  config INFINIBAND_ADDR_TRANS
1270         bool
1271         depends on INET
1272 -       depends on !(INFINIBAND = y && IPV6 = m)
1273 +       depends on !(INFINIBAND = y && IPV6 = y)
1274         default y
1275  
1276  source "drivers/infiniband/hw/mthca/Kconfig"
1277 diff -NurpP --minimal linux-3.3.1/drivers/infiniband/core/addr.c linux-3.3.1-vs2.3.3.2/drivers/infiniband/core/addr.c
1278 --- linux-3.3.1/drivers/infiniband/core/addr.c  2012-03-19 19:46:54.000000000 +0100
1279 +++ linux-3.3.1-vs2.3.3.2/drivers/infiniband/core/addr.c        2012-02-24 03:55:06.000000000 +0100
1280 @@ -259,7 +259,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.3.1/drivers/md/dm-ioctl.c linux-3.3.1-vs2.3.3.2/drivers/md/dm-ioctl.c
1290 --- linux-3.3.1/drivers/md/dm-ioctl.c   2012-03-19 19:46:59.000000000 +0100
1291 +++ linux-3.3.1-vs2.3.3.2/drivers/md/dm-ioctl.c 2012-03-19 20:52:10.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.3.1/drivers/md/dm.c linux-3.3.1-vs2.3.3.2/drivers/md/dm.c
1378 --- linux-3.3.1/drivers/md/dm.c 2012-03-19 19:46:59.000000000 +0100
1379 +++ linux-3.3.1-vs2.3.3.2/drivers/md/dm.c       2012-02-24 03:55:06.000000000 +0100
1380 @@ -19,6 +19,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 @@ -131,6 +132,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 @@ -343,6 +345,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 @@ -351,18 +354,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 @@ -583,6 +587,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 @@ -1849,6 +1861,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.3.1/drivers/md/dm.h linux-3.3.1-vs2.3.3.2/drivers/md/dm.h
1454 --- linux-3.3.1/drivers/md/dm.h 2012-01-09 16:14:21.000000000 +0100
1455 +++ linux-3.3.1-vs2.3.3.2/drivers/md/dm.h       2012-02-24 03:55:06.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.3.1/drivers/net/tun.c linux-3.3.1-vs2.3.3.2/drivers/net/tun.c
1466 --- linux-3.3.1/drivers/net/tun.c       2012-03-19 19:47:08.000000000 +0100
1467 +++ linux-3.3.1-vs2.3.3.2/drivers/net/tun.c     2012-03-19 20:52:10.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         netdev_features_t       set_features;
1484 @@ -910,6 +912,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 @@ -1068,7 +1071,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 @@ -1082,7 +1085,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 @@ -1151,6 +1154,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 @@ -1332,6 +1338,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.3.1/drivers/tty/sysrq.c linux-3.3.1-vs2.3.3.2/drivers/tty/sysrq.c
1538 --- linux-3.3.1/drivers/tty/sysrq.c     2012-03-19 19:47:19.000000000 +0100
1539 +++ linux-3.3.1-vs2.3.3.2/drivers/tty/sysrq.c   2012-02-24 04:03:15.000000000 +0100
1540 @@ -41,6 +41,7 @@
1541  #include <linux/slab.h>
1542  #include <linux/input.h>
1543  #include <linux/uaccess.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.3.1/drivers/tty/tty_io.c linux-3.3.1-vs2.3.3.2/drivers/tty/tty_io.c
1592 --- linux-3.3.1/drivers/tty/tty_io.c    2012-03-19 19:47:19.000000000 +0100
1593 +++ linux-3.3.1-vs2.3.3.2/drivers/tty/tty_io.c  2012-02-24 03:55:06.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 @@ -2131,7 +2132,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 @@ -2419,6 +2421,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.3.1/fs/attr.c linux-3.3.1-vs2.3.3.2/fs/attr.c
1621 --- linux-3.3.1/fs/attr.c       2012-03-19 19:47:24.000000000 +0100
1622 +++ linux-3.3.1-vs2.3.3.2/fs/attr.c     2012-02-24 03:55:06.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.3.1/fs/block_dev.c linux-3.3.1-vs2.3.3.2/fs/block_dev.c
1664 --- linux-3.3.1/fs/block_dev.c  2012-03-19 19:47:24.000000000 +0100
1665 +++ linux-3.3.1-vs2.3.3.2/fs/block_dev.c        2012-03-19 20:52:10.000000000 +0100
1666 @@ -26,6 +26,7 @@
1667  #include <linux/namei.h>
1668  #include <linux/log2.h>
1669  #include <linux/cleancache.h>
1670 +#include <linux/vs_device.h>
1671  #include <asm/uaccess.h>
1672  #include "internal.h"
1673  
1674 @@ -580,6 +581,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 @@ -626,6 +628,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 @@ -636,7 +643,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.3.1/fs/btrfs/ctree.h linux-3.3.1-vs2.3.3.2/fs/btrfs/ctree.h
1704 --- linux-3.3.1/fs/btrfs/ctree.h        2012-03-19 19:47:24.000000000 +0100
1705 +++ linux-3.3.1-vs2.3.3.2/fs/btrfs/ctree.h      2012-03-19 20:52:10.000000000 +0100
1706 @@ -646,11 +646,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 @@ -1504,6 +1507,8 @@ struct btrfs_ioctl_defrag_range_args {
1723  #define BTRFS_MOUNT_CHECK_INTEGRITY    (1 << 20)
1724  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
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 @@ -1711,6 +1716,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 @@ -1764,6 +1770,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 @@ -2925,6 +2935,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.3.1/fs/btrfs/disk-io.c linux-3.3.1-vs2.3.3.2/fs/btrfs/disk-io.c
1759 --- linux-3.3.1/fs/btrfs/disk-io.c      2012-03-19 19:47:24.000000000 +0100
1760 +++ linux-3.3.1-vs2.3.3.2/fs/btrfs/disk-io.c    2012-03-19 20:52:10.000000000 +0100
1761 @@ -2125,6 +2125,9 @@ int open_ctree(struct super_block *sb,
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.3.1/fs/btrfs/inode.c linux-3.3.1-vs2.3.3.2/fs/btrfs/inode.c
1772 --- linux-3.3.1/fs/btrfs/inode.c        2012-03-19 19:47:24.000000000 +0100
1773 +++ linux-3.3.1-vs2.3.3.2/fs/btrfs/inode.c      2012-03-19 20:52:10.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 @@ -2350,6 +2351,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 @@ -2377,8 +2380,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 @@ -2456,8 +2464,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 @@ -7412,11 +7426,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.3.1/fs/btrfs/ioctl.c linux-3.3.1-vs2.3.3.2/fs/btrfs/ioctl.c
1839 --- linux-3.3.1/fs/btrfs/ioctl.c        2012-03-19 19:47:24.000000000 +0100
1840 +++ linux-3.3.1-vs2.3.3.2/fs/btrfs/ioctl.c      2012-03-19 20:52:10.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 @@ -199,7 +277,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 @@ -210,14 +289,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.3.1/fs/btrfs/super.c linux-3.3.1-vs2.3.3.2/fs/btrfs/super.c
2014 --- linux-3.3.1/fs/btrfs/super.c        2012-03-19 19:47:24.000000000 +0100
2015 +++ linux-3.3.1-vs2.3.3.2/fs/btrfs/super.c      2012-02-24 04:42:16.000000000 +0100
2016 @@ -167,7 +167,7 @@ enum {
2017         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
2018         Opt_check_integrity, Opt_check_integrity_including_extent_data,
2019         Opt_check_integrity_print_mask,
2020 -       Opt_err,
2021 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2022  };
2023  
2024  static match_table_t tokens = {
2025 @@ -206,6 +206,9 @@ static match_table_t tokens = {
2026         {Opt_check_integrity, "check_int"},
2027         {Opt_check_integrity_including_extent_data, "check_int_data"},
2028         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2029 +       {Opt_tag, "tag"},
2030 +       {Opt_notag, "notag"},
2031 +       {Opt_tagid, "tagid=%u"},
2032         {Opt_err, NULL},
2033  };
2034  
2035 @@ -438,6 +441,22 @@ int btrfs_parse_options(struct btrfs_roo
2036                         ret = -EINVAL;
2037                         goto out;
2038  #endif
2039 +#ifndef CONFIG_TAGGING_NONE
2040 +               case Opt_tag:
2041 +                       printk(KERN_INFO "btrfs: use tagging\n");
2042 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2043 +                       break;
2044 +               case Opt_notag:
2045 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2046 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2047 +                       break;
2048 +#endif
2049 +#ifdef CONFIG_PROPAGATE
2050 +               case Opt_tagid:
2051 +                       /* use args[0] */
2052 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2053 +                       break;
2054 +#endif
2055                 case Opt_err:
2056                         printk(KERN_INFO "btrfs: unrecognized mount option "
2057                                "'%s'\n", p);
2058 @@ -1005,6 +1024,12 @@ static int btrfs_remount(struct super_bl
2059         if (ret)
2060                 return -EINVAL;
2061  
2062 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2063 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2064 +                       sb->s_id);
2065 +               return -EINVAL;
2066 +       }
2067 +
2068         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2069                 return 0;
2070  
2071 diff -NurpP --minimal linux-3.3.1/fs/char_dev.c linux-3.3.1-vs2.3.3.2/fs/char_dev.c
2072 --- linux-3.3.1/fs/char_dev.c   2012-03-19 19:47:25.000000000 +0100
2073 +++ linux-3.3.1-vs2.3.3.2/fs/char_dev.c 2012-02-24 03:55:06.000000000 +0100
2074 @@ -21,6 +21,8 @@
2075  #include <linux/mutex.h>
2076  #include <linux/backing-dev.h>
2077  #include <linux/tty.h>
2078 +#include <linux/vs_context.h>
2079 +#include <linux/vs_device.h>
2080  
2081  #include "internal.h"
2082  
2083 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2084         struct cdev *p;
2085         struct cdev *new = NULL;
2086         int ret = 0;
2087 +       dev_t mdev;
2088 +
2089 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2090 +               return -EPERM;
2091 +       inode->i_mdev = mdev;
2092  
2093         spin_lock(&cdev_lock);
2094         p = inode->i_cdev;
2095         if (!p) {
2096                 struct kobject *kobj;
2097                 int idx;
2098 +
2099                 spin_unlock(&cdev_lock);
2100 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2101 +
2102 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2103                 if (!kobj)
2104                         return -ENXIO;
2105                 new = container_of(kobj, struct cdev, kobj);
2106 diff -NurpP --minimal linux-3.3.1/fs/dcache.c linux-3.3.1-vs2.3.3.2/fs/dcache.c
2107 --- linux-3.3.1/fs/dcache.c     2012-04-03 03:01:26.000000000 +0200
2108 +++ linux-3.3.1-vs2.3.3.2/fs/dcache.c   2012-04-03 03:02:12.000000000 +0200
2109 @@ -37,6 +37,7 @@
2110  #include <linux/rculist_bl.h>
2111  #include <linux/prefetch.h>
2112  #include <linux/ratelimit.h>
2113 +#include <linux/vs_limit.h>
2114  #include "internal.h"
2115  #include "mount.h"
2116  
2117 @@ -560,6 +561,8 @@ int d_invalidate(struct dentry * dentry)
2118                 spin_lock(&dentry->d_lock);
2119         }
2120  
2121 +       vx_dentry_dec(dentry);
2122 +
2123         /*
2124          * Somebody else still using it?
2125          *
2126 @@ -589,6 +592,7 @@ EXPORT_SYMBOL(d_invalidate);
2127  static inline void __dget_dlock(struct dentry *dentry)
2128  {
2129         dentry->d_count++;
2130 +       vx_dentry_inc(dentry);
2131  }
2132  
2133  static inline void __dget(struct dentry *dentry)
2134 @@ -1213,6 +1217,9 @@ struct dentry *__d_alloc(struct super_bl
2135         struct dentry *dentry;
2136         char *dname;
2137  
2138 +       if (!vx_dentry_avail(1))
2139 +               return NULL;
2140 +
2141         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2142         if (!dentry)
2143                 return NULL;
2144 @@ -1235,6 +1242,7 @@ struct dentry *__d_alloc(struct super_bl
2145  
2146         dentry->d_count = 1;
2147         dentry->d_flags = 0;
2148 +       vx_dentry_inc(dentry);
2149         spin_lock_init(&dentry->d_lock);
2150         seqcount_init(&dentry->d_seq);
2151         dentry->d_inode = NULL;
2152 @@ -1920,6 +1928,7 @@ struct dentry *__d_lookup(struct dentry 
2153                 }
2154  
2155                 dentry->d_count++;
2156 +               vx_dentry_inc(dentry);
2157                 found = dentry;
2158                 spin_unlock(&dentry->d_lock);
2159                 break;
2160 diff -NurpP --minimal linux-3.3.1/fs/devpts/inode.c linux-3.3.1-vs2.3.3.2/fs/devpts/inode.c
2161 --- linux-3.3.1/fs/devpts/inode.c       2012-03-19 19:47:25.000000000 +0100
2162 +++ linux-3.3.1-vs2.3.3.2/fs/devpts/inode.c     2012-02-24 03:55:06.000000000 +0100
2163 @@ -25,6 +25,7 @@
2164  #include <linux/parser.h>
2165  #include <linux/fsnotify.h>
2166  #include <linux/seq_file.h>
2167 +#include <linux/vs_base.h>
2168  
2169  #define DEVPTS_DEFAULT_MODE 0600
2170  /*
2171 @@ -36,6 +37,20 @@
2172  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2173  #define PTMX_MINOR     2
2174  
2175 +static int devpts_permission(struct inode *inode, int mask)
2176 +{
2177 +       int ret = -EACCES;
2178 +
2179 +       /* devpts is xid tagged */
2180 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2181 +               ret = generic_permission(inode, mask);
2182 +       return ret;
2183 +}
2184 +
2185 +static struct inode_operations devpts_file_inode_operations = {
2186 +       .permission     = devpts_permission,
2187 +};
2188 +
2189  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2190  static DEFINE_MUTEX(allocated_ptys_lock);
2191  
2192 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2193         return 0;
2194  }
2195  
2196 +static int devpts_filter(struct dentry *de)
2197 +{
2198 +       xid_t xid = 0;
2199 +
2200 +       /* devpts is xid tagged */
2201 +       if (de && de->d_inode)
2202 +               xid = (xid_t)de->d_inode->i_tag;
2203 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2204 +       else
2205 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2206 +                       de->d_name.len, de->d_name.name);
2207 +#endif
2208 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2209 +}
2210 +
2211 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2212 +{
2213 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2214 +}
2215 +
2216 +static struct file_operations devpts_dir_operations = {
2217 +       .open           = dcache_dir_open,
2218 +       .release        = dcache_dir_close,
2219 +       .llseek         = dcache_dir_lseek,
2220 +       .read           = generic_read_dir,
2221 +       .readdir        = devpts_readdir,
2222 +};
2223 +
2224  static const struct super_operations devpts_sops = {
2225         .statfs         = simple_statfs,
2226         .remount_fs     = devpts_remount,
2227 @@ -306,8 +349,10 @@ devpts_fill_super(struct super_block *s,
2228         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2229         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2230         inode->i_op = &simple_dir_inode_operations;
2231 -       inode->i_fop = &simple_dir_operations;
2232 +       inode->i_fop = &devpts_dir_operations;
2233         set_nlink(inode, 2);
2234 +       /* devpts is xid tagged */
2235 +       inode->i_tag = (tag_t)vx_current_xid();
2236  
2237         s->s_root = d_alloc_root(inode);
2238         if (s->s_root)
2239 @@ -492,6 +537,9 @@ int devpts_pty_new(struct inode *ptmx_in
2240         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2241         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2242         init_special_inode(inode, S_IFCHR|opts->mode, device);
2243 +       /* devpts is xid tagged */
2244 +       inode->i_tag = (tag_t)vx_current_xid();
2245 +       inode->i_op = &devpts_file_inode_operations;
2246         inode->i_private = tty;
2247         tty->driver_data = inode;
2248  
2249 diff -NurpP --minimal linux-3.3.1/fs/ext2/balloc.c linux-3.3.1-vs2.3.3.2/fs/ext2/balloc.c
2250 --- linux-3.3.1/fs/ext2/balloc.c        2012-01-09 16:14:54.000000000 +0100
2251 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/balloc.c      2012-02-24 03:55:06.000000000 +0100
2252 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2253                         start = 0;
2254                 end = EXT2_BLOCKS_PER_GROUP(sb);
2255         }
2256 -
2257         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2258  
2259  repeat:
2260 diff -NurpP --minimal linux-3.3.1/fs/ext2/ext2.h linux-3.3.1-vs2.3.3.2/fs/ext2/ext2.h
2261 --- linux-3.3.1/fs/ext2/ext2.h  2012-03-19 19:47:25.000000000 +0100
2262 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/ext2.h        2012-02-24 03:55:06.000000000 +0100
2263 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2264  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2265  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2266                        u64 start, u64 len);
2267 +extern int ext2_sync_flags(struct inode *, int, int);
2268  
2269  /* ioctl.c */
2270  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2271 diff -NurpP --minimal linux-3.3.1/fs/ext2/file.c linux-3.3.1-vs2.3.3.2/fs/ext2/file.c
2272 --- linux-3.3.1/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2273 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/file.c        2012-02-24 03:55:06.000000000 +0100
2274 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2275         .setattr        = ext2_setattr,
2276         .get_acl        = ext2_get_acl,
2277         .fiemap         = ext2_fiemap,
2278 +       .sync_flags     = ext2_sync_flags,
2279  };
2280 diff -NurpP --minimal linux-3.3.1/fs/ext2/ialloc.c linux-3.3.1-vs2.3.3.2/fs/ext2/ialloc.c
2281 --- linux-3.3.1/fs/ext2/ialloc.c        2012-03-19 19:47:25.000000000 +0100
2282 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/ialloc.c      2012-02-24 03:55:06.000000000 +0100
2283 @@ -17,6 +17,7 @@
2284  #include <linux/backing-dev.h>
2285  #include <linux/buffer_head.h>
2286  #include <linux/random.h>
2287 +#include <linux/vs_tag.h>
2288  #include "ext2.h"
2289  #include "xattr.h"
2290  #include "acl.h"
2291 @@ -549,6 +550,7 @@ got:
2292                 inode->i_mode = mode;
2293                 inode->i_uid = current_fsuid();
2294                 inode->i_gid = dir->i_gid;
2295 +               inode->i_tag = dx_current_fstag(sb);
2296         } else
2297                 inode_init_owner(inode, dir, mode);
2298  
2299 diff -NurpP --minimal linux-3.3.1/fs/ext2/inode.c linux-3.3.1-vs2.3.3.2/fs/ext2/inode.c
2300 --- linux-3.3.1/fs/ext2/inode.c 2012-03-19 19:47:25.000000000 +0100
2301 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/inode.c       2012-02-24 03:55:06.000000000 +0100
2302 @@ -31,6 +31,7 @@
2303  #include <linux/mpage.h>
2304  #include <linux/fiemap.h>
2305  #include <linux/namei.h>
2306 +#include <linux/vs_tag.h>
2307  #include "ext2.h"
2308  #include "acl.h"
2309  #include "xip.h"
2310 @@ -1162,7 +1163,7 @@ static void ext2_truncate_blocks(struct 
2311                 return;
2312         if (ext2_inode_is_fast_symlink(inode))
2313                 return;
2314 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2315 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2316                 return;
2317         __ext2_truncate_blocks(inode, offset);
2318  }
2319 @@ -1253,36 +1254,61 @@ void ext2_set_inode_flags(struct inode *
2320  {
2321         unsigned int flags = EXT2_I(inode)->i_flags;
2322  
2323 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2324 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2325 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2326 +
2327 +
2328 +       if (flags & EXT2_IMMUTABLE_FL)
2329 +               inode->i_flags |= S_IMMUTABLE;
2330 +       if (flags & EXT2_IXUNLINK_FL)
2331 +               inode->i_flags |= S_IXUNLINK;
2332 +
2333         if (flags & EXT2_SYNC_FL)
2334                 inode->i_flags |= S_SYNC;
2335         if (flags & EXT2_APPEND_FL)
2336                 inode->i_flags |= S_APPEND;
2337 -       if (flags & EXT2_IMMUTABLE_FL)
2338 -               inode->i_flags |= S_IMMUTABLE;
2339         if (flags & EXT2_NOATIME_FL)
2340                 inode->i_flags |= S_NOATIME;
2341         if (flags & EXT2_DIRSYNC_FL)
2342                 inode->i_flags |= S_DIRSYNC;
2343 +
2344 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2345 +
2346 +       if (flags & EXT2_BARRIER_FL)
2347 +               inode->i_vflags |= V_BARRIER;
2348 +       if (flags & EXT2_COW_FL)
2349 +               inode->i_vflags |= V_COW;
2350  }
2351  
2352  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2353  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2354  {
2355         unsigned int flags = ei->vfs_inode.i_flags;
2356 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2357 +
2358 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2359 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2360 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2361 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2362 +
2363 +       if (flags & S_IMMUTABLE)
2364 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2365 +       if (flags & S_IXUNLINK)
2366 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2367  
2368 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2369 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2370         if (flags & S_SYNC)
2371                 ei->i_flags |= EXT2_SYNC_FL;
2372         if (flags & S_APPEND)
2373                 ei->i_flags |= EXT2_APPEND_FL;
2374 -       if (flags & S_IMMUTABLE)
2375 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2376         if (flags & S_NOATIME)
2377                 ei->i_flags |= EXT2_NOATIME_FL;
2378         if (flags & S_DIRSYNC)
2379                 ei->i_flags |= EXT2_DIRSYNC_FL;
2380 +
2381 +       if (vflags & V_BARRIER)
2382 +               ei->i_flags |= EXT2_BARRIER_FL;
2383 +       if (vflags & V_COW)
2384 +               ei->i_flags |= EXT2_COW_FL;
2385  }
2386  
2387  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2388 @@ -1292,6 +1318,8 @@ struct inode *ext2_iget (struct super_bl
2389         struct ext2_inode *raw_inode;
2390         struct inode *inode;
2391         long ret = -EIO;
2392 +       uid_t uid;
2393 +       gid_t gid;
2394         int n;
2395  
2396         inode = iget_locked(sb, ino);
2397 @@ -1310,12 +1338,16 @@ struct inode *ext2_iget (struct super_bl
2398         }
2399  
2400         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2401 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2402 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2403 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2404 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2405         if (!(test_opt (inode->i_sb, NO_UID32))) {
2406 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2407 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2408 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2409 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2410         }
2411 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2412 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2413 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2414 +               le16_to_cpu(raw_inode->i_raw_tag));
2415         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2416         inode->i_size = le32_to_cpu(raw_inode->i_size);
2417         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2418 @@ -1413,8 +1445,8 @@ static int __ext2_write_inode(struct ino
2419         struct ext2_inode_info *ei = EXT2_I(inode);
2420         struct super_block *sb = inode->i_sb;
2421         ino_t ino = inode->i_ino;
2422 -       uid_t uid = inode->i_uid;
2423 -       gid_t gid = inode->i_gid;
2424 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2425 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2426         struct buffer_head * bh;
2427         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2428         int n;
2429 @@ -1450,6 +1482,9 @@ static int __ext2_write_inode(struct ino
2430                 raw_inode->i_uid_high = 0;
2431                 raw_inode->i_gid_high = 0;
2432         }
2433 +#ifdef CONFIG_TAGGING_INTERN
2434 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2435 +#endif
2436         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2437         raw_inode->i_size = cpu_to_le32(inode->i_size);
2438         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2439 @@ -1530,7 +1565,8 @@ int ext2_setattr(struct dentry *dentry, 
2440         if (is_quota_modification(inode, iattr))
2441                 dquot_initialize(inode);
2442         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2443 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2444 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2445 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2446                 error = dquot_transfer(inode, iattr);
2447                 if (error)
2448                         return error;
2449 diff -NurpP --minimal linux-3.3.1/fs/ext2/ioctl.c linux-3.3.1-vs2.3.3.2/fs/ext2/ioctl.c
2450 --- linux-3.3.1/fs/ext2/ioctl.c 2012-03-19 19:47:25.000000000 +0100
2451 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/ioctl.c       2012-02-24 03:55:06.000000000 +0100
2452 @@ -17,6 +17,16 @@
2453  #include <asm/uaccess.h>
2454  
2455  
2456 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2457 +{
2458 +       inode->i_flags = flags;
2459 +       inode->i_vflags = vflags;
2460 +       ext2_get_inode_flags(EXT2_I(inode));
2461 +       inode->i_ctime = CURRENT_TIME_SEC;
2462 +       mark_inode_dirty(inode);
2463 +       return 0;
2464 +}
2465 +
2466  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2467  {
2468         struct inode *inode = filp->f_dentry->d_inode;
2469 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2470  
2471                 flags = ext2_mask_flags(inode->i_mode, flags);
2472  
2473 +               if (IS_BARRIER(inode)) {
2474 +                       vxwprintk_task(1, "messing with the barrier.");
2475 +                       return -EACCES;
2476 +               }
2477 +
2478                 mutex_lock(&inode->i_mutex);
2479                 /* Is it quota file? Do not allow user to mess with it */
2480                 if (IS_NOQUOTA(inode)) {
2481 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2482                  *
2483                  * This test looks nicer. Thanks to Pauline Middelink
2484                  */
2485 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2486 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2487 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2488 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2489                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2490                                 mutex_unlock(&inode->i_mutex);
2491                                 ret = -EPERM;
2492 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2493                         }
2494                 }
2495  
2496 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2497 +               flags &= EXT2_FL_USER_MODIFIABLE;
2498                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2499                 ei->i_flags = flags;
2500  
2501 diff -NurpP --minimal linux-3.3.1/fs/ext2/namei.c linux-3.3.1-vs2.3.3.2/fs/ext2/namei.c
2502 --- linux-3.3.1/fs/ext2/namei.c 2012-03-19 19:47:25.000000000 +0100
2503 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/namei.c       2012-02-24 03:55:06.000000000 +0100
2504 @@ -32,6 +32,7 @@
2505  
2506  #include <linux/pagemap.h>
2507  #include <linux/quotaops.h>
2508 +#include <linux/vs_tag.h>
2509  #include "ext2.h"
2510  #include "xattr.h"
2511  #include "acl.h"
2512 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2513                                         (unsigned long) ino);
2514                         return ERR_PTR(-EIO);
2515                 }
2516 +               dx_propagate_tag(nd, inode);
2517         }
2518         return d_splice_alias(inode, dentry);
2519  }
2520 @@ -408,6 +410,7 @@ const struct inode_operations ext2_dir_i
2521         .removexattr    = generic_removexattr,
2522  #endif
2523         .setattr        = ext2_setattr,
2524 +       .sync_flags     = ext2_sync_flags,
2525         .get_acl        = ext2_get_acl,
2526  };
2527  
2528 diff -NurpP --minimal linux-3.3.1/fs/ext2/super.c linux-3.3.1-vs2.3.3.2/fs/ext2/super.c
2529 --- linux-3.3.1/fs/ext2/super.c 2012-03-19 19:47:25.000000000 +0100
2530 +++ linux-3.3.1-vs2.3.3.2/fs/ext2/super.c       2012-02-24 03:55:06.000000000 +0100
2531 @@ -393,7 +393,8 @@ enum {
2532         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2533         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2534         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2535 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2536 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2537 +       Opt_tag, Opt_notag, Opt_tagid
2538  };
2539  
2540  static const match_table_t tokens = {
2541 @@ -421,6 +422,9 @@ static const match_table_t tokens = {
2542         {Opt_acl, "acl"},
2543         {Opt_noacl, "noacl"},
2544         {Opt_xip, "xip"},
2545 +       {Opt_tag, "tag"},
2546 +       {Opt_notag, "notag"},
2547 +       {Opt_tagid, "tagid=%u"},
2548         {Opt_grpquota, "grpquota"},
2549         {Opt_ignore, "noquota"},
2550         {Opt_quota, "quota"},
2551 @@ -491,6 +495,20 @@ static int parse_options(char *options, 
2552                 case Opt_nouid32:
2553                         set_opt (sbi->s_mount_opt, NO_UID32);
2554                         break;
2555 +#ifndef CONFIG_TAGGING_NONE
2556 +               case Opt_tag:
2557 +                       set_opt (sbi->s_mount_opt, TAGGED);
2558 +                       break;
2559 +               case Opt_notag:
2560 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2561 +                       break;
2562 +#endif
2563 +#ifdef CONFIG_PROPAGATE
2564 +               case Opt_tagid:
2565 +                       /* use args[0] */
2566 +                       set_opt (sbi->s_mount_opt, TAGGED);
2567 +                       break;
2568 +#endif
2569                 case Opt_nocheck:
2570                         clear_opt (sbi->s_mount_opt, CHECK);
2571                         break;
2572 @@ -849,6 +867,8 @@ static int ext2_fill_super(struct super_
2573         if (!parse_options((char *) data, sb))
2574                 goto failed_mount;
2575  
2576 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2577 +               sb->s_flags |= MS_TAGGED;
2578         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2579                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2580                  MS_POSIXACL : 0);
2581 @@ -1223,6 +1243,14 @@ static int ext2_remount (struct super_bl
2582                 goto restore_opts;
2583         }
2584  
2585 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2586 +               !(sb->s_flags & MS_TAGGED)) {
2587 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2588 +                      sb->s_id);
2589 +               err = -EINVAL;
2590 +               goto restore_opts;
2591 +       }
2592 +
2593         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2594                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2595  
2596 diff -NurpP --minimal linux-3.3.1/fs/ext3/file.c linux-3.3.1-vs2.3.3.2/fs/ext3/file.c
2597 --- linux-3.3.1/fs/ext3/file.c  2011-10-24 18:45:27.000000000 +0200
2598 +++ linux-3.3.1-vs2.3.3.2/fs/ext3/file.c        2012-02-24 03:55:06.000000000 +0100
2599 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
2600  #endif
2601         .get_acl        = ext3_get_acl,
2602         .fiemap         = ext3_fiemap,
2603 +       .sync_flags     = ext3_sync_flags,
2604  };
2605  
2606 diff -NurpP --minimal linux-3.3.1/fs/ext3/ialloc.c linux-3.3.1-vs2.3.3.2/fs/ext3/ialloc.c
2607 --- linux-3.3.1/fs/ext3/ialloc.c        2012-03-19 19:47:25.000000000 +0100
2608 +++ linux-3.3.1-vs2.3.3.2/fs/ext3/ialloc.c      2012-02-24 03:55:06.000000000 +0100
2609 @@ -23,6 +23,7 @@
2610  #include <linux/buffer_head.h>
2611  #include <linux/random.h>
2612  #include <linux/bitops.h>
2613 +#include <linux/vs_tag.h>
2614  #include <trace/events/ext3.h>
2615  
2616  #include <asm/byteorder.h>
2617 @@ -496,6 +497,7 @@ got:
2618                 inode->i_mode = mode;
2619                 inode->i_uid = current_fsuid();
2620                 inode->i_gid = dir->i_gid;
2621 +               inode->i_tag = dx_current_fstag(sb);
2622         } else
2623                 inode_init_owner(inode, dir, mode);
2624  
2625 diff -NurpP --minimal linux-3.3.1/fs/ext3/inode.c linux-3.3.1-vs2.3.3.2/fs/ext3/inode.c
2626 --- linux-3.3.1/fs/ext3/inode.c 2012-03-19 19:47:25.000000000 +0100
2627 +++ linux-3.3.1-vs2.3.3.2/fs/ext3/inode.c       2012-02-24 03:55:06.000000000 +0100
2628 @@ -37,6 +37,7 @@
2629  #include <linux/bio.h>
2630  #include <linux/fiemap.h>
2631  #include <linux/namei.h>
2632 +#include <linux/vs_tag.h>
2633  #include <trace/events/ext3.h>
2634  #include "xattr.h"
2635  #include "acl.h"
2636 @@ -2855,36 +2856,60 @@ void ext3_set_inode_flags(struct inode *
2637  {
2638         unsigned int flags = EXT3_I(inode)->i_flags;
2639  
2640 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2641 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2642 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2643 +
2644 +       if (flags & EXT3_IMMUTABLE_FL)
2645 +               inode->i_flags |= S_IMMUTABLE;
2646 +       if (flags & EXT3_IXUNLINK_FL)
2647 +               inode->i_flags |= S_IXUNLINK;
2648 +
2649         if (flags & EXT3_SYNC_FL)
2650                 inode->i_flags |= S_SYNC;
2651         if (flags & EXT3_APPEND_FL)
2652                 inode->i_flags |= S_APPEND;
2653 -       if (flags & EXT3_IMMUTABLE_FL)
2654 -               inode->i_flags |= S_IMMUTABLE;
2655         if (flags & EXT3_NOATIME_FL)
2656                 inode->i_flags |= S_NOATIME;
2657         if (flags & EXT3_DIRSYNC_FL)
2658                 inode->i_flags |= S_DIRSYNC;
2659 +
2660 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2661 +
2662 +       if (flags & EXT3_BARRIER_FL)
2663 +               inode->i_vflags |= V_BARRIER;
2664 +       if (flags & EXT3_COW_FL)
2665 +               inode->i_vflags |= V_COW;
2666  }
2667  
2668  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2669  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2670  {
2671         unsigned int flags = ei->vfs_inode.i_flags;
2672 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2673 +
2674 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2675 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2676 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2677 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2678 +
2679 +       if (flags & S_IMMUTABLE)
2680 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2681 +       if (flags & S_IXUNLINK)
2682 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2683  
2684 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2685 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2686         if (flags & S_SYNC)
2687                 ei->i_flags |= EXT3_SYNC_FL;
2688         if (flags & S_APPEND)
2689                 ei->i_flags |= EXT3_APPEND_FL;
2690 -       if (flags & S_IMMUTABLE)
2691 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2692         if (flags & S_NOATIME)
2693                 ei->i_flags |= EXT3_NOATIME_FL;
2694         if (flags & S_DIRSYNC)
2695                 ei->i_flags |= EXT3_DIRSYNC_FL;
2696 +
2697 +       if (vflags & V_BARRIER)
2698 +               ei->i_flags |= EXT3_BARRIER_FL;
2699 +       if (vflags & V_COW)
2700 +               ei->i_flags |= EXT3_COW_FL;
2701  }
2702  
2703  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2704 @@ -2898,6 +2923,8 @@ struct inode *ext3_iget(struct super_blo
2705         transaction_t *transaction;
2706         long ret;
2707         int block;
2708 +       uid_t uid;
2709 +       gid_t gid;
2710  
2711         inode = iget_locked(sb, ino);
2712         if (!inode)
2713 @@ -2914,12 +2941,16 @@ struct inode *ext3_iget(struct super_blo
2714         bh = iloc.bh;
2715         raw_inode = ext3_raw_inode(&iloc);
2716         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2717 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2718 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2719 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2720 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2721         if(!(test_opt (inode->i_sb, NO_UID32))) {
2722 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2723 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2724 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2725 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2726         }
2727 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2728 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2729 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2730 +               le16_to_cpu(raw_inode->i_raw_tag));
2731         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2732         inode->i_size = le32_to_cpu(raw_inode->i_size);
2733         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2734 @@ -3074,6 +3105,8 @@ static int ext3_do_update_inode(handle_t
2735         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2736         struct ext3_inode_info *ei = EXT3_I(inode);
2737         struct buffer_head *bh = iloc->bh;
2738 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2739 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2740         int err = 0, rc, block;
2741  
2742  again:
2743 @@ -3088,29 +3121,32 @@ again:
2744         ext3_get_inode_flags(ei);
2745         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2746         if(!(test_opt(inode->i_sb, NO_UID32))) {
2747 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2748 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2749 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2750 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2751  /*
2752   * Fix up interoperability with old kernels. Otherwise, old inodes get
2753   * re-used with the upper 16 bits of the uid/gid intact
2754   */
2755                 if(!ei->i_dtime) {
2756                         raw_inode->i_uid_high =
2757 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2758 +                               cpu_to_le16(high_16_bits(uid));
2759                         raw_inode->i_gid_high =
2760 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2761 +                               cpu_to_le16(high_16_bits(gid));
2762                 } else {
2763                         raw_inode->i_uid_high = 0;
2764                         raw_inode->i_gid_high = 0;
2765                 }
2766         } else {
2767                 raw_inode->i_uid_low =
2768 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2769 +                       cpu_to_le16(fs_high2lowuid(uid));
2770                 raw_inode->i_gid_low =
2771 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2772 +                       cpu_to_le16(fs_high2lowgid(gid));
2773                 raw_inode->i_uid_high = 0;
2774                 raw_inode->i_gid_high = 0;
2775         }
2776 +#ifdef CONFIG_TAGGING_INTERN
2777 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2778 +#endif
2779         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2780         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2781         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2782 @@ -3270,7 +3306,8 @@ int ext3_setattr(struct dentry *dentry, 
2783         if (is_quota_modification(inode, attr))
2784                 dquot_initialize(inode);
2785         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2786 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2787 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2788 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2789                 handle_t *handle;
2790  
2791                 /* (user+group)*(old+new) structure, inode write (sb,
2792 @@ -3292,6 +3329,8 @@ int ext3_setattr(struct dentry *dentry, 
2793                         inode->i_uid = attr->ia_uid;
2794                 if (attr->ia_valid & ATTR_GID)
2795                         inode->i_gid = attr->ia_gid;
2796 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2797 +                       inode->i_tag = attr->ia_tag;
2798                 error = ext3_mark_inode_dirty(handle, inode);
2799                 ext3_journal_stop(handle);
2800         }
2801 diff -NurpP --minimal linux-3.3.1/fs/ext3/ioctl.c linux-3.3.1-vs2.3.3.2/fs/ext3/ioctl.c
2802 --- linux-3.3.1/fs/ext3/ioctl.c 2012-03-19 19:47:25.000000000 +0100
2803 +++ linux-3.3.1-vs2.3.3.2/fs/ext3/ioctl.c       2012-02-24 03:55:06.000000000 +0100
2804 @@ -8,6 +8,7 @@
2805   */
2806  
2807  #include <linux/fs.h>
2808 +#include <linux/mount.h>
2809  #include <linux/jbd.h>
2810  #include <linux/capability.h>
2811  #include <linux/ext3_fs.h>
2812 @@ -17,6 +18,34 @@
2813  #include <linux/compat.h>
2814  #include <asm/uaccess.h>
2815  
2816 +
2817 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2818 +{
2819 +       handle_t *handle = NULL;
2820 +       struct ext3_iloc iloc;
2821 +       int err;
2822 +
2823 +       handle = ext3_journal_start(inode, 1);
2824 +       if (IS_ERR(handle))
2825 +               return PTR_ERR(handle);
2826 +
2827 +       if (IS_SYNC(inode))
2828 +               handle->h_sync = 1;
2829 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2830 +       if (err)
2831 +               goto flags_err;
2832 +
2833 +       inode->i_flags = flags;
2834 +       inode->i_vflags = vflags;
2835 +       ext3_get_inode_flags(EXT3_I(inode));
2836 +       inode->i_ctime = CURRENT_TIME_SEC;
2837 +
2838 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2839 +flags_err:
2840 +       ext3_journal_stop(handle);
2841 +       return err;
2842 +}
2843 +
2844  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2845  {
2846         struct inode *inode = filp->f_dentry->d_inode;
2847 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
2848  
2849                 flags = ext3_mask_flags(inode->i_mode, flags);
2850  
2851 +               if (IS_BARRIER(inode)) {
2852 +                       vxwprintk_task(1, "messing with the barrier.");
2853 +                       return -EACCES;
2854 +               }
2855 +
2856                 mutex_lock(&inode->i_mutex);
2857  
2858                 /* Is it quota file? Do not allow user to mess with it */
2859 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
2860                  *
2861                  * This test looks nicer. Thanks to Pauline Middelink
2862                  */
2863 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2864 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2865 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2866 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2867                         if (!capable(CAP_LINUX_IMMUTABLE))
2868                                 goto flags_out;
2869                 }
2870 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
2871                 if (err)
2872                         goto flags_err;
2873  
2874 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2875 +               flags &= EXT3_FL_USER_MODIFIABLE;
2876                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2877                 ei->i_flags = flags;
2878  
2879 diff -NurpP --minimal linux-3.3.1/fs/ext3/namei.c linux-3.3.1-vs2.3.3.2/fs/ext3/namei.c
2880 --- linux-3.3.1/fs/ext3/namei.c 2012-03-19 19:47:25.000000000 +0100
2881 +++ linux-3.3.1-vs2.3.3.2/fs/ext3/namei.c       2012-02-24 03:55:06.000000000 +0100
2882 @@ -36,6 +36,7 @@
2883  #include <linux/quotaops.h>
2884  #include <linux/buffer_head.h>
2885  #include <linux/bio.h>
2886 +#include <linux/vs_tag.h>
2887  #include <trace/events/ext3.h>
2888  
2889  #include "namei.h"
2890 @@ -927,6 +928,7 @@ restart:
2891                                         submit_bh(READ | REQ_META | REQ_PRIO,
2892                                                   bh);
2893                                 }
2894 +               dx_propagate_tag(nd, inode);
2895                         }
2896                 }
2897                 if ((bh = bh_use[ra_ptr++]) == NULL)
2898 @@ -2538,6 +2540,7 @@ const struct inode_operations ext3_dir_i
2899         .listxattr      = ext3_listxattr,
2900         .removexattr    = generic_removexattr,
2901  #endif
2902 +       .sync_flags     = ext3_sync_flags,
2903         .get_acl        = ext3_get_acl,
2904  };
2905  
2906 diff -NurpP --minimal linux-3.3.1/fs/ext3/super.c linux-3.3.1-vs2.3.3.2/fs/ext3/super.c
2907 --- linux-3.3.1/fs/ext3/super.c 2012-03-19 19:47:25.000000000 +0100
2908 +++ linux-3.3.1-vs2.3.3.2/fs/ext3/super.c       2012-02-24 03:55:06.000000000 +0100
2909 @@ -830,7 +830,8 @@ enum {
2910         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2911         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2912         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2913 -       Opt_resize, Opt_usrquota, Opt_grpquota
2914 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2915 +       Opt_tag, Opt_notag, Opt_tagid
2916  };
2917  
2918  static const match_table_t tokens = {
2919 @@ -887,6 +888,9 @@ static const match_table_t tokens = {
2920         {Opt_barrier, "barrier"},
2921         {Opt_nobarrier, "nobarrier"},
2922         {Opt_resize, "resize"},
2923 +       {Opt_tag, "tag"},
2924 +       {Opt_notag, "notag"},
2925 +       {Opt_tagid, "tagid=%u"},
2926         {Opt_err, NULL},
2927  };
2928  
2929 @@ -1039,6 +1043,20 @@ static int parse_options (char *options,
2930                 case Opt_nouid32:
2931                         set_opt (sbi->s_mount_opt, NO_UID32);
2932                         break;
2933 +#ifndef CONFIG_TAGGING_NONE
2934 +               case Opt_tag:
2935 +                       set_opt (sbi->s_mount_opt, TAGGED);
2936 +                       break;
2937 +               case Opt_notag:
2938 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2939 +                       break;
2940 +#endif
2941 +#ifdef CONFIG_PROPAGATE
2942 +               case Opt_tagid:
2943 +                       /* use args[0] */
2944 +                       set_opt (sbi->s_mount_opt, TAGGED);
2945 +                       break;
2946 +#endif
2947                 case Opt_nocheck:
2948                         clear_opt (sbi->s_mount_opt, CHECK);
2949                         break;
2950 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2951                             NULL, 0))
2952                 goto failed_mount;
2953  
2954 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2955 +               sb->s_flags |= MS_TAGGED;
2956 +
2957         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2958                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2959  
2960 @@ -2619,6 +2640,14 @@ static int ext3_remount (struct super_bl
2961         if (test_opt(sb, ABORT))
2962                 ext3_abort(sb, __func__, "Abort forced by user");
2963  
2964 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2965 +               !(sb->s_flags & MS_TAGGED)) {
2966 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2967 +                       sb->s_id);
2968 +               err = -EINVAL;
2969 +               goto restore_opts;
2970 +       }
2971 +
2972         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2973                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2974  
2975 diff -NurpP --minimal linux-3.3.1/fs/ext4/ext4.h linux-3.3.1-vs2.3.3.2/fs/ext4/ext4.h
2976 --- linux-3.3.1/fs/ext4/ext4.h  2012-04-03 03:01:26.000000000 +0200
2977 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/ext4.h        2012-04-03 03:02:12.000000000 +0200
2978 @@ -373,8 +373,12 @@ struct flex_groups {
2979  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2980  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2981  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2982 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2983  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2984  
2985 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2986 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2987 +
2988  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2989  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
2990  
2991 @@ -643,7 +647,8 @@ struct ext4_inode {
2992                         __le16  l_i_file_acl_high;
2993                         __le16  l_i_uid_high;   /* these 2 fields */
2994                         __le16  l_i_gid_high;   /* were reserved2[0] */
2995 -                       __u32   l_i_reserved2;
2996 +                       __le16  l_i_tag;        /* Context Tag */
2997 +                       __u16   l_i_reserved2;
2998                 } linux2;
2999                 struct {
3000                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3001 @@ -761,6 +766,7 @@ do {                                                                               \
3002  #define i_gid_low      i_gid
3003  #define i_uid_high     osd2.linux2.l_i_uid_high
3004  #define i_gid_high     osd2.linux2.l_i_gid_high
3005 +#define i_raw_tag      osd2.linux2.l_i_tag
3006  #define i_reserved2    osd2.linux2.l_i_reserved2
3007  
3008  #elif defined(__GNU__)
3009 @@ -937,6 +943,7 @@ struct ext4_inode_info {
3010  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3011  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3012  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3013 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3014  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3015  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3016  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3017 @@ -2277,6 +2284,7 @@ extern int ext4_map_blocks(handle_t *han
3018                            struct ext4_map_blocks *map, int flags);
3019  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3020                         __u64 start, __u64 len);
3021 +extern int ext4_sync_flags(struct inode *, int, int);
3022  /* move_extent.c */
3023  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3024                              __u64 start_orig, __u64 start_donor,
3025 diff -NurpP --minimal linux-3.3.1/fs/ext4/file.c linux-3.3.1-vs2.3.3.2/fs/ext4/file.c
3026 --- linux-3.3.1/fs/ext4/file.c  2012-01-09 16:14:54.000000000 +0100
3027 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/file.c        2012-02-24 03:55:06.000000000 +0100
3028 @@ -258,5 +258,6 @@ const struct inode_operations ext4_file_
3029  #endif
3030         .get_acl        = ext4_get_acl,
3031         .fiemap         = ext4_fiemap,
3032 +       .sync_flags     = ext4_sync_flags,
3033  };
3034  
3035 diff -NurpP --minimal linux-3.3.1/fs/ext4/ialloc.c linux-3.3.1-vs2.3.3.2/fs/ext4/ialloc.c
3036 --- linux-3.3.1/fs/ext4/ialloc.c        2012-03-19 19:47:25.000000000 +0100
3037 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/ialloc.c      2012-02-24 03:55:06.000000000 +0100
3038 @@ -22,6 +22,7 @@
3039  #include <linux/random.h>
3040  #include <linux/bitops.h>
3041  #include <linux/blkdev.h>
3042 +#include <linux/vs_tag.h>
3043  #include <asm/byteorder.h>
3044  
3045  #include "ext4.h"
3046 @@ -860,6 +861,7 @@ got:
3047                 inode->i_mode = mode;
3048                 inode->i_uid = current_fsuid();
3049                 inode->i_gid = dir->i_gid;
3050 +               inode->i_tag = dx_current_fstag(sb);
3051         } else
3052                 inode_init_owner(inode, dir, mode);
3053  
3054 diff -NurpP --minimal linux-3.3.1/fs/ext4/inode.c linux-3.3.1-vs2.3.3.2/fs/ext4/inode.c
3055 --- linux-3.3.1/fs/ext4/inode.c 2012-04-03 03:01:26.000000000 +0200
3056 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/inode.c       2012-04-03 03:02:12.000000000 +0200
3057 @@ -37,6 +37,7 @@
3058  #include <linux/printk.h>
3059  #include <linux/slab.h>
3060  #include <linux/ratelimit.h>
3061 +#include <linux/vs_tag.h>
3062  
3063  #include "ext4_jbd2.h"
3064  #include "xattr.h"
3065 @@ -3557,41 +3558,64 @@ void ext4_set_inode_flags(struct inode *
3066  {
3067         unsigned int flags = EXT4_I(inode)->i_flags;
3068  
3069 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3070 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3071 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3072 +
3073 +       if (flags & EXT4_IMMUTABLE_FL)
3074 +               inode->i_flags |= S_IMMUTABLE;
3075 +       if (flags & EXT4_IXUNLINK_FL)
3076 +               inode->i_flags |= S_IXUNLINK;
3077 +
3078         if (flags & EXT4_SYNC_FL)
3079                 inode->i_flags |= S_SYNC;
3080         if (flags & EXT4_APPEND_FL)
3081                 inode->i_flags |= S_APPEND;
3082 -       if (flags & EXT4_IMMUTABLE_FL)
3083 -               inode->i_flags |= S_IMMUTABLE;
3084         if (flags & EXT4_NOATIME_FL)
3085                 inode->i_flags |= S_NOATIME;
3086         if (flags & EXT4_DIRSYNC_FL)
3087                 inode->i_flags |= S_DIRSYNC;
3088 +
3089 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3090 +
3091 +       if (flags & EXT4_BARRIER_FL)
3092 +               inode->i_vflags |= V_BARRIER;
3093 +       if (flags & EXT4_COW_FL)
3094 +               inode->i_vflags |= V_COW;
3095  }
3096  
3097  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3098  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3099  {
3100 -       unsigned int vfs_fl;
3101 +       unsigned int vfs_fl, vfs_vf;
3102         unsigned long old_fl, new_fl;
3103  
3104         do {
3105                 vfs_fl = ei->vfs_inode.i_flags;
3106 +               vfs_vf = ei->vfs_inode.i_vflags;
3107                 old_fl = ei->i_flags;
3108                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3109                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3110 -                               EXT4_DIRSYNC_FL);
3111 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3112 +                               EXT4_COW_FL);
3113 +
3114 +               if (vfs_fl & S_IMMUTABLE)
3115 +                       new_fl |= EXT4_IMMUTABLE_FL;
3116 +               if (vfs_fl & S_IXUNLINK)
3117 +                       new_fl |= EXT4_IXUNLINK_FL;
3118 +
3119                 if (vfs_fl & S_SYNC)
3120                         new_fl |= EXT4_SYNC_FL;
3121                 if (vfs_fl & S_APPEND)
3122                         new_fl |= EXT4_APPEND_FL;
3123 -               if (vfs_fl & S_IMMUTABLE)
3124 -                       new_fl |= EXT4_IMMUTABLE_FL;
3125                 if (vfs_fl & S_NOATIME)
3126                         new_fl |= EXT4_NOATIME_FL;
3127                 if (vfs_fl & S_DIRSYNC)
3128                         new_fl |= EXT4_DIRSYNC_FL;
3129 +
3130 +               if (vfs_vf & V_BARRIER)
3131 +                       new_fl |= EXT4_BARRIER_FL;
3132 +               if (vfs_vf & V_COW)
3133 +                       new_fl |= EXT4_COW_FL;
3134         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3135  }
3136  
3137 @@ -3627,6 +3651,8 @@ struct inode *ext4_iget(struct super_blo
3138         journal_t *journal = EXT4_SB(sb)->s_journal;
3139         long ret;
3140         int block;
3141 +       uid_t uid;
3142 +       gid_t gid;
3143  
3144         inode = iget_locked(sb, ino);
3145         if (!inode)
3146 @@ -3642,12 +3668,16 @@ struct inode *ext4_iget(struct super_blo
3147                 goto bad_inode;
3148         raw_inode = ext4_raw_inode(&iloc);
3149         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3150 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3151 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3152 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3153 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3154         if (!(test_opt(inode->i_sb, NO_UID32))) {
3155 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3156 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3157 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3158 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3159         }
3160 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3161 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3162 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3163 +               le16_to_cpu(raw_inode->i_raw_tag));
3164         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3165  
3166         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3167 @@ -3866,6 +3896,8 @@ static int ext4_do_update_inode(handle_t
3168         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3169         struct ext4_inode_info *ei = EXT4_I(inode);
3170         struct buffer_head *bh = iloc->bh;
3171 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3172 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3173         int err = 0, rc, block;
3174  
3175         /* For fields not not tracking in the in-memory inode,
3176 @@ -3876,29 +3908,32 @@ static int ext4_do_update_inode(handle_t
3177         ext4_get_inode_flags(ei);
3178         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3179         if (!(test_opt(inode->i_sb, NO_UID32))) {
3180 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3181 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3182 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3183 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3184  /*
3185   * Fix up interoperability with old kernels. Otherwise, old inodes get
3186   * re-used with the upper 16 bits of the uid/gid intact
3187   */
3188                 if (!ei->i_dtime) {
3189                         raw_inode->i_uid_high =
3190 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3191 +                               cpu_to_le16(high_16_bits(uid));
3192                         raw_inode->i_gid_high =
3193 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3194 +                               cpu_to_le16(high_16_bits(gid));
3195                 } else {
3196                         raw_inode->i_uid_high = 0;
3197                         raw_inode->i_gid_high = 0;
3198                 }
3199         } else {
3200                 raw_inode->i_uid_low =
3201 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3202 +                       cpu_to_le16(fs_high2lowuid(uid));
3203                 raw_inode->i_gid_low =
3204 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3205 +                       cpu_to_le16(fs_high2lowgid(gid));
3206                 raw_inode->i_uid_high = 0;
3207                 raw_inode->i_gid_high = 0;
3208         }
3209 +#ifdef CONFIG_TAGGING_INTERN
3210 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3211 +#endif
3212         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3213  
3214         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3215 @@ -4084,7 +4119,8 @@ int ext4_setattr(struct dentry *dentry, 
3216         if (is_quota_modification(inode, attr))
3217                 dquot_initialize(inode);
3218         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3219 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3220 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3221 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3222                 handle_t *handle;
3223  
3224                 /* (user+group)*(old+new) structure, inode write (sb,
3225 @@ -4106,6 +4142,8 @@ int ext4_setattr(struct dentry *dentry, 
3226                         inode->i_uid = attr->ia_uid;
3227                 if (attr->ia_valid & ATTR_GID)
3228                         inode->i_gid = attr->ia_gid;
3229 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3230 +                       inode->i_tag = attr->ia_tag;
3231                 error = ext4_mark_inode_dirty(handle, inode);
3232                 ext4_journal_stop(handle);
3233         }
3234 diff -NurpP --minimal linux-3.3.1/fs/ext4/ioctl.c linux-3.3.1-vs2.3.3.2/fs/ext4/ioctl.c
3235 --- linux-3.3.1/fs/ext4/ioctl.c 2012-03-19 19:47:25.000000000 +0100
3236 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/ioctl.c       2012-02-24 04:29:04.000000000 +0100
3237 @@ -14,12 +14,40 @@
3238  #include <linux/compat.h>
3239  #include <linux/mount.h>
3240  #include <linux/file.h>
3241 +#include <linux/vs_tag.h>
3242  #include <asm/uaccess.h>
3243  #include "ext4_jbd2.h"
3244  #include "ext4.h"
3245  
3246  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
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 @@ -53,6 +81,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 @@ -70,7 +103,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.3.1/fs/ext4/namei.c linux-3.3.1-vs2.3.3.2/fs/ext4/namei.c
3302 --- linux-3.3.1/fs/ext4/namei.c 2012-03-19 19:47:25.000000000 +0100
3303 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/namei.c       2012-02-24 03:55:06.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.3.1/fs/ext4/super.c linux-3.3.1-vs2.3.3.2/fs/ext4/super.c
3329 --- linux-3.3.1/fs/ext4/super.c 2012-03-19 19:47:25.000000000 +0100
3330 +++ linux-3.3.1-vs2.3.3.2/fs/ext4/super.c       2012-02-24 03:55:06.000000000 +0100
3331 @@ -1333,6 +1333,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 @@ -1408,6 +1409,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 @@ -1576,6 +1580,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 @@ -3276,6 +3294,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 @@ -4428,6 +4449,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.3.1/fs/fcntl.c linux-3.3.1-vs2.3.3.2/fs/fcntl.c
3396 --- linux-3.3.1/fs/fcntl.c      2011-05-22 16:17:52.000000000 +0200
3397 +++ linux-3.3.1-vs2.3.3.2/fs/fcntl.c    2012-02-24 03:55:06.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.3.1/fs/file.c linux-3.3.1-vs2.3.3.2/fs/file.c
3425 --- linux-3.3.1/fs/file.c       2011-05-22 16:17:52.000000000 +0200
3426 +++ linux-3.3.1-vs2.3.3.2/fs/file.c     2012-02-24 03:55:06.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.3.1/fs/file_table.c linux-3.3.1-vs2.3.3.2/fs/file_table.c
3453 --- linux-3.3.1/fs/file_table.c 2012-03-19 19:47:25.000000000 +0100
3454 +++ linux-3.3.1-vs2.3.3.2/fs/file_table.c       2012-02-24 03:55:06.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.3.1/fs/fs_struct.c linux-3.3.1-vs2.3.3.2/fs/fs_struct.c
3492 --- linux-3.3.1/fs/fs_struct.c  2011-03-15 18:07:31.000000000 +0100
3493 +++ linux-3.3.1-vs2.3.3.2/fs/fs_struct.c        2012-02-24 03:55:06.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.3.1/fs/gfs2/file.c linux-3.3.1-vs2.3.3.2/fs/gfs2/file.c
3519 --- linux-3.3.1/fs/gfs2/file.c  2012-03-19 19:47:25.000000000 +0100
3520 +++ linux-3.3.1-vs2.3.3.2/fs/gfs2/file.c        2012-02-24 03:55:06.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.3.1/fs/gfs2/inode.h linux-3.3.1-vs2.3.3.2/fs/gfs2/inode.h
3644 --- linux-3.3.1/fs/gfs2/inode.h 2012-01-09 16:14:54.000000000 +0100
3645 +++ linux-3.3.1-vs2.3.3.2/fs/gfs2/inode.h       2012-02-24 03:55:06.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.3.1/fs/inode.c linux-3.3.1-vs2.3.3.2/fs/inode.c
3655 --- linux-3.3.1/fs/inode.c      2012-03-19 19:47:25.000000000 +0100
3656 +++ linux-3.3.1-vs2.3.3.2/fs/inode.c    2012-03-19 20:52:10.000000000 +0100
3657 @@ -27,6 +27,7 @@
3658  #include <linux/cred.h>
3659  #include <linux/buffer_head.h> /* for inode_has_buffers */
3660  #include <linux/ratelimit.h>
3661 +#include <linux/vs_tag.h>
3662  #include "internal.h"
3663  
3664  /*
3665 @@ -138,6 +139,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 @@ -159,6 +163,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 @@ -480,6 +485,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 @@ -1709,9 +1716,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 @@ -1740,6 +1749,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.3.1/fs/ioctl.c linux-3.3.1-vs2.3.3.2/fs/ioctl.c
3713 --- linux-3.3.1/fs/ioctl.c      2012-03-19 19:47:25.000000000 +0100
3714 +++ linux-3.3.1-vs2.3.3.2/fs/ioctl.c    2012-02-24 03:55:06.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.3.1/fs/ioprio.c linux-3.3.1-vs2.3.3.2/fs/ioprio.c
3726 --- linux-3.3.1/fs/ioprio.c     2012-03-19 19:47:25.000000000 +0100
3727 +++ linux-3.3.1-vs2.3.3.2/fs/ioprio.c   2012-02-24 03:55:06.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 @@ -104,6 +105,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 @@ -193,6 +196,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.3.1/fs/jfs/file.c linux-3.3.1-vs2.3.3.2/fs/jfs/file.c
3755 --- linux-3.3.1/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3756 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/file.c 2012-02-24 03:55:06.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.3.1/fs/jfs/ioctl.c linux-3.3.1-vs2.3.3.2/fs/jfs/ioctl.c
3776 --- linux-3.3.1/fs/jfs/ioctl.c  2012-03-19 19:47:25.000000000 +0100
3777 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/ioctl.c        2012-02-24 03:55:06.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.3.1/fs/jfs/jfs_dinode.h linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_dinode.h
3836 --- linux-3.3.1/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3837 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_dinode.h   2012-02-24 03:55:06.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.3.1/fs/jfs/jfs_filsys.h linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_filsys.h
3855 --- linux-3.3.1/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3856 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_filsys.h   2012-02-24 03:55:06.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.3.1/fs/jfs/jfs_imap.c linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_imap.c
3866 --- linux-3.3.1/fs/jfs/jfs_imap.c       2012-01-09 16:14:54.000000000 +0100
3867 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_imap.c     2012-02-24 03:55:06.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.3.1/fs/jfs/jfs_inode.c linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_inode.c
3928 --- linux-3.3.1/fs/jfs/jfs_inode.c      2012-01-09 16:14:54.000000000 +0100
3929 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_inode.c    2012-02-24 03:55:06.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.3.1/fs/jfs/jfs_inode.h linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_inode.h
4004 --- linux-3.3.1/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
4005 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/jfs_inode.h    2012-02-24 03:55:06.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.3.1/fs/jfs/namei.c linux-3.3.1-vs2.3.3.2/fs/jfs/namei.c
4015 --- linux-3.3.1/fs/jfs/namei.c  2012-03-19 19:47:25.000000000 +0100
4016 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/namei.c        2012-02-24 03:55:06.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.3.1/fs/jfs/super.c linux-3.3.1-vs2.3.3.2/fs/jfs/super.c
4042 --- linux-3.3.1/fs/jfs/super.c  2012-03-19 19:47:25.000000000 +0100
4043 +++ linux-3.3.1-vs2.3.3.2/fs/jfs/super.c        2012-02-24 03:55:06.000000000 +0100
4044 @@ -197,7 +197,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 @@ -207,6 +208,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 @@ -341,6 +346,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 @@ -372,6 +391,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 @@ -454,6 +479,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.3.1/fs/libfs.c linux-3.3.1-vs2.3.3.2/fs/libfs.c
4110 --- linux-3.3.1/fs/libfs.c      2012-03-19 19:47:26.000000000 +0100
4111 +++ linux-3.3.1-vs2.3.3.2/fs/libfs.c    2012-02-24 03:55:06.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.3.1/fs/locks.c linux-3.3.1-vs2.3.3.2/fs/locks.c
4158 --- linux-3.3.1/fs/locks.c      2012-01-09 16:14:54.000000000 +0100
4159 +++ linux-3.3.1-vs2.3.3.2/fs/locks.c    2012-03-23 18:52:48.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.3.1/fs/mount.h linux-3.3.1-vs2.3.3.2/fs/mount.h
4358 --- linux-3.3.1/fs/mount.h      2012-03-19 19:47:26.000000000 +0100
4359 +++ linux-3.3.1-vs2.3.3.2/fs/mount.h    2012-02-24 17:29:48.000000000 +0100
4360 @@ -47,6 +47,7 @@ struct mount {
4361         int mnt_expiry_mark;            /* true if marked for expiry */
4362         int mnt_pinned;
4363         int mnt_ghosts;
4364 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4365  };
4366  
4367  static inline struct mount *real_mount(struct vfsmount *mnt)
4368 diff -NurpP --minimal linux-3.3.1/fs/namei.c linux-3.3.1-vs2.3.3.2/fs/namei.c
4369 --- linux-3.3.1/fs/namei.c      2012-03-19 19:47:26.000000000 +0100
4370 +++ linux-3.3.1-vs2.3.3.2/fs/namei.c    2012-03-19 20:52:10.000000000 +0100
4371 @@ -33,6 +33,14 @@
4372  #include <linux/device_cgroup.h>
4373  #include <linux/fs_struct.h>
4374  #include <linux/posix_acl.h>
4375 +#include <linux/proc_fs.h>
4376 +#include <linux/vserver/inode.h>
4377 +#include <linux/vs_base.h>
4378 +#include <linux/vs_tag.h>
4379 +#include <linux/vs_cowbl.h>
4380 +#include <linux/vs_device.h>
4381 +#include <linux/vs_context.h>
4382 +#include <linux/pid_namespace.h>
4383  #include <asm/uaccess.h>
4384  
4385  #include "internal.h"
4386 @@ -221,6 +229,89 @@ static int check_acl(struct inode *inode
4387         return -EAGAIN;
4388  }
4389  
4390 +static inline int dx_barrier(const struct inode *inode)
4391 +{
4392 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4393 +               vxwprintk_task(1, "did hit the barrier.");
4394 +               return 1;
4395 +       }
4396 +       return 0;
4397 +}
4398 +
4399 +static int __dx_permission(const struct inode *inode, int mask)
4400 +{
4401 +       if (dx_barrier(inode))
4402 +               return -EACCES;
4403 +
4404 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4405 +               /* devpts is xid tagged */
4406 +               if (S_ISDIR(inode->i_mode) ||
4407 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4408 +                       return 0;
4409 +
4410 +               /* just pretend we didn't find anything */
4411 +               return -ENOENT;
4412 +       }
4413 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4414 +               struct proc_dir_entry *de = PDE(inode);
4415 +
4416 +               if (de && !vx_hide_check(0, de->vx_flags))
4417 +                       goto out;
4418 +
4419 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4420 +                       struct pid *pid;
4421 +                       struct task_struct *tsk;
4422 +
4423 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4424 +                           vx_flags(VXF_STATE_SETUP, 0))
4425 +                               return 0;
4426 +
4427 +                       pid = PROC_I(inode)->pid;
4428 +                       if (!pid)
4429 +                               goto out;
4430 +
4431 +                       rcu_read_lock();
4432 +                       tsk = pid_task(pid, PIDTYPE_PID);
4433 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4434 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4435 +                       if (tsk &&
4436 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4437 +                               rcu_read_unlock();
4438 +                               return 0;
4439 +                       }
4440 +                       rcu_read_unlock();
4441 +               }
4442 +               else {
4443 +                       /* FIXME: Should we block some entries here? */
4444 +                       return 0;
4445 +               }
4446 +       }
4447 +       else {
4448 +               if (dx_notagcheck(inode->i_sb) ||
4449 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4450 +                            DX_IDENT))
4451 +                       return 0;
4452 +       }
4453 +
4454 +out:
4455 +       return -EACCES;
4456 +}
4457 +
4458 +int dx_permission(const struct inode *inode, int mask)
4459 +{
4460 +       int ret = __dx_permission(inode, mask);
4461 +       if (unlikely(ret)) {
4462 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4463 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4464 +#endif
4465 +                   vxwprintk_task(1,
4466 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4467 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4468 +                       inode->i_ino);
4469 +       }
4470 +       return ret;
4471 +}
4472 +
4473  /*
4474   * This does the basic permission checking
4475   */
4476 @@ -356,10 +447,14 @@ int inode_permission(struct inode *inode
4477                 /*
4478                  * Nobody gets write access to an immutable file.
4479                  */
4480 -               if (IS_IMMUTABLE(inode))
4481 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4482                         return -EACCES;
4483         }
4484  
4485 +       retval = dx_permission(inode, mask);
4486 +       if (retval)
4487 +               return retval;
4488 +
4489         retval = do_inode_permission(inode, mask);
4490         if (retval)
4491                 return retval;
4492 @@ -1038,7 +1133,8 @@ static void follow_dotdot(struct nameida
4493  
4494                 if (nd->path.dentry == nd->root.dentry &&
4495                     nd->path.mnt == nd->root.mnt) {
4496 -                       break;
4497 +                       /* for sane '/' avoid follow_mount() */
4498 +                       return;
4499                 }
4500                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4501                         /* rare case of legitimate dget_parent()... */
4502 @@ -1149,6 +1245,9 @@ static int do_lookup(struct nameidata *n
4503                 }
4504                 if (unlikely(d_need_lookup(dentry)))
4505                         goto unlazy;
4506 +
4507 +               /* FIXME: check dx permission */
4508 +
4509                 path->mnt = mnt;
4510                 path->dentry = dentry;
4511                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4512 @@ -1210,6 +1309,8 @@ retry:
4513                 }
4514         }
4515  
4516 +       /* FIXME: check dx permission */
4517 +
4518         path->mnt = mnt;
4519         path->dentry = dentry;
4520         err = follow_managed(path, nd->flags);
4521 @@ -1926,7 +2027,7 @@ static int may_delete(struct inode *dir,
4522         if (IS_APPEND(dir))
4523                 return -EPERM;
4524         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4525 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4526 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4527                 return -EPERM;
4528         if (isdir) {
4529                 if (!S_ISDIR(victim->d_inode->i_mode))
4530 @@ -2006,19 +2107,25 @@ int vfs_create(struct inode *dir, struct
4531  {
4532         int error = may_create(dir, dentry);
4533  
4534 -       if (error)
4535 +       if (error) {
4536 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4537                 return error;
4538 +       }
4539  
4540         if (!dir->i_op->create)
4541                 return -EACCES; /* shouldn't it be ENOSYS? */
4542         mode &= S_IALLUGO;
4543         mode |= S_IFREG;
4544         error = security_inode_create(dir, dentry, mode);
4545 -       if (error)
4546 +       if (error) {
4547 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4548                 return error;
4549 +       }
4550         error = dir->i_op->create(dir, dentry, mode, nd);
4551         if (!error)
4552                 fsnotify_create(dir, dentry);
4553 +       else
4554 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4555         return error;
4556  }
4557  
4558 @@ -2053,6 +2160,15 @@ static int may_open(struct path *path, i
4559                 break;
4560         }
4561  
4562 +#ifdef CONFIG_VSERVER_COWBL
4563 +       if (IS_COW(inode) &&
4564 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4565 +               if (IS_COW_LINK(inode))
4566 +                       return -EMLINK;
4567 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4568 +               mark_inode_dirty(inode);
4569 +       }
4570 +#endif
4571         error = inode_permission(inode, acc_mode);
4572         if (error)
4573                 return error;
4574 @@ -2277,6 +2393,16 @@ ok:
4575         }
4576  common:
4577         error = may_open(&nd->path, acc_mode, open_flag);
4578 +#ifdef CONFIG_VSERVER_COWBL
4579 +       if (error == -EMLINK) {
4580 +               struct dentry *dentry;
4581 +               dentry = cow_break_link(pathname);
4582 +               if (IS_ERR(dentry))
4583 +                       error = PTR_ERR(dentry);
4584 +               else
4585 +                       dput(dentry);
4586 +       }
4587 +#endif
4588         if (error)
4589                 goto exit;
4590         filp = nameidata_to_filp(nd);
4591 @@ -2319,6 +2445,7 @@ static struct file *path_openat(int dfd,
4592         struct path path;
4593         int error;
4594  
4595 +restart:
4596         filp = get_empty_filp();
4597         if (!filp)
4598                 return ERR_PTR(-ENFILE);
4599 @@ -2356,6 +2483,17 @@ static struct file *path_openat(int dfd,
4600                         filp = do_last(nd, &path, op, pathname);
4601                 put_link(nd, &link, cookie);
4602         }
4603 +
4604 +#ifdef CONFIG_VSERVER_COWBL
4605 +       if (filp == ERR_PTR(-EMLINK)) {
4606 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4607 +                       path_put(&nd->root);
4608 +               if (base)
4609 +                       fput(base);
4610 +               release_open_intent(nd);
4611 +               goto restart;
4612 +       }
4613 +#endif
4614  out:
4615         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4616                 path_put(&nd->root);
4617 @@ -2445,6 +2583,11 @@ struct dentry *kern_path_create(int dfd,
4618                 goto fail;
4619         }
4620         *path = nd.path;
4621 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4622 +               path->dentry, path->dentry->d_name.len,
4623 +               path->dentry->d_name.name, dentry,
4624 +               dentry->d_name.len, dentry->d_name.name,
4625 +               path->dentry->d_inode);
4626         return dentry;
4627  eexist:
4628         dput(dentry);
4629 @@ -2926,7 +3069,7 @@ int vfs_link(struct dentry *old_dentry, 
4630         /*
4631          * A link to an append-only or immutable file cannot be created.
4632          */
4633 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4634 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4635                 return -EPERM;
4636         if (!dir->i_op->link)
4637                 return -EPERM;
4638 @@ -3307,6 +3450,227 @@ int vfs_follow_link(struct nameidata *nd
4639         return __vfs_follow_link(nd, link);
4640  }
4641  
4642 +
4643 +#ifdef CONFIG_VSERVER_COWBL
4644 +
4645 +static inline
4646 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4647 +{
4648 +       loff_t ppos = 0;
4649 +
4650 +       return do_splice_direct(in, &ppos, out, len, 0);
4651 +}
4652 +
4653 +struct dentry *cow_break_link(const char *pathname)
4654 +{
4655 +       int ret, mode, pathlen, redo = 0;
4656 +       struct nameidata old_nd, dir_nd;
4657 +       struct path old_path, dir_path;
4658 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4659 +       struct file *old_file;
4660 +       struct file *new_file;
4661 +       char *to, *path, pad='\251';
4662 +       loff_t size;
4663 +
4664 +       vxdprintk(VXD_CBIT(misc, 1),
4665 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4666 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4667 +       ret = -ENOMEM;
4668 +       if (!path)
4669 +               goto out;
4670 +
4671 +       /* old_nd will have refs to dentry and mnt */
4672 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4673 +       vxdprintk(VXD_CBIT(misc, 2),
4674 +               "do_path_lookup(old): %d [r=%d]",
4675 +               ret, mnt_get_count(old_nd.path.mnt));
4676 +       if (ret < 0)
4677 +               goto out_free_path;
4678 +
4679 +       old_path = old_nd.path;
4680 +       old_dentry = old_path.dentry;
4681 +       mode = old_dentry->d_inode->i_mode;
4682 +
4683 +       to = d_path(&old_path, path, PATH_MAX-2);
4684 +       pathlen = strlen(to);
4685 +       vxdprintk(VXD_CBIT(misc, 2),
4686 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4687 +               old_dentry,
4688 +               old_dentry->d_name.len, old_dentry->d_name.name,
4689 +               old_dentry->d_name.len);
4690 +
4691 +       to[pathlen + 1] = 0;
4692 +retry:
4693 +       new_dentry = NULL;
4694 +       to[pathlen] = pad--;
4695 +       ret = -ELOOP;
4696 +       if (pad <= '\240')
4697 +               goto out_rel_old;
4698 +
4699 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4700 +       /* dir_nd will have refs to dentry and mnt */
4701 +       ret = do_path_lookup(AT_FDCWD, to,
4702 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4703 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4704 +       if (ret < 0)
4705 +               goto retry;
4706 +
4707 +       /* this puppy downs the dir inode mutex if successful */
4708 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4709 +       if (!new_dentry || IS_ERR(new_dentry)) {
4710 +               path_put(&dir_nd.path);
4711 +               vxdprintk(VXD_CBIT(misc, 2),
4712 +                       "kern_path_create(new) failed with %ld",
4713 +                       PTR_ERR(new_dentry));
4714 +               goto retry;
4715 +       }
4716 +       path_put(&dir_path);
4717 +       vxdprintk(VXD_CBIT(misc, 2),
4718 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4719 +               new_dentry,
4720 +               new_dentry->d_name.len, new_dentry->d_name.name,
4721 +               new_dentry->d_name.len);
4722 +
4723 +       dir = dir_nd.path.dentry;
4724 +
4725 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4726 +       vxdprintk(VXD_CBIT(misc, 2),
4727 +               "vfs_create(new): %d", ret);
4728 +       if (ret == -EEXIST) {
4729 +               mutex_unlock(&dir->d_inode->i_mutex);
4730 +               path_put(&dir_nd.path);
4731 +               dput(new_dentry);
4732 +               goto retry;
4733 +       }
4734 +       else if (ret < 0)
4735 +               goto out_unlock_new;
4736 +
4737 +       /* drop out early, ret passes ENOENT */
4738 +       ret = -ENOENT;
4739 +       if ((redo = d_unhashed(old_dentry)))
4740 +               goto out_unlock_new;
4741 +
4742 +       path_get(&old_path);
4743 +       /* this one cleans up the dentry/mnt in case of failure */
4744 +       old_file = dentry_open(old_dentry, old_path.mnt,
4745 +               O_RDONLY, current_cred());
4746 +       vxdprintk(VXD_CBIT(misc, 2),
4747 +               "dentry_open(old): %p", old_file);
4748 +       if (IS_ERR(old_file)) {
4749 +               ret = PTR_ERR(old_file);
4750 +               goto out_unlock_new;
4751 +       }
4752 +
4753 +       dget(new_dentry);
4754 +       mntget(old_path.mnt);
4755 +       /* this one cleans up the dentry/mnt in case of failure */
4756 +       new_file = dentry_open(new_dentry, old_path.mnt,
4757 +               O_WRONLY, current_cred());
4758 +       vxdprintk(VXD_CBIT(misc, 2),
4759 +               "dentry_open(new): %p", new_file);
4760 +       if (IS_ERR(new_file)) {
4761 +               ret = PTR_ERR(new_file);
4762 +               goto out_fput_old;
4763 +       }
4764 +
4765 +       size = i_size_read(old_file->f_dentry->d_inode);
4766 +       ret = do_cow_splice(old_file, new_file, size);
4767 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4768 +       if (ret < 0) {
4769 +               goto out_fput_both;
4770 +       } else if (ret < size) {
4771 +               ret = -ENOSPC;
4772 +               goto out_fput_both;
4773 +       } else {
4774 +               struct inode *old_inode = old_dentry->d_inode;
4775 +               struct inode *new_inode = new_dentry->d_inode;
4776 +               struct iattr attr = {
4777 +                       .ia_uid = old_inode->i_uid,
4778 +                       .ia_gid = old_inode->i_gid,
4779 +                       .ia_valid = ATTR_UID | ATTR_GID
4780 +                       };
4781 +
4782 +               setattr_copy(new_inode, &attr);
4783 +               mark_inode_dirty(new_inode);
4784 +       }
4785 +
4786 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4787 +
4788 +       /* drop out late */
4789 +       ret = -ENOENT;
4790 +       if ((redo = d_unhashed(old_dentry)))
4791 +               goto out_unlock;
4792 +
4793 +       vxdprintk(VXD_CBIT(misc, 2),
4794 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4795 +               new_dentry->d_name.len, new_dentry->d_name.name,
4796 +               new_dentry->d_name.len,
4797 +               old_dentry->d_name.len, old_dentry->d_name.name,
4798 +               old_dentry->d_name.len);
4799 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4800 +               old_dentry->d_parent->d_inode, old_dentry);
4801 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4802 +
4803 +out_unlock:
4804 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4805 +
4806 +out_fput_both:
4807 +       vxdprintk(VXD_CBIT(misc, 3),
4808 +               "fput(new_file=%p[#%ld])", new_file,
4809 +               atomic_long_read(&new_file->f_count));
4810 +       fput(new_file);
4811 +
4812 +out_fput_old:
4813 +       vxdprintk(VXD_CBIT(misc, 3),
4814 +               "fput(old_file=%p[#%ld])", old_file,
4815 +               atomic_long_read(&old_file->f_count));
4816 +       fput(old_file);
4817 +
4818 +out_unlock_new:
4819 +       mutex_unlock(&dir->d_inode->i_mutex);
4820 +       if (!ret)
4821 +               goto out_redo;
4822 +
4823 +       /* error path cleanup */
4824 +       vfs_unlink(dir->d_inode, new_dentry);
4825 +
4826 +out_redo:
4827 +       if (!redo)
4828 +               goto out_rel_both;
4829 +       /* lookup dentry once again */
4830 +       /* old_nd.path is freed as old_path in out_rel_old */
4831 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4832 +       if (ret)
4833 +               goto out_rel_both;
4834 +
4835 +       dput(new_dentry);
4836 +       new_dentry = old_nd.path.dentry;
4837 +       vxdprintk(VXD_CBIT(misc, 2),
4838 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4839 +               new_dentry,
4840 +               new_dentry->d_name.len, new_dentry->d_name.name,
4841 +               new_dentry->d_name.len);
4842 +       dget(new_dentry);
4843 +
4844 +out_rel_both:
4845 +       path_put(&dir_nd.path);
4846 +out_rel_old:
4847 +       path_put(&old_path);
4848 +out_free_path:
4849 +       kfree(path);
4850 +out:
4851 +       if (ret) {
4852 +               dput(new_dentry);
4853 +               new_dentry = ERR_PTR(ret);
4854 +       }
4855 +       vxdprintk(VXD_CBIT(misc, 3),
4856 +               "cow_break_link returning with %p [r=%d]",
4857 +               new_dentry, mnt_get_count(old_nd.path.mnt));
4858 +       return new_dentry;
4859 +}
4860 +
4861 +#endif
4862 +
4863  /* get the link contents into pagecache */
4864  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4865  {
4866 diff -NurpP --minimal linux-3.3.1/fs/namespace.c linux-3.3.1-vs2.3.3.2/fs/namespace.c
4867 --- linux-3.3.1/fs/namespace.c  2012-03-19 19:47:26.000000000 +0100
4868 +++ linux-3.3.1-vs2.3.3.2/fs/namespace.c        2012-02-24 17:38:42.000000000 +0100
4869 @@ -20,6 +20,11 @@
4870  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4871  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4872  #include <linux/uaccess.h>
4873 +#include <linux/vs_base.h>
4874 +#include <linux/vs_context.h>
4875 +#include <linux/vs_tag.h>
4876 +#include <linux/vserver/space.h>
4877 +#include <linux/vserver/global.h>
4878  #include "pnode.h"
4879  #include "internal.h"
4880  
4881 @@ -697,6 +702,10 @@ vfs_kern_mount(struct file_system_type *
4882         if (!type)
4883                 return ERR_PTR(-ENODEV);
4884  
4885 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4886 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4887 +               return ERR_PTR(-EPERM);
4888 +
4889         mnt = alloc_vfsmnt(name);
4890         if (!mnt)
4891                 return ERR_PTR(-ENOMEM);
4892 @@ -745,6 +754,7 @@ static struct mount *clone_mnt(struct mo
4893                 mnt->mnt.mnt_root = dget(root);
4894                 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4895                 mnt->mnt_parent = mnt;
4896 +               mnt->mnt_tag = old->mnt_tag;
4897                 br_write_lock(vfsmount_lock);
4898                 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4899                 br_write_unlock(vfsmount_lock);
4900 @@ -1209,7 +1219,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4901                 goto dput_and_out;
4902  
4903         retval = -EPERM;
4904 -       if (!capable(CAP_SYS_ADMIN))
4905 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4906                 goto dput_and_out;
4907  
4908         retval = do_umount(mnt, flags);
4909 @@ -1235,7 +1245,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4910  
4911  static int mount_is_safe(struct path *path)
4912  {
4913 -       if (capable(CAP_SYS_ADMIN))
4914 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4915                 return 0;
4916         return -EPERM;
4917  #ifdef notyet
4918 @@ -1548,7 +1558,7 @@ static int do_change_type(struct path *p
4919         int type;
4920         int err = 0;
4921  
4922 -       if (!capable(CAP_SYS_ADMIN))
4923 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4924                 return -EPERM;
4925  
4926         if (path->dentry != path->mnt->mnt_root)
4927 @@ -1564,6 +1574,7 @@ static int do_change_type(struct path *p
4928                 if (err)
4929                         goto out_unlock;
4930         }
4931 +       // mnt->mnt_flags = mnt_flags;
4932  
4933         br_write_lock(vfsmount_lock);
4934         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4935 @@ -1579,12 +1590,14 @@ static int do_change_type(struct path *p
4936   * do loopback mount.
4937   */
4938  static int do_loopback(struct path *path, char *old_name,
4939 -                               int recurse)
4940 +       tag_t tag, unsigned long flags, int mnt_flags)
4941  {
4942         LIST_HEAD(umount_list);
4943         struct path old_path;
4944         struct mount *mnt = NULL, *old;
4945         int err = mount_is_safe(path);
4946 +       int recurse = flags & MS_REC;
4947 +
4948         if (err)
4949                 return err;
4950         if (!old_name || !*old_name)
4951 @@ -1652,13 +1665,13 @@ static int change_mount_flags(struct vfs
4952   * on it - tough luck.
4953   */
4954  static int do_remount(struct path *path, int flags, int mnt_flags,
4955 -                     void *data)
4956 +       void *data, xid_t xid)
4957  {
4958         int err;
4959         struct super_block *sb = path->mnt->mnt_sb;
4960         struct mount *mnt = real_mount(path->mnt);
4961  
4962 -       if (!capable(CAP_SYS_ADMIN))
4963 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
4964                 return -EPERM;
4965  
4966         if (!check_mnt(mnt))
4967 @@ -1707,7 +1720,7 @@ static int do_move_mount(struct path *pa
4968         struct mount *p;
4969         struct mount *old;
4970         int err = 0;
4971 -       if (!capable(CAP_SYS_ADMIN))
4972 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4973                 return -EPERM;
4974         if (!old_name || !*old_name)
4975                 return -EINVAL;
4976 @@ -1858,7 +1871,7 @@ static int do_new_mount(struct path *pat
4977                 return -EINVAL;
4978  
4979         /* we need capabilities... */
4980 -       if (!capable(CAP_SYS_ADMIN))
4981 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4982                 return -EPERM;
4983  
4984         mnt = do_kern_mount(type, flags, name, data);
4985 @@ -2128,6 +2141,7 @@ long do_mount(char *dev_name, char *dir_
4986         struct path path;
4987         int retval = 0;
4988         int mnt_flags = 0;
4989 +       tag_t tag = 0;
4990  
4991         /* Discard magic */
4992         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4993 @@ -2155,6 +2169,12 @@ long do_mount(char *dev_name, char *dir_
4994         if (!(flags & MS_NOATIME))
4995                 mnt_flags |= MNT_RELATIME;
4996  
4997 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4998 +               /* FIXME: bind and re-mounts get the tag flag? */
4999 +               if (flags & (MS_BIND|MS_REMOUNT))
5000 +                       flags |= MS_TAGID;
5001 +       }
5002 +
5003         /* Separate the per-mountpoint flags */
5004         if (flags & MS_NOSUID)
5005                 mnt_flags |= MNT_NOSUID;
5006 @@ -2171,15 +2191,17 @@ long do_mount(char *dev_name, char *dir_
5007         if (flags & MS_RDONLY)
5008                 mnt_flags |= MNT_READONLY;
5009  
5010 +       if (!capable(CAP_SYS_ADMIN))
5011 +               mnt_flags |= MNT_NODEV;
5012         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5013                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5014                    MS_STRICTATIME);
5015  
5016         if (flags & MS_REMOUNT)
5017                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5018 -                                   data_page);
5019 +                                   data_page, tag);
5020         else if (flags & MS_BIND)
5021 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5022 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5023         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5024                 retval = do_change_type(&path, flags);
5025         else if (flags & MS_MOVE)
5026 @@ -2282,6 +2304,7 @@ static struct mnt_namespace *dup_mnt_ns(
5027                 q = next_mnt(q, new);
5028         }
5029         up_write(&namespace_sem);
5030 +       atomic_inc(&vs_global_mnt_ns);
5031  
5032         if (rootmnt)
5033                 mntput(rootmnt);
5034 @@ -2478,9 +2501,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5035         error = -EINVAL;
5036         new_mnt = real_mount(new.mnt);
5037         root_mnt = real_mount(root.mnt);
5038 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5039 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5040                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5041 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5042 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5043 +               !vx_flags(VXF_STATE_SETUP, 0))
5044                 goto out4;
5045         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5046                 goto out4;
5047 @@ -2601,6 +2625,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5048         br_write_unlock(vfsmount_lock);
5049         up_write(&namespace_sem);
5050         release_mounts(&umount_list);
5051 +       atomic_dec(&vs_global_mnt_ns);
5052         kfree(ns);
5053  }
5054  
5055 diff -NurpP --minimal linux-3.3.1/fs/nfs/client.c linux-3.3.1-vs2.3.3.2/fs/nfs/client.c
5056 --- linux-3.3.1/fs/nfs/client.c 2012-03-19 19:47:26.000000000 +0100
5057 +++ linux-3.3.1-vs2.3.3.2/fs/nfs/client.c       2012-02-24 03:55:06.000000000 +0100
5058 @@ -784,6 +784,9 @@ static int nfs_init_server_rpcclient(str
5059         if (server->flags & NFS_MOUNT_SOFT)
5060                 server->client->cl_softrtry = 1;
5061  
5062 +       server->client->cl_tag = 0;
5063 +       if (server->flags & NFS_MOUNT_TAGGED)
5064 +               server->client->cl_tag = 1;
5065         return 0;
5066  }
5067  
5068 @@ -958,6 +961,10 @@ static void nfs_server_set_fsinfo(struct
5069                 server->acdirmin = server->acdirmax = 0;
5070         }
5071  
5072 +       /* FIXME: needs fsinfo
5073 +       if (server->flags & NFS_MOUNT_TAGGED)
5074 +               sb->s_flags |= MS_TAGGED;       */
5075 +
5076         server->maxfilesize = fsinfo->maxfilesize;
5077  
5078         server->time_delta = fsinfo->time_delta;
5079 diff -NurpP --minimal linux-3.3.1/fs/nfs/dir.c linux-3.3.1-vs2.3.3.2/fs/nfs/dir.c
5080 --- linux-3.3.1/fs/nfs/dir.c    2012-03-19 19:47:26.000000000 +0100
5081 +++ linux-3.3.1-vs2.3.3.2/fs/nfs/dir.c  2012-02-24 03:55:06.000000000 +0100
5082 @@ -35,6 +35,7 @@
5083  #include <linux/sched.h>
5084  #include <linux/kmemleak.h>
5085  #include <linux/xattr.h>
5086 +#include <linux/vs_tag.h>
5087  
5088  #include "delegation.h"
5089  #include "iostat.h"
5090 @@ -1311,6 +1312,7 @@ static struct dentry *nfs_lookup(struct 
5091         if (IS_ERR(res))
5092                 goto out_unblock_sillyrename;
5093  
5094 +       dx_propagate_tag(nd, inode);
5095  no_entry:
5096         res = d_materialise_unique(dentry, inode);
5097         if (res != NULL) {
5098 diff -NurpP --minimal linux-3.3.1/fs/nfs/inode.c linux-3.3.1-vs2.3.3.2/fs/nfs/inode.c
5099 --- linux-3.3.1/fs/nfs/inode.c  2012-03-19 19:47:26.000000000 +0100
5100 +++ linux-3.3.1-vs2.3.3.2/fs/nfs/inode.c        2012-02-24 04:40:22.000000000 +0100
5101 @@ -39,6 +39,7 @@
5102  #include <linux/slab.h>
5103  #include <linux/compat.h>
5104  #include <linux/freezer.h>
5105 +#include <linux/vs_tag.h>
5106  
5107  #include <asm/system.h>
5108  #include <asm/uaccess.h>
5109 @@ -274,6 +275,8 @@ nfs_fhget(struct super_block *sb, struct
5110         if (inode->i_state & I_NEW) {
5111                 struct nfs_inode *nfsi = NFS_I(inode);
5112                 unsigned long now = jiffies;
5113 +               uid_t uid;
5114 +               gid_t gid;
5115  
5116                 /* We set i_ino for the few things that still rely on it,
5117                  * such as stat(2) */
5118 @@ -322,8 +325,8 @@ nfs_fhget(struct super_block *sb, struct
5119                 inode->i_version = 0;
5120                 inode->i_size = 0;
5121                 clear_nlink(inode);
5122 -               inode->i_uid = -2;
5123 -               inode->i_gid = -2;
5124 +               uid = -2;
5125 +               gid = -2;
5126                 inode->i_blocks = 0;
5127                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5128  
5129 @@ -360,13 +363,13 @@ nfs_fhget(struct super_block *sb, struct
5130                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5131                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5132                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5133 -                       inode->i_uid = fattr->uid;
5134 +                       uid = fattr->uid;
5135                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5136                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5137                                 | NFS_INO_INVALID_ACCESS
5138                                 | NFS_INO_INVALID_ACL;
5139                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5140 -                       inode->i_gid = fattr->gid;
5141 +                       gid = fattr->gid;
5142                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5143                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5144                                 | NFS_INO_INVALID_ACCESS
5145 @@ -379,6 +382,11 @@ nfs_fhget(struct super_block *sb, struct
5146                          */
5147                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5148                 }
5149 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5150 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5151 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5152 +                               /* maybe fattr->xid someday */
5153 +
5154                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5155                 nfsi->attrtimeo_timestamp = now;
5156                 nfsi->access_cache = RB_ROOT;
5157 @@ -495,6 +503,8 @@ void nfs_setattr_update_inode(struct ino
5158                         inode->i_uid = attr->ia_uid;
5159                 if ((attr->ia_valid & ATTR_GID) != 0)
5160                         inode->i_gid = attr->ia_gid;
5161 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5162 +                       inode->i_tag = attr->ia_tag;
5163                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5164                 spin_unlock(&inode->i_lock);
5165         }
5166 @@ -944,6 +954,9 @@ static int nfs_check_inode_attributes(st
5167         struct nfs_inode *nfsi = NFS_I(inode);
5168         loff_t cur_size, new_isize;
5169         unsigned long invalid = 0;
5170 +       uid_t uid;
5171 +       gid_t gid;
5172 +       tag_t tag;
5173  
5174  
5175         /* Has the inode gone and changed behind our back? */
5176 @@ -967,13 +980,18 @@ static int nfs_check_inode_attributes(st
5177                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5178         }
5179  
5180 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5181 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5182 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5183 +
5184         /* Have any file permissions changed? */
5185         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5186                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5187 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5188 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5189                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5190 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5191 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5192                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5193 +               /* maybe check for tag too? */
5194  
5195         /* Has the link count changed? */
5196         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5197 @@ -1210,6 +1228,9 @@ static int nfs_update_inode(struct inode
5198         unsigned long invalid = 0;
5199         unsigned long now = jiffies;
5200         unsigned long save_cache_validity;
5201 +       uid_t uid;
5202 +       gid_t gid;
5203 +       tag_t tag;
5204  
5205         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5206                         __func__, inode->i_sb->s_id, inode->i_ino,
5207 @@ -1317,6 +1338,9 @@ static int nfs_update_inode(struct inode
5208                                 | NFS_INO_REVAL_PAGECACHE
5209                                 | NFS_INO_REVAL_FORCED);
5210  
5211 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5212 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5213 +       tag = inode->i_tag;
5214  
5215         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5216                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5217 @@ -1338,9 +1362,9 @@ static int nfs_update_inode(struct inode
5218                                 | NFS_INO_REVAL_FORCED);
5219  
5220         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5221 -               if (inode->i_uid != fattr->uid) {
5222 +               if (uid != fattr->uid) {
5223                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5224 -                       inode->i_uid = fattr->uid;
5225 +                       uid = fattr->uid;
5226                 }
5227         } else if (server->caps & NFS_CAP_OWNER)
5228                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5229 @@ -1349,9 +1373,9 @@ static int nfs_update_inode(struct inode
5230                                 | NFS_INO_REVAL_FORCED);
5231  
5232         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5233 -               if (inode->i_gid != fattr->gid) {
5234 +               if (gid != fattr->gid) {
5235                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5236 -                       inode->i_gid = fattr->gid;
5237 +                       gid = fattr->gid;
5238                 }
5239         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5240                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5241 @@ -1359,6 +1383,10 @@ static int nfs_update_inode(struct inode
5242                                 | NFS_INO_INVALID_ACL
5243                                 | NFS_INO_REVAL_FORCED);
5244  
5245 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5246 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5247 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5248 +
5249         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5250                 if (inode->i_nlink != fattr->nlink) {
5251                         invalid |= NFS_INO_INVALID_ATTR;
5252 diff -NurpP --minimal linux-3.3.1/fs/nfs/nfs3xdr.c linux-3.3.1-vs2.3.3.2/fs/nfs/nfs3xdr.c
5253 --- linux-3.3.1/fs/nfs/nfs3xdr.c        2011-03-15 18:07:32.000000000 +0100
5254 +++ linux-3.3.1-vs2.3.3.2/fs/nfs/nfs3xdr.c      2012-02-24 03:55:06.000000000 +0100
5255 @@ -20,6 +20,7 @@
5256  #include <linux/nfs3.h>
5257  #include <linux/nfs_fs.h>
5258  #include <linux/nfsacl.h>
5259 +#include <linux/vs_tag.h>
5260  #include "internal.h"
5261  
5262  #define NFSDBG_FACILITY                NFSDBG_XDR
5263 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5264   *             set_mtime       mtime;
5265   *     };
5266   */
5267 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5268 +static void encode_sattr3(struct xdr_stream *xdr,
5269 +       const struct iattr *attr, int tag)
5270  {
5271         u32 nbytes;
5272         __be32 *p;
5273 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5274         } else
5275                 *p++ = xdr_zero;
5276  
5277 -       if (attr->ia_valid & ATTR_UID) {
5278 +       if (attr->ia_valid & ATTR_UID ||
5279 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5280                 *p++ = xdr_one;
5281 -               *p++ = cpu_to_be32(attr->ia_uid);
5282 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5283 +                       attr->ia_uid, attr->ia_tag));
5284         } else
5285                 *p++ = xdr_zero;
5286  
5287 -       if (attr->ia_valid & ATTR_GID) {
5288 +       if (attr->ia_valid & ATTR_GID ||
5289 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5290                 *p++ = xdr_one;
5291 -               *p++ = cpu_to_be32(attr->ia_gid);
5292 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5293 +                       attr->ia_gid, attr->ia_tag));
5294         } else
5295                 *p++ = xdr_zero;
5296  
5297 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5298                                       const struct nfs3_sattrargs *args)
5299  {
5300         encode_nfs_fh3(xdr, args->fh);
5301 -       encode_sattr3(xdr, args->sattr);
5302 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5303         encode_sattrguard3(xdr, args);
5304  }
5305  
5306 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5307   *     };
5308   */
5309  static void encode_createhow3(struct xdr_stream *xdr,
5310 -                             const struct nfs3_createargs *args)
5311 +       const struct nfs3_createargs *args, int tag)
5312  {
5313         encode_uint32(xdr, args->createmode);
5314         switch (args->createmode) {
5315         case NFS3_CREATE_UNCHECKED:
5316         case NFS3_CREATE_GUARDED:
5317 -               encode_sattr3(xdr, args->sattr);
5318 +               encode_sattr3(xdr, args->sattr, tag);
5319                 break;
5320         case NFS3_CREATE_EXCLUSIVE:
5321                 encode_createverf3(xdr, args->verifier);
5322 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5323                                      const struct nfs3_createargs *args)
5324  {
5325         encode_diropargs3(xdr, args->fh, args->name, args->len);
5326 -       encode_createhow3(xdr, args);
5327 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5328  }
5329  
5330  /*
5331 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5332                                     const struct nfs3_mkdirargs *args)
5333  {
5334         encode_diropargs3(xdr, args->fh, args->name, args->len);
5335 -       encode_sattr3(xdr, args->sattr);
5336 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5337  }
5338  
5339  /*
5340 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5341   *     };
5342   */
5343  static void encode_symlinkdata3(struct xdr_stream *xdr,
5344 -                               const struct nfs3_symlinkargs *args)
5345 +       const struct nfs3_symlinkargs *args, int tag)
5346  {
5347 -       encode_sattr3(xdr, args->sattr);
5348 +       encode_sattr3(xdr, args->sattr, tag);
5349         encode_nfspath3(xdr, args->pages, args->pathlen);
5350  }
5351  
5352 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5353                                       const struct nfs3_symlinkargs *args)
5354  {
5355         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5356 -       encode_symlinkdata3(xdr, args);
5357 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5358  }
5359  
5360  /*
5361 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5362   *     };
5363   */
5364  static void encode_devicedata3(struct xdr_stream *xdr,
5365 -                              const struct nfs3_mknodargs *args)
5366 +       const struct nfs3_mknodargs *args, int tag)
5367  {
5368 -       encode_sattr3(xdr, args->sattr);
5369 +       encode_sattr3(xdr, args->sattr, tag);
5370         encode_specdata3(xdr, args->rdev);
5371  }
5372  
5373  static void encode_mknoddata3(struct xdr_stream *xdr,
5374 -                             const struct nfs3_mknodargs *args)
5375 +       const struct nfs3_mknodargs *args, int tag)
5376  {
5377         encode_ftype3(xdr, args->type);
5378         switch (args->type) {
5379         case NF3CHR:
5380         case NF3BLK:
5381 -               encode_devicedata3(xdr, args);
5382 +               encode_devicedata3(xdr, args, tag);
5383                 break;
5384         case NF3SOCK:
5385         case NF3FIFO:
5386 -               encode_sattr3(xdr, args->sattr);
5387 +               encode_sattr3(xdr, args->sattr, tag);
5388                 break;
5389         case NF3REG:
5390         case NF3DIR:
5391 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5392                                     const struct nfs3_mknodargs *args)
5393  {
5394         encode_diropargs3(xdr, args->fh, args->name, args->len);
5395 -       encode_mknoddata3(xdr, args);
5396 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5397  }
5398  
5399  /*
5400 diff -NurpP --minimal linux-3.3.1/fs/nfs/super.c linux-3.3.1-vs2.3.3.2/fs/nfs/super.c
5401 --- linux-3.3.1/fs/nfs/super.c  2012-03-19 19:47:26.000000000 +0100
5402 +++ linux-3.3.1-vs2.3.3.2/fs/nfs/super.c        2012-02-24 03:55:06.000000000 +0100
5403 @@ -52,6 +52,7 @@
5404  #include <linux/nfs_xdr.h>
5405  #include <linux/magic.h>
5406  #include <linux/parser.h>
5407 +#include <linux/vs_tag.h>
5408  
5409  #include <asm/system.h>
5410  #include <asm/uaccess.h>
5411 @@ -86,6 +87,7 @@ enum {
5412         Opt_sharecache, Opt_nosharecache,
5413         Opt_resvport, Opt_noresvport,
5414         Opt_fscache, Opt_nofscache,
5415 +       Opt_tag, Opt_notag,
5416  
5417         /* Mount options that take integer arguments */
5418         Opt_port,
5419 @@ -99,6 +101,7 @@ enum {
5420         Opt_mountvers,
5421         Opt_nfsvers,
5422         Opt_minorversion,
5423 +       Opt_tagid,
5424  
5425         /* Mount options that take string arguments */
5426         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5427 @@ -179,6 +182,10 @@ static const match_table_t nfs_mount_opt
5428         { Opt_fscache_uniq, "fsc=%s" },
5429         { Opt_local_lock, "local_lock=%s" },
5430  
5431 +       { Opt_tag, "tag" },
5432 +       { Opt_notag, "notag" },
5433 +       { Opt_tagid, "tagid=%u" },
5434 +
5435         { Opt_err, NULL }
5436  };
5437  
5438 @@ -649,6 +656,7 @@ static void nfs_show_mount_options(struc
5439                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5440                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5441                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5442 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5443                 { 0, NULL, NULL }
5444         };
5445         const struct proc_nfs_info *nfs_infop;
5446 @@ -1216,6 +1224,14 @@ static int nfs_parse_mount_options(char 
5447                         kfree(mnt->fscache_uniq);
5448                         mnt->fscache_uniq = NULL;
5449                         break;
5450 +#ifndef CONFIG_TAGGING_NONE
5451 +               case Opt_tag:
5452 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5453 +                       break;
5454 +               case Opt_notag:
5455 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5456 +                       break;
5457 +#endif
5458  
5459                 /*
5460                  * options that take numeric values
5461 @@ -1322,6 +1338,12 @@ static int nfs_parse_mount_options(char 
5462                                 goto out_invalid_value;
5463                         mnt->minorversion = option;
5464                         break;
5465 +#ifdef CONFIG_PROPAGATE
5466 +               case Opt_tagid:
5467 +                       /* use args[0] */
5468 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5469 +                       break;
5470 +#endif
5471  
5472                 /*
5473                  * options that take text values
5474 diff -NurpP --minimal linux-3.3.1/fs/nfsd/auth.c linux-3.3.1-vs2.3.3.2/fs/nfsd/auth.c
5475 --- linux-3.3.1/fs/nfsd/auth.c  2010-02-25 11:52:05.000000000 +0100
5476 +++ linux-3.3.1-vs2.3.3.2/fs/nfsd/auth.c        2012-02-24 03:55:06.000000000 +0100
5477 @@ -1,6 +1,7 @@
5478  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5479  
5480  #include <linux/sched.h>
5481 +#include <linux/vs_tag.h>
5482  #include "nfsd.h"
5483  #include "auth.h"
5484  
5485 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5486  
5487         new->fsuid = rqstp->rq_cred.cr_uid;
5488         new->fsgid = rqstp->rq_cred.cr_gid;
5489 +       /* FIXME: this desperately needs a tag :)
5490 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5491 +                       */
5492  
5493         rqgi = rqstp->rq_cred.cr_group_info;
5494  
5495 diff -NurpP --minimal linux-3.3.1/fs/nfsd/nfs3xdr.c linux-3.3.1-vs2.3.3.2/fs/nfsd/nfs3xdr.c
5496 --- linux-3.3.1/fs/nfsd/nfs3xdr.c       2011-07-22 11:18:05.000000000 +0200
5497 +++ linux-3.3.1-vs2.3.3.2/fs/nfsd/nfs3xdr.c     2012-02-24 03:55:06.000000000 +0100
5498 @@ -7,6 +7,7 @@
5499   */
5500  
5501  #include <linux/namei.h>
5502 +#include <linux/vs_tag.h>
5503  #include "xdr3.h"
5504  #include "auth.h"
5505  
5506 @@ -95,6 +96,8 @@ static __be32 *
5507  decode_sattr3(__be32 *p, struct iattr *iap)
5508  {
5509         u32     tmp;
5510 +       uid_t   uid = 0;
5511 +       gid_t   gid = 0;
5512  
5513         iap->ia_valid = 0;
5514  
5515 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5516         }
5517         if (*p++) {
5518                 iap->ia_valid |= ATTR_UID;
5519 -               iap->ia_uid = ntohl(*p++);
5520 +               uid = ntohl(*p++);
5521         }
5522         if (*p++) {
5523                 iap->ia_valid |= ATTR_GID;
5524 -               iap->ia_gid = ntohl(*p++);
5525 +               gid = ntohl(*p++);
5526         }
5527 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5528 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5529 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5530         if (*p++) {
5531                 u64     newsize;
5532  
5533 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5534         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5535         *p++ = htonl((u32) stat->mode);
5536         *p++ = htonl((u32) stat->nlink);
5537 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5538 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5539 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5540 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5541 +               stat->uid, stat->tag)));
5542 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5543 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5544 +               stat->gid, stat->tag)));
5545         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5546                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5547         } else {
5548 diff -NurpP --minimal linux-3.3.1/fs/nfsd/nfs4xdr.c linux-3.3.1-vs2.3.3.2/fs/nfsd/nfs4xdr.c
5549 --- linux-3.3.1/fs/nfsd/nfs4xdr.c       2012-03-19 19:47:26.000000000 +0100
5550 +++ linux-3.3.1-vs2.3.3.2/fs/nfsd/nfs4xdr.c     2012-02-24 03:55:06.000000000 +0100
5551 @@ -46,6 +46,7 @@
5552  #include <linux/utsname.h>
5553  #include <linux/pagemap.h>
5554  #include <linux/sunrpc/svcauth_gss.h>
5555 +#include <linux/vs_tag.h>
5556  
5557  #include "idmap.h"
5558  #include "acl.h"
5559 @@ -2327,14 +2328,18 @@ out_acl:
5560                 WRITE32(stat.nlink);
5561         }
5562         if (bmval1 & FATTR4_WORD1_OWNER) {
5563 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5564 +               status = nfsd4_encode_user(rqstp,
5565 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5566 +                       stat.uid, stat.tag), &p, &buflen);
5567                 if (status == nfserr_resource)
5568                         goto out_resource;
5569                 if (status)
5570                         goto out;
5571         }
5572         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5573 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5574 +               status = nfsd4_encode_group(rqstp,
5575 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5576 +                       stat.gid, stat.tag), &p, &buflen);
5577                 if (status == nfserr_resource)
5578                         goto out_resource;
5579                 if (status)
5580 diff -NurpP --minimal linux-3.3.1/fs/nfsd/nfsxdr.c linux-3.3.1-vs2.3.3.2/fs/nfsd/nfsxdr.c
5581 --- linux-3.3.1/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5582 +++ linux-3.3.1-vs2.3.3.2/fs/nfsd/nfsxdr.c      2012-02-24 03:55:06.000000000 +0100
5583 @@ -6,6 +6,7 @@
5584  
5585  #include "xdr.h"
5586  #include "auth.h"
5587 +#include <linux/vs_tag.h>
5588  
5589  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5590  
5591 @@ -88,6 +89,8 @@ static __be32 *
5592  decode_sattr(__be32 *p, struct iattr *iap)
5593  {
5594         u32     tmp, tmp1;
5595 +       uid_t   uid = 0;
5596 +       gid_t   gid = 0;
5597  
5598         iap->ia_valid = 0;
5599  
5600 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5601         }
5602         if ((tmp = ntohl(*p++)) != (u32)-1) {
5603                 iap->ia_valid |= ATTR_UID;
5604 -               iap->ia_uid = tmp;
5605 +               uid = tmp;
5606         }
5607         if ((tmp = ntohl(*p++)) != (u32)-1) {
5608                 iap->ia_valid |= ATTR_GID;
5609 -               iap->ia_gid = tmp;
5610 +               gid = tmp;
5611         }
5612 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5613 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5614 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5615         if ((tmp = ntohl(*p++)) != (u32)-1) {
5616                 iap->ia_valid |= ATTR_SIZE;
5617                 iap->ia_size = tmp;
5618 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5619         *p++ = htonl(nfs_ftypes[type >> 12]);
5620         *p++ = htonl((u32) stat->mode);
5621         *p++ = htonl((u32) stat->nlink);
5622 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5623 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5624 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5625 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5626 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5627 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5628  
5629         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5630                 *p++ = htonl(NFS_MAXPATHLEN);
5631 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/dlmglue.c linux-3.3.1-vs2.3.3.2/fs/ocfs2/dlmglue.c
5632 --- linux-3.3.1/fs/ocfs2/dlmglue.c      2012-01-09 16:14:55.000000000 +0100
5633 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/dlmglue.c    2012-02-24 03:55:06.000000000 +0100
5634 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5635         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5636         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5637         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5638 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5639         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5640         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5641         lvb->lvb_iatime_packed  =
5642 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5643  
5644         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5645         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5646 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5647         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5648         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5649         ocfs2_unpack_timespec(&inode->i_atime,
5650 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/dlmglue.h linux-3.3.1-vs2.3.3.2/fs/ocfs2/dlmglue.h
5651 --- linux-3.3.1/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5652 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/dlmglue.h    2012-02-24 03:55:06.000000000 +0100
5653 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5654         __be16       lvb_inlink;
5655         __be32       lvb_iattr;
5656         __be32       lvb_igeneration;
5657 -       __be32       lvb_reserved2;
5658 +       __be16       lvb_itag;
5659 +       __be16       lvb_reserved2;
5660  };
5661  
5662  #define OCFS2_QINFO_LVB_VERSION 1
5663 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/file.c linux-3.3.1-vs2.3.3.2/fs/ocfs2/file.c
5664 --- linux-3.3.1/fs/ocfs2/file.c 2012-03-19 19:47:26.000000000 +0100
5665 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/file.c       2012-02-24 03:55:06.000000000 +0100
5666 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5667                 attr->ia_valid &= ~ATTR_SIZE;
5668  
5669  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5670 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5671 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5672         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5673                 return 0;
5674  
5675 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/inode.c linux-3.3.1-vs2.3.3.2/fs/ocfs2/inode.c
5676 --- linux-3.3.1/fs/ocfs2/inode.c        2012-01-09 16:14:55.000000000 +0100
5677 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/inode.c      2012-02-24 03:55:06.000000000 +0100
5678 @@ -28,6 +28,7 @@
5679  #include <linux/highmem.h>
5680  #include <linux/pagemap.h>
5681  #include <linux/quotaops.h>
5682 +#include <linux/vs_tag.h>
5683  
5684  #include <asm/byteorder.h>
5685  
5686 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5687  {
5688         unsigned int flags = OCFS2_I(inode)->ip_attr;
5689  
5690 -       inode->i_flags &= ~(S_IMMUTABLE |
5691 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5692                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5693  
5694         if (flags & OCFS2_IMMUTABLE_FL)
5695                 inode->i_flags |= S_IMMUTABLE;
5696 +       if (flags & OCFS2_IXUNLINK_FL)
5697 +               inode->i_flags |= S_IXUNLINK;
5698  
5699         if (flags & OCFS2_SYNC_FL)
5700                 inode->i_flags |= S_SYNC;
5701 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5702                 inode->i_flags |= S_NOATIME;
5703         if (flags & OCFS2_DIRSYNC_FL)
5704                 inode->i_flags |= S_DIRSYNC;
5705 +
5706 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5707 +
5708 +       if (flags & OCFS2_BARRIER_FL)
5709 +               inode->i_vflags |= V_BARRIER;
5710 +       if (flags & OCFS2_COW_FL)
5711 +               inode->i_vflags |= V_COW;
5712  }
5713  
5714  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5715  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5716  {
5717         unsigned int flags = oi->vfs_inode.i_flags;
5718 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5719 +
5720 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5721 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5722 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5723 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5724 +
5725 +       if (flags & S_IMMUTABLE)
5726 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5727 +       if (flags & S_IXUNLINK)
5728 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5729  
5730 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5731 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5732         if (flags & S_SYNC)
5733                 oi->ip_attr |= OCFS2_SYNC_FL;
5734         if (flags & S_APPEND)
5735                 oi->ip_attr |= OCFS2_APPEND_FL;
5736 -       if (flags & S_IMMUTABLE)
5737 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5738         if (flags & S_NOATIME)
5739                 oi->ip_attr |= OCFS2_NOATIME_FL;
5740         if (flags & S_DIRSYNC)
5741                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5742 +
5743 +       if (vflags & V_BARRIER)
5744 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5745 +       if (vflags & V_COW)
5746 +               oi->ip_attr |= OCFS2_COW_FL;
5747  }
5748  
5749  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5750 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5751         struct super_block *sb;
5752         struct ocfs2_super *osb;
5753         int use_plocks = 1;
5754 +       uid_t uid;
5755 +       gid_t gid;
5756  
5757         sb = inode->i_sb;
5758         osb = OCFS2_SB(sb);
5759 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5760         inode->i_generation = le32_to_cpu(fe->i_generation);
5761         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5762         inode->i_mode = le16_to_cpu(fe->i_mode);
5763 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5764 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5765 +       uid = le32_to_cpu(fe->i_uid);
5766 +       gid = le32_to_cpu(fe->i_gid);
5767 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5768 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5769 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5770 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5771  
5772         /* Fast symlinks will have i_size but no allocated clusters. */
5773         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5774 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/inode.h linux-3.3.1-vs2.3.3.2/fs/ocfs2/inode.h
5775 --- linux-3.3.1/fs/ocfs2/inode.h        2012-01-09 16:14:55.000000000 +0100
5776 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/inode.h      2012-02-24 03:55:06.000000000 +0100
5777 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5778  
5779  void ocfs2_set_inode_flags(struct inode *inode);
5780  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5781 +int ocfs2_sync_flags(struct inode *inode, int, int);
5782  
5783  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5784  {
5785 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/ioctl.c linux-3.3.1-vs2.3.3.2/fs/ocfs2/ioctl.c
5786 --- linux-3.3.1/fs/ocfs2/ioctl.c        2012-03-19 19:47:26.000000000 +0100
5787 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/ioctl.c      2012-02-24 03:55:06.000000000 +0100
5788 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
5789         return status;
5790  }
5791  
5792 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5793 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5794 +{
5795 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5796 +       struct buffer_head *bh = NULL;
5797 +       handle_t *handle = NULL;
5798 +       int status;
5799 +
5800 +       status = ocfs2_inode_lock(inode, &bh, 1);
5801 +       if (status < 0) {
5802 +               mlog_errno(status);
5803 +               return status;
5804 +       }
5805 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5806 +       if (IS_ERR(handle)) {
5807 +               status = PTR_ERR(handle);
5808 +               mlog_errno(status);
5809 +               goto bail_unlock;
5810 +       }
5811 +
5812 +       inode->i_flags = flags;
5813 +       inode->i_vflags = vflags;
5814 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5815 +
5816 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5817 +       if (status < 0)
5818 +               mlog_errno(status);
5819 +
5820 +       ocfs2_commit_trans(osb, handle);
5821 +bail_unlock:
5822 +       ocfs2_inode_unlock(inode, 1);
5823 +       brelse(bh);
5824 +       return status;
5825 +}
5826 +
5827 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5828                                 unsigned mask)
5829  {
5830         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5831 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
5832         if (!S_ISDIR(inode->i_mode))
5833                 flags &= ~OCFS2_DIRSYNC_FL;
5834  
5835 +       if (IS_BARRIER(inode)) {
5836 +               vxwprintk_task(1, "messing with the barrier.");
5837 +               goto bail_unlock;
5838 +       }
5839 +
5840         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5841         if (IS_ERR(handle)) {
5842                 status = PTR_ERR(handle);
5843 @@ -881,6 +920,7 @@ bail:
5844         return status;
5845  }
5846  
5847 +
5848  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5849  {
5850         struct inode *inode = filp->f_path.dentry->d_inode;
5851 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/namei.c linux-3.3.1-vs2.3.3.2/fs/ocfs2/namei.c
5852 --- linux-3.3.1/fs/ocfs2/namei.c        2012-03-19 19:47:26.000000000 +0100
5853 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/namei.c      2012-03-19 20:52:10.000000000 +0100
5854 @@ -41,6 +41,7 @@
5855  #include <linux/slab.h>
5856  #include <linux/highmem.h>
5857  #include <linux/quotaops.h>
5858 +#include <linux/vs_tag.h>
5859  
5860  #include <cluster/masklog.h>
5861  
5862 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5863         struct ocfs2_dinode *fe = NULL;
5864         struct ocfs2_extent_list *fel;
5865         u16 feat;
5866 +       tag_t tag;
5867  
5868         *new_fe_bh = NULL;
5869  
5870 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5871         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5872         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5873         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5874 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5875 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5876 +
5877 +       tag = dx_current_fstag(osb->sb);
5878 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5879 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5880 +       inode->i_tag = tag;
5881         fe->i_mode = cpu_to_le16(inode->i_mode);
5882         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5883                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5884 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/ocfs2.h linux-3.3.1-vs2.3.3.2/fs/ocfs2/ocfs2.h
5885 --- linux-3.3.1/fs/ocfs2/ocfs2.h        2012-01-09 16:14:55.000000000 +0100
5886 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/ocfs2.h      2012-02-24 03:55:06.000000000 +0100
5887 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5888                                                      writes */
5889         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5890         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5891 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5892  };
5893  
5894  #define OCFS2_OSB_SOFT_RO                      0x0001
5895 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/ocfs2_fs.h linux-3.3.1-vs2.3.3.2/fs/ocfs2/ocfs2_fs.h
5896 --- linux-3.3.1/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
5897 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/ocfs2_fs.h   2012-02-24 03:55:06.000000000 +0100
5898 @@ -266,6 +266,11 @@
5899  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5900  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5901  
5902 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5903 +
5904 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5905 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5906 +
5907  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5908  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5909  
5910 diff -NurpP --minimal linux-3.3.1/fs/ocfs2/super.c linux-3.3.1-vs2.3.3.2/fs/ocfs2/super.c
5911 --- linux-3.3.1/fs/ocfs2/super.c        2012-03-19 19:47:26.000000000 +0100
5912 +++ linux-3.3.1-vs2.3.3.2/fs/ocfs2/super.c      2012-02-24 03:55:06.000000000 +0100
5913 @@ -185,6 +185,7 @@ enum {
5914         Opt_coherency_full,
5915         Opt_resv_level,
5916         Opt_dir_resv_level,
5917 +       Opt_tag, Opt_notag, Opt_tagid,
5918         Opt_err,
5919  };
5920  
5921 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5922         {Opt_coherency_full, "coherency=full"},
5923         {Opt_resv_level, "resv_level=%u"},
5924         {Opt_dir_resv_level, "dir_resv_level=%u"},
5925 +       {Opt_tag, "tag"},
5926 +       {Opt_notag, "notag"},
5927 +       {Opt_tagid, "tagid=%u"},
5928         {Opt_err, NULL}
5929  };
5930  
5931 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5932                 goto out;
5933         }
5934  
5935 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5936 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5937 +               ret = -EINVAL;
5938 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5939 +               goto out;
5940 +       }
5941 +
5942         /* We're going to/from readonly mode. */
5943         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5944                 /* Disable quota accounting before remounting RO */
5945 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5946  
5947         ocfs2_complete_mount_recovery(osb);
5948  
5949 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5950 +               sb->s_flags |= MS_TAGGED;
5951 +
5952         if (ocfs2_mount_local(osb))
5953                 snprintf(nodestr, sizeof(nodestr), "local");
5954         else
5955 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
5956                             option < OCFS2_MAX_RESV_LEVEL)
5957                                 mopt->dir_resv_level = option;
5958                         break;
5959 +#ifndef CONFIG_TAGGING_NONE
5960 +               case Opt_tag:
5961 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5962 +                       break;
5963 +               case Opt_notag:
5964 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5965 +                       break;
5966 +#endif
5967 +#ifdef CONFIG_PROPAGATE
5968 +               case Opt_tagid:
5969 +                       /* use args[0] */
5970 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5971 +                       break;
5972 +#endif
5973                 default:
5974                         mlog(ML_ERROR,
5975                              "Unrecognized mount option \"%s\" "
5976 diff -NurpP --minimal linux-3.3.1/fs/open.c linux-3.3.1-vs2.3.3.2/fs/open.c
5977 --- linux-3.3.1/fs/open.c       2012-03-19 19:47:26.000000000 +0100
5978 +++ linux-3.3.1-vs2.3.3.2/fs/open.c     2012-02-24 03:55:06.000000000 +0100
5979 @@ -30,6 +30,11 @@
5980  #include <linux/fs_struct.h>
5981  #include <linux/ima.h>
5982  #include <linux/dnotify.h>
5983 +#include <linux/vs_base.h>
5984 +#include <linux/vs_limit.h>
5985 +#include <linux/vs_tag.h>
5986 +#include <linux/vs_cowbl.h>
5987 +#include <linux/vserver/dlimit.h>
5988  
5989  #include "internal.h"
5990  
5991 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
5992         error = user_path(pathname, &path);
5993         if (error)
5994                 goto out;
5995 +
5996 +#ifdef CONFIG_VSERVER_COWBL
5997 +       error = cow_check_and_break(&path);
5998 +       if (error)
5999 +               goto dput_and_out;
6000 +#endif
6001         inode = path.dentry->d_inode;
6002  
6003         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6004 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6005  
6006         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6007         if (!error) {
6008 +#ifdef CONFIG_VSERVER_COWBL
6009 +               error = cow_check_and_break(&path);
6010 +               if (!error)
6011 +#endif
6012                 error = chmod_common(&path, mode);
6013                 path_put(&path);
6014         }
6015 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6016         newattrs.ia_valid =  ATTR_CTIME;
6017         if (user != (uid_t) -1) {
6018                 newattrs.ia_valid |= ATTR_UID;
6019 -               newattrs.ia_uid = user;
6020 +               newattrs.ia_uid = dx_map_uid(user);
6021         }
6022         if (group != (gid_t) -1) {
6023                 newattrs.ia_valid |= ATTR_GID;
6024 -               newattrs.ia_gid = group;
6025 +               newattrs.ia_gid = dx_map_gid(group);
6026         }
6027         if (!S_ISDIR(inode->i_mode))
6028                 newattrs.ia_valid |=
6029 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6030         error = mnt_want_write(path.mnt);
6031         if (error)
6032                 goto out_release;
6033 +#ifdef CONFIG_VSERVER_COWBL
6034 +       error = cow_check_and_break(&path);
6035 +       if (!error)
6036 +#endif
6037         error = chown_common(&path, user, group);
6038         mnt_drop_write(path.mnt);
6039  out_release:
6040 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6041         error = mnt_want_write(path.mnt);
6042         if (error)
6043                 goto out_release;
6044 +#ifdef CONFIG_VSERVER_COWBL
6045 +       error = cow_check_and_break(&path);
6046 +       if (!error)
6047 +#endif
6048         error = chown_common(&path, user, group);
6049         mnt_drop_write(path.mnt);
6050  out_release:
6051 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6052         error = mnt_want_write(path.mnt);
6053         if (error)
6054                 goto out_release;
6055 +#ifdef CONFIG_VSERVER_COWBL
6056 +       error = cow_check_and_break(&path);
6057 +       if (!error)
6058 +#endif
6059         error = chown_common(&path, user, group);
6060         mnt_drop_write(path.mnt);
6061  out_release:
6062 @@ -839,6 +866,7 @@ static void __put_unused_fd(struct files
6063         __FD_CLR(fd, fdt->open_fds);
6064         if (fd < files->next_fd)
6065                 files->next_fd = fd;
6066 +       vx_openfd_dec(fd);
6067  }
6068  
6069  void put_unused_fd(unsigned int fd)
6070 diff -NurpP --minimal linux-3.3.1/fs/proc/array.c linux-3.3.1-vs2.3.3.2/fs/proc/array.c
6071 --- linux-3.3.1/fs/proc/array.c 2012-03-19 19:47:26.000000000 +0100
6072 +++ linux-3.3.1-vs2.3.3.2/fs/proc/array.c       2012-02-24 03:55:06.000000000 +0100
6073 @@ -81,6 +81,8 @@
6074  #include <linux/pid_namespace.h>
6075  #include <linux/ptrace.h>
6076  #include <linux/tracehook.h>
6077 +#include <linux/vs_context.h>
6078 +#include <linux/vs_network.h>
6079  
6080  #include <asm/pgtable.h>
6081  #include <asm/processor.h>
6082 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6083         rcu_read_lock();
6084         ppid = pid_alive(p) ?
6085                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6086 +       if (unlikely(vx_current_initpid(p->pid)))
6087 +               ppid = 0;
6088 +
6089         tpid = 0;
6090         if (pid_alive(p)) {
6091                 struct task_struct *tracer = ptrace_parent(p);
6092 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6093  }
6094  
6095  static void render_cap_t(struct seq_file *m, const char *header,
6096 -                       kernel_cap_t *a)
6097 +                       struct vx_info *vxi, kernel_cap_t *a)
6098  {
6099         unsigned __capi;
6100  
6101 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6102         cap_bset        = cred->cap_bset;
6103         rcu_read_unlock();
6104  
6105 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6106 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6107 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6108 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6109 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6110 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6111 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6112 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6113 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6114  }
6115  
6116  static inline void task_context_switch_counts(struct seq_file *m,
6117 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6118         seq_putc(m, '\n');
6119  }
6120  
6121 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6122 +                       struct pid *pid, struct task_struct *task)
6123 +{
6124 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6125 +                       "Count:\t%u\n"
6126 +                       "uts:\t%p(%c)\n"
6127 +                       "ipc:\t%p(%c)\n"
6128 +                       "mnt:\t%p(%c)\n"
6129 +                       "pid:\t%p(%c)\n"
6130 +                       "net:\t%p(%c)\n",
6131 +                       task->nsproxy,
6132 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6133 +                       atomic_read(&task->nsproxy->count),
6134 +                       task->nsproxy->uts_ns,
6135 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6136 +                       task->nsproxy->ipc_ns,
6137 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6138 +                       task->nsproxy->mnt_ns,
6139 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6140 +                       task->nsproxy->pid_ns,
6141 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6142 +                       task->nsproxy->net_ns,
6143 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6144 +       return 0;
6145 +}
6146 +
6147 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6148 +{
6149 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6150 +               return;
6151 +
6152 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6153 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6154 +}
6155 +
6156 +
6157  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6158                         struct pid *pid, struct task_struct *task)
6159  {
6160 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6161         task_cap(m, task);
6162         task_cpus_allowed(m, task);
6163         cpuset_task_status_allowed(m, task);
6164 +       task_vs_id(m, task);
6165         task_context_switch_counts(m, task);
6166         return 0;
6167  }
6168 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6169         /* convert nsec -> ticks */
6170         start_time = nsec_to_clock_t(start_time);
6171  
6172 +       /* fixup start time for virt uptime */
6173 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6174 +               unsigned long long bias =
6175 +                       current->vx_info->cvirt.bias_clock;
6176 +
6177 +               if (start_time > bias)
6178 +                       start_time -= bias;
6179 +               else
6180 +                       start_time = 0;
6181 +       }
6182 +
6183         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6184  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6185  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld %lu %lu %lu\n",
6186 diff -NurpP --minimal linux-3.3.1/fs/proc/base.c linux-3.3.1-vs2.3.3.2/fs/proc/base.c
6187 --- linux-3.3.1/fs/proc/base.c  2012-03-19 19:47:26.000000000 +0100
6188 +++ linux-3.3.1-vs2.3.3.2/fs/proc/base.c        2012-02-24 04:45:58.000000000 +0100
6189 @@ -84,6 +84,8 @@
6190  #include <linux/fs_struct.h>
6191  #include <linux/slab.h>
6192  #include <linux/flex_array.h>
6193 +#include <linux/vs_context.h>
6194 +#include <linux/vs_network.h>
6195  #ifdef CONFIG_HARDWALL
6196  #include <asm/hardwall.h>
6197  #endif
6198 @@ -937,11 +939,16 @@ static ssize_t oom_adjust_write(struct f
6199                 goto err_task_lock;
6200         }
6201  
6202 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6203 +       if (oom_adjust < task->signal->oom_adj &&
6204 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6205                 err = -EACCES;
6206                 goto err_sighand;
6207         }
6208  
6209 +       /* prevent guest processes from circumventing the oom killer */
6210 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6211 +               oom_adjust = OOM_ADJUST_MIN;
6212 +
6213         /*
6214          * Warn that /proc/pid/oom_adj is deprecated, see
6215          * Documentation/feature-removal-schedule.txt.
6216 @@ -1542,6 +1549,8 @@ struct inode *proc_pid_make_inode(struct
6217                 inode->i_gid = cred->egid;
6218                 rcu_read_unlock();
6219         }
6220 +       /* procfs is xid tagged */
6221 +       inode->i_tag = (tag_t)vx_task_xid(task);
6222         security_task_to_inode(task, inode);
6223  
6224  out:
6225 @@ -1587,6 +1596,8 @@ int pid_getattr(struct vfsmount *mnt, st
6226  
6227  /* dentry stuff */
6228  
6229 +static unsigned name_to_int(struct dentry *dentry);
6230 +
6231  /*
6232   *     Exceptional case: normally we are not allowed to unhash a busy
6233   * directory. In this case, however, we can do it - no aliasing problems
6234 @@ -1615,6 +1626,12 @@ int pid_revalidate(struct dentry *dentry
6235         task = get_proc_task(inode);
6236  
6237         if (task) {
6238 +               unsigned pid = name_to_int(dentry);
6239 +
6240 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6241 +                       put_task_struct(task);
6242 +                       goto drop;
6243 +               }
6244                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6245                     task_dumpable(task)) {
6246                         rcu_read_lock();
6247 @@ -1631,6 +1648,7 @@ int pid_revalidate(struct dentry *dentry
6248                 put_task_struct(task);
6249                 return 1;
6250         }
6251 +drop:
6252         d_drop(dentry);
6253         return 0;
6254  }
6255 @@ -2469,6 +2487,13 @@ static struct dentry *proc_pident_lookup
6256         if (!task)
6257                 goto out_no_task;
6258  
6259 +       /* TODO: maybe we can come up with a generic approach? */
6260 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6261 +               (dentry->d_name.len == 5) &&
6262 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6263 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6264 +               goto out;
6265 +
6266         /*
6267          * Yes, it does not scale. And it should not. Don't add
6268          * new entries into /proc/<tgid>/ without very good reasons.
6269 @@ -2854,7 +2879,7 @@ out_iput:
6270  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6271  {
6272         struct dentry *error;
6273 -       struct task_struct *task = get_proc_task(dir);
6274 +       struct task_struct *task = get_proc_task_real(dir);
6275         const struct pid_entry *p, *last;
6276  
6277         error = ERR_PTR(-ENOENT);
6278 @@ -2961,6 +2986,9 @@ static int proc_pid_personality(struct s
6279  static const struct file_operations proc_task_operations;
6280  static const struct inode_operations proc_task_inode_operations;
6281  
6282 +extern int proc_pid_vx_info(struct task_struct *, char *);
6283 +extern int proc_pid_nx_info(struct task_struct *, char *);
6284 +
6285  static const struct pid_entry tgid_base_stuff[] = {
6286         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6287         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6288 @@ -3027,6 +3055,8 @@ static const struct pid_entry tgid_base_
6289  #ifdef CONFIG_CGROUPS
6290         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6291  #endif
6292 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6293 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6294         INF("oom_score",  S_IRUGO, proc_oom_score),
6295         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6296         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6297 @@ -3046,6 +3076,7 @@ static const struct pid_entry tgid_base_
6298  #ifdef CONFIG_HARDWALL
6299         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6300  #endif
6301 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6302  };
6303  
6304  static int proc_tgid_base_readdir(struct file * filp,
6305 @@ -3239,7 +3270,7 @@ retry:
6306         iter.task = NULL;
6307         pid = find_ge_pid(iter.tgid, ns);
6308         if (pid) {
6309 -               iter.tgid = pid_nr_ns(pid, ns);
6310 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6311                 iter.task = pid_task(pid, PIDTYPE_PID);
6312                 /* What we to know is if the pid we have find is the
6313                  * pid of a thread_group_leader.  Testing for task
6314 @@ -3269,7 +3300,7 @@ static int proc_pid_fill_cache(struct fi
6315         struct tgid_iter iter)
6316  {
6317         char name[PROC_NUMBUF];
6318 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6319 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6320         return proc_fill_cache(filp, dirent, filldir, name, len,
6321                                 proc_pid_instantiate, iter.task, NULL);
6322  }
6323 @@ -3293,7 +3324,7 @@ int proc_pid_readdir(struct file * filp,
6324                 goto out_no_task;
6325         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6326  
6327 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6328 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6329         if (!reaper)
6330                 goto out_no_task;
6331  
6332 @@ -3315,6 +3346,8 @@ int proc_pid_readdir(struct file * filp,
6333                         __filldir = fake_filldir;
6334  
6335                 filp->f_pos = iter.tgid + TGID_OFFSET;
6336 +               if (!vx_proc_task_visible(iter.task))
6337 +                       continue;
6338                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6339                         put_task_struct(iter.task);
6340                         goto out;
6341 @@ -3468,6 +3501,8 @@ static struct dentry *proc_task_lookup(s
6342         tid = name_to_int(dentry);
6343         if (tid == ~0U)
6344                 goto out;
6345 +       if (vx_current_initpid(tid))
6346 +               goto out;
6347  
6348         ns = dentry->d_sb->s_fs_info;
6349         rcu_read_lock();
6350 diff -NurpP --minimal linux-3.3.1/fs/proc/generic.c linux-3.3.1-vs2.3.3.2/fs/proc/generic.c
6351 --- linux-3.3.1/fs/proc/generic.c       2012-03-19 19:47:26.000000000 +0100
6352 +++ linux-3.3.1-vs2.3.3.2/fs/proc/generic.c     2012-02-24 03:55:06.000000000 +0100
6353 @@ -22,6 +22,7 @@
6354  #include <linux/bitops.h>
6355  #include <linux/spinlock.h>
6356  #include <linux/completion.h>
6357 +#include <linux/vserver/inode.h>
6358  #include <asm/uaccess.h>
6359  
6360  #include "internal.h"
6361 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6362         for (de = de->subdir; de ; de = de->next) {
6363                 if (de->namelen != dentry->d_name.len)
6364                         continue;
6365 +               if (!vx_hide_check(0, de->vx_flags))
6366 +                       continue;
6367                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6368                         pde_get(de);
6369                         spin_unlock(&proc_subdir_lock);
6370                         error = -EINVAL;
6371                         inode = proc_get_inode(dir->i_sb, de);
6372 +                       /* generic proc entries belong to the host */
6373 +                       inode->i_tag = 0;
6374                         goto out_unlock;
6375                 }
6376         }
6377 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6378  
6379                                 /* filldir passes info to user space */
6380                                 pde_get(de);
6381 +                               if (!vx_hide_check(0, de->vx_flags))
6382 +                                       goto skip;
6383                                 spin_unlock(&proc_subdir_lock);
6384                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6385                                             de->low_ino, de->mode >> 12) < 0) {
6386 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6387                                         goto out;
6388                                 }
6389                                 spin_lock(&proc_subdir_lock);
6390 +                       skip:
6391                                 filp->f_pos++;
6392                                 next = de->next;
6393                                 pde_put(de);
6394 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6395         ent->nlink = nlink;
6396         atomic_set(&ent->count, 1);
6397         ent->pde_users = 0;
6398 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6399         spin_lock_init(&ent->pde_unload_lock);
6400         ent->pde_unload_completion = NULL;
6401         INIT_LIST_HEAD(&ent->pde_openers);
6402 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6403                                 kfree(ent->data);
6404                                 kfree(ent);
6405                                 ent = NULL;
6406 -                       }
6407 +                       } else
6408 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6409                 } else {
6410                         kfree(ent);
6411                         ent = NULL;
6412 diff -NurpP --minimal linux-3.3.1/fs/proc/inode.c linux-3.3.1-vs2.3.3.2/fs/proc/inode.c
6413 --- linux-3.3.1/fs/proc/inode.c 2012-03-19 19:47:26.000000000 +0100
6414 +++ linux-3.3.1-vs2.3.3.2/fs/proc/inode.c       2012-02-24 03:55:06.000000000 +0100
6415 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
6416                         inode->i_uid = de->uid;
6417                         inode->i_gid = de->gid;
6418                 }
6419 +               if (de->vx_flags)
6420 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6421                 if (de->size)
6422                         inode->i_size = de->size;
6423                 if (de->nlink)
6424 diff -NurpP --minimal linux-3.3.1/fs/proc/internal.h linux-3.3.1-vs2.3.3.2/fs/proc/internal.h
6425 --- linux-3.3.1/fs/proc/internal.h      2012-03-19 19:47:26.000000000 +0100
6426 +++ linux-3.3.1-vs2.3.3.2/fs/proc/internal.h    2012-02-24 03:55:06.000000000 +0100
6427 @@ -10,6 +10,7 @@
6428   */
6429  
6430  #include <linux/proc_fs.h>
6431 +#include <linux/vs_pid.h>
6432  
6433  extern struct proc_dir_entry proc_root;
6434  #ifdef CONFIG_PROC_SYSCTL
6435 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6436                                 struct pid *pid, struct task_struct *task);
6437  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6438                                 struct pid *pid, struct task_struct *task);
6439 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6440 +                               struct pid *pid, struct task_struct *task);
6441 +
6442  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6443  
6444  extern const struct file_operations proc_maps_operations;
6445 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6446         return PROC_I(inode)->pid;
6447  }
6448  
6449 -static inline struct task_struct *get_proc_task(struct inode *inode)
6450 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6451  {
6452         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6453  }
6454  
6455 +static inline struct task_struct *get_proc_task(struct inode *inode)
6456 +{
6457 +       return vx_get_proc_task(inode, proc_pid(inode));
6458 +}
6459 +
6460  static inline int proc_fd(struct inode *inode)
6461  {
6462         return PROC_I(inode)->fd;
6463 diff -NurpP --minimal linux-3.3.1/fs/proc/loadavg.c linux-3.3.1-vs2.3.3.2/fs/proc/loadavg.c
6464 --- linux-3.3.1/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6465 +++ linux-3.3.1-vs2.3.3.2/fs/proc/loadavg.c     2012-02-24 03:55:06.000000000 +0100
6466 @@ -12,15 +12,27 @@
6467  
6468  static int loadavg_proc_show(struct seq_file *m, void *v)
6469  {
6470 +       unsigned long running;
6471 +       unsigned int threads;
6472         unsigned long avnrun[3];
6473  
6474         get_avenrun(avnrun, FIXED_1/200, 0);
6475  
6476 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6477 +               struct vx_info *vxi = current_vx_info();
6478 +
6479 +               running = atomic_read(&vxi->cvirt.nr_running);
6480 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6481 +       } else {
6482 +               running = nr_running();
6483 +               threads = nr_threads;
6484 +       }
6485 +
6486         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6487                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6488                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6489                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6490 -               nr_running(), nr_threads,
6491 +               running, threads,
6492                 task_active_pid_ns(current)->last_pid);
6493         return 0;
6494  }
6495 diff -NurpP --minimal linux-3.3.1/fs/proc/meminfo.c linux-3.3.1-vs2.3.3.2/fs/proc/meminfo.c
6496 --- linux-3.3.1/fs/proc/meminfo.c       2012-01-09 16:14:55.000000000 +0100
6497 +++ linux-3.3.1-vs2.3.3.2/fs/proc/meminfo.c     2012-02-24 03:55:06.000000000 +0100
6498 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6499         allowed = ((totalram_pages - hugetlb_total_pages())
6500                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6501  
6502 -       cached = global_page_state(NR_FILE_PAGES) -
6503 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6504 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6505                         total_swapcache_pages - i.bufferram;
6506         if (cached < 0)
6507                 cached = 0;
6508 diff -NurpP --minimal linux-3.3.1/fs/proc/root.c linux-3.3.1-vs2.3.3.2/fs/proc/root.c
6509 --- linux-3.3.1/fs/proc/root.c  2012-03-19 19:47:26.000000000 +0100
6510 +++ linux-3.3.1-vs2.3.3.2/fs/proc/root.c        2012-02-24 04:46:50.000000000 +0100
6511 @@ -19,9 +19,14 @@
6512  #include <linux/mount.h>
6513  #include <linux/pid_namespace.h>
6514  #include <linux/parser.h>
6515 +#include <linux/vserver/inode.h>
6516  
6517  #include "internal.h"
6518  
6519 +struct proc_dir_entry *proc_virtual;
6520 +
6521 +extern void proc_vx_init(void);
6522 +
6523  static int proc_test_super(struct super_block *sb, void *data)
6524  {
6525         return sb->s_fs_info == data;
6526 @@ -189,6 +194,7 @@ void __init proc_root_init(void)
6527  #endif
6528         proc_mkdir("bus", NULL);
6529         proc_sys_init();
6530 +       proc_vx_init();
6531  }
6532  
6533  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6534 @@ -256,6 +262,7 @@ struct proc_dir_entry proc_root = {
6535         .proc_iops      = &proc_root_inode_operations, 
6536         .proc_fops      = &proc_root_operations,
6537         .parent         = &proc_root,
6538 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6539         .name           = "/proc",
6540  };
6541  
6542 diff -NurpP --minimal linux-3.3.1/fs/proc/uptime.c linux-3.3.1-vs2.3.3.2/fs/proc/uptime.c
6543 --- linux-3.3.1/fs/proc/uptime.c        2012-03-19 19:47:26.000000000 +0100
6544 +++ linux-3.3.1-vs2.3.3.2/fs/proc/uptime.c      2012-02-24 03:55:06.000000000 +0100
6545 @@ -5,6 +5,7 @@
6546  #include <linux/seq_file.h>
6547  #include <linux/time.h>
6548  #include <linux/kernel_stat.h>
6549 +#include <linux/vserver/cvirt.h>
6550  #include <asm/cputime.h>
6551  
6552  static int uptime_proc_show(struct seq_file *m, void *v)
6553 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6554         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6555         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6556         idle.tv_nsec = rem;
6557 +
6558 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6559 +               vx_vsi_uptime(&uptime, &idle);
6560 +
6561         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6562                         (unsigned long) uptime.tv_sec,
6563                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6564 diff -NurpP --minimal linux-3.3.1/fs/proc_namespace.c linux-3.3.1-vs2.3.3.2/fs/proc_namespace.c
6565 --- linux-3.3.1/fs/proc_namespace.c     2012-03-19 19:47:26.000000000 +0100
6566 +++ linux-3.3.1-vs2.3.3.2/fs/proc_namespace.c   2012-02-24 17:41:22.000000000 +0100
6567 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file 
6568                 { MS_SYNCHRONOUS, ",sync" },
6569                 { MS_DIRSYNC, ",dirsync" },
6570                 { MS_MANDLOCK, ",mand" },
6571 +               { MS_TAGGED, ",tag" },
6572 +               { MS_NOTAGCHECK, ",notagcheck" },
6573                 { 0, NULL }
6574         };
6575         const struct proc_fs_info *fs_infop;
6576 @@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6577         seq_escape(m, s, " \t\n\\");
6578  }
6579  
6580 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6581 +{
6582 +       struct path root;
6583 +       struct dentry *point;
6584 +       struct mount *mnt = real_mount(vfsmnt);
6585 +       struct mount *root_mnt;
6586 +       int ret;
6587 +
6588 +       if (mnt == mnt->mnt_ns->root)
6589 +               return 1;
6590 +
6591 +       br_read_lock(vfsmount_lock);
6592 +       root = current->fs->root;
6593 +       root_mnt = real_mount(root.mnt);
6594 +       point = root.dentry;
6595 +
6596 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6597 +               point = mnt->mnt_mountpoint;
6598 +               mnt = mnt->mnt_parent;
6599 +       }
6600 +
6601 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6602 +
6603 +       br_read_unlock(vfsmount_lock);
6604 +
6605 +       return ret;
6606 +}
6607 +
6608  static void show_type(struct seq_file *m, struct super_block *sb)
6609  {
6610         mangle(m, sb->s_type->name);
6611 @@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6612         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6613         struct super_block *sb = mnt_path.dentry->d_sb;
6614  
6615 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6616 +               return SEQ_SKIP;
6617 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6618 +               return SEQ_SKIP;
6619 +
6620 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6621 +               mnt == current->fs->root.mnt) {
6622 +               seq_puts(m, "/dev/root / ");
6623 +               goto type;
6624 +       }
6625 +
6626         if (sb->s_op->show_devname) {
6627                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6628                 if (err)
6629 @@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6630         seq_putc(m, ' ');
6631         seq_path(m, &mnt_path, " \t\n\\");
6632         seq_putc(m, ' ');
6633 +type:
6634         show_type(m, sb);
6635         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6636         err = show_sb_opts(m, sb);
6637 @@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6638         struct path root = p->root;
6639         int err = 0;
6640  
6641 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6642 +               return SEQ_SKIP;
6643 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6644 +               return SEQ_SKIP;
6645 +
6646         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6647                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6648         if (sb->s_op->show_path)
6649 @@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file 
6650         struct super_block *sb = mnt_path.dentry->d_sb;
6651         int err = 0;
6652  
6653 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6654 +               return SEQ_SKIP;
6655 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6656 +               return SEQ_SKIP;
6657 +
6658 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6659 +               mnt == current->fs->root.mnt) {
6660 +               seq_puts(m, "device /dev/root mounted on / ");
6661 +               goto type;
6662 +       }
6663 +
6664         /* device */
6665         if (sb->s_op->show_devname) {
6666                 seq_puts(m, "device ");
6667 @@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file 
6668         seq_puts(m, " mounted on ");
6669         seq_path(m, &mnt_path, " \t\n\\");
6670         seq_putc(m, ' ');
6671 -
6672 +type:
6673         /* file system type */
6674         seq_puts(m, "with fstype ");
6675         show_type(m, sb);
6676 diff -NurpP --minimal linux-3.3.1/fs/quota/dquot.c linux-3.3.1-vs2.3.3.2/fs/quota/dquot.c
6677 --- linux-3.3.1/fs/quota/dquot.c        2012-03-19 19:47:26.000000000 +0100
6678 +++ linux-3.3.1-vs2.3.3.2/fs/quota/dquot.c      2012-02-24 03:55:06.000000000 +0100
6679 @@ -1547,6 +1547,9 @@ int __dquot_alloc_space(struct inode *in
6680         int reserve = flags & DQUOT_SPACE_RESERVE;
6681         int nofail = flags & DQUOT_SPACE_NOFAIL;
6682  
6683 +       if ((ret = dl_alloc_space(inode, number)))
6684 +               return ret;
6685 +
6686         /*
6687          * First test before acquiring mutex - solves deadlocks when we
6688          * re-enter the quota code and are already holding the mutex
6689 @@ -1601,6 +1604,9 @@ int dquot_alloc_inode(const struct inode
6690         int cnt, ret = 0;
6691         char warntype[MAXQUOTAS];
6692  
6693 +       if ((ret = dl_alloc_inode(inode)))
6694 +               return ret;
6695 +
6696         /* First test before acquiring mutex - solves deadlocks when we
6697           * re-enter the quota code and are already holding the mutex */
6698         if (!dquot_active(inode))
6699 @@ -1671,6 +1677,8 @@ void __dquot_free_space(struct inode *in
6700         char warntype[MAXQUOTAS];
6701         int reserve = flags & DQUOT_SPACE_RESERVE;
6702  
6703 +       dl_free_space(inode, number);
6704 +
6705         /* First test before acquiring mutex - solves deadlocks when we
6706           * re-enter the quota code and are already holding the mutex */
6707         if (!dquot_active(inode)) {
6708 @@ -1709,6 +1717,8 @@ void dquot_free_inode(const struct inode
6709         unsigned int cnt;
6710         char warntype[MAXQUOTAS];
6711  
6712 +       dl_free_inode(inode);
6713 +
6714         /* First test before acquiring mutex - solves deadlocks when we
6715           * re-enter the quota code and are already holding the mutex */
6716         if (!dquot_active(inode))
6717 diff -NurpP --minimal linux-3.3.1/fs/quota/quota.c linux-3.3.1-vs2.3.3.2/fs/quota/quota.c
6718 --- linux-3.3.1/fs/quota/quota.c        2012-03-19 19:47:26.000000000 +0100
6719 +++ linux-3.3.1-vs2.3.3.2/fs/quota/quota.c      2012-03-19 20:54:39.000000000 +0100
6720 @@ -8,6 +8,7 @@
6721  #include <linux/fs.h>
6722  #include <linux/namei.h>
6723  #include <linux/slab.h>
6724 +#include <linux/vs_context.h>
6725  #include <asm/current.h>
6726  #include <asm/uaccess.h>
6727  #include <linux/kernel.h>
6728 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6729                         break;
6730                 /*FALLTHROUGH*/
6731         default:
6732 -               if (!capable(CAP_SYS_ADMIN))
6733 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6734                         return -EPERM;
6735         }
6736  
6737 @@ -292,6 +293,46 @@ static int do_quotactl(struct super_bloc
6738         }
6739  }
6740  
6741 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6742 +
6743 +#include <linux/vroot.h>
6744 +#include <linux/major.h>
6745 +#include <linux/module.h>
6746 +#include <linux/kallsyms.h>
6747 +#include <linux/vserver/debug.h>
6748 +
6749 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6750 +
6751 +static DEFINE_SPINLOCK(vroot_grb_lock);
6752 +
6753 +int register_vroot_grb(vroot_grb_func *func) {
6754 +       int ret = -EBUSY;
6755 +
6756 +       spin_lock(&vroot_grb_lock);
6757 +       if (!vroot_get_real_bdev) {
6758 +               vroot_get_real_bdev = func;
6759 +               ret = 0;
6760 +       }
6761 +       spin_unlock(&vroot_grb_lock);
6762 +       return ret;
6763 +}
6764 +EXPORT_SYMBOL(register_vroot_grb);
6765 +
6766 +int unregister_vroot_grb(vroot_grb_func *func) {
6767 +       int ret = -EINVAL;
6768 +
6769 +       spin_lock(&vroot_grb_lock);
6770 +       if (vroot_get_real_bdev) {
6771 +               vroot_get_real_bdev = NULL;
6772 +               ret = 0;
6773 +       }
6774 +       spin_unlock(&vroot_grb_lock);
6775 +       return ret;
6776 +}
6777 +EXPORT_SYMBOL(unregister_vroot_grb);
6778 +
6779 +#endif
6780 +
6781  /* Return 1 if 'cmd' will block on frozen filesystem */
6782  static int quotactl_cmd_write(int cmd)
6783  {
6784 @@ -324,6 +365,22 @@ static struct super_block *quotactl_bloc
6785         putname(tmp);
6786         if (IS_ERR(bdev))
6787                 return ERR_CAST(bdev);
6788 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6789 +       if (bdev && bdev->bd_inode &&
6790 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6791 +               struct block_device *bdnew = (void *)-EINVAL;
6792 +
6793 +               if (vroot_get_real_bdev)
6794 +                       bdnew = vroot_get_real_bdev(bdev);
6795 +               else
6796 +                       vxdprintk(VXD_CBIT(misc, 0),
6797 +                                       "vroot_get_real_bdev not set");
6798 +               bdput(bdev);
6799 +               if (IS_ERR(bdnew))
6800 +                       return ERR_PTR(PTR_ERR(bdnew));
6801 +               bdev = bdnew;
6802 +       }
6803 +#endif
6804         if (quotactl_cmd_write(cmd))
6805                 sb = get_super_thawed(bdev);
6806         else
6807 diff -NurpP --minimal linux-3.3.1/fs/reiserfs/file.c linux-3.3.1-vs2.3.3.2/fs/reiserfs/file.c
6808 --- linux-3.3.1/fs/reiserfs/file.c      2011-10-24 18:45:27.000000000 +0200
6809 +++ linux-3.3.1-vs2.3.3.2/fs/reiserfs/file.c    2012-02-24 03:55:06.000000000 +0100
6810 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6811         .listxattr = reiserfs_listxattr,
6812         .removexattr = reiserfs_removexattr,
6813         .permission = reiserfs_permission,
6814 +       .sync_flags = reiserfs_sync_flags,
6815         .get_acl = reiserfs_get_acl,
6816  };
6817 diff -NurpP --minimal linux-3.3.1/fs/reiserfs/inode.c linux-3.3.1-vs2.3.3.2/fs/reiserfs/inode.c
6818 --- linux-3.3.1/fs/reiserfs/inode.c     2012-03-19 19:47:26.000000000 +0100
6819 +++ linux-3.3.1-vs2.3.3.2/fs/reiserfs/inode.c   2012-02-24 03:55:06.000000000 +0100
6820 @@ -18,6 +18,7 @@
6821  #include <linux/writeback.h>
6822  #include <linux/quotaops.h>
6823  #include <linux/swap.h>
6824 +#include <linux/vs_tag.h>
6825  
6826  int reiserfs_commit_write(struct file *f, struct page *page,
6827                           unsigned from, unsigned to);
6828 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6829         struct buffer_head *bh;
6830         struct item_head *ih;
6831         __u32 rdev;
6832 +       uid_t uid;
6833 +       gid_t gid;
6834         //int version = ITEM_VERSION_1;
6835  
6836         bh = PATH_PLAST_BUFFER(path);
6837 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6838                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6839                 unsigned long blocks;
6840  
6841 +               uid = sd_v1_uid(sd);
6842 +               gid = sd_v1_gid(sd);
6843 +
6844                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6845                 set_inode_sd_version(inode, STAT_DATA_V1);
6846                 inode->i_mode = sd_v1_mode(sd);
6847                 set_nlink(inode, sd_v1_nlink(sd));
6848 -               inode->i_uid = sd_v1_uid(sd);
6849 -               inode->i_gid = sd_v1_gid(sd);
6850                 inode->i_size = sd_v1_size(sd);
6851                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6852                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6853 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6854                 // (directories and symlinks)
6855                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6856  
6857 +               uid    = sd_v2_uid(sd);
6858 +               gid    = sd_v2_gid(sd);
6859 +
6860                 inode->i_mode = sd_v2_mode(sd);
6861                 set_nlink(inode, sd_v2_nlink(sd));
6862 -               inode->i_uid = sd_v2_uid(sd);
6863                 inode->i_size = sd_v2_size(sd);
6864 -               inode->i_gid = sd_v2_gid(sd);
6865                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6866                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6867                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6868 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6869                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6870         }
6871  
6872 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6873 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6874 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6875 +
6876         pathrelse(path);
6877         if (S_ISREG(inode->i_mode)) {
6878                 inode->i_op = &reiserfs_file_inode_operations;
6879 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6880  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6881  {
6882         struct stat_data *sd_v2 = (struct stat_data *)sd;
6883 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6884 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6885         __u16 flags;
6886  
6887 +       set_sd_v2_uid(sd_v2, uid);
6888 +       set_sd_v2_gid(sd_v2, gid);
6889         set_sd_v2_mode(sd_v2, inode->i_mode);
6890         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6891 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6892         set_sd_v2_size(sd_v2, size);
6893 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6894         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6895         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6896         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6897 @@ -2868,14 +2879,19 @@ int reiserfs_commit_write(struct file *f
6898  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6899  {
6900         if (reiserfs_attrs(inode->i_sb)) {
6901 -               if (sd_attrs & REISERFS_SYNC_FL)
6902 -                       inode->i_flags |= S_SYNC;
6903 -               else
6904 -                       inode->i_flags &= ~S_SYNC;
6905                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6906                         inode->i_flags |= S_IMMUTABLE;
6907                 else
6908                         inode->i_flags &= ~S_IMMUTABLE;
6909 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6910 +                       inode->i_flags |= S_IXUNLINK;
6911 +               else
6912 +                       inode->i_flags &= ~S_IXUNLINK;
6913 +
6914 +               if (sd_attrs & REISERFS_SYNC_FL)
6915 +                       inode->i_flags |= S_SYNC;
6916 +               else
6917 +                       inode->i_flags &= ~S_SYNC;
6918                 if (sd_attrs & REISERFS_APPEND_FL)
6919                         inode->i_flags |= S_APPEND;
6920                 else
6921 @@ -2888,6 +2904,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6922                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6923                 else
6924                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6925 +
6926 +               if (sd_attrs & REISERFS_BARRIER_FL)
6927 +                       inode->i_vflags |= V_BARRIER;
6928 +               else
6929 +                       inode->i_vflags &= ~V_BARRIER;
6930 +               if (sd_attrs & REISERFS_COW_FL)
6931 +                       inode->i_vflags |= V_COW;
6932 +               else
6933 +                       inode->i_vflags &= ~V_COW;
6934         }
6935  }
6936  
6937 @@ -2898,6 +2923,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6938                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6939                 else
6940                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6941 +               if (inode->i_flags & S_IXUNLINK)
6942 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6943 +               else
6944 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6945 +
6946                 if (inode->i_flags & S_SYNC)
6947                         *sd_attrs |= REISERFS_SYNC_FL;
6948                 else
6949 @@ -2910,6 +2940,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6950                         *sd_attrs |= REISERFS_NOTAIL_FL;
6951                 else
6952                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6953 +
6954 +               if (inode->i_vflags & V_BARRIER)
6955 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6956 +               else
6957 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6958 +               if (inode->i_vflags & V_COW)
6959 +                       *sd_attrs |= REISERFS_COW_FL;
6960 +               else
6961 +                       *sd_attrs &= ~REISERFS_COW_FL;
6962         }
6963  }
6964  
6965 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
6966         }
6967  
6968         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
6969 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
6970 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
6971 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
6972                 struct reiserfs_transaction_handle th;
6973                 int jbegin_count =
6974                     2 *
6975 @@ -3184,6 +3224,9 @@ int reiserfs_setattr(struct dentry *dent
6976                         inode->i_uid = attr->ia_uid;
6977                 if (attr->ia_valid & ATTR_GID)
6978                         inode->i_gid = attr->ia_gid;
6979 +                               if ((attr->ia_valid & ATTR_TAG) &&
6980 +                                       IS_TAGGED(inode))
6981 +                                       inode->i_tag = attr->ia_tag;
6982                 mark_inode_dirty(inode);
6983                 error = journal_end(&th, inode->i_sb, jbegin_count);
6984                 if (error)
6985 diff -NurpP --minimal linux-3.3.1/fs/reiserfs/ioctl.c linux-3.3.1-vs2.3.3.2/fs/reiserfs/ioctl.c
6986 --- linux-3.3.1/fs/reiserfs/ioctl.c     2012-03-19 19:47:26.000000000 +0100
6987 +++ linux-3.3.1-vs2.3.3.2/fs/reiserfs/ioctl.c   2012-02-24 03:55:06.000000000 +0100
6988 @@ -11,6 +11,21 @@
6989  #include <linux/pagemap.h>
6990  #include <linux/compat.h>
6991  
6992 +
6993 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
6994 +{
6995 +       __u16 sd_attrs = 0;
6996 +
6997 +       inode->i_flags = flags;
6998 +       inode->i_vflags = vflags;
6999 +
7000 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7001 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7002 +       inode->i_ctime = CURRENT_TIME_SEC;
7003 +       mark_inode_dirty(inode);
7004 +       return 0;
7005 +}
7006 +
7007  /*
7008   * reiserfs_ioctl - handler for ioctl for inode
7009   * supported commands:
7010 @@ -22,7 +37,7 @@
7011  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7012  {
7013         struct inode *inode = filp->f_path.dentry->d_inode;
7014 -       unsigned int flags;
7015 +       unsigned int flags, oldflags;
7016         int err = 0;
7017  
7018         reiserfs_write_lock(inode->i_sb);
7019 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7020  
7021                 flags = REISERFS_I(inode)->i_attrs;
7022                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7023 +               flags &= REISERFS_FL_USER_VISIBLE;
7024                 err = put_user(flags, (int __user *)arg);
7025                 break;
7026         case REISERFS_IOC_SETFLAGS:{
7027 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7028                                 err = -EFAULT;
7029                                 goto setflags_out;
7030                         }
7031 +                       if (IS_BARRIER(inode)) {
7032 +                               vxwprintk_task(1, "messing with the barrier.");
7033 +                               return -EACCES;
7034 +                       }
7035                         /*
7036                          * Is it quota file? Do not allow user to mess with it
7037                          */
7038 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7039                                         goto setflags_out;
7040                                 }
7041                         }
7042 +
7043 +                       oldflags = REISERFS_I(inode)->i_attrs;
7044 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7045 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7046                         sd_attrs_to_i_attrs(flags, inode);
7047                         REISERFS_I(inode)->i_attrs = flags;
7048                         inode->i_ctime = CURRENT_TIME_SEC;
7049 diff -NurpP --minimal linux-3.3.1/fs/reiserfs/namei.c linux-3.3.1-vs2.3.3.2/fs/reiserfs/namei.c
7050 --- linux-3.3.1/fs/reiserfs/namei.c     2012-03-19 19:47:26.000000000 +0100
7051 +++ linux-3.3.1-vs2.3.3.2/fs/reiserfs/namei.c   2012-02-24 03:55:06.000000000 +0100
7052 @@ -18,6 +18,7 @@
7053  #include <linux/reiserfs_acl.h>
7054  #include <linux/reiserfs_xattr.h>
7055  #include <linux/quotaops.h>
7056 +#include <linux/vs_tag.h>
7057  
7058  #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); }
7059  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7060 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7061         if (retval == IO_ERROR) {
7062                 return ERR_PTR(-EIO);
7063         }
7064 +               dx_propagate_tag(nd, inode);
7065  
7066         return d_splice_alias(inode, dentry);
7067  }
7068 diff -NurpP --minimal linux-3.3.1/fs/reiserfs/super.c linux-3.3.1-vs2.3.3.2/fs/reiserfs/super.c
7069 --- linux-3.3.1/fs/reiserfs/super.c     2012-03-19 19:47:26.000000000 +0100
7070 +++ linux-3.3.1-vs2.3.3.2/fs/reiserfs/super.c   2012-02-24 03:55:06.000000000 +0100
7071 @@ -980,6 +980,14 @@ static int reiserfs_parse_options(struct
7072                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7073                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7074  #endif
7075 +#ifndef CONFIG_TAGGING_NONE
7076 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7077 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7078 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7079 +#endif
7080 +#ifdef CONFIG_PROPAGATE
7081 +               {"tag",.arg_required = 'T',.values = NULL},
7082 +#endif
7083  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7084                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7085                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7086 @@ -1298,6 +1306,14 @@ static int reiserfs_remount(struct super
7087         handle_quota_files(s, qf_names, &qfmt);
7088  #endif
7089  
7090 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7091 +               !(s->s_flags & MS_TAGGED)) {
7092 +               reiserfs_warning(s, "super-vs01",
7093 +                       "reiserfs: tagging not permitted on remount.");
7094 +               err = -EINVAL;
7095 +               goto out_err;
7096 +       }
7097 +
7098         handle_attrs(s);
7099  
7100         /* Add options that are safe here */
7101 @@ -1777,6 +1793,10 @@ static int reiserfs_fill_super(struct su
7102                 goto error_unlocked;
7103         }
7104  
7105 +       /* map mount option tagxid */
7106 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7107 +               s->s_flags |= MS_TAGGED;
7108 +
7109         rs = SB_DISK_SUPER_BLOCK(s);
7110         /* Let's do basic sanity check to verify that underlying device is not
7111            smaller than the filesystem. If the check fails then abort and scream,
7112 diff -NurpP --minimal linux-3.3.1/fs/reiserfs/xattr.c linux-3.3.1-vs2.3.3.2/fs/reiserfs/xattr.c
7113 --- linux-3.3.1/fs/reiserfs/xattr.c     2012-03-19 19:47:26.000000000 +0100
7114 +++ linux-3.3.1-vs2.3.3.2/fs/reiserfs/xattr.c   2012-02-24 03:55:06.000000000 +0100
7115 @@ -40,6 +40,7 @@
7116  #include <linux/errno.h>
7117  #include <linux/gfp.h>
7118  #include <linux/fs.h>
7119 +#include <linux/mount.h>
7120  #include <linux/file.h>
7121  #include <linux/pagemap.h>
7122  #include <linux/xattr.h>
7123 diff -NurpP --minimal linux-3.3.1/fs/stat.c linux-3.3.1-vs2.3.3.2/fs/stat.c
7124 --- linux-3.3.1/fs/stat.c       2012-01-09 16:14:55.000000000 +0100
7125 +++ linux-3.3.1-vs2.3.3.2/fs/stat.c     2012-02-24 03:55:06.000000000 +0100
7126 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7127         stat->nlink = inode->i_nlink;
7128         stat->uid = inode->i_uid;
7129         stat->gid = inode->i_gid;
7130 +       stat->tag = inode->i_tag;
7131         stat->rdev = inode->i_rdev;
7132         stat->size = i_size_read(inode);
7133         stat->atime = inode->i_atime;
7134 diff -NurpP --minimal linux-3.3.1/fs/statfs.c linux-3.3.1-vs2.3.3.2/fs/statfs.c
7135 --- linux-3.3.1/fs/statfs.c     2012-03-19 19:47:26.000000000 +0100
7136 +++ linux-3.3.1-vs2.3.3.2/fs/statfs.c   2012-02-24 04:27:47.000000000 +0100
7137 @@ -7,6 +7,8 @@
7138  #include <linux/statfs.h>
7139  #include <linux/security.h>
7140  #include <linux/uaccess.h>
7141 +#include <linux/vs_base.h>
7142 +#include <linux/vs_dlimit.h>
7143  #include "internal.h"
7144  
7145  static int flags_by_mnt(int mnt_flags)
7146 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7147         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7148         if (retval == 0 && buf->f_frsize == 0)
7149                 buf->f_frsize = buf->f_bsize;
7150 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7151 +               vx_vsi_statfs(dentry->d_sb, buf);
7152         return retval;
7153  }
7154  
7155 diff -NurpP --minimal linux-3.3.1/fs/super.c linux-3.3.1-vs2.3.3.2/fs/super.c
7156 --- linux-3.3.1/fs/super.c      2012-03-19 19:47:26.000000000 +0100
7157 +++ linux-3.3.1-vs2.3.3.2/fs/super.c    2012-03-19 20:52:10.000000000 +0100
7158 @@ -32,6 +32,9 @@
7159  #include <linux/backing-dev.h>
7160  #include <linux/rculist_bl.h>
7161  #include <linux/cleancache.h>
7162 +#include <linux/devpts_fs.h>
7163 +#include <linux/proc_fs.h>
7164 +#include <linux/vs_context.h>
7165  #include "internal.h"
7166  
7167  
7168 @@ -1137,6 +1140,13 @@ mount_fs(struct file_system_type *type, 
7169         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7170         sb->s_flags |= MS_BORN;
7171  
7172 +       error = -EPERM;
7173 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7174 +               !sb->s_bdev &&
7175 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7176 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7177 +               goto out_sb;
7178 +
7179         error = security_sb_kern_mount(sb, flags, secdata);
7180         if (error)
7181                 goto out_sb;
7182 diff -NurpP --minimal linux-3.3.1/fs/sysfs/mount.c linux-3.3.1-vs2.3.3.2/fs/sysfs/mount.c
7183 --- linux-3.3.1/fs/sysfs/mount.c        2011-07-22 11:18:06.000000000 +0200
7184 +++ linux-3.3.1-vs2.3.3.2/fs/sysfs/mount.c      2012-02-24 03:55:06.000000000 +0100
7185 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7186  
7187         sb->s_blocksize = PAGE_CACHE_SIZE;
7188         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7189 -       sb->s_magic = SYSFS_MAGIC;
7190 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7191         sb->s_op = &sysfs_ops;
7192         sb->s_time_gran = 1;
7193  
7194 diff -NurpP --minimal linux-3.3.1/fs/utimes.c linux-3.3.1-vs2.3.3.2/fs/utimes.c
7195 --- linux-3.3.1/fs/utimes.c     2011-05-22 16:17:54.000000000 +0200
7196 +++ linux-3.3.1-vs2.3.3.2/fs/utimes.c   2012-02-24 03:55:06.000000000 +0100
7197 @@ -8,6 +8,8 @@
7198  #include <linux/stat.h>
7199  #include <linux/utime.h>
7200  #include <linux/syscalls.h>
7201 +#include <linux/mount.h>
7202 +#include <linux/vs_cowbl.h>
7203  #include <asm/uaccess.h>
7204  #include <asm/unistd.h>
7205  
7206 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7207  {
7208         int error;
7209         struct iattr newattrs;
7210 -       struct inode *inode = path->dentry->d_inode;
7211 +       struct inode *inode;
7212  
7213         error = mnt_want_write(path->mnt);
7214         if (error)
7215                 goto out;
7216  
7217 +       error = cow_check_and_break(path);
7218 +       if (error)
7219 +               goto mnt_drop_write_and_out;
7220 +
7221 +       inode = path->dentry->d_inode;
7222 +
7223         if (times && times[0].tv_nsec == UTIME_NOW &&
7224                      times[1].tv_nsec == UTIME_NOW)
7225                 times = NULL;
7226 diff -NurpP --minimal linux-3.3.1/fs/xattr.c linux-3.3.1-vs2.3.3.2/fs/xattr.c
7227 --- linux-3.3.1/fs/xattr.c      2012-03-19 19:47:27.000000000 +0100
7228 +++ linux-3.3.1-vs2.3.3.2/fs/xattr.c    2012-02-24 03:55:06.000000000 +0100
7229 @@ -19,6 +19,7 @@
7230  #include <linux/module.h>
7231  #include <linux/fsnotify.h>
7232  #include <linux/audit.h>
7233 +#include <linux/mount.h>
7234  #include <asm/uaccess.h>
7235  
7236  
7237 @@ -50,7 +51,7 @@ xattr_permission(struct inode *inode, co
7238          * The trusted.* namespace can only be accessed by privileged users.
7239          */
7240         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7241 -               if (!capable(CAP_SYS_ADMIN))
7242 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7243                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7244                 return 0;
7245         }
7246 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_dinode.h linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_dinode.h
7247 --- linux-3.3.1/fs/xfs/xfs_dinode.h     2011-10-24 18:45:31.000000000 +0200
7248 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_dinode.h   2012-02-24 03:55:06.000000000 +0100
7249 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7250         __be32          di_nlink;       /* number of links to file */
7251         __be16          di_projid_lo;   /* lower part of owner's project id */
7252         __be16          di_projid_hi;   /* higher part owner's project id */
7253 -       __u8            di_pad[6];      /* unused, zeroed space */
7254 +       __u8            di_pad[2];      /* unused, zeroed space */
7255 +       __be16          di_tag;         /* context tagging */
7256 +       __be16          di_vflags;      /* vserver specific flags */
7257         __be16          di_flushiter;   /* incremented on flush */
7258         xfs_timestamp_t di_atime;       /* time last accessed */
7259         xfs_timestamp_t di_mtime;       /* time last modified */
7260 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7261  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7262  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7263  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7264 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7265 +
7266  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7267  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7268  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7269 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7270  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7271  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7272  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7273 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7274  
7275  #ifdef CONFIG_XFS_RT
7276  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7277 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7278          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7279          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7280          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7281 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7282 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7283 +        XFS_DIFLAG_IXUNLINK)
7284 +
7285 +#define XFS_DIVFLAG_BARRIER    0x01
7286 +#define XFS_DIVFLAG_COW                0x02
7287  
7288  #endif /* __XFS_DINODE_H__ */
7289 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_fs.h linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_fs.h
7290 --- linux-3.3.1/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7291 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_fs.h       2012-02-24 03:55:06.000000000 +0100
7292 @@ -67,6 +67,9 @@ struct fsxattr {
7293  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7294  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7295  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7296 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7297 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7298 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7299  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7300  
7301  /*
7302 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7303  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7304         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7305         __u16           bs_projid_hi;   /* higher part of project id    */
7306 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7307 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7308 +       __u16           bs_tag;         /* context tagging              */
7309         __u32           bs_dmevmask;    /* DMIG event mask              */
7310         __u16           bs_dmstate;     /* DMIG state info              */
7311         __u16           bs_aextents;    /* attribute number of extents  */
7312 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_ialloc.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_ialloc.c
7313 --- linux-3.3.1/fs/xfs/xfs_ialloc.c     2012-03-19 19:47:27.000000000 +0100
7314 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_ialloc.c   2012-02-24 03:55:06.000000000 +0100
7315 @@ -37,7 +37,6 @@
7316  #include "xfs_error.h"
7317  #include "xfs_bmap.h"
7318  
7319 -
7320  /*
7321   * Allocation group level functions.
7322   */
7323 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_inode.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_inode.c
7324 --- linux-3.3.1/fs/xfs/xfs_inode.c      2012-03-19 19:47:27.000000000 +0100
7325 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_inode.c    2012-02-24 03:55:06.000000000 +0100
7326 @@ -236,6 +236,7 @@ xfs_inotobp(
7327         return 0;
7328  }
7329  
7330 +#include <linux/vs_tag.h>
7331  
7332  /*
7333   * This routine is called to map an inode to the buffer containing
7334 @@ -631,15 +632,25 @@ xfs_iformat_btree(
7335  STATIC void
7336  xfs_dinode_from_disk(
7337         xfs_icdinode_t          *to,
7338 -       xfs_dinode_t            *from)
7339 +       xfs_dinode_t            *from,
7340 +       int tagged)
7341  {
7342 +       uint32_t uid, gid, tag;
7343 +
7344         to->di_magic = be16_to_cpu(from->di_magic);
7345         to->di_mode = be16_to_cpu(from->di_mode);
7346         to->di_version = from ->di_version;
7347         to->di_format = from->di_format;
7348         to->di_onlink = be16_to_cpu(from->di_onlink);
7349 -       to->di_uid = be32_to_cpu(from->di_uid);
7350 -       to->di_gid = be32_to_cpu(from->di_gid);
7351 +
7352 +       uid = be32_to_cpu(from->di_uid);
7353 +       gid = be32_to_cpu(from->di_gid);
7354 +       tag = be16_to_cpu(from->di_tag);
7355 +
7356 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7357 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7358 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7359 +
7360         to->di_nlink = be32_to_cpu(from->di_nlink);
7361         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7362         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7363 @@ -661,21 +672,26 @@ xfs_dinode_from_disk(
7364         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7365         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7366         to->di_flags    = be16_to_cpu(from->di_flags);
7367 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7368         to->di_gen      = be32_to_cpu(from->di_gen);
7369  }
7370  
7371  void
7372  xfs_dinode_to_disk(
7373         xfs_dinode_t            *to,
7374 -       xfs_icdinode_t          *from)
7375 +       xfs_icdinode_t          *from,
7376 +       int tagged)
7377  {
7378         to->di_magic = cpu_to_be16(from->di_magic);
7379         to->di_mode = cpu_to_be16(from->di_mode);
7380         to->di_version = from ->di_version;
7381         to->di_format = from->di_format;
7382         to->di_onlink = cpu_to_be16(from->di_onlink);
7383 -       to->di_uid = cpu_to_be32(from->di_uid);
7384 -       to->di_gid = cpu_to_be32(from->di_gid);
7385 +
7386 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7387 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7388 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7389 +
7390         to->di_nlink = cpu_to_be32(from->di_nlink);
7391         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7392         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7393 @@ -697,12 +713,14 @@ xfs_dinode_to_disk(
7394         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7395         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7396         to->di_flags = cpu_to_be16(from->di_flags);
7397 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7398         to->di_gen = cpu_to_be32(from->di_gen);
7399  }
7400  
7401  STATIC uint
7402  _xfs_dic2xflags(
7403 -       __uint16_t              di_flags)
7404 +       __uint16_t              di_flags,
7405 +       __uint16_t              di_vflags)
7406  {
7407         uint                    flags = 0;
7408  
7409 @@ -713,6 +731,8 @@ _xfs_dic2xflags(
7410                         flags |= XFS_XFLAG_PREALLOC;
7411                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7412                         flags |= XFS_XFLAG_IMMUTABLE;
7413 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7414 +                       flags |= XFS_XFLAG_IXUNLINK;
7415                 if (di_flags & XFS_DIFLAG_APPEND)
7416                         flags |= XFS_XFLAG_APPEND;
7417                 if (di_flags & XFS_DIFLAG_SYNC)
7418 @@ -737,6 +757,10 @@ _xfs_dic2xflags(
7419                         flags |= XFS_XFLAG_FILESTREAM;
7420         }
7421  
7422 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7423 +               flags |= FS_BARRIER_FL;
7424 +       if (di_vflags & XFS_DIVFLAG_COW)
7425 +               flags |= FS_COW_FL;
7426         return flags;
7427  }
7428  
7429 @@ -746,7 +770,7 @@ xfs_ip2xflags(
7430  {
7431         xfs_icdinode_t          *dic = &ip->i_d;
7432  
7433 -       return _xfs_dic2xflags(dic->di_flags) |
7434 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7435                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7436  }
7437  
7438 @@ -754,7 +778,8 @@ uint
7439  xfs_dic2xflags(
7440         xfs_dinode_t            *dip)
7441  {
7442 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7443 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7444 +                               be16_to_cpu(dip->di_vflags)) |
7445                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7446  }
7447  
7448 @@ -787,7 +812,6 @@ xfs_iread(
7449         if (error)
7450                 return error;
7451         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7452 -
7453         /*
7454          * If we got something that isn't an inode it means someone
7455          * (nfs or dmi) has a stale handle.
7456 @@ -810,7 +834,8 @@ xfs_iread(
7457          * Otherwise, just get the truly permanent information.
7458          */
7459         if (dip->di_mode) {
7460 -               xfs_dinode_from_disk(&ip->i_d, dip);
7461 +               xfs_dinode_from_disk(&ip->i_d, dip,
7462 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7463                 error = xfs_iformat(ip, dip);
7464                 if (error)  {
7465  #ifdef DEBUG
7466 @@ -998,6 +1023,7 @@ xfs_ialloc(
7467         ASSERT(ip->i_d.di_nlink == nlink);
7468         ip->i_d.di_uid = current_fsuid();
7469         ip->i_d.di_gid = current_fsgid();
7470 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7471         xfs_set_projid(ip, prid);
7472         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7473  
7474 @@ -1057,6 +1083,7 @@ xfs_ialloc(
7475         ip->i_d.di_dmevmask = 0;
7476         ip->i_d.di_dmstate = 0;
7477         ip->i_d.di_flags = 0;
7478 +       ip->i_d.di_vflags = 0;
7479         flags = XFS_ILOG_CORE;
7480         switch (mode & S_IFMT) {
7481         case S_IFIFO:
7482 @@ -1726,6 +1753,7 @@ xfs_ifree(
7483         }
7484         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7485         ip->i_d.di_flags = 0;
7486 +       ip->i_d.di_vflags = 0;
7487         ip->i_d.di_dmevmask = 0;
7488         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7489         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7490 @@ -2620,7 +2648,8 @@ xfs_iflush_int(
7491          * because if the inode is dirty at all the core must
7492          * be.
7493          */
7494 -       xfs_dinode_to_disk(dip, &ip->i_d);
7495 +       xfs_dinode_to_disk(dip, &ip->i_d,
7496 +               mp->m_flags & XFS_MOUNT_TAGGED);
7497  
7498         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7499         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7500 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_inode.h linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_inode.h
7501 --- linux-3.3.1/fs/xfs/xfs_inode.h      2012-03-19 19:47:27.000000000 +0100
7502 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_inode.h    2012-02-24 03:55:06.000000000 +0100
7503 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7504         __uint32_t      di_nlink;       /* number of links to file */
7505         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7506         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7507 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7508 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7509 +       __uint16_t      di_tag;         /* context tagging */
7510 +       __uint16_t      di_vflags;      /* vserver specific flags */
7511         __uint16_t      di_flushiter;   /* incremented on flush */
7512         xfs_ictimestamp_t di_atime;     /* time last accessed */
7513         xfs_ictimestamp_t di_mtime;     /* time last modified */
7514 @@ -556,7 +558,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7515  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7516                           struct xfs_inode *, uint);
7517  void           xfs_dinode_to_disk(struct xfs_dinode *,
7518 -                                  struct xfs_icdinode *);
7519 +                                  struct xfs_icdinode *, int);
7520  void           xfs_idestroy_fork(struct xfs_inode *, int);
7521  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7522  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7523 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_ioctl.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_ioctl.c
7524 --- linux-3.3.1/fs/xfs/xfs_ioctl.c      2012-03-19 19:47:27.000000000 +0100
7525 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_ioctl.c    2012-02-24 03:55:06.000000000 +0100
7526 @@ -28,7 +28,7 @@
7527  #include "xfs_bmap_btree.h"
7528  #include "xfs_dinode.h"
7529  #include "xfs_inode.h"
7530 -#include "xfs_ioctl.h"
7531 +// #include "xfs_ioctl.h"
7532  #include "xfs_rtalloc.h"
7533  #include "xfs_itable.h"
7534  #include "xfs_error.h"
7535 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7536                 xflags |= XFS_XFLAG_IMMUTABLE;
7537         else
7538                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7539 +       if (flags & FS_IXUNLINK_FL)
7540 +               xflags |= XFS_XFLAG_IXUNLINK;
7541 +       else
7542 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7543         if (flags & FS_APPEND_FL)
7544                 xflags |= XFS_XFLAG_APPEND;
7545         else
7546 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7547  
7548         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7549                 flags |= FS_IMMUTABLE_FL;
7550 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7551 +               flags |= FS_IXUNLINK_FL;
7552         if (di_flags & XFS_DIFLAG_APPEND)
7553                 flags |= FS_APPEND_FL;
7554         if (di_flags & XFS_DIFLAG_SYNC)
7555 @@ -836,6 +842,8 @@ xfs_set_diflags(
7556         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7557         if (xflags & XFS_XFLAG_IMMUTABLE)
7558                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7559 +       if (xflags & XFS_XFLAG_IXUNLINK)
7560 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7561         if (xflags & XFS_XFLAG_APPEND)
7562                 di_flags |= XFS_DIFLAG_APPEND;
7563         if (xflags & XFS_XFLAG_SYNC)
7564 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7565                 inode->i_flags |= S_IMMUTABLE;
7566         else
7567                 inode->i_flags &= ~S_IMMUTABLE;
7568 +       if (xflags & XFS_XFLAG_IXUNLINK)
7569 +               inode->i_flags |= S_IXUNLINK;
7570 +       else
7571 +               inode->i_flags &= ~S_IXUNLINK;
7572         if (xflags & XFS_XFLAG_APPEND)
7573                 inode->i_flags |= S_APPEND;
7574         else
7575 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7576         case XFS_IOC_FSGETXATTRA:
7577                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7578         case XFS_IOC_FSSETXATTR:
7579 +               if (IS_BARRIER(inode)) {
7580 +                       vxwprintk_task(1, "messing with the barrier.");
7581 +                       return -XFS_ERROR(EACCES);
7582 +               }
7583                 return xfs_ioc_fssetxattr(ip, filp, arg);
7584         case XFS_IOC_GETXFLAGS:
7585                 return xfs_ioc_getxflags(ip, arg);
7586         case XFS_IOC_SETXFLAGS:
7587 +               if (IS_BARRIER(inode)) {
7588 +                       vxwprintk_task(1, "messing with the barrier.");
7589 +                       return -XFS_ERROR(EACCES);
7590 +               }
7591                 return xfs_ioc_setxflags(ip, filp, arg);
7592  
7593         case XFS_IOC_FSSETDM: {
7594 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_ioctl.h linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_ioctl.h
7595 --- linux-3.3.1/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7596 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_ioctl.h    2012-02-24 03:55:06.000000000 +0100
7597 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7598         void __user             *uhandle,
7599         u32                     hlen);
7600  
7601 +extern int
7602 +xfs_sync_flags(
7603 +       struct inode            *inode,
7604 +       int                     flags,
7605 +       int                     vflags);
7606 +
7607  extern long
7608  xfs_file_ioctl(
7609         struct file             *filp,
7610 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_iops.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_iops.c
7611 --- linux-3.3.1/fs/xfs/xfs_iops.c       2012-03-19 19:47:27.000000000 +0100
7612 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_iops.c     2012-02-24 03:55:06.000000000 +0100
7613 @@ -30,6 +30,7 @@
7614  #include "xfs_bmap_btree.h"
7615  #include "xfs_dinode.h"
7616  #include "xfs_inode.h"
7617 +#include "xfs_ioctl.h"
7618  #include "xfs_bmap.h"
7619  #include "xfs_rtalloc.h"
7620  #include "xfs_error.h"
7621 @@ -49,6 +50,7 @@
7622  #include <linux/security.h>
7623  #include <linux/fiemap.h>
7624  #include <linux/slab.h>
7625 +#include <linux/vs_tag.h>
7626  
7627  /*
7628   * Bring the timestamps in the XFS inode uptodate.
7629 @@ -474,6 +476,7 @@ xfs_vn_getattr(
7630         stat->nlink = ip->i_d.di_nlink;
7631         stat->uid = ip->i_d.di_uid;
7632         stat->gid = ip->i_d.di_gid;
7633 +       stat->tag = ip->i_d.di_tag;
7634         stat->ino = ip->i_ino;
7635         stat->atime = inode->i_atime;
7636         stat->mtime = inode->i_mtime;
7637 @@ -1051,6 +1054,7 @@ static const struct inode_operations xfs
7638         .removexattr            = generic_removexattr,
7639         .listxattr              = xfs_vn_listxattr,
7640         .fiemap                 = xfs_vn_fiemap,
7641 +       .sync_flags             = xfs_sync_flags,
7642  };
7643  
7644  static const struct inode_operations xfs_dir_inode_operations = {
7645 @@ -1076,6 +1080,7 @@ static const struct inode_operations xfs
7646         .getxattr               = generic_getxattr,
7647         .removexattr            = generic_removexattr,
7648         .listxattr              = xfs_vn_listxattr,
7649 +       .sync_flags             = xfs_sync_flags,
7650  };
7651  
7652  static const struct inode_operations xfs_dir_ci_inode_operations = {
7653 @@ -1125,6 +1130,10 @@ xfs_diflags_to_iflags(
7654                 inode->i_flags |= S_IMMUTABLE;
7655         else
7656                 inode->i_flags &= ~S_IMMUTABLE;
7657 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7658 +               inode->i_flags |= S_IXUNLINK;
7659 +       else
7660 +               inode->i_flags &= ~S_IXUNLINK;
7661         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7662                 inode->i_flags |= S_APPEND;
7663         else
7664 @@ -1137,6 +1146,15 @@ xfs_diflags_to_iflags(
7665                 inode->i_flags |= S_NOATIME;
7666         else
7667                 inode->i_flags &= ~S_NOATIME;
7668 +
7669 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7670 +               inode->i_vflags |= V_BARRIER;
7671 +       else
7672 +               inode->i_vflags &= ~V_BARRIER;
7673 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7674 +               inode->i_vflags |= V_COW;
7675 +       else
7676 +               inode->i_vflags &= ~V_COW;
7677  }
7678  
7679  /*
7680 @@ -1168,6 +1186,7 @@ xfs_setup_inode(
7681         set_nlink(inode, ip->i_d.di_nlink);
7682         inode->i_uid    = ip->i_d.di_uid;
7683         inode->i_gid    = ip->i_d.di_gid;
7684 +       inode->i_tag    = ip->i_d.di_tag;
7685  
7686         switch (inode->i_mode & S_IFMT) {
7687         case S_IFBLK:
7688 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_itable.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_itable.c
7689 --- linux-3.3.1/fs/xfs/xfs_itable.c     2011-05-22 16:17:54.000000000 +0200
7690 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_itable.c   2012-02-24 03:55:06.000000000 +0100
7691 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
7692         buf->bs_mode = dic->di_mode;
7693         buf->bs_uid = dic->di_uid;
7694         buf->bs_gid = dic->di_gid;
7695 +       buf->bs_tag = dic->di_tag;
7696         buf->bs_size = dic->di_size;
7697  
7698         /*
7699 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_linux.h linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_linux.h
7700 --- linux-3.3.1/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7701 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_linux.h    2012-02-24 03:55:06.000000000 +0100
7702 @@ -121,6 +121,7 @@
7703  
7704  #define current_cpu()          (raw_smp_processor_id())
7705  #define current_pid()          (current->pid)
7706 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7707  #define current_test_flags(f)  (current->flags & (f))
7708  #define current_set_flags_nested(sp, f)                \
7709                 (*(sp) = current->flags, current->flags |= (f))
7710 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_log_recover.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_log_recover.c
7711 --- linux-3.3.1/fs/xfs/xfs_log_recover.c        2012-04-03 03:01:26.000000000 +0200
7712 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_log_recover.c      2012-04-03 03:02:12.000000000 +0200
7713 @@ -2344,7 +2344,8 @@ xlog_recover_inode_pass2(
7714         }
7715  
7716         /* The core is in in-core format */
7717 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7718 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7719 +               mp->m_flags & XFS_MOUNT_TAGGED);
7720  
7721         /* the rest is in on-disk format */
7722         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7723 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_mount.h linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_mount.h
7724 --- linux-3.3.1/fs/xfs/xfs_mount.h      2012-03-19 19:47:27.000000000 +0100
7725 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_mount.h    2012-02-24 03:55:06.000000000 +0100
7726 @@ -248,6 +248,7 @@ typedef struct xfs_mount {
7727                                                    allocator */
7728  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7729  
7730 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7731  
7732  /*
7733   * Default minimum read and write sizes.
7734 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_super.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_super.c
7735 --- linux-3.3.1/fs/xfs/xfs_super.c      2012-03-19 19:47:27.000000000 +0100
7736 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_super.c    2012-02-24 03:55:06.000000000 +0100
7737 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7738  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7739  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7740  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7741 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7742 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7743 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7744  
7745  /*
7746   * Table driven mount option parser.
7747 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7748   * in the future, too.
7749   */
7750  enum {
7751 +       Opt_tag, Opt_notag,
7752         Opt_barrier, Opt_nobarrier, Opt_err
7753  };
7754  
7755  static const match_table_t tokens = {
7756 +       {Opt_tag, "tagxid"},
7757 +       {Opt_tag, "tag"},
7758 +       {Opt_notag, "notag"},
7759         {Opt_barrier, "barrier"},
7760         {Opt_nobarrier, "nobarrier"},
7761         {Opt_err, NULL}
7762 @@ -373,6 +380,19 @@ xfs_parseargs(
7763                 } else if (!strcmp(this_char, "irixsgid")) {
7764                         xfs_warn(mp,
7765         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7766 +#ifndef CONFIG_TAGGING_NONE
7767 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7768 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7769 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7770 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7771 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7772 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7773 +#endif
7774 +#ifdef CONFIG_PROPAGATE
7775 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7776 +                       /* use value */
7777 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7778 +#endif
7779                 } else {
7780                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7781                         return EINVAL;
7782 @@ -1114,6 +1134,16 @@ xfs_fs_remount(
7783                 case Opt_nobarrier:
7784                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7785                         break;
7786 +               case Opt_tag:
7787 +                       if (!(sb->s_flags & MS_TAGGED)) {
7788 +                               printk(KERN_INFO
7789 +                                       "XFS: %s: tagging not permitted on remount.\n",
7790 +                                       sb->s_id);
7791 +                               return -EINVAL;
7792 +                       }
7793 +                       break;
7794 +               case Opt_notag:
7795 +                       break;
7796                 default:
7797                         /*
7798                          * Logically we would return an error here to prevent
7799 @@ -1329,6 +1359,9 @@ xfs_fs_fill_super(
7800         if (error)
7801                 goto out_free_sb;
7802  
7803 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7804 +               sb->s_flags |= MS_TAGGED;
7805 +
7806         /*
7807          * we must configure the block size in the superblock before we run the
7808          * full mount process as the mount process can lookup and cache inodes.
7809 diff -NurpP --minimal linux-3.3.1/fs/xfs/xfs_vnodeops.c linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_vnodeops.c
7810 --- linux-3.3.1/fs/xfs/xfs_vnodeops.c   2012-03-19 19:47:27.000000000 +0100
7811 +++ linux-3.3.1-vs2.3.3.2/fs/xfs/xfs_vnodeops.c 2012-04-01 18:12:15.000000000 +0200
7812 @@ -106,6 +106,77 @@ xfs_readlink_bmap(
7813         return error;
7814  }
7815  
7816 +
7817 +STATIC void
7818 +xfs_get_inode_flags(
7819 +       xfs_inode_t     *ip)
7820 +{
7821 +       struct inode    *inode = VFS_I(ip);
7822 +       unsigned int    flags = inode->i_flags;
7823 +       unsigned int    vflags = inode->i_vflags;
7824 +
7825 +       if (flags & S_IMMUTABLE)
7826 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7827 +       else
7828 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7829 +       if (flags & S_IXUNLINK)
7830 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7831 +       else
7832 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7833 +
7834 +       if (vflags & V_BARRIER)
7835 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7836 +       else
7837 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7838 +       if (vflags & V_COW)
7839 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7840 +       else
7841 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7842 +}
7843 +
7844 +int
7845 +xfs_sync_flags(
7846 +       struct inode            *inode,
7847 +       int                     flags,
7848 +       int                     vflags)
7849 +{
7850 +       struct xfs_inode        *ip = XFS_I(inode);
7851 +       struct xfs_mount        *mp = ip->i_mount;
7852 +       struct xfs_trans        *tp;
7853 +       unsigned int            lock_flags = 0;
7854 +       int                     code;
7855 +
7856 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7857 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7858 +       if (code)
7859 +               goto error_out;
7860 +
7861 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7862 +       xfs_trans_ijoin(tp, ip, 0);
7863 +
7864 +       inode->i_flags = flags;
7865 +       inode->i_vflags = vflags;
7866 +       xfs_get_inode_flags(ip);
7867 +
7868 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7869 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7870 +
7871 +       XFS_STATS_INC(xs_ig_attrchg);
7872 +
7873 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7874 +               xfs_trans_set_sync(tp);
7875 +       code = xfs_trans_commit(tp, 0);
7876 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7877 +       return code;
7878 +
7879 +error_out:
7880 +       xfs_trans_cancel(tp, 0);
7881 +       if (lock_flags)
7882 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7883 +       return code;
7884 +}
7885 +
7886 +
7887  int
7888  xfs_readlink(
7889         xfs_inode_t     *ip,
7890 diff -NurpP --minimal linux-3.3.1/include/linux/Kbuild linux-3.3.1-vs2.3.3.2/include/linux/Kbuild
7891 --- linux-3.3.1/include/linux/Kbuild    2012-03-19 19:47:27.000000000 +0100
7892 +++ linux-3.3.1-vs2.3.3.2/include/linux/Kbuild  2012-02-24 03:55:06.000000000 +0100
7893 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
7894  header-y += netfilter_ipv4/
7895  header-y += netfilter_ipv6/
7896  header-y += usb/
7897 +header-y += vserver/
7898  header-y += wimax/
7899  
7900  objhdr-y += version.h
7901 diff -NurpP --minimal linux-3.3.1/include/linux/capability.h linux-3.3.1-vs2.3.3.2/include/linux/capability.h
7902 --- linux-3.3.1/include/linux/capability.h      2012-03-19 19:47:27.000000000 +0100
7903 +++ linux-3.3.1-vs2.3.3.2/include/linux/capability.h    2012-02-24 03:55:06.000000000 +0100
7904 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7905     arbitrary SCSI commands */
7906  /* Allow setting encryption key on loopback filesystem */
7907  /* Allow setting zone reclaim policy */
7908 +/* Allow the selection of a security context */
7909  
7910  #define CAP_SYS_ADMIN        21
7911  
7912 @@ -363,7 +364,12 @@ struct cpu_vfs_cap_data {
7913  
7914  #define CAP_LAST_CAP         CAP_WAKE_ALARM
7915  
7916 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7917 +/* Allow context manipulations */
7918 +/* Allow changing context info on files */
7919 +
7920 +#define CAP_CONTEXT         63
7921 +
7922 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7923  
7924  /*
7925   * Bit location of each capability (used by user-space library and kernel)
7926 diff -NurpP --minimal linux-3.3.1/include/linux/cred.h linux-3.3.1-vs2.3.3.2/include/linux/cred.h
7927 --- linux-3.3.1/include/linux/cred.h    2012-03-19 19:47:27.000000000 +0100
7928 +++ linux-3.3.1-vs2.3.3.2/include/linux/cred.h  2012-02-24 03:55:06.000000000 +0100
7929 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
7930  extern int copy_creds(struct task_struct *, unsigned long);
7931  extern const struct cred *get_task_cred(struct task_struct *);
7932  extern struct cred *cred_alloc_blank(void);
7933 +extern struct cred *__prepare_creds(const struct cred *);
7934  extern struct cred *prepare_creds(void);
7935  extern struct cred *prepare_exec_creds(void);
7936  extern int commit_creds(struct cred *);
7937 @@ -209,6 +210,31 @@ static inline void validate_process_cred
7938  }
7939  #endif
7940  
7941 +static inline void set_cred_subscribers(struct cred *cred, int n)
7942 +{
7943 +#ifdef CONFIG_DEBUG_CREDENTIALS
7944 +       atomic_set(&cred->subscribers, n);
7945 +#endif
7946 +}
7947 +
7948 +static inline int read_cred_subscribers(const struct cred *cred)
7949 +{
7950 +#ifdef CONFIG_DEBUG_CREDENTIALS
7951 +       return atomic_read(&cred->subscribers);
7952 +#else
7953 +       return 0;
7954 +#endif
7955 +}
7956 +
7957 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7958 +{
7959 +#ifdef CONFIG_DEBUG_CREDENTIALS
7960 +       struct cred *cred = (struct cred *) _cred;
7961 +
7962 +       atomic_add(n, &cred->subscribers);
7963 +#endif
7964 +}
7965 +
7966  /**
7967   * get_new_cred - Get a reference on a new set of credentials
7968   * @cred: The new credentials to reference
7969 diff -NurpP --minimal linux-3.3.1/include/linux/devpts_fs.h linux-3.3.1-vs2.3.3.2/include/linux/devpts_fs.h
7970 --- linux-3.3.1/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
7971 +++ linux-3.3.1-vs2.3.3.2/include/linux/devpts_fs.h     2012-02-24 03:55:06.000000000 +0100
7972 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7973  
7974  #endif
7975  
7976 -
7977  #endif /* _LINUX_DEVPTS_FS_H */
7978 diff -NurpP --minimal linux-3.3.1/include/linux/ext2_fs.h linux-3.3.1-vs2.3.3.2/include/linux/ext2_fs.h
7979 --- linux-3.3.1/include/linux/ext2_fs.h 2012-01-09 16:14:56.000000000 +0100
7980 +++ linux-3.3.1-vs2.3.3.2/include/linux/ext2_fs.h       2012-02-24 03:55:06.000000000 +0100
7981 @@ -190,8 +190,12 @@ struct ext2_group_desc
7982  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
7983  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
7984  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
7985 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
7986  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
7987  
7988 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
7989 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
7990 +
7991  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
7992  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
7993  
7994 @@ -275,7 +279,8 @@ struct ext2_inode {
7995                         __u16   i_pad1;
7996                         __le16  l_i_uid_high;   /* these 2 fields    */
7997                         __le16  l_i_gid_high;   /* were reserved2[0] */
7998 -                       __u32   l_i_reserved2;
7999 +                       __le16  l_i_tag;        /* Context Tag */
8000 +                       __u16   l_i_reserved2;
8001                 } linux2;
8002                 struct {
8003                         __u8    h_i_frag;       /* Fragment number */
8004 @@ -304,6 +309,7 @@ struct ext2_inode {
8005  #define i_gid_low      i_gid
8006  #define i_uid_high     osd2.linux2.l_i_uid_high
8007  #define i_gid_high     osd2.linux2.l_i_gid_high
8008 +#define i_raw_tag      osd2.linux2.l_i_tag
8009  #define i_reserved2    osd2.linux2.l_i_reserved2
8010  #endif
8011  
8012 @@ -348,6 +354,7 @@ struct ext2_inode {
8013  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8014  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8015  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8016 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8017  
8018  
8019  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8020 diff -NurpP --minimal linux-3.3.1/include/linux/ext3_fs.h linux-3.3.1-vs2.3.3.2/include/linux/ext3_fs.h
8021 --- linux-3.3.1/include/linux/ext3_fs.h 2012-03-19 19:47:27.000000000 +0100
8022 +++ linux-3.3.1-vs2.3.3.2/include/linux/ext3_fs.h       2012-02-24 03:55:06.000000000 +0100
8023 @@ -173,10 +173,14 @@ struct ext3_group_desc
8024  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8025  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8026  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8027 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8028  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8029  
8030 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8031 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8032 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8033 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8034 +
8035 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8036 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8037  
8038  /* Flags that should be inherited by new inodes from their parent. */
8039  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8040 @@ -312,7 +316,8 @@ struct ext3_inode {
8041                         __u16   i_pad1;
8042                         __le16  l_i_uid_high;   /* these 2 fields    */
8043                         __le16  l_i_gid_high;   /* were reserved2[0] */
8044 -                       __u32   l_i_reserved2;
8045 +                       __le16  l_i_tag;        /* Context Tag */
8046 +                       __u16   l_i_reserved2;
8047                 } linux2;
8048                 struct {
8049                         __u8    h_i_frag;       /* Fragment number */
8050 @@ -343,6 +348,7 @@ struct ext3_inode {
8051  #define i_gid_low      i_gid
8052  #define i_uid_high     osd2.linux2.l_i_uid_high
8053  #define i_gid_high     osd2.linux2.l_i_gid_high
8054 +#define i_raw_tag      osd2.linux2.l_i_tag
8055  #define i_reserved2    osd2.linux2.l_i_reserved2
8056  
8057  #elif defined(__GNU__)
8058 @@ -405,6 +411,7 @@ struct ext3_inode {
8059  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8060  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8061                                                   * error in ordered mode */
8062 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8063  
8064  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8065  #ifndef _LINUX_EXT2_FS_H
8066 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8067  extern void ext3_set_aops(struct inode *inode);
8068  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8069                        u64 start, u64 len);
8070 +extern int ext3_sync_flags(struct inode *, int, int);
8071  
8072  /* ioctl.c */
8073  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8074 diff -NurpP --minimal linux-3.3.1/include/linux/fs.h linux-3.3.1-vs2.3.3.2/include/linux/fs.h
8075 --- linux-3.3.1/include/linux/fs.h      2012-03-19 19:47:27.000000000 +0100
8076 +++ linux-3.3.1-vs2.3.3.2/include/linux/fs.h    2012-03-19 20:52:10.000000000 +0100
8077 @@ -210,6 +210,9 @@ struct inodes_stat_t {
8078  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8079  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8080  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8081 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8082 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8083 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8084  #define MS_NOSEC       (1<<28)
8085  #define MS_BORN                (1<<29)
8086  #define MS_ACTIVE      (1<<30)
8087 @@ -241,6 +244,14 @@ struct inodes_stat_t {
8088  #define S_IMA          1024    /* Inode has an associated IMA struct */
8089  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8090  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8091 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8092 +
8093 +/* Linux-VServer related Inode flags */
8094 +
8095 +#define V_VALID                1
8096 +#define V_XATTR                2
8097 +#define V_BARRIER      4       /* Barrier for chroot() */
8098 +#define V_COW          8       /* Copy on Write */
8099  
8100  /*
8101   * Note that nosuid etc flags are inode-specific: setting some file-system
8102 @@ -263,12 +274,15 @@ struct inodes_stat_t {
8103  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8104                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8105  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8106 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8107 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8108 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8109 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8110 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8111  
8112  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8113  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8114  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8115 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8116 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8117  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8118  
8119  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8120 @@ -279,6 +293,16 @@ struct inodes_stat_t {
8121  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8122  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8123  
8124 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8125 +
8126 +#ifdef CONFIG_VSERVER_COWBL
8127 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8128 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8129 +#else
8130 +#  define IS_COW(inode)                (0)
8131 +#  define IS_COW_LINK(inode)   (0)
8132 +#endif
8133 +
8134  /* the read-only stuff doesn't really belong here, but any other place is
8135     probably as bad and I don't want to create yet another include file. */
8136  
8137 @@ -365,11 +389,14 @@ struct inodes_stat_t {
8138  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8139  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8140  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8141 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8142  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8143  
8144 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8145 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8146 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8147 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8148  
8149 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8150 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8151  
8152  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8153  #define SYNC_FILE_RANGE_WRITE          2
8154 @@ -451,6 +478,7 @@ typedef void (dio_iodone_t)(struct kiocb
8155  #define ATTR_KILL_PRIV (1 << 14)
8156  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8157  #define ATTR_TIMES_SET (1 << 16)
8158 +#define ATTR_TAG       (1 << 17)
8159  
8160  /*
8161   * This is the Inode Attributes structure, used for notify_change().  It
8162 @@ -466,6 +494,7 @@ struct iattr {
8163         umode_t         ia_mode;
8164         uid_t           ia_uid;
8165         gid_t           ia_gid;
8166 +       tag_t           ia_tag;
8167         loff_t          ia_size;
8168         struct timespec ia_atime;
8169         struct timespec ia_mtime;
8170 @@ -479,6 +508,9 @@ struct iattr {
8171         struct file     *ia_file;
8172  };
8173  
8174 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8175 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8176 +
8177  /*
8178   * Includes for diskquotas.
8179   */
8180 @@ -758,7 +790,9 @@ struct inode {
8181         unsigned short          i_opflags;
8182         uid_t                   i_uid;
8183         gid_t                   i_gid;
8184 -       unsigned int            i_flags;
8185 +       tag_t                   i_tag;
8186 +       unsigned short          i_flags;
8187 +       unsigned short          i_vflags;
8188  
8189  #ifdef CONFIG_FS_POSIX_ACL
8190         struct posix_acl        *i_acl;
8191 @@ -787,6 +821,7 @@ struct inode {
8192                 unsigned int __i_nlink;
8193         };
8194         dev_t                   i_rdev;
8195 +       dev_t                   i_mdev;
8196         struct timespec         i_atime;
8197         struct timespec         i_mtime;
8198         struct timespec         i_ctime;
8199 @@ -924,12 +959,12 @@ static inline void i_size_write(struct i
8200  
8201  static inline unsigned iminor(const struct inode *inode)
8202  {
8203 -       return MINOR(inode->i_rdev);
8204 +       return MINOR(inode->i_mdev);
8205  }
8206  
8207  static inline unsigned imajor(const struct inode *inode)
8208  {
8209 -       return MAJOR(inode->i_rdev);
8210 +       return MAJOR(inode->i_mdev);
8211  }
8212  
8213  extern struct block_device *I_BDEV(struct inode *inode);
8214 @@ -996,6 +1031,7 @@ struct file {
8215         loff_t                  f_pos;
8216         struct fown_struct      f_owner;
8217         const struct cred       *f_cred;
8218 +       xid_t                   f_xid;
8219         struct file_ra_state    f_ra;
8220  
8221         u64                     f_version;
8222 @@ -1143,6 +1179,7 @@ struct file_lock {
8223         struct file *fl_file;
8224         loff_t fl_start;
8225         loff_t fl_end;
8226 +       xid_t fl_xid;
8227  
8228         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8229         /* for lease breaks: */
8230 @@ -1650,6 +1687,7 @@ struct inode_operations {
8231         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8232         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8233         int (*removexattr) (struct dentry *, const char *);
8234 +       int (*sync_flags) (struct inode *, int, int);
8235         void (*truncate_range)(struct inode *, loff_t, loff_t);
8236         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8237                       u64 len);
8238 @@ -1669,6 +1707,7 @@ extern ssize_t vfs_readv(struct file *, 
8239                 unsigned long, loff_t *);
8240  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8241                 unsigned long, loff_t *);
8242 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8243  
8244  struct super_operations {
8245         struct inode *(*alloc_inode)(struct super_block *sb);
8246 @@ -2507,6 +2546,7 @@ extern int dcache_dir_open(struct inode 
8247  extern int dcache_dir_close(struct inode *, struct file *);
8248  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8249  extern int dcache_readdir(struct file *, void *, filldir_t);
8250 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8251  extern int simple_setattr(struct dentry *, struct iattr *);
8252  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8253  extern int simple_statfs(struct dentry *, struct kstatfs *);
8254 diff -NurpP --minimal linux-3.3.1/include/linux/gfs2_ondisk.h linux-3.3.1-vs2.3.3.2/include/linux/gfs2_ondisk.h
8255 --- linux-3.3.1/include/linux/gfs2_ondisk.h     2012-03-19 19:47:28.000000000 +0100
8256 +++ linux-3.3.1-vs2.3.3.2/include/linux/gfs2_ondisk.h   2012-02-24 03:55:06.000000000 +0100
8257 @@ -213,6 +213,9 @@ enum {
8258         gfs2fl_NoAtime          = 7,
8259         gfs2fl_Sync             = 8,
8260         gfs2fl_System           = 9,
8261 +       gfs2fl_IXUnlink         = 16,
8262 +       gfs2fl_Barrier          = 17,
8263 +       gfs2fl_Cow              = 18,
8264         gfs2fl_TruncInProg      = 29,
8265         gfs2fl_InheritDirectio  = 30,
8266         gfs2fl_InheritJdata     = 31,
8267 @@ -229,6 +232,9 @@ enum {
8268  #define GFS2_DIF_NOATIME               0x00000080
8269  #define GFS2_DIF_SYNC                  0x00000100
8270  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8271 +#define GFS2_DIF_IXUNLINK              0x00010000
8272 +#define GFS2_DIF_BARRIER               0x00020000
8273 +#define GFS2_DIF_COW                   0x00040000
8274  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8275  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8276  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8277 diff -NurpP --minimal linux-3.3.1/include/linux/if_tun.h linux-3.3.1-vs2.3.3.2/include/linux/if_tun.h
8278 --- linux-3.3.1/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8279 +++ linux-3.3.1-vs2.3.3.2/include/linux/if_tun.h        2012-02-24 03:55:06.000000000 +0100
8280 @@ -53,6 +53,7 @@
8281  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8282  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8283  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8284 +#define TUNSETNID     _IOW('T', 217, int)
8285  
8286  /* TUNSETIFF ifr flags */
8287  #define IFF_TUN                0x0001
8288 diff -NurpP --minimal linux-3.3.1/include/linux/init_task.h linux-3.3.1-vs2.3.3.2/include/linux/init_task.h
8289 --- linux-3.3.1/include/linux/init_task.h       2012-03-19 19:47:28.000000000 +0100
8290 +++ linux-3.3.1-vs2.3.3.2/include/linux/init_task.h     2012-02-24 03:55:06.000000000 +0100
8291 @@ -192,6 +192,10 @@ extern struct cred init_cred;
8292         INIT_FTRACE_GRAPH                                               \
8293         INIT_TRACE_RECURSION                                            \
8294         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8295 +       .xid            = 0,                                            \
8296 +       .vx_info        = NULL,                                         \
8297 +       .nid            = 0,                                            \
8298 +       .nx_info        = NULL,                                         \
8299  }
8300  
8301  
8302 diff -NurpP --minimal linux-3.3.1/include/linux/ipc.h linux-3.3.1-vs2.3.3.2/include/linux/ipc.h
8303 --- linux-3.3.1/include/linux/ipc.h     2012-03-19 19:47:28.000000000 +0100
8304 +++ linux-3.3.1-vs2.3.3.2/include/linux/ipc.h   2012-02-24 03:55:06.000000000 +0100
8305 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8306         key_t           key;
8307         uid_t           uid;
8308         gid_t           gid;
8309 +       xid_t           xid;
8310         uid_t           cuid;
8311         gid_t           cgid;
8312         umode_t         mode; 
8313 diff -NurpP --minimal linux-3.3.1/include/linux/ipc_namespace.h linux-3.3.1-vs2.3.3.2/include/linux/ipc_namespace.h
8314 --- linux-3.3.1/include/linux/ipc_namespace.h   2011-10-24 18:45:32.000000000 +0200
8315 +++ linux-3.3.1-vs2.3.3.2/include/linux/ipc_namespace.h 2012-02-24 03:55:06.000000000 +0100
8316 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8317  
8318  #if defined(CONFIG_IPC_NS)
8319  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8320 -                                      struct task_struct *tsk);
8321 +                                      struct ipc_namespace *old_ns,
8322 +                                      struct user_namespace *user_ns);
8323  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8324  {
8325         if (ns)
8326 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8327  extern void put_ipc_ns(struct ipc_namespace *ns);
8328  #else
8329  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8330 -                                             struct task_struct *tsk)
8331 +                                             struct ipc_namespace *old_ns,
8332 +                                             struct user_namespace *user_ns)
8333  {
8334         if (flags & CLONE_NEWIPC)
8335                 return ERR_PTR(-EINVAL);
8336  
8337 -       return tsk->nsproxy->ipc_ns;
8338 +       return old_ns;
8339  }
8340  
8341  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8342 diff -NurpP --minimal linux-3.3.1/include/linux/loop.h linux-3.3.1-vs2.3.3.2/include/linux/loop.h
8343 --- linux-3.3.1/include/linux/loop.h    2012-01-09 16:14:58.000000000 +0100
8344 +++ linux-3.3.1-vs2.3.3.2/include/linux/loop.h  2012-02-24 03:55:06.000000000 +0100
8345 @@ -45,6 +45,7 @@ struct loop_device {
8346         struct loop_func_table *lo_encryption;
8347         __u32           lo_init[2];
8348         uid_t           lo_key_owner;   /* Who set the key */
8349 +       xid_t           lo_xid;
8350         int             (*ioctl)(struct loop_device *, int cmd, 
8351                                  unsigned long arg); 
8352  
8353 diff -NurpP --minimal linux-3.3.1/include/linux/magic.h linux-3.3.1-vs2.3.3.2/include/linux/magic.h
8354 --- linux-3.3.1/include/linux/magic.h   2012-01-09 16:14:58.000000000 +0100
8355 +++ linux-3.3.1-vs2.3.3.2/include/linux/magic.h 2012-02-24 03:55:06.000000000 +0100
8356 @@ -3,7 +3,7 @@
8357  
8358  #define ADFS_SUPER_MAGIC       0xadf5
8359  #define AFFS_SUPER_MAGIC       0xadff
8360 -#define AFS_SUPER_MAGIC                0x5346414F
8361 +#define AFS_SUPER_MAGIC                0x5346414F
8362  #define AUTOFS_SUPER_MAGIC     0x0187
8363  #define CODA_SUPER_MAGIC       0x73757245
8364  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8365 @@ -41,6 +41,7 @@
8366  #define NFS_SUPER_MAGIC                0x6969
8367  #define OPENPROM_SUPER_MAGIC   0x9fa1
8368  #define PROC_SUPER_MAGIC       0x9fa0
8369 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8370  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8371  
8372  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8373 diff -NurpP --minimal linux-3.3.1/include/linux/major.h linux-3.3.1-vs2.3.3.2/include/linux/major.h
8374 --- linux-3.3.1/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8375 +++ linux-3.3.1-vs2.3.3.2/include/linux/major.h 2012-02-24 03:55:06.000000000 +0100
8376 @@ -15,6 +15,7 @@
8377  #define HD_MAJOR               IDE0_MAJOR
8378  #define PTY_SLAVE_MAJOR                3
8379  #define TTY_MAJOR              4
8380 +#define VROOT_MAJOR            4
8381  #define TTYAUX_MAJOR           5
8382  #define LP_MAJOR               6
8383  #define VCS_MAJOR              7
8384 diff -NurpP --minimal linux-3.3.1/include/linux/memcontrol.h linux-3.3.1-vs2.3.3.2/include/linux/memcontrol.h
8385 --- linux-3.3.1/include/linux/memcontrol.h      2012-03-19 19:47:28.000000000 +0100
8386 +++ linux-3.3.1-vs2.3.3.2/include/linux/memcontrol.h    2012-03-19 20:52:10.000000000 +0100
8387 @@ -87,6 +87,13 @@ extern struct mem_cgroup *try_get_mem_cg
8388  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8389  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8390  
8391 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8392 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8393 +
8394 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8395 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8396 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8397 +
8398  static inline
8399  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8400  {
8401 diff -NurpP --minimal linux-3.3.1/include/linux/mm_types.h linux-3.3.1-vs2.3.3.2/include/linux/mm_types.h
8402 --- linux-3.3.1/include/linux/mm_types.h        2012-03-19 19:47:28.000000000 +0100
8403 +++ linux-3.3.1-vs2.3.3.2/include/linux/mm_types.h      2012-02-24 03:55:06.000000000 +0100
8404 @@ -343,6 +343,7 @@ struct mm_struct {
8405  
8406         /* Architecture-specific MM context */
8407         mm_context_t context;
8408 +       struct vx_info *mm_vx_info;
8409  
8410         /* Swap token stuff */
8411         /*
8412 diff -NurpP --minimal linux-3.3.1/include/linux/mmzone.h linux-3.3.1-vs2.3.3.2/include/linux/mmzone.h
8413 --- linux-3.3.1/include/linux/mmzone.h  2012-03-19 19:47:28.000000000 +0100
8414 +++ linux-3.3.1-vs2.3.3.2/include/linux/mmzone.h        2012-02-24 03:55:06.000000000 +0100
8415 @@ -683,6 +683,13 @@ typedef struct pglist_data {
8416         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8417  })
8418  
8419 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8420 +
8421 +#define node_end_pfn(nid) ({\
8422 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8423 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8424 +})
8425 +
8426  #include <linux/memory_hotplug.h>
8427  
8428  extern struct mutex zonelists_mutex;
8429 diff -NurpP --minimal linux-3.3.1/include/linux/mount.h linux-3.3.1-vs2.3.3.2/include/linux/mount.h
8430 --- linux-3.3.1/include/linux/mount.h   2012-03-19 19:47:28.000000000 +0100
8431 +++ linux-3.3.1-vs2.3.3.2/include/linux/mount.h 2012-02-24 17:29:28.000000000 +0100
8432 @@ -47,6 +47,9 @@ struct mnt_namespace;
8433  
8434  #define MNT_INTERNAL   0x4000
8435  
8436 +#define MNT_TAGID      0x10000
8437 +#define MNT_NOTAG      0x20000
8438 +
8439  struct vfsmount {
8440         struct dentry *mnt_root;        /* root of the mounted tree */
8441         struct super_block *mnt_sb;     /* pointer to superblock */
8442 diff -NurpP --minimal linux-3.3.1/include/linux/net.h linux-3.3.1-vs2.3.3.2/include/linux/net.h
8443 --- linux-3.3.1/include/linux/net.h     2011-07-22 11:18:11.000000000 +0200
8444 +++ linux-3.3.1-vs2.3.3.2/include/linux/net.h   2012-02-24 03:55:06.000000000 +0100
8445 @@ -72,6 +72,7 @@ struct net;
8446  #define SOCK_NOSPACE           2
8447  #define SOCK_PASSCRED          3
8448  #define SOCK_PASSSEC           4
8449 +#define SOCK_USER_SOCKET       5
8450  
8451  #ifndef ARCH_HAS_SOCKET_TYPES
8452  /**
8453 diff -NurpP --minimal linux-3.3.1/include/linux/netdevice.h linux-3.3.1-vs2.3.3.2/include/linux/netdevice.h
8454 --- linux-3.3.1/include/linux/netdevice.h       2012-03-19 19:47:28.000000000 +0100
8455 +++ linux-3.3.1-vs2.3.3.2/include/linux/netdevice.h     2012-02-24 03:55:06.000000000 +0100
8456 @@ -1627,6 +1627,7 @@ extern void               netdev_resync_ops(struct ne
8457  
8458  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8459  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8460 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8461  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8462  extern int             dev_restart(struct net_device *dev);
8463  #ifdef CONFIG_NETPOLL_TRAP
8464 diff -NurpP --minimal linux-3.3.1/include/linux/nfs_mount.h linux-3.3.1-vs2.3.3.2/include/linux/nfs_mount.h
8465 --- linux-3.3.1/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8466 +++ linux-3.3.1-vs2.3.3.2/include/linux/nfs_mount.h     2012-02-24 03:55:06.000000000 +0100
8467 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8468  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8469  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8470  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8471 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8472 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8473 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8474  
8475  /* The following are for internal use only */
8476  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8477 diff -NurpP --minimal linux-3.3.1/include/linux/nsproxy.h linux-3.3.1-vs2.3.3.2/include/linux/nsproxy.h
8478 --- linux-3.3.1/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8479 +++ linux-3.3.1-vs2.3.3.2/include/linux/nsproxy.h       2012-02-24 03:55:06.000000000 +0100
8480 @@ -3,6 +3,7 @@
8481  
8482  #include <linux/spinlock.h>
8483  #include <linux/sched.h>
8484 +#include <linux/vserver/debug.h>
8485  
8486  struct mnt_namespace;
8487  struct uts_namespace;
8488 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8489  }
8490  
8491  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8492 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8493  void exit_task_namespaces(struct task_struct *tsk);
8494  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8495  void free_nsproxy(struct nsproxy *ns);
8496 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8497         struct fs_struct *);
8498  int __init nsproxy_cache_init(void);
8499  
8500 -static inline void put_nsproxy(struct nsproxy *ns)
8501 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8502 +
8503 +static inline void __get_nsproxy(struct nsproxy *ns,
8504 +       const char *_file, int _line)
8505  {
8506 -       if (atomic_dec_and_test(&ns->count)) {
8507 -               free_nsproxy(ns);
8508 -       }
8509 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8510 +               ns, atomic_read(&ns->count), _file, _line);
8511 +       atomic_inc(&ns->count);
8512  }
8513  
8514 -static inline void get_nsproxy(struct nsproxy *ns)
8515 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8516 +
8517 +static inline void __put_nsproxy(struct nsproxy *ns,
8518 +       const char *_file, int _line)
8519  {
8520 -       atomic_inc(&ns->count);
8521 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8522 +               ns, atomic_read(&ns->count), _file, _line);
8523 +       if (atomic_dec_and_test(&ns->count)) {
8524 +               free_nsproxy(ns);
8525 +       }
8526  }
8527  
8528  #endif
8529 diff -NurpP --minimal linux-3.3.1/include/linux/pid.h linux-3.3.1-vs2.3.3.2/include/linux/pid.h
8530 --- linux-3.3.1/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8531 +++ linux-3.3.1-vs2.3.3.2/include/linux/pid.h   2012-02-24 03:55:06.000000000 +0100
8532 @@ -8,7 +8,8 @@ enum pid_type
8533         PIDTYPE_PID,
8534         PIDTYPE_PGID,
8535         PIDTYPE_SID,
8536 -       PIDTYPE_MAX
8537 +       PIDTYPE_MAX,
8538 +       PIDTYPE_REALPID
8539  };
8540  
8541  /*
8542 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8543  }
8544  
8545  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8546 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8547  pid_t pid_vnr(struct pid *pid);
8548  
8549  #define do_each_pid_task(pid, type, task)                              \
8550 diff -NurpP --minimal linux-3.3.1/include/linux/proc_fs.h linux-3.3.1-vs2.3.3.2/include/linux/proc_fs.h
8551 --- linux-3.3.1/include/linux/proc_fs.h 2012-03-19 19:47:28.000000000 +0100
8552 +++ linux-3.3.1-vs2.3.3.2/include/linux/proc_fs.h       2012-02-24 04:17:21.000000000 +0100
8553 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8554         nlink_t nlink;
8555         uid_t uid;
8556         gid_t gid;
8557 +       int vx_flags;
8558         loff_t size;
8559         const struct inode_operations *proc_iops;
8560         /*
8561 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8562  extern const struct proc_ns_operations utsns_operations;
8563  extern const struct proc_ns_operations ipcns_operations;
8564  
8565 +struct vx_info;
8566 +struct nx_info;
8567 +
8568  union proc_op {
8569         int (*proc_get_link)(struct dentry *, struct path *);
8570         int (*proc_read)(struct task_struct *task, char *page);
8571         int (*proc_show)(struct seq_file *m,
8572                 struct pid_namespace *ns, struct pid *pid,
8573                 struct task_struct *task);
8574 +       int (*proc_vs_read)(char *page);
8575 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8576 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8577  };
8578  
8579  struct ctl_table_header;
8580 @@ -265,6 +272,7 @@ struct ctl_table;
8581  
8582  struct proc_inode {
8583         struct pid *pid;
8584 +       int vx_flags;
8585         int fd;
8586         union proc_op op;
8587         struct proc_dir_entry *pde;
8588 diff -NurpP --minimal linux-3.3.1/include/linux/quotaops.h linux-3.3.1-vs2.3.3.2/include/linux/quotaops.h
8589 --- linux-3.3.1/include/linux/quotaops.h        2012-01-09 16:14:58.000000000 +0100
8590 +++ linux-3.3.1-vs2.3.3.2/include/linux/quotaops.h      2012-02-24 03:55:06.000000000 +0100
8591 @@ -8,6 +8,7 @@
8592  #define _LINUX_QUOTAOPS_
8593  
8594  #include <linux/fs.h>
8595 +#include <linux/vs_dlimit.h>
8596  
8597  #define DQUOT_SPACE_WARN       0x1
8598  #define DQUOT_SPACE_RESERVE    0x2
8599 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8600  
8601  static inline int dquot_alloc_inode(const struct inode *inode)
8602  {
8603 -       return 0;
8604 +       return dl_alloc_inode(inode);
8605  }
8606  
8607  static inline void dquot_free_inode(const struct inode *inode)
8608  {
8609 +       dl_free_inode(inode);
8610  }
8611  
8612  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8613 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8614  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8615                 int flags)
8616  {
8617 +       int ret = 0;
8618 +
8619 +       if ((ret = dl_alloc_space(inode, number)))
8620 +               return ret;
8621         if (!(flags & DQUOT_SPACE_RESERVE))
8622                 inode_add_bytes(inode, number);
8623         return 0;
8624 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8625  {
8626         if (!(flags & DQUOT_SPACE_RESERVE))
8627                 inode_sub_bytes(inode, number);
8628 +       dl_free_space(inode, number);
8629  }
8630  
8631  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8632 diff -NurpP --minimal linux-3.3.1/include/linux/reboot.h linux-3.3.1-vs2.3.3.2/include/linux/reboot.h
8633 --- linux-3.3.1/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8634 +++ linux-3.3.1-vs2.3.3.2/include/linux/reboot.h        2012-02-24 03:55:06.000000000 +0100
8635 @@ -33,6 +33,7 @@
8636  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8637  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8638  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8639 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8640  
8641  
8642  #ifdef __KERNEL__
8643 diff -NurpP --minimal linux-3.3.1/include/linux/reiserfs_fs.h linux-3.3.1-vs2.3.3.2/include/linux/reiserfs_fs.h
8644 --- linux-3.3.1/include/linux/reiserfs_fs.h     2012-03-19 19:47:28.000000000 +0100
8645 +++ linux-3.3.1-vs2.3.3.2/include/linux/reiserfs_fs.h   2012-02-24 03:55:06.000000000 +0100
8646 @@ -976,6 +976,11 @@ struct stat_data_v1 {
8647  #define REISERFS_COMPR_FL     FS_COMPR_FL
8648  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8649  
8650 +/* unfortunately reiserfs sdattr is only 16 bit */
8651 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8652 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8653 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8654 +
8655  /* persistent flags that file inherits from the parent directory */
8656  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8657                                 REISERFS_SYNC_FL |      \
8658 @@ -985,6 +990,9 @@ struct stat_data_v1 {
8659                                 REISERFS_COMPR_FL |     \
8660                                 REISERFS_NOTAIL_FL )
8661  
8662 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8663 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8664 +
8665  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8666     address blocks) */
8667  struct stat_data {
8668 @@ -2074,6 +2082,7 @@ static inline void reiserfs_update_sd(st
8669  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8670  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8671  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8672 +int reiserfs_sync_flags(struct inode *inode, int, int);
8673  
8674  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
8675  
8676 diff -NurpP --minimal linux-3.3.1/include/linux/reiserfs_fs_sb.h linux-3.3.1-vs2.3.3.2/include/linux/reiserfs_fs_sb.h
8677 --- linux-3.3.1/include/linux/reiserfs_fs_sb.h  2012-03-19 19:47:28.000000000 +0100
8678 +++ linux-3.3.1-vs2.3.3.2/include/linux/reiserfs_fs_sb.h        2012-02-24 03:55:06.000000000 +0100
8679 @@ -477,6 +477,7 @@ enum reiserfs_mount_options {
8680         REISERFS_EXPOSE_PRIVROOT,
8681         REISERFS_BARRIER_NONE,
8682         REISERFS_BARRIER_FLUSH,
8683 +       REISERFS_TAGGED,
8684  
8685         /* Actions on error */
8686         REISERFS_ERROR_PANIC,
8687 diff -NurpP --minimal linux-3.3.1/include/linux/sched.h linux-3.3.1-vs2.3.3.2/include/linux/sched.h
8688 --- linux-3.3.1/include/linux/sched.h   2012-03-19 19:47:28.000000000 +0100
8689 +++ linux-3.3.1-vs2.3.3.2/include/linux/sched.h 2012-03-19 20:52:10.000000000 +0100
8690 @@ -1420,6 +1420,14 @@ struct task_struct {
8691  #endif
8692         seccomp_t seccomp;
8693  
8694 +/* vserver context data */
8695 +       struct vx_info *vx_info;
8696 +       struct nx_info *nx_info;
8697 +
8698 +       xid_t xid;
8699 +       nid_t nid;
8700 +       tag_t tag;
8701 +
8702  /* Thread group tracking */
8703         u32 parent_exec_id;
8704         u32 self_exec_id;
8705 @@ -1669,6 +1677,11 @@ struct pid_namespace;
8706  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8707                         struct pid_namespace *ns);
8708  
8709 +#include <linux/vserver/base.h>
8710 +#include <linux/vserver/context.h>
8711 +#include <linux/vserver/debug.h>
8712 +#include <linux/vserver/pid.h>
8713 +
8714  static inline pid_t task_pid_nr(struct task_struct *tsk)
8715  {
8716         return tsk->pid;
8717 @@ -1682,7 +1695,8 @@ static inline pid_t task_pid_nr_ns(struc
8718  
8719  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8720  {
8721 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8722 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8723 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8724  }
8725  
8726  
8727 @@ -1695,7 +1709,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8728  
8729  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8730  {
8731 -       return pid_vnr(task_tgid(tsk));
8732 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8733  }
8734  
8735  
8736 diff -NurpP --minimal linux-3.3.1/include/linux/shmem_fs.h linux-3.3.1-vs2.3.3.2/include/linux/shmem_fs.h
8737 --- linux-3.3.1/include/linux/shmem_fs.h        2012-03-19 19:47:29.000000000 +0100
8738 +++ linux-3.3.1-vs2.3.3.2/include/linux/shmem_fs.h      2012-02-24 03:55:06.000000000 +0100
8739 @@ -8,6 +8,9 @@
8740  
8741  /* inode in-kernel data */
8742  
8743 +#define TMPFS_SUPER_MAGIC      0x01021994
8744 +
8745 +
8746  struct shmem_inode_info {
8747         spinlock_t              lock;
8748         unsigned long           flags;
8749 diff -NurpP --minimal linux-3.3.1/include/linux/stat.h linux-3.3.1-vs2.3.3.2/include/linux/stat.h
8750 --- linux-3.3.1/include/linux/stat.h    2008-12-25 00:26:37.000000000 +0100
8751 +++ linux-3.3.1-vs2.3.3.2/include/linux/stat.h  2012-02-24 03:55:06.000000000 +0100
8752 @@ -66,6 +66,7 @@ struct kstat {
8753         unsigned int    nlink;
8754         uid_t           uid;
8755         gid_t           gid;
8756 +       tag_t           tag;
8757         dev_t           rdev;
8758         loff_t          size;
8759         struct timespec  atime;
8760 diff -NurpP --minimal linux-3.3.1/include/linux/sunrpc/auth.h linux-3.3.1-vs2.3.3.2/include/linux/sunrpc/auth.h
8761 --- linux-3.3.1/include/linux/sunrpc/auth.h     2012-03-19 19:47:29.000000000 +0100
8762 +++ linux-3.3.1-vs2.3.3.2/include/linux/sunrpc/auth.h   2012-02-24 03:55:06.000000000 +0100
8763 @@ -25,6 +25,7 @@
8764  struct auth_cred {
8765         uid_t   uid;
8766         gid_t   gid;
8767 +       tag_t   tag;
8768         struct group_info *group_info;
8769         const char *principal;
8770         unsigned char machine_cred : 1;
8771 diff -NurpP --minimal linux-3.3.1/include/linux/sunrpc/clnt.h linux-3.3.1-vs2.3.3.2/include/linux/sunrpc/clnt.h
8772 --- linux-3.3.1/include/linux/sunrpc/clnt.h     2012-03-19 19:47:29.000000000 +0100
8773 +++ linux-3.3.1-vs2.3.3.2/include/linux/sunrpc/clnt.h   2012-02-24 03:55:06.000000000 +0100
8774 @@ -50,7 +50,8 @@ struct rpc_clnt {
8775         unsigned int            cl_softrtry : 1,/* soft timeouts */
8776                                 cl_discrtry : 1,/* disconnect before retry */
8777                                 cl_autobind : 1,/* use getport() */
8778 -                               cl_chatty   : 1;/* be verbose */
8779 +                               cl_chatty   : 1,/* be verbose */
8780 +                               cl_tag      : 1;/* context tagging */
8781  
8782         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8783         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8784 diff -NurpP --minimal linux-3.3.1/include/linux/sysctl.h linux-3.3.1-vs2.3.3.2/include/linux/sysctl.h
8785 --- linux-3.3.1/include/linux/sysctl.h  2012-03-19 19:47:29.000000000 +0100
8786 +++ linux-3.3.1-vs2.3.3.2/include/linux/sysctl.h        2012-02-24 03:55:06.000000000 +0100
8787 @@ -60,6 +60,7 @@ enum
8788         CTL_ABI=9,              /* Binary emulation */
8789         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8790         CTL_ARLAN=254,          /* arlan wireless driver */
8791 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8792         CTL_S390DBF=5677,       /* s390 debug */
8793         CTL_SUNRPC=7249,        /* sunrpc debug */
8794         CTL_PM=9899,            /* frv power management */
8795 @@ -94,6 +95,7 @@ enum
8796  
8797         KERN_PANIC=15,          /* int: panic timeout */
8798         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8799 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8800  
8801         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8802         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8803 diff -NurpP --minimal linux-3.3.1/include/linux/sysfs.h linux-3.3.1-vs2.3.3.2/include/linux/sysfs.h
8804 --- linux-3.3.1/include/linux/sysfs.h   2012-03-19 19:47:29.000000000 +0100
8805 +++ linux-3.3.1-vs2.3.3.2/include/linux/sysfs.h 2012-02-24 03:55:06.000000000 +0100
8806 @@ -19,6 +19,8 @@
8807  #include <linux/kobject_ns.h>
8808  #include <linux/atomic.h>
8809  
8810 +#define SYSFS_SUPER_MAGIC      0x62656572
8811 +
8812  struct kobject;
8813  struct module;
8814  enum kobj_ns_type;
8815 diff -NurpP --minimal linux-3.3.1/include/linux/time.h linux-3.3.1-vs2.3.3.2/include/linux/time.h
8816 --- linux-3.3.1/include/linux/time.h    2011-07-22 11:18:11.000000000 +0200
8817 +++ linux-3.3.1-vs2.3.3.2/include/linux/time.h  2012-02-24 03:55:06.000000000 +0100
8818 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
8819         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
8820         a->tv_nsec = ns;
8821  }
8822 +
8823 +#include <linux/vs_time.h>
8824 +
8825  #endif /* __KERNEL__ */
8826  
8827  #define NFDBITS                        __NFDBITS
8828 diff -NurpP --minimal linux-3.3.1/include/linux/types.h linux-3.3.1-vs2.3.3.2/include/linux/types.h
8829 --- linux-3.3.1/include/linux/types.h   2012-03-19 19:47:29.000000000 +0100
8830 +++ linux-3.3.1-vs2.3.3.2/include/linux/types.h 2012-02-24 03:55:06.000000000 +0100
8831 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8832  typedef __kernel_gid32_t       gid_t;
8833  typedef __kernel_uid16_t        uid16_t;
8834  typedef __kernel_gid16_t        gid16_t;
8835 +typedef unsigned int           xid_t;
8836 +typedef unsigned int           nid_t;
8837 +typedef unsigned int           tag_t;
8838  
8839  typedef unsigned long          uintptr_t;
8840  
8841 diff -NurpP --minimal linux-3.3.1/include/linux/utsname.h linux-3.3.1-vs2.3.3.2/include/linux/utsname.h
8842 --- linux-3.3.1/include/linux/utsname.h 2012-01-09 16:14:59.000000000 +0100
8843 +++ linux-3.3.1-vs2.3.3.2/include/linux/utsname.h       2012-02-24 03:55:06.000000000 +0100
8844 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8845  }
8846  
8847  extern struct uts_namespace *copy_utsname(unsigned long flags,
8848 -                                         struct task_struct *tsk);
8849 +                                         struct uts_namespace *old_ns,
8850 +                                         struct user_namespace *user_ns);
8851  extern void free_uts_ns(struct kref *kref);
8852  
8853  static inline void put_uts_ns(struct uts_namespace *ns)
8854 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8855  }
8856  
8857  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8858 -                                                struct task_struct *tsk)
8859 +                                                struct uts_namespace *old_ns,
8860 +                                                struct user_namespace *user_ns)
8861  {
8862         if (flags & CLONE_NEWUTS)
8863                 return ERR_PTR(-EINVAL);
8864  
8865 -       return tsk->nsproxy->uts_ns;
8866 +       return old_ns;
8867  }
8868  #endif
8869  
8870 diff -NurpP --minimal linux-3.3.1/include/linux/vroot.h linux-3.3.1-vs2.3.3.2/include/linux/vroot.h
8871 --- linux-3.3.1/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
8872 +++ linux-3.3.1-vs2.3.3.2/include/linux/vroot.h 2012-02-24 03:55:06.000000000 +0100
8873 @@ -0,0 +1,51 @@
8874 +
8875 +/*
8876 + * include/linux/vroot.h
8877 + *
8878 + * written by Herbert Pötzl, 9/11/2002
8879 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8880 + *
8881 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8882 + * Redistribution of this file is permitted under the
8883 + * GNU General Public License.
8884 + */
8885 +
8886 +#ifndef _LINUX_VROOT_H
8887 +#define _LINUX_VROOT_H
8888 +
8889 +
8890 +#ifdef __KERNEL__
8891 +
8892 +/* Possible states of device */
8893 +enum {
8894 +       Vr_unbound,
8895 +       Vr_bound,
8896 +};
8897 +
8898 +struct vroot_device {
8899 +       int             vr_number;
8900 +       int             vr_refcnt;
8901 +
8902 +       struct semaphore        vr_ctl_mutex;
8903 +       struct block_device    *vr_device;
8904 +       int                     vr_state;
8905 +};
8906 +
8907 +
8908 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8909 +
8910 +extern int register_vroot_grb(vroot_grb_func *);
8911 +extern int unregister_vroot_grb(vroot_grb_func *);
8912 +
8913 +#endif /* __KERNEL__ */
8914 +
8915 +#define MAX_VROOT_DEFAULT      8
8916 +
8917 +/*
8918 + * IOCTL commands --- we will commandeer 0x56 ('V')
8919 + */
8920 +
8921 +#define VROOT_SET_DEV          0x5600
8922 +#define VROOT_CLR_DEV          0x5601
8923 +
8924 +#endif /* _LINUX_VROOT_H */
8925 diff -NurpP --minimal linux-3.3.1/include/linux/vs_base.h linux-3.3.1-vs2.3.3.2/include/linux/vs_base.h
8926 --- linux-3.3.1/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8927 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_base.h       2012-02-24 03:55:06.000000000 +0100
8928 @@ -0,0 +1,10 @@
8929 +#ifndef _VS_BASE_H
8930 +#define _VS_BASE_H
8931 +
8932 +#include "vserver/base.h"
8933 +#include "vserver/check.h"
8934 +#include "vserver/debug.h"
8935 +
8936 +#else
8937 +#warning duplicate inclusion
8938 +#endif
8939 diff -NurpP --minimal linux-3.3.1/include/linux/vs_context.h linux-3.3.1-vs2.3.3.2/include/linux/vs_context.h
8940 --- linux-3.3.1/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
8941 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_context.h    2012-02-24 03:55:06.000000000 +0100
8942 @@ -0,0 +1,242 @@
8943 +#ifndef _VS_CONTEXT_H
8944 +#define _VS_CONTEXT_H
8945 +
8946 +#include "vserver/base.h"
8947 +#include "vserver/check.h"
8948 +#include "vserver/context.h"
8949 +#include "vserver/history.h"
8950 +#include "vserver/debug.h"
8951 +
8952 +#include <linux/sched.h>
8953 +
8954 +
8955 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8956 +
8957 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8958 +       const char *_file, int _line, void *_here)
8959 +{
8960 +       if (!vxi)
8961 +               return NULL;
8962 +
8963 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8964 +               vxi, vxi ? vxi->vx_id : 0,
8965 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8966 +               _file, _line);
8967 +       __vxh_get_vx_info(vxi, _here);
8968 +
8969 +       atomic_inc(&vxi->vx_usecnt);
8970 +       return vxi;
8971 +}
8972 +
8973 +
8974 +extern void free_vx_info(struct vx_info *);
8975 +
8976 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8977 +
8978 +static inline void __put_vx_info(struct vx_info *vxi,
8979 +       const char *_file, int _line, void *_here)
8980 +{
8981 +       if (!vxi)
8982 +               return;
8983 +
8984 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8985 +               vxi, vxi ? vxi->vx_id : 0,
8986 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8987 +               _file, _line);
8988 +       __vxh_put_vx_info(vxi, _here);
8989 +
8990 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8991 +               free_vx_info(vxi);
8992 +}
8993 +
8994 +
8995 +#define init_vx_info(p, i) \
8996 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8997 +
8998 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8999 +       const char *_file, int _line, void *_here)
9000 +{
9001 +       if (vxi) {
9002 +               vxlprintk(VXD_CBIT(xid, 3),
9003 +                       "init_vx_info(%p[#%d.%d])",
9004 +                       vxi, vxi ? vxi->vx_id : 0,
9005 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9006 +                       _file, _line);
9007 +               __vxh_init_vx_info(vxi, vxp, _here);
9008 +
9009 +               atomic_inc(&vxi->vx_usecnt);
9010 +       }
9011 +       *vxp = vxi;
9012 +}
9013 +
9014 +
9015 +#define set_vx_info(p, i) \
9016 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9017 +
9018 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9019 +       const char *_file, int _line, void *_here)
9020 +{
9021 +       struct vx_info *vxo;
9022 +
9023 +       if (!vxi)
9024 +               return;
9025 +
9026 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9027 +               vxi, vxi ? vxi->vx_id : 0,
9028 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9029 +               _file, _line);
9030 +       __vxh_set_vx_info(vxi, vxp, _here);
9031 +
9032 +       atomic_inc(&vxi->vx_usecnt);
9033 +       vxo = xchg(vxp, vxi);
9034 +       BUG_ON(vxo);
9035 +}
9036 +
9037 +
9038 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9039 +
9040 +static inline void __clr_vx_info(struct vx_info **vxp,
9041 +       const char *_file, int _line, void *_here)
9042 +{
9043 +       struct vx_info *vxo;
9044 +
9045 +       vxo = xchg(vxp, NULL);
9046 +       if (!vxo)
9047 +               return;
9048 +
9049 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9050 +               vxo, vxo ? vxo->vx_id : 0,
9051 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9052 +               _file, _line);
9053 +       __vxh_clr_vx_info(vxo, vxp, _here);
9054 +
9055 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9056 +               free_vx_info(vxo);
9057 +}
9058 +
9059 +
9060 +#define claim_vx_info(v, p) \
9061 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9062 +
9063 +static inline void __claim_vx_info(struct vx_info *vxi,
9064 +       struct task_struct *task,
9065 +       const char *_file, int _line, void *_here)
9066 +{
9067 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9068 +               vxi, vxi ? vxi->vx_id : 0,
9069 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9070 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9071 +               task, _file, _line);
9072 +       __vxh_claim_vx_info(vxi, task, _here);
9073 +
9074 +       atomic_inc(&vxi->vx_tasks);
9075 +}
9076 +
9077 +
9078 +extern void unhash_vx_info(struct vx_info *);
9079 +
9080 +#define release_vx_info(v, p) \
9081 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9082 +
9083 +static inline void __release_vx_info(struct vx_info *vxi,
9084 +       struct task_struct *task,
9085 +       const char *_file, int _line, void *_here)
9086 +{
9087 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9088 +               vxi, vxi ? vxi->vx_id : 0,
9089 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9090 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9091 +               task, _file, _line);
9092 +       __vxh_release_vx_info(vxi, task, _here);
9093 +
9094 +       might_sleep();
9095 +
9096 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9097 +               unhash_vx_info(vxi);
9098 +}
9099 +
9100 +
9101 +#define task_get_vx_info(p) \
9102 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9103 +
9104 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9105 +       const char *_file, int _line, void *_here)
9106 +{
9107 +       struct vx_info *vxi;
9108 +
9109 +       task_lock(p);
9110 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9111 +               p, _file, _line);
9112 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9113 +       task_unlock(p);
9114 +       return vxi;
9115 +}
9116 +
9117 +
9118 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9119 +{
9120 +       if (waitqueue_active(&vxi->vx_wait))
9121 +               wake_up_interruptible(&vxi->vx_wait);
9122 +}
9123 +
9124 +
9125 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9126 +
9127 +static inline void __enter_vx_info(struct vx_info *vxi,
9128 +       struct vx_info_save *vxis, const char *_file, int _line)
9129 +{
9130 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9131 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9132 +               current->xid, current->vx_info, _file, _line);
9133 +       vxis->vxi = xchg(&current->vx_info, vxi);
9134 +       vxis->xid = current->xid;
9135 +       current->xid = vxi ? vxi->vx_id : 0;
9136 +}
9137 +
9138 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9139 +
9140 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9141 +       const char *_file, int _line)
9142 +{
9143 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9144 +               vxis, vxis->xid, vxis->vxi, current,
9145 +               current->xid, current->vx_info, _file, _line);
9146 +       (void)xchg(&current->vx_info, vxis->vxi);
9147 +       current->xid = vxis->xid;
9148 +}
9149 +
9150 +
9151 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9152 +{
9153 +       vxis->vxi = xchg(&current->vx_info, NULL);
9154 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9155 +}
9156 +
9157 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9158 +{
9159 +       (void)xchg(&current->xid, vxis->xid);
9160 +       (void)xchg(&current->vx_info, vxis->vxi);
9161 +}
9162 +
9163 +#define task_is_init(p) \
9164 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9165 +
9166 +static inline int __task_is_init(struct task_struct *p,
9167 +       const char *_file, int _line, void *_here)
9168 +{
9169 +       int is_init = is_global_init(p);
9170 +
9171 +       task_lock(p);
9172 +       if (p->vx_info)
9173 +               is_init = p->vx_info->vx_initpid == p->pid;
9174 +       task_unlock(p);
9175 +       return is_init;
9176 +}
9177 +
9178 +extern void exit_vx_info(struct task_struct *, int);
9179 +extern void exit_vx_info_early(struct task_struct *, int);
9180 +
9181 +
9182 +#else
9183 +#warning duplicate inclusion
9184 +#endif
9185 diff -NurpP --minimal linux-3.3.1/include/linux/vs_cowbl.h linux-3.3.1-vs2.3.3.2/include/linux/vs_cowbl.h
9186 --- linux-3.3.1/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9187 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_cowbl.h      2012-02-24 03:55:06.000000000 +0100
9188 @@ -0,0 +1,48 @@
9189 +#ifndef _VS_COWBL_H
9190 +#define _VS_COWBL_H
9191 +
9192 +#include <linux/fs.h>
9193 +#include <linux/dcache.h>
9194 +#include <linux/namei.h>
9195 +#include <linux/slab.h>
9196 +
9197 +extern struct dentry *cow_break_link(const char *pathname);
9198 +
9199 +static inline int cow_check_and_break(struct path *path)
9200 +{
9201 +       struct inode *inode = path->dentry->d_inode;
9202 +       int error = 0;
9203 +
9204 +       /* do we need this check? */
9205 +       if (IS_RDONLY(inode))
9206 +               return -EROFS;
9207 +
9208 +       if (IS_COW(inode)) {
9209 +               if (IS_COW_LINK(inode)) {
9210 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9211 +                       char *pp, *buf;
9212 +
9213 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9214 +                       if (!buf) {
9215 +                               return -ENOMEM;
9216 +                       }
9217 +                       pp = d_path(path, buf, PATH_MAX);
9218 +                       new_dentry = cow_break_link(pp);
9219 +                       kfree(buf);
9220 +                       if (!IS_ERR(new_dentry)) {
9221 +                               path->dentry = new_dentry;
9222 +                               dput(old_dentry);
9223 +                       } else
9224 +                               error = PTR_ERR(new_dentry);
9225 +               } else {
9226 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9227 +                       inode->i_ctime = CURRENT_TIME;
9228 +                       mark_inode_dirty(inode);
9229 +               }
9230 +       }
9231 +       return error;
9232 +}
9233 +
9234 +#else
9235 +#warning duplicate inclusion
9236 +#endif
9237 diff -NurpP --minimal linux-3.3.1/include/linux/vs_cvirt.h linux-3.3.1-vs2.3.3.2/include/linux/vs_cvirt.h
9238 --- linux-3.3.1/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9239 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_cvirt.h      2012-02-24 03:55:06.000000000 +0100
9240 @@ -0,0 +1,50 @@
9241 +#ifndef _VS_CVIRT_H
9242 +#define _VS_CVIRT_H
9243 +
9244 +#include "vserver/cvirt.h"
9245 +#include "vserver/context.h"
9246 +#include "vserver/base.h"
9247 +#include "vserver/check.h"
9248 +#include "vserver/debug.h"
9249 +
9250 +
9251 +static inline void vx_activate_task(struct task_struct *p)
9252 +{
9253 +       struct vx_info *vxi;
9254 +
9255 +       if ((vxi = p->vx_info)) {
9256 +               vx_update_load(vxi);
9257 +               atomic_inc(&vxi->cvirt.nr_running);
9258 +       }
9259 +}
9260 +
9261 +static inline void vx_deactivate_task(struct task_struct *p)
9262 +{
9263 +       struct vx_info *vxi;
9264 +
9265 +       if ((vxi = p->vx_info)) {
9266 +               vx_update_load(vxi);
9267 +               atomic_dec(&vxi->cvirt.nr_running);
9268 +       }
9269 +}
9270 +
9271 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9272 +{
9273 +       struct vx_info *vxi;
9274 +
9275 +       if ((vxi = p->vx_info))
9276 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9277 +}
9278 +
9279 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9280 +{
9281 +       struct vx_info *vxi;
9282 +
9283 +       if ((vxi = p->vx_info))
9284 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9285 +}
9286 +
9287 +
9288 +#else
9289 +#warning duplicate inclusion
9290 +#endif
9291 diff -NurpP --minimal linux-3.3.1/include/linux/vs_device.h linux-3.3.1-vs2.3.3.2/include/linux/vs_device.h
9292 --- linux-3.3.1/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9293 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_device.h     2012-02-24 03:55:06.000000000 +0100
9294 @@ -0,0 +1,45 @@
9295 +#ifndef _VS_DEVICE_H
9296 +#define _VS_DEVICE_H
9297 +
9298 +#include "vserver/base.h"
9299 +#include "vserver/device.h"
9300 +#include "vserver/debug.h"
9301 +
9302 +
9303 +#ifdef CONFIG_VSERVER_DEVICE
9304 +
9305 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9306 +
9307 +#define vs_device_perm(v, d, m, p) \
9308 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9309 +
9310 +#else
9311 +
9312 +static inline
9313 +int vs_map_device(struct vx_info *vxi,
9314 +       dev_t device, dev_t *target, umode_t mode)
9315 +{
9316 +       if (target)
9317 +               *target = device;
9318 +       return ~0;
9319 +}
9320 +
9321 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9322 +
9323 +#endif
9324 +
9325 +
9326 +#define vs_map_chrdev(d, t, p) \
9327 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9328 +#define vs_map_blkdev(d, t, p) \
9329 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9330 +
9331 +#define vs_chrdev_perm(d, p) \
9332 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9333 +#define vs_blkdev_perm(d, p) \
9334 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9335 +
9336 +
9337 +#else
9338 +#warning duplicate inclusion
9339 +#endif
9340 diff -NurpP --minimal linux-3.3.1/include/linux/vs_dlimit.h linux-3.3.1-vs2.3.3.2/include/linux/vs_dlimit.h
9341 --- linux-3.3.1/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9342 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_dlimit.h     2012-02-24 03:55:06.000000000 +0100
9343 @@ -0,0 +1,215 @@
9344 +#ifndef _VS_DLIMIT_H
9345 +#define _VS_DLIMIT_H
9346 +
9347 +#include <linux/fs.h>
9348 +
9349 +#include "vserver/dlimit.h"
9350 +#include "vserver/base.h"
9351 +#include "vserver/debug.h"
9352 +
9353 +
9354 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9355 +
9356 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9357 +       const char *_file, int _line)
9358 +{
9359 +       if (!dli)
9360 +               return NULL;
9361 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9362 +               dli, dli ? dli->dl_tag : 0,
9363 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9364 +               _file, _line);
9365 +       atomic_inc(&dli->dl_usecnt);
9366 +       return dli;
9367 +}
9368 +
9369 +
9370 +#define free_dl_info(i) \
9371 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9372 +
9373 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9374 +
9375 +static inline void __put_dl_info(struct dl_info *dli,
9376 +       const char *_file, int _line)
9377 +{
9378 +       if (!dli)
9379 +               return;
9380 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9381 +               dli, dli ? dli->dl_tag : 0,
9382 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9383 +               _file, _line);
9384 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9385 +               free_dl_info(dli);
9386 +}
9387 +
9388 +
9389 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9390 +
9391 +static inline int __dl_alloc_space(struct super_block *sb,
9392 +       tag_t tag, dlsize_t nr, const char *file, int line)
9393 +{
9394 +       struct dl_info *dli = NULL;
9395 +       int ret = 0;
9396 +
9397 +       if (nr == 0)
9398 +               goto out;
9399 +       dli = locate_dl_info(sb, tag);
9400 +       if (!dli)
9401 +               goto out;
9402 +
9403 +       spin_lock(&dli->dl_lock);
9404 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9405 +       if (!ret)
9406 +               dli->dl_space_used += nr;
9407 +       spin_unlock(&dli->dl_lock);
9408 +       put_dl_info(dli);
9409 +out:
9410 +       vxlprintk(VXD_CBIT(dlim, 1),
9411 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9412 +               sb, tag, __dlimit_char(dli), (long long)nr,
9413 +               ret, file, line);
9414 +       return ret ? -ENOSPC : 0;
9415 +}
9416 +
9417 +static inline void __dl_free_space(struct super_block *sb,
9418 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9419 +{
9420 +       struct dl_info *dli = NULL;
9421 +
9422 +       if (nr == 0)
9423 +               goto out;
9424 +       dli = locate_dl_info(sb, tag);
9425 +       if (!dli)
9426 +               goto out;
9427 +
9428 +       spin_lock(&dli->dl_lock);
9429 +       if (dli->dl_space_used > nr)
9430 +               dli->dl_space_used -= nr;
9431 +       else
9432 +               dli->dl_space_used = 0;
9433 +       spin_unlock(&dli->dl_lock);
9434 +       put_dl_info(dli);
9435 +out:
9436 +       vxlprintk(VXD_CBIT(dlim, 1),
9437 +               "FREE  (%p,#%d)%c %lld bytes",
9438 +               sb, tag, __dlimit_char(dli), (long long)nr,
9439 +               _file, _line);
9440 +}
9441 +
9442 +static inline int __dl_alloc_inode(struct super_block *sb,
9443 +       tag_t tag, const char *_file, int _line)
9444 +{
9445 +       struct dl_info *dli;
9446 +       int ret = 0;
9447 +
9448 +       dli = locate_dl_info(sb, tag);
9449 +       if (!dli)
9450 +               goto out;
9451 +
9452 +       spin_lock(&dli->dl_lock);
9453 +       dli->dl_inodes_used++;
9454 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9455 +       spin_unlock(&dli->dl_lock);
9456 +       put_dl_info(dli);
9457 +out:
9458 +       vxlprintk(VXD_CBIT(dlim, 0),
9459 +               "ALLOC (%p,#%d)%c inode (%d)",
9460 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9461 +       return ret ? -ENOSPC : 0;
9462 +}
9463 +
9464 +static inline void __dl_free_inode(struct super_block *sb,
9465 +       tag_t tag, const char *_file, int _line)
9466 +{
9467 +       struct dl_info *dli;
9468 +
9469 +       dli = locate_dl_info(sb, tag);
9470 +       if (!dli)
9471 +               goto out;
9472 +
9473 +       spin_lock(&dli->dl_lock);
9474 +       if (dli->dl_inodes_used > 1)
9475 +               dli->dl_inodes_used--;
9476 +       else
9477 +               dli->dl_inodes_used = 0;
9478 +       spin_unlock(&dli->dl_lock);
9479 +       put_dl_info(dli);
9480 +out:
9481 +       vxlprintk(VXD_CBIT(dlim, 0),
9482 +               "FREE  (%p,#%d)%c inode",
9483 +               sb, tag, __dlimit_char(dli), _file, _line);
9484 +}
9485 +
9486 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9487 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9488 +       const char *_file, int _line)
9489 +{
9490 +       struct dl_info *dli;
9491 +       uint64_t broot, bfree;
9492 +
9493 +       dli = locate_dl_info(sb, tag);
9494 +       if (!dli)
9495 +               return;
9496 +
9497 +       spin_lock(&dli->dl_lock);
9498 +       broot = (dli->dl_space_total -
9499 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9500 +               >> sb->s_blocksize_bits;
9501 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9502 +                       >> sb->s_blocksize_bits;
9503 +       spin_unlock(&dli->dl_lock);
9504 +
9505 +       vxlprintk(VXD_CBIT(dlim, 2),
9506 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9507 +               (long long)bfree, (long long)broot,
9508 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9509 +               _file, _line);
9510 +       if (free_blocks) {
9511 +               if (*free_blocks > bfree)
9512 +                       *free_blocks = bfree;
9513 +       }
9514 +       if (root_blocks) {
9515 +               if (*root_blocks > broot)
9516 +                       *root_blocks = broot;
9517 +       }
9518 +       put_dl_info(dli);
9519 +}
9520 +
9521 +#define dl_prealloc_space(in, bytes) \
9522 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9523 +               __FILE__, __LINE__ )
9524 +
9525 +#define dl_alloc_space(in, bytes) \
9526 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9527 +               __FILE__, __LINE__ )
9528 +
9529 +#define dl_reserve_space(in, bytes) \
9530 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9531 +               __FILE__, __LINE__ )
9532 +
9533 +#define dl_claim_space(in, bytes) (0)
9534 +
9535 +#define dl_release_space(in, bytes) \
9536 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9537 +               __FILE__, __LINE__ )
9538 +
9539 +#define dl_free_space(in, bytes) \
9540 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9541 +               __FILE__, __LINE__ )
9542 +
9543 +
9544 +
9545 +#define dl_alloc_inode(in) \
9546 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9547 +
9548 +#define dl_free_inode(in) \
9549 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9550 +
9551 +
9552 +#define dl_adjust_block(sb, tag, fb, rb) \
9553 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9554 +
9555 +
9556 +#else
9557 +#warning duplicate inclusion
9558 +#endif
9559 diff -NurpP --minimal linux-3.3.1/include/linux/vs_inet.h linux-3.3.1-vs2.3.3.2/include/linux/vs_inet.h
9560 --- linux-3.3.1/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9561 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_inet.h       2012-02-24 03:55:06.000000000 +0100
9562 @@ -0,0 +1,353 @@
9563 +#ifndef _VS_INET_H
9564 +#define _VS_INET_H
9565 +
9566 +#include "vserver/base.h"
9567 +#include "vserver/network.h"
9568 +#include "vserver/debug.h"
9569 +
9570 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9571 +
9572 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9573 +                       NIPQUAD((a)->mask), (a)->type
9574 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9575 +
9576 +#define NIPQUAD(addr) \
9577 +       ((unsigned char *)&addr)[0], \
9578 +       ((unsigned char *)&addr)[1], \
9579 +       ((unsigned char *)&addr)[2], \
9580 +       ((unsigned char *)&addr)[3]
9581 +
9582 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9583 +
9584 +
9585 +static inline
9586 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9587 +{
9588 +       __be32 ip = nxa->ip[0].s_addr;
9589 +       __be32 mask = nxa->mask.s_addr;
9590 +       __be32 bcast = ip | ~mask;
9591 +       int ret = 0;
9592 +
9593 +       switch (nxa->type & tmask) {
9594 +       case NXA_TYPE_MASK:
9595 +               ret = (ip == (addr & mask));
9596 +               break;
9597 +       case NXA_TYPE_ADDR:
9598 +               ret = 3;
9599 +               if (addr == ip)
9600 +                       break;
9601 +               /* fall through to broadcast */
9602 +       case NXA_MOD_BCAST:
9603 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9604 +               break;
9605 +       case NXA_TYPE_RANGE:
9606 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9607 +                       (nxa->ip[1].s_addr > addr));
9608 +               break;
9609 +       case NXA_TYPE_ANY:
9610 +               ret = 2;
9611 +               break;
9612 +       }
9613 +
9614 +       vxdprintk(VXD_CBIT(net, 0),
9615 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9616 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9617 +       return ret;
9618 +}
9619 +
9620 +static inline
9621 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9622 +{
9623 +       struct nx_addr_v4 *nxa;
9624 +       int ret = 1;
9625 +
9626 +       if (!nxi)
9627 +               goto out;
9628 +
9629 +       ret = 2;
9630 +       /* allow 127.0.0.1 when remapping lback */
9631 +       if ((tmask & NXA_LOOPBACK) &&
9632 +               (addr == IPI_LOOPBACK) &&
9633 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9634 +               goto out;
9635 +       ret = 3;
9636 +       /* check for lback address */
9637 +       if ((tmask & NXA_MOD_LBACK) &&
9638 +               (nxi->v4_lback.s_addr == addr))
9639 +               goto out;
9640 +       ret = 4;
9641 +       /* check for broadcast address */
9642 +       if ((tmask & NXA_MOD_BCAST) &&
9643 +               (nxi->v4_bcast.s_addr == addr))
9644 +               goto out;
9645 +       ret = 5;
9646 +       /* check for v4 addresses */
9647 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9648 +               if (v4_addr_match(nxa, addr, tmask))
9649 +                       goto out;
9650 +       ret = 0;
9651 +out:
9652 +       vxdprintk(VXD_CBIT(net, 0),
9653 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9654 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9655 +       return ret;
9656 +}
9657 +
9658 +static inline
9659 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9660 +{
9661 +       /* FIXME: needs full range checks */
9662 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9663 +}
9664 +
9665 +static inline
9666 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9667 +{
9668 +       struct nx_addr_v4 *ptr;
9669 +
9670 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9671 +               if (v4_nx_addr_match(ptr, nxa, mask))
9672 +                       return 1;
9673 +       return 0;
9674 +}
9675 +
9676 +#include <net/inet_sock.h>
9677 +
9678 +/*
9679 + *     Check if a given address matches for a socket
9680 + *
9681 + *     nxi:            the socket's nx_info if any
9682 + *     addr:           to be verified address
9683 + */
9684 +static inline
9685 +int v4_sock_addr_match (
9686 +       struct nx_info *nxi,
9687 +       struct inet_sock *inet,
9688 +       __be32 addr)
9689 +{
9690 +       __be32 saddr = inet->inet_rcv_saddr;
9691 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9692 +
9693 +       if (addr && (saddr == addr || bcast == addr))
9694 +               return 1;
9695 +       if (!saddr)
9696 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9697 +       return 0;
9698 +}
9699 +
9700 +
9701 +/* inet related checks and helpers */
9702 +
9703 +
9704 +struct in_ifaddr;
9705 +struct net_device;
9706 +struct sock;
9707 +
9708 +#ifdef CONFIG_INET
9709 +
9710 +#include <linux/netdevice.h>
9711 +#include <linux/inetdevice.h>
9712 +#include <net/inet_sock.h>
9713 +#include <net/inet_timewait_sock.h>
9714 +
9715 +
9716 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9717 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9718 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9719 +
9720 +
9721 +/*
9722 + *     check if address is covered by socket
9723 + *
9724 + *     sk:     the socket to check against
9725 + *     addr:   the address in question (must be != 0)
9726 + */
9727 +
9728 +static inline
9729 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9730 +{
9731 +       struct nx_info *nxi = sk->sk_nx_info;
9732 +       __be32 saddr = sk_rcv_saddr(sk);
9733 +
9734 +       vxdprintk(VXD_CBIT(net, 5),
9735 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9736 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9737 +               (sk->sk_socket?sk->sk_socket->flags:0));
9738 +
9739 +       if (saddr) {            /* direct address match */
9740 +               return v4_addr_match(nxa, saddr, -1);
9741 +       } else if (nxi) {       /* match against nx_info */
9742 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9743 +       } else {                /* unrestricted any socket */
9744 +               return 1;
9745 +       }
9746 +}
9747 +
9748 +
9749 +
9750 +static inline
9751 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9752 +{
9753 +       vxdprintk(VXD_CBIT(net, 1),
9754 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9755 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9756 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9757 +
9758 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9759 +               return 1;
9760 +       if (dev_in_nx_info(dev, nxi))
9761 +               return 1;
9762 +       return 0;
9763 +}
9764 +
9765 +
9766 +static inline
9767 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9768 +{
9769 +       if (!nxi)
9770 +               return 1;
9771 +       if (!ifa)
9772 +               return 0;
9773 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9774 +}
9775 +
9776 +static inline
9777 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9778 +{
9779 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9780 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9781 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9782 +
9783 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9784 +               return 1;
9785 +       if (v4_ifa_in_nx_info(ifa, nxi))
9786 +               return 1;
9787 +       return 0;
9788 +}
9789 +
9790 +
9791 +struct nx_v4_sock_addr {
9792 +       __be32 saddr;   /* Address used for validation */
9793 +       __be32 baddr;   /* Address used for socket bind */
9794 +};
9795 +
9796 +static inline
9797 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9798 +       struct nx_v4_sock_addr *nsa)
9799 +{
9800 +       struct sock *sk = &inet->sk;
9801 +       struct nx_info *nxi = sk->sk_nx_info;
9802 +       __be32 saddr = addr->sin_addr.s_addr;
9803 +       __be32 baddr = saddr;
9804 +
9805 +       vxdprintk(VXD_CBIT(net, 3),
9806 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9807 +               sk, sk->sk_nx_info, sk->sk_socket,
9808 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9809 +               NIPQUAD(saddr));
9810 +
9811 +       if (nxi) {
9812 +               if (saddr == INADDR_ANY) {
9813 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9814 +                               baddr = nxi->v4.ip[0].s_addr;
9815 +               } else if (saddr == IPI_LOOPBACK) {
9816 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9817 +                               baddr = nxi->v4_lback.s_addr;
9818 +               } else if (!ipv4_is_multicast(saddr) ||
9819 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9820 +                       /* normal address bind */
9821 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9822 +                               return -EADDRNOTAVAIL;
9823 +               }
9824 +       }
9825 +
9826 +       vxdprintk(VXD_CBIT(net, 3),
9827 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9828 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9829 +
9830 +       nsa->saddr = saddr;
9831 +       nsa->baddr = baddr;
9832 +       return 0;
9833 +}
9834 +
9835 +static inline
9836 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9837 +{
9838 +       inet->inet_saddr = nsa->baddr;
9839 +       inet->inet_rcv_saddr = nsa->baddr;
9840 +}
9841 +
9842 +
9843 +/*
9844 + *      helper to simplify inet_lookup_listener
9845 + *
9846 + *      nxi:   the socket's nx_info if any
9847 + *      addr:  to be verified address
9848 + *      saddr: socket address
9849 + */
9850 +static inline int v4_inet_addr_match (
9851 +       struct nx_info *nxi,
9852 +       __be32 addr,
9853 +       __be32 saddr)
9854 +{
9855 +       if (addr && (saddr == addr))
9856 +               return 1;
9857 +       if (!saddr)
9858 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9859 +       return 0;
9860 +}
9861 +
9862 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9863 +{
9864 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9865 +               (addr == nxi->v4_lback.s_addr))
9866 +               return IPI_LOOPBACK;
9867 +       return addr;
9868 +}
9869 +
9870 +static inline
9871 +int nx_info_has_v4(struct nx_info *nxi)
9872 +{
9873 +       if (!nxi)
9874 +               return 1;
9875 +       if (NX_IPV4(nxi))
9876 +               return 1;
9877 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9878 +               return 1;
9879 +       return 0;
9880 +}
9881 +
9882 +#else /* CONFIG_INET */
9883 +
9884 +static inline
9885 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9886 +{
9887 +       return 1;
9888 +}
9889 +
9890 +static inline
9891 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9892 +{
9893 +       return 1;
9894 +}
9895 +
9896 +static inline
9897 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9898 +{
9899 +       return 1;
9900 +}
9901 +
9902 +static inline
9903 +int nx_info_has_v4(struct nx_info *nxi)
9904 +{
9905 +       return 0;
9906 +}
9907 +
9908 +#endif /* CONFIG_INET */
9909 +
9910 +#define current_nx_info_has_v4() \
9911 +       nx_info_has_v4(current_nx_info())
9912 +
9913 +#else
9914 +// #warning duplicate inclusion
9915 +#endif
9916 diff -NurpP --minimal linux-3.3.1/include/linux/vs_inet6.h linux-3.3.1-vs2.3.3.2/include/linux/vs_inet6.h
9917 --- linux-3.3.1/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
9918 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_inet6.h      2012-02-24 03:55:06.000000000 +0100
9919 @@ -0,0 +1,246 @@
9920 +#ifndef _VS_INET6_H
9921 +#define _VS_INET6_H
9922 +
9923 +#include "vserver/base.h"
9924 +#include "vserver/network.h"
9925 +#include "vserver/debug.h"
9926 +
9927 +#include <net/ipv6.h>
9928 +
9929 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9930 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9931 +
9932 +
9933 +#ifdef CONFIG_IPV6
9934 +
9935 +static inline
9936 +int v6_addr_match(struct nx_addr_v6 *nxa,
9937 +       const struct in6_addr *addr, uint16_t mask)
9938 +{
9939 +       int ret = 0;
9940 +
9941 +       switch (nxa->type & mask) {
9942 +       case NXA_TYPE_MASK:
9943 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9944 +               break;
9945 +       case NXA_TYPE_ADDR:
9946 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9947 +               break;
9948 +       case NXA_TYPE_ANY:
9949 +               ret = 1;
9950 +               break;
9951 +       }
9952 +       vxdprintk(VXD_CBIT(net, 0),
9953 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9954 +               nxa, NXAV6(nxa), addr, mask, ret);
9955 +       return ret;
9956 +}
9957 +
9958 +static inline
9959 +int v6_addr_in_nx_info(struct nx_info *nxi,
9960 +       const struct in6_addr *addr, uint16_t mask)
9961 +{
9962 +       struct nx_addr_v6 *nxa;
9963 +       int ret = 1;
9964 +
9965 +       if (!nxi)
9966 +               goto out;
9967 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9968 +               if (v6_addr_match(nxa, addr, mask))
9969 +                       goto out;
9970 +       ret = 0;
9971 +out:
9972 +       vxdprintk(VXD_CBIT(net, 0),
9973 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9974 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9975 +       return ret;
9976 +}
9977 +
9978 +static inline
9979 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9980 +{
9981 +       /* FIXME: needs full range checks */
9982 +       return v6_addr_match(nxa, &addr->ip, mask);
9983 +}
9984 +
9985 +static inline
9986 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9987 +{
9988 +       struct nx_addr_v6 *ptr;
9989 +
9990 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9991 +               if (v6_nx_addr_match(ptr, nxa, mask))
9992 +                       return 1;
9993 +       return 0;
9994 +}
9995 +
9996 +
9997 +/*
9998 + *     Check if a given address matches for a socket
9999 + *
10000 + *     nxi:            the socket's nx_info if any
10001 + *     addr:           to be verified address
10002 + */
10003 +static inline
10004 +int v6_sock_addr_match (
10005 +       struct nx_info *nxi,
10006 +       struct inet_sock *inet,
10007 +       struct in6_addr *addr)
10008 +{
10009 +       struct sock *sk = &inet->sk;
10010 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10011 +
10012 +       if (!ipv6_addr_any(addr) &&
10013 +               ipv6_addr_equal(saddr, addr))
10014 +               return 1;
10015 +       if (ipv6_addr_any(saddr))
10016 +               return v6_addr_in_nx_info(nxi, addr, -1);
10017 +       return 0;
10018 +}
10019 +
10020 +/*
10021 + *     check if address is covered by socket
10022 + *
10023 + *     sk:     the socket to check against
10024 + *     addr:   the address in question (must be != 0)
10025 + */
10026 +
10027 +static inline
10028 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10029 +{
10030 +       struct nx_info *nxi = sk->sk_nx_info;
10031 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10032 +
10033 +       vxdprintk(VXD_CBIT(net, 5),
10034 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10035 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10036 +               (sk->sk_socket?sk->sk_socket->flags:0));
10037 +
10038 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10039 +               return v6_addr_match(nxa, saddr, -1);
10040 +       } else if (nxi) {               /* match against nx_info */
10041 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10042 +       } else {                        /* unrestricted any socket */
10043 +               return 1;
10044 +       }
10045 +}
10046 +
10047 +
10048 +/* inet related checks and helpers */
10049 +
10050 +
10051 +struct in_ifaddr;
10052 +struct net_device;
10053 +struct sock;
10054 +
10055 +
10056 +#include <linux/netdevice.h>
10057 +#include <linux/inetdevice.h>
10058 +#include <net/inet_timewait_sock.h>
10059 +
10060 +
10061 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10062 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10063 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10064 +
10065 +
10066 +
10067 +static inline
10068 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10069 +{
10070 +       if (!nxi)
10071 +               return 1;
10072 +       if (!ifa)
10073 +               return 0;
10074 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10075 +}
10076 +
10077 +static inline
10078 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10079 +{
10080 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10081 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10082 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10083 +
10084 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10085 +               return 1;
10086 +       if (v6_ifa_in_nx_info(ifa, nxi))
10087 +               return 1;
10088 +       return 0;
10089 +}
10090 +
10091 +
10092 +struct nx_v6_sock_addr {
10093 +       struct in6_addr saddr;  /* Address used for validation */
10094 +       struct in6_addr baddr;  /* Address used for socket bind */
10095 +};
10096 +
10097 +static inline
10098 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10099 +       struct nx_v6_sock_addr *nsa)
10100 +{
10101 +       // struct sock *sk = &inet->sk;
10102 +       // struct nx_info *nxi = sk->sk_nx_info;
10103 +       struct in6_addr saddr = addr->sin6_addr;
10104 +       struct in6_addr baddr = saddr;
10105 +
10106 +       nsa->saddr = saddr;
10107 +       nsa->baddr = baddr;
10108 +       return 0;
10109 +}
10110 +
10111 +static inline
10112 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10113 +{
10114 +       // struct sock *sk = &inet->sk;
10115 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10116 +
10117 +       // *saddr = nsa->baddr;
10118 +       // inet->inet_saddr = nsa->baddr;
10119 +}
10120 +
10121 +static inline
10122 +int nx_info_has_v6(struct nx_info *nxi)
10123 +{
10124 +       if (!nxi)
10125 +               return 1;
10126 +       if (NX_IPV6(nxi))
10127 +               return 1;
10128 +       return 0;
10129 +}
10130 +
10131 +#else /* CONFIG_IPV6 */
10132 +
10133 +static inline
10134 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10135 +{
10136 +       return 1;
10137 +}
10138 +
10139 +
10140 +static inline
10141 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10142 +{
10143 +       return 1;
10144 +}
10145 +
10146 +static inline
10147 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10148 +{
10149 +       return 1;
10150 +}
10151 +
10152 +static inline
10153 +int nx_info_has_v6(struct nx_info *nxi)
10154 +{
10155 +       return 0;
10156 +}
10157 +
10158 +#endif /* CONFIG_IPV6 */
10159 +
10160 +#define current_nx_info_has_v6() \
10161 +       nx_info_has_v6(current_nx_info())
10162 +
10163 +#else
10164 +#warning duplicate inclusion
10165 +#endif
10166 diff -NurpP --minimal linux-3.3.1/include/linux/vs_limit.h linux-3.3.1-vs2.3.3.2/include/linux/vs_limit.h
10167 --- linux-3.3.1/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10168 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_limit.h      2012-02-24 03:55:06.000000000 +0100
10169 @@ -0,0 +1,140 @@
10170 +#ifndef _VS_LIMIT_H
10171 +#define _VS_LIMIT_H
10172 +
10173 +#include "vserver/limit.h"
10174 +#include "vserver/base.h"
10175 +#include "vserver/context.h"
10176 +#include "vserver/debug.h"
10177 +#include "vserver/context.h"
10178 +#include "vserver/limit_int.h"
10179 +
10180 +
10181 +#define vx_acc_cres(v, d, p, r) \
10182 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10183 +
10184 +#define vx_acc_cres_cond(x, d, p, r) \
10185 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10186 +       r, d, p, __FILE__, __LINE__)
10187 +
10188 +
10189 +#define vx_add_cres(v, a, p, r) \
10190 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10191 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10192 +
10193 +#define vx_add_cres_cond(x, a, p, r) \
10194 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10195 +       r, a, p, __FILE__, __LINE__)
10196 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10197 +
10198 +
10199 +/* process and file limits */
10200 +
10201 +#define vx_nproc_inc(p) \
10202 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10203 +
10204 +#define vx_nproc_dec(p) \
10205 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10206 +
10207 +#define vx_files_inc(f) \
10208 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10209 +
10210 +#define vx_files_dec(f) \
10211 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10212 +
10213 +#define vx_locks_inc(l) \
10214 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10215 +
10216 +#define vx_locks_dec(l) \
10217 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10218 +
10219 +#define vx_openfd_inc(f) \
10220 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10221 +
10222 +#define vx_openfd_dec(f) \
10223 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10224 +
10225 +
10226 +#define vx_cres_avail(v, n, r) \
10227 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10228 +
10229 +
10230 +#define vx_nproc_avail(n) \
10231 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10232 +
10233 +#define vx_files_avail(n) \
10234 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10235 +
10236 +#define vx_locks_avail(n) \
10237 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10238 +
10239 +#define vx_openfd_avail(n) \
10240 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10241 +
10242 +
10243 +/* dentry limits */
10244 +
10245 +#define vx_dentry_inc(d) do {                                          \
10246 +       if ((d)->d_count == 1)                                          \
10247 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10248 +       } while (0)
10249 +
10250 +#define vx_dentry_dec(d) do {                                          \
10251 +       if ((d)->d_count == 0)                                          \
10252 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10253 +       } while (0)
10254 +
10255 +#define vx_dentry_avail(n) \
10256 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10257 +
10258 +
10259 +/* socket limits */
10260 +
10261 +#define vx_sock_inc(s) \
10262 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10263 +
10264 +#define vx_sock_dec(s) \
10265 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10266 +
10267 +#define vx_sock_avail(n) \
10268 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10269 +
10270 +
10271 +/* ipc resource limits */
10272 +
10273 +#define vx_ipcmsg_add(v, u, a) \
10274 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10275 +
10276 +#define vx_ipcmsg_sub(v, u, a) \
10277 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10278 +
10279 +#define vx_ipcmsg_avail(v, a) \
10280 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10281 +
10282 +
10283 +#define vx_ipcshm_add(v, k, a) \
10284 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10285 +
10286 +#define vx_ipcshm_sub(v, k, a) \
10287 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10288 +
10289 +#define vx_ipcshm_avail(v, a) \
10290 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10291 +
10292 +
10293 +#define vx_semary_inc(a) \
10294 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10295 +
10296 +#define vx_semary_dec(a) \
10297 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10298 +
10299 +
10300 +#define vx_nsems_add(a,n) \
10301 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10302 +
10303 +#define vx_nsems_sub(a,n) \
10304 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10305 +
10306 +
10307 +#else
10308 +#warning duplicate inclusion
10309 +#endif
10310 diff -NurpP --minimal linux-3.3.1/include/linux/vs_network.h linux-3.3.1-vs2.3.3.2/include/linux/vs_network.h
10311 --- linux-3.3.1/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10312 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_network.h    2012-02-24 03:55:06.000000000 +0100
10313 @@ -0,0 +1,169 @@
10314 +#ifndef _NX_VS_NETWORK_H
10315 +#define _NX_VS_NETWORK_H
10316 +
10317 +#include "vserver/context.h"
10318 +#include "vserver/network.h"
10319 +#include "vserver/base.h"
10320 +#include "vserver/check.h"
10321 +#include "vserver/debug.h"
10322 +
10323 +#include <linux/sched.h>
10324 +
10325 +
10326 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10327 +
10328 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10329 +       const char *_file, int _line)
10330 +{
10331 +       if (!nxi)
10332 +               return NULL;
10333 +
10334 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10335 +               nxi, nxi ? nxi->nx_id : 0,
10336 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10337 +               _file, _line);
10338 +
10339 +       atomic_inc(&nxi->nx_usecnt);
10340 +       return nxi;
10341 +}
10342 +
10343 +
10344 +extern void free_nx_info(struct nx_info *);
10345 +
10346 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10347 +
10348 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10349 +{
10350 +       if (!nxi)
10351 +               return;
10352 +
10353 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10354 +               nxi, nxi ? nxi->nx_id : 0,
10355 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10356 +               _file, _line);
10357 +
10358 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10359 +               free_nx_info(nxi);
10360 +}
10361 +
10362 +
10363 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10364 +
10365 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10366 +               const char *_file, int _line)
10367 +{
10368 +       if (nxi) {
10369 +               vxlprintk(VXD_CBIT(nid, 3),
10370 +                       "init_nx_info(%p[#%d.%d])",
10371 +                       nxi, nxi ? nxi->nx_id : 0,
10372 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10373 +                       _file, _line);
10374 +
10375 +               atomic_inc(&nxi->nx_usecnt);
10376 +       }
10377 +       *nxp = nxi;
10378 +}
10379 +
10380 +
10381 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10382 +
10383 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10384 +       const char *_file, int _line)
10385 +{
10386 +       struct nx_info *nxo;
10387 +
10388 +       if (!nxi)
10389 +               return;
10390 +
10391 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10392 +               nxi, nxi ? nxi->nx_id : 0,
10393 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10394 +               _file, _line);
10395 +
10396 +       atomic_inc(&nxi->nx_usecnt);
10397 +       nxo = xchg(nxp, nxi);
10398 +       BUG_ON(nxo);
10399 +}
10400 +
10401 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10402 +
10403 +static inline void __clr_nx_info(struct nx_info **nxp,
10404 +       const char *_file, int _line)
10405 +{
10406 +       struct nx_info *nxo;
10407 +
10408 +       nxo = xchg(nxp, NULL);
10409 +       if (!nxo)
10410 +               return;
10411 +
10412 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10413 +               nxo, nxo ? nxo->nx_id : 0,
10414 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10415 +               _file, _line);
10416 +
10417 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10418 +               free_nx_info(nxo);
10419 +}
10420 +
10421 +
10422 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10423 +
10424 +static inline void __claim_nx_info(struct nx_info *nxi,
10425 +       struct task_struct *task, const char *_file, int _line)
10426 +{
10427 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10428 +               nxi, nxi ? nxi->nx_id : 0,
10429 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10430 +               nxi?atomic_read(&nxi->nx_tasks):0,
10431 +               task, _file, _line);
10432 +
10433 +       atomic_inc(&nxi->nx_tasks);
10434 +}
10435 +
10436 +
10437 +extern void unhash_nx_info(struct nx_info *);
10438 +
10439 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10440 +
10441 +static inline void __release_nx_info(struct nx_info *nxi,
10442 +       struct task_struct *task, const char *_file, int _line)
10443 +{
10444 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10445 +               nxi, nxi ? nxi->nx_id : 0,
10446 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10447 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10448 +               task, _file, _line);
10449 +
10450 +       might_sleep();
10451 +
10452 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10453 +               unhash_nx_info(nxi);
10454 +}
10455 +
10456 +
10457 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10458 +
10459 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10460 +       const char *_file, int _line)
10461 +{
10462 +       struct nx_info *nxi;
10463 +
10464 +       task_lock(p);
10465 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10466 +               p, _file, _line);
10467 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10468 +       task_unlock(p);
10469 +       return nxi;
10470 +}
10471 +
10472 +
10473 +static inline void exit_nx_info(struct task_struct *p)
10474 +{
10475 +       if (p->nx_info)
10476 +               release_nx_info(p->nx_info, p);
10477 +}
10478 +
10479 +
10480 +#else
10481 +#warning duplicate inclusion
10482 +#endif
10483 diff -NurpP --minimal linux-3.3.1/include/linux/vs_pid.h linux-3.3.1-vs2.3.3.2/include/linux/vs_pid.h
10484 --- linux-3.3.1/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10485 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_pid.h        2012-02-24 03:55:06.000000000 +0100
10486 @@ -0,0 +1,50 @@
10487 +#ifndef _VS_PID_H
10488 +#define _VS_PID_H
10489 +
10490 +#include "vserver/base.h"
10491 +#include "vserver/check.h"
10492 +#include "vserver/context.h"
10493 +#include "vserver/debug.h"
10494 +#include "vserver/pid.h"
10495 +#include <linux/pid_namespace.h>
10496 +
10497 +
10498 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10499 +
10500 +static inline
10501 +int vx_proc_task_visible(struct task_struct *task)
10502 +{
10503 +       if ((task->pid == 1) &&
10504 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10505 +               /* show a blend through init */
10506 +               goto visible;
10507 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10508 +               goto visible;
10509 +       return 0;
10510 +visible:
10511 +       return 1;
10512 +}
10513 +
10514 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10515 +
10516 +
10517 +static inline
10518 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10519 +{
10520 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10521 +
10522 +       if (task && !vx_proc_task_visible(task)) {
10523 +               vxdprintk(VXD_CBIT(misc, 6),
10524 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10525 +                       task, task->xid, task->pid,
10526 +                       current, current->xid, current->pid);
10527 +               put_task_struct(task);
10528 +               task = NULL;
10529 +       }
10530 +       return task;
10531 +}
10532 +
10533 +
10534 +#else
10535 +#warning duplicate inclusion
10536 +#endif
10537 diff -NurpP --minimal linux-3.3.1/include/linux/vs_sched.h linux-3.3.1-vs2.3.3.2/include/linux/vs_sched.h
10538 --- linux-3.3.1/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10539 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_sched.h      2012-02-24 03:55:06.000000000 +0100
10540 @@ -0,0 +1,40 @@
10541 +#ifndef _VS_SCHED_H
10542 +#define _VS_SCHED_H
10543 +
10544 +#include "vserver/base.h"
10545 +#include "vserver/context.h"
10546 +#include "vserver/sched.h"
10547 +
10548 +
10549 +#define MAX_PRIO_BIAS           20
10550 +#define MIN_PRIO_BIAS          -20
10551 +
10552 +static inline
10553 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10554 +{
10555 +       struct vx_info *vxi = p->vx_info;
10556 +
10557 +       if (vxi)
10558 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10559 +       return prio;
10560 +}
10561 +
10562 +static inline void vx_account_user(struct vx_info *vxi,
10563 +       cputime_t cputime, int nice)
10564 +{
10565 +       if (!vxi)
10566 +               return;
10567 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10568 +}
10569 +
10570 +static inline void vx_account_system(struct vx_info *vxi,
10571 +       cputime_t cputime, int idle)
10572 +{
10573 +       if (!vxi)
10574 +               return;
10575 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10576 +}
10577 +
10578 +#else
10579 +#warning duplicate inclusion
10580 +#endif
10581 diff -NurpP --minimal linux-3.3.1/include/linux/vs_socket.h linux-3.3.1-vs2.3.3.2/include/linux/vs_socket.h
10582 --- linux-3.3.1/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10583 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_socket.h     2012-02-24 03:55:06.000000000 +0100
10584 @@ -0,0 +1,67 @@
10585 +#ifndef _VS_SOCKET_H
10586 +#define _VS_SOCKET_H
10587 +
10588 +#include "vserver/debug.h"
10589 +#include "vserver/base.h"
10590 +#include "vserver/cacct.h"
10591 +#include "vserver/context.h"
10592 +#include "vserver/tag.h"
10593 +
10594 +
10595 +/* socket accounting */
10596 +
10597 +#include <linux/socket.h>
10598 +
10599 +static inline int vx_sock_type(int family)
10600 +{
10601 +       switch (family) {
10602 +       case PF_UNSPEC:
10603 +               return VXA_SOCK_UNSPEC;
10604 +       case PF_UNIX:
10605 +               return VXA_SOCK_UNIX;
10606 +       case PF_INET:
10607 +               return VXA_SOCK_INET;
10608 +       case PF_INET6:
10609 +               return VXA_SOCK_INET6;
10610 +       case PF_PACKET:
10611 +               return VXA_SOCK_PACKET;
10612 +       default:
10613 +               return VXA_SOCK_OTHER;
10614 +       }
10615 +}
10616 +
10617 +#define vx_acc_sock(v, f, p, s) \
10618 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10619 +
10620 +static inline void __vx_acc_sock(struct vx_info *vxi,
10621 +       int family, int pos, int size, char *file, int line)
10622 +{
10623 +       if (vxi) {
10624 +               int type = vx_sock_type(family);
10625 +
10626 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10627 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10628 +       }
10629 +}
10630 +
10631 +#define vx_sock_recv(sk, s) \
10632 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10633 +#define vx_sock_send(sk, s) \
10634 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10635 +#define vx_sock_fail(sk, s) \
10636 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10637 +
10638 +
10639 +#define sock_vx_init(s) do {           \
10640 +       (s)->sk_xid = 0;                \
10641 +       (s)->sk_vx_info = NULL;         \
10642 +       } while (0)
10643 +
10644 +#define sock_nx_init(s) do {           \
10645 +       (s)->sk_nid = 0;                \
10646 +       (s)->sk_nx_info = NULL;         \
10647 +       } while (0)
10648 +
10649 +#else
10650 +#warning duplicate inclusion
10651 +#endif
10652 diff -NurpP --minimal linux-3.3.1/include/linux/vs_tag.h linux-3.3.1-vs2.3.3.2/include/linux/vs_tag.h
10653 --- linux-3.3.1/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10654 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_tag.h        2012-02-24 03:55:06.000000000 +0100
10655 @@ -0,0 +1,47 @@
10656 +#ifndef _VS_TAG_H
10657 +#define _VS_TAG_H
10658 +
10659 +#include <linux/vserver/tag.h>
10660 +
10661 +/* check conditions */
10662 +
10663 +#define DX_ADMIN       0x0001
10664 +#define DX_WATCH       0x0002
10665 +#define DX_HOSTID      0x0008
10666 +
10667 +#define DX_IDENT       0x0010
10668 +
10669 +#define DX_ARG_MASK    0x0010
10670 +
10671 +
10672 +#define dx_task_tag(t) ((t)->tag)
10673 +
10674 +#define dx_current_tag() dx_task_tag(current)
10675 +
10676 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10677 +
10678 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10679 +
10680 +
10681 +/*
10682 + * check current context for ADMIN/WATCH and
10683 + * optionally against supplied argument
10684 + */
10685 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10686 +{
10687 +       if (mode & DX_ARG_MASK) {
10688 +               if ((mode & DX_IDENT) && (id == cid))
10689 +                       return 1;
10690 +       }
10691 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10692 +               ((mode & DX_WATCH) && (cid == 1)) ||
10693 +               ((mode & DX_HOSTID) && (id == 0)));
10694 +}
10695 +
10696 +struct inode;
10697 +int dx_permission(const struct inode *inode, int mask);
10698 +
10699 +
10700 +#else
10701 +#warning duplicate inclusion
10702 +#endif
10703 diff -NurpP --minimal linux-3.3.1/include/linux/vs_time.h linux-3.3.1-vs2.3.3.2/include/linux/vs_time.h
10704 --- linux-3.3.1/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10705 +++ linux-3.3.1-vs2.3.3.2/include/linux/vs_time.h       2012-02-24 03:55:06.000000000 +0100
10706 @@ -0,0 +1,19 @@
10707 +#ifndef _VS_TIME_H
10708 +#define _VS_TIME_H
10709 +
10710 +
10711 +/* time faking stuff */
10712 +
10713 +#ifdef CONFIG_VSERVER_VTIME
10714 +
10715 +extern void vx_adjust_timespec(struct timespec *ts);
10716 +extern int vx_settimeofday(const struct timespec *ts);
10717 +
10718 +#else
10719 +#define        vx_adjust_timespec(t)   do { } while (0)
10720 +#define        vx_settimeofday(t)      do_settimeofday(t)
10721 +#endif
10722 +
10723 +#else
10724 +#warning duplicate inclusion
10725 +#endif
10726 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/Kbuild linux-3.3.1-vs2.3.3.2/include/linux/vserver/Kbuild
10727 --- linux-3.3.1/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10728 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/Kbuild  2012-02-24 03:55:06.000000000 +0100
10729 @@ -0,0 +1,8 @@
10730 +
10731 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10732 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10733 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10734 +       debug_cmd.h device_cmd.h
10735 +
10736 +header-y += switch.h network.h monitor.h inode.h device.h
10737 +
10738 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/base.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/base.h
10739 --- linux-3.3.1/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
10740 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/base.h  2012-02-24 03:55:06.000000000 +0100
10741 @@ -0,0 +1,178 @@
10742 +#ifndef _VX_BASE_H
10743 +#define _VX_BASE_H
10744 +
10745 +
10746 +/* context state changes */
10747 +
10748 +enum {
10749 +       VSC_STARTUP = 1,
10750 +       VSC_SHUTDOWN,
10751 +
10752 +       VSC_NETUP,
10753 +       VSC_NETDOWN,
10754 +};
10755 +
10756 +
10757 +
10758 +#define vx_task_xid(t) ((t)->xid)
10759 +
10760 +#define vx_current_xid() vx_task_xid(current)
10761 +
10762 +#define current_vx_info() (current->vx_info)
10763 +
10764 +
10765 +#define nx_task_nid(t) ((t)->nid)
10766 +
10767 +#define nx_current_nid() nx_task_nid(current)
10768 +
10769 +#define current_nx_info() (current->nx_info)
10770 +
10771 +
10772 +/* generic flag merging */
10773 +
10774 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10775 +
10776 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10777 +
10778 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10779 +
10780 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10781 +
10782 +
10783 +/* context flags */
10784 +
10785 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10786 +
10787 +#define vx_current_flags()     __vx_flags(current_vx_info())
10788 +
10789 +#define vx_info_flags(v, m, f) \
10790 +       vs_check_flags(__vx_flags(v), m, f)
10791 +
10792 +#define task_vx_flags(t, m, f) \
10793 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10794 +
10795 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10796 +
10797 +
10798 +/* context caps */
10799 +
10800 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10801 +
10802 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10803 +
10804 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10805 +
10806 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10807 +
10808 +
10809 +
10810 +/* network flags */
10811 +
10812 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10813 +
10814 +#define nx_current_flags()     __nx_flags(current_nx_info())
10815 +
10816 +#define nx_info_flags(n, m, f) \
10817 +       vs_check_flags(__nx_flags(n), m, f)
10818 +
10819 +#define task_nx_flags(t, m, f) \
10820 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10821 +
10822 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10823 +
10824 +
10825 +/* network caps */
10826 +
10827 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10828 +
10829 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10830 +
10831 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10832 +
10833 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10834 +
10835 +
10836 +/* context mask capabilities */
10837 +
10838 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10839 +
10840 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10841 +
10842 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10843 +
10844 +
10845 +/* context bcap mask */
10846 +
10847 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10848 +
10849 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10850 +
10851 +
10852 +/* mask given bcaps */
10853 +
10854 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10855 +
10856 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10857 +
10858 +
10859 +/* masked cap_bset */
10860 +
10861 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10862 +
10863 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10864 +
10865 +#if 0
10866 +#define vx_info_mbcap(v, b) \
10867 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10868 +       vx_info_bcaps(v, b) : (b))
10869 +
10870 +#define task_vx_mbcap(t, b) \
10871 +       vx_info_mbcap((t)->vx_info, (t)->b)
10872 +
10873 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10874 +#endif
10875 +
10876 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10877 +
10878 +#define vx_capable(b, c) (capable(b) || \
10879 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10880 +
10881 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10882 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10883 +
10884 +#define nx_capable(b, c) (capable(b) || \
10885 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10886 +
10887 +#define vx_task_initpid(t, n) \
10888 +       ((t)->vx_info && \
10889 +       ((t)->vx_info->vx_initpid == (n)))
10890 +
10891 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10892 +
10893 +
10894 +/* context unshare mask */
10895 +
10896 +#define __vx_umask(v)          ((v)->vx_umask)
10897 +
10898 +#define vx_current_umask()     __vx_umask(current_vx_info())
10899 +
10900 +#define vx_can_unshare(b, f) (capable(b) || \
10901 +       (cap_raised(current_cap(), b) && \
10902 +       !((f) & ~vx_current_umask())))
10903 +
10904 +
10905 +#define __vx_wmask(v)          ((v)->vx_wmask)
10906 +
10907 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10908 +
10909 +
10910 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10911 +
10912 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10913 +
10914 +
10915 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10916 +
10917 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10918 +
10919 +#endif
10920 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cacct.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct.h
10921 --- linux-3.3.1/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
10922 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct.h 2012-02-24 03:55:06.000000000 +0100
10923 @@ -0,0 +1,15 @@
10924 +#ifndef _VX_CACCT_H
10925 +#define _VX_CACCT_H
10926 +
10927 +
10928 +enum sock_acc_field {
10929 +       VXA_SOCK_UNSPEC = 0,
10930 +       VXA_SOCK_UNIX,
10931 +       VXA_SOCK_INET,
10932 +       VXA_SOCK_INET6,
10933 +       VXA_SOCK_PACKET,
10934 +       VXA_SOCK_OTHER,
10935 +       VXA_SOCK_SIZE   /* array size */
10936 +};
10937 +
10938 +#endif /* _VX_CACCT_H */
10939 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cacct_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct_cmd.h
10940 --- linux-3.3.1/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
10941 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct_cmd.h     2012-02-24 03:55:06.000000000 +0100
10942 @@ -0,0 +1,23 @@
10943 +#ifndef _VX_CACCT_CMD_H
10944 +#define _VX_CACCT_CMD_H
10945 +
10946 +
10947 +/* virtual host info name commands */
10948 +
10949 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10950 +
10951 +struct vcmd_sock_stat_v0 {
10952 +       uint32_t field;
10953 +       uint32_t count[3];
10954 +       uint64_t total[3];
10955 +};
10956 +
10957 +
10958 +#ifdef __KERNEL__
10959 +
10960 +#include <linux/compiler.h>
10961 +
10962 +extern int vc_sock_stat(struct vx_info *, void __user *);
10963 +
10964 +#endif /* __KERNEL__ */
10965 +#endif /* _VX_CACCT_CMD_H */
10966 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cacct_def.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct_def.h
10967 --- linux-3.3.1/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
10968 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct_def.h     2012-02-24 03:55:06.000000000 +0100
10969 @@ -0,0 +1,43 @@
10970 +#ifndef _VX_CACCT_DEF_H
10971 +#define _VX_CACCT_DEF_H
10972 +
10973 +#include <asm/atomic.h>
10974 +#include <linux/vserver/cacct.h>
10975 +
10976 +
10977 +struct _vx_sock_acc {
10978 +       atomic_long_t count;
10979 +       atomic_long_t total;
10980 +};
10981 +
10982 +/* context sub struct */
10983 +
10984 +struct _vx_cacct {
10985 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10986 +       atomic_t slab[8];
10987 +       atomic_t page[6][8];
10988 +};
10989 +
10990 +#ifdef CONFIG_VSERVER_DEBUG
10991 +
10992 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10993 +{
10994 +       int i, j;
10995 +
10996 +       printk("\t_vx_cacct:");
10997 +       for (i = 0; i < 6; i++) {
10998 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10999 +
11000 +               printk("\t [%d] =", i);
11001 +               for (j = 0; j < 3; j++) {
11002 +                       printk(" [%d] = %8lu, %8lu", j,
11003 +                               atomic_long_read(&ptr[j].count),
11004 +                               atomic_long_read(&ptr[j].total));
11005 +               }
11006 +               printk("\n");
11007 +       }
11008 +}
11009 +
11010 +#endif
11011 +
11012 +#endif /* _VX_CACCT_DEF_H */
11013 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cacct_int.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct_int.h
11014 --- linux-3.3.1/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
11015 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cacct_int.h     2012-02-24 03:55:06.000000000 +0100
11016 @@ -0,0 +1,21 @@
11017 +#ifndef _VX_CACCT_INT_H
11018 +#define _VX_CACCT_INT_H
11019 +
11020 +
11021 +#ifdef __KERNEL__
11022 +
11023 +static inline
11024 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11025 +{
11026 +       return atomic_long_read(&cacct->sock[type][pos].count);
11027 +}
11028 +
11029 +
11030 +static inline
11031 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11032 +{
11033 +       return atomic_long_read(&cacct->sock[type][pos].total);
11034 +}
11035 +
11036 +#endif /* __KERNEL__ */
11037 +#endif /* _VX_CACCT_INT_H */
11038 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/check.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/check.h
11039 --- linux-3.3.1/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
11040 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/check.h 2012-02-24 03:55:06.000000000 +0100
11041 @@ -0,0 +1,89 @@
11042 +#ifndef _VS_CHECK_H
11043 +#define _VS_CHECK_H
11044 +
11045 +
11046 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11047 +
11048 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11049 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11050 +#else
11051 +#define MIN_D_CONTEXT  65536
11052 +#endif
11053 +
11054 +/* check conditions */
11055 +
11056 +#define VS_ADMIN       0x0001
11057 +#define VS_WATCH       0x0002
11058 +#define VS_HIDE                0x0004
11059 +#define VS_HOSTID      0x0008
11060 +
11061 +#define VS_IDENT       0x0010
11062 +#define VS_EQUIV       0x0020
11063 +#define VS_PARENT      0x0040
11064 +#define VS_CHILD       0x0080
11065 +
11066 +#define VS_ARG_MASK    0x00F0
11067 +
11068 +#define VS_DYNAMIC     0x0100
11069 +#define VS_STATIC      0x0200
11070 +
11071 +#define VS_ATR_MASK    0x0F00
11072 +
11073 +#ifdef CONFIG_VSERVER_PRIVACY
11074 +#define VS_ADMIN_P     (0)
11075 +#define VS_WATCH_P     (0)
11076 +#else
11077 +#define VS_ADMIN_P     VS_ADMIN
11078 +#define VS_WATCH_P     VS_WATCH
11079 +#endif
11080 +
11081 +#define VS_HARDIRQ     0x1000
11082 +#define VS_SOFTIRQ     0x2000
11083 +#define VS_IRQ         0x4000
11084 +
11085 +#define VS_IRQ_MASK    0xF000
11086 +
11087 +#include <linux/hardirq.h>
11088 +
11089 +/*
11090 + * check current context for ADMIN/WATCH and
11091 + * optionally against supplied argument
11092 + */
11093 +static inline int __vs_check(int cid, int id, unsigned int mode)
11094 +{
11095 +       if (mode & VS_ARG_MASK) {
11096 +               if ((mode & VS_IDENT) && (id == cid))
11097 +                       return 1;
11098 +       }
11099 +       if (mode & VS_ATR_MASK) {
11100 +               if ((mode & VS_DYNAMIC) &&
11101 +                       (id >= MIN_D_CONTEXT) &&
11102 +                       (id <= MAX_S_CONTEXT))
11103 +                       return 1;
11104 +               if ((mode & VS_STATIC) &&
11105 +                       (id > 1) && (id < MIN_D_CONTEXT))
11106 +                       return 1;
11107 +       }
11108 +       if (mode & VS_IRQ_MASK) {
11109 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11110 +                       return 1;
11111 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11112 +                       return 1;
11113 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11114 +                       return 1;
11115 +       }
11116 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11117 +               ((mode & VS_WATCH) && (cid == 1)) ||
11118 +               ((mode & VS_HOSTID) && (id == 0)));
11119 +}
11120 +
11121 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11122 +
11123 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11124 +
11125 +
11126 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11127 +
11128 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11129 +
11130 +#endif
11131 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/context.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/context.h
11132 --- linux-3.3.1/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11133 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/context.h       2012-02-24 03:55:06.000000000 +0100
11134 @@ -0,0 +1,188 @@
11135 +#ifndef _VX_CONTEXT_H
11136 +#define _VX_CONTEXT_H
11137 +
11138 +#include <linux/types.h>
11139 +#include <linux/capability.h>
11140 +
11141 +
11142 +/* context flags */
11143 +
11144 +#define VXF_INFO_SCHED         0x00000002
11145 +#define VXF_INFO_NPROC         0x00000004
11146 +#define VXF_INFO_PRIVATE       0x00000008
11147 +
11148 +#define VXF_INFO_INIT          0x00000010
11149 +#define VXF_INFO_HIDE          0x00000020
11150 +#define VXF_INFO_ULIMIT                0x00000040
11151 +#define VXF_INFO_NSPACE                0x00000080
11152 +
11153 +#define VXF_SCHED_HARD         0x00000100
11154 +#define VXF_SCHED_PRIO         0x00000200
11155 +#define VXF_SCHED_PAUSE                0x00000400
11156 +
11157 +#define VXF_VIRT_MEM           0x00010000
11158 +#define VXF_VIRT_UPTIME                0x00020000
11159 +#define VXF_VIRT_CPU           0x00040000
11160 +#define VXF_VIRT_LOAD          0x00080000
11161 +#define VXF_VIRT_TIME          0x00100000
11162 +
11163 +#define VXF_HIDE_MOUNT         0x01000000
11164 +/* was VXF_HIDE_NETIF          0x02000000 */
11165 +#define VXF_HIDE_VINFO         0x04000000
11166 +
11167 +#define VXF_STATE_SETUP                (1ULL << 32)
11168 +#define VXF_STATE_INIT         (1ULL << 33)
11169 +#define VXF_STATE_ADMIN                (1ULL << 34)
11170 +
11171 +#define VXF_SC_HELPER          (1ULL << 36)
11172 +#define VXF_REBOOT_KILL                (1ULL << 37)
11173 +#define VXF_PERSISTENT         (1ULL << 38)
11174 +
11175 +#define VXF_FORK_RSS           (1ULL << 48)
11176 +#define VXF_PROLIFIC           (1ULL << 49)
11177 +
11178 +#define VXF_IGNEG_NICE         (1ULL << 52)
11179 +
11180 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11181 +
11182 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11183 +
11184 +
11185 +/* context migration */
11186 +
11187 +#define VXM_SET_INIT           0x00000001
11188 +#define VXM_SET_REAPER         0x00000002
11189 +
11190 +/* context caps */
11191 +
11192 +#define VXC_SET_UTSNAME                0x00000001
11193 +#define VXC_SET_RLIMIT         0x00000002
11194 +#define VXC_FS_SECURITY                0x00000004
11195 +#define VXC_FS_TRUSTED         0x00000008
11196 +#define VXC_TIOCSTI            0x00000010
11197 +
11198 +/* was VXC_RAW_ICMP            0x00000100 */
11199 +#define VXC_SYSLOG             0x00001000
11200 +#define VXC_OOM_ADJUST         0x00002000
11201 +#define VXC_AUDIT_CONTROL      0x00004000
11202 +
11203 +#define VXC_SECURE_MOUNT       0x00010000
11204 +#define VXC_SECURE_REMOUNT     0x00020000
11205 +#define VXC_BINARY_MOUNT       0x00040000
11206 +
11207 +#define VXC_QUOTA_CTL          0x00100000
11208 +#define VXC_ADMIN_MAPPER       0x00200000
11209 +#define VXC_ADMIN_CLOOP                0x00400000
11210 +
11211 +#define VXC_KTHREAD            0x01000000
11212 +#define VXC_NAMESPACE          0x02000000
11213 +
11214 +
11215 +#ifdef __KERNEL__
11216 +
11217 +#include <linux/list.h>
11218 +#include <linux/spinlock.h>
11219 +#include <linux/rcupdate.h>
11220 +
11221 +#include "limit_def.h"
11222 +#include "sched_def.h"
11223 +#include "cvirt_def.h"
11224 +#include "cacct_def.h"
11225 +#include "device_def.h"
11226 +
11227 +#define VX_SPACES      2
11228 +
11229 +struct _vx_info_pc {
11230 +       struct _vx_sched_pc sched_pc;
11231 +       struct _vx_cvirt_pc cvirt_pc;
11232 +};
11233 +
11234 +struct _vx_space {
11235 +       unsigned long vx_nsmask;                /* assignment mask */
11236 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11237 +       struct fs_struct *vx_fs;                /* private namespace fs */
11238 +       const struct cred *vx_cred;             /* task credentials */
11239 +};
11240 +
11241 +struct vx_info {
11242 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11243 +       xid_t vx_id;                            /* context id */
11244 +       atomic_t vx_usecnt;                     /* usage count */
11245 +       atomic_t vx_tasks;                      /* tasks count */
11246 +       struct vx_info *vx_parent;              /* parent context */
11247 +       int vx_state;                           /* context state */
11248 +
11249 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11250 +
11251 +       uint64_t vx_flags;                      /* context flags */
11252 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11253 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11254 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11255 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11256 +
11257 +       struct task_struct *vx_reaper;          /* guest reaper process */
11258 +       pid_t vx_initpid;                       /* PID of guest init */
11259 +       int64_t vx_badness_bias;                /* OOM points bias */
11260 +
11261 +       struct _vx_limit limit;                 /* vserver limits */
11262 +       struct _vx_sched sched;                 /* vserver scheduler */
11263 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11264 +       struct _vx_cacct cacct;                 /* context accounting */
11265 +
11266 +       struct _vx_device dmap;                 /* default device map targets */
11267 +
11268 +#ifndef CONFIG_SMP
11269 +       struct _vx_info_pc info_pc;             /* per cpu data */
11270 +#else
11271 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11272 +#endif
11273 +
11274 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11275 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11276 +       int exit_code;                          /* last process exit code */
11277 +
11278 +       char vx_name[65];                       /* vserver name */
11279 +};
11280 +
11281 +#ifndef CONFIG_SMP
11282 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11283 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11284 +#else
11285 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11286 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11287 +#endif
11288 +
11289 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11290 +
11291 +
11292 +struct vx_info_save {
11293 +       struct vx_info *vxi;
11294 +       xid_t xid;
11295 +};
11296 +
11297 +
11298 +/* status flags */
11299 +
11300 +#define VXS_HASHED     0x0001
11301 +#define VXS_PAUSED     0x0010
11302 +#define VXS_SHUTDOWN   0x0100
11303 +#define VXS_HELPER     0x1000
11304 +#define VXS_RELEASED   0x8000
11305 +
11306 +
11307 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11308 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11309 +
11310 +extern struct vx_info *lookup_vx_info(int);
11311 +extern struct vx_info *lookup_or_create_vx_info(int);
11312 +
11313 +extern int get_xid_list(int, unsigned int *, int);
11314 +extern int xid_is_hashed(xid_t);
11315 +
11316 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11317 +
11318 +extern long vs_state_change(struct vx_info *, unsigned int);
11319 +
11320 +
11321 +#endif /* __KERNEL__ */
11322 +#endif /* _VX_CONTEXT_H */
11323 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/context_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/context_cmd.h
11324 --- linux-3.3.1/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11325 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/context_cmd.h   2012-02-24 03:55:06.000000000 +0100
11326 @@ -0,0 +1,162 @@
11327 +#ifndef _VX_CONTEXT_CMD_H
11328 +#define _VX_CONTEXT_CMD_H
11329 +
11330 +
11331 +/* vinfo commands */
11332 +
11333 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11334 +
11335 +#ifdef __KERNEL__
11336 +extern int vc_task_xid(uint32_t);
11337 +
11338 +#endif /* __KERNEL__ */
11339 +
11340 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11341 +
11342 +struct vcmd_vx_info_v0 {
11343 +       uint32_t xid;
11344 +       uint32_t initpid;
11345 +       /* more to come */
11346 +};
11347 +
11348 +#ifdef __KERNEL__
11349 +extern int vc_vx_info(struct vx_info *, void __user *);
11350 +
11351 +#endif /* __KERNEL__ */
11352 +
11353 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11354 +
11355 +struct vcmd_ctx_stat_v0 {
11356 +       uint32_t usecnt;
11357 +       uint32_t tasks;
11358 +       /* more to come */
11359 +};
11360 +
11361 +#ifdef __KERNEL__
11362 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11363 +
11364 +#endif /* __KERNEL__ */
11365 +
11366 +/* context commands */
11367 +
11368 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11369 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11370 +
11371 +struct vcmd_ctx_create {
11372 +       uint64_t flagword;
11373 +};
11374 +
11375 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11376 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11377 +
11378 +struct vcmd_ctx_migrate {
11379 +       uint64_t flagword;
11380 +};
11381 +
11382 +#ifdef __KERNEL__
11383 +extern int vc_ctx_create(uint32_t, void __user *);
11384 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11385 +
11386 +#endif /* __KERNEL__ */
11387 +
11388 +
11389 +/* flag commands */
11390 +
11391 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11392 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11393 +
11394 +struct vcmd_ctx_flags_v0 {
11395 +       uint64_t flagword;
11396 +       uint64_t mask;
11397 +};
11398 +
11399 +#ifdef __KERNEL__
11400 +extern int vc_get_cflags(struct vx_info *, void __user *);
11401 +extern int vc_set_cflags(struct vx_info *, void __user *);
11402 +
11403 +#endif /* __KERNEL__ */
11404 +
11405 +
11406 +/* context caps commands */
11407 +
11408 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11409 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11410 +
11411 +struct vcmd_ctx_caps_v1 {
11412 +       uint64_t ccaps;
11413 +       uint64_t cmask;
11414 +};
11415 +
11416 +#ifdef __KERNEL__
11417 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11418 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11419 +
11420 +#endif /* __KERNEL__ */
11421 +
11422 +
11423 +/* bcaps commands */
11424 +
11425 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11426 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11427 +
11428 +struct vcmd_bcaps {
11429 +       uint64_t bcaps;
11430 +       uint64_t bmask;
11431 +};
11432 +
11433 +#ifdef __KERNEL__
11434 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11435 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11436 +
11437 +#endif /* __KERNEL__ */
11438 +
11439 +
11440 +/* umask commands */
11441 +
11442 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11443 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11444 +
11445 +struct vcmd_umask {
11446 +       uint64_t umask;
11447 +       uint64_t mask;
11448 +};
11449 +
11450 +#ifdef __KERNEL__
11451 +extern int vc_get_umask(struct vx_info *, void __user *);
11452 +extern int vc_set_umask(struct vx_info *, void __user *);
11453 +
11454 +#endif /* __KERNEL__ */
11455 +
11456 +
11457 +/* wmask commands */
11458 +
11459 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11460 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11461 +
11462 +struct vcmd_wmask {
11463 +       uint64_t wmask;
11464 +       uint64_t mask;
11465 +};
11466 +
11467 +#ifdef __KERNEL__
11468 +extern int vc_get_wmask(struct vx_info *, void __user *);
11469 +extern int vc_set_wmask(struct vx_info *, void __user *);
11470 +
11471 +#endif /* __KERNEL__ */
11472 +
11473 +
11474 +/* OOM badness */
11475 +
11476 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11477 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11478 +
11479 +struct vcmd_badness_v0 {
11480 +       int64_t bias;
11481 +};
11482 +
11483 +#ifdef __KERNEL__
11484 +extern int vc_get_badness(struct vx_info *, void __user *);
11485 +extern int vc_set_badness(struct vx_info *, void __user *);
11486 +
11487 +#endif /* __KERNEL__ */
11488 +#endif /* _VX_CONTEXT_CMD_H */
11489 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cvirt.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cvirt.h
11490 --- linux-3.3.1/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11491 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cvirt.h 2012-02-24 03:55:06.000000000 +0100
11492 @@ -0,0 +1,20 @@
11493 +#ifndef _VX_CVIRT_H
11494 +#define _VX_CVIRT_H
11495 +
11496 +
11497 +#ifdef __KERNEL__
11498 +
11499 +struct timespec;
11500 +
11501 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11502 +
11503 +
11504 +struct vx_info;
11505 +
11506 +void vx_update_load(struct vx_info *);
11507 +
11508 +
11509 +int vx_do_syslog(int, char __user *, int);
11510 +
11511 +#endif /* __KERNEL__ */
11512 +#endif /* _VX_CVIRT_H */
11513 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cvirt_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cvirt_cmd.h
11514 --- linux-3.3.1/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11515 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cvirt_cmd.h     2012-02-24 03:55:06.000000000 +0100
11516 @@ -0,0 +1,53 @@
11517 +#ifndef _VX_CVIRT_CMD_H
11518 +#define _VX_CVIRT_CMD_H
11519 +
11520 +
11521 +/* virtual host info name commands */
11522 +
11523 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11524 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11525 +
11526 +struct vcmd_vhi_name_v0 {
11527 +       uint32_t field;
11528 +       char name[65];
11529 +};
11530 +
11531 +
11532 +enum vhi_name_field {
11533 +       VHIN_CONTEXT = 0,
11534 +       VHIN_SYSNAME,
11535 +       VHIN_NODENAME,
11536 +       VHIN_RELEASE,
11537 +       VHIN_VERSION,
11538 +       VHIN_MACHINE,
11539 +       VHIN_DOMAINNAME,
11540 +};
11541 +
11542 +
11543 +#ifdef __KERNEL__
11544 +
11545 +#include <linux/compiler.h>
11546 +
11547 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11548 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11549 +
11550 +#endif /* __KERNEL__ */
11551 +
11552 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11553 +
11554 +struct vcmd_virt_stat_v0 {
11555 +       uint64_t offset;
11556 +       uint64_t uptime;
11557 +       uint32_t nr_threads;
11558 +       uint32_t nr_running;
11559 +       uint32_t nr_uninterruptible;
11560 +       uint32_t nr_onhold;
11561 +       uint32_t nr_forks;
11562 +       uint32_t load[3];
11563 +};
11564 +
11565 +#ifdef __KERNEL__
11566 +extern int vc_virt_stat(struct vx_info *, void __user *);
11567 +
11568 +#endif /* __KERNEL__ */
11569 +#endif /* _VX_CVIRT_CMD_H */
11570 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/cvirt_def.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/cvirt_def.h
11571 --- linux-3.3.1/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11572 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/cvirt_def.h     2012-02-24 03:55:06.000000000 +0100
11573 @@ -0,0 +1,80 @@
11574 +#ifndef _VX_CVIRT_DEF_H
11575 +#define _VX_CVIRT_DEF_H
11576 +
11577 +#include <linux/jiffies.h>
11578 +#include <linux/spinlock.h>
11579 +#include <linux/wait.h>
11580 +#include <linux/time.h>
11581 +#include <asm/atomic.h>
11582 +
11583 +
11584 +struct _vx_usage_stat {
11585 +       uint64_t user;
11586 +       uint64_t nice;
11587 +       uint64_t system;
11588 +       uint64_t softirq;
11589 +       uint64_t irq;
11590 +       uint64_t idle;
11591 +       uint64_t iowait;
11592 +};
11593 +
11594 +struct _vx_syslog {
11595 +       wait_queue_head_t log_wait;
11596 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11597 +
11598 +       unsigned long log_start;        /* next char to be read by syslog() */
11599 +       unsigned long con_start;        /* next char to be sent to consoles */
11600 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11601 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11602 +
11603 +       char log_buf[1024];
11604 +};
11605 +
11606 +
11607 +/* context sub struct */
11608 +
11609 +struct _vx_cvirt {
11610 +       atomic_t nr_threads;            /* number of current threads */
11611 +       atomic_t nr_running;            /* number of running threads */
11612 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11613 +
11614 +       atomic_t nr_onhold;             /* processes on hold */
11615 +       uint32_t onhold_last;           /* jiffies when put on hold */
11616 +
11617 +       struct timespec bias_ts;        /* time offset to the host */
11618 +       struct timespec bias_idle;
11619 +       struct timespec bias_uptime;    /* context creation point */
11620 +       uint64_t bias_clock;            /* offset in clock_t */
11621 +
11622 +       spinlock_t load_lock;           /* lock for the load averages */
11623 +       atomic_t load_updates;          /* nr of load updates done so far */
11624 +       uint32_t load_last;             /* last time load was calculated */
11625 +       uint32_t load[3];               /* load averages 1,5,15 */
11626 +
11627 +       atomic_t total_forks;           /* number of forks so far */
11628 +
11629 +       struct _vx_syslog syslog;
11630 +};
11631 +
11632 +struct _vx_cvirt_pc {
11633 +       struct _vx_usage_stat cpustat;
11634 +};
11635 +
11636 +
11637 +#ifdef CONFIG_VSERVER_DEBUG
11638 +
11639 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11640 +{
11641 +       printk("\t_vx_cvirt:\n");
11642 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11643 +               atomic_read(&cvirt->nr_threads),
11644 +               atomic_read(&cvirt->nr_running),
11645 +               atomic_read(&cvirt->nr_uninterruptible),
11646 +               atomic_read(&cvirt->nr_onhold));
11647 +       /* add rest here */
11648 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11649 +}
11650 +
11651 +#endif
11652 +
11653 +#endif /* _VX_CVIRT_DEF_H */
11654 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/debug.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/debug.h
11655 --- linux-3.3.1/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11656 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/debug.h 2012-02-24 03:55:06.000000000 +0100
11657 @@ -0,0 +1,145 @@
11658 +#ifndef _VX_DEBUG_H
11659 +#define _VX_DEBUG_H
11660 +
11661 +
11662 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11663 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11664 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11665 +
11666 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11667 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11668 +#define VXF_DEV                "%p[%lu,%d:%d]"
11669 +
11670 +#if    defined(CONFIG_QUOTES_UTF8)
11671 +#define        VS_Q_LQM        "\xc2\xbb"
11672 +#define        VS_Q_RQM        "\xc2\xab"
11673 +#elif  defined(CONFIG_QUOTES_ASCII)
11674 +#define        VS_Q_LQM        "\x27"
11675 +#define        VS_Q_RQM        "\x27"
11676 +#else
11677 +#define        VS_Q_LQM        "\xbb"
11678 +#define        VS_Q_RQM        "\xab"
11679 +#endif
11680 +
11681 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11682 +
11683 +
11684 +#define vxd_path(p)                                            \
11685 +       ({ static char _buffer[PATH_MAX];                       \
11686 +          d_path(p, _buffer, sizeof(_buffer)); })
11687 +
11688 +#define vxd_cond_path(n)                                       \
11689 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11690 +
11691 +
11692 +#ifdef CONFIG_VSERVER_DEBUG
11693 +
11694 +extern unsigned int vs_debug_switch;
11695 +extern unsigned int vs_debug_xid;
11696 +extern unsigned int vs_debug_nid;
11697 +extern unsigned int vs_debug_tag;
11698 +extern unsigned int vs_debug_net;
11699 +extern unsigned int vs_debug_limit;
11700 +extern unsigned int vs_debug_cres;
11701 +extern unsigned int vs_debug_dlim;
11702 +extern unsigned int vs_debug_quota;
11703 +extern unsigned int vs_debug_cvirt;
11704 +extern unsigned int vs_debug_space;
11705 +extern unsigned int vs_debug_perm;
11706 +extern unsigned int vs_debug_misc;
11707 +
11708 +
11709 +#define VX_LOGLEVEL    "vxD: "
11710 +#define VX_PROC_FMT    "%p: "
11711 +#define VX_PROCESS     current
11712 +
11713 +#define vxdprintk(c, f, x...)                                  \
11714 +       do {                                                    \
11715 +               if (c)                                          \
11716 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11717 +                               VX_PROCESS , ##x);              \
11718 +       } while (0)
11719 +
11720 +#define vxlprintk(c, f, x...)                                  \
11721 +       do {                                                    \
11722 +               if (c)                                          \
11723 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11724 +       } while (0)
11725 +
11726 +#define vxfprintk(c, f, x...)                                  \
11727 +       do {                                                    \
11728 +               if (c)                                          \
11729 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11730 +       } while (0)
11731 +
11732 +
11733 +struct vx_info;
11734 +
11735 +void dump_vx_info(struct vx_info *, int);
11736 +void dump_vx_info_inactive(int);
11737 +
11738 +#else  /* CONFIG_VSERVER_DEBUG */
11739 +
11740 +#define vs_debug_switch        0
11741 +#define vs_debug_xid   0
11742 +#define vs_debug_nid   0
11743 +#define vs_debug_tag   0
11744 +#define vs_debug_net   0
11745 +#define vs_debug_limit 0
11746 +#define vs_debug_cres  0
11747 +#define vs_debug_dlim  0
11748 +#define vs_debug_quota 0
11749 +#define vs_debug_cvirt 0
11750 +#define vs_debug_space 0
11751 +#define vs_debug_perm  0
11752 +#define vs_debug_misc  0
11753 +
11754 +#define vxdprintk(x...) do { } while (0)
11755 +#define vxlprintk(x...) do { } while (0)
11756 +#define vxfprintk(x...) do { } while (0)
11757 +
11758 +#endif /* CONFIG_VSERVER_DEBUG */
11759 +
11760 +
11761 +#ifdef CONFIG_VSERVER_WARN
11762 +
11763 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11764 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11765 +#define VX_WARN_XID    "[xid #%u] "
11766 +#define VX_WARN_NID    "[nid #%u] "
11767 +#define VX_WARN_TAG    "[tag #%u] "
11768 +
11769 +#define vxwprintk(c, f, x...)                                  \
11770 +       do {                                                    \
11771 +               if (c)                                          \
11772 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11773 +       } while (0)
11774 +
11775 +#else  /* CONFIG_VSERVER_WARN */
11776 +
11777 +#define vxwprintk(x...) do { } while (0)
11778 +
11779 +#endif /* CONFIG_VSERVER_WARN */
11780 +
11781 +#define vxwprintk_task(c, f, x...)                             \
11782 +       vxwprintk(c, VX_WARN_TASK f,                            \
11783 +               current->comm, current->pid,                    \
11784 +               current->xid, current->nid, current->tag, ##x)
11785 +#define vxwprintk_xid(c, f, x...)                              \
11786 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11787 +#define vxwprintk_nid(c, f, x...)                              \
11788 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11789 +#define vxwprintk_tag(c, f, x...)                              \
11790 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11791 +
11792 +#ifdef CONFIG_VSERVER_DEBUG
11793 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11794 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11795 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11796 +#else
11797 +#define vxd_assert_lock(l)     do { } while (0)
11798 +#define vxd_assert(c, f, x...) do { } while (0)
11799 +#endif
11800 +
11801 +
11802 +#endif /* _VX_DEBUG_H */
11803 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/debug_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/debug_cmd.h
11804 --- linux-3.3.1/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
11805 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/debug_cmd.h     2012-02-24 03:55:06.000000000 +0100
11806 @@ -0,0 +1,58 @@
11807 +#ifndef _VX_DEBUG_CMD_H
11808 +#define _VX_DEBUG_CMD_H
11809 +
11810 +
11811 +/* debug commands */
11812 +
11813 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11814 +
11815 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11816 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11817 +
11818 +struct  vcmd_read_history_v0 {
11819 +       uint32_t index;
11820 +       uint32_t count;
11821 +       char __user *data;
11822 +};
11823 +
11824 +struct  vcmd_read_monitor_v0 {
11825 +       uint32_t index;
11826 +       uint32_t count;
11827 +       char __user *data;
11828 +};
11829 +
11830 +
11831 +#ifdef __KERNEL__
11832 +
11833 +#ifdef CONFIG_COMPAT
11834 +
11835 +#include <asm/compat.h>
11836 +
11837 +struct vcmd_read_history_v0_x32 {
11838 +       uint32_t index;
11839 +       uint32_t count;
11840 +       compat_uptr_t data_ptr;
11841 +};
11842 +
11843 +struct vcmd_read_monitor_v0_x32 {
11844 +       uint32_t index;
11845 +       uint32_t count;
11846 +       compat_uptr_t data_ptr;
11847 +};
11848 +
11849 +#endif  /* CONFIG_COMPAT */
11850 +
11851 +extern int vc_dump_history(uint32_t);
11852 +
11853 +extern int vc_read_history(uint32_t, void __user *);
11854 +extern int vc_read_monitor(uint32_t, void __user *);
11855 +
11856 +#ifdef CONFIG_COMPAT
11857 +
11858 +extern int vc_read_history_x32(uint32_t, void __user *);
11859 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11860 +
11861 +#endif  /* CONFIG_COMPAT */
11862 +
11863 +#endif /* __KERNEL__ */
11864 +#endif /* _VX_DEBUG_CMD_H */
11865 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/device.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/device.h
11866 --- linux-3.3.1/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
11867 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/device.h        2012-02-24 03:55:06.000000000 +0100
11868 @@ -0,0 +1,15 @@
11869 +#ifndef _VX_DEVICE_H
11870 +#define _VX_DEVICE_H
11871 +
11872 +
11873 +#define DATTR_CREATE   0x00000001
11874 +#define DATTR_OPEN     0x00000002
11875 +
11876 +#define DATTR_REMAP    0x00000010
11877 +
11878 +#define DATTR_MASK     0x00000013
11879 +
11880 +
11881 +#else  /* _VX_DEVICE_H */
11882 +#warning duplicate inclusion
11883 +#endif /* _VX_DEVICE_H */
11884 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/device_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/device_cmd.h
11885 --- linux-3.3.1/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
11886 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/device_cmd.h    2012-02-24 03:55:06.000000000 +0100
11887 @@ -0,0 +1,44 @@
11888 +#ifndef _VX_DEVICE_CMD_H
11889 +#define _VX_DEVICE_CMD_H
11890 +
11891 +
11892 +/*  device vserver commands */
11893 +
11894 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11895 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11896 +
11897 +struct vcmd_set_mapping_v0 {
11898 +       const char __user *device;
11899 +       const char __user *target;
11900 +       uint32_t flags;
11901 +};
11902 +
11903 +
11904 +#ifdef __KERNEL__
11905 +
11906 +#ifdef CONFIG_COMPAT
11907 +
11908 +#include <asm/compat.h>
11909 +
11910 +struct vcmd_set_mapping_v0_x32 {
11911 +       compat_uptr_t device_ptr;
11912 +       compat_uptr_t target_ptr;
11913 +       uint32_t flags;
11914 +};
11915 +
11916 +#endif /* CONFIG_COMPAT */
11917 +
11918 +#include <linux/compiler.h>
11919 +
11920 +extern int vc_set_mapping(struct vx_info *, void __user *);
11921 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11922 +
11923 +#ifdef CONFIG_COMPAT
11924 +
11925 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11926 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11927 +
11928 +#endif /* CONFIG_COMPAT */
11929 +
11930 +#endif /* __KERNEL__ */
11931 +#endif /* _VX_DEVICE_CMD_H */
11932 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/device_def.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/device_def.h
11933 --- linux-3.3.1/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
11934 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/device_def.h    2012-02-24 03:55:06.000000000 +0100
11935 @@ -0,0 +1,17 @@
11936 +#ifndef _VX_DEVICE_DEF_H
11937 +#define _VX_DEVICE_DEF_H
11938 +
11939 +#include <linux/types.h>
11940 +
11941 +struct vx_dmap_target {
11942 +       dev_t target;
11943 +       uint32_t flags;
11944 +};
11945 +
11946 +struct _vx_device {
11947 +#ifdef CONFIG_VSERVER_DEVICE
11948 +       struct vx_dmap_target targets[2];
11949 +#endif
11950 +};
11951 +
11952 +#endif /* _VX_DEVICE_DEF_H */
11953 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/dlimit.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/dlimit.h
11954 --- linux-3.3.1/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
11955 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/dlimit.h        2012-02-24 03:55:06.000000000 +0100
11956 @@ -0,0 +1,54 @@
11957 +#ifndef _VX_DLIMIT_H
11958 +#define _VX_DLIMIT_H
11959 +
11960 +#include "switch.h"
11961 +
11962 +
11963 +#ifdef __KERNEL__
11964 +
11965 +/*      keep in sync with CDLIM_INFINITY       */
11966 +
11967 +#define DLIM_INFINITY          (~0ULL)
11968 +
11969 +#include <linux/spinlock.h>
11970 +#include <linux/rcupdate.h>
11971 +
11972 +struct super_block;
11973 +
11974 +struct dl_info {
11975 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11976 +       struct rcu_head dl_rcu;                 /* the rcu head */
11977 +       tag_t dl_tag;                           /* context tag */
11978 +       atomic_t dl_usecnt;                     /* usage count */
11979 +       atomic_t dl_refcnt;                     /* reference count */
11980 +
11981 +       struct super_block *dl_sb;              /* associated superblock */
11982 +
11983 +       spinlock_t dl_lock;                     /* protect the values */
11984 +
11985 +       unsigned long long dl_space_used;       /* used space in bytes */
11986 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11987 +       unsigned long dl_inodes_used;           /* used inodes */
11988 +       unsigned long dl_inodes_total;          /* maximum inodes */
11989 +
11990 +       unsigned int dl_nrlmult;                /* non root limit mult */
11991 +};
11992 +
11993 +struct rcu_head;
11994 +
11995 +extern void rcu_free_dl_info(struct rcu_head *);
11996 +extern void unhash_dl_info(struct dl_info *);
11997 +
11998 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11999 +
12000 +
12001 +struct kstatfs;
12002 +
12003 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12004 +
12005 +typedef uint64_t dlsize_t;
12006 +
12007 +#endif /* __KERNEL__ */
12008 +#else  /* _VX_DLIMIT_H */
12009 +#warning duplicate inclusion
12010 +#endif /* _VX_DLIMIT_H */
12011 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/dlimit_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/dlimit_cmd.h
12012 --- linux-3.3.1/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12013 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/dlimit_cmd.h    2012-02-24 03:55:06.000000000 +0100
12014 @@ -0,0 +1,109 @@
12015 +#ifndef _VX_DLIMIT_CMD_H
12016 +#define _VX_DLIMIT_CMD_H
12017 +
12018 +
12019 +/*  dlimit vserver commands */
12020 +
12021 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12022 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12023 +
12024 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12025 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12026 +
12027 +struct vcmd_ctx_dlimit_base_v0 {
12028 +       const char __user *name;
12029 +       uint32_t flags;
12030 +};
12031 +
12032 +struct vcmd_ctx_dlimit_v0 {
12033 +       const char __user *name;
12034 +       uint32_t space_used;                    /* used space in kbytes */
12035 +       uint32_t space_total;                   /* maximum space in kbytes */
12036 +       uint32_t inodes_used;                   /* used inodes */
12037 +       uint32_t inodes_total;                  /* maximum inodes */
12038 +       uint32_t reserved;                      /* reserved for root in % */
12039 +       uint32_t flags;
12040 +};
12041 +
12042 +#define CDLIM_UNSET            ((uint32_t)0UL)
12043 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12044 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12045 +
12046 +#define DLIME_UNIT     0
12047 +#define DLIME_KILO     1
12048 +#define DLIME_MEGA     2
12049 +#define DLIME_GIGA     3
12050 +
12051 +#define DLIMF_SHIFT    0x10
12052 +
12053 +#define DLIMS_USED     0
12054 +#define DLIMS_TOTAL    2
12055 +
12056 +static inline
12057 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12058 +{
12059 +       int exp = (flags & DLIMF_SHIFT) ?
12060 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12061 +       return ((uint64_t)val) << (10 * exp);
12062 +}
12063 +
12064 +static inline
12065 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12066 +{
12067 +       int exp = 0;
12068 +
12069 +       if (*flags & DLIMF_SHIFT) {
12070 +               while (val > (1LL << 32) && (exp < 3)) {
12071 +                       val >>= 10;
12072 +                       exp++;
12073 +               }
12074 +               *flags &= ~(DLIME_GIGA << shift);
12075 +               *flags |= exp << shift;
12076 +       } else
12077 +               val >>= 10;
12078 +       return val;
12079 +}
12080 +
12081 +#ifdef __KERNEL__
12082 +
12083 +#ifdef CONFIG_COMPAT
12084 +
12085 +#include <asm/compat.h>
12086 +
12087 +struct vcmd_ctx_dlimit_base_v0_x32 {
12088 +       compat_uptr_t name_ptr;
12089 +       uint32_t flags;
12090 +};
12091 +
12092 +struct vcmd_ctx_dlimit_v0_x32 {
12093 +       compat_uptr_t name_ptr;
12094 +       uint32_t space_used;                    /* used space in kbytes */
12095 +       uint32_t space_total;                   /* maximum space in kbytes */
12096 +       uint32_t inodes_used;                   /* used inodes */
12097 +       uint32_t inodes_total;                  /* maximum inodes */
12098 +       uint32_t reserved;                      /* reserved for root in % */
12099 +       uint32_t flags;
12100 +};
12101 +
12102 +#endif /* CONFIG_COMPAT */
12103 +
12104 +#include <linux/compiler.h>
12105 +
12106 +extern int vc_add_dlimit(uint32_t, void __user *);
12107 +extern int vc_rem_dlimit(uint32_t, void __user *);
12108 +
12109 +extern int vc_set_dlimit(uint32_t, void __user *);
12110 +extern int vc_get_dlimit(uint32_t, void __user *);
12111 +
12112 +#ifdef CONFIG_COMPAT
12113 +
12114 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12115 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12116 +
12117 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12118 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12119 +
12120 +#endif /* CONFIG_COMPAT */
12121 +
12122 +#endif /* __KERNEL__ */
12123 +#endif /* _VX_DLIMIT_CMD_H */
12124 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/global.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/global.h
12125 --- linux-3.3.1/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12126 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/global.h        2012-02-24 03:55:06.000000000 +0100
12127 @@ -0,0 +1,19 @@
12128 +#ifndef _VX_GLOBAL_H
12129 +#define _VX_GLOBAL_H
12130 +
12131 +
12132 +extern atomic_t vx_global_ctotal;
12133 +extern atomic_t vx_global_cactive;
12134 +
12135 +extern atomic_t nx_global_ctotal;
12136 +extern atomic_t nx_global_cactive;
12137 +
12138 +extern atomic_t vs_global_nsproxy;
12139 +extern atomic_t vs_global_fs;
12140 +extern atomic_t vs_global_mnt_ns;
12141 +extern atomic_t vs_global_uts_ns;
12142 +extern atomic_t vs_global_user_ns;
12143 +extern atomic_t vs_global_pid_ns;
12144 +
12145 +
12146 +#endif /* _VX_GLOBAL_H */
12147 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/history.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/history.h
12148 --- linux-3.3.1/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12149 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/history.h       2012-02-24 03:55:06.000000000 +0100
12150 @@ -0,0 +1,197 @@
12151 +#ifndef _VX_HISTORY_H
12152 +#define _VX_HISTORY_H
12153 +
12154 +
12155 +enum {
12156 +       VXH_UNUSED = 0,
12157 +       VXH_THROW_OOPS = 1,
12158 +
12159 +       VXH_GET_VX_INFO,
12160 +       VXH_PUT_VX_INFO,
12161 +       VXH_INIT_VX_INFO,
12162 +       VXH_SET_VX_INFO,
12163 +       VXH_CLR_VX_INFO,
12164 +       VXH_CLAIM_VX_INFO,
12165 +       VXH_RELEASE_VX_INFO,
12166 +       VXH_ALLOC_VX_INFO,
12167 +       VXH_DEALLOC_VX_INFO,
12168 +       VXH_HASH_VX_INFO,
12169 +       VXH_UNHASH_VX_INFO,
12170 +       VXH_LOC_VX_INFO,
12171 +       VXH_LOOKUP_VX_INFO,
12172 +       VXH_CREATE_VX_INFO,
12173 +};
12174 +
12175 +struct _vxhe_vxi {
12176 +       struct vx_info *ptr;
12177 +       unsigned xid;
12178 +       unsigned usecnt;
12179 +       unsigned tasks;
12180 +};
12181 +
12182 +struct _vxhe_set_clr {
12183 +       void *data;
12184 +};
12185 +
12186 +struct _vxhe_loc_lookup {
12187 +       unsigned arg;
12188 +};
12189 +
12190 +struct _vx_hist_entry {
12191 +       void *loc;
12192 +       unsigned short seq;
12193 +       unsigned short type;
12194 +       struct _vxhe_vxi vxi;
12195 +       union {
12196 +               struct _vxhe_set_clr sc;
12197 +               struct _vxhe_loc_lookup ll;
12198 +       };
12199 +};
12200 +
12201 +#ifdef CONFIG_VSERVER_HISTORY
12202 +
12203 +extern unsigned volatile int vxh_active;
12204 +
12205 +struct _vx_hist_entry *vxh_advance(void *loc);
12206 +
12207 +
12208 +static inline
12209 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12210 +{
12211 +       entry->vxi.ptr = vxi;
12212 +       if (vxi) {
12213 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12214 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12215 +               entry->vxi.xid = vxi->vx_id;
12216 +       }
12217 +}
12218 +
12219 +
12220 +#define        __HERE__ current_text_addr()
12221 +
12222 +#define __VXH_BODY(__type, __data, __here)     \
12223 +       struct _vx_hist_entry *entry;           \
12224 +                                               \
12225 +       preempt_disable();                      \
12226 +       entry = vxh_advance(__here);            \
12227 +       __data;                                 \
12228 +       entry->type = __type;                   \
12229 +       preempt_enable();
12230 +
12231 +
12232 +       /* pass vxi only */
12233 +
12234 +#define __VXH_SMPL                             \
12235 +       __vxh_copy_vxi(entry, vxi)
12236 +
12237 +static inline
12238 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12239 +{
12240 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12241 +}
12242 +
12243 +       /* pass vxi and data (void *) */
12244 +
12245 +#define __VXH_DATA                             \
12246 +       __vxh_copy_vxi(entry, vxi);             \
12247 +       entry->sc.data = data
12248 +
12249 +static inline
12250 +void   __vxh_data(struct vx_info *vxi, void *data,
12251 +                       int __type, void *__here)
12252 +{
12253 +       __VXH_BODY(__type, __VXH_DATA, __here)
12254 +}
12255 +
12256 +       /* pass vxi and arg (long) */
12257 +
12258 +#define __VXH_LONG                             \
12259 +       __vxh_copy_vxi(entry, vxi);             \
12260 +       entry->ll.arg = arg
12261 +
12262 +static inline
12263 +void   __vxh_long(struct vx_info *vxi, long arg,
12264 +                       int __type, void *__here)
12265 +{
12266 +       __VXH_BODY(__type, __VXH_LONG, __here)
12267 +}
12268 +
12269 +
12270 +static inline
12271 +void   __vxh_throw_oops(void *__here)
12272 +{
12273 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12274 +       /* prevent further acquisition */
12275 +       vxh_active = 0;
12276 +}
12277 +
12278 +
12279 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12280 +
12281 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12282 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12283 +
12284 +#define __vxh_init_vx_info(v, d, h) \
12285 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12286 +#define __vxh_set_vx_info(v, d, h) \
12287 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12288 +#define __vxh_clr_vx_info(v, d, h) \
12289 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12290 +
12291 +#define __vxh_claim_vx_info(v, d, h) \
12292 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12293 +#define __vxh_release_vx_info(v, d, h) \
12294 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12295 +
12296 +#define vxh_alloc_vx_info(v) \
12297 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12298 +#define vxh_dealloc_vx_info(v) \
12299 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12300 +
12301 +#define vxh_hash_vx_info(v) \
12302 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12303 +#define vxh_unhash_vx_info(v) \
12304 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12305 +
12306 +#define vxh_loc_vx_info(v, l) \
12307 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12308 +#define vxh_lookup_vx_info(v, l) \
12309 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12310 +#define vxh_create_vx_info(v, l) \
12311 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12312 +
12313 +extern void vxh_dump_history(void);
12314 +
12315 +
12316 +#else  /* CONFIG_VSERVER_HISTORY */
12317 +
12318 +#define        __HERE__        0
12319 +
12320 +#define vxh_throw_oops()               do { } while (0)
12321 +
12322 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12323 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12324 +
12325 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12326 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12327 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12328 +
12329 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12330 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12331 +
12332 +#define vxh_alloc_vx_info(v)           do { } while (0)
12333 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12334 +
12335 +#define vxh_hash_vx_info(v)            do { } while (0)
12336 +#define vxh_unhash_vx_info(v)          do { } while (0)
12337 +
12338 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12339 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12340 +#define vxh_create_vx_info(v, l)       do { } while (0)
12341 +
12342 +#define vxh_dump_history()             do { } while (0)
12343 +
12344 +
12345 +#endif /* CONFIG_VSERVER_HISTORY */
12346 +
12347 +#endif /* _VX_HISTORY_H */
12348 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/inode.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/inode.h
12349 --- linux-3.3.1/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12350 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/inode.h 2012-02-24 03:55:06.000000000 +0100
12351 @@ -0,0 +1,39 @@
12352 +#ifndef _VX_INODE_H
12353 +#define _VX_INODE_H
12354 +
12355 +
12356 +#define IATTR_TAG      0x01000000
12357 +
12358 +#define IATTR_ADMIN    0x00000001
12359 +#define IATTR_WATCH    0x00000002
12360 +#define IATTR_HIDE     0x00000004
12361 +#define IATTR_FLAGS    0x00000007
12362 +
12363 +#define IATTR_BARRIER  0x00010000
12364 +#define IATTR_IXUNLINK 0x00020000
12365 +#define IATTR_IMMUTABLE 0x00040000
12366 +#define IATTR_COW      0x00080000
12367 +
12368 +#ifdef __KERNEL__
12369 +
12370 +
12371 +#ifdef CONFIG_VSERVER_PROC_SECURE
12372 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12373 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12374 +#else
12375 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12376 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12377 +#endif
12378 +
12379 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12380 +
12381 +#endif /* __KERNEL__ */
12382 +
12383 +/* inode ioctls */
12384 +
12385 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12386 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12387 +
12388 +#else  /* _VX_INODE_H */
12389 +#warning duplicate inclusion
12390 +#endif /* _VX_INODE_H */
12391 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/inode_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/inode_cmd.h
12392 --- linux-3.3.1/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12393 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/inode_cmd.h     2012-02-24 03:55:06.000000000 +0100
12394 @@ -0,0 +1,59 @@
12395 +#ifndef _VX_INODE_CMD_H
12396 +#define _VX_INODE_CMD_H
12397 +
12398 +
12399 +/*  inode vserver commands */
12400 +
12401 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12402 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12403 +
12404 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12405 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12406 +
12407 +struct vcmd_ctx_iattr_v1 {
12408 +       const char __user *name;
12409 +       uint32_t tag;
12410 +       uint32_t flags;
12411 +       uint32_t mask;
12412 +};
12413 +
12414 +struct vcmd_ctx_fiattr_v0 {
12415 +       uint32_t tag;
12416 +       uint32_t flags;
12417 +       uint32_t mask;
12418 +};
12419 +
12420 +
12421 +#ifdef __KERNEL__
12422 +
12423 +
12424 +#ifdef CONFIG_COMPAT
12425 +
12426 +#include <asm/compat.h>
12427 +
12428 +struct vcmd_ctx_iattr_v1_x32 {
12429 +       compat_uptr_t name_ptr;
12430 +       uint32_t tag;
12431 +       uint32_t flags;
12432 +       uint32_t mask;
12433 +};
12434 +
12435 +#endif /* CONFIG_COMPAT */
12436 +
12437 +#include <linux/compiler.h>
12438 +
12439 +extern int vc_get_iattr(void __user *);
12440 +extern int vc_set_iattr(void __user *);
12441 +
12442 +extern int vc_fget_iattr(uint32_t, void __user *);
12443 +extern int vc_fset_iattr(uint32_t, void __user *);
12444 +
12445 +#ifdef CONFIG_COMPAT
12446 +
12447 +extern int vc_get_iattr_x32(void __user *);
12448 +extern int vc_set_iattr_x32(void __user *);
12449 +
12450 +#endif /* CONFIG_COMPAT */
12451 +
12452 +#endif /* __KERNEL__ */
12453 +#endif /* _VX_INODE_CMD_H */
12454 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/limit.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit.h
12455 --- linux-3.3.1/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12456 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit.h 2012-02-24 03:55:06.000000000 +0100
12457 @@ -0,0 +1,71 @@
12458 +#ifndef _VX_LIMIT_H
12459 +#define _VX_LIMIT_H
12460 +
12461 +#define VLIMIT_NSOCK   16
12462 +#define VLIMIT_OPENFD  17
12463 +#define VLIMIT_ANON    18
12464 +#define VLIMIT_SHMEM   19
12465 +#define VLIMIT_SEMARY  20
12466 +#define VLIMIT_NSEMS   21
12467 +#define VLIMIT_DENTRY  22
12468 +#define VLIMIT_MAPPED  23
12469 +
12470 +
12471 +#ifdef __KERNEL__
12472 +
12473 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12474 +
12475 +/*     keep in sync with CRLIM_INFINITY */
12476 +
12477 +#define        VLIM_INFINITY   (~0ULL)
12478 +
12479 +#include <asm/atomic.h>
12480 +#include <asm/resource.h>
12481 +
12482 +#ifndef RLIM_INFINITY
12483 +#warning RLIM_INFINITY is undefined
12484 +#endif
12485 +
12486 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12487 +
12488 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12489 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12490 +
12491 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12492 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12493 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12494 +
12495 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12496 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12497 +
12498 +typedef atomic_long_t rlim_atomic_t;
12499 +typedef unsigned long rlim_t;
12500 +
12501 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12502 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12503 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12504 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12505 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12506 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12507 +
12508 +
12509 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12510 +#define        VX_VLIM(r) ((long long)(long)(r))
12511 +#define        VX_RLIM(v) ((rlim_t)(v))
12512 +#else
12513 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12514 +               ? VLIM_INFINITY : (long long)(r))
12515 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12516 +               ? RLIM_INFINITY : (rlim_t)(v))
12517 +#endif
12518 +
12519 +struct sysinfo;
12520 +
12521 +void vx_vsi_meminfo(struct sysinfo *);
12522 +void vx_vsi_swapinfo(struct sysinfo *);
12523 +long vx_vsi_cached(struct sysinfo *);
12524 +
12525 +#define NUM_LIMITS     24
12526 +
12527 +#endif /* __KERNEL__ */
12528 +#endif /* _VX_LIMIT_H */
12529 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/limit_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit_cmd.h
12530 --- linux-3.3.1/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12531 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit_cmd.h     2012-02-24 03:55:06.000000000 +0100
12532 @@ -0,0 +1,71 @@
12533 +#ifndef _VX_LIMIT_CMD_H
12534 +#define _VX_LIMIT_CMD_H
12535 +
12536 +
12537 +/*  rlimit vserver commands */
12538 +
12539 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12540 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12541 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12542 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12543 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12544 +
12545 +struct vcmd_ctx_rlimit_v0 {
12546 +       uint32_t id;
12547 +       uint64_t minimum;
12548 +       uint64_t softlimit;
12549 +       uint64_t maximum;
12550 +};
12551 +
12552 +struct vcmd_ctx_rlimit_mask_v0 {
12553 +       uint32_t minimum;
12554 +       uint32_t softlimit;
12555 +       uint32_t maximum;
12556 +};
12557 +
12558 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12559 +
12560 +struct vcmd_rlimit_stat_v0 {
12561 +       uint32_t id;
12562 +       uint32_t hits;
12563 +       uint64_t value;
12564 +       uint64_t minimum;
12565 +       uint64_t maximum;
12566 +};
12567 +
12568 +#define CRLIM_UNSET            (0ULL)
12569 +#define CRLIM_INFINITY         (~0ULL)
12570 +#define CRLIM_KEEP             (~1ULL)
12571 +
12572 +#ifdef __KERNEL__
12573 +
12574 +#ifdef CONFIG_IA32_EMULATION
12575 +
12576 +struct vcmd_ctx_rlimit_v0_x32 {
12577 +       uint32_t id;
12578 +       uint64_t minimum;
12579 +       uint64_t softlimit;
12580 +       uint64_t maximum;
12581 +} __attribute__ ((packed));
12582 +
12583 +#endif /* CONFIG_IA32_EMULATION */
12584 +
12585 +#include <linux/compiler.h>
12586 +
12587 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12588 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12589 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12590 +extern int vc_reset_hits(struct vx_info *, void __user *);
12591 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12592 +
12593 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12594 +
12595 +#ifdef CONFIG_IA32_EMULATION
12596 +
12597 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12598 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12599 +
12600 +#endif /* CONFIG_IA32_EMULATION */
12601 +
12602 +#endif /* __KERNEL__ */
12603 +#endif /* _VX_LIMIT_CMD_H */
12604 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/limit_def.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit_def.h
12605 --- linux-3.3.1/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12606 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit_def.h     2012-02-24 03:55:06.000000000 +0100
12607 @@ -0,0 +1,47 @@
12608 +#ifndef _VX_LIMIT_DEF_H
12609 +#define _VX_LIMIT_DEF_H
12610 +
12611 +#include <asm/atomic.h>
12612 +#include <asm/resource.h>
12613 +
12614 +#include "limit.h"
12615 +
12616 +
12617 +struct _vx_res_limit {
12618 +       rlim_t soft;            /* Context soft limit */
12619 +       rlim_t hard;            /* Context hard limit */
12620 +
12621 +       rlim_atomic_t rcur;     /* Current value */
12622 +       rlim_t rmin;            /* Context minimum */
12623 +       rlim_t rmax;            /* Context maximum */
12624 +
12625 +       atomic_t lhit;          /* Limit hits */
12626 +};
12627 +
12628 +/* context sub struct */
12629 +
12630 +struct _vx_limit {
12631 +       struct _vx_res_limit res[NUM_LIMITS];
12632 +};
12633 +
12634 +#ifdef CONFIG_VSERVER_DEBUG
12635 +
12636 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12637 +{
12638 +       int i;
12639 +
12640 +       printk("\t_vx_limit:");
12641 +       for (i = 0; i < NUM_LIMITS; i++) {
12642 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12643 +                       i, (unsigned long)__rlim_get(limit, i),
12644 +                       (unsigned long)__rlim_rmin(limit, i),
12645 +                       (unsigned long)__rlim_rmax(limit, i),
12646 +                       (long)__rlim_soft(limit, i),
12647 +                       (long)__rlim_hard(limit, i),
12648 +                       atomic_read(&__rlim_lhit(limit, i)));
12649 +       }
12650 +}
12651 +
12652 +#endif
12653 +
12654 +#endif /* _VX_LIMIT_DEF_H */
12655 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/limit_int.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit_int.h
12656 --- linux-3.3.1/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12657 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/limit_int.h     2012-02-24 03:55:06.000000000 +0100
12658 @@ -0,0 +1,198 @@
12659 +#ifndef _VX_LIMIT_INT_H
12660 +#define _VX_LIMIT_INT_H
12661 +
12662 +#include "context.h"
12663 +
12664 +#ifdef __KERNEL__
12665 +
12666 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12667 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12668 +
12669 +extern const char *vlimit_name[NUM_LIMITS];
12670 +
12671 +static inline void __vx_acc_cres(struct vx_info *vxi,
12672 +       int res, int dir, void *_data, char *_file, int _line)
12673 +{
12674 +       if (VXD_RCRES_COND(res))
12675 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12676 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12677 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12678 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12679 +       if (!vxi)
12680 +               return;
12681 +
12682 +       if (dir > 0)
12683 +               __rlim_inc(&vxi->limit, res);
12684 +       else
12685 +               __rlim_dec(&vxi->limit, res);
12686 +}
12687 +
12688 +static inline void __vx_add_cres(struct vx_info *vxi,
12689 +       int res, int amount, void *_data, char *_file, int _line)
12690 +{
12691 +       if (VXD_RCRES_COND(res))
12692 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12693 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12694 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12695 +                       amount, _data, _file, _line);
12696 +       if (amount == 0)
12697 +               return;
12698 +       if (!vxi)
12699 +               return;
12700 +       __rlim_add(&vxi->limit, res, amount);
12701 +}
12702 +
12703 +static inline
12704 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12705 +{
12706 +       int cond = (value > __rlim_rmax(limit, res));
12707 +
12708 +       if (cond)
12709 +               __rlim_rmax(limit, res) = value;
12710 +       return cond;
12711 +}
12712 +
12713 +static inline
12714 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12715 +{
12716 +       int cond = (value < __rlim_rmin(limit, res));
12717 +
12718 +       if (cond)
12719 +               __rlim_rmin(limit, res) = value;
12720 +       return cond;
12721 +}
12722 +
12723 +static inline
12724 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12725 +{
12726 +       if (!__vx_cres_adjust_max(limit, res, value))
12727 +               __vx_cres_adjust_min(limit, res, value);
12728 +}
12729 +
12730 +
12731 +/*     return values:
12732 +        +1 ... no limit hit
12733 +        -1 ... over soft limit
12734 +         0 ... over hard limit         */
12735 +
12736 +static inline int __vx_cres_avail(struct vx_info *vxi,
12737 +       int res, int num, char *_file, int _line)
12738 +{
12739 +       struct _vx_limit *limit;
12740 +       rlim_t value;
12741 +
12742 +       if (VXD_RLIMIT_COND(res))
12743 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12744 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12745 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12746 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12747 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12748 +                       num, _file, _line);
12749 +       if (!vxi)
12750 +               return 1;
12751 +
12752 +       limit = &vxi->limit;
12753 +       value = __rlim_get(limit, res);
12754 +
12755 +       if (!__vx_cres_adjust_max(limit, res, value))
12756 +               __vx_cres_adjust_min(limit, res, value);
12757 +
12758 +       if (num == 0)
12759 +               return 1;
12760 +
12761 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12762 +               return -1;
12763 +       if (value + num <= __rlim_soft(limit, res))
12764 +               return -1;
12765 +
12766 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12767 +               return 1;
12768 +       if (value + num <= __rlim_hard(limit, res))
12769 +               return 1;
12770 +
12771 +       __rlim_hit(limit, res);
12772 +       return 0;
12773 +}
12774 +
12775 +
12776 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12777 +
12778 +static inline
12779 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12780 +{
12781 +       rlim_t value, sum = 0;
12782 +       int res;
12783 +
12784 +       while ((res = *array++)) {
12785 +               value = __rlim_get(limit, res);
12786 +               __vx_cres_fixup(limit, res, value);
12787 +               sum += value;
12788 +       }
12789 +       return sum;
12790 +}
12791 +
12792 +static inline
12793 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12794 +{
12795 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12796 +       int res = *array;
12797 +
12798 +       if (value == __rlim_get(limit, res))
12799 +               return value;
12800 +
12801 +       __rlim_set(limit, res, value);
12802 +       /* now adjust min/max */
12803 +       if (!__vx_cres_adjust_max(limit, res, value))
12804 +               __vx_cres_adjust_min(limit, res, value);
12805 +
12806 +       return value;
12807 +}
12808 +
12809 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12810 +       const int *array, int num, char *_file, int _line)
12811 +{
12812 +       struct _vx_limit *limit;
12813 +       rlim_t value = 0;
12814 +       int res;
12815 +
12816 +       if (num == 0)
12817 +               return 1;
12818 +       if (!vxi)
12819 +               return 1;
12820 +
12821 +       limit = &vxi->limit;
12822 +       res = *array;
12823 +       value = __vx_cres_array_sum(limit, array + 1);
12824 +
12825 +       __rlim_set(limit, res, value);
12826 +       __vx_cres_fixup(limit, res, value);
12827 +
12828 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12829 +}
12830 +
12831 +
12832 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12833 +{
12834 +       rlim_t value;
12835 +       int res;
12836 +
12837 +       /* complex resources first */
12838 +       if ((id < 0) || (id == RLIMIT_RSS))
12839 +               __vx_cres_array_fixup(limit, VLA_RSS);
12840 +
12841 +       for (res = 0; res < NUM_LIMITS; res++) {
12842 +               if ((id > 0) && (res != id))
12843 +                       continue;
12844 +
12845 +               value = __rlim_get(limit, res);
12846 +               __vx_cres_fixup(limit, res, value);
12847 +
12848 +               /* not supposed to happen, maybe warn? */
12849 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12850 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12851 +       }
12852 +}
12853 +
12854 +
12855 +#endif /* __KERNEL__ */
12856 +#endif /* _VX_LIMIT_INT_H */
12857 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/monitor.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/monitor.h
12858 --- linux-3.3.1/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12859 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/monitor.h       2012-02-24 03:55:06.000000000 +0100
12860 @@ -0,0 +1,96 @@
12861 +#ifndef _VX_MONITOR_H
12862 +#define _VX_MONITOR_H
12863 +
12864 +#include <linux/types.h>
12865 +
12866 +enum {
12867 +       VXM_UNUSED = 0,
12868 +
12869 +       VXM_SYNC = 0x10,
12870 +
12871 +       VXM_UPDATE = 0x20,
12872 +       VXM_UPDATE_1,
12873 +       VXM_UPDATE_2,
12874 +
12875 +       VXM_RQINFO_1 = 0x24,
12876 +       VXM_RQINFO_2,
12877 +
12878 +       VXM_ACTIVATE = 0x40,
12879 +       VXM_DEACTIVATE,
12880 +       VXM_IDLE,
12881 +
12882 +       VXM_HOLD = 0x44,
12883 +       VXM_UNHOLD,
12884 +
12885 +       VXM_MIGRATE = 0x48,
12886 +       VXM_RESCHED,
12887 +
12888 +       /* all other bits are flags */
12889 +       VXM_SCHED = 0x80,
12890 +};
12891 +
12892 +struct _vxm_update_1 {
12893 +       uint32_t tokens_max;
12894 +       uint32_t fill_rate;
12895 +       uint32_t interval;
12896 +};
12897 +
12898 +struct _vxm_update_2 {
12899 +       uint32_t tokens_min;
12900 +       uint32_t fill_rate;
12901 +       uint32_t interval;
12902 +};
12903 +
12904 +struct _vxm_rqinfo_1 {
12905 +       uint16_t running;
12906 +       uint16_t onhold;
12907 +       uint16_t iowait;
12908 +       uint16_t uintr;
12909 +       uint32_t idle_tokens;
12910 +};
12911 +
12912 +struct _vxm_rqinfo_2 {
12913 +       uint32_t norm_time;
12914 +       uint32_t idle_time;
12915 +       uint32_t idle_skip;
12916 +};
12917 +
12918 +struct _vxm_sched {
12919 +       uint32_t tokens;
12920 +       uint32_t norm_time;
12921 +       uint32_t idle_time;
12922 +};
12923 +
12924 +struct _vxm_task {
12925 +       uint16_t pid;
12926 +       uint16_t state;
12927 +};
12928 +
12929 +struct _vxm_event {
12930 +       uint32_t jif;
12931 +       union {
12932 +               uint32_t seq;
12933 +               uint32_t sec;
12934 +       };
12935 +       union {
12936 +               uint32_t tokens;
12937 +               uint32_t nsec;
12938 +               struct _vxm_task tsk;
12939 +       };
12940 +};
12941 +
12942 +struct _vx_mon_entry {
12943 +       uint16_t type;
12944 +       uint16_t xid;
12945 +       union {
12946 +               struct _vxm_event ev;
12947 +               struct _vxm_sched sd;
12948 +               struct _vxm_update_1 u1;
12949 +               struct _vxm_update_2 u2;
12950 +               struct _vxm_rqinfo_1 q1;
12951 +               struct _vxm_rqinfo_2 q2;
12952 +       };
12953 +};
12954 +
12955 +
12956 +#endif /* _VX_MONITOR_H */
12957 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/network.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/network.h
12958 --- linux-3.3.1/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
12959 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/network.h       2012-02-24 03:55:06.000000000 +0100
12960 @@ -0,0 +1,148 @@
12961 +#ifndef _VX_NETWORK_H
12962 +#define _VX_NETWORK_H
12963 +
12964 +#include <linux/types.h>
12965 +
12966 +
12967 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12968 +
12969 +
12970 +/* network flags */
12971 +
12972 +#define NXF_INFO_PRIVATE       0x00000008
12973 +
12974 +#define NXF_SINGLE_IP          0x00000100
12975 +#define NXF_LBACK_REMAP                0x00000200
12976 +#define NXF_LBACK_ALLOW                0x00000400
12977 +
12978 +#define NXF_HIDE_NETIF         0x02000000
12979 +#define NXF_HIDE_LBACK         0x04000000
12980 +
12981 +#define NXF_STATE_SETUP                (1ULL << 32)
12982 +#define NXF_STATE_ADMIN                (1ULL << 34)
12983 +
12984 +#define NXF_SC_HELPER          (1ULL << 36)
12985 +#define NXF_PERSISTENT         (1ULL << 38)
12986 +
12987 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12988 +
12989 +
12990 +#define        NXF_INIT_SET            (__nxf_init_set())
12991 +
12992 +static inline uint64_t __nxf_init_set(void) {
12993 +       return    NXF_STATE_ADMIN
12994 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12995 +               | NXF_LBACK_REMAP
12996 +               | NXF_HIDE_LBACK
12997 +#endif
12998 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12999 +               | NXF_SINGLE_IP
13000 +#endif
13001 +               | NXF_HIDE_NETIF;
13002 +}
13003 +
13004 +
13005 +/* network caps */
13006 +
13007 +#define NXC_TUN_CREATE         0x00000001
13008 +
13009 +#define NXC_RAW_ICMP           0x00000100
13010 +
13011 +#define NXC_MULTICAST          0x00001000
13012 +
13013 +
13014 +/* address types */
13015 +
13016 +#define NXA_TYPE_IPV4          0x0001
13017 +#define NXA_TYPE_IPV6          0x0002
13018 +
13019 +#define NXA_TYPE_NONE          0x0000
13020 +#define NXA_TYPE_ANY           0x00FF
13021 +
13022 +#define NXA_TYPE_ADDR          0x0010
13023 +#define NXA_TYPE_MASK          0x0020
13024 +#define NXA_TYPE_RANGE         0x0040
13025 +
13026 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13027 +
13028 +#define NXA_MOD_BCAST          0x0100
13029 +#define NXA_MOD_LBACK          0x0200
13030 +
13031 +#define NXA_LOOPBACK           0x1000
13032 +
13033 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13034 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13035 +
13036 +#ifdef __KERNEL__
13037 +
13038 +#include <linux/list.h>
13039 +#include <linux/spinlock.h>
13040 +#include <linux/rcupdate.h>
13041 +#include <linux/in.h>
13042 +#include <linux/in6.h>
13043 +#include <asm/atomic.h>
13044 +
13045 +struct nx_addr_v4 {
13046 +       struct nx_addr_v4 *next;
13047 +       struct in_addr ip[2];
13048 +       struct in_addr mask;
13049 +       uint16_t type;
13050 +       uint16_t flags;
13051 +};
13052 +
13053 +struct nx_addr_v6 {
13054 +       struct nx_addr_v6 *next;
13055 +       struct in6_addr ip;
13056 +       struct in6_addr mask;
13057 +       uint32_t prefix;
13058 +       uint16_t type;
13059 +       uint16_t flags;
13060 +};
13061 +
13062 +struct nx_info {
13063 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13064 +       nid_t nx_id;                    /* vnet id */
13065 +       atomic_t nx_usecnt;             /* usage count */
13066 +       atomic_t nx_tasks;              /* tasks count */
13067 +       int nx_state;                   /* context state */
13068 +
13069 +       uint64_t nx_flags;              /* network flag word */
13070 +       uint64_t nx_ncaps;              /* network capabilities */
13071 +
13072 +       struct in_addr v4_lback;        /* Loopback address */
13073 +       struct in_addr v4_bcast;        /* Broadcast address */
13074 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13075 +#ifdef CONFIG_IPV6
13076 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13077 +#endif
13078 +       char nx_name[65];               /* network context name */
13079 +};
13080 +
13081 +
13082 +/* status flags */
13083 +
13084 +#define NXS_HASHED      0x0001
13085 +#define NXS_SHUTDOWN    0x0100
13086 +#define NXS_RELEASED    0x8000
13087 +
13088 +extern struct nx_info *lookup_nx_info(int);
13089 +
13090 +extern int get_nid_list(int, unsigned int *, int);
13091 +extern int nid_is_hashed(nid_t);
13092 +
13093 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13094 +
13095 +extern long vs_net_change(struct nx_info *, unsigned int);
13096 +
13097 +struct sock;
13098 +
13099 +
13100 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13101 +#ifdef  CONFIG_IPV6
13102 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13103 +#else
13104 +#define NX_IPV6(n)     (0)
13105 +#endif
13106 +
13107 +#endif /* __KERNEL__ */
13108 +#endif /* _VX_NETWORK_H */
13109 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/network_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/network_cmd.h
13110 --- linux-3.3.1/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13111 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/network_cmd.h   2012-02-24 03:55:06.000000000 +0100
13112 @@ -0,0 +1,164 @@
13113 +#ifndef _VX_NETWORK_CMD_H
13114 +#define _VX_NETWORK_CMD_H
13115 +
13116 +
13117 +/* vinfo commands */
13118 +
13119 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13120 +
13121 +#ifdef __KERNEL__
13122 +extern int vc_task_nid(uint32_t);
13123 +
13124 +#endif /* __KERNEL__ */
13125 +
13126 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13127 +
13128 +struct vcmd_nx_info_v0 {
13129 +       uint32_t nid;
13130 +       /* more to come */
13131 +};
13132 +
13133 +#ifdef __KERNEL__
13134 +extern int vc_nx_info(struct nx_info *, void __user *);
13135 +
13136 +#endif /* __KERNEL__ */
13137 +
13138 +#include <linux/in.h>
13139 +#include <linux/in6.h>
13140 +
13141 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13142 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13143 +
13144 +struct  vcmd_net_create {
13145 +       uint64_t flagword;
13146 +};
13147 +
13148 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13149 +
13150 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13151 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13152 +
13153 +struct vcmd_net_addr_v0 {
13154 +       uint16_t type;
13155 +       uint16_t count;
13156 +       struct in_addr ip[4];
13157 +       struct in_addr mask[4];
13158 +};
13159 +
13160 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13161 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13162 +
13163 +struct vcmd_net_addr_ipv4_v1 {
13164 +       uint16_t type;
13165 +       uint16_t flags;
13166 +       struct in_addr ip;
13167 +       struct in_addr mask;
13168 +};
13169 +
13170 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13171 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13172 +
13173 +struct vcmd_net_addr_ipv4_v2 {
13174 +       uint16_t type;
13175 +       uint16_t flags;
13176 +       struct in_addr ip;
13177 +       struct in_addr ip2;
13178 +       struct in_addr mask;
13179 +};
13180 +
13181 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13182 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13183 +
13184 +struct vcmd_net_addr_ipv6_v1 {
13185 +       uint16_t type;
13186 +       uint16_t flags;
13187 +       uint32_t prefix;
13188 +       struct in6_addr ip;
13189 +       struct in6_addr mask;
13190 +};
13191 +
13192 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13193 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13194 +
13195 +struct vcmd_match_ipv4_v0 {
13196 +       uint16_t type;
13197 +       uint16_t flags;
13198 +       uint16_t parent;
13199 +       uint16_t prefix;
13200 +       struct in_addr ip;
13201 +       struct in_addr ip2;
13202 +       struct in_addr mask;
13203 +};
13204 +
13205 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13206 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13207 +
13208 +struct vcmd_match_ipv6_v0 {
13209 +       uint16_t type;
13210 +       uint16_t flags;
13211 +       uint16_t parent;
13212 +       uint16_t prefix;
13213 +       struct in6_addr ip;
13214 +       struct in6_addr ip2;
13215 +       struct in6_addr mask;
13216 +};
13217 +
13218 +
13219 +#ifdef __KERNEL__
13220 +extern int vc_net_create(uint32_t, void __user *);
13221 +extern int vc_net_migrate(struct nx_info *, void __user *);
13222 +
13223 +extern int vc_net_add(struct nx_info *, void __user *);
13224 +extern int vc_net_remove(struct nx_info *, void __user *);
13225 +
13226 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13227 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13228 +
13229 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13230 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13231 +
13232 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13233 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13234 +
13235 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13236 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13237 +
13238 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13239 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13240 +
13241 +#endif /* __KERNEL__ */
13242 +
13243 +
13244 +/* flag commands */
13245 +
13246 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13247 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13248 +
13249 +struct vcmd_net_flags_v0 {
13250 +       uint64_t flagword;
13251 +       uint64_t mask;
13252 +};
13253 +
13254 +#ifdef __KERNEL__
13255 +extern int vc_get_nflags(struct nx_info *, void __user *);
13256 +extern int vc_set_nflags(struct nx_info *, void __user *);
13257 +
13258 +#endif /* __KERNEL__ */
13259 +
13260 +
13261 +/* network caps commands */
13262 +
13263 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13264 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13265 +
13266 +struct vcmd_net_caps_v0 {
13267 +       uint64_t ncaps;
13268 +       uint64_t cmask;
13269 +};
13270 +
13271 +#ifdef __KERNEL__
13272 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13273 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13274 +
13275 +#endif /* __KERNEL__ */
13276 +#endif /* _VX_CONTEXT_CMD_H */
13277 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/percpu.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/percpu.h
13278 --- linux-3.3.1/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13279 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/percpu.h        2012-02-24 03:55:06.000000000 +0100
13280 @@ -0,0 +1,14 @@
13281 +#ifndef _VX_PERCPU_H
13282 +#define _VX_PERCPU_H
13283 +
13284 +#include "cvirt_def.h"
13285 +#include "sched_def.h"
13286 +
13287 +struct _vx_percpu {
13288 +       struct _vx_cvirt_pc cvirt;
13289 +       struct _vx_sched_pc sched;
13290 +};
13291 +
13292 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13293 +
13294 +#endif /* _VX_PERCPU_H */
13295 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/pid.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/pid.h
13296 --- linux-3.3.1/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13297 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/pid.h   2012-02-24 03:55:06.000000000 +0100
13298 @@ -0,0 +1,51 @@
13299 +#ifndef _VSERVER_PID_H
13300 +#define _VSERVER_PID_H
13301 +
13302 +/* pid faking stuff */
13303 +
13304 +#define vx_info_map_pid(v, p) \
13305 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13306 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13307 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13308 +#define vx_map_tgid(p) vx_map_pid(p)
13309 +
13310 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13311 +       const char *func, const char *file, int line)
13312 +{
13313 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13314 +               vxfprintk(VXD_CBIT(cvirt, 2),
13315 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13316 +                       vxi, (long long)vxi->vx_flags, pid,
13317 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13318 +                       func, file, line);
13319 +               if (pid == 0)
13320 +                       return 0;
13321 +               if (pid == vxi->vx_initpid)
13322 +                       return 1;
13323 +       }
13324 +       return pid;
13325 +}
13326 +
13327 +#define vx_info_rmap_pid(v, p) \
13328 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13329 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13330 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13331 +
13332 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13333 +       const char *func, const char *file, int line)
13334 +{
13335 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13336 +               vxfprintk(VXD_CBIT(cvirt, 2),
13337 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13338 +                       vxi, (long long)vxi->vx_flags, pid,
13339 +                       (pid == 1) ? vxi->vx_initpid : pid,
13340 +                       func, file, line);
13341 +               if ((pid == 1) && vxi->vx_initpid)
13342 +                       return vxi->vx_initpid;
13343 +               if (pid == vxi->vx_initpid)
13344 +                       return ~0U;
13345 +       }
13346 +       return pid;
13347 +}
13348 +
13349 +#endif
13350 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/sched.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/sched.h
13351 --- linux-3.3.1/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13352 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/sched.h 2012-02-24 03:55:06.000000000 +0100
13353 @@ -0,0 +1,23 @@
13354 +#ifndef _VX_SCHED_H
13355 +#define _VX_SCHED_H
13356 +
13357 +
13358 +#ifdef __KERNEL__
13359 +
13360 +struct timespec;
13361 +
13362 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13363 +
13364 +
13365 +struct vx_info;
13366 +
13367 +void vx_update_load(struct vx_info *);
13368 +
13369 +
13370 +void vx_update_sched_param(struct _vx_sched *sched,
13371 +       struct _vx_sched_pc *sched_pc);
13372 +
13373 +#endif /* __KERNEL__ */
13374 +#else  /* _VX_SCHED_H */
13375 +#warning duplicate inclusion
13376 +#endif /* _VX_SCHED_H */
13377 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/sched_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/sched_cmd.h
13378 --- linux-3.3.1/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13379 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/sched_cmd.h     2012-02-24 03:55:06.000000000 +0100
13380 @@ -0,0 +1,21 @@
13381 +#ifndef _VX_SCHED_CMD_H
13382 +#define _VX_SCHED_CMD_H
13383 +
13384 +
13385 +struct vcmd_prio_bias {
13386 +       int32_t cpu_id;
13387 +       int32_t prio_bias;
13388 +};
13389 +
13390 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13391 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13392 +
13393 +#ifdef __KERNEL__
13394 +
13395 +#include <linux/compiler.h>
13396 +
13397 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13398 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13399 +
13400 +#endif /* __KERNEL__ */
13401 +#endif /* _VX_SCHED_CMD_H */
13402 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/sched_def.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/sched_def.h
13403 --- linux-3.3.1/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13404 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/sched_def.h     2012-02-24 03:55:06.000000000 +0100
13405 @@ -0,0 +1,38 @@
13406 +#ifndef _VX_SCHED_DEF_H
13407 +#define _VX_SCHED_DEF_H
13408 +
13409 +#include <linux/spinlock.h>
13410 +#include <linux/jiffies.h>
13411 +#include <linux/cpumask.h>
13412 +#include <asm/atomic.h>
13413 +#include <asm/param.h>
13414 +
13415 +
13416 +/* context sub struct */
13417 +
13418 +struct _vx_sched {
13419 +       int prio_bias;                  /* bias offset for priority */
13420 +
13421 +       cpumask_t update;               /* CPUs which should update */
13422 +};
13423 +
13424 +struct _vx_sched_pc {
13425 +       int prio_bias;                  /* bias offset for priority */
13426 +
13427 +       uint64_t user_ticks;            /* token tick events */
13428 +       uint64_t sys_ticks;             /* token tick events */
13429 +       uint64_t hold_ticks;            /* token ticks paused */
13430 +};
13431 +
13432 +
13433 +#ifdef CONFIG_VSERVER_DEBUG
13434 +
13435 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13436 +{
13437 +       printk("\t_vx_sched:\n");
13438 +       printk("\t priority = %4d\n", sched->prio_bias);
13439 +}
13440 +
13441 +#endif
13442 +
13443 +#endif /* _VX_SCHED_DEF_H */
13444 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/signal.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/signal.h
13445 --- linux-3.3.1/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13446 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/signal.h        2012-02-24 03:55:06.000000000 +0100
13447 @@ -0,0 +1,14 @@
13448 +#ifndef _VX_SIGNAL_H
13449 +#define _VX_SIGNAL_H
13450 +
13451 +
13452 +#ifdef __KERNEL__
13453 +
13454 +struct vx_info;
13455 +
13456 +int vx_info_kill(struct vx_info *, int, int);
13457 +
13458 +#endif /* __KERNEL__ */
13459 +#else  /* _VX_SIGNAL_H */
13460 +#warning duplicate inclusion
13461 +#endif /* _VX_SIGNAL_H */
13462 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/signal_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/signal_cmd.h
13463 --- linux-3.3.1/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13464 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/signal_cmd.h    2012-02-24 03:55:06.000000000 +0100
13465 @@ -0,0 +1,43 @@
13466 +#ifndef _VX_SIGNAL_CMD_H
13467 +#define _VX_SIGNAL_CMD_H
13468 +
13469 +
13470 +/*  signalling vserver commands */
13471 +
13472 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13473 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13474 +
13475 +struct vcmd_ctx_kill_v0 {
13476 +       int32_t pid;
13477 +       int32_t sig;
13478 +};
13479 +
13480 +struct vcmd_wait_exit_v0 {
13481 +       int32_t reboot_cmd;
13482 +       int32_t exit_code;
13483 +};
13484 +
13485 +#ifdef __KERNEL__
13486 +
13487 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13488 +extern int vc_wait_exit(struct vx_info *, void __user *);
13489 +
13490 +#endif /* __KERNEL__ */
13491 +
13492 +/*  process alteration commands */
13493 +
13494 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13495 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13496 +
13497 +struct vcmd_pflags_v0 {
13498 +       uint32_t flagword;
13499 +       uint32_t mask;
13500 +};
13501 +
13502 +#ifdef __KERNEL__
13503 +
13504 +extern int vc_get_pflags(uint32_t pid, void __user *);
13505 +extern int vc_set_pflags(uint32_t pid, void __user *);
13506 +
13507 +#endif /* __KERNEL__ */
13508 +#endif /* _VX_SIGNAL_CMD_H */
13509 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/space.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/space.h
13510 --- linux-3.3.1/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13511 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/space.h 2012-02-24 03:55:06.000000000 +0100
13512 @@ -0,0 +1,12 @@
13513 +#ifndef _VX_SPACE_H
13514 +#define _VX_SPACE_H
13515 +
13516 +#include <linux/types.h>
13517 +
13518 +struct vx_info;
13519 +
13520 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13521 +
13522 +#else  /* _VX_SPACE_H */
13523 +#warning duplicate inclusion
13524 +#endif /* _VX_SPACE_H */
13525 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/space_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/space_cmd.h
13526 --- linux-3.3.1/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13527 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/space_cmd.h     2012-02-24 03:55:06.000000000 +0100
13528 @@ -0,0 +1,38 @@
13529 +#ifndef _VX_SPACE_CMD_H
13530 +#define _VX_SPACE_CMD_H
13531 +
13532 +
13533 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13534 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13535 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13536 +
13537 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13538 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13539 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13540 +
13541 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13542 +
13543 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13544 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13545 +
13546 +
13547 +struct vcmd_space_mask_v1 {
13548 +       uint64_t mask;
13549 +};
13550 +
13551 +struct vcmd_space_mask_v2 {
13552 +       uint64_t mask;
13553 +       uint32_t index;
13554 +};
13555 +
13556 +
13557 +#ifdef __KERNEL__
13558 +
13559 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13560 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13561 +extern int vc_enter_space(struct vx_info *, void __user *);
13562 +extern int vc_set_space(struct vx_info *, void __user *);
13563 +extern int vc_get_space_mask(void __user *, int);
13564 +
13565 +#endif /* __KERNEL__ */
13566 +#endif /* _VX_SPACE_CMD_H */
13567 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/switch.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/switch.h
13568 --- linux-3.3.1/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13569 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/switch.h        2012-02-24 03:55:06.000000000 +0100
13570 @@ -0,0 +1,98 @@
13571 +#ifndef _VX_SWITCH_H
13572 +#define _VX_SWITCH_H
13573 +
13574 +#include <linux/types.h>
13575 +
13576 +
13577 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13578 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13579 +#define VC_VERSION(c)          ((c) & 0xFFF)
13580 +
13581 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13582 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13583 +
13584 +/*
13585 +
13586 +  Syscall Matrix V2.8
13587 +
13588 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13589 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13590 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13591 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13592 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13593 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13594 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13595 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13596 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13597 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13598 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13599 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13600 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13601 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13602 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13603 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13604 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13605 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13606 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13607 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13608 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13609 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13610 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13611 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13612 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13613 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13614 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13615 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13616 +
13617 +*/
13618 +
13619 +#define VC_CAT_VERSION         0
13620 +
13621 +#define VC_CAT_VSETUP          1
13622 +#define VC_CAT_VHOST           2
13623 +
13624 +#define VC_CAT_DEVICE          6
13625 +
13626 +#define VC_CAT_VPROC           9
13627 +#define VC_CAT_PROCALT         10
13628 +#define VC_CAT_PROCMIG         11
13629 +#define VC_CAT_PROCTRL         12
13630 +
13631 +#define VC_CAT_SCHED           14
13632 +#define VC_CAT_MEMCTRL         20
13633 +
13634 +#define VC_CAT_VNET            25
13635 +#define VC_CAT_NETALT          26
13636 +#define VC_CAT_NETMIG          27
13637 +#define VC_CAT_NETCTRL         28
13638 +
13639 +#define VC_CAT_TAGMIG          35
13640 +#define VC_CAT_DLIMIT          36
13641 +#define VC_CAT_INODE           38
13642 +
13643 +#define VC_CAT_VSTAT           40
13644 +#define VC_CAT_VINFO           46
13645 +#define VC_CAT_EVENT           48
13646 +
13647 +#define VC_CAT_FLAGS           52
13648 +#define VC_CAT_VSPACE          54
13649 +#define VC_CAT_DEBUG           56
13650 +#define VC_CAT_RLIMIT          60
13651 +
13652 +#define VC_CAT_SYSTEST         61
13653 +#define VC_CAT_COMPAT          63
13654 +
13655 +/*  query version */
13656 +
13657 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13658 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13659 +
13660 +
13661 +#ifdef __KERNEL__
13662 +
13663 +#include <linux/errno.h>
13664 +
13665 +#endif /* __KERNEL__ */
13666 +
13667 +#endif /* _VX_SWITCH_H */
13668 +
13669 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/tag.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/tag.h
13670 --- linux-3.3.1/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13671 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/tag.h   2012-02-24 03:55:06.000000000 +0100
13672 @@ -0,0 +1,143 @@
13673 +#ifndef _DX_TAG_H
13674 +#define _DX_TAG_H
13675 +
13676 +#include <linux/types.h>
13677 +
13678 +
13679 +#define DX_TAG(in)     (IS_TAGGED(in))
13680 +
13681 +
13682 +#ifdef CONFIG_TAG_NFSD
13683 +#define DX_TAG_NFSD    1
13684 +#else
13685 +#define DX_TAG_NFSD    0
13686 +#endif
13687 +
13688 +
13689 +#ifdef CONFIG_TAGGING_NONE
13690 +
13691 +#define MAX_UID                0xFFFFFFFF
13692 +#define MAX_GID                0xFFFFFFFF
13693 +
13694 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13695 +
13696 +#define TAGINO_UID(cond, uid, tag)     (uid)
13697 +#define TAGINO_GID(cond, gid, tag)     (gid)
13698 +
13699 +#endif
13700 +
13701 +
13702 +#ifdef CONFIG_TAGGING_GID16
13703 +
13704 +#define MAX_UID                0xFFFFFFFF
13705 +#define MAX_GID                0x0000FFFF
13706 +
13707 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13708 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13709 +
13710 +#define TAGINO_UID(cond, uid, tag)     (uid)
13711 +#define TAGINO_GID(cond, gid, tag)     \
13712 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13713 +
13714 +#endif
13715 +
13716 +
13717 +#ifdef CONFIG_TAGGING_ID24
13718 +
13719 +#define MAX_UID                0x00FFFFFF
13720 +#define MAX_GID                0x00FFFFFF
13721 +
13722 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13723 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13724 +
13725 +#define TAGINO_UID(cond, uid, tag)     \
13726 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13727 +#define TAGINO_GID(cond, gid, tag)     \
13728 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13729 +
13730 +#endif
13731 +
13732 +
13733 +#ifdef CONFIG_TAGGING_UID16
13734 +
13735 +#define MAX_UID                0x0000FFFF
13736 +#define MAX_GID                0xFFFFFFFF
13737 +
13738 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13739 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13740 +
13741 +#define TAGINO_UID(cond, uid, tag)     \
13742 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13743 +#define TAGINO_GID(cond, gid, tag)     (gid)
13744 +
13745 +#endif
13746 +
13747 +
13748 +#ifdef CONFIG_TAGGING_INTERN
13749 +
13750 +#define MAX_UID                0xFFFFFFFF
13751 +#define MAX_GID                0xFFFFFFFF
13752 +
13753 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13754 +       ((cond) ? (tag) : 0)
13755 +
13756 +#define TAGINO_UID(cond, uid, tag)     (uid)
13757 +#define TAGINO_GID(cond, gid, tag)     (gid)
13758 +
13759 +#endif
13760 +
13761 +
13762 +#ifndef CONFIG_TAGGING_NONE
13763 +#define dx_current_fstag(sb)   \
13764 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13765 +#else
13766 +#define dx_current_fstag(sb)   (0)
13767 +#endif
13768 +
13769 +#ifndef CONFIG_TAGGING_INTERN
13770 +#define TAGINO_TAG(cond, tag)  (0)
13771 +#else
13772 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13773 +#endif
13774 +
13775 +#define INOTAG_UID(cond, uid, gid)     \
13776 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13777 +#define INOTAG_GID(cond, uid, gid)     \
13778 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13779 +
13780 +
13781 +static inline uid_t dx_map_uid(uid_t uid)
13782 +{
13783 +       if ((uid > MAX_UID) && (uid != -1))
13784 +               uid = -2;
13785 +       return (uid & MAX_UID);
13786 +}
13787 +
13788 +static inline gid_t dx_map_gid(gid_t gid)
13789 +{
13790 +       if ((gid > MAX_GID) && (gid != -1))
13791 +               gid = -2;
13792 +       return (gid & MAX_GID);
13793 +}
13794 +
13795 +struct peer_tag {
13796 +       int32_t xid;
13797 +       int32_t nid;
13798 +};
13799 +
13800 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13801 +
13802 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13803 +                unsigned long *flags);
13804 +
13805 +#ifdef CONFIG_PROPAGATE
13806 +
13807 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13808 +
13809 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13810 +
13811 +#else
13812 +#define dx_propagate_tag(n, i) do { } while (0)
13813 +#endif
13814 +
13815 +#endif /* _DX_TAG_H */
13816 diff -NurpP --minimal linux-3.3.1/include/linux/vserver/tag_cmd.h linux-3.3.1-vs2.3.3.2/include/linux/vserver/tag_cmd.h
13817 --- linux-3.3.1/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13818 +++ linux-3.3.1-vs2.3.3.2/include/linux/vserver/tag_cmd.h       2012-02-24 03:55:06.000000000 +0100
13819 @@ -0,0 +1,22 @@
13820 +#ifndef _VX_TAG_CMD_H
13821 +#define _VX_TAG_CMD_H
13822 +
13823 +
13824 +/* vinfo commands */
13825 +
13826 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13827 +
13828 +#ifdef __KERNEL__
13829 +extern int vc_task_tag(uint32_t);
13830 +
13831 +#endif /* __KERNEL__ */
13832 +
13833 +/* context commands */
13834 +
13835 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13836 +
13837 +#ifdef __KERNEL__
13838 +extern int vc_tag_migrate(uint32_t);
13839 +
13840 +#endif /* __KERNEL__ */
13841 +#endif /* _VX_TAG_CMD_H */
13842 diff -NurpP --minimal linux-3.3.1/include/net/addrconf.h linux-3.3.1-vs2.3.3.2/include/net/addrconf.h
13843 --- linux-3.3.1/include/net/addrconf.h  2012-03-19 19:47:29.000000000 +0100
13844 +++ linux-3.3.1-vs2.3.3.2/include/net/addrconf.h        2012-02-24 03:55:06.000000000 +0100
13845 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13846                                                struct net_device *dev,
13847                                                const struct in6_addr *daddr,
13848                                                unsigned int srcprefs,
13849 -                                              struct in6_addr *saddr);
13850 +                                              struct in6_addr *saddr,
13851 +                                              struct nx_info *nxi);
13852  extern int                     ipv6_get_lladdr(struct net_device *dev,
13853                                                 struct in6_addr *addr,
13854                                                 unsigned char banned_flags);
13855 diff -NurpP --minimal linux-3.3.1/include/net/af_unix.h linux-3.3.1-vs2.3.3.2/include/net/af_unix.h
13856 --- linux-3.3.1/include/net/af_unix.h   2012-03-19 19:47:29.000000000 +0100
13857 +++ linux-3.3.1-vs2.3.3.2/include/net/af_unix.h 2012-02-24 03:55:06.000000000 +0100
13858 @@ -4,6 +4,7 @@
13859  #include <linux/socket.h>
13860  #include <linux/un.h>
13861  #include <linux/mutex.h>
13862 +#include <linux/vs_base.h>
13863  #include <net/sock.h>
13864  
13865  extern void unix_inflight(struct file *fp);
13866 diff -NurpP --minimal linux-3.3.1/include/net/inet_timewait_sock.h linux-3.3.1-vs2.3.3.2/include/net/inet_timewait_sock.h
13867 --- linux-3.3.1/include/net/inet_timewait_sock.h        2012-03-19 19:47:29.000000000 +0100
13868 +++ linux-3.3.1-vs2.3.3.2/include/net/inet_timewait_sock.h      2012-02-24 03:55:06.000000000 +0100
13869 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13870  #define tw_net                 __tw_common.skc_net
13871  #define tw_daddr               __tw_common.skc_daddr
13872  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13873 +#define tw_xid                 __tw_common.skc_xid
13874 +#define tw_vx_info             __tw_common.skc_vx_info
13875 +#define tw_nid                 __tw_common.skc_nid
13876 +#define tw_nx_info             __tw_common.skc_nx_info
13877         int                     tw_timeout;
13878         volatile unsigned char  tw_substate;
13879         unsigned char           tw_rcv_wscale;
13880 diff -NurpP --minimal linux-3.3.1/include/net/ip6_route.h linux-3.3.1-vs2.3.3.2/include/net/ip6_route.h
13881 --- linux-3.3.1/include/net/ip6_route.h 2012-03-19 19:47:29.000000000 +0100
13882 +++ linux-3.3.1-vs2.3.3.2/include/net/ip6_route.h       2012-02-24 03:55:06.000000000 +0100
13883 @@ -88,7 +88,8 @@ extern int                    ip6_route_get_saddr(struct 
13884                                                     struct rt6_info *rt,
13885                                                     const struct in6_addr *daddr,
13886                                                     unsigned int prefs,
13887 -                                                   struct in6_addr *saddr);
13888 +                                                   struct in6_addr *saddr,
13889 +                                                   struct nx_info *nxi);
13890  
13891  extern struct rt6_info         *rt6_lookup(struct net *net,
13892                                             const struct in6_addr *daddr,
13893 diff -NurpP --minimal linux-3.3.1/include/net/route.h linux-3.3.1-vs2.3.3.2/include/net/route.h
13894 --- linux-3.3.1/include/net/route.h     2012-03-19 19:47:29.000000000 +0100
13895 +++ linux-3.3.1-vs2.3.3.2/include/net/route.h   2012-02-24 03:55:06.000000000 +0100
13896 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13897                 dst_release(&rt->dst);
13898  }
13899  
13900 +#include <linux/vs_base.h>
13901 +#include <linux/vs_inet.h>
13902 +
13903  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13904  
13905  extern const __u8 ip_tos2prio[16];
13906 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13907                            protocol, flow_flags, dst, src, dport, sport);
13908  }
13909  
13910 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13911 +       struct flowi4 *);
13912 +
13913  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13914                                               __be32 dst, __be32 src, u32 tos,
13915                                               int oif, u8 protocol,
13916 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13917  {
13918         struct net *net = sock_net(sk);
13919         struct rtable *rt;
13920 +       struct nx_info *nx_info = current_nx_info();
13921  
13922         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13923                               sport, dport, sk, can_sleep);
13924  
13925 -       if (!dst || !src) {
13926 +       if (sk)
13927 +               nx_info = sk->sk_nx_info;
13928 +
13929 +       vxdprintk(VXD_CBIT(net, 4),
13930 +               "ip_route_connect(%p) %p,%p;%lx",
13931 +               sk, nx_info, sk->sk_socket,
13932 +               (sk->sk_socket?sk->sk_socket->flags:0));
13933 +
13934 +       rt = ip_v4_find_src(net, nx_info, fl4);
13935 +       if (IS_ERR(rt))
13936 +               return rt;
13937 +       ip_rt_put(rt);
13938 +
13939 +       if (!fl4->daddr || !fl4->saddr) {
13940                 rt = __ip_route_output_key(net, fl4);
13941                 if (IS_ERR(rt))
13942                         return rt;
13943 diff -NurpP --minimal linux-3.3.1/include/net/sock.h linux-3.3.1-vs2.3.3.2/include/net/sock.h
13944 --- linux-3.3.1/include/net/sock.h      2012-03-19 19:47:29.000000000 +0100
13945 +++ linux-3.3.1-vs2.3.3.2/include/net/sock.h    2012-02-24 03:55:06.000000000 +0100
13946 @@ -168,6 +168,10 @@ struct sock_common {
13947  #ifdef CONFIG_NET_NS
13948         struct net              *skc_net;
13949  #endif
13950 +       xid_t                   skc_xid;
13951 +       struct vx_info          *skc_vx_info;
13952 +       nid_t                   skc_nid;
13953 +       struct nx_info          *skc_nx_info;
13954         /*
13955          * fields between dontcopy_begin/dontcopy_end
13956          * are not copied in sock_copy()
13957 @@ -278,6 +282,10 @@ struct sock {
13958  #define sk_bind_node           __sk_common.skc_bind_node
13959  #define sk_prot                        __sk_common.skc_prot
13960  #define sk_net                 __sk_common.skc_net
13961 +#define sk_xid                 __sk_common.skc_xid
13962 +#define sk_vx_info             __sk_common.skc_vx_info
13963 +#define sk_nid                 __sk_common.skc_nid
13964 +#define sk_nx_info             __sk_common.skc_nx_info
13965         socket_lock_t           sk_lock;
13966         struct sk_buff_head     sk_receive_queue;
13967         /*
13968 diff -NurpP --minimal linux-3.3.1/init/Kconfig linux-3.3.1-vs2.3.3.2/init/Kconfig
13969 --- linux-3.3.1/init/Kconfig    2012-03-19 19:47:29.000000000 +0100
13970 +++ linux-3.3.1-vs2.3.3.2/init/Kconfig  2012-02-24 03:55:06.000000000 +0100
13971 @@ -588,6 +588,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13972  menuconfig CGROUPS
13973         boolean "Control Group support"
13974         depends on EVENTFD
13975 +       default y
13976         help
13977           This option adds support for grouping sets of processes together, for
13978           use with process control subsystems such as Cpusets, CFS, memory
13979 @@ -837,6 +838,7 @@ config IPC_NS
13980  config USER_NS
13981         bool "User namespace (EXPERIMENTAL)"
13982         depends on EXPERIMENTAL
13983 +       depends on VSERVER_DISABLED
13984         default y
13985         help
13986           This allows containers, i.e. vservers, to use user namespaces
13987 diff -NurpP --minimal linux-3.3.1/init/main.c linux-3.3.1-vs2.3.3.2/init/main.c
13988 --- linux-3.3.1/init/main.c     2012-03-19 19:47:29.000000000 +0100
13989 +++ linux-3.3.1-vs2.3.3.2/init/main.c   2012-02-24 03:55:06.000000000 +0100
13990 @@ -68,6 +68,7 @@
13991  #include <linux/shmem_fs.h>
13992  #include <linux/slab.h>
13993  #include <linux/perf_event.h>
13994 +#include <linux/vserver/percpu.h>
13995  
13996  #include <asm/io.h>
13997  #include <asm/bugs.h>
13998 diff -NurpP --minimal linux-3.3.1/ipc/mqueue.c linux-3.3.1-vs2.3.3.2/ipc/mqueue.c
13999 --- linux-3.3.1/ipc/mqueue.c    2012-03-19 19:47:29.000000000 +0100
14000 +++ linux-3.3.1-vs2.3.3.2/ipc/mqueue.c  2012-02-24 04:07:13.000000000 +0100
14001 @@ -34,6 +34,8 @@
14002  #include <linux/ipc_namespace.h>
14003  #include <linux/user_namespace.h>
14004  #include <linux/slab.h>
14005 +#include <linux/vs_context.h>
14006 +#include <linux/vs_limit.h>
14007  
14008  #include <net/sock.h>
14009  #include "util.h"
14010 @@ -67,6 +69,7 @@ struct mqueue_inode_info {
14011         struct sigevent notify;
14012         struct pid* notify_owner;
14013         struct user_struct *user;       /* user who created, for accounting */
14014 +       struct vx_info *vxi;
14015         struct sock *notify_sock;
14016         struct sk_buff *notify_cookie;
14017  
14018 @@ -129,6 +132,7 @@ static struct inode *mqueue_get_inode(st
14019         if (S_ISREG(mode)) {
14020                 struct mqueue_inode_info *info;
14021                 unsigned long mq_bytes, mq_msg_tblsz;
14022 +               struct vx_info *vxi = current_vx_info();
14023  
14024                 inode->i_fop = &mqueue_file_operations;
14025                 inode->i_size = FILENT_SIZE;
14026 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14027                 info->notify_owner = NULL;
14028                 info->qsize = 0;
14029                 info->user = NULL;      /* set when all is ok */
14030 +               info->vxi = NULL;
14031                 memset(&info->attr, 0, sizeof(info->attr));
14032                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14033                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14034 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14035  
14036                 spin_lock(&mq_lock);
14037                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14038 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
14039 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
14040 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14041                         spin_unlock(&mq_lock);
14042                         /* mqueue_evict_inode() releases info->messages */
14043                         ret = -EMFILE;
14044                         goto out_inode;
14045                 }
14046                 u->mq_bytes += mq_bytes;
14047 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14048                 spin_unlock(&mq_lock);
14049  
14050                 /* all is ok */
14051                 info->user = get_uid(u);
14052 +               info->vxi = get_vx_info(vxi);
14053         } else if (S_ISDIR(mode)) {
14054                 inc_nlink(inode);
14055                 /* Some things misbehave if size == 0 on a directory */
14056 @@ -277,8 +285,11 @@ static void mqueue_evict_inode(struct in
14057             + info->attr.mq_msgsize);
14058         user = info->user;
14059         if (user) {
14060 +               struct vx_info *vxi = info->vxi;
14061 +
14062                 spin_lock(&mq_lock);
14063                 user->mq_bytes -= mq_bytes;
14064 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14065                 /*
14066                  * get_ns_from_inode() ensures that the
14067                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14068 @@ -288,6 +299,7 @@ static void mqueue_evict_inode(struct in
14069                 if (ipc_ns)
14070                         ipc_ns->mq_queues_count--;
14071                 spin_unlock(&mq_lock);
14072 +               put_vx_info(vxi);
14073                 free_uid(user);
14074         }
14075         if (ipc_ns)
14076 diff -NurpP --minimal linux-3.3.1/ipc/msg.c linux-3.3.1-vs2.3.3.2/ipc/msg.c
14077 --- linux-3.3.1/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
14078 +++ linux-3.3.1-vs2.3.3.2/ipc/msg.c     2012-02-24 03:55:06.000000000 +0100
14079 @@ -37,6 +37,7 @@
14080  #include <linux/rwsem.h>
14081  #include <linux/nsproxy.h>
14082  #include <linux/ipc_namespace.h>
14083 +#include <linux/vs_base.h>
14084  
14085  #include <asm/current.h>
14086  #include <asm/uaccess.h>
14087 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14088  
14089         msq->q_perm.mode = msgflg & S_IRWXUGO;
14090         msq->q_perm.key = key;
14091 +       msq->q_perm.xid = vx_current_xid();
14092  
14093         msq->q_perm.security = NULL;
14094         retval = security_msg_queue_alloc(msq);
14095 diff -NurpP --minimal linux-3.3.1/ipc/namespace.c linux-3.3.1-vs2.3.3.2/ipc/namespace.c
14096 --- linux-3.3.1/ipc/namespace.c 2011-07-22 11:18:12.000000000 +0200
14097 +++ linux-3.3.1-vs2.3.3.2/ipc/namespace.c       2012-02-24 03:55:06.000000000 +0100
14098 @@ -13,11 +13,12 @@
14099  #include <linux/mount.h>
14100  #include <linux/user_namespace.h>
14101  #include <linux/proc_fs.h>
14102 +#include <linux/vs_base.h>
14103 +#include <linux/vserver/global.h>
14104  
14105  #include "util.h"
14106  
14107 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14108 -                                          struct ipc_namespace *old_ns)
14109 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14110  {
14111         struct ipc_namespace *ns;
14112         int err;
14113 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14114         ipcns_notify(IPCNS_CREATED);
14115         register_ipcns_notifier(ns);
14116  
14117 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14118 +       ns->user_ns = get_user_ns(user_ns);
14119  
14120         return ns;
14121  }
14122  
14123  struct ipc_namespace *copy_ipcs(unsigned long flags,
14124 -                               struct task_struct *tsk)
14125 +                               struct ipc_namespace *old_ns,
14126 +                               struct user_namespace *user_ns)
14127  {
14128 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14129 -
14130         if (!(flags & CLONE_NEWIPC))
14131 -               return get_ipc_ns(ns);
14132 -       return create_ipc_ns(tsk, ns);
14133 +               return get_ipc_ns(old_ns);
14134 +       return create_ipc_ns(user_ns);
14135  }
14136  
14137  /*
14138 diff -NurpP --minimal linux-3.3.1/ipc/sem.c linux-3.3.1-vs2.3.3.2/ipc/sem.c
14139 --- linux-3.3.1/ipc/sem.c       2012-01-09 16:14:59.000000000 +0100
14140 +++ linux-3.3.1-vs2.3.3.2/ipc/sem.c     2012-02-24 03:55:06.000000000 +0100
14141 @@ -86,6 +86,8 @@
14142  #include <linux/rwsem.h>
14143  #include <linux/nsproxy.h>
14144  #include <linux/ipc_namespace.h>
14145 +#include <linux/vs_base.h>
14146 +#include <linux/vs_limit.h>
14147  
14148  #include <asm/uaccess.h>
14149  #include "util.h"
14150 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14151  
14152         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14153         sma->sem_perm.key = key;
14154 +       sma->sem_perm.xid = vx_current_xid();
14155  
14156         sma->sem_perm.security = NULL;
14157         retval = security_sem_alloc(sma);
14158 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14159                 return id;
14160         }
14161         ns->used_sems += nsems;
14162 +       /* FIXME: obsoleted? */
14163 +       vx_semary_inc(sma);
14164 +       vx_nsems_add(sma, nsems);
14165  
14166         sma->sem_base = (struct sem *) &sma[1];
14167  
14168 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14169  
14170         wake_up_sem_queue_do(&tasks);
14171         ns->used_sems -= sma->sem_nsems;
14172 +       /* FIXME: obsoleted? */
14173 +       vx_nsems_sub(sma, sma->sem_nsems);
14174 +       vx_semary_dec(sma);
14175         security_sem_free(sma);
14176         ipc_rcu_putref(sma);
14177  }
14178 diff -NurpP --minimal linux-3.3.1/ipc/shm.c linux-3.3.1-vs2.3.3.2/ipc/shm.c
14179 --- linux-3.3.1/ipc/shm.c       2012-03-19 19:47:29.000000000 +0100
14180 +++ linux-3.3.1-vs2.3.3.2/ipc/shm.c     2012-02-24 03:55:06.000000000 +0100
14181 @@ -39,6 +39,8 @@
14182  #include <linux/nsproxy.h>
14183  #include <linux/mount.h>
14184  #include <linux/ipc_namespace.h>
14185 +#include <linux/vs_context.h>
14186 +#include <linux/vs_limit.h>
14187  
14188  #include <asm/uaccess.h>
14189  
14190 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14191   */
14192  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14193  {
14194 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14195 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14196 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14197 +
14198 +       vx_ipcshm_sub(vxi, shp, numpages);
14199 +       ns->shm_tot -= numpages;
14200 +
14201         shm_rmid(ns, shp);
14202         shm_unlock(shp);
14203         if (!is_file_hugepages(shp->shm_file))
14204 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14205                                                 shp->mlock_user);
14206         fput (shp->shm_file);
14207         security_shm_free(shp);
14208 +       put_vx_info(vxi);
14209         ipc_rcu_putref(shp);
14210  }
14211  
14212 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14213         if (ns->shm_tot + numpages > ns->shm_ctlall)
14214                 return -ENOSPC;
14215  
14216 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14217 +               return -ENOSPC;
14218 +
14219         shp = ipc_rcu_alloc(sizeof(*shp));
14220         if (!shp)
14221                 return -ENOMEM;
14222  
14223         shp->shm_perm.key = key;
14224 +       shp->shm_perm.xid = vx_current_xid();
14225         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14226         shp->mlock_user = NULL;
14227  
14228 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
14229         ns->shm_tot += numpages;
14230         error = shp->shm_perm.id;
14231         shm_unlock(shp);
14232 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14233         return error;
14234  
14235  no_id:
14236 diff -NurpP --minimal linux-3.3.1/kernel/Makefile linux-3.3.1-vs2.3.3.2/kernel/Makefile
14237 --- linux-3.3.1/kernel/Makefile 2012-03-19 19:47:29.000000000 +0100
14238 +++ linux-3.3.1-vs2.3.3.2/kernel/Makefile       2012-02-24 03:55:06.000000000 +0100
14239 @@ -25,6 +25,7 @@ endif
14240  obj-y += sched/
14241  obj-y += power/
14242  
14243 +obj-y += vserver/
14244  obj-$(CONFIG_FREEZER) += freezer.o
14245  obj-$(CONFIG_PROFILING) += profile.o
14246  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14247 diff -NurpP --minimal linux-3.3.1/kernel/auditsc.c linux-3.3.1-vs2.3.3.2/kernel/auditsc.c
14248 --- linux-3.3.1/kernel/auditsc.c        2012-03-19 19:47:29.000000000 +0100
14249 +++ linux-3.3.1-vs2.3.3.2/kernel/auditsc.c      2012-02-24 16:47:49.000000000 +0100
14250 @@ -2308,7 +2308,7 @@ int audit_set_loginuid(uid_t loginuid)
14251         if (task->loginuid != -1)
14252                 return -EPERM;
14253  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14254 -       if (!capable(CAP_AUDIT_CONTROL))
14255 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14256                 return -EPERM;
14257  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14258  
14259 diff -NurpP --minimal linux-3.3.1/kernel/capability.c linux-3.3.1-vs2.3.3.2/kernel/capability.c
14260 --- linux-3.3.1/kernel/capability.c     2012-03-19 19:47:29.000000000 +0100
14261 +++ linux-3.3.1-vs2.3.3.2/kernel/capability.c   2012-02-24 03:55:06.000000000 +0100
14262 @@ -15,6 +15,7 @@
14263  #include <linux/syscalls.h>
14264  #include <linux/pid_namespace.h>
14265  #include <linux/user_namespace.h>
14266 +#include <linux/vs_context.h>
14267  #include <asm/uaccess.h>
14268  
14269  /*
14270 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14271         return 0;
14272  }
14273  
14274 +
14275  /*
14276   * The only thing that can change the capabilities of the current
14277   * process is the current process. As such, we can't be in this code
14278 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14279         return (ret == 0);
14280  }
14281  
14282 +#include <linux/vserver/base.h>
14283 +
14284  /**
14285   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14286   * initial user ns
14287 diff -NurpP --minimal linux-3.3.1/kernel/compat.c linux-3.3.1-vs2.3.3.2/kernel/compat.c
14288 --- linux-3.3.1/kernel/compat.c 2012-01-09 16:14:59.000000000 +0100
14289 +++ linux-3.3.1-vs2.3.3.2/kernel/compat.c       2012-02-24 03:55:06.000000000 +0100
14290 @@ -973,7 +973,7 @@ asmlinkage long compat_sys_stime(compat_
14291         if (err)
14292                 return err;
14293  
14294 -       do_settimeofday(&tv);
14295 +       vx_settimeofday(&tv);
14296         return 0;
14297  }
14298  
14299 diff -NurpP --minimal linux-3.3.1/kernel/cred.c linux-3.3.1-vs2.3.3.2/kernel/cred.c
14300 --- linux-3.3.1/kernel/cred.c   2012-01-09 16:15:00.000000000 +0100
14301 +++ linux-3.3.1-vs2.3.3.2/kernel/cred.c 2012-02-24 03:55:06.000000000 +0100
14302 @@ -61,31 +61,6 @@ struct cred init_cred = {
14303  #endif
14304  };
14305  
14306 -static inline void set_cred_subscribers(struct cred *cred, int n)
14307 -{
14308 -#ifdef CONFIG_DEBUG_CREDENTIALS
14309 -       atomic_set(&cred->subscribers, n);
14310 -#endif
14311 -}
14312 -
14313 -static inline int read_cred_subscribers(const struct cred *cred)
14314 -{
14315 -#ifdef CONFIG_DEBUG_CREDENTIALS
14316 -       return atomic_read(&cred->subscribers);
14317 -#else
14318 -       return 0;
14319 -#endif
14320 -}
14321 -
14322 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14323 -{
14324 -#ifdef CONFIG_DEBUG_CREDENTIALS
14325 -       struct cred *cred = (struct cred *) _cred;
14326 -
14327 -       atomic_add(n, &cred->subscribers);
14328 -#endif
14329 -}
14330 -
14331  /*
14332   * Dispose of the shared task group credentials
14333   */
14334 @@ -281,21 +256,16 @@ error:
14335   *
14336   * Call commit_creds() or abort_creds() to clean up.
14337   */
14338 -struct cred *prepare_creds(void)
14339 +struct cred *__prepare_creds(const struct cred *old)
14340  {
14341 -       struct task_struct *task = current;
14342 -       const struct cred *old;
14343         struct cred *new;
14344  
14345 -       validate_process_creds();
14346 -
14347         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14348         if (!new)
14349                 return NULL;
14350  
14351         kdebug("prepare_creds() alloc %p", new);
14352  
14353 -       old = task->cred;
14354         memcpy(new, old, sizeof(struct cred));
14355  
14356         atomic_set(&new->usage, 1);
14357 @@ -322,6 +292,13 @@ error:
14358         abort_creds(new);
14359         return NULL;
14360  }
14361 +
14362 +struct cred *prepare_creds(void)
14363 +{
14364 +       validate_process_creds();
14365 +
14366 +       return __prepare_creds(current->cred);
14367 +}
14368  EXPORT_SYMBOL(prepare_creds);
14369  
14370  /*
14371 diff -NurpP --minimal linux-3.3.1/kernel/exit.c linux-3.3.1-vs2.3.3.2/kernel/exit.c
14372 --- linux-3.3.1/kernel/exit.c   2012-03-19 19:47:30.000000000 +0100
14373 +++ linux-3.3.1-vs2.3.3.2/kernel/exit.c 2012-02-24 04:09:40.000000000 +0100
14374 @@ -48,6 +48,10 @@
14375  #include <linux/fs_struct.h>
14376  #include <linux/init_task.h>
14377  #include <linux/perf_event.h>
14378 +#include <linux/vs_limit.h>
14379 +#include <linux/vs_context.h>
14380 +#include <linux/vs_network.h>
14381 +#include <linux/vs_pid.h>
14382  #include <trace/events/sched.h>
14383  #include <linux/hw_breakpoint.h>
14384  #include <linux/oom.h>
14385 @@ -481,9 +485,11 @@ static void close_files(struct files_str
14386                                         filp_close(file, files);
14387                                         cond_resched();
14388                                 }
14389 +                               vx_openfd_dec(i);
14390                         }
14391                         i++;
14392                         set >>= 1;
14393 +                       cond_resched();
14394                 }
14395         }
14396  }
14397 @@ -1054,10 +1060,15 @@ void do_exit(long code)
14398         smp_mb();
14399         raw_spin_unlock_wait(&tsk->pi_lock);
14400  
14401 +       /* needs to stay after exit_notify() */
14402 +       exit_vx_info(tsk, code);
14403 +       exit_nx_info(tsk);
14404 +
14405         /* causes final put_task_struct in finish_task_switch(). */
14406         tsk->state = TASK_DEAD;
14407         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14408         schedule();
14409 +       printk("bad task: %p [%lx]\n", current, current->state);
14410         BUG();
14411         /* Avoid "noreturn function does return".  */
14412         for (;;)
14413 diff -NurpP --minimal linux-3.3.1/kernel/fork.c linux-3.3.1-vs2.3.3.2/kernel/fork.c
14414 --- linux-3.3.1/kernel/fork.c   2012-03-19 19:47:30.000000000 +0100
14415 +++ linux-3.3.1-vs2.3.3.2/kernel/fork.c 2012-03-19 20:52:37.000000000 +0100
14416 @@ -67,6 +67,9 @@
14417  #include <linux/oom.h>
14418  #include <linux/khugepaged.h>
14419  #include <linux/signalfd.h>
14420 +#include <linux/vs_context.h>
14421 +#include <linux/vs_network.h>
14422 +#include <linux/vs_limit.h>
14423  
14424  #include <asm/pgtable.h>
14425  #include <asm/pgalloc.h>
14426 @@ -169,6 +172,8 @@ void free_task(struct task_struct *tsk)
14427         account_kernel_stack(tsk->stack, -1);
14428         free_thread_info(tsk->stack);
14429         rt_mutex_debug_task_free(tsk);
14430 +       clr_vx_info(&tsk->vx_info);
14431 +       clr_nx_info(&tsk->nx_info);
14432         ftrace_graph_exit_task(tsk);
14433         free_task_struct(tsk);
14434  }
14435 @@ -504,6 +509,7 @@ static struct mm_struct *mm_init(struct 
14436         if (likely(!mm_alloc_pgd(mm))) {
14437                 mm->def_flags = 0;
14438                 mmu_notifier_mm_init(mm);
14439 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14440                 return mm;
14441         }
14442  
14443 @@ -541,6 +547,7 @@ void __mmdrop(struct mm_struct *mm)
14444  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14445         VM_BUG_ON(mm->pmd_huge_pte);
14446  #endif
14447 +       clr_vx_info(&mm->mm_vx_info);
14448         free_mm(mm);
14449  }
14450  EXPORT_SYMBOL_GPL(__mmdrop);
14451 @@ -776,6 +783,7 @@ struct mm_struct *dup_mm(struct task_str
14452                 goto fail_nomem;
14453  
14454         memcpy(mm, oldmm, sizeof(*mm));
14455 +       mm->mm_vx_info = NULL;
14456         mm_init_cpumask(mm);
14457  
14458         /* Initializing for Swap token stuff */
14459 @@ -819,6 +827,7 @@ fail_nocontext:
14460          * If init_new_context() failed, we cannot use mmput() to free the mm
14461          * because it calls destroy_context()
14462          */
14463 +       clr_vx_info(&mm->mm_vx_info);
14464         mm_free_pgd(mm);
14465         free_mm(mm);
14466         return NULL;
14467 @@ -1104,6 +1113,8 @@ static struct task_struct *copy_process(
14468         int retval;
14469         struct task_struct *p;
14470         int cgroup_callbacks_done = 0;
14471 +       struct vx_info *vxi;
14472 +       struct nx_info *nxi;
14473  
14474         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14475                 return ERR_PTR(-EINVAL);
14476 @@ -1150,7 +1161,12 @@ static struct task_struct *copy_process(
14477         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14478         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14479  #endif
14480 +       init_vx_info(&p->vx_info, current_vx_info());
14481 +       init_nx_info(&p->nx_info, current_nx_info());
14482 +
14483         retval = -EAGAIN;
14484 +       if (!vx_nproc_avail(1))
14485 +               goto bad_fork_free;
14486         if (atomic_read(&p->real_cred->user->processes) >=
14487                         task_rlimit(p, RLIMIT_NPROC)) {
14488                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14489 @@ -1420,6 +1436,18 @@ static struct task_struct *copy_process(
14490  
14491         total_forks++;
14492         spin_unlock(&current->sighand->siglock);
14493 +
14494 +       /* p is copy of current */
14495 +       vxi = p->vx_info;
14496 +       if (vxi) {
14497 +               claim_vx_info(vxi, p);
14498 +               atomic_inc(&vxi->cvirt.nr_threads);
14499 +               atomic_inc(&vxi->cvirt.total_forks);
14500 +               vx_nproc_inc(p);
14501 +       }
14502 +       nxi = p->nx_info;
14503 +       if (nxi)
14504 +               claim_nx_info(nxi, p);
14505         write_unlock_irq(&tasklist_lock);
14506         proc_fork_connector(p);
14507         cgroup_post_fork(p);
14508 diff -NurpP --minimal linux-3.3.1/kernel/kthread.c linux-3.3.1-vs2.3.3.2/kernel/kthread.c
14509 --- linux-3.3.1/kernel/kthread.c        2012-03-19 19:47:30.000000000 +0100
14510 +++ linux-3.3.1-vs2.3.3.2/kernel/kthread.c      2012-02-24 03:55:06.000000000 +0100
14511 @@ -16,6 +16,7 @@
14512  #include <linux/mutex.h>
14513  #include <linux/slab.h>
14514  #include <linux/freezer.h>
14515 +#include <linux/vs_pid.h>
14516  #include <trace/events/sched.h>
14517  
14518  static DEFINE_SPINLOCK(kthread_create_lock);
14519 diff -NurpP --minimal linux-3.3.1/kernel/nsproxy.c linux-3.3.1-vs2.3.3.2/kernel/nsproxy.c
14520 --- linux-3.3.1/kernel/nsproxy.c        2012-01-09 16:15:00.000000000 +0100
14521 +++ linux-3.3.1-vs2.3.3.2/kernel/nsproxy.c      2012-02-24 16:59:37.000000000 +0100
14522 @@ -20,11 +20,14 @@
14523  #include <linux/mnt_namespace.h>
14524  #include <linux/utsname.h>
14525  #include <linux/pid_namespace.h>
14526 +#include <linux/vserver/global.h>
14527 +#include <linux/vserver/debug.h>
14528  #include <net/net_namespace.h>
14529  #include <linux/ipc_namespace.h>
14530  #include <linux/proc_fs.h>
14531  #include <linux/file.h>
14532  #include <linux/syscalls.h>
14533 +#include "../fs/mount.h"
14534  
14535  static struct kmem_cache *nsproxy_cachep;
14536  
14537 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14538         struct nsproxy *nsproxy;
14539  
14540         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14541 -       if (nsproxy)
14542 +       if (nsproxy) {
14543                 atomic_set(&nsproxy->count, 1);
14544 +               atomic_inc(&vs_global_nsproxy);
14545 +       }
14546 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14547         return nsproxy;
14548  }
14549  
14550 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14551   * Return the newly created nsproxy.  Do not attach this to the task,
14552   * leave it to the caller to do proper locking and attach it to task.
14553   */
14554 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14555 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14556 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14557 +                       struct nsproxy *orig,
14558 +                       struct fs_struct *new_fs,
14559 +                       struct user_namespace *new_user,
14560 +                       struct pid_namespace *new_pid)
14561  {
14562         struct nsproxy *new_nsp;
14563         int err;
14564 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14565         if (!new_nsp)
14566                 return ERR_PTR(-ENOMEM);
14567  
14568 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14569 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14570         if (IS_ERR(new_nsp->mnt_ns)) {
14571                 err = PTR_ERR(new_nsp->mnt_ns);
14572                 goto out_ns;
14573         }
14574  
14575 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14576 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14577         if (IS_ERR(new_nsp->uts_ns)) {
14578                 err = PTR_ERR(new_nsp->uts_ns);
14579                 goto out_uts;
14580         }
14581  
14582 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14583 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14584         if (IS_ERR(new_nsp->ipc_ns)) {
14585                 err = PTR_ERR(new_nsp->ipc_ns);
14586                 goto out_ipc;
14587         }
14588  
14589 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14590 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14591         if (IS_ERR(new_nsp->pid_ns)) {
14592                 err = PTR_ERR(new_nsp->pid_ns);
14593                 goto out_pid;
14594         }
14595  
14596 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14597 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14598         if (IS_ERR(new_nsp->net_ns)) {
14599                 err = PTR_ERR(new_nsp->net_ns);
14600                 goto out_net;
14601 @@ -115,6 +124,40 @@ out_ns:
14602         return ERR_PTR(err);
14603  }
14604  
14605 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14606 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14607 +{
14608 +       return unshare_namespaces(flags, tsk->nsproxy,
14609 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14610 +               task_active_pid_ns(tsk));
14611 +}
14612 +
14613 +/*
14614 + * copies the nsproxy, setting refcount to 1, and grabbing a
14615 + * reference to all contained namespaces.
14616 + */
14617 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14618 +{
14619 +       struct nsproxy *ns = create_nsproxy();
14620 +
14621 +       if (ns) {
14622 +               memcpy(ns, orig, sizeof(struct nsproxy));
14623 +               atomic_set(&ns->count, 1);
14624 +
14625 +               if (ns->mnt_ns)
14626 +                       get_mnt_ns(ns->mnt_ns);
14627 +               if (ns->uts_ns)
14628 +                       get_uts_ns(ns->uts_ns);
14629 +               if (ns->ipc_ns)
14630 +                       get_ipc_ns(ns->ipc_ns);
14631 +               if (ns->pid_ns)
14632 +                       get_pid_ns(ns->pid_ns);
14633 +               if (ns->net_ns)
14634 +                       get_net(ns->net_ns);
14635 +       }
14636 +       return ns;
14637 +}
14638 +
14639  /*
14640   * called from clone.  This now handles copy for nsproxy and all
14641   * namespaces therein.
14642 @@ -122,9 +165,12 @@ out_ns:
14643  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14644  {
14645         struct nsproxy *old_ns = tsk->nsproxy;
14646 -       struct nsproxy *new_ns;
14647 +       struct nsproxy *new_ns = NULL;
14648         int err = 0;
14649  
14650 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14651 +               flags, tsk, old_ns);
14652 +
14653         if (!old_ns)
14654                 return 0;
14655  
14656 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14657                                 CLONE_NEWPID | CLONE_NEWNET)))
14658                 return 0;
14659  
14660 -       if (!capable(CAP_SYS_ADMIN)) {
14661 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14662                 err = -EPERM;
14663                 goto out;
14664         }
14665 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14666  
14667  out:
14668         put_nsproxy(old_ns);
14669 +       vxdprintk(VXD_CBIT(space, 3),
14670 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14671 +               flags, tsk, old_ns, err, new_ns);
14672         return err;
14673  }
14674  
14675 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14676                 put_ipc_ns(ns->ipc_ns);
14677         if (ns->pid_ns)
14678                 put_pid_ns(ns->pid_ns);
14679 -       put_net(ns->net_ns);
14680 +       if (ns->net_ns)
14681 +               put_net(ns->net_ns);
14682 +       atomic_dec(&vs_global_nsproxy);
14683         kmem_cache_free(nsproxy_cachep, ns);
14684  }
14685  
14686 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned 
14687  {
14688         int err = 0;
14689  
14690 +       vxdprintk(VXD_CBIT(space, 4),
14691 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14692 +               unshare_flags, current->nsproxy);
14693 +
14694         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14695                                CLONE_NEWNET)))
14696                 return 0;
14697  
14698 -       if (!capable(CAP_SYS_ADMIN))
14699 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14700                 return -EPERM;
14701  
14702         *new_nsp = create_new_namespaces(unshare_flags, current,
14703 diff -NurpP --minimal linux-3.3.1/kernel/pid.c linux-3.3.1-vs2.3.3.2/kernel/pid.c
14704 --- linux-3.3.1/kernel/pid.c    2012-03-19 19:47:30.000000000 +0100
14705 +++ linux-3.3.1-vs2.3.3.2/kernel/pid.c  2012-03-19 20:52:10.000000000 +0100
14706 @@ -36,6 +36,7 @@
14707  #include <linux/pid_namespace.h>
14708  #include <linux/init_task.h>
14709  #include <linux/syscalls.h>
14710 +#include <linux/vs_pid.h>
14711  
14712  #define pid_hashfn(nr, ns)     \
14713         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14714 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14715  
14716  struct pid *find_vpid(int nr)
14717  {
14718 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14719 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14720  }
14721  EXPORT_SYMBOL_GPL(find_vpid);
14722  
14723 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14724  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14725  {
14726         struct task_struct *result = NULL;
14727 +
14728 +       if (type == PIDTYPE_REALPID)
14729 +               type = PIDTYPE_PID;
14730         if (pid) {
14731                 struct hlist_node *first;
14732                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14733 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14734         rcu_lockdep_assert(rcu_read_lock_held(),
14735                            "find_task_by_pid_ns() needs rcu_read_lock()"
14736                            " protection");
14737 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14738 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14739  }
14740  
14741  struct task_struct *find_task_by_vpid(pid_t vnr)
14742 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14743  }
14744  EXPORT_SYMBOL_GPL(find_get_pid);
14745  
14746 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14747 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14748  {
14749         struct upid *upid;
14750         pid_t nr = 0;
14751 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14752         return nr;
14753  }
14754  
14755 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14756 +{
14757 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14758 +}
14759 +
14760  pid_t pid_vnr(struct pid *pid)
14761  {
14762         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14763 diff -NurpP --minimal linux-3.3.1/kernel/pid_namespace.c linux-3.3.1-vs2.3.3.2/kernel/pid_namespace.c
14764 --- linux-3.3.1/kernel/pid_namespace.c  2012-03-19 19:47:30.000000000 +0100
14765 +++ linux-3.3.1-vs2.3.3.2/kernel/pid_namespace.c        2012-02-24 03:55:06.000000000 +0100
14766 @@ -15,6 +15,7 @@
14767  #include <linux/acct.h>
14768  #include <linux/slab.h>
14769  #include <linux/proc_fs.h>
14770 +#include <linux/vserver/global.h>
14771  
14772  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14773  
14774 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
14775                 goto out_free_map;
14776  
14777         kref_init(&ns->kref);
14778 +       atomic_inc(&vs_global_pid_ns);
14779         ns->level = level;
14780         ns->parent = get_pid_ns(parent_pid_ns);
14781  
14782 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
14783  
14784         for (i = 0; i < PIDMAP_ENTRIES; i++)
14785                 kfree(ns->pidmap[i].page);
14786 +       atomic_dec(&vs_global_pid_ns);
14787         kmem_cache_free(pid_ns_cachep, ns);
14788  }
14789  
14790 diff -NurpP --minimal linux-3.3.1/kernel/posix-timers.c linux-3.3.1-vs2.3.3.2/kernel/posix-timers.c
14791 --- linux-3.3.1/kernel/posix-timers.c   2012-01-09 16:15:00.000000000 +0100
14792 +++ linux-3.3.1-vs2.3.3.2/kernel/posix-timers.c 2012-02-24 03:55:06.000000000 +0100
14793 @@ -47,6 +47,7 @@
14794  #include <linux/wait.h>
14795  #include <linux/workqueue.h>
14796  #include <linux/export.h>
14797 +#include <linux/vs_context.h>
14798  
14799  /*
14800   * Management arrays for POSIX timers.  Timers are kept in slab memory
14801 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14802  {
14803         struct task_struct *task;
14804         int shared, ret = -1;
14805 +
14806         /*
14807          * FIXME: if ->sigq is queued we can race with
14808          * dequeue_signal()->do_schedule_next_timer().
14809 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14810         rcu_read_lock();
14811         task = pid_task(timr->it_pid, PIDTYPE_PID);
14812         if (task) {
14813 +               struct vx_info_save vxis;
14814 +               struct vx_info *vxi;
14815 +
14816 +               vxi = get_vx_info(task->vx_info);
14817 +               enter_vx_info(vxi, &vxis);
14818                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14819                 ret = send_sigqueue(timr->sigq, task, shared);
14820 +               leave_vx_info(&vxis);
14821 +               put_vx_info(vxi);
14822         }
14823         rcu_read_unlock();
14824 +
14825         /* If we failed to send the signal the timer stops. */
14826         return ret > 0;
14827  }
14828 diff -NurpP --minimal linux-3.3.1/kernel/printk.c linux-3.3.1-vs2.3.3.2/kernel/printk.c
14829 --- linux-3.3.1/kernel/printk.c 2012-03-19 19:47:30.000000000 +0100
14830 +++ linux-3.3.1-vs2.3.3.2/kernel/printk.c       2012-03-19 20:52:10.000000000 +0100
14831 @@ -41,6 +41,7 @@
14832  #include <linux/cpu.h>
14833  #include <linux/notifier.h>
14834  #include <linux/rculist.h>
14835 +#include <linux/vs_cvirt.h>
14836  
14837  #include <asm/uaccess.h>
14838  
14839 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
14840                 return 0;
14841  
14842         if (syslog_action_restricted(type)) {
14843 -               if (capable(CAP_SYSLOG))
14844 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14845                         return 0;
14846                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14847                 if (capable(CAP_SYS_ADMIN)) {
14848 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
14849         if (error)
14850                 return error;
14851  
14852 -       switch (type) {
14853 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14854 -               break;
14855 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14856 -               break;
14857 -       case SYSLOG_ACTION_READ:        /* Read from log */
14858 +       if ((type == SYSLOG_ACTION_READ) ||
14859 +           (type == SYSLOG_ACTION_READ_ALL) ||
14860 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14861                 error = -EINVAL;
14862                 if (!buf || len < 0)
14863                         goto out;
14864 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
14865                         error = -EFAULT;
14866                         goto out;
14867                 }
14868 +       }
14869 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14870 +               return vx_do_syslog(type, buf, len);
14871 +
14872 +       switch (type) {
14873 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14874 +               break;
14875 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14876 +               break;
14877 +       case SYSLOG_ACTION_READ:        /* Read from log */
14878                 error = wait_event_interruptible(log_wait,
14879                                                         (log_start - log_end));
14880                 if (error)
14881 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
14882                 /* FALL THRU */
14883         /* Read last kernel messages */
14884         case SYSLOG_ACTION_READ_ALL:
14885 -               error = -EINVAL;
14886 -               if (!buf || len < 0)
14887 -                       goto out;
14888 -               error = 0;
14889 -               if (!len)
14890 -                       goto out;
14891 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14892 -                       error = -EFAULT;
14893 -                       goto out;
14894 -               }
14895                 count = len;
14896                 if (count > log_buf_len)
14897                         count = log_buf_len;
14898 diff -NurpP --minimal linux-3.3.1/kernel/ptrace.c linux-3.3.1-vs2.3.3.2/kernel/ptrace.c
14899 --- linux-3.3.1/kernel/ptrace.c 2012-03-19 19:47:30.000000000 +0100
14900 +++ linux-3.3.1-vs2.3.3.2/kernel/ptrace.c       2012-02-24 03:55:06.000000000 +0100
14901 @@ -22,6 +22,7 @@
14902  #include <linux/syscalls.h>
14903  #include <linux/uaccess.h>
14904  #include <linux/regset.h>
14905 +#include <linux/vs_context.h>
14906  #include <linux/hw_breakpoint.h>
14907  #include <linux/cn_proc.h>
14908  
14909 @@ -217,6 +218,11 @@ ok:
14910                 dumpable = get_dumpable(task->mm);
14911         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14912                 return -EPERM;
14913 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14914 +               return -EPERM;
14915 +       if (!vx_check(task->xid, VS_IDENT) &&
14916 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14917 +               return -EACCES;
14918  
14919         return security_ptrace_access_check(task, mode);
14920  }
14921 diff -NurpP --minimal linux-3.3.1/kernel/sched/core.c linux-3.3.1-vs2.3.3.2/kernel/sched/core.c
14922 --- linux-3.3.1/kernel/sched/core.c     2012-03-19 19:47:30.000000000 +0100
14923 +++ linux-3.3.1-vs2.3.3.2/kernel/sched/core.c   2012-03-19 20:52:10.000000000 +0100
14924 @@ -71,6 +71,8 @@
14925  #include <linux/ftrace.h>
14926  #include <linux/slab.h>
14927  #include <linux/init_task.h>
14928 +#include <linux/vs_sched.h>
14929 +#include <linux/vs_cvirt.h>
14930  
14931  #include <asm/tlb.h>
14932  #include <asm/irq_regs.h>
14933 @@ -2335,9 +2337,17 @@ static void calc_global_nohz(unsigned lo
14934   */
14935  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14936  {
14937 -       loads[0] = (avenrun[0] + offset) << shift;
14938 -       loads[1] = (avenrun[1] + offset) << shift;
14939 -       loads[2] = (avenrun[2] + offset) << shift;
14940 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14941 +               struct vx_info *vxi = current_vx_info();
14942 +
14943 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14944 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14945 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14946 +       } else {
14947 +               loads[0] = (avenrun[0] + offset) << shift;
14948 +               loads[1] = (avenrun[1] + offset) << shift;
14949 +               loads[2] = (avenrun[2] + offset) << shift;
14950 +       }
14951  }
14952  
14953  /*
14954 @@ -2633,14 +2643,17 @@ static inline void task_group_account_fi
14955  void account_user_time(struct task_struct *p, cputime_t cputime,
14956                        cputime_t cputime_scaled)
14957  {
14958 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14959 +       int nice = (TASK_NICE(p) > 0);
14960         int index;
14961  
14962         /* Add user time to process. */
14963         p->utime += cputime;
14964         p->utimescaled += cputime_scaled;
14965 +       vx_account_user(vxi, cputime, nice);
14966         account_group_user_time(p, cputime);
14967  
14968 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14969 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14970  
14971         /* Add user time to cpustat. */
14972         task_group_account_field(p, index, (__force u64) cputime);
14973 @@ -2687,9 +2700,12 @@ static inline
14974  void __account_system_time(struct task_struct *p, cputime_t cputime,
14975                         cputime_t cputime_scaled, int index)
14976  {
14977 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14978 +
14979         /* Add system time to process. */
14980         p->stime += cputime;
14981         p->stimescaled += cputime_scaled;
14982 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14983         account_group_system_time(p, cputime);
14984  
14985         /* Add system time to cpustat. */
14986 @@ -3886,7 +3902,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14987                 nice = 19;
14988  
14989         if (increment < 0 && !can_nice(current, nice))
14990 -               return -EPERM;
14991 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14992  
14993         retval = security_task_setnice(current, nice);
14994         if (retval)
14995 diff -NurpP --minimal linux-3.3.1/kernel/sched/fair.c linux-3.3.1-vs2.3.3.2/kernel/sched/fair.c
14996 --- linux-3.3.1/kernel/sched/fair.c     2012-03-19 19:47:30.000000000 +0100
14997 +++ linux-3.3.1-vs2.3.3.2/kernel/sched/fair.c   2012-03-19 20:52:10.000000000 +0100
14998 @@ -26,6 +26,7 @@
14999  #include <linux/slab.h>
15000  #include <linux/profile.h>
15001  #include <linux/interrupt.h>
15002 +#include <linux/vs_cvirt.h>
15003  
15004  #include <trace/events/sched.h>
15005  
15006 @@ -1126,6 +1127,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15007                 __enqueue_entity(cfs_rq, se);
15008         se->on_rq = 1;
15009  
15010 +       if (entity_is_task(se))
15011 +               vx_activate_task(task_of(se));
15012         if (cfs_rq->nr_running == 1) {
15013                 list_add_leaf_cfs_rq(cfs_rq);
15014                 check_enqueue_throttle(cfs_rq);
15015 @@ -1206,6 +1209,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15016         if (se != cfs_rq->curr)
15017                 __dequeue_entity(cfs_rq, se);
15018         se->on_rq = 0;
15019 +       if (entity_is_task(se))
15020 +               vx_deactivate_task(task_of(se));
15021         update_cfs_load(cfs_rq, 0);
15022         account_entity_dequeue(cfs_rq, se);
15023  
15024 diff -NurpP --minimal linux-3.3.1/kernel/signal.c linux-3.3.1-vs2.3.3.2/kernel/signal.c
15025 --- linux-3.3.1/kernel/signal.c 2012-03-19 19:47:30.000000000 +0100
15026 +++ linux-3.3.1-vs2.3.3.2/kernel/signal.c       2012-02-24 04:10:10.000000000 +0100
15027 @@ -29,6 +29,8 @@
15028  #include <linux/pid_namespace.h>
15029  #include <linux/nsproxy.h>
15030  #include <linux/user_namespace.h>
15031 +#include <linux/vs_context.h>
15032 +#include <linux/vs_pid.h>
15033  #define CREATE_TRACE_POINTS
15034  #include <trace/events/signal.h>
15035  
15036 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
15037         struct pid *sid;
15038         int error;
15039  
15040 +       vxdprintk(VXD_CBIT(misc, 7),
15041 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15042 +               sig, info, t, vx_task_xid(t), t->pid);
15043 +
15044         if (!valid_signal(sig))
15045                 return -EINVAL;
15046  
15047 +/*     FIXME: needed? if so, why?
15048 +       if ((info != SEND_SIG_NOINFO) &&
15049 +               (is_si_special(info) || !si_fromuser(info)))
15050 +               goto skip;      */
15051 +
15052         if (!si_fromuser(info))
15053                 return 0;
15054  
15055 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
15056                 }
15057         }
15058  
15059 +       error = -EPERM;
15060 +       if (t->pid == 1 && current->xid)
15061 +               return error;
15062 +
15063 +       error = -ESRCH;
15064 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15065 +                 loops, maybe ENOENT or EACCES? */
15066 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15067 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15068 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15069 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15070 +               return error;
15071 +       }
15072 +/* skip: */
15073         return security_task_kill(t, info, sig, 0);
15074  }
15075  
15076 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
15077         rcu_read_lock();
15078  retry:
15079         p = pid_task(pid, PIDTYPE_PID);
15080 -       if (p) {
15081 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15082                 error = group_send_sig_info(sig, info, p);
15083                 if (unlikely(error == -ESRCH))
15084                         /*
15085 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
15086  
15087         rcu_read_lock();
15088         p = pid_task(pid, PIDTYPE_PID);
15089 -       if (!p) {
15090 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15091                 ret = -ESRCH;
15092                 goto out_unlock;
15093         }
15094 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig, 
15095                 struct task_struct * p;
15096  
15097                 for_each_process(p) {
15098 -                       if (task_pid_vnr(p) > 1 &&
15099 -                                       !same_thread_group(p, current)) {
15100 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15101 +                               task_pid_vnr(p) > 1 &&
15102 +                               !same_thread_group(p, current) &&
15103 +                               !vx_current_initpid(p->pid)) {
15104                                 int err = group_send_sig_info(sig, info, p);
15105                                 ++count;
15106                                 if (err != -EPERM)
15107 @@ -2290,6 +2317,11 @@ relock:
15108                                 !sig_kernel_only(signr))
15109                         continue;
15110  
15111 +               /* virtual init is protected against user signals */
15112 +               if ((info->si_code == SI_USER) &&
15113 +                       vx_current_initpid(current->pid))
15114 +                       continue;
15115 +
15116                 if (sig_kernel_stop(signr)) {
15117                         /*
15118                          * The default action is to stop all threads in
15119 diff -NurpP --minimal linux-3.3.1/kernel/softirq.c linux-3.3.1-vs2.3.3.2/kernel/softirq.c
15120 --- linux-3.3.1/kernel/softirq.c        2012-03-19 19:47:30.000000000 +0100
15121 +++ linux-3.3.1-vs2.3.3.2/kernel/softirq.c      2012-02-24 03:55:06.000000000 +0100
15122 @@ -24,6 +24,7 @@
15123  #include <linux/ftrace.h>
15124  #include <linux/smp.h>
15125  #include <linux/tick.h>
15126 +#include <linux/vs_context.h>
15127  
15128  #define CREATE_TRACE_POINTS
15129  #include <trace/events/irq.h>
15130 diff -NurpP --minimal linux-3.3.1/kernel/sys.c linux-3.3.1-vs2.3.3.2/kernel/sys.c
15131 --- linux-3.3.1/kernel/sys.c    2012-03-19 19:47:30.000000000 +0100
15132 +++ linux-3.3.1-vs2.3.3.2/kernel/sys.c  2012-03-19 20:52:10.000000000 +0100
15133 @@ -45,6 +45,7 @@
15134  #include <linux/syscalls.h>
15135  #include <linux/kprobes.h>
15136  #include <linux/user_namespace.h>
15137 +#include <linux/vs_pid.h>
15138  
15139  #include <linux/kmsg_dump.h>
15140  /* Move somewhere else to avoid recompiling? */
15141 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15142                 goto out;
15143         }
15144         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15145 -               error = -EACCES;
15146 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15147 +                       error = 0;
15148 +               else
15149 +                       error = -EACCES;
15150                 goto out;
15151         }
15152         no_nice = security_task_setnice(p, niceval);
15153 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15154                         else
15155                                 pgrp = task_pgrp(current);
15156                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15157 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15158 +                                       continue;
15159                                 error = set_one_prio(p, niceval, error);
15160                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15161                         break;
15162 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15163                         else
15164                                 pgrp = task_pgrp(current);
15165                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15166 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15167 +                                       continue;
15168                                 niceval = 20 - task_nice(p);
15169                                 if (niceval > retval)
15170                                         retval = niceval;
15171 @@ -418,6 +426,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15172  
15173  static DEFINE_MUTEX(reboot_mutex);
15174  
15175 +long vs_reboot(unsigned int, void __user *);
15176 +
15177  /*
15178   * Reboot system call: for obvious reasons only root may call it,
15179   * and even root needs to set up some magic numbers in the registers
15180 @@ -450,6 +460,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15181         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15182                 cmd = LINUX_REBOOT_CMD_HALT;
15183  
15184 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15185 +               return vs_reboot(cmd, arg);
15186 +
15187         mutex_lock(&reboot_mutex);
15188         switch (cmd) {
15189         case LINUX_REBOOT_CMD_RESTART:
15190 @@ -1273,7 +1286,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15191         int errno;
15192         char tmp[__NEW_UTS_LEN];
15193  
15194 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15195 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15196 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15197                 return -EPERM;
15198  
15199         if (len < 0 || len > __NEW_UTS_LEN)
15200 @@ -1324,7 +1338,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15201         int errno;
15202         char tmp[__NEW_UTS_LEN];
15203  
15204 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15205 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15206 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15207                 return -EPERM;
15208         if (len < 0 || len > __NEW_UTS_LEN)
15209                 return -EINVAL;
15210 @@ -1443,7 +1458,7 @@ int do_prlimit(struct task_struct *tsk, 
15211                 /* Keep the capable check against init_user_ns until
15212                    cgroups can contain all limits */
15213                 if (new_rlim->rlim_max > rlim->rlim_max &&
15214 -                               !capable(CAP_SYS_RESOURCE))
15215 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15216                         retval = -EPERM;
15217                 if (!retval)
15218                         retval = security_task_setrlimit(tsk->group_leader,
15219 @@ -1497,7 +1512,8 @@ static int check_prlimit_permission(stru
15220              cred->gid == tcred->sgid &&
15221              cred->gid == tcred->gid))
15222                 return 0;
15223 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15224 +       if (vx_ns_capable(tcred->user->user_ns,
15225 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15226                 return 0;
15227  
15228         return -EPERM;
15229 diff -NurpP --minimal linux-3.3.1/kernel/sysctl.c linux-3.3.1-vs2.3.3.2/kernel/sysctl.c
15230 --- linux-3.3.1/kernel/sysctl.c 2012-03-19 19:47:30.000000000 +0100
15231 +++ linux-3.3.1-vs2.3.3.2/kernel/sysctl.c       2012-02-24 03:55:06.000000000 +0100
15232 @@ -76,6 +76,7 @@
15233  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15234  #include <linux/lockdep.h>
15235  #endif
15236 +extern char vshelper_path[];
15237  #ifdef CONFIG_CHR_DEV_SG
15238  #include <scsi/sg.h>
15239  #endif
15240 @@ -572,6 +573,13 @@ static struct ctl_table kern_table[] = {
15241                 .proc_handler   = proc_dostring,
15242         },
15243  #endif
15244 +       {
15245 +               .procname       = "vshelper",
15246 +               .data           = &vshelper_path,
15247 +               .maxlen         = 256,
15248 +               .mode           = 0644,
15249 +               .proc_handler   = &proc_dostring,
15250 +       },
15251  #ifdef CONFIG_CHR_DEV_SG
15252         {
15253                 .procname       = "sg-big-buff",
15254 diff -NurpP --minimal linux-3.3.1/kernel/sysctl_binary.c linux-3.3.1-vs2.3.3.2/kernel/sysctl_binary.c
15255 --- linux-3.3.1/kernel/sysctl_binary.c  2012-01-09 16:15:00.000000000 +0100
15256 +++ linux-3.3.1-vs2.3.3.2/kernel/sysctl_binary.c        2012-02-24 03:55:06.000000000 +0100
15257 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15258  
15259         { CTL_INT,      KERN_PANIC,                     "panic" },
15260         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15261 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15262  
15263         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15264         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15265 diff -NurpP --minimal linux-3.3.1/kernel/time/timekeeping.c linux-3.3.1-vs2.3.3.2/kernel/time/timekeeping.c
15266 --- linux-3.3.1/kernel/time/timekeeping.c       2012-03-19 19:47:30.000000000 +0100
15267 +++ linux-3.3.1-vs2.3.3.2/kernel/time/timekeeping.c     2012-02-24 03:55:06.000000000 +0100
15268 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15269         } while (read_seqretry(&xtime_lock, seq));
15270  
15271         timespec_add_ns(ts, nsecs);
15272 +       vx_adjust_timespec(ts);
15273  }
15274  
15275  EXPORT_SYMBOL(getnstimeofday);
15276 diff -NurpP --minimal linux-3.3.1/kernel/time.c linux-3.3.1-vs2.3.3.2/kernel/time.c
15277 --- linux-3.3.1/kernel/time.c   2012-01-09 16:15:00.000000000 +0100
15278 +++ linux-3.3.1-vs2.3.3.2/kernel/time.c 2012-02-24 03:55:06.000000000 +0100
15279 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15280         if (err)
15281                 return err;
15282  
15283 -       do_settimeofday(&tv);
15284 +       vx_settimeofday(&tv);
15285         return 0;
15286  }
15287  
15288 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15289                 /* SMP safe, again the code in arch/foo/time.c should
15290                  * globally block out interrupts when it runs.
15291                  */
15292 -               return do_settimeofday(tv);
15293 +               return vx_settimeofday(tv);
15294         }
15295         return 0;
15296  }
15297 diff -NurpP --minimal linux-3.3.1/kernel/timer.c linux-3.3.1-vs2.3.3.2/kernel/timer.c
15298 --- linux-3.3.1/kernel/timer.c  2012-03-19 19:47:30.000000000 +0100
15299 +++ linux-3.3.1-vs2.3.3.2/kernel/timer.c        2012-02-24 03:55:06.000000000 +0100
15300 @@ -40,6 +40,10 @@
15301  #include <linux/irq_work.h>
15302  #include <linux/sched.h>
15303  #include <linux/slab.h>
15304 +#include <linux/vs_base.h>
15305 +#include <linux/vs_cvirt.h>
15306 +#include <linux/vs_pid.h>
15307 +#include <linux/vserver/sched.h>
15308  
15309  #include <asm/uaccess.h>
15310  #include <asm/unistd.h>
15311 @@ -1386,12 +1390,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15312  
15313  #endif
15314  
15315 -#ifndef __alpha__
15316 -
15317 -/*
15318 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15319 - * should be moved into arch/i386 instead?
15320 - */
15321  
15322  /**
15323   * sys_getpid - return the thread group id of the current process
15324 @@ -1420,10 +1418,23 @@ SYSCALL_DEFINE0(getppid)
15325         rcu_read_lock();
15326         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
15327         rcu_read_unlock();
15328 +       return vx_map_pid(pid);
15329 +}
15330  
15331 -       return pid;
15332 +#ifdef __alpha__
15333 +
15334 +/*
15335 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15336 + */
15337 +
15338 +asmlinkage long do_getxpid(long *ppid)
15339 +{
15340 +       *ppid = sys_getppid();
15341 +       return sys_getpid();
15342  }
15343  
15344 +#else /* _alpha_ */
15345 +
15346  SYSCALL_DEFINE0(getuid)
15347  {
15348         /* Only we change this so SMP safe */
15349 diff -NurpP --minimal linux-3.3.1/kernel/user_namespace.c linux-3.3.1-vs2.3.3.2/kernel/user_namespace.c
15350 --- linux-3.3.1/kernel/user_namespace.c 2012-01-09 16:15:00.000000000 +0100
15351 +++ linux-3.3.1-vs2.3.3.2/kernel/user_namespace.c       2012-02-24 03:55:06.000000000 +0100
15352 @@ -11,6 +11,7 @@
15353  #include <linux/user_namespace.h>
15354  #include <linux/highuid.h>
15355  #include <linux/cred.h>
15356 +#include <linux/vserver/global.h>
15357  
15358  static struct kmem_cache *user_ns_cachep __read_mostly;
15359  
15360 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15361                 return -ENOMEM;
15362  
15363         kref_init(&ns->kref);
15364 +       atomic_inc(&vs_global_user_ns);
15365  
15366         for (n = 0; n < UIDHASH_SZ; ++n)
15367                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15368 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15369         struct user_namespace *ns =
15370                 container_of(kref, struct user_namespace, kref);
15371  
15372 +       /* FIXME: maybe move into destroyer? */
15373 +       atomic_dec(&vs_global_user_ns);
15374         INIT_WORK(&ns->destroyer, free_user_ns_work);
15375         schedule_work(&ns->destroyer);
15376  }
15377 diff -NurpP --minimal linux-3.3.1/kernel/utsname.c linux-3.3.1-vs2.3.3.2/kernel/utsname.c
15378 --- linux-3.3.1/kernel/utsname.c        2012-01-09 16:15:00.000000000 +0100
15379 +++ linux-3.3.1-vs2.3.3.2/kernel/utsname.c      2012-02-24 03:55:06.000000000 +0100
15380 @@ -16,14 +16,17 @@
15381  #include <linux/slab.h>
15382  #include <linux/user_namespace.h>
15383  #include <linux/proc_fs.h>
15384 +#include <linux/vserver/global.h>
15385  
15386  static struct uts_namespace *create_uts_ns(void)
15387  {
15388         struct uts_namespace *uts_ns;
15389  
15390         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15391 -       if (uts_ns)
15392 +       if (uts_ns) {
15393                 kref_init(&uts_ns->kref);
15394 +               atomic_inc(&vs_global_uts_ns);
15395 +       }
15396         return uts_ns;
15397  }
15398  
15399 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15400   * @old_ns: namespace to clone
15401   * Return NULL on error (failure to kmalloc), new ns otherwise
15402   */
15403 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15404 -                                         struct uts_namespace *old_ns)
15405 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15406 +                                         struct user_namespace *old_user)
15407  {
15408         struct uts_namespace *ns;
15409  
15410 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15411  
15412         down_read(&uts_sem);
15413         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15414 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15415 +       ns->user_ns = get_user_ns(old_user);
15416         up_read(&uts_sem);
15417         return ns;
15418  }
15419 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15420   * versa.
15421   */
15422  struct uts_namespace *copy_utsname(unsigned long flags,
15423 -                                  struct task_struct *tsk)
15424 +                                  struct uts_namespace *old_ns,
15425 +                                  struct user_namespace *user_ns)
15426  {
15427 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15428         struct uts_namespace *new_ns;
15429  
15430         BUG_ON(!old_ns);
15431 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15432         if (!(flags & CLONE_NEWUTS))
15433                 return old_ns;
15434  
15435 -       new_ns = clone_uts_ns(tsk, old_ns);
15436 +       new_ns = clone_uts_ns(old_ns, user_ns);
15437  
15438         put_uts_ns(old_ns);
15439         return new_ns;
15440 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15441  
15442         ns = container_of(kref, struct uts_namespace, kref);
15443         put_user_ns(ns->user_ns);
15444 +       atomic_dec(&vs_global_uts_ns);
15445         kfree(ns);
15446  }
15447  
15448 diff -NurpP --minimal linux-3.3.1/kernel/vserver/Kconfig linux-3.3.1-vs2.3.3.2/kernel/vserver/Kconfig
15449 --- linux-3.3.1/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15450 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/Kconfig        2012-02-24 03:55:06.000000000 +0100
15451 @@ -0,0 +1,224 @@
15452 +#
15453 +# Linux VServer configuration
15454 +#
15455 +
15456 +menu "Linux VServer"
15457 +
15458 +config VSERVER_AUTO_LBACK
15459 +       bool    "Automatically Assign Loopback IP"
15460 +       default y
15461 +       help
15462 +         Automatically assign a guest specific loopback
15463 +         IP and add it to the kernel network stack on
15464 +         startup.
15465 +
15466 +config VSERVER_AUTO_SINGLE
15467 +       bool    "Automatic Single IP Special Casing"
15468 +       depends on EXPERIMENTAL
15469 +       default y
15470 +       help
15471 +         This allows network contexts with a single IP to
15472 +         automatically remap 0.0.0.0 bindings to that IP,
15473 +         avoiding further network checks and improving
15474 +         performance.
15475 +
15476 +         (note: such guests do not allow to change the ip
15477 +          on the fly and do not show loopback addresses)
15478 +
15479 +config VSERVER_COWBL
15480 +       bool    "Enable COW Immutable Link Breaking"
15481 +       default y
15482 +       help
15483 +         This enables the COW (Copy-On-Write) link break code.
15484 +         It allows you to treat unified files like normal files
15485 +         when writing to them (which will implicitely break the
15486 +         link and create a copy of the unified file)
15487 +
15488 +config VSERVER_VTIME
15489 +       bool    "Enable Virtualized Guest Time"
15490 +       depends on EXPERIMENTAL
15491 +       default n
15492 +       help
15493 +         This enables per guest time offsets to allow for
15494 +         adjusting the system clock individually per guest.
15495 +         this adds some overhead to the time functions and
15496 +         therefore should not be enabled without good reason.
15497 +
15498 +config VSERVER_DEVICE
15499 +       bool    "Enable Guest Device Mapping"
15500 +       depends on EXPERIMENTAL
15501 +       default n
15502 +       help
15503 +         This enables generic device remapping.
15504 +
15505 +config VSERVER_PROC_SECURE
15506 +       bool    "Enable Proc Security"
15507 +       depends on PROC_FS
15508 +       default y
15509 +       help
15510 +         This configures ProcFS security to initially hide
15511 +         non-process entries for all contexts except the main and
15512 +         spectator context (i.e. for all guests), which is a secure
15513 +         default.
15514 +
15515 +         (note: on 1.2x the entries were visible by default)
15516 +
15517 +choice
15518 +       prompt  "Persistent Inode Tagging"
15519 +       default TAGGING_ID24
15520 +       help
15521 +         This adds persistent context information to filesystems
15522 +         mounted with the tagxid option. Tagging is a requirement
15523 +         for per-context disk limits and per-context quota.
15524 +
15525 +
15526 +config TAGGING_NONE
15527 +       bool    "Disabled"
15528 +       help
15529 +         do not store per-context information in inodes.
15530 +
15531 +config TAGGING_UID16
15532 +       bool    "UID16/GID32"
15533 +       help
15534 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15535 +
15536 +config TAGGING_GID16
15537 +       bool    "UID32/GID16"
15538 +       help
15539 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15540 +
15541 +config TAGGING_ID24
15542 +       bool    "UID24/GID24"
15543 +       help
15544 +         uses the upper 8bit from UID and GID for XID tagging
15545 +         which leaves 24bit for UID/GID each, which should be
15546 +         more than sufficient for normal use.
15547 +
15548 +config TAGGING_INTERN
15549 +       bool    "UID32/GID32"
15550 +       help
15551 +         this uses otherwise reserved inode fields in the on
15552 +         disk representation, which limits the use to a few
15553 +         filesystems (currently ext2 and ext3)
15554 +
15555 +endchoice
15556 +
15557 +config TAG_NFSD
15558 +       bool    "Tag NFSD User Auth and Files"
15559 +       default n
15560 +       help
15561 +         Enable this if you do want the in-kernel NFS
15562 +         Server to use the tagging specified above.
15563 +         (will require patched clients too)
15564 +
15565 +config VSERVER_PRIVACY
15566 +       bool    "Honor Privacy Aspects of Guests"
15567 +       default n
15568 +       help
15569 +         When enabled, most context checks will disallow
15570 +         access to structures assigned to a specific context,
15571 +         like ptys or loop devices.
15572 +
15573 +config VSERVER_CONTEXTS
15574 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15575 +       range 1 65533
15576 +       default "768"   if 64BIT
15577 +       default "256"
15578 +       help
15579 +         This setting will optimize certain data structures
15580 +         and memory allocations according to the expected
15581 +         maximum.
15582 +
15583 +         note: this is not a strict upper limit.
15584 +
15585 +config VSERVER_WARN
15586 +       bool    "VServer Warnings"
15587 +       default y
15588 +       help
15589 +         This enables various runtime warnings, which will
15590 +         notify about potential manipulation attempts or
15591 +         resource shortage. It is generally considered to
15592 +         be a good idea to have that enabled.
15593 +
15594 +config VSERVER_WARN_DEVPTS
15595 +       bool    "VServer DevPTS Warnings"
15596 +       depends on VSERVER_WARN
15597 +       default y
15598 +       help
15599 +         This enables DevPTS related warnings, issued when a
15600 +         process inside a context tries to lookup or access
15601 +         a dynamic pts from the host or a different context.
15602 +
15603 +config VSERVER_DEBUG
15604 +       bool    "VServer Debugging Code"
15605 +       default n
15606 +       help
15607 +         Set this to yes if you want to be able to activate
15608 +         debugging output at runtime. It adds a very small
15609 +         overhead to all vserver related functions and
15610 +         increases the kernel size by about 20k.
15611 +
15612 +config VSERVER_HISTORY
15613 +       bool    "VServer History Tracing"
15614 +       depends on VSERVER_DEBUG
15615 +       default n
15616 +       help
15617 +         Set this to yes if you want to record the history of
15618 +         linux-vserver activities, so they can be replayed in
15619 +         the event of a kernel panic or oops.
15620 +
15621 +config VSERVER_HISTORY_SIZE
15622 +       int     "Per-CPU History Size (32-65536)"
15623 +       depends on VSERVER_HISTORY
15624 +       range 32 65536
15625 +       default 64
15626 +       help
15627 +         This allows you to specify the number of entries in
15628 +         the per-CPU history buffer.
15629 +
15630 +choice
15631 +       prompt  "Quotes used in debug and warn messages"
15632 +       default QUOTES_ISO8859
15633 +
15634 +config QUOTES_ISO8859
15635 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15636 +       help
15637 +         This uses the extended ASCII characters \xbb
15638 +         and \xab for quoting file and process names.
15639 +
15640 +config QUOTES_UTF8
15641 +       bool    "UTF-8 angle quotes"
15642 +       help
15643 +         This uses the the UTF-8 sequences for angle
15644 +         quotes to quote file and process names.
15645 +
15646 +config QUOTES_ASCII
15647 +       bool    "ASCII single quotes"
15648 +       help
15649 +         This uses the ASCII single quote character
15650 +         (\x27) to quote file and process names.
15651 +
15652 +endchoice
15653 +
15654 +endmenu
15655 +
15656 +
15657 +config VSERVER
15658 +       bool
15659 +       default y
15660 +       select NAMESPACES
15661 +       select UTS_NS
15662 +       select IPC_NS
15663 +#      select USER_NS
15664 +       select SYSVIPC
15665 +
15666 +config VSERVER_SECURITY
15667 +       bool
15668 +       depends on SECURITY
15669 +       default y
15670 +       select SECURITY_CAPABILITIES
15671 +
15672 +config VSERVER_DISABLED
15673 +       bool
15674 +       default n
15675 +
15676 diff -NurpP --minimal linux-3.3.1/kernel/vserver/Makefile linux-3.3.1-vs2.3.3.2/kernel/vserver/Makefile
15677 --- linux-3.3.1/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15678 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/Makefile       2012-02-24 03:55:06.000000000 +0100
15679 @@ -0,0 +1,18 @@
15680 +#
15681 +# Makefile for the Linux vserver routines.
15682 +#
15683 +
15684 +
15685 +obj-y          += vserver.o
15686 +
15687 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15688 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15689 +                  dlimit.o tag.o
15690 +
15691 +vserver-$(CONFIG_INET) += inet.o
15692 +vserver-$(CONFIG_PROC_FS) += proc.o
15693 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15694 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15695 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15696 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15697 +
15698 diff -NurpP --minimal linux-3.3.1/kernel/vserver/cacct.c linux-3.3.1-vs2.3.3.2/kernel/vserver/cacct.c
15699 --- linux-3.3.1/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15700 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/cacct.c        2012-02-24 03:55:06.000000000 +0100
15701 @@ -0,0 +1,42 @@
15702 +/*
15703 + *  linux/kernel/vserver/cacct.c
15704 + *
15705 + *  Virtual Server: Context Accounting
15706 + *
15707 + *  Copyright (C) 2006-2007 Herbert Pötzl
15708 + *
15709 + *  V0.01  added accounting stats
15710 + *
15711 + */
15712 +
15713 +#include <linux/types.h>
15714 +#include <linux/vs_context.h>
15715 +#include <linux/vserver/cacct_cmd.h>
15716 +#include <linux/vserver/cacct_int.h>
15717 +
15718 +#include <asm/errno.h>
15719 +#include <asm/uaccess.h>
15720 +
15721 +
15722 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15723 +{
15724 +       struct vcmd_sock_stat_v0 vc_data;
15725 +       int j, field;
15726 +
15727 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15728 +               return -EFAULT;
15729 +
15730 +       field = vc_data.field;
15731 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15732 +               return -EINVAL;
15733 +
15734 +       for (j = 0; j < 3; j++) {
15735 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15736 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15737 +       }
15738 +
15739 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15740 +               return -EFAULT;
15741 +       return 0;
15742 +}
15743 +
15744 diff -NurpP --minimal linux-3.3.1/kernel/vserver/cacct_init.h linux-3.3.1-vs2.3.3.2/kernel/vserver/cacct_init.h
15745 --- linux-3.3.1/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
15746 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/cacct_init.h   2012-02-24 03:55:06.000000000 +0100
15747 @@ -0,0 +1,25 @@
15748 +
15749 +
15750 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15751 +{
15752 +       int i, j;
15753 +
15754 +
15755 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15756 +               for (j = 0; j < 3; j++) {
15757 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15758 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15759 +               }
15760 +       }
15761 +       for (i = 0; i < 8; i++)
15762 +               atomic_set(&cacct->slab[i], 0);
15763 +       for (i = 0; i < 5; i++)
15764 +               for (j = 0; j < 4; j++)
15765 +                       atomic_set(&cacct->page[i][j], 0);
15766 +}
15767 +
15768 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15769 +{
15770 +       return;
15771 +}
15772 +
15773 diff -NurpP --minimal linux-3.3.1/kernel/vserver/cacct_proc.h linux-3.3.1-vs2.3.3.2/kernel/vserver/cacct_proc.h
15774 --- linux-3.3.1/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
15775 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/cacct_proc.h   2012-02-24 03:55:06.000000000 +0100
15776 @@ -0,0 +1,53 @@
15777 +#ifndef _VX_CACCT_PROC_H
15778 +#define _VX_CACCT_PROC_H
15779 +
15780 +#include <linux/vserver/cacct_int.h>
15781 +
15782 +
15783 +#define VX_SOCKA_TOP   \
15784 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15785 +
15786 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15787 +{
15788 +       int i, j, length = 0;
15789 +       static char *type[VXA_SOCK_SIZE] = {
15790 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15791 +       };
15792 +
15793 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15794 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15795 +               length += sprintf(buffer + length, "%s:", type[i]);
15796 +               for (j = 0; j < 3; j++) {
15797 +                       length += sprintf(buffer + length,
15798 +                               "\t%10lu/%-10lu",
15799 +                               vx_sock_count(cacct, i, j),
15800 +                               vx_sock_total(cacct, i, j));
15801 +               }
15802 +               buffer[length++] = '\n';
15803 +       }
15804 +
15805 +       length += sprintf(buffer + length, "\n");
15806 +       length += sprintf(buffer + length,
15807 +               "slab:\t %8u %8u %8u %8u\n",
15808 +               atomic_read(&cacct->slab[1]),
15809 +               atomic_read(&cacct->slab[4]),
15810 +               atomic_read(&cacct->slab[0]),
15811 +               atomic_read(&cacct->slab[2]));
15812 +
15813 +       length += sprintf(buffer + length, "\n");
15814 +       for (i = 0; i < 5; i++) {
15815 +               length += sprintf(buffer + length,
15816 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15817 +                       atomic_read(&cacct->page[i][0]),
15818 +                       atomic_read(&cacct->page[i][1]),
15819 +                       atomic_read(&cacct->page[i][2]),
15820 +                       atomic_read(&cacct->page[i][3]),
15821 +                       atomic_read(&cacct->page[i][4]),
15822 +                       atomic_read(&cacct->page[i][5]),
15823 +                       atomic_read(&cacct->page[i][6]),
15824 +                       atomic_read(&cacct->page[i][7]));
15825 +       }
15826 +       return length;
15827 +}
15828 +
15829 +#endif /* _VX_CACCT_PROC_H */
15830 diff -NurpP --minimal linux-3.3.1/kernel/vserver/context.c linux-3.3.1-vs2.3.3.2/kernel/vserver/context.c
15831 --- linux-3.3.1/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
15832 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/context.c      2012-02-24 03:55:06.000000000 +0100
15833 @@ -0,0 +1,1107 @@
15834 +/*
15835 + *  linux/kernel/vserver/context.c
15836 + *
15837 + *  Virtual Server: Context Support
15838 + *
15839 + *  Copyright (C) 2003-2011  Herbert Pötzl
15840 + *
15841 + *  V0.01  context helper
15842 + *  V0.02  vx_ctx_kill syscall command
15843 + *  V0.03  replaced context_info calls
15844 + *  V0.04  redesign of struct (de)alloc
15845 + *  V0.05  rlimit basic implementation
15846 + *  V0.06  task_xid and info commands
15847 + *  V0.07  context flags and caps
15848 + *  V0.08  switch to RCU based hash
15849 + *  V0.09  revert to non RCU for now
15850 + *  V0.10  and back to working RCU hash
15851 + *  V0.11  and back to locking again
15852 + *  V0.12  referenced context store
15853 + *  V0.13  separate per cpu data
15854 + *  V0.14  changed vcmds to vxi arg
15855 + *  V0.15  added context stat
15856 + *  V0.16  have __create claim() the vxi
15857 + *  V0.17  removed older and legacy stuff
15858 + *  V0.18  added user credentials
15859 + *  V0.19  added warn mask
15860 + *
15861 + */
15862 +
15863 +#include <linux/slab.h>
15864 +#include <linux/types.h>
15865 +#include <linux/security.h>
15866 +#include <linux/pid_namespace.h>
15867 +#include <linux/capability.h>
15868 +
15869 +#include <linux/vserver/context.h>
15870 +#include <linux/vserver/network.h>
15871 +#include <linux/vserver/debug.h>
15872 +#include <linux/vserver/limit.h>
15873 +#include <linux/vserver/limit_int.h>
15874 +#include <linux/vserver/space.h>
15875 +#include <linux/init_task.h>
15876 +#include <linux/fs_struct.h>
15877 +#include <linux/cred.h>
15878 +
15879 +#include <linux/vs_context.h>
15880 +#include <linux/vs_limit.h>
15881 +#include <linux/vs_pid.h>
15882 +#include <linux/vserver/context_cmd.h>
15883 +
15884 +#include "cvirt_init.h"
15885 +#include "cacct_init.h"
15886 +#include "limit_init.h"
15887 +#include "sched_init.h"
15888 +
15889 +
15890 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15891 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15892 +
15893 +
15894 +/*     now inactive context structures */
15895 +
15896 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15897 +
15898 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15899 +
15900 +
15901 +/*     __alloc_vx_info()
15902 +
15903 +       * allocate an initialized vx_info struct
15904 +       * doesn't make it visible (hash)                        */
15905 +
15906 +static struct vx_info *__alloc_vx_info(xid_t xid)
15907 +{
15908 +       struct vx_info *new = NULL;
15909 +       int cpu, index;
15910 +
15911 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15912 +
15913 +       /* would this benefit from a slab cache? */
15914 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15915 +       if (!new)
15916 +               return 0;
15917 +
15918 +       memset(new, 0, sizeof(struct vx_info));
15919 +#ifdef CONFIG_SMP
15920 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15921 +       if (!new->ptr_pc)
15922 +               goto error;
15923 +#endif
15924 +       new->vx_id = xid;
15925 +       INIT_HLIST_NODE(&new->vx_hlist);
15926 +       atomic_set(&new->vx_usecnt, 0);
15927 +       atomic_set(&new->vx_tasks, 0);
15928 +       new->vx_parent = NULL;
15929 +       new->vx_state = 0;
15930 +       init_waitqueue_head(&new->vx_wait);
15931 +
15932 +       /* prepare reaper */
15933 +       get_task_struct(init_pid_ns.child_reaper);
15934 +       new->vx_reaper = init_pid_ns.child_reaper;
15935 +       new->vx_badness_bias = 0;
15936 +
15937 +       /* rest of init goes here */
15938 +       vx_info_init_limit(&new->limit);
15939 +       vx_info_init_sched(&new->sched);
15940 +       vx_info_init_cvirt(&new->cvirt);
15941 +       vx_info_init_cacct(&new->cacct);
15942 +
15943 +       /* per cpu data structures */
15944 +       for_each_possible_cpu(cpu) {
15945 +               vx_info_init_sched_pc(
15946 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15947 +               vx_info_init_cvirt_pc(
15948 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15949 +       }
15950 +
15951 +       new->vx_flags = VXF_INIT_SET;
15952 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15953 +       new->vx_ccaps = 0;
15954 +       new->vx_umask = 0;
15955 +       new->vx_wmask = 0;
15956 +
15957 +       new->reboot_cmd = 0;
15958 +       new->exit_code = 0;
15959 +
15960 +       // preconfig spaces
15961 +       for (index = 0; index < VX_SPACES; index++) {
15962 +               struct _vx_space *space = &new->space[index];
15963 +
15964 +               // filesystem
15965 +               spin_lock(&init_fs.lock);
15966 +               init_fs.users++;
15967 +               spin_unlock(&init_fs.lock);
15968 +               space->vx_fs = &init_fs;
15969 +
15970 +               /* FIXME: do we want defaults? */
15971 +               // space->vx_real_cred = 0;
15972 +               // space->vx_cred = 0;
15973 +       }
15974 +
15975 +
15976 +       vxdprintk(VXD_CBIT(xid, 0),
15977 +               "alloc_vx_info(%d) = %p", xid, new);
15978 +       vxh_alloc_vx_info(new);
15979 +       atomic_inc(&vx_global_ctotal);
15980 +       return new;
15981 +#ifdef CONFIG_SMP
15982 +error:
15983 +       kfree(new);
15984 +       return 0;
15985 +#endif
15986 +}
15987 +
15988 +/*     __dealloc_vx_info()
15989 +
15990 +       * final disposal of vx_info                             */
15991 +
15992 +static void __dealloc_vx_info(struct vx_info *vxi)
15993 +{
15994 +#ifdef CONFIG_VSERVER_WARN
15995 +       struct vx_info_save vxis;
15996 +       int cpu;
15997 +#endif
15998 +       vxdprintk(VXD_CBIT(xid, 0),
15999 +               "dealloc_vx_info(%p)", vxi);
16000 +       vxh_dealloc_vx_info(vxi);
16001 +
16002 +#ifdef CONFIG_VSERVER_WARN
16003 +       enter_vx_info(vxi, &vxis);
16004 +       vx_info_exit_limit(&vxi->limit);
16005 +       vx_info_exit_sched(&vxi->sched);
16006 +       vx_info_exit_cvirt(&vxi->cvirt);
16007 +       vx_info_exit_cacct(&vxi->cacct);
16008 +
16009 +       for_each_possible_cpu(cpu) {
16010 +               vx_info_exit_sched_pc(
16011 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16012 +               vx_info_exit_cvirt_pc(
16013 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16014 +       }
16015 +       leave_vx_info(&vxis);
16016 +#endif
16017 +
16018 +       vxi->vx_id = -1;
16019 +       vxi->vx_state |= VXS_RELEASED;
16020 +
16021 +#ifdef CONFIG_SMP
16022 +       free_percpu(vxi->ptr_pc);
16023 +#endif
16024 +       kfree(vxi);
16025 +       atomic_dec(&vx_global_ctotal);
16026 +}
16027 +
16028 +static void __shutdown_vx_info(struct vx_info *vxi)
16029 +{
16030 +       struct nsproxy *nsproxy;
16031 +       struct fs_struct *fs;
16032 +       struct cred *cred;
16033 +       int index, kill;
16034 +
16035 +       might_sleep();
16036 +
16037 +       vxi->vx_state |= VXS_SHUTDOWN;
16038 +       vs_state_change(vxi, VSC_SHUTDOWN);
16039 +
16040 +       for (index = 0; index < VX_SPACES; index++) {
16041 +               struct _vx_space *space = &vxi->space[index];
16042 +
16043 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16044 +               if (nsproxy)
16045 +                       put_nsproxy(nsproxy);
16046 +
16047 +               fs = xchg(&space->vx_fs, NULL);
16048 +               spin_lock(&fs->lock);
16049 +               kill = !--fs->users;
16050 +               spin_unlock(&fs->lock);
16051 +               if (kill)
16052 +                       free_fs_struct(fs);
16053 +
16054 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16055 +               if (cred)
16056 +                       abort_creds(cred);
16057 +       }
16058 +}
16059 +
16060 +/* exported stuff */
16061 +
16062 +void free_vx_info(struct vx_info *vxi)
16063 +{
16064 +       unsigned long flags;
16065 +       unsigned index;
16066 +
16067 +       /* check for reference counts first */
16068 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16069 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16070 +
16071 +       /* context must not be hashed */
16072 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16073 +
16074 +       /* context shutdown is mandatory */
16075 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16076 +
16077 +       /* spaces check */
16078 +       for (index = 0; index < VX_SPACES; index++) {
16079 +               struct _vx_space *space = &vxi->space[index];
16080 +
16081 +               BUG_ON(space->vx_nsproxy);
16082 +               BUG_ON(space->vx_fs);
16083 +               // BUG_ON(space->vx_real_cred);
16084 +               // BUG_ON(space->vx_cred);
16085 +       }
16086 +
16087 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16088 +       hlist_del(&vxi->vx_hlist);
16089 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16090 +
16091 +       __dealloc_vx_info(vxi);
16092 +}
16093 +
16094 +
16095 +/*     hash table for vx_info hash */
16096 +
16097 +#define VX_HASH_SIZE   13
16098 +
16099 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16100 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16101 +
16102 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16103 +
16104 +
16105 +static inline unsigned int __hashval(xid_t xid)
16106 +{
16107 +       return (xid % VX_HASH_SIZE);
16108 +}
16109 +
16110 +
16111 +
16112 +/*     __hash_vx_info()
16113 +
16114 +       * add the vxi to the global hash table
16115 +       * requires the hash_lock to be held                     */
16116 +
16117 +static inline void __hash_vx_info(struct vx_info *vxi)
16118 +{
16119 +       struct hlist_head *head;
16120 +
16121 +       vxd_assert_lock(&vx_info_hash_lock);
16122 +       vxdprintk(VXD_CBIT(xid, 4),
16123 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16124 +       vxh_hash_vx_info(vxi);
16125 +
16126 +       /* context must not be hashed */
16127 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16128 +
16129 +       vxi->vx_state |= VXS_HASHED;
16130 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16131 +       hlist_add_head(&vxi->vx_hlist, head);
16132 +       atomic_inc(&vx_global_cactive);
16133 +}
16134 +
16135 +/*     __unhash_vx_info()
16136 +
16137 +       * remove the vxi from the global hash table
16138 +       * requires the hash_lock to be held                     */
16139 +
16140 +static inline void __unhash_vx_info(struct vx_info *vxi)
16141 +{
16142 +       unsigned long flags;
16143 +
16144 +       vxd_assert_lock(&vx_info_hash_lock);
16145 +       vxdprintk(VXD_CBIT(xid, 4),
16146 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16147 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16148 +       vxh_unhash_vx_info(vxi);
16149 +
16150 +       /* context must be hashed */
16151 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16152 +       /* but without tasks */
16153 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16154 +
16155 +       vxi->vx_state &= ~VXS_HASHED;
16156 +       hlist_del_init(&vxi->vx_hlist);
16157 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16158 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16159 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16160 +       atomic_dec(&vx_global_cactive);
16161 +}
16162 +
16163 +
16164 +/*     __lookup_vx_info()
16165 +
16166 +       * requires the hash_lock to be held
16167 +       * doesn't increment the vx_refcnt                       */
16168 +
16169 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16170 +{
16171 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16172 +       struct hlist_node *pos;
16173 +       struct vx_info *vxi;
16174 +
16175 +       vxd_assert_lock(&vx_info_hash_lock);
16176 +       hlist_for_each(pos, head) {
16177 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16178 +
16179 +               if (vxi->vx_id == xid)
16180 +                       goto found;
16181 +       }
16182 +       vxi = NULL;
16183 +found:
16184 +       vxdprintk(VXD_CBIT(xid, 0),
16185 +               "__lookup_vx_info(#%u): %p[#%u]",
16186 +               xid, vxi, vxi ? vxi->vx_id : 0);
16187 +       vxh_lookup_vx_info(vxi, xid);
16188 +       return vxi;
16189 +}
16190 +
16191 +
16192 +/*     __create_vx_info()
16193 +
16194 +       * create the requested context
16195 +       * get(), claim() and hash it                            */
16196 +
16197 +static struct vx_info *__create_vx_info(int id)
16198 +{
16199 +       struct vx_info *new, *vxi = NULL;
16200 +
16201 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16202 +
16203 +       if (!(new = __alloc_vx_info(id)))
16204 +               return ERR_PTR(-ENOMEM);
16205 +
16206 +       /* required to make dynamic xids unique */
16207 +       spin_lock(&vx_info_hash_lock);
16208 +
16209 +       /* static context requested */
16210 +       if ((vxi = __lookup_vx_info(id))) {
16211 +               vxdprintk(VXD_CBIT(xid, 0),
16212 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16213 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16214 +                       vxi = ERR_PTR(-EBUSY);
16215 +               else
16216 +                       vxi = ERR_PTR(-EEXIST);
16217 +               goto out_unlock;
16218 +       }
16219 +       /* new context */
16220 +       vxdprintk(VXD_CBIT(xid, 0),
16221 +               "create_vx_info(%d) = %p (new)", id, new);
16222 +       claim_vx_info(new, NULL);
16223 +       __hash_vx_info(get_vx_info(new));
16224 +       vxi = new, new = NULL;
16225 +
16226 +out_unlock:
16227 +       spin_unlock(&vx_info_hash_lock);
16228 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16229 +       if (new)
16230 +               __dealloc_vx_info(new);
16231 +       return vxi;
16232 +}
16233 +
16234 +
16235 +/*     exported stuff                                          */
16236 +
16237 +
16238 +void unhash_vx_info(struct vx_info *vxi)
16239 +{
16240 +       spin_lock(&vx_info_hash_lock);
16241 +       __unhash_vx_info(vxi);
16242 +       spin_unlock(&vx_info_hash_lock);
16243 +       __shutdown_vx_info(vxi);
16244 +       __wakeup_vx_info(vxi);
16245 +}
16246 +
16247 +
16248 +/*     lookup_vx_info()
16249 +
16250 +       * search for a vx_info and get() it
16251 +       * negative id means current                             */
16252 +
16253 +struct vx_info *lookup_vx_info(int id)
16254 +{
16255 +       struct vx_info *vxi = NULL;
16256 +
16257 +       if (id < 0) {
16258 +               vxi = get_vx_info(current_vx_info());
16259 +       } else if (id > 1) {
16260 +               spin_lock(&vx_info_hash_lock);
16261 +               vxi = get_vx_info(__lookup_vx_info(id));
16262 +               spin_unlock(&vx_info_hash_lock);
16263 +       }
16264 +       return vxi;
16265 +}
16266 +
16267 +/*     xid_is_hashed()
16268 +
16269 +       * verify that xid is still hashed                       */
16270 +
16271 +int xid_is_hashed(xid_t xid)
16272 +{
16273 +       int hashed;
16274 +
16275 +       spin_lock(&vx_info_hash_lock);
16276 +       hashed = (__lookup_vx_info(xid) != NULL);
16277 +       spin_unlock(&vx_info_hash_lock);
16278 +       return hashed;
16279 +}
16280 +
16281 +#ifdef CONFIG_PROC_FS
16282 +
16283 +/*     get_xid_list()
16284 +
16285 +       * get a subset of hashed xids for proc
16286 +       * assumes size is at least one                          */
16287 +
16288 +int get_xid_list(int index, unsigned int *xids, int size)
16289 +{
16290 +       int hindex, nr_xids = 0;
16291 +
16292 +       /* only show current and children */
16293 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16294 +               if (index > 0)
16295 +                       return 0;
16296 +               xids[nr_xids] = vx_current_xid();
16297 +               return 1;
16298 +       }
16299 +
16300 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16301 +               struct hlist_head *head = &vx_info_hash[hindex];
16302 +               struct hlist_node *pos;
16303 +
16304 +               spin_lock(&vx_info_hash_lock);
16305 +               hlist_for_each(pos, head) {
16306 +                       struct vx_info *vxi;
16307 +
16308 +                       if (--index > 0)
16309 +                               continue;
16310 +
16311 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16312 +                       xids[nr_xids] = vxi->vx_id;
16313 +                       if (++nr_xids >= size) {
16314 +                               spin_unlock(&vx_info_hash_lock);
16315 +                               goto out;
16316 +                       }
16317 +               }
16318 +               /* keep the lock time short */
16319 +               spin_unlock(&vx_info_hash_lock);
16320 +       }
16321 +out:
16322 +       return nr_xids;
16323 +}
16324 +#endif
16325 +
16326 +#ifdef CONFIG_VSERVER_DEBUG
16327 +
16328 +void   dump_vx_info_inactive(int level)
16329 +{
16330 +       struct hlist_node *entry, *next;
16331 +
16332 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16333 +               struct vx_info *vxi =
16334 +                       list_entry(entry, struct vx_info, vx_hlist);
16335 +
16336 +               dump_vx_info(vxi, level);
16337 +       }
16338 +}
16339 +
16340 +#endif
16341 +
16342 +#if 0
16343 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16344 +{
16345 +       struct user_struct *new_user, *old_user;
16346 +
16347 +       if (!p || !vxi)
16348 +               BUG();
16349 +
16350 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16351 +               return -EACCES;
16352 +
16353 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16354 +       if (!new_user)
16355 +               return -ENOMEM;
16356 +
16357 +       old_user = p->user;
16358 +       if (new_user != old_user) {
16359 +               atomic_inc(&new_user->processes);
16360 +               atomic_dec(&old_user->processes);
16361 +               p->user = new_user;
16362 +       }
16363 +       free_uid(old_user);
16364 +       return 0;
16365 +}
16366 +#endif
16367 +
16368 +#if 0
16369 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16370 +{
16371 +       // p->cap_effective &= vxi->vx_cap_bset;
16372 +       p->cap_effective =
16373 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16374 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16375 +       p->cap_inheritable =
16376 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16377 +       // p->cap_permitted &= vxi->vx_cap_bset;
16378 +       p->cap_permitted =
16379 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16380 +}
16381 +#endif
16382 +
16383 +
16384 +#include <linux/file.h>
16385 +#include <linux/fdtable.h>
16386 +
16387 +static int vx_openfd_task(struct task_struct *tsk)
16388 +{
16389 +       struct files_struct *files = tsk->files;
16390 +       struct fdtable *fdt;
16391 +       const unsigned long *bptr;
16392 +       int count, total;
16393 +
16394 +       /* no rcu_read_lock() because of spin_lock() */
16395 +       spin_lock(&files->file_lock);
16396 +       fdt = files_fdtable(files);
16397 +       bptr = fdt->open_fds->fds_bits;
16398 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16399 +       for (total = 0; count > 0; count--) {
16400 +               if (*bptr)
16401 +                       total += hweight_long(*bptr);
16402 +               bptr++;
16403 +       }
16404 +       spin_unlock(&files->file_lock);
16405 +       return total;
16406 +}
16407 +
16408 +
16409 +/*     for *space compatibility */
16410 +
16411 +asmlinkage long sys_unshare(unsigned long);
16412 +
16413 +/*
16414 + *     migrate task to new context
16415 + *     gets vxi, puts old_vxi on change
16416 + *     optionally unshares namespaces (hack)
16417 + */
16418 +
16419 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16420 +{
16421 +       struct vx_info *old_vxi;
16422 +       int ret = 0;
16423 +
16424 +       if (!p || !vxi)
16425 +               BUG();
16426 +
16427 +       vxdprintk(VXD_CBIT(xid, 5),
16428 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16429 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16430 +
16431 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16432 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16433 +               return -EACCES;
16434 +
16435 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16436 +               return -EFAULT;
16437 +
16438 +       old_vxi = task_get_vx_info(p);
16439 +       if (old_vxi == vxi)
16440 +               goto out;
16441 +
16442 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16443 +       {
16444 +               int openfd;
16445 +
16446 +               task_lock(p);
16447 +               openfd = vx_openfd_task(p);
16448 +
16449 +               if (old_vxi) {
16450 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16451 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16452 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16453 +                       /* FIXME: what about the struct files here? */
16454 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16455 +                       /* account for the executable */
16456 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16457 +               }
16458 +               atomic_inc(&vxi->cvirt.nr_threads);
16459 +               atomic_inc(&vxi->cvirt.nr_running);
16460 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16461 +               /* FIXME: what about the struct files here? */
16462 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16463 +               /* account for the executable */
16464 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16465 +
16466 +               if (old_vxi) {
16467 +                       release_vx_info(old_vxi, p);
16468 +                       clr_vx_info(&p->vx_info);
16469 +               }
16470 +               claim_vx_info(vxi, p);
16471 +               set_vx_info(&p->vx_info, vxi);
16472 +               p->xid = vxi->vx_id;
16473 +
16474 +               vxdprintk(VXD_CBIT(xid, 5),
16475 +                       "moved task %p into vxi:%p[#%d]",
16476 +                       p, vxi, vxi->vx_id);
16477 +
16478 +               // vx_mask_cap_bset(vxi, p);
16479 +               task_unlock(p);
16480 +
16481 +               /* hack for *spaces to provide compatibility */
16482 +               if (unshare) {
16483 +                       struct nsproxy *old_nsp, *new_nsp;
16484 +
16485 +                       ret = unshare_nsproxy_namespaces(
16486 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16487 +                               &new_nsp, NULL);
16488 +                       if (ret)
16489 +                               goto out;
16490 +
16491 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16492 +                       vx_set_space(vxi,
16493 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16494 +                       put_nsproxy(old_nsp);
16495 +               }
16496 +       }
16497 +out:
16498 +       put_vx_info(old_vxi);
16499 +       return ret;
16500 +}
16501 +
16502 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16503 +{
16504 +       struct task_struct *old_reaper;
16505 +
16506 +       if (!vxi)
16507 +               return -EINVAL;
16508 +
16509 +       vxdprintk(VXD_CBIT(xid, 6),
16510 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16511 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16512 +
16513 +       old_reaper = vxi->vx_reaper;
16514 +       if (old_reaper == p)
16515 +               return 0;
16516 +
16517 +       /* set new child reaper */
16518 +       get_task_struct(p);
16519 +       vxi->vx_reaper = p;
16520 +       put_task_struct(old_reaper);
16521 +       return 0;
16522 +}
16523 +
16524 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16525 +{
16526 +       if (!vxi)
16527 +               return -EINVAL;
16528 +
16529 +       vxdprintk(VXD_CBIT(xid, 6),
16530 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16531 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16532 +
16533 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16534 +       // vxi->vx_initpid = p->tgid;
16535 +       vxi->vx_initpid = p->pid;
16536 +       return 0;
16537 +}
16538 +
16539 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16540 +{
16541 +       vxdprintk(VXD_CBIT(xid, 6),
16542 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16543 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16544 +
16545 +       vxi->exit_code = code;
16546 +       vxi->vx_initpid = 0;
16547 +}
16548 +
16549 +
16550 +void vx_set_persistent(struct vx_info *vxi)
16551 +{
16552 +       vxdprintk(VXD_CBIT(xid, 6),
16553 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16554 +
16555 +       get_vx_info(vxi);
16556 +       claim_vx_info(vxi, NULL);
16557 +}
16558 +
16559 +void vx_clear_persistent(struct vx_info *vxi)
16560 +{
16561 +       vxdprintk(VXD_CBIT(xid, 6),
16562 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16563 +
16564 +       release_vx_info(vxi, NULL);
16565 +       put_vx_info(vxi);
16566 +}
16567 +
16568 +void vx_update_persistent(struct vx_info *vxi)
16569 +{
16570 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16571 +               vx_set_persistent(vxi);
16572 +       else
16573 +               vx_clear_persistent(vxi);
16574 +}
16575 +
16576 +
16577 +/*     task must be current or locked          */
16578 +
16579 +void   exit_vx_info(struct task_struct *p, int code)
16580 +{
16581 +       struct vx_info *vxi = p->vx_info;
16582 +
16583 +       if (vxi) {
16584 +               atomic_dec(&vxi->cvirt.nr_threads);
16585 +               vx_nproc_dec(p);
16586 +
16587 +               vxi->exit_code = code;
16588 +               release_vx_info(vxi, p);
16589 +       }
16590 +}
16591 +
16592 +void   exit_vx_info_early(struct task_struct *p, int code)
16593 +{
16594 +       struct vx_info *vxi = p->vx_info;
16595 +
16596 +       if (vxi) {
16597 +               if (vxi->vx_initpid == p->pid)
16598 +                       vx_exit_init(vxi, p, code);
16599 +               if (vxi->vx_reaper == p)
16600 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16601 +       }
16602 +}
16603 +
16604 +
16605 +/* vserver syscall commands below here */
16606 +
16607 +/* taks xid and vx_info functions */
16608 +
16609 +#include <asm/uaccess.h>
16610 +
16611 +
16612 +int vc_task_xid(uint32_t id)
16613 +{
16614 +       xid_t xid;
16615 +
16616 +       if (id) {
16617 +               struct task_struct *tsk;
16618 +
16619 +               rcu_read_lock();
16620 +               tsk = find_task_by_real_pid(id);
16621 +               xid = (tsk) ? tsk->xid : -ESRCH;
16622 +               rcu_read_unlock();
16623 +       } else
16624 +               xid = vx_current_xid();
16625 +       return xid;
16626 +}
16627 +
16628 +
16629 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16630 +{
16631 +       struct vcmd_vx_info_v0 vc_data;
16632 +
16633 +       vc_data.xid = vxi->vx_id;
16634 +       vc_data.initpid = vxi->vx_initpid;
16635 +
16636 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16637 +               return -EFAULT;
16638 +       return 0;
16639 +}
16640 +
16641 +
16642 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16643 +{
16644 +       struct vcmd_ctx_stat_v0 vc_data;
16645 +
16646 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16647 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16648 +
16649 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16650 +               return -EFAULT;
16651 +       return 0;
16652 +}
16653 +
16654 +
16655 +/* context functions */
16656 +
16657 +int vc_ctx_create(uint32_t xid, void __user *data)
16658 +{
16659 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16660 +       struct vx_info *new_vxi;
16661 +       int ret;
16662 +
16663 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16664 +               return -EFAULT;
16665 +
16666 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16667 +               return -EINVAL;
16668 +
16669 +       new_vxi = __create_vx_info(xid);
16670 +       if (IS_ERR(new_vxi))
16671 +               return PTR_ERR(new_vxi);
16672 +
16673 +       /* initial flags */
16674 +       new_vxi->vx_flags = vc_data.flagword;
16675 +
16676 +       ret = -ENOEXEC;
16677 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16678 +               goto out;
16679 +
16680 +       ret = vx_migrate_task(current, new_vxi, (!data));
16681 +       if (ret)
16682 +               goto out;
16683 +
16684 +       /* return context id on success */
16685 +       ret = new_vxi->vx_id;
16686 +
16687 +       /* get a reference for persistent contexts */
16688 +       if ((vc_data.flagword & VXF_PERSISTENT))
16689 +               vx_set_persistent(new_vxi);
16690 +out:
16691 +       release_vx_info(new_vxi, NULL);
16692 +       put_vx_info(new_vxi);
16693 +       return ret;
16694 +}
16695 +
16696 +
16697 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16698 +{
16699 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16700 +       int ret;
16701 +
16702 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16703 +               return -EFAULT;
16704 +
16705 +       ret = vx_migrate_task(current, vxi, 0);
16706 +       if (ret)
16707 +               return ret;
16708 +       if (vc_data.flagword & VXM_SET_INIT)
16709 +               ret = vx_set_init(vxi, current);
16710 +       if (ret)
16711 +               return ret;
16712 +       if (vc_data.flagword & VXM_SET_REAPER)
16713 +               ret = vx_set_reaper(vxi, current);
16714 +       return ret;
16715 +}
16716 +
16717 +
16718 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16719 +{
16720 +       struct vcmd_ctx_flags_v0 vc_data;
16721 +
16722 +       vc_data.flagword = vxi->vx_flags;
16723 +
16724 +       /* special STATE flag handling */
16725 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16726 +
16727 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16728 +               return -EFAULT;
16729 +       return 0;
16730 +}
16731 +
16732 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16733 +{
16734 +       struct vcmd_ctx_flags_v0 vc_data;
16735 +       uint64_t mask, trigger;
16736 +
16737 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16738 +               return -EFAULT;
16739 +
16740 +       /* special STATE flag handling */
16741 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16742 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16743 +
16744 +       if (vxi == current_vx_info()) {
16745 +               /* if (trigger & VXF_STATE_SETUP)
16746 +                       vx_mask_cap_bset(vxi, current); */
16747 +               if (trigger & VXF_STATE_INIT) {
16748 +                       int ret;
16749 +
16750 +                       ret = vx_set_init(vxi, current);
16751 +                       if (ret)
16752 +                               return ret;
16753 +                       ret = vx_set_reaper(vxi, current);
16754 +                       if (ret)
16755 +                               return ret;
16756 +               }
16757 +       }
16758 +
16759 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16760 +               vc_data.flagword, mask);
16761 +       if (trigger & VXF_PERSISTENT)
16762 +               vx_update_persistent(vxi);
16763 +
16764 +       return 0;
16765 +}
16766 +
16767 +
16768 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16769 +{
16770 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16771 +
16772 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16773 +       return v;
16774 +}
16775 +
16776 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16777 +{
16778 +       kernel_cap_t c = __cap_empty_set;
16779 +
16780 +       c.cap[0] = v & 0xFFFFFFFF;
16781 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16782 +
16783 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16784 +       return c;
16785 +}
16786 +
16787 +
16788 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16789 +{
16790 +       if (bcaps)
16791 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16792 +       if (ccaps)
16793 +               *ccaps = vxi->vx_ccaps;
16794 +
16795 +       return 0;
16796 +}
16797 +
16798 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16799 +{
16800 +       struct vcmd_ctx_caps_v1 vc_data;
16801 +       int ret;
16802 +
16803 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16804 +       if (ret)
16805 +               return ret;
16806 +       vc_data.cmask = ~0ULL;
16807 +
16808 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16809 +               return -EFAULT;
16810 +       return 0;
16811 +}
16812 +
16813 +static int do_set_caps(struct vx_info *vxi,
16814 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16815 +{
16816 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16817 +
16818 +#if 0
16819 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16820 +               bcaps, bmask, ccaps, cmask);
16821 +#endif
16822 +       vxi->vx_bcaps = cap_t_from_caps(
16823 +               vs_mask_flags(bcold, bcaps, bmask));
16824 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16825 +
16826 +       return 0;
16827 +}
16828 +
16829 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16830 +{
16831 +       struct vcmd_ctx_caps_v1 vc_data;
16832 +
16833 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16834 +               return -EFAULT;
16835 +
16836 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16837 +}
16838 +
16839 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16840 +{
16841 +       struct vcmd_bcaps vc_data;
16842 +       int ret;
16843 +
16844 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16845 +       if (ret)
16846 +               return ret;
16847 +       vc_data.bmask = ~0ULL;
16848 +
16849 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16850 +               return -EFAULT;
16851 +       return 0;
16852 +}
16853 +
16854 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16855 +{
16856 +       struct vcmd_bcaps vc_data;
16857 +
16858 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16859 +               return -EFAULT;
16860 +
16861 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16862 +}
16863 +
16864 +
16865 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16866 +{
16867 +       struct vcmd_umask vc_data;
16868 +
16869 +       vc_data.umask = vxi->vx_umask;
16870 +       vc_data.mask = ~0ULL;
16871 +
16872 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16873 +               return -EFAULT;
16874 +       return 0;
16875 +}
16876 +
16877 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16878 +{
16879 +       struct vcmd_umask vc_data;
16880 +
16881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16882 +               return -EFAULT;
16883 +
16884 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16885 +               vc_data.umask, vc_data.mask);
16886 +       return 0;
16887 +}
16888 +
16889 +
16890 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16891 +{
16892 +       struct vcmd_wmask vc_data;
16893 +
16894 +       vc_data.wmask = vxi->vx_wmask;
16895 +       vc_data.mask = ~0ULL;
16896 +
16897 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16898 +               return -EFAULT;
16899 +       return 0;
16900 +}
16901 +
16902 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16903 +{
16904 +       struct vcmd_wmask vc_data;
16905 +
16906 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16907 +               return -EFAULT;
16908 +
16909 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16910 +               vc_data.wmask, vc_data.mask);
16911 +       return 0;
16912 +}
16913 +
16914 +
16915 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16916 +{
16917 +       struct vcmd_badness_v0 vc_data;
16918 +
16919 +       vc_data.bias = vxi->vx_badness_bias;
16920 +
16921 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16922 +               return -EFAULT;
16923 +       return 0;
16924 +}
16925 +
16926 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16927 +{
16928 +       struct vcmd_badness_v0 vc_data;
16929 +
16930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16931 +               return -EFAULT;
16932 +
16933 +       vxi->vx_badness_bias = vc_data.bias;
16934 +       return 0;
16935 +}
16936 +
16937 +#include <linux/module.h>
16938 +
16939 +EXPORT_SYMBOL_GPL(free_vx_info);
16940 +
16941 diff -NurpP --minimal linux-3.3.1/kernel/vserver/cvirt.c linux-3.3.1-vs2.3.3.2/kernel/vserver/cvirt.c
16942 --- linux-3.3.1/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
16943 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/cvirt.c        2012-02-24 03:55:06.000000000 +0100
16944 @@ -0,0 +1,303 @@
16945 +/*
16946 + *  linux/kernel/vserver/cvirt.c
16947 + *
16948 + *  Virtual Server: Context Virtualization
16949 + *
16950 + *  Copyright (C) 2004-2007  Herbert Pötzl
16951 + *
16952 + *  V0.01  broken out from limit.c
16953 + *  V0.02  added utsname stuff
16954 + *  V0.03  changed vcmds to vxi arg
16955 + *
16956 + */
16957 +
16958 +#include <linux/types.h>
16959 +#include <linux/utsname.h>
16960 +#include <linux/vs_cvirt.h>
16961 +#include <linux/vserver/switch.h>
16962 +#include <linux/vserver/cvirt_cmd.h>
16963 +
16964 +#include <asm/uaccess.h>
16965 +
16966 +
16967 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16968 +{
16969 +       struct vx_info *vxi = current_vx_info();
16970 +
16971 +       set_normalized_timespec(uptime,
16972 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16973 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16974 +       if (!idle)
16975 +               return;
16976 +       set_normalized_timespec(idle,
16977 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16978 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16979 +       return;
16980 +}
16981 +
16982 +uint64_t vx_idle_jiffies(void)
16983 +{
16984 +       return init_task.utime + init_task.stime;
16985 +}
16986 +
16987 +
16988 +
16989 +static inline uint32_t __update_loadavg(uint32_t load,
16990 +       int wsize, int delta, int n)
16991 +{
16992 +       unsigned long long calc, prev;
16993 +
16994 +       /* just set it to n */
16995 +       if (unlikely(delta >= wsize))
16996 +               return (n << FSHIFT);
16997 +
16998 +       calc = delta * n;
16999 +       calc <<= FSHIFT;
17000 +       prev = (wsize - delta);
17001 +       prev *= load;
17002 +       calc += prev;
17003 +       do_div(calc, wsize);
17004 +       return calc;
17005 +}
17006 +
17007 +
17008 +void vx_update_load(struct vx_info *vxi)
17009 +{
17010 +       uint32_t now, last, delta;
17011 +       unsigned int nr_running, nr_uninterruptible;
17012 +       unsigned int total;
17013 +       unsigned long flags;
17014 +
17015 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17016 +
17017 +       now = jiffies;
17018 +       last = vxi->cvirt.load_last;
17019 +       delta = now - last;
17020 +
17021 +       if (delta < 5*HZ)
17022 +               goto out;
17023 +
17024 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17025 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17026 +       total = nr_running + nr_uninterruptible;
17027 +
17028 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17029 +               60*HZ, delta, total);
17030 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17031 +               5*60*HZ, delta, total);
17032 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17033 +               15*60*HZ, delta, total);
17034 +
17035 +       vxi->cvirt.load_last = now;
17036 +out:
17037 +       atomic_inc(&vxi->cvirt.load_updates);
17038 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17039 +}
17040 +
17041 +
17042 +/*
17043 + * Commands to do_syslog:
17044 + *
17045 + *      0 -- Close the log.  Currently a NOP.
17046 + *      1 -- Open the log. Currently a NOP.
17047 + *      2 -- Read from the log.
17048 + *      3 -- Read all messages remaining in the ring buffer.
17049 + *      4 -- Read and clear all messages remaining in the ring buffer
17050 + *      5 -- Clear ring buffer.
17051 + *      6 -- Disable printk's to console
17052 + *      7 -- Enable printk's to console
17053 + *      8 -- Set level of messages printed to console
17054 + *      9 -- Return number of unread characters in the log buffer
17055 + *     10 -- Return size of the log buffer
17056 + */
17057 +int vx_do_syslog(int type, char __user *buf, int len)
17058 +{
17059 +       int error = 0;
17060 +       int do_clear = 0;
17061 +       struct vx_info *vxi = current_vx_info();
17062 +       struct _vx_syslog *log;
17063 +
17064 +       if (!vxi)
17065 +               return -EINVAL;
17066 +       log = &vxi->cvirt.syslog;
17067 +
17068 +       switch (type) {
17069 +       case 0:         /* Close log */
17070 +       case 1:         /* Open log */
17071 +               break;
17072 +       case 2:         /* Read from log */
17073 +               error = wait_event_interruptible(log->log_wait,
17074 +                       (log->log_start - log->log_end));
17075 +               if (error)
17076 +                       break;
17077 +               spin_lock_irq(&log->logbuf_lock);
17078 +               spin_unlock_irq(&log->logbuf_lock);
17079 +               break;
17080 +       case 4:         /* Read/clear last kernel messages */
17081 +               do_clear = 1;
17082 +               /* fall through */
17083 +       case 3:         /* Read last kernel messages */
17084 +               return 0;
17085 +
17086 +       case 5:         /* Clear ring buffer */
17087 +               return 0;
17088 +
17089 +       case 6:         /* Disable logging to console */
17090 +       case 7:         /* Enable logging to console */
17091 +       case 8:         /* Set level of messages printed to console */
17092 +               break;
17093 +
17094 +       case 9:         /* Number of chars in the log buffer */
17095 +               return 0;
17096 +       case 10:        /* Size of the log buffer */
17097 +               return 0;
17098 +       default:
17099 +               error = -EINVAL;
17100 +               break;
17101 +       }
17102 +       return error;
17103 +}
17104 +
17105 +
17106 +/* virtual host info names */
17107 +
17108 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17109 +{
17110 +       struct nsproxy *nsproxy;
17111 +       struct uts_namespace *uts;
17112 +
17113 +       if (id == VHIN_CONTEXT)
17114 +               return vxi->vx_name;
17115 +
17116 +       nsproxy = vxi->space[0].vx_nsproxy;
17117 +       if (!nsproxy)
17118 +               return NULL;
17119 +
17120 +       uts = nsproxy->uts_ns;
17121 +       if (!uts)
17122 +               return NULL;
17123 +
17124 +       switch (id) {
17125 +       case VHIN_SYSNAME:
17126 +               return uts->name.sysname;
17127 +       case VHIN_NODENAME:
17128 +               return uts->name.nodename;
17129 +       case VHIN_RELEASE:
17130 +               return uts->name.release;
17131 +       case VHIN_VERSION:
17132 +               return uts->name.version;
17133 +       case VHIN_MACHINE:
17134 +               return uts->name.machine;
17135 +       case VHIN_DOMAINNAME:
17136 +               return uts->name.domainname;
17137 +       default:
17138 +               return NULL;
17139 +       }
17140 +       return NULL;
17141 +}
17142 +
17143 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17144 +{
17145 +       struct vcmd_vhi_name_v0 vc_data;
17146 +       char *name;
17147 +
17148 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17149 +               return -EFAULT;
17150 +
17151 +       name = vx_vhi_name(vxi, vc_data.field);
17152 +       if (!name)
17153 +               return -EINVAL;
17154 +
17155 +       memcpy(name, vc_data.name, 65);
17156 +       return 0;
17157 +}
17158 +
17159 +int vc_get_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(vc_data.name, name, 65);
17172 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17173 +               return -EFAULT;
17174 +       return 0;
17175 +}
17176 +
17177 +
17178 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17179 +{
17180 +       struct vcmd_virt_stat_v0 vc_data;
17181 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17182 +       struct timespec uptime;
17183 +
17184 +       do_posix_clock_monotonic_gettime(&uptime);
17185 +       set_normalized_timespec(&uptime,
17186 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17187 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17188 +
17189 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17190 +       vc_data.uptime = timespec_to_ns(&uptime);
17191 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17192 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17193 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17194 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17195 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17196 +       vc_data.load[0] = cvirt->load[0];
17197 +       vc_data.load[1] = cvirt->load[1];
17198 +       vc_data.load[2] = cvirt->load[2];
17199 +
17200 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17201 +               return -EFAULT;
17202 +       return 0;
17203 +}
17204 +
17205 +
17206 +#ifdef CONFIG_VSERVER_VTIME
17207 +
17208 +/* virtualized time base */
17209 +
17210 +void vx_adjust_timespec(struct timespec *ts)
17211 +{
17212 +       struct vx_info *vxi;
17213 +
17214 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17215 +               return;
17216 +
17217 +       vxi = current_vx_info();
17218 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17219 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17220 +
17221 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17222 +               ts->tv_sec++;
17223 +               ts->tv_nsec -= NSEC_PER_SEC;
17224 +       } else if (ts->tv_nsec < 0) {
17225 +               ts->tv_sec--;
17226 +               ts->tv_nsec += NSEC_PER_SEC;
17227 +       }
17228 +}
17229 +
17230 +int vx_settimeofday(const struct timespec *ts)
17231 +{
17232 +       struct timespec ats, delta;
17233 +       struct vx_info *vxi;
17234 +
17235 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17236 +               return do_settimeofday(ts);
17237 +
17238 +       getnstimeofday(&ats);
17239 +       delta = timespec_sub(*ts, ats);
17240 +
17241 +       vxi = current_vx_info();
17242 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17243 +       return 0;
17244 +}
17245 +
17246 +#endif
17247 +
17248 diff -NurpP --minimal linux-3.3.1/kernel/vserver/cvirt_init.h linux-3.3.1-vs2.3.3.2/kernel/vserver/cvirt_init.h
17249 --- linux-3.3.1/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17250 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/cvirt_init.h   2012-02-24 03:55:06.000000000 +0100
17251 @@ -0,0 +1,70 @@
17252 +
17253 +
17254 +extern uint64_t vx_idle_jiffies(void);
17255 +
17256 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17257 +{
17258 +       uint64_t idle_jiffies = vx_idle_jiffies();
17259 +       uint64_t nsuptime;
17260 +
17261 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17262 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17263 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17264 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17265 +       cvirt->bias_ts.tv_sec = 0;
17266 +       cvirt->bias_ts.tv_nsec = 0;
17267 +
17268 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17269 +       atomic_set(&cvirt->nr_threads, 0);
17270 +       atomic_set(&cvirt->nr_running, 0);
17271 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17272 +       atomic_set(&cvirt->nr_onhold, 0);
17273 +
17274 +       spin_lock_init(&cvirt->load_lock);
17275 +       cvirt->load_last = jiffies;
17276 +       atomic_set(&cvirt->load_updates, 0);
17277 +       cvirt->load[0] = 0;
17278 +       cvirt->load[1] = 0;
17279 +       cvirt->load[2] = 0;
17280 +       atomic_set(&cvirt->total_forks, 0);
17281 +
17282 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17283 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17284 +       cvirt->syslog.log_start = 0;
17285 +       cvirt->syslog.log_end = 0;
17286 +       cvirt->syslog.con_start = 0;
17287 +       cvirt->syslog.logged_chars = 0;
17288 +}
17289 +
17290 +static inline
17291 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17292 +{
17293 +       // cvirt_pc->cpustat = { 0 };
17294 +}
17295 +
17296 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17297 +{
17298 +#ifdef CONFIG_VSERVER_WARN
17299 +       int value;
17300 +#endif
17301 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17302 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17303 +               cvirt, value);
17304 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17305 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17306 +               cvirt, value);
17307 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17308 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17309 +               cvirt, value);
17310 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17311 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17312 +               cvirt, value);
17313 +       return;
17314 +}
17315 +
17316 +static inline
17317 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17318 +{
17319 +       return;
17320 +}
17321 +
17322 diff -NurpP --minimal linux-3.3.1/kernel/vserver/cvirt_proc.h linux-3.3.1-vs2.3.3.2/kernel/vserver/cvirt_proc.h
17323 --- linux-3.3.1/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17324 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/cvirt_proc.h   2012-02-24 17:26:10.000000000 +0100
17325 @@ -0,0 +1,137 @@
17326 +#ifndef _VX_CVIRT_PROC_H
17327 +#define _VX_CVIRT_PROC_H
17328 +
17329 +#include <linux/nsproxy.h>
17330 +#include <linux/mnt_namespace.h>
17331 +#include <linux/ipc_namespace.h>
17332 +#include <linux/utsname.h>
17333 +#include <linux/ipc.h>
17334 +
17335 +
17336 +static inline
17337 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17338 +{
17339 +       struct mnt_namespace *ns;
17340 +       struct uts_namespace *uts;
17341 +       struct ipc_namespace *ipc;
17342 +       struct path path;
17343 +       char *pstr, *root;
17344 +       int length = 0;
17345 +
17346 +       if (!nsproxy)
17347 +               goto out;
17348 +
17349 +       length += sprintf(buffer + length,
17350 +               "NSProxy:\t%p [%p,%p,%p]\n",
17351 +               nsproxy, nsproxy->mnt_ns,
17352 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17353 +
17354 +       ns = nsproxy->mnt_ns;
17355 +       if (!ns)
17356 +               goto skip_ns;
17357 +
17358 +/*     FIXME: move to fs?
17359 +
17360 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17361 +       if (!pstr)
17362 +               goto skip_ns;
17363 +
17364 +       path.mnt = ns->root;
17365 +       path.dentry = ns->root->mnt_root;
17366 +       root = d_path(&path, pstr, PATH_MAX - 2);
17367 +       length += sprintf(buffer + length,
17368 +               "Namespace:\t%p [#%u]\n"
17369 +               "RootPath:\t%s\n",
17370 +               ns, atomic_read(&ns->count),
17371 +               root);
17372 +       kfree(pstr); */
17373 +skip_ns:
17374 +
17375 +       uts = nsproxy->uts_ns;
17376 +       if (!uts)
17377 +               goto skip_uts;
17378 +
17379 +       length += sprintf(buffer + length,
17380 +               "SysName:\t%.*s\n"
17381 +               "NodeName:\t%.*s\n"
17382 +               "Release:\t%.*s\n"
17383 +               "Version:\t%.*s\n"
17384 +               "Machine:\t%.*s\n"
17385 +               "DomainName:\t%.*s\n",
17386 +               __NEW_UTS_LEN, uts->name.sysname,
17387 +               __NEW_UTS_LEN, uts->name.nodename,
17388 +               __NEW_UTS_LEN, uts->name.release,
17389 +               __NEW_UTS_LEN, uts->name.version,
17390 +               __NEW_UTS_LEN, uts->name.machine,
17391 +               __NEW_UTS_LEN, uts->name.domainname);
17392 +skip_uts:
17393 +
17394 +       ipc = nsproxy->ipc_ns;
17395 +       if (!ipc)
17396 +               goto skip_ipc;
17397 +
17398 +       length += sprintf(buffer + length,
17399 +               "SEMS:\t\t%d %d %d %d  %d\n"
17400 +               "MSG:\t\t%d %d %d\n"
17401 +               "SHM:\t\t%lu %lu  %d %d\n",
17402 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17403 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17404 +               ipc->used_sems,
17405 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17406 +               (unsigned long)ipc->shm_ctlmax,
17407 +               (unsigned long)ipc->shm_ctlall,
17408 +               ipc->shm_ctlmni, ipc->shm_tot);
17409 +skip_ipc:
17410 +out:
17411 +       return length;
17412 +}
17413 +
17414 +
17415 +#include <linux/sched.h>
17416 +
17417 +#define LOAD_INT(x) ((x) >> FSHIFT)
17418 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17419 +
17420 +static inline
17421 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17422 +{
17423 +       int length = 0;
17424 +       int a, b, c;
17425 +
17426 +       length += sprintf(buffer + length,
17427 +               "BiasUptime:\t%lu.%02lu\n",
17428 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17429 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17430 +
17431 +       a = cvirt->load[0] + (FIXED_1 / 200);
17432 +       b = cvirt->load[1] + (FIXED_1 / 200);
17433 +       c = cvirt->load[2] + (FIXED_1 / 200);
17434 +       length += sprintf(buffer + length,
17435 +               "nr_threads:\t%d\n"
17436 +               "nr_running:\t%d\n"
17437 +               "nr_unintr:\t%d\n"
17438 +               "nr_onhold:\t%d\n"
17439 +               "load_updates:\t%d\n"
17440 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17441 +               "total_forks:\t%d\n",
17442 +               atomic_read(&cvirt->nr_threads),
17443 +               atomic_read(&cvirt->nr_running),
17444 +               atomic_read(&cvirt->nr_uninterruptible),
17445 +               atomic_read(&cvirt->nr_onhold),
17446 +               atomic_read(&cvirt->load_updates),
17447 +               LOAD_INT(a), LOAD_FRAC(a),
17448 +               LOAD_INT(b), LOAD_FRAC(b),
17449 +               LOAD_INT(c), LOAD_FRAC(c),
17450 +               atomic_read(&cvirt->total_forks));
17451 +       return length;
17452 +}
17453 +
17454 +static inline
17455 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17456 +       char *buffer, int cpu)
17457 +{
17458 +       int length = 0;
17459 +       return length;
17460 +}
17461 +
17462 +#endif /* _VX_CVIRT_PROC_H */
17463 diff -NurpP --minimal linux-3.3.1/kernel/vserver/debug.c linux-3.3.1-vs2.3.3.2/kernel/vserver/debug.c
17464 --- linux-3.3.1/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17465 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/debug.c        2012-02-24 03:55:06.000000000 +0100
17466 @@ -0,0 +1,32 @@
17467 +/*
17468 + *  kernel/vserver/debug.c
17469 + *
17470 + *  Copyright (C) 2005-2007 Herbert Pötzl
17471 + *
17472 + *  V0.01  vx_info dump support
17473 + *
17474 + */
17475 +
17476 +#include <linux/module.h>
17477 +
17478 +#include <linux/vserver/context.h>
17479 +
17480 +
17481 +void   dump_vx_info(struct vx_info *vxi, int level)
17482 +{
17483 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17484 +               atomic_read(&vxi->vx_usecnt),
17485 +               atomic_read(&vxi->vx_tasks),
17486 +               vxi->vx_state);
17487 +       if (level > 0) {
17488 +               __dump_vx_limit(&vxi->limit);
17489 +               __dump_vx_sched(&vxi->sched);
17490 +               __dump_vx_cvirt(&vxi->cvirt);
17491 +               __dump_vx_cacct(&vxi->cacct);
17492 +       }
17493 +       printk("---\n");
17494 +}
17495 +
17496 +
17497 +EXPORT_SYMBOL_GPL(dump_vx_info);
17498 +
17499 diff -NurpP --minimal linux-3.3.1/kernel/vserver/device.c linux-3.3.1-vs2.3.3.2/kernel/vserver/device.c
17500 --- linux-3.3.1/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17501 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/device.c       2012-02-24 03:55:07.000000000 +0100
17502 @@ -0,0 +1,443 @@
17503 +/*
17504 + *  linux/kernel/vserver/device.c
17505 + *
17506 + *  Linux-VServer: Device Support
17507 + *
17508 + *  Copyright (C) 2006  Herbert Pötzl
17509 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17510 + *
17511 + *  V0.01  device mapping basics
17512 + *  V0.02  added defaults
17513 + *
17514 + */
17515 +
17516 +#include <linux/slab.h>
17517 +#include <linux/rcupdate.h>
17518 +#include <linux/fs.h>
17519 +#include <linux/namei.h>
17520 +#include <linux/hash.h>
17521 +
17522 +#include <asm/errno.h>
17523 +#include <asm/uaccess.h>
17524 +#include <linux/vserver/base.h>
17525 +#include <linux/vserver/debug.h>
17526 +#include <linux/vserver/context.h>
17527 +#include <linux/vserver/device.h>
17528 +#include <linux/vserver/device_cmd.h>
17529 +
17530 +
17531 +#define DMAP_HASH_BITS 4
17532 +
17533 +
17534 +struct vs_mapping {
17535 +       union {
17536 +               struct hlist_node hlist;
17537 +               struct list_head list;
17538 +       } u;
17539 +#define dm_hlist       u.hlist
17540 +#define dm_list                u.list
17541 +       xid_t xid;
17542 +       dev_t device;
17543 +       struct vx_dmap_target target;
17544 +};
17545 +
17546 +
17547 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17548 +
17549 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17550 +
17551 +static struct vx_dmap_target dmap_defaults[2] = {
17552 +       { .flags = DATTR_OPEN },
17553 +       { .flags = DATTR_OPEN },
17554 +};
17555 +
17556 +
17557 +struct kmem_cache *dmap_cachep __read_mostly;
17558 +
17559 +int __init dmap_cache_init(void)
17560 +{
17561 +       dmap_cachep = kmem_cache_create("dmap_cache",
17562 +               sizeof(struct vs_mapping), 0,
17563 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17564 +       return 0;
17565 +}
17566 +
17567 +__initcall(dmap_cache_init);
17568 +
17569 +
17570 +static inline unsigned int __hashval(dev_t dev, int bits)
17571 +{
17572 +       return hash_long((unsigned long)dev, bits);
17573 +}
17574 +
17575 +
17576 +/*     __hash_mapping()
17577 + *     add the mapping to the hash table
17578 + */
17579 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17580 +{
17581 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17582 +       struct hlist_head *head, *hash = dmap_main_hash;
17583 +       int device = vdm->device;
17584 +
17585 +       spin_lock(hash_lock);
17586 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17587 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17588 +
17589 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17590 +       hlist_add_head(&vdm->dm_hlist, head);
17591 +       spin_unlock(hash_lock);
17592 +}
17593 +
17594 +
17595 +static inline int __mode_to_default(umode_t mode)
17596 +{
17597 +       switch (mode) {
17598 +       case S_IFBLK:
17599 +               return 0;
17600 +       case S_IFCHR:
17601 +               return 1;
17602 +       default:
17603 +               BUG();
17604 +       }
17605 +}
17606 +
17607 +
17608 +/*     __set_default()
17609 + *     set a default
17610 + */
17611 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17612 +       struct vx_dmap_target *vdmt)
17613 +{
17614 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17615 +       spin_lock(hash_lock);
17616 +
17617 +       if (vxi)
17618 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17619 +       else
17620 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17621 +
17622 +
17623 +       spin_unlock(hash_lock);
17624 +
17625 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17626 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17627 +}
17628 +
17629 +
17630 +/*     __remove_default()
17631 + *     remove a default
17632 + */
17633 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17634 +{
17635 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17636 +       spin_lock(hash_lock);
17637 +
17638 +       if (vxi)
17639 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17640 +       else    /* remove == reset */
17641 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17642 +
17643 +       spin_unlock(hash_lock);
17644 +       return 0;
17645 +}
17646 +
17647 +
17648 +/*     __find_mapping()
17649 + *     find a mapping in the hash table
17650 + *
17651 + *     caller must hold hash_lock
17652 + */
17653 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17654 +       struct vs_mapping **local, struct vs_mapping **global)
17655 +{
17656 +       struct hlist_head *hash = dmap_main_hash;
17657 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17658 +       struct hlist_node *pos;
17659 +       struct vs_mapping *vdm;
17660 +
17661 +       *local = NULL;
17662 +       if (global)
17663 +               *global = NULL;
17664 +
17665 +       hlist_for_each(pos, head) {
17666 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17667 +
17668 +               if ((vdm->device == device) &&
17669 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17670 +                       if (vdm->xid == xid) {
17671 +                               *local = vdm;
17672 +                               return 1;
17673 +                       } else if (global && vdm->xid == 0)
17674 +                               *global = vdm;
17675 +               }
17676 +       }
17677 +
17678 +       if (global && *global)
17679 +               return 0;
17680 +       else
17681 +               return -ENOENT;
17682 +}
17683 +
17684 +
17685 +/*     __lookup_mapping()
17686 + *     find a mapping and store the result in target and flags
17687 + */
17688 +static inline int __lookup_mapping(struct vx_info *vxi,
17689 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17690 +{
17691 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17692 +       struct vs_mapping *vdm, *global;
17693 +       struct vx_dmap_target *vdmt;
17694 +       int ret = 0;
17695 +       xid_t xid = vxi->vx_id;
17696 +       int index;
17697 +
17698 +       spin_lock(hash_lock);
17699 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17700 +               ret = 1;
17701 +               vdmt = &vdm->target;
17702 +               goto found;
17703 +       }
17704 +
17705 +       index = __mode_to_default(mode);
17706 +       if (vxi && vxi->dmap.targets[index].flags) {
17707 +               ret = 2;
17708 +               vdmt = &vxi->dmap.targets[index];
17709 +       } else if (global) {
17710 +               ret = 3;
17711 +               vdmt = &global->target;
17712 +               goto found;
17713 +       } else {
17714 +               ret = 4;
17715 +               vdmt = &dmap_defaults[index];
17716 +       }
17717 +
17718 +found:
17719 +       if (target && (vdmt->flags & DATTR_REMAP))
17720 +               *target = vdmt->target;
17721 +       else if (target)
17722 +               *target = device;
17723 +       if (flags)
17724 +               *flags = vdmt->flags;
17725 +
17726 +       spin_unlock(hash_lock);
17727 +
17728 +       return ret;
17729 +}
17730 +
17731 +
17732 +/*     __remove_mapping()
17733 + *     remove a mapping from the hash table
17734 + */
17735 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17736 +       umode_t mode)
17737 +{
17738 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17739 +       struct vs_mapping *vdm = NULL;
17740 +       int ret = 0;
17741 +
17742 +       spin_lock(hash_lock);
17743 +
17744 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17745 +               NULL);
17746 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17747 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17748 +       if (ret < 0)
17749 +               goto out;
17750 +       hlist_del(&vdm->dm_hlist);
17751 +
17752 +out:
17753 +       spin_unlock(hash_lock);
17754 +       if (vdm)
17755 +               kmem_cache_free(dmap_cachep, vdm);
17756 +       return ret;
17757 +}
17758 +
17759 +
17760 +
17761 +int vs_map_device(struct vx_info *vxi,
17762 +       dev_t device, dev_t *target, umode_t mode)
17763 +{
17764 +       int ret, flags = DATTR_MASK;
17765 +
17766 +       if (!vxi) {
17767 +               if (target)
17768 +                       *target = device;
17769 +               goto out;
17770 +       }
17771 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17772 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17773 +               device, target ? *target : 0, flags, mode, ret);
17774 +out:
17775 +       return (flags & DATTR_MASK);
17776 +}
17777 +
17778 +
17779 +
17780 +static int do_set_mapping(struct vx_info *vxi,
17781 +       dev_t device, dev_t target, int flags, umode_t mode)
17782 +{
17783 +       if (device) {
17784 +               struct vs_mapping *new;
17785 +
17786 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17787 +               if (!new)
17788 +                       return -ENOMEM;
17789 +
17790 +               INIT_HLIST_NODE(&new->dm_hlist);
17791 +               new->device = device;
17792 +               new->target.target = target;
17793 +               new->target.flags = flags | mode;
17794 +               new->xid = (vxi ? vxi->vx_id : 0);
17795 +
17796 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17797 +               __hash_mapping(vxi, new);
17798 +       } else {
17799 +               struct vx_dmap_target new = {
17800 +                       .target = target,
17801 +                       .flags = flags | mode,
17802 +               };
17803 +               __set_default(vxi, mode, &new);
17804 +       }
17805 +       return 0;
17806 +}
17807 +
17808 +
17809 +static int do_unset_mapping(struct vx_info *vxi,
17810 +       dev_t device, dev_t target, int flags, umode_t mode)
17811 +{
17812 +       int ret = -EINVAL;
17813 +
17814 +       if (device) {
17815 +               ret = __remove_mapping(vxi, device, mode);
17816 +               if (ret < 0)
17817 +                       goto out;
17818 +       } else {
17819 +               ret = __remove_default(vxi, mode);
17820 +               if (ret < 0)
17821 +                       goto out;
17822 +       }
17823 +
17824 +out:
17825 +       return ret;
17826 +}
17827 +
17828 +
17829 +static inline int __user_device(const char __user *name, dev_t *dev,
17830 +       umode_t *mode)
17831 +{
17832 +       struct nameidata nd;
17833 +       int ret;
17834 +
17835 +       if (!name) {
17836 +               *dev = 0;
17837 +               return 0;
17838 +       }
17839 +       ret = user_lpath(name, &nd.path);
17840 +       if (ret)
17841 +               return ret;
17842 +       if (nd.path.dentry->d_inode) {
17843 +               *dev = nd.path.dentry->d_inode->i_rdev;
17844 +               *mode = nd.path.dentry->d_inode->i_mode;
17845 +       }
17846 +       path_put(&nd.path);
17847 +       return 0;
17848 +}
17849 +
17850 +static inline int __mapping_mode(dev_t device, dev_t target,
17851 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17852 +{
17853 +       if (device)
17854 +               *mode = device_mode & S_IFMT;
17855 +       else if (target)
17856 +               *mode = target_mode & S_IFMT;
17857 +       else
17858 +               return -EINVAL;
17859 +
17860 +       /* if both given, device and target mode have to match */
17861 +       if (device && target &&
17862 +               ((device_mode ^ target_mode) & S_IFMT))
17863 +               return -EINVAL;
17864 +       return 0;
17865 +}
17866 +
17867 +
17868 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17869 +       const char __user *target_path, int flags, int set)
17870 +{
17871 +       dev_t device = ~0, target = ~0;
17872 +       umode_t device_mode = 0, target_mode = 0, mode;
17873 +       int ret;
17874 +
17875 +       ret = __user_device(device_path, &device, &device_mode);
17876 +       if (ret)
17877 +               return ret;
17878 +       ret = __user_device(target_path, &target, &target_mode);
17879 +       if (ret)
17880 +               return ret;
17881 +
17882 +       ret = __mapping_mode(device, target,
17883 +               device_mode, target_mode, &mode);
17884 +       if (ret)
17885 +               return ret;
17886 +
17887 +       if (set)
17888 +               return do_set_mapping(vxi, device, target,
17889 +                       flags, mode);
17890 +       else
17891 +               return do_unset_mapping(vxi, device, target,
17892 +                       flags, mode);
17893 +}
17894 +
17895 +
17896 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17897 +{
17898 +       struct vcmd_set_mapping_v0 vc_data;
17899 +
17900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17901 +               return -EFAULT;
17902 +
17903 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17904 +               vc_data.flags, 1);
17905 +}
17906 +
17907 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17908 +{
17909 +       struct vcmd_set_mapping_v0 vc_data;
17910 +
17911 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17912 +               return -EFAULT;
17913 +
17914 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17915 +               vc_data.flags, 0);
17916 +}
17917 +
17918 +
17919 +#ifdef CONFIG_COMPAT
17920 +
17921 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17922 +{
17923 +       struct vcmd_set_mapping_v0_x32 vc_data;
17924 +
17925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17926 +               return -EFAULT;
17927 +
17928 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17929 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17930 +}
17931 +
17932 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17933 +{
17934 +       struct vcmd_set_mapping_v0_x32 vc_data;
17935 +
17936 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17937 +               return -EFAULT;
17938 +
17939 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17940 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17941 +}
17942 +
17943 +#endif /* CONFIG_COMPAT */
17944 +
17945 +
17946 diff -NurpP --minimal linux-3.3.1/kernel/vserver/dlimit.c linux-3.3.1-vs2.3.3.2/kernel/vserver/dlimit.c
17947 --- linux-3.3.1/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17948 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/dlimit.c       2012-02-24 03:55:07.000000000 +0100
17949 @@ -0,0 +1,531 @@
17950 +/*
17951 + *  linux/kernel/vserver/dlimit.c
17952 + *
17953 + *  Virtual Server: Context Disk Limits
17954 + *
17955 + *  Copyright (C) 2004-2009  Herbert Pötzl
17956 + *
17957 + *  V0.01  initial version
17958 + *  V0.02  compat32 splitup
17959 + *  V0.03  extended interface
17960 + *
17961 + */
17962 +
17963 +#include <linux/statfs.h>
17964 +#include <linux/sched.h>
17965 +#include <linux/namei.h>
17966 +#include <linux/vs_tag.h>
17967 +#include <linux/vs_dlimit.h>
17968 +#include <linux/vserver/dlimit_cmd.h>
17969 +#include <linux/slab.h>
17970 +// #include <linux/gfp.h>
17971 +
17972 +#include <asm/uaccess.h>
17973 +
17974 +/*     __alloc_dl_info()
17975 +
17976 +       * allocate an initialized dl_info struct
17977 +       * doesn't make it visible (hash)                        */
17978 +
17979 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17980 +{
17981 +       struct dl_info *new = NULL;
17982 +
17983 +       vxdprintk(VXD_CBIT(dlim, 5),
17984 +               "alloc_dl_info(%p,%d)*", sb, tag);
17985 +
17986 +       /* would this benefit from a slab cache? */
17987 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17988 +       if (!new)
17989 +               return 0;
17990 +
17991 +       memset(new, 0, sizeof(struct dl_info));
17992 +       new->dl_tag = tag;
17993 +       new->dl_sb = sb;
17994 +       // INIT_RCU_HEAD(&new->dl_rcu);
17995 +       INIT_HLIST_NODE(&new->dl_hlist);
17996 +       spin_lock_init(&new->dl_lock);
17997 +       atomic_set(&new->dl_refcnt, 0);
17998 +       atomic_set(&new->dl_usecnt, 0);
17999 +
18000 +       /* rest of init goes here */
18001 +
18002 +       vxdprintk(VXD_CBIT(dlim, 4),
18003 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18004 +       return new;
18005 +}
18006 +
18007 +/*     __dealloc_dl_info()
18008 +
18009 +       * final disposal of dl_info                             */
18010 +
18011 +static void __dealloc_dl_info(struct dl_info *dli)
18012 +{
18013 +       vxdprintk(VXD_CBIT(dlim, 4),
18014 +               "dealloc_dl_info(%p)", dli);
18015 +
18016 +       dli->dl_hlist.next = LIST_POISON1;
18017 +       dli->dl_tag = -1;
18018 +       dli->dl_sb = 0;
18019 +
18020 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18021 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18022 +
18023 +       kfree(dli);
18024 +}
18025 +
18026 +
18027 +/*     hash table for dl_info hash */
18028 +
18029 +#define DL_HASH_SIZE   13
18030 +
18031 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18032 +
18033 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18034 +
18035 +
18036 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18037 +{
18038 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18039 +}
18040 +
18041 +
18042 +
18043 +/*     __hash_dl_info()
18044 +
18045 +       * add the dli to the global hash table
18046 +       * requires the hash_lock to be held                     */
18047 +
18048 +static inline void __hash_dl_info(struct dl_info *dli)
18049 +{
18050 +       struct hlist_head *head;
18051 +
18052 +       vxdprintk(VXD_CBIT(dlim, 6),
18053 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18054 +       get_dl_info(dli);
18055 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18056 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18057 +}
18058 +
18059 +/*     __unhash_dl_info()
18060 +
18061 +       * remove the dli from the global hash table
18062 +       * requires the hash_lock to be held                     */
18063 +
18064 +static inline void __unhash_dl_info(struct dl_info *dli)
18065 +{
18066 +       vxdprintk(VXD_CBIT(dlim, 6),
18067 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18068 +       hlist_del_rcu(&dli->dl_hlist);
18069 +       put_dl_info(dli);
18070 +}
18071 +
18072 +
18073 +/*     __lookup_dl_info()
18074 +
18075 +       * requires the rcu_read_lock()
18076 +       * doesn't increment the dl_refcnt                       */
18077 +
18078 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18079 +{
18080 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18081 +       struct hlist_node *pos;
18082 +       struct dl_info *dli;
18083 +
18084 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18085 +
18086 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18087 +                       return dli;
18088 +               }
18089 +       }
18090 +       return NULL;
18091 +}
18092 +
18093 +
18094 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18095 +{
18096 +       struct dl_info *dli;
18097 +
18098 +       rcu_read_lock();
18099 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18100 +       vxdprintk(VXD_CBIT(dlim, 7),
18101 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18102 +       rcu_read_unlock();
18103 +       return dli;
18104 +}
18105 +
18106 +void rcu_free_dl_info(struct rcu_head *head)
18107 +{
18108 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18109 +       int usecnt, refcnt;
18110 +
18111 +       BUG_ON(!dli || !head);
18112 +
18113 +       usecnt = atomic_read(&dli->dl_usecnt);
18114 +       BUG_ON(usecnt < 0);
18115 +
18116 +       refcnt = atomic_read(&dli->dl_refcnt);
18117 +       BUG_ON(refcnt < 0);
18118 +
18119 +       vxdprintk(VXD_CBIT(dlim, 3),
18120 +               "rcu_free_dl_info(%p)", dli);
18121 +       if (!usecnt)
18122 +               __dealloc_dl_info(dli);
18123 +       else
18124 +               printk("!!! rcu didn't free\n");
18125 +}
18126 +
18127 +
18128 +
18129 +
18130 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18131 +       uint32_t flags, int add)
18132 +{
18133 +       struct path path;
18134 +       int ret;
18135 +
18136 +       ret = user_lpath(name, &path);
18137 +       if (!ret) {
18138 +               struct super_block *sb;
18139 +               struct dl_info *dli;
18140 +
18141 +               ret = -EINVAL;
18142 +               if (!path.dentry->d_inode)
18143 +                       goto out_release;
18144 +               if (!(sb = path.dentry->d_inode->i_sb))
18145 +                       goto out_release;
18146 +
18147 +               if (add) {
18148 +                       dli = __alloc_dl_info(sb, id);
18149 +                       spin_lock(&dl_info_hash_lock);
18150 +
18151 +                       ret = -EEXIST;
18152 +                       if (__lookup_dl_info(sb, id))
18153 +                               goto out_unlock;
18154 +                       __hash_dl_info(dli);
18155 +                       dli = NULL;
18156 +               } else {
18157 +                       spin_lock(&dl_info_hash_lock);
18158 +                       dli = __lookup_dl_info(sb, id);
18159 +
18160 +                       ret = -ESRCH;
18161 +                       if (!dli)
18162 +                               goto out_unlock;
18163 +                       __unhash_dl_info(dli);
18164 +               }
18165 +               ret = 0;
18166 +       out_unlock:
18167 +               spin_unlock(&dl_info_hash_lock);
18168 +               if (add && dli)
18169 +                       __dealloc_dl_info(dli);
18170 +       out_release:
18171 +               path_put(&path);
18172 +       }
18173 +       return ret;
18174 +}
18175 +
18176 +int vc_add_dlimit(uint32_t id, void __user *data)
18177 +{
18178 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18179 +
18180 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18181 +               return -EFAULT;
18182 +
18183 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18184 +}
18185 +
18186 +int vc_rem_dlimit(uint32_t id, void __user *data)
18187 +{
18188 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18189 +
18190 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18191 +               return -EFAULT;
18192 +
18193 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18194 +}
18195 +
18196 +#ifdef CONFIG_COMPAT
18197 +
18198 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18199 +{
18200 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18201 +
18202 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18203 +               return -EFAULT;
18204 +
18205 +       return do_addrem_dlimit(id,
18206 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18207 +}
18208 +
18209 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18210 +{
18211 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18212 +
18213 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18214 +               return -EFAULT;
18215 +
18216 +       return do_addrem_dlimit(id,
18217 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18218 +}
18219 +
18220 +#endif /* CONFIG_COMPAT */
18221 +
18222 +
18223 +static inline
18224 +int do_set_dlimit(uint32_t id, const char __user *name,
18225 +       uint32_t space_used, uint32_t space_total,
18226 +       uint32_t inodes_used, uint32_t inodes_total,
18227 +       uint32_t reserved, uint32_t flags)
18228 +{
18229 +       struct path path;
18230 +       int ret;
18231 +
18232 +       ret = user_lpath(name, &path);
18233 +       if (!ret) {
18234 +               struct super_block *sb;
18235 +               struct dl_info *dli;
18236 +
18237 +               ret = -EINVAL;
18238 +               if (!path.dentry->d_inode)
18239 +                       goto out_release;
18240 +               if (!(sb = path.dentry->d_inode->i_sb))
18241 +                       goto out_release;
18242 +
18243 +               /* sanity checks */
18244 +               if ((reserved != CDLIM_KEEP &&
18245 +                       reserved > 100) ||
18246 +                       (inodes_used != CDLIM_KEEP &&
18247 +                       inodes_used > inodes_total) ||
18248 +                       (space_used != CDLIM_KEEP &&
18249 +                       space_used > space_total))
18250 +                       goto out_release;
18251 +
18252 +               ret = -ESRCH;
18253 +               dli = locate_dl_info(sb, id);
18254 +               if (!dli)
18255 +                       goto out_release;
18256 +
18257 +               spin_lock(&dli->dl_lock);
18258 +
18259 +               if (inodes_used != CDLIM_KEEP)
18260 +                       dli->dl_inodes_used = inodes_used;
18261 +               if (inodes_total != CDLIM_KEEP)
18262 +                       dli->dl_inodes_total = inodes_total;
18263 +               if (space_used != CDLIM_KEEP)
18264 +                       dli->dl_space_used = dlimit_space_32to64(
18265 +                               space_used, flags, DLIMS_USED);
18266 +
18267 +               if (space_total == CDLIM_INFINITY)
18268 +                       dli->dl_space_total = DLIM_INFINITY;
18269 +               else if (space_total != CDLIM_KEEP)
18270 +                       dli->dl_space_total = dlimit_space_32to64(
18271 +                               space_total, flags, DLIMS_TOTAL);
18272 +
18273 +               if (reserved != CDLIM_KEEP)
18274 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18275 +
18276 +               spin_unlock(&dli->dl_lock);
18277 +
18278 +               put_dl_info(dli);
18279 +               ret = 0;
18280 +
18281 +       out_release:
18282 +               path_put(&path);
18283 +       }
18284 +       return ret;
18285 +}
18286 +
18287 +int vc_set_dlimit(uint32_t id, void __user *data)
18288 +{
18289 +       struct vcmd_ctx_dlimit_v0 vc_data;
18290 +
18291 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18292 +               return -EFAULT;
18293 +
18294 +       return do_set_dlimit(id, vc_data.name,
18295 +               vc_data.space_used, vc_data.space_total,
18296 +               vc_data.inodes_used, vc_data.inodes_total,
18297 +               vc_data.reserved, vc_data.flags);
18298 +}
18299 +
18300 +#ifdef CONFIG_COMPAT
18301 +
18302 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18303 +{
18304 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18305 +
18306 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18307 +               return -EFAULT;
18308 +
18309 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18310 +               vc_data.space_used, vc_data.space_total,
18311 +               vc_data.inodes_used, vc_data.inodes_total,
18312 +               vc_data.reserved, vc_data.flags);
18313 +}
18314 +
18315 +#endif /* CONFIG_COMPAT */
18316 +
18317 +
18318 +static inline
18319 +int do_get_dlimit(uint32_t id, const char __user *name,
18320 +       uint32_t *space_used, uint32_t *space_total,
18321 +       uint32_t *inodes_used, uint32_t *inodes_total,
18322 +       uint32_t *reserved, uint32_t *flags)
18323 +{
18324 +       struct path path;
18325 +       int ret;
18326 +
18327 +       ret = user_lpath(name, &path);
18328 +       if (!ret) {
18329 +               struct super_block *sb;
18330 +               struct dl_info *dli;
18331 +
18332 +               ret = -EINVAL;
18333 +               if (!path.dentry->d_inode)
18334 +                       goto out_release;
18335 +               if (!(sb = path.dentry->d_inode->i_sb))
18336 +                       goto out_release;
18337 +
18338 +               ret = -ESRCH;
18339 +               dli = locate_dl_info(sb, id);
18340 +               if (!dli)
18341 +                       goto out_release;
18342 +
18343 +               spin_lock(&dli->dl_lock);
18344 +               *inodes_used = dli->dl_inodes_used;
18345 +               *inodes_total = dli->dl_inodes_total;
18346 +
18347 +               *space_used = dlimit_space_64to32(
18348 +                       dli->dl_space_used, flags, DLIMS_USED);
18349 +
18350 +               if (dli->dl_space_total == DLIM_INFINITY)
18351 +                       *space_total = CDLIM_INFINITY;
18352 +               else
18353 +                       *space_total = dlimit_space_64to32(
18354 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18355 +
18356 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18357 +               spin_unlock(&dli->dl_lock);
18358 +
18359 +               put_dl_info(dli);
18360 +               ret = -EFAULT;
18361 +
18362 +               ret = 0;
18363 +       out_release:
18364 +               path_put(&path);
18365 +       }
18366 +       return ret;
18367 +}
18368 +
18369 +
18370 +int vc_get_dlimit(uint32_t id, void __user *data)
18371 +{
18372 +       struct vcmd_ctx_dlimit_v0 vc_data;
18373 +       int ret;
18374 +
18375 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18376 +               return -EFAULT;
18377 +
18378 +       ret = do_get_dlimit(id, vc_data.name,
18379 +               &vc_data.space_used, &vc_data.space_total,
18380 +               &vc_data.inodes_used, &vc_data.inodes_total,
18381 +               &vc_data.reserved, &vc_data.flags);
18382 +       if (ret)
18383 +               return ret;
18384 +
18385 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18386 +               return -EFAULT;
18387 +       return 0;
18388 +}
18389 +
18390 +#ifdef CONFIG_COMPAT
18391 +
18392 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18393 +{
18394 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18395 +       int ret;
18396 +
18397 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18398 +               return -EFAULT;
18399 +
18400 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18401 +               &vc_data.space_used, &vc_data.space_total,
18402 +               &vc_data.inodes_used, &vc_data.inodes_total,
18403 +               &vc_data.reserved, &vc_data.flags);
18404 +       if (ret)
18405 +               return ret;
18406 +
18407 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18408 +               return -EFAULT;
18409 +       return 0;
18410 +}
18411 +
18412 +#endif /* CONFIG_COMPAT */
18413 +
18414 +
18415 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18416 +{
18417 +       struct dl_info *dli;
18418 +       __u64 blimit, bfree, bavail;
18419 +       __u32 ifree;
18420 +
18421 +       dli = locate_dl_info(sb, dx_current_tag());
18422 +       if (!dli)
18423 +               return;
18424 +
18425 +       spin_lock(&dli->dl_lock);
18426 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18427 +               goto no_ilim;
18428 +
18429 +       /* reduce max inodes available to limit */
18430 +       if (buf->f_files > dli->dl_inodes_total)
18431 +               buf->f_files = dli->dl_inodes_total;
18432 +
18433 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18434 +       /* reduce free inodes to min */
18435 +       if (ifree < buf->f_ffree)
18436 +               buf->f_ffree = ifree;
18437 +
18438 +no_ilim:
18439 +       if (dli->dl_space_total == DLIM_INFINITY)
18440 +               goto no_blim;
18441 +
18442 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18443 +
18444 +       if (dli->dl_space_total < dli->dl_space_used)
18445 +               bfree = 0;
18446 +       else
18447 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18448 +                       >> sb->s_blocksize_bits;
18449 +
18450 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18451 +       if (bavail < dli->dl_space_used)
18452 +               bavail = 0;
18453 +       else
18454 +               bavail = (bavail - dli->dl_space_used)
18455 +                       >> sb->s_blocksize_bits;
18456 +
18457 +       /* reduce max space available to limit */
18458 +       if (buf->f_blocks > blimit)
18459 +               buf->f_blocks = blimit;
18460 +
18461 +       /* reduce free space to min */
18462 +       if (bfree < buf->f_bfree)
18463 +               buf->f_bfree = bfree;
18464 +
18465 +       /* reduce avail space to min */
18466 +       if (bavail < buf->f_bavail)
18467 +               buf->f_bavail = bavail;
18468 +
18469 +no_blim:
18470 +       spin_unlock(&dli->dl_lock);
18471 +       put_dl_info(dli);
18472 +
18473 +       return;
18474 +}
18475 +
18476 +#include <linux/module.h>
18477 +
18478 +EXPORT_SYMBOL_GPL(locate_dl_info);
18479 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18480 +
18481 diff -NurpP --minimal linux-3.3.1/kernel/vserver/helper.c linux-3.3.1-vs2.3.3.2/kernel/vserver/helper.c
18482 --- linux-3.3.1/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18483 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/helper.c       2012-02-24 03:55:07.000000000 +0100
18484 @@ -0,0 +1,223 @@
18485 +/*
18486 + *  linux/kernel/vserver/helper.c
18487 + *
18488 + *  Virtual Context Support
18489 + *
18490 + *  Copyright (C) 2004-2007  Herbert Pötzl
18491 + *
18492 + *  V0.01  basic helper
18493 + *
18494 + */
18495 +
18496 +#include <linux/kmod.h>
18497 +#include <linux/reboot.h>
18498 +#include <linux/vs_context.h>
18499 +#include <linux/vs_network.h>
18500 +#include <linux/vserver/signal.h>
18501 +
18502 +
18503 +char vshelper_path[255] = "/sbin/vshelper";
18504 +
18505 +
18506 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18507 +{
18508 +       int ret;
18509 +
18510 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18511 +               printk( KERN_WARNING
18512 +                       "%s: (%s %s) returned %s with %d\n",
18513 +                       name, argv[1], argv[2],
18514 +                       sync ? "sync" : "async", ret);
18515 +       }
18516 +       vxdprintk(VXD_CBIT(switch, 4),
18517 +               "%s: (%s %s) returned %s with %d",
18518 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18519 +       return ret;
18520 +}
18521 +
18522 +/*
18523 + *      vshelper path is set via /proc/sys
18524 + *      invoked by vserver sys_reboot(), with
18525 + *      the following arguments
18526 + *
18527 + *      argv [0] = vshelper_path;
18528 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18529 + *      argv [2] = context identifier
18530 + *
18531 + *      envp [*] = type-specific parameters
18532 + */
18533 +
18534 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18535 +{
18536 +       char id_buf[8], cmd_buf[16];
18537 +       char uid_buf[16], pid_buf[16];
18538 +       int ret;
18539 +
18540 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18541 +       char *envp[] = {"HOME=/", "TERM=linux",
18542 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18543 +                       uid_buf, pid_buf, cmd_buf, 0};
18544 +
18545 +       if (vx_info_state(vxi, VXS_HELPER))
18546 +               return -EAGAIN;
18547 +       vxi->vx_state |= VXS_HELPER;
18548 +
18549 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18550 +
18551 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18552 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18553 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18554 +
18555 +       switch (cmd) {
18556 +       case LINUX_REBOOT_CMD_RESTART:
18557 +               argv[1] = "restart";
18558 +               break;
18559 +
18560 +       case LINUX_REBOOT_CMD_HALT:
18561 +               argv[1] = "halt";
18562 +               break;
18563 +
18564 +       case LINUX_REBOOT_CMD_POWER_OFF:
18565 +               argv[1] = "poweroff";
18566 +               break;
18567 +
18568 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18569 +               argv[1] = "swsusp";
18570 +               break;
18571 +
18572 +       case LINUX_REBOOT_CMD_OOM:
18573 +               argv[1] = "oom";
18574 +               break;
18575 +
18576 +       default:
18577 +               vxi->vx_state &= ~VXS_HELPER;
18578 +               return 0;
18579 +       }
18580 +
18581 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18582 +       vxi->vx_state &= ~VXS_HELPER;
18583 +       __wakeup_vx_info(vxi);
18584 +       return (ret) ? -EPERM : 0;
18585 +}
18586 +
18587 +
18588 +long vs_reboot(unsigned int cmd, void __user *arg)
18589 +{
18590 +       struct vx_info *vxi = current_vx_info();
18591 +       long ret = 0;
18592 +
18593 +       vxdprintk(VXD_CBIT(misc, 5),
18594 +               "vs_reboot(%p[#%d],%u)",
18595 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18596 +
18597 +       ret = vs_reboot_helper(vxi, cmd, arg);
18598 +       if (ret)
18599 +               return ret;
18600 +
18601 +       vxi->reboot_cmd = cmd;
18602 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18603 +               switch (cmd) {
18604 +               case LINUX_REBOOT_CMD_RESTART:
18605 +               case LINUX_REBOOT_CMD_HALT:
18606 +               case LINUX_REBOOT_CMD_POWER_OFF:
18607 +                       vx_info_kill(vxi, 0, SIGKILL);
18608 +                       vx_info_kill(vxi, 1, SIGKILL);
18609 +               default:
18610 +                       break;
18611 +               }
18612 +       }
18613 +       return 0;
18614 +}
18615 +
18616 +long vs_oom_action(unsigned int cmd)
18617 +{
18618 +       struct vx_info *vxi = current_vx_info();
18619 +       long ret = 0;
18620 +
18621 +       vxdprintk(VXD_CBIT(misc, 5),
18622 +               "vs_oom_action(%p[#%d],%u)",
18623 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18624 +
18625 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18626 +       if (ret)
18627 +               return ret;
18628 +
18629 +       vxi->reboot_cmd = cmd;
18630 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18631 +               vx_info_kill(vxi, 0, SIGKILL);
18632 +               vx_info_kill(vxi, 1, SIGKILL);
18633 +       }
18634 +       return 0;
18635 +}
18636 +
18637 +/*
18638 + *      argv [0] = vshelper_path;
18639 + *      argv [1] = action: "startup", "shutdown"
18640 + *      argv [2] = context identifier
18641 + *
18642 + *      envp [*] = type-specific parameters
18643 + */
18644 +
18645 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18646 +{
18647 +       char id_buf[8], cmd_buf[16];
18648 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18649 +       char *envp[] = {"HOME=/", "TERM=linux",
18650 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18651 +
18652 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18653 +               return 0;
18654 +
18655 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18656 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18657 +
18658 +       switch (cmd) {
18659 +       case VSC_STARTUP:
18660 +               argv[1] = "startup";
18661 +               break;
18662 +       case VSC_SHUTDOWN:
18663 +               argv[1] = "shutdown";
18664 +               break;
18665 +       default:
18666 +               return 0;
18667 +       }
18668 +
18669 +       return do_vshelper(vshelper_path, argv, envp, 1);
18670 +}
18671 +
18672 +
18673 +/*
18674 + *      argv [0] = vshelper_path;
18675 + *      argv [1] = action: "netup", "netdown"
18676 + *      argv [2] = context identifier
18677 + *
18678 + *      envp [*] = type-specific parameters
18679 + */
18680 +
18681 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18682 +{
18683 +       char id_buf[8], cmd_buf[16];
18684 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18685 +       char *envp[] = {"HOME=/", "TERM=linux",
18686 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18687 +
18688 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18689 +               return 0;
18690 +
18691 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18692 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18693 +
18694 +       switch (cmd) {
18695 +       case VSC_NETUP:
18696 +               argv[1] = "netup";
18697 +               break;
18698 +       case VSC_NETDOWN:
18699 +               argv[1] = "netdown";
18700 +               break;
18701 +       default:
18702 +               return 0;
18703 +       }
18704 +
18705 +       return do_vshelper(vshelper_path, argv, envp, 1);
18706 +}
18707 +
18708 diff -NurpP --minimal linux-3.3.1/kernel/vserver/history.c linux-3.3.1-vs2.3.3.2/kernel/vserver/history.c
18709 --- linux-3.3.1/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18710 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/history.c      2012-02-24 03:55:07.000000000 +0100
18711 @@ -0,0 +1,258 @@
18712 +/*
18713 + *  kernel/vserver/history.c
18714 + *
18715 + *  Virtual Context History Backtrace
18716 + *
18717 + *  Copyright (C) 2004-2007  Herbert Pötzl
18718 + *
18719 + *  V0.01  basic structure
18720 + *  V0.02  hash/unhash and trace
18721 + *  V0.03  preemption fixes
18722 + *
18723 + */
18724 +
18725 +#include <linux/module.h>
18726 +#include <asm/uaccess.h>
18727 +
18728 +#include <linux/vserver/context.h>
18729 +#include <linux/vserver/debug.h>
18730 +#include <linux/vserver/debug_cmd.h>
18731 +#include <linux/vserver/history.h>
18732 +
18733 +
18734 +#ifdef CONFIG_VSERVER_HISTORY
18735 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18736 +#else
18737 +#define VXH_SIZE       64
18738 +#endif
18739 +
18740 +struct _vx_history {
18741 +       unsigned int counter;
18742 +
18743 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18744 +};
18745 +
18746 +
18747 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18748 +
18749 +unsigned volatile int vxh_active = 1;
18750 +
18751 +static atomic_t sequence = ATOMIC_INIT(0);
18752 +
18753 +
18754 +/*     vxh_advance()
18755 +
18756 +       * requires disabled preemption                          */
18757 +
18758 +struct _vx_hist_entry *vxh_advance(void *loc)
18759 +{
18760 +       unsigned int cpu = smp_processor_id();
18761 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18762 +       struct _vx_hist_entry *entry;
18763 +       unsigned int index;
18764 +
18765 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18766 +       entry = &hist->entry[index];
18767 +
18768 +       entry->seq = atomic_inc_return(&sequence);
18769 +       entry->loc = loc;
18770 +       return entry;
18771 +}
18772 +
18773 +EXPORT_SYMBOL_GPL(vxh_advance);
18774 +
18775 +
18776 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18777 +
18778 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18779 +
18780 +
18781 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18782 +
18783 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18784 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18785 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18786 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18787 +
18788 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18789 +{
18790 +       switch (e->type) {
18791 +       case VXH_THROW_OOPS:
18792 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18793 +               break;
18794 +
18795 +       case VXH_GET_VX_INFO:
18796 +       case VXH_PUT_VX_INFO:
18797 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18798 +                       VXH_LOC_ARGS(e),
18799 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18800 +                       VXH_VXI_ARGS(e));
18801 +               break;
18802 +
18803 +       case VXH_INIT_VX_INFO:
18804 +       case VXH_SET_VX_INFO:
18805 +       case VXH_CLR_VX_INFO:
18806 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18807 +                       VXH_LOC_ARGS(e),
18808 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18809 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18810 +                       VXH_VXI_ARGS(e), e->sc.data);
18811 +               break;
18812 +
18813 +       case VXH_CLAIM_VX_INFO:
18814 +       case VXH_RELEASE_VX_INFO:
18815 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18816 +                       VXH_LOC_ARGS(e),
18817 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18818 +                       VXH_VXI_ARGS(e), e->sc.data);
18819 +               break;
18820 +
18821 +       case VXH_ALLOC_VX_INFO:
18822 +       case VXH_DEALLOC_VX_INFO:
18823 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18824 +                       VXH_LOC_ARGS(e),
18825 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18826 +                       VXH_VXI_ARGS(e));
18827 +               break;
18828 +
18829 +       case VXH_HASH_VX_INFO:
18830 +       case VXH_UNHASH_VX_INFO:
18831 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18832 +                       VXH_LOC_ARGS(e),
18833 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18834 +                       VXH_VXI_ARGS(e));
18835 +               break;
18836 +
18837 +       case VXH_LOC_VX_INFO:
18838 +       case VXH_LOOKUP_VX_INFO:
18839 +       case VXH_CREATE_VX_INFO:
18840 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18841 +                       VXH_LOC_ARGS(e),
18842 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18843 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18844 +                       e->ll.arg, VXH_VXI_ARGS(e));
18845 +               break;
18846 +       }
18847 +}
18848 +
18849 +static void __vxh_dump_history(void)
18850 +{
18851 +       unsigned int i, cpu;
18852 +
18853 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18854 +               atomic_read(&sequence), NR_CPUS);
18855 +
18856 +       for (i = 0; i < VXH_SIZE; i++) {
18857 +               for_each_online_cpu(cpu) {
18858 +                       struct _vx_history *hist =
18859 +                               &per_cpu(vx_history_buffer, cpu);
18860 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18861 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18862 +
18863 +                       vxh_dump_entry(entry, cpu);
18864 +               }
18865 +       }
18866 +}
18867 +
18868 +void   vxh_dump_history(void)
18869 +{
18870 +       vxh_active = 0;
18871 +#ifdef CONFIG_SMP
18872 +       local_irq_enable();
18873 +       smp_send_stop();
18874 +       local_irq_disable();
18875 +#endif
18876 +       __vxh_dump_history();
18877 +}
18878 +
18879 +
18880 +/* vserver syscall commands below here */
18881 +
18882 +
18883 +int vc_dump_history(uint32_t id)
18884 +{
18885 +       vxh_active = 0;
18886 +       __vxh_dump_history();
18887 +       vxh_active = 1;
18888 +
18889 +       return 0;
18890 +}
18891 +
18892 +
18893 +int do_read_history(struct __user _vx_hist_entry *data,
18894 +       int cpu, uint32_t *index, uint32_t *count)
18895 +{
18896 +       int pos, ret = 0;
18897 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18898 +       int end = hist->counter;
18899 +       int start = end - VXH_SIZE + 2;
18900 +       int idx = *index;
18901 +
18902 +       /* special case: get current pos */
18903 +       if (!*count) {
18904 +               *index = end;
18905 +               return 0;
18906 +       }
18907 +
18908 +       /* have we lost some data? */
18909 +       if (idx < start)
18910 +               idx = start;
18911 +
18912 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18913 +               struct _vx_hist_entry *entry =
18914 +                       &hist->entry[idx % VXH_SIZE];
18915 +
18916 +               /* send entry to userspace */
18917 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18918 +               if (ret)
18919 +                       break;
18920 +       }
18921 +       /* save new index and count */
18922 +       *index = idx;
18923 +       *count = pos;
18924 +       return ret ? ret : (*index < end);
18925 +}
18926 +
18927 +int vc_read_history(uint32_t id, void __user *data)
18928 +{
18929 +       struct vcmd_read_history_v0 vc_data;
18930 +       int ret;
18931 +
18932 +       if (id >= NR_CPUS)
18933 +               return -EINVAL;
18934 +
18935 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18936 +               return -EFAULT;
18937 +
18938 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18939 +               id, &vc_data.index, &vc_data.count);
18940 +
18941 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18942 +               return -EFAULT;
18943 +       return ret;
18944 +}
18945 +
18946 +#ifdef CONFIG_COMPAT
18947 +
18948 +int vc_read_history_x32(uint32_t id, void __user *data)
18949 +{
18950 +       struct vcmd_read_history_v0_x32 vc_data;
18951 +       int ret;
18952 +
18953 +       if (id >= NR_CPUS)
18954 +               return -EINVAL;
18955 +
18956 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18957 +               return -EFAULT;
18958 +
18959 +       ret = do_read_history((struct __user _vx_hist_entry *)
18960 +               compat_ptr(vc_data.data_ptr),
18961 +               id, &vc_data.index, &vc_data.count);
18962 +
18963 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18964 +               return -EFAULT;
18965 +       return ret;
18966 +}
18967 +
18968 +#endif /* CONFIG_COMPAT */
18969 +
18970 diff -NurpP --minimal linux-3.3.1/kernel/vserver/inet.c linux-3.3.1-vs2.3.3.2/kernel/vserver/inet.c
18971 --- linux-3.3.1/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
18972 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/inet.c 2012-02-24 03:55:07.000000000 +0100
18973 @@ -0,0 +1,226 @@
18974 +
18975 +#include <linux/in.h>
18976 +#include <linux/inetdevice.h>
18977 +#include <linux/export.h>
18978 +#include <linux/vs_inet.h>
18979 +#include <linux/vs_inet6.h>
18980 +#include <linux/vserver/debug.h>
18981 +#include <net/route.h>
18982 +#include <net/addrconf.h>
18983 +
18984 +
18985 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18986 +{
18987 +       int ret = 0;
18988 +
18989 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18990 +               ret = 1;
18991 +       else {
18992 +               struct nx_addr_v4 *ptr;
18993 +
18994 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18995 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18996 +                               ret = 1;
18997 +                               break;
18998 +                       }
18999 +               }
19000 +       }
19001 +
19002 +       vxdprintk(VXD_CBIT(net, 2),
19003 +               "nx_v4_addr_conflict(%p,%p): %d",
19004 +               nxi1, nxi2, ret);
19005 +
19006 +       return ret;
19007 +}
19008 +
19009 +
19010 +#ifdef CONFIG_IPV6
19011 +
19012 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19013 +{
19014 +       int ret = 0;
19015 +
19016 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19017 +               ret = 1;
19018 +       else {
19019 +               struct nx_addr_v6 *ptr;
19020 +
19021 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19022 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19023 +                               ret = 1;
19024 +                               break;
19025 +                       }
19026 +               }
19027 +       }
19028 +
19029 +       vxdprintk(VXD_CBIT(net, 2),
19030 +               "nx_v6_addr_conflict(%p,%p): %d",
19031 +               nxi1, nxi2, ret);
19032 +
19033 +       return ret;
19034 +}
19035 +
19036 +#endif
19037 +
19038 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19039 +{
19040 +       struct in_device *in_dev;
19041 +       struct in_ifaddr **ifap;
19042 +       struct in_ifaddr *ifa;
19043 +       int ret = 0;
19044 +
19045 +       if (!dev)
19046 +               goto out;
19047 +       in_dev = in_dev_get(dev);
19048 +       if (!in_dev)
19049 +               goto out;
19050 +
19051 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19052 +               ifap = &ifa->ifa_next) {
19053 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19054 +                       ret = 1;
19055 +                       break;
19056 +               }
19057 +       }
19058 +       in_dev_put(in_dev);
19059 +out:
19060 +       return ret;
19061 +}
19062 +
19063 +
19064 +#ifdef CONFIG_IPV6
19065 +
19066 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19067 +{
19068 +       struct inet6_dev *in_dev;
19069 +       struct inet6_ifaddr *ifa;
19070 +       int ret = 0;
19071 +
19072 +       if (!dev)
19073 +               goto out;
19074 +       in_dev = in6_dev_get(dev);
19075 +       if (!in_dev)
19076 +               goto out;
19077 +
19078 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19079 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19080 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19081 +                       ret = 1;
19082 +                       break;
19083 +               }
19084 +       }
19085 +       in6_dev_put(in_dev);
19086 +out:
19087 +       return ret;
19088 +}
19089 +
19090 +#endif
19091 +
19092 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19093 +{
19094 +       int ret = 1;
19095 +
19096 +       if (!nxi)
19097 +               goto out;
19098 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19099 +               goto out;
19100 +#ifdef CONFIG_IPV6
19101 +       ret = 2;
19102 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19103 +               goto out;
19104 +#endif
19105 +       ret = 0;
19106 +out:
19107 +       vxdprintk(VXD_CBIT(net, 3),
19108 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19109 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19110 +       return ret;
19111 +}
19112 +
19113 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19114 +       struct flowi4 *fl4)
19115 +{
19116 +       struct rtable *rt;
19117 +
19118 +       if (!nxi)
19119 +               return NULL;
19120 +
19121 +       /* FIXME: handle lback only case */
19122 +       if (!NX_IPV4(nxi))
19123 +               return ERR_PTR(-EPERM);
19124 +
19125 +       vxdprintk(VXD_CBIT(net, 4),
19126 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19127 +               nxi, nxi ? nxi->nx_id : 0,
19128 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19129 +
19130 +       /* single IP is unconditional */
19131 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19132 +               (fl4->saddr == INADDR_ANY))
19133 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19134 +
19135 +       if (fl4->saddr == INADDR_ANY) {
19136 +               struct nx_addr_v4 *ptr;
19137 +               __be32 found = 0;
19138 +
19139 +               rt = __ip_route_output_key(net, fl4);
19140 +               if (!IS_ERR(rt)) {
19141 +                       found = fl4->saddr;
19142 +                       ip_rt_put(rt);
19143 +                       vxdprintk(VXD_CBIT(net, 4),
19144 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19145 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19146 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19147 +                               goto found;
19148 +               }
19149 +
19150 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19151 +                       __be32 primary = ptr->ip[0].s_addr;
19152 +                       __be32 mask = ptr->mask.s_addr;
19153 +                       __be32 neta = primary & mask;
19154 +
19155 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19156 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19157 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19158 +                               NIPQUAD(mask), NIPQUAD(neta));
19159 +                       if ((found & mask) != neta)
19160 +                               continue;
19161 +
19162 +                       fl4->saddr = primary;
19163 +                       rt = __ip_route_output_key(net, fl4);
19164 +                       vxdprintk(VXD_CBIT(net, 4),
19165 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19166 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19167 +                       if (!IS_ERR(rt)) {
19168 +                               found = fl4->saddr;
19169 +                               ip_rt_put(rt);
19170 +                               if (found == primary)
19171 +                                       goto found;
19172 +                       }
19173 +               }
19174 +               /* still no source ip? */
19175 +               found = ipv4_is_loopback(fl4->daddr)
19176 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19177 +       found:
19178 +               /* assign src ip to flow */
19179 +               fl4->saddr = found;
19180 +
19181 +       } else {
19182 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19183 +                       return ERR_PTR(-EPERM);
19184 +       }
19185 +
19186 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19187 +               if (ipv4_is_loopback(fl4->daddr))
19188 +                       fl4->daddr = nxi->v4_lback.s_addr;
19189 +               if (ipv4_is_loopback(fl4->saddr))
19190 +                       fl4->saddr = nxi->v4_lback.s_addr;
19191 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19192 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19193 +               return ERR_PTR(-EPERM);
19194 +
19195 +       return NULL;
19196 +}
19197 +
19198 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19199 +
19200 diff -NurpP --minimal linux-3.3.1/kernel/vserver/init.c linux-3.3.1-vs2.3.3.2/kernel/vserver/init.c
19201 --- linux-3.3.1/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19202 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/init.c 2012-02-24 03:55:07.000000000 +0100
19203 @@ -0,0 +1,45 @@
19204 +/*
19205 + *  linux/kernel/init.c
19206 + *
19207 + *  Virtual Server Init
19208 + *
19209 + *  Copyright (C) 2004-2007  Herbert Pötzl
19210 + *
19211 + *  V0.01  basic structure
19212 + *
19213 + */
19214 +
19215 +#include <linux/init.h>
19216 +
19217 +int    vserver_register_sysctl(void);
19218 +void   vserver_unregister_sysctl(void);
19219 +
19220 +
19221 +static int __init init_vserver(void)
19222 +{
19223 +       int ret = 0;
19224 +
19225 +#ifdef CONFIG_VSERVER_DEBUG
19226 +       vserver_register_sysctl();
19227 +#endif
19228 +       return ret;
19229 +}
19230 +
19231 +
19232 +static void __exit exit_vserver(void)
19233 +{
19234 +
19235 +#ifdef CONFIG_VSERVER_DEBUG
19236 +       vserver_unregister_sysctl();
19237 +#endif
19238 +       return;
19239 +}
19240 +
19241 +/* FIXME: GFP_ZONETYPES gone
19242 +long vx_slab[GFP_ZONETYPES]; */
19243 +long vx_area;
19244 +
19245 +
19246 +module_init(init_vserver);
19247 +module_exit(exit_vserver);
19248 +
19249 diff -NurpP --minimal linux-3.3.1/kernel/vserver/inode.c linux-3.3.1-vs2.3.3.2/kernel/vserver/inode.c
19250 --- linux-3.3.1/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19251 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/inode.c        2012-02-24 03:55:07.000000000 +0100
19252 @@ -0,0 +1,437 @@
19253 +/*
19254 + *  linux/kernel/vserver/inode.c
19255 + *
19256 + *  Virtual Server: File System Support
19257 + *
19258 + *  Copyright (C) 2004-2007  Herbert Pötzl
19259 + *
19260 + *  V0.01  separated from vcontext V0.05
19261 + *  V0.02  moved to tag (instead of xid)
19262 + *
19263 + */
19264 +
19265 +#include <linux/tty.h>
19266 +#include <linux/proc_fs.h>
19267 +#include <linux/devpts_fs.h>
19268 +#include <linux/fs.h>
19269 +#include <linux/file.h>
19270 +#include <linux/mount.h>
19271 +#include <linux/parser.h>
19272 +#include <linux/namei.h>
19273 +#include <linux/vserver/inode.h>
19274 +#include <linux/vserver/inode_cmd.h>
19275 +#include <linux/vs_base.h>
19276 +#include <linux/vs_tag.h>
19277 +
19278 +#include <asm/uaccess.h>
19279 +
19280 +
19281 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19282 +{
19283 +       struct proc_dir_entry *entry;
19284 +
19285 +       if (!in || !in->i_sb)
19286 +               return -ESRCH;
19287 +
19288 +       *flags = IATTR_TAG
19289 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19290 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19291 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19292 +               | (IS_COW(in) ? IATTR_COW : 0);
19293 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19294 +
19295 +       if (S_ISDIR(in->i_mode))
19296 +               *mask |= IATTR_BARRIER;
19297 +
19298 +       if (IS_TAGGED(in)) {
19299 +               *tag = in->i_tag;
19300 +               *mask |= IATTR_TAG;
19301 +       }
19302 +
19303 +       switch (in->i_sb->s_magic) {
19304 +       case PROC_SUPER_MAGIC:
19305 +               entry = PROC_I(in)->pde;
19306 +
19307 +               /* check for specific inodes? */
19308 +               if (entry)
19309 +                       *mask |= IATTR_FLAGS;
19310 +               if (entry)
19311 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19312 +               else
19313 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19314 +               break;
19315 +
19316 +       case DEVPTS_SUPER_MAGIC:
19317 +               *tag = in->i_tag;
19318 +               *mask |= IATTR_TAG;
19319 +               break;
19320 +
19321 +       default:
19322 +               break;
19323 +       }
19324 +       return 0;
19325 +}
19326 +
19327 +int vc_get_iattr(void __user *data)
19328 +{
19329 +       struct path path;
19330 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19331 +       int ret;
19332 +
19333 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19334 +               return -EFAULT;
19335 +
19336 +       ret = user_lpath(vc_data.name, &path);
19337 +       if (!ret) {
19338 +               ret = __vc_get_iattr(path.dentry->d_inode,
19339 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19340 +               path_put(&path);
19341 +       }
19342 +       if (ret)
19343 +               return ret;
19344 +
19345 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19346 +               ret = -EFAULT;
19347 +       return ret;
19348 +}
19349 +
19350 +#ifdef CONFIG_COMPAT
19351 +
19352 +int vc_get_iattr_x32(void __user *data)
19353 +{
19354 +       struct path path;
19355 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19356 +       int ret;
19357 +
19358 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19359 +               return -EFAULT;
19360 +
19361 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19362 +       if (!ret) {
19363 +               ret = __vc_get_iattr(path.dentry->d_inode,
19364 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19365 +               path_put(&path);
19366 +       }
19367 +       if (ret)
19368 +               return ret;
19369 +
19370 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19371 +               ret = -EFAULT;
19372 +       return ret;
19373 +}
19374 +
19375 +#endif /* CONFIG_COMPAT */
19376 +
19377 +
19378 +int vc_fget_iattr(uint32_t fd, void __user *data)
19379 +{
19380 +       struct file *filp;
19381 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19382 +       int ret;
19383 +
19384 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19385 +               return -EFAULT;
19386 +
19387 +       filp = fget(fd);
19388 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19389 +               return -EBADF;
19390 +
19391 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19392 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19393 +
19394 +       fput(filp);
19395 +
19396 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19397 +               ret = -EFAULT;
19398 +       return ret;
19399 +}
19400 +
19401 +
19402 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19403 +{
19404 +       struct inode *in = de->d_inode;
19405 +       int error = 0, is_proc = 0, has_tag = 0;
19406 +       struct iattr attr = { 0 };
19407 +
19408 +       if (!in || !in->i_sb)
19409 +               return -ESRCH;
19410 +
19411 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19412 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19413 +               return -EINVAL;
19414 +
19415 +       has_tag = IS_TAGGED(in) ||
19416 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19417 +       if ((*mask & IATTR_TAG) && !has_tag)
19418 +               return -EINVAL;
19419 +
19420 +       mutex_lock(&in->i_mutex);
19421 +       if (*mask & IATTR_TAG) {
19422 +               attr.ia_tag = *tag;
19423 +               attr.ia_valid |= ATTR_TAG;
19424 +       }
19425 +
19426 +       if (*mask & IATTR_FLAGS) {
19427 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19428 +               unsigned int iflags = PROC_I(in)->vx_flags;
19429 +
19430 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19431 +                       | (*flags & IATTR_FLAGS);
19432 +               PROC_I(in)->vx_flags = iflags;
19433 +               if (entry)
19434 +                       entry->vx_flags = iflags;
19435 +       }
19436 +
19437 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19438 +               IATTR_BARRIER | IATTR_COW)) {
19439 +               int iflags = in->i_flags;
19440 +               int vflags = in->i_vflags;
19441 +
19442 +               if (*mask & IATTR_IMMUTABLE) {
19443 +                       if (*flags & IATTR_IMMUTABLE)
19444 +                               iflags |= S_IMMUTABLE;
19445 +                       else
19446 +                               iflags &= ~S_IMMUTABLE;
19447 +               }
19448 +               if (*mask & IATTR_IXUNLINK) {
19449 +                       if (*flags & IATTR_IXUNLINK)
19450 +                               iflags |= S_IXUNLINK;
19451 +                       else
19452 +                               iflags &= ~S_IXUNLINK;
19453 +               }
19454 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19455 +                       if (*flags & IATTR_BARRIER)
19456 +                               vflags |= V_BARRIER;
19457 +                       else
19458 +                               vflags &= ~V_BARRIER;
19459 +               }
19460 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19461 +                       if (*flags & IATTR_COW)
19462 +                               vflags |= V_COW;
19463 +                       else
19464 +                               vflags &= ~V_COW;
19465 +               }
19466 +               if (in->i_op && in->i_op->sync_flags) {
19467 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19468 +                       if (error)
19469 +                               goto out;
19470 +               }
19471 +       }
19472 +
19473 +       if (attr.ia_valid) {
19474 +               if (in->i_op && in->i_op->setattr)
19475 +                       error = in->i_op->setattr(de, &attr);
19476 +               else {
19477 +                       error = inode_change_ok(in, &attr);
19478 +                       if (!error) {
19479 +                               setattr_copy(in, &attr);
19480 +                               mark_inode_dirty(in);
19481 +                       }
19482 +               }
19483 +       }
19484 +
19485 +out:
19486 +       mutex_unlock(&in->i_mutex);
19487 +       return error;
19488 +}
19489 +
19490 +int vc_set_iattr(void __user *data)
19491 +{
19492 +       struct path path;
19493 +       struct vcmd_ctx_iattr_v1 vc_data;
19494 +       int ret;
19495 +
19496 +       if (!capable(CAP_LINUX_IMMUTABLE))
19497 +               return -EPERM;
19498 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19499 +               return -EFAULT;
19500 +
19501 +       ret = user_lpath(vc_data.name, &path);
19502 +       if (!ret) {
19503 +               ret = __vc_set_iattr(path.dentry,
19504 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19505 +               path_put(&path);
19506 +       }
19507 +
19508 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19509 +               ret = -EFAULT;
19510 +       return ret;
19511 +}
19512 +
19513 +#ifdef CONFIG_COMPAT
19514 +
19515 +int vc_set_iattr_x32(void __user *data)
19516 +{
19517 +       struct path path;
19518 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19519 +       int ret;
19520 +
19521 +       if (!capable(CAP_LINUX_IMMUTABLE))
19522 +               return -EPERM;
19523 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19524 +               return -EFAULT;
19525 +
19526 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19527 +       if (!ret) {
19528 +               ret = __vc_set_iattr(path.dentry,
19529 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19530 +               path_put(&path);
19531 +       }
19532 +
19533 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19534 +               ret = -EFAULT;
19535 +       return ret;
19536 +}
19537 +
19538 +#endif /* CONFIG_COMPAT */
19539 +
19540 +int vc_fset_iattr(uint32_t fd, void __user *data)
19541 +{
19542 +       struct file *filp;
19543 +       struct vcmd_ctx_fiattr_v0 vc_data;
19544 +       int ret;
19545 +
19546 +       if (!capable(CAP_LINUX_IMMUTABLE))
19547 +               return -EPERM;
19548 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19549 +               return -EFAULT;
19550 +
19551 +       filp = fget(fd);
19552 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19553 +               return -EBADF;
19554 +
19555 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19556 +               &vc_data.flags, &vc_data.mask);
19557 +
19558 +       fput(filp);
19559 +
19560 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19561 +               return -EFAULT;
19562 +       return ret;
19563 +}
19564 +
19565 +
19566 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19567 +
19568 +static match_table_t tokens = {
19569 +       {Opt_notagcheck, "notagcheck"},
19570 +#ifdef CONFIG_PROPAGATE
19571 +       {Opt_notag, "notag"},
19572 +       {Opt_tag, "tag"},
19573 +       {Opt_tagid, "tagid=%u"},
19574 +#endif
19575 +       {Opt_err, NULL}
19576 +};
19577 +
19578 +
19579 +static void __dx_parse_remove(char *string, char *opt)
19580 +{
19581 +       char *p = strstr(string, opt);
19582 +       char *q = p;
19583 +
19584 +       if (p) {
19585 +               while (*q != '\0' && *q != ',')
19586 +                       q++;
19587 +               while (*q)
19588 +                       *p++ = *q++;
19589 +               while (*p)
19590 +                       *p++ = '\0';
19591 +       }
19592 +}
19593 +
19594 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19595 +                unsigned long *flags)
19596 +{
19597 +       int set = 0;
19598 +       substring_t args[MAX_OPT_ARGS];
19599 +       int token;
19600 +       char *s, *p, *opts;
19601 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19602 +       int option = 0;
19603 +#endif
19604 +
19605 +       if (!string)
19606 +               return 0;
19607 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19608 +       if (!s)
19609 +               return 0;
19610 +
19611 +       opts = s;
19612 +       while ((p = strsep(&opts, ",")) != NULL) {
19613 +               token = match_token(p, tokens, args);
19614 +
19615 +               switch (token) {
19616 +#ifdef CONFIG_PROPAGATE
19617 +               case Opt_tag:
19618 +                       if (tag)
19619 +                               *tag = 0;
19620 +                       if (remove)
19621 +                               __dx_parse_remove(s, "tag");
19622 +                       *mnt_flags |= MNT_TAGID;
19623 +                       set |= MNT_TAGID;
19624 +                       break;
19625 +               case Opt_notag:
19626 +                       if (remove)
19627 +                               __dx_parse_remove(s, "notag");
19628 +                       *mnt_flags |= MNT_NOTAG;
19629 +                       set |= MNT_NOTAG;
19630 +                       break;
19631 +               case Opt_tagid:
19632 +                       if (tag && !match_int(args, &option))
19633 +                               *tag = option;
19634 +                       if (remove)
19635 +                               __dx_parse_remove(s, "tagid");
19636 +                       *mnt_flags |= MNT_TAGID;
19637 +                       set |= MNT_TAGID;
19638 +                       break;
19639 +#endif /* CONFIG_PROPAGATE */
19640 +               case Opt_notagcheck:
19641 +                       if (remove)
19642 +                               __dx_parse_remove(s, "notagcheck");
19643 +                       *flags |= MS_NOTAGCHECK;
19644 +                       set |= MS_NOTAGCHECK;
19645 +                       break;
19646 +               }
19647 +               vxdprintk(VXD_CBIT(tag, 7),
19648 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19649 +                       p, token, option);
19650 +       }
19651 +       if (set)
19652 +               strcpy(string, s);
19653 +       kfree(s);
19654 +       return set;
19655 +}
19656 +
19657 +#ifdef CONFIG_PROPAGATE
19658 +
19659 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19660 +{
19661 +       tag_t new_tag = 0;
19662 +       struct vfsmount *mnt;
19663 +       int propagate;
19664 +
19665 +       if (!nd)
19666 +               return;
19667 +       mnt = nd->path.mnt;
19668 +       if (!mnt)
19669 +               return;
19670 +
19671 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19672 +       if (propagate)
19673 +               new_tag = mnt->mnt_tag;
19674 +
19675 +       vxdprintk(VXD_CBIT(tag, 7),
19676 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19677 +               inode, inode->i_ino, inode->i_tag,
19678 +               new_tag, (propagate) ? 1 : 0);
19679 +
19680 +       if (propagate)
19681 +               inode->i_tag = new_tag;
19682 +}
19683 +
19684 +#include <linux/module.h>
19685 +
19686 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19687 +
19688 +#endif /* CONFIG_PROPAGATE */
19689 +
19690 diff -NurpP --minimal linux-3.3.1/kernel/vserver/limit.c linux-3.3.1-vs2.3.3.2/kernel/vserver/limit.c
19691 --- linux-3.3.1/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19692 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/limit.c        2012-02-24 03:55:07.000000000 +0100
19693 @@ -0,0 +1,330 @@
19694 +/*
19695 + *  linux/kernel/vserver/limit.c
19696 + *
19697 + *  Virtual Server: Context Limits
19698 + *
19699 + *  Copyright (C) 2004-2010  Herbert Pötzl
19700 + *
19701 + *  V0.01  broken out from vcontext V0.05
19702 + *  V0.02  changed vcmds to vxi arg
19703 + *  V0.03  added memory cgroup support
19704 + *
19705 + */
19706 +
19707 +#include <linux/sched.h>
19708 +#include <linux/module.h>
19709 +#include <linux/memcontrol.h>
19710 +#include <linux/res_counter.h>
19711 +#include <linux/vs_limit.h>
19712 +#include <linux/vserver/limit.h>
19713 +#include <linux/vserver/limit_cmd.h>
19714 +
19715 +#include <asm/uaccess.h>
19716 +
19717 +
19718 +const char *vlimit_name[NUM_LIMITS] = {
19719 +       [RLIMIT_CPU]            = "CPU",
19720 +       [RLIMIT_NPROC]          = "NPROC",
19721 +       [RLIMIT_NOFILE]         = "NOFILE",
19722 +       [RLIMIT_LOCKS]          = "LOCKS",
19723 +       [RLIMIT_SIGPENDING]     = "SIGP",
19724 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19725 +
19726 +       [VLIMIT_NSOCK]          = "NSOCK",
19727 +       [VLIMIT_OPENFD]         = "OPENFD",
19728 +       [VLIMIT_SHMEM]          = "SHMEM",
19729 +       [VLIMIT_DENTRY]         = "DENTRY",
19730 +};
19731 +
19732 +EXPORT_SYMBOL_GPL(vlimit_name);
19733 +
19734 +#define MASK_ENTRY(x)  (1 << (x))
19735 +
19736 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19737 +               /* minimum */
19738 +       0
19739 +       ,       /* softlimit */
19740 +       0
19741 +       ,       /* maximum */
19742 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19743 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19744 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19745 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19746 +
19747 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19748 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19749 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19750 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19751 +       0
19752 +};
19753 +               /* accounting only */
19754 +uint32_t account_mask =
19755 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19756 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19757 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19758 +       0;
19759 +
19760 +
19761 +static int is_valid_vlimit(int id)
19762 +{
19763 +       uint32_t mask = vlimit_mask.minimum |
19764 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19765 +       return mask & (1 << id);
19766 +}
19767 +
19768 +static int is_accounted_vlimit(int id)
19769 +{
19770 +       if (is_valid_vlimit(id))
19771 +               return 1;
19772 +       return account_mask & (1 << id);
19773 +}
19774 +
19775 +
19776 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19777 +{
19778 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19779 +       return VX_VLIM(limit);
19780 +}
19781 +
19782 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19783 +{
19784 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19785 +       return VX_VLIM(limit);
19786 +}
19787 +
19788 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19789 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19790 +{
19791 +       if (!is_valid_vlimit(id))
19792 +               return -EINVAL;
19793 +
19794 +       if (minimum)
19795 +               *minimum = CRLIM_UNSET;
19796 +       if (softlimit)
19797 +               *softlimit = vc_get_soft(vxi, id);
19798 +       if (maximum)
19799 +               *maximum = vc_get_hard(vxi, id);
19800 +       return 0;
19801 +}
19802 +
19803 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19804 +{
19805 +       struct vcmd_ctx_rlimit_v0 vc_data;
19806 +       int ret;
19807 +
19808 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19809 +               return -EFAULT;
19810 +
19811 +       ret = do_get_rlimit(vxi, vc_data.id,
19812 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19813 +       if (ret)
19814 +               return ret;
19815 +
19816 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19817 +               return -EFAULT;
19818 +       return 0;
19819 +}
19820 +
19821 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19822 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19823 +{
19824 +       if (!is_valid_vlimit(id))
19825 +               return -EINVAL;
19826 +
19827 +       if (maximum != CRLIM_KEEP)
19828 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19829 +       if (softlimit != CRLIM_KEEP)
19830 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19831 +
19832 +       /* clamp soft limit */
19833 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19834 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19835 +
19836 +       return 0;
19837 +}
19838 +
19839 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19840 +{
19841 +       struct vcmd_ctx_rlimit_v0 vc_data;
19842 +
19843 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19844 +               return -EFAULT;
19845 +
19846 +       return do_set_rlimit(vxi, vc_data.id,
19847 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19848 +}
19849 +
19850 +#ifdef CONFIG_IA32_EMULATION
19851 +
19852 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19853 +{
19854 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19855 +
19856 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19857 +               return -EFAULT;
19858 +
19859 +       return do_set_rlimit(vxi, vc_data.id,
19860 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19861 +}
19862 +
19863 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19864 +{
19865 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19866 +       int ret;
19867 +
19868 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19869 +               return -EFAULT;
19870 +
19871 +       ret = do_get_rlimit(vxi, vc_data.id,
19872 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19873 +       if (ret)
19874 +               return ret;
19875 +
19876 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19877 +               return -EFAULT;
19878 +       return 0;
19879 +}
19880 +
19881 +#endif /* CONFIG_IA32_EMULATION */
19882 +
19883 +
19884 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19885 +{
19886 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19887 +               return -EFAULT;
19888 +       return 0;
19889 +}
19890 +
19891 +
19892 +static inline void vx_reset_hits(struct _vx_limit *limit)
19893 +{
19894 +       int lim;
19895 +
19896 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19897 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19898 +       }
19899 +}
19900 +
19901 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19902 +{
19903 +       vx_reset_hits(&vxi->limit);
19904 +       return 0;
19905 +}
19906 +
19907 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19908 +{
19909 +       rlim_t value;
19910 +       int lim;
19911 +
19912 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19913 +               value = __rlim_get(limit, lim);
19914 +               __rlim_rmax(limit, lim) = value;
19915 +               __rlim_rmin(limit, lim) = value;
19916 +       }
19917 +}
19918 +
19919 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19920 +{
19921 +       vx_reset_minmax(&vxi->limit);
19922 +       return 0;
19923 +}
19924 +
19925 +
19926 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19927 +{
19928 +       struct vcmd_rlimit_stat_v0 vc_data;
19929 +       struct _vx_limit *limit = &vxi->limit;
19930 +       int id;
19931 +
19932 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19933 +               return -EFAULT;
19934 +
19935 +       id = vc_data.id;
19936 +       if (!is_accounted_vlimit(id))
19937 +               return -EINVAL;
19938 +
19939 +       vx_limit_fixup(limit, id);
19940 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19941 +       vc_data.value = __rlim_get(limit, id);
19942 +       vc_data.minimum = __rlim_rmin(limit, id);
19943 +       vc_data.maximum = __rlim_rmax(limit, id);
19944 +
19945 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19946 +               return -EFAULT;
19947 +       return 0;
19948 +}
19949 +
19950 +
19951 +void vx_vsi_meminfo(struct sysinfo *val)
19952 +{
19953 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19954 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
19955 +       u64 res_limit, res_usage;
19956 +
19957 +       if (!mcg)
19958 +               return;
19959 +
19960 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19961 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19962 +
19963 +       if (res_limit != RESOURCE_MAX)
19964 +               val->totalram = (res_limit >> PAGE_SHIFT);
19965 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19966 +       val->bufferram = 0;
19967 +       val->totalhigh = 0;
19968 +       val->freehigh = 0;
19969 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19970 +       return;
19971 +}
19972 +
19973 +void vx_vsi_swapinfo(struct sysinfo *val)
19974 +{
19975 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19976 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19977 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
19978 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19979 +       s64 swap_limit, swap_usage;
19980 +
19981 +       if (!mcg)
19982 +               return;
19983 +
19984 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19985 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19986 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19987 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19988 +
19989 +       /* memory unlimited */
19990 +       if (res_limit == RESOURCE_MAX)
19991 +               return;
19992 +
19993 +       swap_limit = memsw_limit - res_limit;
19994 +       /* we have a swap limit? */
19995 +       if (memsw_limit != RESOURCE_MAX)
19996 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19997 +
19998 +       /* calculate swap part */
19999 +       swap_usage = (memsw_usage > res_usage) ?
20000 +               memsw_usage - res_usage : 0;
20001 +
20002 +       /* total shown minus usage gives free swap */
20003 +       val->freeswap = (swap_usage < swap_limit) ?
20004 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20005 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20006 +       val->totalswap = 0;
20007 +       val->freeswap = 0;
20008 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20009 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20010 +       return;
20011 +}
20012 +
20013 +long vx_vsi_cached(struct sysinfo *val)
20014 +{
20015 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20016 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20017 +
20018 +       return mem_cgroup_stat_read_cache(mcg);
20019 +#else
20020 +       return 0;
20021 +#endif
20022 +}
20023 +
20024 diff -NurpP --minimal linux-3.3.1/kernel/vserver/limit_init.h linux-3.3.1-vs2.3.3.2/kernel/vserver/limit_init.h
20025 --- linux-3.3.1/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
20026 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/limit_init.h   2012-02-24 03:55:07.000000000 +0100
20027 @@ -0,0 +1,31 @@
20028 +
20029 +
20030 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20031 +{
20032 +       int lim;
20033 +
20034 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20035 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20036 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20037 +               __rlim_set(limit, lim, 0);
20038 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20039 +               __rlim_rmin(limit, lim) = 0;
20040 +               __rlim_rmax(limit, lim) = 0;
20041 +       }
20042 +}
20043 +
20044 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20045 +{
20046 +       rlim_t value;
20047 +       int lim;
20048 +
20049 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20050 +               if ((1 << lim) & VLIM_NOCHECK)
20051 +                       continue;
20052 +               value = __rlim_get(limit, lim);
20053 +               vxwprintk_xid(value,
20054 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20055 +                       limit, vlimit_name[lim], lim, (long)value);
20056 +       }
20057 +}
20058 +
20059 diff -NurpP --minimal linux-3.3.1/kernel/vserver/limit_proc.h linux-3.3.1-vs2.3.3.2/kernel/vserver/limit_proc.h
20060 --- linux-3.3.1/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20061 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/limit_proc.h   2012-02-24 03:55:07.000000000 +0100
20062 @@ -0,0 +1,57 @@
20063 +#ifndef _VX_LIMIT_PROC_H
20064 +#define _VX_LIMIT_PROC_H
20065 +
20066 +#include <linux/vserver/limit_int.h>
20067 +
20068 +
20069 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20070 +#define VX_LIMIT_TOP   \
20071 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20072 +
20073 +#define VX_LIMIT_ARG(r)                                \
20074 +       (unsigned long)__rlim_get(limit, r),    \
20075 +       (unsigned long)__rlim_rmin(limit, r),   \
20076 +       (unsigned long)__rlim_rmax(limit, r),   \
20077 +       VX_VLIM(__rlim_soft(limit, r)),         \
20078 +       VX_VLIM(__rlim_hard(limit, r)),         \
20079 +       atomic_read(&__rlim_lhit(limit, r))
20080 +
20081 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20082 +{
20083 +       vx_limit_fixup(limit, -1);
20084 +       return sprintf(buffer, VX_LIMIT_TOP
20085 +               "PROC"  VX_LIMIT_FMT
20086 +               "VM"    VX_LIMIT_FMT
20087 +               "VML"   VX_LIMIT_FMT
20088 +               "RSS"   VX_LIMIT_FMT
20089 +               "ANON"  VX_LIMIT_FMT
20090 +               "RMAP"  VX_LIMIT_FMT
20091 +               "FILES" VX_LIMIT_FMT
20092 +               "OFD"   VX_LIMIT_FMT
20093 +               "LOCKS" VX_LIMIT_FMT
20094 +               "SOCK"  VX_LIMIT_FMT
20095 +               "MSGQ"  VX_LIMIT_FMT
20096 +               "SHM"   VX_LIMIT_FMT
20097 +               "SEMA"  VX_LIMIT_FMT
20098 +               "SEMS"  VX_LIMIT_FMT
20099 +               "DENT"  VX_LIMIT_FMT,
20100 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20101 +               VX_LIMIT_ARG(RLIMIT_AS),
20102 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20103 +               VX_LIMIT_ARG(RLIMIT_RSS),
20104 +               VX_LIMIT_ARG(VLIMIT_ANON),
20105 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20106 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20107 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20108 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20109 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20110 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20111 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20112 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20113 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20114 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20115 +}
20116 +
20117 +#endif /* _VX_LIMIT_PROC_H */
20118 +
20119 +
20120 diff -NurpP --minimal linux-3.3.1/kernel/vserver/network.c linux-3.3.1-vs2.3.3.2/kernel/vserver/network.c
20121 --- linux-3.3.1/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20122 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/network.c      2012-02-24 03:55:07.000000000 +0100
20123 @@ -0,0 +1,912 @@
20124 +/*
20125 + *  linux/kernel/vserver/network.c
20126 + *
20127 + *  Virtual Server: Network Support
20128 + *
20129 + *  Copyright (C) 2003-2007  Herbert Pötzl
20130 + *
20131 + *  V0.01  broken out from vcontext V0.05
20132 + *  V0.02  cleaned up implementation
20133 + *  V0.03  added equiv nx commands
20134 + *  V0.04  switch to RCU based hash
20135 + *  V0.05  and back to locking again
20136 + *  V0.06  changed vcmds to nxi arg
20137 + *  V0.07  have __create claim() the nxi
20138 + *
20139 + */
20140 +
20141 +#include <linux/err.h>
20142 +#include <linux/slab.h>
20143 +#include <linux/rcupdate.h>
20144 +
20145 +#include <linux/vs_network.h>
20146 +#include <linux/vs_pid.h>
20147 +#include <linux/vserver/network_cmd.h>
20148 +
20149 +
20150 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20151 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20152 +
20153 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20154 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20155 +
20156 +
20157 +static int __init init_network(void)
20158 +{
20159 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20160 +               sizeof(struct nx_addr_v4), 0,
20161 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20162 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20163 +               sizeof(struct nx_addr_v6), 0,
20164 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20165 +       return 0;
20166 +}
20167 +
20168 +
20169 +/*     __alloc_nx_addr_v4()                                    */
20170 +
20171 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20172 +{
20173 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20174 +               nx_addr_v4_cachep, GFP_KERNEL);
20175 +
20176 +       if (!IS_ERR(nxa))
20177 +               memset(nxa, 0, sizeof(*nxa));
20178 +       return nxa;
20179 +}
20180 +
20181 +/*     __dealloc_nx_addr_v4()                                  */
20182 +
20183 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20184 +{
20185 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20186 +}
20187 +
20188 +/*     __dealloc_nx_addr_v4_all()                              */
20189 +
20190 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20191 +{
20192 +       while (nxa) {
20193 +               struct nx_addr_v4 *next = nxa->next;
20194 +
20195 +               __dealloc_nx_addr_v4(nxa);
20196 +               nxa = next;
20197 +       }
20198 +}
20199 +
20200 +
20201 +#ifdef CONFIG_IPV6
20202 +
20203 +/*     __alloc_nx_addr_v6()                                    */
20204 +
20205 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20206 +{
20207 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20208 +               nx_addr_v6_cachep, GFP_KERNEL);
20209 +
20210 +       if (!IS_ERR(nxa))
20211 +               memset(nxa, 0, sizeof(*nxa));
20212 +       return nxa;
20213 +}
20214 +
20215 +/*     __dealloc_nx_addr_v6()                                  */
20216 +
20217 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20218 +{
20219 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20220 +}
20221 +
20222 +/*     __dealloc_nx_addr_v6_all()                              */
20223 +
20224 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20225 +{
20226 +       while (nxa) {
20227 +               struct nx_addr_v6 *next = nxa->next;
20228 +
20229 +               __dealloc_nx_addr_v6(nxa);
20230 +               nxa = next;
20231 +       }
20232 +}
20233 +
20234 +#endif /* CONFIG_IPV6 */
20235 +
20236 +/*     __alloc_nx_info()
20237 +
20238 +       * allocate an initialized nx_info struct
20239 +       * doesn't make it visible (hash)                        */
20240 +
20241 +static struct nx_info *__alloc_nx_info(nid_t nid)
20242 +{
20243 +       struct nx_info *new = NULL;
20244 +
20245 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20246 +
20247 +       /* would this benefit from a slab cache? */
20248 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20249 +       if (!new)
20250 +               return 0;
20251 +
20252 +       memset(new, 0, sizeof(struct nx_info));
20253 +       new->nx_id = nid;
20254 +       INIT_HLIST_NODE(&new->nx_hlist);
20255 +       atomic_set(&new->nx_usecnt, 0);
20256 +       atomic_set(&new->nx_tasks, 0);
20257 +       new->nx_state = 0;
20258 +
20259 +       new->nx_flags = NXF_INIT_SET;
20260 +
20261 +       /* rest of init goes here */
20262 +
20263 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20264 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20265 +
20266 +       vxdprintk(VXD_CBIT(nid, 0),
20267 +               "alloc_nx_info(%d) = %p", nid, new);
20268 +       atomic_inc(&nx_global_ctotal);
20269 +       return new;
20270 +}
20271 +
20272 +/*     __dealloc_nx_info()
20273 +
20274 +       * final disposal of nx_info                             */
20275 +
20276 +static void __dealloc_nx_info(struct nx_info *nxi)
20277 +{
20278 +       vxdprintk(VXD_CBIT(nid, 0),
20279 +               "dealloc_nx_info(%p)", nxi);
20280 +
20281 +       nxi->nx_hlist.next = LIST_POISON1;
20282 +       nxi->nx_id = -1;
20283 +
20284 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20285 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20286 +
20287 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20288 +
20289 +       nxi->nx_state |= NXS_RELEASED;
20290 +       kfree(nxi);
20291 +       atomic_dec(&nx_global_ctotal);
20292 +}
20293 +
20294 +static void __shutdown_nx_info(struct nx_info *nxi)
20295 +{
20296 +       nxi->nx_state |= NXS_SHUTDOWN;
20297 +       vs_net_change(nxi, VSC_NETDOWN);
20298 +}
20299 +
20300 +/*     exported stuff                                          */
20301 +
20302 +void free_nx_info(struct nx_info *nxi)
20303 +{
20304 +       /* context shutdown is mandatory */
20305 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20306 +
20307 +       /* context must not be hashed */
20308 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20309 +
20310 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20311 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20312 +
20313 +       __dealloc_nx_info(nxi);
20314 +}
20315 +
20316 +
20317 +void __nx_set_lback(struct nx_info *nxi)
20318 +{
20319 +       int nid = nxi->nx_id;
20320 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20321 +
20322 +       nxi->v4_lback.s_addr = lback;
20323 +}
20324 +
20325 +extern int __nx_inet_add_lback(__be32 addr);
20326 +extern int __nx_inet_del_lback(__be32 addr);
20327 +
20328 +
20329 +/*     hash table for nx_info hash */
20330 +
20331 +#define NX_HASH_SIZE   13
20332 +
20333 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20334 +
20335 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20336 +
20337 +
20338 +static inline unsigned int __hashval(nid_t nid)
20339 +{
20340 +       return (nid % NX_HASH_SIZE);
20341 +}
20342 +
20343 +
20344 +
20345 +/*     __hash_nx_info()
20346 +
20347 +       * add the nxi to the global hash table
20348 +       * requires the hash_lock to be held                     */
20349 +
20350 +static inline void __hash_nx_info(struct nx_info *nxi)
20351 +{
20352 +       struct hlist_head *head;
20353 +
20354 +       vxd_assert_lock(&nx_info_hash_lock);
20355 +       vxdprintk(VXD_CBIT(nid, 4),
20356 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20357 +
20358 +       /* context must not be hashed */
20359 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20360 +
20361 +       nxi->nx_state |= NXS_HASHED;
20362 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20363 +       hlist_add_head(&nxi->nx_hlist, head);
20364 +       atomic_inc(&nx_global_cactive);
20365 +}
20366 +
20367 +/*     __unhash_nx_info()
20368 +
20369 +       * remove the nxi from the global hash table
20370 +       * requires the hash_lock to be held                     */
20371 +
20372 +static inline void __unhash_nx_info(struct nx_info *nxi)
20373 +{
20374 +       vxd_assert_lock(&nx_info_hash_lock);
20375 +       vxdprintk(VXD_CBIT(nid, 4),
20376 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20377 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20378 +
20379 +       /* context must be hashed */
20380 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20381 +       /* but without tasks */
20382 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20383 +
20384 +       nxi->nx_state &= ~NXS_HASHED;
20385 +       hlist_del(&nxi->nx_hlist);
20386 +       atomic_dec(&nx_global_cactive);
20387 +}
20388 +
20389 +
20390 +/*     __lookup_nx_info()
20391 +
20392 +       * requires the hash_lock to be held
20393 +       * doesn't increment the nx_refcnt                       */
20394 +
20395 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20396 +{
20397 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20398 +       struct hlist_node *pos;
20399 +       struct nx_info *nxi;
20400 +
20401 +       vxd_assert_lock(&nx_info_hash_lock);
20402 +       hlist_for_each(pos, head) {
20403 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20404 +
20405 +               if (nxi->nx_id == nid)
20406 +                       goto found;
20407 +       }
20408 +       nxi = NULL;
20409 +found:
20410 +       vxdprintk(VXD_CBIT(nid, 0),
20411 +               "__lookup_nx_info(#%u): %p[#%u]",
20412 +               nid, nxi, nxi ? nxi->nx_id : 0);
20413 +       return nxi;
20414 +}
20415 +
20416 +
20417 +/*     __create_nx_info()
20418 +
20419 +       * create the requested context
20420 +       * get(), claim() and hash it                            */
20421 +
20422 +static struct nx_info *__create_nx_info(int id)
20423 +{
20424 +       struct nx_info *new, *nxi = NULL;
20425 +
20426 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20427 +
20428 +       if (!(new = __alloc_nx_info(id)))
20429 +               return ERR_PTR(-ENOMEM);
20430 +
20431 +       /* required to make dynamic xids unique */
20432 +       spin_lock(&nx_info_hash_lock);
20433 +
20434 +       /* static context requested */
20435 +       if ((nxi = __lookup_nx_info(id))) {
20436 +               vxdprintk(VXD_CBIT(nid, 0),
20437 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20438 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20439 +                       nxi = ERR_PTR(-EBUSY);
20440 +               else
20441 +                       nxi = ERR_PTR(-EEXIST);
20442 +               goto out_unlock;
20443 +       }
20444 +       /* new context */
20445 +       vxdprintk(VXD_CBIT(nid, 0),
20446 +               "create_nx_info(%d) = %p (new)", id, new);
20447 +       claim_nx_info(new, NULL);
20448 +       __nx_set_lback(new);
20449 +       __hash_nx_info(get_nx_info(new));
20450 +       nxi = new, new = NULL;
20451 +
20452 +out_unlock:
20453 +       spin_unlock(&nx_info_hash_lock);
20454 +       if (new)
20455 +               __dealloc_nx_info(new);
20456 +       return nxi;
20457 +}
20458 +
20459 +
20460 +
20461 +/*     exported stuff                                          */
20462 +
20463 +
20464 +void unhash_nx_info(struct nx_info *nxi)
20465 +{
20466 +       __shutdown_nx_info(nxi);
20467 +       spin_lock(&nx_info_hash_lock);
20468 +       __unhash_nx_info(nxi);
20469 +       spin_unlock(&nx_info_hash_lock);
20470 +}
20471 +
20472 +/*     lookup_nx_info()
20473 +
20474 +       * search for a nx_info and get() it
20475 +       * negative id means current                             */
20476 +
20477 +struct nx_info *lookup_nx_info(int id)
20478 +{
20479 +       struct nx_info *nxi = NULL;
20480 +
20481 +       if (id < 0) {
20482 +               nxi = get_nx_info(current_nx_info());
20483 +       } else if (id > 1) {
20484 +               spin_lock(&nx_info_hash_lock);
20485 +               nxi = get_nx_info(__lookup_nx_info(id));
20486 +               spin_unlock(&nx_info_hash_lock);
20487 +       }
20488 +       return nxi;
20489 +}
20490 +
20491 +/*     nid_is_hashed()
20492 +
20493 +       * verify that nid is still hashed                       */
20494 +
20495 +int nid_is_hashed(nid_t nid)
20496 +{
20497 +       int hashed;
20498 +
20499 +       spin_lock(&nx_info_hash_lock);
20500 +       hashed = (__lookup_nx_info(nid) != NULL);
20501 +       spin_unlock(&nx_info_hash_lock);
20502 +       return hashed;
20503 +}
20504 +
20505 +
20506 +#ifdef CONFIG_PROC_FS
20507 +
20508 +/*     get_nid_list()
20509 +
20510 +       * get a subset of hashed nids for proc
20511 +       * assumes size is at least one                          */
20512 +
20513 +int get_nid_list(int index, unsigned int *nids, int size)
20514 +{
20515 +       int hindex, nr_nids = 0;
20516 +
20517 +       /* only show current and children */
20518 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20519 +               if (index > 0)
20520 +                       return 0;
20521 +               nids[nr_nids] = nx_current_nid();
20522 +               return 1;
20523 +       }
20524 +
20525 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20526 +               struct hlist_head *head = &nx_info_hash[hindex];
20527 +               struct hlist_node *pos;
20528 +
20529 +               spin_lock(&nx_info_hash_lock);
20530 +               hlist_for_each(pos, head) {
20531 +                       struct nx_info *nxi;
20532 +
20533 +                       if (--index > 0)
20534 +                               continue;
20535 +
20536 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20537 +                       nids[nr_nids] = nxi->nx_id;
20538 +                       if (++nr_nids >= size) {
20539 +                               spin_unlock(&nx_info_hash_lock);
20540 +                               goto out;
20541 +                       }
20542 +               }
20543 +               /* keep the lock time short */
20544 +               spin_unlock(&nx_info_hash_lock);
20545 +       }
20546 +out:
20547 +       return nr_nids;
20548 +}
20549 +#endif
20550 +
20551 +
20552 +/*
20553 + *     migrate task to new network
20554 + *     gets nxi, puts old_nxi on change
20555 + */
20556 +
20557 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20558 +{
20559 +       struct nx_info *old_nxi;
20560 +       int ret = 0;
20561 +
20562 +       if (!p || !nxi)
20563 +               BUG();
20564 +
20565 +       vxdprintk(VXD_CBIT(nid, 5),
20566 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20567 +               p, nxi, nxi->nx_id,
20568 +               atomic_read(&nxi->nx_usecnt),
20569 +               atomic_read(&nxi->nx_tasks));
20570 +
20571 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20572 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20573 +               return -EACCES;
20574 +
20575 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20576 +               return -EFAULT;
20577 +
20578 +       /* maybe disallow this completely? */
20579 +       old_nxi = task_get_nx_info(p);
20580 +       if (old_nxi == nxi)
20581 +               goto out;
20582 +
20583 +       task_lock(p);
20584 +       if (old_nxi)
20585 +               clr_nx_info(&p->nx_info);
20586 +       claim_nx_info(nxi, p);
20587 +       set_nx_info(&p->nx_info, nxi);
20588 +       p->nid = nxi->nx_id;
20589 +       task_unlock(p);
20590 +
20591 +       vxdprintk(VXD_CBIT(nid, 5),
20592 +               "moved task %p into nxi:%p[#%d]",
20593 +               p, nxi, nxi->nx_id);
20594 +
20595 +       if (old_nxi)
20596 +               release_nx_info(old_nxi, p);
20597 +       ret = 0;
20598 +out:
20599 +       put_nx_info(old_nxi);
20600 +       return ret;
20601 +}
20602 +
20603 +
20604 +void nx_set_persistent(struct nx_info *nxi)
20605 +{
20606 +       vxdprintk(VXD_CBIT(nid, 6),
20607 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20608 +
20609 +       get_nx_info(nxi);
20610 +       claim_nx_info(nxi, NULL);
20611 +}
20612 +
20613 +void nx_clear_persistent(struct nx_info *nxi)
20614 +{
20615 +       vxdprintk(VXD_CBIT(nid, 6),
20616 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20617 +
20618 +       release_nx_info(nxi, NULL);
20619 +       put_nx_info(nxi);
20620 +}
20621 +
20622 +void nx_update_persistent(struct nx_info *nxi)
20623 +{
20624 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20625 +               nx_set_persistent(nxi);
20626 +       else
20627 +               nx_clear_persistent(nxi);
20628 +}
20629 +
20630 +/* vserver syscall commands below here */
20631 +
20632 +/* taks nid and nx_info functions */
20633 +
20634 +#include <asm/uaccess.h>
20635 +
20636 +
20637 +int vc_task_nid(uint32_t id)
20638 +{
20639 +       nid_t nid;
20640 +
20641 +       if (id) {
20642 +               struct task_struct *tsk;
20643 +
20644 +               rcu_read_lock();
20645 +               tsk = find_task_by_real_pid(id);
20646 +               nid = (tsk) ? tsk->nid : -ESRCH;
20647 +               rcu_read_unlock();
20648 +       } else
20649 +               nid = nx_current_nid();
20650 +       return nid;
20651 +}
20652 +
20653 +
20654 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20655 +{
20656 +       struct vcmd_nx_info_v0 vc_data;
20657 +
20658 +       vc_data.nid = nxi->nx_id;
20659 +
20660 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20661 +               return -EFAULT;
20662 +       return 0;
20663 +}
20664 +
20665 +
20666 +/* network functions */
20667 +
20668 +int vc_net_create(uint32_t nid, void __user *data)
20669 +{
20670 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20671 +       struct nx_info *new_nxi;
20672 +       int ret;
20673 +
20674 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20675 +               return -EFAULT;
20676 +
20677 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20678 +               return -EINVAL;
20679 +
20680 +       new_nxi = __create_nx_info(nid);
20681 +       if (IS_ERR(new_nxi))
20682 +               return PTR_ERR(new_nxi);
20683 +
20684 +       /* initial flags */
20685 +       new_nxi->nx_flags = vc_data.flagword;
20686 +
20687 +       ret = -ENOEXEC;
20688 +       if (vs_net_change(new_nxi, VSC_NETUP))
20689 +               goto out;
20690 +
20691 +       ret = nx_migrate_task(current, new_nxi);
20692 +       if (ret)
20693 +               goto out;
20694 +
20695 +       /* return context id on success */
20696 +       ret = new_nxi->nx_id;
20697 +
20698 +       /* get a reference for persistent contexts */
20699 +       if ((vc_data.flagword & NXF_PERSISTENT))
20700 +               nx_set_persistent(new_nxi);
20701 +out:
20702 +       release_nx_info(new_nxi, NULL);
20703 +       put_nx_info(new_nxi);
20704 +       return ret;
20705 +}
20706 +
20707 +
20708 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20709 +{
20710 +       return nx_migrate_task(current, nxi);
20711 +}
20712 +
20713 +
20714 +
20715 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20716 +       uint16_t type, uint16_t flags)
20717 +{
20718 +       struct nx_addr_v4 *nxa = &nxi->v4;
20719 +
20720 +       if (NX_IPV4(nxi)) {
20721 +               /* locate last entry */
20722 +               for (; nxa->next; nxa = nxa->next);
20723 +               nxa->next = __alloc_nx_addr_v4();
20724 +               nxa = nxa->next;
20725 +
20726 +               if (IS_ERR(nxa))
20727 +                       return PTR_ERR(nxa);
20728 +       }
20729 +
20730 +       if (nxi->v4.next)
20731 +               /* remove single ip for ip list */
20732 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20733 +
20734 +       nxa->ip[0].s_addr = ip;
20735 +       nxa->ip[1].s_addr = ip2;
20736 +       nxa->mask.s_addr = mask;
20737 +       nxa->type = type;
20738 +       nxa->flags = flags;
20739 +       return 0;
20740 +}
20741 +
20742 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20743 +       uint16_t type, uint16_t flags)
20744 +{
20745 +       struct nx_addr_v4 *nxa = &nxi->v4;
20746 +
20747 +       switch (type) {
20748 +/*     case NXA_TYPE_ADDR:
20749 +               break;          */
20750 +
20751 +       case NXA_TYPE_ANY:
20752 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20753 +               memset(nxa, 0, sizeof(*nxa));
20754 +               break;
20755 +
20756 +       default:
20757 +               return -EINVAL;
20758 +       }
20759 +       return 0;
20760 +}
20761 +
20762 +
20763 +int vc_net_add(struct nx_info *nxi, void __user *data)
20764 +{
20765 +       struct vcmd_net_addr_v0 vc_data;
20766 +       int index, ret = 0;
20767 +
20768 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20769 +               return -EFAULT;
20770 +
20771 +       switch (vc_data.type) {
20772 +       case NXA_TYPE_IPV4:
20773 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20774 +                       return -EINVAL;
20775 +
20776 +               index = 0;
20777 +               while (index < vc_data.count) {
20778 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20779 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20780 +                       if (ret)
20781 +                               return ret;
20782 +                       index++;
20783 +               }
20784 +               ret = index;
20785 +               break;
20786 +
20787 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20788 +               nxi->v4_bcast = vc_data.ip[0];
20789 +               ret = 1;
20790 +               break;
20791 +
20792 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20793 +               nxi->v4_lback = vc_data.ip[0];
20794 +               ret = 1;
20795 +               break;
20796 +
20797 +       default:
20798 +               ret = -EINVAL;
20799 +               break;
20800 +       }
20801 +       return ret;
20802 +}
20803 +
20804 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20805 +{
20806 +       struct vcmd_net_addr_v0 vc_data;
20807 +
20808 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20809 +               return -EFAULT;
20810 +
20811 +       switch (vc_data.type) {
20812 +       case NXA_TYPE_ANY:
20813 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20814 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20815 +               break;
20816 +
20817 +       default:
20818 +               return -EINVAL;
20819 +       }
20820 +       return 0;
20821 +}
20822 +
20823 +
20824 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20825 +{
20826 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20827 +
20828 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20829 +               return -EFAULT;
20830 +
20831 +       switch (vc_data.type) {
20832 +       case NXA_TYPE_ADDR:
20833 +       case NXA_TYPE_MASK:
20834 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20835 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20836 +
20837 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20838 +               nxi->v4_bcast = vc_data.ip;
20839 +               break;
20840 +
20841 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20842 +               nxi->v4_lback = vc_data.ip;
20843 +               break;
20844 +
20845 +       default:
20846 +               return -EINVAL;
20847 +       }
20848 +       return 0;
20849 +}
20850 +
20851 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20852 +{
20853 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20854 +
20855 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20856 +               return -EFAULT;
20857 +
20858 +       switch (vc_data.type) {
20859 +       case NXA_TYPE_ADDR:
20860 +       case NXA_TYPE_MASK:
20861 +       case NXA_TYPE_RANGE:
20862 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20863 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20864 +
20865 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20866 +               nxi->v4_bcast = vc_data.ip;
20867 +               break;
20868 +
20869 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20870 +               nxi->v4_lback = vc_data.ip;
20871 +               break;
20872 +
20873 +       default:
20874 +               return -EINVAL;
20875 +       }
20876 +       return 0;
20877 +}
20878 +
20879 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20880 +{
20881 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20882 +
20883 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20884 +               return -EFAULT;
20885 +
20886 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20887 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20888 +}
20889 +
20890 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20891 +{
20892 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20893 +
20894 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20895 +               return -EFAULT;
20896 +
20897 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20898 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20899 +}
20900 +
20901 +#ifdef CONFIG_IPV6
20902 +
20903 +int do_add_v6_addr(struct nx_info *nxi,
20904 +       struct in6_addr *ip, struct in6_addr *mask,
20905 +       uint32_t prefix, uint16_t type, uint16_t flags)
20906 +{
20907 +       struct nx_addr_v6 *nxa = &nxi->v6;
20908 +
20909 +       if (NX_IPV6(nxi)) {
20910 +               /* locate last entry */
20911 +               for (; nxa->next; nxa = nxa->next);
20912 +               nxa->next = __alloc_nx_addr_v6();
20913 +               nxa = nxa->next;
20914 +
20915 +               if (IS_ERR(nxa))
20916 +                       return PTR_ERR(nxa);
20917 +       }
20918 +
20919 +       nxa->ip = *ip;
20920 +       nxa->mask = *mask;
20921 +       nxa->prefix = prefix;
20922 +       nxa->type = type;
20923 +       nxa->flags = flags;
20924 +       return 0;
20925 +}
20926 +
20927 +
20928 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20929 +{
20930 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20931 +
20932 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20933 +               return -EFAULT;
20934 +
20935 +       switch (vc_data.type) {
20936 +       case NXA_TYPE_ADDR:
20937 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20938 +               /* fallthrough */
20939 +       case NXA_TYPE_MASK:
20940 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20941 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20942 +       default:
20943 +               return -EINVAL;
20944 +       }
20945 +       return 0;
20946 +}
20947 +
20948 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20949 +{
20950 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20951 +
20952 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20953 +               return -EFAULT;
20954 +
20955 +       switch (vc_data.type) {
20956 +       case NXA_TYPE_ANY:
20957 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20958 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20959 +               break;
20960 +
20961 +       default:
20962 +               return -EINVAL;
20963 +       }
20964 +       return 0;
20965 +}
20966 +
20967 +#endif /* CONFIG_IPV6 */
20968 +
20969 +
20970 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20971 +{
20972 +       struct vcmd_net_flags_v0 vc_data;
20973 +
20974 +       vc_data.flagword = nxi->nx_flags;
20975 +
20976 +       /* special STATE flag handling */
20977 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20978 +
20979 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20980 +               return -EFAULT;
20981 +       return 0;
20982 +}
20983 +
20984 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20985 +{
20986 +       struct vcmd_net_flags_v0 vc_data;
20987 +       uint64_t mask, trigger;
20988 +
20989 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20990 +               return -EFAULT;
20991 +
20992 +       /* special STATE flag handling */
20993 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20994 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20995 +
20996 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20997 +               vc_data.flagword, mask);
20998 +       if (trigger & NXF_PERSISTENT)
20999 +               nx_update_persistent(nxi);
21000 +
21001 +       return 0;
21002 +}
21003 +
21004 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21005 +{
21006 +       struct vcmd_net_caps_v0 vc_data;
21007 +
21008 +       vc_data.ncaps = nxi->nx_ncaps;
21009 +       vc_data.cmask = ~0ULL;
21010 +
21011 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21012 +               return -EFAULT;
21013 +       return 0;
21014 +}
21015 +
21016 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21017 +{
21018 +       struct vcmd_net_caps_v0 vc_data;
21019 +
21020 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21021 +               return -EFAULT;
21022 +
21023 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21024 +               vc_data.ncaps, vc_data.cmask);
21025 +       return 0;
21026 +}
21027 +
21028 +
21029 +#include <linux/module.h>
21030 +
21031 +module_init(init_network);
21032 +
21033 +EXPORT_SYMBOL_GPL(free_nx_info);
21034 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21035 +
21036 diff -NurpP --minimal linux-3.3.1/kernel/vserver/proc.c linux-3.3.1-vs2.3.3.2/kernel/vserver/proc.c
21037 --- linux-3.3.1/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21038 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/proc.c 2012-02-24 03:55:07.000000000 +0100
21039 @@ -0,0 +1,1103 @@
21040 +/*
21041 + *  linux/kernel/vserver/proc.c
21042 + *
21043 + *  Virtual Context Support
21044 + *
21045 + *  Copyright (C) 2003-2011  Herbert Pötzl
21046 + *
21047 + *  V0.01  basic structure
21048 + *  V0.02  adaptation vs1.3.0
21049 + *  V0.03  proc permissions
21050 + *  V0.04  locking/generic
21051 + *  V0.05  next generation procfs
21052 + *  V0.06  inode validation
21053 + *  V0.07  generic rewrite vid
21054 + *  V0.08  remove inode type
21055 + *  V0.09  added u/wmask info
21056 + *
21057 + */
21058 +
21059 +#include <linux/proc_fs.h>
21060 +#include <linux/fs_struct.h>
21061 +#include <linux/mount.h>
21062 +#include <asm/unistd.h>
21063 +
21064 +#include <linux/vs_context.h>
21065 +#include <linux/vs_network.h>
21066 +#include <linux/vs_cvirt.h>
21067 +
21068 +#include <linux/in.h>
21069 +#include <linux/inetdevice.h>
21070 +#include <linux/vs_inet.h>
21071 +#include <linux/vs_inet6.h>
21072 +
21073 +#include <linux/vserver/global.h>
21074 +
21075 +#include "cvirt_proc.h"
21076 +#include "cacct_proc.h"
21077 +#include "limit_proc.h"
21078 +#include "sched_proc.h"
21079 +#include "vci_config.h"
21080 +
21081 +
21082 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21083 +{
21084 +       unsigned __capi;
21085 +
21086 +       CAP_FOR_EACH_U32(__capi) {
21087 +               buffer += sprintf(buffer, "%08x",
21088 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21089 +       }
21090 +       return buffer;
21091 +}
21092 +
21093 +
21094 +static struct proc_dir_entry *proc_virtual;
21095 +
21096 +static struct proc_dir_entry *proc_virtnet;
21097 +
21098 +
21099 +/* first the actual feeds */
21100 +
21101 +
21102 +static int proc_vci(char *buffer)
21103 +{
21104 +       return sprintf(buffer,
21105 +               "VCIVersion:\t%04x:%04x\n"
21106 +               "VCISyscall:\t%d\n"
21107 +               "VCIKernel:\t%08x\n",
21108 +               VCI_VERSION >> 16,
21109 +               VCI_VERSION & 0xFFFF,
21110 +               __NR_vserver,
21111 +               vci_kernel_config());
21112 +}
21113 +
21114 +static int proc_virtual_info(char *buffer)
21115 +{
21116 +       return proc_vci(buffer);
21117 +}
21118 +
21119 +static int proc_virtual_status(char *buffer)
21120 +{
21121 +       return sprintf(buffer,
21122 +               "#CTotal:\t%d\n"
21123 +               "#CActive:\t%d\n"
21124 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21125 +               "#InitTask:\t%d\t%d %d\n",
21126 +               atomic_read(&vx_global_ctotal),
21127 +               atomic_read(&vx_global_cactive),
21128 +               atomic_read(&vs_global_nsproxy),
21129 +               atomic_read(&vs_global_fs),
21130 +               atomic_read(&vs_global_mnt_ns),
21131 +               atomic_read(&vs_global_uts_ns),
21132 +               atomic_read(&nr_ipc_ns),
21133 +               atomic_read(&vs_global_user_ns),
21134 +               atomic_read(&vs_global_pid_ns),
21135 +               atomic_read(&init_task.usage),
21136 +               atomic_read(&init_task.nsproxy->count),
21137 +               init_task.fs->users);
21138 +}
21139 +
21140 +
21141 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21142 +{
21143 +       int length;
21144 +
21145 +       length = sprintf(buffer,
21146 +               "ID:\t%d\n"
21147 +               "Info:\t%p\n"
21148 +               "Init:\t%d\n"
21149 +               "OOM:\t%lld\n",
21150 +               vxi->vx_id,
21151 +               vxi,
21152 +               vxi->vx_initpid,
21153 +               vxi->vx_badness_bias);
21154 +       return length;
21155 +}
21156 +
21157 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21158 +{
21159 +       char *orig = buffer;
21160 +
21161 +       buffer += sprintf(buffer,
21162 +               "UseCnt:\t%d\n"
21163 +               "Tasks:\t%d\n"
21164 +               "Flags:\t%016llx\n",
21165 +               atomic_read(&vxi->vx_usecnt),
21166 +               atomic_read(&vxi->vx_tasks),
21167 +               (unsigned long long)vxi->vx_flags);
21168 +
21169 +       buffer += sprintf(buffer, "BCaps:\t");
21170 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21171 +       buffer += sprintf(buffer, "\n");
21172 +
21173 +       buffer += sprintf(buffer,
21174 +               "CCaps:\t%016llx\n"
21175 +               "Umask:\t%16llx\n"
21176 +               "Wmask:\t%16llx\n"
21177 +               "Spaces:\t%08lx %08lx\n",
21178 +               (unsigned long long)vxi->vx_ccaps,
21179 +               (unsigned long long)vxi->vx_umask,
21180 +               (unsigned long long)vxi->vx_wmask,
21181 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21182 +       return buffer - orig;
21183 +}
21184 +
21185 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21186 +{
21187 +       return vx_info_proc_limit(&vxi->limit, buffer);
21188 +}
21189 +
21190 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21191 +{
21192 +       int cpu, length;
21193 +
21194 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21195 +       for_each_online_cpu(cpu) {
21196 +               length += vx_info_proc_sched_pc(
21197 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21198 +                       buffer + length, cpu);
21199 +       }
21200 +       return length;
21201 +}
21202 +
21203 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21204 +{
21205 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21206 +}
21207 +
21208 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21209 +{
21210 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21211 +}
21212 +
21213 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21214 +{
21215 +       int cpu, length;
21216 +
21217 +       vx_update_load(vxi);
21218 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21219 +       for_each_online_cpu(cpu) {
21220 +               length += vx_info_proc_cvirt_pc(
21221 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21222 +                       buffer + length, cpu);
21223 +       }
21224 +       return length;
21225 +}
21226 +
21227 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21228 +{
21229 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21230 +}
21231 +
21232 +
21233 +static int proc_virtnet_info(char *buffer)
21234 +{
21235 +       return proc_vci(buffer);
21236 +}
21237 +
21238 +static int proc_virtnet_status(char *buffer)
21239 +{
21240 +       return sprintf(buffer,
21241 +               "#CTotal:\t%d\n"
21242 +               "#CActive:\t%d\n",
21243 +               atomic_read(&nx_global_ctotal),
21244 +               atomic_read(&nx_global_cactive));
21245 +}
21246 +
21247 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21248 +{
21249 +       struct nx_addr_v4 *v4a;
21250 +#ifdef CONFIG_IPV6
21251 +       struct nx_addr_v6 *v6a;
21252 +#endif
21253 +       int length, i;
21254 +
21255 +       length = sprintf(buffer,
21256 +               "ID:\t%d\n"
21257 +               "Info:\t%p\n"
21258 +               "Bcast:\t" NIPQUAD_FMT "\n"
21259 +               "Lback:\t" NIPQUAD_FMT "\n",
21260 +               nxi->nx_id,
21261 +               nxi,
21262 +               NIPQUAD(nxi->v4_bcast.s_addr),
21263 +               NIPQUAD(nxi->v4_lback.s_addr));
21264 +
21265 +       if (!NX_IPV4(nxi))
21266 +               goto skip_v4;
21267 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21268 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21269 +                       i, NXAV4(v4a));
21270 +skip_v4:
21271 +#ifdef CONFIG_IPV6
21272 +       if (!NX_IPV6(nxi))
21273 +               goto skip_v6;
21274 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21275 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21276 +                       i, NXAV6(v6a));
21277 +skip_v6:
21278 +#endif
21279 +       return length;
21280 +}
21281 +
21282 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21283 +{
21284 +       int length;
21285 +
21286 +       length = sprintf(buffer,
21287 +               "UseCnt:\t%d\n"
21288 +               "Tasks:\t%d\n"
21289 +               "Flags:\t%016llx\n"
21290 +               "NCaps:\t%016llx\n",
21291 +               atomic_read(&nxi->nx_usecnt),
21292 +               atomic_read(&nxi->nx_tasks),
21293 +               (unsigned long long)nxi->nx_flags,
21294 +               (unsigned long long)nxi->nx_ncaps);
21295 +       return length;
21296 +}
21297 +
21298 +
21299 +
21300 +/* here the inode helpers */
21301 +
21302 +struct vs_entry {
21303 +       int len;
21304 +       char *name;
21305 +       mode_t mode;
21306 +       struct inode_operations *iop;
21307 +       struct file_operations *fop;
21308 +       union proc_op op;
21309 +};
21310 +
21311 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21312 +{
21313 +       struct inode *inode = new_inode(sb);
21314 +
21315 +       if (!inode)
21316 +               goto out;
21317 +
21318 +       inode->i_mode = p->mode;
21319 +       if (p->iop)
21320 +               inode->i_op = p->iop;
21321 +       if (p->fop)
21322 +               inode->i_fop = p->fop;
21323 +
21324 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21325 +       inode->i_flags |= S_IMMUTABLE;
21326 +
21327 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21328 +
21329 +       inode->i_uid = 0;
21330 +       inode->i_gid = 0;
21331 +       inode->i_tag = 0;
21332 +out:
21333 +       return inode;
21334 +}
21335 +
21336 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21337 +       struct dentry *dentry, int id, void *ptr)
21338 +{
21339 +       struct vs_entry *p = ptr;
21340 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21341 +       struct dentry *error = ERR_PTR(-EINVAL);
21342 +
21343 +       if (!inode)
21344 +               goto out;
21345 +
21346 +       PROC_I(inode)->op = p->op;
21347 +       PROC_I(inode)->fd = id;
21348 +       d_add(dentry, inode);
21349 +       error = NULL;
21350 +out:
21351 +       return error;
21352 +}
21353 +
21354 +/* Lookups */
21355 +
21356 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21357 +
21358 +/*
21359 + * Fill a directory entry.
21360 + *
21361 + * If possible create the dcache entry and derive our inode number and
21362 + * file type from dcache entry.
21363 + *
21364 + * Since all of the proc inode numbers are dynamically generated, the inode
21365 + * numbers do not exist until the inode is cache.  This means creating the
21366 + * the dcache entry in readdir is necessary to keep the inode numbers
21367 + * reported by readdir in sync with the inode numbers reported
21368 + * by stat.
21369 + */
21370 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21371 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21372 +{
21373 +       struct dentry *child, *dir = filp->f_dentry;
21374 +       struct inode *inode;
21375 +       struct qstr qname;
21376 +       ino_t ino = 0;
21377 +       unsigned type = DT_UNKNOWN;
21378 +
21379 +       qname.name = name;
21380 +       qname.len  = len;
21381 +       qname.hash = full_name_hash(name, len);
21382 +
21383 +       child = d_lookup(dir, &qname);
21384 +       if (!child) {
21385 +               struct dentry *new;
21386 +               new = d_alloc(dir, &qname);
21387 +               if (new) {
21388 +                       child = instantiate(dir->d_inode, new, id, ptr);
21389 +                       if (child)
21390 +                               dput(new);
21391 +                       else
21392 +                               child = new;
21393 +               }
21394 +       }
21395 +       if (!child || IS_ERR(child) || !child->d_inode)
21396 +               goto end_instantiate;
21397 +       inode = child->d_inode;
21398 +       if (inode) {
21399 +               ino = inode->i_ino;
21400 +               type = inode->i_mode >> 12;
21401 +       }
21402 +       dput(child);
21403 +end_instantiate:
21404 +       if (!ino)
21405 +               ino = find_inode_number(dir, &qname);
21406 +       if (!ino)
21407 +               ino = 1;
21408 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21409 +}
21410 +
21411 +
21412 +
21413 +/* get and revalidate vx_info/xid */
21414 +
21415 +static inline
21416 +struct vx_info *get_proc_vx_info(struct inode *inode)
21417 +{
21418 +       return lookup_vx_info(PROC_I(inode)->fd);
21419 +}
21420 +
21421 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21422 +{
21423 +       struct inode *inode = dentry->d_inode;
21424 +       xid_t xid = PROC_I(inode)->fd;
21425 +
21426 +       if (!xid || xid_is_hashed(xid))
21427 +               return 1;
21428 +       d_drop(dentry);
21429 +       return 0;
21430 +}
21431 +
21432 +
21433 +/* get and revalidate nx_info/nid */
21434 +
21435 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21436 +{
21437 +       struct inode *inode = dentry->d_inode;
21438 +       nid_t nid = PROC_I(inode)->fd;
21439 +
21440 +       if (!nid || nid_is_hashed(nid))
21441 +               return 1;
21442 +       d_drop(dentry);
21443 +       return 0;
21444 +}
21445 +
21446 +
21447 +
21448 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21449 +
21450 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21451 +                         size_t count, loff_t *ppos)
21452 +{
21453 +       struct inode *inode = file->f_dentry->d_inode;
21454 +       unsigned long page;
21455 +       ssize_t length = 0;
21456 +
21457 +       if (count > PROC_BLOCK_SIZE)
21458 +               count = PROC_BLOCK_SIZE;
21459 +
21460 +       /* fade that out as soon as stable */
21461 +       WARN_ON(PROC_I(inode)->fd);
21462 +
21463 +       if (!(page = __get_free_page(GFP_KERNEL)))
21464 +               return -ENOMEM;
21465 +
21466 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21467 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21468 +
21469 +       if (length >= 0)
21470 +               length = simple_read_from_buffer(buf, count, ppos,
21471 +                       (char *)page, length);
21472 +
21473 +       free_page(page);
21474 +       return length;
21475 +}
21476 +
21477 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21478 +                         size_t count, loff_t *ppos)
21479 +{
21480 +       struct inode *inode = file->f_dentry->d_inode;
21481 +       struct vx_info *vxi = NULL;
21482 +       xid_t xid = PROC_I(inode)->fd;
21483 +       unsigned long page;
21484 +       ssize_t length = 0;
21485 +
21486 +       if (count > PROC_BLOCK_SIZE)
21487 +               count = PROC_BLOCK_SIZE;
21488 +
21489 +       /* fade that out as soon as stable */
21490 +       WARN_ON(!xid);
21491 +       vxi = lookup_vx_info(xid);
21492 +       if (!vxi)
21493 +               goto out;
21494 +
21495 +       length = -ENOMEM;
21496 +       if (!(page = __get_free_page(GFP_KERNEL)))
21497 +               goto out_put;
21498 +
21499 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21500 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21501 +
21502 +       if (length >= 0)
21503 +               length = simple_read_from_buffer(buf, count, ppos,
21504 +                       (char *)page, length);
21505 +
21506 +       free_page(page);
21507 +out_put:
21508 +       put_vx_info(vxi);
21509 +out:
21510 +       return length;
21511 +}
21512 +
21513 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21514 +                         size_t count, loff_t *ppos)
21515 +{
21516 +       struct inode *inode = file->f_dentry->d_inode;
21517 +       struct nx_info *nxi = NULL;
21518 +       nid_t nid = PROC_I(inode)->fd;
21519 +       unsigned long page;
21520 +       ssize_t length = 0;
21521 +
21522 +       if (count > PROC_BLOCK_SIZE)
21523 +               count = PROC_BLOCK_SIZE;
21524 +
21525 +       /* fade that out as soon as stable */
21526 +       WARN_ON(!nid);
21527 +       nxi = lookup_nx_info(nid);
21528 +       if (!nxi)
21529 +               goto out;
21530 +
21531 +       length = -ENOMEM;
21532 +       if (!(page = __get_free_page(GFP_KERNEL)))
21533 +               goto out_put;
21534 +
21535 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21536 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21537 +
21538 +       if (length >= 0)
21539 +               length = simple_read_from_buffer(buf, count, ppos,
21540 +                       (char *)page, length);
21541 +
21542 +       free_page(page);
21543 +out_put:
21544 +       put_nx_info(nxi);
21545 +out:
21546 +       return length;
21547 +}
21548 +
21549 +
21550 +
21551 +/* here comes the lower level */
21552 +
21553 +
21554 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21555 +       .len  = sizeof(NAME) - 1,       \
21556 +       .name = (NAME),                 \
21557 +       .mode = MODE,                   \
21558 +       .iop  = IOP,                    \
21559 +       .fop  = FOP,                    \
21560 +       .op   = OP,                     \
21561 +}
21562 +
21563 +
21564 +#define DIR(NAME, MODE, OTYPE)                         \
21565 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21566 +               &proc_ ## OTYPE ## _inode_operations,   \
21567 +               &proc_ ## OTYPE ## _file_operations, { } )
21568 +
21569 +#define INF(NAME, MODE, OTYPE)                         \
21570 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21571 +               &proc_vs_info_file_operations,          \
21572 +               { .proc_vs_read = &proc_##OTYPE } )
21573 +
21574 +#define VINF(NAME, MODE, OTYPE)                                \
21575 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21576 +               &proc_vx_info_file_operations,          \
21577 +               { .proc_vxi_read = &proc_##OTYPE } )
21578 +
21579 +#define NINF(NAME, MODE, OTYPE)                                \
21580 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21581 +               &proc_nx_info_file_operations,          \
21582 +               { .proc_nxi_read = &proc_##OTYPE } )
21583 +
21584 +
21585 +static struct file_operations proc_vs_info_file_operations = {
21586 +       .read =         proc_vs_info_read,
21587 +};
21588 +
21589 +static struct file_operations proc_vx_info_file_operations = {
21590 +       .read =         proc_vx_info_read,
21591 +};
21592 +
21593 +static struct dentry_operations proc_xid_dentry_operations = {
21594 +       .d_revalidate = proc_xid_revalidate,
21595 +};
21596 +
21597 +static struct vs_entry vx_base_stuff[] = {
21598 +       VINF("info",    S_IRUGO, vxi_info),
21599 +       VINF("status",  S_IRUGO, vxi_status),
21600 +       VINF("limit",   S_IRUGO, vxi_limit),
21601 +       VINF("sched",   S_IRUGO, vxi_sched),
21602 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21603 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21604 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21605 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21606 +       {}
21607 +};
21608 +
21609 +
21610 +
21611 +
21612 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21613 +       struct dentry *dentry, int id, void *ptr)
21614 +{
21615 +       dentry->d_op = &proc_xid_dentry_operations;
21616 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21617 +}
21618 +
21619 +static struct dentry *proc_xid_lookup(struct inode *dir,
21620 +       struct dentry *dentry, struct nameidata *nd)
21621 +{
21622 +       struct vs_entry *p = vx_base_stuff;
21623 +       struct dentry *error = ERR_PTR(-ENOENT);
21624 +
21625 +       for (; p->name; p++) {
21626 +               if (p->len != dentry->d_name.len)
21627 +                       continue;
21628 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21629 +                       break;
21630 +       }
21631 +       if (!p->name)
21632 +               goto out;
21633 +
21634 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21635 +out:
21636 +       return error;
21637 +}
21638 +
21639 +static int proc_xid_readdir(struct file *filp,
21640 +       void *dirent, filldir_t filldir)
21641 +{
21642 +       struct dentry *dentry = filp->f_dentry;
21643 +       struct inode *inode = dentry->d_inode;
21644 +       struct vs_entry *p = vx_base_stuff;
21645 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21646 +       int pos, index;
21647 +       u64 ino;
21648 +
21649 +       pos = filp->f_pos;
21650 +       switch (pos) {
21651 +       case 0:
21652 +               ino = inode->i_ino;
21653 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21654 +                       goto out;
21655 +               pos++;
21656 +               /* fall through */
21657 +       case 1:
21658 +               ino = parent_ino(dentry);
21659 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21660 +                       goto out;
21661 +               pos++;
21662 +               /* fall through */
21663 +       default:
21664 +               index = pos - 2;
21665 +               if (index >= size)
21666 +                       goto out;
21667 +               for (p += index; p->name; p++) {
21668 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21669 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21670 +                               goto out;
21671 +                       pos++;
21672 +               }
21673 +       }
21674 +out:
21675 +       filp->f_pos = pos;
21676 +       return 1;
21677 +}
21678 +
21679 +
21680 +
21681 +static struct file_operations proc_nx_info_file_operations = {
21682 +       .read =         proc_nx_info_read,
21683 +};
21684 +
21685 +static struct dentry_operations proc_nid_dentry_operations = {
21686 +       .d_revalidate = proc_nid_revalidate,
21687 +};
21688 +
21689 +static struct vs_entry nx_base_stuff[] = {
21690 +       NINF("info",    S_IRUGO, nxi_info),
21691 +       NINF("status",  S_IRUGO, nxi_status),
21692 +       {}
21693 +};
21694 +
21695 +
21696 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21697 +       struct dentry *dentry, int id, void *ptr)
21698 +{
21699 +       dentry->d_op = &proc_nid_dentry_operations;
21700 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21701 +}
21702 +
21703 +static struct dentry *proc_nid_lookup(struct inode *dir,
21704 +       struct dentry *dentry, struct nameidata *nd)
21705 +{
21706 +       struct vs_entry *p = nx_base_stuff;
21707 +       struct dentry *error = ERR_PTR(-ENOENT);
21708 +
21709 +       for (; p->name; p++) {
21710 +               if (p->len != dentry->d_name.len)
21711 +                       continue;
21712 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21713 +                       break;
21714 +       }
21715 +       if (!p->name)
21716 +               goto out;
21717 +
21718 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21719 +out:
21720 +       return error;
21721 +}
21722 +
21723 +static int proc_nid_readdir(struct file *filp,
21724 +       void *dirent, filldir_t filldir)
21725 +{
21726 +       struct dentry *dentry = filp->f_dentry;
21727 +       struct inode *inode = dentry->d_inode;
21728 +       struct vs_entry *p = nx_base_stuff;
21729 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21730 +       int pos, index;
21731 +       u64 ino;
21732 +
21733 +       pos = filp->f_pos;
21734 +       switch (pos) {
21735 +       case 0:
21736 +               ino = inode->i_ino;
21737 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21738 +                       goto out;
21739 +               pos++;
21740 +               /* fall through */
21741 +       case 1:
21742 +               ino = parent_ino(dentry);
21743 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21744 +                       goto out;
21745 +               pos++;
21746 +               /* fall through */
21747 +       default:
21748 +               index = pos - 2;
21749 +               if (index >= size)
21750 +                       goto out;
21751 +               for (p += index; p->name; p++) {
21752 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21753 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21754 +                               goto out;
21755 +                       pos++;
21756 +               }
21757 +       }
21758 +out:
21759 +       filp->f_pos = pos;
21760 +       return 1;
21761 +}
21762 +
21763 +
21764 +#define MAX_MULBY10    ((~0U - 9) / 10)
21765 +
21766 +static inline int atovid(const char *str, int len)
21767 +{
21768 +       int vid, c;
21769 +
21770 +       vid = 0;
21771 +       while (len-- > 0) {
21772 +               c = *str - '0';
21773 +               str++;
21774 +               if (c > 9)
21775 +                       return -1;
21776 +               if (vid >= MAX_MULBY10)
21777 +                       return -1;
21778 +               vid *= 10;
21779 +               vid += c;
21780 +               if (!vid)
21781 +                       return -1;
21782 +       }
21783 +       return vid;
21784 +}
21785 +
21786 +/* now the upper level (virtual) */
21787 +
21788 +
21789 +static struct file_operations proc_xid_file_operations = {
21790 +       .read =         generic_read_dir,
21791 +       .readdir =      proc_xid_readdir,
21792 +};
21793 +
21794 +static struct inode_operations proc_xid_inode_operations = {
21795 +       .lookup =       proc_xid_lookup,
21796 +};
21797 +
21798 +static struct vs_entry vx_virtual_stuff[] = {
21799 +       INF("info",     S_IRUGO, virtual_info),
21800 +       INF("status",   S_IRUGO, virtual_status),
21801 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21802 +};
21803 +
21804 +
21805 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21806 +       struct dentry *dentry, struct nameidata *nd)
21807 +{
21808 +       struct vs_entry *p = vx_virtual_stuff;
21809 +       struct dentry *error = ERR_PTR(-ENOENT);
21810 +       int id = 0;
21811 +
21812 +       for (; p->name; p++) {
21813 +               if (p->len != dentry->d_name.len)
21814 +                       continue;
21815 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21816 +                       break;
21817 +       }
21818 +       if (p->name)
21819 +               goto instantiate;
21820 +
21821 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21822 +       if ((id < 0) || !xid_is_hashed(id))
21823 +               goto out;
21824 +
21825 +instantiate:
21826 +       error = proc_xid_instantiate(dir, dentry, id, p);
21827 +out:
21828 +       return error;
21829 +}
21830 +
21831 +static struct file_operations proc_nid_file_operations = {
21832 +       .read =         generic_read_dir,
21833 +       .readdir =      proc_nid_readdir,
21834 +};
21835 +
21836 +static struct inode_operations proc_nid_inode_operations = {
21837 +       .lookup =       proc_nid_lookup,
21838 +};
21839 +
21840 +static struct vs_entry nx_virtnet_stuff[] = {
21841 +       INF("info",     S_IRUGO, virtnet_info),
21842 +       INF("status",   S_IRUGO, virtnet_status),
21843 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21844 +};
21845 +
21846 +
21847 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21848 +       struct dentry *dentry, struct nameidata *nd)
21849 +{
21850 +       struct vs_entry *p = nx_virtnet_stuff;
21851 +       struct dentry *error = ERR_PTR(-ENOENT);
21852 +       int id = 0;
21853 +
21854 +       for (; p->name; p++) {
21855 +               if (p->len != dentry->d_name.len)
21856 +                       continue;
21857 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21858 +                       break;
21859 +       }
21860 +       if (p->name)
21861 +               goto instantiate;
21862 +
21863 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21864 +       if ((id < 0) || !nid_is_hashed(id))
21865 +               goto out;
21866 +
21867 +instantiate:
21868 +       error = proc_nid_instantiate(dir, dentry, id, p);
21869 +out:
21870 +       return error;
21871 +}
21872 +
21873 +
21874 +#define PROC_MAXVIDS 32
21875 +
21876 +int proc_virtual_readdir(struct file *filp,
21877 +       void *dirent, filldir_t filldir)
21878 +{
21879 +       struct dentry *dentry = filp->f_dentry;
21880 +       struct inode *inode = dentry->d_inode;
21881 +       struct vs_entry *p = vx_virtual_stuff;
21882 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21883 +       int pos, index;
21884 +       unsigned int xid_array[PROC_MAXVIDS];
21885 +       char buf[PROC_NUMBUF];
21886 +       unsigned int nr_xids, i;
21887 +       u64 ino;
21888 +
21889 +       pos = filp->f_pos;
21890 +       switch (pos) {
21891 +       case 0:
21892 +               ino = inode->i_ino;
21893 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21894 +                       goto out;
21895 +               pos++;
21896 +               /* fall through */
21897 +       case 1:
21898 +               ino = parent_ino(dentry);
21899 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21900 +                       goto out;
21901 +               pos++;
21902 +               /* fall through */
21903 +       default:
21904 +               index = pos - 2;
21905 +               if (index >= size)
21906 +                       goto entries;
21907 +               for (p += index; p->name; p++) {
21908 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21909 +                               vs_proc_instantiate, 0, p))
21910 +                               goto out;
21911 +                       pos++;
21912 +               }
21913 +       entries:
21914 +               index = pos - size;
21915 +               p = &vx_virtual_stuff[size - 1];
21916 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21917 +               for (i = 0; i < nr_xids; i++) {
21918 +                       int n, xid = xid_array[i];
21919 +                       unsigned int j = PROC_NUMBUF;
21920 +
21921 +                       n = xid;
21922 +                       do
21923 +                               buf[--j] = '0' + (n % 10);
21924 +                       while (n /= 10);
21925 +
21926 +                       if (proc_fill_cache(filp, dirent, filldir,
21927 +                               buf + j, PROC_NUMBUF - j,
21928 +                               vs_proc_instantiate, xid, p))
21929 +                               goto out;
21930 +                       pos++;
21931 +               }
21932 +       }
21933 +out:
21934 +       filp->f_pos = pos;
21935 +       return 0;
21936 +}
21937 +
21938 +static int proc_virtual_getattr(struct vfsmount *mnt,
21939 +       struct dentry *dentry, struct kstat *stat)
21940 +{
21941 +       struct inode *inode = dentry->d_inode;
21942 +
21943 +       generic_fillattr(inode, stat);
21944 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21945 +       return 0;
21946 +}
21947 +
21948 +static struct file_operations proc_virtual_dir_operations = {
21949 +       .read =         generic_read_dir,
21950 +       .readdir =      proc_virtual_readdir,
21951 +};
21952 +
21953 +static struct inode_operations proc_virtual_dir_inode_operations = {
21954 +       .getattr =      proc_virtual_getattr,
21955 +       .lookup =       proc_virtual_lookup,
21956 +};
21957 +
21958 +
21959 +
21960 +
21961 +
21962 +int proc_virtnet_readdir(struct file *filp,
21963 +       void *dirent, filldir_t filldir)
21964 +{
21965 +       struct dentry *dentry = filp->f_dentry;
21966 +       struct inode *inode = dentry->d_inode;
21967 +       struct vs_entry *p = nx_virtnet_stuff;
21968 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21969 +       int pos, index;
21970 +       unsigned int nid_array[PROC_MAXVIDS];
21971 +       char buf[PROC_NUMBUF];
21972 +       unsigned int nr_nids, i;
21973 +       u64 ino;
21974 +
21975 +       pos = filp->f_pos;
21976 +       switch (pos) {
21977 +       case 0:
21978 +               ino = inode->i_ino;
21979 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21980 +                       goto out;
21981 +               pos++;
21982 +               /* fall through */
21983 +       case 1:
21984 +               ino = parent_ino(dentry);
21985 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21986 +                       goto out;
21987 +               pos++;
21988 +               /* fall through */
21989 +       default:
21990 +               index = pos - 2;
21991 +               if (index >= size)
21992 +                       goto entries;
21993 +               for (p += index; p->name; p++) {
21994 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21995 +                               vs_proc_instantiate, 0, p))
21996 +                               goto out;
21997 +                       pos++;
21998 +               }
21999 +       entries:
22000 +               index = pos - size;
22001 +               p = &nx_virtnet_stuff[size - 1];
22002 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22003 +               for (i = 0; i < nr_nids; i++) {
22004 +                       int n, nid = nid_array[i];
22005 +                       unsigned int j = PROC_NUMBUF;
22006 +
22007 +                       n = nid;
22008 +                       do
22009 +                               buf[--j] = '0' + (n % 10);
22010 +                       while (n /= 10);
22011 +
22012 +                       if (proc_fill_cache(filp, dirent, filldir,
22013 +                               buf + j, PROC_NUMBUF - j,
22014 +                               vs_proc_instantiate, nid, p))
22015 +                               goto out;
22016 +                       pos++;
22017 +               }
22018 +       }
22019 +out:
22020 +       filp->f_pos = pos;
22021 +       return 0;
22022 +}
22023 +
22024 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22025 +       struct dentry *dentry, struct kstat *stat)
22026 +{
22027 +       struct inode *inode = dentry->d_inode;
22028 +
22029 +       generic_fillattr(inode, stat);
22030 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22031 +       return 0;
22032 +}
22033 +
22034 +static struct file_operations proc_virtnet_dir_operations = {
22035 +       .read =         generic_read_dir,
22036 +       .readdir =      proc_virtnet_readdir,
22037 +};
22038 +
22039 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22040 +       .getattr =      proc_virtnet_getattr,
22041 +       .lookup =       proc_virtnet_lookup,
22042 +};
22043 +
22044 +
22045 +
22046 +void proc_vx_init(void)
22047 +{
22048 +       struct proc_dir_entry *ent;
22049 +
22050 +       ent = proc_mkdir("virtual", 0);
22051 +       if (ent) {
22052 +               ent->proc_fops = &proc_virtual_dir_operations;
22053 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22054 +       }
22055 +       proc_virtual = ent;
22056 +
22057 +       ent = proc_mkdir("virtnet", 0);
22058 +       if (ent) {
22059 +               ent->proc_fops = &proc_virtnet_dir_operations;
22060 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22061 +       }
22062 +       proc_virtnet = ent;
22063 +}
22064 +
22065 +
22066 +
22067 +
22068 +/* per pid info */
22069 +
22070 +
22071 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22072 +{
22073 +       struct vx_info *vxi;
22074 +       char *orig = buffer;
22075 +
22076 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22077 +
22078 +       vxi = task_get_vx_info(p);
22079 +       if (!vxi)
22080 +               goto out;
22081 +
22082 +       buffer += sprintf(buffer, "BCaps:\t");
22083 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22084 +       buffer += sprintf(buffer, "\n");
22085 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22086 +               (unsigned long long)vxi->vx_ccaps);
22087 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22088 +               (unsigned long long)vxi->vx_flags);
22089 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22090 +
22091 +       put_vx_info(vxi);
22092 +out:
22093 +       return buffer - orig;
22094 +}
22095 +
22096 +
22097 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22098 +{
22099 +       struct nx_info *nxi;
22100 +       struct nx_addr_v4 *v4a;
22101 +#ifdef CONFIG_IPV6
22102 +       struct nx_addr_v6 *v6a;
22103 +#endif
22104 +       char *orig = buffer;
22105 +       int i;
22106 +
22107 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22108 +
22109 +       nxi = task_get_nx_info(p);
22110 +       if (!nxi)
22111 +               goto out;
22112 +
22113 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22114 +               (unsigned long long)nxi->nx_ncaps);
22115 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22116 +               (unsigned long long)nxi->nx_flags);
22117 +
22118 +       buffer += sprintf(buffer,
22119 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22120 +               NIPQUAD(nxi->v4_bcast.s_addr));
22121 +       buffer += sprintf (buffer,
22122 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22123 +               NIPQUAD(nxi->v4_lback.s_addr));
22124 +       if (!NX_IPV4(nxi))
22125 +               goto skip_v4;
22126 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22127 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22128 +                       i, NXAV4(v4a));
22129 +skip_v4:
22130 +#ifdef CONFIG_IPV6
22131 +       if (!NX_IPV6(nxi))
22132 +               goto skip_v6;
22133 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22134 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22135 +                       i, NXAV6(v6a));
22136 +skip_v6:
22137 +#endif
22138 +       put_nx_info(nxi);
22139 +out:
22140 +       return buffer - orig;
22141 +}
22142 +
22143 diff -NurpP --minimal linux-3.3.1/kernel/vserver/sched.c linux-3.3.1-vs2.3.3.2/kernel/vserver/sched.c
22144 --- linux-3.3.1/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22145 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/sched.c        2012-02-24 03:55:07.000000000 +0100
22146 @@ -0,0 +1,82 @@
22147 +/*
22148 + *  linux/kernel/vserver/sched.c
22149 + *
22150 + *  Virtual Server: Scheduler Support
22151 + *
22152 + *  Copyright (C) 2004-2010  Herbert Pötzl
22153 + *
22154 + *  V0.01  adapted Sam Vilains version to 2.6.3
22155 + *  V0.02  removed legacy interface
22156 + *  V0.03  changed vcmds to vxi arg
22157 + *  V0.04  removed older and legacy interfaces
22158 + *  V0.05  removed scheduler code/commands
22159 + *
22160 + */
22161 +
22162 +#include <linux/vs_context.h>
22163 +#include <linux/vs_sched.h>
22164 +#include <linux/vserver/sched_cmd.h>
22165 +
22166 +#include <asm/uaccess.h>
22167 +
22168 +
22169 +void vx_update_sched_param(struct _vx_sched *sched,
22170 +       struct _vx_sched_pc *sched_pc)
22171 +{
22172 +       sched_pc->prio_bias = sched->prio_bias;
22173 +}
22174 +
22175 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22176 +{
22177 +       int cpu;
22178 +
22179 +       if (data->prio_bias > MAX_PRIO_BIAS)
22180 +               data->prio_bias = MAX_PRIO_BIAS;
22181 +       if (data->prio_bias < MIN_PRIO_BIAS)
22182 +               data->prio_bias = MIN_PRIO_BIAS;
22183 +
22184 +       if (data->cpu_id != ~0) {
22185 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22186 +               cpus_and(vxi->sched.update, cpu_online_map,
22187 +                       vxi->sched.update);
22188 +       } else
22189 +               vxi->sched.update = cpu_online_map;
22190 +
22191 +       for_each_cpu_mask(cpu, vxi->sched.update)
22192 +               vx_update_sched_param(&vxi->sched,
22193 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22194 +       return 0;
22195 +}
22196 +
22197 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22198 +{
22199 +       struct vcmd_prio_bias vc_data;
22200 +
22201 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22202 +               return -EFAULT;
22203 +
22204 +       return do_set_prio_bias(vxi, &vc_data);
22205 +}
22206 +
22207 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22208 +{
22209 +       struct vcmd_prio_bias vc_data;
22210 +       struct _vx_sched_pc *pcd;
22211 +       int cpu;
22212 +
22213 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22214 +               return -EFAULT;
22215 +
22216 +       cpu = vc_data.cpu_id;
22217 +
22218 +       if (!cpu_possible(cpu))
22219 +               return -EINVAL;
22220 +
22221 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22222 +       vc_data.prio_bias = pcd->prio_bias;
22223 +
22224 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22225 +               return -EFAULT;
22226 +       return 0;
22227 +}
22228 +
22229 diff -NurpP --minimal linux-3.3.1/kernel/vserver/sched_init.h linux-3.3.1-vs2.3.3.2/kernel/vserver/sched_init.h
22230 --- linux-3.3.1/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22231 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/sched_init.h   2012-02-24 03:55:07.000000000 +0100
22232 @@ -0,0 +1,27 @@
22233 +
22234 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22235 +{
22236 +       /* scheduling; hard code starting values as constants */
22237 +       sched->prio_bias = 0;
22238 +}
22239 +
22240 +static inline
22241 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22242 +{
22243 +       sched_pc->prio_bias = 0;
22244 +
22245 +       sched_pc->user_ticks = 0;
22246 +       sched_pc->sys_ticks = 0;
22247 +       sched_pc->hold_ticks = 0;
22248 +}
22249 +
22250 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22251 +{
22252 +       return;
22253 +}
22254 +
22255 +static inline
22256 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22257 +{
22258 +       return;
22259 +}
22260 diff -NurpP --minimal linux-3.3.1/kernel/vserver/sched_proc.h linux-3.3.1-vs2.3.3.2/kernel/vserver/sched_proc.h
22261 --- linux-3.3.1/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22262 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/sched_proc.h   2012-02-24 03:55:07.000000000 +0100
22263 @@ -0,0 +1,32 @@
22264 +#ifndef _VX_SCHED_PROC_H
22265 +#define _VX_SCHED_PROC_H
22266 +
22267 +
22268 +static inline
22269 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22270 +{
22271 +       int length = 0;
22272 +
22273 +       length += sprintf(buffer,
22274 +               "PrioBias:\t%8d\n",
22275 +               sched->prio_bias);
22276 +       return length;
22277 +}
22278 +
22279 +static inline
22280 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22281 +       char *buffer, int cpu)
22282 +{
22283 +       int length = 0;
22284 +
22285 +       length += sprintf(buffer + length,
22286 +               "cpu %d: %lld %lld %lld", cpu,
22287 +               (unsigned long long)sched_pc->user_ticks,
22288 +               (unsigned long long)sched_pc->sys_ticks,
22289 +               (unsigned long long)sched_pc->hold_ticks);
22290 +       length += sprintf(buffer + length,
22291 +               " %d\n", sched_pc->prio_bias);
22292 +       return length;
22293 +}
22294 +
22295 +#endif /* _VX_SCHED_PROC_H */
22296 diff -NurpP --minimal linux-3.3.1/kernel/vserver/signal.c linux-3.3.1-vs2.3.3.2/kernel/vserver/signal.c
22297 --- linux-3.3.1/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22298 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/signal.c       2012-02-24 03:55:07.000000000 +0100
22299 @@ -0,0 +1,134 @@
22300 +/*
22301 + *  linux/kernel/vserver/signal.c
22302 + *
22303 + *  Virtual Server: Signal Support
22304 + *
22305 + *  Copyright (C) 2003-2007  Herbert Pötzl
22306 + *
22307 + *  V0.01  broken out from vcontext V0.05
22308 + *  V0.02  changed vcmds to vxi arg
22309 + *  V0.03  adjusted siginfo for kill
22310 + *
22311 + */
22312 +
22313 +#include <asm/uaccess.h>
22314 +
22315 +#include <linux/vs_context.h>
22316 +#include <linux/vs_pid.h>
22317 +#include <linux/vserver/signal_cmd.h>
22318 +
22319 +
22320 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22321 +{
22322 +       int retval, count = 0;
22323 +       struct task_struct *p;
22324 +       struct siginfo *sip = SEND_SIG_PRIV;
22325 +
22326 +       retval = -ESRCH;
22327 +       vxdprintk(VXD_CBIT(misc, 4),
22328 +               "vx_info_kill(%p[#%d],%d,%d)*",
22329 +               vxi, vxi->vx_id, pid, sig);
22330 +       read_lock(&tasklist_lock);
22331 +       switch (pid) {
22332 +       case  0:
22333 +       case -1:
22334 +               for_each_process(p) {
22335 +                       int err = 0;
22336 +
22337 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22338 +                               (pid && vxi->vx_initpid == p->pid))
22339 +                               continue;
22340 +
22341 +                       err = group_send_sig_info(sig, sip, p);
22342 +                       ++count;
22343 +                       if (err != -EPERM)
22344 +                               retval = err;
22345 +               }
22346 +               break;
22347 +
22348 +       case 1:
22349 +               if (vxi->vx_initpid) {
22350 +                       pid = vxi->vx_initpid;
22351 +                       /* for now, only SIGINT to private init ... */
22352 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22353 +                               /* ... as long as there are tasks left */
22354 +                               (atomic_read(&vxi->vx_tasks) > 1))
22355 +                               sig = SIGINT;
22356 +               }
22357 +               /* fallthrough */
22358 +       default:
22359 +               rcu_read_lock();
22360 +               p = find_task_by_real_pid(pid);
22361 +               rcu_read_unlock();
22362 +               if (p) {
22363 +                       if (vx_task_xid(p) == vxi->vx_id)
22364 +                               retval = group_send_sig_info(sig, sip, p);
22365 +               }
22366 +               break;
22367 +       }
22368 +       read_unlock(&tasklist_lock);
22369 +       vxdprintk(VXD_CBIT(misc, 4),
22370 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22371 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22372 +       return retval;
22373 +}
22374 +
22375 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22376 +{
22377 +       struct vcmd_ctx_kill_v0 vc_data;
22378 +
22379 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22380 +               return -EFAULT;
22381 +
22382 +       /* special check to allow guest shutdown */
22383 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22384 +               /* forbid killall pid=0 when init is present */
22385 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22386 +               (vc_data.pid > 1)))
22387 +               return -EACCES;
22388 +
22389 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22390 +}
22391 +
22392 +
22393 +static int __wait_exit(struct vx_info *vxi)
22394 +{
22395 +       DECLARE_WAITQUEUE(wait, current);
22396 +       int ret = 0;
22397 +
22398 +       add_wait_queue(&vxi->vx_wait, &wait);
22399 +       set_current_state(TASK_INTERRUPTIBLE);
22400 +
22401 +wait:
22402 +       if (vx_info_state(vxi,
22403 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22404 +               goto out;
22405 +       if (signal_pending(current)) {
22406 +               ret = -ERESTARTSYS;
22407 +               goto out;
22408 +       }
22409 +       schedule();
22410 +       goto wait;
22411 +
22412 +out:
22413 +       set_current_state(TASK_RUNNING);
22414 +       remove_wait_queue(&vxi->vx_wait, &wait);
22415 +       return ret;
22416 +}
22417 +
22418 +
22419 +
22420 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22421 +{
22422 +       struct vcmd_wait_exit_v0 vc_data;
22423 +       int ret;
22424 +
22425 +       ret = __wait_exit(vxi);
22426 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22427 +       vc_data.exit_code = vxi->exit_code;
22428 +
22429 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22430 +               ret = -EFAULT;
22431 +       return ret;
22432 +}
22433 +
22434 diff -NurpP --minimal linux-3.3.1/kernel/vserver/space.c linux-3.3.1-vs2.3.3.2/kernel/vserver/space.c
22435 --- linux-3.3.1/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22436 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/space.c        2012-02-24 17:01:40.000000000 +0100
22437 @@ -0,0 +1,436 @@
22438 +/*
22439 + *  linux/kernel/vserver/space.c
22440 + *
22441 + *  Virtual Server: Context Space Support
22442 + *
22443 + *  Copyright (C) 2003-2010  Herbert Pötzl
22444 + *
22445 + *  V0.01  broken out from context.c 0.07
22446 + *  V0.02  added task locking for namespace
22447 + *  V0.03  broken out vx_enter_namespace
22448 + *  V0.04  added *space support and commands
22449 + *  V0.05  added credential support
22450 + *
22451 + */
22452 +
22453 +#include <linux/utsname.h>
22454 +#include <linux/nsproxy.h>
22455 +#include <linux/err.h>
22456 +#include <linux/fs_struct.h>
22457 +#include <linux/cred.h>
22458 +#include <asm/uaccess.h>
22459 +
22460 +#include <linux/vs_context.h>
22461 +#include <linux/vserver/space.h>
22462 +#include <linux/vserver/space_cmd.h>
22463 +
22464 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22465 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22466 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22467 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22468 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22469 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22470 +
22471 +
22472 +/* namespace functions */
22473 +
22474 +#include <linux/mnt_namespace.h>
22475 +#include <linux/user_namespace.h>
22476 +#include <linux/pid_namespace.h>
22477 +#include <linux/ipc_namespace.h>
22478 +#include <net/net_namespace.h>
22479 +#include "../fs/mount.h"
22480 +
22481 +
22482 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22483 +       .mask = CLONE_FS |
22484 +               CLONE_NEWNS |
22485 +#ifdef CONFIG_UTS_NS
22486 +               CLONE_NEWUTS |
22487 +#endif
22488 +#ifdef CONFIG_IPC_NS
22489 +               CLONE_NEWIPC |
22490 +#endif
22491 +#ifdef CONFIG_USER_NS
22492 +               CLONE_NEWUSER |
22493 +#endif
22494 +               0
22495 +};
22496 +
22497 +static const struct vcmd_space_mask_v1 space_mask = {
22498 +       .mask = CLONE_FS |
22499 +               CLONE_NEWNS |
22500 +#ifdef CONFIG_UTS_NS
22501 +               CLONE_NEWUTS |
22502 +#endif
22503 +#ifdef CONFIG_IPC_NS
22504 +               CLONE_NEWIPC |
22505 +#endif
22506 +#ifdef CONFIG_USER_NS
22507 +               CLONE_NEWUSER |
22508 +#endif
22509 +#ifdef CONFIG_PID_NS
22510 +               CLONE_NEWPID |
22511 +#endif
22512 +#ifdef CONFIG_NET_NS
22513 +               CLONE_NEWNET |
22514 +#endif
22515 +               0
22516 +};
22517 +
22518 +static const struct vcmd_space_mask_v1 default_space_mask = {
22519 +       .mask = CLONE_FS |
22520 +               CLONE_NEWNS |
22521 +#ifdef CONFIG_UTS_NS
22522 +               CLONE_NEWUTS |
22523 +#endif
22524 +#ifdef CONFIG_IPC_NS
22525 +               CLONE_NEWIPC |
22526 +#endif
22527 +#ifdef CONFIG_USER_NS
22528 +               CLONE_NEWUSER |
22529 +#endif
22530 +#ifdef CONFIG_PID_NS
22531 +//             CLONE_NEWPID |
22532 +#endif
22533 +               0
22534 +};
22535 +
22536 +/*
22537 + *     build a new nsproxy mix
22538 + *      assumes that both proxies are 'const'
22539 + *     does not touch nsproxy refcounts
22540 + *     will hold a reference on the result.
22541 + */
22542 +
22543 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22544 +       struct nsproxy *new_nsproxy, unsigned long mask)
22545 +{
22546 +       struct mnt_namespace *old_ns;
22547 +       struct uts_namespace *old_uts;
22548 +       struct ipc_namespace *old_ipc;
22549 +#ifdef CONFIG_PID_NS
22550 +       struct pid_namespace *old_pid;
22551 +#endif
22552 +#ifdef CONFIG_NET_NS
22553 +       struct net *old_net;
22554 +#endif
22555 +       struct nsproxy *nsproxy;
22556 +
22557 +       nsproxy = copy_nsproxy(old_nsproxy);
22558 +       if (!nsproxy)
22559 +               goto out;
22560 +
22561 +       if (mask & CLONE_NEWNS) {
22562 +               old_ns = nsproxy->mnt_ns;
22563 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22564 +               if (nsproxy->mnt_ns)
22565 +                       get_mnt_ns(nsproxy->mnt_ns);
22566 +       } else
22567 +               old_ns = NULL;
22568 +
22569 +       if (mask & CLONE_NEWUTS) {
22570 +               old_uts = nsproxy->uts_ns;
22571 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22572 +               if (nsproxy->uts_ns)
22573 +                       get_uts_ns(nsproxy->uts_ns);
22574 +       } else
22575 +               old_uts = NULL;
22576 +
22577 +       if (mask & CLONE_NEWIPC) {
22578 +               old_ipc = nsproxy->ipc_ns;
22579 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22580 +               if (nsproxy->ipc_ns)
22581 +                       get_ipc_ns(nsproxy->ipc_ns);
22582 +       } else
22583 +               old_ipc = NULL;
22584 +
22585 +#ifdef CONFIG_PID_NS
22586 +       if (mask & CLONE_NEWPID) {
22587 +               old_pid = nsproxy->pid_ns;
22588 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22589 +               if (nsproxy->pid_ns)
22590 +                       get_pid_ns(nsproxy->pid_ns);
22591 +       } else
22592 +               old_pid = NULL;
22593 +#endif
22594 +#ifdef CONFIG_NET_NS
22595 +       if (mask & CLONE_NEWNET) {
22596 +               old_net = nsproxy->net_ns;
22597 +               nsproxy->net_ns = new_nsproxy->net_ns;
22598 +               if (nsproxy->net_ns)
22599 +                       get_net(nsproxy->net_ns);
22600 +       } else
22601 +               old_net = NULL;
22602 +#endif
22603 +       if (old_ns)
22604 +               put_mnt_ns(old_ns);
22605 +       if (old_uts)
22606 +               put_uts_ns(old_uts);
22607 +       if (old_ipc)
22608 +               put_ipc_ns(old_ipc);
22609 +#ifdef CONFIG_PID_NS
22610 +       if (old_pid)
22611 +               put_pid_ns(old_pid);
22612 +#endif
22613 +#ifdef CONFIG_NET_NS
22614 +       if (old_net)
22615 +               put_net(old_net);
22616 +#endif
22617 +out:
22618 +       return nsproxy;
22619 +}
22620 +
22621 +
22622 +/*
22623 + *     merge two nsproxy structs into a new one.
22624 + *     will hold a reference on the result.
22625 + */
22626 +
22627 +static inline
22628 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22629 +       struct nsproxy *proxy, unsigned long mask)
22630 +{
22631 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22632 +
22633 +       if (!proxy)
22634 +               return NULL;
22635 +
22636 +       if (mask) {
22637 +               /* vs_mix_nsproxy returns with reference */
22638 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22639 +                       proxy, mask);
22640 +       }
22641 +       get_nsproxy(proxy);
22642 +       return proxy;
22643 +}
22644 +
22645 +
22646 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22647 +{
22648 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22649 +       struct fs_struct *fs_cur, *fs = NULL;
22650 +       struct _vx_space *space;
22651 +       int ret, kill = 0;
22652 +
22653 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22654 +               vxi, vxi->vx_id, mask, index);
22655 +
22656 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22657 +               return -EACCES;
22658 +
22659 +       if (index >= VX_SPACES)
22660 +               return -EINVAL;
22661 +
22662 +       space = &vxi->space[index];
22663 +
22664 +       if (!mask)
22665 +               mask = space->vx_nsmask;
22666 +
22667 +       if ((mask & space->vx_nsmask) != mask)
22668 +               return -EINVAL;
22669 +
22670 +       if (mask & CLONE_FS) {
22671 +               fs = copy_fs_struct(space->vx_fs);
22672 +               if (!fs)
22673 +                       return -ENOMEM;
22674 +       }
22675 +       proxy = space->vx_nsproxy;
22676 +
22677 +       vxdprintk(VXD_CBIT(space, 9),
22678 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22679 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22680 +
22681 +       task_lock(current);
22682 +       fs_cur = current->fs;
22683 +
22684 +       if (mask & CLONE_FS) {
22685 +               spin_lock(&fs_cur->lock);
22686 +               current->fs = fs;
22687 +               kill = !--fs_cur->users;
22688 +               spin_unlock(&fs_cur->lock);
22689 +       }
22690 +
22691 +       proxy_cur = current->nsproxy;
22692 +       get_nsproxy(proxy_cur);
22693 +       task_unlock(current);
22694 +
22695 +       if (kill)
22696 +               free_fs_struct(fs_cur);
22697 +
22698 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22699 +       if (IS_ERR(proxy_new)) {
22700 +               ret = PTR_ERR(proxy_new);
22701 +               goto out_put;
22702 +       }
22703 +
22704 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22705 +
22706 +       if (mask & CLONE_NEWUSER) {
22707 +               struct cred *cred;
22708 +
22709 +               vxdprintk(VXD_CBIT(space, 10),
22710 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22711 +                       vxi, vxi->vx_id, space->vx_cred,
22712 +                       current->real_cred, current->cred);
22713 +
22714 +               if (space->vx_cred) {
22715 +                       cred = __prepare_creds(space->vx_cred);
22716 +                       if (cred)
22717 +                               commit_creds(cred);
22718 +               }
22719 +       }
22720 +
22721 +       ret = 0;
22722 +
22723 +       if (proxy_new)
22724 +               put_nsproxy(proxy_new);
22725 +out_put:
22726 +       if (proxy_cur)
22727 +               put_nsproxy(proxy_cur);
22728 +       return ret;
22729 +}
22730 +
22731 +
22732 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22733 +{
22734 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22735 +       struct fs_struct *fs_vxi, *fs;
22736 +       struct _vx_space *space;
22737 +       int ret, kill = 0;
22738 +
22739 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22740 +               vxi, vxi->vx_id, mask, index);
22741 +
22742 +       if ((mask & space_mask.mask) != mask)
22743 +               return -EINVAL;
22744 +
22745 +       if (index >= VX_SPACES)
22746 +               return -EINVAL;
22747 +
22748 +       space = &vxi->space[index];
22749 +
22750 +       proxy_vxi = space->vx_nsproxy;
22751 +       fs_vxi = space->vx_fs;
22752 +
22753 +       if (mask & CLONE_FS) {
22754 +               fs = copy_fs_struct(current->fs);
22755 +               if (!fs)
22756 +                       return -ENOMEM;
22757 +       }
22758 +
22759 +       task_lock(current);
22760 +
22761 +       if (mask & CLONE_FS) {
22762 +               spin_lock(&fs_vxi->lock);
22763 +               space->vx_fs = fs;
22764 +               kill = !--fs_vxi->users;
22765 +               spin_unlock(&fs_vxi->lock);
22766 +       }
22767 +
22768 +       proxy_cur = current->nsproxy;
22769 +       get_nsproxy(proxy_cur);
22770 +       task_unlock(current);
22771 +
22772 +       if (kill)
22773 +               free_fs_struct(fs_vxi);
22774 +
22775 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22776 +       if (IS_ERR(proxy_new)) {
22777 +               ret = PTR_ERR(proxy_new);
22778 +               goto out_put;
22779 +       }
22780 +
22781 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22782 +       space->vx_nsmask |= mask;
22783 +
22784 +       if (mask & CLONE_NEWUSER) {
22785 +               struct cred *cred;
22786 +
22787 +               vxdprintk(VXD_CBIT(space, 10),
22788 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22789 +                       vxi, vxi->vx_id, space->vx_cred,
22790 +                       current->real_cred, current->cred);
22791 +
22792 +               cred = prepare_creds();
22793 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22794 +               if (cred)
22795 +                       abort_creds(cred);
22796 +       }
22797 +
22798 +       ret = 0;
22799 +
22800 +       if (proxy_new)
22801 +               put_nsproxy(proxy_new);
22802 +out_put:
22803 +       if (proxy_cur)
22804 +               put_nsproxy(proxy_cur);
22805 +       return ret;
22806 +}
22807 +
22808 +
22809 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22810 +{
22811 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22812 +
22813 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22814 +               return -EFAULT;
22815 +
22816 +       return vx_enter_space(vxi, vc_data.mask, 0);
22817 +}
22818 +
22819 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22820 +{
22821 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22822 +
22823 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22824 +               return -EFAULT;
22825 +
22826 +       if (vc_data.index >= VX_SPACES)
22827 +               return -EINVAL;
22828 +
22829 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22830 +}
22831 +
22832 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22833 +{
22834 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22835 +
22836 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22837 +               return -EFAULT;
22838 +
22839 +       return vx_set_space(vxi, vc_data.mask, 0);
22840 +}
22841 +
22842 +int vc_set_space(struct vx_info *vxi, void __user *data)
22843 +{
22844 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22845 +
22846 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22847 +               return -EFAULT;
22848 +
22849 +       if (vc_data.index >= VX_SPACES)
22850 +               return -EINVAL;
22851 +
22852 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22853 +}
22854 +
22855 +int vc_get_space_mask(void __user *data, int type)
22856 +{
22857 +       const struct vcmd_space_mask_v1 *mask;
22858 +
22859 +       if (type == 0)
22860 +               mask = &space_mask_v0;
22861 +       else if (type == 1)
22862 +               mask = &space_mask;
22863 +       else
22864 +               mask = &default_space_mask;
22865 +
22866 +       vxdprintk(VXD_CBIT(space, 10),
22867 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22868 +
22869 +       if (copy_to_user(data, mask, sizeof(*mask)))
22870 +               return -EFAULT;
22871 +       return 0;
22872 +}
22873 +
22874 diff -NurpP --minimal linux-3.3.1/kernel/vserver/switch.c linux-3.3.1-vs2.3.3.2/kernel/vserver/switch.c
22875 --- linux-3.3.1/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22876 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/switch.c       2012-02-24 03:55:07.000000000 +0100
22877 @@ -0,0 +1,556 @@
22878 +/*
22879 + *  linux/kernel/vserver/switch.c
22880 + *
22881 + *  Virtual Server: Syscall Switch
22882 + *
22883 + *  Copyright (C) 2003-2011  Herbert Pötzl
22884 + *
22885 + *  V0.01  syscall switch
22886 + *  V0.02  added signal to context
22887 + *  V0.03  added rlimit functions
22888 + *  V0.04  added iattr, task/xid functions
22889 + *  V0.05  added debug/history stuff
22890 + *  V0.06  added compat32 layer
22891 + *  V0.07  vcmd args and perms
22892 + *  V0.08  added status commands
22893 + *  V0.09  added tag commands
22894 + *  V0.10  added oom bias
22895 + *  V0.11  added device commands
22896 + *  V0.12  added warn mask
22897 + *
22898 + */
22899 +
22900 +#include <linux/vs_context.h>
22901 +#include <linux/vs_network.h>
22902 +#include <linux/vserver/switch.h>
22903 +
22904 +#include "vci_config.h"
22905 +
22906 +
22907 +static inline
22908 +int vc_get_version(uint32_t id)
22909 +{
22910 +       return VCI_VERSION;
22911 +}
22912 +
22913 +static inline
22914 +int vc_get_vci(uint32_t id)
22915 +{
22916 +       return vci_kernel_config();
22917 +}
22918 +
22919 +#include <linux/vserver/context_cmd.h>
22920 +#include <linux/vserver/cvirt_cmd.h>
22921 +#include <linux/vserver/cacct_cmd.h>
22922 +#include <linux/vserver/limit_cmd.h>
22923 +#include <linux/vserver/network_cmd.h>
22924 +#include <linux/vserver/sched_cmd.h>
22925 +#include <linux/vserver/debug_cmd.h>
22926 +#include <linux/vserver/inode_cmd.h>
22927 +#include <linux/vserver/dlimit_cmd.h>
22928 +#include <linux/vserver/signal_cmd.h>
22929 +#include <linux/vserver/space_cmd.h>
22930 +#include <linux/vserver/tag_cmd.h>
22931 +#include <linux/vserver/device_cmd.h>
22932 +
22933 +#include <linux/vserver/inode.h>
22934 +#include <linux/vserver/dlimit.h>
22935 +
22936 +
22937 +#ifdef CONFIG_COMPAT
22938 +#define __COMPAT(name, id, data, compat)       \
22939 +       (compat) ? name ## _x32(id, data) : name(id, data)
22940 +#define __COMPAT_NO_ID(name, data, compat)     \
22941 +       (compat) ? name ## _x32(data) : name(data)
22942 +#else
22943 +#define __COMPAT(name, id, data, compat)       \
22944 +       name(id, data)
22945 +#define __COMPAT_NO_ID(name, data, compat)     \
22946 +       name(data)
22947 +#endif
22948 +
22949 +
22950 +static inline
22951 +long do_vcmd(uint32_t cmd, uint32_t id,
22952 +       struct vx_info *vxi, struct nx_info *nxi,
22953 +       void __user *data, int compat)
22954 +{
22955 +       switch (cmd) {
22956 +
22957 +       case VCMD_get_version:
22958 +               return vc_get_version(id);
22959 +       case VCMD_get_vci:
22960 +               return vc_get_vci(id);
22961 +
22962 +       case VCMD_task_xid:
22963 +               return vc_task_xid(id);
22964 +       case VCMD_vx_info:
22965 +               return vc_vx_info(vxi, data);
22966 +
22967 +       case VCMD_task_nid:
22968 +               return vc_task_nid(id);
22969 +       case VCMD_nx_info:
22970 +               return vc_nx_info(nxi, data);
22971 +
22972 +       case VCMD_task_tag:
22973 +               return vc_task_tag(id);
22974 +
22975 +       case VCMD_set_space_v1:
22976 +               return vc_set_space_v1(vxi, data);
22977 +       /* this is version 2 */
22978 +       case VCMD_set_space:
22979 +               return vc_set_space(vxi, data);
22980 +
22981 +       case VCMD_get_space_mask_v0:
22982 +               return vc_get_space_mask(data, 0);
22983 +       /* this is version 1 */
22984 +       case VCMD_get_space_mask:
22985 +               return vc_get_space_mask(data, 1);
22986 +
22987 +       case VCMD_get_space_default:
22988 +               return vc_get_space_mask(data, -1);
22989 +
22990 +       case VCMD_set_umask:
22991 +               return vc_set_umask(vxi, data);
22992 +
22993 +       case VCMD_get_umask:
22994 +               return vc_get_umask(vxi, data);
22995 +
22996 +       case VCMD_set_wmask:
22997 +               return vc_set_wmask(vxi, data);
22998 +
22999 +       case VCMD_get_wmask:
23000 +               return vc_get_wmask(vxi, data);
23001 +#ifdef CONFIG_IA32_EMULATION
23002 +       case VCMD_get_rlimit:
23003 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23004 +       case VCMD_set_rlimit:
23005 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23006 +#else
23007 +       case VCMD_get_rlimit:
23008 +               return vc_get_rlimit(vxi, data);
23009 +       case VCMD_set_rlimit:
23010 +               return vc_set_rlimit(vxi, data);
23011 +#endif
23012 +       case VCMD_get_rlimit_mask:
23013 +               return vc_get_rlimit_mask(id, data);
23014 +       case VCMD_reset_hits:
23015 +               return vc_reset_hits(vxi, data);
23016 +       case VCMD_reset_minmax:
23017 +               return vc_reset_minmax(vxi, data);
23018 +
23019 +       case VCMD_get_vhi_name:
23020 +               return vc_get_vhi_name(vxi, data);
23021 +       case VCMD_set_vhi_name:
23022 +               return vc_set_vhi_name(vxi, data);
23023 +
23024 +       case VCMD_ctx_stat:
23025 +               return vc_ctx_stat(vxi, data);
23026 +       case VCMD_virt_stat:
23027 +               return vc_virt_stat(vxi, data);
23028 +       case VCMD_sock_stat:
23029 +               return vc_sock_stat(vxi, data);
23030 +       case VCMD_rlimit_stat:
23031 +               return vc_rlimit_stat(vxi, data);
23032 +
23033 +       case VCMD_set_cflags:
23034 +               return vc_set_cflags(vxi, data);
23035 +       case VCMD_get_cflags:
23036 +               return vc_get_cflags(vxi, data);
23037 +
23038 +       /* this is version 1 */
23039 +       case VCMD_set_ccaps:
23040 +               return vc_set_ccaps(vxi, data);
23041 +       /* this is version 1 */
23042 +       case VCMD_get_ccaps:
23043 +               return vc_get_ccaps(vxi, data);
23044 +       case VCMD_set_bcaps:
23045 +               return vc_set_bcaps(vxi, data);
23046 +       case VCMD_get_bcaps:
23047 +               return vc_get_bcaps(vxi, data);
23048 +
23049 +       case VCMD_set_badness:
23050 +               return vc_set_badness(vxi, data);
23051 +       case VCMD_get_badness:
23052 +               return vc_get_badness(vxi, data);
23053 +
23054 +       case VCMD_set_nflags:
23055 +               return vc_set_nflags(nxi, data);
23056 +       case VCMD_get_nflags:
23057 +               return vc_get_nflags(nxi, data);
23058 +
23059 +       case VCMD_set_ncaps:
23060 +               return vc_set_ncaps(nxi, data);
23061 +       case VCMD_get_ncaps:
23062 +               return vc_get_ncaps(nxi, data);
23063 +
23064 +       case VCMD_set_prio_bias:
23065 +               return vc_set_prio_bias(vxi, data);
23066 +       case VCMD_get_prio_bias:
23067 +               return vc_get_prio_bias(vxi, data);
23068 +       case VCMD_add_dlimit:
23069 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23070 +       case VCMD_rem_dlimit:
23071 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23072 +       case VCMD_set_dlimit:
23073 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23074 +       case VCMD_get_dlimit:
23075 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23076 +
23077 +       case VCMD_ctx_kill:
23078 +               return vc_ctx_kill(vxi, data);
23079 +
23080 +       case VCMD_wait_exit:
23081 +               return vc_wait_exit(vxi, data);
23082 +
23083 +       case VCMD_get_iattr:
23084 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23085 +       case VCMD_set_iattr:
23086 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23087 +
23088 +       case VCMD_fget_iattr:
23089 +               return vc_fget_iattr(id, data);
23090 +       case VCMD_fset_iattr:
23091 +               return vc_fset_iattr(id, data);
23092 +
23093 +       case VCMD_enter_space_v0:
23094 +               return vc_enter_space_v1(vxi, NULL);
23095 +       case VCMD_enter_space_v1:
23096 +               return vc_enter_space_v1(vxi, data);
23097 +       /* this is version 2 */
23098 +       case VCMD_enter_space:
23099 +               return vc_enter_space(vxi, data);
23100 +
23101 +       case VCMD_ctx_create_v0:
23102 +               return vc_ctx_create(id, NULL);
23103 +       case VCMD_ctx_create:
23104 +               return vc_ctx_create(id, data);
23105 +       case VCMD_ctx_migrate_v0:
23106 +               return vc_ctx_migrate(vxi, NULL);
23107 +       case VCMD_ctx_migrate:
23108 +               return vc_ctx_migrate(vxi, data);
23109 +
23110 +       case VCMD_net_create_v0:
23111 +               return vc_net_create(id, NULL);
23112 +       case VCMD_net_create:
23113 +               return vc_net_create(id, data);
23114 +       case VCMD_net_migrate:
23115 +               return vc_net_migrate(nxi, data);
23116 +
23117 +       case VCMD_tag_migrate:
23118 +               return vc_tag_migrate(id);
23119 +
23120 +       case VCMD_net_add:
23121 +               return vc_net_add(nxi, data);
23122 +       case VCMD_net_remove:
23123 +               return vc_net_remove(nxi, data);
23124 +
23125 +       case VCMD_net_add_ipv4_v1:
23126 +               return vc_net_add_ipv4_v1(nxi, data);
23127 +       /* this is version 2 */
23128 +       case VCMD_net_add_ipv4:
23129 +               return vc_net_add_ipv4(nxi, data);
23130 +
23131 +       case VCMD_net_rem_ipv4_v1:
23132 +               return vc_net_rem_ipv4_v1(nxi, data);
23133 +       /* this is version 2 */
23134 +       case VCMD_net_rem_ipv4:
23135 +               return vc_net_rem_ipv4(nxi, data);
23136 +#ifdef CONFIG_IPV6
23137 +       case VCMD_net_add_ipv6:
23138 +               return vc_net_add_ipv6(nxi, data);
23139 +       case VCMD_net_remove_ipv6:
23140 +               return vc_net_remove_ipv6(nxi, data);
23141 +#endif
23142 +/*     case VCMD_add_match_ipv4:
23143 +               return vc_add_match_ipv4(nxi, data);
23144 +       case VCMD_get_match_ipv4:
23145 +               return vc_get_match_ipv4(nxi, data);
23146 +#ifdef CONFIG_IPV6
23147 +       case VCMD_add_match_ipv6:
23148 +               return vc_add_match_ipv6(nxi, data);
23149 +       case VCMD_get_match_ipv6:
23150 +               return vc_get_match_ipv6(nxi, data);
23151 +#endif */
23152 +
23153 +#ifdef CONFIG_VSERVER_DEVICE
23154 +       case VCMD_set_mapping:
23155 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23156 +       case VCMD_unset_mapping:
23157 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23158 +#endif
23159 +#ifdef CONFIG_VSERVER_HISTORY
23160 +       case VCMD_dump_history:
23161 +               return vc_dump_history(id);
23162 +       case VCMD_read_history:
23163 +               return __COMPAT(vc_read_history, id, data, compat);
23164 +#endif
23165 +       default:
23166 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23167 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23168 +       }
23169 +       return -ENOSYS;
23170 +}
23171 +
23172 +
23173 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23174 +       case VCMD_ ## vcmd: perm = _perm;               \
23175 +               args = _args; flags = _flags; break
23176 +
23177 +
23178 +#define VCA_NONE       0x00
23179 +#define VCA_VXI                0x01
23180 +#define VCA_NXI                0x02
23181 +
23182 +#define VCF_NONE       0x00
23183 +#define VCF_INFO       0x01
23184 +#define VCF_ADMIN      0x02
23185 +#define VCF_ARES       0x06    /* includes admin */
23186 +#define VCF_SETUP      0x08
23187 +
23188 +#define VCF_ZIDOK      0x10    /* zero id okay */
23189 +
23190 +
23191 +static inline
23192 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23193 +{
23194 +       long ret;
23195 +       int permit = -1, state = 0;
23196 +       int perm = -1, args = 0, flags = 0;
23197 +       struct vx_info *vxi = NULL;
23198 +       struct nx_info *nxi = NULL;
23199 +
23200 +       switch (cmd) {
23201 +       /* unpriviledged commands */
23202 +       __VCMD(get_version,      0, VCA_NONE,   0);
23203 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23204 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23205 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23206 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23207 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23208 +
23209 +       /* info commands */
23210 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23211 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23212 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23213 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23214 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23215 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23216 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23217 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23218 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23219 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23220 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23221 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23222 +
23223 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23224 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23225 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23226 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23227 +
23228 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23229 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23230 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23231 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23232 +
23233 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23234 +
23235 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23236 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23237 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23238 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23239 +
23240 +       /* lower admin commands */
23241 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23242 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23243 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23244 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23245 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23246 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23247 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23248 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23249 +
23250 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23251 +       __VCMD(net_create,       5, VCA_NONE,   0);
23252 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23253 +
23254 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23255 +
23256 +       /* higher admin commands */
23257 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23258 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23259 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23260 +
23261 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23262 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23263 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23264 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23265 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23266 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23267 +
23268 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23269 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23270 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23271 +
23272 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23273 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23274 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23275 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23276 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23277 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23278 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23279 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23280 +#ifdef CONFIG_IPV6
23281 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23282 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23283 +#endif
23284 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23285 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23286 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23287 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23288 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23289 +
23290 +#ifdef CONFIG_VSERVER_DEVICE
23291 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23292 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23293 +#endif
23294 +       /* debug level admin commands */
23295 +#ifdef CONFIG_VSERVER_HISTORY
23296 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23297 +       __VCMD(read_history,     9, VCA_NONE,   0);
23298 +#endif
23299 +
23300 +       default:
23301 +               perm = -1;
23302 +       }
23303 +
23304 +       vxdprintk(VXD_CBIT(switch, 0),
23305 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23306 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23307 +               VC_VERSION(cmd), id, data, compat,
23308 +               perm, args, flags);
23309 +
23310 +       ret = -ENOSYS;
23311 +       if (perm < 0)
23312 +               goto out;
23313 +
23314 +       state = 1;
23315 +       if (!capable(CAP_CONTEXT))
23316 +               goto out;
23317 +
23318 +       state = 2;
23319 +       /* moved here from the individual commands */
23320 +       ret = -EPERM;
23321 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23322 +               goto out;
23323 +
23324 +       state = 3;
23325 +       /* vcmd involves resource management  */
23326 +       ret = -EPERM;
23327 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23328 +               goto out;
23329 +
23330 +       state = 4;
23331 +       /* various legacy exceptions */
23332 +       switch (cmd) {
23333 +       /* will go away when spectator is a cap */
23334 +       case VCMD_ctx_migrate_v0:
23335 +       case VCMD_ctx_migrate:
23336 +               if (id == 1) {
23337 +                       current->xid = 1;
23338 +                       ret = 1;
23339 +                       goto out;
23340 +               }
23341 +               break;
23342 +
23343 +       /* will go away when spectator is a cap */
23344 +       case VCMD_net_migrate:
23345 +               if (id == 1) {
23346 +                       current->nid = 1;
23347 +                       ret = 1;
23348 +                       goto out;
23349 +               }
23350 +               break;
23351 +       }
23352 +
23353 +       /* vcmds are fine by default */
23354 +       permit = 1;
23355 +
23356 +       /* admin type vcmds require admin ... */
23357 +       if (flags & VCF_ADMIN)
23358 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23359 +
23360 +       /* ... but setup type vcmds override that */
23361 +       if (!permit && (flags & VCF_SETUP))
23362 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23363 +
23364 +       state = 5;
23365 +       ret = -EPERM;
23366 +       if (!permit)
23367 +               goto out;
23368 +
23369 +       state = 6;
23370 +       if (!id && (flags & VCF_ZIDOK))
23371 +               goto skip_id;
23372 +
23373 +       ret = -ESRCH;
23374 +       if (args & VCA_VXI) {
23375 +               vxi = lookup_vx_info(id);
23376 +               if (!vxi)
23377 +                       goto out;
23378 +
23379 +               if ((flags & VCF_ADMIN) &&
23380 +                       /* special case kill for shutdown */
23381 +                       (cmd != VCMD_ctx_kill) &&
23382 +                       /* can context be administrated? */
23383 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23384 +                       ret = -EACCES;
23385 +                       goto out_vxi;
23386 +               }
23387 +       }
23388 +       state = 7;
23389 +       if (args & VCA_NXI) {
23390 +               nxi = lookup_nx_info(id);
23391 +               if (!nxi)
23392 +                       goto out_vxi;
23393 +
23394 +               if ((flags & VCF_ADMIN) &&
23395 +                       /* can context be administrated? */
23396 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23397 +                       ret = -EACCES;
23398 +                       goto out_nxi;
23399 +               }
23400 +       }
23401 +skip_id:
23402 +       state = 8;
23403 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23404 +
23405 +out_nxi:
23406 +       if ((args & VCA_NXI) && nxi)
23407 +               put_nx_info(nxi);
23408 +out_vxi:
23409 +       if ((args & VCA_VXI) && vxi)
23410 +               put_vx_info(vxi);
23411 +out:
23412 +       vxdprintk(VXD_CBIT(switch, 1),
23413 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23414 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23415 +               VC_VERSION(cmd), ret, ret, state, permit);
23416 +       return ret;
23417 +}
23418 +
23419 +asmlinkage long
23420 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23421 +{
23422 +       return do_vserver(cmd, id, data, 0);
23423 +}
23424 +
23425 +#ifdef CONFIG_COMPAT
23426 +
23427 +asmlinkage long
23428 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23429 +{
23430 +       return do_vserver(cmd, id, data, 1);
23431 +}
23432 +
23433 +#endif /* CONFIG_COMPAT */
23434 diff -NurpP --minimal linux-3.3.1/kernel/vserver/sysctl.c linux-3.3.1-vs2.3.3.2/kernel/vserver/sysctl.c
23435 --- linux-3.3.1/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23436 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/sysctl.c       2012-02-24 03:55:07.000000000 +0100
23437 @@ -0,0 +1,247 @@
23438 +/*
23439 + *  kernel/vserver/sysctl.c
23440 + *
23441 + *  Virtual Context Support
23442 + *
23443 + *  Copyright (C) 2004-2007  Herbert Pötzl
23444 + *
23445 + *  V0.01  basic structure
23446 + *
23447 + */
23448 +
23449 +#include <linux/module.h>
23450 +#include <linux/ctype.h>
23451 +#include <linux/sysctl.h>
23452 +#include <linux/parser.h>
23453 +#include <asm/uaccess.h>
23454 +
23455 +enum {
23456 +       CTL_DEBUG_ERROR         = 0,
23457 +       CTL_DEBUG_SWITCH        = 1,
23458 +       CTL_DEBUG_XID,
23459 +       CTL_DEBUG_NID,
23460 +       CTL_DEBUG_TAG,
23461 +       CTL_DEBUG_NET,
23462 +       CTL_DEBUG_LIMIT,
23463 +       CTL_DEBUG_CRES,
23464 +       CTL_DEBUG_DLIM,
23465 +       CTL_DEBUG_QUOTA,
23466 +       CTL_DEBUG_CVIRT,
23467 +       CTL_DEBUG_SPACE,
23468 +       CTL_DEBUG_PERM,
23469 +       CTL_DEBUG_MISC,
23470 +};
23471 +
23472 +
23473 +unsigned int vs_debug_switch   = 0;
23474 +unsigned int vs_debug_xid      = 0;
23475 +unsigned int vs_debug_nid      = 0;
23476 +unsigned int vs_debug_tag      = 0;
23477 +unsigned int vs_debug_net      = 0;
23478 +unsigned int vs_debug_limit    = 0;
23479 +unsigned int vs_debug_cres     = 0;
23480 +unsigned int vs_debug_dlim     = 0;
23481 +unsigned int vs_debug_quota    = 0;
23482 +unsigned int vs_debug_cvirt    = 0;
23483 +unsigned int vs_debug_space    = 0;
23484 +unsigned int vs_debug_perm     = 0;
23485 +unsigned int vs_debug_misc     = 0;
23486 +
23487 +
23488 +static struct ctl_table_header *vserver_table_header;
23489 +static ctl_table vserver_root_table[];
23490 +
23491 +
23492 +void vserver_register_sysctl(void)
23493 +{
23494 +       if (!vserver_table_header) {
23495 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23496 +       }
23497 +
23498 +}
23499 +
23500 +void vserver_unregister_sysctl(void)
23501 +{
23502 +       if (vserver_table_header) {
23503 +               unregister_sysctl_table(vserver_table_header);
23504 +               vserver_table_header = NULL;
23505 +       }
23506 +}
23507 +
23508 +
23509 +static int proc_dodebug(ctl_table *table, int write,
23510 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23511 +{
23512 +       char            tmpbuf[20], *p, c;
23513 +       unsigned int    value;
23514 +       size_t          left, len;
23515 +
23516 +       if ((*ppos && !write) || !*lenp) {
23517 +               *lenp = 0;
23518 +               return 0;
23519 +       }
23520 +
23521 +       left = *lenp;
23522 +
23523 +       if (write) {
23524 +               if (!access_ok(VERIFY_READ, buffer, left))
23525 +                       return -EFAULT;
23526 +               p = (char *)buffer;
23527 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23528 +                       left--, p++;
23529 +               if (!left)
23530 +                       goto done;
23531 +
23532 +               if (left > sizeof(tmpbuf) - 1)
23533 +                       return -EINVAL;
23534 +               if (copy_from_user(tmpbuf, p, left))
23535 +                       return -EFAULT;
23536 +               tmpbuf[left] = '\0';
23537 +
23538 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23539 +                       value = 10 * value + (*p - '0');
23540 +               if (*p && !isspace(*p))
23541 +                       return -EINVAL;
23542 +               while (left && isspace(*p))
23543 +                       left--, p++;
23544 +               *(unsigned int *)table->data = value;
23545 +       } else {
23546 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23547 +                       return -EFAULT;
23548 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23549 +               if (len > left)
23550 +                       len = left;
23551 +               if (__copy_to_user(buffer, tmpbuf, len))
23552 +                       return -EFAULT;
23553 +               if ((left -= len) > 0) {
23554 +                       if (put_user('\n', (char *)buffer + len))
23555 +                               return -EFAULT;
23556 +                       left--;
23557 +               }
23558 +       }
23559 +
23560 +done:
23561 +       *lenp -= left;
23562 +       *ppos += *lenp;
23563 +       return 0;
23564 +}
23565 +
23566 +static int zero;
23567 +
23568 +#define        CTL_ENTRY(ctl, name)                            \
23569 +       {                                               \
23570 +               .procname       = #name,                \
23571 +               .data           = &vs_ ## name,         \
23572 +               .maxlen         = sizeof(int),          \
23573 +               .mode           = 0644,                 \
23574 +               .proc_handler   = &proc_dodebug,        \
23575 +               .extra1         = &zero,                \
23576 +               .extra2         = &zero,                \
23577 +       }
23578 +
23579 +static ctl_table vserver_debug_table[] = {
23580 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23581 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23582 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23583 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23584 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23585 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23586 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23587 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23588 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23589 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23590 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23591 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23592 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23593 +       { 0 }
23594 +};
23595 +
23596 +static ctl_table vserver_root_table[] = {
23597 +       {
23598 +               .procname       = "vserver",
23599 +               .mode           = 0555,
23600 +               .child          = vserver_debug_table
23601 +       },
23602 +       { 0 }
23603 +};
23604 +
23605 +
23606 +static match_table_t tokens = {
23607 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23608 +       { CTL_DEBUG_XID,        "xid=%x"        },
23609 +       { CTL_DEBUG_NID,        "nid=%x"        },
23610 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23611 +       { CTL_DEBUG_NET,        "net=%x"        },
23612 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23613 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23614 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23615 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23616 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23617 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23618 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23619 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23620 +       { CTL_DEBUG_ERROR,      NULL            }
23621 +};
23622 +
23623 +#define        HANDLE_CASE(id, name, val)                              \
23624 +       case CTL_DEBUG_ ## id:                                  \
23625 +               vs_debug_ ## name = val;                        \
23626 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23627 +               break
23628 +
23629 +
23630 +static int __init vs_debug_setup(char *str)
23631 +{
23632 +       char *p;
23633 +       int token;
23634 +
23635 +       printk("vs_debug_setup(%s)\n", str);
23636 +       while ((p = strsep(&str, ",")) != NULL) {
23637 +               substring_t args[MAX_OPT_ARGS];
23638 +               unsigned int value;
23639 +
23640 +               if (!*p)
23641 +                       continue;
23642 +
23643 +               token = match_token(p, tokens, args);
23644 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23645 +
23646 +               switch (token) {
23647 +               HANDLE_CASE(SWITCH, switch, value);
23648 +               HANDLE_CASE(XID,    xid,    value);
23649 +               HANDLE_CASE(NID,    nid,    value);
23650 +               HANDLE_CASE(TAG,    tag,    value);
23651 +               HANDLE_CASE(NET,    net,    value);
23652 +               HANDLE_CASE(LIMIT,  limit,  value);
23653 +               HANDLE_CASE(CRES,   cres,   value);
23654 +               HANDLE_CASE(DLIM,   dlim,   value);
23655 +               HANDLE_CASE(QUOTA,  quota,  value);
23656 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23657 +               HANDLE_CASE(SPACE,  space,  value);
23658 +               HANDLE_CASE(PERM,   perm,   value);
23659 +               HANDLE_CASE(MISC,   misc,   value);
23660 +               default:
23661 +                       return -EINVAL;
23662 +                       break;
23663 +               }
23664 +       }
23665 +       return 1;
23666 +}
23667 +
23668 +__setup("vsdebug=", vs_debug_setup);
23669 +
23670 +
23671 +
23672 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23673 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23674 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23675 +EXPORT_SYMBOL_GPL(vs_debug_net);
23676 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23677 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23678 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23679 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23680 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23681 +EXPORT_SYMBOL_GPL(vs_debug_space);
23682 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23683 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23684 +
23685 diff -NurpP --minimal linux-3.3.1/kernel/vserver/tag.c linux-3.3.1-vs2.3.3.2/kernel/vserver/tag.c
23686 --- linux-3.3.1/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23687 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/tag.c  2012-02-24 03:55:07.000000000 +0100
23688 @@ -0,0 +1,63 @@
23689 +/*
23690 + *  linux/kernel/vserver/tag.c
23691 + *
23692 + *  Virtual Server: Shallow Tag Space
23693 + *
23694 + *  Copyright (C) 2007  Herbert Pötzl
23695 + *
23696 + *  V0.01  basic implementation
23697 + *
23698 + */
23699 +
23700 +#include <linux/sched.h>
23701 +#include <linux/vserver/debug.h>
23702 +#include <linux/vs_pid.h>
23703 +#include <linux/vs_tag.h>
23704 +
23705 +#include <linux/vserver/tag_cmd.h>
23706 +
23707 +
23708 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23709 +{
23710 +       if (!p)
23711 +               BUG();
23712 +
23713 +       vxdprintk(VXD_CBIT(tag, 5),
23714 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23715 +
23716 +       task_lock(p);
23717 +       p->tag = tag;
23718 +       task_unlock(p);
23719 +
23720 +       vxdprintk(VXD_CBIT(tag, 5),
23721 +               "moved task %p into [#%d]", p, tag);
23722 +       return 0;
23723 +}
23724 +
23725 +/* vserver syscall commands below here */
23726 +
23727 +/* taks xid and vx_info functions */
23728 +
23729 +
23730 +int vc_task_tag(uint32_t id)
23731 +{
23732 +       tag_t tag;
23733 +
23734 +       if (id) {
23735 +               struct task_struct *tsk;
23736 +               rcu_read_lock();
23737 +               tsk = find_task_by_real_pid(id);
23738 +               tag = (tsk) ? tsk->tag : -ESRCH;
23739 +               rcu_read_unlock();
23740 +       } else
23741 +               tag = dx_current_tag();
23742 +       return tag;
23743 +}
23744 +
23745 +
23746 +int vc_tag_migrate(uint32_t tag)
23747 +{
23748 +       return dx_migrate_task(current, tag & 0xFFFF);
23749 +}
23750 +
23751 +
23752 diff -NurpP --minimal linux-3.3.1/kernel/vserver/vci_config.h linux-3.3.1-vs2.3.3.2/kernel/vserver/vci_config.h
23753 --- linux-3.3.1/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
23754 +++ linux-3.3.1-vs2.3.3.2/kernel/vserver/vci_config.h   2012-02-24 03:55:07.000000000 +0100
23755 @@ -0,0 +1,76 @@
23756 +
23757 +/*  interface version */
23758 +
23759 +#define VCI_VERSION            0x00020308
23760 +
23761 +
23762 +enum {
23763 +       VCI_KCBIT_NO_DYNAMIC = 0,
23764 +
23765 +       VCI_KCBIT_PROC_SECURE = 4,
23766 +       /* VCI_KCBIT_HARDCPU = 5, */
23767 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23768 +       /* VCI_KCBIT_IDLETIME = 7, */
23769 +
23770 +       VCI_KCBIT_COWBL = 8,
23771 +       VCI_KCBIT_FULLCOWBL = 9,
23772 +       VCI_KCBIT_SPACES = 10,
23773 +       VCI_KCBIT_NETV2 = 11,
23774 +       VCI_KCBIT_MEMCG = 12,
23775 +
23776 +       VCI_KCBIT_DEBUG = 16,
23777 +       VCI_KCBIT_HISTORY = 20,
23778 +       VCI_KCBIT_TAGGED = 24,
23779 +       VCI_KCBIT_PPTAG = 28,
23780 +
23781 +       VCI_KCBIT_MORE = 31,
23782 +};
23783 +
23784 +
23785 +static inline uint32_t vci_kernel_config(void)
23786 +{
23787 +       return
23788 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23789 +
23790 +       /* configured features */
23791 +#ifdef CONFIG_VSERVER_PROC_SECURE
23792 +       (1 << VCI_KCBIT_PROC_SECURE) |
23793 +#endif
23794 +#ifdef CONFIG_VSERVER_COWBL
23795 +       (1 << VCI_KCBIT_COWBL) |
23796 +       (1 << VCI_KCBIT_FULLCOWBL) |
23797 +#endif
23798 +       (1 << VCI_KCBIT_SPACES) |
23799 +       (1 << VCI_KCBIT_NETV2) |
23800 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23801 +       (1 << VCI_KCBIT_MEMCG) |
23802 +#endif
23803 +
23804 +       /* debug options */
23805 +#ifdef CONFIG_VSERVER_DEBUG
23806 +       (1 << VCI_KCBIT_DEBUG) |
23807 +#endif
23808 +#ifdef CONFIG_VSERVER_HISTORY
23809 +       (1 << VCI_KCBIT_HISTORY) |
23810 +#endif
23811 +
23812 +       /* inode context tagging */
23813 +#if    defined(CONFIG_TAGGING_NONE)
23814 +       (0 << VCI_KCBIT_TAGGED) |
23815 +#elif  defined(CONFIG_TAGGING_UID16)
23816 +       (1 << VCI_KCBIT_TAGGED) |
23817 +#elif  defined(CONFIG_TAGGING_GID16)
23818 +       (2 << VCI_KCBIT_TAGGED) |
23819 +#elif  defined(CONFIG_TAGGING_ID24)
23820 +       (3 << VCI_KCBIT_TAGGED) |
23821 +#elif  defined(CONFIG_TAGGING_INTERN)
23822 +       (4 << VCI_KCBIT_TAGGED) |
23823 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23824 +       (5 << VCI_KCBIT_TAGGED) |
23825 +#else
23826 +       (7 << VCI_KCBIT_TAGGED) |
23827 +#endif
23828 +       (1 << VCI_KCBIT_PPTAG) |
23829 +       0;
23830 +}
23831 +
23832 diff -NurpP --minimal linux-3.3.1/mm/memcontrol.c linux-3.3.1-vs2.3.3.2/mm/memcontrol.c
23833 --- linux-3.3.1/mm/memcontrol.c 2012-04-03 03:01:26.000000000 +0200
23834 +++ linux-3.3.1-vs2.3.3.2/mm/memcontrol.c       2012-04-03 03:02:13.000000000 +0200
23835 @@ -839,6 +839,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23836                                 struct mem_cgroup, css);
23837  }
23838  
23839 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23840 +{
23841 +       return res_counter_read_u64(&mem->res, member);
23842 +}
23843 +
23844 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23845 +{
23846 +       return res_counter_read_u64(&mem->memsw, member);
23847 +}
23848 +
23849 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23850 +{
23851 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23852 +}
23853 +
23854 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23855 +{
23856 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23857 +}
23858 +
23859 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23860 +{
23861 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23862 +}
23863 +
23864  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23865  {
23866         struct mem_cgroup *memcg = NULL;
23867 diff -NurpP --minimal linux-3.3.1/mm/oom_kill.c linux-3.3.1-vs2.3.3.2/mm/oom_kill.c
23868 --- linux-3.3.1/mm/oom_kill.c   2012-03-19 19:47:30.000000000 +0100
23869 +++ linux-3.3.1-vs2.3.3.2/mm/oom_kill.c 2012-02-24 04:15:27.000000000 +0100
23870 @@ -34,6 +34,8 @@
23871  #include <linux/ptrace.h>
23872  #include <linux/freezer.h>
23873  #include <linux/ftrace.h>
23874 +#include <linux/reboot.h>
23875 +#include <linux/vs_context.h>
23876  
23877  #define CREATE_TRACE_POINTS
23878  #include <trace/events/oom.h>
23879 @@ -154,11 +156,18 @@ struct task_struct *find_lock_task_mm(st
23880  static bool oom_unkillable_task(struct task_struct *p,
23881                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23882  {
23883 -       if (is_global_init(p))
23884 +       unsigned xid = vx_current_xid();
23885 +
23886 +       /* skip the init task, global and per guest */
23887 +       if (task_is_init(p))
23888                 return true;
23889         if (p->flags & PF_KTHREAD)
23890                 return true;
23891  
23892 +       /* skip other guest and host processes if oom in guest */
23893 +       if (xid && vx_task_xid(p) != xid)
23894 +               return true;
23895 +
23896         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23897         if (memcg && !task_in_mem_cgroup(p, memcg))
23898                 return true;
23899 @@ -446,8 +455,8 @@ static int oom_kill_task(struct task_str
23900         /* mm cannot be safely dereferenced after task_unlock(p) */
23901         mm = p->mm;
23902  
23903 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23904 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
23905 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23906 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
23907                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
23908                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
23909         task_unlock(p);
23910 @@ -505,8 +514,8 @@ static int oom_kill_process(struct task_
23911         }
23912  
23913         task_lock(p);
23914 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23915 -               message, task_pid_nr(p), p->comm, points);
23916 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23917 +               message, task_pid_nr(p), p->xid, p->comm, points);
23918         task_unlock(p);
23919  
23920         /*
23921 @@ -607,6 +616,8 @@ int unregister_oom_notifier(struct notif
23922  }
23923  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23924  
23925 +long vs_oom_action(unsigned int);
23926 +
23927  /*
23928   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23929   * if a parallel OOM killing is already taking place that includes a zone in
23930 @@ -765,7 +776,12 @@ retry:
23931         if (!p) {
23932                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23933                 read_unlock(&tasklist_lock);
23934 -               panic("Out of memory and no killable processes...\n");
23935 +
23936 +               /* avoid panic for guest OOM */
23937 +               if (current->xid)
23938 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23939 +               else
23940 +                       panic("Out of memory and no killable processes...\n");
23941         }
23942  
23943         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23944 diff -NurpP --minimal linux-3.3.1/mm/page_alloc.c linux-3.3.1-vs2.3.3.2/mm/page_alloc.c
23945 --- linux-3.3.1/mm/page_alloc.c 2012-03-19 19:47:30.000000000 +0100
23946 +++ linux-3.3.1-vs2.3.3.2/mm/page_alloc.c       2012-03-19 20:52:10.000000000 +0100
23947 @@ -58,6 +58,8 @@
23948  #include <linux/memcontrol.h>
23949  #include <linux/prefetch.h>
23950  #include <linux/page-debug-flags.h>
23951 +#include <linux/vs_base.h>
23952 +#include <linux/vs_limit.h>
23953  
23954  #include <asm/tlbflush.h>
23955  #include <asm/div64.h>
23956 @@ -2602,6 +2604,9 @@ void si_meminfo(struct sysinfo *val)
23957         val->totalhigh = totalhigh_pages;
23958         val->freehigh = nr_free_highpages();
23959         val->mem_unit = PAGE_SIZE;
23960 +
23961 +       if (vx_flags(VXF_VIRT_MEM, 0))
23962 +               vx_vsi_meminfo(val);
23963  }
23964  
23965  EXPORT_SYMBOL(si_meminfo);
23966 @@ -2622,6 +2627,9 @@ void si_meminfo_node(struct sysinfo *val
23967         val->freehigh = 0;
23968  #endif
23969         val->mem_unit = PAGE_SIZE;
23970 +
23971 +       if (vx_flags(VXF_VIRT_MEM, 0))
23972 +               vx_vsi_meminfo(val);
23973  }
23974  #endif
23975  
23976 diff -NurpP --minimal linux-3.3.1/mm/pgtable-generic.c linux-3.3.1-vs2.3.3.2/mm/pgtable-generic.c
23977 --- linux-3.3.1/mm/pgtable-generic.c    2011-03-15 18:07:42.000000000 +0100
23978 +++ linux-3.3.1-vs2.3.3.2/mm/pgtable-generic.c  2012-02-24 03:55:07.000000000 +0100
23979 @@ -6,6 +6,8 @@
23980   *  Copyright (C) 2010  Linus Torvalds
23981   */
23982  
23983 +#include <linux/mm.h>
23984 +
23985  #include <linux/pagemap.h>
23986  #include <asm/tlb.h>
23987  #include <asm-generic/pgtable.h>
23988 diff -NurpP --minimal linux-3.3.1/mm/shmem.c linux-3.3.1-vs2.3.3.2/mm/shmem.c
23989 --- linux-3.3.1/mm/shmem.c      2012-03-19 19:47:30.000000000 +0100
23990 +++ linux-3.3.1-vs2.3.3.2/mm/shmem.c    2012-02-24 03:55:07.000000000 +0100
23991 @@ -1460,7 +1460,7 @@ static int shmem_statfs(struct dentry *d
23992  {
23993         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23994  
23995 -       buf->f_type = TMPFS_MAGIC;
23996 +       buf->f_type = TMPFS_SUPER_MAGIC;
23997         buf->f_bsize = PAGE_CACHE_SIZE;
23998         buf->f_namelen = NAME_MAX;
23999         if (sbinfo->max_blocks) {
24000 @@ -2217,7 +2217,7 @@ int shmem_fill_super(struct super_block 
24001         sb->s_maxbytes = MAX_LFS_FILESIZE;
24002         sb->s_blocksize = PAGE_CACHE_SIZE;
24003         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24004 -       sb->s_magic = TMPFS_MAGIC;
24005 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24006         sb->s_op = &shmem_ops;
24007         sb->s_time_gran = 1;
24008  #ifdef CONFIG_TMPFS_XATTR
24009 diff -NurpP --minimal linux-3.3.1/mm/slab.c linux-3.3.1-vs2.3.3.2/mm/slab.c
24010 --- linux-3.3.1/mm/slab.c       2012-03-19 19:47:30.000000000 +0100
24011 +++ linux-3.3.1-vs2.3.3.2/mm/slab.c     2012-02-24 03:55:07.000000000 +0100
24012 @@ -413,6 +413,8 @@ static void kmem_list3_init(struct kmem_
24013  #define STATS_INC_FREEMISS(x)  do { } while (0)
24014  #endif
24015  
24016 +#include "slab_vs.h"
24017 +
24018  #if DEBUG
24019  
24020  /*
24021 @@ -3414,6 +3416,7 @@ retry:
24022  
24023         obj = slab_get_obj(cachep, slabp, nodeid);
24024         check_slabp(cachep, slabp);
24025 +       vx_slab_alloc(cachep, flags);
24026         l3->free_objects--;
24027         /* move slabp to correct slabp list: */
24028         list_del(&slabp->list);
24029 @@ -3491,6 +3494,7 @@ __cache_alloc_node(struct kmem_cache *ca
24030         /* ___cache_alloc_node can fall back to other nodes */
24031         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24032    out:
24033 +       vx_slab_alloc(cachep, flags);
24034         local_irq_restore(save_flags);
24035         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24036         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24037 @@ -3678,6 +3682,7 @@ static inline void __cache_free(struct k
24038         check_irq_off();
24039         kmemleak_free_recursive(objp, cachep->flags);
24040         objp = cache_free_debugcheck(cachep, objp, caller);
24041 +       vx_slab_free(cachep);
24042  
24043         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24044  
24045 diff -NurpP --minimal linux-3.3.1/mm/slab_vs.h linux-3.3.1-vs2.3.3.2/mm/slab_vs.h
24046 --- linux-3.3.1/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24047 +++ linux-3.3.1-vs2.3.3.2/mm/slab_vs.h  2012-02-24 03:55:07.000000000 +0100
24048 @@ -0,0 +1,29 @@
24049 +
24050 +#include <linux/vserver/context.h>
24051 +
24052 +#include <linux/vs_context.h>
24053 +
24054 +static inline
24055 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24056 +{
24057 +       int what = gfp_zone(cachep->gfpflags);
24058 +       struct vx_info *vxi = current_vx_info();
24059 +
24060 +       if (!vxi)
24061 +               return;
24062 +
24063 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24064 +}
24065 +
24066 +static inline
24067 +void vx_slab_free(struct kmem_cache *cachep)
24068 +{
24069 +       int what = gfp_zone(cachep->gfpflags);
24070 +       struct vx_info *vxi = current_vx_info();
24071 +
24072 +       if (!vxi)
24073 +               return;
24074 +
24075 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24076 +}
24077 +
24078 diff -NurpP --minimal linux-3.3.1/mm/swapfile.c linux-3.3.1-vs2.3.3.2/mm/swapfile.c
24079 --- linux-3.3.1/mm/swapfile.c   2012-04-03 03:01:26.000000000 +0200
24080 +++ linux-3.3.1-vs2.3.3.2/mm/swapfile.c 2012-04-03 03:02:13.000000000 +0200
24081 @@ -36,6 +36,7 @@
24082  #include <asm/tlbflush.h>
24083  #include <linux/swapops.h>
24084  #include <linux/page_cgroup.h>
24085 +#include <linux/vs_base.h>
24086  
24087  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24088                                  unsigned char);
24089 @@ -1752,6 +1753,16 @@ static int swap_show(struct seq_file *sw
24090  
24091         if (si == SEQ_START_TOKEN) {
24092                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24093 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24094 +                       struct sysinfo si;
24095 +
24096 +                       vx_vsi_swapinfo(&si);
24097 +                       if (si.totalswap < (1 << 10))
24098 +                               return 0;
24099 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24100 +                               "hdv0", "partition", si.totalswap >> 10,
24101 +                               (si.totalswap - si.freeswap) >> 10, -1);
24102 +               }
24103                 return 0;
24104         }
24105  
24106 @@ -2175,6 +2186,8 @@ void si_swapinfo(struct sysinfo *val)
24107         val->freeswap = nr_swap_pages + nr_to_be_unused;
24108         val->totalswap = total_swap_pages + nr_to_be_unused;
24109         spin_unlock(&swap_lock);
24110 +       if (vx_flags(VXF_VIRT_MEM, 0))
24111 +               vx_vsi_swapinfo(val);
24112  }
24113  
24114  /*
24115 diff -NurpP --minimal linux-3.3.1/net/bridge/br_multicast.c linux-3.3.1-vs2.3.3.2/net/bridge/br_multicast.c
24116 --- linux-3.3.1/net/bridge/br_multicast.c       2012-03-19 19:47:32.000000000 +0100
24117 +++ linux-3.3.1-vs2.3.3.2/net/bridge/br_multicast.c     2012-03-19 20:53:28.000000000 +0100
24118 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24119         ip6h->hop_limit = 1;
24120         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24121         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24122 -                              &ip6h->saddr)) {
24123 +                              &ip6h->saddr, NULL)) {
24124                 kfree_skb(skb);
24125                 return NULL;
24126         }
24127 diff -NurpP --minimal linux-3.3.1/net/core/dev.c linux-3.3.1-vs2.3.3.2/net/core/dev.c
24128 --- linux-3.3.1/net/core/dev.c  2012-04-03 03:01:26.000000000 +0200
24129 +++ linux-3.3.1-vs2.3.3.2/net/core/dev.c        2012-04-03 03:02:13.000000000 +0200
24130 @@ -127,6 +127,7 @@
24131  #include <linux/in.h>
24132  #include <linux/jhash.h>
24133  #include <linux/random.h>
24134 +#include <linux/vs_inet.h>
24135  #include <trace/events/napi.h>
24136  #include <trace/events/net.h>
24137  #include <trace/events/skb.h>
24138 @@ -622,7 +623,8 @@ struct net_device *__dev_get_by_name(str
24139         struct hlist_head *head = dev_name_hash(net, name);
24140  
24141         hlist_for_each_entry(dev, p, head, name_hlist)
24142 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24143 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24144 +                   nx_dev_visible(current_nx_info(), dev))
24145                         return dev;
24146  
24147         return NULL;
24148 @@ -648,7 +650,8 @@ struct net_device *dev_get_by_name_rcu(s
24149         struct hlist_head *head = dev_name_hash(net, name);
24150  
24151         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24152 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24153 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24154 +                   nx_dev_visible(current_nx_info(), dev))
24155                         return dev;
24156  
24157         return NULL;
24158 @@ -699,7 +702,8 @@ struct net_device *__dev_get_by_index(st
24159         struct hlist_head *head = dev_index_hash(net, ifindex);
24160  
24161         hlist_for_each_entry(dev, p, head, index_hlist)
24162 -               if (dev->ifindex == ifindex)
24163 +               if ((dev->ifindex == ifindex) &&
24164 +                   nx_dev_visible(current_nx_info(), dev))
24165                         return dev;
24166  
24167         return NULL;
24168 @@ -717,7 +721,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24169   *     about locking. The caller must hold RCU lock.
24170   */
24171  
24172 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24173 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24174  {
24175         struct hlist_node *p;
24176         struct net_device *dev;
24177 @@ -729,6 +733,16 @@ struct net_device *dev_get_by_index_rcu(
24178  
24179         return NULL;
24180  }
24181 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24182 +
24183 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24184 +{
24185 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24186 +
24187 +       if (nx_dev_visible(current_nx_info(), dev))
24188 +               return dev;
24189 +       return NULL;
24190 +}
24191  EXPORT_SYMBOL(dev_get_by_index_rcu);
24192  
24193  
24194 @@ -777,7 +791,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24195  
24196         for_each_netdev_rcu(net, dev)
24197                 if (dev->type == type &&
24198 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24199 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24200 +                   nx_dev_visible(current_nx_info(), dev))
24201                         return dev;
24202  
24203         return NULL;
24204 @@ -789,9 +804,11 @@ struct net_device *__dev_getfirstbyhwtyp
24205         struct net_device *dev;
24206  
24207         ASSERT_RTNL();
24208 -       for_each_netdev(net, dev)
24209 -               if (dev->type == type)
24210 +       for_each_netdev(net, dev) {
24211 +               if ((dev->type == type) &&
24212 +                   nx_dev_visible(current_nx_info(), dev))
24213                         return dev;
24214 +       }
24215  
24216         return NULL;
24217  }
24218 @@ -909,6 +926,8 @@ static int __dev_alloc_name(struct net *
24219                                 continue;
24220                         if (i < 0 || i >= max_netdevices)
24221                                 continue;
24222 +                       if (!nx_dev_visible(current_nx_info(), d))
24223 +                               continue;
24224  
24225                         /*  avoid cases where sscanf is not exact inverse of printf */
24226                         snprintf(buf, IFNAMSIZ, name, i);
24227 @@ -4009,6 +4028,8 @@ static int dev_ifconf(struct net *net, c
24228  
24229         total = 0;
24230         for_each_netdev(net, dev) {
24231 +               if (!nx_dev_visible(current_nx_info(), dev))
24232 +                       continue;
24233                 for (i = 0; i < NPROTO; i++) {
24234                         if (gifconf_list[i]) {
24235                                 int done;
24236 @@ -4137,6 +4158,10 @@ static void dev_seq_printf_stats(struct 
24237         struct rtnl_link_stats64 temp;
24238         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24239  
24240 +       /* device visible inside network context? */
24241 +       if (!nx_dev_visible(current_nx_info(), dev))
24242 +               return;
24243 +
24244         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24245                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24246                    dev->name, stats->rx_bytes, stats->rx_packets,
24247 diff -NurpP --minimal linux-3.3.1/net/core/rtnetlink.c linux-3.3.1-vs2.3.3.2/net/core/rtnetlink.c
24248 --- linux-3.3.1/net/core/rtnetlink.c    2012-04-03 03:01:26.000000000 +0200
24249 +++ linux-3.3.1-vs2.3.3.2/net/core/rtnetlink.c  2012-04-03 03:02:13.000000000 +0200
24250 @@ -1073,6 +1073,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24251                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24252                         if (idx < s_idx)
24253                                 goto cont;
24254 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24255 +                               continue;
24256                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24257                                              NETLINK_CB(cb->skb).pid,
24258                                              cb->nlh->nlmsg_seq, 0,
24259 @@ -1955,6 +1957,9 @@ void rtmsg_ifinfo(int type, struct net_d
24260         int err = -ENOBUFS;
24261         size_t if_info_size;
24262  
24263 +       if (!nx_dev_visible(current_nx_info(), dev))
24264 +               return;
24265 +
24266         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24267         if (skb == NULL)
24268                 goto errout;
24269 diff -NurpP --minimal linux-3.3.1/net/core/sock.c linux-3.3.1-vs2.3.3.2/net/core/sock.c
24270 --- linux-3.3.1/net/core/sock.c 2012-03-19 19:47:33.000000000 +0100
24271 +++ linux-3.3.1-vs2.3.3.2/net/core/sock.c       2012-02-24 03:55:07.000000000 +0100
24272 @@ -130,6 +130,10 @@
24273  #include <net/netprio_cgroup.h>
24274  
24275  #include <linux/filter.h>
24276 +#include <linux/vs_socket.h>
24277 +#include <linux/vs_limit.h>
24278 +#include <linux/vs_context.h>
24279 +#include <linux/vs_network.h>
24280  
24281  #include <trace/events/sock.h>
24282  
24283 @@ -1127,6 +1131,8 @@ static struct sock *sk_prot_alloc(struct
24284                         goto out_free_sec;
24285                 sk_tx_queue_clear(sk);
24286         }
24287 +               sock_vx_init(sk);
24288 +               sock_nx_init(sk);
24289  
24290         return sk;
24291  
24292 @@ -1235,6 +1241,11 @@ static void __sk_free(struct sock *sk)
24293                 put_cred(sk->sk_peer_cred);
24294         put_pid(sk->sk_peer_pid);
24295         put_net(sock_net(sk));
24296 +       vx_sock_dec(sk);
24297 +       clr_vx_info(&sk->sk_vx_info);
24298 +       sk->sk_xid = -1;
24299 +       clr_nx_info(&sk->sk_nx_info);
24300 +       sk->sk_nid = -1;
24301         sk_prot_free(sk->sk_prot_creator, sk);
24302  }
24303  
24304 @@ -1295,6 +1306,8 @@ struct sock *sk_clone_lock(const struct 
24305  
24306                 /* SANITY */
24307                 get_net(sock_net(newsk));
24308 +               sock_vx_init(newsk);
24309 +               sock_nx_init(newsk);
24310                 sk_node_init(&newsk->sk_node);
24311                 sock_lock_init(newsk);
24312                 bh_lock_sock(newsk);
24313 @@ -1351,6 +1364,12 @@ struct sock *sk_clone_lock(const struct 
24314                 smp_wmb();
24315                 atomic_set(&newsk->sk_refcnt, 2);
24316  
24317 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24318 +               newsk->sk_xid = sk->sk_xid;
24319 +               vx_sock_inc(newsk);
24320 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24321 +               newsk->sk_nid = sk->sk_nid;
24322 +
24323                 /*
24324                  * Increment the counter in the same struct proto as the master
24325                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24326 @@ -2102,6 +2121,12 @@ void sock_init_data(struct socket *sock,
24327  
24328         sk->sk_stamp = ktime_set(-1L, 0);
24329  
24330 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24331 +       sk->sk_xid = vx_current_xid();
24332 +       vx_sock_inc(sk);
24333 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24334 +       sk->sk_nid = nx_current_nid();
24335 +
24336         /*
24337          * Before updating sk_refcnt, we must commit prior changes to memory
24338          * (Documentation/RCU/rculist_nulls.txt for details)
24339 diff -NurpP --minimal linux-3.3.1/net/ipv4/af_inet.c linux-3.3.1-vs2.3.3.2/net/ipv4/af_inet.c
24340 --- linux-3.3.1/net/ipv4/af_inet.c      2012-03-19 19:47:33.000000000 +0100
24341 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/af_inet.c    2012-02-24 03:55:07.000000000 +0100
24342 @@ -117,6 +117,7 @@
24343  #ifdef CONFIG_IP_MROUTE
24344  #include <linux/mroute.h>
24345  #endif
24346 +#include <linux/vs_limit.h>
24347  
24348  
24349  /* The inetsw table contains everything that inet_create needs to
24350 @@ -326,9 +327,13 @@ lookup_protocol:
24351         }
24352  
24353         err = -EPERM;
24354 +       if ((protocol == IPPROTO_ICMP) &&
24355 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24356 +               goto override;
24357 +
24358         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24359                 goto out_rcu_unlock;
24360 -
24361 +override:
24362         err = -EAFNOSUPPORT;
24363         if (!inet_netns_ok(net, protocol))
24364                 goto out_rcu_unlock;
24365 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24366         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24367         struct sock *sk = sock->sk;
24368         struct inet_sock *inet = inet_sk(sk);
24369 +       struct nx_v4_sock_addr nsa;
24370         unsigned short snum;
24371         int chk_addr_ret;
24372         int err;
24373 @@ -475,7 +481,11 @@ int inet_bind(struct socket *sock, struc
24374                         goto out;
24375         }
24376  
24377 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24378 +       err = v4_map_sock_addr(inet, addr, &nsa);
24379 +       if (err)
24380 +               goto out;
24381 +
24382 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24383  
24384         /* Not specified by any standard per-se, however it breaks too
24385          * many applications when removed.  It is unfortunate since
24386 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
24387         err = -EADDRNOTAVAIL;
24388         if (!sysctl_ip_nonlocal_bind &&
24389             !(inet->freebind || inet->transparent) &&
24390 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24391 +           nsa.saddr != htonl(INADDR_ANY) &&
24392             chk_addr_ret != RTN_LOCAL &&
24393             chk_addr_ret != RTN_MULTICAST &&
24394             chk_addr_ret != RTN_BROADCAST)
24395 @@ -512,7 +522,7 @@ int inet_bind(struct socket *sock, struc
24396         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24397                 goto out_release_sock;
24398  
24399 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24400 +       v4_set_sock_addr(inet, &nsa);
24401         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24402                 inet->inet_saddr = 0;  /* Use device */
24403  
24404 @@ -715,11 +725,13 @@ int inet_getname(struct socket *sock, st
24405                      peer == 1))
24406                         return -ENOTCONN;
24407                 sin->sin_port = inet->inet_dport;
24408 -               sin->sin_addr.s_addr = inet->inet_daddr;
24409 +               sin->sin_addr.s_addr =
24410 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24411         } else {
24412                 __be32 addr = inet->inet_rcv_saddr;
24413                 if (!addr)
24414                         addr = inet->inet_saddr;
24415 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24416                 sin->sin_port = inet->inet_sport;
24417                 sin->sin_addr.s_addr = addr;
24418         }
24419 diff -NurpP --minimal linux-3.3.1/net/ipv4/arp.c linux-3.3.1-vs2.3.3.2/net/ipv4/arp.c
24420 --- linux-3.3.1/net/ipv4/arp.c  2012-03-19 19:47:33.000000000 +0100
24421 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/arp.c        2012-02-24 03:55:07.000000000 +0100
24422 @@ -1329,6 +1329,7 @@ static void arp_format_neigh_entry(struc
24423         struct net_device *dev = n->dev;
24424         int hatype = dev->type;
24425  
24426 +       /* FIXME: check for network context */
24427         read_lock(&n->lock);
24428         /* Convert hardware address to XX:XX:XX:XX ... form. */
24429  #if IS_ENABLED(CONFIG_AX25)
24430 @@ -1360,6 +1361,7 @@ static void arp_format_pneigh_entry(stru
24431         int hatype = dev ? dev->type : 0;
24432         char tbuf[16];
24433  
24434 +       /* FIXME: check for network context */
24435         sprintf(tbuf, "%pI4", n->key);
24436         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24437                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24438 diff -NurpP --minimal linux-3.3.1/net/ipv4/devinet.c linux-3.3.1-vs2.3.3.2/net/ipv4/devinet.c
24439 --- linux-3.3.1/net/ipv4/devinet.c      2012-03-19 19:47:33.000000000 +0100
24440 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/devinet.c    2012-02-24 03:55:07.000000000 +0100
24441 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24442  }
24443  EXPORT_SYMBOL(inetdev_by_index);
24444  
24445 +
24446  /* Called only from RTNL semaphored context. No locks. */
24447  
24448  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24449 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24450  
24451         in_dev = __in_dev_get_rtnl(dev);
24452         if (in_dev) {
24453 +               struct nx_info *nxi = current_nx_info();
24454 +
24455                 if (tryaddrmatch) {
24456                         /* Matthias Andree */
24457                         /* compare label and address (4.4BSD style) */
24458 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24459                            This is checked above. */
24460                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24461                              ifap = &ifa->ifa_next) {
24462 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24463 +                                       continue;
24464                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24465                                     sin_orig.sin_addr.s_addr ==
24466                                                         ifa->ifa_local) {
24467 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24468                    comparing just the label */
24469                 if (!ifa) {
24470                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24471 -                            ifap = &ifa->ifa_next)
24472 +                            ifap = &ifa->ifa_next) {
24473 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24474 +                                       continue;
24475                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24476                                         break;
24477 +                       }
24478                 }
24479         }
24480  
24481 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24482                 goto out;
24483  
24484         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24485 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24486 +                       continue;
24487                 if (!buf) {
24488                         done += sizeof(ifr);
24489                         continue;
24490 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24491         struct net_device *dev;
24492         struct in_device *in_dev;
24493         struct in_ifaddr *ifa;
24494 +       struct sock *sk = skb->sk;
24495         struct hlist_head *head;
24496         struct hlist_node *node;
24497  
24498 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24499  
24500                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24501                              ifa = ifa->ifa_next, ip_idx++) {
24502 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24503 +                               continue;
24504                                 if (ip_idx < s_ip_idx)
24505                                         continue;
24506                                 if (inet_fill_ifaddr(skb, ifa,
24507 diff -NurpP --minimal linux-3.3.1/net/ipv4/fib_trie.c linux-3.3.1-vs2.3.3.2/net/ipv4/fib_trie.c
24508 --- linux-3.3.1/net/ipv4/fib_trie.c     2012-03-19 19:47:33.000000000 +0100
24509 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/fib_trie.c   2012-02-24 03:55:07.000000000 +0100
24510 @@ -2556,6 +2556,7 @@ static int fib_route_seq_show(struct seq
24511                             || fa->fa_type == RTN_MULTICAST)
24512                                 continue;
24513  
24514 +                       /* FIXME: check for network context? */
24515                         if (fi)
24516                                 seq_printf(seq,
24517                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24518 diff -NurpP --minimal linux-3.3.1/net/ipv4/inet_connection_sock.c linux-3.3.1-vs2.3.3.2/net/ipv4/inet_connection_sock.c
24519 --- linux-3.3.1/net/ipv4/inet_connection_sock.c 2012-03-19 19:47:33.000000000 +0100
24520 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/inet_connection_sock.c       2012-02-24 03:55:07.000000000 +0100
24521 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24522  }
24523  EXPORT_SYMBOL(inet_get_local_port_range);
24524  
24525 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24526 +{
24527 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24528 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24529 +
24530 +       if (inet_v6_ipv6only(sk2))
24531 +               return 0;
24532 +
24533 +       if (sk1_rcv_saddr &&
24534 +           sk2_rcv_saddr &&
24535 +           sk1_rcv_saddr == sk2_rcv_saddr)
24536 +               return 1;
24537 +
24538 +       if (sk1_rcv_saddr &&
24539 +           !sk2_rcv_saddr &&
24540 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24541 +               return 1;
24542 +
24543 +       if (sk2_rcv_saddr &&
24544 +           !sk1_rcv_saddr &&
24545 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24546 +               return 1;
24547 +
24548 +       if (!sk1_rcv_saddr &&
24549 +           !sk2_rcv_saddr &&
24550 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24551 +               return 1;
24552 +
24553 +       return 0;
24554 +}
24555 +
24556  int inet_csk_bind_conflict(const struct sock *sk,
24557                            const struct inet_bind_bucket *tb)
24558  {
24559 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
24560                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24561                         if (!reuse || !sk2->sk_reuse ||
24562                             sk2->sk_state == TCP_LISTEN) {
24563 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24564 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24565 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24566 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24567                                         break;
24568                         }
24569                 }
24570 diff -NurpP --minimal linux-3.3.1/net/ipv4/inet_diag.c linux-3.3.1-vs2.3.3.2/net/ipv4/inet_diag.c
24571 --- linux-3.3.1/net/ipv4/inet_diag.c    2012-03-19 19:47:33.000000000 +0100
24572 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/inet_diag.c  2012-02-24 04:26:38.000000000 +0100
24573 @@ -31,6 +31,8 @@
24574  
24575  #include <linux/inet.h>
24576  #include <linux/stddef.h>
24577 +#include <linux/vs_network.h>
24578 +#include <linux/vs_inet.h>
24579  
24580  #include <linux/inet_diag.h>
24581  #include <linux/sock_diag.h>
24582 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24583  
24584         r->id.idiag_sport = inet->inet_sport;
24585         r->id.idiag_dport = inet->inet_dport;
24586 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24587 -       r->id.idiag_dst[0] = inet->inet_daddr;
24588 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24589 +               inet->inet_rcv_saddr);
24590 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24591 +               inet->inet_daddr);
24592  
24593         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24594          * hence this needs to be included regardless of socket family.
24595 @@ -227,8 +231,8 @@ static int inet_twsk_diag_fill(struct in
24596         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24597         r->id.idiag_sport     = tw->tw_sport;
24598         r->id.idiag_dport     = tw->tw_dport;
24599 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24600 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24601 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24602 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24603         r->idiag_state        = tw->tw_substate;
24604         r->idiag_timer        = 3;
24605         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24606 @@ -272,12 +276,14 @@ int inet_diag_dump_one_icsk(struct inet_
24607  
24608         err = -EINVAL;
24609         if (req->sdiag_family == AF_INET) {
24610 +               /* TODO: lback */
24611                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24612                                  req->id.idiag_dport, req->id.idiag_src[0],
24613                                  req->id.idiag_sport, req->id.idiag_if);
24614         }
24615  #if IS_ENABLED(CONFIG_IPV6)
24616         else if (req->sdiag_family == AF_INET6) {
24617 +               /* TODO: lback */
24618                 sk = inet6_lookup(&init_net, hashinfo,
24619                                   (struct in6_addr *)req->id.idiag_dst,
24620                                   req->id.idiag_dport,
24621 @@ -472,6 +478,7 @@ int inet_diag_bc_sk(const struct nlattr 
24622         } else
24623  #endif
24624         {
24625 +                       /* TODO: lback */
24626                 entry.saddr = &inet->inet_rcv_saddr;
24627                 entry.daddr = &inet->inet_daddr;
24628         }
24629 @@ -570,6 +577,7 @@ static int inet_twsk_diag_dump(struct in
24630                 } else
24631  #endif
24632                 {
24633 +                       /* TODO: lback */
24634                         entry.saddr = &tw->tw_rcv_saddr;
24635                         entry.daddr = &tw->tw_daddr;
24636                 }
24637 @@ -615,8 +623,8 @@ static int inet_diag_fill_req(struct sk_
24638  
24639         r->id.idiag_sport = inet->inet_sport;
24640         r->id.idiag_dport = ireq->rmt_port;
24641 -       r->id.idiag_src[0] = ireq->loc_addr;
24642 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24643 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24644 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24645         r->idiag_expires = jiffies_to_msecs(tmo);
24646         r->idiag_rqueue = 0;
24647         r->idiag_wqueue = 0;
24648 @@ -683,6 +691,7 @@ static int inet_diag_dump_reqs(struct sk
24649                                 continue;
24650  
24651                         if (bc) {
24652 +                               /* TODO: lback */
24653                                 entry.saddr =
24654  #if IS_ENABLED(CONFIG_IPV6)
24655                                         (entry.family == AF_INET6) ?
24656 @@ -744,6 +753,8 @@ void inet_diag_dump_icsk(struct inet_has
24657                         sk_nulls_for_each(sk, node, &ilb->head) {
24658                                 struct inet_sock *inet = inet_sk(sk);
24659  
24660 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24661 +                                       continue;
24662                                 if (num < s_num) {
24663                                         num++;
24664                                         continue;
24665 @@ -814,6 +825,8 @@ skip_listen_ht:
24666                 sk_nulls_for_each(sk, node, &head->chain) {
24667                         struct inet_sock *inet = inet_sk(sk);
24668  
24669 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24670 +                               continue;
24671                         if (num < s_num)
24672                                 goto next_normal;
24673                         if (!(r->idiag_states & (1 << sk->sk_state)))
24674 @@ -841,6 +854,8 @@ next_normal:
24675                         inet_twsk_for_each(tw, node,
24676                                     &head->twchain) {
24677  
24678 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24679 +                                       continue;
24680                                 if (num < s_num)
24681                                         goto next_dying;
24682                                 if (r->sdiag_family != AF_UNSPEC &&
24683 diff -NurpP --minimal linux-3.3.1/net/ipv4/inet_hashtables.c linux-3.3.1-vs2.3.3.2/net/ipv4/inet_hashtables.c
24684 --- linux-3.3.1/net/ipv4/inet_hashtables.c      2011-10-24 18:45:34.000000000 +0200
24685 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/inet_hashtables.c    2012-02-24 03:55:07.000000000 +0100
24686 @@ -22,6 +22,7 @@
24687  #include <net/inet_connection_sock.h>
24688  #include <net/inet_hashtables.h>
24689  #include <net/secure_seq.h>
24690 +#include <net/route.h>
24691  #include <net/ip.h>
24692  
24693  /*
24694 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24695                         if (rcv_saddr != daddr)
24696                                 return -1;
24697                         score += 2;
24698 +               } else {
24699 +                       /* block non nx_info ips */
24700 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24701 +                               daddr, NXA_MASK_BIND))
24702 +                               return -1;
24703                 }
24704                 if (sk->sk_bound_dev_if) {
24705                         if (sk->sk_bound_dev_if != dif)
24706 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24707   * wildcarded during the search since they can never be otherwise.
24708   */
24709  
24710 -
24711  struct sock *__inet_lookup_listener(struct net *net,
24712                                     struct inet_hashinfo *hashinfo,
24713                                     const __be32 daddr, const unsigned short hnum,
24714 @@ -196,6 +201,7 @@ begin:
24715                         hiscore = score;
24716                 }
24717         }
24718 +
24719         /*
24720          * if the nulls value we got at the end of this lookup is
24721          * not the expected one, we must restart lookup.
24722 diff -NurpP --minimal linux-3.3.1/net/ipv4/netfilter/nf_nat_helper.c linux-3.3.1-vs2.3.3.2/net/ipv4/netfilter/nf_nat_helper.c
24723 --- linux-3.3.1/net/ipv4/netfilter/nf_nat_helper.c      2012-03-19 19:47:33.000000000 +0100
24724 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/netfilter/nf_nat_helper.c    2012-02-24 03:55:07.000000000 +0100
24725 @@ -20,6 +20,7 @@
24726  #include <net/route.h>
24727  
24728  #include <linux/netfilter_ipv4.h>
24729 +#include <net/route.h>
24730  #include <net/netfilter/nf_conntrack.h>
24731  #include <net/netfilter/nf_conntrack_helper.h>
24732  #include <net/netfilter/nf_conntrack_ecache.h>
24733 diff -NurpP --minimal linux-3.3.1/net/ipv4/netfilter.c linux-3.3.1-vs2.3.3.2/net/ipv4/netfilter.c
24734 --- linux-3.3.1/net/ipv4/netfilter.c    2012-01-09 16:15:03.000000000 +0100
24735 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/netfilter.c  2012-02-24 03:55:07.000000000 +0100
24736 @@ -6,7 +6,7 @@
24737  #include <linux/skbuff.h>
24738  #include <linux/gfp.h>
24739  #include <linux/export.h>
24740 -#include <net/route.h>
24741 +// #include <net/route.h>
24742  #include <net/xfrm.h>
24743  #include <net/ip.h>
24744  #include <net/netfilter/nf_queue.h>
24745 diff -NurpP --minimal linux-3.3.1/net/ipv4/raw.c linux-3.3.1-vs2.3.3.2/net/ipv4/raw.c
24746 --- linux-3.3.1/net/ipv4/raw.c  2012-03-19 19:47:33.000000000 +0100
24747 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/raw.c        2012-02-24 03:55:07.000000000 +0100
24748 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24749  
24750                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24751                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24752 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24753 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24754                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24755                         goto found; /* gotcha */
24756         }
24757 @@ -390,6 +390,12 @@ static int raw_send_hdrinc(struct sock *
24758                 icmp_out_count(net, ((struct icmphdr *)
24759                         skb_transport_header(skb))->type);
24760  
24761 +       err = -EPERM;
24762 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24763 +               sk->sk_nx_info &&
24764 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24765 +               goto error_free;
24766 +
24767         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24768                       rt->dst.dev, dst_output);
24769         if (err > 0)
24770 @@ -577,6 +583,16 @@ static int raw_sendmsg(struct kiocb *ioc
24771                         goto done;
24772         }
24773  
24774 +       if (sk->sk_nx_info) {
24775 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24776 +               if (IS_ERR(rt)) {
24777 +                       err = PTR_ERR(rt);
24778 +                       rt = NULL;
24779 +                       goto done;
24780 +               }
24781 +               ip_rt_put(rt);
24782 +       }
24783 +
24784         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24785         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24786         if (IS_ERR(rt)) {
24787 @@ -653,17 +669,19 @@ static int raw_bind(struct sock *sk, str
24788  {
24789         struct inet_sock *inet = inet_sk(sk);
24790         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24791 +       struct nx_v4_sock_addr nsa = { 0 };
24792         int ret = -EINVAL;
24793         int chk_addr_ret;
24794  
24795         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24796                 goto out;
24797 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24798 +       v4_map_sock_addr(inet, addr, &nsa);
24799 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24800         ret = -EADDRNOTAVAIL;
24801 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24802 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24803             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24804                 goto out;
24805 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24806 +       v4_set_sock_addr(inet, &nsa);
24807         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24808                 inet->inet_saddr = 0;  /* Use device */
24809         sk_dst_reset(sk);
24810 @@ -715,7 +733,8 @@ static int raw_recvmsg(struct kiocb *ioc
24811         /* Copy the address. */
24812         if (sin) {
24813                 sin->sin_family = AF_INET;
24814 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24815 +               sin->sin_addr.s_addr =
24816 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24817                 sin->sin_port = 0;
24818                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24819         }
24820 @@ -911,7 +930,8 @@ static struct sock *raw_get_first(struct
24821                 struct hlist_node *node;
24822  
24823                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24824 -                       if (sock_net(sk) == seq_file_net(seq))
24825 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24826 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24827                                 goto found;
24828         }
24829         sk = NULL;
24830 @@ -927,7 +947,8 @@ static struct sock *raw_get_next(struct 
24831                 sk = sk_next(sk);
24832  try_again:
24833                 ;
24834 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24835 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24836 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24837  
24838         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24839                 sk = sk_head(&state->h->ht[state->bucket]);
24840 diff -NurpP --minimal linux-3.3.1/net/ipv4/route.c linux-3.3.1-vs2.3.3.2/net/ipv4/route.c
24841 --- linux-3.3.1/net/ipv4/route.c        2012-03-19 19:47:33.000000000 +0100
24842 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/route.c      2012-03-19 20:52:10.000000000 +0100
24843 @@ -2697,7 +2697,7 @@ static struct rtable *ip_route_output_sl
24844  
24845  
24846         if (fl4->flowi4_oif) {
24847 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24848 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24849                 rth = ERR_PTR(-ENODEV);
24850                 if (dev_out == NULL)
24851                         goto out;
24852 diff -NurpP --minimal linux-3.3.1/net/ipv4/tcp.c linux-3.3.1-vs2.3.3.2/net/ipv4/tcp.c
24853 --- linux-3.3.1/net/ipv4/tcp.c  2012-03-19 19:47:33.000000000 +0100
24854 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/tcp.c        2012-03-19 20:52:10.000000000 +0100
24855 @@ -266,6 +266,7 @@
24856  #include <linux/crypto.h>
24857  #include <linux/time.h>
24858  #include <linux/slab.h>
24859 +#include <linux/in.h>
24860  
24861  #include <net/icmp.h>
24862  #include <net/tcp.h>
24863 diff -NurpP --minimal linux-3.3.1/net/ipv4/tcp_ipv4.c linux-3.3.1-vs2.3.3.2/net/ipv4/tcp_ipv4.c
24864 --- linux-3.3.1/net/ipv4/tcp_ipv4.c     2012-03-19 19:47:33.000000000 +0100
24865 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/tcp_ipv4.c   2012-03-19 20:52:10.000000000 +0100
24866 @@ -2036,6 +2036,12 @@ static void *listening_get_next(struct s
24867                 req = req->dl_next;
24868                 while (1) {
24869                         while (req) {
24870 +                               vxdprintk(VXD_CBIT(net, 6),
24871 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24872 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24873 +                               if (req->sk &&
24874 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24875 +                                       continue;
24876                                 if (req->rsk_ops->family == st->family) {
24877                                         cur = req;
24878                                         goto out;
24879 @@ -2060,6 +2066,10 @@ get_req:
24880         }
24881  get_sk:
24882         sk_nulls_for_each_from(sk, node) {
24883 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24884 +                       sk, sk->sk_nid, nx_current_nid());
24885 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24886 +                       continue;
24887                 if (!net_eq(sock_net(sk), net))
24888                         continue;
24889                 if (sk->sk_family == st->family) {
24890 @@ -2136,6 +2146,11 @@ static void *established_get_first(struc
24891  
24892                 spin_lock_bh(lock);
24893                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24894 +                       vxdprintk(VXD_CBIT(net, 6),
24895 +                               "sk,egf: %p [#%d] (from %d)",
24896 +                               sk, sk->sk_nid, nx_current_nid());
24897 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24898 +                               continue;
24899                         if (sk->sk_family != st->family ||
24900                             !net_eq(sock_net(sk), net)) {
24901                                 continue;
24902 @@ -2146,6 +2161,11 @@ static void *established_get_first(struc
24903                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24904                 inet_twsk_for_each(tw, node,
24905                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24906 +                       vxdprintk(VXD_CBIT(net, 6),
24907 +                               "tw: %p [#%d] (from %d)",
24908 +                               tw, tw->tw_nid, nx_current_nid());
24909 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24910 +                               continue;
24911                         if (tw->tw_family != st->family ||
24912                             !net_eq(twsk_net(tw), net)) {
24913                                 continue;
24914 @@ -2175,7 +2195,9 @@ static void *established_get_next(struct
24915                 tw = cur;
24916                 tw = tw_next(tw);
24917  get_tw:
24918 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24919 +               while (tw && (tw->tw_family != st->family ||
24920 +                       !net_eq(twsk_net(tw), net) ||
24921 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24922                         tw = tw_next(tw);
24923                 }
24924                 if (tw) {
24925 @@ -2199,6 +2221,11 @@ get_tw:
24926                 sk = sk_nulls_next(sk);
24927  
24928         sk_nulls_for_each_from(sk, node) {
24929 +               vxdprintk(VXD_CBIT(net, 6),
24930 +                       "sk,egn: %p [#%d] (from %d)",
24931 +                       sk, sk->sk_nid, nx_current_nid());
24932 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24933 +                       continue;
24934                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24935                         goto found;
24936         }
24937 @@ -2404,9 +2431,9 @@ static void get_openreq4(const struct so
24938         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24939                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24940                 i,
24941 -               ireq->loc_addr,
24942 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24943                 ntohs(inet_sk(sk)->inet_sport),
24944 -               ireq->rmt_addr,
24945 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24946                 ntohs(ireq->rmt_port),
24947                 TCP_SYN_RECV,
24948                 0, 0, /* could print option size, but that is af dependent. */
24949 @@ -2428,8 +2455,8 @@ static void get_tcp4_sock(struct sock *s
24950         const struct tcp_sock *tp = tcp_sk(sk);
24951         const struct inet_connection_sock *icsk = inet_csk(sk);
24952         const struct inet_sock *inet = inet_sk(sk);
24953 -       __be32 dest = inet->inet_daddr;
24954 -       __be32 src = inet->inet_rcv_saddr;
24955 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24956 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24957         __u16 destp = ntohs(inet->inet_dport);
24958         __u16 srcp = ntohs(inet->inet_sport);
24959         int rx_queue;
24960 @@ -2486,8 +2513,8 @@ static void get_timewait4_sock(const str
24961         if (ttd < 0)
24962                 ttd = 0;
24963  
24964 -       dest  = tw->tw_daddr;
24965 -       src   = tw->tw_rcv_saddr;
24966 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24967 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24968         destp = ntohs(tw->tw_dport);
24969         srcp  = ntohs(tw->tw_sport);
24970  
24971 diff -NurpP --minimal linux-3.3.1/net/ipv4/tcp_minisocks.c linux-3.3.1-vs2.3.3.2/net/ipv4/tcp_minisocks.c
24972 --- linux-3.3.1/net/ipv4/tcp_minisocks.c        2012-03-19 19:47:33.000000000 +0100
24973 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/tcp_minisocks.c      2012-02-24 04:25:11.000000000 +0100
24974 @@ -23,6 +23,9 @@
24975  #include <linux/slab.h>
24976  #include <linux/sysctl.h>
24977  #include <linux/workqueue.h>
24978 +#include <linux/vs_limit.h>
24979 +#include <linux/vs_socket.h>
24980 +#include <linux/vs_context.h>
24981  #include <net/tcp.h>
24982  #include <net/inet_common.h>
24983  #include <net/xfrm.h>
24984 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
24985                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
24986                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24987  
24988 +               tw->tw_xid              = sk->sk_xid;
24989 +               tw->tw_vx_info          = NULL;
24990 +               tw->tw_nid              = sk->sk_nid;
24991 +               tw->tw_nx_info          = NULL;
24992 +
24993  #if IS_ENABLED(CONFIG_IPV6)
24994                 if (tw->tw_family == PF_INET6) {
24995                         struct ipv6_pinfo *np = inet6_sk(sk);
24996 diff -NurpP --minimal linux-3.3.1/net/ipv4/udp.c linux-3.3.1-vs2.3.3.2/net/ipv4/udp.c
24997 --- linux-3.3.1/net/ipv4/udp.c  2012-03-19 19:47:33.000000000 +0100
24998 +++ linux-3.3.1-vs2.3.3.2/net/ipv4/udp.c        2012-02-24 03:55:07.000000000 +0100
24999 @@ -297,14 +297,7 @@ fail:
25000  }
25001  EXPORT_SYMBOL(udp_lib_get_port);
25002  
25003 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25004 -{
25005 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25006 -
25007 -       return  (!ipv6_only_sock(sk2)  &&
25008 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25009 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25010 -}
25011 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25012  
25013  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25014                                        unsigned int port)
25015 @@ -339,6 +332,11 @@ static inline int compute_score(struct s
25016                         if (inet->inet_rcv_saddr != daddr)
25017                                 return -1;
25018                         score += 2;
25019 +               } else {
25020 +                       /* block non nx_info ips */
25021 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25022 +                               daddr, NXA_MASK_BIND))
25023 +                               return -1;
25024                 }
25025                 if (inet->inet_daddr) {
25026                         if (inet->inet_daddr != saddr)
25027 @@ -442,6 +440,7 @@ exact_match:
25028         return result;
25029  }
25030  
25031 +
25032  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25033   * harder than this. -DaveM
25034   */
25035 @@ -487,6 +486,11 @@ begin:
25036         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25037                 score = compute_score(sk, net, saddr, hnum, sport,
25038                                       daddr, dport, dif);
25039 +               /* FIXME: disabled?
25040 +               if (score == 9) {
25041 +                       result = sk;
25042 +                       break;
25043 +               } else */
25044                 if (score > badness) {
25045                         result = sk;
25046                         badness = score;
25047 @@ -500,6 +504,7 @@ begin:
25048         if (get_nulls_value(node) != slot)
25049                 goto begin;
25050  
25051 +
25052         if (result) {
25053                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25054                         result = NULL;
25055 @@ -509,6 +514,7 @@ begin:
25056                         goto begin;
25057                 }
25058         }
25059 +
25060         rcu_read_unlock();
25061         return result;
25062  }
25063 @@ -552,8 +558,7 @@ static inline struct sock *udp_v4_mcast_
25064                     udp_sk(s)->udp_port_hash != hnum ||
25065                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25066                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25067 -                   (inet->inet_rcv_saddr &&
25068 -                    inet->inet_rcv_saddr != loc_addr) ||
25069 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25070                     ipv6_only_sock(s) ||
25071                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25072                         continue;
25073 @@ -931,6 +936,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25074                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25075                                    faddr, saddr, dport, inet->inet_sport);
25076  
25077 +               if (sk->sk_nx_info) {
25078 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25079 +                       if (IS_ERR(rt)) {
25080 +                               err = PTR_ERR(rt);
25081 +                               rt = NULL;
25082 +                               goto out;
25083 +                       }
25084 +                       ip_rt_put(rt);
25085 +               }
25086 +
25087                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25088                 rt = ip_route_output_flow(net, fl4, sk);
25089                 if (IS_ERR(rt)) {
25090 @@ -1229,7 +1244,8 @@ try_again:
25091         if (sin) {
25092                 sin->sin_family = AF_INET;
25093                 sin->sin_port = udp_hdr(skb)->source;
25094 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25095 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25096 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25097                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25098         }
25099         if (inet->cmsg_flags)
25100 @@ -1976,6 +1992,8 @@ static struct sock *udp_get_first(struct
25101                 sk_nulls_for_each(sk, node, &hslot->head) {
25102                         if (!net_eq(sock_net(sk), net))
25103                                 continue;
25104 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25105 +                               continue;
25106                         if (sk->sk_family == state->family)
25107                                 goto found;
25108                 }
25109 @@ -1993,7 +2011,9 @@ static struct sock *udp_get_next(struct 
25110  
25111         do {
25112                 sk = sk_nulls_next(sk);
25113 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25114 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25115 +               sk->sk_family != state->family ||
25116 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25117  
25118         if (!sk) {
25119                 if (state->bucket <= state->udp_table->mask)
25120 diff -NurpP --minimal linux-3.3.1/net/ipv6/Kconfig linux-3.3.1-vs2.3.3.2/net/ipv6/Kconfig
25121 --- linux-3.3.1/net/ipv6/Kconfig        2010-08-02 16:52:59.000000000 +0200
25122 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/Kconfig      2012-02-24 03:55:07.000000000 +0100
25123 @@ -4,8 +4,8 @@
25124  
25125  #   IPv6 as module will cause a CRASH if you try to unload it
25126  menuconfig IPV6
25127 -       tristate "The IPv6 protocol"
25128 -       default m
25129 +       bool "The IPv6 protocol"
25130 +       default n
25131         ---help---
25132           This is complemental support for the IP version 6.
25133           You will still be able to do traditional IPv4 networking as well.
25134 diff -NurpP --minimal linux-3.3.1/net/ipv6/addrconf.c linux-3.3.1-vs2.3.3.2/net/ipv6/addrconf.c
25135 --- linux-3.3.1/net/ipv6/addrconf.c     2012-03-19 19:47:33.000000000 +0100
25136 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/addrconf.c   2012-03-19 20:52:10.000000000 +0100
25137 @@ -88,6 +88,8 @@
25138  #include <linux/proc_fs.h>
25139  #include <linux/seq_file.h>
25140  #include <linux/export.h>
25141 +#include <linux/vs_network.h>
25142 +#include <linux/vs_inet6.h>
25143  
25144  /* Set to 3 to get tracing... */
25145  #define ACONF_DEBUG 2
25146 @@ -1105,7 +1107,7 @@ out:
25147  
25148  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25149                        const struct in6_addr *daddr, unsigned int prefs,
25150 -                      struct in6_addr *saddr)
25151 +                      struct in6_addr *saddr, struct nx_info *nxi)
25152  {
25153         struct ipv6_saddr_score scores[2],
25154                                 *score = &scores[0], *hiscore = &scores[1];
25155 @@ -1177,6 +1179,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25156                                                dev->name);
25157                                 continue;
25158                         }
25159 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25160 +                               continue;
25161  
25162                         score->rule = -1;
25163                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25164 @@ -3162,7 +3166,10 @@ static void if6_seq_stop(struct seq_file
25165  static int if6_seq_show(struct seq_file *seq, void *v)
25166  {
25167         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25168 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25169 +
25170 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25171 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25172 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25173                    &ifp->addr,
25174                    ifp->idev->dev->ifindex,
25175                    ifp->prefix_len,
25176 @@ -3668,6 +3675,11 @@ static int in6_dump_addrs(struct inet6_d
25177         struct ifacaddr6 *ifaca;
25178         int err = 1;
25179         int ip_idx = *p_ip_idx;
25180 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25181 +
25182 +       /* disable ipv6 on non v6 guests */
25183 +       if (nxi && !nx_info_has_v6(nxi))
25184 +               return skb->len;
25185  
25186         read_lock_bh(&idev->lock);
25187         switch (type) {
25188 @@ -3678,6 +3690,8 @@ static int in6_dump_addrs(struct inet6_d
25189                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25190                         if (++ip_idx < s_ip_idx)
25191                                 continue;
25192 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25193 +                                       continue;
25194                         err = inet6_fill_ifaddr(skb, ifa,
25195                                                 NETLINK_CB(cb->skb).pid,
25196                                                 cb->nlh->nlmsg_seq,
25197 @@ -3694,6 +3708,8 @@ static int in6_dump_addrs(struct inet6_d
25198                      ifmca = ifmca->next, ip_idx++) {
25199                         if (ip_idx < s_ip_idx)
25200                                 continue;
25201 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25202 +                                       continue;
25203                         err = inet6_fill_ifmcaddr(skb, ifmca,
25204                                                   NETLINK_CB(cb->skb).pid,
25205                                                   cb->nlh->nlmsg_seq,
25206 @@ -3709,6 +3725,8 @@ static int in6_dump_addrs(struct inet6_d
25207                      ifaca = ifaca->aca_next, ip_idx++) {
25208                         if (ip_idx < s_ip_idx)
25209                                 continue;
25210 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25211 +                                       continue;
25212                         err = inet6_fill_ifacaddr(skb, ifaca,
25213                                                   NETLINK_CB(cb->skb).pid,
25214                                                   cb->nlh->nlmsg_seq,
25215 @@ -4094,6 +4112,11 @@ static int inet6_dump_ifinfo(struct sk_b
25216         struct inet6_dev *idev;
25217         struct hlist_head *head;
25218         struct hlist_node *node;
25219 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25220 +
25221 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25222 +       if (skb->sk && skb->sk->sk_vx_info)
25223 +               return skb->len; */
25224  
25225         s_h = cb->args[0];
25226         s_idx = cb->args[1];
25227 @@ -4105,6 +4128,8 @@ static int inet6_dump_ifinfo(struct sk_b
25228                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25229                         if (idx < s_idx)
25230                                 goto cont;
25231 +                       if (!v6_dev_in_nx_info(dev, nxi))
25232 +                               goto cont;
25233                         idev = __in6_dev_get(dev);
25234                         if (!idev)
25235                                 goto cont;
25236 diff -NurpP --minimal linux-3.3.1/net/ipv6/af_inet6.c linux-3.3.1-vs2.3.3.2/net/ipv6/af_inet6.c
25237 --- linux-3.3.1/net/ipv6/af_inet6.c     2012-03-19 19:47:33.000000000 +0100
25238 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/af_inet6.c   2012-02-24 04:23:27.000000000 +0100
25239 @@ -42,6 +42,8 @@
25240  #include <linux/netdevice.h>
25241  #include <linux/icmpv6.h>
25242  #include <linux/netfilter_ipv6.h>
25243 +#include <linux/vs_inet.h>
25244 +#include <linux/vs_inet6.h>
25245  
25246  #include <net/ip.h>
25247  #include <net/ipv6.h>
25248 @@ -160,9 +162,12 @@ lookup_protocol:
25249         }
25250  
25251         err = -EPERM;
25252 +       if ((protocol == IPPROTO_ICMPV6) &&
25253 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25254 +               goto override;
25255         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25256                 goto out_rcu_unlock;
25257 -
25258 +override:
25259         sock->ops = answer->ops;
25260         answer_prot = answer->prot;
25261         answer_no_check = answer->no_check;
25262 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25263         struct inet_sock *inet = inet_sk(sk);
25264         struct ipv6_pinfo *np = inet6_sk(sk);
25265         struct net *net = sock_net(sk);
25266 +       struct nx_v6_sock_addr nsa;
25267         __be32 v4addr = 0;
25268         unsigned short snum;
25269         int addr_type = 0;
25270 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25271         if (addr->sin6_family != AF_INET6)
25272                 return -EAFNOSUPPORT;
25273  
25274 +       err = v6_map_sock_addr(inet, addr, &nsa);
25275 +       if (err)
25276 +               return err;
25277 +
25278         addr_type = ipv6_addr_type(&addr->sin6_addr);
25279         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25280                 return -EINVAL;
25281 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25282                 /* Reproduce AF_INET checks to make the bindings consistent */
25283                 v4addr = addr->sin6_addr.s6_addr32[3];
25284                 chk_addr_ret = inet_addr_type(net, v4addr);
25285 +
25286                 if (!sysctl_ip_nonlocal_bind &&
25287                     !(inet->freebind || inet->transparent) &&
25288                     v4addr != htonl(INADDR_ANY) &&
25289 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25290                         err = -EADDRNOTAVAIL;
25291                         goto out;
25292                 }
25293 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25294 +                       err = -EADDRNOTAVAIL;
25295 +                       goto out;
25296 +               }
25297         } else {
25298                 if (addr_type != IPV6_ADDR_ANY) {
25299                         struct net_device *dev = NULL;
25300 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25301                                 }
25302                         }
25303  
25304 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25305 +                               err = -EADDRNOTAVAIL;
25306 +                               goto out;
25307 +                       }
25308 +
25309                         /* ipv4 addr of the socket is invalid.  Only the
25310                          * unspecified and mapped address have a v4 equivalent.
25311                          */
25312 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25313                 }
25314         }
25315  
25316 +       /* what's that for? */
25317 +       v6_set_sock_addr(inet, &nsa);
25318 +
25319         inet->inet_rcv_saddr = v4addr;
25320         inet->inet_saddr = v4addr;
25321  
25322 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25323                         return -ENOTCONN;
25324                 sin->sin6_port = inet->inet_dport;
25325                 sin->sin6_addr = np->daddr;
25326 +               /* FIXME: remap lback? */
25327                 if (np->sndflow)
25328                         sin->sin6_flowinfo = np->flow_label;
25329         } else {
25330 +               /* FIXME: remap lback? */
25331                 if (ipv6_addr_any(&np->rcv_saddr))
25332                         sin->sin6_addr = np->saddr;
25333                 else
25334 diff -NurpP --minimal linux-3.3.1/net/ipv6/datagram.c linux-3.3.1-vs2.3.3.2/net/ipv6/datagram.c
25335 --- linux-3.3.1/net/ipv6/datagram.c     2012-03-19 19:47:33.000000000 +0100
25336 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/datagram.c   2012-02-24 03:55:07.000000000 +0100
25337 @@ -642,7 +642,7 @@ int datagram_send_ctl(struct net *net, s
25338  
25339                         rcu_read_lock();
25340                         if (fl6->flowi6_oif) {
25341 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25342 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25343                                 if (!dev) {
25344                                         rcu_read_unlock();
25345                                         return -ENODEV;
25346 diff -NurpP --minimal linux-3.3.1/net/ipv6/fib6_rules.c linux-3.3.1-vs2.3.3.2/net/ipv6/fib6_rules.c
25347 --- linux-3.3.1/net/ipv6/fib6_rules.c   2012-03-19 19:47:33.000000000 +0100
25348 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/fib6_rules.c 2012-02-24 03:55:07.000000000 +0100
25349 @@ -91,7 +91,7 @@ static int fib6_rule_action(struct fib_r
25350                                                ip6_dst_idev(&rt->dst)->dev,
25351                                                &flp6->daddr,
25352                                                rt6_flags2srcprefs(flags),
25353 -                                              &saddr))
25354 +                                              &saddr, NULL))
25355                                 goto again;
25356                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25357                                                r->src.plen))
25358 diff -NurpP --minimal linux-3.3.1/net/ipv6/inet6_hashtables.c linux-3.3.1-vs2.3.3.2/net/ipv6/inet6_hashtables.c
25359 --- linux-3.3.1/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25360 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/inet6_hashtables.c   2012-02-24 03:55:07.000000000 +0100
25361 @@ -16,6 +16,7 @@
25362  
25363  #include <linux/module.h>
25364  #include <linux/random.h>
25365 +#include <linux/vs_inet6.h>
25366  
25367  #include <net/inet_connection_sock.h>
25368  #include <net/inet_hashtables.h>
25369 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25370         unsigned int slot = hash & hashinfo->ehash_mask;
25371         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25372  
25373 -
25374         rcu_read_lock();
25375  begin:
25376         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25377 @@ -95,7 +95,7 @@ begin:
25378                                 sock_put(sk);
25379                                 goto begin;
25380                         }
25381 -               goto out;
25382 +                       goto out;
25383                 }
25384         }
25385         if (get_nulls_value(node) != slot)
25386 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25387                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25388                                 return -1;
25389                         score++;
25390 +               } else {
25391 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25392 +                               return -1;
25393                 }
25394                 if (sk->sk_bound_dev_if) {
25395                         if (sk->sk_bound_dev_if != dif)
25396 diff -NurpP --minimal linux-3.3.1/net/ipv6/ip6_output.c linux-3.3.1-vs2.3.3.2/net/ipv6/ip6_output.c
25397 --- linux-3.3.1/net/ipv6/ip6_output.c   2012-04-03 03:01:26.000000000 +0200
25398 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/ip6_output.c 2012-04-03 03:02:13.000000000 +0200
25399 @@ -968,7 +968,8 @@ static int ip6_dst_lookup_tail(struct so
25400                 struct rt6_info *rt = (struct rt6_info *) *dst;
25401                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25402                                           sk ? inet6_sk(sk)->srcprefs : 0,
25403 -                                         &fl6->saddr);
25404 +                                         &fl6->saddr,
25405 +                                         sk ? sk->sk_nx_info : NULL);
25406                 if (err)
25407                         goto out_err_release;
25408         }
25409 diff -NurpP --minimal linux-3.3.1/net/ipv6/ndisc.c linux-3.3.1-vs2.3.3.2/net/ipv6/ndisc.c
25410 --- linux-3.3.1/net/ipv6/ndisc.c        2012-03-19 19:47:33.000000000 +0100
25411 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/ndisc.c      2012-03-19 20:52:10.000000000 +0100
25412 @@ -575,7 +575,7 @@ static void ndisc_send_na(struct net_dev
25413         } else {
25414                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25415                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25416 -                                      &tmpaddr))
25417 +                                      &tmpaddr, NULL))
25418                         return;
25419                 src_addr = &tmpaddr;
25420         }
25421 diff -NurpP --minimal linux-3.3.1/net/ipv6/raw.c linux-3.3.1-vs2.3.3.2/net/ipv6/raw.c
25422 --- linux-3.3.1/net/ipv6/raw.c  2012-03-19 19:47:33.000000000 +0100
25423 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/raw.c        2012-02-24 03:55:07.000000000 +0100
25424 @@ -30,6 +30,7 @@
25425  #include <linux/icmpv6.h>
25426  #include <linux/netfilter.h>
25427  #include <linux/netfilter_ipv6.h>
25428 +#include <linux/vs_inet6.h>
25429  #include <linux/skbuff.h>
25430  #include <linux/compat.h>
25431  #include <asm/uaccess.h>
25432 @@ -285,6 +286,13 @@ static int rawv6_bind(struct sock *sk, s
25433                                 goto out_unlock;
25434                 }
25435  
25436 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25437 +                       err = -EADDRNOTAVAIL;
25438 +                       if (dev)
25439 +                               dev_put(dev);
25440 +                       goto out;
25441 +               }
25442 +
25443                 /* ipv4 addr of the socket is invalid.  Only the
25444                  * unspecified and mapped address have a v4 equivalent.
25445                  */
25446 diff -NurpP --minimal linux-3.3.1/net/ipv6/route.c linux-3.3.1-vs2.3.3.2/net/ipv6/route.c
25447 --- linux-3.3.1/net/ipv6/route.c        2012-04-03 03:01:26.000000000 +0200
25448 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/route.c      2012-04-03 03:02:13.000000000 +0200
25449 @@ -55,6 +55,7 @@
25450  #include <net/xfrm.h>
25451  #include <net/netevent.h>
25452  #include <net/netlink.h>
25453 +#include <linux/vs_inet6.h>
25454  
25455  #include <asm/uaccess.h>
25456  
25457 @@ -2107,15 +2108,17 @@ int ip6_route_get_saddr(struct net *net,
25458                         struct rt6_info *rt,
25459                         const struct in6_addr *daddr,
25460                         unsigned int prefs,
25461 -                       struct in6_addr *saddr)
25462 +                       struct in6_addr *saddr,
25463 +                       struct nx_info *nxi)
25464  {
25465         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25466         int err = 0;
25467 -       if (rt->rt6i_prefsrc.plen)
25468 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25469 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25470                 *saddr = rt->rt6i_prefsrc.addr;
25471         else
25472                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25473 -                                        daddr, prefs, saddr);
25474 +                                        daddr, prefs, saddr, nxi);
25475         return err;
25476  }
25477  
25478 @@ -2446,7 +2449,8 @@ static int rt6_fill_node(struct net *net
25479                         NLA_PUT_U32(skb, RTA_IIF, iif);
25480         } else if (dst) {
25481                 struct in6_addr saddr_buf;
25482 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25483 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25484 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25485                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25486         }
25487  
25488 @@ -2660,6 +2664,7 @@ static int rt6_info_route(struct rt6_inf
25489         struct seq_file *m = p_arg;
25490         struct neighbour *n;
25491  
25492 +       /* FIXME: check for network context? */
25493         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25494  
25495  #ifdef CONFIG_IPV6_SUBTREES
25496 diff -NurpP --minimal linux-3.3.1/net/ipv6/tcp_ipv6.c linux-3.3.1-vs2.3.3.2/net/ipv6/tcp_ipv6.c
25497 --- linux-3.3.1/net/ipv6/tcp_ipv6.c     2012-03-19 19:47:33.000000000 +0100
25498 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/tcp_ipv6.c   2012-02-24 03:55:07.000000000 +0100
25499 @@ -71,6 +71,7 @@
25500  
25501  #include <linux/crypto.h>
25502  #include <linux/scatterlist.h>
25503 +#include <linux/vs_inet6.h>
25504  
25505  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25506  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25507 @@ -163,8 +164,15 @@ static int tcp_v6_connect(struct sock *s
25508          *      connect() to INADDR_ANY means loopback (BSD'ism).
25509          */
25510  
25511 -       if(ipv6_addr_any(&usin->sin6_addr))
25512 -               usin->sin6_addr.s6_addr[15] = 0x1;
25513 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25514 +               struct nx_info *nxi =  sk->sk_nx_info;
25515 +
25516 +               if (nxi && nx_info_has_v6(nxi))
25517 +                       /* FIXME: remap lback? */
25518 +                       usin->sin6_addr = nxi->v6.ip;
25519 +               else
25520 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25521 +       }
25522  
25523         addr_type = ipv6_addr_type(&usin->sin6_addr);
25524  
25525 diff -NurpP --minimal linux-3.3.1/net/ipv6/udp.c linux-3.3.1-vs2.3.3.2/net/ipv6/udp.c
25526 --- linux-3.3.1/net/ipv6/udp.c  2012-03-19 19:47:33.000000000 +0100
25527 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/udp.c        2012-02-24 03:55:07.000000000 +0100
25528 @@ -45,41 +45,67 @@
25529  #include <net/tcp_states.h>
25530  #include <net/ip6_checksum.h>
25531  #include <net/xfrm.h>
25532 +#include <linux/vs_inet6.h>
25533  
25534  #include <linux/proc_fs.h>
25535  #include <linux/seq_file.h>
25536  #include "udp_impl.h"
25537  
25538 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25539 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25540  {
25541 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25542 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25543         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25544 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25545 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25546         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25547 -       int sk_ipv6only = ipv6_only_sock(sk);
25548 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25549         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25550 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25551 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25552         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25553  
25554         /* if both are mapped, treat as IPv4 */
25555 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25556 -               return (!sk2_ipv6only &&
25557 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25558 +               if (!sk2_ipv6only &&
25559                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25560 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25561 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25562 +                       goto vs_v4;
25563 +               else
25564 +                       return 0;
25565 +       }
25566  
25567         if (addr_type2 == IPV6_ADDR_ANY &&
25568             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25569 -               return 1;
25570 +               goto vs;
25571  
25572         if (addr_type == IPV6_ADDR_ANY &&
25573 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25574 -               return 1;
25575 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25576 +               goto vs;
25577  
25578         if (sk2_rcv_saddr6 &&
25579 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25580 -               return 1;
25581 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25582 +               goto vs;
25583  
25584         return 0;
25585 +
25586 +vs_v4:
25587 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25588 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25589 +       if (!sk2_rcv_saddr)
25590 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25591 +       if (!sk1_rcv_saddr)
25592 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25593 +       return 1;
25594 +vs:
25595 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25596 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25597 +       else if (addr_type2 == IPV6_ADDR_ANY)
25598 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25599 +       else if (addr_type == IPV6_ADDR_ANY) {
25600 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25601 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25602 +               else
25603 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25604 +       }
25605 +       return 1;
25606  }
25607  
25608  static unsigned int udp6_portaddr_hash(struct net *net,
25609 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25610                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25611                                 return -1;
25612                         score++;
25613 +               } else {
25614 +                       /* block non nx_info ips */
25615 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25616 +                               return -1;
25617                 }
25618                 if (!ipv6_addr_any(&np->daddr)) {
25619                         if (!ipv6_addr_equal(&np->daddr, saddr))
25620 diff -NurpP --minimal linux-3.3.1/net/ipv6/xfrm6_policy.c linux-3.3.1-vs2.3.3.2/net/ipv6/xfrm6_policy.c
25621 --- linux-3.3.1/net/ipv6/xfrm6_policy.c 2012-03-19 19:47:33.000000000 +0100
25622 +++ linux-3.3.1-vs2.3.3.2/net/ipv6/xfrm6_policy.c       2012-02-24 03:55:07.000000000 +0100
25623 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25624         dev = ip6_dst_idev(dst)->dev;
25625         ipv6_dev_get_saddr(dev_net(dev), dev,
25626                            (struct in6_addr *)&daddr->a6, 0,
25627 -                          (struct in6_addr *)&saddr->a6);
25628 +                          (struct in6_addr *)&saddr->a6, NULL);
25629         dst_release(dst);
25630         return 0;
25631  }
25632 diff -NurpP --minimal linux-3.3.1/net/netfilter/ipvs/ip_vs_xmit.c linux-3.3.1-vs2.3.3.2/net/netfilter/ipvs/ip_vs_xmit.c
25633 --- linux-3.3.1/net/netfilter/ipvs/ip_vs_xmit.c 2012-03-19 19:47:33.000000000 +0100
25634 +++ linux-3.3.1-vs2.3.3.2/net/netfilter/ipvs/ip_vs_xmit.c       2012-02-24 03:55:07.000000000 +0100
25635 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25636                 return dst;
25637         if (ipv6_addr_any(&fl6.saddr) &&
25638             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25639 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25640 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25641                 goto out_err;
25642         if (do_xfrm) {
25643                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25644 diff -NurpP --minimal linux-3.3.1/net/netlink/af_netlink.c linux-3.3.1-vs2.3.3.2/net/netlink/af_netlink.c
25645 --- linux-3.3.1/net/netlink/af_netlink.c        2012-03-19 19:47:33.000000000 +0100
25646 +++ linux-3.3.1-vs2.3.3.2/net/netlink/af_netlink.c      2012-02-24 03:55:07.000000000 +0100
25647 @@ -55,6 +55,9 @@
25648  #include <linux/types.h>
25649  #include <linux/audit.h>
25650  #include <linux/mutex.h>
25651 +#include <linux/vs_context.h>
25652 +#include <linux/vs_network.h>
25653 +#include <linux/vs_limit.h>
25654  
25655  #include <net/net_namespace.h>
25656  #include <net/sock.h>
25657 @@ -1908,6 +1911,8 @@ static struct sock *netlink_seq_socket_i
25658                         sk_for_each(s, node, &hash->table[j]) {
25659                                 if (sock_net(s) != seq_file_net(seq))
25660                                         continue;
25661 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25662 +                                       continue;
25663                                 if (off == pos) {
25664                                         iter->link = i;
25665                                         iter->hash_idx = j;
25666 @@ -1942,7 +1947,8 @@ static void *netlink_seq_next(struct seq
25667         s = v;
25668         do {
25669                 s = sk_next(s);
25670 -       } while (s && sock_net(s) != seq_file_net(seq));
25671 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25672 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25673         if (s)
25674                 return s;
25675  
25676 @@ -1954,7 +1960,8 @@ static void *netlink_seq_next(struct seq
25677  
25678                 for (; j <= hash->mask; j++) {
25679                         s = sk_head(&hash->table[j]);
25680 -                       while (s && sock_net(s) != seq_file_net(seq))
25681 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25682 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25683                                 s = sk_next(s);
25684                         if (s) {
25685                                 iter->link = i;
25686 diff -NurpP --minimal linux-3.3.1/net/socket.c linux-3.3.1-vs2.3.3.2/net/socket.c
25687 --- linux-3.3.1/net/socket.c    2012-03-19 19:47:33.000000000 +0100
25688 +++ linux-3.3.1-vs2.3.3.2/net/socket.c  2012-02-24 03:55:07.000000000 +0100
25689 @@ -98,6 +98,10 @@
25690  
25691  #include <net/sock.h>
25692  #include <linux/netfilter.h>
25693 +#include <linux/vs_base.h>
25694 +#include <linux/vs_socket.h>
25695 +#include <linux/vs_inet.h>
25696 +#include <linux/vs_inet6.h>
25697  
25698  #include <linux/if_tun.h>
25699  #include <linux/ipv6_route.h>
25700 @@ -548,6 +552,7 @@ static inline int __sock_sendmsg_nosec(s
25701                                        struct msghdr *msg, size_t size)
25702  {
25703         struct sock_iocb *si = kiocb_to_siocb(iocb);
25704 +       size_t len;
25705  
25706         sock_update_classid(sock->sk);
25707  
25708 @@ -558,7 +563,22 @@ static inline int __sock_sendmsg_nosec(s
25709         si->msg = msg;
25710         si->size = size;
25711  
25712 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25713 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25714 +       if (sock->sk) {
25715 +               if (len == size)
25716 +                       vx_sock_send(sock->sk, size);
25717 +               else
25718 +                       vx_sock_fail(sock->sk, size);
25719 +       }
25720 +       vxdprintk(VXD_CBIT(net, 7),
25721 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25722 +               sock, sock->sk,
25723 +               (sock->sk)?sock->sk->sk_nx_info:0,
25724 +               (sock->sk)?sock->sk->sk_vx_info:0,
25725 +               (sock->sk)?sock->sk->sk_xid:0,
25726 +               (sock->sk)?sock->sk->sk_nid:0,
25727 +               (unsigned int)size, len);
25728 +       return len;
25729  }
25730  
25731  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25732 @@ -714,6 +734,7 @@ static inline int __sock_recvmsg_nosec(s
25733                                        struct msghdr *msg, size_t size, int flags)
25734  {
25735         struct sock_iocb *si = kiocb_to_siocb(iocb);
25736 +       int len;
25737  
25738         sock_update_classid(sock->sk);
25739  
25740 @@ -723,7 +744,18 @@ static inline int __sock_recvmsg_nosec(s
25741         si->size = size;
25742         si->flags = flags;
25743  
25744 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25745 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25746 +       if ((len >= 0) && sock->sk)
25747 +               vx_sock_recv(sock->sk, len);
25748 +       vxdprintk(VXD_CBIT(net, 7),
25749 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25750 +               sock, sock->sk,
25751 +               (sock->sk)?sock->sk->sk_nx_info:0,
25752 +               (sock->sk)?sock->sk->sk_vx_info:0,
25753 +               (sock->sk)?sock->sk->sk_xid:0,
25754 +               (sock->sk)?sock->sk->sk_nid:0,
25755 +               (unsigned int)size, len);
25756 +       return len;
25757  }
25758  
25759  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25760 @@ -1208,6 +1240,13 @@ int __sock_create(struct net *net, int f
25761         if (type < 0 || type >= SOCK_MAX)
25762                 return -EINVAL;
25763  
25764 +       if (!nx_check(0, VS_ADMIN)) {
25765 +               if (family == PF_INET && !current_nx_info_has_v4())
25766 +                       return -EAFNOSUPPORT;
25767 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25768 +                       return -EAFNOSUPPORT;
25769 +       }
25770 +
25771         /* Compatibility.
25772  
25773            This uglymoron is moved from INET layer to here to avoid
25774 @@ -1343,6 +1382,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25775         if (retval < 0)
25776                 goto out;
25777  
25778 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25779         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25780         if (retval < 0)
25781                 goto out_release;
25782 @@ -1384,10 +1424,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25783         err = sock_create(family, type, protocol, &sock1);
25784         if (err < 0)
25785                 goto out;
25786 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25787  
25788         err = sock_create(family, type, protocol, &sock2);
25789         if (err < 0)
25790                 goto out_release_1;
25791 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25792  
25793         err = sock1->ops->socketpair(sock1, sock2);
25794         if (err < 0)
25795 diff -NurpP --minimal linux-3.3.1/net/sunrpc/auth.c linux-3.3.1-vs2.3.3.2/net/sunrpc/auth.c
25796 --- linux-3.3.1/net/sunrpc/auth.c       2011-10-24 18:45:34.000000000 +0200
25797 +++ linux-3.3.1-vs2.3.3.2/net/sunrpc/auth.c     2012-02-24 03:55:07.000000000 +0100
25798 @@ -14,6 +14,7 @@
25799  #include <linux/hash.h>
25800  #include <linux/sunrpc/clnt.h>
25801  #include <linux/spinlock.h>
25802 +#include <linux/vs_tag.h>
25803  
25804  #ifdef RPC_DEBUG
25805  # define RPCDBG_FACILITY       RPCDBG_AUTH
25806 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25807         memset(&acred, 0, sizeof(acred));
25808         acred.uid = cred->fsuid;
25809         acred.gid = cred->fsgid;
25810 +       acred.tag = dx_current_tag();
25811         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25812  
25813         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25814 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25815         struct auth_cred acred = {
25816                 .uid = 0,
25817                 .gid = 0,
25818 +               .tag = dx_current_tag(),
25819         };
25820  
25821         dprintk("RPC: %5u looking up %s cred\n",
25822 diff -NurpP --minimal linux-3.3.1/net/sunrpc/auth_unix.c linux-3.3.1-vs2.3.3.2/net/sunrpc/auth_unix.c
25823 --- linux-3.3.1/net/sunrpc/auth_unix.c  2012-01-09 16:15:04.000000000 +0100
25824 +++ linux-3.3.1-vs2.3.3.2/net/sunrpc/auth_unix.c        2012-02-24 03:55:07.000000000 +0100
25825 @@ -12,12 +12,14 @@
25826  #include <linux/module.h>
25827  #include <linux/sunrpc/clnt.h>
25828  #include <linux/sunrpc/auth.h>
25829 +#include <linux/vs_tag.h>
25830  
25831  #define NFS_NGROUPS    16
25832  
25833  struct unx_cred {
25834         struct rpc_cred         uc_base;
25835         gid_t                   uc_gid;
25836 +       tag_t                   uc_tag;
25837         gid_t                   uc_gids[NFS_NGROUPS];
25838  };
25839  #define uc_uid                 uc_base.cr_uid
25840 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
25841                 groups = NFS_NGROUPS;
25842  
25843         cred->uc_gid = acred->gid;
25844 +       cred->uc_tag = acred->tag;
25845         for (i = 0; i < groups; i++)
25846                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25847         if (i < NFS_NGROUPS)
25848 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
25849         unsigned int i;
25850  
25851  
25852 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25853 +       if (cred->uc_uid != acred->uid ||
25854 +               cred->uc_gid != acred->gid ||
25855 +               cred->uc_tag != acred->tag)
25856                 return 0;
25857  
25858         if (acred->group_info != NULL)
25859 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
25860         struct rpc_clnt *clnt = task->tk_client;
25861         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25862         __be32          *base, *hold;
25863 -       int             i;
25864 +       int             i, tag;
25865  
25866         *p++ = htonl(RPC_AUTH_UNIX);
25867         base = p++;
25868 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
25869          * Copy the UTS nodename captured when the client was created.
25870          */
25871         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25872 +       tag = task->tk_client->cl_tag;
25873  
25874 -       *p++ = htonl((u32) cred->uc_uid);
25875 -       *p++ = htonl((u32) cred->uc_gid);
25876 +       *p++ = htonl((u32) TAGINO_UID(tag,
25877 +               cred->uc_uid, cred->uc_tag));
25878 +       *p++ = htonl((u32) TAGINO_GID(tag,
25879 +               cred->uc_gid, cred->uc_tag));
25880         hold = p++;
25881         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25882                 *p++ = htonl((u32) cred->uc_gids[i]);
25883 diff -NurpP --minimal linux-3.3.1/net/sunrpc/clnt.c linux-3.3.1-vs2.3.3.2/net/sunrpc/clnt.c
25884 --- linux-3.3.1/net/sunrpc/clnt.c       2012-01-09 16:15:04.000000000 +0100
25885 +++ linux-3.3.1-vs2.3.3.2/net/sunrpc/clnt.c     2012-02-24 03:55:07.000000000 +0100
25886 @@ -31,6 +31,7 @@
25887  #include <linux/in.h>
25888  #include <linux/in6.h>
25889  #include <linux/un.h>
25890 +#include <linux/vs_cvirt.h>
25891  
25892  #include <linux/sunrpc/clnt.h>
25893  #include <linux/sunrpc/rpc_pipe_fs.h>
25894 @@ -361,6 +362,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25895         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25896                 clnt->cl_chatty = 1;
25897  
25898 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25899 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25900 +               clnt->cl_tag = 1; */
25901         return clnt;
25902  }
25903  EXPORT_SYMBOL_GPL(rpc_create);
25904 diff -NurpP --minimal linux-3.3.1/net/unix/af_unix.c linux-3.3.1-vs2.3.3.2/net/unix/af_unix.c
25905 --- linux-3.3.1/net/unix/af_unix.c      2012-03-19 19:47:34.000000000 +0100
25906 +++ linux-3.3.1-vs2.3.3.2/net/unix/af_unix.c    2012-02-24 03:55:07.000000000 +0100
25907 @@ -114,6 +114,8 @@
25908  #include <linux/mount.h>
25909  #include <net/checksum.h>
25910  #include <linux/security.h>
25911 +#include <linux/vs_context.h>
25912 +#include <linux/vs_limit.h>
25913  
25914  struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
25915  EXPORT_SYMBOL_GPL(unix_socket_table);
25916 @@ -261,6 +263,8 @@ static struct sock *__unix_find_socket_b
25917                 if (!net_eq(sock_net(s), net))
25918                         continue;
25919  
25920 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25921 +                       continue;
25922                 if (u->addr->len == len &&
25923                     !memcmp(u->addr->name, sunname, len))
25924                         goto found;
25925 @@ -2235,6 +2239,8 @@ static struct sock *unix_seq_idx(struct 
25926         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
25927                 if (sock_net(s) != seq_file_net(seq))
25928                         continue;
25929 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25930 +                       continue;
25931                 if (off == pos)
25932                         return s;
25933                 ++off;
25934 @@ -2259,7 +2265,8 @@ static void *unix_seq_next(struct seq_fi
25935                 sk = first_unix_socket(&iter->i);
25936         else
25937                 sk = next_unix_socket(&iter->i, sk);
25938 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
25939 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
25940 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
25941                 sk = next_unix_socket(&iter->i, sk);
25942         return sk;
25943  }
25944 diff -NurpP --minimal linux-3.3.1/scripts/checksyscalls.sh linux-3.3.1-vs2.3.3.2/scripts/checksyscalls.sh
25945 --- linux-3.3.1/scripts/checksyscalls.sh        2012-03-19 19:47:34.000000000 +0100
25946 +++ linux-3.3.1-vs2.3.3.2/scripts/checksyscalls.sh      2012-02-24 03:55:07.000000000 +0100
25947 @@ -193,7 +193,6 @@ cat << EOF
25948  #define __IGNORE_afs_syscall
25949  #define __IGNORE_getpmsg
25950  #define __IGNORE_putpmsg
25951 -#define __IGNORE_vserver
25952  EOF
25953  }
25954  
25955 diff -NurpP --minimal linux-3.3.1/security/commoncap.c linux-3.3.1-vs2.3.3.2/security/commoncap.c
25956 --- linux-3.3.1/security/commoncap.c    2012-03-19 19:47:34.000000000 +0100
25957 +++ linux-3.3.1-vs2.3.3.2/security/commoncap.c  2012-02-24 18:08:52.000000000 +0100
25958 @@ -74,14 +74,20 @@ int cap_netlink_send(struct sock *sk, st
25959  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25960                 int cap, int audit)
25961  {
25962 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25963 +
25964         for (;;) {
25965                 /* The creator of the user namespace has all caps. */
25966                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
25967                         return 0;
25968  
25969                 /* Do we have the necessary capabilities? */
25970 -               if (targ_ns == cred->user->user_ns)
25971 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25972 +               if (targ_ns == cred->user->user_ns) {
25973 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25974 +                           cap_raised(cred->cap_effective, cap))
25975 +                               return 0;
25976 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25977 +               }
25978  
25979                 /* Have we tried all of the parent namespaces? */
25980                 if (targ_ns == &init_user_ns)
25981 @@ -605,7 +611,7 @@ int cap_inode_setxattr(struct dentry *de
25982  
25983         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25984                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25985 -           !capable(CAP_SYS_ADMIN))
25986 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25987                 return -EPERM;
25988         return 0;
25989  }
25990 @@ -631,7 +637,7 @@ int cap_inode_removexattr(struct dentry 
25991  
25992         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25993                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25994 -           !capable(CAP_SYS_ADMIN))
25995 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25996                 return -EPERM;
25997         return 0;
25998  }
25999 diff -NurpP --minimal linux-3.3.1/security/selinux/hooks.c linux-3.3.1-vs2.3.3.2/security/selinux/hooks.c
26000 --- linux-3.3.1/security/selinux/hooks.c        2012-03-19 19:47:34.000000000 +0100
26001 +++ linux-3.3.1-vs2.3.3.2/security/selinux/hooks.c      2012-02-24 03:55:07.000000000 +0100
26002 @@ -67,7 +67,6 @@
26003  #include <linux/dccp.h>
26004  #include <linux/quota.h>
26005  #include <linux/un.h>          /* for Unix socket types */
26006 -#include <net/af_unix.h>       /* for Unix socket types */
26007  #include <linux/parser.h>
26008  #include <linux/nfs_mount.h>
26009  #include <net/ipv6.h>
This page took 6.243916 seconds and 4 git commands to generate.