]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.5.5
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.5.4/Documentation/vserver/debug.txt linux-3.5.4-vs2.3.4.3/Documentation/vserver/debug.txt
2 --- linux-3.5.4/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.5.4-vs2.3.4.3/Documentation/vserver/debug.txt       2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/alpha/Kconfig linux-3.5.4-vs2.3.4.3/arch/alpha/Kconfig
160 --- linux-3.5.4/arch/alpha/Kconfig      2012-07-22 23:38:45.000000000 +0200
161 +++ linux-3.5.4-vs2.3.4.3/arch/alpha/Kconfig    2012-07-23 01:45:55.000000000 +0200
162 @@ -661,6 +661,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.5.4/arch/alpha/kernel/entry.S linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/entry.S
172 --- linux-3.5.4/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/entry.S     2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/alpha/kernel/ptrace.c linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/ptrace.c
207 --- linux-3.5.4/arch/alpha/kernel/ptrace.c      2012-05-21 18:06:12.000000000 +0200
208 +++ linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/ptrace.c    2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/alpha/kernel/systbls.S linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/systbls.S
218 --- linux-3.5.4/arch/alpha/kernel/systbls.S     2012-07-22 23:38:45.000000000 +0200
219 +++ linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/systbls.S   2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/alpha/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/traps.c
230 --- linux-3.5.4/arch/alpha/kernel/traps.c       2012-05-21 18:06:12.000000000 +0200
231 +++ linux-3.5.4-vs2.3.4.3/arch/alpha/kernel/traps.c     2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/arm/Kconfig linux-3.5.4-vs2.3.4.3/arch/arm/Kconfig
243 --- linux-3.5.4/arch/arm/Kconfig        2012-09-16 20:46:29.000000000 +0200
244 +++ linux-3.5.4-vs2.3.4.3/arch/arm/Kconfig      2012-09-16 20:50:19.000000000 +0200
245 @@ -2270,6 +2270,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.5.4/arch/arm/kernel/calls.S linux-3.5.4-vs2.3.4.3/arch/arm/kernel/calls.S
255 --- linux-3.5.4/arch/arm/kernel/calls.S 2012-01-09 16:13:54.000000000 +0100
256 +++ linux-3.5.4-vs2.3.4.3/arch/arm/kernel/calls.S       2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/arm/kernel/process.c linux-3.5.4-vs2.3.4.3/arch/arm/kernel/process.c
267 --- linux-3.5.4/arch/arm/kernel/process.c       2012-09-16 20:46:29.000000000 +0200
268 +++ linux-3.5.4-vs2.3.4.3/arch/arm/kernel/process.c     2012-08-19 13:28:27.000000000 +0200
269 @@ -337,7 +337,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.5.4/arch/arm/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/arm/kernel/traps.c
280 --- linux-3.5.4/arch/arm/kernel/traps.c 2012-09-16 20:46:29.000000000 +0200
281 +++ linux-3.5.4-vs2.3.4.3/arch/arm/kernel/traps.c       2012-08-19 13:28:27.000000000 +0200
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.5.4/arch/cris/Kconfig linux-3.5.4-vs2.3.4.3/arch/cris/Kconfig
294 --- linux-3.5.4/arch/cris/Kconfig       2012-07-22 23:38:50.000000000 +0200
295 +++ linux-3.5.4-vs2.3.4.3/arch/cris/Kconfig     2012-07-23 01:45:55.000000000 +0200
296 @@ -672,6 +672,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.5.4/arch/frv/kernel/kernel_thread.S linux-3.5.4-vs2.3.4.3/arch/frv/kernel/kernel_thread.S
306 --- linux-3.5.4/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.5.4-vs2.3.4.3/arch/frv/kernel/kernel_thread.S       2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/h8300/Kconfig linux-3.5.4-vs2.3.4.3/arch/h8300/Kconfig
318 --- linux-3.5.4/arch/h8300/Kconfig      2012-03-19 19:46:39.000000000 +0100
319 +++ linux-3.5.4-vs2.3.4.3/arch/h8300/Kconfig    2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/ia64/Kconfig linux-3.5.4-vs2.3.4.3/arch/ia64/Kconfig
330 --- linux-3.5.4/arch/ia64/Kconfig       2012-07-22 23:38:50.000000000 +0200
331 +++ linux-3.5.4-vs2.3.4.3/arch/ia64/Kconfig     2012-07-23 01:45:55.000000000 +0200
332 @@ -653,6 +653,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.5.4/arch/ia64/kernel/entry.S linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/entry.S
342 --- linux-3.5.4/arch/ia64/kernel/entry.S        2012-03-19 19:46:40.000000000 +0100
343 +++ linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/entry.S      2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/ia64/kernel/process.c linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/process.c
354 --- linux-3.5.4/arch/ia64/kernel/process.c      2012-07-22 23:38:51.000000000 +0200
355 +++ linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/process.c    2012-07-23 01:45:55.000000000 +0200
356 @@ -110,8 +110,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.5.4/arch/ia64/kernel/ptrace.c linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/ptrace.c
368 --- linux-3.5.4/arch/ia64/kernel/ptrace.c       2012-05-21 18:06:26.000000000 +0200
369 +++ linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/ptrace.c     2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/ia64/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/traps.c
379 --- linux-3.5.4/arch/ia64/kernel/traps.c        2012-05-21 18:06:26.000000000 +0200
380 +++ linux-3.5.4-vs2.3.4.3/arch/ia64/kernel/traps.c      2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/m32r/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/m32r/kernel/traps.c
406 --- linux-3.5.4/arch/m32r/kernel/traps.c        2012-05-21 18:06:26.000000000 +0200
407 +++ linux-3.5.4-vs2.3.4.3/arch/m32r/kernel/traps.c      2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/m68k/Kconfig linux-3.5.4-vs2.3.4.3/arch/m68k/Kconfig
421 --- linux-3.5.4/arch/m68k/Kconfig       2012-07-22 23:38:51.000000000 +0200
422 +++ linux-3.5.4-vs2.3.4.3/arch/m68k/Kconfig     2012-07-23 01:45:55.000000000 +0200
423 @@ -139,6 +139,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.5.4/arch/mips/Kconfig linux-3.5.4-vs2.3.4.3/arch/mips/Kconfig
433 --- linux-3.5.4/arch/mips/Kconfig       2012-07-22 23:38:51.000000000 +0200
434 +++ linux-3.5.4-vs2.3.4.3/arch/mips/Kconfig     2012-07-23 01:45:55.000000000 +0200
435 @@ -2513,6 +2513,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.5.4/arch/mips/kernel/ptrace.c linux-3.5.4-vs2.3.4.3/arch/mips/kernel/ptrace.c
445 --- linux-3.5.4/arch/mips/kernel/ptrace.c       2012-07-22 23:38:52.000000000 +0200
446 +++ linux-3.5.4-vs2.3.4.3/arch/mips/kernel/ptrace.c     2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/mips/kernel/scall32-o32.S linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall32-o32.S
466 --- linux-3.5.4/arch/mips/kernel/scall32-o32.S  2012-01-09 16:14:05.000000000 +0100
467 +++ linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall32-o32.S        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/mips/kernel/scall64-64.S linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall64-64.S
478 --- linux-3.5.4/arch/mips/kernel/scall64-64.S   2012-01-09 16:14:05.000000000 +0100
479 +++ linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall64-64.S 2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/mips/kernel/scall64-n32.S linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall64-n32.S
490 --- linux-3.5.4/arch/mips/kernel/scall64-n32.S  2012-01-09 16:14:05.000000000 +0100
491 +++ linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall64-n32.S        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/mips/kernel/scall64-o32.S linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall64-o32.S
502 --- linux-3.5.4/arch/mips/kernel/scall64-o32.S  2012-01-09 16:14:05.000000000 +0100
503 +++ linux-3.5.4-vs2.3.4.3/arch/mips/kernel/scall64-o32.S        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/mips/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/mips/kernel/traps.c
514 --- linux-3.5.4/arch/mips/kernel/traps.c        2012-07-22 23:38:52.000000000 +0200
515 +++ linux-3.5.4-vs2.3.4.3/arch/mips/kernel/traps.c      2012-07-23 01:45:55.000000000 +0200
516 @@ -347,9 +347,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.5.4/arch/parisc/Kconfig linux-3.5.4-vs2.3.4.3/arch/parisc/Kconfig
531 --- linux-3.5.4/arch/parisc/Kconfig     2012-07-22 23:38:52.000000000 +0200
532 +++ linux-3.5.4-vs2.3.4.3/arch/parisc/Kconfig   2012-07-23 01:45:55.000000000 +0200
533 @@ -281,6 +281,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.5.4/arch/parisc/kernel/syscall_table.S linux-3.5.4-vs2.3.4.3/arch/parisc/kernel/syscall_table.S
543 --- linux-3.5.4/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
544 +++ linux-3.5.4-vs2.3.4.3/arch/parisc/kernel/syscall_table.S    2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/parisc/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/parisc/kernel/traps.c
555 --- linux-3.5.4/arch/parisc/kernel/traps.c      2012-05-21 18:06:28.000000000 +0200
556 +++ linux-3.5.4-vs2.3.4.3/arch/parisc/kernel/traps.c    2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/parisc/mm/fault.c linux-3.5.4-vs2.3.4.3/arch/parisc/mm/fault.c
581 --- linux-3.5.4/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
582 +++ linux-3.5.4-vs2.3.4.3/arch/parisc/mm/fault.c        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/powerpc/Kconfig linux-3.5.4-vs2.3.4.3/arch/powerpc/Kconfig
596 --- linux-3.5.4/arch/powerpc/Kconfig    2012-07-22 23:38:53.000000000 +0200
597 +++ linux-3.5.4-vs2.3.4.3/arch/powerpc/Kconfig  2012-07-23 01:45:55.000000000 +0200
598 @@ -994,6 +994,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.5.4/arch/powerpc/include/asm/unistd.h linux-3.5.4-vs2.3.4.3/arch/powerpc/include/asm/unistd.h
608 --- linux-3.5.4/arch/powerpc/include/asm/unistd.h       2012-01-09 16:14:05.000000000 +0100
609 +++ linux-3.5.4-vs2.3.4.3/arch/powerpc/include/asm/unistd.h     2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/powerpc/kernel/process.c linux-3.5.4-vs2.3.4.3/arch/powerpc/kernel/process.c
620 --- linux-3.5.4/arch/powerpc/kernel/process.c   2012-09-16 20:46:30.000000000 +0200
621 +++ linux-3.5.4-vs2.3.4.3/arch/powerpc/kernel/process.c 2012-09-16 20:50:19.000000000 +0200
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.5.4/arch/powerpc/kernel/traps.c linux-3.5.4-vs2.3.4.3/arch/powerpc/kernel/traps.c
635 --- linux-3.5.4/arch/powerpc/kernel/traps.c     2012-09-16 20:46:30.000000000 +0200
636 +++ linux-3.5.4-vs2.3.4.3/arch/powerpc/kernel/traps.c   2012-09-16 20:50:19.000000000 +0200
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.5.4/arch/s390/Kconfig linux-3.5.4-vs2.3.4.3/arch/s390/Kconfig
650 --- linux-3.5.4/arch/s390/Kconfig       2012-07-22 23:38:58.000000000 +0200
651 +++ linux-3.5.4-vs2.3.4.3/arch/s390/Kconfig     2012-07-23 01:45:55.000000000 +0200
652 @@ -630,6 +630,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.5.4/arch/s390/include/asm/tlb.h linux-3.5.4-vs2.3.4.3/arch/s390/include/asm/tlb.h
662 --- linux-3.5.4/arch/s390/include/asm/tlb.h     2012-07-22 23:38:59.000000000 +0200
663 +++ linux-3.5.4-vs2.3.4.3/arch/s390/include/asm/tlb.h   2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/s390/include/asm/unistd.h linux-3.5.4-vs2.3.4.3/arch/s390/include/asm/unistd.h
673 --- linux-3.5.4/arch/s390/include/asm/unistd.h  2012-03-19 19:46:48.000000000 +0100
674 +++ linux-3.5.4-vs2.3.4.3/arch/s390/include/asm/unistd.h        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/s390/kernel/ptrace.c linux-3.5.4-vs2.3.4.3/arch/s390/kernel/ptrace.c
685 --- linux-3.5.4/arch/s390/kernel/ptrace.c       2012-07-22 23:38:59.000000000 +0200
686 +++ linux-3.5.4-vs2.3.4.3/arch/s390/kernel/ptrace.c     2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/s390/kernel/syscalls.S linux-3.5.4-vs2.3.4.3/arch/s390/kernel/syscalls.S
696 --- linux-3.5.4/arch/s390/kernel/syscalls.S     2012-01-09 16:14:06.000000000 +0100
697 +++ linux-3.5.4-vs2.3.4.3/arch/s390/kernel/syscalls.S   2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/sh/Kconfig linux-3.5.4-vs2.3.4.3/arch/sh/Kconfig
708 --- linux-3.5.4/arch/sh/Kconfig 2012-07-22 23:38:59.000000000 +0200
709 +++ linux-3.5.4-vs2.3.4.3/arch/sh/Kconfig       2012-07-23 01:45:55.000000000 +0200
710 @@ -937,6 +937,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.5.4/arch/sh/kernel/irq.c linux-3.5.4-vs2.3.4.3/arch/sh/kernel/irq.c
720 --- linux-3.5.4/arch/sh/kernel/irq.c    2012-07-22 23:38:59.000000000 +0200
721 +++ linux-3.5.4-vs2.3.4.3/arch/sh/kernel/irq.c  2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/sparc/Kconfig linux-3.5.4-vs2.3.4.3/arch/sparc/Kconfig
731 --- linux-3.5.4/arch/sparc/Kconfig      2012-07-22 23:38:59.000000000 +0200
732 +++ linux-3.5.4-vs2.3.4.3/arch/sparc/Kconfig    2012-07-23 01:45:55.000000000 +0200
733 @@ -592,6 +592,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.5.4/arch/sparc/include/asm/unistd.h linux-3.5.4-vs2.3.4.3/arch/sparc/include/asm/unistd.h
743 --- linux-3.5.4/arch/sparc/include/asm/unistd.h 2012-01-09 16:14:07.000000000 +0100
744 +++ linux-3.5.4-vs2.3.4.3/arch/sparc/include/asm/unistd.h       2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/sparc/kernel/systbls_32.S linux-3.5.4-vs2.3.4.3/arch/sparc/kernel/systbls_32.S
755 --- linux-3.5.4/arch/sparc/kernel/systbls_32.S  2012-01-09 16:14:09.000000000 +0100
756 +++ linux-3.5.4-vs2.3.4.3/arch/sparc/kernel/systbls_32.S        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/sparc/kernel/systbls_64.S linux-3.5.4-vs2.3.4.3/arch/sparc/kernel/systbls_64.S
767 --- linux-3.5.4/arch/sparc/kernel/systbls_64.S  2012-07-22 23:39:00.000000000 +0200
768 +++ linux-3.5.4-vs2.3.4.3/arch/sparc/kernel/systbls_64.S        2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/um/Kconfig.rest linux-3.5.4-vs2.3.4.3/arch/um/Kconfig.rest
788 --- linux-3.5.4/arch/um/Kconfig.rest    2012-01-09 16:14:09.000000000 +0100
789 +++ linux-3.5.4-vs2.3.4.3/arch/um/Kconfig.rest  2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/um/include/shared/kern_constants.h linux-3.5.4-vs2.3.4.3/arch/um/include/shared/kern_constants.h
800 --- linux-3.5.4/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
801 +++ linux-3.5.4-vs2.3.4.3/arch/um/include/shared/kern_constants.h       2012-07-23 01:45:55.000000000 +0200
802 @@ -0,0 +1 @@
803 +#include "../../../../include/generated/asm-offsets.h"
804 diff -NurpP --minimal linux-3.5.4/arch/um/include/shared/user_constants.h linux-3.5.4-vs2.3.4.3/arch/um/include/shared/user_constants.h
805 --- linux-3.5.4/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
806 +++ linux-3.5.4-vs2.3.4.3/arch/um/include/shared/user_constants.h       2012-07-23 01:45:55.000000000 +0200
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.5.4/arch/x86/Kconfig linux-3.5.4-vs2.3.4.3/arch/x86/Kconfig
849 --- linux-3.5.4/arch/x86/Kconfig        2012-07-22 23:39:01.000000000 +0200
850 +++ linux-3.5.4-vs2.3.4.3/arch/x86/Kconfig      2012-07-23 01:45:55.000000000 +0200
851 @@ -2226,6 +2226,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.5.4/arch/x86/syscalls/syscall_32.tbl linux-3.5.4-vs2.3.4.3/arch/x86/syscalls/syscall_32.tbl
861 --- linux-3.5.4/arch/x86/syscalls/syscall_32.tbl        2012-07-22 23:39:02.000000000 +0200
862 +++ linux-3.5.4-vs2.3.4.3/arch/x86/syscalls/syscall_32.tbl      2012-07-23 01:45:55.000000000 +0200
863 @@ -279,7 +279,7 @@
864  270    i386    tgkill                  sys_tgkill
865  271    i386    utimes                  sys_utimes                      compat_sys_utimes
866  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
867 -273    i386    vserver
868 +273    i386    vserver                 sys_vserver                     sys32_vserver
869  274    i386    mbind                   sys_mbind
870  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
871  276    i386    set_mempolicy           sys_set_mempolicy
872 diff -NurpP --minimal linux-3.5.4/arch/x86/syscalls/syscall_64.tbl linux-3.5.4-vs2.3.4.3/arch/x86/syscalls/syscall_64.tbl
873 --- linux-3.5.4/arch/x86/syscalls/syscall_64.tbl        2012-09-16 20:46:30.000000000 +0200
874 +++ linux-3.5.4-vs2.3.4.3/arch/x86/syscalls/syscall_64.tbl      2012-09-16 20:50:19.000000000 +0200
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.5.4/drivers/block/Kconfig linux-3.5.4-vs2.3.4.3/drivers/block/Kconfig
885 --- linux-3.5.4/drivers/block/Kconfig   2012-05-21 18:06:43.000000000 +0200
886 +++ linux-3.5.4-vs2.3.4.3/drivers/block/Kconfig 2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/block/Makefile linux-3.5.4-vs2.3.4.3/drivers/block/Makefile
902 --- linux-3.5.4/drivers/block/Makefile  2012-03-19 19:46:52.000000000 +0100
903 +++ linux-3.5.4-vs2.3.4.3/drivers/block/Makefile        2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/block/loop.c linux-3.5.4-vs2.3.4.3/drivers/block/loop.c
913 --- linux-3.5.4/drivers/block/loop.c    2012-07-22 23:39:02.000000000 +0200
914 +++ linux-3.5.4-vs2.3.4.3/drivers/block/loop.c  2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/block/vroot.c linux-3.5.4-vs2.3.4.3/drivers/block/vroot.c
971 --- linux-3.5.4/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
972 +++ linux-3.5.4-vs2.3.4.3/drivers/block/vroot.c 2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/infiniband/Kconfig linux-3.5.4-vs2.3.4.3/drivers/infiniband/Kconfig
1266 --- linux-3.5.4/drivers/infiniband/Kconfig      2012-07-22 23:39:06.000000000 +0200
1267 +++ linux-3.5.4-vs2.3.4.3/drivers/infiniband/Kconfig    2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/infiniband/core/addr.c linux-3.5.4-vs2.3.4.3/drivers/infiniband/core/addr.c
1278 --- linux-3.5.4/drivers/infiniband/core/addr.c  2012-05-21 18:06:46.000000000 +0200
1279 +++ linux-3.5.4-vs2.3.4.3/drivers/infiniband/core/addr.c        2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/md/dm-ioctl.c linux-3.5.4-vs2.3.4.3/drivers/md/dm-ioctl.c
1290 --- linux-3.5.4/drivers/md/dm-ioctl.c   2012-05-21 18:06:49.000000000 +0200
1291 +++ linux-3.5.4-vs2.3.4.3/drivers/md/dm-ioctl.c 2012-07-23 01:45:55.000000000 +0200
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 @@ -1616,8 +1628,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.5.4/drivers/md/dm.c linux-3.5.4-vs2.3.4.3/drivers/md/dm.c
1378 --- linux-3.5.4/drivers/md/dm.c 2012-05-21 18:06:49.000000000 +0200
1379 +++ linux-3.5.4-vs2.3.4.3/drivers/md/dm.c       2012-07-23 01:45:55.000000000 +0200
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 @@ -1850,6 +1862,7 @@ static struct mapped_device *alloc_dev(i
1446         INIT_LIST_HEAD(&md->uevent_list);
1447         spin_lock_init(&md->uevent_lock);
1448  
1449 +       md->xid = vx_current_xid();
1450         md->queue = blk_alloc_queue(GFP_KERNEL);
1451         if (!md->queue)
1452                 goto bad_queue;
1453 diff -NurpP --minimal linux-3.5.4/drivers/md/dm.h linux-3.5.4-vs2.3.4.3/drivers/md/dm.h
1454 --- linux-3.5.4/drivers/md/dm.h 2012-01-09 16:14:21.000000000 +0100
1455 +++ linux-3.5.4-vs2.3.4.3/drivers/md/dm.h       2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/net/tun.c linux-3.5.4-vs2.3.4.3/drivers/net/tun.c
1466 --- linux-3.5.4/drivers/net/tun.c       2012-09-16 20:46:30.000000000 +0200
1467 +++ linux-3.5.4-vs2.3.4.3/drivers/net/tun.c     2012-08-19 13:28:27.000000000 +0200
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.5.4/drivers/tty/sysrq.c linux-3.5.4-vs2.3.4.3/drivers/tty/sysrq.c
1538 --- linux-3.5.4/drivers/tty/sysrq.c     2012-05-21 18:07:16.000000000 +0200
1539 +++ linux-3.5.4-vs2.3.4.3/drivers/tty/sysrq.c   2012-07-23 01:45:55.000000000 +0200
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.5.4/drivers/tty/tty_io.c linux-3.5.4-vs2.3.4.3/drivers/tty/tty_io.c
1592 --- linux-3.5.4/drivers/tty/tty_io.c    2012-07-22 23:39:32.000000000 +0200
1593 +++ linux-3.5.4-vs2.3.4.3/drivers/tty/tty_io.c  2012-07-23 01:45:55.000000000 +0200
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 @@ -2123,7 +2124,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 @@ -2411,6 +2413,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.5.4/fs/attr.c linux-3.5.4-vs2.3.4.3/fs/attr.c
1621 --- linux-3.5.4/fs/attr.c       2012-07-22 23:39:35.000000000 +0200
1622 +++ linux-3.5.4-vs2.3.4.3/fs/attr.c     2012-07-23 01:45:55.000000000 +0200
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.5.4/fs/block_dev.c linux-3.5.4-vs2.3.4.3/fs/block_dev.c
1664 --- linux-3.5.4/fs/block_dev.c  2012-07-22 23:39:35.000000000 +0200
1665 +++ linux-3.5.4-vs2.3.4.3/fs/block_dev.c        2012-07-23 01:45:55.000000000 +0200
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.5.4/fs/btrfs/ctree.h linux-3.5.4-vs2.3.4.3/fs/btrfs/ctree.h
1704 --- linux-3.5.4/fs/btrfs/ctree.h        2012-07-22 23:39:35.000000000 +0200
1705 +++ linux-3.5.4-vs2.3.4.3/fs/btrfs/ctree.h      2012-07-23 01:45:55.000000000 +0200
1706 @@ -671,11 +671,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 @@ -1568,6 +1571,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 @@ -1788,6 +1793,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 @@ -1841,6 +1847,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 @@ -3017,6 +3027,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.5.4/fs/btrfs/disk-io.c linux-3.5.4-vs2.3.4.3/fs/btrfs/disk-io.c
1759 --- linux-3.5.4/fs/btrfs/disk-io.c      2012-07-22 23:39:35.000000000 +0200
1760 +++ linux-3.5.4-vs2.3.4.3/fs/btrfs/disk-io.c    2012-07-23 01:45:55.000000000 +0200
1761 @@ -2090,6 +2090,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.5.4/fs/btrfs/inode.c linux-3.5.4-vs2.3.4.3/fs/btrfs/inode.c
1772 --- linux-3.5.4/fs/btrfs/inode.c        2012-07-22 23:39:35.000000000 +0200
1773 +++ linux-3.5.4-vs2.3.4.3/fs/btrfs/inode.c      2012-07-23 01:45:55.000000000 +0200
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 @@ -2543,6 +2544,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 @@ -2570,8 +2573,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 @@ -2649,8 +2657,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 @@ -7621,11 +7635,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.5.4/fs/btrfs/ioctl.c linux-3.5.4-vs2.3.4.3/fs/btrfs/ioctl.c
1839 --- linux-3.5.4/fs/btrfs/ioctl.c        2012-07-22 23:39:35.000000000 +0200
1840 +++ linux-3.5.4-vs2.3.4.3/fs/btrfs/ioctl.c      2012-07-23 01:45:55.000000000 +0200
1841 @@ -72,10 +72,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 @@ -92,28 +95,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 @@ -129,6 +182,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 @@ -144,6 +198,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 @@ -200,7 +278,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 @@ -211,14 +290,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.5.4/fs/btrfs/super.c linux-3.5.4-vs2.3.4.3/fs/btrfs/super.c
2014 --- linux-3.5.4/fs/btrfs/super.c        2012-07-22 23:39:35.000000000 +0200
2015 +++ linux-3.5.4-vs2.3.4.3/fs/btrfs/super.c      2012-07-23 01:45:55.000000000 +0200
2016 @@ -281,7 +281,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 @@ -321,6 +321,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 @@ -563,6 +566,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 @@ -1158,6 +1177,12 @@ static int btrfs_remount(struct super_bl
2059         btrfs_resize_thread_pool(fs_info,
2060                 fs_info->thread_pool_size, old_thread_pool_size);
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.5.4/fs/char_dev.c linux-3.5.4-vs2.3.4.3/fs/char_dev.c
2072 --- linux-3.5.4/fs/char_dev.c   2012-03-19 19:47:25.000000000 +0100
2073 +++ linux-3.5.4-vs2.3.4.3/fs/char_dev.c 2012-07-23 01:45:55.000000000 +0200
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.5.4/fs/dcache.c linux-3.5.4-vs2.3.4.3/fs/dcache.c
2107 --- linux-3.5.4/fs/dcache.c     2012-07-22 23:39:36.000000000 +0200
2108 +++ linux-3.5.4-vs2.3.4.3/fs/dcache.c   2012-07-23 01:45:55.000000000 +0200
2109 @@ -37,6 +37,7 @@
2110  #include <linux/rculist_bl.h>
2111  #include <linux/prefetch.h>
2112  #include <linux/ratelimit.h>
2113 +#include <linux/vs_limit.h>
2114  #include "internal.h"
2115  #include "mount.h"
2116  
2117 @@ -617,6 +618,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 @@ -646,6 +649,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 @@ -1270,6 +1274,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 @@ -1302,6 +1309,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 @@ -2005,6 +2013,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.5.4/fs/devpts/inode.c linux-3.5.4-vs2.3.4.3/fs/devpts/inode.c
2161 --- linux-3.5.4/fs/devpts/inode.c       2012-07-22 23:39:38.000000000 +0200
2162 +++ linux-3.5.4-vs2.3.4.3/fs/devpts/inode.c     2012-07-23 01:45:55.000000000 +0200
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 @@ -336,6 +352,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 @@ -379,8 +423,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 @@ -572,6 +618,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.5.4/fs/ext2/balloc.c linux-3.5.4-vs2.3.4.3/fs/ext2/balloc.c
2251 --- linux-3.5.4/fs/ext2/balloc.c        2012-07-22 23:39:39.000000000 +0200
2252 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/balloc.c      2012-07-23 01:45:55.000000000 +0200
2253 @@ -699,7 +699,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.5.4/fs/ext2/ext2.h linux-3.5.4-vs2.3.4.3/fs/ext2/ext2.h
2262 --- linux-3.5.4/fs/ext2/ext2.h  2012-07-22 23:39:39.000000000 +0200
2263 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/ext2.h        2012-07-23 01:45:55.000000000 +0200
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.5.4/fs/ext2/file.c linux-3.5.4-vs2.3.4.3/fs/ext2/file.c
2312 --- linux-3.5.4/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2313 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/file.c        2012-07-23 01:45:55.000000000 +0200
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.5.4/fs/ext2/ialloc.c linux-3.5.4-vs2.3.4.3/fs/ext2/ialloc.c
2321 --- linux-3.5.4/fs/ext2/ialloc.c        2012-07-22 23:39:39.000000000 +0200
2322 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/ialloc.c      2012-07-23 01:45:55.000000000 +0200
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 @@ -547,6 +548,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.5.4/fs/ext2/inode.c linux-3.5.4-vs2.3.4.3/fs/ext2/inode.c
2340 --- linux-3.5.4/fs/ext2/inode.c 2012-07-22 23:39:39.000000000 +0200
2341 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/inode.c       2012-07-23 11:01:46.000000000 +0200
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 @@ -1318,8 +1344,10 @@ struct inode *ext2_iget (struct super_bl
2429                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2430                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2431         }
2432 -       i_uid_write(inode, i_uid);
2433 -       i_gid_write(inode, i_gid);
2434 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2435 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2436 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2437 +               le16_to_cpu(raw_inode->i_raw_tag));
2438         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2439         inode->i_size = le32_to_cpu(raw_inode->i_size);
2440         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2441 @@ -1417,8 +1445,8 @@ static int __ext2_write_inode(struct ino
2442         struct ext2_inode_info *ei = EXT2_I(inode);
2443         struct super_block *sb = inode->i_sb;
2444         ino_t ino = inode->i_ino;
2445 -       uid_t uid = i_uid_read(inode);
2446 -       gid_t gid = i_gid_read(inode);
2447 +       uid_t uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2448 +       gid_t gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2449         struct buffer_head * bh;
2450         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2451         int n;
2452 @@ -1454,6 +1482,9 @@ static int __ext2_write_inode(struct ino
2453                 raw_inode->i_uid_high = 0;
2454                 raw_inode->i_gid_high = 0;
2455         }
2456 +#ifdef CONFIG_TAGGING_INTERN
2457 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2458 +#endif
2459         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2460         raw_inode->i_size = cpu_to_le32(inode->i_size);
2461         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2462 @@ -1534,7 +1565,8 @@ int ext2_setattr(struct dentry *dentry, 
2463         if (is_quota_modification(inode, iattr))
2464                 dquot_initialize(inode);
2465         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2466 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2467 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2468 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2469                 error = dquot_transfer(inode, iattr);
2470                 if (error)
2471                         return error;
2472 diff -NurpP --minimal linux-3.5.4/fs/ext2/ioctl.c linux-3.5.4-vs2.3.4.3/fs/ext2/ioctl.c
2473 --- linux-3.5.4/fs/ext2/ioctl.c 2012-03-19 19:47:25.000000000 +0100
2474 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/ioctl.c       2012-07-23 01:45:55.000000000 +0200
2475 @@ -17,6 +17,16 @@
2476  #include <asm/uaccess.h>
2477  
2478  
2479 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2480 +{
2481 +       inode->i_flags = flags;
2482 +       inode->i_vflags = vflags;
2483 +       ext2_get_inode_flags(EXT2_I(inode));
2484 +       inode->i_ctime = CURRENT_TIME_SEC;
2485 +       mark_inode_dirty(inode);
2486 +       return 0;
2487 +}
2488 +
2489  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2490  {
2491         struct inode *inode = filp->f_dentry->d_inode;
2492 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2493  
2494                 flags = ext2_mask_flags(inode->i_mode, flags);
2495  
2496 +               if (IS_BARRIER(inode)) {
2497 +                       vxwprintk_task(1, "messing with the barrier.");
2498 +                       return -EACCES;
2499 +               }
2500 +
2501                 mutex_lock(&inode->i_mutex);
2502                 /* Is it quota file? Do not allow user to mess with it */
2503                 if (IS_NOQUOTA(inode)) {
2504 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2505                  *
2506                  * This test looks nicer. Thanks to Pauline Middelink
2507                  */
2508 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2509 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2510 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2511 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2512                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2513                                 mutex_unlock(&inode->i_mutex);
2514                                 ret = -EPERM;
2515 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2516                         }
2517                 }
2518  
2519 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2520 +               flags &= EXT2_FL_USER_MODIFIABLE;
2521                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2522                 ei->i_flags = flags;
2523  
2524 diff -NurpP --minimal linux-3.5.4/fs/ext2/namei.c linux-3.5.4-vs2.3.4.3/fs/ext2/namei.c
2525 --- linux-3.5.4/fs/ext2/namei.c 2012-07-22 23:39:39.000000000 +0200
2526 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/namei.c       2012-07-23 01:45:55.000000000 +0200
2527 @@ -32,6 +32,7 @@
2528  
2529  #include <linux/pagemap.h>
2530  #include <linux/quotaops.h>
2531 +#include <linux/vs_tag.h>
2532  #include "ext2.h"
2533  #include "xattr.h"
2534  #include "acl.h"
2535 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2536                                         (unsigned long) ino);
2537                         return ERR_PTR(-EIO);
2538                 }
2539 +               dx_propagate_tag(nd, inode);
2540         }
2541         return d_splice_alias(inode, dentry);
2542  }
2543 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2544         .removexattr    = generic_removexattr,
2545  #endif
2546         .setattr        = ext2_setattr,
2547 +       .sync_flags     = ext2_sync_flags,
2548         .get_acl        = ext2_get_acl,
2549  };
2550  
2551 diff -NurpP --minimal linux-3.5.4/fs/ext2/super.c linux-3.5.4-vs2.3.4.3/fs/ext2/super.c
2552 --- linux-3.5.4/fs/ext2/super.c 2012-07-22 23:39:39.000000000 +0200
2553 +++ linux-3.5.4-vs2.3.4.3/fs/ext2/super.c       2012-07-23 01:45:55.000000000 +0200
2554 @@ -386,7 +386,8 @@ enum {
2555         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2556         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2557         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2558 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2559 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2560 +       Opt_tag, Opt_notag, Opt_tagid
2561  };
2562  
2563  static const match_table_t tokens = {
2564 @@ -414,6 +415,9 @@ static const match_table_t tokens = {
2565         {Opt_acl, "acl"},
2566         {Opt_noacl, "noacl"},
2567         {Opt_xip, "xip"},
2568 +       {Opt_tag, "tag"},
2569 +       {Opt_notag, "notag"},
2570 +       {Opt_tagid, "tagid=%u"},
2571         {Opt_grpquota, "grpquota"},
2572         {Opt_ignore, "noquota"},
2573         {Opt_quota, "quota"},
2574 @@ -497,6 +501,20 @@ static int parse_options(char *options, 
2575                 case Opt_nouid32:
2576                         set_opt (sbi->s_mount_opt, NO_UID32);
2577                         break;
2578 +#ifndef CONFIG_TAGGING_NONE
2579 +               case Opt_tag:
2580 +                       set_opt (sbi->s_mount_opt, TAGGED);
2581 +                       break;
2582 +               case Opt_notag:
2583 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2584 +                       break;
2585 +#endif
2586 +#ifdef CONFIG_PROPAGATE
2587 +               case Opt_tagid:
2588 +                       /* use args[0] */
2589 +                       set_opt (sbi->s_mount_opt, TAGGED);
2590 +                       break;
2591 +#endif
2592                 case Opt_nocheck:
2593                         clear_opt (sbi->s_mount_opt, CHECK);
2594                         break;
2595 @@ -855,6 +873,8 @@ static int ext2_fill_super(struct super_
2596         if (!parse_options((char *) data, sb))
2597                 goto failed_mount;
2598  
2599 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2600 +               sb->s_flags |= MS_TAGGED;
2601         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2602                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2603                  MS_POSIXACL : 0);
2604 @@ -1226,6 +1246,14 @@ static int ext2_remount (struct super_bl
2605                 goto restore_opts;
2606         }
2607  
2608 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2609 +               !(sb->s_flags & MS_TAGGED)) {
2610 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2611 +                      sb->s_id);
2612 +               err = -EINVAL;
2613 +               goto restore_opts;
2614 +       }
2615 +
2616         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2617                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2618  
2619 diff -NurpP --minimal linux-3.5.4/fs/ext3/ext3.h linux-3.5.4-vs2.3.4.3/fs/ext3/ext3.h
2620 --- linux-3.5.4/fs/ext3/ext3.h  2012-07-22 23:39:39.000000000 +0200
2621 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/ext3.h        2012-07-23 01:45:55.000000000 +0200
2622 @@ -151,10 +151,14 @@ struct ext3_group_desc
2623  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2624  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2625  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2626 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2627  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2628  
2629 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2630 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2631 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2632 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2633 +
2634 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2635 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2636  
2637  /* Flags that should be inherited by new inodes from their parent. */
2638  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2639 @@ -290,7 +294,8 @@ struct ext3_inode {
2640                         __u16   i_pad1;
2641                         __le16  l_i_uid_high;   /* these 2 fields    */
2642                         __le16  l_i_gid_high;   /* were reserved2[0] */
2643 -                       __u32   l_i_reserved2;
2644 +                       __le16  l_i_tag;        /* Context Tag */
2645 +                       __u16   l_i_reserved2;
2646                 } linux2;
2647                 struct {
2648                         __u8    h_i_frag;       /* Fragment number */
2649 @@ -320,6 +325,7 @@ struct ext3_inode {
2650  #define i_gid_low      i_gid
2651  #define i_uid_high     osd2.linux2.l_i_uid_high
2652  #define i_gid_high     osd2.linux2.l_i_gid_high
2653 +#define i_raw_tag      osd2.linux2.l_i_tag
2654  #define i_reserved2    osd2.linux2.l_i_reserved2
2655  
2656  /*
2657 @@ -364,6 +370,7 @@ struct ext3_inode {
2658  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2659  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2660                                                   * error in ordered mode */
2661 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2662  
2663  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2664  #ifndef _LINUX_EXT2_FS_H
2665 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct 
2666  extern void ext3_set_aops(struct inode *inode);
2667  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2668                        u64 start, u64 len);
2669 +extern int ext3_sync_flags(struct inode *, int, int);
2670  
2671  /* ioctl.c */
2672  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2673 diff -NurpP --minimal linux-3.5.4/fs/ext3/file.c linux-3.5.4-vs2.3.4.3/fs/ext3/file.c
2674 --- linux-3.5.4/fs/ext3/file.c  2012-05-21 18:07:20.000000000 +0200
2675 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/file.c        2012-07-23 01:45:55.000000000 +0200
2676 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2677  #endif
2678         .get_acl        = ext3_get_acl,
2679         .fiemap         = ext3_fiemap,
2680 +       .sync_flags     = ext3_sync_flags,
2681  };
2682  
2683 diff -NurpP --minimal linux-3.5.4/fs/ext3/ialloc.c linux-3.5.4-vs2.3.4.3/fs/ext3/ialloc.c
2684 --- linux-3.5.4/fs/ext3/ialloc.c        2012-07-22 23:39:39.000000000 +0200
2685 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/ialloc.c      2012-07-23 01:45:55.000000000 +0200
2686 @@ -14,6 +14,7 @@
2687  
2688  #include <linux/quotaops.h>
2689  #include <linux/random.h>
2690 +#include <linux/vs_tag.h>
2691  
2692  #include "ext3.h"
2693  #include "xattr.h"
2694 @@ -469,6 +470,7 @@ got:
2695                 inode->i_mode = mode;
2696                 inode->i_uid = current_fsuid();
2697                 inode->i_gid = dir->i_gid;
2698 +               inode->i_tag = dx_current_fstag(sb);
2699         } else
2700                 inode_init_owner(inode, dir, mode);
2701  
2702 diff -NurpP --minimal linux-3.5.4/fs/ext3/inode.c linux-3.5.4-vs2.3.4.3/fs/ext3/inode.c
2703 --- linux-3.5.4/fs/ext3/inode.c 2012-09-16 20:46:31.000000000 +0200
2704 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/inode.c       2012-09-16 20:50:19.000000000 +0200
2705 @@ -27,6 +27,8 @@
2706  #include <linux/writeback.h>
2707  #include <linux/mpage.h>
2708  #include <linux/namei.h>
2709 +#include <linux/vs_tag.h>
2710 +
2711  #include "ext3.h"
2712  #include "xattr.h"
2713  #include "acl.h"
2714 @@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2715  {
2716         unsigned int flags = EXT3_I(inode)->i_flags;
2717  
2718 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2719 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2720 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2721 +
2722 +       if (flags & EXT3_IMMUTABLE_FL)
2723 +               inode->i_flags |= S_IMMUTABLE;
2724 +       if (flags & EXT3_IXUNLINK_FL)
2725 +               inode->i_flags |= S_IXUNLINK;
2726 +
2727         if (flags & EXT3_SYNC_FL)
2728                 inode->i_flags |= S_SYNC;
2729         if (flags & EXT3_APPEND_FL)
2730                 inode->i_flags |= S_APPEND;
2731 -       if (flags & EXT3_IMMUTABLE_FL)
2732 -               inode->i_flags |= S_IMMUTABLE;
2733         if (flags & EXT3_NOATIME_FL)
2734                 inode->i_flags |= S_NOATIME;
2735         if (flags & EXT3_DIRSYNC_FL)
2736                 inode->i_flags |= S_DIRSYNC;
2737 +
2738 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2739 +
2740 +       if (flags & EXT3_BARRIER_FL)
2741 +               inode->i_vflags |= V_BARRIER;
2742 +       if (flags & EXT3_COW_FL)
2743 +               inode->i_vflags |= V_COW;
2744  }
2745  
2746  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2747  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2748  {
2749         unsigned int flags = ei->vfs_inode.i_flags;
2750 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2751 +
2752 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2753 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2754 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2755 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2756 +
2757 +       if (flags & S_IMMUTABLE)
2758 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2759 +       if (flags & S_IXUNLINK)
2760 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2761  
2762 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2763 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2764         if (flags & S_SYNC)
2765                 ei->i_flags |= EXT3_SYNC_FL;
2766         if (flags & S_APPEND)
2767                 ei->i_flags |= EXT3_APPEND_FL;
2768 -       if (flags & S_IMMUTABLE)
2769 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2770         if (flags & S_NOATIME)
2771                 ei->i_flags |= EXT3_NOATIME_FL;
2772         if (flags & S_DIRSYNC)
2773                 ei->i_flags |= EXT3_DIRSYNC_FL;
2774 +
2775 +       if (vflags & V_BARRIER)
2776 +               ei->i_flags |= EXT3_BARRIER_FL;
2777 +       if (vflags & V_COW)
2778 +               ei->i_flags |= EXT3_COW_FL;
2779  }
2780  
2781  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2782 @@ -2915,8 +2941,10 @@ struct inode *ext3_iget(struct super_blo
2783                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2784                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2785         }
2786 -       i_uid_write(inode, i_uid);
2787 -       i_gid_write(inode, i_gid);
2788 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2789 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2790 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2791 +               le16_to_cpu(raw_inode->i_raw_tag));
2792         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2793         inode->i_size = le32_to_cpu(raw_inode->i_size);
2794         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2795 @@ -3088,8 +3116,8 @@ again:
2796  
2797         ext3_get_inode_flags(ei);
2798         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2799 -       i_uid = i_uid_read(inode);
2800 -       i_gid = i_gid_read(inode);
2801 +       i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2802 +       i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2803         if(!(test_opt(inode->i_sb, NO_UID32))) {
2804                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2805                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2806 @@ -3114,6 +3142,9 @@ again:
2807                 raw_inode->i_uid_high = 0;
2808                 raw_inode->i_gid_high = 0;
2809         }
2810 +#ifdef CONFIG_TAGGING_INTERN
2811 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2812 +#endif
2813         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2814         disksize = cpu_to_le32(ei->i_disksize);
2815         if (disksize != raw_inode->i_size) {
2816 @@ -3282,7 +3313,8 @@ int ext3_setattr(struct dentry *dentry, 
2817         if (is_quota_modification(inode, attr))
2818                 dquot_initialize(inode);
2819         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2820 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2821 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2822 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2823                 handle_t *handle;
2824  
2825                 /* (user+group)*(old+new) structure, inode write (sb,
2826 @@ -3304,6 +3336,8 @@ int ext3_setattr(struct dentry *dentry, 
2827                         inode->i_uid = attr->ia_uid;
2828                 if (attr->ia_valid & ATTR_GID)
2829                         inode->i_gid = attr->ia_gid;
2830 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2831 +                       inode->i_tag = attr->ia_tag;
2832                 error = ext3_mark_inode_dirty(handle, inode);
2833                 ext3_journal_stop(handle);
2834         }
2835 diff -NurpP --minimal linux-3.5.4/fs/ext3/ioctl.c linux-3.5.4-vs2.3.4.3/fs/ext3/ioctl.c
2836 --- linux-3.5.4/fs/ext3/ioctl.c 2012-05-21 18:07:20.000000000 +0200
2837 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/ioctl.c       2012-07-23 01:45:55.000000000 +0200
2838 @@ -12,6 +12,34 @@
2839  #include <asm/uaccess.h>
2840  #include "ext3.h"
2841  
2842 +
2843 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2844 +{
2845 +       handle_t *handle = NULL;
2846 +       struct ext3_iloc iloc;
2847 +       int err;
2848 +
2849 +       handle = ext3_journal_start(inode, 1);
2850 +       if (IS_ERR(handle))
2851 +               return PTR_ERR(handle);
2852 +
2853 +       if (IS_SYNC(inode))
2854 +               handle->h_sync = 1;
2855 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2856 +       if (err)
2857 +               goto flags_err;
2858 +
2859 +       inode->i_flags = flags;
2860 +       inode->i_vflags = vflags;
2861 +       ext3_get_inode_flags(EXT3_I(inode));
2862 +       inode->i_ctime = CURRENT_TIME_SEC;
2863 +
2864 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2865 +flags_err:
2866 +       ext3_journal_stop(handle);
2867 +       return err;
2868 +}
2869 +
2870  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2871  {
2872         struct inode *inode = filp->f_dentry->d_inode;
2873 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2874  
2875                 flags = ext3_mask_flags(inode->i_mode, flags);
2876  
2877 +               if (IS_BARRIER(inode)) {
2878 +                       vxwprintk_task(1, "messing with the barrier.");
2879 +                       return -EACCES;
2880 +               }
2881 +
2882                 mutex_lock(&inode->i_mutex);
2883  
2884                 /* Is it quota file? Do not allow user to mess with it */
2885 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2886                  *
2887                  * This test looks nicer. Thanks to Pauline Middelink
2888                  */
2889 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2890 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2891 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2892 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2893                         if (!capable(CAP_LINUX_IMMUTABLE))
2894                                 goto flags_out;
2895                 }
2896 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2897                 if (err)
2898                         goto flags_err;
2899  
2900 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2901 +               flags &= EXT3_FL_USER_MODIFIABLE;
2902                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2903                 ei->i_flags = flags;
2904  
2905 diff -NurpP --minimal linux-3.5.4/fs/ext3/namei.c linux-3.5.4-vs2.3.4.3/fs/ext3/namei.c
2906 --- linux-3.5.4/fs/ext3/namei.c 2012-07-22 23:39:39.000000000 +0200
2907 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/namei.c       2012-07-23 01:45:55.000000000 +0200
2908 @@ -25,6 +25,8 @@
2909   */
2910  
2911  #include <linux/quotaops.h>
2912 +#include <linux/vs_tag.h>
2913 +
2914  #include "ext3.h"
2915  #include "namei.h"
2916  #include "xattr.h"
2917 @@ -915,6 +917,7 @@ restart:
2918                                         submit_bh(READ | REQ_META | REQ_PRIO,
2919                                                   bh);
2920                                 }
2921 +               dx_propagate_tag(nd, inode);
2922                         }
2923                 }
2924                 if ((bh = bh_use[ra_ptr++]) == NULL)
2925 @@ -2526,6 +2529,7 @@ const struct inode_operations ext3_dir_i
2926         .listxattr      = ext3_listxattr,
2927         .removexattr    = generic_removexattr,
2928  #endif
2929 +       .sync_flags     = ext3_sync_flags,
2930         .get_acl        = ext3_get_acl,
2931  };
2932  
2933 diff -NurpP --minimal linux-3.5.4/fs/ext3/super.c linux-3.5.4-vs2.3.4.3/fs/ext3/super.c
2934 --- linux-3.5.4/fs/ext3/super.c 2012-07-22 23:39:39.000000000 +0200
2935 +++ linux-3.5.4-vs2.3.4.3/fs/ext3/super.c       2012-07-23 01:45:55.000000000 +0200
2936 @@ -822,7 +822,8 @@ enum {
2937         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2938         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2939         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2940 -       Opt_resize, Opt_usrquota, Opt_grpquota
2941 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2942 +       Opt_tag, Opt_notag, Opt_tagid
2943  };
2944  
2945  static const match_table_t tokens = {
2946 @@ -879,6 +880,9 @@ static const match_table_t tokens = {
2947         {Opt_barrier, "barrier"},
2948         {Opt_nobarrier, "nobarrier"},
2949         {Opt_resize, "resize"},
2950 +       {Opt_tag, "tag"},
2951 +       {Opt_notag, "notag"},
2952 +       {Opt_tagid, "tagid=%u"},
2953         {Opt_err, NULL},
2954  };
2955  
2956 @@ -1044,6 +1048,20 @@ static int parse_options (char *options,
2957                 case Opt_nouid32:
2958                         set_opt (sbi->s_mount_opt, NO_UID32);
2959                         break;
2960 +#ifndef CONFIG_TAGGING_NONE
2961 +               case Opt_tag:
2962 +                       set_opt (sbi->s_mount_opt, TAGGED);
2963 +                       break;
2964 +               case Opt_notag:
2965 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2966 +                       break;
2967 +#endif
2968 +#ifdef CONFIG_PROPAGATE
2969 +               case Opt_tagid:
2970 +                       /* use args[0] */
2971 +                       set_opt (sbi->s_mount_opt, TAGGED);
2972 +                       break;
2973 +#endif
2974                 case Opt_nocheck:
2975                         clear_opt (sbi->s_mount_opt, CHECK);
2976                         break;
2977 @@ -1742,6 +1760,9 @@ static int ext3_fill_super (struct super
2978                             NULL, 0))
2979                 goto failed_mount;
2980  
2981 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2982 +               sb->s_flags |= MS_TAGGED;
2983 +
2984         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2985                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2986  
2987 @@ -2623,6 +2644,14 @@ static int ext3_remount (struct super_bl
2988         if (test_opt(sb, ABORT))
2989                 ext3_abort(sb, __func__, "Abort forced by user");
2990  
2991 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2992 +               !(sb->s_flags & MS_TAGGED)) {
2993 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2994 +                       sb->s_id);
2995 +               err = -EINVAL;
2996 +               goto restore_opts;
2997 +       }
2998 +
2999         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3000                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3001  
3002 diff -NurpP --minimal linux-3.5.4/fs/ext4/ext4.h linux-3.5.4-vs2.3.4.3/fs/ext4/ext4.h
3003 --- linux-3.5.4/fs/ext4/ext4.h  2012-09-16 20:46:31.000000000 +0200
3004 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/ext4.h        2012-08-11 15:15:02.000000000 +0200
3005 @@ -393,8 +393,12 @@ struct flex_groups {
3006  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3007  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3008  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3009 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3010  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3011  
3012 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3013 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3014 +
3015  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3016  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3017  
3018 @@ -664,7 +668,7 @@ struct ext4_inode {
3019                         __le16  l_i_uid_high;   /* these 2 fields */
3020                         __le16  l_i_gid_high;   /* were reserved2[0] */
3021                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3022 -                       __le16  l_i_reserved;
3023 +                       __le16  l_i_tag;        /* Context Tag */
3024                 } linux2;
3025                 struct {
3026                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3027 @@ -782,6 +786,7 @@ do {                                                                               \
3028  #define i_gid_low      i_gid
3029  #define i_uid_high     osd2.linux2.l_i_uid_high
3030  #define i_gid_high     osd2.linux2.l_i_gid_high
3031 +#define i_raw_tag      osd2.linux2.l_i_tag
3032  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
3033  
3034  #elif defined(__GNU__)
3035 @@ -962,6 +967,7 @@ struct ext4_inode_info {
3036  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3037  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3038  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3039 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3040  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3041  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3042  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3043 @@ -2395,6 +2401,7 @@ extern int ext4_map_blocks(handle_t *han
3044                            struct ext4_map_blocks *map, int flags);
3045  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3046                         __u64 start, __u64 len);
3047 +extern int ext4_sync_flags(struct inode *, int, int);
3048  /* move_extent.c */
3049  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3050                              __u64 start_orig, __u64 start_donor,
3051 diff -NurpP --minimal linux-3.5.4/fs/ext4/file.c linux-3.5.4-vs2.3.4.3/fs/ext4/file.c
3052 --- linux-3.5.4/fs/ext4/file.c  2012-07-22 23:39:40.000000000 +0200
3053 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/file.c        2012-07-23 01:45:55.000000000 +0200
3054 @@ -258,5 +258,6 @@ const struct inode_operations ext4_file_
3055  #endif
3056         .get_acl        = ext4_get_acl,
3057         .fiemap         = ext4_fiemap,
3058 +       .sync_flags     = ext4_sync_flags,
3059  };
3060  
3061 diff -NurpP --minimal linux-3.5.4/fs/ext4/ialloc.c linux-3.5.4-vs2.3.4.3/fs/ext4/ialloc.c
3062 --- linux-3.5.4/fs/ext4/ialloc.c        2012-09-16 20:46:31.000000000 +0200
3063 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/ialloc.c      2012-08-11 15:15:02.000000000 +0200
3064 @@ -22,6 +22,7 @@
3065  #include <linux/random.h>
3066  #include <linux/bitops.h>
3067  #include <linux/blkdev.h>
3068 +#include <linux/vs_tag.h>
3069  #include <asm/byteorder.h>
3070  
3071  #include "ext4.h"
3072 @@ -844,6 +845,7 @@ got:
3073                 inode->i_mode = mode;
3074                 inode->i_uid = current_fsuid();
3075                 inode->i_gid = dir->i_gid;
3076 +               inode->i_tag = dx_current_fstag(sb);
3077         } else
3078                 inode_init_owner(inode, dir, mode);
3079  
3080 diff -NurpP --minimal linux-3.5.4/fs/ext4/inode.c linux-3.5.4-vs2.3.4.3/fs/ext4/inode.c
3081 --- linux-3.5.4/fs/ext4/inode.c 2012-09-16 20:46:31.000000000 +0200
3082 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/inode.c       2012-08-11 15:15:02.000000000 +0200
3083 @@ -37,6 +37,7 @@
3084  #include <linux/printk.h>
3085  #include <linux/slab.h>
3086  #include <linux/ratelimit.h>
3087 +#include <linux/vs_tag.h>
3088  
3089  #include "ext4_jbd2.h"
3090  #include "xattr.h"
3091 @@ -3645,41 +3646,64 @@ void ext4_set_inode_flags(struct inode *
3092  {
3093         unsigned int flags = EXT4_I(inode)->i_flags;
3094  
3095 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3096 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3097 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3098 +
3099 +       if (flags & EXT4_IMMUTABLE_FL)
3100 +               inode->i_flags |= S_IMMUTABLE;
3101 +       if (flags & EXT4_IXUNLINK_FL)
3102 +               inode->i_flags |= S_IXUNLINK;
3103 +
3104         if (flags & EXT4_SYNC_FL)
3105                 inode->i_flags |= S_SYNC;
3106         if (flags & EXT4_APPEND_FL)
3107                 inode->i_flags |= S_APPEND;
3108 -       if (flags & EXT4_IMMUTABLE_FL)
3109 -               inode->i_flags |= S_IMMUTABLE;
3110         if (flags & EXT4_NOATIME_FL)
3111                 inode->i_flags |= S_NOATIME;
3112         if (flags & EXT4_DIRSYNC_FL)
3113                 inode->i_flags |= S_DIRSYNC;
3114 +
3115 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3116 +
3117 +       if (flags & EXT4_BARRIER_FL)
3118 +               inode->i_vflags |= V_BARRIER;
3119 +       if (flags & EXT4_COW_FL)
3120 +               inode->i_vflags |= V_COW;
3121  }
3122  
3123  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3124  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3125  {
3126 -       unsigned int vfs_fl;
3127 +       unsigned int vfs_fl, vfs_vf;
3128         unsigned long old_fl, new_fl;
3129  
3130         do {
3131                 vfs_fl = ei->vfs_inode.i_flags;
3132 +               vfs_vf = ei->vfs_inode.i_vflags;
3133                 old_fl = ei->i_flags;
3134                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3135                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3136 -                               EXT4_DIRSYNC_FL);
3137 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3138 +                               EXT4_COW_FL);
3139 +
3140 +               if (vfs_fl & S_IMMUTABLE)
3141 +                       new_fl |= EXT4_IMMUTABLE_FL;
3142 +               if (vfs_fl & S_IXUNLINK)
3143 +                       new_fl |= EXT4_IXUNLINK_FL;
3144 +
3145                 if (vfs_fl & S_SYNC)
3146                         new_fl |= EXT4_SYNC_FL;
3147                 if (vfs_fl & S_APPEND)
3148                         new_fl |= EXT4_APPEND_FL;
3149 -               if (vfs_fl & S_IMMUTABLE)
3150 -                       new_fl |= EXT4_IMMUTABLE_FL;
3151                 if (vfs_fl & S_NOATIME)
3152                         new_fl |= EXT4_NOATIME_FL;
3153                 if (vfs_fl & S_DIRSYNC)
3154                         new_fl |= EXT4_DIRSYNC_FL;
3155 +
3156 +               if (vfs_vf & V_BARRIER)
3157 +                       new_fl |= EXT4_BARRIER_FL;
3158 +               if (vfs_vf & V_COW)
3159 +                       new_fl |= EXT4_COW_FL;
3160         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3161  }
3162  
3163 @@ -3771,8 +3795,10 @@ struct inode *ext4_iget(struct super_blo
3164                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3165                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3166         }
3167 -       i_uid_write(inode, i_uid);
3168 -       i_gid_write(inode, i_gid);
3169 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3170 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3171 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3172 +               le16_to_cpu(raw_inode->i_raw_tag));
3173         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3174  
3175         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3176 @@ -3995,8 +4021,8 @@ static int ext4_do_update_inode(handle_t
3177  
3178         ext4_get_inode_flags(ei);
3179         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3180 -       i_uid = i_uid_read(inode);
3181 -       i_gid = i_gid_read(inode);
3182 +       i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
3183 +       i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
3184         if (!(test_opt(inode->i_sb, NO_UID32))) {
3185                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3186                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3187 @@ -4019,6 +4045,9 @@ static int ext4_do_update_inode(handle_t
3188                 raw_inode->i_uid_high = 0;
3189                 raw_inode->i_gid_high = 0;
3190         }
3191 +#ifdef CONFIG_TAGGING_INTERN
3192 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3193 +#endif
3194         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3195  
3196         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3197 @@ -4204,7 +4233,8 @@ int ext4_setattr(struct dentry *dentry, 
3198         if (is_quota_modification(inode, attr))
3199                 dquot_initialize(inode);
3200         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3201 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3202 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3203 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3204                 handle_t *handle;
3205  
3206                 /* (user+group)*(old+new) structure, inode write (sb,
3207 @@ -4226,6 +4256,8 @@ int ext4_setattr(struct dentry *dentry, 
3208                         inode->i_uid = attr->ia_uid;
3209                 if (attr->ia_valid & ATTR_GID)
3210                         inode->i_gid = attr->ia_gid;
3211 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3212 +                       inode->i_tag = attr->ia_tag;
3213                 error = ext4_mark_inode_dirty(handle, inode);
3214                 ext4_journal_stop(handle);
3215         }
3216 diff -NurpP --minimal linux-3.5.4/fs/ext4/ioctl.c linux-3.5.4-vs2.3.4.3/fs/ext4/ioctl.c
3217 --- linux-3.5.4/fs/ext4/ioctl.c 2012-07-22 23:39:40.000000000 +0200
3218 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/ioctl.c       2012-07-23 01:45:55.000000000 +0200
3219 @@ -14,12 +14,40 @@
3220  #include <linux/compat.h>
3221  #include <linux/mount.h>
3222  #include <linux/file.h>
3223 +#include <linux/vs_tag.h>
3224  #include <asm/uaccess.h>
3225  #include "ext4_jbd2.h"
3226  #include "ext4.h"
3227  
3228  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3229  
3230 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3231 +{
3232 +       handle_t *handle = NULL;
3233 +       struct ext4_iloc iloc;
3234 +       int err;
3235 +
3236 +       handle = ext4_journal_start(inode, 1);
3237 +       if (IS_ERR(handle))
3238 +               return PTR_ERR(handle);
3239 +
3240 +       if (IS_SYNC(inode))
3241 +               ext4_handle_sync(handle);
3242 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3243 +       if (err)
3244 +               goto flags_err;
3245 +
3246 +       inode->i_flags = flags;
3247 +       inode->i_vflags = vflags;
3248 +       ext4_get_inode_flags(EXT4_I(inode));
3249 +       inode->i_ctime = ext4_current_time(inode);
3250 +
3251 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3252 +flags_err:
3253 +       ext4_journal_stop(handle);
3254 +       return err;
3255 +}
3256 +
3257  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3258  {
3259         struct inode *inode = filp->f_dentry->d_inode;
3260 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3261  
3262                 flags = ext4_mask_flags(inode->i_mode, flags);
3263  
3264 +               if (IS_BARRIER(inode)) {
3265 +                       vxwprintk_task(1, "messing with the barrier.");
3266 +                       return -EACCES;
3267 +               }
3268 +
3269                 err = -EPERM;
3270                 mutex_lock(&inode->i_mutex);
3271                 /* Is it quota file? Do not allow user to mess with it */
3272 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3273                  *
3274                  * This test looks nicer. Thanks to Pauline Middelink
3275                  */
3276 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3277 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3278 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3279 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3280                         if (!capable(CAP_LINUX_IMMUTABLE))
3281                                 goto flags_out;
3282                 }
3283 diff -NurpP --minimal linux-3.5.4/fs/ext4/namei.c linux-3.5.4-vs2.3.4.3/fs/ext4/namei.c
3284 --- linux-3.5.4/fs/ext4/namei.c 2012-09-16 20:46:31.000000000 +0200
3285 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/namei.c       2012-08-11 15:15:02.000000000 +0200
3286 @@ -34,6 +34,7 @@
3287  #include <linux/quotaops.h>
3288  #include <linux/buffer_head.h>
3289  #include <linux/bio.h>
3290 +#include <linux/vs_tag.h>
3291  #include "ext4.h"
3292  #include "ext4_jbd2.h"
3293  
3294 @@ -1199,6 +1200,7 @@ restart:
3295                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3296                                                     1, &bh);
3297                         }
3298 +               dx_propagate_tag(nd, inode);
3299                 }
3300                 if ((bh = bh_use[ra_ptr++]) == NULL)
3301                         goto next;
3302 @@ -2984,6 +2986,7 @@ const struct inode_operations ext4_dir_i
3303  #endif
3304         .get_acl        = ext4_get_acl,
3305         .fiemap         = ext4_fiemap,
3306 +       .sync_flags     = ext4_sync_flags,
3307  };
3308  
3309  const struct inode_operations ext4_special_inode_operations = {
3310 diff -NurpP --minimal linux-3.5.4/fs/ext4/super.c linux-3.5.4-vs2.3.4.3/fs/ext4/super.c
3311 --- linux-3.5.4/fs/ext4/super.c 2012-09-16 20:46:31.000000000 +0200
3312 +++ linux-3.5.4-vs2.3.4.3/fs/ext4/super.c       2012-08-27 13:24:16.000000000 +0200
3313 @@ -1232,6 +1232,7 @@ enum {
3314         Opt_inode_readahead_blks, Opt_journal_ioprio,
3315         Opt_dioread_nolock, Opt_dioread_lock,
3316         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3317 +       Opt_tag, Opt_notag, Opt_tagid
3318  };
3319  
3320  static const match_table_t tokens = {
3321 @@ -1310,6 +1311,9 @@ static const match_table_t tokens = {
3322         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3323         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3324         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3325 +       {Opt_tag, "tag"},
3326 +       {Opt_notag, "notag"},
3327 +       {Opt_tagid, "tagid=%u"},
3328         {Opt_err, NULL},
3329  };
3330  
3331 @@ -1556,6 +1560,20 @@ static int handle_mount_opt(struct super
3332                         return -1;
3333                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3334                 return 1;
3335 +#ifndef CONFIG_TAGGING_NONE
3336 +       case Opt_tag:
3337 +               set_opt(sb, TAGGED);
3338 +               return 1;
3339 +       case Opt_notag:
3340 +               clear_opt(sb, TAGGED);
3341 +               return 1;
3342 +#endif
3343 +#ifdef CONFIG_PROPAGATE
3344 +       case Opt_tagid:
3345 +               /* use args[0] */
3346 +               set_opt(sb, TAGGED);
3347 +               return 1;
3348 +#endif
3349         }
3350  
3351         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3352 @@ -3418,6 +3436,9 @@ static int ext4_fill_super(struct super_
3353                 }
3354         }
3355  
3356 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3357 +               sb->s_flags |= MS_TAGGED;
3358 +
3359         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3360                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3361  
3362 @@ -4574,6 +4595,14 @@ static int ext4_remount(struct super_blo
3363         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3364                 ext4_abort(sb, "Abort forced by user");
3365  
3366 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3367 +               !(sb->s_flags & MS_TAGGED)) {
3368 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3369 +                       sb->s_id);
3370 +               err = -EINVAL;
3371 +               goto restore_opts;
3372 +       }
3373 +
3374         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3375                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3376  
3377 diff -NurpP --minimal linux-3.5.4/fs/fcntl.c linux-3.5.4-vs2.3.4.3/fs/fcntl.c
3378 --- linux-3.5.4/fs/fcntl.c      2012-07-22 23:39:40.000000000 +0200
3379 +++ linux-3.5.4-vs2.3.4.3/fs/fcntl.c    2012-07-23 01:45:55.000000000 +0200
3380 @@ -20,6 +20,7 @@
3381  #include <linux/signal.h>
3382  #include <linux/rcupdate.h>
3383  #include <linux/pid_namespace.h>
3384 +#include <linux/vs_limit.h>
3385  
3386  #include <asm/poll.h>
3387  #include <asm/siginfo.h>
3388 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3389  
3390         if (tofree)
3391                 filp_close(tofree, files);
3392 +       else
3393 +               vx_openfd_inc(newfd);   /* fd was unused */
3394  
3395         return newfd;
3396  
3397 @@ -448,6 +451,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3398         filp = fget_raw_light(fd, &fput_needed);
3399         if (!filp)
3400                 goto out;
3401 +       if (!vx_files_avail(1))
3402 +               goto out;
3403  
3404         if (unlikely(filp->f_mode & FMODE_PATH)) {
3405                 if (!check_fcntl_cmd(cmd))
3406 diff -NurpP --minimal linux-3.5.4/fs/file.c linux-3.5.4-vs2.3.4.3/fs/file.c
3407 --- linux-3.5.4/fs/file.c       2012-05-21 18:07:20.000000000 +0200
3408 +++ linux-3.5.4-vs2.3.4.3/fs/file.c     2012-07-23 01:45:55.000000000 +0200
3409 @@ -21,6 +21,7 @@
3410  #include <linux/spinlock.h>
3411  #include <linux/rcupdate.h>
3412  #include <linux/workqueue.h>
3413 +#include <linux/vs_limit.h>
3414  
3415  struct fdtable_defer {
3416         spinlock_t lock;
3417 @@ -358,6 +359,8 @@ struct files_struct *dup_fd(struct files
3418                 struct file *f = *old_fds++;
3419                 if (f) {
3420                         get_file(f);
3421 +                       /* TODO: sum it first for check and performance */
3422 +                       vx_openfd_inc(open_files - i);
3423                 } else {
3424                         /*
3425                          * The fd may be claimed in the fd bitmap but not yet
3426 @@ -464,6 +467,7 @@ repeat:
3427         else
3428                 __clear_close_on_exec(fd, fdt);
3429         error = fd;
3430 +       vx_openfd_inc(fd);
3431  #if 1
3432         /* Sanity check */
3433         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3434 diff -NurpP --minimal linux-3.5.4/fs/file_table.c linux-3.5.4-vs2.3.4.3/fs/file_table.c
3435 --- linux-3.5.4/fs/file_table.c 2012-07-22 23:39:40.000000000 +0200
3436 +++ linux-3.5.4-vs2.3.4.3/fs/file_table.c       2012-07-23 01:45:55.000000000 +0200
3437 @@ -24,6 +24,8 @@
3438  #include <linux/percpu_counter.h>
3439  #include <linux/percpu.h>
3440  #include <linux/ima.h>
3441 +#include <linux/vs_limit.h>
3442 +#include <linux/vs_context.h>
3443  
3444  #include <linux/atomic.h>
3445  
3446 @@ -134,6 +136,8 @@ struct file *get_empty_filp(void)
3447         spin_lock_init(&f->f_lock);
3448         eventpoll_init_file(f);
3449         /* f->f_version: 0 */
3450 +       f->f_xid = vx_current_xid();
3451 +       vx_files_inc(f);
3452         return f;
3453  
3454  over:
3455 @@ -251,6 +255,8 @@ static void __fput(struct file *file)
3456         }
3457         fops_put(file->f_op);
3458         put_pid(file->f_owner.pid);
3459 +       vx_files_dec(file);
3460 +       file->f_xid = 0;
3461         file_sb_list_del(file);
3462         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3463                 i_readcount_dec(inode);
3464 @@ -381,6 +387,8 @@ void put_filp(struct file *file)
3465  {
3466         if (atomic_long_dec_and_test(&file->f_count)) {
3467                 security_file_free(file);
3468 +               vx_files_dec(file);
3469 +               file->f_xid = 0;
3470                 file_sb_list_del(file);
3471                 file_free(file);
3472         }
3473 diff -NurpP --minimal linux-3.5.4/fs/fs_struct.c linux-3.5.4-vs2.3.4.3/fs/fs_struct.c
3474 --- linux-3.5.4/fs/fs_struct.c  2012-05-21 18:07:20.000000000 +0200
3475 +++ linux-3.5.4-vs2.3.4.3/fs/fs_struct.c        2012-07-23 01:45:55.000000000 +0200
3476 @@ -4,6 +4,7 @@
3477  #include <linux/path.h>
3478  #include <linux/slab.h>
3479  #include <linux/fs_struct.h>
3480 +#include <linux/vserver/global.h>
3481  #include "internal.h"
3482  
3483  static inline void path_get_longterm(struct path *path)
3484 @@ -99,6 +100,7 @@ void free_fs_struct(struct fs_struct *fs
3485  {
3486         path_put_longterm(&fs->root);
3487         path_put_longterm(&fs->pwd);
3488 +       atomic_dec(&vs_global_fs);
3489         kmem_cache_free(fs_cachep, fs);
3490  }
3491  
3492 @@ -136,6 +138,7 @@ struct fs_struct *copy_fs_struct(struct 
3493                 fs->pwd = old->pwd;
3494                 path_get_longterm(&fs->pwd);
3495                 spin_unlock(&old->lock);
3496 +               atomic_inc(&vs_global_fs);
3497         }
3498         return fs;
3499  }
3500 diff -NurpP --minimal linux-3.5.4/fs/gfs2/file.c linux-3.5.4-vs2.3.4.3/fs/gfs2/file.c
3501 --- linux-3.5.4/fs/gfs2/file.c  2012-07-22 23:39:40.000000000 +0200
3502 +++ linux-3.5.4-vs2.3.4.3/fs/gfs2/file.c        2012-07-23 01:45:55.000000000 +0200
3503 @@ -142,6 +142,9 @@ static const u32 fsflags_to_gfs2[32] = {
3504         [7] = GFS2_DIF_NOATIME,
3505         [12] = GFS2_DIF_EXHASH,
3506         [14] = GFS2_DIF_INHERIT_JDATA,
3507 +       [27] = GFS2_DIF_IXUNLINK,
3508 +       [26] = GFS2_DIF_BARRIER,
3509 +       [29] = GFS2_DIF_COW,
3510  };
3511  
3512  static const u32 gfs2_to_fsflags[32] = {
3513 @@ -151,6 +154,9 @@ static const u32 gfs2_to_fsflags[32] = {
3514         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3515         [gfs2fl_ExHash] = FS_INDEX_FL,
3516         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3517 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3518 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3519 +       [gfs2fl_Cow] = FS_COW_FL,
3520  };
3521  
3522  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3523 @@ -181,12 +187,18 @@ void gfs2_set_inode_flags(struct inode *
3524  {
3525         struct gfs2_inode *ip = GFS2_I(inode);
3526         unsigned int flags = inode->i_flags;
3527 +       unsigned int vflags = inode->i_vflags;
3528 +
3529 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3530 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3531  
3532 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3533         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3534                 inode->i_flags |= S_NOSEC;
3535         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3536                 flags |= S_IMMUTABLE;
3537 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3538 +               flags |= S_IXUNLINK;
3539 +
3540         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3541                 flags |= S_APPEND;
3542         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3543 @@ -194,6 +206,43 @@ void gfs2_set_inode_flags(struct inode *
3544         if (ip->i_diskflags & GFS2_DIF_SYNC)
3545                 flags |= S_SYNC;
3546         inode->i_flags = flags;
3547 +
3548 +       vflags &= ~(V_BARRIER | V_COW);
3549 +
3550 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3551 +               vflags |= V_BARRIER;
3552 +       if (ip->i_diskflags & GFS2_DIF_COW)
3553 +               vflags |= V_COW;
3554 +       inode->i_vflags = vflags;
3555 +}
3556 +
3557 +void gfs2_get_inode_flags(struct inode *inode)
3558 +{
3559 +       struct gfs2_inode *ip = GFS2_I(inode);
3560 +       unsigned int flags = inode->i_flags;
3561 +       unsigned int vflags = inode->i_vflags;
3562 +
3563 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3564 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3565 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3566 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3567 +
3568 +       if (flags & S_IMMUTABLE)
3569 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3570 +       if (flags & S_IXUNLINK)
3571 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3572 +
3573 +       if (flags & S_APPEND)
3574 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3575 +       if (flags & S_NOATIME)
3576 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3577 +       if (flags & S_SYNC)
3578 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3579 +
3580 +       if (vflags & V_BARRIER)
3581 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3582 +       if (vflags & V_COW)
3583 +               ip->i_diskflags |= GFS2_DIF_COW;
3584  }
3585  
3586  /* Flags that can be set by user space */
3587 @@ -305,6 +354,37 @@ static int gfs2_set_flags(struct file *f
3588         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3589  }
3590  
3591 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3592 +{
3593 +       struct gfs2_inode *ip = GFS2_I(inode);
3594 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3595 +       struct buffer_head *bh;
3596 +       struct gfs2_holder gh;
3597 +       int error;
3598 +
3599 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3600 +       if (error)
3601 +               return error;
3602 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3603 +       if (error)
3604 +               goto out;
3605 +       error = gfs2_meta_inode_buffer(ip, &bh);
3606 +       if (error)
3607 +               goto out_trans_end;
3608 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3609 +       inode->i_flags = flags;
3610 +       inode->i_vflags = vflags;
3611 +       gfs2_get_inode_flags(inode);
3612 +       gfs2_dinode_out(ip, bh->b_data);
3613 +       brelse(bh);
3614 +       gfs2_set_aops(inode);
3615 +out_trans_end:
3616 +       gfs2_trans_end(sdp);
3617 +out:
3618 +       gfs2_glock_dq_uninit(&gh);
3619 +       return error;
3620 +}
3621 +
3622  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3623  {
3624         switch(cmd) {
3625 diff -NurpP --minimal linux-3.5.4/fs/gfs2/inode.h linux-3.5.4-vs2.3.4.3/fs/gfs2/inode.h
3626 --- linux-3.5.4/fs/gfs2/inode.h 2012-07-22 23:39:40.000000000 +0200
3627 +++ linux-3.5.4-vs2.3.4.3/fs/gfs2/inode.h       2012-07-23 01:45:55.000000000 +0200
3628 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3629  extern const struct file_operations gfs2_dir_fops_nolock;
3630  
3631  extern void gfs2_set_inode_flags(struct inode *inode);
3632 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3633   
3634  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3635  extern const struct file_operations gfs2_file_fops;
3636 diff -NurpP --minimal linux-3.5.4/fs/inode.c linux-3.5.4-vs2.3.4.3/fs/inode.c
3637 --- linux-3.5.4/fs/inode.c      2012-07-22 23:39:40.000000000 +0200
3638 +++ linux-3.5.4-vs2.3.4.3/fs/inode.c    2012-07-23 01:45:55.000000000 +0200
3639 @@ -17,6 +17,7 @@
3640  #include <linux/prefetch.h>
3641  #include <linux/buffer_head.h> /* for inode_has_buffers */
3642  #include <linux/ratelimit.h>
3643 +#include <linux/vs_tag.h>
3644  #include "internal.h"
3645  
3646  /*
3647 @@ -128,6 +129,9 @@ int inode_init_always(struct super_block
3648         struct address_space *const mapping = &inode->i_data;
3649  
3650         inode->i_sb = sb;
3651 +
3652 +       /* essential because of inode slab reuse */
3653 +       inode->i_tag = 0;
3654         inode->i_blkbits = sb->s_blocksize_bits;
3655         inode->i_flags = 0;
3656         atomic_set(&inode->i_count, 1);
3657 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3658         inode->i_bdev = NULL;
3659         inode->i_cdev = NULL;
3660         inode->i_rdev = 0;
3661 +       inode->i_mdev = 0;
3662         inode->dirtied_when = 0;
3663  
3664         if (security_inode_alloc(inode))
3665 @@ -470,6 +475,8 @@ void __insert_inode_hash(struct inode *i
3666  }
3667  EXPORT_SYMBOL(__insert_inode_hash);
3668  
3669 +EXPORT_SYMBOL_GPL(__iget);
3670 +
3671  /**
3672   *     __remove_inode_hash - remove an inode from the hash
3673   *     @inode: inode to unhash
3674 @@ -1786,9 +1793,11 @@ void init_special_inode(struct inode *in
3675         if (S_ISCHR(mode)) {
3676                 inode->i_fop = &def_chr_fops;
3677                 inode->i_rdev = rdev;
3678 +               inode->i_mdev = rdev;
3679         } else if (S_ISBLK(mode)) {
3680                 inode->i_fop = &def_blk_fops;
3681                 inode->i_rdev = rdev;
3682 +               inode->i_mdev = rdev;
3683         } else if (S_ISFIFO(mode))
3684                 inode->i_fop = &def_fifo_fops;
3685         else if (S_ISSOCK(mode))
3686 @@ -1817,6 +1826,7 @@ void inode_init_owner(struct inode *inod
3687         } else
3688                 inode->i_gid = current_fsgid();
3689         inode->i_mode = mode;
3690 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3691  }
3692  EXPORT_SYMBOL(inode_init_owner);
3693  
3694 diff -NurpP --minimal linux-3.5.4/fs/ioctl.c linux-3.5.4-vs2.3.4.3/fs/ioctl.c
3695 --- linux-3.5.4/fs/ioctl.c      2012-05-21 18:07:24.000000000 +0200
3696 +++ linux-3.5.4-vs2.3.4.3/fs/ioctl.c    2012-07-23 01:45:55.000000000 +0200
3697 @@ -15,6 +15,9 @@
3698  #include <linux/writeback.h>
3699  #include <linux/buffer_head.h>
3700  #include <linux/falloc.h>
3701 +#include <linux/proc_fs.h>
3702 +#include <linux/vserver/inode.h>
3703 +#include <linux/vs_tag.h>
3704  
3705  #include <asm/ioctls.h>
3706  
3707 diff -NurpP --minimal linux-3.5.4/fs/ioprio.c linux-3.5.4-vs2.3.4.3/fs/ioprio.c
3708 --- linux-3.5.4/fs/ioprio.c     2012-07-22 23:39:40.000000000 +0200
3709 +++ linux-3.5.4-vs2.3.4.3/fs/ioprio.c   2012-07-23 01:45:55.000000000 +0200
3710 @@ -28,6 +28,7 @@
3711  #include <linux/syscalls.h>
3712  #include <linux/security.h>
3713  #include <linux/pid_namespace.h>
3714 +#include <linux/vs_base.h>
3715  
3716  int set_task_ioprio(struct task_struct *task, int ioprio)
3717  {
3718 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3719                         else
3720                                 pgrp = find_vpid(who);
3721                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3722 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3723 +                                       continue;
3724                                 ret = set_task_ioprio(p, ioprio);
3725                                 if (ret)
3726                                         break;
3727 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3728                         else
3729                                 pgrp = find_vpid(who);
3730                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3731 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3732 +                                       continue;
3733                                 tmpio = get_task_ioprio(p);
3734                                 if (tmpio < 0)
3735                                         continue;
3736 diff -NurpP --minimal linux-3.5.4/fs/jfs/file.c linux-3.5.4-vs2.3.4.3/fs/jfs/file.c
3737 --- linux-3.5.4/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3738 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/file.c 2012-07-23 01:45:55.000000000 +0200
3739 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3740         if (is_quota_modification(inode, iattr))
3741                 dquot_initialize(inode);
3742         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3743 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3744 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3745 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3746                 rc = dquot_transfer(inode, iattr);
3747                 if (rc)
3748                         return rc;
3749 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3750  #ifdef CONFIG_JFS_POSIX_ACL
3751         .get_acl        = jfs_get_acl,
3752  #endif
3753 +       .sync_flags     = jfs_sync_flags,
3754  };
3755  
3756  const struct file_operations jfs_file_operations = {
3757 diff -NurpP --minimal linux-3.5.4/fs/jfs/ioctl.c linux-3.5.4-vs2.3.4.3/fs/jfs/ioctl.c
3758 --- linux-3.5.4/fs/jfs/ioctl.c  2012-03-19 19:47:25.000000000 +0100
3759 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/ioctl.c        2012-07-23 01:45:55.000000000 +0200
3760 @@ -11,6 +11,7 @@
3761  #include <linux/mount.h>
3762  #include <linux/time.h>
3763  #include <linux/sched.h>
3764 +#include <linux/mount.h>
3765  #include <asm/current.h>
3766  #include <asm/uaccess.h>
3767  
3768 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3769  }
3770  
3771  
3772 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3773 +{
3774 +       inode->i_flags = flags;
3775 +       inode->i_vflags = vflags;
3776 +       jfs_get_inode_flags(JFS_IP(inode));
3777 +       inode->i_ctime = CURRENT_TIME_SEC;
3778 +       mark_inode_dirty(inode);
3779 +       return 0;
3780 +}
3781 +
3782  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3783  {
3784         struct inode *inode = filp->f_dentry->d_inode;
3785 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3786                 if (!S_ISDIR(inode->i_mode))
3787                         flags &= ~JFS_DIRSYNC_FL;
3788  
3789 +               if (IS_BARRIER(inode)) {
3790 +                       vxwprintk_task(1, "messing with the barrier.");
3791 +                       return -EACCES;
3792 +               }
3793 +
3794                 /* Is it quota file? Do not allow user to mess with it */
3795                 if (IS_NOQUOTA(inode)) {
3796                         err = -EPERM;
3797 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3798                  * the relevant capability.
3799                  */
3800                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3801 -                       ((flags ^ oldflags) &
3802 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3803 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3804 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3805                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3806                                 mutex_unlock(&inode->i_mutex);
3807                                 err = -EPERM;
3808 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3809                         }
3810                 }
3811  
3812 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3813 +               flags &= JFS_FL_USER_MODIFIABLE;
3814                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3815                 jfs_inode->mode2 = flags;
3816  
3817 diff -NurpP --minimal linux-3.5.4/fs/jfs/jfs_dinode.h linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_dinode.h
3818 --- linux-3.5.4/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3819 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_dinode.h   2012-07-23 01:45:55.000000000 +0200
3820 @@ -161,9 +161,13 @@ struct dinode {
3821  
3822  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3823  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3824 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3825  
3826 -#define JFS_FL_USER_VISIBLE    0x03F80000
3827 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3828 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3829 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3830 +
3831 +#define JFS_FL_USER_VISIBLE    0x07F80000
3832 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3833  #define JFS_FL_INHERIT         0x03C80000
3834  
3835  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3836 diff -NurpP --minimal linux-3.5.4/fs/jfs/jfs_filsys.h linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_filsys.h
3837 --- linux-3.5.4/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3838 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_filsys.h   2012-07-23 01:45:55.000000000 +0200
3839 @@ -263,6 +263,7 @@
3840  #define JFS_NAME_MAX   255
3841  #define JFS_PATH_MAX   BPSIZE
3842  
3843 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3844  
3845  /*
3846   *     file system state (superblock state)
3847 diff -NurpP --minimal linux-3.5.4/fs/jfs/jfs_imap.c linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_imap.c
3848 --- linux-3.5.4/fs/jfs/jfs_imap.c       2012-01-09 16:14:54.000000000 +0100
3849 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_imap.c     2012-07-23 01:45:55.000000000 +0200
3850 @@ -46,6 +46,7 @@
3851  #include <linux/pagemap.h>
3852  #include <linux/quotaops.h>
3853  #include <linux/slab.h>
3854 +#include <linux/vs_tag.h>
3855  
3856  #include "jfs_incore.h"
3857  #include "jfs_inode.h"
3858 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3859  {
3860         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3861         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3862 +       uid_t uid;
3863 +       gid_t gid;
3864  
3865         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3866         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3867 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3868         }
3869         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3870  
3871 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3872 +       uid = le32_to_cpu(dip->di_uid);
3873 +       gid = le32_to_cpu(dip->di_gid);
3874 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3875 +
3876 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3877         if (sbi->uid == -1)
3878                 ip->i_uid = jfs_ip->saved_uid;
3879         else {
3880                 ip->i_uid = sbi->uid;
3881         }
3882  
3883 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3884 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3885         if (sbi->gid == -1)
3886                 ip->i_gid = jfs_ip->saved_gid;
3887         else {
3888 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3889         dip->di_size = cpu_to_le64(ip->i_size);
3890         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3891         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3892 -       if (sbi->uid == -1)
3893 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3894 -       else
3895 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3896 -       if (sbi->gid == -1)
3897 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3898 -       else
3899 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3900 +
3901 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3902 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3903 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3904 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3905 +
3906         jfs_get_inode_flags(jfs_ip);
3907         /*
3908          * mode2 is only needed for storing the higher order bits.
3909 diff -NurpP --minimal linux-3.5.4/fs/jfs/jfs_inode.c linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_inode.c
3910 --- linux-3.5.4/fs/jfs/jfs_inode.c      2012-01-09 16:14:54.000000000 +0100
3911 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_inode.c    2012-07-23 01:45:55.000000000 +0200
3912 @@ -18,6 +18,7 @@
3913  
3914  #include <linux/fs.h>
3915  #include <linux/quotaops.h>
3916 +#include <linux/vs_tag.h>
3917  #include "jfs_incore.h"
3918  #include "jfs_inode.h"
3919  #include "jfs_filsys.h"
3920 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3921  {
3922         unsigned int flags = JFS_IP(inode)->mode2;
3923  
3924 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3925 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3926 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3927 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3928  
3929         if (flags & JFS_IMMUTABLE_FL)
3930                 inode->i_flags |= S_IMMUTABLE;
3931 +       if (flags & JFS_IXUNLINK_FL)
3932 +               inode->i_flags |= S_IXUNLINK;
3933 +
3934 +       if (flags & JFS_SYNC_FL)
3935 +               inode->i_flags |= S_SYNC;
3936         if (flags & JFS_APPEND_FL)
3937                 inode->i_flags |= S_APPEND;
3938         if (flags & JFS_NOATIME_FL)
3939                 inode->i_flags |= S_NOATIME;
3940         if (flags & JFS_DIRSYNC_FL)
3941                 inode->i_flags |= S_DIRSYNC;
3942 -       if (flags & JFS_SYNC_FL)
3943 -               inode->i_flags |= S_SYNC;
3944 +
3945 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3946 +
3947 +       if (flags & JFS_BARRIER_FL)
3948 +               inode->i_vflags |= V_BARRIER;
3949 +       if (flags & JFS_COW_FL)
3950 +               inode->i_vflags |= V_COW;
3951  }
3952  
3953  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3954  {
3955         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3956 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3957 +
3958 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3959 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3960 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3961 +                          JFS_BARRIER_FL | JFS_COW_FL);
3962  
3963 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3964 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3965         if (flags & S_IMMUTABLE)
3966                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3967 +       if (flags & S_IXUNLINK)
3968 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3969 +
3970         if (flags & S_APPEND)
3971                 jfs_ip->mode2 |= JFS_APPEND_FL;
3972         if (flags & S_NOATIME)
3973 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3974                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3975         if (flags & S_SYNC)
3976                 jfs_ip->mode2 |= JFS_SYNC_FL;
3977 +
3978 +       if (vflags & V_BARRIER)
3979 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3980 +       if (vflags & V_COW)
3981 +               jfs_ip->mode2 |= JFS_COW_FL;
3982  }
3983  
3984  /*
3985 diff -NurpP --minimal linux-3.5.4/fs/jfs/jfs_inode.h linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_inode.h
3986 --- linux-3.5.4/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
3987 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/jfs_inode.h    2012-07-23 01:45:55.000000000 +0200
3988 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3989  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3990         int fh_len, int fh_type);
3991  extern void jfs_set_inode_flags(struct inode *);
3992 +extern int jfs_sync_flags(struct inode *, int, int);
3993  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3994  extern int jfs_setattr(struct dentry *, struct iattr *);
3995  
3996 diff -NurpP --minimal linux-3.5.4/fs/jfs/namei.c linux-3.5.4-vs2.3.4.3/fs/jfs/namei.c
3997 --- linux-3.5.4/fs/jfs/namei.c  2012-05-21 18:07:25.000000000 +0200
3998 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/namei.c        2012-07-23 01:45:55.000000000 +0200
3999 @@ -22,6 +22,7 @@
4000  #include <linux/ctype.h>
4001  #include <linux/quotaops.h>
4002  #include <linux/exportfs.h>
4003 +#include <linux/vs_tag.h>
4004  #include "jfs_incore.h"
4005  #include "jfs_superblock.h"
4006  #include "jfs_inode.h"
4007 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct 
4008                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4009         }
4010  
4011 +       dx_propagate_tag(nd, ip);
4012         return d_splice_alias(ip, dentry);
4013  }
4014  
4015 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4016  #ifdef CONFIG_JFS_POSIX_ACL
4017         .get_acl        = jfs_get_acl,
4018  #endif
4019 +       .sync_flags     = jfs_sync_flags,
4020  };
4021  
4022  const struct file_operations jfs_dir_operations = {
4023 diff -NurpP --minimal linux-3.5.4/fs/jfs/super.c linux-3.5.4-vs2.3.4.3/fs/jfs/super.c
4024 --- linux-3.5.4/fs/jfs/super.c  2012-05-21 18:07:25.000000000 +0200
4025 +++ linux-3.5.4-vs2.3.4.3/fs/jfs/super.c        2012-07-23 01:45:55.000000000 +0200
4026 @@ -197,7 +197,8 @@ static void jfs_put_super(struct super_b
4027  enum {
4028         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4029         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4030 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4031 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4032 +       Opt_tag, Opt_notag, Opt_tagid
4033  };
4034  
4035  static const match_table_t tokens = {
4036 @@ -207,6 +208,10 @@ static const match_table_t tokens = {
4037         {Opt_resize, "resize=%u"},
4038         {Opt_resize_nosize, "resize"},
4039         {Opt_errors, "errors=%s"},
4040 +       {Opt_tag, "tag"},
4041 +       {Opt_notag, "notag"},
4042 +       {Opt_tagid, "tagid=%u"},
4043 +       {Opt_tag, "tagxid"},
4044         {Opt_ignore, "noquota"},
4045         {Opt_ignore, "quota"},
4046         {Opt_usrquota, "usrquota"},
4047 @@ -341,6 +346,20 @@ static int parse_options(char *options, 
4048                         }
4049                         break;
4050                 }
4051 +#ifndef CONFIG_TAGGING_NONE
4052 +               case Opt_tag:
4053 +                       *flag |= JFS_TAGGED;
4054 +                       break;
4055 +               case Opt_notag:
4056 +                       *flag &= JFS_TAGGED;
4057 +                       break;
4058 +#endif
4059 +#ifdef CONFIG_PROPAGATE
4060 +               case Opt_tagid:
4061 +                       /* use args[0] */
4062 +                       *flag |= JFS_TAGGED;
4063 +                       break;
4064 +#endif
4065                 default:
4066                         printk("jfs: Unrecognized mount option \"%s\" "
4067                                         " or missing value\n", p);
4068 @@ -372,6 +391,12 @@ static int jfs_remount(struct super_bloc
4069                 return -EINVAL;
4070         }
4071  
4072 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4073 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4074 +                       sb->s_id);
4075 +               return -EINVAL;
4076 +       }
4077 +
4078         if (newLVSize) {
4079                 if (sb->s_flags & MS_RDONLY) {
4080                         printk(KERN_ERR
4081 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4082  #ifdef CONFIG_JFS_POSIX_ACL
4083         sb->s_flags |= MS_POSIXACL;
4084  #endif
4085 +       /* map mount option tagxid */
4086 +       if (sbi->flag & JFS_TAGGED)
4087 +               sb->s_flags |= MS_TAGGED;
4088  
4089         if (newLVSize) {
4090                 printk(KERN_ERR "resize option for remount only\n");
4091 diff -NurpP --minimal linux-3.5.4/fs/libfs.c linux-3.5.4-vs2.3.4.3/fs/libfs.c
4092 --- linux-3.5.4/fs/libfs.c      2012-07-22 23:39:40.000000000 +0200
4093 +++ linux-3.5.4-vs2.3.4.3/fs/libfs.c    2012-07-23 01:45:55.000000000 +0200
4094 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4095   * both impossible due to the lock on directory.
4096   */
4097  
4098 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4099 +static inline int do_dcache_readdir_filter(struct file *filp,
4100 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4101  {
4102         struct dentry *dentry = filp->f_path.dentry;
4103         struct dentry *cursor = filp->private_data;
4104 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4105                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4106                                 struct dentry *next;
4107                                 next = list_entry(p, struct dentry, d_u.d_child);
4108 +                               if (filter && !filter(next))
4109 +                                       continue;
4110                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4111                                 if (!simple_positive(next)) {
4112                                         spin_unlock(&next->d_lock);
4113 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4114         return 0;
4115  }
4116  
4117 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4118 +{
4119 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4120 +}
4121 +
4122 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4123 +       int (*filter)(struct dentry *))
4124 +{
4125 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4126 +}
4127 +
4128  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4129  {
4130         return -EISDIR;
4131 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4132  EXPORT_SYMBOL(dcache_dir_lseek);
4133  EXPORT_SYMBOL(dcache_dir_open);
4134  EXPORT_SYMBOL(dcache_readdir);
4135 +EXPORT_SYMBOL(dcache_readdir_filter);
4136  EXPORT_SYMBOL(generic_read_dir);
4137  EXPORT_SYMBOL(mount_pseudo);
4138  EXPORT_SYMBOL(simple_write_begin);
4139 diff -NurpP --minimal linux-3.5.4/fs/locks.c linux-3.5.4-vs2.3.4.3/fs/locks.c
4140 --- linux-3.5.4/fs/locks.c      2012-09-16 20:46:31.000000000 +0200
4141 +++ linux-3.5.4-vs2.3.4.3/fs/locks.c    2012-08-11 15:15:02.000000000 +0200
4142 @@ -126,6 +126,8 @@
4143  #include <linux/time.h>
4144  #include <linux/rcupdate.h>
4145  #include <linux/pid_namespace.h>
4146 +#include <linux/vs_base.h>
4147 +#include <linux/vs_limit.h>
4148  
4149  #include <asm/uaccess.h>
4150  
4151 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4152  /* Allocate an empty lock structure. */
4153  struct file_lock *locks_alloc_lock(void)
4154  {
4155 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4156 +       struct file_lock *fl;
4157  
4158 -       if (fl)
4159 -               locks_init_lock_heads(fl);
4160 +       if (!vx_locks_avail(1))
4161 +               return NULL;
4162  
4163 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4164 +
4165 +       if (fl) {
4166 +               locks_init_lock_heads(fl);
4167 +               fl->fl_xid = -1;
4168 +       }
4169         return fl;
4170  }
4171  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4172 @@ -216,6 +224,7 @@ void locks_free_lock(struct file_lock *f
4173         BUG_ON(!list_empty(&fl->fl_block));
4174         BUG_ON(!list_empty(&fl->fl_link));
4175  
4176 +       vx_locks_dec(fl);
4177         locks_release_private(fl);
4178         kmem_cache_free(filelock_cache, fl);
4179  }
4180 @@ -225,6 +234,7 @@ void locks_init_lock(struct file_lock *f
4181  {
4182         memset(fl, 0, sizeof(struct file_lock));
4183         locks_init_lock_heads(fl);
4184 +       fl->fl_xid = -1;
4185  }
4186  
4187  EXPORT_SYMBOL(locks_init_lock);
4188 @@ -265,6 +275,7 @@ void locks_copy_lock(struct file_lock *n
4189         new->fl_file = fl->fl_file;
4190         new->fl_ops = fl->fl_ops;
4191         new->fl_lmops = fl->fl_lmops;
4192 +       new->fl_xid = fl->fl_xid;
4193  
4194         locks_copy_private(new, fl);
4195  }
4196 @@ -303,6 +314,11 @@ static int flock_make_lock(struct file *
4197         fl->fl_flags = FL_FLOCK;
4198         fl->fl_type = type;
4199         fl->fl_end = OFFSET_MAX;
4200 +
4201 +       vxd_assert(filp->f_xid == vx_current_xid(),
4202 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4203 +       fl->fl_xid = filp->f_xid;
4204 +       vx_locks_inc(fl);
4205         
4206         *lock = fl;
4207         return 0;
4208 @@ -452,6 +468,7 @@ static int lease_init(struct file *filp,
4209  
4210         fl->fl_owner = current->files;
4211         fl->fl_pid = current->tgid;
4212 +       fl->fl_xid = vx_current_xid();
4213  
4214         fl->fl_file = filp;
4215         fl->fl_flags = FL_LEASE;
4216 @@ -471,6 +488,11 @@ static struct file_lock *lease_alloc(str
4217         if (fl == NULL)
4218                 return ERR_PTR(error);
4219  
4220 +       fl->fl_xid = vx_current_xid();
4221 +       if (filp)
4222 +               vxd_assert(filp->f_xid == fl->fl_xid,
4223 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4224 +       vx_locks_inc(fl);
4225         error = lease_init(filp, type, fl);
4226         if (error) {
4227                 locks_free_lock(fl);
4228 @@ -773,6 +795,7 @@ static int flock_lock_file(struct file *
4229                 lock_flocks();
4230         }
4231  
4232 +       new_fl->fl_xid = -1;
4233  find_conflict:
4234         for_each_lock(inode, before) {
4235                 struct file_lock *fl = *before;
4236 @@ -793,6 +816,7 @@ find_conflict:
4237                 goto out;
4238         locks_copy_lock(new_fl, request);
4239         locks_insert_lock(before, new_fl);
4240 +       vx_locks_inc(new_fl);
4241         new_fl = NULL;
4242         error = 0;
4243  
4244 @@ -803,7 +827,8 @@ out:
4245         return error;
4246  }
4247  
4248 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4249 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4250 +       struct file_lock *conflock, xid_t xid)
4251  {
4252         struct file_lock *fl;
4253         struct file_lock *new_fl = NULL;
4254 @@ -813,6 +838,8 @@ static int __posix_lock_file(struct inod
4255         struct file_lock **before;
4256         int error, added = 0;
4257  
4258 +       vxd_assert(xid == vx_current_xid(),
4259 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4260         /*
4261          * We may need two file_lock structures for this operation,
4262          * so we get them in advance to avoid races.
4263 @@ -823,7 +850,11 @@ static int __posix_lock_file(struct inod
4264             (request->fl_type != F_UNLCK ||
4265              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4266                 new_fl = locks_alloc_lock();
4267 +               new_fl->fl_xid = xid;
4268 +               vx_locks_inc(new_fl);
4269                 new_fl2 = locks_alloc_lock();
4270 +               new_fl2->fl_xid = xid;
4271 +               vx_locks_inc(new_fl2);
4272         }
4273  
4274         lock_flocks();
4275 @@ -1022,7 +1053,8 @@ static int __posix_lock_file(struct inod
4276  int posix_lock_file(struct file *filp, struct file_lock *fl,
4277                         struct file_lock *conflock)
4278  {
4279 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4280 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4281 +               fl, conflock, filp->f_xid);
4282  }
4283  EXPORT_SYMBOL(posix_lock_file);
4284  
4285 @@ -1112,7 +1144,7 @@ int locks_mandatory_area(int read_write,
4286         fl.fl_end = offset + count - 1;
4287  
4288         for (;;) {
4289 -               error = __posix_lock_file(inode, &fl, NULL);
4290 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4291                 if (error != FILE_LOCK_DEFERRED)
4292                         break;
4293                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4294 @@ -1407,6 +1439,7 @@ int generic_add_lease(struct file *filp,
4295                 goto out;
4296  
4297         locks_insert_lock(before, lease);
4298 +       vx_locks_inc(lease);
4299         return 0;
4300  
4301  out:
4302 @@ -1848,6 +1881,11 @@ int fcntl_setlk(unsigned int fd, struct 
4303         if (file_lock == NULL)
4304                 return -ENOLCK;
4305  
4306 +       vxd_assert(filp->f_xid == vx_current_xid(),
4307 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4308 +       file_lock->fl_xid = filp->f_xid;
4309 +       vx_locks_inc(file_lock);
4310 +
4311         /*
4312          * This might block, so we do it before checking the inode.
4313          */
4314 @@ -1966,6 +2004,11 @@ int fcntl_setlk64(unsigned int fd, struc
4315         if (file_lock == NULL)
4316                 return -ENOLCK;
4317  
4318 +       vxd_assert(filp->f_xid == vx_current_xid(),
4319 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4320 +       file_lock->fl_xid = filp->f_xid;
4321 +       vx_locks_inc(file_lock);
4322 +
4323         /*
4324          * This might block, so we do it before checking the inode.
4325          */
4326 @@ -2231,8 +2274,11 @@ static int locks_show(struct seq_file *f
4327  
4328         lock_get_status(f, fl, *((loff_t *)f->private), "");
4329  
4330 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4331 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4332 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4333 +                       continue;
4334                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4335 +       }
4336  
4337         return 0;
4338  }
4339 diff -NurpP --minimal linux-3.5.4/fs/mount.h linux-3.5.4-vs2.3.4.3/fs/mount.h
4340 --- linux-3.5.4/fs/mount.h      2012-03-19 19:47:26.000000000 +0100
4341 +++ linux-3.5.4-vs2.3.4.3/fs/mount.h    2012-07-23 01:45:55.000000000 +0200
4342 @@ -47,6 +47,7 @@ struct mount {
4343         int mnt_expiry_mark;            /* true if marked for expiry */
4344         int mnt_pinned;
4345         int mnt_ghosts;
4346 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4347  };
4348  
4349  static inline struct mount *real_mount(struct vfsmount *mnt)
4350 diff -NurpP --minimal linux-3.5.4/fs/namei.c linux-3.5.4-vs2.3.4.3/fs/namei.c
4351 --- linux-3.5.4/fs/namei.c      2012-07-22 23:39:41.000000000 +0200
4352 +++ linux-3.5.4-vs2.3.4.3/fs/namei.c    2012-07-23 10:46:40.000000000 +0200
4353 @@ -34,6 +34,14 @@
4354  #include <linux/device_cgroup.h>
4355  #include <linux/fs_struct.h>
4356  #include <linux/posix_acl.h>
4357 +#include <linux/proc_fs.h>
4358 +#include <linux/vserver/inode.h>
4359 +#include <linux/vs_base.h>
4360 +#include <linux/vs_tag.h>
4361 +#include <linux/vs_cowbl.h>
4362 +#include <linux/vs_device.h>
4363 +#include <linux/vs_context.h>
4364 +#include <linux/pid_namespace.h>
4365  #include <asm/uaccess.h>
4366  
4367  #include "internal.h"
4368 @@ -212,6 +220,89 @@ static int check_acl(struct inode *inode
4369         return -EAGAIN;
4370  }
4371  
4372 +static inline int dx_barrier(const struct inode *inode)
4373 +{
4374 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4375 +               vxwprintk_task(1, "did hit the barrier.");
4376 +               return 1;
4377 +       }
4378 +       return 0;
4379 +}
4380 +
4381 +static int __dx_permission(const struct inode *inode, int mask)
4382 +{
4383 +       if (dx_barrier(inode))
4384 +               return -EACCES;
4385 +
4386 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4387 +               /* devpts is xid tagged */
4388 +               if (S_ISDIR(inode->i_mode) ||
4389 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4390 +                       return 0;
4391 +
4392 +               /* just pretend we didn't find anything */
4393 +               return -ENOENT;
4394 +       }
4395 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4396 +               struct proc_dir_entry *de = PDE(inode);
4397 +
4398 +               if (de && !vx_hide_check(0, de->vx_flags))
4399 +                       goto out;
4400 +
4401 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4402 +                       struct pid *pid;
4403 +                       struct task_struct *tsk;
4404 +
4405 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4406 +                           vx_flags(VXF_STATE_SETUP, 0))
4407 +                               return 0;
4408 +
4409 +                       pid = PROC_I(inode)->pid;
4410 +                       if (!pid)
4411 +                               goto out;
4412 +
4413 +                       rcu_read_lock();
4414 +                       tsk = pid_task(pid, PIDTYPE_PID);
4415 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4416 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4417 +                       if (tsk &&
4418 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4419 +                               rcu_read_unlock();
4420 +                               return 0;
4421 +                       }
4422 +                       rcu_read_unlock();
4423 +               }
4424 +               else {
4425 +                       /* FIXME: Should we block some entries here? */
4426 +                       return 0;
4427 +               }
4428 +       }
4429 +       else {
4430 +               if (dx_notagcheck(inode->i_sb) ||
4431 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4432 +                            DX_IDENT))
4433 +                       return 0;
4434 +       }
4435 +
4436 +out:
4437 +       return -EACCES;
4438 +}
4439 +
4440 +int dx_permission(const struct inode *inode, int mask)
4441 +{
4442 +       int ret = __dx_permission(inode, mask);
4443 +       if (unlikely(ret)) {
4444 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4445 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4446 +#endif
4447 +                   vxwprintk_task(1,
4448 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4449 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4450 +                       inode->i_ino);
4451 +       }
4452 +       return ret;
4453 +}
4454 +
4455  /*
4456   * This does the basic permission checking
4457   */
4458 @@ -343,10 +434,14 @@ int inode_permission(struct inode *inode
4459                 /*
4460                  * Nobody gets write access to an immutable file.
4461                  */
4462 -               if (IS_IMMUTABLE(inode))
4463 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4464                         return -EACCES;
4465         }
4466  
4467 +       retval = dx_permission(inode, mask);
4468 +       if (retval)
4469 +               return retval;
4470 +
4471         retval = do_inode_permission(inode, mask);
4472         if (retval)
4473                 return retval;
4474 @@ -1025,7 +1120,8 @@ static void follow_dotdot(struct nameida
4475  
4476                 if (nd->path.dentry == nd->root.dentry &&
4477                     nd->path.mnt == nd->root.mnt) {
4478 -                       break;
4479 +                       /* for sane '/' avoid follow_mount() */
4480 +                       return;
4481                 }
4482                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4483                         /* rare case of legitimate dget_parent()... */
4484 @@ -1174,6 +1270,9 @@ static int lookup_fast(struct nameidata 
4485                                 goto unlazy;
4486                         }
4487                 }
4488 +
4489 +               /* FIXME: check dx permission */
4490 +
4491                 path->mnt = mnt;
4492                 path->dentry = dentry;
4493                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4494 @@ -1209,6 +1308,8 @@ unlazy:
4495                 }
4496         }
4497  
4498 +       /* FIXME: check dx permission */
4499 +
4500         path->mnt = mnt;
4501         path->dentry = dentry;
4502         err = follow_managed(path, nd->flags);
4503 @@ -2010,7 +2111,7 @@ static int may_delete(struct inode *dir,
4504         if (IS_APPEND(dir))
4505                 return -EPERM;
4506         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4507 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4508 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4509                 return -EPERM;
4510         if (isdir) {
4511                 if (!S_ISDIR(victim->d_inode->i_mode))
4512 @@ -2090,19 +2191,25 @@ int vfs_create(struct inode *dir, struct
4513  {
4514         int error = may_create(dir, dentry);
4515  
4516 -       if (error)
4517 +       if (error) {
4518 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4519                 return error;
4520 +       }
4521  
4522         if (!dir->i_op->create)
4523                 return -EACCES; /* shouldn't it be ENOSYS? */
4524         mode &= S_IALLUGO;
4525         mode |= S_IFREG;
4526         error = security_inode_create(dir, dentry, mode);
4527 -       if (error)
4528 +       if (error) {
4529 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4530                 return error;
4531 +       }
4532         error = dir->i_op->create(dir, dentry, mode, nd);
4533         if (!error)
4534                 fsnotify_create(dir, dentry);
4535 +       else
4536 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4537         return error;
4538  }
4539  
4540 @@ -2137,6 +2244,15 @@ static int may_open(struct path *path, i
4541                 break;
4542         }
4543  
4544 +#ifdef CONFIG_VSERVER_COWBL
4545 +       if (IS_COW(inode) &&
4546 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4547 +               if (IS_COW_LINK(inode))
4548 +                       return -EMLINK;
4549 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4550 +               mark_inode_dirty(inode);
4551 +       }
4552 +#endif
4553         error = inode_permission(inode, acc_mode);
4554         if (error)
4555                 return error;
4556 @@ -2386,6 +2502,16 @@ ok:
4557         }
4558  common:
4559         error = may_open(&nd->path, acc_mode, open_flag);
4560 +#ifdef CONFIG_VSERVER_COWBL
4561 +       if (error == -EMLINK) {
4562 +               struct dentry *dentry;
4563 +               dentry = cow_break_link(pathname);
4564 +               if (IS_ERR(dentry))
4565 +                       error = PTR_ERR(dentry);
4566 +               else
4567 +                       dput(dentry);
4568 +       }
4569 +#endif
4570         if (error)
4571                 goto exit;
4572         filp = nameidata_to_filp(nd);
4573 @@ -2443,6 +2569,7 @@ static struct file *path_openat(int dfd,
4574         struct path path;
4575         int error;
4576  
4577 +restart:
4578         filp = get_empty_filp();
4579         if (!filp)
4580                 return ERR_PTR(-ENFILE);
4581 @@ -2480,6 +2607,17 @@ static struct file *path_openat(int dfd,
4582                         filp = do_last(nd, &path, op, pathname);
4583                 put_link(nd, &link, cookie);
4584         }
4585 +
4586 +#ifdef CONFIG_VSERVER_COWBL
4587 +       if (filp == ERR_PTR(-EMLINK)) {
4588 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4589 +                       path_put(&nd->root);
4590 +               if (base)
4591 +                       fput(base);
4592 +               release_open_intent(nd);
4593 +               goto restart;
4594 +       }
4595 +#endif
4596  out:
4597         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4598                 path_put(&nd->root);
4599 @@ -2575,6 +2713,11 @@ struct dentry *kern_path_create(int dfd,
4600                 goto fail;
4601         }
4602         *path = nd.path;
4603 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4604 +               path->dentry, path->dentry->d_name.len,
4605 +               path->dentry->d_name.name, dentry,
4606 +               dentry->d_name.len, dentry->d_name.name,
4607 +               path->dentry->d_inode);
4608         return dentry;
4609  eexist:
4610         dput(dentry);
4611 @@ -3060,7 +3203,7 @@ int vfs_link(struct dentry *old_dentry, 
4612         /*
4613          * A link to an append-only or immutable file cannot be created.
4614          */
4615 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4616 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4617                 return -EPERM;
4618         if (!dir->i_op->link)
4619                 return -EPERM;
4620 @@ -3449,6 +3592,253 @@ int vfs_follow_link(struct nameidata *nd
4621         return __vfs_follow_link(nd, link);
4622  }
4623  
4624 +
4625 +#ifdef CONFIG_VSERVER_COWBL
4626 +
4627 +static inline
4628 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4629 +{
4630 +       loff_t ppos = 0;
4631 +
4632 +       return do_splice_direct(in, &ppos, out, len, 0);
4633 +}
4634 +
4635 +extern unsigned int mnt_get_count(struct mount *mnt);
4636 +
4637 +struct dentry *cow_break_link(const char *pathname)
4638 +{
4639 +       int ret, mode, pathlen, redo = 0;
4640 +       struct nameidata old_nd, dir_nd;
4641 +       struct path old_path, dir_path;
4642 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4643 +       struct file *old_file;
4644 +       struct file *new_file;
4645 +       char *to, *path, pad='\251';
4646 +       loff_t size;
4647 +
4648 +       vxdprintk(VXD_CBIT(misc, 1),
4649 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4650 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4651 +       ret = -ENOMEM;
4652 +       if (!path)
4653 +               goto out;
4654 +
4655 +       /* old_nd will have refs to dentry and mnt */
4656 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4657 +       vxdprintk(VXD_CBIT(misc, 2),
4658 +               "do_path_lookup(old): %d [r=%d]",
4659 +               ret, mnt_get_count(real_mount(old_nd.path.mnt)));
4660 +       if (ret < 0)
4661 +               goto out_free_path;
4662 +
4663 +       old_path = old_nd.path;
4664 +       old_dentry = old_path.dentry;
4665 +       mode = old_dentry->d_inode->i_mode;
4666 +
4667 +       to = d_path(&old_path, path, PATH_MAX-2);
4668 +       pathlen = strlen(to);
4669 +       vxdprintk(VXD_CBIT(misc, 2),
4670 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4671 +               old_dentry,
4672 +               old_dentry->d_name.len, old_dentry->d_name.name,
4673 +               old_dentry->d_name.len);
4674 +
4675 +       to[pathlen + 1] = 0;
4676 +retry:
4677 +       new_dentry = NULL;
4678 +       to[pathlen] = pad--;
4679 +       ret = -ELOOP;
4680 +       if (pad <= '\240')
4681 +               goto out_rel_old;
4682 +
4683 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4684 +       /* dir_nd will have refs to dentry and mnt */
4685 +       ret = do_path_lookup(AT_FDCWD, to,
4686 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4687 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4688 +       if (ret < 0)
4689 +               goto retry;
4690 +
4691 +       /* this puppy downs the dir inode mutex if successful */
4692 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4693 +       if (!new_dentry || IS_ERR(new_dentry)) {
4694 +               path_put(&dir_nd.path);
4695 +               vxdprintk(VXD_CBIT(misc, 2),
4696 +                       "kern_path_create(new) failed with %ld",
4697 +                       PTR_ERR(new_dentry));
4698 +               goto retry;
4699 +       }
4700 +       path_put(&dir_path);
4701 +       vxdprintk(VXD_CBIT(misc, 2),
4702 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4703 +               new_dentry,
4704 +               new_dentry->d_name.len, new_dentry->d_name.name,
4705 +               new_dentry->d_name.len);
4706 +
4707 +       dir = dir_nd.path.dentry;
4708 +
4709 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4710 +       vxdprintk(VXD_CBIT(misc, 2),
4711 +               "vfs_create(new): %d", ret);
4712 +       if (ret == -EEXIST) {
4713 +               mutex_unlock(&dir->d_inode->i_mutex);
4714 +               path_put(&dir_nd.path);
4715 +               dput(new_dentry);
4716 +               goto retry;
4717 +       }
4718 +       else if (ret < 0)
4719 +               goto out_unlock_new;
4720 +
4721 +       /* drop out early, ret passes ENOENT */
4722 +       ret = -ENOENT;
4723 +       if ((redo = d_unhashed(old_dentry)))
4724 +               goto out_unlock_new;
4725 +
4726 +       path_get(&old_path);
4727 +       /* this one cleans up the dentry/mnt in case of failure */
4728 +       old_file = dentry_open(old_dentry, old_path.mnt,
4729 +               O_RDONLY, current_cred());
4730 +       vxdprintk(VXD_CBIT(misc, 2),
4731 +               "dentry_open(old): %p", old_file);
4732 +       if (IS_ERR(old_file)) {
4733 +               ret = PTR_ERR(old_file);
4734 +               goto out_unlock_new;
4735 +       }
4736 +
4737 +       dget(new_dentry);
4738 +       mntget(old_path.mnt);
4739 +       /* this one cleans up the dentry/mnt in case of failure */
4740 +       new_file = dentry_open(new_dentry, old_path.mnt,
4741 +               O_WRONLY, current_cred());
4742 +       vxdprintk(VXD_CBIT(misc, 2),
4743 +               "dentry_open(new): %p", new_file);
4744 +       if (IS_ERR(new_file)) {
4745 +               ret = PTR_ERR(new_file);
4746 +               goto out_fput_old;
4747 +       }
4748 +
4749 +       size = i_size_read(old_file->f_dentry->d_inode);
4750 +       ret = do_cow_splice(old_file, new_file, size);
4751 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4752 +       if (ret < 0) {
4753 +               goto out_fput_both;
4754 +       } else if (ret < size) {
4755 +               ret = -ENOSPC;
4756 +               goto out_fput_both;
4757 +       } else {
4758 +               struct inode *old_inode = old_dentry->d_inode;
4759 +               struct inode *new_inode = new_dentry->d_inode;
4760 +               struct iattr attr = {
4761 +                       .ia_uid = old_inode->i_uid,
4762 +                       .ia_gid = old_inode->i_gid,
4763 +                       .ia_valid = ATTR_UID | ATTR_GID
4764 +                       };
4765 +
4766 +               setattr_copy(new_inode, &attr);
4767 +               mark_inode_dirty(new_inode);
4768 +       }
4769 +
4770 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4771 +
4772 +       /* drop out late */
4773 +       ret = -ENOENT;
4774 +       if ((redo = d_unhashed(old_dentry)))
4775 +               goto out_unlock;
4776 +
4777 +       vxdprintk(VXD_CBIT(misc, 2),
4778 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4779 +               new_dentry->d_name.len, new_dentry->d_name.name,
4780 +               new_dentry->d_name.len,
4781 +               old_dentry->d_name.len, old_dentry->d_name.name,
4782 +               old_dentry->d_name.len);
4783 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4784 +               old_dentry->d_parent->d_inode, old_dentry);
4785 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4786 +
4787 +out_unlock:
4788 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4789 +
4790 +out_fput_both:
4791 +       vxdprintk(VXD_CBIT(misc, 3),
4792 +               "fput(new_file=%p[#%ld])", new_file,
4793 +               atomic_long_read(&new_file->f_count));
4794 +       fput(new_file);
4795 +
4796 +out_fput_old:
4797 +       vxdprintk(VXD_CBIT(misc, 3),
4798 +               "fput(old_file=%p[#%ld])", old_file,
4799 +               atomic_long_read(&old_file->f_count));
4800 +       fput(old_file);
4801 +
4802 +out_unlock_new:
4803 +       mutex_unlock(&dir->d_inode->i_mutex);
4804 +       if (!ret)
4805 +               goto out_redo;
4806 +
4807 +       /* error path cleanup */
4808 +       vfs_unlink(dir->d_inode, new_dentry);
4809 +
4810 +out_redo:
4811 +       if (!redo)
4812 +               goto out_rel_both;
4813 +       /* lookup dentry once again */
4814 +       /* old_nd.path is freed as old_path in out_rel_old */
4815 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4816 +       if (ret)
4817 +               goto out_rel_both;
4818 +
4819 +       dput(new_dentry);
4820 +       new_dentry = old_nd.path.dentry;
4821 +       vxdprintk(VXD_CBIT(misc, 2),
4822 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4823 +               new_dentry,
4824 +               new_dentry->d_name.len, new_dentry->d_name.name,
4825 +               new_dentry->d_name.len);
4826 +       dget(new_dentry);
4827 +
4828 +out_rel_both:
4829 +       path_put(&dir_nd.path);
4830 +out_rel_old:
4831 +       path_put(&old_path);
4832 +out_free_path:
4833 +       kfree(path);
4834 +out:
4835 +       if (ret) {
4836 +               dput(new_dentry);
4837 +               new_dentry = ERR_PTR(ret);
4838 +       }
4839 +       vxdprintk(VXD_CBIT(misc, 3),
4840 +               "cow_break_link returning with %p [r=%d]",
4841 +               new_dentry, mnt_get_count(real_mount(old_nd.path.mnt)));
4842 +       return new_dentry;
4843 +}
4844 +
4845 +#endif
4846 +
4847 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4848 +{
4849 +       struct path path;
4850 +       struct vfsmount *vmnt;
4851 +       char *pstr, *root;
4852 +       int length = 0;
4853 +
4854 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4855 +       if (!pstr)
4856 +               return 0;
4857 +
4858 +       vmnt = &ns->root->mnt;
4859 +       path.mnt = vmnt;
4860 +       path.dentry = vmnt->mnt_root;
4861 +       root = d_path(&path, pstr, PATH_MAX - 2);
4862 +       length = sprintf(buffer + length,
4863 +               "Namespace:\t%p [#%u]\n"
4864 +               "RootPath:\t%s\n",
4865 +               ns, atomic_read(&ns->count),
4866 +               root);
4867 +       kfree(pstr);
4868 +       return length;
4869 +}
4870 +
4871  /* get the link contents into pagecache */
4872  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4873  {
4874 @@ -3573,3 +3963,4 @@ EXPORT_SYMBOL(vfs_symlink);
4875  EXPORT_SYMBOL(vfs_unlink);
4876  EXPORT_SYMBOL(dentry_unhash);
4877  EXPORT_SYMBOL(generic_readlink);
4878 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4879 diff -NurpP --minimal linux-3.5.4/fs/namespace.c linux-3.5.4-vs2.3.4.3/fs/namespace.c
4880 --- linux-3.5.4/fs/namespace.c  2012-07-22 23:39:41.000000000 +0200
4881 +++ linux-3.5.4-vs2.3.4.3/fs/namespace.c        2012-07-23 10:44:12.000000000 +0200
4882 @@ -20,6 +20,11 @@
4883  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4884  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4885  #include <linux/uaccess.h>
4886 +#include <linux/vs_base.h>
4887 +#include <linux/vs_context.h>
4888 +#include <linux/vs_tag.h>
4889 +#include <linux/vserver/space.h>
4890 +#include <linux/vserver/global.h>
4891  #include "pnode.h"
4892  #include "internal.h"
4893  
4894 @@ -697,6 +702,10 @@ vfs_kern_mount(struct file_system_type *
4895         if (!type)
4896                 return ERR_PTR(-ENODEV);
4897  
4898 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4899 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4900 +               return ERR_PTR(-EPERM);
4901 +
4902         mnt = alloc_vfsmnt(name);
4903         if (!mnt)
4904                 return ERR_PTR(-ENOMEM);
4905 @@ -745,6 +754,7 @@ static struct mount *clone_mnt(struct mo
4906                 mnt->mnt.mnt_root = dget(root);
4907                 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4908                 mnt->mnt_parent = mnt;
4909 +               mnt->mnt_tag = old->mnt_tag;
4910                 br_write_lock(&vfsmount_lock);
4911                 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4912                 br_write_unlock(&vfsmount_lock);
4913 @@ -1211,7 +1221,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4914                 goto dput_and_out;
4915  
4916         retval = -EPERM;
4917 -       if (!capable(CAP_SYS_ADMIN))
4918 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4919                 goto dput_and_out;
4920  
4921         retval = do_umount(mnt, flags);
4922 @@ -1237,7 +1247,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4923  
4924  static int mount_is_safe(struct path *path)
4925  {
4926 -       if (capable(CAP_SYS_ADMIN))
4927 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4928                 return 0;
4929         return -EPERM;
4930  #ifdef notyet
4931 @@ -1550,7 +1560,7 @@ static int do_change_type(struct path *p
4932         int type;
4933         int err = 0;
4934  
4935 -       if (!capable(CAP_SYS_ADMIN))
4936 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4937                 return -EPERM;
4938  
4939         if (path->dentry != path->mnt->mnt_root)
4940 @@ -1566,6 +1576,7 @@ static int do_change_type(struct path *p
4941                 if (err)
4942                         goto out_unlock;
4943         }
4944 +       // mnt->mnt_flags = mnt_flags;
4945  
4946         br_write_lock(&vfsmount_lock);
4947         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4948 @@ -1581,12 +1592,14 @@ static int do_change_type(struct path *p
4949   * do loopback mount.
4950   */
4951  static int do_loopback(struct path *path, char *old_name,
4952 -                               int recurse)
4953 +       tag_t tag, unsigned long flags, int mnt_flags)
4954  {
4955         LIST_HEAD(umount_list);
4956         struct path old_path;
4957         struct mount *mnt = NULL, *old;
4958         int err = mount_is_safe(path);
4959 +       int recurse = flags & MS_REC;
4960 +
4961         if (err)
4962                 return err;
4963         if (!old_name || !*old_name)
4964 @@ -1654,13 +1667,13 @@ static int change_mount_flags(struct vfs
4965   * on it - tough luck.
4966   */
4967  static int do_remount(struct path *path, int flags, int mnt_flags,
4968 -                     void *data)
4969 +       void *data, xid_t xid)
4970  {
4971         int err;
4972         struct super_block *sb = path->mnt->mnt_sb;
4973         struct mount *mnt = real_mount(path->mnt);
4974  
4975 -       if (!capable(CAP_SYS_ADMIN))
4976 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
4977                 return -EPERM;
4978  
4979         if (!check_mnt(mnt))
4980 @@ -1709,7 +1722,7 @@ static int do_move_mount(struct path *pa
4981         struct mount *p;
4982         struct mount *old;
4983         int err = 0;
4984 -       if (!capable(CAP_SYS_ADMIN))
4985 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4986                 return -EPERM;
4987         if (!old_name || !*old_name)
4988                 return -EINVAL;
4989 @@ -1860,7 +1873,7 @@ static int do_new_mount(struct path *pat
4990                 return -EINVAL;
4991  
4992         /* we need capabilities... */
4993 -       if (!capable(CAP_SYS_ADMIN))
4994 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4995                 return -EPERM;
4996  
4997         mnt = do_kern_mount(type, flags, name, data);
4998 @@ -2130,6 +2143,7 @@ long do_mount(char *dev_name, char *dir_
4999         struct path path;
5000         int retval = 0;
5001         int mnt_flags = 0;
5002 +       tag_t tag = 0;
5003  
5004         /* Discard magic */
5005         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5006 @@ -2157,6 +2171,12 @@ long do_mount(char *dev_name, char *dir_
5007         if (!(flags & MS_NOATIME))
5008                 mnt_flags |= MNT_RELATIME;
5009  
5010 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5011 +               /* FIXME: bind and re-mounts get the tag flag? */
5012 +               if (flags & (MS_BIND|MS_REMOUNT))
5013 +                       flags |= MS_TAGID;
5014 +       }
5015 +
5016         /* Separate the per-mountpoint flags */
5017         if (flags & MS_NOSUID)
5018                 mnt_flags |= MNT_NOSUID;
5019 @@ -2173,15 +2193,17 @@ long do_mount(char *dev_name, char *dir_
5020         if (flags & MS_RDONLY)
5021                 mnt_flags |= MNT_READONLY;
5022  
5023 +       if (!capable(CAP_SYS_ADMIN))
5024 +               mnt_flags |= MNT_NODEV;
5025         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5026                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5027                    MS_STRICTATIME);
5028  
5029         if (flags & MS_REMOUNT)
5030                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5031 -                                   data_page);
5032 +                                   data_page, tag);
5033         else if (flags & MS_BIND)
5034 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5035 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5036         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5037                 retval = do_change_type(&path, flags);
5038         else if (flags & MS_MOVE)
5039 @@ -2284,6 +2306,7 @@ static struct mnt_namespace *dup_mnt_ns(
5040                 q = next_mnt(q, new);
5041         }
5042         up_write(&namespace_sem);
5043 +       atomic_inc(&vs_global_mnt_ns);
5044  
5045         if (rootmnt)
5046                 mntput(rootmnt);
5047 @@ -2480,9 +2503,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5048         error = -EINVAL;
5049         new_mnt = real_mount(new.mnt);
5050         root_mnt = real_mount(root.mnt);
5051 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5052 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5053                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5054 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5055 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5056 +               !vx_flags(VXF_STATE_SETUP, 0))
5057                 goto out4;
5058         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5059                 goto out4;
5060 @@ -2603,6 +2627,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5061         br_write_unlock(&vfsmount_lock);
5062         up_write(&namespace_sem);
5063         release_mounts(&umount_list);
5064 +       atomic_dec(&vs_global_mnt_ns);
5065         kfree(ns);
5066  }
5067  
5068 diff -NurpP --minimal linux-3.5.4/fs/nfs/client.c linux-3.5.4-vs2.3.4.3/fs/nfs/client.c
5069 --- linux-3.5.4/fs/nfs/client.c 2012-07-22 23:39:41.000000000 +0200
5070 +++ linux-3.5.4-vs2.3.4.3/fs/nfs/client.c       2012-07-23 01:45:55.000000000 +0200
5071 @@ -797,6 +797,9 @@ static int nfs_init_server_rpcclient(str
5072         if (server->flags & NFS_MOUNT_SOFT)
5073                 server->client->cl_softrtry = 1;
5074  
5075 +       server->client->cl_tag = 0;
5076 +       if (server->flags & NFS_MOUNT_TAGGED)
5077 +               server->client->cl_tag = 1;
5078         return 0;
5079  }
5080  
5081 @@ -990,6 +993,10 @@ static void nfs_server_set_fsinfo(struct
5082                 server->acdirmin = server->acdirmax = 0;
5083         }
5084  
5085 +       /* FIXME: needs fsinfo
5086 +       if (server->flags & NFS_MOUNT_TAGGED)
5087 +               sb->s_flags |= MS_TAGGED;       */
5088 +
5089         server->maxfilesize = fsinfo->maxfilesize;
5090  
5091         server->time_delta = fsinfo->time_delta;
5092 diff -NurpP --minimal linux-3.5.4/fs/nfs/dir.c linux-3.5.4-vs2.3.4.3/fs/nfs/dir.c
5093 --- linux-3.5.4/fs/nfs/dir.c    2012-07-22 23:39:41.000000000 +0200
5094 +++ linux-3.5.4-vs2.3.4.3/fs/nfs/dir.c  2012-07-23 01:45:55.000000000 +0200
5095 @@ -35,6 +35,7 @@
5096  #include <linux/sched.h>
5097  #include <linux/kmemleak.h>
5098  #include <linux/xattr.h>
5099 +#include <linux/vs_tag.h>
5100  
5101  #include "delegation.h"
5102  #include "iostat.h"
5103 @@ -1337,6 +1338,7 @@ static struct dentry *nfs_lookup(struct 
5104         /* Success: notify readdir to use READDIRPLUS */
5105         nfs_advise_use_readdirplus(dir);
5106  
5107 +       dx_propagate_tag(nd, inode);
5108  no_entry:
5109         res = d_materialise_unique(dentry, inode);
5110         if (res != NULL) {
5111 diff -NurpP --minimal linux-3.5.4/fs/nfs/inode.c linux-3.5.4-vs2.3.4.3/fs/nfs/inode.c
5112 --- linux-3.5.4/fs/nfs/inode.c  2012-07-22 23:39:41.000000000 +0200
5113 +++ linux-3.5.4-vs2.3.4.3/fs/nfs/inode.c        2012-07-23 10:48:04.000000000 +0200
5114 @@ -40,6 +40,7 @@
5115  #include <linux/compat.h>
5116  #include <linux/freezer.h>
5117  #include <linux/crc32.h>
5118 +#include <linux/vs_tag.h>
5119  
5120  #include <asm/uaccess.h>
5121  
5122 @@ -275,6 +276,8 @@ nfs_fhget(struct super_block *sb, struct
5123         if (inode->i_state & I_NEW) {
5124                 struct nfs_inode *nfsi = NFS_I(inode);
5125                 unsigned long now = jiffies;
5126 +               uid_t uid;
5127 +               gid_t gid;
5128  
5129                 /* We set i_ino for the few things that still rely on it,
5130                  * such as stat(2) */
5131 @@ -319,8 +322,8 @@ nfs_fhget(struct super_block *sb, struct
5132                 inode->i_version = 0;
5133                 inode->i_size = 0;
5134                 clear_nlink(inode);
5135 -               inode->i_uid = -2;
5136 -               inode->i_gid = -2;
5137 +               uid = -2;
5138 +               gid = -2;
5139                 inode->i_blocks = 0;
5140                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5141                 nfsi->write_io = 0;
5142 @@ -354,11 +357,11 @@ nfs_fhget(struct super_block *sb, struct
5143                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5144                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5145                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5146 -                       inode->i_uid = fattr->uid;
5147 +                       uid = fattr->uid;
5148                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5149                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5150                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5151 -                       inode->i_gid = fattr->gid;
5152 +                       gid = fattr->gid;
5153                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5154                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5155                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5156 @@ -369,6 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5157                          */
5158                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5159                 }
5160 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5161 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5162 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5163 +                               /* maybe fattr->xid someday */
5164 +
5165                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5166                 nfsi->attrtimeo_timestamp = now;
5167                 nfsi->access_cache = RB_ROOT;
5168 @@ -488,6 +496,8 @@ void nfs_setattr_update_inode(struct ino
5169                         inode->i_uid = attr->ia_uid;
5170                 if ((attr->ia_valid & ATTR_GID) != 0)
5171                         inode->i_gid = attr->ia_gid;
5172 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5173 +                       inode->i_tag = attr->ia_tag;
5174                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5175                 spin_unlock(&inode->i_lock);
5176         }
5177 @@ -947,6 +957,9 @@ static int nfs_check_inode_attributes(st
5178         struct nfs_inode *nfsi = NFS_I(inode);
5179         loff_t cur_size, new_isize;
5180         unsigned long invalid = 0;
5181 +       uid_t uid;
5182 +       gid_t gid;
5183 +       tag_t tag;
5184  
5185  
5186         if (nfs_have_delegated_attributes(inode))
5187 @@ -972,13 +985,18 @@ static int nfs_check_inode_attributes(st
5188                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5189         }
5190  
5191 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5192 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5193 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5194 +
5195         /* Have any file permissions changed? */
5196         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5197                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5198 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5199 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5200                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5201 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5202 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5203                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5204 +               /* maybe check for tag too? */
5205  
5206         /* Has the link count changed? */
5207         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5208 @@ -1276,6 +1294,9 @@ static int nfs_update_inode(struct inode
5209         unsigned long invalid = 0;
5210         unsigned long now = jiffies;
5211         unsigned long save_cache_validity;
5212 +       uid_t uid;
5213 +       gid_t gid;
5214 +       tag_t tag;
5215  
5216         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5217                         __func__, inode->i_sb->s_id, inode->i_ino,
5218 @@ -1377,6 +1398,9 @@ static int nfs_update_inode(struct inode
5219                                 | NFS_INO_REVAL_PAGECACHE
5220                                 | NFS_INO_REVAL_FORCED);
5221  
5222 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5223 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5224 +       tag = inode->i_tag;
5225  
5226         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5227                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5228 @@ -1398,9 +1422,9 @@ static int nfs_update_inode(struct inode
5229                                 | NFS_INO_REVAL_FORCED);
5230  
5231         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5232 -               if (inode->i_uid != fattr->uid) {
5233 +               if (uid != fattr->uid) {
5234                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5235 -                       inode->i_uid = fattr->uid;
5236 +                       uid = fattr->uid;
5237                 }
5238         } else if (server->caps & NFS_CAP_OWNER)
5239                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5240 @@ -1409,9 +1433,9 @@ static int nfs_update_inode(struct inode
5241                                 | NFS_INO_REVAL_FORCED);
5242  
5243         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5244 -               if (inode->i_gid != fattr->gid) {
5245 +               if (gid != fattr->gid) {
5246                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5247 -                       inode->i_gid = fattr->gid;
5248 +                       gid = fattr->gid;
5249                 }
5250         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5251                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5252 @@ -1419,6 +1443,10 @@ static int nfs_update_inode(struct inode
5253                                 | NFS_INO_INVALID_ACL
5254                                 | NFS_INO_REVAL_FORCED);
5255  
5256 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5257 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5258 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5259 +
5260         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5261                 if (inode->i_nlink != fattr->nlink) {
5262                         invalid |= NFS_INO_INVALID_ATTR;
5263 diff -NurpP --minimal linux-3.5.4/fs/nfs/nfs3xdr.c linux-3.5.4-vs2.3.4.3/fs/nfs/nfs3xdr.c
5264 --- linux-3.5.4/fs/nfs/nfs3xdr.c        2012-07-22 23:39:41.000000000 +0200
5265 +++ linux-3.5.4-vs2.3.4.3/fs/nfs/nfs3xdr.c      2012-07-23 01:45:55.000000000 +0200
5266 @@ -20,6 +20,7 @@
5267  #include <linux/nfs3.h>
5268  #include <linux/nfs_fs.h>
5269  #include <linux/nfsacl.h>
5270 +#include <linux/vs_tag.h>
5271  #include "internal.h"
5272  
5273  #define NFSDBG_FACILITY                NFSDBG_XDR
5274 @@ -564,7 +565,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5275   *             set_mtime       mtime;
5276   *     };
5277   */
5278 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5279 +static void encode_sattr3(struct xdr_stream *xdr,
5280 +       const struct iattr *attr, int tag)
5281  {
5282         u32 nbytes;
5283         __be32 *p;
5284 @@ -596,15 +598,19 @@ static void encode_sattr3(struct xdr_str
5285         } else
5286                 *p++ = xdr_zero;
5287  
5288 -       if (attr->ia_valid & ATTR_UID) {
5289 +       if (attr->ia_valid & ATTR_UID ||
5290 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5291                 *p++ = xdr_one;
5292 -               *p++ = cpu_to_be32(attr->ia_uid);
5293 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5294 +                       attr->ia_uid, attr->ia_tag));
5295         } else
5296                 *p++ = xdr_zero;
5297  
5298 -       if (attr->ia_valid & ATTR_GID) {
5299 +       if (attr->ia_valid & ATTR_GID ||
5300 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5301                 *p++ = xdr_one;
5302 -               *p++ = cpu_to_be32(attr->ia_gid);
5303 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5304 +                       attr->ia_gid, attr->ia_tag));
5305         } else
5306                 *p++ = xdr_zero;
5307  
5308 @@ -883,7 +889,7 @@ static void nfs3_xdr_enc_setattr3args(st
5309                                       const struct nfs3_sattrargs *args)
5310  {
5311         encode_nfs_fh3(xdr, args->fh);
5312 -       encode_sattr3(xdr, args->sattr);
5313 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5314         encode_sattrguard3(xdr, args);
5315  }
5316  
5317 @@ -1033,13 +1039,13 @@ static void nfs3_xdr_enc_write3args(stru
5318   *     };
5319   */
5320  static void encode_createhow3(struct xdr_stream *xdr,
5321 -                             const struct nfs3_createargs *args)
5322 +       const struct nfs3_createargs *args, int tag)
5323  {
5324         encode_uint32(xdr, args->createmode);
5325         switch (args->createmode) {
5326         case NFS3_CREATE_UNCHECKED:
5327         case NFS3_CREATE_GUARDED:
5328 -               encode_sattr3(xdr, args->sattr);
5329 +               encode_sattr3(xdr, args->sattr, tag);
5330                 break;
5331         case NFS3_CREATE_EXCLUSIVE:
5332                 encode_createverf3(xdr, args->verifier);
5333 @@ -1054,7 +1060,7 @@ static void nfs3_xdr_enc_create3args(str
5334                                      const struct nfs3_createargs *args)
5335  {
5336         encode_diropargs3(xdr, args->fh, args->name, args->len);
5337 -       encode_createhow3(xdr, args);
5338 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5339  }
5340  
5341  /*
5342 @@ -1070,7 +1076,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5343                                     const struct nfs3_mkdirargs *args)
5344  {
5345         encode_diropargs3(xdr, args->fh, args->name, args->len);
5346 -       encode_sattr3(xdr, args->sattr);
5347 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5348  }
5349  
5350  /*
5351 @@ -1087,9 +1093,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5352   *     };
5353   */
5354  static void encode_symlinkdata3(struct xdr_stream *xdr,
5355 -                               const struct nfs3_symlinkargs *args)
5356 +       const struct nfs3_symlinkargs *args, int tag)
5357  {
5358 -       encode_sattr3(xdr, args->sattr);
5359 +       encode_sattr3(xdr, args->sattr, tag);
5360         encode_nfspath3(xdr, args->pages, args->pathlen);
5361  }
5362  
5363 @@ -1098,7 +1104,7 @@ static void nfs3_xdr_enc_symlink3args(st
5364                                       const struct nfs3_symlinkargs *args)
5365  {
5366         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5367 -       encode_symlinkdata3(xdr, args);
5368 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5369  }
5370  
5371  /*
5372 @@ -1126,24 +1132,24 @@ static void nfs3_xdr_enc_symlink3args(st
5373   *     };
5374   */
5375  static void encode_devicedata3(struct xdr_stream *xdr,
5376 -                              const struct nfs3_mknodargs *args)
5377 +       const struct nfs3_mknodargs *args, int tag)
5378  {
5379 -       encode_sattr3(xdr, args->sattr);
5380 +       encode_sattr3(xdr, args->sattr, tag);
5381         encode_specdata3(xdr, args->rdev);
5382  }
5383  
5384  static void encode_mknoddata3(struct xdr_stream *xdr,
5385 -                             const struct nfs3_mknodargs *args)
5386 +       const struct nfs3_mknodargs *args, int tag)
5387  {
5388         encode_ftype3(xdr, args->type);
5389         switch (args->type) {
5390         case NF3CHR:
5391         case NF3BLK:
5392 -               encode_devicedata3(xdr, args);
5393 +               encode_devicedata3(xdr, args, tag);
5394                 break;
5395         case NF3SOCK:
5396         case NF3FIFO:
5397 -               encode_sattr3(xdr, args->sattr);
5398 +               encode_sattr3(xdr, args->sattr, tag);
5399                 break;
5400         case NF3REG:
5401         case NF3DIR:
5402 @@ -1158,7 +1164,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5403                                     const struct nfs3_mknodargs *args)
5404  {
5405         encode_diropargs3(xdr, args->fh, args->name, args->len);
5406 -       encode_mknoddata3(xdr, args);
5407 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5408  }
5409  
5410  /*
5411 diff -NurpP --minimal linux-3.5.4/fs/nfs/super.c linux-3.5.4-vs2.3.4.3/fs/nfs/super.c
5412 --- linux-3.5.4/fs/nfs/super.c  2012-09-16 20:46:31.000000000 +0200
5413 +++ linux-3.5.4-vs2.3.4.3/fs/nfs/super.c        2012-09-16 20:50:19.000000000 +0200
5414 @@ -54,6 +54,7 @@
5415  #include <linux/parser.h>
5416  #include <linux/nsproxy.h>
5417  #include <linux/rcupdate.h>
5418 +#include <linux/vs_tag.h>
5419  
5420  #include <asm/uaccess.h>
5421  
5422 @@ -87,6 +88,7 @@ enum {
5423         Opt_sharecache, Opt_nosharecache,
5424         Opt_resvport, Opt_noresvport,
5425         Opt_fscache, Opt_nofscache,
5426 +       Opt_tag, Opt_notag,
5427  
5428         /* Mount options that take integer arguments */
5429         Opt_port,
5430 @@ -99,6 +101,7 @@ enum {
5431         Opt_mountport,
5432         Opt_mountvers,
5433         Opt_minorversion,
5434 +       Opt_tagid,
5435  
5436         /* Mount options that take string arguments */
5437         Opt_nfsvers,
5438 @@ -181,6 +184,10 @@ static const match_table_t nfs_mount_opt
5439         /* The following needs to be listed after all other options */
5440         { Opt_nfsvers, "v%s" },
5441  
5442 +       { Opt_tag, "tag" },
5443 +       { Opt_notag, "notag" },
5444 +       { Opt_tagid, "tagid=%u" },
5445 +
5446         { Opt_err, NULL }
5447  };
5448  
5449 @@ -684,6 +691,7 @@ static void nfs_show_mount_options(struc
5450                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5451                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5452                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5453 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5454                 { 0, NULL, NULL }
5455         };
5456         const struct proc_nfs_info *nfs_infop;
5457 @@ -1296,6 +1304,14 @@ static int nfs_parse_mount_options(char 
5458                         kfree(mnt->fscache_uniq);
5459                         mnt->fscache_uniq = NULL;
5460                         break;
5461 +#ifndef CONFIG_TAGGING_NONE
5462 +               case Opt_tag:
5463 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5464 +                       break;
5465 +               case Opt_notag:
5466 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5467 +                       break;
5468 +#endif
5469  
5470                 /*
5471                  * options that take numeric values
5472 @@ -1382,6 +1398,12 @@ static int nfs_parse_mount_options(char 
5473                                 goto out_invalid_value;
5474                         mnt->minorversion = option;
5475                         break;
5476 +#ifdef CONFIG_PROPAGATE
5477 +               case Opt_tagid:
5478 +                       /* use args[0] */
5479 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5480 +                       break;
5481 +#endif
5482  
5483                 /*
5484                  * options that take text values
5485 diff -NurpP --minimal linux-3.5.4/fs/nfsd/auth.c linux-3.5.4-vs2.3.4.3/fs/nfsd/auth.c
5486 --- linux-3.5.4/fs/nfsd/auth.c  2012-07-22 23:39:41.000000000 +0200
5487 +++ linux-3.5.4-vs2.3.4.3/fs/nfsd/auth.c        2012-07-23 10:47:00.000000000 +0200
5488 @@ -2,6 +2,7 @@
5489  
5490  #include <linux/sched.h>
5491  #include <linux/user_namespace.h>
5492 +#include <linux/vs_tag.h>
5493  #include "nfsd.h"
5494  #include "auth.h"
5495  
5496 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5497  
5498         new->fsuid = rqstp->rq_cred.cr_uid;
5499         new->fsgid = rqstp->rq_cred.cr_gid;
5500 +       /* FIXME: this desperately needs a tag :)
5501 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5502 +                       */
5503  
5504         rqgi = rqstp->rq_cred.cr_group_info;
5505  
5506 diff -NurpP --minimal linux-3.5.4/fs/nfsd/nfs3xdr.c linux-3.5.4-vs2.3.4.3/fs/nfsd/nfs3xdr.c
5507 --- linux-3.5.4/fs/nfsd/nfs3xdr.c       2012-05-21 18:07:26.000000000 +0200
5508 +++ linux-3.5.4-vs2.3.4.3/fs/nfsd/nfs3xdr.c     2012-07-23 01:45:55.000000000 +0200
5509 @@ -7,6 +7,7 @@
5510   */
5511  
5512  #include <linux/namei.h>
5513 +#include <linux/vs_tag.h>
5514  #include "xdr3.h"
5515  #include "auth.h"
5516  
5517 @@ -95,6 +96,8 @@ static __be32 *
5518  decode_sattr3(__be32 *p, struct iattr *iap)
5519  {
5520         u32     tmp;
5521 +       uid_t   uid = 0;
5522 +       gid_t   gid = 0;
5523  
5524         iap->ia_valid = 0;
5525  
5526 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5527         }
5528         if (*p++) {
5529                 iap->ia_valid |= ATTR_UID;
5530 -               iap->ia_uid = ntohl(*p++);
5531 +               uid = ntohl(*p++);
5532         }
5533         if (*p++) {
5534                 iap->ia_valid |= ATTR_GID;
5535 -               iap->ia_gid = ntohl(*p++);
5536 +               gid = ntohl(*p++);
5537         }
5538 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5539 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5540 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5541         if (*p++) {
5542                 u64     newsize;
5543  
5544 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5545         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5546         *p++ = htonl((u32) stat->mode);
5547         *p++ = htonl((u32) stat->nlink);
5548 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5549 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5550 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5551 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5552 +               stat->uid, stat->tag)));
5553 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5554 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5555 +               stat->gid, stat->tag)));
5556         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5557                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5558         } else {
5559 diff -NurpP --minimal linux-3.5.4/fs/nfsd/nfs4xdr.c linux-3.5.4-vs2.3.4.3/fs/nfsd/nfs4xdr.c
5560 --- linux-3.5.4/fs/nfsd/nfs4xdr.c       2012-09-16 20:46:31.000000000 +0200
5561 +++ linux-3.5.4-vs2.3.4.3/fs/nfsd/nfs4xdr.c     2012-08-11 15:15:02.000000000 +0200
5562 @@ -46,6 +46,7 @@
5563  #include <linux/utsname.h>
5564  #include <linux/pagemap.h>
5565  #include <linux/sunrpc/svcauth_gss.h>
5566 +#include <linux/vs_tag.h>
5567  
5568  #include "idmap.h"
5569  #include "acl.h"
5570 @@ -2351,14 +2352,18 @@ out_acl:
5571                 WRITE32(stat.nlink);
5572         }
5573         if (bmval1 & FATTR4_WORD1_OWNER) {
5574 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5575 +               status = nfsd4_encode_user(rqstp,
5576 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5577 +                       stat.uid, stat.tag), &p, &buflen);
5578                 if (status == nfserr_resource)
5579                         goto out_resource;
5580                 if (status)
5581                         goto out;
5582         }
5583         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5584 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5585 +               status = nfsd4_encode_group(rqstp,
5586 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5587 +                       stat.gid, stat.tag), &p, &buflen);
5588                 if (status == nfserr_resource)
5589                         goto out_resource;
5590                 if (status)
5591 diff -NurpP --minimal linux-3.5.4/fs/nfsd/nfsxdr.c linux-3.5.4-vs2.3.4.3/fs/nfsd/nfsxdr.c
5592 --- linux-3.5.4/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5593 +++ linux-3.5.4-vs2.3.4.3/fs/nfsd/nfsxdr.c      2012-07-23 01:45:55.000000000 +0200
5594 @@ -6,6 +6,7 @@
5595  
5596  #include "xdr.h"
5597  #include "auth.h"
5598 +#include <linux/vs_tag.h>
5599  
5600  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5601  
5602 @@ -88,6 +89,8 @@ static __be32 *
5603  decode_sattr(__be32 *p, struct iattr *iap)
5604  {
5605         u32     tmp, tmp1;
5606 +       uid_t   uid = 0;
5607 +       gid_t   gid = 0;
5608  
5609         iap->ia_valid = 0;
5610  
5611 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5612         }
5613         if ((tmp = ntohl(*p++)) != (u32)-1) {
5614                 iap->ia_valid |= ATTR_UID;
5615 -               iap->ia_uid = tmp;
5616 +               uid = tmp;
5617         }
5618         if ((tmp = ntohl(*p++)) != (u32)-1) {
5619                 iap->ia_valid |= ATTR_GID;
5620 -               iap->ia_gid = tmp;
5621 +               gid = tmp;
5622         }
5623 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5624 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5625 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5626         if ((tmp = ntohl(*p++)) != (u32)-1) {
5627                 iap->ia_valid |= ATTR_SIZE;
5628                 iap->ia_size = tmp;
5629 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5630         *p++ = htonl(nfs_ftypes[type >> 12]);
5631         *p++ = htonl((u32) stat->mode);
5632         *p++ = htonl((u32) stat->nlink);
5633 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5634 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5635 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5636 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5637 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5638 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5639  
5640         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5641                 *p++ = htonl(NFS_MAXPATHLEN);
5642 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/dlmglue.c linux-3.5.4-vs2.3.4.3/fs/ocfs2/dlmglue.c
5643 --- linux-3.5.4/fs/ocfs2/dlmglue.c      2012-07-22 23:39:41.000000000 +0200
5644 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/dlmglue.c    2012-07-23 01:45:55.000000000 +0200
5645 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5646         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5647         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5648         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5649 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5650         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5651         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5652         lvb->lvb_iatime_packed  =
5653 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5654  
5655         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5656         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5657 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5658         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5659         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5660         ocfs2_unpack_timespec(&inode->i_atime,
5661 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/dlmglue.h linux-3.5.4-vs2.3.4.3/fs/ocfs2/dlmglue.h
5662 --- linux-3.5.4/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5663 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/dlmglue.h    2012-07-23 01:45:55.000000000 +0200
5664 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5665         __be16       lvb_inlink;
5666         __be32       lvb_iattr;
5667         __be32       lvb_igeneration;
5668 -       __be32       lvb_reserved2;
5669 +       __be16       lvb_itag;
5670 +       __be16       lvb_reserved2;
5671  };
5672  
5673  #define OCFS2_QINFO_LVB_VERSION 1
5674 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/file.c linux-3.5.4-vs2.3.4.3/fs/ocfs2/file.c
5675 --- linux-3.5.4/fs/ocfs2/file.c 2012-07-22 23:39:41.000000000 +0200
5676 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/file.c       2012-07-23 01:45:55.000000000 +0200
5677 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5678                 attr->ia_valid &= ~ATTR_SIZE;
5679  
5680  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5681 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5682 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5683         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5684                 return 0;
5685  
5686 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/inode.c linux-3.5.4-vs2.3.4.3/fs/ocfs2/inode.c
5687 --- linux-3.5.4/fs/ocfs2/inode.c        2012-07-22 23:39:41.000000000 +0200
5688 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/inode.c      2012-07-23 01:45:55.000000000 +0200
5689 @@ -28,6 +28,7 @@
5690  #include <linux/highmem.h>
5691  #include <linux/pagemap.h>
5692  #include <linux/quotaops.h>
5693 +#include <linux/vs_tag.h>
5694  
5695  #include <asm/byteorder.h>
5696  
5697 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5698  {
5699         unsigned int flags = OCFS2_I(inode)->ip_attr;
5700  
5701 -       inode->i_flags &= ~(S_IMMUTABLE |
5702 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5703                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5704  
5705         if (flags & OCFS2_IMMUTABLE_FL)
5706                 inode->i_flags |= S_IMMUTABLE;
5707 +       if (flags & OCFS2_IXUNLINK_FL)
5708 +               inode->i_flags |= S_IXUNLINK;
5709  
5710         if (flags & OCFS2_SYNC_FL)
5711                 inode->i_flags |= S_SYNC;
5712 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5713                 inode->i_flags |= S_NOATIME;
5714         if (flags & OCFS2_DIRSYNC_FL)
5715                 inode->i_flags |= S_DIRSYNC;
5716 +
5717 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5718 +
5719 +       if (flags & OCFS2_BARRIER_FL)
5720 +               inode->i_vflags |= V_BARRIER;
5721 +       if (flags & OCFS2_COW_FL)
5722 +               inode->i_vflags |= V_COW;
5723  }
5724  
5725  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5726  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5727  {
5728         unsigned int flags = oi->vfs_inode.i_flags;
5729 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5730 +
5731 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5732 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5733 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5734 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5735 +
5736 +       if (flags & S_IMMUTABLE)
5737 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5738 +       if (flags & S_IXUNLINK)
5739 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5740  
5741 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5742 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5743         if (flags & S_SYNC)
5744                 oi->ip_attr |= OCFS2_SYNC_FL;
5745         if (flags & S_APPEND)
5746                 oi->ip_attr |= OCFS2_APPEND_FL;
5747 -       if (flags & S_IMMUTABLE)
5748 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5749         if (flags & S_NOATIME)
5750                 oi->ip_attr |= OCFS2_NOATIME_FL;
5751         if (flags & S_DIRSYNC)
5752                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5753 +
5754 +       if (vflags & V_BARRIER)
5755 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5756 +       if (vflags & V_COW)
5757 +               oi->ip_attr |= OCFS2_COW_FL;
5758  }
5759  
5760  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5761 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5762         struct super_block *sb;
5763         struct ocfs2_super *osb;
5764         int use_plocks = 1;
5765 +       uid_t uid;
5766 +       gid_t gid;
5767  
5768         sb = inode->i_sb;
5769         osb = OCFS2_SB(sb);
5770 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5771         inode->i_generation = le32_to_cpu(fe->i_generation);
5772         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5773         inode->i_mode = le16_to_cpu(fe->i_mode);
5774 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5775 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5776 +       uid = le32_to_cpu(fe->i_uid);
5777 +       gid = le32_to_cpu(fe->i_gid);
5778 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5779 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5780 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5781 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5782  
5783         /* Fast symlinks will have i_size but no allocated clusters. */
5784         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5785 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/inode.h linux-3.5.4-vs2.3.4.3/fs/ocfs2/inode.h
5786 --- linux-3.5.4/fs/ocfs2/inode.h        2012-01-09 16:14:55.000000000 +0100
5787 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/inode.h      2012-07-23 01:45:55.000000000 +0200
5788 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5789  
5790  void ocfs2_set_inode_flags(struct inode *inode);
5791  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5792 +int ocfs2_sync_flags(struct inode *inode, int, int);
5793  
5794  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5795  {
5796 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/ioctl.c linux-3.5.4-vs2.3.4.3/fs/ocfs2/ioctl.c
5797 --- linux-3.5.4/fs/ocfs2/ioctl.c        2012-07-22 23:39:41.000000000 +0200
5798 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/ioctl.c      2012-07-23 01:45:55.000000000 +0200
5799 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5800         return status;
5801  }
5802  
5803 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5804 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5805 +{
5806 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5807 +       struct buffer_head *bh = NULL;
5808 +       handle_t *handle = NULL;
5809 +       int status;
5810 +
5811 +       status = ocfs2_inode_lock(inode, &bh, 1);
5812 +       if (status < 0) {
5813 +               mlog_errno(status);
5814 +               return status;
5815 +       }
5816 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5817 +       if (IS_ERR(handle)) {
5818 +               status = PTR_ERR(handle);
5819 +               mlog_errno(status);
5820 +               goto bail_unlock;
5821 +       }
5822 +
5823 +       inode->i_flags = flags;
5824 +       inode->i_vflags = vflags;
5825 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5826 +
5827 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5828 +       if (status < 0)
5829 +               mlog_errno(status);
5830 +
5831 +       ocfs2_commit_trans(osb, handle);
5832 +bail_unlock:
5833 +       ocfs2_inode_unlock(inode, 1);
5834 +       brelse(bh);
5835 +       return status;
5836 +}
5837 +
5838 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5839                                 unsigned mask)
5840  {
5841         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5842 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5843         if (!S_ISDIR(inode->i_mode))
5844                 flags &= ~OCFS2_DIRSYNC_FL;
5845  
5846 +       if (IS_BARRIER(inode)) {
5847 +               vxwprintk_task(1, "messing with the barrier.");
5848 +               goto bail_unlock;
5849 +       }
5850 +
5851         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5852         if (IS_ERR(handle)) {
5853                 status = PTR_ERR(handle);
5854 @@ -879,6 +918,7 @@ bail:
5855         return status;
5856  }
5857  
5858 +
5859  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5860  {
5861         struct inode *inode = filp->f_path.dentry->d_inode;
5862 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/namei.c linux-3.5.4-vs2.3.4.3/fs/ocfs2/namei.c
5863 --- linux-3.5.4/fs/ocfs2/namei.c        2012-07-22 23:39:41.000000000 +0200
5864 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/namei.c      2012-07-23 01:45:55.000000000 +0200
5865 @@ -41,6 +41,7 @@
5866  #include <linux/slab.h>
5867  #include <linux/highmem.h>
5868  #include <linux/quotaops.h>
5869 +#include <linux/vs_tag.h>
5870  
5871  #include <cluster/masklog.h>
5872  
5873 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5874         struct ocfs2_dinode *fe = NULL;
5875         struct ocfs2_extent_list *fel;
5876         u16 feat;
5877 +       tag_t tag;
5878  
5879         *new_fe_bh = NULL;
5880  
5881 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5882         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5883         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5884         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5885 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5886 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5887 +
5888 +       tag = dx_current_fstag(osb->sb);
5889 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5890 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5891 +       inode->i_tag = tag;
5892         fe->i_mode = cpu_to_le16(inode->i_mode);
5893         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5894                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5895 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/ocfs2.h linux-3.5.4-vs2.3.4.3/fs/ocfs2/ocfs2.h
5896 --- linux-3.5.4/fs/ocfs2/ocfs2.h        2012-01-09 16:14:55.000000000 +0100
5897 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/ocfs2.h      2012-07-23 01:45:55.000000000 +0200
5898 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5899                                                      writes */
5900         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5901         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5902 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5903  };
5904  
5905  #define OCFS2_OSB_SOFT_RO                      0x0001
5906 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/ocfs2_fs.h linux-3.5.4-vs2.3.4.3/fs/ocfs2/ocfs2_fs.h
5907 --- linux-3.5.4/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
5908 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/ocfs2_fs.h   2012-07-23 01:45:55.000000000 +0200
5909 @@ -266,6 +266,11 @@
5910  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5911  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5912  
5913 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5914 +
5915 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5916 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5917 +
5918  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5919  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5920  
5921 diff -NurpP --minimal linux-3.5.4/fs/ocfs2/super.c linux-3.5.4-vs2.3.4.3/fs/ocfs2/super.c
5922 --- linux-3.5.4/fs/ocfs2/super.c        2012-05-21 18:07:26.000000000 +0200
5923 +++ linux-3.5.4-vs2.3.4.3/fs/ocfs2/super.c      2012-07-23 01:45:55.000000000 +0200
5924 @@ -185,6 +185,7 @@ enum {
5925         Opt_coherency_full,
5926         Opt_resv_level,
5927         Opt_dir_resv_level,
5928 +       Opt_tag, Opt_notag, Opt_tagid,
5929         Opt_err,
5930  };
5931  
5932 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5933         {Opt_coherency_full, "coherency=full"},
5934         {Opt_resv_level, "resv_level=%u"},
5935         {Opt_dir_resv_level, "dir_resv_level=%u"},
5936 +       {Opt_tag, "tag"},
5937 +       {Opt_notag, "notag"},
5938 +       {Opt_tagid, "tagid=%u"},
5939         {Opt_err, NULL}
5940  };
5941  
5942 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5943                 goto out;
5944         }
5945  
5946 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5947 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5948 +               ret = -EINVAL;
5949 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5950 +               goto out;
5951 +       }
5952 +
5953         /* We're going to/from readonly mode. */
5954         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5955                 /* Disable quota accounting before remounting RO */
5956 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5957  
5958         ocfs2_complete_mount_recovery(osb);
5959  
5960 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5961 +               sb->s_flags |= MS_TAGGED;
5962 +
5963         if (ocfs2_mount_local(osb))
5964                 snprintf(nodestr, sizeof(nodestr), "local");
5965         else
5966 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5967                             option < OCFS2_MAX_RESV_LEVEL)
5968                                 mopt->dir_resv_level = option;
5969                         break;
5970 +#ifndef CONFIG_TAGGING_NONE
5971 +               case Opt_tag:
5972 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5973 +                       break;
5974 +               case Opt_notag:
5975 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5976 +                       break;
5977 +#endif
5978 +#ifdef CONFIG_PROPAGATE
5979 +               case Opt_tagid:
5980 +                       /* use args[0] */
5981 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5982 +                       break;
5983 +#endif
5984                 default:
5985                         mlog(ML_ERROR,
5986                              "Unrecognized mount option \"%s\" "
5987 diff -NurpP --minimal linux-3.5.4/fs/open.c linux-3.5.4-vs2.3.4.3/fs/open.c
5988 --- linux-3.5.4/fs/open.c       2012-09-16 20:46:31.000000000 +0200
5989 +++ linux-3.5.4-vs2.3.4.3/fs/open.c     2012-09-16 20:50:19.000000000 +0200
5990 @@ -30,6 +30,11 @@
5991  #include <linux/fs_struct.h>
5992  #include <linux/ima.h>
5993  #include <linux/dnotify.h>
5994 +#include <linux/vs_base.h>
5995 +#include <linux/vs_limit.h>
5996 +#include <linux/vs_tag.h>
5997 +#include <linux/vs_cowbl.h>
5998 +#include <linux/vserver/dlimit.h>
5999  
6000  #include "internal.h"
6001  
6002 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6003         error = user_path(pathname, &path);
6004         if (error)
6005                 goto out;
6006 +
6007 +#ifdef CONFIG_VSERVER_COWBL
6008 +       error = cow_check_and_break(&path);
6009 +       if (error)
6010 +               goto dput_and_out;
6011 +#endif
6012         inode = path.dentry->d_inode;
6013  
6014         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6015 @@ -490,6 +501,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6016  
6017         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6018         if (!error) {
6019 +#ifdef CONFIG_VSERVER_COWBL
6020 +               error = cow_check_and_break(&path);
6021 +               if (!error)
6022 +#endif
6023                 error = chmod_common(&path, mode);
6024                 path_put(&path);
6025         }
6026 @@ -517,13 +532,13 @@ static int chown_common(struct path *pat
6027                 if (!uid_valid(uid))
6028                         return -EINVAL;
6029                 newattrs.ia_valid |= ATTR_UID;
6030 -               newattrs.ia_uid = uid;
6031 +               newattrs.ia_uid = dx_map_uid(user);
6032         }
6033         if (group != (gid_t) -1) {
6034                 if (!gid_valid(gid))
6035                         return -EINVAL;
6036                 newattrs.ia_valid |= ATTR_GID;
6037 -               newattrs.ia_gid = gid;
6038 +               newattrs.ia_gid = dx_map_gid(group);
6039         }
6040         if (!S_ISDIR(inode->i_mode))
6041                 newattrs.ia_valid |=
6042 @@ -548,6 +563,10 @@ SYSCALL_DEFINE3(chown, const char __user
6043         error = mnt_want_write(path.mnt);
6044         if (error)
6045                 goto out_release;
6046 +#ifdef CONFIG_VSERVER_COWBL
6047 +       error = cow_check_and_break(&path);
6048 +       if (!error)
6049 +#endif
6050         error = chown_common(&path, user, group);
6051         mnt_drop_write(path.mnt);
6052  out_release:
6053 @@ -575,6 +594,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6054         error = mnt_want_write(path.mnt);
6055         if (error)
6056                 goto out_release;
6057 +#ifdef CONFIG_VSERVER_COWBL
6058 +       error = cow_check_and_break(&path);
6059 +       if (!error)
6060 +#endif
6061         error = chown_common(&path, user, group);
6062         mnt_drop_write(path.mnt);
6063  out_release:
6064 @@ -594,6 +617,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6065         error = mnt_want_write(path.mnt);
6066         if (error)
6067                 goto out_release;
6068 +#ifdef CONFIG_VSERVER_COWBL
6069 +       error = cow_check_and_break(&path);
6070 +       if (!error)
6071 +#endif
6072         error = chown_common(&path, user, group);
6073         mnt_drop_write(path.mnt);
6074  out_release:
6075 @@ -887,6 +914,7 @@ static void __put_unused_fd(struct files
6076         __clear_open_fd(fd, fdt);
6077         if (fd < files->next_fd)
6078                 files->next_fd = fd;
6079 +       vx_openfd_dec(fd);
6080  }
6081  
6082  void put_unused_fd(unsigned int fd)
6083 diff -NurpP --minimal linux-3.5.4/fs/proc/array.c linux-3.5.4-vs2.3.4.3/fs/proc/array.c
6084 --- linux-3.5.4/fs/proc/array.c 2012-07-22 23:39:42.000000000 +0200
6085 +++ linux-3.5.4-vs2.3.4.3/fs/proc/array.c       2012-07-23 10:51:47.000000000 +0200
6086 @@ -82,6 +82,8 @@
6087  #include <linux/ptrace.h>
6088  #include <linux/tracehook.h>
6089  #include <linux/user_namespace.h>
6090 +#include <linux/vs_context.h>
6091 +#include <linux/vs_network.h>
6092  
6093  #include <asm/pgtable.h>
6094  #include <asm/processor.h>
6095 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6096         rcu_read_lock();
6097         ppid = pid_alive(p) ?
6098                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6099 +       if (unlikely(vx_current_initpid(p->pid)))
6100 +               ppid = 0;
6101 +
6102         tpid = 0;
6103         if (pid_alive(p)) {
6104                 struct task_struct *tracer = ptrace_parent(p);
6105 @@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6106  }
6107  
6108  static void render_cap_t(struct seq_file *m, const char *header,
6109 -                       kernel_cap_t *a)
6110 +                       struct vx_info *vxi, kernel_cap_t *a)
6111  {
6112         unsigned __capi;
6113  
6114 @@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6115         cap_bset        = cred->cap_bset;
6116         rcu_read_unlock();
6117  
6118 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6119 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6120 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6121 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6122 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6123 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6124 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6125 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6126 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6127  }
6128  
6129  static inline void task_context_switch_counts(struct seq_file *m,
6130 @@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6131         seq_putc(m, '\n');
6132  }
6133  
6134 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6135 +                       struct pid *pid, struct task_struct *task)
6136 +{
6137 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6138 +                       "Count:\t%u\n"
6139 +                       "uts:\t%p(%c)\n"
6140 +                       "ipc:\t%p(%c)\n"
6141 +                       "mnt:\t%p(%c)\n"
6142 +                       "pid:\t%p(%c)\n"
6143 +                       "net:\t%p(%c)\n",
6144 +                       task->nsproxy,
6145 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6146 +                       atomic_read(&task->nsproxy->count),
6147 +                       task->nsproxy->uts_ns,
6148 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6149 +                       task->nsproxy->ipc_ns,
6150 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6151 +                       task->nsproxy->mnt_ns,
6152 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6153 +                       task->nsproxy->pid_ns,
6154 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6155 +                       task->nsproxy->net_ns,
6156 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6157 +       return 0;
6158 +}
6159 +
6160 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6161 +{
6162 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6163 +               return;
6164 +
6165 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6166 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6167 +}
6168 +
6169 +
6170  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6171                         struct pid *pid, struct task_struct *task)
6172  {
6173 @@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m, 
6174         task_cap(m, task);
6175         task_cpus_allowed(m, task);
6176         cpuset_task_status_allowed(m, task);
6177 +       task_vs_id(m, task);
6178         task_context_switch_counts(m, task);
6179         return 0;
6180  }
6181 @@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file 
6182         /* convert nsec -> ticks */
6183         start_time = nsec_to_clock_t(start_time);
6184  
6185 +       /* fixup start time for virt uptime */
6186 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6187 +               unsigned long long bias =
6188 +                       current->vx_info->cvirt.bias_clock;
6189 +
6190 +               if (start_time > bias)
6191 +                       start_time -= bias;
6192 +               else
6193 +                       start_time = 0;
6194 +       }
6195 +
6196         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6197         seq_put_decimal_ll(m, ' ', ppid);
6198         seq_put_decimal_ll(m, ' ', pgid);
6199 diff -NurpP --minimal linux-3.5.4/fs/proc/base.c linux-3.5.4-vs2.3.4.3/fs/proc/base.c
6200 --- linux-3.5.4/fs/proc/base.c  2012-07-22 23:39:42.000000000 +0200
6201 +++ linux-3.5.4-vs2.3.4.3/fs/proc/base.c        2012-07-23 01:45:55.000000000 +0200
6202 @@ -85,6 +85,8 @@
6203  #include <linux/fs_struct.h>
6204  #include <linux/slab.h>
6205  #include <linux/flex_array.h>
6206 +#include <linux/vs_context.h>
6207 +#include <linux/vs_network.h>
6208  #ifdef CONFIG_HARDWALL
6209  #include <asm/hardwall.h>
6210  #endif
6211 @@ -937,11 +939,16 @@ static ssize_t oom_adjust_write(struct f
6212                 goto err_task_lock;
6213         }
6214  
6215 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6216 +       if (oom_adjust < task->signal->oom_adj &&
6217 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6218                 err = -EACCES;
6219                 goto err_sighand;
6220         }
6221  
6222 +       /* prevent guest processes from circumventing the oom killer */
6223 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6224 +               oom_adjust = OOM_ADJUST_MIN;
6225 +
6226         /*
6227          * Warn that /proc/pid/oom_adj is deprecated, see
6228          * Documentation/feature-removal-schedule.txt.
6229 @@ -1541,6 +1548,8 @@ struct inode *proc_pid_make_inode(struct
6230                 inode->i_gid = cred->egid;
6231                 rcu_read_unlock();
6232         }
6233 +       /* procfs is xid tagged */
6234 +       inode->i_tag = (tag_t)vx_task_xid(task);
6235         security_task_to_inode(task, inode);
6236  
6237  out:
6238 @@ -1586,6 +1595,8 @@ int pid_getattr(struct vfsmount *mnt, st
6239  
6240  /* dentry stuff */
6241  
6242 +static unsigned name_to_int(struct dentry *dentry);
6243 +
6244  /*
6245   *     Exceptional case: normally we are not allowed to unhash a busy
6246   * directory. In this case, however, we can do it - no aliasing problems
6247 @@ -1614,6 +1625,12 @@ int pid_revalidate(struct dentry *dentry
6248         task = get_proc_task(inode);
6249  
6250         if (task) {
6251 +               unsigned pid = name_to_int(dentry);
6252 +
6253 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6254 +                       put_task_struct(task);
6255 +                       goto drop;
6256 +               }
6257                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6258                     task_dumpable(task)) {
6259                         rcu_read_lock();
6260 @@ -1630,6 +1647,7 @@ int pid_revalidate(struct dentry *dentry
6261                 put_task_struct(task);
6262                 return 1;
6263         }
6264 +drop:
6265         d_drop(dentry);
6266         return 0;
6267  }
6268 @@ -2450,6 +2468,13 @@ static struct dentry *proc_pident_lookup
6269         if (!task)
6270                 goto out_no_task;
6271  
6272 +       /* TODO: maybe we can come up with a generic approach? */
6273 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6274 +               (dentry->d_name.len == 5) &&
6275 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6276 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6277 +               goto out;
6278 +
6279         /*
6280          * Yes, it does not scale. And it should not. Don't add
6281          * new entries into /proc/<tgid>/ without very good reasons.
6282 @@ -2835,7 +2860,7 @@ out_iput:
6283  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6284  {
6285         struct dentry *error;
6286 -       struct task_struct *task = get_proc_task(dir);
6287 +       struct task_struct *task = get_proc_task_real(dir);
6288         const struct pid_entry *p, *last;
6289  
6290         error = ERR_PTR(-ENOENT);
6291 @@ -3010,6 +3035,9 @@ static int proc_pid_personality(struct s
6292  static const struct file_operations proc_task_operations;
6293  static const struct inode_operations proc_task_inode_operations;
6294  
6295 +extern int proc_pid_vx_info(struct task_struct *, char *);
6296 +extern int proc_pid_nx_info(struct task_struct *, char *);
6297 +
6298  static const struct pid_entry tgid_base_stuff[] = {
6299         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6300         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6301 @@ -3076,6 +3104,8 @@ static const struct pid_entry tgid_base_
6302  #ifdef CONFIG_CGROUPS
6303         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6304  #endif
6305 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6306 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6307         INF("oom_score",  S_IRUGO, proc_oom_score),
6308         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6309         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6310 @@ -3099,6 +3129,7 @@ static const struct pid_entry tgid_base_
6311         REG("uid_map",    S_IRUGO|S_IWUSR, proc_uid_map_operations),
6312         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6313  #endif
6314 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6315  };
6316  
6317  static int proc_tgid_base_readdir(struct file * filp,
6318 @@ -3292,7 +3323,7 @@ retry:
6319         iter.task = NULL;
6320         pid = find_ge_pid(iter.tgid, ns);
6321         if (pid) {
6322 -               iter.tgid = pid_nr_ns(pid, ns);
6323 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6324                 iter.task = pid_task(pid, PIDTYPE_PID);
6325                 /* What we to know is if the pid we have find is the
6326                  * pid of a thread_group_leader.  Testing for task
6327 @@ -3322,7 +3353,7 @@ static int proc_pid_fill_cache(struct fi
6328         struct tgid_iter iter)
6329  {
6330         char name[PROC_NUMBUF];
6331 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6332 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6333         return proc_fill_cache(filp, dirent, filldir, name, len,
6334                                 proc_pid_instantiate, iter.task, NULL);
6335  }
6336 @@ -3346,7 +3377,7 @@ int proc_pid_readdir(struct file * filp,
6337                 goto out_no_task;
6338         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6339  
6340 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6341 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6342         if (!reaper)
6343                 goto out_no_task;
6344  
6345 @@ -3368,6 +3399,8 @@ int proc_pid_readdir(struct file * filp,
6346                         __filldir = fake_filldir;
6347  
6348                 filp->f_pos = iter.tgid + TGID_OFFSET;
6349 +               if (!vx_proc_task_visible(iter.task))
6350 +                       continue;
6351                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6352                         put_task_struct(iter.task);
6353                         goto out;
6354 @@ -3528,6 +3561,8 @@ static struct dentry *proc_task_lookup(s
6355         tid = name_to_int(dentry);
6356         if (tid == ~0U)
6357                 goto out;
6358 +       if (vx_current_initpid(tid))
6359 +               goto out;
6360  
6361         ns = dentry->d_sb->s_fs_info;
6362         rcu_read_lock();
6363 diff -NurpP --minimal linux-3.5.4/fs/proc/generic.c linux-3.5.4-vs2.3.4.3/fs/proc/generic.c
6364 --- linux-3.5.4/fs/proc/generic.c       2012-03-19 19:47:26.000000000 +0100
6365 +++ linux-3.5.4-vs2.3.4.3/fs/proc/generic.c     2012-07-23 01:45:55.000000000 +0200
6366 @@ -22,6 +22,7 @@
6367  #include <linux/bitops.h>
6368  #include <linux/spinlock.h>
6369  #include <linux/completion.h>
6370 +#include <linux/vserver/inode.h>
6371  #include <asm/uaccess.h>
6372  
6373  #include "internal.h"
6374 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6375         for (de = de->subdir; de ; de = de->next) {
6376                 if (de->namelen != dentry->d_name.len)
6377                         continue;
6378 +               if (!vx_hide_check(0, de->vx_flags))
6379 +                       continue;
6380                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6381                         pde_get(de);
6382                         spin_unlock(&proc_subdir_lock);
6383                         error = -EINVAL;
6384                         inode = proc_get_inode(dir->i_sb, de);
6385 +                       /* generic proc entries belong to the host */
6386 +                       inode->i_tag = 0;
6387                         goto out_unlock;
6388                 }
6389         }
6390 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6391  
6392                                 /* filldir passes info to user space */
6393                                 pde_get(de);
6394 +                               if (!vx_hide_check(0, de->vx_flags))
6395 +                                       goto skip;
6396                                 spin_unlock(&proc_subdir_lock);
6397                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6398                                             de->low_ino, de->mode >> 12) < 0) {
6399 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6400                                         goto out;
6401                                 }
6402                                 spin_lock(&proc_subdir_lock);
6403 +                       skip:
6404                                 filp->f_pos++;
6405                                 next = de->next;
6406                                 pde_put(de);
6407 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6408         ent->nlink = nlink;
6409         atomic_set(&ent->count, 1);
6410         ent->pde_users = 0;
6411 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6412         spin_lock_init(&ent->pde_unload_lock);
6413         ent->pde_unload_completion = NULL;
6414         INIT_LIST_HEAD(&ent->pde_openers);
6415 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6416                                 kfree(ent->data);
6417                                 kfree(ent);
6418                                 ent = NULL;
6419 -                       }
6420 +                       } else
6421 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6422                 } else {
6423                         kfree(ent);
6424                         ent = NULL;
6425 diff -NurpP --minimal linux-3.5.4/fs/proc/inode.c linux-3.5.4-vs2.3.4.3/fs/proc/inode.c
6426 --- linux-3.5.4/fs/proc/inode.c 2012-07-22 23:39:42.000000000 +0200
6427 +++ linux-3.5.4-vs2.3.4.3/fs/proc/inode.c       2012-07-23 01:45:55.000000000 +0200
6428 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6429                         inode->i_uid = de->uid;
6430                         inode->i_gid = de->gid;
6431                 }
6432 +               if (de->vx_flags)
6433 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6434                 if (de->size)
6435                         inode->i_size = de->size;
6436                 if (de->nlink)
6437 diff -NurpP --minimal linux-3.5.4/fs/proc/internal.h linux-3.5.4-vs2.3.4.3/fs/proc/internal.h
6438 --- linux-3.5.4/fs/proc/internal.h      2012-07-22 23:39:42.000000000 +0200
6439 +++ linux-3.5.4-vs2.3.4.3/fs/proc/internal.h    2012-07-23 01:45:55.000000000 +0200
6440 @@ -10,6 +10,8 @@
6441   */
6442  
6443  #include <linux/proc_fs.h>
6444 +#include <linux/vs_pid.h>
6445 +
6446  struct  ctl_table_header;
6447  
6448  extern struct proc_dir_entry proc_root;
6449 @@ -52,6 +54,9 @@ extern int proc_pid_status(struct seq_fi
6450                                 struct pid *pid, struct task_struct *task);
6451  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6452                                 struct pid *pid, struct task_struct *task);
6453 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6454 +                               struct pid *pid, struct task_struct *task);
6455 +
6456  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6457  
6458  extern const struct file_operations proc_tid_children_operations;
6459 @@ -81,11 +86,16 @@ static inline struct pid *proc_pid(struc
6460         return PROC_I(inode)->pid;
6461  }
6462  
6463 -static inline struct task_struct *get_proc_task(struct inode *inode)
6464 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6465  {
6466         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6467  }
6468  
6469 +static inline struct task_struct *get_proc_task(struct inode *inode)
6470 +{
6471 +       return vx_get_proc_task(inode, proc_pid(inode));
6472 +}
6473 +
6474  static inline int proc_fd(struct inode *inode)
6475  {
6476         return PROC_I(inode)->fd;
6477 diff -NurpP --minimal linux-3.5.4/fs/proc/loadavg.c linux-3.5.4-vs2.3.4.3/fs/proc/loadavg.c
6478 --- linux-3.5.4/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6479 +++ linux-3.5.4-vs2.3.4.3/fs/proc/loadavg.c     2012-07-23 01:45:55.000000000 +0200
6480 @@ -12,15 +12,27 @@
6481  
6482  static int loadavg_proc_show(struct seq_file *m, void *v)
6483  {
6484 +       unsigned long running;
6485 +       unsigned int threads;
6486         unsigned long avnrun[3];
6487  
6488         get_avenrun(avnrun, FIXED_1/200, 0);
6489  
6490 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6491 +               struct vx_info *vxi = current_vx_info();
6492 +
6493 +               running = atomic_read(&vxi->cvirt.nr_running);
6494 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6495 +       } else {
6496 +               running = nr_running();
6497 +               threads = nr_threads;
6498 +       }
6499 +
6500         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6501                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6502                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6503                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6504 -               nr_running(), nr_threads,
6505 +               running, threads,
6506                 task_active_pid_ns(current)->last_pid);
6507         return 0;
6508  }
6509 diff -NurpP --minimal linux-3.5.4/fs/proc/meminfo.c linux-3.5.4-vs2.3.4.3/fs/proc/meminfo.c
6510 --- linux-3.5.4/fs/proc/meminfo.c       2012-01-09 16:14:55.000000000 +0100
6511 +++ linux-3.5.4-vs2.3.4.3/fs/proc/meminfo.c     2012-07-23 01:45:55.000000000 +0200
6512 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6513         allowed = ((totalram_pages - hugetlb_total_pages())
6514                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6515  
6516 -       cached = global_page_state(NR_FILE_PAGES) -
6517 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6518 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6519                         total_swapcache_pages - i.bufferram;
6520         if (cached < 0)
6521                 cached = 0;
6522 diff -NurpP --minimal linux-3.5.4/fs/proc/root.c linux-3.5.4-vs2.3.4.3/fs/proc/root.c
6523 --- linux-3.5.4/fs/proc/root.c  2012-07-22 23:39:42.000000000 +0200
6524 +++ linux-3.5.4-vs2.3.4.3/fs/proc/root.c        2012-07-23 01:45:55.000000000 +0200
6525 @@ -19,9 +19,14 @@
6526  #include <linux/mount.h>
6527  #include <linux/pid_namespace.h>
6528  #include <linux/parser.h>
6529 +#include <linux/vserver/inode.h>
6530  
6531  #include "internal.h"
6532  
6533 +struct proc_dir_entry *proc_virtual;
6534 +
6535 +extern void proc_vx_init(void);
6536 +
6537  static int proc_test_super(struct super_block *sb, void *data)
6538  {
6539         return sb->s_fs_info == data;
6540 @@ -190,6 +195,7 @@ void __init proc_root_init(void)
6541  #endif
6542         proc_mkdir("bus", NULL);
6543         proc_sys_init();
6544 +       proc_vx_init();
6545  }
6546  
6547  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6548 @@ -257,6 +263,7 @@ struct proc_dir_entry proc_root = {
6549         .proc_iops      = &proc_root_inode_operations, 
6550         .proc_fops      = &proc_root_operations,
6551         .parent         = &proc_root,
6552 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6553         .name           = "/proc",
6554  };
6555  
6556 diff -NurpP --minimal linux-3.5.4/fs/proc/stat.c linux-3.5.4-vs2.3.4.3/fs/proc/stat.c
6557 --- linux-3.5.4/fs/proc/stat.c  2012-05-21 18:07:26.000000000 +0200
6558 +++ linux-3.5.4-vs2.3.4.3/fs/proc/stat.c        2012-07-23 01:45:55.000000000 +0200
6559 @@ -9,6 +9,7 @@
6560  #include <linux/slab.h>
6561  #include <linux/time.h>
6562  #include <linux/irqnr.h>
6563 +#include <linux/vserver/cvirt.h>
6564  #include <asm/cputime.h>
6565  #include <linux/tick.h>
6566  
6567 @@ -86,6 +87,10 @@ static int show_stat(struct seq_file *p,
6568                 irq = softirq = steal = 0;
6569         guest = guest_nice = 0;
6570         getboottime(&boottime);
6571 +
6572 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6573 +               vx_vsi_boottime(&boottime);
6574 +
6575         jif = boottime.tv_sec;
6576  
6577         for_each_possible_cpu(i) {
6578 diff -NurpP --minimal linux-3.5.4/fs/proc/uptime.c linux-3.5.4-vs2.3.4.3/fs/proc/uptime.c
6579 --- linux-3.5.4/fs/proc/uptime.c        2012-03-19 19:47:26.000000000 +0100
6580 +++ linux-3.5.4-vs2.3.4.3/fs/proc/uptime.c      2012-07-23 01:45:55.000000000 +0200
6581 @@ -5,6 +5,7 @@
6582  #include <linux/seq_file.h>
6583  #include <linux/time.h>
6584  #include <linux/kernel_stat.h>
6585 +#include <linux/vserver/cvirt.h>
6586  #include <asm/cputime.h>
6587  
6588  static int uptime_proc_show(struct seq_file *m, void *v)
6589 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6590         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6591         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6592         idle.tv_nsec = rem;
6593 +
6594 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6595 +               vx_vsi_uptime(&uptime, &idle);
6596 +
6597         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6598                         (unsigned long) uptime.tv_sec,
6599                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6600 diff -NurpP --minimal linux-3.5.4/fs/proc_namespace.c linux-3.5.4-vs2.3.4.3/fs/proc_namespace.c
6601 --- linux-3.5.4/fs/proc_namespace.c     2012-07-22 23:39:42.000000000 +0200
6602 +++ linux-3.5.4-vs2.3.4.3/fs/proc_namespace.c   2012-07-23 11:01:00.000000000 +0200
6603 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file 
6604                 { MS_SYNCHRONOUS, ",sync" },
6605                 { MS_DIRSYNC, ",dirsync" },
6606                 { MS_MANDLOCK, ",mand" },
6607 +               { MS_TAGGED, ",tag" },
6608 +               { MS_NOTAGCHECK, ",notagcheck" },
6609                 { 0, NULL }
6610         };
6611         const struct proc_fs_info *fs_infop;
6612 @@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6613         seq_escape(m, s, " \t\n\\");
6614  }
6615  
6616 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6617 +{
6618 +       struct path root;
6619 +       struct dentry *point;
6620 +       struct mount *mnt = real_mount(vfsmnt);
6621 +       struct mount *root_mnt;
6622 +       int ret;
6623 +
6624 +       if (mnt == mnt->mnt_ns->root)
6625 +               return 1;
6626 +
6627 +       br_read_lock(&vfsmount_lock);
6628 +       root = current->fs->root;
6629 +       root_mnt = real_mount(root.mnt);
6630 +       point = root.dentry;
6631 +
6632 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6633 +               point = mnt->mnt_mountpoint;
6634 +               mnt = mnt->mnt_parent;
6635 +       }
6636 +
6637 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6638 +
6639 +       br_read_unlock(&vfsmount_lock);
6640 +
6641 +       return ret;
6642 +}
6643 +
6644  static void show_type(struct seq_file *m, struct super_block *sb)
6645  {
6646         mangle(m, sb->s_type->name);
6647 @@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6648         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6649         struct super_block *sb = mnt_path.dentry->d_sb;
6650  
6651 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6652 +               return SEQ_SKIP;
6653 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6654 +               return SEQ_SKIP;
6655 +
6656 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6657 +               mnt == current->fs->root.mnt) {
6658 +               seq_puts(m, "/dev/root / ");
6659 +               goto type;
6660 +       }
6661 +
6662         if (sb->s_op->show_devname) {
6663                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6664                 if (err)
6665 @@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6666         seq_putc(m, ' ');
6667         seq_path(m, &mnt_path, " \t\n\\");
6668         seq_putc(m, ' ');
6669 +type:
6670         show_type(m, sb);
6671         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6672         err = show_sb_opts(m, sb);
6673 @@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6674         struct path root = p->root;
6675         int err = 0;
6676  
6677 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6678 +               return SEQ_SKIP;
6679 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6680 +               return SEQ_SKIP;
6681 +
6682         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6683                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6684         if (sb->s_op->show_path)
6685 @@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file 
6686         struct super_block *sb = mnt_path.dentry->d_sb;
6687         int err = 0;
6688  
6689 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6690 +               return SEQ_SKIP;
6691 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6692 +               return SEQ_SKIP;
6693 +
6694 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6695 +               mnt == current->fs->root.mnt) {
6696 +               seq_puts(m, "device /dev/root mounted on / ");
6697 +               goto type;
6698 +       }
6699 +
6700         /* device */
6701         if (sb->s_op->show_devname) {
6702                 seq_puts(m, "device ");
6703 @@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file 
6704         seq_puts(m, " mounted on ");
6705         seq_path(m, &mnt_path, " \t\n\\");
6706         seq_putc(m, ' ');
6707 -
6708 +type:
6709         /* file system type */
6710         seq_puts(m, "with fstype ");
6711         show_type(m, sb);
6712 diff -NurpP --minimal linux-3.5.4/fs/quota/dquot.c linux-3.5.4-vs2.3.4.3/fs/quota/dquot.c
6713 --- linux-3.5.4/fs/quota/dquot.c        2012-07-22 23:39:42.000000000 +0200
6714 +++ linux-3.5.4-vs2.3.4.3/fs/quota/dquot.c      2012-07-23 01:45:55.000000000 +0200
6715 @@ -1562,6 +1562,9 @@ int __dquot_alloc_space(struct inode *in
6716         struct dquot **dquots = inode->i_dquot;
6717         int reserve = flags & DQUOT_SPACE_RESERVE;
6718  
6719 +       if ((ret = dl_alloc_space(inode, number)))
6720 +               return ret;
6721 +
6722         /*
6723          * First test before acquiring mutex - solves deadlocks when we
6724          * re-enter the quota code and are already holding the mutex
6725 @@ -1617,6 +1620,9 @@ int dquot_alloc_inode(const struct inode
6726         struct dquot_warn warn[MAXQUOTAS];
6727         struct dquot * const *dquots = inode->i_dquot;
6728  
6729 +       if ((ret = dl_alloc_inode(inode)))
6730 +               return ret;
6731 +
6732         /* First test before acquiring mutex - solves deadlocks when we
6733           * re-enter the quota code and are already holding the mutex */
6734         if (!dquot_active(inode))
6735 @@ -1688,6 +1694,8 @@ void __dquot_free_space(struct inode *in
6736         struct dquot **dquots = inode->i_dquot;
6737         int reserve = flags & DQUOT_SPACE_RESERVE;
6738  
6739 +       dl_free_space(inode, number);
6740 +
6741         /* First test before acquiring mutex - solves deadlocks when we
6742           * re-enter the quota code and are already holding the mutex */
6743         if (!dquot_active(inode)) {
6744 @@ -1732,6 +1740,8 @@ void dquot_free_inode(const struct inode
6745         struct dquot_warn warn[MAXQUOTAS];
6746         struct dquot * const *dquots = inode->i_dquot;
6747  
6748 +       dl_free_inode(inode);
6749 +
6750         /* First test before acquiring mutex - solves deadlocks when we
6751           * re-enter the quota code and are already holding the mutex */
6752         if (!dquot_active(inode))
6753 diff -NurpP --minimal linux-3.5.4/fs/quota/quota.c linux-3.5.4-vs2.3.4.3/fs/quota/quota.c
6754 --- linux-3.5.4/fs/quota/quota.c        2012-05-21 18:07:26.000000000 +0200
6755 +++ linux-3.5.4-vs2.3.4.3/fs/quota/quota.c      2012-07-23 01:45:55.000000000 +0200
6756 @@ -8,6 +8,7 @@
6757  #include <linux/fs.h>
6758  #include <linux/namei.h>
6759  #include <linux/slab.h>
6760 +#include <linux/vs_context.h>
6761  #include <asm/current.h>
6762  #include <asm/uaccess.h>
6763  #include <linux/kernel.h>
6764 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6765                         break;
6766                 /*FALLTHROUGH*/
6767         default:
6768 -               if (!capable(CAP_SYS_ADMIN))
6769 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6770                         return -EPERM;
6771         }
6772  
6773 @@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6774         }
6775  }
6776  
6777 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6778 +
6779 +#include <linux/vroot.h>
6780 +#include <linux/major.h>
6781 +#include <linux/module.h>
6782 +#include <linux/kallsyms.h>
6783 +#include <linux/vserver/debug.h>
6784 +
6785 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6786 +
6787 +static DEFINE_SPINLOCK(vroot_grb_lock);
6788 +
6789 +int register_vroot_grb(vroot_grb_func *func) {
6790 +       int ret = -EBUSY;
6791 +
6792 +       spin_lock(&vroot_grb_lock);
6793 +       if (!vroot_get_real_bdev) {
6794 +               vroot_get_real_bdev = func;
6795 +               ret = 0;
6796 +       }
6797 +       spin_unlock(&vroot_grb_lock);
6798 +       return ret;
6799 +}
6800 +EXPORT_SYMBOL(register_vroot_grb);
6801 +
6802 +int unregister_vroot_grb(vroot_grb_func *func) {
6803 +       int ret = -EINVAL;
6804 +
6805 +       spin_lock(&vroot_grb_lock);
6806 +       if (vroot_get_real_bdev) {
6807 +               vroot_get_real_bdev = NULL;
6808 +               ret = 0;
6809 +       }
6810 +       spin_unlock(&vroot_grb_lock);
6811 +       return ret;
6812 +}
6813 +EXPORT_SYMBOL(unregister_vroot_grb);
6814 +
6815 +#endif
6816 +
6817  /* Return 1 if 'cmd' will block on frozen filesystem */
6818  static int quotactl_cmd_write(int cmd)
6819  {
6820 @@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6821         putname(tmp);
6822         if (IS_ERR(bdev))
6823                 return ERR_CAST(bdev);
6824 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6825 +       if (bdev && bdev->bd_inode &&
6826 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6827 +               struct block_device *bdnew = (void *)-EINVAL;
6828 +
6829 +               if (vroot_get_real_bdev)
6830 +                       bdnew = vroot_get_real_bdev(bdev);
6831 +               else
6832 +                       vxdprintk(VXD_CBIT(misc, 0),
6833 +                                       "vroot_get_real_bdev not set");
6834 +               bdput(bdev);
6835 +               if (IS_ERR(bdnew))
6836 +                       return ERR_PTR(PTR_ERR(bdnew));
6837 +               bdev = bdnew;
6838 +       }
6839 +#endif
6840         if (quotactl_cmd_write(cmd))
6841                 sb = get_super_thawed(bdev);
6842         else
6843 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/file.c linux-3.5.4-vs2.3.4.3/fs/reiserfs/file.c
6844 --- linux-3.5.4/fs/reiserfs/file.c      2012-05-21 18:07:26.000000000 +0200
6845 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/file.c    2012-07-23 01:45:55.000000000 +0200
6846 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6847         .listxattr = reiserfs_listxattr,
6848         .removexattr = reiserfs_removexattr,
6849         .permission = reiserfs_permission,
6850 +       .sync_flags = reiserfs_sync_flags,
6851         .get_acl = reiserfs_get_acl,
6852  };
6853 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/inode.c linux-3.5.4-vs2.3.4.3/fs/reiserfs/inode.c
6854 --- linux-3.5.4/fs/reiserfs/inode.c     2012-07-22 23:39:42.000000000 +0200
6855 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/inode.c   2012-07-23 01:45:55.000000000 +0200
6856 @@ -18,6 +18,7 @@
6857  #include <linux/writeback.h>
6858  #include <linux/quotaops.h>
6859  #include <linux/swap.h>
6860 +#include <linux/vs_tag.h>
6861  
6862  int reiserfs_commit_write(struct file *f, struct page *page,
6863                           unsigned from, unsigned to);
6864 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6865         struct buffer_head *bh;
6866         struct item_head *ih;
6867         __u32 rdev;
6868 +       uid_t uid;
6869 +       gid_t gid;
6870         //int version = ITEM_VERSION_1;
6871  
6872         bh = PATH_PLAST_BUFFER(path);
6873 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6874                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6875                 unsigned long blocks;
6876  
6877 +               uid = sd_v1_uid(sd);
6878 +               gid = sd_v1_gid(sd);
6879 +
6880                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6881                 set_inode_sd_version(inode, STAT_DATA_V1);
6882                 inode->i_mode = sd_v1_mode(sd);
6883                 set_nlink(inode, sd_v1_nlink(sd));
6884 -               inode->i_uid = sd_v1_uid(sd);
6885 -               inode->i_gid = sd_v1_gid(sd);
6886                 inode->i_size = sd_v1_size(sd);
6887                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6888                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6889 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6890                 // (directories and symlinks)
6891                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6892  
6893 +               uid    = sd_v2_uid(sd);
6894 +               gid    = sd_v2_gid(sd);
6895 +
6896                 inode->i_mode = sd_v2_mode(sd);
6897                 set_nlink(inode, sd_v2_nlink(sd));
6898 -               inode->i_uid = sd_v2_uid(sd);
6899                 inode->i_size = sd_v2_size(sd);
6900 -               inode->i_gid = sd_v2_gid(sd);
6901                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6902                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6903                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6904 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6905                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6906         }
6907  
6908 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6909 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6910 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6911 +
6912         pathrelse(path);
6913         if (S_ISREG(inode->i_mode)) {
6914                 inode->i_op = &reiserfs_file_inode_operations;
6915 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6916  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6917  {
6918         struct stat_data *sd_v2 = (struct stat_data *)sd;
6919 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6920 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6921         __u16 flags;
6922  
6923 +       set_sd_v2_uid(sd_v2, uid);
6924 +       set_sd_v2_gid(sd_v2, gid);
6925         set_sd_v2_mode(sd_v2, inode->i_mode);
6926         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6927 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6928         set_sd_v2_size(sd_v2, size);
6929 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6930         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6931         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6932         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6933 @@ -2862,14 +2873,19 @@ int reiserfs_commit_write(struct file *f
6934  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6935  {
6936         if (reiserfs_attrs(inode->i_sb)) {
6937 -               if (sd_attrs & REISERFS_SYNC_FL)
6938 -                       inode->i_flags |= S_SYNC;
6939 -               else
6940 -                       inode->i_flags &= ~S_SYNC;
6941                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6942                         inode->i_flags |= S_IMMUTABLE;
6943                 else
6944                         inode->i_flags &= ~S_IMMUTABLE;
6945 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6946 +                       inode->i_flags |= S_IXUNLINK;
6947 +               else
6948 +                       inode->i_flags &= ~S_IXUNLINK;
6949 +
6950 +               if (sd_attrs & REISERFS_SYNC_FL)
6951 +                       inode->i_flags |= S_SYNC;
6952 +               else
6953 +                       inode->i_flags &= ~S_SYNC;
6954                 if (sd_attrs & REISERFS_APPEND_FL)
6955                         inode->i_flags |= S_APPEND;
6956                 else
6957 @@ -2882,6 +2898,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6958                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6959                 else
6960                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6961 +
6962 +               if (sd_attrs & REISERFS_BARRIER_FL)
6963 +                       inode->i_vflags |= V_BARRIER;
6964 +               else
6965 +                       inode->i_vflags &= ~V_BARRIER;
6966 +               if (sd_attrs & REISERFS_COW_FL)
6967 +                       inode->i_vflags |= V_COW;
6968 +               else
6969 +                       inode->i_vflags &= ~V_COW;
6970         }
6971  }
6972  
6973 @@ -2892,6 +2917,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6974                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6975                 else
6976                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6977 +               if (inode->i_flags & S_IXUNLINK)
6978 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6979 +               else
6980 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6981 +
6982                 if (inode->i_flags & S_SYNC)
6983                         *sd_attrs |= REISERFS_SYNC_FL;
6984                 else
6985 @@ -2904,6 +2934,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6986                         *sd_attrs |= REISERFS_NOTAIL_FL;
6987                 else
6988                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6989 +
6990 +               if (inode->i_vflags & V_BARRIER)
6991 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6992 +               else
6993 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6994 +               if (inode->i_vflags & V_COW)
6995 +                       *sd_attrs |= REISERFS_COW_FL;
6996 +               else
6997 +                       *sd_attrs &= ~REISERFS_COW_FL;
6998         }
6999  }
7000  
7001 @@ -3149,7 +3188,8 @@ int reiserfs_setattr(struct dentry *dent
7002         }
7003  
7004         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7005 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7006 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7007 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7008                 struct reiserfs_transaction_handle th;
7009                 int jbegin_count =
7010                     2 *
7011 @@ -3178,6 +3218,9 @@ int reiserfs_setattr(struct dentry *dent
7012                         inode->i_uid = attr->ia_uid;
7013                 if (attr->ia_valid & ATTR_GID)
7014                         inode->i_gid = attr->ia_gid;
7015 +                               if ((attr->ia_valid & ATTR_TAG) &&
7016 +                                       IS_TAGGED(inode))
7017 +                                       inode->i_tag = attr->ia_tag;
7018                 mark_inode_dirty(inode);
7019                 error = journal_end(&th, inode->i_sb, jbegin_count);
7020                 if (error)
7021 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/ioctl.c linux-3.5.4-vs2.3.4.3/fs/reiserfs/ioctl.c
7022 --- linux-3.5.4/fs/reiserfs/ioctl.c     2012-05-21 18:07:27.000000000 +0200
7023 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/ioctl.c   2012-07-23 01:45:55.000000000 +0200
7024 @@ -11,6 +11,21 @@
7025  #include <linux/pagemap.h>
7026  #include <linux/compat.h>
7027  
7028 +
7029 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7030 +{
7031 +       __u16 sd_attrs = 0;
7032 +
7033 +       inode->i_flags = flags;
7034 +       inode->i_vflags = vflags;
7035 +
7036 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7037 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7038 +       inode->i_ctime = CURRENT_TIME_SEC;
7039 +       mark_inode_dirty(inode);
7040 +       return 0;
7041 +}
7042 +
7043  /*
7044   * reiserfs_ioctl - handler for ioctl for inode
7045   * supported commands:
7046 @@ -22,7 +37,7 @@
7047  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7048  {
7049         struct inode *inode = filp->f_path.dentry->d_inode;
7050 -       unsigned int flags;
7051 +       unsigned int flags, oldflags;
7052         int err = 0;
7053  
7054         reiserfs_write_lock(inode->i_sb);
7055 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7056  
7057                 flags = REISERFS_I(inode)->i_attrs;
7058                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7059 +               flags &= REISERFS_FL_USER_VISIBLE;
7060                 err = put_user(flags, (int __user *)arg);
7061                 break;
7062         case REISERFS_IOC_SETFLAGS:{
7063 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7064                                 err = -EFAULT;
7065                                 goto setflags_out;
7066                         }
7067 +                       if (IS_BARRIER(inode)) {
7068 +                               vxwprintk_task(1, "messing with the barrier.");
7069 +                               return -EACCES;
7070 +                       }
7071                         /*
7072                          * Is it quota file? Do not allow user to mess with it
7073                          */
7074 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7075                                         goto setflags_out;
7076                                 }
7077                         }
7078 +
7079 +                       oldflags = REISERFS_I(inode)->i_attrs;
7080 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7081 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7082                         sd_attrs_to_i_attrs(flags, inode);
7083                         REISERFS_I(inode)->i_attrs = flags;
7084                         inode->i_ctime = CURRENT_TIME_SEC;
7085 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/namei.c linux-3.5.4-vs2.3.4.3/fs/reiserfs/namei.c
7086 --- linux-3.5.4/fs/reiserfs/namei.c     2012-05-21 18:07:27.000000000 +0200
7087 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/namei.c   2012-07-23 01:45:55.000000000 +0200
7088 @@ -18,6 +18,7 @@
7089  #include "acl.h"
7090  #include "xattr.h"
7091  #include <linux/quotaops.h>
7092 +#include <linux/vs_tag.h>
7093  
7094  #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); }
7095  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7096 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7097         if (retval == IO_ERROR) {
7098                 return ERR_PTR(-EIO);
7099         }
7100 +               dx_propagate_tag(nd, inode);
7101  
7102         return d_splice_alias(inode, dentry);
7103  }
7104 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/reiserfs.h linux-3.5.4-vs2.3.4.3/fs/reiserfs/reiserfs.h
7105 --- linux-3.5.4/fs/reiserfs/reiserfs.h  2012-07-22 23:39:42.000000000 +0200
7106 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/reiserfs.h        2012-07-23 01:45:55.000000000 +0200
7107 @@ -549,6 +549,7 @@ enum reiserfs_mount_options {
7108         REISERFS_EXPOSE_PRIVROOT,
7109         REISERFS_BARRIER_NONE,
7110         REISERFS_BARRIER_FLUSH,
7111 +       REISERFS_TAGGED,
7112  
7113         /* Actions on error */
7114         REISERFS_ERROR_PANIC,
7115 @@ -1548,6 +1549,11 @@ struct stat_data_v1 {
7116  #define REISERFS_COMPR_FL     FS_COMPR_FL
7117  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
7118  
7119 +/* unfortunately reiserfs sdattr is only 16 bit */
7120 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
7121 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
7122 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
7123 +
7124  /* persistent flags that file inherits from the parent directory */
7125  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
7126                                 REISERFS_SYNC_FL |      \
7127 @@ -1557,6 +1563,9 @@ struct stat_data_v1 {
7128                                 REISERFS_COMPR_FL |     \
7129                                 REISERFS_NOTAIL_FL )
7130  
7131 +#define REISERFS_FL_USER_VISIBLE       0x80FF
7132 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
7133 +
7134  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7135     address blocks) */
7136  struct stat_data {
7137 @@ -2647,6 +2656,7 @@ static inline void reiserfs_update_sd(st
7138  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7139  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7140  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7141 +int reiserfs_sync_flags(struct inode *inode, int, int);
7142  
7143  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7144  
7145 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/super.c linux-3.5.4-vs2.3.4.3/fs/reiserfs/super.c
7146 --- linux-3.5.4/fs/reiserfs/super.c     2012-07-22 23:39:42.000000000 +0200
7147 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/super.c   2012-07-23 01:45:55.000000000 +0200
7148 @@ -1013,6 +1013,14 @@ static int reiserfs_parse_options(struct
7149                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7150                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7151  #endif
7152 +#ifndef CONFIG_TAGGING_NONE
7153 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7154 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7155 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7156 +#endif
7157 +#ifdef CONFIG_PROPAGATE
7158 +               {"tag",.arg_required = 'T',.values = NULL},
7159 +#endif
7160  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7161                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7162                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7163 @@ -1331,6 +1339,14 @@ static int reiserfs_remount(struct super
7164         handle_quota_files(s, qf_names, &qfmt);
7165  #endif
7166  
7167 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7168 +               !(s->s_flags & MS_TAGGED)) {
7169 +               reiserfs_warning(s, "super-vs01",
7170 +                       "reiserfs: tagging not permitted on remount.");
7171 +               err = -EINVAL;
7172 +               goto out_err;
7173 +       }
7174 +
7175         handle_attrs(s);
7176  
7177         /* Add options that are safe here */
7178 @@ -1811,6 +1827,10 @@ static int reiserfs_fill_super(struct su
7179                 goto error_unlocked;
7180         }
7181  
7182 +       /* map mount option tagxid */
7183 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7184 +               s->s_flags |= MS_TAGGED;
7185 +
7186         rs = SB_DISK_SUPER_BLOCK(s);
7187         /* Let's do basic sanity check to verify that underlying device is not
7188            smaller than the filesystem. If the check fails then abort and scream,
7189 diff -NurpP --minimal linux-3.5.4/fs/reiserfs/xattr.c linux-3.5.4-vs2.3.4.3/fs/reiserfs/xattr.c
7190 --- linux-3.5.4/fs/reiserfs/xattr.c     2012-05-21 18:07:27.000000000 +0200
7191 +++ linux-3.5.4-vs2.3.4.3/fs/reiserfs/xattr.c   2012-07-23 01:45:55.000000000 +0200
7192 @@ -40,6 +40,7 @@
7193  #include <linux/errno.h>
7194  #include <linux/gfp.h>
7195  #include <linux/fs.h>
7196 +#include <linux/mount.h>
7197  #include <linux/file.h>
7198  #include <linux/pagemap.h>
7199  #include <linux/xattr.h>
7200 diff -NurpP --minimal linux-3.5.4/fs/stat.c linux-3.5.4-vs2.3.4.3/fs/stat.c
7201 --- linux-3.5.4/fs/stat.c       2012-07-22 23:39:42.000000000 +0200
7202 +++ linux-3.5.4-vs2.3.4.3/fs/stat.c     2012-07-23 01:45:55.000000000 +0200
7203 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7204         stat->nlink = inode->i_nlink;
7205         stat->uid = inode->i_uid;
7206         stat->gid = inode->i_gid;
7207 +       stat->tag = inode->i_tag;
7208         stat->rdev = inode->i_rdev;
7209         stat->size = i_size_read(inode);
7210         stat->atime = inode->i_atime;
7211 diff -NurpP --minimal linux-3.5.4/fs/statfs.c linux-3.5.4-vs2.3.4.3/fs/statfs.c
7212 --- linux-3.5.4/fs/statfs.c     2012-07-22 23:39:42.000000000 +0200
7213 +++ linux-3.5.4-vs2.3.4.3/fs/statfs.c   2012-07-23 01:45:55.000000000 +0200
7214 @@ -7,6 +7,8 @@
7215  #include <linux/statfs.h>
7216  #include <linux/security.h>
7217  #include <linux/uaccess.h>
7218 +#include <linux/vs_base.h>
7219 +#include <linux/vs_dlimit.h>
7220  #include "internal.h"
7221  
7222  static int flags_by_mnt(int mnt_flags)
7223 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7224         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7225         if (retval == 0 && buf->f_frsize == 0)
7226                 buf->f_frsize = buf->f_bsize;
7227 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7228 +               vx_vsi_statfs(dentry->d_sb, buf);
7229         return retval;
7230  }
7231  
7232 diff -NurpP --minimal linux-3.5.4/fs/super.c linux-3.5.4-vs2.3.4.3/fs/super.c
7233 --- linux-3.5.4/fs/super.c      2012-05-21 18:07:27.000000000 +0200
7234 +++ linux-3.5.4-vs2.3.4.3/fs/super.c    2012-07-23 01:45:55.000000000 +0200
7235 @@ -33,6 +33,8 @@
7236  #include <linux/rculist_bl.h>
7237  #include <linux/cleancache.h>
7238  #include <linux/fsnotify.h>
7239 +#include <linux/magic.h>
7240 +#include <linux/vs_context.h>
7241  #include "internal.h"
7242  
7243  
7244 @@ -1138,6 +1140,13 @@ mount_fs(struct file_system_type *type, 
7245         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7246         sb->s_flags |= MS_BORN;
7247  
7248 +       error = -EPERM;
7249 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7250 +               !sb->s_bdev &&
7251 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7252 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7253 +               goto out_sb;
7254 +
7255         error = security_sb_kern_mount(sb, flags, secdata);
7256         if (error)
7257                 goto out_sb;
7258 diff -NurpP --minimal linux-3.5.4/fs/sysfs/mount.c linux-3.5.4-vs2.3.4.3/fs/sysfs/mount.c
7259 --- linux-3.5.4/fs/sysfs/mount.c        2012-05-21 18:07:27.000000000 +0200
7260 +++ linux-3.5.4-vs2.3.4.3/fs/sysfs/mount.c      2012-07-23 01:45:55.000000000 +0200
7261 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7262  
7263         sb->s_blocksize = PAGE_CACHE_SIZE;
7264         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7265 -       sb->s_magic = SYSFS_MAGIC;
7266 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7267         sb->s_op = &sysfs_ops;
7268         sb->s_time_gran = 1;
7269  
7270 diff -NurpP --minimal linux-3.5.4/fs/utimes.c linux-3.5.4-vs2.3.4.3/fs/utimes.c
7271 --- linux-3.5.4/fs/utimes.c     2012-07-22 23:39:42.000000000 +0200
7272 +++ linux-3.5.4-vs2.3.4.3/fs/utimes.c   2012-07-23 01:45:55.000000000 +0200
7273 @@ -8,6 +8,8 @@
7274  #include <linux/stat.h>
7275  #include <linux/utime.h>
7276  #include <linux/syscalls.h>
7277 +#include <linux/mount.h>
7278 +#include <linux/vs_cowbl.h>
7279  #include <asm/uaccess.h>
7280  #include <asm/unistd.h>
7281  
7282 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7283  {
7284         int error;
7285         struct iattr newattrs;
7286 -       struct inode *inode = path->dentry->d_inode;
7287 +       struct inode *inode;
7288  
7289         error = mnt_want_write(path->mnt);
7290         if (error)
7291                 goto out;
7292  
7293 +       error = cow_check_and_break(path);
7294 +       if (error)
7295 +               goto mnt_drop_write_and_out;
7296 +
7297 +       inode = path->dentry->d_inode;
7298 +
7299         if (times && times[0].tv_nsec == UTIME_NOW &&
7300                      times[1].tv_nsec == UTIME_NOW)
7301                 times = NULL;
7302 diff -NurpP --minimal linux-3.5.4/fs/xattr.c linux-3.5.4-vs2.3.4.3/fs/xattr.c
7303 --- linux-3.5.4/fs/xattr.c      2012-07-22 23:39:42.000000000 +0200
7304 +++ linux-3.5.4-vs2.3.4.3/fs/xattr.c    2012-07-23 01:45:55.000000000 +0200
7305 @@ -20,6 +20,7 @@
7306  #include <linux/fsnotify.h>
7307  #include <linux/audit.h>
7308  #include <linux/vmalloc.h>
7309 +#include <linux/mount.h>
7310  
7311  #include <asm/uaccess.h>
7312  
7313 @@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7314          * The trusted.* namespace can only be accessed by privileged users.
7315          */
7316         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7317 -               if (!capable(CAP_SYS_ADMIN))
7318 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7319                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7320                 return 0;
7321         }
7322 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_dinode.h linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_dinode.h
7323 --- linux-3.5.4/fs/xfs/xfs_dinode.h     2011-10-24 18:45:31.000000000 +0200
7324 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_dinode.h   2012-07-23 01:45:55.000000000 +0200
7325 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7326         __be32          di_nlink;       /* number of links to file */
7327         __be16          di_projid_lo;   /* lower part of owner's project id */
7328         __be16          di_projid_hi;   /* higher part owner's project id */
7329 -       __u8            di_pad[6];      /* unused, zeroed space */
7330 +       __u8            di_pad[2];      /* unused, zeroed space */
7331 +       __be16          di_tag;         /* context tagging */
7332 +       __be16          di_vflags;      /* vserver specific flags */
7333         __be16          di_flushiter;   /* incremented on flush */
7334         xfs_timestamp_t di_atime;       /* time last accessed */
7335         xfs_timestamp_t di_mtime;       /* time last modified */
7336 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7337  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7338  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7339  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7340 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7341 +
7342  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7343  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7344  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7345 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7346  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7347  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7348  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7349 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7350  
7351  #ifdef CONFIG_XFS_RT
7352  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7353 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7354          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7355          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7356          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7357 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7358 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7359 +        XFS_DIFLAG_IXUNLINK)
7360 +
7361 +#define XFS_DIVFLAG_BARRIER    0x01
7362 +#define XFS_DIVFLAG_COW                0x02
7363  
7364  #endif /* __XFS_DINODE_H__ */
7365 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_fs.h linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_fs.h
7366 --- linux-3.5.4/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7367 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_fs.h       2012-07-23 01:45:55.000000000 +0200
7368 @@ -67,6 +67,9 @@ struct fsxattr {
7369  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7370  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7371  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7372 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7373 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7374 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7375  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7376  
7377  /*
7378 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7379  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7380         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7381         __u16           bs_projid_hi;   /* higher part of project id    */
7382 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7383 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7384 +       __u16           bs_tag;         /* context tagging              */
7385         __u32           bs_dmevmask;    /* DMIG event mask              */
7386         __u16           bs_dmstate;     /* DMIG state info              */
7387         __u16           bs_aextents;    /* attribute number of extents  */
7388 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_ialloc.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_ialloc.c
7389 --- linux-3.5.4/fs/xfs/xfs_ialloc.c     2012-07-22 23:39:42.000000000 +0200
7390 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_ialloc.c   2012-07-23 01:45:55.000000000 +0200
7391 @@ -37,7 +37,6 @@
7392  #include "xfs_error.h"
7393  #include "xfs_bmap.h"
7394  
7395 -
7396  /*
7397   * Allocation group level functions.
7398   */
7399 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_inode.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_inode.c
7400 --- linux-3.5.4/fs/xfs/xfs_inode.c      2012-07-22 23:39:42.000000000 +0200
7401 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_inode.c    2012-07-23 01:45:55.000000000 +0200
7402 @@ -250,6 +250,7 @@ xfs_inotobp(
7403         return 0;
7404  }
7405  
7406 +#include <linux/vs_tag.h>
7407  
7408  /*
7409   * This routine is called to map an inode to the buffer containing
7410 @@ -645,15 +646,25 @@ xfs_iformat_btree(
7411  STATIC void
7412  xfs_dinode_from_disk(
7413         xfs_icdinode_t          *to,
7414 -       xfs_dinode_t            *from)
7415 +       xfs_dinode_t            *from,
7416 +       int tagged)
7417  {
7418 +       uint32_t uid, gid, tag;
7419 +
7420         to->di_magic = be16_to_cpu(from->di_magic);
7421         to->di_mode = be16_to_cpu(from->di_mode);
7422         to->di_version = from ->di_version;
7423         to->di_format = from->di_format;
7424         to->di_onlink = be16_to_cpu(from->di_onlink);
7425 -       to->di_uid = be32_to_cpu(from->di_uid);
7426 -       to->di_gid = be32_to_cpu(from->di_gid);
7427 +
7428 +       uid = be32_to_cpu(from->di_uid);
7429 +       gid = be32_to_cpu(from->di_gid);
7430 +       tag = be16_to_cpu(from->di_tag);
7431 +
7432 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7433 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7434 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7435 +
7436         to->di_nlink = be32_to_cpu(from->di_nlink);
7437         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7438         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7439 @@ -675,21 +686,26 @@ xfs_dinode_from_disk(
7440         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7441         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7442         to->di_flags    = be16_to_cpu(from->di_flags);
7443 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7444         to->di_gen      = be32_to_cpu(from->di_gen);
7445  }
7446  
7447  void
7448  xfs_dinode_to_disk(
7449         xfs_dinode_t            *to,
7450 -       xfs_icdinode_t          *from)
7451 +       xfs_icdinode_t          *from,
7452 +       int tagged)
7453  {
7454         to->di_magic = cpu_to_be16(from->di_magic);
7455         to->di_mode = cpu_to_be16(from->di_mode);
7456         to->di_version = from ->di_version;
7457         to->di_format = from->di_format;
7458         to->di_onlink = cpu_to_be16(from->di_onlink);
7459 -       to->di_uid = cpu_to_be32(from->di_uid);
7460 -       to->di_gid = cpu_to_be32(from->di_gid);
7461 +
7462 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7463 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7464 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7465 +
7466         to->di_nlink = cpu_to_be32(from->di_nlink);
7467         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7468         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7469 @@ -711,12 +727,14 @@ xfs_dinode_to_disk(
7470         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7471         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7472         to->di_flags = cpu_to_be16(from->di_flags);
7473 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7474         to->di_gen = cpu_to_be32(from->di_gen);
7475  }
7476  
7477  STATIC uint
7478  _xfs_dic2xflags(
7479 -       __uint16_t              di_flags)
7480 +       __uint16_t              di_flags,
7481 +       __uint16_t              di_vflags)
7482  {
7483         uint                    flags = 0;
7484  
7485 @@ -727,6 +745,8 @@ _xfs_dic2xflags(
7486                         flags |= XFS_XFLAG_PREALLOC;
7487                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7488                         flags |= XFS_XFLAG_IMMUTABLE;
7489 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7490 +                       flags |= XFS_XFLAG_IXUNLINK;
7491                 if (di_flags & XFS_DIFLAG_APPEND)
7492                         flags |= XFS_XFLAG_APPEND;
7493                 if (di_flags & XFS_DIFLAG_SYNC)
7494 @@ -751,6 +771,10 @@ _xfs_dic2xflags(
7495                         flags |= XFS_XFLAG_FILESTREAM;
7496         }
7497  
7498 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7499 +               flags |= FS_BARRIER_FL;
7500 +       if (di_vflags & XFS_DIVFLAG_COW)
7501 +               flags |= FS_COW_FL;
7502         return flags;
7503  }
7504  
7505 @@ -760,7 +784,7 @@ xfs_ip2xflags(
7506  {
7507         xfs_icdinode_t          *dic = &ip->i_d;
7508  
7509 -       return _xfs_dic2xflags(dic->di_flags) |
7510 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7511                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7512  }
7513  
7514 @@ -768,7 +792,8 @@ uint
7515  xfs_dic2xflags(
7516         xfs_dinode_t            *dip)
7517  {
7518 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7519 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7520 +                               be16_to_cpu(dip->di_vflags)) |
7521                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7522  }
7523  
7524 @@ -800,7 +825,6 @@ xfs_iread(
7525         if (error)
7526                 return error;
7527         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7528 -
7529         /*
7530          * If we got something that isn't an inode it means someone
7531          * (nfs or dmi) has a stale handle.
7532 @@ -823,7 +847,8 @@ xfs_iread(
7533          * Otherwise, just get the truly permanent information.
7534          */
7535         if (dip->di_mode) {
7536 -               xfs_dinode_from_disk(&ip->i_d, dip);
7537 +               xfs_dinode_from_disk(&ip->i_d, dip,
7538 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7539                 error = xfs_iformat(ip, dip);
7540                 if (error)  {
7541  #ifdef DEBUG
7542 @@ -1011,6 +1036,7 @@ xfs_ialloc(
7543         ASSERT(ip->i_d.di_nlink == nlink);
7544         ip->i_d.di_uid = current_fsuid();
7545         ip->i_d.di_gid = current_fsgid();
7546 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7547         xfs_set_projid(ip, prid);
7548         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7549  
7550 @@ -1070,6 +1096,7 @@ xfs_ialloc(
7551         ip->i_d.di_dmevmask = 0;
7552         ip->i_d.di_dmstate = 0;
7553         ip->i_d.di_flags = 0;
7554 +       ip->i_d.di_vflags = 0;
7555         flags = XFS_ILOG_CORE;
7556         switch (mode & S_IFMT) {
7557         case S_IFIFO:
7558 @@ -1737,6 +1764,7 @@ xfs_ifree(
7559         }
7560         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7561         ip->i_d.di_flags = 0;
7562 +       ip->i_d.di_vflags = 0;
7563         ip->i_d.di_dmevmask = 0;
7564         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7565         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7566 @@ -2589,7 +2617,8 @@ xfs_iflush_int(
7567          * because if the inode is dirty at all the core must
7568          * be.
7569          */
7570 -       xfs_dinode_to_disk(dip, &ip->i_d);
7571 +       xfs_dinode_to_disk(dip, &ip->i_d,
7572 +               mp->m_flags & XFS_MOUNT_TAGGED);
7573  
7574         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7575         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7576 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_inode.h linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_inode.h
7577 --- linux-3.5.4/fs/xfs/xfs_inode.h      2012-07-22 23:39:42.000000000 +0200
7578 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_inode.h    2012-07-23 01:45:55.000000000 +0200
7579 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7580         __uint32_t      di_nlink;       /* number of links to file */
7581         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7582         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7583 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7584 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7585 +       __uint16_t      di_tag;         /* context tagging */
7586 +       __uint16_t      di_vflags;      /* vserver specific flags */
7587         __uint16_t      di_flushiter;   /* incremented on flush */
7588         xfs_ictimestamp_t di_atime;     /* time last accessed */
7589         xfs_ictimestamp_t di_mtime;     /* time last modified */
7590 @@ -566,7 +568,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7591  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7592                           struct xfs_inode *, uint);
7593  void           xfs_dinode_to_disk(struct xfs_dinode *,
7594 -                                  struct xfs_icdinode *);
7595 +                                  struct xfs_icdinode *, int);
7596  void           xfs_idestroy_fork(struct xfs_inode *, int);
7597  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7598  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7599 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_ioctl.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_ioctl.c
7600 --- linux-3.5.4/fs/xfs/xfs_ioctl.c      2012-07-22 23:39:42.000000000 +0200
7601 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_ioctl.c    2012-07-23 01:45:55.000000000 +0200
7602 @@ -26,7 +26,7 @@
7603  #include "xfs_bmap_btree.h"
7604  #include "xfs_dinode.h"
7605  #include "xfs_inode.h"
7606 -#include "xfs_ioctl.h"
7607 +// #include "xfs_ioctl.h"
7608  #include "xfs_rtalloc.h"
7609  #include "xfs_itable.h"
7610  #include "xfs_error.h"
7611 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7612                 xflags |= XFS_XFLAG_IMMUTABLE;
7613         else
7614                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7615 +       if (flags & FS_IXUNLINK_FL)
7616 +               xflags |= XFS_XFLAG_IXUNLINK;
7617 +       else
7618 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7619         if (flags & FS_APPEND_FL)
7620                 xflags |= XFS_XFLAG_APPEND;
7621         else
7622 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7623  
7624         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7625                 flags |= FS_IMMUTABLE_FL;
7626 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7627 +               flags |= FS_IXUNLINK_FL;
7628         if (di_flags & XFS_DIFLAG_APPEND)
7629                 flags |= FS_APPEND_FL;
7630         if (di_flags & XFS_DIFLAG_SYNC)
7631 @@ -836,6 +842,8 @@ xfs_set_diflags(
7632         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7633         if (xflags & XFS_XFLAG_IMMUTABLE)
7634                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7635 +       if (xflags & XFS_XFLAG_IXUNLINK)
7636 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7637         if (xflags & XFS_XFLAG_APPEND)
7638                 di_flags |= XFS_DIFLAG_APPEND;
7639         if (xflags & XFS_XFLAG_SYNC)
7640 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7641                 inode->i_flags |= S_IMMUTABLE;
7642         else
7643                 inode->i_flags &= ~S_IMMUTABLE;
7644 +       if (xflags & XFS_XFLAG_IXUNLINK)
7645 +               inode->i_flags |= S_IXUNLINK;
7646 +       else
7647 +               inode->i_flags &= ~S_IXUNLINK;
7648         if (xflags & XFS_XFLAG_APPEND)
7649                 inode->i_flags |= S_APPEND;
7650         else
7651 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7652         case XFS_IOC_FSGETXATTRA:
7653                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7654         case XFS_IOC_FSSETXATTR:
7655 +               if (IS_BARRIER(inode)) {
7656 +                       vxwprintk_task(1, "messing with the barrier.");
7657 +                       return -XFS_ERROR(EACCES);
7658 +               }
7659                 return xfs_ioc_fssetxattr(ip, filp, arg);
7660         case XFS_IOC_GETXFLAGS:
7661                 return xfs_ioc_getxflags(ip, arg);
7662         case XFS_IOC_SETXFLAGS:
7663 +               if (IS_BARRIER(inode)) {
7664 +                       vxwprintk_task(1, "messing with the barrier.");
7665 +                       return -XFS_ERROR(EACCES);
7666 +               }
7667                 return xfs_ioc_setxflags(ip, filp, arg);
7668  
7669         case XFS_IOC_FSSETDM: {
7670 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_ioctl.h linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_ioctl.h
7671 --- linux-3.5.4/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7672 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_ioctl.h    2012-07-23 01:45:55.000000000 +0200
7673 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7674         void __user             *uhandle,
7675         u32                     hlen);
7676  
7677 +extern int
7678 +xfs_sync_flags(
7679 +       struct inode            *inode,
7680 +       int                     flags,
7681 +       int                     vflags);
7682 +
7683  extern long
7684  xfs_file_ioctl(
7685         struct file             *filp,
7686 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_iops.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_iops.c
7687 --- linux-3.5.4/fs/xfs/xfs_iops.c       2012-07-22 23:39:42.000000000 +0200
7688 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_iops.c     2012-07-23 01:45:55.000000000 +0200
7689 @@ -28,6 +28,7 @@
7690  #include "xfs_bmap_btree.h"
7691  #include "xfs_dinode.h"
7692  #include "xfs_inode.h"
7693 +#include "xfs_ioctl.h"
7694  #include "xfs_bmap.h"
7695  #include "xfs_rtalloc.h"
7696  #include "xfs_error.h"
7697 @@ -46,6 +47,7 @@
7698  #include <linux/security.h>
7699  #include <linux/fiemap.h>
7700  #include <linux/slab.h>
7701 +#include <linux/vs_tag.h>
7702  
7703  static int
7704  xfs_initxattrs(
7705 @@ -421,6 +423,7 @@ xfs_vn_getattr(
7706         stat->nlink = ip->i_d.di_nlink;
7707         stat->uid = ip->i_d.di_uid;
7708         stat->gid = ip->i_d.di_gid;
7709 +       stat->tag = ip->i_d.di_tag;
7710         stat->ino = ip->i_ino;
7711         stat->atime = inode->i_atime;
7712         stat->mtime = inode->i_mtime;
7713 @@ -991,6 +994,7 @@ static const struct inode_operations xfs
7714         .removexattr            = generic_removexattr,
7715         .listxattr              = xfs_vn_listxattr,
7716         .fiemap                 = xfs_vn_fiemap,
7717 +       .sync_flags             = xfs_sync_flags,
7718  };
7719  
7720  static const struct inode_operations xfs_dir_inode_operations = {
7721 @@ -1016,6 +1020,7 @@ static const struct inode_operations xfs
7722         .getxattr               = generic_getxattr,
7723         .removexattr            = generic_removexattr,
7724         .listxattr              = xfs_vn_listxattr,
7725 +       .sync_flags             = xfs_sync_flags,
7726  };
7727  
7728  static const struct inode_operations xfs_dir_ci_inode_operations = {
7729 @@ -1065,6 +1070,10 @@ xfs_diflags_to_iflags(
7730                 inode->i_flags |= S_IMMUTABLE;
7731         else
7732                 inode->i_flags &= ~S_IMMUTABLE;
7733 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7734 +               inode->i_flags |= S_IXUNLINK;
7735 +       else
7736 +               inode->i_flags &= ~S_IXUNLINK;
7737         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7738                 inode->i_flags |= S_APPEND;
7739         else
7740 @@ -1077,6 +1086,15 @@ xfs_diflags_to_iflags(
7741                 inode->i_flags |= S_NOATIME;
7742         else
7743                 inode->i_flags &= ~S_NOATIME;
7744 +
7745 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7746 +               inode->i_vflags |= V_BARRIER;
7747 +       else
7748 +               inode->i_vflags &= ~V_BARRIER;
7749 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7750 +               inode->i_vflags |= V_COW;
7751 +       else
7752 +               inode->i_vflags &= ~V_COW;
7753  }
7754  
7755  /*
7756 @@ -1108,6 +1126,7 @@ xfs_setup_inode(
7757         set_nlink(inode, ip->i_d.di_nlink);
7758         inode->i_uid    = ip->i_d.di_uid;
7759         inode->i_gid    = ip->i_d.di_gid;
7760 +       inode->i_tag    = ip->i_d.di_tag;
7761  
7762         switch (inode->i_mode & S_IFMT) {
7763         case S_IFBLK:
7764 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_itable.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_itable.c
7765 --- linux-3.5.4/fs/xfs/xfs_itable.c     2012-07-22 23:39:42.000000000 +0200
7766 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_itable.c   2012-07-23 01:45:55.000000000 +0200
7767 @@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7768         buf->bs_mode = dic->di_mode;
7769         buf->bs_uid = dic->di_uid;
7770         buf->bs_gid = dic->di_gid;
7771 +       buf->bs_tag = dic->di_tag;
7772         buf->bs_size = dic->di_size;
7773         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7774         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7775 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_linux.h linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_linux.h
7776 --- linux-3.5.4/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7777 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_linux.h    2012-07-23 01:45:55.000000000 +0200
7778 @@ -121,6 +121,7 @@
7779  
7780  #define current_cpu()          (raw_smp_processor_id())
7781  #define current_pid()          (current->pid)
7782 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7783  #define current_test_flags(f)  (current->flags & (f))
7784  #define current_set_flags_nested(sp, f)                \
7785                 (*(sp) = current->flags, current->flags |= (f))
7786 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_log_recover.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_log_recover.c
7787 --- linux-3.5.4/fs/xfs/xfs_log_recover.c        2012-07-22 23:39:42.000000000 +0200
7788 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_log_recover.c      2012-07-23 01:45:55.000000000 +0200
7789 @@ -2351,7 +2351,8 @@ xlog_recover_inode_pass2(
7790         }
7791  
7792         /* The core is in in-core format */
7793 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7794 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7795 +               mp->m_flags & XFS_MOUNT_TAGGED);
7796  
7797         /* the rest is in on-disk format */
7798         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7799 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_mount.h linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_mount.h
7800 --- linux-3.5.4/fs/xfs/xfs_mount.h      2012-07-22 23:39:42.000000000 +0200
7801 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_mount.h    2012-07-23 01:45:55.000000000 +0200
7802 @@ -252,6 +252,7 @@ typedef struct xfs_mount {
7803                                                    allocator */
7804  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7805  
7806 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7807  
7808  /*
7809   * Default minimum read and write sizes.
7810 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_super.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_super.c
7811 --- linux-3.5.4/fs/xfs/xfs_super.c      2012-07-22 23:39:42.000000000 +0200
7812 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_super.c    2012-07-23 01:45:55.000000000 +0200
7813 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
7814  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7815  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7816  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7817 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7818 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7819 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7820  
7821  /*
7822   * Table driven mount option parser.
7823 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
7824   * in the future, too.
7825   */
7826  enum {
7827 +       Opt_tag, Opt_notag,
7828         Opt_barrier, Opt_nobarrier, Opt_err
7829  };
7830  
7831  static const match_table_t tokens = {
7832 +       {Opt_tag, "tagxid"},
7833 +       {Opt_tag, "tag"},
7834 +       {Opt_notag, "notag"},
7835         {Opt_barrier, "barrier"},
7836         {Opt_nobarrier, "nobarrier"},
7837         {Opt_err, NULL}
7838 @@ -371,6 +378,19 @@ xfs_parseargs(
7839                 } else if (!strcmp(this_char, "irixsgid")) {
7840                         xfs_warn(mp,
7841         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7842 +#ifndef CONFIG_TAGGING_NONE
7843 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7844 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7845 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7846 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7847 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7848 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7849 +#endif
7850 +#ifdef CONFIG_PROPAGATE
7851 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7852 +                       /* use value */
7853 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7854 +#endif
7855                 } else {
7856                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7857                         return EINVAL;
7858 @@ -1124,6 +1144,16 @@ xfs_fs_remount(
7859                 case Opt_nobarrier:
7860                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7861                         break;
7862 +               case Opt_tag:
7863 +                       if (!(sb->s_flags & MS_TAGGED)) {
7864 +                               printk(KERN_INFO
7865 +                                       "XFS: %s: tagging not permitted on remount.\n",
7866 +                                       sb->s_id);
7867 +                               return -EINVAL;
7868 +                       }
7869 +                       break;
7870 +               case Opt_notag:
7871 +                       break;
7872                 default:
7873                         /*
7874                          * Logically we would return an error here to prevent
7875 @@ -1343,6 +1373,9 @@ xfs_fs_fill_super(
7876         if (error)
7877                 goto out_free_sb;
7878  
7879 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7880 +               sb->s_flags |= MS_TAGGED;
7881 +
7882         /*
7883          * we must configure the block size in the superblock before we run the
7884          * full mount process as the mount process can lookup and cache inodes.
7885 diff -NurpP --minimal linux-3.5.4/fs/xfs/xfs_vnodeops.c linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_vnodeops.c
7886 --- linux-3.5.4/fs/xfs/xfs_vnodeops.c   2012-07-22 23:39:42.000000000 +0200
7887 +++ linux-3.5.4-vs2.3.4.3/fs/xfs/xfs_vnodeops.c 2012-07-23 01:45:55.000000000 +0200
7888 @@ -103,6 +103,77 @@ xfs_readlink_bmap(
7889         return error;
7890  }
7891  
7892 +
7893 +STATIC void
7894 +xfs_get_inode_flags(
7895 +       xfs_inode_t     *ip)
7896 +{
7897 +       struct inode    *inode = VFS_I(ip);
7898 +       unsigned int    flags = inode->i_flags;
7899 +       unsigned int    vflags = inode->i_vflags;
7900 +
7901 +       if (flags & S_IMMUTABLE)
7902 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7903 +       else
7904 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7905 +       if (flags & S_IXUNLINK)
7906 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7907 +       else
7908 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7909 +
7910 +       if (vflags & V_BARRIER)
7911 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7912 +       else
7913 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7914 +       if (vflags & V_COW)
7915 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7916 +       else
7917 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7918 +}
7919 +
7920 +int
7921 +xfs_sync_flags(
7922 +       struct inode            *inode,
7923 +       int                     flags,
7924 +       int                     vflags)
7925 +{
7926 +       struct xfs_inode        *ip = XFS_I(inode);
7927 +       struct xfs_mount        *mp = ip->i_mount;
7928 +       struct xfs_trans        *tp;
7929 +       unsigned int            lock_flags = 0;
7930 +       int                     code;
7931 +
7932 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7933 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7934 +       if (code)
7935 +               goto error_out;
7936 +
7937 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7938 +       xfs_trans_ijoin(tp, ip, 0);
7939 +
7940 +       inode->i_flags = flags;
7941 +       inode->i_vflags = vflags;
7942 +       xfs_get_inode_flags(ip);
7943 +
7944 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7945 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7946 +
7947 +       XFS_STATS_INC(xs_ig_attrchg);
7948 +
7949 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7950 +               xfs_trans_set_sync(tp);
7951 +       code = xfs_trans_commit(tp, 0);
7952 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7953 +       return code;
7954 +
7955 +error_out:
7956 +       xfs_trans_cancel(tp, 0);
7957 +       if (lock_flags)
7958 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7959 +       return code;
7960 +}
7961 +
7962 +
7963  int
7964  xfs_readlink(
7965         xfs_inode_t     *ip,
7966 diff -NurpP --minimal linux-3.5.4/include/linux/Kbuild linux-3.5.4-vs2.3.4.3/include/linux/Kbuild
7967 --- linux-3.5.4/include/linux/Kbuild    2012-07-22 23:39:43.000000000 +0200
7968 +++ linux-3.5.4-vs2.3.4.3/include/linux/Kbuild  2012-07-23 01:45:55.000000000 +0200
7969 @@ -18,6 +18,7 @@ header-y += netfilter_bridge/
7970  header-y += netfilter_ipv4/
7971  header-y += netfilter_ipv6/
7972  header-y += usb/
7973 +header-y += vserver/
7974  header-y += wimax/
7975  
7976  objhdr-y += version.h
7977 diff -NurpP --minimal linux-3.5.4/include/linux/capability.h linux-3.5.4-vs2.3.4.3/include/linux/capability.h
7978 --- linux-3.5.4/include/linux/capability.h      2012-07-22 23:39:43.000000000 +0200
7979 +++ linux-3.5.4-vs2.3.4.3/include/linux/capability.h    2012-07-23 01:45:55.000000000 +0200
7980 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7981     arbitrary SCSI commands */
7982  /* Allow setting encryption key on loopback filesystem */
7983  /* Allow setting zone reclaim policy */
7984 +/* Allow the selection of a security context */
7985  
7986  #define CAP_SYS_ADMIN        21
7987  
7988 @@ -366,7 +367,12 @@ struct cpu_vfs_cap_data {
7989  
7990  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
7991  
7992 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7993 +/* Allow context manipulations */
7994 +/* Allow changing context info on files */
7995 +
7996 +#define CAP_CONTEXT         63
7997 +
7998 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7999  
8000  /*
8001   * Bit location of each capability (used by user-space library and kernel)
8002 diff -NurpP --minimal linux-3.5.4/include/linux/cred.h linux-3.5.4-vs2.3.4.3/include/linux/cred.h
8003 --- linux-3.5.4/include/linux/cred.h    2012-07-22 23:39:43.000000000 +0200
8004 +++ linux-3.5.4-vs2.3.4.3/include/linux/cred.h  2012-07-23 01:45:55.000000000 +0200
8005 @@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
8006  extern int copy_creds(struct task_struct *, unsigned long);
8007  extern const struct cred *get_task_cred(struct task_struct *);
8008  extern struct cred *cred_alloc_blank(void);
8009 +extern struct cred *__prepare_creds(const struct cred *);
8010  extern struct cred *prepare_creds(void);
8011  extern struct cred *prepare_exec_creds(void);
8012  extern int commit_creds(struct cred *);
8013 @@ -210,6 +211,31 @@ static inline void validate_process_cred
8014  }
8015  #endif
8016  
8017 +static inline void set_cred_subscribers(struct cred *cred, int n)
8018 +{
8019 +#ifdef CONFIG_DEBUG_CREDENTIALS
8020 +       atomic_set(&cred->subscribers, n);
8021 +#endif
8022 +}
8023 +
8024 +static inline int read_cred_subscribers(const struct cred *cred)
8025 +{
8026 +#ifdef CONFIG_DEBUG_CREDENTIALS
8027 +       return atomic_read(&cred->subscribers);
8028 +#else
8029 +       return 0;
8030 +#endif
8031 +}
8032 +
8033 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8034 +{
8035 +#ifdef CONFIG_DEBUG_CREDENTIALS
8036 +       struct cred *cred = (struct cred *) _cred;
8037 +
8038 +       atomic_add(n, &cred->subscribers);
8039 +#endif
8040 +}
8041 +
8042  /**
8043   * get_new_cred - Get a reference on a new set of credentials
8044   * @cred: The new credentials to reference
8045 diff -NurpP --minimal linux-3.5.4/include/linux/devpts_fs.h linux-3.5.4-vs2.3.4.3/include/linux/devpts_fs.h
8046 --- linux-3.5.4/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
8047 +++ linux-3.5.4-vs2.3.4.3/include/linux/devpts_fs.h     2012-07-23 01:45:55.000000000 +0200
8048 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8049  
8050  #endif
8051  
8052 -
8053  #endif /* _LINUX_DEVPTS_FS_H */
8054 diff -NurpP --minimal linux-3.5.4/include/linux/fs.h linux-3.5.4-vs2.3.4.3/include/linux/fs.h
8055 --- linux-3.5.4/include/linux/fs.h      2012-07-22 23:39:43.000000000 +0200
8056 +++ linux-3.5.4-vs2.3.4.3/include/linux/fs.h    2012-07-23 10:22:46.000000000 +0200
8057 @@ -223,6 +223,9 @@ struct inodes_stat_t {
8058  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8059  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8060  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8061 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8062 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8063 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8064  #define MS_NOSEC       (1<<28)
8065  #define MS_BORN                (1<<29)
8066  #define MS_ACTIVE      (1<<30)
8067 @@ -254,6 +257,14 @@ struct inodes_stat_t {
8068  #define S_IMA          1024    /* Inode has an associated IMA struct */
8069  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8070  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8071 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8072 +
8073 +/* Linux-VServer related Inode flags */
8074 +
8075 +#define V_VALID                1
8076 +#define V_XATTR                2
8077 +#define V_BARRIER      4       /* Barrier for chroot() */
8078 +#define V_COW          8       /* Copy on Write */
8079  
8080  /*
8081   * Note that nosuid etc flags are inode-specific: setting some file-system
8082 @@ -276,12 +287,15 @@ struct inodes_stat_t {
8083  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8084                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8085  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8086 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8087 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8088 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8089 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8090 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8091  
8092  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8093  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8094  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8095 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8096 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8097  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8098  
8099  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8100 @@ -292,6 +306,16 @@ struct inodes_stat_t {
8101  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8102  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8103  
8104 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8105 +
8106 +#ifdef CONFIG_VSERVER_COWBL
8107 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8108 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8109 +#else
8110 +#  define IS_COW(inode)                (0)
8111 +#  define IS_COW_LINK(inode)   (0)
8112 +#endif
8113 +
8114  /* the read-only stuff doesn't really belong here, but any other place is
8115     probably as bad and I don't want to create yet another include file. */
8116  
8117 @@ -378,11 +402,14 @@ struct inodes_stat_t {
8118  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8119  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8120  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8121 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8122  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8123  
8124 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8125 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8126 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8127 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8128  
8129 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8130 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8131  
8132  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8133  #define SYNC_FILE_RANGE_WRITE          2
8134 @@ -466,6 +493,7 @@ typedef void (dio_iodone_t)(struct kiocb
8135  #define ATTR_KILL_PRIV (1 << 14)
8136  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8137  #define ATTR_TIMES_SET (1 << 16)
8138 +#define ATTR_TAG       (1 << 17)
8139  
8140  /*
8141   * This is the Inode Attributes structure, used for notify_change().  It
8142 @@ -481,6 +509,7 @@ struct iattr {
8143         umode_t         ia_mode;
8144         kuid_t          ia_uid;
8145         kgid_t          ia_gid;
8146 +       tag_t           ia_tag;
8147         loff_t          ia_size;
8148         struct timespec ia_atime;
8149         struct timespec ia_mtime;
8150 @@ -494,6 +523,9 @@ struct iattr {
8151         struct file     *ia_file;
8152  };
8153  
8154 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8155 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8156 +
8157  /*
8158   * Includes for diskquotas.
8159   */
8160 @@ -773,7 +805,9 @@ struct inode {
8161         unsigned short          i_opflags;
8162         kuid_t                  i_uid;
8163         kgid_t                  i_gid;
8164 -       unsigned int            i_flags;
8165 +       tag_t                   i_tag;
8166 +       unsigned short          i_flags;
8167 +       unsigned short          i_vflags;
8168  
8169  #ifdef CONFIG_FS_POSIX_ACL
8170         struct posix_acl        *i_acl;
8171 @@ -802,6 +836,7 @@ struct inode {
8172                 unsigned int __i_nlink;
8173         };
8174         dev_t                   i_rdev;
8175 +       dev_t                   i_mdev;
8176         loff_t                  i_size;
8177         struct timespec         i_atime;
8178         struct timespec         i_mtime;
8179 @@ -964,12 +999,12 @@ static inline void i_gid_write(struct in
8180  
8181  static inline unsigned iminor(const struct inode *inode)
8182  {
8183 -       return MINOR(inode->i_rdev);
8184 +       return MINOR(inode->i_mdev);
8185  }
8186  
8187  static inline unsigned imajor(const struct inode *inode)
8188  {
8189 -       return MAJOR(inode->i_rdev);
8190 +       return MAJOR(inode->i_mdev);
8191  }
8192  
8193  extern struct block_device *I_BDEV(struct inode *inode);
8194 @@ -1036,6 +1071,7 @@ struct file {
8195         loff_t                  f_pos;
8196         struct fown_struct      f_owner;
8197         const struct cred       *f_cred;
8198 +       xid_t                   f_xid;
8199         struct file_ra_state    f_ra;
8200  
8201         u64                     f_version;
8202 @@ -1183,6 +1219,7 @@ struct file_lock {
8203         struct file *fl_file;
8204         loff_t fl_start;
8205         loff_t fl_end;
8206 +       xid_t fl_xid;
8207  
8208         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8209         /* for lease breaks: */
8210 @@ -1690,6 +1727,7 @@ struct inode_operations {
8211         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8212         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8213         int (*removexattr) (struct dentry *, const char *);
8214 +       int (*sync_flags) (struct inode *, int, int);
8215         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8216                       u64 len);
8217         int (*update_time)(struct inode *, struct timespec *, int);
8218 @@ -1708,6 +1746,7 @@ extern ssize_t vfs_readv(struct file *, 
8219                 unsigned long, loff_t *);
8220  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8221                 unsigned long, loff_t *);
8222 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8223  
8224  struct super_operations {
8225         struct inode *(*alloc_inode)(struct super_block *sb);
8226 @@ -2542,6 +2581,7 @@ extern int dcache_dir_open(struct inode 
8227  extern int dcache_dir_close(struct inode *, struct file *);
8228  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8229  extern int dcache_readdir(struct file *, void *, filldir_t);
8230 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8231  extern int simple_setattr(struct dentry *, struct iattr *);
8232  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8233  extern int simple_statfs(struct dentry *, struct kstatfs *);
8234 diff -NurpP --minimal linux-3.5.4/include/linux/gfs2_ondisk.h linux-3.5.4-vs2.3.4.3/include/linux/gfs2_ondisk.h
8235 --- linux-3.5.4/include/linux/gfs2_ondisk.h     2012-05-21 18:07:29.000000000 +0200
8236 +++ linux-3.5.4-vs2.3.4.3/include/linux/gfs2_ondisk.h   2012-07-23 01:45:55.000000000 +0200
8237 @@ -214,6 +214,9 @@ enum {
8238         gfs2fl_NoAtime          = 7,
8239         gfs2fl_Sync             = 8,
8240         gfs2fl_System           = 9,
8241 +       gfs2fl_IXUnlink         = 16,
8242 +       gfs2fl_Barrier          = 17,
8243 +       gfs2fl_Cow              = 18,
8244         gfs2fl_TruncInProg      = 29,
8245         gfs2fl_InheritDirectio  = 30,
8246         gfs2fl_InheritJdata     = 31,
8247 @@ -230,6 +233,9 @@ enum {
8248  #define GFS2_DIF_NOATIME               0x00000080
8249  #define GFS2_DIF_SYNC                  0x00000100
8250  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8251 +#define GFS2_DIF_IXUNLINK              0x00010000
8252 +#define GFS2_DIF_BARRIER               0x00020000
8253 +#define GFS2_DIF_COW                   0x00040000
8254  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8255  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8256  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8257 diff -NurpP --minimal linux-3.5.4/include/linux/if_tun.h linux-3.5.4-vs2.3.4.3/include/linux/if_tun.h
8258 --- linux-3.5.4/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8259 +++ linux-3.5.4-vs2.3.4.3/include/linux/if_tun.h        2012-07-23 01:45:55.000000000 +0200
8260 @@ -53,6 +53,7 @@
8261  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8262  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8263  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8264 +#define TUNSETNID     _IOW('T', 217, int)
8265  
8266  /* TUNSETIFF ifr flags */
8267  #define IFF_TUN                0x0001
8268 diff -NurpP --minimal linux-3.5.4/include/linux/init_task.h linux-3.5.4-vs2.3.4.3/include/linux/init_task.h
8269 --- linux-3.5.4/include/linux/init_task.h       2012-07-22 23:39:43.000000000 +0200
8270 +++ linux-3.5.4-vs2.3.4.3/include/linux/init_task.h     2012-07-23 01:45:55.000000000 +0200
8271 @@ -200,6 +200,10 @@ extern struct cred init_cred;
8272         INIT_TRACE_RECURSION                                            \
8273         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8274         INIT_CPUSET_SEQ                                                 \
8275 +       .xid            = 0,                                            \
8276 +       .vx_info        = NULL,                                         \
8277 +       .nid            = 0,                                            \
8278 +       .nx_info        = NULL,                                         \
8279  }
8280  
8281  
8282 diff -NurpP --minimal linux-3.5.4/include/linux/ipc.h linux-3.5.4-vs2.3.4.3/include/linux/ipc.h
8283 --- linux-3.5.4/include/linux/ipc.h     2012-03-19 19:47:28.000000000 +0100
8284 +++ linux-3.5.4-vs2.3.4.3/include/linux/ipc.h   2012-07-23 01:45:55.000000000 +0200
8285 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8286         key_t           key;
8287         uid_t           uid;
8288         gid_t           gid;
8289 +       xid_t           xid;
8290         uid_t           cuid;
8291         gid_t           cgid;
8292         umode_t         mode; 
8293 diff -NurpP --minimal linux-3.5.4/include/linux/ipc_namespace.h linux-3.5.4-vs2.3.4.3/include/linux/ipc_namespace.h
8294 --- linux-3.5.4/include/linux/ipc_namespace.h   2012-07-22 23:39:43.000000000 +0200
8295 +++ linux-3.5.4-vs2.3.4.3/include/linux/ipc_namespace.h 2012-07-23 01:45:55.000000000 +0200
8296 @@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
8297  
8298  #if defined(CONFIG_IPC_NS)
8299  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8300 -                                      struct task_struct *tsk);
8301 +                                      struct ipc_namespace *old_ns,
8302 +                                      struct user_namespace *user_ns);
8303  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8304  {
8305         if (ns)
8306 @@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
8307  extern void put_ipc_ns(struct ipc_namespace *ns);
8308  #else
8309  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8310 -                                             struct task_struct *tsk)
8311 +                                             struct ipc_namespace *old_ns,
8312 +                                             struct user_namespace *user_ns)
8313  {
8314         if (flags & CLONE_NEWIPC)
8315                 return ERR_PTR(-EINVAL);
8316  
8317 -       return tsk->nsproxy->ipc_ns;
8318 +       return old_ns;
8319  }
8320  
8321  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8322 diff -NurpP --minimal linux-3.5.4/include/linux/loop.h linux-3.5.4-vs2.3.4.3/include/linux/loop.h
8323 --- linux-3.5.4/include/linux/loop.h    2012-01-09 16:14:58.000000000 +0100
8324 +++ linux-3.5.4-vs2.3.4.3/include/linux/loop.h  2012-07-23 01:45:55.000000000 +0200
8325 @@ -45,6 +45,7 @@ struct loop_device {
8326         struct loop_func_table *lo_encryption;
8327         __u32           lo_init[2];
8328         uid_t           lo_key_owner;   /* Who set the key */
8329 +       xid_t           lo_xid;
8330         int             (*ioctl)(struct loop_device *, int cmd, 
8331                                  unsigned long arg); 
8332  
8333 diff -NurpP --minimal linux-3.5.4/include/linux/magic.h linux-3.5.4-vs2.3.4.3/include/linux/magic.h
8334 --- linux-3.5.4/include/linux/magic.h   2012-05-21 18:07:31.000000000 +0200
8335 +++ linux-3.5.4-vs2.3.4.3/include/linux/magic.h 2012-07-23 01:45:55.000000000 +0200
8336 @@ -3,7 +3,7 @@
8337  
8338  #define ADFS_SUPER_MAGIC       0xadf5
8339  #define AFFS_SUPER_MAGIC       0xadff
8340 -#define AFS_SUPER_MAGIC                0x5346414F
8341 +#define AFS_SUPER_MAGIC                0x5346414F
8342  #define AUTOFS_SUPER_MAGIC     0x0187
8343  #define CODA_SUPER_MAGIC       0x73757245
8344  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8345 diff -NurpP --minimal linux-3.5.4/include/linux/major.h linux-3.5.4-vs2.3.4.3/include/linux/major.h
8346 --- linux-3.5.4/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8347 +++ linux-3.5.4-vs2.3.4.3/include/linux/major.h 2012-07-23 01:45:55.000000000 +0200
8348 @@ -15,6 +15,7 @@
8349  #define HD_MAJOR               IDE0_MAJOR
8350  #define PTY_SLAVE_MAJOR                3
8351  #define TTY_MAJOR              4
8352 +#define VROOT_MAJOR            4
8353  #define TTYAUX_MAJOR           5
8354  #define LP_MAJOR               6
8355  #define VCS_MAJOR              7
8356 diff -NurpP --minimal linux-3.5.4/include/linux/memcontrol.h linux-3.5.4-vs2.3.4.3/include/linux/memcontrol.h
8357 --- linux-3.5.4/include/linux/memcontrol.h      2012-07-22 23:39:43.000000000 +0200
8358 +++ linux-3.5.4-vs2.3.4.3/include/linux/memcontrol.h    2012-07-23 01:45:55.000000000 +0200
8359 @@ -85,6 +85,13 @@ extern struct mem_cgroup *try_get_mem_cg
8360  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8361  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8362  
8363 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8364 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8365 +
8366 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8367 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8368 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8369 +
8370  static inline
8371  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8372  {
8373 diff -NurpP --minimal linux-3.5.4/include/linux/mm_types.h linux-3.5.4-vs2.3.4.3/include/linux/mm_types.h
8374 --- linux-3.5.4/include/linux/mm_types.h        2012-07-22 23:39:44.000000000 +0200
8375 +++ linux-3.5.4-vs2.3.4.3/include/linux/mm_types.h      2012-07-23 01:45:55.000000000 +0200
8376 @@ -354,6 +354,7 @@ struct mm_struct {
8377  
8378         /* Architecture-specific MM context */
8379         mm_context_t context;
8380 +       struct vx_info *mm_vx_info;
8381  
8382         unsigned long flags; /* Must use atomic bitops to access the bits */
8383  
8384 diff -NurpP --minimal linux-3.5.4/include/linux/mmzone.h linux-3.5.4-vs2.3.4.3/include/linux/mmzone.h
8385 --- linux-3.5.4/include/linux/mmzone.h  2012-07-22 23:39:44.000000000 +0200
8386 +++ linux-3.5.4-vs2.3.4.3/include/linux/mmzone.h        2012-07-23 01:45:55.000000000 +0200
8387 @@ -715,6 +715,13 @@ typedef struct pglist_data {
8388         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8389  })
8390  
8391 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8392 +
8393 +#define node_end_pfn(nid) ({\
8394 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8395 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8396 +})
8397 +
8398  #include <linux/memory_hotplug.h>
8399  
8400  extern struct mutex zonelists_mutex;
8401 diff -NurpP --minimal linux-3.5.4/include/linux/mount.h linux-3.5.4-vs2.3.4.3/include/linux/mount.h
8402 --- linux-3.5.4/include/linux/mount.h   2012-03-19 19:47:28.000000000 +0100
8403 +++ linux-3.5.4-vs2.3.4.3/include/linux/mount.h 2012-07-23 01:45:55.000000000 +0200
8404 @@ -47,6 +47,9 @@ struct mnt_namespace;
8405  
8406  #define MNT_INTERNAL   0x4000
8407  
8408 +#define MNT_TAGID      0x10000
8409 +#define MNT_NOTAG      0x20000
8410 +
8411  struct vfsmount {
8412         struct dentry *mnt_root;        /* root of the mounted tree */
8413         struct super_block *mnt_sb;     /* pointer to superblock */
8414 diff -NurpP --minimal linux-3.5.4/include/linux/net.h linux-3.5.4-vs2.3.4.3/include/linux/net.h
8415 --- linux-3.5.4/include/linux/net.h     2012-09-16 20:46:31.000000000 +0200
8416 +++ linux-3.5.4-vs2.3.4.3/include/linux/net.h   2012-08-11 15:16:09.000000000 +0200
8417 @@ -73,6 +73,7 @@ struct net;
8418  #define SOCK_PASSCRED          3
8419  #define SOCK_PASSSEC           4
8420  #define SOCK_EXTERNALLY_ALLOCATED 5
8421 +#define SOCK_USER_SOCKET       6
8422  
8423  #ifndef ARCH_HAS_SOCKET_TYPES
8424  /**
8425 diff -NurpP --minimal linux-3.5.4/include/linux/netdevice.h linux-3.5.4-vs2.3.4.3/include/linux/netdevice.h
8426 --- linux-3.5.4/include/linux/netdevice.h       2012-07-22 23:39:44.000000000 +0200
8427 +++ linux-3.5.4-vs2.3.4.3/include/linux/netdevice.h     2012-07-23 01:45:55.000000000 +0200
8428 @@ -1644,6 +1644,7 @@ extern void               netdev_resync_ops(struct ne
8429  
8430  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8431  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8432 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8433  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8434  extern int             dev_restart(struct net_device *dev);
8435  #ifdef CONFIG_NETPOLL_TRAP
8436 diff -NurpP --minimal linux-3.5.4/include/linux/nfs_mount.h linux-3.5.4-vs2.3.4.3/include/linux/nfs_mount.h
8437 --- linux-3.5.4/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8438 +++ linux-3.5.4-vs2.3.4.3/include/linux/nfs_mount.h     2012-07-23 01:45:55.000000000 +0200
8439 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8440  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8441  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8442  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8443 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8444 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8445 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8446  
8447  /* The following are for internal use only */
8448  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8449 diff -NurpP --minimal linux-3.5.4/include/linux/nsproxy.h linux-3.5.4-vs2.3.4.3/include/linux/nsproxy.h
8450 --- linux-3.5.4/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8451 +++ linux-3.5.4-vs2.3.4.3/include/linux/nsproxy.h       2012-07-23 01:45:55.000000000 +0200
8452 @@ -3,6 +3,7 @@
8453  
8454  #include <linux/spinlock.h>
8455  #include <linux/sched.h>
8456 +#include <linux/vserver/debug.h>
8457  
8458  struct mnt_namespace;
8459  struct uts_namespace;
8460 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8461  }
8462  
8463  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8464 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8465  void exit_task_namespaces(struct task_struct *tsk);
8466  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8467  void free_nsproxy(struct nsproxy *ns);
8468 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8469         struct fs_struct *);
8470  int __init nsproxy_cache_init(void);
8471  
8472 -static inline void put_nsproxy(struct nsproxy *ns)
8473 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8474 +
8475 +static inline void __get_nsproxy(struct nsproxy *ns,
8476 +       const char *_file, int _line)
8477  {
8478 -       if (atomic_dec_and_test(&ns->count)) {
8479 -               free_nsproxy(ns);
8480 -       }
8481 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8482 +               ns, atomic_read(&ns->count), _file, _line);
8483 +       atomic_inc(&ns->count);
8484  }
8485  
8486 -static inline void get_nsproxy(struct nsproxy *ns)
8487 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8488 +
8489 +static inline void __put_nsproxy(struct nsproxy *ns,
8490 +       const char *_file, int _line)
8491  {
8492 -       atomic_inc(&ns->count);
8493 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8494 +               ns, atomic_read(&ns->count), _file, _line);
8495 +       if (atomic_dec_and_test(&ns->count)) {
8496 +               free_nsproxy(ns);
8497 +       }
8498  }
8499  
8500  #endif
8501 diff -NurpP --minimal linux-3.5.4/include/linux/pid.h linux-3.5.4-vs2.3.4.3/include/linux/pid.h
8502 --- linux-3.5.4/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8503 +++ linux-3.5.4-vs2.3.4.3/include/linux/pid.h   2012-07-23 01:45:55.000000000 +0200
8504 @@ -8,7 +8,8 @@ enum pid_type
8505         PIDTYPE_PID,
8506         PIDTYPE_PGID,
8507         PIDTYPE_SID,
8508 -       PIDTYPE_MAX
8509 +       PIDTYPE_MAX,
8510 +       PIDTYPE_REALPID
8511  };
8512  
8513  /*
8514 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8515  }
8516  
8517  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8518 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8519  pid_t pid_vnr(struct pid *pid);
8520  
8521  #define do_each_pid_task(pid, type, task)                              \
8522 diff -NurpP --minimal linux-3.5.4/include/linux/proc_fs.h linux-3.5.4-vs2.3.4.3/include/linux/proc_fs.h
8523 --- linux-3.5.4/include/linux/proc_fs.h 2012-07-22 23:39:44.000000000 +0200
8524 +++ linux-3.5.4-vs2.3.4.3/include/linux/proc_fs.h       2012-07-23 10:20:57.000000000 +0200
8525 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8526         nlink_t nlink;
8527         kuid_t uid;
8528         kgid_t gid;
8529 +       int vx_flags;
8530         loff_t size;
8531         const struct inode_operations *proc_iops;
8532         /*
8533 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8534  extern const struct proc_ns_operations utsns_operations;
8535  extern const struct proc_ns_operations ipcns_operations;
8536  
8537 +struct vx_info;
8538 +struct nx_info;
8539 +
8540  union proc_op {
8541         int (*proc_get_link)(struct dentry *, struct path *);
8542         int (*proc_read)(struct task_struct *task, char *page);
8543         int (*proc_show)(struct seq_file *m,
8544                 struct pid_namespace *ns, struct pid *pid,
8545                 struct task_struct *task);
8546 +       int (*proc_vs_read)(char *page);
8547 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8548 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8549  };
8550  
8551  struct ctl_table_header;
8552 @@ -265,6 +272,7 @@ struct ctl_table;
8553  
8554  struct proc_inode {
8555         struct pid *pid;
8556 +       int vx_flags;
8557         int fd;
8558         union proc_op op;
8559         struct proc_dir_entry *pde;
8560 diff -NurpP --minimal linux-3.5.4/include/linux/quotaops.h linux-3.5.4-vs2.3.4.3/include/linux/quotaops.h
8561 --- linux-3.5.4/include/linux/quotaops.h        2012-07-22 23:39:44.000000000 +0200
8562 +++ linux-3.5.4-vs2.3.4.3/include/linux/quotaops.h      2012-07-23 01:45:55.000000000 +0200
8563 @@ -8,6 +8,7 @@
8564  #define _LINUX_QUOTAOPS_
8565  
8566  #include <linux/fs.h>
8567 +#include <linux/vs_dlimit.h>
8568  
8569  #define DQUOT_SPACE_WARN       0x1
8570  #define DQUOT_SPACE_RESERVE    0x2
8571 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8572  
8573  static inline int dquot_alloc_inode(const struct inode *inode)
8574  {
8575 -       return 0;
8576 +       return dl_alloc_inode(inode);
8577  }
8578  
8579  static inline void dquot_free_inode(const struct inode *inode)
8580  {
8581 +       dl_free_inode(inode);
8582  }
8583  
8584  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8585 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8586  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8587                 int flags)
8588  {
8589 +       int ret = 0;
8590 +
8591 +       if ((ret = dl_alloc_space(inode, number)))
8592 +               return ret;
8593         if (!(flags & DQUOT_SPACE_RESERVE))
8594                 inode_add_bytes(inode, number);
8595         return 0;
8596 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8597  {
8598         if (!(flags & DQUOT_SPACE_RESERVE))
8599                 inode_sub_bytes(inode, number);
8600 +       dl_free_space(inode, number);
8601  }
8602  
8603  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8604 diff -NurpP --minimal linux-3.5.4/include/linux/reboot.h linux-3.5.4-vs2.3.4.3/include/linux/reboot.h
8605 --- linux-3.5.4/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8606 +++ linux-3.5.4-vs2.3.4.3/include/linux/reboot.h        2012-07-23 01:45:55.000000000 +0200
8607 @@ -33,6 +33,7 @@
8608  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8609  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8610  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8611 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8612  
8613  
8614  #ifdef __KERNEL__
8615 diff -NurpP --minimal linux-3.5.4/include/linux/sched.h linux-3.5.4-vs2.3.4.3/include/linux/sched.h
8616 --- linux-3.5.4/include/linux/sched.h   2012-07-22 23:39:44.000000000 +0200
8617 +++ linux-3.5.4-vs2.3.4.3/include/linux/sched.h 2012-07-23 01:45:55.000000000 +0200
8618 @@ -1414,6 +1414,14 @@ struct task_struct {
8619  #endif
8620         struct seccomp seccomp;
8621  
8622 +/* vserver context data */
8623 +       struct vx_info *vx_info;
8624 +       struct nx_info *nx_info;
8625 +
8626 +       xid_t xid;
8627 +       nid_t nid;
8628 +       tag_t tag;
8629 +
8630  /* Thread group tracking */
8631         u32 parent_exec_id;
8632         u32 self_exec_id;
8633 @@ -1662,6 +1670,11 @@ struct pid_namespace;
8634  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8635                         struct pid_namespace *ns);
8636  
8637 +#include <linux/vserver/base.h>
8638 +#include <linux/vserver/context.h>
8639 +#include <linux/vserver/debug.h>
8640 +#include <linux/vserver/pid.h>
8641 +
8642  static inline pid_t task_pid_nr(struct task_struct *tsk)
8643  {
8644         return tsk->pid;
8645 @@ -1675,7 +1688,8 @@ static inline pid_t task_pid_nr_ns(struc
8646  
8647  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8648  {
8649 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8650 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8651 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8652  }
8653  
8654  
8655 @@ -1688,7 +1702,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8656  
8657  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8658  {
8659 -       return pid_vnr(task_tgid(tsk));
8660 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8661  }
8662  
8663  
8664 diff -NurpP --minimal linux-3.5.4/include/linux/shmem_fs.h linux-3.5.4-vs2.3.4.3/include/linux/shmem_fs.h
8665 --- linux-3.5.4/include/linux/shmem_fs.h        2012-07-22 23:39:44.000000000 +0200
8666 +++ linux-3.5.4-vs2.3.4.3/include/linux/shmem_fs.h      2012-07-23 01:45:55.000000000 +0200
8667 @@ -8,6 +8,9 @@
8668  
8669  /* inode in-kernel data */
8670  
8671 +#define TMPFS_SUPER_MAGIC      0x01021994
8672 +
8673 +
8674  struct shmem_inode_info {
8675         spinlock_t              lock;
8676         unsigned long           flags;
8677 diff -NurpP --minimal linux-3.5.4/include/linux/stat.h linux-3.5.4-vs2.3.4.3/include/linux/stat.h
8678 --- linux-3.5.4/include/linux/stat.h    2012-07-22 23:39:44.000000000 +0200
8679 +++ linux-3.5.4-vs2.3.4.3/include/linux/stat.h  2012-07-23 10:23:18.000000000 +0200
8680 @@ -67,6 +67,7 @@ struct kstat {
8681         unsigned int    nlink;
8682         kuid_t          uid;
8683         kgid_t          gid;
8684 +       tag_t           tag;
8685         dev_t           rdev;
8686         loff_t          size;
8687         struct timespec  atime;
8688 diff -NurpP --minimal linux-3.5.4/include/linux/sunrpc/auth.h linux-3.5.4-vs2.3.4.3/include/linux/sunrpc/auth.h
8689 --- linux-3.5.4/include/linux/sunrpc/auth.h     2012-05-21 18:07:32.000000000 +0200
8690 +++ linux-3.5.4-vs2.3.4.3/include/linux/sunrpc/auth.h   2012-07-23 01:45:55.000000000 +0200
8691 @@ -25,6 +25,7 @@
8692  struct auth_cred {
8693         uid_t   uid;
8694         gid_t   gid;
8695 +       tag_t   tag;
8696         struct group_info *group_info;
8697         const char *principal;
8698         unsigned char machine_cred : 1;
8699 diff -NurpP --minimal linux-3.5.4/include/linux/sunrpc/clnt.h linux-3.5.4-vs2.3.4.3/include/linux/sunrpc/clnt.h
8700 --- linux-3.5.4/include/linux/sunrpc/clnt.h     2012-05-21 18:07:32.000000000 +0200
8701 +++ linux-3.5.4-vs2.3.4.3/include/linux/sunrpc/clnt.h   2012-07-23 01:45:55.000000000 +0200
8702 @@ -49,7 +49,8 @@ struct rpc_clnt {
8703         unsigned int            cl_softrtry : 1,/* soft timeouts */
8704                                 cl_discrtry : 1,/* disconnect before retry */
8705                                 cl_autobind : 1,/* use getport() */
8706 -                               cl_chatty   : 1;/* be verbose */
8707 +                               cl_chatty   : 1,/* be verbose */
8708 +                               cl_tag      : 1;/* context tagging */
8709  
8710         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8711         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8712 diff -NurpP --minimal linux-3.5.4/include/linux/sysctl.h linux-3.5.4-vs2.3.4.3/include/linux/sysctl.h
8713 --- linux-3.5.4/include/linux/sysctl.h  2012-05-21 18:07:32.000000000 +0200
8714 +++ linux-3.5.4-vs2.3.4.3/include/linux/sysctl.h        2012-07-23 01:45:55.000000000 +0200
8715 @@ -60,6 +60,7 @@ enum
8716         CTL_ABI=9,              /* Binary emulation */
8717         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8718         CTL_ARLAN=254,          /* arlan wireless driver */
8719 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8720         CTL_S390DBF=5677,       /* s390 debug */
8721         CTL_SUNRPC=7249,        /* sunrpc debug */
8722         CTL_PM=9899,            /* frv power management */
8723 @@ -94,6 +95,7 @@ enum
8724  
8725         KERN_PANIC=15,          /* int: panic timeout */
8726         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8727 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8728  
8729         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8730         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8731 diff -NurpP --minimal linux-3.5.4/include/linux/sysfs.h linux-3.5.4-vs2.3.4.3/include/linux/sysfs.h
8732 --- linux-3.5.4/include/linux/sysfs.h   2012-07-22 23:39:44.000000000 +0200
8733 +++ linux-3.5.4-vs2.3.4.3/include/linux/sysfs.h 2012-07-23 01:45:55.000000000 +0200
8734 @@ -19,6 +19,8 @@
8735  #include <linux/kobject_ns.h>
8736  #include <linux/atomic.h>
8737  
8738 +#define SYSFS_SUPER_MAGIC      0x62656572
8739 +
8740  struct kobject;
8741  struct module;
8742  enum kobj_ns_type;
8743 diff -NurpP --minimal linux-3.5.4/include/linux/time.h linux-3.5.4-vs2.3.4.3/include/linux/time.h
8744 --- linux-3.5.4/include/linux/time.h    2012-09-16 20:46:31.000000000 +0200
8745 +++ linux-3.5.4-vs2.3.4.3/include/linux/time.h  2012-08-11 15:15:02.000000000 +0200
8746 @@ -255,6 +255,8 @@ static __always_inline void timespec_add
8747         a->tv_nsec = ns;
8748  }
8749  
8750 +#include <linux/vs_time.h>
8751 +
8752  #endif /* __KERNEL__ */
8753  
8754  /*
8755 diff -NurpP --minimal linux-3.5.4/include/linux/types.h linux-3.5.4-vs2.3.4.3/include/linux/types.h
8756 --- linux-3.5.4/include/linux/types.h   2012-07-22 23:39:45.000000000 +0200
8757 +++ linux-3.5.4-vs2.3.4.3/include/linux/types.h 2012-07-23 01:45:55.000000000 +0200
8758 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8759  typedef __kernel_gid32_t       gid_t;
8760  typedef __kernel_uid16_t        uid16_t;
8761  typedef __kernel_gid16_t        gid16_t;
8762 +typedef unsigned int           xid_t;
8763 +typedef unsigned int           nid_t;
8764 +typedef unsigned int           tag_t;
8765  
8766  typedef unsigned long          uintptr_t;
8767  
8768 diff -NurpP --minimal linux-3.5.4/include/linux/utsname.h linux-3.5.4-vs2.3.4.3/include/linux/utsname.h
8769 --- linux-3.5.4/include/linux/utsname.h 2012-01-09 16:14:59.000000000 +0100
8770 +++ linux-3.5.4-vs2.3.4.3/include/linux/utsname.h       2012-07-23 01:45:55.000000000 +0200
8771 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8772  }
8773  
8774  extern struct uts_namespace *copy_utsname(unsigned long flags,
8775 -                                         struct task_struct *tsk);
8776 +                                         struct uts_namespace *old_ns,
8777 +                                         struct user_namespace *user_ns);
8778  extern void free_uts_ns(struct kref *kref);
8779  
8780  static inline void put_uts_ns(struct uts_namespace *ns)
8781 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8782  }
8783  
8784  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8785 -                                                struct task_struct *tsk)
8786 +                                                struct uts_namespace *old_ns,
8787 +                                                struct user_namespace *user_ns)
8788  {
8789         if (flags & CLONE_NEWUTS)
8790                 return ERR_PTR(-EINVAL);
8791  
8792 -       return tsk->nsproxy->uts_ns;
8793 +       return old_ns;
8794  }
8795  #endif
8796  
8797 diff -NurpP --minimal linux-3.5.4/include/linux/vroot.h linux-3.5.4-vs2.3.4.3/include/linux/vroot.h
8798 --- linux-3.5.4/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
8799 +++ linux-3.5.4-vs2.3.4.3/include/linux/vroot.h 2012-07-23 01:45:55.000000000 +0200
8800 @@ -0,0 +1,51 @@
8801 +
8802 +/*
8803 + * include/linux/vroot.h
8804 + *
8805 + * written by Herbert Pötzl, 9/11/2002
8806 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8807 + *
8808 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8809 + * Redistribution of this file is permitted under the
8810 + * GNU General Public License.
8811 + */
8812 +
8813 +#ifndef _LINUX_VROOT_H
8814 +#define _LINUX_VROOT_H
8815 +
8816 +
8817 +#ifdef __KERNEL__
8818 +
8819 +/* Possible states of device */
8820 +enum {
8821 +       Vr_unbound,
8822 +       Vr_bound,
8823 +};
8824 +
8825 +struct vroot_device {
8826 +       int             vr_number;
8827 +       int             vr_refcnt;
8828 +
8829 +       struct semaphore        vr_ctl_mutex;
8830 +       struct block_device    *vr_device;
8831 +       int                     vr_state;
8832 +};
8833 +
8834 +
8835 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8836 +
8837 +extern int register_vroot_grb(vroot_grb_func *);
8838 +extern int unregister_vroot_grb(vroot_grb_func *);
8839 +
8840 +#endif /* __KERNEL__ */
8841 +
8842 +#define MAX_VROOT_DEFAULT      8
8843 +
8844 +/*
8845 + * IOCTL commands --- we will commandeer 0x56 ('V')
8846 + */
8847 +
8848 +#define VROOT_SET_DEV          0x5600
8849 +#define VROOT_CLR_DEV          0x5601
8850 +
8851 +#endif /* _LINUX_VROOT_H */
8852 diff -NurpP --minimal linux-3.5.4/include/linux/vs_base.h linux-3.5.4-vs2.3.4.3/include/linux/vs_base.h
8853 --- linux-3.5.4/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8854 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_base.h       2012-07-23 01:45:55.000000000 +0200
8855 @@ -0,0 +1,10 @@
8856 +#ifndef _VS_BASE_H
8857 +#define _VS_BASE_H
8858 +
8859 +#include "vserver/base.h"
8860 +#include "vserver/check.h"
8861 +#include "vserver/debug.h"
8862 +
8863 +#else
8864 +#warning duplicate inclusion
8865 +#endif
8866 diff -NurpP --minimal linux-3.5.4/include/linux/vs_context.h linux-3.5.4-vs2.3.4.3/include/linux/vs_context.h
8867 --- linux-3.5.4/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
8868 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_context.h    2012-07-23 01:45:55.000000000 +0200
8869 @@ -0,0 +1,242 @@
8870 +#ifndef _VS_CONTEXT_H
8871 +#define _VS_CONTEXT_H
8872 +
8873 +#include "vserver/base.h"
8874 +#include "vserver/check.h"
8875 +#include "vserver/context.h"
8876 +#include "vserver/history.h"
8877 +#include "vserver/debug.h"
8878 +
8879 +#include <linux/sched.h>
8880 +
8881 +
8882 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8883 +
8884 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8885 +       const char *_file, int _line, void *_here)
8886 +{
8887 +       if (!vxi)
8888 +               return NULL;
8889 +
8890 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8891 +               vxi, vxi ? vxi->vx_id : 0,
8892 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8893 +               _file, _line);
8894 +       __vxh_get_vx_info(vxi, _here);
8895 +
8896 +       atomic_inc(&vxi->vx_usecnt);
8897 +       return vxi;
8898 +}
8899 +
8900 +
8901 +extern void free_vx_info(struct vx_info *);
8902 +
8903 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8904 +
8905 +static inline void __put_vx_info(struct vx_info *vxi,
8906 +       const char *_file, int _line, void *_here)
8907 +{
8908 +       if (!vxi)
8909 +               return;
8910 +
8911 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8912 +               vxi, vxi ? vxi->vx_id : 0,
8913 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8914 +               _file, _line);
8915 +       __vxh_put_vx_info(vxi, _here);
8916 +
8917 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8918 +               free_vx_info(vxi);
8919 +}
8920 +
8921 +
8922 +#define init_vx_info(p, i) \
8923 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8924 +
8925 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8926 +       const char *_file, int _line, void *_here)
8927 +{
8928 +       if (vxi) {
8929 +               vxlprintk(VXD_CBIT(xid, 3),
8930 +                       "init_vx_info(%p[#%d.%d])",
8931 +                       vxi, vxi ? vxi->vx_id : 0,
8932 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8933 +                       _file, _line);
8934 +               __vxh_init_vx_info(vxi, vxp, _here);
8935 +
8936 +               atomic_inc(&vxi->vx_usecnt);
8937 +       }
8938 +       *vxp = vxi;
8939 +}
8940 +
8941 +
8942 +#define set_vx_info(p, i) \
8943 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8944 +
8945 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8946 +       const char *_file, int _line, void *_here)
8947 +{
8948 +       struct vx_info *vxo;
8949 +
8950 +       if (!vxi)
8951 +               return;
8952 +
8953 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8954 +               vxi, vxi ? vxi->vx_id : 0,
8955 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8956 +               _file, _line);
8957 +       __vxh_set_vx_info(vxi, vxp, _here);
8958 +
8959 +       atomic_inc(&vxi->vx_usecnt);
8960 +       vxo = xchg(vxp, vxi);
8961 +       BUG_ON(vxo);
8962 +}
8963 +
8964 +
8965 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8966 +
8967 +static inline void __clr_vx_info(struct vx_info **vxp,
8968 +       const char *_file, int _line, void *_here)
8969 +{
8970 +       struct vx_info *vxo;
8971 +
8972 +       vxo = xchg(vxp, NULL);
8973 +       if (!vxo)
8974 +               return;
8975 +
8976 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8977 +               vxo, vxo ? vxo->vx_id : 0,
8978 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8979 +               _file, _line);
8980 +       __vxh_clr_vx_info(vxo, vxp, _here);
8981 +
8982 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8983 +               free_vx_info(vxo);
8984 +}
8985 +
8986 +
8987 +#define claim_vx_info(v, p) \
8988 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8989 +
8990 +static inline void __claim_vx_info(struct vx_info *vxi,
8991 +       struct task_struct *task,
8992 +       const char *_file, int _line, void *_here)
8993 +{
8994 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8995 +               vxi, vxi ? vxi->vx_id : 0,
8996 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8997 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8998 +               task, _file, _line);
8999 +       __vxh_claim_vx_info(vxi, task, _here);
9000 +
9001 +       atomic_inc(&vxi->vx_tasks);
9002 +}
9003 +
9004 +
9005 +extern void unhash_vx_info(struct vx_info *);
9006 +
9007 +#define release_vx_info(v, p) \
9008 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9009 +
9010 +static inline void __release_vx_info(struct vx_info *vxi,
9011 +       struct task_struct *task,
9012 +       const char *_file, int _line, void *_here)
9013 +{
9014 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9015 +               vxi, vxi ? vxi->vx_id : 0,
9016 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9017 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9018 +               task, _file, _line);
9019 +       __vxh_release_vx_info(vxi, task, _here);
9020 +
9021 +       might_sleep();
9022 +
9023 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9024 +               unhash_vx_info(vxi);
9025 +}
9026 +
9027 +
9028 +#define task_get_vx_info(p) \
9029 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9030 +
9031 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9032 +       const char *_file, int _line, void *_here)
9033 +{
9034 +       struct vx_info *vxi;
9035 +
9036 +       task_lock(p);
9037 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9038 +               p, _file, _line);
9039 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9040 +       task_unlock(p);
9041 +       return vxi;
9042 +}
9043 +
9044 +
9045 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9046 +{
9047 +       if (waitqueue_active(&vxi->vx_wait))
9048 +               wake_up_interruptible(&vxi->vx_wait);
9049 +}
9050 +
9051 +
9052 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9053 +
9054 +static inline void __enter_vx_info(struct vx_info *vxi,
9055 +       struct vx_info_save *vxis, const char *_file, int _line)
9056 +{
9057 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9058 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9059 +               current->xid, current->vx_info, _file, _line);
9060 +       vxis->vxi = xchg(&current->vx_info, vxi);
9061 +       vxis->xid = current->xid;
9062 +       current->xid = vxi ? vxi->vx_id : 0;
9063 +}
9064 +
9065 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9066 +
9067 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9068 +       const char *_file, int _line)
9069 +{
9070 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9071 +               vxis, vxis->xid, vxis->vxi, current,
9072 +               current->xid, current->vx_info, _file, _line);
9073 +       (void)xchg(&current->vx_info, vxis->vxi);
9074 +       current->xid = vxis->xid;
9075 +}
9076 +
9077 +
9078 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9079 +{
9080 +       vxis->vxi = xchg(&current->vx_info, NULL);
9081 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9082 +}
9083 +
9084 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9085 +{
9086 +       (void)xchg(&current->xid, vxis->xid);
9087 +       (void)xchg(&current->vx_info, vxis->vxi);
9088 +}
9089 +
9090 +#define task_is_init(p) \
9091 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9092 +
9093 +static inline int __task_is_init(struct task_struct *p,
9094 +       const char *_file, int _line, void *_here)
9095 +{
9096 +       int is_init = is_global_init(p);
9097 +
9098 +       task_lock(p);
9099 +       if (p->vx_info)
9100 +               is_init = p->vx_info->vx_initpid == p->pid;
9101 +       task_unlock(p);
9102 +       return is_init;
9103 +}
9104 +
9105 +extern void exit_vx_info(struct task_struct *, int);
9106 +extern void exit_vx_info_early(struct task_struct *, int);
9107 +
9108 +
9109 +#else
9110 +#warning duplicate inclusion
9111 +#endif
9112 diff -NurpP --minimal linux-3.5.4/include/linux/vs_cowbl.h linux-3.5.4-vs2.3.4.3/include/linux/vs_cowbl.h
9113 --- linux-3.5.4/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9114 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_cowbl.h      2012-07-23 01:45:55.000000000 +0200
9115 @@ -0,0 +1,48 @@
9116 +#ifndef _VS_COWBL_H
9117 +#define _VS_COWBL_H
9118 +
9119 +#include <linux/fs.h>
9120 +#include <linux/dcache.h>
9121 +#include <linux/namei.h>
9122 +#include <linux/slab.h>
9123 +
9124 +extern struct dentry *cow_break_link(const char *pathname);
9125 +
9126 +static inline int cow_check_and_break(struct path *path)
9127 +{
9128 +       struct inode *inode = path->dentry->d_inode;
9129 +       int error = 0;
9130 +
9131 +       /* do we need this check? */
9132 +       if (IS_RDONLY(inode))
9133 +               return -EROFS;
9134 +
9135 +       if (IS_COW(inode)) {
9136 +               if (IS_COW_LINK(inode)) {
9137 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9138 +                       char *pp, *buf;
9139 +
9140 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9141 +                       if (!buf) {
9142 +                               return -ENOMEM;
9143 +                       }
9144 +                       pp = d_path(path, buf, PATH_MAX);
9145 +                       new_dentry = cow_break_link(pp);
9146 +                       kfree(buf);
9147 +                       if (!IS_ERR(new_dentry)) {
9148 +                               path->dentry = new_dentry;
9149 +                               dput(old_dentry);
9150 +                       } else
9151 +                               error = PTR_ERR(new_dentry);
9152 +               } else {
9153 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9154 +                       inode->i_ctime = CURRENT_TIME;
9155 +                       mark_inode_dirty(inode);
9156 +               }
9157 +       }
9158 +       return error;
9159 +}
9160 +
9161 +#else
9162 +#warning duplicate inclusion
9163 +#endif
9164 diff -NurpP --minimal linux-3.5.4/include/linux/vs_cvirt.h linux-3.5.4-vs2.3.4.3/include/linux/vs_cvirt.h
9165 --- linux-3.5.4/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9166 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_cvirt.h      2012-07-23 01:45:55.000000000 +0200
9167 @@ -0,0 +1,50 @@
9168 +#ifndef _VS_CVIRT_H
9169 +#define _VS_CVIRT_H
9170 +
9171 +#include "vserver/cvirt.h"
9172 +#include "vserver/context.h"
9173 +#include "vserver/base.h"
9174 +#include "vserver/check.h"
9175 +#include "vserver/debug.h"
9176 +
9177 +
9178 +static inline void vx_activate_task(struct task_struct *p)
9179 +{
9180 +       struct vx_info *vxi;
9181 +
9182 +       if ((vxi = p->vx_info)) {
9183 +               vx_update_load(vxi);
9184 +               atomic_inc(&vxi->cvirt.nr_running);
9185 +       }
9186 +}
9187 +
9188 +static inline void vx_deactivate_task(struct task_struct *p)
9189 +{
9190 +       struct vx_info *vxi;
9191 +
9192 +       if ((vxi = p->vx_info)) {
9193 +               vx_update_load(vxi);
9194 +               atomic_dec(&vxi->cvirt.nr_running);
9195 +       }
9196 +}
9197 +
9198 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9199 +{
9200 +       struct vx_info *vxi;
9201 +
9202 +       if ((vxi = p->vx_info))
9203 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9204 +}
9205 +
9206 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9207 +{
9208 +       struct vx_info *vxi;
9209 +
9210 +       if ((vxi = p->vx_info))
9211 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9212 +}
9213 +
9214 +
9215 +#else
9216 +#warning duplicate inclusion
9217 +#endif
9218 diff -NurpP --minimal linux-3.5.4/include/linux/vs_device.h linux-3.5.4-vs2.3.4.3/include/linux/vs_device.h
9219 --- linux-3.5.4/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9220 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_device.h     2012-07-23 01:45:55.000000000 +0200
9221 @@ -0,0 +1,45 @@
9222 +#ifndef _VS_DEVICE_H
9223 +#define _VS_DEVICE_H
9224 +
9225 +#include "vserver/base.h"
9226 +#include "vserver/device.h"
9227 +#include "vserver/debug.h"
9228 +
9229 +
9230 +#ifdef CONFIG_VSERVER_DEVICE
9231 +
9232 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9233 +
9234 +#define vs_device_perm(v, d, m, p) \
9235 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9236 +
9237 +#else
9238 +
9239 +static inline
9240 +int vs_map_device(struct vx_info *vxi,
9241 +       dev_t device, dev_t *target, umode_t mode)
9242 +{
9243 +       if (target)
9244 +               *target = device;
9245 +       return ~0;
9246 +}
9247 +
9248 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9249 +
9250 +#endif
9251 +
9252 +
9253 +#define vs_map_chrdev(d, t, p) \
9254 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9255 +#define vs_map_blkdev(d, t, p) \
9256 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9257 +
9258 +#define vs_chrdev_perm(d, p) \
9259 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9260 +#define vs_blkdev_perm(d, p) \
9261 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9262 +
9263 +
9264 +#else
9265 +#warning duplicate inclusion
9266 +#endif
9267 diff -NurpP --minimal linux-3.5.4/include/linux/vs_dlimit.h linux-3.5.4-vs2.3.4.3/include/linux/vs_dlimit.h
9268 --- linux-3.5.4/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9269 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_dlimit.h     2012-07-23 01:45:55.000000000 +0200
9270 @@ -0,0 +1,215 @@
9271 +#ifndef _VS_DLIMIT_H
9272 +#define _VS_DLIMIT_H
9273 +
9274 +#include <linux/fs.h>
9275 +
9276 +#include "vserver/dlimit.h"
9277 +#include "vserver/base.h"
9278 +#include "vserver/debug.h"
9279 +
9280 +
9281 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9282 +
9283 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9284 +       const char *_file, int _line)
9285 +{
9286 +       if (!dli)
9287 +               return NULL;
9288 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9289 +               dli, dli ? dli->dl_tag : 0,
9290 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9291 +               _file, _line);
9292 +       atomic_inc(&dli->dl_usecnt);
9293 +       return dli;
9294 +}
9295 +
9296 +
9297 +#define free_dl_info(i) \
9298 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9299 +
9300 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9301 +
9302 +static inline void __put_dl_info(struct dl_info *dli,
9303 +       const char *_file, int _line)
9304 +{
9305 +       if (!dli)
9306 +               return;
9307 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9308 +               dli, dli ? dli->dl_tag : 0,
9309 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9310 +               _file, _line);
9311 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9312 +               free_dl_info(dli);
9313 +}
9314 +
9315 +
9316 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9317 +
9318 +static inline int __dl_alloc_space(struct super_block *sb,
9319 +       tag_t tag, dlsize_t nr, const char *file, int line)
9320 +{
9321 +       struct dl_info *dli = NULL;
9322 +       int ret = 0;
9323 +
9324 +       if (nr == 0)
9325 +               goto out;
9326 +       dli = locate_dl_info(sb, tag);
9327 +       if (!dli)
9328 +               goto out;
9329 +
9330 +       spin_lock(&dli->dl_lock);
9331 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9332 +       if (!ret)
9333 +               dli->dl_space_used += nr;
9334 +       spin_unlock(&dli->dl_lock);
9335 +       put_dl_info(dli);
9336 +out:
9337 +       vxlprintk(VXD_CBIT(dlim, 1),
9338 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9339 +               sb, tag, __dlimit_char(dli), (long long)nr,
9340 +               ret, file, line);
9341 +       return ret ? -ENOSPC : 0;
9342 +}
9343 +
9344 +static inline void __dl_free_space(struct super_block *sb,
9345 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9346 +{
9347 +       struct dl_info *dli = NULL;
9348 +
9349 +       if (nr == 0)
9350 +               goto out;
9351 +       dli = locate_dl_info(sb, tag);
9352 +       if (!dli)
9353 +               goto out;
9354 +
9355 +       spin_lock(&dli->dl_lock);
9356 +       if (dli->dl_space_used > nr)
9357 +               dli->dl_space_used -= nr;
9358 +       else
9359 +               dli->dl_space_used = 0;
9360 +       spin_unlock(&dli->dl_lock);
9361 +       put_dl_info(dli);
9362 +out:
9363 +       vxlprintk(VXD_CBIT(dlim, 1),
9364 +               "FREE  (%p,#%d)%c %lld bytes",
9365 +               sb, tag, __dlimit_char(dli), (long long)nr,
9366 +               _file, _line);
9367 +}
9368 +
9369 +static inline int __dl_alloc_inode(struct super_block *sb,
9370 +       tag_t tag, const char *_file, int _line)
9371 +{
9372 +       struct dl_info *dli;
9373 +       int ret = 0;
9374 +
9375 +       dli = locate_dl_info(sb, tag);
9376 +       if (!dli)
9377 +               goto out;
9378 +
9379 +       spin_lock(&dli->dl_lock);
9380 +       dli->dl_inodes_used++;
9381 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9382 +       spin_unlock(&dli->dl_lock);
9383 +       put_dl_info(dli);
9384 +out:
9385 +       vxlprintk(VXD_CBIT(dlim, 0),
9386 +               "ALLOC (%p,#%d)%c inode (%d)",
9387 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9388 +       return ret ? -ENOSPC : 0;
9389 +}
9390 +
9391 +static inline void __dl_free_inode(struct super_block *sb,
9392 +       tag_t tag, const char *_file, int _line)
9393 +{
9394 +       struct dl_info *dli;
9395 +
9396 +       dli = locate_dl_info(sb, tag);
9397 +       if (!dli)
9398 +               goto out;
9399 +
9400 +       spin_lock(&dli->dl_lock);
9401 +       if (dli->dl_inodes_used > 1)
9402 +               dli->dl_inodes_used--;
9403 +       else
9404 +               dli->dl_inodes_used = 0;
9405 +       spin_unlock(&dli->dl_lock);
9406 +       put_dl_info(dli);
9407 +out:
9408 +       vxlprintk(VXD_CBIT(dlim, 0),
9409 +               "FREE  (%p,#%d)%c inode",
9410 +               sb, tag, __dlimit_char(dli), _file, _line);
9411 +}
9412 +
9413 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9414 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9415 +       const char *_file, int _line)
9416 +{
9417 +       struct dl_info *dli;
9418 +       uint64_t broot, bfree;
9419 +
9420 +       dli = locate_dl_info(sb, tag);
9421 +       if (!dli)
9422 +               return;
9423 +
9424 +       spin_lock(&dli->dl_lock);
9425 +       broot = (dli->dl_space_total -
9426 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9427 +               >> sb->s_blocksize_bits;
9428 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9429 +                       >> sb->s_blocksize_bits;
9430 +       spin_unlock(&dli->dl_lock);
9431 +
9432 +       vxlprintk(VXD_CBIT(dlim, 2),
9433 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9434 +               (long long)bfree, (long long)broot,
9435 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9436 +               _file, _line);
9437 +       if (free_blocks) {
9438 +               if (*free_blocks > bfree)
9439 +                       *free_blocks = bfree;
9440 +       }
9441 +       if (root_blocks) {
9442 +               if (*root_blocks > broot)
9443 +                       *root_blocks = broot;
9444 +       }
9445 +       put_dl_info(dli);
9446 +}
9447 +
9448 +#define dl_prealloc_space(in, bytes) \
9449 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9450 +               __FILE__, __LINE__ )
9451 +
9452 +#define dl_alloc_space(in, bytes) \
9453 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9454 +               __FILE__, __LINE__ )
9455 +
9456 +#define dl_reserve_space(in, bytes) \
9457 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9458 +               __FILE__, __LINE__ )
9459 +
9460 +#define dl_claim_space(in, bytes) (0)
9461 +
9462 +#define dl_release_space(in, bytes) \
9463 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9464 +               __FILE__, __LINE__ )
9465 +
9466 +#define dl_free_space(in, bytes) \
9467 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9468 +               __FILE__, __LINE__ )
9469 +
9470 +
9471 +
9472 +#define dl_alloc_inode(in) \
9473 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9474 +
9475 +#define dl_free_inode(in) \
9476 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9477 +
9478 +
9479 +#define dl_adjust_block(sb, tag, fb, rb) \
9480 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9481 +
9482 +
9483 +#else
9484 +#warning duplicate inclusion
9485 +#endif
9486 diff -NurpP --minimal linux-3.5.4/include/linux/vs_inet.h linux-3.5.4-vs2.3.4.3/include/linux/vs_inet.h
9487 --- linux-3.5.4/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9488 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_inet.h       2012-07-23 01:45:55.000000000 +0200
9489 @@ -0,0 +1,353 @@
9490 +#ifndef _VS_INET_H
9491 +#define _VS_INET_H
9492 +
9493 +#include "vserver/base.h"
9494 +#include "vserver/network.h"
9495 +#include "vserver/debug.h"
9496 +
9497 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9498 +
9499 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9500 +                       NIPQUAD((a)->mask), (a)->type
9501 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9502 +
9503 +#define NIPQUAD(addr) \
9504 +       ((unsigned char *)&addr)[0], \
9505 +       ((unsigned char *)&addr)[1], \
9506 +       ((unsigned char *)&addr)[2], \
9507 +       ((unsigned char *)&addr)[3]
9508 +
9509 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9510 +
9511 +
9512 +static inline
9513 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9514 +{
9515 +       __be32 ip = nxa->ip[0].s_addr;
9516 +       __be32 mask = nxa->mask.s_addr;
9517 +       __be32 bcast = ip | ~mask;
9518 +       int ret = 0;
9519 +
9520 +       switch (nxa->type & tmask) {
9521 +       case NXA_TYPE_MASK:
9522 +               ret = (ip == (addr & mask));
9523 +               break;
9524 +       case NXA_TYPE_ADDR:
9525 +               ret = 3;
9526 +               if (addr == ip)
9527 +                       break;
9528 +               /* fall through to broadcast */
9529 +       case NXA_MOD_BCAST:
9530 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9531 +               break;
9532 +       case NXA_TYPE_RANGE:
9533 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9534 +                       (nxa->ip[1].s_addr > addr));
9535 +               break;
9536 +       case NXA_TYPE_ANY:
9537 +               ret = 2;
9538 +               break;
9539 +       }
9540 +
9541 +       vxdprintk(VXD_CBIT(net, 0),
9542 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9543 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9544 +       return ret;
9545 +}
9546 +
9547 +static inline
9548 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9549 +{
9550 +       struct nx_addr_v4 *nxa;
9551 +       int ret = 1;
9552 +
9553 +       if (!nxi)
9554 +               goto out;
9555 +
9556 +       ret = 2;
9557 +       /* allow 127.0.0.1 when remapping lback */
9558 +       if ((tmask & NXA_LOOPBACK) &&
9559 +               (addr == IPI_LOOPBACK) &&
9560 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9561 +               goto out;
9562 +       ret = 3;
9563 +       /* check for lback address */
9564 +       if ((tmask & NXA_MOD_LBACK) &&
9565 +               (nxi->v4_lback.s_addr == addr))
9566 +               goto out;
9567 +       ret = 4;
9568 +       /* check for broadcast address */
9569 +       if ((tmask & NXA_MOD_BCAST) &&
9570 +               (nxi->v4_bcast.s_addr == addr))
9571 +               goto out;
9572 +       ret = 5;
9573 +       /* check for v4 addresses */
9574 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9575 +               if (v4_addr_match(nxa, addr, tmask))
9576 +                       goto out;
9577 +       ret = 0;
9578 +out:
9579 +       vxdprintk(VXD_CBIT(net, 0),
9580 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9581 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9582 +       return ret;
9583 +}
9584 +
9585 +static inline
9586 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9587 +{
9588 +       /* FIXME: needs full range checks */
9589 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9590 +}
9591 +
9592 +static inline
9593 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9594 +{
9595 +       struct nx_addr_v4 *ptr;
9596 +
9597 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9598 +               if (v4_nx_addr_match(ptr, nxa, mask))
9599 +                       return 1;
9600 +       return 0;
9601 +}
9602 +
9603 +#include <net/inet_sock.h>
9604 +
9605 +/*
9606 + *     Check if a given address matches for a socket
9607 + *
9608 + *     nxi:            the socket's nx_info if any
9609 + *     addr:           to be verified address
9610 + */
9611 +static inline
9612 +int v4_sock_addr_match (
9613 +       struct nx_info *nxi,
9614 +       struct inet_sock *inet,
9615 +       __be32 addr)
9616 +{
9617 +       __be32 saddr = inet->inet_rcv_saddr;
9618 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9619 +
9620 +       if (addr && (saddr == addr || bcast == addr))
9621 +               return 1;
9622 +       if (!saddr)
9623 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9624 +       return 0;
9625 +}
9626 +
9627 +
9628 +/* inet related checks and helpers */
9629 +
9630 +
9631 +struct in_ifaddr;
9632 +struct net_device;
9633 +struct sock;
9634 +
9635 +#ifdef CONFIG_INET
9636 +
9637 +#include <linux/netdevice.h>
9638 +#include <linux/inetdevice.h>
9639 +#include <net/inet_sock.h>
9640 +#include <net/inet_timewait_sock.h>
9641 +
9642 +
9643 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9644 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9645 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9646 +
9647 +
9648 +/*
9649 + *     check if address is covered by socket
9650 + *
9651 + *     sk:     the socket to check against
9652 + *     addr:   the address in question (must be != 0)
9653 + */
9654 +
9655 +static inline
9656 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9657 +{
9658 +       struct nx_info *nxi = sk->sk_nx_info;
9659 +       __be32 saddr = sk_rcv_saddr(sk);
9660 +
9661 +       vxdprintk(VXD_CBIT(net, 5),
9662 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9663 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9664 +               (sk->sk_socket?sk->sk_socket->flags:0));
9665 +
9666 +       if (saddr) {            /* direct address match */
9667 +               return v4_addr_match(nxa, saddr, -1);
9668 +       } else if (nxi) {       /* match against nx_info */
9669 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9670 +       } else {                /* unrestricted any socket */
9671 +               return 1;
9672 +       }
9673 +}
9674 +
9675 +
9676 +
9677 +static inline
9678 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9679 +{
9680 +       vxdprintk(VXD_CBIT(net, 1),
9681 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9682 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9683 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9684 +
9685 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9686 +               return 1;
9687 +       if (dev_in_nx_info(dev, nxi))
9688 +               return 1;
9689 +       return 0;
9690 +}
9691 +
9692 +
9693 +static inline
9694 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9695 +{
9696 +       if (!nxi)
9697 +               return 1;
9698 +       if (!ifa)
9699 +               return 0;
9700 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9701 +}
9702 +
9703 +static inline
9704 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9705 +{
9706 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9707 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9708 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9709 +
9710 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9711 +               return 1;
9712 +       if (v4_ifa_in_nx_info(ifa, nxi))
9713 +               return 1;
9714 +       return 0;
9715 +}
9716 +
9717 +
9718 +struct nx_v4_sock_addr {
9719 +       __be32 saddr;   /* Address used for validation */
9720 +       __be32 baddr;   /* Address used for socket bind */
9721 +};
9722 +
9723 +static inline
9724 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9725 +       struct nx_v4_sock_addr *nsa)
9726 +{
9727 +       struct sock *sk = &inet->sk;
9728 +       struct nx_info *nxi = sk->sk_nx_info;
9729 +       __be32 saddr = addr->sin_addr.s_addr;
9730 +       __be32 baddr = saddr;
9731 +
9732 +       vxdprintk(VXD_CBIT(net, 3),
9733 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9734 +               sk, sk->sk_nx_info, sk->sk_socket,
9735 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9736 +               NIPQUAD(saddr));
9737 +
9738 +       if (nxi) {
9739 +               if (saddr == INADDR_ANY) {
9740 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9741 +                               baddr = nxi->v4.ip[0].s_addr;
9742 +               } else if (saddr == IPI_LOOPBACK) {
9743 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9744 +                               baddr = nxi->v4_lback.s_addr;
9745 +               } else if (!ipv4_is_multicast(saddr) ||
9746 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9747 +                       /* normal address bind */
9748 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9749 +                               return -EADDRNOTAVAIL;
9750 +               }
9751 +       }
9752 +
9753 +       vxdprintk(VXD_CBIT(net, 3),
9754 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9755 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9756 +
9757 +       nsa->saddr = saddr;
9758 +       nsa->baddr = baddr;
9759 +       return 0;
9760 +}
9761 +
9762 +static inline
9763 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9764 +{
9765 +       inet->inet_saddr = nsa->baddr;
9766 +       inet->inet_rcv_saddr = nsa->baddr;
9767 +}
9768 +
9769 +
9770 +/*
9771 + *      helper to simplify inet_lookup_listener
9772 + *
9773 + *      nxi:   the socket's nx_info if any
9774 + *      addr:  to be verified address
9775 + *      saddr: socket address
9776 + */
9777 +static inline int v4_inet_addr_match (
9778 +       struct nx_info *nxi,
9779 +       __be32 addr,
9780 +       __be32 saddr)
9781 +{
9782 +       if (addr && (saddr == addr))
9783 +               return 1;
9784 +       if (!saddr)
9785 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9786 +       return 0;
9787 +}
9788 +
9789 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9790 +{
9791 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9792 +               (addr == nxi->v4_lback.s_addr))
9793 +               return IPI_LOOPBACK;
9794 +       return addr;
9795 +}
9796 +
9797 +static inline
9798 +int nx_info_has_v4(struct nx_info *nxi)
9799 +{
9800 +       if (!nxi)
9801 +               return 1;
9802 +       if (NX_IPV4(nxi))
9803 +               return 1;
9804 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9805 +               return 1;
9806 +       return 0;
9807 +}
9808 +
9809 +#else /* CONFIG_INET */
9810 +
9811 +static inline
9812 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9813 +{
9814 +       return 1;
9815 +}
9816 +
9817 +static inline
9818 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9819 +{
9820 +       return 1;
9821 +}
9822 +
9823 +static inline
9824 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9825 +{
9826 +       return 1;
9827 +}
9828 +
9829 +static inline
9830 +int nx_info_has_v4(struct nx_info *nxi)
9831 +{
9832 +       return 0;
9833 +}
9834 +
9835 +#endif /* CONFIG_INET */
9836 +
9837 +#define current_nx_info_has_v4() \
9838 +       nx_info_has_v4(current_nx_info())
9839 +
9840 +#else
9841 +// #warning duplicate inclusion
9842 +#endif
9843 diff -NurpP --minimal linux-3.5.4/include/linux/vs_inet6.h linux-3.5.4-vs2.3.4.3/include/linux/vs_inet6.h
9844 --- linux-3.5.4/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
9845 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_inet6.h      2012-07-23 01:45:55.000000000 +0200
9846 @@ -0,0 +1,246 @@
9847 +#ifndef _VS_INET6_H
9848 +#define _VS_INET6_H
9849 +
9850 +#include "vserver/base.h"
9851 +#include "vserver/network.h"
9852 +#include "vserver/debug.h"
9853 +
9854 +#include <net/ipv6.h>
9855 +
9856 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9857 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9858 +
9859 +
9860 +#ifdef CONFIG_IPV6
9861 +
9862 +static inline
9863 +int v6_addr_match(struct nx_addr_v6 *nxa,
9864 +       const struct in6_addr *addr, uint16_t mask)
9865 +{
9866 +       int ret = 0;
9867 +
9868 +       switch (nxa->type & mask) {
9869 +       case NXA_TYPE_MASK:
9870 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9871 +               break;
9872 +       case NXA_TYPE_ADDR:
9873 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9874 +               break;
9875 +       case NXA_TYPE_ANY:
9876 +               ret = 1;
9877 +               break;
9878 +       }
9879 +       vxdprintk(VXD_CBIT(net, 0),
9880 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9881 +               nxa, NXAV6(nxa), addr, mask, ret);
9882 +       return ret;
9883 +}
9884 +
9885 +static inline
9886 +int v6_addr_in_nx_info(struct nx_info *nxi,
9887 +       const struct in6_addr *addr, uint16_t mask)
9888 +{
9889 +       struct nx_addr_v6 *nxa;
9890 +       int ret = 1;
9891 +
9892 +       if (!nxi)
9893 +               goto out;
9894 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9895 +               if (v6_addr_match(nxa, addr, mask))
9896 +                       goto out;
9897 +       ret = 0;
9898 +out:
9899 +       vxdprintk(VXD_CBIT(net, 0),
9900 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9901 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9902 +       return ret;
9903 +}
9904 +
9905 +static inline
9906 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9907 +{
9908 +       /* FIXME: needs full range checks */
9909 +       return v6_addr_match(nxa, &addr->ip, mask);
9910 +}
9911 +
9912 +static inline
9913 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9914 +{
9915 +       struct nx_addr_v6 *ptr;
9916 +
9917 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9918 +               if (v6_nx_addr_match(ptr, nxa, mask))
9919 +                       return 1;
9920 +       return 0;
9921 +}
9922 +
9923 +
9924 +/*
9925 + *     Check if a given address matches for a socket
9926 + *
9927 + *     nxi:            the socket's nx_info if any
9928 + *     addr:           to be verified address
9929 + */
9930 +static inline
9931 +int v6_sock_addr_match (
9932 +       struct nx_info *nxi,
9933 +       struct inet_sock *inet,
9934 +       struct in6_addr *addr)
9935 +{
9936 +       struct sock *sk = &inet->sk;
9937 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9938 +
9939 +       if (!ipv6_addr_any(addr) &&
9940 +               ipv6_addr_equal(saddr, addr))
9941 +               return 1;
9942 +       if (ipv6_addr_any(saddr))
9943 +               return v6_addr_in_nx_info(nxi, addr, -1);
9944 +       return 0;
9945 +}
9946 +
9947 +/*
9948 + *     check if address is covered by socket
9949 + *
9950 + *     sk:     the socket to check against
9951 + *     addr:   the address in question (must be != 0)
9952 + */
9953 +
9954 +static inline
9955 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9956 +{
9957 +       struct nx_info *nxi = sk->sk_nx_info;
9958 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9959 +
9960 +       vxdprintk(VXD_CBIT(net, 5),
9961 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9962 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9963 +               (sk->sk_socket?sk->sk_socket->flags:0));
9964 +
9965 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9966 +               return v6_addr_match(nxa, saddr, -1);
9967 +       } else if (nxi) {               /* match against nx_info */
9968 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9969 +       } else {                        /* unrestricted any socket */
9970 +               return 1;
9971 +       }
9972 +}
9973 +
9974 +
9975 +/* inet related checks and helpers */
9976 +
9977 +
9978 +struct in_ifaddr;
9979 +struct net_device;
9980 +struct sock;
9981 +
9982 +
9983 +#include <linux/netdevice.h>
9984 +#include <linux/inetdevice.h>
9985 +#include <net/inet_timewait_sock.h>
9986 +
9987 +
9988 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9989 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9990 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9991 +
9992 +
9993 +
9994 +static inline
9995 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9996 +{
9997 +       if (!nxi)
9998 +               return 1;
9999 +       if (!ifa)
10000 +               return 0;
10001 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10002 +}
10003 +
10004 +static inline
10005 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10006 +{
10007 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10008 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10009 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10010 +
10011 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10012 +               return 1;
10013 +       if (v6_ifa_in_nx_info(ifa, nxi))
10014 +               return 1;
10015 +       return 0;
10016 +}
10017 +
10018 +
10019 +struct nx_v6_sock_addr {
10020 +       struct in6_addr saddr;  /* Address used for validation */
10021 +       struct in6_addr baddr;  /* Address used for socket bind */
10022 +};
10023 +
10024 +static inline
10025 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10026 +       struct nx_v6_sock_addr *nsa)
10027 +{
10028 +       // struct sock *sk = &inet->sk;
10029 +       // struct nx_info *nxi = sk->sk_nx_info;
10030 +       struct in6_addr saddr = addr->sin6_addr;
10031 +       struct in6_addr baddr = saddr;
10032 +
10033 +       nsa->saddr = saddr;
10034 +       nsa->baddr = baddr;
10035 +       return 0;
10036 +}
10037 +
10038 +static inline
10039 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10040 +{
10041 +       // struct sock *sk = &inet->sk;
10042 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10043 +
10044 +       // *saddr = nsa->baddr;
10045 +       // inet->inet_saddr = nsa->baddr;
10046 +}
10047 +
10048 +static inline
10049 +int nx_info_has_v6(struct nx_info *nxi)
10050 +{
10051 +       if (!nxi)
10052 +               return 1;
10053 +       if (NX_IPV6(nxi))
10054 +               return 1;
10055 +       return 0;
10056 +}
10057 +
10058 +#else /* CONFIG_IPV6 */
10059 +
10060 +static inline
10061 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10062 +{
10063 +       return 1;
10064 +}
10065 +
10066 +
10067 +static inline
10068 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10069 +{
10070 +       return 1;
10071 +}
10072 +
10073 +static inline
10074 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10075 +{
10076 +       return 1;
10077 +}
10078 +
10079 +static inline
10080 +int nx_info_has_v6(struct nx_info *nxi)
10081 +{
10082 +       return 0;
10083 +}
10084 +
10085 +#endif /* CONFIG_IPV6 */
10086 +
10087 +#define current_nx_info_has_v6() \
10088 +       nx_info_has_v6(current_nx_info())
10089 +
10090 +#else
10091 +#warning duplicate inclusion
10092 +#endif
10093 diff -NurpP --minimal linux-3.5.4/include/linux/vs_limit.h linux-3.5.4-vs2.3.4.3/include/linux/vs_limit.h
10094 --- linux-3.5.4/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10095 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_limit.h      2012-07-23 01:45:55.000000000 +0200
10096 @@ -0,0 +1,140 @@
10097 +#ifndef _VS_LIMIT_H
10098 +#define _VS_LIMIT_H
10099 +
10100 +#include "vserver/limit.h"
10101 +#include "vserver/base.h"
10102 +#include "vserver/context.h"
10103 +#include "vserver/debug.h"
10104 +#include "vserver/context.h"
10105 +#include "vserver/limit_int.h"
10106 +
10107 +
10108 +#define vx_acc_cres(v, d, p, r) \
10109 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10110 +
10111 +#define vx_acc_cres_cond(x, d, p, r) \
10112 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10113 +       r, d, p, __FILE__, __LINE__)
10114 +
10115 +
10116 +#define vx_add_cres(v, a, p, r) \
10117 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10118 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10119 +
10120 +#define vx_add_cres_cond(x, a, p, r) \
10121 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10122 +       r, a, p, __FILE__, __LINE__)
10123 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10124 +
10125 +
10126 +/* process and file limits */
10127 +
10128 +#define vx_nproc_inc(p) \
10129 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10130 +
10131 +#define vx_nproc_dec(p) \
10132 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10133 +
10134 +#define vx_files_inc(f) \
10135 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10136 +
10137 +#define vx_files_dec(f) \
10138 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10139 +
10140 +#define vx_locks_inc(l) \
10141 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10142 +
10143 +#define vx_locks_dec(l) \
10144 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10145 +
10146 +#define vx_openfd_inc(f) \
10147 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10148 +
10149 +#define vx_openfd_dec(f) \
10150 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10151 +
10152 +
10153 +#define vx_cres_avail(v, n, r) \
10154 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10155 +
10156 +
10157 +#define vx_nproc_avail(n) \
10158 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10159 +
10160 +#define vx_files_avail(n) \
10161 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10162 +
10163 +#define vx_locks_avail(n) \
10164 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10165 +
10166 +#define vx_openfd_avail(n) \
10167 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10168 +
10169 +
10170 +/* dentry limits */
10171 +
10172 +#define vx_dentry_inc(d) do {                                          \
10173 +       if ((d)->d_count == 1)                                          \
10174 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10175 +       } while (0)
10176 +
10177 +#define vx_dentry_dec(d) do {                                          \
10178 +       if ((d)->d_count == 0)                                          \
10179 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10180 +       } while (0)
10181 +
10182 +#define vx_dentry_avail(n) \
10183 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10184 +
10185 +
10186 +/* socket limits */
10187 +
10188 +#define vx_sock_inc(s) \
10189 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10190 +
10191 +#define vx_sock_dec(s) \
10192 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10193 +
10194 +#define vx_sock_avail(n) \
10195 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10196 +
10197 +
10198 +/* ipc resource limits */
10199 +
10200 +#define vx_ipcmsg_add(v, u, a) \
10201 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10202 +
10203 +#define vx_ipcmsg_sub(v, u, a) \
10204 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10205 +
10206 +#define vx_ipcmsg_avail(v, a) \
10207 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10208 +
10209 +
10210 +#define vx_ipcshm_add(v, k, a) \
10211 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10212 +
10213 +#define vx_ipcshm_sub(v, k, a) \
10214 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10215 +
10216 +#define vx_ipcshm_avail(v, a) \
10217 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10218 +
10219 +
10220 +#define vx_semary_inc(a) \
10221 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10222 +
10223 +#define vx_semary_dec(a) \
10224 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10225 +
10226 +
10227 +#define vx_nsems_add(a,n) \
10228 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10229 +
10230 +#define vx_nsems_sub(a,n) \
10231 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10232 +
10233 +
10234 +#else
10235 +#warning duplicate inclusion
10236 +#endif
10237 diff -NurpP --minimal linux-3.5.4/include/linux/vs_network.h linux-3.5.4-vs2.3.4.3/include/linux/vs_network.h
10238 --- linux-3.5.4/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10239 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_network.h    2012-07-23 01:45:55.000000000 +0200
10240 @@ -0,0 +1,169 @@
10241 +#ifndef _NX_VS_NETWORK_H
10242 +#define _NX_VS_NETWORK_H
10243 +
10244 +#include "vserver/context.h"
10245 +#include "vserver/network.h"
10246 +#include "vserver/base.h"
10247 +#include "vserver/check.h"
10248 +#include "vserver/debug.h"
10249 +
10250 +#include <linux/sched.h>
10251 +
10252 +
10253 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10254 +
10255 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10256 +       const char *_file, int _line)
10257 +{
10258 +       if (!nxi)
10259 +               return NULL;
10260 +
10261 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10262 +               nxi, nxi ? nxi->nx_id : 0,
10263 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10264 +               _file, _line);
10265 +
10266 +       atomic_inc(&nxi->nx_usecnt);
10267 +       return nxi;
10268 +}
10269 +
10270 +
10271 +extern void free_nx_info(struct nx_info *);
10272 +
10273 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10274 +
10275 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10276 +{
10277 +       if (!nxi)
10278 +               return;
10279 +
10280 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10281 +               nxi, nxi ? nxi->nx_id : 0,
10282 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10283 +               _file, _line);
10284 +
10285 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10286 +               free_nx_info(nxi);
10287 +}
10288 +
10289 +
10290 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10291 +
10292 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10293 +               const char *_file, int _line)
10294 +{
10295 +       if (nxi) {
10296 +               vxlprintk(VXD_CBIT(nid, 3),
10297 +                       "init_nx_info(%p[#%d.%d])",
10298 +                       nxi, nxi ? nxi->nx_id : 0,
10299 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10300 +                       _file, _line);
10301 +
10302 +               atomic_inc(&nxi->nx_usecnt);
10303 +       }
10304 +       *nxp = nxi;
10305 +}
10306 +
10307 +
10308 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10309 +
10310 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10311 +       const char *_file, int _line)
10312 +{
10313 +       struct nx_info *nxo;
10314 +
10315 +       if (!nxi)
10316 +               return;
10317 +
10318 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10319 +               nxi, nxi ? nxi->nx_id : 0,
10320 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10321 +               _file, _line);
10322 +
10323 +       atomic_inc(&nxi->nx_usecnt);
10324 +       nxo = xchg(nxp, nxi);
10325 +       BUG_ON(nxo);
10326 +}
10327 +
10328 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10329 +
10330 +static inline void __clr_nx_info(struct nx_info **nxp,
10331 +       const char *_file, int _line)
10332 +{
10333 +       struct nx_info *nxo;
10334 +
10335 +       nxo = xchg(nxp, NULL);
10336 +       if (!nxo)
10337 +               return;
10338 +
10339 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10340 +               nxo, nxo ? nxo->nx_id : 0,
10341 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10342 +               _file, _line);
10343 +
10344 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10345 +               free_nx_info(nxo);
10346 +}
10347 +
10348 +
10349 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10350 +
10351 +static inline void __claim_nx_info(struct nx_info *nxi,
10352 +       struct task_struct *task, const char *_file, int _line)
10353 +{
10354 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10355 +               nxi, nxi ? nxi->nx_id : 0,
10356 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10357 +               nxi?atomic_read(&nxi->nx_tasks):0,
10358 +               task, _file, _line);
10359 +
10360 +       atomic_inc(&nxi->nx_tasks);
10361 +}
10362 +
10363 +
10364 +extern void unhash_nx_info(struct nx_info *);
10365 +
10366 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10367 +
10368 +static inline void __release_nx_info(struct nx_info *nxi,
10369 +       struct task_struct *task, const char *_file, int _line)
10370 +{
10371 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10372 +               nxi, nxi ? nxi->nx_id : 0,
10373 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10374 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10375 +               task, _file, _line);
10376 +
10377 +       might_sleep();
10378 +
10379 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10380 +               unhash_nx_info(nxi);
10381 +}
10382 +
10383 +
10384 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10385 +
10386 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10387 +       const char *_file, int _line)
10388 +{
10389 +       struct nx_info *nxi;
10390 +
10391 +       task_lock(p);
10392 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10393 +               p, _file, _line);
10394 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10395 +       task_unlock(p);
10396 +       return nxi;
10397 +}
10398 +
10399 +
10400 +static inline void exit_nx_info(struct task_struct *p)
10401 +{
10402 +       if (p->nx_info)
10403 +               release_nx_info(p->nx_info, p);
10404 +}
10405 +
10406 +
10407 +#else
10408 +#warning duplicate inclusion
10409 +#endif
10410 diff -NurpP --minimal linux-3.5.4/include/linux/vs_pid.h linux-3.5.4-vs2.3.4.3/include/linux/vs_pid.h
10411 --- linux-3.5.4/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10412 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_pid.h        2012-07-23 01:45:55.000000000 +0200
10413 @@ -0,0 +1,50 @@
10414 +#ifndef _VS_PID_H
10415 +#define _VS_PID_H
10416 +
10417 +#include "vserver/base.h"
10418 +#include "vserver/check.h"
10419 +#include "vserver/context.h"
10420 +#include "vserver/debug.h"
10421 +#include "vserver/pid.h"
10422 +#include <linux/pid_namespace.h>
10423 +
10424 +
10425 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10426 +
10427 +static inline
10428 +int vx_proc_task_visible(struct task_struct *task)
10429 +{
10430 +       if ((task->pid == 1) &&
10431 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10432 +               /* show a blend through init */
10433 +               goto visible;
10434 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10435 +               goto visible;
10436 +       return 0;
10437 +visible:
10438 +       return 1;
10439 +}
10440 +
10441 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10442 +
10443 +
10444 +static inline
10445 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10446 +{
10447 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10448 +
10449 +       if (task && !vx_proc_task_visible(task)) {
10450 +               vxdprintk(VXD_CBIT(misc, 6),
10451 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10452 +                       task, task->xid, task->pid,
10453 +                       current, current->xid, current->pid);
10454 +               put_task_struct(task);
10455 +               task = NULL;
10456 +       }
10457 +       return task;
10458 +}
10459 +
10460 +
10461 +#else
10462 +#warning duplicate inclusion
10463 +#endif
10464 diff -NurpP --minimal linux-3.5.4/include/linux/vs_sched.h linux-3.5.4-vs2.3.4.3/include/linux/vs_sched.h
10465 --- linux-3.5.4/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10466 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_sched.h      2012-07-23 01:45:55.000000000 +0200
10467 @@ -0,0 +1,40 @@
10468 +#ifndef _VS_SCHED_H
10469 +#define _VS_SCHED_H
10470 +
10471 +#include "vserver/base.h"
10472 +#include "vserver/context.h"
10473 +#include "vserver/sched.h"
10474 +
10475 +
10476 +#define MAX_PRIO_BIAS           20
10477 +#define MIN_PRIO_BIAS          -20
10478 +
10479 +static inline
10480 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10481 +{
10482 +       struct vx_info *vxi = p->vx_info;
10483 +
10484 +       if (vxi)
10485 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10486 +       return prio;
10487 +}
10488 +
10489 +static inline void vx_account_user(struct vx_info *vxi,
10490 +       cputime_t cputime, int nice)
10491 +{
10492 +       if (!vxi)
10493 +               return;
10494 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10495 +}
10496 +
10497 +static inline void vx_account_system(struct vx_info *vxi,
10498 +       cputime_t cputime, int idle)
10499 +{
10500 +       if (!vxi)
10501 +               return;
10502 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10503 +}
10504 +
10505 +#else
10506 +#warning duplicate inclusion
10507 +#endif
10508 diff -NurpP --minimal linux-3.5.4/include/linux/vs_socket.h linux-3.5.4-vs2.3.4.3/include/linux/vs_socket.h
10509 --- linux-3.5.4/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10510 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_socket.h     2012-07-23 01:45:55.000000000 +0200
10511 @@ -0,0 +1,67 @@
10512 +#ifndef _VS_SOCKET_H
10513 +#define _VS_SOCKET_H
10514 +
10515 +#include "vserver/debug.h"
10516 +#include "vserver/base.h"
10517 +#include "vserver/cacct.h"
10518 +#include "vserver/context.h"
10519 +#include "vserver/tag.h"
10520 +
10521 +
10522 +/* socket accounting */
10523 +
10524 +#include <linux/socket.h>
10525 +
10526 +static inline int vx_sock_type(int family)
10527 +{
10528 +       switch (family) {
10529 +       case PF_UNSPEC:
10530 +               return VXA_SOCK_UNSPEC;
10531 +       case PF_UNIX:
10532 +               return VXA_SOCK_UNIX;
10533 +       case PF_INET:
10534 +               return VXA_SOCK_INET;
10535 +       case PF_INET6:
10536 +               return VXA_SOCK_INET6;
10537 +       case PF_PACKET:
10538 +               return VXA_SOCK_PACKET;
10539 +       default:
10540 +               return VXA_SOCK_OTHER;
10541 +       }
10542 +}
10543 +
10544 +#define vx_acc_sock(v, f, p, s) \
10545 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10546 +
10547 +static inline void __vx_acc_sock(struct vx_info *vxi,
10548 +       int family, int pos, int size, char *file, int line)
10549 +{
10550 +       if (vxi) {
10551 +               int type = vx_sock_type(family);
10552 +
10553 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10554 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10555 +       }
10556 +}
10557 +
10558 +#define vx_sock_recv(sk, s) \
10559 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10560 +#define vx_sock_send(sk, s) \
10561 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10562 +#define vx_sock_fail(sk, s) \
10563 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10564 +
10565 +
10566 +#define sock_vx_init(s) do {           \
10567 +       (s)->sk_xid = 0;                \
10568 +       (s)->sk_vx_info = NULL;         \
10569 +       } while (0)
10570 +
10571 +#define sock_nx_init(s) do {           \
10572 +       (s)->sk_nid = 0;                \
10573 +       (s)->sk_nx_info = NULL;         \
10574 +       } while (0)
10575 +
10576 +#else
10577 +#warning duplicate inclusion
10578 +#endif
10579 diff -NurpP --minimal linux-3.5.4/include/linux/vs_tag.h linux-3.5.4-vs2.3.4.3/include/linux/vs_tag.h
10580 --- linux-3.5.4/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10581 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_tag.h        2012-07-23 01:45:55.000000000 +0200
10582 @@ -0,0 +1,47 @@
10583 +#ifndef _VS_TAG_H
10584 +#define _VS_TAG_H
10585 +
10586 +#include <linux/vserver/tag.h>
10587 +
10588 +/* check conditions */
10589 +
10590 +#define DX_ADMIN       0x0001
10591 +#define DX_WATCH       0x0002
10592 +#define DX_HOSTID      0x0008
10593 +
10594 +#define DX_IDENT       0x0010
10595 +
10596 +#define DX_ARG_MASK    0x0010
10597 +
10598 +
10599 +#define dx_task_tag(t) ((t)->tag)
10600 +
10601 +#define dx_current_tag() dx_task_tag(current)
10602 +
10603 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10604 +
10605 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10606 +
10607 +
10608 +/*
10609 + * check current context for ADMIN/WATCH and
10610 + * optionally against supplied argument
10611 + */
10612 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10613 +{
10614 +       if (mode & DX_ARG_MASK) {
10615 +               if ((mode & DX_IDENT) && (id == cid))
10616 +                       return 1;
10617 +       }
10618 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10619 +               ((mode & DX_WATCH) && (cid == 1)) ||
10620 +               ((mode & DX_HOSTID) && (id == 0)));
10621 +}
10622 +
10623 +struct inode;
10624 +int dx_permission(const struct inode *inode, int mask);
10625 +
10626 +
10627 +#else
10628 +#warning duplicate inclusion
10629 +#endif
10630 diff -NurpP --minimal linux-3.5.4/include/linux/vs_time.h linux-3.5.4-vs2.3.4.3/include/linux/vs_time.h
10631 --- linux-3.5.4/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10632 +++ linux-3.5.4-vs2.3.4.3/include/linux/vs_time.h       2012-07-23 01:45:55.000000000 +0200
10633 @@ -0,0 +1,19 @@
10634 +#ifndef _VS_TIME_H
10635 +#define _VS_TIME_H
10636 +
10637 +
10638 +/* time faking stuff */
10639 +
10640 +#ifdef CONFIG_VSERVER_VTIME
10641 +
10642 +extern void vx_adjust_timespec(struct timespec *ts);
10643 +extern int vx_settimeofday(const struct timespec *ts);
10644 +
10645 +#else
10646 +#define        vx_adjust_timespec(t)   do { } while (0)
10647 +#define        vx_settimeofday(t)      do_settimeofday(t)
10648 +#endif
10649 +
10650 +#else
10651 +#warning duplicate inclusion
10652 +#endif
10653 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/Kbuild linux-3.5.4-vs2.3.4.3/include/linux/vserver/Kbuild
10654 --- linux-3.5.4/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10655 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/Kbuild  2012-07-23 01:45:55.000000000 +0200
10656 @@ -0,0 +1,8 @@
10657 +
10658 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10659 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10660 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10661 +       debug_cmd.h device_cmd.h
10662 +
10663 +header-y += switch.h network.h monitor.h inode.h device.h
10664 +
10665 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/base.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/base.h
10666 --- linux-3.5.4/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
10667 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/base.h  2012-07-23 01:45:55.000000000 +0200
10668 @@ -0,0 +1,178 @@
10669 +#ifndef _VX_BASE_H
10670 +#define _VX_BASE_H
10671 +
10672 +
10673 +/* context state changes */
10674 +
10675 +enum {
10676 +       VSC_STARTUP = 1,
10677 +       VSC_SHUTDOWN,
10678 +
10679 +       VSC_NETUP,
10680 +       VSC_NETDOWN,
10681 +};
10682 +
10683 +
10684 +
10685 +#define vx_task_xid(t) ((t)->xid)
10686 +
10687 +#define vx_current_xid() vx_task_xid(current)
10688 +
10689 +#define current_vx_info() (current->vx_info)
10690 +
10691 +
10692 +#define nx_task_nid(t) ((t)->nid)
10693 +
10694 +#define nx_current_nid() nx_task_nid(current)
10695 +
10696 +#define current_nx_info() (current->nx_info)
10697 +
10698 +
10699 +/* generic flag merging */
10700 +
10701 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10702 +
10703 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10704 +
10705 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10706 +
10707 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10708 +
10709 +
10710 +/* context flags */
10711 +
10712 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10713 +
10714 +#define vx_current_flags()     __vx_flags(current_vx_info())
10715 +
10716 +#define vx_info_flags(v, m, f) \
10717 +       vs_check_flags(__vx_flags(v), m, f)
10718 +
10719 +#define task_vx_flags(t, m, f) \
10720 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10721 +
10722 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10723 +
10724 +
10725 +/* context caps */
10726 +
10727 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10728 +
10729 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10730 +
10731 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10732 +
10733 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10734 +
10735 +
10736 +
10737 +/* network flags */
10738 +
10739 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10740 +
10741 +#define nx_current_flags()     __nx_flags(current_nx_info())
10742 +
10743 +#define nx_info_flags(n, m, f) \
10744 +       vs_check_flags(__nx_flags(n), m, f)
10745 +
10746 +#define task_nx_flags(t, m, f) \
10747 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10748 +
10749 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10750 +
10751 +
10752 +/* network caps */
10753 +
10754 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10755 +
10756 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10757 +
10758 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10759 +
10760 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10761 +
10762 +
10763 +/* context mask capabilities */
10764 +
10765 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10766 +
10767 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10768 +
10769 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10770 +
10771 +
10772 +/* context bcap mask */
10773 +
10774 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10775 +
10776 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10777 +
10778 +
10779 +/* mask given bcaps */
10780 +
10781 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10782 +
10783 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10784 +
10785 +
10786 +/* masked cap_bset */
10787 +
10788 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10789 +
10790 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10791 +
10792 +#if 0
10793 +#define vx_info_mbcap(v, b) \
10794 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10795 +       vx_info_bcaps(v, b) : (b))
10796 +
10797 +#define task_vx_mbcap(t, b) \
10798 +       vx_info_mbcap((t)->vx_info, (t)->b)
10799 +
10800 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10801 +#endif
10802 +
10803 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10804 +
10805 +#define vx_capable(b, c) (capable(b) || \
10806 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10807 +
10808 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10809 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10810 +
10811 +#define nx_capable(b, c) (capable(b) || \
10812 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10813 +
10814 +#define vx_task_initpid(t, n) \
10815 +       ((t)->vx_info && \
10816 +       ((t)->vx_info->vx_initpid == (n)))
10817 +
10818 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10819 +
10820 +
10821 +/* context unshare mask */
10822 +
10823 +#define __vx_umask(v)          ((v)->vx_umask)
10824 +
10825 +#define vx_current_umask()     __vx_umask(current_vx_info())
10826 +
10827 +#define vx_can_unshare(b, f) (capable(b) || \
10828 +       (cap_raised(current_cap(), b) && \
10829 +       !((f) & ~vx_current_umask())))
10830 +
10831 +
10832 +#define __vx_wmask(v)          ((v)->vx_wmask)
10833 +
10834 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10835 +
10836 +
10837 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10838 +
10839 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10840 +
10841 +
10842 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10843 +
10844 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10845 +
10846 +#endif
10847 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cacct.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct.h
10848 --- linux-3.5.4/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
10849 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct.h 2012-07-23 01:45:55.000000000 +0200
10850 @@ -0,0 +1,15 @@
10851 +#ifndef _VX_CACCT_H
10852 +#define _VX_CACCT_H
10853 +
10854 +
10855 +enum sock_acc_field {
10856 +       VXA_SOCK_UNSPEC = 0,
10857 +       VXA_SOCK_UNIX,
10858 +       VXA_SOCK_INET,
10859 +       VXA_SOCK_INET6,
10860 +       VXA_SOCK_PACKET,
10861 +       VXA_SOCK_OTHER,
10862 +       VXA_SOCK_SIZE   /* array size */
10863 +};
10864 +
10865 +#endif /* _VX_CACCT_H */
10866 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cacct_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct_cmd.h
10867 --- linux-3.5.4/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
10868 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct_cmd.h     2012-07-23 01:45:55.000000000 +0200
10869 @@ -0,0 +1,23 @@
10870 +#ifndef _VX_CACCT_CMD_H
10871 +#define _VX_CACCT_CMD_H
10872 +
10873 +
10874 +/* virtual host info name commands */
10875 +
10876 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10877 +
10878 +struct vcmd_sock_stat_v0 {
10879 +       uint32_t field;
10880 +       uint32_t count[3];
10881 +       uint64_t total[3];
10882 +};
10883 +
10884 +
10885 +#ifdef __KERNEL__
10886 +
10887 +#include <linux/compiler.h>
10888 +
10889 +extern int vc_sock_stat(struct vx_info *, void __user *);
10890 +
10891 +#endif /* __KERNEL__ */
10892 +#endif /* _VX_CACCT_CMD_H */
10893 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cacct_def.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct_def.h
10894 --- linux-3.5.4/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
10895 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct_def.h     2012-07-23 01:45:55.000000000 +0200
10896 @@ -0,0 +1,43 @@
10897 +#ifndef _VX_CACCT_DEF_H
10898 +#define _VX_CACCT_DEF_H
10899 +
10900 +#include <asm/atomic.h>
10901 +#include <linux/vserver/cacct.h>
10902 +
10903 +
10904 +struct _vx_sock_acc {
10905 +       atomic_long_t count;
10906 +       atomic_long_t total;
10907 +};
10908 +
10909 +/* context sub struct */
10910 +
10911 +struct _vx_cacct {
10912 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10913 +       atomic_t slab[8];
10914 +       atomic_t page[6][8];
10915 +};
10916 +
10917 +#ifdef CONFIG_VSERVER_DEBUG
10918 +
10919 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10920 +{
10921 +       int i, j;
10922 +
10923 +       printk("\t_vx_cacct:");
10924 +       for (i = 0; i < 6; i++) {
10925 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10926 +
10927 +               printk("\t [%d] =", i);
10928 +               for (j = 0; j < 3; j++) {
10929 +                       printk(" [%d] = %8lu, %8lu", j,
10930 +                               atomic_long_read(&ptr[j].count),
10931 +                               atomic_long_read(&ptr[j].total));
10932 +               }
10933 +               printk("\n");
10934 +       }
10935 +}
10936 +
10937 +#endif
10938 +
10939 +#endif /* _VX_CACCT_DEF_H */
10940 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cacct_int.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct_int.h
10941 --- linux-3.5.4/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
10942 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cacct_int.h     2012-07-23 01:45:55.000000000 +0200
10943 @@ -0,0 +1,21 @@
10944 +#ifndef _VX_CACCT_INT_H
10945 +#define _VX_CACCT_INT_H
10946 +
10947 +
10948 +#ifdef __KERNEL__
10949 +
10950 +static inline
10951 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10952 +{
10953 +       return atomic_long_read(&cacct->sock[type][pos].count);
10954 +}
10955 +
10956 +
10957 +static inline
10958 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10959 +{
10960 +       return atomic_long_read(&cacct->sock[type][pos].total);
10961 +}
10962 +
10963 +#endif /* __KERNEL__ */
10964 +#endif /* _VX_CACCT_INT_H */
10965 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/check.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/check.h
10966 --- linux-3.5.4/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
10967 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/check.h 2012-07-23 01:45:55.000000000 +0200
10968 @@ -0,0 +1,89 @@
10969 +#ifndef _VS_CHECK_H
10970 +#define _VS_CHECK_H
10971 +
10972 +
10973 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10974 +
10975 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10976 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10977 +#else
10978 +#define MIN_D_CONTEXT  65536
10979 +#endif
10980 +
10981 +/* check conditions */
10982 +
10983 +#define VS_ADMIN       0x0001
10984 +#define VS_WATCH       0x0002
10985 +#define VS_HIDE                0x0004
10986 +#define VS_HOSTID      0x0008
10987 +
10988 +#define VS_IDENT       0x0010
10989 +#define VS_EQUIV       0x0020
10990 +#define VS_PARENT      0x0040
10991 +#define VS_CHILD       0x0080
10992 +
10993 +#define VS_ARG_MASK    0x00F0
10994 +
10995 +#define VS_DYNAMIC     0x0100
10996 +#define VS_STATIC      0x0200
10997 +
10998 +#define VS_ATR_MASK    0x0F00
10999 +
11000 +#ifdef CONFIG_VSERVER_PRIVACY
11001 +#define VS_ADMIN_P     (0)
11002 +#define VS_WATCH_P     (0)
11003 +#else
11004 +#define VS_ADMIN_P     VS_ADMIN
11005 +#define VS_WATCH_P     VS_WATCH
11006 +#endif
11007 +
11008 +#define VS_HARDIRQ     0x1000
11009 +#define VS_SOFTIRQ     0x2000
11010 +#define VS_IRQ         0x4000
11011 +
11012 +#define VS_IRQ_MASK    0xF000
11013 +
11014 +#include <linux/hardirq.h>
11015 +
11016 +/*
11017 + * check current context for ADMIN/WATCH and
11018 + * optionally against supplied argument
11019 + */
11020 +static inline int __vs_check(int cid, int id, unsigned int mode)
11021 +{
11022 +       if (mode & VS_ARG_MASK) {
11023 +               if ((mode & VS_IDENT) && (id == cid))
11024 +                       return 1;
11025 +       }
11026 +       if (mode & VS_ATR_MASK) {
11027 +               if ((mode & VS_DYNAMIC) &&
11028 +                       (id >= MIN_D_CONTEXT) &&
11029 +                       (id <= MAX_S_CONTEXT))
11030 +                       return 1;
11031 +               if ((mode & VS_STATIC) &&
11032 +                       (id > 1) && (id < MIN_D_CONTEXT))
11033 +                       return 1;
11034 +       }
11035 +       if (mode & VS_IRQ_MASK) {
11036 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11037 +                       return 1;
11038 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11039 +                       return 1;
11040 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11041 +                       return 1;
11042 +       }
11043 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11044 +               ((mode & VS_WATCH) && (cid == 1)) ||
11045 +               ((mode & VS_HOSTID) && (id == 0)));
11046 +}
11047 +
11048 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11049 +
11050 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11051 +
11052 +
11053 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11054 +
11055 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11056 +
11057 +#endif
11058 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/context.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/context.h
11059 --- linux-3.5.4/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11060 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/context.h       2012-07-23 01:45:55.000000000 +0200
11061 @@ -0,0 +1,188 @@
11062 +#ifndef _VX_CONTEXT_H
11063 +#define _VX_CONTEXT_H
11064 +
11065 +#include <linux/types.h>
11066 +#include <linux/capability.h>
11067 +
11068 +
11069 +/* context flags */
11070 +
11071 +#define VXF_INFO_SCHED         0x00000002
11072 +#define VXF_INFO_NPROC         0x00000004
11073 +#define VXF_INFO_PRIVATE       0x00000008
11074 +
11075 +#define VXF_INFO_INIT          0x00000010
11076 +#define VXF_INFO_HIDE          0x00000020
11077 +#define VXF_INFO_ULIMIT                0x00000040
11078 +#define VXF_INFO_NSPACE                0x00000080
11079 +
11080 +#define VXF_SCHED_HARD         0x00000100
11081 +#define VXF_SCHED_PRIO         0x00000200
11082 +#define VXF_SCHED_PAUSE                0x00000400
11083 +
11084 +#define VXF_VIRT_MEM           0x00010000
11085 +#define VXF_VIRT_UPTIME                0x00020000
11086 +#define VXF_VIRT_CPU           0x00040000
11087 +#define VXF_VIRT_LOAD          0x00080000
11088 +#define VXF_VIRT_TIME          0x00100000
11089 +
11090 +#define VXF_HIDE_MOUNT         0x01000000
11091 +/* was VXF_HIDE_NETIF          0x02000000 */
11092 +#define VXF_HIDE_VINFO         0x04000000
11093 +
11094 +#define VXF_STATE_SETUP                (1ULL << 32)
11095 +#define VXF_STATE_INIT         (1ULL << 33)
11096 +#define VXF_STATE_ADMIN                (1ULL << 34)
11097 +
11098 +#define VXF_SC_HELPER          (1ULL << 36)
11099 +#define VXF_REBOOT_KILL                (1ULL << 37)
11100 +#define VXF_PERSISTENT         (1ULL << 38)
11101 +
11102 +#define VXF_FORK_RSS           (1ULL << 48)
11103 +#define VXF_PROLIFIC           (1ULL << 49)
11104 +
11105 +#define VXF_IGNEG_NICE         (1ULL << 52)
11106 +
11107 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11108 +
11109 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11110 +
11111 +
11112 +/* context migration */
11113 +
11114 +#define VXM_SET_INIT           0x00000001
11115 +#define VXM_SET_REAPER         0x00000002
11116 +
11117 +/* context caps */
11118 +
11119 +#define VXC_SET_UTSNAME                0x00000001
11120 +#define VXC_SET_RLIMIT         0x00000002
11121 +#define VXC_FS_SECURITY                0x00000004
11122 +#define VXC_FS_TRUSTED         0x00000008
11123 +#define VXC_TIOCSTI            0x00000010
11124 +
11125 +/* was VXC_RAW_ICMP            0x00000100 */
11126 +#define VXC_SYSLOG             0x00001000
11127 +#define VXC_OOM_ADJUST         0x00002000
11128 +#define VXC_AUDIT_CONTROL      0x00004000
11129 +
11130 +#define VXC_SECURE_MOUNT       0x00010000
11131 +#define VXC_SECURE_REMOUNT     0x00020000
11132 +#define VXC_BINARY_MOUNT       0x00040000
11133 +
11134 +#define VXC_QUOTA_CTL          0x00100000
11135 +#define VXC_ADMIN_MAPPER       0x00200000
11136 +#define VXC_ADMIN_CLOOP                0x00400000
11137 +
11138 +#define VXC_KTHREAD            0x01000000
11139 +#define VXC_NAMESPACE          0x02000000
11140 +
11141 +
11142 +#ifdef __KERNEL__
11143 +
11144 +#include <linux/list.h>
11145 +#include <linux/spinlock.h>
11146 +#include <linux/rcupdate.h>
11147 +
11148 +#include "limit_def.h"
11149 +#include "sched_def.h"
11150 +#include "cvirt_def.h"
11151 +#include "cacct_def.h"
11152 +#include "device_def.h"
11153 +
11154 +#define VX_SPACES      2
11155 +
11156 +struct _vx_info_pc {
11157 +       struct _vx_sched_pc sched_pc;
11158 +       struct _vx_cvirt_pc cvirt_pc;
11159 +};
11160 +
11161 +struct _vx_space {
11162 +       unsigned long vx_nsmask;                /* assignment mask */
11163 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11164 +       struct fs_struct *vx_fs;                /* private namespace fs */
11165 +       const struct cred *vx_cred;             /* task credentials */
11166 +};
11167 +
11168 +struct vx_info {
11169 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11170 +       xid_t vx_id;                            /* context id */
11171 +       atomic_t vx_usecnt;                     /* usage count */
11172 +       atomic_t vx_tasks;                      /* tasks count */
11173 +       struct vx_info *vx_parent;              /* parent context */
11174 +       int vx_state;                           /* context state */
11175 +
11176 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11177 +
11178 +       uint64_t vx_flags;                      /* context flags */
11179 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11180 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11181 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11182 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11183 +
11184 +       struct task_struct *vx_reaper;          /* guest reaper process */
11185 +       pid_t vx_initpid;                       /* PID of guest init */
11186 +       int64_t vx_badness_bias;                /* OOM points bias */
11187 +
11188 +       struct _vx_limit limit;                 /* vserver limits */
11189 +       struct _vx_sched sched;                 /* vserver scheduler */
11190 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11191 +       struct _vx_cacct cacct;                 /* context accounting */
11192 +
11193 +       struct _vx_device dmap;                 /* default device map targets */
11194 +
11195 +#ifndef CONFIG_SMP
11196 +       struct _vx_info_pc info_pc;             /* per cpu data */
11197 +#else
11198 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11199 +#endif
11200 +
11201 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11202 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11203 +       int exit_code;                          /* last process exit code */
11204 +
11205 +       char vx_name[65];                       /* vserver name */
11206 +};
11207 +
11208 +#ifndef CONFIG_SMP
11209 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11210 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11211 +#else
11212 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11213 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11214 +#endif
11215 +
11216 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11217 +
11218 +
11219 +struct vx_info_save {
11220 +       struct vx_info *vxi;
11221 +       xid_t xid;
11222 +};
11223 +
11224 +
11225 +/* status flags */
11226 +
11227 +#define VXS_HASHED     0x0001
11228 +#define VXS_PAUSED     0x0010
11229 +#define VXS_SHUTDOWN   0x0100
11230 +#define VXS_HELPER     0x1000
11231 +#define VXS_RELEASED   0x8000
11232 +
11233 +
11234 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11235 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11236 +
11237 +extern struct vx_info *lookup_vx_info(int);
11238 +extern struct vx_info *lookup_or_create_vx_info(int);
11239 +
11240 +extern int get_xid_list(int, unsigned int *, int);
11241 +extern int xid_is_hashed(xid_t);
11242 +
11243 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11244 +
11245 +extern long vs_state_change(struct vx_info *, unsigned int);
11246 +
11247 +
11248 +#endif /* __KERNEL__ */
11249 +#endif /* _VX_CONTEXT_H */
11250 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/context_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/context_cmd.h
11251 --- linux-3.5.4/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11252 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/context_cmd.h   2012-07-23 01:45:55.000000000 +0200
11253 @@ -0,0 +1,162 @@
11254 +#ifndef _VX_CONTEXT_CMD_H
11255 +#define _VX_CONTEXT_CMD_H
11256 +
11257 +
11258 +/* vinfo commands */
11259 +
11260 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11261 +
11262 +#ifdef __KERNEL__
11263 +extern int vc_task_xid(uint32_t);
11264 +
11265 +#endif /* __KERNEL__ */
11266 +
11267 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11268 +
11269 +struct vcmd_vx_info_v0 {
11270 +       uint32_t xid;
11271 +       uint32_t initpid;
11272 +       /* more to come */
11273 +};
11274 +
11275 +#ifdef __KERNEL__
11276 +extern int vc_vx_info(struct vx_info *, void __user *);
11277 +
11278 +#endif /* __KERNEL__ */
11279 +
11280 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11281 +
11282 +struct vcmd_ctx_stat_v0 {
11283 +       uint32_t usecnt;
11284 +       uint32_t tasks;
11285 +       /* more to come */
11286 +};
11287 +
11288 +#ifdef __KERNEL__
11289 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11290 +
11291 +#endif /* __KERNEL__ */
11292 +
11293 +/* context commands */
11294 +
11295 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11296 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11297 +
11298 +struct vcmd_ctx_create {
11299 +       uint64_t flagword;
11300 +};
11301 +
11302 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11303 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11304 +
11305 +struct vcmd_ctx_migrate {
11306 +       uint64_t flagword;
11307 +};
11308 +
11309 +#ifdef __KERNEL__
11310 +extern int vc_ctx_create(uint32_t, void __user *);
11311 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11312 +
11313 +#endif /* __KERNEL__ */
11314 +
11315 +
11316 +/* flag commands */
11317 +
11318 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11319 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11320 +
11321 +struct vcmd_ctx_flags_v0 {
11322 +       uint64_t flagword;
11323 +       uint64_t mask;
11324 +};
11325 +
11326 +#ifdef __KERNEL__
11327 +extern int vc_get_cflags(struct vx_info *, void __user *);
11328 +extern int vc_set_cflags(struct vx_info *, void __user *);
11329 +
11330 +#endif /* __KERNEL__ */
11331 +
11332 +
11333 +/* context caps commands */
11334 +
11335 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11336 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11337 +
11338 +struct vcmd_ctx_caps_v1 {
11339 +       uint64_t ccaps;
11340 +       uint64_t cmask;
11341 +};
11342 +
11343 +#ifdef __KERNEL__
11344 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11345 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11346 +
11347 +#endif /* __KERNEL__ */
11348 +
11349 +
11350 +/* bcaps commands */
11351 +
11352 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11353 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11354 +
11355 +struct vcmd_bcaps {
11356 +       uint64_t bcaps;
11357 +       uint64_t bmask;
11358 +};
11359 +
11360 +#ifdef __KERNEL__
11361 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11362 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11363 +
11364 +#endif /* __KERNEL__ */
11365 +
11366 +
11367 +/* umask commands */
11368 +
11369 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11370 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11371 +
11372 +struct vcmd_umask {
11373 +       uint64_t umask;
11374 +       uint64_t mask;
11375 +};
11376 +
11377 +#ifdef __KERNEL__
11378 +extern int vc_get_umask(struct vx_info *, void __user *);
11379 +extern int vc_set_umask(struct vx_info *, void __user *);
11380 +
11381 +#endif /* __KERNEL__ */
11382 +
11383 +
11384 +/* wmask commands */
11385 +
11386 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11387 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11388 +
11389 +struct vcmd_wmask {
11390 +       uint64_t wmask;
11391 +       uint64_t mask;
11392 +};
11393 +
11394 +#ifdef __KERNEL__
11395 +extern int vc_get_wmask(struct vx_info *, void __user *);
11396 +extern int vc_set_wmask(struct vx_info *, void __user *);
11397 +
11398 +#endif /* __KERNEL__ */
11399 +
11400 +
11401 +/* OOM badness */
11402 +
11403 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11404 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11405 +
11406 +struct vcmd_badness_v0 {
11407 +       int64_t bias;
11408 +};
11409 +
11410 +#ifdef __KERNEL__
11411 +extern int vc_get_badness(struct vx_info *, void __user *);
11412 +extern int vc_set_badness(struct vx_info *, void __user *);
11413 +
11414 +#endif /* __KERNEL__ */
11415 +#endif /* _VX_CONTEXT_CMD_H */
11416 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cvirt.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cvirt.h
11417 --- linux-3.5.4/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11418 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cvirt.h 2012-07-23 01:45:55.000000000 +0200
11419 @@ -0,0 +1,22 @@
11420 +#ifndef _VX_CVIRT_H
11421 +#define _VX_CVIRT_H
11422 +
11423 +
11424 +#ifdef __KERNEL__
11425 +
11426 +struct timespec;
11427 +
11428 +void vx_vsi_boottime(struct timespec *);
11429 +
11430 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11431 +
11432 +
11433 +struct vx_info;
11434 +
11435 +void vx_update_load(struct vx_info *);
11436 +
11437 +
11438 +int vx_do_syslog(int, char __user *, int);
11439 +
11440 +#endif /* __KERNEL__ */
11441 +#endif /* _VX_CVIRT_H */
11442 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cvirt_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cvirt_cmd.h
11443 --- linux-3.5.4/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11444 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cvirt_cmd.h     2012-07-23 01:45:55.000000000 +0200
11445 @@ -0,0 +1,53 @@
11446 +#ifndef _VX_CVIRT_CMD_H
11447 +#define _VX_CVIRT_CMD_H
11448 +
11449 +
11450 +/* virtual host info name commands */
11451 +
11452 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11453 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11454 +
11455 +struct vcmd_vhi_name_v0 {
11456 +       uint32_t field;
11457 +       char name[65];
11458 +};
11459 +
11460 +
11461 +enum vhi_name_field {
11462 +       VHIN_CONTEXT = 0,
11463 +       VHIN_SYSNAME,
11464 +       VHIN_NODENAME,
11465 +       VHIN_RELEASE,
11466 +       VHIN_VERSION,
11467 +       VHIN_MACHINE,
11468 +       VHIN_DOMAINNAME,
11469 +};
11470 +
11471 +
11472 +#ifdef __KERNEL__
11473 +
11474 +#include <linux/compiler.h>
11475 +
11476 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11477 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11478 +
11479 +#endif /* __KERNEL__ */
11480 +
11481 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11482 +
11483 +struct vcmd_virt_stat_v0 {
11484 +       uint64_t offset;
11485 +       uint64_t uptime;
11486 +       uint32_t nr_threads;
11487 +       uint32_t nr_running;
11488 +       uint32_t nr_uninterruptible;
11489 +       uint32_t nr_onhold;
11490 +       uint32_t nr_forks;
11491 +       uint32_t load[3];
11492 +};
11493 +
11494 +#ifdef __KERNEL__
11495 +extern int vc_virt_stat(struct vx_info *, void __user *);
11496 +
11497 +#endif /* __KERNEL__ */
11498 +#endif /* _VX_CVIRT_CMD_H */
11499 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/cvirt_def.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/cvirt_def.h
11500 --- linux-3.5.4/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11501 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/cvirt_def.h     2012-07-23 01:45:55.000000000 +0200
11502 @@ -0,0 +1,80 @@
11503 +#ifndef _VX_CVIRT_DEF_H
11504 +#define _VX_CVIRT_DEF_H
11505 +
11506 +#include <linux/jiffies.h>
11507 +#include <linux/spinlock.h>
11508 +#include <linux/wait.h>
11509 +#include <linux/time.h>
11510 +#include <asm/atomic.h>
11511 +
11512 +
11513 +struct _vx_usage_stat {
11514 +       uint64_t user;
11515 +       uint64_t nice;
11516 +       uint64_t system;
11517 +       uint64_t softirq;
11518 +       uint64_t irq;
11519 +       uint64_t idle;
11520 +       uint64_t iowait;
11521 +};
11522 +
11523 +struct _vx_syslog {
11524 +       wait_queue_head_t log_wait;
11525 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11526 +
11527 +       unsigned long log_start;        /* next char to be read by syslog() */
11528 +       unsigned long con_start;        /* next char to be sent to consoles */
11529 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11530 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11531 +
11532 +       char log_buf[1024];
11533 +};
11534 +
11535 +
11536 +/* context sub struct */
11537 +
11538 +struct _vx_cvirt {
11539 +       atomic_t nr_threads;            /* number of current threads */
11540 +       atomic_t nr_running;            /* number of running threads */
11541 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11542 +
11543 +       atomic_t nr_onhold;             /* processes on hold */
11544 +       uint32_t onhold_last;           /* jiffies when put on hold */
11545 +
11546 +       struct timespec bias_ts;        /* time offset to the host */
11547 +       struct timespec bias_idle;
11548 +       struct timespec bias_uptime;    /* context creation point */
11549 +       uint64_t bias_clock;            /* offset in clock_t */
11550 +
11551 +       spinlock_t load_lock;           /* lock for the load averages */
11552 +       atomic_t load_updates;          /* nr of load updates done so far */
11553 +       uint32_t load_last;             /* last time load was calculated */
11554 +       uint32_t load[3];               /* load averages 1,5,15 */
11555 +
11556 +       atomic_t total_forks;           /* number of forks so far */
11557 +
11558 +       struct _vx_syslog syslog;
11559 +};
11560 +
11561 +struct _vx_cvirt_pc {
11562 +       struct _vx_usage_stat cpustat;
11563 +};
11564 +
11565 +
11566 +#ifdef CONFIG_VSERVER_DEBUG
11567 +
11568 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11569 +{
11570 +       printk("\t_vx_cvirt:\n");
11571 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11572 +               atomic_read(&cvirt->nr_threads),
11573 +               atomic_read(&cvirt->nr_running),
11574 +               atomic_read(&cvirt->nr_uninterruptible),
11575 +               atomic_read(&cvirt->nr_onhold));
11576 +       /* add rest here */
11577 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11578 +}
11579 +
11580 +#endif
11581 +
11582 +#endif /* _VX_CVIRT_DEF_H */
11583 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/debug.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/debug.h
11584 --- linux-3.5.4/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11585 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/debug.h 2012-07-23 01:45:55.000000000 +0200
11586 @@ -0,0 +1,145 @@
11587 +#ifndef _VX_DEBUG_H
11588 +#define _VX_DEBUG_H
11589 +
11590 +
11591 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11592 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11593 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11594 +
11595 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11596 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11597 +#define VXF_DEV                "%p[%lu,%d:%d]"
11598 +
11599 +#if    defined(CONFIG_QUOTES_UTF8)
11600 +#define        VS_Q_LQM        "\xc2\xbb"
11601 +#define        VS_Q_RQM        "\xc2\xab"
11602 +#elif  defined(CONFIG_QUOTES_ASCII)
11603 +#define        VS_Q_LQM        "\x27"
11604 +#define        VS_Q_RQM        "\x27"
11605 +#else
11606 +#define        VS_Q_LQM        "\xbb"
11607 +#define        VS_Q_RQM        "\xab"
11608 +#endif
11609 +
11610 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11611 +
11612 +
11613 +#define vxd_path(p)                                            \
11614 +       ({ static char _buffer[PATH_MAX];                       \
11615 +          d_path(p, _buffer, sizeof(_buffer)); })
11616 +
11617 +#define vxd_cond_path(n)                                       \
11618 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11619 +
11620 +
11621 +#ifdef CONFIG_VSERVER_DEBUG
11622 +
11623 +extern unsigned int vs_debug_switch;
11624 +extern unsigned int vs_debug_xid;
11625 +extern unsigned int vs_debug_nid;
11626 +extern unsigned int vs_debug_tag;
11627 +extern unsigned int vs_debug_net;
11628 +extern unsigned int vs_debug_limit;
11629 +extern unsigned int vs_debug_cres;
11630 +extern unsigned int vs_debug_dlim;
11631 +extern unsigned int vs_debug_quota;
11632 +extern unsigned int vs_debug_cvirt;
11633 +extern unsigned int vs_debug_space;
11634 +extern unsigned int vs_debug_perm;
11635 +extern unsigned int vs_debug_misc;
11636 +
11637 +
11638 +#define VX_LOGLEVEL    "vxD: "
11639 +#define VX_PROC_FMT    "%p: "
11640 +#define VX_PROCESS     current
11641 +
11642 +#define vxdprintk(c, f, x...)                                  \
11643 +       do {                                                    \
11644 +               if (c)                                          \
11645 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11646 +                               VX_PROCESS , ##x);              \
11647 +       } while (0)
11648 +
11649 +#define vxlprintk(c, f, x...)                                  \
11650 +       do {                                                    \
11651 +               if (c)                                          \
11652 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11653 +       } while (0)
11654 +
11655 +#define vxfprintk(c, f, x...)                                  \
11656 +       do {                                                    \
11657 +               if (c)                                          \
11658 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11659 +       } while (0)
11660 +
11661 +
11662 +struct vx_info;
11663 +
11664 +void dump_vx_info(struct vx_info *, int);
11665 +void dump_vx_info_inactive(int);
11666 +
11667 +#else  /* CONFIG_VSERVER_DEBUG */
11668 +
11669 +#define vs_debug_switch        0
11670 +#define vs_debug_xid   0
11671 +#define vs_debug_nid   0
11672 +#define vs_debug_tag   0
11673 +#define vs_debug_net   0
11674 +#define vs_debug_limit 0
11675 +#define vs_debug_cres  0
11676 +#define vs_debug_dlim  0
11677 +#define vs_debug_quota 0
11678 +#define vs_debug_cvirt 0
11679 +#define vs_debug_space 0
11680 +#define vs_debug_perm  0
11681 +#define vs_debug_misc  0
11682 +
11683 +#define vxdprintk(x...) do { } while (0)
11684 +#define vxlprintk(x...) do { } while (0)
11685 +#define vxfprintk(x...) do { } while (0)
11686 +
11687 +#endif /* CONFIG_VSERVER_DEBUG */
11688 +
11689 +
11690 +#ifdef CONFIG_VSERVER_WARN
11691 +
11692 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11693 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11694 +#define VX_WARN_XID    "[xid #%u] "
11695 +#define VX_WARN_NID    "[nid #%u] "
11696 +#define VX_WARN_TAG    "[tag #%u] "
11697 +
11698 +#define vxwprintk(c, f, x...)                                  \
11699 +       do {                                                    \
11700 +               if (c)                                          \
11701 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11702 +       } while (0)
11703 +
11704 +#else  /* CONFIG_VSERVER_WARN */
11705 +
11706 +#define vxwprintk(x...) do { } while (0)
11707 +
11708 +#endif /* CONFIG_VSERVER_WARN */
11709 +
11710 +#define vxwprintk_task(c, f, x...)                             \
11711 +       vxwprintk(c, VX_WARN_TASK f,                            \
11712 +               current->comm, current->pid,                    \
11713 +               current->xid, current->nid, current->tag, ##x)
11714 +#define vxwprintk_xid(c, f, x...)                              \
11715 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11716 +#define vxwprintk_nid(c, f, x...)                              \
11717 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11718 +#define vxwprintk_tag(c, f, x...)                              \
11719 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11720 +
11721 +#ifdef CONFIG_VSERVER_DEBUG
11722 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11723 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11724 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11725 +#else
11726 +#define vxd_assert_lock(l)     do { } while (0)
11727 +#define vxd_assert(c, f, x...) do { } while (0)
11728 +#endif
11729 +
11730 +
11731 +#endif /* _VX_DEBUG_H */
11732 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/debug_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/debug_cmd.h
11733 --- linux-3.5.4/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
11734 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/debug_cmd.h     2012-07-23 01:45:55.000000000 +0200
11735 @@ -0,0 +1,58 @@
11736 +#ifndef _VX_DEBUG_CMD_H
11737 +#define _VX_DEBUG_CMD_H
11738 +
11739 +
11740 +/* debug commands */
11741 +
11742 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11743 +
11744 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11745 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11746 +
11747 +struct  vcmd_read_history_v0 {
11748 +       uint32_t index;
11749 +       uint32_t count;
11750 +       char __user *data;
11751 +};
11752 +
11753 +struct  vcmd_read_monitor_v0 {
11754 +       uint32_t index;
11755 +       uint32_t count;
11756 +       char __user *data;
11757 +};
11758 +
11759 +
11760 +#ifdef __KERNEL__
11761 +
11762 +#ifdef CONFIG_COMPAT
11763 +
11764 +#include <asm/compat.h>
11765 +
11766 +struct vcmd_read_history_v0_x32 {
11767 +       uint32_t index;
11768 +       uint32_t count;
11769 +       compat_uptr_t data_ptr;
11770 +};
11771 +
11772 +struct vcmd_read_monitor_v0_x32 {
11773 +       uint32_t index;
11774 +       uint32_t count;
11775 +       compat_uptr_t data_ptr;
11776 +};
11777 +
11778 +#endif  /* CONFIG_COMPAT */
11779 +
11780 +extern int vc_dump_history(uint32_t);
11781 +
11782 +extern int vc_read_history(uint32_t, void __user *);
11783 +extern int vc_read_monitor(uint32_t, void __user *);
11784 +
11785 +#ifdef CONFIG_COMPAT
11786 +
11787 +extern int vc_read_history_x32(uint32_t, void __user *);
11788 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11789 +
11790 +#endif  /* CONFIG_COMPAT */
11791 +
11792 +#endif /* __KERNEL__ */
11793 +#endif /* _VX_DEBUG_CMD_H */
11794 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/device.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/device.h
11795 --- linux-3.5.4/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
11796 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/device.h        2012-07-23 01:45:55.000000000 +0200
11797 @@ -0,0 +1,15 @@
11798 +#ifndef _VX_DEVICE_H
11799 +#define _VX_DEVICE_H
11800 +
11801 +
11802 +#define DATTR_CREATE   0x00000001
11803 +#define DATTR_OPEN     0x00000002
11804 +
11805 +#define DATTR_REMAP    0x00000010
11806 +
11807 +#define DATTR_MASK     0x00000013
11808 +
11809 +
11810 +#else  /* _VX_DEVICE_H */
11811 +#warning duplicate inclusion
11812 +#endif /* _VX_DEVICE_H */
11813 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/device_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/device_cmd.h
11814 --- linux-3.5.4/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
11815 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/device_cmd.h    2012-07-23 01:45:55.000000000 +0200
11816 @@ -0,0 +1,44 @@
11817 +#ifndef _VX_DEVICE_CMD_H
11818 +#define _VX_DEVICE_CMD_H
11819 +
11820 +
11821 +/*  device vserver commands */
11822 +
11823 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11824 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11825 +
11826 +struct vcmd_set_mapping_v0 {
11827 +       const char __user *device;
11828 +       const char __user *target;
11829 +       uint32_t flags;
11830 +};
11831 +
11832 +
11833 +#ifdef __KERNEL__
11834 +
11835 +#ifdef CONFIG_COMPAT
11836 +
11837 +#include <asm/compat.h>
11838 +
11839 +struct vcmd_set_mapping_v0_x32 {
11840 +       compat_uptr_t device_ptr;
11841 +       compat_uptr_t target_ptr;
11842 +       uint32_t flags;
11843 +};
11844 +
11845 +#endif /* CONFIG_COMPAT */
11846 +
11847 +#include <linux/compiler.h>
11848 +
11849 +extern int vc_set_mapping(struct vx_info *, void __user *);
11850 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11851 +
11852 +#ifdef CONFIG_COMPAT
11853 +
11854 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11855 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11856 +
11857 +#endif /* CONFIG_COMPAT */
11858 +
11859 +#endif /* __KERNEL__ */
11860 +#endif /* _VX_DEVICE_CMD_H */
11861 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/device_def.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/device_def.h
11862 --- linux-3.5.4/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
11863 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/device_def.h    2012-07-23 01:45:55.000000000 +0200
11864 @@ -0,0 +1,17 @@
11865 +#ifndef _VX_DEVICE_DEF_H
11866 +#define _VX_DEVICE_DEF_H
11867 +
11868 +#include <linux/types.h>
11869 +
11870 +struct vx_dmap_target {
11871 +       dev_t target;
11872 +       uint32_t flags;
11873 +};
11874 +
11875 +struct _vx_device {
11876 +#ifdef CONFIG_VSERVER_DEVICE
11877 +       struct vx_dmap_target targets[2];
11878 +#endif
11879 +};
11880 +
11881 +#endif /* _VX_DEVICE_DEF_H */
11882 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/dlimit.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/dlimit.h
11883 --- linux-3.5.4/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
11884 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/dlimit.h        2012-07-23 01:45:55.000000000 +0200
11885 @@ -0,0 +1,54 @@
11886 +#ifndef _VX_DLIMIT_H
11887 +#define _VX_DLIMIT_H
11888 +
11889 +#include "switch.h"
11890 +
11891 +
11892 +#ifdef __KERNEL__
11893 +
11894 +/*      keep in sync with CDLIM_INFINITY       */
11895 +
11896 +#define DLIM_INFINITY          (~0ULL)
11897 +
11898 +#include <linux/spinlock.h>
11899 +#include <linux/rcupdate.h>
11900 +
11901 +struct super_block;
11902 +
11903 +struct dl_info {
11904 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11905 +       struct rcu_head dl_rcu;                 /* the rcu head */
11906 +       tag_t dl_tag;                           /* context tag */
11907 +       atomic_t dl_usecnt;                     /* usage count */
11908 +       atomic_t dl_refcnt;                     /* reference count */
11909 +
11910 +       struct super_block *dl_sb;              /* associated superblock */
11911 +
11912 +       spinlock_t dl_lock;                     /* protect the values */
11913 +
11914 +       unsigned long long dl_space_used;       /* used space in bytes */
11915 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11916 +       unsigned long dl_inodes_used;           /* used inodes */
11917 +       unsigned long dl_inodes_total;          /* maximum inodes */
11918 +
11919 +       unsigned int dl_nrlmult;                /* non root limit mult */
11920 +};
11921 +
11922 +struct rcu_head;
11923 +
11924 +extern void rcu_free_dl_info(struct rcu_head *);
11925 +extern void unhash_dl_info(struct dl_info *);
11926 +
11927 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11928 +
11929 +
11930 +struct kstatfs;
11931 +
11932 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11933 +
11934 +typedef uint64_t dlsize_t;
11935 +
11936 +#endif /* __KERNEL__ */
11937 +#else  /* _VX_DLIMIT_H */
11938 +#warning duplicate inclusion
11939 +#endif /* _VX_DLIMIT_H */
11940 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/dlimit_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/dlimit_cmd.h
11941 --- linux-3.5.4/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11942 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/dlimit_cmd.h    2012-07-23 01:45:55.000000000 +0200
11943 @@ -0,0 +1,109 @@
11944 +#ifndef _VX_DLIMIT_CMD_H
11945 +#define _VX_DLIMIT_CMD_H
11946 +
11947 +
11948 +/*  dlimit vserver commands */
11949 +
11950 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11951 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11952 +
11953 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11954 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11955 +
11956 +struct vcmd_ctx_dlimit_base_v0 {
11957 +       const char __user *name;
11958 +       uint32_t flags;
11959 +};
11960 +
11961 +struct vcmd_ctx_dlimit_v0 {
11962 +       const char __user *name;
11963 +       uint32_t space_used;                    /* used space in kbytes */
11964 +       uint32_t space_total;                   /* maximum space in kbytes */
11965 +       uint32_t inodes_used;                   /* used inodes */
11966 +       uint32_t inodes_total;                  /* maximum inodes */
11967 +       uint32_t reserved;                      /* reserved for root in % */
11968 +       uint32_t flags;
11969 +};
11970 +
11971 +#define CDLIM_UNSET            ((uint32_t)0UL)
11972 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11973 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11974 +
11975 +#define DLIME_UNIT     0
11976 +#define DLIME_KILO     1
11977 +#define DLIME_MEGA     2
11978 +#define DLIME_GIGA     3
11979 +
11980 +#define DLIMF_SHIFT    0x10
11981 +
11982 +#define DLIMS_USED     0
11983 +#define DLIMS_TOTAL    2
11984 +
11985 +static inline
11986 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11987 +{
11988 +       int exp = (flags & DLIMF_SHIFT) ?
11989 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11990 +       return ((uint64_t)val) << (10 * exp);
11991 +}
11992 +
11993 +static inline
11994 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11995 +{
11996 +       int exp = 0;
11997 +
11998 +       if (*flags & DLIMF_SHIFT) {
11999 +               while (val > (1LL << 32) && (exp < 3)) {
12000 +                       val >>= 10;
12001 +                       exp++;
12002 +               }
12003 +               *flags &= ~(DLIME_GIGA << shift);
12004 +               *flags |= exp << shift;
12005 +       } else
12006 +               val >>= 10;
12007 +       return val;
12008 +}
12009 +
12010 +#ifdef __KERNEL__
12011 +
12012 +#ifdef CONFIG_COMPAT
12013 +
12014 +#include <asm/compat.h>
12015 +
12016 +struct vcmd_ctx_dlimit_base_v0_x32 {
12017 +       compat_uptr_t name_ptr;
12018 +       uint32_t flags;
12019 +};
12020 +
12021 +struct vcmd_ctx_dlimit_v0_x32 {
12022 +       compat_uptr_t name_ptr;
12023 +       uint32_t space_used;                    /* used space in kbytes */
12024 +       uint32_t space_total;                   /* maximum space in kbytes */
12025 +       uint32_t inodes_used;                   /* used inodes */
12026 +       uint32_t inodes_total;                  /* maximum inodes */
12027 +       uint32_t reserved;                      /* reserved for root in % */
12028 +       uint32_t flags;
12029 +};
12030 +
12031 +#endif /* CONFIG_COMPAT */
12032 +
12033 +#include <linux/compiler.h>
12034 +
12035 +extern int vc_add_dlimit(uint32_t, void __user *);
12036 +extern int vc_rem_dlimit(uint32_t, void __user *);
12037 +
12038 +extern int vc_set_dlimit(uint32_t, void __user *);
12039 +extern int vc_get_dlimit(uint32_t, void __user *);
12040 +
12041 +#ifdef CONFIG_COMPAT
12042 +
12043 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12044 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12045 +
12046 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12047 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12048 +
12049 +#endif /* CONFIG_COMPAT */
12050 +
12051 +#endif /* __KERNEL__ */
12052 +#endif /* _VX_DLIMIT_CMD_H */
12053 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/global.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/global.h
12054 --- linux-3.5.4/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12055 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/global.h        2012-07-23 01:45:55.000000000 +0200
12056 @@ -0,0 +1,19 @@
12057 +#ifndef _VX_GLOBAL_H
12058 +#define _VX_GLOBAL_H
12059 +
12060 +
12061 +extern atomic_t vx_global_ctotal;
12062 +extern atomic_t vx_global_cactive;
12063 +
12064 +extern atomic_t nx_global_ctotal;
12065 +extern atomic_t nx_global_cactive;
12066 +
12067 +extern atomic_t vs_global_nsproxy;
12068 +extern atomic_t vs_global_fs;
12069 +extern atomic_t vs_global_mnt_ns;
12070 +extern atomic_t vs_global_uts_ns;
12071 +extern atomic_t vs_global_user_ns;
12072 +extern atomic_t vs_global_pid_ns;
12073 +
12074 +
12075 +#endif /* _VX_GLOBAL_H */
12076 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/history.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/history.h
12077 --- linux-3.5.4/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12078 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/history.h       2012-07-23 01:45:55.000000000 +0200
12079 @@ -0,0 +1,197 @@
12080 +#ifndef _VX_HISTORY_H
12081 +#define _VX_HISTORY_H
12082 +
12083 +
12084 +enum {
12085 +       VXH_UNUSED = 0,
12086 +       VXH_THROW_OOPS = 1,
12087 +
12088 +       VXH_GET_VX_INFO,
12089 +       VXH_PUT_VX_INFO,
12090 +       VXH_INIT_VX_INFO,
12091 +       VXH_SET_VX_INFO,
12092 +       VXH_CLR_VX_INFO,
12093 +       VXH_CLAIM_VX_INFO,
12094 +       VXH_RELEASE_VX_INFO,
12095 +       VXH_ALLOC_VX_INFO,
12096 +       VXH_DEALLOC_VX_INFO,
12097 +       VXH_HASH_VX_INFO,
12098 +       VXH_UNHASH_VX_INFO,
12099 +       VXH_LOC_VX_INFO,
12100 +       VXH_LOOKUP_VX_INFO,
12101 +       VXH_CREATE_VX_INFO,
12102 +};
12103 +
12104 +struct _vxhe_vxi {
12105 +       struct vx_info *ptr;
12106 +       unsigned xid;
12107 +       unsigned usecnt;
12108 +       unsigned tasks;
12109 +};
12110 +
12111 +struct _vxhe_set_clr {
12112 +       void *data;
12113 +};
12114 +
12115 +struct _vxhe_loc_lookup {
12116 +       unsigned arg;
12117 +};
12118 +
12119 +struct _vx_hist_entry {
12120 +       void *loc;
12121 +       unsigned short seq;
12122 +       unsigned short type;
12123 +       struct _vxhe_vxi vxi;
12124 +       union {
12125 +               struct _vxhe_set_clr sc;
12126 +               struct _vxhe_loc_lookup ll;
12127 +       };
12128 +};
12129 +
12130 +#ifdef CONFIG_VSERVER_HISTORY
12131 +
12132 +extern unsigned volatile int vxh_active;
12133 +
12134 +struct _vx_hist_entry *vxh_advance(void *loc);
12135 +
12136 +
12137 +static inline
12138 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12139 +{
12140 +       entry->vxi.ptr = vxi;
12141 +       if (vxi) {
12142 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12143 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12144 +               entry->vxi.xid = vxi->vx_id;
12145 +       }
12146 +}
12147 +
12148 +
12149 +#define        __HERE__ current_text_addr()
12150 +
12151 +#define __VXH_BODY(__type, __data, __here)     \
12152 +       struct _vx_hist_entry *entry;           \
12153 +                                               \
12154 +       preempt_disable();                      \
12155 +       entry = vxh_advance(__here);            \
12156 +       __data;                                 \
12157 +       entry->type = __type;                   \
12158 +       preempt_enable();
12159 +
12160 +
12161 +       /* pass vxi only */
12162 +
12163 +#define __VXH_SMPL                             \
12164 +       __vxh_copy_vxi(entry, vxi)
12165 +
12166 +static inline
12167 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12168 +{
12169 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12170 +}
12171 +
12172 +       /* pass vxi and data (void *) */
12173 +
12174 +#define __VXH_DATA                             \
12175 +       __vxh_copy_vxi(entry, vxi);             \
12176 +       entry->sc.data = data
12177 +
12178 +static inline
12179 +void   __vxh_data(struct vx_info *vxi, void *data,
12180 +                       int __type, void *__here)
12181 +{
12182 +       __VXH_BODY(__type, __VXH_DATA, __here)
12183 +}
12184 +
12185 +       /* pass vxi and arg (long) */
12186 +
12187 +#define __VXH_LONG                             \
12188 +       __vxh_copy_vxi(entry, vxi);             \
12189 +       entry->ll.arg = arg
12190 +
12191 +static inline
12192 +void   __vxh_long(struct vx_info *vxi, long arg,
12193 +                       int __type, void *__here)
12194 +{
12195 +       __VXH_BODY(__type, __VXH_LONG, __here)
12196 +}
12197 +
12198 +
12199 +static inline
12200 +void   __vxh_throw_oops(void *__here)
12201 +{
12202 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12203 +       /* prevent further acquisition */
12204 +       vxh_active = 0;
12205 +}
12206 +
12207 +
12208 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12209 +
12210 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12211 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12212 +
12213 +#define __vxh_init_vx_info(v, d, h) \
12214 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12215 +#define __vxh_set_vx_info(v, d, h) \
12216 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12217 +#define __vxh_clr_vx_info(v, d, h) \
12218 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12219 +
12220 +#define __vxh_claim_vx_info(v, d, h) \
12221 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12222 +#define __vxh_release_vx_info(v, d, h) \
12223 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12224 +
12225 +#define vxh_alloc_vx_info(v) \
12226 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12227 +#define vxh_dealloc_vx_info(v) \
12228 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12229 +
12230 +#define vxh_hash_vx_info(v) \
12231 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12232 +#define vxh_unhash_vx_info(v) \
12233 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12234 +
12235 +#define vxh_loc_vx_info(v, l) \
12236 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12237 +#define vxh_lookup_vx_info(v, l) \
12238 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12239 +#define vxh_create_vx_info(v, l) \
12240 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12241 +
12242 +extern void vxh_dump_history(void);
12243 +
12244 +
12245 +#else  /* CONFIG_VSERVER_HISTORY */
12246 +
12247 +#define        __HERE__        0
12248 +
12249 +#define vxh_throw_oops()               do { } while (0)
12250 +
12251 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12252 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12253 +
12254 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12255 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12256 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12257 +
12258 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12259 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12260 +
12261 +#define vxh_alloc_vx_info(v)           do { } while (0)
12262 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12263 +
12264 +#define vxh_hash_vx_info(v)            do { } while (0)
12265 +#define vxh_unhash_vx_info(v)          do { } while (0)
12266 +
12267 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12268 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12269 +#define vxh_create_vx_info(v, l)       do { } while (0)
12270 +
12271 +#define vxh_dump_history()             do { } while (0)
12272 +
12273 +
12274 +#endif /* CONFIG_VSERVER_HISTORY */
12275 +
12276 +#endif /* _VX_HISTORY_H */
12277 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/inode.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/inode.h
12278 --- linux-3.5.4/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12279 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/inode.h 2012-07-23 01:45:55.000000000 +0200
12280 @@ -0,0 +1,39 @@
12281 +#ifndef _VX_INODE_H
12282 +#define _VX_INODE_H
12283 +
12284 +
12285 +#define IATTR_TAG      0x01000000
12286 +
12287 +#define IATTR_ADMIN    0x00000001
12288 +#define IATTR_WATCH    0x00000002
12289 +#define IATTR_HIDE     0x00000004
12290 +#define IATTR_FLAGS    0x00000007
12291 +
12292 +#define IATTR_BARRIER  0x00010000
12293 +#define IATTR_IXUNLINK 0x00020000
12294 +#define IATTR_IMMUTABLE 0x00040000
12295 +#define IATTR_COW      0x00080000
12296 +
12297 +#ifdef __KERNEL__
12298 +
12299 +
12300 +#ifdef CONFIG_VSERVER_PROC_SECURE
12301 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12302 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12303 +#else
12304 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12305 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12306 +#endif
12307 +
12308 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12309 +
12310 +#endif /* __KERNEL__ */
12311 +
12312 +/* inode ioctls */
12313 +
12314 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12315 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12316 +
12317 +#else  /* _VX_INODE_H */
12318 +#warning duplicate inclusion
12319 +#endif /* _VX_INODE_H */
12320 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/inode_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/inode_cmd.h
12321 --- linux-3.5.4/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12322 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/inode_cmd.h     2012-07-23 01:45:55.000000000 +0200
12323 @@ -0,0 +1,59 @@
12324 +#ifndef _VX_INODE_CMD_H
12325 +#define _VX_INODE_CMD_H
12326 +
12327 +
12328 +/*  inode vserver commands */
12329 +
12330 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12331 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12332 +
12333 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12334 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12335 +
12336 +struct vcmd_ctx_iattr_v1 {
12337 +       const char __user *name;
12338 +       uint32_t tag;
12339 +       uint32_t flags;
12340 +       uint32_t mask;
12341 +};
12342 +
12343 +struct vcmd_ctx_fiattr_v0 {
12344 +       uint32_t tag;
12345 +       uint32_t flags;
12346 +       uint32_t mask;
12347 +};
12348 +
12349 +
12350 +#ifdef __KERNEL__
12351 +
12352 +
12353 +#ifdef CONFIG_COMPAT
12354 +
12355 +#include <asm/compat.h>
12356 +
12357 +struct vcmd_ctx_iattr_v1_x32 {
12358 +       compat_uptr_t name_ptr;
12359 +       uint32_t tag;
12360 +       uint32_t flags;
12361 +       uint32_t mask;
12362 +};
12363 +
12364 +#endif /* CONFIG_COMPAT */
12365 +
12366 +#include <linux/compiler.h>
12367 +
12368 +extern int vc_get_iattr(void __user *);
12369 +extern int vc_set_iattr(void __user *);
12370 +
12371 +extern int vc_fget_iattr(uint32_t, void __user *);
12372 +extern int vc_fset_iattr(uint32_t, void __user *);
12373 +
12374 +#ifdef CONFIG_COMPAT
12375 +
12376 +extern int vc_get_iattr_x32(void __user *);
12377 +extern int vc_set_iattr_x32(void __user *);
12378 +
12379 +#endif /* CONFIG_COMPAT */
12380 +
12381 +#endif /* __KERNEL__ */
12382 +#endif /* _VX_INODE_CMD_H */
12383 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/limit.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit.h
12384 --- linux-3.5.4/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12385 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit.h 2012-07-23 01:45:55.000000000 +0200
12386 @@ -0,0 +1,71 @@
12387 +#ifndef _VX_LIMIT_H
12388 +#define _VX_LIMIT_H
12389 +
12390 +#define VLIMIT_NSOCK   16
12391 +#define VLIMIT_OPENFD  17
12392 +#define VLIMIT_ANON    18
12393 +#define VLIMIT_SHMEM   19
12394 +#define VLIMIT_SEMARY  20
12395 +#define VLIMIT_NSEMS   21
12396 +#define VLIMIT_DENTRY  22
12397 +#define VLIMIT_MAPPED  23
12398 +
12399 +
12400 +#ifdef __KERNEL__
12401 +
12402 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12403 +
12404 +/*     keep in sync with CRLIM_INFINITY */
12405 +
12406 +#define        VLIM_INFINITY   (~0ULL)
12407 +
12408 +#include <asm/atomic.h>
12409 +#include <asm/resource.h>
12410 +
12411 +#ifndef RLIM_INFINITY
12412 +#warning RLIM_INFINITY is undefined
12413 +#endif
12414 +
12415 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12416 +
12417 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12418 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12419 +
12420 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12421 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12422 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12423 +
12424 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12425 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12426 +
12427 +typedef atomic_long_t rlim_atomic_t;
12428 +typedef unsigned long rlim_t;
12429 +
12430 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12431 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12432 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12433 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12434 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12435 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12436 +
12437 +
12438 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12439 +#define        VX_VLIM(r) ((long long)(long)(r))
12440 +#define        VX_RLIM(v) ((rlim_t)(v))
12441 +#else
12442 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12443 +               ? VLIM_INFINITY : (long long)(r))
12444 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12445 +               ? RLIM_INFINITY : (rlim_t)(v))
12446 +#endif
12447 +
12448 +struct sysinfo;
12449 +
12450 +void vx_vsi_meminfo(struct sysinfo *);
12451 +void vx_vsi_swapinfo(struct sysinfo *);
12452 +long vx_vsi_cached(struct sysinfo *);
12453 +
12454 +#define NUM_LIMITS     24
12455 +
12456 +#endif /* __KERNEL__ */
12457 +#endif /* _VX_LIMIT_H */
12458 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/limit_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit_cmd.h
12459 --- linux-3.5.4/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12460 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit_cmd.h     2012-07-23 01:45:55.000000000 +0200
12461 @@ -0,0 +1,71 @@
12462 +#ifndef _VX_LIMIT_CMD_H
12463 +#define _VX_LIMIT_CMD_H
12464 +
12465 +
12466 +/*  rlimit vserver commands */
12467 +
12468 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12469 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12470 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12471 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12472 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12473 +
12474 +struct vcmd_ctx_rlimit_v0 {
12475 +       uint32_t id;
12476 +       uint64_t minimum;
12477 +       uint64_t softlimit;
12478 +       uint64_t maximum;
12479 +};
12480 +
12481 +struct vcmd_ctx_rlimit_mask_v0 {
12482 +       uint32_t minimum;
12483 +       uint32_t softlimit;
12484 +       uint32_t maximum;
12485 +};
12486 +
12487 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12488 +
12489 +struct vcmd_rlimit_stat_v0 {
12490 +       uint32_t id;
12491 +       uint32_t hits;
12492 +       uint64_t value;
12493 +       uint64_t minimum;
12494 +       uint64_t maximum;
12495 +};
12496 +
12497 +#define CRLIM_UNSET            (0ULL)
12498 +#define CRLIM_INFINITY         (~0ULL)
12499 +#define CRLIM_KEEP             (~1ULL)
12500 +
12501 +#ifdef __KERNEL__
12502 +
12503 +#ifdef CONFIG_IA32_EMULATION
12504 +
12505 +struct vcmd_ctx_rlimit_v0_x32 {
12506 +       uint32_t id;
12507 +       uint64_t minimum;
12508 +       uint64_t softlimit;
12509 +       uint64_t maximum;
12510 +} __attribute__ ((packed));
12511 +
12512 +#endif /* CONFIG_IA32_EMULATION */
12513 +
12514 +#include <linux/compiler.h>
12515 +
12516 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12517 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12518 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12519 +extern int vc_reset_hits(struct vx_info *, void __user *);
12520 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12521 +
12522 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12523 +
12524 +#ifdef CONFIG_IA32_EMULATION
12525 +
12526 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12527 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12528 +
12529 +#endif /* CONFIG_IA32_EMULATION */
12530 +
12531 +#endif /* __KERNEL__ */
12532 +#endif /* _VX_LIMIT_CMD_H */
12533 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/limit_def.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit_def.h
12534 --- linux-3.5.4/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12535 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit_def.h     2012-07-23 01:45:55.000000000 +0200
12536 @@ -0,0 +1,47 @@
12537 +#ifndef _VX_LIMIT_DEF_H
12538 +#define _VX_LIMIT_DEF_H
12539 +
12540 +#include <asm/atomic.h>
12541 +#include <asm/resource.h>
12542 +
12543 +#include "limit.h"
12544 +
12545 +
12546 +struct _vx_res_limit {
12547 +       rlim_t soft;            /* Context soft limit */
12548 +       rlim_t hard;            /* Context hard limit */
12549 +
12550 +       rlim_atomic_t rcur;     /* Current value */
12551 +       rlim_t rmin;            /* Context minimum */
12552 +       rlim_t rmax;            /* Context maximum */
12553 +
12554 +       atomic_t lhit;          /* Limit hits */
12555 +};
12556 +
12557 +/* context sub struct */
12558 +
12559 +struct _vx_limit {
12560 +       struct _vx_res_limit res[NUM_LIMITS];
12561 +};
12562 +
12563 +#ifdef CONFIG_VSERVER_DEBUG
12564 +
12565 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12566 +{
12567 +       int i;
12568 +
12569 +       printk("\t_vx_limit:");
12570 +       for (i = 0; i < NUM_LIMITS; i++) {
12571 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12572 +                       i, (unsigned long)__rlim_get(limit, i),
12573 +                       (unsigned long)__rlim_rmin(limit, i),
12574 +                       (unsigned long)__rlim_rmax(limit, i),
12575 +                       (long)__rlim_soft(limit, i),
12576 +                       (long)__rlim_hard(limit, i),
12577 +                       atomic_read(&__rlim_lhit(limit, i)));
12578 +       }
12579 +}
12580 +
12581 +#endif
12582 +
12583 +#endif /* _VX_LIMIT_DEF_H */
12584 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/limit_int.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit_int.h
12585 --- linux-3.5.4/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12586 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/limit_int.h     2012-07-23 01:45:55.000000000 +0200
12587 @@ -0,0 +1,198 @@
12588 +#ifndef _VX_LIMIT_INT_H
12589 +#define _VX_LIMIT_INT_H
12590 +
12591 +#include "context.h"
12592 +
12593 +#ifdef __KERNEL__
12594 +
12595 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12596 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12597 +
12598 +extern const char *vlimit_name[NUM_LIMITS];
12599 +
12600 +static inline void __vx_acc_cres(struct vx_info *vxi,
12601 +       int res, int dir, void *_data, char *_file, int _line)
12602 +{
12603 +       if (VXD_RCRES_COND(res))
12604 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12605 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12606 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12607 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12608 +       if (!vxi)
12609 +               return;
12610 +
12611 +       if (dir > 0)
12612 +               __rlim_inc(&vxi->limit, res);
12613 +       else
12614 +               __rlim_dec(&vxi->limit, res);
12615 +}
12616 +
12617 +static inline void __vx_add_cres(struct vx_info *vxi,
12618 +       int res, int amount, void *_data, char *_file, int _line)
12619 +{
12620 +       if (VXD_RCRES_COND(res))
12621 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12622 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12623 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12624 +                       amount, _data, _file, _line);
12625 +       if (amount == 0)
12626 +               return;
12627 +       if (!vxi)
12628 +               return;
12629 +       __rlim_add(&vxi->limit, res, amount);
12630 +}
12631 +
12632 +static inline
12633 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12634 +{
12635 +       int cond = (value > __rlim_rmax(limit, res));
12636 +
12637 +       if (cond)
12638 +               __rlim_rmax(limit, res) = value;
12639 +       return cond;
12640 +}
12641 +
12642 +static inline
12643 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12644 +{
12645 +       int cond = (value < __rlim_rmin(limit, res));
12646 +
12647 +       if (cond)
12648 +               __rlim_rmin(limit, res) = value;
12649 +       return cond;
12650 +}
12651 +
12652 +static inline
12653 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12654 +{
12655 +       if (!__vx_cres_adjust_max(limit, res, value))
12656 +               __vx_cres_adjust_min(limit, res, value);
12657 +}
12658 +
12659 +
12660 +/*     return values:
12661 +        +1 ... no limit hit
12662 +        -1 ... over soft limit
12663 +         0 ... over hard limit         */
12664 +
12665 +static inline int __vx_cres_avail(struct vx_info *vxi,
12666 +       int res, int num, char *_file, int _line)
12667 +{
12668 +       struct _vx_limit *limit;
12669 +       rlim_t value;
12670 +
12671 +       if (VXD_RLIMIT_COND(res))
12672 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12673 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12674 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12675 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12676 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12677 +                       num, _file, _line);
12678 +       if (!vxi)
12679 +               return 1;
12680 +
12681 +       limit = &vxi->limit;
12682 +       value = __rlim_get(limit, res);
12683 +
12684 +       if (!__vx_cres_adjust_max(limit, res, value))
12685 +               __vx_cres_adjust_min(limit, res, value);
12686 +
12687 +       if (num == 0)
12688 +               return 1;
12689 +
12690 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12691 +               return -1;
12692 +       if (value + num <= __rlim_soft(limit, res))
12693 +               return -1;
12694 +
12695 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12696 +               return 1;
12697 +       if (value + num <= __rlim_hard(limit, res))
12698 +               return 1;
12699 +
12700 +       __rlim_hit(limit, res);
12701 +       return 0;
12702 +}
12703 +
12704 +
12705 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12706 +
12707 +static inline
12708 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12709 +{
12710 +       rlim_t value, sum = 0;
12711 +       int res;
12712 +
12713 +       while ((res = *array++)) {
12714 +               value = __rlim_get(limit, res);
12715 +               __vx_cres_fixup(limit, res, value);
12716 +               sum += value;
12717 +       }
12718 +       return sum;
12719 +}
12720 +
12721 +static inline
12722 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12723 +{
12724 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12725 +       int res = *array;
12726 +
12727 +       if (value == __rlim_get(limit, res))
12728 +               return value;
12729 +
12730 +       __rlim_set(limit, res, value);
12731 +       /* now adjust min/max */
12732 +       if (!__vx_cres_adjust_max(limit, res, value))
12733 +               __vx_cres_adjust_min(limit, res, value);
12734 +
12735 +       return value;
12736 +}
12737 +
12738 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12739 +       const int *array, int num, char *_file, int _line)
12740 +{
12741 +       struct _vx_limit *limit;
12742 +       rlim_t value = 0;
12743 +       int res;
12744 +
12745 +       if (num == 0)
12746 +               return 1;
12747 +       if (!vxi)
12748 +               return 1;
12749 +
12750 +       limit = &vxi->limit;
12751 +       res = *array;
12752 +       value = __vx_cres_array_sum(limit, array + 1);
12753 +
12754 +       __rlim_set(limit, res, value);
12755 +       __vx_cres_fixup(limit, res, value);
12756 +
12757 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12758 +}
12759 +
12760 +
12761 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12762 +{
12763 +       rlim_t value;
12764 +       int res;
12765 +
12766 +       /* complex resources first */
12767 +       if ((id < 0) || (id == RLIMIT_RSS))
12768 +               __vx_cres_array_fixup(limit, VLA_RSS);
12769 +
12770 +       for (res = 0; res < NUM_LIMITS; res++) {
12771 +               if ((id > 0) && (res != id))
12772 +                       continue;
12773 +
12774 +               value = __rlim_get(limit, res);
12775 +               __vx_cres_fixup(limit, res, value);
12776 +
12777 +               /* not supposed to happen, maybe warn? */
12778 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12779 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12780 +       }
12781 +}
12782 +
12783 +
12784 +#endif /* __KERNEL__ */
12785 +#endif /* _VX_LIMIT_INT_H */
12786 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/monitor.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/monitor.h
12787 --- linux-3.5.4/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12788 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/monitor.h       2012-07-23 01:45:55.000000000 +0200
12789 @@ -0,0 +1,96 @@
12790 +#ifndef _VX_MONITOR_H
12791 +#define _VX_MONITOR_H
12792 +
12793 +#include <linux/types.h>
12794 +
12795 +enum {
12796 +       VXM_UNUSED = 0,
12797 +
12798 +       VXM_SYNC = 0x10,
12799 +
12800 +       VXM_UPDATE = 0x20,
12801 +       VXM_UPDATE_1,
12802 +       VXM_UPDATE_2,
12803 +
12804 +       VXM_RQINFO_1 = 0x24,
12805 +       VXM_RQINFO_2,
12806 +
12807 +       VXM_ACTIVATE = 0x40,
12808 +       VXM_DEACTIVATE,
12809 +       VXM_IDLE,
12810 +
12811 +       VXM_HOLD = 0x44,
12812 +       VXM_UNHOLD,
12813 +
12814 +       VXM_MIGRATE = 0x48,
12815 +       VXM_RESCHED,
12816 +
12817 +       /* all other bits are flags */
12818 +       VXM_SCHED = 0x80,
12819 +};
12820 +
12821 +struct _vxm_update_1 {
12822 +       uint32_t tokens_max;
12823 +       uint32_t fill_rate;
12824 +       uint32_t interval;
12825 +};
12826 +
12827 +struct _vxm_update_2 {
12828 +       uint32_t tokens_min;
12829 +       uint32_t fill_rate;
12830 +       uint32_t interval;
12831 +};
12832 +
12833 +struct _vxm_rqinfo_1 {
12834 +       uint16_t running;
12835 +       uint16_t onhold;
12836 +       uint16_t iowait;
12837 +       uint16_t uintr;
12838 +       uint32_t idle_tokens;
12839 +};
12840 +
12841 +struct _vxm_rqinfo_2 {
12842 +       uint32_t norm_time;
12843 +       uint32_t idle_time;
12844 +       uint32_t idle_skip;
12845 +};
12846 +
12847 +struct _vxm_sched {
12848 +       uint32_t tokens;
12849 +       uint32_t norm_time;
12850 +       uint32_t idle_time;
12851 +};
12852 +
12853 +struct _vxm_task {
12854 +       uint16_t pid;
12855 +       uint16_t state;
12856 +};
12857 +
12858 +struct _vxm_event {
12859 +       uint32_t jif;
12860 +       union {
12861 +               uint32_t seq;
12862 +               uint32_t sec;
12863 +       };
12864 +       union {
12865 +               uint32_t tokens;
12866 +               uint32_t nsec;
12867 +               struct _vxm_task tsk;
12868 +       };
12869 +};
12870 +
12871 +struct _vx_mon_entry {
12872 +       uint16_t type;
12873 +       uint16_t xid;
12874 +       union {
12875 +               struct _vxm_event ev;
12876 +               struct _vxm_sched sd;
12877 +               struct _vxm_update_1 u1;
12878 +               struct _vxm_update_2 u2;
12879 +               struct _vxm_rqinfo_1 q1;
12880 +               struct _vxm_rqinfo_2 q2;
12881 +       };
12882 +};
12883 +
12884 +
12885 +#endif /* _VX_MONITOR_H */
12886 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/network.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/network.h
12887 --- linux-3.5.4/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
12888 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/network.h       2012-07-23 01:45:55.000000000 +0200
12889 @@ -0,0 +1,148 @@
12890 +#ifndef _VX_NETWORK_H
12891 +#define _VX_NETWORK_H
12892 +
12893 +#include <linux/types.h>
12894 +
12895 +
12896 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12897 +
12898 +
12899 +/* network flags */
12900 +
12901 +#define NXF_INFO_PRIVATE       0x00000008
12902 +
12903 +#define NXF_SINGLE_IP          0x00000100
12904 +#define NXF_LBACK_REMAP                0x00000200
12905 +#define NXF_LBACK_ALLOW                0x00000400
12906 +
12907 +#define NXF_HIDE_NETIF         0x02000000
12908 +#define NXF_HIDE_LBACK         0x04000000
12909 +
12910 +#define NXF_STATE_SETUP                (1ULL << 32)
12911 +#define NXF_STATE_ADMIN                (1ULL << 34)
12912 +
12913 +#define NXF_SC_HELPER          (1ULL << 36)
12914 +#define NXF_PERSISTENT         (1ULL << 38)
12915 +
12916 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12917 +
12918 +
12919 +#define        NXF_INIT_SET            (__nxf_init_set())
12920 +
12921 +static inline uint64_t __nxf_init_set(void) {
12922 +       return    NXF_STATE_ADMIN
12923 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12924 +               | NXF_LBACK_REMAP
12925 +               | NXF_HIDE_LBACK
12926 +#endif
12927 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12928 +               | NXF_SINGLE_IP
12929 +#endif
12930 +               | NXF_HIDE_NETIF;
12931 +}
12932 +
12933 +
12934 +/* network caps */
12935 +
12936 +#define NXC_TUN_CREATE         0x00000001
12937 +
12938 +#define NXC_RAW_ICMP           0x00000100
12939 +
12940 +#define NXC_MULTICAST          0x00001000
12941 +
12942 +
12943 +/* address types */
12944 +
12945 +#define NXA_TYPE_IPV4          0x0001
12946 +#define NXA_TYPE_IPV6          0x0002
12947 +
12948 +#define NXA_TYPE_NONE          0x0000
12949 +#define NXA_TYPE_ANY           0x00FF
12950 +
12951 +#define NXA_TYPE_ADDR          0x0010
12952 +#define NXA_TYPE_MASK          0x0020
12953 +#define NXA_TYPE_RANGE         0x0040
12954 +
12955 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12956 +
12957 +#define NXA_MOD_BCAST          0x0100
12958 +#define NXA_MOD_LBACK          0x0200
12959 +
12960 +#define NXA_LOOPBACK           0x1000
12961 +
12962 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12963 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12964 +
12965 +#ifdef __KERNEL__
12966 +
12967 +#include <linux/list.h>
12968 +#include <linux/spinlock.h>
12969 +#include <linux/rcupdate.h>
12970 +#include <linux/in.h>
12971 +#include <linux/in6.h>
12972 +#include <asm/atomic.h>
12973 +
12974 +struct nx_addr_v4 {
12975 +       struct nx_addr_v4 *next;
12976 +       struct in_addr ip[2];
12977 +       struct in_addr mask;
12978 +       uint16_t type;
12979 +       uint16_t flags;
12980 +};
12981 +
12982 +struct nx_addr_v6 {
12983 +       struct nx_addr_v6 *next;
12984 +       struct in6_addr ip;
12985 +       struct in6_addr mask;
12986 +       uint32_t prefix;
12987 +       uint16_t type;
12988 +       uint16_t flags;
12989 +};
12990 +
12991 +struct nx_info {
12992 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12993 +       nid_t nx_id;                    /* vnet id */
12994 +       atomic_t nx_usecnt;             /* usage count */
12995 +       atomic_t nx_tasks;              /* tasks count */
12996 +       int nx_state;                   /* context state */
12997 +
12998 +       uint64_t nx_flags;              /* network flag word */
12999 +       uint64_t nx_ncaps;              /* network capabilities */
13000 +
13001 +       struct in_addr v4_lback;        /* Loopback address */
13002 +       struct in_addr v4_bcast;        /* Broadcast address */
13003 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13004 +#ifdef CONFIG_IPV6
13005 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13006 +#endif
13007 +       char nx_name[65];               /* network context name */
13008 +};
13009 +
13010 +
13011 +/* status flags */
13012 +
13013 +#define NXS_HASHED      0x0001
13014 +#define NXS_SHUTDOWN    0x0100
13015 +#define NXS_RELEASED    0x8000
13016 +
13017 +extern struct nx_info *lookup_nx_info(int);
13018 +
13019 +extern int get_nid_list(int, unsigned int *, int);
13020 +extern int nid_is_hashed(nid_t);
13021 +
13022 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13023 +
13024 +extern long vs_net_change(struct nx_info *, unsigned int);
13025 +
13026 +struct sock;
13027 +
13028 +
13029 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13030 +#ifdef  CONFIG_IPV6
13031 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13032 +#else
13033 +#define NX_IPV6(n)     (0)
13034 +#endif
13035 +
13036 +#endif /* __KERNEL__ */
13037 +#endif /* _VX_NETWORK_H */
13038 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/network_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/network_cmd.h
13039 --- linux-3.5.4/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13040 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/network_cmd.h   2012-07-23 01:45:55.000000000 +0200
13041 @@ -0,0 +1,164 @@
13042 +#ifndef _VX_NETWORK_CMD_H
13043 +#define _VX_NETWORK_CMD_H
13044 +
13045 +
13046 +/* vinfo commands */
13047 +
13048 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13049 +
13050 +#ifdef __KERNEL__
13051 +extern int vc_task_nid(uint32_t);
13052 +
13053 +#endif /* __KERNEL__ */
13054 +
13055 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13056 +
13057 +struct vcmd_nx_info_v0 {
13058 +       uint32_t nid;
13059 +       /* more to come */
13060 +};
13061 +
13062 +#ifdef __KERNEL__
13063 +extern int vc_nx_info(struct nx_info *, void __user *);
13064 +
13065 +#endif /* __KERNEL__ */
13066 +
13067 +#include <linux/in.h>
13068 +#include <linux/in6.h>
13069 +
13070 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13071 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13072 +
13073 +struct  vcmd_net_create {
13074 +       uint64_t flagword;
13075 +};
13076 +
13077 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13078 +
13079 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13080 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13081 +
13082 +struct vcmd_net_addr_v0 {
13083 +       uint16_t type;
13084 +       uint16_t count;
13085 +       struct in_addr ip[4];
13086 +       struct in_addr mask[4];
13087 +};
13088 +
13089 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13090 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13091 +
13092 +struct vcmd_net_addr_ipv4_v1 {
13093 +       uint16_t type;
13094 +       uint16_t flags;
13095 +       struct in_addr ip;
13096 +       struct in_addr mask;
13097 +};
13098 +
13099 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13100 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13101 +
13102 +struct vcmd_net_addr_ipv4_v2 {
13103 +       uint16_t type;
13104 +       uint16_t flags;
13105 +       struct in_addr ip;
13106 +       struct in_addr ip2;
13107 +       struct in_addr mask;
13108 +};
13109 +
13110 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13111 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13112 +
13113 +struct vcmd_net_addr_ipv6_v1 {
13114 +       uint16_t type;
13115 +       uint16_t flags;
13116 +       uint32_t prefix;
13117 +       struct in6_addr ip;
13118 +       struct in6_addr mask;
13119 +};
13120 +
13121 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13122 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13123 +
13124 +struct vcmd_match_ipv4_v0 {
13125 +       uint16_t type;
13126 +       uint16_t flags;
13127 +       uint16_t parent;
13128 +       uint16_t prefix;
13129 +       struct in_addr ip;
13130 +       struct in_addr ip2;
13131 +       struct in_addr mask;
13132 +};
13133 +
13134 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13135 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13136 +
13137 +struct vcmd_match_ipv6_v0 {
13138 +       uint16_t type;
13139 +       uint16_t flags;
13140 +       uint16_t parent;
13141 +       uint16_t prefix;
13142 +       struct in6_addr ip;
13143 +       struct in6_addr ip2;
13144 +       struct in6_addr mask;
13145 +};
13146 +
13147 +
13148 +#ifdef __KERNEL__
13149 +extern int vc_net_create(uint32_t, void __user *);
13150 +extern int vc_net_migrate(struct nx_info *, void __user *);
13151 +
13152 +extern int vc_net_add(struct nx_info *, void __user *);
13153 +extern int vc_net_remove(struct nx_info *, void __user *);
13154 +
13155 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13156 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13157 +
13158 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13159 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13160 +
13161 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13162 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13163 +
13164 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13165 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13166 +
13167 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13168 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13169 +
13170 +#endif /* __KERNEL__ */
13171 +
13172 +
13173 +/* flag commands */
13174 +
13175 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13176 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13177 +
13178 +struct vcmd_net_flags_v0 {
13179 +       uint64_t flagword;
13180 +       uint64_t mask;
13181 +};
13182 +
13183 +#ifdef __KERNEL__
13184 +extern int vc_get_nflags(struct nx_info *, void __user *);
13185 +extern int vc_set_nflags(struct nx_info *, void __user *);
13186 +
13187 +#endif /* __KERNEL__ */
13188 +
13189 +
13190 +/* network caps commands */
13191 +
13192 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13193 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13194 +
13195 +struct vcmd_net_caps_v0 {
13196 +       uint64_t ncaps;
13197 +       uint64_t cmask;
13198 +};
13199 +
13200 +#ifdef __KERNEL__
13201 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13202 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13203 +
13204 +#endif /* __KERNEL__ */
13205 +#endif /* _VX_CONTEXT_CMD_H */
13206 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/percpu.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/percpu.h
13207 --- linux-3.5.4/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13208 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/percpu.h        2012-07-23 01:45:55.000000000 +0200
13209 @@ -0,0 +1,14 @@
13210 +#ifndef _VX_PERCPU_H
13211 +#define _VX_PERCPU_H
13212 +
13213 +#include "cvirt_def.h"
13214 +#include "sched_def.h"
13215 +
13216 +struct _vx_percpu {
13217 +       struct _vx_cvirt_pc cvirt;
13218 +       struct _vx_sched_pc sched;
13219 +};
13220 +
13221 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13222 +
13223 +#endif /* _VX_PERCPU_H */
13224 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/pid.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/pid.h
13225 --- linux-3.5.4/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13226 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/pid.h   2012-07-23 01:45:55.000000000 +0200
13227 @@ -0,0 +1,51 @@
13228 +#ifndef _VSERVER_PID_H
13229 +#define _VSERVER_PID_H
13230 +
13231 +/* pid faking stuff */
13232 +
13233 +#define vx_info_map_pid(v, p) \
13234 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13235 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13236 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13237 +#define vx_map_tgid(p) vx_map_pid(p)
13238 +
13239 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13240 +       const char *func, const char *file, int line)
13241 +{
13242 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13243 +               vxfprintk(VXD_CBIT(cvirt, 2),
13244 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13245 +                       vxi, (long long)vxi->vx_flags, pid,
13246 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13247 +                       func, file, line);
13248 +               if (pid == 0)
13249 +                       return 0;
13250 +               if (pid == vxi->vx_initpid)
13251 +                       return 1;
13252 +       }
13253 +       return pid;
13254 +}
13255 +
13256 +#define vx_info_rmap_pid(v, p) \
13257 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13258 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13259 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13260 +
13261 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13262 +       const char *func, const char *file, int line)
13263 +{
13264 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13265 +               vxfprintk(VXD_CBIT(cvirt, 2),
13266 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13267 +                       vxi, (long long)vxi->vx_flags, pid,
13268 +                       (pid == 1) ? vxi->vx_initpid : pid,
13269 +                       func, file, line);
13270 +               if ((pid == 1) && vxi->vx_initpid)
13271 +                       return vxi->vx_initpid;
13272 +               if (pid == vxi->vx_initpid)
13273 +                       return ~0U;
13274 +       }
13275 +       return pid;
13276 +}
13277 +
13278 +#endif
13279 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/sched.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/sched.h
13280 --- linux-3.5.4/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13281 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/sched.h 2012-07-23 01:45:55.000000000 +0200
13282 @@ -0,0 +1,23 @@
13283 +#ifndef _VX_SCHED_H
13284 +#define _VX_SCHED_H
13285 +
13286 +
13287 +#ifdef __KERNEL__
13288 +
13289 +struct timespec;
13290 +
13291 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13292 +
13293 +
13294 +struct vx_info;
13295 +
13296 +void vx_update_load(struct vx_info *);
13297 +
13298 +
13299 +void vx_update_sched_param(struct _vx_sched *sched,
13300 +       struct _vx_sched_pc *sched_pc);
13301 +
13302 +#endif /* __KERNEL__ */
13303 +#else  /* _VX_SCHED_H */
13304 +#warning duplicate inclusion
13305 +#endif /* _VX_SCHED_H */
13306 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/sched_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/sched_cmd.h
13307 --- linux-3.5.4/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13308 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/sched_cmd.h     2012-07-23 01:45:55.000000000 +0200
13309 @@ -0,0 +1,21 @@
13310 +#ifndef _VX_SCHED_CMD_H
13311 +#define _VX_SCHED_CMD_H
13312 +
13313 +
13314 +struct vcmd_prio_bias {
13315 +       int32_t cpu_id;
13316 +       int32_t prio_bias;
13317 +};
13318 +
13319 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13320 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13321 +
13322 +#ifdef __KERNEL__
13323 +
13324 +#include <linux/compiler.h>
13325 +
13326 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13327 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13328 +
13329 +#endif /* __KERNEL__ */
13330 +#endif /* _VX_SCHED_CMD_H */
13331 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/sched_def.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/sched_def.h
13332 --- linux-3.5.4/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13333 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/sched_def.h     2012-07-23 01:45:55.000000000 +0200
13334 @@ -0,0 +1,38 @@
13335 +#ifndef _VX_SCHED_DEF_H
13336 +#define _VX_SCHED_DEF_H
13337 +
13338 +#include <linux/spinlock.h>
13339 +#include <linux/jiffies.h>
13340 +#include <linux/cpumask.h>
13341 +#include <asm/atomic.h>
13342 +#include <asm/param.h>
13343 +
13344 +
13345 +/* context sub struct */
13346 +
13347 +struct _vx_sched {
13348 +       int prio_bias;                  /* bias offset for priority */
13349 +
13350 +       cpumask_t update;               /* CPUs which should update */
13351 +};
13352 +
13353 +struct _vx_sched_pc {
13354 +       int prio_bias;                  /* bias offset for priority */
13355 +
13356 +       uint64_t user_ticks;            /* token tick events */
13357 +       uint64_t sys_ticks;             /* token tick events */
13358 +       uint64_t hold_ticks;            /* token ticks paused */
13359 +};
13360 +
13361 +
13362 +#ifdef CONFIG_VSERVER_DEBUG
13363 +
13364 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13365 +{
13366 +       printk("\t_vx_sched:\n");
13367 +       printk("\t priority = %4d\n", sched->prio_bias);
13368 +}
13369 +
13370 +#endif
13371 +
13372 +#endif /* _VX_SCHED_DEF_H */
13373 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/signal.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/signal.h
13374 --- linux-3.5.4/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13375 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/signal.h        2012-07-23 01:45:55.000000000 +0200
13376 @@ -0,0 +1,14 @@
13377 +#ifndef _VX_SIGNAL_H
13378 +#define _VX_SIGNAL_H
13379 +
13380 +
13381 +#ifdef __KERNEL__
13382 +
13383 +struct vx_info;
13384 +
13385 +int vx_info_kill(struct vx_info *, int, int);
13386 +
13387 +#endif /* __KERNEL__ */
13388 +#else  /* _VX_SIGNAL_H */
13389 +#warning duplicate inclusion
13390 +#endif /* _VX_SIGNAL_H */
13391 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/signal_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/signal_cmd.h
13392 --- linux-3.5.4/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13393 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/signal_cmd.h    2012-07-23 01:45:55.000000000 +0200
13394 @@ -0,0 +1,43 @@
13395 +#ifndef _VX_SIGNAL_CMD_H
13396 +#define _VX_SIGNAL_CMD_H
13397 +
13398 +
13399 +/*  signalling vserver commands */
13400 +
13401 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13402 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13403 +
13404 +struct vcmd_ctx_kill_v0 {
13405 +       int32_t pid;
13406 +       int32_t sig;
13407 +};
13408 +
13409 +struct vcmd_wait_exit_v0 {
13410 +       int32_t reboot_cmd;
13411 +       int32_t exit_code;
13412 +};
13413 +
13414 +#ifdef __KERNEL__
13415 +
13416 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13417 +extern int vc_wait_exit(struct vx_info *, void __user *);
13418 +
13419 +#endif /* __KERNEL__ */
13420 +
13421 +/*  process alteration commands */
13422 +
13423 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13424 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13425 +
13426 +struct vcmd_pflags_v0 {
13427 +       uint32_t flagword;
13428 +       uint32_t mask;
13429 +};
13430 +
13431 +#ifdef __KERNEL__
13432 +
13433 +extern int vc_get_pflags(uint32_t pid, void __user *);
13434 +extern int vc_set_pflags(uint32_t pid, void __user *);
13435 +
13436 +#endif /* __KERNEL__ */
13437 +#endif /* _VX_SIGNAL_CMD_H */
13438 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/space.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/space.h
13439 --- linux-3.5.4/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13440 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/space.h 2012-07-23 01:45:55.000000000 +0200
13441 @@ -0,0 +1,12 @@
13442 +#ifndef _VX_SPACE_H
13443 +#define _VX_SPACE_H
13444 +
13445 +#include <linux/types.h>
13446 +
13447 +struct vx_info;
13448 +
13449 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13450 +
13451 +#else  /* _VX_SPACE_H */
13452 +#warning duplicate inclusion
13453 +#endif /* _VX_SPACE_H */
13454 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/space_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/space_cmd.h
13455 --- linux-3.5.4/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13456 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/space_cmd.h     2012-07-23 01:45:55.000000000 +0200
13457 @@ -0,0 +1,38 @@
13458 +#ifndef _VX_SPACE_CMD_H
13459 +#define _VX_SPACE_CMD_H
13460 +
13461 +
13462 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13463 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13464 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13465 +
13466 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13467 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13468 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13469 +
13470 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13471 +
13472 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13473 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13474 +
13475 +
13476 +struct vcmd_space_mask_v1 {
13477 +       uint64_t mask;
13478 +};
13479 +
13480 +struct vcmd_space_mask_v2 {
13481 +       uint64_t mask;
13482 +       uint32_t index;
13483 +};
13484 +
13485 +
13486 +#ifdef __KERNEL__
13487 +
13488 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13489 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13490 +extern int vc_enter_space(struct vx_info *, void __user *);
13491 +extern int vc_set_space(struct vx_info *, void __user *);
13492 +extern int vc_get_space_mask(void __user *, int);
13493 +
13494 +#endif /* __KERNEL__ */
13495 +#endif /* _VX_SPACE_CMD_H */
13496 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/switch.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/switch.h
13497 --- linux-3.5.4/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13498 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/switch.h        2012-07-23 01:45:55.000000000 +0200
13499 @@ -0,0 +1,98 @@
13500 +#ifndef _VX_SWITCH_H
13501 +#define _VX_SWITCH_H
13502 +
13503 +#include <linux/types.h>
13504 +
13505 +
13506 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13507 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13508 +#define VC_VERSION(c)          ((c) & 0xFFF)
13509 +
13510 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13511 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13512 +
13513 +/*
13514 +
13515 +  Syscall Matrix V2.8
13516 +
13517 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13518 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13519 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13520 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13521 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13522 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13523 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13524 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13525 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13526 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13527 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13528 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13529 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13530 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13531 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13532 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13533 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13534 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13535 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13536 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13537 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13538 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13539 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13540 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13541 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13542 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13543 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13544 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13545 +
13546 +*/
13547 +
13548 +#define VC_CAT_VERSION         0
13549 +
13550 +#define VC_CAT_VSETUP          1
13551 +#define VC_CAT_VHOST           2
13552 +
13553 +#define VC_CAT_DEVICE          6
13554 +
13555 +#define VC_CAT_VPROC           9
13556 +#define VC_CAT_PROCALT         10
13557 +#define VC_CAT_PROCMIG         11
13558 +#define VC_CAT_PROCTRL         12
13559 +
13560 +#define VC_CAT_SCHED           14
13561 +#define VC_CAT_MEMCTRL         20
13562 +
13563 +#define VC_CAT_VNET            25
13564 +#define VC_CAT_NETALT          26
13565 +#define VC_CAT_NETMIG          27
13566 +#define VC_CAT_NETCTRL         28
13567 +
13568 +#define VC_CAT_TAGMIG          35
13569 +#define VC_CAT_DLIMIT          36
13570 +#define VC_CAT_INODE           38
13571 +
13572 +#define VC_CAT_VSTAT           40
13573 +#define VC_CAT_VINFO           46
13574 +#define VC_CAT_EVENT           48
13575 +
13576 +#define VC_CAT_FLAGS           52
13577 +#define VC_CAT_VSPACE          54
13578 +#define VC_CAT_DEBUG           56
13579 +#define VC_CAT_RLIMIT          60
13580 +
13581 +#define VC_CAT_SYSTEST         61
13582 +#define VC_CAT_COMPAT          63
13583 +
13584 +/*  query version */
13585 +
13586 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13587 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13588 +
13589 +
13590 +#ifdef __KERNEL__
13591 +
13592 +#include <linux/errno.h>
13593 +
13594 +#endif /* __KERNEL__ */
13595 +
13596 +#endif /* _VX_SWITCH_H */
13597 +
13598 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/tag.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/tag.h
13599 --- linux-3.5.4/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13600 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/tag.h   2012-07-23 01:45:55.000000000 +0200
13601 @@ -0,0 +1,143 @@
13602 +#ifndef _DX_TAG_H
13603 +#define _DX_TAG_H
13604 +
13605 +#include <linux/types.h>
13606 +
13607 +
13608 +#define DX_TAG(in)     (IS_TAGGED(in))
13609 +
13610 +
13611 +#ifdef CONFIG_TAG_NFSD
13612 +#define DX_TAG_NFSD    1
13613 +#else
13614 +#define DX_TAG_NFSD    0
13615 +#endif
13616 +
13617 +
13618 +#ifdef CONFIG_TAGGING_NONE
13619 +
13620 +#define MAX_UID                0xFFFFFFFF
13621 +#define MAX_GID                0xFFFFFFFF
13622 +
13623 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13624 +
13625 +#define TAGINO_UID(cond, uid, tag)     (uid)
13626 +#define TAGINO_GID(cond, gid, tag)     (gid)
13627 +
13628 +#endif
13629 +
13630 +
13631 +#ifdef CONFIG_TAGGING_GID16
13632 +
13633 +#define MAX_UID                0xFFFFFFFF
13634 +#define MAX_GID                0x0000FFFF
13635 +
13636 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13637 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13638 +
13639 +#define TAGINO_UID(cond, uid, tag)     (uid)
13640 +#define TAGINO_GID(cond, gid, tag)     \
13641 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13642 +
13643 +#endif
13644 +
13645 +
13646 +#ifdef CONFIG_TAGGING_ID24
13647 +
13648 +#define MAX_UID                0x00FFFFFF
13649 +#define MAX_GID                0x00FFFFFF
13650 +
13651 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13652 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13653 +
13654 +#define TAGINO_UID(cond, uid, tag)     \
13655 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13656 +#define TAGINO_GID(cond, gid, tag)     \
13657 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13658 +
13659 +#endif
13660 +
13661 +
13662 +#ifdef CONFIG_TAGGING_UID16
13663 +
13664 +#define MAX_UID                0x0000FFFF
13665 +#define MAX_GID                0xFFFFFFFF
13666 +
13667 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13668 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13669 +
13670 +#define TAGINO_UID(cond, uid, tag)     \
13671 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13672 +#define TAGINO_GID(cond, gid, tag)     (gid)
13673 +
13674 +#endif
13675 +
13676 +
13677 +#ifdef CONFIG_TAGGING_INTERN
13678 +
13679 +#define MAX_UID                0xFFFFFFFF
13680 +#define MAX_GID                0xFFFFFFFF
13681 +
13682 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13683 +       ((cond) ? (tag) : 0)
13684 +
13685 +#define TAGINO_UID(cond, uid, tag)     (uid)
13686 +#define TAGINO_GID(cond, gid, tag)     (gid)
13687 +
13688 +#endif
13689 +
13690 +
13691 +#ifndef CONFIG_TAGGING_NONE
13692 +#define dx_current_fstag(sb)   \
13693 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13694 +#else
13695 +#define dx_current_fstag(sb)   (0)
13696 +#endif
13697 +
13698 +#ifndef CONFIG_TAGGING_INTERN
13699 +#define TAGINO_TAG(cond, tag)  (0)
13700 +#else
13701 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13702 +#endif
13703 +
13704 +#define INOTAG_UID(cond, uid, gid)     \
13705 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13706 +#define INOTAG_GID(cond, uid, gid)     \
13707 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13708 +
13709 +
13710 +static inline uid_t dx_map_uid(uid_t uid)
13711 +{
13712 +       if ((uid > MAX_UID) && (uid != -1))
13713 +               uid = -2;
13714 +       return (uid & MAX_UID);
13715 +}
13716 +
13717 +static inline gid_t dx_map_gid(gid_t gid)
13718 +{
13719 +       if ((gid > MAX_GID) && (gid != -1))
13720 +               gid = -2;
13721 +       return (gid & MAX_GID);
13722 +}
13723 +
13724 +struct peer_tag {
13725 +       int32_t xid;
13726 +       int32_t nid;
13727 +};
13728 +
13729 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13730 +
13731 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13732 +                unsigned long *flags);
13733 +
13734 +#ifdef CONFIG_PROPAGATE
13735 +
13736 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13737 +
13738 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13739 +
13740 +#else
13741 +#define dx_propagate_tag(n, i) do { } while (0)
13742 +#endif
13743 +
13744 +#endif /* _DX_TAG_H */
13745 diff -NurpP --minimal linux-3.5.4/include/linux/vserver/tag_cmd.h linux-3.5.4-vs2.3.4.3/include/linux/vserver/tag_cmd.h
13746 --- linux-3.5.4/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13747 +++ linux-3.5.4-vs2.3.4.3/include/linux/vserver/tag_cmd.h       2012-07-23 01:45:55.000000000 +0200
13748 @@ -0,0 +1,22 @@
13749 +#ifndef _VX_TAG_CMD_H
13750 +#define _VX_TAG_CMD_H
13751 +
13752 +
13753 +/* vinfo commands */
13754 +
13755 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13756 +
13757 +#ifdef __KERNEL__
13758 +extern int vc_task_tag(uint32_t);
13759 +
13760 +#endif /* __KERNEL__ */
13761 +
13762 +/* context commands */
13763 +
13764 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13765 +
13766 +#ifdef __KERNEL__
13767 +extern int vc_tag_migrate(uint32_t);
13768 +
13769 +#endif /* __KERNEL__ */
13770 +#endif /* _VX_TAG_CMD_H */
13771 diff -NurpP --minimal linux-3.5.4/include/net/addrconf.h linux-3.5.4-vs2.3.4.3/include/net/addrconf.h
13772 --- linux-3.5.4/include/net/addrconf.h  2012-07-22 23:39:46.000000000 +0200
13773 +++ linux-3.5.4-vs2.3.4.3/include/net/addrconf.h        2012-07-23 01:45:55.000000000 +0200
13774 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13775                                                struct net_device *dev,
13776                                                const struct in6_addr *daddr,
13777                                                unsigned int srcprefs,
13778 -                                              struct in6_addr *saddr);
13779 +                                              struct in6_addr *saddr,
13780 +                                              struct nx_info *nxi);
13781  extern int                     ipv6_get_lladdr(struct net_device *dev,
13782                                                 struct in6_addr *addr,
13783                                                 unsigned char banned_flags);
13784 diff -NurpP --minimal linux-3.5.4/include/net/af_unix.h linux-3.5.4-vs2.3.4.3/include/net/af_unix.h
13785 --- linux-3.5.4/include/net/af_unix.h   2012-07-22 23:39:46.000000000 +0200
13786 +++ linux-3.5.4-vs2.3.4.3/include/net/af_unix.h 2012-07-23 01:45:55.000000000 +0200
13787 @@ -4,6 +4,7 @@
13788  #include <linux/socket.h>
13789  #include <linux/un.h>
13790  #include <linux/mutex.h>
13791 +#include <linux/vs_base.h>
13792  #include <net/sock.h>
13793  
13794  extern void unix_inflight(struct file *fp);
13795 diff -NurpP --minimal linux-3.5.4/include/net/inet_timewait_sock.h linux-3.5.4-vs2.3.4.3/include/net/inet_timewait_sock.h
13796 --- linux-3.5.4/include/net/inet_timewait_sock.h        2012-03-19 19:47:29.000000000 +0100
13797 +++ linux-3.5.4-vs2.3.4.3/include/net/inet_timewait_sock.h      2012-07-23 01:45:55.000000000 +0200
13798 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13799  #define tw_net                 __tw_common.skc_net
13800  #define tw_daddr               __tw_common.skc_daddr
13801  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13802 +#define tw_xid                 __tw_common.skc_xid
13803 +#define tw_vx_info             __tw_common.skc_vx_info
13804 +#define tw_nid                 __tw_common.skc_nid
13805 +#define tw_nx_info             __tw_common.skc_nx_info
13806         int                     tw_timeout;
13807         volatile unsigned char  tw_substate;
13808         unsigned char           tw_rcv_wscale;
13809 diff -NurpP --minimal linux-3.5.4/include/net/ip6_route.h linux-3.5.4-vs2.3.4.3/include/net/ip6_route.h
13810 --- linux-3.5.4/include/net/ip6_route.h 2012-07-22 23:39:46.000000000 +0200
13811 +++ linux-3.5.4-vs2.3.4.3/include/net/ip6_route.h       2012-07-23 01:45:55.000000000 +0200
13812 @@ -88,7 +88,8 @@ extern int                    ip6_route_get_saddr(struct 
13813                                                     struct rt6_info *rt,
13814                                                     const struct in6_addr *daddr,
13815                                                     unsigned int prefs,
13816 -                                                   struct in6_addr *saddr);
13817 +                                                   struct in6_addr *saddr,
13818 +                                                   struct nx_info *nxi);
13819  
13820  extern struct rt6_info         *rt6_lookup(struct net *net,
13821                                             const struct in6_addr *daddr,
13822 diff -NurpP --minimal linux-3.5.4/include/net/route.h linux-3.5.4-vs2.3.4.3/include/net/route.h
13823 --- linux-3.5.4/include/net/route.h     2012-07-22 23:39:46.000000000 +0200
13824 +++ linux-3.5.4-vs2.3.4.3/include/net/route.h   2012-07-23 01:45:55.000000000 +0200
13825 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13826                 dst_release(&rt->dst);
13827  }
13828  
13829 +#include <linux/vs_base.h>
13830 +#include <linux/vs_inet.h>
13831 +
13832  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13833  
13834  extern const __u8 ip_tos2prio[16];
13835 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13836                            protocol, flow_flags, dst, src, dport, sport);
13837  }
13838  
13839 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13840 +       struct flowi4 *);
13841 +
13842  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13843                                               __be32 dst, __be32 src, u32 tos,
13844                                               int oif, u8 protocol,
13845 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13846  {
13847         struct net *net = sock_net(sk);
13848         struct rtable *rt;
13849 +       struct nx_info *nx_info = current_nx_info();
13850  
13851         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13852                               sport, dport, sk, can_sleep);
13853  
13854 -       if (!dst || !src) {
13855 +       if (sk)
13856 +               nx_info = sk->sk_nx_info;
13857 +
13858 +       vxdprintk(VXD_CBIT(net, 4),
13859 +               "ip_route_connect(%p) %p,%p;%lx",
13860 +               sk, nx_info, sk->sk_socket,
13861 +               (sk->sk_socket?sk->sk_socket->flags:0));
13862 +
13863 +       rt = ip_v4_find_src(net, nx_info, fl4);
13864 +       if (IS_ERR(rt))
13865 +               return rt;
13866 +       ip_rt_put(rt);
13867 +
13868 +       if (!fl4->daddr || !fl4->saddr) {
13869                 rt = __ip_route_output_key(net, fl4);
13870                 if (IS_ERR(rt))
13871                         return rt;
13872 diff -NurpP --minimal linux-3.5.4/include/net/sock.h linux-3.5.4-vs2.3.4.3/include/net/sock.h
13873 --- linux-3.5.4/include/net/sock.h      2012-07-22 23:39:46.000000000 +0200
13874 +++ linux-3.5.4-vs2.3.4.3/include/net/sock.h    2012-07-23 01:45:55.000000000 +0200
13875 @@ -171,6 +171,10 @@ struct sock_common {
13876  #ifdef CONFIG_NET_NS
13877         struct net              *skc_net;
13878  #endif
13879 +       xid_t                   skc_xid;
13880 +       struct vx_info          *skc_vx_info;
13881 +       nid_t                   skc_nid;
13882 +       struct nx_info          *skc_nx_info;
13883         /*
13884          * fields between dontcopy_begin/dontcopy_end
13885          * are not copied in sock_copy()
13886 @@ -282,6 +286,10 @@ struct sock {
13887  #define sk_bind_node           __sk_common.skc_bind_node
13888  #define sk_prot                        __sk_common.skc_prot
13889  #define sk_net                 __sk_common.skc_net
13890 +#define sk_xid                 __sk_common.skc_xid
13891 +#define sk_vx_info             __sk_common.skc_vx_info
13892 +#define sk_nid                 __sk_common.skc_nid
13893 +#define sk_nx_info             __sk_common.skc_nx_info
13894         socket_lock_t           sk_lock;
13895         struct sk_buff_head     sk_receive_queue;
13896         /*
13897 diff -NurpP --minimal linux-3.5.4/init/Kconfig linux-3.5.4-vs2.3.4.3/init/Kconfig
13898 --- linux-3.5.4/init/Kconfig    2012-07-22 23:39:46.000000000 +0200
13899 +++ linux-3.5.4-vs2.3.4.3/init/Kconfig  2012-07-23 01:54:21.000000000 +0200
13900 @@ -624,6 +624,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13901  menuconfig CGROUPS
13902         boolean "Control Group support"
13903         depends on EVENTFD
13904 +       default y
13905         help
13906           This option adds support for grouping sets of processes together, for
13907           use with process control subsystems such as Cpusets, CFS, memory
13908 @@ -874,6 +875,7 @@ config USER_NS
13909         bool "User namespace (EXPERIMENTAL)"
13910         depends on EXPERIMENTAL
13911         depends on UIDGID_CONVERTED
13912 +       depends on VSERVER_DISABLED
13913         select UIDGID_STRICT_TYPE_CHECKS
13914  
13915         default n
13916 diff -NurpP --minimal linux-3.5.4/init/main.c linux-3.5.4-vs2.3.4.3/init/main.c
13917 --- linux-3.5.4/init/main.c     2012-07-22 23:39:46.000000000 +0200
13918 +++ linux-3.5.4-vs2.3.4.3/init/main.c   2012-07-23 01:45:55.000000000 +0200
13919 @@ -68,6 +68,7 @@
13920  #include <linux/shmem_fs.h>
13921  #include <linux/slab.h>
13922  #include <linux/perf_event.h>
13923 +#include <linux/vserver/percpu.h>
13924  
13925  #include <asm/io.h>
13926  #include <asm/bugs.h>
13927 diff -NurpP --minimal linux-3.5.4/ipc/mqueue.c linux-3.5.4-vs2.3.4.3/ipc/mqueue.c
13928 --- linux-3.5.4/ipc/mqueue.c    2012-07-22 23:39:46.000000000 +0200
13929 +++ linux-3.5.4-vs2.3.4.3/ipc/mqueue.c  2012-07-23 01:56:45.000000000 +0200
13930 @@ -35,6 +35,8 @@
13931  #include <linux/ipc_namespace.h>
13932  #include <linux/user_namespace.h>
13933  #include <linux/slab.h>
13934 +#include <linux/vs_context.h>
13935 +#include <linux/vs_limit.h>
13936  
13937  #include <net/sock.h>
13938  #include "util.h"
13939 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13940         struct pid* notify_owner;
13941         struct user_namespace *notify_user_ns;
13942         struct user_struct *user;       /* user who created, for accounting */
13943 +       struct vx_info *vxi;
13944         struct sock *notify_sock;
13945         struct sk_buff *notify_cookie;
13946  
13947 @@ -235,6 +238,7 @@ static struct inode *mqueue_get_inode(st
13948         if (S_ISREG(mode)) {
13949                 struct mqueue_inode_info *info;
13950                 unsigned long mq_bytes, mq_treesize;
13951 +               struct vx_info *vxi = current_vx_info();
13952  
13953                 inode->i_fop = &mqueue_file_operations;
13954                 inode->i_size = FILENT_SIZE;
13955 @@ -248,6 +252,7 @@ static struct inode *mqueue_get_inode(st
13956                 info->notify_user_ns = NULL;
13957                 info->qsize = 0;
13958                 info->user = NULL;      /* set when all is ok */
13959 +               info->vxi = NULL;
13960                 info->msg_tree = RB_ROOT;
13961                 info->node_cache = NULL;
13962                 memset(&info->attr, 0, sizeof(info->attr));
13963 @@ -281,17 +286,20 @@ static struct inode *mqueue_get_inode(st
13964  
13965                 spin_lock(&mq_lock);
13966                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13967 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13968 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13969 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13970                         spin_unlock(&mq_lock);
13971                         /* mqueue_evict_inode() releases info->messages */
13972                         ret = -EMFILE;
13973                         goto out_inode;
13974                 }
13975                 u->mq_bytes += mq_bytes;
13976 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13977                 spin_unlock(&mq_lock);
13978  
13979                 /* all is ok */
13980                 info->user = get_uid(u);
13981 +               info->vxi = get_vx_info(vxi);
13982         } else if (S_ISDIR(mode)) {
13983                 inc_nlink(inode);
13984                 /* Some things misbehave if size == 0 on a directory */
13985 @@ -395,8 +403,11 @@ static void mqueue_evict_inode(struct in
13986  
13987         user = info->user;
13988         if (user) {
13989 +               struct vx_info *vxi = info->vxi;
13990 +
13991                 spin_lock(&mq_lock);
13992                 user->mq_bytes -= mq_bytes;
13993 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13994                 /*
13995                  * get_ns_from_inode() ensures that the
13996                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13997 @@ -406,6 +417,7 @@ static void mqueue_evict_inode(struct in
13998                 if (ipc_ns)
13999                         ipc_ns->mq_queues_count--;
14000                 spin_unlock(&mq_lock);
14001 +               put_vx_info(vxi);
14002                 free_uid(user);
14003         }
14004         if (ipc_ns)
14005 diff -NurpP --minimal linux-3.5.4/ipc/msg.c linux-3.5.4-vs2.3.4.3/ipc/msg.c
14006 --- linux-3.5.4/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
14007 +++ linux-3.5.4-vs2.3.4.3/ipc/msg.c     2012-07-23 01:45:55.000000000 +0200
14008 @@ -37,6 +37,7 @@
14009  #include <linux/rwsem.h>
14010  #include <linux/nsproxy.h>
14011  #include <linux/ipc_namespace.h>
14012 +#include <linux/vs_base.h>
14013  
14014  #include <asm/current.h>
14015  #include <asm/uaccess.h>
14016 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14017  
14018         msq->q_perm.mode = msgflg & S_IRWXUGO;
14019         msq->q_perm.key = key;
14020 +       msq->q_perm.xid = vx_current_xid();
14021  
14022         msq->q_perm.security = NULL;
14023         retval = security_msg_queue_alloc(msq);
14024 diff -NurpP --minimal linux-3.5.4/ipc/namespace.c linux-3.5.4-vs2.3.4.3/ipc/namespace.c
14025 --- linux-3.5.4/ipc/namespace.c 2012-07-22 23:39:46.000000000 +0200
14026 +++ linux-3.5.4-vs2.3.4.3/ipc/namespace.c       2012-07-23 03:31:37.000000000 +0200
14027 @@ -13,11 +13,12 @@
14028  #include <linux/mount.h>
14029  #include <linux/user_namespace.h>
14030  #include <linux/proc_fs.h>
14031 +#include <linux/vs_base.h>
14032 +#include <linux/vserver/global.h>
14033  
14034  #include "util.h"
14035  
14036 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14037 -                                          struct ipc_namespace *old_ns)
14038 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14039  {
14040         struct ipc_namespace *ns;
14041         int err;
14042 @@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
14043         ipcns_notify(IPCNS_CREATED);
14044         register_ipcns_notifier(ns);
14045  
14046 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14047 +       // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14048 +       ns->user_ns = get_user_ns(user_ns);
14049  
14050         return ns;
14051  }
14052  
14053  struct ipc_namespace *copy_ipcs(unsigned long flags,
14054 -                               struct task_struct *tsk)
14055 +                               struct ipc_namespace *old_ns,
14056 +                               struct user_namespace *user_ns)
14057  {
14058 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14059 -
14060         if (!(flags & CLONE_NEWIPC))
14061 -               return get_ipc_ns(ns);
14062 -       return create_ipc_ns(tsk, ns);
14063 +               return get_ipc_ns(old_ns);
14064 +       return create_ipc_ns(user_ns);
14065  }
14066  
14067  /*
14068 diff -NurpP --minimal linux-3.5.4/ipc/sem.c linux-3.5.4-vs2.3.4.3/ipc/sem.c
14069 --- linux-3.5.4/ipc/sem.c       2012-01-09 16:14:59.000000000 +0100
14070 +++ linux-3.5.4-vs2.3.4.3/ipc/sem.c     2012-07-23 01:45:55.000000000 +0200
14071 @@ -86,6 +86,8 @@
14072  #include <linux/rwsem.h>
14073  #include <linux/nsproxy.h>
14074  #include <linux/ipc_namespace.h>
14075 +#include <linux/vs_base.h>
14076 +#include <linux/vs_limit.h>
14077  
14078  #include <asm/uaccess.h>
14079  #include "util.h"
14080 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14081  
14082         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14083         sma->sem_perm.key = key;
14084 +       sma->sem_perm.xid = vx_current_xid();
14085  
14086         sma->sem_perm.security = NULL;
14087         retval = security_sem_alloc(sma);
14088 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14089                 return id;
14090         }
14091         ns->used_sems += nsems;
14092 +       /* FIXME: obsoleted? */
14093 +       vx_semary_inc(sma);
14094 +       vx_nsems_add(sma, nsems);
14095  
14096         sma->sem_base = (struct sem *) &sma[1];
14097  
14098 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14099  
14100         wake_up_sem_queue_do(&tasks);
14101         ns->used_sems -= sma->sem_nsems;
14102 +       /* FIXME: obsoleted? */
14103 +       vx_nsems_sub(sma, sma->sem_nsems);
14104 +       vx_semary_dec(sma);
14105         security_sem_free(sma);
14106         ipc_rcu_putref(sma);
14107  }
14108 diff -NurpP --minimal linux-3.5.4/ipc/shm.c linux-3.5.4-vs2.3.4.3/ipc/shm.c
14109 --- linux-3.5.4/ipc/shm.c       2012-07-22 23:39:46.000000000 +0200
14110 +++ linux-3.5.4-vs2.3.4.3/ipc/shm.c     2012-07-23 01:45:55.000000000 +0200
14111 @@ -39,6 +39,8 @@
14112  #include <linux/nsproxy.h>
14113  #include <linux/mount.h>
14114  #include <linux/ipc_namespace.h>
14115 +#include <linux/vs_context.h>
14116 +#include <linux/vs_limit.h>
14117  
14118  #include <asm/uaccess.h>
14119  
14120 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14121   */
14122  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14123  {
14124 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14125 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14126 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14127 +
14128 +       vx_ipcshm_sub(vxi, shp, numpages);
14129 +       ns->shm_tot -= numpages;
14130 +
14131         shm_rmid(ns, shp);
14132         shm_unlock(shp);
14133         if (!is_file_hugepages(shp->shm_file))
14134 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14135                                                 shp->mlock_user);
14136         fput (shp->shm_file);
14137         security_shm_free(shp);
14138 +       put_vx_info(vxi);
14139         ipc_rcu_putref(shp);
14140  }
14141  
14142 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
14143         if (ns->shm_tot + numpages > ns->shm_ctlall)
14144                 return -ENOSPC;
14145  
14146 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14147 +               return -ENOSPC;
14148 +
14149         shp = ipc_rcu_alloc(sizeof(*shp));
14150         if (!shp)
14151                 return -ENOMEM;
14152  
14153         shp->shm_perm.key = key;
14154 +       shp->shm_perm.xid = vx_current_xid();
14155         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14156         shp->mlock_user = NULL;
14157  
14158 @@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
14159         ns->shm_tot += numpages;
14160         error = shp->shm_perm.id;
14161         shm_unlock(shp);
14162 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14163         return error;
14164  
14165  no_id:
14166 diff -NurpP --minimal linux-3.5.4/kernel/Makefile linux-3.5.4-vs2.3.4.3/kernel/Makefile
14167 --- linux-3.5.4/kernel/Makefile 2012-07-22 23:39:46.000000000 +0200
14168 +++ linux-3.5.4-vs2.3.4.3/kernel/Makefile       2012-07-23 10:20:32.000000000 +0200
14169 @@ -24,6 +24,7 @@ endif
14170  
14171  obj-y += sched/
14172  obj-y += power/
14173 +obj-y += vserver/
14174  
14175  ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
14176  obj-$(CONFIG_X86) += kcmp.o
14177 diff -NurpP --minimal linux-3.5.4/kernel/auditsc.c linux-3.5.4-vs2.3.4.3/kernel/auditsc.c
14178 --- linux-3.5.4/kernel/auditsc.c        2012-07-22 23:39:46.000000000 +0200
14179 +++ linux-3.5.4-vs2.3.4.3/kernel/auditsc.c      2012-07-23 01:45:55.000000000 +0200
14180 @@ -2309,7 +2309,7 @@ int audit_set_loginuid(uid_t loginuid)
14181         if (task->loginuid != -1)
14182                 return -EPERM;
14183  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14184 -       if (!capable(CAP_AUDIT_CONTROL))
14185 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14186                 return -EPERM;
14187  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14188  
14189 diff -NurpP --minimal linux-3.5.4/kernel/capability.c linux-3.5.4-vs2.3.4.3/kernel/capability.c
14190 --- linux-3.5.4/kernel/capability.c     2012-07-22 23:39:46.000000000 +0200
14191 +++ linux-3.5.4-vs2.3.4.3/kernel/capability.c   2012-07-23 01:45:55.000000000 +0200
14192 @@ -15,6 +15,7 @@
14193  #include <linux/syscalls.h>
14194  #include <linux/pid_namespace.h>
14195  #include <linux/user_namespace.h>
14196 +#include <linux/vs_context.h>
14197  #include <asm/uaccess.h>
14198  
14199  /*
14200 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14201         return 0;
14202  }
14203  
14204 +
14205  /*
14206   * The only thing that can change the capabilities of the current
14207   * process is the current process. As such, we can't be in this code
14208 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14209         return (ret == 0);
14210  }
14211  
14212 +#include <linux/vserver/base.h>
14213 +
14214  /**
14215   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14216   * initial user ns
14217 diff -NurpP --minimal linux-3.5.4/kernel/compat.c linux-3.5.4-vs2.3.4.3/kernel/compat.c
14218 --- linux-3.5.4/kernel/compat.c 2012-07-22 23:39:46.000000000 +0200
14219 +++ linux-3.5.4-vs2.3.4.3/kernel/compat.c       2012-07-23 01:45:55.000000000 +0200
14220 @@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14221         if (err)
14222                 return err;
14223  
14224 -       do_settimeofday(&tv);
14225 +       vx_settimeofday(&tv);
14226         return 0;
14227  }
14228  
14229 diff -NurpP --minimal linux-3.5.4/kernel/cred.c linux-3.5.4-vs2.3.4.3/kernel/cred.c
14230 --- linux-3.5.4/kernel/cred.c   2012-07-22 23:39:46.000000000 +0200
14231 +++ linux-3.5.4-vs2.3.4.3/kernel/cred.c 2012-07-23 01:45:55.000000000 +0200
14232 @@ -70,31 +70,6 @@ struct cred init_cred = {
14233  #endif
14234  };
14235  
14236 -static inline void set_cred_subscribers(struct cred *cred, int n)
14237 -{
14238 -#ifdef CONFIG_DEBUG_CREDENTIALS
14239 -       atomic_set(&cred->subscribers, n);
14240 -#endif
14241 -}
14242 -
14243 -static inline int read_cred_subscribers(const struct cred *cred)
14244 -{
14245 -#ifdef CONFIG_DEBUG_CREDENTIALS
14246 -       return atomic_read(&cred->subscribers);
14247 -#else
14248 -       return 0;
14249 -#endif
14250 -}
14251 -
14252 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14253 -{
14254 -#ifdef CONFIG_DEBUG_CREDENTIALS
14255 -       struct cred *cred = (struct cred *) _cred;
14256 -
14257 -       atomic_add(n, &cred->subscribers);
14258 -#endif
14259 -}
14260 -
14261  /*
14262   * Dispose of the shared task group credentials
14263   */
14264 @@ -284,21 +259,16 @@ error:
14265   *
14266   * Call commit_creds() or abort_creds() to clean up.
14267   */
14268 -struct cred *prepare_creds(void)
14269 +struct cred *__prepare_creds(const struct cred *old)
14270  {
14271 -       struct task_struct *task = current;
14272 -       const struct cred *old;
14273         struct cred *new;
14274  
14275 -       validate_process_creds();
14276 -
14277         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14278         if (!new)
14279                 return NULL;
14280  
14281         kdebug("prepare_creds() alloc %p", new);
14282  
14283 -       old = task->cred;
14284         memcpy(new, old, sizeof(struct cred));
14285  
14286         atomic_set(&new->usage, 1);
14287 @@ -326,6 +296,13 @@ error:
14288         abort_creds(new);
14289         return NULL;
14290  }
14291 +
14292 +struct cred *prepare_creds(void)
14293 +{
14294 +       validate_process_creds();
14295 +
14296 +       return __prepare_creds(current->cred);
14297 +}
14298  EXPORT_SYMBOL(prepare_creds);
14299  
14300  /*
14301 diff -NurpP --minimal linux-3.5.4/kernel/exit.c linux-3.5.4-vs2.3.4.3/kernel/exit.c
14302 --- linux-3.5.4/kernel/exit.c   2012-09-16 20:46:31.000000000 +0200
14303 +++ linux-3.5.4-vs2.3.4.3/kernel/exit.c 2012-08-11 15:15:02.000000000 +0200
14304 @@ -48,6 +48,10 @@
14305  #include <linux/fs_struct.h>
14306  #include <linux/init_task.h>
14307  #include <linux/perf_event.h>
14308 +#include <linux/vs_limit.h>
14309 +#include <linux/vs_context.h>
14310 +#include <linux/vs_network.h>
14311 +#include <linux/vs_pid.h>
14312  #include <trace/events/sched.h>
14313  #include <linux/hw_breakpoint.h>
14314  #include <linux/oom.h>
14315 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14316                                         filp_close(file, files);
14317                                         cond_resched();
14318                                 }
14319 +                               vx_openfd_dec(i);
14320                         }
14321                         i++;
14322                         set >>= 1;
14323 +                       cond_resched();
14324                 }
14325         }
14326  }
14327 @@ -1020,6 +1026,9 @@ void do_exit(long code)
14328          */
14329         ptrace_put_breakpoints(tsk);
14330  
14331 +       /* needs to stay before exit_notify() */
14332 +       exit_vx_info_early(tsk, code);
14333 +
14334         exit_notify(tsk, group_dead);
14335  #ifdef CONFIG_NUMA
14336         task_lock(tsk);
14337 @@ -1070,10 +1079,15 @@ void do_exit(long code)
14338         smp_mb();
14339         raw_spin_unlock_wait(&tsk->pi_lock);
14340  
14341 +       /* needs to stay after exit_notify() */
14342 +       exit_vx_info(tsk, code);
14343 +       exit_nx_info(tsk);
14344 +
14345         /* causes final put_task_struct in finish_task_switch(). */
14346         tsk->state = TASK_DEAD;
14347         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14348         schedule();
14349 +       printk("bad task: %p [%lx]\n", current, current->state);
14350         BUG();
14351         /* Avoid "noreturn function does return".  */
14352         for (;;)
14353 diff -NurpP --minimal linux-3.5.4/kernel/fork.c linux-3.5.4-vs2.3.4.3/kernel/fork.c
14354 --- linux-3.5.4/kernel/fork.c   2012-09-16 20:46:31.000000000 +0200
14355 +++ linux-3.5.4-vs2.3.4.3/kernel/fork.c 2012-09-16 20:50:19.000000000 +0200
14356 @@ -70,6 +70,9 @@
14357  #include <linux/khugepaged.h>
14358  #include <linux/signalfd.h>
14359  #include <linux/uprobes.h>
14360 +#include <linux/vs_context.h>
14361 +#include <linux/vs_network.h>
14362 +#include <linux/vs_limit.h>
14363  
14364  #include <asm/pgtable.h>
14365  #include <asm/pgalloc.h>
14366 @@ -207,6 +210,8 @@ void free_task(struct task_struct *tsk)
14367         account_kernel_stack(tsk->stack, -1);
14368         free_thread_info(tsk->stack);
14369         rt_mutex_debug_task_free(tsk);
14370 +       clr_vx_info(&tsk->vx_info);
14371 +       clr_nx_info(&tsk->nx_info);
14372         ftrace_graph_exit_task(tsk);
14373         put_seccomp_filter(tsk);
14374         free_task_struct(tsk);
14375 @@ -545,6 +550,7 @@ static struct mm_struct *mm_init(struct 
14376         if (likely(!mm_alloc_pgd(mm))) {
14377                 mm->def_flags = 0;
14378                 mmu_notifier_mm_init(mm);
14379 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14380                 return mm;
14381         }
14382  
14383 @@ -597,6 +603,7 @@ void __mmdrop(struct mm_struct *mm)
14384         destroy_context(mm);
14385         mmu_notifier_mm_destroy(mm);
14386         check_mm(mm);
14387 +       clr_vx_info(&mm->mm_vx_info);
14388         free_mm(mm);
14389  }
14390  EXPORT_SYMBOL_GPL(__mmdrop);
14391 @@ -838,6 +845,7 @@ struct mm_struct *dup_mm(struct task_str
14392                 goto fail_nomem;
14393  
14394         memcpy(mm, oldmm, sizeof(*mm));
14395 +       mm->mm_vx_info = NULL;
14396         mm_init_cpumask(mm);
14397  
14398  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14399 @@ -878,6 +886,7 @@ fail_nocontext:
14400          * If init_new_context() failed, we cannot use mmput() to free the mm
14401          * because it calls destroy_context()
14402          */
14403 +       clr_vx_info(&mm->mm_vx_info);
14404         mm_free_pgd(mm);
14405         free_mm(mm);
14406         return NULL;
14407 @@ -1161,6 +1170,8 @@ static struct task_struct *copy_process(
14408         int retval;
14409         struct task_struct *p;
14410         int cgroup_callbacks_done = 0;
14411 +       struct vx_info *vxi;
14412 +       struct nx_info *nxi;
14413  
14414         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14415                 return ERR_PTR(-EINVAL);
14416 @@ -1208,7 +1219,12 @@ static struct task_struct *copy_process(
14417         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14418         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14419  #endif
14420 +       init_vx_info(&p->vx_info, current_vx_info());
14421 +       init_nx_info(&p->nx_info, current_nx_info());
14422 +
14423         retval = -EAGAIN;
14424 +       if (!vx_nproc_avail(1))
14425 +               goto bad_fork_free;
14426         if (atomic_read(&p->real_cred->user->processes) >=
14427                         task_rlimit(p, RLIMIT_NPROC)) {
14428                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14429 @@ -1487,6 +1503,18 @@ static struct task_struct *copy_process(
14430  
14431         total_forks++;
14432         spin_unlock(&current->sighand->siglock);
14433 +
14434 +       /* p is copy of current */
14435 +       vxi = p->vx_info;
14436 +       if (vxi) {
14437 +               claim_vx_info(vxi, p);
14438 +               atomic_inc(&vxi->cvirt.nr_threads);
14439 +               atomic_inc(&vxi->cvirt.total_forks);
14440 +               vx_nproc_inc(p);
14441 +       }
14442 +       nxi = p->nx_info;
14443 +       if (nxi)
14444 +               claim_nx_info(nxi, p);
14445         write_unlock_irq(&tasklist_lock);
14446         proc_fork_connector(p);
14447         cgroup_post_fork(p);
14448 diff -NurpP --minimal linux-3.5.4/kernel/kthread.c linux-3.5.4-vs2.3.4.3/kernel/kthread.c
14449 --- linux-3.5.4/kernel/kthread.c        2012-03-19 19:47:30.000000000 +0100
14450 +++ linux-3.5.4-vs2.3.4.3/kernel/kthread.c      2012-07-23 01:45:55.000000000 +0200
14451 @@ -16,6 +16,7 @@
14452  #include <linux/mutex.h>
14453  #include <linux/slab.h>
14454  #include <linux/freezer.h>
14455 +#include <linux/vs_pid.h>
14456  #include <trace/events/sched.h>
14457  
14458  static DEFINE_SPINLOCK(kthread_create_lock);
14459 diff -NurpP --minimal linux-3.5.4/kernel/nsproxy.c linux-3.5.4-vs2.3.4.3/kernel/nsproxy.c
14460 --- linux-3.5.4/kernel/nsproxy.c        2012-01-09 16:15:00.000000000 +0100
14461 +++ linux-3.5.4-vs2.3.4.3/kernel/nsproxy.c      2012-07-23 10:58:02.000000000 +0200
14462 @@ -20,11 +20,14 @@
14463  #include <linux/mnt_namespace.h>
14464  #include <linux/utsname.h>
14465  #include <linux/pid_namespace.h>
14466 +#include <linux/vserver/global.h>
14467 +#include <linux/vserver/debug.h>
14468  #include <net/net_namespace.h>
14469  #include <linux/ipc_namespace.h>
14470  #include <linux/proc_fs.h>
14471  #include <linux/file.h>
14472  #include <linux/syscalls.h>
14473 +#include "../fs/mount.h"
14474  
14475  static struct kmem_cache *nsproxy_cachep;
14476  
14477 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14478         struct nsproxy *nsproxy;
14479  
14480         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14481 -       if (nsproxy)
14482 +       if (nsproxy) {
14483                 atomic_set(&nsproxy->count, 1);
14484 +               atomic_inc(&vs_global_nsproxy);
14485 +       }
14486 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14487         return nsproxy;
14488  }
14489  
14490 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14491   * Return the newly created nsproxy.  Do not attach this to the task,
14492   * leave it to the caller to do proper locking and attach it to task.
14493   */
14494 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14495 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14496 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14497 +                       struct nsproxy *orig,
14498 +                       struct fs_struct *new_fs,
14499 +                       struct user_namespace *new_user,
14500 +                       struct pid_namespace *new_pid)
14501  {
14502         struct nsproxy *new_nsp;
14503         int err;
14504 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14505         if (!new_nsp)
14506                 return ERR_PTR(-ENOMEM);
14507  
14508 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14509 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14510         if (IS_ERR(new_nsp->mnt_ns)) {
14511                 err = PTR_ERR(new_nsp->mnt_ns);
14512                 goto out_ns;
14513         }
14514  
14515 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14516 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14517         if (IS_ERR(new_nsp->uts_ns)) {
14518                 err = PTR_ERR(new_nsp->uts_ns);
14519                 goto out_uts;
14520         }
14521  
14522 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14523 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14524         if (IS_ERR(new_nsp->ipc_ns)) {
14525                 err = PTR_ERR(new_nsp->ipc_ns);
14526                 goto out_ipc;
14527         }
14528  
14529 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14530 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14531         if (IS_ERR(new_nsp->pid_ns)) {
14532                 err = PTR_ERR(new_nsp->pid_ns);
14533                 goto out_pid;
14534         }
14535  
14536 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14537 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14538         if (IS_ERR(new_nsp->net_ns)) {
14539                 err = PTR_ERR(new_nsp->net_ns);
14540                 goto out_net;
14541 @@ -115,6 +124,40 @@ out_ns:
14542         return ERR_PTR(err);
14543  }
14544  
14545 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14546 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14547 +{
14548 +       return unshare_namespaces(flags, tsk->nsproxy,
14549 +               new_fs, task_cred_xxx(tsk, user_ns),
14550 +               task_active_pid_ns(tsk));
14551 +}
14552 +
14553 +/*
14554 + * copies the nsproxy, setting refcount to 1, and grabbing a
14555 + * reference to all contained namespaces.
14556 + */
14557 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14558 +{
14559 +       struct nsproxy *ns = create_nsproxy();
14560 +
14561 +       if (ns) {
14562 +               memcpy(ns, orig, sizeof(struct nsproxy));
14563 +               atomic_set(&ns->count, 1);
14564 +
14565 +               if (ns->mnt_ns)
14566 +                       get_mnt_ns(ns->mnt_ns);
14567 +               if (ns->uts_ns)
14568 +                       get_uts_ns(ns->uts_ns);
14569 +               if (ns->ipc_ns)
14570 +                       get_ipc_ns(ns->ipc_ns);
14571 +               if (ns->pid_ns)
14572 +                       get_pid_ns(ns->pid_ns);
14573 +               if (ns->net_ns)
14574 +                       get_net(ns->net_ns);
14575 +       }
14576 +       return ns;
14577 +}
14578 +
14579  /*
14580   * called from clone.  This now handles copy for nsproxy and all
14581   * namespaces therein.
14582 @@ -122,9 +165,12 @@ out_ns:
14583  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14584  {
14585         struct nsproxy *old_ns = tsk->nsproxy;
14586 -       struct nsproxy *new_ns;
14587 +       struct nsproxy *new_ns = NULL;
14588         int err = 0;
14589  
14590 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14591 +               flags, tsk, old_ns);
14592 +
14593         if (!old_ns)
14594                 return 0;
14595  
14596 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14597                                 CLONE_NEWPID | CLONE_NEWNET)))
14598                 return 0;
14599  
14600 -       if (!capable(CAP_SYS_ADMIN)) {
14601 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14602                 err = -EPERM;
14603                 goto out;
14604         }
14605 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14606  
14607  out:
14608         put_nsproxy(old_ns);
14609 +       vxdprintk(VXD_CBIT(space, 3),
14610 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14611 +               flags, tsk, old_ns, err, new_ns);
14612         return err;
14613  }
14614  
14615 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14616                 put_ipc_ns(ns->ipc_ns);
14617         if (ns->pid_ns)
14618                 put_pid_ns(ns->pid_ns);
14619 -       put_net(ns->net_ns);
14620 +       if (ns->net_ns)
14621 +               put_net(ns->net_ns);
14622 +       atomic_dec(&vs_global_nsproxy);
14623         kmem_cache_free(nsproxy_cachep, ns);
14624  }
14625  
14626 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned 
14627  {
14628         int err = 0;
14629  
14630 +       vxdprintk(VXD_CBIT(space, 4),
14631 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14632 +               unshare_flags, current->nsproxy);
14633 +
14634         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14635                                CLONE_NEWNET)))
14636                 return 0;
14637  
14638 -       if (!capable(CAP_SYS_ADMIN))
14639 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14640                 return -EPERM;
14641  
14642         *new_nsp = create_new_namespaces(unshare_flags, current,
14643 diff -NurpP --minimal linux-3.5.4/kernel/pid.c linux-3.5.4-vs2.3.4.3/kernel/pid.c
14644 --- linux-3.5.4/kernel/pid.c    2012-07-22 23:39:46.000000000 +0200
14645 +++ linux-3.5.4-vs2.3.4.3/kernel/pid.c  2012-07-23 01:45:55.000000000 +0200
14646 @@ -36,6 +36,7 @@
14647  #include <linux/pid_namespace.h>
14648  #include <linux/init_task.h>
14649  #include <linux/syscalls.h>
14650 +#include <linux/vs_pid.h>
14651  
14652  #define pid_hashfn(nr, ns)     \
14653         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14654 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14655  
14656  struct pid *find_vpid(int nr)
14657  {
14658 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14659 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14660  }
14661  EXPORT_SYMBOL_GPL(find_vpid);
14662  
14663 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14664  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14665  {
14666         struct task_struct *result = NULL;
14667 +
14668 +       if (type == PIDTYPE_REALPID)
14669 +               type = PIDTYPE_PID;
14670         if (pid) {
14671                 struct hlist_node *first;
14672                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14673 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14674         rcu_lockdep_assert(rcu_read_lock_held(),
14675                            "find_task_by_pid_ns() needs rcu_read_lock()"
14676                            " protection");
14677 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14678 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14679  }
14680  
14681  struct task_struct *find_task_by_vpid(pid_t vnr)
14682 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14683  }
14684  EXPORT_SYMBOL_GPL(find_get_pid);
14685  
14686 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14687 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14688  {
14689         struct upid *upid;
14690         pid_t nr = 0;
14691 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14692         return nr;
14693  }
14694  
14695 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14696 +{
14697 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14698 +}
14699 +
14700  pid_t pid_vnr(struct pid *pid)
14701  {
14702         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14703 diff -NurpP --minimal linux-3.5.4/kernel/pid_namespace.c linux-3.5.4-vs2.3.4.3/kernel/pid_namespace.c
14704 --- linux-3.5.4/kernel/pid_namespace.c  2012-07-22 23:39:46.000000000 +0200
14705 +++ linux-3.5.4-vs2.3.4.3/kernel/pid_namespace.c        2012-07-23 01:45:55.000000000 +0200
14706 @@ -16,6 +16,7 @@
14707  #include <linux/slab.h>
14708  #include <linux/proc_fs.h>
14709  #include <linux/reboot.h>
14710 +#include <linux/vserver/global.h>
14711  
14712  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14713  
14714 @@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14715                 goto out_free_map;
14716  
14717         kref_init(&ns->kref);
14718 +       atomic_inc(&vs_global_pid_ns);
14719         ns->level = level;
14720         ns->parent = get_pid_ns(parent_pid_ns);
14721  
14722 @@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14723  
14724         for (i = 0; i < PIDMAP_ENTRIES; i++)
14725                 kfree(ns->pidmap[i].page);
14726 +       atomic_dec(&vs_global_pid_ns);
14727         kmem_cache_free(pid_ns_cachep, ns);
14728  }
14729  
14730 diff -NurpP --minimal linux-3.5.4/kernel/posix-timers.c linux-3.5.4-vs2.3.4.3/kernel/posix-timers.c
14731 --- linux-3.5.4/kernel/posix-timers.c   2012-01-09 16:15:00.000000000 +0100
14732 +++ linux-3.5.4-vs2.3.4.3/kernel/posix-timers.c 2012-07-23 01:45:55.000000000 +0200
14733 @@ -47,6 +47,7 @@
14734  #include <linux/wait.h>
14735  #include <linux/workqueue.h>
14736  #include <linux/export.h>
14737 +#include <linux/vs_context.h>
14738  
14739  /*
14740   * Management arrays for POSIX timers.  Timers are kept in slab memory
14741 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14742  {
14743         struct task_struct *task;
14744         int shared, ret = -1;
14745 +
14746         /*
14747          * FIXME: if ->sigq is queued we can race with
14748          * dequeue_signal()->do_schedule_next_timer().
14749 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14750         rcu_read_lock();
14751         task = pid_task(timr->it_pid, PIDTYPE_PID);
14752         if (task) {
14753 +               struct vx_info_save vxis;
14754 +               struct vx_info *vxi;
14755 +
14756 +               vxi = get_vx_info(task->vx_info);
14757 +               enter_vx_info(vxi, &vxis);
14758                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14759                 ret = send_sigqueue(timr->sigq, task, shared);
14760 +               leave_vx_info(&vxis);
14761 +               put_vx_info(vxi);
14762         }
14763         rcu_read_unlock();
14764 +
14765         /* If we failed to send the signal the timer stops. */
14766         return ret > 0;
14767  }
14768 diff -NurpP --minimal linux-3.5.4/kernel/printk.c linux-3.5.4-vs2.3.4.3/kernel/printk.c
14769 --- linux-3.5.4/kernel/printk.c 2012-09-16 20:46:31.000000000 +0200
14770 +++ linux-3.5.4-vs2.3.4.3/kernel/printk.c       2012-08-19 13:28:27.000000000 +0200
14771 @@ -42,6 +42,7 @@
14772  #include <linux/notifier.h>
14773  #include <linux/rculist.h>
14774  #include <linux/poll.h>
14775 +#include <linux/vs_cvirt.h>
14776  
14777  #include <asm/uaccess.h>
14778  
14779 @@ -783,7 +784,7 @@ static int check_syslog_permissions(int 
14780                 return 0;
14781  
14782         if (syslog_action_restricted(type)) {
14783 -               if (capable(CAP_SYSLOG))
14784 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14785                         return 0;
14786                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14787                 if (capable(CAP_SYS_ADMIN)) {
14788 @@ -1076,12 +1077,9 @@ int do_syslog(int type, char __user *buf
14789         if (error)
14790                 return error;
14791  
14792 -       switch (type) {
14793 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14794 -               break;
14795 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14796 -               break;
14797 -       case SYSLOG_ACTION_READ:        /* Read from log */
14798 +       if ((type == SYSLOG_ACTION_READ) ||
14799 +           (type == SYSLOG_ACTION_READ_ALL) ||
14800 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14801                 error = -EINVAL;
14802                 if (!buf || len < 0)
14803                         goto out;
14804 @@ -1092,6 +1090,16 @@ int do_syslog(int type, char __user *buf
14805                         error = -EFAULT;
14806                         goto out;
14807                 }
14808 +       }
14809 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14810 +               return vx_do_syslog(type, buf, len);
14811 +
14812 +       switch (type) {
14813 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14814 +               break;
14815 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14816 +               break;
14817 +       case SYSLOG_ACTION_READ:        /* Read from log */
14818                 error = wait_event_interruptible(log_wait,
14819                                                  syslog_seq != log_next_seq);
14820                 if (error)
14821 @@ -1104,16 +1112,6 @@ int do_syslog(int type, char __user *buf
14822                 /* FALL THRU */
14823         /* Read last kernel messages */
14824         case SYSLOG_ACTION_READ_ALL:
14825 -               error = -EINVAL;
14826 -               if (!buf || len < 0)
14827 -                       goto out;
14828 -               error = 0;
14829 -               if (!len)
14830 -                       goto out;
14831 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14832 -                       error = -EFAULT;
14833 -                       goto out;
14834 -               }
14835                 error = syslog_print_all(buf, len, clear);
14836                 break;
14837         /* Clear ring buffer */
14838 diff -NurpP --minimal linux-3.5.4/kernel/ptrace.c linux-3.5.4-vs2.3.4.3/kernel/ptrace.c
14839 --- linux-3.5.4/kernel/ptrace.c 2012-07-22 23:39:46.000000000 +0200
14840 +++ linux-3.5.4-vs2.3.4.3/kernel/ptrace.c       2012-07-23 01:45:55.000000000 +0200
14841 @@ -22,6 +22,7 @@
14842  #include <linux/syscalls.h>
14843  #include <linux/uaccess.h>
14844  #include <linux/regset.h>
14845 +#include <linux/vs_context.h>
14846  #include <linux/hw_breakpoint.h>
14847  #include <linux/cn_proc.h>
14848  
14849 @@ -216,6 +217,11 @@ ok:
14850                 dumpable = get_dumpable(task->mm);
14851         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14852                 return -EPERM;
14853 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14854 +               return -EPERM;
14855 +       if (!vx_check(task->xid, VS_IDENT) &&
14856 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14857 +               return -EACCES;
14858  
14859         return security_ptrace_access_check(task, mode);
14860  }
14861 diff -NurpP --minimal linux-3.5.4/kernel/sched/core.c linux-3.5.4-vs2.3.4.3/kernel/sched/core.c
14862 --- linux-3.5.4/kernel/sched/core.c     2012-09-16 20:46:31.000000000 +0200
14863 +++ linux-3.5.4-vs2.3.4.3/kernel/sched/core.c   2012-09-16 20:50:19.000000000 +0200
14864 @@ -72,6 +72,8 @@
14865  #include <linux/slab.h>
14866  #include <linux/init_task.h>
14867  #include <linux/binfmts.h>
14868 +#include <linux/vs_sched.h>
14869 +#include <linux/vs_cvirt.h>
14870  
14871  #include <asm/switch_to.h>
14872  #include <asm/tlb.h>
14873 @@ -2223,9 +2225,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14874   */
14875  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14876  {
14877 -       loads[0] = (avenrun[0] + offset) << shift;
14878 -       loads[1] = (avenrun[1] + offset) << shift;
14879 -       loads[2] = (avenrun[2] + offset) << shift;
14880 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14881 +               struct vx_info *vxi = current_vx_info();
14882 +
14883 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14884 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14885 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14886 +       } else {
14887 +               loads[0] = (avenrun[0] + offset) << shift;
14888 +               loads[1] = (avenrun[1] + offset) << shift;
14889 +               loads[2] = (avenrun[2] + offset) << shift;
14890 +       }
14891  }
14892  
14893  static long calc_load_fold_active(struct rq *this_rq)
14894 @@ -2854,14 +2864,17 @@ static inline void task_group_account_fi
14895  void account_user_time(struct task_struct *p, cputime_t cputime,
14896                        cputime_t cputime_scaled)
14897  {
14898 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14899 +       int nice = (TASK_NICE(p) > 0);
14900         int index;
14901  
14902         /* Add user time to process. */
14903         p->utime += cputime;
14904         p->utimescaled += cputime_scaled;
14905 +       vx_account_user(vxi, cputime, nice);
14906         account_group_user_time(p, cputime);
14907  
14908 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14909 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14910  
14911         /* Add user time to cpustat. */
14912         task_group_account_field(p, index, (__force u64) cputime);
14913 @@ -2908,9 +2921,12 @@ static inline
14914  void __account_system_time(struct task_struct *p, cputime_t cputime,
14915                         cputime_t cputime_scaled, int index)
14916  {
14917 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14918 +
14919         /* Add system time to process. */
14920         p->stime += cputime;
14921         p->stimescaled += cputime_scaled;
14922 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14923         account_group_system_time(p, cputime);
14924  
14925         /* Add system time to cpustat. */
14926 @@ -4137,7 +4153,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14927                 nice = 19;
14928  
14929         if (increment < 0 && !can_nice(current, nice))
14930 -               return -EPERM;
14931 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14932  
14933         retval = security_task_setnice(current, nice);
14934         if (retval)
14935 diff -NurpP --minimal linux-3.5.4/kernel/sched/fair.c linux-3.5.4-vs2.3.4.3/kernel/sched/fair.c
14936 --- linux-3.5.4/kernel/sched/fair.c     2012-07-22 23:39:47.000000000 +0200
14937 +++ linux-3.5.4-vs2.3.4.3/kernel/sched/fair.c   2012-07-23 01:45:55.000000000 +0200
14938 @@ -26,6 +26,7 @@
14939  #include <linux/slab.h>
14940  #include <linux/profile.h>
14941  #include <linux/interrupt.h>
14942 +#include <linux/vs_cvirt.h>
14943  
14944  #include <trace/events/sched.h>
14945  
14946 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14947                 __enqueue_entity(cfs_rq, se);
14948         se->on_rq = 1;
14949  
14950 +       if (entity_is_task(se))
14951 +               vx_activate_task(task_of(se));
14952         if (cfs_rq->nr_running == 1) {
14953                 list_add_leaf_cfs_rq(cfs_rq);
14954                 check_enqueue_throttle(cfs_rq);
14955 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14956         if (se != cfs_rq->curr)
14957                 __dequeue_entity(cfs_rq, se);
14958         se->on_rq = 0;
14959 +       if (entity_is_task(se))
14960 +               vx_deactivate_task(task_of(se));
14961         update_cfs_load(cfs_rq, 0);
14962         account_entity_dequeue(cfs_rq, se);
14963  
14964 diff -NurpP --minimal linux-3.5.4/kernel/signal.c linux-3.5.4-vs2.3.4.3/kernel/signal.c
14965 --- linux-3.5.4/kernel/signal.c 2012-07-22 23:39:47.000000000 +0200
14966 +++ linux-3.5.4-vs2.3.4.3/kernel/signal.c       2012-07-23 03:53:00.000000000 +0200
14967 @@ -30,6 +30,8 @@
14968  #include <linux/nsproxy.h>
14969  #include <linux/user_namespace.h>
14970  #include <linux/uprobes.h>
14971 +#include <linux/vs_context.h>
14972 +#include <linux/vs_pid.h>
14973  #define CREATE_TRACE_POINTS
14974  #include <trace/events/signal.h>
14975  
14976 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14977         struct pid *sid;
14978         int error;
14979  
14980 +       vxdprintk(VXD_CBIT(misc, 7),
14981 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14982 +               sig, info, t, vx_task_xid(t), t->pid);
14983 +
14984         if (!valid_signal(sig))
14985                 return -EINVAL;
14986  
14987 +/*     FIXME: needed? if so, why?
14988 +       if ((info != SEND_SIG_NOINFO) &&
14989 +               (is_si_special(info) || !si_fromuser(info)))
14990 +               goto skip;      */
14991 +
14992         if (!si_fromuser(info))
14993                 return 0;
14994  
14995 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14996                 }
14997         }
14998  
14999 +       error = -EPERM;
15000 +       if (t->pid == 1 && current->xid)
15001 +               return error;
15002 +
15003 +       error = -ESRCH;
15004 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15005 +                 loops, maybe ENOENT or EACCES? */
15006 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15007 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15008 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15009 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15010 +               return error;
15011 +       }
15012 +/* skip: */
15013         return security_task_kill(t, info, sig, 0);
15014  }
15015  
15016 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
15017         rcu_read_lock();
15018  retry:
15019         p = pid_task(pid, PIDTYPE_PID);
15020 -       if (p) {
15021 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15022                 error = group_send_sig_info(sig, info, p);
15023                 if (unlikely(error == -ESRCH))
15024                         /*
15025 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
15026  
15027         rcu_read_lock();
15028         p = pid_task(pid, PIDTYPE_PID);
15029 -       if (!p) {
15030 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15031                 ret = -ESRCH;
15032                 goto out_unlock;
15033         }
15034 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig, 
15035                 struct task_struct * p;
15036  
15037                 for_each_process(p) {
15038 -                       if (task_pid_vnr(p) > 1 &&
15039 -                                       !same_thread_group(p, current)) {
15040 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15041 +                               task_pid_vnr(p) > 1 &&
15042 +                               !same_thread_group(p, current) &&
15043 +                               !vx_current_initpid(p->pid)) {
15044                                 int err = group_send_sig_info(sig, info, p);
15045                                 ++count;
15046                                 if (err != -EPERM)
15047 @@ -2302,6 +2329,11 @@ relock:
15048                                 !sig_kernel_only(signr))
15049                         continue;
15050  
15051 +               /* virtual init is protected against user signals */
15052 +               if ((info->si_code == SI_USER) &&
15053 +                       vx_current_initpid(current->pid))
15054 +                       continue;
15055 +
15056                 if (sig_kernel_stop(signr)) {
15057                         /*
15058                          * The default action is to stop all threads in
15059 diff -NurpP --minimal linux-3.5.4/kernel/softirq.c linux-3.5.4-vs2.3.4.3/kernel/softirq.c
15060 --- linux-3.5.4/kernel/softirq.c        2012-05-21 18:07:34.000000000 +0200
15061 +++ linux-3.5.4-vs2.3.4.3/kernel/softirq.c      2012-07-23 01:45:55.000000000 +0200
15062 @@ -24,6 +24,7 @@
15063  #include <linux/ftrace.h>
15064  #include <linux/smp.h>
15065  #include <linux/tick.h>
15066 +#include <linux/vs_context.h>
15067  
15068  #define CREATE_TRACE_POINTS
15069  #include <trace/events/irq.h>
15070 diff -NurpP --minimal linux-3.5.4/kernel/sys.c linux-3.5.4-vs2.3.4.3/kernel/sys.c
15071 --- linux-3.5.4/kernel/sys.c    2012-07-22 23:39:47.000000000 +0200
15072 +++ linux-3.5.4-vs2.3.4.3/kernel/sys.c  2012-07-23 03:33:13.000000000 +0200
15073 @@ -47,6 +47,7 @@
15074  #include <linux/syscalls.h>
15075  #include <linux/kprobes.h>
15076  #include <linux/user_namespace.h>
15077 +#include <linux/vs_pid.h>
15078  
15079  #include <linux/kmsg_dump.h>
15080  /* Move somewhere else to avoid recompiling? */
15081 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
15082                 goto out;
15083         }
15084         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15085 -               error = -EACCES;
15086 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15087 +                       error = 0;
15088 +               else
15089 +                       error = -EACCES;
15090                 goto out;
15091         }
15092         no_nice = security_task_setnice(p, niceval);
15093 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15094                         else
15095                                 pgrp = task_pgrp(current);
15096                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15097 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15098 +                                       continue;
15099                                 error = set_one_prio(p, niceval, error);
15100                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15101                         break;
15102 @@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15103                         else
15104                                 pgrp = task_pgrp(current);
15105                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15106 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15107 +                                       continue;
15108                                 niceval = 20 - task_nice(p);
15109                                 if (niceval > retval)
15110                                         retval = niceval;
15111 @@ -421,6 +429,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15112  
15113  static DEFINE_MUTEX(reboot_mutex);
15114  
15115 +long vs_reboot(unsigned int, void __user *);
15116 +
15117  /*
15118   * Reboot system call: for obvious reasons only root may call it,
15119   * and even root needs to set up some magic numbers in the registers
15120 @@ -462,6 +472,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15121         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15122                 cmd = LINUX_REBOOT_CMD_HALT;
15123  
15124 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15125 +               return vs_reboot(cmd, arg);
15126 +
15127         mutex_lock(&reboot_mutex);
15128         switch (cmd) {
15129         case LINUX_REBOOT_CMD_RESTART:
15130 @@ -1367,7 +1380,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15131         int errno;
15132         char tmp[__NEW_UTS_LEN];
15133  
15134 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15135 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15136 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15137                 return -EPERM;
15138  
15139         if (len < 0 || len > __NEW_UTS_LEN)
15140 @@ -1418,7 +1432,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15141         int errno;
15142         char tmp[__NEW_UTS_LEN];
15143  
15144 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15145 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15146 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15147                 return -EPERM;
15148         if (len < 0 || len > __NEW_UTS_LEN)
15149                 return -EINVAL;
15150 @@ -1537,7 +1552,7 @@ int do_prlimit(struct task_struct *tsk, 
15151                 /* Keep the capable check against init_user_ns until
15152                    cgroups can contain all limits */
15153                 if (new_rlim->rlim_max > rlim->rlim_max &&
15154 -                               !capable(CAP_SYS_RESOURCE))
15155 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15156                         retval = -EPERM;
15157                 if (!retval)
15158                         retval = security_task_setrlimit(tsk->group_leader,
15159 @@ -1590,7 +1605,8 @@ static int check_prlimit_permission(stru
15160             gid_eq(cred->gid, tcred->sgid) &&
15161             gid_eq(cred->gid, tcred->gid))
15162                 return 0;
15163 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15164 +       if (vx_ns_capable(tcred->user_ns,
15165 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15166                 return 0;
15167  
15168         return -EPERM;
15169 diff -NurpP --minimal linux-3.5.4/kernel/sysctl.c linux-3.5.4-vs2.3.4.3/kernel/sysctl.c
15170 --- linux-3.5.4/kernel/sysctl.c 2012-05-21 18:07:34.000000000 +0200
15171 +++ linux-3.5.4-vs2.3.4.3/kernel/sysctl.c       2012-07-23 01:45:55.000000000 +0200
15172 @@ -81,6 +81,7 @@
15173  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15174  #include <linux/lockdep.h>
15175  #endif
15176 +extern char vshelper_path[];
15177  #ifdef CONFIG_CHR_DEV_SG
15178  #include <scsi/sg.h>
15179  #endif
15180 @@ -562,6 +563,13 @@ static struct ctl_table kern_table[] = {
15181                 .proc_handler   = proc_dostring,
15182         },
15183  #endif
15184 +       {
15185 +               .procname       = "vshelper",
15186 +               .data           = &vshelper_path,
15187 +               .maxlen         = 256,
15188 +               .mode           = 0644,
15189 +               .proc_handler   = &proc_dostring,
15190 +       },
15191  #ifdef CONFIG_CHR_DEV_SG
15192         {
15193                 .procname       = "sg-big-buff",
15194 diff -NurpP --minimal linux-3.5.4/kernel/sysctl_binary.c linux-3.5.4-vs2.3.4.3/kernel/sysctl_binary.c
15195 --- linux-3.5.4/kernel/sysctl_binary.c  2012-01-09 16:15:00.000000000 +0100
15196 +++ linux-3.5.4-vs2.3.4.3/kernel/sysctl_binary.c        2012-07-23 01:45:55.000000000 +0200
15197 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15198  
15199         { CTL_INT,      KERN_PANIC,                     "panic" },
15200         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15201 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15202  
15203         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15204         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15205 diff -NurpP --minimal linux-3.5.4/kernel/time/timekeeping.c linux-3.5.4-vs2.3.4.3/kernel/time/timekeeping.c
15206 --- linux-3.5.4/kernel/time/timekeeping.c       2012-07-22 23:39:47.000000000 +0200
15207 +++ linux-3.5.4-vs2.3.4.3/kernel/time/timekeeping.c     2012-07-23 01:45:55.000000000 +0200
15208 @@ -254,6 +254,7 @@ void getnstimeofday(struct timespec *ts)
15209         } while (read_seqretry(&timekeeper.lock, seq));
15210  
15211         timespec_add_ns(ts, nsecs);
15212 +       vx_adjust_timespec(ts);
15213  }
15214  EXPORT_SYMBOL(getnstimeofday);
15215  
15216 diff -NurpP --minimal linux-3.5.4/kernel/time.c linux-3.5.4-vs2.3.4.3/kernel/time.c
15217 --- linux-3.5.4/kernel/time.c   2012-05-21 18:07:34.000000000 +0200
15218 +++ linux-3.5.4-vs2.3.4.3/kernel/time.c 2012-07-23 01:45:55.000000000 +0200
15219 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15220         if (err)
15221                 return err;
15222  
15223 -       do_settimeofday(&tv);
15224 +       vx_settimeofday(&tv);
15225         return 0;
15226  }
15227  
15228 @@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15229                 }
15230         }
15231         if (tv)
15232 -               return do_settimeofday(tv);
15233 +               return vx_settimeofday(tv);
15234         return 0;
15235  }
15236  
15237 diff -NurpP --minimal linux-3.5.4/kernel/timer.c linux-3.5.4-vs2.3.4.3/kernel/timer.c
15238 --- linux-3.5.4/kernel/timer.c  2012-07-22 23:39:47.000000000 +0200
15239 +++ linux-3.5.4-vs2.3.4.3/kernel/timer.c        2012-07-23 01:45:55.000000000 +0200
15240 @@ -40,6 +40,10 @@
15241  #include <linux/irq_work.h>
15242  #include <linux/sched.h>
15243  #include <linux/slab.h>
15244 +#include <linux/vs_base.h>
15245 +#include <linux/vs_cvirt.h>
15246 +#include <linux/vs_pid.h>
15247 +#include <linux/vserver/sched.h>
15248  
15249  #include <asm/uaccess.h>
15250  #include <asm/unistd.h>
15251 @@ -1394,12 +1398,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15252  
15253  #endif
15254  
15255 -#ifndef __alpha__
15256 -
15257 -/*
15258 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15259 - * should be moved into arch/i386 instead?
15260 - */
15261  
15262  /**
15263   * sys_getpid - return the thread group id of the current process
15264 @@ -1428,10 +1426,23 @@ SYSCALL_DEFINE0(getppid)
15265         rcu_read_lock();
15266         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
15267         rcu_read_unlock();
15268 +       return vx_map_pid(pid);
15269 +}
15270  
15271 -       return pid;
15272 +#ifdef __alpha__
15273 +
15274 +/*
15275 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15276 + */
15277 +
15278 +asmlinkage long do_getxpid(long *ppid)
15279 +{
15280 +       *ppid = sys_getppid();
15281 +       return sys_getpid();
15282  }
15283  
15284 +#else /* _alpha_ */
15285 +
15286  SYSCALL_DEFINE0(getuid)
15287  {
15288         /* Only we change this so SMP safe */
15289 diff -NurpP --minimal linux-3.5.4/kernel/user_namespace.c linux-3.5.4-vs2.3.4.3/kernel/user_namespace.c
15290 --- linux-3.5.4/kernel/user_namespace.c 2012-07-22 23:39:47.000000000 +0200
15291 +++ linux-3.5.4-vs2.3.4.3/kernel/user_namespace.c       2012-07-23 03:38:28.000000000 +0200
15292 @@ -19,6 +19,7 @@
15293  #include <linux/fs.h>
15294  #include <linux/uaccess.h>
15295  #include <linux/ctype.h>
15296 +#include <linux/vserver/global.h>
15297  
15298  static struct kmem_cache *user_ns_cachep __read_mostly;
15299  
15300 @@ -52,6 +53,7 @@ int create_user_ns(struct cred *new)
15301                 return -ENOMEM;
15302  
15303         kref_init(&ns->kref);
15304 +       atomic_inc(&vs_global_user_ns);
15305         ns->parent = parent_ns;
15306         ns->owner = owner;
15307         ns->group = group;
15308 @@ -84,6 +86,9 @@ void free_user_ns(struct kref *kref)
15309  
15310         parent = ns->parent;
15311         kmem_cache_free(user_ns_cachep, ns);
15312 +
15313 +       /* FIXME: maybe move into destroyer? */
15314 +       atomic_dec(&vs_global_user_ns);
15315         put_user_ns(parent);
15316  }
15317  EXPORT_SYMBOL(free_user_ns);
15318 diff -NurpP --minimal linux-3.5.4/kernel/utsname.c linux-3.5.4-vs2.3.4.3/kernel/utsname.c
15319 --- linux-3.5.4/kernel/utsname.c        2012-07-22 23:39:47.000000000 +0200
15320 +++ linux-3.5.4-vs2.3.4.3/kernel/utsname.c      2012-07-23 03:52:22.000000000 +0200
15321 @@ -16,14 +16,17 @@
15322  #include <linux/slab.h>
15323  #include <linux/user_namespace.h>
15324  #include <linux/proc_fs.h>
15325 +#include <linux/vserver/global.h>
15326  
15327  static struct uts_namespace *create_uts_ns(void)
15328  {
15329         struct uts_namespace *uts_ns;
15330  
15331         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15332 -       if (uts_ns)
15333 +       if (uts_ns) {
15334                 kref_init(&uts_ns->kref);
15335 +               atomic_inc(&vs_global_uts_ns);
15336 +       }
15337         return uts_ns;
15338  }
15339  
15340 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15341   * @old_ns: namespace to clone
15342   * Return NULL on error (failure to kmalloc), new ns otherwise
15343   */
15344 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15345 -                                         struct uts_namespace *old_ns)
15346 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15347 +                                         struct user_namespace *old_user)
15348  {
15349         struct uts_namespace *ns;
15350  
15351 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15352  
15353         down_read(&uts_sem);
15354         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15355 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15356 +       ns->user_ns = get_user_ns(old_user);
15357         up_read(&uts_sem);
15358         return ns;
15359  }
15360 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15361   * versa.
15362   */
15363  struct uts_namespace *copy_utsname(unsigned long flags,
15364 -                                  struct task_struct *tsk)
15365 +                                  struct uts_namespace *old_ns,
15366 +                                  struct user_namespace *user_ns)
15367  {
15368 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15369         struct uts_namespace *new_ns;
15370  
15371         BUG_ON(!old_ns);
15372 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15373         if (!(flags & CLONE_NEWUTS))
15374                 return old_ns;
15375  
15376 -       new_ns = clone_uts_ns(tsk, old_ns);
15377 +       new_ns = clone_uts_ns(old_ns, user_ns);
15378  
15379         put_uts_ns(old_ns);
15380         return new_ns;
15381 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15382  
15383         ns = container_of(kref, struct uts_namespace, kref);
15384         put_user_ns(ns->user_ns);
15385 +       atomic_dec(&vs_global_uts_ns);
15386         kfree(ns);
15387  }
15388  
15389 diff -NurpP --minimal linux-3.5.4/kernel/vserver/Kconfig linux-3.5.4-vs2.3.4.3/kernel/vserver/Kconfig
15390 --- linux-3.5.4/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15391 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/Kconfig        2012-07-23 01:45:55.000000000 +0200
15392 @@ -0,0 +1,224 @@
15393 +#
15394 +# Linux VServer configuration
15395 +#
15396 +
15397 +menu "Linux VServer"
15398 +
15399 +config VSERVER_AUTO_LBACK
15400 +       bool    "Automatically Assign Loopback IP"
15401 +       default y
15402 +       help
15403 +         Automatically assign a guest specific loopback
15404 +         IP and add it to the kernel network stack on
15405 +         startup.
15406 +
15407 +config VSERVER_AUTO_SINGLE
15408 +       bool    "Automatic Single IP Special Casing"
15409 +       depends on EXPERIMENTAL
15410 +       default y
15411 +       help
15412 +         This allows network contexts with a single IP to
15413 +         automatically remap 0.0.0.0 bindings to that IP,
15414 +         avoiding further network checks and improving
15415 +         performance.
15416 +
15417 +         (note: such guests do not allow to change the ip
15418 +          on the fly and do not show loopback addresses)
15419 +
15420 +config VSERVER_COWBL
15421 +       bool    "Enable COW Immutable Link Breaking"
15422 +       default y
15423 +       help
15424 +         This enables the COW (Copy-On-Write) link break code.
15425 +         It allows you to treat unified files like normal files
15426 +         when writing to them (which will implicitely break the
15427 +         link and create a copy of the unified file)
15428 +
15429 +config VSERVER_VTIME
15430 +       bool    "Enable Virtualized Guest Time"
15431 +       depends on EXPERIMENTAL
15432 +       default n
15433 +       help
15434 +         This enables per guest time offsets to allow for
15435 +         adjusting the system clock individually per guest.
15436 +         this adds some overhead to the time functions and
15437 +         therefore should not be enabled without good reason.
15438 +
15439 +config VSERVER_DEVICE
15440 +       bool    "Enable Guest Device Mapping"
15441 +       depends on EXPERIMENTAL
15442 +       default n
15443 +       help
15444 +         This enables generic device remapping.
15445 +
15446 +config VSERVER_PROC_SECURE
15447 +       bool    "Enable Proc Security"
15448 +       depends on PROC_FS
15449 +       default y
15450 +       help
15451 +         This configures ProcFS security to initially hide
15452 +         non-process entries for all contexts except the main and
15453 +         spectator context (i.e. for all guests), which is a secure
15454 +         default.
15455 +
15456 +         (note: on 1.2x the entries were visible by default)
15457 +
15458 +choice
15459 +       prompt  "Persistent Inode Tagging"
15460 +       default TAGGING_ID24
15461 +       help
15462 +         This adds persistent context information to filesystems
15463 +         mounted with the tagxid option. Tagging is a requirement
15464 +         for per-context disk limits and per-context quota.
15465 +
15466 +
15467 +config TAGGING_NONE
15468 +       bool    "Disabled"
15469 +       help
15470 +         do not store per-context information in inodes.
15471 +
15472 +config TAGGING_UID16
15473 +       bool    "UID16/GID32"
15474 +       help
15475 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15476 +
15477 +config TAGGING_GID16
15478 +       bool    "UID32/GID16"
15479 +       help
15480 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15481 +
15482 +config TAGGING_ID24
15483 +       bool    "UID24/GID24"
15484 +       help
15485 +         uses the upper 8bit from UID and GID for XID tagging
15486 +         which leaves 24bit for UID/GID each, which should be
15487 +         more than sufficient for normal use.
15488 +
15489 +config TAGGING_INTERN
15490 +       bool    "UID32/GID32"
15491 +       help
15492 +         this uses otherwise reserved inode fields in the on
15493 +         disk representation, which limits the use to a few
15494 +         filesystems (currently ext2 and ext3)
15495 +
15496 +endchoice
15497 +
15498 +config TAG_NFSD
15499 +       bool    "Tag NFSD User Auth and Files"
15500 +       default n
15501 +       help
15502 +         Enable this if you do want the in-kernel NFS
15503 +         Server to use the tagging specified above.
15504 +         (will require patched clients too)
15505 +
15506 +config VSERVER_PRIVACY
15507 +       bool    "Honor Privacy Aspects of Guests"
15508 +       default n
15509 +       help
15510 +         When enabled, most context checks will disallow
15511 +         access to structures assigned to a specific context,
15512 +         like ptys or loop devices.
15513 +
15514 +config VSERVER_CONTEXTS
15515 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15516 +       range 1 65533
15517 +       default "768"   if 64BIT
15518 +       default "256"
15519 +       help
15520 +         This setting will optimize certain data structures
15521 +         and memory allocations according to the expected
15522 +         maximum.
15523 +
15524 +         note: this is not a strict upper limit.
15525 +
15526 +config VSERVER_WARN
15527 +       bool    "VServer Warnings"
15528 +       default y
15529 +       help
15530 +         This enables various runtime warnings, which will
15531 +         notify about potential manipulation attempts or
15532 +         resource shortage. It is generally considered to
15533 +         be a good idea to have that enabled.
15534 +
15535 +config VSERVER_WARN_DEVPTS
15536 +       bool    "VServer DevPTS Warnings"
15537 +       depends on VSERVER_WARN
15538 +       default y
15539 +       help
15540 +         This enables DevPTS related warnings, issued when a
15541 +         process inside a context tries to lookup or access
15542 +         a dynamic pts from the host or a different context.
15543 +
15544 +config VSERVER_DEBUG
15545 +       bool    "VServer Debugging Code"
15546 +       default n
15547 +       help
15548 +         Set this to yes if you want to be able to activate
15549 +         debugging output at runtime. It adds a very small
15550 +         overhead to all vserver related functions and
15551 +         increases the kernel size by about 20k.
15552 +
15553 +config VSERVER_HISTORY
15554 +       bool    "VServer History Tracing"
15555 +       depends on VSERVER_DEBUG
15556 +       default n
15557 +       help
15558 +         Set this to yes if you want to record the history of
15559 +         linux-vserver activities, so they can be replayed in
15560 +         the event of a kernel panic or oops.
15561 +
15562 +config VSERVER_HISTORY_SIZE
15563 +       int     "Per-CPU History Size (32-65536)"
15564 +       depends on VSERVER_HISTORY
15565 +       range 32 65536
15566 +       default 64
15567 +       help
15568 +         This allows you to specify the number of entries in
15569 +         the per-CPU history buffer.
15570 +
15571 +choice
15572 +       prompt  "Quotes used in debug and warn messages"
15573 +       default QUOTES_ISO8859
15574 +
15575 +config QUOTES_ISO8859
15576 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15577 +       help
15578 +         This uses the extended ASCII characters \xbb
15579 +         and \xab for quoting file and process names.
15580 +
15581 +config QUOTES_UTF8
15582 +       bool    "UTF-8 angle quotes"
15583 +       help
15584 +         This uses the the UTF-8 sequences for angle
15585 +         quotes to quote file and process names.
15586 +
15587 +config QUOTES_ASCII
15588 +       bool    "ASCII single quotes"
15589 +       help
15590 +         This uses the ASCII single quote character
15591 +         (\x27) to quote file and process names.
15592 +
15593 +endchoice
15594 +
15595 +endmenu
15596 +
15597 +
15598 +config VSERVER
15599 +       bool
15600 +       default y
15601 +       select NAMESPACES
15602 +       select UTS_NS
15603 +       select IPC_NS
15604 +#      select USER_NS
15605 +       select SYSVIPC
15606 +
15607 +config VSERVER_SECURITY
15608 +       bool
15609 +       depends on SECURITY
15610 +       default y
15611 +       select SECURITY_CAPABILITIES
15612 +
15613 +config VSERVER_DISABLED
15614 +       bool
15615 +       default n
15616 +
15617 diff -NurpP --minimal linux-3.5.4/kernel/vserver/Makefile linux-3.5.4-vs2.3.4.3/kernel/vserver/Makefile
15618 --- linux-3.5.4/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15619 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/Makefile       2012-07-23 01:45:55.000000000 +0200
15620 @@ -0,0 +1,18 @@
15621 +#
15622 +# Makefile for the Linux vserver routines.
15623 +#
15624 +
15625 +
15626 +obj-y          += vserver.o
15627 +
15628 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15629 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15630 +                  dlimit.o tag.o
15631 +
15632 +vserver-$(CONFIG_INET) += inet.o
15633 +vserver-$(CONFIG_PROC_FS) += proc.o
15634 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15635 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15636 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15637 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15638 +
15639 diff -NurpP --minimal linux-3.5.4/kernel/vserver/cacct.c linux-3.5.4-vs2.3.4.3/kernel/vserver/cacct.c
15640 --- linux-3.5.4/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15641 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/cacct.c        2012-07-23 01:45:55.000000000 +0200
15642 @@ -0,0 +1,42 @@
15643 +/*
15644 + *  linux/kernel/vserver/cacct.c
15645 + *
15646 + *  Virtual Server: Context Accounting
15647 + *
15648 + *  Copyright (C) 2006-2007 Herbert Pötzl
15649 + *
15650 + *  V0.01  added accounting stats
15651 + *
15652 + */
15653 +
15654 +#include <linux/types.h>
15655 +#include <linux/vs_context.h>
15656 +#include <linux/vserver/cacct_cmd.h>
15657 +#include <linux/vserver/cacct_int.h>
15658 +
15659 +#include <asm/errno.h>
15660 +#include <asm/uaccess.h>
15661 +
15662 +
15663 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15664 +{
15665 +       struct vcmd_sock_stat_v0 vc_data;
15666 +       int j, field;
15667 +
15668 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15669 +               return -EFAULT;
15670 +
15671 +       field = vc_data.field;
15672 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15673 +               return -EINVAL;
15674 +
15675 +       for (j = 0; j < 3; j++) {
15676 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15677 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15678 +       }
15679 +
15680 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15681 +               return -EFAULT;
15682 +       return 0;
15683 +}
15684 +
15685 diff -NurpP --minimal linux-3.5.4/kernel/vserver/cacct_init.h linux-3.5.4-vs2.3.4.3/kernel/vserver/cacct_init.h
15686 --- linux-3.5.4/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
15687 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/cacct_init.h   2012-07-23 01:45:55.000000000 +0200
15688 @@ -0,0 +1,25 @@
15689 +
15690 +
15691 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15692 +{
15693 +       int i, j;
15694 +
15695 +
15696 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15697 +               for (j = 0; j < 3; j++) {
15698 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15699 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15700 +               }
15701 +       }
15702 +       for (i = 0; i < 8; i++)
15703 +               atomic_set(&cacct->slab[i], 0);
15704 +       for (i = 0; i < 5; i++)
15705 +               for (j = 0; j < 4; j++)
15706 +                       atomic_set(&cacct->page[i][j], 0);
15707 +}
15708 +
15709 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15710 +{
15711 +       return;
15712 +}
15713 +
15714 diff -NurpP --minimal linux-3.5.4/kernel/vserver/cacct_proc.h linux-3.5.4-vs2.3.4.3/kernel/vserver/cacct_proc.h
15715 --- linux-3.5.4/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
15716 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/cacct_proc.h   2012-07-23 01:45:55.000000000 +0200
15717 @@ -0,0 +1,53 @@
15718 +#ifndef _VX_CACCT_PROC_H
15719 +#define _VX_CACCT_PROC_H
15720 +
15721 +#include <linux/vserver/cacct_int.h>
15722 +
15723 +
15724 +#define VX_SOCKA_TOP   \
15725 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15726 +
15727 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15728 +{
15729 +       int i, j, length = 0;
15730 +       static char *type[VXA_SOCK_SIZE] = {
15731 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15732 +       };
15733 +
15734 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15735 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15736 +               length += sprintf(buffer + length, "%s:", type[i]);
15737 +               for (j = 0; j < 3; j++) {
15738 +                       length += sprintf(buffer + length,
15739 +                               "\t%10lu/%-10lu",
15740 +                               vx_sock_count(cacct, i, j),
15741 +                               vx_sock_total(cacct, i, j));
15742 +               }
15743 +               buffer[length++] = '\n';
15744 +       }
15745 +
15746 +       length += sprintf(buffer + length, "\n");
15747 +       length += sprintf(buffer + length,
15748 +               "slab:\t %8u %8u %8u %8u\n",
15749 +               atomic_read(&cacct->slab[1]),
15750 +               atomic_read(&cacct->slab[4]),
15751 +               atomic_read(&cacct->slab[0]),
15752 +               atomic_read(&cacct->slab[2]));
15753 +
15754 +       length += sprintf(buffer + length, "\n");
15755 +       for (i = 0; i < 5; i++) {
15756 +               length += sprintf(buffer + length,
15757 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15758 +                       atomic_read(&cacct->page[i][0]),
15759 +                       atomic_read(&cacct->page[i][1]),
15760 +                       atomic_read(&cacct->page[i][2]),
15761 +                       atomic_read(&cacct->page[i][3]),
15762 +                       atomic_read(&cacct->page[i][4]),
15763 +                       atomic_read(&cacct->page[i][5]),
15764 +                       atomic_read(&cacct->page[i][6]),
15765 +                       atomic_read(&cacct->page[i][7]));
15766 +       }
15767 +       return length;
15768 +}
15769 +
15770 +#endif /* _VX_CACCT_PROC_H */
15771 diff -NurpP --minimal linux-3.5.4/kernel/vserver/context.c linux-3.5.4-vs2.3.4.3/kernel/vserver/context.c
15772 --- linux-3.5.4/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
15773 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/context.c      2012-07-23 01:45:55.000000000 +0200
15774 @@ -0,0 +1,1119 @@
15775 +/*
15776 + *  linux/kernel/vserver/context.c
15777 + *
15778 + *  Virtual Server: Context Support
15779 + *
15780 + *  Copyright (C) 2003-2011  Herbert Pötzl
15781 + *
15782 + *  V0.01  context helper
15783 + *  V0.02  vx_ctx_kill syscall command
15784 + *  V0.03  replaced context_info calls
15785 + *  V0.04  redesign of struct (de)alloc
15786 + *  V0.05  rlimit basic implementation
15787 + *  V0.06  task_xid and info commands
15788 + *  V0.07  context flags and caps
15789 + *  V0.08  switch to RCU based hash
15790 + *  V0.09  revert to non RCU for now
15791 + *  V0.10  and back to working RCU hash
15792 + *  V0.11  and back to locking again
15793 + *  V0.12  referenced context store
15794 + *  V0.13  separate per cpu data
15795 + *  V0.14  changed vcmds to vxi arg
15796 + *  V0.15  added context stat
15797 + *  V0.16  have __create claim() the vxi
15798 + *  V0.17  removed older and legacy stuff
15799 + *  V0.18  added user credentials
15800 + *  V0.19  added warn mask
15801 + *
15802 + */
15803 +
15804 +#include <linux/slab.h>
15805 +#include <linux/types.h>
15806 +#include <linux/security.h>
15807 +#include <linux/pid_namespace.h>
15808 +#include <linux/capability.h>
15809 +
15810 +#include <linux/vserver/context.h>
15811 +#include <linux/vserver/network.h>
15812 +#include <linux/vserver/debug.h>
15813 +#include <linux/vserver/limit.h>
15814 +#include <linux/vserver/limit_int.h>
15815 +#include <linux/vserver/space.h>
15816 +#include <linux/init_task.h>
15817 +#include <linux/fs_struct.h>
15818 +#include <linux/cred.h>
15819 +
15820 +#include <linux/vs_context.h>
15821 +#include <linux/vs_limit.h>
15822 +#include <linux/vs_pid.h>
15823 +#include <linux/vserver/context_cmd.h>
15824 +
15825 +#include "cvirt_init.h"
15826 +#include "cacct_init.h"
15827 +#include "limit_init.h"
15828 +#include "sched_init.h"
15829 +
15830 +
15831 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15832 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15833 +
15834 +
15835 +/*     now inactive context structures */
15836 +
15837 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15838 +
15839 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15840 +
15841 +
15842 +/*     __alloc_vx_info()
15843 +
15844 +       * allocate an initialized vx_info struct
15845 +       * doesn't make it visible (hash)                        */
15846 +
15847 +static struct vx_info *__alloc_vx_info(xid_t xid)
15848 +{
15849 +       struct vx_info *new = NULL;
15850 +       int cpu, index;
15851 +
15852 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15853 +
15854 +       /* would this benefit from a slab cache? */
15855 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15856 +       if (!new)
15857 +               return 0;
15858 +
15859 +       memset(new, 0, sizeof(struct vx_info));
15860 +#ifdef CONFIG_SMP
15861 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15862 +       if (!new->ptr_pc)
15863 +               goto error;
15864 +#endif
15865 +       new->vx_id = xid;
15866 +       INIT_HLIST_NODE(&new->vx_hlist);
15867 +       atomic_set(&new->vx_usecnt, 0);
15868 +       atomic_set(&new->vx_tasks, 0);
15869 +       new->vx_parent = NULL;
15870 +       new->vx_state = 0;
15871 +       init_waitqueue_head(&new->vx_wait);
15872 +
15873 +       /* prepare reaper */
15874 +       get_task_struct(init_pid_ns.child_reaper);
15875 +       new->vx_reaper = init_pid_ns.child_reaper;
15876 +       new->vx_badness_bias = 0;
15877 +
15878 +       /* rest of init goes here */
15879 +       vx_info_init_limit(&new->limit);
15880 +       vx_info_init_sched(&new->sched);
15881 +       vx_info_init_cvirt(&new->cvirt);
15882 +       vx_info_init_cacct(&new->cacct);
15883 +
15884 +       /* per cpu data structures */
15885 +       for_each_possible_cpu(cpu) {
15886 +               vx_info_init_sched_pc(
15887 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15888 +               vx_info_init_cvirt_pc(
15889 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15890 +       }
15891 +
15892 +       new->vx_flags = VXF_INIT_SET;
15893 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15894 +       new->vx_ccaps = 0;
15895 +       new->vx_umask = 0;
15896 +       new->vx_wmask = 0;
15897 +
15898 +       new->reboot_cmd = 0;
15899 +       new->exit_code = 0;
15900 +
15901 +       // preconfig spaces
15902 +       for (index = 0; index < VX_SPACES; index++) {
15903 +               struct _vx_space *space = &new->space[index];
15904 +
15905 +               // filesystem
15906 +               spin_lock(&init_fs.lock);
15907 +               init_fs.users++;
15908 +               spin_unlock(&init_fs.lock);
15909 +               space->vx_fs = &init_fs;
15910 +
15911 +               /* FIXME: do we want defaults? */
15912 +               // space->vx_real_cred = 0;
15913 +               // space->vx_cred = 0;
15914 +       }
15915 +
15916 +
15917 +       vxdprintk(VXD_CBIT(xid, 0),
15918 +               "alloc_vx_info(%d) = %p", xid, new);
15919 +       vxh_alloc_vx_info(new);
15920 +       atomic_inc(&vx_global_ctotal);
15921 +       return new;
15922 +#ifdef CONFIG_SMP
15923 +error:
15924 +       kfree(new);
15925 +       return 0;
15926 +#endif
15927 +}
15928 +
15929 +/*     __dealloc_vx_info()
15930 +
15931 +       * final disposal of vx_info                             */
15932 +
15933 +static void __dealloc_vx_info(struct vx_info *vxi)
15934 +{
15935 +#ifdef CONFIG_VSERVER_WARN
15936 +       struct vx_info_save vxis;
15937 +       int cpu;
15938 +#endif
15939 +       vxdprintk(VXD_CBIT(xid, 0),
15940 +               "dealloc_vx_info(%p)", vxi);
15941 +       vxh_dealloc_vx_info(vxi);
15942 +
15943 +#ifdef CONFIG_VSERVER_WARN
15944 +       enter_vx_info(vxi, &vxis);
15945 +       vx_info_exit_limit(&vxi->limit);
15946 +       vx_info_exit_sched(&vxi->sched);
15947 +       vx_info_exit_cvirt(&vxi->cvirt);
15948 +       vx_info_exit_cacct(&vxi->cacct);
15949 +
15950 +       for_each_possible_cpu(cpu) {
15951 +               vx_info_exit_sched_pc(
15952 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15953 +               vx_info_exit_cvirt_pc(
15954 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15955 +       }
15956 +       leave_vx_info(&vxis);
15957 +#endif
15958 +
15959 +       vxi->vx_id = -1;
15960 +       vxi->vx_state |= VXS_RELEASED;
15961 +
15962 +#ifdef CONFIG_SMP
15963 +       free_percpu(vxi->ptr_pc);
15964 +#endif
15965 +       kfree(vxi);
15966 +       atomic_dec(&vx_global_ctotal);
15967 +}
15968 +
15969 +static void __shutdown_vx_info(struct vx_info *vxi)
15970 +{
15971 +       struct nsproxy *nsproxy;
15972 +       struct fs_struct *fs;
15973 +       struct cred *cred;
15974 +       int index, kill;
15975 +
15976 +       might_sleep();
15977 +
15978 +       vxi->vx_state |= VXS_SHUTDOWN;
15979 +       vs_state_change(vxi, VSC_SHUTDOWN);
15980 +
15981 +       for (index = 0; index < VX_SPACES; index++) {
15982 +               struct _vx_space *space = &vxi->space[index];
15983 +
15984 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15985 +               if (nsproxy)
15986 +                       put_nsproxy(nsproxy);
15987 +
15988 +               fs = xchg(&space->vx_fs, NULL);
15989 +               spin_lock(&fs->lock);
15990 +               kill = !--fs->users;
15991 +               spin_unlock(&fs->lock);
15992 +               if (kill)
15993 +                       free_fs_struct(fs);
15994 +
15995 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15996 +               if (cred)
15997 +                       abort_creds(cred);
15998 +       }
15999 +}
16000 +
16001 +/* exported stuff */
16002 +
16003 +void free_vx_info(struct vx_info *vxi)
16004 +{
16005 +       unsigned long flags;
16006 +       unsigned index;
16007 +
16008 +       /* check for reference counts first */
16009 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16010 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16011 +
16012 +       /* context must not be hashed */
16013 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16014 +
16015 +       /* context shutdown is mandatory */
16016 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16017 +
16018 +       /* spaces check */
16019 +       for (index = 0; index < VX_SPACES; index++) {
16020 +               struct _vx_space *space = &vxi->space[index];
16021 +
16022 +               BUG_ON(space->vx_nsproxy);
16023 +               BUG_ON(space->vx_fs);
16024 +               // BUG_ON(space->vx_real_cred);
16025 +               // BUG_ON(space->vx_cred);
16026 +       }
16027 +
16028 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16029 +       hlist_del(&vxi->vx_hlist);
16030 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16031 +
16032 +       __dealloc_vx_info(vxi);
16033 +}
16034 +
16035 +
16036 +/*     hash table for vx_info hash */
16037 +
16038 +#define VX_HASH_SIZE   13
16039 +
16040 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16041 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16042 +
16043 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16044 +
16045 +
16046 +static inline unsigned int __hashval(xid_t xid)
16047 +{
16048 +       return (xid % VX_HASH_SIZE);
16049 +}
16050 +
16051 +
16052 +
16053 +/*     __hash_vx_info()
16054 +
16055 +       * add the vxi to the global hash table
16056 +       * requires the hash_lock to be held                     */
16057 +
16058 +static inline void __hash_vx_info(struct vx_info *vxi)
16059 +{
16060 +       struct hlist_head *head;
16061 +
16062 +       vxd_assert_lock(&vx_info_hash_lock);
16063 +       vxdprintk(VXD_CBIT(xid, 4),
16064 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16065 +       vxh_hash_vx_info(vxi);
16066 +
16067 +       /* context must not be hashed */
16068 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16069 +
16070 +       vxi->vx_state |= VXS_HASHED;
16071 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16072 +       hlist_add_head(&vxi->vx_hlist, head);
16073 +       atomic_inc(&vx_global_cactive);
16074 +}
16075 +
16076 +/*     __unhash_vx_info()
16077 +
16078 +       * remove the vxi from the global hash table
16079 +       * requires the hash_lock to be held                     */
16080 +
16081 +static inline void __unhash_vx_info(struct vx_info *vxi)
16082 +{
16083 +       unsigned long flags;
16084 +
16085 +       vxd_assert_lock(&vx_info_hash_lock);
16086 +       vxdprintk(VXD_CBIT(xid, 4),
16087 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16088 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16089 +       vxh_unhash_vx_info(vxi);
16090 +
16091 +       /* context must be hashed */
16092 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16093 +       /* but without tasks */
16094 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16095 +
16096 +       vxi->vx_state &= ~VXS_HASHED;
16097 +       hlist_del_init(&vxi->vx_hlist);
16098 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16099 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16100 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16101 +       atomic_dec(&vx_global_cactive);
16102 +}
16103 +
16104 +
16105 +/*     __lookup_vx_info()
16106 +
16107 +       * requires the hash_lock to be held
16108 +       * doesn't increment the vx_refcnt                       */
16109 +
16110 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16111 +{
16112 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16113 +       struct hlist_node *pos;
16114 +       struct vx_info *vxi;
16115 +
16116 +       vxd_assert_lock(&vx_info_hash_lock);
16117 +       hlist_for_each(pos, head) {
16118 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16119 +
16120 +               if (vxi->vx_id == xid)
16121 +                       goto found;
16122 +       }
16123 +       vxi = NULL;
16124 +found:
16125 +       vxdprintk(VXD_CBIT(xid, 0),
16126 +               "__lookup_vx_info(#%u): %p[#%u]",
16127 +               xid, vxi, vxi ? vxi->vx_id : 0);
16128 +       vxh_lookup_vx_info(vxi, xid);
16129 +       return vxi;
16130 +}
16131 +
16132 +
16133 +/*     __create_vx_info()
16134 +
16135 +       * create the requested context
16136 +       * get(), claim() and hash it                            */
16137 +
16138 +static struct vx_info *__create_vx_info(int id)
16139 +{
16140 +       struct vx_info *new, *vxi = NULL;
16141 +
16142 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16143 +
16144 +       if (!(new = __alloc_vx_info(id)))
16145 +               return ERR_PTR(-ENOMEM);
16146 +
16147 +       /* required to make dynamic xids unique */
16148 +       spin_lock(&vx_info_hash_lock);
16149 +
16150 +       /* static context requested */
16151 +       if ((vxi = __lookup_vx_info(id))) {
16152 +               vxdprintk(VXD_CBIT(xid, 0),
16153 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16154 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16155 +                       vxi = ERR_PTR(-EBUSY);
16156 +               else
16157 +                       vxi = ERR_PTR(-EEXIST);
16158 +               goto out_unlock;
16159 +       }
16160 +       /* new context */
16161 +       vxdprintk(VXD_CBIT(xid, 0),
16162 +               "create_vx_info(%d) = %p (new)", id, new);
16163 +       claim_vx_info(new, NULL);
16164 +       __hash_vx_info(get_vx_info(new));
16165 +       vxi = new, new = NULL;
16166 +
16167 +out_unlock:
16168 +       spin_unlock(&vx_info_hash_lock);
16169 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16170 +       if (new)
16171 +               __dealloc_vx_info(new);
16172 +       return vxi;
16173 +}
16174 +
16175 +
16176 +/*     exported stuff                                          */
16177 +
16178 +
16179 +void unhash_vx_info(struct vx_info *vxi)
16180 +{
16181 +       spin_lock(&vx_info_hash_lock);
16182 +       __unhash_vx_info(vxi);
16183 +       spin_unlock(&vx_info_hash_lock);
16184 +       __shutdown_vx_info(vxi);
16185 +       __wakeup_vx_info(vxi);
16186 +}
16187 +
16188 +
16189 +/*     lookup_vx_info()
16190 +
16191 +       * search for a vx_info and get() it
16192 +       * negative id means current                             */
16193 +
16194 +struct vx_info *lookup_vx_info(int id)
16195 +{
16196 +       struct vx_info *vxi = NULL;
16197 +
16198 +       if (id < 0) {
16199 +               vxi = get_vx_info(current_vx_info());
16200 +       } else if (id > 1) {
16201 +               spin_lock(&vx_info_hash_lock);
16202 +               vxi = get_vx_info(__lookup_vx_info(id));
16203 +               spin_unlock(&vx_info_hash_lock);
16204 +       }
16205 +       return vxi;
16206 +}
16207 +
16208 +/*     xid_is_hashed()
16209 +
16210 +       * verify that xid is still hashed                       */
16211 +
16212 +int xid_is_hashed(xid_t xid)
16213 +{
16214 +       int hashed;
16215 +
16216 +       spin_lock(&vx_info_hash_lock);
16217 +       hashed = (__lookup_vx_info(xid) != NULL);
16218 +       spin_unlock(&vx_info_hash_lock);
16219 +       return hashed;
16220 +}
16221 +
16222 +#ifdef CONFIG_PROC_FS
16223 +
16224 +/*     get_xid_list()
16225 +
16226 +       * get a subset of hashed xids for proc
16227 +       * assumes size is at least one                          */
16228 +
16229 +int get_xid_list(int index, unsigned int *xids, int size)
16230 +{
16231 +       int hindex, nr_xids = 0;
16232 +
16233 +       /* only show current and children */
16234 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16235 +               if (index > 0)
16236 +                       return 0;
16237 +               xids[nr_xids] = vx_current_xid();
16238 +               return 1;
16239 +       }
16240 +
16241 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16242 +               struct hlist_head *head = &vx_info_hash[hindex];
16243 +               struct hlist_node *pos;
16244 +
16245 +               spin_lock(&vx_info_hash_lock);
16246 +               hlist_for_each(pos, head) {
16247 +                       struct vx_info *vxi;
16248 +
16249 +                       if (--index > 0)
16250 +                               continue;
16251 +
16252 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16253 +                       xids[nr_xids] = vxi->vx_id;
16254 +                       if (++nr_xids >= size) {
16255 +                               spin_unlock(&vx_info_hash_lock);
16256 +                               goto out;
16257 +                       }
16258 +               }
16259 +               /* keep the lock time short */
16260 +               spin_unlock(&vx_info_hash_lock);
16261 +       }
16262 +out:
16263 +       return nr_xids;
16264 +}
16265 +#endif
16266 +
16267 +#ifdef CONFIG_VSERVER_DEBUG
16268 +
16269 +void   dump_vx_info_inactive(int level)
16270 +{
16271 +       struct hlist_node *entry, *next;
16272 +
16273 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16274 +               struct vx_info *vxi =
16275 +                       list_entry(entry, struct vx_info, vx_hlist);
16276 +
16277 +               dump_vx_info(vxi, level);
16278 +       }
16279 +}
16280 +
16281 +#endif
16282 +
16283 +#if 0
16284 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16285 +{
16286 +       struct user_struct *new_user, *old_user;
16287 +
16288 +       if (!p || !vxi)
16289 +               BUG();
16290 +
16291 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16292 +               return -EACCES;
16293 +
16294 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16295 +       if (!new_user)
16296 +               return -ENOMEM;
16297 +
16298 +       old_user = p->user;
16299 +       if (new_user != old_user) {
16300 +               atomic_inc(&new_user->processes);
16301 +               atomic_dec(&old_user->processes);
16302 +               p->user = new_user;
16303 +       }
16304 +       free_uid(old_user);
16305 +       return 0;
16306 +}
16307 +#endif
16308 +
16309 +#if 0
16310 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16311 +{
16312 +       // p->cap_effective &= vxi->vx_cap_bset;
16313 +       p->cap_effective =
16314 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16315 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16316 +       p->cap_inheritable =
16317 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16318 +       // p->cap_permitted &= vxi->vx_cap_bset;
16319 +       p->cap_permitted =
16320 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16321 +}
16322 +#endif
16323 +
16324 +
16325 +#include <linux/file.h>
16326 +#include <linux/fdtable.h>
16327 +
16328 +static int vx_openfd_task(struct task_struct *tsk)
16329 +{
16330 +       struct files_struct *files = tsk->files;
16331 +       struct fdtable *fdt;
16332 +       const unsigned long *bptr;
16333 +       int count, total;
16334 +
16335 +       /* no rcu_read_lock() because of spin_lock() */
16336 +       spin_lock(&files->file_lock);
16337 +       fdt = files_fdtable(files);
16338 +       bptr = fdt->open_fds;
16339 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16340 +       for (total = 0; count > 0; count--) {
16341 +               if (*bptr)
16342 +                       total += hweight_long(*bptr);
16343 +               bptr++;
16344 +       }
16345 +       spin_unlock(&files->file_lock);
16346 +       return total;
16347 +}
16348 +
16349 +
16350 +/*     for *space compatibility */
16351 +
16352 +asmlinkage long sys_unshare(unsigned long);
16353 +
16354 +/*
16355 + *     migrate task to new context
16356 + *     gets vxi, puts old_vxi on change
16357 + *     optionally unshares namespaces (hack)
16358 + */
16359 +
16360 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16361 +{
16362 +       struct vx_info *old_vxi;
16363 +       int ret = 0;
16364 +
16365 +       if (!p || !vxi)
16366 +               BUG();
16367 +
16368 +       vxdprintk(VXD_CBIT(xid, 5),
16369 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16370 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16371 +
16372 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16373 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16374 +               return -EACCES;
16375 +
16376 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16377 +               return -EFAULT;
16378 +
16379 +       old_vxi = task_get_vx_info(p);
16380 +       if (old_vxi == vxi)
16381 +               goto out;
16382 +
16383 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16384 +       {
16385 +               int openfd;
16386 +
16387 +               task_lock(p);
16388 +               openfd = vx_openfd_task(p);
16389 +
16390 +               if (old_vxi) {
16391 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16392 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16393 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16394 +                       /* FIXME: what about the struct files here? */
16395 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16396 +                       /* account for the executable */
16397 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16398 +               }
16399 +               atomic_inc(&vxi->cvirt.nr_threads);
16400 +               atomic_inc(&vxi->cvirt.nr_running);
16401 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16402 +               /* FIXME: what about the struct files here? */
16403 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16404 +               /* account for the executable */
16405 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16406 +
16407 +               if (old_vxi) {
16408 +                       release_vx_info(old_vxi, p);
16409 +                       clr_vx_info(&p->vx_info);
16410 +               }
16411 +               claim_vx_info(vxi, p);
16412 +               set_vx_info(&p->vx_info, vxi);
16413 +               p->xid = vxi->vx_id;
16414 +
16415 +               vxdprintk(VXD_CBIT(xid, 5),
16416 +                       "moved task %p into vxi:%p[#%d]",
16417 +                       p, vxi, vxi->vx_id);
16418 +
16419 +               // vx_mask_cap_bset(vxi, p);
16420 +               task_unlock(p);
16421 +
16422 +               /* hack for *spaces to provide compatibility */
16423 +               if (unshare) {
16424 +                       struct nsproxy *old_nsp, *new_nsp;
16425 +
16426 +                       ret = unshare_nsproxy_namespaces(
16427 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16428 +                               &new_nsp, NULL);
16429 +                       if (ret)
16430 +                               goto out;
16431 +
16432 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16433 +                       vx_set_space(vxi,
16434 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16435 +                       put_nsproxy(old_nsp);
16436 +               }
16437 +       }
16438 +out:
16439 +       put_vx_info(old_vxi);
16440 +       return ret;
16441 +}
16442 +
16443 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16444 +{
16445 +       struct task_struct *old_reaper;
16446 +       struct vx_info *reaper_vxi;
16447 +
16448 +       if (!vxi)
16449 +               return -EINVAL;
16450 +
16451 +       vxdprintk(VXD_CBIT(xid, 6),
16452 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16453 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16454 +
16455 +       old_reaper = vxi->vx_reaper;
16456 +       if (old_reaper == p)
16457 +               return 0;
16458 +
16459 +       reaper_vxi = task_get_vx_info(p);
16460 +       if (reaper_vxi && reaper_vxi != vxi) {
16461 +               vxwprintk(1,
16462 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16463 +                       "for [xid #%u]",
16464 +                       p->comm, p->pid, p->xid, vx_current_xid());
16465 +               goto out;
16466 +       }
16467 +
16468 +       /* set new child reaper */
16469 +       get_task_struct(p);
16470 +       vxi->vx_reaper = p;
16471 +       put_task_struct(old_reaper);
16472 +out:
16473 +       put_vx_info(reaper_vxi);
16474 +       return 0;
16475 +}
16476 +
16477 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16478 +{
16479 +       if (!vxi)
16480 +               return -EINVAL;
16481 +
16482 +       vxdprintk(VXD_CBIT(xid, 6),
16483 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16484 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16485 +
16486 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16487 +       // vxi->vx_initpid = p->tgid;
16488 +       vxi->vx_initpid = p->pid;
16489 +       return 0;
16490 +}
16491 +
16492 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16493 +{
16494 +       vxdprintk(VXD_CBIT(xid, 6),
16495 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16496 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16497 +
16498 +       vxi->exit_code = code;
16499 +       vxi->vx_initpid = 0;
16500 +}
16501 +
16502 +
16503 +void vx_set_persistent(struct vx_info *vxi)
16504 +{
16505 +       vxdprintk(VXD_CBIT(xid, 6),
16506 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16507 +
16508 +       get_vx_info(vxi);
16509 +       claim_vx_info(vxi, NULL);
16510 +}
16511 +
16512 +void vx_clear_persistent(struct vx_info *vxi)
16513 +{
16514 +       vxdprintk(VXD_CBIT(xid, 6),
16515 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16516 +
16517 +       release_vx_info(vxi, NULL);
16518 +       put_vx_info(vxi);
16519 +}
16520 +
16521 +void vx_update_persistent(struct vx_info *vxi)
16522 +{
16523 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16524 +               vx_set_persistent(vxi);
16525 +       else
16526 +               vx_clear_persistent(vxi);
16527 +}
16528 +
16529 +
16530 +/*     task must be current or locked          */
16531 +
16532 +void   exit_vx_info(struct task_struct *p, int code)
16533 +{
16534 +       struct vx_info *vxi = p->vx_info;
16535 +
16536 +       if (vxi) {
16537 +               atomic_dec(&vxi->cvirt.nr_threads);
16538 +               vx_nproc_dec(p);
16539 +
16540 +               vxi->exit_code = code;
16541 +               release_vx_info(vxi, p);
16542 +       }
16543 +}
16544 +
16545 +void   exit_vx_info_early(struct task_struct *p, int code)
16546 +{
16547 +       struct vx_info *vxi = p->vx_info;
16548 +
16549 +       if (vxi) {
16550 +               if (vxi->vx_initpid == p->pid)
16551 +                       vx_exit_init(vxi, p, code);
16552 +               if (vxi->vx_reaper == p)
16553 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16554 +       }
16555 +}
16556 +
16557 +
16558 +/* vserver syscall commands below here */
16559 +
16560 +/* taks xid and vx_info functions */
16561 +
16562 +#include <asm/uaccess.h>
16563 +
16564 +
16565 +int vc_task_xid(uint32_t id)
16566 +{
16567 +       xid_t xid;
16568 +
16569 +       if (id) {
16570 +               struct task_struct *tsk;
16571 +
16572 +               rcu_read_lock();
16573 +               tsk = find_task_by_real_pid(id);
16574 +               xid = (tsk) ? tsk->xid : -ESRCH;
16575 +               rcu_read_unlock();
16576 +       } else
16577 +               xid = vx_current_xid();
16578 +       return xid;
16579 +}
16580 +
16581 +
16582 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16583 +{
16584 +       struct vcmd_vx_info_v0 vc_data;
16585 +
16586 +       vc_data.xid = vxi->vx_id;
16587 +       vc_data.initpid = vxi->vx_initpid;
16588 +
16589 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16590 +               return -EFAULT;
16591 +       return 0;
16592 +}
16593 +
16594 +
16595 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16596 +{
16597 +       struct vcmd_ctx_stat_v0 vc_data;
16598 +
16599 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16600 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16601 +
16602 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16603 +               return -EFAULT;
16604 +       return 0;
16605 +}
16606 +
16607 +
16608 +/* context functions */
16609 +
16610 +int vc_ctx_create(uint32_t xid, void __user *data)
16611 +{
16612 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16613 +       struct vx_info *new_vxi;
16614 +       int ret;
16615 +
16616 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16617 +               return -EFAULT;
16618 +
16619 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16620 +               return -EINVAL;
16621 +
16622 +       new_vxi = __create_vx_info(xid);
16623 +       if (IS_ERR(new_vxi))
16624 +               return PTR_ERR(new_vxi);
16625 +
16626 +       /* initial flags */
16627 +       new_vxi->vx_flags = vc_data.flagword;
16628 +
16629 +       ret = -ENOEXEC;
16630 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16631 +               goto out;
16632 +
16633 +       ret = vx_migrate_task(current, new_vxi, (!data));
16634 +       if (ret)
16635 +               goto out;
16636 +
16637 +       /* return context id on success */
16638 +       ret = new_vxi->vx_id;
16639 +
16640 +       /* get a reference for persistent contexts */
16641 +       if ((vc_data.flagword & VXF_PERSISTENT))
16642 +               vx_set_persistent(new_vxi);
16643 +out:
16644 +       release_vx_info(new_vxi, NULL);
16645 +       put_vx_info(new_vxi);
16646 +       return ret;
16647 +}
16648 +
16649 +
16650 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16651 +{
16652 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16653 +       int ret;
16654 +
16655 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16656 +               return -EFAULT;
16657 +
16658 +       ret = vx_migrate_task(current, vxi, 0);
16659 +       if (ret)
16660 +               return ret;
16661 +       if (vc_data.flagword & VXM_SET_INIT)
16662 +               ret = vx_set_init(vxi, current);
16663 +       if (ret)
16664 +               return ret;
16665 +       if (vc_data.flagword & VXM_SET_REAPER)
16666 +               ret = vx_set_reaper(vxi, current);
16667 +       return ret;
16668 +}
16669 +
16670 +
16671 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16672 +{
16673 +       struct vcmd_ctx_flags_v0 vc_data;
16674 +
16675 +       vc_data.flagword = vxi->vx_flags;
16676 +
16677 +       /* special STATE flag handling */
16678 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16679 +
16680 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16681 +               return -EFAULT;
16682 +       return 0;
16683 +}
16684 +
16685 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16686 +{
16687 +       struct vcmd_ctx_flags_v0 vc_data;
16688 +       uint64_t mask, trigger;
16689 +
16690 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16691 +               return -EFAULT;
16692 +
16693 +       /* special STATE flag handling */
16694 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16695 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16696 +
16697 +       if (vxi == current_vx_info()) {
16698 +               /* if (trigger & VXF_STATE_SETUP)
16699 +                       vx_mask_cap_bset(vxi, current); */
16700 +               if (trigger & VXF_STATE_INIT) {
16701 +                       int ret;
16702 +
16703 +                       ret = vx_set_init(vxi, current);
16704 +                       if (ret)
16705 +                               return ret;
16706 +                       ret = vx_set_reaper(vxi, current);
16707 +                       if (ret)
16708 +                               return ret;
16709 +               }
16710 +       }
16711 +
16712 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16713 +               vc_data.flagword, mask);
16714 +       if (trigger & VXF_PERSISTENT)
16715 +               vx_update_persistent(vxi);
16716 +
16717 +       return 0;
16718 +}
16719 +
16720 +
16721 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16722 +{
16723 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16724 +
16725 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16726 +       return v;
16727 +}
16728 +
16729 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16730 +{
16731 +       kernel_cap_t c = __cap_empty_set;
16732 +
16733 +       c.cap[0] = v & 0xFFFFFFFF;
16734 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16735 +
16736 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16737 +       return c;
16738 +}
16739 +
16740 +
16741 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16742 +{
16743 +       if (bcaps)
16744 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16745 +       if (ccaps)
16746 +               *ccaps = vxi->vx_ccaps;
16747 +
16748 +       return 0;
16749 +}
16750 +
16751 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16752 +{
16753 +       struct vcmd_ctx_caps_v1 vc_data;
16754 +       int ret;
16755 +
16756 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16757 +       if (ret)
16758 +               return ret;
16759 +       vc_data.cmask = ~0ULL;
16760 +
16761 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16762 +               return -EFAULT;
16763 +       return 0;
16764 +}
16765 +
16766 +static int do_set_caps(struct vx_info *vxi,
16767 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16768 +{
16769 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16770 +
16771 +#if 0
16772 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16773 +               bcaps, bmask, ccaps, cmask);
16774 +#endif
16775 +       vxi->vx_bcaps = cap_t_from_caps(
16776 +               vs_mask_flags(bcold, bcaps, bmask));
16777 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16778 +
16779 +       return 0;
16780 +}
16781 +
16782 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16783 +{
16784 +       struct vcmd_ctx_caps_v1 vc_data;
16785 +
16786 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16787 +               return -EFAULT;
16788 +
16789 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16790 +}
16791 +
16792 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16793 +{
16794 +       struct vcmd_bcaps vc_data;
16795 +       int ret;
16796 +
16797 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16798 +       if (ret)
16799 +               return ret;
16800 +       vc_data.bmask = ~0ULL;
16801 +
16802 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16803 +               return -EFAULT;
16804 +       return 0;
16805 +}
16806 +
16807 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16808 +{
16809 +       struct vcmd_bcaps vc_data;
16810 +
16811 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16812 +               return -EFAULT;
16813 +
16814 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16815 +}
16816 +
16817 +
16818 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16819 +{
16820 +       struct vcmd_umask vc_data;
16821 +
16822 +       vc_data.umask = vxi->vx_umask;
16823 +       vc_data.mask = ~0ULL;
16824 +
16825 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16826 +               return -EFAULT;
16827 +       return 0;
16828 +}
16829 +
16830 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16831 +{
16832 +       struct vcmd_umask vc_data;
16833 +
16834 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16835 +               return -EFAULT;
16836 +
16837 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16838 +               vc_data.umask, vc_data.mask);
16839 +       return 0;
16840 +}
16841 +
16842 +
16843 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16844 +{
16845 +       struct vcmd_wmask vc_data;
16846 +
16847 +       vc_data.wmask = vxi->vx_wmask;
16848 +       vc_data.mask = ~0ULL;
16849 +
16850 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16851 +               return -EFAULT;
16852 +       return 0;
16853 +}
16854 +
16855 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16856 +{
16857 +       struct vcmd_wmask vc_data;
16858 +
16859 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16860 +               return -EFAULT;
16861 +
16862 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16863 +               vc_data.wmask, vc_data.mask);
16864 +       return 0;
16865 +}
16866 +
16867 +
16868 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16869 +{
16870 +       struct vcmd_badness_v0 vc_data;
16871 +
16872 +       vc_data.bias = vxi->vx_badness_bias;
16873 +
16874 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16875 +               return -EFAULT;
16876 +       return 0;
16877 +}
16878 +
16879 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16880 +{
16881 +       struct vcmd_badness_v0 vc_data;
16882 +
16883 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16884 +               return -EFAULT;
16885 +
16886 +       vxi->vx_badness_bias = vc_data.bias;
16887 +       return 0;
16888 +}
16889 +
16890 +#include <linux/module.h>
16891 +
16892 +EXPORT_SYMBOL_GPL(free_vx_info);
16893 +
16894 diff -NurpP --minimal linux-3.5.4/kernel/vserver/cvirt.c linux-3.5.4-vs2.3.4.3/kernel/vserver/cvirt.c
16895 --- linux-3.5.4/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
16896 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/cvirt.c        2012-07-23 01:45:55.000000000 +0200
16897 @@ -0,0 +1,313 @@
16898 +/*
16899 + *  linux/kernel/vserver/cvirt.c
16900 + *
16901 + *  Virtual Server: Context Virtualization
16902 + *
16903 + *  Copyright (C) 2004-2007  Herbert Pötzl
16904 + *
16905 + *  V0.01  broken out from limit.c
16906 + *  V0.02  added utsname stuff
16907 + *  V0.03  changed vcmds to vxi arg
16908 + *
16909 + */
16910 +
16911 +#include <linux/types.h>
16912 +#include <linux/utsname.h>
16913 +#include <linux/vs_cvirt.h>
16914 +#include <linux/vserver/switch.h>
16915 +#include <linux/vserver/cvirt_cmd.h>
16916 +
16917 +#include <asm/uaccess.h>
16918 +
16919 +
16920 +void vx_vsi_boottime(struct timespec *boottime)
16921 +{
16922 +       struct vx_info *vxi = current_vx_info();
16923 +
16924 +       set_normalized_timespec(boottime,
16925 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16926 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16927 +       return;
16928 +}
16929 +
16930 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16931 +{
16932 +       struct vx_info *vxi = current_vx_info();
16933 +
16934 +       set_normalized_timespec(uptime,
16935 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16936 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16937 +       if (!idle)
16938 +               return;
16939 +       set_normalized_timespec(idle,
16940 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16941 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16942 +       return;
16943 +}
16944 +
16945 +uint64_t vx_idle_jiffies(void)
16946 +{
16947 +       return init_task.utime + init_task.stime;
16948 +}
16949 +
16950 +
16951 +
16952 +static inline uint32_t __update_loadavg(uint32_t load,
16953 +       int wsize, int delta, int n)
16954 +{
16955 +       unsigned long long calc, prev;
16956 +
16957 +       /* just set it to n */
16958 +       if (unlikely(delta >= wsize))
16959 +               return (n << FSHIFT);
16960 +
16961 +       calc = delta * n;
16962 +       calc <<= FSHIFT;
16963 +       prev = (wsize - delta);
16964 +       prev *= load;
16965 +       calc += prev;
16966 +       do_div(calc, wsize);
16967 +       return calc;
16968 +}
16969 +
16970 +
16971 +void vx_update_load(struct vx_info *vxi)
16972 +{
16973 +       uint32_t now, last, delta;
16974 +       unsigned int nr_running, nr_uninterruptible;
16975 +       unsigned int total;
16976 +       unsigned long flags;
16977 +
16978 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16979 +
16980 +       now = jiffies;
16981 +       last = vxi->cvirt.load_last;
16982 +       delta = now - last;
16983 +
16984 +       if (delta < 5*HZ)
16985 +               goto out;
16986 +
16987 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16988 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16989 +       total = nr_running + nr_uninterruptible;
16990 +
16991 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16992 +               60*HZ, delta, total);
16993 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16994 +               5*60*HZ, delta, total);
16995 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16996 +               15*60*HZ, delta, total);
16997 +
16998 +       vxi->cvirt.load_last = now;
16999 +out:
17000 +       atomic_inc(&vxi->cvirt.load_updates);
17001 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17002 +}
17003 +
17004 +
17005 +/*
17006 + * Commands to do_syslog:
17007 + *
17008 + *      0 -- Close the log.  Currently a NOP.
17009 + *      1 -- Open the log. Currently a NOP.
17010 + *      2 -- Read from the log.
17011 + *      3 -- Read all messages remaining in the ring buffer.
17012 + *      4 -- Read and clear all messages remaining in the ring buffer
17013 + *      5 -- Clear ring buffer.
17014 + *      6 -- Disable printk's to console
17015 + *      7 -- Enable printk's to console
17016 + *      8 -- Set level of messages printed to console
17017 + *      9 -- Return number of unread characters in the log buffer
17018 + *     10 -- Return size of the log buffer
17019 + */
17020 +int vx_do_syslog(int type, char __user *buf, int len)
17021 +{
17022 +       int error = 0;
17023 +       int do_clear = 0;
17024 +       struct vx_info *vxi = current_vx_info();
17025 +       struct _vx_syslog *log;
17026 +
17027 +       if (!vxi)
17028 +               return -EINVAL;
17029 +       log = &vxi->cvirt.syslog;
17030 +
17031 +       switch (type) {
17032 +       case 0:         /* Close log */
17033 +       case 1:         /* Open log */
17034 +               break;
17035 +       case 2:         /* Read from log */
17036 +               error = wait_event_interruptible(log->log_wait,
17037 +                       (log->log_start - log->log_end));
17038 +               if (error)
17039 +                       break;
17040 +               spin_lock_irq(&log->logbuf_lock);
17041 +               spin_unlock_irq(&log->logbuf_lock);
17042 +               break;
17043 +       case 4:         /* Read/clear last kernel messages */
17044 +               do_clear = 1;
17045 +               /* fall through */
17046 +       case 3:         /* Read last kernel messages */
17047 +               return 0;
17048 +
17049 +       case 5:         /* Clear ring buffer */
17050 +               return 0;
17051 +
17052 +       case 6:         /* Disable logging to console */
17053 +       case 7:         /* Enable logging to console */
17054 +       case 8:         /* Set level of messages printed to console */
17055 +               break;
17056 +
17057 +       case 9:         /* Number of chars in the log buffer */
17058 +               return 0;
17059 +       case 10:        /* Size of the log buffer */
17060 +               return 0;
17061 +       default:
17062 +               error = -EINVAL;
17063 +               break;
17064 +       }
17065 +       return error;
17066 +}
17067 +
17068 +
17069 +/* virtual host info names */
17070 +
17071 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17072 +{
17073 +       struct nsproxy *nsproxy;
17074 +       struct uts_namespace *uts;
17075 +
17076 +       if (id == VHIN_CONTEXT)
17077 +               return vxi->vx_name;
17078 +
17079 +       nsproxy = vxi->space[0].vx_nsproxy;
17080 +       if (!nsproxy)
17081 +               return NULL;
17082 +
17083 +       uts = nsproxy->uts_ns;
17084 +       if (!uts)
17085 +               return NULL;
17086 +
17087 +       switch (id) {
17088 +       case VHIN_SYSNAME:
17089 +               return uts->name.sysname;
17090 +       case VHIN_NODENAME:
17091 +               return uts->name.nodename;
17092 +       case VHIN_RELEASE:
17093 +               return uts->name.release;
17094 +       case VHIN_VERSION:
17095 +               return uts->name.version;
17096 +       case VHIN_MACHINE:
17097 +               return uts->name.machine;
17098 +       case VHIN_DOMAINNAME:
17099 +               return uts->name.domainname;
17100 +       default:
17101 +               return NULL;
17102 +       }
17103 +       return NULL;
17104 +}
17105 +
17106 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17107 +{
17108 +       struct vcmd_vhi_name_v0 vc_data;
17109 +       char *name;
17110 +
17111 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17112 +               return -EFAULT;
17113 +
17114 +       name = vx_vhi_name(vxi, vc_data.field);
17115 +       if (!name)
17116 +               return -EINVAL;
17117 +
17118 +       memcpy(name, vc_data.name, 65);
17119 +       return 0;
17120 +}
17121 +
17122 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17123 +{
17124 +       struct vcmd_vhi_name_v0 vc_data;
17125 +       char *name;
17126 +
17127 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17128 +               return -EFAULT;
17129 +
17130 +       name = vx_vhi_name(vxi, vc_data.field);
17131 +       if (!name)
17132 +               return -EINVAL;
17133 +
17134 +       memcpy(vc_data.name, name, 65);
17135 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17136 +               return -EFAULT;
17137 +       return 0;
17138 +}
17139 +
17140 +
17141 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17142 +{
17143 +       struct vcmd_virt_stat_v0 vc_data;
17144 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17145 +       struct timespec uptime;
17146 +
17147 +       do_posix_clock_monotonic_gettime(&uptime);
17148 +       set_normalized_timespec(&uptime,
17149 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17150 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17151 +
17152 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17153 +       vc_data.uptime = timespec_to_ns(&uptime);
17154 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17155 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17156 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17157 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17158 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17159 +       vc_data.load[0] = cvirt->load[0];
17160 +       vc_data.load[1] = cvirt->load[1];
17161 +       vc_data.load[2] = cvirt->load[2];
17162 +
17163 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17164 +               return -EFAULT;
17165 +       return 0;
17166 +}
17167 +
17168 +
17169 +#ifdef CONFIG_VSERVER_VTIME
17170 +
17171 +/* virtualized time base */
17172 +
17173 +void vx_adjust_timespec(struct timespec *ts)
17174 +{
17175 +       struct vx_info *vxi;
17176 +
17177 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17178 +               return;
17179 +
17180 +       vxi = current_vx_info();
17181 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17182 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17183 +
17184 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17185 +               ts->tv_sec++;
17186 +               ts->tv_nsec -= NSEC_PER_SEC;
17187 +       } else if (ts->tv_nsec < 0) {
17188 +               ts->tv_sec--;
17189 +               ts->tv_nsec += NSEC_PER_SEC;
17190 +       }
17191 +}
17192 +
17193 +int vx_settimeofday(const struct timespec *ts)
17194 +{
17195 +       struct timespec ats, delta;
17196 +       struct vx_info *vxi;
17197 +
17198 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17199 +               return do_settimeofday(ts);
17200 +
17201 +       getnstimeofday(&ats);
17202 +       delta = timespec_sub(*ts, ats);
17203 +
17204 +       vxi = current_vx_info();
17205 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17206 +       return 0;
17207 +}
17208 +
17209 +#endif
17210 +
17211 diff -NurpP --minimal linux-3.5.4/kernel/vserver/cvirt_init.h linux-3.5.4-vs2.3.4.3/kernel/vserver/cvirt_init.h
17212 --- linux-3.5.4/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17213 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/cvirt_init.h   2012-07-23 01:45:55.000000000 +0200
17214 @@ -0,0 +1,70 @@
17215 +
17216 +
17217 +extern uint64_t vx_idle_jiffies(void);
17218 +
17219 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17220 +{
17221 +       uint64_t idle_jiffies = vx_idle_jiffies();
17222 +       uint64_t nsuptime;
17223 +
17224 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17225 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17226 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17227 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17228 +       cvirt->bias_ts.tv_sec = 0;
17229 +       cvirt->bias_ts.tv_nsec = 0;
17230 +
17231 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17232 +       atomic_set(&cvirt->nr_threads, 0);
17233 +       atomic_set(&cvirt->nr_running, 0);
17234 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17235 +       atomic_set(&cvirt->nr_onhold, 0);
17236 +
17237 +       spin_lock_init(&cvirt->load_lock);
17238 +       cvirt->load_last = jiffies;
17239 +       atomic_set(&cvirt->load_updates, 0);
17240 +       cvirt->load[0] = 0;
17241 +       cvirt->load[1] = 0;
17242 +       cvirt->load[2] = 0;
17243 +       atomic_set(&cvirt->total_forks, 0);
17244 +
17245 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17246 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17247 +       cvirt->syslog.log_start = 0;
17248 +       cvirt->syslog.log_end = 0;
17249 +       cvirt->syslog.con_start = 0;
17250 +       cvirt->syslog.logged_chars = 0;
17251 +}
17252 +
17253 +static inline
17254 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17255 +{
17256 +       // cvirt_pc->cpustat = { 0 };
17257 +}
17258 +
17259 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17260 +{
17261 +#ifdef CONFIG_VSERVER_WARN
17262 +       int value;
17263 +#endif
17264 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17265 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17266 +               cvirt, value);
17267 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17268 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17269 +               cvirt, value);
17270 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17271 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17272 +               cvirt, value);
17273 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17274 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17275 +               cvirt, value);
17276 +       return;
17277 +}
17278 +
17279 +static inline
17280 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17281 +{
17282 +       return;
17283 +}
17284 +
17285 diff -NurpP --minimal linux-3.5.4/kernel/vserver/cvirt_proc.h linux-3.5.4-vs2.3.4.3/kernel/vserver/cvirt_proc.h
17286 --- linux-3.5.4/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17287 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/cvirt_proc.h   2012-07-23 01:45:55.000000000 +0200
17288 @@ -0,0 +1,123 @@
17289 +#ifndef _VX_CVIRT_PROC_H
17290 +#define _VX_CVIRT_PROC_H
17291 +
17292 +#include <linux/nsproxy.h>
17293 +#include <linux/mnt_namespace.h>
17294 +#include <linux/ipc_namespace.h>
17295 +#include <linux/utsname.h>
17296 +#include <linux/ipc.h>
17297 +
17298 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17299 +
17300 +static inline
17301 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17302 +{
17303 +       struct mnt_namespace *ns;
17304 +       struct uts_namespace *uts;
17305 +       struct ipc_namespace *ipc;
17306 +       int length = 0;
17307 +
17308 +       if (!nsproxy)
17309 +               goto out;
17310 +
17311 +       length += sprintf(buffer + length,
17312 +               "NSProxy:\t%p [%p,%p,%p]\n",
17313 +               nsproxy, nsproxy->mnt_ns,
17314 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17315 +
17316 +       ns = nsproxy->mnt_ns;
17317 +       if (!ns)
17318 +               goto skip_ns;
17319 +
17320 +       length += vx_info_mnt_namespace(ns, buffer + length);
17321 +
17322 +skip_ns:
17323 +
17324 +       uts = nsproxy->uts_ns;
17325 +       if (!uts)
17326 +               goto skip_uts;
17327 +
17328 +       length += sprintf(buffer + length,
17329 +               "SysName:\t%.*s\n"
17330 +               "NodeName:\t%.*s\n"
17331 +               "Release:\t%.*s\n"
17332 +               "Version:\t%.*s\n"
17333 +               "Machine:\t%.*s\n"
17334 +               "DomainName:\t%.*s\n",
17335 +               __NEW_UTS_LEN, uts->name.sysname,
17336 +               __NEW_UTS_LEN, uts->name.nodename,
17337 +               __NEW_UTS_LEN, uts->name.release,
17338 +               __NEW_UTS_LEN, uts->name.version,
17339 +               __NEW_UTS_LEN, uts->name.machine,
17340 +               __NEW_UTS_LEN, uts->name.domainname);
17341 +skip_uts:
17342 +
17343 +       ipc = nsproxy->ipc_ns;
17344 +       if (!ipc)
17345 +               goto skip_ipc;
17346 +
17347 +       length += sprintf(buffer + length,
17348 +               "SEMS:\t\t%d %d %d %d  %d\n"
17349 +               "MSG:\t\t%d %d %d\n"
17350 +               "SHM:\t\t%lu %lu  %d %d\n",
17351 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17352 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17353 +               ipc->used_sems,
17354 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17355 +               (unsigned long)ipc->shm_ctlmax,
17356 +               (unsigned long)ipc->shm_ctlall,
17357 +               ipc->shm_ctlmni, ipc->shm_tot);
17358 +skip_ipc:
17359 +out:
17360 +       return length;
17361 +}
17362 +
17363 +
17364 +#include <linux/sched.h>
17365 +
17366 +#define LOAD_INT(x) ((x) >> FSHIFT)
17367 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17368 +
17369 +static inline
17370 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17371 +{
17372 +       int length = 0;
17373 +       int a, b, c;
17374 +
17375 +       length += sprintf(buffer + length,
17376 +               "BiasUptime:\t%lu.%02lu\n",
17377 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17378 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17379 +
17380 +       a = cvirt->load[0] + (FIXED_1 / 200);
17381 +       b = cvirt->load[1] + (FIXED_1 / 200);
17382 +       c = cvirt->load[2] + (FIXED_1 / 200);
17383 +       length += sprintf(buffer + length,
17384 +               "nr_threads:\t%d\n"
17385 +               "nr_running:\t%d\n"
17386 +               "nr_unintr:\t%d\n"
17387 +               "nr_onhold:\t%d\n"
17388 +               "load_updates:\t%d\n"
17389 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17390 +               "total_forks:\t%d\n",
17391 +               atomic_read(&cvirt->nr_threads),
17392 +               atomic_read(&cvirt->nr_running),
17393 +               atomic_read(&cvirt->nr_uninterruptible),
17394 +               atomic_read(&cvirt->nr_onhold),
17395 +               atomic_read(&cvirt->load_updates),
17396 +               LOAD_INT(a), LOAD_FRAC(a),
17397 +               LOAD_INT(b), LOAD_FRAC(b),
17398 +               LOAD_INT(c), LOAD_FRAC(c),
17399 +               atomic_read(&cvirt->total_forks));
17400 +       return length;
17401 +}
17402 +
17403 +static inline
17404 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17405 +       char *buffer, int cpu)
17406 +{
17407 +       int length = 0;
17408 +       return length;
17409 +}
17410 +
17411 +#endif /* _VX_CVIRT_PROC_H */
17412 diff -NurpP --minimal linux-3.5.4/kernel/vserver/debug.c linux-3.5.4-vs2.3.4.3/kernel/vserver/debug.c
17413 --- linux-3.5.4/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17414 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/debug.c        2012-07-23 01:45:55.000000000 +0200
17415 @@ -0,0 +1,32 @@
17416 +/*
17417 + *  kernel/vserver/debug.c
17418 + *
17419 + *  Copyright (C) 2005-2007 Herbert Pötzl
17420 + *
17421 + *  V0.01  vx_info dump support
17422 + *
17423 + */
17424 +
17425 +#include <linux/module.h>
17426 +
17427 +#include <linux/vserver/context.h>
17428 +
17429 +
17430 +void   dump_vx_info(struct vx_info *vxi, int level)
17431 +{
17432 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17433 +               atomic_read(&vxi->vx_usecnt),
17434 +               atomic_read(&vxi->vx_tasks),
17435 +               vxi->vx_state);
17436 +       if (level > 0) {
17437 +               __dump_vx_limit(&vxi->limit);
17438 +               __dump_vx_sched(&vxi->sched);
17439 +               __dump_vx_cvirt(&vxi->cvirt);
17440 +               __dump_vx_cacct(&vxi->cacct);
17441 +       }
17442 +       printk("---\n");
17443 +}
17444 +
17445 +
17446 +EXPORT_SYMBOL_GPL(dump_vx_info);
17447 +
17448 diff -NurpP --minimal linux-3.5.4/kernel/vserver/device.c linux-3.5.4-vs2.3.4.3/kernel/vserver/device.c
17449 --- linux-3.5.4/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17450 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/device.c       2012-07-23 01:45:55.000000000 +0200
17451 @@ -0,0 +1,443 @@
17452 +/*
17453 + *  linux/kernel/vserver/device.c
17454 + *
17455 + *  Linux-VServer: Device Support
17456 + *
17457 + *  Copyright (C) 2006  Herbert Pötzl
17458 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17459 + *
17460 + *  V0.01  device mapping basics
17461 + *  V0.02  added defaults
17462 + *
17463 + */
17464 +
17465 +#include <linux/slab.h>
17466 +#include <linux/rcupdate.h>
17467 +#include <linux/fs.h>
17468 +#include <linux/namei.h>
17469 +#include <linux/hash.h>
17470 +
17471 +#include <asm/errno.h>
17472 +#include <asm/uaccess.h>
17473 +#include <linux/vserver/base.h>
17474 +#include <linux/vserver/debug.h>
17475 +#include <linux/vserver/context.h>
17476 +#include <linux/vserver/device.h>
17477 +#include <linux/vserver/device_cmd.h>
17478 +
17479 +
17480 +#define DMAP_HASH_BITS 4
17481 +
17482 +
17483 +struct vs_mapping {
17484 +       union {
17485 +               struct hlist_node hlist;
17486 +               struct list_head list;
17487 +       } u;
17488 +#define dm_hlist       u.hlist
17489 +#define dm_list                u.list
17490 +       xid_t xid;
17491 +       dev_t device;
17492 +       struct vx_dmap_target target;
17493 +};
17494 +
17495 +
17496 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17497 +
17498 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17499 +
17500 +static struct vx_dmap_target dmap_defaults[2] = {
17501 +       { .flags = DATTR_OPEN },
17502 +       { .flags = DATTR_OPEN },
17503 +};
17504 +
17505 +
17506 +struct kmem_cache *dmap_cachep __read_mostly;
17507 +
17508 +int __init dmap_cache_init(void)
17509 +{
17510 +       dmap_cachep = kmem_cache_create("dmap_cache",
17511 +               sizeof(struct vs_mapping), 0,
17512 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17513 +       return 0;
17514 +}
17515 +
17516 +__initcall(dmap_cache_init);
17517 +
17518 +
17519 +static inline unsigned int __hashval(dev_t dev, int bits)
17520 +{
17521 +       return hash_long((unsigned long)dev, bits);
17522 +}
17523 +
17524 +
17525 +/*     __hash_mapping()
17526 + *     add the mapping to the hash table
17527 + */
17528 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17529 +{
17530 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17531 +       struct hlist_head *head, *hash = dmap_main_hash;
17532 +       int device = vdm->device;
17533 +
17534 +       spin_lock(hash_lock);
17535 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17536 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17537 +
17538 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17539 +       hlist_add_head(&vdm->dm_hlist, head);
17540 +       spin_unlock(hash_lock);
17541 +}
17542 +
17543 +
17544 +static inline int __mode_to_default(umode_t mode)
17545 +{
17546 +       switch (mode) {
17547 +       case S_IFBLK:
17548 +               return 0;
17549 +       case S_IFCHR:
17550 +               return 1;
17551 +       default:
17552 +               BUG();
17553 +       }
17554 +}
17555 +
17556 +
17557 +/*     __set_default()
17558 + *     set a default
17559 + */
17560 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17561 +       struct vx_dmap_target *vdmt)
17562 +{
17563 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17564 +       spin_lock(hash_lock);
17565 +
17566 +       if (vxi)
17567 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17568 +       else
17569 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17570 +
17571 +
17572 +       spin_unlock(hash_lock);
17573 +
17574 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17575 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17576 +}
17577 +
17578 +
17579 +/*     __remove_default()
17580 + *     remove a default
17581 + */
17582 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17583 +{
17584 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17585 +       spin_lock(hash_lock);
17586 +
17587 +       if (vxi)
17588 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17589 +       else    /* remove == reset */
17590 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17591 +
17592 +       spin_unlock(hash_lock);
17593 +       return 0;
17594 +}
17595 +
17596 +
17597 +/*     __find_mapping()
17598 + *     find a mapping in the hash table
17599 + *
17600 + *     caller must hold hash_lock
17601 + */
17602 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17603 +       struct vs_mapping **local, struct vs_mapping **global)
17604 +{
17605 +       struct hlist_head *hash = dmap_main_hash;
17606 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17607 +       struct hlist_node *pos;
17608 +       struct vs_mapping *vdm;
17609 +
17610 +       *local = NULL;
17611 +       if (global)
17612 +               *global = NULL;
17613 +
17614 +       hlist_for_each(pos, head) {
17615 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17616 +
17617 +               if ((vdm->device == device) &&
17618 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17619 +                       if (vdm->xid == xid) {
17620 +                               *local = vdm;
17621 +                               return 1;
17622 +                       } else if (global && vdm->xid == 0)
17623 +                               *global = vdm;
17624 +               }
17625 +       }
17626 +
17627 +       if (global && *global)
17628 +               return 0;
17629 +       else
17630 +               return -ENOENT;
17631 +}
17632 +
17633 +
17634 +/*     __lookup_mapping()
17635 + *     find a mapping and store the result in target and flags
17636 + */
17637 +static inline int __lookup_mapping(struct vx_info *vxi,
17638 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17639 +{
17640 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17641 +       struct vs_mapping *vdm, *global;
17642 +       struct vx_dmap_target *vdmt;
17643 +       int ret = 0;
17644 +       xid_t xid = vxi->vx_id;
17645 +       int index;
17646 +
17647 +       spin_lock(hash_lock);
17648 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17649 +               ret = 1;
17650 +               vdmt = &vdm->target;
17651 +               goto found;
17652 +       }
17653 +
17654 +       index = __mode_to_default(mode);
17655 +       if (vxi && vxi->dmap.targets[index].flags) {
17656 +               ret = 2;
17657 +               vdmt = &vxi->dmap.targets[index];
17658 +       } else if (global) {
17659 +               ret = 3;
17660 +               vdmt = &global->target;
17661 +               goto found;
17662 +       } else {
17663 +               ret = 4;
17664 +               vdmt = &dmap_defaults[index];
17665 +       }
17666 +
17667 +found:
17668 +       if (target && (vdmt->flags & DATTR_REMAP))
17669 +               *target = vdmt->target;
17670 +       else if (target)
17671 +               *target = device;
17672 +       if (flags)
17673 +               *flags = vdmt->flags;
17674 +
17675 +       spin_unlock(hash_lock);
17676 +
17677 +       return ret;
17678 +}
17679 +
17680 +
17681 +/*     __remove_mapping()
17682 + *     remove a mapping from the hash table
17683 + */
17684 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17685 +       umode_t mode)
17686 +{
17687 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17688 +       struct vs_mapping *vdm = NULL;
17689 +       int ret = 0;
17690 +
17691 +       spin_lock(hash_lock);
17692 +
17693 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17694 +               NULL);
17695 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17696 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17697 +       if (ret < 0)
17698 +               goto out;
17699 +       hlist_del(&vdm->dm_hlist);
17700 +
17701 +out:
17702 +       spin_unlock(hash_lock);
17703 +       if (vdm)
17704 +               kmem_cache_free(dmap_cachep, vdm);
17705 +       return ret;
17706 +}
17707 +
17708 +
17709 +
17710 +int vs_map_device(struct vx_info *vxi,
17711 +       dev_t device, dev_t *target, umode_t mode)
17712 +{
17713 +       int ret, flags = DATTR_MASK;
17714 +
17715 +       if (!vxi) {
17716 +               if (target)
17717 +                       *target = device;
17718 +               goto out;
17719 +       }
17720 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17721 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17722 +               device, target ? *target : 0, flags, mode, ret);
17723 +out:
17724 +       return (flags & DATTR_MASK);
17725 +}
17726 +
17727 +
17728 +
17729 +static int do_set_mapping(struct vx_info *vxi,
17730 +       dev_t device, dev_t target, int flags, umode_t mode)
17731 +{
17732 +       if (device) {
17733 +               struct vs_mapping *new;
17734 +
17735 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17736 +               if (!new)
17737 +                       return -ENOMEM;
17738 +
17739 +               INIT_HLIST_NODE(&new->dm_hlist);
17740 +               new->device = device;
17741 +               new->target.target = target;
17742 +               new->target.flags = flags | mode;
17743 +               new->xid = (vxi ? vxi->vx_id : 0);
17744 +
17745 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17746 +               __hash_mapping(vxi, new);
17747 +       } else {
17748 +               struct vx_dmap_target new = {
17749 +                       .target = target,
17750 +                       .flags = flags | mode,
17751 +               };
17752 +               __set_default(vxi, mode, &new);
17753 +       }
17754 +       return 0;
17755 +}
17756 +
17757 +
17758 +static int do_unset_mapping(struct vx_info *vxi,
17759 +       dev_t device, dev_t target, int flags, umode_t mode)
17760 +{
17761 +       int ret = -EINVAL;
17762 +
17763 +       if (device) {
17764 +               ret = __remove_mapping(vxi, device, mode);
17765 +               if (ret < 0)
17766 +                       goto out;
17767 +       } else {
17768 +               ret = __remove_default(vxi, mode);
17769 +               if (ret < 0)
17770 +                       goto out;
17771 +       }
17772 +
17773 +out:
17774 +       return ret;
17775 +}
17776 +
17777 +
17778 +static inline int __user_device(const char __user *name, dev_t *dev,
17779 +       umode_t *mode)
17780 +{
17781 +       struct nameidata nd;
17782 +       int ret;
17783 +
17784 +       if (!name) {
17785 +               *dev = 0;
17786 +               return 0;
17787 +       }
17788 +       ret = user_lpath(name, &nd.path);
17789 +       if (ret)
17790 +               return ret;
17791 +       if (nd.path.dentry->d_inode) {
17792 +               *dev = nd.path.dentry->d_inode->i_rdev;
17793 +               *mode = nd.path.dentry->d_inode->i_mode;
17794 +       }
17795 +       path_put(&nd.path);
17796 +       return 0;
17797 +}
17798 +
17799 +static inline int __mapping_mode(dev_t device, dev_t target,
17800 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17801 +{
17802 +       if (device)
17803 +               *mode = device_mode & S_IFMT;
17804 +       else if (target)
17805 +               *mode = target_mode & S_IFMT;
17806 +       else
17807 +               return -EINVAL;
17808 +
17809 +       /* if both given, device and target mode have to match */
17810 +       if (device && target &&
17811 +               ((device_mode ^ target_mode) & S_IFMT))
17812 +               return -EINVAL;
17813 +       return 0;
17814 +}
17815 +
17816 +
17817 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17818 +       const char __user *target_path, int flags, int set)
17819 +{
17820 +       dev_t device = ~0, target = ~0;
17821 +       umode_t device_mode = 0, target_mode = 0, mode;
17822 +       int ret;
17823 +
17824 +       ret = __user_device(device_path, &device, &device_mode);
17825 +       if (ret)
17826 +               return ret;
17827 +       ret = __user_device(target_path, &target, &target_mode);
17828 +       if (ret)
17829 +               return ret;
17830 +
17831 +       ret = __mapping_mode(device, target,
17832 +               device_mode, target_mode, &mode);
17833 +       if (ret)
17834 +               return ret;
17835 +
17836 +       if (set)
17837 +               return do_set_mapping(vxi, device, target,
17838 +                       flags, mode);
17839 +       else
17840 +               return do_unset_mapping(vxi, device, target,
17841 +                       flags, mode);
17842 +}
17843 +
17844 +
17845 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17846 +{
17847 +       struct vcmd_set_mapping_v0 vc_data;
17848 +
17849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17850 +               return -EFAULT;
17851 +
17852 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17853 +               vc_data.flags, 1);
17854 +}
17855 +
17856 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17857 +{
17858 +       struct vcmd_set_mapping_v0 vc_data;
17859 +
17860 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17861 +               return -EFAULT;
17862 +
17863 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17864 +               vc_data.flags, 0);
17865 +}
17866 +
17867 +
17868 +#ifdef CONFIG_COMPAT
17869 +
17870 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17871 +{
17872 +       struct vcmd_set_mapping_v0_x32 vc_data;
17873 +
17874 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17875 +               return -EFAULT;
17876 +
17877 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17878 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17879 +}
17880 +
17881 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17882 +{
17883 +       struct vcmd_set_mapping_v0_x32 vc_data;
17884 +
17885 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17886 +               return -EFAULT;
17887 +
17888 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17889 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17890 +}
17891 +
17892 +#endif /* CONFIG_COMPAT */
17893 +
17894 +
17895 diff -NurpP --minimal linux-3.5.4/kernel/vserver/dlimit.c linux-3.5.4-vs2.3.4.3/kernel/vserver/dlimit.c
17896 --- linux-3.5.4/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17897 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/dlimit.c       2012-07-23 01:45:55.000000000 +0200
17898 @@ -0,0 +1,531 @@
17899 +/*
17900 + *  linux/kernel/vserver/dlimit.c
17901 + *
17902 + *  Virtual Server: Context Disk Limits
17903 + *
17904 + *  Copyright (C) 2004-2009  Herbert Pötzl
17905 + *
17906 + *  V0.01  initial version
17907 + *  V0.02  compat32 splitup
17908 + *  V0.03  extended interface
17909 + *
17910 + */
17911 +
17912 +#include <linux/statfs.h>
17913 +#include <linux/sched.h>
17914 +#include <linux/namei.h>
17915 +#include <linux/vs_tag.h>
17916 +#include <linux/vs_dlimit.h>
17917 +#include <linux/vserver/dlimit_cmd.h>
17918 +#include <linux/slab.h>
17919 +// #include <linux/gfp.h>
17920 +
17921 +#include <asm/uaccess.h>
17922 +
17923 +/*     __alloc_dl_info()
17924 +
17925 +       * allocate an initialized dl_info struct
17926 +       * doesn't make it visible (hash)                        */
17927 +
17928 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17929 +{
17930 +       struct dl_info *new = NULL;
17931 +
17932 +       vxdprintk(VXD_CBIT(dlim, 5),
17933 +               "alloc_dl_info(%p,%d)*", sb, tag);
17934 +
17935 +       /* would this benefit from a slab cache? */
17936 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17937 +       if (!new)
17938 +               return 0;
17939 +
17940 +       memset(new, 0, sizeof(struct dl_info));
17941 +       new->dl_tag = tag;
17942 +       new->dl_sb = sb;
17943 +       // INIT_RCU_HEAD(&new->dl_rcu);
17944 +       INIT_HLIST_NODE(&new->dl_hlist);
17945 +       spin_lock_init(&new->dl_lock);
17946 +       atomic_set(&new->dl_refcnt, 0);
17947 +       atomic_set(&new->dl_usecnt, 0);
17948 +
17949 +       /* rest of init goes here */
17950 +
17951 +       vxdprintk(VXD_CBIT(dlim, 4),
17952 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17953 +       return new;
17954 +}
17955 +
17956 +/*     __dealloc_dl_info()
17957 +
17958 +       * final disposal of dl_info                             */
17959 +
17960 +static void __dealloc_dl_info(struct dl_info *dli)
17961 +{
17962 +       vxdprintk(VXD_CBIT(dlim, 4),
17963 +               "dealloc_dl_info(%p)", dli);
17964 +
17965 +       dli->dl_hlist.next = LIST_POISON1;
17966 +       dli->dl_tag = -1;
17967 +       dli->dl_sb = 0;
17968 +
17969 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17970 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17971 +
17972 +       kfree(dli);
17973 +}
17974 +
17975 +
17976 +/*     hash table for dl_info hash */
17977 +
17978 +#define DL_HASH_SIZE   13
17979 +
17980 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17981 +
17982 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17983 +
17984 +
17985 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17986 +{
17987 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17988 +}
17989 +
17990 +
17991 +
17992 +/*     __hash_dl_info()
17993 +
17994 +       * add the dli to the global hash table
17995 +       * requires the hash_lock to be held                     */
17996 +
17997 +static inline void __hash_dl_info(struct dl_info *dli)
17998 +{
17999 +       struct hlist_head *head;
18000 +
18001 +       vxdprintk(VXD_CBIT(dlim, 6),
18002 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18003 +       get_dl_info(dli);
18004 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18005 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18006 +}
18007 +
18008 +/*     __unhash_dl_info()
18009 +
18010 +       * remove the dli from the global hash table
18011 +       * requires the hash_lock to be held                     */
18012 +
18013 +static inline void __unhash_dl_info(struct dl_info *dli)
18014 +{
18015 +       vxdprintk(VXD_CBIT(dlim, 6),
18016 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18017 +       hlist_del_rcu(&dli->dl_hlist);
18018 +       put_dl_info(dli);
18019 +}
18020 +
18021 +
18022 +/*     __lookup_dl_info()
18023 +
18024 +       * requires the rcu_read_lock()
18025 +       * doesn't increment the dl_refcnt                       */
18026 +
18027 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18028 +{
18029 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18030 +       struct hlist_node *pos;
18031 +       struct dl_info *dli;
18032 +
18033 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18034 +
18035 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18036 +                       return dli;
18037 +               }
18038 +       }
18039 +       return NULL;
18040 +}
18041 +
18042 +
18043 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18044 +{
18045 +       struct dl_info *dli;
18046 +
18047 +       rcu_read_lock();
18048 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18049 +       vxdprintk(VXD_CBIT(dlim, 7),
18050 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18051 +       rcu_read_unlock();
18052 +       return dli;
18053 +}
18054 +
18055 +void rcu_free_dl_info(struct rcu_head *head)
18056 +{
18057 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18058 +       int usecnt, refcnt;
18059 +
18060 +       BUG_ON(!dli || !head);
18061 +
18062 +       usecnt = atomic_read(&dli->dl_usecnt);
18063 +       BUG_ON(usecnt < 0);
18064 +
18065 +       refcnt = atomic_read(&dli->dl_refcnt);
18066 +       BUG_ON(refcnt < 0);
18067 +
18068 +       vxdprintk(VXD_CBIT(dlim, 3),
18069 +               "rcu_free_dl_info(%p)", dli);
18070 +       if (!usecnt)
18071 +               __dealloc_dl_info(dli);
18072 +       else
18073 +               printk("!!! rcu didn't free\n");
18074 +}
18075 +
18076 +
18077 +
18078 +
18079 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18080 +       uint32_t flags, int add)
18081 +{
18082 +       struct path path;
18083 +       int ret;
18084 +
18085 +       ret = user_lpath(name, &path);
18086 +       if (!ret) {
18087 +               struct super_block *sb;
18088 +               struct dl_info *dli;
18089 +
18090 +               ret = -EINVAL;
18091 +               if (!path.dentry->d_inode)
18092 +                       goto out_release;
18093 +               if (!(sb = path.dentry->d_inode->i_sb))
18094 +                       goto out_release;
18095 +
18096 +               if (add) {
18097 +                       dli = __alloc_dl_info(sb, id);
18098 +                       spin_lock(&dl_info_hash_lock);
18099 +
18100 +                       ret = -EEXIST;
18101 +                       if (__lookup_dl_info(sb, id))
18102 +                               goto out_unlock;
18103 +                       __hash_dl_info(dli);
18104 +                       dli = NULL;
18105 +               } else {
18106 +                       spin_lock(&dl_info_hash_lock);
18107 +                       dli = __lookup_dl_info(sb, id);
18108 +
18109 +                       ret = -ESRCH;
18110 +                       if (!dli)
18111 +                               goto out_unlock;
18112 +                       __unhash_dl_info(dli);
18113 +               }
18114 +               ret = 0;
18115 +       out_unlock:
18116 +               spin_unlock(&dl_info_hash_lock);
18117 +               if (add && dli)
18118 +                       __dealloc_dl_info(dli);
18119 +       out_release:
18120 +               path_put(&path);
18121 +       }
18122 +       return ret;
18123 +}
18124 +
18125 +int vc_add_dlimit(uint32_t id, void __user *data)
18126 +{
18127 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18128 +
18129 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18130 +               return -EFAULT;
18131 +
18132 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18133 +}
18134 +
18135 +int vc_rem_dlimit(uint32_t id, void __user *data)
18136 +{
18137 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18138 +
18139 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18140 +               return -EFAULT;
18141 +
18142 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18143 +}
18144 +
18145 +#ifdef CONFIG_COMPAT
18146 +
18147 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18148 +{
18149 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18150 +
18151 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18152 +               return -EFAULT;
18153 +
18154 +       return do_addrem_dlimit(id,
18155 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18156 +}
18157 +
18158 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18159 +{
18160 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18161 +
18162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18163 +               return -EFAULT;
18164 +
18165 +       return do_addrem_dlimit(id,
18166 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18167 +}
18168 +
18169 +#endif /* CONFIG_COMPAT */
18170 +
18171 +
18172 +static inline
18173 +int do_set_dlimit(uint32_t id, const char __user *name,
18174 +       uint32_t space_used, uint32_t space_total,
18175 +       uint32_t inodes_used, uint32_t inodes_total,
18176 +       uint32_t reserved, uint32_t flags)
18177 +{
18178 +       struct path path;
18179 +       int ret;
18180 +
18181 +       ret = user_lpath(name, &path);
18182 +       if (!ret) {
18183 +               struct super_block *sb;
18184 +               struct dl_info *dli;
18185 +
18186 +               ret = -EINVAL;
18187 +               if (!path.dentry->d_inode)
18188 +                       goto out_release;
18189 +               if (!(sb = path.dentry->d_inode->i_sb))
18190 +                       goto out_release;
18191 +
18192 +               /* sanity checks */
18193 +               if ((reserved != CDLIM_KEEP &&
18194 +                       reserved > 100) ||
18195 +                       (inodes_used != CDLIM_KEEP &&
18196 +                       inodes_used > inodes_total) ||
18197 +                       (space_used != CDLIM_KEEP &&
18198 +                       space_used > space_total))
18199 +                       goto out_release;
18200 +
18201 +               ret = -ESRCH;
18202 +               dli = locate_dl_info(sb, id);
18203 +               if (!dli)
18204 +                       goto out_release;
18205 +
18206 +               spin_lock(&dli->dl_lock);
18207 +
18208 +               if (inodes_used != CDLIM_KEEP)
18209 +                       dli->dl_inodes_used = inodes_used;
18210 +               if (inodes_total != CDLIM_KEEP)
18211 +                       dli->dl_inodes_total = inodes_total;
18212 +               if (space_used != CDLIM_KEEP)
18213 +                       dli->dl_space_used = dlimit_space_32to64(
18214 +                               space_used, flags, DLIMS_USED);
18215 +
18216 +               if (space_total == CDLIM_INFINITY)
18217 +                       dli->dl_space_total = DLIM_INFINITY;
18218 +               else if (space_total != CDLIM_KEEP)
18219 +                       dli->dl_space_total = dlimit_space_32to64(
18220 +                               space_total, flags, DLIMS_TOTAL);
18221 +
18222 +               if (reserved != CDLIM_KEEP)
18223 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18224 +
18225 +               spin_unlock(&dli->dl_lock);
18226 +
18227 +               put_dl_info(dli);
18228 +               ret = 0;
18229 +
18230 +       out_release:
18231 +               path_put(&path);
18232 +       }
18233 +       return ret;
18234 +}
18235 +
18236 +int vc_set_dlimit(uint32_t id, void __user *data)
18237 +{
18238 +       struct vcmd_ctx_dlimit_v0 vc_data;
18239 +
18240 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18241 +               return -EFAULT;
18242 +
18243 +       return do_set_dlimit(id, vc_data.name,
18244 +               vc_data.space_used, vc_data.space_total,
18245 +               vc_data.inodes_used, vc_data.inodes_total,
18246 +               vc_data.reserved, vc_data.flags);
18247 +}
18248 +
18249 +#ifdef CONFIG_COMPAT
18250 +
18251 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18252 +{
18253 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18254 +
18255 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18256 +               return -EFAULT;
18257 +
18258 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18259 +               vc_data.space_used, vc_data.space_total,
18260 +               vc_data.inodes_used, vc_data.inodes_total,
18261 +               vc_data.reserved, vc_data.flags);
18262 +}
18263 +
18264 +#endif /* CONFIG_COMPAT */
18265 +
18266 +
18267 +static inline
18268 +int do_get_dlimit(uint32_t id, const char __user *name,
18269 +       uint32_t *space_used, uint32_t *space_total,
18270 +       uint32_t *inodes_used, uint32_t *inodes_total,
18271 +       uint32_t *reserved, uint32_t *flags)
18272 +{
18273 +       struct path path;
18274 +       int ret;
18275 +
18276 +       ret = user_lpath(name, &path);
18277 +       if (!ret) {
18278 +               struct super_block *sb;
18279 +               struct dl_info *dli;
18280 +
18281 +               ret = -EINVAL;
18282 +               if (!path.dentry->d_inode)
18283 +                       goto out_release;
18284 +               if (!(sb = path.dentry->d_inode->i_sb))
18285 +                       goto out_release;
18286 +
18287 +               ret = -ESRCH;
18288 +               dli = locate_dl_info(sb, id);
18289 +               if (!dli)
18290 +                       goto out_release;
18291 +
18292 +               spin_lock(&dli->dl_lock);
18293 +               *inodes_used = dli->dl_inodes_used;
18294 +               *inodes_total = dli->dl_inodes_total;
18295 +
18296 +               *space_used = dlimit_space_64to32(
18297 +                       dli->dl_space_used, flags, DLIMS_USED);
18298 +
18299 +               if (dli->dl_space_total == DLIM_INFINITY)
18300 +                       *space_total = CDLIM_INFINITY;
18301 +               else
18302 +                       *space_total = dlimit_space_64to32(
18303 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18304 +
18305 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18306 +               spin_unlock(&dli->dl_lock);
18307 +
18308 +               put_dl_info(dli);
18309 +               ret = -EFAULT;
18310 +
18311 +               ret = 0;
18312 +       out_release:
18313 +               path_put(&path);
18314 +       }
18315 +       return ret;
18316 +}
18317 +
18318 +
18319 +int vc_get_dlimit(uint32_t id, void __user *data)
18320 +{
18321 +       struct vcmd_ctx_dlimit_v0 vc_data;
18322 +       int ret;
18323 +
18324 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18325 +               return -EFAULT;
18326 +
18327 +       ret = do_get_dlimit(id, vc_data.name,
18328 +               &vc_data.space_used, &vc_data.space_total,
18329 +               &vc_data.inodes_used, &vc_data.inodes_total,
18330 +               &vc_data.reserved, &vc_data.flags);
18331 +       if (ret)
18332 +               return ret;
18333 +
18334 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18335 +               return -EFAULT;
18336 +       return 0;
18337 +}
18338 +
18339 +#ifdef CONFIG_COMPAT
18340 +
18341 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18342 +{
18343 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18344 +       int ret;
18345 +
18346 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18347 +               return -EFAULT;
18348 +
18349 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18350 +               &vc_data.space_used, &vc_data.space_total,
18351 +               &vc_data.inodes_used, &vc_data.inodes_total,
18352 +               &vc_data.reserved, &vc_data.flags);
18353 +       if (ret)
18354 +               return ret;
18355 +
18356 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18357 +               return -EFAULT;
18358 +       return 0;
18359 +}
18360 +
18361 +#endif /* CONFIG_COMPAT */
18362 +
18363 +
18364 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18365 +{
18366 +       struct dl_info *dli;
18367 +       __u64 blimit, bfree, bavail;
18368 +       __u32 ifree;
18369 +
18370 +       dli = locate_dl_info(sb, dx_current_tag());
18371 +       if (!dli)
18372 +               return;
18373 +
18374 +       spin_lock(&dli->dl_lock);
18375 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18376 +               goto no_ilim;
18377 +
18378 +       /* reduce max inodes available to limit */
18379 +       if (buf->f_files > dli->dl_inodes_total)
18380 +               buf->f_files = dli->dl_inodes_total;
18381 +
18382 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18383 +       /* reduce free inodes to min */
18384 +       if (ifree < buf->f_ffree)
18385 +               buf->f_ffree = ifree;
18386 +
18387 +no_ilim:
18388 +       if (dli->dl_space_total == DLIM_INFINITY)
18389 +               goto no_blim;
18390 +
18391 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18392 +
18393 +       if (dli->dl_space_total < dli->dl_space_used)
18394 +               bfree = 0;
18395 +       else
18396 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18397 +                       >> sb->s_blocksize_bits;
18398 +
18399 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18400 +       if (bavail < dli->dl_space_used)
18401 +               bavail = 0;
18402 +       else
18403 +               bavail = (bavail - dli->dl_space_used)
18404 +                       >> sb->s_blocksize_bits;
18405 +
18406 +       /* reduce max space available to limit */
18407 +       if (buf->f_blocks > blimit)
18408 +               buf->f_blocks = blimit;
18409 +
18410 +       /* reduce free space to min */
18411 +       if (bfree < buf->f_bfree)
18412 +               buf->f_bfree = bfree;
18413 +
18414 +       /* reduce avail space to min */
18415 +       if (bavail < buf->f_bavail)
18416 +               buf->f_bavail = bavail;
18417 +
18418 +no_blim:
18419 +       spin_unlock(&dli->dl_lock);
18420 +       put_dl_info(dli);
18421 +
18422 +       return;
18423 +}
18424 +
18425 +#include <linux/module.h>
18426 +
18427 +EXPORT_SYMBOL_GPL(locate_dl_info);
18428 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18429 +
18430 diff -NurpP --minimal linux-3.5.4/kernel/vserver/helper.c linux-3.5.4-vs2.3.4.3/kernel/vserver/helper.c
18431 --- linux-3.5.4/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18432 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/helper.c       2012-09-16 17:54:50.000000000 +0200
18433 @@ -0,0 +1,229 @@
18434 +/*
18435 + *  linux/kernel/vserver/helper.c
18436 + *
18437 + *  Virtual Context Support
18438 + *
18439 + *  Copyright (C) 2004-2007  Herbert Pötzl
18440 + *
18441 + *  V0.01  basic helper
18442 + *
18443 + */
18444 +
18445 +#include <linux/kmod.h>
18446 +#include <linux/reboot.h>
18447 +#include <linux/vs_context.h>
18448 +#include <linux/vs_network.h>
18449 +#include <linux/vserver/signal.h>
18450 +
18451 +
18452 +char vshelper_path[255] = "/sbin/vshelper";
18453 +
18454 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18455 +{
18456 +       current->flags &= ~PF_THREAD_BOUND;
18457 +       return 0;
18458 +}
18459 +
18460 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18461 +{
18462 +       int ret;
18463 +
18464 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18465 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18466 +               vshelper_init, NULL, NULL))) {
18467 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18468 +                       name, argv[1], argv[2],
18469 +                       sync ? "sync" : "async", ret);
18470 +       }
18471 +       vxdprintk(VXD_CBIT(switch, 4),
18472 +               "%s: (%s %s) returned %s with %d",
18473 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18474 +       return ret;
18475 +}
18476 +
18477 +/*
18478 + *      vshelper path is set via /proc/sys
18479 + *      invoked by vserver sys_reboot(), with
18480 + *      the following arguments
18481 + *
18482 + *      argv [0] = vshelper_path;
18483 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18484 + *      argv [2] = context identifier
18485 + *
18486 + *      envp [*] = type-specific parameters
18487 + */
18488 +
18489 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18490 +{
18491 +       char id_buf[8], cmd_buf[16];
18492 +       char uid_buf[16], pid_buf[16];
18493 +       int ret;
18494 +
18495 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18496 +       char *envp[] = {"HOME=/", "TERM=linux",
18497 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18498 +                       uid_buf, pid_buf, cmd_buf, 0};
18499 +
18500 +       if (vx_info_state(vxi, VXS_HELPER))
18501 +               return -EAGAIN;
18502 +       vxi->vx_state |= VXS_HELPER;
18503 +
18504 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18505 +
18506 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18507 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18508 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18509 +
18510 +       switch (cmd) {
18511 +       case LINUX_REBOOT_CMD_RESTART:
18512 +               argv[1] = "restart";
18513 +               break;
18514 +
18515 +       case LINUX_REBOOT_CMD_HALT:
18516 +               argv[1] = "halt";
18517 +               break;
18518 +
18519 +       case LINUX_REBOOT_CMD_POWER_OFF:
18520 +               argv[1] = "poweroff";
18521 +               break;
18522 +
18523 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18524 +               argv[1] = "swsusp";
18525 +               break;
18526 +
18527 +       case LINUX_REBOOT_CMD_OOM:
18528 +               argv[1] = "oom";
18529 +               break;
18530 +
18531 +       default:
18532 +               vxi->vx_state &= ~VXS_HELPER;
18533 +               return 0;
18534 +       }
18535 +
18536 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18537 +       vxi->vx_state &= ~VXS_HELPER;
18538 +       __wakeup_vx_info(vxi);
18539 +       return (ret) ? -EPERM : 0;
18540 +}
18541 +
18542 +
18543 +long vs_reboot(unsigned int cmd, void __user *arg)
18544 +{
18545 +       struct vx_info *vxi = current_vx_info();
18546 +       long ret = 0;
18547 +
18548 +       vxdprintk(VXD_CBIT(misc, 5),
18549 +               "vs_reboot(%p[#%d],%u)",
18550 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18551 +
18552 +       ret = vs_reboot_helper(vxi, cmd, arg);
18553 +       if (ret)
18554 +               return ret;
18555 +
18556 +       vxi->reboot_cmd = cmd;
18557 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18558 +               switch (cmd) {
18559 +               case LINUX_REBOOT_CMD_RESTART:
18560 +               case LINUX_REBOOT_CMD_HALT:
18561 +               case LINUX_REBOOT_CMD_POWER_OFF:
18562 +                       vx_info_kill(vxi, 0, SIGKILL);
18563 +                       vx_info_kill(vxi, 1, SIGKILL);
18564 +               default:
18565 +                       break;
18566 +               }
18567 +       }
18568 +       return 0;
18569 +}
18570 +
18571 +long vs_oom_action(unsigned int cmd)
18572 +{
18573 +       struct vx_info *vxi = current_vx_info();
18574 +       long ret = 0;
18575 +
18576 +       vxdprintk(VXD_CBIT(misc, 5),
18577 +               "vs_oom_action(%p[#%d],%u)",
18578 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18579 +
18580 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18581 +       if (ret)
18582 +               return ret;
18583 +
18584 +       vxi->reboot_cmd = cmd;
18585 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18586 +               vx_info_kill(vxi, 0, SIGKILL);
18587 +               vx_info_kill(vxi, 1, SIGKILL);
18588 +       }
18589 +       return 0;
18590 +}
18591 +
18592 +/*
18593 + *      argv [0] = vshelper_path;
18594 + *      argv [1] = action: "startup", "shutdown"
18595 + *      argv [2] = context identifier
18596 + *
18597 + *      envp [*] = type-specific parameters
18598 + */
18599 +
18600 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18601 +{
18602 +       char id_buf[8], cmd_buf[16];
18603 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18604 +       char *envp[] = {"HOME=/", "TERM=linux",
18605 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18606 +
18607 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18608 +               return 0;
18609 +
18610 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18611 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18612 +
18613 +       switch (cmd) {
18614 +       case VSC_STARTUP:
18615 +               argv[1] = "startup";
18616 +               break;
18617 +       case VSC_SHUTDOWN:
18618 +               argv[1] = "shutdown";
18619 +               break;
18620 +       default:
18621 +               return 0;
18622 +       }
18623 +
18624 +       return do_vshelper(vshelper_path, argv, envp, 1);
18625 +}
18626 +
18627 +
18628 +/*
18629 + *      argv [0] = vshelper_path;
18630 + *      argv [1] = action: "netup", "netdown"
18631 + *      argv [2] = context identifier
18632 + *
18633 + *      envp [*] = type-specific parameters
18634 + */
18635 +
18636 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18637 +{
18638 +       char id_buf[8], cmd_buf[16];
18639 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18640 +       char *envp[] = {"HOME=/", "TERM=linux",
18641 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18642 +
18643 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18644 +               return 0;
18645 +
18646 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18647 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18648 +
18649 +       switch (cmd) {
18650 +       case VSC_NETUP:
18651 +               argv[1] = "netup";
18652 +               break;
18653 +       case VSC_NETDOWN:
18654 +               argv[1] = "netdown";
18655 +               break;
18656 +       default:
18657 +               return 0;
18658 +       }
18659 +
18660 +       return do_vshelper(vshelper_path, argv, envp, 1);
18661 +}
18662 +
18663 diff -NurpP --minimal linux-3.5.4/kernel/vserver/history.c linux-3.5.4-vs2.3.4.3/kernel/vserver/history.c
18664 --- linux-3.5.4/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18665 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/history.c      2012-07-23 01:45:55.000000000 +0200
18666 @@ -0,0 +1,258 @@
18667 +/*
18668 + *  kernel/vserver/history.c
18669 + *
18670 + *  Virtual Context History Backtrace
18671 + *
18672 + *  Copyright (C) 2004-2007  Herbert Pötzl
18673 + *
18674 + *  V0.01  basic structure
18675 + *  V0.02  hash/unhash and trace
18676 + *  V0.03  preemption fixes
18677 + *
18678 + */
18679 +
18680 +#include <linux/module.h>
18681 +#include <asm/uaccess.h>
18682 +
18683 +#include <linux/vserver/context.h>
18684 +#include <linux/vserver/debug.h>
18685 +#include <linux/vserver/debug_cmd.h>
18686 +#include <linux/vserver/history.h>
18687 +
18688 +
18689 +#ifdef CONFIG_VSERVER_HISTORY
18690 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18691 +#else
18692 +#define VXH_SIZE       64
18693 +#endif
18694 +
18695 +struct _vx_history {
18696 +       unsigned int counter;
18697 +
18698 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18699 +};
18700 +
18701 +
18702 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18703 +
18704 +unsigned volatile int vxh_active = 1;
18705 +
18706 +static atomic_t sequence = ATOMIC_INIT(0);
18707 +
18708 +
18709 +/*     vxh_advance()
18710 +
18711 +       * requires disabled preemption                          */
18712 +
18713 +struct _vx_hist_entry *vxh_advance(void *loc)
18714 +{
18715 +       unsigned int cpu = smp_processor_id();
18716 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18717 +       struct _vx_hist_entry *entry;
18718 +       unsigned int index;
18719 +
18720 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18721 +       entry = &hist->entry[index];
18722 +
18723 +       entry->seq = atomic_inc_return(&sequence);
18724 +       entry->loc = loc;
18725 +       return entry;
18726 +}
18727 +
18728 +EXPORT_SYMBOL_GPL(vxh_advance);
18729 +
18730 +
18731 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18732 +
18733 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18734 +
18735 +
18736 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18737 +
18738 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18739 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18740 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18741 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18742 +
18743 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18744 +{
18745 +       switch (e->type) {
18746 +       case VXH_THROW_OOPS:
18747 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18748 +               break;
18749 +
18750 +       case VXH_GET_VX_INFO:
18751 +       case VXH_PUT_VX_INFO:
18752 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18753 +                       VXH_LOC_ARGS(e),
18754 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18755 +                       VXH_VXI_ARGS(e));
18756 +               break;
18757 +
18758 +       case VXH_INIT_VX_INFO:
18759 +       case VXH_SET_VX_INFO:
18760 +       case VXH_CLR_VX_INFO:
18761 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18762 +                       VXH_LOC_ARGS(e),
18763 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18764 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18765 +                       VXH_VXI_ARGS(e), e->sc.data);
18766 +               break;
18767 +
18768 +       case VXH_CLAIM_VX_INFO:
18769 +       case VXH_RELEASE_VX_INFO:
18770 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18771 +                       VXH_LOC_ARGS(e),
18772 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18773 +                       VXH_VXI_ARGS(e), e->sc.data);
18774 +               break;
18775 +
18776 +       case VXH_ALLOC_VX_INFO:
18777 +       case VXH_DEALLOC_VX_INFO:
18778 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18779 +                       VXH_LOC_ARGS(e),
18780 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18781 +                       VXH_VXI_ARGS(e));
18782 +               break;
18783 +
18784 +       case VXH_HASH_VX_INFO:
18785 +       case VXH_UNHASH_VX_INFO:
18786 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18787 +                       VXH_LOC_ARGS(e),
18788 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18789 +                       VXH_VXI_ARGS(e));
18790 +               break;
18791 +
18792 +       case VXH_LOC_VX_INFO:
18793 +       case VXH_LOOKUP_VX_INFO:
18794 +       case VXH_CREATE_VX_INFO:
18795 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18796 +                       VXH_LOC_ARGS(e),
18797 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18798 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18799 +                       e->ll.arg, VXH_VXI_ARGS(e));
18800 +               break;
18801 +       }
18802 +}
18803 +
18804 +static void __vxh_dump_history(void)
18805 +{
18806 +       unsigned int i, cpu;
18807 +
18808 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18809 +               atomic_read(&sequence), NR_CPUS);
18810 +
18811 +       for (i = 0; i < VXH_SIZE; i++) {
18812 +               for_each_online_cpu(cpu) {
18813 +                       struct _vx_history *hist =
18814 +                               &per_cpu(vx_history_buffer, cpu);
18815 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18816 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18817 +
18818 +                       vxh_dump_entry(entry, cpu);
18819 +               }
18820 +       }
18821 +}
18822 +
18823 +void   vxh_dump_history(void)
18824 +{
18825 +       vxh_active = 0;
18826 +#ifdef CONFIG_SMP
18827 +       local_irq_enable();
18828 +       smp_send_stop();
18829 +       local_irq_disable();
18830 +#endif
18831 +       __vxh_dump_history();
18832 +}
18833 +
18834 +
18835 +/* vserver syscall commands below here */
18836 +
18837 +
18838 +int vc_dump_history(uint32_t id)
18839 +{
18840 +       vxh_active = 0;
18841 +       __vxh_dump_history();
18842 +       vxh_active = 1;
18843 +
18844 +       return 0;
18845 +}
18846 +
18847 +
18848 +int do_read_history(struct __user _vx_hist_entry *data,
18849 +       int cpu, uint32_t *index, uint32_t *count)
18850 +{
18851 +       int pos, ret = 0;
18852 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18853 +       int end = hist->counter;
18854 +       int start = end - VXH_SIZE + 2;
18855 +       int idx = *index;
18856 +
18857 +       /* special case: get current pos */
18858 +       if (!*count) {
18859 +               *index = end;
18860 +               return 0;
18861 +       }
18862 +
18863 +       /* have we lost some data? */
18864 +       if (idx < start)
18865 +               idx = start;
18866 +
18867 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18868 +               struct _vx_hist_entry *entry =
18869 +                       &hist->entry[idx % VXH_SIZE];
18870 +
18871 +               /* send entry to userspace */
18872 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18873 +               if (ret)
18874 +                       break;
18875 +       }
18876 +       /* save new index and count */
18877 +       *index = idx;
18878 +       *count = pos;
18879 +       return ret ? ret : (*index < end);
18880 +}
18881 +
18882 +int vc_read_history(uint32_t id, void __user *data)
18883 +{
18884 +       struct vcmd_read_history_v0 vc_data;
18885 +       int ret;
18886 +
18887 +       if (id >= NR_CPUS)
18888 +               return -EINVAL;
18889 +
18890 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18891 +               return -EFAULT;
18892 +
18893 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18894 +               id, &vc_data.index, &vc_data.count);
18895 +
18896 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18897 +               return -EFAULT;
18898 +       return ret;
18899 +}
18900 +
18901 +#ifdef CONFIG_COMPAT
18902 +
18903 +int vc_read_history_x32(uint32_t id, void __user *data)
18904 +{
18905 +       struct vcmd_read_history_v0_x32 vc_data;
18906 +       int ret;
18907 +
18908 +       if (id >= NR_CPUS)
18909 +               return -EINVAL;
18910 +
18911 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18912 +               return -EFAULT;
18913 +
18914 +       ret = do_read_history((struct __user _vx_hist_entry *)
18915 +               compat_ptr(vc_data.data_ptr),
18916 +               id, &vc_data.index, &vc_data.count);
18917 +
18918 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18919 +               return -EFAULT;
18920 +       return ret;
18921 +}
18922 +
18923 +#endif /* CONFIG_COMPAT */
18924 +
18925 diff -NurpP --minimal linux-3.5.4/kernel/vserver/inet.c linux-3.5.4-vs2.3.4.3/kernel/vserver/inet.c
18926 --- linux-3.5.4/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
18927 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/inet.c 2012-07-23 01:45:55.000000000 +0200
18928 @@ -0,0 +1,226 @@
18929 +
18930 +#include <linux/in.h>
18931 +#include <linux/inetdevice.h>
18932 +#include <linux/export.h>
18933 +#include <linux/vs_inet.h>
18934 +#include <linux/vs_inet6.h>
18935 +#include <linux/vserver/debug.h>
18936 +#include <net/route.h>
18937 +#include <net/addrconf.h>
18938 +
18939 +
18940 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18941 +{
18942 +       int ret = 0;
18943 +
18944 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18945 +               ret = 1;
18946 +       else {
18947 +               struct nx_addr_v4 *ptr;
18948 +
18949 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18950 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18951 +                               ret = 1;
18952 +                               break;
18953 +                       }
18954 +               }
18955 +       }
18956 +
18957 +       vxdprintk(VXD_CBIT(net, 2),
18958 +               "nx_v4_addr_conflict(%p,%p): %d",
18959 +               nxi1, nxi2, ret);
18960 +
18961 +       return ret;
18962 +}
18963 +
18964 +
18965 +#ifdef CONFIG_IPV6
18966 +
18967 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18968 +{
18969 +       int ret = 0;
18970 +
18971 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18972 +               ret = 1;
18973 +       else {
18974 +               struct nx_addr_v6 *ptr;
18975 +
18976 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18977 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18978 +                               ret = 1;
18979 +                               break;
18980 +                       }
18981 +               }
18982 +       }
18983 +
18984 +       vxdprintk(VXD_CBIT(net, 2),
18985 +               "nx_v6_addr_conflict(%p,%p): %d",
18986 +               nxi1, nxi2, ret);
18987 +
18988 +       return ret;
18989 +}
18990 +
18991 +#endif
18992 +
18993 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18994 +{
18995 +       struct in_device *in_dev;
18996 +       struct in_ifaddr **ifap;
18997 +       struct in_ifaddr *ifa;
18998 +       int ret = 0;
18999 +
19000 +       if (!dev)
19001 +               goto out;
19002 +       in_dev = in_dev_get(dev);
19003 +       if (!in_dev)
19004 +               goto out;
19005 +
19006 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19007 +               ifap = &ifa->ifa_next) {
19008 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19009 +                       ret = 1;
19010 +                       break;
19011 +               }
19012 +       }
19013 +       in_dev_put(in_dev);
19014 +out:
19015 +       return ret;
19016 +}
19017 +
19018 +
19019 +#ifdef CONFIG_IPV6
19020 +
19021 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19022 +{
19023 +       struct inet6_dev *in_dev;
19024 +       struct inet6_ifaddr *ifa;
19025 +       int ret = 0;
19026 +
19027 +       if (!dev)
19028 +               goto out;
19029 +       in_dev = in6_dev_get(dev);
19030 +       if (!in_dev)
19031 +               goto out;
19032 +
19033 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19034 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19035 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19036 +                       ret = 1;
19037 +                       break;
19038 +               }
19039 +       }
19040 +       in6_dev_put(in_dev);
19041 +out:
19042 +       return ret;
19043 +}
19044 +
19045 +#endif
19046 +
19047 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19048 +{
19049 +       int ret = 1;
19050 +
19051 +       if (!nxi)
19052 +               goto out;
19053 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19054 +               goto out;
19055 +#ifdef CONFIG_IPV6
19056 +       ret = 2;
19057 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19058 +               goto out;
19059 +#endif
19060 +       ret = 0;
19061 +out:
19062 +       vxdprintk(VXD_CBIT(net, 3),
19063 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19064 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19065 +       return ret;
19066 +}
19067 +
19068 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19069 +       struct flowi4 *fl4)
19070 +{
19071 +       struct rtable *rt;
19072 +
19073 +       if (!nxi)
19074 +               return NULL;
19075 +
19076 +       /* FIXME: handle lback only case */
19077 +       if (!NX_IPV4(nxi))
19078 +               return ERR_PTR(-EPERM);
19079 +
19080 +       vxdprintk(VXD_CBIT(net, 4),
19081 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19082 +               nxi, nxi ? nxi->nx_id : 0,
19083 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19084 +
19085 +       /* single IP is unconditional */
19086 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19087 +               (fl4->saddr == INADDR_ANY))
19088 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19089 +
19090 +       if (fl4->saddr == INADDR_ANY) {
19091 +               struct nx_addr_v4 *ptr;
19092 +               __be32 found = 0;
19093 +
19094 +               rt = __ip_route_output_key(net, fl4);
19095 +               if (!IS_ERR(rt)) {
19096 +                       found = fl4->saddr;
19097 +                       ip_rt_put(rt);
19098 +                       vxdprintk(VXD_CBIT(net, 4),
19099 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19100 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19101 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19102 +                               goto found;
19103 +               }
19104 +
19105 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19106 +                       __be32 primary = ptr->ip[0].s_addr;
19107 +                       __be32 mask = ptr->mask.s_addr;
19108 +                       __be32 neta = primary & mask;
19109 +
19110 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19111 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19112 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19113 +                               NIPQUAD(mask), NIPQUAD(neta));
19114 +                       if ((found & mask) != neta)
19115 +                               continue;
19116 +
19117 +                       fl4->saddr = primary;
19118 +                       rt = __ip_route_output_key(net, fl4);
19119 +                       vxdprintk(VXD_CBIT(net, 4),
19120 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19121 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19122 +                       if (!IS_ERR(rt)) {
19123 +                               found = fl4->saddr;
19124 +                               ip_rt_put(rt);
19125 +                               if (found == primary)
19126 +                                       goto found;
19127 +                       }
19128 +               }
19129 +               /* still no source ip? */
19130 +               found = ipv4_is_loopback(fl4->daddr)
19131 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19132 +       found:
19133 +               /* assign src ip to flow */
19134 +               fl4->saddr = found;
19135 +
19136 +       } else {
19137 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19138 +                       return ERR_PTR(-EPERM);
19139 +       }
19140 +
19141 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19142 +               if (ipv4_is_loopback(fl4->daddr))
19143 +                       fl4->daddr = nxi->v4_lback.s_addr;
19144 +               if (ipv4_is_loopback(fl4->saddr))
19145 +                       fl4->saddr = nxi->v4_lback.s_addr;
19146 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19147 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19148 +               return ERR_PTR(-EPERM);
19149 +
19150 +       return NULL;
19151 +}
19152 +
19153 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19154 +
19155 diff -NurpP --minimal linux-3.5.4/kernel/vserver/init.c linux-3.5.4-vs2.3.4.3/kernel/vserver/init.c
19156 --- linux-3.5.4/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19157 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/init.c 2012-07-23 01:45:55.000000000 +0200
19158 @@ -0,0 +1,45 @@
19159 +/*
19160 + *  linux/kernel/init.c
19161 + *
19162 + *  Virtual Server Init
19163 + *
19164 + *  Copyright (C) 2004-2007  Herbert Pötzl
19165 + *
19166 + *  V0.01  basic structure
19167 + *
19168 + */
19169 +
19170 +#include <linux/init.h>
19171 +
19172 +int    vserver_register_sysctl(void);
19173 +void   vserver_unregister_sysctl(void);
19174 +
19175 +
19176 +static int __init init_vserver(void)
19177 +{
19178 +       int ret = 0;
19179 +
19180 +#ifdef CONFIG_VSERVER_DEBUG
19181 +       vserver_register_sysctl();
19182 +#endif
19183 +       return ret;
19184 +}
19185 +
19186 +
19187 +static void __exit exit_vserver(void)
19188 +{
19189 +
19190 +#ifdef CONFIG_VSERVER_DEBUG
19191 +       vserver_unregister_sysctl();
19192 +#endif
19193 +       return;
19194 +}
19195 +
19196 +/* FIXME: GFP_ZONETYPES gone
19197 +long vx_slab[GFP_ZONETYPES]; */
19198 +long vx_area;
19199 +
19200 +
19201 +module_init(init_vserver);
19202 +module_exit(exit_vserver);
19203 +
19204 diff -NurpP --minimal linux-3.5.4/kernel/vserver/inode.c linux-3.5.4-vs2.3.4.3/kernel/vserver/inode.c
19205 --- linux-3.5.4/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19206 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/inode.c        2012-07-23 01:45:55.000000000 +0200
19207 @@ -0,0 +1,437 @@
19208 +/*
19209 + *  linux/kernel/vserver/inode.c
19210 + *
19211 + *  Virtual Server: File System Support
19212 + *
19213 + *  Copyright (C) 2004-2007  Herbert Pötzl
19214 + *
19215 + *  V0.01  separated from vcontext V0.05
19216 + *  V0.02  moved to tag (instead of xid)
19217 + *
19218 + */
19219 +
19220 +#include <linux/tty.h>
19221 +#include <linux/proc_fs.h>
19222 +#include <linux/devpts_fs.h>
19223 +#include <linux/fs.h>
19224 +#include <linux/file.h>
19225 +#include <linux/mount.h>
19226 +#include <linux/parser.h>
19227 +#include <linux/namei.h>
19228 +#include <linux/vserver/inode.h>
19229 +#include <linux/vserver/inode_cmd.h>
19230 +#include <linux/vs_base.h>
19231 +#include <linux/vs_tag.h>
19232 +
19233 +#include <asm/uaccess.h>
19234 +
19235 +
19236 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19237 +{
19238 +       struct proc_dir_entry *entry;
19239 +
19240 +       if (!in || !in->i_sb)
19241 +               return -ESRCH;
19242 +
19243 +       *flags = IATTR_TAG
19244 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19245 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19246 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19247 +               | (IS_COW(in) ? IATTR_COW : 0);
19248 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19249 +
19250 +       if (S_ISDIR(in->i_mode))
19251 +               *mask |= IATTR_BARRIER;
19252 +
19253 +       if (IS_TAGGED(in)) {
19254 +               *tag = in->i_tag;
19255 +               *mask |= IATTR_TAG;
19256 +       }
19257 +
19258 +       switch (in->i_sb->s_magic) {
19259 +       case PROC_SUPER_MAGIC:
19260 +               entry = PROC_I(in)->pde;
19261 +
19262 +               /* check for specific inodes? */
19263 +               if (entry)
19264 +                       *mask |= IATTR_FLAGS;
19265 +               if (entry)
19266 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19267 +               else
19268 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19269 +               break;
19270 +
19271 +       case DEVPTS_SUPER_MAGIC:
19272 +               *tag = in->i_tag;
19273 +               *mask |= IATTR_TAG;
19274 +               break;
19275 +
19276 +       default:
19277 +               break;
19278 +       }
19279 +       return 0;
19280 +}
19281 +
19282 +int vc_get_iattr(void __user *data)
19283 +{
19284 +       struct path path;
19285 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19286 +       int ret;
19287 +
19288 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19289 +               return -EFAULT;
19290 +
19291 +       ret = user_lpath(vc_data.name, &path);
19292 +       if (!ret) {
19293 +               ret = __vc_get_iattr(path.dentry->d_inode,
19294 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19295 +               path_put(&path);
19296 +       }
19297 +       if (ret)
19298 +               return ret;
19299 +
19300 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19301 +               ret = -EFAULT;
19302 +       return ret;
19303 +}
19304 +
19305 +#ifdef CONFIG_COMPAT
19306 +
19307 +int vc_get_iattr_x32(void __user *data)
19308 +{
19309 +       struct path path;
19310 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19311 +       int ret;
19312 +
19313 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19314 +               return -EFAULT;
19315 +
19316 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19317 +       if (!ret) {
19318 +               ret = __vc_get_iattr(path.dentry->d_inode,
19319 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19320 +               path_put(&path);
19321 +       }
19322 +       if (ret)
19323 +               return ret;
19324 +
19325 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19326 +               ret = -EFAULT;
19327 +       return ret;
19328 +}
19329 +
19330 +#endif /* CONFIG_COMPAT */
19331 +
19332 +
19333 +int vc_fget_iattr(uint32_t fd, void __user *data)
19334 +{
19335 +       struct file *filp;
19336 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19337 +       int ret;
19338 +
19339 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19340 +               return -EFAULT;
19341 +
19342 +       filp = fget(fd);
19343 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19344 +               return -EBADF;
19345 +
19346 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19347 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19348 +
19349 +       fput(filp);
19350 +
19351 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19352 +               ret = -EFAULT;
19353 +       return ret;
19354 +}
19355 +
19356 +
19357 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19358 +{
19359 +       struct inode *in = de->d_inode;
19360 +       int error = 0, is_proc = 0, has_tag = 0;
19361 +       struct iattr attr = { 0 };
19362 +
19363 +       if (!in || !in->i_sb)
19364 +               return -ESRCH;
19365 +
19366 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19367 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19368 +               return -EINVAL;
19369 +
19370 +       has_tag = IS_TAGGED(in) ||
19371 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19372 +       if ((*mask & IATTR_TAG) && !has_tag)
19373 +               return -EINVAL;
19374 +
19375 +       mutex_lock(&in->i_mutex);
19376 +       if (*mask & IATTR_TAG) {
19377 +               attr.ia_tag = *tag;
19378 +               attr.ia_valid |= ATTR_TAG;
19379 +       }
19380 +
19381 +       if (*mask & IATTR_FLAGS) {
19382 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19383 +               unsigned int iflags = PROC_I(in)->vx_flags;
19384 +
19385 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19386 +                       | (*flags & IATTR_FLAGS);
19387 +               PROC_I(in)->vx_flags = iflags;
19388 +               if (entry)
19389 +                       entry->vx_flags = iflags;
19390 +       }
19391 +
19392 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19393 +               IATTR_BARRIER | IATTR_COW)) {
19394 +               int iflags = in->i_flags;
19395 +               int vflags = in->i_vflags;
19396 +
19397 +               if (*mask & IATTR_IMMUTABLE) {
19398 +                       if (*flags & IATTR_IMMUTABLE)
19399 +                               iflags |= S_IMMUTABLE;
19400 +                       else
19401 +                               iflags &= ~S_IMMUTABLE;
19402 +               }
19403 +               if (*mask & IATTR_IXUNLINK) {
19404 +                       if (*flags & IATTR_IXUNLINK)
19405 +                               iflags |= S_IXUNLINK;
19406 +                       else
19407 +                               iflags &= ~S_IXUNLINK;
19408 +               }
19409 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19410 +                       if (*flags & IATTR_BARRIER)
19411 +                               vflags |= V_BARRIER;
19412 +                       else
19413 +                               vflags &= ~V_BARRIER;
19414 +               }
19415 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19416 +                       if (*flags & IATTR_COW)
19417 +                               vflags |= V_COW;
19418 +                       else
19419 +                               vflags &= ~V_COW;
19420 +               }
19421 +               if (in->i_op && in->i_op->sync_flags) {
19422 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19423 +                       if (error)
19424 +                               goto out;
19425 +               }
19426 +       }
19427 +
19428 +       if (attr.ia_valid) {
19429 +               if (in->i_op && in->i_op->setattr)
19430 +                       error = in->i_op->setattr(de, &attr);
19431 +               else {
19432 +                       error = inode_change_ok(in, &attr);
19433 +                       if (!error) {
19434 +                               setattr_copy(in, &attr);
19435 +                               mark_inode_dirty(in);
19436 +                       }
19437 +               }
19438 +       }
19439 +
19440 +out:
19441 +       mutex_unlock(&in->i_mutex);
19442 +       return error;
19443 +}
19444 +
19445 +int vc_set_iattr(void __user *data)
19446 +{
19447 +       struct path path;
19448 +       struct vcmd_ctx_iattr_v1 vc_data;
19449 +       int ret;
19450 +
19451 +       if (!capable(CAP_LINUX_IMMUTABLE))
19452 +               return -EPERM;
19453 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19454 +               return -EFAULT;
19455 +
19456 +       ret = user_lpath(vc_data.name, &path);
19457 +       if (!ret) {
19458 +               ret = __vc_set_iattr(path.dentry,
19459 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19460 +               path_put(&path);
19461 +       }
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_set_iattr_x32(void __user *data)
19471 +{
19472 +       struct path path;
19473 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19474 +       int ret;
19475 +
19476 +       if (!capable(CAP_LINUX_IMMUTABLE))
19477 +               return -EPERM;
19478 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19479 +               return -EFAULT;
19480 +
19481 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19482 +       if (!ret) {
19483 +               ret = __vc_set_iattr(path.dentry,
19484 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19485 +               path_put(&path);
19486 +       }
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 +int vc_fset_iattr(uint32_t fd, void __user *data)
19496 +{
19497 +       struct file *filp;
19498 +       struct vcmd_ctx_fiattr_v0 vc_data;
19499 +       int ret;
19500 +
19501 +       if (!capable(CAP_LINUX_IMMUTABLE))
19502 +               return -EPERM;
19503 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19504 +               return -EFAULT;
19505 +
19506 +       filp = fget(fd);
19507 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19508 +               return -EBADF;
19509 +
19510 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19511 +               &vc_data.flags, &vc_data.mask);
19512 +
19513 +       fput(filp);
19514 +
19515 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19516 +               return -EFAULT;
19517 +       return ret;
19518 +}
19519 +
19520 +
19521 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19522 +
19523 +static match_table_t tokens = {
19524 +       {Opt_notagcheck, "notagcheck"},
19525 +#ifdef CONFIG_PROPAGATE
19526 +       {Opt_notag, "notag"},
19527 +       {Opt_tag, "tag"},
19528 +       {Opt_tagid, "tagid=%u"},
19529 +#endif
19530 +       {Opt_err, NULL}
19531 +};
19532 +
19533 +
19534 +static void __dx_parse_remove(char *string, char *opt)
19535 +{
19536 +       char *p = strstr(string, opt);
19537 +       char *q = p;
19538 +
19539 +       if (p) {
19540 +               while (*q != '\0' && *q != ',')
19541 +                       q++;
19542 +               while (*q)
19543 +                       *p++ = *q++;
19544 +               while (*p)
19545 +                       *p++ = '\0';
19546 +       }
19547 +}
19548 +
19549 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19550 +                unsigned long *flags)
19551 +{
19552 +       int set = 0;
19553 +       substring_t args[MAX_OPT_ARGS];
19554 +       int token;
19555 +       char *s, *p, *opts;
19556 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19557 +       int option = 0;
19558 +#endif
19559 +
19560 +       if (!string)
19561 +               return 0;
19562 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19563 +       if (!s)
19564 +               return 0;
19565 +
19566 +       opts = s;
19567 +       while ((p = strsep(&opts, ",")) != NULL) {
19568 +               token = match_token(p, tokens, args);
19569 +
19570 +               switch (token) {
19571 +#ifdef CONFIG_PROPAGATE
19572 +               case Opt_tag:
19573 +                       if (tag)
19574 +                               *tag = 0;
19575 +                       if (remove)
19576 +                               __dx_parse_remove(s, "tag");
19577 +                       *mnt_flags |= MNT_TAGID;
19578 +                       set |= MNT_TAGID;
19579 +                       break;
19580 +               case Opt_notag:
19581 +                       if (remove)
19582 +                               __dx_parse_remove(s, "notag");
19583 +                       *mnt_flags |= MNT_NOTAG;
19584 +                       set |= MNT_NOTAG;
19585 +                       break;
19586 +               case Opt_tagid:
19587 +                       if (tag && !match_int(args, &option))
19588 +                               *tag = option;
19589 +                       if (remove)
19590 +                               __dx_parse_remove(s, "tagid");
19591 +                       *mnt_flags |= MNT_TAGID;
19592 +                       set |= MNT_TAGID;
19593 +                       break;
19594 +#endif /* CONFIG_PROPAGATE */
19595 +               case Opt_notagcheck:
19596 +                       if (remove)
19597 +                               __dx_parse_remove(s, "notagcheck");
19598 +                       *flags |= MS_NOTAGCHECK;
19599 +                       set |= MS_NOTAGCHECK;
19600 +                       break;
19601 +               }
19602 +               vxdprintk(VXD_CBIT(tag, 7),
19603 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19604 +                       p, token, option);
19605 +       }
19606 +       if (set)
19607 +               strcpy(string, s);
19608 +       kfree(s);
19609 +       return set;
19610 +}
19611 +
19612 +#ifdef CONFIG_PROPAGATE
19613 +
19614 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19615 +{
19616 +       tag_t new_tag = 0;
19617 +       struct vfsmount *mnt;
19618 +       int propagate;
19619 +
19620 +       if (!nd)
19621 +               return;
19622 +       mnt = nd->path.mnt;
19623 +       if (!mnt)
19624 +               return;
19625 +
19626 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19627 +       if (propagate)
19628 +               new_tag = mnt->mnt_tag;
19629 +
19630 +       vxdprintk(VXD_CBIT(tag, 7),
19631 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19632 +               inode, inode->i_ino, inode->i_tag,
19633 +               new_tag, (propagate) ? 1 : 0);
19634 +
19635 +       if (propagate)
19636 +               inode->i_tag = new_tag;
19637 +}
19638 +
19639 +#include <linux/module.h>
19640 +
19641 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19642 +
19643 +#endif /* CONFIG_PROPAGATE */
19644 +
19645 diff -NurpP --minimal linux-3.5.4/kernel/vserver/limit.c linux-3.5.4-vs2.3.4.3/kernel/vserver/limit.c
19646 --- linux-3.5.4/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19647 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/limit.c        2012-09-10 16:04:53.000000000 +0200
19648 @@ -0,0 +1,345 @@
19649 +/*
19650 + *  linux/kernel/vserver/limit.c
19651 + *
19652 + *  Virtual Server: Context Limits
19653 + *
19654 + *  Copyright (C) 2004-2010  Herbert Pötzl
19655 + *
19656 + *  V0.01  broken out from vcontext V0.05
19657 + *  V0.02  changed vcmds to vxi arg
19658 + *  V0.03  added memory cgroup support
19659 + *
19660 + */
19661 +
19662 +#include <linux/sched.h>
19663 +#include <linux/module.h>
19664 +#include <linux/memcontrol.h>
19665 +#include <linux/res_counter.h>
19666 +#include <linux/vs_limit.h>
19667 +#include <linux/vserver/limit.h>
19668 +#include <linux/vserver/limit_cmd.h>
19669 +
19670 +#include <asm/uaccess.h>
19671 +
19672 +
19673 +const char *vlimit_name[NUM_LIMITS] = {
19674 +       [RLIMIT_CPU]            = "CPU",
19675 +       [RLIMIT_NPROC]          = "NPROC",
19676 +       [RLIMIT_NOFILE]         = "NOFILE",
19677 +       [RLIMIT_LOCKS]          = "LOCKS",
19678 +       [RLIMIT_SIGPENDING]     = "SIGP",
19679 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19680 +
19681 +       [VLIMIT_NSOCK]          = "NSOCK",
19682 +       [VLIMIT_OPENFD]         = "OPENFD",
19683 +       [VLIMIT_SHMEM]          = "SHMEM",
19684 +       [VLIMIT_DENTRY]         = "DENTRY",
19685 +};
19686 +
19687 +EXPORT_SYMBOL_GPL(vlimit_name);
19688 +
19689 +#define MASK_ENTRY(x)  (1 << (x))
19690 +
19691 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19692 +               /* minimum */
19693 +       0
19694 +       ,       /* softlimit */
19695 +       0
19696 +       ,       /* maximum */
19697 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19698 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19699 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19700 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19701 +
19702 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19703 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19704 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19705 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19706 +       0
19707 +};
19708 +               /* accounting only */
19709 +uint32_t account_mask =
19710 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19711 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19712 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19713 +       0;
19714 +
19715 +
19716 +static int is_valid_vlimit(int id)
19717 +{
19718 +       uint32_t mask = vlimit_mask.minimum |
19719 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19720 +       return mask & (1 << id);
19721 +}
19722 +
19723 +static int is_accounted_vlimit(int id)
19724 +{
19725 +       if (is_valid_vlimit(id))
19726 +               return 1;
19727 +       return account_mask & (1 << id);
19728 +}
19729 +
19730 +
19731 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19732 +{
19733 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19734 +       return VX_VLIM(limit);
19735 +}
19736 +
19737 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19738 +{
19739 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19740 +       return VX_VLIM(limit);
19741 +}
19742 +
19743 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19744 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19745 +{
19746 +       if (!is_valid_vlimit(id))
19747 +               return -EINVAL;
19748 +
19749 +       if (minimum)
19750 +               *minimum = CRLIM_UNSET;
19751 +       if (softlimit)
19752 +               *softlimit = vc_get_soft(vxi, id);
19753 +       if (maximum)
19754 +               *maximum = vc_get_hard(vxi, id);
19755 +       return 0;
19756 +}
19757 +
19758 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19759 +{
19760 +       struct vcmd_ctx_rlimit_v0 vc_data;
19761 +       int ret;
19762 +
19763 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19764 +               return -EFAULT;
19765 +
19766 +       ret = do_get_rlimit(vxi, vc_data.id,
19767 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19768 +       if (ret)
19769 +               return ret;
19770 +
19771 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19772 +               return -EFAULT;
19773 +       return 0;
19774 +}
19775 +
19776 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19777 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19778 +{
19779 +       if (!is_valid_vlimit(id))
19780 +               return -EINVAL;
19781 +
19782 +       if (maximum != CRLIM_KEEP)
19783 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19784 +       if (softlimit != CRLIM_KEEP)
19785 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19786 +
19787 +       /* clamp soft limit */
19788 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19789 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19790 +
19791 +       return 0;
19792 +}
19793 +
19794 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19795 +{
19796 +       struct vcmd_ctx_rlimit_v0 vc_data;
19797 +
19798 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19799 +               return -EFAULT;
19800 +
19801 +       return do_set_rlimit(vxi, vc_data.id,
19802 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19803 +}
19804 +
19805 +#ifdef CONFIG_IA32_EMULATION
19806 +
19807 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19808 +{
19809 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19810 +
19811 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19812 +               return -EFAULT;
19813 +
19814 +       return do_set_rlimit(vxi, vc_data.id,
19815 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19816 +}
19817 +
19818 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19819 +{
19820 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19821 +       int ret;
19822 +
19823 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19824 +               return -EFAULT;
19825 +
19826 +       ret = do_get_rlimit(vxi, vc_data.id,
19827 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19828 +       if (ret)
19829 +               return ret;
19830 +
19831 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19832 +               return -EFAULT;
19833 +       return 0;
19834 +}
19835 +
19836 +#endif /* CONFIG_IA32_EMULATION */
19837 +
19838 +
19839 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19840 +{
19841 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19842 +               return -EFAULT;
19843 +       return 0;
19844 +}
19845 +
19846 +
19847 +static inline void vx_reset_hits(struct _vx_limit *limit)
19848 +{
19849 +       int lim;
19850 +
19851 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19852 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19853 +       }
19854 +}
19855 +
19856 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19857 +{
19858 +       vx_reset_hits(&vxi->limit);
19859 +       return 0;
19860 +}
19861 +
19862 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19863 +{
19864 +       rlim_t value;
19865 +       int lim;
19866 +
19867 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19868 +               value = __rlim_get(limit, lim);
19869 +               __rlim_rmax(limit, lim) = value;
19870 +               __rlim_rmin(limit, lim) = value;
19871 +       }
19872 +}
19873 +
19874 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19875 +{
19876 +       vx_reset_minmax(&vxi->limit);
19877 +       return 0;
19878 +}
19879 +
19880 +
19881 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19882 +{
19883 +       struct vcmd_rlimit_stat_v0 vc_data;
19884 +       struct _vx_limit *limit = &vxi->limit;
19885 +       int id;
19886 +
19887 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19888 +               return -EFAULT;
19889 +
19890 +       id = vc_data.id;
19891 +       if (!is_accounted_vlimit(id))
19892 +               return -EINVAL;
19893 +
19894 +       vx_limit_fixup(limit, id);
19895 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19896 +       vc_data.value = __rlim_get(limit, id);
19897 +       vc_data.minimum = __rlim_rmin(limit, id);
19898 +       vc_data.maximum = __rlim_rmax(limit, id);
19899 +
19900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19901 +               return -EFAULT;
19902 +       return 0;
19903 +}
19904 +
19905 +
19906 +void vx_vsi_meminfo(struct sysinfo *val)
19907 +{
19908 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19909 +       struct mem_cgroup *mcg;
19910 +       u64 res_limit, res_usage;
19911 +
19912 +       rcu_read_lock();
19913 +       mcg = mem_cgroup_from_task(current);
19914 +       rcu_read_unlock();
19915 +       if (!mcg)
19916 +               goto out;
19917 +
19918 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19919 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19920 +
19921 +       if (res_limit != RESOURCE_MAX)
19922 +               val->totalram = (res_limit >> PAGE_SHIFT);
19923 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19924 +       val->bufferram = 0;
19925 +       val->totalhigh = 0;
19926 +       val->freehigh = 0;
19927 +out:
19928 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19929 +       return;
19930 +}
19931 +
19932 +void vx_vsi_swapinfo(struct sysinfo *val)
19933 +{
19934 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19935 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19936 +       struct mem_cgroup *mcg;
19937 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19938 +       s64 swap_limit, swap_usage;
19939 +
19940 +       rcu_read_lock();
19941 +       mcg = mem_cgroup_from_task(current);
19942 +       rcu_read_unlock();
19943 +       if (!mcg)
19944 +               goto out;
19945 +
19946 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19947 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19948 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19949 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19950 +
19951 +       /* memory unlimited */
19952 +       if (res_limit == RESOURCE_MAX)
19953 +               goto out;
19954 +
19955 +       swap_limit = memsw_limit - res_limit;
19956 +       /* we have a swap limit? */
19957 +       if (memsw_limit != RESOURCE_MAX)
19958 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19959 +
19960 +       /* calculate swap part */
19961 +       swap_usage = (memsw_usage > res_usage) ?
19962 +               memsw_usage - res_usage : 0;
19963 +
19964 +       /* total shown minus usage gives free swap */
19965 +       val->freeswap = (swap_usage < swap_limit) ?
19966 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19967 +out:
19968 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19969 +       val->totalswap = 0;
19970 +       val->freeswap = 0;
19971 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19972 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19973 +       return;
19974 +}
19975 +
19976 +long vx_vsi_cached(struct sysinfo *val)
19977 +{
19978 +       long cache = 0;
19979 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19980 +       struct mem_cgroup *mcg;
19981 +
19982 +       rcu_read_lock();
19983 +       mcg = mem_cgroup_from_task(current);
19984 +       rcu_read_unlock();
19985 +       if (!mcg)
19986 +               goto out;
19987 +
19988 +       cache = mem_cgroup_stat_read_cache(mcg);
19989 +out:
19990 +#endif
19991 +       return cache;
19992 +}
19993 +
19994 diff -NurpP --minimal linux-3.5.4/kernel/vserver/limit_init.h linux-3.5.4-vs2.3.4.3/kernel/vserver/limit_init.h
19995 --- linux-3.5.4/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
19996 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/limit_init.h   2012-07-23 01:45:55.000000000 +0200
19997 @@ -0,0 +1,31 @@
19998 +
19999 +
20000 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20001 +{
20002 +       int lim;
20003 +
20004 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20005 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20006 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20007 +               __rlim_set(limit, lim, 0);
20008 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20009 +               __rlim_rmin(limit, lim) = 0;
20010 +               __rlim_rmax(limit, lim) = 0;
20011 +       }
20012 +}
20013 +
20014 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20015 +{
20016 +       rlim_t value;
20017 +       int lim;
20018 +
20019 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20020 +               if ((1 << lim) & VLIM_NOCHECK)
20021 +                       continue;
20022 +               value = __rlim_get(limit, lim);
20023 +               vxwprintk_xid(value,
20024 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20025 +                       limit, vlimit_name[lim], lim, (long)value);
20026 +       }
20027 +}
20028 +
20029 diff -NurpP --minimal linux-3.5.4/kernel/vserver/limit_proc.h linux-3.5.4-vs2.3.4.3/kernel/vserver/limit_proc.h
20030 --- linux-3.5.4/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20031 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/limit_proc.h   2012-07-23 01:45:55.000000000 +0200
20032 @@ -0,0 +1,57 @@
20033 +#ifndef _VX_LIMIT_PROC_H
20034 +#define _VX_LIMIT_PROC_H
20035 +
20036 +#include <linux/vserver/limit_int.h>
20037 +
20038 +
20039 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20040 +#define VX_LIMIT_TOP   \
20041 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20042 +
20043 +#define VX_LIMIT_ARG(r)                                \
20044 +       (unsigned long)__rlim_get(limit, r),    \
20045 +       (unsigned long)__rlim_rmin(limit, r),   \
20046 +       (unsigned long)__rlim_rmax(limit, r),   \
20047 +       VX_VLIM(__rlim_soft(limit, r)),         \
20048 +       VX_VLIM(__rlim_hard(limit, r)),         \
20049 +       atomic_read(&__rlim_lhit(limit, r))
20050 +
20051 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20052 +{
20053 +       vx_limit_fixup(limit, -1);
20054 +       return sprintf(buffer, VX_LIMIT_TOP
20055 +               "PROC"  VX_LIMIT_FMT
20056 +               "VM"    VX_LIMIT_FMT
20057 +               "VML"   VX_LIMIT_FMT
20058 +               "RSS"   VX_LIMIT_FMT
20059 +               "ANON"  VX_LIMIT_FMT
20060 +               "RMAP"  VX_LIMIT_FMT
20061 +               "FILES" VX_LIMIT_FMT
20062 +               "OFD"   VX_LIMIT_FMT
20063 +               "LOCKS" VX_LIMIT_FMT
20064 +               "SOCK"  VX_LIMIT_FMT
20065 +               "MSGQ"  VX_LIMIT_FMT
20066 +               "SHM"   VX_LIMIT_FMT
20067 +               "SEMA"  VX_LIMIT_FMT
20068 +               "SEMS"  VX_LIMIT_FMT
20069 +               "DENT"  VX_LIMIT_FMT,
20070 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20071 +               VX_LIMIT_ARG(RLIMIT_AS),
20072 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20073 +               VX_LIMIT_ARG(RLIMIT_RSS),
20074 +               VX_LIMIT_ARG(VLIMIT_ANON),
20075 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20076 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20077 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20078 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20079 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20080 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20081 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20082 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20083 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20084 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20085 +}
20086 +
20087 +#endif /* _VX_LIMIT_PROC_H */
20088 +
20089 +
20090 diff -NurpP --minimal linux-3.5.4/kernel/vserver/network.c linux-3.5.4-vs2.3.4.3/kernel/vserver/network.c
20091 --- linux-3.5.4/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20092 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/network.c      2012-07-23 01:45:55.000000000 +0200
20093 @@ -0,0 +1,912 @@
20094 +/*
20095 + *  linux/kernel/vserver/network.c
20096 + *
20097 + *  Virtual Server: Network Support
20098 + *
20099 + *  Copyright (C) 2003-2007  Herbert Pötzl
20100 + *
20101 + *  V0.01  broken out from vcontext V0.05
20102 + *  V0.02  cleaned up implementation
20103 + *  V0.03  added equiv nx commands
20104 + *  V0.04  switch to RCU based hash
20105 + *  V0.05  and back to locking again
20106 + *  V0.06  changed vcmds to nxi arg
20107 + *  V0.07  have __create claim() the nxi
20108 + *
20109 + */
20110 +
20111 +#include <linux/err.h>
20112 +#include <linux/slab.h>
20113 +#include <linux/rcupdate.h>
20114 +
20115 +#include <linux/vs_network.h>
20116 +#include <linux/vs_pid.h>
20117 +#include <linux/vserver/network_cmd.h>
20118 +
20119 +
20120 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20121 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20122 +
20123 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20124 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20125 +
20126 +
20127 +static int __init init_network(void)
20128 +{
20129 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20130 +               sizeof(struct nx_addr_v4), 0,
20131 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20132 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20133 +               sizeof(struct nx_addr_v6), 0,
20134 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20135 +       return 0;
20136 +}
20137 +
20138 +
20139 +/*     __alloc_nx_addr_v4()                                    */
20140 +
20141 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20142 +{
20143 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20144 +               nx_addr_v4_cachep, GFP_KERNEL);
20145 +
20146 +       if (!IS_ERR(nxa))
20147 +               memset(nxa, 0, sizeof(*nxa));
20148 +       return nxa;
20149 +}
20150 +
20151 +/*     __dealloc_nx_addr_v4()                                  */
20152 +
20153 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20154 +{
20155 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20156 +}
20157 +
20158 +/*     __dealloc_nx_addr_v4_all()                              */
20159 +
20160 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20161 +{
20162 +       while (nxa) {
20163 +               struct nx_addr_v4 *next = nxa->next;
20164 +
20165 +               __dealloc_nx_addr_v4(nxa);
20166 +               nxa = next;
20167 +       }
20168 +}
20169 +
20170 +
20171 +#ifdef CONFIG_IPV6
20172 +
20173 +/*     __alloc_nx_addr_v6()                                    */
20174 +
20175 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20176 +{
20177 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20178 +               nx_addr_v6_cachep, GFP_KERNEL);
20179 +
20180 +       if (!IS_ERR(nxa))
20181 +               memset(nxa, 0, sizeof(*nxa));
20182 +       return nxa;
20183 +}
20184 +
20185 +/*     __dealloc_nx_addr_v6()                                  */
20186 +
20187 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20188 +{
20189 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20190 +}
20191 +
20192 +/*     __dealloc_nx_addr_v6_all()                              */
20193 +
20194 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20195 +{
20196 +       while (nxa) {
20197 +               struct nx_addr_v6 *next = nxa->next;
20198 +
20199 +               __dealloc_nx_addr_v6(nxa);
20200 +               nxa = next;
20201 +       }
20202 +}
20203 +
20204 +#endif /* CONFIG_IPV6 */
20205 +
20206 +/*     __alloc_nx_info()
20207 +
20208 +       * allocate an initialized nx_info struct
20209 +       * doesn't make it visible (hash)                        */
20210 +
20211 +static struct nx_info *__alloc_nx_info(nid_t nid)
20212 +{
20213 +       struct nx_info *new = NULL;
20214 +
20215 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20216 +
20217 +       /* would this benefit from a slab cache? */
20218 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20219 +       if (!new)
20220 +               return 0;
20221 +
20222 +       memset(new, 0, sizeof(struct nx_info));
20223 +       new->nx_id = nid;
20224 +       INIT_HLIST_NODE(&new->nx_hlist);
20225 +       atomic_set(&new->nx_usecnt, 0);
20226 +       atomic_set(&new->nx_tasks, 0);
20227 +       new->nx_state = 0;
20228 +
20229 +       new->nx_flags = NXF_INIT_SET;
20230 +
20231 +       /* rest of init goes here */
20232 +
20233 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20234 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20235 +
20236 +       vxdprintk(VXD_CBIT(nid, 0),
20237 +               "alloc_nx_info(%d) = %p", nid, new);
20238 +       atomic_inc(&nx_global_ctotal);
20239 +       return new;
20240 +}
20241 +
20242 +/*     __dealloc_nx_info()
20243 +
20244 +       * final disposal of nx_info                             */
20245 +
20246 +static void __dealloc_nx_info(struct nx_info *nxi)
20247 +{
20248 +       vxdprintk(VXD_CBIT(nid, 0),
20249 +               "dealloc_nx_info(%p)", nxi);
20250 +
20251 +       nxi->nx_hlist.next = LIST_POISON1;
20252 +       nxi->nx_id = -1;
20253 +
20254 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20255 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20256 +
20257 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20258 +
20259 +       nxi->nx_state |= NXS_RELEASED;
20260 +       kfree(nxi);
20261 +       atomic_dec(&nx_global_ctotal);
20262 +}
20263 +
20264 +static void __shutdown_nx_info(struct nx_info *nxi)
20265 +{
20266 +       nxi->nx_state |= NXS_SHUTDOWN;
20267 +       vs_net_change(nxi, VSC_NETDOWN);
20268 +}
20269 +
20270 +/*     exported stuff                                          */
20271 +
20272 +void free_nx_info(struct nx_info *nxi)
20273 +{
20274 +       /* context shutdown is mandatory */
20275 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20276 +
20277 +       /* context must not be hashed */
20278 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20279 +
20280 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20281 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20282 +
20283 +       __dealloc_nx_info(nxi);
20284 +}
20285 +
20286 +
20287 +void __nx_set_lback(struct nx_info *nxi)
20288 +{
20289 +       int nid = nxi->nx_id;
20290 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20291 +
20292 +       nxi->v4_lback.s_addr = lback;
20293 +}
20294 +
20295 +extern int __nx_inet_add_lback(__be32 addr);
20296 +extern int __nx_inet_del_lback(__be32 addr);
20297 +
20298 +
20299 +/*     hash table for nx_info hash */
20300 +
20301 +#define NX_HASH_SIZE   13
20302 +
20303 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20304 +
20305 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20306 +
20307 +
20308 +static inline unsigned int __hashval(nid_t nid)
20309 +{
20310 +       return (nid % NX_HASH_SIZE);
20311 +}
20312 +
20313 +
20314 +
20315 +/*     __hash_nx_info()
20316 +
20317 +       * add the nxi to the global hash table
20318 +       * requires the hash_lock to be held                     */
20319 +
20320 +static inline void __hash_nx_info(struct nx_info *nxi)
20321 +{
20322 +       struct hlist_head *head;
20323 +
20324 +       vxd_assert_lock(&nx_info_hash_lock);
20325 +       vxdprintk(VXD_CBIT(nid, 4),
20326 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20327 +
20328 +       /* context must not be hashed */
20329 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20330 +
20331 +       nxi->nx_state |= NXS_HASHED;
20332 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20333 +       hlist_add_head(&nxi->nx_hlist, head);
20334 +       atomic_inc(&nx_global_cactive);
20335 +}
20336 +
20337 +/*     __unhash_nx_info()
20338 +
20339 +       * remove the nxi from the global hash table
20340 +       * requires the hash_lock to be held                     */
20341 +
20342 +static inline void __unhash_nx_info(struct nx_info *nxi)
20343 +{
20344 +       vxd_assert_lock(&nx_info_hash_lock);
20345 +       vxdprintk(VXD_CBIT(nid, 4),
20346 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20347 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20348 +
20349 +       /* context must be hashed */
20350 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20351 +       /* but without tasks */
20352 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20353 +
20354 +       nxi->nx_state &= ~NXS_HASHED;
20355 +       hlist_del(&nxi->nx_hlist);
20356 +       atomic_dec(&nx_global_cactive);
20357 +}
20358 +
20359 +
20360 +/*     __lookup_nx_info()
20361 +
20362 +       * requires the hash_lock to be held
20363 +       * doesn't increment the nx_refcnt                       */
20364 +
20365 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20366 +{
20367 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20368 +       struct hlist_node *pos;
20369 +       struct nx_info *nxi;
20370 +
20371 +       vxd_assert_lock(&nx_info_hash_lock);
20372 +       hlist_for_each(pos, head) {
20373 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20374 +
20375 +               if (nxi->nx_id == nid)
20376 +                       goto found;
20377 +       }
20378 +       nxi = NULL;
20379 +found:
20380 +       vxdprintk(VXD_CBIT(nid, 0),
20381 +               "__lookup_nx_info(#%u): %p[#%u]",
20382 +               nid, nxi, nxi ? nxi->nx_id : 0);
20383 +       return nxi;
20384 +}
20385 +
20386 +
20387 +/*     __create_nx_info()
20388 +
20389 +       * create the requested context
20390 +       * get(), claim() and hash it                            */
20391 +
20392 +static struct nx_info *__create_nx_info(int id)
20393 +{
20394 +       struct nx_info *new, *nxi = NULL;
20395 +
20396 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20397 +
20398 +       if (!(new = __alloc_nx_info(id)))
20399 +               return ERR_PTR(-ENOMEM);
20400 +
20401 +       /* required to make dynamic xids unique */
20402 +       spin_lock(&nx_info_hash_lock);
20403 +
20404 +       /* static context requested */
20405 +       if ((nxi = __lookup_nx_info(id))) {
20406 +               vxdprintk(VXD_CBIT(nid, 0),
20407 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20408 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20409 +                       nxi = ERR_PTR(-EBUSY);
20410 +               else
20411 +                       nxi = ERR_PTR(-EEXIST);
20412 +               goto out_unlock;
20413 +       }
20414 +       /* new context */
20415 +       vxdprintk(VXD_CBIT(nid, 0),
20416 +               "create_nx_info(%d) = %p (new)", id, new);
20417 +       claim_nx_info(new, NULL);
20418 +       __nx_set_lback(new);
20419 +       __hash_nx_info(get_nx_info(new));
20420 +       nxi = new, new = NULL;
20421 +
20422 +out_unlock:
20423 +       spin_unlock(&nx_info_hash_lock);
20424 +       if (new)
20425 +               __dealloc_nx_info(new);
20426 +       return nxi;
20427 +}
20428 +
20429 +
20430 +
20431 +/*     exported stuff                                          */
20432 +
20433 +
20434 +void unhash_nx_info(struct nx_info *nxi)
20435 +{
20436 +       __shutdown_nx_info(nxi);
20437 +       spin_lock(&nx_info_hash_lock);
20438 +       __unhash_nx_info(nxi);
20439 +       spin_unlock(&nx_info_hash_lock);
20440 +}
20441 +
20442 +/*     lookup_nx_info()
20443 +
20444 +       * search for a nx_info and get() it
20445 +       * negative id means current                             */
20446 +
20447 +struct nx_info *lookup_nx_info(int id)
20448 +{
20449 +       struct nx_info *nxi = NULL;
20450 +
20451 +       if (id < 0) {
20452 +               nxi = get_nx_info(current_nx_info());
20453 +       } else if (id > 1) {
20454 +               spin_lock(&nx_info_hash_lock);
20455 +               nxi = get_nx_info(__lookup_nx_info(id));
20456 +               spin_unlock(&nx_info_hash_lock);
20457 +       }
20458 +       return nxi;
20459 +}
20460 +
20461 +/*     nid_is_hashed()
20462 +
20463 +       * verify that nid is still hashed                       */
20464 +
20465 +int nid_is_hashed(nid_t nid)
20466 +{
20467 +       int hashed;
20468 +
20469 +       spin_lock(&nx_info_hash_lock);
20470 +       hashed = (__lookup_nx_info(nid) != NULL);
20471 +       spin_unlock(&nx_info_hash_lock);
20472 +       return hashed;
20473 +}
20474 +
20475 +
20476 +#ifdef CONFIG_PROC_FS
20477 +
20478 +/*     get_nid_list()
20479 +
20480 +       * get a subset of hashed nids for proc
20481 +       * assumes size is at least one                          */
20482 +
20483 +int get_nid_list(int index, unsigned int *nids, int size)
20484 +{
20485 +       int hindex, nr_nids = 0;
20486 +
20487 +       /* only show current and children */
20488 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20489 +               if (index > 0)
20490 +                       return 0;
20491 +               nids[nr_nids] = nx_current_nid();
20492 +               return 1;
20493 +       }
20494 +
20495 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20496 +               struct hlist_head *head = &nx_info_hash[hindex];
20497 +               struct hlist_node *pos;
20498 +
20499 +               spin_lock(&nx_info_hash_lock);
20500 +               hlist_for_each(pos, head) {
20501 +                       struct nx_info *nxi;
20502 +
20503 +                       if (--index > 0)
20504 +                               continue;
20505 +
20506 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20507 +                       nids[nr_nids] = nxi->nx_id;
20508 +                       if (++nr_nids >= size) {
20509 +                               spin_unlock(&nx_info_hash_lock);
20510 +                               goto out;
20511 +                       }
20512 +               }
20513 +               /* keep the lock time short */
20514 +               spin_unlock(&nx_info_hash_lock);
20515 +       }
20516 +out:
20517 +       return nr_nids;
20518 +}
20519 +#endif
20520 +
20521 +
20522 +/*
20523 + *     migrate task to new network
20524 + *     gets nxi, puts old_nxi on change
20525 + */
20526 +
20527 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20528 +{
20529 +       struct nx_info *old_nxi;
20530 +       int ret = 0;
20531 +
20532 +       if (!p || !nxi)
20533 +               BUG();
20534 +
20535 +       vxdprintk(VXD_CBIT(nid, 5),
20536 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20537 +               p, nxi, nxi->nx_id,
20538 +               atomic_read(&nxi->nx_usecnt),
20539 +               atomic_read(&nxi->nx_tasks));
20540 +
20541 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20542 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20543 +               return -EACCES;
20544 +
20545 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20546 +               return -EFAULT;
20547 +
20548 +       /* maybe disallow this completely? */
20549 +       old_nxi = task_get_nx_info(p);
20550 +       if (old_nxi == nxi)
20551 +               goto out;
20552 +
20553 +       task_lock(p);
20554 +       if (old_nxi)
20555 +               clr_nx_info(&p->nx_info);
20556 +       claim_nx_info(nxi, p);
20557 +       set_nx_info(&p->nx_info, nxi);
20558 +       p->nid = nxi->nx_id;
20559 +       task_unlock(p);
20560 +
20561 +       vxdprintk(VXD_CBIT(nid, 5),
20562 +               "moved task %p into nxi:%p[#%d]",
20563 +               p, nxi, nxi->nx_id);
20564 +
20565 +       if (old_nxi)
20566 +               release_nx_info(old_nxi, p);
20567 +       ret = 0;
20568 +out:
20569 +       put_nx_info(old_nxi);
20570 +       return ret;
20571 +}
20572 +
20573 +
20574 +void nx_set_persistent(struct nx_info *nxi)
20575 +{
20576 +       vxdprintk(VXD_CBIT(nid, 6),
20577 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20578 +
20579 +       get_nx_info(nxi);
20580 +       claim_nx_info(nxi, NULL);
20581 +}
20582 +
20583 +void nx_clear_persistent(struct nx_info *nxi)
20584 +{
20585 +       vxdprintk(VXD_CBIT(nid, 6),
20586 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20587 +
20588 +       release_nx_info(nxi, NULL);
20589 +       put_nx_info(nxi);
20590 +}
20591 +
20592 +void nx_update_persistent(struct nx_info *nxi)
20593 +{
20594 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20595 +               nx_set_persistent(nxi);
20596 +       else
20597 +               nx_clear_persistent(nxi);
20598 +}
20599 +
20600 +/* vserver syscall commands below here */
20601 +
20602 +/* taks nid and nx_info functions */
20603 +
20604 +#include <asm/uaccess.h>
20605 +
20606 +
20607 +int vc_task_nid(uint32_t id)
20608 +{
20609 +       nid_t nid;
20610 +
20611 +       if (id) {
20612 +               struct task_struct *tsk;
20613 +
20614 +               rcu_read_lock();
20615 +               tsk = find_task_by_real_pid(id);
20616 +               nid = (tsk) ? tsk->nid : -ESRCH;
20617 +               rcu_read_unlock();
20618 +       } else
20619 +               nid = nx_current_nid();
20620 +       return nid;
20621 +}
20622 +
20623 +
20624 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20625 +{
20626 +       struct vcmd_nx_info_v0 vc_data;
20627 +
20628 +       vc_data.nid = nxi->nx_id;
20629 +
20630 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20631 +               return -EFAULT;
20632 +       return 0;
20633 +}
20634 +
20635 +
20636 +/* network functions */
20637 +
20638 +int vc_net_create(uint32_t nid, void __user *data)
20639 +{
20640 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20641 +       struct nx_info *new_nxi;
20642 +       int ret;
20643 +
20644 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20645 +               return -EFAULT;
20646 +
20647 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20648 +               return -EINVAL;
20649 +
20650 +       new_nxi = __create_nx_info(nid);
20651 +       if (IS_ERR(new_nxi))
20652 +               return PTR_ERR(new_nxi);
20653 +
20654 +       /* initial flags */
20655 +       new_nxi->nx_flags = vc_data.flagword;
20656 +
20657 +       ret = -ENOEXEC;
20658 +       if (vs_net_change(new_nxi, VSC_NETUP))
20659 +               goto out;
20660 +
20661 +       ret = nx_migrate_task(current, new_nxi);
20662 +       if (ret)
20663 +               goto out;
20664 +
20665 +       /* return context id on success */
20666 +       ret = new_nxi->nx_id;
20667 +
20668 +       /* get a reference for persistent contexts */
20669 +       if ((vc_data.flagword & NXF_PERSISTENT))
20670 +               nx_set_persistent(new_nxi);
20671 +out:
20672 +       release_nx_info(new_nxi, NULL);
20673 +       put_nx_info(new_nxi);
20674 +       return ret;
20675 +}
20676 +
20677 +
20678 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20679 +{
20680 +       return nx_migrate_task(current, nxi);
20681 +}
20682 +
20683 +
20684 +
20685 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20686 +       uint16_t type, uint16_t flags)
20687 +{
20688 +       struct nx_addr_v4 *nxa = &nxi->v4;
20689 +
20690 +       if (NX_IPV4(nxi)) {
20691 +               /* locate last entry */
20692 +               for (; nxa->next; nxa = nxa->next);
20693 +               nxa->next = __alloc_nx_addr_v4();
20694 +               nxa = nxa->next;
20695 +
20696 +               if (IS_ERR(nxa))
20697 +                       return PTR_ERR(nxa);
20698 +       }
20699 +
20700 +       if (nxi->v4.next)
20701 +               /* remove single ip for ip list */
20702 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20703 +
20704 +       nxa->ip[0].s_addr = ip;
20705 +       nxa->ip[1].s_addr = ip2;
20706 +       nxa->mask.s_addr = mask;
20707 +       nxa->type = type;
20708 +       nxa->flags = flags;
20709 +       return 0;
20710 +}
20711 +
20712 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20713 +       uint16_t type, uint16_t flags)
20714 +{
20715 +       struct nx_addr_v4 *nxa = &nxi->v4;
20716 +
20717 +       switch (type) {
20718 +/*     case NXA_TYPE_ADDR:
20719 +               break;          */
20720 +
20721 +       case NXA_TYPE_ANY:
20722 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20723 +               memset(nxa, 0, sizeof(*nxa));
20724 +               break;
20725 +
20726 +       default:
20727 +               return -EINVAL;
20728 +       }
20729 +       return 0;
20730 +}
20731 +
20732 +
20733 +int vc_net_add(struct nx_info *nxi, void __user *data)
20734 +{
20735 +       struct vcmd_net_addr_v0 vc_data;
20736 +       int index, ret = 0;
20737 +
20738 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20739 +               return -EFAULT;
20740 +
20741 +       switch (vc_data.type) {
20742 +       case NXA_TYPE_IPV4:
20743 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20744 +                       return -EINVAL;
20745 +
20746 +               index = 0;
20747 +               while (index < vc_data.count) {
20748 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20749 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20750 +                       if (ret)
20751 +                               return ret;
20752 +                       index++;
20753 +               }
20754 +               ret = index;
20755 +               break;
20756 +
20757 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20758 +               nxi->v4_bcast = vc_data.ip[0];
20759 +               ret = 1;
20760 +               break;
20761 +
20762 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20763 +               nxi->v4_lback = vc_data.ip[0];
20764 +               ret = 1;
20765 +               break;
20766 +
20767 +       default:
20768 +               ret = -EINVAL;
20769 +               break;
20770 +       }
20771 +       return ret;
20772 +}
20773 +
20774 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20775 +{
20776 +       struct vcmd_net_addr_v0 vc_data;
20777 +
20778 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20779 +               return -EFAULT;
20780 +
20781 +       switch (vc_data.type) {
20782 +       case NXA_TYPE_ANY:
20783 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20784 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20785 +               break;
20786 +
20787 +       default:
20788 +               return -EINVAL;
20789 +       }
20790 +       return 0;
20791 +}
20792 +
20793 +
20794 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20795 +{
20796 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20797 +
20798 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20799 +               return -EFAULT;
20800 +
20801 +       switch (vc_data.type) {
20802 +       case NXA_TYPE_ADDR:
20803 +       case NXA_TYPE_MASK:
20804 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20805 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20806 +
20807 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20808 +               nxi->v4_bcast = vc_data.ip;
20809 +               break;
20810 +
20811 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20812 +               nxi->v4_lback = vc_data.ip;
20813 +               break;
20814 +
20815 +       default:
20816 +               return -EINVAL;
20817 +       }
20818 +       return 0;
20819 +}
20820 +
20821 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20822 +{
20823 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20824 +
20825 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20826 +               return -EFAULT;
20827 +
20828 +       switch (vc_data.type) {
20829 +       case NXA_TYPE_ADDR:
20830 +       case NXA_TYPE_MASK:
20831 +       case NXA_TYPE_RANGE:
20832 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20833 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20834 +
20835 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20836 +               nxi->v4_bcast = vc_data.ip;
20837 +               break;
20838 +
20839 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20840 +               nxi->v4_lback = vc_data.ip;
20841 +               break;
20842 +
20843 +       default:
20844 +               return -EINVAL;
20845 +       }
20846 +       return 0;
20847 +}
20848 +
20849 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20850 +{
20851 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20852 +
20853 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20854 +               return -EFAULT;
20855 +
20856 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20857 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20858 +}
20859 +
20860 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20861 +{
20862 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20863 +
20864 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20865 +               return -EFAULT;
20866 +
20867 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20868 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20869 +}
20870 +
20871 +#ifdef CONFIG_IPV6
20872 +
20873 +int do_add_v6_addr(struct nx_info *nxi,
20874 +       struct in6_addr *ip, struct in6_addr *mask,
20875 +       uint32_t prefix, uint16_t type, uint16_t flags)
20876 +{
20877 +       struct nx_addr_v6 *nxa = &nxi->v6;
20878 +
20879 +       if (NX_IPV6(nxi)) {
20880 +               /* locate last entry */
20881 +               for (; nxa->next; nxa = nxa->next);
20882 +               nxa->next = __alloc_nx_addr_v6();
20883 +               nxa = nxa->next;
20884 +
20885 +               if (IS_ERR(nxa))
20886 +                       return PTR_ERR(nxa);
20887 +       }
20888 +
20889 +       nxa->ip = *ip;
20890 +       nxa->mask = *mask;
20891 +       nxa->prefix = prefix;
20892 +       nxa->type = type;
20893 +       nxa->flags = flags;
20894 +       return 0;
20895 +}
20896 +
20897 +
20898 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20899 +{
20900 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20901 +
20902 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20903 +               return -EFAULT;
20904 +
20905 +       switch (vc_data.type) {
20906 +       case NXA_TYPE_ADDR:
20907 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20908 +               /* fallthrough */
20909 +       case NXA_TYPE_MASK:
20910 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20911 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20912 +       default:
20913 +               return -EINVAL;
20914 +       }
20915 +       return 0;
20916 +}
20917 +
20918 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20919 +{
20920 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20921 +
20922 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20923 +               return -EFAULT;
20924 +
20925 +       switch (vc_data.type) {
20926 +       case NXA_TYPE_ANY:
20927 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20928 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20929 +               break;
20930 +
20931 +       default:
20932 +               return -EINVAL;
20933 +       }
20934 +       return 0;
20935 +}
20936 +
20937 +#endif /* CONFIG_IPV6 */
20938 +
20939 +
20940 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20941 +{
20942 +       struct vcmd_net_flags_v0 vc_data;
20943 +
20944 +       vc_data.flagword = nxi->nx_flags;
20945 +
20946 +       /* special STATE flag handling */
20947 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20948 +
20949 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20950 +               return -EFAULT;
20951 +       return 0;
20952 +}
20953 +
20954 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20955 +{
20956 +       struct vcmd_net_flags_v0 vc_data;
20957 +       uint64_t mask, trigger;
20958 +
20959 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20960 +               return -EFAULT;
20961 +
20962 +       /* special STATE flag handling */
20963 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20964 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20965 +
20966 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20967 +               vc_data.flagword, mask);
20968 +       if (trigger & NXF_PERSISTENT)
20969 +               nx_update_persistent(nxi);
20970 +
20971 +       return 0;
20972 +}
20973 +
20974 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20975 +{
20976 +       struct vcmd_net_caps_v0 vc_data;
20977 +
20978 +       vc_data.ncaps = nxi->nx_ncaps;
20979 +       vc_data.cmask = ~0ULL;
20980 +
20981 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20982 +               return -EFAULT;
20983 +       return 0;
20984 +}
20985 +
20986 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20987 +{
20988 +       struct vcmd_net_caps_v0 vc_data;
20989 +
20990 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20991 +               return -EFAULT;
20992 +
20993 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20994 +               vc_data.ncaps, vc_data.cmask);
20995 +       return 0;
20996 +}
20997 +
20998 +
20999 +#include <linux/module.h>
21000 +
21001 +module_init(init_network);
21002 +
21003 +EXPORT_SYMBOL_GPL(free_nx_info);
21004 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21005 +
21006 diff -NurpP --minimal linux-3.5.4/kernel/vserver/proc.c linux-3.5.4-vs2.3.4.3/kernel/vserver/proc.c
21007 --- linux-3.5.4/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21008 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/proc.c 2012-07-23 01:45:55.000000000 +0200
21009 @@ -0,0 +1,1103 @@
21010 +/*
21011 + *  linux/kernel/vserver/proc.c
21012 + *
21013 + *  Virtual Context Support
21014 + *
21015 + *  Copyright (C) 2003-2011  Herbert Pötzl
21016 + *
21017 + *  V0.01  basic structure
21018 + *  V0.02  adaptation vs1.3.0
21019 + *  V0.03  proc permissions
21020 + *  V0.04  locking/generic
21021 + *  V0.05  next generation procfs
21022 + *  V0.06  inode validation
21023 + *  V0.07  generic rewrite vid
21024 + *  V0.08  remove inode type
21025 + *  V0.09  added u/wmask info
21026 + *
21027 + */
21028 +
21029 +#include <linux/proc_fs.h>
21030 +#include <linux/fs_struct.h>
21031 +#include <linux/mount.h>
21032 +#include <asm/unistd.h>
21033 +
21034 +#include <linux/vs_context.h>
21035 +#include <linux/vs_network.h>
21036 +#include <linux/vs_cvirt.h>
21037 +
21038 +#include <linux/in.h>
21039 +#include <linux/inetdevice.h>
21040 +#include <linux/vs_inet.h>
21041 +#include <linux/vs_inet6.h>
21042 +
21043 +#include <linux/vserver/global.h>
21044 +
21045 +#include "cvirt_proc.h"
21046 +#include "cacct_proc.h"
21047 +#include "limit_proc.h"
21048 +#include "sched_proc.h"
21049 +#include "vci_config.h"
21050 +
21051 +
21052 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21053 +{
21054 +       unsigned __capi;
21055 +
21056 +       CAP_FOR_EACH_U32(__capi) {
21057 +               buffer += sprintf(buffer, "%08x",
21058 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21059 +       }
21060 +       return buffer;
21061 +}
21062 +
21063 +
21064 +static struct proc_dir_entry *proc_virtual;
21065 +
21066 +static struct proc_dir_entry *proc_virtnet;
21067 +
21068 +
21069 +/* first the actual feeds */
21070 +
21071 +
21072 +static int proc_vci(char *buffer)
21073 +{
21074 +       return sprintf(buffer,
21075 +               "VCIVersion:\t%04x:%04x\n"
21076 +               "VCISyscall:\t%d\n"
21077 +               "VCIKernel:\t%08x\n",
21078 +               VCI_VERSION >> 16,
21079 +               VCI_VERSION & 0xFFFF,
21080 +               __NR_vserver,
21081 +               vci_kernel_config());
21082 +}
21083 +
21084 +static int proc_virtual_info(char *buffer)
21085 +{
21086 +       return proc_vci(buffer);
21087 +}
21088 +
21089 +static int proc_virtual_status(char *buffer)
21090 +{
21091 +       return sprintf(buffer,
21092 +               "#CTotal:\t%d\n"
21093 +               "#CActive:\t%d\n"
21094 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21095 +               "#InitTask:\t%d\t%d %d\n",
21096 +               atomic_read(&vx_global_ctotal),
21097 +               atomic_read(&vx_global_cactive),
21098 +               atomic_read(&vs_global_nsproxy),
21099 +               atomic_read(&vs_global_fs),
21100 +               atomic_read(&vs_global_mnt_ns),
21101 +               atomic_read(&vs_global_uts_ns),
21102 +               atomic_read(&nr_ipc_ns),
21103 +               atomic_read(&vs_global_user_ns),
21104 +               atomic_read(&vs_global_pid_ns),
21105 +               atomic_read(&init_task.usage),
21106 +               atomic_read(&init_task.nsproxy->count),
21107 +               init_task.fs->users);
21108 +}
21109 +
21110 +
21111 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21112 +{
21113 +       int length;
21114 +
21115 +       length = sprintf(buffer,
21116 +               "ID:\t%d\n"
21117 +               "Info:\t%p\n"
21118 +               "Init:\t%d\n"
21119 +               "OOM:\t%lld\n",
21120 +               vxi->vx_id,
21121 +               vxi,
21122 +               vxi->vx_initpid,
21123 +               vxi->vx_badness_bias);
21124 +       return length;
21125 +}
21126 +
21127 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21128 +{
21129 +       char *orig = buffer;
21130 +
21131 +       buffer += sprintf(buffer,
21132 +               "UseCnt:\t%d\n"
21133 +               "Tasks:\t%d\n"
21134 +               "Flags:\t%016llx\n",
21135 +               atomic_read(&vxi->vx_usecnt),
21136 +               atomic_read(&vxi->vx_tasks),
21137 +               (unsigned long long)vxi->vx_flags);
21138 +
21139 +       buffer += sprintf(buffer, "BCaps:\t");
21140 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21141 +       buffer += sprintf(buffer, "\n");
21142 +
21143 +       buffer += sprintf(buffer,
21144 +               "CCaps:\t%016llx\n"
21145 +               "Umask:\t%16llx\n"
21146 +               "Wmask:\t%16llx\n"
21147 +               "Spaces:\t%08lx %08lx\n",
21148 +               (unsigned long long)vxi->vx_ccaps,
21149 +               (unsigned long long)vxi->vx_umask,
21150 +               (unsigned long long)vxi->vx_wmask,
21151 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21152 +       return buffer - orig;
21153 +}
21154 +
21155 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21156 +{
21157 +       return vx_info_proc_limit(&vxi->limit, buffer);
21158 +}
21159 +
21160 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21161 +{
21162 +       int cpu, length;
21163 +
21164 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21165 +       for_each_online_cpu(cpu) {
21166 +               length += vx_info_proc_sched_pc(
21167 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21168 +                       buffer + length, cpu);
21169 +       }
21170 +       return length;
21171 +}
21172 +
21173 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21174 +{
21175 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21176 +}
21177 +
21178 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21179 +{
21180 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21181 +}
21182 +
21183 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21184 +{
21185 +       int cpu, length;
21186 +
21187 +       vx_update_load(vxi);
21188 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21189 +       for_each_online_cpu(cpu) {
21190 +               length += vx_info_proc_cvirt_pc(
21191 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21192 +                       buffer + length, cpu);
21193 +       }
21194 +       return length;
21195 +}
21196 +
21197 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21198 +{
21199 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21200 +}
21201 +
21202 +
21203 +static int proc_virtnet_info(char *buffer)
21204 +{
21205 +       return proc_vci(buffer);
21206 +}
21207 +
21208 +static int proc_virtnet_status(char *buffer)
21209 +{
21210 +       return sprintf(buffer,
21211 +               "#CTotal:\t%d\n"
21212 +               "#CActive:\t%d\n",
21213 +               atomic_read(&nx_global_ctotal),
21214 +               atomic_read(&nx_global_cactive));
21215 +}
21216 +
21217 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21218 +{
21219 +       struct nx_addr_v4 *v4a;
21220 +#ifdef CONFIG_IPV6
21221 +       struct nx_addr_v6 *v6a;
21222 +#endif
21223 +       int length, i;
21224 +
21225 +       length = sprintf(buffer,
21226 +               "ID:\t%d\n"
21227 +               "Info:\t%p\n"
21228 +               "Bcast:\t" NIPQUAD_FMT "\n"
21229 +               "Lback:\t" NIPQUAD_FMT "\n",
21230 +               nxi->nx_id,
21231 +               nxi,
21232 +               NIPQUAD(nxi->v4_bcast.s_addr),
21233 +               NIPQUAD(nxi->v4_lback.s_addr));
21234 +
21235 +       if (!NX_IPV4(nxi))
21236 +               goto skip_v4;
21237 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21238 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21239 +                       i, NXAV4(v4a));
21240 +skip_v4:
21241 +#ifdef CONFIG_IPV6
21242 +       if (!NX_IPV6(nxi))
21243 +               goto skip_v6;
21244 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21245 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21246 +                       i, NXAV6(v6a));
21247 +skip_v6:
21248 +#endif
21249 +       return length;
21250 +}
21251 +
21252 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21253 +{
21254 +       int length;
21255 +
21256 +       length = sprintf(buffer,
21257 +               "UseCnt:\t%d\n"
21258 +               "Tasks:\t%d\n"
21259 +               "Flags:\t%016llx\n"
21260 +               "NCaps:\t%016llx\n",
21261 +               atomic_read(&nxi->nx_usecnt),
21262 +               atomic_read(&nxi->nx_tasks),
21263 +               (unsigned long long)nxi->nx_flags,
21264 +               (unsigned long long)nxi->nx_ncaps);
21265 +       return length;
21266 +}
21267 +
21268 +
21269 +
21270 +/* here the inode helpers */
21271 +
21272 +struct vs_entry {
21273 +       int len;
21274 +       char *name;
21275 +       mode_t mode;
21276 +       struct inode_operations *iop;
21277 +       struct file_operations *fop;
21278 +       union proc_op op;
21279 +};
21280 +
21281 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21282 +{
21283 +       struct inode *inode = new_inode(sb);
21284 +
21285 +       if (!inode)
21286 +               goto out;
21287 +
21288 +       inode->i_mode = p->mode;
21289 +       if (p->iop)
21290 +               inode->i_op = p->iop;
21291 +       if (p->fop)
21292 +               inode->i_fop = p->fop;
21293 +
21294 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21295 +       inode->i_flags |= S_IMMUTABLE;
21296 +
21297 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21298 +
21299 +       inode->i_uid = 0;
21300 +       inode->i_gid = 0;
21301 +       inode->i_tag = 0;
21302 +out:
21303 +       return inode;
21304 +}
21305 +
21306 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21307 +       struct dentry *dentry, int id, void *ptr)
21308 +{
21309 +       struct vs_entry *p = ptr;
21310 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21311 +       struct dentry *error = ERR_PTR(-EINVAL);
21312 +
21313 +       if (!inode)
21314 +               goto out;
21315 +
21316 +       PROC_I(inode)->op = p->op;
21317 +       PROC_I(inode)->fd = id;
21318 +       d_add(dentry, inode);
21319 +       error = NULL;
21320 +out:
21321 +       return error;
21322 +}
21323 +
21324 +/* Lookups */
21325 +
21326 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21327 +
21328 +/*
21329 + * Fill a directory entry.
21330 + *
21331 + * If possible create the dcache entry and derive our inode number and
21332 + * file type from dcache entry.
21333 + *
21334 + * Since all of the proc inode numbers are dynamically generated, the inode
21335 + * numbers do not exist until the inode is cache.  This means creating the
21336 + * the dcache entry in readdir is necessary to keep the inode numbers
21337 + * reported by readdir in sync with the inode numbers reported
21338 + * by stat.
21339 + */
21340 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21341 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21342 +{
21343 +       struct dentry *child, *dir = filp->f_dentry;
21344 +       struct inode *inode;
21345 +       struct qstr qname;
21346 +       ino_t ino = 0;
21347 +       unsigned type = DT_UNKNOWN;
21348 +
21349 +       qname.name = name;
21350 +       qname.len  = len;
21351 +       qname.hash = full_name_hash(name, len);
21352 +
21353 +       child = d_lookup(dir, &qname);
21354 +       if (!child) {
21355 +               struct dentry *new;
21356 +               new = d_alloc(dir, &qname);
21357 +               if (new) {
21358 +                       child = instantiate(dir->d_inode, new, id, ptr);
21359 +                       if (child)
21360 +                               dput(new);
21361 +                       else
21362 +                               child = new;
21363 +               }
21364 +       }
21365 +       if (!child || IS_ERR(child) || !child->d_inode)
21366 +               goto end_instantiate;
21367 +       inode = child->d_inode;
21368 +       if (inode) {
21369 +               ino = inode->i_ino;
21370 +               type = inode->i_mode >> 12;
21371 +       }
21372 +       dput(child);
21373 +end_instantiate:
21374 +       if (!ino)
21375 +               ino = find_inode_number(dir, &qname);
21376 +       if (!ino)
21377 +               ino = 1;
21378 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21379 +}
21380 +
21381 +
21382 +
21383 +/* get and revalidate vx_info/xid */
21384 +
21385 +static inline
21386 +struct vx_info *get_proc_vx_info(struct inode *inode)
21387 +{
21388 +       return lookup_vx_info(PROC_I(inode)->fd);
21389 +}
21390 +
21391 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21392 +{
21393 +       struct inode *inode = dentry->d_inode;
21394 +       xid_t xid = PROC_I(inode)->fd;
21395 +
21396 +       if (!xid || xid_is_hashed(xid))
21397 +               return 1;
21398 +       d_drop(dentry);
21399 +       return 0;
21400 +}
21401 +
21402 +
21403 +/* get and revalidate nx_info/nid */
21404 +
21405 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21406 +{
21407 +       struct inode *inode = dentry->d_inode;
21408 +       nid_t nid = PROC_I(inode)->fd;
21409 +
21410 +       if (!nid || nid_is_hashed(nid))
21411 +               return 1;
21412 +       d_drop(dentry);
21413 +       return 0;
21414 +}
21415 +
21416 +
21417 +
21418 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21419 +
21420 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21421 +                         size_t count, loff_t *ppos)
21422 +{
21423 +       struct inode *inode = file->f_dentry->d_inode;
21424 +       unsigned long page;
21425 +       ssize_t length = 0;
21426 +
21427 +       if (count > PROC_BLOCK_SIZE)
21428 +               count = PROC_BLOCK_SIZE;
21429 +
21430 +       /* fade that out as soon as stable */
21431 +       WARN_ON(PROC_I(inode)->fd);
21432 +
21433 +       if (!(page = __get_free_page(GFP_KERNEL)))
21434 +               return -ENOMEM;
21435 +
21436 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21437 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21438 +
21439 +       if (length >= 0)
21440 +               length = simple_read_from_buffer(buf, count, ppos,
21441 +                       (char *)page, length);
21442 +
21443 +       free_page(page);
21444 +       return length;
21445 +}
21446 +
21447 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21448 +                         size_t count, loff_t *ppos)
21449 +{
21450 +       struct inode *inode = file->f_dentry->d_inode;
21451 +       struct vx_info *vxi = NULL;
21452 +       xid_t xid = PROC_I(inode)->fd;
21453 +       unsigned long page;
21454 +       ssize_t length = 0;
21455 +
21456 +       if (count > PROC_BLOCK_SIZE)
21457 +               count = PROC_BLOCK_SIZE;
21458 +
21459 +       /* fade that out as soon as stable */
21460 +       WARN_ON(!xid);
21461 +       vxi = lookup_vx_info(xid);
21462 +       if (!vxi)
21463 +               goto out;
21464 +
21465 +       length = -ENOMEM;
21466 +       if (!(page = __get_free_page(GFP_KERNEL)))
21467 +               goto out_put;
21468 +
21469 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21470 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21471 +
21472 +       if (length >= 0)
21473 +               length = simple_read_from_buffer(buf, count, ppos,
21474 +                       (char *)page, length);
21475 +
21476 +       free_page(page);
21477 +out_put:
21478 +       put_vx_info(vxi);
21479 +out:
21480 +       return length;
21481 +}
21482 +
21483 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21484 +                         size_t count, loff_t *ppos)
21485 +{
21486 +       struct inode *inode = file->f_dentry->d_inode;
21487 +       struct nx_info *nxi = NULL;
21488 +       nid_t nid = PROC_I(inode)->fd;
21489 +       unsigned long page;
21490 +       ssize_t length = 0;
21491 +
21492 +       if (count > PROC_BLOCK_SIZE)
21493 +               count = PROC_BLOCK_SIZE;
21494 +
21495 +       /* fade that out as soon as stable */
21496 +       WARN_ON(!nid);
21497 +       nxi = lookup_nx_info(nid);
21498 +       if (!nxi)
21499 +               goto out;
21500 +
21501 +       length = -ENOMEM;
21502 +       if (!(page = __get_free_page(GFP_KERNEL)))
21503 +               goto out_put;
21504 +
21505 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21506 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21507 +
21508 +       if (length >= 0)
21509 +               length = simple_read_from_buffer(buf, count, ppos,
21510 +                       (char *)page, length);
21511 +
21512 +       free_page(page);
21513 +out_put:
21514 +       put_nx_info(nxi);
21515 +out:
21516 +       return length;
21517 +}
21518 +
21519 +
21520 +
21521 +/* here comes the lower level */
21522 +
21523 +
21524 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21525 +       .len  = sizeof(NAME) - 1,       \
21526 +       .name = (NAME),                 \
21527 +       .mode = MODE,                   \
21528 +       .iop  = IOP,                    \
21529 +       .fop  = FOP,                    \
21530 +       .op   = OP,                     \
21531 +}
21532 +
21533 +
21534 +#define DIR(NAME, MODE, OTYPE)                         \
21535 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21536 +               &proc_ ## OTYPE ## _inode_operations,   \
21537 +               &proc_ ## OTYPE ## _file_operations, { } )
21538 +
21539 +#define INF(NAME, MODE, OTYPE)                         \
21540 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21541 +               &proc_vs_info_file_operations,          \
21542 +               { .proc_vs_read = &proc_##OTYPE } )
21543 +
21544 +#define VINF(NAME, MODE, OTYPE)                                \
21545 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21546 +               &proc_vx_info_file_operations,          \
21547 +               { .proc_vxi_read = &proc_##OTYPE } )
21548 +
21549 +#define NINF(NAME, MODE, OTYPE)                                \
21550 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21551 +               &proc_nx_info_file_operations,          \
21552 +               { .proc_nxi_read = &proc_##OTYPE } )
21553 +
21554 +
21555 +static struct file_operations proc_vs_info_file_operations = {
21556 +       .read =         proc_vs_info_read,
21557 +};
21558 +
21559 +static struct file_operations proc_vx_info_file_operations = {
21560 +       .read =         proc_vx_info_read,
21561 +};
21562 +
21563 +static struct dentry_operations proc_xid_dentry_operations = {
21564 +       .d_revalidate = proc_xid_revalidate,
21565 +};
21566 +
21567 +static struct vs_entry vx_base_stuff[] = {
21568 +       VINF("info",    S_IRUGO, vxi_info),
21569 +       VINF("status",  S_IRUGO, vxi_status),
21570 +       VINF("limit",   S_IRUGO, vxi_limit),
21571 +       VINF("sched",   S_IRUGO, vxi_sched),
21572 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21573 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21574 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21575 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21576 +       {}
21577 +};
21578 +
21579 +
21580 +
21581 +
21582 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21583 +       struct dentry *dentry, int id, void *ptr)
21584 +{
21585 +       dentry->d_op = &proc_xid_dentry_operations;
21586 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21587 +}
21588 +
21589 +static struct dentry *proc_xid_lookup(struct inode *dir,
21590 +       struct dentry *dentry, struct nameidata *nd)
21591 +{
21592 +       struct vs_entry *p = vx_base_stuff;
21593 +       struct dentry *error = ERR_PTR(-ENOENT);
21594 +
21595 +       for (; p->name; p++) {
21596 +               if (p->len != dentry->d_name.len)
21597 +                       continue;
21598 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21599 +                       break;
21600 +       }
21601 +       if (!p->name)
21602 +               goto out;
21603 +
21604 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21605 +out:
21606 +       return error;
21607 +}
21608 +
21609 +static int proc_xid_readdir(struct file *filp,
21610 +       void *dirent, filldir_t filldir)
21611 +{
21612 +       struct dentry *dentry = filp->f_dentry;
21613 +       struct inode *inode = dentry->d_inode;
21614 +       struct vs_entry *p = vx_base_stuff;
21615 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21616 +       int pos, index;
21617 +       u64 ino;
21618 +
21619 +       pos = filp->f_pos;
21620 +       switch (pos) {
21621 +       case 0:
21622 +               ino = inode->i_ino;
21623 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21624 +                       goto out;
21625 +               pos++;
21626 +               /* fall through */
21627 +       case 1:
21628 +               ino = parent_ino(dentry);
21629 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21630 +                       goto out;
21631 +               pos++;
21632 +               /* fall through */
21633 +       default:
21634 +               index = pos - 2;
21635 +               if (index >= size)
21636 +                       goto out;
21637 +               for (p += index; p->name; p++) {
21638 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21639 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21640 +                               goto out;
21641 +                       pos++;
21642 +               }
21643 +       }
21644 +out:
21645 +       filp->f_pos = pos;
21646 +       return 1;
21647 +}
21648 +
21649 +
21650 +
21651 +static struct file_operations proc_nx_info_file_operations = {
21652 +       .read =         proc_nx_info_read,
21653 +};
21654 +
21655 +static struct dentry_operations proc_nid_dentry_operations = {
21656 +       .d_revalidate = proc_nid_revalidate,
21657 +};
21658 +
21659 +static struct vs_entry nx_base_stuff[] = {
21660 +       NINF("info",    S_IRUGO, nxi_info),
21661 +       NINF("status",  S_IRUGO, nxi_status),
21662 +       {}
21663 +};
21664 +
21665 +
21666 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21667 +       struct dentry *dentry, int id, void *ptr)
21668 +{
21669 +       dentry->d_op = &proc_nid_dentry_operations;
21670 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21671 +}
21672 +
21673 +static struct dentry *proc_nid_lookup(struct inode *dir,
21674 +       struct dentry *dentry, struct nameidata *nd)
21675 +{
21676 +       struct vs_entry *p = nx_base_stuff;
21677 +       struct dentry *error = ERR_PTR(-ENOENT);
21678 +
21679 +       for (; p->name; p++) {
21680 +               if (p->len != dentry->d_name.len)
21681 +                       continue;
21682 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21683 +                       break;
21684 +       }
21685 +       if (!p->name)
21686 +               goto out;
21687 +
21688 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21689 +out:
21690 +       return error;
21691 +}
21692 +
21693 +static int proc_nid_readdir(struct file *filp,
21694 +       void *dirent, filldir_t filldir)
21695 +{
21696 +       struct dentry *dentry = filp->f_dentry;
21697 +       struct inode *inode = dentry->d_inode;
21698 +       struct vs_entry *p = nx_base_stuff;
21699 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21700 +       int pos, index;
21701 +       u64 ino;
21702 +
21703 +       pos = filp->f_pos;
21704 +       switch (pos) {
21705 +       case 0:
21706 +               ino = inode->i_ino;
21707 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21708 +                       goto out;
21709 +               pos++;
21710 +               /* fall through */
21711 +       case 1:
21712 +               ino = parent_ino(dentry);
21713 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21714 +                       goto out;
21715 +               pos++;
21716 +               /* fall through */
21717 +       default:
21718 +               index = pos - 2;
21719 +               if (index >= size)
21720 +                       goto out;
21721 +               for (p += index; p->name; p++) {
21722 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21723 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21724 +                               goto out;
21725 +                       pos++;
21726 +               }
21727 +       }
21728 +out:
21729 +       filp->f_pos = pos;
21730 +       return 1;
21731 +}
21732 +
21733 +
21734 +#define MAX_MULBY10    ((~0U - 9) / 10)
21735 +
21736 +static inline int atovid(const char *str, int len)
21737 +{
21738 +       int vid, c;
21739 +
21740 +       vid = 0;
21741 +       while (len-- > 0) {
21742 +               c = *str - '0';
21743 +               str++;
21744 +               if (c > 9)
21745 +                       return -1;
21746 +               if (vid >= MAX_MULBY10)
21747 +                       return -1;
21748 +               vid *= 10;
21749 +               vid += c;
21750 +               if (!vid)
21751 +                       return -1;
21752 +       }
21753 +       return vid;
21754 +}
21755 +
21756 +/* now the upper level (virtual) */
21757 +
21758 +
21759 +static struct file_operations proc_xid_file_operations = {
21760 +       .read =         generic_read_dir,
21761 +       .readdir =      proc_xid_readdir,
21762 +};
21763 +
21764 +static struct inode_operations proc_xid_inode_operations = {
21765 +       .lookup =       proc_xid_lookup,
21766 +};
21767 +
21768 +static struct vs_entry vx_virtual_stuff[] = {
21769 +       INF("info",     S_IRUGO, virtual_info),
21770 +       INF("status",   S_IRUGO, virtual_status),
21771 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21772 +};
21773 +
21774 +
21775 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21776 +       struct dentry *dentry, struct nameidata *nd)
21777 +{
21778 +       struct vs_entry *p = vx_virtual_stuff;
21779 +       struct dentry *error = ERR_PTR(-ENOENT);
21780 +       int id = 0;
21781 +
21782 +       for (; p->name; p++) {
21783 +               if (p->len != dentry->d_name.len)
21784 +                       continue;
21785 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21786 +                       break;
21787 +       }
21788 +       if (p->name)
21789 +               goto instantiate;
21790 +
21791 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21792 +       if ((id < 0) || !xid_is_hashed(id))
21793 +               goto out;
21794 +
21795 +instantiate:
21796 +       error = proc_xid_instantiate(dir, dentry, id, p);
21797 +out:
21798 +       return error;
21799 +}
21800 +
21801 +static struct file_operations proc_nid_file_operations = {
21802 +       .read =         generic_read_dir,
21803 +       .readdir =      proc_nid_readdir,
21804 +};
21805 +
21806 +static struct inode_operations proc_nid_inode_operations = {
21807 +       .lookup =       proc_nid_lookup,
21808 +};
21809 +
21810 +static struct vs_entry nx_virtnet_stuff[] = {
21811 +       INF("info",     S_IRUGO, virtnet_info),
21812 +       INF("status",   S_IRUGO, virtnet_status),
21813 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21814 +};
21815 +
21816 +
21817 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21818 +       struct dentry *dentry, struct nameidata *nd)
21819 +{
21820 +       struct vs_entry *p = nx_virtnet_stuff;
21821 +       struct dentry *error = ERR_PTR(-ENOENT);
21822 +       int id = 0;
21823 +
21824 +       for (; p->name; p++) {
21825 +               if (p->len != dentry->d_name.len)
21826 +                       continue;
21827 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21828 +                       break;
21829 +       }
21830 +       if (p->name)
21831 +               goto instantiate;
21832 +
21833 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21834 +       if ((id < 0) || !nid_is_hashed(id))
21835 +               goto out;
21836 +
21837 +instantiate:
21838 +       error = proc_nid_instantiate(dir, dentry, id, p);
21839 +out:
21840 +       return error;
21841 +}
21842 +
21843 +
21844 +#define PROC_MAXVIDS 32
21845 +
21846 +int proc_virtual_readdir(struct file *filp,
21847 +       void *dirent, filldir_t filldir)
21848 +{
21849 +       struct dentry *dentry = filp->f_dentry;
21850 +       struct inode *inode = dentry->d_inode;
21851 +       struct vs_entry *p = vx_virtual_stuff;
21852 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21853 +       int pos, index;
21854 +       unsigned int xid_array[PROC_MAXVIDS];
21855 +       char buf[PROC_NUMBUF];
21856 +       unsigned int nr_xids, i;
21857 +       u64 ino;
21858 +
21859 +       pos = filp->f_pos;
21860 +       switch (pos) {
21861 +       case 0:
21862 +               ino = inode->i_ino;
21863 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21864 +                       goto out;
21865 +               pos++;
21866 +               /* fall through */
21867 +       case 1:
21868 +               ino = parent_ino(dentry);
21869 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21870 +                       goto out;
21871 +               pos++;
21872 +               /* fall through */
21873 +       default:
21874 +               index = pos - 2;
21875 +               if (index >= size)
21876 +                       goto entries;
21877 +               for (p += index; p->name; p++) {
21878 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21879 +                               vs_proc_instantiate, 0, p))
21880 +                               goto out;
21881 +                       pos++;
21882 +               }
21883 +       entries:
21884 +               index = pos - size;
21885 +               p = &vx_virtual_stuff[size - 1];
21886 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21887 +               for (i = 0; i < nr_xids; i++) {
21888 +                       int n, xid = xid_array[i];
21889 +                       unsigned int j = PROC_NUMBUF;
21890 +
21891 +                       n = xid;
21892 +                       do
21893 +                               buf[--j] = '0' + (n % 10);
21894 +                       while (n /= 10);
21895 +
21896 +                       if (proc_fill_cache(filp, dirent, filldir,
21897 +                               buf + j, PROC_NUMBUF - j,
21898 +                               vs_proc_instantiate, xid, p))
21899 +                               goto out;
21900 +                       pos++;
21901 +               }
21902 +       }
21903 +out:
21904 +       filp->f_pos = pos;
21905 +       return 0;
21906 +}
21907 +
21908 +static int proc_virtual_getattr(struct vfsmount *mnt,
21909 +       struct dentry *dentry, struct kstat *stat)
21910 +{
21911 +       struct inode *inode = dentry->d_inode;
21912 +
21913 +       generic_fillattr(inode, stat);
21914 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21915 +       return 0;
21916 +}
21917 +
21918 +static struct file_operations proc_virtual_dir_operations = {
21919 +       .read =         generic_read_dir,
21920 +       .readdir =      proc_virtual_readdir,
21921 +};
21922 +
21923 +static struct inode_operations proc_virtual_dir_inode_operations = {
21924 +       .getattr =      proc_virtual_getattr,
21925 +       .lookup =       proc_virtual_lookup,
21926 +};
21927 +
21928 +
21929 +
21930 +
21931 +
21932 +int proc_virtnet_readdir(struct file *filp,
21933 +       void *dirent, filldir_t filldir)
21934 +{
21935 +       struct dentry *dentry = filp->f_dentry;
21936 +       struct inode *inode = dentry->d_inode;
21937 +       struct vs_entry *p = nx_virtnet_stuff;
21938 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21939 +       int pos, index;
21940 +       unsigned int nid_array[PROC_MAXVIDS];
21941 +       char buf[PROC_NUMBUF];
21942 +       unsigned int nr_nids, i;
21943 +       u64 ino;
21944 +
21945 +       pos = filp->f_pos;
21946 +       switch (pos) {
21947 +       case 0:
21948 +               ino = inode->i_ino;
21949 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21950 +                       goto out;
21951 +               pos++;
21952 +               /* fall through */
21953 +       case 1:
21954 +               ino = parent_ino(dentry);
21955 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21956 +                       goto out;
21957 +               pos++;
21958 +               /* fall through */
21959 +       default:
21960 +               index = pos - 2;
21961 +               if (index >= size)
21962 +                       goto entries;
21963 +               for (p += index; p->name; p++) {
21964 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21965 +                               vs_proc_instantiate, 0, p))
21966 +                               goto out;
21967 +                       pos++;
21968 +               }
21969 +       entries:
21970 +               index = pos - size;
21971 +               p = &nx_virtnet_stuff[size - 1];
21972 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21973 +               for (i = 0; i < nr_nids; i++) {
21974 +                       int n, nid = nid_array[i];
21975 +                       unsigned int j = PROC_NUMBUF;
21976 +
21977 +                       n = nid;
21978 +                       do
21979 +                               buf[--j] = '0' + (n % 10);
21980 +                       while (n /= 10);
21981 +
21982 +                       if (proc_fill_cache(filp, dirent, filldir,
21983 +                               buf + j, PROC_NUMBUF - j,
21984 +                               vs_proc_instantiate, nid, p))
21985 +                               goto out;
21986 +                       pos++;
21987 +               }
21988 +       }
21989 +out:
21990 +       filp->f_pos = pos;
21991 +       return 0;
21992 +}
21993 +
21994 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21995 +       struct dentry *dentry, struct kstat *stat)
21996 +{
21997 +       struct inode *inode = dentry->d_inode;
21998 +
21999 +       generic_fillattr(inode, stat);
22000 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22001 +       return 0;
22002 +}
22003 +
22004 +static struct file_operations proc_virtnet_dir_operations = {
22005 +       .read =         generic_read_dir,
22006 +       .readdir =      proc_virtnet_readdir,
22007 +};
22008 +
22009 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22010 +       .getattr =      proc_virtnet_getattr,
22011 +       .lookup =       proc_virtnet_lookup,
22012 +};
22013 +
22014 +
22015 +
22016 +void proc_vx_init(void)
22017 +{
22018 +       struct proc_dir_entry *ent;
22019 +
22020 +       ent = proc_mkdir("virtual", 0);
22021 +       if (ent) {
22022 +               ent->proc_fops = &proc_virtual_dir_operations;
22023 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22024 +       }
22025 +       proc_virtual = ent;
22026 +
22027 +       ent = proc_mkdir("virtnet", 0);
22028 +       if (ent) {
22029 +               ent->proc_fops = &proc_virtnet_dir_operations;
22030 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22031 +       }
22032 +       proc_virtnet = ent;
22033 +}
22034 +
22035 +
22036 +
22037 +
22038 +/* per pid info */
22039 +
22040 +
22041 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22042 +{
22043 +       struct vx_info *vxi;
22044 +       char *orig = buffer;
22045 +
22046 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22047 +
22048 +       vxi = task_get_vx_info(p);
22049 +       if (!vxi)
22050 +               goto out;
22051 +
22052 +       buffer += sprintf(buffer, "BCaps:\t");
22053 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22054 +       buffer += sprintf(buffer, "\n");
22055 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22056 +               (unsigned long long)vxi->vx_ccaps);
22057 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22058 +               (unsigned long long)vxi->vx_flags);
22059 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22060 +
22061 +       put_vx_info(vxi);
22062 +out:
22063 +       return buffer - orig;
22064 +}
22065 +
22066 +
22067 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22068 +{
22069 +       struct nx_info *nxi;
22070 +       struct nx_addr_v4 *v4a;
22071 +#ifdef CONFIG_IPV6
22072 +       struct nx_addr_v6 *v6a;
22073 +#endif
22074 +       char *orig = buffer;
22075 +       int i;
22076 +
22077 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22078 +
22079 +       nxi = task_get_nx_info(p);
22080 +       if (!nxi)
22081 +               goto out;
22082 +
22083 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22084 +               (unsigned long long)nxi->nx_ncaps);
22085 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22086 +               (unsigned long long)nxi->nx_flags);
22087 +
22088 +       buffer += sprintf(buffer,
22089 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22090 +               NIPQUAD(nxi->v4_bcast.s_addr));
22091 +       buffer += sprintf (buffer,
22092 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22093 +               NIPQUAD(nxi->v4_lback.s_addr));
22094 +       if (!NX_IPV4(nxi))
22095 +               goto skip_v4;
22096 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22097 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22098 +                       i, NXAV4(v4a));
22099 +skip_v4:
22100 +#ifdef CONFIG_IPV6
22101 +       if (!NX_IPV6(nxi))
22102 +               goto skip_v6;
22103 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22104 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22105 +                       i, NXAV6(v6a));
22106 +skip_v6:
22107 +#endif
22108 +       put_nx_info(nxi);
22109 +out:
22110 +       return buffer - orig;
22111 +}
22112 +
22113 diff -NurpP --minimal linux-3.5.4/kernel/vserver/sched.c linux-3.5.4-vs2.3.4.3/kernel/vserver/sched.c
22114 --- linux-3.5.4/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22115 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/sched.c        2012-07-23 01:45:55.000000000 +0200
22116 @@ -0,0 +1,83 @@
22117 +/*
22118 + *  linux/kernel/vserver/sched.c
22119 + *
22120 + *  Virtual Server: Scheduler Support
22121 + *
22122 + *  Copyright (C) 2004-2010  Herbert Pötzl
22123 + *
22124 + *  V0.01  adapted Sam Vilains version to 2.6.3
22125 + *  V0.02  removed legacy interface
22126 + *  V0.03  changed vcmds to vxi arg
22127 + *  V0.04  removed older and legacy interfaces
22128 + *  V0.05  removed scheduler code/commands
22129 + *
22130 + */
22131 +
22132 +#include <linux/vs_context.h>
22133 +#include <linux/vs_sched.h>
22134 +#include <linux/cpumask.h>
22135 +#include <linux/vserver/sched_cmd.h>
22136 +
22137 +#include <asm/uaccess.h>
22138 +
22139 +
22140 +void vx_update_sched_param(struct _vx_sched *sched,
22141 +       struct _vx_sched_pc *sched_pc)
22142 +{
22143 +       sched_pc->prio_bias = sched->prio_bias;
22144 +}
22145 +
22146 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22147 +{
22148 +       int cpu;
22149 +
22150 +       if (data->prio_bias > MAX_PRIO_BIAS)
22151 +               data->prio_bias = MAX_PRIO_BIAS;
22152 +       if (data->prio_bias < MIN_PRIO_BIAS)
22153 +               data->prio_bias = MIN_PRIO_BIAS;
22154 +
22155 +       if (data->cpu_id != ~0) {
22156 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22157 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22158 +                       cpu_online_mask);
22159 +       } else
22160 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22161 +
22162 +       for_each_cpu_mask(cpu, vxi->sched.update)
22163 +               vx_update_sched_param(&vxi->sched,
22164 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22165 +       return 0;
22166 +}
22167 +
22168 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22169 +{
22170 +       struct vcmd_prio_bias vc_data;
22171 +
22172 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22173 +               return -EFAULT;
22174 +
22175 +       return do_set_prio_bias(vxi, &vc_data);
22176 +}
22177 +
22178 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22179 +{
22180 +       struct vcmd_prio_bias vc_data;
22181 +       struct _vx_sched_pc *pcd;
22182 +       int cpu;
22183 +
22184 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22185 +               return -EFAULT;
22186 +
22187 +       cpu = vc_data.cpu_id;
22188 +
22189 +       if (!cpu_possible(cpu))
22190 +               return -EINVAL;
22191 +
22192 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22193 +       vc_data.prio_bias = pcd->prio_bias;
22194 +
22195 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22196 +               return -EFAULT;
22197 +       return 0;
22198 +}
22199 +
22200 diff -NurpP --minimal linux-3.5.4/kernel/vserver/sched_init.h linux-3.5.4-vs2.3.4.3/kernel/vserver/sched_init.h
22201 --- linux-3.5.4/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22202 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/sched_init.h   2012-07-23 01:45:55.000000000 +0200
22203 @@ -0,0 +1,27 @@
22204 +
22205 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22206 +{
22207 +       /* scheduling; hard code starting values as constants */
22208 +       sched->prio_bias = 0;
22209 +}
22210 +
22211 +static inline
22212 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22213 +{
22214 +       sched_pc->prio_bias = 0;
22215 +
22216 +       sched_pc->user_ticks = 0;
22217 +       sched_pc->sys_ticks = 0;
22218 +       sched_pc->hold_ticks = 0;
22219 +}
22220 +
22221 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22222 +{
22223 +       return;
22224 +}
22225 +
22226 +static inline
22227 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22228 +{
22229 +       return;
22230 +}
22231 diff -NurpP --minimal linux-3.5.4/kernel/vserver/sched_proc.h linux-3.5.4-vs2.3.4.3/kernel/vserver/sched_proc.h
22232 --- linux-3.5.4/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22233 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/sched_proc.h   2012-07-23 01:45:55.000000000 +0200
22234 @@ -0,0 +1,32 @@
22235 +#ifndef _VX_SCHED_PROC_H
22236 +#define _VX_SCHED_PROC_H
22237 +
22238 +
22239 +static inline
22240 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22241 +{
22242 +       int length = 0;
22243 +
22244 +       length += sprintf(buffer,
22245 +               "PrioBias:\t%8d\n",
22246 +               sched->prio_bias);
22247 +       return length;
22248 +}
22249 +
22250 +static inline
22251 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22252 +       char *buffer, int cpu)
22253 +{
22254 +       int length = 0;
22255 +
22256 +       length += sprintf(buffer + length,
22257 +               "cpu %d: %lld %lld %lld", cpu,
22258 +               (unsigned long long)sched_pc->user_ticks,
22259 +               (unsigned long long)sched_pc->sys_ticks,
22260 +               (unsigned long long)sched_pc->hold_ticks);
22261 +       length += sprintf(buffer + length,
22262 +               " %d\n", sched_pc->prio_bias);
22263 +       return length;
22264 +}
22265 +
22266 +#endif /* _VX_SCHED_PROC_H */
22267 diff -NurpP --minimal linux-3.5.4/kernel/vserver/signal.c linux-3.5.4-vs2.3.4.3/kernel/vserver/signal.c
22268 --- linux-3.5.4/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22269 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/signal.c       2012-07-23 01:45:55.000000000 +0200
22270 @@ -0,0 +1,134 @@
22271 +/*
22272 + *  linux/kernel/vserver/signal.c
22273 + *
22274 + *  Virtual Server: Signal Support
22275 + *
22276 + *  Copyright (C) 2003-2007  Herbert Pötzl
22277 + *
22278 + *  V0.01  broken out from vcontext V0.05
22279 + *  V0.02  changed vcmds to vxi arg
22280 + *  V0.03  adjusted siginfo for kill
22281 + *
22282 + */
22283 +
22284 +#include <asm/uaccess.h>
22285 +
22286 +#include <linux/vs_context.h>
22287 +#include <linux/vs_pid.h>
22288 +#include <linux/vserver/signal_cmd.h>
22289 +
22290 +
22291 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22292 +{
22293 +       int retval, count = 0;
22294 +       struct task_struct *p;
22295 +       struct siginfo *sip = SEND_SIG_PRIV;
22296 +
22297 +       retval = -ESRCH;
22298 +       vxdprintk(VXD_CBIT(misc, 4),
22299 +               "vx_info_kill(%p[#%d],%d,%d)*",
22300 +               vxi, vxi->vx_id, pid, sig);
22301 +       read_lock(&tasklist_lock);
22302 +       switch (pid) {
22303 +       case  0:
22304 +       case -1:
22305 +               for_each_process(p) {
22306 +                       int err = 0;
22307 +
22308 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22309 +                               (pid && vxi->vx_initpid == p->pid))
22310 +                               continue;
22311 +
22312 +                       err = group_send_sig_info(sig, sip, p);
22313 +                       ++count;
22314 +                       if (err != -EPERM)
22315 +                               retval = err;
22316 +               }
22317 +               break;
22318 +
22319 +       case 1:
22320 +               if (vxi->vx_initpid) {
22321 +                       pid = vxi->vx_initpid;
22322 +                       /* for now, only SIGINT to private init ... */
22323 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22324 +                               /* ... as long as there are tasks left */
22325 +                               (atomic_read(&vxi->vx_tasks) > 1))
22326 +                               sig = SIGINT;
22327 +               }
22328 +               /* fallthrough */
22329 +       default:
22330 +               rcu_read_lock();
22331 +               p = find_task_by_real_pid(pid);
22332 +               rcu_read_unlock();
22333 +               if (p) {
22334 +                       if (vx_task_xid(p) == vxi->vx_id)
22335 +                               retval = group_send_sig_info(sig, sip, p);
22336 +               }
22337 +               break;
22338 +       }
22339 +       read_unlock(&tasklist_lock);
22340 +       vxdprintk(VXD_CBIT(misc, 4),
22341 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22342 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22343 +       return retval;
22344 +}
22345 +
22346 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22347 +{
22348 +       struct vcmd_ctx_kill_v0 vc_data;
22349 +
22350 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22351 +               return -EFAULT;
22352 +
22353 +       /* special check to allow guest shutdown */
22354 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22355 +               /* forbid killall pid=0 when init is present */
22356 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22357 +               (vc_data.pid > 1)))
22358 +               return -EACCES;
22359 +
22360 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22361 +}
22362 +
22363 +
22364 +static int __wait_exit(struct vx_info *vxi)
22365 +{
22366 +       DECLARE_WAITQUEUE(wait, current);
22367 +       int ret = 0;
22368 +
22369 +       add_wait_queue(&vxi->vx_wait, &wait);
22370 +       set_current_state(TASK_INTERRUPTIBLE);
22371 +
22372 +wait:
22373 +       if (vx_info_state(vxi,
22374 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22375 +               goto out;
22376 +       if (signal_pending(current)) {
22377 +               ret = -ERESTARTSYS;
22378 +               goto out;
22379 +       }
22380 +       schedule();
22381 +       goto wait;
22382 +
22383 +out:
22384 +       set_current_state(TASK_RUNNING);
22385 +       remove_wait_queue(&vxi->vx_wait, &wait);
22386 +       return ret;
22387 +}
22388 +
22389 +
22390 +
22391 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22392 +{
22393 +       struct vcmd_wait_exit_v0 vc_data;
22394 +       int ret;
22395 +
22396 +       ret = __wait_exit(vxi);
22397 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22398 +       vc_data.exit_code = vxi->exit_code;
22399 +
22400 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22401 +               ret = -EFAULT;
22402 +       return ret;
22403 +}
22404 +
22405 diff -NurpP --minimal linux-3.5.4/kernel/vserver/space.c linux-3.5.4-vs2.3.4.3/kernel/vserver/space.c
22406 --- linux-3.5.4/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22407 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/space.c        2012-07-23 01:45:55.000000000 +0200
22408 @@ -0,0 +1,436 @@
22409 +/*
22410 + *  linux/kernel/vserver/space.c
22411 + *
22412 + *  Virtual Server: Context Space Support
22413 + *
22414 + *  Copyright (C) 2003-2010  Herbert Pötzl
22415 + *
22416 + *  V0.01  broken out from context.c 0.07
22417 + *  V0.02  added task locking for namespace
22418 + *  V0.03  broken out vx_enter_namespace
22419 + *  V0.04  added *space support and commands
22420 + *  V0.05  added credential support
22421 + *
22422 + */
22423 +
22424 +#include <linux/utsname.h>
22425 +#include <linux/nsproxy.h>
22426 +#include <linux/err.h>
22427 +#include <linux/fs_struct.h>
22428 +#include <linux/cred.h>
22429 +#include <asm/uaccess.h>
22430 +
22431 +#include <linux/vs_context.h>
22432 +#include <linux/vserver/space.h>
22433 +#include <linux/vserver/space_cmd.h>
22434 +
22435 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22436 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22437 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22438 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22439 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22440 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22441 +
22442 +
22443 +/* namespace functions */
22444 +
22445 +#include <linux/mnt_namespace.h>
22446 +#include <linux/user_namespace.h>
22447 +#include <linux/pid_namespace.h>
22448 +#include <linux/ipc_namespace.h>
22449 +#include <net/net_namespace.h>
22450 +#include "../fs/mount.h"
22451 +
22452 +
22453 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22454 +       .mask = CLONE_FS |
22455 +               CLONE_NEWNS |
22456 +#ifdef CONFIG_UTS_NS
22457 +               CLONE_NEWUTS |
22458 +#endif
22459 +#ifdef CONFIG_IPC_NS
22460 +               CLONE_NEWIPC |
22461 +#endif
22462 +#ifdef CONFIG_USER_NS
22463 +               CLONE_NEWUSER |
22464 +#endif
22465 +               0
22466 +};
22467 +
22468 +static const struct vcmd_space_mask_v1 space_mask = {
22469 +       .mask = CLONE_FS |
22470 +               CLONE_NEWNS |
22471 +#ifdef CONFIG_UTS_NS
22472 +               CLONE_NEWUTS |
22473 +#endif
22474 +#ifdef CONFIG_IPC_NS
22475 +               CLONE_NEWIPC |
22476 +#endif
22477 +#ifdef CONFIG_USER_NS
22478 +               CLONE_NEWUSER |
22479 +#endif
22480 +#ifdef CONFIG_PID_NS
22481 +               CLONE_NEWPID |
22482 +#endif
22483 +#ifdef CONFIG_NET_NS
22484 +               CLONE_NEWNET |
22485 +#endif
22486 +               0
22487 +};
22488 +
22489 +static const struct vcmd_space_mask_v1 default_space_mask = {
22490 +       .mask = CLONE_FS |
22491 +               CLONE_NEWNS |
22492 +#ifdef CONFIG_UTS_NS
22493 +               CLONE_NEWUTS |
22494 +#endif
22495 +#ifdef CONFIG_IPC_NS
22496 +               CLONE_NEWIPC |
22497 +#endif
22498 +#ifdef CONFIG_USER_NS
22499 +               CLONE_NEWUSER |
22500 +#endif
22501 +#ifdef CONFIG_PID_NS
22502 +//             CLONE_NEWPID |
22503 +#endif
22504 +               0
22505 +};
22506 +
22507 +/*
22508 + *     build a new nsproxy mix
22509 + *      assumes that both proxies are 'const'
22510 + *     does not touch nsproxy refcounts
22511 + *     will hold a reference on the result.
22512 + */
22513 +
22514 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22515 +       struct nsproxy *new_nsproxy, unsigned long mask)
22516 +{
22517 +       struct mnt_namespace *old_ns;
22518 +       struct uts_namespace *old_uts;
22519 +       struct ipc_namespace *old_ipc;
22520 +#ifdef CONFIG_PID_NS
22521 +       struct pid_namespace *old_pid;
22522 +#endif
22523 +#ifdef CONFIG_NET_NS
22524 +       struct net *old_net;
22525 +#endif
22526 +       struct nsproxy *nsproxy;
22527 +
22528 +       nsproxy = copy_nsproxy(old_nsproxy);
22529 +       if (!nsproxy)
22530 +               goto out;
22531 +
22532 +       if (mask & CLONE_NEWNS) {
22533 +               old_ns = nsproxy->mnt_ns;
22534 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22535 +               if (nsproxy->mnt_ns)
22536 +                       get_mnt_ns(nsproxy->mnt_ns);
22537 +       } else
22538 +               old_ns = NULL;
22539 +
22540 +       if (mask & CLONE_NEWUTS) {
22541 +               old_uts = nsproxy->uts_ns;
22542 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22543 +               if (nsproxy->uts_ns)
22544 +                       get_uts_ns(nsproxy->uts_ns);
22545 +       } else
22546 +               old_uts = NULL;
22547 +
22548 +       if (mask & CLONE_NEWIPC) {
22549 +               old_ipc = nsproxy->ipc_ns;
22550 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22551 +               if (nsproxy->ipc_ns)
22552 +                       get_ipc_ns(nsproxy->ipc_ns);
22553 +       } else
22554 +               old_ipc = NULL;
22555 +
22556 +#ifdef CONFIG_PID_NS
22557 +       if (mask & CLONE_NEWPID) {
22558 +               old_pid = nsproxy->pid_ns;
22559 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22560 +               if (nsproxy->pid_ns)
22561 +                       get_pid_ns(nsproxy->pid_ns);
22562 +       } else
22563 +               old_pid = NULL;
22564 +#endif
22565 +#ifdef CONFIG_NET_NS
22566 +       if (mask & CLONE_NEWNET) {
22567 +               old_net = nsproxy->net_ns;
22568 +               nsproxy->net_ns = new_nsproxy->net_ns;
22569 +               if (nsproxy->net_ns)
22570 +                       get_net(nsproxy->net_ns);
22571 +       } else
22572 +               old_net = NULL;
22573 +#endif
22574 +       if (old_ns)
22575 +               put_mnt_ns(old_ns);
22576 +       if (old_uts)
22577 +               put_uts_ns(old_uts);
22578 +       if (old_ipc)
22579 +               put_ipc_ns(old_ipc);
22580 +#ifdef CONFIG_PID_NS
22581 +       if (old_pid)
22582 +               put_pid_ns(old_pid);
22583 +#endif
22584 +#ifdef CONFIG_NET_NS
22585 +       if (old_net)
22586 +               put_net(old_net);
22587 +#endif
22588 +out:
22589 +       return nsproxy;
22590 +}
22591 +
22592 +
22593 +/*
22594 + *     merge two nsproxy structs into a new one.
22595 + *     will hold a reference on the result.
22596 + */
22597 +
22598 +static inline
22599 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22600 +       struct nsproxy *proxy, unsigned long mask)
22601 +{
22602 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22603 +
22604 +       if (!proxy)
22605 +               return NULL;
22606 +
22607 +       if (mask) {
22608 +               /* vs_mix_nsproxy returns with reference */
22609 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22610 +                       proxy, mask);
22611 +       }
22612 +       get_nsproxy(proxy);
22613 +       return proxy;
22614 +}
22615 +
22616 +
22617 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22618 +{
22619 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22620 +       struct fs_struct *fs_cur, *fs = NULL;
22621 +       struct _vx_space *space;
22622 +       int ret, kill = 0;
22623 +
22624 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22625 +               vxi, vxi->vx_id, mask, index);
22626 +
22627 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22628 +               return -EACCES;
22629 +
22630 +       if (index >= VX_SPACES)
22631 +               return -EINVAL;
22632 +
22633 +       space = &vxi->space[index];
22634 +
22635 +       if (!mask)
22636 +               mask = space->vx_nsmask;
22637 +
22638 +       if ((mask & space->vx_nsmask) != mask)
22639 +               return -EINVAL;
22640 +
22641 +       if (mask & CLONE_FS) {
22642 +               fs = copy_fs_struct(space->vx_fs);
22643 +               if (!fs)
22644 +                       return -ENOMEM;
22645 +       }
22646 +       proxy = space->vx_nsproxy;
22647 +
22648 +       vxdprintk(VXD_CBIT(space, 9),
22649 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22650 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22651 +
22652 +       task_lock(current);
22653 +       fs_cur = current->fs;
22654 +
22655 +       if (mask & CLONE_FS) {
22656 +               spin_lock(&fs_cur->lock);
22657 +               current->fs = fs;
22658 +               kill = !--fs_cur->users;
22659 +               spin_unlock(&fs_cur->lock);
22660 +       }
22661 +
22662 +       proxy_cur = current->nsproxy;
22663 +       get_nsproxy(proxy_cur);
22664 +       task_unlock(current);
22665 +
22666 +       if (kill)
22667 +               free_fs_struct(fs_cur);
22668 +
22669 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22670 +       if (IS_ERR(proxy_new)) {
22671 +               ret = PTR_ERR(proxy_new);
22672 +               goto out_put;
22673 +       }
22674 +
22675 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22676 +
22677 +       if (mask & CLONE_NEWUSER) {
22678 +               struct cred *cred;
22679 +
22680 +               vxdprintk(VXD_CBIT(space, 10),
22681 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22682 +                       vxi, vxi->vx_id, space->vx_cred,
22683 +                       current->real_cred, current->cred);
22684 +
22685 +               if (space->vx_cred) {
22686 +                       cred = __prepare_creds(space->vx_cred);
22687 +                       if (cred)
22688 +                               commit_creds(cred);
22689 +               }
22690 +       }
22691 +
22692 +       ret = 0;
22693 +
22694 +       if (proxy_new)
22695 +               put_nsproxy(proxy_new);
22696 +out_put:
22697 +       if (proxy_cur)
22698 +               put_nsproxy(proxy_cur);
22699 +       return ret;
22700 +}
22701 +
22702 +
22703 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22704 +{
22705 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22706 +       struct fs_struct *fs_vxi, *fs;
22707 +       struct _vx_space *space;
22708 +       int ret, kill = 0;
22709 +
22710 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22711 +               vxi, vxi->vx_id, mask, index);
22712 +
22713 +       if ((mask & space_mask.mask) != mask)
22714 +               return -EINVAL;
22715 +
22716 +       if (index >= VX_SPACES)
22717 +               return -EINVAL;
22718 +
22719 +       space = &vxi->space[index];
22720 +
22721 +       proxy_vxi = space->vx_nsproxy;
22722 +       fs_vxi = space->vx_fs;
22723 +
22724 +       if (mask & CLONE_FS) {
22725 +               fs = copy_fs_struct(current->fs);
22726 +               if (!fs)
22727 +                       return -ENOMEM;
22728 +       }
22729 +
22730 +       task_lock(current);
22731 +
22732 +       if (mask & CLONE_FS) {
22733 +               spin_lock(&fs_vxi->lock);
22734 +               space->vx_fs = fs;
22735 +               kill = !--fs_vxi->users;
22736 +               spin_unlock(&fs_vxi->lock);
22737 +       }
22738 +
22739 +       proxy_cur = current->nsproxy;
22740 +       get_nsproxy(proxy_cur);
22741 +       task_unlock(current);
22742 +
22743 +       if (kill)
22744 +               free_fs_struct(fs_vxi);
22745 +
22746 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22747 +       if (IS_ERR(proxy_new)) {
22748 +               ret = PTR_ERR(proxy_new);
22749 +               goto out_put;
22750 +       }
22751 +
22752 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22753 +       space->vx_nsmask |= mask;
22754 +
22755 +       if (mask & CLONE_NEWUSER) {
22756 +               struct cred *cred;
22757 +
22758 +               vxdprintk(VXD_CBIT(space, 10),
22759 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22760 +                       vxi, vxi->vx_id, space->vx_cred,
22761 +                       current->real_cred, current->cred);
22762 +
22763 +               cred = prepare_creds();
22764 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22765 +               if (cred)
22766 +                       abort_creds(cred);
22767 +       }
22768 +
22769 +       ret = 0;
22770 +
22771 +       if (proxy_new)
22772 +               put_nsproxy(proxy_new);
22773 +out_put:
22774 +       if (proxy_cur)
22775 +               put_nsproxy(proxy_cur);
22776 +       return ret;
22777 +}
22778 +
22779 +
22780 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22781 +{
22782 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22783 +
22784 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22785 +               return -EFAULT;
22786 +
22787 +       return vx_enter_space(vxi, vc_data.mask, 0);
22788 +}
22789 +
22790 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22791 +{
22792 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22793 +
22794 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22795 +               return -EFAULT;
22796 +
22797 +       if (vc_data.index >= VX_SPACES)
22798 +               return -EINVAL;
22799 +
22800 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22801 +}
22802 +
22803 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22804 +{
22805 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22806 +
22807 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22808 +               return -EFAULT;
22809 +
22810 +       return vx_set_space(vxi, vc_data.mask, 0);
22811 +}
22812 +
22813 +int vc_set_space(struct vx_info *vxi, void __user *data)
22814 +{
22815 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22816 +
22817 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22818 +               return -EFAULT;
22819 +
22820 +       if (vc_data.index >= VX_SPACES)
22821 +               return -EINVAL;
22822 +
22823 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22824 +}
22825 +
22826 +int vc_get_space_mask(void __user *data, int type)
22827 +{
22828 +       const struct vcmd_space_mask_v1 *mask;
22829 +
22830 +       if (type == 0)
22831 +               mask = &space_mask_v0;
22832 +       else if (type == 1)
22833 +               mask = &space_mask;
22834 +       else
22835 +               mask = &default_space_mask;
22836 +
22837 +       vxdprintk(VXD_CBIT(space, 10),
22838 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22839 +
22840 +       if (copy_to_user(data, mask, sizeof(*mask)))
22841 +               return -EFAULT;
22842 +       return 0;
22843 +}
22844 +
22845 diff -NurpP --minimal linux-3.5.4/kernel/vserver/switch.c linux-3.5.4-vs2.3.4.3/kernel/vserver/switch.c
22846 --- linux-3.5.4/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22847 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/switch.c       2012-07-23 01:45:55.000000000 +0200
22848 @@ -0,0 +1,556 @@
22849 +/*
22850 + *  linux/kernel/vserver/switch.c
22851 + *
22852 + *  Virtual Server: Syscall Switch
22853 + *
22854 + *  Copyright (C) 2003-2011  Herbert Pötzl
22855 + *
22856 + *  V0.01  syscall switch
22857 + *  V0.02  added signal to context
22858 + *  V0.03  added rlimit functions
22859 + *  V0.04  added iattr, task/xid functions
22860 + *  V0.05  added debug/history stuff
22861 + *  V0.06  added compat32 layer
22862 + *  V0.07  vcmd args and perms
22863 + *  V0.08  added status commands
22864 + *  V0.09  added tag commands
22865 + *  V0.10  added oom bias
22866 + *  V0.11  added device commands
22867 + *  V0.12  added warn mask
22868 + *
22869 + */
22870 +
22871 +#include <linux/vs_context.h>
22872 +#include <linux/vs_network.h>
22873 +#include <linux/vserver/switch.h>
22874 +
22875 +#include "vci_config.h"
22876 +
22877 +
22878 +static inline
22879 +int vc_get_version(uint32_t id)
22880 +{
22881 +       return VCI_VERSION;
22882 +}
22883 +
22884 +static inline
22885 +int vc_get_vci(uint32_t id)
22886 +{
22887 +       return vci_kernel_config();
22888 +}
22889 +
22890 +#include <linux/vserver/context_cmd.h>
22891 +#include <linux/vserver/cvirt_cmd.h>
22892 +#include <linux/vserver/cacct_cmd.h>
22893 +#include <linux/vserver/limit_cmd.h>
22894 +#include <linux/vserver/network_cmd.h>
22895 +#include <linux/vserver/sched_cmd.h>
22896 +#include <linux/vserver/debug_cmd.h>
22897 +#include <linux/vserver/inode_cmd.h>
22898 +#include <linux/vserver/dlimit_cmd.h>
22899 +#include <linux/vserver/signal_cmd.h>
22900 +#include <linux/vserver/space_cmd.h>
22901 +#include <linux/vserver/tag_cmd.h>
22902 +#include <linux/vserver/device_cmd.h>
22903 +
22904 +#include <linux/vserver/inode.h>
22905 +#include <linux/vserver/dlimit.h>
22906 +
22907 +
22908 +#ifdef CONFIG_COMPAT
22909 +#define __COMPAT(name, id, data, compat)       \
22910 +       (compat) ? name ## _x32(id, data) : name(id, data)
22911 +#define __COMPAT_NO_ID(name, data, compat)     \
22912 +       (compat) ? name ## _x32(data) : name(data)
22913 +#else
22914 +#define __COMPAT(name, id, data, compat)       \
22915 +       name(id, data)
22916 +#define __COMPAT_NO_ID(name, data, compat)     \
22917 +       name(data)
22918 +#endif
22919 +
22920 +
22921 +static inline
22922 +long do_vcmd(uint32_t cmd, uint32_t id,
22923 +       struct vx_info *vxi, struct nx_info *nxi,
22924 +       void __user *data, int compat)
22925 +{
22926 +       switch (cmd) {
22927 +
22928 +       case VCMD_get_version:
22929 +               return vc_get_version(id);
22930 +       case VCMD_get_vci:
22931 +               return vc_get_vci(id);
22932 +
22933 +       case VCMD_task_xid:
22934 +               return vc_task_xid(id);
22935 +       case VCMD_vx_info:
22936 +               return vc_vx_info(vxi, data);
22937 +
22938 +       case VCMD_task_nid:
22939 +               return vc_task_nid(id);
22940 +       case VCMD_nx_info:
22941 +               return vc_nx_info(nxi, data);
22942 +
22943 +       case VCMD_task_tag:
22944 +               return vc_task_tag(id);
22945 +
22946 +       case VCMD_set_space_v1:
22947 +               return vc_set_space_v1(vxi, data);
22948 +       /* this is version 2 */
22949 +       case VCMD_set_space:
22950 +               return vc_set_space(vxi, data);
22951 +
22952 +       case VCMD_get_space_mask_v0:
22953 +               return vc_get_space_mask(data, 0);
22954 +       /* this is version 1 */
22955 +       case VCMD_get_space_mask:
22956 +               return vc_get_space_mask(data, 1);
22957 +
22958 +       case VCMD_get_space_default:
22959 +               return vc_get_space_mask(data, -1);
22960 +
22961 +       case VCMD_set_umask:
22962 +               return vc_set_umask(vxi, data);
22963 +
22964 +       case VCMD_get_umask:
22965 +               return vc_get_umask(vxi, data);
22966 +
22967 +       case VCMD_set_wmask:
22968 +               return vc_set_wmask(vxi, data);
22969 +
22970 +       case VCMD_get_wmask:
22971 +               return vc_get_wmask(vxi, data);
22972 +#ifdef CONFIG_IA32_EMULATION
22973 +       case VCMD_get_rlimit:
22974 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22975 +       case VCMD_set_rlimit:
22976 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22977 +#else
22978 +       case VCMD_get_rlimit:
22979 +               return vc_get_rlimit(vxi, data);
22980 +       case VCMD_set_rlimit:
22981 +               return vc_set_rlimit(vxi, data);
22982 +#endif
22983 +       case VCMD_get_rlimit_mask:
22984 +               return vc_get_rlimit_mask(id, data);
22985 +       case VCMD_reset_hits:
22986 +               return vc_reset_hits(vxi, data);
22987 +       case VCMD_reset_minmax:
22988 +               return vc_reset_minmax(vxi, data);
22989 +
22990 +       case VCMD_get_vhi_name:
22991 +               return vc_get_vhi_name(vxi, data);
22992 +       case VCMD_set_vhi_name:
22993 +               return vc_set_vhi_name(vxi, data);
22994 +
22995 +       case VCMD_ctx_stat:
22996 +               return vc_ctx_stat(vxi, data);
22997 +       case VCMD_virt_stat:
22998 +               return vc_virt_stat(vxi, data);
22999 +       case VCMD_sock_stat:
23000 +               return vc_sock_stat(vxi, data);
23001 +       case VCMD_rlimit_stat:
23002 +               return vc_rlimit_stat(vxi, data);
23003 +
23004 +       case VCMD_set_cflags:
23005 +               return vc_set_cflags(vxi, data);
23006 +       case VCMD_get_cflags:
23007 +               return vc_get_cflags(vxi, data);
23008 +
23009 +       /* this is version 1 */
23010 +       case VCMD_set_ccaps:
23011 +               return vc_set_ccaps(vxi, data);
23012 +       /* this is version 1 */
23013 +       case VCMD_get_ccaps:
23014 +               return vc_get_ccaps(vxi, data);
23015 +       case VCMD_set_bcaps:
23016 +               return vc_set_bcaps(vxi, data);
23017 +       case VCMD_get_bcaps:
23018 +               return vc_get_bcaps(vxi, data);
23019 +
23020 +       case VCMD_set_badness:
23021 +               return vc_set_badness(vxi, data);
23022 +       case VCMD_get_badness:
23023 +               return vc_get_badness(vxi, data);
23024 +
23025 +       case VCMD_set_nflags:
23026 +               return vc_set_nflags(nxi, data);
23027 +       case VCMD_get_nflags:
23028 +               return vc_get_nflags(nxi, data);
23029 +
23030 +       case VCMD_set_ncaps:
23031 +               return vc_set_ncaps(nxi, data);
23032 +       case VCMD_get_ncaps:
23033 +               return vc_get_ncaps(nxi, data);
23034 +
23035 +       case VCMD_set_prio_bias:
23036 +               return vc_set_prio_bias(vxi, data);
23037 +       case VCMD_get_prio_bias:
23038 +               return vc_get_prio_bias(vxi, data);
23039 +       case VCMD_add_dlimit:
23040 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23041 +       case VCMD_rem_dlimit:
23042 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23043 +       case VCMD_set_dlimit:
23044 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23045 +       case VCMD_get_dlimit:
23046 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23047 +
23048 +       case VCMD_ctx_kill:
23049 +               return vc_ctx_kill(vxi, data);
23050 +
23051 +       case VCMD_wait_exit:
23052 +               return vc_wait_exit(vxi, data);
23053 +
23054 +       case VCMD_get_iattr:
23055 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23056 +       case VCMD_set_iattr:
23057 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23058 +
23059 +       case VCMD_fget_iattr:
23060 +               return vc_fget_iattr(id, data);
23061 +       case VCMD_fset_iattr:
23062 +               return vc_fset_iattr(id, data);
23063 +
23064 +       case VCMD_enter_space_v0:
23065 +               return vc_enter_space_v1(vxi, NULL);
23066 +       case VCMD_enter_space_v1:
23067 +               return vc_enter_space_v1(vxi, data);
23068 +       /* this is version 2 */
23069 +       case VCMD_enter_space:
23070 +               return vc_enter_space(vxi, data);
23071 +
23072 +       case VCMD_ctx_create_v0:
23073 +               return vc_ctx_create(id, NULL);
23074 +       case VCMD_ctx_create:
23075 +               return vc_ctx_create(id, data);
23076 +       case VCMD_ctx_migrate_v0:
23077 +               return vc_ctx_migrate(vxi, NULL);
23078 +       case VCMD_ctx_migrate:
23079 +               return vc_ctx_migrate(vxi, data);
23080 +
23081 +       case VCMD_net_create_v0:
23082 +               return vc_net_create(id, NULL);
23083 +       case VCMD_net_create:
23084 +               return vc_net_create(id, data);
23085 +       case VCMD_net_migrate:
23086 +               return vc_net_migrate(nxi, data);
23087 +
23088 +       case VCMD_tag_migrate:
23089 +               return vc_tag_migrate(id);
23090 +
23091 +       case VCMD_net_add:
23092 +               return vc_net_add(nxi, data);
23093 +       case VCMD_net_remove:
23094 +               return vc_net_remove(nxi, data);
23095 +
23096 +       case VCMD_net_add_ipv4_v1:
23097 +               return vc_net_add_ipv4_v1(nxi, data);
23098 +       /* this is version 2 */
23099 +       case VCMD_net_add_ipv4:
23100 +               return vc_net_add_ipv4(nxi, data);
23101 +
23102 +       case VCMD_net_rem_ipv4_v1:
23103 +               return vc_net_rem_ipv4_v1(nxi, data);
23104 +       /* this is version 2 */
23105 +       case VCMD_net_rem_ipv4:
23106 +               return vc_net_rem_ipv4(nxi, data);
23107 +#ifdef CONFIG_IPV6
23108 +       case VCMD_net_add_ipv6:
23109 +               return vc_net_add_ipv6(nxi, data);
23110 +       case VCMD_net_remove_ipv6:
23111 +               return vc_net_remove_ipv6(nxi, data);
23112 +#endif
23113 +/*     case VCMD_add_match_ipv4:
23114 +               return vc_add_match_ipv4(nxi, data);
23115 +       case VCMD_get_match_ipv4:
23116 +               return vc_get_match_ipv4(nxi, data);
23117 +#ifdef CONFIG_IPV6
23118 +       case VCMD_add_match_ipv6:
23119 +               return vc_add_match_ipv6(nxi, data);
23120 +       case VCMD_get_match_ipv6:
23121 +               return vc_get_match_ipv6(nxi, data);
23122 +#endif */
23123 +
23124 +#ifdef CONFIG_VSERVER_DEVICE
23125 +       case VCMD_set_mapping:
23126 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23127 +       case VCMD_unset_mapping:
23128 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23129 +#endif
23130 +#ifdef CONFIG_VSERVER_HISTORY
23131 +       case VCMD_dump_history:
23132 +               return vc_dump_history(id);
23133 +       case VCMD_read_history:
23134 +               return __COMPAT(vc_read_history, id, data, compat);
23135 +#endif
23136 +       default:
23137 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23138 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23139 +       }
23140 +       return -ENOSYS;
23141 +}
23142 +
23143 +
23144 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23145 +       case VCMD_ ## vcmd: perm = _perm;               \
23146 +               args = _args; flags = _flags; break
23147 +
23148 +
23149 +#define VCA_NONE       0x00
23150 +#define VCA_VXI                0x01
23151 +#define VCA_NXI                0x02
23152 +
23153 +#define VCF_NONE       0x00
23154 +#define VCF_INFO       0x01
23155 +#define VCF_ADMIN      0x02
23156 +#define VCF_ARES       0x06    /* includes admin */
23157 +#define VCF_SETUP      0x08
23158 +
23159 +#define VCF_ZIDOK      0x10    /* zero id okay */
23160 +
23161 +
23162 +static inline
23163 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23164 +{
23165 +       long ret;
23166 +       int permit = -1, state = 0;
23167 +       int perm = -1, args = 0, flags = 0;
23168 +       struct vx_info *vxi = NULL;
23169 +       struct nx_info *nxi = NULL;
23170 +
23171 +       switch (cmd) {
23172 +       /* unpriviledged commands */
23173 +       __VCMD(get_version,      0, VCA_NONE,   0);
23174 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23175 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23176 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23177 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23178 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23179 +
23180 +       /* info commands */
23181 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23182 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23183 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23184 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23185 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23186 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23187 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23188 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23189 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23190 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23191 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23192 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23193 +
23194 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23195 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23196 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23197 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23198 +
23199 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23200 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23201 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23202 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23203 +
23204 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23205 +
23206 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23207 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23208 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23209 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23210 +
23211 +       /* lower admin commands */
23212 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23213 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23214 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23215 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23216 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23217 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23218 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23219 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23220 +
23221 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23222 +       __VCMD(net_create,       5, VCA_NONE,   0);
23223 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23224 +
23225 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23226 +
23227 +       /* higher admin commands */
23228 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23229 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23230 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23231 +
23232 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23233 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23234 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23235 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23236 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23237 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23238 +
23239 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23240 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23241 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23242 +
23243 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23244 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23245 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23246 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23247 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23248 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23249 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23250 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23251 +#ifdef CONFIG_IPV6
23252 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23253 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23254 +#endif
23255 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23256 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23257 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23258 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23259 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23260 +
23261 +#ifdef CONFIG_VSERVER_DEVICE
23262 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23263 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23264 +#endif
23265 +       /* debug level admin commands */
23266 +#ifdef CONFIG_VSERVER_HISTORY
23267 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23268 +       __VCMD(read_history,     9, VCA_NONE,   0);
23269 +#endif
23270 +
23271 +       default:
23272 +               perm = -1;
23273 +       }
23274 +
23275 +       vxdprintk(VXD_CBIT(switch, 0),
23276 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23277 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23278 +               VC_VERSION(cmd), id, data, compat,
23279 +               perm, args, flags);
23280 +
23281 +       ret = -ENOSYS;
23282 +       if (perm < 0)
23283 +               goto out;
23284 +
23285 +       state = 1;
23286 +       if (!capable(CAP_CONTEXT))
23287 +               goto out;
23288 +
23289 +       state = 2;
23290 +       /* moved here from the individual commands */
23291 +       ret = -EPERM;
23292 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23293 +               goto out;
23294 +
23295 +       state = 3;
23296 +       /* vcmd involves resource management  */
23297 +       ret = -EPERM;
23298 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23299 +               goto out;
23300 +
23301 +       state = 4;
23302 +       /* various legacy exceptions */
23303 +       switch (cmd) {
23304 +       /* will go away when spectator is a cap */
23305 +       case VCMD_ctx_migrate_v0:
23306 +       case VCMD_ctx_migrate:
23307 +               if (id == 1) {
23308 +                       current->xid = 1;
23309 +                       ret = 1;
23310 +                       goto out;
23311 +               }
23312 +               break;
23313 +
23314 +       /* will go away when spectator is a cap */
23315 +       case VCMD_net_migrate:
23316 +               if (id == 1) {
23317 +                       current->nid = 1;
23318 +                       ret = 1;
23319 +                       goto out;
23320 +               }
23321 +               break;
23322 +       }
23323 +
23324 +       /* vcmds are fine by default */
23325 +       permit = 1;
23326 +
23327 +       /* admin type vcmds require admin ... */
23328 +       if (flags & VCF_ADMIN)
23329 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23330 +
23331 +       /* ... but setup type vcmds override that */
23332 +       if (!permit && (flags & VCF_SETUP))
23333 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23334 +
23335 +       state = 5;
23336 +       ret = -EPERM;
23337 +       if (!permit)
23338 +               goto out;
23339 +
23340 +       state = 6;
23341 +       if (!id && (flags & VCF_ZIDOK))
23342 +               goto skip_id;
23343 +
23344 +       ret = -ESRCH;
23345 +       if (args & VCA_VXI) {
23346 +               vxi = lookup_vx_info(id);
23347 +               if (!vxi)
23348 +                       goto out;
23349 +
23350 +               if ((flags & VCF_ADMIN) &&
23351 +                       /* special case kill for shutdown */
23352 +                       (cmd != VCMD_ctx_kill) &&
23353 +                       /* can context be administrated? */
23354 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23355 +                       ret = -EACCES;
23356 +                       goto out_vxi;
23357 +               }
23358 +       }
23359 +       state = 7;
23360 +       if (args & VCA_NXI) {
23361 +               nxi = lookup_nx_info(id);
23362 +               if (!nxi)
23363 +                       goto out_vxi;
23364 +
23365 +               if ((flags & VCF_ADMIN) &&
23366 +                       /* can context be administrated? */
23367 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23368 +                       ret = -EACCES;
23369 +                       goto out_nxi;
23370 +               }
23371 +       }
23372 +skip_id:
23373 +       state = 8;
23374 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23375 +
23376 +out_nxi:
23377 +       if ((args & VCA_NXI) && nxi)
23378 +               put_nx_info(nxi);
23379 +out_vxi:
23380 +       if ((args & VCA_VXI) && vxi)
23381 +               put_vx_info(vxi);
23382 +out:
23383 +       vxdprintk(VXD_CBIT(switch, 1),
23384 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23385 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23386 +               VC_VERSION(cmd), ret, ret, state, permit);
23387 +       return ret;
23388 +}
23389 +
23390 +asmlinkage long
23391 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23392 +{
23393 +       return do_vserver(cmd, id, data, 0);
23394 +}
23395 +
23396 +#ifdef CONFIG_COMPAT
23397 +
23398 +asmlinkage long
23399 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23400 +{
23401 +       return do_vserver(cmd, id, data, 1);
23402 +}
23403 +
23404 +#endif /* CONFIG_COMPAT */
23405 diff -NurpP --minimal linux-3.5.4/kernel/vserver/sysctl.c linux-3.5.4-vs2.3.4.3/kernel/vserver/sysctl.c
23406 --- linux-3.5.4/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23407 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/sysctl.c       2012-07-23 01:45:55.000000000 +0200
23408 @@ -0,0 +1,247 @@
23409 +/*
23410 + *  kernel/vserver/sysctl.c
23411 + *
23412 + *  Virtual Context Support
23413 + *
23414 + *  Copyright (C) 2004-2007  Herbert Pötzl
23415 + *
23416 + *  V0.01  basic structure
23417 + *
23418 + */
23419 +
23420 +#include <linux/module.h>
23421 +#include <linux/ctype.h>
23422 +#include <linux/sysctl.h>
23423 +#include <linux/parser.h>
23424 +#include <asm/uaccess.h>
23425 +
23426 +enum {
23427 +       CTL_DEBUG_ERROR         = 0,
23428 +       CTL_DEBUG_SWITCH        = 1,
23429 +       CTL_DEBUG_XID,
23430 +       CTL_DEBUG_NID,
23431 +       CTL_DEBUG_TAG,
23432 +       CTL_DEBUG_NET,
23433 +       CTL_DEBUG_LIMIT,
23434 +       CTL_DEBUG_CRES,
23435 +       CTL_DEBUG_DLIM,
23436 +       CTL_DEBUG_QUOTA,
23437 +       CTL_DEBUG_CVIRT,
23438 +       CTL_DEBUG_SPACE,
23439 +       CTL_DEBUG_PERM,
23440 +       CTL_DEBUG_MISC,
23441 +};
23442 +
23443 +
23444 +unsigned int vs_debug_switch   = 0;
23445 +unsigned int vs_debug_xid      = 0;
23446 +unsigned int vs_debug_nid      = 0;
23447 +unsigned int vs_debug_tag      = 0;
23448 +unsigned int vs_debug_net      = 0;
23449 +unsigned int vs_debug_limit    = 0;
23450 +unsigned int vs_debug_cres     = 0;
23451 +unsigned int vs_debug_dlim     = 0;
23452 +unsigned int vs_debug_quota    = 0;
23453 +unsigned int vs_debug_cvirt    = 0;
23454 +unsigned int vs_debug_space    = 0;
23455 +unsigned int vs_debug_perm     = 0;
23456 +unsigned int vs_debug_misc     = 0;
23457 +
23458 +
23459 +static struct ctl_table_header *vserver_table_header;
23460 +static ctl_table vserver_root_table[];
23461 +
23462 +
23463 +void vserver_register_sysctl(void)
23464 +{
23465 +       if (!vserver_table_header) {
23466 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23467 +       }
23468 +
23469 +}
23470 +
23471 +void vserver_unregister_sysctl(void)
23472 +{
23473 +       if (vserver_table_header) {
23474 +               unregister_sysctl_table(vserver_table_header);
23475 +               vserver_table_header = NULL;
23476 +       }
23477 +}
23478 +
23479 +
23480 +static int proc_dodebug(ctl_table *table, int write,
23481 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23482 +{
23483 +       char            tmpbuf[20], *p, c;
23484 +       unsigned int    value;
23485 +       size_t          left, len;
23486 +
23487 +       if ((*ppos && !write) || !*lenp) {
23488 +               *lenp = 0;
23489 +               return 0;
23490 +       }
23491 +
23492 +       left = *lenp;
23493 +
23494 +       if (write) {
23495 +               if (!access_ok(VERIFY_READ, buffer, left))
23496 +                       return -EFAULT;
23497 +               p = (char *)buffer;
23498 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23499 +                       left--, p++;
23500 +               if (!left)
23501 +                       goto done;
23502 +
23503 +               if (left > sizeof(tmpbuf) - 1)
23504 +                       return -EINVAL;
23505 +               if (copy_from_user(tmpbuf, p, left))
23506 +                       return -EFAULT;
23507 +               tmpbuf[left] = '\0';
23508 +
23509 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23510 +                       value = 10 * value + (*p - '0');
23511 +               if (*p && !isspace(*p))
23512 +                       return -EINVAL;
23513 +               while (left && isspace(*p))
23514 +                       left--, p++;
23515 +               *(unsigned int *)table->data = value;
23516 +       } else {
23517 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23518 +                       return -EFAULT;
23519 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23520 +               if (len > left)
23521 +                       len = left;
23522 +               if (__copy_to_user(buffer, tmpbuf, len))
23523 +                       return -EFAULT;
23524 +               if ((left -= len) > 0) {
23525 +                       if (put_user('\n', (char *)buffer + len))
23526 +                               return -EFAULT;
23527 +                       left--;
23528 +               }
23529 +       }
23530 +
23531 +done:
23532 +       *lenp -= left;
23533 +       *ppos += *lenp;
23534 +       return 0;
23535 +}
23536 +
23537 +static int zero;
23538 +
23539 +#define        CTL_ENTRY(ctl, name)                            \
23540 +       {                                               \
23541 +               .procname       = #name,                \
23542 +               .data           = &vs_ ## name,         \
23543 +               .maxlen         = sizeof(int),          \
23544 +               .mode           = 0644,                 \
23545 +               .proc_handler   = &proc_dodebug,        \
23546 +               .extra1         = &zero,                \
23547 +               .extra2         = &zero,                \
23548 +       }
23549 +
23550 +static ctl_table vserver_debug_table[] = {
23551 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23552 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23553 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23554 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23555 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23556 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23557 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23558 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23559 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23560 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23561 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23562 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23563 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23564 +       { 0 }
23565 +};
23566 +
23567 +static ctl_table vserver_root_table[] = {
23568 +       {
23569 +               .procname       = "vserver",
23570 +               .mode           = 0555,
23571 +               .child          = vserver_debug_table
23572 +       },
23573 +       { 0 }
23574 +};
23575 +
23576 +
23577 +static match_table_t tokens = {
23578 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23579 +       { CTL_DEBUG_XID,        "xid=%x"        },
23580 +       { CTL_DEBUG_NID,        "nid=%x"        },
23581 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23582 +       { CTL_DEBUG_NET,        "net=%x"        },
23583 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23584 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23585 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23586 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23587 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23588 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23589 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23590 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23591 +       { CTL_DEBUG_ERROR,      NULL            }
23592 +};
23593 +
23594 +#define        HANDLE_CASE(id, name, val)                              \
23595 +       case CTL_DEBUG_ ## id:                                  \
23596 +               vs_debug_ ## name = val;                        \
23597 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23598 +               break
23599 +
23600 +
23601 +static int __init vs_debug_setup(char *str)
23602 +{
23603 +       char *p;
23604 +       int token;
23605 +
23606 +       printk("vs_debug_setup(%s)\n", str);
23607 +       while ((p = strsep(&str, ",")) != NULL) {
23608 +               substring_t args[MAX_OPT_ARGS];
23609 +               unsigned int value;
23610 +
23611 +               if (!*p)
23612 +                       continue;
23613 +
23614 +               token = match_token(p, tokens, args);
23615 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23616 +
23617 +               switch (token) {
23618 +               HANDLE_CASE(SWITCH, switch, value);
23619 +               HANDLE_CASE(XID,    xid,    value);
23620 +               HANDLE_CASE(NID,    nid,    value);
23621 +               HANDLE_CASE(TAG,    tag,    value);
23622 +               HANDLE_CASE(NET,    net,    value);
23623 +               HANDLE_CASE(LIMIT,  limit,  value);
23624 +               HANDLE_CASE(CRES,   cres,   value);
23625 +               HANDLE_CASE(DLIM,   dlim,   value);
23626 +               HANDLE_CASE(QUOTA,  quota,  value);
23627 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23628 +               HANDLE_CASE(SPACE,  space,  value);
23629 +               HANDLE_CASE(PERM,   perm,   value);
23630 +               HANDLE_CASE(MISC,   misc,   value);
23631 +               default:
23632 +                       return -EINVAL;
23633 +                       break;
23634 +               }
23635 +       }
23636 +       return 1;
23637 +}
23638 +
23639 +__setup("vsdebug=", vs_debug_setup);
23640 +
23641 +
23642 +
23643 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23644 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23645 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23646 +EXPORT_SYMBOL_GPL(vs_debug_net);
23647 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23648 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23649 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23650 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23651 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23652 +EXPORT_SYMBOL_GPL(vs_debug_space);
23653 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23654 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23655 +
23656 diff -NurpP --minimal linux-3.5.4/kernel/vserver/tag.c linux-3.5.4-vs2.3.4.3/kernel/vserver/tag.c
23657 --- linux-3.5.4/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23658 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/tag.c  2012-07-23 01:45:55.000000000 +0200
23659 @@ -0,0 +1,63 @@
23660 +/*
23661 + *  linux/kernel/vserver/tag.c
23662 + *
23663 + *  Virtual Server: Shallow Tag Space
23664 + *
23665 + *  Copyright (C) 2007  Herbert Pötzl
23666 + *
23667 + *  V0.01  basic implementation
23668 + *
23669 + */
23670 +
23671 +#include <linux/sched.h>
23672 +#include <linux/vserver/debug.h>
23673 +#include <linux/vs_pid.h>
23674 +#include <linux/vs_tag.h>
23675 +
23676 +#include <linux/vserver/tag_cmd.h>
23677 +
23678 +
23679 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23680 +{
23681 +       if (!p)
23682 +               BUG();
23683 +
23684 +       vxdprintk(VXD_CBIT(tag, 5),
23685 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23686 +
23687 +       task_lock(p);
23688 +       p->tag = tag;
23689 +       task_unlock(p);
23690 +
23691 +       vxdprintk(VXD_CBIT(tag, 5),
23692 +               "moved task %p into [#%d]", p, tag);
23693 +       return 0;
23694 +}
23695 +
23696 +/* vserver syscall commands below here */
23697 +
23698 +/* taks xid and vx_info functions */
23699 +
23700 +
23701 +int vc_task_tag(uint32_t id)
23702 +{
23703 +       tag_t tag;
23704 +
23705 +       if (id) {
23706 +               struct task_struct *tsk;
23707 +               rcu_read_lock();
23708 +               tsk = find_task_by_real_pid(id);
23709 +               tag = (tsk) ? tsk->tag : -ESRCH;
23710 +               rcu_read_unlock();
23711 +       } else
23712 +               tag = dx_current_tag();
23713 +       return tag;
23714 +}
23715 +
23716 +
23717 +int vc_tag_migrate(uint32_t tag)
23718 +{
23719 +       return dx_migrate_task(current, tag & 0xFFFF);
23720 +}
23721 +
23722 +
23723 diff -NurpP --minimal linux-3.5.4/kernel/vserver/vci_config.h linux-3.5.4-vs2.3.4.3/kernel/vserver/vci_config.h
23724 --- linux-3.5.4/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
23725 +++ linux-3.5.4-vs2.3.4.3/kernel/vserver/vci_config.h   2012-07-23 01:45:55.000000000 +0200
23726 @@ -0,0 +1,76 @@
23727 +
23728 +/*  interface version */
23729 +
23730 +#define VCI_VERSION            0x00020308
23731 +
23732 +
23733 +enum {
23734 +       VCI_KCBIT_NO_DYNAMIC = 0,
23735 +
23736 +       VCI_KCBIT_PROC_SECURE = 4,
23737 +       /* VCI_KCBIT_HARDCPU = 5, */
23738 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23739 +       /* VCI_KCBIT_IDLETIME = 7, */
23740 +
23741 +       VCI_KCBIT_COWBL = 8,
23742 +       VCI_KCBIT_FULLCOWBL = 9,
23743 +       VCI_KCBIT_SPACES = 10,
23744 +       VCI_KCBIT_NETV2 = 11,
23745 +       VCI_KCBIT_MEMCG = 12,
23746 +
23747 +       VCI_KCBIT_DEBUG = 16,
23748 +       VCI_KCBIT_HISTORY = 20,
23749 +       VCI_KCBIT_TAGGED = 24,
23750 +       VCI_KCBIT_PPTAG = 28,
23751 +
23752 +       VCI_KCBIT_MORE = 31,
23753 +};
23754 +
23755 +
23756 +static inline uint32_t vci_kernel_config(void)
23757 +{
23758 +       return
23759 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23760 +
23761 +       /* configured features */
23762 +#ifdef CONFIG_VSERVER_PROC_SECURE
23763 +       (1 << VCI_KCBIT_PROC_SECURE) |
23764 +#endif
23765 +#ifdef CONFIG_VSERVER_COWBL
23766 +       (1 << VCI_KCBIT_COWBL) |
23767 +       (1 << VCI_KCBIT_FULLCOWBL) |
23768 +#endif
23769 +       (1 << VCI_KCBIT_SPACES) |
23770 +       (1 << VCI_KCBIT_NETV2) |
23771 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23772 +       (1 << VCI_KCBIT_MEMCG) |
23773 +#endif
23774 +
23775 +       /* debug options */
23776 +#ifdef CONFIG_VSERVER_DEBUG
23777 +       (1 << VCI_KCBIT_DEBUG) |
23778 +#endif
23779 +#ifdef CONFIG_VSERVER_HISTORY
23780 +       (1 << VCI_KCBIT_HISTORY) |
23781 +#endif
23782 +
23783 +       /* inode context tagging */
23784 +#if    defined(CONFIG_TAGGING_NONE)
23785 +       (0 << VCI_KCBIT_TAGGED) |
23786 +#elif  defined(CONFIG_TAGGING_UID16)
23787 +       (1 << VCI_KCBIT_TAGGED) |
23788 +#elif  defined(CONFIG_TAGGING_GID16)
23789 +       (2 << VCI_KCBIT_TAGGED) |
23790 +#elif  defined(CONFIG_TAGGING_ID24)
23791 +       (3 << VCI_KCBIT_TAGGED) |
23792 +#elif  defined(CONFIG_TAGGING_INTERN)
23793 +       (4 << VCI_KCBIT_TAGGED) |
23794 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23795 +       (5 << VCI_KCBIT_TAGGED) |
23796 +#else
23797 +       (7 << VCI_KCBIT_TAGGED) |
23798 +#endif
23799 +       (1 << VCI_KCBIT_PPTAG) |
23800 +       0;
23801 +}
23802 +
23803 diff -NurpP --minimal linux-3.5.4/mm/memcontrol.c linux-3.5.4-vs2.3.4.3/mm/memcontrol.c
23804 --- linux-3.5.4/mm/memcontrol.c 2012-07-22 23:39:47.000000000 +0200
23805 +++ linux-3.5.4-vs2.3.4.3/mm/memcontrol.c       2012-07-23 01:45:55.000000000 +0200
23806 @@ -883,6 +883,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23807                                 struct mem_cgroup, css);
23808  }
23809  
23810 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23811 +{
23812 +       return res_counter_read_u64(&mem->res, member);
23813 +}
23814 +
23815 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23816 +{
23817 +       return res_counter_read_u64(&mem->memsw, member);
23818 +}
23819 +
23820 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23821 +{
23822 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23823 +}
23824 +
23825 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23826 +{
23827 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23828 +}
23829 +
23830 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23831 +{
23832 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23833 +}
23834 +
23835  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23836  {
23837         struct mem_cgroup *memcg = NULL;
23838 diff -NurpP --minimal linux-3.5.4/mm/oom_kill.c linux-3.5.4-vs2.3.4.3/mm/oom_kill.c
23839 --- linux-3.5.4/mm/oom_kill.c   2012-07-22 23:39:47.000000000 +0200
23840 +++ linux-3.5.4-vs2.3.4.3/mm/oom_kill.c 2012-07-23 01:45:55.000000000 +0200
23841 @@ -35,6 +35,8 @@
23842  #include <linux/freezer.h>
23843  #include <linux/ftrace.h>
23844  #include <linux/ratelimit.h>
23845 +#include <linux/reboot.h>
23846 +#include <linux/vs_context.h>
23847  
23848  #define CREATE_TRACE_POINTS
23849  #include <trace/events/oom.h>
23850 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23851  static bool oom_unkillable_task(struct task_struct *p,
23852                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23853  {
23854 -       if (is_global_init(p))
23855 +       unsigned xid = vx_current_xid();
23856 +
23857 +       /* skip the init task, global and per guest */
23858 +       if (task_is_init(p))
23859                 return true;
23860         if (p->flags & PF_KTHREAD)
23861                 return true;
23862  
23863 +       /* skip other guest and host processes if oom in guest */
23864 +       if (xid && vx_task_xid(p) != xid)
23865 +               return true;
23866 +
23867         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23868         if (memcg && !task_in_mem_cgroup(p, memcg))
23869                 return true;
23870 @@ -449,8 +458,8 @@ static void oom_kill_process(struct task
23871                 dump_header(p, gfp_mask, order, memcg, nodemask);
23872  
23873         task_lock(p);
23874 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23875 -               message, task_pid_nr(p), p->comm, points);
23876 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23877 +               message, task_pid_nr(p), p->xid, p->comm, points);
23878         task_unlock(p);
23879  
23880         /*
23881 @@ -483,8 +492,8 @@ static void oom_kill_process(struct task
23882  
23883         /* mm cannot safely be dereferenced after task_unlock(victim) */
23884         mm = victim->mm;
23885 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23886 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23887 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23888 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23889                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23890                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23891         task_unlock(victim);
23892 @@ -583,6 +592,8 @@ int unregister_oom_notifier(struct notif
23893  }
23894  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23895  
23896 +long vs_oom_action(unsigned int);
23897 +
23898  /*
23899   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23900   * if a parallel OOM killing is already taking place that includes a zone in
23901 @@ -734,7 +745,12 @@ void out_of_memory(struct zonelist *zone
23902         if (!p) {
23903                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23904                 read_unlock(&tasklist_lock);
23905 -               panic("Out of memory and no killable processes...\n");
23906 +
23907 +               /* avoid panic for guest OOM */
23908 +               if (current->xid)
23909 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23910 +               else
23911 +                       panic("Out of memory and no killable processes...\n");
23912         }
23913         if (PTR_ERR(p) != -1UL) {
23914                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23915 diff -NurpP --minimal linux-3.5.4/mm/page_alloc.c linux-3.5.4-vs2.3.4.3/mm/page_alloc.c
23916 --- linux-3.5.4/mm/page_alloc.c 2012-09-16 20:46:31.000000000 +0200
23917 +++ linux-3.5.4-vs2.3.4.3/mm/page_alloc.c       2012-08-19 13:28:27.000000000 +0200
23918 @@ -59,6 +59,8 @@
23919  #include <linux/prefetch.h>
23920  #include <linux/migrate.h>
23921  #include <linux/page-debug-flags.h>
23922 +#include <linux/vs_base.h>
23923 +#include <linux/vs_limit.h>
23924  
23925  #include <asm/tlbflush.h>
23926  #include <asm/div64.h>
23927 @@ -2711,6 +2713,9 @@ void si_meminfo(struct sysinfo *val)
23928         val->totalhigh = totalhigh_pages;
23929         val->freehigh = nr_free_highpages();
23930         val->mem_unit = PAGE_SIZE;
23931 +
23932 +       if (vx_flags(VXF_VIRT_MEM, 0))
23933 +               vx_vsi_meminfo(val);
23934  }
23935  
23936  EXPORT_SYMBOL(si_meminfo);
23937 @@ -2731,6 +2736,9 @@ void si_meminfo_node(struct sysinfo *val
23938         val->freehigh = 0;
23939  #endif
23940         val->mem_unit = PAGE_SIZE;
23941 +
23942 +       if (vx_flags(VXF_VIRT_MEM, 0))
23943 +               vx_vsi_meminfo(val);
23944  }
23945  #endif
23946  
23947 diff -NurpP --minimal linux-3.5.4/mm/pgtable-generic.c linux-3.5.4-vs2.3.4.3/mm/pgtable-generic.c
23948 --- linux-3.5.4/mm/pgtable-generic.c    2012-07-22 23:39:47.000000000 +0200
23949 +++ linux-3.5.4-vs2.3.4.3/mm/pgtable-generic.c  2012-07-23 01:45:55.000000000 +0200
23950 @@ -6,6 +6,8 @@
23951   *  Copyright (C) 2010  Linus Torvalds
23952   */
23953  
23954 +#include <linux/mm.h>
23955 +
23956  #include <linux/pagemap.h>
23957  #include <asm/tlb.h>
23958  #include <asm-generic/pgtable.h>
23959 diff -NurpP --minimal linux-3.5.4/mm/shmem.c linux-3.5.4-vs2.3.4.3/mm/shmem.c
23960 --- linux-3.5.4/mm/shmem.c      2012-07-22 23:39:47.000000000 +0200
23961 +++ linux-3.5.4-vs2.3.4.3/mm/shmem.c    2012-07-23 01:45:55.000000000 +0200
23962 @@ -1812,7 +1812,7 @@ static int shmem_statfs(struct dentry *d
23963  {
23964         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23965  
23966 -       buf->f_type = TMPFS_MAGIC;
23967 +       buf->f_type = TMPFS_SUPER_MAGIC;
23968         buf->f_bsize = PAGE_CACHE_SIZE;
23969         buf->f_namelen = NAME_MAX;
23970         if (sbinfo->max_blocks) {
23971 @@ -2628,7 +2628,7 @@ int shmem_fill_super(struct super_block 
23972         sb->s_maxbytes = MAX_LFS_FILESIZE;
23973         sb->s_blocksize = PAGE_CACHE_SIZE;
23974         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23975 -       sb->s_magic = TMPFS_MAGIC;
23976 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23977         sb->s_op = &shmem_ops;
23978         sb->s_time_gran = 1;
23979  #ifdef CONFIG_TMPFS_XATTR
23980 diff -NurpP --minimal linux-3.5.4/mm/slab.c linux-3.5.4-vs2.3.4.3/mm/slab.c
23981 --- linux-3.5.4/mm/slab.c       2012-05-21 18:07:35.000000000 +0200
23982 +++ linux-3.5.4-vs2.3.4.3/mm/slab.c     2012-07-23 01:45:55.000000000 +0200
23983 @@ -413,6 +413,8 @@ static void kmem_list3_init(struct kmem_
23984  #define STATS_INC_FREEMISS(x)  do { } while (0)
23985  #endif
23986  
23987 +#include "slab_vs.h"
23988 +
23989  #if DEBUG
23990  
23991  /*
23992 @@ -3466,6 +3468,7 @@ retry:
23993  
23994         obj = slab_get_obj(cachep, slabp, nodeid);
23995         check_slabp(cachep, slabp);
23996 +       vx_slab_alloc(cachep, flags);
23997         l3->free_objects--;
23998         /* move slabp to correct slabp list: */
23999         list_del(&slabp->list);
24000 @@ -3543,6 +3546,7 @@ __cache_alloc_node(struct kmem_cache *ca
24001         /* ___cache_alloc_node can fall back to other nodes */
24002         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24003    out:
24004 +       vx_slab_alloc(cachep, flags);
24005         local_irq_restore(save_flags);
24006         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24007         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24008 @@ -3730,6 +3734,7 @@ static inline void __cache_free(struct k
24009         check_irq_off();
24010         kmemleak_free_recursive(objp, cachep->flags);
24011         objp = cache_free_debugcheck(cachep, objp, caller);
24012 +       vx_slab_free(cachep);
24013  
24014         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24015  
24016 diff -NurpP --minimal linux-3.5.4/mm/slab_vs.h linux-3.5.4-vs2.3.4.3/mm/slab_vs.h
24017 --- linux-3.5.4/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24018 +++ linux-3.5.4-vs2.3.4.3/mm/slab_vs.h  2012-07-23 01:45:55.000000000 +0200
24019 @@ -0,0 +1,29 @@
24020 +
24021 +#include <linux/vserver/context.h>
24022 +
24023 +#include <linux/vs_context.h>
24024 +
24025 +static inline
24026 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24027 +{
24028 +       int what = gfp_zone(cachep->gfpflags);
24029 +       struct vx_info *vxi = current_vx_info();
24030 +
24031 +       if (!vxi)
24032 +               return;
24033 +
24034 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24035 +}
24036 +
24037 +static inline
24038 +void vx_slab_free(struct kmem_cache *cachep)
24039 +{
24040 +       int what = gfp_zone(cachep->gfpflags);
24041 +       struct vx_info *vxi = current_vx_info();
24042 +
24043 +       if (!vxi)
24044 +               return;
24045 +
24046 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24047 +}
24048 +
24049 diff -NurpP --minimal linux-3.5.4/mm/swapfile.c linux-3.5.4-vs2.3.4.3/mm/swapfile.c
24050 --- linux-3.5.4/mm/swapfile.c   2012-07-22 23:39:47.000000000 +0200
24051 +++ linux-3.5.4-vs2.3.4.3/mm/swapfile.c 2012-07-23 01:45:55.000000000 +0200
24052 @@ -38,6 +38,7 @@
24053  #include <asm/tlbflush.h>
24054  #include <linux/swapops.h>
24055  #include <linux/page_cgroup.h>
24056 +#include <linux/vs_base.h>
24057  
24058  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24059                                  unsigned char);
24060 @@ -1746,6 +1747,16 @@ static int swap_show(struct seq_file *sw
24061  
24062         if (si == SEQ_START_TOKEN) {
24063                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24064 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24065 +                       struct sysinfo si;
24066 +
24067 +                       vx_vsi_swapinfo(&si);
24068 +                       if (si.totalswap < (1 << 10))
24069 +                               return 0;
24070 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24071 +                               "hdv0", "partition", si.totalswap >> 10,
24072 +                               (si.totalswap - si.freeswap) >> 10, -1);
24073 +               }
24074                 return 0;
24075         }
24076  
24077 @@ -2173,6 +2184,8 @@ void si_swapinfo(struct sysinfo *val)
24078         val->freeswap = nr_swap_pages + nr_to_be_unused;
24079         val->totalswap = total_swap_pages + nr_to_be_unused;
24080         spin_unlock(&swap_lock);
24081 +       if (vx_flags(VXF_VIRT_MEM, 0))
24082 +               vx_vsi_swapinfo(val);
24083  }
24084  
24085  /*
24086 diff -NurpP --minimal linux-3.5.4/net/bridge/br_multicast.c linux-3.5.4-vs2.3.4.3/net/bridge/br_multicast.c
24087 --- linux-3.5.4/net/bridge/br_multicast.c       2012-07-22 23:39:47.000000000 +0200
24088 +++ linux-3.5.4-vs2.3.4.3/net/bridge/br_multicast.c     2012-07-23 01:45:55.000000000 +0200
24089 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24090         ip6h->hop_limit = 1;
24091         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24092         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24093 -                              &ip6h->saddr)) {
24094 +                              &ip6h->saddr, NULL)) {
24095                 kfree_skb(skb);
24096                 return NULL;
24097         }
24098 diff -NurpP --minimal linux-3.5.4/net/core/dev.c linux-3.5.4-vs2.3.4.3/net/core/dev.c
24099 --- linux-3.5.4/net/core/dev.c  2012-09-16 20:46:31.000000000 +0200
24100 +++ linux-3.5.4-vs2.3.4.3/net/core/dev.c        2012-08-19 13:28:27.000000000 +0200
24101 @@ -126,6 +126,7 @@
24102  #include <linux/in.h>
24103  #include <linux/jhash.h>
24104  #include <linux/random.h>
24105 +#include <linux/vs_inet.h>
24106  #include <trace/events/napi.h>
24107  #include <trace/events/net.h>
24108  #include <trace/events/skb.h>
24109 @@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
24110         struct hlist_head *head = dev_name_hash(net, name);
24111  
24112         hlist_for_each_entry(dev, p, head, name_hlist)
24113 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24114 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24115 +                   nx_dev_visible(current_nx_info(), dev))
24116                         return dev;
24117  
24118         return NULL;
24119 @@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
24120         struct hlist_head *head = dev_name_hash(net, name);
24121  
24122         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24123 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24124 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24125 +                   nx_dev_visible(current_nx_info(), dev))
24126                         return dev;
24127  
24128         return NULL;
24129 @@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
24130         struct hlist_head *head = dev_index_hash(net, ifindex);
24131  
24132         hlist_for_each_entry(dev, p, head, index_hlist)
24133 -               if (dev->ifindex == ifindex)
24134 +               if ((dev->ifindex == ifindex) &&
24135 +                   nx_dev_visible(current_nx_info(), dev))
24136                         return dev;
24137  
24138         return NULL;
24139 @@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24140   *     about locking. The caller must hold RCU lock.
24141   */
24142  
24143 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24144 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24145  {
24146         struct hlist_node *p;
24147         struct net_device *dev;
24148 @@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
24149  
24150         return NULL;
24151  }
24152 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24153 +
24154 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24155 +{
24156 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24157 +
24158 +       if (nx_dev_visible(current_nx_info(), dev))
24159 +               return dev;
24160 +       return NULL;
24161 +}
24162  EXPORT_SYMBOL(dev_get_by_index_rcu);
24163  
24164  
24165 @@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24166  
24167         for_each_netdev_rcu(net, dev)
24168                 if (dev->type == type &&
24169 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24170 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24171 +                   nx_dev_visible(current_nx_info(), dev))
24172                         return dev;
24173  
24174         return NULL;
24175 @@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
24176         struct net_device *dev;
24177  
24178         ASSERT_RTNL();
24179 -       for_each_netdev(net, dev)
24180 -               if (dev->type == type)
24181 +       for_each_netdev(net, dev) {
24182 +               if ((dev->type == type) &&
24183 +                   nx_dev_visible(current_nx_info(), dev))
24184                         return dev;
24185 +       }
24186  
24187         return NULL;
24188  }
24189 @@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
24190                                 continue;
24191                         if (i < 0 || i >= max_netdevices)
24192                                 continue;
24193 +                       if (!nx_dev_visible(current_nx_info(), d))
24194 +                               continue;
24195  
24196                         /*  avoid cases where sscanf is not exact inverse of printf */
24197                         snprintf(buf, IFNAMSIZ, name, i);
24198 @@ -3976,6 +3995,8 @@ static int dev_ifconf(struct net *net, c
24199  
24200         total = 0;
24201         for_each_netdev(net, dev) {
24202 +               if (!nx_dev_visible(current_nx_info(), dev))
24203 +                       continue;
24204                 for (i = 0; i < NPROTO; i++) {
24205                         if (gifconf_list[i]) {
24206                                 int done;
24207 @@ -4078,6 +4099,10 @@ static void dev_seq_printf_stats(struct 
24208         struct rtnl_link_stats64 temp;
24209         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24210  
24211 +       /* device visible inside network context? */
24212 +       if (!nx_dev_visible(current_nx_info(), dev))
24213 +               return;
24214 +
24215         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24216                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24217                    dev->name, stats->rx_bytes, stats->rx_packets,
24218 diff -NurpP --minimal linux-3.5.4/net/core/rtnetlink.c linux-3.5.4-vs2.3.4.3/net/core/rtnetlink.c
24219 --- linux-3.5.4/net/core/rtnetlink.c    2012-09-16 20:46:31.000000000 +0200
24220 +++ linux-3.5.4-vs2.3.4.3/net/core/rtnetlink.c  2012-08-19 13:28:27.000000000 +0200
24221 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24222                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24223                         if (idx < s_idx)
24224                                 goto cont;
24225 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24226 +                               continue;
24227                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24228                                              NETLINK_CB(cb->skb).pid,
24229                                              cb->nlh->nlmsg_seq, 0,
24230 @@ -1967,6 +1969,9 @@ void rtmsg_ifinfo(int type, struct net_d
24231         int err = -ENOBUFS;
24232         size_t if_info_size;
24233  
24234 +       if (!nx_dev_visible(current_nx_info(), dev))
24235 +               return;
24236 +
24237         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24238         if (skb == NULL)
24239                 goto errout;
24240 diff -NurpP --minimal linux-3.5.4/net/core/sock.c linux-3.5.4-vs2.3.4.3/net/core/sock.c
24241 --- linux-3.5.4/net/core/sock.c 2012-07-22 23:39:48.000000000 +0200
24242 +++ linux-3.5.4-vs2.3.4.3/net/core/sock.c       2012-07-23 01:45:55.000000000 +0200
24243 @@ -132,6 +132,10 @@
24244  #include <net/netprio_cgroup.h>
24245  
24246  #include <linux/filter.h>
24247 +#include <linux/vs_socket.h>
24248 +#include <linux/vs_limit.h>
24249 +#include <linux/vs_context.h>
24250 +#include <linux/vs_network.h>
24251  
24252  #include <trace/events/sock.h>
24253  
24254 @@ -1138,6 +1142,8 @@ static struct sock *sk_prot_alloc(struct
24255                         goto out_free_sec;
24256                 sk_tx_queue_clear(sk);
24257         }
24258 +               sock_vx_init(sk);
24259 +               sock_nx_init(sk);
24260  
24261         return sk;
24262  
24263 @@ -1246,6 +1252,11 @@ static void __sk_free(struct sock *sk)
24264                 put_cred(sk->sk_peer_cred);
24265         put_pid(sk->sk_peer_pid);
24266         put_net(sock_net(sk));
24267 +       vx_sock_dec(sk);
24268 +       clr_vx_info(&sk->sk_vx_info);
24269 +       sk->sk_xid = -1;
24270 +       clr_nx_info(&sk->sk_nx_info);
24271 +       sk->sk_nid = -1;
24272         sk_prot_free(sk->sk_prot_creator, sk);
24273  }
24274  
24275 @@ -1306,6 +1317,8 @@ struct sock *sk_clone_lock(const struct 
24276  
24277                 /* SANITY */
24278                 get_net(sock_net(newsk));
24279 +               sock_vx_init(newsk);
24280 +               sock_nx_init(newsk);
24281                 sk_node_init(&newsk->sk_node);
24282                 sock_lock_init(newsk);
24283                 bh_lock_sock(newsk);
24284 @@ -1362,6 +1375,12 @@ struct sock *sk_clone_lock(const struct 
24285                 smp_wmb();
24286                 atomic_set(&newsk->sk_refcnt, 2);
24287  
24288 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24289 +               newsk->sk_xid = sk->sk_xid;
24290 +               vx_sock_inc(newsk);
24291 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24292 +               newsk->sk_nid = sk->sk_nid;
24293 +
24294                 /*
24295                  * Increment the counter in the same struct proto as the master
24296                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24297 @@ -2118,6 +2137,12 @@ void sock_init_data(struct socket *sock,
24298  
24299         sk->sk_stamp = ktime_set(-1L, 0);
24300  
24301 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24302 +       sk->sk_xid = vx_current_xid();
24303 +       vx_sock_inc(sk);
24304 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24305 +       sk->sk_nid = nx_current_nid();
24306 +
24307         /*
24308          * Before updating sk_refcnt, we must commit prior changes to memory
24309          * (Documentation/RCU/rculist_nulls.txt for details)
24310 diff -NurpP --minimal linux-3.5.4/net/ipv4/af_inet.c linux-3.5.4-vs2.3.4.3/net/ipv4/af_inet.c
24311 --- linux-3.5.4/net/ipv4/af_inet.c      2012-07-22 23:39:48.000000000 +0200
24312 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/af_inet.c    2012-07-23 01:45:55.000000000 +0200
24313 @@ -118,6 +118,7 @@
24314  #ifdef CONFIG_IP_MROUTE
24315  #include <linux/mroute.h>
24316  #endif
24317 +#include <linux/vs_limit.h>
24318  
24319  
24320  /* The inetsw table contains everything that inet_create needs to
24321 @@ -327,9 +328,13 @@ lookup_protocol:
24322         }
24323  
24324         err = -EPERM;
24325 +       if ((protocol == IPPROTO_ICMP) &&
24326 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24327 +               goto override;
24328 +
24329         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24330                 goto out_rcu_unlock;
24331 -
24332 +override:
24333         err = -EAFNOSUPPORT;
24334         if (!inet_netns_ok(net, protocol))
24335                 goto out_rcu_unlock;
24336 @@ -454,6 +459,7 @@ int inet_bind(struct socket *sock, struc
24337         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24338         struct sock *sk = sock->sk;
24339         struct inet_sock *inet = inet_sk(sk);
24340 +       struct nx_v4_sock_addr nsa;
24341         unsigned short snum;
24342         int chk_addr_ret;
24343         int err;
24344 @@ -477,7 +483,11 @@ int inet_bind(struct socket *sock, struc
24345                         goto out;
24346         }
24347  
24348 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24349 +       err = v4_map_sock_addr(inet, addr, &nsa);
24350 +       if (err)
24351 +               goto out;
24352 +
24353 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24354  
24355         /* Not specified by any standard per-se, however it breaks too
24356          * many applications when removed.  It is unfortunate since
24357 @@ -489,7 +499,7 @@ int inet_bind(struct socket *sock, struc
24358         err = -EADDRNOTAVAIL;
24359         if (!sysctl_ip_nonlocal_bind &&
24360             !(inet->freebind || inet->transparent) &&
24361 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24362 +           nsa.saddr != htonl(INADDR_ANY) &&
24363             chk_addr_ret != RTN_LOCAL &&
24364             chk_addr_ret != RTN_MULTICAST &&
24365             chk_addr_ret != RTN_BROADCAST)
24366 @@ -514,7 +524,7 @@ int inet_bind(struct socket *sock, struc
24367         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24368                 goto out_release_sock;
24369  
24370 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24371 +       v4_set_sock_addr(inet, &nsa);
24372         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24373                 inet->inet_saddr = 0;  /* Use device */
24374  
24375 @@ -717,11 +727,13 @@ int inet_getname(struct socket *sock, st
24376                      peer == 1))
24377                         return -ENOTCONN;
24378                 sin->sin_port = inet->inet_dport;
24379 -               sin->sin_addr.s_addr = inet->inet_daddr;
24380 +               sin->sin_addr.s_addr =
24381 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24382         } else {
24383                 __be32 addr = inet->inet_rcv_saddr;
24384                 if (!addr)
24385                         addr = inet->inet_saddr;
24386 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24387                 sin->sin_port = inet->inet_sport;
24388                 sin->sin_addr.s_addr = addr;
24389         }
24390 diff -NurpP --minimal linux-3.5.4/net/ipv4/arp.c linux-3.5.4-vs2.3.4.3/net/ipv4/arp.c
24391 --- linux-3.5.4/net/ipv4/arp.c  2012-07-22 23:39:48.000000000 +0200
24392 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/arp.c        2012-07-23 01:45:55.000000000 +0200
24393 @@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24394         struct net_device *dev = n->dev;
24395         int hatype = dev->type;
24396  
24397 +       /* FIXME: check for network context */
24398         read_lock(&n->lock);
24399         /* Convert hardware address to XX:XX:XX:XX ... form. */
24400  #if IS_ENABLED(CONFIG_AX25)
24401 @@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24402         int hatype = dev ? dev->type : 0;
24403         char tbuf[16];
24404  
24405 +       /* FIXME: check for network context */
24406         sprintf(tbuf, "%pI4", n->key);
24407         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24408                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24409 diff -NurpP --minimal linux-3.5.4/net/ipv4/devinet.c linux-3.5.4-vs2.3.4.3/net/ipv4/devinet.c
24410 --- linux-3.5.4/net/ipv4/devinet.c      2012-07-22 23:39:48.000000000 +0200
24411 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/devinet.c    2012-07-23 01:45:55.000000000 +0200
24412 @@ -516,6 +516,7 @@ struct in_device *inetdev_by_index(struc
24413  }
24414  EXPORT_SYMBOL(inetdev_by_index);
24415  
24416 +
24417  /* Called only from RTNL semaphored context. No locks. */
24418  
24419  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24420 @@ -757,6 +758,8 @@ int devinet_ioctl(struct net *net, unsig
24421  
24422         in_dev = __in_dev_get_rtnl(dev);
24423         if (in_dev) {
24424 +               struct nx_info *nxi = current_nx_info();
24425 +
24426                 if (tryaddrmatch) {
24427                         /* Matthias Andree */
24428                         /* compare label and address (4.4BSD style) */
24429 @@ -765,6 +768,8 @@ int devinet_ioctl(struct net *net, unsig
24430                            This is checked above. */
24431                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24432                              ifap = &ifa->ifa_next) {
24433 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24434 +                                       continue;
24435                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24436                                     sin_orig.sin_addr.s_addr ==
24437                                                         ifa->ifa_local) {
24438 @@ -777,9 +782,12 @@ int devinet_ioctl(struct net *net, unsig
24439                    comparing just the label */
24440                 if (!ifa) {
24441                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24442 -                            ifap = &ifa->ifa_next)
24443 +                            ifap = &ifa->ifa_next) {
24444 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24445 +                                       continue;
24446                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24447                                         break;
24448 +                       }
24449                 }
24450         }
24451  
24452 @@ -932,6 +940,8 @@ static int inet_gifconf(struct net_devic
24453                 goto out;
24454  
24455         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24456 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24457 +                       continue;
24458                 if (!buf) {
24459                         done += sizeof(ifr);
24460                         continue;
24461 @@ -1291,6 +1301,7 @@ static int inet_dump_ifaddr(struct sk_bu
24462         struct net_device *dev;
24463         struct in_device *in_dev;
24464         struct in_ifaddr *ifa;
24465 +       struct sock *sk = skb->sk;
24466         struct hlist_head *head;
24467         struct hlist_node *node;
24468  
24469 @@ -1313,6 +1324,8 @@ static int inet_dump_ifaddr(struct sk_bu
24470  
24471                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24472                              ifa = ifa->ifa_next, ip_idx++) {
24473 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24474 +                               continue;
24475                                 if (ip_idx < s_ip_idx)
24476                                         continue;
24477                                 if (inet_fill_ifaddr(skb, ifa,
24478 diff -NurpP --minimal linux-3.5.4/net/ipv4/fib_trie.c linux-3.5.4-vs2.3.4.3/net/ipv4/fib_trie.c
24479 --- linux-3.5.4/net/ipv4/fib_trie.c     2012-05-21 18:07:40.000000000 +0200
24480 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/fib_trie.c   2012-07-23 01:45:55.000000000 +0200
24481 @@ -2556,6 +2556,7 @@ static int fib_route_seq_show(struct seq
24482                             || fa->fa_type == RTN_MULTICAST)
24483                                 continue;
24484  
24485 +                       /* FIXME: check for network context? */
24486                         if (fi)
24487                                 seq_printf(seq,
24488                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24489 diff -NurpP --minimal linux-3.5.4/net/ipv4/inet_connection_sock.c linux-3.5.4-vs2.3.4.3/net/ipv4/inet_connection_sock.c
24490 --- linux-3.5.4/net/ipv4/inet_connection_sock.c 2012-07-22 23:39:48.000000000 +0200
24491 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/inet_connection_sock.c       2012-07-23 01:45:55.000000000 +0200
24492 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24493  }
24494  EXPORT_SYMBOL(inet_get_local_port_range);
24495  
24496 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24497 +{
24498 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24499 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24500 +
24501 +       if (inet_v6_ipv6only(sk2))
24502 +               return 0;
24503 +
24504 +       if (sk1_rcv_saddr &&
24505 +           sk2_rcv_saddr &&
24506 +           sk1_rcv_saddr == sk2_rcv_saddr)
24507 +               return 1;
24508 +
24509 +       if (sk1_rcv_saddr &&
24510 +           !sk2_rcv_saddr &&
24511 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24512 +               return 1;
24513 +
24514 +       if (sk2_rcv_saddr &&
24515 +           !sk1_rcv_saddr &&
24516 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24517 +               return 1;
24518 +
24519 +       if (!sk1_rcv_saddr &&
24520 +           !sk2_rcv_saddr &&
24521 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24522 +               return 1;
24523 +
24524 +       return 0;
24525 +}
24526 +
24527  int inet_csk_bind_conflict(const struct sock *sk,
24528                            const struct inet_bind_bucket *tb, bool relax)
24529  {
24530 @@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct 
24531                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24532                         if (!reuse || !sk2->sk_reuse ||
24533                             sk2->sk_state == TCP_LISTEN) {
24534 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24535 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24536 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24537 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24538                                         break;
24539                         }
24540                         if (!relax && reuse && sk2->sk_reuse &&
24541 diff -NurpP --minimal linux-3.5.4/net/ipv4/inet_diag.c linux-3.5.4-vs2.3.4.3/net/ipv4/inet_diag.c
24542 --- linux-3.5.4/net/ipv4/inet_diag.c    2012-07-22 23:39:48.000000000 +0200
24543 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/inet_diag.c  2012-07-23 01:45:55.000000000 +0200
24544 @@ -31,6 +31,8 @@
24545  
24546  #include <linux/inet.h>
24547  #include <linux/stddef.h>
24548 +#include <linux/vs_network.h>
24549 +#include <linux/vs_inet.h>
24550  
24551  #include <linux/inet_diag.h>
24552  #include <linux/sock_diag.h>
24553 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24554  
24555         r->id.idiag_sport = inet->inet_sport;
24556         r->id.idiag_dport = inet->inet_dport;
24557 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24558 -       r->id.idiag_dst[0] = inet->inet_daddr;
24559 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24560 +               inet->inet_rcv_saddr);
24561 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24562 +               inet->inet_daddr);
24563  
24564         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24565          * hence this needs to be included regardless of socket family.
24566 @@ -227,8 +231,8 @@ static int inet_twsk_diag_fill(struct in
24567         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24568         r->id.idiag_sport     = tw->tw_sport;
24569         r->id.idiag_dport     = tw->tw_dport;
24570 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24571 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24572 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24573 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24574         r->idiag_state        = tw->tw_substate;
24575         r->idiag_timer        = 3;
24576         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24577 @@ -272,12 +276,14 @@ int inet_diag_dump_one_icsk(struct inet_
24578  
24579         err = -EINVAL;
24580         if (req->sdiag_family == AF_INET) {
24581 +               /* TODO: lback */
24582                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24583                                  req->id.idiag_dport, req->id.idiag_src[0],
24584                                  req->id.idiag_sport, req->id.idiag_if);
24585         }
24586  #if IS_ENABLED(CONFIG_IPV6)
24587         else if (req->sdiag_family == AF_INET6) {
24588 +               /* TODO: lback */
24589                 sk = inet6_lookup(&init_net, hashinfo,
24590                                   (struct in6_addr *)req->id.idiag_dst,
24591                                   req->id.idiag_dport,
24592 @@ -472,6 +478,7 @@ int inet_diag_bc_sk(const struct nlattr 
24593         } else
24594  #endif
24595         {
24596 +                       /* TODO: lback */
24597                 entry.saddr = &inet->inet_rcv_saddr;
24598                 entry.daddr = &inet->inet_daddr;
24599         }
24600 @@ -570,6 +577,7 @@ static int inet_twsk_diag_dump(struct in
24601                 } else
24602  #endif
24603                 {
24604 +                       /* TODO: lback */
24605                         entry.saddr = &tw->tw_rcv_saddr;
24606                         entry.daddr = &tw->tw_daddr;
24607                 }
24608 @@ -615,8 +623,8 @@ static int inet_diag_fill_req(struct sk_
24609  
24610         r->id.idiag_sport = inet->inet_sport;
24611         r->id.idiag_dport = ireq->rmt_port;
24612 -       r->id.idiag_src[0] = ireq->loc_addr;
24613 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24614 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24615 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24616         r->idiag_expires = jiffies_to_msecs(tmo);
24617         r->idiag_rqueue = 0;
24618         r->idiag_wqueue = 0;
24619 @@ -683,6 +691,7 @@ static int inet_diag_dump_reqs(struct sk
24620                                 continue;
24621  
24622                         if (bc) {
24623 +                               /* TODO: lback */
24624                                 entry.saddr =
24625  #if IS_ENABLED(CONFIG_IPV6)
24626                                         (entry.family == AF_INET6) ?
24627 @@ -744,6 +753,8 @@ void inet_diag_dump_icsk(struct inet_has
24628                         sk_nulls_for_each(sk, node, &ilb->head) {
24629                                 struct inet_sock *inet = inet_sk(sk);
24630  
24631 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24632 +                                       continue;
24633                                 if (num < s_num) {
24634                                         num++;
24635                                         continue;
24636 @@ -814,6 +825,8 @@ skip_listen_ht:
24637                 sk_nulls_for_each(sk, node, &head->chain) {
24638                         struct inet_sock *inet = inet_sk(sk);
24639  
24640 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24641 +                               continue;
24642                         if (num < s_num)
24643                                 goto next_normal;
24644                         if (!(r->idiag_states & (1 << sk->sk_state)))
24645 @@ -841,6 +854,8 @@ next_normal:
24646                         inet_twsk_for_each(tw, node,
24647                                     &head->twchain) {
24648  
24649 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24650 +                                       continue;
24651                                 if (num < s_num)
24652                                         goto next_dying;
24653                                 if (r->sdiag_family != AF_UNSPEC &&
24654 diff -NurpP --minimal linux-3.5.4/net/ipv4/inet_hashtables.c linux-3.5.4-vs2.3.4.3/net/ipv4/inet_hashtables.c
24655 --- linux-3.5.4/net/ipv4/inet_hashtables.c      2012-07-22 23:39:48.000000000 +0200
24656 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/inet_hashtables.c    2012-07-23 01:45:55.000000000 +0200
24657 @@ -22,6 +22,7 @@
24658  #include <net/inet_connection_sock.h>
24659  #include <net/inet_hashtables.h>
24660  #include <net/secure_seq.h>
24661 +#include <net/route.h>
24662  #include <net/ip.h>
24663  
24664  /*
24665 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24666                         if (rcv_saddr != daddr)
24667                                 return -1;
24668                         score += 2;
24669 +               } else {
24670 +                       /* block non nx_info ips */
24671 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24672 +                               daddr, NXA_MASK_BIND))
24673 +                               return -1;
24674                 }
24675                 if (sk->sk_bound_dev_if) {
24676                         if (sk->sk_bound_dev_if != dif)
24677 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24678   * wildcarded during the search since they can never be otherwise.
24679   */
24680  
24681 -
24682  struct sock *__inet_lookup_listener(struct net *net,
24683                                     struct inet_hashinfo *hashinfo,
24684                                     const __be32 daddr, const unsigned short hnum,
24685 @@ -196,6 +201,7 @@ begin:
24686                         hiscore = score;
24687                 }
24688         }
24689 +
24690         /*
24691          * if the nulls value we got at the end of this lookup is
24692          * not the expected one, we must restart lookup.
24693 diff -NurpP --minimal linux-3.5.4/net/ipv4/netfilter/nf_nat_helper.c linux-3.5.4-vs2.3.4.3/net/ipv4/netfilter/nf_nat_helper.c
24694 --- linux-3.5.4/net/ipv4/netfilter/nf_nat_helper.c      2012-03-19 19:47:33.000000000 +0100
24695 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/netfilter/nf_nat_helper.c    2012-07-23 01:45:55.000000000 +0200
24696 @@ -20,6 +20,7 @@
24697  #include <net/route.h>
24698  
24699  #include <linux/netfilter_ipv4.h>
24700 +#include <net/route.h>
24701  #include <net/netfilter/nf_conntrack.h>
24702  #include <net/netfilter/nf_conntrack_helper.h>
24703  #include <net/netfilter/nf_conntrack_ecache.h>
24704 diff -NurpP --minimal linux-3.5.4/net/ipv4/netfilter.c linux-3.5.4-vs2.3.4.3/net/ipv4/netfilter.c
24705 --- linux-3.5.4/net/ipv4/netfilter.c    2012-07-22 23:39:48.000000000 +0200
24706 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/netfilter.c  2012-07-23 01:45:55.000000000 +0200
24707 @@ -6,7 +6,7 @@
24708  #include <linux/skbuff.h>
24709  #include <linux/gfp.h>
24710  #include <linux/export.h>
24711 -#include <net/route.h>
24712 +// #include <net/route.h>
24713  #include <net/xfrm.h>
24714  #include <net/ip.h>
24715  #include <net/netfilter/nf_queue.h>
24716 diff -NurpP --minimal linux-3.5.4/net/ipv4/raw.c linux-3.5.4-vs2.3.4.3/net/ipv4/raw.c
24717 --- linux-3.5.4/net/ipv4/raw.c  2012-07-22 23:39:48.000000000 +0200
24718 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/raw.c        2012-07-23 01:45:55.000000000 +0200
24719 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24720  
24721                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24722                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24723 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24724 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24725                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24726                         goto found; /* gotcha */
24727         }
24728 @@ -390,6 +390,12 @@ static int raw_send_hdrinc(struct sock *
24729                 icmp_out_count(net, ((struct icmphdr *)
24730                         skb_transport_header(skb))->type);
24731  
24732 +       err = -EPERM;
24733 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24734 +               sk->sk_nx_info &&
24735 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24736 +               goto error_free;
24737 +
24738         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24739                       rt->dst.dev, dst_output);
24740         if (err > 0)
24741 @@ -575,6 +581,16 @@ static int raw_sendmsg(struct kiocb *ioc
24742                         goto done;
24743         }
24744  
24745 +       if (sk->sk_nx_info) {
24746 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24747 +               if (IS_ERR(rt)) {
24748 +                       err = PTR_ERR(rt);
24749 +                       rt = NULL;
24750 +                       goto done;
24751 +               }
24752 +               ip_rt_put(rt);
24753 +       }
24754 +
24755         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24756         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24757         if (IS_ERR(rt)) {
24758 @@ -651,17 +667,19 @@ static int raw_bind(struct sock *sk, str
24759  {
24760         struct inet_sock *inet = inet_sk(sk);
24761         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24762 +       struct nx_v4_sock_addr nsa = { 0 };
24763         int ret = -EINVAL;
24764         int chk_addr_ret;
24765  
24766         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24767                 goto out;
24768 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24769 +       v4_map_sock_addr(inet, addr, &nsa);
24770 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24771         ret = -EADDRNOTAVAIL;
24772 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24773 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24774             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24775                 goto out;
24776 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24777 +       v4_set_sock_addr(inet, &nsa);
24778         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24779                 inet->inet_saddr = 0;  /* Use device */
24780         sk_dst_reset(sk);
24781 @@ -713,7 +731,8 @@ static int raw_recvmsg(struct kiocb *ioc
24782         /* Copy the address. */
24783         if (sin) {
24784                 sin->sin_family = AF_INET;
24785 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24786 +               sin->sin_addr.s_addr =
24787 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24788                 sin->sin_port = 0;
24789                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24790         }
24791 @@ -909,7 +928,8 @@ static struct sock *raw_get_first(struct
24792                 struct hlist_node *node;
24793  
24794                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24795 -                       if (sock_net(sk) == seq_file_net(seq))
24796 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24797 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24798                                 goto found;
24799         }
24800         sk = NULL;
24801 @@ -925,7 +945,8 @@ static struct sock *raw_get_next(struct 
24802                 sk = sk_next(sk);
24803  try_again:
24804                 ;
24805 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24806 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24807 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24808  
24809         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24810                 sk = sk_head(&state->h->ht[state->bucket]);
24811 diff -NurpP --minimal linux-3.5.4/net/ipv4/route.c linux-3.5.4-vs2.3.4.3/net/ipv4/route.c
24812 --- linux-3.5.4/net/ipv4/route.c        2012-07-22 23:39:48.000000000 +0200
24813 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/route.c      2012-07-23 01:45:55.000000000 +0200
24814 @@ -2690,7 +2690,7 @@ static struct rtable *ip_route_output_sl
24815  
24816  
24817         if (fl4->flowi4_oif) {
24818 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24819 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24820                 rth = ERR_PTR(-ENODEV);
24821                 if (dev_out == NULL)
24822                         goto out;
24823 diff -NurpP --minimal linux-3.5.4/net/ipv4/tcp.c linux-3.5.4-vs2.3.4.3/net/ipv4/tcp.c
24824 --- linux-3.5.4/net/ipv4/tcp.c  2012-09-16 20:46:31.000000000 +0200
24825 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/tcp.c        2012-08-11 15:15:02.000000000 +0200
24826 @@ -268,6 +268,7 @@
24827  #include <linux/crypto.h>
24828  #include <linux/time.h>
24829  #include <linux/slab.h>
24830 +#include <linux/in.h>
24831  
24832  #include <net/icmp.h>
24833  #include <net/tcp.h>
24834 diff -NurpP --minimal linux-3.5.4/net/ipv4/tcp_ipv4.c linux-3.5.4-vs2.3.4.3/net/ipv4/tcp_ipv4.c
24835 --- linux-3.5.4/net/ipv4/tcp_ipv4.c     2012-07-22 23:39:48.000000000 +0200
24836 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/tcp_ipv4.c   2012-07-23 01:45:55.000000000 +0200
24837 @@ -2005,6 +2005,12 @@ static void *listening_get_next(struct s
24838                 req = req->dl_next;
24839                 while (1) {
24840                         while (req) {
24841 +                               vxdprintk(VXD_CBIT(net, 6),
24842 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24843 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24844 +                               if (req->sk &&
24845 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24846 +                                       continue;
24847                                 if (req->rsk_ops->family == st->family) {
24848                                         cur = req;
24849                                         goto out;
24850 @@ -2029,6 +2035,10 @@ get_req:
24851         }
24852  get_sk:
24853         sk_nulls_for_each_from(sk, node) {
24854 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24855 +                       sk, sk->sk_nid, nx_current_nid());
24856 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24857 +                       continue;
24858                 if (!net_eq(sock_net(sk), net))
24859                         continue;
24860                 if (sk->sk_family == st->family) {
24861 @@ -2105,6 +2115,11 @@ static void *established_get_first(struc
24862  
24863                 spin_lock_bh(lock);
24864                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24865 +                       vxdprintk(VXD_CBIT(net, 6),
24866 +                               "sk,egf: %p [#%d] (from %d)",
24867 +                               sk, sk->sk_nid, nx_current_nid());
24868 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24869 +                               continue;
24870                         if (sk->sk_family != st->family ||
24871                             !net_eq(sock_net(sk), net)) {
24872                                 continue;
24873 @@ -2115,6 +2130,11 @@ static void *established_get_first(struc
24874                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24875                 inet_twsk_for_each(tw, node,
24876                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24877 +                       vxdprintk(VXD_CBIT(net, 6),
24878 +                               "tw: %p [#%d] (from %d)",
24879 +                               tw, tw->tw_nid, nx_current_nid());
24880 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24881 +                               continue;
24882                         if (tw->tw_family != st->family ||
24883                             !net_eq(twsk_net(tw), net)) {
24884                                 continue;
24885 @@ -2144,7 +2164,9 @@ static void *established_get_next(struct
24886                 tw = cur;
24887                 tw = tw_next(tw);
24888  get_tw:
24889 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24890 +               while (tw && (tw->tw_family != st->family ||
24891 +                       !net_eq(twsk_net(tw), net) ||
24892 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24893                         tw = tw_next(tw);
24894                 }
24895                 if (tw) {
24896 @@ -2168,6 +2190,11 @@ get_tw:
24897                 sk = sk_nulls_next(sk);
24898  
24899         sk_nulls_for_each_from(sk, node) {
24900 +               vxdprintk(VXD_CBIT(net, 6),
24901 +                       "sk,egn: %p [#%d] (from %d)",
24902 +                       sk, sk->sk_nid, nx_current_nid());
24903 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24904 +                       continue;
24905                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24906                         goto found;
24907         }
24908 @@ -2373,9 +2400,9 @@ static void get_openreq4(const struct so
24909         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24910                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24911                 i,
24912 -               ireq->loc_addr,
24913 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24914                 ntohs(inet_sk(sk)->inet_sport),
24915 -               ireq->rmt_addr,
24916 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24917                 ntohs(ireq->rmt_port),
24918                 TCP_SYN_RECV,
24919                 0, 0, /* could print option size, but that is af dependent. */
24920 @@ -2397,8 +2424,8 @@ static void get_tcp4_sock(struct sock *s
24921         const struct tcp_sock *tp = tcp_sk(sk);
24922         const struct inet_connection_sock *icsk = inet_csk(sk);
24923         const struct inet_sock *inet = inet_sk(sk);
24924 -       __be32 dest = inet->inet_daddr;
24925 -       __be32 src = inet->inet_rcv_saddr;
24926 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24927 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24928         __u16 destp = ntohs(inet->inet_dport);
24929         __u16 srcp = ntohs(inet->inet_sport);
24930         int rx_queue;
24931 @@ -2455,8 +2482,8 @@ static void get_timewait4_sock(const str
24932         if (ttd < 0)
24933                 ttd = 0;
24934  
24935 -       dest  = tw->tw_daddr;
24936 -       src   = tw->tw_rcv_saddr;
24937 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24938 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24939         destp = ntohs(tw->tw_dport);
24940         srcp  = ntohs(tw->tw_sport);
24941  
24942 diff -NurpP --minimal linux-3.5.4/net/ipv4/tcp_minisocks.c linux-3.5.4-vs2.3.4.3/net/ipv4/tcp_minisocks.c
24943 --- linux-3.5.4/net/ipv4/tcp_minisocks.c        2012-07-22 23:39:48.000000000 +0200
24944 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/tcp_minisocks.c      2012-07-23 01:45:55.000000000 +0200
24945 @@ -23,6 +23,9 @@
24946  #include <linux/slab.h>
24947  #include <linux/sysctl.h>
24948  #include <linux/workqueue.h>
24949 +#include <linux/vs_limit.h>
24950 +#include <linux/vs_socket.h>
24951 +#include <linux/vs_context.h>
24952  #include <net/tcp.h>
24953  #include <net/inet_common.h>
24954  #include <net/xfrm.h>
24955 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
24956                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
24957                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24958  
24959 +               tw->tw_xid              = sk->sk_xid;
24960 +               tw->tw_vx_info          = NULL;
24961 +               tw->tw_nid              = sk->sk_nid;
24962 +               tw->tw_nx_info          = NULL;
24963 +
24964  #if IS_ENABLED(CONFIG_IPV6)
24965                 if (tw->tw_family == PF_INET6) {
24966                         struct ipv6_pinfo *np = inet6_sk(sk);
24967 diff -NurpP --minimal linux-3.5.4/net/ipv4/udp.c linux-3.5.4-vs2.3.4.3/net/ipv4/udp.c
24968 --- linux-3.5.4/net/ipv4/udp.c  2012-07-22 23:39:48.000000000 +0200
24969 +++ linux-3.5.4-vs2.3.4.3/net/ipv4/udp.c        2012-07-23 01:45:55.000000000 +0200
24970 @@ -299,14 +299,7 @@ fail:
24971  }
24972  EXPORT_SYMBOL(udp_lib_get_port);
24973  
24974 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24975 -{
24976 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24977 -
24978 -       return  (!ipv6_only_sock(sk2)  &&
24979 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24980 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24981 -}
24982 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24983  
24984  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24985                                        unsigned int port)
24986 @@ -341,6 +334,11 @@ static inline int compute_score(struct s
24987                         if (inet->inet_rcv_saddr != daddr)
24988                                 return -1;
24989                         score += 2;
24990 +               } else {
24991 +                       /* block non nx_info ips */
24992 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24993 +                               daddr, NXA_MASK_BIND))
24994 +                               return -1;
24995                 }
24996                 if (inet->inet_daddr) {
24997                         if (inet->inet_daddr != saddr)
24998 @@ -444,6 +442,7 @@ exact_match:
24999         return result;
25000  }
25001  
25002 +
25003  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25004   * harder than this. -DaveM
25005   */
25006 @@ -489,6 +488,11 @@ begin:
25007         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25008                 score = compute_score(sk, net, saddr, hnum, sport,
25009                                       daddr, dport, dif);
25010 +               /* FIXME: disabled?
25011 +               if (score == 9) {
25012 +                       result = sk;
25013 +                       break;
25014 +               } else */
25015                 if (score > badness) {
25016                         result = sk;
25017                         badness = score;
25018 @@ -502,6 +506,7 @@ begin:
25019         if (get_nulls_value(node) != slot)
25020                 goto begin;
25021  
25022 +
25023         if (result) {
25024                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25025                         result = NULL;
25026 @@ -511,6 +516,7 @@ begin:
25027                         goto begin;
25028                 }
25029         }
25030 +
25031         rcu_read_unlock();
25032         return result;
25033  }
25034 @@ -554,8 +560,7 @@ static inline struct sock *udp_v4_mcast_
25035                     udp_sk(s)->udp_port_hash != hnum ||
25036                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25037                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25038 -                   (inet->inet_rcv_saddr &&
25039 -                    inet->inet_rcv_saddr != loc_addr) ||
25040 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25041                     ipv6_only_sock(s) ||
25042                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25043                         continue;
25044 @@ -934,6 +939,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25045                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25046                                    faddr, saddr, dport, inet->inet_sport);
25047  
25048 +               if (sk->sk_nx_info) {
25049 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25050 +                       if (IS_ERR(rt)) {
25051 +                               err = PTR_ERR(rt);
25052 +                               rt = NULL;
25053 +                               goto out;
25054 +                       }
25055 +                       ip_rt_put(rt);
25056 +               }
25057 +
25058                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25059                 rt = ip_route_output_flow(net, fl4, sk);
25060                 if (IS_ERR(rt)) {
25061 @@ -1232,7 +1247,8 @@ try_again:
25062         if (sin) {
25063                 sin->sin_family = AF_INET;
25064                 sin->sin_port = udp_hdr(skb)->source;
25065 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25066 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25067 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25068                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25069         }
25070         if (inet->cmsg_flags)
25071 @@ -1980,6 +1996,8 @@ static struct sock *udp_get_first(struct
25072                 sk_nulls_for_each(sk, node, &hslot->head) {
25073                         if (!net_eq(sock_net(sk), net))
25074                                 continue;
25075 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25076 +                               continue;
25077                         if (sk->sk_family == state->family)
25078                                 goto found;
25079                 }
25080 @@ -1997,7 +2015,9 @@ static struct sock *udp_get_next(struct 
25081  
25082         do {
25083                 sk = sk_nulls_next(sk);
25084 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25085 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25086 +               sk->sk_family != state->family ||
25087 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25088  
25089         if (!sk) {
25090                 if (state->bucket <= state->udp_table->mask)
25091 @@ -2093,8 +2113,8 @@ static void udp4_format_sock(struct sock
25092                 int bucket, int *len)
25093  {
25094         struct inet_sock *inet = inet_sk(sp);
25095 -       __be32 dest = inet->inet_daddr;
25096 -       __be32 src  = inet->inet_rcv_saddr;
25097 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25098 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25099         __u16 destp       = ntohs(inet->inet_dport);
25100         __u16 srcp        = ntohs(inet->inet_sport);
25101  
25102 diff -NurpP --minimal linux-3.5.4/net/ipv6/Kconfig linux-3.5.4-vs2.3.4.3/net/ipv6/Kconfig
25103 --- linux-3.5.4/net/ipv6/Kconfig        2012-07-22 23:39:48.000000000 +0200
25104 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/Kconfig      2012-07-23 01:45:55.000000000 +0200
25105 @@ -4,8 +4,8 @@
25106  
25107  #   IPv6 as module will cause a CRASH if you try to unload it
25108  menuconfig IPV6
25109 -       tristate "The IPv6 protocol"
25110 -       default m
25111 +       bool "The IPv6 protocol"
25112 +       default n
25113         ---help---
25114           This is complemental support for the IP version 6.
25115           You will still be able to do traditional IPv4 networking as well.
25116 diff -NurpP --minimal linux-3.5.4/net/ipv6/addrconf.c linux-3.5.4-vs2.3.4.3/net/ipv6/addrconf.c
25117 --- linux-3.5.4/net/ipv6/addrconf.c     2012-07-22 23:39:48.000000000 +0200
25118 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/addrconf.c   2012-07-23 01:45:56.000000000 +0200
25119 @@ -91,6 +91,8 @@
25120  #include <linux/proc_fs.h>
25121  #include <linux/seq_file.h>
25122  #include <linux/export.h>
25123 +#include <linux/vs_network.h>
25124 +#include <linux/vs_inet6.h>
25125  
25126  /* Set to 3 to get tracing... */
25127  #define ACONF_DEBUG 2
25128 @@ -1102,7 +1104,7 @@ out:
25129  
25130  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25131                        const struct in6_addr *daddr, unsigned int prefs,
25132 -                      struct in6_addr *saddr)
25133 +                      struct in6_addr *saddr, struct nx_info *nxi)
25134  {
25135         struct ipv6_saddr_score scores[2],
25136                                 *score = &scores[0], *hiscore = &scores[1];
25137 @@ -1174,6 +1176,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25138                                                dev->name);
25139                                 continue;
25140                         }
25141 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25142 +                               continue;
25143  
25144                         score->rule = -1;
25145                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25146 @@ -3157,7 +3161,10 @@ static void if6_seq_stop(struct seq_file
25147  static int if6_seq_show(struct seq_file *seq, void *v)
25148  {
25149         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25150 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25151 +
25152 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25153 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25154 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25155                    &ifp->addr,
25156                    ifp->idev->dev->ifindex,
25157                    ifp->prefix_len,
25158 @@ -3663,6 +3670,11 @@ static int in6_dump_addrs(struct inet6_d
25159         struct ifacaddr6 *ifaca;
25160         int err = 1;
25161         int ip_idx = *p_ip_idx;
25162 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25163 +
25164 +       /* disable ipv6 on non v6 guests */
25165 +       if (nxi && !nx_info_has_v6(nxi))
25166 +               return skb->len;
25167  
25168         read_lock_bh(&idev->lock);
25169         switch (type) {
25170 @@ -3673,6 +3685,8 @@ static int in6_dump_addrs(struct inet6_d
25171                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25172                         if (++ip_idx < s_ip_idx)
25173                                 continue;
25174 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25175 +                                       continue;
25176                         err = inet6_fill_ifaddr(skb, ifa,
25177                                                 NETLINK_CB(cb->skb).pid,
25178                                                 cb->nlh->nlmsg_seq,
25179 @@ -3689,6 +3703,8 @@ static int in6_dump_addrs(struct inet6_d
25180                      ifmca = ifmca->next, ip_idx++) {
25181                         if (ip_idx < s_ip_idx)
25182                                 continue;
25183 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25184 +                                       continue;
25185                         err = inet6_fill_ifmcaddr(skb, ifmca,
25186                                                   NETLINK_CB(cb->skb).pid,
25187                                                   cb->nlh->nlmsg_seq,
25188 @@ -3704,6 +3720,8 @@ static int in6_dump_addrs(struct inet6_d
25189                      ifaca = ifaca->aca_next, ip_idx++) {
25190                         if (ip_idx < s_ip_idx)
25191                                 continue;
25192 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25193 +                                       continue;
25194                         err = inet6_fill_ifacaddr(skb, ifaca,
25195                                                   NETLINK_CB(cb->skb).pid,
25196                                                   cb->nlh->nlmsg_seq,
25197 @@ -4087,6 +4105,11 @@ static int inet6_dump_ifinfo(struct sk_b
25198         struct inet6_dev *idev;
25199         struct hlist_head *head;
25200         struct hlist_node *node;
25201 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25202 +
25203 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25204 +       if (skb->sk && skb->sk->sk_vx_info)
25205 +               return skb->len; */
25206  
25207         s_h = cb->args[0];
25208         s_idx = cb->args[1];
25209 @@ -4098,6 +4121,8 @@ static int inet6_dump_ifinfo(struct sk_b
25210                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25211                         if (idx < s_idx)
25212                                 goto cont;
25213 +                       if (!v6_dev_in_nx_info(dev, nxi))
25214 +                               goto cont;
25215                         idev = __in6_dev_get(dev);
25216                         if (!idev)
25217                                 goto cont;
25218 diff -NurpP --minimal linux-3.5.4/net/ipv6/af_inet6.c linux-3.5.4-vs2.3.4.3/net/ipv6/af_inet6.c
25219 --- linux-3.5.4/net/ipv6/af_inet6.c     2012-07-22 23:39:48.000000000 +0200
25220 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/af_inet6.c   2012-08-27 12:52:07.000000000 +0200
25221 @@ -43,6 +43,8 @@
25222  #include <linux/netdevice.h>
25223  #include <linux/icmpv6.h>
25224  #include <linux/netfilter_ipv6.h>
25225 +#include <linux/vs_inet.h>
25226 +#include <linux/vs_inet6.h>
25227  
25228  #include <net/ip.h>
25229  #include <net/ipv6.h>
25230 @@ -160,9 +162,12 @@ lookup_protocol:
25231         }
25232  
25233         err = -EPERM;
25234 +       if ((protocol == IPPROTO_ICMPV6) &&
25235 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25236 +               goto override;
25237         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25238                 goto out_rcu_unlock;
25239 -
25240 +override:
25241         sock->ops = answer->ops;
25242         answer_prot = answer->prot;
25243         answer_no_check = answer->no_check;
25244 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25245         struct inet_sock *inet = inet_sk(sk);
25246         struct ipv6_pinfo *np = inet6_sk(sk);
25247         struct net *net = sock_net(sk);
25248 +       struct nx_v6_sock_addr nsa;
25249         __be32 v4addr = 0;
25250         unsigned short snum;
25251         int addr_type = 0;
25252 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25253         if (addr->sin6_family != AF_INET6)
25254                 return -EAFNOSUPPORT;
25255  
25256 +       err = v6_map_sock_addr(inet, addr, &nsa);
25257 +       if (err)
25258 +               return err;
25259 +
25260         addr_type = ipv6_addr_type(&addr->sin6_addr);
25261         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25262                 return -EINVAL;
25263 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25264                 /* Reproduce AF_INET checks to make the bindings consistent */
25265                 v4addr = addr->sin6_addr.s6_addr32[3];
25266                 chk_addr_ret = inet_addr_type(net, v4addr);
25267 +
25268                 if (!sysctl_ip_nonlocal_bind &&
25269                     !(inet->freebind || inet->transparent) &&
25270                     v4addr != htonl(INADDR_ANY) &&
25271 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25272                         err = -EADDRNOTAVAIL;
25273                         goto out;
25274                 }
25275 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25276 +                       err = -EADDRNOTAVAIL;
25277 +                       goto out;
25278 +               }
25279         } else {
25280                 if (addr_type != IPV6_ADDR_ANY) {
25281                         struct net_device *dev = NULL;
25282 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25283                                 }
25284                         }
25285  
25286 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25287 +                               err = -EADDRNOTAVAIL;
25288 +                               goto out_unlock;
25289 +                       }
25290 +
25291                         /* ipv4 addr of the socket is invalid.  Only the
25292                          * unspecified and mapped address have a v4 equivalent.
25293                          */
25294 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25295                 }
25296         }
25297  
25298 +       /* what's that for? */
25299 +       v6_set_sock_addr(inet, &nsa);
25300 +
25301         inet->inet_rcv_saddr = v4addr;
25302         inet->inet_saddr = v4addr;
25303  
25304 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25305                         return -ENOTCONN;
25306                 sin->sin6_port = inet->inet_dport;
25307                 sin->sin6_addr = np->daddr;
25308 +               /* FIXME: remap lback? */
25309                 if (np->sndflow)
25310                         sin->sin6_flowinfo = np->flow_label;
25311         } else {
25312 +               /* FIXME: remap lback? */
25313                 if (ipv6_addr_any(&np->rcv_saddr))
25314                         sin->sin6_addr = np->saddr;
25315                 else
25316 diff -NurpP --minimal linux-3.5.4/net/ipv6/datagram.c linux-3.5.4-vs2.3.4.3/net/ipv6/datagram.c
25317 --- linux-3.5.4/net/ipv6/datagram.c     2012-07-22 23:39:48.000000000 +0200
25318 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/datagram.c   2012-07-23 01:45:56.000000000 +0200
25319 @@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25320  
25321                         rcu_read_lock();
25322                         if (fl6->flowi6_oif) {
25323 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25324 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25325                                 if (!dev) {
25326                                         rcu_read_unlock();
25327                                         return -ENODEV;
25328 diff -NurpP --minimal linux-3.5.4/net/ipv6/fib6_rules.c linux-3.5.4-vs2.3.4.3/net/ipv6/fib6_rules.c
25329 --- linux-3.5.4/net/ipv6/fib6_rules.c   2012-07-22 23:39:48.000000000 +0200
25330 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/fib6_rules.c 2012-07-23 01:45:56.000000000 +0200
25331 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25332                                                ip6_dst_idev(&rt->dst)->dev,
25333                                                &flp6->daddr,
25334                                                rt6_flags2srcprefs(flags),
25335 -                                              &saddr))
25336 +                                              &saddr, NULL))
25337                                 goto again;
25338                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25339                                                r->src.plen))
25340 diff -NurpP --minimal linux-3.5.4/net/ipv6/inet6_hashtables.c linux-3.5.4-vs2.3.4.3/net/ipv6/inet6_hashtables.c
25341 --- linux-3.5.4/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25342 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/inet6_hashtables.c   2012-07-23 01:45:56.000000000 +0200
25343 @@ -16,6 +16,7 @@
25344  
25345  #include <linux/module.h>
25346  #include <linux/random.h>
25347 +#include <linux/vs_inet6.h>
25348  
25349  #include <net/inet_connection_sock.h>
25350  #include <net/inet_hashtables.h>
25351 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25352         unsigned int slot = hash & hashinfo->ehash_mask;
25353         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25354  
25355 -
25356         rcu_read_lock();
25357  begin:
25358         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25359 @@ -95,7 +95,7 @@ begin:
25360                                 sock_put(sk);
25361                                 goto begin;
25362                         }
25363 -               goto out;
25364 +                       goto out;
25365                 }
25366         }
25367         if (get_nulls_value(node) != slot)
25368 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25369                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25370                                 return -1;
25371                         score++;
25372 +               } else {
25373 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25374 +                               return -1;
25375                 }
25376                 if (sk->sk_bound_dev_if) {
25377                         if (sk->sk_bound_dev_if != dif)
25378 diff -NurpP --minimal linux-3.5.4/net/ipv6/ip6_output.c linux-3.5.4-vs2.3.4.3/net/ipv6/ip6_output.c
25379 --- linux-3.5.4/net/ipv6/ip6_output.c   2012-07-22 23:39:48.000000000 +0200
25380 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/ip6_output.c 2012-07-23 01:45:56.000000000 +0200
25381 @@ -973,7 +973,8 @@ static int ip6_dst_lookup_tail(struct so
25382                 struct rt6_info *rt = (struct rt6_info *) *dst;
25383                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25384                                           sk ? inet6_sk(sk)->srcprefs : 0,
25385 -                                         &fl6->saddr);
25386 +                                         &fl6->saddr,
25387 +                                         sk ? sk->sk_nx_info : NULL);
25388                 if (err)
25389                         goto out_err_release;
25390         }
25391 diff -NurpP --minimal linux-3.5.4/net/ipv6/ndisc.c linux-3.5.4-vs2.3.4.3/net/ipv6/ndisc.c
25392 --- linux-3.5.4/net/ipv6/ndisc.c        2012-07-22 23:39:48.000000000 +0200
25393 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/ndisc.c      2012-07-23 01:45:56.000000000 +0200
25394 @@ -562,7 +562,7 @@ static void ndisc_send_na(struct net_dev
25395         } else {
25396                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25397                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25398 -                                      &tmpaddr))
25399 +                                      &tmpaddr, NULL))
25400                         return;
25401                 src_addr = &tmpaddr;
25402         }
25403 diff -NurpP --minimal linux-3.5.4/net/ipv6/raw.c linux-3.5.4-vs2.3.4.3/net/ipv6/raw.c
25404 --- linux-3.5.4/net/ipv6/raw.c  2012-07-22 23:39:48.000000000 +0200
25405 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/raw.c        2012-07-23 01:45:56.000000000 +0200
25406 @@ -30,6 +30,7 @@
25407  #include <linux/icmpv6.h>
25408  #include <linux/netfilter.h>
25409  #include <linux/netfilter_ipv6.h>
25410 +#include <linux/vs_inet6.h>
25411  #include <linux/skbuff.h>
25412  #include <linux/compat.h>
25413  #include <asm/uaccess.h>
25414 @@ -285,6 +286,13 @@ static int rawv6_bind(struct sock *sk, s
25415                                 goto out_unlock;
25416                 }
25417  
25418 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25419 +                       err = -EADDRNOTAVAIL;
25420 +                       if (dev)
25421 +                               dev_put(dev);
25422 +                       goto out;
25423 +               }
25424 +
25425                 /* ipv4 addr of the socket is invalid.  Only the
25426                  * unspecified and mapped address have a v4 equivalent.
25427                  */
25428 diff -NurpP --minimal linux-3.5.4/net/ipv6/route.c linux-3.5.4-vs2.3.4.3/net/ipv6/route.c
25429 --- linux-3.5.4/net/ipv6/route.c        2012-07-22 23:39:48.000000000 +0200
25430 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/route.c      2012-07-23 10:25:43.000000000 +0200
25431 @@ -57,6 +57,7 @@
25432  #include <net/xfrm.h>
25433  #include <net/netevent.h>
25434  #include <net/netlink.h>
25435 +#include <linux/vs_inet6.h>
25436  
25437  #include <asm/uaccess.h>
25438  
25439 @@ -2140,15 +2141,17 @@ int ip6_route_get_saddr(struct net *net,
25440                         struct rt6_info *rt,
25441                         const struct in6_addr *daddr,
25442                         unsigned int prefs,
25443 -                       struct in6_addr *saddr)
25444 +                       struct in6_addr *saddr,
25445 +                       struct nx_info *nxi)
25446  {
25447         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25448         int err = 0;
25449 -       if (rt->rt6i_prefsrc.plen)
25450 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25451 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25452                 *saddr = rt->rt6i_prefsrc.addr;
25453         else
25454                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25455 -                                        daddr, prefs, saddr);
25456 +                                        daddr, prefs, saddr, nxi);
25457         return err;
25458  }
25459  
25460 @@ -2484,7 +2487,8 @@ static int rt6_fill_node(struct net *net
25461                                 goto nla_put_failure;
25462         } else if (dst) {
25463                 struct in6_addr saddr_buf;
25464 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25465 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25466 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25467                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25468                         goto nla_put_failure;
25469         }
25470 @@ -2714,6 +2718,7 @@ static int rt6_info_route(struct rt6_inf
25471         struct seq_file *m = p_arg;
25472         struct neighbour *n;
25473  
25474 +       /* FIXME: check for network context? */
25475         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25476  
25477  #ifdef CONFIG_IPV6_SUBTREES
25478 diff -NurpP --minimal linux-3.5.4/net/ipv6/tcp_ipv6.c linux-3.5.4-vs2.3.4.3/net/ipv6/tcp_ipv6.c
25479 --- linux-3.5.4/net/ipv6/tcp_ipv6.c     2012-07-22 23:39:48.000000000 +0200
25480 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/tcp_ipv6.c   2012-07-23 01:45:56.000000000 +0200
25481 @@ -71,6 +71,7 @@
25482  
25483  #include <linux/crypto.h>
25484  #include <linux/scatterlist.h>
25485 +#include <linux/vs_inet6.h>
25486  
25487  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25488  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25489 @@ -163,8 +164,15 @@ static int tcp_v6_connect(struct sock *s
25490          *      connect() to INADDR_ANY means loopback (BSD'ism).
25491          */
25492  
25493 -       if(ipv6_addr_any(&usin->sin6_addr))
25494 -               usin->sin6_addr.s6_addr[15] = 0x1;
25495 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25496 +               struct nx_info *nxi =  sk->sk_nx_info;
25497 +
25498 +               if (nxi && nx_info_has_v6(nxi))
25499 +                       /* FIXME: remap lback? */
25500 +                       usin->sin6_addr = nxi->v6.ip;
25501 +               else
25502 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25503 +       }
25504  
25505         addr_type = ipv6_addr_type(&usin->sin6_addr);
25506  
25507 diff -NurpP --minimal linux-3.5.4/net/ipv6/udp.c linux-3.5.4-vs2.3.4.3/net/ipv6/udp.c
25508 --- linux-3.5.4/net/ipv6/udp.c  2012-07-22 23:39:48.000000000 +0200
25509 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/udp.c        2012-07-23 01:45:56.000000000 +0200
25510 @@ -45,41 +45,67 @@
25511  #include <net/tcp_states.h>
25512  #include <net/ip6_checksum.h>
25513  #include <net/xfrm.h>
25514 +#include <linux/vs_inet6.h>
25515  
25516  #include <linux/proc_fs.h>
25517  #include <linux/seq_file.h>
25518  #include "udp_impl.h"
25519  
25520 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25521 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25522  {
25523 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25524 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25525         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25526 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25527 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25528         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25529 -       int sk_ipv6only = ipv6_only_sock(sk);
25530 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25531         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25532 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25533 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25534         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25535  
25536         /* if both are mapped, treat as IPv4 */
25537 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25538 -               return (!sk2_ipv6only &&
25539 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25540 +               if (!sk2_ipv6only &&
25541                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25542 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25543 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25544 +                       goto vs_v4;
25545 +               else
25546 +                       return 0;
25547 +       }
25548  
25549         if (addr_type2 == IPV6_ADDR_ANY &&
25550             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25551 -               return 1;
25552 +               goto vs;
25553  
25554         if (addr_type == IPV6_ADDR_ANY &&
25555 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25556 -               return 1;
25557 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25558 +               goto vs;
25559  
25560         if (sk2_rcv_saddr6 &&
25561 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25562 -               return 1;
25563 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25564 +               goto vs;
25565  
25566         return 0;
25567 +
25568 +vs_v4:
25569 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25570 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25571 +       if (!sk2_rcv_saddr)
25572 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25573 +       if (!sk1_rcv_saddr)
25574 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25575 +       return 1;
25576 +vs:
25577 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25578 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25579 +       else if (addr_type2 == IPV6_ADDR_ANY)
25580 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25581 +       else if (addr_type == IPV6_ADDR_ANY) {
25582 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25583 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25584 +               else
25585 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25586 +       }
25587 +       return 1;
25588  }
25589  
25590  static unsigned int udp6_portaddr_hash(struct net *net,
25591 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25592                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25593                                 return -1;
25594                         score++;
25595 +               } else {
25596 +                       /* block non nx_info ips */
25597 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25598 +                               return -1;
25599                 }
25600                 if (!ipv6_addr_any(&np->daddr)) {
25601                         if (!ipv6_addr_equal(&np->daddr, saddr))
25602 diff -NurpP --minimal linux-3.5.4/net/ipv6/xfrm6_policy.c linux-3.5.4-vs2.3.4.3/net/ipv6/xfrm6_policy.c
25603 --- linux-3.5.4/net/ipv6/xfrm6_policy.c 2012-07-22 23:39:48.000000000 +0200
25604 +++ linux-3.5.4-vs2.3.4.3/net/ipv6/xfrm6_policy.c       2012-07-23 01:45:56.000000000 +0200
25605 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25606         dev = ip6_dst_idev(dst)->dev;
25607         ipv6_dev_get_saddr(dev_net(dev), dev,
25608                            (struct in6_addr *)&daddr->a6, 0,
25609 -                          (struct in6_addr *)&saddr->a6);
25610 +                          (struct in6_addr *)&saddr->a6, NULL);
25611         dst_release(dst);
25612         return 0;
25613  }
25614 diff -NurpP --minimal linux-3.5.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.5.4-vs2.3.4.3/net/netfilter/ipvs/ip_vs_xmit.c
25615 --- linux-3.5.4/net/netfilter/ipvs/ip_vs_xmit.c 2012-03-19 19:47:33.000000000 +0100
25616 +++ linux-3.5.4-vs2.3.4.3/net/netfilter/ipvs/ip_vs_xmit.c       2012-07-23 01:45:56.000000000 +0200
25617 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25618                 return dst;
25619         if (ipv6_addr_any(&fl6.saddr) &&
25620             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25621 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25622 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25623                 goto out_err;
25624         if (do_xfrm) {
25625                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25626 diff -NurpP --minimal linux-3.5.4/net/netlink/af_netlink.c linux-3.5.4-vs2.3.4.3/net/netlink/af_netlink.c
25627 --- linux-3.5.4/net/netlink/af_netlink.c        2012-07-22 23:39:48.000000000 +0200
25628 +++ linux-3.5.4-vs2.3.4.3/net/netlink/af_netlink.c      2012-07-23 01:45:56.000000000 +0200
25629 @@ -55,6 +55,9 @@
25630  #include <linux/types.h>
25631  #include <linux/audit.h>
25632  #include <linux/mutex.h>
25633 +#include <linux/vs_context.h>
25634 +#include <linux/vs_network.h>
25635 +#include <linux/vs_limit.h>
25636  
25637  #include <net/net_namespace.h>
25638  #include <net/sock.h>
25639 @@ -1935,6 +1938,8 @@ static struct sock *netlink_seq_socket_i
25640                         sk_for_each(s, node, &hash->table[j]) {
25641                                 if (sock_net(s) != seq_file_net(seq))
25642                                         continue;
25643 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25644 +                                       continue;
25645                                 if (off == pos) {
25646                                         iter->link = i;
25647                                         iter->hash_idx = j;
25648 @@ -1969,7 +1974,8 @@ static void *netlink_seq_next(struct seq
25649         s = v;
25650         do {
25651                 s = sk_next(s);
25652 -       } while (s && sock_net(s) != seq_file_net(seq));
25653 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25654 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25655         if (s)
25656                 return s;
25657  
25658 @@ -1981,7 +1987,8 @@ static void *netlink_seq_next(struct seq
25659  
25660                 for (; j <= hash->mask; j++) {
25661                         s = sk_head(&hash->table[j]);
25662 -                       while (s && sock_net(s) != seq_file_net(seq))
25663 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25664 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25665                                 s = sk_next(s);
25666                         if (s) {
25667                                 iter->link = i;
25668 diff -NurpP --minimal linux-3.5.4/net/socket.c linux-3.5.4-vs2.3.4.3/net/socket.c
25669 --- linux-3.5.4/net/socket.c    2012-09-16 20:46:31.000000000 +0200
25670 +++ linux-3.5.4-vs2.3.4.3/net/socket.c  2012-09-16 20:50:19.000000000 +0200
25671 @@ -98,6 +98,10 @@
25672  
25673  #include <net/sock.h>
25674  #include <linux/netfilter.h>
25675 +#include <linux/vs_base.h>
25676 +#include <linux/vs_socket.h>
25677 +#include <linux/vs_inet.h>
25678 +#include <linux/vs_inet6.h>
25679  
25680  #include <linux/if_tun.h>
25681  #include <linux/ipv6_route.h>
25682 @@ -551,6 +555,7 @@ static inline int __sock_sendmsg_nosec(s
25683                                        struct msghdr *msg, size_t size)
25684  {
25685         struct sock_iocb *si = kiocb_to_siocb(iocb);
25686 +       size_t len;
25687  
25688         sock_update_classid(sock->sk);
25689  
25690 @@ -561,7 +566,22 @@ static inline int __sock_sendmsg_nosec(s
25691         si->msg = msg;
25692         si->size = size;
25693  
25694 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25695 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25696 +       if (sock->sk) {
25697 +               if (len == size)
25698 +                       vx_sock_send(sock->sk, size);
25699 +               else
25700 +                       vx_sock_fail(sock->sk, size);
25701 +       }
25702 +       vxdprintk(VXD_CBIT(net, 7),
25703 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25704 +               sock, sock->sk,
25705 +               (sock->sk)?sock->sk->sk_nx_info:0,
25706 +               (sock->sk)?sock->sk->sk_vx_info:0,
25707 +               (sock->sk)?sock->sk->sk_xid:0,
25708 +               (sock->sk)?sock->sk->sk_nid:0,
25709 +               (unsigned int)size, len);
25710 +       return len;
25711  }
25712  
25713  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25714 @@ -717,6 +737,7 @@ static inline int __sock_recvmsg_nosec(s
25715                                        struct msghdr *msg, size_t size, int flags)
25716  {
25717         struct sock_iocb *si = kiocb_to_siocb(iocb);
25718 +       int len;
25719  
25720         sock_update_classid(sock->sk);
25721  
25722 @@ -726,7 +747,18 @@ static inline int __sock_recvmsg_nosec(s
25723         si->size = size;
25724         si->flags = flags;
25725  
25726 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25727 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25728 +       if ((len >= 0) && sock->sk)
25729 +               vx_sock_recv(sock->sk, len);
25730 +       vxdprintk(VXD_CBIT(net, 7),
25731 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25732 +               sock, sock->sk,
25733 +               (sock->sk)?sock->sk->sk_nx_info:0,
25734 +               (sock->sk)?sock->sk->sk_vx_info:0,
25735 +               (sock->sk)?sock->sk->sk_xid:0,
25736 +               (sock->sk)?sock->sk->sk_nid:0,
25737 +               (unsigned int)size, len);
25738 +       return len;
25739  }
25740  
25741  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25742 @@ -1211,6 +1243,13 @@ int __sock_create(struct net *net, int f
25743         if (type < 0 || type >= SOCK_MAX)
25744                 return -EINVAL;
25745  
25746 +       if (!nx_check(0, VS_ADMIN)) {
25747 +               if (family == PF_INET && !current_nx_info_has_v4())
25748 +                       return -EAFNOSUPPORT;
25749 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25750 +                       return -EAFNOSUPPORT;
25751 +       }
25752 +
25753         /* Compatibility.
25754  
25755            This uglymoron is moved from INET layer to here to avoid
25756 @@ -1345,6 +1384,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25757         if (retval < 0)
25758                 goto out;
25759  
25760 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25761         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25762         if (retval < 0)
25763                 goto out_release;
25764 @@ -1386,10 +1426,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25765         err = sock_create(family, type, protocol, &sock1);
25766         if (err < 0)
25767                 goto out;
25768 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25769  
25770         err = sock_create(family, type, protocol, &sock2);
25771         if (err < 0)
25772                 goto out_release_1;
25773 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25774  
25775         err = sock1->ops->socketpair(sock1, sock2);
25776         if (err < 0)
25777 diff -NurpP --minimal linux-3.5.4/net/sunrpc/auth.c linux-3.5.4-vs2.3.4.3/net/sunrpc/auth.c
25778 --- linux-3.5.4/net/sunrpc/auth.c       2011-10-24 18:45:34.000000000 +0200
25779 +++ linux-3.5.4-vs2.3.4.3/net/sunrpc/auth.c     2012-07-23 01:45:56.000000000 +0200
25780 @@ -14,6 +14,7 @@
25781  #include <linux/hash.h>
25782  #include <linux/sunrpc/clnt.h>
25783  #include <linux/spinlock.h>
25784 +#include <linux/vs_tag.h>
25785  
25786  #ifdef RPC_DEBUG
25787  # define RPCDBG_FACILITY       RPCDBG_AUTH
25788 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25789         memset(&acred, 0, sizeof(acred));
25790         acred.uid = cred->fsuid;
25791         acred.gid = cred->fsgid;
25792 +       acred.tag = dx_current_tag();
25793         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25794  
25795         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25796 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25797         struct auth_cred acred = {
25798                 .uid = 0,
25799                 .gid = 0,
25800 +               .tag = dx_current_tag(),
25801         };
25802  
25803         dprintk("RPC: %5u looking up %s cred\n",
25804 diff -NurpP --minimal linux-3.5.4/net/sunrpc/auth_unix.c linux-3.5.4-vs2.3.4.3/net/sunrpc/auth_unix.c
25805 --- linux-3.5.4/net/sunrpc/auth_unix.c  2012-07-22 23:39:49.000000000 +0200
25806 +++ linux-3.5.4-vs2.3.4.3/net/sunrpc/auth_unix.c        2012-07-23 10:26:39.000000000 +0200
25807 @@ -13,11 +13,13 @@
25808  #include <linux/sunrpc/clnt.h>
25809  #include <linux/sunrpc/auth.h>
25810  #include <linux/user_namespace.h>
25811 +#include <linux/vs_tag.h>
25812  
25813  #define NFS_NGROUPS    16
25814  
25815  struct unx_cred {
25816         struct rpc_cred         uc_base;
25817 +       tag_t                   uc_tag;
25818         gid_t                   uc_gid;
25819         gid_t                   uc_gids[NFS_NGROUPS];
25820  };
25821 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25822                 groups = NFS_NGROUPS;
25823  
25824         cred->uc_gid = acred->gid;
25825 +       cred->uc_tag = acred->tag;
25826         for (i = 0; i < groups; i++) {
25827                 gid_t gid;
25828                 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
25829 @@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
25830         unsigned int i;
25831  
25832  
25833 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25834 +       if (cred->uc_uid != acred->uid ||
25835 +               cred->uc_gid != acred->gid ||
25836 +               cred->uc_tag != acred->tag)
25837                 return 0;
25838  
25839         if (acred->group_info != NULL)
25840 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
25841         struct rpc_clnt *clnt = task->tk_client;
25842         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25843         __be32          *base, *hold;
25844 -       int             i;
25845 +       int             i, tag;
25846  
25847         *p++ = htonl(RPC_AUTH_UNIX);
25848         base = p++;
25849 @@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
25850          * Copy the UTS nodename captured when the client was created.
25851          */
25852         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25853 +       tag = task->tk_client->cl_tag;
25854  
25855 -       *p++ = htonl((u32) cred->uc_uid);
25856 -       *p++ = htonl((u32) cred->uc_gid);
25857 +       *p++ = htonl((u32) TAGINO_UID(tag,
25858 +               cred->uc_uid, cred->uc_tag));
25859 +       *p++ = htonl((u32) TAGINO_GID(tag,
25860 +               cred->uc_gid, cred->uc_tag));
25861         hold = p++;
25862         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25863                 *p++ = htonl((u32) cred->uc_gids[i]);
25864 diff -NurpP --minimal linux-3.5.4/net/sunrpc/clnt.c linux-3.5.4-vs2.3.4.3/net/sunrpc/clnt.c
25865 --- linux-3.5.4/net/sunrpc/clnt.c       2012-09-16 20:46:31.000000000 +0200
25866 +++ linux-3.5.4-vs2.3.4.3/net/sunrpc/clnt.c     2012-08-19 13:28:27.000000000 +0200
25867 @@ -31,6 +31,7 @@
25868  #include <linux/in6.h>
25869  #include <linux/un.h>
25870  #include <linux/rcupdate.h>
25871 +#include <linux/vs_cvirt.h>
25872  
25873  #include <linux/sunrpc/clnt.h>
25874  #include <linux/sunrpc/rpc_pipe_fs.h>
25875 @@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25876         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25877                 clnt->cl_chatty = 1;
25878  
25879 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25880 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25881 +               clnt->cl_tag = 1; */
25882         return clnt;
25883  }
25884  EXPORT_SYMBOL_GPL(rpc_create);
25885 diff -NurpP --minimal linux-3.5.4/net/unix/af_unix.c linux-3.5.4-vs2.3.4.3/net/unix/af_unix.c
25886 --- linux-3.5.4/net/unix/af_unix.c      2012-07-22 23:39:49.000000000 +0200
25887 +++ linux-3.5.4-vs2.3.4.3/net/unix/af_unix.c    2012-07-23 01:45:56.000000000 +0200
25888 @@ -114,6 +114,8 @@
25889  #include <linux/mount.h>
25890  #include <net/checksum.h>
25891  #include <linux/security.h>
25892 +#include <linux/vs_context.h>
25893 +#include <linux/vs_limit.h>
25894  
25895  struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
25896  EXPORT_SYMBOL_GPL(unix_socket_table);
25897 @@ -262,6 +264,8 @@ static struct sock *__unix_find_socket_b
25898                 if (!net_eq(sock_net(s), net))
25899                         continue;
25900  
25901 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25902 +                       continue;
25903                 if (u->addr->len == len &&
25904                     !memcmp(u->addr->name, sunname, len))
25905                         goto found;
25906 @@ -2276,6 +2280,8 @@ static struct sock *unix_seq_idx(struct 
25907         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
25908                 if (sock_net(s) != seq_file_net(seq))
25909                         continue;
25910 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25911 +                       continue;
25912                 if (off == pos)
25913                         return s;
25914                 ++off;
25915 @@ -2300,7 +2306,8 @@ static void *unix_seq_next(struct seq_fi
25916                 sk = first_unix_socket(&iter->i);
25917         else
25918                 sk = next_unix_socket(&iter->i, sk);
25919 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
25920 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
25921 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
25922                 sk = next_unix_socket(&iter->i, sk);
25923         return sk;
25924  }
25925 diff -NurpP --minimal linux-3.5.4/scripts/checksyscalls.sh linux-3.5.4-vs2.3.4.3/scripts/checksyscalls.sh
25926 --- linux-3.5.4/scripts/checksyscalls.sh        2012-03-19 19:47:34.000000000 +0100
25927 +++ linux-3.5.4-vs2.3.4.3/scripts/checksyscalls.sh      2012-07-23 01:45:56.000000000 +0200
25928 @@ -193,7 +193,6 @@ cat << EOF
25929  #define __IGNORE_afs_syscall
25930  #define __IGNORE_getpmsg
25931  #define __IGNORE_putpmsg
25932 -#define __IGNORE_vserver
25933  EOF
25934  }
25935  
25936 diff -NurpP --minimal linux-3.5.4/security/commoncap.c linux-3.5.4-vs2.3.4.3/security/commoncap.c
25937 --- linux-3.5.4/security/commoncap.c    2012-07-22 23:39:51.000000000 +0200
25938 +++ linux-3.5.4-vs2.3.4.3/security/commoncap.c  2012-07-23 11:05:45.000000000 +0200
25939 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
25940  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25941                 int cap, int audit)
25942  {
25943 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25944 +
25945         for (;;) {
25946                 /* The owner of the user namespace has all caps. */
25947                 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
25948                         return 0;
25949  
25950                 /* Do we have the necessary capabilities? */
25951 -               if (targ_ns == cred->user_ns)
25952 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25953 +               if (targ_ns == cred->user_ns) {
25954 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25955 +                           cap_raised(cred->cap_effective, cap))
25956 +                               return 0;
25957 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25958 +               }
25959  
25960                 /* Have we tried all of the parent namespaces? */
25961                 if (targ_ns == &init_user_ns)
25962 @@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
25963  
25964         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25965                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25966 -           !capable(CAP_SYS_ADMIN))
25967 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25968                 return -EPERM;
25969         return 0;
25970  }
25971 @@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry 
25972  
25973         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25974                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25975 -           !capable(CAP_SYS_ADMIN))
25976 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25977                 return -EPERM;
25978         return 0;
25979  }
25980 diff -NurpP --minimal linux-3.5.4/security/selinux/hooks.c linux-3.5.4-vs2.3.4.3/security/selinux/hooks.c
25981 --- linux-3.5.4/security/selinux/hooks.c        2012-09-16 20:46:31.000000000 +0200
25982 +++ linux-3.5.4-vs2.3.4.3/security/selinux/hooks.c      2012-08-19 13:28:27.000000000 +0200
25983 @@ -66,7 +66,6 @@
25984  #include <linux/dccp.h>
25985  #include <linux/quota.h>
25986  #include <linux/un.h>          /* for Unix socket types */
25987 -#include <net/af_unix.h>       /* for Unix socket types */
25988  #include <linux/parser.h>
25989  #include <linux/nfs_mount.h>
25990  #include <net/ipv6.h>
This page took 2.238415 seconds and 4 git commands to generate.