]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- updated to 3.4.40
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.4.32/Documentation/vserver/debug.txt linux-3.4.32-vs2.3.3.9/Documentation/vserver/debug.txt
2 --- linux-3.4.32/Documentation/vserver/debug.txt        1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.4.32-vs2.3.3.9/Documentation/vserver/debug.txt      2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/alpha/Kconfig linux-3.4.32-vs2.3.3.9/arch/alpha/Kconfig
160 --- linux-3.4.32/arch/alpha/Kconfig     2012-05-21 16:06:12.000000000 +0000
161 +++ linux-3.4.32-vs2.3.3.9/arch/alpha/Kconfig   2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/alpha/kernel/entry.S linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/entry.S
172 --- linux-3.4.32/arch/alpha/kernel/entry.S      2010-10-21 11:06:45.000000000 +0000
173 +++ linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/entry.S    2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/alpha/kernel/ptrace.c linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/ptrace.c
207 --- linux-3.4.32/arch/alpha/kernel/ptrace.c     2012-05-21 16:06:12.000000000 +0000
208 +++ linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/ptrace.c   2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/alpha/kernel/systbls.S linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/systbls.S
218 --- linux-3.4.32/arch/alpha/kernel/systbls.S    2012-01-09 15:13:54.000000000 +0000
219 +++ linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/systbls.S  2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/alpha/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/traps.c
230 --- linux-3.4.32/arch/alpha/kernel/traps.c      2012-05-21 16:06:12.000000000 +0000
231 +++ linux-3.4.32-vs2.3.3.9/arch/alpha/kernel/traps.c    2012-05-21 16:15:04.000000000 +0000
232 @@ -184,7 +184,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.4.32/arch/arm/Kconfig linux-3.4.32-vs2.3.3.9/arch/arm/Kconfig
243 --- linux-3.4.32/arch/arm/Kconfig       2013-02-19 13:55:11.000000000 +0000
244 +++ linux-3.4.32-vs2.3.3.9/arch/arm/Kconfig     2012-12-11 11:42:38.000000000 +0000
245 @@ -2311,6 +2311,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.4.32/arch/arm/kernel/calls.S linux-3.4.32-vs2.3.3.9/arch/arm/kernel/calls.S
255 --- linux-3.4.32/arch/arm/kernel/calls.S        2012-01-09 15:13:54.000000000 +0000
256 +++ linux-3.4.32-vs2.3.3.9/arch/arm/kernel/calls.S      2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/arm/kernel/process.c linux-3.4.32-vs2.3.3.9/arch/arm/kernel/process.c
267 --- linux-3.4.32/arch/arm/kernel/process.c      2013-02-19 13:55:11.000000000 +0000
268 +++ linux-3.4.32-vs2.3.3.9/arch/arm/kernel/process.c    2012-09-01 08:50:48.000000000 +0000
269 @@ -357,7 +357,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.4.32/arch/arm/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/arm/kernel/traps.c
280 --- linux-3.4.32/arch/arm/kernel/traps.c        2013-02-19 13:55:11.000000000 +0000
281 +++ linux-3.4.32-vs2.3.3.9/arch/arm/kernel/traps.c      2012-10-22 13:09:53.000000000 +0000
282 @@ -249,8 +249,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.4.32/arch/cris/Kconfig linux-3.4.32-vs2.3.3.9/arch/cris/Kconfig
294 --- linux-3.4.32/arch/cris/Kconfig      2012-03-19 18:46:39.000000000 +0000
295 +++ linux-3.4.32-vs2.3.3.9/arch/cris/Kconfig    2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/frv/kernel/kernel_thread.S linux-3.4.32-vs2.3.3.9/arch/frv/kernel/kernel_thread.S
306 --- linux-3.4.32/arch/frv/kernel/kernel_thread.S        2008-12-24 23:26:37.000000000 +0000
307 +++ linux-3.4.32-vs2.3.3.9/arch/frv/kernel/kernel_thread.S      2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/h8300/Kconfig linux-3.4.32-vs2.3.3.9/arch/h8300/Kconfig
318 --- linux-3.4.32/arch/h8300/Kconfig     2012-03-19 18:46:39.000000000 +0000
319 +++ linux-3.4.32-vs2.3.3.9/arch/h8300/Kconfig   2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/ia64/Kconfig linux-3.4.32-vs2.3.3.9/arch/ia64/Kconfig
330 --- linux-3.4.32/arch/ia64/Kconfig      2012-03-19 18:46:39.000000000 +0000
331 +++ linux-3.4.32-vs2.3.3.9/arch/ia64/Kconfig    2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/ia64/kernel/entry.S linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/entry.S
342 --- linux-3.4.32/arch/ia64/kernel/entry.S       2012-03-19 18:46:40.000000000 +0000
343 +++ linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/entry.S     2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/ia64/kernel/process.c linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/process.c
354 --- linux-3.4.32/arch/ia64/kernel/process.c     2013-02-19 13:55:12.000000000 +0000
355 +++ linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/process.c   2012-10-22 13:09:53.000000000 +0000
356 @@ -111,8 +111,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.4.32/arch/ia64/kernel/ptrace.c linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/ptrace.c
368 --- linux-3.4.32/arch/ia64/kernel/ptrace.c      2012-05-21 16:06:26.000000000 +0000
369 +++ linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/ptrace.c    2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/ia64/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/traps.c
379 --- linux-3.4.32/arch/ia64/kernel/traps.c       2012-05-21 16:06:26.000000000 +0000
380 +++ linux-3.4.32-vs2.3.3.9/arch/ia64/kernel/traps.c     2012-05-21 16:15:04.000000000 +0000
381 @@ -60,8 +60,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 @@ -324,8 +325,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.4.32/arch/m32r/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/m32r/kernel/traps.c
406 --- linux-3.4.32/arch/m32r/kernel/traps.c       2012-05-21 16:06:26.000000000 +0000
407 +++ linux-3.4.32-vs2.3.3.9/arch/m32r/kernel/traps.c     2012-05-21 16:15:04.000000000 +0000
408 @@ -195,8 +195,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.4.32/arch/m68k/Kconfig linux-3.4.32-vs2.3.3.9/arch/m68k/Kconfig
421 --- linux-3.4.32/arch/m68k/Kconfig      2012-05-21 16:06:26.000000000 +0000
422 +++ linux-3.4.32-vs2.3.3.9/arch/m68k/Kconfig    2012-05-21 16:15:04.000000000 +0000
423 @@ -146,6 +146,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.4.32/arch/mips/Kconfig linux-3.4.32-vs2.3.3.9/arch/mips/Kconfig
433 --- linux-3.4.32/arch/mips/Kconfig      2012-05-21 16:06:27.000000000 +0000
434 +++ linux-3.4.32-vs2.3.3.9/arch/mips/Kconfig    2012-05-21 16:15:04.000000000 +0000
435 @@ -2516,6 +2516,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.4.32/arch/mips/kernel/ptrace.c linux-3.4.32-vs2.3.3.9/arch/mips/kernel/ptrace.c
445 --- linux-3.4.32/arch/mips/kernel/ptrace.c      2012-05-21 16:06:27.000000000 +0000
446 +++ linux-3.4.32-vs2.3.3.9/arch/mips/kernel/ptrace.c    2012-05-21 16:15:04.000000000 +0000
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 @@ -262,6 +263,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.4.32/arch/mips/kernel/scall32-o32.S linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall32-o32.S
466 --- linux-3.4.32/arch/mips/kernel/scall32-o32.S 2012-01-09 15:14:05.000000000 +0000
467 +++ linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall32-o32.S       2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/mips/kernel/scall64-64.S linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall64-64.S
478 --- linux-3.4.32/arch/mips/kernel/scall64-64.S  2012-01-09 15:14:05.000000000 +0000
479 +++ linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall64-64.S        2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/mips/kernel/scall64-n32.S linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall64-n32.S
490 --- linux-3.4.32/arch/mips/kernel/scall64-n32.S 2012-01-09 15:14:05.000000000 +0000
491 +++ linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall64-n32.S       2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/mips/kernel/scall64-o32.S linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall64-o32.S
502 --- linux-3.4.32/arch/mips/kernel/scall64-o32.S 2012-01-09 15:14:05.000000000 +0000
503 +++ linux-3.4.32-vs2.3.3.9/arch/mips/kernel/scall64-o32.S       2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/mips/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/mips/kernel/traps.c
514 --- linux-3.4.32/arch/mips/kernel/traps.c       2012-05-21 16:06:27.000000000 +0000
515 +++ linux-3.4.32-vs2.3.3.9/arch/mips/kernel/traps.c     2012-05-21 16:15:04.000000000 +0000
516 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
517  
518         __show_regs(regs);
519         print_modules();
520 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
521 -              current->comm, current->pid, current_thread_info(), current,
522 -             field, current_thread_info()->tp_value);
523 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
524 +               current->comm, task_pid_nr(current), current->xid,
525 +               current_thread_info(), current,
526 +               field, current_thread_info()->tp_value);
527         if (cpu_has_userlocal) {
528                 unsigned long tls;
529  
530 diff -NurpP --minimal linux-3.4.32/arch/parisc/Kconfig linux-3.4.32-vs2.3.3.9/arch/parisc/Kconfig
531 --- linux-3.4.32/arch/parisc/Kconfig    2012-03-19 18:46:44.000000000 +0000
532 +++ linux-3.4.32-vs2.3.3.9/arch/parisc/Kconfig  2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/parisc/kernel/syscall_table.S linux-3.4.32-vs2.3.3.9/arch/parisc/kernel/syscall_table.S
543 --- linux-3.4.32/arch/parisc/kernel/syscall_table.S     2011-10-24 16:45:00.000000000 +0000
544 +++ linux-3.4.32-vs2.3.3.9/arch/parisc/kernel/syscall_table.S   2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/parisc/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/parisc/kernel/traps.c
555 --- linux-3.4.32/arch/parisc/kernel/traps.c     2012-05-21 16:06:28.000000000 +0000
556 +++ linux-3.4.32-vs2.3.3.9/arch/parisc/kernel/traps.c   2012-05-21 16:15:04.000000000 +0000
557 @@ -235,8 +235,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 @@ -269,8 +270,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.4.32/arch/parisc/mm/fault.c linux-3.4.32-vs2.3.3.9/arch/parisc/mm/fault.c
581 --- linux-3.4.32/arch/parisc/mm/fault.c 2010-08-02 14:52:06.000000000 +0000
582 +++ linux-3.4.32-vs2.3.3.9/arch/parisc/mm/fault.c       2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/powerpc/Kconfig linux-3.4.32-vs2.3.3.9/arch/powerpc/Kconfig
596 --- linux-3.4.32/arch/powerpc/Kconfig   2012-05-21 16:06:28.000000000 +0000
597 +++ linux-3.4.32-vs2.3.3.9/arch/powerpc/Kconfig 2012-05-21 16:15:04.000000000 +0000
598 @@ -1002,6 +1002,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.4.32/arch/powerpc/include/asm/unistd.h linux-3.4.32-vs2.3.3.9/arch/powerpc/include/asm/unistd.h
608 --- linux-3.4.32/arch/powerpc/include/asm/unistd.h      2012-01-09 15:14:05.000000000 +0000
609 +++ linux-3.4.32-vs2.3.3.9/arch/powerpc/include/asm/unistd.h    2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/powerpc/kernel/process.c linux-3.4.32-vs2.3.3.9/arch/powerpc/kernel/process.c
620 --- linux-3.4.32/arch/powerpc/kernel/process.c  2013-02-19 13:55:13.000000000 +0000
621 +++ linux-3.4.32-vs2.3.3.9/arch/powerpc/kernel/process.c        2012-09-16 18:49:11.000000000 +0000
622 @@ -661,8 +661,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.4.32/arch/powerpc/kernel/traps.c linux-3.4.32-vs2.3.3.9/arch/powerpc/kernel/traps.c
635 --- linux-3.4.32/arch/powerpc/kernel/traps.c    2013-02-19 13:55:13.000000000 +0000
636 +++ linux-3.4.32-vs2.3.3.9/arch/powerpc/kernel/traps.c  2012-09-16 18:49:11.000000000 +0000
637 @@ -1119,8 +1119,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.4.32/arch/s390/Kconfig linux-3.4.32-vs2.3.3.9/arch/s390/Kconfig
650 --- linux-3.4.32/arch/s390/Kconfig      2012-05-21 16:06:32.000000000 +0000
651 +++ linux-3.4.32-vs2.3.3.9/arch/s390/Kconfig    2012-05-21 16:15:04.000000000 +0000
652 @@ -639,6 +639,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.4.32/arch/s390/include/asm/tlb.h linux-3.4.32-vs2.3.3.9/arch/s390/include/asm/tlb.h
662 --- linux-3.4.32/arch/s390/include/asm/tlb.h    2012-05-21 16:06:32.000000000 +0000
663 +++ linux-3.4.32-vs2.3.3.9/arch/s390/include/asm/tlb.h  2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/s390/include/asm/unistd.h linux-3.4.32-vs2.3.3.9/arch/s390/include/asm/unistd.h
673 --- linux-3.4.32/arch/s390/include/asm/unistd.h 2012-03-19 18:46:48.000000000 +0000
674 +++ linux-3.4.32-vs2.3.3.9/arch/s390/include/asm/unistd.h       2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/s390/kernel/ptrace.c linux-3.4.32-vs2.3.3.9/arch/s390/kernel/ptrace.c
685 --- linux-3.4.32/arch/s390/kernel/ptrace.c      2012-05-21 16:06:32.000000000 +0000
686 +++ linux-3.4.32-vs2.3.3.9/arch/s390/kernel/ptrace.c    2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/s390/kernel/syscalls.S linux-3.4.32-vs2.3.3.9/arch/s390/kernel/syscalls.S
696 --- linux-3.4.32/arch/s390/kernel/syscalls.S    2012-01-09 15:14:06.000000000 +0000
697 +++ linux-3.4.32-vs2.3.3.9/arch/s390/kernel/syscalls.S  2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/sh/Kconfig linux-3.4.32-vs2.3.3.9/arch/sh/Kconfig
708 --- linux-3.4.32/arch/sh/Kconfig        2012-05-21 16:06:33.000000000 +0000
709 +++ linux-3.4.32-vs2.3.3.9/arch/sh/Kconfig      2012-05-21 16:15:04.000000000 +0000
710 @@ -905,6 +905,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.4.32/arch/sh/kernel/irq.c linux-3.4.32-vs2.3.3.9/arch/sh/kernel/irq.c
720 --- linux-3.4.32/arch/sh/kernel/irq.c   2011-07-22 09:17:41.000000000 +0000
721 +++ linux-3.4.32-vs2.3.3.9/arch/sh/kernel/irq.c 2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/sparc/Kconfig linux-3.4.32-vs2.3.3.9/arch/sparc/Kconfig
731 --- linux-3.4.32/arch/sparc/Kconfig     2013-02-19 13:55:17.000000000 +0000
732 +++ linux-3.4.32-vs2.3.3.9/arch/sparc/Kconfig   2012-06-08 13:57:24.000000000 +0000
733 @@ -599,6 +599,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.4.32/arch/sparc/include/asm/unistd.h linux-3.4.32-vs2.3.3.9/arch/sparc/include/asm/unistd.h
743 --- linux-3.4.32/arch/sparc/include/asm/unistd.h        2012-01-09 15:14:07.000000000 +0000
744 +++ linux-3.4.32-vs2.3.3.9/arch/sparc/include/asm/unistd.h      2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/sparc/kernel/systbls_32.S linux-3.4.32-vs2.3.3.9/arch/sparc/kernel/systbls_32.S
755 --- linux-3.4.32/arch/sparc/kernel/systbls_32.S 2012-01-09 15:14:09.000000000 +0000
756 +++ linux-3.4.32-vs2.3.3.9/arch/sparc/kernel/systbls_32.S       2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/sparc/kernel/systbls_64.S linux-3.4.32-vs2.3.3.9/arch/sparc/kernel/systbls_64.S
767 --- linux-3.4.32/arch/sparc/kernel/systbls_64.S 2013-02-19 13:55:17.000000000 +0000
768 +++ linux-3.4.32-vs2.3.3.9/arch/sparc/kernel/systbls_64.S       2012-06-08 13:57:24.000000000 +0000
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, compat_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.4.32/arch/um/Kconfig.rest linux-3.4.32-vs2.3.3.9/arch/um/Kconfig.rest
788 --- linux-3.4.32/arch/um/Kconfig.rest   2012-01-09 15:14:09.000000000 +0000
789 +++ linux-3.4.32-vs2.3.3.9/arch/um/Kconfig.rest 2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/um/include/shared/kern_constants.h linux-3.4.32-vs2.3.3.9/arch/um/include/shared/kern_constants.h
800 --- linux-3.4.32/arch/um/include/shared/kern_constants.h        1970-01-01 00:00:00.000000000 +0000
801 +++ linux-3.4.32-vs2.3.3.9/arch/um/include/shared/kern_constants.h      2012-05-21 16:15:04.000000000 +0000
802 @@ -0,0 +1 @@
803 +#include "../../../../include/generated/asm-offsets.h"
804 diff -NurpP --minimal linux-3.4.32/arch/um/include/shared/user_constants.h linux-3.4.32-vs2.3.3.9/arch/um/include/shared/user_constants.h
805 --- linux-3.4.32/arch/um/include/shared/user_constants.h        1970-01-01 00:00:00.000000000 +0000
806 +++ linux-3.4.32-vs2.3.3.9/arch/um/include/shared/user_constants.h      2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/x86/Kconfig linux-3.4.32-vs2.3.3.9/arch/x86/Kconfig
849 --- linux-3.4.32/arch/x86/Kconfig       2012-05-21 16:06:35.000000000 +0000
850 +++ linux-3.4.32-vs2.3.3.9/arch/x86/Kconfig     2012-05-21 16:15:04.000000000 +0000
851 @@ -2225,6 +2225,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.4.32/arch/x86/syscalls/syscall_32.tbl linux-3.4.32-vs2.3.3.9/arch/x86/syscalls/syscall_32.tbl
861 --- linux-3.4.32/arch/x86/syscalls/syscall_32.tbl       2012-05-21 16:06:42.000000000 +0000
862 +++ linux-3.4.32-vs2.3.3.9/arch/x86/syscalls/syscall_32.tbl     2012-05-21 16:15:04.000000000 +0000
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.4.32/arch/x86/syscalls/syscall_64.tbl linux-3.4.32-vs2.3.3.9/arch/x86/syscalls/syscall_64.tbl
873 --- linux-3.4.32/arch/x86/syscalls/syscall_64.tbl       2013-02-19 13:55:18.000000000 +0000
874 +++ linux-3.4.32-vs2.3.3.9/arch/x86/syscalls/syscall_64.tbl     2012-09-16 18:49:11.000000000 +0000
875 @@ -242,7 +242,7 @@
876  233    common  epoll_ctl               sys_epoll_ctl
877  234    common  tgkill                  sys_tgkill
878  235    common  utimes                  sys_utimes
879 -236    64      vserver
880 +236    64      vserver                 sys_vserver
881  237    common  mbind                   sys_mbind
882  238    common  set_mempolicy           sys_set_mempolicy
883  239    common  get_mempolicy           sys_get_mempolicy
884 diff -NurpP --minimal linux-3.4.32/drivers/block/Kconfig linux-3.4.32-vs2.3.3.9/drivers/block/Kconfig
885 --- linux-3.4.32/drivers/block/Kconfig  2012-05-21 16:06:43.000000000 +0000
886 +++ linux-3.4.32-vs2.3.3.9/drivers/block/Kconfig        2012-05-21 16:15:04.000000000 +0000
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.4.32/drivers/block/Makefile linux-3.4.32-vs2.3.3.9/drivers/block/Makefile
902 --- linux-3.4.32/drivers/block/Makefile 2012-03-19 18:46:52.000000000 +0000
903 +++ linux-3.4.32-vs2.3.3.9/drivers/block/Makefile       2012-05-21 16:15:04.000000000 +0000
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.4.32/drivers/block/loop.c linux-3.4.32-vs2.3.3.9/drivers/block/loop.c
913 --- linux-3.4.32/drivers/block/loop.c   2012-05-21 16:06:43.000000000 +0000
914 +++ linux-3.4.32-vs2.3.3.9/drivers/block/loop.c 2012-05-21 16:15:04.000000000 +0000
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.4.32/drivers/block/vroot.c linux-3.4.32-vs2.3.3.9/drivers/block/vroot.c
971 --- linux-3.4.32/drivers/block/vroot.c  1970-01-01 00:00:00.000000000 +0000
972 +++ linux-3.4.32-vs2.3.3.9/drivers/block/vroot.c        2012-05-21 16:15:04.000000000 +0000
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.4.32/drivers/infiniband/Kconfig linux-3.4.32-vs2.3.3.9/drivers/infiniband/Kconfig
1266 --- linux-3.4.32/drivers/infiniband/Kconfig     2012-03-19 18:46:54.000000000 +0000
1267 +++ linux-3.4.32-vs2.3.3.9/drivers/infiniband/Kconfig   2012-05-21 16:15:04.000000000 +0000
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.4.32/drivers/infiniband/core/addr.c linux-3.4.32-vs2.3.3.9/drivers/infiniband/core/addr.c
1278 --- linux-3.4.32/drivers/infiniband/core/addr.c 2012-05-21 16:06:46.000000000 +0000
1279 +++ linux-3.4.32-vs2.3.3.9/drivers/infiniband/core/addr.c       2012-05-21 16:15:04.000000000 +0000
1280 @@ -263,7 +263,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.4.32/drivers/md/dm-ioctl.c linux-3.4.32-vs2.3.3.9/drivers/md/dm-ioctl.c
1290 --- linux-3.4.32/drivers/md/dm-ioctl.c  2013-02-19 13:55:26.000000000 +0000
1291 +++ linux-3.4.32-vs2.3.3.9/drivers/md/dm-ioctl.c        2013-02-11 23:37:30.000000000 +0000
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 @@ -1624,8 +1636,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.4.32/drivers/md/dm.c linux-3.4.32-vs2.3.3.9/drivers/md/dm.c
1378 --- linux-3.4.32/drivers/md/dm.c        2013-02-19 13:55:26.000000000 +0000
1379 +++ linux-3.4.32-vs2.3.3.9/drivers/md/dm.c      2012-12-08 00:53:53.000000000 +0000
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 @@ -1876,6 +1888,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.4.32/drivers/md/dm.h linux-3.4.32-vs2.3.3.9/drivers/md/dm.h
1454 --- linux-3.4.32/drivers/md/dm.h        2012-01-09 15:14:21.000000000 +0000
1455 +++ linux-3.4.32-vs2.3.3.9/drivers/md/dm.h      2012-05-21 16:15:04.000000000 +0000
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.4.32/drivers/net/tun.c linux-3.4.32-vs2.3.3.9/drivers/net/tun.c
1466 --- linux-3.4.32/drivers/net/tun.c      2013-02-19 13:55:29.000000000 +0000
1467 +++ linux-3.4.32-vs2.3.3.9/drivers/net/tun.c    2012-09-01 08:50:48.000000000 +0000
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 @@ -120,6 +121,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 @@ -1152,6 +1155,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 @@ -1335,6 +1341,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.4.32/drivers/tty/sysrq.c linux-3.4.32-vs2.3.3.9/drivers/tty/sysrq.c
1538 --- linux-3.4.32/drivers/tty/sysrq.c    2012-05-21 16:07:16.000000000 +0000
1539 +++ linux-3.4.32-vs2.3.3.9/drivers/tty/sysrq.c  2012-05-21 16:15:04.000000000 +0000
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 @@ -398,6 +399,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 @@ -452,7 +468,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 @@ -467,6 +487,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.4.32/drivers/tty/tty_io.c linux-3.4.32-vs2.3.3.9/drivers/tty/tty_io.c
1592 --- linux-3.4.32/drivers/tty/tty_io.c   2012-05-21 16:07:16.000000000 +0000
1593 +++ linux-3.4.32-vs2.3.3.9/drivers/tty/tty_io.c 2012-05-21 16:15:04.000000000 +0000
1594 @@ -104,6 +104,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 @@ -2118,7 +2119,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 @@ -2406,6 +2408,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.4.32/fs/attr.c linux-3.4.32-vs2.3.3.9/fs/attr.c
1621 --- linux-3.4.32/fs/attr.c      2013-02-19 13:55:45.000000000 +0000
1622 +++ linux-3.4.32-vs2.3.3.9/fs/attr.c    2012-06-28 14:45:07.000000000 +0000
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.4.32/fs/block_dev.c linux-3.4.32-vs2.3.3.9/fs/block_dev.c
1664 --- linux-3.4.32/fs/block_dev.c 2012-05-21 16:07:18.000000000 +0000
1665 +++ linux-3.4.32-vs2.3.3.9/fs/block_dev.c       2012-05-21 16:15:04.000000000 +0000
1666 @@ -27,6 +27,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 @@ -581,6 +582,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 @@ -627,6 +629,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 @@ -637,7 +644,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.4.32/fs/btrfs/ctree.h linux-3.4.32-vs2.3.3.9/fs/btrfs/ctree.h
1704 --- linux-3.4.32/fs/btrfs/ctree.h       2012-05-21 16:07:18.000000000 +0000
1705 +++ linux-3.4.32-vs2.3.3.9/fs/btrfs/ctree.h     2012-05-21 16:15:04.000000000 +0000
1706 @@ -668,11 +668,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 @@ -1542,6 +1545,8 @@ struct btrfs_ioctl_defrag_range_args {
1723  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1724  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
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 @@ -1762,6 +1767,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 @@ -1815,6 +1821,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 @@ -2959,6 +2969,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.4.32/fs/btrfs/disk-io.c linux-3.4.32-vs2.3.3.9/fs/btrfs/disk-io.c
1759 --- linux-3.4.32/fs/btrfs/disk-io.c     2012-05-21 16:07:18.000000000 +0000
1760 +++ linux-3.4.32-vs2.3.3.9/fs/btrfs/disk-io.c   2012-05-21 16:15:04.000000000 +0000
1761 @@ -2083,6 +2083,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.4.32/fs/btrfs/inode.c linux-3.4.32-vs2.3.3.9/fs/btrfs/inode.c
1772 --- linux-3.4.32/fs/btrfs/inode.c       2013-02-19 13:55:46.000000000 +0000
1773 +++ linux-3.4.32-vs2.3.3.9/fs/btrfs/inode.c     2012-06-28 14:45:07.000000000 +0000
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 @@ -2468,6 +2469,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 @@ -2495,8 +2498,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 @@ -2574,8 +2582,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 @@ -7576,11 +7590,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.4.32/fs/btrfs/ioctl.c linux-3.4.32-vs2.3.3.9/fs/btrfs/ioctl.c
1839 --- linux-3.4.32/fs/btrfs/ioctl.c       2012-05-21 16:07:19.000000000 +0000
1840 +++ linux-3.4.32-vs2.3.3.9/fs/btrfs/ioctl.c     2012-05-21 16:15:04.000000000 +0000
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.4.32/fs/btrfs/super.c linux-3.4.32-vs2.3.3.9/fs/btrfs/super.c
2014 --- linux-3.4.32/fs/btrfs/super.c       2012-05-21 16:07:19.000000000 +0000
2015 +++ linux-3.4.32-vs2.3.3.9/fs/btrfs/super.c     2012-05-21 16:15:04.000000000 +0000
2016 @@ -279,7 +279,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, Opt_fatal_errors,
2020 -       Opt_err,
2021 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2022  };
2023  
2024  static match_table_t tokens = {
2025 @@ -319,6 +319,9 @@ static match_table_t tokens = {
2026         {Opt_check_integrity_including_extent_data, "check_int_data"},
2027         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2028         {Opt_fatal_errors, "fatal_errors=%s"},
2029 +       {Opt_tag, "tag"},
2030 +       {Opt_notag, "notag"},
2031 +       {Opt_tagid, "tagid=%u"},
2032         {Opt_err, NULL},
2033  };
2034  
2035 @@ -564,6 +567,22 @@ int btrfs_parse_options(struct btrfs_roo
2036                                 goto out;
2037                         }
2038                         break;
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 @@ -1137,6 +1156,12 @@ static int btrfs_remount(struct super_bl
2059                 goto restore;
2060         }
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.4.32/fs/char_dev.c linux-3.4.32-vs2.3.3.9/fs/char_dev.c
2072 --- linux-3.4.32/fs/char_dev.c  2012-03-19 18:47:25.000000000 +0000
2073 +++ linux-3.4.32-vs2.3.3.9/fs/char_dev.c        2012-05-21 16:15:04.000000000 +0000
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.4.32/fs/dcache.c linux-3.4.32-vs2.3.3.9/fs/dcache.c
2107 --- linux-3.4.32/fs/dcache.c    2013-02-19 13:55:49.000000000 +0000
2108 +++ linux-3.4.32-vs2.3.3.9/fs/dcache.c  2012-10-22 13:09:53.000000000 +0000
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 @@ -601,6 +602,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 @@ -630,6 +633,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 @@ -1258,6 +1262,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 @@ -1280,6 +1287,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 @@ -1941,6 +1949,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.4.32/fs/devpts/inode.c linux-3.4.32-vs2.3.3.9/fs/devpts/inode.c
2161 --- linux-3.4.32/fs/devpts/inode.c      2012-05-21 16:07:20.000000000 +0000
2162 +++ linux-3.4.32-vs2.3.3.9/fs/devpts/inode.c    2012-05-21 16:15:04.000000000 +0000
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,21 @@
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 +
2190  /*
2191   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2192   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2193 @@ -328,6 +344,34 @@ static int devpts_show_options(struct se
2194         return 0;
2195  }
2196  
2197 +static int devpts_filter(struct dentry *de)
2198 +{
2199 +       xid_t xid = 0;
2200 +
2201 +       /* devpts is xid tagged */
2202 +       if (de && de->d_inode)
2203 +               xid = (xid_t)de->d_inode->i_tag;
2204 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2205 +       else
2206 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2207 +                       de->d_name.len, de->d_name.name);
2208 +#endif
2209 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2210 +}
2211 +
2212 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2213 +{
2214 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2215 +}
2216 +
2217 +static struct file_operations devpts_dir_operations = {
2218 +       .open           = dcache_dir_open,
2219 +       .release        = dcache_dir_close,
2220 +       .llseek         = dcache_dir_lseek,
2221 +       .read           = generic_read_dir,
2222 +       .readdir        = devpts_readdir,
2223 +};
2224 +
2225  static const struct super_operations devpts_sops = {
2226         .statfs         = simple_statfs,
2227         .remount_fs     = devpts_remount,
2228 @@ -371,8 +415,10 @@ devpts_fill_super(struct super_block *s,
2229         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2230         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2231         inode->i_op = &simple_dir_inode_operations;
2232 -       inode->i_fop = &simple_dir_operations;
2233 +       inode->i_fop = &devpts_dir_operations;
2234         set_nlink(inode, 2);
2235 +       /* devpts is xid tagged */
2236 +       inode->i_tag = (tag_t)vx_current_xid();
2237  
2238         s->s_root = d_make_root(inode);
2239         if (s->s_root)
2240 @@ -564,6 +610,9 @@ int devpts_pty_new(struct inode *ptmx_in
2241         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2242         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2243         init_special_inode(inode, S_IFCHR|opts->mode, device);
2244 +       /* devpts is xid tagged */
2245 +       inode->i_tag = (tag_t)vx_current_xid();
2246 +       inode->i_op = &devpts_file_inode_operations;
2247         inode->i_private = tty;
2248         tty->driver_data = inode;
2249  
2250 diff -NurpP --minimal linux-3.4.32/fs/ext2/balloc.c linux-3.4.32-vs2.3.3.9/fs/ext2/balloc.c
2251 --- linux-3.4.32/fs/ext2/balloc.c       2012-01-09 15:14:54.000000000 +0000
2252 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/balloc.c     2012-05-21 16:15:04.000000000 +0000
2253 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block
2254                         start = 0;
2255                 end = EXT2_BLOCKS_PER_GROUP(sb);
2256         }
2257 -
2258         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2259  
2260  repeat:
2261 diff -NurpP --minimal linux-3.4.32/fs/ext2/ext2.h linux-3.4.32-vs2.3.3.9/fs/ext2/ext2.h
2262 --- linux-3.4.32/fs/ext2/ext2.h 2012-05-21 16:07:20.000000000 +0000
2263 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/ext2.h       2012-05-21 16:15:05.000000000 +0000
2264 @@ -244,8 +244,12 @@ struct ext2_group_desc
2265  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2266  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2267  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2268 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2269  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2270  
2271 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2272 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2273 +
2274  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2275  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2276  
2277 @@ -329,7 +333,8 @@ struct ext2_inode {
2278                         __u16   i_pad1;
2279                         __le16  l_i_uid_high;   /* these 2 fields    */
2280                         __le16  l_i_gid_high;   /* were reserved2[0] */
2281 -                       __u32   l_i_reserved2;
2282 +                       __le16  l_i_tag;        /* Context Tag */
2283 +                       __u16   l_i_reserved2;
2284                 } linux2;
2285                 struct {
2286                         __u8    h_i_frag;       /* Fragment number */
2287 @@ -357,6 +362,7 @@ struct ext2_inode {
2288  #define i_gid_low      i_gid
2289  #define i_uid_high     osd2.linux2.l_i_uid_high
2290  #define i_gid_high     osd2.linux2.l_i_gid_high
2291 +#define i_raw_tag      osd2.linux2.l_i_tag
2292  #define i_reserved2    osd2.linux2.l_i_reserved2
2293  
2294  /*
2295 @@ -384,6 +390,7 @@ struct ext2_inode {
2296  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2297  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2298  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2299 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2300  
2301  
2302  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2303 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2304  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2305  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2306                        u64 start, u64 len);
2307 +extern int ext2_sync_flags(struct inode *, int, int);
2308  
2309  /* ioctl.c */
2310  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2311 diff -NurpP --minimal linux-3.4.32/fs/ext2/file.c linux-3.4.32-vs2.3.3.9/fs/ext2/file.c
2312 --- linux-3.4.32/fs/ext2/file.c 2011-10-24 16:45:27.000000000 +0000
2313 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/file.c       2012-05-21 16:15:05.000000000 +0000
2314 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2315         .setattr        = ext2_setattr,
2316         .get_acl        = ext2_get_acl,
2317         .fiemap         = ext2_fiemap,
2318 +       .sync_flags     = ext2_sync_flags,
2319  };
2320 diff -NurpP --minimal linux-3.4.32/fs/ext2/ialloc.c linux-3.4.32-vs2.3.3.9/fs/ext2/ialloc.c
2321 --- linux-3.4.32/fs/ext2/ialloc.c       2012-03-19 18:47:25.000000000 +0000
2322 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/ialloc.c     2012-05-21 16:15:05.000000000 +0000
2323 @@ -17,6 +17,7 @@
2324  #include <linux/backing-dev.h>
2325  #include <linux/buffer_head.h>
2326  #include <linux/random.h>
2327 +#include <linux/vs_tag.h>
2328  #include "ext2.h"
2329  #include "xattr.h"
2330  #include "acl.h"
2331 @@ -549,6 +550,7 @@ got:
2332                 inode->i_mode = mode;
2333                 inode->i_uid = current_fsuid();
2334                 inode->i_gid = dir->i_gid;
2335 +               inode->i_tag = dx_current_fstag(sb);
2336         } else
2337                 inode_init_owner(inode, dir, mode);
2338  
2339 diff -NurpP --minimal linux-3.4.32/fs/ext2/inode.c linux-3.4.32-vs2.3.3.9/fs/ext2/inode.c
2340 --- linux-3.4.32/fs/ext2/inode.c        2012-03-19 18:47:25.000000000 +0000
2341 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/inode.c      2012-05-21 16:15:05.000000000 +0000
2342 @@ -31,6 +31,7 @@
2343  #include <linux/mpage.h>
2344  #include <linux/fiemap.h>
2345  #include <linux/namei.h>
2346 +#include <linux/vs_tag.h>
2347  #include "ext2.h"
2348  #include "acl.h"
2349  #include "xip.h"
2350 @@ -1162,7 +1163,7 @@ static void ext2_truncate_blocks(struct
2351                 return;
2352         if (ext2_inode_is_fast_symlink(inode))
2353                 return;
2354 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2355 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2356                 return;
2357         __ext2_truncate_blocks(inode, offset);
2358  }
2359 @@ -1253,36 +1254,61 @@ void ext2_set_inode_flags(struct inode *
2360  {
2361         unsigned int flags = EXT2_I(inode)->i_flags;
2362  
2363 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2364 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2365 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2366 +
2367 +
2368 +       if (flags & EXT2_IMMUTABLE_FL)
2369 +               inode->i_flags |= S_IMMUTABLE;
2370 +       if (flags & EXT2_IXUNLINK_FL)
2371 +               inode->i_flags |= S_IXUNLINK;
2372 +
2373         if (flags & EXT2_SYNC_FL)
2374                 inode->i_flags |= S_SYNC;
2375         if (flags & EXT2_APPEND_FL)
2376                 inode->i_flags |= S_APPEND;
2377 -       if (flags & EXT2_IMMUTABLE_FL)
2378 -               inode->i_flags |= S_IMMUTABLE;
2379         if (flags & EXT2_NOATIME_FL)
2380                 inode->i_flags |= S_NOATIME;
2381         if (flags & EXT2_DIRSYNC_FL)
2382                 inode->i_flags |= S_DIRSYNC;
2383 +
2384 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2385 +
2386 +       if (flags & EXT2_BARRIER_FL)
2387 +               inode->i_vflags |= V_BARRIER;
2388 +       if (flags & EXT2_COW_FL)
2389 +               inode->i_vflags |= V_COW;
2390  }
2391  
2392  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2393  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2394  {
2395         unsigned int flags = ei->vfs_inode.i_flags;
2396 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2397 +
2398 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2399 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2400 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2401 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2402 +
2403 +       if (flags & S_IMMUTABLE)
2404 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2405 +       if (flags & S_IXUNLINK)
2406 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2407  
2408 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2409 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2410         if (flags & S_SYNC)
2411                 ei->i_flags |= EXT2_SYNC_FL;
2412         if (flags & S_APPEND)
2413                 ei->i_flags |= EXT2_APPEND_FL;
2414 -       if (flags & S_IMMUTABLE)
2415 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2416         if (flags & S_NOATIME)
2417                 ei->i_flags |= EXT2_NOATIME_FL;
2418         if (flags & S_DIRSYNC)
2419                 ei->i_flags |= EXT2_DIRSYNC_FL;
2420 +
2421 +       if (vflags & V_BARRIER)
2422 +               ei->i_flags |= EXT2_BARRIER_FL;
2423 +       if (vflags & V_COW)
2424 +               ei->i_flags |= EXT2_COW_FL;
2425  }
2426  
2427  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2428 @@ -1292,6 +1318,8 @@ struct inode *ext2_iget (struct super_bl
2429         struct ext2_inode *raw_inode;
2430         struct inode *inode;
2431         long ret = -EIO;
2432 +       uid_t uid;
2433 +       gid_t gid;
2434         int n;
2435  
2436         inode = iget_locked(sb, ino);
2437 @@ -1310,12 +1338,16 @@ struct inode *ext2_iget (struct super_bl
2438         }
2439  
2440         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2441 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2442 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2443 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2444 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2445         if (!(test_opt (inode->i_sb, NO_UID32))) {
2446 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2447 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2448 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2449 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2450         }
2451 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2452 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2453 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2454 +               le16_to_cpu(raw_inode->i_raw_tag));
2455         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2456         inode->i_size = le32_to_cpu(raw_inode->i_size);
2457         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2458 @@ -1413,8 +1445,8 @@ static int __ext2_write_inode(struct ino
2459         struct ext2_inode_info *ei = EXT2_I(inode);
2460         struct super_block *sb = inode->i_sb;
2461         ino_t ino = inode->i_ino;
2462 -       uid_t uid = inode->i_uid;
2463 -       gid_t gid = inode->i_gid;
2464 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2465 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2466         struct buffer_head * bh;
2467         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2468         int n;
2469 @@ -1450,6 +1482,9 @@ static int __ext2_write_inode(struct ino
2470                 raw_inode->i_uid_high = 0;
2471                 raw_inode->i_gid_high = 0;
2472         }
2473 +#ifdef CONFIG_TAGGING_INTERN
2474 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2475 +#endif
2476         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2477         raw_inode->i_size = cpu_to_le32(inode->i_size);
2478         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2479 @@ -1530,7 +1565,8 @@ int ext2_setattr(struct dentry *dentry,
2480         if (is_quota_modification(inode, iattr))
2481                 dquot_initialize(inode);
2482         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2483 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2484 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2485 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2486                 error = dquot_transfer(inode, iattr);
2487                 if (error)
2488                         return error;
2489 diff -NurpP --minimal linux-3.4.32/fs/ext2/ioctl.c linux-3.4.32-vs2.3.3.9/fs/ext2/ioctl.c
2490 --- linux-3.4.32/fs/ext2/ioctl.c        2012-03-19 18:47:25.000000000 +0000
2491 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/ioctl.c      2012-05-21 16:15:05.000000000 +0000
2492 @@ -17,6 +17,16 @@
2493  #include <asm/uaccess.h>
2494  
2495  
2496 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2497 +{
2498 +       inode->i_flags = flags;
2499 +       inode->i_vflags = vflags;
2500 +       ext2_get_inode_flags(EXT2_I(inode));
2501 +       inode->i_ctime = CURRENT_TIME_SEC;
2502 +       mark_inode_dirty(inode);
2503 +       return 0;
2504 +}
2505 +
2506  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2507  {
2508         struct inode *inode = filp->f_dentry->d_inode;
2509 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2510  
2511                 flags = ext2_mask_flags(inode->i_mode, flags);
2512  
2513 +               if (IS_BARRIER(inode)) {
2514 +                       vxwprintk_task(1, "messing with the barrier.");
2515 +                       return -EACCES;
2516 +               }
2517 +
2518                 mutex_lock(&inode->i_mutex);
2519                 /* Is it quota file? Do not allow user to mess with it */
2520                 if (IS_NOQUOTA(inode)) {
2521 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2522                  *
2523                  * This test looks nicer. Thanks to Pauline Middelink
2524                  */
2525 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2526 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2527 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2528 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2529                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2530                                 mutex_unlock(&inode->i_mutex);
2531                                 ret = -EPERM;
2532 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2533                         }
2534                 }
2535  
2536 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2537 +               flags &= EXT2_FL_USER_MODIFIABLE;
2538                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2539                 ei->i_flags = flags;
2540  
2541 diff -NurpP --minimal linux-3.4.32/fs/ext2/namei.c linux-3.4.32-vs2.3.3.9/fs/ext2/namei.c
2542 --- linux-3.4.32/fs/ext2/namei.c        2012-05-21 16:07:20.000000000 +0000
2543 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/namei.c      2012-05-21 16:15:05.000000000 +0000
2544 @@ -32,6 +32,7 @@
2545  
2546  #include <linux/pagemap.h>
2547  #include <linux/quotaops.h>
2548 +#include <linux/vs_tag.h>
2549  #include "ext2.h"
2550  #include "xattr.h"
2551  #include "acl.h"
2552 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2553                                         (unsigned long) ino);
2554                         return ERR_PTR(-EIO);
2555                 }
2556 +               dx_propagate_tag(nd, inode);
2557         }
2558         return d_splice_alias(inode, dentry);
2559  }
2560 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2561         .removexattr    = generic_removexattr,
2562  #endif
2563         .setattr        = ext2_setattr,
2564 +       .sync_flags     = ext2_sync_flags,
2565         .get_acl        = ext2_get_acl,
2566  };
2567  
2568 diff -NurpP --minimal linux-3.4.32/fs/ext2/super.c linux-3.4.32-vs2.3.3.9/fs/ext2/super.c
2569 --- linux-3.4.32/fs/ext2/super.c        2012-05-21 16:07:20.000000000 +0000
2570 +++ linux-3.4.32-vs2.3.3.9/fs/ext2/super.c      2012-05-21 16:15:05.000000000 +0000
2571 @@ -393,7 +393,8 @@ enum {
2572         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2573         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2574         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2575 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2576 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2577 +       Opt_tag, Opt_notag, Opt_tagid
2578  };
2579  
2580  static const match_table_t tokens = {
2581 @@ -421,6 +422,9 @@ static const match_table_t tokens = {
2582         {Opt_acl, "acl"},
2583         {Opt_noacl, "noacl"},
2584         {Opt_xip, "xip"},
2585 +       {Opt_tag, "tag"},
2586 +       {Opt_notag, "notag"},
2587 +       {Opt_tagid, "tagid=%u"},
2588         {Opt_grpquota, "grpquota"},
2589         {Opt_ignore, "noquota"},
2590         {Opt_quota, "quota"},
2591 @@ -491,6 +495,20 @@ static int parse_options(char *options,
2592                 case Opt_nouid32:
2593                         set_opt (sbi->s_mount_opt, NO_UID32);
2594                         break;
2595 +#ifndef CONFIG_TAGGING_NONE
2596 +               case Opt_tag:
2597 +                       set_opt (sbi->s_mount_opt, TAGGED);
2598 +                       break;
2599 +               case Opt_notag:
2600 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2601 +                       break;
2602 +#endif
2603 +#ifdef CONFIG_PROPAGATE
2604 +               case Opt_tagid:
2605 +                       /* use args[0] */
2606 +                       set_opt (sbi->s_mount_opt, TAGGED);
2607 +                       break;
2608 +#endif
2609                 case Opt_nocheck:
2610                         clear_opt (sbi->s_mount_opt, CHECK);
2611                         break;
2612 @@ -849,6 +867,8 @@ static int ext2_fill_super(struct super_
2613         if (!parse_options((char *) data, sb))
2614                 goto failed_mount;
2615  
2616 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2617 +               sb->s_flags |= MS_TAGGED;
2618         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2619                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2620                  MS_POSIXACL : 0);
2621 @@ -1222,6 +1242,14 @@ static int ext2_remount (struct super_bl
2622                 err = -EINVAL;
2623                 goto restore_opts;
2624         }
2625 +
2626 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2627 +               !(sb->s_flags & MS_TAGGED)) {
2628 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2629 +                      sb->s_id);
2630 +               err = -EINVAL;
2631 +               goto restore_opts;
2632 +       }
2633  
2634         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2635                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2636 diff -NurpP --minimal linux-3.4.32/fs/ext3/ext3.h linux-3.4.32-vs2.3.3.9/fs/ext3/ext3.h
2637 --- linux-3.4.32/fs/ext3/ext3.h 2012-05-21 16:07:20.000000000 +0000
2638 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/ext3.h       2012-05-21 17:13:31.000000000 +0000
2639 @@ -151,10 +151,14 @@ struct ext3_group_desc
2640  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2641  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2642  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2643 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2644  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2645  
2646 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2647 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2648 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2649 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2650 +
2651 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2652 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2653  
2654  /* Flags that should be inherited by new inodes from their parent. */
2655  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2656 @@ -290,7 +294,8 @@ struct ext3_inode {
2657                         __u16   i_pad1;
2658                         __le16  l_i_uid_high;   /* these 2 fields    */
2659                         __le16  l_i_gid_high;   /* were reserved2[0] */
2660 -                       __u32   l_i_reserved2;
2661 +                       __le16  l_i_tag;        /* Context Tag */
2662 +                       __u16   l_i_reserved2;
2663                 } linux2;
2664                 struct {
2665                         __u8    h_i_frag;       /* Fragment number */
2666 @@ -320,6 +325,7 @@ struct ext3_inode {
2667  #define i_gid_low      i_gid
2668  #define i_uid_high     osd2.linux2.l_i_uid_high
2669  #define i_gid_high     osd2.linux2.l_i_gid_high
2670 +#define i_raw_tag      osd2.linux2.l_i_tag
2671  #define i_reserved2    osd2.linux2.l_i_reserved2
2672  
2673  /*
2674 @@ -364,6 +370,7 @@ struct ext3_inode {
2675  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2676  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2677                                                   * error in ordered mode */
2678 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2679  
2680  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2681  #ifndef _LINUX_EXT2_FS_H
2682 @@ -1057,6 +1064,7 @@ extern void ext3_get_inode_flags(struct
2683  extern void ext3_set_aops(struct inode *inode);
2684  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2685                        u64 start, u64 len);
2686 +extern int ext3_sync_flags(struct inode *, int, int);
2687  
2688  /* ioctl.c */
2689  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2690 diff -NurpP --minimal linux-3.4.32/fs/ext3/file.c linux-3.4.32-vs2.3.3.9/fs/ext3/file.c
2691 --- linux-3.4.32/fs/ext3/file.c 2012-05-21 16:07:20.000000000 +0000
2692 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/file.c       2012-05-21 16:15:05.000000000 +0000
2693 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2694  #endif
2695         .get_acl        = ext3_get_acl,
2696         .fiemap         = ext3_fiemap,
2697 +       .sync_flags     = ext3_sync_flags,
2698  };
2699  
2700 diff -NurpP --minimal linux-3.4.32/fs/ext3/ialloc.c linux-3.4.32-vs2.3.3.9/fs/ext3/ialloc.c
2701 --- linux-3.4.32/fs/ext3/ialloc.c       2012-05-21 16:07:20.000000000 +0000
2702 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/ialloc.c     2012-05-21 16:15:05.000000000 +0000
2703 @@ -14,6 +14,7 @@
2704  
2705  #include <linux/quotaops.h>
2706  #include <linux/random.h>
2707 +#include <linux/vs_tag.h>
2708  
2709  #include "ext3.h"
2710  #include "xattr.h"
2711 @@ -485,6 +486,7 @@ got:
2712                 inode->i_mode = mode;
2713                 inode->i_uid = current_fsuid();
2714                 inode->i_gid = dir->i_gid;
2715 +               inode->i_tag = dx_current_fstag(sb);
2716         } else
2717                 inode_init_owner(inode, dir, mode);
2718  
2719 diff -NurpP --minimal linux-3.4.32/fs/ext3/inode.c linux-3.4.32-vs2.3.3.9/fs/ext3/inode.c
2720 --- linux-3.4.32/fs/ext3/inode.c        2013-02-19 13:55:49.000000000 +0000
2721 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/inode.c      2012-09-16 18:49:11.000000000 +0000
2722 @@ -27,6 +27,8 @@
2723  #include <linux/writeback.h>
2724  #include <linux/mpage.h>
2725  #include <linux/namei.h>
2726 +#include <linux/vs_tag.h>
2727 +
2728  #include "ext3.h"
2729  #include "xattr.h"
2730  #include "acl.h"
2731 @@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2732  {
2733         unsigned int flags = EXT3_I(inode)->i_flags;
2734  
2735 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2736 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2737 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2738 +
2739 +       if (flags & EXT3_IMMUTABLE_FL)
2740 +               inode->i_flags |= S_IMMUTABLE;
2741 +       if (flags & EXT3_IXUNLINK_FL)
2742 +               inode->i_flags |= S_IXUNLINK;
2743 +
2744         if (flags & EXT3_SYNC_FL)
2745                 inode->i_flags |= S_SYNC;
2746         if (flags & EXT3_APPEND_FL)
2747                 inode->i_flags |= S_APPEND;
2748 -       if (flags & EXT3_IMMUTABLE_FL)
2749 -               inode->i_flags |= S_IMMUTABLE;
2750         if (flags & EXT3_NOATIME_FL)
2751                 inode->i_flags |= S_NOATIME;
2752         if (flags & EXT3_DIRSYNC_FL)
2753                 inode->i_flags |= S_DIRSYNC;
2754 +
2755 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2756 +
2757 +       if (flags & EXT3_BARRIER_FL)
2758 +               inode->i_vflags |= V_BARRIER;
2759 +       if (flags & EXT3_COW_FL)
2760 +               inode->i_vflags |= V_COW;
2761  }
2762  
2763  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2764  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2765  {
2766         unsigned int flags = ei->vfs_inode.i_flags;
2767 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2768 +
2769 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2770 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2771 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2772 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2773 +
2774 +       if (flags & S_IMMUTABLE)
2775 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2776 +       if (flags & S_IXUNLINK)
2777 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2778  
2779 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2780 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2781         if (flags & S_SYNC)
2782                 ei->i_flags |= EXT3_SYNC_FL;
2783         if (flags & S_APPEND)
2784                 ei->i_flags |= EXT3_APPEND_FL;
2785 -       if (flags & S_IMMUTABLE)
2786 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2787         if (flags & S_NOATIME)
2788                 ei->i_flags |= EXT3_NOATIME_FL;
2789         if (flags & S_DIRSYNC)
2790                 ei->i_flags |= EXT3_DIRSYNC_FL;
2791 +
2792 +       if (vflags & V_BARRIER)
2793 +               ei->i_flags |= EXT3_BARRIER_FL;
2794 +       if (vflags & V_COW)
2795 +               ei->i_flags |= EXT3_COW_FL;
2796  }
2797  
2798  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2799 @@ -2891,6 +2917,8 @@ struct inode *ext3_iget(struct super_blo
2800         transaction_t *transaction;
2801         long ret;
2802         int block;
2803 +       uid_t uid;
2804 +       gid_t gid;
2805  
2806         inode = iget_locked(sb, ino);
2807         if (!inode)
2808 @@ -2907,12 +2935,16 @@ struct inode *ext3_iget(struct super_blo
2809         bh = iloc.bh;
2810         raw_inode = ext3_raw_inode(&iloc);
2811         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2812 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2813 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2814 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2815 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2816         if(!(test_opt (inode->i_sb, NO_UID32))) {
2817 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2818 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2819 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2820 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2821         }
2822 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2823 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2824 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2825 +               le16_to_cpu(raw_inode->i_raw_tag));
2826         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2827         inode->i_size = le32_to_cpu(raw_inode->i_size);
2828         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2829 @@ -3067,6 +3099,8 @@ static int ext3_do_update_inode(handle_t
2830         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2831         struct ext3_inode_info *ei = EXT3_I(inode);
2832         struct buffer_head *bh = iloc->bh;
2833 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2834 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2835         int err = 0, rc, block;
2836         int need_datasync = 0;
2837         __le32 disksize;
2838 @@ -3083,29 +3117,32 @@ again:
2839         ext3_get_inode_flags(ei);
2840         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2841         if(!(test_opt(inode->i_sb, NO_UID32))) {
2842 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2843 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2844 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2845 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2846  /*
2847   * Fix up interoperability with old kernels. Otherwise, old inodes get
2848   * re-used with the upper 16 bits of the uid/gid intact
2849   */
2850                 if(!ei->i_dtime) {
2851                         raw_inode->i_uid_high =
2852 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2853 +                               cpu_to_le16(high_16_bits(uid));
2854                         raw_inode->i_gid_high =
2855 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2856 +                               cpu_to_le16(high_16_bits(gid));
2857                 } else {
2858                         raw_inode->i_uid_high = 0;
2859                         raw_inode->i_gid_high = 0;
2860                 }
2861         } else {
2862                 raw_inode->i_uid_low =
2863 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2864 +                       cpu_to_le16(fs_high2lowuid(uid));
2865                 raw_inode->i_gid_low =
2866 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2867 +                       cpu_to_le16(fs_high2lowgid(gid));
2868                 raw_inode->i_uid_high = 0;
2869                 raw_inode->i_gid_high = 0;
2870         }
2871 +#ifdef CONFIG_TAGGING_INTERN
2872 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2873 +#endif
2874         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2875         disksize = cpu_to_le32(ei->i_disksize);
2876         if (disksize != raw_inode->i_size) {
2877 @@ -3274,7 +3311,8 @@ int ext3_setattr(struct dentry *dentry,
2878         if (is_quota_modification(inode, attr))
2879                 dquot_initialize(inode);
2880         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2881 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2882 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2883 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2884                 handle_t *handle;
2885  
2886                 /* (user+group)*(old+new) structure, inode write (sb,
2887 @@ -3296,6 +3334,8 @@ int ext3_setattr(struct dentry *dentry,
2888                         inode->i_uid = attr->ia_uid;
2889                 if (attr->ia_valid & ATTR_GID)
2890                         inode->i_gid = attr->ia_gid;
2891 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2892 +                       inode->i_tag = attr->ia_tag;
2893                 error = ext3_mark_inode_dirty(handle, inode);
2894                 ext3_journal_stop(handle);
2895         }
2896 diff -NurpP --minimal linux-3.4.32/fs/ext3/ioctl.c linux-3.4.32-vs2.3.3.9/fs/ext3/ioctl.c
2897 --- linux-3.4.32/fs/ext3/ioctl.c        2012-05-21 16:07:20.000000000 +0000
2898 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/ioctl.c      2012-05-21 16:15:05.000000000 +0000
2899 @@ -12,6 +12,34 @@
2900  #include <asm/uaccess.h>
2901  #include "ext3.h"
2902  
2903 +
2904 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2905 +{
2906 +       handle_t *handle = NULL;
2907 +       struct ext3_iloc iloc;
2908 +       int err;
2909 +
2910 +       handle = ext3_journal_start(inode, 1);
2911 +       if (IS_ERR(handle))
2912 +               return PTR_ERR(handle);
2913 +
2914 +       if (IS_SYNC(inode))
2915 +               handle->h_sync = 1;
2916 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2917 +       if (err)
2918 +               goto flags_err;
2919 +
2920 +       inode->i_flags = flags;
2921 +       inode->i_vflags = vflags;
2922 +       ext3_get_inode_flags(EXT3_I(inode));
2923 +       inode->i_ctime = CURRENT_TIME_SEC;
2924 +
2925 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2926 +flags_err:
2927 +       ext3_journal_stop(handle);
2928 +       return err;
2929 +}
2930 +
2931  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2932  {
2933         struct inode *inode = filp->f_dentry->d_inode;
2934 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2935  
2936                 flags = ext3_mask_flags(inode->i_mode, flags);
2937  
2938 +               if (IS_BARRIER(inode)) {
2939 +                       vxwprintk_task(1, "messing with the barrier.");
2940 +                       return -EACCES;
2941 +               }
2942 +
2943                 mutex_lock(&inode->i_mutex);
2944  
2945                 /* Is it quota file? Do not allow user to mess with it */
2946 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2947                  *
2948                  * This test looks nicer. Thanks to Pauline Middelink
2949                  */
2950 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2951 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2952 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2953 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2954                         if (!capable(CAP_LINUX_IMMUTABLE))
2955                                 goto flags_out;
2956                 }
2957 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2958                 if (err)
2959                         goto flags_err;
2960  
2961 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2962 +               flags &= EXT3_FL_USER_MODIFIABLE;
2963                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2964                 ei->i_flags = flags;
2965  
2966 diff -NurpP --minimal linux-3.4.32/fs/ext3/namei.c linux-3.4.32-vs2.3.3.9/fs/ext3/namei.c
2967 --- linux-3.4.32/fs/ext3/namei.c        2012-05-21 16:07:20.000000000 +0000
2968 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/namei.c      2012-05-21 16:15:05.000000000 +0000
2969 @@ -25,6 +25,8 @@
2970   */
2971  
2972  #include <linux/quotaops.h>
2973 +#include <linux/vs_tag.h>
2974 +
2975  #include "ext3.h"
2976  #include "namei.h"
2977  #include "xattr.h"
2978 @@ -915,6 +917,7 @@ restart:
2979                                         submit_bh(READ | REQ_META | REQ_PRIO,
2980                                                   bh);
2981                                 }
2982 +               dx_propagate_tag(nd, inode);
2983                         }
2984                 }
2985                 if ((bh = bh_use[ra_ptr++]) == NULL)
2986 @@ -2526,6 +2529,7 @@ const struct inode_operations ext3_dir_i
2987         .listxattr      = ext3_listxattr,
2988         .removexattr    = generic_removexattr,
2989  #endif
2990 +       .sync_flags     = ext3_sync_flags,
2991         .get_acl        = ext3_get_acl,
2992  };
2993  
2994 diff -NurpP --minimal linux-3.4.32/fs/ext3/super.c linux-3.4.32-vs2.3.3.9/fs/ext3/super.c
2995 --- linux-3.4.32/fs/ext3/super.c        2012-05-21 16:07:20.000000000 +0000
2996 +++ linux-3.4.32-vs2.3.3.9/fs/ext3/super.c      2012-05-21 16:15:05.000000000 +0000
2997 @@ -820,7 +820,8 @@ enum {
2998         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2999         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3000         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3001 -       Opt_resize, Opt_usrquota, Opt_grpquota
3002 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3003 +       Opt_tag, Opt_notag, Opt_tagid
3004  };
3005  
3006  static const match_table_t tokens = {
3007 @@ -877,6 +878,9 @@ static const match_table_t tokens = {
3008         {Opt_barrier, "barrier"},
3009         {Opt_nobarrier, "nobarrier"},
3010         {Opt_resize, "resize"},
3011 +       {Opt_tag, "tag"},
3012 +       {Opt_notag, "notag"},
3013 +       {Opt_tagid, "tagid=%u"},
3014         {Opt_err, NULL},
3015  };
3016  
3017 @@ -1029,6 +1033,20 @@ static int parse_options (char *options,
3018                 case Opt_nouid32:
3019                         set_opt (sbi->s_mount_opt, NO_UID32);
3020                         break;
3021 +#ifndef CONFIG_TAGGING_NONE
3022 +               case Opt_tag:
3023 +                       set_opt (sbi->s_mount_opt, TAGGED);
3024 +                       break;
3025 +               case Opt_notag:
3026 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3027 +                       break;
3028 +#endif
3029 +#ifdef CONFIG_PROPAGATE
3030 +               case Opt_tagid:
3031 +                       /* use args[0] */
3032 +                       set_opt (sbi->s_mount_opt, TAGGED);
3033 +                       break;
3034 +#endif
3035                 case Opt_nocheck:
3036                         clear_opt (sbi->s_mount_opt, CHECK);
3037                         break;
3038 @@ -1727,6 +1745,9 @@ static int ext3_fill_super (struct super
3039                             NULL, 0))
3040                 goto failed_mount;
3041  
3042 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3043 +               sb->s_flags |= MS_TAGGED;
3044 +
3045         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3046                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3047  
3048 @@ -2608,6 +2629,14 @@ static int ext3_remount (struct super_bl
3049         if (test_opt(sb, ABORT))
3050                 ext3_abort(sb, __func__, "Abort forced by user");
3051  
3052 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3053 +               !(sb->s_flags & MS_TAGGED)) {
3054 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3055 +                       sb->s_id);
3056 +               err = -EINVAL;
3057 +               goto restore_opts;
3058 +       }
3059 +
3060         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3061                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3062  
3063 diff -NurpP --minimal linux-3.4.32/fs/ext4/ext4.h linux-3.4.32-vs2.3.3.9/fs/ext4/ext4.h
3064 --- linux-3.4.32/fs/ext4/ext4.h 2013-02-19 13:55:50.000000000 +0000
3065 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/ext4.h       2012-09-01 08:50:49.000000000 +0000
3066 @@ -380,8 +380,12 @@ struct flex_groups {
3067  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3068  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3069  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3070 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3071  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3072  
3073 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3074 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3075 +
3076  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3077  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3078  
3079 @@ -650,7 +654,8 @@ struct ext4_inode {
3080                         __le16  l_i_file_acl_high;
3081                         __le16  l_i_uid_high;   /* these 2 fields */
3082                         __le16  l_i_gid_high;   /* were reserved2[0] */
3083 -                       __u32   l_i_reserved2;
3084 +                       __le16  l_i_tag;        /* Context Tag */
3085 +                       __u16   l_i_reserved2;
3086                 } linux2;
3087                 struct {
3088                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3089 @@ -768,6 +773,7 @@ do {                                                                               \
3090  #define i_gid_low      i_gid
3091  #define i_uid_high     osd2.linux2.l_i_uid_high
3092  #define i_gid_high     osd2.linux2.l_i_gid_high
3093 +#define i_raw_tag      osd2.linux2.l_i_tag
3094  #define i_reserved2    osd2.linux2.l_i_reserved2
3095  
3096  #elif defined(__GNU__)
3097 @@ -945,6 +951,7 @@ struct ext4_inode_info {
3098  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3099  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3100  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3101 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3102  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3103  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3104  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3105 @@ -2294,6 +2301,7 @@ extern int ext4_map_blocks(handle_t *han
3106                            struct ext4_map_blocks *map, int flags);
3107  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3108                         __u64 start, __u64 len);
3109 +extern int ext4_sync_flags(struct inode *, int, int);
3110  /* move_extent.c */
3111  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3112                              __u64 start_orig, __u64 start_donor,
3113 diff -NurpP --minimal linux-3.4.32/fs/ext4/file.c linux-3.4.32-vs2.3.3.9/fs/ext4/file.c
3114 --- linux-3.4.32/fs/ext4/file.c 2012-01-09 15:14:54.000000000 +0000
3115 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/file.c       2012-05-21 16:15:05.000000000 +0000
3116 @@ -258,5 +258,6 @@ const struct inode_operations ext4_file_
3117  #endif
3118         .get_acl        = ext4_get_acl,
3119         .fiemap         = ext4_fiemap,
3120 +       .sync_flags     = ext4_sync_flags,
3121  };
3122  
3123 diff -NurpP --minimal linux-3.4.32/fs/ext4/ialloc.c linux-3.4.32-vs2.3.3.9/fs/ext4/ialloc.c
3124 --- linux-3.4.32/fs/ext4/ialloc.c       2013-02-19 13:55:50.000000000 +0000
3125 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/ialloc.c     2013-02-11 23:37:30.000000000 +0000
3126 @@ -22,6 +22,7 @@
3127  #include <linux/random.h>
3128  #include <linux/bitops.h>
3129  #include <linux/blkdev.h>
3130 +#include <linux/vs_tag.h>
3131  #include <asm/byteorder.h>
3132  
3133  #include "ext4.h"
3134 @@ -815,6 +816,7 @@ got:
3135                 inode->i_mode = mode;
3136                 inode->i_uid = current_fsuid();
3137                 inode->i_gid = dir->i_gid;
3138 +               inode->i_tag = dx_current_fstag(sb);
3139         } else
3140                 inode_init_owner(inode, dir, mode);
3141  
3142 diff -NurpP --minimal linux-3.4.32/fs/ext4/inode.c linux-3.4.32-vs2.3.3.9/fs/ext4/inode.c
3143 --- linux-3.4.32/fs/ext4/inode.c        2013-02-19 13:55:50.000000000 +0000
3144 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/inode.c      2013-02-11 23:37:30.000000000 +0000
3145 @@ -37,6 +37,7 @@
3146  #include <linux/printk.h>
3147  #include <linux/slab.h>
3148  #include <linux/ratelimit.h>
3149 +#include <linux/vs_tag.h>
3150  
3151  #include "ext4_jbd2.h"
3152  #include "xattr.h"
3153 @@ -3584,41 +3585,64 @@ void ext4_set_inode_flags(struct inode *
3154  {
3155         unsigned int flags = EXT4_I(inode)->i_flags;
3156  
3157 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3158 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3159 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3160 +
3161 +       if (flags & EXT4_IMMUTABLE_FL)
3162 +               inode->i_flags |= S_IMMUTABLE;
3163 +       if (flags & EXT4_IXUNLINK_FL)
3164 +               inode->i_flags |= S_IXUNLINK;
3165 +
3166         if (flags & EXT4_SYNC_FL)
3167                 inode->i_flags |= S_SYNC;
3168         if (flags & EXT4_APPEND_FL)
3169                 inode->i_flags |= S_APPEND;
3170 -       if (flags & EXT4_IMMUTABLE_FL)
3171 -               inode->i_flags |= S_IMMUTABLE;
3172         if (flags & EXT4_NOATIME_FL)
3173                 inode->i_flags |= S_NOATIME;
3174         if (flags & EXT4_DIRSYNC_FL)
3175                 inode->i_flags |= S_DIRSYNC;
3176 +
3177 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3178 +
3179 +       if (flags & EXT4_BARRIER_FL)
3180 +               inode->i_vflags |= V_BARRIER;
3181 +       if (flags & EXT4_COW_FL)
3182 +               inode->i_vflags |= V_COW;
3183  }
3184  
3185  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3186  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3187  {
3188 -       unsigned int vfs_fl;
3189 +       unsigned int vfs_fl, vfs_vf;
3190         unsigned long old_fl, new_fl;
3191  
3192         do {
3193                 vfs_fl = ei->vfs_inode.i_flags;
3194 +               vfs_vf = ei->vfs_inode.i_vflags;
3195                 old_fl = ei->i_flags;
3196                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3197                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3198 -                               EXT4_DIRSYNC_FL);
3199 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3200 +                               EXT4_COW_FL);
3201 +
3202 +               if (vfs_fl & S_IMMUTABLE)
3203 +                       new_fl |= EXT4_IMMUTABLE_FL;
3204 +               if (vfs_fl & S_IXUNLINK)
3205 +                       new_fl |= EXT4_IXUNLINK_FL;
3206 +
3207                 if (vfs_fl & S_SYNC)
3208                         new_fl |= EXT4_SYNC_FL;
3209                 if (vfs_fl & S_APPEND)
3210                         new_fl |= EXT4_APPEND_FL;
3211 -               if (vfs_fl & S_IMMUTABLE)
3212 -                       new_fl |= EXT4_IMMUTABLE_FL;
3213                 if (vfs_fl & S_NOATIME)
3214                         new_fl |= EXT4_NOATIME_FL;
3215                 if (vfs_fl & S_DIRSYNC)
3216                         new_fl |= EXT4_DIRSYNC_FL;
3217 +
3218 +               if (vfs_vf & V_BARRIER)
3219 +                       new_fl |= EXT4_BARRIER_FL;
3220 +               if (vfs_vf & V_COW)
3221 +                       new_fl |= EXT4_COW_FL;
3222         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3223  }
3224  
3225 @@ -3654,6 +3678,8 @@ struct inode *ext4_iget(struct super_blo
3226         journal_t *journal = EXT4_SB(sb)->s_journal;
3227         long ret;
3228         int block;
3229 +       uid_t uid;
3230 +       gid_t gid;
3231  
3232         inode = iget_locked(sb, ino);
3233         if (!inode)
3234 @@ -3669,12 +3695,16 @@ struct inode *ext4_iget(struct super_blo
3235                 goto bad_inode;
3236         raw_inode = ext4_raw_inode(&iloc);
3237         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3238 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3239 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3240 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3241 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3242         if (!(test_opt(inode->i_sb, NO_UID32))) {
3243 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3244 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3245 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3246 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3247         }
3248 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3249 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3250 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3251 +               le16_to_cpu(raw_inode->i_raw_tag));
3252         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3253  
3254         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3255 @@ -3893,6 +3923,8 @@ static int ext4_do_update_inode(handle_t
3256         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3257         struct ext4_inode_info *ei = EXT4_I(inode);
3258         struct buffer_head *bh = iloc->bh;
3259 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3260 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3261         int err = 0, rc, block;
3262         int need_datasync = 0;
3263  
3264 @@ -3904,29 +3936,32 @@ static int ext4_do_update_inode(handle_t
3265         ext4_get_inode_flags(ei);
3266         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3267         if (!(test_opt(inode->i_sb, NO_UID32))) {
3268 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3269 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3270 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3271 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3272  /*
3273   * Fix up interoperability with old kernels. Otherwise, old inodes get
3274   * re-used with the upper 16 bits of the uid/gid intact
3275   */
3276                 if (!ei->i_dtime) {
3277                         raw_inode->i_uid_high =
3278 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3279 +                               cpu_to_le16(high_16_bits(uid));
3280                         raw_inode->i_gid_high =
3281 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3282 +                               cpu_to_le16(high_16_bits(gid));
3283                 } else {
3284                         raw_inode->i_uid_high = 0;
3285                         raw_inode->i_gid_high = 0;
3286                 }
3287         } else {
3288                 raw_inode->i_uid_low =
3289 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3290 +                       cpu_to_le16(fs_high2lowuid(uid));
3291                 raw_inode->i_gid_low =
3292 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3293 +                       cpu_to_le16(fs_high2lowgid(gid));
3294                 raw_inode->i_uid_high = 0;
3295                 raw_inode->i_gid_high = 0;
3296         }
3297 +#ifdef CONFIG_TAGGING_INTERN
3298 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3299 +#endif
3300         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3301  
3302         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3303 @@ -4113,7 +4148,8 @@ int ext4_setattr(struct dentry *dentry,
3304         if (is_quota_modification(inode, attr))
3305                 dquot_initialize(inode);
3306         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3307 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3308 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3309 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3310                 handle_t *handle;
3311  
3312                 /* (user+group)*(old+new) structure, inode write (sb,
3313 @@ -4135,6 +4171,8 @@ int ext4_setattr(struct dentry *dentry,
3314                         inode->i_uid = attr->ia_uid;
3315                 if (attr->ia_valid & ATTR_GID)
3316                         inode->i_gid = attr->ia_gid;
3317 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3318 +                       inode->i_tag = attr->ia_tag;
3319                 error = ext4_mark_inode_dirty(handle, inode);
3320                 ext4_journal_stop(handle);
3321         }
3322 diff -NurpP --minimal linux-3.4.32/fs/ext4/ioctl.c linux-3.4.32-vs2.3.3.9/fs/ext4/ioctl.c
3323 --- linux-3.4.32/fs/ext4/ioctl.c        2013-02-19 13:55:50.000000000 +0000
3324 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/ioctl.c      2012-09-01 08:50:49.000000000 +0000
3325 @@ -14,12 +14,40 @@
3326  #include <linux/compat.h>
3327  #include <linux/mount.h>
3328  #include <linux/file.h>
3329 +#include <linux/vs_tag.h>
3330  #include <asm/uaccess.h>
3331  #include "ext4_jbd2.h"
3332  #include "ext4.h"
3333  
3334  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3335  
3336 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3337 +{
3338 +       handle_t *handle = NULL;
3339 +       struct ext4_iloc iloc;
3340 +       int err;
3341 +
3342 +       handle = ext4_journal_start(inode, 1);
3343 +       if (IS_ERR(handle))
3344 +               return PTR_ERR(handle);
3345 +
3346 +       if (IS_SYNC(inode))
3347 +               ext4_handle_sync(handle);
3348 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3349 +       if (err)
3350 +               goto flags_err;
3351 +
3352 +       inode->i_flags = flags;
3353 +       inode->i_vflags = vflags;
3354 +       ext4_get_inode_flags(EXT4_I(inode));
3355 +       inode->i_ctime = ext4_current_time(inode);
3356 +
3357 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3358 +flags_err:
3359 +       ext4_journal_stop(handle);
3360 +       return err;
3361 +}
3362 +
3363  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3364  {
3365         struct inode *inode = filp->f_dentry->d_inode;
3366 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3367  
3368                 flags = ext4_mask_flags(inode->i_mode, flags);
3369  
3370 +               if (IS_BARRIER(inode)) {
3371 +                       vxwprintk_task(1, "messing with the barrier.");
3372 +                       return -EACCES;
3373 +               }
3374 +
3375                 err = -EPERM;
3376                 mutex_lock(&inode->i_mutex);
3377                 /* Is it quota file? Do not allow user to mess with it */
3378 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3379                  *
3380                  * This test looks nicer. Thanks to Pauline Middelink
3381                  */
3382 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3383 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3384 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3385 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3386                         if (!capable(CAP_LINUX_IMMUTABLE))
3387                                 goto flags_out;
3388                 }
3389 diff -NurpP --minimal linux-3.4.32/fs/ext4/namei.c linux-3.4.32-vs2.3.3.9/fs/ext4/namei.c
3390 --- linux-3.4.32/fs/ext4/namei.c        2013-02-19 13:55:50.000000000 +0000
3391 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/namei.c      2012-10-22 13:09:53.000000000 +0000
3392 @@ -34,6 +34,7 @@
3393  #include <linux/quotaops.h>
3394  #include <linux/buffer_head.h>
3395  #include <linux/bio.h>
3396 +#include <linux/vs_tag.h>
3397  #include "ext4.h"
3398  #include "ext4_jbd2.h"
3399  
3400 @@ -925,6 +926,7 @@ restart:
3401                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3402                                                     1, &bh);
3403                         }
3404 +               dx_propagate_tag(nd, inode);
3405                 }
3406                 if ((bh = bh_use[ra_ptr++]) == NULL)
3407                         goto next;
3408 @@ -2591,6 +2593,7 @@ const struct inode_operations ext4_dir_i
3409  #endif
3410         .get_acl        = ext4_get_acl,
3411         .fiemap         = ext4_fiemap,
3412 +       .sync_flags     = ext4_sync_flags,
3413  };
3414  
3415  const struct inode_operations ext4_special_inode_operations = {
3416 diff -NurpP --minimal linux-3.4.32/fs/ext4/super.c linux-3.4.32-vs2.3.3.9/fs/ext4/super.c
3417 --- linux-3.4.32/fs/ext4/super.c        2013-02-19 13:55:50.000000000 +0000
3418 +++ linux-3.4.32-vs2.3.3.9/fs/ext4/super.c      2013-02-11 23:38:27.000000000 +0000
3419 @@ -1188,6 +1188,7 @@ enum {
3420         Opt_inode_readahead_blks, Opt_journal_ioprio,
3421         Opt_dioread_nolock, Opt_dioread_lock,
3422         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3423 +       Opt_tag, Opt_notag, Opt_tagid
3424  };
3425  
3426  static const match_table_t tokens = {
3427 @@ -1266,6 +1267,9 @@ static const match_table_t tokens = {
3428         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3429         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3430         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3431 +       {Opt_tag, "tag"},
3432 +       {Opt_notag, "notag"},
3433 +       {Opt_tagid, "tagid=%u"},
3434         {Opt_err, NULL},
3435  };
3436  
3437 @@ -1500,6 +1504,20 @@ static int handle_mount_opt(struct super
3438                         return -1;
3439                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3440                 return 1;
3441 +#ifndef CONFIG_TAGGING_NONE
3442 +       case Opt_tag:
3443 +               set_opt(sb, TAGGED);
3444 +               return 1;
3445 +       case Opt_notag:
3446 +               clear_opt(sb, TAGGED);
3447 +               return 1;
3448 +#endif
3449 +#ifdef CONFIG_PROPAGATE
3450 +       case Opt_tagid:
3451 +               /* use args[0] */
3452 +               set_opt(sb, TAGGED);
3453 +               return 1;
3454 +#endif
3455         }
3456  
3457         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3458 @@ -3236,6 +3254,9 @@ static int ext4_fill_super(struct super_
3459                         clear_opt(sb, DELALLOC);
3460         }
3461  
3462 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3463 +               sb->s_flags |= MS_TAGGED;
3464 +
3465         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3466                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3467  
3468 @@ -4397,6 +4418,14 @@ static int ext4_remount(struct super_blo
3469         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3470                 ext4_abort(sb, "Abort forced by user");
3471  
3472 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3473 +               !(sb->s_flags & MS_TAGGED)) {
3474 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3475 +                       sb->s_id);
3476 +               err = -EINVAL;
3477 +               goto restore_opts;
3478 +       }
3479 +
3480         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3481                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3482  
3483 diff -NurpP --minimal linux-3.4.32/fs/fcntl.c linux-3.4.32-vs2.3.3.9/fs/fcntl.c
3484 --- linux-3.4.32/fs/fcntl.c     2012-05-21 16:07:20.000000000 +0000
3485 +++ linux-3.4.32-vs2.3.3.9/fs/fcntl.c   2012-05-21 16:15:05.000000000 +0000
3486 @@ -20,6 +20,7 @@
3487  #include <linux/signal.h>
3488  #include <linux/rcupdate.h>
3489  #include <linux/pid_namespace.h>
3490 +#include <linux/vs_limit.h>
3491  
3492  #include <asm/poll.h>
3493  #include <asm/siginfo.h>
3494 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3495  
3496         if (tofree)
3497                 filp_close(tofree, files);
3498 +       else
3499 +               vx_openfd_inc(newfd);   /* fd was unused */
3500  
3501         return newfd;
3502  
3503 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3504         filp = fget_raw(fd);
3505         if (!filp)
3506                 goto out;
3507 +       if (!vx_files_avail(1))
3508 +               goto out;
3509  
3510         if (unlikely(filp->f_mode & FMODE_PATH)) {
3511                 if (!check_fcntl_cmd(cmd)) {
3512 diff -NurpP --minimal linux-3.4.32/fs/file.c linux-3.4.32-vs2.3.3.9/fs/file.c
3513 --- linux-3.4.32/fs/file.c      2012-05-21 16:07:20.000000000 +0000
3514 +++ linux-3.4.32-vs2.3.3.9/fs/file.c    2012-05-21 16:15:05.000000000 +0000
3515 @@ -21,6 +21,7 @@
3516  #include <linux/spinlock.h>
3517  #include <linux/rcupdate.h>
3518  #include <linux/workqueue.h>
3519 +#include <linux/vs_limit.h>
3520  
3521  struct fdtable_defer {
3522         spinlock_t lock;
3523 @@ -358,6 +359,8 @@ struct files_struct *dup_fd(struct files
3524                 struct file *f = *old_fds++;
3525                 if (f) {
3526                         get_file(f);
3527 +                       /* TODO: sum it first for check and performance */
3528 +                       vx_openfd_inc(open_files - i);
3529                 } else {
3530                         /*
3531                          * The fd may be claimed in the fd bitmap but not yet
3532 @@ -464,6 +467,7 @@ repeat:
3533         else
3534                 __clear_close_on_exec(fd, fdt);
3535         error = fd;
3536 +       vx_openfd_inc(fd);
3537  #if 1
3538         /* Sanity check */
3539         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3540 diff -NurpP --minimal linux-3.4.32/fs/file_table.c linux-3.4.32-vs2.3.3.9/fs/file_table.c
3541 --- linux-3.4.32/fs/file_table.c        2012-05-21 16:07:20.000000000 +0000
3542 +++ linux-3.4.32-vs2.3.3.9/fs/file_table.c      2012-05-21 16:15:05.000000000 +0000
3543 @@ -24,6 +24,8 @@
3544  #include <linux/percpu_counter.h>
3545  #include <linux/percpu.h>
3546  #include <linux/ima.h>
3547 +#include <linux/vs_limit.h>
3548 +#include <linux/vs_context.h>
3549  
3550  #include <linux/atomic.h>
3551  
3552 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3553         spin_lock_init(&f->f_lock);
3554         eventpoll_init_file(f);
3555         /* f->f_version: 0 */
3556 +       f->f_xid = vx_current_xid();
3557 +       vx_files_inc(f);
3558         return f;
3559  
3560  over:
3561 @@ -252,6 +256,8 @@ static void __fput(struct file *file)
3562         }
3563         fops_put(file->f_op);
3564         put_pid(file->f_owner.pid);
3565 +       vx_files_dec(file);
3566 +       file->f_xid = 0;
3567         file_sb_list_del(file);
3568         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3569                 i_readcount_dec(inode);
3570 @@ -382,6 +388,8 @@ void put_filp(struct file *file)
3571  {
3572         if (atomic_long_dec_and_test(&file->f_count)) {
3573                 security_file_free(file);
3574 +               vx_files_dec(file);
3575 +               file->f_xid = 0;
3576                 file_sb_list_del(file);
3577                 file_free(file);
3578         }
3579 diff -NurpP --minimal linux-3.4.32/fs/fs_struct.c linux-3.4.32-vs2.3.3.9/fs/fs_struct.c
3580 --- linux-3.4.32/fs/fs_struct.c 2012-05-21 16:07:20.000000000 +0000
3581 +++ linux-3.4.32-vs2.3.3.9/fs/fs_struct.c       2012-05-21 16:15:05.000000000 +0000
3582 @@ -4,6 +4,7 @@
3583  #include <linux/path.h>
3584  #include <linux/slab.h>
3585  #include <linux/fs_struct.h>
3586 +#include <linux/vserver/global.h>
3587  #include "internal.h"
3588  
3589  static inline void path_get_longterm(struct path *path)
3590 @@ -99,6 +100,7 @@ void free_fs_struct(struct fs_struct *fs
3591  {
3592         path_put_longterm(&fs->root);
3593         path_put_longterm(&fs->pwd);
3594 +       atomic_dec(&vs_global_fs);
3595         kmem_cache_free(fs_cachep, fs);
3596  }
3597  
3598 @@ -136,6 +138,7 @@ struct fs_struct *copy_fs_struct(struct
3599                 fs->pwd = old->pwd;
3600                 path_get_longterm(&fs->pwd);
3601                 spin_unlock(&old->lock);
3602 +               atomic_inc(&vs_global_fs);
3603         }
3604         return fs;
3605  }
3606 diff -NurpP --minimal linux-3.4.32/fs/gfs2/file.c linux-3.4.32-vs2.3.3.9/fs/gfs2/file.c
3607 --- linux-3.4.32/fs/gfs2/file.c 2012-05-21 16:07:20.000000000 +0000
3608 +++ linux-3.4.32-vs2.3.3.9/fs/gfs2/file.c       2012-05-21 16:15:05.000000000 +0000
3609 @@ -142,6 +142,9 @@ static const u32 fsflags_to_gfs2[32] = {
3610         [7] = GFS2_DIF_NOATIME,
3611         [12] = GFS2_DIF_EXHASH,
3612         [14] = GFS2_DIF_INHERIT_JDATA,
3613 +       [27] = GFS2_DIF_IXUNLINK,
3614 +       [26] = GFS2_DIF_BARRIER,
3615 +       [29] = GFS2_DIF_COW,
3616  };
3617  
3618  static const u32 gfs2_to_fsflags[32] = {
3619 @@ -151,6 +154,9 @@ static const u32 gfs2_to_fsflags[32] = {
3620         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3621         [gfs2fl_ExHash] = FS_INDEX_FL,
3622         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3623 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3624 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3625 +       [gfs2fl_Cow] = FS_COW_FL,
3626  };
3627  
3628  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3629 @@ -181,12 +187,18 @@ void gfs2_set_inode_flags(struct inode *
3630  {
3631         struct gfs2_inode *ip = GFS2_I(inode);
3632         unsigned int flags = inode->i_flags;
3633 +       unsigned int vflags = inode->i_vflags;
3634 +
3635 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3636 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3637  
3638 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3639         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3640                 inode->i_flags |= S_NOSEC;
3641         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3642                 flags |= S_IMMUTABLE;
3643 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3644 +               flags |= S_IXUNLINK;
3645 +
3646         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3647                 flags |= S_APPEND;
3648         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3649 @@ -194,6 +206,43 @@ void gfs2_set_inode_flags(struct inode *
3650         if (ip->i_diskflags & GFS2_DIF_SYNC)
3651                 flags |= S_SYNC;
3652         inode->i_flags = flags;
3653 +
3654 +       vflags &= ~(V_BARRIER | V_COW);
3655 +
3656 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3657 +               vflags |= V_BARRIER;
3658 +       if (ip->i_diskflags & GFS2_DIF_COW)
3659 +               vflags |= V_COW;
3660 +       inode->i_vflags = vflags;
3661 +}
3662 +
3663 +void gfs2_get_inode_flags(struct inode *inode)
3664 +{
3665 +       struct gfs2_inode *ip = GFS2_I(inode);
3666 +       unsigned int flags = inode->i_flags;
3667 +       unsigned int vflags = inode->i_vflags;
3668 +
3669 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3670 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3671 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3672 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3673 +
3674 +       if (flags & S_IMMUTABLE)
3675 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3676 +       if (flags & S_IXUNLINK)
3677 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3678 +
3679 +       if (flags & S_APPEND)
3680 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3681 +       if (flags & S_NOATIME)
3682 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3683 +       if (flags & S_SYNC)
3684 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3685 +
3686 +       if (vflags & V_BARRIER)
3687 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3688 +       if (vflags & V_COW)
3689 +               ip->i_diskflags |= GFS2_DIF_COW;
3690  }
3691  
3692  /* Flags that can be set by user space */
3693 @@ -305,6 +354,37 @@ static int gfs2_set_flags(struct file *f
3694         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3695  }
3696  
3697 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3698 +{
3699 +       struct gfs2_inode *ip = GFS2_I(inode);
3700 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3701 +       struct buffer_head *bh;
3702 +       struct gfs2_holder gh;
3703 +       int error;
3704 +
3705 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3706 +       if (error)
3707 +               return error;
3708 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3709 +       if (error)
3710 +               goto out;
3711 +       error = gfs2_meta_inode_buffer(ip, &bh);
3712 +       if (error)
3713 +               goto out_trans_end;
3714 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3715 +       inode->i_flags = flags;
3716 +       inode->i_vflags = vflags;
3717 +       gfs2_get_inode_flags(inode);
3718 +       gfs2_dinode_out(ip, bh->b_data);
3719 +       brelse(bh);
3720 +       gfs2_set_aops(inode);
3721 +out_trans_end:
3722 +       gfs2_trans_end(sdp);
3723 +out:
3724 +       gfs2_glock_dq_uninit(&gh);
3725 +       return error;
3726 +}
3727 +
3728  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3729  {
3730         switch(cmd) {
3731 diff -NurpP --minimal linux-3.4.32/fs/gfs2/inode.h linux-3.4.32-vs2.3.3.9/fs/gfs2/inode.h
3732 --- linux-3.4.32/fs/gfs2/inode.h        2012-01-09 15:14:54.000000000 +0000
3733 +++ linux-3.4.32-vs2.3.3.9/fs/gfs2/inode.h      2012-05-21 16:15:05.000000000 +0000
3734 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3735  extern const struct file_operations gfs2_dir_fops_nolock;
3736  
3737  extern void gfs2_set_inode_flags(struct inode *inode);
3738 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3739   
3740  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3741  extern const struct file_operations gfs2_file_fops;
3742 diff -NurpP --minimal linux-3.4.32/fs/inode.c linux-3.4.32-vs2.3.3.9/fs/inode.c
3743 --- linux-3.4.32/fs/inode.c     2012-05-21 16:07:24.000000000 +0000
3744 +++ linux-3.4.32-vs2.3.3.9/fs/inode.c   2012-05-21 16:15:05.000000000 +0000
3745 @@ -17,6 +17,7 @@
3746  #include <linux/prefetch.h>
3747  #include <linux/buffer_head.h> /* for inode_has_buffers */
3748  #include <linux/ratelimit.h>
3749 +#include <linux/vs_tag.h>
3750  #include "internal.h"
3751  
3752  /*
3753 @@ -128,6 +129,9 @@ int inode_init_always(struct super_block
3754         struct address_space *const mapping = &inode->i_data;
3755  
3756         inode->i_sb = sb;
3757 +
3758 +       /* essential because of inode slab reuse */
3759 +       inode->i_tag = 0;
3760         inode->i_blkbits = sb->s_blocksize_bits;
3761         inode->i_flags = 0;
3762         atomic_set(&inode->i_count, 1);
3763 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3764         inode->i_bdev = NULL;
3765         inode->i_cdev = NULL;
3766         inode->i_rdev = 0;
3767 +       inode->i_mdev = 0;
3768         inode->dirtied_when = 0;
3769  
3770         if (security_inode_alloc(inode))
3771 @@ -470,6 +475,8 @@ void __insert_inode_hash(struct inode *i
3772  }
3773  EXPORT_SYMBOL(__insert_inode_hash);
3774  
3775 +EXPORT_SYMBOL_GPL(__iget);
3776 +
3777  /**
3778   *     __remove_inode_hash - remove an inode from the hash
3779   *     @inode: inode to unhash
3780 @@ -1689,9 +1696,11 @@ void init_special_inode(struct inode *in
3781         if (S_ISCHR(mode)) {
3782                 inode->i_fop = &def_chr_fops;
3783                 inode->i_rdev = rdev;
3784 +               inode->i_mdev = rdev;
3785         } else if (S_ISBLK(mode)) {
3786                 inode->i_fop = &def_blk_fops;
3787                 inode->i_rdev = rdev;
3788 +               inode->i_mdev = rdev;
3789         } else if (S_ISFIFO(mode))
3790                 inode->i_fop = &def_fifo_fops;
3791         else if (S_ISSOCK(mode))
3792 @@ -1720,6 +1729,7 @@ void inode_init_owner(struct inode *inod
3793         } else
3794                 inode->i_gid = current_fsgid();
3795         inode->i_mode = mode;
3796 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3797  }
3798  EXPORT_SYMBOL(inode_init_owner);
3799  
3800 diff -NurpP --minimal linux-3.4.32/fs/ioctl.c linux-3.4.32-vs2.3.3.9/fs/ioctl.c
3801 --- linux-3.4.32/fs/ioctl.c     2012-05-21 16:07:24.000000000 +0000
3802 +++ linux-3.4.32-vs2.3.3.9/fs/ioctl.c   2012-05-21 16:15:05.000000000 +0000
3803 @@ -15,6 +15,9 @@
3804  #include <linux/writeback.h>
3805  #include <linux/buffer_head.h>
3806  #include <linux/falloc.h>
3807 +#include <linux/proc_fs.h>
3808 +#include <linux/vserver/inode.h>
3809 +#include <linux/vs_tag.h>
3810  
3811  #include <asm/ioctls.h>
3812  
3813 diff -NurpP --minimal linux-3.4.32/fs/ioprio.c linux-3.4.32-vs2.3.3.9/fs/ioprio.c
3814 --- linux-3.4.32/fs/ioprio.c    2012-03-19 18:47:25.000000000 +0000
3815 +++ linux-3.4.32-vs2.3.3.9/fs/ioprio.c  2012-05-21 16:15:05.000000000 +0000
3816 @@ -28,6 +28,7 @@
3817  #include <linux/syscalls.h>
3818  #include <linux/security.h>
3819  #include <linux/pid_namespace.h>
3820 +#include <linux/vs_base.h>
3821  
3822  int set_task_ioprio(struct task_struct *task, int ioprio)
3823  {
3824 @@ -104,6 +105,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3825                         else
3826                                 pgrp = find_vpid(who);
3827                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3828 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3829 +                                       continue;
3830                                 ret = set_task_ioprio(p, ioprio);
3831                                 if (ret)
3832                                         break;
3833 @@ -193,6 +196,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3834                         else
3835                                 pgrp = find_vpid(who);
3836                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3837 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3838 +                                       continue;
3839                                 tmpio = get_task_ioprio(p);
3840                                 if (tmpio < 0)
3841                                         continue;
3842 diff -NurpP --minimal linux-3.4.32/fs/jfs/file.c linux-3.4.32-vs2.3.3.9/fs/jfs/file.c
3843 --- linux-3.4.32/fs/jfs/file.c  2011-10-24 16:45:27.000000000 +0000
3844 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/file.c        2012-05-21 16:15:05.000000000 +0000
3845 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3846         if (is_quota_modification(inode, iattr))
3847                 dquot_initialize(inode);
3848         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3849 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3850 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3851 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3852                 rc = dquot_transfer(inode, iattr);
3853                 if (rc)
3854                         return rc;
3855 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3856  #ifdef CONFIG_JFS_POSIX_ACL
3857         .get_acl        = jfs_get_acl,
3858  #endif
3859 +       .sync_flags     = jfs_sync_flags,
3860  };
3861  
3862  const struct file_operations jfs_file_operations = {
3863 diff -NurpP --minimal linux-3.4.32/fs/jfs/ioctl.c linux-3.4.32-vs2.3.3.9/fs/jfs/ioctl.c
3864 --- linux-3.4.32/fs/jfs/ioctl.c 2012-03-19 18:47:25.000000000 +0000
3865 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/ioctl.c       2012-05-21 16:15:05.000000000 +0000
3866 @@ -11,6 +11,7 @@
3867  #include <linux/mount.h>
3868  #include <linux/time.h>
3869  #include <linux/sched.h>
3870 +#include <linux/mount.h>
3871  #include <asm/current.h>
3872  #include <asm/uaccess.h>
3873  
3874 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3875  }
3876  
3877  
3878 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3879 +{
3880 +       inode->i_flags = flags;
3881 +       inode->i_vflags = vflags;
3882 +       jfs_get_inode_flags(JFS_IP(inode));
3883 +       inode->i_ctime = CURRENT_TIME_SEC;
3884 +       mark_inode_dirty(inode);
3885 +       return 0;
3886 +}
3887 +
3888  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3889  {
3890         struct inode *inode = filp->f_dentry->d_inode;
3891 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3892                 if (!S_ISDIR(inode->i_mode))
3893                         flags &= ~JFS_DIRSYNC_FL;
3894  
3895 +               if (IS_BARRIER(inode)) {
3896 +                       vxwprintk_task(1, "messing with the barrier.");
3897 +                       return -EACCES;
3898 +               }
3899 +
3900                 /* Is it quota file? Do not allow user to mess with it */
3901                 if (IS_NOQUOTA(inode)) {
3902                         err = -EPERM;
3903 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3904                  * the relevant capability.
3905                  */
3906                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3907 -                       ((flags ^ oldflags) &
3908 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3909 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3910 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3911                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3912                                 mutex_unlock(&inode->i_mutex);
3913                                 err = -EPERM;
3914 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3915                         }
3916                 }
3917  
3918 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3919 +               flags &= JFS_FL_USER_MODIFIABLE;
3920                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3921                 jfs_inode->mode2 = flags;
3922  
3923 diff -NurpP --minimal linux-3.4.32/fs/jfs/jfs_dinode.h linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_dinode.h
3924 --- linux-3.4.32/fs/jfs/jfs_dinode.h    2008-12-24 23:26:37.000000000 +0000
3925 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_dinode.h  2012-05-21 16:15:05.000000000 +0000
3926 @@ -161,9 +161,13 @@ struct dinode {
3927  
3928  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3929  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3930 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3931  
3932 -#define JFS_FL_USER_VISIBLE    0x03F80000
3933 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3934 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3935 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3936 +
3937 +#define JFS_FL_USER_VISIBLE    0x07F80000
3938 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3939  #define JFS_FL_INHERIT         0x03C80000
3940  
3941  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3942 diff -NurpP --minimal linux-3.4.32/fs/jfs/jfs_filsys.h linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_filsys.h
3943 --- linux-3.4.32/fs/jfs/jfs_filsys.h    2008-12-24 23:26:37.000000000 +0000
3944 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_filsys.h  2012-05-21 16:15:05.000000000 +0000
3945 @@ -263,6 +263,7 @@
3946  #define JFS_NAME_MAX   255
3947  #define JFS_PATH_MAX   BPSIZE
3948  
3949 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3950  
3951  /*
3952   *     file system state (superblock state)
3953 diff -NurpP --minimal linux-3.4.32/fs/jfs/jfs_imap.c linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_imap.c
3954 --- linux-3.4.32/fs/jfs/jfs_imap.c      2012-01-09 15:14:54.000000000 +0000
3955 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_imap.c    2012-05-21 16:15:05.000000000 +0000
3956 @@ -46,6 +46,7 @@
3957  #include <linux/pagemap.h>
3958  #include <linux/quotaops.h>
3959  #include <linux/slab.h>
3960 +#include <linux/vs_tag.h>
3961  
3962  #include "jfs_incore.h"
3963  #include "jfs_inode.h"
3964 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3965  {
3966         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3967         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3968 +       uid_t uid;
3969 +       gid_t gid;
3970  
3971         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3972         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3973 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3974         }
3975         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3976  
3977 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3978 +       uid = le32_to_cpu(dip->di_uid);
3979 +       gid = le32_to_cpu(dip->di_gid);
3980 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3981 +
3982 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3983         if (sbi->uid == -1)
3984                 ip->i_uid = jfs_ip->saved_uid;
3985         else {
3986                 ip->i_uid = sbi->uid;
3987         }
3988  
3989 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3990 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3991         if (sbi->gid == -1)
3992                 ip->i_gid = jfs_ip->saved_gid;
3993         else {
3994 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3995         dip->di_size = cpu_to_le64(ip->i_size);
3996         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3997         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3998 -       if (sbi->uid == -1)
3999 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4000 -       else
4001 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4002 -       if (sbi->gid == -1)
4003 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4004 -       else
4005 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4006 +
4007 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4008 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4009 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4010 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4011 +
4012         jfs_get_inode_flags(jfs_ip);
4013         /*
4014          * mode2 is only needed for storing the higher order bits.
4015 diff -NurpP --minimal linux-3.4.32/fs/jfs/jfs_inode.c linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_inode.c
4016 --- linux-3.4.32/fs/jfs/jfs_inode.c     2012-01-09 15:14:54.000000000 +0000
4017 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_inode.c   2012-05-21 16:15:05.000000000 +0000
4018 @@ -18,6 +18,7 @@
4019  
4020  #include <linux/fs.h>
4021  #include <linux/quotaops.h>
4022 +#include <linux/vs_tag.h>
4023  #include "jfs_incore.h"
4024  #include "jfs_inode.h"
4025  #include "jfs_filsys.h"
4026 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4027  {
4028         unsigned int flags = JFS_IP(inode)->mode2;
4029  
4030 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4031 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4032 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4033 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4034  
4035         if (flags & JFS_IMMUTABLE_FL)
4036                 inode->i_flags |= S_IMMUTABLE;
4037 +       if (flags & JFS_IXUNLINK_FL)
4038 +               inode->i_flags |= S_IXUNLINK;
4039 +
4040 +       if (flags & JFS_SYNC_FL)
4041 +               inode->i_flags |= S_SYNC;
4042         if (flags & JFS_APPEND_FL)
4043                 inode->i_flags |= S_APPEND;
4044         if (flags & JFS_NOATIME_FL)
4045                 inode->i_flags |= S_NOATIME;
4046         if (flags & JFS_DIRSYNC_FL)
4047                 inode->i_flags |= S_DIRSYNC;
4048 -       if (flags & JFS_SYNC_FL)
4049 -               inode->i_flags |= S_SYNC;
4050 +
4051 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4052 +
4053 +       if (flags & JFS_BARRIER_FL)
4054 +               inode->i_vflags |= V_BARRIER;
4055 +       if (flags & JFS_COW_FL)
4056 +               inode->i_vflags |= V_COW;
4057  }
4058  
4059  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4060  {
4061         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4062 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4063 +
4064 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4065 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4066 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4067 +                          JFS_BARRIER_FL | JFS_COW_FL);
4068  
4069 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4070 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4071         if (flags & S_IMMUTABLE)
4072                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4073 +       if (flags & S_IXUNLINK)
4074 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4075 +
4076         if (flags & S_APPEND)
4077                 jfs_ip->mode2 |= JFS_APPEND_FL;
4078         if (flags & S_NOATIME)
4079 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4080                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4081         if (flags & S_SYNC)
4082                 jfs_ip->mode2 |= JFS_SYNC_FL;
4083 +
4084 +       if (vflags & V_BARRIER)
4085 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4086 +       if (vflags & V_COW)
4087 +               jfs_ip->mode2 |= JFS_COW_FL;
4088  }
4089  
4090  /*
4091 diff -NurpP --minimal linux-3.4.32/fs/jfs/jfs_inode.h linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_inode.h
4092 --- linux-3.4.32/fs/jfs/jfs_inode.h     2011-10-24 16:45:27.000000000 +0000
4093 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/jfs_inode.h   2012-05-21 16:15:05.000000000 +0000
4094 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4095  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4096         int fh_len, int fh_type);
4097  extern void jfs_set_inode_flags(struct inode *);
4098 +extern int jfs_sync_flags(struct inode *, int, int);
4099  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4100  extern int jfs_setattr(struct dentry *, struct iattr *);
4101  
4102 diff -NurpP --minimal linux-3.4.32/fs/jfs/namei.c linux-3.4.32-vs2.3.3.9/fs/jfs/namei.c
4103 --- linux-3.4.32/fs/jfs/namei.c 2012-05-21 16:07:25.000000000 +0000
4104 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/namei.c       2012-05-21 16:15:05.000000000 +0000
4105 @@ -22,6 +22,7 @@
4106  #include <linux/ctype.h>
4107  #include <linux/quotaops.h>
4108  #include <linux/exportfs.h>
4109 +#include <linux/vs_tag.h>
4110  #include "jfs_incore.h"
4111  #include "jfs_superblock.h"
4112  #include "jfs_inode.h"
4113 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4114                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4115         }
4116  
4117 +       dx_propagate_tag(nd, ip);
4118         return d_splice_alias(ip, dentry);
4119  }
4120  
4121 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4122  #ifdef CONFIG_JFS_POSIX_ACL
4123         .get_acl        = jfs_get_acl,
4124  #endif
4125 +       .sync_flags     = jfs_sync_flags,
4126  };
4127  
4128  const struct file_operations jfs_dir_operations = {
4129 diff -NurpP --minimal linux-3.4.32/fs/jfs/super.c linux-3.4.32-vs2.3.3.9/fs/jfs/super.c
4130 --- linux-3.4.32/fs/jfs/super.c 2012-05-21 16:07:25.000000000 +0000
4131 +++ linux-3.4.32-vs2.3.3.9/fs/jfs/super.c       2012-05-21 16:15:05.000000000 +0000
4132 @@ -197,7 +197,8 @@ static void jfs_put_super(struct super_b
4133  enum {
4134         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4135         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4136 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4137 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4138 +       Opt_tag, Opt_notag, Opt_tagid
4139  };
4140  
4141  static const match_table_t tokens = {
4142 @@ -207,6 +208,10 @@ static const match_table_t tokens = {
4143         {Opt_resize, "resize=%u"},
4144         {Opt_resize_nosize, "resize"},
4145         {Opt_errors, "errors=%s"},
4146 +       {Opt_tag, "tag"},
4147 +       {Opt_notag, "notag"},
4148 +       {Opt_tagid, "tagid=%u"},
4149 +       {Opt_tag, "tagxid"},
4150         {Opt_ignore, "noquota"},
4151         {Opt_ignore, "quota"},
4152         {Opt_usrquota, "usrquota"},
4153 @@ -341,6 +346,20 @@ static int parse_options(char *options,
4154                         }
4155                         break;
4156                 }
4157 +#ifndef CONFIG_TAGGING_NONE
4158 +               case Opt_tag:
4159 +                       *flag |= JFS_TAGGED;
4160 +                       break;
4161 +               case Opt_notag:
4162 +                       *flag &= JFS_TAGGED;
4163 +                       break;
4164 +#endif
4165 +#ifdef CONFIG_PROPAGATE
4166 +               case Opt_tagid:
4167 +                       /* use args[0] */
4168 +                       *flag |= JFS_TAGGED;
4169 +                       break;
4170 +#endif
4171                 default:
4172                         printk("jfs: Unrecognized mount option \"%s\" "
4173                                         " or missing value\n", p);
4174 @@ -372,6 +391,12 @@ static int jfs_remount(struct super_bloc
4175                 return -EINVAL;
4176         }
4177  
4178 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4179 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4180 +                       sb->s_id);
4181 +               return -EINVAL;
4182 +       }
4183 +
4184         if (newLVSize) {
4185                 if (sb->s_flags & MS_RDONLY) {
4186                         printk(KERN_ERR
4187 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4188  #ifdef CONFIG_JFS_POSIX_ACL
4189         sb->s_flags |= MS_POSIXACL;
4190  #endif
4191 +       /* map mount option tagxid */
4192 +       if (sbi->flag & JFS_TAGGED)
4193 +               sb->s_flags |= MS_TAGGED;
4194  
4195         if (newLVSize) {
4196                 printk(KERN_ERR "resize option for remount only\n");
4197 diff -NurpP --minimal linux-3.4.32/fs/libfs.c linux-3.4.32-vs2.3.3.9/fs/libfs.c
4198 --- linux-3.4.32/fs/libfs.c     2012-05-21 16:07:25.000000000 +0000
4199 +++ linux-3.4.32-vs2.3.3.9/fs/libfs.c   2012-05-21 16:15:05.000000000 +0000
4200 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4201   * both impossible due to the lock on directory.
4202   */
4203  
4204 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4205 +static inline int do_dcache_readdir_filter(struct file *filp,
4206 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4207  {
4208         struct dentry *dentry = filp->f_path.dentry;
4209         struct dentry *cursor = filp->private_data;
4210 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4211                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4212                                 struct dentry *next;
4213                                 next = list_entry(p, struct dentry, d_u.d_child);
4214 +                               if (filter && !filter(next))
4215 +                                       continue;
4216                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4217                                 if (!simple_positive(next)) {
4218                                         spin_unlock(&next->d_lock);
4219 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4220         return 0;
4221  }
4222  
4223 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4224 +{
4225 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4226 +}
4227 +
4228 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4229 +       int (*filter)(struct dentry *))
4230 +{
4231 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4232 +}
4233 +
4234  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4235  {
4236         return -EISDIR;
4237 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4238  EXPORT_SYMBOL(dcache_dir_lseek);
4239  EXPORT_SYMBOL(dcache_dir_open);
4240  EXPORT_SYMBOL(dcache_readdir);
4241 +EXPORT_SYMBOL(dcache_readdir_filter);
4242  EXPORT_SYMBOL(generic_read_dir);
4243  EXPORT_SYMBOL(mount_pseudo);
4244  EXPORT_SYMBOL(simple_write_begin);
4245 diff -NurpP --minimal linux-3.4.32/fs/locks.c linux-3.4.32-vs2.3.3.9/fs/locks.c
4246 --- linux-3.4.32/fs/locks.c     2013-02-19 13:55:51.000000000 +0000
4247 +++ linux-3.4.32-vs2.3.3.9/fs/locks.c   2012-09-01 08:50:49.000000000 +0000
4248 @@ -126,6 +126,8 @@
4249  #include <linux/time.h>
4250  #include <linux/rcupdate.h>
4251  #include <linux/pid_namespace.h>
4252 +#include <linux/vs_base.h>
4253 +#include <linux/vs_limit.h>
4254  
4255  #include <asm/uaccess.h>
4256  
4257 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4258  /* Allocate an empty lock structure. */
4259  struct file_lock *locks_alloc_lock(void)
4260  {
4261 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4262 +       struct file_lock *fl;
4263  
4264 -       if (fl)
4265 -               locks_init_lock_heads(fl);
4266 +       if (!vx_locks_avail(1))
4267 +               return NULL;
4268  
4269 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4270 +
4271 +       if (fl) {
4272 +               locks_init_lock_heads(fl);
4273 +               fl->fl_xid = -1;
4274 +       }
4275         return fl;
4276  }
4277  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4278 @@ -216,6 +224,7 @@ void locks_free_lock(struct file_lock *f
4279         BUG_ON(!list_empty(&fl->fl_block));
4280         BUG_ON(!list_empty(&fl->fl_link));
4281  
4282 +       vx_locks_dec(fl);
4283         locks_release_private(fl);
4284         kmem_cache_free(filelock_cache, fl);
4285  }
4286 @@ -225,6 +234,7 @@ void locks_init_lock(struct file_lock *f
4287  {
4288         memset(fl, 0, sizeof(struct file_lock));
4289         locks_init_lock_heads(fl);
4290 +       fl->fl_xid = -1;
4291  }
4292  
4293  EXPORT_SYMBOL(locks_init_lock);
4294 @@ -265,6 +275,7 @@ void locks_copy_lock(struct file_lock *n
4295         new->fl_file = fl->fl_file;
4296         new->fl_ops = fl->fl_ops;
4297         new->fl_lmops = fl->fl_lmops;
4298 +       new->fl_xid = fl->fl_xid;
4299  
4300         locks_copy_private(new, fl);
4301  }
4302 @@ -303,6 +314,11 @@ static int flock_make_lock(struct file *
4303         fl->fl_flags = FL_FLOCK;
4304         fl->fl_type = type;
4305         fl->fl_end = OFFSET_MAX;
4306 +
4307 +       vxd_assert(filp->f_xid == vx_current_xid(),
4308 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4309 +       fl->fl_xid = filp->f_xid;
4310 +       vx_locks_inc(fl);
4311         
4312         *lock = fl;
4313         return 0;
4314 @@ -452,6 +468,7 @@ static int lease_init(struct file *filp,
4315  
4316         fl->fl_owner = current->files;
4317         fl->fl_pid = current->tgid;
4318 +       fl->fl_xid = vx_current_xid();
4319  
4320         fl->fl_file = filp;
4321         fl->fl_flags = FL_LEASE;
4322 @@ -471,6 +488,11 @@ static struct file_lock *lease_alloc(str
4323         if (fl == NULL)
4324                 return ERR_PTR(error);
4325  
4326 +       fl->fl_xid = vx_current_xid();
4327 +       if (filp)
4328 +               vxd_assert(filp->f_xid == fl->fl_xid,
4329 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4330 +       vx_locks_inc(fl);
4331         error = lease_init(filp, type, fl);
4332         if (error) {
4333                 locks_free_lock(fl);
4334 @@ -773,6 +795,7 @@ static int flock_lock_file(struct file *
4335                 lock_flocks();
4336         }
4337  
4338 +       new_fl->fl_xid = -1;
4339  find_conflict:
4340         for_each_lock(inode, before) {
4341                 struct file_lock *fl = *before;
4342 @@ -793,6 +816,7 @@ find_conflict:
4343                 goto out;
4344         locks_copy_lock(new_fl, request);
4345         locks_insert_lock(before, new_fl);
4346 +       vx_locks_inc(new_fl);
4347         new_fl = NULL;
4348         error = 0;
4349  
4350 @@ -803,7 +827,8 @@ out:
4351         return error;
4352  }
4353  
4354 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4355 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4356 +       struct file_lock *conflock, xid_t xid)
4357  {
4358         struct file_lock *fl;
4359         struct file_lock *new_fl = NULL;
4360 @@ -813,6 +838,8 @@ static int __posix_lock_file(struct inod
4361         struct file_lock **before;
4362         int error, added = 0;
4363  
4364 +       vxd_assert(xid == vx_current_xid(),
4365 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4366         /*
4367          * We may need two file_lock structures for this operation,
4368          * so we get them in advance to avoid races.
4369 @@ -823,7 +850,11 @@ static int __posix_lock_file(struct inod
4370             (request->fl_type != F_UNLCK ||
4371              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4372                 new_fl = locks_alloc_lock();
4373 +               new_fl->fl_xid = xid;
4374 +               vx_locks_inc(new_fl);
4375                 new_fl2 = locks_alloc_lock();
4376 +               new_fl2->fl_xid = xid;
4377 +               vx_locks_inc(new_fl2);
4378         }
4379  
4380         lock_flocks();
4381 @@ -1022,7 +1053,8 @@ static int __posix_lock_file(struct inod
4382  int posix_lock_file(struct file *filp, struct file_lock *fl,
4383                         struct file_lock *conflock)
4384  {
4385 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4386 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4387 +               fl, conflock, filp->f_xid);
4388  }
4389  EXPORT_SYMBOL(posix_lock_file);
4390  
4391 @@ -1112,7 +1144,7 @@ int locks_mandatory_area(int read_write,
4392         fl.fl_end = offset + count - 1;
4393  
4394         for (;;) {
4395 -               error = __posix_lock_file(inode, &fl, NULL);
4396 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4397                 if (error != FILE_LOCK_DEFERRED)
4398                         break;
4399                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4400 @@ -1407,6 +1439,7 @@ int generic_add_lease(struct file *filp,
4401                 goto out;
4402  
4403         locks_insert_lock(before, lease);
4404 +       vx_locks_inc(lease);
4405         return 0;
4406  
4407  out:
4408 @@ -1847,6 +1880,11 @@ int fcntl_setlk(unsigned int fd, struct
4409         if (file_lock == NULL)
4410                 return -ENOLCK;
4411  
4412 +       vxd_assert(filp->f_xid == vx_current_xid(),
4413 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4414 +       file_lock->fl_xid = filp->f_xid;
4415 +       vx_locks_inc(file_lock);
4416 +
4417         /*
4418          * This might block, so we do it before checking the inode.
4419          */
4420 @@ -1965,6 +2003,11 @@ int fcntl_setlk64(unsigned int fd, struc
4421         if (file_lock == NULL)
4422                 return -ENOLCK;
4423  
4424 +       vxd_assert(filp->f_xid == vx_current_xid(),
4425 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4426 +       file_lock->fl_xid = filp->f_xid;
4427 +       vx_locks_inc(file_lock);
4428 +
4429         /*
4430          * This might block, so we do it before checking the inode.
4431          */
4432 @@ -2230,8 +2273,11 @@ static int locks_show(struct seq_file *f
4433  
4434         lock_get_status(f, fl, *((loff_t *)f->private), "");
4435  
4436 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4437 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4438 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4439 +                       continue;
4440                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4441 +       }
4442  
4443         return 0;
4444  }
4445 diff -NurpP --minimal linux-3.4.32/fs/mount.h linux-3.4.32-vs2.3.3.9/fs/mount.h
4446 --- linux-3.4.32/fs/mount.h     2012-03-19 18:47:26.000000000 +0000
4447 +++ linux-3.4.32-vs2.3.3.9/fs/mount.h   2012-05-21 16:15:05.000000000 +0000
4448 @@ -47,6 +47,7 @@ struct mount {
4449         int mnt_expiry_mark;            /* true if marked for expiry */
4450         int mnt_pinned;
4451         int mnt_ghosts;
4452 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4453  };
4454  
4455  static inline struct mount *real_mount(struct vfsmount *mnt)
4456 diff -NurpP --minimal linux-3.4.32/fs/namei.c linux-3.4.32-vs2.3.3.9/fs/namei.c
4457 --- linux-3.4.32/fs/namei.c     2012-05-21 16:07:25.000000000 +0000
4458 +++ linux-3.4.32-vs2.3.3.9/fs/namei.c   2012-05-21 16:15:05.000000000 +0000
4459 @@ -33,6 +33,14 @@
4460  #include <linux/device_cgroup.h>
4461  #include <linux/fs_struct.h>
4462  #include <linux/posix_acl.h>
4463 +#include <linux/proc_fs.h>
4464 +#include <linux/vserver/inode.h>
4465 +#include <linux/vs_base.h>
4466 +#include <linux/vs_tag.h>
4467 +#include <linux/vs_cowbl.h>
4468 +#include <linux/vs_device.h>
4469 +#include <linux/vs_context.h>
4470 +#include <linux/pid_namespace.h>
4471  #include <asm/uaccess.h>
4472  
4473  #include "internal.h"
4474 @@ -221,6 +229,89 @@ static int check_acl(struct inode *inode
4475         return -EAGAIN;
4476  }
4477  
4478 +static inline int dx_barrier(const struct inode *inode)
4479 +{
4480 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4481 +               vxwprintk_task(1, "did hit the barrier.");
4482 +               return 1;
4483 +       }
4484 +       return 0;
4485 +}
4486 +
4487 +static int __dx_permission(const struct inode *inode, int mask)
4488 +{
4489 +       if (dx_barrier(inode))
4490 +               return -EACCES;
4491 +
4492 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4493 +               /* devpts is xid tagged */
4494 +               if (S_ISDIR(inode->i_mode) ||
4495 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4496 +                       return 0;
4497 +
4498 +               /* just pretend we didn't find anything */
4499 +               return -ENOENT;
4500 +       }
4501 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4502 +               struct proc_dir_entry *de = PDE(inode);
4503 +
4504 +               if (de && !vx_hide_check(0, de->vx_flags))
4505 +                       goto out;
4506 +
4507 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4508 +                       struct pid *pid;
4509 +                       struct task_struct *tsk;
4510 +
4511 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4512 +                           vx_flags(VXF_STATE_SETUP, 0))
4513 +                               return 0;
4514 +
4515 +                       pid = PROC_I(inode)->pid;
4516 +                       if (!pid)
4517 +                               goto out;
4518 +
4519 +                       rcu_read_lock();
4520 +                       tsk = pid_task(pid, PIDTYPE_PID);
4521 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4522 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4523 +                       if (tsk &&
4524 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4525 +                               rcu_read_unlock();
4526 +                               return 0;
4527 +                       }
4528 +                       rcu_read_unlock();
4529 +               }
4530 +               else {
4531 +                       /* FIXME: Should we block some entries here? */
4532 +                       return 0;
4533 +               }
4534 +       }
4535 +       else {
4536 +               if (dx_notagcheck(inode->i_sb) ||
4537 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4538 +                            DX_IDENT))
4539 +                       return 0;
4540 +       }
4541 +
4542 +out:
4543 +       return -EACCES;
4544 +}
4545 +
4546 +int dx_permission(const struct inode *inode, int mask)
4547 +{
4548 +       int ret = __dx_permission(inode, mask);
4549 +       if (unlikely(ret)) {
4550 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4551 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4552 +#endif
4553 +                   vxwprintk_task(1,
4554 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4555 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4556 +                       inode->i_ino);
4557 +       }
4558 +       return ret;
4559 +}
4560 +
4561  /*
4562   * This does the basic permission checking
4563   */
4564 @@ -356,10 +447,14 @@ int inode_permission(struct inode *inode
4565                 /*
4566                  * Nobody gets write access to an immutable file.
4567                  */
4568 -               if (IS_IMMUTABLE(inode))
4569 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4570                         return -EACCES;
4571         }
4572  
4573 +       retval = dx_permission(inode, mask);
4574 +       if (retval)
4575 +               return retval;
4576 +
4577         retval = do_inode_permission(inode, mask);
4578         if (retval)
4579                 return retval;
4580 @@ -1038,7 +1133,8 @@ static void follow_dotdot(struct nameida
4581  
4582                 if (nd->path.dentry == nd->root.dentry &&
4583                     nd->path.mnt == nd->root.mnt) {
4584 -                       break;
4585 +                       /* for sane '/' avoid follow_mount() */
4586 +                       return;
4587                 }
4588                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4589                         /* rare case of legitimate dget_parent()... */
4590 @@ -1174,6 +1270,9 @@ static int do_lookup(struct nameidata *n
4591                                 goto unlazy;
4592                         }
4593                 }
4594 +
4595 +               /* FIXME: check dx permission */
4596 +
4597                 path->mnt = mnt;
4598                 path->dentry = dentry;
4599                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4600 @@ -1208,6 +1307,9 @@ unlazy:
4601                         goto need_lookup;
4602                 }
4603         }
4604 +
4605 +       /* FIXME: check dx permission */
4606 +
4607  done:
4608         path->mnt = mnt;
4609         path->dentry = dentry;
4610 @@ -1981,7 +2083,7 @@ static int may_delete(struct inode *dir,
4611         if (IS_APPEND(dir))
4612                 return -EPERM;
4613         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4614 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4615 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4616                 return -EPERM;
4617         if (isdir) {
4618                 if (!S_ISDIR(victim->d_inode->i_mode))
4619 @@ -2061,19 +2163,25 @@ int vfs_create(struct inode *dir, struct
4620  {
4621         int error = may_create(dir, dentry);
4622  
4623 -       if (error)
4624 +       if (error) {
4625 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4626                 return error;
4627 +       }
4628  
4629         if (!dir->i_op->create)
4630                 return -EACCES; /* shouldn't it be ENOSYS? */
4631         mode &= S_IALLUGO;
4632         mode |= S_IFREG;
4633         error = security_inode_create(dir, dentry, mode);
4634 -       if (error)
4635 +       if (error) {
4636 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4637                 return error;
4638 +       }
4639         error = dir->i_op->create(dir, dentry, mode, nd);
4640         if (!error)
4641                 fsnotify_create(dir, dentry);
4642 +       else
4643 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4644         return error;
4645  }
4646  
4647 @@ -2108,6 +2216,15 @@ static int may_open(struct path *path, i
4648                 break;
4649         }
4650  
4651 +#ifdef CONFIG_VSERVER_COWBL
4652 +       if (IS_COW(inode) &&
4653 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4654 +               if (IS_COW_LINK(inode))
4655 +                       return -EMLINK;
4656 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4657 +               mark_inode_dirty(inode);
4658 +       }
4659 +#endif
4660         error = inode_permission(inode, acc_mode);
4661         if (error)
4662                 return error;
4663 @@ -2332,6 +2449,16 @@ ok:
4664         }
4665  common:
4666         error = may_open(&nd->path, acc_mode, open_flag);
4667 +#ifdef CONFIG_VSERVER_COWBL
4668 +       if (error == -EMLINK) {
4669 +               struct dentry *dentry;
4670 +               dentry = cow_break_link(pathname);
4671 +               if (IS_ERR(dentry))
4672 +                       error = PTR_ERR(dentry);
4673 +               else
4674 +                       dput(dentry);
4675 +       }
4676 +#endif
4677         if (error)
4678                 goto exit;
4679         filp = nameidata_to_filp(nd);
4680 @@ -2374,6 +2501,7 @@ static struct file *path_openat(int dfd,
4681         struct path path;
4682         int error;
4683  
4684 +restart:
4685         filp = get_empty_filp();
4686         if (!filp)
4687                 return ERR_PTR(-ENFILE);
4688 @@ -2411,6 +2539,17 @@ static struct file *path_openat(int dfd,
4689                         filp = do_last(nd, &path, op, pathname);
4690                 put_link(nd, &link, cookie);
4691         }
4692 +
4693 +#ifdef CONFIG_VSERVER_COWBL
4694 +       if (filp == ERR_PTR(-EMLINK)) {
4695 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4696 +                       path_put(&nd->root);
4697 +               if (base)
4698 +                       fput(base);
4699 +               release_open_intent(nd);
4700 +               goto restart;
4701 +       }
4702 +#endif
4703  out:
4704         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4705                 path_put(&nd->root);
4706 @@ -2500,6 +2639,11 @@ struct dentry *kern_path_create(int dfd,
4707                 goto fail;
4708         }
4709         *path = nd.path;
4710 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4711 +               path->dentry, path->dentry->d_name.len,
4712 +               path->dentry->d_name.name, dentry,
4713 +               dentry->d_name.len, dentry->d_name.name,
4714 +               path->dentry->d_inode);
4715         return dentry;
4716  eexist:
4717         dput(dentry);
4718 @@ -2986,7 +3130,7 @@ int vfs_link(struct dentry *old_dentry,
4719         /*
4720          * A link to an append-only or immutable file cannot be created.
4721          */
4722 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4723 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4724                 return -EPERM;
4725         if (!dir->i_op->link)
4726                 return -EPERM;
4727 @@ -3375,6 +3519,253 @@ int vfs_follow_link(struct nameidata *nd
4728         return __vfs_follow_link(nd, link);
4729  }
4730  
4731 +
4732 +#ifdef CONFIG_VSERVER_COWBL
4733 +
4734 +static inline
4735 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4736 +{
4737 +       loff_t ppos = 0;
4738 +
4739 +       return do_splice_direct(in, &ppos, out, len, 0);
4740 +}
4741 +
4742 +extern unsigned int mnt_get_count(struct mount *mnt);
4743 +
4744 +struct dentry *cow_break_link(const char *pathname)
4745 +{
4746 +       int ret, mode, pathlen, redo = 0;
4747 +       struct nameidata old_nd, dir_nd;
4748 +       struct path old_path, dir_path;
4749 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4750 +       struct file *old_file;
4751 +       struct file *new_file;
4752 +       char *to, *path, pad='\251';
4753 +       loff_t size;
4754 +
4755 +       vxdprintk(VXD_CBIT(misc, 1),
4756 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4757 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4758 +       ret = -ENOMEM;
4759 +       if (!path)
4760 +               goto out;
4761 +
4762 +       /* old_nd will have refs to dentry and mnt */
4763 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4764 +       vxdprintk(VXD_CBIT(misc, 2),
4765 +               "do_path_lookup(old): %d [r=%d]",
4766 +               ret, mnt_get_count(real_mount(old_nd.path.mnt)));
4767 +       if (ret < 0)
4768 +               goto out_free_path;
4769 +
4770 +       old_path = old_nd.path;
4771 +       old_dentry = old_path.dentry;
4772 +       mode = old_dentry->d_inode->i_mode;
4773 +
4774 +       to = d_path(&old_path, path, PATH_MAX-2);
4775 +       pathlen = strlen(to);
4776 +       vxdprintk(VXD_CBIT(misc, 2),
4777 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4778 +               old_dentry,
4779 +               old_dentry->d_name.len, old_dentry->d_name.name,
4780 +               old_dentry->d_name.len);
4781 +
4782 +       to[pathlen + 1] = 0;
4783 +retry:
4784 +       new_dentry = NULL;
4785 +       to[pathlen] = pad--;
4786 +       ret = -ELOOP;
4787 +       if (pad <= '\240')
4788 +               goto out_rel_old;
4789 +
4790 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4791 +       /* dir_nd will have refs to dentry and mnt */
4792 +       ret = do_path_lookup(AT_FDCWD, to,
4793 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4794 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4795 +       if (ret < 0)
4796 +               goto retry;
4797 +
4798 +       /* this puppy downs the dir inode mutex if successful */
4799 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4800 +       if (!new_dentry || IS_ERR(new_dentry)) {
4801 +               path_put(&dir_nd.path);
4802 +               vxdprintk(VXD_CBIT(misc, 2),
4803 +                       "kern_path_create(new) failed with %ld",
4804 +                       PTR_ERR(new_dentry));
4805 +               goto retry;
4806 +       }
4807 +       path_put(&dir_path);
4808 +       vxdprintk(VXD_CBIT(misc, 2),
4809 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4810 +               new_dentry,
4811 +               new_dentry->d_name.len, new_dentry->d_name.name,
4812 +               new_dentry->d_name.len);
4813 +
4814 +       dir = dir_nd.path.dentry;
4815 +
4816 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4817 +       vxdprintk(VXD_CBIT(misc, 2),
4818 +               "vfs_create(new): %d", ret);
4819 +       if (ret == -EEXIST) {
4820 +               mutex_unlock(&dir->d_inode->i_mutex);
4821 +               path_put(&dir_nd.path);
4822 +               dput(new_dentry);
4823 +               goto retry;
4824 +       }
4825 +       else if (ret < 0)
4826 +               goto out_unlock_new;
4827 +
4828 +       /* drop out early, ret passes ENOENT */
4829 +       ret = -ENOENT;
4830 +       if ((redo = d_unhashed(old_dentry)))
4831 +               goto out_unlock_new;
4832 +
4833 +       path_get(&old_path);
4834 +       /* this one cleans up the dentry/mnt in case of failure */
4835 +       old_file = dentry_open(old_dentry, old_path.mnt,
4836 +               O_RDONLY, current_cred());
4837 +       vxdprintk(VXD_CBIT(misc, 2),
4838 +               "dentry_open(old): %p", old_file);
4839 +       if (IS_ERR(old_file)) {
4840 +               ret = PTR_ERR(old_file);
4841 +               goto out_unlock_new;
4842 +       }
4843 +
4844 +       dget(new_dentry);
4845 +       mntget(old_path.mnt);
4846 +       /* this one cleans up the dentry/mnt in case of failure */
4847 +       new_file = dentry_open(new_dentry, old_path.mnt,
4848 +               O_WRONLY, current_cred());
4849 +       vxdprintk(VXD_CBIT(misc, 2),
4850 +               "dentry_open(new): %p", new_file);
4851 +       if (IS_ERR(new_file)) {
4852 +               ret = PTR_ERR(new_file);
4853 +               goto out_fput_old;
4854 +       }
4855 +
4856 +       size = i_size_read(old_file->f_dentry->d_inode);
4857 +       ret = do_cow_splice(old_file, new_file, size);
4858 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4859 +       if (ret < 0) {
4860 +               goto out_fput_both;
4861 +       } else if (ret < size) {
4862 +               ret = -ENOSPC;
4863 +               goto out_fput_both;
4864 +       } else {
4865 +               struct inode *old_inode = old_dentry->d_inode;
4866 +               struct inode *new_inode = new_dentry->d_inode;
4867 +               struct iattr attr = {
4868 +                       .ia_uid = old_inode->i_uid,
4869 +                       .ia_gid = old_inode->i_gid,
4870 +                       .ia_valid = ATTR_UID | ATTR_GID
4871 +                       };
4872 +
4873 +               setattr_copy(new_inode, &attr);
4874 +               mark_inode_dirty(new_inode);
4875 +       }
4876 +
4877 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4878 +
4879 +       /* drop out late */
4880 +       ret = -ENOENT;
4881 +       if ((redo = d_unhashed(old_dentry)))
4882 +               goto out_unlock;
4883 +
4884 +       vxdprintk(VXD_CBIT(misc, 2),
4885 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4886 +               new_dentry->d_name.len, new_dentry->d_name.name,
4887 +               new_dentry->d_name.len,
4888 +               old_dentry->d_name.len, old_dentry->d_name.name,
4889 +               old_dentry->d_name.len);
4890 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4891 +               old_dentry->d_parent->d_inode, old_dentry);
4892 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4893 +
4894 +out_unlock:
4895 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4896 +
4897 +out_fput_both:
4898 +       vxdprintk(VXD_CBIT(misc, 3),
4899 +               "fput(new_file=%p[#%ld])", new_file,
4900 +               atomic_long_read(&new_file->f_count));
4901 +       fput(new_file);
4902 +
4903 +out_fput_old:
4904 +       vxdprintk(VXD_CBIT(misc, 3),
4905 +               "fput(old_file=%p[#%ld])", old_file,
4906 +               atomic_long_read(&old_file->f_count));
4907 +       fput(old_file);
4908 +
4909 +out_unlock_new:
4910 +       mutex_unlock(&dir->d_inode->i_mutex);
4911 +       if (!ret)
4912 +               goto out_redo;
4913 +
4914 +       /* error path cleanup */
4915 +       vfs_unlink(dir->d_inode, new_dentry);
4916 +
4917 +out_redo:
4918 +       if (!redo)
4919 +               goto out_rel_both;
4920 +       /* lookup dentry once again */
4921 +       /* old_nd.path is freed as old_path in out_rel_old */
4922 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4923 +       if (ret)
4924 +               goto out_rel_both;
4925 +
4926 +       dput(new_dentry);
4927 +       new_dentry = old_nd.path.dentry;
4928 +       vxdprintk(VXD_CBIT(misc, 2),
4929 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4930 +               new_dentry,
4931 +               new_dentry->d_name.len, new_dentry->d_name.name,
4932 +               new_dentry->d_name.len);
4933 +       dget(new_dentry);
4934 +
4935 +out_rel_both:
4936 +       path_put(&dir_nd.path);
4937 +out_rel_old:
4938 +       path_put(&old_path);
4939 +out_free_path:
4940 +       kfree(path);
4941 +out:
4942 +       if (ret) {
4943 +               dput(new_dentry);
4944 +               new_dentry = ERR_PTR(ret);
4945 +       }
4946 +       vxdprintk(VXD_CBIT(misc, 3),
4947 +               "cow_break_link returning with %p [r=%d]",
4948 +               new_dentry, mnt_get_count(real_mount(old_nd.path.mnt)));
4949 +       return new_dentry;
4950 +}
4951 +
4952 +#endif
4953 +
4954 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4955 +{
4956 +       struct path path;
4957 +       struct vfsmount *vmnt;
4958 +       char *pstr, *root;
4959 +       int length = 0;
4960 +
4961 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4962 +       if (!pstr)
4963 +               return 0;
4964 +
4965 +       vmnt = &ns->root->mnt;
4966 +       path.mnt = vmnt;
4967 +       path.dentry = vmnt->mnt_root;
4968 +       root = d_path(&path, pstr, PATH_MAX - 2);
4969 +       length = sprintf(buffer + length,
4970 +               "Namespace:\t%p [#%u]\n"
4971 +               "RootPath:\t%s\n",
4972 +               ns, atomic_read(&ns->count),
4973 +               root);
4974 +       kfree(pstr);
4975 +       return length;
4976 +}
4977 +
4978  /* get the link contents into pagecache */
4979  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4980  {
4981 @@ -3499,3 +3890,4 @@ EXPORT_SYMBOL(vfs_symlink);
4982  EXPORT_SYMBOL(vfs_unlink);
4983  EXPORT_SYMBOL(dentry_unhash);
4984  EXPORT_SYMBOL(generic_readlink);
4985 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4986 diff -NurpP --minimal linux-3.4.32/fs/namespace.c linux-3.4.32-vs2.3.3.9/fs/namespace.c
4987 --- linux-3.4.32/fs/namespace.c 2013-02-19 13:55:51.000000000 +0000
4988 +++ linux-3.4.32-vs2.3.3.9/fs/namespace.c       2012-06-28 14:45:07.000000000 +0000
4989 @@ -20,6 +20,11 @@
4990  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4991  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4992  #include <linux/uaccess.h>
4993 +#include <linux/vs_base.h>
4994 +#include <linux/vs_context.h>
4995 +#include <linux/vs_tag.h>
4996 +#include <linux/vserver/space.h>
4997 +#include <linux/vserver/global.h>
4998  #include "pnode.h"
4999  #include "internal.h"
5000  
5001 @@ -697,6 +702,10 @@ vfs_kern_mount(struct file_system_type *
5002         if (!type)
5003                 return ERR_PTR(-ENODEV);
5004  
5005 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
5006 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
5007 +               return ERR_PTR(-EPERM);
5008 +
5009         mnt = alloc_vfsmnt(name);
5010         if (!mnt)
5011                 return ERR_PTR(-ENOMEM);
5012 @@ -745,6 +754,7 @@ static struct mount *clone_mnt(struct mo
5013                 mnt->mnt.mnt_root = dget(root);
5014                 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
5015                 mnt->mnt_parent = mnt;
5016 +               mnt->mnt_tag = old->mnt_tag;
5017                 br_write_lock(vfsmount_lock);
5018                 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
5019                 br_write_unlock(vfsmount_lock);
5020 @@ -1210,7 +1220,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5021                 goto dput_and_out;
5022  
5023         retval = -EPERM;
5024 -       if (!capable(CAP_SYS_ADMIN))
5025 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5026                 goto dput_and_out;
5027  
5028         retval = do_umount(mnt, flags);
5029 @@ -1236,7 +1246,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5030  
5031  static int mount_is_safe(struct path *path)
5032  {
5033 -       if (capable(CAP_SYS_ADMIN))
5034 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5035                 return 0;
5036         return -EPERM;
5037  #ifdef notyet
5038 @@ -1549,7 +1559,7 @@ static int do_change_type(struct path *p
5039         int type;
5040         int err = 0;
5041  
5042 -       if (!capable(CAP_SYS_ADMIN))
5043 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5044                 return -EPERM;
5045  
5046         if (path->dentry != path->mnt->mnt_root)
5047 @@ -1565,6 +1575,7 @@ static int do_change_type(struct path *p
5048                 if (err)
5049                         goto out_unlock;
5050         }
5051 +       // mnt->mnt_flags = mnt_flags;
5052  
5053         br_write_lock(vfsmount_lock);
5054         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5055 @@ -1580,12 +1591,14 @@ static int do_change_type(struct path *p
5056   * do loopback mount.
5057   */
5058  static int do_loopback(struct path *path, char *old_name,
5059 -                               int recurse)
5060 +       tag_t tag, unsigned long flags, int mnt_flags)
5061  {
5062         LIST_HEAD(umount_list);
5063         struct path old_path;
5064         struct mount *mnt = NULL, *old;
5065         int err = mount_is_safe(path);
5066 +       int recurse = flags & MS_REC;
5067 +
5068         if (err)
5069                 return err;
5070         if (!old_name || !*old_name)
5071 @@ -1653,13 +1666,13 @@ static int change_mount_flags(struct vfs
5072   * on it - tough luck.
5073   */
5074  static int do_remount(struct path *path, int flags, int mnt_flags,
5075 -                     void *data)
5076 +       void *data, xid_t xid)
5077  {
5078         int err;
5079         struct super_block *sb = path->mnt->mnt_sb;
5080         struct mount *mnt = real_mount(path->mnt);
5081  
5082 -       if (!capable(CAP_SYS_ADMIN))
5083 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5084                 return -EPERM;
5085  
5086         if (!check_mnt(mnt))
5087 @@ -1708,7 +1721,7 @@ static int do_move_mount(struct path *pa
5088         struct mount *p;
5089         struct mount *old;
5090         int err = 0;
5091 -       if (!capable(CAP_SYS_ADMIN))
5092 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5093                 return -EPERM;
5094         if (!old_name || !*old_name)
5095                 return -EINVAL;
5096 @@ -1859,7 +1872,7 @@ static int do_new_mount(struct path *pat
5097                 return -EINVAL;
5098  
5099         /* we need capabilities... */
5100 -       if (!capable(CAP_SYS_ADMIN))
5101 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5102                 return -EPERM;
5103  
5104         mnt = do_kern_mount(type, flags, name, data);
5105 @@ -2129,6 +2142,7 @@ long do_mount(char *dev_name, char *dir_
5106         struct path path;
5107         int retval = 0;
5108         int mnt_flags = 0;
5109 +       tag_t tag = 0;
5110  
5111         /* Discard magic */
5112         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5113 @@ -2156,6 +2170,12 @@ long do_mount(char *dev_name, char *dir_
5114         if (!(flags & MS_NOATIME))
5115                 mnt_flags |= MNT_RELATIME;
5116  
5117 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5118 +               /* FIXME: bind and re-mounts get the tag flag? */
5119 +               if (flags & (MS_BIND|MS_REMOUNT))
5120 +                       flags |= MS_TAGID;
5121 +       }
5122 +
5123         /* Separate the per-mountpoint flags */
5124         if (flags & MS_NOSUID)
5125                 mnt_flags |= MNT_NOSUID;
5126 @@ -2172,15 +2192,17 @@ long do_mount(char *dev_name, char *dir_
5127         if (flags & MS_RDONLY)
5128                 mnt_flags |= MNT_READONLY;
5129  
5130 +       if (!capable(CAP_SYS_ADMIN))
5131 +               mnt_flags |= MNT_NODEV;
5132         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5133                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5134                    MS_STRICTATIME);
5135  
5136         if (flags & MS_REMOUNT)
5137                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5138 -                                   data_page);
5139 +                                   data_page, tag);
5140         else if (flags & MS_BIND)
5141 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5142 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5143         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5144                 retval = do_change_type(&path, flags);
5145         else if (flags & MS_MOVE)
5146 @@ -2283,6 +2305,7 @@ static struct mnt_namespace *dup_mnt_ns(
5147                 q = next_mnt(q, new);
5148         }
5149         up_write(&namespace_sem);
5150 +       atomic_inc(&vs_global_mnt_ns);
5151  
5152         if (rootmnt)
5153                 mntput(rootmnt);
5154 @@ -2479,9 +2502,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5155         error = -EINVAL;
5156         new_mnt = real_mount(new.mnt);
5157         root_mnt = real_mount(root.mnt);
5158 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5159 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5160                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5161 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5162 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5163 +               !vx_flags(VXF_STATE_SETUP, 0))
5164                 goto out4;
5165         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5166                 goto out4;
5167 @@ -2602,6 +2626,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5168         br_write_unlock(vfsmount_lock);
5169         up_write(&namespace_sem);
5170         release_mounts(&umount_list);
5171 +       atomic_dec(&vs_global_mnt_ns);
5172         kfree(ns);
5173  }
5174  
5175 diff -NurpP --minimal linux-3.4.32/fs/nfs/client.c linux-3.4.32-vs2.3.3.9/fs/nfs/client.c
5176 --- linux-3.4.32/fs/nfs/client.c        2013-02-19 13:55:51.000000000 +0000
5177 +++ linux-3.4.32-vs2.3.3.9/fs/nfs/client.c      2013-01-16 00:15:57.000000000 +0000
5178 @@ -801,6 +801,9 @@ static int nfs_init_server_rpcclient(str
5179         if (server->flags & NFS_MOUNT_SOFT)
5180                 server->client->cl_softrtry = 1;
5181  
5182 +       server->client->cl_tag = 0;
5183 +       if (server->flags & NFS_MOUNT_TAGGED)
5184 +               server->client->cl_tag = 1;
5185         return 0;
5186  }
5187  
5188 @@ -976,6 +979,10 @@ static void nfs_server_set_fsinfo(struct
5189                 server->acdirmin = server->acdirmax = 0;
5190         }
5191  
5192 +       /* FIXME: needs fsinfo
5193 +       if (server->flags & NFS_MOUNT_TAGGED)
5194 +               sb->s_flags |= MS_TAGGED;       */
5195 +
5196         server->maxfilesize = fsinfo->maxfilesize;
5197  
5198         server->time_delta = fsinfo->time_delta;
5199 diff -NurpP --minimal linux-3.4.32/fs/nfs/dir.c linux-3.4.32-vs2.3.3.9/fs/nfs/dir.c
5200 --- linux-3.4.32/fs/nfs/dir.c   2013-02-19 13:55:51.000000000 +0000
5201 +++ linux-3.4.32-vs2.3.3.9/fs/nfs/dir.c 2013-01-16 00:15:57.000000000 +0000
5202 @@ -35,6 +35,7 @@
5203  #include <linux/sched.h>
5204  #include <linux/kmemleak.h>
5205  #include <linux/xattr.h>
5206 +#include <linux/vs_tag.h>
5207  
5208  #include "delegation.h"
5209  #include "iostat.h"
5210 @@ -1314,6 +1315,7 @@ static struct dentry *nfs_lookup(struct
5211         if (IS_ERR(res))
5212                 goto out_unblock_sillyrename;
5213  
5214 +       dx_propagate_tag(nd, inode);
5215  no_entry:
5216         res = d_materialise_unique(dentry, inode);
5217         if (res != NULL) {
5218 diff -NurpP --minimal linux-3.4.32/fs/nfs/inode.c linux-3.4.32-vs2.3.3.9/fs/nfs/inode.c
5219 --- linux-3.4.32/fs/nfs/inode.c 2013-02-19 13:55:51.000000000 +0000
5220 +++ linux-3.4.32-vs2.3.3.9/fs/nfs/inode.c       2012-10-22 13:09:53.000000000 +0000
5221 @@ -40,6 +40,7 @@
5222  #include <linux/compat.h>
5223  #include <linux/freezer.h>
5224  #include <linux/crc32.h>
5225 +#include <linux/vs_tag.h>
5226  
5227  #include <asm/uaccess.h>
5228  
5229 @@ -275,6 +276,8 @@ nfs_fhget(struct super_block *sb, struct
5230         if (inode->i_state & I_NEW) {
5231                 struct nfs_inode *nfsi = NFS_I(inode);
5232                 unsigned long now = jiffies;
5233 +               uid_t uid;
5234 +               gid_t gid;
5235  
5236                 /* We set i_ino for the few things that still rely on it,
5237                  * such as stat(2) */
5238 @@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5239                 inode->i_version = 0;
5240                 inode->i_size = 0;
5241                 clear_nlink(inode);
5242 -               inode->i_uid = -2;
5243 -               inode->i_gid = -2;
5244 +               uid = -2;
5245 +               gid = -2;
5246                 inode->i_blocks = 0;
5247                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5248  
5249 @@ -361,13 +364,13 @@ nfs_fhget(struct super_block *sb, struct
5250                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5251                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5252                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5253 -                       inode->i_uid = fattr->uid;
5254 +                       uid = fattr->uid;
5255                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5256                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5257                                 | NFS_INO_INVALID_ACCESS
5258                                 | NFS_INO_INVALID_ACL;
5259                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5260 -                       inode->i_gid = fattr->gid;
5261 +                       gid = fattr->gid;
5262                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5263                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5264                                 | NFS_INO_INVALID_ACCESS
5265 @@ -380,6 +383,11 @@ nfs_fhget(struct super_block *sb, struct
5266                          */
5267                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5268                 }
5269 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5270 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5271 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5272 +                               /* maybe fattr->xid someday */
5273 +
5274                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5275                 nfsi->attrtimeo_timestamp = now;
5276                 nfsi->access_cache = RB_ROOT;
5277 @@ -497,6 +505,8 @@ void nfs_setattr_update_inode(struct ino
5278                         inode->i_uid = attr->ia_uid;
5279                 if ((attr->ia_valid & ATTR_GID) != 0)
5280                         inode->i_gid = attr->ia_gid;
5281 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5282 +                       inode->i_tag = attr->ia_tag;
5283                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5284                 spin_unlock(&inode->i_lock);
5285         }
5286 @@ -946,6 +956,9 @@ static int nfs_check_inode_attributes(st
5287         struct nfs_inode *nfsi = NFS_I(inode);
5288         loff_t cur_size, new_isize;
5289         unsigned long invalid = 0;
5290 +       uid_t uid;
5291 +       gid_t gid;
5292 +       tag_t tag;
5293  
5294  
5295         /* Has the inode gone and changed behind our back? */
5296 @@ -969,13 +982,18 @@ static int nfs_check_inode_attributes(st
5297                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5298         }
5299  
5300 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5301 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5302 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5303 +
5304         /* Have any file permissions changed? */
5305         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5306                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5307 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5308 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5309                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5310 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5311 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5312                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5313 +               /* maybe check for tag too? */
5314  
5315         /* Has the link count changed? */
5316         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5317 @@ -1273,6 +1291,9 @@ static int nfs_update_inode(struct inode
5318         unsigned long invalid = 0;
5319         unsigned long now = jiffies;
5320         unsigned long save_cache_validity;
5321 +       uid_t uid;
5322 +       gid_t gid;
5323 +       tag_t tag;
5324  
5325         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5326                         __func__, inode->i_sb->s_id, inode->i_ino,
5327 @@ -1381,6 +1402,9 @@ static int nfs_update_inode(struct inode
5328                                 | NFS_INO_REVAL_PAGECACHE
5329                                 | NFS_INO_REVAL_FORCED);
5330  
5331 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5332 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5333 +       tag = inode->i_tag;
5334  
5335         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5336                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5337 @@ -1402,9 +1426,9 @@ static int nfs_update_inode(struct inode
5338                                 | NFS_INO_REVAL_FORCED);
5339  
5340         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5341 -               if (inode->i_uid != fattr->uid) {
5342 +               if (uid != fattr->uid) {
5343                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5344 -                       inode->i_uid = fattr->uid;
5345 +                       uid = fattr->uid;
5346                 }
5347         } else if (server->caps & NFS_CAP_OWNER)
5348                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5349 @@ -1413,9 +1437,9 @@ static int nfs_update_inode(struct inode
5350                                 | NFS_INO_REVAL_FORCED);
5351  
5352         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5353 -               if (inode->i_gid != fattr->gid) {
5354 +               if (gid != fattr->gid) {
5355                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5356 -                       inode->i_gid = fattr->gid;
5357 +                       gid = fattr->gid;
5358                 }
5359         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5360                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5361 @@ -1423,6 +1447,10 @@ static int nfs_update_inode(struct inode
5362                                 | NFS_INO_INVALID_ACL
5363                                 | NFS_INO_REVAL_FORCED);
5364  
5365 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5366 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5367 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5368 +
5369         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5370                 if (inode->i_nlink != fattr->nlink) {
5371                         invalid |= NFS_INO_INVALID_ATTR;
5372 diff -NurpP --minimal linux-3.4.32/fs/nfs/nfs3xdr.c linux-3.4.32-vs2.3.3.9/fs/nfs/nfs3xdr.c
5373 --- linux-3.4.32/fs/nfs/nfs3xdr.c       2012-05-21 16:07:25.000000000 +0000
5374 +++ linux-3.4.32-vs2.3.3.9/fs/nfs/nfs3xdr.c     2012-05-21 16:15:05.000000000 +0000
5375 @@ -20,6 +20,7 @@
5376  #include <linux/nfs3.h>
5377  #include <linux/nfs_fs.h>
5378  #include <linux/nfsacl.h>
5379 +#include <linux/vs_tag.h>
5380  #include "internal.h"
5381  
5382  #define NFSDBG_FACILITY                NFSDBG_XDR
5383 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5384   *             set_mtime       mtime;
5385   *     };
5386   */
5387 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5388 +static void encode_sattr3(struct xdr_stream *xdr,
5389 +       const struct iattr *attr, int tag)
5390  {
5391         u32 nbytes;
5392         __be32 *p;
5393 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5394         } else
5395                 *p++ = xdr_zero;
5396  
5397 -       if (attr->ia_valid & ATTR_UID) {
5398 +       if (attr->ia_valid & ATTR_UID ||
5399 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5400                 *p++ = xdr_one;
5401 -               *p++ = cpu_to_be32(attr->ia_uid);
5402 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5403 +                       attr->ia_uid, attr->ia_tag));
5404         } else
5405                 *p++ = xdr_zero;
5406  
5407 -       if (attr->ia_valid & ATTR_GID) {
5408 +       if (attr->ia_valid & ATTR_GID ||
5409 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5410                 *p++ = xdr_one;
5411 -               *p++ = cpu_to_be32(attr->ia_gid);
5412 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5413 +                       attr->ia_gid, attr->ia_tag));
5414         } else
5415                 *p++ = xdr_zero;
5416  
5417 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5418                                       const struct nfs3_sattrargs *args)
5419  {
5420         encode_nfs_fh3(xdr, args->fh);
5421 -       encode_sattr3(xdr, args->sattr);
5422 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5423         encode_sattrguard3(xdr, args);
5424  }
5425  
5426 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5427   *     };
5428   */
5429  static void encode_createhow3(struct xdr_stream *xdr,
5430 -                             const struct nfs3_createargs *args)
5431 +       const struct nfs3_createargs *args, int tag)
5432  {
5433         encode_uint32(xdr, args->createmode);
5434         switch (args->createmode) {
5435         case NFS3_CREATE_UNCHECKED:
5436         case NFS3_CREATE_GUARDED:
5437 -               encode_sattr3(xdr, args->sattr);
5438 +               encode_sattr3(xdr, args->sattr, tag);
5439                 break;
5440         case NFS3_CREATE_EXCLUSIVE:
5441                 encode_createverf3(xdr, args->verifier);
5442 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5443                                      const struct nfs3_createargs *args)
5444  {
5445         encode_diropargs3(xdr, args->fh, args->name, args->len);
5446 -       encode_createhow3(xdr, args);
5447 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5448  }
5449  
5450  /*
5451 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5452                                     const struct nfs3_mkdirargs *args)
5453  {
5454         encode_diropargs3(xdr, args->fh, args->name, args->len);
5455 -       encode_sattr3(xdr, args->sattr);
5456 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5457  }
5458  
5459  /*
5460 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5461   *     };
5462   */
5463  static void encode_symlinkdata3(struct xdr_stream *xdr,
5464 -                               const struct nfs3_symlinkargs *args)
5465 +       const struct nfs3_symlinkargs *args, int tag)
5466  {
5467 -       encode_sattr3(xdr, args->sattr);
5468 +       encode_sattr3(xdr, args->sattr, tag);
5469         encode_nfspath3(xdr, args->pages, args->pathlen);
5470  }
5471  
5472 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5473                                       const struct nfs3_symlinkargs *args)
5474  {
5475         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5476 -       encode_symlinkdata3(xdr, args);
5477 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5478  }
5479  
5480  /*
5481 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5482   *     };
5483   */
5484  static void encode_devicedata3(struct xdr_stream *xdr,
5485 -                              const struct nfs3_mknodargs *args)
5486 +       const struct nfs3_mknodargs *args, int tag)
5487  {
5488 -       encode_sattr3(xdr, args->sattr);
5489 +       encode_sattr3(xdr, args->sattr, tag);
5490         encode_specdata3(xdr, args->rdev);
5491  }
5492  
5493  static void encode_mknoddata3(struct xdr_stream *xdr,
5494 -                             const struct nfs3_mknodargs *args)
5495 +       const struct nfs3_mknodargs *args, int tag)
5496  {
5497         encode_ftype3(xdr, args->type);
5498         switch (args->type) {
5499         case NF3CHR:
5500         case NF3BLK:
5501 -               encode_devicedata3(xdr, args);
5502 +               encode_devicedata3(xdr, args, tag);
5503                 break;
5504         case NF3SOCK:
5505         case NF3FIFO:
5506 -               encode_sattr3(xdr, args->sattr);
5507 +               encode_sattr3(xdr, args->sattr, tag);
5508                 break;
5509         case NF3REG:
5510         case NF3DIR:
5511 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5512                                     const struct nfs3_mknodargs *args)
5513  {
5514         encode_diropargs3(xdr, args->fh, args->name, args->len);
5515 -       encode_mknoddata3(xdr, args);
5516 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5517  }
5518  
5519  /*
5520 diff -NurpP --minimal linux-3.4.32/fs/nfs/super.c linux-3.4.32-vs2.3.3.9/fs/nfs/super.c
5521 --- linux-3.4.32/fs/nfs/super.c 2013-02-19 13:55:51.000000000 +0000
5522 +++ linux-3.4.32-vs2.3.3.9/fs/nfs/super.c       2013-01-16 00:15:57.000000000 +0000
5523 @@ -54,6 +54,7 @@
5524  #include <linux/parser.h>
5525  #include <linux/nsproxy.h>
5526  #include <linux/rcupdate.h>
5527 +#include <linux/vs_tag.h>
5528  
5529  #include <asm/uaccess.h>
5530  
5531 @@ -86,6 +87,7 @@ enum {
5532         Opt_sharecache, Opt_nosharecache,
5533         Opt_resvport, Opt_noresvport,
5534         Opt_fscache, Opt_nofscache,
5535 +       Opt_tag, Opt_notag,
5536  
5537         /* Mount options that take integer arguments */
5538         Opt_port,
5539 @@ -98,6 +100,7 @@ enum {
5540         Opt_mountport,
5541         Opt_mountvers,
5542         Opt_minorversion,
5543 +       Opt_tagid,
5544  
5545         /* Mount options that take string arguments */
5546         Opt_nfsvers,
5547 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5548         /* The following needs to be listed after all other options */
5549         { Opt_nfsvers, "v%s" },
5550  
5551 +       { Opt_tag, "tag" },
5552 +       { Opt_notag, "notag" },
5553 +       { Opt_tagid, "tagid=%u" },
5554 +
5555         { Opt_err, NULL }
5556  };
5557  
5558 @@ -674,6 +681,7 @@ static void nfs_show_mount_options(struc
5559                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5560                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5561                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5562 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5563                 { 0, NULL, NULL }
5564         };
5565         const struct proc_nfs_info *nfs_infop;
5566 @@ -1286,6 +1294,14 @@ static int nfs_parse_mount_options(char
5567                         kfree(mnt->fscache_uniq);
5568                         mnt->fscache_uniq = NULL;
5569                         break;
5570 +#ifndef CONFIG_TAGGING_NONE
5571 +               case Opt_tag:
5572 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5573 +                       break;
5574 +               case Opt_notag:
5575 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5576 +                       break;
5577 +#endif
5578  
5579                 /*
5580                  * options that take numeric values
5581 @@ -1372,6 +1388,12 @@ static int nfs_parse_mount_options(char
5582                                 goto out_invalid_value;
5583                         mnt->minorversion = option;
5584                         break;
5585 +#ifdef CONFIG_PROPAGATE
5586 +               case Opt_tagid:
5587 +                       /* use args[0] */
5588 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5589 +                       break;
5590 +#endif
5591  
5592                 /*
5593                  * options that take text values
5594 diff -NurpP --minimal linux-3.4.32/fs/nfsd/auth.c linux-3.4.32-vs2.3.3.9/fs/nfsd/auth.c
5595 --- linux-3.4.32/fs/nfsd/auth.c 2010-02-25 10:52:05.000000000 +0000
5596 +++ linux-3.4.32-vs2.3.3.9/fs/nfsd/auth.c       2012-05-21 16:15:05.000000000 +0000
5597 @@ -1,6 +1,7 @@
5598  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5599  
5600  #include <linux/sched.h>
5601 +#include <linux/vs_tag.h>
5602  #include "nfsd.h"
5603  #include "auth.h"
5604  
5605 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5606  
5607         new->fsuid = rqstp->rq_cred.cr_uid;
5608         new->fsgid = rqstp->rq_cred.cr_gid;
5609 +       /* FIXME: this desperately needs a tag :)
5610 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5611 +                       */
5612  
5613         rqgi = rqstp->rq_cred.cr_group_info;
5614  
5615 diff -NurpP --minimal linux-3.4.32/fs/nfsd/nfs3xdr.c linux-3.4.32-vs2.3.3.9/fs/nfsd/nfs3xdr.c
5616 --- linux-3.4.32/fs/nfsd/nfs3xdr.c      2012-05-21 16:07:26.000000000 +0000
5617 +++ linux-3.4.32-vs2.3.3.9/fs/nfsd/nfs3xdr.c    2012-05-21 16:15:05.000000000 +0000
5618 @@ -7,6 +7,7 @@
5619   */
5620  
5621  #include <linux/namei.h>
5622 +#include <linux/vs_tag.h>
5623  #include "xdr3.h"
5624  #include "auth.h"
5625  
5626 @@ -95,6 +96,8 @@ static __be32 *
5627  decode_sattr3(__be32 *p, struct iattr *iap)
5628  {
5629         u32     tmp;
5630 +       uid_t   uid = 0;
5631 +       gid_t   gid = 0;
5632  
5633         iap->ia_valid = 0;
5634  
5635 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5636         }
5637         if (*p++) {
5638                 iap->ia_valid |= ATTR_UID;
5639 -               iap->ia_uid = ntohl(*p++);
5640 +               uid = ntohl(*p++);
5641         }
5642         if (*p++) {
5643                 iap->ia_valid |= ATTR_GID;
5644 -               iap->ia_gid = ntohl(*p++);
5645 +               gid = ntohl(*p++);
5646         }
5647 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5648 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5649 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5650         if (*p++) {
5651                 u64     newsize;
5652  
5653 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5654         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5655         *p++ = htonl((u32) stat->mode);
5656         *p++ = htonl((u32) stat->nlink);
5657 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5658 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5659 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5660 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5661 +               stat->uid, stat->tag)));
5662 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5663 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5664 +               stat->gid, stat->tag)));
5665         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5666                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5667         } else {
5668 diff -NurpP --minimal linux-3.4.32/fs/nfsd/nfs4xdr.c linux-3.4.32-vs2.3.3.9/fs/nfsd/nfs4xdr.c
5669 --- linux-3.4.32/fs/nfsd/nfs4xdr.c      2013-02-19 13:55:51.000000000 +0000
5670 +++ linux-3.4.32-vs2.3.3.9/fs/nfsd/nfs4xdr.c    2013-01-16 00:15:57.000000000 +0000
5671 @@ -46,6 +46,7 @@
5672  #include <linux/utsname.h>
5673  #include <linux/pagemap.h>
5674  #include <linux/sunrpc/svcauth_gss.h>
5675 +#include <linux/vs_tag.h>
5676  
5677  #include "idmap.h"
5678  #include "acl.h"
5679 @@ -2325,14 +2326,18 @@ out_acl:
5680                 WRITE32(stat.nlink);
5681         }
5682         if (bmval1 & FATTR4_WORD1_OWNER) {
5683 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5684 +               status = nfsd4_encode_user(rqstp,
5685 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5686 +                       stat.uid, stat.tag), &p, &buflen);
5687                 if (status == nfserr_resource)
5688                         goto out_resource;
5689                 if (status)
5690                         goto out;
5691         }
5692         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5693 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5694 +               status = nfsd4_encode_group(rqstp,
5695 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5696 +                       stat.gid, stat.tag), &p, &buflen);
5697                 if (status == nfserr_resource)
5698                         goto out_resource;
5699                 if (status)
5700 diff -NurpP --minimal linux-3.4.32/fs/nfsd/nfsxdr.c linux-3.4.32-vs2.3.3.9/fs/nfsd/nfsxdr.c
5701 --- linux-3.4.32/fs/nfsd/nfsxdr.c       2011-05-22 14:17:53.000000000 +0000
5702 +++ linux-3.4.32-vs2.3.3.9/fs/nfsd/nfsxdr.c     2012-05-21 16:15:05.000000000 +0000
5703 @@ -6,6 +6,7 @@
5704  
5705  #include "xdr.h"
5706  #include "auth.h"
5707 +#include <linux/vs_tag.h>
5708  
5709  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5710  
5711 @@ -88,6 +89,8 @@ static __be32 *
5712  decode_sattr(__be32 *p, struct iattr *iap)
5713  {
5714         u32     tmp, tmp1;
5715 +       uid_t   uid = 0;
5716 +       gid_t   gid = 0;
5717  
5718         iap->ia_valid = 0;
5719  
5720 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5721         }
5722         if ((tmp = ntohl(*p++)) != (u32)-1) {
5723                 iap->ia_valid |= ATTR_UID;
5724 -               iap->ia_uid = tmp;
5725 +               uid = tmp;
5726         }
5727         if ((tmp = ntohl(*p++)) != (u32)-1) {
5728                 iap->ia_valid |= ATTR_GID;
5729 -               iap->ia_gid = tmp;
5730 +               gid = tmp;
5731         }
5732 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5733 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5734 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5735         if ((tmp = ntohl(*p++)) != (u32)-1) {
5736                 iap->ia_valid |= ATTR_SIZE;
5737                 iap->ia_size = tmp;
5738 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5739         *p++ = htonl(nfs_ftypes[type >> 12]);
5740         *p++ = htonl((u32) stat->mode);
5741         *p++ = htonl((u32) stat->nlink);
5742 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5743 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5744 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5745 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5746 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5747 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5748  
5749         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5750                 *p++ = htonl(NFS_MAXPATHLEN);
5751 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/dlmglue.c linux-3.4.32-vs2.3.3.9/fs/ocfs2/dlmglue.c
5752 --- linux-3.4.32/fs/ocfs2/dlmglue.c     2012-01-09 15:14:55.000000000 +0000
5753 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/dlmglue.c   2012-05-21 16:15:05.000000000 +0000
5754 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5755         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5756         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5757         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5758 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5759         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5760         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5761         lvb->lvb_iatime_packed  =
5762 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5763  
5764         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5765         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5766 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5767         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5768         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5769         ocfs2_unpack_timespec(&inode->i_atime,
5770 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/dlmglue.h linux-3.4.32-vs2.3.3.9/fs/ocfs2/dlmglue.h
5771 --- linux-3.4.32/fs/ocfs2/dlmglue.h     2010-10-21 11:07:50.000000000 +0000
5772 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/dlmglue.h   2012-05-21 16:15:05.000000000 +0000
5773 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5774         __be16       lvb_inlink;
5775         __be32       lvb_iattr;
5776         __be32       lvb_igeneration;
5777 -       __be32       lvb_reserved2;
5778 +       __be16       lvb_itag;
5779 +       __be16       lvb_reserved2;
5780  };
5781  
5782  #define OCFS2_QINFO_LVB_VERSION 1
5783 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/file.c linux-3.4.32-vs2.3.3.9/fs/ocfs2/file.c
5784 --- linux-3.4.32/fs/ocfs2/file.c        2013-02-19 13:55:52.000000000 +0000
5785 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/file.c      2012-07-17 22:29:43.000000000 +0000
5786 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5787                 attr->ia_valid &= ~ATTR_SIZE;
5788  
5789  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5790 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5791 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5792         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5793                 return 0;
5794  
5795 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/inode.c linux-3.4.32-vs2.3.3.9/fs/ocfs2/inode.c
5796 --- linux-3.4.32/fs/ocfs2/inode.c       2012-01-09 15:14:55.000000000 +0000
5797 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/inode.c     2012-05-21 16:15:05.000000000 +0000
5798 @@ -28,6 +28,7 @@
5799  #include <linux/highmem.h>
5800  #include <linux/pagemap.h>
5801  #include <linux/quotaops.h>
5802 +#include <linux/vs_tag.h>
5803  
5804  #include <asm/byteorder.h>
5805  
5806 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5807  {
5808         unsigned int flags = OCFS2_I(inode)->ip_attr;
5809  
5810 -       inode->i_flags &= ~(S_IMMUTABLE |
5811 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5812                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5813  
5814         if (flags & OCFS2_IMMUTABLE_FL)
5815                 inode->i_flags |= S_IMMUTABLE;
5816 +       if (flags & OCFS2_IXUNLINK_FL)
5817 +               inode->i_flags |= S_IXUNLINK;
5818  
5819         if (flags & OCFS2_SYNC_FL)
5820                 inode->i_flags |= S_SYNC;
5821 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5822                 inode->i_flags |= S_NOATIME;
5823         if (flags & OCFS2_DIRSYNC_FL)
5824                 inode->i_flags |= S_DIRSYNC;
5825 +
5826 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5827 +
5828 +       if (flags & OCFS2_BARRIER_FL)
5829 +               inode->i_vflags |= V_BARRIER;
5830 +       if (flags & OCFS2_COW_FL)
5831 +               inode->i_vflags |= V_COW;
5832  }
5833  
5834  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5835  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5836  {
5837         unsigned int flags = oi->vfs_inode.i_flags;
5838 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5839 +
5840 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5841 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5842 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5843 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5844 +
5845 +       if (flags & S_IMMUTABLE)
5846 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5847 +       if (flags & S_IXUNLINK)
5848 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5849  
5850 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5851 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5852         if (flags & S_SYNC)
5853                 oi->ip_attr |= OCFS2_SYNC_FL;
5854         if (flags & S_APPEND)
5855                 oi->ip_attr |= OCFS2_APPEND_FL;
5856 -       if (flags & S_IMMUTABLE)
5857 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5858         if (flags & S_NOATIME)
5859                 oi->ip_attr |= OCFS2_NOATIME_FL;
5860         if (flags & S_DIRSYNC)
5861                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5862 +
5863 +       if (vflags & V_BARRIER)
5864 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5865 +       if (vflags & V_COW)
5866 +               oi->ip_attr |= OCFS2_COW_FL;
5867  }
5868  
5869  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5870 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5871         struct super_block *sb;
5872         struct ocfs2_super *osb;
5873         int use_plocks = 1;
5874 +       uid_t uid;
5875 +       gid_t gid;
5876  
5877         sb = inode->i_sb;
5878         osb = OCFS2_SB(sb);
5879 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5880         inode->i_generation = le32_to_cpu(fe->i_generation);
5881         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5882         inode->i_mode = le16_to_cpu(fe->i_mode);
5883 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5884 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5885 +       uid = le32_to_cpu(fe->i_uid);
5886 +       gid = le32_to_cpu(fe->i_gid);
5887 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5888 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5889 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5890 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5891  
5892         /* Fast symlinks will have i_size but no allocated clusters. */
5893         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5894 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/inode.h linux-3.4.32-vs2.3.3.9/fs/ocfs2/inode.h
5895 --- linux-3.4.32/fs/ocfs2/inode.h       2012-01-09 15:14:55.000000000 +0000
5896 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/inode.h     2012-05-21 16:15:05.000000000 +0000
5897 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5898  
5899  void ocfs2_set_inode_flags(struct inode *inode);
5900  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5901 +int ocfs2_sync_flags(struct inode *inode, int, int);
5902  
5903  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5904  {
5905 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/ioctl.c linux-3.4.32-vs2.3.3.9/fs/ocfs2/ioctl.c
5906 --- linux-3.4.32/fs/ocfs2/ioctl.c       2012-05-21 16:07:26.000000000 +0000
5907 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/ioctl.c     2012-05-21 16:15:05.000000000 +0000
5908 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5909         return status;
5910  }
5911  
5912 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5913 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5914 +{
5915 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5916 +       struct buffer_head *bh = NULL;
5917 +       handle_t *handle = NULL;
5918 +       int status;
5919 +
5920 +       status = ocfs2_inode_lock(inode, &bh, 1);
5921 +       if (status < 0) {
5922 +               mlog_errno(status);
5923 +               return status;
5924 +       }
5925 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5926 +       if (IS_ERR(handle)) {
5927 +               status = PTR_ERR(handle);
5928 +               mlog_errno(status);
5929 +               goto bail_unlock;
5930 +       }
5931 +
5932 +       inode->i_flags = flags;
5933 +       inode->i_vflags = vflags;
5934 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5935 +
5936 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5937 +       if (status < 0)
5938 +               mlog_errno(status);
5939 +
5940 +       ocfs2_commit_trans(osb, handle);
5941 +bail_unlock:
5942 +       ocfs2_inode_unlock(inode, 1);
5943 +       brelse(bh);
5944 +       return status;
5945 +}
5946 +
5947 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5948                                 unsigned mask)
5949  {
5950         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5951 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5952         if (!S_ISDIR(inode->i_mode))
5953                 flags &= ~OCFS2_DIRSYNC_FL;
5954  
5955 +       if (IS_BARRIER(inode)) {
5956 +               vxwprintk_task(1, "messing with the barrier.");
5957 +               goto bail_unlock;
5958 +       }
5959 +
5960         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5961         if (IS_ERR(handle)) {
5962                 status = PTR_ERR(handle);
5963 @@ -879,6 +918,7 @@ bail:
5964         return status;
5965  }
5966  
5967 +
5968  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5969  {
5970         struct inode *inode = filp->f_path.dentry->d_inode;
5971 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/namei.c linux-3.4.32-vs2.3.3.9/fs/ocfs2/namei.c
5972 --- linux-3.4.32/fs/ocfs2/namei.c       2012-03-19 18:47:26.000000000 +0000
5973 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/namei.c     2012-05-21 16:15:05.000000000 +0000
5974 @@ -41,6 +41,7 @@
5975  #include <linux/slab.h>
5976  #include <linux/highmem.h>
5977  #include <linux/quotaops.h>
5978 +#include <linux/vs_tag.h>
5979  
5980  #include <cluster/masklog.h>
5981  
5982 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5983         struct ocfs2_dinode *fe = NULL;
5984         struct ocfs2_extent_list *fel;
5985         u16 feat;
5986 +       tag_t tag;
5987  
5988         *new_fe_bh = NULL;
5989  
5990 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5991         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5992         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5993         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5994 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5995 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5996 +
5997 +       tag = dx_current_fstag(osb->sb);
5998 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5999 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6000 +       inode->i_tag = tag;
6001         fe->i_mode = cpu_to_le16(inode->i_mode);
6002         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6003                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6004 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/ocfs2.h linux-3.4.32-vs2.3.3.9/fs/ocfs2/ocfs2.h
6005 --- linux-3.4.32/fs/ocfs2/ocfs2.h       2012-01-09 15:14:55.000000000 +0000
6006 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/ocfs2.h     2012-05-21 16:15:05.000000000 +0000
6007 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6008                                                      writes */
6009         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6010         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6011 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6012  };
6013  
6014  #define OCFS2_OSB_SOFT_RO                      0x0001
6015 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/ocfs2_fs.h linux-3.4.32-vs2.3.3.9/fs/ocfs2/ocfs2_fs.h
6016 --- linux-3.4.32/fs/ocfs2/ocfs2_fs.h    2011-05-22 14:17:53.000000000 +0000
6017 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/ocfs2_fs.h  2012-05-21 16:15:05.000000000 +0000
6018 @@ -266,6 +266,11 @@
6019  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6020  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6021  
6022 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6023 +
6024 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6025 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6026 +
6027  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6028  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6029  
6030 diff -NurpP --minimal linux-3.4.32/fs/ocfs2/super.c linux-3.4.32-vs2.3.3.9/fs/ocfs2/super.c
6031 --- linux-3.4.32/fs/ocfs2/super.c       2012-05-21 16:07:26.000000000 +0000
6032 +++ linux-3.4.32-vs2.3.3.9/fs/ocfs2/super.c     2012-05-21 16:15:05.000000000 +0000
6033 @@ -185,6 +185,7 @@ enum {
6034         Opt_coherency_full,
6035         Opt_resv_level,
6036         Opt_dir_resv_level,
6037 +       Opt_tag, Opt_notag, Opt_tagid,
6038         Opt_err,
6039  };
6040  
6041 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
6042         {Opt_coherency_full, "coherency=full"},
6043         {Opt_resv_level, "resv_level=%u"},
6044         {Opt_dir_resv_level, "dir_resv_level=%u"},
6045 +       {Opt_tag, "tag"},
6046 +       {Opt_notag, "notag"},
6047 +       {Opt_tagid, "tagid=%u"},
6048         {Opt_err, NULL}
6049  };
6050  
6051 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6052                 goto out;
6053         }
6054  
6055 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6056 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6057 +               ret = -EINVAL;
6058 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6059 +               goto out;
6060 +       }
6061 +
6062         /* We're going to/from readonly mode. */
6063         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6064                 /* Disable quota accounting before remounting RO */
6065 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6066  
6067         ocfs2_complete_mount_recovery(osb);
6068  
6069 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6070 +               sb->s_flags |= MS_TAGGED;
6071 +
6072         if (ocfs2_mount_local(osb))
6073                 snprintf(nodestr, sizeof(nodestr), "local");
6074         else
6075 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
6076                             option < OCFS2_MAX_RESV_LEVEL)
6077                                 mopt->dir_resv_level = option;
6078                         break;
6079 +#ifndef CONFIG_TAGGING_NONE
6080 +               case Opt_tag:
6081 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6082 +                       break;
6083 +               case Opt_notag:
6084 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6085 +                       break;
6086 +#endif
6087 +#ifdef CONFIG_PROPAGATE
6088 +               case Opt_tagid:
6089 +                       /* use args[0] */
6090 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6091 +                       break;
6092 +#endif
6093                 default:
6094                         mlog(ML_ERROR,
6095                              "Unrecognized mount option \"%s\" "
6096 diff -NurpP --minimal linux-3.4.32/fs/open.c linux-3.4.32-vs2.3.3.9/fs/open.c
6097 --- linux-3.4.32/fs/open.c      2013-02-19 13:55:52.000000000 +0000
6098 +++ linux-3.4.32-vs2.3.3.9/fs/open.c    2012-09-16 18:49:11.000000000 +0000
6099 @@ -30,6 +30,11 @@
6100  #include <linux/fs_struct.h>
6101  #include <linux/ima.h>
6102  #include <linux/dnotify.h>
6103 +#include <linux/vs_base.h>
6104 +#include <linux/vs_limit.h>
6105 +#include <linux/vs_tag.h>
6106 +#include <linux/vs_cowbl.h>
6107 +#include <linux/vserver/dlimit.h>
6108  
6109  #include "internal.h"
6110  
6111 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6112         error = user_path(pathname, &path);
6113         if (error)
6114                 goto out;
6115 +
6116 +#ifdef CONFIG_VSERVER_COWBL
6117 +       error = cow_check_and_break(&path);
6118 +       if (error)
6119 +               goto dput_and_out;
6120 +#endif
6121         inode = path.dentry->d_inode;
6122  
6123         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6124 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6125  
6126         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6127         if (!error) {
6128 +#ifdef CONFIG_VSERVER_COWBL
6129 +               error = cow_check_and_break(&path);
6130 +               if (!error)
6131 +#endif
6132                 error = chmod_common(&path, mode);
6133                 path_put(&path);
6134         }
6135 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6136         newattrs.ia_valid =  ATTR_CTIME;
6137         if (user != (uid_t) -1) {
6138                 newattrs.ia_valid |= ATTR_UID;
6139 -               newattrs.ia_uid = user;
6140 +               newattrs.ia_uid = dx_map_uid(user);
6141         }
6142         if (group != (gid_t) -1) {
6143                 newattrs.ia_valid |= ATTR_GID;
6144 -               newattrs.ia_gid = group;
6145 +               newattrs.ia_gid = dx_map_gid(group);
6146         }
6147         if (!S_ISDIR(inode->i_mode))
6148                 newattrs.ia_valid |=
6149 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6150         error = mnt_want_write(path.mnt);
6151         if (error)
6152                 goto out_release;
6153 +#ifdef CONFIG_VSERVER_COWBL
6154 +       error = cow_check_and_break(&path);
6155 +       if (!error)
6156 +#endif
6157         error = chown_common(&path, user, group);
6158         mnt_drop_write(path.mnt);
6159  out_release:
6160 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6161         error = mnt_want_write(path.mnt);
6162         if (error)
6163                 goto out_release;
6164 +#ifdef CONFIG_VSERVER_COWBL
6165 +       error = cow_check_and_break(&path);
6166 +       if (!error)
6167 +#endif
6168         error = chown_common(&path, user, group);
6169         mnt_drop_write(path.mnt);
6170  out_release:
6171 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6172         error = mnt_want_write(path.mnt);
6173         if (error)
6174                 goto out_release;
6175 +#ifdef CONFIG_VSERVER_COWBL
6176 +       error = cow_check_and_break(&path);
6177 +       if (!error)
6178 +#endif
6179         error = chown_common(&path, user, group);
6180         mnt_drop_write(path.mnt);
6181  out_release:
6182 @@ -839,6 +866,7 @@ static void __put_unused_fd(struct files
6183         __clear_open_fd(fd, fdt);
6184         if (fd < files->next_fd)
6185                 files->next_fd = fd;
6186 +       vx_openfd_dec(fd);
6187  }
6188  
6189  void put_unused_fd(unsigned int fd)
6190 diff -NurpP --minimal linux-3.4.32/fs/proc/array.c linux-3.4.32-vs2.3.3.9/fs/proc/array.c
6191 --- linux-3.4.32/fs/proc/array.c        2012-05-21 16:07:26.000000000 +0000
6192 +++ linux-3.4.32-vs2.3.3.9/fs/proc/array.c      2012-05-21 16:15:05.000000000 +0000
6193 @@ -81,6 +81,8 @@
6194  #include <linux/pid_namespace.h>
6195  #include <linux/ptrace.h>
6196  #include <linux/tracehook.h>
6197 +#include <linux/vs_context.h>
6198 +#include <linux/vs_network.h>
6199  
6200  #include <asm/pgtable.h>
6201  #include <asm/processor.h>
6202 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6203         rcu_read_lock();
6204         ppid = pid_alive(p) ?
6205                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6206 +       if (unlikely(vx_current_initpid(p->pid)))
6207 +               ppid = 0;
6208 +
6209         tpid = 0;
6210         if (pid_alive(p)) {
6211                 struct task_struct *tracer = ptrace_parent(p);
6212 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6213  }
6214  
6215  static void render_cap_t(struct seq_file *m, const char *header,
6216 -                       kernel_cap_t *a)
6217 +                       struct vx_info *vxi, kernel_cap_t *a)
6218  {
6219         unsigned __capi;
6220  
6221 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6222         cap_bset        = cred->cap_bset;
6223         rcu_read_unlock();
6224  
6225 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6226 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6227 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6228 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6229 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6230 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6231 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6232 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6233 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6234  }
6235  
6236  static inline void task_context_switch_counts(struct seq_file *m,
6237 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6238         seq_putc(m, '\n');
6239  }
6240  
6241 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6242 +                       struct pid *pid, struct task_struct *task)
6243 +{
6244 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6245 +                       "Count:\t%u\n"
6246 +                       "uts:\t%p(%c)\n"
6247 +                       "ipc:\t%p(%c)\n"
6248 +                       "mnt:\t%p(%c)\n"
6249 +                       "pid:\t%p(%c)\n"
6250 +                       "net:\t%p(%c)\n",
6251 +                       task->nsproxy,
6252 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6253 +                       atomic_read(&task->nsproxy->count),
6254 +                       task->nsproxy->uts_ns,
6255 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6256 +                       task->nsproxy->ipc_ns,
6257 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6258 +                       task->nsproxy->mnt_ns,
6259 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6260 +                       task->nsproxy->pid_ns,
6261 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6262 +                       task->nsproxy->net_ns,
6263 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6264 +       return 0;
6265 +}
6266 +
6267 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6268 +{
6269 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6270 +               return;
6271 +
6272 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6273 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6274 +}
6275 +
6276 +
6277  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6278                         struct pid *pid, struct task_struct *task)
6279  {
6280 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m,
6281         task_cap(m, task);
6282         task_cpus_allowed(m, task);
6283         cpuset_task_status_allowed(m, task);
6284 +       task_vs_id(m, task);
6285         task_context_switch_counts(m, task);
6286         return 0;
6287  }
6288 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file
6289         /* convert nsec -> ticks */
6290         start_time = nsec_to_clock_t(start_time);
6291  
6292 +       /* fixup start time for virt uptime */
6293 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6294 +               unsigned long long bias =
6295 +                       current->vx_info->cvirt.bias_clock;
6296 +
6297 +               if (start_time > bias)
6298 +                       start_time -= bias;
6299 +               else
6300 +                       start_time = 0;
6301 +       }
6302 +
6303         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6304         seq_put_decimal_ll(m, ' ', ppid);
6305         seq_put_decimal_ll(m, ' ', pgid);
6306 diff -NurpP --minimal linux-3.4.32/fs/proc/base.c linux-3.4.32-vs2.3.3.9/fs/proc/base.c
6307 --- linux-3.4.32/fs/proc/base.c 2013-02-19 13:55:52.000000000 +0000
6308 +++ linux-3.4.32-vs2.3.3.9/fs/proc/base.c       2012-06-28 14:45:07.000000000 +0000
6309 @@ -84,6 +84,8 @@
6310  #include <linux/fs_struct.h>
6311  #include <linux/slab.h>
6312  #include <linux/flex_array.h>
6313 +#include <linux/vs_context.h>
6314 +#include <linux/vs_network.h>
6315  #ifdef CONFIG_HARDWALL
6316  #include <asm/hardwall.h>
6317  #endif
6318 @@ -937,11 +939,16 @@ static ssize_t oom_adjust_write(struct f
6319                 goto err_task_lock;
6320         }
6321  
6322 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6323 +       if (oom_adjust < task->signal->oom_adj &&
6324 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6325                 err = -EACCES;
6326                 goto err_sighand;
6327         }
6328  
6329 +       /* prevent guest processes from circumventing the oom killer */
6330 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6331 +               oom_adjust = OOM_ADJUST_MIN;
6332 +
6333         /*
6334          * Warn that /proc/pid/oom_adj is deprecated, see
6335          * Documentation/feature-removal-schedule.txt.
6336 @@ -1541,6 +1548,8 @@ struct inode *proc_pid_make_inode(struct
6337                 inode->i_gid = cred->egid;
6338                 rcu_read_unlock();
6339         }
6340 +       /* procfs is xid tagged */
6341 +       inode->i_tag = (tag_t)vx_task_xid(task);
6342         security_task_to_inode(task, inode);
6343  
6344  out:
6345 @@ -1586,6 +1595,8 @@ int pid_getattr(struct vfsmount *mnt, st
6346  
6347  /* dentry stuff */
6348  
6349 +static unsigned name_to_int(struct dentry *dentry);
6350 +
6351  /*
6352   *     Exceptional case: normally we are not allowed to unhash a busy
6353   * directory. In this case, however, we can do it - no aliasing problems
6354 @@ -1614,6 +1625,12 @@ int pid_revalidate(struct dentry *dentry
6355         task = get_proc_task(inode);
6356  
6357         if (task) {
6358 +               unsigned pid = name_to_int(dentry);
6359 +
6360 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6361 +                       put_task_struct(task);
6362 +                       goto drop;
6363 +               }
6364                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6365                     task_dumpable(task)) {
6366                         rcu_read_lock();
6367 @@ -1630,6 +1647,7 @@ int pid_revalidate(struct dentry *dentry
6368                 put_task_struct(task);
6369                 return 1;
6370         }
6371 +drop:
6372         d_drop(dentry);
6373         return 0;
6374  }
6375 @@ -2452,6 +2470,13 @@ static struct dentry *proc_pident_lookup
6376         if (!task)
6377                 goto out_no_task;
6378  
6379 +       /* TODO: maybe we can come up with a generic approach? */
6380 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6381 +               (dentry->d_name.len == 5) &&
6382 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6383 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6384 +               goto out;
6385 +
6386         /*
6387          * Yes, it does not scale. And it should not. Don't add
6388          * new entries into /proc/<tgid>/ without very good reasons.
6389 @@ -2837,7 +2862,7 @@ out_iput:
6390  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6391  {
6392         struct dentry *error;
6393 -       struct task_struct *task = get_proc_task(dir);
6394 +       struct task_struct *task = get_proc_task_real(dir);
6395         const struct pid_entry *p, *last;
6396  
6397         error = ERR_PTR(-ENOENT);
6398 @@ -2944,6 +2969,9 @@ static int proc_pid_personality(struct s
6399  static const struct file_operations proc_task_operations;
6400  static const struct inode_operations proc_task_inode_operations;
6401  
6402 +extern int proc_pid_vx_info(struct task_struct *, char *);
6403 +extern int proc_pid_nx_info(struct task_struct *, char *);
6404 +
6405  static const struct pid_entry tgid_base_stuff[] = {
6406         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6407         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6408 @@ -3010,6 +3038,8 @@ static const struct pid_entry tgid_base_
6409  #ifdef CONFIG_CGROUPS
6410         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6411  #endif
6412 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6413 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6414         INF("oom_score",  S_IRUGO, proc_oom_score),
6415         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6416         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6417 @@ -3029,6 +3059,7 @@ static const struct pid_entry tgid_base_
6418  #ifdef CONFIG_HARDWALL
6419         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6420  #endif
6421 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6422  };
6423  
6424  static int proc_tgid_base_readdir(struct file * filp,
6425 @@ -3222,7 +3253,7 @@ retry:
6426         iter.task = NULL;
6427         pid = find_ge_pid(iter.tgid, ns);
6428         if (pid) {
6429 -               iter.tgid = pid_nr_ns(pid, ns);
6430 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6431                 iter.task = pid_task(pid, PIDTYPE_PID);
6432                 /* What we to know is if the pid we have find is the
6433                  * pid of a thread_group_leader.  Testing for task
6434 @@ -3252,7 +3283,7 @@ static int proc_pid_fill_cache(struct fi
6435         struct tgid_iter iter)
6436  {
6437         char name[PROC_NUMBUF];
6438 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6439 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6440         return proc_fill_cache(filp, dirent, filldir, name, len,
6441                                 proc_pid_instantiate, iter.task, NULL);
6442  }
6443 @@ -3276,7 +3307,7 @@ int proc_pid_readdir(struct file * filp,
6444                 goto out_no_task;
6445         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6446  
6447 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6448 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6449         if (!reaper)
6450                 goto out_no_task;
6451  
6452 @@ -3298,6 +3329,8 @@ int proc_pid_readdir(struct file * filp,
6453                         __filldir = fake_filldir;
6454  
6455                 filp->f_pos = iter.tgid + TGID_OFFSET;
6456 +               if (!vx_proc_task_visible(iter.task))
6457 +                       continue;
6458                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6459                         put_task_struct(iter.task);
6460                         goto out;
6461 @@ -3451,6 +3484,8 @@ static struct dentry *proc_task_lookup(s
6462         tid = name_to_int(dentry);
6463         if (tid == ~0U)
6464                 goto out;
6465 +       if (vx_current_initpid(tid))
6466 +               goto out;
6467  
6468         ns = dentry->d_sb->s_fs_info;
6469         rcu_read_lock();
6470 diff -NurpP --minimal linux-3.4.32/fs/proc/generic.c linux-3.4.32-vs2.3.3.9/fs/proc/generic.c
6471 --- linux-3.4.32/fs/proc/generic.c      2012-03-19 18:47:26.000000000 +0000
6472 +++ linux-3.4.32-vs2.3.3.9/fs/proc/generic.c    2012-05-21 16:15:05.000000000 +0000
6473 @@ -22,6 +22,7 @@
6474  #include <linux/bitops.h>
6475  #include <linux/spinlock.h>
6476  #include <linux/completion.h>
6477 +#include <linux/vserver/inode.h>
6478  #include <asm/uaccess.h>
6479  
6480  #include "internal.h"
6481 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6482         for (de = de->subdir; de ; de = de->next) {
6483                 if (de->namelen != dentry->d_name.len)
6484                         continue;
6485 +               if (!vx_hide_check(0, de->vx_flags))
6486 +                       continue;
6487                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6488                         pde_get(de);
6489                         spin_unlock(&proc_subdir_lock);
6490                         error = -EINVAL;
6491                         inode = proc_get_inode(dir->i_sb, de);
6492 +                       /* generic proc entries belong to the host */
6493 +                       inode->i_tag = 0;
6494                         goto out_unlock;
6495                 }
6496         }
6497 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6498  
6499                                 /* filldir passes info to user space */
6500                                 pde_get(de);
6501 +                               if (!vx_hide_check(0, de->vx_flags))
6502 +                                       goto skip;
6503                                 spin_unlock(&proc_subdir_lock);
6504                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6505                                             de->low_ino, de->mode >> 12) < 0) {
6506 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6507                                         goto out;
6508                                 }
6509                                 spin_lock(&proc_subdir_lock);
6510 +                       skip:
6511                                 filp->f_pos++;
6512                                 next = de->next;
6513                                 pde_put(de);
6514 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6515         ent->nlink = nlink;
6516         atomic_set(&ent->count, 1);
6517         ent->pde_users = 0;
6518 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6519         spin_lock_init(&ent->pde_unload_lock);
6520         ent->pde_unload_completion = NULL;
6521         INIT_LIST_HEAD(&ent->pde_openers);
6522 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6523                                 kfree(ent->data);
6524                                 kfree(ent);
6525                                 ent = NULL;
6526 -                       }
6527 +                       } else
6528 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6529                 } else {
6530                         kfree(ent);
6531                         ent = NULL;
6532 diff -NurpP --minimal linux-3.4.32/fs/proc/inode.c linux-3.4.32-vs2.3.3.9/fs/proc/inode.c
6533 --- linux-3.4.32/fs/proc/inode.c        2012-05-21 16:07:26.000000000 +0000
6534 +++ linux-3.4.32-vs2.3.3.9/fs/proc/inode.c      2012-05-21 16:15:05.000000000 +0000
6535 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6536                         inode->i_uid = de->uid;
6537                         inode->i_gid = de->gid;
6538                 }
6539 +               if (de->vx_flags)
6540 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6541                 if (de->size)
6542                         inode->i_size = de->size;
6543                 if (de->nlink)
6544 diff -NurpP --minimal linux-3.4.32/fs/proc/internal.h linux-3.4.32-vs2.3.3.9/fs/proc/internal.h
6545 --- linux-3.4.32/fs/proc/internal.h     2012-05-21 16:07:26.000000000 +0000
6546 +++ linux-3.4.32-vs2.3.3.9/fs/proc/internal.h   2012-05-21 16:15:05.000000000 +0000
6547 @@ -10,6 +10,8 @@
6548   */
6549  
6550  #include <linux/proc_fs.h>
6551 +#include <linux/vs_pid.h>
6552 +
6553  struct  ctl_table_header;
6554  
6555  extern struct proc_dir_entry proc_root;
6556 @@ -54,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
6557                                 struct pid *pid, struct task_struct *task);
6558  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6559                                 struct pid *pid, struct task_struct *task);
6560 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6561 +                               struct pid *pid, struct task_struct *task);
6562 +
6563  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6564  
6565  extern const struct file_operations proc_pid_maps_operations;
6566 @@ -82,11 +87,16 @@ static inline struct pid *proc_pid(struc
6567         return PROC_I(inode)->pid;
6568  }
6569  
6570 -static inline struct task_struct *get_proc_task(struct inode *inode)
6571 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6572  {
6573         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6574  }
6575  
6576 +static inline struct task_struct *get_proc_task(struct inode *inode)
6577 +{
6578 +       return vx_get_proc_task(inode, proc_pid(inode));
6579 +}
6580 +
6581  static inline int proc_fd(struct inode *inode)
6582  {
6583         return PROC_I(inode)->fd;
6584 diff -NurpP --minimal linux-3.4.32/fs/proc/loadavg.c linux-3.4.32-vs2.3.3.9/fs/proc/loadavg.c
6585 --- linux-3.4.32/fs/proc/loadavg.c      2009-09-10 13:26:23.000000000 +0000
6586 +++ linux-3.4.32-vs2.3.3.9/fs/proc/loadavg.c    2012-05-21 16:15:05.000000000 +0000
6587 @@ -12,15 +12,27 @@
6588  
6589  static int loadavg_proc_show(struct seq_file *m, void *v)
6590  {
6591 +       unsigned long running;
6592 +       unsigned int threads;
6593         unsigned long avnrun[3];
6594  
6595         get_avenrun(avnrun, FIXED_1/200, 0);
6596  
6597 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6598 +               struct vx_info *vxi = current_vx_info();
6599 +
6600 +               running = atomic_read(&vxi->cvirt.nr_running);
6601 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6602 +       } else {
6603 +               running = nr_running();
6604 +               threads = nr_threads;
6605 +       }
6606 +
6607         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6608                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6609                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6610                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6611 -               nr_running(), nr_threads,
6612 +               running, threads,
6613                 task_active_pid_ns(current)->last_pid);
6614         return 0;
6615  }
6616 diff -NurpP --minimal linux-3.4.32/fs/proc/meminfo.c linux-3.4.32-vs2.3.3.9/fs/proc/meminfo.c
6617 --- linux-3.4.32/fs/proc/meminfo.c      2012-01-09 15:14:55.000000000 +0000
6618 +++ linux-3.4.32-vs2.3.3.9/fs/proc/meminfo.c    2012-05-21 16:15:05.000000000 +0000
6619 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6620         allowed = ((totalram_pages - hugetlb_total_pages())
6621                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6622  
6623 -       cached = global_page_state(NR_FILE_PAGES) -
6624 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6625 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6626                         total_swapcache_pages - i.bufferram;
6627         if (cached < 0)
6628                 cached = 0;
6629 diff -NurpP --minimal linux-3.4.32/fs/proc/root.c linux-3.4.32-vs2.3.3.9/fs/proc/root.c
6630 --- linux-3.4.32/fs/proc/root.c 2012-05-21 16:07:26.000000000 +0000
6631 +++ linux-3.4.32-vs2.3.3.9/fs/proc/root.c       2012-05-21 16:15:05.000000000 +0000
6632 @@ -19,9 +19,14 @@
6633  #include <linux/mount.h>
6634  #include <linux/pid_namespace.h>
6635  #include <linux/parser.h>
6636 +#include <linux/vserver/inode.h>
6637  
6638  #include "internal.h"
6639  
6640 +struct proc_dir_entry *proc_virtual;
6641 +
6642 +extern void proc_vx_init(void);
6643 +
6644  static int proc_test_super(struct super_block *sb, void *data)
6645  {
6646         return sb->s_fs_info == data;
6647 @@ -190,6 +195,7 @@ void __init proc_root_init(void)
6648  #endif
6649         proc_mkdir("bus", NULL);
6650         proc_sys_init();
6651 +       proc_vx_init();
6652  }
6653  
6654  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6655 @@ -257,6 +263,7 @@ struct proc_dir_entry proc_root = {
6656         .proc_iops      = &proc_root_inode_operations, 
6657         .proc_fops      = &proc_root_operations,
6658         .parent         = &proc_root,
6659 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6660         .name           = "/proc",
6661  };
6662  
6663 diff -NurpP --minimal linux-3.4.32/fs/proc/stat.c linux-3.4.32-vs2.3.3.9/fs/proc/stat.c
6664 --- linux-3.4.32/fs/proc/stat.c 2013-02-19 13:55:52.000000000 +0000
6665 +++ linux-3.4.32-vs2.3.3.9/fs/proc/stat.c       2012-11-06 17:02:35.000000000 +0000
6666 @@ -9,6 +9,7 @@
6667  #include <linux/slab.h>
6668  #include <linux/time.h>
6669  #include <linux/irqnr.h>
6670 +#include <linux/vserver/cvirt.h>
6671  #include <asm/cputime.h>
6672  #include <linux/tick.h>
6673  
6674 @@ -92,6 +93,10 @@ static int show_stat(struct seq_file *p,
6675                 irq = softirq = steal = 0;
6676         guest = guest_nice = 0;
6677         getboottime(&boottime);
6678 +
6679 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6680 +               vx_vsi_boottime(&boottime);
6681 +
6682         jif = boottime.tv_sec;
6683  
6684         for_each_possible_cpu(i) {
6685 diff -NurpP --minimal linux-3.4.32/fs/proc/uptime.c linux-3.4.32-vs2.3.3.9/fs/proc/uptime.c
6686 --- linux-3.4.32/fs/proc/uptime.c       2012-03-19 18:47:26.000000000 +0000
6687 +++ linux-3.4.32-vs2.3.3.9/fs/proc/uptime.c     2012-05-21 16:15:05.000000000 +0000
6688 @@ -5,6 +5,7 @@
6689  #include <linux/seq_file.h>
6690  #include <linux/time.h>
6691  #include <linux/kernel_stat.h>
6692 +#include <linux/vserver/cvirt.h>
6693  #include <asm/cputime.h>
6694  
6695  static int uptime_proc_show(struct seq_file *m, void *v)
6696 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6697         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6698         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6699         idle.tv_nsec = rem;
6700 +
6701 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6702 +               vx_vsi_uptime(&uptime, &idle);
6703 +
6704         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6705                         (unsigned long) uptime.tv_sec,
6706                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6707 diff -NurpP --minimal linux-3.4.32/fs/proc_namespace.c linux-3.4.32-vs2.3.3.9/fs/proc_namespace.c
6708 --- linux-3.4.32/fs/proc_namespace.c    2012-03-19 18:47:26.000000000 +0000
6709 +++ linux-3.4.32-vs2.3.3.9/fs/proc_namespace.c  2012-05-21 16:15:05.000000000 +0000
6710 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6711                 { MS_SYNCHRONOUS, ",sync" },
6712                 { MS_DIRSYNC, ",dirsync" },
6713                 { MS_MANDLOCK, ",mand" },
6714 +               { MS_TAGGED, ",tag" },
6715 +               { MS_NOTAGCHECK, ",notagcheck" },
6716                 { 0, NULL }
6717         };
6718         const struct proc_fs_info *fs_infop;
6719 @@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6720         seq_escape(m, s, " \t\n\\");
6721  }
6722  
6723 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6724 +{
6725 +       struct path root;
6726 +       struct dentry *point;
6727 +       struct mount *mnt = real_mount(vfsmnt);
6728 +       struct mount *root_mnt;
6729 +       int ret;
6730 +
6731 +       if (mnt == mnt->mnt_ns->root)
6732 +               return 1;
6733 +
6734 +       br_read_lock(vfsmount_lock);
6735 +       root = current->fs->root;
6736 +       root_mnt = real_mount(root.mnt);
6737 +       point = root.dentry;
6738 +
6739 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6740 +               point = mnt->mnt_mountpoint;
6741 +               mnt = mnt->mnt_parent;
6742 +       }
6743 +
6744 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6745 +
6746 +       br_read_unlock(vfsmount_lock);
6747 +
6748 +       return ret;
6749 +}
6750 +
6751  static void show_type(struct seq_file *m, struct super_block *sb)
6752  {
6753         mangle(m, sb->s_type->name);
6754 @@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6755         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6756         struct super_block *sb = mnt_path.dentry->d_sb;
6757  
6758 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6759 +               return SEQ_SKIP;
6760 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6761 +               return SEQ_SKIP;
6762 +
6763 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6764 +               mnt == current->fs->root.mnt) {
6765 +               seq_puts(m, "/dev/root / ");
6766 +               goto type;
6767 +       }
6768 +
6769         if (sb->s_op->show_devname) {
6770                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6771                 if (err)
6772 @@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6773         seq_putc(m, ' ');
6774         seq_path(m, &mnt_path, " \t\n\\");
6775         seq_putc(m, ' ');
6776 +type:
6777         show_type(m, sb);
6778         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6779         err = show_sb_opts(m, sb);
6780 @@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6781         struct path root = p->root;
6782         int err = 0;
6783  
6784 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6785 +               return SEQ_SKIP;
6786 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6787 +               return SEQ_SKIP;
6788 +
6789         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6790                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6791         if (sb->s_op->show_path)
6792 @@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file
6793         struct super_block *sb = mnt_path.dentry->d_sb;
6794         int err = 0;
6795  
6796 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6797 +               return SEQ_SKIP;
6798 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6799 +               return SEQ_SKIP;
6800 +
6801 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6802 +               mnt == current->fs->root.mnt) {
6803 +               seq_puts(m, "device /dev/root mounted on / ");
6804 +               goto type;
6805 +       }
6806 +
6807         /* device */
6808         if (sb->s_op->show_devname) {
6809                 seq_puts(m, "device ");
6810 @@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file
6811         seq_puts(m, " mounted on ");
6812         seq_path(m, &mnt_path, " \t\n\\");
6813         seq_putc(m, ' ');
6814 -
6815 +type:
6816         /* file system type */
6817         seq_puts(m, "with fstype ");
6818         show_type(m, sb);
6819 diff -NurpP --minimal linux-3.4.32/fs/quota/dquot.c linux-3.4.32-vs2.3.3.9/fs/quota/dquot.c
6820 --- linux-3.4.32/fs/quota/dquot.c       2012-05-21 16:07:26.000000000 +0000
6821 +++ linux-3.4.32-vs2.3.3.9/fs/quota/dquot.c     2012-05-21 16:15:05.000000000 +0000
6822 @@ -1563,6 +1563,9 @@ int __dquot_alloc_space(struct inode *in
6823         struct dquot **dquots = inode->i_dquot;
6824         int reserve = flags & DQUOT_SPACE_RESERVE;
6825  
6826 +       if ((ret = dl_alloc_space(inode, number)))
6827 +               return ret;
6828 +
6829         /*
6830          * First test before acquiring mutex - solves deadlocks when we
6831          * re-enter the quota code and are already holding the mutex
6832 @@ -1618,6 +1621,9 @@ int dquot_alloc_inode(const struct inode
6833         struct dquot_warn warn[MAXQUOTAS];
6834         struct dquot * const *dquots = inode->i_dquot;
6835  
6836 +       if ((ret = dl_alloc_inode(inode)))
6837 +               return ret;
6838 +
6839         /* First test before acquiring mutex - solves deadlocks when we
6840           * re-enter the quota code and are already holding the mutex */
6841         if (!dquot_active(inode))
6842 @@ -1689,6 +1695,8 @@ void __dquot_free_space(struct inode *in
6843         struct dquot **dquots = inode->i_dquot;
6844         int reserve = flags & DQUOT_SPACE_RESERVE;
6845  
6846 +       dl_free_space(inode, number);
6847 +
6848         /* First test before acquiring mutex - solves deadlocks when we
6849           * re-enter the quota code and are already holding the mutex */
6850         if (!dquot_active(inode)) {
6851 @@ -1733,6 +1741,8 @@ void dquot_free_inode(const struct inode
6852         struct dquot_warn warn[MAXQUOTAS];
6853         struct dquot * const *dquots = inode->i_dquot;
6854  
6855 +       dl_free_inode(inode);
6856 +
6857         /* First test before acquiring mutex - solves deadlocks when we
6858           * re-enter the quota code and are already holding the mutex */
6859         if (!dquot_active(inode))
6860 diff -NurpP --minimal linux-3.4.32/fs/quota/quota.c linux-3.4.32-vs2.3.3.9/fs/quota/quota.c
6861 --- linux-3.4.32/fs/quota/quota.c       2012-05-21 16:07:26.000000000 +0000
6862 +++ linux-3.4.32-vs2.3.3.9/fs/quota/quota.c     2012-05-21 16:15:05.000000000 +0000
6863 @@ -8,6 +8,7 @@
6864  #include <linux/fs.h>
6865  #include <linux/namei.h>
6866  #include <linux/slab.h>
6867 +#include <linux/vs_context.h>
6868  #include <asm/current.h>
6869  #include <asm/uaccess.h>
6870  #include <linux/kernel.h>
6871 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6872                         break;
6873                 /*FALLTHROUGH*/
6874         default:
6875 -               if (!capable(CAP_SYS_ADMIN))
6876 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6877                         return -EPERM;
6878         }
6879  
6880 @@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6881         }
6882  }
6883  
6884 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6885 +
6886 +#include <linux/vroot.h>
6887 +#include <linux/major.h>
6888 +#include <linux/module.h>
6889 +#include <linux/kallsyms.h>
6890 +#include <linux/vserver/debug.h>
6891 +
6892 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6893 +
6894 +static DEFINE_SPINLOCK(vroot_grb_lock);
6895 +
6896 +int register_vroot_grb(vroot_grb_func *func) {
6897 +       int ret = -EBUSY;
6898 +
6899 +       spin_lock(&vroot_grb_lock);
6900 +       if (!vroot_get_real_bdev) {
6901 +               vroot_get_real_bdev = func;
6902 +               ret = 0;
6903 +       }
6904 +       spin_unlock(&vroot_grb_lock);
6905 +       return ret;
6906 +}
6907 +EXPORT_SYMBOL(register_vroot_grb);
6908 +
6909 +int unregister_vroot_grb(vroot_grb_func *func) {
6910 +       int ret = -EINVAL;
6911 +
6912 +       spin_lock(&vroot_grb_lock);
6913 +       if (vroot_get_real_bdev) {
6914 +               vroot_get_real_bdev = NULL;
6915 +               ret = 0;
6916 +       }
6917 +       spin_unlock(&vroot_grb_lock);
6918 +       return ret;
6919 +}
6920 +EXPORT_SYMBOL(unregister_vroot_grb);
6921 +
6922 +#endif
6923 +
6924  /* Return 1 if 'cmd' will block on frozen filesystem */
6925  static int quotactl_cmd_write(int cmd)
6926  {
6927 @@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6928         putname(tmp);
6929         if (IS_ERR(bdev))
6930                 return ERR_CAST(bdev);
6931 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6932 +       if (bdev && bdev->bd_inode &&
6933 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6934 +               struct block_device *bdnew = (void *)-EINVAL;
6935 +
6936 +               if (vroot_get_real_bdev)
6937 +                       bdnew = vroot_get_real_bdev(bdev);
6938 +               else
6939 +                       vxdprintk(VXD_CBIT(misc, 0),
6940 +                                       "vroot_get_real_bdev not set");
6941 +               bdput(bdev);
6942 +               if (IS_ERR(bdnew))
6943 +                       return ERR_PTR(PTR_ERR(bdnew));
6944 +               bdev = bdnew;
6945 +       }
6946 +#endif
6947         if (quotactl_cmd_write(cmd))
6948                 sb = get_super_thawed(bdev);
6949         else
6950 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/file.c linux-3.4.32-vs2.3.3.9/fs/reiserfs/file.c
6951 --- linux-3.4.32/fs/reiserfs/file.c     2012-05-21 16:07:26.000000000 +0000
6952 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/file.c   2012-05-21 16:15:05.000000000 +0000
6953 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6954         .listxattr = reiserfs_listxattr,
6955         .removexattr = reiserfs_removexattr,
6956         .permission = reiserfs_permission,
6957 +       .sync_flags = reiserfs_sync_flags,
6958         .get_acl = reiserfs_get_acl,
6959  };
6960 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/inode.c linux-3.4.32-vs2.3.3.9/fs/reiserfs/inode.c
6961 --- linux-3.4.32/fs/reiserfs/inode.c    2013-02-19 13:55:52.000000000 +0000
6962 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/inode.c  2012-12-08 00:53:53.000000000 +0000
6963 @@ -18,6 +18,7 @@
6964  #include <linux/writeback.h>
6965  #include <linux/quotaops.h>
6966  #include <linux/swap.h>
6967 +#include <linux/vs_tag.h>
6968  
6969  int reiserfs_commit_write(struct file *f, struct page *page,
6970                           unsigned from, unsigned to);
6971 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6972         struct buffer_head *bh;
6973         struct item_head *ih;
6974         __u32 rdev;
6975 +       uid_t uid;
6976 +       gid_t gid;
6977         //int version = ITEM_VERSION_1;
6978  
6979         bh = PATH_PLAST_BUFFER(path);
6980 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6981                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6982                 unsigned long blocks;
6983  
6984 +               uid = sd_v1_uid(sd);
6985 +               gid = sd_v1_gid(sd);
6986 +
6987                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6988                 set_inode_sd_version(inode, STAT_DATA_V1);
6989                 inode->i_mode = sd_v1_mode(sd);
6990                 set_nlink(inode, sd_v1_nlink(sd));
6991 -               inode->i_uid = sd_v1_uid(sd);
6992 -               inode->i_gid = sd_v1_gid(sd);
6993                 inode->i_size = sd_v1_size(sd);
6994                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6995                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6996 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6997                 // (directories and symlinks)
6998                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6999  
7000 +               uid    = sd_v2_uid(sd);
7001 +               gid    = sd_v2_gid(sd);
7002 +
7003                 inode->i_mode = sd_v2_mode(sd);
7004                 set_nlink(inode, sd_v2_nlink(sd));
7005 -               inode->i_uid = sd_v2_uid(sd);
7006                 inode->i_size = sd_v2_size(sd);
7007 -               inode->i_gid = sd_v2_gid(sd);
7008                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7009                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7010                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7011 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7012                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7013         }
7014  
7015 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7016 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7017 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7018 +
7019         pathrelse(path);
7020         if (S_ISREG(inode->i_mode)) {
7021                 inode->i_op = &reiserfs_file_inode_operations;
7022 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7023  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7024  {
7025         struct stat_data *sd_v2 = (struct stat_data *)sd;
7026 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7027 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7028         __u16 flags;
7029  
7030 +       set_sd_v2_uid(sd_v2, uid);
7031 +       set_sd_v2_gid(sd_v2, gid);
7032         set_sd_v2_mode(sd_v2, inode->i_mode);
7033         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7034 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7035         set_sd_v2_size(sd_v2, size);
7036 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7037         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7038         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7039         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7040 @@ -2875,14 +2886,19 @@ int reiserfs_commit_write(struct file *f
7041  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7042  {
7043         if (reiserfs_attrs(inode->i_sb)) {
7044 -               if (sd_attrs & REISERFS_SYNC_FL)
7045 -                       inode->i_flags |= S_SYNC;
7046 -               else
7047 -                       inode->i_flags &= ~S_SYNC;
7048                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7049                         inode->i_flags |= S_IMMUTABLE;
7050                 else
7051                         inode->i_flags &= ~S_IMMUTABLE;
7052 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7053 +                       inode->i_flags |= S_IXUNLINK;
7054 +               else
7055 +                       inode->i_flags &= ~S_IXUNLINK;
7056 +
7057 +               if (sd_attrs & REISERFS_SYNC_FL)
7058 +                       inode->i_flags |= S_SYNC;
7059 +               else
7060 +                       inode->i_flags &= ~S_SYNC;
7061                 if (sd_attrs & REISERFS_APPEND_FL)
7062                         inode->i_flags |= S_APPEND;
7063                 else
7064 @@ -2895,6 +2911,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7065                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7066                 else
7067                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7068 +
7069 +               if (sd_attrs & REISERFS_BARRIER_FL)
7070 +                       inode->i_vflags |= V_BARRIER;
7071 +               else
7072 +                       inode->i_vflags &= ~V_BARRIER;
7073 +               if (sd_attrs & REISERFS_COW_FL)
7074 +                       inode->i_vflags |= V_COW;
7075 +               else
7076 +                       inode->i_vflags &= ~V_COW;
7077         }
7078  }
7079  
7080 @@ -2905,6 +2930,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7081                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7082                 else
7083                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7084 +               if (inode->i_flags & S_IXUNLINK)
7085 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7086 +               else
7087 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7088 +
7089                 if (inode->i_flags & S_SYNC)
7090                         *sd_attrs |= REISERFS_SYNC_FL;
7091                 else
7092 @@ -2917,6 +2947,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7093                         *sd_attrs |= REISERFS_NOTAIL_FL;
7094                 else
7095                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7096 +
7097 +               if (inode->i_vflags & V_BARRIER)
7098 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7099 +               else
7100 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7101 +               if (inode->i_vflags & V_COW)
7102 +                       *sd_attrs |= REISERFS_COW_FL;
7103 +               else
7104 +                       *sd_attrs &= ~REISERFS_COW_FL;
7105         }
7106  }
7107  
7108 @@ -3161,7 +3200,8 @@ int reiserfs_setattr(struct dentry *dent
7109         }
7110  
7111         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7112 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7113 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7114 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7115                 struct reiserfs_transaction_handle th;
7116                 int jbegin_count =
7117                     2 *
7118 @@ -3192,6 +3232,9 @@ int reiserfs_setattr(struct dentry *dent
7119                         inode->i_uid = attr->ia_uid;
7120                 if (attr->ia_valid & ATTR_GID)
7121                         inode->i_gid = attr->ia_gid;
7122 +                               if ((attr->ia_valid & ATTR_TAG) &&
7123 +                                       IS_TAGGED(inode))
7124 +                                       inode->i_tag = attr->ia_tag;
7125                 mark_inode_dirty(inode);
7126                 error = journal_end(&th, inode->i_sb, jbegin_count);
7127                 if (error)
7128 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/ioctl.c linux-3.4.32-vs2.3.3.9/fs/reiserfs/ioctl.c
7129 --- linux-3.4.32/fs/reiserfs/ioctl.c    2012-05-21 16:07:27.000000000 +0000
7130 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/ioctl.c  2012-05-21 16:15:05.000000000 +0000
7131 @@ -11,6 +11,21 @@
7132  #include <linux/pagemap.h>
7133  #include <linux/compat.h>
7134  
7135 +
7136 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7137 +{
7138 +       __u16 sd_attrs = 0;
7139 +
7140 +       inode->i_flags = flags;
7141 +       inode->i_vflags = vflags;
7142 +
7143 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7144 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7145 +       inode->i_ctime = CURRENT_TIME_SEC;
7146 +       mark_inode_dirty(inode);
7147 +       return 0;
7148 +}
7149 +
7150  /*
7151   * reiserfs_ioctl - handler for ioctl for inode
7152   * supported commands:
7153 @@ -22,7 +37,7 @@
7154  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7155  {
7156         struct inode *inode = filp->f_path.dentry->d_inode;
7157 -       unsigned int flags;
7158 +       unsigned int flags, oldflags;
7159         int err = 0;
7160  
7161         reiserfs_write_lock(inode->i_sb);
7162 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7163  
7164                 flags = REISERFS_I(inode)->i_attrs;
7165                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7166 +               flags &= REISERFS_FL_USER_VISIBLE;
7167                 err = put_user(flags, (int __user *)arg);
7168                 break;
7169         case REISERFS_IOC_SETFLAGS:{
7170 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7171                                 err = -EFAULT;
7172                                 goto setflags_out;
7173                         }
7174 +                       if (IS_BARRIER(inode)) {
7175 +                               vxwprintk_task(1, "messing with the barrier.");
7176 +                               return -EACCES;
7177 +                       }
7178                         /*
7179                          * Is it quota file? Do not allow user to mess with it
7180                          */
7181 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7182                                         goto setflags_out;
7183                                 }
7184                         }
7185 +
7186 +                       oldflags = REISERFS_I(inode)->i_attrs;
7187 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7188 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7189                         sd_attrs_to_i_attrs(flags, inode);
7190                         REISERFS_I(inode)->i_attrs = flags;
7191                         inode->i_ctime = CURRENT_TIME_SEC;
7192 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/namei.c linux-3.4.32-vs2.3.3.9/fs/reiserfs/namei.c
7193 --- linux-3.4.32/fs/reiserfs/namei.c    2012-05-21 16:07:27.000000000 +0000
7194 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/namei.c  2012-05-21 16:15:05.000000000 +0000
7195 @@ -18,6 +18,7 @@
7196  #include "acl.h"
7197  #include "xattr.h"
7198  #include <linux/quotaops.h>
7199 +#include <linux/vs_tag.h>
7200  
7201  #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); }
7202  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7203 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7204         if (retval == IO_ERROR) {
7205                 return ERR_PTR(-EIO);
7206         }
7207 +               dx_propagate_tag(nd, inode);
7208  
7209         return d_splice_alias(inode, dentry);
7210  }
7211 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/reiserfs.h linux-3.4.32-vs2.3.3.9/fs/reiserfs/reiserfs.h
7212 --- linux-3.4.32/fs/reiserfs/reiserfs.h 2012-05-21 16:07:27.000000000 +0000
7213 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/reiserfs.h       2012-05-21 17:19:33.000000000 +0000
7214 @@ -544,6 +544,7 @@ enum reiserfs_mount_options {
7215         REISERFS_EXPOSE_PRIVROOT,
7216         REISERFS_BARRIER_NONE,
7217         REISERFS_BARRIER_FLUSH,
7218 +       REISERFS_TAGGED,
7219  
7220         /* Actions on error */
7221         REISERFS_ERROR_PANIC,
7222 @@ -1543,6 +1544,11 @@ struct stat_data_v1 {
7223  #define REISERFS_COMPR_FL     FS_COMPR_FL
7224  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
7225  
7226 +/* unfortunately reiserfs sdattr is only 16 bit */
7227 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
7228 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
7229 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
7230 +
7231  /* persistent flags that file inherits from the parent directory */
7232  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
7233                                 REISERFS_SYNC_FL |      \
7234 @@ -1552,6 +1558,9 @@ struct stat_data_v1 {
7235                                 REISERFS_COMPR_FL |     \
7236                                 REISERFS_NOTAIL_FL )
7237  
7238 +#define REISERFS_FL_USER_VISIBLE       0x80FF
7239 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
7240 +
7241  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7242     address blocks) */
7243  struct stat_data {
7244 @@ -2641,6 +2650,7 @@ static inline void reiserfs_update_sd(st
7245  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7246  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7247  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7248 +int reiserfs_sync_flags(struct inode *inode, int, int);
7249  
7250  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7251  
7252 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/super.c linux-3.4.32-vs2.3.3.9/fs/reiserfs/super.c
7253 --- linux-3.4.32/fs/reiserfs/super.c    2013-02-19 13:55:52.000000000 +0000
7254 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/super.c  2012-12-08 00:53:53.000000000 +0000
7255 @@ -982,6 +982,14 @@ static int reiserfs_parse_options(struct
7256                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7257                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7258  #endif
7259 +#ifndef CONFIG_TAGGING_NONE
7260 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7261 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7262 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7263 +#endif
7264 +#ifdef CONFIG_PROPAGATE
7265 +               {"tag",.arg_required = 'T',.values = NULL},
7266 +#endif
7267  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7268                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7269                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7270 @@ -1300,6 +1308,14 @@ static int reiserfs_remount(struct super
7271         handle_quota_files(s, qf_names, &qfmt);
7272  #endif
7273  
7274 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7275 +               !(s->s_flags & MS_TAGGED)) {
7276 +               reiserfs_warning(s, "super-vs01",
7277 +                       "reiserfs: tagging not permitted on remount.");
7278 +               err = -EINVAL;
7279 +               goto out_err;
7280 +       }
7281 +
7282         handle_attrs(s);
7283  
7284         /* Add options that are safe here */
7285 @@ -1792,6 +1808,10 @@ static int reiserfs_fill_super(struct su
7286                 goto error_unlocked;
7287         }
7288  
7289 +       /* map mount option tagxid */
7290 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7291 +               s->s_flags |= MS_TAGGED;
7292 +
7293         rs = SB_DISK_SUPER_BLOCK(s);
7294         /* Let's do basic sanity check to verify that underlying device is not
7295            smaller than the filesystem. If the check fails then abort and scream,
7296 diff -NurpP --minimal linux-3.4.32/fs/reiserfs/xattr.c linux-3.4.32-vs2.3.3.9/fs/reiserfs/xattr.c
7297 --- linux-3.4.32/fs/reiserfs/xattr.c    2012-05-21 16:07:27.000000000 +0000
7298 +++ linux-3.4.32-vs2.3.3.9/fs/reiserfs/xattr.c  2012-05-21 16:15:05.000000000 +0000
7299 @@ -40,6 +40,7 @@
7300  #include <linux/errno.h>
7301  #include <linux/gfp.h>
7302  #include <linux/fs.h>
7303 +#include <linux/mount.h>
7304  #include <linux/file.h>
7305  #include <linux/pagemap.h>
7306  #include <linux/xattr.h>
7307 diff -NurpP --minimal linux-3.4.32/fs/stat.c linux-3.4.32-vs2.3.3.9/fs/stat.c
7308 --- linux-3.4.32/fs/stat.c      2013-02-19 13:55:52.000000000 +0000
7309 +++ linux-3.4.32-vs2.3.3.9/fs/stat.c    2012-10-22 13:09:53.000000000 +0000
7310 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7311         stat->nlink = inode->i_nlink;
7312         stat->uid = inode->i_uid;
7313         stat->gid = inode->i_gid;
7314 +       stat->tag = inode->i_tag;
7315         stat->rdev = inode->i_rdev;
7316         stat->size = i_size_read(inode);
7317         stat->atime = inode->i_atime;
7318 diff -NurpP --minimal linux-3.4.32/fs/statfs.c linux-3.4.32-vs2.3.3.9/fs/statfs.c
7319 --- linux-3.4.32/fs/statfs.c    2012-05-21 16:07:27.000000000 +0000
7320 +++ linux-3.4.32-vs2.3.3.9/fs/statfs.c  2012-05-21 16:15:05.000000000 +0000
7321 @@ -7,6 +7,8 @@
7322  #include <linux/statfs.h>
7323  #include <linux/security.h>
7324  #include <linux/uaccess.h>
7325 +#include <linux/vs_base.h>
7326 +#include <linux/vs_dlimit.h>
7327  #include "internal.h"
7328  
7329  static int flags_by_mnt(int mnt_flags)
7330 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7331         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7332         if (retval == 0 && buf->f_frsize == 0)
7333                 buf->f_frsize = buf->f_bsize;
7334 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7335 +               vx_vsi_statfs(dentry->d_sb, buf);
7336         return retval;
7337  }
7338  
7339 diff -NurpP --minimal linux-3.4.32/fs/super.c linux-3.4.32-vs2.3.3.9/fs/super.c
7340 --- linux-3.4.32/fs/super.c     2012-05-21 16:07:27.000000000 +0000
7341 +++ linux-3.4.32-vs2.3.3.9/fs/super.c   2012-05-21 16:59:38.000000000 +0000
7342 @@ -33,6 +33,8 @@
7343  #include <linux/rculist_bl.h>
7344  #include <linux/cleancache.h>
7345  #include <linux/fsnotify.h>
7346 +#include <linux/magic.h>
7347 +#include <linux/vs_context.h>
7348  #include "internal.h"
7349  
7350  
7351 @@ -1138,6 +1140,13 @@ mount_fs(struct file_system_type *type,
7352         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7353         sb->s_flags |= MS_BORN;
7354  
7355 +       error = -EPERM;
7356 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7357 +               !sb->s_bdev &&
7358 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7359 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7360 +               goto out_sb;
7361 +
7362         error = security_sb_kern_mount(sb, flags, secdata);
7363         if (error)
7364                 goto out_sb;
7365 diff -NurpP --minimal linux-3.4.32/fs/sysfs/mount.c linux-3.4.32-vs2.3.3.9/fs/sysfs/mount.c
7366 --- linux-3.4.32/fs/sysfs/mount.c       2012-05-21 16:07:27.000000000 +0000
7367 +++ linux-3.4.32-vs2.3.3.9/fs/sysfs/mount.c     2012-05-21 16:15:05.000000000 +0000
7368 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7369  
7370         sb->s_blocksize = PAGE_CACHE_SIZE;
7371         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7372 -       sb->s_magic = SYSFS_MAGIC;
7373 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7374         sb->s_op = &sysfs_ops;
7375         sb->s_time_gran = 1;
7376  
7377 diff -NurpP --minimal linux-3.4.32/fs/utimes.c linux-3.4.32-vs2.3.3.9/fs/utimes.c
7378 --- linux-3.4.32/fs/utimes.c    2011-05-22 14:17:54.000000000 +0000
7379 +++ linux-3.4.32-vs2.3.3.9/fs/utimes.c  2012-05-21 16:15:05.000000000 +0000
7380 @@ -8,6 +8,8 @@
7381  #include <linux/stat.h>
7382  #include <linux/utime.h>
7383  #include <linux/syscalls.h>
7384 +#include <linux/mount.h>
7385 +#include <linux/vs_cowbl.h>
7386  #include <asm/uaccess.h>
7387  #include <asm/unistd.h>
7388  
7389 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7390  {
7391         int error;
7392         struct iattr newattrs;
7393 -       struct inode *inode = path->dentry->d_inode;
7394 +       struct inode *inode;
7395  
7396         error = mnt_want_write(path->mnt);
7397         if (error)
7398                 goto out;
7399  
7400 +       error = cow_check_and_break(path);
7401 +       if (error)
7402 +               goto mnt_drop_write_and_out;
7403 +
7404 +       inode = path->dentry->d_inode;
7405 +
7406         if (times && times[0].tv_nsec == UTIME_NOW &&
7407                      times[1].tv_nsec == UTIME_NOW)
7408                 times = NULL;
7409 diff -NurpP --minimal linux-3.4.32/fs/xattr.c linux-3.4.32-vs2.3.3.9/fs/xattr.c
7410 --- linux-3.4.32/fs/xattr.c     2012-05-21 16:07:27.000000000 +0000
7411 +++ linux-3.4.32-vs2.3.3.9/fs/xattr.c   2012-05-21 16:15:05.000000000 +0000
7412 @@ -20,6 +20,7 @@
7413  #include <linux/fsnotify.h>
7414  #include <linux/audit.h>
7415  #include <linux/vmalloc.h>
7416 +#include <linux/mount.h>
7417  
7418  #include <asm/uaccess.h>
7419  
7420 @@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7421          * The trusted.* namespace can only be accessed by privileged users.
7422          */
7423         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7424 -               if (!capable(CAP_SYS_ADMIN))
7425 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7426                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7427                 return 0;
7428         }
7429 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_dinode.h linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_dinode.h
7430 --- linux-3.4.32/fs/xfs/xfs_dinode.h    2011-10-24 16:45:31.000000000 +0000
7431 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_dinode.h  2012-05-21 16:15:05.000000000 +0000
7432 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7433         __be32          di_nlink;       /* number of links to file */
7434         __be16          di_projid_lo;   /* lower part of owner's project id */
7435         __be16          di_projid_hi;   /* higher part owner's project id */
7436 -       __u8            di_pad[6];      /* unused, zeroed space */
7437 +       __u8            di_pad[2];      /* unused, zeroed space */
7438 +       __be16          di_tag;         /* context tagging */
7439 +       __be16          di_vflags;      /* vserver specific flags */
7440         __be16          di_flushiter;   /* incremented on flush */
7441         xfs_timestamp_t di_atime;       /* time last accessed */
7442         xfs_timestamp_t di_mtime;       /* time last modified */
7443 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7444  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7445  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7446  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7447 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7448 +
7449  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7450  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7451  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7452 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7453  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7454  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7455  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7456 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7457  
7458  #ifdef CONFIG_XFS_RT
7459  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7460 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7461          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7462          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7463          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7464 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7465 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7466 +        XFS_DIFLAG_IXUNLINK)
7467 +
7468 +#define XFS_DIVFLAG_BARRIER    0x01
7469 +#define XFS_DIVFLAG_COW                0x02
7470  
7471  #endif /* __XFS_DINODE_H__ */
7472 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_fs.h linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_fs.h
7473 --- linux-3.4.32/fs/xfs/xfs_fs.h        2011-10-24 16:45:31.000000000 +0000
7474 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_fs.h      2012-05-21 16:15:05.000000000 +0000
7475 @@ -67,6 +67,9 @@ struct fsxattr {
7476  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7477  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7478  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7479 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7480 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7481 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7482  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7483  
7484  /*
7485 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7486  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7487         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7488         __u16           bs_projid_hi;   /* higher part of project id    */
7489 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7490 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7491 +       __u16           bs_tag;         /* context tagging              */
7492         __u32           bs_dmevmask;    /* DMIG event mask              */
7493         __u16           bs_dmstate;     /* DMIG state info              */
7494         __u16           bs_aextents;    /* attribute number of extents  */
7495 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_ialloc.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_ialloc.c
7496 --- linux-3.4.32/fs/xfs/xfs_ialloc.c    2012-03-19 18:47:27.000000000 +0000
7497 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_ialloc.c  2012-05-21 16:15:05.000000000 +0000
7498 @@ -37,7 +37,6 @@
7499  #include "xfs_error.h"
7500  #include "xfs_bmap.h"
7501  
7502 -
7503  /*
7504   * Allocation group level functions.
7505   */
7506 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_inode.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_inode.c
7507 --- linux-3.4.32/fs/xfs/xfs_inode.c     2012-05-21 16:07:27.000000000 +0000
7508 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_inode.c   2012-05-21 16:15:05.000000000 +0000
7509 @@ -236,6 +236,7 @@ xfs_inotobp(
7510         return 0;
7511  }
7512  
7513 +#include <linux/vs_tag.h>
7514  
7515  /*
7516   * This routine is called to map an inode to the buffer containing
7517 @@ -631,15 +632,25 @@ xfs_iformat_btree(
7518  STATIC void
7519  xfs_dinode_from_disk(
7520         xfs_icdinode_t          *to,
7521 -       xfs_dinode_t            *from)
7522 +       xfs_dinode_t            *from,
7523 +       int tagged)
7524  {
7525 +       uint32_t uid, gid, tag;
7526 +
7527         to->di_magic = be16_to_cpu(from->di_magic);
7528         to->di_mode = be16_to_cpu(from->di_mode);
7529         to->di_version = from ->di_version;
7530         to->di_format = from->di_format;
7531         to->di_onlink = be16_to_cpu(from->di_onlink);
7532 -       to->di_uid = be32_to_cpu(from->di_uid);
7533 -       to->di_gid = be32_to_cpu(from->di_gid);
7534 +
7535 +       uid = be32_to_cpu(from->di_uid);
7536 +       gid = be32_to_cpu(from->di_gid);
7537 +       tag = be16_to_cpu(from->di_tag);
7538 +
7539 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7540 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7541 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7542 +
7543         to->di_nlink = be32_to_cpu(from->di_nlink);
7544         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7545         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7546 @@ -661,21 +672,26 @@ xfs_dinode_from_disk(
7547         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7548         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7549         to->di_flags    = be16_to_cpu(from->di_flags);
7550 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7551         to->di_gen      = be32_to_cpu(from->di_gen);
7552  }
7553  
7554  void
7555  xfs_dinode_to_disk(
7556         xfs_dinode_t            *to,
7557 -       xfs_icdinode_t          *from)
7558 +       xfs_icdinode_t          *from,
7559 +       int tagged)
7560  {
7561         to->di_magic = cpu_to_be16(from->di_magic);
7562         to->di_mode = cpu_to_be16(from->di_mode);
7563         to->di_version = from ->di_version;
7564         to->di_format = from->di_format;
7565         to->di_onlink = cpu_to_be16(from->di_onlink);
7566 -       to->di_uid = cpu_to_be32(from->di_uid);
7567 -       to->di_gid = cpu_to_be32(from->di_gid);
7568 +
7569 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7570 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7571 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7572 +
7573         to->di_nlink = cpu_to_be32(from->di_nlink);
7574         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7575         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7576 @@ -697,12 +713,14 @@ xfs_dinode_to_disk(
7577         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7578         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7579         to->di_flags = cpu_to_be16(from->di_flags);
7580 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7581         to->di_gen = cpu_to_be32(from->di_gen);
7582  }
7583  
7584  STATIC uint
7585  _xfs_dic2xflags(
7586 -       __uint16_t              di_flags)
7587 +       __uint16_t              di_flags,
7588 +       __uint16_t              di_vflags)
7589  {
7590         uint                    flags = 0;
7591  
7592 @@ -713,6 +731,8 @@ _xfs_dic2xflags(
7593                         flags |= XFS_XFLAG_PREALLOC;
7594                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7595                         flags |= XFS_XFLAG_IMMUTABLE;
7596 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7597 +                       flags |= XFS_XFLAG_IXUNLINK;
7598                 if (di_flags & XFS_DIFLAG_APPEND)
7599                         flags |= XFS_XFLAG_APPEND;
7600                 if (di_flags & XFS_DIFLAG_SYNC)
7601 @@ -737,6 +757,10 @@ _xfs_dic2xflags(
7602                         flags |= XFS_XFLAG_FILESTREAM;
7603         }
7604  
7605 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7606 +               flags |= FS_BARRIER_FL;
7607 +       if (di_vflags & XFS_DIVFLAG_COW)
7608 +               flags |= FS_COW_FL;
7609         return flags;
7610  }
7611  
7612 @@ -746,7 +770,7 @@ xfs_ip2xflags(
7613  {
7614         xfs_icdinode_t          *dic = &ip->i_d;
7615  
7616 -       return _xfs_dic2xflags(dic->di_flags) |
7617 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7618                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7619  }
7620  
7621 @@ -754,7 +778,8 @@ uint
7622  xfs_dic2xflags(
7623         xfs_dinode_t            *dip)
7624  {
7625 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7626 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7627 +                               be16_to_cpu(dip->di_vflags)) |
7628                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7629  }
7630  
7631 @@ -787,7 +812,6 @@ xfs_iread(
7632         if (error)
7633                 return error;
7634         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7635 -
7636         /*
7637          * If we got something that isn't an inode it means someone
7638          * (nfs or dmi) has a stale handle.
7639 @@ -810,7 +834,8 @@ xfs_iread(
7640          * Otherwise, just get the truly permanent information.
7641          */
7642         if (dip->di_mode) {
7643 -               xfs_dinode_from_disk(&ip->i_d, dip);
7644 +               xfs_dinode_from_disk(&ip->i_d, dip,
7645 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7646                 error = xfs_iformat(ip, dip);
7647                 if (error)  {
7648  #ifdef DEBUG
7649 @@ -998,6 +1023,7 @@ xfs_ialloc(
7650         ASSERT(ip->i_d.di_nlink == nlink);
7651         ip->i_d.di_uid = current_fsuid();
7652         ip->i_d.di_gid = current_fsgid();
7653 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7654         xfs_set_projid(ip, prid);
7655         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7656  
7657 @@ -1057,6 +1083,7 @@ xfs_ialloc(
7658         ip->i_d.di_dmevmask = 0;
7659         ip->i_d.di_dmstate = 0;
7660         ip->i_d.di_flags = 0;
7661 +       ip->i_d.di_vflags = 0;
7662         flags = XFS_ILOG_CORE;
7663         switch (mode & S_IFMT) {
7664         case S_IFIFO:
7665 @@ -1725,6 +1752,7 @@ xfs_ifree(
7666         }
7667         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7668         ip->i_d.di_flags = 0;
7669 +       ip->i_d.di_vflags = 0;
7670         ip->i_d.di_dmevmask = 0;
7671         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7672         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7673 @@ -2598,7 +2626,8 @@ xfs_iflush_int(
7674          * because if the inode is dirty at all the core must
7675          * be.
7676          */
7677 -       xfs_dinode_to_disk(dip, &ip->i_d);
7678 +       xfs_dinode_to_disk(dip, &ip->i_d,
7679 +               mp->m_flags & XFS_MOUNT_TAGGED);
7680  
7681         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7682         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7683 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_inode.h linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_inode.h
7684 --- linux-3.4.32/fs/xfs/xfs_inode.h     2012-05-21 16:07:27.000000000 +0000
7685 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_inode.h   2012-05-21 16:15:05.000000000 +0000
7686 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7687         __uint32_t      di_nlink;       /* number of links to file */
7688         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7689         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7690 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7691 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7692 +       __uint16_t      di_tag;         /* context tagging */
7693 +       __uint16_t      di_vflags;      /* vserver specific flags */
7694         __uint16_t      di_flushiter;   /* incremented on flush */
7695         xfs_ictimestamp_t di_atime;     /* time last accessed */
7696         xfs_ictimestamp_t di_mtime;     /* time last modified */
7697 @@ -565,7 +567,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7698  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7699                           struct xfs_inode *, uint);
7700  void           xfs_dinode_to_disk(struct xfs_dinode *,
7701 -                                  struct xfs_icdinode *);
7702 +                                  struct xfs_icdinode *, int);
7703  void           xfs_idestroy_fork(struct xfs_inode *, int);
7704  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7705  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7706 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_ioctl.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_ioctl.c
7707 --- linux-3.4.32/fs/xfs/xfs_ioctl.c     2012-05-21 16:07:27.000000000 +0000
7708 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_ioctl.c   2012-05-21 16:15:05.000000000 +0000
7709 @@ -28,7 +28,7 @@
7710  #include "xfs_bmap_btree.h"
7711  #include "xfs_dinode.h"
7712  #include "xfs_inode.h"
7713 -#include "xfs_ioctl.h"
7714 +// #include "xfs_ioctl.h"
7715  #include "xfs_rtalloc.h"
7716  #include "xfs_itable.h"
7717  #include "xfs_error.h"
7718 @@ -750,6 +750,10 @@ xfs_merge_ioc_xflags(
7719                 xflags |= XFS_XFLAG_IMMUTABLE;
7720         else
7721                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7722 +       if (flags & FS_IXUNLINK_FL)
7723 +               xflags |= XFS_XFLAG_IXUNLINK;
7724 +       else
7725 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7726         if (flags & FS_APPEND_FL)
7727                 xflags |= XFS_XFLAG_APPEND;
7728         else
7729 @@ -778,6 +782,8 @@ xfs_di2lxflags(
7730  
7731         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7732                 flags |= FS_IMMUTABLE_FL;
7733 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7734 +               flags |= FS_IXUNLINK_FL;
7735         if (di_flags & XFS_DIFLAG_APPEND)
7736                 flags |= FS_APPEND_FL;
7737         if (di_flags & XFS_DIFLAG_SYNC)
7738 @@ -838,6 +844,8 @@ xfs_set_diflags(
7739         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7740         if (xflags & XFS_XFLAG_IMMUTABLE)
7741                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7742 +       if (xflags & XFS_XFLAG_IXUNLINK)
7743 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7744         if (xflags & XFS_XFLAG_APPEND)
7745                 di_flags |= XFS_DIFLAG_APPEND;
7746         if (xflags & XFS_XFLAG_SYNC)
7747 @@ -880,6 +888,10 @@ xfs_diflags_to_linux(
7748                 inode->i_flags |= S_IMMUTABLE;
7749         else
7750                 inode->i_flags &= ~S_IMMUTABLE;
7751 +       if (xflags & XFS_XFLAG_IXUNLINK)
7752 +               inode->i_flags |= S_IXUNLINK;
7753 +       else
7754 +               inode->i_flags &= ~S_IXUNLINK;
7755         if (xflags & XFS_XFLAG_APPEND)
7756                 inode->i_flags |= S_APPEND;
7757         else
7758 @@ -1372,10 +1384,18 @@ xfs_file_ioctl(
7759         case XFS_IOC_FSGETXATTRA:
7760                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7761         case XFS_IOC_FSSETXATTR:
7762 +               if (IS_BARRIER(inode)) {
7763 +                       vxwprintk_task(1, "messing with the barrier.");
7764 +                       return -XFS_ERROR(EACCES);
7765 +               }
7766                 return xfs_ioc_fssetxattr(ip, filp, arg);
7767         case XFS_IOC_GETXFLAGS:
7768                 return xfs_ioc_getxflags(ip, arg);
7769         case XFS_IOC_SETXFLAGS:
7770 +               if (IS_BARRIER(inode)) {
7771 +                       vxwprintk_task(1, "messing with the barrier.");
7772 +                       return -XFS_ERROR(EACCES);
7773 +               }
7774                 return xfs_ioc_setxflags(ip, filp, arg);
7775  
7776         case XFS_IOC_FSSETDM: {
7777 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_ioctl.h linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_ioctl.h
7778 --- linux-3.4.32/fs/xfs/xfs_ioctl.h     2011-10-24 16:45:31.000000000 +0000
7779 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_ioctl.h   2012-05-21 16:15:05.000000000 +0000
7780 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7781         void __user             *uhandle,
7782         u32                     hlen);
7783  
7784 +extern int
7785 +xfs_sync_flags(
7786 +       struct inode            *inode,
7787 +       int                     flags,
7788 +       int                     vflags);
7789 +
7790  extern long
7791  xfs_file_ioctl(
7792         struct file             *filp,
7793 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_iops.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_iops.c
7794 --- linux-3.4.32/fs/xfs/xfs_iops.c      2012-05-21 16:07:27.000000000 +0000
7795 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_iops.c    2012-05-21 16:15:05.000000000 +0000
7796 @@ -30,6 +30,7 @@
7797  #include "xfs_bmap_btree.h"
7798  #include "xfs_dinode.h"
7799  #include "xfs_inode.h"
7800 +#include "xfs_ioctl.h"
7801  #include "xfs_bmap.h"
7802  #include "xfs_rtalloc.h"
7803  #include "xfs_error.h"
7804 @@ -49,6 +50,7 @@
7805  #include <linux/security.h>
7806  #include <linux/fiemap.h>
7807  #include <linux/slab.h>
7808 +#include <linux/vs_tag.h>
7809  
7810  static int
7811  xfs_initxattrs(
7812 @@ -424,6 +426,7 @@ xfs_vn_getattr(
7813         stat->nlink = ip->i_d.di_nlink;
7814         stat->uid = ip->i_d.di_uid;
7815         stat->gid = ip->i_d.di_gid;
7816 +       stat->tag = ip->i_d.di_tag;
7817         stat->ino = ip->i_ino;
7818         stat->atime = inode->i_atime;
7819         stat->mtime = inode->i_mtime;
7820 @@ -996,6 +999,7 @@ static const struct inode_operations xfs
7821         .removexattr            = generic_removexattr,
7822         .listxattr              = xfs_vn_listxattr,
7823         .fiemap                 = xfs_vn_fiemap,
7824 +       .sync_flags             = xfs_sync_flags,
7825  };
7826  
7827  static const struct inode_operations xfs_dir_inode_operations = {
7828 @@ -1021,6 +1025,7 @@ static const struct inode_operations xfs
7829         .getxattr               = generic_getxattr,
7830         .removexattr            = generic_removexattr,
7831         .listxattr              = xfs_vn_listxattr,
7832 +       .sync_flags             = xfs_sync_flags,
7833  };
7834  
7835  static const struct inode_operations xfs_dir_ci_inode_operations = {
7836 @@ -1070,6 +1075,10 @@ xfs_diflags_to_iflags(
7837                 inode->i_flags |= S_IMMUTABLE;
7838         else
7839                 inode->i_flags &= ~S_IMMUTABLE;
7840 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7841 +               inode->i_flags |= S_IXUNLINK;
7842 +       else
7843 +               inode->i_flags &= ~S_IXUNLINK;
7844         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7845                 inode->i_flags |= S_APPEND;
7846         else
7847 @@ -1082,6 +1091,15 @@ xfs_diflags_to_iflags(
7848                 inode->i_flags |= S_NOATIME;
7849         else
7850                 inode->i_flags &= ~S_NOATIME;
7851 +
7852 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7853 +               inode->i_vflags |= V_BARRIER;
7854 +       else
7855 +               inode->i_vflags &= ~V_BARRIER;
7856 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7857 +               inode->i_vflags |= V_COW;
7858 +       else
7859 +               inode->i_vflags &= ~V_COW;
7860  }
7861  
7862  /*
7863 @@ -1113,6 +1131,7 @@ xfs_setup_inode(
7864         set_nlink(inode, ip->i_d.di_nlink);
7865         inode->i_uid    = ip->i_d.di_uid;
7866         inode->i_gid    = ip->i_d.di_gid;
7867 +       inode->i_tag    = ip->i_d.di_tag;
7868  
7869         switch (inode->i_mode & S_IFMT) {
7870         case S_IFBLK:
7871 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_itable.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_itable.c
7872 --- linux-3.4.32/fs/xfs/xfs_itable.c    2012-05-21 16:07:27.000000000 +0000
7873 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_itable.c  2012-05-21 16:15:05.000000000 +0000
7874 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7875         buf->bs_mode = dic->di_mode;
7876         buf->bs_uid = dic->di_uid;
7877         buf->bs_gid = dic->di_gid;
7878 +       buf->bs_tag = dic->di_tag;
7879         buf->bs_size = dic->di_size;
7880         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7881         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7882 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_linux.h linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_linux.h
7883 --- linux-3.4.32/fs/xfs/xfs_linux.h     2011-10-24 16:45:31.000000000 +0000
7884 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_linux.h   2012-05-21 16:15:05.000000000 +0000
7885 @@ -121,6 +121,7 @@
7886  
7887  #define current_cpu()          (raw_smp_processor_id())
7888  #define current_pid()          (current->pid)
7889 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7890  #define current_test_flags(f)  (current->flags & (f))
7891  #define current_set_flags_nested(sp, f)                \
7892                 (*(sp) = current->flags, current->flags |= (f))
7893 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_log_recover.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_log_recover.c
7894 --- linux-3.4.32/fs/xfs/xfs_log_recover.c       2013-02-19 13:55:53.000000000 +0000
7895 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_log_recover.c     2012-11-18 23:52:29.000000000 +0000
7896 @@ -2344,7 +2344,8 @@ xlog_recover_inode_pass2(
7897         }
7898  
7899         /* The core is in in-core format */
7900 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7901 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7902 +               mp->m_flags & XFS_MOUNT_TAGGED);
7903  
7904         /* the rest is in on-disk format */
7905         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7906 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_mount.h linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_mount.h
7907 --- linux-3.4.32/fs/xfs/xfs_mount.h     2012-05-21 16:07:28.000000000 +0000
7908 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_mount.h   2012-05-21 16:15:05.000000000 +0000
7909 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
7910                                                    allocator */
7911  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7912  
7913 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7914  
7915  /*
7916   * Default minimum read and write sizes.
7917 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_super.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_super.c
7918 --- linux-3.4.32/fs/xfs/xfs_super.c     2012-05-21 16:07:28.000000000 +0000
7919 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_super.c   2012-05-21 16:15:05.000000000 +0000
7920 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7921  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7922  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7923  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7924 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7925 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7926 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7927  
7928  /*
7929   * Table driven mount option parser.
7930 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7931   * in the future, too.
7932   */
7933  enum {
7934 +       Opt_tag, Opt_notag,
7935         Opt_barrier, Opt_nobarrier, Opt_err
7936  };
7937  
7938  static const match_table_t tokens = {
7939 +       {Opt_tag, "tagxid"},
7940 +       {Opt_tag, "tag"},
7941 +       {Opt_notag, "notag"},
7942         {Opt_barrier, "barrier"},
7943         {Opt_nobarrier, "nobarrier"},
7944         {Opt_err, NULL}
7945 @@ -372,6 +379,19 @@ xfs_parseargs(
7946                 } else if (!strcmp(this_char, "irixsgid")) {
7947                         xfs_warn(mp,
7948         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7949 +#ifndef CONFIG_TAGGING_NONE
7950 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7951 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7952 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7953 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7954 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7955 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7956 +#endif
7957 +#ifdef CONFIG_PROPAGATE
7958 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7959 +                       /* use value */
7960 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7961 +#endif
7962                 } else {
7963                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7964                         return EINVAL;
7965 @@ -1127,6 +1147,16 @@ xfs_fs_remount(
7966                 case Opt_nobarrier:
7967                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7968                         break;
7969 +               case Opt_tag:
7970 +                       if (!(sb->s_flags & MS_TAGGED)) {
7971 +                               printk(KERN_INFO
7972 +                                       "XFS: %s: tagging not permitted on remount.\n",
7973 +                                       sb->s_id);
7974 +                               return -EINVAL;
7975 +                       }
7976 +                       break;
7977 +               case Opt_notag:
7978 +                       break;
7979                 default:
7980                         /*
7981                          * Logically we would return an error here to prevent
7982 @@ -1346,6 +1376,9 @@ xfs_fs_fill_super(
7983         if (error)
7984                 goto out_free_sb;
7985  
7986 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7987 +               sb->s_flags |= MS_TAGGED;
7988 +
7989         /*
7990          * we must configure the block size in the superblock before we run the
7991          * full mount process as the mount process can lookup and cache inodes.
7992 diff -NurpP --minimal linux-3.4.32/fs/xfs/xfs_vnodeops.c linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_vnodeops.c
7993 --- linux-3.4.32/fs/xfs/xfs_vnodeops.c  2012-05-21 16:07:28.000000000 +0000
7994 +++ linux-3.4.32-vs2.3.3.9/fs/xfs/xfs_vnodeops.c        2012-05-21 16:15:05.000000000 +0000
7995 @@ -106,6 +106,77 @@ xfs_readlink_bmap(
7996         return error;
7997  }
7998  
7999 +
8000 +STATIC void
8001 +xfs_get_inode_flags(
8002 +       xfs_inode_t     *ip)
8003 +{
8004 +       struct inode    *inode = VFS_I(ip);
8005 +       unsigned int    flags = inode->i_flags;
8006 +       unsigned int    vflags = inode->i_vflags;
8007 +
8008 +       if (flags & S_IMMUTABLE)
8009 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8010 +       else
8011 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8012 +       if (flags & S_IXUNLINK)
8013 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8014 +       else
8015 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8016 +
8017 +       if (vflags & V_BARRIER)
8018 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8019 +       else
8020 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8021 +       if (vflags & V_COW)
8022 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8023 +       else
8024 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8025 +}
8026 +
8027 +int
8028 +xfs_sync_flags(
8029 +       struct inode            *inode,
8030 +       int                     flags,
8031 +       int                     vflags)
8032 +{
8033 +       struct xfs_inode        *ip = XFS_I(inode);
8034 +       struct xfs_mount        *mp = ip->i_mount;
8035 +       struct xfs_trans        *tp;
8036 +       unsigned int            lock_flags = 0;
8037 +       int                     code;
8038 +
8039 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8040 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8041 +       if (code)
8042 +               goto error_out;
8043 +
8044 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8045 +       xfs_trans_ijoin(tp, ip, 0);
8046 +
8047 +       inode->i_flags = flags;
8048 +       inode->i_vflags = vflags;
8049 +       xfs_get_inode_flags(ip);
8050 +
8051 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8052 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8053 +
8054 +       XFS_STATS_INC(xs_ig_attrchg);
8055 +
8056 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8057 +               xfs_trans_set_sync(tp);
8058 +       code = xfs_trans_commit(tp, 0);
8059 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8060 +       return code;
8061 +
8062 +error_out:
8063 +       xfs_trans_cancel(tp, 0);
8064 +       if (lock_flags)
8065 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8066 +       return code;
8067 +}
8068 +
8069 +
8070  int
8071  xfs_readlink(
8072         xfs_inode_t     *ip,
8073 diff -NurpP --minimal linux-3.4.32/include/linux/Kbuild linux-3.4.32-vs2.3.3.9/include/linux/Kbuild
8074 --- linux-3.4.32/include/linux/Kbuild   2013-02-19 13:55:53.000000000 +0000
8075 +++ linux-3.4.32-vs2.3.3.9/include/linux/Kbuild 2012-07-24 09:52:30.000000000 +0000
8076 @@ -18,6 +18,7 @@ header-y += netfilter_bridge/
8077  header-y += netfilter_ipv4/
8078  header-y += netfilter_ipv6/
8079  header-y += usb/
8080 +header-y += vserver/
8081  header-y += wimax/
8082  
8083  objhdr-y += version.h
8084 diff -NurpP --minimal linux-3.4.32/include/linux/capability.h linux-3.4.32-vs2.3.3.9/include/linux/capability.h
8085 --- linux-3.4.32/include/linux/capability.h     2012-03-19 18:47:27.000000000 +0000
8086 +++ linux-3.4.32-vs2.3.3.9/include/linux/capability.h   2012-05-21 16:15:05.000000000 +0000
8087 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
8088     arbitrary SCSI commands */
8089  /* Allow setting encryption key on loopback filesystem */
8090  /* Allow setting zone reclaim policy */
8091 +/* Allow the selection of a security context */
8092  
8093  #define CAP_SYS_ADMIN        21
8094  
8095 @@ -363,7 +364,12 @@ struct cpu_vfs_cap_data {
8096  
8097  #define CAP_LAST_CAP         CAP_WAKE_ALARM
8098  
8099 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8100 +/* Allow context manipulations */
8101 +/* Allow changing context info on files */
8102 +
8103 +#define CAP_CONTEXT         63
8104 +
8105 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8106  
8107  /*
8108   * Bit location of each capability (used by user-space library and kernel)
8109 diff -NurpP --minimal linux-3.4.32/include/linux/cred.h linux-3.4.32-vs2.3.3.9/include/linux/cred.h
8110 --- linux-3.4.32/include/linux/cred.h   2012-03-19 18:47:27.000000000 +0000
8111 +++ linux-3.4.32-vs2.3.3.9/include/linux/cred.h 2012-05-21 16:15:05.000000000 +0000
8112 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
8113  extern int copy_creds(struct task_struct *, unsigned long);
8114  extern const struct cred *get_task_cred(struct task_struct *);
8115  extern struct cred *cred_alloc_blank(void);
8116 +extern struct cred *__prepare_creds(const struct cred *);
8117  extern struct cred *prepare_creds(void);
8118  extern struct cred *prepare_exec_creds(void);
8119  extern int commit_creds(struct cred *);
8120 @@ -209,6 +210,31 @@ static inline void validate_process_cred
8121  }
8122  #endif
8123  
8124 +static inline void set_cred_subscribers(struct cred *cred, int n)
8125 +{
8126 +#ifdef CONFIG_DEBUG_CREDENTIALS
8127 +       atomic_set(&cred->subscribers, n);
8128 +#endif
8129 +}
8130 +
8131 +static inline int read_cred_subscribers(const struct cred *cred)
8132 +{
8133 +#ifdef CONFIG_DEBUG_CREDENTIALS
8134 +       return atomic_read(&cred->subscribers);
8135 +#else
8136 +       return 0;
8137 +#endif
8138 +}
8139 +
8140 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8141 +{
8142 +#ifdef CONFIG_DEBUG_CREDENTIALS
8143 +       struct cred *cred = (struct cred *) _cred;
8144 +
8145 +       atomic_add(n, &cred->subscribers);
8146 +#endif
8147 +}
8148 +
8149  /**
8150   * get_new_cred - Get a reference on a new set of credentials
8151   * @cred: The new credentials to reference
8152 diff -NurpP --minimal linux-3.4.32/include/linux/devpts_fs.h linux-3.4.32-vs2.3.3.9/include/linux/devpts_fs.h
8153 --- linux-3.4.32/include/linux/devpts_fs.h      2008-12-24 23:26:37.000000000 +0000
8154 +++ linux-3.4.32-vs2.3.3.9/include/linux/devpts_fs.h    2012-05-21 16:15:05.000000000 +0000
8155 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8156  
8157  #endif
8158  
8159 -
8160  #endif /* _LINUX_DEVPTS_FS_H */
8161 diff -NurpP --minimal linux-3.4.32/include/linux/fs.h linux-3.4.32-vs2.3.3.9/include/linux/fs.h
8162 --- linux-3.4.32/include/linux/fs.h     2012-05-21 16:07:29.000000000 +0000
8163 +++ linux-3.4.32-vs2.3.3.9/include/linux/fs.h   2012-05-21 16:15:05.000000000 +0000
8164 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8165  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8166  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8167  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8168 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8169 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8170 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8171  #define MS_NOSEC       (1<<28)
8172  #define MS_BORN                (1<<29)
8173  #define MS_ACTIVE      (1<<30)
8174 @@ -245,6 +248,14 @@ struct inodes_stat_t {
8175  #define S_IMA          1024    /* Inode has an associated IMA struct */
8176  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8177  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8178 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8179 +
8180 +/* Linux-VServer related Inode flags */
8181 +
8182 +#define V_VALID                1
8183 +#define V_XATTR                2
8184 +#define V_BARRIER      4       /* Barrier for chroot() */
8185 +#define V_COW          8       /* Copy on Write */
8186  
8187  /*
8188   * Note that nosuid etc flags are inode-specific: setting some file-system
8189 @@ -267,12 +278,15 @@ struct inodes_stat_t {
8190  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8191                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8192  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8193 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8194 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8195 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8196 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8197 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8198  
8199  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8200  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8201  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8202 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8203 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8204  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8205  
8206  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8207 @@ -283,6 +297,16 @@ struct inodes_stat_t {
8208  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8209  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8210  
8211 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8212 +
8213 +#ifdef CONFIG_VSERVER_COWBL
8214 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8215 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8216 +#else
8217 +#  define IS_COW(inode)                (0)
8218 +#  define IS_COW_LINK(inode)   (0)
8219 +#endif
8220 +
8221  /* the read-only stuff doesn't really belong here, but any other place is
8222     probably as bad and I don't want to create yet another include file. */
8223  
8224 @@ -369,11 +393,14 @@ struct inodes_stat_t {
8225  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8226  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8227  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8228 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8229  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8230  
8231 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8232 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8233 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8234 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8235  
8236 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8237 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8238  
8239  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8240  #define SYNC_FILE_RANGE_WRITE          2
8241 @@ -456,6 +483,7 @@ typedef void (dio_iodone_t)(struct kiocb
8242  #define ATTR_KILL_PRIV (1 << 14)
8243  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8244  #define ATTR_TIMES_SET (1 << 16)
8245 +#define ATTR_TAG       (1 << 17)
8246  
8247  /*
8248   * This is the Inode Attributes structure, used for notify_change().  It
8249 @@ -471,6 +499,7 @@ struct iattr {
8250         umode_t         ia_mode;
8251         uid_t           ia_uid;
8252         gid_t           ia_gid;
8253 +       tag_t           ia_tag;
8254         loff_t          ia_size;
8255         struct timespec ia_atime;
8256         struct timespec ia_mtime;
8257 @@ -484,6 +513,9 @@ struct iattr {
8258         struct file     *ia_file;
8259  };
8260  
8261 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8262 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8263 +
8264  /*
8265   * Includes for diskquotas.
8266   */
8267 @@ -763,7 +795,9 @@ struct inode {
8268         unsigned short          i_opflags;
8269         uid_t                   i_uid;
8270         gid_t                   i_gid;
8271 -       unsigned int            i_flags;
8272 +       tag_t                   i_tag;
8273 +       unsigned short          i_flags;
8274 +       unsigned short          i_vflags;
8275  
8276  #ifdef CONFIG_FS_POSIX_ACL
8277         struct posix_acl        *i_acl;
8278 @@ -792,6 +826,7 @@ struct inode {
8279                 unsigned int __i_nlink;
8280         };
8281         dev_t                   i_rdev;
8282 +       dev_t                   i_mdev;
8283         struct timespec         i_atime;
8284         struct timespec         i_mtime;
8285         struct timespec         i_ctime;
8286 @@ -929,12 +964,12 @@ static inline void i_size_write(struct i
8287  
8288  static inline unsigned iminor(const struct inode *inode)
8289  {
8290 -       return MINOR(inode->i_rdev);
8291 +       return MINOR(inode->i_mdev);
8292  }
8293  
8294  static inline unsigned imajor(const struct inode *inode)
8295  {
8296 -       return MAJOR(inode->i_rdev);
8297 +       return MAJOR(inode->i_mdev);
8298  }
8299  
8300  extern struct block_device *I_BDEV(struct inode *inode);
8301 @@ -1001,6 +1036,7 @@ struct file {
8302         loff_t                  f_pos;
8303         struct fown_struct      f_owner;
8304         const struct cred       *f_cred;
8305 +       xid_t                   f_xid;
8306         struct file_ra_state    f_ra;
8307  
8308         u64                     f_version;
8309 @@ -1148,6 +1184,7 @@ struct file_lock {
8310         struct file *fl_file;
8311         loff_t fl_start;
8312         loff_t fl_end;
8313 +       xid_t fl_xid;
8314  
8315         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8316         /* for lease breaks: */
8317 @@ -1661,6 +1698,7 @@ struct inode_operations {
8318         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8319         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8320         int (*removexattr) (struct dentry *, const char *);
8321 +       int (*sync_flags) (struct inode *, int, int);
8322         void (*truncate_range)(struct inode *, loff_t, loff_t);
8323         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8324                       u64 len);
8325 @@ -1680,6 +1718,7 @@ extern ssize_t vfs_readv(struct file *,
8326                 unsigned long, loff_t *);
8327  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8328                 unsigned long, loff_t *);
8329 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8330  
8331  struct super_operations {
8332         struct inode *(*alloc_inode)(struct super_block *sb);
8333 @@ -2509,6 +2548,7 @@ extern int dcache_dir_open(struct inode
8334  extern int dcache_dir_close(struct inode *, struct file *);
8335  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8336  extern int dcache_readdir(struct file *, void *, filldir_t);
8337 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8338  extern int simple_setattr(struct dentry *, struct iattr *);
8339  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8340  extern int simple_statfs(struct dentry *, struct kstatfs *);
8341 diff -NurpP --minimal linux-3.4.32/include/linux/gfs2_ondisk.h linux-3.4.32-vs2.3.3.9/include/linux/gfs2_ondisk.h
8342 --- linux-3.4.32/include/linux/gfs2_ondisk.h    2012-05-21 16:07:29.000000000 +0000
8343 +++ linux-3.4.32-vs2.3.3.9/include/linux/gfs2_ondisk.h  2012-05-21 16:15:05.000000000 +0000
8344 @@ -214,6 +214,9 @@ enum {
8345         gfs2fl_NoAtime          = 7,
8346         gfs2fl_Sync             = 8,
8347         gfs2fl_System           = 9,
8348 +       gfs2fl_IXUnlink         = 16,
8349 +       gfs2fl_Barrier          = 17,
8350 +       gfs2fl_Cow              = 18,
8351         gfs2fl_TruncInProg      = 29,
8352         gfs2fl_InheritDirectio  = 30,
8353         gfs2fl_InheritJdata     = 31,
8354 @@ -230,6 +233,9 @@ enum {
8355  #define GFS2_DIF_NOATIME               0x00000080
8356  #define GFS2_DIF_SYNC                  0x00000100
8357  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8358 +#define GFS2_DIF_IXUNLINK              0x00010000
8359 +#define GFS2_DIF_BARRIER               0x00020000
8360 +#define GFS2_DIF_COW                   0x00040000
8361  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8362  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8363  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8364 diff -NurpP --minimal linux-3.4.32/include/linux/if_tun.h linux-3.4.32-vs2.3.3.9/include/linux/if_tun.h
8365 --- linux-3.4.32/include/linux/if_tun.h 2010-08-02 14:52:54.000000000 +0000
8366 +++ linux-3.4.32-vs2.3.3.9/include/linux/if_tun.h       2012-05-21 16:15:05.000000000 +0000
8367 @@ -53,6 +53,7 @@
8368  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8369  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8370  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8371 +#define TUNSETNID     _IOW('T', 217, int)
8372  
8373  /* TUNSETIFF ifr flags */
8374  #define IFF_TUN                0x0001
8375 diff -NurpP --minimal linux-3.4.32/include/linux/init_task.h linux-3.4.32-vs2.3.3.9/include/linux/init_task.h
8376 --- linux-3.4.32/include/linux/init_task.h      2013-02-19 13:55:53.000000000 +0000
8377 +++ linux-3.4.32-vs2.3.3.9/include/linux/init_task.h    2012-10-22 13:09:53.000000000 +0000
8378 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
8379         INIT_TRACE_RECURSION                                            \
8380         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8381         INIT_CPUSET_SEQ                                                 \
8382 +       .xid            = 0,                                            \
8383 +       .vx_info        = NULL,                                         \
8384 +       .nid            = 0,                                            \
8385 +       .nx_info        = NULL,                                         \
8386  }
8387  
8388  
8389 diff -NurpP --minimal linux-3.4.32/include/linux/ipc.h linux-3.4.32-vs2.3.3.9/include/linux/ipc.h
8390 --- linux-3.4.32/include/linux/ipc.h    2012-03-19 18:47:28.000000000 +0000
8391 +++ linux-3.4.32-vs2.3.3.9/include/linux/ipc.h  2012-05-21 16:15:05.000000000 +0000
8392 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8393         key_t           key;
8394         uid_t           uid;
8395         gid_t           gid;
8396 +       xid_t           xid;
8397         uid_t           cuid;
8398         gid_t           cgid;
8399         umode_t         mode; 
8400 diff -NurpP --minimal linux-3.4.32/include/linux/ipc_namespace.h linux-3.4.32-vs2.3.3.9/include/linux/ipc_namespace.h
8401 --- linux-3.4.32/include/linux/ipc_namespace.h  2011-10-24 16:45:32.000000000 +0000
8402 +++ linux-3.4.32-vs2.3.3.9/include/linux/ipc_namespace.h        2012-05-21 16:15:05.000000000 +0000
8403 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8404  
8405  #if defined(CONFIG_IPC_NS)
8406  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8407 -                                      struct task_struct *tsk);
8408 +                                      struct ipc_namespace *old_ns,
8409 +                                      struct user_namespace *user_ns);
8410  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8411  {
8412         if (ns)
8413 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8414  extern void put_ipc_ns(struct ipc_namespace *ns);
8415  #else
8416  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8417 -                                             struct task_struct *tsk)
8418 +                                             struct ipc_namespace *old_ns,
8419 +                                             struct user_namespace *user_ns)
8420  {
8421         if (flags & CLONE_NEWIPC)
8422                 return ERR_PTR(-EINVAL);
8423  
8424 -       return tsk->nsproxy->ipc_ns;
8425 +       return old_ns;
8426  }
8427  
8428  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8429 diff -NurpP --minimal linux-3.4.32/include/linux/loop.h linux-3.4.32-vs2.3.3.9/include/linux/loop.h
8430 --- linux-3.4.32/include/linux/loop.h   2012-01-09 15:14:58.000000000 +0000
8431 +++ linux-3.4.32-vs2.3.3.9/include/linux/loop.h 2012-05-21 16:15:05.000000000 +0000
8432 @@ -45,6 +45,7 @@ struct loop_device {
8433         struct loop_func_table *lo_encryption;
8434         __u32           lo_init[2];
8435         uid_t           lo_key_owner;   /* Who set the key */
8436 +       xid_t           lo_xid;
8437         int             (*ioctl)(struct loop_device *, int cmd, 
8438                                  unsigned long arg); 
8439  
8440 diff -NurpP --minimal linux-3.4.32/include/linux/magic.h linux-3.4.32-vs2.3.3.9/include/linux/magic.h
8441 --- linux-3.4.32/include/linux/magic.h  2012-05-21 16:07:31.000000000 +0000
8442 +++ linux-3.4.32-vs2.3.3.9/include/linux/magic.h        2012-05-21 16:15:05.000000000 +0000
8443 @@ -3,7 +3,7 @@
8444  
8445  #define ADFS_SUPER_MAGIC       0xadf5
8446  #define AFFS_SUPER_MAGIC       0xadff
8447 -#define AFS_SUPER_MAGIC                0x5346414F
8448 +#define AFS_SUPER_MAGIC                0x5346414F
8449  #define AUTOFS_SUPER_MAGIC     0x0187
8450  #define CODA_SUPER_MAGIC       0x73757245
8451  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8452 diff -NurpP --minimal linux-3.4.32/include/linux/major.h linux-3.4.32-vs2.3.3.9/include/linux/major.h
8453 --- linux-3.4.32/include/linux/major.h  2009-09-10 13:26:25.000000000 +0000
8454 +++ linux-3.4.32-vs2.3.3.9/include/linux/major.h        2012-05-21 16:15:05.000000000 +0000
8455 @@ -15,6 +15,7 @@
8456  #define HD_MAJOR               IDE0_MAJOR
8457  #define PTY_SLAVE_MAJOR                3
8458  #define TTY_MAJOR              4
8459 +#define VROOT_MAJOR            4
8460  #define TTYAUX_MAJOR           5
8461  #define LP_MAJOR               6
8462  #define VCS_MAJOR              7
8463 diff -NurpP --minimal linux-3.4.32/include/linux/memcontrol.h linux-3.4.32-vs2.3.3.9/include/linux/memcontrol.h
8464 --- linux-3.4.32/include/linux/memcontrol.h     2012-05-21 16:07:31.000000000 +0000
8465 +++ linux-3.4.32-vs2.3.3.9/include/linux/memcontrol.h   2012-05-21 16:15:05.000000000 +0000
8466 @@ -88,6 +88,13 @@ extern struct mem_cgroup *try_get_mem_cg
8467  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8468  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8469  
8470 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8471 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8472 +
8473 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8474 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8475 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8476 +
8477  static inline
8478  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8479  {
8480 diff -NurpP --minimal linux-3.4.32/include/linux/mm_types.h linux-3.4.32-vs2.3.3.9/include/linux/mm_types.h
8481 --- linux-3.4.32/include/linux/mm_types.h       2013-02-19 13:55:53.000000000 +0000
8482 +++ linux-3.4.32-vs2.3.3.9/include/linux/mm_types.h     2012-07-17 22:29:43.000000000 +0000
8483 @@ -353,6 +353,7 @@ struct mm_struct {
8484  
8485         /* Architecture-specific MM context */
8486         mm_context_t context;
8487 +       struct vx_info *mm_vx_info;
8488  
8489         /* Swap token stuff */
8490         /*
8491 diff -NurpP --minimal linux-3.4.32/include/linux/mmzone.h linux-3.4.32-vs2.3.3.9/include/linux/mmzone.h
8492 --- linux-3.4.32/include/linux/mmzone.h 2013-02-19 13:55:57.000000000 +0000
8493 +++ linux-3.4.32-vs2.3.3.9/include/linux/mmzone.h       2012-07-17 22:29:43.000000000 +0000
8494 @@ -684,6 +684,13 @@ typedef struct pglist_data {
8495         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8496  })
8497  
8498 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8499 +
8500 +#define node_end_pfn(nid) ({\
8501 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8502 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8503 +})
8504 +
8505  #include <linux/memory_hotplug.h>
8506  
8507  extern struct mutex zonelists_mutex;
8508 diff -NurpP --minimal linux-3.4.32/include/linux/mount.h linux-3.4.32-vs2.3.3.9/include/linux/mount.h
8509 --- linux-3.4.32/include/linux/mount.h  2012-03-19 18:47:28.000000000 +0000
8510 +++ linux-3.4.32-vs2.3.3.9/include/linux/mount.h        2012-05-21 16:15:05.000000000 +0000
8511 @@ -47,6 +47,9 @@ struct mnt_namespace;
8512  
8513  #define MNT_INTERNAL   0x4000
8514  
8515 +#define MNT_TAGID      0x10000
8516 +#define MNT_NOTAG      0x20000
8517 +
8518  struct vfsmount {
8519         struct dentry *mnt_root;        /* root of the mounted tree */
8520         struct super_block *mnt_sb;     /* pointer to superblock */
8521 diff -NurpP --minimal linux-3.4.32/include/linux/net.h linux-3.4.32-vs2.3.3.9/include/linux/net.h
8522 --- linux-3.4.32/include/linux/net.h    2013-02-19 13:55:59.000000000 +0000
8523 +++ linux-3.4.32-vs2.3.3.9/include/linux/net.h  2012-09-01 08:51:18.000000000 +0000
8524 @@ -73,6 +73,7 @@ struct net;
8525  #define SOCK_PASSCRED          3
8526  #define SOCK_PASSSEC           4
8527  #define SOCK_EXTERNALLY_ALLOCATED 5
8528 +#define SOCK_USER_SOCKET       6
8529  
8530  #ifndef ARCH_HAS_SOCKET_TYPES
8531  /**
8532 diff -NurpP --minimal linux-3.4.32/include/linux/netdevice.h linux-3.4.32-vs2.3.3.9/include/linux/netdevice.h
8533 --- linux-3.4.32/include/linux/netdevice.h      2013-02-19 13:56:02.000000000 +0000
8534 +++ linux-3.4.32-vs2.3.3.9/include/linux/netdevice.h    2012-10-22 13:09:53.000000000 +0000
8535 @@ -1624,6 +1624,7 @@ extern void               netdev_resync_ops(struct ne
8536  
8537  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8538  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8539 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8540  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8541  extern int             dev_restart(struct net_device *dev);
8542  #ifdef CONFIG_NETPOLL_TRAP
8543 diff -NurpP --minimal linux-3.4.32/include/linux/nfs_mount.h linux-3.4.32-vs2.3.3.9/include/linux/nfs_mount.h
8544 --- linux-3.4.32/include/linux/nfs_mount.h      2011-01-05 20:50:31.000000000 +0000
8545 +++ linux-3.4.32-vs2.3.3.9/include/linux/nfs_mount.h    2012-05-21 16:15:05.000000000 +0000
8546 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8547  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8548  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8549  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8550 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8551 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8552 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8553  
8554  /* The following are for internal use only */
8555  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8556 diff -NurpP --minimal linux-3.4.32/include/linux/nsproxy.h linux-3.4.32-vs2.3.3.9/include/linux/nsproxy.h
8557 --- linux-3.4.32/include/linux/nsproxy.h        2011-10-24 16:45:32.000000000 +0000
8558 +++ linux-3.4.32-vs2.3.3.9/include/linux/nsproxy.h      2012-05-21 16:15:05.000000000 +0000
8559 @@ -3,6 +3,7 @@
8560  
8561  #include <linux/spinlock.h>
8562  #include <linux/sched.h>
8563 +#include <linux/vserver/debug.h>
8564  
8565  struct mnt_namespace;
8566  struct uts_namespace;
8567 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8568  }
8569  
8570  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8571 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8572  void exit_task_namespaces(struct task_struct *tsk);
8573  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8574  void free_nsproxy(struct nsproxy *ns);
8575 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
8576         struct fs_struct *);
8577  int __init nsproxy_cache_init(void);
8578  
8579 -static inline void put_nsproxy(struct nsproxy *ns)
8580 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8581 +
8582 +static inline void __get_nsproxy(struct nsproxy *ns,
8583 +       const char *_file, int _line)
8584  {
8585 -       if (atomic_dec_and_test(&ns->count)) {
8586 -               free_nsproxy(ns);
8587 -       }
8588 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8589 +               ns, atomic_read(&ns->count), _file, _line);
8590 +       atomic_inc(&ns->count);
8591  }
8592  
8593 -static inline void get_nsproxy(struct nsproxy *ns)
8594 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8595 +
8596 +static inline void __put_nsproxy(struct nsproxy *ns,
8597 +       const char *_file, int _line)
8598  {
8599 -       atomic_inc(&ns->count);
8600 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8601 +               ns, atomic_read(&ns->count), _file, _line);
8602 +       if (atomic_dec_and_test(&ns->count)) {
8603 +               free_nsproxy(ns);
8604 +       }
8605  }
8606  
8607  #endif
8608 diff -NurpP --minimal linux-3.4.32/include/linux/pid.h linux-3.4.32-vs2.3.3.9/include/linux/pid.h
8609 --- linux-3.4.32/include/linux/pid.h    2011-07-22 09:18:11.000000000 +0000
8610 +++ linux-3.4.32-vs2.3.3.9/include/linux/pid.h  2012-05-21 16:15:05.000000000 +0000
8611 @@ -8,7 +8,8 @@ enum pid_type
8612         PIDTYPE_PID,
8613         PIDTYPE_PGID,
8614         PIDTYPE_SID,
8615 -       PIDTYPE_MAX
8616 +       PIDTYPE_MAX,
8617 +       PIDTYPE_REALPID
8618  };
8619  
8620  /*
8621 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8622  }
8623  
8624  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8625 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8626  pid_t pid_vnr(struct pid *pid);
8627  
8628  #define do_each_pid_task(pid, type, task)                              \
8629 diff -NurpP --minimal linux-3.4.32/include/linux/proc_fs.h linux-3.4.32-vs2.3.3.9/include/linux/proc_fs.h
8630 --- linux-3.4.32/include/linux/proc_fs.h        2012-03-19 18:47:28.000000000 +0000
8631 +++ linux-3.4.32-vs2.3.3.9/include/linux/proc_fs.h      2012-05-21 16:15:05.000000000 +0000
8632 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8633         nlink_t nlink;
8634         uid_t uid;
8635         gid_t gid;
8636 +       int vx_flags;
8637         loff_t size;
8638         const struct inode_operations *proc_iops;
8639         /*
8640 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8641  extern const struct proc_ns_operations utsns_operations;
8642  extern const struct proc_ns_operations ipcns_operations;
8643  
8644 +struct vx_info;
8645 +struct nx_info;
8646 +
8647  union proc_op {
8648         int (*proc_get_link)(struct dentry *, struct path *);
8649         int (*proc_read)(struct task_struct *task, char *page);
8650         int (*proc_show)(struct seq_file *m,
8651                 struct pid_namespace *ns, struct pid *pid,
8652                 struct task_struct *task);
8653 +       int (*proc_vs_read)(char *page);
8654 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8655 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8656  };
8657  
8658  struct ctl_table_header;
8659 @@ -265,6 +272,7 @@ struct ctl_table;
8660  
8661  struct proc_inode {
8662         struct pid *pid;
8663 +       int vx_flags;
8664         int fd;
8665         union proc_op op;
8666         struct proc_dir_entry *pde;
8667 diff -NurpP --minimal linux-3.4.32/include/linux/quotaops.h linux-3.4.32-vs2.3.3.9/include/linux/quotaops.h
8668 --- linux-3.4.32/include/linux/quotaops.h       2012-01-09 15:14:58.000000000 +0000
8669 +++ linux-3.4.32-vs2.3.3.9/include/linux/quotaops.h     2012-05-21 16:15:05.000000000 +0000
8670 @@ -8,6 +8,7 @@
8671  #define _LINUX_QUOTAOPS_
8672  
8673  #include <linux/fs.h>
8674 +#include <linux/vs_dlimit.h>
8675  
8676  #define DQUOT_SPACE_WARN       0x1
8677  #define DQUOT_SPACE_RESERVE    0x2
8678 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8679  
8680  static inline int dquot_alloc_inode(const struct inode *inode)
8681  {
8682 -       return 0;
8683 +       return dl_alloc_inode(inode);
8684  }
8685  
8686  static inline void dquot_free_inode(const struct inode *inode)
8687  {
8688 +       dl_free_inode(inode);
8689  }
8690  
8691  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8692 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct
8693  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8694                 int flags)
8695  {
8696 +       int ret = 0;
8697 +
8698 +       if ((ret = dl_alloc_space(inode, number)))
8699 +               return ret;
8700         if (!(flags & DQUOT_SPACE_RESERVE))
8701                 inode_add_bytes(inode, number);
8702         return 0;
8703 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8704  {
8705         if (!(flags & DQUOT_SPACE_RESERVE))
8706                 inode_sub_bytes(inode, number);
8707 +       dl_free_space(inode, number);
8708  }
8709  
8710  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8711 diff -NurpP --minimal linux-3.4.32/include/linux/reboot.h linux-3.4.32-vs2.3.3.9/include/linux/reboot.h
8712 --- linux-3.4.32/include/linux/reboot.h 2011-10-24 16:45:32.000000000 +0000
8713 +++ linux-3.4.32-vs2.3.3.9/include/linux/reboot.h       2012-05-21 16:15:05.000000000 +0000
8714 @@ -33,6 +33,7 @@
8715  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8716  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8717  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8718 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8719  
8720  
8721  #ifdef __KERNEL__
8722 diff -NurpP --minimal linux-3.4.32/include/linux/sched.h linux-3.4.32-vs2.3.3.9/include/linux/sched.h
8723 --- linux-3.4.32/include/linux/sched.h  2013-02-19 13:56:07.000000000 +0000
8724 +++ linux-3.4.32-vs2.3.3.9/include/linux/sched.h        2013-02-11 23:37:30.000000000 +0000
8725 @@ -1455,6 +1455,14 @@ struct task_struct {
8726  #endif
8727         seccomp_t seccomp;
8728  
8729 +/* vserver context data */
8730 +       struct vx_info *vx_info;
8731 +       struct nx_info *nx_info;
8732 +
8733 +       xid_t xid;
8734 +       nid_t nid;
8735 +       tag_t tag;
8736 +
8737  /* Thread group tracking */
8738         u32 parent_exec_id;
8739         u32 self_exec_id;
8740 @@ -1699,6 +1707,11 @@ struct pid_namespace;
8741  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8742                         struct pid_namespace *ns);
8743  
8744 +#include <linux/vserver/base.h>
8745 +#include <linux/vserver/context.h>
8746 +#include <linux/vserver/debug.h>
8747 +#include <linux/vserver/pid.h>
8748 +
8749  static inline pid_t task_pid_nr(struct task_struct *tsk)
8750  {
8751         return tsk->pid;
8752 @@ -1712,7 +1725,8 @@ static inline pid_t task_pid_nr_ns(struc
8753  
8754  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8755  {
8756 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8757 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8758 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8759  }
8760  
8761  
8762 @@ -1725,7 +1739,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8763  
8764  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8765  {
8766 -       return pid_vnr(task_tgid(tsk));
8767 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8768  }
8769  
8770  
8771 diff -NurpP --minimal linux-3.4.32/include/linux/shmem_fs.h linux-3.4.32-vs2.3.3.9/include/linux/shmem_fs.h
8772 --- linux-3.4.32/include/linux/shmem_fs.h       2012-03-19 18:47:29.000000000 +0000
8773 +++ linux-3.4.32-vs2.3.3.9/include/linux/shmem_fs.h     2012-05-21 16:15:05.000000000 +0000
8774 @@ -8,6 +8,9 @@
8775  
8776  /* inode in-kernel data */
8777  
8778 +#define TMPFS_SUPER_MAGIC      0x01021994
8779 +
8780 +
8781  struct shmem_inode_info {
8782         spinlock_t              lock;
8783         unsigned long           flags;
8784 diff -NurpP --minimal linux-3.4.32/include/linux/stat.h linux-3.4.32-vs2.3.3.9/include/linux/stat.h
8785 --- linux-3.4.32/include/linux/stat.h   2008-12-24 23:26:37.000000000 +0000
8786 +++ linux-3.4.32-vs2.3.3.9/include/linux/stat.h 2012-05-21 16:15:05.000000000 +0000
8787 @@ -66,6 +66,7 @@ struct kstat {
8788         unsigned int    nlink;
8789         uid_t           uid;
8790         gid_t           gid;
8791 +       tag_t           tag;
8792         dev_t           rdev;
8793         loff_t          size;
8794         struct timespec  atime;
8795 diff -NurpP --minimal linux-3.4.32/include/linux/sunrpc/auth.h linux-3.4.32-vs2.3.3.9/include/linux/sunrpc/auth.h
8796 --- linux-3.4.32/include/linux/sunrpc/auth.h    2012-05-21 16:07:32.000000000 +0000
8797 +++ linux-3.4.32-vs2.3.3.9/include/linux/sunrpc/auth.h  2012-05-21 16:15:05.000000000 +0000
8798 @@ -25,6 +25,7 @@
8799  struct auth_cred {
8800         uid_t   uid;
8801         gid_t   gid;
8802 +       tag_t   tag;
8803         struct group_info *group_info;
8804         const char *principal;
8805         unsigned char machine_cred : 1;
8806 diff -NurpP --minimal linux-3.4.32/include/linux/sunrpc/clnt.h linux-3.4.32-vs2.3.3.9/include/linux/sunrpc/clnt.h
8807 --- linux-3.4.32/include/linux/sunrpc/clnt.h    2012-05-21 16:07:32.000000000 +0000
8808 +++ linux-3.4.32-vs2.3.3.9/include/linux/sunrpc/clnt.h  2012-05-21 16:15:05.000000000 +0000
8809 @@ -49,7 +49,8 @@ struct rpc_clnt {
8810         unsigned int            cl_softrtry : 1,/* soft timeouts */
8811                                 cl_discrtry : 1,/* disconnect before retry */
8812                                 cl_autobind : 1,/* use getport() */
8813 -                               cl_chatty   : 1;/* be verbose */
8814 +                               cl_chatty   : 1,/* be verbose */
8815 +                               cl_tag      : 1;/* context tagging */
8816  
8817         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8818         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8819 diff -NurpP --minimal linux-3.4.32/include/linux/sysctl.h linux-3.4.32-vs2.3.3.9/include/linux/sysctl.h
8820 --- linux-3.4.32/include/linux/sysctl.h 2012-05-21 16:07:32.000000000 +0000
8821 +++ linux-3.4.32-vs2.3.3.9/include/linux/sysctl.h       2012-05-21 16:15:05.000000000 +0000
8822 @@ -60,6 +60,7 @@ enum
8823         CTL_ABI=9,              /* Binary emulation */
8824         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8825         CTL_ARLAN=254,          /* arlan wireless driver */
8826 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8827         CTL_S390DBF=5677,       /* s390 debug */
8828         CTL_SUNRPC=7249,        /* sunrpc debug */
8829         CTL_PM=9899,            /* frv power management */
8830 @@ -94,6 +95,7 @@ enum
8831  
8832         KERN_PANIC=15,          /* int: panic timeout */
8833         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8834 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8835  
8836         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8837         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8838 diff -NurpP --minimal linux-3.4.32/include/linux/sysfs.h linux-3.4.32-vs2.3.3.9/include/linux/sysfs.h
8839 --- linux-3.4.32/include/linux/sysfs.h  2012-03-19 18:47:29.000000000 +0000
8840 +++ linux-3.4.32-vs2.3.3.9/include/linux/sysfs.h        2012-05-21 16:15:05.000000000 +0000
8841 @@ -19,6 +19,8 @@
8842  #include <linux/kobject_ns.h>
8843  #include <linux/atomic.h>
8844  
8845 +#define SYSFS_SUPER_MAGIC      0x62656572
8846 +
8847  struct kobject;
8848  struct module;
8849  enum kobj_ns_type;
8850 diff -NurpP --minimal linux-3.4.32/include/linux/time.h linux-3.4.32-vs2.3.3.9/include/linux/time.h
8851 --- linux-3.4.32/include/linux/time.h   2013-02-19 13:56:07.000000000 +0000
8852 +++ linux-3.4.32-vs2.3.3.9/include/linux/time.h 2012-10-22 13:09:53.000000000 +0000
8853 @@ -281,6 +281,8 @@ static __always_inline void timespec_add
8854         a->tv_nsec = ns;
8855  }
8856  
8857 +#include <linux/vs_time.h>
8858 +
8859  #endif /* __KERNEL__ */
8860  
8861  /*
8862 diff -NurpP --minimal linux-3.4.32/include/linux/types.h linux-3.4.32-vs2.3.3.9/include/linux/types.h
8863 --- linux-3.4.32/include/linux/types.h  2012-05-21 16:07:32.000000000 +0000
8864 +++ linux-3.4.32-vs2.3.3.9/include/linux/types.h        2012-05-21 16:15:05.000000000 +0000
8865 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8866  typedef __kernel_gid32_t       gid_t;
8867  typedef __kernel_uid16_t        uid16_t;
8868  typedef __kernel_gid16_t        gid16_t;
8869 +typedef unsigned int           xid_t;
8870 +typedef unsigned int           nid_t;
8871 +typedef unsigned int           tag_t;
8872  
8873  typedef unsigned long          uintptr_t;
8874  
8875 diff -NurpP --minimal linux-3.4.32/include/linux/utsname.h linux-3.4.32-vs2.3.3.9/include/linux/utsname.h
8876 --- linux-3.4.32/include/linux/utsname.h        2012-01-09 15:14:59.000000000 +0000
8877 +++ linux-3.4.32-vs2.3.3.9/include/linux/utsname.h      2012-05-21 16:15:05.000000000 +0000
8878 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8879  }
8880  
8881  extern struct uts_namespace *copy_utsname(unsigned long flags,
8882 -                                         struct task_struct *tsk);
8883 +                                         struct uts_namespace *old_ns,
8884 +                                         struct user_namespace *user_ns);
8885  extern void free_uts_ns(struct kref *kref);
8886  
8887  static inline void put_uts_ns(struct uts_namespace *ns)
8888 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8889  }
8890  
8891  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8892 -                                                struct task_struct *tsk)
8893 +                                                struct uts_namespace *old_ns,
8894 +                                                struct user_namespace *user_ns)
8895  {
8896         if (flags & CLONE_NEWUTS)
8897                 return ERR_PTR(-EINVAL);
8898  
8899 -       return tsk->nsproxy->uts_ns;
8900 +       return old_ns;
8901  }
8902  #endif
8903  
8904 diff -NurpP --minimal linux-3.4.32/include/linux/vroot.h linux-3.4.32-vs2.3.3.9/include/linux/vroot.h
8905 --- linux-3.4.32/include/linux/vroot.h  1970-01-01 00:00:00.000000000 +0000
8906 +++ linux-3.4.32-vs2.3.3.9/include/linux/vroot.h        2012-05-21 16:15:05.000000000 +0000
8907 @@ -0,0 +1,51 @@
8908 +
8909 +/*
8910 + * include/linux/vroot.h
8911 + *
8912 + * written by Herbert Pötzl, 9/11/2002
8913 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8914 + *
8915 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8916 + * Redistribution of this file is permitted under the
8917 + * GNU General Public License.
8918 + */
8919 +
8920 +#ifndef _LINUX_VROOT_H
8921 +#define _LINUX_VROOT_H
8922 +
8923 +
8924 +#ifdef __KERNEL__
8925 +
8926 +/* Possible states of device */
8927 +enum {
8928 +       Vr_unbound,
8929 +       Vr_bound,
8930 +};
8931 +
8932 +struct vroot_device {
8933 +       int             vr_number;
8934 +       int             vr_refcnt;
8935 +
8936 +       struct semaphore        vr_ctl_mutex;
8937 +       struct block_device    *vr_device;
8938 +       int                     vr_state;
8939 +};
8940 +
8941 +
8942 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8943 +
8944 +extern int register_vroot_grb(vroot_grb_func *);
8945 +extern int unregister_vroot_grb(vroot_grb_func *);
8946 +
8947 +#endif /* __KERNEL__ */
8948 +
8949 +#define MAX_VROOT_DEFAULT      8
8950 +
8951 +/*
8952 + * IOCTL commands --- we will commandeer 0x56 ('V')
8953 + */
8954 +
8955 +#define VROOT_SET_DEV          0x5600
8956 +#define VROOT_CLR_DEV          0x5601
8957 +
8958 +#endif /* _LINUX_VROOT_H */
8959 diff -NurpP --minimal linux-3.4.32/include/linux/vs_base.h linux-3.4.32-vs2.3.3.9/include/linux/vs_base.h
8960 --- linux-3.4.32/include/linux/vs_base.h        1970-01-01 00:00:00.000000000 +0000
8961 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_base.h      2012-05-21 16:15:05.000000000 +0000
8962 @@ -0,0 +1,10 @@
8963 +#ifndef _VS_BASE_H
8964 +#define _VS_BASE_H
8965 +
8966 +#include "vserver/base.h"
8967 +#include "vserver/check.h"
8968 +#include "vserver/debug.h"
8969 +
8970 +#else
8971 +#warning duplicate inclusion
8972 +#endif
8973 diff -NurpP --minimal linux-3.4.32/include/linux/vs_context.h linux-3.4.32-vs2.3.3.9/include/linux/vs_context.h
8974 --- linux-3.4.32/include/linux/vs_context.h     1970-01-01 00:00:00.000000000 +0000
8975 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_context.h   2012-05-21 16:15:05.000000000 +0000
8976 @@ -0,0 +1,242 @@
8977 +#ifndef _VS_CONTEXT_H
8978 +#define _VS_CONTEXT_H
8979 +
8980 +#include "vserver/base.h"
8981 +#include "vserver/check.h"
8982 +#include "vserver/context.h"
8983 +#include "vserver/history.h"
8984 +#include "vserver/debug.h"
8985 +
8986 +#include <linux/sched.h>
8987 +
8988 +
8989 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8990 +
8991 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8992 +       const char *_file, int _line, void *_here)
8993 +{
8994 +       if (!vxi)
8995 +               return NULL;
8996 +
8997 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8998 +               vxi, vxi ? vxi->vx_id : 0,
8999 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9000 +               _file, _line);
9001 +       __vxh_get_vx_info(vxi, _here);
9002 +
9003 +       atomic_inc(&vxi->vx_usecnt);
9004 +       return vxi;
9005 +}
9006 +
9007 +
9008 +extern void free_vx_info(struct vx_info *);
9009 +
9010 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9011 +
9012 +static inline void __put_vx_info(struct vx_info *vxi,
9013 +       const char *_file, int _line, void *_here)
9014 +{
9015 +       if (!vxi)
9016 +               return;
9017 +
9018 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9019 +               vxi, vxi ? vxi->vx_id : 0,
9020 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9021 +               _file, _line);
9022 +       __vxh_put_vx_info(vxi, _here);
9023 +
9024 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9025 +               free_vx_info(vxi);
9026 +}
9027 +
9028 +
9029 +#define init_vx_info(p, i) \
9030 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9031 +
9032 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9033 +       const char *_file, int _line, void *_here)
9034 +{
9035 +       if (vxi) {
9036 +               vxlprintk(VXD_CBIT(xid, 3),
9037 +                       "init_vx_info(%p[#%d.%d])",
9038 +                       vxi, vxi ? vxi->vx_id : 0,
9039 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9040 +                       _file, _line);
9041 +               __vxh_init_vx_info(vxi, vxp, _here);
9042 +
9043 +               atomic_inc(&vxi->vx_usecnt);
9044 +       }
9045 +       *vxp = vxi;
9046 +}
9047 +
9048 +
9049 +#define set_vx_info(p, i) \
9050 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9051 +
9052 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9053 +       const char *_file, int _line, void *_here)
9054 +{
9055 +       struct vx_info *vxo;
9056 +
9057 +       if (!vxi)
9058 +               return;
9059 +
9060 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9061 +               vxi, vxi ? vxi->vx_id : 0,
9062 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9063 +               _file, _line);
9064 +       __vxh_set_vx_info(vxi, vxp, _here);
9065 +
9066 +       atomic_inc(&vxi->vx_usecnt);
9067 +       vxo = xchg(vxp, vxi);
9068 +       BUG_ON(vxo);
9069 +}
9070 +
9071 +
9072 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9073 +
9074 +static inline void __clr_vx_info(struct vx_info **vxp,
9075 +       const char *_file, int _line, void *_here)
9076 +{
9077 +       struct vx_info *vxo;
9078 +
9079 +       vxo = xchg(vxp, NULL);
9080 +       if (!vxo)
9081 +               return;
9082 +
9083 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9084 +               vxo, vxo ? vxo->vx_id : 0,
9085 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9086 +               _file, _line);
9087 +       __vxh_clr_vx_info(vxo, vxp, _here);
9088 +
9089 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9090 +               free_vx_info(vxo);
9091 +}
9092 +
9093 +
9094 +#define claim_vx_info(v, p) \
9095 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9096 +
9097 +static inline void __claim_vx_info(struct vx_info *vxi,
9098 +       struct task_struct *task,
9099 +       const char *_file, int _line, void *_here)
9100 +{
9101 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9102 +               vxi, vxi ? vxi->vx_id : 0,
9103 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9104 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9105 +               task, _file, _line);
9106 +       __vxh_claim_vx_info(vxi, task, _here);
9107 +
9108 +       atomic_inc(&vxi->vx_tasks);
9109 +}
9110 +
9111 +
9112 +extern void unhash_vx_info(struct vx_info *);
9113 +
9114 +#define release_vx_info(v, p) \
9115 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9116 +
9117 +static inline void __release_vx_info(struct vx_info *vxi,
9118 +       struct task_struct *task,
9119 +       const char *_file, int _line, void *_here)
9120 +{
9121 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9122 +               vxi, vxi ? vxi->vx_id : 0,
9123 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9124 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9125 +               task, _file, _line);
9126 +       __vxh_release_vx_info(vxi, task, _here);
9127 +
9128 +       might_sleep();
9129 +
9130 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9131 +               unhash_vx_info(vxi);
9132 +}
9133 +
9134 +
9135 +#define task_get_vx_info(p) \
9136 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9137 +
9138 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9139 +       const char *_file, int _line, void *_here)
9140 +{
9141 +       struct vx_info *vxi;
9142 +
9143 +       task_lock(p);
9144 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9145 +               p, _file, _line);
9146 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9147 +       task_unlock(p);
9148 +       return vxi;
9149 +}
9150 +
9151 +
9152 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9153 +{
9154 +       if (waitqueue_active(&vxi->vx_wait))
9155 +               wake_up_interruptible(&vxi->vx_wait);
9156 +}
9157 +
9158 +
9159 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9160 +
9161 +static inline void __enter_vx_info(struct vx_info *vxi,
9162 +       struct vx_info_save *vxis, const char *_file, int _line)
9163 +{
9164 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9165 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9166 +               current->xid, current->vx_info, _file, _line);
9167 +       vxis->vxi = xchg(&current->vx_info, vxi);
9168 +       vxis->xid = current->xid;
9169 +       current->xid = vxi ? vxi->vx_id : 0;
9170 +}
9171 +
9172 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9173 +
9174 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9175 +       const char *_file, int _line)
9176 +{
9177 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9178 +               vxis, vxis->xid, vxis->vxi, current,
9179 +               current->xid, current->vx_info, _file, _line);
9180 +       (void)xchg(&current->vx_info, vxis->vxi);
9181 +       current->xid = vxis->xid;
9182 +}
9183 +
9184 +
9185 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9186 +{
9187 +       vxis->vxi = xchg(&current->vx_info, NULL);
9188 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9189 +}
9190 +
9191 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9192 +{
9193 +       (void)xchg(&current->xid, vxis->xid);
9194 +       (void)xchg(&current->vx_info, vxis->vxi);
9195 +}
9196 +
9197 +#define task_is_init(p) \
9198 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9199 +
9200 +static inline int __task_is_init(struct task_struct *p,
9201 +       const char *_file, int _line, void *_here)
9202 +{
9203 +       int is_init = is_global_init(p);
9204 +
9205 +       task_lock(p);
9206 +       if (p->vx_info)
9207 +               is_init = p->vx_info->vx_initpid == p->pid;
9208 +       task_unlock(p);
9209 +       return is_init;
9210 +}
9211 +
9212 +extern void exit_vx_info(struct task_struct *, int);
9213 +extern void exit_vx_info_early(struct task_struct *, int);
9214 +
9215 +
9216 +#else
9217 +#warning duplicate inclusion
9218 +#endif
9219 diff -NurpP --minimal linux-3.4.32/include/linux/vs_cowbl.h linux-3.4.32-vs2.3.3.9/include/linux/vs_cowbl.h
9220 --- linux-3.4.32/include/linux/vs_cowbl.h       1970-01-01 00:00:00.000000000 +0000
9221 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_cowbl.h     2012-05-21 16:15:05.000000000 +0000
9222 @@ -0,0 +1,48 @@
9223 +#ifndef _VS_COWBL_H
9224 +#define _VS_COWBL_H
9225 +
9226 +#include <linux/fs.h>
9227 +#include <linux/dcache.h>
9228 +#include <linux/namei.h>
9229 +#include <linux/slab.h>
9230 +
9231 +extern struct dentry *cow_break_link(const char *pathname);
9232 +
9233 +static inline int cow_check_and_break(struct path *path)
9234 +{
9235 +       struct inode *inode = path->dentry->d_inode;
9236 +       int error = 0;
9237 +
9238 +       /* do we need this check? */
9239 +       if (IS_RDONLY(inode))
9240 +               return -EROFS;
9241 +
9242 +       if (IS_COW(inode)) {
9243 +               if (IS_COW_LINK(inode)) {
9244 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9245 +                       char *pp, *buf;
9246 +
9247 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9248 +                       if (!buf) {
9249 +                               return -ENOMEM;
9250 +                       }
9251 +                       pp = d_path(path, buf, PATH_MAX);
9252 +                       new_dentry = cow_break_link(pp);
9253 +                       kfree(buf);
9254 +                       if (!IS_ERR(new_dentry)) {
9255 +                               path->dentry = new_dentry;
9256 +                               dput(old_dentry);
9257 +                       } else
9258 +                               error = PTR_ERR(new_dentry);
9259 +               } else {
9260 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9261 +                       inode->i_ctime = CURRENT_TIME;
9262 +                       mark_inode_dirty(inode);
9263 +               }
9264 +       }
9265 +       return error;
9266 +}
9267 +
9268 +#else
9269 +#warning duplicate inclusion
9270 +#endif
9271 diff -NurpP --minimal linux-3.4.32/include/linux/vs_cvirt.h linux-3.4.32-vs2.3.3.9/include/linux/vs_cvirt.h
9272 --- linux-3.4.32/include/linux/vs_cvirt.h       1970-01-01 00:00:00.000000000 +0000
9273 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_cvirt.h     2012-05-21 16:15:05.000000000 +0000
9274 @@ -0,0 +1,50 @@
9275 +#ifndef _VS_CVIRT_H
9276 +#define _VS_CVIRT_H
9277 +
9278 +#include "vserver/cvirt.h"
9279 +#include "vserver/context.h"
9280 +#include "vserver/base.h"
9281 +#include "vserver/check.h"
9282 +#include "vserver/debug.h"
9283 +
9284 +
9285 +static inline void vx_activate_task(struct task_struct *p)
9286 +{
9287 +       struct vx_info *vxi;
9288 +
9289 +       if ((vxi = p->vx_info)) {
9290 +               vx_update_load(vxi);
9291 +               atomic_inc(&vxi->cvirt.nr_running);
9292 +       }
9293 +}
9294 +
9295 +static inline void vx_deactivate_task(struct task_struct *p)
9296 +{
9297 +       struct vx_info *vxi;
9298 +
9299 +       if ((vxi = p->vx_info)) {
9300 +               vx_update_load(vxi);
9301 +               atomic_dec(&vxi->cvirt.nr_running);
9302 +       }
9303 +}
9304 +
9305 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9306 +{
9307 +       struct vx_info *vxi;
9308 +
9309 +       if ((vxi = p->vx_info))
9310 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9311 +}
9312 +
9313 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9314 +{
9315 +       struct vx_info *vxi;
9316 +
9317 +       if ((vxi = p->vx_info))
9318 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9319 +}
9320 +
9321 +
9322 +#else
9323 +#warning duplicate inclusion
9324 +#endif
9325 diff -NurpP --minimal linux-3.4.32/include/linux/vs_device.h linux-3.4.32-vs2.3.3.9/include/linux/vs_device.h
9326 --- linux-3.4.32/include/linux/vs_device.h      1970-01-01 00:00:00.000000000 +0000
9327 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_device.h    2012-05-21 16:15:05.000000000 +0000
9328 @@ -0,0 +1,45 @@
9329 +#ifndef _VS_DEVICE_H
9330 +#define _VS_DEVICE_H
9331 +
9332 +#include "vserver/base.h"
9333 +#include "vserver/device.h"
9334 +#include "vserver/debug.h"
9335 +
9336 +
9337 +#ifdef CONFIG_VSERVER_DEVICE
9338 +
9339 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9340 +
9341 +#define vs_device_perm(v, d, m, p) \
9342 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9343 +
9344 +#else
9345 +
9346 +static inline
9347 +int vs_map_device(struct vx_info *vxi,
9348 +       dev_t device, dev_t *target, umode_t mode)
9349 +{
9350 +       if (target)
9351 +               *target = device;
9352 +       return ~0;
9353 +}
9354 +
9355 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9356 +
9357 +#endif
9358 +
9359 +
9360 +#define vs_map_chrdev(d, t, p) \
9361 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9362 +#define vs_map_blkdev(d, t, p) \
9363 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9364 +
9365 +#define vs_chrdev_perm(d, p) \
9366 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9367 +#define vs_blkdev_perm(d, p) \
9368 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9369 +
9370 +
9371 +#else
9372 +#warning duplicate inclusion
9373 +#endif
9374 diff -NurpP --minimal linux-3.4.32/include/linux/vs_dlimit.h linux-3.4.32-vs2.3.3.9/include/linux/vs_dlimit.h
9375 --- linux-3.4.32/include/linux/vs_dlimit.h      1970-01-01 00:00:00.000000000 +0000
9376 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_dlimit.h    2012-05-21 16:15:05.000000000 +0000
9377 @@ -0,0 +1,215 @@
9378 +#ifndef _VS_DLIMIT_H
9379 +#define _VS_DLIMIT_H
9380 +
9381 +#include <linux/fs.h>
9382 +
9383 +#include "vserver/dlimit.h"
9384 +#include "vserver/base.h"
9385 +#include "vserver/debug.h"
9386 +
9387 +
9388 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9389 +
9390 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9391 +       const char *_file, int _line)
9392 +{
9393 +       if (!dli)
9394 +               return NULL;
9395 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9396 +               dli, dli ? dli->dl_tag : 0,
9397 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9398 +               _file, _line);
9399 +       atomic_inc(&dli->dl_usecnt);
9400 +       return dli;
9401 +}
9402 +
9403 +
9404 +#define free_dl_info(i) \
9405 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9406 +
9407 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9408 +
9409 +static inline void __put_dl_info(struct dl_info *dli,
9410 +       const char *_file, int _line)
9411 +{
9412 +       if (!dli)
9413 +               return;
9414 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9415 +               dli, dli ? dli->dl_tag : 0,
9416 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9417 +               _file, _line);
9418 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9419 +               free_dl_info(dli);
9420 +}
9421 +
9422 +
9423 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9424 +
9425 +static inline int __dl_alloc_space(struct super_block *sb,
9426 +       tag_t tag, dlsize_t nr, const char *file, int line)
9427 +{
9428 +       struct dl_info *dli = NULL;
9429 +       int ret = 0;
9430 +
9431 +       if (nr == 0)
9432 +               goto out;
9433 +       dli = locate_dl_info(sb, tag);
9434 +       if (!dli)
9435 +               goto out;
9436 +
9437 +       spin_lock(&dli->dl_lock);
9438 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9439 +       if (!ret)
9440 +               dli->dl_space_used += nr;
9441 +       spin_unlock(&dli->dl_lock);
9442 +       put_dl_info(dli);
9443 +out:
9444 +       vxlprintk(VXD_CBIT(dlim, 1),
9445 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9446 +               sb, tag, __dlimit_char(dli), (long long)nr,
9447 +               ret, file, line);
9448 +       return ret ? -ENOSPC : 0;
9449 +}
9450 +
9451 +static inline void __dl_free_space(struct super_block *sb,
9452 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9453 +{
9454 +       struct dl_info *dli = NULL;
9455 +
9456 +       if (nr == 0)
9457 +               goto out;
9458 +       dli = locate_dl_info(sb, tag);
9459 +       if (!dli)
9460 +               goto out;
9461 +
9462 +       spin_lock(&dli->dl_lock);
9463 +       if (dli->dl_space_used > nr)
9464 +               dli->dl_space_used -= nr;
9465 +       else
9466 +               dli->dl_space_used = 0;
9467 +       spin_unlock(&dli->dl_lock);
9468 +       put_dl_info(dli);
9469 +out:
9470 +       vxlprintk(VXD_CBIT(dlim, 1),
9471 +               "FREE  (%p,#%d)%c %lld bytes",
9472 +               sb, tag, __dlimit_char(dli), (long long)nr,
9473 +               _file, _line);
9474 +}
9475 +
9476 +static inline int __dl_alloc_inode(struct super_block *sb,
9477 +       tag_t tag, const char *_file, int _line)
9478 +{
9479 +       struct dl_info *dli;
9480 +       int ret = 0;
9481 +
9482 +       dli = locate_dl_info(sb, tag);
9483 +       if (!dli)
9484 +               goto out;
9485 +
9486 +       spin_lock(&dli->dl_lock);
9487 +       dli->dl_inodes_used++;
9488 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9489 +       spin_unlock(&dli->dl_lock);
9490 +       put_dl_info(dli);
9491 +out:
9492 +       vxlprintk(VXD_CBIT(dlim, 0),
9493 +               "ALLOC (%p,#%d)%c inode (%d)",
9494 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9495 +       return ret ? -ENOSPC : 0;
9496 +}
9497 +
9498 +static inline void __dl_free_inode(struct super_block *sb,
9499 +       tag_t tag, const char *_file, int _line)
9500 +{
9501 +       struct dl_info *dli;
9502 +
9503 +       dli = locate_dl_info(sb, tag);
9504 +       if (!dli)
9505 +               goto out;
9506 +
9507 +       spin_lock(&dli->dl_lock);
9508 +       if (dli->dl_inodes_used > 1)
9509 +               dli->dl_inodes_used--;
9510 +       else
9511 +               dli->dl_inodes_used = 0;
9512 +       spin_unlock(&dli->dl_lock);
9513 +       put_dl_info(dli);
9514 +out:
9515 +       vxlprintk(VXD_CBIT(dlim, 0),
9516 +               "FREE  (%p,#%d)%c inode",
9517 +               sb, tag, __dlimit_char(dli), _file, _line);
9518 +}
9519 +
9520 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9521 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9522 +       const char *_file, int _line)
9523 +{
9524 +       struct dl_info *dli;
9525 +       uint64_t broot, bfree;
9526 +
9527 +       dli = locate_dl_info(sb, tag);
9528 +       if (!dli)
9529 +               return;
9530 +
9531 +       spin_lock(&dli->dl_lock);
9532 +       broot = (dli->dl_space_total -
9533 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9534 +               >> sb->s_blocksize_bits;
9535 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9536 +                       >> sb->s_blocksize_bits;
9537 +       spin_unlock(&dli->dl_lock);
9538 +
9539 +       vxlprintk(VXD_CBIT(dlim, 2),
9540 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9541 +               (long long)bfree, (long long)broot,
9542 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9543 +               _file, _line);
9544 +       if (free_blocks) {
9545 +               if (*free_blocks > bfree)
9546 +                       *free_blocks = bfree;
9547 +       }
9548 +       if (root_blocks) {
9549 +               if (*root_blocks > broot)
9550 +                       *root_blocks = broot;
9551 +       }
9552 +       put_dl_info(dli);
9553 +}
9554 +
9555 +#define dl_prealloc_space(in, bytes) \
9556 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9557 +               __FILE__, __LINE__ )
9558 +
9559 +#define dl_alloc_space(in, bytes) \
9560 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9561 +               __FILE__, __LINE__ )
9562 +
9563 +#define dl_reserve_space(in, bytes) \
9564 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9565 +               __FILE__, __LINE__ )
9566 +
9567 +#define dl_claim_space(in, bytes) (0)
9568 +
9569 +#define dl_release_space(in, bytes) \
9570 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9571 +               __FILE__, __LINE__ )
9572 +
9573 +#define dl_free_space(in, bytes) \
9574 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9575 +               __FILE__, __LINE__ )
9576 +
9577 +
9578 +
9579 +#define dl_alloc_inode(in) \
9580 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9581 +
9582 +#define dl_free_inode(in) \
9583 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9584 +
9585 +
9586 +#define dl_adjust_block(sb, tag, fb, rb) \
9587 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9588 +
9589 +
9590 +#else
9591 +#warning duplicate inclusion
9592 +#endif
9593 diff -NurpP --minimal linux-3.4.32/include/linux/vs_inet.h linux-3.4.32-vs2.3.3.9/include/linux/vs_inet.h
9594 --- linux-3.4.32/include/linux/vs_inet.h        1970-01-01 00:00:00.000000000 +0000
9595 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_inet.h      2012-05-21 16:15:05.000000000 +0000
9596 @@ -0,0 +1,353 @@
9597 +#ifndef _VS_INET_H
9598 +#define _VS_INET_H
9599 +
9600 +#include "vserver/base.h"
9601 +#include "vserver/network.h"
9602 +#include "vserver/debug.h"
9603 +
9604 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9605 +
9606 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9607 +                       NIPQUAD((a)->mask), (a)->type
9608 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9609 +
9610 +#define NIPQUAD(addr) \
9611 +       ((unsigned char *)&addr)[0], \
9612 +       ((unsigned char *)&addr)[1], \
9613 +       ((unsigned char *)&addr)[2], \
9614 +       ((unsigned char *)&addr)[3]
9615 +
9616 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9617 +
9618 +
9619 +static inline
9620 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9621 +{
9622 +       __be32 ip = nxa->ip[0].s_addr;
9623 +       __be32 mask = nxa->mask.s_addr;
9624 +       __be32 bcast = ip | ~mask;
9625 +       int ret = 0;
9626 +
9627 +       switch (nxa->type & tmask) {
9628 +       case NXA_TYPE_MASK:
9629 +               ret = (ip == (addr & mask));
9630 +               break;
9631 +       case NXA_TYPE_ADDR:
9632 +               ret = 3;
9633 +               if (addr == ip)
9634 +                       break;
9635 +               /* fall through to broadcast */
9636 +       case NXA_MOD_BCAST:
9637 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9638 +               break;
9639 +       case NXA_TYPE_RANGE:
9640 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9641 +                       (nxa->ip[1].s_addr > addr));
9642 +               break;
9643 +       case NXA_TYPE_ANY:
9644 +               ret = 2;
9645 +               break;
9646 +       }
9647 +
9648 +       vxdprintk(VXD_CBIT(net, 0),
9649 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9650 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9651 +       return ret;
9652 +}
9653 +
9654 +static inline
9655 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9656 +{
9657 +       struct nx_addr_v4 *nxa;
9658 +       int ret = 1;
9659 +
9660 +       if (!nxi)
9661 +               goto out;
9662 +
9663 +       ret = 2;
9664 +       /* allow 127.0.0.1 when remapping lback */
9665 +       if ((tmask & NXA_LOOPBACK) &&
9666 +               (addr == IPI_LOOPBACK) &&
9667 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9668 +               goto out;
9669 +       ret = 3;
9670 +       /* check for lback address */
9671 +       if ((tmask & NXA_MOD_LBACK) &&
9672 +               (nxi->v4_lback.s_addr == addr))
9673 +               goto out;
9674 +       ret = 4;
9675 +       /* check for broadcast address */
9676 +       if ((tmask & NXA_MOD_BCAST) &&
9677 +               (nxi->v4_bcast.s_addr == addr))
9678 +               goto out;
9679 +       ret = 5;
9680 +       /* check for v4 addresses */
9681 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9682 +               if (v4_addr_match(nxa, addr, tmask))
9683 +                       goto out;
9684 +       ret = 0;
9685 +out:
9686 +       vxdprintk(VXD_CBIT(net, 0),
9687 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9688 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9689 +       return ret;
9690 +}
9691 +
9692 +static inline
9693 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9694 +{
9695 +       /* FIXME: needs full range checks */
9696 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9697 +}
9698 +
9699 +static inline
9700 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9701 +{
9702 +       struct nx_addr_v4 *ptr;
9703 +
9704 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9705 +               if (v4_nx_addr_match(ptr, nxa, mask))
9706 +                       return 1;
9707 +       return 0;
9708 +}
9709 +
9710 +#include <net/inet_sock.h>
9711 +
9712 +/*
9713 + *     Check if a given address matches for a socket
9714 + *
9715 + *     nxi:            the socket's nx_info if any
9716 + *     addr:           to be verified address
9717 + */
9718 +static inline
9719 +int v4_sock_addr_match (
9720 +       struct nx_info *nxi,
9721 +       struct inet_sock *inet,
9722 +       __be32 addr)
9723 +{
9724 +       __be32 saddr = inet->inet_rcv_saddr;
9725 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9726 +
9727 +       if (addr && (saddr == addr || bcast == addr))
9728 +               return 1;
9729 +       if (!saddr)
9730 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9731 +       return 0;
9732 +}
9733 +
9734 +
9735 +/* inet related checks and helpers */
9736 +
9737 +
9738 +struct in_ifaddr;
9739 +struct net_device;
9740 +struct sock;
9741 +
9742 +#ifdef CONFIG_INET
9743 +
9744 +#include <linux/netdevice.h>
9745 +#include <linux/inetdevice.h>
9746 +#include <net/inet_sock.h>
9747 +#include <net/inet_timewait_sock.h>
9748 +
9749 +
9750 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9751 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9752 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9753 +
9754 +
9755 +/*
9756 + *     check if address is covered by socket
9757 + *
9758 + *     sk:     the socket to check against
9759 + *     addr:   the address in question (must be != 0)
9760 + */
9761 +
9762 +static inline
9763 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9764 +{
9765 +       struct nx_info *nxi = sk->sk_nx_info;
9766 +       __be32 saddr = sk_rcv_saddr(sk);
9767 +
9768 +       vxdprintk(VXD_CBIT(net, 5),
9769 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9770 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9771 +               (sk->sk_socket?sk->sk_socket->flags:0));
9772 +
9773 +       if (saddr) {            /* direct address match */
9774 +               return v4_addr_match(nxa, saddr, -1);
9775 +       } else if (nxi) {       /* match against nx_info */
9776 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9777 +       } else {                /* unrestricted any socket */
9778 +               return 1;
9779 +       }
9780 +}
9781 +
9782 +
9783 +
9784 +static inline
9785 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9786 +{
9787 +       vxdprintk(VXD_CBIT(net, 1),
9788 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9789 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9790 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9791 +
9792 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9793 +               return 1;
9794 +       if (dev_in_nx_info(dev, nxi))
9795 +               return 1;
9796 +       return 0;
9797 +}
9798 +
9799 +
9800 +static inline
9801 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9802 +{
9803 +       if (!nxi)
9804 +               return 1;
9805 +       if (!ifa)
9806 +               return 0;
9807 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9808 +}
9809 +
9810 +static inline
9811 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9812 +{
9813 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9814 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9815 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9816 +
9817 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9818 +               return 1;
9819 +       if (v4_ifa_in_nx_info(ifa, nxi))
9820 +               return 1;
9821 +       return 0;
9822 +}
9823 +
9824 +
9825 +struct nx_v4_sock_addr {
9826 +       __be32 saddr;   /* Address used for validation */
9827 +       __be32 baddr;   /* Address used for socket bind */
9828 +};
9829 +
9830 +static inline
9831 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9832 +       struct nx_v4_sock_addr *nsa)
9833 +{
9834 +       struct sock *sk = &inet->sk;
9835 +       struct nx_info *nxi = sk->sk_nx_info;
9836 +       __be32 saddr = addr->sin_addr.s_addr;
9837 +       __be32 baddr = saddr;
9838 +
9839 +       vxdprintk(VXD_CBIT(net, 3),
9840 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9841 +               sk, sk->sk_nx_info, sk->sk_socket,
9842 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9843 +               NIPQUAD(saddr));
9844 +
9845 +       if (nxi) {
9846 +               if (saddr == INADDR_ANY) {
9847 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9848 +                               baddr = nxi->v4.ip[0].s_addr;
9849 +               } else if (saddr == IPI_LOOPBACK) {
9850 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9851 +                               baddr = nxi->v4_lback.s_addr;
9852 +               } else if (!ipv4_is_multicast(saddr) ||
9853 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9854 +                       /* normal address bind */
9855 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9856 +                               return -EADDRNOTAVAIL;
9857 +               }
9858 +       }
9859 +
9860 +       vxdprintk(VXD_CBIT(net, 3),
9861 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9862 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9863 +
9864 +       nsa->saddr = saddr;
9865 +       nsa->baddr = baddr;
9866 +       return 0;
9867 +}
9868 +
9869 +static inline
9870 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9871 +{
9872 +       inet->inet_saddr = nsa->baddr;
9873 +       inet->inet_rcv_saddr = nsa->baddr;
9874 +}
9875 +
9876 +
9877 +/*
9878 + *      helper to simplify inet_lookup_listener
9879 + *
9880 + *      nxi:   the socket's nx_info if any
9881 + *      addr:  to be verified address
9882 + *      saddr: socket address
9883 + */
9884 +static inline int v4_inet_addr_match (
9885 +       struct nx_info *nxi,
9886 +       __be32 addr,
9887 +       __be32 saddr)
9888 +{
9889 +       if (addr && (saddr == addr))
9890 +               return 1;
9891 +       if (!saddr)
9892 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9893 +       return 0;
9894 +}
9895 +
9896 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9897 +{
9898 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9899 +               (addr == nxi->v4_lback.s_addr))
9900 +               return IPI_LOOPBACK;
9901 +       return addr;
9902 +}
9903 +
9904 +static inline
9905 +int nx_info_has_v4(struct nx_info *nxi)
9906 +{
9907 +       if (!nxi)
9908 +               return 1;
9909 +       if (NX_IPV4(nxi))
9910 +               return 1;
9911 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9912 +               return 1;
9913 +       return 0;
9914 +}
9915 +
9916 +#else /* CONFIG_INET */
9917 +
9918 +static inline
9919 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9920 +{
9921 +       return 1;
9922 +}
9923 +
9924 +static inline
9925 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9926 +{
9927 +       return 1;
9928 +}
9929 +
9930 +static inline
9931 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9932 +{
9933 +       return 1;
9934 +}
9935 +
9936 +static inline
9937 +int nx_info_has_v4(struct nx_info *nxi)
9938 +{
9939 +       return 0;
9940 +}
9941 +
9942 +#endif /* CONFIG_INET */
9943 +
9944 +#define current_nx_info_has_v4() \
9945 +       nx_info_has_v4(current_nx_info())
9946 +
9947 +#else
9948 +// #warning duplicate inclusion
9949 +#endif
9950 diff -NurpP --minimal linux-3.4.32/include/linux/vs_inet6.h linux-3.4.32-vs2.3.3.9/include/linux/vs_inet6.h
9951 --- linux-3.4.32/include/linux/vs_inet6.h       1970-01-01 00:00:00.000000000 +0000
9952 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_inet6.h     2012-05-21 16:15:05.000000000 +0000
9953 @@ -0,0 +1,246 @@
9954 +#ifndef _VS_INET6_H
9955 +#define _VS_INET6_H
9956 +
9957 +#include "vserver/base.h"
9958 +#include "vserver/network.h"
9959 +#include "vserver/debug.h"
9960 +
9961 +#include <net/ipv6.h>
9962 +
9963 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9964 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9965 +
9966 +
9967 +#ifdef CONFIG_IPV6
9968 +
9969 +static inline
9970 +int v6_addr_match(struct nx_addr_v6 *nxa,
9971 +       const struct in6_addr *addr, uint16_t mask)
9972 +{
9973 +       int ret = 0;
9974 +
9975 +       switch (nxa->type & mask) {
9976 +       case NXA_TYPE_MASK:
9977 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9978 +               break;
9979 +       case NXA_TYPE_ADDR:
9980 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9981 +               break;
9982 +       case NXA_TYPE_ANY:
9983 +               ret = 1;
9984 +               break;
9985 +       }
9986 +       vxdprintk(VXD_CBIT(net, 0),
9987 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9988 +               nxa, NXAV6(nxa), addr, mask, ret);
9989 +       return ret;
9990 +}
9991 +
9992 +static inline
9993 +int v6_addr_in_nx_info(struct nx_info *nxi,
9994 +       const struct in6_addr *addr, uint16_t mask)
9995 +{
9996 +       struct nx_addr_v6 *nxa;
9997 +       int ret = 1;
9998 +
9999 +       if (!nxi)
10000 +               goto out;
10001 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10002 +               if (v6_addr_match(nxa, addr, mask))
10003 +                       goto out;
10004 +       ret = 0;
10005 +out:
10006 +       vxdprintk(VXD_CBIT(net, 0),
10007 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10008 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10009 +       return ret;
10010 +}
10011 +
10012 +static inline
10013 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10014 +{
10015 +       /* FIXME: needs full range checks */
10016 +       return v6_addr_match(nxa, &addr->ip, mask);
10017 +}
10018 +
10019 +static inline
10020 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10021 +{
10022 +       struct nx_addr_v6 *ptr;
10023 +
10024 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10025 +               if (v6_nx_addr_match(ptr, nxa, mask))
10026 +                       return 1;
10027 +       return 0;
10028 +}
10029 +
10030 +
10031 +/*
10032 + *     Check if a given address matches for a socket
10033 + *
10034 + *     nxi:            the socket's nx_info if any
10035 + *     addr:           to be verified address
10036 + */
10037 +static inline
10038 +int v6_sock_addr_match (
10039 +       struct nx_info *nxi,
10040 +       struct inet_sock *inet,
10041 +       struct in6_addr *addr)
10042 +{
10043 +       struct sock *sk = &inet->sk;
10044 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10045 +
10046 +       if (!ipv6_addr_any(addr) &&
10047 +               ipv6_addr_equal(saddr, addr))
10048 +               return 1;
10049 +       if (ipv6_addr_any(saddr))
10050 +               return v6_addr_in_nx_info(nxi, addr, -1);
10051 +       return 0;
10052 +}
10053 +
10054 +/*
10055 + *     check if address is covered by socket
10056 + *
10057 + *     sk:     the socket to check against
10058 + *     addr:   the address in question (must be != 0)
10059 + */
10060 +
10061 +static inline
10062 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10063 +{
10064 +       struct nx_info *nxi = sk->sk_nx_info;
10065 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10066 +
10067 +       vxdprintk(VXD_CBIT(net, 5),
10068 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10069 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10070 +               (sk->sk_socket?sk->sk_socket->flags:0));
10071 +
10072 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10073 +               return v6_addr_match(nxa, saddr, -1);
10074 +       } else if (nxi) {               /* match against nx_info */
10075 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10076 +       } else {                        /* unrestricted any socket */
10077 +               return 1;
10078 +       }
10079 +}
10080 +
10081 +
10082 +/* inet related checks and helpers */
10083 +
10084 +
10085 +struct in_ifaddr;
10086 +struct net_device;
10087 +struct sock;
10088 +
10089 +
10090 +#include <linux/netdevice.h>
10091 +#include <linux/inetdevice.h>
10092 +#include <net/inet_timewait_sock.h>
10093 +
10094 +
10095 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10096 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10097 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10098 +
10099 +
10100 +
10101 +static inline
10102 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10103 +{
10104 +       if (!nxi)
10105 +               return 1;
10106 +       if (!ifa)
10107 +               return 0;
10108 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10109 +}
10110 +
10111 +static inline
10112 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10113 +{
10114 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10115 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10116 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10117 +
10118 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10119 +               return 1;
10120 +       if (v6_ifa_in_nx_info(ifa, nxi))
10121 +               return 1;
10122 +       return 0;
10123 +}
10124 +
10125 +
10126 +struct nx_v6_sock_addr {
10127 +       struct in6_addr saddr;  /* Address used for validation */
10128 +       struct in6_addr baddr;  /* Address used for socket bind */
10129 +};
10130 +
10131 +static inline
10132 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10133 +       struct nx_v6_sock_addr *nsa)
10134 +{
10135 +       // struct sock *sk = &inet->sk;
10136 +       // struct nx_info *nxi = sk->sk_nx_info;
10137 +       struct in6_addr saddr = addr->sin6_addr;
10138 +       struct in6_addr baddr = saddr;
10139 +
10140 +       nsa->saddr = saddr;
10141 +       nsa->baddr = baddr;
10142 +       return 0;
10143 +}
10144 +
10145 +static inline
10146 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10147 +{
10148 +       // struct sock *sk = &inet->sk;
10149 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10150 +
10151 +       // *saddr = nsa->baddr;
10152 +       // inet->inet_saddr = nsa->baddr;
10153 +}
10154 +
10155 +static inline
10156 +int nx_info_has_v6(struct nx_info *nxi)
10157 +{
10158 +       if (!nxi)
10159 +               return 1;
10160 +       if (NX_IPV6(nxi))
10161 +               return 1;
10162 +       return 0;
10163 +}
10164 +
10165 +#else /* CONFIG_IPV6 */
10166 +
10167 +static inline
10168 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10169 +{
10170 +       return 1;
10171 +}
10172 +
10173 +
10174 +static inline
10175 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10176 +{
10177 +       return 1;
10178 +}
10179 +
10180 +static inline
10181 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10182 +{
10183 +       return 1;
10184 +}
10185 +
10186 +static inline
10187 +int nx_info_has_v6(struct nx_info *nxi)
10188 +{
10189 +       return 0;
10190 +}
10191 +
10192 +#endif /* CONFIG_IPV6 */
10193 +
10194 +#define current_nx_info_has_v6() \
10195 +       nx_info_has_v6(current_nx_info())
10196 +
10197 +#else
10198 +#warning duplicate inclusion
10199 +#endif
10200 diff -NurpP --minimal linux-3.4.32/include/linux/vs_limit.h linux-3.4.32-vs2.3.3.9/include/linux/vs_limit.h
10201 --- linux-3.4.32/include/linux/vs_limit.h       1970-01-01 00:00:00.000000000 +0000
10202 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_limit.h     2012-05-21 16:15:05.000000000 +0000
10203 @@ -0,0 +1,140 @@
10204 +#ifndef _VS_LIMIT_H
10205 +#define _VS_LIMIT_H
10206 +
10207 +#include "vserver/limit.h"
10208 +#include "vserver/base.h"
10209 +#include "vserver/context.h"
10210 +#include "vserver/debug.h"
10211 +#include "vserver/context.h"
10212 +#include "vserver/limit_int.h"
10213 +
10214 +
10215 +#define vx_acc_cres(v, d, p, r) \
10216 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10217 +
10218 +#define vx_acc_cres_cond(x, d, p, r) \
10219 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10220 +       r, d, p, __FILE__, __LINE__)
10221 +
10222 +
10223 +#define vx_add_cres(v, a, p, r) \
10224 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10225 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10226 +
10227 +#define vx_add_cres_cond(x, a, p, r) \
10228 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10229 +       r, a, p, __FILE__, __LINE__)
10230 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10231 +
10232 +
10233 +/* process and file limits */
10234 +
10235 +#define vx_nproc_inc(p) \
10236 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10237 +
10238 +#define vx_nproc_dec(p) \
10239 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10240 +
10241 +#define vx_files_inc(f) \
10242 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10243 +
10244 +#define vx_files_dec(f) \
10245 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10246 +
10247 +#define vx_locks_inc(l) \
10248 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10249 +
10250 +#define vx_locks_dec(l) \
10251 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10252 +
10253 +#define vx_openfd_inc(f) \
10254 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10255 +
10256 +#define vx_openfd_dec(f) \
10257 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10258 +
10259 +
10260 +#define vx_cres_avail(v, n, r) \
10261 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10262 +
10263 +
10264 +#define vx_nproc_avail(n) \
10265 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10266 +
10267 +#define vx_files_avail(n) \
10268 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10269 +
10270 +#define vx_locks_avail(n) \
10271 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10272 +
10273 +#define vx_openfd_avail(n) \
10274 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10275 +
10276 +
10277 +/* dentry limits */
10278 +
10279 +#define vx_dentry_inc(d) do {                                          \
10280 +       if ((d)->d_count == 1)                                          \
10281 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10282 +       } while (0)
10283 +
10284 +#define vx_dentry_dec(d) do {                                          \
10285 +       if ((d)->d_count == 0)                                          \
10286 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10287 +       } while (0)
10288 +
10289 +#define vx_dentry_avail(n) \
10290 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10291 +
10292 +
10293 +/* socket limits */
10294 +
10295 +#define vx_sock_inc(s) \
10296 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10297 +
10298 +#define vx_sock_dec(s) \
10299 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10300 +
10301 +#define vx_sock_avail(n) \
10302 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10303 +
10304 +
10305 +/* ipc resource limits */
10306 +
10307 +#define vx_ipcmsg_add(v, u, a) \
10308 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10309 +
10310 +#define vx_ipcmsg_sub(v, u, a) \
10311 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10312 +
10313 +#define vx_ipcmsg_avail(v, a) \
10314 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10315 +
10316 +
10317 +#define vx_ipcshm_add(v, k, a) \
10318 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10319 +
10320 +#define vx_ipcshm_sub(v, k, a) \
10321 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10322 +
10323 +#define vx_ipcshm_avail(v, a) \
10324 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10325 +
10326 +
10327 +#define vx_semary_inc(a) \
10328 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10329 +
10330 +#define vx_semary_dec(a) \
10331 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10332 +
10333 +
10334 +#define vx_nsems_add(a,n) \
10335 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10336 +
10337 +#define vx_nsems_sub(a,n) \
10338 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10339 +
10340 +
10341 +#else
10342 +#warning duplicate inclusion
10343 +#endif
10344 diff -NurpP --minimal linux-3.4.32/include/linux/vs_network.h linux-3.4.32-vs2.3.3.9/include/linux/vs_network.h
10345 --- linux-3.4.32/include/linux/vs_network.h     1970-01-01 00:00:00.000000000 +0000
10346 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_network.h   2012-05-21 16:15:05.000000000 +0000
10347 @@ -0,0 +1,169 @@
10348 +#ifndef _NX_VS_NETWORK_H
10349 +#define _NX_VS_NETWORK_H
10350 +
10351 +#include "vserver/context.h"
10352 +#include "vserver/network.h"
10353 +#include "vserver/base.h"
10354 +#include "vserver/check.h"
10355 +#include "vserver/debug.h"
10356 +
10357 +#include <linux/sched.h>
10358 +
10359 +
10360 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10361 +
10362 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10363 +       const char *_file, int _line)
10364 +{
10365 +       if (!nxi)
10366 +               return NULL;
10367 +
10368 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10369 +               nxi, nxi ? nxi->nx_id : 0,
10370 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10371 +               _file, _line);
10372 +
10373 +       atomic_inc(&nxi->nx_usecnt);
10374 +       return nxi;
10375 +}
10376 +
10377 +
10378 +extern void free_nx_info(struct nx_info *);
10379 +
10380 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10381 +
10382 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10383 +{
10384 +       if (!nxi)
10385 +               return;
10386 +
10387 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10388 +               nxi, nxi ? nxi->nx_id : 0,
10389 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10390 +               _file, _line);
10391 +
10392 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10393 +               free_nx_info(nxi);
10394 +}
10395 +
10396 +
10397 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10398 +
10399 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10400 +               const char *_file, int _line)
10401 +{
10402 +       if (nxi) {
10403 +               vxlprintk(VXD_CBIT(nid, 3),
10404 +                       "init_nx_info(%p[#%d.%d])",
10405 +                       nxi, nxi ? nxi->nx_id : 0,
10406 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10407 +                       _file, _line);
10408 +
10409 +               atomic_inc(&nxi->nx_usecnt);
10410 +       }
10411 +       *nxp = nxi;
10412 +}
10413 +
10414 +
10415 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10416 +
10417 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10418 +       const char *_file, int _line)
10419 +{
10420 +       struct nx_info *nxo;
10421 +
10422 +       if (!nxi)
10423 +               return;
10424 +
10425 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10426 +               nxi, nxi ? nxi->nx_id : 0,
10427 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10428 +               _file, _line);
10429 +
10430 +       atomic_inc(&nxi->nx_usecnt);
10431 +       nxo = xchg(nxp, nxi);
10432 +       BUG_ON(nxo);
10433 +}
10434 +
10435 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10436 +
10437 +static inline void __clr_nx_info(struct nx_info **nxp,
10438 +       const char *_file, int _line)
10439 +{
10440 +       struct nx_info *nxo;
10441 +
10442 +       nxo = xchg(nxp, NULL);
10443 +       if (!nxo)
10444 +               return;
10445 +
10446 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10447 +               nxo, nxo ? nxo->nx_id : 0,
10448 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10449 +               _file, _line);
10450 +
10451 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10452 +               free_nx_info(nxo);
10453 +}
10454 +
10455 +
10456 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10457 +
10458 +static inline void __claim_nx_info(struct nx_info *nxi,
10459 +       struct task_struct *task, const char *_file, int _line)
10460 +{
10461 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10462 +               nxi, nxi ? nxi->nx_id : 0,
10463 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10464 +               nxi?atomic_read(&nxi->nx_tasks):0,
10465 +               task, _file, _line);
10466 +
10467 +       atomic_inc(&nxi->nx_tasks);
10468 +}
10469 +
10470 +
10471 +extern void unhash_nx_info(struct nx_info *);
10472 +
10473 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10474 +
10475 +static inline void __release_nx_info(struct nx_info *nxi,
10476 +       struct task_struct *task, const char *_file, int _line)
10477 +{
10478 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10479 +               nxi, nxi ? nxi->nx_id : 0,
10480 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10481 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10482 +               task, _file, _line);
10483 +
10484 +       might_sleep();
10485 +
10486 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10487 +               unhash_nx_info(nxi);
10488 +}
10489 +
10490 +
10491 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10492 +
10493 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10494 +       const char *_file, int _line)
10495 +{
10496 +       struct nx_info *nxi;
10497 +
10498 +       task_lock(p);
10499 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10500 +               p, _file, _line);
10501 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10502 +       task_unlock(p);
10503 +       return nxi;
10504 +}
10505 +
10506 +
10507 +static inline void exit_nx_info(struct task_struct *p)
10508 +{
10509 +       if (p->nx_info)
10510 +               release_nx_info(p->nx_info, p);
10511 +}
10512 +
10513 +
10514 +#else
10515 +#warning duplicate inclusion
10516 +#endif
10517 diff -NurpP --minimal linux-3.4.32/include/linux/vs_pid.h linux-3.4.32-vs2.3.3.9/include/linux/vs_pid.h
10518 --- linux-3.4.32/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
10519 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_pid.h       2012-05-21 16:15:05.000000000 +0000
10520 @@ -0,0 +1,50 @@
10521 +#ifndef _VS_PID_H
10522 +#define _VS_PID_H
10523 +
10524 +#include "vserver/base.h"
10525 +#include "vserver/check.h"
10526 +#include "vserver/context.h"
10527 +#include "vserver/debug.h"
10528 +#include "vserver/pid.h"
10529 +#include <linux/pid_namespace.h>
10530 +
10531 +
10532 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10533 +
10534 +static inline
10535 +int vx_proc_task_visible(struct task_struct *task)
10536 +{
10537 +       if ((task->pid == 1) &&
10538 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10539 +               /* show a blend through init */
10540 +               goto visible;
10541 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10542 +               goto visible;
10543 +       return 0;
10544 +visible:
10545 +       return 1;
10546 +}
10547 +
10548 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10549 +
10550 +
10551 +static inline
10552 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10553 +{
10554 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10555 +
10556 +       if (task && !vx_proc_task_visible(task)) {
10557 +               vxdprintk(VXD_CBIT(misc, 6),
10558 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10559 +                       task, task->xid, task->pid,
10560 +                       current, current->xid, current->pid);
10561 +               put_task_struct(task);
10562 +               task = NULL;
10563 +       }
10564 +       return task;
10565 +}
10566 +
10567 +
10568 +#else
10569 +#warning duplicate inclusion
10570 +#endif
10571 diff -NurpP --minimal linux-3.4.32/include/linux/vs_sched.h linux-3.4.32-vs2.3.3.9/include/linux/vs_sched.h
10572 --- linux-3.4.32/include/linux/vs_sched.h       1970-01-01 00:00:00.000000000 +0000
10573 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_sched.h     2012-05-21 16:15:05.000000000 +0000
10574 @@ -0,0 +1,40 @@
10575 +#ifndef _VS_SCHED_H
10576 +#define _VS_SCHED_H
10577 +
10578 +#include "vserver/base.h"
10579 +#include "vserver/context.h"
10580 +#include "vserver/sched.h"
10581 +
10582 +
10583 +#define MAX_PRIO_BIAS           20
10584 +#define MIN_PRIO_BIAS          -20
10585 +
10586 +static inline
10587 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10588 +{
10589 +       struct vx_info *vxi = p->vx_info;
10590 +
10591 +       if (vxi)
10592 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10593 +       return prio;
10594 +}
10595 +
10596 +static inline void vx_account_user(struct vx_info *vxi,
10597 +       cputime_t cputime, int nice)
10598 +{
10599 +       if (!vxi)
10600 +               return;
10601 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10602 +}
10603 +
10604 +static inline void vx_account_system(struct vx_info *vxi,
10605 +       cputime_t cputime, int idle)
10606 +{
10607 +       if (!vxi)
10608 +               return;
10609 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10610 +}
10611 +
10612 +#else
10613 +#warning duplicate inclusion
10614 +#endif
10615 diff -NurpP --minimal linux-3.4.32/include/linux/vs_socket.h linux-3.4.32-vs2.3.3.9/include/linux/vs_socket.h
10616 --- linux-3.4.32/include/linux/vs_socket.h      1970-01-01 00:00:00.000000000 +0000
10617 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_socket.h    2012-05-21 16:15:05.000000000 +0000
10618 @@ -0,0 +1,67 @@
10619 +#ifndef _VS_SOCKET_H
10620 +#define _VS_SOCKET_H
10621 +
10622 +#include "vserver/debug.h"
10623 +#include "vserver/base.h"
10624 +#include "vserver/cacct.h"
10625 +#include "vserver/context.h"
10626 +#include "vserver/tag.h"
10627 +
10628 +
10629 +/* socket accounting */
10630 +
10631 +#include <linux/socket.h>
10632 +
10633 +static inline int vx_sock_type(int family)
10634 +{
10635 +       switch (family) {
10636 +       case PF_UNSPEC:
10637 +               return VXA_SOCK_UNSPEC;
10638 +       case PF_UNIX:
10639 +               return VXA_SOCK_UNIX;
10640 +       case PF_INET:
10641 +               return VXA_SOCK_INET;
10642 +       case PF_INET6:
10643 +               return VXA_SOCK_INET6;
10644 +       case PF_PACKET:
10645 +               return VXA_SOCK_PACKET;
10646 +       default:
10647 +               return VXA_SOCK_OTHER;
10648 +       }
10649 +}
10650 +
10651 +#define vx_acc_sock(v, f, p, s) \
10652 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10653 +
10654 +static inline void __vx_acc_sock(struct vx_info *vxi,
10655 +       int family, int pos, int size, char *file, int line)
10656 +{
10657 +       if (vxi) {
10658 +               int type = vx_sock_type(family);
10659 +
10660 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10661 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10662 +       }
10663 +}
10664 +
10665 +#define vx_sock_recv(sk, s) \
10666 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10667 +#define vx_sock_send(sk, s) \
10668 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10669 +#define vx_sock_fail(sk, s) \
10670 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10671 +
10672 +
10673 +#define sock_vx_init(s) do {           \
10674 +       (s)->sk_xid = 0;                \
10675 +       (s)->sk_vx_info = NULL;         \
10676 +       } while (0)
10677 +
10678 +#define sock_nx_init(s) do {           \
10679 +       (s)->sk_nid = 0;                \
10680 +       (s)->sk_nx_info = NULL;         \
10681 +       } while (0)
10682 +
10683 +#else
10684 +#warning duplicate inclusion
10685 +#endif
10686 diff -NurpP --minimal linux-3.4.32/include/linux/vs_tag.h linux-3.4.32-vs2.3.3.9/include/linux/vs_tag.h
10687 --- linux-3.4.32/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
10688 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_tag.h       2012-05-21 16:15:05.000000000 +0000
10689 @@ -0,0 +1,47 @@
10690 +#ifndef _VS_TAG_H
10691 +#define _VS_TAG_H
10692 +
10693 +#include <linux/vserver/tag.h>
10694 +
10695 +/* check conditions */
10696 +
10697 +#define DX_ADMIN       0x0001
10698 +#define DX_WATCH       0x0002
10699 +#define DX_HOSTID      0x0008
10700 +
10701 +#define DX_IDENT       0x0010
10702 +
10703 +#define DX_ARG_MASK    0x0010
10704 +
10705 +
10706 +#define dx_task_tag(t) ((t)->tag)
10707 +
10708 +#define dx_current_tag() dx_task_tag(current)
10709 +
10710 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10711 +
10712 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10713 +
10714 +
10715 +/*
10716 + * check current context for ADMIN/WATCH and
10717 + * optionally against supplied argument
10718 + */
10719 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10720 +{
10721 +       if (mode & DX_ARG_MASK) {
10722 +               if ((mode & DX_IDENT) && (id == cid))
10723 +                       return 1;
10724 +       }
10725 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10726 +               ((mode & DX_WATCH) && (cid == 1)) ||
10727 +               ((mode & DX_HOSTID) && (id == 0)));
10728 +}
10729 +
10730 +struct inode;
10731 +int dx_permission(const struct inode *inode, int mask);
10732 +
10733 +
10734 +#else
10735 +#warning duplicate inclusion
10736 +#endif
10737 diff -NurpP --minimal linux-3.4.32/include/linux/vs_time.h linux-3.4.32-vs2.3.3.9/include/linux/vs_time.h
10738 --- linux-3.4.32/include/linux/vs_time.h        1970-01-01 00:00:00.000000000 +0000
10739 +++ linux-3.4.32-vs2.3.3.9/include/linux/vs_time.h      2012-05-21 16:15:05.000000000 +0000
10740 @@ -0,0 +1,19 @@
10741 +#ifndef _VS_TIME_H
10742 +#define _VS_TIME_H
10743 +
10744 +
10745 +/* time faking stuff */
10746 +
10747 +#ifdef CONFIG_VSERVER_VTIME
10748 +
10749 +extern void vx_adjust_timespec(struct timespec *ts);
10750 +extern int vx_settimeofday(const struct timespec *ts);
10751 +
10752 +#else
10753 +#define        vx_adjust_timespec(t)   do { } while (0)
10754 +#define        vx_settimeofday(t)      do_settimeofday(t)
10755 +#endif
10756 +
10757 +#else
10758 +#warning duplicate inclusion
10759 +#endif
10760 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/Kbuild linux-3.4.32-vs2.3.3.9/include/linux/vserver/Kbuild
10761 --- linux-3.4.32/include/linux/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
10762 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/Kbuild 2012-05-21 16:15:05.000000000 +0000
10763 @@ -0,0 +1,8 @@
10764 +
10765 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10766 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10767 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10768 +       debug_cmd.h device_cmd.h
10769 +
10770 +header-y += switch.h network.h monitor.h inode.h device.h
10771 +
10772 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/base.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/base.h
10773 --- linux-3.4.32/include/linux/vserver/base.h   1970-01-01 00:00:00.000000000 +0000
10774 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/base.h 2012-05-21 16:15:05.000000000 +0000
10775 @@ -0,0 +1,178 @@
10776 +#ifndef _VX_BASE_H
10777 +#define _VX_BASE_H
10778 +
10779 +
10780 +/* context state changes */
10781 +
10782 +enum {
10783 +       VSC_STARTUP = 1,
10784 +       VSC_SHUTDOWN,
10785 +
10786 +       VSC_NETUP,
10787 +       VSC_NETDOWN,
10788 +};
10789 +
10790 +
10791 +
10792 +#define vx_task_xid(t) ((t)->xid)
10793 +
10794 +#define vx_current_xid() vx_task_xid(current)
10795 +
10796 +#define current_vx_info() (current->vx_info)
10797 +
10798 +
10799 +#define nx_task_nid(t) ((t)->nid)
10800 +
10801 +#define nx_current_nid() nx_task_nid(current)
10802 +
10803 +#define current_nx_info() (current->nx_info)
10804 +
10805 +
10806 +/* generic flag merging */
10807 +
10808 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10809 +
10810 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10811 +
10812 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10813 +
10814 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10815 +
10816 +
10817 +/* context flags */
10818 +
10819 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10820 +
10821 +#define vx_current_flags()     __vx_flags(current_vx_info())
10822 +
10823 +#define vx_info_flags(v, m, f) \
10824 +       vs_check_flags(__vx_flags(v), m, f)
10825 +
10826 +#define task_vx_flags(t, m, f) \
10827 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10828 +
10829 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10830 +
10831 +
10832 +/* context caps */
10833 +
10834 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10835 +
10836 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10837 +
10838 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10839 +
10840 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10841 +
10842 +
10843 +
10844 +/* network flags */
10845 +
10846 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10847 +
10848 +#define nx_current_flags()     __nx_flags(current_nx_info())
10849 +
10850 +#define nx_info_flags(n, m, f) \
10851 +       vs_check_flags(__nx_flags(n), m, f)
10852 +
10853 +#define task_nx_flags(t, m, f) \
10854 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10855 +
10856 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10857 +
10858 +
10859 +/* network caps */
10860 +
10861 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10862 +
10863 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10864 +
10865 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10866 +
10867 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10868 +
10869 +
10870 +/* context mask capabilities */
10871 +
10872 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10873 +
10874 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10875 +
10876 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10877 +
10878 +
10879 +/* context bcap mask */
10880 +
10881 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10882 +
10883 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10884 +
10885 +
10886 +/* mask given bcaps */
10887 +
10888 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10889 +
10890 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10891 +
10892 +
10893 +/* masked cap_bset */
10894 +
10895 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10896 +
10897 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10898 +
10899 +#if 0
10900 +#define vx_info_mbcap(v, b) \
10901 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10902 +       vx_info_bcaps(v, b) : (b))
10903 +
10904 +#define task_vx_mbcap(t, b) \
10905 +       vx_info_mbcap((t)->vx_info, (t)->b)
10906 +
10907 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10908 +#endif
10909 +
10910 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10911 +
10912 +#define vx_capable(b, c) (capable(b) || \
10913 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10914 +
10915 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10916 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10917 +
10918 +#define nx_capable(b, c) (capable(b) || \
10919 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10920 +
10921 +#define vx_task_initpid(t, n) \
10922 +       ((t)->vx_info && \
10923 +       ((t)->vx_info->vx_initpid == (n)))
10924 +
10925 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10926 +
10927 +
10928 +/* context unshare mask */
10929 +
10930 +#define __vx_umask(v)          ((v)->vx_umask)
10931 +
10932 +#define vx_current_umask()     __vx_umask(current_vx_info())
10933 +
10934 +#define vx_can_unshare(b, f) (capable(b) || \
10935 +       (cap_raised(current_cap(), b) && \
10936 +       !((f) & ~vx_current_umask())))
10937 +
10938 +
10939 +#define __vx_wmask(v)          ((v)->vx_wmask)
10940 +
10941 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10942 +
10943 +
10944 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10945 +
10946 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10947 +
10948 +
10949 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10950 +
10951 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10952 +
10953 +#endif
10954 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cacct.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct.h
10955 --- linux-3.4.32/include/linux/vserver/cacct.h  1970-01-01 00:00:00.000000000 +0000
10956 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct.h        2012-05-21 16:15:05.000000000 +0000
10957 @@ -0,0 +1,15 @@
10958 +#ifndef _VX_CACCT_H
10959 +#define _VX_CACCT_H
10960 +
10961 +
10962 +enum sock_acc_field {
10963 +       VXA_SOCK_UNSPEC = 0,
10964 +       VXA_SOCK_UNIX,
10965 +       VXA_SOCK_INET,
10966 +       VXA_SOCK_INET6,
10967 +       VXA_SOCK_PACKET,
10968 +       VXA_SOCK_OTHER,
10969 +       VXA_SOCK_SIZE   /* array size */
10970 +};
10971 +
10972 +#endif /* _VX_CACCT_H */
10973 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cacct_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct_cmd.h
10974 --- linux-3.4.32/include/linux/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
10975 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct_cmd.h    2012-05-21 16:15:05.000000000 +0000
10976 @@ -0,0 +1,23 @@
10977 +#ifndef _VX_CACCT_CMD_H
10978 +#define _VX_CACCT_CMD_H
10979 +
10980 +
10981 +/* virtual host info name commands */
10982 +
10983 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10984 +
10985 +struct vcmd_sock_stat_v0 {
10986 +       uint32_t field;
10987 +       uint32_t count[3];
10988 +       uint64_t total[3];
10989 +};
10990 +
10991 +
10992 +#ifdef __KERNEL__
10993 +
10994 +#include <linux/compiler.h>
10995 +
10996 +extern int vc_sock_stat(struct vx_info *, void __user *);
10997 +
10998 +#endif /* __KERNEL__ */
10999 +#endif /* _VX_CACCT_CMD_H */
11000 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cacct_def.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct_def.h
11001 --- linux-3.4.32/include/linux/vserver/cacct_def.h      1970-01-01 00:00:00.000000000 +0000
11002 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct_def.h    2012-05-21 16:15:05.000000000 +0000
11003 @@ -0,0 +1,43 @@
11004 +#ifndef _VX_CACCT_DEF_H
11005 +#define _VX_CACCT_DEF_H
11006 +
11007 +#include <asm/atomic.h>
11008 +#include <linux/vserver/cacct.h>
11009 +
11010 +
11011 +struct _vx_sock_acc {
11012 +       atomic_long_t count;
11013 +       atomic_long_t total;
11014 +};
11015 +
11016 +/* context sub struct */
11017 +
11018 +struct _vx_cacct {
11019 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11020 +       atomic_t slab[8];
11021 +       atomic_t page[6][8];
11022 +};
11023 +
11024 +#ifdef CONFIG_VSERVER_DEBUG
11025 +
11026 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11027 +{
11028 +       int i, j;
11029 +
11030 +       printk("\t_vx_cacct:");
11031 +       for (i = 0; i < 6; i++) {
11032 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11033 +
11034 +               printk("\t [%d] =", i);
11035 +               for (j = 0; j < 3; j++) {
11036 +                       printk(" [%d] = %8lu, %8lu", j,
11037 +                               atomic_long_read(&ptr[j].count),
11038 +                               atomic_long_read(&ptr[j].total));
11039 +               }
11040 +               printk("\n");
11041 +       }
11042 +}
11043 +
11044 +#endif
11045 +
11046 +#endif /* _VX_CACCT_DEF_H */
11047 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cacct_int.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct_int.h
11048 --- linux-3.4.32/include/linux/vserver/cacct_int.h      1970-01-01 00:00:00.000000000 +0000
11049 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cacct_int.h    2012-05-21 16:15:05.000000000 +0000
11050 @@ -0,0 +1,21 @@
11051 +#ifndef _VX_CACCT_INT_H
11052 +#define _VX_CACCT_INT_H
11053 +
11054 +
11055 +#ifdef __KERNEL__
11056 +
11057 +static inline
11058 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11059 +{
11060 +       return atomic_long_read(&cacct->sock[type][pos].count);
11061 +}
11062 +
11063 +
11064 +static inline
11065 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11066 +{
11067 +       return atomic_long_read(&cacct->sock[type][pos].total);
11068 +}
11069 +
11070 +#endif /* __KERNEL__ */
11071 +#endif /* _VX_CACCT_INT_H */
11072 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/check.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/check.h
11073 --- linux-3.4.32/include/linux/vserver/check.h  1970-01-01 00:00:00.000000000 +0000
11074 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/check.h        2012-05-21 16:15:05.000000000 +0000
11075 @@ -0,0 +1,89 @@
11076 +#ifndef _VS_CHECK_H
11077 +#define _VS_CHECK_H
11078 +
11079 +
11080 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11081 +
11082 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11083 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11084 +#else
11085 +#define MIN_D_CONTEXT  65536
11086 +#endif
11087 +
11088 +/* check conditions */
11089 +
11090 +#define VS_ADMIN       0x0001
11091 +#define VS_WATCH       0x0002
11092 +#define VS_HIDE                0x0004
11093 +#define VS_HOSTID      0x0008
11094 +
11095 +#define VS_IDENT       0x0010
11096 +#define VS_EQUIV       0x0020
11097 +#define VS_PARENT      0x0040
11098 +#define VS_CHILD       0x0080
11099 +
11100 +#define VS_ARG_MASK    0x00F0
11101 +
11102 +#define VS_DYNAMIC     0x0100
11103 +#define VS_STATIC      0x0200
11104 +
11105 +#define VS_ATR_MASK    0x0F00
11106 +
11107 +#ifdef CONFIG_VSERVER_PRIVACY
11108 +#define VS_ADMIN_P     (0)
11109 +#define VS_WATCH_P     (0)
11110 +#else
11111 +#define VS_ADMIN_P     VS_ADMIN
11112 +#define VS_WATCH_P     VS_WATCH
11113 +#endif
11114 +
11115 +#define VS_HARDIRQ     0x1000
11116 +#define VS_SOFTIRQ     0x2000
11117 +#define VS_IRQ         0x4000
11118 +
11119 +#define VS_IRQ_MASK    0xF000
11120 +
11121 +#include <linux/hardirq.h>
11122 +
11123 +/*
11124 + * check current context for ADMIN/WATCH and
11125 + * optionally against supplied argument
11126 + */
11127 +static inline int __vs_check(int cid, int id, unsigned int mode)
11128 +{
11129 +       if (mode & VS_ARG_MASK) {
11130 +               if ((mode & VS_IDENT) && (id == cid))
11131 +                       return 1;
11132 +       }
11133 +       if (mode & VS_ATR_MASK) {
11134 +               if ((mode & VS_DYNAMIC) &&
11135 +                       (id >= MIN_D_CONTEXT) &&
11136 +                       (id <= MAX_S_CONTEXT))
11137 +                       return 1;
11138 +               if ((mode & VS_STATIC) &&
11139 +                       (id > 1) && (id < MIN_D_CONTEXT))
11140 +                       return 1;
11141 +       }
11142 +       if (mode & VS_IRQ_MASK) {
11143 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11144 +                       return 1;
11145 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11146 +                       return 1;
11147 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11148 +                       return 1;
11149 +       }
11150 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11151 +               ((mode & VS_WATCH) && (cid == 1)) ||
11152 +               ((mode & VS_HOSTID) && (id == 0)));
11153 +}
11154 +
11155 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11156 +
11157 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11158 +
11159 +
11160 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11161 +
11162 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11163 +
11164 +#endif
11165 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/context.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/context.h
11166 --- linux-3.4.32/include/linux/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11167 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/context.h      2012-05-21 16:15:05.000000000 +0000
11168 @@ -0,0 +1,188 @@
11169 +#ifndef _VX_CONTEXT_H
11170 +#define _VX_CONTEXT_H
11171 +
11172 +#include <linux/types.h>
11173 +#include <linux/capability.h>
11174 +
11175 +
11176 +/* context flags */
11177 +
11178 +#define VXF_INFO_SCHED         0x00000002
11179 +#define VXF_INFO_NPROC         0x00000004
11180 +#define VXF_INFO_PRIVATE       0x00000008
11181 +
11182 +#define VXF_INFO_INIT          0x00000010
11183 +#define VXF_INFO_HIDE          0x00000020
11184 +#define VXF_INFO_ULIMIT                0x00000040
11185 +#define VXF_INFO_NSPACE                0x00000080
11186 +
11187 +#define VXF_SCHED_HARD         0x00000100
11188 +#define VXF_SCHED_PRIO         0x00000200
11189 +#define VXF_SCHED_PAUSE                0x00000400
11190 +
11191 +#define VXF_VIRT_MEM           0x00010000
11192 +#define VXF_VIRT_UPTIME                0x00020000
11193 +#define VXF_VIRT_CPU           0x00040000
11194 +#define VXF_VIRT_LOAD          0x00080000
11195 +#define VXF_VIRT_TIME          0x00100000
11196 +
11197 +#define VXF_HIDE_MOUNT         0x01000000
11198 +/* was VXF_HIDE_NETIF          0x02000000 */
11199 +#define VXF_HIDE_VINFO         0x04000000
11200 +
11201 +#define VXF_STATE_SETUP                (1ULL << 32)
11202 +#define VXF_STATE_INIT         (1ULL << 33)
11203 +#define VXF_STATE_ADMIN                (1ULL << 34)
11204 +
11205 +#define VXF_SC_HELPER          (1ULL << 36)
11206 +#define VXF_REBOOT_KILL                (1ULL << 37)
11207 +#define VXF_PERSISTENT         (1ULL << 38)
11208 +
11209 +#define VXF_FORK_RSS           (1ULL << 48)
11210 +#define VXF_PROLIFIC           (1ULL << 49)
11211 +
11212 +#define VXF_IGNEG_NICE         (1ULL << 52)
11213 +
11214 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11215 +
11216 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11217 +
11218 +
11219 +/* context migration */
11220 +
11221 +#define VXM_SET_INIT           0x00000001
11222 +#define VXM_SET_REAPER         0x00000002
11223 +
11224 +/* context caps */
11225 +
11226 +#define VXC_SET_UTSNAME                0x00000001
11227 +#define VXC_SET_RLIMIT         0x00000002
11228 +#define VXC_FS_SECURITY                0x00000004
11229 +#define VXC_FS_TRUSTED         0x00000008
11230 +#define VXC_TIOCSTI            0x00000010
11231 +
11232 +/* was VXC_RAW_ICMP            0x00000100 */
11233 +#define VXC_SYSLOG             0x00001000
11234 +#define VXC_OOM_ADJUST         0x00002000
11235 +#define VXC_AUDIT_CONTROL      0x00004000
11236 +
11237 +#define VXC_SECURE_MOUNT       0x00010000
11238 +#define VXC_SECURE_REMOUNT     0x00020000
11239 +#define VXC_BINARY_MOUNT       0x00040000
11240 +
11241 +#define VXC_QUOTA_CTL          0x00100000
11242 +#define VXC_ADMIN_MAPPER       0x00200000
11243 +#define VXC_ADMIN_CLOOP                0x00400000
11244 +
11245 +#define VXC_KTHREAD            0x01000000
11246 +#define VXC_NAMESPACE          0x02000000
11247 +
11248 +
11249 +#ifdef __KERNEL__
11250 +
11251 +#include <linux/list.h>
11252 +#include <linux/spinlock.h>
11253 +#include <linux/rcupdate.h>
11254 +
11255 +#include "limit_def.h"
11256 +#include "sched_def.h"
11257 +#include "cvirt_def.h"
11258 +#include "cacct_def.h"
11259 +#include "device_def.h"
11260 +
11261 +#define VX_SPACES      2
11262 +
11263 +struct _vx_info_pc {
11264 +       struct _vx_sched_pc sched_pc;
11265 +       struct _vx_cvirt_pc cvirt_pc;
11266 +};
11267 +
11268 +struct _vx_space {
11269 +       unsigned long vx_nsmask;                /* assignment mask */
11270 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11271 +       struct fs_struct *vx_fs;                /* private namespace fs */
11272 +       const struct cred *vx_cred;             /* task credentials */
11273 +};
11274 +
11275 +struct vx_info {
11276 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11277 +       xid_t vx_id;                            /* context id */
11278 +       atomic_t vx_usecnt;                     /* usage count */
11279 +       atomic_t vx_tasks;                      /* tasks count */
11280 +       struct vx_info *vx_parent;              /* parent context */
11281 +       int vx_state;                           /* context state */
11282 +
11283 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11284 +
11285 +       uint64_t vx_flags;                      /* context flags */
11286 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11287 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11288 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11289 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11290 +
11291 +       struct task_struct *vx_reaper;          /* guest reaper process */
11292 +       pid_t vx_initpid;                       /* PID of guest init */
11293 +       int64_t vx_badness_bias;                /* OOM points bias */
11294 +
11295 +       struct _vx_limit limit;                 /* vserver limits */
11296 +       struct _vx_sched sched;                 /* vserver scheduler */
11297 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11298 +       struct _vx_cacct cacct;                 /* context accounting */
11299 +
11300 +       struct _vx_device dmap;                 /* default device map targets */
11301 +
11302 +#ifndef CONFIG_SMP
11303 +       struct _vx_info_pc info_pc;             /* per cpu data */
11304 +#else
11305 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11306 +#endif
11307 +
11308 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11309 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11310 +       int exit_code;                          /* last process exit code */
11311 +
11312 +       char vx_name[65];                       /* vserver name */
11313 +};
11314 +
11315 +#ifndef CONFIG_SMP
11316 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11317 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11318 +#else
11319 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11320 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11321 +#endif
11322 +
11323 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11324 +
11325 +
11326 +struct vx_info_save {
11327 +       struct vx_info *vxi;
11328 +       xid_t xid;
11329 +};
11330 +
11331 +
11332 +/* status flags */
11333 +
11334 +#define VXS_HASHED     0x0001
11335 +#define VXS_PAUSED     0x0010
11336 +#define VXS_SHUTDOWN   0x0100
11337 +#define VXS_HELPER     0x1000
11338 +#define VXS_RELEASED   0x8000
11339 +
11340 +
11341 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11342 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11343 +
11344 +extern struct vx_info *lookup_vx_info(int);
11345 +extern struct vx_info *lookup_or_create_vx_info(int);
11346 +
11347 +extern int get_xid_list(int, unsigned int *, int);
11348 +extern int xid_is_hashed(xid_t);
11349 +
11350 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11351 +
11352 +extern long vs_state_change(struct vx_info *, unsigned int);
11353 +
11354 +
11355 +#endif /* __KERNEL__ */
11356 +#endif /* _VX_CONTEXT_H */
11357 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/context_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/context_cmd.h
11358 --- linux-3.4.32/include/linux/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
11359 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/context_cmd.h  2012-05-21 16:15:05.000000000 +0000
11360 @@ -0,0 +1,162 @@
11361 +#ifndef _VX_CONTEXT_CMD_H
11362 +#define _VX_CONTEXT_CMD_H
11363 +
11364 +
11365 +/* vinfo commands */
11366 +
11367 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11368 +
11369 +#ifdef __KERNEL__
11370 +extern int vc_task_xid(uint32_t);
11371 +
11372 +#endif /* __KERNEL__ */
11373 +
11374 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11375 +
11376 +struct vcmd_vx_info_v0 {
11377 +       uint32_t xid;
11378 +       uint32_t initpid;
11379 +       /* more to come */
11380 +};
11381 +
11382 +#ifdef __KERNEL__
11383 +extern int vc_vx_info(struct vx_info *, void __user *);
11384 +
11385 +#endif /* __KERNEL__ */
11386 +
11387 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11388 +
11389 +struct vcmd_ctx_stat_v0 {
11390 +       uint32_t usecnt;
11391 +       uint32_t tasks;
11392 +       /* more to come */
11393 +};
11394 +
11395 +#ifdef __KERNEL__
11396 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11397 +
11398 +#endif /* __KERNEL__ */
11399 +
11400 +/* context commands */
11401 +
11402 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11403 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11404 +
11405 +struct vcmd_ctx_create {
11406 +       uint64_t flagword;
11407 +};
11408 +
11409 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11410 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11411 +
11412 +struct vcmd_ctx_migrate {
11413 +       uint64_t flagword;
11414 +};
11415 +
11416 +#ifdef __KERNEL__
11417 +extern int vc_ctx_create(uint32_t, void __user *);
11418 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11419 +
11420 +#endif /* __KERNEL__ */
11421 +
11422 +
11423 +/* flag commands */
11424 +
11425 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11426 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11427 +
11428 +struct vcmd_ctx_flags_v0 {
11429 +       uint64_t flagword;
11430 +       uint64_t mask;
11431 +};
11432 +
11433 +#ifdef __KERNEL__
11434 +extern int vc_get_cflags(struct vx_info *, void __user *);
11435 +extern int vc_set_cflags(struct vx_info *, void __user *);
11436 +
11437 +#endif /* __KERNEL__ */
11438 +
11439 +
11440 +/* context caps commands */
11441 +
11442 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11443 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11444 +
11445 +struct vcmd_ctx_caps_v1 {
11446 +       uint64_t ccaps;
11447 +       uint64_t cmask;
11448 +};
11449 +
11450 +#ifdef __KERNEL__
11451 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11452 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11453 +
11454 +#endif /* __KERNEL__ */
11455 +
11456 +
11457 +/* bcaps commands */
11458 +
11459 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11460 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11461 +
11462 +struct vcmd_bcaps {
11463 +       uint64_t bcaps;
11464 +       uint64_t bmask;
11465 +};
11466 +
11467 +#ifdef __KERNEL__
11468 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11469 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11470 +
11471 +#endif /* __KERNEL__ */
11472 +
11473 +
11474 +/* umask commands */
11475 +
11476 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11477 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11478 +
11479 +struct vcmd_umask {
11480 +       uint64_t umask;
11481 +       uint64_t mask;
11482 +};
11483 +
11484 +#ifdef __KERNEL__
11485 +extern int vc_get_umask(struct vx_info *, void __user *);
11486 +extern int vc_set_umask(struct vx_info *, void __user *);
11487 +
11488 +#endif /* __KERNEL__ */
11489 +
11490 +
11491 +/* wmask commands */
11492 +
11493 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11494 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11495 +
11496 +struct vcmd_wmask {
11497 +       uint64_t wmask;
11498 +       uint64_t mask;
11499 +};
11500 +
11501 +#ifdef __KERNEL__
11502 +extern int vc_get_wmask(struct vx_info *, void __user *);
11503 +extern int vc_set_wmask(struct vx_info *, void __user *);
11504 +
11505 +#endif /* __KERNEL__ */
11506 +
11507 +
11508 +/* OOM badness */
11509 +
11510 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11511 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11512 +
11513 +struct vcmd_badness_v0 {
11514 +       int64_t bias;
11515 +};
11516 +
11517 +#ifdef __KERNEL__
11518 +extern int vc_get_badness(struct vx_info *, void __user *);
11519 +extern int vc_set_badness(struct vx_info *, void __user *);
11520 +
11521 +#endif /* __KERNEL__ */
11522 +#endif /* _VX_CONTEXT_CMD_H */
11523 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cvirt.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cvirt.h
11524 --- linux-3.4.32/include/linux/vserver/cvirt.h  1970-01-01 00:00:00.000000000 +0000
11525 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cvirt.h        2012-05-21 16:15:05.000000000 +0000
11526 @@ -0,0 +1,22 @@
11527 +#ifndef _VX_CVIRT_H
11528 +#define _VX_CVIRT_H
11529 +
11530 +
11531 +#ifdef __KERNEL__
11532 +
11533 +struct timespec;
11534 +
11535 +void vx_vsi_boottime(struct timespec *);
11536 +
11537 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11538 +
11539 +
11540 +struct vx_info;
11541 +
11542 +void vx_update_load(struct vx_info *);
11543 +
11544 +
11545 +int vx_do_syslog(int, char __user *, int);
11546 +
11547 +#endif /* __KERNEL__ */
11548 +#endif /* _VX_CVIRT_H */
11549 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cvirt_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cvirt_cmd.h
11550 --- linux-3.4.32/include/linux/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
11551 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cvirt_cmd.h    2012-05-21 16:15:05.000000000 +0000
11552 @@ -0,0 +1,53 @@
11553 +#ifndef _VX_CVIRT_CMD_H
11554 +#define _VX_CVIRT_CMD_H
11555 +
11556 +
11557 +/* virtual host info name commands */
11558 +
11559 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11560 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11561 +
11562 +struct vcmd_vhi_name_v0 {
11563 +       uint32_t field;
11564 +       char name[65];
11565 +};
11566 +
11567 +
11568 +enum vhi_name_field {
11569 +       VHIN_CONTEXT = 0,
11570 +       VHIN_SYSNAME,
11571 +       VHIN_NODENAME,
11572 +       VHIN_RELEASE,
11573 +       VHIN_VERSION,
11574 +       VHIN_MACHINE,
11575 +       VHIN_DOMAINNAME,
11576 +};
11577 +
11578 +
11579 +#ifdef __KERNEL__
11580 +
11581 +#include <linux/compiler.h>
11582 +
11583 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11584 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11585 +
11586 +#endif /* __KERNEL__ */
11587 +
11588 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11589 +
11590 +struct vcmd_virt_stat_v0 {
11591 +       uint64_t offset;
11592 +       uint64_t uptime;
11593 +       uint32_t nr_threads;
11594 +       uint32_t nr_running;
11595 +       uint32_t nr_uninterruptible;
11596 +       uint32_t nr_onhold;
11597 +       uint32_t nr_forks;
11598 +       uint32_t load[3];
11599 +};
11600 +
11601 +#ifdef __KERNEL__
11602 +extern int vc_virt_stat(struct vx_info *, void __user *);
11603 +
11604 +#endif /* __KERNEL__ */
11605 +#endif /* _VX_CVIRT_CMD_H */
11606 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/cvirt_def.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/cvirt_def.h
11607 --- linux-3.4.32/include/linux/vserver/cvirt_def.h      1970-01-01 00:00:00.000000000 +0000
11608 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/cvirt_def.h    2012-05-21 16:15:05.000000000 +0000
11609 @@ -0,0 +1,80 @@
11610 +#ifndef _VX_CVIRT_DEF_H
11611 +#define _VX_CVIRT_DEF_H
11612 +
11613 +#include <linux/jiffies.h>
11614 +#include <linux/spinlock.h>
11615 +#include <linux/wait.h>
11616 +#include <linux/time.h>
11617 +#include <asm/atomic.h>
11618 +
11619 +
11620 +struct _vx_usage_stat {
11621 +       uint64_t user;
11622 +       uint64_t nice;
11623 +       uint64_t system;
11624 +       uint64_t softirq;
11625 +       uint64_t irq;
11626 +       uint64_t idle;
11627 +       uint64_t iowait;
11628 +};
11629 +
11630 +struct _vx_syslog {
11631 +       wait_queue_head_t log_wait;
11632 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11633 +
11634 +       unsigned long log_start;        /* next char to be read by syslog() */
11635 +       unsigned long con_start;        /* next char to be sent to consoles */
11636 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11637 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11638 +
11639 +       char log_buf[1024];
11640 +};
11641 +
11642 +
11643 +/* context sub struct */
11644 +
11645 +struct _vx_cvirt {
11646 +       atomic_t nr_threads;            /* number of current threads */
11647 +       atomic_t nr_running;            /* number of running threads */
11648 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11649 +
11650 +       atomic_t nr_onhold;             /* processes on hold */
11651 +       uint32_t onhold_last;           /* jiffies when put on hold */
11652 +
11653 +       struct timespec bias_ts;        /* time offset to the host */
11654 +       struct timespec bias_idle;
11655 +       struct timespec bias_uptime;    /* context creation point */
11656 +       uint64_t bias_clock;            /* offset in clock_t */
11657 +
11658 +       spinlock_t load_lock;           /* lock for the load averages */
11659 +       atomic_t load_updates;          /* nr of load updates done so far */
11660 +       uint32_t load_last;             /* last time load was calculated */
11661 +       uint32_t load[3];               /* load averages 1,5,15 */
11662 +
11663 +       atomic_t total_forks;           /* number of forks so far */
11664 +
11665 +       struct _vx_syslog syslog;
11666 +};
11667 +
11668 +struct _vx_cvirt_pc {
11669 +       struct _vx_usage_stat cpustat;
11670 +};
11671 +
11672 +
11673 +#ifdef CONFIG_VSERVER_DEBUG
11674 +
11675 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11676 +{
11677 +       printk("\t_vx_cvirt:\n");
11678 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11679 +               atomic_read(&cvirt->nr_threads),
11680 +               atomic_read(&cvirt->nr_running),
11681 +               atomic_read(&cvirt->nr_uninterruptible),
11682 +               atomic_read(&cvirt->nr_onhold));
11683 +       /* add rest here */
11684 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11685 +}
11686 +
11687 +#endif
11688 +
11689 +#endif /* _VX_CVIRT_DEF_H */
11690 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/debug.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/debug.h
11691 --- linux-3.4.32/include/linux/vserver/debug.h  1970-01-01 00:00:00.000000000 +0000
11692 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/debug.h        2012-05-21 16:15:05.000000000 +0000
11693 @@ -0,0 +1,145 @@
11694 +#ifndef _VX_DEBUG_H
11695 +#define _VX_DEBUG_H
11696 +
11697 +
11698 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11699 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11700 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11701 +
11702 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11703 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11704 +#define VXF_DEV                "%p[%lu,%d:%d]"
11705 +
11706 +#if    defined(CONFIG_QUOTES_UTF8)
11707 +#define        VS_Q_LQM        "\xc2\xbb"
11708 +#define        VS_Q_RQM        "\xc2\xab"
11709 +#elif  defined(CONFIG_QUOTES_ASCII)
11710 +#define        VS_Q_LQM        "\x27"
11711 +#define        VS_Q_RQM        "\x27"
11712 +#else
11713 +#define        VS_Q_LQM        "\xbb"
11714 +#define        VS_Q_RQM        "\xab"
11715 +#endif
11716 +
11717 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11718 +
11719 +
11720 +#define vxd_path(p)                                            \
11721 +       ({ static char _buffer[PATH_MAX];                       \
11722 +          d_path(p, _buffer, sizeof(_buffer)); })
11723 +
11724 +#define vxd_cond_path(n)                                       \
11725 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11726 +
11727 +
11728 +#ifdef CONFIG_VSERVER_DEBUG
11729 +
11730 +extern unsigned int vs_debug_switch;
11731 +extern unsigned int vs_debug_xid;
11732 +extern unsigned int vs_debug_nid;
11733 +extern unsigned int vs_debug_tag;
11734 +extern unsigned int vs_debug_net;
11735 +extern unsigned int vs_debug_limit;
11736 +extern unsigned int vs_debug_cres;
11737 +extern unsigned int vs_debug_dlim;
11738 +extern unsigned int vs_debug_quota;
11739 +extern unsigned int vs_debug_cvirt;
11740 +extern unsigned int vs_debug_space;
11741 +extern unsigned int vs_debug_perm;
11742 +extern unsigned int vs_debug_misc;
11743 +
11744 +
11745 +#define VX_LOGLEVEL    "vxD: "
11746 +#define VX_PROC_FMT    "%p: "
11747 +#define VX_PROCESS     current
11748 +
11749 +#define vxdprintk(c, f, x...)                                  \
11750 +       do {                                                    \
11751 +               if (c)                                          \
11752 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11753 +                               VX_PROCESS , ##x);              \
11754 +       } while (0)
11755 +
11756 +#define vxlprintk(c, f, x...)                                  \
11757 +       do {                                                    \
11758 +               if (c)                                          \
11759 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11760 +       } while (0)
11761 +
11762 +#define vxfprintk(c, f, x...)                                  \
11763 +       do {                                                    \
11764 +               if (c)                                          \
11765 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11766 +       } while (0)
11767 +
11768 +
11769 +struct vx_info;
11770 +
11771 +void dump_vx_info(struct vx_info *, int);
11772 +void dump_vx_info_inactive(int);
11773 +
11774 +#else  /* CONFIG_VSERVER_DEBUG */
11775 +
11776 +#define vs_debug_switch        0
11777 +#define vs_debug_xid   0
11778 +#define vs_debug_nid   0
11779 +#define vs_debug_tag   0
11780 +#define vs_debug_net   0
11781 +#define vs_debug_limit 0
11782 +#define vs_debug_cres  0
11783 +#define vs_debug_dlim  0
11784 +#define vs_debug_quota 0
11785 +#define vs_debug_cvirt 0
11786 +#define vs_debug_space 0
11787 +#define vs_debug_perm  0
11788 +#define vs_debug_misc  0
11789 +
11790 +#define vxdprintk(x...) do { } while (0)
11791 +#define vxlprintk(x...) do { } while (0)
11792 +#define vxfprintk(x...) do { } while (0)
11793 +
11794 +#endif /* CONFIG_VSERVER_DEBUG */
11795 +
11796 +
11797 +#ifdef CONFIG_VSERVER_WARN
11798 +
11799 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11800 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11801 +#define VX_WARN_XID    "[xid #%u] "
11802 +#define VX_WARN_NID    "[nid #%u] "
11803 +#define VX_WARN_TAG    "[tag #%u] "
11804 +
11805 +#define vxwprintk(c, f, x...)                                  \
11806 +       do {                                                    \
11807 +               if (c)                                          \
11808 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11809 +       } while (0)
11810 +
11811 +#else  /* CONFIG_VSERVER_WARN */
11812 +
11813 +#define vxwprintk(x...) do { } while (0)
11814 +
11815 +#endif /* CONFIG_VSERVER_WARN */
11816 +
11817 +#define vxwprintk_task(c, f, x...)                             \
11818 +       vxwprintk(c, VX_WARN_TASK f,                            \
11819 +               current->comm, current->pid,                    \
11820 +               current->xid, current->nid, current->tag, ##x)
11821 +#define vxwprintk_xid(c, f, x...)                              \
11822 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11823 +#define vxwprintk_nid(c, f, x...)                              \
11824 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11825 +#define vxwprintk_tag(c, f, x...)                              \
11826 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11827 +
11828 +#ifdef CONFIG_VSERVER_DEBUG
11829 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11830 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11831 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11832 +#else
11833 +#define vxd_assert_lock(l)     do { } while (0)
11834 +#define vxd_assert(c, f, x...) do { } while (0)
11835 +#endif
11836 +
11837 +
11838 +#endif /* _VX_DEBUG_H */
11839 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/debug_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/debug_cmd.h
11840 --- linux-3.4.32/include/linux/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
11841 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/debug_cmd.h    2012-05-21 16:15:05.000000000 +0000
11842 @@ -0,0 +1,58 @@
11843 +#ifndef _VX_DEBUG_CMD_H
11844 +#define _VX_DEBUG_CMD_H
11845 +
11846 +
11847 +/* debug commands */
11848 +
11849 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11850 +
11851 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11852 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11853 +
11854 +struct  vcmd_read_history_v0 {
11855 +       uint32_t index;
11856 +       uint32_t count;
11857 +       char __user *data;
11858 +};
11859 +
11860 +struct  vcmd_read_monitor_v0 {
11861 +       uint32_t index;
11862 +       uint32_t count;
11863 +       char __user *data;
11864 +};
11865 +
11866 +
11867 +#ifdef __KERNEL__
11868 +
11869 +#ifdef CONFIG_COMPAT
11870 +
11871 +#include <asm/compat.h>
11872 +
11873 +struct vcmd_read_history_v0_x32 {
11874 +       uint32_t index;
11875 +       uint32_t count;
11876 +       compat_uptr_t data_ptr;
11877 +};
11878 +
11879 +struct vcmd_read_monitor_v0_x32 {
11880 +       uint32_t index;
11881 +       uint32_t count;
11882 +       compat_uptr_t data_ptr;
11883 +};
11884 +
11885 +#endif  /* CONFIG_COMPAT */
11886 +
11887 +extern int vc_dump_history(uint32_t);
11888 +
11889 +extern int vc_read_history(uint32_t, void __user *);
11890 +extern int vc_read_monitor(uint32_t, void __user *);
11891 +
11892 +#ifdef CONFIG_COMPAT
11893 +
11894 +extern int vc_read_history_x32(uint32_t, void __user *);
11895 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11896 +
11897 +#endif  /* CONFIG_COMPAT */
11898 +
11899 +#endif /* __KERNEL__ */
11900 +#endif /* _VX_DEBUG_CMD_H */
11901 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/device.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/device.h
11902 --- linux-3.4.32/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11903 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/device.h       2012-05-21 16:15:05.000000000 +0000
11904 @@ -0,0 +1,15 @@
11905 +#ifndef _VX_DEVICE_H
11906 +#define _VX_DEVICE_H
11907 +
11908 +
11909 +#define DATTR_CREATE   0x00000001
11910 +#define DATTR_OPEN     0x00000002
11911 +
11912 +#define DATTR_REMAP    0x00000010
11913 +
11914 +#define DATTR_MASK     0x00000013
11915 +
11916 +
11917 +#else  /* _VX_DEVICE_H */
11918 +#warning duplicate inclusion
11919 +#endif /* _VX_DEVICE_H */
11920 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/device_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/device_cmd.h
11921 --- linux-3.4.32/include/linux/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
11922 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/device_cmd.h   2012-05-21 16:15:05.000000000 +0000
11923 @@ -0,0 +1,44 @@
11924 +#ifndef _VX_DEVICE_CMD_H
11925 +#define _VX_DEVICE_CMD_H
11926 +
11927 +
11928 +/*  device vserver commands */
11929 +
11930 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11931 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11932 +
11933 +struct vcmd_set_mapping_v0 {
11934 +       const char __user *device;
11935 +       const char __user *target;
11936 +       uint32_t flags;
11937 +};
11938 +
11939 +
11940 +#ifdef __KERNEL__
11941 +
11942 +#ifdef CONFIG_COMPAT
11943 +
11944 +#include <asm/compat.h>
11945 +
11946 +struct vcmd_set_mapping_v0_x32 {
11947 +       compat_uptr_t device_ptr;
11948 +       compat_uptr_t target_ptr;
11949 +       uint32_t flags;
11950 +};
11951 +
11952 +#endif /* CONFIG_COMPAT */
11953 +
11954 +#include <linux/compiler.h>
11955 +
11956 +extern int vc_set_mapping(struct vx_info *, void __user *);
11957 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11958 +
11959 +#ifdef CONFIG_COMPAT
11960 +
11961 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11962 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11963 +
11964 +#endif /* CONFIG_COMPAT */
11965 +
11966 +#endif /* __KERNEL__ */
11967 +#endif /* _VX_DEVICE_CMD_H */
11968 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/device_def.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/device_def.h
11969 --- linux-3.4.32/include/linux/vserver/device_def.h     1970-01-01 00:00:00.000000000 +0000
11970 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/device_def.h   2012-05-21 16:15:05.000000000 +0000
11971 @@ -0,0 +1,17 @@
11972 +#ifndef _VX_DEVICE_DEF_H
11973 +#define _VX_DEVICE_DEF_H
11974 +
11975 +#include <linux/types.h>
11976 +
11977 +struct vx_dmap_target {
11978 +       dev_t target;
11979 +       uint32_t flags;
11980 +};
11981 +
11982 +struct _vx_device {
11983 +#ifdef CONFIG_VSERVER_DEVICE
11984 +       struct vx_dmap_target targets[2];
11985 +#endif
11986 +};
11987 +
11988 +#endif /* _VX_DEVICE_DEF_H */
11989 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/dlimit.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/dlimit.h
11990 --- linux-3.4.32/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
11991 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/dlimit.h       2012-05-21 16:15:05.000000000 +0000
11992 @@ -0,0 +1,54 @@
11993 +#ifndef _VX_DLIMIT_H
11994 +#define _VX_DLIMIT_H
11995 +
11996 +#include "switch.h"
11997 +
11998 +
11999 +#ifdef __KERNEL__
12000 +
12001 +/*      keep in sync with CDLIM_INFINITY       */
12002 +
12003 +#define DLIM_INFINITY          (~0ULL)
12004 +
12005 +#include <linux/spinlock.h>
12006 +#include <linux/rcupdate.h>
12007 +
12008 +struct super_block;
12009 +
12010 +struct dl_info {
12011 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12012 +       struct rcu_head dl_rcu;                 /* the rcu head */
12013 +       tag_t dl_tag;                           /* context tag */
12014 +       atomic_t dl_usecnt;                     /* usage count */
12015 +       atomic_t dl_refcnt;                     /* reference count */
12016 +
12017 +       struct super_block *dl_sb;              /* associated superblock */
12018 +
12019 +       spinlock_t dl_lock;                     /* protect the values */
12020 +
12021 +       unsigned long long dl_space_used;       /* used space in bytes */
12022 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12023 +       unsigned long dl_inodes_used;           /* used inodes */
12024 +       unsigned long dl_inodes_total;          /* maximum inodes */
12025 +
12026 +       unsigned int dl_nrlmult;                /* non root limit mult */
12027 +};
12028 +
12029 +struct rcu_head;
12030 +
12031 +extern void rcu_free_dl_info(struct rcu_head *);
12032 +extern void unhash_dl_info(struct dl_info *);
12033 +
12034 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12035 +
12036 +
12037 +struct kstatfs;
12038 +
12039 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12040 +
12041 +typedef uint64_t dlsize_t;
12042 +
12043 +#endif /* __KERNEL__ */
12044 +#else  /* _VX_DLIMIT_H */
12045 +#warning duplicate inclusion
12046 +#endif /* _VX_DLIMIT_H */
12047 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/dlimit_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/dlimit_cmd.h
12048 --- linux-3.4.32/include/linux/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12049 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/dlimit_cmd.h   2012-05-21 16:15:05.000000000 +0000
12050 @@ -0,0 +1,109 @@
12051 +#ifndef _VX_DLIMIT_CMD_H
12052 +#define _VX_DLIMIT_CMD_H
12053 +
12054 +
12055 +/*  dlimit vserver commands */
12056 +
12057 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12058 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12059 +
12060 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12061 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12062 +
12063 +struct vcmd_ctx_dlimit_base_v0 {
12064 +       const char __user *name;
12065 +       uint32_t flags;
12066 +};
12067 +
12068 +struct vcmd_ctx_dlimit_v0 {
12069 +       const char __user *name;
12070 +       uint32_t space_used;                    /* used space in kbytes */
12071 +       uint32_t space_total;                   /* maximum space in kbytes */
12072 +       uint32_t inodes_used;                   /* used inodes */
12073 +       uint32_t inodes_total;                  /* maximum inodes */
12074 +       uint32_t reserved;                      /* reserved for root in % */
12075 +       uint32_t flags;
12076 +};
12077 +
12078 +#define CDLIM_UNSET            ((uint32_t)0UL)
12079 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12080 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12081 +
12082 +#define DLIME_UNIT     0
12083 +#define DLIME_KILO     1
12084 +#define DLIME_MEGA     2
12085 +#define DLIME_GIGA     3
12086 +
12087 +#define DLIMF_SHIFT    0x10
12088 +
12089 +#define DLIMS_USED     0
12090 +#define DLIMS_TOTAL    2
12091 +
12092 +static inline
12093 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12094 +{
12095 +       int exp = (flags & DLIMF_SHIFT) ?
12096 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12097 +       return ((uint64_t)val) << (10 * exp);
12098 +}
12099 +
12100 +static inline
12101 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12102 +{
12103 +       int exp = 0;
12104 +
12105 +       if (*flags & DLIMF_SHIFT) {
12106 +               while (val > (1LL << 32) && (exp < 3)) {
12107 +                       val >>= 10;
12108 +                       exp++;
12109 +               }
12110 +               *flags &= ~(DLIME_GIGA << shift);
12111 +               *flags |= exp << shift;
12112 +       } else
12113 +               val >>= 10;
12114 +       return val;
12115 +}
12116 +
12117 +#ifdef __KERNEL__
12118 +
12119 +#ifdef CONFIG_COMPAT
12120 +
12121 +#include <asm/compat.h>
12122 +
12123 +struct vcmd_ctx_dlimit_base_v0_x32 {
12124 +       compat_uptr_t name_ptr;
12125 +       uint32_t flags;
12126 +};
12127 +
12128 +struct vcmd_ctx_dlimit_v0_x32 {
12129 +       compat_uptr_t name_ptr;
12130 +       uint32_t space_used;                    /* used space in kbytes */
12131 +       uint32_t space_total;                   /* maximum space in kbytes */
12132 +       uint32_t inodes_used;                   /* used inodes */
12133 +       uint32_t inodes_total;                  /* maximum inodes */
12134 +       uint32_t reserved;                      /* reserved for root in % */
12135 +       uint32_t flags;
12136 +};
12137 +
12138 +#endif /* CONFIG_COMPAT */
12139 +
12140 +#include <linux/compiler.h>
12141 +
12142 +extern int vc_add_dlimit(uint32_t, void __user *);
12143 +extern int vc_rem_dlimit(uint32_t, void __user *);
12144 +
12145 +extern int vc_set_dlimit(uint32_t, void __user *);
12146 +extern int vc_get_dlimit(uint32_t, void __user *);
12147 +
12148 +#ifdef CONFIG_COMPAT
12149 +
12150 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12151 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12152 +
12153 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12154 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12155 +
12156 +#endif /* CONFIG_COMPAT */
12157 +
12158 +#endif /* __KERNEL__ */
12159 +#endif /* _VX_DLIMIT_CMD_H */
12160 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/global.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/global.h
12161 --- linux-3.4.32/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
12162 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/global.h       2012-05-21 16:15:05.000000000 +0000
12163 @@ -0,0 +1,19 @@
12164 +#ifndef _VX_GLOBAL_H
12165 +#define _VX_GLOBAL_H
12166 +
12167 +
12168 +extern atomic_t vx_global_ctotal;
12169 +extern atomic_t vx_global_cactive;
12170 +
12171 +extern atomic_t nx_global_ctotal;
12172 +extern atomic_t nx_global_cactive;
12173 +
12174 +extern atomic_t vs_global_nsproxy;
12175 +extern atomic_t vs_global_fs;
12176 +extern atomic_t vs_global_mnt_ns;
12177 +extern atomic_t vs_global_uts_ns;
12178 +extern atomic_t vs_global_user_ns;
12179 +extern atomic_t vs_global_pid_ns;
12180 +
12181 +
12182 +#endif /* _VX_GLOBAL_H */
12183 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/history.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/history.h
12184 --- linux-3.4.32/include/linux/vserver/history.h        1970-01-01 00:00:00.000000000 +0000
12185 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/history.h      2012-05-21 16:15:05.000000000 +0000
12186 @@ -0,0 +1,197 @@
12187 +#ifndef _VX_HISTORY_H
12188 +#define _VX_HISTORY_H
12189 +
12190 +
12191 +enum {
12192 +       VXH_UNUSED = 0,
12193 +       VXH_THROW_OOPS = 1,
12194 +
12195 +       VXH_GET_VX_INFO,
12196 +       VXH_PUT_VX_INFO,
12197 +       VXH_INIT_VX_INFO,
12198 +       VXH_SET_VX_INFO,
12199 +       VXH_CLR_VX_INFO,
12200 +       VXH_CLAIM_VX_INFO,
12201 +       VXH_RELEASE_VX_INFO,
12202 +       VXH_ALLOC_VX_INFO,
12203 +       VXH_DEALLOC_VX_INFO,
12204 +       VXH_HASH_VX_INFO,
12205 +       VXH_UNHASH_VX_INFO,
12206 +       VXH_LOC_VX_INFO,
12207 +       VXH_LOOKUP_VX_INFO,
12208 +       VXH_CREATE_VX_INFO,
12209 +};
12210 +
12211 +struct _vxhe_vxi {
12212 +       struct vx_info *ptr;
12213 +       unsigned xid;
12214 +       unsigned usecnt;
12215 +       unsigned tasks;
12216 +};
12217 +
12218 +struct _vxhe_set_clr {
12219 +       void *data;
12220 +};
12221 +
12222 +struct _vxhe_loc_lookup {
12223 +       unsigned arg;
12224 +};
12225 +
12226 +struct _vx_hist_entry {
12227 +       void *loc;
12228 +       unsigned short seq;
12229 +       unsigned short type;
12230 +       struct _vxhe_vxi vxi;
12231 +       union {
12232 +               struct _vxhe_set_clr sc;
12233 +               struct _vxhe_loc_lookup ll;
12234 +       };
12235 +};
12236 +
12237 +#ifdef CONFIG_VSERVER_HISTORY
12238 +
12239 +extern unsigned volatile int vxh_active;
12240 +
12241 +struct _vx_hist_entry *vxh_advance(void *loc);
12242 +
12243 +
12244 +static inline
12245 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12246 +{
12247 +       entry->vxi.ptr = vxi;
12248 +       if (vxi) {
12249 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12250 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12251 +               entry->vxi.xid = vxi->vx_id;
12252 +       }
12253 +}
12254 +
12255 +
12256 +#define        __HERE__ current_text_addr()
12257 +
12258 +#define __VXH_BODY(__type, __data, __here)     \
12259 +       struct _vx_hist_entry *entry;           \
12260 +                                               \
12261 +       preempt_disable();                      \
12262 +       entry = vxh_advance(__here);            \
12263 +       __data;                                 \
12264 +       entry->type = __type;                   \
12265 +       preempt_enable();
12266 +
12267 +
12268 +       /* pass vxi only */
12269 +
12270 +#define __VXH_SMPL                             \
12271 +       __vxh_copy_vxi(entry, vxi)
12272 +
12273 +static inline
12274 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12275 +{
12276 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12277 +}
12278 +
12279 +       /* pass vxi and data (void *) */
12280 +
12281 +#define __VXH_DATA                             \
12282 +       __vxh_copy_vxi(entry, vxi);             \
12283 +       entry->sc.data = data
12284 +
12285 +static inline
12286 +void   __vxh_data(struct vx_info *vxi, void *data,
12287 +                       int __type, void *__here)
12288 +{
12289 +       __VXH_BODY(__type, __VXH_DATA, __here)
12290 +}
12291 +
12292 +       /* pass vxi and arg (long) */
12293 +
12294 +#define __VXH_LONG                             \
12295 +       __vxh_copy_vxi(entry, vxi);             \
12296 +       entry->ll.arg = arg
12297 +
12298 +static inline
12299 +void   __vxh_long(struct vx_info *vxi, long arg,
12300 +                       int __type, void *__here)
12301 +{
12302 +       __VXH_BODY(__type, __VXH_LONG, __here)
12303 +}
12304 +
12305 +
12306 +static inline
12307 +void   __vxh_throw_oops(void *__here)
12308 +{
12309 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12310 +       /* prevent further acquisition */
12311 +       vxh_active = 0;
12312 +}
12313 +
12314 +
12315 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12316 +
12317 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12318 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12319 +
12320 +#define __vxh_init_vx_info(v, d, h) \
12321 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12322 +#define __vxh_set_vx_info(v, d, h) \
12323 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12324 +#define __vxh_clr_vx_info(v, d, h) \
12325 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12326 +
12327 +#define __vxh_claim_vx_info(v, d, h) \
12328 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12329 +#define __vxh_release_vx_info(v, d, h) \
12330 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12331 +
12332 +#define vxh_alloc_vx_info(v) \
12333 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12334 +#define vxh_dealloc_vx_info(v) \
12335 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12336 +
12337 +#define vxh_hash_vx_info(v) \
12338 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12339 +#define vxh_unhash_vx_info(v) \
12340 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12341 +
12342 +#define vxh_loc_vx_info(v, l) \
12343 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12344 +#define vxh_lookup_vx_info(v, l) \
12345 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12346 +#define vxh_create_vx_info(v, l) \
12347 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12348 +
12349 +extern void vxh_dump_history(void);
12350 +
12351 +
12352 +#else  /* CONFIG_VSERVER_HISTORY */
12353 +
12354 +#define        __HERE__        0
12355 +
12356 +#define vxh_throw_oops()               do { } while (0)
12357 +
12358 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12359 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12360 +
12361 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12362 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12363 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12364 +
12365 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12366 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12367 +
12368 +#define vxh_alloc_vx_info(v)           do { } while (0)
12369 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12370 +
12371 +#define vxh_hash_vx_info(v)            do { } while (0)
12372 +#define vxh_unhash_vx_info(v)          do { } while (0)
12373 +
12374 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12375 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12376 +#define vxh_create_vx_info(v, l)       do { } while (0)
12377 +
12378 +#define vxh_dump_history()             do { } while (0)
12379 +
12380 +
12381 +#endif /* CONFIG_VSERVER_HISTORY */
12382 +
12383 +#endif /* _VX_HISTORY_H */
12384 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/inode.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/inode.h
12385 --- linux-3.4.32/include/linux/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12386 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/inode.h        2012-05-21 16:15:05.000000000 +0000
12387 @@ -0,0 +1,39 @@
12388 +#ifndef _VX_INODE_H
12389 +#define _VX_INODE_H
12390 +
12391 +
12392 +#define IATTR_TAG      0x01000000
12393 +
12394 +#define IATTR_ADMIN    0x00000001
12395 +#define IATTR_WATCH    0x00000002
12396 +#define IATTR_HIDE     0x00000004
12397 +#define IATTR_FLAGS    0x00000007
12398 +
12399 +#define IATTR_BARRIER  0x00010000
12400 +#define IATTR_IXUNLINK 0x00020000
12401 +#define IATTR_IMMUTABLE 0x00040000
12402 +#define IATTR_COW      0x00080000
12403 +
12404 +#ifdef __KERNEL__
12405 +
12406 +
12407 +#ifdef CONFIG_VSERVER_PROC_SECURE
12408 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12409 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12410 +#else
12411 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12412 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12413 +#endif
12414 +
12415 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12416 +
12417 +#endif /* __KERNEL__ */
12418 +
12419 +/* inode ioctls */
12420 +
12421 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12422 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12423 +
12424 +#else  /* _VX_INODE_H */
12425 +#warning duplicate inclusion
12426 +#endif /* _VX_INODE_H */
12427 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/inode_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/inode_cmd.h
12428 --- linux-3.4.32/include/linux/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12429 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/inode_cmd.h    2012-05-21 16:15:05.000000000 +0000
12430 @@ -0,0 +1,59 @@
12431 +#ifndef _VX_INODE_CMD_H
12432 +#define _VX_INODE_CMD_H
12433 +
12434 +
12435 +/*  inode vserver commands */
12436 +
12437 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12438 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12439 +
12440 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12441 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12442 +
12443 +struct vcmd_ctx_iattr_v1 {
12444 +       const char __user *name;
12445 +       uint32_t tag;
12446 +       uint32_t flags;
12447 +       uint32_t mask;
12448 +};
12449 +
12450 +struct vcmd_ctx_fiattr_v0 {
12451 +       uint32_t tag;
12452 +       uint32_t flags;
12453 +       uint32_t mask;
12454 +};
12455 +
12456 +
12457 +#ifdef __KERNEL__
12458 +
12459 +
12460 +#ifdef CONFIG_COMPAT
12461 +
12462 +#include <asm/compat.h>
12463 +
12464 +struct vcmd_ctx_iattr_v1_x32 {
12465 +       compat_uptr_t name_ptr;
12466 +       uint32_t tag;
12467 +       uint32_t flags;
12468 +       uint32_t mask;
12469 +};
12470 +
12471 +#endif /* CONFIG_COMPAT */
12472 +
12473 +#include <linux/compiler.h>
12474 +
12475 +extern int vc_get_iattr(void __user *);
12476 +extern int vc_set_iattr(void __user *);
12477 +
12478 +extern int vc_fget_iattr(uint32_t, void __user *);
12479 +extern int vc_fset_iattr(uint32_t, void __user *);
12480 +
12481 +#ifdef CONFIG_COMPAT
12482 +
12483 +extern int vc_get_iattr_x32(void __user *);
12484 +extern int vc_set_iattr_x32(void __user *);
12485 +
12486 +#endif /* CONFIG_COMPAT */
12487 +
12488 +#endif /* __KERNEL__ */
12489 +#endif /* _VX_INODE_CMD_H */
12490 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/limit.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit.h
12491 --- linux-3.4.32/include/linux/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12492 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit.h        2012-05-21 16:15:05.000000000 +0000
12493 @@ -0,0 +1,71 @@
12494 +#ifndef _VX_LIMIT_H
12495 +#define _VX_LIMIT_H
12496 +
12497 +#define VLIMIT_NSOCK   16
12498 +#define VLIMIT_OPENFD  17
12499 +#define VLIMIT_ANON    18
12500 +#define VLIMIT_SHMEM   19
12501 +#define VLIMIT_SEMARY  20
12502 +#define VLIMIT_NSEMS   21
12503 +#define VLIMIT_DENTRY  22
12504 +#define VLIMIT_MAPPED  23
12505 +
12506 +
12507 +#ifdef __KERNEL__
12508 +
12509 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12510 +
12511 +/*     keep in sync with CRLIM_INFINITY */
12512 +
12513 +#define        VLIM_INFINITY   (~0ULL)
12514 +
12515 +#include <asm/atomic.h>
12516 +#include <asm/resource.h>
12517 +
12518 +#ifndef RLIM_INFINITY
12519 +#warning RLIM_INFINITY is undefined
12520 +#endif
12521 +
12522 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12523 +
12524 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12525 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12526 +
12527 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12528 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12529 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12530 +
12531 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12532 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12533 +
12534 +typedef atomic_long_t rlim_atomic_t;
12535 +typedef unsigned long rlim_t;
12536 +
12537 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12538 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12539 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12540 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12541 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12542 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12543 +
12544 +
12545 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12546 +#define        VX_VLIM(r) ((long long)(long)(r))
12547 +#define        VX_RLIM(v) ((rlim_t)(v))
12548 +#else
12549 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12550 +               ? VLIM_INFINITY : (long long)(r))
12551 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12552 +               ? RLIM_INFINITY : (rlim_t)(v))
12553 +#endif
12554 +
12555 +struct sysinfo;
12556 +
12557 +void vx_vsi_meminfo(struct sysinfo *);
12558 +void vx_vsi_swapinfo(struct sysinfo *);
12559 +long vx_vsi_cached(struct sysinfo *);
12560 +
12561 +#define NUM_LIMITS     24
12562 +
12563 +#endif /* __KERNEL__ */
12564 +#endif /* _VX_LIMIT_H */
12565 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/limit_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit_cmd.h
12566 --- linux-3.4.32/include/linux/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12567 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit_cmd.h    2012-05-21 16:15:05.000000000 +0000
12568 @@ -0,0 +1,71 @@
12569 +#ifndef _VX_LIMIT_CMD_H
12570 +#define _VX_LIMIT_CMD_H
12571 +
12572 +
12573 +/*  rlimit vserver commands */
12574 +
12575 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12576 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12577 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12578 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12579 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12580 +
12581 +struct vcmd_ctx_rlimit_v0 {
12582 +       uint32_t id;
12583 +       uint64_t minimum;
12584 +       uint64_t softlimit;
12585 +       uint64_t maximum;
12586 +};
12587 +
12588 +struct vcmd_ctx_rlimit_mask_v0 {
12589 +       uint32_t minimum;
12590 +       uint32_t softlimit;
12591 +       uint32_t maximum;
12592 +};
12593 +
12594 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12595 +
12596 +struct vcmd_rlimit_stat_v0 {
12597 +       uint32_t id;
12598 +       uint32_t hits;
12599 +       uint64_t value;
12600 +       uint64_t minimum;
12601 +       uint64_t maximum;
12602 +};
12603 +
12604 +#define CRLIM_UNSET            (0ULL)
12605 +#define CRLIM_INFINITY         (~0ULL)
12606 +#define CRLIM_KEEP             (~1ULL)
12607 +
12608 +#ifdef __KERNEL__
12609 +
12610 +#ifdef CONFIG_IA32_EMULATION
12611 +
12612 +struct vcmd_ctx_rlimit_v0_x32 {
12613 +       uint32_t id;
12614 +       uint64_t minimum;
12615 +       uint64_t softlimit;
12616 +       uint64_t maximum;
12617 +} __attribute__ ((packed));
12618 +
12619 +#endif /* CONFIG_IA32_EMULATION */
12620 +
12621 +#include <linux/compiler.h>
12622 +
12623 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12624 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12625 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12626 +extern int vc_reset_hits(struct vx_info *, void __user *);
12627 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12628 +
12629 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12630 +
12631 +#ifdef CONFIG_IA32_EMULATION
12632 +
12633 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12634 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12635 +
12636 +#endif /* CONFIG_IA32_EMULATION */
12637 +
12638 +#endif /* __KERNEL__ */
12639 +#endif /* _VX_LIMIT_CMD_H */
12640 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/limit_def.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit_def.h
12641 --- linux-3.4.32/include/linux/vserver/limit_def.h      1970-01-01 00:00:00.000000000 +0000
12642 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit_def.h    2012-05-21 16:15:05.000000000 +0000
12643 @@ -0,0 +1,47 @@
12644 +#ifndef _VX_LIMIT_DEF_H
12645 +#define _VX_LIMIT_DEF_H
12646 +
12647 +#include <asm/atomic.h>
12648 +#include <asm/resource.h>
12649 +
12650 +#include "limit.h"
12651 +
12652 +
12653 +struct _vx_res_limit {
12654 +       rlim_t soft;            /* Context soft limit */
12655 +       rlim_t hard;            /* Context hard limit */
12656 +
12657 +       rlim_atomic_t rcur;     /* Current value */
12658 +       rlim_t rmin;            /* Context minimum */
12659 +       rlim_t rmax;            /* Context maximum */
12660 +
12661 +       atomic_t lhit;          /* Limit hits */
12662 +};
12663 +
12664 +/* context sub struct */
12665 +
12666 +struct _vx_limit {
12667 +       struct _vx_res_limit res[NUM_LIMITS];
12668 +};
12669 +
12670 +#ifdef CONFIG_VSERVER_DEBUG
12671 +
12672 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12673 +{
12674 +       int i;
12675 +
12676 +       printk("\t_vx_limit:");
12677 +       for (i = 0; i < NUM_LIMITS; i++) {
12678 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12679 +                       i, (unsigned long)__rlim_get(limit, i),
12680 +                       (unsigned long)__rlim_rmin(limit, i),
12681 +                       (unsigned long)__rlim_rmax(limit, i),
12682 +                       (long)__rlim_soft(limit, i),
12683 +                       (long)__rlim_hard(limit, i),
12684 +                       atomic_read(&__rlim_lhit(limit, i)));
12685 +       }
12686 +}
12687 +
12688 +#endif
12689 +
12690 +#endif /* _VX_LIMIT_DEF_H */
12691 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/limit_int.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit_int.h
12692 --- linux-3.4.32/include/linux/vserver/limit_int.h      1970-01-01 00:00:00.000000000 +0000
12693 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/limit_int.h    2012-05-21 16:15:05.000000000 +0000
12694 @@ -0,0 +1,198 @@
12695 +#ifndef _VX_LIMIT_INT_H
12696 +#define _VX_LIMIT_INT_H
12697 +
12698 +#include "context.h"
12699 +
12700 +#ifdef __KERNEL__
12701 +
12702 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12703 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12704 +
12705 +extern const char *vlimit_name[NUM_LIMITS];
12706 +
12707 +static inline void __vx_acc_cres(struct vx_info *vxi,
12708 +       int res, int dir, void *_data, char *_file, int _line)
12709 +{
12710 +       if (VXD_RCRES_COND(res))
12711 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12712 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12713 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12714 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12715 +       if (!vxi)
12716 +               return;
12717 +
12718 +       if (dir > 0)
12719 +               __rlim_inc(&vxi->limit, res);
12720 +       else
12721 +               __rlim_dec(&vxi->limit, res);
12722 +}
12723 +
12724 +static inline void __vx_add_cres(struct vx_info *vxi,
12725 +       int res, int amount, void *_data, char *_file, int _line)
12726 +{
12727 +       if (VXD_RCRES_COND(res))
12728 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12729 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12730 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12731 +                       amount, _data, _file, _line);
12732 +       if (amount == 0)
12733 +               return;
12734 +       if (!vxi)
12735 +               return;
12736 +       __rlim_add(&vxi->limit, res, amount);
12737 +}
12738 +
12739 +static inline
12740 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12741 +{
12742 +       int cond = (value > __rlim_rmax(limit, res));
12743 +
12744 +       if (cond)
12745 +               __rlim_rmax(limit, res) = value;
12746 +       return cond;
12747 +}
12748 +
12749 +static inline
12750 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12751 +{
12752 +       int cond = (value < __rlim_rmin(limit, res));
12753 +
12754 +       if (cond)
12755 +               __rlim_rmin(limit, res) = value;
12756 +       return cond;
12757 +}
12758 +
12759 +static inline
12760 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12761 +{
12762 +       if (!__vx_cres_adjust_max(limit, res, value))
12763 +               __vx_cres_adjust_min(limit, res, value);
12764 +}
12765 +
12766 +
12767 +/*     return values:
12768 +        +1 ... no limit hit
12769 +        -1 ... over soft limit
12770 +         0 ... over hard limit         */
12771 +
12772 +static inline int __vx_cres_avail(struct vx_info *vxi,
12773 +       int res, int num, char *_file, int _line)
12774 +{
12775 +       struct _vx_limit *limit;
12776 +       rlim_t value;
12777 +
12778 +       if (VXD_RLIMIT_COND(res))
12779 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12780 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12781 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12782 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12783 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12784 +                       num, _file, _line);
12785 +       if (!vxi)
12786 +               return 1;
12787 +
12788 +       limit = &vxi->limit;
12789 +       value = __rlim_get(limit, res);
12790 +
12791 +       if (!__vx_cres_adjust_max(limit, res, value))
12792 +               __vx_cres_adjust_min(limit, res, value);
12793 +
12794 +       if (num == 0)
12795 +               return 1;
12796 +
12797 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12798 +               return -1;
12799 +       if (value + num <= __rlim_soft(limit, res))
12800 +               return -1;
12801 +
12802 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12803 +               return 1;
12804 +       if (value + num <= __rlim_hard(limit, res))
12805 +               return 1;
12806 +
12807 +       __rlim_hit(limit, res);
12808 +       return 0;
12809 +}
12810 +
12811 +
12812 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12813 +
12814 +static inline
12815 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12816 +{
12817 +       rlim_t value, sum = 0;
12818 +       int res;
12819 +
12820 +       while ((res = *array++)) {
12821 +               value = __rlim_get(limit, res);
12822 +               __vx_cres_fixup(limit, res, value);
12823 +               sum += value;
12824 +       }
12825 +       return sum;
12826 +}
12827 +
12828 +static inline
12829 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12830 +{
12831 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12832 +       int res = *array;
12833 +
12834 +       if (value == __rlim_get(limit, res))
12835 +               return value;
12836 +
12837 +       __rlim_set(limit, res, value);
12838 +       /* now adjust min/max */
12839 +       if (!__vx_cres_adjust_max(limit, res, value))
12840 +               __vx_cres_adjust_min(limit, res, value);
12841 +
12842 +       return value;
12843 +}
12844 +
12845 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12846 +       const int *array, int num, char *_file, int _line)
12847 +{
12848 +       struct _vx_limit *limit;
12849 +       rlim_t value = 0;
12850 +       int res;
12851 +
12852 +       if (num == 0)
12853 +               return 1;
12854 +       if (!vxi)
12855 +               return 1;
12856 +
12857 +       limit = &vxi->limit;
12858 +       res = *array;
12859 +       value = __vx_cres_array_sum(limit, array + 1);
12860 +
12861 +       __rlim_set(limit, res, value);
12862 +       __vx_cres_fixup(limit, res, value);
12863 +
12864 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12865 +}
12866 +
12867 +
12868 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12869 +{
12870 +       rlim_t value;
12871 +       int res;
12872 +
12873 +       /* complex resources first */
12874 +       if ((id < 0) || (id == RLIMIT_RSS))
12875 +               __vx_cres_array_fixup(limit, VLA_RSS);
12876 +
12877 +       for (res = 0; res < NUM_LIMITS; res++) {
12878 +               if ((id > 0) && (res != id))
12879 +                       continue;
12880 +
12881 +               value = __rlim_get(limit, res);
12882 +               __vx_cres_fixup(limit, res, value);
12883 +
12884 +               /* not supposed to happen, maybe warn? */
12885 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12886 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12887 +       }
12888 +}
12889 +
12890 +
12891 +#endif /* __KERNEL__ */
12892 +#endif /* _VX_LIMIT_INT_H */
12893 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/monitor.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/monitor.h
12894 --- linux-3.4.32/include/linux/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12895 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/monitor.h      2012-05-21 16:15:05.000000000 +0000
12896 @@ -0,0 +1,96 @@
12897 +#ifndef _VX_MONITOR_H
12898 +#define _VX_MONITOR_H
12899 +
12900 +#include <linux/types.h>
12901 +
12902 +enum {
12903 +       VXM_UNUSED = 0,
12904 +
12905 +       VXM_SYNC = 0x10,
12906 +
12907 +       VXM_UPDATE = 0x20,
12908 +       VXM_UPDATE_1,
12909 +       VXM_UPDATE_2,
12910 +
12911 +       VXM_RQINFO_1 = 0x24,
12912 +       VXM_RQINFO_2,
12913 +
12914 +       VXM_ACTIVATE = 0x40,
12915 +       VXM_DEACTIVATE,
12916 +       VXM_IDLE,
12917 +
12918 +       VXM_HOLD = 0x44,
12919 +       VXM_UNHOLD,
12920 +
12921 +       VXM_MIGRATE = 0x48,
12922 +       VXM_RESCHED,
12923 +
12924 +       /* all other bits are flags */
12925 +       VXM_SCHED = 0x80,
12926 +};
12927 +
12928 +struct _vxm_update_1 {
12929 +       uint32_t tokens_max;
12930 +       uint32_t fill_rate;
12931 +       uint32_t interval;
12932 +};
12933 +
12934 +struct _vxm_update_2 {
12935 +       uint32_t tokens_min;
12936 +       uint32_t fill_rate;
12937 +       uint32_t interval;
12938 +};
12939 +
12940 +struct _vxm_rqinfo_1 {
12941 +       uint16_t running;
12942 +       uint16_t onhold;
12943 +       uint16_t iowait;
12944 +       uint16_t uintr;
12945 +       uint32_t idle_tokens;
12946 +};
12947 +
12948 +struct _vxm_rqinfo_2 {
12949 +       uint32_t norm_time;
12950 +       uint32_t idle_time;
12951 +       uint32_t idle_skip;
12952 +};
12953 +
12954 +struct _vxm_sched {
12955 +       uint32_t tokens;
12956 +       uint32_t norm_time;
12957 +       uint32_t idle_time;
12958 +};
12959 +
12960 +struct _vxm_task {
12961 +       uint16_t pid;
12962 +       uint16_t state;
12963 +};
12964 +
12965 +struct _vxm_event {
12966 +       uint32_t jif;
12967 +       union {
12968 +               uint32_t seq;
12969 +               uint32_t sec;
12970 +       };
12971 +       union {
12972 +               uint32_t tokens;
12973 +               uint32_t nsec;
12974 +               struct _vxm_task tsk;
12975 +       };
12976 +};
12977 +
12978 +struct _vx_mon_entry {
12979 +       uint16_t type;
12980 +       uint16_t xid;
12981 +       union {
12982 +               struct _vxm_event ev;
12983 +               struct _vxm_sched sd;
12984 +               struct _vxm_update_1 u1;
12985 +               struct _vxm_update_2 u2;
12986 +               struct _vxm_rqinfo_1 q1;
12987 +               struct _vxm_rqinfo_2 q2;
12988 +       };
12989 +};
12990 +
12991 +
12992 +#endif /* _VX_MONITOR_H */
12993 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/network.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/network.h
12994 --- linux-3.4.32/include/linux/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12995 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/network.h      2012-05-21 16:15:05.000000000 +0000
12996 @@ -0,0 +1,148 @@
12997 +#ifndef _VX_NETWORK_H
12998 +#define _VX_NETWORK_H
12999 +
13000 +#include <linux/types.h>
13001 +
13002 +
13003 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13004 +
13005 +
13006 +/* network flags */
13007 +
13008 +#define NXF_INFO_PRIVATE       0x00000008
13009 +
13010 +#define NXF_SINGLE_IP          0x00000100
13011 +#define NXF_LBACK_REMAP                0x00000200
13012 +#define NXF_LBACK_ALLOW                0x00000400
13013 +
13014 +#define NXF_HIDE_NETIF         0x02000000
13015 +#define NXF_HIDE_LBACK         0x04000000
13016 +
13017 +#define NXF_STATE_SETUP                (1ULL << 32)
13018 +#define NXF_STATE_ADMIN                (1ULL << 34)
13019 +
13020 +#define NXF_SC_HELPER          (1ULL << 36)
13021 +#define NXF_PERSISTENT         (1ULL << 38)
13022 +
13023 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13024 +
13025 +
13026 +#define        NXF_INIT_SET            (__nxf_init_set())
13027 +
13028 +static inline uint64_t __nxf_init_set(void) {
13029 +       return    NXF_STATE_ADMIN
13030 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13031 +               | NXF_LBACK_REMAP
13032 +               | NXF_HIDE_LBACK
13033 +#endif
13034 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13035 +               | NXF_SINGLE_IP
13036 +#endif
13037 +               | NXF_HIDE_NETIF;
13038 +}
13039 +
13040 +
13041 +/* network caps */
13042 +
13043 +#define NXC_TUN_CREATE         0x00000001
13044 +
13045 +#define NXC_RAW_ICMP           0x00000100
13046 +
13047 +#define NXC_MULTICAST          0x00001000
13048 +
13049 +
13050 +/* address types */
13051 +
13052 +#define NXA_TYPE_IPV4          0x0001
13053 +#define NXA_TYPE_IPV6          0x0002
13054 +
13055 +#define NXA_TYPE_NONE          0x0000
13056 +#define NXA_TYPE_ANY           0x00FF
13057 +
13058 +#define NXA_TYPE_ADDR          0x0010
13059 +#define NXA_TYPE_MASK          0x0020
13060 +#define NXA_TYPE_RANGE         0x0040
13061 +
13062 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13063 +
13064 +#define NXA_MOD_BCAST          0x0100
13065 +#define NXA_MOD_LBACK          0x0200
13066 +
13067 +#define NXA_LOOPBACK           0x1000
13068 +
13069 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13070 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13071 +
13072 +#ifdef __KERNEL__
13073 +
13074 +#include <linux/list.h>
13075 +#include <linux/spinlock.h>
13076 +#include <linux/rcupdate.h>
13077 +#include <linux/in.h>
13078 +#include <linux/in6.h>
13079 +#include <asm/atomic.h>
13080 +
13081 +struct nx_addr_v4 {
13082 +       struct nx_addr_v4 *next;
13083 +       struct in_addr ip[2];
13084 +       struct in_addr mask;
13085 +       uint16_t type;
13086 +       uint16_t flags;
13087 +};
13088 +
13089 +struct nx_addr_v6 {
13090 +       struct nx_addr_v6 *next;
13091 +       struct in6_addr ip;
13092 +       struct in6_addr mask;
13093 +       uint32_t prefix;
13094 +       uint16_t type;
13095 +       uint16_t flags;
13096 +};
13097 +
13098 +struct nx_info {
13099 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13100 +       nid_t nx_id;                    /* vnet id */
13101 +       atomic_t nx_usecnt;             /* usage count */
13102 +       atomic_t nx_tasks;              /* tasks count */
13103 +       int nx_state;                   /* context state */
13104 +
13105 +       uint64_t nx_flags;              /* network flag word */
13106 +       uint64_t nx_ncaps;              /* network capabilities */
13107 +
13108 +       struct in_addr v4_lback;        /* Loopback address */
13109 +       struct in_addr v4_bcast;        /* Broadcast address */
13110 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13111 +#ifdef CONFIG_IPV6
13112 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13113 +#endif
13114 +       char nx_name[65];               /* network context name */
13115 +};
13116 +
13117 +
13118 +/* status flags */
13119 +
13120 +#define NXS_HASHED      0x0001
13121 +#define NXS_SHUTDOWN    0x0100
13122 +#define NXS_RELEASED    0x8000
13123 +
13124 +extern struct nx_info *lookup_nx_info(int);
13125 +
13126 +extern int get_nid_list(int, unsigned int *, int);
13127 +extern int nid_is_hashed(nid_t);
13128 +
13129 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13130 +
13131 +extern long vs_net_change(struct nx_info *, unsigned int);
13132 +
13133 +struct sock;
13134 +
13135 +
13136 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13137 +#ifdef  CONFIG_IPV6
13138 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13139 +#else
13140 +#define NX_IPV6(n)     (0)
13141 +#endif
13142 +
13143 +#endif /* __KERNEL__ */
13144 +#endif /* _VX_NETWORK_H */
13145 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/network_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/network_cmd.h
13146 --- linux-3.4.32/include/linux/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
13147 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/network_cmd.h  2012-05-21 16:15:05.000000000 +0000
13148 @@ -0,0 +1,164 @@
13149 +#ifndef _VX_NETWORK_CMD_H
13150 +#define _VX_NETWORK_CMD_H
13151 +
13152 +
13153 +/* vinfo commands */
13154 +
13155 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13156 +
13157 +#ifdef __KERNEL__
13158 +extern int vc_task_nid(uint32_t);
13159 +
13160 +#endif /* __KERNEL__ */
13161 +
13162 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13163 +
13164 +struct vcmd_nx_info_v0 {
13165 +       uint32_t nid;
13166 +       /* more to come */
13167 +};
13168 +
13169 +#ifdef __KERNEL__
13170 +extern int vc_nx_info(struct nx_info *, void __user *);
13171 +
13172 +#endif /* __KERNEL__ */
13173 +
13174 +#include <linux/in.h>
13175 +#include <linux/in6.h>
13176 +
13177 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13178 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13179 +
13180 +struct  vcmd_net_create {
13181 +       uint64_t flagword;
13182 +};
13183 +
13184 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13185 +
13186 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13187 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13188 +
13189 +struct vcmd_net_addr_v0 {
13190 +       uint16_t type;
13191 +       uint16_t count;
13192 +       struct in_addr ip[4];
13193 +       struct in_addr mask[4];
13194 +};
13195 +
13196 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13197 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13198 +
13199 +struct vcmd_net_addr_ipv4_v1 {
13200 +       uint16_t type;
13201 +       uint16_t flags;
13202 +       struct in_addr ip;
13203 +       struct in_addr mask;
13204 +};
13205 +
13206 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13207 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13208 +
13209 +struct vcmd_net_addr_ipv4_v2 {
13210 +       uint16_t type;
13211 +       uint16_t flags;
13212 +       struct in_addr ip;
13213 +       struct in_addr ip2;
13214 +       struct in_addr mask;
13215 +};
13216 +
13217 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13218 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13219 +
13220 +struct vcmd_net_addr_ipv6_v1 {
13221 +       uint16_t type;
13222 +       uint16_t flags;
13223 +       uint32_t prefix;
13224 +       struct in6_addr ip;
13225 +       struct in6_addr mask;
13226 +};
13227 +
13228 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13229 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13230 +
13231 +struct vcmd_match_ipv4_v0 {
13232 +       uint16_t type;
13233 +       uint16_t flags;
13234 +       uint16_t parent;
13235 +       uint16_t prefix;
13236 +       struct in_addr ip;
13237 +       struct in_addr ip2;
13238 +       struct in_addr mask;
13239 +};
13240 +
13241 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13242 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13243 +
13244 +struct vcmd_match_ipv6_v0 {
13245 +       uint16_t type;
13246 +       uint16_t flags;
13247 +       uint16_t parent;
13248 +       uint16_t prefix;
13249 +       struct in6_addr ip;
13250 +       struct in6_addr ip2;
13251 +       struct in6_addr mask;
13252 +};
13253 +
13254 +
13255 +#ifdef __KERNEL__
13256 +extern int vc_net_create(uint32_t, void __user *);
13257 +extern int vc_net_migrate(struct nx_info *, void __user *);
13258 +
13259 +extern int vc_net_add(struct nx_info *, void __user *);
13260 +extern int vc_net_remove(struct nx_info *, void __user *);
13261 +
13262 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13263 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13264 +
13265 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13266 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13267 +
13268 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13269 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13270 +
13271 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13272 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13273 +
13274 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13275 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13276 +
13277 +#endif /* __KERNEL__ */
13278 +
13279 +
13280 +/* flag commands */
13281 +
13282 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13283 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13284 +
13285 +struct vcmd_net_flags_v0 {
13286 +       uint64_t flagword;
13287 +       uint64_t mask;
13288 +};
13289 +
13290 +#ifdef __KERNEL__
13291 +extern int vc_get_nflags(struct nx_info *, void __user *);
13292 +extern int vc_set_nflags(struct nx_info *, void __user *);
13293 +
13294 +#endif /* __KERNEL__ */
13295 +
13296 +
13297 +/* network caps commands */
13298 +
13299 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13300 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13301 +
13302 +struct vcmd_net_caps_v0 {
13303 +       uint64_t ncaps;
13304 +       uint64_t cmask;
13305 +};
13306 +
13307 +#ifdef __KERNEL__
13308 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13309 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13310 +
13311 +#endif /* __KERNEL__ */
13312 +#endif /* _VX_CONTEXT_CMD_H */
13313 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/percpu.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/percpu.h
13314 --- linux-3.4.32/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
13315 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/percpu.h       2012-05-21 16:15:05.000000000 +0000
13316 @@ -0,0 +1,14 @@
13317 +#ifndef _VX_PERCPU_H
13318 +#define _VX_PERCPU_H
13319 +
13320 +#include "cvirt_def.h"
13321 +#include "sched_def.h"
13322 +
13323 +struct _vx_percpu {
13324 +       struct _vx_cvirt_pc cvirt;
13325 +       struct _vx_sched_pc sched;
13326 +};
13327 +
13328 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13329 +
13330 +#endif /* _VX_PERCPU_H */
13331 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/pid.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/pid.h
13332 --- linux-3.4.32/include/linux/vserver/pid.h    1970-01-01 00:00:00.000000000 +0000
13333 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/pid.h  2012-05-21 16:15:05.000000000 +0000
13334 @@ -0,0 +1,51 @@
13335 +#ifndef _VSERVER_PID_H
13336 +#define _VSERVER_PID_H
13337 +
13338 +/* pid faking stuff */
13339 +
13340 +#define vx_info_map_pid(v, p) \
13341 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13342 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13343 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13344 +#define vx_map_tgid(p) vx_map_pid(p)
13345 +
13346 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13347 +       const char *func, const char *file, int line)
13348 +{
13349 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13350 +               vxfprintk(VXD_CBIT(cvirt, 2),
13351 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13352 +                       vxi, (long long)vxi->vx_flags, pid,
13353 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13354 +                       func, file, line);
13355 +               if (pid == 0)
13356 +                       return 0;
13357 +               if (pid == vxi->vx_initpid)
13358 +                       return 1;
13359 +       }
13360 +       return pid;
13361 +}
13362 +
13363 +#define vx_info_rmap_pid(v, p) \
13364 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13365 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13366 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13367 +
13368 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13369 +       const char *func, const char *file, int line)
13370 +{
13371 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13372 +               vxfprintk(VXD_CBIT(cvirt, 2),
13373 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13374 +                       vxi, (long long)vxi->vx_flags, pid,
13375 +                       (pid == 1) ? vxi->vx_initpid : pid,
13376 +                       func, file, line);
13377 +               if ((pid == 1) && vxi->vx_initpid)
13378 +                       return vxi->vx_initpid;
13379 +               if (pid == vxi->vx_initpid)
13380 +                       return ~0U;
13381 +       }
13382 +       return pid;
13383 +}
13384 +
13385 +#endif
13386 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/sched.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/sched.h
13387 --- linux-3.4.32/include/linux/vserver/sched.h  1970-01-01 00:00:00.000000000 +0000
13388 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/sched.h        2012-05-21 16:15:05.000000000 +0000
13389 @@ -0,0 +1,23 @@
13390 +#ifndef _VX_SCHED_H
13391 +#define _VX_SCHED_H
13392 +
13393 +
13394 +#ifdef __KERNEL__
13395 +
13396 +struct timespec;
13397 +
13398 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13399 +
13400 +
13401 +struct vx_info;
13402 +
13403 +void vx_update_load(struct vx_info *);
13404 +
13405 +
13406 +void vx_update_sched_param(struct _vx_sched *sched,
13407 +       struct _vx_sched_pc *sched_pc);
13408 +
13409 +#endif /* __KERNEL__ */
13410 +#else  /* _VX_SCHED_H */
13411 +#warning duplicate inclusion
13412 +#endif /* _VX_SCHED_H */
13413 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/sched_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/sched_cmd.h
13414 --- linux-3.4.32/include/linux/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
13415 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/sched_cmd.h    2012-05-21 16:15:05.000000000 +0000
13416 @@ -0,0 +1,21 @@
13417 +#ifndef _VX_SCHED_CMD_H
13418 +#define _VX_SCHED_CMD_H
13419 +
13420 +
13421 +struct vcmd_prio_bias {
13422 +       int32_t cpu_id;
13423 +       int32_t prio_bias;
13424 +};
13425 +
13426 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13427 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13428 +
13429 +#ifdef __KERNEL__
13430 +
13431 +#include <linux/compiler.h>
13432 +
13433 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13434 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13435 +
13436 +#endif /* __KERNEL__ */
13437 +#endif /* _VX_SCHED_CMD_H */
13438 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/sched_def.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/sched_def.h
13439 --- linux-3.4.32/include/linux/vserver/sched_def.h      1970-01-01 00:00:00.000000000 +0000
13440 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/sched_def.h    2012-05-21 16:15:05.000000000 +0000
13441 @@ -0,0 +1,38 @@
13442 +#ifndef _VX_SCHED_DEF_H
13443 +#define _VX_SCHED_DEF_H
13444 +
13445 +#include <linux/spinlock.h>
13446 +#include <linux/jiffies.h>
13447 +#include <linux/cpumask.h>
13448 +#include <asm/atomic.h>
13449 +#include <asm/param.h>
13450 +
13451 +
13452 +/* context sub struct */
13453 +
13454 +struct _vx_sched {
13455 +       int prio_bias;                  /* bias offset for priority */
13456 +
13457 +       cpumask_t update;               /* CPUs which should update */
13458 +};
13459 +
13460 +struct _vx_sched_pc {
13461 +       int prio_bias;                  /* bias offset for priority */
13462 +
13463 +       uint64_t user_ticks;            /* token tick events */
13464 +       uint64_t sys_ticks;             /* token tick events */
13465 +       uint64_t hold_ticks;            /* token ticks paused */
13466 +};
13467 +
13468 +
13469 +#ifdef CONFIG_VSERVER_DEBUG
13470 +
13471 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13472 +{
13473 +       printk("\t_vx_sched:\n");
13474 +       printk("\t priority = %4d\n", sched->prio_bias);
13475 +}
13476 +
13477 +#endif
13478 +
13479 +#endif /* _VX_SCHED_DEF_H */
13480 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/signal.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/signal.h
13481 --- linux-3.4.32/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
13482 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/signal.h       2012-05-21 16:15:05.000000000 +0000
13483 @@ -0,0 +1,14 @@
13484 +#ifndef _VX_SIGNAL_H
13485 +#define _VX_SIGNAL_H
13486 +
13487 +
13488 +#ifdef __KERNEL__
13489 +
13490 +struct vx_info;
13491 +
13492 +int vx_info_kill(struct vx_info *, int, int);
13493 +
13494 +#endif /* __KERNEL__ */
13495 +#else  /* _VX_SIGNAL_H */
13496 +#warning duplicate inclusion
13497 +#endif /* _VX_SIGNAL_H */
13498 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/signal_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/signal_cmd.h
13499 --- linux-3.4.32/include/linux/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
13500 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/signal_cmd.h   2012-05-21 16:15:05.000000000 +0000
13501 @@ -0,0 +1,43 @@
13502 +#ifndef _VX_SIGNAL_CMD_H
13503 +#define _VX_SIGNAL_CMD_H
13504 +
13505 +
13506 +/*  signalling vserver commands */
13507 +
13508 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13509 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13510 +
13511 +struct vcmd_ctx_kill_v0 {
13512 +       int32_t pid;
13513 +       int32_t sig;
13514 +};
13515 +
13516 +struct vcmd_wait_exit_v0 {
13517 +       int32_t reboot_cmd;
13518 +       int32_t exit_code;
13519 +};
13520 +
13521 +#ifdef __KERNEL__
13522 +
13523 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13524 +extern int vc_wait_exit(struct vx_info *, void __user *);
13525 +
13526 +#endif /* __KERNEL__ */
13527 +
13528 +/*  process alteration commands */
13529 +
13530 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13531 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13532 +
13533 +struct vcmd_pflags_v0 {
13534 +       uint32_t flagword;
13535 +       uint32_t mask;
13536 +};
13537 +
13538 +#ifdef __KERNEL__
13539 +
13540 +extern int vc_get_pflags(uint32_t pid, void __user *);
13541 +extern int vc_set_pflags(uint32_t pid, void __user *);
13542 +
13543 +#endif /* __KERNEL__ */
13544 +#endif /* _VX_SIGNAL_CMD_H */
13545 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/space.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/space.h
13546 --- linux-3.4.32/include/linux/vserver/space.h  1970-01-01 00:00:00.000000000 +0000
13547 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/space.h        2012-05-21 16:15:05.000000000 +0000
13548 @@ -0,0 +1,12 @@
13549 +#ifndef _VX_SPACE_H
13550 +#define _VX_SPACE_H
13551 +
13552 +#include <linux/types.h>
13553 +
13554 +struct vx_info;
13555 +
13556 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13557 +
13558 +#else  /* _VX_SPACE_H */
13559 +#warning duplicate inclusion
13560 +#endif /* _VX_SPACE_H */
13561 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/space_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/space_cmd.h
13562 --- linux-3.4.32/include/linux/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
13563 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/space_cmd.h    2012-05-21 16:15:05.000000000 +0000
13564 @@ -0,0 +1,38 @@
13565 +#ifndef _VX_SPACE_CMD_H
13566 +#define _VX_SPACE_CMD_H
13567 +
13568 +
13569 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13570 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13571 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13572 +
13573 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13574 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13575 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13576 +
13577 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13578 +
13579 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13580 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13581 +
13582 +
13583 +struct vcmd_space_mask_v1 {
13584 +       uint64_t mask;
13585 +};
13586 +
13587 +struct vcmd_space_mask_v2 {
13588 +       uint64_t mask;
13589 +       uint32_t index;
13590 +};
13591 +
13592 +
13593 +#ifdef __KERNEL__
13594 +
13595 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13596 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13597 +extern int vc_enter_space(struct vx_info *, void __user *);
13598 +extern int vc_set_space(struct vx_info *, void __user *);
13599 +extern int vc_get_space_mask(void __user *, int);
13600 +
13601 +#endif /* __KERNEL__ */
13602 +#endif /* _VX_SPACE_CMD_H */
13603 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/switch.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/switch.h
13604 --- linux-3.4.32/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13605 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/switch.h       2012-05-21 16:15:05.000000000 +0000
13606 @@ -0,0 +1,98 @@
13607 +#ifndef _VX_SWITCH_H
13608 +#define _VX_SWITCH_H
13609 +
13610 +#include <linux/types.h>
13611 +
13612 +
13613 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13614 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13615 +#define VC_VERSION(c)          ((c) & 0xFFF)
13616 +
13617 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13618 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13619 +
13620 +/*
13621 +
13622 +  Syscall Matrix V2.8
13623 +
13624 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13625 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13626 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13627 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13628 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13629 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13630 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13631 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13632 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13633 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13634 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13635 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13636 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13637 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13638 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13639 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13640 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13641 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13642 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13643 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13644 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13645 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13646 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13647 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13648 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13649 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13650 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13651 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13652 +
13653 +*/
13654 +
13655 +#define VC_CAT_VERSION         0
13656 +
13657 +#define VC_CAT_VSETUP          1
13658 +#define VC_CAT_VHOST           2
13659 +
13660 +#define VC_CAT_DEVICE          6
13661 +
13662 +#define VC_CAT_VPROC           9
13663 +#define VC_CAT_PROCALT         10
13664 +#define VC_CAT_PROCMIG         11
13665 +#define VC_CAT_PROCTRL         12
13666 +
13667 +#define VC_CAT_SCHED           14
13668 +#define VC_CAT_MEMCTRL         20
13669 +
13670 +#define VC_CAT_VNET            25
13671 +#define VC_CAT_NETALT          26
13672 +#define VC_CAT_NETMIG          27
13673 +#define VC_CAT_NETCTRL         28
13674 +
13675 +#define VC_CAT_TAGMIG          35
13676 +#define VC_CAT_DLIMIT          36
13677 +#define VC_CAT_INODE           38
13678 +
13679 +#define VC_CAT_VSTAT           40
13680 +#define VC_CAT_VINFO           46
13681 +#define VC_CAT_EVENT           48
13682 +
13683 +#define VC_CAT_FLAGS           52
13684 +#define VC_CAT_VSPACE          54
13685 +#define VC_CAT_DEBUG           56
13686 +#define VC_CAT_RLIMIT          60
13687 +
13688 +#define VC_CAT_SYSTEST         61
13689 +#define VC_CAT_COMPAT          63
13690 +
13691 +/*  query version */
13692 +
13693 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13694 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13695 +
13696 +
13697 +#ifdef __KERNEL__
13698 +
13699 +#include <linux/errno.h>
13700 +
13701 +#endif /* __KERNEL__ */
13702 +
13703 +#endif /* _VX_SWITCH_H */
13704 +
13705 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/tag.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/tag.h
13706 --- linux-3.4.32/include/linux/vserver/tag.h    1970-01-01 00:00:00.000000000 +0000
13707 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/tag.h  2012-05-21 16:15:05.000000000 +0000
13708 @@ -0,0 +1,143 @@
13709 +#ifndef _DX_TAG_H
13710 +#define _DX_TAG_H
13711 +
13712 +#include <linux/types.h>
13713 +
13714 +
13715 +#define DX_TAG(in)     (IS_TAGGED(in))
13716 +
13717 +
13718 +#ifdef CONFIG_TAG_NFSD
13719 +#define DX_TAG_NFSD    1
13720 +#else
13721 +#define DX_TAG_NFSD    0
13722 +#endif
13723 +
13724 +
13725 +#ifdef CONFIG_TAGGING_NONE
13726 +
13727 +#define MAX_UID                0xFFFFFFFF
13728 +#define MAX_GID                0xFFFFFFFF
13729 +
13730 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13731 +
13732 +#define TAGINO_UID(cond, uid, tag)     (uid)
13733 +#define TAGINO_GID(cond, gid, tag)     (gid)
13734 +
13735 +#endif
13736 +
13737 +
13738 +#ifdef CONFIG_TAGGING_GID16
13739 +
13740 +#define MAX_UID                0xFFFFFFFF
13741 +#define MAX_GID                0x0000FFFF
13742 +
13743 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13744 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13745 +
13746 +#define TAGINO_UID(cond, uid, tag)     (uid)
13747 +#define TAGINO_GID(cond, gid, tag)     \
13748 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13749 +
13750 +#endif
13751 +
13752 +
13753 +#ifdef CONFIG_TAGGING_ID24
13754 +
13755 +#define MAX_UID                0x00FFFFFF
13756 +#define MAX_GID                0x00FFFFFF
13757 +
13758 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13759 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13760 +
13761 +#define TAGINO_UID(cond, uid, tag)     \
13762 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13763 +#define TAGINO_GID(cond, gid, tag)     \
13764 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13765 +
13766 +#endif
13767 +
13768 +
13769 +#ifdef CONFIG_TAGGING_UID16
13770 +
13771 +#define MAX_UID                0x0000FFFF
13772 +#define MAX_GID                0xFFFFFFFF
13773 +
13774 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13775 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13776 +
13777 +#define TAGINO_UID(cond, uid, tag)     \
13778 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13779 +#define TAGINO_GID(cond, gid, tag)     (gid)
13780 +
13781 +#endif
13782 +
13783 +
13784 +#ifdef CONFIG_TAGGING_INTERN
13785 +
13786 +#define MAX_UID                0xFFFFFFFF
13787 +#define MAX_GID                0xFFFFFFFF
13788 +
13789 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13790 +       ((cond) ? (tag) : 0)
13791 +
13792 +#define TAGINO_UID(cond, uid, tag)     (uid)
13793 +#define TAGINO_GID(cond, gid, tag)     (gid)
13794 +
13795 +#endif
13796 +
13797 +
13798 +#ifndef CONFIG_TAGGING_NONE
13799 +#define dx_current_fstag(sb)   \
13800 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13801 +#else
13802 +#define dx_current_fstag(sb)   (0)
13803 +#endif
13804 +
13805 +#ifndef CONFIG_TAGGING_INTERN
13806 +#define TAGINO_TAG(cond, tag)  (0)
13807 +#else
13808 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13809 +#endif
13810 +
13811 +#define INOTAG_UID(cond, uid, gid)     \
13812 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13813 +#define INOTAG_GID(cond, uid, gid)     \
13814 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13815 +
13816 +
13817 +static inline uid_t dx_map_uid(uid_t uid)
13818 +{
13819 +       if ((uid > MAX_UID) && (uid != -1))
13820 +               uid = -2;
13821 +       return (uid & MAX_UID);
13822 +}
13823 +
13824 +static inline gid_t dx_map_gid(gid_t gid)
13825 +{
13826 +       if ((gid > MAX_GID) && (gid != -1))
13827 +               gid = -2;
13828 +       return (gid & MAX_GID);
13829 +}
13830 +
13831 +struct peer_tag {
13832 +       int32_t xid;
13833 +       int32_t nid;
13834 +};
13835 +
13836 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13837 +
13838 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13839 +                unsigned long *flags);
13840 +
13841 +#ifdef CONFIG_PROPAGATE
13842 +
13843 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13844 +
13845 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13846 +
13847 +#else
13848 +#define dx_propagate_tag(n, i) do { } while (0)
13849 +#endif
13850 +
13851 +#endif /* _DX_TAG_H */
13852 diff -NurpP --minimal linux-3.4.32/include/linux/vserver/tag_cmd.h linux-3.4.32-vs2.3.3.9/include/linux/vserver/tag_cmd.h
13853 --- linux-3.4.32/include/linux/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
13854 +++ linux-3.4.32-vs2.3.3.9/include/linux/vserver/tag_cmd.h      2012-05-21 16:15:05.000000000 +0000
13855 @@ -0,0 +1,22 @@
13856 +#ifndef _VX_TAG_CMD_H
13857 +#define _VX_TAG_CMD_H
13858 +
13859 +
13860 +/* vinfo commands */
13861 +
13862 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13863 +
13864 +#ifdef __KERNEL__
13865 +extern int vc_task_tag(uint32_t);
13866 +
13867 +#endif /* __KERNEL__ */
13868 +
13869 +/* context commands */
13870 +
13871 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13872 +
13873 +#ifdef __KERNEL__
13874 +extern int vc_tag_migrate(uint32_t);
13875 +
13876 +#endif /* __KERNEL__ */
13877 +#endif /* _VX_TAG_CMD_H */
13878 diff -NurpP --minimal linux-3.4.32/include/net/addrconf.h linux-3.4.32-vs2.3.3.9/include/net/addrconf.h
13879 --- linux-3.4.32/include/net/addrconf.h 2012-05-21 16:07:33.000000000 +0000
13880 +++ linux-3.4.32-vs2.3.3.9/include/net/addrconf.h       2012-05-21 16:15:05.000000000 +0000
13881 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13882                                                struct net_device *dev,
13883                                                const struct in6_addr *daddr,
13884                                                unsigned int srcprefs,
13885 -                                              struct in6_addr *saddr);
13886 +                                              struct in6_addr *saddr,
13887 +                                              struct nx_info *nxi);
13888  extern int                     ipv6_get_lladdr(struct net_device *dev,
13889                                                 struct in6_addr *addr,
13890                                                 unsigned char banned_flags);
13891 diff -NurpP --minimal linux-3.4.32/include/net/af_unix.h linux-3.4.32-vs2.3.3.9/include/net/af_unix.h
13892 --- linux-3.4.32/include/net/af_unix.h  2012-05-21 16:07:33.000000000 +0000
13893 +++ linux-3.4.32-vs2.3.3.9/include/net/af_unix.h        2012-05-21 16:15:05.000000000 +0000
13894 @@ -4,6 +4,7 @@
13895  #include <linux/socket.h>
13896  #include <linux/un.h>
13897  #include <linux/mutex.h>
13898 +#include <linux/vs_base.h>
13899  #include <net/sock.h>
13900  
13901  extern void unix_inflight(struct file *fp);
13902 diff -NurpP --minimal linux-3.4.32/include/net/inet_timewait_sock.h linux-3.4.32-vs2.3.3.9/include/net/inet_timewait_sock.h
13903 --- linux-3.4.32/include/net/inet_timewait_sock.h       2012-03-19 18:47:29.000000000 +0000
13904 +++ linux-3.4.32-vs2.3.3.9/include/net/inet_timewait_sock.h     2012-05-21 16:15:05.000000000 +0000
13905 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13906  #define tw_net                 __tw_common.skc_net
13907  #define tw_daddr               __tw_common.skc_daddr
13908  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13909 +#define tw_xid                 __tw_common.skc_xid
13910 +#define tw_vx_info             __tw_common.skc_vx_info
13911 +#define tw_nid                 __tw_common.skc_nid
13912 +#define tw_nx_info             __tw_common.skc_nx_info
13913         int                     tw_timeout;
13914         volatile unsigned char  tw_substate;
13915         unsigned char           tw_rcv_wscale;
13916 diff -NurpP --minimal linux-3.4.32/include/net/ip6_route.h linux-3.4.32-vs2.3.3.9/include/net/ip6_route.h
13917 --- linux-3.4.32/include/net/ip6_route.h        2012-03-19 18:47:29.000000000 +0000
13918 +++ linux-3.4.32-vs2.3.3.9/include/net/ip6_route.h      2012-05-21 16:15:05.000000000 +0000
13919 @@ -88,7 +88,8 @@ extern int                    ip6_route_get_saddr(struct
13920                                                     struct rt6_info *rt,
13921                                                     const struct in6_addr *daddr,
13922                                                     unsigned int prefs,
13923 -                                                   struct in6_addr *saddr);
13924 +                                                   struct in6_addr *saddr,
13925 +                                                   struct nx_info *nxi);
13926  
13927  extern struct rt6_info         *rt6_lookup(struct net *net,
13928                                             const struct in6_addr *daddr,
13929 diff -NurpP --minimal linux-3.4.32/include/net/route.h linux-3.4.32-vs2.3.3.9/include/net/route.h
13930 --- linux-3.4.32/include/net/route.h    2012-03-19 18:47:29.000000000 +0000
13931 +++ linux-3.4.32-vs2.3.3.9/include/net/route.h  2012-05-21 16:15:05.000000000 +0000
13932 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13933                 dst_release(&rt->dst);
13934  }
13935  
13936 +#include <linux/vs_base.h>
13937 +#include <linux/vs_inet.h>
13938 +
13939  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13940  
13941  extern const __u8 ip_tos2prio[16];
13942 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13943                            protocol, flow_flags, dst, src, dport, sport);
13944  }
13945  
13946 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13947 +       struct flowi4 *);
13948 +
13949  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13950                                               __be32 dst, __be32 src, u32 tos,
13951                                               int oif, u8 protocol,
13952 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13953  {
13954         struct net *net = sock_net(sk);
13955         struct rtable *rt;
13956 +       struct nx_info *nx_info = current_nx_info();
13957  
13958         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13959                               sport, dport, sk, can_sleep);
13960  
13961 -       if (!dst || !src) {
13962 +       if (sk)
13963 +               nx_info = sk->sk_nx_info;
13964 +
13965 +       vxdprintk(VXD_CBIT(net, 4),
13966 +               "ip_route_connect(%p) %p,%p;%lx",
13967 +               sk, nx_info, sk->sk_socket,
13968 +               (sk->sk_socket?sk->sk_socket->flags:0));
13969 +
13970 +       rt = ip_v4_find_src(net, nx_info, fl4);
13971 +       if (IS_ERR(rt))
13972 +               return rt;
13973 +       ip_rt_put(rt);
13974 +
13975 +       if (!fl4->daddr || !fl4->saddr) {
13976                 rt = __ip_route_output_key(net, fl4);
13977                 if (IS_ERR(rt))
13978                         return rt;
13979 diff -NurpP --minimal linux-3.4.32/include/net/sock.h linux-3.4.32-vs2.3.3.9/include/net/sock.h
13980 --- linux-3.4.32/include/net/sock.h     2013-02-19 13:56:07.000000000 +0000
13981 +++ linux-3.4.32-vs2.3.3.9/include/net/sock.h   2012-10-22 13:09:53.000000000 +0000
13982 @@ -170,6 +170,10 @@ struct sock_common {
13983  #ifdef CONFIG_NET_NS
13984         struct net              *skc_net;
13985  #endif
13986 +       xid_t                   skc_xid;
13987 +       struct vx_info          *skc_vx_info;
13988 +       nid_t                   skc_nid;
13989 +       struct nx_info          *skc_nx_info;
13990         /*
13991          * fields between dontcopy_begin/dontcopy_end
13992          * are not copied in sock_copy()
13993 @@ -282,6 +286,10 @@ struct sock {
13994  #define sk_bind_node           __sk_common.skc_bind_node
13995  #define sk_prot                        __sk_common.skc_prot
13996  #define sk_net                 __sk_common.skc_net
13997 +#define sk_xid                 __sk_common.skc_xid
13998 +#define sk_vx_info             __sk_common.skc_vx_info
13999 +#define sk_nid                 __sk_common.skc_nid
14000 +#define sk_nx_info             __sk_common.skc_nx_info
14001         socket_lock_t           sk_lock;
14002         struct sk_buff_head     sk_receive_queue;
14003         /*
14004 diff -NurpP --minimal linux-3.4.32/init/Kconfig linux-3.4.32-vs2.3.3.9/init/Kconfig
14005 --- linux-3.4.32/init/Kconfig   2012-05-21 16:07:33.000000000 +0000
14006 +++ linux-3.4.32-vs2.3.3.9/init/Kconfig 2012-05-21 16:15:05.000000000 +0000
14007 @@ -579,6 +579,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14008  menuconfig CGROUPS
14009         boolean "Control Group support"
14010         depends on EVENTFD
14011 +       default y
14012         help
14013           This option adds support for grouping sets of processes together, for
14014           use with process control subsystems such as Cpusets, CFS, memory
14015 @@ -828,6 +829,7 @@ config IPC_NS
14016  config USER_NS
14017         bool "User namespace (EXPERIMENTAL)"
14018         depends on EXPERIMENTAL
14019 +       depends on VSERVER_DISABLED
14020         default y
14021         help
14022           This allows containers, i.e. vservers, to use user namespaces
14023 diff -NurpP --minimal linux-3.4.32/init/main.c linux-3.4.32-vs2.3.3.9/init/main.c
14024 --- linux-3.4.32/init/main.c    2013-02-19 13:56:08.000000000 +0000
14025 +++ linux-3.4.32-vs2.3.3.9/init/main.c  2013-02-19 14:42:56.000000000 +0000
14026 @@ -68,6 +68,7 @@
14027  #include <linux/shmem_fs.h>
14028  #include <linux/slab.h>
14029  #include <linux/perf_event.h>
14030 +#include <linux/vserver/percpu.h>
14031  
14032  #include <asm/io.h>
14033  #include <asm/bugs.h>
14034 diff -NurpP --minimal linux-3.4.32/ipc/mqueue.c linux-3.4.32-vs2.3.3.9/ipc/mqueue.c
14035 --- linux-3.4.32/ipc/mqueue.c   2012-05-21 16:07:34.000000000 +0000
14036 +++ linux-3.4.32-vs2.3.3.9/ipc/mqueue.c 2012-05-21 16:15:05.000000000 +0000
14037 @@ -34,6 +34,8 @@
14038  #include <linux/ipc_namespace.h>
14039  #include <linux/user_namespace.h>
14040  #include <linux/slab.h>
14041 +#include <linux/vs_context.h>
14042 +#include <linux/vs_limit.h>
14043  
14044  #include <net/sock.h>
14045  #include "util.h"
14046 @@ -67,6 +69,7 @@ struct mqueue_inode_info {
14047         struct sigevent notify;
14048         struct pid* notify_owner;
14049         struct user_struct *user;       /* user who created, for accounting */
14050 +       struct vx_info *vxi;
14051         struct sock *notify_sock;
14052         struct sk_buff *notify_cookie;
14053  
14054 @@ -129,6 +132,7 @@ static struct inode *mqueue_get_inode(st
14055         if (S_ISREG(mode)) {
14056                 struct mqueue_inode_info *info;
14057                 unsigned long mq_bytes, mq_msg_tblsz;
14058 +               struct vx_info *vxi = current_vx_info();
14059  
14060                 inode->i_fop = &mqueue_file_operations;
14061                 inode->i_size = FILENT_SIZE;
14062 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14063                 info->notify_owner = NULL;
14064                 info->qsize = 0;
14065                 info->user = NULL;      /* set when all is ok */
14066 +               info->vxi = NULL;
14067                 memset(&info->attr, 0, sizeof(info->attr));
14068                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14069                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14070 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14071  
14072                 spin_lock(&mq_lock);
14073                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14074 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
14075 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
14076 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14077                         spin_unlock(&mq_lock);
14078                         /* mqueue_evict_inode() releases info->messages */
14079                         ret = -EMFILE;
14080                         goto out_inode;
14081                 }
14082                 u->mq_bytes += mq_bytes;
14083 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14084                 spin_unlock(&mq_lock);
14085  
14086                 /* all is ok */
14087                 info->user = get_uid(u);
14088 +               info->vxi = get_vx_info(vxi);
14089         } else if (S_ISDIR(mode)) {
14090                 inc_nlink(inode);
14091                 /* Some things misbehave if size == 0 on a directory */
14092 @@ -267,8 +275,11 @@ static void mqueue_evict_inode(struct in
14093             + info->attr.mq_msgsize);
14094         user = info->user;
14095         if (user) {
14096 +               struct vx_info *vxi = info->vxi;
14097 +
14098                 spin_lock(&mq_lock);
14099                 user->mq_bytes -= mq_bytes;
14100 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14101                 /*
14102                  * get_ns_from_inode() ensures that the
14103                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14104 @@ -278,6 +289,7 @@ static void mqueue_evict_inode(struct in
14105                 if (ipc_ns)
14106                         ipc_ns->mq_queues_count--;
14107                 spin_unlock(&mq_lock);
14108 +               put_vx_info(vxi);
14109                 free_uid(user);
14110         }
14111         if (ipc_ns)
14112 diff -NurpP --minimal linux-3.4.32/ipc/msg.c linux-3.4.32-vs2.3.3.9/ipc/msg.c
14113 --- linux-3.4.32/ipc/msg.c      2011-05-22 14:17:59.000000000 +0000
14114 +++ linux-3.4.32-vs2.3.3.9/ipc/msg.c    2012-05-21 16:15:05.000000000 +0000
14115 @@ -37,6 +37,7 @@
14116  #include <linux/rwsem.h>
14117  #include <linux/nsproxy.h>
14118  #include <linux/ipc_namespace.h>
14119 +#include <linux/vs_base.h>
14120  
14121  #include <asm/current.h>
14122  #include <asm/uaccess.h>
14123 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14124  
14125         msq->q_perm.mode = msgflg & S_IRWXUGO;
14126         msq->q_perm.key = key;
14127 +       msq->q_perm.xid = vx_current_xid();
14128  
14129         msq->q_perm.security = NULL;
14130         retval = security_msg_queue_alloc(msq);
14131 diff -NurpP --minimal linux-3.4.32/ipc/namespace.c linux-3.4.32-vs2.3.3.9/ipc/namespace.c
14132 --- linux-3.4.32/ipc/namespace.c        2011-07-22 09:18:12.000000000 +0000
14133 +++ linux-3.4.32-vs2.3.3.9/ipc/namespace.c      2012-05-21 16:15:05.000000000 +0000
14134 @@ -13,11 +13,12 @@
14135  #include <linux/mount.h>
14136  #include <linux/user_namespace.h>
14137  #include <linux/proc_fs.h>
14138 +#include <linux/vs_base.h>
14139 +#include <linux/vserver/global.h>
14140  
14141  #include "util.h"
14142  
14143 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14144 -                                          struct ipc_namespace *old_ns)
14145 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14146  {
14147         struct ipc_namespace *ns;
14148         int err;
14149 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14150         ipcns_notify(IPCNS_CREATED);
14151         register_ipcns_notifier(ns);
14152  
14153 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14154 +       ns->user_ns = get_user_ns(user_ns);
14155  
14156         return ns;
14157  }
14158  
14159  struct ipc_namespace *copy_ipcs(unsigned long flags,
14160 -                               struct task_struct *tsk)
14161 +                               struct ipc_namespace *old_ns,
14162 +                               struct user_namespace *user_ns)
14163  {
14164 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14165 -
14166         if (!(flags & CLONE_NEWIPC))
14167 -               return get_ipc_ns(ns);
14168 -       return create_ipc_ns(tsk, ns);
14169 +               return get_ipc_ns(old_ns);
14170 +       return create_ipc_ns(user_ns);
14171  }
14172  
14173  /*
14174 diff -NurpP --minimal linux-3.4.32/ipc/sem.c linux-3.4.32-vs2.3.3.9/ipc/sem.c
14175 --- linux-3.4.32/ipc/sem.c      2012-01-09 15:14:59.000000000 +0000
14176 +++ linux-3.4.32-vs2.3.3.9/ipc/sem.c    2012-05-21 16:15:05.000000000 +0000
14177 @@ -86,6 +86,8 @@
14178  #include <linux/rwsem.h>
14179  #include <linux/nsproxy.h>
14180  #include <linux/ipc_namespace.h>
14181 +#include <linux/vs_base.h>
14182 +#include <linux/vs_limit.h>
14183  
14184  #include <asm/uaccess.h>
14185  #include "util.h"
14186 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14187  
14188         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14189         sma->sem_perm.key = key;
14190 +       sma->sem_perm.xid = vx_current_xid();
14191  
14192         sma->sem_perm.security = NULL;
14193         retval = security_sem_alloc(sma);
14194 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14195                 return id;
14196         }
14197         ns->used_sems += nsems;
14198 +       /* FIXME: obsoleted? */
14199 +       vx_semary_inc(sma);
14200 +       vx_nsems_add(sma, nsems);
14201  
14202         sma->sem_base = (struct sem *) &sma[1];
14203  
14204 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14205  
14206         wake_up_sem_queue_do(&tasks);
14207         ns->used_sems -= sma->sem_nsems;
14208 +       /* FIXME: obsoleted? */
14209 +       vx_nsems_sub(sma, sma->sem_nsems);
14210 +       vx_semary_dec(sma);
14211         security_sem_free(sma);
14212         ipc_rcu_putref(sma);
14213  }
14214 diff -NurpP --minimal linux-3.4.32/ipc/shm.c linux-3.4.32-vs2.3.3.9/ipc/shm.c
14215 --- linux-3.4.32/ipc/shm.c      2012-05-21 16:07:34.000000000 +0000
14216 +++ linux-3.4.32-vs2.3.3.9/ipc/shm.c    2012-05-21 16:15:05.000000000 +0000
14217 @@ -39,6 +39,8 @@
14218  #include <linux/nsproxy.h>
14219  #include <linux/mount.h>
14220  #include <linux/ipc_namespace.h>
14221 +#include <linux/vs_context.h>
14222 +#include <linux/vs_limit.h>
14223  
14224  #include <asm/uaccess.h>
14225  
14226 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14227   */
14228  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14229  {
14230 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14231 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14232 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14233 +
14234 +       vx_ipcshm_sub(vxi, shp, numpages);
14235 +       ns->shm_tot -= numpages;
14236 +
14237         shm_rmid(ns, shp);
14238         shm_unlock(shp);
14239         if (!is_file_hugepages(shp->shm_file))
14240 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14241                                                 shp->mlock_user);
14242         fput (shp->shm_file);
14243         security_shm_free(shp);
14244 +       put_vx_info(vxi);
14245         ipc_rcu_putref(shp);
14246  }
14247  
14248 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14249         if (ns->shm_tot + numpages > ns->shm_ctlall)
14250                 return -ENOSPC;
14251  
14252 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14253 +               return -ENOSPC;
14254 +
14255         shp = ipc_rcu_alloc(sizeof(*shp));
14256         if (!shp)
14257                 return -ENOMEM;
14258  
14259         shp->shm_perm.key = key;
14260 +       shp->shm_perm.xid = vx_current_xid();
14261         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14262         shp->mlock_user = NULL;
14263  
14264 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
14265         ns->shm_tot += numpages;
14266         error = shp->shm_perm.id;
14267         shm_unlock(shp);
14268 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14269         return error;
14270  
14271  no_id:
14272 diff -NurpP --minimal linux-3.4.32/kernel/Makefile linux-3.4.32-vs2.3.3.9/kernel/Makefile
14273 --- linux-3.4.32/kernel/Makefile        2012-05-21 16:07:34.000000000 +0000
14274 +++ linux-3.4.32-vs2.3.3.9/kernel/Makefile      2012-05-21 16:15:05.000000000 +0000
14275 @@ -25,6 +25,7 @@ endif
14276  obj-y += sched/
14277  obj-y += power/
14278  
14279 +obj-y += vserver/
14280  obj-$(CONFIG_FREEZER) += freezer.o
14281  obj-$(CONFIG_PROFILING) += profile.o
14282  obj-$(CONFIG_STACKTRACE) += stacktrace.o
14283 diff -NurpP --minimal linux-3.4.32/kernel/auditsc.c linux-3.4.32-vs2.3.3.9/kernel/auditsc.c
14284 --- linux-3.4.32/kernel/auditsc.c       2012-03-19 18:47:29.000000000 +0000
14285 +++ linux-3.4.32-vs2.3.3.9/kernel/auditsc.c     2012-05-21 16:15:05.000000000 +0000
14286 @@ -2308,7 +2308,7 @@ int audit_set_loginuid(uid_t loginuid)
14287         if (task->loginuid != -1)
14288                 return -EPERM;
14289  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14290 -       if (!capable(CAP_AUDIT_CONTROL))
14291 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14292                 return -EPERM;
14293  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14294  
14295 diff -NurpP --minimal linux-3.4.32/kernel/capability.c linux-3.4.32-vs2.3.3.9/kernel/capability.c
14296 --- linux-3.4.32/kernel/capability.c    2012-03-19 18:47:29.000000000 +0000
14297 +++ linux-3.4.32-vs2.3.3.9/kernel/capability.c  2012-05-21 16:15:05.000000000 +0000
14298 @@ -15,6 +15,7 @@
14299  #include <linux/syscalls.h>
14300  #include <linux/pid_namespace.h>
14301  #include <linux/user_namespace.h>
14302 +#include <linux/vs_context.h>
14303  #include <asm/uaccess.h>
14304  
14305  /*
14306 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14307         return 0;
14308  }
14309  
14310 +
14311  /*
14312   * The only thing that can change the capabilities of the current
14313   * process is the current process. As such, we can't be in this code
14314 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14315         return (ret == 0);
14316  }
14317  
14318 +#include <linux/vserver/base.h>
14319 +
14320  /**
14321   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14322   * initial user ns
14323 diff -NurpP --minimal linux-3.4.32/kernel/compat.c linux-3.4.32-vs2.3.3.9/kernel/compat.c
14324 --- linux-3.4.32/kernel/compat.c        2012-05-21 16:07:34.000000000 +0000
14325 +++ linux-3.4.32-vs2.3.3.9/kernel/compat.c      2012-05-21 16:15:05.000000000 +0000
14326 @@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14327         if (err)
14328                 return err;
14329  
14330 -       do_settimeofday(&tv);
14331 +       vx_settimeofday(&tv);
14332         return 0;
14333  }
14334  
14335 diff -NurpP --minimal linux-3.4.32/kernel/cred.c linux-3.4.32-vs2.3.3.9/kernel/cred.c
14336 --- linux-3.4.32/kernel/cred.c  2012-05-21 16:07:34.000000000 +0000
14337 +++ linux-3.4.32-vs2.3.3.9/kernel/cred.c        2012-05-21 16:15:05.000000000 +0000
14338 @@ -62,31 +62,6 @@ struct cred init_cred = {
14339  #endif
14340  };
14341  
14342 -static inline void set_cred_subscribers(struct cred *cred, int n)
14343 -{
14344 -#ifdef CONFIG_DEBUG_CREDENTIALS
14345 -       atomic_set(&cred->subscribers, n);
14346 -#endif
14347 -}
14348 -
14349 -static inline int read_cred_subscribers(const struct cred *cred)
14350 -{
14351 -#ifdef CONFIG_DEBUG_CREDENTIALS
14352 -       return atomic_read(&cred->subscribers);
14353 -#else
14354 -       return 0;
14355 -#endif
14356 -}
14357 -
14358 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14359 -{
14360 -#ifdef CONFIG_DEBUG_CREDENTIALS
14361 -       struct cred *cred = (struct cred *) _cred;
14362 -
14363 -       atomic_add(n, &cred->subscribers);
14364 -#endif
14365 -}
14366 -
14367  /*
14368   * Dispose of the shared task group credentials
14369   */
14370 @@ -282,21 +257,16 @@ error:
14371   *
14372   * Call commit_creds() or abort_creds() to clean up.
14373   */
14374 -struct cred *prepare_creds(void)
14375 +struct cred *__prepare_creds(const struct cred *old)
14376  {
14377 -       struct task_struct *task = current;
14378 -       const struct cred *old;
14379         struct cred *new;
14380  
14381 -       validate_process_creds();
14382 -
14383         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14384         if (!new)
14385                 return NULL;
14386  
14387         kdebug("prepare_creds() alloc %p", new);
14388  
14389 -       old = task->cred;
14390         memcpy(new, old, sizeof(struct cred));
14391  
14392         atomic_set(&new->usage, 1);
14393 @@ -323,6 +293,13 @@ error:
14394         abort_creds(new);
14395         return NULL;
14396  }
14397 +
14398 +struct cred *prepare_creds(void)
14399 +{
14400 +       validate_process_creds();
14401 +
14402 +       return __prepare_creds(current->cred);
14403 +}
14404  EXPORT_SYMBOL(prepare_creds);
14405  
14406  /*
14407 diff -NurpP --minimal linux-3.4.32/kernel/exit.c linux-3.4.32-vs2.3.3.9/kernel/exit.c
14408 --- linux-3.4.32/kernel/exit.c  2013-02-19 13:56:08.000000000 +0000
14409 +++ linux-3.4.32-vs2.3.3.9/kernel/exit.c        2012-12-08 00:54:06.000000000 +0000
14410 @@ -48,6 +48,10 @@
14411  #include <linux/fs_struct.h>
14412  #include <linux/init_task.h>
14413  #include <linux/perf_event.h>
14414 +#include <linux/vs_limit.h>
14415 +#include <linux/vs_context.h>
14416 +#include <linux/vs_network.h>
14417 +#include <linux/vs_pid.h>
14418  #include <trace/events/sched.h>
14419  #include <linux/hw_breakpoint.h>
14420  #include <linux/oom.h>
14421 @@ -482,9 +486,11 @@ static void close_files(struct files_str
14422                                         filp_close(file, files);
14423                                         cond_resched();
14424                                 }
14425 +                               vx_openfd_dec(i);
14426                         }
14427                         i++;
14428                         set >>= 1;
14429 +                       cond_resched();
14430                 }
14431         }
14432  }
14433 @@ -699,15 +705,25 @@ static struct task_struct *find_new_reap
14434         __acquires(&tasklist_lock)
14435  {
14436         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14437 -       struct task_struct *thread;
14438 +       struct vx_info *vxi = task_get_vx_info(father);
14439 +       struct task_struct *thread = father;
14440 +       struct task_struct *reaper;
14441  
14442 -       thread = father;
14443         while_each_thread(father, thread) {
14444                 if (thread->flags & PF_EXITING)
14445                         continue;
14446                 if (unlikely(pid_ns->child_reaper == father))
14447                         pid_ns->child_reaper = thread;
14448 -               return thread;
14449 +               reaper = thread;
14450 +               goto out_put;
14451 +       }
14452 +
14453 +       reaper = pid_ns->child_reaper;
14454 +       if (vxi) {
14455 +               BUG_ON(!vxi->vx_reaper);
14456 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14457 +                   vxi->vx_reaper != father)
14458 +                       reaper = vxi->vx_reaper;
14459         }
14460  
14461         if (unlikely(pid_ns->child_reaper == father)) {
14462 @@ -751,7 +767,9 @@ static struct task_struct *find_new_reap
14463                 }
14464         }
14465  
14466 -       return pid_ns->child_reaper;
14467 +out_put:
14468 +       put_vx_info(vxi);
14469 +       return reaper;
14470  }
14471  
14472  /*
14473 @@ -802,10 +820,15 @@ static void forget_original_parent(struc
14474         list_for_each_entry_safe(p, n, &father->children, sibling) {
14475                 struct task_struct *t = p;
14476                 do {
14477 -                       t->real_parent = reaper;
14478 +                       struct task_struct *new_parent = reaper;
14479 +
14480 +                       if (unlikely(p == reaper))
14481 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14482 +
14483 +                       t->real_parent = new_parent;
14484                         if (t->parent == father) {
14485                                 BUG_ON(t->ptrace);
14486 -                               t->parent = t->real_parent;
14487 +                               t->parent = new_parent;
14488                         }
14489                         if (t->pdeath_signal)
14490                                 group_send_sig_info(t->pdeath_signal,
14491 @@ -1013,6 +1036,9 @@ void do_exit(long code)
14492          */
14493         ptrace_put_breakpoints(tsk);
14494  
14495 +       /* needs to stay before exit_notify() */
14496 +       exit_vx_info_early(tsk, code);
14497 +
14498         exit_notify(tsk, group_dead);
14499  #ifdef CONFIG_NUMA
14500         task_lock(tsk);
14501 @@ -1063,10 +1089,15 @@ void do_exit(long code)
14502         smp_mb();
14503         raw_spin_unlock_wait(&tsk->pi_lock);
14504  
14505 +       /* needs to stay after exit_notify() */
14506 +       exit_vx_info(tsk, code);
14507 +       exit_nx_info(tsk);
14508 +
14509         /* causes final put_task_struct in finish_task_switch(). */
14510         tsk->state = TASK_DEAD;
14511         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14512         schedule();
14513 +       printk("bad task: %p [%lx]\n", current, current->state);
14514         BUG();
14515         /* Avoid "noreturn function does return".  */
14516         for (;;)
14517 diff -NurpP --minimal linux-3.4.32/kernel/fork.c linux-3.4.32-vs2.3.3.9/kernel/fork.c
14518 --- linux-3.4.32/kernel/fork.c  2013-02-19 13:56:08.000000000 +0000
14519 +++ linux-3.4.32-vs2.3.3.9/kernel/fork.c        2012-06-28 14:45:07.000000000 +0000
14520 @@ -68,6 +68,9 @@
14521  #include <linux/oom.h>
14522  #include <linux/khugepaged.h>
14523  #include <linux/signalfd.h>
14524 +#include <linux/vs_context.h>
14525 +#include <linux/vs_network.h>
14526 +#include <linux/vs_limit.h>
14527  
14528  #include <asm/pgtable.h>
14529  #include <asm/pgalloc.h>
14530 @@ -170,6 +173,8 @@ void free_task(struct task_struct *tsk)
14531         account_kernel_stack(tsk->stack, -1);
14532         free_thread_info(tsk->stack);
14533         rt_mutex_debug_task_free(tsk);
14534 +       clr_vx_info(&tsk->vx_info);
14535 +       clr_nx_info(&tsk->nx_info);
14536         ftrace_graph_exit_task(tsk);
14537         free_task_struct(tsk);
14538  }
14539 @@ -507,6 +512,7 @@ static struct mm_struct *mm_init(struct
14540         if (likely(!mm_alloc_pgd(mm))) {
14541                 mm->def_flags = 0;
14542                 mmu_notifier_mm_init(mm);
14543 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14544                 return mm;
14545         }
14546  
14547 @@ -559,6 +565,7 @@ void __mmdrop(struct mm_struct *mm)
14548         destroy_context(mm);
14549         mmu_notifier_mm_destroy(mm);
14550         check_mm(mm);
14551 +       clr_vx_info(&mm->mm_vx_info);
14552         free_mm(mm);
14553  }
14554  EXPORT_SYMBOL_GPL(__mmdrop);
14555 @@ -794,6 +801,7 @@ struct mm_struct *dup_mm(struct task_str
14556                 goto fail_nomem;
14557  
14558         memcpy(mm, oldmm, sizeof(*mm));
14559 +       mm->mm_vx_info = NULL;
14560         mm_init_cpumask(mm);
14561  
14562         /* Initializing for Swap token stuff */
14563 @@ -837,6 +845,7 @@ fail_nocontext:
14564          * If init_new_context() failed, we cannot use mmput() to free the mm
14565          * because it calls destroy_context()
14566          */
14567 +       clr_vx_info(&mm->mm_vx_info);
14568         mm_free_pgd(mm);
14569         free_mm(mm);
14570         return NULL;
14571 @@ -1125,6 +1134,8 @@ static struct task_struct *copy_process(
14572         int retval;
14573         struct task_struct *p;
14574         int cgroup_callbacks_done = 0;
14575 +       struct vx_info *vxi;
14576 +       struct nx_info *nxi;
14577  
14578         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14579                 return ERR_PTR(-EINVAL);
14580 @@ -1171,7 +1182,12 @@ static struct task_struct *copy_process(
14581         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14582         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14583  #endif
14584 +       init_vx_info(&p->vx_info, current_vx_info());
14585 +       init_nx_info(&p->nx_info, current_nx_info());
14586 +
14587         retval = -EAGAIN;
14588 +       if (!vx_nproc_avail(1))
14589 +               goto bad_fork_free;
14590         if (atomic_read(&p->real_cred->user->processes) >=
14591                         task_rlimit(p, RLIMIT_NPROC)) {
14592                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14593 @@ -1448,6 +1464,18 @@ static struct task_struct *copy_process(
14594  
14595         total_forks++;
14596         spin_unlock(&current->sighand->siglock);
14597 +
14598 +       /* p is copy of current */
14599 +       vxi = p->vx_info;
14600 +       if (vxi) {
14601 +               claim_vx_info(vxi, p);
14602 +               atomic_inc(&vxi->cvirt.nr_threads);
14603 +               atomic_inc(&vxi->cvirt.total_forks);
14604 +               vx_nproc_inc(p);
14605 +       }
14606 +       nxi = p->nx_info;
14607 +       if (nxi)
14608 +               claim_nx_info(nxi, p);
14609         write_unlock_irq(&tasklist_lock);
14610         proc_fork_connector(p);
14611         cgroup_post_fork(p);
14612 diff -NurpP --minimal linux-3.4.32/kernel/kthread.c linux-3.4.32-vs2.3.3.9/kernel/kthread.c
14613 --- linux-3.4.32/kernel/kthread.c       2013-02-19 13:56:08.000000000 +0000
14614 +++ linux-3.4.32-vs2.3.3.9/kernel/kthread.c     2012-10-22 13:09:53.000000000 +0000
14615 @@ -16,6 +16,7 @@
14616  #include <linux/mutex.h>
14617  #include <linux/slab.h>
14618  #include <linux/freezer.h>
14619 +#include <linux/vs_pid.h>
14620  #include <trace/events/sched.h>
14621  
14622  static DEFINE_SPINLOCK(kthread_create_lock);
14623 diff -NurpP --minimal linux-3.4.32/kernel/nsproxy.c linux-3.4.32-vs2.3.3.9/kernel/nsproxy.c
14624 --- linux-3.4.32/kernel/nsproxy.c       2012-01-09 15:15:00.000000000 +0000
14625 +++ linux-3.4.32-vs2.3.3.9/kernel/nsproxy.c     2012-05-21 16:15:05.000000000 +0000
14626 @@ -20,11 +20,14 @@
14627  #include <linux/mnt_namespace.h>
14628  #include <linux/utsname.h>
14629  #include <linux/pid_namespace.h>
14630 +#include <linux/vserver/global.h>
14631 +#include <linux/vserver/debug.h>
14632  #include <net/net_namespace.h>
14633  #include <linux/ipc_namespace.h>
14634  #include <linux/proc_fs.h>
14635  #include <linux/file.h>
14636  #include <linux/syscalls.h>
14637 +#include "../fs/mount.h"
14638  
14639  static struct kmem_cache *nsproxy_cachep;
14640  
14641 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14642         struct nsproxy *nsproxy;
14643  
14644         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14645 -       if (nsproxy)
14646 +       if (nsproxy) {
14647                 atomic_set(&nsproxy->count, 1);
14648 +               atomic_inc(&vs_global_nsproxy);
14649 +       }
14650 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14651         return nsproxy;
14652  }
14653  
14654 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14655   * Return the newly created nsproxy.  Do not attach this to the task,
14656   * leave it to the caller to do proper locking and attach it to task.
14657   */
14658 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14659 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14660 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14661 +                       struct nsproxy *orig,
14662 +                       struct fs_struct *new_fs,
14663 +                       struct user_namespace *new_user,
14664 +                       struct pid_namespace *new_pid)
14665  {
14666         struct nsproxy *new_nsp;
14667         int err;
14668 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14669         if (!new_nsp)
14670                 return ERR_PTR(-ENOMEM);
14671  
14672 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14673 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14674         if (IS_ERR(new_nsp->mnt_ns)) {
14675                 err = PTR_ERR(new_nsp->mnt_ns);
14676                 goto out_ns;
14677         }
14678  
14679 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14680 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14681         if (IS_ERR(new_nsp->uts_ns)) {
14682                 err = PTR_ERR(new_nsp->uts_ns);
14683                 goto out_uts;
14684         }
14685  
14686 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14687 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14688         if (IS_ERR(new_nsp->ipc_ns)) {
14689                 err = PTR_ERR(new_nsp->ipc_ns);
14690                 goto out_ipc;
14691         }
14692  
14693 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14694 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14695         if (IS_ERR(new_nsp->pid_ns)) {
14696                 err = PTR_ERR(new_nsp->pid_ns);
14697                 goto out_pid;
14698         }
14699  
14700 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14701 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14702         if (IS_ERR(new_nsp->net_ns)) {
14703                 err = PTR_ERR(new_nsp->net_ns);
14704                 goto out_net;
14705 @@ -115,6 +124,40 @@ out_ns:
14706         return ERR_PTR(err);
14707  }
14708  
14709 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14710 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14711 +{
14712 +       return unshare_namespaces(flags, tsk->nsproxy,
14713 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14714 +               task_active_pid_ns(tsk));
14715 +}
14716 +
14717 +/*
14718 + * copies the nsproxy, setting refcount to 1, and grabbing a
14719 + * reference to all contained namespaces.
14720 + */
14721 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14722 +{
14723 +       struct nsproxy *ns = create_nsproxy();
14724 +
14725 +       if (ns) {
14726 +               memcpy(ns, orig, sizeof(struct nsproxy));
14727 +               atomic_set(&ns->count, 1);
14728 +
14729 +               if (ns->mnt_ns)
14730 +                       get_mnt_ns(ns->mnt_ns);
14731 +               if (ns->uts_ns)
14732 +                       get_uts_ns(ns->uts_ns);
14733 +               if (ns->ipc_ns)
14734 +                       get_ipc_ns(ns->ipc_ns);
14735 +               if (ns->pid_ns)
14736 +                       get_pid_ns(ns->pid_ns);
14737 +               if (ns->net_ns)
14738 +                       get_net(ns->net_ns);
14739 +       }
14740 +       return ns;
14741 +}
14742 +
14743  /*
14744   * called from clone.  This now handles copy for nsproxy and all
14745   * namespaces therein.
14746 @@ -122,9 +165,12 @@ out_ns:
14747  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14748  {
14749         struct nsproxy *old_ns = tsk->nsproxy;
14750 -       struct nsproxy *new_ns;
14751 +       struct nsproxy *new_ns = NULL;
14752         int err = 0;
14753  
14754 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14755 +               flags, tsk, old_ns);
14756 +
14757         if (!old_ns)
14758                 return 0;
14759  
14760 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14761                                 CLONE_NEWPID | CLONE_NEWNET)))
14762                 return 0;
14763  
14764 -       if (!capable(CAP_SYS_ADMIN)) {
14765 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14766                 err = -EPERM;
14767                 goto out;
14768         }
14769 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14770  
14771  out:
14772         put_nsproxy(old_ns);
14773 +       vxdprintk(VXD_CBIT(space, 3),
14774 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14775 +               flags, tsk, old_ns, err, new_ns);
14776         return err;
14777  }
14778  
14779 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14780                 put_ipc_ns(ns->ipc_ns);
14781         if (ns->pid_ns)
14782                 put_pid_ns(ns->pid_ns);
14783 -       put_net(ns->net_ns);
14784 +       if (ns->net_ns)
14785 +               put_net(ns->net_ns);
14786 +       atomic_dec(&vs_global_nsproxy);
14787         kmem_cache_free(nsproxy_cachep, ns);
14788  }
14789  
14790 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned
14791  {
14792         int err = 0;
14793  
14794 +       vxdprintk(VXD_CBIT(space, 4),
14795 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14796 +               unshare_flags, current->nsproxy);
14797 +
14798         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14799                                CLONE_NEWNET)))
14800                 return 0;
14801  
14802 -       if (!capable(CAP_SYS_ADMIN))
14803 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14804                 return -EPERM;
14805  
14806         *new_nsp = create_new_namespaces(unshare_flags, current,
14807 diff -NurpP --minimal linux-3.4.32/kernel/pid.c linux-3.4.32-vs2.3.3.9/kernel/pid.c
14808 --- linux-3.4.32/kernel/pid.c   2012-03-19 18:47:30.000000000 +0000
14809 +++ linux-3.4.32-vs2.3.3.9/kernel/pid.c 2012-05-21 16:15:05.000000000 +0000
14810 @@ -36,6 +36,7 @@
14811  #include <linux/pid_namespace.h>
14812  #include <linux/init_task.h>
14813  #include <linux/syscalls.h>
14814 +#include <linux/vs_pid.h>
14815  
14816  #define pid_hashfn(nr, ns)     \
14817         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14818 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14819  
14820  struct pid *find_vpid(int nr)
14821  {
14822 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14823 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14824  }
14825  EXPORT_SYMBOL_GPL(find_vpid);
14826  
14827 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14828  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14829  {
14830         struct task_struct *result = NULL;
14831 +
14832 +       if (type == PIDTYPE_REALPID)
14833 +               type = PIDTYPE_PID;
14834         if (pid) {
14835                 struct hlist_node *first;
14836                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14837 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14838         rcu_lockdep_assert(rcu_read_lock_held(),
14839                            "find_task_by_pid_ns() needs rcu_read_lock()"
14840                            " protection");
14841 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14842 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14843  }
14844  
14845  struct task_struct *find_task_by_vpid(pid_t vnr)
14846 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14847  }
14848  EXPORT_SYMBOL_GPL(find_get_pid);
14849  
14850 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14851 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14852  {
14853         struct upid *upid;
14854         pid_t nr = 0;
14855 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14856         return nr;
14857  }
14858  
14859 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14860 +{
14861 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14862 +}
14863 +
14864  pid_t pid_vnr(struct pid *pid)
14865  {
14866         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14867 diff -NurpP --minimal linux-3.4.32/kernel/pid_namespace.c linux-3.4.32-vs2.3.3.9/kernel/pid_namespace.c
14868 --- linux-3.4.32/kernel/pid_namespace.c 2012-05-21 16:07:34.000000000 +0000
14869 +++ linux-3.4.32-vs2.3.3.9/kernel/pid_namespace.c       2012-05-21 16:15:05.000000000 +0000
14870 @@ -16,6 +16,7 @@
14871  #include <linux/slab.h>
14872  #include <linux/proc_fs.h>
14873  #include <linux/reboot.h>
14874 +#include <linux/vserver/global.h>
14875  
14876  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14877  
14878 @@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14879                 goto out_free_map;
14880  
14881         kref_init(&ns->kref);
14882 +       atomic_inc(&vs_global_pid_ns);
14883         ns->level = level;
14884         ns->parent = get_pid_ns(parent_pid_ns);
14885  
14886 @@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14887  
14888         for (i = 0; i < PIDMAP_ENTRIES; i++)
14889                 kfree(ns->pidmap[i].page);
14890 +       atomic_dec(&vs_global_pid_ns);
14891         kmem_cache_free(pid_ns_cachep, ns);
14892  }
14893  
14894 diff -NurpP --minimal linux-3.4.32/kernel/posix-timers.c linux-3.4.32-vs2.3.3.9/kernel/posix-timers.c
14895 --- linux-3.4.32/kernel/posix-timers.c  2012-01-09 15:15:00.000000000 +0000
14896 +++ linux-3.4.32-vs2.3.3.9/kernel/posix-timers.c        2012-05-21 16:15:05.000000000 +0000
14897 @@ -47,6 +47,7 @@
14898  #include <linux/wait.h>
14899  #include <linux/workqueue.h>
14900  #include <linux/export.h>
14901 +#include <linux/vs_context.h>
14902  
14903  /*
14904   * Management arrays for POSIX timers.  Timers are kept in slab memory
14905 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14906  {
14907         struct task_struct *task;
14908         int shared, ret = -1;
14909 +
14910         /*
14911          * FIXME: if ->sigq is queued we can race with
14912          * dequeue_signal()->do_schedule_next_timer().
14913 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14914         rcu_read_lock();
14915         task = pid_task(timr->it_pid, PIDTYPE_PID);
14916         if (task) {
14917 +               struct vx_info_save vxis;
14918 +               struct vx_info *vxi;
14919 +
14920 +               vxi = get_vx_info(task->vx_info);
14921 +               enter_vx_info(vxi, &vxis);
14922                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14923                 ret = send_sigqueue(timr->sigq, task, shared);
14924 +               leave_vx_info(&vxis);
14925 +               put_vx_info(vxi);
14926         }
14927         rcu_read_unlock();
14928 +
14929         /* If we failed to send the signal the timer stops. */
14930         return ret > 0;
14931  }
14932 diff -NurpP --minimal linux-3.4.32/kernel/printk.c linux-3.4.32-vs2.3.3.9/kernel/printk.c
14933 --- linux-3.4.32/kernel/printk.c        2012-05-21 16:07:34.000000000 +0000
14934 +++ linux-3.4.32-vs2.3.3.9/kernel/printk.c      2012-05-21 16:15:05.000000000 +0000
14935 @@ -41,6 +41,7 @@
14936  #include <linux/cpu.h>
14937  #include <linux/notifier.h>
14938  #include <linux/rculist.h>
14939 +#include <linux/vs_cvirt.h>
14940  
14941  #include <asm/uaccess.h>
14942  
14943 @@ -317,7 +318,7 @@ static int check_syslog_permissions(int
14944                 return 0;
14945  
14946         if (syslog_action_restricted(type)) {
14947 -               if (capable(CAP_SYSLOG))
14948 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14949                         return 0;
14950                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14951                 if (capable(CAP_SYS_ADMIN)) {
14952 @@ -347,12 +348,9 @@ int do_syslog(int type, char __user *buf
14953         if (error)
14954                 return error;
14955  
14956 -       switch (type) {
14957 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14958 -               break;
14959 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14960 -               break;
14961 -       case SYSLOG_ACTION_READ:        /* Read from log */
14962 +       if ((type == SYSLOG_ACTION_READ) ||
14963 +           (type == SYSLOG_ACTION_READ_ALL) ||
14964 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14965                 error = -EINVAL;
14966                 if (!buf || len < 0)
14967                         goto out;
14968 @@ -363,6 +361,16 @@ int do_syslog(int type, char __user *buf
14969                         error = -EFAULT;
14970                         goto out;
14971                 }
14972 +       }
14973 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14974 +               return vx_do_syslog(type, buf, len);
14975 +
14976 +       switch (type) {
14977 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14978 +               break;
14979 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14980 +               break;
14981 +       case SYSLOG_ACTION_READ:        /* Read from log */
14982                 error = wait_event_interruptible(log_wait,
14983                                                         (log_start - log_end));
14984                 if (error)
14985 @@ -389,16 +397,6 @@ int do_syslog(int type, char __user *buf
14986                 /* FALL THRU */
14987         /* Read last kernel messages */
14988         case SYSLOG_ACTION_READ_ALL:
14989 -               error = -EINVAL;
14990 -               if (!buf || len < 0)
14991 -                       goto out;
14992 -               error = 0;
14993 -               if (!len)
14994 -                       goto out;
14995 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14996 -                       error = -EFAULT;
14997 -                       goto out;
14998 -               }
14999                 count = len;
15000                 if (count > log_buf_len)
15001                         count = log_buf_len;
15002 diff -NurpP --minimal linux-3.4.32/kernel/ptrace.c linux-3.4.32-vs2.3.3.9/kernel/ptrace.c
15003 --- linux-3.4.32/kernel/ptrace.c        2013-02-19 13:56:08.000000000 +0000
15004 +++ linux-3.4.32-vs2.3.3.9/kernel/ptrace.c      2013-02-11 23:37:30.000000000 +0000
15005 @@ -22,6 +22,7 @@
15006  #include <linux/syscalls.h>
15007  #include <linux/uaccess.h>
15008  #include <linux/regset.h>
15009 +#include <linux/vs_context.h>
15010  #include <linux/hw_breakpoint.h>
15011  #include <linux/cn_proc.h>
15012  
15013 @@ -256,6 +257,11 @@ ok:
15014                 dumpable = get_dumpable(task->mm);
15015         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
15016                 return -EPERM;
15017 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15018 +               return -EPERM;
15019 +       if (!vx_check(task->xid, VS_IDENT) &&
15020 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15021 +               return -EACCES;
15022  
15023         return security_ptrace_access_check(task, mode);
15024  }
15025 diff -NurpP --minimal linux-3.4.32/kernel/sched/core.c linux-3.4.32-vs2.3.3.9/kernel/sched/core.c
15026 --- linux-3.4.32/kernel/sched/core.c    2013-02-19 13:56:09.000000000 +0000
15027 +++ linux-3.4.32-vs2.3.3.9/kernel/sched/core.c  2013-02-11 23:37:30.000000000 +0000
15028 @@ -72,6 +72,8 @@
15029  #include <linux/slab.h>
15030  #include <linux/init_task.h>
15031  #include <linux/binfmts.h>
15032 +#include <linux/vs_sched.h>
15033 +#include <linux/vs_cvirt.h>
15034  
15035  #include <asm/switch_to.h>
15036  #include <asm/tlb.h>
15037 @@ -2226,9 +2228,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
15038   */
15039  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15040  {
15041 -       loads[0] = (avenrun[0] + offset) << shift;
15042 -       loads[1] = (avenrun[1] + offset) << shift;
15043 -       loads[2] = (avenrun[2] + offset) << shift;
15044 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15045 +               struct vx_info *vxi = current_vx_info();
15046 +
15047 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15048 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15049 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15050 +       } else {
15051 +               loads[0] = (avenrun[0] + offset) << shift;
15052 +               loads[1] = (avenrun[1] + offset) << shift;
15053 +               loads[2] = (avenrun[2] + offset) << shift;
15054 +       }
15055  }
15056  
15057  static long calc_load_fold_active(struct rq *this_rq)
15058 @@ -2797,14 +2807,17 @@ static inline void task_group_account_fi
15059  void account_user_time(struct task_struct *p, cputime_t cputime,
15060                        cputime_t cputime_scaled)
15061  {
15062 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15063 +       int nice = (TASK_NICE(p) > 0);
15064         int index;
15065  
15066         /* Add user time to process. */
15067         p->utime += cputime;
15068         p->utimescaled += cputime_scaled;
15069 +       vx_account_user(vxi, cputime, nice);
15070         account_group_user_time(p, cputime);
15071  
15072 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
15073 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
15074  
15075         /* Add user time to cpustat. */
15076         task_group_account_field(p, index, (__force u64) cputime);
15077 @@ -2851,9 +2864,12 @@ static inline
15078  void __account_system_time(struct task_struct *p, cputime_t cputime,
15079                         cputime_t cputime_scaled, int index)
15080  {
15081 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15082 +
15083         /* Add system time to process. */
15084         p->stime += cputime;
15085         p->stimescaled += cputime_scaled;
15086 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15087         account_group_system_time(p, cputime);
15088  
15089         /* Add system time to cpustat. */
15090 @@ -4079,7 +4095,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15091                 nice = 19;
15092  
15093         if (increment < 0 && !can_nice(current, nice))
15094 -               return -EPERM;
15095 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15096  
15097         retval = security_task_setnice(current, nice);
15098         if (retval)
15099 diff -NurpP --minimal linux-3.4.32/kernel/sched/fair.c linux-3.4.32-vs2.3.3.9/kernel/sched/fair.c
15100 --- linux-3.4.32/kernel/sched/fair.c    2012-05-21 16:07:34.000000000 +0000
15101 +++ linux-3.4.32-vs2.3.3.9/kernel/sched/fair.c  2012-05-21 16:15:05.000000000 +0000
15102 @@ -26,6 +26,7 @@
15103  #include <linux/slab.h>
15104  #include <linux/profile.h>
15105  #include <linux/interrupt.h>
15106 +#include <linux/vs_cvirt.h>
15107  
15108  #include <trace/events/sched.h>
15109  
15110 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15111                 __enqueue_entity(cfs_rq, se);
15112         se->on_rq = 1;
15113  
15114 +       if (entity_is_task(se))
15115 +               vx_activate_task(task_of(se));
15116         if (cfs_rq->nr_running == 1) {
15117                 list_add_leaf_cfs_rq(cfs_rq);
15118                 check_enqueue_throttle(cfs_rq);
15119 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15120         if (se != cfs_rq->curr)
15121                 __dequeue_entity(cfs_rq, se);
15122         se->on_rq = 0;
15123 +       if (entity_is_task(se))
15124 +               vx_deactivate_task(task_of(se));
15125         update_cfs_load(cfs_rq, 0);
15126         account_entity_dequeue(cfs_rq, se);
15127  
15128 diff -NurpP --minimal linux-3.4.32/kernel/signal.c linux-3.4.32-vs2.3.3.9/kernel/signal.c
15129 --- linux-3.4.32/kernel/signal.c        2013-02-19 13:56:09.000000000 +0000
15130 +++ linux-3.4.32-vs2.3.3.9/kernel/signal.c      2013-02-11 23:37:30.000000000 +0000
15131 @@ -29,6 +29,8 @@
15132  #include <linux/pid_namespace.h>
15133  #include <linux/nsproxy.h>
15134  #include <linux/user_namespace.h>
15135 +#include <linux/vs_context.h>
15136 +#include <linux/vs_pid.h>
15137  #define CREATE_TRACE_POINTS
15138  #include <trace/events/signal.h>
15139  
15140 @@ -784,9 +786,18 @@ static int check_kill_permission(int sig
15141         struct pid *sid;
15142         int error;
15143  
15144 +       vxdprintk(VXD_CBIT(misc, 7),
15145 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15146 +               sig, info, t, vx_task_xid(t), t->pid);
15147 +
15148         if (!valid_signal(sig))
15149                 return -EINVAL;
15150  
15151 +/*     FIXME: needed? if so, why?
15152 +       if ((info != SEND_SIG_NOINFO) &&
15153 +               (is_si_special(info) || !si_fromuser(info)))
15154 +               goto skip;      */
15155 +
15156         if (!si_fromuser(info))
15157                 return 0;
15158  
15159 @@ -810,6 +821,20 @@ static int check_kill_permission(int sig
15160                 }
15161         }
15162  
15163 +       error = -EPERM;
15164 +       if (t->pid == 1 && current->xid)
15165 +               return error;
15166 +
15167 +       error = -ESRCH;
15168 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15169 +                 loops, maybe ENOENT or EACCES? */
15170 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15171 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15172 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15173 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15174 +               return error;
15175 +       }
15176 +/* skip: */
15177         return security_task_kill(t, info, sig, 0);
15178  }
15179  
15180 @@ -1352,7 +1377,7 @@ int kill_pid_info(int sig, struct siginf
15181         rcu_read_lock();
15182  retry:
15183         p = pid_task(pid, PIDTYPE_PID);
15184 -       if (p) {
15185 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15186                 error = group_send_sig_info(sig, info, p);
15187                 if (unlikely(error == -ESRCH))
15188                         /*
15189 @@ -1402,7 +1427,7 @@ int kill_pid_info_as_cred(int sig, struc
15190  
15191         rcu_read_lock();
15192         p = pid_task(pid, PIDTYPE_PID);
15193 -       if (!p) {
15194 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15195                 ret = -ESRCH;
15196                 goto out_unlock;
15197         }
15198 @@ -1454,8 +1479,10 @@ static int kill_something_info(int sig,
15199                 struct task_struct * p;
15200  
15201                 for_each_process(p) {
15202 -                       if (task_pid_vnr(p) > 1 &&
15203 -                                       !same_thread_group(p, current)) {
15204 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15205 +                               task_pid_vnr(p) > 1 &&
15206 +                               !same_thread_group(p, current) &&
15207 +                               !vx_current_initpid(p->pid)) {
15208                                 int err = group_send_sig_info(sig, info, p);
15209                                 ++count;
15210                                 if (err != -EPERM)
15211 @@ -2309,6 +2336,11 @@ relock:
15212                                 !sig_kernel_only(signr))
15213                         continue;
15214  
15215 +               /* virtual init is protected against user signals */
15216 +               if ((info->si_code == SI_USER) &&
15217 +                       vx_current_initpid(current->pid))
15218 +                       continue;
15219 +
15220                 if (sig_kernel_stop(signr)) {
15221                         /*
15222                          * The default action is to stop all threads in
15223 diff -NurpP --minimal linux-3.4.32/kernel/softirq.c linux-3.4.32-vs2.3.3.9/kernel/softirq.c
15224 --- linux-3.4.32/kernel/softirq.c       2012-05-21 16:07:34.000000000 +0000
15225 +++ linux-3.4.32-vs2.3.3.9/kernel/softirq.c     2012-05-21 16:15:05.000000000 +0000
15226 @@ -24,6 +24,7 @@
15227  #include <linux/ftrace.h>
15228  #include <linux/smp.h>
15229  #include <linux/tick.h>
15230 +#include <linux/vs_context.h>
15231  
15232  #define CREATE_TRACE_POINTS
15233  #include <trace/events/irq.h>
15234 diff -NurpP --minimal linux-3.4.32/kernel/sys.c linux-3.4.32-vs2.3.3.9/kernel/sys.c
15235 --- linux-3.4.32/kernel/sys.c   2013-02-19 13:56:09.000000000 +0000
15236 +++ linux-3.4.32-vs2.3.3.9/kernel/sys.c 2012-11-06 17:02:35.000000000 +0000
15237 @@ -45,6 +45,7 @@
15238  #include <linux/syscalls.h>
15239  #include <linux/kprobes.h>
15240  #include <linux/user_namespace.h>
15241 +#include <linux/vs_pid.h>
15242  
15243  #include <linux/kmsg_dump.h>
15244  /* Move somewhere else to avoid recompiling? */
15245 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15246                 goto out;
15247         }
15248         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15249 -               error = -EACCES;
15250 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15251 +                       error = 0;
15252 +               else
15253 +                       error = -EACCES;
15254                 goto out;
15255         }
15256         no_nice = security_task_setnice(p, niceval);
15257 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15258                         else
15259                                 pgrp = task_pgrp(current);
15260                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15261 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15262 +                                       continue;
15263                                 error = set_one_prio(p, niceval, error);
15264                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15265                         break;
15266 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15267                         else
15268                                 pgrp = task_pgrp(current);
15269                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15270 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15271 +                                       continue;
15272                                 niceval = 20 - task_nice(p);
15273                                 if (niceval > retval)
15274                                         retval = niceval;
15275 @@ -419,6 +427,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15276  
15277  static DEFINE_MUTEX(reboot_mutex);
15278  
15279 +long vs_reboot(unsigned int, void __user *);
15280 +
15281  /*
15282   * Reboot system call: for obvious reasons only root may call it,
15283   * and even root needs to set up some magic numbers in the registers
15284 @@ -460,6 +470,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15285         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15286                 cmd = LINUX_REBOOT_CMD_HALT;
15287  
15288 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15289 +               return vs_reboot(cmd, arg);
15290 +
15291         mutex_lock(&reboot_mutex);
15292         switch (cmd) {
15293         case LINUX_REBOOT_CMD_RESTART:
15294 @@ -1285,7 +1298,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15295         int errno;
15296         char tmp[__NEW_UTS_LEN];
15297  
15298 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15299 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15300 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15301                 return -EPERM;
15302  
15303         if (len < 0 || len > __NEW_UTS_LEN)
15304 @@ -1336,7 +1350,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15305         int errno;
15306         char tmp[__NEW_UTS_LEN];
15307  
15308 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15309 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15310 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15311                 return -EPERM;
15312         if (len < 0 || len > __NEW_UTS_LEN)
15313                 return -EINVAL;
15314 @@ -1455,7 +1470,7 @@ int do_prlimit(struct task_struct *tsk,
15315                 /* Keep the capable check against init_user_ns until
15316                    cgroups can contain all limits */
15317                 if (new_rlim->rlim_max > rlim->rlim_max &&
15318 -                               !capable(CAP_SYS_RESOURCE))
15319 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15320                         retval = -EPERM;
15321                 if (!retval)
15322                         retval = security_task_setrlimit(tsk->group_leader,
15323 @@ -1509,7 +1524,8 @@ static int check_prlimit_permission(stru
15324              cred->gid == tcred->sgid &&
15325              cred->gid == tcred->gid))
15326                 return 0;
15327 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15328 +       if (vx_ns_capable(tcred->user->user_ns,
15329 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15330                 return 0;
15331  
15332         return -EPERM;
15333 diff -NurpP --minimal linux-3.4.32/kernel/sysctl.c linux-3.4.32-vs2.3.3.9/kernel/sysctl.c
15334 --- linux-3.4.32/kernel/sysctl.c        2012-05-21 16:07:34.000000000 +0000
15335 +++ linux-3.4.32-vs2.3.3.9/kernel/sysctl.c      2012-05-21 16:15:05.000000000 +0000
15336 @@ -81,6 +81,7 @@
15337  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15338  #include <linux/lockdep.h>
15339  #endif
15340 +extern char vshelper_path[];
15341  #ifdef CONFIG_CHR_DEV_SG
15342  #include <scsi/sg.h>
15343  #endif
15344 @@ -562,6 +563,13 @@ static struct ctl_table kern_table[] = {
15345                 .proc_handler   = proc_dostring,
15346         },
15347  #endif
15348 +       {
15349 +               .procname       = "vshelper",
15350 +               .data           = &vshelper_path,
15351 +               .maxlen         = 256,
15352 +               .mode           = 0644,
15353 +               .proc_handler   = &proc_dostring,
15354 +       },
15355  #ifdef CONFIG_CHR_DEV_SG
15356         {
15357                 .procname       = "sg-big-buff",
15358 diff -NurpP --minimal linux-3.4.32/kernel/sysctl_binary.c linux-3.4.32-vs2.3.3.9/kernel/sysctl_binary.c
15359 --- linux-3.4.32/kernel/sysctl_binary.c 2012-01-09 15:15:00.000000000 +0000
15360 +++ linux-3.4.32-vs2.3.3.9/kernel/sysctl_binary.c       2012-05-21 16:15:05.000000000 +0000
15361 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15362  
15363         { CTL_INT,      KERN_PANIC,                     "panic" },
15364         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15365 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15366  
15367         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15368         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15369 diff -NurpP --minimal linux-3.4.32/kernel/time/timekeeping.c linux-3.4.32-vs2.3.3.9/kernel/time/timekeeping.c
15370 --- linux-3.4.32/kernel/time/timekeeping.c      2013-02-19 13:56:09.000000000 +0000
15371 +++ linux-3.4.32-vs2.3.3.9/kernel/time/timekeeping.c    2012-12-08 00:53:53.000000000 +0000
15372 @@ -254,6 +254,7 @@ void getnstimeofday(struct timespec *ts)
15373         } while (read_seqretry(&timekeeper.lock, seq));
15374  
15375         timespec_add_ns(ts, nsecs);
15376 +       vx_adjust_timespec(ts);
15377  }
15378  
15379  EXPORT_SYMBOL(getnstimeofday);
15380 diff -NurpP --minimal linux-3.4.32/kernel/time.c linux-3.4.32-vs2.3.3.9/kernel/time.c
15381 --- linux-3.4.32/kernel/time.c  2012-05-21 16:07:34.000000000 +0000
15382 +++ linux-3.4.32-vs2.3.3.9/kernel/time.c        2012-05-21 16:15:05.000000000 +0000
15383 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15384         if (err)
15385                 return err;
15386  
15387 -       do_settimeofday(&tv);
15388 +       vx_settimeofday(&tv);
15389         return 0;
15390  }
15391  
15392 @@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15393                 }
15394         }
15395         if (tv)
15396 -               return do_settimeofday(tv);
15397 +               return vx_settimeofday(tv);
15398         return 0;
15399  }
15400  
15401 diff -NurpP --minimal linux-3.4.32/kernel/timer.c linux-3.4.32-vs2.3.3.9/kernel/timer.c
15402 --- linux-3.4.32/kernel/timer.c 2013-02-19 13:56:09.000000000 +0000
15403 +++ linux-3.4.32-vs2.3.3.9/kernel/timer.c       2012-10-22 13:09:53.000000000 +0000
15404 @@ -40,6 +40,10 @@
15405  #include <linux/irq_work.h>
15406  #include <linux/sched.h>
15407  #include <linux/slab.h>
15408 +#include <linux/vs_base.h>
15409 +#include <linux/vs_cvirt.h>
15410 +#include <linux/vs_pid.h>
15411 +#include <linux/vserver/sched.h>
15412  
15413  #include <asm/uaccess.h>
15414  #include <asm/unistd.h>
15415 @@ -1388,12 +1392,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15416  
15417  #endif
15418  
15419 -#ifndef __alpha__
15420 -
15421 -/*
15422 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15423 - * should be moved into arch/i386 instead?
15424 - */
15425  
15426  /**
15427   * sys_getpid - return the thread group id of the current process
15428 @@ -1422,10 +1420,23 @@ SYSCALL_DEFINE0(getppid)
15429         rcu_read_lock();
15430         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
15431         rcu_read_unlock();
15432 +       return vx_map_pid(pid);
15433 +}
15434  
15435 -       return pid;
15436 +#ifdef __alpha__
15437 +
15438 +/*
15439 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15440 + */
15441 +
15442 +asmlinkage long do_getxpid(long *ppid)
15443 +{
15444 +       *ppid = sys_getppid();
15445 +       return sys_getpid();
15446  }
15447  
15448 +#else /* _alpha_ */
15449 +
15450  SYSCALL_DEFINE0(getuid)
15451  {
15452         /* Only we change this so SMP safe */
15453 diff -NurpP --minimal linux-3.4.32/kernel/user_namespace.c linux-3.4.32-vs2.3.3.9/kernel/user_namespace.c
15454 --- linux-3.4.32/kernel/user_namespace.c        2012-01-09 15:15:00.000000000 +0000
15455 +++ linux-3.4.32-vs2.3.3.9/kernel/user_namespace.c      2012-05-21 16:15:05.000000000 +0000
15456 @@ -11,6 +11,7 @@
15457  #include <linux/user_namespace.h>
15458  #include <linux/highuid.h>
15459  #include <linux/cred.h>
15460 +#include <linux/vserver/global.h>
15461  
15462  static struct kmem_cache *user_ns_cachep __read_mostly;
15463  
15464 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15465                 return -ENOMEM;
15466  
15467         kref_init(&ns->kref);
15468 +       atomic_inc(&vs_global_user_ns);
15469  
15470         for (n = 0; n < UIDHASH_SZ; ++n)
15471                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15472 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15473         struct user_namespace *ns =
15474                 container_of(kref, struct user_namespace, kref);
15475  
15476 +       /* FIXME: maybe move into destroyer? */
15477 +       atomic_dec(&vs_global_user_ns);
15478         INIT_WORK(&ns->destroyer, free_user_ns_work);
15479         schedule_work(&ns->destroyer);
15480  }
15481 diff -NurpP --minimal linux-3.4.32/kernel/utsname.c linux-3.4.32-vs2.3.3.9/kernel/utsname.c
15482 --- linux-3.4.32/kernel/utsname.c       2012-01-09 15:15:00.000000000 +0000
15483 +++ linux-3.4.32-vs2.3.3.9/kernel/utsname.c     2012-05-21 16:15:05.000000000 +0000
15484 @@ -16,14 +16,17 @@
15485  #include <linux/slab.h>
15486  #include <linux/user_namespace.h>
15487  #include <linux/proc_fs.h>
15488 +#include <linux/vserver/global.h>
15489  
15490  static struct uts_namespace *create_uts_ns(void)
15491  {
15492         struct uts_namespace *uts_ns;
15493  
15494         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15495 -       if (uts_ns)
15496 +       if (uts_ns) {
15497                 kref_init(&uts_ns->kref);
15498 +               atomic_inc(&vs_global_uts_ns);
15499 +       }
15500         return uts_ns;
15501  }
15502  
15503 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15504   * @old_ns: namespace to clone
15505   * Return NULL on error (failure to kmalloc), new ns otherwise
15506   */
15507 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15508 -                                         struct uts_namespace *old_ns)
15509 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15510 +                                         struct user_namespace *old_user)
15511  {
15512         struct uts_namespace *ns;
15513  
15514 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15515  
15516         down_read(&uts_sem);
15517         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15518 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15519 +       ns->user_ns = get_user_ns(old_user);
15520         up_read(&uts_sem);
15521         return ns;
15522  }
15523 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15524   * versa.
15525   */
15526  struct uts_namespace *copy_utsname(unsigned long flags,
15527 -                                  struct task_struct *tsk)
15528 +                                  struct uts_namespace *old_ns,
15529 +                                  struct user_namespace *user_ns)
15530  {
15531 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15532         struct uts_namespace *new_ns;
15533  
15534         BUG_ON(!old_ns);
15535 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15536         if (!(flags & CLONE_NEWUTS))
15537                 return old_ns;
15538  
15539 -       new_ns = clone_uts_ns(tsk, old_ns);
15540 +       new_ns = clone_uts_ns(old_ns, user_ns);
15541  
15542         put_uts_ns(old_ns);
15543         return new_ns;
15544 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15545  
15546         ns = container_of(kref, struct uts_namespace, kref);
15547         put_user_ns(ns->user_ns);
15548 +       atomic_dec(&vs_global_uts_ns);
15549         kfree(ns);
15550  }
15551  
15552 diff -NurpP --minimal linux-3.4.32/kernel/vserver/Kconfig linux-3.4.32-vs2.3.3.9/kernel/vserver/Kconfig
15553 --- linux-3.4.32/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
15554 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/Kconfig       2012-05-21 16:15:05.000000000 +0000
15555 @@ -0,0 +1,224 @@
15556 +#
15557 +# Linux VServer configuration
15558 +#
15559 +
15560 +menu "Linux VServer"
15561 +
15562 +config VSERVER_AUTO_LBACK
15563 +       bool    "Automatically Assign Loopback IP"
15564 +       default y
15565 +       help
15566 +         Automatically assign a guest specific loopback
15567 +         IP and add it to the kernel network stack on
15568 +         startup.
15569 +
15570 +config VSERVER_AUTO_SINGLE
15571 +       bool    "Automatic Single IP Special Casing"
15572 +       depends on EXPERIMENTAL
15573 +       default y
15574 +       help
15575 +         This allows network contexts with a single IP to
15576 +         automatically remap 0.0.0.0 bindings to that IP,
15577 +         avoiding further network checks and improving
15578 +         performance.
15579 +
15580 +         (note: such guests do not allow to change the ip
15581 +          on the fly and do not show loopback addresses)
15582 +
15583 +config VSERVER_COWBL
15584 +       bool    "Enable COW Immutable Link Breaking"
15585 +       default y
15586 +       help
15587 +         This enables the COW (Copy-On-Write) link break code.
15588 +         It allows you to treat unified files like normal files
15589 +         when writing to them (which will implicitely break the
15590 +         link and create a copy of the unified file)
15591 +
15592 +config VSERVER_VTIME
15593 +       bool    "Enable Virtualized Guest Time"
15594 +       depends on EXPERIMENTAL
15595 +       default n
15596 +       help
15597 +         This enables per guest time offsets to allow for
15598 +         adjusting the system clock individually per guest.
15599 +         this adds some overhead to the time functions and
15600 +         therefore should not be enabled without good reason.
15601 +
15602 +config VSERVER_DEVICE
15603 +       bool    "Enable Guest Device Mapping"
15604 +       depends on EXPERIMENTAL
15605 +       default n
15606 +       help
15607 +         This enables generic device remapping.
15608 +
15609 +config VSERVER_PROC_SECURE
15610 +       bool    "Enable Proc Security"
15611 +       depends on PROC_FS
15612 +       default y
15613 +       help
15614 +         This configures ProcFS security to initially hide
15615 +         non-process entries for all contexts except the main and
15616 +         spectator context (i.e. for all guests), which is a secure
15617 +         default.
15618 +
15619 +         (note: on 1.2x the entries were visible by default)
15620 +
15621 +choice
15622 +       prompt  "Persistent Inode Tagging"
15623 +       default TAGGING_ID24
15624 +       help
15625 +         This adds persistent context information to filesystems
15626 +         mounted with the tagxid option. Tagging is a requirement
15627 +         for per-context disk limits and per-context quota.
15628 +
15629 +
15630 +config TAGGING_NONE
15631 +       bool    "Disabled"
15632 +       help
15633 +         do not store per-context information in inodes.
15634 +
15635 +config TAGGING_UID16
15636 +       bool    "UID16/GID32"
15637 +       help
15638 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15639 +
15640 +config TAGGING_GID16
15641 +       bool    "UID32/GID16"
15642 +       help
15643 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15644 +
15645 +config TAGGING_ID24
15646 +       bool    "UID24/GID24"
15647 +       help
15648 +         uses the upper 8bit from UID and GID for XID tagging
15649 +         which leaves 24bit for UID/GID each, which should be
15650 +         more than sufficient for normal use.
15651 +
15652 +config TAGGING_INTERN
15653 +       bool    "UID32/GID32"
15654 +       help
15655 +         this uses otherwise reserved inode fields in the on
15656 +         disk representation, which limits the use to a few
15657 +         filesystems (currently ext2 and ext3)
15658 +
15659 +endchoice
15660 +
15661 +config TAG_NFSD
15662 +       bool    "Tag NFSD User Auth and Files"
15663 +       default n
15664 +       help
15665 +         Enable this if you do want the in-kernel NFS
15666 +         Server to use the tagging specified above.
15667 +         (will require patched clients too)
15668 +
15669 +config VSERVER_PRIVACY
15670 +       bool    "Honor Privacy Aspects of Guests"
15671 +       default n
15672 +       help
15673 +         When enabled, most context checks will disallow
15674 +         access to structures assigned to a specific context,
15675 +         like ptys or loop devices.
15676 +
15677 +config VSERVER_CONTEXTS
15678 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15679 +       range 1 65533
15680 +       default "768"   if 64BIT
15681 +       default "256"
15682 +       help
15683 +         This setting will optimize certain data structures
15684 +         and memory allocations according to the expected
15685 +         maximum.
15686 +
15687 +         note: this is not a strict upper limit.
15688 +
15689 +config VSERVER_WARN
15690 +       bool    "VServer Warnings"
15691 +       default y
15692 +       help
15693 +         This enables various runtime warnings, which will
15694 +         notify about potential manipulation attempts or
15695 +         resource shortage. It is generally considered to
15696 +         be a good idea to have that enabled.
15697 +
15698 +config VSERVER_WARN_DEVPTS
15699 +       bool    "VServer DevPTS Warnings"
15700 +       depends on VSERVER_WARN
15701 +       default y
15702 +       help
15703 +         This enables DevPTS related warnings, issued when a
15704 +         process inside a context tries to lookup or access
15705 +         a dynamic pts from the host or a different context.
15706 +
15707 +config VSERVER_DEBUG
15708 +       bool    "VServer Debugging Code"
15709 +       default n
15710 +       help
15711 +         Set this to yes if you want to be able to activate
15712 +         debugging output at runtime. It adds a very small
15713 +         overhead to all vserver related functions and
15714 +         increases the kernel size by about 20k.
15715 +
15716 +config VSERVER_HISTORY
15717 +       bool    "VServer History Tracing"
15718 +       depends on VSERVER_DEBUG
15719 +       default n
15720 +       help
15721 +         Set this to yes if you want to record the history of
15722 +         linux-vserver activities, so they can be replayed in
15723 +         the event of a kernel panic or oops.
15724 +
15725 +config VSERVER_HISTORY_SIZE
15726 +       int     "Per-CPU History Size (32-65536)"
15727 +       depends on VSERVER_HISTORY
15728 +       range 32 65536
15729 +       default 64
15730 +       help
15731 +         This allows you to specify the number of entries in
15732 +         the per-CPU history buffer.
15733 +
15734 +choice
15735 +       prompt  "Quotes used in debug and warn messages"
15736 +       default QUOTES_ISO8859
15737 +
15738 +config QUOTES_ISO8859
15739 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15740 +       help
15741 +         This uses the extended ASCII characters \xbb
15742 +         and \xab for quoting file and process names.
15743 +
15744 +config QUOTES_UTF8
15745 +       bool    "UTF-8 angle quotes"
15746 +       help
15747 +         This uses the the UTF-8 sequences for angle
15748 +         quotes to quote file and process names.
15749 +
15750 +config QUOTES_ASCII
15751 +       bool    "ASCII single quotes"
15752 +       help
15753 +         This uses the ASCII single quote character
15754 +         (\x27) to quote file and process names.
15755 +
15756 +endchoice
15757 +
15758 +endmenu
15759 +
15760 +
15761 +config VSERVER
15762 +       bool
15763 +       default y
15764 +       select NAMESPACES
15765 +       select UTS_NS
15766 +       select IPC_NS
15767 +#      select USER_NS
15768 +       select SYSVIPC
15769 +
15770 +config VSERVER_SECURITY
15771 +       bool
15772 +       depends on SECURITY
15773 +       default y
15774 +       select SECURITY_CAPABILITIES
15775 +
15776 +config VSERVER_DISABLED
15777 +       bool
15778 +       default n
15779 +
15780 diff -NurpP --minimal linux-3.4.32/kernel/vserver/Makefile linux-3.4.32-vs2.3.3.9/kernel/vserver/Makefile
15781 --- linux-3.4.32/kernel/vserver/Makefile        1970-01-01 00:00:00.000000000 +0000
15782 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/Makefile      2012-05-21 16:15:05.000000000 +0000
15783 @@ -0,0 +1,18 @@
15784 +#
15785 +# Makefile for the Linux vserver routines.
15786 +#
15787 +
15788 +
15789 +obj-y          += vserver.o
15790 +
15791 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15792 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15793 +                  dlimit.o tag.o
15794 +
15795 +vserver-$(CONFIG_INET) += inet.o
15796 +vserver-$(CONFIG_PROC_FS) += proc.o
15797 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15798 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15799 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15800 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15801 +
15802 diff -NurpP --minimal linux-3.4.32/kernel/vserver/cacct.c linux-3.4.32-vs2.3.3.9/kernel/vserver/cacct.c
15803 --- linux-3.4.32/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
15804 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/cacct.c       2012-05-21 16:15:05.000000000 +0000
15805 @@ -0,0 +1,42 @@
15806 +/*
15807 + *  linux/kernel/vserver/cacct.c
15808 + *
15809 + *  Virtual Server: Context Accounting
15810 + *
15811 + *  Copyright (C) 2006-2007 Herbert Pötzl
15812 + *
15813 + *  V0.01  added accounting stats
15814 + *
15815 + */
15816 +
15817 +#include <linux/types.h>
15818 +#include <linux/vs_context.h>
15819 +#include <linux/vserver/cacct_cmd.h>
15820 +#include <linux/vserver/cacct_int.h>
15821 +
15822 +#include <asm/errno.h>
15823 +#include <asm/uaccess.h>
15824 +
15825 +
15826 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15827 +{
15828 +       struct vcmd_sock_stat_v0 vc_data;
15829 +       int j, field;
15830 +
15831 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15832 +               return -EFAULT;
15833 +
15834 +       field = vc_data.field;
15835 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15836 +               return -EINVAL;
15837 +
15838 +       for (j = 0; j < 3; j++) {
15839 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15840 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15841 +       }
15842 +
15843 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15844 +               return -EFAULT;
15845 +       return 0;
15846 +}
15847 +
15848 diff -NurpP --minimal linux-3.4.32/kernel/vserver/cacct_init.h linux-3.4.32-vs2.3.3.9/kernel/vserver/cacct_init.h
15849 --- linux-3.4.32/kernel/vserver/cacct_init.h    1970-01-01 00:00:00.000000000 +0000
15850 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/cacct_init.h  2012-05-21 16:15:05.000000000 +0000
15851 @@ -0,0 +1,25 @@
15852 +
15853 +
15854 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15855 +{
15856 +       int i, j;
15857 +
15858 +
15859 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15860 +               for (j = 0; j < 3; j++) {
15861 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15862 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15863 +               }
15864 +       }
15865 +       for (i = 0; i < 8; i++)
15866 +               atomic_set(&cacct->slab[i], 0);
15867 +       for (i = 0; i < 5; i++)
15868 +               for (j = 0; j < 4; j++)
15869 +                       atomic_set(&cacct->page[i][j], 0);
15870 +}
15871 +
15872 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15873 +{
15874 +       return;
15875 +}
15876 +
15877 diff -NurpP --minimal linux-3.4.32/kernel/vserver/cacct_proc.h linux-3.4.32-vs2.3.3.9/kernel/vserver/cacct_proc.h
15878 --- linux-3.4.32/kernel/vserver/cacct_proc.h    1970-01-01 00:00:00.000000000 +0000
15879 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/cacct_proc.h  2012-05-21 16:15:05.000000000 +0000
15880 @@ -0,0 +1,53 @@
15881 +#ifndef _VX_CACCT_PROC_H
15882 +#define _VX_CACCT_PROC_H
15883 +
15884 +#include <linux/vserver/cacct_int.h>
15885 +
15886 +
15887 +#define VX_SOCKA_TOP   \
15888 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15889 +
15890 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15891 +{
15892 +       int i, j, length = 0;
15893 +       static char *type[VXA_SOCK_SIZE] = {
15894 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15895 +       };
15896 +
15897 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15898 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15899 +               length += sprintf(buffer + length, "%s:", type[i]);
15900 +               for (j = 0; j < 3; j++) {
15901 +                       length += sprintf(buffer + length,
15902 +                               "\t%10lu/%-10lu",
15903 +                               vx_sock_count(cacct, i, j),
15904 +                               vx_sock_total(cacct, i, j));
15905 +               }
15906 +               buffer[length++] = '\n';
15907 +       }
15908 +
15909 +       length += sprintf(buffer + length, "\n");
15910 +       length += sprintf(buffer + length,
15911 +               "slab:\t %8u %8u %8u %8u\n",
15912 +               atomic_read(&cacct->slab[1]),
15913 +               atomic_read(&cacct->slab[4]),
15914 +               atomic_read(&cacct->slab[0]),
15915 +               atomic_read(&cacct->slab[2]));
15916 +
15917 +       length += sprintf(buffer + length, "\n");
15918 +       for (i = 0; i < 5; i++) {
15919 +               length += sprintf(buffer + length,
15920 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15921 +                       atomic_read(&cacct->page[i][0]),
15922 +                       atomic_read(&cacct->page[i][1]),
15923 +                       atomic_read(&cacct->page[i][2]),
15924 +                       atomic_read(&cacct->page[i][3]),
15925 +                       atomic_read(&cacct->page[i][4]),
15926 +                       atomic_read(&cacct->page[i][5]),
15927 +                       atomic_read(&cacct->page[i][6]),
15928 +                       atomic_read(&cacct->page[i][7]));
15929 +       }
15930 +       return length;
15931 +}
15932 +
15933 +#endif /* _VX_CACCT_PROC_H */
15934 diff -NurpP --minimal linux-3.4.32/kernel/vserver/context.c linux-3.4.32-vs2.3.3.9/kernel/vserver/context.c
15935 --- linux-3.4.32/kernel/vserver/context.c       1970-01-01 00:00:00.000000000 +0000
15936 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/context.c     2012-06-28 14:45:48.000000000 +0000
15937 @@ -0,0 +1,1119 @@
15938 +/*
15939 + *  linux/kernel/vserver/context.c
15940 + *
15941 + *  Virtual Server: Context Support
15942 + *
15943 + *  Copyright (C) 2003-2011  Herbert Pötzl
15944 + *
15945 + *  V0.01  context helper
15946 + *  V0.02  vx_ctx_kill syscall command
15947 + *  V0.03  replaced context_info calls
15948 + *  V0.04  redesign of struct (de)alloc
15949 + *  V0.05  rlimit basic implementation
15950 + *  V0.06  task_xid and info commands
15951 + *  V0.07  context flags and caps
15952 + *  V0.08  switch to RCU based hash
15953 + *  V0.09  revert to non RCU for now
15954 + *  V0.10  and back to working RCU hash
15955 + *  V0.11  and back to locking again
15956 + *  V0.12  referenced context store
15957 + *  V0.13  separate per cpu data
15958 + *  V0.14  changed vcmds to vxi arg
15959 + *  V0.15  added context stat
15960 + *  V0.16  have __create claim() the vxi
15961 + *  V0.17  removed older and legacy stuff
15962 + *  V0.18  added user credentials
15963 + *  V0.19  added warn mask
15964 + *
15965 + */
15966 +
15967 +#include <linux/slab.h>
15968 +#include <linux/types.h>
15969 +#include <linux/security.h>
15970 +#include <linux/pid_namespace.h>
15971 +#include <linux/capability.h>
15972 +
15973 +#include <linux/vserver/context.h>
15974 +#include <linux/vserver/network.h>
15975 +#include <linux/vserver/debug.h>
15976 +#include <linux/vserver/limit.h>
15977 +#include <linux/vserver/limit_int.h>
15978 +#include <linux/vserver/space.h>
15979 +#include <linux/init_task.h>
15980 +#include <linux/fs_struct.h>
15981 +#include <linux/cred.h>
15982 +
15983 +#include <linux/vs_context.h>
15984 +#include <linux/vs_limit.h>
15985 +#include <linux/vs_pid.h>
15986 +#include <linux/vserver/context_cmd.h>
15987 +
15988 +#include "cvirt_init.h"
15989 +#include "cacct_init.h"
15990 +#include "limit_init.h"
15991 +#include "sched_init.h"
15992 +
15993 +
15994 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15995 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15996 +
15997 +
15998 +/*     now inactive context structures */
15999 +
16000 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16001 +
16002 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
16003 +
16004 +
16005 +/*     __alloc_vx_info()
16006 +
16007 +       * allocate an initialized vx_info struct
16008 +       * doesn't make it visible (hash)                        */
16009 +
16010 +static struct vx_info *__alloc_vx_info(xid_t xid)
16011 +{
16012 +       struct vx_info *new = NULL;
16013 +       int cpu, index;
16014 +
16015 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16016 +
16017 +       /* would this benefit from a slab cache? */
16018 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16019 +       if (!new)
16020 +               return 0;
16021 +
16022 +       memset(new, 0, sizeof(struct vx_info));
16023 +#ifdef CONFIG_SMP
16024 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16025 +       if (!new->ptr_pc)
16026 +               goto error;
16027 +#endif
16028 +       new->vx_id = xid;
16029 +       INIT_HLIST_NODE(&new->vx_hlist);
16030 +       atomic_set(&new->vx_usecnt, 0);
16031 +       atomic_set(&new->vx_tasks, 0);
16032 +       new->vx_parent = NULL;
16033 +       new->vx_state = 0;
16034 +       init_waitqueue_head(&new->vx_wait);
16035 +
16036 +       /* prepare reaper */
16037 +       get_task_struct(init_pid_ns.child_reaper);
16038 +       new->vx_reaper = init_pid_ns.child_reaper;
16039 +       new->vx_badness_bias = 0;
16040 +
16041 +       /* rest of init goes here */
16042 +       vx_info_init_limit(&new->limit);
16043 +       vx_info_init_sched(&new->sched);
16044 +       vx_info_init_cvirt(&new->cvirt);
16045 +       vx_info_init_cacct(&new->cacct);
16046 +
16047 +       /* per cpu data structures */
16048 +       for_each_possible_cpu(cpu) {
16049 +               vx_info_init_sched_pc(
16050 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16051 +               vx_info_init_cvirt_pc(
16052 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16053 +       }
16054 +
16055 +       new->vx_flags = VXF_INIT_SET;
16056 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
16057 +       new->vx_ccaps = 0;
16058 +       new->vx_umask = 0;
16059 +       new->vx_wmask = 0;
16060 +
16061 +       new->reboot_cmd = 0;
16062 +       new->exit_code = 0;
16063 +
16064 +       // preconfig spaces
16065 +       for (index = 0; index < VX_SPACES; index++) {
16066 +               struct _vx_space *space = &new->space[index];
16067 +
16068 +               // filesystem
16069 +               spin_lock(&init_fs.lock);
16070 +               init_fs.users++;
16071 +               spin_unlock(&init_fs.lock);
16072 +               space->vx_fs = &init_fs;
16073 +
16074 +               /* FIXME: do we want defaults? */
16075 +               // space->vx_real_cred = 0;
16076 +               // space->vx_cred = 0;
16077 +       }
16078 +
16079 +
16080 +       vxdprintk(VXD_CBIT(xid, 0),
16081 +               "alloc_vx_info(%d) = %p", xid, new);
16082 +       vxh_alloc_vx_info(new);
16083 +       atomic_inc(&vx_global_ctotal);
16084 +       return new;
16085 +#ifdef CONFIG_SMP
16086 +error:
16087 +       kfree(new);
16088 +       return 0;
16089 +#endif
16090 +}
16091 +
16092 +/*     __dealloc_vx_info()
16093 +
16094 +       * final disposal of vx_info                             */
16095 +
16096 +static void __dealloc_vx_info(struct vx_info *vxi)
16097 +{
16098 +#ifdef CONFIG_VSERVER_WARN
16099 +       struct vx_info_save vxis;
16100 +       int cpu;
16101 +#endif
16102 +       vxdprintk(VXD_CBIT(xid, 0),
16103 +               "dealloc_vx_info(%p)", vxi);
16104 +       vxh_dealloc_vx_info(vxi);
16105 +
16106 +#ifdef CONFIG_VSERVER_WARN
16107 +       enter_vx_info(vxi, &vxis);
16108 +       vx_info_exit_limit(&vxi->limit);
16109 +       vx_info_exit_sched(&vxi->sched);
16110 +       vx_info_exit_cvirt(&vxi->cvirt);
16111 +       vx_info_exit_cacct(&vxi->cacct);
16112 +
16113 +       for_each_possible_cpu(cpu) {
16114 +               vx_info_exit_sched_pc(
16115 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16116 +               vx_info_exit_cvirt_pc(
16117 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16118 +       }
16119 +       leave_vx_info(&vxis);
16120 +#endif
16121 +
16122 +       vxi->vx_id = -1;
16123 +       vxi->vx_state |= VXS_RELEASED;
16124 +
16125 +#ifdef CONFIG_SMP
16126 +       free_percpu(vxi->ptr_pc);
16127 +#endif
16128 +       kfree(vxi);
16129 +       atomic_dec(&vx_global_ctotal);
16130 +}
16131 +
16132 +static void __shutdown_vx_info(struct vx_info *vxi)
16133 +{
16134 +       struct nsproxy *nsproxy;
16135 +       struct fs_struct *fs;
16136 +       struct cred *cred;
16137 +       int index, kill;
16138 +
16139 +       might_sleep();
16140 +
16141 +       vxi->vx_state |= VXS_SHUTDOWN;
16142 +       vs_state_change(vxi, VSC_SHUTDOWN);
16143 +
16144 +       for (index = 0; index < VX_SPACES; index++) {
16145 +               struct _vx_space *space = &vxi->space[index];
16146 +
16147 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16148 +               if (nsproxy)
16149 +                       put_nsproxy(nsproxy);
16150 +
16151 +               fs = xchg(&space->vx_fs, NULL);
16152 +               spin_lock(&fs->lock);
16153 +               kill = !--fs->users;
16154 +               spin_unlock(&fs->lock);
16155 +               if (kill)
16156 +                       free_fs_struct(fs);
16157 +
16158 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16159 +               if (cred)
16160 +                       abort_creds(cred);
16161 +       }
16162 +}
16163 +
16164 +/* exported stuff */
16165 +
16166 +void free_vx_info(struct vx_info *vxi)
16167 +{
16168 +       unsigned long flags;
16169 +       unsigned index;
16170 +
16171 +       /* check for reference counts first */
16172 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16173 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16174 +
16175 +       /* context must not be hashed */
16176 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16177 +
16178 +       /* context shutdown is mandatory */
16179 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16180 +
16181 +       /* spaces check */
16182 +       for (index = 0; index < VX_SPACES; index++) {
16183 +               struct _vx_space *space = &vxi->space[index];
16184 +
16185 +               BUG_ON(space->vx_nsproxy);
16186 +               BUG_ON(space->vx_fs);
16187 +               // BUG_ON(space->vx_real_cred);
16188 +               // BUG_ON(space->vx_cred);
16189 +       }
16190 +
16191 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16192 +       hlist_del(&vxi->vx_hlist);
16193 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16194 +
16195 +       __dealloc_vx_info(vxi);
16196 +}
16197 +
16198 +
16199 +/*     hash table for vx_info hash */
16200 +
16201 +#define VX_HASH_SIZE   13
16202 +
16203 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16204 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16205 +
16206 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16207 +
16208 +
16209 +static inline unsigned int __hashval(xid_t xid)
16210 +{
16211 +       return (xid % VX_HASH_SIZE);
16212 +}
16213 +
16214 +
16215 +
16216 +/*     __hash_vx_info()
16217 +
16218 +       * add the vxi to the global hash table
16219 +       * requires the hash_lock to be held                     */
16220 +
16221 +static inline void __hash_vx_info(struct vx_info *vxi)
16222 +{
16223 +       struct hlist_head *head;
16224 +
16225 +       vxd_assert_lock(&vx_info_hash_lock);
16226 +       vxdprintk(VXD_CBIT(xid, 4),
16227 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16228 +       vxh_hash_vx_info(vxi);
16229 +
16230 +       /* context must not be hashed */
16231 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16232 +
16233 +       vxi->vx_state |= VXS_HASHED;
16234 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16235 +       hlist_add_head(&vxi->vx_hlist, head);
16236 +       atomic_inc(&vx_global_cactive);
16237 +}
16238 +
16239 +/*     __unhash_vx_info()
16240 +
16241 +       * remove the vxi from the global hash table
16242 +       * requires the hash_lock to be held                     */
16243 +
16244 +static inline void __unhash_vx_info(struct vx_info *vxi)
16245 +{
16246 +       unsigned long flags;
16247 +
16248 +       vxd_assert_lock(&vx_info_hash_lock);
16249 +       vxdprintk(VXD_CBIT(xid, 4),
16250 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16251 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16252 +       vxh_unhash_vx_info(vxi);
16253 +
16254 +       /* context must be hashed */
16255 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16256 +       /* but without tasks */
16257 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16258 +
16259 +       vxi->vx_state &= ~VXS_HASHED;
16260 +       hlist_del_init(&vxi->vx_hlist);
16261 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16262 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16263 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16264 +       atomic_dec(&vx_global_cactive);
16265 +}
16266 +
16267 +
16268 +/*     __lookup_vx_info()
16269 +
16270 +       * requires the hash_lock to be held
16271 +       * doesn't increment the vx_refcnt                       */
16272 +
16273 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16274 +{
16275 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16276 +       struct hlist_node *pos;
16277 +       struct vx_info *vxi;
16278 +
16279 +       vxd_assert_lock(&vx_info_hash_lock);
16280 +       hlist_for_each(pos, head) {
16281 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16282 +
16283 +               if (vxi->vx_id == xid)
16284 +                       goto found;
16285 +       }
16286 +       vxi = NULL;
16287 +found:
16288 +       vxdprintk(VXD_CBIT(xid, 0),
16289 +               "__lookup_vx_info(#%u): %p[#%u]",
16290 +               xid, vxi, vxi ? vxi->vx_id : 0);
16291 +       vxh_lookup_vx_info(vxi, xid);
16292 +       return vxi;
16293 +}
16294 +
16295 +
16296 +/*     __create_vx_info()
16297 +
16298 +       * create the requested context
16299 +       * get(), claim() and hash it                            */
16300 +
16301 +static struct vx_info *__create_vx_info(int id)
16302 +{
16303 +       struct vx_info *new, *vxi = NULL;
16304 +
16305 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16306 +
16307 +       if (!(new = __alloc_vx_info(id)))
16308 +               return ERR_PTR(-ENOMEM);
16309 +
16310 +       /* required to make dynamic xids unique */
16311 +       spin_lock(&vx_info_hash_lock);
16312 +
16313 +       /* static context requested */
16314 +       if ((vxi = __lookup_vx_info(id))) {
16315 +               vxdprintk(VXD_CBIT(xid, 0),
16316 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16317 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16318 +                       vxi = ERR_PTR(-EBUSY);
16319 +               else
16320 +                       vxi = ERR_PTR(-EEXIST);
16321 +               goto out_unlock;
16322 +       }
16323 +       /* new context */
16324 +       vxdprintk(VXD_CBIT(xid, 0),
16325 +               "create_vx_info(%d) = %p (new)", id, new);
16326 +       claim_vx_info(new, NULL);
16327 +       __hash_vx_info(get_vx_info(new));
16328 +       vxi = new, new = NULL;
16329 +
16330 +out_unlock:
16331 +       spin_unlock(&vx_info_hash_lock);
16332 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16333 +       if (new)
16334 +               __dealloc_vx_info(new);
16335 +       return vxi;
16336 +}
16337 +
16338 +
16339 +/*     exported stuff                                          */
16340 +
16341 +
16342 +void unhash_vx_info(struct vx_info *vxi)
16343 +{
16344 +       spin_lock(&vx_info_hash_lock);
16345 +       __unhash_vx_info(vxi);
16346 +       spin_unlock(&vx_info_hash_lock);
16347 +       __shutdown_vx_info(vxi);
16348 +       __wakeup_vx_info(vxi);
16349 +}
16350 +
16351 +
16352 +/*     lookup_vx_info()
16353 +
16354 +       * search for a vx_info and get() it
16355 +       * negative id means current                             */
16356 +
16357 +struct vx_info *lookup_vx_info(int id)
16358 +{
16359 +       struct vx_info *vxi = NULL;
16360 +
16361 +       if (id < 0) {
16362 +               vxi = get_vx_info(current_vx_info());
16363 +       } else if (id > 1) {
16364 +               spin_lock(&vx_info_hash_lock);
16365 +               vxi = get_vx_info(__lookup_vx_info(id));
16366 +               spin_unlock(&vx_info_hash_lock);
16367 +       }
16368 +       return vxi;
16369 +}
16370 +
16371 +/*     xid_is_hashed()
16372 +
16373 +       * verify that xid is still hashed                       */
16374 +
16375 +int xid_is_hashed(xid_t xid)
16376 +{
16377 +       int hashed;
16378 +
16379 +       spin_lock(&vx_info_hash_lock);
16380 +       hashed = (__lookup_vx_info(xid) != NULL);
16381 +       spin_unlock(&vx_info_hash_lock);
16382 +       return hashed;
16383 +}
16384 +
16385 +#ifdef CONFIG_PROC_FS
16386 +
16387 +/*     get_xid_list()
16388 +
16389 +       * get a subset of hashed xids for proc
16390 +       * assumes size is at least one                          */
16391 +
16392 +int get_xid_list(int index, unsigned int *xids, int size)
16393 +{
16394 +       int hindex, nr_xids = 0;
16395 +
16396 +       /* only show current and children */
16397 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16398 +               if (index > 0)
16399 +                       return 0;
16400 +               xids[nr_xids] = vx_current_xid();
16401 +               return 1;
16402 +       }
16403 +
16404 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16405 +               struct hlist_head *head = &vx_info_hash[hindex];
16406 +               struct hlist_node *pos;
16407 +
16408 +               spin_lock(&vx_info_hash_lock);
16409 +               hlist_for_each(pos, head) {
16410 +                       struct vx_info *vxi;
16411 +
16412 +                       if (--index > 0)
16413 +                               continue;
16414 +
16415 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16416 +                       xids[nr_xids] = vxi->vx_id;
16417 +                       if (++nr_xids >= size) {
16418 +                               spin_unlock(&vx_info_hash_lock);
16419 +                               goto out;
16420 +                       }
16421 +               }
16422 +               /* keep the lock time short */
16423 +               spin_unlock(&vx_info_hash_lock);
16424 +       }
16425 +out:
16426 +       return nr_xids;
16427 +}
16428 +#endif
16429 +
16430 +#ifdef CONFIG_VSERVER_DEBUG
16431 +
16432 +void   dump_vx_info_inactive(int level)
16433 +{
16434 +       struct hlist_node *entry, *next;
16435 +
16436 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16437 +               struct vx_info *vxi =
16438 +                       list_entry(entry, struct vx_info, vx_hlist);
16439 +
16440 +               dump_vx_info(vxi, level);
16441 +       }
16442 +}
16443 +
16444 +#endif
16445 +
16446 +#if 0
16447 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16448 +{
16449 +       struct user_struct *new_user, *old_user;
16450 +
16451 +       if (!p || !vxi)
16452 +               BUG();
16453 +
16454 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16455 +               return -EACCES;
16456 +
16457 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16458 +       if (!new_user)
16459 +               return -ENOMEM;
16460 +
16461 +       old_user = p->user;
16462 +       if (new_user != old_user) {
16463 +               atomic_inc(&new_user->processes);
16464 +               atomic_dec(&old_user->processes);
16465 +               p->user = new_user;
16466 +       }
16467 +       free_uid(old_user);
16468 +       return 0;
16469 +}
16470 +#endif
16471 +
16472 +#if 0
16473 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16474 +{
16475 +       // p->cap_effective &= vxi->vx_cap_bset;
16476 +       p->cap_effective =
16477 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16478 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16479 +       p->cap_inheritable =
16480 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16481 +       // p->cap_permitted &= vxi->vx_cap_bset;
16482 +       p->cap_permitted =
16483 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16484 +}
16485 +#endif
16486 +
16487 +
16488 +#include <linux/file.h>
16489 +#include <linux/fdtable.h>
16490 +
16491 +static int vx_openfd_task(struct task_struct *tsk)
16492 +{
16493 +       struct files_struct *files = tsk->files;
16494 +       struct fdtable *fdt;
16495 +       const unsigned long *bptr;
16496 +       int count, total;
16497 +
16498 +       /* no rcu_read_lock() because of spin_lock() */
16499 +       spin_lock(&files->file_lock);
16500 +       fdt = files_fdtable(files);
16501 +       bptr = fdt->open_fds;
16502 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16503 +       for (total = 0; count > 0; count--) {
16504 +               if (*bptr)
16505 +                       total += hweight_long(*bptr);
16506 +               bptr++;
16507 +       }
16508 +       spin_unlock(&files->file_lock);
16509 +       return total;
16510 +}
16511 +
16512 +
16513 +/*     for *space compatibility */
16514 +
16515 +asmlinkage long sys_unshare(unsigned long);
16516 +
16517 +/*
16518 + *     migrate task to new context
16519 + *     gets vxi, puts old_vxi on change
16520 + *     optionally unshares namespaces (hack)
16521 + */
16522 +
16523 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16524 +{
16525 +       struct vx_info *old_vxi;
16526 +       int ret = 0;
16527 +
16528 +       if (!p || !vxi)
16529 +               BUG();
16530 +
16531 +       vxdprintk(VXD_CBIT(xid, 5),
16532 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16533 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16534 +
16535 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16536 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16537 +               return -EACCES;
16538 +
16539 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16540 +               return -EFAULT;
16541 +
16542 +       old_vxi = task_get_vx_info(p);
16543 +       if (old_vxi == vxi)
16544 +               goto out;
16545 +
16546 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16547 +       {
16548 +               int openfd;
16549 +
16550 +               task_lock(p);
16551 +               openfd = vx_openfd_task(p);
16552 +
16553 +               if (old_vxi) {
16554 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16555 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16556 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16557 +                       /* FIXME: what about the struct files here? */
16558 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16559 +                       /* account for the executable */
16560 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16561 +               }
16562 +               atomic_inc(&vxi->cvirt.nr_threads);
16563 +               atomic_inc(&vxi->cvirt.nr_running);
16564 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16565 +               /* FIXME: what about the struct files here? */
16566 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16567 +               /* account for the executable */
16568 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16569 +
16570 +               if (old_vxi) {
16571 +                       release_vx_info(old_vxi, p);
16572 +                       clr_vx_info(&p->vx_info);
16573 +               }
16574 +               claim_vx_info(vxi, p);
16575 +               set_vx_info(&p->vx_info, vxi);
16576 +               p->xid = vxi->vx_id;
16577 +
16578 +               vxdprintk(VXD_CBIT(xid, 5),
16579 +                       "moved task %p into vxi:%p[#%d]",
16580 +                       p, vxi, vxi->vx_id);
16581 +
16582 +               // vx_mask_cap_bset(vxi, p);
16583 +               task_unlock(p);
16584 +
16585 +               /* hack for *spaces to provide compatibility */
16586 +               if (unshare) {
16587 +                       struct nsproxy *old_nsp, *new_nsp;
16588 +
16589 +                       ret = unshare_nsproxy_namespaces(
16590 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16591 +                               &new_nsp, NULL);
16592 +                       if (ret)
16593 +                               goto out;
16594 +
16595 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16596 +                       vx_set_space(vxi,
16597 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16598 +                       put_nsproxy(old_nsp);
16599 +               }
16600 +       }
16601 +out:
16602 +       put_vx_info(old_vxi);
16603 +       return ret;
16604 +}
16605 +
16606 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16607 +{
16608 +       struct task_struct *old_reaper;
16609 +       struct vx_info *reaper_vxi;
16610 +
16611 +       if (!vxi)
16612 +               return -EINVAL;
16613 +
16614 +       vxdprintk(VXD_CBIT(xid, 6),
16615 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16616 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16617 +
16618 +       old_reaper = vxi->vx_reaper;
16619 +       if (old_reaper == p)
16620 +               return 0;
16621 +
16622 +       reaper_vxi = task_get_vx_info(p);
16623 +       if (reaper_vxi && reaper_vxi != vxi) {
16624 +               vxwprintk(1,
16625 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16626 +                       "for [xid #%u]",
16627 +                       p->comm, p->pid, p->xid, vx_current_xid());
16628 +               goto out;
16629 +       }
16630 +
16631 +       /* set new child reaper */
16632 +       get_task_struct(p);
16633 +       vxi->vx_reaper = p;
16634 +       put_task_struct(old_reaper);
16635 +out:
16636 +       put_vx_info(reaper_vxi);
16637 +       return 0;
16638 +}
16639 +
16640 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16641 +{
16642 +       if (!vxi)
16643 +               return -EINVAL;
16644 +
16645 +       vxdprintk(VXD_CBIT(xid, 6),
16646 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16647 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16648 +
16649 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16650 +       // vxi->vx_initpid = p->tgid;
16651 +       vxi->vx_initpid = p->pid;
16652 +       return 0;
16653 +}
16654 +
16655 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16656 +{
16657 +       vxdprintk(VXD_CBIT(xid, 6),
16658 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16659 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16660 +
16661 +       vxi->exit_code = code;
16662 +       vxi->vx_initpid = 0;
16663 +}
16664 +
16665 +
16666 +void vx_set_persistent(struct vx_info *vxi)
16667 +{
16668 +       vxdprintk(VXD_CBIT(xid, 6),
16669 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16670 +
16671 +       get_vx_info(vxi);
16672 +       claim_vx_info(vxi, NULL);
16673 +}
16674 +
16675 +void vx_clear_persistent(struct vx_info *vxi)
16676 +{
16677 +       vxdprintk(VXD_CBIT(xid, 6),
16678 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16679 +
16680 +       release_vx_info(vxi, NULL);
16681 +       put_vx_info(vxi);
16682 +}
16683 +
16684 +void vx_update_persistent(struct vx_info *vxi)
16685 +{
16686 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16687 +               vx_set_persistent(vxi);
16688 +       else
16689 +               vx_clear_persistent(vxi);
16690 +}
16691 +
16692 +
16693 +/*     task must be current or locked          */
16694 +
16695 +void   exit_vx_info(struct task_struct *p, int code)
16696 +{
16697 +       struct vx_info *vxi = p->vx_info;
16698 +
16699 +       if (vxi) {
16700 +               atomic_dec(&vxi->cvirt.nr_threads);
16701 +               vx_nproc_dec(p);
16702 +
16703 +               vxi->exit_code = code;
16704 +               release_vx_info(vxi, p);
16705 +       }
16706 +}
16707 +
16708 +void   exit_vx_info_early(struct task_struct *p, int code)
16709 +{
16710 +       struct vx_info *vxi = p->vx_info;
16711 +
16712 +       if (vxi) {
16713 +               if (vxi->vx_initpid == p->pid)
16714 +                       vx_exit_init(vxi, p, code);
16715 +               if (vxi->vx_reaper == p)
16716 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16717 +       }
16718 +}
16719 +
16720 +
16721 +/* vserver syscall commands below here */
16722 +
16723 +/* taks xid and vx_info functions */
16724 +
16725 +#include <asm/uaccess.h>
16726 +
16727 +
16728 +int vc_task_xid(uint32_t id)
16729 +{
16730 +       xid_t xid;
16731 +
16732 +       if (id) {
16733 +               struct task_struct *tsk;
16734 +
16735 +               rcu_read_lock();
16736 +               tsk = find_task_by_real_pid(id);
16737 +               xid = (tsk) ? tsk->xid : -ESRCH;
16738 +               rcu_read_unlock();
16739 +       } else
16740 +               xid = vx_current_xid();
16741 +       return xid;
16742 +}
16743 +
16744 +
16745 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16746 +{
16747 +       struct vcmd_vx_info_v0 vc_data;
16748 +
16749 +       vc_data.xid = vxi->vx_id;
16750 +       vc_data.initpid = vxi->vx_initpid;
16751 +
16752 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16753 +               return -EFAULT;
16754 +       return 0;
16755 +}
16756 +
16757 +
16758 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16759 +{
16760 +       struct vcmd_ctx_stat_v0 vc_data;
16761 +
16762 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16763 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16764 +
16765 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16766 +               return -EFAULT;
16767 +       return 0;
16768 +}
16769 +
16770 +
16771 +/* context functions */
16772 +
16773 +int vc_ctx_create(uint32_t xid, void __user *data)
16774 +{
16775 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16776 +       struct vx_info *new_vxi;
16777 +       int ret;
16778 +
16779 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16780 +               return -EFAULT;
16781 +
16782 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16783 +               return -EINVAL;
16784 +
16785 +       new_vxi = __create_vx_info(xid);
16786 +       if (IS_ERR(new_vxi))
16787 +               return PTR_ERR(new_vxi);
16788 +
16789 +       /* initial flags */
16790 +       new_vxi->vx_flags = vc_data.flagword;
16791 +
16792 +       ret = -ENOEXEC;
16793 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16794 +               goto out;
16795 +
16796 +       ret = vx_migrate_task(current, new_vxi, (!data));
16797 +       if (ret)
16798 +               goto out;
16799 +
16800 +       /* return context id on success */
16801 +       ret = new_vxi->vx_id;
16802 +
16803 +       /* get a reference for persistent contexts */
16804 +       if ((vc_data.flagword & VXF_PERSISTENT))
16805 +               vx_set_persistent(new_vxi);
16806 +out:
16807 +       release_vx_info(new_vxi, NULL);
16808 +       put_vx_info(new_vxi);
16809 +       return ret;
16810 +}
16811 +
16812 +
16813 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16814 +{
16815 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16816 +       int ret;
16817 +
16818 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16819 +               return -EFAULT;
16820 +
16821 +       ret = vx_migrate_task(current, vxi, 0);
16822 +       if (ret)
16823 +               return ret;
16824 +       if (vc_data.flagword & VXM_SET_INIT)
16825 +               ret = vx_set_init(vxi, current);
16826 +       if (ret)
16827 +               return ret;
16828 +       if (vc_data.flagword & VXM_SET_REAPER)
16829 +               ret = vx_set_reaper(vxi, current);
16830 +       return ret;
16831 +}
16832 +
16833 +
16834 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16835 +{
16836 +       struct vcmd_ctx_flags_v0 vc_data;
16837 +
16838 +       vc_data.flagword = vxi->vx_flags;
16839 +
16840 +       /* special STATE flag handling */
16841 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16842 +
16843 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16844 +               return -EFAULT;
16845 +       return 0;
16846 +}
16847 +
16848 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16849 +{
16850 +       struct vcmd_ctx_flags_v0 vc_data;
16851 +       uint64_t mask, trigger;
16852 +
16853 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16854 +               return -EFAULT;
16855 +
16856 +       /* special STATE flag handling */
16857 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16858 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16859 +
16860 +       if (vxi == current_vx_info()) {
16861 +               /* if (trigger & VXF_STATE_SETUP)
16862 +                       vx_mask_cap_bset(vxi, current); */
16863 +               if (trigger & VXF_STATE_INIT) {
16864 +                       int ret;
16865 +
16866 +                       ret = vx_set_init(vxi, current);
16867 +                       if (ret)
16868 +                               return ret;
16869 +                       ret = vx_set_reaper(vxi, current);
16870 +                       if (ret)
16871 +                               return ret;
16872 +               }
16873 +       }
16874 +
16875 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16876 +               vc_data.flagword, mask);
16877 +       if (trigger & VXF_PERSISTENT)
16878 +               vx_update_persistent(vxi);
16879 +
16880 +       return 0;
16881 +}
16882 +
16883 +
16884 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16885 +{
16886 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16887 +
16888 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16889 +       return v;
16890 +}
16891 +
16892 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16893 +{
16894 +       kernel_cap_t c = __cap_empty_set;
16895 +
16896 +       c.cap[0] = v & 0xFFFFFFFF;
16897 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16898 +
16899 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16900 +       return c;
16901 +}
16902 +
16903 +
16904 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16905 +{
16906 +       if (bcaps)
16907 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16908 +       if (ccaps)
16909 +               *ccaps = vxi->vx_ccaps;
16910 +
16911 +       return 0;
16912 +}
16913 +
16914 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16915 +{
16916 +       struct vcmd_ctx_caps_v1 vc_data;
16917 +       int ret;
16918 +
16919 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16920 +       if (ret)
16921 +               return ret;
16922 +       vc_data.cmask = ~0ULL;
16923 +
16924 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16925 +               return -EFAULT;
16926 +       return 0;
16927 +}
16928 +
16929 +static int do_set_caps(struct vx_info *vxi,
16930 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16931 +{
16932 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16933 +
16934 +#if 0
16935 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16936 +               bcaps, bmask, ccaps, cmask);
16937 +#endif
16938 +       vxi->vx_bcaps = cap_t_from_caps(
16939 +               vs_mask_flags(bcold, bcaps, bmask));
16940 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16941 +
16942 +       return 0;
16943 +}
16944 +
16945 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16946 +{
16947 +       struct vcmd_ctx_caps_v1 vc_data;
16948 +
16949 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16950 +               return -EFAULT;
16951 +
16952 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16953 +}
16954 +
16955 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16956 +{
16957 +       struct vcmd_bcaps vc_data;
16958 +       int ret;
16959 +
16960 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16961 +       if (ret)
16962 +               return ret;
16963 +       vc_data.bmask = ~0ULL;
16964 +
16965 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16966 +               return -EFAULT;
16967 +       return 0;
16968 +}
16969 +
16970 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16971 +{
16972 +       struct vcmd_bcaps vc_data;
16973 +
16974 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16975 +               return -EFAULT;
16976 +
16977 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16978 +}
16979 +
16980 +
16981 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16982 +{
16983 +       struct vcmd_umask vc_data;
16984 +
16985 +       vc_data.umask = vxi->vx_umask;
16986 +       vc_data.mask = ~0ULL;
16987 +
16988 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16989 +               return -EFAULT;
16990 +       return 0;
16991 +}
16992 +
16993 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16994 +{
16995 +       struct vcmd_umask vc_data;
16996 +
16997 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16998 +               return -EFAULT;
16999 +
17000 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17001 +               vc_data.umask, vc_data.mask);
17002 +       return 0;
17003 +}
17004 +
17005 +
17006 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
17007 +{
17008 +       struct vcmd_wmask vc_data;
17009 +
17010 +       vc_data.wmask = vxi->vx_wmask;
17011 +       vc_data.mask = ~0ULL;
17012 +
17013 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17014 +               return -EFAULT;
17015 +       return 0;
17016 +}
17017 +
17018 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
17019 +{
17020 +       struct vcmd_wmask vc_data;
17021 +
17022 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17023 +               return -EFAULT;
17024 +
17025 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
17026 +               vc_data.wmask, vc_data.mask);
17027 +       return 0;
17028 +}
17029 +
17030 +
17031 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17032 +{
17033 +       struct vcmd_badness_v0 vc_data;
17034 +
17035 +       vc_data.bias = vxi->vx_badness_bias;
17036 +
17037 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17038 +               return -EFAULT;
17039 +       return 0;
17040 +}
17041 +
17042 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17043 +{
17044 +       struct vcmd_badness_v0 vc_data;
17045 +
17046 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17047 +               return -EFAULT;
17048 +
17049 +       vxi->vx_badness_bias = vc_data.bias;
17050 +       return 0;
17051 +}
17052 +
17053 +#include <linux/module.h>
17054 +
17055 +EXPORT_SYMBOL_GPL(free_vx_info);
17056 +
17057 diff -NurpP --minimal linux-3.4.32/kernel/vserver/cvirt.c linux-3.4.32-vs2.3.3.9/kernel/vserver/cvirt.c
17058 --- linux-3.4.32/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
17059 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/cvirt.c       2012-05-21 16:15:05.000000000 +0000
17060 @@ -0,0 +1,313 @@
17061 +/*
17062 + *  linux/kernel/vserver/cvirt.c
17063 + *
17064 + *  Virtual Server: Context Virtualization
17065 + *
17066 + *  Copyright (C) 2004-2007  Herbert Pötzl
17067 + *
17068 + *  V0.01  broken out from limit.c
17069 + *  V0.02  added utsname stuff
17070 + *  V0.03  changed vcmds to vxi arg
17071 + *
17072 + */
17073 +
17074 +#include <linux/types.h>
17075 +#include <linux/utsname.h>
17076 +#include <linux/vs_cvirt.h>
17077 +#include <linux/vserver/switch.h>
17078 +#include <linux/vserver/cvirt_cmd.h>
17079 +
17080 +#include <asm/uaccess.h>
17081 +
17082 +
17083 +void vx_vsi_boottime(struct timespec *boottime)
17084 +{
17085 +       struct vx_info *vxi = current_vx_info();
17086 +
17087 +       set_normalized_timespec(boottime,
17088 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
17089 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
17090 +       return;
17091 +}
17092 +
17093 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17094 +{
17095 +       struct vx_info *vxi = current_vx_info();
17096 +
17097 +       set_normalized_timespec(uptime,
17098 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17099 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17100 +       if (!idle)
17101 +               return;
17102 +       set_normalized_timespec(idle,
17103 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17104 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17105 +       return;
17106 +}
17107 +
17108 +uint64_t vx_idle_jiffies(void)
17109 +{
17110 +       return init_task.utime + init_task.stime;
17111 +}
17112 +
17113 +
17114 +
17115 +static inline uint32_t __update_loadavg(uint32_t load,
17116 +       int wsize, int delta, int n)
17117 +{
17118 +       unsigned long long calc, prev;
17119 +
17120 +       /* just set it to n */
17121 +       if (unlikely(delta >= wsize))
17122 +               return (n << FSHIFT);
17123 +
17124 +       calc = delta * n;
17125 +       calc <<= FSHIFT;
17126 +       prev = (wsize - delta);
17127 +       prev *= load;
17128 +       calc += prev;
17129 +       do_div(calc, wsize);
17130 +       return calc;
17131 +}
17132 +
17133 +
17134 +void vx_update_load(struct vx_info *vxi)
17135 +{
17136 +       uint32_t now, last, delta;
17137 +       unsigned int nr_running, nr_uninterruptible;
17138 +       unsigned int total;
17139 +       unsigned long flags;
17140 +
17141 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17142 +
17143 +       now = jiffies;
17144 +       last = vxi->cvirt.load_last;
17145 +       delta = now - last;
17146 +
17147 +       if (delta < 5*HZ)
17148 +               goto out;
17149 +
17150 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17151 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17152 +       total = nr_running + nr_uninterruptible;
17153 +
17154 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17155 +               60*HZ, delta, total);
17156 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17157 +               5*60*HZ, delta, total);
17158 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17159 +               15*60*HZ, delta, total);
17160 +
17161 +       vxi->cvirt.load_last = now;
17162 +out:
17163 +       atomic_inc(&vxi->cvirt.load_updates);
17164 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17165 +}
17166 +
17167 +
17168 +/*
17169 + * Commands to do_syslog:
17170 + *
17171 + *      0 -- Close the log.  Currently a NOP.
17172 + *      1 -- Open the log. Currently a NOP.
17173 + *      2 -- Read from the log.
17174 + *      3 -- Read all messages remaining in the ring buffer.
17175 + *      4 -- Read and clear all messages remaining in the ring buffer
17176 + *      5 -- Clear ring buffer.
17177 + *      6 -- Disable printk's to console
17178 + *      7 -- Enable printk's to console
17179 + *      8 -- Set level of messages printed to console
17180 + *      9 -- Return number of unread characters in the log buffer
17181 + *     10 -- Return size of the log buffer
17182 + */
17183 +int vx_do_syslog(int type, char __user *buf, int len)
17184 +{
17185 +       int error = 0;
17186 +       int do_clear = 0;
17187 +       struct vx_info *vxi = current_vx_info();
17188 +       struct _vx_syslog *log;
17189 +
17190 +       if (!vxi)
17191 +               return -EINVAL;
17192 +       log = &vxi->cvirt.syslog;
17193 +
17194 +       switch (type) {
17195 +       case 0:         /* Close log */
17196 +       case 1:         /* Open log */
17197 +               break;
17198 +       case 2:         /* Read from log */
17199 +               error = wait_event_interruptible(log->log_wait,
17200 +                       (log->log_start - log->log_end));
17201 +               if (error)
17202 +                       break;
17203 +               spin_lock_irq(&log->logbuf_lock);
17204 +               spin_unlock_irq(&log->logbuf_lock);
17205 +               break;
17206 +       case 4:         /* Read/clear last kernel messages */
17207 +               do_clear = 1;
17208 +               /* fall through */
17209 +       case 3:         /* Read last kernel messages */
17210 +               return 0;
17211 +
17212 +       case 5:         /* Clear ring buffer */
17213 +               return 0;
17214 +
17215 +       case 6:         /* Disable logging to console */
17216 +       case 7:         /* Enable logging to console */
17217 +       case 8:         /* Set level of messages printed to console */
17218 +               break;
17219 +
17220 +       case 9:         /* Number of chars in the log buffer */
17221 +               return 0;
17222 +       case 10:        /* Size of the log buffer */
17223 +               return 0;
17224 +       default:
17225 +               error = -EINVAL;
17226 +               break;
17227 +       }
17228 +       return error;
17229 +}
17230 +
17231 +
17232 +/* virtual host info names */
17233 +
17234 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17235 +{
17236 +       struct nsproxy *nsproxy;
17237 +       struct uts_namespace *uts;
17238 +
17239 +       if (id == VHIN_CONTEXT)
17240 +               return vxi->vx_name;
17241 +
17242 +       nsproxy = vxi->space[0].vx_nsproxy;
17243 +       if (!nsproxy)
17244 +               return NULL;
17245 +
17246 +       uts = nsproxy->uts_ns;
17247 +       if (!uts)
17248 +               return NULL;
17249 +
17250 +       switch (id) {
17251 +       case VHIN_SYSNAME:
17252 +               return uts->name.sysname;
17253 +       case VHIN_NODENAME:
17254 +               return uts->name.nodename;
17255 +       case VHIN_RELEASE:
17256 +               return uts->name.release;
17257 +       case VHIN_VERSION:
17258 +               return uts->name.version;
17259 +       case VHIN_MACHINE:
17260 +               return uts->name.machine;
17261 +       case VHIN_DOMAINNAME:
17262 +               return uts->name.domainname;
17263 +       default:
17264 +               return NULL;
17265 +       }
17266 +       return NULL;
17267 +}
17268 +
17269 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17270 +{
17271 +       struct vcmd_vhi_name_v0 vc_data;
17272 +       char *name;
17273 +
17274 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17275 +               return -EFAULT;
17276 +
17277 +       name = vx_vhi_name(vxi, vc_data.field);
17278 +       if (!name)
17279 +               return -EINVAL;
17280 +
17281 +       memcpy(name, vc_data.name, 65);
17282 +       return 0;
17283 +}
17284 +
17285 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17286 +{
17287 +       struct vcmd_vhi_name_v0 vc_data;
17288 +       char *name;
17289 +
17290 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17291 +               return -EFAULT;
17292 +
17293 +       name = vx_vhi_name(vxi, vc_data.field);
17294 +       if (!name)
17295 +               return -EINVAL;
17296 +
17297 +       memcpy(vc_data.name, name, 65);
17298 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17299 +               return -EFAULT;
17300 +       return 0;
17301 +}
17302 +
17303 +
17304 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17305 +{
17306 +       struct vcmd_virt_stat_v0 vc_data;
17307 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17308 +       struct timespec uptime;
17309 +
17310 +       do_posix_clock_monotonic_gettime(&uptime);
17311 +       set_normalized_timespec(&uptime,
17312 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17313 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17314 +
17315 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17316 +       vc_data.uptime = timespec_to_ns(&uptime);
17317 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17318 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17319 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17320 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17321 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17322 +       vc_data.load[0] = cvirt->load[0];
17323 +       vc_data.load[1] = cvirt->load[1];
17324 +       vc_data.load[2] = cvirt->load[2];
17325 +
17326 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17327 +               return -EFAULT;
17328 +       return 0;
17329 +}
17330 +
17331 +
17332 +#ifdef CONFIG_VSERVER_VTIME
17333 +
17334 +/* virtualized time base */
17335 +
17336 +void vx_adjust_timespec(struct timespec *ts)
17337 +{
17338 +       struct vx_info *vxi;
17339 +
17340 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17341 +               return;
17342 +
17343 +       vxi = current_vx_info();
17344 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17345 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17346 +
17347 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17348 +               ts->tv_sec++;
17349 +               ts->tv_nsec -= NSEC_PER_SEC;
17350 +       } else if (ts->tv_nsec < 0) {
17351 +               ts->tv_sec--;
17352 +               ts->tv_nsec += NSEC_PER_SEC;
17353 +       }
17354 +}
17355 +
17356 +int vx_settimeofday(const struct timespec *ts)
17357 +{
17358 +       struct timespec ats, delta;
17359 +       struct vx_info *vxi;
17360 +
17361 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17362 +               return do_settimeofday(ts);
17363 +
17364 +       getnstimeofday(&ats);
17365 +       delta = timespec_sub(*ts, ats);
17366 +
17367 +       vxi = current_vx_info();
17368 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17369 +       return 0;
17370 +}
17371 +
17372 +#endif
17373 +
17374 diff -NurpP --minimal linux-3.4.32/kernel/vserver/cvirt_init.h linux-3.4.32-vs2.3.3.9/kernel/vserver/cvirt_init.h
17375 --- linux-3.4.32/kernel/vserver/cvirt_init.h    1970-01-01 00:00:00.000000000 +0000
17376 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/cvirt_init.h  2012-05-21 16:15:05.000000000 +0000
17377 @@ -0,0 +1,70 @@
17378 +
17379 +
17380 +extern uint64_t vx_idle_jiffies(void);
17381 +
17382 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17383 +{
17384 +       uint64_t idle_jiffies = vx_idle_jiffies();
17385 +       uint64_t nsuptime;
17386 +
17387 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17388 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17389 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17390 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17391 +       cvirt->bias_ts.tv_sec = 0;
17392 +       cvirt->bias_ts.tv_nsec = 0;
17393 +
17394 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17395 +       atomic_set(&cvirt->nr_threads, 0);
17396 +       atomic_set(&cvirt->nr_running, 0);
17397 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17398 +       atomic_set(&cvirt->nr_onhold, 0);
17399 +
17400 +       spin_lock_init(&cvirt->load_lock);
17401 +       cvirt->load_last = jiffies;
17402 +       atomic_set(&cvirt->load_updates, 0);
17403 +       cvirt->load[0] = 0;
17404 +       cvirt->load[1] = 0;
17405 +       cvirt->load[2] = 0;
17406 +       atomic_set(&cvirt->total_forks, 0);
17407 +
17408 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17409 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17410 +       cvirt->syslog.log_start = 0;
17411 +       cvirt->syslog.log_end = 0;
17412 +       cvirt->syslog.con_start = 0;
17413 +       cvirt->syslog.logged_chars = 0;
17414 +}
17415 +
17416 +static inline
17417 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17418 +{
17419 +       // cvirt_pc->cpustat = { 0 };
17420 +}
17421 +
17422 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17423 +{
17424 +#ifdef CONFIG_VSERVER_WARN
17425 +       int value;
17426 +#endif
17427 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17428 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17429 +               cvirt, value);
17430 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17431 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17432 +               cvirt, value);
17433 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17434 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17435 +               cvirt, value);
17436 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17437 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17438 +               cvirt, value);
17439 +       return;
17440 +}
17441 +
17442 +static inline
17443 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17444 +{
17445 +       return;
17446 +}
17447 +
17448 diff -NurpP --minimal linux-3.4.32/kernel/vserver/cvirt_proc.h linux-3.4.32-vs2.3.3.9/kernel/vserver/cvirt_proc.h
17449 --- linux-3.4.32/kernel/vserver/cvirt_proc.h    1970-01-01 00:00:00.000000000 +0000
17450 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/cvirt_proc.h  2012-05-21 16:15:05.000000000 +0000
17451 @@ -0,0 +1,123 @@
17452 +#ifndef _VX_CVIRT_PROC_H
17453 +#define _VX_CVIRT_PROC_H
17454 +
17455 +#include <linux/nsproxy.h>
17456 +#include <linux/mnt_namespace.h>
17457 +#include <linux/ipc_namespace.h>
17458 +#include <linux/utsname.h>
17459 +#include <linux/ipc.h>
17460 +
17461 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17462 +
17463 +static inline
17464 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17465 +{
17466 +       struct mnt_namespace *ns;
17467 +       struct uts_namespace *uts;
17468 +       struct ipc_namespace *ipc;
17469 +       int length = 0;
17470 +
17471 +       if (!nsproxy)
17472 +               goto out;
17473 +
17474 +       length += sprintf(buffer + length,
17475 +               "NSProxy:\t%p [%p,%p,%p]\n",
17476 +               nsproxy, nsproxy->mnt_ns,
17477 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17478 +
17479 +       ns = nsproxy->mnt_ns;
17480 +       if (!ns)
17481 +               goto skip_ns;
17482 +
17483 +       length += vx_info_mnt_namespace(ns, buffer + length);
17484 +
17485 +skip_ns:
17486 +
17487 +       uts = nsproxy->uts_ns;
17488 +       if (!uts)
17489 +               goto skip_uts;
17490 +
17491 +       length += sprintf(buffer + length,
17492 +               "SysName:\t%.*s\n"
17493 +               "NodeName:\t%.*s\n"
17494 +               "Release:\t%.*s\n"
17495 +               "Version:\t%.*s\n"
17496 +               "Machine:\t%.*s\n"
17497 +               "DomainName:\t%.*s\n",
17498 +               __NEW_UTS_LEN, uts->name.sysname,
17499 +               __NEW_UTS_LEN, uts->name.nodename,
17500 +               __NEW_UTS_LEN, uts->name.release,
17501 +               __NEW_UTS_LEN, uts->name.version,
17502 +               __NEW_UTS_LEN, uts->name.machine,
17503 +               __NEW_UTS_LEN, uts->name.domainname);
17504 +skip_uts:
17505 +
17506 +       ipc = nsproxy->ipc_ns;
17507 +       if (!ipc)
17508 +               goto skip_ipc;
17509 +
17510 +       length += sprintf(buffer + length,
17511 +               "SEMS:\t\t%d %d %d %d  %d\n"
17512 +               "MSG:\t\t%d %d %d\n"
17513 +               "SHM:\t\t%lu %lu  %d %d\n",
17514 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17515 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17516 +               ipc->used_sems,
17517 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17518 +               (unsigned long)ipc->shm_ctlmax,
17519 +               (unsigned long)ipc->shm_ctlall,
17520 +               ipc->shm_ctlmni, ipc->shm_tot);
17521 +skip_ipc:
17522 +out:
17523 +       return length;
17524 +}
17525 +
17526 +
17527 +#include <linux/sched.h>
17528 +
17529 +#define LOAD_INT(x) ((x) >> FSHIFT)
17530 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17531 +
17532 +static inline
17533 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17534 +{
17535 +       int length = 0;
17536 +       int a, b, c;
17537 +
17538 +       length += sprintf(buffer + length,
17539 +               "BiasUptime:\t%lu.%02lu\n",
17540 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17541 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17542 +
17543 +       a = cvirt->load[0] + (FIXED_1 / 200);
17544 +       b = cvirt->load[1] + (FIXED_1 / 200);
17545 +       c = cvirt->load[2] + (FIXED_1 / 200);
17546 +       length += sprintf(buffer + length,
17547 +               "nr_threads:\t%d\n"
17548 +               "nr_running:\t%d\n"
17549 +               "nr_unintr:\t%d\n"
17550 +               "nr_onhold:\t%d\n"
17551 +               "load_updates:\t%d\n"
17552 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17553 +               "total_forks:\t%d\n",
17554 +               atomic_read(&cvirt->nr_threads),
17555 +               atomic_read(&cvirt->nr_running),
17556 +               atomic_read(&cvirt->nr_uninterruptible),
17557 +               atomic_read(&cvirt->nr_onhold),
17558 +               atomic_read(&cvirt->load_updates),
17559 +               LOAD_INT(a), LOAD_FRAC(a),
17560 +               LOAD_INT(b), LOAD_FRAC(b),
17561 +               LOAD_INT(c), LOAD_FRAC(c),
17562 +               atomic_read(&cvirt->total_forks));
17563 +       return length;
17564 +}
17565 +
17566 +static inline
17567 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17568 +       char *buffer, int cpu)
17569 +{
17570 +       int length = 0;
17571 +       return length;
17572 +}
17573 +
17574 +#endif /* _VX_CVIRT_PROC_H */
17575 diff -NurpP --minimal linux-3.4.32/kernel/vserver/debug.c linux-3.4.32-vs2.3.3.9/kernel/vserver/debug.c
17576 --- linux-3.4.32/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
17577 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/debug.c       2012-05-21 16:15:05.000000000 +0000
17578 @@ -0,0 +1,32 @@
17579 +/*
17580 + *  kernel/vserver/debug.c
17581 + *
17582 + *  Copyright (C) 2005-2007 Herbert Pötzl
17583 + *
17584 + *  V0.01  vx_info dump support
17585 + *
17586 + */
17587 +
17588 +#include <linux/module.h>
17589 +
17590 +#include <linux/vserver/context.h>
17591 +
17592 +
17593 +void   dump_vx_info(struct vx_info *vxi, int level)
17594 +{
17595 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17596 +               atomic_read(&vxi->vx_usecnt),
17597 +               atomic_read(&vxi->vx_tasks),
17598 +               vxi->vx_state);
17599 +       if (level > 0) {
17600 +               __dump_vx_limit(&vxi->limit);
17601 +               __dump_vx_sched(&vxi->sched);
17602 +               __dump_vx_cvirt(&vxi->cvirt);
17603 +               __dump_vx_cacct(&vxi->cacct);
17604 +       }
17605 +       printk("---\n");
17606 +}
17607 +
17608 +
17609 +EXPORT_SYMBOL_GPL(dump_vx_info);
17610 +
17611 diff -NurpP --minimal linux-3.4.32/kernel/vserver/device.c linux-3.4.32-vs2.3.3.9/kernel/vserver/device.c
17612 --- linux-3.4.32/kernel/vserver/device.c        1970-01-01 00:00:00.000000000 +0000
17613 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/device.c      2012-05-21 16:15:05.000000000 +0000
17614 @@ -0,0 +1,443 @@
17615 +/*
17616 + *  linux/kernel/vserver/device.c
17617 + *
17618 + *  Linux-VServer: Device Support
17619 + *
17620 + *  Copyright (C) 2006  Herbert Pötzl
17621 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17622 + *
17623 + *  V0.01  device mapping basics
17624 + *  V0.02  added defaults
17625 + *
17626 + */
17627 +
17628 +#include <linux/slab.h>
17629 +#include <linux/rcupdate.h>
17630 +#include <linux/fs.h>
17631 +#include <linux/namei.h>
17632 +#include <linux/hash.h>
17633 +
17634 +#include <asm/errno.h>
17635 +#include <asm/uaccess.h>
17636 +#include <linux/vserver/base.h>
17637 +#include <linux/vserver/debug.h>
17638 +#include <linux/vserver/context.h>
17639 +#include <linux/vserver/device.h>
17640 +#include <linux/vserver/device_cmd.h>
17641 +
17642 +
17643 +#define DMAP_HASH_BITS 4
17644 +
17645 +
17646 +struct vs_mapping {
17647 +       union {
17648 +               struct hlist_node hlist;
17649 +               struct list_head list;
17650 +       } u;
17651 +#define dm_hlist       u.hlist
17652 +#define dm_list                u.list
17653 +       xid_t xid;
17654 +       dev_t device;
17655 +       struct vx_dmap_target target;
17656 +};
17657 +
17658 +
17659 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17660 +
17661 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17662 +
17663 +static struct vx_dmap_target dmap_defaults[2] = {
17664 +       { .flags = DATTR_OPEN },
17665 +       { .flags = DATTR_OPEN },
17666 +};
17667 +
17668 +
17669 +struct kmem_cache *dmap_cachep __read_mostly;
17670 +
17671 +int __init dmap_cache_init(void)
17672 +{
17673 +       dmap_cachep = kmem_cache_create("dmap_cache",
17674 +               sizeof(struct vs_mapping), 0,
17675 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17676 +       return 0;
17677 +}
17678 +
17679 +__initcall(dmap_cache_init);
17680 +
17681 +
17682 +static inline unsigned int __hashval(dev_t dev, int bits)
17683 +{
17684 +       return hash_long((unsigned long)dev, bits);
17685 +}
17686 +
17687 +
17688 +/*     __hash_mapping()
17689 + *     add the mapping to the hash table
17690 + */
17691 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17692 +{
17693 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17694 +       struct hlist_head *head, *hash = dmap_main_hash;
17695 +       int device = vdm->device;
17696 +
17697 +       spin_lock(hash_lock);
17698 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17699 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17700 +
17701 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17702 +       hlist_add_head(&vdm->dm_hlist, head);
17703 +       spin_unlock(hash_lock);
17704 +}
17705 +
17706 +
17707 +static inline int __mode_to_default(umode_t mode)
17708 +{
17709 +       switch (mode) {
17710 +       case S_IFBLK:
17711 +               return 0;
17712 +       case S_IFCHR:
17713 +               return 1;
17714 +       default:
17715 +               BUG();
17716 +       }
17717 +}
17718 +
17719 +
17720 +/*     __set_default()
17721 + *     set a default
17722 + */
17723 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17724 +       struct vx_dmap_target *vdmt)
17725 +{
17726 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17727 +       spin_lock(hash_lock);
17728 +
17729 +       if (vxi)
17730 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17731 +       else
17732 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17733 +
17734 +
17735 +       spin_unlock(hash_lock);
17736 +
17737 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17738 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17739 +}
17740 +
17741 +
17742 +/*     __remove_default()
17743 + *     remove a default
17744 + */
17745 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17746 +{
17747 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17748 +       spin_lock(hash_lock);
17749 +
17750 +       if (vxi)
17751 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17752 +       else    /* remove == reset */
17753 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17754 +
17755 +       spin_unlock(hash_lock);
17756 +       return 0;
17757 +}
17758 +
17759 +
17760 +/*     __find_mapping()
17761 + *     find a mapping in the hash table
17762 + *
17763 + *     caller must hold hash_lock
17764 + */
17765 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17766 +       struct vs_mapping **local, struct vs_mapping **global)
17767 +{
17768 +       struct hlist_head *hash = dmap_main_hash;
17769 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17770 +       struct hlist_node *pos;
17771 +       struct vs_mapping *vdm;
17772 +
17773 +       *local = NULL;
17774 +       if (global)
17775 +               *global = NULL;
17776 +
17777 +       hlist_for_each(pos, head) {
17778 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17779 +
17780 +               if ((vdm->device == device) &&
17781 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17782 +                       if (vdm->xid == xid) {
17783 +                               *local = vdm;
17784 +                               return 1;
17785 +                       } else if (global && vdm->xid == 0)
17786 +                               *global = vdm;
17787 +               }
17788 +       }
17789 +
17790 +       if (global && *global)
17791 +               return 0;
17792 +       else
17793 +               return -ENOENT;
17794 +}
17795 +
17796 +
17797 +/*     __lookup_mapping()
17798 + *     find a mapping and store the result in target and flags
17799 + */
17800 +static inline int __lookup_mapping(struct vx_info *vxi,
17801 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17802 +{
17803 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17804 +       struct vs_mapping *vdm, *global;
17805 +       struct vx_dmap_target *vdmt;
17806 +       int ret = 0;
17807 +       xid_t xid = vxi->vx_id;
17808 +       int index;
17809 +
17810 +       spin_lock(hash_lock);
17811 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17812 +               ret = 1;
17813 +               vdmt = &vdm->target;
17814 +               goto found;
17815 +       }
17816 +
17817 +       index = __mode_to_default(mode);
17818 +       if (vxi && vxi->dmap.targets[index].flags) {
17819 +               ret = 2;
17820 +               vdmt = &vxi->dmap.targets[index];
17821 +       } else if (global) {
17822 +               ret = 3;
17823 +               vdmt = &global->target;
17824 +               goto found;
17825 +       } else {
17826 +               ret = 4;
17827 +               vdmt = &dmap_defaults[index];
17828 +       }
17829 +
17830 +found:
17831 +       if (target && (vdmt->flags & DATTR_REMAP))
17832 +               *target = vdmt->target;
17833 +       else if (target)
17834 +               *target = device;
17835 +       if (flags)
17836 +               *flags = vdmt->flags;
17837 +
17838 +       spin_unlock(hash_lock);
17839 +
17840 +       return ret;
17841 +}
17842 +
17843 +
17844 +/*     __remove_mapping()
17845 + *     remove a mapping from the hash table
17846 + */
17847 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17848 +       umode_t mode)
17849 +{
17850 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17851 +       struct vs_mapping *vdm = NULL;
17852 +       int ret = 0;
17853 +
17854 +       spin_lock(hash_lock);
17855 +
17856 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17857 +               NULL);
17858 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17859 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17860 +       if (ret < 0)
17861 +               goto out;
17862 +       hlist_del(&vdm->dm_hlist);
17863 +
17864 +out:
17865 +       spin_unlock(hash_lock);
17866 +       if (vdm)
17867 +               kmem_cache_free(dmap_cachep, vdm);
17868 +       return ret;
17869 +}
17870 +
17871 +
17872 +
17873 +int vs_map_device(struct vx_info *vxi,
17874 +       dev_t device, dev_t *target, umode_t mode)
17875 +{
17876 +       int ret, flags = DATTR_MASK;
17877 +
17878 +       if (!vxi) {
17879 +               if (target)
17880 +                       *target = device;
17881 +               goto out;
17882 +       }
17883 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17884 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17885 +               device, target ? *target : 0, flags, mode, ret);
17886 +out:
17887 +       return (flags & DATTR_MASK);
17888 +}
17889 +
17890 +
17891 +
17892 +static int do_set_mapping(struct vx_info *vxi,
17893 +       dev_t device, dev_t target, int flags, umode_t mode)
17894 +{
17895 +       if (device) {
17896 +               struct vs_mapping *new;
17897 +
17898 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17899 +               if (!new)
17900 +                       return -ENOMEM;
17901 +
17902 +               INIT_HLIST_NODE(&new->dm_hlist);
17903 +               new->device = device;
17904 +               new->target.target = target;
17905 +               new->target.flags = flags | mode;
17906 +               new->xid = (vxi ? vxi->vx_id : 0);
17907 +
17908 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17909 +               __hash_mapping(vxi, new);
17910 +       } else {
17911 +               struct vx_dmap_target new = {
17912 +                       .target = target,
17913 +                       .flags = flags | mode,
17914 +               };
17915 +               __set_default(vxi, mode, &new);
17916 +       }
17917 +       return 0;
17918 +}
17919 +
17920 +
17921 +static int do_unset_mapping(struct vx_info *vxi,
17922 +       dev_t device, dev_t target, int flags, umode_t mode)
17923 +{
17924 +       int ret = -EINVAL;
17925 +
17926 +       if (device) {
17927 +               ret = __remove_mapping(vxi, device, mode);
17928 +               if (ret < 0)
17929 +                       goto out;
17930 +       } else {
17931 +               ret = __remove_default(vxi, mode);
17932 +               if (ret < 0)
17933 +                       goto out;
17934 +       }
17935 +
17936 +out:
17937 +       return ret;
17938 +}
17939 +
17940 +
17941 +static inline int __user_device(const char __user *name, dev_t *dev,
17942 +       umode_t *mode)
17943 +{
17944 +       struct nameidata nd;
17945 +       int ret;
17946 +
17947 +       if (!name) {
17948 +               *dev = 0;
17949 +               return 0;
17950 +       }
17951 +       ret = user_lpath(name, &nd.path);
17952 +       if (ret)
17953 +               return ret;
17954 +       if (nd.path.dentry->d_inode) {
17955 +               *dev = nd.path.dentry->d_inode->i_rdev;
17956 +               *mode = nd.path.dentry->d_inode->i_mode;
17957 +       }
17958 +       path_put(&nd.path);
17959 +       return 0;
17960 +}
17961 +
17962 +static inline int __mapping_mode(dev_t device, dev_t target,
17963 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17964 +{
17965 +       if (device)
17966 +               *mode = device_mode & S_IFMT;
17967 +       else if (target)
17968 +               *mode = target_mode & S_IFMT;
17969 +       else
17970 +               return -EINVAL;
17971 +
17972 +       /* if both given, device and target mode have to match */
17973 +       if (device && target &&
17974 +               ((device_mode ^ target_mode) & S_IFMT))
17975 +               return -EINVAL;
17976 +       return 0;
17977 +}
17978 +
17979 +
17980 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17981 +       const char __user *target_path, int flags, int set)
17982 +{
17983 +       dev_t device = ~0, target = ~0;
17984 +       umode_t device_mode = 0, target_mode = 0, mode;
17985 +       int ret;
17986 +
17987 +       ret = __user_device(device_path, &device, &device_mode);
17988 +       if (ret)
17989 +               return ret;
17990 +       ret = __user_device(target_path, &target, &target_mode);
17991 +       if (ret)
17992 +               return ret;
17993 +
17994 +       ret = __mapping_mode(device, target,
17995 +               device_mode, target_mode, &mode);
17996 +       if (ret)
17997 +               return ret;
17998 +
17999 +       if (set)
18000 +               return do_set_mapping(vxi, device, target,
18001 +                       flags, mode);
18002 +       else
18003 +               return do_unset_mapping(vxi, device, target,
18004 +                       flags, mode);
18005 +}
18006 +
18007 +
18008 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18009 +{
18010 +       struct vcmd_set_mapping_v0 vc_data;
18011 +
18012 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18013 +               return -EFAULT;
18014 +
18015 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18016 +               vc_data.flags, 1);
18017 +}
18018 +
18019 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18020 +{
18021 +       struct vcmd_set_mapping_v0 vc_data;
18022 +
18023 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18024 +               return -EFAULT;
18025 +
18026 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18027 +               vc_data.flags, 0);
18028 +}
18029 +
18030 +
18031 +#ifdef CONFIG_COMPAT
18032 +
18033 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18034 +{
18035 +       struct vcmd_set_mapping_v0_x32 vc_data;
18036 +
18037 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18038 +               return -EFAULT;
18039 +
18040 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18041 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18042 +}
18043 +
18044 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18045 +{
18046 +       struct vcmd_set_mapping_v0_x32 vc_data;
18047 +
18048 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18049 +               return -EFAULT;
18050 +
18051 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18052 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18053 +}
18054 +
18055 +#endif /* CONFIG_COMPAT */
18056 +
18057 +
18058 diff -NurpP --minimal linux-3.4.32/kernel/vserver/dlimit.c linux-3.4.32-vs2.3.3.9/kernel/vserver/dlimit.c
18059 --- linux-3.4.32/kernel/vserver/dlimit.c        1970-01-01 00:00:00.000000000 +0000
18060 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/dlimit.c      2012-05-21 16:15:05.000000000 +0000
18061 @@ -0,0 +1,531 @@
18062 +/*
18063 + *  linux/kernel/vserver/dlimit.c
18064 + *
18065 + *  Virtual Server: Context Disk Limits
18066 + *
18067 + *  Copyright (C) 2004-2009  Herbert Pötzl
18068 + *
18069 + *  V0.01  initial version
18070 + *  V0.02  compat32 splitup
18071 + *  V0.03  extended interface
18072 + *
18073 + */
18074 +
18075 +#include <linux/statfs.h>
18076 +#include <linux/sched.h>
18077 +#include <linux/namei.h>
18078 +#include <linux/vs_tag.h>
18079 +#include <linux/vs_dlimit.h>
18080 +#include <linux/vserver/dlimit_cmd.h>
18081 +#include <linux/slab.h>
18082 +// #include <linux/gfp.h>
18083 +
18084 +#include <asm/uaccess.h>
18085 +
18086 +/*     __alloc_dl_info()
18087 +
18088 +       * allocate an initialized dl_info struct
18089 +       * doesn't make it visible (hash)                        */
18090 +
18091 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18092 +{
18093 +       struct dl_info *new = NULL;
18094 +
18095 +       vxdprintk(VXD_CBIT(dlim, 5),
18096 +               "alloc_dl_info(%p,%d)*", sb, tag);
18097 +
18098 +       /* would this benefit from a slab cache? */
18099 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18100 +       if (!new)
18101 +               return 0;
18102 +
18103 +       memset(new, 0, sizeof(struct dl_info));
18104 +       new->dl_tag = tag;
18105 +       new->dl_sb = sb;
18106 +       // INIT_RCU_HEAD(&new->dl_rcu);
18107 +       INIT_HLIST_NODE(&new->dl_hlist);
18108 +       spin_lock_init(&new->dl_lock);
18109 +       atomic_set(&new->dl_refcnt, 0);
18110 +       atomic_set(&new->dl_usecnt, 0);
18111 +
18112 +       /* rest of init goes here */
18113 +
18114 +       vxdprintk(VXD_CBIT(dlim, 4),
18115 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18116 +       return new;
18117 +}
18118 +
18119 +/*     __dealloc_dl_info()
18120 +
18121 +       * final disposal of dl_info                             */
18122 +
18123 +static void __dealloc_dl_info(struct dl_info *dli)
18124 +{
18125 +       vxdprintk(VXD_CBIT(dlim, 4),
18126 +               "dealloc_dl_info(%p)", dli);
18127 +
18128 +       dli->dl_hlist.next = LIST_POISON1;
18129 +       dli->dl_tag = -1;
18130 +       dli->dl_sb = 0;
18131 +
18132 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18133 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18134 +
18135 +       kfree(dli);
18136 +}
18137 +
18138 +
18139 +/*     hash table for dl_info hash */
18140 +
18141 +#define DL_HASH_SIZE   13
18142 +
18143 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18144 +
18145 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18146 +
18147 +
18148 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18149 +{
18150 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18151 +}
18152 +
18153 +
18154 +
18155 +/*     __hash_dl_info()
18156 +
18157 +       * add the dli to the global hash table
18158 +       * requires the hash_lock to be held                     */
18159 +
18160 +static inline void __hash_dl_info(struct dl_info *dli)
18161 +{
18162 +       struct hlist_head *head;
18163 +
18164 +       vxdprintk(VXD_CBIT(dlim, 6),
18165 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18166 +       get_dl_info(dli);
18167 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18168 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18169 +}
18170 +
18171 +/*     __unhash_dl_info()
18172 +
18173 +       * remove the dli from the global hash table
18174 +       * requires the hash_lock to be held                     */
18175 +
18176 +static inline void __unhash_dl_info(struct dl_info *dli)
18177 +{
18178 +       vxdprintk(VXD_CBIT(dlim, 6),
18179 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18180 +       hlist_del_rcu(&dli->dl_hlist);
18181 +       put_dl_info(dli);
18182 +}
18183 +
18184 +
18185 +/*     __lookup_dl_info()
18186 +
18187 +       * requires the rcu_read_lock()
18188 +       * doesn't increment the dl_refcnt                       */
18189 +
18190 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18191 +{
18192 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18193 +       struct hlist_node *pos;
18194 +       struct dl_info *dli;
18195 +
18196 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18197 +
18198 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18199 +                       return dli;
18200 +               }
18201 +       }
18202 +       return NULL;
18203 +}
18204 +
18205 +
18206 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18207 +{
18208 +       struct dl_info *dli;
18209 +
18210 +       rcu_read_lock();
18211 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18212 +       vxdprintk(VXD_CBIT(dlim, 7),
18213 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18214 +       rcu_read_unlock();
18215 +       return dli;
18216 +}
18217 +
18218 +void rcu_free_dl_info(struct rcu_head *head)
18219 +{
18220 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18221 +       int usecnt, refcnt;
18222 +
18223 +       BUG_ON(!dli || !head);
18224 +
18225 +       usecnt = atomic_read(&dli->dl_usecnt);
18226 +       BUG_ON(usecnt < 0);
18227 +
18228 +       refcnt = atomic_read(&dli->dl_refcnt);
18229 +       BUG_ON(refcnt < 0);
18230 +
18231 +       vxdprintk(VXD_CBIT(dlim, 3),
18232 +               "rcu_free_dl_info(%p)", dli);
18233 +       if (!usecnt)
18234 +               __dealloc_dl_info(dli);
18235 +       else
18236 +               printk("!!! rcu didn't free\n");
18237 +}
18238 +
18239 +
18240 +
18241 +
18242 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18243 +       uint32_t flags, int add)
18244 +{
18245 +       struct path path;
18246 +       int ret;
18247 +
18248 +       ret = user_lpath(name, &path);
18249 +       if (!ret) {
18250 +               struct super_block *sb;
18251 +               struct dl_info *dli;
18252 +
18253 +               ret = -EINVAL;
18254 +               if (!path.dentry->d_inode)
18255 +                       goto out_release;
18256 +               if (!(sb = path.dentry->d_inode->i_sb))
18257 +                       goto out_release;
18258 +
18259 +               if (add) {
18260 +                       dli = __alloc_dl_info(sb, id);
18261 +                       spin_lock(&dl_info_hash_lock);
18262 +
18263 +                       ret = -EEXIST;
18264 +                       if (__lookup_dl_info(sb, id))
18265 +                               goto out_unlock;
18266 +                       __hash_dl_info(dli);
18267 +                       dli = NULL;
18268 +               } else {
18269 +                       spin_lock(&dl_info_hash_lock);
18270 +                       dli = __lookup_dl_info(sb, id);
18271 +
18272 +                       ret = -ESRCH;
18273 +                       if (!dli)
18274 +                               goto out_unlock;
18275 +                       __unhash_dl_info(dli);
18276 +               }
18277 +               ret = 0;
18278 +       out_unlock:
18279 +               spin_unlock(&dl_info_hash_lock);
18280 +               if (add && dli)
18281 +                       __dealloc_dl_info(dli);
18282 +       out_release:
18283 +               path_put(&path);
18284 +       }
18285 +       return ret;
18286 +}
18287 +
18288 +int vc_add_dlimit(uint32_t id, void __user *data)
18289 +{
18290 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18291 +
18292 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18293 +               return -EFAULT;
18294 +
18295 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18296 +}
18297 +
18298 +int vc_rem_dlimit(uint32_t id, void __user *data)
18299 +{
18300 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18301 +
18302 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18303 +               return -EFAULT;
18304 +
18305 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18306 +}
18307 +
18308 +#ifdef CONFIG_COMPAT
18309 +
18310 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18311 +{
18312 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18313 +
18314 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18315 +               return -EFAULT;
18316 +
18317 +       return do_addrem_dlimit(id,
18318 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18319 +}
18320 +
18321 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18322 +{
18323 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18324 +
18325 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18326 +               return -EFAULT;
18327 +
18328 +       return do_addrem_dlimit(id,
18329 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18330 +}
18331 +
18332 +#endif /* CONFIG_COMPAT */
18333 +
18334 +
18335 +static inline
18336 +int do_set_dlimit(uint32_t id, const char __user *name,
18337 +       uint32_t space_used, uint32_t space_total,
18338 +       uint32_t inodes_used, uint32_t inodes_total,
18339 +       uint32_t reserved, uint32_t flags)
18340 +{
18341 +       struct path path;
18342 +       int ret;
18343 +
18344 +       ret = user_lpath(name, &path);
18345 +       if (!ret) {
18346 +               struct super_block *sb;
18347 +               struct dl_info *dli;
18348 +
18349 +               ret = -EINVAL;
18350 +               if (!path.dentry->d_inode)
18351 +                       goto out_release;
18352 +               if (!(sb = path.dentry->d_inode->i_sb))
18353 +                       goto out_release;
18354 +
18355 +               /* sanity checks */
18356 +               if ((reserved != CDLIM_KEEP &&
18357 +                       reserved > 100) ||
18358 +                       (inodes_used != CDLIM_KEEP &&
18359 +                       inodes_used > inodes_total) ||
18360 +                       (space_used != CDLIM_KEEP &&
18361 +                       space_used > space_total))
18362 +                       goto out_release;
18363 +
18364 +               ret = -ESRCH;
18365 +               dli = locate_dl_info(sb, id);
18366 +               if (!dli)
18367 +                       goto out_release;
18368 +
18369 +               spin_lock(&dli->dl_lock);
18370 +
18371 +               if (inodes_used != CDLIM_KEEP)
18372 +                       dli->dl_inodes_used = inodes_used;
18373 +               if (inodes_total != CDLIM_KEEP)
18374 +                       dli->dl_inodes_total = inodes_total;
18375 +               if (space_used != CDLIM_KEEP)
18376 +                       dli->dl_space_used = dlimit_space_32to64(
18377 +                               space_used, flags, DLIMS_USED);
18378 +
18379 +               if (space_total == CDLIM_INFINITY)
18380 +                       dli->dl_space_total = DLIM_INFINITY;
18381 +               else if (space_total != CDLIM_KEEP)
18382 +                       dli->dl_space_total = dlimit_space_32to64(
18383 +                               space_total, flags, DLIMS_TOTAL);
18384 +
18385 +               if (reserved != CDLIM_KEEP)
18386 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18387 +
18388 +               spin_unlock(&dli->dl_lock);
18389 +
18390 +               put_dl_info(dli);
18391 +               ret = 0;
18392 +
18393 +       out_release:
18394 +               path_put(&path);
18395 +       }
18396 +       return ret;
18397 +}
18398 +
18399 +int vc_set_dlimit(uint32_t id, void __user *data)
18400 +{
18401 +       struct vcmd_ctx_dlimit_v0 vc_data;
18402 +
18403 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18404 +               return -EFAULT;
18405 +
18406 +       return do_set_dlimit(id, vc_data.name,
18407 +               vc_data.space_used, vc_data.space_total,
18408 +               vc_data.inodes_used, vc_data.inodes_total,
18409 +               vc_data.reserved, vc_data.flags);
18410 +}
18411 +
18412 +#ifdef CONFIG_COMPAT
18413 +
18414 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18415 +{
18416 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18417 +
18418 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18419 +               return -EFAULT;
18420 +
18421 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18422 +               vc_data.space_used, vc_data.space_total,
18423 +               vc_data.inodes_used, vc_data.inodes_total,
18424 +               vc_data.reserved, vc_data.flags);
18425 +}
18426 +
18427 +#endif /* CONFIG_COMPAT */
18428 +
18429 +
18430 +static inline
18431 +int do_get_dlimit(uint32_t id, const char __user *name,
18432 +       uint32_t *space_used, uint32_t *space_total,
18433 +       uint32_t *inodes_used, uint32_t *inodes_total,
18434 +       uint32_t *reserved, uint32_t *flags)
18435 +{
18436 +       struct path path;
18437 +       int ret;
18438 +
18439 +       ret = user_lpath(name, &path);
18440 +       if (!ret) {
18441 +               struct super_block *sb;
18442 +               struct dl_info *dli;
18443 +
18444 +               ret = -EINVAL;
18445 +               if (!path.dentry->d_inode)
18446 +                       goto out_release;
18447 +               if (!(sb = path.dentry->d_inode->i_sb))
18448 +                       goto out_release;
18449 +
18450 +               ret = -ESRCH;
18451 +               dli = locate_dl_info(sb, id);
18452 +               if (!dli)
18453 +                       goto out_release;
18454 +
18455 +               spin_lock(&dli->dl_lock);
18456 +               *inodes_used = dli->dl_inodes_used;
18457 +               *inodes_total = dli->dl_inodes_total;
18458 +
18459 +               *space_used = dlimit_space_64to32(
18460 +                       dli->dl_space_used, flags, DLIMS_USED);
18461 +
18462 +               if (dli->dl_space_total == DLIM_INFINITY)
18463 +                       *space_total = CDLIM_INFINITY;
18464 +               else
18465 +                       *space_total = dlimit_space_64to32(
18466 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18467 +
18468 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18469 +               spin_unlock(&dli->dl_lock);
18470 +
18471 +               put_dl_info(dli);
18472 +               ret = -EFAULT;
18473 +
18474 +               ret = 0;
18475 +       out_release:
18476 +               path_put(&path);
18477 +       }
18478 +       return ret;
18479 +}
18480 +
18481 +
18482 +int vc_get_dlimit(uint32_t id, void __user *data)
18483 +{
18484 +       struct vcmd_ctx_dlimit_v0 vc_data;
18485 +       int ret;
18486 +
18487 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18488 +               return -EFAULT;
18489 +
18490 +       ret = do_get_dlimit(id, vc_data.name,
18491 +               &vc_data.space_used, &vc_data.space_total,
18492 +               &vc_data.inodes_used, &vc_data.inodes_total,
18493 +               &vc_data.reserved, &vc_data.flags);
18494 +       if (ret)
18495 +               return ret;
18496 +
18497 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18498 +               return -EFAULT;
18499 +       return 0;
18500 +}
18501 +
18502 +#ifdef CONFIG_COMPAT
18503 +
18504 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18505 +{
18506 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18507 +       int ret;
18508 +
18509 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18510 +               return -EFAULT;
18511 +
18512 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18513 +               &vc_data.space_used, &vc_data.space_total,
18514 +               &vc_data.inodes_used, &vc_data.inodes_total,
18515 +               &vc_data.reserved, &vc_data.flags);
18516 +       if (ret)
18517 +               return ret;
18518 +
18519 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18520 +               return -EFAULT;
18521 +       return 0;
18522 +}
18523 +
18524 +#endif /* CONFIG_COMPAT */
18525 +
18526 +
18527 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18528 +{
18529 +       struct dl_info *dli;
18530 +       __u64 blimit, bfree, bavail;
18531 +       __u32 ifree;
18532 +
18533 +       dli = locate_dl_info(sb, dx_current_tag());
18534 +       if (!dli)
18535 +               return;
18536 +
18537 +       spin_lock(&dli->dl_lock);
18538 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18539 +               goto no_ilim;
18540 +
18541 +       /* reduce max inodes available to limit */
18542 +       if (buf->f_files > dli->dl_inodes_total)
18543 +               buf->f_files = dli->dl_inodes_total;
18544 +
18545 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18546 +       /* reduce free inodes to min */
18547 +       if (ifree < buf->f_ffree)
18548 +               buf->f_ffree = ifree;
18549 +
18550 +no_ilim:
18551 +       if (dli->dl_space_total == DLIM_INFINITY)
18552 +               goto no_blim;
18553 +
18554 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18555 +
18556 +       if (dli->dl_space_total < dli->dl_space_used)
18557 +               bfree = 0;
18558 +       else
18559 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18560 +                       >> sb->s_blocksize_bits;
18561 +
18562 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18563 +       if (bavail < dli->dl_space_used)
18564 +               bavail = 0;
18565 +       else
18566 +               bavail = (bavail - dli->dl_space_used)
18567 +                       >> sb->s_blocksize_bits;
18568 +
18569 +       /* reduce max space available to limit */
18570 +       if (buf->f_blocks > blimit)
18571 +               buf->f_blocks = blimit;
18572 +
18573 +       /* reduce free space to min */
18574 +       if (bfree < buf->f_bfree)
18575 +               buf->f_bfree = bfree;
18576 +
18577 +       /* reduce avail space to min */
18578 +       if (bavail < buf->f_bavail)
18579 +               buf->f_bavail = bavail;
18580 +
18581 +no_blim:
18582 +       spin_unlock(&dli->dl_lock);
18583 +       put_dl_info(dli);
18584 +
18585 +       return;
18586 +}
18587 +
18588 +#include <linux/module.h>
18589 +
18590 +EXPORT_SYMBOL_GPL(locate_dl_info);
18591 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18592 +
18593 diff -NurpP --minimal linux-3.4.32/kernel/vserver/helper.c linux-3.4.32-vs2.3.3.9/kernel/vserver/helper.c
18594 --- linux-3.4.32/kernel/vserver/helper.c        1970-01-01 00:00:00.000000000 +0000
18595 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/helper.c      2012-09-16 18:49:44.000000000 +0000
18596 @@ -0,0 +1,229 @@
18597 +/*
18598 + *  linux/kernel/vserver/helper.c
18599 + *
18600 + *  Virtual Context Support
18601 + *
18602 + *  Copyright (C) 2004-2007  Herbert Pötzl
18603 + *
18604 + *  V0.01  basic helper
18605 + *
18606 + */
18607 +
18608 +#include <linux/kmod.h>
18609 +#include <linux/reboot.h>
18610 +#include <linux/vs_context.h>
18611 +#include <linux/vs_network.h>
18612 +#include <linux/vserver/signal.h>
18613 +
18614 +
18615 +char vshelper_path[255] = "/sbin/vshelper";
18616 +
18617 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18618 +{
18619 +       current->flags &= ~PF_THREAD_BOUND;
18620 +       return 0;
18621 +}
18622 +
18623 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18624 +{
18625 +       int ret;
18626 +
18627 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18628 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18629 +               vshelper_init, NULL, NULL))) {
18630 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18631 +                       name, argv[1], argv[2],
18632 +                       sync ? "sync" : "async", ret);
18633 +       }
18634 +       vxdprintk(VXD_CBIT(switch, 4),
18635 +               "%s: (%s %s) returned %s with %d",
18636 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18637 +       return ret;
18638 +}
18639 +
18640 +/*
18641 + *      vshelper path is set via /proc/sys
18642 + *      invoked by vserver sys_reboot(), with
18643 + *      the following arguments
18644 + *
18645 + *      argv [0] = vshelper_path;
18646 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18647 + *      argv [2] = context identifier
18648 + *
18649 + *      envp [*] = type-specific parameters
18650 + */
18651 +
18652 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18653 +{
18654 +       char id_buf[8], cmd_buf[16];
18655 +       char uid_buf[16], pid_buf[16];
18656 +       int ret;
18657 +
18658 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18659 +       char *envp[] = {"HOME=/", "TERM=linux",
18660 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18661 +                       uid_buf, pid_buf, cmd_buf, 0};
18662 +
18663 +       if (vx_info_state(vxi, VXS_HELPER))
18664 +               return -EAGAIN;
18665 +       vxi->vx_state |= VXS_HELPER;
18666 +
18667 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18668 +
18669 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18670 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18671 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18672 +
18673 +       switch (cmd) {
18674 +       case LINUX_REBOOT_CMD_RESTART:
18675 +               argv[1] = "restart";
18676 +               break;
18677 +
18678 +       case LINUX_REBOOT_CMD_HALT:
18679 +               argv[1] = "halt";
18680 +               break;
18681 +
18682 +       case LINUX_REBOOT_CMD_POWER_OFF:
18683 +               argv[1] = "poweroff";
18684 +               break;
18685 +
18686 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18687 +               argv[1] = "swsusp";
18688 +               break;
18689 +
18690 +       case LINUX_REBOOT_CMD_OOM:
18691 +               argv[1] = "oom";
18692 +               break;
18693 +
18694 +       default:
18695 +               vxi->vx_state &= ~VXS_HELPER;
18696 +               return 0;
18697 +       }
18698 +
18699 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18700 +       vxi->vx_state &= ~VXS_HELPER;
18701 +       __wakeup_vx_info(vxi);
18702 +       return (ret) ? -EPERM : 0;
18703 +}
18704 +
18705 +
18706 +long vs_reboot(unsigned int cmd, void __user *arg)
18707 +{
18708 +       struct vx_info *vxi = current_vx_info();
18709 +       long ret = 0;
18710 +
18711 +       vxdprintk(VXD_CBIT(misc, 5),
18712 +               "vs_reboot(%p[#%d],%u)",
18713 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18714 +
18715 +       ret = vs_reboot_helper(vxi, cmd, arg);
18716 +       if (ret)
18717 +               return ret;
18718 +
18719 +       vxi->reboot_cmd = cmd;
18720 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18721 +               switch (cmd) {
18722 +               case LINUX_REBOOT_CMD_RESTART:
18723 +               case LINUX_REBOOT_CMD_HALT:
18724 +               case LINUX_REBOOT_CMD_POWER_OFF:
18725 +                       vx_info_kill(vxi, 0, SIGKILL);
18726 +                       vx_info_kill(vxi, 1, SIGKILL);
18727 +               default:
18728 +                       break;
18729 +               }
18730 +       }
18731 +       return 0;
18732 +}
18733 +
18734 +long vs_oom_action(unsigned int cmd)
18735 +{
18736 +       struct vx_info *vxi = current_vx_info();
18737 +       long ret = 0;
18738 +
18739 +       vxdprintk(VXD_CBIT(misc, 5),
18740 +               "vs_oom_action(%p[#%d],%u)",
18741 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18742 +
18743 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18744 +       if (ret)
18745 +               return ret;
18746 +
18747 +       vxi->reboot_cmd = cmd;
18748 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18749 +               vx_info_kill(vxi, 0, SIGKILL);
18750 +               vx_info_kill(vxi, 1, SIGKILL);
18751 +       }
18752 +       return 0;
18753 +}
18754 +
18755 +/*
18756 + *      argv [0] = vshelper_path;
18757 + *      argv [1] = action: "startup", "shutdown"
18758 + *      argv [2] = context identifier
18759 + *
18760 + *      envp [*] = type-specific parameters
18761 + */
18762 +
18763 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18764 +{
18765 +       char id_buf[8], cmd_buf[16];
18766 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18767 +       char *envp[] = {"HOME=/", "TERM=linux",
18768 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18769 +
18770 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18771 +               return 0;
18772 +
18773 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18774 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18775 +
18776 +       switch (cmd) {
18777 +       case VSC_STARTUP:
18778 +               argv[1] = "startup";
18779 +               break;
18780 +       case VSC_SHUTDOWN:
18781 +               argv[1] = "shutdown";
18782 +               break;
18783 +       default:
18784 +               return 0;
18785 +       }
18786 +
18787 +       return do_vshelper(vshelper_path, argv, envp, 1);
18788 +}
18789 +
18790 +
18791 +/*
18792 + *      argv [0] = vshelper_path;
18793 + *      argv [1] = action: "netup", "netdown"
18794 + *      argv [2] = context identifier
18795 + *
18796 + *      envp [*] = type-specific parameters
18797 + */
18798 +
18799 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18800 +{
18801 +       char id_buf[8], cmd_buf[16];
18802 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18803 +       char *envp[] = {"HOME=/", "TERM=linux",
18804 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18805 +
18806 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18807 +               return 0;
18808 +
18809 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18810 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18811 +
18812 +       switch (cmd) {
18813 +       case VSC_NETUP:
18814 +               argv[1] = "netup";
18815 +               break;
18816 +       case VSC_NETDOWN:
18817 +               argv[1] = "netdown";
18818 +               break;
18819 +       default:
18820 +               return 0;
18821 +       }
18822 +
18823 +       return do_vshelper(vshelper_path, argv, envp, 1);
18824 +}
18825 +
18826 diff -NurpP --minimal linux-3.4.32/kernel/vserver/history.c linux-3.4.32-vs2.3.3.9/kernel/vserver/history.c
18827 --- linux-3.4.32/kernel/vserver/history.c       1970-01-01 00:00:00.000000000 +0000
18828 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/history.c     2012-05-21 16:15:05.000000000 +0000
18829 @@ -0,0 +1,258 @@
18830 +/*
18831 + *  kernel/vserver/history.c
18832 + *
18833 + *  Virtual Context History Backtrace
18834 + *
18835 + *  Copyright (C) 2004-2007  Herbert Pötzl
18836 + *
18837 + *  V0.01  basic structure
18838 + *  V0.02  hash/unhash and trace
18839 + *  V0.03  preemption fixes
18840 + *
18841 + */
18842 +
18843 +#include <linux/module.h>
18844 +#include <asm/uaccess.h>
18845 +
18846 +#include <linux/vserver/context.h>
18847 +#include <linux/vserver/debug.h>
18848 +#include <linux/vserver/debug_cmd.h>
18849 +#include <linux/vserver/history.h>
18850 +
18851 +
18852 +#ifdef CONFIG_VSERVER_HISTORY
18853 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18854 +#else
18855 +#define VXH_SIZE       64
18856 +#endif
18857 +
18858 +struct _vx_history {
18859 +       unsigned int counter;
18860 +
18861 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18862 +};
18863 +
18864 +
18865 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18866 +
18867 +unsigned volatile int vxh_active = 1;
18868 +
18869 +static atomic_t sequence = ATOMIC_INIT(0);
18870 +
18871 +
18872 +/*     vxh_advance()
18873 +
18874 +       * requires disabled preemption                          */
18875 +
18876 +struct _vx_hist_entry *vxh_advance(void *loc)
18877 +{
18878 +       unsigned int cpu = smp_processor_id();
18879 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18880 +       struct _vx_hist_entry *entry;
18881 +       unsigned int index;
18882 +
18883 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18884 +       entry = &hist->entry[index];
18885 +
18886 +       entry->seq = atomic_inc_return(&sequence);
18887 +       entry->loc = loc;
18888 +       return entry;
18889 +}
18890 +
18891 +EXPORT_SYMBOL_GPL(vxh_advance);
18892 +
18893 +
18894 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18895 +
18896 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18897 +
18898 +
18899 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18900 +
18901 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18902 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18903 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18904 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18905 +
18906 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18907 +{
18908 +       switch (e->type) {
18909 +       case VXH_THROW_OOPS:
18910 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18911 +               break;
18912 +
18913 +       case VXH_GET_VX_INFO:
18914 +       case VXH_PUT_VX_INFO:
18915 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18916 +                       VXH_LOC_ARGS(e),
18917 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18918 +                       VXH_VXI_ARGS(e));
18919 +               break;
18920 +
18921 +       case VXH_INIT_VX_INFO:
18922 +       case VXH_SET_VX_INFO:
18923 +       case VXH_CLR_VX_INFO:
18924 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18925 +                       VXH_LOC_ARGS(e),
18926 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18927 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18928 +                       VXH_VXI_ARGS(e), e->sc.data);
18929 +               break;
18930 +
18931 +       case VXH_CLAIM_VX_INFO:
18932 +       case VXH_RELEASE_VX_INFO:
18933 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18934 +                       VXH_LOC_ARGS(e),
18935 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18936 +                       VXH_VXI_ARGS(e), e->sc.data);
18937 +               break;
18938 +
18939 +       case VXH_ALLOC_VX_INFO:
18940 +       case VXH_DEALLOC_VX_INFO:
18941 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18942 +                       VXH_LOC_ARGS(e),
18943 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18944 +                       VXH_VXI_ARGS(e));
18945 +               break;
18946 +
18947 +       case VXH_HASH_VX_INFO:
18948 +       case VXH_UNHASH_VX_INFO:
18949 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18950 +                       VXH_LOC_ARGS(e),
18951 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18952 +                       VXH_VXI_ARGS(e));
18953 +               break;
18954 +
18955 +       case VXH_LOC_VX_INFO:
18956 +       case VXH_LOOKUP_VX_INFO:
18957 +       case VXH_CREATE_VX_INFO:
18958 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18959 +                       VXH_LOC_ARGS(e),
18960 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18961 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18962 +                       e->ll.arg, VXH_VXI_ARGS(e));
18963 +               break;
18964 +       }
18965 +}
18966 +
18967 +static void __vxh_dump_history(void)
18968 +{
18969 +       unsigned int i, cpu;
18970 +
18971 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18972 +               atomic_read(&sequence), NR_CPUS);
18973 +
18974 +       for (i = 0; i < VXH_SIZE; i++) {
18975 +               for_each_online_cpu(cpu) {
18976 +                       struct _vx_history *hist =
18977 +                               &per_cpu(vx_history_buffer, cpu);
18978 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18979 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18980 +
18981 +                       vxh_dump_entry(entry, cpu);
18982 +               }
18983 +       }
18984 +}
18985 +
18986 +void   vxh_dump_history(void)
18987 +{
18988 +       vxh_active = 0;
18989 +#ifdef CONFIG_SMP
18990 +       local_irq_enable();
18991 +       smp_send_stop();
18992 +       local_irq_disable();
18993 +#endif
18994 +       __vxh_dump_history();
18995 +}
18996 +
18997 +
18998 +/* vserver syscall commands below here */
18999 +
19000 +
19001 +int vc_dump_history(uint32_t id)
19002 +{
19003 +       vxh_active = 0;
19004 +       __vxh_dump_history();
19005 +       vxh_active = 1;
19006 +
19007 +       return 0;
19008 +}
19009 +
19010 +
19011 +int do_read_history(struct __user _vx_hist_entry *data,
19012 +       int cpu, uint32_t *index, uint32_t *count)
19013 +{
19014 +       int pos, ret = 0;
19015 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19016 +       int end = hist->counter;
19017 +       int start = end - VXH_SIZE + 2;
19018 +       int idx = *index;
19019 +
19020 +       /* special case: get current pos */
19021 +       if (!*count) {
19022 +               *index = end;
19023 +               return 0;
19024 +       }
19025 +
19026 +       /* have we lost some data? */
19027 +       if (idx < start)
19028 +               idx = start;
19029 +
19030 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19031 +               struct _vx_hist_entry *entry =
19032 +                       &hist->entry[idx % VXH_SIZE];
19033 +
19034 +               /* send entry to userspace */
19035 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19036 +               if (ret)
19037 +                       break;
19038 +       }
19039 +       /* save new index and count */
19040 +       *index = idx;
19041 +       *count = pos;
19042 +       return ret ? ret : (*index < end);
19043 +}
19044 +
19045 +int vc_read_history(uint32_t id, void __user *data)
19046 +{
19047 +       struct vcmd_read_history_v0 vc_data;
19048 +       int ret;
19049 +
19050 +       if (id >= NR_CPUS)
19051 +               return -EINVAL;
19052 +
19053 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19054 +               return -EFAULT;
19055 +
19056 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19057 +               id, &vc_data.index, &vc_data.count);
19058 +
19059 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19060 +               return -EFAULT;
19061 +       return ret;
19062 +}
19063 +
19064 +#ifdef CONFIG_COMPAT
19065 +
19066 +int vc_read_history_x32(uint32_t id, void __user *data)
19067 +{
19068 +       struct vcmd_read_history_v0_x32 vc_data;
19069 +       int ret;
19070 +
19071 +       if (id >= NR_CPUS)
19072 +               return -EINVAL;
19073 +
19074 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19075 +               return -EFAULT;
19076 +
19077 +       ret = do_read_history((struct __user _vx_hist_entry *)
19078 +               compat_ptr(vc_data.data_ptr),
19079 +               id, &vc_data.index, &vc_data.count);
19080 +
19081 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19082 +               return -EFAULT;
19083 +       return ret;
19084 +}
19085 +
19086 +#endif /* CONFIG_COMPAT */
19087 +
19088 diff -NurpP --minimal linux-3.4.32/kernel/vserver/inet.c linux-3.4.32-vs2.3.3.9/kernel/vserver/inet.c
19089 --- linux-3.4.32/kernel/vserver/inet.c  1970-01-01 00:00:00.000000000 +0000
19090 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/inet.c        2012-05-21 16:15:05.000000000 +0000
19091 @@ -0,0 +1,226 @@
19092 +
19093 +#include <linux/in.h>
19094 +#include <linux/inetdevice.h>
19095 +#include <linux/export.h>
19096 +#include <linux/vs_inet.h>
19097 +#include <linux/vs_inet6.h>
19098 +#include <linux/vserver/debug.h>
19099 +#include <net/route.h>
19100 +#include <net/addrconf.h>
19101 +
19102 +
19103 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19104 +{
19105 +       int ret = 0;
19106 +
19107 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19108 +               ret = 1;
19109 +       else {
19110 +               struct nx_addr_v4 *ptr;
19111 +
19112 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19113 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19114 +                               ret = 1;
19115 +                               break;
19116 +                       }
19117 +               }
19118 +       }
19119 +
19120 +       vxdprintk(VXD_CBIT(net, 2),
19121 +               "nx_v4_addr_conflict(%p,%p): %d",
19122 +               nxi1, nxi2, ret);
19123 +
19124 +       return ret;
19125 +}
19126 +
19127 +
19128 +#ifdef CONFIG_IPV6
19129 +
19130 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19131 +{
19132 +       int ret = 0;
19133 +
19134 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19135 +               ret = 1;
19136 +       else {
19137 +               struct nx_addr_v6 *ptr;
19138 +
19139 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19140 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19141 +                               ret = 1;
19142 +                               break;
19143 +                       }
19144 +               }
19145 +       }
19146 +
19147 +       vxdprintk(VXD_CBIT(net, 2),
19148 +               "nx_v6_addr_conflict(%p,%p): %d",
19149 +               nxi1, nxi2, ret);
19150 +
19151 +       return ret;
19152 +}
19153 +
19154 +#endif
19155 +
19156 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19157 +{
19158 +       struct in_device *in_dev;
19159 +       struct in_ifaddr **ifap;
19160 +       struct in_ifaddr *ifa;
19161 +       int ret = 0;
19162 +
19163 +       if (!dev)
19164 +               goto out;
19165 +       in_dev = in_dev_get(dev);
19166 +       if (!in_dev)
19167 +               goto out;
19168 +
19169 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19170 +               ifap = &ifa->ifa_next) {
19171 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19172 +                       ret = 1;
19173 +                       break;
19174 +               }
19175 +       }
19176 +       in_dev_put(in_dev);
19177 +out:
19178 +       return ret;
19179 +}
19180 +
19181 +
19182 +#ifdef CONFIG_IPV6
19183 +
19184 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19185 +{
19186 +       struct inet6_dev *in_dev;
19187 +       struct inet6_ifaddr *ifa;
19188 +       int ret = 0;
19189 +
19190 +       if (!dev)
19191 +               goto out;
19192 +       in_dev = in6_dev_get(dev);
19193 +       if (!in_dev)
19194 +               goto out;
19195 +
19196 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19197 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19198 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19199 +                       ret = 1;
19200 +                       break;
19201 +               }
19202 +       }
19203 +       in6_dev_put(in_dev);
19204 +out:
19205 +       return ret;
19206 +}
19207 +
19208 +#endif
19209 +
19210 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19211 +{
19212 +       int ret = 1;
19213 +
19214 +       if (!nxi)
19215 +               goto out;
19216 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19217 +               goto out;
19218 +#ifdef CONFIG_IPV6
19219 +       ret = 2;
19220 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19221 +               goto out;
19222 +#endif
19223 +       ret = 0;
19224 +out:
19225 +       vxdprintk(VXD_CBIT(net, 3),
19226 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19227 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19228 +       return ret;
19229 +}
19230 +
19231 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19232 +       struct flowi4 *fl4)
19233 +{
19234 +       struct rtable *rt;
19235 +
19236 +       if (!nxi)
19237 +               return NULL;
19238 +
19239 +       /* FIXME: handle lback only case */
19240 +       if (!NX_IPV4(nxi))
19241 +               return ERR_PTR(-EPERM);
19242 +
19243 +       vxdprintk(VXD_CBIT(net, 4),
19244 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19245 +               nxi, nxi ? nxi->nx_id : 0,
19246 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19247 +
19248 +       /* single IP is unconditional */
19249 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19250 +               (fl4->saddr == INADDR_ANY))
19251 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19252 +
19253 +       if (fl4->saddr == INADDR_ANY) {
19254 +               struct nx_addr_v4 *ptr;
19255 +               __be32 found = 0;
19256 +
19257 +               rt = __ip_route_output_key(net, fl4);
19258 +               if (!IS_ERR(rt)) {
19259 +                       found = fl4->saddr;
19260 +                       ip_rt_put(rt);
19261 +                       vxdprintk(VXD_CBIT(net, 4),
19262 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19263 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19264 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19265 +                               goto found;
19266 +               }
19267 +
19268 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19269 +                       __be32 primary = ptr->ip[0].s_addr;
19270 +                       __be32 mask = ptr->mask.s_addr;
19271 +                       __be32 neta = primary & mask;
19272 +
19273 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19274 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19275 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19276 +                               NIPQUAD(mask), NIPQUAD(neta));
19277 +                       if ((found & mask) != neta)
19278 +                               continue;
19279 +
19280 +                       fl4->saddr = primary;
19281 +                       rt = __ip_route_output_key(net, fl4);
19282 +                       vxdprintk(VXD_CBIT(net, 4),
19283 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19284 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19285 +                       if (!IS_ERR(rt)) {
19286 +                               found = fl4->saddr;
19287 +                               ip_rt_put(rt);
19288 +                               if (found == primary)
19289 +                                       goto found;
19290 +                       }
19291 +               }
19292 +               /* still no source ip? */
19293 +               found = ipv4_is_loopback(fl4->daddr)
19294 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19295 +       found:
19296 +               /* assign src ip to flow */
19297 +               fl4->saddr = found;
19298 +
19299 +       } else {
19300 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19301 +                       return ERR_PTR(-EPERM);
19302 +       }
19303 +
19304 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19305 +               if (ipv4_is_loopback(fl4->daddr))
19306 +                       fl4->daddr = nxi->v4_lback.s_addr;
19307 +               if (ipv4_is_loopback(fl4->saddr))
19308 +                       fl4->saddr = nxi->v4_lback.s_addr;
19309 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19310 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19311 +               return ERR_PTR(-EPERM);
19312 +
19313 +       return NULL;
19314 +}
19315 +
19316 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19317 +
19318 diff -NurpP --minimal linux-3.4.32/kernel/vserver/init.c linux-3.4.32-vs2.3.3.9/kernel/vserver/init.c
19319 --- linux-3.4.32/kernel/vserver/init.c  1970-01-01 00:00:00.000000000 +0000
19320 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/init.c        2012-05-21 16:15:05.000000000 +0000
19321 @@ -0,0 +1,45 @@
19322 +/*
19323 + *  linux/kernel/init.c
19324 + *
19325 + *  Virtual Server Init
19326 + *
19327 + *  Copyright (C) 2004-2007  Herbert Pötzl
19328 + *
19329 + *  V0.01  basic structure
19330 + *
19331 + */
19332 +
19333 +#include <linux/init.h>
19334 +
19335 +int    vserver_register_sysctl(void);
19336 +void   vserver_unregister_sysctl(void);
19337 +
19338 +
19339 +static int __init init_vserver(void)
19340 +{
19341 +       int ret = 0;
19342 +
19343 +#ifdef CONFIG_VSERVER_DEBUG
19344 +       vserver_register_sysctl();
19345 +#endif
19346 +       return ret;
19347 +}
19348 +
19349 +
19350 +static void __exit exit_vserver(void)
19351 +{
19352 +
19353 +#ifdef CONFIG_VSERVER_DEBUG
19354 +       vserver_unregister_sysctl();
19355 +#endif
19356 +       return;
19357 +}
19358 +
19359 +/* FIXME: GFP_ZONETYPES gone
19360 +long vx_slab[GFP_ZONETYPES]; */
19361 +long vx_area;
19362 +
19363 +
19364 +module_init(init_vserver);
19365 +module_exit(exit_vserver);
19366 +
19367 diff -NurpP --minimal linux-3.4.32/kernel/vserver/inode.c linux-3.4.32-vs2.3.3.9/kernel/vserver/inode.c
19368 --- linux-3.4.32/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
19369 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/inode.c       2012-05-21 16:15:05.000000000 +0000
19370 @@ -0,0 +1,437 @@
19371 +/*
19372 + *  linux/kernel/vserver/inode.c
19373 + *
19374 + *  Virtual Server: File System Support
19375 + *
19376 + *  Copyright (C) 2004-2007  Herbert Pötzl
19377 + *
19378 + *  V0.01  separated from vcontext V0.05
19379 + *  V0.02  moved to tag (instead of xid)
19380 + *
19381 + */
19382 +
19383 +#include <linux/tty.h>
19384 +#include <linux/proc_fs.h>
19385 +#include <linux/devpts_fs.h>
19386 +#include <linux/fs.h>
19387 +#include <linux/file.h>
19388 +#include <linux/mount.h>
19389 +#include <linux/parser.h>
19390 +#include <linux/namei.h>
19391 +#include <linux/vserver/inode.h>
19392 +#include <linux/vserver/inode_cmd.h>
19393 +#include <linux/vs_base.h>
19394 +#include <linux/vs_tag.h>
19395 +
19396 +#include <asm/uaccess.h>
19397 +
19398 +
19399 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19400 +{
19401 +       struct proc_dir_entry *entry;
19402 +
19403 +       if (!in || !in->i_sb)
19404 +               return -ESRCH;
19405 +
19406 +       *flags = IATTR_TAG
19407 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19408 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19409 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19410 +               | (IS_COW(in) ? IATTR_COW : 0);
19411 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19412 +
19413 +       if (S_ISDIR(in->i_mode))
19414 +               *mask |= IATTR_BARRIER;
19415 +
19416 +       if (IS_TAGGED(in)) {
19417 +               *tag = in->i_tag;
19418 +               *mask |= IATTR_TAG;
19419 +       }
19420 +
19421 +       switch (in->i_sb->s_magic) {
19422 +       case PROC_SUPER_MAGIC:
19423 +               entry = PROC_I(in)->pde;
19424 +
19425 +               /* check for specific inodes? */
19426 +               if (entry)
19427 +                       *mask |= IATTR_FLAGS;
19428 +               if (entry)
19429 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19430 +               else
19431 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19432 +               break;
19433 +
19434 +       case DEVPTS_SUPER_MAGIC:
19435 +               *tag = in->i_tag;
19436 +               *mask |= IATTR_TAG;
19437 +               break;
19438 +
19439 +       default:
19440 +               break;
19441 +       }
19442 +       return 0;
19443 +}
19444 +
19445 +int vc_get_iattr(void __user *data)
19446 +{
19447 +       struct path path;
19448 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19449 +       int ret;
19450 +
19451 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19452 +               return -EFAULT;
19453 +
19454 +       ret = user_lpath(vc_data.name, &path);
19455 +       if (!ret) {
19456 +               ret = __vc_get_iattr(path.dentry->d_inode,
19457 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19458 +               path_put(&path);
19459 +       }
19460 +       if (ret)
19461 +               return ret;
19462 +
19463 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19464 +               ret = -EFAULT;
19465 +       return ret;
19466 +}
19467 +
19468 +#ifdef CONFIG_COMPAT
19469 +
19470 +int vc_get_iattr_x32(void __user *data)
19471 +{
19472 +       struct path path;
19473 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19474 +       int ret;
19475 +
19476 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19477 +               return -EFAULT;
19478 +
19479 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19480 +       if (!ret) {
19481 +               ret = __vc_get_iattr(path.dentry->d_inode,
19482 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19483 +               path_put(&path);
19484 +       }
19485 +       if (ret)
19486 +               return ret;
19487 +
19488 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19489 +               ret = -EFAULT;
19490 +       return ret;
19491 +}
19492 +
19493 +#endif /* CONFIG_COMPAT */
19494 +
19495 +
19496 +int vc_fget_iattr(uint32_t fd, void __user *data)
19497 +{
19498 +       struct file *filp;
19499 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19500 +       int ret;
19501 +
19502 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19503 +               return -EFAULT;
19504 +
19505 +       filp = fget(fd);
19506 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19507 +               return -EBADF;
19508 +
19509 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19510 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19511 +
19512 +       fput(filp);
19513 +
19514 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19515 +               ret = -EFAULT;
19516 +       return ret;
19517 +}
19518 +
19519 +
19520 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19521 +{
19522 +       struct inode *in = de->d_inode;
19523 +       int error = 0, is_proc = 0, has_tag = 0;
19524 +       struct iattr attr = { 0 };
19525 +
19526 +       if (!in || !in->i_sb)
19527 +               return -ESRCH;
19528 +
19529 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19530 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19531 +               return -EINVAL;
19532 +
19533 +       has_tag = IS_TAGGED(in) ||
19534 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19535 +       if ((*mask & IATTR_TAG) && !has_tag)
19536 +               return -EINVAL;
19537 +
19538 +       mutex_lock(&in->i_mutex);
19539 +       if (*mask & IATTR_TAG) {
19540 +               attr.ia_tag = *tag;
19541 +               attr.ia_valid |= ATTR_TAG;
19542 +       }
19543 +
19544 +       if (*mask & IATTR_FLAGS) {
19545 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19546 +               unsigned int iflags = PROC_I(in)->vx_flags;
19547 +
19548 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19549 +                       | (*flags & IATTR_FLAGS);
19550 +               PROC_I(in)->vx_flags = iflags;
19551 +               if (entry)
19552 +                       entry->vx_flags = iflags;
19553 +       }
19554 +
19555 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19556 +               IATTR_BARRIER | IATTR_COW)) {
19557 +               int iflags = in->i_flags;
19558 +               int vflags = in->i_vflags;
19559 +
19560 +               if (*mask & IATTR_IMMUTABLE) {
19561 +                       if (*flags & IATTR_IMMUTABLE)
19562 +                               iflags |= S_IMMUTABLE;
19563 +                       else
19564 +                               iflags &= ~S_IMMUTABLE;
19565 +               }
19566 +               if (*mask & IATTR_IXUNLINK) {
19567 +                       if (*flags & IATTR_IXUNLINK)
19568 +                               iflags |= S_IXUNLINK;
19569 +                       else
19570 +                               iflags &= ~S_IXUNLINK;
19571 +               }
19572 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19573 +                       if (*flags & IATTR_BARRIER)
19574 +                               vflags |= V_BARRIER;
19575 +                       else
19576 +                               vflags &= ~V_BARRIER;
19577 +               }
19578 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19579 +                       if (*flags & IATTR_COW)
19580 +                               vflags |= V_COW;
19581 +                       else
19582 +                               vflags &= ~V_COW;
19583 +               }
19584 +               if (in->i_op && in->i_op->sync_flags) {
19585 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19586 +                       if (error)
19587 +                               goto out;
19588 +               }
19589 +       }
19590 +
19591 +       if (attr.ia_valid) {
19592 +               if (in->i_op && in->i_op->setattr)
19593 +                       error = in->i_op->setattr(de, &attr);
19594 +               else {
19595 +                       error = inode_change_ok(in, &attr);
19596 +                       if (!error) {
19597 +                               setattr_copy(in, &attr);
19598 +                               mark_inode_dirty(in);
19599 +                       }
19600 +               }
19601 +       }
19602 +
19603 +out:
19604 +       mutex_unlock(&in->i_mutex);
19605 +       return error;
19606 +}
19607 +
19608 +int vc_set_iattr(void __user *data)
19609 +{
19610 +       struct path path;
19611 +       struct vcmd_ctx_iattr_v1 vc_data;
19612 +       int ret;
19613 +
19614 +       if (!capable(CAP_LINUX_IMMUTABLE))
19615 +               return -EPERM;
19616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19617 +               return -EFAULT;
19618 +
19619 +       ret = user_lpath(vc_data.name, &path);
19620 +       if (!ret) {
19621 +               ret = __vc_set_iattr(path.dentry,
19622 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19623 +               path_put(&path);
19624 +       }
19625 +
19626 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19627 +               ret = -EFAULT;
19628 +       return ret;
19629 +}
19630 +
19631 +#ifdef CONFIG_COMPAT
19632 +
19633 +int vc_set_iattr_x32(void __user *data)
19634 +{
19635 +       struct path path;
19636 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19637 +       int ret;
19638 +
19639 +       if (!capable(CAP_LINUX_IMMUTABLE))
19640 +               return -EPERM;
19641 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19642 +               return -EFAULT;
19643 +
19644 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19645 +       if (!ret) {
19646 +               ret = __vc_set_iattr(path.dentry,
19647 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19648 +               path_put(&path);
19649 +       }
19650 +
19651 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19652 +               ret = -EFAULT;
19653 +       return ret;
19654 +}
19655 +
19656 +#endif /* CONFIG_COMPAT */
19657 +
19658 +int vc_fset_iattr(uint32_t fd, void __user *data)
19659 +{
19660 +       struct file *filp;
19661 +       struct vcmd_ctx_fiattr_v0 vc_data;
19662 +       int ret;
19663 +
19664 +       if (!capable(CAP_LINUX_IMMUTABLE))
19665 +               return -EPERM;
19666 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19667 +               return -EFAULT;
19668 +
19669 +       filp = fget(fd);
19670 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19671 +               return -EBADF;
19672 +
19673 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19674 +               &vc_data.flags, &vc_data.mask);
19675 +
19676 +       fput(filp);
19677 +
19678 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19679 +               return -EFAULT;
19680 +       return ret;
19681 +}
19682 +
19683 +
19684 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19685 +
19686 +static match_table_t tokens = {
19687 +       {Opt_notagcheck, "notagcheck"},
19688 +#ifdef CONFIG_PROPAGATE
19689 +       {Opt_notag, "notag"},
19690 +       {Opt_tag, "tag"},
19691 +       {Opt_tagid, "tagid=%u"},
19692 +#endif
19693 +       {Opt_err, NULL}
19694 +};
19695 +
19696 +
19697 +static void __dx_parse_remove(char *string, char *opt)
19698 +{
19699 +       char *p = strstr(string, opt);
19700 +       char *q = p;
19701 +
19702 +       if (p) {
19703 +               while (*q != '\0' && *q != ',')
19704 +                       q++;
19705 +               while (*q)
19706 +                       *p++ = *q++;
19707 +               while (*p)
19708 +                       *p++ = '\0';
19709 +       }
19710 +}
19711 +
19712 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19713 +                unsigned long *flags)
19714 +{
19715 +       int set = 0;
19716 +       substring_t args[MAX_OPT_ARGS];
19717 +       int token;
19718 +       char *s, *p, *opts;
19719 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19720 +       int option = 0;
19721 +#endif
19722 +
19723 +       if (!string)
19724 +               return 0;
19725 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19726 +       if (!s)
19727 +               return 0;
19728 +
19729 +       opts = s;
19730 +       while ((p = strsep(&opts, ",")) != NULL) {
19731 +               token = match_token(p, tokens, args);
19732 +
19733 +               switch (token) {
19734 +#ifdef CONFIG_PROPAGATE
19735 +               case Opt_tag:
19736 +                       if (tag)
19737 +                               *tag = 0;
19738 +                       if (remove)
19739 +                               __dx_parse_remove(s, "tag");
19740 +                       *mnt_flags |= MNT_TAGID;
19741 +                       set |= MNT_TAGID;
19742 +                       break;
19743 +               case Opt_notag:
19744 +                       if (remove)
19745 +                               __dx_parse_remove(s, "notag");
19746 +                       *mnt_flags |= MNT_NOTAG;
19747 +                       set |= MNT_NOTAG;
19748 +                       break;
19749 +               case Opt_tagid:
19750 +                       if (tag && !match_int(args, &option))
19751 +                               *tag = option;
19752 +                       if (remove)
19753 +                               __dx_parse_remove(s, "tagid");
19754 +                       *mnt_flags |= MNT_TAGID;
19755 +                       set |= MNT_TAGID;
19756 +                       break;
19757 +#endif /* CONFIG_PROPAGATE */
19758 +               case Opt_notagcheck:
19759 +                       if (remove)
19760 +                               __dx_parse_remove(s, "notagcheck");
19761 +                       *flags |= MS_NOTAGCHECK;
19762 +                       set |= MS_NOTAGCHECK;
19763 +                       break;
19764 +               }
19765 +               vxdprintk(VXD_CBIT(tag, 7),
19766 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19767 +                       p, token, option);
19768 +       }
19769 +       if (set)
19770 +               strcpy(string, s);
19771 +       kfree(s);
19772 +       return set;
19773 +}
19774 +
19775 +#ifdef CONFIG_PROPAGATE
19776 +
19777 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19778 +{
19779 +       tag_t new_tag = 0;
19780 +       struct vfsmount *mnt;
19781 +       int propagate;
19782 +
19783 +       if (!nd)
19784 +               return;
19785 +       mnt = nd->path.mnt;
19786 +       if (!mnt)
19787 +               return;
19788 +
19789 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19790 +       if (propagate)
19791 +               new_tag = mnt->mnt_tag;
19792 +
19793 +       vxdprintk(VXD_CBIT(tag, 7),
19794 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19795 +               inode, inode->i_ino, inode->i_tag,
19796 +               new_tag, (propagate) ? 1 : 0);
19797 +
19798 +       if (propagate)
19799 +               inode->i_tag = new_tag;
19800 +}
19801 +
19802 +#include <linux/module.h>
19803 +
19804 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19805 +
19806 +#endif /* CONFIG_PROPAGATE */
19807 +
19808 diff -NurpP --minimal linux-3.4.32/kernel/vserver/limit.c linux-3.4.32-vs2.3.3.9/kernel/vserver/limit.c
19809 --- linux-3.4.32/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
19810 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/limit.c       2012-09-01 09:15:21.000000000 +0000
19811 @@ -0,0 +1,345 @@
19812 +/*
19813 + *  linux/kernel/vserver/limit.c
19814 + *
19815 + *  Virtual Server: Context Limits
19816 + *
19817 + *  Copyright (C) 2004-2010  Herbert Pötzl
19818 + *
19819 + *  V0.01  broken out from vcontext V0.05
19820 + *  V0.02  changed vcmds to vxi arg
19821 + *  V0.03  added memory cgroup support
19822 + *
19823 + */
19824 +
19825 +#include <linux/sched.h>
19826 +#include <linux/module.h>
19827 +#include <linux/memcontrol.h>
19828 +#include <linux/res_counter.h>
19829 +#include <linux/vs_limit.h>
19830 +#include <linux/vserver/limit.h>
19831 +#include <linux/vserver/limit_cmd.h>
19832 +
19833 +#include <asm/uaccess.h>
19834 +
19835 +
19836 +const char *vlimit_name[NUM_LIMITS] = {
19837 +       [RLIMIT_CPU]            = "CPU",
19838 +       [RLIMIT_NPROC]          = "NPROC",
19839 +       [RLIMIT_NOFILE]         = "NOFILE",
19840 +       [RLIMIT_LOCKS]          = "LOCKS",
19841 +       [RLIMIT_SIGPENDING]     = "SIGP",
19842 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19843 +
19844 +       [VLIMIT_NSOCK]          = "NSOCK",
19845 +       [VLIMIT_OPENFD]         = "OPENFD",
19846 +       [VLIMIT_SHMEM]          = "SHMEM",
19847 +       [VLIMIT_DENTRY]         = "DENTRY",
19848 +};
19849 +
19850 +EXPORT_SYMBOL_GPL(vlimit_name);
19851 +
19852 +#define MASK_ENTRY(x)  (1 << (x))
19853 +
19854 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19855 +               /* minimum */
19856 +       0
19857 +       ,       /* softlimit */
19858 +       0
19859 +       ,       /* maximum */
19860 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19861 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19862 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19863 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19864 +
19865 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19866 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19867 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19868 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19869 +       0
19870 +};
19871 +               /* accounting only */
19872 +uint32_t account_mask =
19873 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19874 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19875 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19876 +       0;
19877 +
19878 +
19879 +static int is_valid_vlimit(int id)
19880 +{
19881 +       uint32_t mask = vlimit_mask.minimum |
19882 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19883 +       return mask & (1 << id);
19884 +}
19885 +
19886 +static int is_accounted_vlimit(int id)
19887 +{
19888 +       if (is_valid_vlimit(id))
19889 +               return 1;
19890 +       return account_mask & (1 << id);
19891 +}
19892 +
19893 +
19894 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19895 +{
19896 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19897 +       return VX_VLIM(limit);
19898 +}
19899 +
19900 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19901 +{
19902 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19903 +       return VX_VLIM(limit);
19904 +}
19905 +
19906 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19907 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19908 +{
19909 +       if (!is_valid_vlimit(id))
19910 +               return -EINVAL;
19911 +
19912 +       if (minimum)
19913 +               *minimum = CRLIM_UNSET;
19914 +       if (softlimit)
19915 +               *softlimit = vc_get_soft(vxi, id);
19916 +       if (maximum)
19917 +               *maximum = vc_get_hard(vxi, id);
19918 +       return 0;
19919 +}
19920 +
19921 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19922 +{
19923 +       struct vcmd_ctx_rlimit_v0 vc_data;
19924 +       int ret;
19925 +
19926 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19927 +               return -EFAULT;
19928 +
19929 +       ret = do_get_rlimit(vxi, vc_data.id,
19930 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19931 +       if (ret)
19932 +               return ret;
19933 +
19934 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19935 +               return -EFAULT;
19936 +       return 0;
19937 +}
19938 +
19939 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19940 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19941 +{
19942 +       if (!is_valid_vlimit(id))
19943 +               return -EINVAL;
19944 +
19945 +       if (maximum != CRLIM_KEEP)
19946 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19947 +       if (softlimit != CRLIM_KEEP)
19948 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19949 +
19950 +       /* clamp soft limit */
19951 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19952 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19953 +
19954 +       return 0;
19955 +}
19956 +
19957 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19958 +{
19959 +       struct vcmd_ctx_rlimit_v0 vc_data;
19960 +
19961 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19962 +               return -EFAULT;
19963 +
19964 +       return do_set_rlimit(vxi, vc_data.id,
19965 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19966 +}
19967 +
19968 +#ifdef CONFIG_IA32_EMULATION
19969 +
19970 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19971 +{
19972 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19973 +
19974 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19975 +               return -EFAULT;
19976 +
19977 +       return do_set_rlimit(vxi, vc_data.id,
19978 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19979 +}
19980 +
19981 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19982 +{
19983 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19984 +       int ret;
19985 +
19986 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19987 +               return -EFAULT;
19988 +
19989 +       ret = do_get_rlimit(vxi, vc_data.id,
19990 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19991 +       if (ret)
19992 +               return ret;
19993 +
19994 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19995 +               return -EFAULT;
19996 +       return 0;
19997 +}
19998 +
19999 +#endif /* CONFIG_IA32_EMULATION */
20000 +
20001 +
20002 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20003 +{
20004 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20005 +               return -EFAULT;
20006 +       return 0;
20007 +}
20008 +
20009 +
20010 +static inline void vx_reset_hits(struct _vx_limit *limit)
20011 +{
20012 +       int lim;
20013 +
20014 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20015 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20016 +       }
20017 +}
20018 +
20019 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20020 +{
20021 +       vx_reset_hits(&vxi->limit);
20022 +       return 0;
20023 +}
20024 +
20025 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20026 +{
20027 +       rlim_t value;
20028 +       int lim;
20029 +
20030 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20031 +               value = __rlim_get(limit, lim);
20032 +               __rlim_rmax(limit, lim) = value;
20033 +               __rlim_rmin(limit, lim) = value;
20034 +       }
20035 +}
20036 +
20037 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20038 +{
20039 +       vx_reset_minmax(&vxi->limit);
20040 +       return 0;
20041 +}
20042 +
20043 +
20044 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20045 +{
20046 +       struct vcmd_rlimit_stat_v0 vc_data;
20047 +       struct _vx_limit *limit = &vxi->limit;
20048 +       int id;
20049 +
20050 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20051 +               return -EFAULT;
20052 +
20053 +       id = vc_data.id;
20054 +       if (!is_accounted_vlimit(id))
20055 +               return -EINVAL;
20056 +
20057 +       vx_limit_fixup(limit, id);
20058 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20059 +       vc_data.value = __rlim_get(limit, id);
20060 +       vc_data.minimum = __rlim_rmin(limit, id);
20061 +       vc_data.maximum = __rlim_rmax(limit, id);
20062 +
20063 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20064 +               return -EFAULT;
20065 +       return 0;
20066 +}
20067 +
20068 +
20069 +void vx_vsi_meminfo(struct sysinfo *val)
20070 +{
20071 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20072 +       struct mem_cgroup *mcg;
20073 +       u64 res_limit, res_usage;
20074 +
20075 +       rcu_read_lock();
20076 +       mcg = mem_cgroup_from_task(current);
20077 +       if (!mcg)
20078 +               goto out;
20079 +
20080 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20081 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20082 +
20083 +       if (res_limit != RESOURCE_MAX)
20084 +               val->totalram = (res_limit >> PAGE_SHIFT);
20085 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20086 +       val->bufferram = 0;
20087 +       val->totalhigh = 0;
20088 +       val->freehigh = 0;
20089 +out:
20090 +       rcu_read_unlock();
20091 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20092 +       return;
20093 +}
20094 +
20095 +void vx_vsi_swapinfo(struct sysinfo *val)
20096 +{
20097 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20098 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20099 +       struct mem_cgroup *mcg;
20100 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20101 +       s64 swap_limit, swap_usage;
20102 +
20103 +       rcu_read_lock();
20104 +       mcg = mem_cgroup_from_task(current);
20105 +       if (!mcg)
20106 +               goto out;
20107 +
20108 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20109 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20110 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20111 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20112 +
20113 +       /* memory unlimited */
20114 +       if (res_limit == RESOURCE_MAX)
20115 +               goto out;
20116 +
20117 +       swap_limit = memsw_limit - res_limit;
20118 +       /* we have a swap limit? */
20119 +       if (memsw_limit != RESOURCE_MAX)
20120 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20121 +
20122 +       /* calculate swap part */
20123 +       swap_usage = (memsw_usage > res_usage) ?
20124 +               memsw_usage - res_usage : 0;
20125 +
20126 +       /* total shown minus usage gives free swap */
20127 +       val->freeswap = (swap_usage < swap_limit) ?
20128 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20129 +out:
20130 +       rcu_read_unlock();
20131 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20132 +       val->totalswap = 0;
20133 +       val->freeswap = 0;
20134 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20135 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20136 +       return;
20137 +}
20138 +
20139 +long vx_vsi_cached(struct sysinfo *val)
20140 +{
20141 +       long cache = 0;
20142 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20143 +       struct mem_cgroup *mcg;
20144 +
20145 +       rcu_read_lock();
20146 +       mcg = mem_cgroup_from_task(current);
20147 +       if (!mcg)
20148 +               goto out;
20149 +
20150 +       cache = mem_cgroup_stat_read_cache(mcg);
20151 +out:
20152 +       rcu_read_unlock();
20153 +#endif
20154 +       return cache;
20155 +}
20156 +
20157 diff -NurpP --minimal linux-3.4.32/kernel/vserver/limit_init.h linux-3.4.32-vs2.3.3.9/kernel/vserver/limit_init.h
20158 --- linux-3.4.32/kernel/vserver/limit_init.h    1970-01-01 00:00:00.000000000 +0000
20159 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/limit_init.h  2012-05-21 16:15:05.000000000 +0000
20160 @@ -0,0 +1,31 @@
20161 +
20162 +
20163 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20164 +{
20165 +       int lim;
20166 +
20167 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20168 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20169 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20170 +               __rlim_set(limit, lim, 0);
20171 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20172 +               __rlim_rmin(limit, lim) = 0;
20173 +               __rlim_rmax(limit, lim) = 0;
20174 +       }
20175 +}
20176 +
20177 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20178 +{
20179 +       rlim_t value;
20180 +       int lim;
20181 +
20182 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20183 +               if ((1 << lim) & VLIM_NOCHECK)
20184 +                       continue;
20185 +               value = __rlim_get(limit, lim);
20186 +               vxwprintk_xid(value,
20187 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20188 +                       limit, vlimit_name[lim], lim, (long)value);
20189 +       }
20190 +}
20191 +
20192 diff -NurpP --minimal linux-3.4.32/kernel/vserver/limit_proc.h linux-3.4.32-vs2.3.3.9/kernel/vserver/limit_proc.h
20193 --- linux-3.4.32/kernel/vserver/limit_proc.h    1970-01-01 00:00:00.000000000 +0000
20194 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/limit_proc.h  2012-05-21 16:15:05.000000000 +0000
20195 @@ -0,0 +1,57 @@
20196 +#ifndef _VX_LIMIT_PROC_H
20197 +#define _VX_LIMIT_PROC_H
20198 +
20199 +#include <linux/vserver/limit_int.h>
20200 +
20201 +
20202 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20203 +#define VX_LIMIT_TOP   \
20204 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20205 +
20206 +#define VX_LIMIT_ARG(r)                                \
20207 +       (unsigned long)__rlim_get(limit, r),    \
20208 +       (unsigned long)__rlim_rmin(limit, r),   \
20209 +       (unsigned long)__rlim_rmax(limit, r),   \
20210 +       VX_VLIM(__rlim_soft(limit, r)),         \
20211 +       VX_VLIM(__rlim_hard(limit, r)),         \
20212 +       atomic_read(&__rlim_lhit(limit, r))
20213 +
20214 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20215 +{
20216 +       vx_limit_fixup(limit, -1);
20217 +       return sprintf(buffer, VX_LIMIT_TOP
20218 +               "PROC"  VX_LIMIT_FMT
20219 +               "VM"    VX_LIMIT_FMT
20220 +               "VML"   VX_LIMIT_FMT
20221 +               "RSS"   VX_LIMIT_FMT
20222 +               "ANON"  VX_LIMIT_FMT
20223 +               "RMAP"  VX_LIMIT_FMT
20224 +               "FILES" VX_LIMIT_FMT
20225 +               "OFD"   VX_LIMIT_FMT
20226 +               "LOCKS" VX_LIMIT_FMT
20227 +               "SOCK"  VX_LIMIT_FMT
20228 +               "MSGQ"  VX_LIMIT_FMT
20229 +               "SHM"   VX_LIMIT_FMT
20230 +               "SEMA"  VX_LIMIT_FMT
20231 +               "SEMS"  VX_LIMIT_FMT
20232 +               "DENT"  VX_LIMIT_FMT,
20233 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20234 +               VX_LIMIT_ARG(RLIMIT_AS),
20235 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20236 +               VX_LIMIT_ARG(RLIMIT_RSS),
20237 +               VX_LIMIT_ARG(VLIMIT_ANON),
20238 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20239 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20240 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20241 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20242 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20243 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20244 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20245 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20246 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20247 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20248 +}
20249 +
20250 +#endif /* _VX_LIMIT_PROC_H */
20251 +
20252 +
20253 diff -NurpP --minimal linux-3.4.32/kernel/vserver/network.c linux-3.4.32-vs2.3.3.9/kernel/vserver/network.c
20254 --- linux-3.4.32/kernel/vserver/network.c       1970-01-01 00:00:00.000000000 +0000
20255 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/network.c     2012-05-21 16:15:05.000000000 +0000
20256 @@ -0,0 +1,912 @@
20257 +/*
20258 + *  linux/kernel/vserver/network.c
20259 + *
20260 + *  Virtual Server: Network Support
20261 + *
20262 + *  Copyright (C) 2003-2007  Herbert Pötzl
20263 + *
20264 + *  V0.01  broken out from vcontext V0.05
20265 + *  V0.02  cleaned up implementation
20266 + *  V0.03  added equiv nx commands
20267 + *  V0.04  switch to RCU based hash
20268 + *  V0.05  and back to locking again
20269 + *  V0.06  changed vcmds to nxi arg
20270 + *  V0.07  have __create claim() the nxi
20271 + *
20272 + */
20273 +
20274 +#include <linux/err.h>
20275 +#include <linux/slab.h>
20276 +#include <linux/rcupdate.h>
20277 +
20278 +#include <linux/vs_network.h>
20279 +#include <linux/vs_pid.h>
20280 +#include <linux/vserver/network_cmd.h>
20281 +
20282 +
20283 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20284 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20285 +
20286 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20287 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20288 +
20289 +
20290 +static int __init init_network(void)
20291 +{
20292 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20293 +               sizeof(struct nx_addr_v4), 0,
20294 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20295 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20296 +               sizeof(struct nx_addr_v6), 0,
20297 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20298 +       return 0;
20299 +}
20300 +
20301 +
20302 +/*     __alloc_nx_addr_v4()                                    */
20303 +
20304 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20305 +{
20306 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20307 +               nx_addr_v4_cachep, GFP_KERNEL);
20308 +
20309 +       if (!IS_ERR(nxa))
20310 +               memset(nxa, 0, sizeof(*nxa));
20311 +       return nxa;
20312 +}
20313 +
20314 +/*     __dealloc_nx_addr_v4()                                  */
20315 +
20316 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20317 +{
20318 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20319 +}
20320 +
20321 +/*     __dealloc_nx_addr_v4_all()                              */
20322 +
20323 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20324 +{
20325 +       while (nxa) {
20326 +               struct nx_addr_v4 *next = nxa->next;
20327 +
20328 +               __dealloc_nx_addr_v4(nxa);
20329 +               nxa = next;
20330 +       }
20331 +}
20332 +
20333 +
20334 +#ifdef CONFIG_IPV6
20335 +
20336 +/*     __alloc_nx_addr_v6()                                    */
20337 +
20338 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20339 +{
20340 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20341 +               nx_addr_v6_cachep, GFP_KERNEL);
20342 +
20343 +       if (!IS_ERR(nxa))
20344 +               memset(nxa, 0, sizeof(*nxa));
20345 +       return nxa;
20346 +}
20347 +
20348 +/*     __dealloc_nx_addr_v6()                                  */
20349 +
20350 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20351 +{
20352 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20353 +}
20354 +
20355 +/*     __dealloc_nx_addr_v6_all()                              */
20356 +
20357 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20358 +{
20359 +       while (nxa) {
20360 +               struct nx_addr_v6 *next = nxa->next;
20361 +
20362 +               __dealloc_nx_addr_v6(nxa);
20363 +               nxa = next;
20364 +       }
20365 +}
20366 +
20367 +#endif /* CONFIG_IPV6 */
20368 +
20369 +/*     __alloc_nx_info()
20370 +
20371 +       * allocate an initialized nx_info struct
20372 +       * doesn't make it visible (hash)                        */
20373 +
20374 +static struct nx_info *__alloc_nx_info(nid_t nid)
20375 +{
20376 +       struct nx_info *new = NULL;
20377 +
20378 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20379 +
20380 +       /* would this benefit from a slab cache? */
20381 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20382 +       if (!new)
20383 +               return 0;
20384 +
20385 +       memset(new, 0, sizeof(struct nx_info));
20386 +       new->nx_id = nid;
20387 +       INIT_HLIST_NODE(&new->nx_hlist);
20388 +       atomic_set(&new->nx_usecnt, 0);
20389 +       atomic_set(&new->nx_tasks, 0);
20390 +       new->nx_state = 0;
20391 +
20392 +       new->nx_flags = NXF_INIT_SET;
20393 +
20394 +       /* rest of init goes here */
20395 +
20396 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20397 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20398 +
20399 +       vxdprintk(VXD_CBIT(nid, 0),
20400 +               "alloc_nx_info(%d) = %p", nid, new);
20401 +       atomic_inc(&nx_global_ctotal);
20402 +       return new;
20403 +}
20404 +
20405 +/*     __dealloc_nx_info()
20406 +
20407 +       * final disposal of nx_info                             */
20408 +
20409 +static void __dealloc_nx_info(struct nx_info *nxi)
20410 +{
20411 +       vxdprintk(VXD_CBIT(nid, 0),
20412 +               "dealloc_nx_info(%p)", nxi);
20413 +
20414 +       nxi->nx_hlist.next = LIST_POISON1;
20415 +       nxi->nx_id = -1;
20416 +
20417 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20418 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20419 +
20420 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20421 +
20422 +       nxi->nx_state |= NXS_RELEASED;
20423 +       kfree(nxi);
20424 +       atomic_dec(&nx_global_ctotal);
20425 +}
20426 +
20427 +static void __shutdown_nx_info(struct nx_info *nxi)
20428 +{
20429 +       nxi->nx_state |= NXS_SHUTDOWN;
20430 +       vs_net_change(nxi, VSC_NETDOWN);
20431 +}
20432 +
20433 +/*     exported stuff                                          */
20434 +
20435 +void free_nx_info(struct nx_info *nxi)
20436 +{
20437 +       /* context shutdown is mandatory */
20438 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20439 +
20440 +       /* context must not be hashed */
20441 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20442 +
20443 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20444 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20445 +
20446 +       __dealloc_nx_info(nxi);
20447 +}
20448 +
20449 +
20450 +void __nx_set_lback(struct nx_info *nxi)
20451 +{
20452 +       int nid = nxi->nx_id;
20453 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20454 +
20455 +       nxi->v4_lback.s_addr = lback;
20456 +}
20457 +
20458 +extern int __nx_inet_add_lback(__be32 addr);
20459 +extern int __nx_inet_del_lback(__be32 addr);
20460 +
20461 +
20462 +/*     hash table for nx_info hash */
20463 +
20464 +#define NX_HASH_SIZE   13
20465 +
20466 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20467 +
20468 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20469 +
20470 +
20471 +static inline unsigned int __hashval(nid_t nid)
20472 +{
20473 +       return (nid % NX_HASH_SIZE);
20474 +}
20475 +
20476 +
20477 +
20478 +/*     __hash_nx_info()
20479 +
20480 +       * add the nxi to the global hash table
20481 +       * requires the hash_lock to be held                     */
20482 +
20483 +static inline void __hash_nx_info(struct nx_info *nxi)
20484 +{
20485 +       struct hlist_head *head;
20486 +
20487 +       vxd_assert_lock(&nx_info_hash_lock);
20488 +       vxdprintk(VXD_CBIT(nid, 4),
20489 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20490 +
20491 +       /* context must not be hashed */
20492 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20493 +
20494 +       nxi->nx_state |= NXS_HASHED;
20495 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20496 +       hlist_add_head(&nxi->nx_hlist, head);
20497 +       atomic_inc(&nx_global_cactive);
20498 +}
20499 +
20500 +/*     __unhash_nx_info()
20501 +
20502 +       * remove the nxi from the global hash table
20503 +       * requires the hash_lock to be held                     */
20504 +
20505 +static inline void __unhash_nx_info(struct nx_info *nxi)
20506 +{
20507 +       vxd_assert_lock(&nx_info_hash_lock);
20508 +       vxdprintk(VXD_CBIT(nid, 4),
20509 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20510 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20511 +
20512 +       /* context must be hashed */
20513 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20514 +       /* but without tasks */
20515 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20516 +
20517 +       nxi->nx_state &= ~NXS_HASHED;
20518 +       hlist_del(&nxi->nx_hlist);
20519 +       atomic_dec(&nx_global_cactive);
20520 +}
20521 +
20522 +
20523 +/*     __lookup_nx_info()
20524 +
20525 +       * requires the hash_lock to be held
20526 +       * doesn't increment the nx_refcnt                       */
20527 +
20528 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20529 +{
20530 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20531 +       struct hlist_node *pos;
20532 +       struct nx_info *nxi;
20533 +
20534 +       vxd_assert_lock(&nx_info_hash_lock);
20535 +       hlist_for_each(pos, head) {
20536 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20537 +
20538 +               if (nxi->nx_id == nid)
20539 +                       goto found;
20540 +       }
20541 +       nxi = NULL;
20542 +found:
20543 +       vxdprintk(VXD_CBIT(nid, 0),
20544 +               "__lookup_nx_info(#%u): %p[#%u]",
20545 +               nid, nxi, nxi ? nxi->nx_id : 0);
20546 +       return nxi;
20547 +}
20548 +
20549 +
20550 +/*     __create_nx_info()
20551 +
20552 +       * create the requested context
20553 +       * get(), claim() and hash it                            */
20554 +
20555 +static struct nx_info *__create_nx_info(int id)
20556 +{
20557 +       struct nx_info *new, *nxi = NULL;
20558 +
20559 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20560 +
20561 +       if (!(new = __alloc_nx_info(id)))
20562 +               return ERR_PTR(-ENOMEM);
20563 +
20564 +       /* required to make dynamic xids unique */
20565 +       spin_lock(&nx_info_hash_lock);
20566 +
20567 +       /* static context requested */
20568 +       if ((nxi = __lookup_nx_info(id))) {
20569 +               vxdprintk(VXD_CBIT(nid, 0),
20570 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20571 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20572 +                       nxi = ERR_PTR(-EBUSY);
20573 +               else
20574 +                       nxi = ERR_PTR(-EEXIST);
20575 +               goto out_unlock;
20576 +       }
20577 +       /* new context */
20578 +       vxdprintk(VXD_CBIT(nid, 0),
20579 +               "create_nx_info(%d) = %p (new)", id, new);
20580 +       claim_nx_info(new, NULL);
20581 +       __nx_set_lback(new);
20582 +       __hash_nx_info(get_nx_info(new));
20583 +       nxi = new, new = NULL;
20584 +
20585 +out_unlock:
20586 +       spin_unlock(&nx_info_hash_lock);
20587 +       if (new)
20588 +               __dealloc_nx_info(new);
20589 +       return nxi;
20590 +}
20591 +
20592 +
20593 +
20594 +/*     exported stuff                                          */
20595 +
20596 +
20597 +void unhash_nx_info(struct nx_info *nxi)
20598 +{
20599 +       __shutdown_nx_info(nxi);
20600 +       spin_lock(&nx_info_hash_lock);
20601 +       __unhash_nx_info(nxi);
20602 +       spin_unlock(&nx_info_hash_lock);
20603 +}
20604 +
20605 +/*     lookup_nx_info()
20606 +
20607 +       * search for a nx_info and get() it
20608 +       * negative id means current                             */
20609 +
20610 +struct nx_info *lookup_nx_info(int id)
20611 +{
20612 +       struct nx_info *nxi = NULL;
20613 +
20614 +       if (id < 0) {
20615 +               nxi = get_nx_info(current_nx_info());
20616 +       } else if (id > 1) {
20617 +               spin_lock(&nx_info_hash_lock);
20618 +               nxi = get_nx_info(__lookup_nx_info(id));
20619 +               spin_unlock(&nx_info_hash_lock);
20620 +       }
20621 +       return nxi;
20622 +}
20623 +
20624 +/*     nid_is_hashed()
20625 +
20626 +       * verify that nid is still hashed                       */
20627 +
20628 +int nid_is_hashed(nid_t nid)
20629 +{
20630 +       int hashed;
20631 +
20632 +       spin_lock(&nx_info_hash_lock);
20633 +       hashed = (__lookup_nx_info(nid) != NULL);
20634 +       spin_unlock(&nx_info_hash_lock);
20635 +       return hashed;
20636 +}
20637 +
20638 +
20639 +#ifdef CONFIG_PROC_FS
20640 +
20641 +/*     get_nid_list()
20642 +
20643 +       * get a subset of hashed nids for proc
20644 +       * assumes size is at least one                          */
20645 +
20646 +int get_nid_list(int index, unsigned int *nids, int size)
20647 +{
20648 +       int hindex, nr_nids = 0;
20649 +
20650 +       /* only show current and children */
20651 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20652 +               if (index > 0)
20653 +                       return 0;
20654 +               nids[nr_nids] = nx_current_nid();
20655 +               return 1;
20656 +       }
20657 +
20658 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20659 +               struct hlist_head *head = &nx_info_hash[hindex];
20660 +               struct hlist_node *pos;
20661 +
20662 +               spin_lock(&nx_info_hash_lock);
20663 +               hlist_for_each(pos, head) {
20664 +                       struct nx_info *nxi;
20665 +
20666 +                       if (--index > 0)
20667 +                               continue;
20668 +
20669 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20670 +                       nids[nr_nids] = nxi->nx_id;
20671 +                       if (++nr_nids >= size) {
20672 +                               spin_unlock(&nx_info_hash_lock);
20673 +                               goto out;
20674 +                       }
20675 +               }
20676 +               /* keep the lock time short */
20677 +               spin_unlock(&nx_info_hash_lock);
20678 +       }
20679 +out:
20680 +       return nr_nids;
20681 +}
20682 +#endif
20683 +
20684 +
20685 +/*
20686 + *     migrate task to new network
20687 + *     gets nxi, puts old_nxi on change
20688 + */
20689 +
20690 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20691 +{
20692 +       struct nx_info *old_nxi;
20693 +       int ret = 0;
20694 +
20695 +       if (!p || !nxi)
20696 +               BUG();
20697 +
20698 +       vxdprintk(VXD_CBIT(nid, 5),
20699 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20700 +               p, nxi, nxi->nx_id,
20701 +               atomic_read(&nxi->nx_usecnt),
20702 +               atomic_read(&nxi->nx_tasks));
20703 +
20704 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20705 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20706 +               return -EACCES;
20707 +
20708 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20709 +               return -EFAULT;
20710 +
20711 +       /* maybe disallow this completely? */
20712 +       old_nxi = task_get_nx_info(p);
20713 +       if (old_nxi == nxi)
20714 +               goto out;
20715 +
20716 +       task_lock(p);
20717 +       if (old_nxi)
20718 +               clr_nx_info(&p->nx_info);
20719 +       claim_nx_info(nxi, p);
20720 +       set_nx_info(&p->nx_info, nxi);
20721 +       p->nid = nxi->nx_id;
20722 +       task_unlock(p);
20723 +
20724 +       vxdprintk(VXD_CBIT(nid, 5),
20725 +               "moved task %p into nxi:%p[#%d]",
20726 +               p, nxi, nxi->nx_id);
20727 +
20728 +       if (old_nxi)
20729 +               release_nx_info(old_nxi, p);
20730 +       ret = 0;
20731 +out:
20732 +       put_nx_info(old_nxi);
20733 +       return ret;
20734 +}
20735 +
20736 +
20737 +void nx_set_persistent(struct nx_info *nxi)
20738 +{
20739 +       vxdprintk(VXD_CBIT(nid, 6),
20740 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20741 +
20742 +       get_nx_info(nxi);
20743 +       claim_nx_info(nxi, NULL);
20744 +}
20745 +
20746 +void nx_clear_persistent(struct nx_info *nxi)
20747 +{
20748 +       vxdprintk(VXD_CBIT(nid, 6),
20749 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20750 +
20751 +       release_nx_info(nxi, NULL);
20752 +       put_nx_info(nxi);
20753 +}
20754 +
20755 +void nx_update_persistent(struct nx_info *nxi)
20756 +{
20757 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20758 +               nx_set_persistent(nxi);
20759 +       else
20760 +               nx_clear_persistent(nxi);
20761 +}
20762 +
20763 +/* vserver syscall commands below here */
20764 +
20765 +/* taks nid and nx_info functions */
20766 +
20767 +#include <asm/uaccess.h>
20768 +
20769 +
20770 +int vc_task_nid(uint32_t id)
20771 +{
20772 +       nid_t nid;
20773 +
20774 +       if (id) {
20775 +               struct task_struct *tsk;
20776 +
20777 +               rcu_read_lock();
20778 +               tsk = find_task_by_real_pid(id);
20779 +               nid = (tsk) ? tsk->nid : -ESRCH;
20780 +               rcu_read_unlock();
20781 +       } else
20782 +               nid = nx_current_nid();
20783 +       return nid;
20784 +}
20785 +
20786 +
20787 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20788 +{
20789 +       struct vcmd_nx_info_v0 vc_data;
20790 +
20791 +       vc_data.nid = nxi->nx_id;
20792 +
20793 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20794 +               return -EFAULT;
20795 +       return 0;
20796 +}
20797 +
20798 +
20799 +/* network functions */
20800 +
20801 +int vc_net_create(uint32_t nid, void __user *data)
20802 +{
20803 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20804 +       struct nx_info *new_nxi;
20805 +       int ret;
20806 +
20807 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20808 +               return -EFAULT;
20809 +
20810 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20811 +               return -EINVAL;
20812 +
20813 +       new_nxi = __create_nx_info(nid);
20814 +       if (IS_ERR(new_nxi))
20815 +               return PTR_ERR(new_nxi);
20816 +
20817 +       /* initial flags */
20818 +       new_nxi->nx_flags = vc_data.flagword;
20819 +
20820 +       ret = -ENOEXEC;
20821 +       if (vs_net_change(new_nxi, VSC_NETUP))
20822 +               goto out;
20823 +
20824 +       ret = nx_migrate_task(current, new_nxi);
20825 +       if (ret)
20826 +               goto out;
20827 +
20828 +       /* return context id on success */
20829 +       ret = new_nxi->nx_id;
20830 +
20831 +       /* get a reference for persistent contexts */
20832 +       if ((vc_data.flagword & NXF_PERSISTENT))
20833 +               nx_set_persistent(new_nxi);
20834 +out:
20835 +       release_nx_info(new_nxi, NULL);
20836 +       put_nx_info(new_nxi);
20837 +       return ret;
20838 +}
20839 +
20840 +
20841 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20842 +{
20843 +       return nx_migrate_task(current, nxi);
20844 +}
20845 +
20846 +
20847 +
20848 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20849 +       uint16_t type, uint16_t flags)
20850 +{
20851 +       struct nx_addr_v4 *nxa = &nxi->v4;
20852 +
20853 +       if (NX_IPV4(nxi)) {
20854 +               /* locate last entry */
20855 +               for (; nxa->next; nxa = nxa->next);
20856 +               nxa->next = __alloc_nx_addr_v4();
20857 +               nxa = nxa->next;
20858 +
20859 +               if (IS_ERR(nxa))
20860 +                       return PTR_ERR(nxa);
20861 +       }
20862 +
20863 +       if (nxi->v4.next)
20864 +               /* remove single ip for ip list */
20865 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20866 +
20867 +       nxa->ip[0].s_addr = ip;
20868 +       nxa->ip[1].s_addr = ip2;
20869 +       nxa->mask.s_addr = mask;
20870 +       nxa->type = type;
20871 +       nxa->flags = flags;
20872 +       return 0;
20873 +}
20874 +
20875 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20876 +       uint16_t type, uint16_t flags)
20877 +{
20878 +       struct nx_addr_v4 *nxa = &nxi->v4;
20879 +
20880 +       switch (type) {
20881 +/*     case NXA_TYPE_ADDR:
20882 +               break;          */
20883 +
20884 +       case NXA_TYPE_ANY:
20885 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20886 +               memset(nxa, 0, sizeof(*nxa));
20887 +               break;
20888 +
20889 +       default:
20890 +               return -EINVAL;
20891 +       }
20892 +       return 0;
20893 +}
20894 +
20895 +
20896 +int vc_net_add(struct nx_info *nxi, void __user *data)
20897 +{
20898 +       struct vcmd_net_addr_v0 vc_data;
20899 +       int index, ret = 0;
20900 +
20901 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20902 +               return -EFAULT;
20903 +
20904 +       switch (vc_data.type) {
20905 +       case NXA_TYPE_IPV4:
20906 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20907 +                       return -EINVAL;
20908 +
20909 +               index = 0;
20910 +               while (index < vc_data.count) {
20911 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20912 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20913 +                       if (ret)
20914 +                               return ret;
20915 +                       index++;
20916 +               }
20917 +               ret = index;
20918 +               break;
20919 +
20920 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20921 +               nxi->v4_bcast = vc_data.ip[0];
20922 +               ret = 1;
20923 +               break;
20924 +
20925 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20926 +               nxi->v4_lback = vc_data.ip[0];
20927 +               ret = 1;
20928 +               break;
20929 +
20930 +       default:
20931 +               ret = -EINVAL;
20932 +               break;
20933 +       }
20934 +       return ret;
20935 +}
20936 +
20937 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20938 +{
20939 +       struct vcmd_net_addr_v0 vc_data;
20940 +
20941 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20942 +               return -EFAULT;
20943 +
20944 +       switch (vc_data.type) {
20945 +       case NXA_TYPE_ANY:
20946 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20947 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20948 +               break;
20949 +
20950 +       default:
20951 +               return -EINVAL;
20952 +       }
20953 +       return 0;
20954 +}
20955 +
20956 +
20957 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20958 +{
20959 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20960 +
20961 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20962 +               return -EFAULT;
20963 +
20964 +       switch (vc_data.type) {
20965 +       case NXA_TYPE_ADDR:
20966 +       case NXA_TYPE_MASK:
20967 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20968 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20969 +
20970 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20971 +               nxi->v4_bcast = vc_data.ip;
20972 +               break;
20973 +
20974 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20975 +               nxi->v4_lback = vc_data.ip;
20976 +               break;
20977 +
20978 +       default:
20979 +               return -EINVAL;
20980 +       }
20981 +       return 0;
20982 +}
20983 +
20984 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20985 +{
20986 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20987 +
20988 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20989 +               return -EFAULT;
20990 +
20991 +       switch (vc_data.type) {
20992 +       case NXA_TYPE_ADDR:
20993 +       case NXA_TYPE_MASK:
20994 +       case NXA_TYPE_RANGE:
20995 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20996 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20997 +
20998 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20999 +               nxi->v4_bcast = vc_data.ip;
21000 +               break;
21001 +
21002 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21003 +               nxi->v4_lback = vc_data.ip;
21004 +               break;
21005 +
21006 +       default:
21007 +               return -EINVAL;
21008 +       }
21009 +       return 0;
21010 +}
21011 +
21012 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
21013 +{
21014 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21015 +
21016 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21017 +               return -EFAULT;
21018 +
21019 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
21020 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21021 +}
21022 +
21023 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
21024 +{
21025 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21026 +
21027 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21028 +               return -EFAULT;
21029 +
21030 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21031 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21032 +}
21033 +
21034 +#ifdef CONFIG_IPV6
21035 +
21036 +int do_add_v6_addr(struct nx_info *nxi,
21037 +       struct in6_addr *ip, struct in6_addr *mask,
21038 +       uint32_t prefix, uint16_t type, uint16_t flags)
21039 +{
21040 +       struct nx_addr_v6 *nxa = &nxi->v6;
21041 +
21042 +       if (NX_IPV6(nxi)) {
21043 +               /* locate last entry */
21044 +               for (; nxa->next; nxa = nxa->next);
21045 +               nxa->next = __alloc_nx_addr_v6();
21046 +               nxa = nxa->next;
21047 +
21048 +               if (IS_ERR(nxa))
21049 +                       return PTR_ERR(nxa);
21050 +       }
21051 +
21052 +       nxa->ip = *ip;
21053 +       nxa->mask = *mask;
21054 +       nxa->prefix = prefix;
21055 +       nxa->type = type;
21056 +       nxa->flags = flags;
21057 +       return 0;
21058 +}
21059 +
21060 +
21061 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21062 +{
21063 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21064 +
21065 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21066 +               return -EFAULT;
21067 +
21068 +       switch (vc_data.type) {
21069 +       case NXA_TYPE_ADDR:
21070 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21071 +               /* fallthrough */
21072 +       case NXA_TYPE_MASK:
21073 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21074 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21075 +       default:
21076 +               return -EINVAL;
21077 +       }
21078 +       return 0;
21079 +}
21080 +
21081 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21082 +{
21083 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21084 +
21085 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21086 +               return -EFAULT;
21087 +
21088 +       switch (vc_data.type) {
21089 +       case NXA_TYPE_ANY:
21090 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21091 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21092 +               break;
21093 +
21094 +       default:
21095 +               return -EINVAL;
21096 +       }
21097 +       return 0;
21098 +}
21099 +
21100 +#endif /* CONFIG_IPV6 */
21101 +
21102 +
21103 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21104 +{
21105 +       struct vcmd_net_flags_v0 vc_data;
21106 +
21107 +       vc_data.flagword = nxi->nx_flags;
21108 +
21109 +       /* special STATE flag handling */
21110 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21111 +
21112 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21113 +               return -EFAULT;
21114 +       return 0;
21115 +}
21116 +
21117 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21118 +{
21119 +       struct vcmd_net_flags_v0 vc_data;
21120 +       uint64_t mask, trigger;
21121 +
21122 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21123 +               return -EFAULT;
21124 +
21125 +       /* special STATE flag handling */
21126 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21127 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21128 +
21129 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21130 +               vc_data.flagword, mask);
21131 +       if (trigger & NXF_PERSISTENT)
21132 +               nx_update_persistent(nxi);
21133 +
21134 +       return 0;
21135 +}
21136 +
21137 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21138 +{
21139 +       struct vcmd_net_caps_v0 vc_data;
21140 +
21141 +       vc_data.ncaps = nxi->nx_ncaps;
21142 +       vc_data.cmask = ~0ULL;
21143 +
21144 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21145 +               return -EFAULT;
21146 +       return 0;
21147 +}
21148 +
21149 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21150 +{
21151 +       struct vcmd_net_caps_v0 vc_data;
21152 +
21153 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21154 +               return -EFAULT;
21155 +
21156 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21157 +               vc_data.ncaps, vc_data.cmask);
21158 +       return 0;
21159 +}
21160 +
21161 +
21162 +#include <linux/module.h>
21163 +
21164 +module_init(init_network);
21165 +
21166 +EXPORT_SYMBOL_GPL(free_nx_info);
21167 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21168 +
21169 diff -NurpP --minimal linux-3.4.32/kernel/vserver/proc.c linux-3.4.32-vs2.3.3.9/kernel/vserver/proc.c
21170 --- linux-3.4.32/kernel/vserver/proc.c  1970-01-01 00:00:00.000000000 +0000
21171 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/proc.c        2012-05-21 16:15:05.000000000 +0000
21172 @@ -0,0 +1,1103 @@
21173 +/*
21174 + *  linux/kernel/vserver/proc.c
21175 + *
21176 + *  Virtual Context Support
21177 + *
21178 + *  Copyright (C) 2003-2011  Herbert Pötzl
21179 + *
21180 + *  V0.01  basic structure
21181 + *  V0.02  adaptation vs1.3.0
21182 + *  V0.03  proc permissions
21183 + *  V0.04  locking/generic
21184 + *  V0.05  next generation procfs
21185 + *  V0.06  inode validation
21186 + *  V0.07  generic rewrite vid
21187 + *  V0.08  remove inode type
21188 + *  V0.09  added u/wmask info
21189 + *
21190 + */
21191 +
21192 +#include <linux/proc_fs.h>
21193 +#include <linux/fs_struct.h>
21194 +#include <linux/mount.h>
21195 +#include <asm/unistd.h>
21196 +
21197 +#include <linux/vs_context.h>
21198 +#include <linux/vs_network.h>
21199 +#include <linux/vs_cvirt.h>
21200 +
21201 +#include <linux/in.h>
21202 +#include <linux/inetdevice.h>
21203 +#include <linux/vs_inet.h>
21204 +#include <linux/vs_inet6.h>
21205 +
21206 +#include <linux/vserver/global.h>
21207 +
21208 +#include "cvirt_proc.h"
21209 +#include "cacct_proc.h"
21210 +#include "limit_proc.h"
21211 +#include "sched_proc.h"
21212 +#include "vci_config.h"
21213 +
21214 +
21215 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21216 +{
21217 +       unsigned __capi;
21218 +
21219 +       CAP_FOR_EACH_U32(__capi) {
21220 +               buffer += sprintf(buffer, "%08x",
21221 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21222 +       }
21223 +       return buffer;
21224 +}
21225 +
21226 +
21227 +static struct proc_dir_entry *proc_virtual;
21228 +
21229 +static struct proc_dir_entry *proc_virtnet;
21230 +
21231 +
21232 +/* first the actual feeds */
21233 +
21234 +
21235 +static int proc_vci(char *buffer)
21236 +{
21237 +       return sprintf(buffer,
21238 +               "VCIVersion:\t%04x:%04x\n"
21239 +               "VCISyscall:\t%d\n"
21240 +               "VCIKernel:\t%08x\n",
21241 +               VCI_VERSION >> 16,
21242 +               VCI_VERSION & 0xFFFF,
21243 +               __NR_vserver,
21244 +               vci_kernel_config());
21245 +}
21246 +
21247 +static int proc_virtual_info(char *buffer)
21248 +{
21249 +       return proc_vci(buffer);
21250 +}
21251 +
21252 +static int proc_virtual_status(char *buffer)
21253 +{
21254 +       return sprintf(buffer,
21255 +               "#CTotal:\t%d\n"
21256 +               "#CActive:\t%d\n"
21257 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21258 +               "#InitTask:\t%d\t%d %d\n",
21259 +               atomic_read(&vx_global_ctotal),
21260 +               atomic_read(&vx_global_cactive),
21261 +               atomic_read(&vs_global_nsproxy),
21262 +               atomic_read(&vs_global_fs),
21263 +               atomic_read(&vs_global_mnt_ns),
21264 +               atomic_read(&vs_global_uts_ns),
21265 +               atomic_read(&nr_ipc_ns),
21266 +               atomic_read(&vs_global_user_ns),
21267 +               atomic_read(&vs_global_pid_ns),
21268 +               atomic_read(&init_task.usage),
21269 +               atomic_read(&init_task.nsproxy->count),
21270 +               init_task.fs->users);
21271 +}
21272 +
21273 +
21274 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21275 +{
21276 +       int length;
21277 +
21278 +       length = sprintf(buffer,
21279 +               "ID:\t%d\n"
21280 +               "Info:\t%p\n"
21281 +               "Init:\t%d\n"
21282 +               "OOM:\t%lld\n",
21283 +               vxi->vx_id,
21284 +               vxi,
21285 +               vxi->vx_initpid,
21286 +               vxi->vx_badness_bias);
21287 +       return length;
21288 +}
21289 +
21290 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21291 +{
21292 +       char *orig = buffer;
21293 +
21294 +       buffer += sprintf(buffer,
21295 +               "UseCnt:\t%d\n"
21296 +               "Tasks:\t%d\n"
21297 +               "Flags:\t%016llx\n",
21298 +               atomic_read(&vxi->vx_usecnt),
21299 +               atomic_read(&vxi->vx_tasks),
21300 +               (unsigned long long)vxi->vx_flags);
21301 +
21302 +       buffer += sprintf(buffer, "BCaps:\t");
21303 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21304 +       buffer += sprintf(buffer, "\n");
21305 +
21306 +       buffer += sprintf(buffer,
21307 +               "CCaps:\t%016llx\n"
21308 +               "Umask:\t%16llx\n"
21309 +               "Wmask:\t%16llx\n"
21310 +               "Spaces:\t%08lx %08lx\n",
21311 +               (unsigned long long)vxi->vx_ccaps,
21312 +               (unsigned long long)vxi->vx_umask,
21313 +               (unsigned long long)vxi->vx_wmask,
21314 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21315 +       return buffer - orig;
21316 +}
21317 +
21318 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21319 +{
21320 +       return vx_info_proc_limit(&vxi->limit, buffer);
21321 +}
21322 +
21323 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21324 +{
21325 +       int cpu, length;
21326 +
21327 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21328 +       for_each_online_cpu(cpu) {
21329 +               length += vx_info_proc_sched_pc(
21330 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21331 +                       buffer + length, cpu);
21332 +       }
21333 +       return length;
21334 +}
21335 +
21336 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21337 +{
21338 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21339 +}
21340 +
21341 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21342 +{
21343 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21344 +}
21345 +
21346 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21347 +{
21348 +       int cpu, length;
21349 +
21350 +       vx_update_load(vxi);
21351 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21352 +       for_each_online_cpu(cpu) {
21353 +               length += vx_info_proc_cvirt_pc(
21354 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21355 +                       buffer + length, cpu);
21356 +       }
21357 +       return length;
21358 +}
21359 +
21360 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21361 +{
21362 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21363 +}
21364 +
21365 +
21366 +static int proc_virtnet_info(char *buffer)
21367 +{
21368 +       return proc_vci(buffer);
21369 +}
21370 +
21371 +static int proc_virtnet_status(char *buffer)
21372 +{
21373 +       return sprintf(buffer,
21374 +               "#CTotal:\t%d\n"
21375 +               "#CActive:\t%d\n",
21376 +               atomic_read(&nx_global_ctotal),
21377 +               atomic_read(&nx_global_cactive));
21378 +}
21379 +
21380 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21381 +{
21382 +       struct nx_addr_v4 *v4a;
21383 +#ifdef CONFIG_IPV6
21384 +       struct nx_addr_v6 *v6a;
21385 +#endif
21386 +       int length, i;
21387 +
21388 +       length = sprintf(buffer,
21389 +               "ID:\t%d\n"
21390 +               "Info:\t%p\n"
21391 +               "Bcast:\t" NIPQUAD_FMT "\n"
21392 +               "Lback:\t" NIPQUAD_FMT "\n",
21393 +               nxi->nx_id,
21394 +               nxi,
21395 +               NIPQUAD(nxi->v4_bcast.s_addr),
21396 +               NIPQUAD(nxi->v4_lback.s_addr));
21397 +
21398 +       if (!NX_IPV4(nxi))
21399 +               goto skip_v4;
21400 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21401 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21402 +                       i, NXAV4(v4a));
21403 +skip_v4:
21404 +#ifdef CONFIG_IPV6
21405 +       if (!NX_IPV6(nxi))
21406 +               goto skip_v6;
21407 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21408 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21409 +                       i, NXAV6(v6a));
21410 +skip_v6:
21411 +#endif
21412 +       return length;
21413 +}
21414 +
21415 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21416 +{
21417 +       int length;
21418 +
21419 +       length = sprintf(buffer,
21420 +               "UseCnt:\t%d\n"
21421 +               "Tasks:\t%d\n"
21422 +               "Flags:\t%016llx\n"
21423 +               "NCaps:\t%016llx\n",
21424 +               atomic_read(&nxi->nx_usecnt),
21425 +               atomic_read(&nxi->nx_tasks),
21426 +               (unsigned long long)nxi->nx_flags,
21427 +               (unsigned long long)nxi->nx_ncaps);
21428 +       return length;
21429 +}
21430 +
21431 +
21432 +
21433 +/* here the inode helpers */
21434 +
21435 +struct vs_entry {
21436 +       int len;
21437 +       char *name;
21438 +       mode_t mode;
21439 +       struct inode_operations *iop;
21440 +       struct file_operations *fop;
21441 +       union proc_op op;
21442 +};
21443 +
21444 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21445 +{
21446 +       struct inode *inode = new_inode(sb);
21447 +
21448 +       if (!inode)
21449 +               goto out;
21450 +
21451 +       inode->i_mode = p->mode;
21452 +       if (p->iop)
21453 +               inode->i_op = p->iop;
21454 +       if (p->fop)
21455 +               inode->i_fop = p->fop;
21456 +
21457 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21458 +       inode->i_flags |= S_IMMUTABLE;
21459 +
21460 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21461 +
21462 +       inode->i_uid = 0;
21463 +       inode->i_gid = 0;
21464 +       inode->i_tag = 0;
21465 +out:
21466 +       return inode;
21467 +}
21468 +
21469 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21470 +       struct dentry *dentry, int id, void *ptr)
21471 +{
21472 +       struct vs_entry *p = ptr;
21473 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21474 +       struct dentry *error = ERR_PTR(-EINVAL);
21475 +
21476 +       if (!inode)
21477 +               goto out;
21478 +
21479 +       PROC_I(inode)->op = p->op;
21480 +       PROC_I(inode)->fd = id;
21481 +       d_add(dentry, inode);
21482 +       error = NULL;
21483 +out:
21484 +       return error;
21485 +}
21486 +
21487 +/* Lookups */
21488 +
21489 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21490 +
21491 +/*
21492 + * Fill a directory entry.
21493 + *
21494 + * If possible create the dcache entry and derive our inode number and
21495 + * file type from dcache entry.
21496 + *
21497 + * Since all of the proc inode numbers are dynamically generated, the inode
21498 + * numbers do not exist until the inode is cache.  This means creating the
21499 + * the dcache entry in readdir is necessary to keep the inode numbers
21500 + * reported by readdir in sync with the inode numbers reported
21501 + * by stat.
21502 + */
21503 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21504 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21505 +{
21506 +       struct dentry *child, *dir = filp->f_dentry;
21507 +       struct inode *inode;
21508 +       struct qstr qname;
21509 +       ino_t ino = 0;
21510 +       unsigned type = DT_UNKNOWN;
21511 +
21512 +       qname.name = name;
21513 +       qname.len  = len;
21514 +       qname.hash = full_name_hash(name, len);
21515 +
21516 +       child = d_lookup(dir, &qname);
21517 +       if (!child) {
21518 +               struct dentry *new;
21519 +               new = d_alloc(dir, &qname);
21520 +               if (new) {
21521 +                       child = instantiate(dir->d_inode, new, id, ptr);
21522 +                       if (child)
21523 +                               dput(new);
21524 +                       else
21525 +                               child = new;
21526 +               }
21527 +       }
21528 +       if (!child || IS_ERR(child) || !child->d_inode)
21529 +               goto end_instantiate;
21530 +       inode = child->d_inode;
21531 +       if (inode) {
21532 +               ino = inode->i_ino;
21533 +               type = inode->i_mode >> 12;
21534 +       }
21535 +       dput(child);
21536 +end_instantiate:
21537 +       if (!ino)
21538 +               ino = find_inode_number(dir, &qname);
21539 +       if (!ino)
21540 +               ino = 1;
21541 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21542 +}
21543 +
21544 +
21545 +
21546 +/* get and revalidate vx_info/xid */
21547 +
21548 +static inline
21549 +struct vx_info *get_proc_vx_info(struct inode *inode)
21550 +{
21551 +       return lookup_vx_info(PROC_I(inode)->fd);
21552 +}
21553 +
21554 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21555 +{
21556 +       struct inode *inode = dentry->d_inode;
21557 +       xid_t xid = PROC_I(inode)->fd;
21558 +
21559 +       if (!xid || xid_is_hashed(xid))
21560 +               return 1;
21561 +       d_drop(dentry);
21562 +       return 0;
21563 +}
21564 +
21565 +
21566 +/* get and revalidate nx_info/nid */
21567 +
21568 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21569 +{
21570 +       struct inode *inode = dentry->d_inode;
21571 +       nid_t nid = PROC_I(inode)->fd;
21572 +
21573 +       if (!nid || nid_is_hashed(nid))
21574 +               return 1;
21575 +       d_drop(dentry);
21576 +       return 0;
21577 +}
21578 +
21579 +
21580 +
21581 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21582 +
21583 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21584 +                         size_t count, loff_t *ppos)
21585 +{
21586 +       struct inode *inode = file->f_dentry->d_inode;
21587 +       unsigned long page;
21588 +       ssize_t length = 0;
21589 +
21590 +       if (count > PROC_BLOCK_SIZE)
21591 +               count = PROC_BLOCK_SIZE;
21592 +
21593 +       /* fade that out as soon as stable */
21594 +       WARN_ON(PROC_I(inode)->fd);
21595 +
21596 +       if (!(page = __get_free_page(GFP_KERNEL)))
21597 +               return -ENOMEM;
21598 +
21599 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21600 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21601 +
21602 +       if (length >= 0)
21603 +               length = simple_read_from_buffer(buf, count, ppos,
21604 +                       (char *)page, length);
21605 +
21606 +       free_page(page);
21607 +       return length;
21608 +}
21609 +
21610 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21611 +                         size_t count, loff_t *ppos)
21612 +{
21613 +       struct inode *inode = file->f_dentry->d_inode;
21614 +       struct vx_info *vxi = NULL;
21615 +       xid_t xid = PROC_I(inode)->fd;
21616 +       unsigned long page;
21617 +       ssize_t length = 0;
21618 +
21619 +       if (count > PROC_BLOCK_SIZE)
21620 +               count = PROC_BLOCK_SIZE;
21621 +
21622 +       /* fade that out as soon as stable */
21623 +       WARN_ON(!xid);
21624 +       vxi = lookup_vx_info(xid);
21625 +       if (!vxi)
21626 +               goto out;
21627 +
21628 +       length = -ENOMEM;
21629 +       if (!(page = __get_free_page(GFP_KERNEL)))
21630 +               goto out_put;
21631 +
21632 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21633 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21634 +
21635 +       if (length >= 0)
21636 +               length = simple_read_from_buffer(buf, count, ppos,
21637 +                       (char *)page, length);
21638 +
21639 +       free_page(page);
21640 +out_put:
21641 +       put_vx_info(vxi);
21642 +out:
21643 +       return length;
21644 +}
21645 +
21646 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21647 +                         size_t count, loff_t *ppos)
21648 +{
21649 +       struct inode *inode = file->f_dentry->d_inode;
21650 +       struct nx_info *nxi = NULL;
21651 +       nid_t nid = PROC_I(inode)->fd;
21652 +       unsigned long page;
21653 +       ssize_t length = 0;
21654 +
21655 +       if (count > PROC_BLOCK_SIZE)
21656 +               count = PROC_BLOCK_SIZE;
21657 +
21658 +       /* fade that out as soon as stable */
21659 +       WARN_ON(!nid);
21660 +       nxi = lookup_nx_info(nid);
21661 +       if (!nxi)
21662 +               goto out;
21663 +
21664 +       length = -ENOMEM;
21665 +       if (!(page = __get_free_page(GFP_KERNEL)))
21666 +               goto out_put;
21667 +
21668 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21669 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21670 +
21671 +       if (length >= 0)
21672 +               length = simple_read_from_buffer(buf, count, ppos,
21673 +                       (char *)page, length);
21674 +
21675 +       free_page(page);
21676 +out_put:
21677 +       put_nx_info(nxi);
21678 +out:
21679 +       return length;
21680 +}
21681 +
21682 +
21683 +
21684 +/* here comes the lower level */
21685 +
21686 +
21687 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21688 +       .len  = sizeof(NAME) - 1,       \
21689 +       .name = (NAME),                 \
21690 +       .mode = MODE,                   \
21691 +       .iop  = IOP,                    \
21692 +       .fop  = FOP,                    \
21693 +       .op   = OP,                     \
21694 +}
21695 +
21696 +
21697 +#define DIR(NAME, MODE, OTYPE)                         \
21698 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21699 +               &proc_ ## OTYPE ## _inode_operations,   \
21700 +               &proc_ ## OTYPE ## _file_operations, { } )
21701 +
21702 +#define INF(NAME, MODE, OTYPE)                         \
21703 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21704 +               &proc_vs_info_file_operations,          \
21705 +               { .proc_vs_read = &proc_##OTYPE } )
21706 +
21707 +#define VINF(NAME, MODE, OTYPE)                                \
21708 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21709 +               &proc_vx_info_file_operations,          \
21710 +               { .proc_vxi_read = &proc_##OTYPE } )
21711 +
21712 +#define NINF(NAME, MODE, OTYPE)                                \
21713 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21714 +               &proc_nx_info_file_operations,          \
21715 +               { .proc_nxi_read = &proc_##OTYPE } )
21716 +
21717 +
21718 +static struct file_operations proc_vs_info_file_operations = {
21719 +       .read =         proc_vs_info_read,
21720 +};
21721 +
21722 +static struct file_operations proc_vx_info_file_operations = {
21723 +       .read =         proc_vx_info_read,
21724 +};
21725 +
21726 +static struct dentry_operations proc_xid_dentry_operations = {
21727 +       .d_revalidate = proc_xid_revalidate,
21728 +};
21729 +
21730 +static struct vs_entry vx_base_stuff[] = {
21731 +       VINF("info",    S_IRUGO, vxi_info),
21732 +       VINF("status",  S_IRUGO, vxi_status),
21733 +       VINF("limit",   S_IRUGO, vxi_limit),
21734 +       VINF("sched",   S_IRUGO, vxi_sched),
21735 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21736 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21737 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21738 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21739 +       {}
21740 +};
21741 +
21742 +
21743 +
21744 +
21745 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21746 +       struct dentry *dentry, int id, void *ptr)
21747 +{
21748 +       dentry->d_op = &proc_xid_dentry_operations;
21749 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21750 +}
21751 +
21752 +static struct dentry *proc_xid_lookup(struct inode *dir,
21753 +       struct dentry *dentry, struct nameidata *nd)
21754 +{
21755 +       struct vs_entry *p = vx_base_stuff;
21756 +       struct dentry *error = ERR_PTR(-ENOENT);
21757 +
21758 +       for (; p->name; p++) {
21759 +               if (p->len != dentry->d_name.len)
21760 +                       continue;
21761 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21762 +                       break;
21763 +       }
21764 +       if (!p->name)
21765 +               goto out;
21766 +
21767 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21768 +out:
21769 +       return error;
21770 +}
21771 +
21772 +static int proc_xid_readdir(struct file *filp,
21773 +       void *dirent, filldir_t filldir)
21774 +{
21775 +       struct dentry *dentry = filp->f_dentry;
21776 +       struct inode *inode = dentry->d_inode;
21777 +       struct vs_entry *p = vx_base_stuff;
21778 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21779 +       int pos, index;
21780 +       u64 ino;
21781 +
21782 +       pos = filp->f_pos;
21783 +       switch (pos) {
21784 +       case 0:
21785 +               ino = inode->i_ino;
21786 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21787 +                       goto out;
21788 +               pos++;
21789 +               /* fall through */
21790 +       case 1:
21791 +               ino = parent_ino(dentry);
21792 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21793 +                       goto out;
21794 +               pos++;
21795 +               /* fall through */
21796 +       default:
21797 +               index = pos - 2;
21798 +               if (index >= size)
21799 +                       goto out;
21800 +               for (p += index; p->name; p++) {
21801 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21802 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21803 +                               goto out;
21804 +                       pos++;
21805 +               }
21806 +       }
21807 +out:
21808 +       filp->f_pos = pos;
21809 +       return 1;
21810 +}
21811 +
21812 +
21813 +
21814 +static struct file_operations proc_nx_info_file_operations = {
21815 +       .read =         proc_nx_info_read,
21816 +};
21817 +
21818 +static struct dentry_operations proc_nid_dentry_operations = {
21819 +       .d_revalidate = proc_nid_revalidate,
21820 +};
21821 +
21822 +static struct vs_entry nx_base_stuff[] = {
21823 +       NINF("info",    S_IRUGO, nxi_info),
21824 +       NINF("status",  S_IRUGO, nxi_status),
21825 +       {}
21826 +};
21827 +
21828 +
21829 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21830 +       struct dentry *dentry, int id, void *ptr)
21831 +{
21832 +       dentry->d_op = &proc_nid_dentry_operations;
21833 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21834 +}
21835 +
21836 +static struct dentry *proc_nid_lookup(struct inode *dir,
21837 +       struct dentry *dentry, struct nameidata *nd)
21838 +{
21839 +       struct vs_entry *p = nx_base_stuff;
21840 +       struct dentry *error = ERR_PTR(-ENOENT);
21841 +
21842 +       for (; p->name; p++) {
21843 +               if (p->len != dentry->d_name.len)
21844 +                       continue;
21845 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21846 +                       break;
21847 +       }
21848 +       if (!p->name)
21849 +               goto out;
21850 +
21851 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21852 +out:
21853 +       return error;
21854 +}
21855 +
21856 +static int proc_nid_readdir(struct file *filp,
21857 +       void *dirent, filldir_t filldir)
21858 +{
21859 +       struct dentry *dentry = filp->f_dentry;
21860 +       struct inode *inode = dentry->d_inode;
21861 +       struct vs_entry *p = nx_base_stuff;
21862 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21863 +       int pos, index;
21864 +       u64 ino;
21865 +
21866 +       pos = filp->f_pos;
21867 +       switch (pos) {
21868 +       case 0:
21869 +               ino = inode->i_ino;
21870 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21871 +                       goto out;
21872 +               pos++;
21873 +               /* fall through */
21874 +       case 1:
21875 +               ino = parent_ino(dentry);
21876 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21877 +                       goto out;
21878 +               pos++;
21879 +               /* fall through */
21880 +       default:
21881 +               index = pos - 2;
21882 +               if (index >= size)
21883 +                       goto out;
21884 +               for (p += index; p->name; p++) {
21885 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21886 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21887 +                               goto out;
21888 +                       pos++;
21889 +               }
21890 +       }
21891 +out:
21892 +       filp->f_pos = pos;
21893 +       return 1;
21894 +}
21895 +
21896 +
21897 +#define MAX_MULBY10    ((~0U - 9) / 10)
21898 +
21899 +static inline int atovid(const char *str, int len)
21900 +{
21901 +       int vid, c;
21902 +
21903 +       vid = 0;
21904 +       while (len-- > 0) {
21905 +               c = *str - '0';
21906 +               str++;
21907 +               if (c > 9)
21908 +                       return -1;
21909 +               if (vid >= MAX_MULBY10)
21910 +                       return -1;
21911 +               vid *= 10;
21912 +               vid += c;
21913 +               if (!vid)
21914 +                       return -1;
21915 +       }
21916 +       return vid;
21917 +}
21918 +
21919 +/* now the upper level (virtual) */
21920 +
21921 +
21922 +static struct file_operations proc_xid_file_operations = {
21923 +       .read =         generic_read_dir,
21924 +       .readdir =      proc_xid_readdir,
21925 +};
21926 +
21927 +static struct inode_operations proc_xid_inode_operations = {
21928 +       .lookup =       proc_xid_lookup,
21929 +};
21930 +
21931 +static struct vs_entry vx_virtual_stuff[] = {
21932 +       INF("info",     S_IRUGO, virtual_info),
21933 +       INF("status",   S_IRUGO, virtual_status),
21934 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21935 +};
21936 +
21937 +
21938 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21939 +       struct dentry *dentry, struct nameidata *nd)
21940 +{
21941 +       struct vs_entry *p = vx_virtual_stuff;
21942 +       struct dentry *error = ERR_PTR(-ENOENT);
21943 +       int id = 0;
21944 +
21945 +       for (; p->name; p++) {
21946 +               if (p->len != dentry->d_name.len)
21947 +                       continue;
21948 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21949 +                       break;
21950 +       }
21951 +       if (p->name)
21952 +               goto instantiate;
21953 +
21954 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21955 +       if ((id < 0) || !xid_is_hashed(id))
21956 +               goto out;
21957 +
21958 +instantiate:
21959 +       error = proc_xid_instantiate(dir, dentry, id, p);
21960 +out:
21961 +       return error;
21962 +}
21963 +
21964 +static struct file_operations proc_nid_file_operations = {
21965 +       .read =         generic_read_dir,
21966 +       .readdir =      proc_nid_readdir,
21967 +};
21968 +
21969 +static struct inode_operations proc_nid_inode_operations = {
21970 +       .lookup =       proc_nid_lookup,
21971 +};
21972 +
21973 +static struct vs_entry nx_virtnet_stuff[] = {
21974 +       INF("info",     S_IRUGO, virtnet_info),
21975 +       INF("status",   S_IRUGO, virtnet_status),
21976 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21977 +};
21978 +
21979 +
21980 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21981 +       struct dentry *dentry, struct nameidata *nd)
21982 +{
21983 +       struct vs_entry *p = nx_virtnet_stuff;
21984 +       struct dentry *error = ERR_PTR(-ENOENT);
21985 +       int id = 0;
21986 +
21987 +       for (; p->name; p++) {
21988 +               if (p->len != dentry->d_name.len)
21989 +                       continue;
21990 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21991 +                       break;
21992 +       }
21993 +       if (p->name)
21994 +               goto instantiate;
21995 +
21996 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21997 +       if ((id < 0) || !nid_is_hashed(id))
21998 +               goto out;
21999 +
22000 +instantiate:
22001 +       error = proc_nid_instantiate(dir, dentry, id, p);
22002 +out:
22003 +       return error;
22004 +}
22005 +
22006 +
22007 +#define PROC_MAXVIDS 32
22008 +
22009 +int proc_virtual_readdir(struct file *filp,
22010 +       void *dirent, filldir_t filldir)
22011 +{
22012 +       struct dentry *dentry = filp->f_dentry;
22013 +       struct inode *inode = dentry->d_inode;
22014 +       struct vs_entry *p = vx_virtual_stuff;
22015 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22016 +       int pos, index;
22017 +       unsigned int xid_array[PROC_MAXVIDS];
22018 +       char buf[PROC_NUMBUF];
22019 +       unsigned int nr_xids, i;
22020 +       u64 ino;
22021 +
22022 +       pos = filp->f_pos;
22023 +       switch (pos) {
22024 +       case 0:
22025 +               ino = inode->i_ino;
22026 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22027 +                       goto out;
22028 +               pos++;
22029 +               /* fall through */
22030 +       case 1:
22031 +               ino = parent_ino(dentry);
22032 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22033 +                       goto out;
22034 +               pos++;
22035 +               /* fall through */
22036 +       default:
22037 +               index = pos - 2;
22038 +               if (index >= size)
22039 +                       goto entries;
22040 +               for (p += index; p->name; p++) {
22041 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22042 +                               vs_proc_instantiate, 0, p))
22043 +                               goto out;
22044 +                       pos++;
22045 +               }
22046 +       entries:
22047 +               index = pos - size;
22048 +               p = &vx_virtual_stuff[size - 1];
22049 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22050 +               for (i = 0; i < nr_xids; i++) {
22051 +                       int n, xid = xid_array[i];
22052 +                       unsigned int j = PROC_NUMBUF;
22053 +
22054 +                       n = xid;
22055 +                       do
22056 +                               buf[--j] = '0' + (n % 10);
22057 +                       while (n /= 10);
22058 +
22059 +                       if (proc_fill_cache(filp, dirent, filldir,
22060 +                               buf + j, PROC_NUMBUF - j,
22061 +                               vs_proc_instantiate, xid, p))
22062 +                               goto out;
22063 +                       pos++;
22064 +               }
22065 +       }
22066 +out:
22067 +       filp->f_pos = pos;
22068 +       return 0;
22069 +}
22070 +
22071 +static int proc_virtual_getattr(struct vfsmount *mnt,
22072 +       struct dentry *dentry, struct kstat *stat)
22073 +{
22074 +       struct inode *inode = dentry->d_inode;
22075 +
22076 +       generic_fillattr(inode, stat);
22077 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22078 +       return 0;
22079 +}
22080 +
22081 +static struct file_operations proc_virtual_dir_operations = {
22082 +       .read =         generic_read_dir,
22083 +       .readdir =      proc_virtual_readdir,
22084 +};
22085 +
22086 +static struct inode_operations proc_virtual_dir_inode_operations = {
22087 +       .getattr =      proc_virtual_getattr,
22088 +       .lookup =       proc_virtual_lookup,
22089 +};
22090 +
22091 +
22092 +
22093 +
22094 +
22095 +int proc_virtnet_readdir(struct file *filp,
22096 +       void *dirent, filldir_t filldir)
22097 +{
22098 +       struct dentry *dentry = filp->f_dentry;
22099 +       struct inode *inode = dentry->d_inode;
22100 +       struct vs_entry *p = nx_virtnet_stuff;
22101 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22102 +       int pos, index;
22103 +       unsigned int nid_array[PROC_MAXVIDS];
22104 +       char buf[PROC_NUMBUF];
22105 +       unsigned int nr_nids, i;
22106 +       u64 ino;
22107 +
22108 +       pos = filp->f_pos;
22109 +       switch (pos) {
22110 +       case 0:
22111 +               ino = inode->i_ino;
22112 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22113 +                       goto out;
22114 +               pos++;
22115 +               /* fall through */
22116 +       case 1:
22117 +               ino = parent_ino(dentry);
22118 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22119 +                       goto out;
22120 +               pos++;
22121 +               /* fall through */
22122 +       default:
22123 +               index = pos - 2;
22124 +               if (index >= size)
22125 +                       goto entries;
22126 +               for (p += index; p->name; p++) {
22127 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22128 +                               vs_proc_instantiate, 0, p))
22129 +                               goto out;
22130 +                       pos++;
22131 +               }
22132 +       entries:
22133 +               index = pos - size;
22134 +               p = &nx_virtnet_stuff[size - 1];
22135 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22136 +               for (i = 0; i < nr_nids; i++) {
22137 +                       int n, nid = nid_array[i];
22138 +                       unsigned int j = PROC_NUMBUF;
22139 +
22140 +                       n = nid;
22141 +                       do
22142 +                               buf[--j] = '0' + (n % 10);
22143 +                       while (n /= 10);
22144 +
22145 +                       if (proc_fill_cache(filp, dirent, filldir,
22146 +                               buf + j, PROC_NUMBUF - j,
22147 +                               vs_proc_instantiate, nid, p))
22148 +                               goto out;
22149 +                       pos++;
22150 +               }
22151 +       }
22152 +out:
22153 +       filp->f_pos = pos;
22154 +       return 0;
22155 +}
22156 +
22157 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22158 +       struct dentry *dentry, struct kstat *stat)
22159 +{
22160 +       struct inode *inode = dentry->d_inode;
22161 +
22162 +       generic_fillattr(inode, stat);
22163 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22164 +       return 0;
22165 +}
22166 +
22167 +static struct file_operations proc_virtnet_dir_operations = {
22168 +       .read =         generic_read_dir,
22169 +       .readdir =      proc_virtnet_readdir,
22170 +};
22171 +
22172 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22173 +       .getattr =      proc_virtnet_getattr,
22174 +       .lookup =       proc_virtnet_lookup,
22175 +};
22176 +
22177 +
22178 +
22179 +void proc_vx_init(void)
22180 +{
22181 +       struct proc_dir_entry *ent;
22182 +
22183 +       ent = proc_mkdir("virtual", 0);
22184 +       if (ent) {
22185 +               ent->proc_fops = &proc_virtual_dir_operations;
22186 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22187 +       }
22188 +       proc_virtual = ent;
22189 +
22190 +       ent = proc_mkdir("virtnet", 0);
22191 +       if (ent) {
22192 +               ent->proc_fops = &proc_virtnet_dir_operations;
22193 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22194 +       }
22195 +       proc_virtnet = ent;
22196 +}
22197 +
22198 +
22199 +
22200 +
22201 +/* per pid info */
22202 +
22203 +
22204 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22205 +{
22206 +       struct vx_info *vxi;
22207 +       char *orig = buffer;
22208 +
22209 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22210 +
22211 +       vxi = task_get_vx_info(p);
22212 +       if (!vxi)
22213 +               goto out;
22214 +
22215 +       buffer += sprintf(buffer, "BCaps:\t");
22216 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22217 +       buffer += sprintf(buffer, "\n");
22218 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22219 +               (unsigned long long)vxi->vx_ccaps);
22220 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22221 +               (unsigned long long)vxi->vx_flags);
22222 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22223 +
22224 +       put_vx_info(vxi);
22225 +out:
22226 +       return buffer - orig;
22227 +}
22228 +
22229 +
22230 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22231 +{
22232 +       struct nx_info *nxi;
22233 +       struct nx_addr_v4 *v4a;
22234 +#ifdef CONFIG_IPV6
22235 +       struct nx_addr_v6 *v6a;
22236 +#endif
22237 +       char *orig = buffer;
22238 +       int i;
22239 +
22240 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22241 +
22242 +       nxi = task_get_nx_info(p);
22243 +       if (!nxi)
22244 +               goto out;
22245 +
22246 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22247 +               (unsigned long long)nxi->nx_ncaps);
22248 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22249 +               (unsigned long long)nxi->nx_flags);
22250 +
22251 +       buffer += sprintf(buffer,
22252 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22253 +               NIPQUAD(nxi->v4_bcast.s_addr));
22254 +       buffer += sprintf (buffer,
22255 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22256 +               NIPQUAD(nxi->v4_lback.s_addr));
22257 +       if (!NX_IPV4(nxi))
22258 +               goto skip_v4;
22259 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22260 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22261 +                       i, NXAV4(v4a));
22262 +skip_v4:
22263 +#ifdef CONFIG_IPV6
22264 +       if (!NX_IPV6(nxi))
22265 +               goto skip_v6;
22266 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22267 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22268 +                       i, NXAV6(v6a));
22269 +skip_v6:
22270 +#endif
22271 +       put_nx_info(nxi);
22272 +out:
22273 +       return buffer - orig;
22274 +}
22275 +
22276 diff -NurpP --minimal linux-3.4.32/kernel/vserver/sched.c linux-3.4.32-vs2.3.3.9/kernel/vserver/sched.c
22277 --- linux-3.4.32/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
22278 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/sched.c       2012-05-21 16:25:11.000000000 +0000
22279 @@ -0,0 +1,83 @@
22280 +/*
22281 + *  linux/kernel/vserver/sched.c
22282 + *
22283 + *  Virtual Server: Scheduler Support
22284 + *
22285 + *  Copyright (C) 2004-2010  Herbert Pötzl
22286 + *
22287 + *  V0.01  adapted Sam Vilains version to 2.6.3
22288 + *  V0.02  removed legacy interface
22289 + *  V0.03  changed vcmds to vxi arg
22290 + *  V0.04  removed older and legacy interfaces
22291 + *  V0.05  removed scheduler code/commands
22292 + *
22293 + */
22294 +
22295 +#include <linux/vs_context.h>
22296 +#include <linux/vs_sched.h>
22297 +#include <linux/cpumask.h>
22298 +#include <linux/vserver/sched_cmd.h>
22299 +
22300 +#include <asm/uaccess.h>
22301 +
22302 +
22303 +void vx_update_sched_param(struct _vx_sched *sched,
22304 +       struct _vx_sched_pc *sched_pc)
22305 +{
22306 +       sched_pc->prio_bias = sched->prio_bias;
22307 +}
22308 +
22309 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22310 +{
22311 +       int cpu;
22312 +
22313 +       if (data->prio_bias > MAX_PRIO_BIAS)
22314 +               data->prio_bias = MAX_PRIO_BIAS;
22315 +       if (data->prio_bias < MIN_PRIO_BIAS)
22316 +               data->prio_bias = MIN_PRIO_BIAS;
22317 +
22318 +       if (data->cpu_id != ~0) {
22319 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22320 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22321 +                       cpu_online_mask);
22322 +       } else
22323 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22324 +
22325 +       for_each_cpu_mask(cpu, vxi->sched.update)
22326 +               vx_update_sched_param(&vxi->sched,
22327 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22328 +       return 0;
22329 +}
22330 +
22331 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22332 +{
22333 +       struct vcmd_prio_bias vc_data;
22334 +
22335 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22336 +               return -EFAULT;
22337 +
22338 +       return do_set_prio_bias(vxi, &vc_data);
22339 +}
22340 +
22341 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22342 +{
22343 +       struct vcmd_prio_bias vc_data;
22344 +       struct _vx_sched_pc *pcd;
22345 +       int cpu;
22346 +
22347 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22348 +               return -EFAULT;
22349 +
22350 +       cpu = vc_data.cpu_id;
22351 +
22352 +       if (!cpu_possible(cpu))
22353 +               return -EINVAL;
22354 +
22355 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22356 +       vc_data.prio_bias = pcd->prio_bias;
22357 +
22358 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22359 +               return -EFAULT;
22360 +       return 0;
22361 +}
22362 +
22363 diff -NurpP --minimal linux-3.4.32/kernel/vserver/sched_init.h linux-3.4.32-vs2.3.3.9/kernel/vserver/sched_init.h
22364 --- linux-3.4.32/kernel/vserver/sched_init.h    1970-01-01 00:00:00.000000000 +0000
22365 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/sched_init.h  2012-05-21 16:15:05.000000000 +0000
22366 @@ -0,0 +1,27 @@
22367 +
22368 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22369 +{
22370 +       /* scheduling; hard code starting values as constants */
22371 +       sched->prio_bias = 0;
22372 +}
22373 +
22374 +static inline
22375 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22376 +{
22377 +       sched_pc->prio_bias = 0;
22378 +
22379 +       sched_pc->user_ticks = 0;
22380 +       sched_pc->sys_ticks = 0;
22381 +       sched_pc->hold_ticks = 0;
22382 +}
22383 +
22384 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22385 +{
22386 +       return;
22387 +}
22388 +
22389 +static inline
22390 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22391 +{
22392 +       return;
22393 +}
22394 diff -NurpP --minimal linux-3.4.32/kernel/vserver/sched_proc.h linux-3.4.32-vs2.3.3.9/kernel/vserver/sched_proc.h
22395 --- linux-3.4.32/kernel/vserver/sched_proc.h    1970-01-01 00:00:00.000000000 +0000
22396 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/sched_proc.h  2012-05-21 16:15:05.000000000 +0000
22397 @@ -0,0 +1,32 @@
22398 +#ifndef _VX_SCHED_PROC_H
22399 +#define _VX_SCHED_PROC_H
22400 +
22401 +
22402 +static inline
22403 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22404 +{
22405 +       int length = 0;
22406 +
22407 +       length += sprintf(buffer,
22408 +               "PrioBias:\t%8d\n",
22409 +               sched->prio_bias);
22410 +       return length;
22411 +}
22412 +
22413 +static inline
22414 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22415 +       char *buffer, int cpu)
22416 +{
22417 +       int length = 0;
22418 +
22419 +       length += sprintf(buffer + length,
22420 +               "cpu %d: %lld %lld %lld", cpu,
22421 +               (unsigned long long)sched_pc->user_ticks,
22422 +               (unsigned long long)sched_pc->sys_ticks,
22423 +               (unsigned long long)sched_pc->hold_ticks);
22424 +       length += sprintf(buffer + length,
22425 +               " %d\n", sched_pc->prio_bias);
22426 +       return length;
22427 +}
22428 +
22429 +#endif /* _VX_SCHED_PROC_H */
22430 diff -NurpP --minimal linux-3.4.32/kernel/vserver/signal.c linux-3.4.32-vs2.3.3.9/kernel/vserver/signal.c
22431 --- linux-3.4.32/kernel/vserver/signal.c        1970-01-01 00:00:00.000000000 +0000
22432 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/signal.c      2012-05-21 16:15:05.000000000 +0000
22433 @@ -0,0 +1,134 @@
22434 +/*
22435 + *  linux/kernel/vserver/signal.c
22436 + *
22437 + *  Virtual Server: Signal Support
22438 + *
22439 + *  Copyright (C) 2003-2007  Herbert Pötzl
22440 + *
22441 + *  V0.01  broken out from vcontext V0.05
22442 + *  V0.02  changed vcmds to vxi arg
22443 + *  V0.03  adjusted siginfo for kill
22444 + *
22445 + */
22446 +
22447 +#include <asm/uaccess.h>
22448 +
22449 +#include <linux/vs_context.h>
22450 +#include <linux/vs_pid.h>
22451 +#include <linux/vserver/signal_cmd.h>
22452 +
22453 +
22454 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22455 +{
22456 +       int retval, count = 0;
22457 +       struct task_struct *p;
22458 +       struct siginfo *sip = SEND_SIG_PRIV;
22459 +
22460 +       retval = -ESRCH;
22461 +       vxdprintk(VXD_CBIT(misc, 4),
22462 +               "vx_info_kill(%p[#%d],%d,%d)*",
22463 +               vxi, vxi->vx_id, pid, sig);
22464 +       read_lock(&tasklist_lock);
22465 +       switch (pid) {
22466 +       case  0:
22467 +       case -1:
22468 +               for_each_process(p) {
22469 +                       int err = 0;
22470 +
22471 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22472 +                               (pid && vxi->vx_initpid == p->pid))
22473 +                               continue;
22474 +
22475 +                       err = group_send_sig_info(sig, sip, p);
22476 +                       ++count;
22477 +                       if (err != -EPERM)
22478 +                               retval = err;
22479 +               }
22480 +               break;
22481 +
22482 +       case 1:
22483 +               if (vxi->vx_initpid) {
22484 +                       pid = vxi->vx_initpid;
22485 +                       /* for now, only SIGINT to private init ... */
22486 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22487 +                               /* ... as long as there are tasks left */
22488 +                               (atomic_read(&vxi->vx_tasks) > 1))
22489 +                               sig = SIGINT;
22490 +               }
22491 +               /* fallthrough */
22492 +       default:
22493 +               rcu_read_lock();
22494 +               p = find_task_by_real_pid(pid);
22495 +               rcu_read_unlock();
22496 +               if (p) {
22497 +                       if (vx_task_xid(p) == vxi->vx_id)
22498 +                               retval = group_send_sig_info(sig, sip, p);
22499 +               }
22500 +               break;
22501 +       }
22502 +       read_unlock(&tasklist_lock);
22503 +       vxdprintk(VXD_CBIT(misc, 4),
22504 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22505 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22506 +       return retval;
22507 +}
22508 +
22509 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22510 +{
22511 +       struct vcmd_ctx_kill_v0 vc_data;
22512 +
22513 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22514 +               return -EFAULT;
22515 +
22516 +       /* special check to allow guest shutdown */
22517 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22518 +               /* forbid killall pid=0 when init is present */
22519 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22520 +               (vc_data.pid > 1)))
22521 +               return -EACCES;
22522 +
22523 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22524 +}
22525 +
22526 +
22527 +static int __wait_exit(struct vx_info *vxi)
22528 +{
22529 +       DECLARE_WAITQUEUE(wait, current);
22530 +       int ret = 0;
22531 +
22532 +       add_wait_queue(&vxi->vx_wait, &wait);
22533 +       set_current_state(TASK_INTERRUPTIBLE);
22534 +
22535 +wait:
22536 +       if (vx_info_state(vxi,
22537 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22538 +               goto out;
22539 +       if (signal_pending(current)) {
22540 +               ret = -ERESTARTSYS;
22541 +               goto out;
22542 +       }
22543 +       schedule();
22544 +       goto wait;
22545 +
22546 +out:
22547 +       set_current_state(TASK_RUNNING);
22548 +       remove_wait_queue(&vxi->vx_wait, &wait);
22549 +       return ret;
22550 +}
22551 +
22552 +
22553 +
22554 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22555 +{
22556 +       struct vcmd_wait_exit_v0 vc_data;
22557 +       int ret;
22558 +
22559 +       ret = __wait_exit(vxi);
22560 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22561 +       vc_data.exit_code = vxi->exit_code;
22562 +
22563 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22564 +               ret = -EFAULT;
22565 +       return ret;
22566 +}
22567 +
22568 diff -NurpP --minimal linux-3.4.32/kernel/vserver/space.c linux-3.4.32-vs2.3.3.9/kernel/vserver/space.c
22569 --- linux-3.4.32/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
22570 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/space.c       2013-02-12 00:16:04.000000000 +0000
22571 @@ -0,0 +1,436 @@
22572 +/*
22573 + *  linux/kernel/vserver/space.c
22574 + *
22575 + *  Virtual Server: Context Space Support
22576 + *
22577 + *  Copyright (C) 2003-2010  Herbert Pötzl
22578 + *
22579 + *  V0.01  broken out from context.c 0.07
22580 + *  V0.02  added task locking for namespace
22581 + *  V0.03  broken out vx_enter_namespace
22582 + *  V0.04  added *space support and commands
22583 + *  V0.05  added credential support
22584 + *
22585 + */
22586 +
22587 +#include <linux/utsname.h>
22588 +#include <linux/nsproxy.h>
22589 +#include <linux/err.h>
22590 +#include <linux/fs_struct.h>
22591 +#include <linux/cred.h>
22592 +#include <asm/uaccess.h>
22593 +
22594 +#include <linux/vs_context.h>
22595 +#include <linux/vserver/space.h>
22596 +#include <linux/vserver/space_cmd.h>
22597 +
22598 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22599 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22600 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22601 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22602 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22603 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22604 +
22605 +
22606 +/* namespace functions */
22607 +
22608 +#include <linux/mnt_namespace.h>
22609 +#include <linux/user_namespace.h>
22610 +#include <linux/pid_namespace.h>
22611 +#include <linux/ipc_namespace.h>
22612 +#include <net/net_namespace.h>
22613 +#include "../fs/mount.h"
22614 +
22615 +
22616 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22617 +       .mask = CLONE_FS |
22618 +               CLONE_NEWNS |
22619 +#ifdef CONFIG_UTS_NS
22620 +               CLONE_NEWUTS |
22621 +#endif
22622 +#ifdef CONFIG_IPC_NS
22623 +               CLONE_NEWIPC |
22624 +#endif
22625 +#ifdef CONFIG_USER_NS
22626 +               CLONE_NEWUSER |
22627 +#endif
22628 +               0
22629 +};
22630 +
22631 +static const struct vcmd_space_mask_v1 space_mask = {
22632 +       .mask = CLONE_FS |
22633 +               CLONE_NEWNS |
22634 +#ifdef CONFIG_UTS_NS
22635 +               CLONE_NEWUTS |
22636 +#endif
22637 +#ifdef CONFIG_IPC_NS
22638 +               CLONE_NEWIPC |
22639 +#endif
22640 +#ifdef CONFIG_USER_NS
22641 +               CLONE_NEWUSER |
22642 +#endif
22643 +#ifdef CONFIG_PID_NS
22644 +               CLONE_NEWPID |
22645 +#endif
22646 +#ifdef CONFIG_NET_NS
22647 +               CLONE_NEWNET |
22648 +#endif
22649 +               0
22650 +};
22651 +
22652 +static const struct vcmd_space_mask_v1 default_space_mask = {
22653 +       .mask = CLONE_FS |
22654 +               CLONE_NEWNS |
22655 +#ifdef CONFIG_UTS_NS
22656 +               CLONE_NEWUTS |
22657 +#endif
22658 +#ifdef CONFIG_IPC_NS
22659 +               CLONE_NEWIPC |
22660 +#endif
22661 +#ifdef CONFIG_USER_NS
22662 +               CLONE_NEWUSER |
22663 +#endif
22664 +#ifdef CONFIG_PID_NS
22665 +//             CLONE_NEWPID |
22666 +#endif
22667 +               0
22668 +};
22669 +
22670 +/*
22671 + *     build a new nsproxy mix
22672 + *      assumes that both proxies are 'const'
22673 + *     does not touch nsproxy refcounts
22674 + *     will hold a reference on the result.
22675 + */
22676 +
22677 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22678 +       struct nsproxy *new_nsproxy, unsigned long mask)
22679 +{
22680 +       struct mnt_namespace *old_ns;
22681 +       struct uts_namespace *old_uts;
22682 +       struct ipc_namespace *old_ipc;
22683 +#ifdef CONFIG_PID_NS
22684 +       struct pid_namespace *old_pid;
22685 +#endif
22686 +#ifdef CONFIG_NET_NS
22687 +       struct net *old_net;
22688 +#endif
22689 +       struct nsproxy *nsproxy;
22690 +
22691 +       nsproxy = copy_nsproxy(old_nsproxy);
22692 +       if (!nsproxy)
22693 +               goto out;
22694 +
22695 +       if (mask & CLONE_NEWNS) {
22696 +               old_ns = nsproxy->mnt_ns;
22697 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22698 +               if (nsproxy->mnt_ns)
22699 +                       get_mnt_ns(nsproxy->mnt_ns);
22700 +       } else
22701 +               old_ns = NULL;
22702 +
22703 +       if (mask & CLONE_NEWUTS) {
22704 +               old_uts = nsproxy->uts_ns;
22705 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22706 +               if (nsproxy->uts_ns)
22707 +                       get_uts_ns(nsproxy->uts_ns);
22708 +       } else
22709 +               old_uts = NULL;
22710 +
22711 +       if (mask & CLONE_NEWIPC) {
22712 +               old_ipc = nsproxy->ipc_ns;
22713 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22714 +               if (nsproxy->ipc_ns)
22715 +                       get_ipc_ns(nsproxy->ipc_ns);
22716 +       } else
22717 +               old_ipc = NULL;
22718 +
22719 +#ifdef CONFIG_PID_NS
22720 +       if (mask & CLONE_NEWPID) {
22721 +               old_pid = nsproxy->pid_ns;
22722 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22723 +               if (nsproxy->pid_ns)
22724 +                       get_pid_ns(nsproxy->pid_ns);
22725 +       } else
22726 +               old_pid = NULL;
22727 +#endif
22728 +#ifdef CONFIG_NET_NS
22729 +       if (mask & CLONE_NEWNET) {
22730 +               old_net = nsproxy->net_ns;
22731 +               nsproxy->net_ns = new_nsproxy->net_ns;
22732 +               if (nsproxy->net_ns)
22733 +                       get_net(nsproxy->net_ns);
22734 +       } else
22735 +               old_net = NULL;
22736 +#endif
22737 +       if (old_ns)
22738 +               put_mnt_ns(old_ns);
22739 +       if (old_uts)
22740 +               put_uts_ns(old_uts);
22741 +       if (old_ipc)
22742 +               put_ipc_ns(old_ipc);
22743 +#ifdef CONFIG_PID_NS
22744 +       if (old_pid)
22745 +               put_pid_ns(old_pid);
22746 +#endif
22747 +#ifdef CONFIG_NET_NS
22748 +       if (old_net)
22749 +               put_net(old_net);
22750 +#endif
22751 +out:
22752 +       return nsproxy;
22753 +}
22754 +
22755 +
22756 +/*
22757 + *     merge two nsproxy structs into a new one.
22758 + *     will hold a reference on the result.
22759 + */
22760 +
22761 +static inline
22762 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22763 +       struct nsproxy *proxy, unsigned long mask)
22764 +{
22765 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22766 +
22767 +       if (!proxy)
22768 +               return NULL;
22769 +
22770 +       if (mask) {
22771 +               /* vs_mix_nsproxy returns with reference */
22772 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22773 +                       proxy, mask);
22774 +       }
22775 +       get_nsproxy(proxy);
22776 +       return proxy;
22777 +}
22778 +
22779 +
22780 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22781 +{
22782 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22783 +       struct fs_struct *fs_cur, *fs = NULL;
22784 +       struct _vx_space *space;
22785 +       int ret, kill = 0;
22786 +
22787 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22788 +               vxi, vxi->vx_id, mask, index);
22789 +
22790 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22791 +               return -EACCES;
22792 +
22793 +       if (index >= VX_SPACES)
22794 +               return -EINVAL;
22795 +
22796 +       space = &vxi->space[index];
22797 +
22798 +       if (!mask)
22799 +               mask = space->vx_nsmask;
22800 +
22801 +       if ((mask & space->vx_nsmask) != mask)
22802 +               return -EINVAL;
22803 +
22804 +       if (mask & CLONE_FS) {
22805 +               fs = copy_fs_struct(space->vx_fs);
22806 +               if (!fs)
22807 +                       return -ENOMEM;
22808 +       }
22809 +       proxy = space->vx_nsproxy;
22810 +
22811 +       vxdprintk(VXD_CBIT(space, 9),
22812 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22813 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22814 +
22815 +       task_lock(current);
22816 +       fs_cur = current->fs;
22817 +
22818 +       if (mask & CLONE_FS) {
22819 +               spin_lock(&fs_cur->lock);
22820 +               current->fs = fs;
22821 +               kill = !--fs_cur->users;
22822 +               spin_unlock(&fs_cur->lock);
22823 +       }
22824 +
22825 +       proxy_cur = current->nsproxy;
22826 +       get_nsproxy(proxy_cur);
22827 +       task_unlock(current);
22828 +
22829 +       if (kill)
22830 +               free_fs_struct(fs_cur);
22831 +
22832 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22833 +       if (IS_ERR(proxy_new)) {
22834 +               ret = PTR_ERR(proxy_new);
22835 +               goto out_put;
22836 +       }
22837 +
22838 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22839 +
22840 +       if (mask & CLONE_NEWUSER) {
22841 +               struct cred *cred;
22842 +
22843 +               vxdprintk(VXD_CBIT(space, 10),
22844 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22845 +                       vxi, vxi->vx_id, space->vx_cred,
22846 +                       current->real_cred, current->cred);
22847 +
22848 +               if (space->vx_cred) {
22849 +                       cred = __prepare_creds(space->vx_cred);
22850 +                       if (cred)
22851 +                               commit_creds(cred);
22852 +               }
22853 +       }
22854 +
22855 +       ret = 0;
22856 +
22857 +       if (proxy_new)
22858 +               put_nsproxy(proxy_new);
22859 +out_put:
22860 +       if (proxy_cur)
22861 +               put_nsproxy(proxy_cur);
22862 +       return ret;
22863 +}
22864 +
22865 +
22866 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22867 +{
22868 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22869 +       struct fs_struct *fs_vxi, *fs = NULL;
22870 +       struct _vx_space *space;
22871 +       int ret, kill = 0;
22872 +
22873 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22874 +               vxi, vxi->vx_id, mask, index);
22875 +
22876 +       if ((mask & space_mask.mask) != mask)
22877 +               return -EINVAL;
22878 +
22879 +       if (index >= VX_SPACES)
22880 +               return -EINVAL;
22881 +
22882 +       space = &vxi->space[index];
22883 +
22884 +       proxy_vxi = space->vx_nsproxy;
22885 +       fs_vxi = space->vx_fs;
22886 +
22887 +       if (mask & CLONE_FS) {
22888 +               fs = copy_fs_struct(current->fs);
22889 +               if (!fs)
22890 +                       return -ENOMEM;
22891 +       }
22892 +
22893 +       task_lock(current);
22894 +
22895 +       if (mask & CLONE_FS) {
22896 +               spin_lock(&fs_vxi->lock);
22897 +               space->vx_fs = fs;
22898 +               kill = !--fs_vxi->users;
22899 +               spin_unlock(&fs_vxi->lock);
22900 +       }
22901 +
22902 +       proxy_cur = current->nsproxy;
22903 +       get_nsproxy(proxy_cur);
22904 +       task_unlock(current);
22905 +
22906 +       if (kill)
22907 +               free_fs_struct(fs_vxi);
22908 +
22909 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22910 +       if (IS_ERR(proxy_new)) {
22911 +               ret = PTR_ERR(proxy_new);
22912 +               goto out_put;
22913 +       }
22914 +
22915 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22916 +       space->vx_nsmask |= mask;
22917 +
22918 +       if (mask & CLONE_NEWUSER) {
22919 +               struct cred *cred;
22920 +
22921 +               vxdprintk(VXD_CBIT(space, 10),
22922 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22923 +                       vxi, vxi->vx_id, space->vx_cred,
22924 +                       current->real_cred, current->cred);
22925 +
22926 +               cred = prepare_creds();
22927 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22928 +               if (cred)
22929 +                       abort_creds(cred);
22930 +       }
22931 +
22932 +       ret = 0;
22933 +
22934 +       if (proxy_new)
22935 +               put_nsproxy(proxy_new);
22936 +out_put:
22937 +       if (proxy_cur)
22938 +               put_nsproxy(proxy_cur);
22939 +       return ret;
22940 +}
22941 +
22942 +
22943 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22944 +{
22945 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22946 +
22947 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22948 +               return -EFAULT;
22949 +
22950 +       return vx_enter_space(vxi, vc_data.mask, 0);
22951 +}
22952 +
22953 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22954 +{
22955 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22956 +
22957 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22958 +               return -EFAULT;
22959 +
22960 +       if (vc_data.index >= VX_SPACES)
22961 +               return -EINVAL;
22962 +
22963 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22964 +}
22965 +
22966 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22967 +{
22968 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22969 +
22970 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22971 +               return -EFAULT;
22972 +
22973 +       return vx_set_space(vxi, vc_data.mask, 0);
22974 +}
22975 +
22976 +int vc_set_space(struct vx_info *vxi, void __user *data)
22977 +{
22978 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22979 +
22980 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22981 +               return -EFAULT;
22982 +
22983 +       if (vc_data.index >= VX_SPACES)
22984 +               return -EINVAL;
22985 +
22986 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22987 +}
22988 +
22989 +int vc_get_space_mask(void __user *data, int type)
22990 +{
22991 +       const struct vcmd_space_mask_v1 *mask;
22992 +
22993 +       if (type == 0)
22994 +               mask = &space_mask_v0;
22995 +       else if (type == 1)
22996 +               mask = &space_mask;
22997 +       else
22998 +               mask = &default_space_mask;
22999 +
23000 +       vxdprintk(VXD_CBIT(space, 10),
23001 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23002 +
23003 +       if (copy_to_user(data, mask, sizeof(*mask)))
23004 +               return -EFAULT;
23005 +       return 0;
23006 +}
23007 +
23008 diff -NurpP --minimal linux-3.4.32/kernel/vserver/switch.c linux-3.4.32-vs2.3.3.9/kernel/vserver/switch.c
23009 --- linux-3.4.32/kernel/vserver/switch.c        1970-01-01 00:00:00.000000000 +0000
23010 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/switch.c      2012-05-21 16:15:05.000000000 +0000
23011 @@ -0,0 +1,556 @@
23012 +/*
23013 + *  linux/kernel/vserver/switch.c
23014 + *
23015 + *  Virtual Server: Syscall Switch
23016 + *
23017 + *  Copyright (C) 2003-2011  Herbert Pötzl
23018 + *
23019 + *  V0.01  syscall switch
23020 + *  V0.02  added signal to context
23021 + *  V0.03  added rlimit functions
23022 + *  V0.04  added iattr, task/xid functions
23023 + *  V0.05  added debug/history stuff
23024 + *  V0.06  added compat32 layer
23025 + *  V0.07  vcmd args and perms
23026 + *  V0.08  added status commands
23027 + *  V0.09  added tag commands
23028 + *  V0.10  added oom bias
23029 + *  V0.11  added device commands
23030 + *  V0.12  added warn mask
23031 + *
23032 + */
23033 +
23034 +#include <linux/vs_context.h>
23035 +#include <linux/vs_network.h>
23036 +#include <linux/vserver/switch.h>
23037 +
23038 +#include "vci_config.h"
23039 +
23040 +
23041 +static inline
23042 +int vc_get_version(uint32_t id)
23043 +{
23044 +       return VCI_VERSION;
23045 +}
23046 +
23047 +static inline
23048 +int vc_get_vci(uint32_t id)
23049 +{
23050 +       return vci_kernel_config();
23051 +}
23052 +
23053 +#include <linux/vserver/context_cmd.h>
23054 +#include <linux/vserver/cvirt_cmd.h>
23055 +#include <linux/vserver/cacct_cmd.h>
23056 +#include <linux/vserver/limit_cmd.h>
23057 +#include <linux/vserver/network_cmd.h>
23058 +#include <linux/vserver/sched_cmd.h>
23059 +#include <linux/vserver/debug_cmd.h>
23060 +#include <linux/vserver/inode_cmd.h>
23061 +#include <linux/vserver/dlimit_cmd.h>
23062 +#include <linux/vserver/signal_cmd.h>
23063 +#include <linux/vserver/space_cmd.h>
23064 +#include <linux/vserver/tag_cmd.h>
23065 +#include <linux/vserver/device_cmd.h>
23066 +
23067 +#include <linux/vserver/inode.h>
23068 +#include <linux/vserver/dlimit.h>
23069 +
23070 +
23071 +#ifdef CONFIG_COMPAT
23072 +#define __COMPAT(name, id, data, compat)       \
23073 +       (compat) ? name ## _x32(id, data) : name(id, data)
23074 +#define __COMPAT_NO_ID(name, data, compat)     \
23075 +       (compat) ? name ## _x32(data) : name(data)
23076 +#else
23077 +#define __COMPAT(name, id, data, compat)       \
23078 +       name(id, data)
23079 +#define __COMPAT_NO_ID(name, data, compat)     \
23080 +       name(data)
23081 +#endif
23082 +
23083 +
23084 +static inline
23085 +long do_vcmd(uint32_t cmd, uint32_t id,
23086 +       struct vx_info *vxi, struct nx_info *nxi,
23087 +       void __user *data, int compat)
23088 +{
23089 +       switch (cmd) {
23090 +
23091 +       case VCMD_get_version:
23092 +               return vc_get_version(id);
23093 +       case VCMD_get_vci:
23094 +               return vc_get_vci(id);
23095 +
23096 +       case VCMD_task_xid:
23097 +               return vc_task_xid(id);
23098 +       case VCMD_vx_info:
23099 +               return vc_vx_info(vxi, data);
23100 +
23101 +       case VCMD_task_nid:
23102 +               return vc_task_nid(id);
23103 +       case VCMD_nx_info:
23104 +               return vc_nx_info(nxi, data);
23105 +
23106 +       case VCMD_task_tag:
23107 +               return vc_task_tag(id);
23108 +
23109 +       case VCMD_set_space_v1:
23110 +               return vc_set_space_v1(vxi, data);
23111 +       /* this is version 2 */
23112 +       case VCMD_set_space:
23113 +               return vc_set_space(vxi, data);
23114 +
23115 +       case VCMD_get_space_mask_v0:
23116 +               return vc_get_space_mask(data, 0);
23117 +       /* this is version 1 */
23118 +       case VCMD_get_space_mask:
23119 +               return vc_get_space_mask(data, 1);
23120 +
23121 +       case VCMD_get_space_default:
23122 +               return vc_get_space_mask(data, -1);
23123 +
23124 +       case VCMD_set_umask:
23125 +               return vc_set_umask(vxi, data);
23126 +
23127 +       case VCMD_get_umask:
23128 +               return vc_get_umask(vxi, data);
23129 +
23130 +       case VCMD_set_wmask:
23131 +               return vc_set_wmask(vxi, data);
23132 +
23133 +       case VCMD_get_wmask:
23134 +               return vc_get_wmask(vxi, data);
23135 +#ifdef CONFIG_IA32_EMULATION
23136 +       case VCMD_get_rlimit:
23137 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23138 +       case VCMD_set_rlimit:
23139 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23140 +#else
23141 +       case VCMD_get_rlimit:
23142 +               return vc_get_rlimit(vxi, data);
23143 +       case VCMD_set_rlimit:
23144 +               return vc_set_rlimit(vxi, data);
23145 +#endif
23146 +       case VCMD_get_rlimit_mask:
23147 +               return vc_get_rlimit_mask(id, data);
23148 +       case VCMD_reset_hits:
23149 +               return vc_reset_hits(vxi, data);
23150 +       case VCMD_reset_minmax:
23151 +               return vc_reset_minmax(vxi, data);
23152 +
23153 +       case VCMD_get_vhi_name:
23154 +               return vc_get_vhi_name(vxi, data);
23155 +       case VCMD_set_vhi_name:
23156 +               return vc_set_vhi_name(vxi, data);
23157 +
23158 +       case VCMD_ctx_stat:
23159 +               return vc_ctx_stat(vxi, data);
23160 +       case VCMD_virt_stat:
23161 +               return vc_virt_stat(vxi, data);
23162 +       case VCMD_sock_stat:
23163 +               return vc_sock_stat(vxi, data);
23164 +       case VCMD_rlimit_stat:
23165 +               return vc_rlimit_stat(vxi, data);
23166 +
23167 +       case VCMD_set_cflags:
23168 +               return vc_set_cflags(vxi, data);
23169 +       case VCMD_get_cflags:
23170 +               return vc_get_cflags(vxi, data);
23171 +
23172 +       /* this is version 1 */
23173 +       case VCMD_set_ccaps:
23174 +               return vc_set_ccaps(vxi, data);
23175 +       /* this is version 1 */
23176 +       case VCMD_get_ccaps:
23177 +               return vc_get_ccaps(vxi, data);
23178 +       case VCMD_set_bcaps:
23179 +               return vc_set_bcaps(vxi, data);
23180 +       case VCMD_get_bcaps:
23181 +               return vc_get_bcaps(vxi, data);
23182 +
23183 +       case VCMD_set_badness:
23184 +               return vc_set_badness(vxi, data);
23185 +       case VCMD_get_badness:
23186 +               return vc_get_badness(vxi, data);
23187 +
23188 +       case VCMD_set_nflags:
23189 +               return vc_set_nflags(nxi, data);
23190 +       case VCMD_get_nflags:
23191 +               return vc_get_nflags(nxi, data);
23192 +
23193 +       case VCMD_set_ncaps:
23194 +               return vc_set_ncaps(nxi, data);
23195 +       case VCMD_get_ncaps:
23196 +               return vc_get_ncaps(nxi, data);
23197 +
23198 +       case VCMD_set_prio_bias:
23199 +               return vc_set_prio_bias(vxi, data);
23200 +       case VCMD_get_prio_bias:
23201 +               return vc_get_prio_bias(vxi, data);
23202 +       case VCMD_add_dlimit:
23203 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23204 +       case VCMD_rem_dlimit:
23205 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23206 +       case VCMD_set_dlimit:
23207 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23208 +       case VCMD_get_dlimit:
23209 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23210 +
23211 +       case VCMD_ctx_kill:
23212 +               return vc_ctx_kill(vxi, data);
23213 +
23214 +       case VCMD_wait_exit:
23215 +               return vc_wait_exit(vxi, data);
23216 +
23217 +       case VCMD_get_iattr:
23218 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23219 +       case VCMD_set_iattr:
23220 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23221 +
23222 +       case VCMD_fget_iattr:
23223 +               return vc_fget_iattr(id, data);
23224 +       case VCMD_fset_iattr:
23225 +               return vc_fset_iattr(id, data);
23226 +
23227 +       case VCMD_enter_space_v0:
23228 +               return vc_enter_space_v1(vxi, NULL);
23229 +       case VCMD_enter_space_v1:
23230 +               return vc_enter_space_v1(vxi, data);
23231 +       /* this is version 2 */
23232 +       case VCMD_enter_space:
23233 +               return vc_enter_space(vxi, data);
23234 +
23235 +       case VCMD_ctx_create_v0:
23236 +               return vc_ctx_create(id, NULL);
23237 +       case VCMD_ctx_create:
23238 +               return vc_ctx_create(id, data);
23239 +       case VCMD_ctx_migrate_v0:
23240 +               return vc_ctx_migrate(vxi, NULL);
23241 +       case VCMD_ctx_migrate:
23242 +               return vc_ctx_migrate(vxi, data);
23243 +
23244 +       case VCMD_net_create_v0:
23245 +               return vc_net_create(id, NULL);
23246 +       case VCMD_net_create:
23247 +               return vc_net_create(id, data);
23248 +       case VCMD_net_migrate:
23249 +               return vc_net_migrate(nxi, data);
23250 +
23251 +       case VCMD_tag_migrate:
23252 +               return vc_tag_migrate(id);
23253 +
23254 +       case VCMD_net_add:
23255 +               return vc_net_add(nxi, data);
23256 +       case VCMD_net_remove:
23257 +               return vc_net_remove(nxi, data);
23258 +
23259 +       case VCMD_net_add_ipv4_v1:
23260 +               return vc_net_add_ipv4_v1(nxi, data);
23261 +       /* this is version 2 */
23262 +       case VCMD_net_add_ipv4:
23263 +               return vc_net_add_ipv4(nxi, data);
23264 +
23265 +       case VCMD_net_rem_ipv4_v1:
23266 +               return vc_net_rem_ipv4_v1(nxi, data);
23267 +       /* this is version 2 */
23268 +       case VCMD_net_rem_ipv4:
23269 +               return vc_net_rem_ipv4(nxi, data);
23270 +#ifdef CONFIG_IPV6
23271 +       case VCMD_net_add_ipv6:
23272 +               return vc_net_add_ipv6(nxi, data);
23273 +       case VCMD_net_remove_ipv6:
23274 +               return vc_net_remove_ipv6(nxi, data);
23275 +#endif
23276 +/*     case VCMD_add_match_ipv4:
23277 +               return vc_add_match_ipv4(nxi, data);
23278 +       case VCMD_get_match_ipv4:
23279 +               return vc_get_match_ipv4(nxi, data);
23280 +#ifdef CONFIG_IPV6
23281 +       case VCMD_add_match_ipv6:
23282 +               return vc_add_match_ipv6(nxi, data);
23283 +       case VCMD_get_match_ipv6:
23284 +               return vc_get_match_ipv6(nxi, data);
23285 +#endif */
23286 +
23287 +#ifdef CONFIG_VSERVER_DEVICE
23288 +       case VCMD_set_mapping:
23289 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23290 +       case VCMD_unset_mapping:
23291 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23292 +#endif
23293 +#ifdef CONFIG_VSERVER_HISTORY
23294 +       case VCMD_dump_history:
23295 +               return vc_dump_history(id);
23296 +       case VCMD_read_history:
23297 +               return __COMPAT(vc_read_history, id, data, compat);
23298 +#endif
23299 +       default:
23300 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23301 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23302 +       }
23303 +       return -ENOSYS;
23304 +}
23305 +
23306 +
23307 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23308 +       case VCMD_ ## vcmd: perm = _perm;               \
23309 +               args = _args; flags = _flags; break
23310 +
23311 +
23312 +#define VCA_NONE       0x00
23313 +#define VCA_VXI                0x01
23314 +#define VCA_NXI                0x02
23315 +
23316 +#define VCF_NONE       0x00
23317 +#define VCF_INFO       0x01
23318 +#define VCF_ADMIN      0x02
23319 +#define VCF_ARES       0x06    /* includes admin */
23320 +#define VCF_SETUP      0x08
23321 +
23322 +#define VCF_ZIDOK      0x10    /* zero id okay */
23323 +
23324 +
23325 +static inline
23326 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23327 +{
23328 +       long ret;
23329 +       int permit = -1, state = 0;
23330 +       int perm = -1, args = 0, flags = 0;
23331 +       struct vx_info *vxi = NULL;
23332 +       struct nx_info *nxi = NULL;
23333 +
23334 +       switch (cmd) {
23335 +       /* unpriviledged commands */
23336 +       __VCMD(get_version,      0, VCA_NONE,   0);
23337 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23338 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23339 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23340 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23341 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23342 +
23343 +       /* info commands */
23344 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23345 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23346 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23347 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23348 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23349 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23350 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23351 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23352 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23353 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23354 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23355 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23356 +
23357 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23358 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23359 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23360 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23361 +
23362 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23363 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23364 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23365 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23366 +
23367 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23368 +
23369 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23370 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23371 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23372 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23373 +
23374 +       /* lower admin commands */
23375 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23376 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23377 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23378 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23379 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23380 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23381 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23382 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23383 +
23384 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23385 +       __VCMD(net_create,       5, VCA_NONE,   0);
23386 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23387 +
23388 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23389 +
23390 +       /* higher admin commands */
23391 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23392 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23393 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23394 +
23395 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23396 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23397 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23398 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23399 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23400 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23401 +
23402 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23403 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23404 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23405 +
23406 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23407 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23408 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23409 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23410 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23411 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23412 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23413 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23414 +#ifdef CONFIG_IPV6
23415 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23416 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23417 +#endif
23418 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23419 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23420 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23421 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23422 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23423 +
23424 +#ifdef CONFIG_VSERVER_DEVICE
23425 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23426 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23427 +#endif
23428 +       /* debug level admin commands */
23429 +#ifdef CONFIG_VSERVER_HISTORY
23430 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23431 +       __VCMD(read_history,     9, VCA_NONE,   0);
23432 +#endif
23433 +
23434 +       default:
23435 +               perm = -1;
23436 +       }
23437 +
23438 +       vxdprintk(VXD_CBIT(switch, 0),
23439 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23440 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23441 +               VC_VERSION(cmd), id, data, compat,
23442 +               perm, args, flags);
23443 +
23444 +       ret = -ENOSYS;
23445 +       if (perm < 0)
23446 +               goto out;
23447 +
23448 +       state = 1;
23449 +       if (!capable(CAP_CONTEXT))
23450 +               goto out;
23451 +
23452 +       state = 2;
23453 +       /* moved here from the individual commands */
23454 +       ret = -EPERM;
23455 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23456 +               goto out;
23457 +
23458 +       state = 3;
23459 +       /* vcmd involves resource management  */
23460 +       ret = -EPERM;
23461 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23462 +               goto out;
23463 +
23464 +       state = 4;
23465 +       /* various legacy exceptions */
23466 +       switch (cmd) {
23467 +       /* will go away when spectator is a cap */
23468 +       case VCMD_ctx_migrate_v0:
23469 +       case VCMD_ctx_migrate:
23470 +               if (id == 1) {
23471 +                       current->xid = 1;
23472 +                       ret = 1;
23473 +                       goto out;
23474 +               }
23475 +               break;
23476 +
23477 +       /* will go away when spectator is a cap */
23478 +       case VCMD_net_migrate:
23479 +               if (id == 1) {
23480 +                       current->nid = 1;
23481 +                       ret = 1;
23482 +                       goto out;
23483 +               }
23484 +               break;
23485 +       }
23486 +
23487 +       /* vcmds are fine by default */
23488 +       permit = 1;
23489 +
23490 +       /* admin type vcmds require admin ... */
23491 +       if (flags & VCF_ADMIN)
23492 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23493 +
23494 +       /* ... but setup type vcmds override that */
23495 +       if (!permit && (flags & VCF_SETUP))
23496 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23497 +
23498 +       state = 5;
23499 +       ret = -EPERM;
23500 +       if (!permit)
23501 +               goto out;
23502 +
23503 +       state = 6;
23504 +       if (!id && (flags & VCF_ZIDOK))
23505 +               goto skip_id;
23506 +
23507 +       ret = -ESRCH;
23508 +       if (args & VCA_VXI) {
23509 +               vxi = lookup_vx_info(id);
23510 +               if (!vxi)
23511 +                       goto out;
23512 +
23513 +               if ((flags & VCF_ADMIN) &&
23514 +                       /* special case kill for shutdown */
23515 +                       (cmd != VCMD_ctx_kill) &&
23516 +                       /* can context be administrated? */
23517 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23518 +                       ret = -EACCES;
23519 +                       goto out_vxi;
23520 +               }
23521 +       }
23522 +       state = 7;
23523 +       if (args & VCA_NXI) {
23524 +               nxi = lookup_nx_info(id);
23525 +               if (!nxi)
23526 +                       goto out_vxi;
23527 +
23528 +               if ((flags & VCF_ADMIN) &&
23529 +                       /* can context be administrated? */
23530 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23531 +                       ret = -EACCES;
23532 +                       goto out_nxi;
23533 +               }
23534 +       }
23535 +skip_id:
23536 +       state = 8;
23537 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23538 +
23539 +out_nxi:
23540 +       if ((args & VCA_NXI) && nxi)
23541 +               put_nx_info(nxi);
23542 +out_vxi:
23543 +       if ((args & VCA_VXI) && vxi)
23544 +               put_vx_info(vxi);
23545 +out:
23546 +       vxdprintk(VXD_CBIT(switch, 1),
23547 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23548 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23549 +               VC_VERSION(cmd), ret, ret, state, permit);
23550 +       return ret;
23551 +}
23552 +
23553 +asmlinkage long
23554 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23555 +{
23556 +       return do_vserver(cmd, id, data, 0);
23557 +}
23558 +
23559 +#ifdef CONFIG_COMPAT
23560 +
23561 +asmlinkage long
23562 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23563 +{
23564 +       return do_vserver(cmd, id, data, 1);
23565 +}
23566 +
23567 +#endif /* CONFIG_COMPAT */
23568 diff -NurpP --minimal linux-3.4.32/kernel/vserver/sysctl.c linux-3.4.32-vs2.3.3.9/kernel/vserver/sysctl.c
23569 --- linux-3.4.32/kernel/vserver/sysctl.c        1970-01-01 00:00:00.000000000 +0000
23570 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/sysctl.c      2012-05-21 16:15:05.000000000 +0000
23571 @@ -0,0 +1,247 @@
23572 +/*
23573 + *  kernel/vserver/sysctl.c
23574 + *
23575 + *  Virtual Context Support
23576 + *
23577 + *  Copyright (C) 2004-2007  Herbert Pötzl
23578 + *
23579 + *  V0.01  basic structure
23580 + *
23581 + */
23582 +
23583 +#include <linux/module.h>
23584 +#include <linux/ctype.h>
23585 +#include <linux/sysctl.h>
23586 +#include <linux/parser.h>
23587 +#include <asm/uaccess.h>
23588 +
23589 +enum {
23590 +       CTL_DEBUG_ERROR         = 0,
23591 +       CTL_DEBUG_SWITCH        = 1,
23592 +       CTL_DEBUG_XID,
23593 +       CTL_DEBUG_NID,
23594 +       CTL_DEBUG_TAG,
23595 +       CTL_DEBUG_NET,
23596 +       CTL_DEBUG_LIMIT,
23597 +       CTL_DEBUG_CRES,
23598 +       CTL_DEBUG_DLIM,
23599 +       CTL_DEBUG_QUOTA,
23600 +       CTL_DEBUG_CVIRT,
23601 +       CTL_DEBUG_SPACE,
23602 +       CTL_DEBUG_PERM,
23603 +       CTL_DEBUG_MISC,
23604 +};
23605 +
23606 +
23607 +unsigned int vs_debug_switch   = 0;
23608 +unsigned int vs_debug_xid      = 0;
23609 +unsigned int vs_debug_nid      = 0;
23610 +unsigned int vs_debug_tag      = 0;
23611 +unsigned int vs_debug_net      = 0;
23612 +unsigned int vs_debug_limit    = 0;
23613 +unsigned int vs_debug_cres     = 0;
23614 +unsigned int vs_debug_dlim     = 0;
23615 +unsigned int vs_debug_quota    = 0;
23616 +unsigned int vs_debug_cvirt    = 0;
23617 +unsigned int vs_debug_space    = 0;
23618 +unsigned int vs_debug_perm     = 0;
23619 +unsigned int vs_debug_misc     = 0;
23620 +
23621 +
23622 +static struct ctl_table_header *vserver_table_header;
23623 +static ctl_table vserver_root_table[];
23624 +
23625 +
23626 +void vserver_register_sysctl(void)
23627 +{
23628 +       if (!vserver_table_header) {
23629 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23630 +       }
23631 +
23632 +}
23633 +
23634 +void vserver_unregister_sysctl(void)
23635 +{
23636 +       if (vserver_table_header) {
23637 +               unregister_sysctl_table(vserver_table_header);
23638 +               vserver_table_header = NULL;
23639 +       }
23640 +}
23641 +
23642 +
23643 +static int proc_dodebug(ctl_table *table, int write,
23644 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23645 +{
23646 +       char            tmpbuf[20], *p, c;
23647 +       unsigned int    value;
23648 +       size_t          left, len;
23649 +
23650 +       if ((*ppos && !write) || !*lenp) {
23651 +               *lenp = 0;
23652 +               return 0;
23653 +       }
23654 +
23655 +       left = *lenp;
23656 +
23657 +       if (write) {
23658 +               if (!access_ok(VERIFY_READ, buffer, left))
23659 +                       return -EFAULT;
23660 +               p = (char *)buffer;
23661 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23662 +                       left--, p++;
23663 +               if (!left)
23664 +                       goto done;
23665 +
23666 +               if (left > sizeof(tmpbuf) - 1)
23667 +                       return -EINVAL;
23668 +               if (copy_from_user(tmpbuf, p, left))
23669 +                       return -EFAULT;
23670 +               tmpbuf[left] = '\0';
23671 +
23672 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23673 +                       value = 10 * value + (*p - '0');
23674 +               if (*p && !isspace(*p))
23675 +                       return -EINVAL;
23676 +               while (left && isspace(*p))
23677 +                       left--, p++;
23678 +               *(unsigned int *)table->data = value;
23679 +       } else {
23680 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23681 +                       return -EFAULT;
23682 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23683 +               if (len > left)
23684 +                       len = left;
23685 +               if (__copy_to_user(buffer, tmpbuf, len))
23686 +                       return -EFAULT;
23687 +               if ((left -= len) > 0) {
23688 +                       if (put_user('\n', (char *)buffer + len))
23689 +                               return -EFAULT;
23690 +                       left--;
23691 +               }
23692 +       }
23693 +
23694 +done:
23695 +       *lenp -= left;
23696 +       *ppos += *lenp;
23697 +       return 0;
23698 +}
23699 +
23700 +static int zero;
23701 +
23702 +#define        CTL_ENTRY(ctl, name)                            \
23703 +       {                                               \
23704 +               .procname       = #name,                \
23705 +               .data           = &vs_ ## name,         \
23706 +               .maxlen         = sizeof(int),          \
23707 +               .mode           = 0644,                 \
23708 +               .proc_handler   = &proc_dodebug,        \
23709 +               .extra1         = &zero,                \
23710 +               .extra2         = &zero,                \
23711 +       }
23712 +
23713 +static ctl_table vserver_debug_table[] = {
23714 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23715 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23716 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23717 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23718 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23719 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23720 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23721 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23722 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23723 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23724 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23725 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23726 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23727 +       { 0 }
23728 +};
23729 +
23730 +static ctl_table vserver_root_table[] = {
23731 +       {
23732 +               .procname       = "vserver",
23733 +               .mode           = 0555,
23734 +               .child          = vserver_debug_table
23735 +       },
23736 +       { 0 }
23737 +};
23738 +
23739 +
23740 +static match_table_t tokens = {
23741 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23742 +       { CTL_DEBUG_XID,        "xid=%x"        },
23743 +       { CTL_DEBUG_NID,        "nid=%x"        },
23744 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23745 +       { CTL_DEBUG_NET,        "net=%x"        },
23746 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23747 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23748 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23749 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23750 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23751 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23752 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23753 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23754 +       { CTL_DEBUG_ERROR,      NULL            }
23755 +};
23756 +
23757 +#define        HANDLE_CASE(id, name, val)                              \
23758 +       case CTL_DEBUG_ ## id:                                  \
23759 +               vs_debug_ ## name = val;                        \
23760 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23761 +               break
23762 +
23763 +
23764 +static int __init vs_debug_setup(char *str)
23765 +{
23766 +       char *p;
23767 +       int token;
23768 +
23769 +       printk("vs_debug_setup(%s)\n", str);
23770 +       while ((p = strsep(&str, ",")) != NULL) {
23771 +               substring_t args[MAX_OPT_ARGS];
23772 +               unsigned int value;
23773 +
23774 +               if (!*p)
23775 +                       continue;
23776 +
23777 +               token = match_token(p, tokens, args);
23778 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23779 +
23780 +               switch (token) {
23781 +               HANDLE_CASE(SWITCH, switch, value);
23782 +               HANDLE_CASE(XID,    xid,    value);
23783 +               HANDLE_CASE(NID,    nid,    value);
23784 +               HANDLE_CASE(TAG,    tag,    value);
23785 +               HANDLE_CASE(NET,    net,    value);
23786 +               HANDLE_CASE(LIMIT,  limit,  value);
23787 +               HANDLE_CASE(CRES,   cres,   value);
23788 +               HANDLE_CASE(DLIM,   dlim,   value);
23789 +               HANDLE_CASE(QUOTA,  quota,  value);
23790 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23791 +               HANDLE_CASE(SPACE,  space,  value);
23792 +               HANDLE_CASE(PERM,   perm,   value);
23793 +               HANDLE_CASE(MISC,   misc,   value);
23794 +               default:
23795 +                       return -EINVAL;
23796 +                       break;
23797 +               }
23798 +       }
23799 +       return 1;
23800 +}
23801 +
23802 +__setup("vsdebug=", vs_debug_setup);
23803 +
23804 +
23805 +
23806 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23807 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23808 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23809 +EXPORT_SYMBOL_GPL(vs_debug_net);
23810 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23811 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23812 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23813 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23814 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23815 +EXPORT_SYMBOL_GPL(vs_debug_space);
23816 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23817 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23818 +
23819 diff -NurpP --minimal linux-3.4.32/kernel/vserver/tag.c linux-3.4.32-vs2.3.3.9/kernel/vserver/tag.c
23820 --- linux-3.4.32/kernel/vserver/tag.c   1970-01-01 00:00:00.000000000 +0000
23821 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/tag.c 2012-05-21 16:15:05.000000000 +0000
23822 @@ -0,0 +1,63 @@
23823 +/*
23824 + *  linux/kernel/vserver/tag.c
23825 + *
23826 + *  Virtual Server: Shallow Tag Space
23827 + *
23828 + *  Copyright (C) 2007  Herbert Pötzl
23829 + *
23830 + *  V0.01  basic implementation
23831 + *
23832 + */
23833 +
23834 +#include <linux/sched.h>
23835 +#include <linux/vserver/debug.h>
23836 +#include <linux/vs_pid.h>
23837 +#include <linux/vs_tag.h>
23838 +
23839 +#include <linux/vserver/tag_cmd.h>
23840 +
23841 +
23842 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23843 +{
23844 +       if (!p)
23845 +               BUG();
23846 +
23847 +       vxdprintk(VXD_CBIT(tag, 5),
23848 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23849 +
23850 +       task_lock(p);
23851 +       p->tag = tag;
23852 +       task_unlock(p);
23853 +
23854 +       vxdprintk(VXD_CBIT(tag, 5),
23855 +               "moved task %p into [#%d]", p, tag);
23856 +       return 0;
23857 +}
23858 +
23859 +/* vserver syscall commands below here */
23860 +
23861 +/* taks xid and vx_info functions */
23862 +
23863 +
23864 +int vc_task_tag(uint32_t id)
23865 +{
23866 +       tag_t tag;
23867 +
23868 +       if (id) {
23869 +               struct task_struct *tsk;
23870 +               rcu_read_lock();
23871 +               tsk = find_task_by_real_pid(id);
23872 +               tag = (tsk) ? tsk->tag : -ESRCH;
23873 +               rcu_read_unlock();
23874 +       } else
23875 +               tag = dx_current_tag();
23876 +       return tag;
23877 +}
23878 +
23879 +
23880 +int vc_tag_migrate(uint32_t tag)
23881 +{
23882 +       return dx_migrate_task(current, tag & 0xFFFF);
23883 +}
23884 +
23885 +
23886 diff -NurpP --minimal linux-3.4.32/kernel/vserver/vci_config.h linux-3.4.32-vs2.3.3.9/kernel/vserver/vci_config.h
23887 --- linux-3.4.32/kernel/vserver/vci_config.h    1970-01-01 00:00:00.000000000 +0000
23888 +++ linux-3.4.32-vs2.3.3.9/kernel/vserver/vci_config.h  2012-05-21 16:15:05.000000000 +0000
23889 @@ -0,0 +1,76 @@
23890 +
23891 +/*  interface version */
23892 +
23893 +#define VCI_VERSION            0x00020308
23894 +
23895 +
23896 +enum {
23897 +       VCI_KCBIT_NO_DYNAMIC = 0,
23898 +
23899 +       VCI_KCBIT_PROC_SECURE = 4,
23900 +       /* VCI_KCBIT_HARDCPU = 5, */
23901 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23902 +       /* VCI_KCBIT_IDLETIME = 7, */
23903 +
23904 +       VCI_KCBIT_COWBL = 8,
23905 +       VCI_KCBIT_FULLCOWBL = 9,
23906 +       VCI_KCBIT_SPACES = 10,
23907 +       VCI_KCBIT_NETV2 = 11,
23908 +       VCI_KCBIT_MEMCG = 12,
23909 +
23910 +       VCI_KCBIT_DEBUG = 16,
23911 +       VCI_KCBIT_HISTORY = 20,
23912 +       VCI_KCBIT_TAGGED = 24,
23913 +       VCI_KCBIT_PPTAG = 28,
23914 +
23915 +       VCI_KCBIT_MORE = 31,
23916 +};
23917 +
23918 +
23919 +static inline uint32_t vci_kernel_config(void)
23920 +{
23921 +       return
23922 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23923 +
23924 +       /* configured features */
23925 +#ifdef CONFIG_VSERVER_PROC_SECURE
23926 +       (1 << VCI_KCBIT_PROC_SECURE) |
23927 +#endif
23928 +#ifdef CONFIG_VSERVER_COWBL
23929 +       (1 << VCI_KCBIT_COWBL) |
23930 +       (1 << VCI_KCBIT_FULLCOWBL) |
23931 +#endif
23932 +       (1 << VCI_KCBIT_SPACES) |
23933 +       (1 << VCI_KCBIT_NETV2) |
23934 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23935 +       (1 << VCI_KCBIT_MEMCG) |
23936 +#endif
23937 +
23938 +       /* debug options */
23939 +#ifdef CONFIG_VSERVER_DEBUG
23940 +       (1 << VCI_KCBIT_DEBUG) |
23941 +#endif
23942 +#ifdef CONFIG_VSERVER_HISTORY
23943 +       (1 << VCI_KCBIT_HISTORY) |
23944 +#endif
23945 +
23946 +       /* inode context tagging */
23947 +#if    defined(CONFIG_TAGGING_NONE)
23948 +       (0 << VCI_KCBIT_TAGGED) |
23949 +#elif  defined(CONFIG_TAGGING_UID16)
23950 +       (1 << VCI_KCBIT_TAGGED) |
23951 +#elif  defined(CONFIG_TAGGING_GID16)
23952 +       (2 << VCI_KCBIT_TAGGED) |
23953 +#elif  defined(CONFIG_TAGGING_ID24)
23954 +       (3 << VCI_KCBIT_TAGGED) |
23955 +#elif  defined(CONFIG_TAGGING_INTERN)
23956 +       (4 << VCI_KCBIT_TAGGED) |
23957 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23958 +       (5 << VCI_KCBIT_TAGGED) |
23959 +#else
23960 +       (7 << VCI_KCBIT_TAGGED) |
23961 +#endif
23962 +       (1 << VCI_KCBIT_PPTAG) |
23963 +       0;
23964 +}
23965 +
23966 diff -NurpP --minimal linux-3.4.32/mm/memcontrol.c linux-3.4.32-vs2.3.3.9/mm/memcontrol.c
23967 --- linux-3.4.32/mm/memcontrol.c        2013-02-19 13:56:10.000000000 +0000
23968 +++ linux-3.4.32-vs2.3.3.9/mm/memcontrol.c      2012-12-08 00:53:53.000000000 +0000
23969 @@ -846,6 +846,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23970                                 struct mem_cgroup, css);
23971  }
23972  
23973 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23974 +{
23975 +       return res_counter_read_u64(&mem->res, member);
23976 +}
23977 +
23978 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23979 +{
23980 +       return res_counter_read_u64(&mem->memsw, member);
23981 +}
23982 +
23983 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23984 +{
23985 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23986 +}
23987 +
23988 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23989 +{
23990 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23991 +}
23992 +
23993 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23994 +{
23995 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23996 +}
23997 +
23998  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23999  {
24000         struct mem_cgroup *memcg = NULL;
24001 diff -NurpP --minimal linux-3.4.32/mm/oom_kill.c linux-3.4.32-vs2.3.3.9/mm/oom_kill.c
24002 --- linux-3.4.32/mm/oom_kill.c  2012-05-21 16:07:35.000000000 +0000
24003 +++ linux-3.4.32-vs2.3.3.9/mm/oom_kill.c        2012-05-21 16:15:05.000000000 +0000
24004 @@ -35,6 +35,8 @@
24005  #include <linux/freezer.h>
24006  #include <linux/ftrace.h>
24007  #include <linux/ratelimit.h>
24008 +#include <linux/reboot.h>
24009 +#include <linux/vs_context.h>
24010  
24011  #define CREATE_TRACE_POINTS
24012  #include <trace/events/oom.h>
24013 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
24014  static bool oom_unkillable_task(struct task_struct *p,
24015                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
24016  {
24017 -       if (is_global_init(p))
24018 +       unsigned xid = vx_current_xid();
24019 +
24020 +       /* skip the init task, global and per guest */
24021 +       if (task_is_init(p))
24022                 return true;
24023         if (p->flags & PF_KTHREAD)
24024                 return true;
24025  
24026 +       /* skip other guest and host processes if oom in guest */
24027 +       if (xid && vx_task_xid(p) != xid)
24028 +               return true;
24029 +
24030         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24031         if (memcg && !task_in_mem_cgroup(p, memcg))
24032                 return true;
24033 @@ -462,8 +471,8 @@ static void oom_kill_process(struct task
24034                 dump_header(p, gfp_mask, order, memcg, nodemask);
24035  
24036         task_lock(p);
24037 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24038 -               message, task_pid_nr(p), p->comm, points);
24039 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24040 +               message, task_pid_nr(p), p->xid, p->comm, points);
24041         task_unlock(p);
24042  
24043         /*
24044 @@ -496,8 +505,8 @@ static void oom_kill_process(struct task
24045  
24046         /* mm cannot safely be dereferenced after task_unlock(victim) */
24047         mm = victim->mm;
24048 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24049 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
24050 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24051 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
24052                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
24053                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
24054         task_unlock(victim);
24055 @@ -596,6 +605,8 @@ int unregister_oom_notifier(struct notif
24056  }
24057  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24058  
24059 +long vs_oom_action(unsigned int);
24060 +
24061  /*
24062   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24063   * if a parallel OOM killing is already taking place that includes a zone in
24064 @@ -747,7 +758,12 @@ void out_of_memory(struct zonelist *zone
24065         if (!p) {
24066                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24067                 read_unlock(&tasklist_lock);
24068 -               panic("Out of memory and no killable processes...\n");
24069 +
24070 +               /* avoid panic for guest OOM */
24071 +               if (current->xid)
24072 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24073 +               else
24074 +                       panic("Out of memory and no killable processes...\n");
24075         }
24076         if (PTR_ERR(p) != -1UL) {
24077                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24078 diff -NurpP --minimal linux-3.4.32/mm/page_alloc.c linux-3.4.32-vs2.3.3.9/mm/page_alloc.c
24079 --- linux-3.4.32/mm/page_alloc.c        2013-02-19 13:56:10.000000000 +0000
24080 +++ linux-3.4.32-vs2.3.3.9/mm/page_alloc.c      2013-02-11 23:37:30.000000000 +0000
24081 @@ -58,6 +58,8 @@
24082  #include <linux/memcontrol.h>
24083  #include <linux/prefetch.h>
24084  #include <linux/page-debug-flags.h>
24085 +#include <linux/vs_base.h>
24086 +#include <linux/vs_limit.h>
24087  
24088  #include <asm/tlbflush.h>
24089  #include <asm/div64.h>
24090 @@ -2655,6 +2657,9 @@ void si_meminfo(struct sysinfo *val)
24091         val->totalhigh = totalhigh_pages;
24092         val->freehigh = nr_free_highpages();
24093         val->mem_unit = PAGE_SIZE;
24094 +
24095 +       if (vx_flags(VXF_VIRT_MEM, 0))
24096 +               vx_vsi_meminfo(val);
24097  }
24098  
24099  EXPORT_SYMBOL(si_meminfo);
24100 @@ -2675,6 +2680,9 @@ void si_meminfo_node(struct sysinfo *val
24101         val->freehigh = 0;
24102  #endif
24103         val->mem_unit = PAGE_SIZE;
24104 +
24105 +       if (vx_flags(VXF_VIRT_MEM, 0))
24106 +               vx_vsi_meminfo(val);
24107  }
24108  #endif
24109  
24110 diff -NurpP --minimal linux-3.4.32/mm/pgtable-generic.c linux-3.4.32-vs2.3.3.9/mm/pgtable-generic.c
24111 --- linux-3.4.32/mm/pgtable-generic.c   2012-05-21 16:07:35.000000000 +0000
24112 +++ linux-3.4.32-vs2.3.3.9/mm/pgtable-generic.c 2012-05-21 16:15:05.000000000 +0000
24113 @@ -6,6 +6,8 @@
24114   *  Copyright (C) 2010  Linus Torvalds
24115   */
24116  
24117 +#include <linux/mm.h>
24118 +
24119  #include <linux/pagemap.h>
24120  #include <asm/tlb.h>
24121  #include <asm-generic/pgtable.h>
24122 diff -NurpP --minimal linux-3.4.32/mm/shmem.c linux-3.4.32-vs2.3.3.9/mm/shmem.c
24123 --- linux-3.4.32/mm/shmem.c     2013-02-19 13:56:10.000000000 +0000
24124 +++ linux-3.4.32-vs2.3.3.9/mm/shmem.c   2012-12-18 14:06:36.000000000 +0000
24125 @@ -1473,7 +1473,7 @@ static int shmem_statfs(struct dentry *d
24126  {
24127         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24128  
24129 -       buf->f_type = TMPFS_MAGIC;
24130 +       buf->f_type = TMPFS_SUPER_MAGIC;
24131         buf->f_bsize = PAGE_CACHE_SIZE;
24132         buf->f_namelen = NAME_MAX;
24133         if (sbinfo->max_blocks) {
24134 @@ -2281,7 +2281,7 @@ int shmem_fill_super(struct super_block
24135         sb->s_maxbytes = MAX_LFS_FILESIZE;
24136         sb->s_blocksize = PAGE_CACHE_SIZE;
24137         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24138 -       sb->s_magic = TMPFS_MAGIC;
24139 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24140         sb->s_op = &shmem_ops;
24141         sb->s_time_gran = 1;
24142  #ifdef CONFIG_TMPFS_XATTR
24143 diff -NurpP --minimal linux-3.4.32/mm/slab.c linux-3.4.32-vs2.3.3.9/mm/slab.c
24144 --- linux-3.4.32/mm/slab.c      2013-02-19 13:56:10.000000000 +0000
24145 +++ linux-3.4.32-vs2.3.3.9/mm/slab.c    2012-10-22 13:09:53.000000000 +0000
24146 @@ -413,6 +413,8 @@ static void kmem_list3_init(struct kmem_
24147  #define STATS_INC_FREEMISS(x)  do { } while (0)
24148  #endif
24149  
24150 +#include "slab_vs.h"
24151 +
24152  #if DEBUG
24153  
24154  /*
24155 @@ -3466,6 +3468,7 @@ retry:
24156  
24157         obj = slab_get_obj(cachep, slabp, nodeid);
24158         check_slabp(cachep, slabp);
24159 +       vx_slab_alloc(cachep, flags);
24160         l3->free_objects--;
24161         /* move slabp to correct slabp list: */
24162         list_del(&slabp->list);
24163 @@ -3543,6 +3546,7 @@ __cache_alloc_node(struct kmem_cache *ca
24164         /* ___cache_alloc_node can fall back to other nodes */
24165         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24166    out:
24167 +       vx_slab_alloc(cachep, flags);
24168         local_irq_restore(save_flags);
24169         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24170         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24171 @@ -3730,6 +3734,7 @@ static inline void __cache_free(struct k
24172         check_irq_off();
24173         kmemleak_free_recursive(objp, cachep->flags);
24174         objp = cache_free_debugcheck(cachep, objp, caller);
24175 +       vx_slab_free(cachep);
24176  
24177         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24178  
24179 diff -NurpP --minimal linux-3.4.32/mm/slab_vs.h linux-3.4.32-vs2.3.3.9/mm/slab_vs.h
24180 --- linux-3.4.32/mm/slab_vs.h   1970-01-01 00:00:00.000000000 +0000
24181 +++ linux-3.4.32-vs2.3.3.9/mm/slab_vs.h 2012-05-21 16:15:05.000000000 +0000
24182 @@ -0,0 +1,29 @@
24183 +
24184 +#include <linux/vserver/context.h>
24185 +
24186 +#include <linux/vs_context.h>
24187 +
24188 +static inline
24189 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24190 +{
24191 +       int what = gfp_zone(cachep->gfpflags);
24192 +       struct vx_info *vxi = current_vx_info();
24193 +
24194 +       if (!vxi)
24195 +               return;
24196 +
24197 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24198 +}
24199 +
24200 +static inline
24201 +void vx_slab_free(struct kmem_cache *cachep)
24202 +{
24203 +       int what = gfp_zone(cachep->gfpflags);
24204 +       struct vx_info *vxi = current_vx_info();
24205 +
24206 +       if (!vxi)
24207 +               return;
24208 +
24209 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24210 +}
24211 +
24212 diff -NurpP --minimal linux-3.4.32/mm/swapfile.c linux-3.4.32-vs2.3.3.9/mm/swapfile.c
24213 --- linux-3.4.32/mm/swapfile.c  2013-02-19 13:56:10.000000000 +0000
24214 +++ linux-3.4.32-vs2.3.3.9/mm/swapfile.c        2012-06-28 14:45:07.000000000 +0000
24215 @@ -36,6 +36,7 @@
24216  #include <asm/tlbflush.h>
24217  #include <linux/swapops.h>
24218  #include <linux/page_cgroup.h>
24219 +#include <linux/vs_base.h>
24220  
24221  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24222                                  unsigned char);
24223 @@ -1754,6 +1755,16 @@ static int swap_show(struct seq_file *sw
24224  
24225         if (si == SEQ_START_TOKEN) {
24226                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24227 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24228 +                       struct sysinfo si;
24229 +
24230 +                       vx_vsi_swapinfo(&si);
24231 +                       if (si.totalswap < (1 << 10))
24232 +                               return 0;
24233 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24234 +                               "hdv0", "partition", si.totalswap >> 10,
24235 +                               (si.totalswap - si.freeswap) >> 10, -1);
24236 +               }
24237                 return 0;
24238         }
24239  
24240 @@ -2176,6 +2187,8 @@ void si_swapinfo(struct sysinfo *val)
24241         val->freeswap = nr_swap_pages + nr_to_be_unused;
24242         val->totalswap = total_swap_pages + nr_to_be_unused;
24243         spin_unlock(&swap_lock);
24244 +       if (vx_flags(VXF_VIRT_MEM, 0))
24245 +               vx_vsi_swapinfo(val);
24246  }
24247  
24248  /*
24249 diff -NurpP --minimal linux-3.4.32/net/bridge/br_multicast.c linux-3.4.32-vs2.3.3.9/net/bridge/br_multicast.c
24250 --- linux-3.4.32/net/bridge/br_multicast.c      2012-05-21 16:07:40.000000000 +0000
24251 +++ linux-3.4.32-vs2.3.3.9/net/bridge/br_multicast.c    2012-05-21 16:15:05.000000000 +0000
24252 @@ -445,7 +445,7 @@ static struct sk_buff *br_ip6_multicast_
24253         ip6h->hop_limit = 1;
24254         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24255         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24256 -                              &ip6h->saddr)) {
24257 +                              &ip6h->saddr, NULL)) {
24258                 kfree_skb(skb);
24259                 return NULL;
24260         }
24261 diff -NurpP --minimal linux-3.4.32/net/core/dev.c linux-3.4.32-vs2.3.3.9/net/core/dev.c
24262 --- linux-3.4.32/net/core/dev.c 2013-02-19 13:56:15.000000000 +0000
24263 +++ linux-3.4.32-vs2.3.3.9/net/core/dev.c       2012-12-08 00:53:53.000000000 +0000
24264 @@ -126,6 +126,7 @@
24265  #include <linux/in.h>
24266  #include <linux/jhash.h>
24267  #include <linux/random.h>
24268 +#include <linux/vs_inet.h>
24269  #include <trace/events/napi.h>
24270  #include <trace/events/net.h>
24271  #include <trace/events/skb.h>
24272 @@ -621,7 +622,8 @@ struct net_device *__dev_get_by_name(str
24273         struct hlist_head *head = dev_name_hash(net, name);
24274  
24275         hlist_for_each_entry(dev, p, head, name_hlist)
24276 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24277 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24278 +                   nx_dev_visible(current_nx_info(), dev))
24279                         return dev;
24280  
24281         return NULL;
24282 @@ -647,7 +649,8 @@ struct net_device *dev_get_by_name_rcu(s
24283         struct hlist_head *head = dev_name_hash(net, name);
24284  
24285         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24286 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24287 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24288 +                   nx_dev_visible(current_nx_info(), dev))
24289                         return dev;
24290  
24291         return NULL;
24292 @@ -698,7 +701,8 @@ struct net_device *__dev_get_by_index(st
24293         struct hlist_head *head = dev_index_hash(net, ifindex);
24294  
24295         hlist_for_each_entry(dev, p, head, index_hlist)
24296 -               if (dev->ifindex == ifindex)
24297 +               if ((dev->ifindex == ifindex) &&
24298 +                   nx_dev_visible(current_nx_info(), dev))
24299                         return dev;
24300  
24301         return NULL;
24302 @@ -716,7 +720,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24303   *     about locking. The caller must hold RCU lock.
24304   */
24305  
24306 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24307 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24308  {
24309         struct hlist_node *p;
24310         struct net_device *dev;
24311 @@ -728,6 +732,16 @@ struct net_device *dev_get_by_index_rcu(
24312  
24313         return NULL;
24314  }
24315 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24316 +
24317 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24318 +{
24319 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24320 +
24321 +       if (nx_dev_visible(current_nx_info(), dev))
24322 +               return dev;
24323 +       return NULL;
24324 +}
24325  EXPORT_SYMBOL(dev_get_by_index_rcu);
24326  
24327  
24328 @@ -776,7 +790,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24329  
24330         for_each_netdev_rcu(net, dev)
24331                 if (dev->type == type &&
24332 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24333 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24334 +                   nx_dev_visible(current_nx_info(), dev))
24335                         return dev;
24336  
24337         return NULL;
24338 @@ -788,9 +803,11 @@ struct net_device *__dev_getfirstbyhwtyp
24339         struct net_device *dev;
24340  
24341         ASSERT_RTNL();
24342 -       for_each_netdev(net, dev)
24343 -               if (dev->type == type)
24344 +       for_each_netdev(net, dev) {
24345 +               if ((dev->type == type) &&
24346 +                   nx_dev_visible(current_nx_info(), dev))
24347                         return dev;
24348 +       }
24349  
24350         return NULL;
24351  }
24352 @@ -908,6 +925,8 @@ static int __dev_alloc_name(struct net *
24353                                 continue;
24354                         if (i < 0 || i >= max_netdevices)
24355                                 continue;
24356 +                       if (!nx_dev_visible(current_nx_info(), d))
24357 +                               continue;
24358  
24359                         /*  avoid cases where sscanf is not exact inverse of printf */
24360                         snprintf(buf, IFNAMSIZ, name, i);
24361 @@ -3999,6 +4018,8 @@ static int dev_ifconf(struct net *net, c
24362  
24363         total = 0;
24364         for_each_netdev(net, dev) {
24365 +               if (!nx_dev_visible(current_nx_info(), dev))
24366 +                       continue;
24367                 for (i = 0; i < NPROTO; i++) {
24368                         if (gifconf_list[i]) {
24369                                 int done;
24370 @@ -4101,6 +4122,10 @@ static void dev_seq_printf_stats(struct
24371         struct rtnl_link_stats64 temp;
24372         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24373  
24374 +       /* device visible inside network context? */
24375 +       if (!nx_dev_visible(current_nx_info(), dev))
24376 +               return;
24377 +
24378         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24379                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24380                    dev->name, stats->rx_bytes, stats->rx_packets,
24381 diff -NurpP --minimal linux-3.4.32/net/core/rtnetlink.c linux-3.4.32-vs2.3.3.9/net/core/rtnetlink.c
24382 --- linux-3.4.32/net/core/rtnetlink.c   2013-02-19 13:56:15.000000000 +0000
24383 +++ linux-3.4.32-vs2.3.3.9/net/core/rtnetlink.c 2012-09-01 08:50:49.000000000 +0000
24384 @@ -1078,6 +1078,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24385                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24386                         if (idx < s_idx)
24387                                 goto cont;
24388 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24389 +                               continue;
24390                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24391                                              NETLINK_CB(cb->skb).pid,
24392                                              cb->nlh->nlmsg_seq, 0,
24393 @@ -1961,6 +1963,9 @@ void rtmsg_ifinfo(int type, struct net_d
24394         int err = -ENOBUFS;
24395         size_t if_info_size;
24396  
24397 +       if (!nx_dev_visible(current_nx_info(), dev))
24398 +               return;
24399 +
24400         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24401         if (skb == NULL)
24402                 goto errout;
24403 diff -NurpP --minimal linux-3.4.32/net/core/sock.c linux-3.4.32-vs2.3.3.9/net/core/sock.c
24404 --- linux-3.4.32/net/core/sock.c        2013-02-19 13:56:16.000000000 +0000
24405 +++ linux-3.4.32-vs2.3.3.9/net/core/sock.c      2012-10-22 13:09:53.000000000 +0000
24406 @@ -129,6 +129,10 @@
24407  #include <net/netprio_cgroup.h>
24408  
24409  #include <linux/filter.h>
24410 +#include <linux/vs_socket.h>
24411 +#include <linux/vs_limit.h>
24412 +#include <linux/vs_context.h>
24413 +#include <linux/vs_network.h>
24414  
24415  #include <trace/events/sock.h>
24416  
24417 @@ -1147,6 +1151,8 @@ static struct sock *sk_prot_alloc(struct
24418                         goto out_free_sec;
24419                 sk_tx_queue_clear(sk);
24420         }
24421 +               sock_vx_init(sk);
24422 +               sock_nx_init(sk);
24423  
24424         return sk;
24425  
24426 @@ -1255,6 +1261,11 @@ static void __sk_free(struct sock *sk)
24427                 put_cred(sk->sk_peer_cred);
24428         put_pid(sk->sk_peer_pid);
24429         put_net(sock_net(sk));
24430 +       vx_sock_dec(sk);
24431 +       clr_vx_info(&sk->sk_vx_info);
24432 +       sk->sk_xid = -1;
24433 +       clr_nx_info(&sk->sk_nx_info);
24434 +       sk->sk_nid = -1;
24435         sk_prot_free(sk->sk_prot_creator, sk);
24436  }
24437  
24438 @@ -1315,6 +1326,8 @@ struct sock *sk_clone_lock(const struct
24439  
24440                 /* SANITY */
24441                 get_net(sock_net(newsk));
24442 +               sock_vx_init(newsk);
24443 +               sock_nx_init(newsk);
24444                 sk_node_init(&newsk->sk_node);
24445                 sock_lock_init(newsk);
24446                 bh_lock_sock(newsk);
24447 @@ -1371,6 +1384,12 @@ struct sock *sk_clone_lock(const struct
24448                 smp_wmb();
24449                 atomic_set(&newsk->sk_refcnt, 2);
24450  
24451 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24452 +               newsk->sk_xid = sk->sk_xid;
24453 +               vx_sock_inc(newsk);
24454 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24455 +               newsk->sk_nid = sk->sk_nid;
24456 +
24457                 /*
24458                  * Increment the counter in the same struct proto as the master
24459                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24460 @@ -2127,6 +2146,12 @@ void sock_init_data(struct socket *sock,
24461  
24462         sk->sk_stamp = ktime_set(-1L, 0);
24463  
24464 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24465 +       sk->sk_xid = vx_current_xid();
24466 +       vx_sock_inc(sk);
24467 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24468 +       sk->sk_nid = nx_current_nid();
24469 +
24470         /*
24471          * Before updating sk_refcnt, we must commit prior changes to memory
24472          * (Documentation/RCU/rculist_nulls.txt for details)
24473 diff -NurpP --minimal linux-3.4.32/net/ipv4/af_inet.c linux-3.4.32-vs2.3.3.9/net/ipv4/af_inet.c
24474 --- linux-3.4.32/net/ipv4/af_inet.c     2012-05-21 16:07:40.000000000 +0000
24475 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/af_inet.c   2012-05-21 16:15:05.000000000 +0000
24476 @@ -118,6 +118,7 @@
24477  #ifdef CONFIG_IP_MROUTE
24478  #include <linux/mroute.h>
24479  #endif
24480 +#include <linux/vs_limit.h>
24481  
24482  
24483  /* The inetsw table contains everything that inet_create needs to
24484 @@ -327,9 +328,13 @@ lookup_protocol:
24485         }
24486  
24487         err = -EPERM;
24488 +       if ((protocol == IPPROTO_ICMP) &&
24489 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24490 +               goto override;
24491 +
24492         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24493                 goto out_rcu_unlock;
24494 -
24495 +override:
24496         err = -EAFNOSUPPORT;
24497         if (!inet_netns_ok(net, protocol))
24498                 goto out_rcu_unlock;
24499 @@ -454,6 +459,7 @@ int inet_bind(struct socket *sock, struc
24500         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24501         struct sock *sk = sock->sk;
24502         struct inet_sock *inet = inet_sk(sk);
24503 +       struct nx_v4_sock_addr nsa;
24504         unsigned short snum;
24505         int chk_addr_ret;
24506         int err;
24507 @@ -477,7 +483,11 @@ int inet_bind(struct socket *sock, struc
24508                         goto out;
24509         }
24510  
24511 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24512 +       err = v4_map_sock_addr(inet, addr, &nsa);
24513 +       if (err)
24514 +               goto out;
24515 +
24516 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24517  
24518         /* Not specified by any standard per-se, however it breaks too
24519          * many applications when removed.  It is unfortunate since
24520 @@ -489,7 +499,7 @@ int inet_bind(struct socket *sock, struc
24521         err = -EADDRNOTAVAIL;
24522         if (!sysctl_ip_nonlocal_bind &&
24523             !(inet->freebind || inet->transparent) &&
24524 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24525 +           nsa.saddr != htonl(INADDR_ANY) &&
24526             chk_addr_ret != RTN_LOCAL &&
24527             chk_addr_ret != RTN_MULTICAST &&
24528             chk_addr_ret != RTN_BROADCAST)
24529 @@ -514,7 +524,7 @@ int inet_bind(struct socket *sock, struc
24530         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24531                 goto out_release_sock;
24532  
24533 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24534 +       v4_set_sock_addr(inet, &nsa);
24535         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24536                 inet->inet_saddr = 0;  /* Use device */
24537  
24538 @@ -717,11 +727,13 @@ int inet_getname(struct socket *sock, st
24539                      peer == 1))
24540                         return -ENOTCONN;
24541                 sin->sin_port = inet->inet_dport;
24542 -               sin->sin_addr.s_addr = inet->inet_daddr;
24543 +               sin->sin_addr.s_addr =
24544 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24545         } else {
24546                 __be32 addr = inet->inet_rcv_saddr;
24547                 if (!addr)
24548                         addr = inet->inet_saddr;
24549 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24550                 sin->sin_port = inet->inet_sport;
24551                 sin->sin_addr.s_addr = addr;
24552         }
24553 diff -NurpP --minimal linux-3.4.32/net/ipv4/arp.c linux-3.4.32-vs2.3.3.9/net/ipv4/arp.c
24554 --- linux-3.4.32/net/ipv4/arp.c 2012-05-21 16:07:40.000000000 +0000
24555 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/arp.c       2012-05-21 16:15:05.000000000 +0000
24556 @@ -1328,6 +1328,7 @@ static void arp_format_neigh_entry(struc
24557         struct net_device *dev = n->dev;
24558         int hatype = dev->type;
24559  
24560 +       /* FIXME: check for network context */
24561         read_lock(&n->lock);
24562         /* Convert hardware address to XX:XX:XX:XX ... form. */
24563  #if IS_ENABLED(CONFIG_AX25)
24564 @@ -1359,6 +1360,7 @@ static void arp_format_pneigh_entry(stru
24565         int hatype = dev ? dev->type : 0;
24566         char tbuf[16];
24567  
24568 +       /* FIXME: check for network context */
24569         sprintf(tbuf, "%pI4", n->key);
24570         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24571                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24572 diff -NurpP --minimal linux-3.4.32/net/ipv4/devinet.c linux-3.4.32-vs2.3.3.9/net/ipv4/devinet.c
24573 --- linux-3.4.32/net/ipv4/devinet.c     2012-05-21 16:07:40.000000000 +0000
24574 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/devinet.c   2012-05-21 16:15:05.000000000 +0000
24575 @@ -517,6 +517,7 @@ struct in_device *inetdev_by_index(struc
24576  }
24577  EXPORT_SYMBOL(inetdev_by_index);
24578  
24579 +
24580  /* Called only from RTNL semaphored context. No locks. */
24581  
24582  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24583 @@ -758,6 +759,8 @@ int devinet_ioctl(struct net *net, unsig
24584  
24585         in_dev = __in_dev_get_rtnl(dev);
24586         if (in_dev) {
24587 +               struct nx_info *nxi = current_nx_info();
24588 +
24589                 if (tryaddrmatch) {
24590                         /* Matthias Andree */
24591                         /* compare label and address (4.4BSD style) */
24592 @@ -766,6 +769,8 @@ int devinet_ioctl(struct net *net, unsig
24593                            This is checked above. */
24594                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24595                              ifap = &ifa->ifa_next) {
24596 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24597 +                                       continue;
24598                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24599                                     sin_orig.sin_addr.s_addr ==
24600                                                         ifa->ifa_local) {
24601 @@ -778,9 +783,12 @@ int devinet_ioctl(struct net *net, unsig
24602                    comparing just the label */
24603                 if (!ifa) {
24604                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24605 -                            ifap = &ifa->ifa_next)
24606 +                            ifap = &ifa->ifa_next) {
24607 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24608 +                                       continue;
24609                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24610                                         break;
24611 +                       }
24612                 }
24613         }
24614  
24615 @@ -933,6 +941,8 @@ static int inet_gifconf(struct net_devic
24616                 goto out;
24617  
24618         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24619 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24620 +                       continue;
24621                 if (!buf) {
24622                         done += sizeof(ifr);
24623                         continue;
24624 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24625         struct net_device *dev;
24626         struct in_device *in_dev;
24627         struct in_ifaddr *ifa;
24628 +       struct sock *sk = skb->sk;
24629         struct hlist_head *head;
24630         struct hlist_node *node;
24631  
24632 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24633  
24634                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24635                              ifa = ifa->ifa_next, ip_idx++) {
24636 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24637 +                               continue;
24638                                 if (ip_idx < s_ip_idx)
24639                                         continue;
24640                                 if (inet_fill_ifaddr(skb, ifa,
24641 diff -NurpP --minimal linux-3.4.32/net/ipv4/fib_trie.c linux-3.4.32-vs2.3.3.9/net/ipv4/fib_trie.c
24642 --- linux-3.4.32/net/ipv4/fib_trie.c    2012-05-21 16:07:40.000000000 +0000
24643 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/fib_trie.c  2012-05-21 16:15:05.000000000 +0000
24644 @@ -2556,6 +2556,7 @@ static int fib_route_seq_show(struct seq
24645                             || fa->fa_type == RTN_MULTICAST)
24646                                 continue;
24647  
24648 +                       /* FIXME: check for network context? */
24649                         if (fi)
24650                                 seq_printf(seq,
24651                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24652 diff -NurpP --minimal linux-3.4.32/net/ipv4/inet_connection_sock.c linux-3.4.32-vs2.3.3.9/net/ipv4/inet_connection_sock.c
24653 --- linux-3.4.32/net/ipv4/inet_connection_sock.c        2013-02-19 13:56:16.000000000 +0000
24654 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/inet_connection_sock.c      2013-01-16 00:15:57.000000000 +0000
24655 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24656  }
24657  EXPORT_SYMBOL(inet_get_local_port_range);
24658  
24659 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24660 +{
24661 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24662 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24663 +
24664 +       if (inet_v6_ipv6only(sk2))
24665 +               return 0;
24666 +
24667 +       if (sk1_rcv_saddr &&
24668 +           sk2_rcv_saddr &&
24669 +           sk1_rcv_saddr == sk2_rcv_saddr)
24670 +               return 1;
24671 +
24672 +       if (sk1_rcv_saddr &&
24673 +           !sk2_rcv_saddr &&
24674 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24675 +               return 1;
24676 +
24677 +       if (sk2_rcv_saddr &&
24678 +           !sk1_rcv_saddr &&
24679 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24680 +               return 1;
24681 +
24682 +       if (!sk1_rcv_saddr &&
24683 +           !sk2_rcv_saddr &&
24684 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24685 +               return 1;
24686 +
24687 +       return 0;
24688 +}
24689 +
24690  int inet_csk_bind_conflict(const struct sock *sk,
24691                            const struct inet_bind_bucket *tb)
24692  {
24693 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct
24694                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24695                         if (!reuse || !sk2->sk_reuse ||
24696                             sk2->sk_state == TCP_LISTEN) {
24697 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24698 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24699 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24700 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24701                                         break;
24702                         }
24703                 }
24704 diff -NurpP --minimal linux-3.4.32/net/ipv4/inet_diag.c linux-3.4.32-vs2.3.3.9/net/ipv4/inet_diag.c
24705 --- linux-3.4.32/net/ipv4/inet_diag.c   2013-02-19 13:56:16.000000000 +0000
24706 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/inet_diag.c 2013-01-16 00:18:21.000000000 +0000
24707 @@ -31,6 +31,8 @@
24708  
24709  #include <linux/inet.h>
24710  #include <linux/stddef.h>
24711 +#include <linux/vs_network.h>
24712 +#include <linux/vs_inet.h>
24713  
24714  #include <linux/inet_diag.h>
24715  #include <linux/sock_diag.h>
24716 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24717  
24718         r->id.idiag_sport = inet->inet_sport;
24719         r->id.idiag_dport = inet->inet_dport;
24720 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24721 -       r->id.idiag_dst[0] = inet->inet_daddr;
24722 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24723 +               inet->inet_rcv_saddr);
24724 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24725 +               inet->inet_daddr);
24726  
24727         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24728          * hence this needs to be included regardless of socket family.
24729 @@ -231,8 +235,8 @@ static int inet_twsk_diag_fill(struct in
24730         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24731         r->id.idiag_sport     = tw->tw_sport;
24732         r->id.idiag_dport     = tw->tw_dport;
24733 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24734 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24735 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24736 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24737         r->idiag_state        = tw->tw_substate;
24738         r->idiag_timer        = 3;
24739         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24740 @@ -276,12 +280,14 @@ int inet_diag_dump_one_icsk(struct inet_
24741  
24742         err = -EINVAL;
24743         if (req->sdiag_family == AF_INET) {
24744 +               /* TODO: lback */
24745                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24746                                  req->id.idiag_dport, req->id.idiag_src[0],
24747                                  req->id.idiag_sport, req->id.idiag_if);
24748         }
24749  #if IS_ENABLED(CONFIG_IPV6)
24750         else if (req->sdiag_family == AF_INET6) {
24751 +               /* TODO: lback */
24752                 sk = inet6_lookup(&init_net, hashinfo,
24753                                   (struct in6_addr *)req->id.idiag_dst,
24754                                   req->id.idiag_dport,
24755 @@ -482,6 +488,7 @@ int inet_diag_bc_sk(const struct nlattr
24756         } else
24757  #endif
24758         {
24759 +                       /* TODO: lback */
24760                 entry.saddr = &inet->inet_rcv_saddr;
24761                 entry.daddr = &inet->inet_daddr;
24762         }
24763 @@ -639,6 +646,7 @@ static int inet_twsk_diag_dump(struct in
24764                 } else
24765  #endif
24766                 {
24767 +                       /* TODO: lback */
24768                         entry.saddr = &tw->tw_rcv_saddr;
24769                         entry.daddr = &tw->tw_daddr;
24770                 }
24771 @@ -714,8 +722,8 @@ static int inet_diag_fill_req(struct sk_
24772  
24773         r->id.idiag_sport = inet->inet_sport;
24774         r->id.idiag_dport = ireq->rmt_port;
24775 -       r->id.idiag_src[0] = ireq->loc_addr;
24776 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24777 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24778 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24779         r->idiag_expires = jiffies_to_msecs(tmo);
24780         r->idiag_rqueue = 0;
24781         r->idiag_wqueue = 0;
24782 @@ -784,6 +792,7 @@ static int inet_diag_dump_reqs(struct sk
24783                                 continue;
24784  
24785                         if (bc) {
24786 +                               /* TODO: lback */
24787                                 inet_diag_req_addrs(sk, req, &entry);
24788                                 entry.dport = ntohs(ireq->rmt_port);
24789  
24790 @@ -834,6 +843,8 @@ void inet_diag_dump_icsk(struct inet_has
24791                         sk_nulls_for_each(sk, node, &ilb->head) {
24792                                 struct inet_sock *inet = inet_sk(sk);
24793  
24794 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24795 +                                       continue;
24796                                 if (num < s_num) {
24797                                         num++;
24798                                         continue;
24799 @@ -904,6 +915,8 @@ skip_listen_ht:
24800                 sk_nulls_for_each(sk, node, &head->chain) {
24801                         struct inet_sock *inet = inet_sk(sk);
24802  
24803 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24804 +                               continue;
24805                         if (num < s_num)
24806                                 goto next_normal;
24807                         if (!(r->idiag_states & (1 << sk->sk_state)))
24808 @@ -931,6 +944,8 @@ next_normal:
24809                         inet_twsk_for_each(tw, node,
24810                                     &head->twchain) {
24811  
24812 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24813 +                                       continue;
24814                                 if (num < s_num)
24815                                         goto next_dying;
24816                                 if (r->sdiag_family != AF_UNSPEC &&
24817 diff -NurpP --minimal linux-3.4.32/net/ipv4/inet_hashtables.c linux-3.4.32-vs2.3.3.9/net/ipv4/inet_hashtables.c
24818 --- linux-3.4.32/net/ipv4/inet_hashtables.c     2011-10-24 16:45:34.000000000 +0000
24819 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/inet_hashtables.c   2012-05-21 16:15:05.000000000 +0000
24820 @@ -22,6 +22,7 @@
24821  #include <net/inet_connection_sock.h>
24822  #include <net/inet_hashtables.h>
24823  #include <net/secure_seq.h>
24824 +#include <net/route.h>
24825  #include <net/ip.h>
24826  
24827  /*
24828 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24829                         if (rcv_saddr != daddr)
24830                                 return -1;
24831                         score += 2;
24832 +               } else {
24833 +                       /* block non nx_info ips */
24834 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24835 +                               daddr, NXA_MASK_BIND))
24836 +                               return -1;
24837                 }
24838                 if (sk->sk_bound_dev_if) {
24839                         if (sk->sk_bound_dev_if != dif)
24840 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24841   * wildcarded during the search since they can never be otherwise.
24842   */
24843  
24844 -
24845  struct sock *__inet_lookup_listener(struct net *net,
24846                                     struct inet_hashinfo *hashinfo,
24847                                     const __be32 daddr, const unsigned short hnum,
24848 @@ -196,6 +201,7 @@ begin:
24849                         hiscore = score;
24850                 }
24851         }
24852 +
24853         /*
24854          * if the nulls value we got at the end of this lookup is
24855          * not the expected one, we must restart lookup.
24856 diff -NurpP --minimal linux-3.4.32/net/ipv4/netfilter/nf_nat_helper.c linux-3.4.32-vs2.3.3.9/net/ipv4/netfilter/nf_nat_helper.c
24857 --- linux-3.4.32/net/ipv4/netfilter/nf_nat_helper.c     2012-03-19 18:47:33.000000000 +0000
24858 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/netfilter/nf_nat_helper.c   2012-05-21 16:15:05.000000000 +0000
24859 @@ -20,6 +20,7 @@
24860  #include <net/route.h>
24861  
24862  #include <linux/netfilter_ipv4.h>
24863 +#include <net/route.h>
24864  #include <net/netfilter/nf_conntrack.h>
24865  #include <net/netfilter/nf_conntrack_helper.h>
24866  #include <net/netfilter/nf_conntrack_ecache.h>
24867 diff -NurpP --minimal linux-3.4.32/net/ipv4/netfilter.c linux-3.4.32-vs2.3.3.9/net/ipv4/netfilter.c
24868 --- linux-3.4.32/net/ipv4/netfilter.c   2012-01-09 15:15:03.000000000 +0000
24869 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/netfilter.c 2012-05-21 16:15:05.000000000 +0000
24870 @@ -6,7 +6,7 @@
24871  #include <linux/skbuff.h>
24872  #include <linux/gfp.h>
24873  #include <linux/export.h>
24874 -#include <net/route.h>
24875 +// #include <net/route.h>
24876  #include <net/xfrm.h>
24877  #include <net/ip.h>
24878  #include <net/netfilter/nf_queue.h>
24879 diff -NurpP --minimal linux-3.4.32/net/ipv4/raw.c linux-3.4.32-vs2.3.3.9/net/ipv4/raw.c
24880 --- linux-3.4.32/net/ipv4/raw.c 2013-02-19 13:56:16.000000000 +0000
24881 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/raw.c       2012-10-22 13:09:53.000000000 +0000
24882 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24883  
24884                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24885                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24886 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24887 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24888                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24889                         goto found; /* gotcha */
24890         }
24891 @@ -392,6 +392,12 @@ static int raw_send_hdrinc(struct sock *
24892                 icmp_out_count(net, ((struct icmphdr *)
24893                         skb_transport_header(skb))->type);
24894  
24895 +       err = -EPERM;
24896 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24897 +               sk->sk_nx_info &&
24898 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24899 +               goto error_free;
24900 +
24901         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24902                       rt->dst.dev, dst_output);
24903         if (err > 0)
24904 @@ -577,6 +583,16 @@ static int raw_sendmsg(struct kiocb *ioc
24905                         goto done;
24906         }
24907  
24908 +       if (sk->sk_nx_info) {
24909 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24910 +               if (IS_ERR(rt)) {
24911 +                       err = PTR_ERR(rt);
24912 +                       rt = NULL;
24913 +                       goto done;
24914 +               }
24915 +               ip_rt_put(rt);
24916 +       }
24917 +
24918         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24919         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24920         if (IS_ERR(rt)) {
24921 @@ -653,17 +669,19 @@ static int raw_bind(struct sock *sk, str
24922  {
24923         struct inet_sock *inet = inet_sk(sk);
24924         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24925 +       struct nx_v4_sock_addr nsa = { 0 };
24926         int ret = -EINVAL;
24927         int chk_addr_ret;
24928  
24929         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24930                 goto out;
24931 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24932 +       v4_map_sock_addr(inet, addr, &nsa);
24933 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24934         ret = -EADDRNOTAVAIL;
24935 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24936 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24937             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24938                 goto out;
24939 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24940 +       v4_set_sock_addr(inet, &nsa);
24941         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24942                 inet->inet_saddr = 0;  /* Use device */
24943         sk_dst_reset(sk);
24944 @@ -715,7 +733,8 @@ static int raw_recvmsg(struct kiocb *ioc
24945         /* Copy the address. */
24946         if (sin) {
24947                 sin->sin_family = AF_INET;
24948 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24949 +               sin->sin_addr.s_addr =
24950 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24951                 sin->sin_port = 0;
24952                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24953         }
24954 @@ -911,7 +930,8 @@ static struct sock *raw_get_first(struct
24955                 struct hlist_node *node;
24956  
24957                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24958 -                       if (sock_net(sk) == seq_file_net(seq))
24959 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24960 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24961                                 goto found;
24962         }
24963         sk = NULL;
24964 @@ -927,7 +947,8 @@ static struct sock *raw_get_next(struct
24965                 sk = sk_next(sk);
24966  try_again:
24967                 ;
24968 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24969 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24970 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24971  
24972         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24973                 sk = sk_head(&state->h->ht[state->bucket]);
24974 diff -NurpP --minimal linux-3.4.32/net/ipv4/route.c linux-3.4.32-vs2.3.3.9/net/ipv4/route.c
24975 --- linux-3.4.32/net/ipv4/route.c       2012-05-21 16:07:40.000000000 +0000
24976 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/route.c     2012-05-21 16:15:05.000000000 +0000
24977 @@ -2696,7 +2696,7 @@ static struct rtable *ip_route_output_sl
24978  
24979  
24980         if (fl4->flowi4_oif) {
24981 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24982 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24983                 rth = ERR_PTR(-ENODEV);
24984                 if (dev_out == NULL)
24985                         goto out;
24986 diff -NurpP --minimal linux-3.4.32/net/ipv4/tcp.c linux-3.4.32-vs2.3.3.9/net/ipv4/tcp.c
24987 --- linux-3.4.32/net/ipv4/tcp.c 2013-02-19 13:56:16.000000000 +0000
24988 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/tcp.c       2012-11-18 23:52:30.000000000 +0000
24989 @@ -268,6 +268,7 @@
24990  #include <linux/crypto.h>
24991  #include <linux/time.h>
24992  #include <linux/slab.h>
24993 +#include <linux/in.h>
24994  
24995  #include <net/icmp.h>
24996  #include <net/tcp.h>
24997 diff -NurpP --minimal linux-3.4.32/net/ipv4/tcp_ipv4.c linux-3.4.32-vs2.3.3.9/net/ipv4/tcp_ipv4.c
24998 --- linux-3.4.32/net/ipv4/tcp_ipv4.c    2013-02-19 13:56:16.000000000 +0000
24999 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/tcp_ipv4.c  2013-01-16 00:15:57.000000000 +0000
25000 @@ -2037,6 +2037,12 @@ static void *listening_get_next(struct s
25001                 req = req->dl_next;
25002                 while (1) {
25003                         while (req) {
25004 +                               vxdprintk(VXD_CBIT(net, 6),
25005 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25006 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25007 +                               if (req->sk &&
25008 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25009 +                                       continue;
25010                                 if (req->rsk_ops->family == st->family) {
25011                                         cur = req;
25012                                         goto out;
25013 @@ -2061,6 +2067,10 @@ get_req:
25014         }
25015  get_sk:
25016         sk_nulls_for_each_from(sk, node) {
25017 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25018 +                       sk, sk->sk_nid, nx_current_nid());
25019 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25020 +                       continue;
25021                 if (!net_eq(sock_net(sk), net))
25022                         continue;
25023                 if (sk->sk_family == st->family) {
25024 @@ -2137,6 +2147,11 @@ static void *established_get_first(struc
25025  
25026                 spin_lock_bh(lock);
25027                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25028 +                       vxdprintk(VXD_CBIT(net, 6),
25029 +                               "sk,egf: %p [#%d] (from %d)",
25030 +                               sk, sk->sk_nid, nx_current_nid());
25031 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25032 +                               continue;
25033                         if (sk->sk_family != st->family ||
25034                             !net_eq(sock_net(sk), net)) {
25035                                 continue;
25036 @@ -2147,6 +2162,11 @@ static void *established_get_first(struc
25037                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25038                 inet_twsk_for_each(tw, node,
25039                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25040 +                       vxdprintk(VXD_CBIT(net, 6),
25041 +                               "tw: %p [#%d] (from %d)",
25042 +                               tw, tw->tw_nid, nx_current_nid());
25043 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25044 +                               continue;
25045                         if (tw->tw_family != st->family ||
25046                             !net_eq(twsk_net(tw), net)) {
25047                                 continue;
25048 @@ -2176,7 +2196,9 @@ static void *established_get_next(struct
25049                 tw = cur;
25050                 tw = tw_next(tw);
25051  get_tw:
25052 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25053 +               while (tw && (tw->tw_family != st->family ||
25054 +                       !net_eq(twsk_net(tw), net) ||
25055 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25056                         tw = tw_next(tw);
25057                 }
25058                 if (tw) {
25059 @@ -2200,6 +2222,11 @@ get_tw:
25060                 sk = sk_nulls_next(sk);
25061  
25062         sk_nulls_for_each_from(sk, node) {
25063 +               vxdprintk(VXD_CBIT(net, 6),
25064 +                       "sk,egn: %p [#%d] (from %d)",
25065 +                       sk, sk->sk_nid, nx_current_nid());
25066 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25067 +                       continue;
25068                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25069                         goto found;
25070         }
25071 @@ -2405,9 +2432,9 @@ static void get_openreq4(const struct so
25072         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25073                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25074                 i,
25075 -               ireq->loc_addr,
25076 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25077                 ntohs(inet_sk(sk)->inet_sport),
25078 -               ireq->rmt_addr,
25079 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25080                 ntohs(ireq->rmt_port),
25081                 TCP_SYN_RECV,
25082                 0, 0, /* could print option size, but that is af dependent. */
25083 @@ -2429,8 +2456,8 @@ static void get_tcp4_sock(struct sock *s
25084         const struct tcp_sock *tp = tcp_sk(sk);
25085         const struct inet_connection_sock *icsk = inet_csk(sk);
25086         const struct inet_sock *inet = inet_sk(sk);
25087 -       __be32 dest = inet->inet_daddr;
25088 -       __be32 src = inet->inet_rcv_saddr;
25089 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25090 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25091         __u16 destp = ntohs(inet->inet_dport);
25092         __u16 srcp = ntohs(inet->inet_sport);
25093         int rx_queue;
25094 @@ -2487,8 +2514,8 @@ static void get_timewait4_sock(const str
25095         if (ttd < 0)
25096                 ttd = 0;
25097  
25098 -       dest  = tw->tw_daddr;
25099 -       src   = tw->tw_rcv_saddr;
25100 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
25101 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
25102         destp = ntohs(tw->tw_dport);
25103         srcp  = ntohs(tw->tw_sport);
25104  
25105 diff -NurpP --minimal linux-3.4.32/net/ipv4/tcp_minisocks.c linux-3.4.32-vs2.3.3.9/net/ipv4/tcp_minisocks.c
25106 --- linux-3.4.32/net/ipv4/tcp_minisocks.c       2012-05-21 16:07:40.000000000 +0000
25107 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/tcp_minisocks.c     2012-05-21 16:15:05.000000000 +0000
25108 @@ -23,6 +23,9 @@
25109  #include <linux/slab.h>
25110  #include <linux/sysctl.h>
25111  #include <linux/workqueue.h>
25112 +#include <linux/vs_limit.h>
25113 +#include <linux/vs_socket.h>
25114 +#include <linux/vs_context.h>
25115  #include <net/tcp.h>
25116  #include <net/inet_common.h>
25117  #include <net/xfrm.h>
25118 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int
25119                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25120                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25121  
25122 +               tw->tw_xid              = sk->sk_xid;
25123 +               tw->tw_vx_info          = NULL;
25124 +               tw->tw_nid              = sk->sk_nid;
25125 +               tw->tw_nx_info          = NULL;
25126 +
25127  #if IS_ENABLED(CONFIG_IPV6)
25128                 if (tw->tw_family == PF_INET6) {
25129                         struct ipv6_pinfo *np = inet6_sk(sk);
25130 diff -NurpP --minimal linux-3.4.32/net/ipv4/udp.c linux-3.4.32-vs2.3.3.9/net/ipv4/udp.c
25131 --- linux-3.4.32/net/ipv4/udp.c 2012-05-21 16:07:40.000000000 +0000
25132 +++ linux-3.4.32-vs2.3.3.9/net/ipv4/udp.c       2012-06-28 14:45:36.000000000 +0000
25133 @@ -298,14 +298,7 @@ fail:
25134  }
25135  EXPORT_SYMBOL(udp_lib_get_port);
25136  
25137 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25138 -{
25139 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25140 -
25141 -       return  (!ipv6_only_sock(sk2)  &&
25142 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25143 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25144 -}
25145 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25146  
25147  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25148                                        unsigned int port)
25149 @@ -340,6 +333,11 @@ static inline int compute_score(struct s
25150                         if (inet->inet_rcv_saddr != daddr)
25151                                 return -1;
25152                         score += 2;
25153 +               } else {
25154 +                       /* block non nx_info ips */
25155 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25156 +                               daddr, NXA_MASK_BIND))
25157 +                               return -1;
25158                 }
25159                 if (inet->inet_daddr) {
25160                         if (inet->inet_daddr != saddr)
25161 @@ -443,6 +441,7 @@ exact_match:
25162         return result;
25163  }
25164  
25165 +
25166  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25167   * harder than this. -DaveM
25168   */
25169 @@ -488,6 +487,11 @@ begin:
25170         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25171                 score = compute_score(sk, net, saddr, hnum, sport,
25172                                       daddr, dport, dif);
25173 +               /* FIXME: disabled?
25174 +               if (score == 9) {
25175 +                       result = sk;
25176 +                       break;
25177 +               } else */
25178                 if (score > badness) {
25179                         result = sk;
25180                         badness = score;
25181 @@ -501,6 +505,7 @@ begin:
25182         if (get_nulls_value(node) != slot)
25183                 goto begin;
25184  
25185 +
25186         if (result) {
25187                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25188                         result = NULL;
25189 @@ -510,6 +515,7 @@ begin:
25190                         goto begin;
25191                 }
25192         }
25193 +
25194         rcu_read_unlock();
25195         return result;
25196  }
25197 @@ -553,8 +559,7 @@ static inline struct sock *udp_v4_mcast_
25198                     udp_sk(s)->udp_port_hash != hnum ||
25199                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25200                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25201 -                   (inet->inet_rcv_saddr &&
25202 -                    inet->inet_rcv_saddr != loc_addr) ||
25203 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25204                     ipv6_only_sock(s) ||
25205                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25206                         continue;
25207 @@ -933,6 +938,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25208                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25209                                    faddr, saddr, dport, inet->inet_sport);
25210  
25211 +               if (sk->sk_nx_info) {
25212 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25213 +                       if (IS_ERR(rt)) {
25214 +                               err = PTR_ERR(rt);
25215 +                               rt = NULL;
25216 +                               goto out;
25217 +                       }
25218 +                       ip_rt_put(rt);
25219 +               }
25220 +
25221                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25222                 rt = ip_route_output_flow(net, fl4, sk);
25223                 if (IS_ERR(rt)) {
25224 @@ -1231,7 +1246,8 @@ try_again:
25225         if (sin) {
25226                 sin->sin_family = AF_INET;
25227                 sin->sin_port = udp_hdr(skb)->source;
25228 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25229 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25230 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25231                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25232         }
25233         if (inet->cmsg_flags)
25234 @@ -1970,6 +1986,8 @@ static struct sock *udp_get_first(struct
25235                 sk_nulls_for_each(sk, node, &hslot->head) {
25236                         if (!net_eq(sock_net(sk), net))
25237                                 continue;
25238 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25239 +                               continue;
25240                         if (sk->sk_family == state->family)
25241                                 goto found;
25242                 }
25243 @@ -1987,7 +2005,9 @@ static struct sock *udp_get_next(struct
25244  
25245         do {
25246                 sk = sk_nulls_next(sk);
25247 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25248 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25249 +               sk->sk_family != state->family ||
25250 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25251  
25252         if (!sk) {
25253                 if (state->bucket <= state->udp_table->mask)
25254 @@ -2083,8 +2103,8 @@ static void udp4_format_sock(struct sock
25255                 int bucket, int *len)
25256  {
25257         struct inet_sock *inet = inet_sk(sp);
25258 -       __be32 dest = inet->inet_daddr;
25259 -       __be32 src  = inet->inet_rcv_saddr;
25260 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25261 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25262         __u16 destp       = ntohs(inet->inet_dport);
25263         __u16 srcp        = ntohs(inet->inet_sport);
25264  
25265 diff -NurpP --minimal linux-3.4.32/net/ipv6/Kconfig linux-3.4.32-vs2.3.3.9/net/ipv6/Kconfig
25266 --- linux-3.4.32/net/ipv6/Kconfig       2010-08-02 14:52:59.000000000 +0000
25267 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/Kconfig     2012-05-21 16:15:05.000000000 +0000
25268 @@ -4,8 +4,8 @@
25269  
25270  #   IPv6 as module will cause a CRASH if you try to unload it
25271  menuconfig IPV6
25272 -       tristate "The IPv6 protocol"
25273 -       default m
25274 +       bool "The IPv6 protocol"
25275 +       default n
25276         ---help---
25277           This is complemental support for the IP version 6.
25278           You will still be able to do traditional IPv4 networking as well.
25279 diff -NurpP --minimal linux-3.4.32/net/ipv6/addrconf.c linux-3.4.32-vs2.3.3.9/net/ipv6/addrconf.c
25280 --- linux-3.4.32/net/ipv6/addrconf.c    2013-02-19 13:56:17.000000000 +0000
25281 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/addrconf.c  2013-02-19 14:42:56.000000000 +0000
25282 @@ -88,6 +88,8 @@
25283  #include <linux/proc_fs.h>
25284  #include <linux/seq_file.h>
25285  #include <linux/export.h>
25286 +#include <linux/vs_network.h>
25287 +#include <linux/vs_inet6.h>
25288  
25289  /* Set to 3 to get tracing... */
25290  #define ACONF_DEBUG 2
25291 @@ -1108,7 +1110,7 @@ out:
25292  
25293  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25294                        const struct in6_addr *daddr, unsigned int prefs,
25295 -                      struct in6_addr *saddr)
25296 +                      struct in6_addr *saddr, struct nx_info *nxi)
25297  {
25298         struct ipv6_saddr_score scores[2],
25299                                 *score = &scores[0], *hiscore = &scores[1];
25300 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net,
25301                                                dev->name);
25302                                 continue;
25303                         }
25304 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25305 +                               continue;
25306  
25307                         score->rule = -1;
25308                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25309 @@ -3166,7 +3170,10 @@ static void if6_seq_stop(struct seq_file
25310  static int if6_seq_show(struct seq_file *seq, void *v)
25311  {
25312         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25313 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25314 +
25315 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25316 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25317 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25318                    &ifp->addr,
25319                    ifp->idev->dev->ifindex,
25320                    ifp->prefix_len,
25321 @@ -3672,6 +3679,11 @@ static int in6_dump_addrs(struct inet6_d
25322         struct ifacaddr6 *ifaca;
25323         int err = 1;
25324         int ip_idx = *p_ip_idx;
25325 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25326 +
25327 +       /* disable ipv6 on non v6 guests */
25328 +       if (nxi && !nx_info_has_v6(nxi))
25329 +               return skb->len;
25330  
25331         read_lock_bh(&idev->lock);
25332         switch (type) {
25333 @@ -3682,6 +3694,8 @@ static int in6_dump_addrs(struct inet6_d
25334                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25335                         if (++ip_idx < s_ip_idx)
25336                                 continue;
25337 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25338 +                                       continue;
25339                         err = inet6_fill_ifaddr(skb, ifa,
25340                                                 NETLINK_CB(cb->skb).pid,
25341                                                 cb->nlh->nlmsg_seq,
25342 @@ -3698,6 +3712,8 @@ static int in6_dump_addrs(struct inet6_d
25343                      ifmca = ifmca->next, ip_idx++) {
25344                         if (ip_idx < s_ip_idx)
25345                                 continue;
25346 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25347 +                                       continue;
25348                         err = inet6_fill_ifmcaddr(skb, ifmca,
25349                                                   NETLINK_CB(cb->skb).pid,
25350                                                   cb->nlh->nlmsg_seq,
25351 @@ -3713,6 +3729,8 @@ static int in6_dump_addrs(struct inet6_d
25352                      ifaca = ifaca->aca_next, ip_idx++) {
25353                         if (ip_idx < s_ip_idx)
25354                                 continue;
25355 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25356 +                                       continue;
25357                         err = inet6_fill_ifacaddr(skb, ifaca,
25358                                                   NETLINK_CB(cb->skb).pid,
25359                                                   cb->nlh->nlmsg_seq,
25360 @@ -4098,6 +4116,11 @@ static int inet6_dump_ifinfo(struct sk_b
25361         struct inet6_dev *idev;
25362         struct hlist_head *head;
25363         struct hlist_node *node;
25364 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25365 +
25366 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25367 +       if (skb->sk && skb->sk->sk_vx_info)
25368 +               return skb->len; */
25369  
25370         s_h = cb->args[0];
25371         s_idx = cb->args[1];
25372 @@ -4109,6 +4132,8 @@ static int inet6_dump_ifinfo(struct sk_b
25373                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25374                         if (idx < s_idx)
25375                                 goto cont;
25376 +                       if (!v6_dev_in_nx_info(dev, nxi))
25377 +                               goto cont;
25378                         idev = __in6_dev_get(dev);
25379                         if (!idev)
25380                                 goto cont;
25381 diff -NurpP --minimal linux-3.4.32/net/ipv6/af_inet6.c linux-3.4.32-vs2.3.3.9/net/ipv6/af_inet6.c
25382 --- linux-3.4.32/net/ipv6/af_inet6.c    2012-05-21 16:07:40.000000000 +0000
25383 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/af_inet6.c  2012-09-01 09:15:04.000000000 +0000
25384 @@ -42,6 +42,8 @@
25385  #include <linux/netdevice.h>
25386  #include <linux/icmpv6.h>
25387  #include <linux/netfilter_ipv6.h>
25388 +#include <linux/vs_inet.h>
25389 +#include <linux/vs_inet6.h>
25390  
25391  #include <net/ip.h>
25392  #include <net/ipv6.h>
25393 @@ -159,9 +161,12 @@ lookup_protocol:
25394         }
25395  
25396         err = -EPERM;
25397 +       if ((protocol == IPPROTO_ICMPV6) &&
25398 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25399 +               goto override;
25400         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25401                 goto out_rcu_unlock;
25402 -
25403 +override:
25404         sock->ops = answer->ops;
25405         answer_prot = answer->prot;
25406         answer_no_check = answer->no_check;
25407 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25408         struct inet_sock *inet = inet_sk(sk);
25409         struct ipv6_pinfo *np = inet6_sk(sk);
25410         struct net *net = sock_net(sk);
25411 +       struct nx_v6_sock_addr nsa;
25412         __be32 v4addr = 0;
25413         unsigned short snum;
25414         int addr_type = 0;
25415 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25416         if (addr->sin6_family != AF_INET6)
25417                 return -EAFNOSUPPORT;
25418  
25419 +       err = v6_map_sock_addr(inet, addr, &nsa);
25420 +       if (err)
25421 +               return err;
25422 +
25423         addr_type = ipv6_addr_type(&addr->sin6_addr);
25424         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25425                 return -EINVAL;
25426 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25427                 /* Reproduce AF_INET checks to make the bindings consistent */
25428                 v4addr = addr->sin6_addr.s6_addr32[3];
25429                 chk_addr_ret = inet_addr_type(net, v4addr);
25430 +
25431                 if (!sysctl_ip_nonlocal_bind &&
25432                     !(inet->freebind || inet->transparent) &&
25433                     v4addr != htonl(INADDR_ANY) &&
25434 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25435                         err = -EADDRNOTAVAIL;
25436                         goto out;
25437                 }
25438 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25439 +                       err = -EADDRNOTAVAIL;
25440 +                       goto out;
25441 +               }
25442         } else {
25443                 if (addr_type != IPV6_ADDR_ANY) {
25444                         struct net_device *dev = NULL;
25445 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25446                                 }
25447                         }
25448  
25449 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25450 +                               err = -EADDRNOTAVAIL;
25451 +                               goto out_unlock;
25452 +                       }
25453 +
25454                         /* ipv4 addr of the socket is invalid.  Only the
25455                          * unspecified and mapped address have a v4 equivalent.
25456                          */
25457 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25458                 }
25459         }
25460  
25461 +       /* what's that for? */
25462 +       v6_set_sock_addr(inet, &nsa);
25463 +
25464         inet->inet_rcv_saddr = v4addr;
25465         inet->inet_saddr = v4addr;
25466  
25467 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25468                         return -ENOTCONN;
25469                 sin->sin6_port = inet->inet_dport;
25470                 sin->sin6_addr = np->daddr;
25471 +               /* FIXME: remap lback? */
25472                 if (np->sndflow)
25473                         sin->sin6_flowinfo = np->flow_label;
25474         } else {
25475 +               /* FIXME: remap lback? */
25476                 if (ipv6_addr_any(&np->rcv_saddr))
25477                         sin->sin6_addr = np->saddr;
25478                 else
25479 diff -NurpP --minimal linux-3.4.32/net/ipv6/datagram.c linux-3.4.32-vs2.3.3.9/net/ipv6/datagram.c
25480 --- linux-3.4.32/net/ipv6/datagram.c    2012-05-21 16:07:40.000000000 +0000
25481 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/datagram.c  2012-05-21 16:15:05.000000000 +0000
25482 @@ -642,7 +642,7 @@ int datagram_send_ctl(struct net *net, s
25483  
25484                         rcu_read_lock();
25485                         if (fl6->flowi6_oif) {
25486 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25487 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25488                                 if (!dev) {
25489                                         rcu_read_unlock();
25490                                         return -ENODEV;
25491 diff -NurpP --minimal linux-3.4.32/net/ipv6/fib6_rules.c linux-3.4.32-vs2.3.3.9/net/ipv6/fib6_rules.c
25492 --- linux-3.4.32/net/ipv6/fib6_rules.c  2012-03-19 18:47:33.000000000 +0000
25493 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/fib6_rules.c        2012-05-21 16:15:05.000000000 +0000
25494 @@ -91,7 +91,7 @@ static int fib6_rule_action(struct fib_r
25495                                                ip6_dst_idev(&rt->dst)->dev,
25496                                                &flp6->daddr,
25497                                                rt6_flags2srcprefs(flags),
25498 -                                              &saddr))
25499 +                                              &saddr, NULL))
25500                                 goto again;
25501                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25502                                                r->src.plen))
25503 diff -NurpP --minimal linux-3.4.32/net/ipv6/inet6_hashtables.c linux-3.4.32-vs2.3.3.9/net/ipv6/inet6_hashtables.c
25504 --- linux-3.4.32/net/ipv6/inet6_hashtables.c    2011-10-24 16:45:34.000000000 +0000
25505 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/inet6_hashtables.c  2012-05-21 16:15:05.000000000 +0000
25506 @@ -16,6 +16,7 @@
25507  
25508  #include <linux/module.h>
25509  #include <linux/random.h>
25510 +#include <linux/vs_inet6.h>
25511  
25512  #include <net/inet_connection_sock.h>
25513  #include <net/inet_hashtables.h>
25514 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25515         unsigned int slot = hash & hashinfo->ehash_mask;
25516         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25517  
25518 -
25519         rcu_read_lock();
25520  begin:
25521         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25522 @@ -95,7 +95,7 @@ begin:
25523                                 sock_put(sk);
25524                                 goto begin;
25525                         }
25526 -               goto out;
25527 +                       goto out;
25528                 }
25529         }
25530         if (get_nulls_value(node) != slot)
25531 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25532                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25533                                 return -1;
25534                         score++;
25535 +               } else {
25536 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25537 +                               return -1;
25538                 }
25539                 if (sk->sk_bound_dev_if) {
25540                         if (sk->sk_bound_dev_if != dif)
25541 diff -NurpP --minimal linux-3.4.32/net/ipv6/ip6_output.c linux-3.4.32-vs2.3.3.9/net/ipv6/ip6_output.c
25542 --- linux-3.4.32/net/ipv6/ip6_output.c  2013-02-19 13:56:17.000000000 +0000
25543 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/ip6_output.c        2013-02-19 14:42:56.000000000 +0000
25544 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25545                 struct rt6_info *rt = (struct rt6_info *) *dst;
25546                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25547                                           sk ? inet6_sk(sk)->srcprefs : 0,
25548 -                                         &fl6->saddr);
25549 +                                         &fl6->saddr,
25550 +                                         sk ? sk->sk_nx_info : NULL);
25551                 if (err)
25552                         goto out_err_release;
25553         }
25554 diff -NurpP --minimal linux-3.4.32/net/ipv6/ndisc.c linux-3.4.32-vs2.3.3.9/net/ipv6/ndisc.c
25555 --- linux-3.4.32/net/ipv6/ndisc.c       2013-02-19 13:56:17.000000000 +0000
25556 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/ndisc.c     2012-11-18 23:52:30.000000000 +0000
25557 @@ -575,7 +575,7 @@ static void ndisc_send_na(struct net_dev
25558         } else {
25559                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25560                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25561 -                                      &tmpaddr))
25562 +                                      &tmpaddr, NULL))
25563                         return;
25564                 src_addr = &tmpaddr;
25565         }
25566 diff -NurpP --minimal linux-3.4.32/net/ipv6/raw.c linux-3.4.32-vs2.3.3.9/net/ipv6/raw.c
25567 --- linux-3.4.32/net/ipv6/raw.c 2013-02-19 13:56:17.000000000 +0000
25568 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/raw.c       2012-10-22 13:09:53.000000000 +0000
25569 @@ -30,6 +30,7 @@
25570  #include <linux/icmpv6.h>
25571  #include <linux/netfilter.h>
25572  #include <linux/netfilter_ipv6.h>
25573 +#include <linux/vs_inet6.h>
25574  #include <linux/skbuff.h>
25575  #include <linux/compat.h>
25576  #include <asm/uaccess.h>
25577 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25578                                 goto out_unlock;
25579                 }
25580  
25581 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25582 +                       err = -EADDRNOTAVAIL;
25583 +                       if (dev)
25584 +                               dev_put(dev);
25585 +                       goto out;
25586 +               }
25587 +
25588                 /* ipv4 addr of the socket is invalid.  Only the
25589                  * unspecified and mapped address have a v4 equivalent.
25590                  */
25591 diff -NurpP --minimal linux-3.4.32/net/ipv6/route.c linux-3.4.32-vs2.3.3.9/net/ipv6/route.c
25592 --- linux-3.4.32/net/ipv6/route.c       2013-02-19 13:56:17.000000000 +0000
25593 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/route.c     2013-02-19 14:42:56.000000000 +0000
25594 @@ -55,6 +55,7 @@
25595  #include <net/xfrm.h>
25596  #include <net/netevent.h>
25597  #include <net/netlink.h>
25598 +#include <linux/vs_inet6.h>
25599  
25600  #include <asm/uaccess.h>
25601  
25602 @@ -2146,15 +2147,17 @@ int ip6_route_get_saddr(struct net *net,
25603                         struct rt6_info *rt,
25604                         const struct in6_addr *daddr,
25605                         unsigned int prefs,
25606 -                       struct in6_addr *saddr)
25607 +                       struct in6_addr *saddr,
25608 +                       struct nx_info *nxi)
25609  {
25610         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25611         int err = 0;
25612 -       if (rt->rt6i_prefsrc.plen)
25613 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25614 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25615                 *saddr = rt->rt6i_prefsrc.addr;
25616         else
25617                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25618 -                                        daddr, prefs, saddr);
25619 +                                        daddr, prefs, saddr, nxi);
25620         return err;
25621  }
25622  
25623 @@ -2485,7 +2488,8 @@ static int rt6_fill_node(struct net *net
25624                         NLA_PUT_U32(skb, RTA_IIF, iif);
25625         } else if (dst) {
25626                 struct in6_addr saddr_buf;
25627 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25628 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25629 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25630                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25631         }
25632  
25633 @@ -2712,6 +2716,7 @@ static int rt6_info_route(struct rt6_inf
25634         struct seq_file *m = p_arg;
25635         struct neighbour *n;
25636  
25637 +       /* FIXME: check for network context? */
25638         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25639  
25640  #ifdef CONFIG_IPV6_SUBTREES
25641 diff -NurpP --minimal linux-3.4.32/net/ipv6/tcp_ipv6.c linux-3.4.32-vs2.3.3.9/net/ipv6/tcp_ipv6.c
25642 --- linux-3.4.32/net/ipv6/tcp_ipv6.c    2013-02-19 13:56:17.000000000 +0000
25643 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/tcp_ipv6.c  2013-01-16 00:15:57.000000000 +0000
25644 @@ -71,6 +71,7 @@
25645  
25646  #include <linux/crypto.h>
25647  #include <linux/scatterlist.h>
25648 +#include <linux/vs_inet6.h>
25649  
25650  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25651  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25652 @@ -163,8 +164,15 @@ static int tcp_v6_connect(struct sock *s
25653          *      connect() to INADDR_ANY means loopback (BSD'ism).
25654          */
25655  
25656 -       if(ipv6_addr_any(&usin->sin6_addr))
25657 -               usin->sin6_addr.s6_addr[15] = 0x1;
25658 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25659 +               struct nx_info *nxi =  sk->sk_nx_info;
25660 +
25661 +               if (nxi && nx_info_has_v6(nxi))
25662 +                       /* FIXME: remap lback? */
25663 +                       usin->sin6_addr = nxi->v6.ip;
25664 +               else
25665 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25666 +       }
25667  
25668         addr_type = ipv6_addr_type(&usin->sin6_addr);
25669  
25670 diff -NurpP --minimal linux-3.4.32/net/ipv6/udp.c linux-3.4.32-vs2.3.3.9/net/ipv6/udp.c
25671 --- linux-3.4.32/net/ipv6/udp.c 2012-05-21 16:07:40.000000000 +0000
25672 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/udp.c       2012-05-21 16:15:05.000000000 +0000
25673 @@ -45,41 +45,67 @@
25674  #include <net/tcp_states.h>
25675  #include <net/ip6_checksum.h>
25676  #include <net/xfrm.h>
25677 +#include <linux/vs_inet6.h>
25678  
25679  #include <linux/proc_fs.h>
25680  #include <linux/seq_file.h>
25681  #include "udp_impl.h"
25682  
25683 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25684 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25685  {
25686 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25687 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25688         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25689 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25690 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25691         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25692 -       int sk_ipv6only = ipv6_only_sock(sk);
25693 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25694         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25695 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25696 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25697         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25698  
25699         /* if both are mapped, treat as IPv4 */
25700 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25701 -               return (!sk2_ipv6only &&
25702 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25703 +               if (!sk2_ipv6only &&
25704                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25705 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25706 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25707 +                       goto vs_v4;
25708 +               else
25709 +                       return 0;
25710 +       }
25711  
25712         if (addr_type2 == IPV6_ADDR_ANY &&
25713             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25714 -               return 1;
25715 +               goto vs;
25716  
25717         if (addr_type == IPV6_ADDR_ANY &&
25718 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25719 -               return 1;
25720 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25721 +               goto vs;
25722  
25723         if (sk2_rcv_saddr6 &&
25724 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25725 -               return 1;
25726 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25727 +               goto vs;
25728  
25729         return 0;
25730 +
25731 +vs_v4:
25732 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25733 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25734 +       if (!sk2_rcv_saddr)
25735 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25736 +       if (!sk1_rcv_saddr)
25737 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25738 +       return 1;
25739 +vs:
25740 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25741 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25742 +       else if (addr_type2 == IPV6_ADDR_ANY)
25743 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25744 +       else if (addr_type == IPV6_ADDR_ANY) {
25745 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25746 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25747 +               else
25748 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25749 +       }
25750 +       return 1;
25751  }
25752  
25753  static unsigned int udp6_portaddr_hash(struct net *net,
25754 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25755                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25756                                 return -1;
25757                         score++;
25758 +               } else {
25759 +                       /* block non nx_info ips */
25760 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25761 +                               return -1;
25762                 }
25763                 if (!ipv6_addr_any(&np->daddr)) {
25764                         if (!ipv6_addr_equal(&np->daddr, saddr))
25765 diff -NurpP --minimal linux-3.4.32/net/ipv6/xfrm6_policy.c linux-3.4.32-vs2.3.3.9/net/ipv6/xfrm6_policy.c
25766 --- linux-3.4.32/net/ipv6/xfrm6_policy.c        2012-03-19 18:47:33.000000000 +0000
25767 +++ linux-3.4.32-vs2.3.3.9/net/ipv6/xfrm6_policy.c      2012-05-21 16:15:05.000000000 +0000
25768 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25769         dev = ip6_dst_idev(dst)->dev;
25770         ipv6_dev_get_saddr(dev_net(dev), dev,
25771                            (struct in6_addr *)&daddr->a6, 0,
25772 -                          (struct in6_addr *)&saddr->a6);
25773 +                          (struct in6_addr *)&saddr->a6, NULL);
25774         dst_release(dst);
25775         return 0;
25776  }
25777 diff -NurpP --minimal linux-3.4.32/net/netfilter/ipvs/ip_vs_xmit.c linux-3.4.32-vs2.3.3.9/net/netfilter/ipvs/ip_vs_xmit.c
25778 --- linux-3.4.32/net/netfilter/ipvs/ip_vs_xmit.c        2012-03-19 18:47:33.000000000 +0000
25779 +++ linux-3.4.32-vs2.3.3.9/net/netfilter/ipvs/ip_vs_xmit.c      2012-05-21 16:15:05.000000000 +0000
25780 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25781                 return dst;
25782         if (ipv6_addr_any(&fl6.saddr) &&
25783             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25784 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25785 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25786                 goto out_err;
25787         if (do_xfrm) {
25788                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25789 diff -NurpP --minimal linux-3.4.32/net/netlink/af_netlink.c linux-3.4.32-vs2.3.3.9/net/netlink/af_netlink.c
25790 --- linux-3.4.32/net/netlink/af_netlink.c       2013-02-19 13:56:18.000000000 +0000
25791 +++ linux-3.4.32-vs2.3.3.9/net/netlink/af_netlink.c     2012-11-18 23:52:30.000000000 +0000
25792 @@ -55,6 +55,9 @@
25793  #include <linux/types.h>
25794  #include <linux/audit.h>
25795  #include <linux/mutex.h>
25796 +#include <linux/vs_context.h>
25797 +#include <linux/vs_network.h>
25798 +#include <linux/vs_limit.h>
25799  
25800  #include <net/net_namespace.h>
25801  #include <net/sock.h>
25802 @@ -1951,6 +1954,8 @@ static struct sock *netlink_seq_socket_i
25803                         sk_for_each(s, node, &hash->table[j]) {
25804                                 if (sock_net(s) != seq_file_net(seq))
25805                                         continue;
25806 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25807 +                                       continue;
25808                                 if (off == pos) {
25809                                         iter->link = i;
25810                                         iter->hash_idx = j;
25811 @@ -1985,7 +1990,8 @@ static void *netlink_seq_next(struct seq
25812         s = v;
25813         do {
25814                 s = sk_next(s);
25815 -       } while (s && sock_net(s) != seq_file_net(seq));
25816 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25817 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25818         if (s)
25819                 return s;
25820  
25821 @@ -1997,7 +2003,8 @@ static void *netlink_seq_next(struct seq
25822  
25823                 for (; j <= hash->mask; j++) {
25824                         s = sk_head(&hash->table[j]);
25825 -                       while (s && sock_net(s) != seq_file_net(seq))
25826 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25827 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25828                                 s = sk_next(s);
25829                         if (s) {
25830                                 iter->link = i;
25831 diff -NurpP --minimal linux-3.4.32/net/socket.c linux-3.4.32-vs2.3.3.9/net/socket.c
25832 --- linux-3.4.32/net/socket.c   2013-02-19 13:56:19.000000000 +0000
25833 +++ linux-3.4.32-vs2.3.3.9/net/socket.c 2012-10-22 13:09:53.000000000 +0000
25834 @@ -98,6 +98,10 @@
25835  
25836  #include <net/sock.h>
25837  #include <linux/netfilter.h>
25838 +#include <linux/vs_base.h>
25839 +#include <linux/vs_socket.h>
25840 +#include <linux/vs_inet.h>
25841 +#include <linux/vs_inet6.h>
25842  
25843  #include <linux/if_tun.h>
25844  #include <linux/ipv6_route.h>
25845 @@ -551,6 +555,7 @@ static inline int __sock_sendmsg_nosec(s
25846                                        struct msghdr *msg, size_t size)
25847  {
25848         struct sock_iocb *si = kiocb_to_siocb(iocb);
25849 +       size_t len;
25850  
25851         sock_update_classid(sock->sk);
25852  
25853 @@ -561,7 +566,22 @@ static inline int __sock_sendmsg_nosec(s
25854         si->msg = msg;
25855         si->size = size;
25856  
25857 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25858 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25859 +       if (sock->sk) {
25860 +               if (len == size)
25861 +                       vx_sock_send(sock->sk, size);
25862 +               else
25863 +                       vx_sock_fail(sock->sk, size);
25864 +       }
25865 +       vxdprintk(VXD_CBIT(net, 7),
25866 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25867 +               sock, sock->sk,
25868 +               (sock->sk)?sock->sk->sk_nx_info:0,
25869 +               (sock->sk)?sock->sk->sk_vx_info:0,
25870 +               (sock->sk)?sock->sk->sk_xid:0,
25871 +               (sock->sk)?sock->sk->sk_nid:0,
25872 +               (unsigned int)size, len);
25873 +       return len;
25874  }
25875  
25876  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25877 @@ -717,6 +737,7 @@ static inline int __sock_recvmsg_nosec(s
25878                                        struct msghdr *msg, size_t size, int flags)
25879  {
25880         struct sock_iocb *si = kiocb_to_siocb(iocb);
25881 +       int len;
25882  
25883         sock_update_classid(sock->sk);
25884  
25885 @@ -726,7 +747,18 @@ static inline int __sock_recvmsg_nosec(s
25886         si->size = size;
25887         si->flags = flags;
25888  
25889 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25890 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25891 +       if ((len >= 0) && sock->sk)
25892 +               vx_sock_recv(sock->sk, len);
25893 +       vxdprintk(VXD_CBIT(net, 7),
25894 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25895 +               sock, sock->sk,
25896 +               (sock->sk)?sock->sk->sk_nx_info:0,
25897 +               (sock->sk)?sock->sk->sk_vx_info:0,
25898 +               (sock->sk)?sock->sk->sk_xid:0,
25899 +               (sock->sk)?sock->sk->sk_nid:0,
25900 +               (unsigned int)size, len);
25901 +       return len;
25902  }
25903  
25904  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25905 @@ -1211,6 +1243,13 @@ int __sock_create(struct net *net, int f
25906         if (type < 0 || type >= SOCK_MAX)
25907                 return -EINVAL;
25908  
25909 +       if (!nx_check(0, VS_ADMIN)) {
25910 +               if (family == PF_INET && !current_nx_info_has_v4())
25911 +                       return -EAFNOSUPPORT;
25912 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25913 +                       return -EAFNOSUPPORT;
25914 +       }
25915 +
25916         /* Compatibility.
25917  
25918            This uglymoron is moved from INET layer to here to avoid
25919 @@ -1346,6 +1385,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25920         if (retval < 0)
25921                 goto out;
25922  
25923 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25924         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25925         if (retval < 0)
25926                 goto out_release;
25927 @@ -1387,10 +1427,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25928         err = sock_create(family, type, protocol, &sock1);
25929         if (err < 0)
25930                 goto out;
25931 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25932  
25933         err = sock_create(family, type, protocol, &sock2);
25934         if (err < 0)
25935                 goto out_release_1;
25936 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25937  
25938         err = sock1->ops->socketpair(sock1, sock2);
25939         if (err < 0)
25940 diff -NurpP --minimal linux-3.4.32/net/sunrpc/auth.c linux-3.4.32-vs2.3.3.9/net/sunrpc/auth.c
25941 --- linux-3.4.32/net/sunrpc/auth.c      2011-10-24 16:45:34.000000000 +0000
25942 +++ linux-3.4.32-vs2.3.3.9/net/sunrpc/auth.c    2012-05-21 16:15:05.000000000 +0000
25943 @@ -14,6 +14,7 @@
25944  #include <linux/hash.h>
25945  #include <linux/sunrpc/clnt.h>
25946  #include <linux/spinlock.h>
25947 +#include <linux/vs_tag.h>
25948  
25949  #ifdef RPC_DEBUG
25950  # define RPCDBG_FACILITY       RPCDBG_AUTH
25951 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25952         memset(&acred, 0, sizeof(acred));
25953         acred.uid = cred->fsuid;
25954         acred.gid = cred->fsgid;
25955 +       acred.tag = dx_current_tag();
25956         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25957  
25958         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25959 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25960         struct auth_cred acred = {
25961                 .uid = 0,
25962                 .gid = 0,
25963 +               .tag = dx_current_tag(),
25964         };
25965  
25966         dprintk("RPC: %5u looking up %s cred\n",
25967 diff -NurpP --minimal linux-3.4.32/net/sunrpc/auth_unix.c linux-3.4.32-vs2.3.3.9/net/sunrpc/auth_unix.c
25968 --- linux-3.4.32/net/sunrpc/auth_unix.c 2012-01-09 15:15:04.000000000 +0000
25969 +++ linux-3.4.32-vs2.3.3.9/net/sunrpc/auth_unix.c       2012-05-21 16:15:05.000000000 +0000
25970 @@ -12,12 +12,14 @@
25971  #include <linux/module.h>
25972  #include <linux/sunrpc/clnt.h>
25973  #include <linux/sunrpc/auth.h>
25974 +#include <linux/vs_tag.h>
25975  
25976  #define NFS_NGROUPS    16
25977  
25978  struct unx_cred {
25979         struct rpc_cred         uc_base;
25980         gid_t                   uc_gid;
25981 +       tag_t                   uc_tag;
25982         gid_t                   uc_gids[NFS_NGROUPS];
25983  };
25984  #define uc_uid                 uc_base.cr_uid
25985 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
25986                 groups = NFS_NGROUPS;
25987  
25988         cred->uc_gid = acred->gid;
25989 +       cred->uc_tag = acred->tag;
25990         for (i = 0; i < groups; i++)
25991                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25992         if (i < NFS_NGROUPS)
25993 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
25994         unsigned int i;
25995  
25996  
25997 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25998 +       if (cred->uc_uid != acred->uid ||
25999 +               cred->uc_gid != acred->gid ||
26000 +               cred->uc_tag != acred->tag)
26001                 return 0;
26002  
26003         if (acred->group_info != NULL)
26004 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
26005         struct rpc_clnt *clnt = task->tk_client;
26006         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26007         __be32          *base, *hold;
26008 -       int             i;
26009 +       int             i, tag;
26010  
26011         *p++ = htonl(RPC_AUTH_UNIX);
26012         base = p++;
26013 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
26014          * Copy the UTS nodename captured when the client was created.
26015          */
26016         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26017 +       tag = task->tk_client->cl_tag;
26018  
26019 -       *p++ = htonl((u32) cred->uc_uid);
26020 -       *p++ = htonl((u32) cred->uc_gid);
26021 +       *p++ = htonl((u32) TAGINO_UID(tag,
26022 +               cred->uc_uid, cred->uc_tag));
26023 +       *p++ = htonl((u32) TAGINO_GID(tag,
26024 +               cred->uc_gid, cred->uc_tag));
26025         hold = p++;
26026         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26027                 *p++ = htonl((u32) cred->uc_gids[i]);
26028 diff -NurpP --minimal linux-3.4.32/net/sunrpc/clnt.c linux-3.4.32-vs2.3.3.9/net/sunrpc/clnt.c
26029 --- linux-3.4.32/net/sunrpc/clnt.c      2013-02-19 13:56:22.000000000 +0000
26030 +++ linux-3.4.32-vs2.3.3.9/net/sunrpc/clnt.c    2013-02-11 23:37:30.000000000 +0000
26031 @@ -31,6 +31,7 @@
26032  #include <linux/in6.h>
26033  #include <linux/un.h>
26034  #include <linux/rcupdate.h>
26035 +#include <linux/vs_cvirt.h>
26036  
26037  #include <linux/sunrpc/clnt.h>
26038  #include <linux/sunrpc/rpc_pipe_fs.h>
26039 @@ -483,6 +484,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26040         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26041                 clnt->cl_chatty = 1;
26042  
26043 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26044 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26045 +               clnt->cl_tag = 1; */
26046         return clnt;
26047  }
26048  EXPORT_SYMBOL_GPL(rpc_create);
26049 diff -NurpP --minimal linux-3.4.32/net/unix/af_unix.c linux-3.4.32-vs2.3.3.9/net/unix/af_unix.c
26050 --- linux-3.4.32/net/unix/af_unix.c     2013-02-19 13:56:23.000000000 +0000
26051 +++ linux-3.4.32-vs2.3.3.9/net/unix/af_unix.c   2012-10-22 13:09:53.000000000 +0000
26052 @@ -114,6 +114,8 @@
26053  #include <linux/mount.h>
26054  #include <net/checksum.h>
26055  #include <linux/security.h>
26056 +#include <linux/vs_context.h>
26057 +#include <linux/vs_limit.h>
26058  
26059  struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26060  EXPORT_SYMBOL_GPL(unix_socket_table);
26061 @@ -261,6 +263,8 @@ static struct sock *__unix_find_socket_b
26062                 if (!net_eq(sock_net(s), net))
26063                         continue;
26064  
26065 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26066 +                       continue;
26067                 if (u->addr->len == len &&
26068                     !memcmp(u->addr->name, sunname, len))
26069                         goto found;
26070 @@ -2266,6 +2270,8 @@ static struct sock *unix_seq_idx(struct
26071         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26072                 if (sock_net(s) != seq_file_net(seq))
26073                         continue;
26074 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26075 +                       continue;
26076                 if (off == pos)
26077                         return s;
26078                 ++off;
26079 @@ -2290,7 +2296,8 @@ static void *unix_seq_next(struct seq_fi
26080                 sk = first_unix_socket(&iter->i);
26081         else
26082                 sk = next_unix_socket(&iter->i, sk);
26083 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26084 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26085 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26086                 sk = next_unix_socket(&iter->i, sk);
26087         return sk;
26088  }
26089 diff -NurpP --minimal linux-3.4.32/scripts/checksyscalls.sh linux-3.4.32-vs2.3.3.9/scripts/checksyscalls.sh
26090 --- linux-3.4.32/scripts/checksyscalls.sh       2012-03-19 18:47:34.000000000 +0000
26091 +++ linux-3.4.32-vs2.3.3.9/scripts/checksyscalls.sh     2012-05-21 16:15:05.000000000 +0000
26092 @@ -193,7 +193,6 @@ cat << EOF
26093  #define __IGNORE_afs_syscall
26094  #define __IGNORE_getpmsg
26095  #define __IGNORE_putpmsg
26096 -#define __IGNORE_vserver
26097  EOF
26098  }
26099  
26100 diff -NurpP --minimal linux-3.4.32/security/commoncap.c linux-3.4.32-vs2.3.3.9/security/commoncap.c
26101 --- linux-3.4.32/security/commoncap.c   2012-05-21 16:07:41.000000000 +0000
26102 +++ linux-3.4.32-vs2.3.3.9/security/commoncap.c 2012-05-21 16:15:05.000000000 +0000
26103 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
26104  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26105                 int cap, int audit)
26106  {
26107 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26108 +
26109         for (;;) {
26110                 /* The creator of the user namespace has all caps. */
26111                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
26112                         return 0;
26113  
26114                 /* Do we have the necessary capabilities? */
26115 -               if (targ_ns == cred->user->user_ns)
26116 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26117 +               if (targ_ns == cred->user->user_ns) {
26118 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26119 +                           cap_raised(cred->cap_effective, cap))
26120 +                               return 0;
26121 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26122 +               }
26123  
26124                 /* Have we tried all of the parent namespaces? */
26125                 if (targ_ns == &init_user_ns)
26126 @@ -612,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
26127  
26128         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26129                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26130 -           !capable(CAP_SYS_ADMIN))
26131 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26132                 return -EPERM;
26133         return 0;
26134  }
26135 @@ -638,7 +644,7 @@ int cap_inode_removexattr(struct dentry
26136  
26137         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26138                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26139 -           !capable(CAP_SYS_ADMIN))
26140 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26141                 return -EPERM;
26142         return 0;
26143  }
26144 diff -NurpP --minimal linux-3.4.32/security/selinux/hooks.c linux-3.4.32-vs2.3.3.9/security/selinux/hooks.c
26145 --- linux-3.4.32/security/selinux/hooks.c       2013-02-19 13:56:23.000000000 +0000
26146 +++ linux-3.4.32-vs2.3.3.9/security/selinux/hooks.c     2012-09-01 08:50:49.000000000 +0000
26147 @@ -66,7 +66,6 @@
26148  #include <linux/dccp.h>
26149  #include <linux/quota.h>
26150  #include <linux/un.h>          /* for Unix socket types */
26151 -#include <net/af_unix.h>       /* for Unix socket types */
26152  #include <linux/parser.h>
26153  #include <linux/nfs_mount.h>
26154  #include <net/ipv6.h>
This page took 1.967547 seconds and 3 git commands to generate.