]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- 3.4.83
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.4.83/Documentation/vserver/debug.txt linux-3.4.83-vs2.3.3.9/Documentation/vserver/debug.txt
2 --- linux-3.4.83/Documentation/vserver/debug.txt        1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.4.83-vs2.3.3.9/Documentation/vserver/debug.txt      2012-05-21 16:15:04.000000000 +0000
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.4.83/arch/alpha/Kconfig linux-3.4.83-vs2.3.3.9/arch/alpha/Kconfig
160 --- linux-3.4.83/arch/alpha/Kconfig     2012-05-21 16:06:12.000000000 +0000
161 +++ linux-3.4.83-vs2.3.3.9/arch/alpha/Kconfig   2012-05-21 16:15:04.000000000 +0000
162 @@ -662,6 +662,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.4.83/arch/alpha/kernel/entry.S linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/entry.S
172 --- linux-3.4.83/arch/alpha/kernel/entry.S      2010-10-21 11:06:45.000000000 +0000
173 +++ linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/entry.S    2012-05-21 16:15:04.000000000 +0000
174 @@ -860,24 +860,15 @@ sys_getxgid:
175         .globl  sys_getxpid
176         .ent    sys_getxpid
177  sys_getxpid:
178 +       lda     $sp, -16($sp)
179 +       stq     $26, 0($sp)
180         .prologue 0
181 -       ldq     $2, TI_TASK($8)
182  
183 -       /* See linux/kernel/timer.c sys_getppid for discussion
184 -          about this loop.  */
185 -       ldq     $3, TASK_GROUP_LEADER($2)
186 -       ldq     $4, TASK_REAL_PARENT($3)
187 -       ldl     $0, TASK_TGID($2)
188 -1:     ldl     $1, TASK_TGID($4)
189 -#ifdef CONFIG_SMP
190 -       mov     $4, $5
191 -       mb
192 -       ldq     $3, TASK_GROUP_LEADER($2)
193 -       ldq     $4, TASK_REAL_PARENT($3)
194 -       cmpeq   $4, $5, $5
195 -       beq     $5, 1b
196 -#endif
197 -       stq     $1, 80($sp)
198 +       lda     $16, 96($sp)
199 +       jsr     $26, do_getxpid
200 +       ldq     $26, 0($sp)
201 +
202 +       lda     $sp, 16($sp)
203         ret
204  .end sys_getxpid
205  
206 diff -NurpP --minimal linux-3.4.83/arch/alpha/kernel/ptrace.c linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/ptrace.c
207 --- linux-3.4.83/arch/alpha/kernel/ptrace.c     2012-05-21 16:06:12.000000000 +0000
208 +++ linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/ptrace.c   2012-05-21 16:15:04.000000000 +0000
209 @@ -13,6 +13,7 @@
210  #include <linux/user.h>
211  #include <linux/security.h>
212  #include <linux/signal.h>
213 +#include <linux/vs_base.h>
214  
215  #include <asm/uaccess.h>
216  #include <asm/pgtable.h>
217 diff -NurpP --minimal linux-3.4.83/arch/alpha/kernel/systbls.S linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/systbls.S
218 --- linux-3.4.83/arch/alpha/kernel/systbls.S    2012-01-09 15:13:54.000000000 +0000
219 +++ linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/systbls.S  2012-05-21 16:15:04.000000000 +0000
220 @@ -446,7 +446,7 @@ sys_call_table:
221         .quad sys_stat64                        /* 425 */
222         .quad sys_lstat64
223         .quad sys_fstat64
224 -       .quad sys_ni_syscall                    /* sys_vserver */
225 +       .quad sys_vserver                       /* sys_vserver */
226         .quad sys_ni_syscall                    /* sys_mbind */
227         .quad sys_ni_syscall                    /* sys_get_mempolicy */
228         .quad sys_ni_syscall                    /* sys_set_mempolicy */
229 diff -NurpP --minimal linux-3.4.83/arch/alpha/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/traps.c
230 --- linux-3.4.83/arch/alpha/kernel/traps.c      2012-05-21 16:06:12.000000000 +0000
231 +++ linux-3.4.83-vs2.3.3.9/arch/alpha/kernel/traps.c    2012-05-21 16:15:04.000000000 +0000
232 @@ -184,7 +184,8 @@ die_if_kernel(char * str, struct pt_regs
233  #ifdef CONFIG_SMP
234         printk("CPU %d ", hard_smp_processor_id());
235  #endif
236 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
237 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
238 +               task_pid_nr(current), current->xid, str, err);
239         dik_show_regs(regs, r9_15);
240         add_taint(TAINT_DIE);
241         dik_show_trace((unsigned long *)(regs+1));
242 diff -NurpP --minimal linux-3.4.83/arch/arm/Kconfig linux-3.4.83-vs2.3.3.9/arch/arm/Kconfig
243 --- linux-3.4.83/arch/arm/Kconfig       2014-03-12 09:47:43.000000000 +0000
244 +++ linux-3.4.83-vs2.3.3.9/arch/arm/Kconfig     2012-12-11 11:42:38.000000000 +0000
245 @@ -2311,6 +2311,8 @@ source "fs/Kconfig"
246  
247  source "arch/arm/Kconfig.debug"
248  
249 +source "kernel/vserver/Kconfig"
250 +
251  source "security/Kconfig"
252  
253  source "crypto/Kconfig"
254 diff -NurpP --minimal linux-3.4.83/arch/arm/kernel/calls.S linux-3.4.83-vs2.3.3.9/arch/arm/kernel/calls.S
255 --- linux-3.4.83/arch/arm/kernel/calls.S        2012-01-09 15:13:54.000000000 +0000
256 +++ linux-3.4.83-vs2.3.3.9/arch/arm/kernel/calls.S      2012-05-21 16:15:04.000000000 +0000
257 @@ -322,7 +322,7 @@
258  /* 310 */      CALL(sys_request_key)
259                 CALL(sys_keyctl)
260                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
261 -/* vserver */  CALL(sys_ni_syscall)
262 +               CALL(sys_vserver)
263                 CALL(sys_ioprio_set)
264  /* 315 */      CALL(sys_ioprio_get)
265                 CALL(sys_inotify_init)
266 diff -NurpP --minimal linux-3.4.83/arch/arm/kernel/process.c linux-3.4.83-vs2.3.3.9/arch/arm/kernel/process.c
267 --- linux-3.4.83/arch/arm/kernel/process.c      2014-03-12 09:47:43.000000000 +0000
268 +++ linux-3.4.83-vs2.3.3.9/arch/arm/kernel/process.c    2014-03-12 09:55:28.000000000 +0000
269 @@ -357,7 +357,8 @@ void __show_regs(struct pt_regs *regs)
270  void show_regs(struct pt_regs * regs)
271  {
272         printk("\n");
273 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
274 +       printk("Pid: %d[#%u], comm: %20s\n",
275 +               task_pid_nr(current), current->xid, current->comm);
276         __show_regs(regs);
277         dump_stack();
278  }
279 diff -NurpP --minimal linux-3.4.83/arch/arm/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/arm/kernel/traps.c
280 --- linux-3.4.83/arch/arm/kernel/traps.c        2014-03-12 09:47:43.000000000 +0000
281 +++ linux-3.4.83-vs2.3.3.9/arch/arm/kernel/traps.c      2014-03-12 09:55:28.000000000 +0000
282 @@ -255,8 +255,8 @@ static int __die(const char *str, int er
283  
284         print_modules();
285         __show_regs(regs);
286 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
287 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
288 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
289 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
290  
291         if (!user_mode(regs) || in_interrupt()) {
292                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
293 diff -NurpP --minimal linux-3.4.83/arch/cris/Kconfig linux-3.4.83-vs2.3.3.9/arch/cris/Kconfig
294 --- linux-3.4.83/arch/cris/Kconfig      2012-03-19 18:46:39.000000000 +0000
295 +++ linux-3.4.83-vs2.3.3.9/arch/cris/Kconfig    2012-05-21 16:15:04.000000000 +0000
296 @@ -675,6 +675,8 @@ source "drivers/staging/Kconfig"
297  
298  source "arch/cris/Kconfig.debug"
299  
300 +source "kernel/vserver/Kconfig"
301 +
302  source "security/Kconfig"
303  
304  source "crypto/Kconfig"
305 diff -NurpP --minimal linux-3.4.83/arch/frv/kernel/kernel_thread.S linux-3.4.83-vs2.3.3.9/arch/frv/kernel/kernel_thread.S
306 --- linux-3.4.83/arch/frv/kernel/kernel_thread.S        2008-12-24 23:26:37.000000000 +0000
307 +++ linux-3.4.83-vs2.3.3.9/arch/frv/kernel/kernel_thread.S      2012-05-21 16:15:04.000000000 +0000
308 @@ -37,7 +37,7 @@ kernel_thread:
309  
310         # start by forking the current process, but with shared VM
311         setlos.p        #__NR_clone,gr7         ; syscall number
312 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
313 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
314         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
315         setlo           #0xe4e4,gr9
316         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
317 diff -NurpP --minimal linux-3.4.83/arch/h8300/Kconfig linux-3.4.83-vs2.3.3.9/arch/h8300/Kconfig
318 --- linux-3.4.83/arch/h8300/Kconfig     2012-03-19 18:46:39.000000000 +0000
319 +++ linux-3.4.83-vs2.3.3.9/arch/h8300/Kconfig   2012-05-21 16:15:04.000000000 +0000
320 @@ -214,6 +214,8 @@ source "fs/Kconfig"
321  
322  source "arch/h8300/Kconfig.debug"
323  
324 +source "kernel/vserver/Kconfig"
325 +
326  source "security/Kconfig"
327  
328  source "crypto/Kconfig"
329 diff -NurpP --minimal linux-3.4.83/arch/ia64/Kconfig linux-3.4.83-vs2.3.3.9/arch/ia64/Kconfig
330 --- linux-3.4.83/arch/ia64/Kconfig      2012-03-19 18:46:39.000000000 +0000
331 +++ linux-3.4.83-vs2.3.3.9/arch/ia64/Kconfig    2012-05-21 16:15:04.000000000 +0000
332 @@ -654,6 +654,8 @@ source "fs/Kconfig"
333  
334  source "arch/ia64/Kconfig.debug"
335  
336 +source "kernel/vserver/Kconfig"
337 +
338  source "security/Kconfig"
339  
340  source "crypto/Kconfig"
341 diff -NurpP --minimal linux-3.4.83/arch/ia64/kernel/entry.S linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/entry.S
342 --- linux-3.4.83/arch/ia64/kernel/entry.S       2012-03-19 18:46:40.000000000 +0000
343 +++ linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/entry.S     2012-05-21 16:15:04.000000000 +0000
344 @@ -1714,7 +1714,7 @@ sys_call_table:
345         data8 sys_mq_notify
346         data8 sys_mq_getsetattr
347         data8 sys_kexec_load
348 -       data8 sys_ni_syscall                    // reserved for vserver
349 +       data8 sys_vserver
350         data8 sys_waitid                        // 1270
351         data8 sys_add_key
352         data8 sys_request_key
353 diff -NurpP --minimal linux-3.4.83/arch/ia64/kernel/process.c linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/process.c
354 --- linux-3.4.83/arch/ia64/kernel/process.c     2014-03-12 09:47:44.000000000 +0000
355 +++ linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/process.c   2012-10-22 13:09:53.000000000 +0000
356 @@ -111,8 +111,8 @@ show_regs (struct pt_regs *regs)
357         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
358  
359         print_modules();
360 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
361 -                       smp_processor_id(), current->comm);
362 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
363 +                       current->xid, smp_processor_id(), current->comm);
364         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
365                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
366                init_utsname()->release);
367 diff -NurpP --minimal linux-3.4.83/arch/ia64/kernel/ptrace.c linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/ptrace.c
368 --- linux-3.4.83/arch/ia64/kernel/ptrace.c      2012-05-21 16:06:26.000000000 +0000
369 +++ linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/ptrace.c    2012-05-21 16:15:04.000000000 +0000
370 @@ -21,6 +21,7 @@
371  #include <linux/regset.h>
372  #include <linux/elf.h>
373  #include <linux/tracehook.h>
374 +#include <linux/vs_base.h>
375  
376  #include <asm/pgtable.h>
377  #include <asm/processor.h>
378 diff -NurpP --minimal linux-3.4.83/arch/ia64/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/traps.c
379 --- linux-3.4.83/arch/ia64/kernel/traps.c       2012-05-21 16:06:26.000000000 +0000
380 +++ linux-3.4.83-vs2.3.3.9/arch/ia64/kernel/traps.c     2012-05-21 16:15:04.000000000 +0000
381 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
382         put_cpu();
383  
384         if (++die.lock_owner_depth < 3) {
385 -               printk("%s[%d]: %s %ld [%d]\n",
386 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
387 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
388 +                       current->comm, task_pid_nr(current), current->xid,
389 +                       str, err, ++die_counter);
390                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
391                     != NOTIFY_STOP)
392                         show_regs(regs);
393 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
394                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
395                                 last.time = current_jiffies + 5 * HZ;
396                                 printk(KERN_WARNING
397 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
398 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
399 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
400 +                                       current->comm, task_pid_nr(current), current->xid,
401 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
402                         }
403                 }
404         }
405 diff -NurpP --minimal linux-3.4.83/arch/m32r/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/m32r/kernel/traps.c
406 --- linux-3.4.83/arch/m32r/kernel/traps.c       2012-05-21 16:06:26.000000000 +0000
407 +++ linux-3.4.83-vs2.3.3.9/arch/m32r/kernel/traps.c     2012-05-21 16:15:04.000000000 +0000
408 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
409         } else {
410                 printk("SPI: %08lx\n", sp);
411         }
412 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
413 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
414 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
415 +               current->comm, task_pid_nr(current), current->xid,
416 +               0xffff & i, 4096+(unsigned long)current);
417  
418         /*
419          * When in-kernel, we also print out the stack and code at the
420 diff -NurpP --minimal linux-3.4.83/arch/m68k/Kconfig linux-3.4.83-vs2.3.3.9/arch/m68k/Kconfig
421 --- linux-3.4.83/arch/m68k/Kconfig      2012-05-21 16:06:26.000000000 +0000
422 +++ linux-3.4.83-vs2.3.3.9/arch/m68k/Kconfig    2012-05-21 16:15:04.000000000 +0000
423 @@ -146,6 +146,8 @@ source "fs/Kconfig"
424  
425  source "arch/m68k/Kconfig.debug"
426  
427 +source "kernel/vserver/Kconfig"
428 +
429  source "security/Kconfig"
430  
431  source "crypto/Kconfig"
432 diff -NurpP --minimal linux-3.4.83/arch/mips/Kconfig linux-3.4.83-vs2.3.3.9/arch/mips/Kconfig
433 --- linux-3.4.83/arch/mips/Kconfig      2014-03-12 09:47:44.000000000 +0000
434 +++ linux-3.4.83-vs2.3.3.9/arch/mips/Kconfig    2013-10-26 18:10:20.000000000 +0000
435 @@ -2516,6 +2516,8 @@ source "fs/Kconfig"
436  
437  source "arch/mips/Kconfig.debug"
438  
439 +source "kernel/vserver/Kconfig"
440 +
441  source "security/Kconfig"
442  
443  source "crypto/Kconfig"
444 diff -NurpP --minimal linux-3.4.83/arch/mips/kernel/ptrace.c linux-3.4.83-vs2.3.3.9/arch/mips/kernel/ptrace.c
445 --- linux-3.4.83/arch/mips/kernel/ptrace.c      2012-05-21 16:06:27.000000000 +0000
446 +++ linux-3.4.83-vs2.3.3.9/arch/mips/kernel/ptrace.c    2012-05-21 16:15:04.000000000 +0000
447 @@ -25,6 +25,7 @@
448  #include <linux/security.h>
449  #include <linux/audit.h>
450  #include <linux/seccomp.h>
451 +#include <linux/vs_base.h>
452  
453  #include <asm/byteorder.h>
454  #include <asm/cpu.h>
455 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
456         void __user *datavp = (void __user *) data;
457         unsigned long __user *datalp = (void __user *) data;
458  
459 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
460 +               goto out;
461 +
462         switch (request) {
463         /* when I and D space are separate, these will need to be fixed. */
464         case PTRACE_PEEKTEXT: /* read word at location addr. */
465 diff -NurpP --minimal linux-3.4.83/arch/mips/kernel/scall32-o32.S linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall32-o32.S
466 --- linux-3.4.83/arch/mips/kernel/scall32-o32.S 2012-01-09 15:14:05.000000000 +0000
467 +++ linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall32-o32.S       2012-05-21 16:15:04.000000000 +0000
468 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
469         sys     sys_mq_timedreceive     5
470         sys     sys_mq_notify           2       /* 4275 */
471         sys     sys_mq_getsetattr       3
472 -       sys     sys_ni_syscall          0       /* sys_vserver */
473 +       sys     sys_vserver             3
474         sys     sys_waitid              5
475         sys     sys_ni_syscall          0       /* available, was setaltroot */
476         sys     sys_add_key             5       /* 4280 */
477 diff -NurpP --minimal linux-3.4.83/arch/mips/kernel/scall64-64.S linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall64-64.S
478 --- linux-3.4.83/arch/mips/kernel/scall64-64.S  2012-01-09 15:14:05.000000000 +0000
479 +++ linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall64-64.S        2012-05-21 16:15:04.000000000 +0000
480 @@ -362,7 +362,7 @@ sys_call_table:
481         PTR     sys_mq_timedreceive
482         PTR     sys_mq_notify
483         PTR     sys_mq_getsetattr               /* 5235 */
484 -       PTR     sys_ni_syscall                  /* sys_vserver */
485 +       PTR     sys_vserver
486         PTR     sys_waitid
487         PTR     sys_ni_syscall                  /* available, was setaltroot */
488         PTR     sys_add_key
489 diff -NurpP --minimal linux-3.4.83/arch/mips/kernel/scall64-n32.S linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall64-n32.S
490 --- linux-3.4.83/arch/mips/kernel/scall64-n32.S 2012-01-09 15:14:05.000000000 +0000
491 +++ linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall64-n32.S       2012-05-21 16:15:04.000000000 +0000
492 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
493         PTR     compat_sys_mq_timedreceive
494         PTR     compat_sys_mq_notify
495         PTR     compat_sys_mq_getsetattr
496 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
497 +       PTR     sys32_vserver                   /* 6240 */
498         PTR     compat_sys_waitid
499         PTR     sys_ni_syscall                  /* available, was setaltroot */
500         PTR     sys_add_key
501 diff -NurpP --minimal linux-3.4.83/arch/mips/kernel/scall64-o32.S linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall64-o32.S
502 --- linux-3.4.83/arch/mips/kernel/scall64-o32.S 2012-01-09 15:14:05.000000000 +0000
503 +++ linux-3.4.83-vs2.3.3.9/arch/mips/kernel/scall64-o32.S       2012-05-21 16:15:04.000000000 +0000
504 @@ -480,7 +480,7 @@ sys_call_table:
505         PTR     compat_sys_mq_timedreceive
506         PTR     compat_sys_mq_notify            /* 4275 */
507         PTR     compat_sys_mq_getsetattr
508 -       PTR     sys_ni_syscall                  /* sys_vserver */
509 +       PTR     sys32_vserver
510         PTR     sys_32_waitid
511         PTR     sys_ni_syscall                  /* available, was setaltroot */
512         PTR     sys_add_key                     /* 4280 */
513 diff -NurpP --minimal linux-3.4.83/arch/mips/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/mips/kernel/traps.c
514 --- linux-3.4.83/arch/mips/kernel/traps.c       2012-05-21 16:06:27.000000000 +0000
515 +++ linux-3.4.83-vs2.3.3.9/arch/mips/kernel/traps.c     2012-05-21 16:15:04.000000000 +0000
516 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
517  
518         __show_regs(regs);
519         print_modules();
520 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
521 -              current->comm, current->pid, current_thread_info(), current,
522 -             field, current_thread_info()->tp_value);
523 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
524 +               current->comm, task_pid_nr(current), current->xid,
525 +               current_thread_info(), current,
526 +               field, current_thread_info()->tp_value);
527         if (cpu_has_userlocal) {
528                 unsigned long tls;
529  
530 diff -NurpP --minimal linux-3.4.83/arch/parisc/Kconfig linux-3.4.83-vs2.3.3.9/arch/parisc/Kconfig
531 --- linux-3.4.83/arch/parisc/Kconfig    2012-03-19 18:46:44.000000000 +0000
532 +++ linux-3.4.83-vs2.3.3.9/arch/parisc/Kconfig  2012-05-21 16:15:04.000000000 +0000
533 @@ -279,6 +279,8 @@ source "fs/Kconfig"
534  
535  source "arch/parisc/Kconfig.debug"
536  
537 +source "kernel/vserver/Kconfig"
538 +
539  source "security/Kconfig"
540  
541  source "crypto/Kconfig"
542 diff -NurpP --minimal linux-3.4.83/arch/parisc/kernel/syscall_table.S linux-3.4.83-vs2.3.3.9/arch/parisc/kernel/syscall_table.S
543 --- linux-3.4.83/arch/parisc/kernel/syscall_table.S     2011-10-24 16:45:00.000000000 +0000
544 +++ linux-3.4.83-vs2.3.3.9/arch/parisc/kernel/syscall_table.S   2012-05-21 16:15:04.000000000 +0000
545 @@ -361,7 +361,7 @@
546         ENTRY_COMP(mbind)               /* 260 */
547         ENTRY_COMP(get_mempolicy)
548         ENTRY_COMP(set_mempolicy)
549 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
550 +       ENTRY_DIFF(vserver)
551         ENTRY_SAME(add_key)
552         ENTRY_SAME(request_key)         /* 265 */
553         ENTRY_SAME(keyctl)
554 diff -NurpP --minimal linux-3.4.83/arch/parisc/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/parisc/kernel/traps.c
555 --- linux-3.4.83/arch/parisc/kernel/traps.c     2014-03-12 09:47:45.000000000 +0000
556 +++ linux-3.4.83-vs2.3.3.9/arch/parisc/kernel/traps.c   2013-10-26 18:10:20.000000000 +0000
557 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
558                 if (err == 0)
559                         return; /* STFU */
560  
561 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
562 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
563 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
564 +                       current->comm, task_pid_nr(current), current->xid,
565 +                       str, err, regs->iaoq[0]);
566  #ifdef PRINT_USER_FAULTS
567                 /* XXX for debugging only */
568                 show_regs(regs);
569 @@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
570                 pdc_console_restart();
571         
572         if (err)
573 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
574 -                       current->comm, task_pid_nr(current), str, err);
575 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
576 +                       current->comm, task_pid_nr(current), current->xid, str, err);
577  
578         /* Wot's wrong wif bein' racy? */
579         if (current->thread.flags & PARISC_KERNEL_DEATH) {
580 diff -NurpP --minimal linux-3.4.83/arch/parisc/mm/fault.c linux-3.4.83-vs2.3.3.9/arch/parisc/mm/fault.c
581 --- linux-3.4.83/arch/parisc/mm/fault.c 2010-08-02 14:52:06.000000000 +0000
582 +++ linux-3.4.83-vs2.3.3.9/arch/parisc/mm/fault.c       2012-05-21 16:15:04.000000000 +0000
583 @@ -237,8 +237,9 @@ bad_area:
584  
585  #ifdef PRINT_USER_FAULTS
586                 printk(KERN_DEBUG "\n");
587 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
588 -                   task_pid_nr(tsk), tsk->comm, code, address);
589 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
590 +                   "command='%s' type=%lu address=0x%08lx\n",
591 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
592                 if (vma) {
593                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
594                                         vma->vm_start, vma->vm_end);
595 diff -NurpP --minimal linux-3.4.83/arch/powerpc/Kconfig linux-3.4.83-vs2.3.3.9/arch/powerpc/Kconfig
596 --- linux-3.4.83/arch/powerpc/Kconfig   2014-03-12 09:47:45.000000000 +0000
597 +++ linux-3.4.83-vs2.3.3.9/arch/powerpc/Kconfig 2013-10-26 18:10:20.000000000 +0000
598 @@ -1003,6 +1003,8 @@ source "lib/Kconfig"
599  
600  source "arch/powerpc/Kconfig.debug"
601  
602 +source "kernel/vserver/Kconfig"
603 +
604  source "security/Kconfig"
605  
606  config KEYS_COMPAT
607 diff -NurpP --minimal linux-3.4.83/arch/powerpc/include/asm/unistd.h linux-3.4.83-vs2.3.3.9/arch/powerpc/include/asm/unistd.h
608 --- linux-3.4.83/arch/powerpc/include/asm/unistd.h      2012-01-09 15:14:05.000000000 +0000
609 +++ linux-3.4.83-vs2.3.3.9/arch/powerpc/include/asm/unistd.h    2012-05-21 16:15:04.000000000 +0000
610 @@ -275,7 +275,7 @@
611  #endif
612  #define __NR_rtas              255
613  #define __NR_sys_debug_setcontext 256
614 -/* Number 257 is reserved for vserver */
615 +#define __NR_vserver           257
616  #define __NR_migrate_pages     258
617  #define __NR_mbind             259
618  #define __NR_get_mempolicy     260
619 diff -NurpP --minimal linux-3.4.83/arch/powerpc/kernel/process.c linux-3.4.83-vs2.3.3.9/arch/powerpc/kernel/process.c
620 --- linux-3.4.83/arch/powerpc/kernel/process.c  2014-03-12 09:47:45.000000000 +0000
621 +++ linux-3.4.83-vs2.3.3.9/arch/powerpc/kernel/process.c        2013-07-14 13:38:26.000000000 +0000
622 @@ -661,8 +661,9 @@ void show_regs(struct pt_regs * regs)
623  #else
624                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
625  #endif
626 -       printk("TASK = %p[%d] '%s' THREAD: %p",
627 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
628 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
629 +              current, task_pid_nr(current), current->xid,
630 +              current->comm, task_thread_info(current));
631  
632  #ifdef CONFIG_SMP
633         printk(" CPU: %d", raw_smp_processor_id());
634 diff -NurpP --minimal linux-3.4.83/arch/powerpc/kernel/traps.c linux-3.4.83-vs2.3.3.9/arch/powerpc/kernel/traps.c
635 --- linux-3.4.83/arch/powerpc/kernel/traps.c    2014-03-12 09:47:45.000000000 +0000
636 +++ linux-3.4.83-vs2.3.3.9/arch/powerpc/kernel/traps.c  2013-07-14 13:38:26.000000000 +0000
637 @@ -1125,8 +1125,9 @@ void nonrecoverable_exception(struct pt_
638  
639  void trace_syscall(struct pt_regs *regs)
640  {
641 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
642 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
643 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
644 +              current, task_pid_nr(current), current->xid,
645 +              regs->nip, regs->link, regs->gpr[0],
646                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
647  }
648  
649 diff -NurpP --minimal linux-3.4.83/arch/s390/Kconfig linux-3.4.83-vs2.3.3.9/arch/s390/Kconfig
650 --- linux-3.4.83/arch/s390/Kconfig      2012-05-21 16:06:32.000000000 +0000
651 +++ linux-3.4.83-vs2.3.3.9/arch/s390/Kconfig    2012-05-21 16:15:04.000000000 +0000
652 @@ -639,6 +639,8 @@ source "fs/Kconfig"
653  
654  source "arch/s390/Kconfig.debug"
655  
656 +source "kernel/vserver/Kconfig"
657 +
658  source "security/Kconfig"
659  
660  source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.4.83/arch/s390/include/asm/tlb.h linux-3.4.83-vs2.3.3.9/arch/s390/include/asm/tlb.h
662 --- linux-3.4.83/arch/s390/include/asm/tlb.h    2012-05-21 16:06:32.000000000 +0000
663 +++ linux-3.4.83-vs2.3.3.9/arch/s390/include/asm/tlb.h  2012-05-21 16:15:04.000000000 +0000
664 @@ -24,6 +24,7 @@
665  #include <linux/mm.h>
666  #include <linux/pagemap.h>
667  #include <linux/swap.h>
668 +
669  #include <asm/processor.h>
670  #include <asm/pgalloc.h>
671  #include <asm/tlbflush.h>
672 diff -NurpP --minimal linux-3.4.83/arch/s390/include/asm/unistd.h linux-3.4.83-vs2.3.3.9/arch/s390/include/asm/unistd.h
673 --- linux-3.4.83/arch/s390/include/asm/unistd.h 2012-03-19 18:46:48.000000000 +0000
674 +++ linux-3.4.83-vs2.3.3.9/arch/s390/include/asm/unistd.h       2012-05-21 16:15:04.000000000 +0000
675 @@ -202,7 +202,7 @@
676  #define __NR_clock_gettime     (__NR_timer_create+6)
677  #define __NR_clock_getres      (__NR_timer_create+7)
678  #define __NR_clock_nanosleep   (__NR_timer_create+8)
679 -/* Number 263 is reserved for vserver */
680 +#define __NR_vserver           263
681  #define __NR_statfs64          265
682  #define __NR_fstatfs64         266
683  #define __NR_remap_file_pages  267
684 diff -NurpP --minimal linux-3.4.83/arch/s390/kernel/ptrace.c linux-3.4.83-vs2.3.3.9/arch/s390/kernel/ptrace.c
685 --- linux-3.4.83/arch/s390/kernel/ptrace.c      2012-05-21 16:06:32.000000000 +0000
686 +++ linux-3.4.83-vs2.3.3.9/arch/s390/kernel/ptrace.c    2012-05-21 16:15:04.000000000 +0000
687 @@ -21,6 +21,7 @@
688  #include <linux/tracehook.h>
689  #include <linux/seccomp.h>
690  #include <linux/compat.h>
691 +#include <linux/vs_base.h>
692  #include <trace/syscall.h>
693  #include <asm/segment.h>
694  #include <asm/page.h>
695 diff -NurpP --minimal linux-3.4.83/arch/s390/kernel/syscalls.S linux-3.4.83-vs2.3.3.9/arch/s390/kernel/syscalls.S
696 --- linux-3.4.83/arch/s390/kernel/syscalls.S    2012-01-09 15:14:06.000000000 +0000
697 +++ linux-3.4.83-vs2.3.3.9/arch/s390/kernel/syscalls.S  2012-05-21 16:15:04.000000000 +0000
698 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
699  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
700  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
701  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
702 -NI_SYSCALL                                                     /* reserved for vserver */
703 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
704  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
705  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
706  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
707 diff -NurpP --minimal linux-3.4.83/arch/sh/Kconfig linux-3.4.83-vs2.3.3.9/arch/sh/Kconfig
708 --- linux-3.4.83/arch/sh/Kconfig        2012-05-21 16:06:33.000000000 +0000
709 +++ linux-3.4.83-vs2.3.3.9/arch/sh/Kconfig      2012-05-21 16:15:04.000000000 +0000
710 @@ -905,6 +905,8 @@ source "fs/Kconfig"
711  
712  source "arch/sh/Kconfig.debug"
713  
714 +source "kernel/vserver/Kconfig"
715 +
716  source "security/Kconfig"
717  
718  source "crypto/Kconfig"
719 diff -NurpP --minimal linux-3.4.83/arch/sh/kernel/irq.c linux-3.4.83-vs2.3.3.9/arch/sh/kernel/irq.c
720 --- linux-3.4.83/arch/sh/kernel/irq.c   2011-07-22 09:17:41.000000000 +0000
721 +++ linux-3.4.83-vs2.3.3.9/arch/sh/kernel/irq.c 2012-05-21 16:15:04.000000000 +0000
722 @@ -14,6 +14,7 @@
723  #include <linux/ftrace.h>
724  #include <linux/delay.h>
725  #include <linux/ratelimit.h>
726 +// #include <linux/vs_context.h>
727  #include <asm/processor.h>
728  #include <asm/machvec.h>
729  #include <asm/uaccess.h>
730 diff -NurpP --minimal linux-3.4.83/arch/sparc/Kconfig linux-3.4.83-vs2.3.3.9/arch/sparc/Kconfig
731 --- linux-3.4.83/arch/sparc/Kconfig     2014-03-12 09:47:46.000000000 +0000
732 +++ linux-3.4.83-vs2.3.3.9/arch/sparc/Kconfig   2012-06-08 13:57:24.000000000 +0000
733 @@ -599,6 +599,8 @@ source "fs/Kconfig"
734  
735  source "arch/sparc/Kconfig.debug"
736  
737 +source "kernel/vserver/Kconfig"
738 +
739  source "security/Kconfig"
740  
741  source "crypto/Kconfig"
742 diff -NurpP --minimal linux-3.4.83/arch/sparc/include/asm/unistd.h linux-3.4.83-vs2.3.3.9/arch/sparc/include/asm/unistd.h
743 --- linux-3.4.83/arch/sparc/include/asm/unistd.h        2012-01-09 15:14:07.000000000 +0000
744 +++ linux-3.4.83-vs2.3.3.9/arch/sparc/include/asm/unistd.h      2012-05-21 16:15:04.000000000 +0000
745 @@ -335,7 +335,7 @@
746  #define __NR_timer_getoverrun  264
747  #define __NR_timer_delete      265
748  #define __NR_timer_create      266
749 -/* #define __NR_vserver                267 Reserved for VSERVER */
750 +#define __NR_vserver           267
751  #define __NR_io_setup          268
752  #define __NR_io_destroy                269
753  #define __NR_io_submit         270
754 diff -NurpP --minimal linux-3.4.83/arch/sparc/kernel/systbls_32.S linux-3.4.83-vs2.3.3.9/arch/sparc/kernel/systbls_32.S
755 --- linux-3.4.83/arch/sparc/kernel/systbls_32.S 2012-01-09 15:14:09.000000000 +0000
756 +++ linux-3.4.83-vs2.3.3.9/arch/sparc/kernel/systbls_32.S       2012-05-21 16:15:04.000000000 +0000
757 @@ -70,7 +70,7 @@ sys_call_table:
758  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
759  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
760  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
761 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
762 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
763  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
764  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
765  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
766 diff -NurpP --minimal linux-3.4.83/arch/sparc/kernel/systbls_64.S linux-3.4.83-vs2.3.3.9/arch/sparc/kernel/systbls_64.S
767 --- linux-3.4.83/arch/sparc/kernel/systbls_64.S 2014-03-12 09:47:46.000000000 +0000
768 +++ linux-3.4.83-vs2.3.3.9/arch/sparc/kernel/systbls_64.S       2012-06-08 13:57:24.000000000 +0000
769 @@ -71,7 +71,7 @@ sys_call_table32:
770  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
771         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
772  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
773 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
774 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
775  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
776         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
777  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
778 @@ -148,7 +148,7 @@ sys_call_table:
779  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
780         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
781  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
782 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
783 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
784  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
785         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
786  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
787 diff -NurpP --minimal linux-3.4.83/arch/um/Kconfig.rest linux-3.4.83-vs2.3.3.9/arch/um/Kconfig.rest
788 --- linux-3.4.83/arch/um/Kconfig.rest   2012-01-09 15:14:09.000000000 +0000
789 +++ linux-3.4.83-vs2.3.3.9/arch/um/Kconfig.rest 2012-05-21 16:15:04.000000000 +0000
790 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
791  
792  source "fs/Kconfig"
793  
794 +source "kernel/vserver/Kconfig"
795 +
796  source "security/Kconfig"
797  
798  source "crypto/Kconfig"
799 diff -NurpP --minimal linux-3.4.83/arch/x86/Kconfig linux-3.4.83-vs2.3.3.9/arch/x86/Kconfig
800 --- linux-3.4.83/arch/x86/Kconfig       2014-03-12 09:47:46.000000000 +0000
801 +++ linux-3.4.83-vs2.3.3.9/arch/x86/Kconfig     2013-03-02 15:26:44.000000000 +0000
802 @@ -2221,6 +2221,8 @@ source "fs/Kconfig"
803  
804  source "arch/x86/Kconfig.debug"
805  
806 +source "kernel/vserver/Kconfig"
807 +
808  source "security/Kconfig"
809  
810  source "crypto/Kconfig"
811 diff -NurpP --minimal linux-3.4.83/arch/x86/syscalls/syscall_32.tbl linux-3.4.83-vs2.3.3.9/arch/x86/syscalls/syscall_32.tbl
812 --- linux-3.4.83/arch/x86/syscalls/syscall_32.tbl       2012-05-21 16:06:42.000000000 +0000
813 +++ linux-3.4.83-vs2.3.3.9/arch/x86/syscalls/syscall_32.tbl     2012-05-21 16:15:04.000000000 +0000
814 @@ -279,7 +279,7 @@
815  270    i386    tgkill                  sys_tgkill
816  271    i386    utimes                  sys_utimes                      compat_sys_utimes
817  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
818 -273    i386    vserver
819 +273    i386    vserver                 sys_vserver                     sys32_vserver
820  274    i386    mbind                   sys_mbind
821  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
822  276    i386    set_mempolicy           sys_set_mempolicy
823 diff -NurpP --minimal linux-3.4.83/arch/x86/syscalls/syscall_64.tbl linux-3.4.83-vs2.3.3.9/arch/x86/syscalls/syscall_64.tbl
824 --- linux-3.4.83/arch/x86/syscalls/syscall_64.tbl       2014-03-12 09:47:47.000000000 +0000
825 +++ linux-3.4.83-vs2.3.3.9/arch/x86/syscalls/syscall_64.tbl     2012-09-16 18:49:11.000000000 +0000
826 @@ -242,7 +242,7 @@
827  233    common  epoll_ctl               sys_epoll_ctl
828  234    common  tgkill                  sys_tgkill
829  235    common  utimes                  sys_utimes
830 -236    64      vserver
831 +236    64      vserver                 sys_vserver
832  237    common  mbind                   sys_mbind
833  238    common  set_mempolicy           sys_set_mempolicy
834  239    common  get_mempolicy           sys_get_mempolicy
835 diff -NurpP --minimal linux-3.4.83/drivers/block/Kconfig linux-3.4.83-vs2.3.3.9/drivers/block/Kconfig
836 --- linux-3.4.83/drivers/block/Kconfig  2012-05-21 16:06:43.000000000 +0000
837 +++ linux-3.4.83-vs2.3.3.9/drivers/block/Kconfig        2012-05-21 16:15:04.000000000 +0000
838 @@ -290,6 +290,13 @@ config BLK_DEV_CRYPTOLOOP
839  
840  source "drivers/block/drbd/Kconfig"
841  
842 +config BLK_DEV_VROOT
843 +       tristate "Virtual Root device support"
844 +       depends on QUOTACTL
845 +       ---help---
846 +         Saying Y here will allow you to use quota/fs ioctls on a shared
847 +         partition within a virtual server without compromising security.
848 +
849  config BLK_DEV_NBD
850         tristate "Network block device support"
851         depends on NET
852 diff -NurpP --minimal linux-3.4.83/drivers/block/Makefile linux-3.4.83-vs2.3.3.9/drivers/block/Makefile
853 --- linux-3.4.83/drivers/block/Makefile 2012-03-19 18:46:52.000000000 +0000
854 +++ linux-3.4.83-vs2.3.3.9/drivers/block/Makefile       2012-05-21 16:15:04.000000000 +0000
855 @@ -35,6 +35,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
856  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
857  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
858  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
859 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
860  
861  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
862  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
863 diff -NurpP --minimal linux-3.4.83/drivers/block/loop.c linux-3.4.83-vs2.3.3.9/drivers/block/loop.c
864 --- linux-3.4.83/drivers/block/loop.c   2014-03-12 09:47:50.000000000 +0000
865 +++ linux-3.4.83-vs2.3.3.9/drivers/block/loop.c 2014-03-12 09:55:28.000000000 +0000
866 @@ -76,6 +76,7 @@
867  #include <linux/sysfs.h>
868  #include <linux/miscdevice.h>
869  #include <linux/falloc.h>
870 +#include <linux/vs_context.h>
871  
872  #include <asm/uaccess.h>
873  
874 @@ -869,6 +870,7 @@ static int loop_set_fd(struct loop_devic
875         lo->lo_blocksize = lo_blocksize;
876         lo->lo_device = bdev;
877         lo->lo_flags = lo_flags;
878 +       lo->lo_xid = vx_current_xid();
879         lo->lo_backing_file = file;
880         lo->transfer = transfer_none;
881         lo->ioctl = NULL;
882 @@ -1006,6 +1008,7 @@ static int loop_clr_fd(struct loop_devic
883         lo->lo_sizelimit = 0;
884         lo->lo_encrypt_key_size = 0;
885         lo->lo_thread = NULL;
886 +       lo->lo_xid = 0;
887         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
888         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
889         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
890 @@ -1049,7 +1052,7 @@ loop_set_status(struct loop_device *lo,
891  
892         if (lo->lo_encrypt_key_size &&
893             lo->lo_key_owner != uid &&
894 -           !capable(CAP_SYS_ADMIN))
895 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
896                 return -EPERM;
897         if (lo->lo_state != Lo_bound)
898                 return -ENXIO;
899 @@ -1139,7 +1142,8 @@ loop_get_status(struct loop_device *lo,
900         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
901         info->lo_encrypt_type =
902                 lo->lo_encryption ? lo->lo_encryption->number : 0;
903 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
904 +       if (lo->lo_encrypt_key_size &&
905 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
906                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
907                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
908                        lo->lo_encrypt_key_size);
909 @@ -1497,6 +1501,11 @@ static int lo_open(struct block_device *
910                 goto out;
911         }
912  
913 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
914 +               err = -EACCES;
915 +               goto out;
916 +       }
917 +
918         mutex_lock(&lo->lo_ctl_mutex);
919         lo->lo_refcnt++;
920         mutex_unlock(&lo->lo_ctl_mutex);
921 diff -NurpP --minimal linux-3.4.83/drivers/block/vroot.c linux-3.4.83-vs2.3.3.9/drivers/block/vroot.c
922 --- linux-3.4.83/drivers/block/vroot.c  1970-01-01 00:00:00.000000000 +0000
923 +++ linux-3.4.83-vs2.3.3.9/drivers/block/vroot.c        2012-05-21 16:15:04.000000000 +0000
924 @@ -0,0 +1,291 @@
925 +/*
926 + *  linux/drivers/block/vroot.c
927 + *
928 + *  written by Herbert Pötzl, 9/11/2002
929 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
930 + *
931 + *  based on the loop.c code by Theodore Ts'o.
932 + *
933 + * Copyright (C) 2002-2007 by Herbert Pötzl.
934 + * Redistribution of this file is permitted under the
935 + * GNU General Public License.
936 + *
937 + */
938 +
939 +#include <linux/module.h>
940 +#include <linux/moduleparam.h>
941 +#include <linux/file.h>
942 +#include <linux/major.h>
943 +#include <linux/blkdev.h>
944 +#include <linux/slab.h>
945 +
946 +#include <linux/vroot.h>
947 +#include <linux/vs_context.h>
948 +
949 +
950 +static int max_vroot = 8;
951 +
952 +static struct vroot_device *vroot_dev;
953 +static struct gendisk **disks;
954 +
955 +
956 +static int vroot_set_dev(
957 +       struct vroot_device *vr,
958 +       struct block_device *bdev,
959 +       unsigned int arg)
960 +{
961 +       struct block_device *real_bdev;
962 +       struct file *file;
963 +       struct inode *inode;
964 +       int error;
965 +
966 +       error = -EBUSY;
967 +       if (vr->vr_state != Vr_unbound)
968 +               goto out;
969 +
970 +       error = -EBADF;
971 +       file = fget(arg);
972 +       if (!file)
973 +               goto out;
974 +
975 +       error = -EINVAL;
976 +       inode = file->f_dentry->d_inode;
977 +
978 +
979 +       if (S_ISBLK(inode->i_mode)) {
980 +               real_bdev = inode->i_bdev;
981 +               vr->vr_device = real_bdev;
982 +               __iget(real_bdev->bd_inode);
983 +       } else
984 +               goto out_fput;
985 +
986 +       vxdprintk(VXD_CBIT(misc, 0),
987 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
988 +               vr->vr_number, VXD_DEV(real_bdev));
989 +
990 +       vr->vr_state = Vr_bound;
991 +       error = 0;
992 +
993 + out_fput:
994 +       fput(file);
995 + out:
996 +       return error;
997 +}
998 +
999 +static int vroot_clr_dev(
1000 +       struct vroot_device *vr,
1001 +       struct block_device *bdev)
1002 +{
1003 +       struct block_device *real_bdev;
1004 +
1005 +       if (vr->vr_state != Vr_bound)
1006 +               return -ENXIO;
1007 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1008 +               return -EBUSY;
1009 +
1010 +       real_bdev = vr->vr_device;
1011 +
1012 +       vxdprintk(VXD_CBIT(misc, 0),
1013 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1014 +               vr->vr_number, VXD_DEV(real_bdev));
1015 +
1016 +       bdput(real_bdev);
1017 +       vr->vr_state = Vr_unbound;
1018 +       vr->vr_device = NULL;
1019 +       return 0;
1020 +}
1021 +
1022 +
1023 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1024 +       unsigned int cmd, unsigned long arg)
1025 +{
1026 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1027 +       int err;
1028 +
1029 +       down(&vr->vr_ctl_mutex);
1030 +       switch (cmd) {
1031 +       case VROOT_SET_DEV:
1032 +               err = vroot_set_dev(vr, bdev, arg);
1033 +               break;
1034 +       case VROOT_CLR_DEV:
1035 +               err = vroot_clr_dev(vr, bdev);
1036 +               break;
1037 +       default:
1038 +               err = -EINVAL;
1039 +               break;
1040 +       }
1041 +       up(&vr->vr_ctl_mutex);
1042 +       return err;
1043 +}
1044 +
1045 +static int vr_open(struct block_device *bdev, fmode_t mode)
1046 +{
1047 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1048 +
1049 +       down(&vr->vr_ctl_mutex);
1050 +       vr->vr_refcnt++;
1051 +       up(&vr->vr_ctl_mutex);
1052 +       return 0;
1053 +}
1054 +
1055 +static int vr_release(struct gendisk *disk, fmode_t mode)
1056 +{
1057 +       struct vroot_device *vr = disk->private_data;
1058 +
1059 +       down(&vr->vr_ctl_mutex);
1060 +       --vr->vr_refcnt;
1061 +       up(&vr->vr_ctl_mutex);
1062 +       return 0;
1063 +}
1064 +
1065 +static struct block_device_operations vr_fops = {
1066 +       .owner =        THIS_MODULE,
1067 +       .open =         vr_open,
1068 +       .release =      vr_release,
1069 +       .ioctl =        vr_ioctl,
1070 +};
1071 +
1072 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1073 +{
1074 +       printk("vroot_make_request %p, %p\n", q, bio);
1075 +       bio_io_error(bio);
1076 +}
1077 +
1078 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1079 +{
1080 +       struct inode *inode = bdev->bd_inode;
1081 +       struct vroot_device *vr;
1082 +       struct block_device *real_bdev;
1083 +       int minor = iminor(inode);
1084 +
1085 +       vr = &vroot_dev[minor];
1086 +       real_bdev = vr->vr_device;
1087 +
1088 +       vxdprintk(VXD_CBIT(misc, 0),
1089 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1090 +               vr->vr_number, VXD_DEV(real_bdev));
1091 +
1092 +       if (vr->vr_state != Vr_bound)
1093 +               return ERR_PTR(-ENXIO);
1094 +
1095 +       __iget(real_bdev->bd_inode);
1096 +       return real_bdev;
1097 +}
1098 +
1099 +
1100 +
1101 +/*
1102 + * And now the modules code and kernel interface.
1103 + */
1104 +
1105 +module_param(max_vroot, int, 0);
1106 +
1107 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1108 +MODULE_LICENSE("GPL");
1109 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1110 +
1111 +MODULE_AUTHOR ("Herbert Pötzl");
1112 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1113 +
1114 +
1115 +int __init vroot_init(void)
1116 +{
1117 +       int err, i;
1118 +
1119 +       if (max_vroot < 1 || max_vroot > 256) {
1120 +               max_vroot = MAX_VROOT_DEFAULT;
1121 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1122 +                       "(must be between 1 and 256), "
1123 +                       "using default (%d)\n", max_vroot);
1124 +       }
1125 +
1126 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1127 +               return -EIO;
1128 +
1129 +       err = -ENOMEM;
1130 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1131 +       if (!vroot_dev)
1132 +               goto out_mem1;
1133 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1134 +
1135 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1136 +       if (!disks)
1137 +               goto out_mem2;
1138 +
1139 +       for (i = 0; i < max_vroot; i++) {
1140 +               disks[i] = alloc_disk(1);
1141 +               if (!disks[i])
1142 +                       goto out_mem3;
1143 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1144 +               if (!disks[i]->queue)
1145 +                       goto out_mem3;
1146 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1147 +       }
1148 +
1149 +       for (i = 0; i < max_vroot; i++) {
1150 +               struct vroot_device *vr = &vroot_dev[i];
1151 +               struct gendisk *disk = disks[i];
1152 +
1153 +               memset(vr, 0, sizeof(*vr));
1154 +               sema_init(&vr->vr_ctl_mutex, 1);
1155 +               vr->vr_number = i;
1156 +               disk->major = VROOT_MAJOR;
1157 +               disk->first_minor = i;
1158 +               disk->fops = &vr_fops;
1159 +               sprintf(disk->disk_name, "vroot%d", i);
1160 +               disk->private_data = vr;
1161 +       }
1162 +
1163 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1164 +       if (err)
1165 +               goto out_mem3;
1166 +
1167 +       for (i = 0; i < max_vroot; i++)
1168 +               add_disk(disks[i]);
1169 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1170 +       return 0;
1171 +
1172 +out_mem3:
1173 +       while (i--)
1174 +               put_disk(disks[i]);
1175 +       kfree(disks);
1176 +out_mem2:
1177 +       kfree(vroot_dev);
1178 +out_mem1:
1179 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1180 +       printk(KERN_ERR "vroot: ran out of memory\n");
1181 +       return err;
1182 +}
1183 +
1184 +void vroot_exit(void)
1185 +{
1186 +       int i;
1187 +
1188 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1189 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1190 +
1191 +       for (i = 0; i < max_vroot; i++) {
1192 +               del_gendisk(disks[i]);
1193 +               put_disk(disks[i]);
1194 +       }
1195 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1196 +
1197 +       kfree(disks);
1198 +       kfree(vroot_dev);
1199 +}
1200 +
1201 +module_init(vroot_init);
1202 +module_exit(vroot_exit);
1203 +
1204 +#ifndef MODULE
1205 +
1206 +static int __init max_vroot_setup(char *str)
1207 +{
1208 +       max_vroot = simple_strtol(str, NULL, 0);
1209 +       return 1;
1210 +}
1211 +
1212 +__setup("max_vroot=", max_vroot_setup);
1213 +
1214 +#endif
1215 +
1216 diff -NurpP --minimal linux-3.4.83/drivers/infiniband/Kconfig linux-3.4.83-vs2.3.3.9/drivers/infiniband/Kconfig
1217 --- linux-3.4.83/drivers/infiniband/Kconfig     2012-03-19 18:46:54.000000000 +0000
1218 +++ linux-3.4.83-vs2.3.3.9/drivers/infiniband/Kconfig   2012-05-21 16:15:04.000000000 +0000
1219 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1220  config INFINIBAND_ADDR_TRANS
1221         bool
1222         depends on INET
1223 -       depends on !(INFINIBAND = y && IPV6 = m)
1224 +       depends on !(INFINIBAND = y && IPV6 = y)
1225         default y
1226  
1227  source "drivers/infiniband/hw/mthca/Kconfig"
1228 diff -NurpP --minimal linux-3.4.83/drivers/infiniband/core/addr.c linux-3.4.83-vs2.3.3.9/drivers/infiniband/core/addr.c
1229 --- linux-3.4.83/drivers/infiniband/core/addr.c 2012-05-21 16:06:46.000000000 +0000
1230 +++ linux-3.4.83-vs2.3.3.9/drivers/infiniband/core/addr.c       2012-05-21 16:15:04.000000000 +0000
1231 @@ -263,7 +263,7 @@ static int addr6_resolve(struct sockaddr
1232  
1233         if (ipv6_addr_any(&fl6.saddr)) {
1234                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1235 -                                        &fl6.daddr, 0, &fl6.saddr);
1236 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1237                 if (ret)
1238                         goto put;
1239  
1240 diff -NurpP --minimal linux-3.4.83/drivers/md/dm-ioctl.c linux-3.4.83-vs2.3.3.9/drivers/md/dm-ioctl.c
1241 --- linux-3.4.83/drivers/md/dm-ioctl.c  2014-03-12 09:47:53.000000000 +0000
1242 +++ linux-3.4.83-vs2.3.3.9/drivers/md/dm-ioctl.c        2014-03-12 09:55:28.000000000 +0000
1243 @@ -16,6 +16,7 @@
1244  #include <linux/dm-ioctl.h>
1245  #include <linux/hdreg.h>
1246  #include <linux/compat.h>
1247 +#include <linux/vs_context.h>
1248  
1249  #include <asm/uaccess.h>
1250  
1251 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1252         unsigned int h = hash_str(str);
1253  
1254         list_for_each_entry (hc, _name_buckets + h, name_list)
1255 -               if (!strcmp(hc->name, str)) {
1256 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1257 +                       !strcmp(hc->name, str)) {
1258                         dm_get(hc->md);
1259                         return hc;
1260                 }
1261 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1262         unsigned int h = hash_str(str);
1263  
1264         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1265 -               if (!strcmp(hc->uuid, str)) {
1266 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1267 +                       !strcmp(hc->uuid, str)) {
1268                         dm_get(hc->md);
1269                         return hc;
1270                 }
1271 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1272  static struct hash_cell *__get_dev_cell(uint64_t dev)
1273  {
1274         struct mapped_device *md;
1275 -       struct hash_cell *hc;
1276 +       struct hash_cell *hc = NULL;
1277  
1278         md = dm_get_md(huge_decode_dev(dev));
1279         if (!md)
1280                 return NULL;
1281  
1282 -       hc = dm_get_mdptr(md);
1283 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1284 +               hc = dm_get_mdptr(md);
1285 +
1286         if (!hc) {
1287                 dm_put(md);
1288                 return NULL;
1289 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1290  
1291  static int remove_all(struct dm_ioctl *param, size_t param_size)
1292  {
1293 +       if (!vx_check(0, VS_ADMIN))
1294 +               return -EPERM;
1295 +
1296         dm_hash_remove_all(1);
1297         param->data_size = 0;
1298         return 0;
1299 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1300          */
1301         for (i = 0; i < NUM_BUCKETS; i++) {
1302                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1303 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1304 +                               continue;
1305                         needed += sizeof(struct dm_name_list);
1306                         needed += strlen(hc->name) + 1;
1307                         needed += ALIGN_MASK;
1308 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1309          */
1310         for (i = 0; i < NUM_BUCKETS; i++) {
1311                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1312 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1313 +                               continue;
1314                         if (old_nl)
1315                                 old_nl->next = (uint32_t) ((void *) nl -
1316                                                            (void *) old_nl);
1317 @@ -1628,8 +1640,8 @@ static int ctl_ioctl(uint command, struc
1318         ioctl_fn fn = NULL;
1319         size_t input_param_size;
1320  
1321 -       /* only root can play with this */
1322 -       if (!capable(CAP_SYS_ADMIN))
1323 +       /* only root and certain contexts can play with this */
1324 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1325                 return -EACCES;
1326  
1327         if (_IOC_TYPE(command) != DM_IOCTL)
1328 diff -NurpP --minimal linux-3.4.83/drivers/md/dm.c linux-3.4.83-vs2.3.3.9/drivers/md/dm.c
1329 --- linux-3.4.83/drivers/md/dm.c        2014-03-12 09:47:53.000000000 +0000
1330 +++ linux-3.4.83-vs2.3.3.9/drivers/md/dm.c      2014-03-12 09:55:28.000000000 +0000
1331 @@ -19,6 +19,7 @@
1332  #include <linux/idr.h>
1333  #include <linux/hdreg.h>
1334  #include <linux/delay.h>
1335 +#include <linux/vs_base.h>
1336  
1337  #include <trace/events/block.h>
1338  
1339 @@ -131,6 +132,7 @@ struct mapped_device {
1340         rwlock_t map_lock;
1341         atomic_t holders;
1342         atomic_t open_count;
1343 +       xid_t xid;
1344  
1345         unsigned long flags;
1346  
1347 @@ -343,6 +345,7 @@ int dm_deleting_md(struct mapped_device
1348  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1349  {
1350         struct mapped_device *md;
1351 +       int ret = -ENXIO;
1352  
1353         spin_lock(&_minor_lock);
1354  
1355 @@ -351,18 +354,19 @@ static int dm_blk_open(struct block_devi
1356                 goto out;
1357  
1358         if (test_bit(DMF_FREEING, &md->flags) ||
1359 -           dm_deleting_md(md)) {
1360 -               md = NULL;
1361 +           dm_deleting_md(md))
1362 +               goto out;
1363 +
1364 +       ret = -EACCES;
1365 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1366                 goto out;
1367 -       }
1368  
1369         dm_get(md);
1370         atomic_inc(&md->open_count);
1371 -
1372 +       ret = 0;
1373  out:
1374         spin_unlock(&_minor_lock);
1375 -
1376 -       return md ? 0 : -ENXIO;
1377 +       return ret;
1378  }
1379  
1380  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1381 @@ -583,6 +587,14 @@ int dm_set_geometry(struct mapped_device
1382         return 0;
1383  }
1384  
1385 +/*
1386 + * Get the xid associated with a dm device
1387 + */
1388 +xid_t dm_get_xid(struct mapped_device *md)
1389 +{
1390 +       return md->xid;
1391 +}
1392 +
1393  /*-----------------------------------------------------------------
1394   * CRUD START:
1395   *   A more elegant soln is in the works that uses the queue
1396 @@ -1876,6 +1888,7 @@ static struct mapped_device *alloc_dev(i
1397         INIT_LIST_HEAD(&md->uevent_list);
1398         spin_lock_init(&md->uevent_lock);
1399  
1400 +       md->xid = vx_current_xid();
1401         md->queue = blk_alloc_queue(GFP_KERNEL);
1402         if (!md->queue)
1403                 goto bad_queue;
1404 diff -NurpP --minimal linux-3.4.83/drivers/md/dm.h linux-3.4.83-vs2.3.3.9/drivers/md/dm.h
1405 --- linux-3.4.83/drivers/md/dm.h        2014-03-12 09:47:53.000000000 +0000
1406 +++ linux-3.4.83-vs2.3.3.9/drivers/md/dm.h      2014-03-12 09:55:28.000000000 +0000
1407 @@ -43,6 +43,8 @@ struct dm_dev_internal {
1408  struct dm_table;
1409  struct dm_md_mempools;
1410  
1411 +xid_t dm_get_xid(struct mapped_device *md);
1412 +
1413  /*-----------------------------------------------------------------
1414   * Internal table functions.
1415   *---------------------------------------------------------------*/
1416 diff -NurpP --minimal linux-3.4.83/drivers/net/tun.c linux-3.4.83-vs2.3.3.9/drivers/net/tun.c
1417 --- linux-3.4.83/drivers/net/tun.c      2014-03-12 09:47:58.000000000 +0000
1418 +++ linux-3.4.83-vs2.3.3.9/drivers/net/tun.c    2014-03-12 09:55:28.000000000 +0000
1419 @@ -64,6 +64,7 @@
1420  #include <linux/nsproxy.h>
1421  #include <linux/virtio_net.h>
1422  #include <linux/rcupdate.h>
1423 +#include <linux/vs_network.h>
1424  #include <net/net_namespace.h>
1425  #include <net/netns/generic.h>
1426  #include <net/rtnetlink.h>
1427 @@ -120,6 +121,7 @@ struct tun_struct {
1428         unsigned int            flags;
1429         uid_t                   owner;
1430         gid_t                   group;
1431 +       nid_t                   nid;
1432  
1433         struct net_device       *dev;
1434         netdev_features_t       set_features;
1435 @@ -916,6 +918,7 @@ static void tun_setup(struct net_device
1436  
1437         tun->owner = -1;
1438         tun->group = -1;
1439 +       tun->nid = current->nid;
1440  
1441         dev->ethtool_ops = &tun_ethtool_ops;
1442         dev->destructor = tun_free_netdev;
1443 @@ -1074,7 +1077,7 @@ static int tun_set_iff(struct net *net,
1444  
1445                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1446                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1447 -                   !capable(CAP_NET_ADMIN))
1448 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1449                         return -EPERM;
1450                 err = security_tun_dev_attach(tun->socket.sk);
1451                 if (err < 0)
1452 @@ -1088,7 +1091,7 @@ static int tun_set_iff(struct net *net,
1453                 char *name;
1454                 unsigned long flags = 0;
1455  
1456 -               if (!capable(CAP_NET_ADMIN))
1457 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1458                         return -EPERM;
1459                 err = security_tun_dev_create();
1460                 if (err < 0)
1461 @@ -1158,6 +1161,9 @@ static int tun_set_iff(struct net *net,
1462  
1463                 sk->sk_destruct = tun_sock_destruct;
1464  
1465 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1466 +                       return -EPERM;
1467 +
1468                 err = tun_attach(tun, file);
1469                 if (err < 0)
1470                         goto failed;
1471 @@ -1341,6 +1347,16 @@ static long __tun_chr_ioctl(struct file
1472                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1473                 break;
1474  
1475 +       case TUNSETNID:
1476 +               if (!capable(CAP_CONTEXT))
1477 +                       return -EPERM;
1478 +
1479 +               /* Set nid owner of the device */
1480 +               tun->nid = (nid_t) arg;
1481 +
1482 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1483 +               break;
1484 +
1485         case TUNSETLINK:
1486                 /* Only allow setting the type when the interface is down */
1487                 if (tun->dev->flags & IFF_UP) {
1488 diff -NurpP --minimal linux-3.4.83/drivers/tty/sysrq.c linux-3.4.83-vs2.3.3.9/drivers/tty/sysrq.c
1489 --- linux-3.4.83/drivers/tty/sysrq.c    2012-05-21 16:07:16.000000000 +0000
1490 +++ linux-3.4.83-vs2.3.3.9/drivers/tty/sysrq.c  2012-05-21 16:15:04.000000000 +0000
1491 @@ -41,6 +41,7 @@
1492  #include <linux/slab.h>
1493  #include <linux/input.h>
1494  #include <linux/uaccess.h>
1495 +#include <linux/vserver/debug.h>
1496  
1497  #include <asm/ptrace.h>
1498  #include <asm/irq_regs.h>
1499 @@ -398,6 +399,21 @@ static struct sysrq_key_op sysrq_unrt_op
1500         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1501  };
1502  
1503 +
1504 +#ifdef CONFIG_VSERVER_DEBUG
1505 +static void sysrq_handle_vxinfo(int key)
1506 +{
1507 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1508 +}
1509 +
1510 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1511 +       .handler        = sysrq_handle_vxinfo,
1512 +       .help_msg       = "conteXt",
1513 +       .action_msg     = "Show Context Info",
1514 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1515 +};
1516 +#endif
1517 +
1518  /* Key Operations table and lock */
1519  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1520  
1521 @@ -452,7 +468,11 @@ static struct sysrq_key_op *sysrq_key_ta
1522         NULL,                           /* v */
1523         &sysrq_showstate_blocked_op,    /* w */
1524         /* x: May be registered on ppc/powerpc for xmon */
1525 +#ifdef CONFIG_VSERVER_DEBUG
1526 +       &sysrq_showvxinfo_op,           /* x */
1527 +#else
1528         NULL,                           /* x */
1529 +#endif
1530         /* y: May be registered on sparc64 for global register dump */
1531         NULL,                           /* y */
1532         &sysrq_ftrace_dump_op,          /* z */
1533 @@ -467,6 +487,8 @@ static int sysrq_key_table_key2index(int
1534                 retval = key - '0';
1535         else if ((key >= 'a') && (key <= 'z'))
1536                 retval = key + 10 - 'a';
1537 +       else if ((key >= 'A') && (key <= 'Z'))
1538 +               retval = key + 10 - 'A';
1539         else
1540                 retval = -1;
1541         return retval;
1542 diff -NurpP --minimal linux-3.4.83/drivers/tty/tty_io.c linux-3.4.83-vs2.3.3.9/drivers/tty/tty_io.c
1543 --- linux-3.4.83/drivers/tty/tty_io.c   2014-03-12 09:48:09.000000000 +0000
1544 +++ linux-3.4.83-vs2.3.3.9/drivers/tty/tty_io.c 2013-07-14 13:38:33.000000000 +0000
1545 @@ -104,6 +104,7 @@
1546  
1547  #include <linux/kmod.h>
1548  #include <linux/nsproxy.h>
1549 +#include <linux/vs_pid.h>
1550  
1551  #undef TTY_DEBUG_HANGUP
1552  
1553 @@ -2128,7 +2129,8 @@ static int tiocsti(struct tty_struct *tt
1554         char ch, mbz = 0;
1555         struct tty_ldisc *ld;
1556  
1557 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1558 +       if (((current->signal->tty != tty) &&
1559 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1560                 return -EPERM;
1561         if (get_user(ch, p))
1562                 return -EFAULT;
1563 @@ -2416,6 +2418,7 @@ static int tiocspgrp(struct tty_struct *
1564                 return -ENOTTY;
1565         if (get_user(pgrp_nr, p))
1566                 return -EFAULT;
1567 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1568         if (pgrp_nr < 0)
1569                 return -EINVAL;
1570         rcu_read_lock();
1571 diff -NurpP --minimal linux-3.4.83/fs/attr.c linux-3.4.83-vs2.3.3.9/fs/attr.c
1572 --- linux-3.4.83/fs/attr.c      2014-03-12 09:48:11.000000000 +0000
1573 +++ linux-3.4.83-vs2.3.3.9/fs/attr.c    2012-06-28 14:45:07.000000000 +0000
1574 @@ -14,6 +14,9 @@
1575  #include <linux/fcntl.h>
1576  #include <linux/security.h>
1577  #include <linux/evm.h>
1578 +#include <linux/proc_fs.h>
1579 +#include <linux/devpts_fs.h>
1580 +#include <linux/vs_tag.h>
1581  
1582  /**
1583   * inode_change_ok - check if attribute changes to an inode are allowed
1584 @@ -74,6 +77,10 @@ int inode_change_ok(const struct inode *
1585                         return -EPERM;
1586         }
1587  
1588 +       /* check for inode tag permission */
1589 +       if (dx_permission(inode, MAY_WRITE))
1590 +               return -EACCES;
1591 +
1592         return 0;
1593  }
1594  EXPORT_SYMBOL(inode_change_ok);
1595 @@ -144,6 +151,8 @@ void setattr_copy(struct inode *inode, c
1596                 inode->i_uid = attr->ia_uid;
1597         if (ia_valid & ATTR_GID)
1598                 inode->i_gid = attr->ia_gid;
1599 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1600 +               inode->i_tag = attr->ia_tag;
1601         if (ia_valid & ATTR_ATIME)
1602                 inode->i_atime = timespec_trunc(attr->ia_atime,
1603                                                 inode->i_sb->s_time_gran);
1604 @@ -171,7 +180,8 @@ int notify_change(struct dentry * dentry
1605         struct timespec now;
1606         unsigned int ia_valid = attr->ia_valid;
1607  
1608 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1609 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1610 +               ATTR_TAG | ATTR_TIMES_SET)) {
1611                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1612                         return -EPERM;
1613         }
1614 diff -NurpP --minimal linux-3.4.83/fs/block_dev.c linux-3.4.83-vs2.3.3.9/fs/block_dev.c
1615 --- linux-3.4.83/fs/block_dev.c 2014-03-12 09:48:11.000000000 +0000
1616 +++ linux-3.4.83-vs2.3.3.9/fs/block_dev.c       2013-08-13 17:07:36.000000000 +0000
1617 @@ -27,6 +27,7 @@
1618  #include <linux/namei.h>
1619  #include <linux/log2.h>
1620  #include <linux/cleancache.h>
1621 +#include <linux/vs_device.h>
1622  #include <asm/uaccess.h>
1623  #include "internal.h"
1624  
1625 @@ -588,6 +589,7 @@ struct block_device *bdget(dev_t dev)
1626                 bdev->bd_invalidated = 0;
1627                 inode->i_mode = S_IFBLK;
1628                 inode->i_rdev = dev;
1629 +               inode->i_mdev = dev;
1630                 inode->i_bdev = bdev;
1631                 inode->i_data.a_ops = &def_blk_aops;
1632                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1633 @@ -635,6 +637,11 @@ EXPORT_SYMBOL(bdput);
1634  static struct block_device *bd_acquire(struct inode *inode)
1635  {
1636         struct block_device *bdev;
1637 +       dev_t mdev;
1638 +
1639 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1640 +               return NULL;
1641 +       inode->i_mdev = mdev;
1642  
1643         spin_lock(&bdev_lock);
1644         bdev = inode->i_bdev;
1645 @@ -645,7 +652,7 @@ static struct block_device *bd_acquire(s
1646         }
1647         spin_unlock(&bdev_lock);
1648  
1649 -       bdev = bdget(inode->i_rdev);
1650 +       bdev = bdget(mdev);
1651         if (bdev) {
1652                 spin_lock(&bdev_lock);
1653                 if (!inode->i_bdev) {
1654 diff -NurpP --minimal linux-3.4.83/fs/btrfs/ctree.h linux-3.4.83-vs2.3.3.9/fs/btrfs/ctree.h
1655 --- linux-3.4.83/fs/btrfs/ctree.h       2012-05-21 16:07:18.000000000 +0000
1656 +++ linux-3.4.83-vs2.3.3.9/fs/btrfs/ctree.h     2012-05-21 16:15:04.000000000 +0000
1657 @@ -668,11 +668,14 @@ struct btrfs_inode_item {
1658         /* modification sequence number for NFS */
1659         __le64 sequence;
1660  
1661 +       __le16 tag;
1662         /*
1663          * a little future expansion, for more than this we can
1664          * just grow the inode item and version it
1665          */
1666 -       __le64 reserved[4];
1667 +       __le16 reserved16;
1668 +       __le32 reserved32;
1669 +       __le64 reserved[3];
1670         struct btrfs_timespec atime;
1671         struct btrfs_timespec ctime;
1672         struct btrfs_timespec mtime;
1673 @@ -1542,6 +1545,8 @@ struct btrfs_ioctl_defrag_range_args {
1674  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1675  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1676  
1677 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1678 +
1679  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1680  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1681  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1682 @@ -1762,6 +1767,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1683  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1684  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1685  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1686 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1687  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1688  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1689  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1690 @@ -1815,6 +1821,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1691  
1692  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1693  
1694 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1695 +#define BTRFS_INODE_BARRIER            (1 << 25)
1696 +#define BTRFS_INODE_COW                        (1 << 26)
1697 +
1698  
1699  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1700  
1701 @@ -2959,6 +2969,7 @@ extern const struct dentry_operations bt
1702  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1703  void btrfs_update_iflags(struct inode *inode);
1704  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1705 +int btrfs_sync_flags(struct inode *inode, int, int);
1706  int btrfs_defrag_file(struct inode *inode, struct file *file,
1707                       struct btrfs_ioctl_defrag_range_args *range,
1708                       u64 newer_than, unsigned long max_pages);
1709 diff -NurpP --minimal linux-3.4.83/fs/btrfs/disk-io.c linux-3.4.83-vs2.3.3.9/fs/btrfs/disk-io.c
1710 --- linux-3.4.83/fs/btrfs/disk-io.c     2012-05-21 16:07:18.000000000 +0000
1711 +++ linux-3.4.83-vs2.3.3.9/fs/btrfs/disk-io.c   2012-05-21 16:15:04.000000000 +0000
1712 @@ -2083,6 +2083,9 @@ int open_ctree(struct super_block *sb,
1713                 goto fail_alloc;
1714         }
1715  
1716 +       if (btrfs_test_opt(tree_root, TAGGED))
1717 +               sb->s_flags |= MS_TAGGED;
1718 +
1719         features = btrfs_super_incompat_flags(disk_super) &
1720                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1721         if (features) {
1722 diff -NurpP --minimal linux-3.4.83/fs/btrfs/inode.c linux-3.4.83-vs2.3.3.9/fs/btrfs/inode.c
1723 --- linux-3.4.83/fs/btrfs/inode.c       2014-03-12 09:48:11.000000000 +0000
1724 +++ linux-3.4.83-vs2.3.3.9/fs/btrfs/inode.c     2013-07-14 13:38:34.000000000 +0000
1725 @@ -39,6 +39,7 @@
1726  #include <linux/slab.h>
1727  #include <linux/ratelimit.h>
1728  #include <linux/mount.h>
1729 +#include <linux/vs_tag.h>
1730  #include "compat.h"
1731  #include "ctree.h"
1732  #include "disk-io.h"
1733 @@ -2482,6 +2483,8 @@ static void btrfs_read_locked_inode(stru
1734         struct btrfs_key location;
1735         int maybe_acls;
1736         u32 rdev;
1737 +       uid_t uid;
1738 +       gid_t gid;
1739         int ret;
1740         bool filled = false;
1741  
1742 @@ -2509,8 +2512,13 @@ static void btrfs_read_locked_inode(stru
1743                                     struct btrfs_inode_item);
1744         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1745         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1746 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1747 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1748 +
1749 +       uid = btrfs_inode_uid(leaf, inode_item);
1750 +       gid = btrfs_inode_gid(leaf, inode_item);
1751 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1752 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1753 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1754 +               btrfs_inode_tag(leaf, inode_item));
1755         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1756  
1757         tspec = btrfs_inode_atime(inode_item);
1758 @@ -2588,8 +2596,14 @@ static void fill_inode_item(struct btrfs
1759                             struct btrfs_inode_item *item,
1760                             struct inode *inode)
1761  {
1762 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1763 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1764 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1765 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1766 +
1767 +       btrfs_set_inode_uid(leaf, item, uid);
1768 +       btrfs_set_inode_gid(leaf, item, gid);
1769 +#ifdef CONFIG_TAGGING_INTERN
1770 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1771 +#endif
1772         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1773         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1774         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1775 @@ -7590,11 +7604,13 @@ static const struct inode_operations btr
1776         .listxattr      = btrfs_listxattr,
1777         .removexattr    = btrfs_removexattr,
1778         .permission     = btrfs_permission,
1779 +       .sync_flags     = btrfs_sync_flags,
1780         .get_acl        = btrfs_get_acl,
1781  };
1782  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1783         .lookup         = btrfs_lookup,
1784         .permission     = btrfs_permission,
1785 +       .sync_flags     = btrfs_sync_flags,
1786         .get_acl        = btrfs_get_acl,
1787  };
1788  
1789 diff -NurpP --minimal linux-3.4.83/fs/btrfs/ioctl.c linux-3.4.83-vs2.3.3.9/fs/btrfs/ioctl.c
1790 --- linux-3.4.83/fs/btrfs/ioctl.c       2014-03-12 09:48:11.000000000 +0000
1791 +++ linux-3.4.83-vs2.3.3.9/fs/btrfs/ioctl.c     2013-07-14 13:38:34.000000000 +0000
1792 @@ -71,10 +71,13 @@ static unsigned int btrfs_flags_to_ioctl
1793  {
1794         unsigned int iflags = 0;
1795  
1796 -       if (flags & BTRFS_INODE_SYNC)
1797 -               iflags |= FS_SYNC_FL;
1798         if (flags & BTRFS_INODE_IMMUTABLE)
1799                 iflags |= FS_IMMUTABLE_FL;
1800 +       if (flags & BTRFS_INODE_IXUNLINK)
1801 +               iflags |= FS_IXUNLINK_FL;
1802 +
1803 +       if (flags & BTRFS_INODE_SYNC)
1804 +               iflags |= FS_SYNC_FL;
1805         if (flags & BTRFS_INODE_APPEND)
1806                 iflags |= FS_APPEND_FL;
1807         if (flags & BTRFS_INODE_NODUMP)
1808 @@ -91,28 +94,78 @@ static unsigned int btrfs_flags_to_ioctl
1809         else if (flags & BTRFS_INODE_NOCOMPRESS)
1810                 iflags |= FS_NOCOMP_FL;
1811  
1812 +       if (flags & BTRFS_INODE_BARRIER)
1813 +               iflags |= FS_BARRIER_FL;
1814 +       if (flags & BTRFS_INODE_COW)
1815 +               iflags |= FS_COW_FL;
1816         return iflags;
1817  }
1818  
1819  /*
1820 - * Update inode->i_flags based on the btrfs internal flags.
1821 + * Update inode->i_(v)flags based on the btrfs internal flags.
1822   */
1823  void btrfs_update_iflags(struct inode *inode)
1824  {
1825         struct btrfs_inode *ip = BTRFS_I(inode);
1826  
1827 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1828 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1829 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1830  
1831 -       if (ip->flags & BTRFS_INODE_SYNC)
1832 -               inode->i_flags |= S_SYNC;
1833         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1834                 inode->i_flags |= S_IMMUTABLE;
1835 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1836 +               inode->i_flags |= S_IXUNLINK;
1837 +
1838 +       if (ip->flags & BTRFS_INODE_SYNC)
1839 +               inode->i_flags |= S_SYNC;
1840         if (ip->flags & BTRFS_INODE_APPEND)
1841                 inode->i_flags |= S_APPEND;
1842         if (ip->flags & BTRFS_INODE_NOATIME)
1843                 inode->i_flags |= S_NOATIME;
1844         if (ip->flags & BTRFS_INODE_DIRSYNC)
1845                 inode->i_flags |= S_DIRSYNC;
1846 +
1847 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1848 +
1849 +       if (ip->flags & BTRFS_INODE_BARRIER)
1850 +               inode->i_vflags |= V_BARRIER;
1851 +       if (ip->flags & BTRFS_INODE_COW)
1852 +               inode->i_vflags |= V_COW;
1853 +}
1854 +
1855 +/*
1856 + * Update btrfs internal flags from inode->i_(v)flags.
1857 + */
1858 +void btrfs_update_flags(struct inode *inode)
1859 +{
1860 +       struct btrfs_inode *ip = BTRFS_I(inode);
1861 +
1862 +       unsigned int flags = inode->i_flags;
1863 +       unsigned int vflags = inode->i_vflags;
1864 +
1865 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1866 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1867 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1868 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1869 +
1870 +       if (flags & S_IMMUTABLE)
1871 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1872 +       if (flags & S_IXUNLINK)
1873 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1874 +
1875 +       if (flags & S_SYNC)
1876 +               ip->flags |= BTRFS_INODE_SYNC;
1877 +       if (flags & S_APPEND)
1878 +               ip->flags |= BTRFS_INODE_APPEND;
1879 +       if (flags & S_NOATIME)
1880 +               ip->flags |= BTRFS_INODE_NOATIME;
1881 +       if (flags & S_DIRSYNC)
1882 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1883 +
1884 +       if (vflags & V_BARRIER)
1885 +               ip->flags |= BTRFS_INODE_BARRIER;
1886 +       if (vflags & V_COW)
1887 +               ip->flags |= BTRFS_INODE_COW;
1888  }
1889  
1890  /*
1891 @@ -128,6 +181,7 @@ void btrfs_inherit_iflags(struct inode *
1892                 return;
1893  
1894         flags = BTRFS_I(dir)->flags;
1895 +       flags &= ~BTRFS_INODE_BARRIER;
1896  
1897         if (flags & BTRFS_INODE_NOCOMPRESS) {
1898                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1899 @@ -143,6 +197,30 @@ void btrfs_inherit_iflags(struct inode *
1900         btrfs_update_iflags(inode);
1901  }
1902  
1903 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1904 +{
1905 +       struct btrfs_inode *ip = BTRFS_I(inode);
1906 +       struct btrfs_root *root = ip->root;
1907 +       struct btrfs_trans_handle *trans;
1908 +       int ret;
1909 +
1910 +       trans = btrfs_join_transaction(root);
1911 +       BUG_ON(!trans);
1912 +
1913 +       inode->i_flags = flags;
1914 +       inode->i_vflags = vflags;
1915 +       btrfs_update_flags(inode);
1916 +
1917 +       ret = btrfs_update_inode(trans, root, inode);
1918 +       BUG_ON(ret);
1919 +
1920 +       btrfs_update_iflags(inode);
1921 +       inode->i_ctime = CURRENT_TIME;
1922 +       btrfs_end_transaction(trans, root);
1923 +
1924 +       return 0;
1925 +}
1926 +
1927  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1928  {
1929         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1930 @@ -199,7 +277,8 @@ static int btrfs_ioctl_setflags(struct f
1931  
1932         flags = btrfs_mask_flags(inode->i_mode, flags);
1933         oldflags = btrfs_flags_to_ioctl(ip->flags);
1934 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1935 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1936 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1937                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1938                         ret = -EPERM;
1939                         goto out_unlock;
1940 @@ -210,14 +289,19 @@ static int btrfs_ioctl_setflags(struct f
1941         if (ret)
1942                 goto out_unlock;
1943  
1944 -       if (flags & FS_SYNC_FL)
1945 -               ip->flags |= BTRFS_INODE_SYNC;
1946 -       else
1947 -               ip->flags &= ~BTRFS_INODE_SYNC;
1948         if (flags & FS_IMMUTABLE_FL)
1949                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1950         else
1951                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1952 +       if (flags & FS_IXUNLINK_FL)
1953 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1954 +       else
1955 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1956 +
1957 +       if (flags & FS_SYNC_FL)
1958 +               ip->flags |= BTRFS_INODE_SYNC;
1959 +       else
1960 +               ip->flags &= ~BTRFS_INODE_SYNC;
1961         if (flags & FS_APPEND_FL)
1962                 ip->flags |= BTRFS_INODE_APPEND;
1963         else
1964 diff -NurpP --minimal linux-3.4.83/fs/btrfs/super.c linux-3.4.83-vs2.3.3.9/fs/btrfs/super.c
1965 --- linux-3.4.83/fs/btrfs/super.c       2012-05-21 16:07:19.000000000 +0000
1966 +++ linux-3.4.83-vs2.3.3.9/fs/btrfs/super.c     2012-05-21 16:15:04.000000000 +0000
1967 @@ -279,7 +279,7 @@ enum {
1968         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1969         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1970         Opt_check_integrity_print_mask, Opt_fatal_errors,
1971 -       Opt_err,
1972 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1973  };
1974  
1975  static match_table_t tokens = {
1976 @@ -319,6 +319,9 @@ static match_table_t tokens = {
1977         {Opt_check_integrity_including_extent_data, "check_int_data"},
1978         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1979         {Opt_fatal_errors, "fatal_errors=%s"},
1980 +       {Opt_tag, "tag"},
1981 +       {Opt_notag, "notag"},
1982 +       {Opt_tagid, "tagid=%u"},
1983         {Opt_err, NULL},
1984  };
1985  
1986 @@ -564,6 +567,22 @@ int btrfs_parse_options(struct btrfs_roo
1987                                 goto out;
1988                         }
1989                         break;
1990 +#ifndef CONFIG_TAGGING_NONE
1991 +               case Opt_tag:
1992 +                       printk(KERN_INFO "btrfs: use tagging\n");
1993 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1994 +                       break;
1995 +               case Opt_notag:
1996 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1997 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1998 +                       break;
1999 +#endif
2000 +#ifdef CONFIG_PROPAGATE
2001 +               case Opt_tagid:
2002 +                       /* use args[0] */
2003 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2004 +                       break;
2005 +#endif
2006                 case Opt_err:
2007                         printk(KERN_INFO "btrfs: unrecognized mount option "
2008                                "'%s'\n", p);
2009 @@ -1137,6 +1156,12 @@ static int btrfs_remount(struct super_bl
2010                 goto restore;
2011         }
2012  
2013 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2014 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2015 +                       sb->s_id);
2016 +               return -EINVAL;
2017 +       }
2018 +
2019         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2020                 return 0;
2021  
2022 diff -NurpP --minimal linux-3.4.83/fs/char_dev.c linux-3.4.83-vs2.3.3.9/fs/char_dev.c
2023 --- linux-3.4.83/fs/char_dev.c  2012-03-19 18:47:25.000000000 +0000
2024 +++ linux-3.4.83-vs2.3.3.9/fs/char_dev.c        2012-05-21 16:15:04.000000000 +0000
2025 @@ -21,6 +21,8 @@
2026  #include <linux/mutex.h>
2027  #include <linux/backing-dev.h>
2028  #include <linux/tty.h>
2029 +#include <linux/vs_context.h>
2030 +#include <linux/vs_device.h>
2031  
2032  #include "internal.h"
2033  
2034 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2035         struct cdev *p;
2036         struct cdev *new = NULL;
2037         int ret = 0;
2038 +       dev_t mdev;
2039 +
2040 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2041 +               return -EPERM;
2042 +       inode->i_mdev = mdev;
2043  
2044         spin_lock(&cdev_lock);
2045         p = inode->i_cdev;
2046         if (!p) {
2047                 struct kobject *kobj;
2048                 int idx;
2049 +
2050                 spin_unlock(&cdev_lock);
2051 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2052 +
2053 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2054                 if (!kobj)
2055                         return -ENXIO;
2056                 new = container_of(kobj, struct cdev, kobj);
2057 diff -NurpP --minimal linux-3.4.83/fs/dcache.c linux-3.4.83-vs2.3.3.9/fs/dcache.c
2058 --- linux-3.4.83/fs/dcache.c    2014-03-12 09:48:12.000000000 +0000
2059 +++ linux-3.4.83-vs2.3.3.9/fs/dcache.c  2014-03-12 09:55:28.000000000 +0000
2060 @@ -37,6 +37,7 @@
2061  #include <linux/rculist_bl.h>
2062  #include <linux/prefetch.h>
2063  #include <linux/ratelimit.h>
2064 +#include <linux/vs_limit.h>
2065  #include "internal.h"
2066  #include "mount.h"
2067  
2068 @@ -601,6 +602,8 @@ int d_invalidate(struct dentry * dentry)
2069                 spin_lock(&dentry->d_lock);
2070         }
2071  
2072 +       vx_dentry_dec(dentry);
2073 +
2074         /*
2075          * Somebody else still using it?
2076          *
2077 @@ -630,6 +633,7 @@ EXPORT_SYMBOL(d_invalidate);
2078  static inline void __dget_dlock(struct dentry *dentry)
2079  {
2080         dentry->d_count++;
2081 +       vx_dentry_inc(dentry);
2082  }
2083  
2084  static inline void __dget(struct dentry *dentry)
2085 @@ -1260,6 +1264,9 @@ struct dentry *__d_alloc(struct super_bl
2086         struct dentry *dentry;
2087         char *dname;
2088  
2089 +       if (!vx_dentry_avail(1))
2090 +               return NULL;
2091 +
2092         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2093         if (!dentry)
2094                 return NULL;
2095 @@ -1282,6 +1289,7 @@ struct dentry *__d_alloc(struct super_bl
2096  
2097         dentry->d_count = 1;
2098         dentry->d_flags = 0;
2099 +       vx_dentry_inc(dentry);
2100         spin_lock_init(&dentry->d_lock);
2101         seqcount_init(&dentry->d_seq);
2102         dentry->d_inode = NULL;
2103 @@ -1943,6 +1951,7 @@ struct dentry *__d_lookup(struct dentry
2104                 }
2105  
2106                 dentry->d_count++;
2107 +               vx_dentry_inc(dentry);
2108                 found = dentry;
2109                 spin_unlock(&dentry->d_lock);
2110                 break;
2111 diff -NurpP --minimal linux-3.4.83/fs/devpts/inode.c linux-3.4.83-vs2.3.3.9/fs/devpts/inode.c
2112 --- linux-3.4.83/fs/devpts/inode.c      2014-03-12 09:48:12.000000000 +0000
2113 +++ linux-3.4.83-vs2.3.3.9/fs/devpts/inode.c    2014-03-12 09:55:28.000000000 +0000
2114 @@ -25,6 +25,7 @@
2115  #include <linux/parser.h>
2116  #include <linux/fsnotify.h>
2117  #include <linux/seq_file.h>
2118 +#include <linux/vs_base.h>
2119  
2120  #define DEVPTS_DEFAULT_MODE 0600
2121  /*
2122 @@ -36,6 +37,21 @@
2123  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2124  #define PTMX_MINOR     2
2125  
2126 +static int devpts_permission(struct inode *inode, int mask)
2127 +{
2128 +       int ret = -EACCES;
2129 +
2130 +       /* devpts is xid tagged */
2131 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2132 +               ret = generic_permission(inode, mask);
2133 +       return ret;
2134 +}
2135 +
2136 +static struct inode_operations devpts_file_inode_operations = {
2137 +       .permission     = devpts_permission,
2138 +};
2139 +
2140 +
2141  /*
2142   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2143   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2144 @@ -328,6 +344,34 @@ static int devpts_show_options(struct se
2145         return 0;
2146  }
2147  
2148 +static int devpts_filter(struct dentry *de)
2149 +{
2150 +       xid_t xid = 0;
2151 +
2152 +       /* devpts is xid tagged */
2153 +       if (de && de->d_inode)
2154 +               xid = (xid_t)de->d_inode->i_tag;
2155 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2156 +       else
2157 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2158 +                       de->d_name.len, de->d_name.name);
2159 +#endif
2160 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2161 +}
2162 +
2163 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2164 +{
2165 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2166 +}
2167 +
2168 +static struct file_operations devpts_dir_operations = {
2169 +       .open           = dcache_dir_open,
2170 +       .release        = dcache_dir_close,
2171 +       .llseek         = dcache_dir_lseek,
2172 +       .read           = generic_read_dir,
2173 +       .readdir        = devpts_readdir,
2174 +};
2175 +
2176  static const struct super_operations devpts_sops = {
2177         .statfs         = simple_statfs,
2178         .remount_fs     = devpts_remount,
2179 @@ -371,8 +415,10 @@ devpts_fill_super(struct super_block *s,
2180         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2181         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2182         inode->i_op = &simple_dir_inode_operations;
2183 -       inode->i_fop = &simple_dir_operations;
2184 +       inode->i_fop = &devpts_dir_operations;
2185         set_nlink(inode, 2);
2186 +       /* devpts is xid tagged */
2187 +       inode->i_tag = (tag_t)vx_current_xid();
2188  
2189         s->s_root = d_make_root(inode);
2190         if (s->s_root)
2191 @@ -565,6 +611,9 @@ int devpts_pty_new(struct inode *ptmx_in
2192         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2193         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2194         init_special_inode(inode, S_IFCHR|opts->mode, device);
2195 +       /* devpts is xid tagged */
2196 +       inode->i_tag = (tag_t)vx_current_xid();
2197 +       inode->i_op = &devpts_file_inode_operations;
2198         inode->i_private = tty;
2199         tty->driver_data = inode;
2200  
2201 diff -NurpP --minimal linux-3.4.83/fs/ext2/balloc.c linux-3.4.83-vs2.3.3.9/fs/ext2/balloc.c
2202 --- linux-3.4.83/fs/ext2/balloc.c       2012-01-09 15:14:54.000000000 +0000
2203 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/balloc.c     2012-05-21 16:15:04.000000000 +0000
2204 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block
2205                         start = 0;
2206                 end = EXT2_BLOCKS_PER_GROUP(sb);
2207         }
2208 -
2209         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2210  
2211  repeat:
2212 diff -NurpP --minimal linux-3.4.83/fs/ext2/ext2.h linux-3.4.83-vs2.3.3.9/fs/ext2/ext2.h
2213 --- linux-3.4.83/fs/ext2/ext2.h 2012-05-21 16:07:20.000000000 +0000
2214 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/ext2.h       2012-05-21 16:15:05.000000000 +0000
2215 @@ -244,8 +244,12 @@ struct ext2_group_desc
2216  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2217  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2218  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2219 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2220  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2221  
2222 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2223 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2224 +
2225  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2226  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2227  
2228 @@ -329,7 +333,8 @@ struct ext2_inode {
2229                         __u16   i_pad1;
2230                         __le16  l_i_uid_high;   /* these 2 fields    */
2231                         __le16  l_i_gid_high;   /* were reserved2[0] */
2232 -                       __u32   l_i_reserved2;
2233 +                       __le16  l_i_tag;        /* Context Tag */
2234 +                       __u16   l_i_reserved2;
2235                 } linux2;
2236                 struct {
2237                         __u8    h_i_frag;       /* Fragment number */
2238 @@ -357,6 +362,7 @@ struct ext2_inode {
2239  #define i_gid_low      i_gid
2240  #define i_uid_high     osd2.linux2.l_i_uid_high
2241  #define i_gid_high     osd2.linux2.l_i_gid_high
2242 +#define i_raw_tag      osd2.linux2.l_i_tag
2243  #define i_reserved2    osd2.linux2.l_i_reserved2
2244  
2245  /*
2246 @@ -384,6 +390,7 @@ struct ext2_inode {
2247  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2248  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2249  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2250 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2251  
2252  
2253  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2254 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2255  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2256  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2257                        u64 start, u64 len);
2258 +extern int ext2_sync_flags(struct inode *, int, int);
2259  
2260  /* ioctl.c */
2261  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2262 diff -NurpP --minimal linux-3.4.83/fs/ext2/file.c linux-3.4.83-vs2.3.3.9/fs/ext2/file.c
2263 --- linux-3.4.83/fs/ext2/file.c 2011-10-24 16:45:27.000000000 +0000
2264 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/file.c       2012-05-21 16:15:05.000000000 +0000
2265 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2266         .setattr        = ext2_setattr,
2267         .get_acl        = ext2_get_acl,
2268         .fiemap         = ext2_fiemap,
2269 +       .sync_flags     = ext2_sync_flags,
2270  };
2271 diff -NurpP --minimal linux-3.4.83/fs/ext2/ialloc.c linux-3.4.83-vs2.3.3.9/fs/ext2/ialloc.c
2272 --- linux-3.4.83/fs/ext2/ialloc.c       2012-03-19 18:47:25.000000000 +0000
2273 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/ialloc.c     2012-05-21 16:15:05.000000000 +0000
2274 @@ -17,6 +17,7 @@
2275  #include <linux/backing-dev.h>
2276  #include <linux/buffer_head.h>
2277  #include <linux/random.h>
2278 +#include <linux/vs_tag.h>
2279  #include "ext2.h"
2280  #include "xattr.h"
2281  #include "acl.h"
2282 @@ -549,6 +550,7 @@ got:
2283                 inode->i_mode = mode;
2284                 inode->i_uid = current_fsuid();
2285                 inode->i_gid = dir->i_gid;
2286 +               inode->i_tag = dx_current_fstag(sb);
2287         } else
2288                 inode_init_owner(inode, dir, mode);
2289  
2290 diff -NurpP --minimal linux-3.4.83/fs/ext2/inode.c linux-3.4.83-vs2.3.3.9/fs/ext2/inode.c
2291 --- linux-3.4.83/fs/ext2/inode.c        2012-03-19 18:47:25.000000000 +0000
2292 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/inode.c      2012-05-21 16:15:05.000000000 +0000
2293 @@ -31,6 +31,7 @@
2294  #include <linux/mpage.h>
2295  #include <linux/fiemap.h>
2296  #include <linux/namei.h>
2297 +#include <linux/vs_tag.h>
2298  #include "ext2.h"
2299  #include "acl.h"
2300  #include "xip.h"
2301 @@ -1162,7 +1163,7 @@ static void ext2_truncate_blocks(struct
2302                 return;
2303         if (ext2_inode_is_fast_symlink(inode))
2304                 return;
2305 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2306 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2307                 return;
2308         __ext2_truncate_blocks(inode, offset);
2309  }
2310 @@ -1253,36 +1254,61 @@ void ext2_set_inode_flags(struct inode *
2311  {
2312         unsigned int flags = EXT2_I(inode)->i_flags;
2313  
2314 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2315 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2316 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2317 +
2318 +
2319 +       if (flags & EXT2_IMMUTABLE_FL)
2320 +               inode->i_flags |= S_IMMUTABLE;
2321 +       if (flags & EXT2_IXUNLINK_FL)
2322 +               inode->i_flags |= S_IXUNLINK;
2323 +
2324         if (flags & EXT2_SYNC_FL)
2325                 inode->i_flags |= S_SYNC;
2326         if (flags & EXT2_APPEND_FL)
2327                 inode->i_flags |= S_APPEND;
2328 -       if (flags & EXT2_IMMUTABLE_FL)
2329 -               inode->i_flags |= S_IMMUTABLE;
2330         if (flags & EXT2_NOATIME_FL)
2331                 inode->i_flags |= S_NOATIME;
2332         if (flags & EXT2_DIRSYNC_FL)
2333                 inode->i_flags |= S_DIRSYNC;
2334 +
2335 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2336 +
2337 +       if (flags & EXT2_BARRIER_FL)
2338 +               inode->i_vflags |= V_BARRIER;
2339 +       if (flags & EXT2_COW_FL)
2340 +               inode->i_vflags |= V_COW;
2341  }
2342  
2343  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2344  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2345  {
2346         unsigned int flags = ei->vfs_inode.i_flags;
2347 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2348 +
2349 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2350 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2351 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2352 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2353 +
2354 +       if (flags & S_IMMUTABLE)
2355 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2356 +       if (flags & S_IXUNLINK)
2357 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2358  
2359 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2360 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2361         if (flags & S_SYNC)
2362                 ei->i_flags |= EXT2_SYNC_FL;
2363         if (flags & S_APPEND)
2364                 ei->i_flags |= EXT2_APPEND_FL;
2365 -       if (flags & S_IMMUTABLE)
2366 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2367         if (flags & S_NOATIME)
2368                 ei->i_flags |= EXT2_NOATIME_FL;
2369         if (flags & S_DIRSYNC)
2370                 ei->i_flags |= EXT2_DIRSYNC_FL;
2371 +
2372 +       if (vflags & V_BARRIER)
2373 +               ei->i_flags |= EXT2_BARRIER_FL;
2374 +       if (vflags & V_COW)
2375 +               ei->i_flags |= EXT2_COW_FL;
2376  }
2377  
2378  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2379 @@ -1292,6 +1318,8 @@ struct inode *ext2_iget (struct super_bl
2380         struct ext2_inode *raw_inode;
2381         struct inode *inode;
2382         long ret = -EIO;
2383 +       uid_t uid;
2384 +       gid_t gid;
2385         int n;
2386  
2387         inode = iget_locked(sb, ino);
2388 @@ -1310,12 +1338,16 @@ struct inode *ext2_iget (struct super_bl
2389         }
2390  
2391         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2392 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2393 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2394 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2395 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2396         if (!(test_opt (inode->i_sb, NO_UID32))) {
2397 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2398 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2399 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2400 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2401         }
2402 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2403 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2404 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2405 +               le16_to_cpu(raw_inode->i_raw_tag));
2406         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2407         inode->i_size = le32_to_cpu(raw_inode->i_size);
2408         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2409 @@ -1413,8 +1445,8 @@ static int __ext2_write_inode(struct ino
2410         struct ext2_inode_info *ei = EXT2_I(inode);
2411         struct super_block *sb = inode->i_sb;
2412         ino_t ino = inode->i_ino;
2413 -       uid_t uid = inode->i_uid;
2414 -       gid_t gid = inode->i_gid;
2415 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2416 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2417         struct buffer_head * bh;
2418         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2419         int n;
2420 @@ -1450,6 +1482,9 @@ static int __ext2_write_inode(struct ino
2421                 raw_inode->i_uid_high = 0;
2422                 raw_inode->i_gid_high = 0;
2423         }
2424 +#ifdef CONFIG_TAGGING_INTERN
2425 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2426 +#endif
2427         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2428         raw_inode->i_size = cpu_to_le32(inode->i_size);
2429         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2430 @@ -1530,7 +1565,8 @@ int ext2_setattr(struct dentry *dentry,
2431         if (is_quota_modification(inode, iattr))
2432                 dquot_initialize(inode);
2433         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2434 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2435 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2436 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2437                 error = dquot_transfer(inode, iattr);
2438                 if (error)
2439                         return error;
2440 diff -NurpP --minimal linux-3.4.83/fs/ext2/ioctl.c linux-3.4.83-vs2.3.3.9/fs/ext2/ioctl.c
2441 --- linux-3.4.83/fs/ext2/ioctl.c        2012-03-19 18:47:25.000000000 +0000
2442 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/ioctl.c      2012-05-21 16:15:05.000000000 +0000
2443 @@ -17,6 +17,16 @@
2444  #include <asm/uaccess.h>
2445  
2446  
2447 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2448 +{
2449 +       inode->i_flags = flags;
2450 +       inode->i_vflags = vflags;
2451 +       ext2_get_inode_flags(EXT2_I(inode));
2452 +       inode->i_ctime = CURRENT_TIME_SEC;
2453 +       mark_inode_dirty(inode);
2454 +       return 0;
2455 +}
2456 +
2457  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2458  {
2459         struct inode *inode = filp->f_dentry->d_inode;
2460 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2461  
2462                 flags = ext2_mask_flags(inode->i_mode, flags);
2463  
2464 +               if (IS_BARRIER(inode)) {
2465 +                       vxwprintk_task(1, "messing with the barrier.");
2466 +                       return -EACCES;
2467 +               }
2468 +
2469                 mutex_lock(&inode->i_mutex);
2470                 /* Is it quota file? Do not allow user to mess with it */
2471                 if (IS_NOQUOTA(inode)) {
2472 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2473                  *
2474                  * This test looks nicer. Thanks to Pauline Middelink
2475                  */
2476 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2477 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2478 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2479 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2480                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2481                                 mutex_unlock(&inode->i_mutex);
2482                                 ret = -EPERM;
2483 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2484                         }
2485                 }
2486  
2487 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2488 +               flags &= EXT2_FL_USER_MODIFIABLE;
2489                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2490                 ei->i_flags = flags;
2491  
2492 diff -NurpP --minimal linux-3.4.83/fs/ext2/namei.c linux-3.4.83-vs2.3.3.9/fs/ext2/namei.c
2493 --- linux-3.4.83/fs/ext2/namei.c        2012-05-21 16:07:20.000000000 +0000
2494 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/namei.c      2012-05-21 16:15:05.000000000 +0000
2495 @@ -32,6 +32,7 @@
2496  
2497  #include <linux/pagemap.h>
2498  #include <linux/quotaops.h>
2499 +#include <linux/vs_tag.h>
2500  #include "ext2.h"
2501  #include "xattr.h"
2502  #include "acl.h"
2503 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2504                                         (unsigned long) ino);
2505                         return ERR_PTR(-EIO);
2506                 }
2507 +               dx_propagate_tag(nd, inode);
2508         }
2509         return d_splice_alias(inode, dentry);
2510  }
2511 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2512         .removexattr    = generic_removexattr,
2513  #endif
2514         .setattr        = ext2_setattr,
2515 +       .sync_flags     = ext2_sync_flags,
2516         .get_acl        = ext2_get_acl,
2517  };
2518  
2519 diff -NurpP --minimal linux-3.4.83/fs/ext2/super.c linux-3.4.83-vs2.3.3.9/fs/ext2/super.c
2520 --- linux-3.4.83/fs/ext2/super.c        2012-05-21 16:07:20.000000000 +0000
2521 +++ linux-3.4.83-vs2.3.3.9/fs/ext2/super.c      2012-05-21 16:15:05.000000000 +0000
2522 @@ -393,7 +393,8 @@ enum {
2523         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2524         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2525         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2526 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2527 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2528 +       Opt_tag, Opt_notag, Opt_tagid
2529  };
2530  
2531  static const match_table_t tokens = {
2532 @@ -421,6 +422,9 @@ static const match_table_t tokens = {
2533         {Opt_acl, "acl"},
2534         {Opt_noacl, "noacl"},
2535         {Opt_xip, "xip"},
2536 +       {Opt_tag, "tag"},
2537 +       {Opt_notag, "notag"},
2538 +       {Opt_tagid, "tagid=%u"},
2539         {Opt_grpquota, "grpquota"},
2540         {Opt_ignore, "noquota"},
2541         {Opt_quota, "quota"},
2542 @@ -491,6 +495,20 @@ static int parse_options(char *options,
2543                 case Opt_nouid32:
2544                         set_opt (sbi->s_mount_opt, NO_UID32);
2545                         break;
2546 +#ifndef CONFIG_TAGGING_NONE
2547 +               case Opt_tag:
2548 +                       set_opt (sbi->s_mount_opt, TAGGED);
2549 +                       break;
2550 +               case Opt_notag:
2551 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2552 +                       break;
2553 +#endif
2554 +#ifdef CONFIG_PROPAGATE
2555 +               case Opt_tagid:
2556 +                       /* use args[0] */
2557 +                       set_opt (sbi->s_mount_opt, TAGGED);
2558 +                       break;
2559 +#endif
2560                 case Opt_nocheck:
2561                         clear_opt (sbi->s_mount_opt, CHECK);
2562                         break;
2563 @@ -849,6 +867,8 @@ static int ext2_fill_super(struct super_
2564         if (!parse_options((char *) data, sb))
2565                 goto failed_mount;
2566  
2567 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2568 +               sb->s_flags |= MS_TAGGED;
2569         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2570                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2571                  MS_POSIXACL : 0);
2572 @@ -1222,6 +1242,14 @@ static int ext2_remount (struct super_bl
2573                 err = -EINVAL;
2574                 goto restore_opts;
2575         }
2576 +
2577 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2578 +               !(sb->s_flags & MS_TAGGED)) {
2579 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2580 +                      sb->s_id);
2581 +               err = -EINVAL;
2582 +               goto restore_opts;
2583 +       }
2584  
2585         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2586                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2587 diff -NurpP --minimal linux-3.4.83/fs/ext3/ext3.h linux-3.4.83-vs2.3.3.9/fs/ext3/ext3.h
2588 --- linux-3.4.83/fs/ext3/ext3.h 2014-03-12 09:48:13.000000000 +0000
2589 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/ext3.h       2014-03-12 09:55:28.000000000 +0000
2590 @@ -151,10 +151,14 @@ struct ext3_group_desc
2591  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2592  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2593  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2594 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2595  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2596  
2597 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2598 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2599 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2600 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2601 +
2602 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2603 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2604  
2605  /* Flags that should be inherited by new inodes from their parent. */
2606  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2607 @@ -290,7 +294,8 @@ struct ext3_inode {
2608                         __u16   i_pad1;
2609                         __le16  l_i_uid_high;   /* these 2 fields    */
2610                         __le16  l_i_gid_high;   /* were reserved2[0] */
2611 -                       __u32   l_i_reserved2;
2612 +                       __le16  l_i_tag;        /* Context Tag */
2613 +                       __u16   l_i_reserved2;
2614                 } linux2;
2615                 struct {
2616                         __u8    h_i_frag;       /* Fragment number */
2617 @@ -320,6 +325,7 @@ struct ext3_inode {
2618  #define i_gid_low      i_gid
2619  #define i_uid_high     osd2.linux2.l_i_uid_high
2620  #define i_gid_high     osd2.linux2.l_i_gid_high
2621 +#define i_raw_tag      osd2.linux2.l_i_tag
2622  #define i_reserved2    osd2.linux2.l_i_reserved2
2623  
2624  /*
2625 @@ -364,6 +370,7 @@ struct ext3_inode {
2626  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2627  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2628                                                   * error in ordered mode */
2629 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2630  
2631  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2632  #ifndef _LINUX_EXT2_FS_H
2633 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2634  extern void ext3_set_aops(struct inode *inode);
2635  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2636                        u64 start, u64 len);
2637 +extern int ext3_sync_flags(struct inode *, int, int);
2638  
2639  /* ioctl.c */
2640  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2641 diff -NurpP --minimal linux-3.4.83/fs/ext3/file.c linux-3.4.83-vs2.3.3.9/fs/ext3/file.c
2642 --- linux-3.4.83/fs/ext3/file.c 2012-05-21 16:07:20.000000000 +0000
2643 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/file.c       2012-05-21 16:15:05.000000000 +0000
2644 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2645  #endif
2646         .get_acl        = ext3_get_acl,
2647         .fiemap         = ext3_fiemap,
2648 +       .sync_flags     = ext3_sync_flags,
2649  };
2650  
2651 diff -NurpP --minimal linux-3.4.83/fs/ext3/ialloc.c linux-3.4.83-vs2.3.3.9/fs/ext3/ialloc.c
2652 --- linux-3.4.83/fs/ext3/ialloc.c       2012-05-21 16:07:20.000000000 +0000
2653 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/ialloc.c     2012-05-21 16:15:05.000000000 +0000
2654 @@ -14,6 +14,7 @@
2655  
2656  #include <linux/quotaops.h>
2657  #include <linux/random.h>
2658 +#include <linux/vs_tag.h>
2659  
2660  #include "ext3.h"
2661  #include "xattr.h"
2662 @@ -485,6 +486,7 @@ got:
2663                 inode->i_mode = mode;
2664                 inode->i_uid = current_fsuid();
2665                 inode->i_gid = dir->i_gid;
2666 +               inode->i_tag = dx_current_fstag(sb);
2667         } else
2668                 inode_init_owner(inode, dir, mode);
2669  
2670 diff -NurpP --minimal linux-3.4.83/fs/ext3/inode.c linux-3.4.83-vs2.3.3.9/fs/ext3/inode.c
2671 --- linux-3.4.83/fs/ext3/inode.c        2014-03-12 09:48:13.000000000 +0000
2672 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/inode.c      2013-08-13 17:07:36.000000000 +0000
2673 @@ -27,6 +27,8 @@
2674  #include <linux/writeback.h>
2675  #include <linux/mpage.h>
2676  #include <linux/namei.h>
2677 +#include <linux/vs_tag.h>
2678 +
2679  #include "ext3.h"
2680  #include "xattr.h"
2681  #include "acl.h"
2682 @@ -2849,36 +2851,60 @@ void ext3_set_inode_flags(struct inode *
2683  {
2684         unsigned int flags = EXT3_I(inode)->i_flags;
2685  
2686 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2687 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2688 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2689 +
2690 +       if (flags & EXT3_IMMUTABLE_FL)
2691 +               inode->i_flags |= S_IMMUTABLE;
2692 +       if (flags & EXT3_IXUNLINK_FL)
2693 +               inode->i_flags |= S_IXUNLINK;
2694 +
2695         if (flags & EXT3_SYNC_FL)
2696                 inode->i_flags |= S_SYNC;
2697         if (flags & EXT3_APPEND_FL)
2698                 inode->i_flags |= S_APPEND;
2699 -       if (flags & EXT3_IMMUTABLE_FL)
2700 -               inode->i_flags |= S_IMMUTABLE;
2701         if (flags & EXT3_NOATIME_FL)
2702                 inode->i_flags |= S_NOATIME;
2703         if (flags & EXT3_DIRSYNC_FL)
2704                 inode->i_flags |= S_DIRSYNC;
2705 +
2706 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2707 +
2708 +       if (flags & EXT3_BARRIER_FL)
2709 +               inode->i_vflags |= V_BARRIER;
2710 +       if (flags & EXT3_COW_FL)
2711 +               inode->i_vflags |= V_COW;
2712  }
2713  
2714  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2715  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2716  {
2717         unsigned int flags = ei->vfs_inode.i_flags;
2718 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2719 +
2720 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2721 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2722 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2723 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2724 +
2725 +       if (flags & S_IMMUTABLE)
2726 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2727 +       if (flags & S_IXUNLINK)
2728 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2729  
2730 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2731 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2732         if (flags & S_SYNC)
2733                 ei->i_flags |= EXT3_SYNC_FL;
2734         if (flags & S_APPEND)
2735                 ei->i_flags |= EXT3_APPEND_FL;
2736 -       if (flags & S_IMMUTABLE)
2737 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2738         if (flags & S_NOATIME)
2739                 ei->i_flags |= EXT3_NOATIME_FL;
2740         if (flags & S_DIRSYNC)
2741                 ei->i_flags |= EXT3_DIRSYNC_FL;
2742 +
2743 +       if (vflags & V_BARRIER)
2744 +               ei->i_flags |= EXT3_BARRIER_FL;
2745 +       if (vflags & V_COW)
2746 +               ei->i_flags |= EXT3_COW_FL;
2747  }
2748  
2749  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2750 @@ -2892,6 +2918,8 @@ struct inode *ext3_iget(struct super_blo
2751         transaction_t *transaction;
2752         long ret;
2753         int block;
2754 +       uid_t uid;
2755 +       gid_t gid;
2756  
2757         inode = iget_locked(sb, ino);
2758         if (!inode)
2759 @@ -2908,12 +2936,16 @@ struct inode *ext3_iget(struct super_blo
2760         bh = iloc.bh;
2761         raw_inode = ext3_raw_inode(&iloc);
2762         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2763 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2764 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2765 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2766 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2767         if(!(test_opt (inode->i_sb, NO_UID32))) {
2768 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2769 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2770 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2771 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2772         }
2773 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2774 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2775 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2776 +               le16_to_cpu(raw_inode->i_raw_tag));
2777         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2778         inode->i_size = le32_to_cpu(raw_inode->i_size);
2779         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2780 @@ -3068,6 +3100,8 @@ static int ext3_do_update_inode(handle_t
2781         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2782         struct ext3_inode_info *ei = EXT3_I(inode);
2783         struct buffer_head *bh = iloc->bh;
2784 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2785 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2786         int err = 0, rc, block;
2787         int need_datasync = 0;
2788         __le32 disksize;
2789 @@ -3084,29 +3118,32 @@ again:
2790         ext3_get_inode_flags(ei);
2791         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2792         if(!(test_opt(inode->i_sb, NO_UID32))) {
2793 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2794 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2795 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2796 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2797  /*
2798   * Fix up interoperability with old kernels. Otherwise, old inodes get
2799   * re-used with the upper 16 bits of the uid/gid intact
2800   */
2801                 if(!ei->i_dtime) {
2802                         raw_inode->i_uid_high =
2803 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2804 +                               cpu_to_le16(high_16_bits(uid));
2805                         raw_inode->i_gid_high =
2806 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2807 +                               cpu_to_le16(high_16_bits(gid));
2808                 } else {
2809                         raw_inode->i_uid_high = 0;
2810                         raw_inode->i_gid_high = 0;
2811                 }
2812         } else {
2813                 raw_inode->i_uid_low =
2814 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2815 +                       cpu_to_le16(fs_high2lowuid(uid));
2816                 raw_inode->i_gid_low =
2817 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2818 +                       cpu_to_le16(fs_high2lowgid(gid));
2819                 raw_inode->i_uid_high = 0;
2820                 raw_inode->i_gid_high = 0;
2821         }
2822 +#ifdef CONFIG_TAGGING_INTERN
2823 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2824 +#endif
2825         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2826         disksize = cpu_to_le32(ei->i_disksize);
2827         if (disksize != raw_inode->i_size) {
2828 @@ -3275,7 +3312,8 @@ int ext3_setattr(struct dentry *dentry,
2829         if (is_quota_modification(inode, attr))
2830                 dquot_initialize(inode);
2831         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2832 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2833 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2834 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2835                 handle_t *handle;
2836  
2837                 /* (user+group)*(old+new) structure, inode write (sb,
2838 @@ -3297,6 +3335,8 @@ int ext3_setattr(struct dentry *dentry,
2839                         inode->i_uid = attr->ia_uid;
2840                 if (attr->ia_valid & ATTR_GID)
2841                         inode->i_gid = attr->ia_gid;
2842 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2843 +                       inode->i_tag = attr->ia_tag;
2844                 error = ext3_mark_inode_dirty(handle, inode);
2845                 ext3_journal_stop(handle);
2846         }
2847 diff -NurpP --minimal linux-3.4.83/fs/ext3/ioctl.c linux-3.4.83-vs2.3.3.9/fs/ext3/ioctl.c
2848 --- linux-3.4.83/fs/ext3/ioctl.c        2012-05-21 16:07:20.000000000 +0000
2849 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/ioctl.c      2012-05-21 16:15:05.000000000 +0000
2850 @@ -12,6 +12,34 @@
2851  #include <asm/uaccess.h>
2852  #include "ext3.h"
2853  
2854 +
2855 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2856 +{
2857 +       handle_t *handle = NULL;
2858 +       struct ext3_iloc iloc;
2859 +       int err;
2860 +
2861 +       handle = ext3_journal_start(inode, 1);
2862 +       if (IS_ERR(handle))
2863 +               return PTR_ERR(handle);
2864 +
2865 +       if (IS_SYNC(inode))
2866 +               handle->h_sync = 1;
2867 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2868 +       if (err)
2869 +               goto flags_err;
2870 +
2871 +       inode->i_flags = flags;
2872 +       inode->i_vflags = vflags;
2873 +       ext3_get_inode_flags(EXT3_I(inode));
2874 +       inode->i_ctime = CURRENT_TIME_SEC;
2875 +
2876 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2877 +flags_err:
2878 +       ext3_journal_stop(handle);
2879 +       return err;
2880 +}
2881 +
2882  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2883  {
2884         struct inode *inode = filp->f_dentry->d_inode;
2885 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2886  
2887                 flags = ext3_mask_flags(inode->i_mode, flags);
2888  
2889 +               if (IS_BARRIER(inode)) {
2890 +                       vxwprintk_task(1, "messing with the barrier.");
2891 +                       return -EACCES;
2892 +               }
2893 +
2894                 mutex_lock(&inode->i_mutex);
2895  
2896                 /* Is it quota file? Do not allow user to mess with it */
2897 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2898                  *
2899                  * This test looks nicer. Thanks to Pauline Middelink
2900                  */
2901 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2902 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2903 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2904 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2905                         if (!capable(CAP_LINUX_IMMUTABLE))
2906                                 goto flags_out;
2907                 }
2908 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2909                 if (err)
2910                         goto flags_err;
2911  
2912 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2913 +               flags &= EXT3_FL_USER_MODIFIABLE;
2914                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2915                 ei->i_flags = flags;
2916  
2917 diff -NurpP --minimal linux-3.4.83/fs/ext3/namei.c linux-3.4.83-vs2.3.3.9/fs/ext3/namei.c
2918 --- linux-3.4.83/fs/ext3/namei.c        2014-03-12 09:48:13.000000000 +0000
2919 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/namei.c      2013-08-13 17:07:36.000000000 +0000
2920 @@ -25,6 +25,8 @@
2921   */
2922  
2923  #include <linux/quotaops.h>
2924 +#include <linux/vs_tag.h>
2925 +
2926  #include "ext3.h"
2927  #include "namei.h"
2928  #include "xattr.h"
2929 @@ -912,6 +914,7 @@ restart:
2930                                         submit_bh(READ | REQ_META | REQ_PRIO,
2931                                                   bh);
2932                                 }
2933 +               dx_propagate_tag(nd, inode);
2934                         }
2935                 }
2936                 if ((bh = bh_use[ra_ptr++]) == NULL)
2937 @@ -2523,6 +2526,7 @@ const struct inode_operations ext3_dir_i
2938         .listxattr      = ext3_listxattr,
2939         .removexattr    = generic_removexattr,
2940  #endif
2941 +       .sync_flags     = ext3_sync_flags,
2942         .get_acl        = ext3_get_acl,
2943  };
2944  
2945 diff -NurpP --minimal linux-3.4.83/fs/ext3/super.c linux-3.4.83-vs2.3.3.9/fs/ext3/super.c
2946 --- linux-3.4.83/fs/ext3/super.c        2014-03-12 09:48:13.000000000 +0000
2947 +++ linux-3.4.83-vs2.3.3.9/fs/ext3/super.c      2013-03-30 21:29:17.000000000 +0000
2948 @@ -820,7 +820,8 @@ enum {
2949         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2950         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2951         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2952 -       Opt_resize, Opt_usrquota, Opt_grpquota
2953 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2954 +       Opt_tag, Opt_notag, Opt_tagid
2955  };
2956  
2957  static const match_table_t tokens = {
2958 @@ -877,6 +878,9 @@ static const match_table_t tokens = {
2959         {Opt_barrier, "barrier"},
2960         {Opt_nobarrier, "nobarrier"},
2961         {Opt_resize, "resize"},
2962 +       {Opt_tag, "tag"},
2963 +       {Opt_notag, "notag"},
2964 +       {Opt_tagid, "tagid=%u"},
2965         {Opt_err, NULL},
2966  };
2967  
2968 @@ -1029,6 +1033,20 @@ static int parse_options (char *options,
2969                 case Opt_nouid32:
2970                         set_opt (sbi->s_mount_opt, NO_UID32);
2971                         break;
2972 +#ifndef CONFIG_TAGGING_NONE
2973 +               case Opt_tag:
2974 +                       set_opt (sbi->s_mount_opt, TAGGED);
2975 +                       break;
2976 +               case Opt_notag:
2977 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2978 +                       break;
2979 +#endif
2980 +#ifdef CONFIG_PROPAGATE
2981 +               case Opt_tagid:
2982 +                       /* use args[0] */
2983 +                       set_opt (sbi->s_mount_opt, TAGGED);
2984 +                       break;
2985 +#endif
2986                 case Opt_nocheck:
2987                         clear_opt (sbi->s_mount_opt, CHECK);
2988                         break;
2989 @@ -1727,6 +1745,9 @@ static int ext3_fill_super (struct super
2990                             NULL, 0))
2991                 goto failed_mount;
2992  
2993 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2994 +               sb->s_flags |= MS_TAGGED;
2995 +
2996         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2997                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2998  
2999 @@ -2608,6 +2629,14 @@ static int ext3_remount (struct super_bl
3000         if (test_opt(sb, ABORT))
3001                 ext3_abort(sb, __func__, "Abort forced by user");
3002  
3003 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3004 +               !(sb->s_flags & MS_TAGGED)) {
3005 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3006 +                       sb->s_id);
3007 +               err = -EINVAL;
3008 +               goto restore_opts;
3009 +       }
3010 +
3011         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3012                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3013  
3014 diff -NurpP --minimal linux-3.4.83/fs/ext4/ext4.h linux-3.4.83-vs2.3.3.9/fs/ext4/ext4.h
3015 --- linux-3.4.83/fs/ext4/ext4.h 2014-03-12 09:48:13.000000000 +0000
3016 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/ext4.h       2014-03-12 09:55:28.000000000 +0000
3017 @@ -380,8 +380,12 @@ struct flex_groups {
3018  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3019  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3020  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3021 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3022  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3023  
3024 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3025 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3026 +
3027  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3028  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3029  
3030 @@ -650,7 +654,8 @@ struct ext4_inode {
3031                         __le16  l_i_file_acl_high;
3032                         __le16  l_i_uid_high;   /* these 2 fields */
3033                         __le16  l_i_gid_high;   /* were reserved2[0] */
3034 -                       __u32   l_i_reserved2;
3035 +                       __le16  l_i_tag;        /* Context Tag */
3036 +                       __u16   l_i_reserved2;
3037                 } linux2;
3038                 struct {
3039                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3040 @@ -770,6 +775,7 @@ do {                                                                               \
3041  #define i_gid_low      i_gid
3042  #define i_uid_high     osd2.linux2.l_i_uid_high
3043  #define i_gid_high     osd2.linux2.l_i_gid_high
3044 +#define i_raw_tag      osd2.linux2.l_i_tag
3045  #define i_reserved2    osd2.linux2.l_i_reserved2
3046  
3047  #elif defined(__GNU__)
3048 @@ -947,6 +953,7 @@ struct ext4_inode_info {
3049  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3050  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3051  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3052 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3053  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3054  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3055  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3056 @@ -2296,6 +2303,7 @@ extern int ext4_map_blocks(handle_t *han
3057                            struct ext4_map_blocks *map, int flags);
3058  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3059                         __u64 start, __u64 len);
3060 +extern int ext4_sync_flags(struct inode *, int, int);
3061  /* move_extent.c */
3062  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3063                              __u64 start_orig, __u64 start_donor,
3064 diff -NurpP --minimal linux-3.4.83/fs/ext4/file.c linux-3.4.83-vs2.3.3.9/fs/ext4/file.c
3065 --- linux-3.4.83/fs/ext4/file.c 2012-01-09 15:14:54.000000000 +0000
3066 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/file.c       2012-05-21 16:15:05.000000000 +0000
3067 @@ -258,5 +258,6 @@ const struct inode_operations ext4_file_
3068  #endif
3069         .get_acl        = ext4_get_acl,
3070         .fiemap         = ext4_fiemap,
3071 +       .sync_flags     = ext4_sync_flags,
3072  };
3073  
3074 diff -NurpP --minimal linux-3.4.83/fs/ext4/ialloc.c linux-3.4.83-vs2.3.3.9/fs/ext4/ialloc.c
3075 --- linux-3.4.83/fs/ext4/ialloc.c       2014-03-12 09:48:13.000000000 +0000
3076 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/ialloc.c     2014-03-12 09:55:28.000000000 +0000
3077 @@ -22,6 +22,7 @@
3078  #include <linux/random.h>
3079  #include <linux/bitops.h>
3080  #include <linux/blkdev.h>
3081 +#include <linux/vs_tag.h>
3082  #include <asm/byteorder.h>
3083  
3084  #include "ext4.h"
3085 @@ -817,6 +818,7 @@ got:
3086                 inode->i_mode = mode;
3087                 inode->i_uid = current_fsuid();
3088                 inode->i_gid = dir->i_gid;
3089 +               inode->i_tag = dx_current_fstag(sb);
3090         } else
3091                 inode_init_owner(inode, dir, mode);
3092  
3093 diff -NurpP --minimal linux-3.4.83/fs/ext4/inode.c linux-3.4.83-vs2.3.3.9/fs/ext4/inode.c
3094 --- linux-3.4.83/fs/ext4/inode.c        2014-03-12 09:48:13.000000000 +0000
3095 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/inode.c      2014-03-12 09:55:28.000000000 +0000
3096 @@ -37,6 +37,7 @@
3097  #include <linux/printk.h>
3098  #include <linux/slab.h>
3099  #include <linux/ratelimit.h>
3100 +#include <linux/vs_tag.h>
3101  
3102  #include "ext4_jbd2.h"
3103  #include "xattr.h"
3104 @@ -3581,41 +3582,64 @@ void ext4_set_inode_flags(struct inode *
3105  {
3106         unsigned int flags = EXT4_I(inode)->i_flags;
3107  
3108 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3109 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3110 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3111 +
3112 +       if (flags & EXT4_IMMUTABLE_FL)
3113 +               inode->i_flags |= S_IMMUTABLE;
3114 +       if (flags & EXT4_IXUNLINK_FL)
3115 +               inode->i_flags |= S_IXUNLINK;
3116 +
3117         if (flags & EXT4_SYNC_FL)
3118                 inode->i_flags |= S_SYNC;
3119         if (flags & EXT4_APPEND_FL)
3120                 inode->i_flags |= S_APPEND;
3121 -       if (flags & EXT4_IMMUTABLE_FL)
3122 -               inode->i_flags |= S_IMMUTABLE;
3123         if (flags & EXT4_NOATIME_FL)
3124                 inode->i_flags |= S_NOATIME;
3125         if (flags & EXT4_DIRSYNC_FL)
3126                 inode->i_flags |= S_DIRSYNC;
3127 +
3128 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3129 +
3130 +       if (flags & EXT4_BARRIER_FL)
3131 +               inode->i_vflags |= V_BARRIER;
3132 +       if (flags & EXT4_COW_FL)
3133 +               inode->i_vflags |= V_COW;
3134  }
3135  
3136  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3137  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3138  {
3139 -       unsigned int vfs_fl;
3140 +       unsigned int vfs_fl, vfs_vf;
3141         unsigned long old_fl, new_fl;
3142  
3143         do {
3144                 vfs_fl = ei->vfs_inode.i_flags;
3145 +               vfs_vf = ei->vfs_inode.i_vflags;
3146                 old_fl = ei->i_flags;
3147                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3148                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3149 -                               EXT4_DIRSYNC_FL);
3150 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3151 +                               EXT4_COW_FL);
3152 +
3153 +               if (vfs_fl & S_IMMUTABLE)
3154 +                       new_fl |= EXT4_IMMUTABLE_FL;
3155 +               if (vfs_fl & S_IXUNLINK)
3156 +                       new_fl |= EXT4_IXUNLINK_FL;
3157 +
3158                 if (vfs_fl & S_SYNC)
3159                         new_fl |= EXT4_SYNC_FL;
3160                 if (vfs_fl & S_APPEND)
3161                         new_fl |= EXT4_APPEND_FL;
3162 -               if (vfs_fl & S_IMMUTABLE)
3163 -                       new_fl |= EXT4_IMMUTABLE_FL;
3164                 if (vfs_fl & S_NOATIME)
3165                         new_fl |= EXT4_NOATIME_FL;
3166                 if (vfs_fl & S_DIRSYNC)
3167                         new_fl |= EXT4_DIRSYNC_FL;
3168 +
3169 +               if (vfs_vf & V_BARRIER)
3170 +                       new_fl |= EXT4_BARRIER_FL;
3171 +               if (vfs_vf & V_COW)
3172 +                       new_fl |= EXT4_COW_FL;
3173         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3174  }
3175  
3176 @@ -3651,6 +3675,8 @@ struct inode *ext4_iget(struct super_blo
3177         journal_t *journal = EXT4_SB(sb)->s_journal;
3178         long ret;
3179         int block;
3180 +       uid_t uid;
3181 +       gid_t gid;
3182  
3183         inode = iget_locked(sb, ino);
3184         if (!inode)
3185 @@ -3666,12 +3692,16 @@ struct inode *ext4_iget(struct super_blo
3186                 goto bad_inode;
3187         raw_inode = ext4_raw_inode(&iloc);
3188         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3189 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3190 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3191 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3192 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3193         if (!(test_opt(inode->i_sb, NO_UID32))) {
3194 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3195 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3196 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3197 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3198         }
3199 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3200 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3201 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3202 +               le16_to_cpu(raw_inode->i_raw_tag));
3203         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3204  
3205         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3206 @@ -3890,6 +3920,8 @@ static int ext4_do_update_inode(handle_t
3207         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3208         struct ext4_inode_info *ei = EXT4_I(inode);
3209         struct buffer_head *bh = iloc->bh;
3210 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3211 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3212         int err = 0, rc, block;
3213         int need_datasync = 0;
3214  
3215 @@ -3901,29 +3933,32 @@ static int ext4_do_update_inode(handle_t
3216         ext4_get_inode_flags(ei);
3217         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3218         if (!(test_opt(inode->i_sb, NO_UID32))) {
3219 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3220 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3221 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3222 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3223  /*
3224   * Fix up interoperability with old kernels. Otherwise, old inodes get
3225   * re-used with the upper 16 bits of the uid/gid intact
3226   */
3227                 if (!ei->i_dtime) {
3228                         raw_inode->i_uid_high =
3229 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3230 +                               cpu_to_le16(high_16_bits(uid));
3231                         raw_inode->i_gid_high =
3232 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3233 +                               cpu_to_le16(high_16_bits(gid));
3234                 } else {
3235                         raw_inode->i_uid_high = 0;
3236                         raw_inode->i_gid_high = 0;
3237                 }
3238         } else {
3239                 raw_inode->i_uid_low =
3240 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3241 +                       cpu_to_le16(fs_high2lowuid(uid));
3242                 raw_inode->i_gid_low =
3243 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3244 +                       cpu_to_le16(fs_high2lowgid(gid));
3245                 raw_inode->i_uid_high = 0;
3246                 raw_inode->i_gid_high = 0;
3247         }
3248 +#ifdef CONFIG_TAGGING_INTERN
3249 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3250 +#endif
3251         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3252  
3253         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3254 @@ -4110,7 +4145,8 @@ int ext4_setattr(struct dentry *dentry,
3255         if (is_quota_modification(inode, attr))
3256                 dquot_initialize(inode);
3257         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3258 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3259 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3260 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3261                 handle_t *handle;
3262  
3263                 /* (user+group)*(old+new) structure, inode write (sb,
3264 @@ -4132,6 +4168,8 @@ int ext4_setattr(struct dentry *dentry,
3265                         inode->i_uid = attr->ia_uid;
3266                 if (attr->ia_valid & ATTR_GID)
3267                         inode->i_gid = attr->ia_gid;
3268 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3269 +                       inode->i_tag = attr->ia_tag;
3270                 error = ext4_mark_inode_dirty(handle, inode);
3271                 ext4_journal_stop(handle);
3272         }
3273 diff -NurpP --minimal linux-3.4.83/fs/ext4/ioctl.c linux-3.4.83-vs2.3.3.9/fs/ext4/ioctl.c
3274 --- linux-3.4.83/fs/ext4/ioctl.c        2014-03-12 09:48:13.000000000 +0000
3275 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/ioctl.c      2012-09-01 08:50:49.000000000 +0000
3276 @@ -14,12 +14,40 @@
3277  #include <linux/compat.h>
3278  #include <linux/mount.h>
3279  #include <linux/file.h>
3280 +#include <linux/vs_tag.h>
3281  #include <asm/uaccess.h>
3282  #include "ext4_jbd2.h"
3283  #include "ext4.h"
3284  
3285  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3286  
3287 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3288 +{
3289 +       handle_t *handle = NULL;
3290 +       struct ext4_iloc iloc;
3291 +       int err;
3292 +
3293 +       handle = ext4_journal_start(inode, 1);
3294 +       if (IS_ERR(handle))
3295 +               return PTR_ERR(handle);
3296 +
3297 +       if (IS_SYNC(inode))
3298 +               ext4_handle_sync(handle);
3299 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3300 +       if (err)
3301 +               goto flags_err;
3302 +
3303 +       inode->i_flags = flags;
3304 +       inode->i_vflags = vflags;
3305 +       ext4_get_inode_flags(EXT4_I(inode));
3306 +       inode->i_ctime = ext4_current_time(inode);
3307 +
3308 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3309 +flags_err:
3310 +       ext4_journal_stop(handle);
3311 +       return err;
3312 +}
3313 +
3314  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3315  {
3316         struct inode *inode = filp->f_dentry->d_inode;
3317 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3318  
3319                 flags = ext4_mask_flags(inode->i_mode, flags);
3320  
3321 +               if (IS_BARRIER(inode)) {
3322 +                       vxwprintk_task(1, "messing with the barrier.");
3323 +                       return -EACCES;
3324 +               }
3325 +
3326                 err = -EPERM;
3327                 mutex_lock(&inode->i_mutex);
3328                 /* Is it quota file? Do not allow user to mess with it */
3329 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3330                  *
3331                  * This test looks nicer. Thanks to Pauline Middelink
3332                  */
3333 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3334 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3335 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3336 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3337                         if (!capable(CAP_LINUX_IMMUTABLE))
3338                                 goto flags_out;
3339                 }
3340 diff -NurpP --minimal linux-3.4.83/fs/ext4/namei.c linux-3.4.83-vs2.3.3.9/fs/ext4/namei.c
3341 --- linux-3.4.83/fs/ext4/namei.c        2014-03-12 09:48:13.000000000 +0000
3342 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/namei.c      2013-10-26 18:10:21.000000000 +0000
3343 @@ -34,6 +34,7 @@
3344  #include <linux/quotaops.h>
3345  #include <linux/buffer_head.h>
3346  #include <linux/bio.h>
3347 +#include <linux/vs_tag.h>
3348  #include "ext4.h"
3349  #include "ext4_jbd2.h"
3350  
3351 @@ -922,6 +923,7 @@ restart:
3352                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3353                                                     1, &bh);
3354                         }
3355 +               dx_propagate_tag(nd, inode);
3356                 }
3357                 if ((bh = bh_use[ra_ptr++]) == NULL)
3358                         goto next;
3359 @@ -2589,6 +2591,7 @@ const struct inode_operations ext4_dir_i
3360  #endif
3361         .get_acl        = ext4_get_acl,
3362         .fiemap         = ext4_fiemap,
3363 +       .sync_flags     = ext4_sync_flags,
3364  };
3365  
3366  const struct inode_operations ext4_special_inode_operations = {
3367 diff -NurpP --minimal linux-3.4.83/fs/ext4/super.c linux-3.4.83-vs2.3.3.9/fs/ext4/super.c
3368 --- linux-3.4.83/fs/ext4/super.c        2014-03-12 09:48:13.000000000 +0000
3369 +++ linux-3.4.83-vs2.3.3.9/fs/ext4/super.c      2014-03-12 09:55:28.000000000 +0000
3370 @@ -1191,6 +1191,7 @@ enum {
3371         Opt_inode_readahead_blks, Opt_journal_ioprio,
3372         Opt_dioread_nolock, Opt_dioread_lock,
3373         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3374 +       Opt_tag, Opt_notag, Opt_tagid
3375  };
3376  
3377  static const match_table_t tokens = {
3378 @@ -1269,6 +1270,9 @@ static const match_table_t tokens = {
3379         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3380         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3381         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3382 +       {Opt_tag, "tag"},
3383 +       {Opt_notag, "notag"},
3384 +       {Opt_tagid, "tagid=%u"},
3385         {Opt_err, NULL},
3386  };
3387  
3388 @@ -1503,6 +1507,20 @@ static int handle_mount_opt(struct super
3389                         return -1;
3390                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3391                 return 1;
3392 +#ifndef CONFIG_TAGGING_NONE
3393 +       case Opt_tag:
3394 +               set_opt(sb, TAGGED);
3395 +               return 1;
3396 +       case Opt_notag:
3397 +               clear_opt(sb, TAGGED);
3398 +               return 1;
3399 +#endif
3400 +#ifdef CONFIG_PROPAGATE
3401 +       case Opt_tagid:
3402 +               /* use args[0] */
3403 +               set_opt(sb, TAGGED);
3404 +               return 1;
3405 +#endif
3406         }
3407  
3408         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3409 @@ -3239,6 +3257,9 @@ static int ext4_fill_super(struct super_
3410                         clear_opt(sb, DELALLOC);
3411         }
3412  
3413 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3414 +               sb->s_flags |= MS_TAGGED;
3415 +
3416         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3417                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3418  
3419 @@ -4421,6 +4442,14 @@ static int ext4_remount(struct super_blo
3420         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3421                 ext4_abort(sb, "Abort forced by user");
3422  
3423 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3424 +               !(sb->s_flags & MS_TAGGED)) {
3425 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3426 +                       sb->s_id);
3427 +               err = -EINVAL;
3428 +               goto restore_opts;
3429 +       }
3430 +
3431         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3432                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3433  
3434 diff -NurpP --minimal linux-3.4.83/fs/fcntl.c linux-3.4.83-vs2.3.3.9/fs/fcntl.c
3435 --- linux-3.4.83/fs/fcntl.c     2012-05-21 16:07:20.000000000 +0000
3436 +++ linux-3.4.83-vs2.3.3.9/fs/fcntl.c   2012-05-21 16:15:05.000000000 +0000
3437 @@ -20,6 +20,7 @@
3438  #include <linux/signal.h>
3439  #include <linux/rcupdate.h>
3440  #include <linux/pid_namespace.h>
3441 +#include <linux/vs_limit.h>
3442  
3443  #include <asm/poll.h>
3444  #include <asm/siginfo.h>
3445 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3446  
3447         if (tofree)
3448                 filp_close(tofree, files);
3449 +       else
3450 +               vx_openfd_inc(newfd);   /* fd was unused */
3451  
3452         return newfd;
3453  
3454 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3455         filp = fget_raw(fd);
3456         if (!filp)
3457                 goto out;
3458 +       if (!vx_files_avail(1))
3459 +               goto out;
3460  
3461         if (unlikely(filp->f_mode & FMODE_PATH)) {
3462                 if (!check_fcntl_cmd(cmd)) {
3463 diff -NurpP --minimal linux-3.4.83/fs/file.c linux-3.4.83-vs2.3.3.9/fs/file.c
3464 --- linux-3.4.83/fs/file.c      2014-03-12 09:48:13.000000000 +0000
3465 +++ linux-3.4.83-vs2.3.3.9/fs/file.c    2014-03-12 09:55:28.000000000 +0000
3466 @@ -21,6 +21,7 @@
3467  #include <linux/spinlock.h>
3468  #include <linux/rcupdate.h>
3469  #include <linux/workqueue.h>
3470 +#include <linux/vs_limit.h>
3471  
3472  struct fdtable_defer {
3473         spinlock_t lock;
3474 @@ -358,6 +359,8 @@ struct files_struct *dup_fd(struct files
3475                 struct file *f = *old_fds++;
3476                 if (f) {
3477                         get_file(f);
3478 +                       /* TODO: sum it first for check and performance */
3479 +                       vx_openfd_inc(open_files - i);
3480                 } else {
3481                         /*
3482                          * The fd may be claimed in the fd bitmap but not yet
3483 @@ -464,6 +467,7 @@ repeat:
3484         else
3485                 __clear_close_on_exec(fd, fdt);
3486         error = fd;
3487 +       vx_openfd_inc(fd);
3488  #if 1
3489         /* Sanity check */
3490         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3491 diff -NurpP --minimal linux-3.4.83/fs/file_table.c linux-3.4.83-vs2.3.3.9/fs/file_table.c
3492 --- linux-3.4.83/fs/file_table.c        2012-05-21 16:07:20.000000000 +0000
3493 +++ linux-3.4.83-vs2.3.3.9/fs/file_table.c      2012-05-21 16:15:05.000000000 +0000
3494 @@ -24,6 +24,8 @@
3495  #include <linux/percpu_counter.h>
3496  #include <linux/percpu.h>
3497  #include <linux/ima.h>
3498 +#include <linux/vs_limit.h>
3499 +#include <linux/vs_context.h>
3500  
3501  #include <linux/atomic.h>
3502  
3503 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3504         spin_lock_init(&f->f_lock);
3505         eventpoll_init_file(f);
3506         /* f->f_version: 0 */
3507 +       f->f_xid = vx_current_xid();
3508 +       vx_files_inc(f);
3509         return f;
3510  
3511  over:
3512 @@ -252,6 +256,8 @@ static void __fput(struct file *file)
3513         }
3514         fops_put(file->f_op);
3515         put_pid(file->f_owner.pid);
3516 +       vx_files_dec(file);
3517 +       file->f_xid = 0;
3518         file_sb_list_del(file);
3519         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3520                 i_readcount_dec(inode);
3521 @@ -382,6 +388,8 @@ void put_filp(struct file *file)
3522  {
3523         if (atomic_long_dec_and_test(&file->f_count)) {
3524                 security_file_free(file);
3525 +               vx_files_dec(file);
3526 +               file->f_xid = 0;
3527                 file_sb_list_del(file);
3528                 file_free(file);
3529         }
3530 diff -NurpP --minimal linux-3.4.83/fs/fs_struct.c linux-3.4.83-vs2.3.3.9/fs/fs_struct.c
3531 --- linux-3.4.83/fs/fs_struct.c 2012-05-21 16:07:20.000000000 +0000
3532 +++ linux-3.4.83-vs2.3.3.9/fs/fs_struct.c       2012-05-21 16:15:05.000000000 +0000
3533 @@ -4,6 +4,7 @@
3534  #include <linux/path.h>
3535  #include <linux/slab.h>
3536  #include <linux/fs_struct.h>
3537 +#include <linux/vserver/global.h>
3538  #include "internal.h"
3539  
3540  static inline void path_get_longterm(struct path *path)
3541 @@ -99,6 +100,7 @@ void free_fs_struct(struct fs_struct *fs
3542  {
3543         path_put_longterm(&fs->root);
3544         path_put_longterm(&fs->pwd);
3545 +       atomic_dec(&vs_global_fs);
3546         kmem_cache_free(fs_cachep, fs);
3547  }
3548  
3549 @@ -136,6 +138,7 @@ struct fs_struct *copy_fs_struct(struct
3550                 fs->pwd = old->pwd;
3551                 path_get_longterm(&fs->pwd);
3552                 spin_unlock(&old->lock);
3553 +               atomic_inc(&vs_global_fs);
3554         }
3555         return fs;
3556  }
3557 diff -NurpP --minimal linux-3.4.83/fs/gfs2/file.c linux-3.4.83-vs2.3.3.9/fs/gfs2/file.c
3558 --- linux-3.4.83/fs/gfs2/file.c 2012-05-21 16:07:20.000000000 +0000
3559 +++ linux-3.4.83-vs2.3.3.9/fs/gfs2/file.c       2012-05-21 16:15:05.000000000 +0000
3560 @@ -142,6 +142,9 @@ static const u32 fsflags_to_gfs2[32] = {
3561         [7] = GFS2_DIF_NOATIME,
3562         [12] = GFS2_DIF_EXHASH,
3563         [14] = GFS2_DIF_INHERIT_JDATA,
3564 +       [27] = GFS2_DIF_IXUNLINK,
3565 +       [26] = GFS2_DIF_BARRIER,
3566 +       [29] = GFS2_DIF_COW,
3567  };
3568  
3569  static const u32 gfs2_to_fsflags[32] = {
3570 @@ -151,6 +154,9 @@ static const u32 gfs2_to_fsflags[32] = {
3571         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3572         [gfs2fl_ExHash] = FS_INDEX_FL,
3573         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3574 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3575 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3576 +       [gfs2fl_Cow] = FS_COW_FL,
3577  };
3578  
3579  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3580 @@ -181,12 +187,18 @@ void gfs2_set_inode_flags(struct inode *
3581  {
3582         struct gfs2_inode *ip = GFS2_I(inode);
3583         unsigned int flags = inode->i_flags;
3584 +       unsigned int vflags = inode->i_vflags;
3585 +
3586 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3587 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3588  
3589 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3590         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3591                 inode->i_flags |= S_NOSEC;
3592         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3593                 flags |= S_IMMUTABLE;
3594 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3595 +               flags |= S_IXUNLINK;
3596 +
3597         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3598                 flags |= S_APPEND;
3599         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3600 @@ -194,6 +206,43 @@ void gfs2_set_inode_flags(struct inode *
3601         if (ip->i_diskflags & GFS2_DIF_SYNC)
3602                 flags |= S_SYNC;
3603         inode->i_flags = flags;
3604 +
3605 +       vflags &= ~(V_BARRIER | V_COW);
3606 +
3607 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3608 +               vflags |= V_BARRIER;
3609 +       if (ip->i_diskflags & GFS2_DIF_COW)
3610 +               vflags |= V_COW;
3611 +       inode->i_vflags = vflags;
3612 +}
3613 +
3614 +void gfs2_get_inode_flags(struct inode *inode)
3615 +{
3616 +       struct gfs2_inode *ip = GFS2_I(inode);
3617 +       unsigned int flags = inode->i_flags;
3618 +       unsigned int vflags = inode->i_vflags;
3619 +
3620 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3621 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3622 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3623 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3624 +
3625 +       if (flags & S_IMMUTABLE)
3626 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3627 +       if (flags & S_IXUNLINK)
3628 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3629 +
3630 +       if (flags & S_APPEND)
3631 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3632 +       if (flags & S_NOATIME)
3633 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3634 +       if (flags & S_SYNC)
3635 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3636 +
3637 +       if (vflags & V_BARRIER)
3638 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3639 +       if (vflags & V_COW)
3640 +               ip->i_diskflags |= GFS2_DIF_COW;
3641  }
3642  
3643  /* Flags that can be set by user space */
3644 @@ -305,6 +354,37 @@ static int gfs2_set_flags(struct file *f
3645         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3646  }
3647  
3648 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3649 +{
3650 +       struct gfs2_inode *ip = GFS2_I(inode);
3651 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3652 +       struct buffer_head *bh;
3653 +       struct gfs2_holder gh;
3654 +       int error;
3655 +
3656 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3657 +       if (error)
3658 +               return error;
3659 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3660 +       if (error)
3661 +               goto out;
3662 +       error = gfs2_meta_inode_buffer(ip, &bh);
3663 +       if (error)
3664 +               goto out_trans_end;
3665 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3666 +       inode->i_flags = flags;
3667 +       inode->i_vflags = vflags;
3668 +       gfs2_get_inode_flags(inode);
3669 +       gfs2_dinode_out(ip, bh->b_data);
3670 +       brelse(bh);
3671 +       gfs2_set_aops(inode);
3672 +out_trans_end:
3673 +       gfs2_trans_end(sdp);
3674 +out:
3675 +       gfs2_glock_dq_uninit(&gh);
3676 +       return error;
3677 +}
3678 +
3679  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3680  {
3681         switch(cmd) {
3682 diff -NurpP --minimal linux-3.4.83/fs/gfs2/inode.h linux-3.4.83-vs2.3.3.9/fs/gfs2/inode.h
3683 --- linux-3.4.83/fs/gfs2/inode.h        2012-01-09 15:14:54.000000000 +0000
3684 +++ linux-3.4.83-vs2.3.3.9/fs/gfs2/inode.h      2012-05-21 16:15:05.000000000 +0000
3685 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3686  extern const struct file_operations gfs2_dir_fops_nolock;
3687  
3688  extern void gfs2_set_inode_flags(struct inode *inode);
3689 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3690   
3691  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3692  extern const struct file_operations gfs2_file_fops;
3693 diff -NurpP --minimal linux-3.4.83/fs/inode.c linux-3.4.83-vs2.3.3.9/fs/inode.c
3694 --- linux-3.4.83/fs/inode.c     2014-03-12 09:48:14.000000000 +0000
3695 +++ linux-3.4.83-vs2.3.3.9/fs/inode.c   2013-07-14 13:38:34.000000000 +0000
3696 @@ -17,6 +17,7 @@
3697  #include <linux/prefetch.h>
3698  #include <linux/buffer_head.h> /* for inode_has_buffers */
3699  #include <linux/ratelimit.h>
3700 +#include <linux/vs_tag.h>
3701  #include "internal.h"
3702  
3703  /*
3704 @@ -128,6 +129,9 @@ int inode_init_always(struct super_block
3705         struct address_space *const mapping = &inode->i_data;
3706  
3707         inode->i_sb = sb;
3708 +
3709 +       /* essential because of inode slab reuse */
3710 +       inode->i_tag = 0;
3711         inode->i_blkbits = sb->s_blocksize_bits;
3712         inode->i_flags = 0;
3713         atomic_set(&inode->i_count, 1);
3714 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3715         inode->i_bdev = NULL;
3716         inode->i_cdev = NULL;
3717         inode->i_rdev = 0;
3718 +       inode->i_mdev = 0;
3719         inode->dirtied_when = 0;
3720  
3721         if (security_inode_alloc(inode))
3722 @@ -470,6 +475,8 @@ void __insert_inode_hash(struct inode *i
3723  }
3724  EXPORT_SYMBOL(__insert_inode_hash);
3725  
3726 +EXPORT_SYMBOL_GPL(__iget);
3727 +
3728  /**
3729   *     __remove_inode_hash - remove an inode from the hash
3730   *     @inode: inode to unhash
3731 @@ -1689,9 +1696,11 @@ void init_special_inode(struct inode *in
3732         if (S_ISCHR(mode)) {
3733                 inode->i_fop = &def_chr_fops;
3734                 inode->i_rdev = rdev;
3735 +               inode->i_mdev = rdev;
3736         } else if (S_ISBLK(mode)) {
3737                 inode->i_fop = &def_blk_fops;
3738                 inode->i_rdev = rdev;
3739 +               inode->i_mdev = rdev;
3740         } else if (S_ISFIFO(mode))
3741                 inode->i_fop = &def_fifo_fops;
3742         else if (S_ISSOCK(mode))
3743 @@ -1720,6 +1729,7 @@ void inode_init_owner(struct inode *inod
3744         } else
3745                 inode->i_gid = current_fsgid();
3746         inode->i_mode = mode;
3747 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3748  }
3749  EXPORT_SYMBOL(inode_init_owner);
3750  
3751 diff -NurpP --minimal linux-3.4.83/fs/ioctl.c linux-3.4.83-vs2.3.3.9/fs/ioctl.c
3752 --- linux-3.4.83/fs/ioctl.c     2012-05-21 16:07:24.000000000 +0000
3753 +++ linux-3.4.83-vs2.3.3.9/fs/ioctl.c   2012-05-21 16:15:05.000000000 +0000
3754 @@ -15,6 +15,9 @@
3755  #include <linux/writeback.h>
3756  #include <linux/buffer_head.h>
3757  #include <linux/falloc.h>
3758 +#include <linux/proc_fs.h>
3759 +#include <linux/vserver/inode.h>
3760 +#include <linux/vs_tag.h>
3761  
3762  #include <asm/ioctls.h>
3763  
3764 diff -NurpP --minimal linux-3.4.83/fs/ioprio.c linux-3.4.83-vs2.3.3.9/fs/ioprio.c
3765 --- linux-3.4.83/fs/ioprio.c    2012-03-19 18:47:25.000000000 +0000
3766 +++ linux-3.4.83-vs2.3.3.9/fs/ioprio.c  2012-05-21 16:15:05.000000000 +0000
3767 @@ -28,6 +28,7 @@
3768  #include <linux/syscalls.h>
3769  #include <linux/security.h>
3770  #include <linux/pid_namespace.h>
3771 +#include <linux/vs_base.h>
3772  
3773  int set_task_ioprio(struct task_struct *task, int ioprio)
3774  {
3775 @@ -104,6 +105,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3776                         else
3777                                 pgrp = find_vpid(who);
3778                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3779 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3780 +                                       continue;
3781                                 ret = set_task_ioprio(p, ioprio);
3782                                 if (ret)
3783                                         break;
3784 @@ -193,6 +196,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3785                         else
3786                                 pgrp = find_vpid(who);
3787                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3788 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3789 +                                       continue;
3790                                 tmpio = get_task_ioprio(p);
3791                                 if (tmpio < 0)
3792                                         continue;
3793 diff -NurpP --minimal linux-3.4.83/fs/jfs/file.c linux-3.4.83-vs2.3.3.9/fs/jfs/file.c
3794 --- linux-3.4.83/fs/jfs/file.c  2011-10-24 16:45:27.000000000 +0000
3795 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/file.c        2012-05-21 16:15:05.000000000 +0000
3796 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3797         if (is_quota_modification(inode, iattr))
3798                 dquot_initialize(inode);
3799         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3800 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3801 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3802 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3803                 rc = dquot_transfer(inode, iattr);
3804                 if (rc)
3805                         return rc;
3806 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3807  #ifdef CONFIG_JFS_POSIX_ACL
3808         .get_acl        = jfs_get_acl,
3809  #endif
3810 +       .sync_flags     = jfs_sync_flags,
3811  };
3812  
3813  const struct file_operations jfs_file_operations = {
3814 diff -NurpP --minimal linux-3.4.83/fs/jfs/ioctl.c linux-3.4.83-vs2.3.3.9/fs/jfs/ioctl.c
3815 --- linux-3.4.83/fs/jfs/ioctl.c 2012-03-19 18:47:25.000000000 +0000
3816 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/ioctl.c       2012-05-21 16:15:05.000000000 +0000
3817 @@ -11,6 +11,7 @@
3818  #include <linux/mount.h>
3819  #include <linux/time.h>
3820  #include <linux/sched.h>
3821 +#include <linux/mount.h>
3822  #include <asm/current.h>
3823  #include <asm/uaccess.h>
3824  
3825 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3826  }
3827  
3828  
3829 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3830 +{
3831 +       inode->i_flags = flags;
3832 +       inode->i_vflags = vflags;
3833 +       jfs_get_inode_flags(JFS_IP(inode));
3834 +       inode->i_ctime = CURRENT_TIME_SEC;
3835 +       mark_inode_dirty(inode);
3836 +       return 0;
3837 +}
3838 +
3839  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3840  {
3841         struct inode *inode = filp->f_dentry->d_inode;
3842 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3843                 if (!S_ISDIR(inode->i_mode))
3844                         flags &= ~JFS_DIRSYNC_FL;
3845  
3846 +               if (IS_BARRIER(inode)) {
3847 +                       vxwprintk_task(1, "messing with the barrier.");
3848 +                       return -EACCES;
3849 +               }
3850 +
3851                 /* Is it quota file? Do not allow user to mess with it */
3852                 if (IS_NOQUOTA(inode)) {
3853                         err = -EPERM;
3854 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3855                  * the relevant capability.
3856                  */
3857                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3858 -                       ((flags ^ oldflags) &
3859 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3860 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3861 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3862                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3863                                 mutex_unlock(&inode->i_mutex);
3864                                 err = -EPERM;
3865 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3866                         }
3867                 }
3868  
3869 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3870 +               flags &= JFS_FL_USER_MODIFIABLE;
3871                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3872                 jfs_inode->mode2 = flags;
3873  
3874 diff -NurpP --minimal linux-3.4.83/fs/jfs/jfs_dinode.h linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_dinode.h
3875 --- linux-3.4.83/fs/jfs/jfs_dinode.h    2008-12-24 23:26:37.000000000 +0000
3876 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_dinode.h  2012-05-21 16:15:05.000000000 +0000
3877 @@ -161,9 +161,13 @@ struct dinode {
3878  
3879  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3880  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3881 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3882  
3883 -#define JFS_FL_USER_VISIBLE    0x03F80000
3884 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3885 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3886 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3887 +
3888 +#define JFS_FL_USER_VISIBLE    0x07F80000
3889 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3890  #define JFS_FL_INHERIT         0x03C80000
3891  
3892  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3893 diff -NurpP --minimal linux-3.4.83/fs/jfs/jfs_filsys.h linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_filsys.h
3894 --- linux-3.4.83/fs/jfs/jfs_filsys.h    2008-12-24 23:26:37.000000000 +0000
3895 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_filsys.h  2012-05-21 16:15:05.000000000 +0000
3896 @@ -263,6 +263,7 @@
3897  #define JFS_NAME_MAX   255
3898  #define JFS_PATH_MAX   BPSIZE
3899  
3900 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3901  
3902  /*
3903   *     file system state (superblock state)
3904 diff -NurpP --minimal linux-3.4.83/fs/jfs/jfs_imap.c linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_imap.c
3905 --- linux-3.4.83/fs/jfs/jfs_imap.c      2012-01-09 15:14:54.000000000 +0000
3906 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_imap.c    2012-05-21 16:15:05.000000000 +0000
3907 @@ -46,6 +46,7 @@
3908  #include <linux/pagemap.h>
3909  #include <linux/quotaops.h>
3910  #include <linux/slab.h>
3911 +#include <linux/vs_tag.h>
3912  
3913  #include "jfs_incore.h"
3914  #include "jfs_inode.h"
3915 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3916  {
3917         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3918         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3919 +       uid_t uid;
3920 +       gid_t gid;
3921  
3922         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3923         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3924 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3925         }
3926         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3927  
3928 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3929 +       uid = le32_to_cpu(dip->di_uid);
3930 +       gid = le32_to_cpu(dip->di_gid);
3931 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3932 +
3933 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3934         if (sbi->uid == -1)
3935                 ip->i_uid = jfs_ip->saved_uid;
3936         else {
3937                 ip->i_uid = sbi->uid;
3938         }
3939  
3940 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3941 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3942         if (sbi->gid == -1)
3943                 ip->i_gid = jfs_ip->saved_gid;
3944         else {
3945 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3946         dip->di_size = cpu_to_le64(ip->i_size);
3947         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3948         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3949 -       if (sbi->uid == -1)
3950 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3951 -       else
3952 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3953 -       if (sbi->gid == -1)
3954 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3955 -       else
3956 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3957 +
3958 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3959 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3960 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3961 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3962 +
3963         jfs_get_inode_flags(jfs_ip);
3964         /*
3965          * mode2 is only needed for storing the higher order bits.
3966 diff -NurpP --minimal linux-3.4.83/fs/jfs/jfs_inode.c linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_inode.c
3967 --- linux-3.4.83/fs/jfs/jfs_inode.c     2014-03-12 09:48:14.000000000 +0000
3968 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_inode.c   2014-03-12 09:55:28.000000000 +0000
3969 @@ -18,6 +18,7 @@
3970  
3971  #include <linux/fs.h>
3972  #include <linux/quotaops.h>
3973 +#include <linux/vs_tag.h>
3974  #include "jfs_incore.h"
3975  #include "jfs_inode.h"
3976  #include "jfs_filsys.h"
3977 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3978  {
3979         unsigned int flags = JFS_IP(inode)->mode2;
3980  
3981 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3982 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3983 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3984 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3985  
3986         if (flags & JFS_IMMUTABLE_FL)
3987                 inode->i_flags |= S_IMMUTABLE;
3988 +       if (flags & JFS_IXUNLINK_FL)
3989 +               inode->i_flags |= S_IXUNLINK;
3990 +
3991 +       if (flags & JFS_SYNC_FL)
3992 +               inode->i_flags |= S_SYNC;
3993         if (flags & JFS_APPEND_FL)
3994                 inode->i_flags |= S_APPEND;
3995         if (flags & JFS_NOATIME_FL)
3996                 inode->i_flags |= S_NOATIME;
3997         if (flags & JFS_DIRSYNC_FL)
3998                 inode->i_flags |= S_DIRSYNC;
3999 -       if (flags & JFS_SYNC_FL)
4000 -               inode->i_flags |= S_SYNC;
4001 +
4002 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4003 +
4004 +       if (flags & JFS_BARRIER_FL)
4005 +               inode->i_vflags |= V_BARRIER;
4006 +       if (flags & JFS_COW_FL)
4007 +               inode->i_vflags |= V_COW;
4008  }
4009  
4010  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4011  {
4012         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4013 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4014 +
4015 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4016 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4017 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4018 +                          JFS_BARRIER_FL | JFS_COW_FL);
4019  
4020 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4021 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4022         if (flags & S_IMMUTABLE)
4023                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4024 +       if (flags & S_IXUNLINK)
4025 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4026 +
4027         if (flags & S_APPEND)
4028                 jfs_ip->mode2 |= JFS_APPEND_FL;
4029         if (flags & S_NOATIME)
4030 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4031                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4032         if (flags & S_SYNC)
4033                 jfs_ip->mode2 |= JFS_SYNC_FL;
4034 +
4035 +       if (vflags & V_BARRIER)
4036 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4037 +       if (vflags & V_COW)
4038 +               jfs_ip->mode2 |= JFS_COW_FL;
4039  }
4040  
4041  /*
4042 diff -NurpP --minimal linux-3.4.83/fs/jfs/jfs_inode.h linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_inode.h
4043 --- linux-3.4.83/fs/jfs/jfs_inode.h     2011-10-24 16:45:27.000000000 +0000
4044 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/jfs_inode.h   2012-05-21 16:15:05.000000000 +0000
4045 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4046  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4047         int fh_len, int fh_type);
4048  extern void jfs_set_inode_flags(struct inode *);
4049 +extern int jfs_sync_flags(struct inode *, int, int);
4050  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4051  extern int jfs_setattr(struct dentry *, struct iattr *);
4052  
4053 diff -NurpP --minimal linux-3.4.83/fs/jfs/namei.c linux-3.4.83-vs2.3.3.9/fs/jfs/namei.c
4054 --- linux-3.4.83/fs/jfs/namei.c 2012-05-21 16:07:25.000000000 +0000
4055 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/namei.c       2012-05-21 16:15:05.000000000 +0000
4056 @@ -22,6 +22,7 @@
4057  #include <linux/ctype.h>
4058  #include <linux/quotaops.h>
4059  #include <linux/exportfs.h>
4060 +#include <linux/vs_tag.h>
4061  #include "jfs_incore.h"
4062  #include "jfs_superblock.h"
4063  #include "jfs_inode.h"
4064 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4065                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4066         }
4067  
4068 +       dx_propagate_tag(nd, ip);
4069         return d_splice_alias(ip, dentry);
4070  }
4071  
4072 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4073  #ifdef CONFIG_JFS_POSIX_ACL
4074         .get_acl        = jfs_get_acl,
4075  #endif
4076 +       .sync_flags     = jfs_sync_flags,
4077  };
4078  
4079  const struct file_operations jfs_dir_operations = {
4080 diff -NurpP --minimal linux-3.4.83/fs/jfs/super.c linux-3.4.83-vs2.3.3.9/fs/jfs/super.c
4081 --- linux-3.4.83/fs/jfs/super.c 2012-05-21 16:07:25.000000000 +0000
4082 +++ linux-3.4.83-vs2.3.3.9/fs/jfs/super.c       2012-05-21 16:15:05.000000000 +0000
4083 @@ -197,7 +197,8 @@ static void jfs_put_super(struct super_b
4084  enum {
4085         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4086         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4087 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4088 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4089 +       Opt_tag, Opt_notag, Opt_tagid
4090  };
4091  
4092  static const match_table_t tokens = {
4093 @@ -207,6 +208,10 @@ static const match_table_t tokens = {
4094         {Opt_resize, "resize=%u"},
4095         {Opt_resize_nosize, "resize"},
4096         {Opt_errors, "errors=%s"},
4097 +       {Opt_tag, "tag"},
4098 +       {Opt_notag, "notag"},
4099 +       {Opt_tagid, "tagid=%u"},
4100 +       {Opt_tag, "tagxid"},
4101         {Opt_ignore, "noquota"},
4102         {Opt_ignore, "quota"},
4103         {Opt_usrquota, "usrquota"},
4104 @@ -341,6 +346,20 @@ static int parse_options(char *options,
4105                         }
4106                         break;
4107                 }
4108 +#ifndef CONFIG_TAGGING_NONE
4109 +               case Opt_tag:
4110 +                       *flag |= JFS_TAGGED;
4111 +                       break;
4112 +               case Opt_notag:
4113 +                       *flag &= JFS_TAGGED;
4114 +                       break;
4115 +#endif
4116 +#ifdef CONFIG_PROPAGATE
4117 +               case Opt_tagid:
4118 +                       /* use args[0] */
4119 +                       *flag |= JFS_TAGGED;
4120 +                       break;
4121 +#endif
4122                 default:
4123                         printk("jfs: Unrecognized mount option \"%s\" "
4124                                         " or missing value\n", p);
4125 @@ -372,6 +391,12 @@ static int jfs_remount(struct super_bloc
4126                 return -EINVAL;
4127         }
4128  
4129 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4130 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4131 +                       sb->s_id);
4132 +               return -EINVAL;
4133 +       }
4134 +
4135         if (newLVSize) {
4136                 if (sb->s_flags & MS_RDONLY) {
4137                         printk(KERN_ERR
4138 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4139  #ifdef CONFIG_JFS_POSIX_ACL
4140         sb->s_flags |= MS_POSIXACL;
4141  #endif
4142 +       /* map mount option tagxid */
4143 +       if (sbi->flag & JFS_TAGGED)
4144 +               sb->s_flags |= MS_TAGGED;
4145  
4146         if (newLVSize) {
4147                 printk(KERN_ERR "resize option for remount only\n");
4148 diff -NurpP --minimal linux-3.4.83/fs/libfs.c linux-3.4.83-vs2.3.3.9/fs/libfs.c
4149 --- linux-3.4.83/fs/libfs.c     2012-05-21 16:07:25.000000000 +0000
4150 +++ linux-3.4.83-vs2.3.3.9/fs/libfs.c   2012-05-21 16:15:05.000000000 +0000
4151 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4152   * both impossible due to the lock on directory.
4153   */
4154  
4155 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4156 +static inline int do_dcache_readdir_filter(struct file *filp,
4157 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4158  {
4159         struct dentry *dentry = filp->f_path.dentry;
4160         struct dentry *cursor = filp->private_data;
4161 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4162                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4163                                 struct dentry *next;
4164                                 next = list_entry(p, struct dentry, d_u.d_child);
4165 +                               if (filter && !filter(next))
4166 +                                       continue;
4167                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4168                                 if (!simple_positive(next)) {
4169                                         spin_unlock(&next->d_lock);
4170 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4171         return 0;
4172  }
4173  
4174 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4175 +{
4176 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4177 +}
4178 +
4179 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4180 +       int (*filter)(struct dentry *))
4181 +{
4182 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4183 +}
4184 +
4185  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4186  {
4187         return -EISDIR;
4188 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4189  EXPORT_SYMBOL(dcache_dir_lseek);
4190  EXPORT_SYMBOL(dcache_dir_open);
4191  EXPORT_SYMBOL(dcache_readdir);
4192 +EXPORT_SYMBOL(dcache_readdir_filter);
4193  EXPORT_SYMBOL(generic_read_dir);
4194  EXPORT_SYMBOL(mount_pseudo);
4195  EXPORT_SYMBOL(simple_write_begin);
4196 diff -NurpP --minimal linux-3.4.83/fs/locks.c linux-3.4.83-vs2.3.3.9/fs/locks.c
4197 --- linux-3.4.83/fs/locks.c     2014-03-12 09:48:14.000000000 +0000
4198 +++ linux-3.4.83-vs2.3.3.9/fs/locks.c   2012-09-01 08:50:49.000000000 +0000
4199 @@ -126,6 +126,8 @@
4200  #include <linux/time.h>
4201  #include <linux/rcupdate.h>
4202  #include <linux/pid_namespace.h>
4203 +#include <linux/vs_base.h>
4204 +#include <linux/vs_limit.h>
4205  
4206  #include <asm/uaccess.h>
4207  
4208 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4209  /* Allocate an empty lock structure. */
4210  struct file_lock *locks_alloc_lock(void)
4211  {
4212 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4213 +       struct file_lock *fl;
4214  
4215 -       if (fl)
4216 -               locks_init_lock_heads(fl);
4217 +       if (!vx_locks_avail(1))
4218 +               return NULL;
4219  
4220 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4221 +
4222 +       if (fl) {
4223 +               locks_init_lock_heads(fl);
4224 +               fl->fl_xid = -1;
4225 +       }
4226         return fl;
4227  }
4228  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4229 @@ -216,6 +224,7 @@ void locks_free_lock(struct file_lock *f
4230         BUG_ON(!list_empty(&fl->fl_block));
4231         BUG_ON(!list_empty(&fl->fl_link));
4232  
4233 +       vx_locks_dec(fl);
4234         locks_release_private(fl);
4235         kmem_cache_free(filelock_cache, fl);
4236  }
4237 @@ -225,6 +234,7 @@ void locks_init_lock(struct file_lock *f
4238  {
4239         memset(fl, 0, sizeof(struct file_lock));
4240         locks_init_lock_heads(fl);
4241 +       fl->fl_xid = -1;
4242  }
4243  
4244  EXPORT_SYMBOL(locks_init_lock);
4245 @@ -265,6 +275,7 @@ void locks_copy_lock(struct file_lock *n
4246         new->fl_file = fl->fl_file;
4247         new->fl_ops = fl->fl_ops;
4248         new->fl_lmops = fl->fl_lmops;
4249 +       new->fl_xid = fl->fl_xid;
4250  
4251         locks_copy_private(new, fl);
4252  }
4253 @@ -303,6 +314,11 @@ static int flock_make_lock(struct file *
4254         fl->fl_flags = FL_FLOCK;
4255         fl->fl_type = type;
4256         fl->fl_end = OFFSET_MAX;
4257 +
4258 +       vxd_assert(filp->f_xid == vx_current_xid(),
4259 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4260 +       fl->fl_xid = filp->f_xid;
4261 +       vx_locks_inc(fl);
4262         
4263         *lock = fl;
4264         return 0;
4265 @@ -452,6 +468,7 @@ static int lease_init(struct file *filp,
4266  
4267         fl->fl_owner = current->files;
4268         fl->fl_pid = current->tgid;
4269 +       fl->fl_xid = vx_current_xid();
4270  
4271         fl->fl_file = filp;
4272         fl->fl_flags = FL_LEASE;
4273 @@ -471,6 +488,11 @@ static struct file_lock *lease_alloc(str
4274         if (fl == NULL)
4275                 return ERR_PTR(error);
4276  
4277 +       fl->fl_xid = vx_current_xid();
4278 +       if (filp)
4279 +               vxd_assert(filp->f_xid == fl->fl_xid,
4280 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4281 +       vx_locks_inc(fl);
4282         error = lease_init(filp, type, fl);
4283         if (error) {
4284                 locks_free_lock(fl);
4285 @@ -773,6 +795,7 @@ static int flock_lock_file(struct file *
4286                 lock_flocks();
4287         }
4288  
4289 +       new_fl->fl_xid = -1;
4290  find_conflict:
4291         for_each_lock(inode, before) {
4292                 struct file_lock *fl = *before;
4293 @@ -793,6 +816,7 @@ find_conflict:
4294                 goto out;
4295         locks_copy_lock(new_fl, request);
4296         locks_insert_lock(before, new_fl);
4297 +       vx_locks_inc(new_fl);
4298         new_fl = NULL;
4299         error = 0;
4300  
4301 @@ -803,7 +827,8 @@ out:
4302         return error;
4303  }
4304  
4305 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4306 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4307 +       struct file_lock *conflock, xid_t xid)
4308  {
4309         struct file_lock *fl;
4310         struct file_lock *new_fl = NULL;
4311 @@ -813,6 +838,8 @@ static int __posix_lock_file(struct inod
4312         struct file_lock **before;
4313         int error, added = 0;
4314  
4315 +       vxd_assert(xid == vx_current_xid(),
4316 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4317         /*
4318          * We may need two file_lock structures for this operation,
4319          * so we get them in advance to avoid races.
4320 @@ -823,7 +850,11 @@ static int __posix_lock_file(struct inod
4321             (request->fl_type != F_UNLCK ||
4322              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4323                 new_fl = locks_alloc_lock();
4324 +               new_fl->fl_xid = xid;
4325 +               vx_locks_inc(new_fl);
4326                 new_fl2 = locks_alloc_lock();
4327 +               new_fl2->fl_xid = xid;
4328 +               vx_locks_inc(new_fl2);
4329         }
4330  
4331         lock_flocks();
4332 @@ -1022,7 +1053,8 @@ static int __posix_lock_file(struct inod
4333  int posix_lock_file(struct file *filp, struct file_lock *fl,
4334                         struct file_lock *conflock)
4335  {
4336 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4337 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4338 +               fl, conflock, filp->f_xid);
4339  }
4340  EXPORT_SYMBOL(posix_lock_file);
4341  
4342 @@ -1112,7 +1144,7 @@ int locks_mandatory_area(int read_write,
4343         fl.fl_end = offset + count - 1;
4344  
4345         for (;;) {
4346 -               error = __posix_lock_file(inode, &fl, NULL);
4347 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4348                 if (error != FILE_LOCK_DEFERRED)
4349                         break;
4350                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4351 @@ -1407,6 +1439,7 @@ int generic_add_lease(struct file *filp,
4352                 goto out;
4353  
4354         locks_insert_lock(before, lease);
4355 +       vx_locks_inc(lease);
4356         return 0;
4357  
4358  out:
4359 @@ -1847,6 +1880,11 @@ int fcntl_setlk(unsigned int fd, struct
4360         if (file_lock == NULL)
4361                 return -ENOLCK;
4362  
4363 +       vxd_assert(filp->f_xid == vx_current_xid(),
4364 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4365 +       file_lock->fl_xid = filp->f_xid;
4366 +       vx_locks_inc(file_lock);
4367 +
4368         /*
4369          * This might block, so we do it before checking the inode.
4370          */
4371 @@ -1965,6 +2003,11 @@ int fcntl_setlk64(unsigned int fd, struc
4372         if (file_lock == NULL)
4373                 return -ENOLCK;
4374  
4375 +       vxd_assert(filp->f_xid == vx_current_xid(),
4376 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4377 +       file_lock->fl_xid = filp->f_xid;
4378 +       vx_locks_inc(file_lock);
4379 +
4380         /*
4381          * This might block, so we do it before checking the inode.
4382          */
4383 @@ -2230,8 +2273,11 @@ static int locks_show(struct seq_file *f
4384  
4385         lock_get_status(f, fl, *((loff_t *)f->private), "");
4386  
4387 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4388 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4389 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4390 +                       continue;
4391                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4392 +       }
4393  
4394         return 0;
4395  }
4396 diff -NurpP --minimal linux-3.4.83/fs/mount.h linux-3.4.83-vs2.3.3.9/fs/mount.h
4397 --- linux-3.4.83/fs/mount.h     2012-03-19 18:47:26.000000000 +0000
4398 +++ linux-3.4.83-vs2.3.3.9/fs/mount.h   2012-05-21 16:15:05.000000000 +0000
4399 @@ -47,6 +47,7 @@ struct mount {
4400         int mnt_expiry_mark;            /* true if marked for expiry */
4401         int mnt_pinned;
4402         int mnt_ghosts;
4403 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4404  };
4405  
4406  static inline struct mount *real_mount(struct vfsmount *mnt)
4407 diff -NurpP --minimal linux-3.4.83/fs/namei.c linux-3.4.83-vs2.3.3.9/fs/namei.c
4408 --- linux-3.4.83/fs/namei.c     2012-05-21 16:07:25.000000000 +0000
4409 +++ linux-3.4.83-vs2.3.3.9/fs/namei.c   2012-05-21 16:15:05.000000000 +0000
4410 @@ -33,6 +33,14 @@
4411  #include <linux/device_cgroup.h>
4412  #include <linux/fs_struct.h>
4413  #include <linux/posix_acl.h>
4414 +#include <linux/proc_fs.h>
4415 +#include <linux/vserver/inode.h>
4416 +#include <linux/vs_base.h>
4417 +#include <linux/vs_tag.h>
4418 +#include <linux/vs_cowbl.h>
4419 +#include <linux/vs_device.h>
4420 +#include <linux/vs_context.h>
4421 +#include <linux/pid_namespace.h>
4422  #include <asm/uaccess.h>
4423  
4424  #include "internal.h"
4425 @@ -221,6 +229,89 @@ static int check_acl(struct inode *inode
4426         return -EAGAIN;
4427  }
4428  
4429 +static inline int dx_barrier(const struct inode *inode)
4430 +{
4431 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4432 +               vxwprintk_task(1, "did hit the barrier.");
4433 +               return 1;
4434 +       }
4435 +       return 0;
4436 +}
4437 +
4438 +static int __dx_permission(const struct inode *inode, int mask)
4439 +{
4440 +       if (dx_barrier(inode))
4441 +               return -EACCES;
4442 +
4443 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4444 +               /* devpts is xid tagged */
4445 +               if (S_ISDIR(inode->i_mode) ||
4446 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4447 +                       return 0;
4448 +
4449 +               /* just pretend we didn't find anything */
4450 +               return -ENOENT;
4451 +       }
4452 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4453 +               struct proc_dir_entry *de = PDE(inode);
4454 +
4455 +               if (de && !vx_hide_check(0, de->vx_flags))
4456 +                       goto out;
4457 +
4458 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4459 +                       struct pid *pid;
4460 +                       struct task_struct *tsk;
4461 +
4462 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4463 +                           vx_flags(VXF_STATE_SETUP, 0))
4464 +                               return 0;
4465 +
4466 +                       pid = PROC_I(inode)->pid;
4467 +                       if (!pid)
4468 +                               goto out;
4469 +
4470 +                       rcu_read_lock();
4471 +                       tsk = pid_task(pid, PIDTYPE_PID);
4472 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4473 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4474 +                       if (tsk &&
4475 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4476 +                               rcu_read_unlock();
4477 +                               return 0;
4478 +                       }
4479 +                       rcu_read_unlock();
4480 +               }
4481 +               else {
4482 +                       /* FIXME: Should we block some entries here? */
4483 +                       return 0;
4484 +               }
4485 +       }
4486 +       else {
4487 +               if (dx_notagcheck(inode->i_sb) ||
4488 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4489 +                            DX_IDENT))
4490 +                       return 0;
4491 +       }
4492 +
4493 +out:
4494 +       return -EACCES;
4495 +}
4496 +
4497 +int dx_permission(const struct inode *inode, int mask)
4498 +{
4499 +       int ret = __dx_permission(inode, mask);
4500 +       if (unlikely(ret)) {
4501 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4502 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4503 +#endif
4504 +                   vxwprintk_task(1,
4505 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4506 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4507 +                       inode->i_ino);
4508 +       }
4509 +       return ret;
4510 +}
4511 +
4512  /*
4513   * This does the basic permission checking
4514   */
4515 @@ -356,10 +447,14 @@ int inode_permission(struct inode *inode
4516                 /*
4517                  * Nobody gets write access to an immutable file.
4518                  */
4519 -               if (IS_IMMUTABLE(inode))
4520 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4521                         return -EACCES;
4522         }
4523  
4524 +       retval = dx_permission(inode, mask);
4525 +       if (retval)
4526 +               return retval;
4527 +
4528         retval = do_inode_permission(inode, mask);
4529         if (retval)
4530                 return retval;
4531 @@ -1038,7 +1133,8 @@ static void follow_dotdot(struct nameida
4532  
4533                 if (nd->path.dentry == nd->root.dentry &&
4534                     nd->path.mnt == nd->root.mnt) {
4535 -                       break;
4536 +                       /* for sane '/' avoid follow_mount() */
4537 +                       return;
4538                 }
4539                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4540                         /* rare case of legitimate dget_parent()... */
4541 @@ -1174,6 +1270,9 @@ static int do_lookup(struct nameidata *n
4542                                 goto unlazy;
4543                         }
4544                 }
4545 +
4546 +               /* FIXME: check dx permission */
4547 +
4548                 path->mnt = mnt;
4549                 path->dentry = dentry;
4550                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4551 @@ -1208,6 +1307,9 @@ unlazy:
4552                         goto need_lookup;
4553                 }
4554         }
4555 +
4556 +       /* FIXME: check dx permission */
4557 +
4558  done:
4559         path->mnt = mnt;
4560         path->dentry = dentry;
4561 @@ -1981,7 +2083,7 @@ static int may_delete(struct inode *dir,
4562         if (IS_APPEND(dir))
4563                 return -EPERM;
4564         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4565 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4566 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4567                 return -EPERM;
4568         if (isdir) {
4569                 if (!S_ISDIR(victim->d_inode->i_mode))
4570 @@ -2061,19 +2163,25 @@ int vfs_create(struct inode *dir, struct
4571  {
4572         int error = may_create(dir, dentry);
4573  
4574 -       if (error)
4575 +       if (error) {
4576 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4577                 return error;
4578 +       }
4579  
4580         if (!dir->i_op->create)
4581                 return -EACCES; /* shouldn't it be ENOSYS? */
4582         mode &= S_IALLUGO;
4583         mode |= S_IFREG;
4584         error = security_inode_create(dir, dentry, mode);
4585 -       if (error)
4586 +       if (error) {
4587 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4588                 return error;
4589 +       }
4590         error = dir->i_op->create(dir, dentry, mode, nd);
4591         if (!error)
4592                 fsnotify_create(dir, dentry);
4593 +       else
4594 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4595         return error;
4596  }
4597  
4598 @@ -2108,6 +2216,15 @@ static int may_open(struct path *path, i
4599                 break;
4600         }
4601  
4602 +#ifdef CONFIG_VSERVER_COWBL
4603 +       if (IS_COW(inode) &&
4604 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4605 +               if (IS_COW_LINK(inode))
4606 +                       return -EMLINK;
4607 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4608 +               mark_inode_dirty(inode);
4609 +       }
4610 +#endif
4611         error = inode_permission(inode, acc_mode);
4612         if (error)
4613                 return error;
4614 @@ -2332,6 +2449,16 @@ ok:
4615         }
4616  common:
4617         error = may_open(&nd->path, acc_mode, open_flag);
4618 +#ifdef CONFIG_VSERVER_COWBL
4619 +       if (error == -EMLINK) {
4620 +               struct dentry *dentry;
4621 +               dentry = cow_break_link(pathname);
4622 +               if (IS_ERR(dentry))
4623 +                       error = PTR_ERR(dentry);
4624 +               else
4625 +                       dput(dentry);
4626 +       }
4627 +#endif
4628         if (error)
4629                 goto exit;
4630         filp = nameidata_to_filp(nd);
4631 @@ -2374,6 +2501,7 @@ static struct file *path_openat(int dfd,
4632         struct path path;
4633         int error;
4634  
4635 +restart:
4636         filp = get_empty_filp();
4637         if (!filp)
4638                 return ERR_PTR(-ENFILE);
4639 @@ -2411,6 +2539,17 @@ static struct file *path_openat(int dfd,
4640                         filp = do_last(nd, &path, op, pathname);
4641                 put_link(nd, &link, cookie);
4642         }
4643 +
4644 +#ifdef CONFIG_VSERVER_COWBL
4645 +       if (filp == ERR_PTR(-EMLINK)) {
4646 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4647 +                       path_put(&nd->root);
4648 +               if (base)
4649 +                       fput(base);
4650 +               release_open_intent(nd);
4651 +               goto restart;
4652 +       }
4653 +#endif
4654  out:
4655         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4656                 path_put(&nd->root);
4657 @@ -2500,6 +2639,11 @@ struct dentry *kern_path_create(int dfd,
4658                 goto fail;
4659         }
4660         *path = nd.path;
4661 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4662 +               path->dentry, path->dentry->d_name.len,
4663 +               path->dentry->d_name.name, dentry,
4664 +               dentry->d_name.len, dentry->d_name.name,
4665 +               path->dentry->d_inode);
4666         return dentry;
4667  eexist:
4668         dput(dentry);
4669 @@ -2986,7 +3130,7 @@ int vfs_link(struct dentry *old_dentry,
4670         /*
4671          * A link to an append-only or immutable file cannot be created.
4672          */
4673 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4674 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4675                 return -EPERM;
4676         if (!dir->i_op->link)
4677                 return -EPERM;
4678 @@ -3375,6 +3519,253 @@ int vfs_follow_link(struct nameidata *nd
4679         return __vfs_follow_link(nd, link);
4680  }
4681  
4682 +
4683 +#ifdef CONFIG_VSERVER_COWBL
4684 +
4685 +static inline
4686 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4687 +{
4688 +       loff_t ppos = 0;
4689 +
4690 +       return do_splice_direct(in, &ppos, out, len, 0);
4691 +}
4692 +
4693 +extern unsigned int mnt_get_count(struct mount *mnt);
4694 +
4695 +struct dentry *cow_break_link(const char *pathname)
4696 +{
4697 +       int ret, mode, pathlen, redo = 0;
4698 +       struct nameidata old_nd, dir_nd;
4699 +       struct path old_path, dir_path;
4700 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4701 +       struct file *old_file;
4702 +       struct file *new_file;
4703 +       char *to, *path, pad='\251';
4704 +       loff_t size;
4705 +
4706 +       vxdprintk(VXD_CBIT(misc, 1),
4707 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4708 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4709 +       ret = -ENOMEM;
4710 +       if (!path)
4711 +               goto out;
4712 +
4713 +       /* old_nd will have refs to dentry and mnt */
4714 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4715 +       vxdprintk(VXD_CBIT(misc, 2),
4716 +               "do_path_lookup(old): %d [r=%d]",
4717 +               ret, mnt_get_count(real_mount(old_nd.path.mnt)));
4718 +       if (ret < 0)
4719 +               goto out_free_path;
4720 +
4721 +       old_path = old_nd.path;
4722 +       old_dentry = old_path.dentry;
4723 +       mode = old_dentry->d_inode->i_mode;
4724 +
4725 +       to = d_path(&old_path, path, PATH_MAX-2);
4726 +       pathlen = strlen(to);
4727 +       vxdprintk(VXD_CBIT(misc, 2),
4728 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4729 +               old_dentry,
4730 +               old_dentry->d_name.len, old_dentry->d_name.name,
4731 +               old_dentry->d_name.len);
4732 +
4733 +       to[pathlen + 1] = 0;
4734 +retry:
4735 +       new_dentry = NULL;
4736 +       to[pathlen] = pad--;
4737 +       ret = -ELOOP;
4738 +       if (pad <= '\240')
4739 +               goto out_rel_old;
4740 +
4741 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4742 +       /* dir_nd will have refs to dentry and mnt */
4743 +       ret = do_path_lookup(AT_FDCWD, to,
4744 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4745 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4746 +       if (ret < 0)
4747 +               goto retry;
4748 +
4749 +       /* this puppy downs the dir inode mutex if successful */
4750 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4751 +       if (!new_dentry || IS_ERR(new_dentry)) {
4752 +               path_put(&dir_nd.path);
4753 +               vxdprintk(VXD_CBIT(misc, 2),
4754 +                       "kern_path_create(new) failed with %ld",
4755 +                       PTR_ERR(new_dentry));
4756 +               goto retry;
4757 +       }
4758 +       path_put(&dir_path);
4759 +       vxdprintk(VXD_CBIT(misc, 2),
4760 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4761 +               new_dentry,
4762 +               new_dentry->d_name.len, new_dentry->d_name.name,
4763 +               new_dentry->d_name.len);
4764 +
4765 +       dir = dir_nd.path.dentry;
4766 +
4767 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4768 +       vxdprintk(VXD_CBIT(misc, 2),
4769 +               "vfs_create(new): %d", ret);
4770 +       if (ret == -EEXIST) {
4771 +               mutex_unlock(&dir->d_inode->i_mutex);
4772 +               path_put(&dir_nd.path);
4773 +               dput(new_dentry);
4774 +               goto retry;
4775 +       }
4776 +       else if (ret < 0)
4777 +               goto out_unlock_new;
4778 +
4779 +       /* drop out early, ret passes ENOENT */
4780 +       ret = -ENOENT;
4781 +       if ((redo = d_unhashed(old_dentry)))
4782 +               goto out_unlock_new;
4783 +
4784 +       path_get(&old_path);
4785 +       /* this one cleans up the dentry/mnt in case of failure */
4786 +       old_file = dentry_open(old_dentry, old_path.mnt,
4787 +               O_RDONLY, current_cred());
4788 +       vxdprintk(VXD_CBIT(misc, 2),
4789 +               "dentry_open(old): %p", old_file);
4790 +       if (IS_ERR(old_file)) {
4791 +               ret = PTR_ERR(old_file);
4792 +               goto out_unlock_new;
4793 +       }
4794 +
4795 +       dget(new_dentry);
4796 +       mntget(old_path.mnt);
4797 +       /* this one cleans up the dentry/mnt in case of failure */
4798 +       new_file = dentry_open(new_dentry, old_path.mnt,
4799 +               O_WRONLY, current_cred());
4800 +       vxdprintk(VXD_CBIT(misc, 2),
4801 +               "dentry_open(new): %p", new_file);
4802 +       if (IS_ERR(new_file)) {
4803 +               ret = PTR_ERR(new_file);
4804 +               goto out_fput_old;
4805 +       }
4806 +
4807 +       size = i_size_read(old_file->f_dentry->d_inode);
4808 +       ret = do_cow_splice(old_file, new_file, size);
4809 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4810 +       if (ret < 0) {
4811 +               goto out_fput_both;
4812 +       } else if (ret < size) {
4813 +               ret = -ENOSPC;
4814 +               goto out_fput_both;
4815 +       } else {
4816 +               struct inode *old_inode = old_dentry->d_inode;
4817 +               struct inode *new_inode = new_dentry->d_inode;
4818 +               struct iattr attr = {
4819 +                       .ia_uid = old_inode->i_uid,
4820 +                       .ia_gid = old_inode->i_gid,
4821 +                       .ia_valid = ATTR_UID | ATTR_GID
4822 +                       };
4823 +
4824 +               setattr_copy(new_inode, &attr);
4825 +               mark_inode_dirty(new_inode);
4826 +       }
4827 +
4828 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4829 +
4830 +       /* drop out late */
4831 +       ret = -ENOENT;
4832 +       if ((redo = d_unhashed(old_dentry)))
4833 +               goto out_unlock;
4834 +
4835 +       vxdprintk(VXD_CBIT(misc, 2),
4836 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4837 +               new_dentry->d_name.len, new_dentry->d_name.name,
4838 +               new_dentry->d_name.len,
4839 +               old_dentry->d_name.len, old_dentry->d_name.name,
4840 +               old_dentry->d_name.len);
4841 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4842 +               old_dentry->d_parent->d_inode, old_dentry);
4843 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4844 +
4845 +out_unlock:
4846 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4847 +
4848 +out_fput_both:
4849 +       vxdprintk(VXD_CBIT(misc, 3),
4850 +               "fput(new_file=%p[#%ld])", new_file,
4851 +               atomic_long_read(&new_file->f_count));
4852 +       fput(new_file);
4853 +
4854 +out_fput_old:
4855 +       vxdprintk(VXD_CBIT(misc, 3),
4856 +               "fput(old_file=%p[#%ld])", old_file,
4857 +               atomic_long_read(&old_file->f_count));
4858 +       fput(old_file);
4859 +
4860 +out_unlock_new:
4861 +       mutex_unlock(&dir->d_inode->i_mutex);
4862 +       if (!ret)
4863 +               goto out_redo;
4864 +
4865 +       /* error path cleanup */
4866 +       vfs_unlink(dir->d_inode, new_dentry);
4867 +
4868 +out_redo:
4869 +       if (!redo)
4870 +               goto out_rel_both;
4871 +       /* lookup dentry once again */
4872 +       /* old_nd.path is freed as old_path in out_rel_old */
4873 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4874 +       if (ret)
4875 +               goto out_rel_both;
4876 +
4877 +       dput(new_dentry);
4878 +       new_dentry = old_nd.path.dentry;
4879 +       vxdprintk(VXD_CBIT(misc, 2),
4880 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4881 +               new_dentry,
4882 +               new_dentry->d_name.len, new_dentry->d_name.name,
4883 +               new_dentry->d_name.len);
4884 +       dget(new_dentry);
4885 +
4886 +out_rel_both:
4887 +       path_put(&dir_nd.path);
4888 +out_rel_old:
4889 +       path_put(&old_path);
4890 +out_free_path:
4891 +       kfree(path);
4892 +out:
4893 +       if (ret) {
4894 +               dput(new_dentry);
4895 +               new_dentry = ERR_PTR(ret);
4896 +       }
4897 +       vxdprintk(VXD_CBIT(misc, 3),
4898 +               "cow_break_link returning with %p [r=%d]",
4899 +               new_dentry, mnt_get_count(real_mount(old_nd.path.mnt)));
4900 +       return new_dentry;
4901 +}
4902 +
4903 +#endif
4904 +
4905 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4906 +{
4907 +       struct path path;
4908 +       struct vfsmount *vmnt;
4909 +       char *pstr, *root;
4910 +       int length = 0;
4911 +
4912 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4913 +       if (!pstr)
4914 +               return 0;
4915 +
4916 +       vmnt = &ns->root->mnt;
4917 +       path.mnt = vmnt;
4918 +       path.dentry = vmnt->mnt_root;
4919 +       root = d_path(&path, pstr, PATH_MAX - 2);
4920 +       length = sprintf(buffer + length,
4921 +               "Namespace:\t%p [#%u]\n"
4922 +               "RootPath:\t%s\n",
4923 +               ns, atomic_read(&ns->count),
4924 +               root);
4925 +       kfree(pstr);
4926 +       return length;
4927 +}
4928 +
4929  /* get the link contents into pagecache */
4930  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4931  {
4932 @@ -3499,3 +3890,4 @@ EXPORT_SYMBOL(vfs_symlink);
4933  EXPORT_SYMBOL(vfs_unlink);
4934  EXPORT_SYMBOL(dentry_unhash);
4935  EXPORT_SYMBOL(generic_readlink);
4936 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4937 diff -NurpP --minimal linux-3.4.83/fs/namespace.c linux-3.4.83-vs2.3.3.9/fs/namespace.c
4938 --- linux-3.4.83/fs/namespace.c 2014-03-12 09:48:14.000000000 +0000
4939 +++ linux-3.4.83-vs2.3.3.9/fs/namespace.c       2012-06-28 14:45:07.000000000 +0000
4940 @@ -20,6 +20,11 @@
4941  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4942  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4943  #include <linux/uaccess.h>
4944 +#include <linux/vs_base.h>
4945 +#include <linux/vs_context.h>
4946 +#include <linux/vs_tag.h>
4947 +#include <linux/vserver/space.h>
4948 +#include <linux/vserver/global.h>
4949  #include "pnode.h"
4950  #include "internal.h"
4951  
4952 @@ -697,6 +702,10 @@ vfs_kern_mount(struct file_system_type *
4953         if (!type)
4954                 return ERR_PTR(-ENODEV);
4955  
4956 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4957 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4958 +               return ERR_PTR(-EPERM);
4959 +
4960         mnt = alloc_vfsmnt(name);
4961         if (!mnt)
4962                 return ERR_PTR(-ENOMEM);
4963 @@ -745,6 +754,7 @@ static struct mount *clone_mnt(struct mo
4964                 mnt->mnt.mnt_root = dget(root);
4965                 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4966                 mnt->mnt_parent = mnt;
4967 +               mnt->mnt_tag = old->mnt_tag;
4968                 br_write_lock(vfsmount_lock);
4969                 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4970                 br_write_unlock(vfsmount_lock);
4971 @@ -1210,7 +1220,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4972                 goto dput_and_out;
4973  
4974         retval = -EPERM;
4975 -       if (!capable(CAP_SYS_ADMIN))
4976 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4977                 goto dput_and_out;
4978  
4979         retval = do_umount(mnt, flags);
4980 @@ -1236,7 +1246,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4981  
4982  static int mount_is_safe(struct path *path)
4983  {
4984 -       if (capable(CAP_SYS_ADMIN))
4985 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4986                 return 0;
4987         return -EPERM;
4988  #ifdef notyet
4989 @@ -1549,7 +1559,7 @@ static int do_change_type(struct path *p
4990         int type;
4991         int err = 0;
4992  
4993 -       if (!capable(CAP_SYS_ADMIN))
4994 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4995                 return -EPERM;
4996  
4997         if (path->dentry != path->mnt->mnt_root)
4998 @@ -1565,6 +1575,7 @@ static int do_change_type(struct path *p
4999                 if (err)
5000                         goto out_unlock;
5001         }
5002 +       // mnt->mnt_flags = mnt_flags;
5003  
5004         br_write_lock(vfsmount_lock);
5005         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5006 @@ -1580,12 +1591,14 @@ static int do_change_type(struct path *p
5007   * do loopback mount.
5008   */
5009  static int do_loopback(struct path *path, char *old_name,
5010 -                               int recurse)
5011 +       tag_t tag, unsigned long flags, int mnt_flags)
5012  {
5013         LIST_HEAD(umount_list);
5014         struct path old_path;
5015         struct mount *mnt = NULL, *old;
5016         int err = mount_is_safe(path);
5017 +       int recurse = flags & MS_REC;
5018 +
5019         if (err)
5020                 return err;
5021         if (!old_name || !*old_name)
5022 @@ -1653,13 +1666,13 @@ static int change_mount_flags(struct vfs
5023   * on it - tough luck.
5024   */
5025  static int do_remount(struct path *path, int flags, int mnt_flags,
5026 -                     void *data)
5027 +       void *data, xid_t xid)
5028  {
5029         int err;
5030         struct super_block *sb = path->mnt->mnt_sb;
5031         struct mount *mnt = real_mount(path->mnt);
5032  
5033 -       if (!capable(CAP_SYS_ADMIN))
5034 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5035                 return -EPERM;
5036  
5037         if (!check_mnt(mnt))
5038 @@ -1708,7 +1721,7 @@ static int do_move_mount(struct path *pa
5039         struct mount *p;
5040         struct mount *old;
5041         int err = 0;
5042 -       if (!capable(CAP_SYS_ADMIN))
5043 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5044                 return -EPERM;
5045         if (!old_name || !*old_name)
5046                 return -EINVAL;
5047 @@ -1859,7 +1872,7 @@ static int do_new_mount(struct path *pat
5048                 return -EINVAL;
5049  
5050         /* we need capabilities... */
5051 -       if (!capable(CAP_SYS_ADMIN))
5052 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5053                 return -EPERM;
5054  
5055         mnt = do_kern_mount(type, flags, name, data);
5056 @@ -2129,6 +2142,7 @@ long do_mount(char *dev_name, char *dir_
5057         struct path path;
5058         int retval = 0;
5059         int mnt_flags = 0;
5060 +       tag_t tag = 0;
5061  
5062         /* Discard magic */
5063         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5064 @@ -2156,6 +2170,12 @@ long do_mount(char *dev_name, char *dir_
5065         if (!(flags & MS_NOATIME))
5066                 mnt_flags |= MNT_RELATIME;
5067  
5068 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5069 +               /* FIXME: bind and re-mounts get the tag flag? */
5070 +               if (flags & (MS_BIND|MS_REMOUNT))
5071 +                       flags |= MS_TAGID;
5072 +       }
5073 +
5074         /* Separate the per-mountpoint flags */
5075         if (flags & MS_NOSUID)
5076                 mnt_flags |= MNT_NOSUID;
5077 @@ -2172,15 +2192,17 @@ long do_mount(char *dev_name, char *dir_
5078         if (flags & MS_RDONLY)
5079                 mnt_flags |= MNT_READONLY;
5080  
5081 +       if (!capable(CAP_SYS_ADMIN))
5082 +               mnt_flags |= MNT_NODEV;
5083         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5084                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5085                    MS_STRICTATIME);
5086  
5087         if (flags & MS_REMOUNT)
5088                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5089 -                                   data_page);
5090 +                                   data_page, tag);
5091         else if (flags & MS_BIND)
5092 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5093 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5094         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5095                 retval = do_change_type(&path, flags);
5096         else if (flags & MS_MOVE)
5097 @@ -2283,6 +2305,7 @@ static struct mnt_namespace *dup_mnt_ns(
5098                 q = next_mnt(q, new);
5099         }
5100         up_write(&namespace_sem);
5101 +       atomic_inc(&vs_global_mnt_ns);
5102  
5103         if (rootmnt)
5104                 mntput(rootmnt);
5105 @@ -2479,9 +2502,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5106         error = -EINVAL;
5107         new_mnt = real_mount(new.mnt);
5108         root_mnt = real_mount(root.mnt);
5109 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5110 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5111                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5112 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5113 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5114 +               !vx_flags(VXF_STATE_SETUP, 0))
5115                 goto out4;
5116         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5117                 goto out4;
5118 @@ -2602,6 +2626,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5119         br_write_unlock(vfsmount_lock);
5120         up_write(&namespace_sem);
5121         release_mounts(&umount_list);
5122 +       atomic_dec(&vs_global_mnt_ns);
5123         kfree(ns);
5124  }
5125  
5126 diff -NurpP --minimal linux-3.4.83/fs/nfs/client.c linux-3.4.83-vs2.3.3.9/fs/nfs/client.c
5127 --- linux-3.4.83/fs/nfs/client.c        2014-03-12 09:48:14.000000000 +0000
5128 +++ linux-3.4.83-vs2.3.3.9/fs/nfs/client.c      2013-01-16 00:15:57.000000000 +0000
5129 @@ -801,6 +801,9 @@ static int nfs_init_server_rpcclient(str
5130         if (server->flags & NFS_MOUNT_SOFT)
5131                 server->client->cl_softrtry = 1;
5132  
5133 +       server->client->cl_tag = 0;
5134 +       if (server->flags & NFS_MOUNT_TAGGED)
5135 +               server->client->cl_tag = 1;
5136         return 0;
5137  }
5138  
5139 @@ -976,6 +979,10 @@ static void nfs_server_set_fsinfo(struct
5140                 server->acdirmin = server->acdirmax = 0;
5141         }
5142  
5143 +       /* FIXME: needs fsinfo
5144 +       if (server->flags & NFS_MOUNT_TAGGED)
5145 +               sb->s_flags |= MS_TAGGED;       */
5146 +
5147         server->maxfilesize = fsinfo->maxfilesize;
5148  
5149         server->time_delta = fsinfo->time_delta;
5150 diff -NurpP --minimal linux-3.4.83/fs/nfs/dir.c linux-3.4.83-vs2.3.3.9/fs/nfs/dir.c
5151 --- linux-3.4.83/fs/nfs/dir.c   2014-03-12 09:48:14.000000000 +0000
5152 +++ linux-3.4.83-vs2.3.3.9/fs/nfs/dir.c 2013-01-16 00:15:57.000000000 +0000
5153 @@ -35,6 +35,7 @@
5154  #include <linux/sched.h>
5155  #include <linux/kmemleak.h>
5156  #include <linux/xattr.h>
5157 +#include <linux/vs_tag.h>
5158  
5159  #include "delegation.h"
5160  #include "iostat.h"
5161 @@ -1314,6 +1315,7 @@ static struct dentry *nfs_lookup(struct
5162         if (IS_ERR(res))
5163                 goto out_unblock_sillyrename;
5164  
5165 +       dx_propagate_tag(nd, inode);
5166  no_entry:
5167         res = d_materialise_unique(dentry, inode);
5168         if (res != NULL) {
5169 diff -NurpP --minimal linux-3.4.83/fs/nfs/inode.c linux-3.4.83-vs2.3.3.9/fs/nfs/inode.c
5170 --- linux-3.4.83/fs/nfs/inode.c 2014-03-12 09:48:14.000000000 +0000
5171 +++ linux-3.4.83-vs2.3.3.9/fs/nfs/inode.c       2014-03-12 09:55:28.000000000 +0000
5172 @@ -40,6 +40,7 @@
5173  #include <linux/compat.h>
5174  #include <linux/freezer.h>
5175  #include <linux/crc32.h>
5176 +#include <linux/vs_tag.h>
5177  
5178  #include <asm/uaccess.h>
5179  
5180 @@ -277,6 +278,8 @@ nfs_fhget(struct super_block *sb, struct
5181         if (inode->i_state & I_NEW) {
5182                 struct nfs_inode *nfsi = NFS_I(inode);
5183                 unsigned long now = jiffies;
5184 +               uid_t uid;
5185 +               gid_t gid;
5186  
5187                 /* We set i_ino for the few things that still rely on it,
5188                  * such as stat(2) */
5189 @@ -325,8 +328,8 @@ nfs_fhget(struct super_block *sb, struct
5190                 inode->i_version = 0;
5191                 inode->i_size = 0;
5192                 clear_nlink(inode);
5193 -               inode->i_uid = -2;
5194 -               inode->i_gid = -2;
5195 +               uid = -2;
5196 +               gid = -2;
5197                 inode->i_blocks = 0;
5198                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5199  
5200 @@ -363,13 +366,13 @@ nfs_fhget(struct super_block *sb, struct
5201                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5202                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5203                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5204 -                       inode->i_uid = fattr->uid;
5205 +                       uid = fattr->uid;
5206                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5207                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5208                                 | NFS_INO_INVALID_ACCESS
5209                                 | NFS_INO_INVALID_ACL;
5210                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5211 -                       inode->i_gid = fattr->gid;
5212 +                       gid = fattr->gid;
5213                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5214                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5215                                 | NFS_INO_INVALID_ACCESS
5216 @@ -382,6 +385,11 @@ nfs_fhget(struct super_block *sb, struct
5217                          */
5218                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5219                 }
5220 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5221 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5222 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5223 +                               /* maybe fattr->xid someday */
5224 +
5225                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5226                 nfsi->attrtimeo_timestamp = now;
5227                 nfsi->access_cache = RB_ROOT;
5228 @@ -499,6 +507,8 @@ void nfs_setattr_update_inode(struct ino
5229                         inode->i_uid = attr->ia_uid;
5230                 if ((attr->ia_valid & ATTR_GID) != 0)
5231                         inode->i_gid = attr->ia_gid;
5232 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5233 +                       inode->i_tag = attr->ia_tag;
5234                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5235                 spin_unlock(&inode->i_lock);
5236         }
5237 @@ -948,6 +958,9 @@ static int nfs_check_inode_attributes(st
5238         struct nfs_inode *nfsi = NFS_I(inode);
5239         loff_t cur_size, new_isize;
5240         unsigned long invalid = 0;
5241 +       uid_t uid;
5242 +       gid_t gid;
5243 +       tag_t tag;
5244  
5245  
5246         /* Has the inode gone and changed behind our back? */
5247 @@ -971,13 +984,18 @@ static int nfs_check_inode_attributes(st
5248                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5249         }
5250  
5251 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5252 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5253 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5254 +
5255         /* Have any file permissions changed? */
5256         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5257                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5258 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5259 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5260                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5261 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5262 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5263                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5264 +               /* maybe check for tag too? */
5265  
5266         /* Has the link count changed? */
5267         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5268 @@ -1275,6 +1293,9 @@ static int nfs_update_inode(struct inode
5269         unsigned long invalid = 0;
5270         unsigned long now = jiffies;
5271         unsigned long save_cache_validity;
5272 +       uid_t uid;
5273 +       gid_t gid;
5274 +       tag_t tag;
5275  
5276         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5277                         __func__, inode->i_sb->s_id, inode->i_ino,
5278 @@ -1383,6 +1404,9 @@ static int nfs_update_inode(struct inode
5279                                 | NFS_INO_REVAL_PAGECACHE
5280                                 | NFS_INO_REVAL_FORCED);
5281  
5282 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5283 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5284 +       tag = inode->i_tag;
5285  
5286         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5287                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5288 @@ -1404,9 +1428,9 @@ static int nfs_update_inode(struct inode
5289                                 | NFS_INO_REVAL_FORCED);
5290  
5291         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5292 -               if (inode->i_uid != fattr->uid) {
5293 +               if (uid != fattr->uid) {
5294                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5295 -                       inode->i_uid = fattr->uid;
5296 +                       uid = fattr->uid;
5297                 }
5298         } else if (server->caps & NFS_CAP_OWNER)
5299                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5300 @@ -1415,9 +1439,9 @@ static int nfs_update_inode(struct inode
5301                                 | NFS_INO_REVAL_FORCED);
5302  
5303         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5304 -               if (inode->i_gid != fattr->gid) {
5305 +               if (gid != fattr->gid) {
5306                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5307 -                       inode->i_gid = fattr->gid;
5308 +                       gid = fattr->gid;
5309                 }
5310         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5311                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5312 @@ -1425,6 +1449,10 @@ static int nfs_update_inode(struct inode
5313                                 | NFS_INO_INVALID_ACL
5314                                 | NFS_INO_REVAL_FORCED);
5315  
5316 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5317 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5318 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5319 +
5320         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5321                 if (inode->i_nlink != fattr->nlink) {
5322                         invalid |= NFS_INO_INVALID_ATTR;
5323 diff -NurpP --minimal linux-3.4.83/fs/nfs/nfs3xdr.c linux-3.4.83-vs2.3.3.9/fs/nfs/nfs3xdr.c
5324 --- linux-3.4.83/fs/nfs/nfs3xdr.c       2012-05-21 16:07:25.000000000 +0000
5325 +++ linux-3.4.83-vs2.3.3.9/fs/nfs/nfs3xdr.c     2012-05-21 16:15:05.000000000 +0000
5326 @@ -20,6 +20,7 @@
5327  #include <linux/nfs3.h>
5328  #include <linux/nfs_fs.h>
5329  #include <linux/nfsacl.h>
5330 +#include <linux/vs_tag.h>
5331  #include "internal.h"
5332  
5333  #define NFSDBG_FACILITY                NFSDBG_XDR
5334 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5335   *             set_mtime       mtime;
5336   *     };
5337   */
5338 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5339 +static void encode_sattr3(struct xdr_stream *xdr,
5340 +       const struct iattr *attr, int tag)
5341  {
5342         u32 nbytes;
5343         __be32 *p;
5344 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5345         } else
5346                 *p++ = xdr_zero;
5347  
5348 -       if (attr->ia_valid & ATTR_UID) {
5349 +       if (attr->ia_valid & ATTR_UID ||
5350 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5351                 *p++ = xdr_one;
5352 -               *p++ = cpu_to_be32(attr->ia_uid);
5353 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5354 +                       attr->ia_uid, attr->ia_tag));
5355         } else
5356                 *p++ = xdr_zero;
5357  
5358 -       if (attr->ia_valid & ATTR_GID) {
5359 +       if (attr->ia_valid & ATTR_GID ||
5360 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5361                 *p++ = xdr_one;
5362 -               *p++ = cpu_to_be32(attr->ia_gid);
5363 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5364 +                       attr->ia_gid, attr->ia_tag));
5365         } else
5366                 *p++ = xdr_zero;
5367  
5368 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5369                                       const struct nfs3_sattrargs *args)
5370  {
5371         encode_nfs_fh3(xdr, args->fh);
5372 -       encode_sattr3(xdr, args->sattr);
5373 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5374         encode_sattrguard3(xdr, args);
5375  }
5376  
5377 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5378   *     };
5379   */
5380  static void encode_createhow3(struct xdr_stream *xdr,
5381 -                             const struct nfs3_createargs *args)
5382 +       const struct nfs3_createargs *args, int tag)
5383  {
5384         encode_uint32(xdr, args->createmode);
5385         switch (args->createmode) {
5386         case NFS3_CREATE_UNCHECKED:
5387         case NFS3_CREATE_GUARDED:
5388 -               encode_sattr3(xdr, args->sattr);
5389 +               encode_sattr3(xdr, args->sattr, tag);
5390                 break;
5391         case NFS3_CREATE_EXCLUSIVE:
5392                 encode_createverf3(xdr, args->verifier);
5393 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5394                                      const struct nfs3_createargs *args)
5395  {
5396         encode_diropargs3(xdr, args->fh, args->name, args->len);
5397 -       encode_createhow3(xdr, args);
5398 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5399  }
5400  
5401  /*
5402 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5403                                     const struct nfs3_mkdirargs *args)
5404  {
5405         encode_diropargs3(xdr, args->fh, args->name, args->len);
5406 -       encode_sattr3(xdr, args->sattr);
5407 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5408  }
5409  
5410  /*
5411 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5412   *     };
5413   */
5414  static void encode_symlinkdata3(struct xdr_stream *xdr,
5415 -                               const struct nfs3_symlinkargs *args)
5416 +       const struct nfs3_symlinkargs *args, int tag)
5417  {
5418 -       encode_sattr3(xdr, args->sattr);
5419 +       encode_sattr3(xdr, args->sattr, tag);
5420         encode_nfspath3(xdr, args->pages, args->pathlen);
5421  }
5422  
5423 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5424                                       const struct nfs3_symlinkargs *args)
5425  {
5426         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5427 -       encode_symlinkdata3(xdr, args);
5428 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5429  }
5430  
5431  /*
5432 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5433   *     };
5434   */
5435  static void encode_devicedata3(struct xdr_stream *xdr,
5436 -                              const struct nfs3_mknodargs *args)
5437 +       const struct nfs3_mknodargs *args, int tag)
5438  {
5439 -       encode_sattr3(xdr, args->sattr);
5440 +       encode_sattr3(xdr, args->sattr, tag);
5441         encode_specdata3(xdr, args->rdev);
5442  }
5443  
5444  static void encode_mknoddata3(struct xdr_stream *xdr,
5445 -                             const struct nfs3_mknodargs *args)
5446 +       const struct nfs3_mknodargs *args, int tag)
5447  {
5448         encode_ftype3(xdr, args->type);
5449         switch (args->type) {
5450         case NF3CHR:
5451         case NF3BLK:
5452 -               encode_devicedata3(xdr, args);
5453 +               encode_devicedata3(xdr, args, tag);
5454                 break;
5455         case NF3SOCK:
5456         case NF3FIFO:
5457 -               encode_sattr3(xdr, args->sattr);
5458 +               encode_sattr3(xdr, args->sattr, tag);
5459                 break;
5460         case NF3REG:
5461         case NF3DIR:
5462 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5463                                     const struct nfs3_mknodargs *args)
5464  {
5465         encode_diropargs3(xdr, args->fh, args->name, args->len);
5466 -       encode_mknoddata3(xdr, args);
5467 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5468  }
5469  
5470  /*
5471 diff -NurpP --minimal linux-3.4.83/fs/nfs/super.c linux-3.4.83-vs2.3.3.9/fs/nfs/super.c
5472 --- linux-3.4.83/fs/nfs/super.c 2014-03-12 09:48:15.000000000 +0000
5473 +++ linux-3.4.83-vs2.3.3.9/fs/nfs/super.c       2013-01-16 00:15:57.000000000 +0000
5474 @@ -54,6 +54,7 @@
5475  #include <linux/parser.h>
5476  #include <linux/nsproxy.h>
5477  #include <linux/rcupdate.h>
5478 +#include <linux/vs_tag.h>
5479  
5480  #include <asm/uaccess.h>
5481  
5482 @@ -86,6 +87,7 @@ enum {
5483         Opt_sharecache, Opt_nosharecache,
5484         Opt_resvport, Opt_noresvport,
5485         Opt_fscache, Opt_nofscache,
5486 +       Opt_tag, Opt_notag,
5487  
5488         /* Mount options that take integer arguments */
5489         Opt_port,
5490 @@ -98,6 +100,7 @@ enum {
5491         Opt_mountport,
5492         Opt_mountvers,
5493         Opt_minorversion,
5494 +       Opt_tagid,
5495  
5496         /* Mount options that take string arguments */
5497         Opt_nfsvers,
5498 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5499         /* The following needs to be listed after all other options */
5500         { Opt_nfsvers, "v%s" },
5501  
5502 +       { Opt_tag, "tag" },
5503 +       { Opt_notag, "notag" },
5504 +       { Opt_tagid, "tagid=%u" },
5505 +
5506         { Opt_err, NULL }
5507  };
5508  
5509 @@ -674,6 +681,7 @@ static void nfs_show_mount_options(struc
5510                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5511                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5512                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5513 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5514                 { 0, NULL, NULL }
5515         };
5516         const struct proc_nfs_info *nfs_infop;
5517 @@ -1286,6 +1294,14 @@ static int nfs_parse_mount_options(char
5518                         kfree(mnt->fscache_uniq);
5519                         mnt->fscache_uniq = NULL;
5520                         break;
5521 +#ifndef CONFIG_TAGGING_NONE
5522 +               case Opt_tag:
5523 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5524 +                       break;
5525 +               case Opt_notag:
5526 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5527 +                       break;
5528 +#endif
5529  
5530                 /*
5531                  * options that take numeric values
5532 @@ -1372,6 +1388,12 @@ static int nfs_parse_mount_options(char
5533                                 goto out_invalid_value;
5534                         mnt->minorversion = option;
5535                         break;
5536 +#ifdef CONFIG_PROPAGATE
5537 +               case Opt_tagid:
5538 +                       /* use args[0] */
5539 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5540 +                       break;
5541 +#endif
5542  
5543                 /*
5544                  * options that take text values
5545 diff -NurpP --minimal linux-3.4.83/fs/nfsd/auth.c linux-3.4.83-vs2.3.3.9/fs/nfsd/auth.c
5546 --- linux-3.4.83/fs/nfsd/auth.c 2010-02-25 10:52:05.000000000 +0000
5547 +++ linux-3.4.83-vs2.3.3.9/fs/nfsd/auth.c       2012-05-21 16:15:05.000000000 +0000
5548 @@ -1,6 +1,7 @@
5549  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5550  
5551  #include <linux/sched.h>
5552 +#include <linux/vs_tag.h>
5553  #include "nfsd.h"
5554  #include "auth.h"
5555  
5556 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5557  
5558         new->fsuid = rqstp->rq_cred.cr_uid;
5559         new->fsgid = rqstp->rq_cred.cr_gid;
5560 +       /* FIXME: this desperately needs a tag :)
5561 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5562 +                       */
5563  
5564         rqgi = rqstp->rq_cred.cr_group_info;
5565  
5566 diff -NurpP --minimal linux-3.4.83/fs/nfsd/nfs3xdr.c linux-3.4.83-vs2.3.3.9/fs/nfsd/nfs3xdr.c
5567 --- linux-3.4.83/fs/nfsd/nfs3xdr.c      2012-05-21 16:07:26.000000000 +0000
5568 +++ linux-3.4.83-vs2.3.3.9/fs/nfsd/nfs3xdr.c    2012-05-21 16:15:05.000000000 +0000
5569 @@ -7,6 +7,7 @@
5570   */
5571  
5572  #include <linux/namei.h>
5573 +#include <linux/vs_tag.h>
5574  #include "xdr3.h"
5575  #include "auth.h"
5576  
5577 @@ -95,6 +96,8 @@ static __be32 *
5578  decode_sattr3(__be32 *p, struct iattr *iap)
5579  {
5580         u32     tmp;
5581 +       uid_t   uid = 0;
5582 +       gid_t   gid = 0;
5583  
5584         iap->ia_valid = 0;
5585  
5586 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5587         }
5588         if (*p++) {
5589                 iap->ia_valid |= ATTR_UID;
5590 -               iap->ia_uid = ntohl(*p++);
5591 +               uid = ntohl(*p++);
5592         }
5593         if (*p++) {
5594                 iap->ia_valid |= ATTR_GID;
5595 -               iap->ia_gid = ntohl(*p++);
5596 +               gid = ntohl(*p++);
5597         }
5598 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5599 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5600 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5601         if (*p++) {
5602                 u64     newsize;
5603  
5604 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5605         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5606         *p++ = htonl((u32) stat->mode);
5607         *p++ = htonl((u32) stat->nlink);
5608 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5609 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5610 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5611 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5612 +               stat->uid, stat->tag)));
5613 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5614 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5615 +               stat->gid, stat->tag)));
5616         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5617                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5618         } else {
5619 diff -NurpP --minimal linux-3.4.83/fs/nfsd/nfs4xdr.c linux-3.4.83-vs2.3.3.9/fs/nfsd/nfs4xdr.c
5620 --- linux-3.4.83/fs/nfsd/nfs4xdr.c      2014-03-12 09:48:15.000000000 +0000
5621 +++ linux-3.4.83-vs2.3.3.9/fs/nfsd/nfs4xdr.c    2013-07-14 13:38:35.000000000 +0000
5622 @@ -46,6 +46,7 @@
5623  #include <linux/utsname.h>
5624  #include <linux/pagemap.h>
5625  #include <linux/sunrpc/svcauth_gss.h>
5626 +#include <linux/vs_tag.h>
5627  
5628  #include "idmap.h"
5629  #include "acl.h"
5630 @@ -2319,14 +2320,18 @@ out_acl:
5631                 WRITE32(stat.nlink);
5632         }
5633         if (bmval1 & FATTR4_WORD1_OWNER) {
5634 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5635 +               status = nfsd4_encode_user(rqstp,
5636 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5637 +                       stat.uid, stat.tag), &p, &buflen);
5638                 if (status == nfserr_resource)
5639                         goto out_resource;
5640                 if (status)
5641                         goto out;
5642         }
5643         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5644 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5645 +               status = nfsd4_encode_group(rqstp,
5646 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5647 +                       stat.gid, stat.tag), &p, &buflen);
5648                 if (status == nfserr_resource)
5649                         goto out_resource;
5650                 if (status)
5651 diff -NurpP --minimal linux-3.4.83/fs/nfsd/nfsxdr.c linux-3.4.83-vs2.3.3.9/fs/nfsd/nfsxdr.c
5652 --- linux-3.4.83/fs/nfsd/nfsxdr.c       2011-05-22 14:17:53.000000000 +0000
5653 +++ linux-3.4.83-vs2.3.3.9/fs/nfsd/nfsxdr.c     2012-05-21 16:15:05.000000000 +0000
5654 @@ -6,6 +6,7 @@
5655  
5656  #include "xdr.h"
5657  #include "auth.h"
5658 +#include <linux/vs_tag.h>
5659  
5660  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5661  
5662 @@ -88,6 +89,8 @@ static __be32 *
5663  decode_sattr(__be32 *p, struct iattr *iap)
5664  {
5665         u32     tmp, tmp1;
5666 +       uid_t   uid = 0;
5667 +       gid_t   gid = 0;
5668  
5669         iap->ia_valid = 0;
5670  
5671 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5672         }
5673         if ((tmp = ntohl(*p++)) != (u32)-1) {
5674                 iap->ia_valid |= ATTR_UID;
5675 -               iap->ia_uid = tmp;
5676 +               uid = tmp;
5677         }
5678         if ((tmp = ntohl(*p++)) != (u32)-1) {
5679                 iap->ia_valid |= ATTR_GID;
5680 -               iap->ia_gid = tmp;
5681 +               gid = tmp;
5682         }
5683 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5684 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5685 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5686         if ((tmp = ntohl(*p++)) != (u32)-1) {
5687                 iap->ia_valid |= ATTR_SIZE;
5688                 iap->ia_size = tmp;
5689 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5690         *p++ = htonl(nfs_ftypes[type >> 12]);
5691         *p++ = htonl((u32) stat->mode);
5692         *p++ = htonl((u32) stat->nlink);
5693 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5694 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5695 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5696 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5697 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5698 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5699  
5700         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5701                 *p++ = htonl(NFS_MAXPATHLEN);
5702 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/dlmglue.c linux-3.4.83-vs2.3.3.9/fs/ocfs2/dlmglue.c
5703 --- linux-3.4.83/fs/ocfs2/dlmglue.c     2014-03-12 09:48:15.000000000 +0000
5704 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/dlmglue.c   2013-03-02 15:26:44.000000000 +0000
5705 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5706         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5707         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5708         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5709 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5710         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5711         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5712         lvb->lvb_iatime_packed  =
5713 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5714  
5715         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5716         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5717 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5718         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5719         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5720         ocfs2_unpack_timespec(&inode->i_atime,
5721 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/dlmglue.h linux-3.4.83-vs2.3.3.9/fs/ocfs2/dlmglue.h
5722 --- linux-3.4.83/fs/ocfs2/dlmglue.h     2010-10-21 11:07:50.000000000 +0000
5723 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/dlmglue.h   2012-05-21 16:15:05.000000000 +0000
5724 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5725         __be16       lvb_inlink;
5726         __be32       lvb_iattr;
5727         __be32       lvb_igeneration;
5728 -       __be32       lvb_reserved2;
5729 +       __be16       lvb_itag;
5730 +       __be16       lvb_reserved2;
5731  };
5732  
5733  #define OCFS2_QINFO_LVB_VERSION 1
5734 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/file.c linux-3.4.83-vs2.3.3.9/fs/ocfs2/file.c
5735 --- linux-3.4.83/fs/ocfs2/file.c        2014-03-12 09:48:15.000000000 +0000
5736 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/file.c      2012-07-17 22:29:43.000000000 +0000
5737 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5738                 attr->ia_valid &= ~ATTR_SIZE;
5739  
5740  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5741 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5742 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5743         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5744                 return 0;
5745  
5746 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/inode.c linux-3.4.83-vs2.3.3.9/fs/ocfs2/inode.c
5747 --- linux-3.4.83/fs/ocfs2/inode.c       2012-01-09 15:14:55.000000000 +0000
5748 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/inode.c     2012-05-21 16:15:05.000000000 +0000
5749 @@ -28,6 +28,7 @@
5750  #include <linux/highmem.h>
5751  #include <linux/pagemap.h>
5752  #include <linux/quotaops.h>
5753 +#include <linux/vs_tag.h>
5754  
5755  #include <asm/byteorder.h>
5756  
5757 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5758  {
5759         unsigned int flags = OCFS2_I(inode)->ip_attr;
5760  
5761 -       inode->i_flags &= ~(S_IMMUTABLE |
5762 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5763                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5764  
5765         if (flags & OCFS2_IMMUTABLE_FL)
5766                 inode->i_flags |= S_IMMUTABLE;
5767 +       if (flags & OCFS2_IXUNLINK_FL)
5768 +               inode->i_flags |= S_IXUNLINK;
5769  
5770         if (flags & OCFS2_SYNC_FL)
5771                 inode->i_flags |= S_SYNC;
5772 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5773                 inode->i_flags |= S_NOATIME;
5774         if (flags & OCFS2_DIRSYNC_FL)
5775                 inode->i_flags |= S_DIRSYNC;
5776 +
5777 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5778 +
5779 +       if (flags & OCFS2_BARRIER_FL)
5780 +               inode->i_vflags |= V_BARRIER;
5781 +       if (flags & OCFS2_COW_FL)
5782 +               inode->i_vflags |= V_COW;
5783  }
5784  
5785  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5786  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5787  {
5788         unsigned int flags = oi->vfs_inode.i_flags;
5789 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5790 +
5791 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5792 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5793 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5794 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5795 +
5796 +       if (flags & S_IMMUTABLE)
5797 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5798 +       if (flags & S_IXUNLINK)
5799 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5800  
5801 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5802 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5803         if (flags & S_SYNC)
5804                 oi->ip_attr |= OCFS2_SYNC_FL;
5805         if (flags & S_APPEND)
5806                 oi->ip_attr |= OCFS2_APPEND_FL;
5807 -       if (flags & S_IMMUTABLE)
5808 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5809         if (flags & S_NOATIME)
5810                 oi->ip_attr |= OCFS2_NOATIME_FL;
5811         if (flags & S_DIRSYNC)
5812                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5813 +
5814 +       if (vflags & V_BARRIER)
5815 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5816 +       if (vflags & V_COW)
5817 +               oi->ip_attr |= OCFS2_COW_FL;
5818  }
5819  
5820  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5821 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5822         struct super_block *sb;
5823         struct ocfs2_super *osb;
5824         int use_plocks = 1;
5825 +       uid_t uid;
5826 +       gid_t gid;
5827  
5828         sb = inode->i_sb;
5829         osb = OCFS2_SB(sb);
5830 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5831         inode->i_generation = le32_to_cpu(fe->i_generation);
5832         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5833         inode->i_mode = le16_to_cpu(fe->i_mode);
5834 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5835 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5836 +       uid = le32_to_cpu(fe->i_uid);
5837 +       gid = le32_to_cpu(fe->i_gid);
5838 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5839 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5840 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5841 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5842  
5843         /* Fast symlinks will have i_size but no allocated clusters. */
5844         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5845 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/inode.h linux-3.4.83-vs2.3.3.9/fs/ocfs2/inode.h
5846 --- linux-3.4.83/fs/ocfs2/inode.h       2012-01-09 15:14:55.000000000 +0000
5847 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/inode.h     2012-05-21 16:15:05.000000000 +0000
5848 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5849  
5850  void ocfs2_set_inode_flags(struct inode *inode);
5851  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5852 +int ocfs2_sync_flags(struct inode *inode, int, int);
5853  
5854  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5855  {
5856 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/ioctl.c linux-3.4.83-vs2.3.3.9/fs/ocfs2/ioctl.c
5857 --- linux-3.4.83/fs/ocfs2/ioctl.c       2012-05-21 16:07:26.000000000 +0000
5858 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/ioctl.c     2012-05-21 16:15:05.000000000 +0000
5859 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5860         return status;
5861  }
5862  
5863 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5864 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5865 +{
5866 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5867 +       struct buffer_head *bh = NULL;
5868 +       handle_t *handle = NULL;
5869 +       int status;
5870 +
5871 +       status = ocfs2_inode_lock(inode, &bh, 1);
5872 +       if (status < 0) {
5873 +               mlog_errno(status);
5874 +               return status;
5875 +       }
5876 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5877 +       if (IS_ERR(handle)) {
5878 +               status = PTR_ERR(handle);
5879 +               mlog_errno(status);
5880 +               goto bail_unlock;
5881 +       }
5882 +
5883 +       inode->i_flags = flags;
5884 +       inode->i_vflags = vflags;
5885 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5886 +
5887 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5888 +       if (status < 0)
5889 +               mlog_errno(status);
5890 +
5891 +       ocfs2_commit_trans(osb, handle);
5892 +bail_unlock:
5893 +       ocfs2_inode_unlock(inode, 1);
5894 +       brelse(bh);
5895 +       return status;
5896 +}
5897 +
5898 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5899                                 unsigned mask)
5900  {
5901         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5902 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5903         if (!S_ISDIR(inode->i_mode))
5904                 flags &= ~OCFS2_DIRSYNC_FL;
5905  
5906 +       if (IS_BARRIER(inode)) {
5907 +               vxwprintk_task(1, "messing with the barrier.");
5908 +               goto bail_unlock;
5909 +       }
5910 +
5911         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5912         if (IS_ERR(handle)) {
5913                 status = PTR_ERR(handle);
5914 @@ -879,6 +918,7 @@ bail:
5915         return status;
5916  }
5917  
5918 +
5919  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5920  {
5921         struct inode *inode = filp->f_path.dentry->d_inode;
5922 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/namei.c linux-3.4.83-vs2.3.3.9/fs/ocfs2/namei.c
5923 --- linux-3.4.83/fs/ocfs2/namei.c       2012-03-19 18:47:26.000000000 +0000
5924 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/namei.c     2012-05-21 16:15:05.000000000 +0000
5925 @@ -41,6 +41,7 @@
5926  #include <linux/slab.h>
5927  #include <linux/highmem.h>
5928  #include <linux/quotaops.h>
5929 +#include <linux/vs_tag.h>
5930  
5931  #include <cluster/masklog.h>
5932  
5933 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5934         struct ocfs2_dinode *fe = NULL;
5935         struct ocfs2_extent_list *fel;
5936         u16 feat;
5937 +       tag_t tag;
5938  
5939         *new_fe_bh = NULL;
5940  
5941 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5942         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5943         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5944         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5945 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5946 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5947 +
5948 +       tag = dx_current_fstag(osb->sb);
5949 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5950 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5951 +       inode->i_tag = tag;
5952         fe->i_mode = cpu_to_le16(inode->i_mode);
5953         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5954                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5955 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/ocfs2.h linux-3.4.83-vs2.3.3.9/fs/ocfs2/ocfs2.h
5956 --- linux-3.4.83/fs/ocfs2/ocfs2.h       2012-01-09 15:14:55.000000000 +0000
5957 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/ocfs2.h     2012-05-21 16:15:05.000000000 +0000
5958 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5959                                                      writes */
5960         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5961         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5962 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5963  };
5964  
5965  #define OCFS2_OSB_SOFT_RO                      0x0001
5966 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/ocfs2_fs.h linux-3.4.83-vs2.3.3.9/fs/ocfs2/ocfs2_fs.h
5967 --- linux-3.4.83/fs/ocfs2/ocfs2_fs.h    2011-05-22 14:17:53.000000000 +0000
5968 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/ocfs2_fs.h  2012-05-21 16:15:05.000000000 +0000
5969 @@ -266,6 +266,11 @@
5970  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5971  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5972  
5973 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5974 +
5975 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5976 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5977 +
5978  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5979  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5980  
5981 diff -NurpP --minimal linux-3.4.83/fs/ocfs2/super.c linux-3.4.83-vs2.3.3.9/fs/ocfs2/super.c
5982 --- linux-3.4.83/fs/ocfs2/super.c       2012-05-21 16:07:26.000000000 +0000
5983 +++ linux-3.4.83-vs2.3.3.9/fs/ocfs2/super.c     2012-05-21 16:15:05.000000000 +0000
5984 @@ -185,6 +185,7 @@ enum {
5985         Opt_coherency_full,
5986         Opt_resv_level,
5987         Opt_dir_resv_level,
5988 +       Opt_tag, Opt_notag, Opt_tagid,
5989         Opt_err,
5990  };
5991  
5992 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5993         {Opt_coherency_full, "coherency=full"},
5994         {Opt_resv_level, "resv_level=%u"},
5995         {Opt_dir_resv_level, "dir_resv_level=%u"},
5996 +       {Opt_tag, "tag"},
5997 +       {Opt_notag, "notag"},
5998 +       {Opt_tagid, "tagid=%u"},
5999         {Opt_err, NULL}
6000  };
6001  
6002 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6003                 goto out;
6004         }
6005  
6006 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6007 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6008 +               ret = -EINVAL;
6009 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6010 +               goto out;
6011 +       }
6012 +
6013         /* We're going to/from readonly mode. */
6014         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6015                 /* Disable quota accounting before remounting RO */
6016 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6017  
6018         ocfs2_complete_mount_recovery(osb);
6019  
6020 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6021 +               sb->s_flags |= MS_TAGGED;
6022 +
6023         if (ocfs2_mount_local(osb))
6024                 snprintf(nodestr, sizeof(nodestr), "local");
6025         else
6026 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
6027                             option < OCFS2_MAX_RESV_LEVEL)
6028                                 mopt->dir_resv_level = option;
6029                         break;
6030 +#ifndef CONFIG_TAGGING_NONE
6031 +               case Opt_tag:
6032 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6033 +                       break;
6034 +               case Opt_notag:
6035 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6036 +                       break;
6037 +#endif
6038 +#ifdef CONFIG_PROPAGATE
6039 +               case Opt_tagid:
6040 +                       /* use args[0] */
6041 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6042 +                       break;
6043 +#endif
6044                 default:
6045                         mlog(ML_ERROR,
6046                              "Unrecognized mount option \"%s\" "
6047 diff -NurpP --minimal linux-3.4.83/fs/open.c linux-3.4.83-vs2.3.3.9/fs/open.c
6048 --- linux-3.4.83/fs/open.c      2014-03-12 09:48:15.000000000 +0000
6049 +++ linux-3.4.83-vs2.3.3.9/fs/open.c    2012-09-16 18:49:11.000000000 +0000
6050 @@ -30,6 +30,11 @@
6051  #include <linux/fs_struct.h>
6052  #include <linux/ima.h>
6053  #include <linux/dnotify.h>
6054 +#include <linux/vs_base.h>
6055 +#include <linux/vs_limit.h>
6056 +#include <linux/vs_tag.h>
6057 +#include <linux/vs_cowbl.h>
6058 +#include <linux/vserver/dlimit.h>
6059  
6060  #include "internal.h"
6061  
6062 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6063         error = user_path(pathname, &path);
6064         if (error)
6065                 goto out;
6066 +
6067 +#ifdef CONFIG_VSERVER_COWBL
6068 +       error = cow_check_and_break(&path);
6069 +       if (error)
6070 +               goto dput_and_out;
6071 +#endif
6072         inode = path.dentry->d_inode;
6073  
6074         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6075 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6076  
6077         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6078         if (!error) {
6079 +#ifdef CONFIG_VSERVER_COWBL
6080 +               error = cow_check_and_break(&path);
6081 +               if (!error)
6082 +#endif
6083                 error = chmod_common(&path, mode);
6084                 path_put(&path);
6085         }
6086 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6087         newattrs.ia_valid =  ATTR_CTIME;
6088         if (user != (uid_t) -1) {
6089                 newattrs.ia_valid |= ATTR_UID;
6090 -               newattrs.ia_uid = user;
6091 +               newattrs.ia_uid = dx_map_uid(user);
6092         }
6093         if (group != (gid_t) -1) {
6094                 newattrs.ia_valid |= ATTR_GID;
6095 -               newattrs.ia_gid = group;
6096 +               newattrs.ia_gid = dx_map_gid(group);
6097         }
6098         if (!S_ISDIR(inode->i_mode))
6099                 newattrs.ia_valid |=
6100 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6101         error = mnt_want_write(path.mnt);
6102         if (error)
6103                 goto out_release;
6104 +#ifdef CONFIG_VSERVER_COWBL
6105 +       error = cow_check_and_break(&path);
6106 +       if (!error)
6107 +#endif
6108         error = chown_common(&path, user, group);
6109         mnt_drop_write(path.mnt);
6110  out_release:
6111 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6112         error = mnt_want_write(path.mnt);
6113         if (error)
6114                 goto out_release;
6115 +#ifdef CONFIG_VSERVER_COWBL
6116 +       error = cow_check_and_break(&path);
6117 +       if (!error)
6118 +#endif
6119         error = chown_common(&path, user, group);
6120         mnt_drop_write(path.mnt);
6121  out_release:
6122 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6123         error = mnt_want_write(path.mnt);
6124         if (error)
6125                 goto out_release;
6126 +#ifdef CONFIG_VSERVER_COWBL
6127 +       error = cow_check_and_break(&path);
6128 +       if (!error)
6129 +#endif
6130         error = chown_common(&path, user, group);
6131         mnt_drop_write(path.mnt);
6132  out_release:
6133 @@ -839,6 +866,7 @@ static void __put_unused_fd(struct files
6134         __clear_open_fd(fd, fdt);
6135         if (fd < files->next_fd)
6136                 files->next_fd = fd;
6137 +       vx_openfd_dec(fd);
6138  }
6139  
6140  void put_unused_fd(unsigned int fd)
6141 diff -NurpP --minimal linux-3.4.83/fs/proc/array.c linux-3.4.83-vs2.3.3.9/fs/proc/array.c
6142 --- linux-3.4.83/fs/proc/array.c        2012-05-21 16:07:26.000000000 +0000
6143 +++ linux-3.4.83-vs2.3.3.9/fs/proc/array.c      2012-05-21 16:15:05.000000000 +0000
6144 @@ -81,6 +81,8 @@
6145  #include <linux/pid_namespace.h>
6146  #include <linux/ptrace.h>
6147  #include <linux/tracehook.h>
6148 +#include <linux/vs_context.h>
6149 +#include <linux/vs_network.h>
6150  
6151  #include <asm/pgtable.h>
6152  #include <asm/processor.h>
6153 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6154         rcu_read_lock();
6155         ppid = pid_alive(p) ?
6156                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6157 +       if (unlikely(vx_current_initpid(p->pid)))
6158 +               ppid = 0;
6159 +
6160         tpid = 0;
6161         if (pid_alive(p)) {
6162                 struct task_struct *tracer = ptrace_parent(p);
6163 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6164  }
6165  
6166  static void render_cap_t(struct seq_file *m, const char *header,
6167 -                       kernel_cap_t *a)
6168 +                       struct vx_info *vxi, kernel_cap_t *a)
6169  {
6170         unsigned __capi;
6171  
6172 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6173         cap_bset        = cred->cap_bset;
6174         rcu_read_unlock();
6175  
6176 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6177 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6178 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6179 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6180 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6181 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6182 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6183 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6184 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6185  }
6186  
6187  static inline void task_context_switch_counts(struct seq_file *m,
6188 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6189         seq_putc(m, '\n');
6190  }
6191  
6192 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6193 +                       struct pid *pid, struct task_struct *task)
6194 +{
6195 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6196 +                       "Count:\t%u\n"
6197 +                       "uts:\t%p(%c)\n"
6198 +                       "ipc:\t%p(%c)\n"
6199 +                       "mnt:\t%p(%c)\n"
6200 +                       "pid:\t%p(%c)\n"
6201 +                       "net:\t%p(%c)\n",
6202 +                       task->nsproxy,
6203 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6204 +                       atomic_read(&task->nsproxy->count),
6205 +                       task->nsproxy->uts_ns,
6206 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6207 +                       task->nsproxy->ipc_ns,
6208 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6209 +                       task->nsproxy->mnt_ns,
6210 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6211 +                       task->nsproxy->pid_ns,
6212 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6213 +                       task->nsproxy->net_ns,
6214 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6215 +       return 0;
6216 +}
6217 +
6218 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6219 +{
6220 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6221 +               return;
6222 +
6223 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6224 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6225 +}
6226 +
6227 +
6228  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6229                         struct pid *pid, struct task_struct *task)
6230  {
6231 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m,
6232         task_cap(m, task);
6233         task_cpus_allowed(m, task);
6234         cpuset_task_status_allowed(m, task);
6235 +       task_vs_id(m, task);
6236         task_context_switch_counts(m, task);
6237         return 0;
6238  }
6239 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file
6240         /* convert nsec -> ticks */
6241         start_time = nsec_to_clock_t(start_time);
6242  
6243 +       /* fixup start time for virt uptime */
6244 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6245 +               unsigned long long bias =
6246 +                       current->vx_info->cvirt.bias_clock;
6247 +
6248 +               if (start_time > bias)
6249 +                       start_time -= bias;
6250 +               else
6251 +                       start_time = 0;
6252 +       }
6253 +
6254         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6255         seq_put_decimal_ll(m, ' ', ppid);
6256         seq_put_decimal_ll(m, ' ', pgid);
6257 diff -NurpP --minimal linux-3.4.83/fs/proc/base.c linux-3.4.83-vs2.3.3.9/fs/proc/base.c
6258 --- linux-3.4.83/fs/proc/base.c 2014-03-12 09:48:15.000000000 +0000
6259 +++ linux-3.4.83-vs2.3.3.9/fs/proc/base.c       2012-06-28 14:45:07.000000000 +0000
6260 @@ -84,6 +84,8 @@
6261  #include <linux/fs_struct.h>
6262  #include <linux/slab.h>
6263  #include <linux/flex_array.h>
6264 +#include <linux/vs_context.h>
6265 +#include <linux/vs_network.h>
6266  #ifdef CONFIG_HARDWALL
6267  #include <asm/hardwall.h>
6268  #endif
6269 @@ -937,11 +939,16 @@ static ssize_t oom_adjust_write(struct f
6270                 goto err_task_lock;
6271         }
6272  
6273 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6274 +       if (oom_adjust < task->signal->oom_adj &&
6275 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6276                 err = -EACCES;
6277                 goto err_sighand;
6278         }
6279  
6280 +       /* prevent guest processes from circumventing the oom killer */
6281 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6282 +               oom_adjust = OOM_ADJUST_MIN;
6283 +
6284         /*
6285          * Warn that /proc/pid/oom_adj is deprecated, see
6286          * Documentation/feature-removal-schedule.txt.
6287 @@ -1541,6 +1548,8 @@ struct inode *proc_pid_make_inode(struct
6288                 inode->i_gid = cred->egid;
6289                 rcu_read_unlock();
6290         }
6291 +       /* procfs is xid tagged */
6292 +       inode->i_tag = (tag_t)vx_task_xid(task);
6293         security_task_to_inode(task, inode);
6294  
6295  out:
6296 @@ -1586,6 +1595,8 @@ int pid_getattr(struct vfsmount *mnt, st
6297  
6298  /* dentry stuff */
6299  
6300 +static unsigned name_to_int(struct dentry *dentry);
6301 +
6302  /*
6303   *     Exceptional case: normally we are not allowed to unhash a busy
6304   * directory. In this case, however, we can do it - no aliasing problems
6305 @@ -1614,6 +1625,12 @@ int pid_revalidate(struct dentry *dentry
6306         task = get_proc_task(inode);
6307  
6308         if (task) {
6309 +               unsigned pid = name_to_int(dentry);
6310 +
6311 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6312 +                       put_task_struct(task);
6313 +                       goto drop;
6314 +               }
6315                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6316                     task_dumpable(task)) {
6317                         rcu_read_lock();
6318 @@ -1630,6 +1647,7 @@ int pid_revalidate(struct dentry *dentry
6319                 put_task_struct(task);
6320                 return 1;
6321         }
6322 +drop:
6323         d_drop(dentry);
6324         return 0;
6325  }
6326 @@ -2452,6 +2470,13 @@ static struct dentry *proc_pident_lookup
6327         if (!task)
6328                 goto out_no_task;
6329  
6330 +       /* TODO: maybe we can come up with a generic approach? */
6331 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6332 +               (dentry->d_name.len == 5) &&
6333 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6334 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6335 +               goto out;
6336 +
6337         /*
6338          * Yes, it does not scale. And it should not. Don't add
6339          * new entries into /proc/<tgid>/ without very good reasons.
6340 @@ -2837,7 +2862,7 @@ out_iput:
6341  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6342  {
6343         struct dentry *error;
6344 -       struct task_struct *task = get_proc_task(dir);
6345 +       struct task_struct *task = get_proc_task_real(dir);
6346         const struct pid_entry *p, *last;
6347  
6348         error = ERR_PTR(-ENOENT);
6349 @@ -2944,6 +2969,9 @@ static int proc_pid_personality(struct s
6350  static const struct file_operations proc_task_operations;
6351  static const struct inode_operations proc_task_inode_operations;
6352  
6353 +extern int proc_pid_vx_info(struct task_struct *, char *);
6354 +extern int proc_pid_nx_info(struct task_struct *, char *);
6355 +
6356  static const struct pid_entry tgid_base_stuff[] = {
6357         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6358         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6359 @@ -3010,6 +3038,8 @@ static const struct pid_entry tgid_base_
6360  #ifdef CONFIG_CGROUPS
6361         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6362  #endif
6363 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6364 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6365         INF("oom_score",  S_IRUGO, proc_oom_score),
6366         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6367         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6368 @@ -3029,6 +3059,7 @@ static const struct pid_entry tgid_base_
6369  #ifdef CONFIG_HARDWALL
6370         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6371  #endif
6372 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6373  };
6374  
6375  static int proc_tgid_base_readdir(struct file * filp,
6376 @@ -3222,7 +3253,7 @@ retry:
6377         iter.task = NULL;
6378         pid = find_ge_pid(iter.tgid, ns);
6379         if (pid) {
6380 -               iter.tgid = pid_nr_ns(pid, ns);
6381 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6382                 iter.task = pid_task(pid, PIDTYPE_PID);
6383                 /* What we to know is if the pid we have find is the
6384                  * pid of a thread_group_leader.  Testing for task
6385 @@ -3252,7 +3283,7 @@ static int proc_pid_fill_cache(struct fi
6386         struct tgid_iter iter)
6387  {
6388         char name[PROC_NUMBUF];
6389 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6390 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6391         return proc_fill_cache(filp, dirent, filldir, name, len,
6392                                 proc_pid_instantiate, iter.task, NULL);
6393  }
6394 @@ -3276,7 +3307,7 @@ int proc_pid_readdir(struct file * filp,
6395                 goto out_no_task;
6396         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6397  
6398 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6399 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6400         if (!reaper)
6401                 goto out_no_task;
6402  
6403 @@ -3298,6 +3329,8 @@ int proc_pid_readdir(struct file * filp,
6404                         __filldir = fake_filldir;
6405  
6406                 filp->f_pos = iter.tgid + TGID_OFFSET;
6407 +               if (!vx_proc_task_visible(iter.task))
6408 +                       continue;
6409                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6410                         put_task_struct(iter.task);
6411                         goto out;
6412 @@ -3451,6 +3484,8 @@ static struct dentry *proc_task_lookup(s
6413         tid = name_to_int(dentry);
6414         if (tid == ~0U)
6415                 goto out;
6416 +       if (vx_current_initpid(tid))
6417 +               goto out;
6418  
6419         ns = dentry->d_sb->s_fs_info;
6420         rcu_read_lock();
6421 diff -NurpP --minimal linux-3.4.83/fs/proc/generic.c linux-3.4.83-vs2.3.3.9/fs/proc/generic.c
6422 --- linux-3.4.83/fs/proc/generic.c      2012-03-19 18:47:26.000000000 +0000
6423 +++ linux-3.4.83-vs2.3.3.9/fs/proc/generic.c    2012-05-21 16:15:05.000000000 +0000
6424 @@ -22,6 +22,7 @@
6425  #include <linux/bitops.h>
6426  #include <linux/spinlock.h>
6427  #include <linux/completion.h>
6428 +#include <linux/vserver/inode.h>
6429  #include <asm/uaccess.h>
6430  
6431  #include "internal.h"
6432 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6433         for (de = de->subdir; de ; de = de->next) {
6434                 if (de->namelen != dentry->d_name.len)
6435                         continue;
6436 +               if (!vx_hide_check(0, de->vx_flags))
6437 +                       continue;
6438                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6439                         pde_get(de);
6440                         spin_unlock(&proc_subdir_lock);
6441                         error = -EINVAL;
6442                         inode = proc_get_inode(dir->i_sb, de);
6443 +                       /* generic proc entries belong to the host */
6444 +                       inode->i_tag = 0;
6445                         goto out_unlock;
6446                 }
6447         }
6448 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6449  
6450                                 /* filldir passes info to user space */
6451                                 pde_get(de);
6452 +                               if (!vx_hide_check(0, de->vx_flags))
6453 +                                       goto skip;
6454                                 spin_unlock(&proc_subdir_lock);
6455                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6456                                             de->low_ino, de->mode >> 12) < 0) {
6457 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6458                                         goto out;
6459                                 }
6460                                 spin_lock(&proc_subdir_lock);
6461 +                       skip:
6462                                 filp->f_pos++;
6463                                 next = de->next;
6464                                 pde_put(de);
6465 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6466         ent->nlink = nlink;
6467         atomic_set(&ent->count, 1);
6468         ent->pde_users = 0;
6469 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6470         spin_lock_init(&ent->pde_unload_lock);
6471         ent->pde_unload_completion = NULL;
6472         INIT_LIST_HEAD(&ent->pde_openers);
6473 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6474                                 kfree(ent->data);
6475                                 kfree(ent);
6476                                 ent = NULL;
6477 -                       }
6478 +                       } else
6479 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6480                 } else {
6481                         kfree(ent);
6482                         ent = NULL;
6483 diff -NurpP --minimal linux-3.4.83/fs/proc/inode.c linux-3.4.83-vs2.3.3.9/fs/proc/inode.c
6484 --- linux-3.4.83/fs/proc/inode.c        2014-03-12 09:48:15.000000000 +0000
6485 +++ linux-3.4.83-vs2.3.3.9/fs/proc/inode.c      2014-03-12 09:55:28.000000000 +0000
6486 @@ -456,6 +456,8 @@ struct inode *proc_get_inode(struct supe
6487                         inode->i_uid = de->uid;
6488                         inode->i_gid = de->gid;
6489                 }
6490 +               if (de->vx_flags)
6491 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6492                 if (de->size)
6493                         inode->i_size = de->size;
6494                 if (de->nlink)
6495 diff -NurpP --minimal linux-3.4.83/fs/proc/internal.h linux-3.4.83-vs2.3.3.9/fs/proc/internal.h
6496 --- linux-3.4.83/fs/proc/internal.h     2012-05-21 16:07:26.000000000 +0000
6497 +++ linux-3.4.83-vs2.3.3.9/fs/proc/internal.h   2012-05-21 16:15:05.000000000 +0000
6498 @@ -10,6 +10,8 @@
6499   */
6500  
6501  #include <linux/proc_fs.h>
6502 +#include <linux/vs_pid.h>
6503 +
6504  struct  ctl_table_header;
6505  
6506  extern struct proc_dir_entry proc_root;
6507 @@ -54,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
6508                                 struct pid *pid, struct task_struct *task);
6509  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6510                                 struct pid *pid, struct task_struct *task);
6511 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6512 +                               struct pid *pid, struct task_struct *task);
6513 +
6514  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6515  
6516  extern const struct file_operations proc_pid_maps_operations;
6517 @@ -82,11 +87,16 @@ static inline struct pid *proc_pid(struc
6518         return PROC_I(inode)->pid;
6519  }
6520  
6521 -static inline struct task_struct *get_proc_task(struct inode *inode)
6522 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6523  {
6524         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6525  }
6526  
6527 +static inline struct task_struct *get_proc_task(struct inode *inode)
6528 +{
6529 +       return vx_get_proc_task(inode, proc_pid(inode));
6530 +}
6531 +
6532  static inline int proc_fd(struct inode *inode)
6533  {
6534         return PROC_I(inode)->fd;
6535 diff -NurpP --minimal linux-3.4.83/fs/proc/loadavg.c linux-3.4.83-vs2.3.3.9/fs/proc/loadavg.c
6536 --- linux-3.4.83/fs/proc/loadavg.c      2009-09-10 13:26:23.000000000 +0000
6537 +++ linux-3.4.83-vs2.3.3.9/fs/proc/loadavg.c    2012-05-21 16:15:05.000000000 +0000
6538 @@ -12,15 +12,27 @@
6539  
6540  static int loadavg_proc_show(struct seq_file *m, void *v)
6541  {
6542 +       unsigned long running;
6543 +       unsigned int threads;
6544         unsigned long avnrun[3];
6545  
6546         get_avenrun(avnrun, FIXED_1/200, 0);
6547  
6548 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6549 +               struct vx_info *vxi = current_vx_info();
6550 +
6551 +               running = atomic_read(&vxi->cvirt.nr_running);
6552 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6553 +       } else {
6554 +               running = nr_running();
6555 +               threads = nr_threads;
6556 +       }
6557 +
6558         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6559                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6560                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6561                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6562 -               nr_running(), nr_threads,
6563 +               running, threads,
6564                 task_active_pid_ns(current)->last_pid);
6565         return 0;
6566  }
6567 diff -NurpP --minimal linux-3.4.83/fs/proc/meminfo.c linux-3.4.83-vs2.3.3.9/fs/proc/meminfo.c
6568 --- linux-3.4.83/fs/proc/meminfo.c      2012-01-09 15:14:55.000000000 +0000
6569 +++ linux-3.4.83-vs2.3.3.9/fs/proc/meminfo.c    2012-05-21 16:15:05.000000000 +0000
6570 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6571         allowed = ((totalram_pages - hugetlb_total_pages())
6572                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6573  
6574 -       cached = global_page_state(NR_FILE_PAGES) -
6575 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6576 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6577                         total_swapcache_pages - i.bufferram;
6578         if (cached < 0)
6579                 cached = 0;
6580 diff -NurpP --minimal linux-3.4.83/fs/proc/root.c linux-3.4.83-vs2.3.3.9/fs/proc/root.c
6581 --- linux-3.4.83/fs/proc/root.c 2012-05-21 16:07:26.000000000 +0000
6582 +++ linux-3.4.83-vs2.3.3.9/fs/proc/root.c       2012-05-21 16:15:05.000000000 +0000
6583 @@ -19,9 +19,14 @@
6584  #include <linux/mount.h>
6585  #include <linux/pid_namespace.h>
6586  #include <linux/parser.h>
6587 +#include <linux/vserver/inode.h>
6588  
6589  #include "internal.h"
6590  
6591 +struct proc_dir_entry *proc_virtual;
6592 +
6593 +extern void proc_vx_init(void);
6594 +
6595  static int proc_test_super(struct super_block *sb, void *data)
6596  {
6597         return sb->s_fs_info == data;
6598 @@ -190,6 +195,7 @@ void __init proc_root_init(void)
6599  #endif
6600         proc_mkdir("bus", NULL);
6601         proc_sys_init();
6602 +       proc_vx_init();
6603  }
6604  
6605  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6606 @@ -257,6 +263,7 @@ struct proc_dir_entry proc_root = {
6607         .proc_iops      = &proc_root_inode_operations, 
6608         .proc_fops      = &proc_root_operations,
6609         .parent         = &proc_root,
6610 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6611         .name           = "/proc",
6612  };
6613  
6614 diff -NurpP --minimal linux-3.4.83/fs/proc/stat.c linux-3.4.83-vs2.3.3.9/fs/proc/stat.c
6615 --- linux-3.4.83/fs/proc/stat.c 2014-03-12 09:48:16.000000000 +0000
6616 +++ linux-3.4.83-vs2.3.3.9/fs/proc/stat.c       2012-11-06 17:02:35.000000000 +0000
6617 @@ -9,6 +9,7 @@
6618  #include <linux/slab.h>
6619  #include <linux/time.h>
6620  #include <linux/irqnr.h>
6621 +#include <linux/vserver/cvirt.h>
6622  #include <asm/cputime.h>
6623  #include <linux/tick.h>
6624  
6625 @@ -92,6 +93,10 @@ static int show_stat(struct seq_file *p,
6626                 irq = softirq = steal = 0;
6627         guest = guest_nice = 0;
6628         getboottime(&boottime);
6629 +
6630 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6631 +               vx_vsi_boottime(&boottime);
6632 +
6633         jif = boottime.tv_sec;
6634  
6635         for_each_possible_cpu(i) {
6636 diff -NurpP --minimal linux-3.4.83/fs/proc/uptime.c linux-3.4.83-vs2.3.3.9/fs/proc/uptime.c
6637 --- linux-3.4.83/fs/proc/uptime.c       2012-03-19 18:47:26.000000000 +0000
6638 +++ linux-3.4.83-vs2.3.3.9/fs/proc/uptime.c     2012-05-21 16:15:05.000000000 +0000
6639 @@ -5,6 +5,7 @@
6640  #include <linux/seq_file.h>
6641  #include <linux/time.h>
6642  #include <linux/kernel_stat.h>
6643 +#include <linux/vserver/cvirt.h>
6644  #include <asm/cputime.h>
6645  
6646  static int uptime_proc_show(struct seq_file *m, void *v)
6647 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6648         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6649         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6650         idle.tv_nsec = rem;
6651 +
6652 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6653 +               vx_vsi_uptime(&uptime, &idle);
6654 +
6655         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6656                         (unsigned long) uptime.tv_sec,
6657                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6658 diff -NurpP --minimal linux-3.4.83/fs/proc_namespace.c linux-3.4.83-vs2.3.3.9/fs/proc_namespace.c
6659 --- linux-3.4.83/fs/proc_namespace.c    2012-03-19 18:47:26.000000000 +0000
6660 +++ linux-3.4.83-vs2.3.3.9/fs/proc_namespace.c  2012-05-21 16:15:05.000000000 +0000
6661 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6662                 { MS_SYNCHRONOUS, ",sync" },
6663                 { MS_DIRSYNC, ",dirsync" },
6664                 { MS_MANDLOCK, ",mand" },
6665 +               { MS_TAGGED, ",tag" },
6666 +               { MS_NOTAGCHECK, ",notagcheck" },
6667                 { 0, NULL }
6668         };
6669         const struct proc_fs_info *fs_infop;
6670 @@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6671         seq_escape(m, s, " \t\n\\");
6672  }
6673  
6674 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6675 +{
6676 +       struct path root;
6677 +       struct dentry *point;
6678 +       struct mount *mnt = real_mount(vfsmnt);
6679 +       struct mount *root_mnt;
6680 +       int ret;
6681 +
6682 +       if (mnt == mnt->mnt_ns->root)
6683 +               return 1;
6684 +
6685 +       br_read_lock(vfsmount_lock);
6686 +       root = current->fs->root;
6687 +       root_mnt = real_mount(root.mnt);
6688 +       point = root.dentry;
6689 +
6690 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6691 +               point = mnt->mnt_mountpoint;
6692 +               mnt = mnt->mnt_parent;
6693 +       }
6694 +
6695 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6696 +
6697 +       br_read_unlock(vfsmount_lock);
6698 +
6699 +       return ret;
6700 +}
6701 +
6702  static void show_type(struct seq_file *m, struct super_block *sb)
6703  {
6704         mangle(m, sb->s_type->name);
6705 @@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6706         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6707         struct super_block *sb = mnt_path.dentry->d_sb;
6708  
6709 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6710 +               return SEQ_SKIP;
6711 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6712 +               return SEQ_SKIP;
6713 +
6714 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6715 +               mnt == current->fs->root.mnt) {
6716 +               seq_puts(m, "/dev/root / ");
6717 +               goto type;
6718 +       }
6719 +
6720         if (sb->s_op->show_devname) {
6721                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6722                 if (err)
6723 @@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6724         seq_putc(m, ' ');
6725         seq_path(m, &mnt_path, " \t\n\\");
6726         seq_putc(m, ' ');
6727 +type:
6728         show_type(m, sb);
6729         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6730         err = show_sb_opts(m, sb);
6731 @@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6732         struct path root = p->root;
6733         int err = 0;
6734  
6735 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6736 +               return SEQ_SKIP;
6737 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6738 +               return SEQ_SKIP;
6739 +
6740         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6741                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6742         if (sb->s_op->show_path)
6743 @@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file
6744         struct super_block *sb = mnt_path.dentry->d_sb;
6745         int err = 0;
6746  
6747 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6748 +               return SEQ_SKIP;
6749 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6750 +               return SEQ_SKIP;
6751 +
6752 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6753 +               mnt == current->fs->root.mnt) {
6754 +               seq_puts(m, "device /dev/root mounted on / ");
6755 +               goto type;
6756 +       }
6757 +
6758         /* device */
6759         if (sb->s_op->show_devname) {
6760                 seq_puts(m, "device ");
6761 @@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file
6762         seq_puts(m, " mounted on ");
6763         seq_path(m, &mnt_path, " \t\n\\");
6764         seq_putc(m, ' ');
6765 -
6766 +type:
6767         /* file system type */
6768         seq_puts(m, "with fstype ");
6769         show_type(m, sb);
6770 diff -NurpP --minimal linux-3.4.83/fs/quota/dquot.c linux-3.4.83-vs2.3.3.9/fs/quota/dquot.c
6771 --- linux-3.4.83/fs/quota/dquot.c       2014-03-12 09:48:16.000000000 +0000
6772 +++ linux-3.4.83-vs2.3.3.9/fs/quota/dquot.c     2014-03-12 09:55:28.000000000 +0000
6773 @@ -1571,6 +1571,9 @@ int __dquot_alloc_space(struct inode *in
6774         struct dquot **dquots = inode->i_dquot;
6775         int reserve = flags & DQUOT_SPACE_RESERVE;
6776  
6777 +       if ((ret = dl_alloc_space(inode, number)))
6778 +               return ret;
6779 +
6780         /*
6781          * First test before acquiring mutex - solves deadlocks when we
6782          * re-enter the quota code and are already holding the mutex
6783 @@ -1626,6 +1629,9 @@ int dquot_alloc_inode(const struct inode
6784         struct dquot_warn warn[MAXQUOTAS];
6785         struct dquot * const *dquots = inode->i_dquot;
6786  
6787 +       if ((ret = dl_alloc_inode(inode)))
6788 +               return ret;
6789 +
6790         /* First test before acquiring mutex - solves deadlocks when we
6791           * re-enter the quota code and are already holding the mutex */
6792         if (!dquot_active(inode))
6793 @@ -1697,6 +1703,8 @@ void __dquot_free_space(struct inode *in
6794         struct dquot **dquots = inode->i_dquot;
6795         int reserve = flags & DQUOT_SPACE_RESERVE;
6796  
6797 +       dl_free_space(inode, number);
6798 +
6799         /* First test before acquiring mutex - solves deadlocks when we
6800           * re-enter the quota code and are already holding the mutex */
6801         if (!dquot_active(inode)) {
6802 @@ -1741,6 +1749,8 @@ void dquot_free_inode(const struct inode
6803         struct dquot_warn warn[MAXQUOTAS];
6804         struct dquot * const *dquots = inode->i_dquot;
6805  
6806 +       dl_free_inode(inode);
6807 +
6808         /* First test before acquiring mutex - solves deadlocks when we
6809           * re-enter the quota code and are already holding the mutex */
6810         if (!dquot_active(inode))
6811 diff -NurpP --minimal linux-3.4.83/fs/quota/quota.c linux-3.4.83-vs2.3.3.9/fs/quota/quota.c
6812 --- linux-3.4.83/fs/quota/quota.c       2012-05-21 16:07:26.000000000 +0000
6813 +++ linux-3.4.83-vs2.3.3.9/fs/quota/quota.c     2012-05-21 16:15:05.000000000 +0000
6814 @@ -8,6 +8,7 @@
6815  #include <linux/fs.h>
6816  #include <linux/namei.h>
6817  #include <linux/slab.h>
6818 +#include <linux/vs_context.h>
6819  #include <asm/current.h>
6820  #include <asm/uaccess.h>
6821  #include <linux/kernel.h>
6822 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6823                         break;
6824                 /*FALLTHROUGH*/
6825         default:
6826 -               if (!capable(CAP_SYS_ADMIN))
6827 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6828                         return -EPERM;
6829         }
6830  
6831 @@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6832         }
6833  }
6834  
6835 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6836 +
6837 +#include <linux/vroot.h>
6838 +#include <linux/major.h>
6839 +#include <linux/module.h>
6840 +#include <linux/kallsyms.h>
6841 +#include <linux/vserver/debug.h>
6842 +
6843 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6844 +
6845 +static DEFINE_SPINLOCK(vroot_grb_lock);
6846 +
6847 +int register_vroot_grb(vroot_grb_func *func) {
6848 +       int ret = -EBUSY;
6849 +
6850 +       spin_lock(&vroot_grb_lock);
6851 +       if (!vroot_get_real_bdev) {
6852 +               vroot_get_real_bdev = func;
6853 +               ret = 0;
6854 +       }
6855 +       spin_unlock(&vroot_grb_lock);
6856 +       return ret;
6857 +}
6858 +EXPORT_SYMBOL(register_vroot_grb);
6859 +
6860 +int unregister_vroot_grb(vroot_grb_func *func) {
6861 +       int ret = -EINVAL;
6862 +
6863 +       spin_lock(&vroot_grb_lock);
6864 +       if (vroot_get_real_bdev) {
6865 +               vroot_get_real_bdev = NULL;
6866 +               ret = 0;
6867 +       }
6868 +       spin_unlock(&vroot_grb_lock);
6869 +       return ret;
6870 +}
6871 +EXPORT_SYMBOL(unregister_vroot_grb);
6872 +
6873 +#endif
6874 +
6875  /* Return 1 if 'cmd' will block on frozen filesystem */
6876  static int quotactl_cmd_write(int cmd)
6877  {
6878 @@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6879         putname(tmp);
6880         if (IS_ERR(bdev))
6881                 return ERR_CAST(bdev);
6882 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6883 +       if (bdev && bdev->bd_inode &&
6884 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6885 +               struct block_device *bdnew = (void *)-EINVAL;
6886 +
6887 +               if (vroot_get_real_bdev)
6888 +                       bdnew = vroot_get_real_bdev(bdev);
6889 +               else
6890 +                       vxdprintk(VXD_CBIT(misc, 0),
6891 +                                       "vroot_get_real_bdev not set");
6892 +               bdput(bdev);
6893 +               if (IS_ERR(bdnew))
6894 +                       return ERR_PTR(PTR_ERR(bdnew));
6895 +               bdev = bdnew;
6896 +       }
6897 +#endif
6898         if (quotactl_cmd_write(cmd))
6899                 sb = get_super_thawed(bdev);
6900         else
6901 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/file.c linux-3.4.83-vs2.3.3.9/fs/reiserfs/file.c
6902 --- linux-3.4.83/fs/reiserfs/file.c     2012-05-21 16:07:26.000000000 +0000
6903 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/file.c   2012-05-21 16:15:05.000000000 +0000
6904 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6905         .listxattr = reiserfs_listxattr,
6906         .removexattr = reiserfs_removexattr,
6907         .permission = reiserfs_permission,
6908 +       .sync_flags = reiserfs_sync_flags,
6909         .get_acl = reiserfs_get_acl,
6910  };
6911 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/inode.c linux-3.4.83-vs2.3.3.9/fs/reiserfs/inode.c
6912 --- linux-3.4.83/fs/reiserfs/inode.c    2014-03-12 09:48:16.000000000 +0000
6913 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/inode.c  2012-12-08 00:53:53.000000000 +0000
6914 @@ -18,6 +18,7 @@
6915  #include <linux/writeback.h>
6916  #include <linux/quotaops.h>
6917  #include <linux/swap.h>
6918 +#include <linux/vs_tag.h>
6919  
6920  int reiserfs_commit_write(struct file *f, struct page *page,
6921                           unsigned from, unsigned to);
6922 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6923         struct buffer_head *bh;
6924         struct item_head *ih;
6925         __u32 rdev;
6926 +       uid_t uid;
6927 +       gid_t gid;
6928         //int version = ITEM_VERSION_1;
6929  
6930         bh = PATH_PLAST_BUFFER(path);
6931 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6932                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6933                 unsigned long blocks;
6934  
6935 +               uid = sd_v1_uid(sd);
6936 +               gid = sd_v1_gid(sd);
6937 +
6938                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6939                 set_inode_sd_version(inode, STAT_DATA_V1);
6940                 inode->i_mode = sd_v1_mode(sd);
6941                 set_nlink(inode, sd_v1_nlink(sd));
6942 -               inode->i_uid = sd_v1_uid(sd);
6943 -               inode->i_gid = sd_v1_gid(sd);
6944                 inode->i_size = sd_v1_size(sd);
6945                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6946                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6947 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6948                 // (directories and symlinks)
6949                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6950  
6951 +               uid    = sd_v2_uid(sd);
6952 +               gid    = sd_v2_gid(sd);
6953 +
6954                 inode->i_mode = sd_v2_mode(sd);
6955                 set_nlink(inode, sd_v2_nlink(sd));
6956 -               inode->i_uid = sd_v2_uid(sd);
6957                 inode->i_size = sd_v2_size(sd);
6958 -               inode->i_gid = sd_v2_gid(sd);
6959                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6960                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6961                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6962 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6963                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6964         }
6965  
6966 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6967 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6968 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6969 +
6970         pathrelse(path);
6971         if (S_ISREG(inode->i_mode)) {
6972                 inode->i_op = &reiserfs_file_inode_operations;
6973 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6974  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6975  {
6976         struct stat_data *sd_v2 = (struct stat_data *)sd;
6977 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6978 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6979         __u16 flags;
6980  
6981 +       set_sd_v2_uid(sd_v2, uid);
6982 +       set_sd_v2_gid(sd_v2, gid);
6983         set_sd_v2_mode(sd_v2, inode->i_mode);
6984         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6985 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6986         set_sd_v2_size(sd_v2, size);
6987 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6988         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6989         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6990         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6991 @@ -2875,14 +2886,19 @@ int reiserfs_commit_write(struct file *f
6992  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6993  {
6994         if (reiserfs_attrs(inode->i_sb)) {
6995 -               if (sd_attrs & REISERFS_SYNC_FL)
6996 -                       inode->i_flags |= S_SYNC;
6997 -               else
6998 -                       inode->i_flags &= ~S_SYNC;
6999                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7000                         inode->i_flags |= S_IMMUTABLE;
7001                 else
7002                         inode->i_flags &= ~S_IMMUTABLE;
7003 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7004 +                       inode->i_flags |= S_IXUNLINK;
7005 +               else
7006 +                       inode->i_flags &= ~S_IXUNLINK;
7007 +
7008 +               if (sd_attrs & REISERFS_SYNC_FL)
7009 +                       inode->i_flags |= S_SYNC;
7010 +               else
7011 +                       inode->i_flags &= ~S_SYNC;
7012                 if (sd_attrs & REISERFS_APPEND_FL)
7013                         inode->i_flags |= S_APPEND;
7014                 else
7015 @@ -2895,6 +2911,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7016                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7017                 else
7018                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7019 +
7020 +               if (sd_attrs & REISERFS_BARRIER_FL)
7021 +                       inode->i_vflags |= V_BARRIER;
7022 +               else
7023 +                       inode->i_vflags &= ~V_BARRIER;
7024 +               if (sd_attrs & REISERFS_COW_FL)
7025 +                       inode->i_vflags |= V_COW;
7026 +               else
7027 +                       inode->i_vflags &= ~V_COW;
7028         }
7029  }
7030  
7031 @@ -2905,6 +2930,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7032                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7033                 else
7034                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7035 +               if (inode->i_flags & S_IXUNLINK)
7036 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7037 +               else
7038 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7039 +
7040                 if (inode->i_flags & S_SYNC)
7041                         *sd_attrs |= REISERFS_SYNC_FL;
7042                 else
7043 @@ -2917,6 +2947,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7044                         *sd_attrs |= REISERFS_NOTAIL_FL;
7045                 else
7046                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7047 +
7048 +               if (inode->i_vflags & V_BARRIER)
7049 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7050 +               else
7051 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7052 +               if (inode->i_vflags & V_COW)
7053 +                       *sd_attrs |= REISERFS_COW_FL;
7054 +               else
7055 +                       *sd_attrs &= ~REISERFS_COW_FL;
7056         }
7057  }
7058  
7059 @@ -3161,7 +3200,8 @@ int reiserfs_setattr(struct dentry *dent
7060         }
7061  
7062         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7063 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7064 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7065 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7066                 struct reiserfs_transaction_handle th;
7067                 int jbegin_count =
7068                     2 *
7069 @@ -3192,6 +3232,9 @@ int reiserfs_setattr(struct dentry *dent
7070                         inode->i_uid = attr->ia_uid;
7071                 if (attr->ia_valid & ATTR_GID)
7072                         inode->i_gid = attr->ia_gid;
7073 +                               if ((attr->ia_valid & ATTR_TAG) &&
7074 +                                       IS_TAGGED(inode))
7075 +                                       inode->i_tag = attr->ia_tag;
7076                 mark_inode_dirty(inode);
7077                 error = journal_end(&th, inode->i_sb, jbegin_count);
7078                 if (error)
7079 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/ioctl.c linux-3.4.83-vs2.3.3.9/fs/reiserfs/ioctl.c
7080 --- linux-3.4.83/fs/reiserfs/ioctl.c    2012-05-21 16:07:27.000000000 +0000
7081 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/ioctl.c  2012-05-21 16:15:05.000000000 +0000
7082 @@ -11,6 +11,21 @@
7083  #include <linux/pagemap.h>
7084  #include <linux/compat.h>
7085  
7086 +
7087 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7088 +{
7089 +       __u16 sd_attrs = 0;
7090 +
7091 +       inode->i_flags = flags;
7092 +       inode->i_vflags = vflags;
7093 +
7094 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7095 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7096 +       inode->i_ctime = CURRENT_TIME_SEC;
7097 +       mark_inode_dirty(inode);
7098 +       return 0;
7099 +}
7100 +
7101  /*
7102   * reiserfs_ioctl - handler for ioctl for inode
7103   * supported commands:
7104 @@ -22,7 +37,7 @@
7105  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7106  {
7107         struct inode *inode = filp->f_path.dentry->d_inode;
7108 -       unsigned int flags;
7109 +       unsigned int flags, oldflags;
7110         int err = 0;
7111  
7112         reiserfs_write_lock(inode->i_sb);
7113 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7114  
7115                 flags = REISERFS_I(inode)->i_attrs;
7116                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7117 +               flags &= REISERFS_FL_USER_VISIBLE;
7118                 err = put_user(flags, (int __user *)arg);
7119                 break;
7120         case REISERFS_IOC_SETFLAGS:{
7121 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7122                                 err = -EFAULT;
7123                                 goto setflags_out;
7124                         }
7125 +                       if (IS_BARRIER(inode)) {
7126 +                               vxwprintk_task(1, "messing with the barrier.");
7127 +                               return -EACCES;
7128 +                       }
7129                         /*
7130                          * Is it quota file? Do not allow user to mess with it
7131                          */
7132 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7133                                         goto setflags_out;
7134                                 }
7135                         }
7136 +
7137 +                       oldflags = REISERFS_I(inode)->i_attrs;
7138 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7139 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7140                         sd_attrs_to_i_attrs(flags, inode);
7141                         REISERFS_I(inode)->i_attrs = flags;
7142                         inode->i_ctime = CURRENT_TIME_SEC;
7143 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/namei.c linux-3.4.83-vs2.3.3.9/fs/reiserfs/namei.c
7144 --- linux-3.4.83/fs/reiserfs/namei.c    2012-05-21 16:07:27.000000000 +0000
7145 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/namei.c  2012-05-21 16:15:05.000000000 +0000
7146 @@ -18,6 +18,7 @@
7147  #include "acl.h"
7148  #include "xattr.h"
7149  #include <linux/quotaops.h>
7150 +#include <linux/vs_tag.h>
7151  
7152  #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); }
7153  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7154 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7155         if (retval == IO_ERROR) {
7156                 return ERR_PTR(-EIO);
7157         }
7158 +               dx_propagate_tag(nd, inode);
7159  
7160         return d_splice_alias(inode, dentry);
7161  }
7162 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/reiserfs.h linux-3.4.83-vs2.3.3.9/fs/reiserfs/reiserfs.h
7163 --- linux-3.4.83/fs/reiserfs/reiserfs.h 2012-05-21 16:07:27.000000000 +0000
7164 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/reiserfs.h       2012-05-21 17:19:33.000000000 +0000
7165 @@ -544,6 +544,7 @@ enum reiserfs_mount_options {
7166         REISERFS_EXPOSE_PRIVROOT,
7167         REISERFS_BARRIER_NONE,
7168         REISERFS_BARRIER_FLUSH,
7169 +       REISERFS_TAGGED,
7170  
7171         /* Actions on error */
7172         REISERFS_ERROR_PANIC,
7173 @@ -1543,6 +1544,11 @@ struct stat_data_v1 {
7174  #define REISERFS_COMPR_FL     FS_COMPR_FL
7175  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
7176  
7177 +/* unfortunately reiserfs sdattr is only 16 bit */
7178 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
7179 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
7180 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
7181 +
7182  /* persistent flags that file inherits from the parent directory */
7183  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
7184                                 REISERFS_SYNC_FL |      \
7185 @@ -1552,6 +1558,9 @@ struct stat_data_v1 {
7186                                 REISERFS_COMPR_FL |     \
7187                                 REISERFS_NOTAIL_FL )
7188  
7189 +#define REISERFS_FL_USER_VISIBLE       0x80FF
7190 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
7191 +
7192  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7193     address blocks) */
7194  struct stat_data {
7195 @@ -2641,6 +2650,7 @@ static inline void reiserfs_update_sd(st
7196  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7197  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7198  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7199 +int reiserfs_sync_flags(struct inode *inode, int, int);
7200  
7201  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7202  
7203 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/super.c linux-3.4.83-vs2.3.3.9/fs/reiserfs/super.c
7204 --- linux-3.4.83/fs/reiserfs/super.c    2014-03-12 09:48:17.000000000 +0000
7205 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/super.c  2012-12-08 00:53:53.000000000 +0000
7206 @@ -982,6 +982,14 @@ static int reiserfs_parse_options(struct
7207                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7208                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7209  #endif
7210 +#ifndef CONFIG_TAGGING_NONE
7211 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7212 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7213 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7214 +#endif
7215 +#ifdef CONFIG_PROPAGATE
7216 +               {"tag",.arg_required = 'T',.values = NULL},
7217 +#endif
7218  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7219                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7220                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7221 @@ -1300,6 +1308,14 @@ static int reiserfs_remount(struct super
7222         handle_quota_files(s, qf_names, &qfmt);
7223  #endif
7224  
7225 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7226 +               !(s->s_flags & MS_TAGGED)) {
7227 +               reiserfs_warning(s, "super-vs01",
7228 +                       "reiserfs: tagging not permitted on remount.");
7229 +               err = -EINVAL;
7230 +               goto out_err;
7231 +       }
7232 +
7233         handle_attrs(s);
7234  
7235         /* Add options that are safe here */
7236 @@ -1792,6 +1808,10 @@ static int reiserfs_fill_super(struct su
7237                 goto error_unlocked;
7238         }
7239  
7240 +       /* map mount option tagxid */
7241 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7242 +               s->s_flags |= MS_TAGGED;
7243 +
7244         rs = SB_DISK_SUPER_BLOCK(s);
7245         /* Let's do basic sanity check to verify that underlying device is not
7246            smaller than the filesystem. If the check fails then abort and scream,
7247 diff -NurpP --minimal linux-3.4.83/fs/reiserfs/xattr.c linux-3.4.83-vs2.3.3.9/fs/reiserfs/xattr.c
7248 --- linux-3.4.83/fs/reiserfs/xattr.c    2014-03-12 09:48:17.000000000 +0000
7249 +++ linux-3.4.83-vs2.3.3.9/fs/reiserfs/xattr.c  2013-07-14 13:38:35.000000000 +0000
7250 @@ -40,6 +40,7 @@
7251  #include <linux/errno.h>
7252  #include <linux/gfp.h>
7253  #include <linux/fs.h>
7254 +#include <linux/mount.h>
7255  #include <linux/file.h>
7256  #include <linux/pagemap.h>
7257  #include <linux/xattr.h>
7258 diff -NurpP --minimal linux-3.4.83/fs/stat.c linux-3.4.83-vs2.3.3.9/fs/stat.c
7259 --- linux-3.4.83/fs/stat.c      2014-03-12 09:48:18.000000000 +0000
7260 +++ linux-3.4.83-vs2.3.3.9/fs/stat.c    2012-10-22 13:09:53.000000000 +0000
7261 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7262         stat->nlink = inode->i_nlink;
7263         stat->uid = inode->i_uid;
7264         stat->gid = inode->i_gid;
7265 +       stat->tag = inode->i_tag;
7266         stat->rdev = inode->i_rdev;
7267         stat->size = i_size_read(inode);
7268         stat->atime = inode->i_atime;
7269 diff -NurpP --minimal linux-3.4.83/fs/statfs.c linux-3.4.83-vs2.3.3.9/fs/statfs.c
7270 --- linux-3.4.83/fs/statfs.c    2014-03-12 09:48:18.000000000 +0000
7271 +++ linux-3.4.83-vs2.3.3.9/fs/statfs.c  2013-10-26 18:10:23.000000000 +0000
7272 @@ -7,6 +7,8 @@
7273  #include <linux/statfs.h>
7274  #include <linux/security.h>
7275  #include <linux/uaccess.h>
7276 +#include <linux/vs_base.h>
7277 +#include <linux/vs_dlimit.h>
7278  #include "internal.h"
7279  
7280  static int flags_by_mnt(int mnt_flags)
7281 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7282         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7283         if (retval == 0 && buf->f_frsize == 0)
7284                 buf->f_frsize = buf->f_bsize;
7285 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7286 +               vx_vsi_statfs(dentry->d_sb, buf);
7287         return retval;
7288  }
7289  
7290 diff -NurpP --minimal linux-3.4.83/fs/super.c linux-3.4.83-vs2.3.3.9/fs/super.c
7291 --- linux-3.4.83/fs/super.c     2014-03-12 09:48:18.000000000 +0000
7292 +++ linux-3.4.83-vs2.3.3.9/fs/super.c   2013-08-13 17:07:36.000000000 +0000
7293 @@ -33,6 +33,8 @@
7294  #include <linux/rculist_bl.h>
7295  #include <linux/cleancache.h>
7296  #include <linux/fsnotify.h>
7297 +#include <linux/magic.h>
7298 +#include <linux/vs_context.h>
7299  #include "internal.h"
7300  
7301  
7302 @@ -1133,6 +1135,13 @@ mount_fs(struct file_system_type *type,
7303         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7304         sb->s_flags |= MS_BORN;
7305  
7306 +       error = -EPERM;
7307 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7308 +               !sb->s_bdev &&
7309 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7310 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7311 +               goto out_sb;
7312 +
7313         error = security_sb_kern_mount(sb, flags, secdata);
7314         if (error)
7315                 goto out_sb;
7316 diff -NurpP --minimal linux-3.4.83/fs/sysfs/mount.c linux-3.4.83-vs2.3.3.9/fs/sysfs/mount.c
7317 --- linux-3.4.83/fs/sysfs/mount.c       2012-05-21 16:07:27.000000000 +0000
7318 +++ linux-3.4.83-vs2.3.3.9/fs/sysfs/mount.c     2012-05-21 16:15:05.000000000 +0000
7319 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7320  
7321         sb->s_blocksize = PAGE_CACHE_SIZE;
7322         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7323 -       sb->s_magic = SYSFS_MAGIC;
7324 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7325         sb->s_op = &sysfs_ops;
7326         sb->s_time_gran = 1;
7327  
7328 diff -NurpP --minimal linux-3.4.83/fs/utimes.c linux-3.4.83-vs2.3.3.9/fs/utimes.c
7329 --- linux-3.4.83/fs/utimes.c    2011-05-22 14:17:54.000000000 +0000
7330 +++ linux-3.4.83-vs2.3.3.9/fs/utimes.c  2012-05-21 16:15:05.000000000 +0000
7331 @@ -8,6 +8,8 @@
7332  #include <linux/stat.h>
7333  #include <linux/utime.h>
7334  #include <linux/syscalls.h>
7335 +#include <linux/mount.h>
7336 +#include <linux/vs_cowbl.h>
7337  #include <asm/uaccess.h>
7338  #include <asm/unistd.h>
7339  
7340 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7341  {
7342         int error;
7343         struct iattr newattrs;
7344 -       struct inode *inode = path->dentry->d_inode;
7345 +       struct inode *inode;
7346  
7347         error = mnt_want_write(path->mnt);
7348         if (error)
7349                 goto out;
7350  
7351 +       error = cow_check_and_break(path);
7352 +       if (error)
7353 +               goto mnt_drop_write_and_out;
7354 +
7355 +       inode = path->dentry->d_inode;
7356 +
7357         if (times && times[0].tv_nsec == UTIME_NOW &&
7358                      times[1].tv_nsec == UTIME_NOW)
7359                 times = NULL;
7360 diff -NurpP --minimal linux-3.4.83/fs/xattr.c linux-3.4.83-vs2.3.3.9/fs/xattr.c
7361 --- linux-3.4.83/fs/xattr.c     2012-05-21 16:07:27.000000000 +0000
7362 +++ linux-3.4.83-vs2.3.3.9/fs/xattr.c   2012-05-21 16:15:05.000000000 +0000
7363 @@ -20,6 +20,7 @@
7364  #include <linux/fsnotify.h>
7365  #include <linux/audit.h>
7366  #include <linux/vmalloc.h>
7367 +#include <linux/mount.h>
7368  
7369  #include <asm/uaccess.h>
7370  
7371 @@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7372          * The trusted.* namespace can only be accessed by privileged users.
7373          */
7374         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7375 -               if (!capable(CAP_SYS_ADMIN))
7376 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7377                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7378                 return 0;
7379         }
7380 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_dinode.h linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_dinode.h
7381 --- linux-3.4.83/fs/xfs/xfs_dinode.h    2011-10-24 16:45:31.000000000 +0000
7382 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_dinode.h  2012-05-21 16:15:05.000000000 +0000
7383 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7384         __be32          di_nlink;       /* number of links to file */
7385         __be16          di_projid_lo;   /* lower part of owner's project id */
7386         __be16          di_projid_hi;   /* higher part owner's project id */
7387 -       __u8            di_pad[6];      /* unused, zeroed space */
7388 +       __u8            di_pad[2];      /* unused, zeroed space */
7389 +       __be16          di_tag;         /* context tagging */
7390 +       __be16          di_vflags;      /* vserver specific flags */
7391         __be16          di_flushiter;   /* incremented on flush */
7392         xfs_timestamp_t di_atime;       /* time last accessed */
7393         xfs_timestamp_t di_mtime;       /* time last modified */
7394 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7395  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7396  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7397  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7398 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7399 +
7400  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7401  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7402  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7403 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7404  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7405  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7406  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7407 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7408  
7409  #ifdef CONFIG_XFS_RT
7410  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7411 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7412          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7413          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7414          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7415 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7416 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7417 +        XFS_DIFLAG_IXUNLINK)
7418 +
7419 +#define XFS_DIVFLAG_BARRIER    0x01
7420 +#define XFS_DIVFLAG_COW                0x02
7421  
7422  #endif /* __XFS_DINODE_H__ */
7423 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_fs.h linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_fs.h
7424 --- linux-3.4.83/fs/xfs/xfs_fs.h        2011-10-24 16:45:31.000000000 +0000
7425 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_fs.h      2012-05-21 16:15:05.000000000 +0000
7426 @@ -67,6 +67,9 @@ struct fsxattr {
7427  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7428  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7429  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7430 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7431 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7432 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7433  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7434  
7435  /*
7436 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7437  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7438         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7439         __u16           bs_projid_hi;   /* higher part of project id    */
7440 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7441 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7442 +       __u16           bs_tag;         /* context tagging              */
7443         __u32           bs_dmevmask;    /* DMIG event mask              */
7444         __u16           bs_dmstate;     /* DMIG state info              */
7445         __u16           bs_aextents;    /* attribute number of extents  */
7446 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_ialloc.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_ialloc.c
7447 --- linux-3.4.83/fs/xfs/xfs_ialloc.c    2012-03-19 18:47:27.000000000 +0000
7448 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_ialloc.c  2012-05-21 16:15:05.000000000 +0000
7449 @@ -37,7 +37,6 @@
7450  #include "xfs_error.h"
7451  #include "xfs_bmap.h"
7452  
7453 -
7454  /*
7455   * Allocation group level functions.
7456   */
7457 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_inode.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_inode.c
7458 --- linux-3.4.83/fs/xfs/xfs_inode.c     2012-05-21 16:07:27.000000000 +0000
7459 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_inode.c   2012-05-21 16:15:05.000000000 +0000
7460 @@ -236,6 +236,7 @@ xfs_inotobp(
7461         return 0;
7462  }
7463  
7464 +#include <linux/vs_tag.h>
7465  
7466  /*
7467   * This routine is called to map an inode to the buffer containing
7468 @@ -631,15 +632,25 @@ xfs_iformat_btree(
7469  STATIC void
7470  xfs_dinode_from_disk(
7471         xfs_icdinode_t          *to,
7472 -       xfs_dinode_t            *from)
7473 +       xfs_dinode_t            *from,
7474 +       int tagged)
7475  {
7476 +       uint32_t uid, gid, tag;
7477 +
7478         to->di_magic = be16_to_cpu(from->di_magic);
7479         to->di_mode = be16_to_cpu(from->di_mode);
7480         to->di_version = from ->di_version;
7481         to->di_format = from->di_format;
7482         to->di_onlink = be16_to_cpu(from->di_onlink);
7483 -       to->di_uid = be32_to_cpu(from->di_uid);
7484 -       to->di_gid = be32_to_cpu(from->di_gid);
7485 +
7486 +       uid = be32_to_cpu(from->di_uid);
7487 +       gid = be32_to_cpu(from->di_gid);
7488 +       tag = be16_to_cpu(from->di_tag);
7489 +
7490 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7491 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7492 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7493 +
7494         to->di_nlink = be32_to_cpu(from->di_nlink);
7495         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7496         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7497 @@ -661,21 +672,26 @@ xfs_dinode_from_disk(
7498         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7499         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7500         to->di_flags    = be16_to_cpu(from->di_flags);
7501 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7502         to->di_gen      = be32_to_cpu(from->di_gen);
7503  }
7504  
7505  void
7506  xfs_dinode_to_disk(
7507         xfs_dinode_t            *to,
7508 -       xfs_icdinode_t          *from)
7509 +       xfs_icdinode_t          *from,
7510 +       int tagged)
7511  {
7512         to->di_magic = cpu_to_be16(from->di_magic);
7513         to->di_mode = cpu_to_be16(from->di_mode);
7514         to->di_version = from ->di_version;
7515         to->di_format = from->di_format;
7516         to->di_onlink = cpu_to_be16(from->di_onlink);
7517 -       to->di_uid = cpu_to_be32(from->di_uid);
7518 -       to->di_gid = cpu_to_be32(from->di_gid);
7519 +
7520 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7521 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7522 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7523 +
7524         to->di_nlink = cpu_to_be32(from->di_nlink);
7525         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7526         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7527 @@ -697,12 +713,14 @@ xfs_dinode_to_disk(
7528         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7529         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7530         to->di_flags = cpu_to_be16(from->di_flags);
7531 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7532         to->di_gen = cpu_to_be32(from->di_gen);
7533  }
7534  
7535  STATIC uint
7536  _xfs_dic2xflags(
7537 -       __uint16_t              di_flags)
7538 +       __uint16_t              di_flags,
7539 +       __uint16_t              di_vflags)
7540  {
7541         uint                    flags = 0;
7542  
7543 @@ -713,6 +731,8 @@ _xfs_dic2xflags(
7544                         flags |= XFS_XFLAG_PREALLOC;
7545                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7546                         flags |= XFS_XFLAG_IMMUTABLE;
7547 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7548 +                       flags |= XFS_XFLAG_IXUNLINK;
7549                 if (di_flags & XFS_DIFLAG_APPEND)
7550                         flags |= XFS_XFLAG_APPEND;
7551                 if (di_flags & XFS_DIFLAG_SYNC)
7552 @@ -737,6 +757,10 @@ _xfs_dic2xflags(
7553                         flags |= XFS_XFLAG_FILESTREAM;
7554         }
7555  
7556 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7557 +               flags |= FS_BARRIER_FL;
7558 +       if (di_vflags & XFS_DIVFLAG_COW)
7559 +               flags |= FS_COW_FL;
7560         return flags;
7561  }
7562  
7563 @@ -746,7 +770,7 @@ xfs_ip2xflags(
7564  {
7565         xfs_icdinode_t          *dic = &ip->i_d;
7566  
7567 -       return _xfs_dic2xflags(dic->di_flags) |
7568 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7569                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7570  }
7571  
7572 @@ -754,7 +778,8 @@ uint
7573  xfs_dic2xflags(
7574         xfs_dinode_t            *dip)
7575  {
7576 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7577 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7578 +                               be16_to_cpu(dip->di_vflags)) |
7579                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7580  }
7581  
7582 @@ -787,7 +812,6 @@ xfs_iread(
7583         if (error)
7584                 return error;
7585         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7586 -
7587         /*
7588          * If we got something that isn't an inode it means someone
7589          * (nfs or dmi) has a stale handle.
7590 @@ -810,7 +834,8 @@ xfs_iread(
7591          * Otherwise, just get the truly permanent information.
7592          */
7593         if (dip->di_mode) {
7594 -               xfs_dinode_from_disk(&ip->i_d, dip);
7595 +               xfs_dinode_from_disk(&ip->i_d, dip,
7596 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7597                 error = xfs_iformat(ip, dip);
7598                 if (error)  {
7599  #ifdef DEBUG
7600 @@ -998,6 +1023,7 @@ xfs_ialloc(
7601         ASSERT(ip->i_d.di_nlink == nlink);
7602         ip->i_d.di_uid = current_fsuid();
7603         ip->i_d.di_gid = current_fsgid();
7604 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7605         xfs_set_projid(ip, prid);
7606         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7607  
7608 @@ -1057,6 +1083,7 @@ xfs_ialloc(
7609         ip->i_d.di_dmevmask = 0;
7610         ip->i_d.di_dmstate = 0;
7611         ip->i_d.di_flags = 0;
7612 +       ip->i_d.di_vflags = 0;
7613         flags = XFS_ILOG_CORE;
7614         switch (mode & S_IFMT) {
7615         case S_IFIFO:
7616 @@ -1725,6 +1752,7 @@ xfs_ifree(
7617         }
7618         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7619         ip->i_d.di_flags = 0;
7620 +       ip->i_d.di_vflags = 0;
7621         ip->i_d.di_dmevmask = 0;
7622         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7623         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7624 @@ -2598,7 +2626,8 @@ xfs_iflush_int(
7625          * because if the inode is dirty at all the core must
7626          * be.
7627          */
7628 -       xfs_dinode_to_disk(dip, &ip->i_d);
7629 +       xfs_dinode_to_disk(dip, &ip->i_d,
7630 +               mp->m_flags & XFS_MOUNT_TAGGED);
7631  
7632         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7633         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7634 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_inode.h linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_inode.h
7635 --- linux-3.4.83/fs/xfs/xfs_inode.h     2012-05-21 16:07:27.000000000 +0000
7636 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_inode.h   2012-05-21 16:15:05.000000000 +0000
7637 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7638         __uint32_t      di_nlink;       /* number of links to file */
7639         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7640         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7641 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7642 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7643 +       __uint16_t      di_tag;         /* context tagging */
7644 +       __uint16_t      di_vflags;      /* vserver specific flags */
7645         __uint16_t      di_flushiter;   /* incremented on flush */
7646         xfs_ictimestamp_t di_atime;     /* time last accessed */
7647         xfs_ictimestamp_t di_mtime;     /* time last modified */
7648 @@ -565,7 +567,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7649  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7650                           struct xfs_inode *, uint);
7651  void           xfs_dinode_to_disk(struct xfs_dinode *,
7652 -                                  struct xfs_icdinode *);
7653 +                                  struct xfs_icdinode *, int);
7654  void           xfs_idestroy_fork(struct xfs_inode *, int);
7655  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7656  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7657 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_ioctl.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_ioctl.c
7658 --- linux-3.4.83/fs/xfs/xfs_ioctl.c     2014-03-12 09:48:18.000000000 +0000
7659 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_ioctl.c   2014-03-12 09:55:28.000000000 +0000
7660 @@ -28,7 +28,7 @@
7661  #include "xfs_bmap_btree.h"
7662  #include "xfs_dinode.h"
7663  #include "xfs_inode.h"
7664 -#include "xfs_ioctl.h"
7665 +// #include "xfs_ioctl.h"
7666  #include "xfs_rtalloc.h"
7667  #include "xfs_itable.h"
7668  #include "xfs_error.h"
7669 @@ -751,6 +751,10 @@ xfs_merge_ioc_xflags(
7670                 xflags |= XFS_XFLAG_IMMUTABLE;
7671         else
7672                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7673 +       if (flags & FS_IXUNLINK_FL)
7674 +               xflags |= XFS_XFLAG_IXUNLINK;
7675 +       else
7676 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7677         if (flags & FS_APPEND_FL)
7678                 xflags |= XFS_XFLAG_APPEND;
7679         else
7680 @@ -779,6 +783,8 @@ xfs_di2lxflags(
7681  
7682         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7683                 flags |= FS_IMMUTABLE_FL;
7684 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7685 +               flags |= FS_IXUNLINK_FL;
7686         if (di_flags & XFS_DIFLAG_APPEND)
7687                 flags |= FS_APPEND_FL;
7688         if (di_flags & XFS_DIFLAG_SYNC)
7689 @@ -839,6 +845,8 @@ xfs_set_diflags(
7690         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7691         if (xflags & XFS_XFLAG_IMMUTABLE)
7692                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7693 +       if (xflags & XFS_XFLAG_IXUNLINK)
7694 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7695         if (xflags & XFS_XFLAG_APPEND)
7696                 di_flags |= XFS_DIFLAG_APPEND;
7697         if (xflags & XFS_XFLAG_SYNC)
7698 @@ -881,6 +889,10 @@ xfs_diflags_to_linux(
7699                 inode->i_flags |= S_IMMUTABLE;
7700         else
7701                 inode->i_flags &= ~S_IMMUTABLE;
7702 +       if (xflags & XFS_XFLAG_IXUNLINK)
7703 +               inode->i_flags |= S_IXUNLINK;
7704 +       else
7705 +               inode->i_flags &= ~S_IXUNLINK;
7706         if (xflags & XFS_XFLAG_APPEND)
7707                 inode->i_flags |= S_APPEND;
7708         else
7709 @@ -1373,10 +1385,18 @@ xfs_file_ioctl(
7710         case XFS_IOC_FSGETXATTRA:
7711                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7712         case XFS_IOC_FSSETXATTR:
7713 +               if (IS_BARRIER(inode)) {
7714 +                       vxwprintk_task(1, "messing with the barrier.");
7715 +                       return -XFS_ERROR(EACCES);
7716 +               }
7717                 return xfs_ioc_fssetxattr(ip, filp, arg);
7718         case XFS_IOC_GETXFLAGS:
7719                 return xfs_ioc_getxflags(ip, arg);
7720         case XFS_IOC_SETXFLAGS:
7721 +               if (IS_BARRIER(inode)) {
7722 +                       vxwprintk_task(1, "messing with the barrier.");
7723 +                       return -XFS_ERROR(EACCES);
7724 +               }
7725                 return xfs_ioc_setxflags(ip, filp, arg);
7726  
7727         case XFS_IOC_FSSETDM: {
7728 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_ioctl.h linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_ioctl.h
7729 --- linux-3.4.83/fs/xfs/xfs_ioctl.h     2011-10-24 16:45:31.000000000 +0000
7730 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_ioctl.h   2012-05-21 16:15:05.000000000 +0000
7731 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7732         void __user             *uhandle,
7733         u32                     hlen);
7734  
7735 +extern int
7736 +xfs_sync_flags(
7737 +       struct inode            *inode,
7738 +       int                     flags,
7739 +       int                     vflags);
7740 +
7741  extern long
7742  xfs_file_ioctl(
7743         struct file             *filp,
7744 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_iops.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_iops.c
7745 --- linux-3.4.83/fs/xfs/xfs_iops.c      2014-03-12 09:48:18.000000000 +0000
7746 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_iops.c    2013-07-14 13:38:35.000000000 +0000
7747 @@ -30,6 +30,7 @@
7748  #include "xfs_bmap_btree.h"
7749  #include "xfs_dinode.h"
7750  #include "xfs_inode.h"
7751 +#include "xfs_ioctl.h"
7752  #include "xfs_bmap.h"
7753  #include "xfs_rtalloc.h"
7754  #include "xfs_error.h"
7755 @@ -49,6 +50,7 @@
7756  #include <linux/security.h>
7757  #include <linux/fiemap.h>
7758  #include <linux/slab.h>
7759 +#include <linux/vs_tag.h>
7760  
7761  static int
7762  xfs_initxattrs(
7763 @@ -424,6 +426,7 @@ xfs_vn_getattr(
7764         stat->nlink = ip->i_d.di_nlink;
7765         stat->uid = ip->i_d.di_uid;
7766         stat->gid = ip->i_d.di_gid;
7767 +       stat->tag = ip->i_d.di_tag;
7768         stat->ino = ip->i_ino;
7769         stat->atime = inode->i_atime;
7770         stat->mtime = inode->i_mtime;
7771 @@ -1013,6 +1016,7 @@ static const struct inode_operations xfs
7772         .removexattr            = generic_removexattr,
7773         .listxattr              = xfs_vn_listxattr,
7774         .fiemap                 = xfs_vn_fiemap,
7775 +       .sync_flags             = xfs_sync_flags,
7776  };
7777  
7778  static const struct inode_operations xfs_dir_inode_operations = {
7779 @@ -1038,6 +1042,7 @@ static const struct inode_operations xfs
7780         .getxattr               = generic_getxattr,
7781         .removexattr            = generic_removexattr,
7782         .listxattr              = xfs_vn_listxattr,
7783 +       .sync_flags             = xfs_sync_flags,
7784  };
7785  
7786  static const struct inode_operations xfs_dir_ci_inode_operations = {
7787 @@ -1087,6 +1092,10 @@ xfs_diflags_to_iflags(
7788                 inode->i_flags |= S_IMMUTABLE;
7789         else
7790                 inode->i_flags &= ~S_IMMUTABLE;
7791 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7792 +               inode->i_flags |= S_IXUNLINK;
7793 +       else
7794 +               inode->i_flags &= ~S_IXUNLINK;
7795         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7796                 inode->i_flags |= S_APPEND;
7797         else
7798 @@ -1099,6 +1108,15 @@ xfs_diflags_to_iflags(
7799                 inode->i_flags |= S_NOATIME;
7800         else
7801                 inode->i_flags &= ~S_NOATIME;
7802 +
7803 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7804 +               inode->i_vflags |= V_BARRIER;
7805 +       else
7806 +               inode->i_vflags &= ~V_BARRIER;
7807 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7808 +               inode->i_vflags |= V_COW;
7809 +       else
7810 +               inode->i_vflags &= ~V_COW;
7811  }
7812  
7813  /*
7814 @@ -1130,6 +1148,7 @@ xfs_setup_inode(
7815         set_nlink(inode, ip->i_d.di_nlink);
7816         inode->i_uid    = ip->i_d.di_uid;
7817         inode->i_gid    = ip->i_d.di_gid;
7818 +       inode->i_tag    = ip->i_d.di_tag;
7819  
7820         switch (inode->i_mode & S_IFMT) {
7821         case S_IFBLK:
7822 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_itable.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_itable.c
7823 --- linux-3.4.83/fs/xfs/xfs_itable.c    2012-05-21 16:07:27.000000000 +0000
7824 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_itable.c  2012-05-21 16:15:05.000000000 +0000
7825 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7826         buf->bs_mode = dic->di_mode;
7827         buf->bs_uid = dic->di_uid;
7828         buf->bs_gid = dic->di_gid;
7829 +       buf->bs_tag = dic->di_tag;
7830         buf->bs_size = dic->di_size;
7831         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7832         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7833 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_linux.h linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_linux.h
7834 --- linux-3.4.83/fs/xfs/xfs_linux.h     2011-10-24 16:45:31.000000000 +0000
7835 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_linux.h   2012-05-21 16:15:05.000000000 +0000
7836 @@ -121,6 +121,7 @@
7837  
7838  #define current_cpu()          (raw_smp_processor_id())
7839  #define current_pid()          (current->pid)
7840 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7841  #define current_test_flags(f)  (current->flags & (f))
7842  #define current_set_flags_nested(sp, f)                \
7843                 (*(sp) = current->flags, current->flags |= (f))
7844 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_log_recover.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_log_recover.c
7845 --- linux-3.4.83/fs/xfs/xfs_log_recover.c       2014-03-12 09:48:18.000000000 +0000
7846 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_log_recover.c     2012-11-18 23:52:29.000000000 +0000
7847 @@ -2344,7 +2344,8 @@ xlog_recover_inode_pass2(
7848         }
7849  
7850         /* The core is in in-core format */
7851 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7852 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7853 +               mp->m_flags & XFS_MOUNT_TAGGED);
7854  
7855         /* the rest is in on-disk format */
7856         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7857 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_mount.h linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_mount.h
7858 --- linux-3.4.83/fs/xfs/xfs_mount.h     2012-05-21 16:07:28.000000000 +0000
7859 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_mount.h   2012-05-21 16:15:05.000000000 +0000
7860 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
7861                                                    allocator */
7862  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7863  
7864 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7865  
7866  /*
7867   * Default minimum read and write sizes.
7868 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_super.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_super.c
7869 --- linux-3.4.83/fs/xfs/xfs_super.c     2012-05-21 16:07:28.000000000 +0000
7870 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_super.c   2012-05-21 16:15:05.000000000 +0000
7871 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7872  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7873  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7874  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7875 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7876 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7877 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7878  
7879  /*
7880   * Table driven mount option parser.
7881 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7882   * in the future, too.
7883   */
7884  enum {
7885 +       Opt_tag, Opt_notag,
7886         Opt_barrier, Opt_nobarrier, Opt_err
7887  };
7888  
7889  static const match_table_t tokens = {
7890 +       {Opt_tag, "tagxid"},
7891 +       {Opt_tag, "tag"},
7892 +       {Opt_notag, "notag"},
7893         {Opt_barrier, "barrier"},
7894         {Opt_nobarrier, "nobarrier"},
7895         {Opt_err, NULL}
7896 @@ -372,6 +379,19 @@ xfs_parseargs(
7897                 } else if (!strcmp(this_char, "irixsgid")) {
7898                         xfs_warn(mp,
7899         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7900 +#ifndef CONFIG_TAGGING_NONE
7901 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7902 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7903 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7904 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7905 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7906 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7907 +#endif
7908 +#ifdef CONFIG_PROPAGATE
7909 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7910 +                       /* use value */
7911 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7912 +#endif
7913                 } else {
7914                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7915                         return EINVAL;
7916 @@ -1127,6 +1147,16 @@ xfs_fs_remount(
7917                 case Opt_nobarrier:
7918                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7919                         break;
7920 +               case Opt_tag:
7921 +                       if (!(sb->s_flags & MS_TAGGED)) {
7922 +                               printk(KERN_INFO
7923 +                                       "XFS: %s: tagging not permitted on remount.\n",
7924 +                                       sb->s_id);
7925 +                               return -EINVAL;
7926 +                       }
7927 +                       break;
7928 +               case Opt_notag:
7929 +                       break;
7930                 default:
7931                         /*
7932                          * Logically we would return an error here to prevent
7933 @@ -1346,6 +1376,9 @@ xfs_fs_fill_super(
7934         if (error)
7935                 goto out_free_sb;
7936  
7937 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7938 +               sb->s_flags |= MS_TAGGED;
7939 +
7940         /*
7941          * we must configure the block size in the superblock before we run the
7942          * full mount process as the mount process can lookup and cache inodes.
7943 diff -NurpP --minimal linux-3.4.83/fs/xfs/xfs_vnodeops.c linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_vnodeops.c
7944 --- linux-3.4.83/fs/xfs/xfs_vnodeops.c  2012-05-21 16:07:28.000000000 +0000
7945 +++ linux-3.4.83-vs2.3.3.9/fs/xfs/xfs_vnodeops.c        2012-05-21 16:15:05.000000000 +0000
7946 @@ -106,6 +106,77 @@ xfs_readlink_bmap(
7947         return error;
7948  }
7949  
7950 +
7951 +STATIC void
7952 +xfs_get_inode_flags(
7953 +       xfs_inode_t     *ip)
7954 +{
7955 +       struct inode    *inode = VFS_I(ip);
7956 +       unsigned int    flags = inode->i_flags;
7957 +       unsigned int    vflags = inode->i_vflags;
7958 +
7959 +       if (flags & S_IMMUTABLE)
7960 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7961 +       else
7962 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7963 +       if (flags & S_IXUNLINK)
7964 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7965 +       else
7966 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7967 +
7968 +       if (vflags & V_BARRIER)
7969 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7970 +       else
7971 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7972 +       if (vflags & V_COW)
7973 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7974 +       else
7975 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7976 +}
7977 +
7978 +int
7979 +xfs_sync_flags(
7980 +       struct inode            *inode,
7981 +       int                     flags,
7982 +       int                     vflags)
7983 +{
7984 +       struct xfs_inode        *ip = XFS_I(inode);
7985 +       struct xfs_mount        *mp = ip->i_mount;
7986 +       struct xfs_trans        *tp;
7987 +       unsigned int            lock_flags = 0;
7988 +       int                     code;
7989 +
7990 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7991 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7992 +       if (code)
7993 +               goto error_out;
7994 +
7995 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7996 +       xfs_trans_ijoin(tp, ip, 0);
7997 +
7998 +       inode->i_flags = flags;
7999 +       inode->i_vflags = vflags;
8000 +       xfs_get_inode_flags(ip);
8001 +
8002 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8003 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8004 +
8005 +       XFS_STATS_INC(xs_ig_attrchg);
8006 +
8007 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8008 +               xfs_trans_set_sync(tp);
8009 +       code = xfs_trans_commit(tp, 0);
8010 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8011 +       return code;
8012 +
8013 +error_out:
8014 +       xfs_trans_cancel(tp, 0);
8015 +       if (lock_flags)
8016 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8017 +       return code;
8018 +}
8019 +
8020 +
8021  int
8022  xfs_readlink(
8023         xfs_inode_t     *ip,
8024 diff -NurpP --minimal linux-3.4.83/include/linux/Kbuild linux-3.4.83-vs2.3.3.9/include/linux/Kbuild
8025 --- linux-3.4.83/include/linux/Kbuild   2014-03-12 09:48:18.000000000 +0000
8026 +++ linux-3.4.83-vs2.3.3.9/include/linux/Kbuild 2012-07-24 09:52:30.000000000 +0000
8027 @@ -18,6 +18,7 @@ header-y += netfilter_bridge/
8028  header-y += netfilter_ipv4/
8029  header-y += netfilter_ipv6/
8030  header-y += usb/
8031 +header-y += vserver/
8032  header-y += wimax/
8033  
8034  objhdr-y += version.h
8035 diff -NurpP --minimal linux-3.4.83/include/linux/capability.h linux-3.4.83-vs2.3.3.9/include/linux/capability.h
8036 --- linux-3.4.83/include/linux/capability.h     2012-03-19 18:47:27.000000000 +0000
8037 +++ linux-3.4.83-vs2.3.3.9/include/linux/capability.h   2012-05-21 16:15:05.000000000 +0000
8038 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
8039     arbitrary SCSI commands */
8040  /* Allow setting encryption key on loopback filesystem */
8041  /* Allow setting zone reclaim policy */
8042 +/* Allow the selection of a security context */
8043  
8044  #define CAP_SYS_ADMIN        21
8045  
8046 @@ -363,7 +364,12 @@ struct cpu_vfs_cap_data {
8047  
8048  #define CAP_LAST_CAP         CAP_WAKE_ALARM
8049  
8050 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8051 +/* Allow context manipulations */
8052 +/* Allow changing context info on files */
8053 +
8054 +#define CAP_CONTEXT         63
8055 +
8056 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8057  
8058  /*
8059   * Bit location of each capability (used by user-space library and kernel)
8060 diff -NurpP --minimal linux-3.4.83/include/linux/cred.h linux-3.4.83-vs2.3.3.9/include/linux/cred.h
8061 --- linux-3.4.83/include/linux/cred.h   2012-03-19 18:47:27.000000000 +0000
8062 +++ linux-3.4.83-vs2.3.3.9/include/linux/cred.h 2012-05-21 16:15:05.000000000 +0000
8063 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
8064  extern int copy_creds(struct task_struct *, unsigned long);
8065  extern const struct cred *get_task_cred(struct task_struct *);
8066  extern struct cred *cred_alloc_blank(void);
8067 +extern struct cred *__prepare_creds(const struct cred *);
8068  extern struct cred *prepare_creds(void);
8069  extern struct cred *prepare_exec_creds(void);
8070  extern int commit_creds(struct cred *);
8071 @@ -209,6 +210,31 @@ static inline void validate_process_cred
8072  }
8073  #endif
8074  
8075 +static inline void set_cred_subscribers(struct cred *cred, int n)
8076 +{
8077 +#ifdef CONFIG_DEBUG_CREDENTIALS
8078 +       atomic_set(&cred->subscribers, n);
8079 +#endif
8080 +}
8081 +
8082 +static inline int read_cred_subscribers(const struct cred *cred)
8083 +{
8084 +#ifdef CONFIG_DEBUG_CREDENTIALS
8085 +       return atomic_read(&cred->subscribers);
8086 +#else
8087 +       return 0;
8088 +#endif
8089 +}
8090 +
8091 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8092 +{
8093 +#ifdef CONFIG_DEBUG_CREDENTIALS
8094 +       struct cred *cred = (struct cred *) _cred;
8095 +
8096 +       atomic_add(n, &cred->subscribers);
8097 +#endif
8098 +}
8099 +
8100  /**
8101   * get_new_cred - Get a reference on a new set of credentials
8102   * @cred: The new credentials to reference
8103 diff -NurpP --minimal linux-3.4.83/include/linux/devpts_fs.h linux-3.4.83-vs2.3.3.9/include/linux/devpts_fs.h
8104 --- linux-3.4.83/include/linux/devpts_fs.h      2008-12-24 23:26:37.000000000 +0000
8105 +++ linux-3.4.83-vs2.3.3.9/include/linux/devpts_fs.h    2012-05-21 16:15:05.000000000 +0000
8106 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8107  
8108  #endif
8109  
8110 -
8111  #endif /* _LINUX_DEVPTS_FS_H */
8112 diff -NurpP --minimal linux-3.4.83/include/linux/fs.h linux-3.4.83-vs2.3.3.9/include/linux/fs.h
8113 --- linux-3.4.83/include/linux/fs.h     2014-03-12 09:48:19.000000000 +0000
8114 +++ linux-3.4.83-vs2.3.3.9/include/linux/fs.h   2014-03-12 09:55:28.000000000 +0000
8115 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8116  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8117  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8118  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8119 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8120 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8121 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8122  #define MS_NOSEC       (1<<28)
8123  #define MS_BORN                (1<<29)
8124  #define MS_ACTIVE      (1<<30)
8125 @@ -245,6 +248,14 @@ struct inodes_stat_t {
8126  #define S_IMA          1024    /* Inode has an associated IMA struct */
8127  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8128  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8129 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8130 +
8131 +/* Linux-VServer related Inode flags */
8132 +
8133 +#define V_VALID                1
8134 +#define V_XATTR                2
8135 +#define V_BARRIER      4       /* Barrier for chroot() */
8136 +#define V_COW          8       /* Copy on Write */
8137  
8138  /*
8139   * Note that nosuid etc flags are inode-specific: setting some file-system
8140 @@ -267,12 +278,15 @@ struct inodes_stat_t {
8141  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8142                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8143  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8144 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8145 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8146 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8147 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8148 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8149  
8150  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8151  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8152  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8153 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8154 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8155  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8156  
8157  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8158 @@ -283,6 +297,16 @@ struct inodes_stat_t {
8159  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8160  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8161  
8162 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8163 +
8164 +#ifdef CONFIG_VSERVER_COWBL
8165 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8166 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8167 +#else
8168 +#  define IS_COW(inode)                (0)
8169 +#  define IS_COW_LINK(inode)   (0)
8170 +#endif
8171 +
8172  /* the read-only stuff doesn't really belong here, but any other place is
8173     probably as bad and I don't want to create yet another include file. */
8174  
8175 @@ -369,11 +393,14 @@ struct inodes_stat_t {
8176  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8177  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8178  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8179 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8180  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8181  
8182 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8183 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8184 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8185 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8186  
8187 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8188 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8189  
8190  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8191  #define SYNC_FILE_RANGE_WRITE          2
8192 @@ -456,6 +483,7 @@ typedef void (dio_iodone_t)(struct kiocb
8193  #define ATTR_KILL_PRIV (1 << 14)
8194  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8195  #define ATTR_TIMES_SET (1 << 16)
8196 +#define ATTR_TAG       (1 << 17)
8197  
8198  /*
8199   * This is the Inode Attributes structure, used for notify_change().  It
8200 @@ -471,6 +499,7 @@ struct iattr {
8201         umode_t         ia_mode;
8202         uid_t           ia_uid;
8203         gid_t           ia_gid;
8204 +       tag_t           ia_tag;
8205         loff_t          ia_size;
8206         struct timespec ia_atime;
8207         struct timespec ia_mtime;
8208 @@ -484,6 +513,9 @@ struct iattr {
8209         struct file     *ia_file;
8210  };
8211  
8212 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8213 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8214 +
8215  /*
8216   * Includes for diskquotas.
8217   */
8218 @@ -763,7 +795,9 @@ struct inode {
8219         unsigned short          i_opflags;
8220         uid_t                   i_uid;
8221         gid_t                   i_gid;
8222 -       unsigned int            i_flags;
8223 +       tag_t                   i_tag;
8224 +       unsigned short          i_flags;
8225 +       unsigned short          i_vflags;
8226  
8227  #ifdef CONFIG_FS_POSIX_ACL
8228         struct posix_acl        *i_acl;
8229 @@ -792,6 +826,7 @@ struct inode {
8230                 unsigned int __i_nlink;
8231         };
8232         dev_t                   i_rdev;
8233 +       dev_t                   i_mdev;
8234         struct timespec         i_atime;
8235         struct timespec         i_mtime;
8236         struct timespec         i_ctime;
8237 @@ -931,12 +966,12 @@ static inline void i_size_write(struct i
8238  
8239  static inline unsigned iminor(const struct inode *inode)
8240  {
8241 -       return MINOR(inode->i_rdev);
8242 +       return MINOR(inode->i_mdev);
8243  }
8244  
8245  static inline unsigned imajor(const struct inode *inode)
8246  {
8247 -       return MAJOR(inode->i_rdev);
8248 +       return MAJOR(inode->i_mdev);
8249  }
8250  
8251  extern struct block_device *I_BDEV(struct inode *inode);
8252 @@ -1003,6 +1038,7 @@ struct file {
8253         loff_t                  f_pos;
8254         struct fown_struct      f_owner;
8255         const struct cred       *f_cred;
8256 +       xid_t                   f_xid;
8257         struct file_ra_state    f_ra;
8258  
8259         u64                     f_version;
8260 @@ -1150,6 +1186,7 @@ struct file_lock {
8261         struct file *fl_file;
8262         loff_t fl_start;
8263         loff_t fl_end;
8264 +       xid_t fl_xid;
8265  
8266         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8267         /* for lease breaks: */
8268 @@ -1663,6 +1700,7 @@ struct inode_operations {
8269         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8270         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8271         int (*removexattr) (struct dentry *, const char *);
8272 +       int (*sync_flags) (struct inode *, int, int);
8273         void (*truncate_range)(struct inode *, loff_t, loff_t);
8274         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8275                       u64 len);
8276 @@ -1682,6 +1720,7 @@ extern ssize_t vfs_readv(struct file *,
8277                 unsigned long, loff_t *);
8278  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8279                 unsigned long, loff_t *);
8280 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8281  
8282  struct super_operations {
8283         struct inode *(*alloc_inode)(struct super_block *sb);
8284 @@ -2511,6 +2550,7 @@ extern int dcache_dir_open(struct inode
8285  extern int dcache_dir_close(struct inode *, struct file *);
8286  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8287  extern int dcache_readdir(struct file *, void *, filldir_t);
8288 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8289  extern int simple_setattr(struct dentry *, struct iattr *);
8290  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8291  extern int simple_statfs(struct dentry *, struct kstatfs *);
8292 diff -NurpP --minimal linux-3.4.83/include/linux/gfs2_ondisk.h linux-3.4.83-vs2.3.3.9/include/linux/gfs2_ondisk.h
8293 --- linux-3.4.83/include/linux/gfs2_ondisk.h    2012-05-21 16:07:29.000000000 +0000
8294 +++ linux-3.4.83-vs2.3.3.9/include/linux/gfs2_ondisk.h  2012-05-21 16:15:05.000000000 +0000
8295 @@ -214,6 +214,9 @@ enum {
8296         gfs2fl_NoAtime          = 7,
8297         gfs2fl_Sync             = 8,
8298         gfs2fl_System           = 9,
8299 +       gfs2fl_IXUnlink         = 16,
8300 +       gfs2fl_Barrier          = 17,
8301 +       gfs2fl_Cow              = 18,
8302         gfs2fl_TruncInProg      = 29,
8303         gfs2fl_InheritDirectio  = 30,
8304         gfs2fl_InheritJdata     = 31,
8305 @@ -230,6 +233,9 @@ enum {
8306  #define GFS2_DIF_NOATIME               0x00000080
8307  #define GFS2_DIF_SYNC                  0x00000100
8308  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8309 +#define GFS2_DIF_IXUNLINK              0x00010000
8310 +#define GFS2_DIF_BARRIER               0x00020000
8311 +#define GFS2_DIF_COW                   0x00040000
8312  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8313  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8314  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8315 diff -NurpP --minimal linux-3.4.83/include/linux/if_tun.h linux-3.4.83-vs2.3.3.9/include/linux/if_tun.h
8316 --- linux-3.4.83/include/linux/if_tun.h 2010-08-02 14:52:54.000000000 +0000
8317 +++ linux-3.4.83-vs2.3.3.9/include/linux/if_tun.h       2012-05-21 16:15:05.000000000 +0000
8318 @@ -53,6 +53,7 @@
8319  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8320  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8321  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8322 +#define TUNSETNID     _IOW('T', 217, int)
8323  
8324  /* TUNSETIFF ifr flags */
8325  #define IFF_TUN                0x0001
8326 diff -NurpP --minimal linux-3.4.83/include/linux/init_task.h linux-3.4.83-vs2.3.3.9/include/linux/init_task.h
8327 --- linux-3.4.83/include/linux/init_task.h      2014-03-12 09:48:19.000000000 +0000
8328 +++ linux-3.4.83-vs2.3.3.9/include/linux/init_task.h    2012-10-22 13:09:53.000000000 +0000
8329 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
8330         INIT_TRACE_RECURSION                                            \
8331         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8332         INIT_CPUSET_SEQ                                                 \
8333 +       .xid            = 0,                                            \
8334 +       .vx_info        = NULL,                                         \
8335 +       .nid            = 0,                                            \
8336 +       .nx_info        = NULL,                                         \
8337  }
8338  
8339  
8340 diff -NurpP --minimal linux-3.4.83/include/linux/ipc.h linux-3.4.83-vs2.3.3.9/include/linux/ipc.h
8341 --- linux-3.4.83/include/linux/ipc.h    2012-03-19 18:47:28.000000000 +0000
8342 +++ linux-3.4.83-vs2.3.3.9/include/linux/ipc.h  2012-05-21 16:15:05.000000000 +0000
8343 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8344         key_t           key;
8345         uid_t           uid;
8346         gid_t           gid;
8347 +       xid_t           xid;
8348         uid_t           cuid;
8349         gid_t           cgid;
8350         umode_t         mode; 
8351 diff -NurpP --minimal linux-3.4.83/include/linux/ipc_namespace.h linux-3.4.83-vs2.3.3.9/include/linux/ipc_namespace.h
8352 --- linux-3.4.83/include/linux/ipc_namespace.h  2014-03-12 09:48:19.000000000 +0000
8353 +++ linux-3.4.83-vs2.3.3.9/include/linux/ipc_namespace.h        2013-07-14 13:38:35.000000000 +0000
8354 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8355  
8356  #if defined(CONFIG_IPC_NS)
8357  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8358 -                                      struct task_struct *tsk);
8359 +                                      struct ipc_namespace *old_ns,
8360 +                                      struct user_namespace *user_ns);
8361  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8362  {
8363         if (ns)
8364 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8365  extern void put_ipc_ns(struct ipc_namespace *ns);
8366  #else
8367  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8368 -                                             struct task_struct *tsk)
8369 +                                             struct ipc_namespace *old_ns,
8370 +                                             struct user_namespace *user_ns)
8371  {
8372         if (flags & CLONE_NEWIPC)
8373                 return ERR_PTR(-EINVAL);
8374  
8375 -       return tsk->nsproxy->ipc_ns;
8376 +       return old_ns;
8377  }
8378  
8379  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8380 diff -NurpP --minimal linux-3.4.83/include/linux/loop.h linux-3.4.83-vs2.3.3.9/include/linux/loop.h
8381 --- linux-3.4.83/include/linux/loop.h   2012-01-09 15:14:58.000000000 +0000
8382 +++ linux-3.4.83-vs2.3.3.9/include/linux/loop.h 2012-05-21 16:15:05.000000000 +0000
8383 @@ -45,6 +45,7 @@ struct loop_device {
8384         struct loop_func_table *lo_encryption;
8385         __u32           lo_init[2];
8386         uid_t           lo_key_owner;   /* Who set the key */
8387 +       xid_t           lo_xid;
8388         int             (*ioctl)(struct loop_device *, int cmd, 
8389                                  unsigned long arg); 
8390  
8391 diff -NurpP --minimal linux-3.4.83/include/linux/magic.h linux-3.4.83-vs2.3.3.9/include/linux/magic.h
8392 --- linux-3.4.83/include/linux/magic.h  2012-05-21 16:07:31.000000000 +0000
8393 +++ linux-3.4.83-vs2.3.3.9/include/linux/magic.h        2012-05-21 16:15:05.000000000 +0000
8394 @@ -3,7 +3,7 @@
8395  
8396  #define ADFS_SUPER_MAGIC       0xadf5
8397  #define AFFS_SUPER_MAGIC       0xadff
8398 -#define AFS_SUPER_MAGIC                0x5346414F
8399 +#define AFS_SUPER_MAGIC                0x5346414F
8400  #define AUTOFS_SUPER_MAGIC     0x0187
8401  #define CODA_SUPER_MAGIC       0x73757245
8402  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8403 diff -NurpP --minimal linux-3.4.83/include/linux/major.h linux-3.4.83-vs2.3.3.9/include/linux/major.h
8404 --- linux-3.4.83/include/linux/major.h  2009-09-10 13:26:25.000000000 +0000
8405 +++ linux-3.4.83-vs2.3.3.9/include/linux/major.h        2012-05-21 16:15:05.000000000 +0000
8406 @@ -15,6 +15,7 @@
8407  #define HD_MAJOR               IDE0_MAJOR
8408  #define PTY_SLAVE_MAJOR                3
8409  #define TTY_MAJOR              4
8410 +#define VROOT_MAJOR            4
8411  #define TTYAUX_MAJOR           5
8412  #define LP_MAJOR               6
8413  #define VCS_MAJOR              7
8414 diff -NurpP --minimal linux-3.4.83/include/linux/memcontrol.h linux-3.4.83-vs2.3.3.9/include/linux/memcontrol.h
8415 --- linux-3.4.83/include/linux/memcontrol.h     2012-05-21 16:07:31.000000000 +0000
8416 +++ linux-3.4.83-vs2.3.3.9/include/linux/memcontrol.h   2012-05-21 16:15:05.000000000 +0000
8417 @@ -88,6 +88,13 @@ extern struct mem_cgroup *try_get_mem_cg
8418  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8419  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8420  
8421 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8422 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8423 +
8424 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8425 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8426 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8427 +
8428  static inline
8429  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8430  {
8431 diff -NurpP --minimal linux-3.4.83/include/linux/mm_types.h linux-3.4.83-vs2.3.3.9/include/linux/mm_types.h
8432 --- linux-3.4.83/include/linux/mm_types.h       2014-03-12 09:48:19.000000000 +0000
8433 +++ linux-3.4.83-vs2.3.3.9/include/linux/mm_types.h     2012-07-17 22:29:43.000000000 +0000
8434 @@ -353,6 +353,7 @@ struct mm_struct {
8435  
8436         /* Architecture-specific MM context */
8437         mm_context_t context;
8438 +       struct vx_info *mm_vx_info;
8439  
8440         /* Swap token stuff */
8441         /*
8442 diff -NurpP --minimal linux-3.4.83/include/linux/mmzone.h linux-3.4.83-vs2.3.3.9/include/linux/mmzone.h
8443 --- linux-3.4.83/include/linux/mmzone.h 2014-03-12 09:48:19.000000000 +0000
8444 +++ linux-3.4.83-vs2.3.3.9/include/linux/mmzone.h       2012-07-17 22:29:43.000000000 +0000
8445 @@ -684,6 +684,13 @@ typedef struct pglist_data {
8446         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8447  })
8448  
8449 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8450 +
8451 +#define node_end_pfn(nid) ({\
8452 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8453 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8454 +})
8455 +
8456  #include <linux/memory_hotplug.h>
8457  
8458  extern struct mutex zonelists_mutex;
8459 diff -NurpP --minimal linux-3.4.83/include/linux/mount.h linux-3.4.83-vs2.3.3.9/include/linux/mount.h
8460 --- linux-3.4.83/include/linux/mount.h  2012-03-19 18:47:28.000000000 +0000
8461 +++ linux-3.4.83-vs2.3.3.9/include/linux/mount.h        2012-05-21 16:15:05.000000000 +0000
8462 @@ -47,6 +47,9 @@ struct mnt_namespace;
8463  
8464  #define MNT_INTERNAL   0x4000
8465  
8466 +#define MNT_TAGID      0x10000
8467 +#define MNT_NOTAG      0x20000
8468 +
8469  struct vfsmount {
8470         struct dentry *mnt_root;        /* root of the mounted tree */
8471         struct super_block *mnt_sb;     /* pointer to superblock */
8472 diff -NurpP --minimal linux-3.4.83/include/linux/net.h linux-3.4.83-vs2.3.3.9/include/linux/net.h
8473 --- linux-3.4.83/include/linux/net.h    2014-03-12 09:48:19.000000000 +0000
8474 +++ linux-3.4.83-vs2.3.3.9/include/linux/net.h  2014-03-12 09:55:28.000000000 +0000
8475 @@ -73,6 +73,7 @@ struct net;
8476  #define SOCK_PASSCRED          3
8477  #define SOCK_PASSSEC           4
8478  #define SOCK_EXTERNALLY_ALLOCATED 5
8479 +#define SOCK_USER_SOCKET       6
8480  
8481  #ifndef ARCH_HAS_SOCKET_TYPES
8482  /**
8483 diff -NurpP --minimal linux-3.4.83/include/linux/netdevice.h linux-3.4.83-vs2.3.3.9/include/linux/netdevice.h
8484 --- linux-3.4.83/include/linux/netdevice.h      2014-03-12 09:48:19.000000000 +0000
8485 +++ linux-3.4.83-vs2.3.3.9/include/linux/netdevice.h    2014-03-12 09:55:28.000000000 +0000
8486 @@ -1624,6 +1624,7 @@ extern void               netdev_resync_ops(struct ne
8487  
8488  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8489  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8490 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8491  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8492  extern int             dev_restart(struct net_device *dev);
8493  #ifdef CONFIG_NETPOLL_TRAP
8494 diff -NurpP --minimal linux-3.4.83/include/linux/nfs_mount.h linux-3.4.83-vs2.3.3.9/include/linux/nfs_mount.h
8495 --- linux-3.4.83/include/linux/nfs_mount.h      2011-01-05 20:50:31.000000000 +0000
8496 +++ linux-3.4.83-vs2.3.3.9/include/linux/nfs_mount.h    2012-05-21 16:15:05.000000000 +0000
8497 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8498  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8499  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8500  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8501 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8502 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8503 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8504  
8505  /* The following are for internal use only */
8506  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8507 diff -NurpP --minimal linux-3.4.83/include/linux/nsproxy.h linux-3.4.83-vs2.3.3.9/include/linux/nsproxy.h
8508 --- linux-3.4.83/include/linux/nsproxy.h        2011-10-24 16:45:32.000000000 +0000
8509 +++ linux-3.4.83-vs2.3.3.9/include/linux/nsproxy.h      2012-05-21 16:15:05.000000000 +0000
8510 @@ -3,6 +3,7 @@
8511  
8512  #include <linux/spinlock.h>
8513  #include <linux/sched.h>
8514 +#include <linux/vserver/debug.h>
8515  
8516  struct mnt_namespace;
8517  struct uts_namespace;
8518 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8519  }
8520  
8521  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8522 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8523  void exit_task_namespaces(struct task_struct *tsk);
8524  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8525  void free_nsproxy(struct nsproxy *ns);
8526 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
8527         struct fs_struct *);
8528  int __init nsproxy_cache_init(void);
8529  
8530 -static inline void put_nsproxy(struct nsproxy *ns)
8531 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8532 +
8533 +static inline void __get_nsproxy(struct nsproxy *ns,
8534 +       const char *_file, int _line)
8535  {
8536 -       if (atomic_dec_and_test(&ns->count)) {
8537 -               free_nsproxy(ns);
8538 -       }
8539 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8540 +               ns, atomic_read(&ns->count), _file, _line);
8541 +       atomic_inc(&ns->count);
8542  }
8543  
8544 -static inline void get_nsproxy(struct nsproxy *ns)
8545 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8546 +
8547 +static inline void __put_nsproxy(struct nsproxy *ns,
8548 +       const char *_file, int _line)
8549  {
8550 -       atomic_inc(&ns->count);
8551 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8552 +               ns, atomic_read(&ns->count), _file, _line);
8553 +       if (atomic_dec_and_test(&ns->count)) {
8554 +               free_nsproxy(ns);
8555 +       }
8556  }
8557  
8558  #endif
8559 diff -NurpP --minimal linux-3.4.83/include/linux/pid.h linux-3.4.83-vs2.3.3.9/include/linux/pid.h
8560 --- linux-3.4.83/include/linux/pid.h    2011-07-22 09:18:11.000000000 +0000
8561 +++ linux-3.4.83-vs2.3.3.9/include/linux/pid.h  2012-05-21 16:15:05.000000000 +0000
8562 @@ -8,7 +8,8 @@ enum pid_type
8563         PIDTYPE_PID,
8564         PIDTYPE_PGID,
8565         PIDTYPE_SID,
8566 -       PIDTYPE_MAX
8567 +       PIDTYPE_MAX,
8568 +       PIDTYPE_REALPID
8569  };
8570  
8571  /*
8572 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8573  }
8574  
8575  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8576 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8577  pid_t pid_vnr(struct pid *pid);
8578  
8579  #define do_each_pid_task(pid, type, task)                              \
8580 diff -NurpP --minimal linux-3.4.83/include/linux/proc_fs.h linux-3.4.83-vs2.3.3.9/include/linux/proc_fs.h
8581 --- linux-3.4.83/include/linux/proc_fs.h        2012-03-19 18:47:28.000000000 +0000
8582 +++ linux-3.4.83-vs2.3.3.9/include/linux/proc_fs.h      2012-05-21 16:15:05.000000000 +0000
8583 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8584         nlink_t nlink;
8585         uid_t uid;
8586         gid_t gid;
8587 +       int vx_flags;
8588         loff_t size;
8589         const struct inode_operations *proc_iops;
8590         /*
8591 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8592  extern const struct proc_ns_operations utsns_operations;
8593  extern const struct proc_ns_operations ipcns_operations;
8594  
8595 +struct vx_info;
8596 +struct nx_info;
8597 +
8598  union proc_op {
8599         int (*proc_get_link)(struct dentry *, struct path *);
8600         int (*proc_read)(struct task_struct *task, char *page);
8601         int (*proc_show)(struct seq_file *m,
8602                 struct pid_namespace *ns, struct pid *pid,
8603                 struct task_struct *task);
8604 +       int (*proc_vs_read)(char *page);
8605 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8606 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8607  };
8608  
8609  struct ctl_table_header;
8610 @@ -265,6 +272,7 @@ struct ctl_table;
8611  
8612  struct proc_inode {
8613         struct pid *pid;
8614 +       int vx_flags;
8615         int fd;
8616         union proc_op op;
8617         struct proc_dir_entry *pde;
8618 diff -NurpP --minimal linux-3.4.83/include/linux/quotaops.h linux-3.4.83-vs2.3.3.9/include/linux/quotaops.h
8619 --- linux-3.4.83/include/linux/quotaops.h       2012-01-09 15:14:58.000000000 +0000
8620 +++ linux-3.4.83-vs2.3.3.9/include/linux/quotaops.h     2012-05-21 16:15:05.000000000 +0000
8621 @@ -8,6 +8,7 @@
8622  #define _LINUX_QUOTAOPS_
8623  
8624  #include <linux/fs.h>
8625 +#include <linux/vs_dlimit.h>
8626  
8627  #define DQUOT_SPACE_WARN       0x1
8628  #define DQUOT_SPACE_RESERVE    0x2
8629 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8630  
8631  static inline int dquot_alloc_inode(const struct inode *inode)
8632  {
8633 -       return 0;
8634 +       return dl_alloc_inode(inode);
8635  }
8636  
8637  static inline void dquot_free_inode(const struct inode *inode)
8638  {
8639 +       dl_free_inode(inode);
8640  }
8641  
8642  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8643 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct
8644  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8645                 int flags)
8646  {
8647 +       int ret = 0;
8648 +
8649 +       if ((ret = dl_alloc_space(inode, number)))
8650 +               return ret;
8651         if (!(flags & DQUOT_SPACE_RESERVE))
8652                 inode_add_bytes(inode, number);
8653         return 0;
8654 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8655  {
8656         if (!(flags & DQUOT_SPACE_RESERVE))
8657                 inode_sub_bytes(inode, number);
8658 +       dl_free_space(inode, number);
8659  }
8660  
8661  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8662 diff -NurpP --minimal linux-3.4.83/include/linux/reboot.h linux-3.4.83-vs2.3.3.9/include/linux/reboot.h
8663 --- linux-3.4.83/include/linux/reboot.h 2011-10-24 16:45:32.000000000 +0000
8664 +++ linux-3.4.83-vs2.3.3.9/include/linux/reboot.h       2012-05-21 16:15:05.000000000 +0000
8665 @@ -33,6 +33,7 @@
8666  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8667  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8668  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8669 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8670  
8671  
8672  #ifdef __KERNEL__
8673 diff -NurpP --minimal linux-3.4.83/include/linux/sched.h linux-3.4.83-vs2.3.3.9/include/linux/sched.h
8674 --- linux-3.4.83/include/linux/sched.h  2014-03-12 09:48:20.000000000 +0000
8675 +++ linux-3.4.83-vs2.3.3.9/include/linux/sched.h        2014-03-12 09:55:28.000000000 +0000
8676 @@ -1461,6 +1461,14 @@ struct task_struct {
8677  #endif
8678         seccomp_t seccomp;
8679  
8680 +/* vserver context data */
8681 +       struct vx_info *vx_info;
8682 +       struct nx_info *nx_info;
8683 +
8684 +       xid_t xid;
8685 +       nid_t nid;
8686 +       tag_t tag;
8687 +
8688  /* Thread group tracking */
8689         u32 parent_exec_id;
8690         u32 self_exec_id;
8691 @@ -1705,6 +1713,11 @@ struct pid_namespace;
8692  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8693                         struct pid_namespace *ns);
8694  
8695 +#include <linux/vserver/base.h>
8696 +#include <linux/vserver/context.h>
8697 +#include <linux/vserver/debug.h>
8698 +#include <linux/vserver/pid.h>
8699 +
8700  static inline pid_t task_pid_nr(struct task_struct *tsk)
8701  {
8702         return tsk->pid;
8703 @@ -1718,7 +1731,8 @@ static inline pid_t task_pid_nr_ns(struc
8704  
8705  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8706  {
8707 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8708 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8709 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8710  }
8711  
8712  
8713 @@ -1731,7 +1745,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8714  
8715  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8716  {
8717 -       return pid_vnr(task_tgid(tsk));
8718 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8719  }
8720  
8721  
8722 diff -NurpP --minimal linux-3.4.83/include/linux/shmem_fs.h linux-3.4.83-vs2.3.3.9/include/linux/shmem_fs.h
8723 --- linux-3.4.83/include/linux/shmem_fs.h       2012-03-19 18:47:29.000000000 +0000
8724 +++ linux-3.4.83-vs2.3.3.9/include/linux/shmem_fs.h     2012-05-21 16:15:05.000000000 +0000
8725 @@ -8,6 +8,9 @@
8726  
8727  /* inode in-kernel data */
8728  
8729 +#define TMPFS_SUPER_MAGIC      0x01021994
8730 +
8731 +
8732  struct shmem_inode_info {
8733         spinlock_t              lock;
8734         unsigned long           flags;
8735 diff -NurpP --minimal linux-3.4.83/include/linux/stat.h linux-3.4.83-vs2.3.3.9/include/linux/stat.h
8736 --- linux-3.4.83/include/linux/stat.h   2008-12-24 23:26:37.000000000 +0000
8737 +++ linux-3.4.83-vs2.3.3.9/include/linux/stat.h 2012-05-21 16:15:05.000000000 +0000
8738 @@ -66,6 +66,7 @@ struct kstat {
8739         unsigned int    nlink;
8740         uid_t           uid;
8741         gid_t           gid;
8742 +       tag_t           tag;
8743         dev_t           rdev;
8744         loff_t          size;
8745         struct timespec  atime;
8746 diff -NurpP --minimal linux-3.4.83/include/linux/sunrpc/auth.h linux-3.4.83-vs2.3.3.9/include/linux/sunrpc/auth.h
8747 --- linux-3.4.83/include/linux/sunrpc/auth.h    2012-05-21 16:07:32.000000000 +0000
8748 +++ linux-3.4.83-vs2.3.3.9/include/linux/sunrpc/auth.h  2012-05-21 16:15:05.000000000 +0000
8749 @@ -25,6 +25,7 @@
8750  struct auth_cred {
8751         uid_t   uid;
8752         gid_t   gid;
8753 +       tag_t   tag;
8754         struct group_info *group_info;
8755         const char *principal;
8756         unsigned char machine_cred : 1;
8757 diff -NurpP --minimal linux-3.4.83/include/linux/sunrpc/clnt.h linux-3.4.83-vs2.3.3.9/include/linux/sunrpc/clnt.h
8758 --- linux-3.4.83/include/linux/sunrpc/clnt.h    2012-05-21 16:07:32.000000000 +0000
8759 +++ linux-3.4.83-vs2.3.3.9/include/linux/sunrpc/clnt.h  2012-05-21 16:15:05.000000000 +0000
8760 @@ -49,7 +49,8 @@ struct rpc_clnt {
8761         unsigned int            cl_softrtry : 1,/* soft timeouts */
8762                                 cl_discrtry : 1,/* disconnect before retry */
8763                                 cl_autobind : 1,/* use getport() */
8764 -                               cl_chatty   : 1;/* be verbose */
8765 +                               cl_chatty   : 1,/* be verbose */
8766 +                               cl_tag      : 1;/* context tagging */
8767  
8768         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8769         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8770 diff -NurpP --minimal linux-3.4.83/include/linux/sysctl.h linux-3.4.83-vs2.3.3.9/include/linux/sysctl.h
8771 --- linux-3.4.83/include/linux/sysctl.h 2012-05-21 16:07:32.000000000 +0000
8772 +++ linux-3.4.83-vs2.3.3.9/include/linux/sysctl.h       2012-05-21 16:15:05.000000000 +0000
8773 @@ -60,6 +60,7 @@ enum
8774         CTL_ABI=9,              /* Binary emulation */
8775         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8776         CTL_ARLAN=254,          /* arlan wireless driver */
8777 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8778         CTL_S390DBF=5677,       /* s390 debug */
8779         CTL_SUNRPC=7249,        /* sunrpc debug */
8780         CTL_PM=9899,            /* frv power management */
8781 @@ -94,6 +95,7 @@ enum
8782  
8783         KERN_PANIC=15,          /* int: panic timeout */
8784         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8785 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8786  
8787         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8788         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8789 diff -NurpP --minimal linux-3.4.83/include/linux/sysfs.h linux-3.4.83-vs2.3.3.9/include/linux/sysfs.h
8790 --- linux-3.4.83/include/linux/sysfs.h  2012-03-19 18:47:29.000000000 +0000
8791 +++ linux-3.4.83-vs2.3.3.9/include/linux/sysfs.h        2012-05-21 16:15:05.000000000 +0000
8792 @@ -19,6 +19,8 @@
8793  #include <linux/kobject_ns.h>
8794  #include <linux/atomic.h>
8795  
8796 +#define SYSFS_SUPER_MAGIC      0x62656572
8797 +
8798  struct kobject;
8799  struct module;
8800  enum kobj_ns_type;
8801 diff -NurpP --minimal linux-3.4.83/include/linux/time.h linux-3.4.83-vs2.3.3.9/include/linux/time.h
8802 --- linux-3.4.83/include/linux/time.h   2014-03-12 09:48:20.000000000 +0000
8803 +++ linux-3.4.83-vs2.3.3.9/include/linux/time.h 2012-10-22 13:09:53.000000000 +0000
8804 @@ -281,6 +281,8 @@ static __always_inline void timespec_add
8805         a->tv_nsec = ns;
8806  }
8807  
8808 +#include <linux/vs_time.h>
8809 +
8810  #endif /* __KERNEL__ */
8811  
8812  /*
8813 diff -NurpP --minimal linux-3.4.83/include/linux/types.h linux-3.4.83-vs2.3.3.9/include/linux/types.h
8814 --- linux-3.4.83/include/linux/types.h  2012-05-21 16:07:32.000000000 +0000
8815 +++ linux-3.4.83-vs2.3.3.9/include/linux/types.h        2012-05-21 16:15:05.000000000 +0000
8816 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8817  typedef __kernel_gid32_t       gid_t;
8818  typedef __kernel_uid16_t        uid16_t;
8819  typedef __kernel_gid16_t        gid16_t;
8820 +typedef unsigned int           xid_t;
8821 +typedef unsigned int           nid_t;
8822 +typedef unsigned int           tag_t;
8823  
8824  typedef unsigned long          uintptr_t;
8825  
8826 diff -NurpP --minimal linux-3.4.83/include/linux/utsname.h linux-3.4.83-vs2.3.3.9/include/linux/utsname.h
8827 --- linux-3.4.83/include/linux/utsname.h        2012-01-09 15:14:59.000000000 +0000
8828 +++ linux-3.4.83-vs2.3.3.9/include/linux/utsname.h      2012-05-21 16:15:05.000000000 +0000
8829 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8830  }
8831  
8832  extern struct uts_namespace *copy_utsname(unsigned long flags,
8833 -                                         struct task_struct *tsk);
8834 +                                         struct uts_namespace *old_ns,
8835 +                                         struct user_namespace *user_ns);
8836  extern void free_uts_ns(struct kref *kref);
8837  
8838  static inline void put_uts_ns(struct uts_namespace *ns)
8839 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8840  }
8841  
8842  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8843 -                                                struct task_struct *tsk)
8844 +                                                struct uts_namespace *old_ns,
8845 +                                                struct user_namespace *user_ns)
8846  {
8847         if (flags & CLONE_NEWUTS)
8848                 return ERR_PTR(-EINVAL);
8849  
8850 -       return tsk->nsproxy->uts_ns;
8851 +       return old_ns;
8852  }
8853  #endif
8854  
8855 diff -NurpP --minimal linux-3.4.83/include/linux/vroot.h linux-3.4.83-vs2.3.3.9/include/linux/vroot.h
8856 --- linux-3.4.83/include/linux/vroot.h  1970-01-01 00:00:00.000000000 +0000
8857 +++ linux-3.4.83-vs2.3.3.9/include/linux/vroot.h        2012-05-21 16:15:05.000000000 +0000
8858 @@ -0,0 +1,51 @@
8859 +
8860 +/*
8861 + * include/linux/vroot.h
8862 + *
8863 + * written by Herbert Pötzl, 9/11/2002
8864 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8865 + *
8866 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8867 + * Redistribution of this file is permitted under the
8868 + * GNU General Public License.
8869 + */
8870 +
8871 +#ifndef _LINUX_VROOT_H
8872 +#define _LINUX_VROOT_H
8873 +
8874 +
8875 +#ifdef __KERNEL__
8876 +
8877 +/* Possible states of device */
8878 +enum {
8879 +       Vr_unbound,
8880 +       Vr_bound,
8881 +};
8882 +
8883 +struct vroot_device {
8884 +       int             vr_number;
8885 +       int             vr_refcnt;
8886 +
8887 +       struct semaphore        vr_ctl_mutex;
8888 +       struct block_device    *vr_device;
8889 +       int                     vr_state;
8890 +};
8891 +
8892 +
8893 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8894 +
8895 +extern int register_vroot_grb(vroot_grb_func *);
8896 +extern int unregister_vroot_grb(vroot_grb_func *);
8897 +
8898 +#endif /* __KERNEL__ */
8899 +
8900 +#define MAX_VROOT_DEFAULT      8
8901 +
8902 +/*
8903 + * IOCTL commands --- we will commandeer 0x56 ('V')
8904 + */
8905 +
8906 +#define VROOT_SET_DEV          0x5600
8907 +#define VROOT_CLR_DEV          0x5601
8908 +
8909 +#endif /* _LINUX_VROOT_H */
8910 diff -NurpP --minimal linux-3.4.83/include/linux/vs_base.h linux-3.4.83-vs2.3.3.9/include/linux/vs_base.h
8911 --- linux-3.4.83/include/linux/vs_base.h        1970-01-01 00:00:00.000000000 +0000
8912 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_base.h      2012-05-21 16:15:05.000000000 +0000
8913 @@ -0,0 +1,10 @@
8914 +#ifndef _VS_BASE_H
8915 +#define _VS_BASE_H
8916 +
8917 +#include "vserver/base.h"
8918 +#include "vserver/check.h"
8919 +#include "vserver/debug.h"
8920 +
8921 +#else
8922 +#warning duplicate inclusion
8923 +#endif
8924 diff -NurpP --minimal linux-3.4.83/include/linux/vs_context.h linux-3.4.83-vs2.3.3.9/include/linux/vs_context.h
8925 --- linux-3.4.83/include/linux/vs_context.h     1970-01-01 00:00:00.000000000 +0000
8926 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_context.h   2012-05-21 16:15:05.000000000 +0000
8927 @@ -0,0 +1,242 @@
8928 +#ifndef _VS_CONTEXT_H
8929 +#define _VS_CONTEXT_H
8930 +
8931 +#include "vserver/base.h"
8932 +#include "vserver/check.h"
8933 +#include "vserver/context.h"
8934 +#include "vserver/history.h"
8935 +#include "vserver/debug.h"
8936 +
8937 +#include <linux/sched.h>
8938 +
8939 +
8940 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8941 +
8942 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8943 +       const char *_file, int _line, void *_here)
8944 +{
8945 +       if (!vxi)
8946 +               return NULL;
8947 +
8948 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8949 +               vxi, vxi ? vxi->vx_id : 0,
8950 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8951 +               _file, _line);
8952 +       __vxh_get_vx_info(vxi, _here);
8953 +
8954 +       atomic_inc(&vxi->vx_usecnt);
8955 +       return vxi;
8956 +}
8957 +
8958 +
8959 +extern void free_vx_info(struct vx_info *);
8960 +
8961 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8962 +
8963 +static inline void __put_vx_info(struct vx_info *vxi,
8964 +       const char *_file, int _line, void *_here)
8965 +{
8966 +       if (!vxi)
8967 +               return;
8968 +
8969 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8970 +               vxi, vxi ? vxi->vx_id : 0,
8971 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8972 +               _file, _line);
8973 +       __vxh_put_vx_info(vxi, _here);
8974 +
8975 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8976 +               free_vx_info(vxi);
8977 +}
8978 +
8979 +
8980 +#define init_vx_info(p, i) \
8981 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8982 +
8983 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8984 +       const char *_file, int _line, void *_here)
8985 +{
8986 +       if (vxi) {
8987 +               vxlprintk(VXD_CBIT(xid, 3),
8988 +                       "init_vx_info(%p[#%d.%d])",
8989 +                       vxi, vxi ? vxi->vx_id : 0,
8990 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8991 +                       _file, _line);
8992 +               __vxh_init_vx_info(vxi, vxp, _here);
8993 +
8994 +               atomic_inc(&vxi->vx_usecnt);
8995 +       }
8996 +       *vxp = vxi;
8997 +}
8998 +
8999 +
9000 +#define set_vx_info(p, i) \
9001 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9002 +
9003 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9004 +       const char *_file, int _line, void *_here)
9005 +{
9006 +       struct vx_info *vxo;
9007 +
9008 +       if (!vxi)
9009 +               return;
9010 +
9011 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9012 +               vxi, vxi ? vxi->vx_id : 0,
9013 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9014 +               _file, _line);
9015 +       __vxh_set_vx_info(vxi, vxp, _here);
9016 +
9017 +       atomic_inc(&vxi->vx_usecnt);
9018 +       vxo = xchg(vxp, vxi);
9019 +       BUG_ON(vxo);
9020 +}
9021 +
9022 +
9023 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9024 +
9025 +static inline void __clr_vx_info(struct vx_info **vxp,
9026 +       const char *_file, int _line, void *_here)
9027 +{
9028 +       struct vx_info *vxo;
9029 +
9030 +       vxo = xchg(vxp, NULL);
9031 +       if (!vxo)
9032 +               return;
9033 +
9034 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9035 +               vxo, vxo ? vxo->vx_id : 0,
9036 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9037 +               _file, _line);
9038 +       __vxh_clr_vx_info(vxo, vxp, _here);
9039 +
9040 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9041 +               free_vx_info(vxo);
9042 +}
9043 +
9044 +
9045 +#define claim_vx_info(v, p) \
9046 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9047 +
9048 +static inline void __claim_vx_info(struct vx_info *vxi,
9049 +       struct task_struct *task,
9050 +       const char *_file, int _line, void *_here)
9051 +{
9052 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9053 +               vxi, vxi ? vxi->vx_id : 0,
9054 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9055 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9056 +               task, _file, _line);
9057 +       __vxh_claim_vx_info(vxi, task, _here);
9058 +
9059 +       atomic_inc(&vxi->vx_tasks);
9060 +}
9061 +
9062 +
9063 +extern void unhash_vx_info(struct vx_info *);
9064 +
9065 +#define release_vx_info(v, p) \
9066 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9067 +
9068 +static inline void __release_vx_info(struct vx_info *vxi,
9069 +       struct task_struct *task,
9070 +       const char *_file, int _line, void *_here)
9071 +{
9072 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9073 +               vxi, vxi ? vxi->vx_id : 0,
9074 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9075 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9076 +               task, _file, _line);
9077 +       __vxh_release_vx_info(vxi, task, _here);
9078 +
9079 +       might_sleep();
9080 +
9081 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9082 +               unhash_vx_info(vxi);
9083 +}
9084 +
9085 +
9086 +#define task_get_vx_info(p) \
9087 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9088 +
9089 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9090 +       const char *_file, int _line, void *_here)
9091 +{
9092 +       struct vx_info *vxi;
9093 +
9094 +       task_lock(p);
9095 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9096 +               p, _file, _line);
9097 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9098 +       task_unlock(p);
9099 +       return vxi;
9100 +}
9101 +
9102 +
9103 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9104 +{
9105 +       if (waitqueue_active(&vxi->vx_wait))
9106 +               wake_up_interruptible(&vxi->vx_wait);
9107 +}
9108 +
9109 +
9110 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9111 +
9112 +static inline void __enter_vx_info(struct vx_info *vxi,
9113 +       struct vx_info_save *vxis, const char *_file, int _line)
9114 +{
9115 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9116 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9117 +               current->xid, current->vx_info, _file, _line);
9118 +       vxis->vxi = xchg(&current->vx_info, vxi);
9119 +       vxis->xid = current->xid;
9120 +       current->xid = vxi ? vxi->vx_id : 0;
9121 +}
9122 +
9123 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9124 +
9125 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9126 +       const char *_file, int _line)
9127 +{
9128 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9129 +               vxis, vxis->xid, vxis->vxi, current,
9130 +               current->xid, current->vx_info, _file, _line);
9131 +       (void)xchg(&current->vx_info, vxis->vxi);
9132 +       current->xid = vxis->xid;
9133 +}
9134 +
9135 +
9136 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9137 +{
9138 +       vxis->vxi = xchg(&current->vx_info, NULL);
9139 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9140 +}
9141 +
9142 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9143 +{
9144 +       (void)xchg(&current->xid, vxis->xid);
9145 +       (void)xchg(&current->vx_info, vxis->vxi);
9146 +}
9147 +
9148 +#define task_is_init(p) \
9149 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9150 +
9151 +static inline int __task_is_init(struct task_struct *p,
9152 +       const char *_file, int _line, void *_here)
9153 +{
9154 +       int is_init = is_global_init(p);
9155 +
9156 +       task_lock(p);
9157 +       if (p->vx_info)
9158 +               is_init = p->vx_info->vx_initpid == p->pid;
9159 +       task_unlock(p);
9160 +       return is_init;
9161 +}
9162 +
9163 +extern void exit_vx_info(struct task_struct *, int);
9164 +extern void exit_vx_info_early(struct task_struct *, int);
9165 +
9166 +
9167 +#else
9168 +#warning duplicate inclusion
9169 +#endif
9170 diff -NurpP --minimal linux-3.4.83/include/linux/vs_cowbl.h linux-3.4.83-vs2.3.3.9/include/linux/vs_cowbl.h
9171 --- linux-3.4.83/include/linux/vs_cowbl.h       1970-01-01 00:00:00.000000000 +0000
9172 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_cowbl.h     2012-05-21 16:15:05.000000000 +0000
9173 @@ -0,0 +1,48 @@
9174 +#ifndef _VS_COWBL_H
9175 +#define _VS_COWBL_H
9176 +
9177 +#include <linux/fs.h>
9178 +#include <linux/dcache.h>
9179 +#include <linux/namei.h>
9180 +#include <linux/slab.h>
9181 +
9182 +extern struct dentry *cow_break_link(const char *pathname);
9183 +
9184 +static inline int cow_check_and_break(struct path *path)
9185 +{
9186 +       struct inode *inode = path->dentry->d_inode;
9187 +       int error = 0;
9188 +
9189 +       /* do we need this check? */
9190 +       if (IS_RDONLY(inode))
9191 +               return -EROFS;
9192 +
9193 +       if (IS_COW(inode)) {
9194 +               if (IS_COW_LINK(inode)) {
9195 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9196 +                       char *pp, *buf;
9197 +
9198 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9199 +                       if (!buf) {
9200 +                               return -ENOMEM;
9201 +                       }
9202 +                       pp = d_path(path, buf, PATH_MAX);
9203 +                       new_dentry = cow_break_link(pp);
9204 +                       kfree(buf);
9205 +                       if (!IS_ERR(new_dentry)) {
9206 +                               path->dentry = new_dentry;
9207 +                               dput(old_dentry);
9208 +                       } else
9209 +                               error = PTR_ERR(new_dentry);
9210 +               } else {
9211 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9212 +                       inode->i_ctime = CURRENT_TIME;
9213 +                       mark_inode_dirty(inode);
9214 +               }
9215 +       }
9216 +       return error;
9217 +}
9218 +
9219 +#else
9220 +#warning duplicate inclusion
9221 +#endif
9222 diff -NurpP --minimal linux-3.4.83/include/linux/vs_cvirt.h linux-3.4.83-vs2.3.3.9/include/linux/vs_cvirt.h
9223 --- linux-3.4.83/include/linux/vs_cvirt.h       1970-01-01 00:00:00.000000000 +0000
9224 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_cvirt.h     2012-05-21 16:15:05.000000000 +0000
9225 @@ -0,0 +1,50 @@
9226 +#ifndef _VS_CVIRT_H
9227 +#define _VS_CVIRT_H
9228 +
9229 +#include "vserver/cvirt.h"
9230 +#include "vserver/context.h"
9231 +#include "vserver/base.h"
9232 +#include "vserver/check.h"
9233 +#include "vserver/debug.h"
9234 +
9235 +
9236 +static inline void vx_activate_task(struct task_struct *p)
9237 +{
9238 +       struct vx_info *vxi;
9239 +
9240 +       if ((vxi = p->vx_info)) {
9241 +               vx_update_load(vxi);
9242 +               atomic_inc(&vxi->cvirt.nr_running);
9243 +       }
9244 +}
9245 +
9246 +static inline void vx_deactivate_task(struct task_struct *p)
9247 +{
9248 +       struct vx_info *vxi;
9249 +
9250 +       if ((vxi = p->vx_info)) {
9251 +               vx_update_load(vxi);
9252 +               atomic_dec(&vxi->cvirt.nr_running);
9253 +       }
9254 +}
9255 +
9256 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9257 +{
9258 +       struct vx_info *vxi;
9259 +
9260 +       if ((vxi = p->vx_info))
9261 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9262 +}
9263 +
9264 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9265 +{
9266 +       struct vx_info *vxi;
9267 +
9268 +       if ((vxi = p->vx_info))
9269 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9270 +}
9271 +
9272 +
9273 +#else
9274 +#warning duplicate inclusion
9275 +#endif
9276 diff -NurpP --minimal linux-3.4.83/include/linux/vs_device.h linux-3.4.83-vs2.3.3.9/include/linux/vs_device.h
9277 --- linux-3.4.83/include/linux/vs_device.h      1970-01-01 00:00:00.000000000 +0000
9278 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_device.h    2012-05-21 16:15:05.000000000 +0000
9279 @@ -0,0 +1,45 @@
9280 +#ifndef _VS_DEVICE_H
9281 +#define _VS_DEVICE_H
9282 +
9283 +#include "vserver/base.h"
9284 +#include "vserver/device.h"
9285 +#include "vserver/debug.h"
9286 +
9287 +
9288 +#ifdef CONFIG_VSERVER_DEVICE
9289 +
9290 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9291 +
9292 +#define vs_device_perm(v, d, m, p) \
9293 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9294 +
9295 +#else
9296 +
9297 +static inline
9298 +int vs_map_device(struct vx_info *vxi,
9299 +       dev_t device, dev_t *target, umode_t mode)
9300 +{
9301 +       if (target)
9302 +               *target = device;
9303 +       return ~0;
9304 +}
9305 +
9306 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9307 +
9308 +#endif
9309 +
9310 +
9311 +#define vs_map_chrdev(d, t, p) \
9312 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9313 +#define vs_map_blkdev(d, t, p) \
9314 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9315 +
9316 +#define vs_chrdev_perm(d, p) \
9317 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9318 +#define vs_blkdev_perm(d, p) \
9319 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9320 +
9321 +
9322 +#else
9323 +#warning duplicate inclusion
9324 +#endif
9325 diff -NurpP --minimal linux-3.4.83/include/linux/vs_dlimit.h linux-3.4.83-vs2.3.3.9/include/linux/vs_dlimit.h
9326 --- linux-3.4.83/include/linux/vs_dlimit.h      1970-01-01 00:00:00.000000000 +0000
9327 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_dlimit.h    2012-05-21 16:15:05.000000000 +0000
9328 @@ -0,0 +1,215 @@
9329 +#ifndef _VS_DLIMIT_H
9330 +#define _VS_DLIMIT_H
9331 +
9332 +#include <linux/fs.h>
9333 +
9334 +#include "vserver/dlimit.h"
9335 +#include "vserver/base.h"
9336 +#include "vserver/debug.h"
9337 +
9338 +
9339 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9340 +
9341 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9342 +       const char *_file, int _line)
9343 +{
9344 +       if (!dli)
9345 +               return NULL;
9346 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9347 +               dli, dli ? dli->dl_tag : 0,
9348 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9349 +               _file, _line);
9350 +       atomic_inc(&dli->dl_usecnt);
9351 +       return dli;
9352 +}
9353 +
9354 +
9355 +#define free_dl_info(i) \
9356 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9357 +
9358 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9359 +
9360 +static inline void __put_dl_info(struct dl_info *dli,
9361 +       const char *_file, int _line)
9362 +{
9363 +       if (!dli)
9364 +               return;
9365 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9366 +               dli, dli ? dli->dl_tag : 0,
9367 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9368 +               _file, _line);
9369 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9370 +               free_dl_info(dli);
9371 +}
9372 +
9373 +
9374 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9375 +
9376 +static inline int __dl_alloc_space(struct super_block *sb,
9377 +       tag_t tag, dlsize_t nr, const char *file, int line)
9378 +{
9379 +       struct dl_info *dli = NULL;
9380 +       int ret = 0;
9381 +
9382 +       if (nr == 0)
9383 +               goto out;
9384 +       dli = locate_dl_info(sb, tag);
9385 +       if (!dli)
9386 +               goto out;
9387 +
9388 +       spin_lock(&dli->dl_lock);
9389 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9390 +       if (!ret)
9391 +               dli->dl_space_used += nr;
9392 +       spin_unlock(&dli->dl_lock);
9393 +       put_dl_info(dli);
9394 +out:
9395 +       vxlprintk(VXD_CBIT(dlim, 1),
9396 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9397 +               sb, tag, __dlimit_char(dli), (long long)nr,
9398 +               ret, file, line);
9399 +       return ret ? -ENOSPC : 0;
9400 +}
9401 +
9402 +static inline void __dl_free_space(struct super_block *sb,
9403 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9404 +{
9405 +       struct dl_info *dli = NULL;
9406 +
9407 +       if (nr == 0)
9408 +               goto out;
9409 +       dli = locate_dl_info(sb, tag);
9410 +       if (!dli)
9411 +               goto out;
9412 +
9413 +       spin_lock(&dli->dl_lock);
9414 +       if (dli->dl_space_used > nr)
9415 +               dli->dl_space_used -= nr;
9416 +       else
9417 +               dli->dl_space_used = 0;
9418 +       spin_unlock(&dli->dl_lock);
9419 +       put_dl_info(dli);
9420 +out:
9421 +       vxlprintk(VXD_CBIT(dlim, 1),
9422 +               "FREE  (%p,#%d)%c %lld bytes",
9423 +               sb, tag, __dlimit_char(dli), (long long)nr,
9424 +               _file, _line);
9425 +}
9426 +
9427 +static inline int __dl_alloc_inode(struct super_block *sb,
9428 +       tag_t tag, const char *_file, int _line)
9429 +{
9430 +       struct dl_info *dli;
9431 +       int ret = 0;
9432 +
9433 +       dli = locate_dl_info(sb, tag);
9434 +       if (!dli)
9435 +               goto out;
9436 +
9437 +       spin_lock(&dli->dl_lock);
9438 +       dli->dl_inodes_used++;
9439 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9440 +       spin_unlock(&dli->dl_lock);
9441 +       put_dl_info(dli);
9442 +out:
9443 +       vxlprintk(VXD_CBIT(dlim, 0),
9444 +               "ALLOC (%p,#%d)%c inode (%d)",
9445 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9446 +       return ret ? -ENOSPC : 0;
9447 +}
9448 +
9449 +static inline void __dl_free_inode(struct super_block *sb,
9450 +       tag_t tag, const char *_file, int _line)
9451 +{
9452 +       struct dl_info *dli;
9453 +
9454 +       dli = locate_dl_info(sb, tag);
9455 +       if (!dli)
9456 +               goto out;
9457 +
9458 +       spin_lock(&dli->dl_lock);
9459 +       if (dli->dl_inodes_used > 1)
9460 +               dli->dl_inodes_used--;
9461 +       else
9462 +               dli->dl_inodes_used = 0;
9463 +       spin_unlock(&dli->dl_lock);
9464 +       put_dl_info(dli);
9465 +out:
9466 +       vxlprintk(VXD_CBIT(dlim, 0),
9467 +               "FREE  (%p,#%d)%c inode",
9468 +               sb, tag, __dlimit_char(dli), _file, _line);
9469 +}
9470 +
9471 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9472 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9473 +       const char *_file, int _line)
9474 +{
9475 +       struct dl_info *dli;
9476 +       uint64_t broot, bfree;
9477 +
9478 +       dli = locate_dl_info(sb, tag);
9479 +       if (!dli)
9480 +               return;
9481 +
9482 +       spin_lock(&dli->dl_lock);
9483 +       broot = (dli->dl_space_total -
9484 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9485 +               >> sb->s_blocksize_bits;
9486 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9487 +                       >> sb->s_blocksize_bits;
9488 +       spin_unlock(&dli->dl_lock);
9489 +
9490 +       vxlprintk(VXD_CBIT(dlim, 2),
9491 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9492 +               (long long)bfree, (long long)broot,
9493 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9494 +               _file, _line);
9495 +       if (free_blocks) {
9496 +               if (*free_blocks > bfree)
9497 +                       *free_blocks = bfree;
9498 +       }
9499 +       if (root_blocks) {
9500 +               if (*root_blocks > broot)
9501 +                       *root_blocks = broot;
9502 +       }
9503 +       put_dl_info(dli);
9504 +}
9505 +
9506 +#define dl_prealloc_space(in, bytes) \
9507 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9508 +               __FILE__, __LINE__ )
9509 +
9510 +#define dl_alloc_space(in, bytes) \
9511 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9512 +               __FILE__, __LINE__ )
9513 +
9514 +#define dl_reserve_space(in, bytes) \
9515 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9516 +               __FILE__, __LINE__ )
9517 +
9518 +#define dl_claim_space(in, bytes) (0)
9519 +
9520 +#define dl_release_space(in, bytes) \
9521 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9522 +               __FILE__, __LINE__ )
9523 +
9524 +#define dl_free_space(in, bytes) \
9525 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9526 +               __FILE__, __LINE__ )
9527 +
9528 +
9529 +
9530 +#define dl_alloc_inode(in) \
9531 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9532 +
9533 +#define dl_free_inode(in) \
9534 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9535 +
9536 +
9537 +#define dl_adjust_block(sb, tag, fb, rb) \
9538 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9539 +
9540 +
9541 +#else
9542 +#warning duplicate inclusion
9543 +#endif
9544 diff -NurpP --minimal linux-3.4.83/include/linux/vs_inet.h linux-3.4.83-vs2.3.3.9/include/linux/vs_inet.h
9545 --- linux-3.4.83/include/linux/vs_inet.h        1970-01-01 00:00:00.000000000 +0000
9546 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_inet.h      2012-05-21 16:15:05.000000000 +0000
9547 @@ -0,0 +1,353 @@
9548 +#ifndef _VS_INET_H
9549 +#define _VS_INET_H
9550 +
9551 +#include "vserver/base.h"
9552 +#include "vserver/network.h"
9553 +#include "vserver/debug.h"
9554 +
9555 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9556 +
9557 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9558 +                       NIPQUAD((a)->mask), (a)->type
9559 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9560 +
9561 +#define NIPQUAD(addr) \
9562 +       ((unsigned char *)&addr)[0], \
9563 +       ((unsigned char *)&addr)[1], \
9564 +       ((unsigned char *)&addr)[2], \
9565 +       ((unsigned char *)&addr)[3]
9566 +
9567 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9568 +
9569 +
9570 +static inline
9571 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9572 +{
9573 +       __be32 ip = nxa->ip[0].s_addr;
9574 +       __be32 mask = nxa->mask.s_addr;
9575 +       __be32 bcast = ip | ~mask;
9576 +       int ret = 0;
9577 +
9578 +       switch (nxa->type & tmask) {
9579 +       case NXA_TYPE_MASK:
9580 +               ret = (ip == (addr & mask));
9581 +               break;
9582 +       case NXA_TYPE_ADDR:
9583 +               ret = 3;
9584 +               if (addr == ip)
9585 +                       break;
9586 +               /* fall through to broadcast */
9587 +       case NXA_MOD_BCAST:
9588 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9589 +               break;
9590 +       case NXA_TYPE_RANGE:
9591 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9592 +                       (nxa->ip[1].s_addr > addr));
9593 +               break;
9594 +       case NXA_TYPE_ANY:
9595 +               ret = 2;
9596 +               break;
9597 +       }
9598 +
9599 +       vxdprintk(VXD_CBIT(net, 0),
9600 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9601 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9602 +       return ret;
9603 +}
9604 +
9605 +static inline
9606 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9607 +{
9608 +       struct nx_addr_v4 *nxa;
9609 +       int ret = 1;
9610 +
9611 +       if (!nxi)
9612 +               goto out;
9613 +
9614 +       ret = 2;
9615 +       /* allow 127.0.0.1 when remapping lback */
9616 +       if ((tmask & NXA_LOOPBACK) &&
9617 +               (addr == IPI_LOOPBACK) &&
9618 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9619 +               goto out;
9620 +       ret = 3;
9621 +       /* check for lback address */
9622 +       if ((tmask & NXA_MOD_LBACK) &&
9623 +               (nxi->v4_lback.s_addr == addr))
9624 +               goto out;
9625 +       ret = 4;
9626 +       /* check for broadcast address */
9627 +       if ((tmask & NXA_MOD_BCAST) &&
9628 +               (nxi->v4_bcast.s_addr == addr))
9629 +               goto out;
9630 +       ret = 5;
9631 +       /* check for v4 addresses */
9632 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9633 +               if (v4_addr_match(nxa, addr, tmask))
9634 +                       goto out;
9635 +       ret = 0;
9636 +out:
9637 +       vxdprintk(VXD_CBIT(net, 0),
9638 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9639 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9640 +       return ret;
9641 +}
9642 +
9643 +static inline
9644 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9645 +{
9646 +       /* FIXME: needs full range checks */
9647 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9648 +}
9649 +
9650 +static inline
9651 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9652 +{
9653 +       struct nx_addr_v4 *ptr;
9654 +
9655 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9656 +               if (v4_nx_addr_match(ptr, nxa, mask))
9657 +                       return 1;
9658 +       return 0;
9659 +}
9660 +
9661 +#include <net/inet_sock.h>
9662 +
9663 +/*
9664 + *     Check if a given address matches for a socket
9665 + *
9666 + *     nxi:            the socket's nx_info if any
9667 + *     addr:           to be verified address
9668 + */
9669 +static inline
9670 +int v4_sock_addr_match (
9671 +       struct nx_info *nxi,
9672 +       struct inet_sock *inet,
9673 +       __be32 addr)
9674 +{
9675 +       __be32 saddr = inet->inet_rcv_saddr;
9676 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9677 +
9678 +       if (addr && (saddr == addr || bcast == addr))
9679 +               return 1;
9680 +       if (!saddr)
9681 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9682 +       return 0;
9683 +}
9684 +
9685 +
9686 +/* inet related checks and helpers */
9687 +
9688 +
9689 +struct in_ifaddr;
9690 +struct net_device;
9691 +struct sock;
9692 +
9693 +#ifdef CONFIG_INET
9694 +
9695 +#include <linux/netdevice.h>
9696 +#include <linux/inetdevice.h>
9697 +#include <net/inet_sock.h>
9698 +#include <net/inet_timewait_sock.h>
9699 +
9700 +
9701 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9702 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9703 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9704 +
9705 +
9706 +/*
9707 + *     check if address is covered by socket
9708 + *
9709 + *     sk:     the socket to check against
9710 + *     addr:   the address in question (must be != 0)
9711 + */
9712 +
9713 +static inline
9714 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9715 +{
9716 +       struct nx_info *nxi = sk->sk_nx_info;
9717 +       __be32 saddr = sk_rcv_saddr(sk);
9718 +
9719 +       vxdprintk(VXD_CBIT(net, 5),
9720 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9721 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9722 +               (sk->sk_socket?sk->sk_socket->flags:0));
9723 +
9724 +       if (saddr) {            /* direct address match */
9725 +               return v4_addr_match(nxa, saddr, -1);
9726 +       } else if (nxi) {       /* match against nx_info */
9727 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9728 +       } else {                /* unrestricted any socket */
9729 +               return 1;
9730 +       }
9731 +}
9732 +
9733 +
9734 +
9735 +static inline
9736 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9737 +{
9738 +       vxdprintk(VXD_CBIT(net, 1),
9739 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9740 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9741 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9742 +
9743 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9744 +               return 1;
9745 +       if (dev_in_nx_info(dev, nxi))
9746 +               return 1;
9747 +       return 0;
9748 +}
9749 +
9750 +
9751 +static inline
9752 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9753 +{
9754 +       if (!nxi)
9755 +               return 1;
9756 +       if (!ifa)
9757 +               return 0;
9758 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9759 +}
9760 +
9761 +static inline
9762 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9763 +{
9764 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9765 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9766 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9767 +
9768 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9769 +               return 1;
9770 +       if (v4_ifa_in_nx_info(ifa, nxi))
9771 +               return 1;
9772 +       return 0;
9773 +}
9774 +
9775 +
9776 +struct nx_v4_sock_addr {
9777 +       __be32 saddr;   /* Address used for validation */
9778 +       __be32 baddr;   /* Address used for socket bind */
9779 +};
9780 +
9781 +static inline
9782 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9783 +       struct nx_v4_sock_addr *nsa)
9784 +{
9785 +       struct sock *sk = &inet->sk;
9786 +       struct nx_info *nxi = sk->sk_nx_info;
9787 +       __be32 saddr = addr->sin_addr.s_addr;
9788 +       __be32 baddr = saddr;
9789 +
9790 +       vxdprintk(VXD_CBIT(net, 3),
9791 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9792 +               sk, sk->sk_nx_info, sk->sk_socket,
9793 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9794 +               NIPQUAD(saddr));
9795 +
9796 +       if (nxi) {
9797 +               if (saddr == INADDR_ANY) {
9798 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9799 +                               baddr = nxi->v4.ip[0].s_addr;
9800 +               } else if (saddr == IPI_LOOPBACK) {
9801 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9802 +                               baddr = nxi->v4_lback.s_addr;
9803 +               } else if (!ipv4_is_multicast(saddr) ||
9804 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9805 +                       /* normal address bind */
9806 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9807 +                               return -EADDRNOTAVAIL;
9808 +               }
9809 +       }
9810 +
9811 +       vxdprintk(VXD_CBIT(net, 3),
9812 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9813 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9814 +
9815 +       nsa->saddr = saddr;
9816 +       nsa->baddr = baddr;
9817 +       return 0;
9818 +}
9819 +
9820 +static inline
9821 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9822 +{
9823 +       inet->inet_saddr = nsa->baddr;
9824 +       inet->inet_rcv_saddr = nsa->baddr;
9825 +}
9826 +
9827 +
9828 +/*
9829 + *      helper to simplify inet_lookup_listener
9830 + *
9831 + *      nxi:   the socket's nx_info if any
9832 + *      addr:  to be verified address
9833 + *      saddr: socket address
9834 + */
9835 +static inline int v4_inet_addr_match (
9836 +       struct nx_info *nxi,
9837 +       __be32 addr,
9838 +       __be32 saddr)
9839 +{
9840 +       if (addr && (saddr == addr))
9841 +               return 1;
9842 +       if (!saddr)
9843 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9844 +       return 0;
9845 +}
9846 +
9847 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9848 +{
9849 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9850 +               (addr == nxi->v4_lback.s_addr))
9851 +               return IPI_LOOPBACK;
9852 +       return addr;
9853 +}
9854 +
9855 +static inline
9856 +int nx_info_has_v4(struct nx_info *nxi)
9857 +{
9858 +       if (!nxi)
9859 +               return 1;
9860 +       if (NX_IPV4(nxi))
9861 +               return 1;
9862 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9863 +               return 1;
9864 +       return 0;
9865 +}
9866 +
9867 +#else /* CONFIG_INET */
9868 +
9869 +static inline
9870 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9871 +{
9872 +       return 1;
9873 +}
9874 +
9875 +static inline
9876 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9877 +{
9878 +       return 1;
9879 +}
9880 +
9881 +static inline
9882 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9883 +{
9884 +       return 1;
9885 +}
9886 +
9887 +static inline
9888 +int nx_info_has_v4(struct nx_info *nxi)
9889 +{
9890 +       return 0;
9891 +}
9892 +
9893 +#endif /* CONFIG_INET */
9894 +
9895 +#define current_nx_info_has_v4() \
9896 +       nx_info_has_v4(current_nx_info())
9897 +
9898 +#else
9899 +// #warning duplicate inclusion
9900 +#endif
9901 diff -NurpP --minimal linux-3.4.83/include/linux/vs_inet6.h linux-3.4.83-vs2.3.3.9/include/linux/vs_inet6.h
9902 --- linux-3.4.83/include/linux/vs_inet6.h       1970-01-01 00:00:00.000000000 +0000
9903 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_inet6.h     2012-05-21 16:15:05.000000000 +0000
9904 @@ -0,0 +1,246 @@
9905 +#ifndef _VS_INET6_H
9906 +#define _VS_INET6_H
9907 +
9908 +#include "vserver/base.h"
9909 +#include "vserver/network.h"
9910 +#include "vserver/debug.h"
9911 +
9912 +#include <net/ipv6.h>
9913 +
9914 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9915 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9916 +
9917 +
9918 +#ifdef CONFIG_IPV6
9919 +
9920 +static inline
9921 +int v6_addr_match(struct nx_addr_v6 *nxa,
9922 +       const struct in6_addr *addr, uint16_t mask)
9923 +{
9924 +       int ret = 0;
9925 +
9926 +       switch (nxa->type & mask) {
9927 +       case NXA_TYPE_MASK:
9928 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9929 +               break;
9930 +       case NXA_TYPE_ADDR:
9931 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9932 +               break;
9933 +       case NXA_TYPE_ANY:
9934 +               ret = 1;
9935 +               break;
9936 +       }
9937 +       vxdprintk(VXD_CBIT(net, 0),
9938 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9939 +               nxa, NXAV6(nxa), addr, mask, ret);
9940 +       return ret;
9941 +}
9942 +
9943 +static inline
9944 +int v6_addr_in_nx_info(struct nx_info *nxi,
9945 +       const struct in6_addr *addr, uint16_t mask)
9946 +{
9947 +       struct nx_addr_v6 *nxa;
9948 +       int ret = 1;
9949 +
9950 +       if (!nxi)
9951 +               goto out;
9952 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9953 +               if (v6_addr_match(nxa, addr, mask))
9954 +                       goto out;
9955 +       ret = 0;
9956 +out:
9957 +       vxdprintk(VXD_CBIT(net, 0),
9958 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9959 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9960 +       return ret;
9961 +}
9962 +
9963 +static inline
9964 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9965 +{
9966 +       /* FIXME: needs full range checks */
9967 +       return v6_addr_match(nxa, &addr->ip, mask);
9968 +}
9969 +
9970 +static inline
9971 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9972 +{
9973 +       struct nx_addr_v6 *ptr;
9974 +
9975 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9976 +               if (v6_nx_addr_match(ptr, nxa, mask))
9977 +                       return 1;
9978 +       return 0;
9979 +}
9980 +
9981 +
9982 +/*
9983 + *     Check if a given address matches for a socket
9984 + *
9985 + *     nxi:            the socket's nx_info if any
9986 + *     addr:           to be verified address
9987 + */
9988 +static inline
9989 +int v6_sock_addr_match (
9990 +       struct nx_info *nxi,
9991 +       struct inet_sock *inet,
9992 +       struct in6_addr *addr)
9993 +{
9994 +       struct sock *sk = &inet->sk;
9995 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9996 +
9997 +       if (!ipv6_addr_any(addr) &&
9998 +               ipv6_addr_equal(saddr, addr))
9999 +               return 1;
10000 +       if (ipv6_addr_any(saddr))
10001 +               return v6_addr_in_nx_info(nxi, addr, -1);
10002 +       return 0;
10003 +}
10004 +
10005 +/*
10006 + *     check if address is covered by socket
10007 + *
10008 + *     sk:     the socket to check against
10009 + *     addr:   the address in question (must be != 0)
10010 + */
10011 +
10012 +static inline
10013 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10014 +{
10015 +       struct nx_info *nxi = sk->sk_nx_info;
10016 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10017 +
10018 +       vxdprintk(VXD_CBIT(net, 5),
10019 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10020 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10021 +               (sk->sk_socket?sk->sk_socket->flags:0));
10022 +
10023 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10024 +               return v6_addr_match(nxa, saddr, -1);
10025 +       } else if (nxi) {               /* match against nx_info */
10026 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10027 +       } else {                        /* unrestricted any socket */
10028 +               return 1;
10029 +       }
10030 +}
10031 +
10032 +
10033 +/* inet related checks and helpers */
10034 +
10035 +
10036 +struct in_ifaddr;
10037 +struct net_device;
10038 +struct sock;
10039 +
10040 +
10041 +#include <linux/netdevice.h>
10042 +#include <linux/inetdevice.h>
10043 +#include <net/inet_timewait_sock.h>
10044 +
10045 +
10046 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10047 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10048 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10049 +
10050 +
10051 +
10052 +static inline
10053 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10054 +{
10055 +       if (!nxi)
10056 +               return 1;
10057 +       if (!ifa)
10058 +               return 0;
10059 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10060 +}
10061 +
10062 +static inline
10063 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10064 +{
10065 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10066 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10067 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10068 +
10069 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10070 +               return 1;
10071 +       if (v6_ifa_in_nx_info(ifa, nxi))
10072 +               return 1;
10073 +       return 0;
10074 +}
10075 +
10076 +
10077 +struct nx_v6_sock_addr {
10078 +       struct in6_addr saddr;  /* Address used for validation */
10079 +       struct in6_addr baddr;  /* Address used for socket bind */
10080 +};
10081 +
10082 +static inline
10083 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10084 +       struct nx_v6_sock_addr *nsa)
10085 +{
10086 +       // struct sock *sk = &inet->sk;
10087 +       // struct nx_info *nxi = sk->sk_nx_info;
10088 +       struct in6_addr saddr = addr->sin6_addr;
10089 +       struct in6_addr baddr = saddr;
10090 +
10091 +       nsa->saddr = saddr;
10092 +       nsa->baddr = baddr;
10093 +       return 0;
10094 +}
10095 +
10096 +static inline
10097 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10098 +{
10099 +       // struct sock *sk = &inet->sk;
10100 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10101 +
10102 +       // *saddr = nsa->baddr;
10103 +       // inet->inet_saddr = nsa->baddr;
10104 +}
10105 +
10106 +static inline
10107 +int nx_info_has_v6(struct nx_info *nxi)
10108 +{
10109 +       if (!nxi)
10110 +               return 1;
10111 +       if (NX_IPV6(nxi))
10112 +               return 1;
10113 +       return 0;
10114 +}
10115 +
10116 +#else /* CONFIG_IPV6 */
10117 +
10118 +static inline
10119 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10120 +{
10121 +       return 1;
10122 +}
10123 +
10124 +
10125 +static inline
10126 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10127 +{
10128 +       return 1;
10129 +}
10130 +
10131 +static inline
10132 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10133 +{
10134 +       return 1;
10135 +}
10136 +
10137 +static inline
10138 +int nx_info_has_v6(struct nx_info *nxi)
10139 +{
10140 +       return 0;
10141 +}
10142 +
10143 +#endif /* CONFIG_IPV6 */
10144 +
10145 +#define current_nx_info_has_v6() \
10146 +       nx_info_has_v6(current_nx_info())
10147 +
10148 +#else
10149 +#warning duplicate inclusion
10150 +#endif
10151 diff -NurpP --minimal linux-3.4.83/include/linux/vs_limit.h linux-3.4.83-vs2.3.3.9/include/linux/vs_limit.h
10152 --- linux-3.4.83/include/linux/vs_limit.h       1970-01-01 00:00:00.000000000 +0000
10153 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_limit.h     2012-05-21 16:15:05.000000000 +0000
10154 @@ -0,0 +1,140 @@
10155 +#ifndef _VS_LIMIT_H
10156 +#define _VS_LIMIT_H
10157 +
10158 +#include "vserver/limit.h"
10159 +#include "vserver/base.h"
10160 +#include "vserver/context.h"
10161 +#include "vserver/debug.h"
10162 +#include "vserver/context.h"
10163 +#include "vserver/limit_int.h"
10164 +
10165 +
10166 +#define vx_acc_cres(v, d, p, r) \
10167 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10168 +
10169 +#define vx_acc_cres_cond(x, d, p, r) \
10170 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10171 +       r, d, p, __FILE__, __LINE__)
10172 +
10173 +
10174 +#define vx_add_cres(v, a, p, r) \
10175 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10176 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10177 +
10178 +#define vx_add_cres_cond(x, a, p, r) \
10179 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10180 +       r, a, p, __FILE__, __LINE__)
10181 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10182 +
10183 +
10184 +/* process and file limits */
10185 +
10186 +#define vx_nproc_inc(p) \
10187 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10188 +
10189 +#define vx_nproc_dec(p) \
10190 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10191 +
10192 +#define vx_files_inc(f) \
10193 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10194 +
10195 +#define vx_files_dec(f) \
10196 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10197 +
10198 +#define vx_locks_inc(l) \
10199 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10200 +
10201 +#define vx_locks_dec(l) \
10202 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10203 +
10204 +#define vx_openfd_inc(f) \
10205 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10206 +
10207 +#define vx_openfd_dec(f) \
10208 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10209 +
10210 +
10211 +#define vx_cres_avail(v, n, r) \
10212 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10213 +
10214 +
10215 +#define vx_nproc_avail(n) \
10216 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10217 +
10218 +#define vx_files_avail(n) \
10219 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10220 +
10221 +#define vx_locks_avail(n) \
10222 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10223 +
10224 +#define vx_openfd_avail(n) \
10225 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10226 +
10227 +
10228 +/* dentry limits */
10229 +
10230 +#define vx_dentry_inc(d) do {                                          \
10231 +       if ((d)->d_count == 1)                                          \
10232 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10233 +       } while (0)
10234 +
10235 +#define vx_dentry_dec(d) do {                                          \
10236 +       if ((d)->d_count == 0)                                          \
10237 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10238 +       } while (0)
10239 +
10240 +#define vx_dentry_avail(n) \
10241 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10242 +
10243 +
10244 +/* socket limits */
10245 +
10246 +#define vx_sock_inc(s) \
10247 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10248 +
10249 +#define vx_sock_dec(s) \
10250 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10251 +
10252 +#define vx_sock_avail(n) \
10253 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10254 +
10255 +
10256 +/* ipc resource limits */
10257 +
10258 +#define vx_ipcmsg_add(v, u, a) \
10259 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10260 +
10261 +#define vx_ipcmsg_sub(v, u, a) \
10262 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10263 +
10264 +#define vx_ipcmsg_avail(v, a) \
10265 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10266 +
10267 +
10268 +#define vx_ipcshm_add(v, k, a) \
10269 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10270 +
10271 +#define vx_ipcshm_sub(v, k, a) \
10272 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10273 +
10274 +#define vx_ipcshm_avail(v, a) \
10275 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10276 +
10277 +
10278 +#define vx_semary_inc(a) \
10279 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10280 +
10281 +#define vx_semary_dec(a) \
10282 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10283 +
10284 +
10285 +#define vx_nsems_add(a,n) \
10286 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10287 +
10288 +#define vx_nsems_sub(a,n) \
10289 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10290 +
10291 +
10292 +#else
10293 +#warning duplicate inclusion
10294 +#endif
10295 diff -NurpP --minimal linux-3.4.83/include/linux/vs_network.h linux-3.4.83-vs2.3.3.9/include/linux/vs_network.h
10296 --- linux-3.4.83/include/linux/vs_network.h     1970-01-01 00:00:00.000000000 +0000
10297 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_network.h   2012-05-21 16:15:05.000000000 +0000
10298 @@ -0,0 +1,169 @@
10299 +#ifndef _NX_VS_NETWORK_H
10300 +#define _NX_VS_NETWORK_H
10301 +
10302 +#include "vserver/context.h"
10303 +#include "vserver/network.h"
10304 +#include "vserver/base.h"
10305 +#include "vserver/check.h"
10306 +#include "vserver/debug.h"
10307 +
10308 +#include <linux/sched.h>
10309 +
10310 +
10311 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10312 +
10313 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10314 +       const char *_file, int _line)
10315 +{
10316 +       if (!nxi)
10317 +               return NULL;
10318 +
10319 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10320 +               nxi, nxi ? nxi->nx_id : 0,
10321 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10322 +               _file, _line);
10323 +
10324 +       atomic_inc(&nxi->nx_usecnt);
10325 +       return nxi;
10326 +}
10327 +
10328 +
10329 +extern void free_nx_info(struct nx_info *);
10330 +
10331 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10332 +
10333 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10334 +{
10335 +       if (!nxi)
10336 +               return;
10337 +
10338 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10339 +               nxi, nxi ? nxi->nx_id : 0,
10340 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10341 +               _file, _line);
10342 +
10343 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10344 +               free_nx_info(nxi);
10345 +}
10346 +
10347 +
10348 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10349 +
10350 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10351 +               const char *_file, int _line)
10352 +{
10353 +       if (nxi) {
10354 +               vxlprintk(VXD_CBIT(nid, 3),
10355 +                       "init_nx_info(%p[#%d.%d])",
10356 +                       nxi, nxi ? nxi->nx_id : 0,
10357 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10358 +                       _file, _line);
10359 +
10360 +               atomic_inc(&nxi->nx_usecnt);
10361 +       }
10362 +       *nxp = nxi;
10363 +}
10364 +
10365 +
10366 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10367 +
10368 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10369 +       const char *_file, int _line)
10370 +{
10371 +       struct nx_info *nxo;
10372 +
10373 +       if (!nxi)
10374 +               return;
10375 +
10376 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10377 +               nxi, nxi ? nxi->nx_id : 0,
10378 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10379 +               _file, _line);
10380 +
10381 +       atomic_inc(&nxi->nx_usecnt);
10382 +       nxo = xchg(nxp, nxi);
10383 +       BUG_ON(nxo);
10384 +}
10385 +
10386 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10387 +
10388 +static inline void __clr_nx_info(struct nx_info **nxp,
10389 +       const char *_file, int _line)
10390 +{
10391 +       struct nx_info *nxo;
10392 +
10393 +       nxo = xchg(nxp, NULL);
10394 +       if (!nxo)
10395 +               return;
10396 +
10397 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10398 +               nxo, nxo ? nxo->nx_id : 0,
10399 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10400 +               _file, _line);
10401 +
10402 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10403 +               free_nx_info(nxo);
10404 +}
10405 +
10406 +
10407 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10408 +
10409 +static inline void __claim_nx_info(struct nx_info *nxi,
10410 +       struct task_struct *task, const char *_file, int _line)
10411 +{
10412 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10413 +               nxi, nxi ? nxi->nx_id : 0,
10414 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10415 +               nxi?atomic_read(&nxi->nx_tasks):0,
10416 +               task, _file, _line);
10417 +
10418 +       atomic_inc(&nxi->nx_tasks);
10419 +}
10420 +
10421 +
10422 +extern void unhash_nx_info(struct nx_info *);
10423 +
10424 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10425 +
10426 +static inline void __release_nx_info(struct nx_info *nxi,
10427 +       struct task_struct *task, const char *_file, int _line)
10428 +{
10429 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10430 +               nxi, nxi ? nxi->nx_id : 0,
10431 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10432 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10433 +               task, _file, _line);
10434 +
10435 +       might_sleep();
10436 +
10437 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10438 +               unhash_nx_info(nxi);
10439 +}
10440 +
10441 +
10442 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10443 +
10444 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10445 +       const char *_file, int _line)
10446 +{
10447 +       struct nx_info *nxi;
10448 +
10449 +       task_lock(p);
10450 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10451 +               p, _file, _line);
10452 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10453 +       task_unlock(p);
10454 +       return nxi;
10455 +}
10456 +
10457 +
10458 +static inline void exit_nx_info(struct task_struct *p)
10459 +{
10460 +       if (p->nx_info)
10461 +               release_nx_info(p->nx_info, p);
10462 +}
10463 +
10464 +
10465 +#else
10466 +#warning duplicate inclusion
10467 +#endif
10468 diff -NurpP --minimal linux-3.4.83/include/linux/vs_pid.h linux-3.4.83-vs2.3.3.9/include/linux/vs_pid.h
10469 --- linux-3.4.83/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
10470 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_pid.h       2012-05-21 16:15:05.000000000 +0000
10471 @@ -0,0 +1,50 @@
10472 +#ifndef _VS_PID_H
10473 +#define _VS_PID_H
10474 +
10475 +#include "vserver/base.h"
10476 +#include "vserver/check.h"
10477 +#include "vserver/context.h"
10478 +#include "vserver/debug.h"
10479 +#include "vserver/pid.h"
10480 +#include <linux/pid_namespace.h>
10481 +
10482 +
10483 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10484 +
10485 +static inline
10486 +int vx_proc_task_visible(struct task_struct *task)
10487 +{
10488 +       if ((task->pid == 1) &&
10489 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10490 +               /* show a blend through init */
10491 +               goto visible;
10492 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10493 +               goto visible;
10494 +       return 0;
10495 +visible:
10496 +       return 1;
10497 +}
10498 +
10499 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10500 +
10501 +
10502 +static inline
10503 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10504 +{
10505 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10506 +
10507 +       if (task && !vx_proc_task_visible(task)) {
10508 +               vxdprintk(VXD_CBIT(misc, 6),
10509 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10510 +                       task, task->xid, task->pid,
10511 +                       current, current->xid, current->pid);
10512 +               put_task_struct(task);
10513 +               task = NULL;
10514 +       }
10515 +       return task;
10516 +}
10517 +
10518 +
10519 +#else
10520 +#warning duplicate inclusion
10521 +#endif
10522 diff -NurpP --minimal linux-3.4.83/include/linux/vs_sched.h linux-3.4.83-vs2.3.3.9/include/linux/vs_sched.h
10523 --- linux-3.4.83/include/linux/vs_sched.h       1970-01-01 00:00:00.000000000 +0000
10524 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_sched.h     2012-05-21 16:15:05.000000000 +0000
10525 @@ -0,0 +1,40 @@
10526 +#ifndef _VS_SCHED_H
10527 +#define _VS_SCHED_H
10528 +
10529 +#include "vserver/base.h"
10530 +#include "vserver/context.h"
10531 +#include "vserver/sched.h"
10532 +
10533 +
10534 +#define MAX_PRIO_BIAS           20
10535 +#define MIN_PRIO_BIAS          -20
10536 +
10537 +static inline
10538 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10539 +{
10540 +       struct vx_info *vxi = p->vx_info;
10541 +
10542 +       if (vxi)
10543 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10544 +       return prio;
10545 +}
10546 +
10547 +static inline void vx_account_user(struct vx_info *vxi,
10548 +       cputime_t cputime, int nice)
10549 +{
10550 +       if (!vxi)
10551 +               return;
10552 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10553 +}
10554 +
10555 +static inline void vx_account_system(struct vx_info *vxi,
10556 +       cputime_t cputime, int idle)
10557 +{
10558 +       if (!vxi)
10559 +               return;
10560 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10561 +}
10562 +
10563 +#else
10564 +#warning duplicate inclusion
10565 +#endif
10566 diff -NurpP --minimal linux-3.4.83/include/linux/vs_socket.h linux-3.4.83-vs2.3.3.9/include/linux/vs_socket.h
10567 --- linux-3.4.83/include/linux/vs_socket.h      1970-01-01 00:00:00.000000000 +0000
10568 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_socket.h    2012-05-21 16:15:05.000000000 +0000
10569 @@ -0,0 +1,67 @@
10570 +#ifndef _VS_SOCKET_H
10571 +#define _VS_SOCKET_H
10572 +
10573 +#include "vserver/debug.h"
10574 +#include "vserver/base.h"
10575 +#include "vserver/cacct.h"
10576 +#include "vserver/context.h"
10577 +#include "vserver/tag.h"
10578 +
10579 +
10580 +/* socket accounting */
10581 +
10582 +#include <linux/socket.h>
10583 +
10584 +static inline int vx_sock_type(int family)
10585 +{
10586 +       switch (family) {
10587 +       case PF_UNSPEC:
10588 +               return VXA_SOCK_UNSPEC;
10589 +       case PF_UNIX:
10590 +               return VXA_SOCK_UNIX;
10591 +       case PF_INET:
10592 +               return VXA_SOCK_INET;
10593 +       case PF_INET6:
10594 +               return VXA_SOCK_INET6;
10595 +       case PF_PACKET:
10596 +               return VXA_SOCK_PACKET;
10597 +       default:
10598 +               return VXA_SOCK_OTHER;
10599 +       }
10600 +}
10601 +
10602 +#define vx_acc_sock(v, f, p, s) \
10603 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10604 +
10605 +static inline void __vx_acc_sock(struct vx_info *vxi,
10606 +       int family, int pos, int size, char *file, int line)
10607 +{
10608 +       if (vxi) {
10609 +               int type = vx_sock_type(family);
10610 +
10611 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10612 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10613 +       }
10614 +}
10615 +
10616 +#define vx_sock_recv(sk, s) \
10617 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10618 +#define vx_sock_send(sk, s) \
10619 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10620 +#define vx_sock_fail(sk, s) \
10621 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10622 +
10623 +
10624 +#define sock_vx_init(s) do {           \
10625 +       (s)->sk_xid = 0;                \
10626 +       (s)->sk_vx_info = NULL;         \
10627 +       } while (0)
10628 +
10629 +#define sock_nx_init(s) do {           \
10630 +       (s)->sk_nid = 0;                \
10631 +       (s)->sk_nx_info = NULL;         \
10632 +       } while (0)
10633 +
10634 +#else
10635 +#warning duplicate inclusion
10636 +#endif
10637 diff -NurpP --minimal linux-3.4.83/include/linux/vs_tag.h linux-3.4.83-vs2.3.3.9/include/linux/vs_tag.h
10638 --- linux-3.4.83/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
10639 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_tag.h       2012-05-21 16:15:05.000000000 +0000
10640 @@ -0,0 +1,47 @@
10641 +#ifndef _VS_TAG_H
10642 +#define _VS_TAG_H
10643 +
10644 +#include <linux/vserver/tag.h>
10645 +
10646 +/* check conditions */
10647 +
10648 +#define DX_ADMIN       0x0001
10649 +#define DX_WATCH       0x0002
10650 +#define DX_HOSTID      0x0008
10651 +
10652 +#define DX_IDENT       0x0010
10653 +
10654 +#define DX_ARG_MASK    0x0010
10655 +
10656 +
10657 +#define dx_task_tag(t) ((t)->tag)
10658 +
10659 +#define dx_current_tag() dx_task_tag(current)
10660 +
10661 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10662 +
10663 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10664 +
10665 +
10666 +/*
10667 + * check current context for ADMIN/WATCH and
10668 + * optionally against supplied argument
10669 + */
10670 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10671 +{
10672 +       if (mode & DX_ARG_MASK) {
10673 +               if ((mode & DX_IDENT) && (id == cid))
10674 +                       return 1;
10675 +       }
10676 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10677 +               ((mode & DX_WATCH) && (cid == 1)) ||
10678 +               ((mode & DX_HOSTID) && (id == 0)));
10679 +}
10680 +
10681 +struct inode;
10682 +int dx_permission(const struct inode *inode, int mask);
10683 +
10684 +
10685 +#else
10686 +#warning duplicate inclusion
10687 +#endif
10688 diff -NurpP --minimal linux-3.4.83/include/linux/vs_time.h linux-3.4.83-vs2.3.3.9/include/linux/vs_time.h
10689 --- linux-3.4.83/include/linux/vs_time.h        1970-01-01 00:00:00.000000000 +0000
10690 +++ linux-3.4.83-vs2.3.3.9/include/linux/vs_time.h      2012-05-21 16:15:05.000000000 +0000
10691 @@ -0,0 +1,19 @@
10692 +#ifndef _VS_TIME_H
10693 +#define _VS_TIME_H
10694 +
10695 +
10696 +/* time faking stuff */
10697 +
10698 +#ifdef CONFIG_VSERVER_VTIME
10699 +
10700 +extern void vx_adjust_timespec(struct timespec *ts);
10701 +extern int vx_settimeofday(const struct timespec *ts);
10702 +
10703 +#else
10704 +#define        vx_adjust_timespec(t)   do { } while (0)
10705 +#define        vx_settimeofday(t)      do_settimeofday(t)
10706 +#endif
10707 +
10708 +#else
10709 +#warning duplicate inclusion
10710 +#endif
10711 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/Kbuild linux-3.4.83-vs2.3.3.9/include/linux/vserver/Kbuild
10712 --- linux-3.4.83/include/linux/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
10713 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/Kbuild 2012-05-21 16:15:05.000000000 +0000
10714 @@ -0,0 +1,8 @@
10715 +
10716 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10717 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10718 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10719 +       debug_cmd.h device_cmd.h
10720 +
10721 +header-y += switch.h network.h monitor.h inode.h device.h
10722 +
10723 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/base.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/base.h
10724 --- linux-3.4.83/include/linux/vserver/base.h   1970-01-01 00:00:00.000000000 +0000
10725 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/base.h 2012-05-21 16:15:05.000000000 +0000
10726 @@ -0,0 +1,178 @@
10727 +#ifndef _VX_BASE_H
10728 +#define _VX_BASE_H
10729 +
10730 +
10731 +/* context state changes */
10732 +
10733 +enum {
10734 +       VSC_STARTUP = 1,
10735 +       VSC_SHUTDOWN,
10736 +
10737 +       VSC_NETUP,
10738 +       VSC_NETDOWN,
10739 +};
10740 +
10741 +
10742 +
10743 +#define vx_task_xid(t) ((t)->xid)
10744 +
10745 +#define vx_current_xid() vx_task_xid(current)
10746 +
10747 +#define current_vx_info() (current->vx_info)
10748 +
10749 +
10750 +#define nx_task_nid(t) ((t)->nid)
10751 +
10752 +#define nx_current_nid() nx_task_nid(current)
10753 +
10754 +#define current_nx_info() (current->nx_info)
10755 +
10756 +
10757 +/* generic flag merging */
10758 +
10759 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10760 +
10761 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10762 +
10763 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10764 +
10765 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10766 +
10767 +
10768 +/* context flags */
10769 +
10770 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10771 +
10772 +#define vx_current_flags()     __vx_flags(current_vx_info())
10773 +
10774 +#define vx_info_flags(v, m, f) \
10775 +       vs_check_flags(__vx_flags(v), m, f)
10776 +
10777 +#define task_vx_flags(t, m, f) \
10778 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10779 +
10780 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10781 +
10782 +
10783 +/* context caps */
10784 +
10785 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10786 +
10787 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10788 +
10789 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10790 +
10791 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10792 +
10793 +
10794 +
10795 +/* network flags */
10796 +
10797 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10798 +
10799 +#define nx_current_flags()     __nx_flags(current_nx_info())
10800 +
10801 +#define nx_info_flags(n, m, f) \
10802 +       vs_check_flags(__nx_flags(n), m, f)
10803 +
10804 +#define task_nx_flags(t, m, f) \
10805 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10806 +
10807 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10808 +
10809 +
10810 +/* network caps */
10811 +
10812 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10813 +
10814 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10815 +
10816 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10817 +
10818 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10819 +
10820 +
10821 +/* context mask capabilities */
10822 +
10823 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10824 +
10825 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10826 +
10827 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10828 +
10829 +
10830 +/* context bcap mask */
10831 +
10832 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10833 +
10834 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10835 +
10836 +
10837 +/* mask given bcaps */
10838 +
10839 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10840 +
10841 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10842 +
10843 +
10844 +/* masked cap_bset */
10845 +
10846 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10847 +
10848 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10849 +
10850 +#if 0
10851 +#define vx_info_mbcap(v, b) \
10852 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10853 +       vx_info_bcaps(v, b) : (b))
10854 +
10855 +#define task_vx_mbcap(t, b) \
10856 +       vx_info_mbcap((t)->vx_info, (t)->b)
10857 +
10858 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10859 +#endif
10860 +
10861 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10862 +
10863 +#define vx_capable(b, c) (capable(b) || \
10864 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10865 +
10866 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10867 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10868 +
10869 +#define nx_capable(b, c) (capable(b) || \
10870 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10871 +
10872 +#define vx_task_initpid(t, n) \
10873 +       ((t)->vx_info && \
10874 +       ((t)->vx_info->vx_initpid == (n)))
10875 +
10876 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10877 +
10878 +
10879 +/* context unshare mask */
10880 +
10881 +#define __vx_umask(v)          ((v)->vx_umask)
10882 +
10883 +#define vx_current_umask()     __vx_umask(current_vx_info())
10884 +
10885 +#define vx_can_unshare(b, f) (capable(b) || \
10886 +       (cap_raised(current_cap(), b) && \
10887 +       !((f) & ~vx_current_umask())))
10888 +
10889 +
10890 +#define __vx_wmask(v)          ((v)->vx_wmask)
10891 +
10892 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10893 +
10894 +
10895 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10896 +
10897 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10898 +
10899 +
10900 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10901 +
10902 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10903 +
10904 +#endif
10905 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cacct.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct.h
10906 --- linux-3.4.83/include/linux/vserver/cacct.h  1970-01-01 00:00:00.000000000 +0000
10907 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct.h        2012-05-21 16:15:05.000000000 +0000
10908 @@ -0,0 +1,15 @@
10909 +#ifndef _VX_CACCT_H
10910 +#define _VX_CACCT_H
10911 +
10912 +
10913 +enum sock_acc_field {
10914 +       VXA_SOCK_UNSPEC = 0,
10915 +       VXA_SOCK_UNIX,
10916 +       VXA_SOCK_INET,
10917 +       VXA_SOCK_INET6,
10918 +       VXA_SOCK_PACKET,
10919 +       VXA_SOCK_OTHER,
10920 +       VXA_SOCK_SIZE   /* array size */
10921 +};
10922 +
10923 +#endif /* _VX_CACCT_H */
10924 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cacct_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct_cmd.h
10925 --- linux-3.4.83/include/linux/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
10926 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct_cmd.h    2012-05-21 16:15:05.000000000 +0000
10927 @@ -0,0 +1,23 @@
10928 +#ifndef _VX_CACCT_CMD_H
10929 +#define _VX_CACCT_CMD_H
10930 +
10931 +
10932 +/* virtual host info name commands */
10933 +
10934 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10935 +
10936 +struct vcmd_sock_stat_v0 {
10937 +       uint32_t field;
10938 +       uint32_t count[3];
10939 +       uint64_t total[3];
10940 +};
10941 +
10942 +
10943 +#ifdef __KERNEL__
10944 +
10945 +#include <linux/compiler.h>
10946 +
10947 +extern int vc_sock_stat(struct vx_info *, void __user *);
10948 +
10949 +#endif /* __KERNEL__ */
10950 +#endif /* _VX_CACCT_CMD_H */
10951 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cacct_def.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct_def.h
10952 --- linux-3.4.83/include/linux/vserver/cacct_def.h      1970-01-01 00:00:00.000000000 +0000
10953 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct_def.h    2012-05-21 16:15:05.000000000 +0000
10954 @@ -0,0 +1,43 @@
10955 +#ifndef _VX_CACCT_DEF_H
10956 +#define _VX_CACCT_DEF_H
10957 +
10958 +#include <asm/atomic.h>
10959 +#include <linux/vserver/cacct.h>
10960 +
10961 +
10962 +struct _vx_sock_acc {
10963 +       atomic_long_t count;
10964 +       atomic_long_t total;
10965 +};
10966 +
10967 +/* context sub struct */
10968 +
10969 +struct _vx_cacct {
10970 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10971 +       atomic_t slab[8];
10972 +       atomic_t page[6][8];
10973 +};
10974 +
10975 +#ifdef CONFIG_VSERVER_DEBUG
10976 +
10977 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10978 +{
10979 +       int i, j;
10980 +
10981 +       printk("\t_vx_cacct:");
10982 +       for (i = 0; i < 6; i++) {
10983 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10984 +
10985 +               printk("\t [%d] =", i);
10986 +               for (j = 0; j < 3; j++) {
10987 +                       printk(" [%d] = %8lu, %8lu", j,
10988 +                               atomic_long_read(&ptr[j].count),
10989 +                               atomic_long_read(&ptr[j].total));
10990 +               }
10991 +               printk("\n");
10992 +       }
10993 +}
10994 +
10995 +#endif
10996 +
10997 +#endif /* _VX_CACCT_DEF_H */
10998 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cacct_int.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct_int.h
10999 --- linux-3.4.83/include/linux/vserver/cacct_int.h      1970-01-01 00:00:00.000000000 +0000
11000 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cacct_int.h    2012-05-21 16:15:05.000000000 +0000
11001 @@ -0,0 +1,21 @@
11002 +#ifndef _VX_CACCT_INT_H
11003 +#define _VX_CACCT_INT_H
11004 +
11005 +
11006 +#ifdef __KERNEL__
11007 +
11008 +static inline
11009 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11010 +{
11011 +       return atomic_long_read(&cacct->sock[type][pos].count);
11012 +}
11013 +
11014 +
11015 +static inline
11016 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11017 +{
11018 +       return atomic_long_read(&cacct->sock[type][pos].total);
11019 +}
11020 +
11021 +#endif /* __KERNEL__ */
11022 +#endif /* _VX_CACCT_INT_H */
11023 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/check.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/check.h
11024 --- linux-3.4.83/include/linux/vserver/check.h  1970-01-01 00:00:00.000000000 +0000
11025 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/check.h        2012-05-21 16:15:05.000000000 +0000
11026 @@ -0,0 +1,89 @@
11027 +#ifndef _VS_CHECK_H
11028 +#define _VS_CHECK_H
11029 +
11030 +
11031 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11032 +
11033 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11034 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11035 +#else
11036 +#define MIN_D_CONTEXT  65536
11037 +#endif
11038 +
11039 +/* check conditions */
11040 +
11041 +#define VS_ADMIN       0x0001
11042 +#define VS_WATCH       0x0002
11043 +#define VS_HIDE                0x0004
11044 +#define VS_HOSTID      0x0008
11045 +
11046 +#define VS_IDENT       0x0010
11047 +#define VS_EQUIV       0x0020
11048 +#define VS_PARENT      0x0040
11049 +#define VS_CHILD       0x0080
11050 +
11051 +#define VS_ARG_MASK    0x00F0
11052 +
11053 +#define VS_DYNAMIC     0x0100
11054 +#define VS_STATIC      0x0200
11055 +
11056 +#define VS_ATR_MASK    0x0F00
11057 +
11058 +#ifdef CONFIG_VSERVER_PRIVACY
11059 +#define VS_ADMIN_P     (0)
11060 +#define VS_WATCH_P     (0)
11061 +#else
11062 +#define VS_ADMIN_P     VS_ADMIN
11063 +#define VS_WATCH_P     VS_WATCH
11064 +#endif
11065 +
11066 +#define VS_HARDIRQ     0x1000
11067 +#define VS_SOFTIRQ     0x2000
11068 +#define VS_IRQ         0x4000
11069 +
11070 +#define VS_IRQ_MASK    0xF000
11071 +
11072 +#include <linux/hardirq.h>
11073 +
11074 +/*
11075 + * check current context for ADMIN/WATCH and
11076 + * optionally against supplied argument
11077 + */
11078 +static inline int __vs_check(int cid, int id, unsigned int mode)
11079 +{
11080 +       if (mode & VS_ARG_MASK) {
11081 +               if ((mode & VS_IDENT) && (id == cid))
11082 +                       return 1;
11083 +       }
11084 +       if (mode & VS_ATR_MASK) {
11085 +               if ((mode & VS_DYNAMIC) &&
11086 +                       (id >= MIN_D_CONTEXT) &&
11087 +                       (id <= MAX_S_CONTEXT))
11088 +                       return 1;
11089 +               if ((mode & VS_STATIC) &&
11090 +                       (id > 1) && (id < MIN_D_CONTEXT))
11091 +                       return 1;
11092 +       }
11093 +       if (mode & VS_IRQ_MASK) {
11094 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11095 +                       return 1;
11096 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11097 +                       return 1;
11098 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11099 +                       return 1;
11100 +       }
11101 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11102 +               ((mode & VS_WATCH) && (cid == 1)) ||
11103 +               ((mode & VS_HOSTID) && (id == 0)));
11104 +}
11105 +
11106 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11107 +
11108 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11109 +
11110 +
11111 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11112 +
11113 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11114 +
11115 +#endif
11116 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/context.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/context.h
11117 --- linux-3.4.83/include/linux/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11118 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/context.h      2012-05-21 16:15:05.000000000 +0000
11119 @@ -0,0 +1,188 @@
11120 +#ifndef _VX_CONTEXT_H
11121 +#define _VX_CONTEXT_H
11122 +
11123 +#include <linux/types.h>
11124 +#include <linux/capability.h>
11125 +
11126 +
11127 +/* context flags */
11128 +
11129 +#define VXF_INFO_SCHED         0x00000002
11130 +#define VXF_INFO_NPROC         0x00000004
11131 +#define VXF_INFO_PRIVATE       0x00000008
11132 +
11133 +#define VXF_INFO_INIT          0x00000010
11134 +#define VXF_INFO_HIDE          0x00000020
11135 +#define VXF_INFO_ULIMIT                0x00000040
11136 +#define VXF_INFO_NSPACE                0x00000080
11137 +
11138 +#define VXF_SCHED_HARD         0x00000100
11139 +#define VXF_SCHED_PRIO         0x00000200
11140 +#define VXF_SCHED_PAUSE                0x00000400
11141 +
11142 +#define VXF_VIRT_MEM           0x00010000
11143 +#define VXF_VIRT_UPTIME                0x00020000
11144 +#define VXF_VIRT_CPU           0x00040000
11145 +#define VXF_VIRT_LOAD          0x00080000
11146 +#define VXF_VIRT_TIME          0x00100000
11147 +
11148 +#define VXF_HIDE_MOUNT         0x01000000
11149 +/* was VXF_HIDE_NETIF          0x02000000 */
11150 +#define VXF_HIDE_VINFO         0x04000000
11151 +
11152 +#define VXF_STATE_SETUP                (1ULL << 32)
11153 +#define VXF_STATE_INIT         (1ULL << 33)
11154 +#define VXF_STATE_ADMIN                (1ULL << 34)
11155 +
11156 +#define VXF_SC_HELPER          (1ULL << 36)
11157 +#define VXF_REBOOT_KILL                (1ULL << 37)
11158 +#define VXF_PERSISTENT         (1ULL << 38)
11159 +
11160 +#define VXF_FORK_RSS           (1ULL << 48)
11161 +#define VXF_PROLIFIC           (1ULL << 49)
11162 +
11163 +#define VXF_IGNEG_NICE         (1ULL << 52)
11164 +
11165 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11166 +
11167 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11168 +
11169 +
11170 +/* context migration */
11171 +
11172 +#define VXM_SET_INIT           0x00000001
11173 +#define VXM_SET_REAPER         0x00000002
11174 +
11175 +/* context caps */
11176 +
11177 +#define VXC_SET_UTSNAME                0x00000001
11178 +#define VXC_SET_RLIMIT         0x00000002
11179 +#define VXC_FS_SECURITY                0x00000004
11180 +#define VXC_FS_TRUSTED         0x00000008
11181 +#define VXC_TIOCSTI            0x00000010
11182 +
11183 +/* was VXC_RAW_ICMP            0x00000100 */
11184 +#define VXC_SYSLOG             0x00001000
11185 +#define VXC_OOM_ADJUST         0x00002000
11186 +#define VXC_AUDIT_CONTROL      0x00004000
11187 +
11188 +#define VXC_SECURE_MOUNT       0x00010000
11189 +#define VXC_SECURE_REMOUNT     0x00020000
11190 +#define VXC_BINARY_MOUNT       0x00040000
11191 +
11192 +#define VXC_QUOTA_CTL          0x00100000
11193 +#define VXC_ADMIN_MAPPER       0x00200000
11194 +#define VXC_ADMIN_CLOOP                0x00400000
11195 +
11196 +#define VXC_KTHREAD            0x01000000
11197 +#define VXC_NAMESPACE          0x02000000
11198 +
11199 +
11200 +#ifdef __KERNEL__
11201 +
11202 +#include <linux/list.h>
11203 +#include <linux/spinlock.h>
11204 +#include <linux/rcupdate.h>
11205 +
11206 +#include "limit_def.h"
11207 +#include "sched_def.h"
11208 +#include "cvirt_def.h"
11209 +#include "cacct_def.h"
11210 +#include "device_def.h"
11211 +
11212 +#define VX_SPACES      2
11213 +
11214 +struct _vx_info_pc {
11215 +       struct _vx_sched_pc sched_pc;
11216 +       struct _vx_cvirt_pc cvirt_pc;
11217 +};
11218 +
11219 +struct _vx_space {
11220 +       unsigned long vx_nsmask;                /* assignment mask */
11221 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11222 +       struct fs_struct *vx_fs;                /* private namespace fs */
11223 +       const struct cred *vx_cred;             /* task credentials */
11224 +};
11225 +
11226 +struct vx_info {
11227 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11228 +       xid_t vx_id;                            /* context id */
11229 +       atomic_t vx_usecnt;                     /* usage count */
11230 +       atomic_t vx_tasks;                      /* tasks count */
11231 +       struct vx_info *vx_parent;              /* parent context */
11232 +       int vx_state;                           /* context state */
11233 +
11234 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11235 +
11236 +       uint64_t vx_flags;                      /* context flags */
11237 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11238 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11239 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11240 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11241 +
11242 +       struct task_struct *vx_reaper;          /* guest reaper process */
11243 +       pid_t vx_initpid;                       /* PID of guest init */
11244 +       int64_t vx_badness_bias;                /* OOM points bias */
11245 +
11246 +       struct _vx_limit limit;                 /* vserver limits */
11247 +       struct _vx_sched sched;                 /* vserver scheduler */
11248 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11249 +       struct _vx_cacct cacct;                 /* context accounting */
11250 +
11251 +       struct _vx_device dmap;                 /* default device map targets */
11252 +
11253 +#ifndef CONFIG_SMP
11254 +       struct _vx_info_pc info_pc;             /* per cpu data */
11255 +#else
11256 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11257 +#endif
11258 +
11259 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11260 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11261 +       int exit_code;                          /* last process exit code */
11262 +
11263 +       char vx_name[65];                       /* vserver name */
11264 +};
11265 +
11266 +#ifndef CONFIG_SMP
11267 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11268 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11269 +#else
11270 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11271 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11272 +#endif
11273 +
11274 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11275 +
11276 +
11277 +struct vx_info_save {
11278 +       struct vx_info *vxi;
11279 +       xid_t xid;
11280 +};
11281 +
11282 +
11283 +/* status flags */
11284 +
11285 +#define VXS_HASHED     0x0001
11286 +#define VXS_PAUSED     0x0010
11287 +#define VXS_SHUTDOWN   0x0100
11288 +#define VXS_HELPER     0x1000
11289 +#define VXS_RELEASED   0x8000
11290 +
11291 +
11292 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11293 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11294 +
11295 +extern struct vx_info *lookup_vx_info(int);
11296 +extern struct vx_info *lookup_or_create_vx_info(int);
11297 +
11298 +extern int get_xid_list(int, unsigned int *, int);
11299 +extern int xid_is_hashed(xid_t);
11300 +
11301 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11302 +
11303 +extern long vs_state_change(struct vx_info *, unsigned int);
11304 +
11305 +
11306 +#endif /* __KERNEL__ */
11307 +#endif /* _VX_CONTEXT_H */
11308 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/context_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/context_cmd.h
11309 --- linux-3.4.83/include/linux/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
11310 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/context_cmd.h  2012-05-21 16:15:05.000000000 +0000
11311 @@ -0,0 +1,162 @@
11312 +#ifndef _VX_CONTEXT_CMD_H
11313 +#define _VX_CONTEXT_CMD_H
11314 +
11315 +
11316 +/* vinfo commands */
11317 +
11318 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11319 +
11320 +#ifdef __KERNEL__
11321 +extern int vc_task_xid(uint32_t);
11322 +
11323 +#endif /* __KERNEL__ */
11324 +
11325 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11326 +
11327 +struct vcmd_vx_info_v0 {
11328 +       uint32_t xid;
11329 +       uint32_t initpid;
11330 +       /* more to come */
11331 +};
11332 +
11333 +#ifdef __KERNEL__
11334 +extern int vc_vx_info(struct vx_info *, void __user *);
11335 +
11336 +#endif /* __KERNEL__ */
11337 +
11338 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11339 +
11340 +struct vcmd_ctx_stat_v0 {
11341 +       uint32_t usecnt;
11342 +       uint32_t tasks;
11343 +       /* more to come */
11344 +};
11345 +
11346 +#ifdef __KERNEL__
11347 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11348 +
11349 +#endif /* __KERNEL__ */
11350 +
11351 +/* context commands */
11352 +
11353 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11354 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11355 +
11356 +struct vcmd_ctx_create {
11357 +       uint64_t flagword;
11358 +};
11359 +
11360 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11361 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11362 +
11363 +struct vcmd_ctx_migrate {
11364 +       uint64_t flagword;
11365 +};
11366 +
11367 +#ifdef __KERNEL__
11368 +extern int vc_ctx_create(uint32_t, void __user *);
11369 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11370 +
11371 +#endif /* __KERNEL__ */
11372 +
11373 +
11374 +/* flag commands */
11375 +
11376 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11377 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11378 +
11379 +struct vcmd_ctx_flags_v0 {
11380 +       uint64_t flagword;
11381 +       uint64_t mask;
11382 +};
11383 +
11384 +#ifdef __KERNEL__
11385 +extern int vc_get_cflags(struct vx_info *, void __user *);
11386 +extern int vc_set_cflags(struct vx_info *, void __user *);
11387 +
11388 +#endif /* __KERNEL__ */
11389 +
11390 +
11391 +/* context caps commands */
11392 +
11393 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11394 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11395 +
11396 +struct vcmd_ctx_caps_v1 {
11397 +       uint64_t ccaps;
11398 +       uint64_t cmask;
11399 +};
11400 +
11401 +#ifdef __KERNEL__
11402 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11403 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11404 +
11405 +#endif /* __KERNEL__ */
11406 +
11407 +
11408 +/* bcaps commands */
11409 +
11410 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11411 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11412 +
11413 +struct vcmd_bcaps {
11414 +       uint64_t bcaps;
11415 +       uint64_t bmask;
11416 +};
11417 +
11418 +#ifdef __KERNEL__
11419 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11420 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11421 +
11422 +#endif /* __KERNEL__ */
11423 +
11424 +
11425 +/* umask commands */
11426 +
11427 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11428 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11429 +
11430 +struct vcmd_umask {
11431 +       uint64_t umask;
11432 +       uint64_t mask;
11433 +};
11434 +
11435 +#ifdef __KERNEL__
11436 +extern int vc_get_umask(struct vx_info *, void __user *);
11437 +extern int vc_set_umask(struct vx_info *, void __user *);
11438 +
11439 +#endif /* __KERNEL__ */
11440 +
11441 +
11442 +/* wmask commands */
11443 +
11444 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11445 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11446 +
11447 +struct vcmd_wmask {
11448 +       uint64_t wmask;
11449 +       uint64_t mask;
11450 +};
11451 +
11452 +#ifdef __KERNEL__
11453 +extern int vc_get_wmask(struct vx_info *, void __user *);
11454 +extern int vc_set_wmask(struct vx_info *, void __user *);
11455 +
11456 +#endif /* __KERNEL__ */
11457 +
11458 +
11459 +/* OOM badness */
11460 +
11461 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11462 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11463 +
11464 +struct vcmd_badness_v0 {
11465 +       int64_t bias;
11466 +};
11467 +
11468 +#ifdef __KERNEL__
11469 +extern int vc_get_badness(struct vx_info *, void __user *);
11470 +extern int vc_set_badness(struct vx_info *, void __user *);
11471 +
11472 +#endif /* __KERNEL__ */
11473 +#endif /* _VX_CONTEXT_CMD_H */
11474 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cvirt.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cvirt.h
11475 --- linux-3.4.83/include/linux/vserver/cvirt.h  1970-01-01 00:00:00.000000000 +0000
11476 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cvirt.h        2012-05-21 16:15:05.000000000 +0000
11477 @@ -0,0 +1,22 @@
11478 +#ifndef _VX_CVIRT_H
11479 +#define _VX_CVIRT_H
11480 +
11481 +
11482 +#ifdef __KERNEL__
11483 +
11484 +struct timespec;
11485 +
11486 +void vx_vsi_boottime(struct timespec *);
11487 +
11488 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11489 +
11490 +
11491 +struct vx_info;
11492 +
11493 +void vx_update_load(struct vx_info *);
11494 +
11495 +
11496 +int vx_do_syslog(int, char __user *, int);
11497 +
11498 +#endif /* __KERNEL__ */
11499 +#endif /* _VX_CVIRT_H */
11500 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cvirt_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cvirt_cmd.h
11501 --- linux-3.4.83/include/linux/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
11502 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cvirt_cmd.h    2012-05-21 16:15:05.000000000 +0000
11503 @@ -0,0 +1,53 @@
11504 +#ifndef _VX_CVIRT_CMD_H
11505 +#define _VX_CVIRT_CMD_H
11506 +
11507 +
11508 +/* virtual host info name commands */
11509 +
11510 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11511 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11512 +
11513 +struct vcmd_vhi_name_v0 {
11514 +       uint32_t field;
11515 +       char name[65];
11516 +};
11517 +
11518 +
11519 +enum vhi_name_field {
11520 +       VHIN_CONTEXT = 0,
11521 +       VHIN_SYSNAME,
11522 +       VHIN_NODENAME,
11523 +       VHIN_RELEASE,
11524 +       VHIN_VERSION,
11525 +       VHIN_MACHINE,
11526 +       VHIN_DOMAINNAME,
11527 +};
11528 +
11529 +
11530 +#ifdef __KERNEL__
11531 +
11532 +#include <linux/compiler.h>
11533 +
11534 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11535 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11536 +
11537 +#endif /* __KERNEL__ */
11538 +
11539 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11540 +
11541 +struct vcmd_virt_stat_v0 {
11542 +       uint64_t offset;
11543 +       uint64_t uptime;
11544 +       uint32_t nr_threads;
11545 +       uint32_t nr_running;
11546 +       uint32_t nr_uninterruptible;
11547 +       uint32_t nr_onhold;
11548 +       uint32_t nr_forks;
11549 +       uint32_t load[3];
11550 +};
11551 +
11552 +#ifdef __KERNEL__
11553 +extern int vc_virt_stat(struct vx_info *, void __user *);
11554 +
11555 +#endif /* __KERNEL__ */
11556 +#endif /* _VX_CVIRT_CMD_H */
11557 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/cvirt_def.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/cvirt_def.h
11558 --- linux-3.4.83/include/linux/vserver/cvirt_def.h      1970-01-01 00:00:00.000000000 +0000
11559 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/cvirt_def.h    2012-05-21 16:15:05.000000000 +0000
11560 @@ -0,0 +1,80 @@
11561 +#ifndef _VX_CVIRT_DEF_H
11562 +#define _VX_CVIRT_DEF_H
11563 +
11564 +#include <linux/jiffies.h>
11565 +#include <linux/spinlock.h>
11566 +#include <linux/wait.h>
11567 +#include <linux/time.h>
11568 +#include <asm/atomic.h>
11569 +
11570 +
11571 +struct _vx_usage_stat {
11572 +       uint64_t user;
11573 +       uint64_t nice;
11574 +       uint64_t system;
11575 +       uint64_t softirq;
11576 +       uint64_t irq;
11577 +       uint64_t idle;
11578 +       uint64_t iowait;
11579 +};
11580 +
11581 +struct _vx_syslog {
11582 +       wait_queue_head_t log_wait;
11583 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11584 +
11585 +       unsigned long log_start;        /* next char to be read by syslog() */
11586 +       unsigned long con_start;        /* next char to be sent to consoles */
11587 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11588 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11589 +
11590 +       char log_buf[1024];
11591 +};
11592 +
11593 +
11594 +/* context sub struct */
11595 +
11596 +struct _vx_cvirt {
11597 +       atomic_t nr_threads;            /* number of current threads */
11598 +       atomic_t nr_running;            /* number of running threads */
11599 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11600 +
11601 +       atomic_t nr_onhold;             /* processes on hold */
11602 +       uint32_t onhold_last;           /* jiffies when put on hold */
11603 +
11604 +       struct timespec bias_ts;        /* time offset to the host */
11605 +       struct timespec bias_idle;
11606 +       struct timespec bias_uptime;    /* context creation point */
11607 +       uint64_t bias_clock;            /* offset in clock_t */
11608 +
11609 +       spinlock_t load_lock;           /* lock for the load averages */
11610 +       atomic_t load_updates;          /* nr of load updates done so far */
11611 +       uint32_t load_last;             /* last time load was calculated */
11612 +       uint32_t load[3];               /* load averages 1,5,15 */
11613 +
11614 +       atomic_t total_forks;           /* number of forks so far */
11615 +
11616 +       struct _vx_syslog syslog;
11617 +};
11618 +
11619 +struct _vx_cvirt_pc {
11620 +       struct _vx_usage_stat cpustat;
11621 +};
11622 +
11623 +
11624 +#ifdef CONFIG_VSERVER_DEBUG
11625 +
11626 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11627 +{
11628 +       printk("\t_vx_cvirt:\n");
11629 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11630 +               atomic_read(&cvirt->nr_threads),
11631 +               atomic_read(&cvirt->nr_running),
11632 +               atomic_read(&cvirt->nr_uninterruptible),
11633 +               atomic_read(&cvirt->nr_onhold));
11634 +       /* add rest here */
11635 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11636 +}
11637 +
11638 +#endif
11639 +
11640 +#endif /* _VX_CVIRT_DEF_H */
11641 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/debug.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/debug.h
11642 --- linux-3.4.83/include/linux/vserver/debug.h  1970-01-01 00:00:00.000000000 +0000
11643 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/debug.h        2012-05-21 16:15:05.000000000 +0000
11644 @@ -0,0 +1,145 @@
11645 +#ifndef _VX_DEBUG_H
11646 +#define _VX_DEBUG_H
11647 +
11648 +
11649 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11650 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11651 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11652 +
11653 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11654 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11655 +#define VXF_DEV                "%p[%lu,%d:%d]"
11656 +
11657 +#if    defined(CONFIG_QUOTES_UTF8)
11658 +#define        VS_Q_LQM        "\xc2\xbb"
11659 +#define        VS_Q_RQM        "\xc2\xab"
11660 +#elif  defined(CONFIG_QUOTES_ASCII)
11661 +#define        VS_Q_LQM        "\x27"
11662 +#define        VS_Q_RQM        "\x27"
11663 +#else
11664 +#define        VS_Q_LQM        "\xbb"
11665 +#define        VS_Q_RQM        "\xab"
11666 +#endif
11667 +
11668 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11669 +
11670 +
11671 +#define vxd_path(p)                                            \
11672 +       ({ static char _buffer[PATH_MAX];                       \
11673 +          d_path(p, _buffer, sizeof(_buffer)); })
11674 +
11675 +#define vxd_cond_path(n)                                       \
11676 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11677 +
11678 +
11679 +#ifdef CONFIG_VSERVER_DEBUG
11680 +
11681 +extern unsigned int vs_debug_switch;
11682 +extern unsigned int vs_debug_xid;
11683 +extern unsigned int vs_debug_nid;
11684 +extern unsigned int vs_debug_tag;
11685 +extern unsigned int vs_debug_net;
11686 +extern unsigned int vs_debug_limit;
11687 +extern unsigned int vs_debug_cres;
11688 +extern unsigned int vs_debug_dlim;
11689 +extern unsigned int vs_debug_quota;
11690 +extern unsigned int vs_debug_cvirt;
11691 +extern unsigned int vs_debug_space;
11692 +extern unsigned int vs_debug_perm;
11693 +extern unsigned int vs_debug_misc;
11694 +
11695 +
11696 +#define VX_LOGLEVEL    "vxD: "
11697 +#define VX_PROC_FMT    "%p: "
11698 +#define VX_PROCESS     current
11699 +
11700 +#define vxdprintk(c, f, x...)                                  \
11701 +       do {                                                    \
11702 +               if (c)                                          \
11703 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11704 +                               VX_PROCESS , ##x);              \
11705 +       } while (0)
11706 +
11707 +#define vxlprintk(c, f, x...)                                  \
11708 +       do {                                                    \
11709 +               if (c)                                          \
11710 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11711 +       } while (0)
11712 +
11713 +#define vxfprintk(c, f, x...)                                  \
11714 +       do {                                                    \
11715 +               if (c)                                          \
11716 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11717 +       } while (0)
11718 +
11719 +
11720 +struct vx_info;
11721 +
11722 +void dump_vx_info(struct vx_info *, int);
11723 +void dump_vx_info_inactive(int);
11724 +
11725 +#else  /* CONFIG_VSERVER_DEBUG */
11726 +
11727 +#define vs_debug_switch        0
11728 +#define vs_debug_xid   0
11729 +#define vs_debug_nid   0
11730 +#define vs_debug_tag   0
11731 +#define vs_debug_net   0
11732 +#define vs_debug_limit 0
11733 +#define vs_debug_cres  0
11734 +#define vs_debug_dlim  0
11735 +#define vs_debug_quota 0
11736 +#define vs_debug_cvirt 0
11737 +#define vs_debug_space 0
11738 +#define vs_debug_perm  0
11739 +#define vs_debug_misc  0
11740 +
11741 +#define vxdprintk(x...) do { } while (0)
11742 +#define vxlprintk(x...) do { } while (0)
11743 +#define vxfprintk(x...) do { } while (0)
11744 +
11745 +#endif /* CONFIG_VSERVER_DEBUG */
11746 +
11747 +
11748 +#ifdef CONFIG_VSERVER_WARN
11749 +
11750 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11751 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11752 +#define VX_WARN_XID    "[xid #%u] "
11753 +#define VX_WARN_NID    "[nid #%u] "
11754 +#define VX_WARN_TAG    "[tag #%u] "
11755 +
11756 +#define vxwprintk(c, f, x...)                                  \
11757 +       do {                                                    \
11758 +               if (c)                                          \
11759 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11760 +       } while (0)
11761 +
11762 +#else  /* CONFIG_VSERVER_WARN */
11763 +
11764 +#define vxwprintk(x...) do { } while (0)
11765 +
11766 +#endif /* CONFIG_VSERVER_WARN */
11767 +
11768 +#define vxwprintk_task(c, f, x...)                             \
11769 +       vxwprintk(c, VX_WARN_TASK f,                            \
11770 +               current->comm, current->pid,                    \
11771 +               current->xid, current->nid, current->tag, ##x)
11772 +#define vxwprintk_xid(c, f, x...)                              \
11773 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11774 +#define vxwprintk_nid(c, f, x...)                              \
11775 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11776 +#define vxwprintk_tag(c, f, x...)                              \
11777 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11778 +
11779 +#ifdef CONFIG_VSERVER_DEBUG
11780 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11781 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11782 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11783 +#else
11784 +#define vxd_assert_lock(l)     do { } while (0)
11785 +#define vxd_assert(c, f, x...) do { } while (0)
11786 +#endif
11787 +
11788 +
11789 +#endif /* _VX_DEBUG_H */
11790 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/debug_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/debug_cmd.h
11791 --- linux-3.4.83/include/linux/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
11792 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/debug_cmd.h    2012-05-21 16:15:05.000000000 +0000
11793 @@ -0,0 +1,58 @@
11794 +#ifndef _VX_DEBUG_CMD_H
11795 +#define _VX_DEBUG_CMD_H
11796 +
11797 +
11798 +/* debug commands */
11799 +
11800 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11801 +
11802 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11803 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11804 +
11805 +struct  vcmd_read_history_v0 {
11806 +       uint32_t index;
11807 +       uint32_t count;
11808 +       char __user *data;
11809 +};
11810 +
11811 +struct  vcmd_read_monitor_v0 {
11812 +       uint32_t index;
11813 +       uint32_t count;
11814 +       char __user *data;
11815 +};
11816 +
11817 +
11818 +#ifdef __KERNEL__
11819 +
11820 +#ifdef CONFIG_COMPAT
11821 +
11822 +#include <asm/compat.h>
11823 +
11824 +struct vcmd_read_history_v0_x32 {
11825 +       uint32_t index;
11826 +       uint32_t count;
11827 +       compat_uptr_t data_ptr;
11828 +};
11829 +
11830 +struct vcmd_read_monitor_v0_x32 {
11831 +       uint32_t index;
11832 +       uint32_t count;
11833 +       compat_uptr_t data_ptr;
11834 +};
11835 +
11836 +#endif  /* CONFIG_COMPAT */
11837 +
11838 +extern int vc_dump_history(uint32_t);
11839 +
11840 +extern int vc_read_history(uint32_t, void __user *);
11841 +extern int vc_read_monitor(uint32_t, void __user *);
11842 +
11843 +#ifdef CONFIG_COMPAT
11844 +
11845 +extern int vc_read_history_x32(uint32_t, void __user *);
11846 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11847 +
11848 +#endif  /* CONFIG_COMPAT */
11849 +
11850 +#endif /* __KERNEL__ */
11851 +#endif /* _VX_DEBUG_CMD_H */
11852 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/device.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/device.h
11853 --- linux-3.4.83/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11854 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/device.h       2012-05-21 16:15:05.000000000 +0000
11855 @@ -0,0 +1,15 @@
11856 +#ifndef _VX_DEVICE_H
11857 +#define _VX_DEVICE_H
11858 +
11859 +
11860 +#define DATTR_CREATE   0x00000001
11861 +#define DATTR_OPEN     0x00000002
11862 +
11863 +#define DATTR_REMAP    0x00000010
11864 +
11865 +#define DATTR_MASK     0x00000013
11866 +
11867 +
11868 +#else  /* _VX_DEVICE_H */
11869 +#warning duplicate inclusion
11870 +#endif /* _VX_DEVICE_H */
11871 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/device_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/device_cmd.h
11872 --- linux-3.4.83/include/linux/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
11873 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/device_cmd.h   2012-05-21 16:15:05.000000000 +0000
11874 @@ -0,0 +1,44 @@
11875 +#ifndef _VX_DEVICE_CMD_H
11876 +#define _VX_DEVICE_CMD_H
11877 +
11878 +
11879 +/*  device vserver commands */
11880 +
11881 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11882 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11883 +
11884 +struct vcmd_set_mapping_v0 {
11885 +       const char __user *device;
11886 +       const char __user *target;
11887 +       uint32_t flags;
11888 +};
11889 +
11890 +
11891 +#ifdef __KERNEL__
11892 +
11893 +#ifdef CONFIG_COMPAT
11894 +
11895 +#include <asm/compat.h>
11896 +
11897 +struct vcmd_set_mapping_v0_x32 {
11898 +       compat_uptr_t device_ptr;
11899 +       compat_uptr_t target_ptr;
11900 +       uint32_t flags;
11901 +};
11902 +
11903 +#endif /* CONFIG_COMPAT */
11904 +
11905 +#include <linux/compiler.h>
11906 +
11907 +extern int vc_set_mapping(struct vx_info *, void __user *);
11908 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11909 +
11910 +#ifdef CONFIG_COMPAT
11911 +
11912 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11913 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11914 +
11915 +#endif /* CONFIG_COMPAT */
11916 +
11917 +#endif /* __KERNEL__ */
11918 +#endif /* _VX_DEVICE_CMD_H */
11919 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/device_def.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/device_def.h
11920 --- linux-3.4.83/include/linux/vserver/device_def.h     1970-01-01 00:00:00.000000000 +0000
11921 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/device_def.h   2012-05-21 16:15:05.000000000 +0000
11922 @@ -0,0 +1,17 @@
11923 +#ifndef _VX_DEVICE_DEF_H
11924 +#define _VX_DEVICE_DEF_H
11925 +
11926 +#include <linux/types.h>
11927 +
11928 +struct vx_dmap_target {
11929 +       dev_t target;
11930 +       uint32_t flags;
11931 +};
11932 +
11933 +struct _vx_device {
11934 +#ifdef CONFIG_VSERVER_DEVICE
11935 +       struct vx_dmap_target targets[2];
11936 +#endif
11937 +};
11938 +
11939 +#endif /* _VX_DEVICE_DEF_H */
11940 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/dlimit.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/dlimit.h
11941 --- linux-3.4.83/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
11942 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/dlimit.h       2012-05-21 16:15:05.000000000 +0000
11943 @@ -0,0 +1,54 @@
11944 +#ifndef _VX_DLIMIT_H
11945 +#define _VX_DLIMIT_H
11946 +
11947 +#include "switch.h"
11948 +
11949 +
11950 +#ifdef __KERNEL__
11951 +
11952 +/*      keep in sync with CDLIM_INFINITY       */
11953 +
11954 +#define DLIM_INFINITY          (~0ULL)
11955 +
11956 +#include <linux/spinlock.h>
11957 +#include <linux/rcupdate.h>
11958 +
11959 +struct super_block;
11960 +
11961 +struct dl_info {
11962 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11963 +       struct rcu_head dl_rcu;                 /* the rcu head */
11964 +       tag_t dl_tag;                           /* context tag */
11965 +       atomic_t dl_usecnt;                     /* usage count */
11966 +       atomic_t dl_refcnt;                     /* reference count */
11967 +
11968 +       struct super_block *dl_sb;              /* associated superblock */
11969 +
11970 +       spinlock_t dl_lock;                     /* protect the values */
11971 +
11972 +       unsigned long long dl_space_used;       /* used space in bytes */
11973 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11974 +       unsigned long dl_inodes_used;           /* used inodes */
11975 +       unsigned long dl_inodes_total;          /* maximum inodes */
11976 +
11977 +       unsigned int dl_nrlmult;                /* non root limit mult */
11978 +};
11979 +
11980 +struct rcu_head;
11981 +
11982 +extern void rcu_free_dl_info(struct rcu_head *);
11983 +extern void unhash_dl_info(struct dl_info *);
11984 +
11985 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11986 +
11987 +
11988 +struct kstatfs;
11989 +
11990 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11991 +
11992 +typedef uint64_t dlsize_t;
11993 +
11994 +#endif /* __KERNEL__ */
11995 +#else  /* _VX_DLIMIT_H */
11996 +#warning duplicate inclusion
11997 +#endif /* _VX_DLIMIT_H */
11998 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/dlimit_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/dlimit_cmd.h
11999 --- linux-3.4.83/include/linux/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12000 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/dlimit_cmd.h   2012-05-21 16:15:05.000000000 +0000
12001 @@ -0,0 +1,109 @@
12002 +#ifndef _VX_DLIMIT_CMD_H
12003 +#define _VX_DLIMIT_CMD_H
12004 +
12005 +
12006 +/*  dlimit vserver commands */
12007 +
12008 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12009 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12010 +
12011 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12012 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12013 +
12014 +struct vcmd_ctx_dlimit_base_v0 {
12015 +       const char __user *name;
12016 +       uint32_t flags;
12017 +};
12018 +
12019 +struct vcmd_ctx_dlimit_v0 {
12020 +       const char __user *name;
12021 +       uint32_t space_used;                    /* used space in kbytes */
12022 +       uint32_t space_total;                   /* maximum space in kbytes */
12023 +       uint32_t inodes_used;                   /* used inodes */
12024 +       uint32_t inodes_total;                  /* maximum inodes */
12025 +       uint32_t reserved;                      /* reserved for root in % */
12026 +       uint32_t flags;
12027 +};
12028 +
12029 +#define CDLIM_UNSET            ((uint32_t)0UL)
12030 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12031 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12032 +
12033 +#define DLIME_UNIT     0
12034 +#define DLIME_KILO     1
12035 +#define DLIME_MEGA     2
12036 +#define DLIME_GIGA     3
12037 +
12038 +#define DLIMF_SHIFT    0x10
12039 +
12040 +#define DLIMS_USED     0
12041 +#define DLIMS_TOTAL    2
12042 +
12043 +static inline
12044 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12045 +{
12046 +       int exp = (flags & DLIMF_SHIFT) ?
12047 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12048 +       return ((uint64_t)val) << (10 * exp);
12049 +}
12050 +
12051 +static inline
12052 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12053 +{
12054 +       int exp = 0;
12055 +
12056 +       if (*flags & DLIMF_SHIFT) {
12057 +               while (val > (1LL << 32) && (exp < 3)) {
12058 +                       val >>= 10;
12059 +                       exp++;
12060 +               }
12061 +               *flags &= ~(DLIME_GIGA << shift);
12062 +               *flags |= exp << shift;
12063 +       } else
12064 +               val >>= 10;
12065 +       return val;
12066 +}
12067 +
12068 +#ifdef __KERNEL__
12069 +
12070 +#ifdef CONFIG_COMPAT
12071 +
12072 +#include <asm/compat.h>
12073 +
12074 +struct vcmd_ctx_dlimit_base_v0_x32 {
12075 +       compat_uptr_t name_ptr;
12076 +       uint32_t flags;
12077 +};
12078 +
12079 +struct vcmd_ctx_dlimit_v0_x32 {
12080 +       compat_uptr_t name_ptr;
12081 +       uint32_t space_used;                    /* used space in kbytes */
12082 +       uint32_t space_total;                   /* maximum space in kbytes */
12083 +       uint32_t inodes_used;                   /* used inodes */
12084 +       uint32_t inodes_total;                  /* maximum inodes */
12085 +       uint32_t reserved;                      /* reserved for root in % */
12086 +       uint32_t flags;
12087 +};
12088 +
12089 +#endif /* CONFIG_COMPAT */
12090 +
12091 +#include <linux/compiler.h>
12092 +
12093 +extern int vc_add_dlimit(uint32_t, void __user *);
12094 +extern int vc_rem_dlimit(uint32_t, void __user *);
12095 +
12096 +extern int vc_set_dlimit(uint32_t, void __user *);
12097 +extern int vc_get_dlimit(uint32_t, void __user *);
12098 +
12099 +#ifdef CONFIG_COMPAT
12100 +
12101 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12102 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12103 +
12104 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12105 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12106 +
12107 +#endif /* CONFIG_COMPAT */
12108 +
12109 +#endif /* __KERNEL__ */
12110 +#endif /* _VX_DLIMIT_CMD_H */
12111 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/global.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/global.h
12112 --- linux-3.4.83/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
12113 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/global.h       2012-05-21 16:15:05.000000000 +0000
12114 @@ -0,0 +1,19 @@
12115 +#ifndef _VX_GLOBAL_H
12116 +#define _VX_GLOBAL_H
12117 +
12118 +
12119 +extern atomic_t vx_global_ctotal;
12120 +extern atomic_t vx_global_cactive;
12121 +
12122 +extern atomic_t nx_global_ctotal;
12123 +extern atomic_t nx_global_cactive;
12124 +
12125 +extern atomic_t vs_global_nsproxy;
12126 +extern atomic_t vs_global_fs;
12127 +extern atomic_t vs_global_mnt_ns;
12128 +extern atomic_t vs_global_uts_ns;
12129 +extern atomic_t vs_global_user_ns;
12130 +extern atomic_t vs_global_pid_ns;
12131 +
12132 +
12133 +#endif /* _VX_GLOBAL_H */
12134 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/history.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/history.h
12135 --- linux-3.4.83/include/linux/vserver/history.h        1970-01-01 00:00:00.000000000 +0000
12136 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/history.h      2012-05-21 16:15:05.000000000 +0000
12137 @@ -0,0 +1,197 @@
12138 +#ifndef _VX_HISTORY_H
12139 +#define _VX_HISTORY_H
12140 +
12141 +
12142 +enum {
12143 +       VXH_UNUSED = 0,
12144 +       VXH_THROW_OOPS = 1,
12145 +
12146 +       VXH_GET_VX_INFO,
12147 +       VXH_PUT_VX_INFO,
12148 +       VXH_INIT_VX_INFO,
12149 +       VXH_SET_VX_INFO,
12150 +       VXH_CLR_VX_INFO,
12151 +       VXH_CLAIM_VX_INFO,
12152 +       VXH_RELEASE_VX_INFO,
12153 +       VXH_ALLOC_VX_INFO,
12154 +       VXH_DEALLOC_VX_INFO,
12155 +       VXH_HASH_VX_INFO,
12156 +       VXH_UNHASH_VX_INFO,
12157 +       VXH_LOC_VX_INFO,
12158 +       VXH_LOOKUP_VX_INFO,
12159 +       VXH_CREATE_VX_INFO,
12160 +};
12161 +
12162 +struct _vxhe_vxi {
12163 +       struct vx_info *ptr;
12164 +       unsigned xid;
12165 +       unsigned usecnt;
12166 +       unsigned tasks;
12167 +};
12168 +
12169 +struct _vxhe_set_clr {
12170 +       void *data;
12171 +};
12172 +
12173 +struct _vxhe_loc_lookup {
12174 +       unsigned arg;
12175 +};
12176 +
12177 +struct _vx_hist_entry {
12178 +       void *loc;
12179 +       unsigned short seq;
12180 +       unsigned short type;
12181 +       struct _vxhe_vxi vxi;
12182 +       union {
12183 +               struct _vxhe_set_clr sc;
12184 +               struct _vxhe_loc_lookup ll;
12185 +       };
12186 +};
12187 +
12188 +#ifdef CONFIG_VSERVER_HISTORY
12189 +
12190 +extern unsigned volatile int vxh_active;
12191 +
12192 +struct _vx_hist_entry *vxh_advance(void *loc);
12193 +
12194 +
12195 +static inline
12196 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12197 +{
12198 +       entry->vxi.ptr = vxi;
12199 +       if (vxi) {
12200 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12201 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12202 +               entry->vxi.xid = vxi->vx_id;
12203 +       }
12204 +}
12205 +
12206 +
12207 +#define        __HERE__ current_text_addr()
12208 +
12209 +#define __VXH_BODY(__type, __data, __here)     \
12210 +       struct _vx_hist_entry *entry;           \
12211 +                                               \
12212 +       preempt_disable();                      \
12213 +       entry = vxh_advance(__here);            \
12214 +       __data;                                 \
12215 +       entry->type = __type;                   \
12216 +       preempt_enable();
12217 +
12218 +
12219 +       /* pass vxi only */
12220 +
12221 +#define __VXH_SMPL                             \
12222 +       __vxh_copy_vxi(entry, vxi)
12223 +
12224 +static inline
12225 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12226 +{
12227 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12228 +}
12229 +
12230 +       /* pass vxi and data (void *) */
12231 +
12232 +#define __VXH_DATA                             \
12233 +       __vxh_copy_vxi(entry, vxi);             \
12234 +       entry->sc.data = data
12235 +
12236 +static inline
12237 +void   __vxh_data(struct vx_info *vxi, void *data,
12238 +                       int __type, void *__here)
12239 +{
12240 +       __VXH_BODY(__type, __VXH_DATA, __here)
12241 +}
12242 +
12243 +       /* pass vxi and arg (long) */
12244 +
12245 +#define __VXH_LONG                             \
12246 +       __vxh_copy_vxi(entry, vxi);             \
12247 +       entry->ll.arg = arg
12248 +
12249 +static inline
12250 +void   __vxh_long(struct vx_info *vxi, long arg,
12251 +                       int __type, void *__here)
12252 +{
12253 +       __VXH_BODY(__type, __VXH_LONG, __here)
12254 +}
12255 +
12256 +
12257 +static inline
12258 +void   __vxh_throw_oops(void *__here)
12259 +{
12260 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12261 +       /* prevent further acquisition */
12262 +       vxh_active = 0;
12263 +}
12264 +
12265 +
12266 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12267 +
12268 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12269 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12270 +
12271 +#define __vxh_init_vx_info(v, d, h) \
12272 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12273 +#define __vxh_set_vx_info(v, d, h) \
12274 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12275 +#define __vxh_clr_vx_info(v, d, h) \
12276 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12277 +
12278 +#define __vxh_claim_vx_info(v, d, h) \
12279 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12280 +#define __vxh_release_vx_info(v, d, h) \
12281 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12282 +
12283 +#define vxh_alloc_vx_info(v) \
12284 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12285 +#define vxh_dealloc_vx_info(v) \
12286 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12287 +
12288 +#define vxh_hash_vx_info(v) \
12289 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12290 +#define vxh_unhash_vx_info(v) \
12291 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12292 +
12293 +#define vxh_loc_vx_info(v, l) \
12294 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12295 +#define vxh_lookup_vx_info(v, l) \
12296 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12297 +#define vxh_create_vx_info(v, l) \
12298 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12299 +
12300 +extern void vxh_dump_history(void);
12301 +
12302 +
12303 +#else  /* CONFIG_VSERVER_HISTORY */
12304 +
12305 +#define        __HERE__        0
12306 +
12307 +#define vxh_throw_oops()               do { } while (0)
12308 +
12309 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12310 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12311 +
12312 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12313 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12314 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12315 +
12316 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12317 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12318 +
12319 +#define vxh_alloc_vx_info(v)           do { } while (0)
12320 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12321 +
12322 +#define vxh_hash_vx_info(v)            do { } while (0)
12323 +#define vxh_unhash_vx_info(v)          do { } while (0)
12324 +
12325 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12326 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12327 +#define vxh_create_vx_info(v, l)       do { } while (0)
12328 +
12329 +#define vxh_dump_history()             do { } while (0)
12330 +
12331 +
12332 +#endif /* CONFIG_VSERVER_HISTORY */
12333 +
12334 +#endif /* _VX_HISTORY_H */
12335 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/inode.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/inode.h
12336 --- linux-3.4.83/include/linux/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12337 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/inode.h        2012-05-21 16:15:05.000000000 +0000
12338 @@ -0,0 +1,39 @@
12339 +#ifndef _VX_INODE_H
12340 +#define _VX_INODE_H
12341 +
12342 +
12343 +#define IATTR_TAG      0x01000000
12344 +
12345 +#define IATTR_ADMIN    0x00000001
12346 +#define IATTR_WATCH    0x00000002
12347 +#define IATTR_HIDE     0x00000004
12348 +#define IATTR_FLAGS    0x00000007
12349 +
12350 +#define IATTR_BARRIER  0x00010000
12351 +#define IATTR_IXUNLINK 0x00020000
12352 +#define IATTR_IMMUTABLE 0x00040000
12353 +#define IATTR_COW      0x00080000
12354 +
12355 +#ifdef __KERNEL__
12356 +
12357 +
12358 +#ifdef CONFIG_VSERVER_PROC_SECURE
12359 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12360 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12361 +#else
12362 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12363 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12364 +#endif
12365 +
12366 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12367 +
12368 +#endif /* __KERNEL__ */
12369 +
12370 +/* inode ioctls */
12371 +
12372 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12373 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12374 +
12375 +#else  /* _VX_INODE_H */
12376 +#warning duplicate inclusion
12377 +#endif /* _VX_INODE_H */
12378 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/inode_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/inode_cmd.h
12379 --- linux-3.4.83/include/linux/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12380 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/inode_cmd.h    2012-05-21 16:15:05.000000000 +0000
12381 @@ -0,0 +1,59 @@
12382 +#ifndef _VX_INODE_CMD_H
12383 +#define _VX_INODE_CMD_H
12384 +
12385 +
12386 +/*  inode vserver commands */
12387 +
12388 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12389 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12390 +
12391 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12392 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12393 +
12394 +struct vcmd_ctx_iattr_v1 {
12395 +       const char __user *name;
12396 +       uint32_t tag;
12397 +       uint32_t flags;
12398 +       uint32_t mask;
12399 +};
12400 +
12401 +struct vcmd_ctx_fiattr_v0 {
12402 +       uint32_t tag;
12403 +       uint32_t flags;
12404 +       uint32_t mask;
12405 +};
12406 +
12407 +
12408 +#ifdef __KERNEL__
12409 +
12410 +
12411 +#ifdef CONFIG_COMPAT
12412 +
12413 +#include <asm/compat.h>
12414 +
12415 +struct vcmd_ctx_iattr_v1_x32 {
12416 +       compat_uptr_t name_ptr;
12417 +       uint32_t tag;
12418 +       uint32_t flags;
12419 +       uint32_t mask;
12420 +};
12421 +
12422 +#endif /* CONFIG_COMPAT */
12423 +
12424 +#include <linux/compiler.h>
12425 +
12426 +extern int vc_get_iattr(void __user *);
12427 +extern int vc_set_iattr(void __user *);
12428 +
12429 +extern int vc_fget_iattr(uint32_t, void __user *);
12430 +extern int vc_fset_iattr(uint32_t, void __user *);
12431 +
12432 +#ifdef CONFIG_COMPAT
12433 +
12434 +extern int vc_get_iattr_x32(void __user *);
12435 +extern int vc_set_iattr_x32(void __user *);
12436 +
12437 +#endif /* CONFIG_COMPAT */
12438 +
12439 +#endif /* __KERNEL__ */
12440 +#endif /* _VX_INODE_CMD_H */
12441 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/limit.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit.h
12442 --- linux-3.4.83/include/linux/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12443 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit.h        2012-05-21 16:15:05.000000000 +0000
12444 @@ -0,0 +1,71 @@
12445 +#ifndef _VX_LIMIT_H
12446 +#define _VX_LIMIT_H
12447 +
12448 +#define VLIMIT_NSOCK   16
12449 +#define VLIMIT_OPENFD  17
12450 +#define VLIMIT_ANON    18
12451 +#define VLIMIT_SHMEM   19
12452 +#define VLIMIT_SEMARY  20
12453 +#define VLIMIT_NSEMS   21
12454 +#define VLIMIT_DENTRY  22
12455 +#define VLIMIT_MAPPED  23
12456 +
12457 +
12458 +#ifdef __KERNEL__
12459 +
12460 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12461 +
12462 +/*     keep in sync with CRLIM_INFINITY */
12463 +
12464 +#define        VLIM_INFINITY   (~0ULL)
12465 +
12466 +#include <asm/atomic.h>
12467 +#include <asm/resource.h>
12468 +
12469 +#ifndef RLIM_INFINITY
12470 +#warning RLIM_INFINITY is undefined
12471 +#endif
12472 +
12473 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12474 +
12475 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12476 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12477 +
12478 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12479 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12480 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12481 +
12482 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12483 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12484 +
12485 +typedef atomic_long_t rlim_atomic_t;
12486 +typedef unsigned long rlim_t;
12487 +
12488 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12489 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12490 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12491 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12492 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12493 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12494 +
12495 +
12496 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12497 +#define        VX_VLIM(r) ((long long)(long)(r))
12498 +#define        VX_RLIM(v) ((rlim_t)(v))
12499 +#else
12500 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12501 +               ? VLIM_INFINITY : (long long)(r))
12502 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12503 +               ? RLIM_INFINITY : (rlim_t)(v))
12504 +#endif
12505 +
12506 +struct sysinfo;
12507 +
12508 +void vx_vsi_meminfo(struct sysinfo *);
12509 +void vx_vsi_swapinfo(struct sysinfo *);
12510 +long vx_vsi_cached(struct sysinfo *);
12511 +
12512 +#define NUM_LIMITS     24
12513 +
12514 +#endif /* __KERNEL__ */
12515 +#endif /* _VX_LIMIT_H */
12516 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/limit_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit_cmd.h
12517 --- linux-3.4.83/include/linux/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12518 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit_cmd.h    2012-05-21 16:15:05.000000000 +0000
12519 @@ -0,0 +1,71 @@
12520 +#ifndef _VX_LIMIT_CMD_H
12521 +#define _VX_LIMIT_CMD_H
12522 +
12523 +
12524 +/*  rlimit vserver commands */
12525 +
12526 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12527 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12528 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12529 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12530 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12531 +
12532 +struct vcmd_ctx_rlimit_v0 {
12533 +       uint32_t id;
12534 +       uint64_t minimum;
12535 +       uint64_t softlimit;
12536 +       uint64_t maximum;
12537 +};
12538 +
12539 +struct vcmd_ctx_rlimit_mask_v0 {
12540 +       uint32_t minimum;
12541 +       uint32_t softlimit;
12542 +       uint32_t maximum;
12543 +};
12544 +
12545 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12546 +
12547 +struct vcmd_rlimit_stat_v0 {
12548 +       uint32_t id;
12549 +       uint32_t hits;
12550 +       uint64_t value;
12551 +       uint64_t minimum;
12552 +       uint64_t maximum;
12553 +};
12554 +
12555 +#define CRLIM_UNSET            (0ULL)
12556 +#define CRLIM_INFINITY         (~0ULL)
12557 +#define CRLIM_KEEP             (~1ULL)
12558 +
12559 +#ifdef __KERNEL__
12560 +
12561 +#ifdef CONFIG_IA32_EMULATION
12562 +
12563 +struct vcmd_ctx_rlimit_v0_x32 {
12564 +       uint32_t id;
12565 +       uint64_t minimum;
12566 +       uint64_t softlimit;
12567 +       uint64_t maximum;
12568 +} __attribute__ ((packed));
12569 +
12570 +#endif /* CONFIG_IA32_EMULATION */
12571 +
12572 +#include <linux/compiler.h>
12573 +
12574 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12575 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12576 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12577 +extern int vc_reset_hits(struct vx_info *, void __user *);
12578 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12579 +
12580 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12581 +
12582 +#ifdef CONFIG_IA32_EMULATION
12583 +
12584 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12585 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12586 +
12587 +#endif /* CONFIG_IA32_EMULATION */
12588 +
12589 +#endif /* __KERNEL__ */
12590 +#endif /* _VX_LIMIT_CMD_H */
12591 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/limit_def.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit_def.h
12592 --- linux-3.4.83/include/linux/vserver/limit_def.h      1970-01-01 00:00:00.000000000 +0000
12593 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit_def.h    2012-05-21 16:15:05.000000000 +0000
12594 @@ -0,0 +1,47 @@
12595 +#ifndef _VX_LIMIT_DEF_H
12596 +#define _VX_LIMIT_DEF_H
12597 +
12598 +#include <asm/atomic.h>
12599 +#include <asm/resource.h>
12600 +
12601 +#include "limit.h"
12602 +
12603 +
12604 +struct _vx_res_limit {
12605 +       rlim_t soft;            /* Context soft limit */
12606 +       rlim_t hard;            /* Context hard limit */
12607 +
12608 +       rlim_atomic_t rcur;     /* Current value */
12609 +       rlim_t rmin;            /* Context minimum */
12610 +       rlim_t rmax;            /* Context maximum */
12611 +
12612 +       atomic_t lhit;          /* Limit hits */
12613 +};
12614 +
12615 +/* context sub struct */
12616 +
12617 +struct _vx_limit {
12618 +       struct _vx_res_limit res[NUM_LIMITS];
12619 +};
12620 +
12621 +#ifdef CONFIG_VSERVER_DEBUG
12622 +
12623 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12624 +{
12625 +       int i;
12626 +
12627 +       printk("\t_vx_limit:");
12628 +       for (i = 0; i < NUM_LIMITS; i++) {
12629 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12630 +                       i, (unsigned long)__rlim_get(limit, i),
12631 +                       (unsigned long)__rlim_rmin(limit, i),
12632 +                       (unsigned long)__rlim_rmax(limit, i),
12633 +                       (long)__rlim_soft(limit, i),
12634 +                       (long)__rlim_hard(limit, i),
12635 +                       atomic_read(&__rlim_lhit(limit, i)));
12636 +       }
12637 +}
12638 +
12639 +#endif
12640 +
12641 +#endif /* _VX_LIMIT_DEF_H */
12642 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/limit_int.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit_int.h
12643 --- linux-3.4.83/include/linux/vserver/limit_int.h      1970-01-01 00:00:00.000000000 +0000
12644 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/limit_int.h    2012-05-21 16:15:05.000000000 +0000
12645 @@ -0,0 +1,198 @@
12646 +#ifndef _VX_LIMIT_INT_H
12647 +#define _VX_LIMIT_INT_H
12648 +
12649 +#include "context.h"
12650 +
12651 +#ifdef __KERNEL__
12652 +
12653 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12654 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12655 +
12656 +extern const char *vlimit_name[NUM_LIMITS];
12657 +
12658 +static inline void __vx_acc_cres(struct vx_info *vxi,
12659 +       int res, int dir, void *_data, char *_file, int _line)
12660 +{
12661 +       if (VXD_RCRES_COND(res))
12662 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12663 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12664 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12665 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12666 +       if (!vxi)
12667 +               return;
12668 +
12669 +       if (dir > 0)
12670 +               __rlim_inc(&vxi->limit, res);
12671 +       else
12672 +               __rlim_dec(&vxi->limit, res);
12673 +}
12674 +
12675 +static inline void __vx_add_cres(struct vx_info *vxi,
12676 +       int res, int amount, void *_data, char *_file, int _line)
12677 +{
12678 +       if (VXD_RCRES_COND(res))
12679 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12680 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12681 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12682 +                       amount, _data, _file, _line);
12683 +       if (amount == 0)
12684 +               return;
12685 +       if (!vxi)
12686 +               return;
12687 +       __rlim_add(&vxi->limit, res, amount);
12688 +}
12689 +
12690 +static inline
12691 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12692 +{
12693 +       int cond = (value > __rlim_rmax(limit, res));
12694 +
12695 +       if (cond)
12696 +               __rlim_rmax(limit, res) = value;
12697 +       return cond;
12698 +}
12699 +
12700 +static inline
12701 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12702 +{
12703 +       int cond = (value < __rlim_rmin(limit, res));
12704 +
12705 +       if (cond)
12706 +               __rlim_rmin(limit, res) = value;
12707 +       return cond;
12708 +}
12709 +
12710 +static inline
12711 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12712 +{
12713 +       if (!__vx_cres_adjust_max(limit, res, value))
12714 +               __vx_cres_adjust_min(limit, res, value);
12715 +}
12716 +
12717 +
12718 +/*     return values:
12719 +        +1 ... no limit hit
12720 +        -1 ... over soft limit
12721 +         0 ... over hard limit         */
12722 +
12723 +static inline int __vx_cres_avail(struct vx_info *vxi,
12724 +       int res, int num, char *_file, int _line)
12725 +{
12726 +       struct _vx_limit *limit;
12727 +       rlim_t value;
12728 +
12729 +       if (VXD_RLIMIT_COND(res))
12730 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12731 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12732 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12733 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12734 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12735 +                       num, _file, _line);
12736 +       if (!vxi)
12737 +               return 1;
12738 +
12739 +       limit = &vxi->limit;
12740 +       value = __rlim_get(limit, res);
12741 +
12742 +       if (!__vx_cres_adjust_max(limit, res, value))
12743 +               __vx_cres_adjust_min(limit, res, value);
12744 +
12745 +       if (num == 0)
12746 +               return 1;
12747 +
12748 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12749 +               return -1;
12750 +       if (value + num <= __rlim_soft(limit, res))
12751 +               return -1;
12752 +
12753 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12754 +               return 1;
12755 +       if (value + num <= __rlim_hard(limit, res))
12756 +               return 1;
12757 +
12758 +       __rlim_hit(limit, res);
12759 +       return 0;
12760 +}
12761 +
12762 +
12763 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12764 +
12765 +static inline
12766 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12767 +{
12768 +       rlim_t value, sum = 0;
12769 +       int res;
12770 +
12771 +       while ((res = *array++)) {
12772 +               value = __rlim_get(limit, res);
12773 +               __vx_cres_fixup(limit, res, value);
12774 +               sum += value;
12775 +       }
12776 +       return sum;
12777 +}
12778 +
12779 +static inline
12780 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12781 +{
12782 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12783 +       int res = *array;
12784 +
12785 +       if (value == __rlim_get(limit, res))
12786 +               return value;
12787 +
12788 +       __rlim_set(limit, res, value);
12789 +       /* now adjust min/max */
12790 +       if (!__vx_cres_adjust_max(limit, res, value))
12791 +               __vx_cres_adjust_min(limit, res, value);
12792 +
12793 +       return value;
12794 +}
12795 +
12796 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12797 +       const int *array, int num, char *_file, int _line)
12798 +{
12799 +       struct _vx_limit *limit;
12800 +       rlim_t value = 0;
12801 +       int res;
12802 +
12803 +       if (num == 0)
12804 +               return 1;
12805 +       if (!vxi)
12806 +               return 1;
12807 +
12808 +       limit = &vxi->limit;
12809 +       res = *array;
12810 +       value = __vx_cres_array_sum(limit, array + 1);
12811 +
12812 +       __rlim_set(limit, res, value);
12813 +       __vx_cres_fixup(limit, res, value);
12814 +
12815 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12816 +}
12817 +
12818 +
12819 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12820 +{
12821 +       rlim_t value;
12822 +       int res;
12823 +
12824 +       /* complex resources first */
12825 +       if ((id < 0) || (id == RLIMIT_RSS))
12826 +               __vx_cres_array_fixup(limit, VLA_RSS);
12827 +
12828 +       for (res = 0; res < NUM_LIMITS; res++) {
12829 +               if ((id > 0) && (res != id))
12830 +                       continue;
12831 +
12832 +               value = __rlim_get(limit, res);
12833 +               __vx_cres_fixup(limit, res, value);
12834 +
12835 +               /* not supposed to happen, maybe warn? */
12836 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12837 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12838 +       }
12839 +}
12840 +
12841 +
12842 +#endif /* __KERNEL__ */
12843 +#endif /* _VX_LIMIT_INT_H */
12844 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/monitor.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/monitor.h
12845 --- linux-3.4.83/include/linux/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12846 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/monitor.h      2012-05-21 16:15:05.000000000 +0000
12847 @@ -0,0 +1,96 @@
12848 +#ifndef _VX_MONITOR_H
12849 +#define _VX_MONITOR_H
12850 +
12851 +#include <linux/types.h>
12852 +
12853 +enum {
12854 +       VXM_UNUSED = 0,
12855 +
12856 +       VXM_SYNC = 0x10,
12857 +
12858 +       VXM_UPDATE = 0x20,
12859 +       VXM_UPDATE_1,
12860 +       VXM_UPDATE_2,
12861 +
12862 +       VXM_RQINFO_1 = 0x24,
12863 +       VXM_RQINFO_2,
12864 +
12865 +       VXM_ACTIVATE = 0x40,
12866 +       VXM_DEACTIVATE,
12867 +       VXM_IDLE,
12868 +
12869 +       VXM_HOLD = 0x44,
12870 +       VXM_UNHOLD,
12871 +
12872 +       VXM_MIGRATE = 0x48,
12873 +       VXM_RESCHED,
12874 +
12875 +       /* all other bits are flags */
12876 +       VXM_SCHED = 0x80,
12877 +};
12878 +
12879 +struct _vxm_update_1 {
12880 +       uint32_t tokens_max;
12881 +       uint32_t fill_rate;
12882 +       uint32_t interval;
12883 +};
12884 +
12885 +struct _vxm_update_2 {
12886 +       uint32_t tokens_min;
12887 +       uint32_t fill_rate;
12888 +       uint32_t interval;
12889 +};
12890 +
12891 +struct _vxm_rqinfo_1 {
12892 +       uint16_t running;
12893 +       uint16_t onhold;
12894 +       uint16_t iowait;
12895 +       uint16_t uintr;
12896 +       uint32_t idle_tokens;
12897 +};
12898 +
12899 +struct _vxm_rqinfo_2 {
12900 +       uint32_t norm_time;
12901 +       uint32_t idle_time;
12902 +       uint32_t idle_skip;
12903 +};
12904 +
12905 +struct _vxm_sched {
12906 +       uint32_t tokens;
12907 +       uint32_t norm_time;
12908 +       uint32_t idle_time;
12909 +};
12910 +
12911 +struct _vxm_task {
12912 +       uint16_t pid;
12913 +       uint16_t state;
12914 +};
12915 +
12916 +struct _vxm_event {
12917 +       uint32_t jif;
12918 +       union {
12919 +               uint32_t seq;
12920 +               uint32_t sec;
12921 +       };
12922 +       union {
12923 +               uint32_t tokens;
12924 +               uint32_t nsec;
12925 +               struct _vxm_task tsk;
12926 +       };
12927 +};
12928 +
12929 +struct _vx_mon_entry {
12930 +       uint16_t type;
12931 +       uint16_t xid;
12932 +       union {
12933 +               struct _vxm_event ev;
12934 +               struct _vxm_sched sd;
12935 +               struct _vxm_update_1 u1;
12936 +               struct _vxm_update_2 u2;
12937 +               struct _vxm_rqinfo_1 q1;
12938 +               struct _vxm_rqinfo_2 q2;
12939 +       };
12940 +};
12941 +
12942 +
12943 +#endif /* _VX_MONITOR_H */
12944 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/network.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/network.h
12945 --- linux-3.4.83/include/linux/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12946 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/network.h      2012-05-21 16:15:05.000000000 +0000
12947 @@ -0,0 +1,148 @@
12948 +#ifndef _VX_NETWORK_H
12949 +#define _VX_NETWORK_H
12950 +
12951 +#include <linux/types.h>
12952 +
12953 +
12954 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12955 +
12956 +
12957 +/* network flags */
12958 +
12959 +#define NXF_INFO_PRIVATE       0x00000008
12960 +
12961 +#define NXF_SINGLE_IP          0x00000100
12962 +#define NXF_LBACK_REMAP                0x00000200
12963 +#define NXF_LBACK_ALLOW                0x00000400
12964 +
12965 +#define NXF_HIDE_NETIF         0x02000000
12966 +#define NXF_HIDE_LBACK         0x04000000
12967 +
12968 +#define NXF_STATE_SETUP                (1ULL << 32)
12969 +#define NXF_STATE_ADMIN                (1ULL << 34)
12970 +
12971 +#define NXF_SC_HELPER          (1ULL << 36)
12972 +#define NXF_PERSISTENT         (1ULL << 38)
12973 +
12974 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12975 +
12976 +
12977 +#define        NXF_INIT_SET            (__nxf_init_set())
12978 +
12979 +static inline uint64_t __nxf_init_set(void) {
12980 +       return    NXF_STATE_ADMIN
12981 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12982 +               | NXF_LBACK_REMAP
12983 +               | NXF_HIDE_LBACK
12984 +#endif
12985 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12986 +               | NXF_SINGLE_IP
12987 +#endif
12988 +               | NXF_HIDE_NETIF;
12989 +}
12990 +
12991 +
12992 +/* network caps */
12993 +
12994 +#define NXC_TUN_CREATE         0x00000001
12995 +
12996 +#define NXC_RAW_ICMP           0x00000100
12997 +
12998 +#define NXC_MULTICAST          0x00001000
12999 +
13000 +
13001 +/* address types */
13002 +
13003 +#define NXA_TYPE_IPV4          0x0001
13004 +#define NXA_TYPE_IPV6          0x0002
13005 +
13006 +#define NXA_TYPE_NONE          0x0000
13007 +#define NXA_TYPE_ANY           0x00FF
13008 +
13009 +#define NXA_TYPE_ADDR          0x0010
13010 +#define NXA_TYPE_MASK          0x0020
13011 +#define NXA_TYPE_RANGE         0x0040
13012 +
13013 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13014 +
13015 +#define NXA_MOD_BCAST          0x0100
13016 +#define NXA_MOD_LBACK          0x0200
13017 +
13018 +#define NXA_LOOPBACK           0x1000
13019 +
13020 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13021 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13022 +
13023 +#ifdef __KERNEL__
13024 +
13025 +#include <linux/list.h>
13026 +#include <linux/spinlock.h>
13027 +#include <linux/rcupdate.h>
13028 +#include <linux/in.h>
13029 +#include <linux/in6.h>
13030 +#include <asm/atomic.h>
13031 +
13032 +struct nx_addr_v4 {
13033 +       struct nx_addr_v4 *next;
13034 +       struct in_addr ip[2];
13035 +       struct in_addr mask;
13036 +       uint16_t type;
13037 +       uint16_t flags;
13038 +};
13039 +
13040 +struct nx_addr_v6 {
13041 +       struct nx_addr_v6 *next;
13042 +       struct in6_addr ip;
13043 +       struct in6_addr mask;
13044 +       uint32_t prefix;
13045 +       uint16_t type;
13046 +       uint16_t flags;
13047 +};
13048 +
13049 +struct nx_info {
13050 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13051 +       nid_t nx_id;                    /* vnet id */
13052 +       atomic_t nx_usecnt;             /* usage count */
13053 +       atomic_t nx_tasks;              /* tasks count */
13054 +       int nx_state;                   /* context state */
13055 +
13056 +       uint64_t nx_flags;              /* network flag word */
13057 +       uint64_t nx_ncaps;              /* network capabilities */
13058 +
13059 +       struct in_addr v4_lback;        /* Loopback address */
13060 +       struct in_addr v4_bcast;        /* Broadcast address */
13061 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13062 +#ifdef CONFIG_IPV6
13063 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13064 +#endif
13065 +       char nx_name[65];               /* network context name */
13066 +};
13067 +
13068 +
13069 +/* status flags */
13070 +
13071 +#define NXS_HASHED      0x0001
13072 +#define NXS_SHUTDOWN    0x0100
13073 +#define NXS_RELEASED    0x8000
13074 +
13075 +extern struct nx_info *lookup_nx_info(int);
13076 +
13077 +extern int get_nid_list(int, unsigned int *, int);
13078 +extern int nid_is_hashed(nid_t);
13079 +
13080 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13081 +
13082 +extern long vs_net_change(struct nx_info *, unsigned int);
13083 +
13084 +struct sock;
13085 +
13086 +
13087 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13088 +#ifdef  CONFIG_IPV6
13089 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13090 +#else
13091 +#define NX_IPV6(n)     (0)
13092 +#endif
13093 +
13094 +#endif /* __KERNEL__ */
13095 +#endif /* _VX_NETWORK_H */
13096 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/network_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/network_cmd.h
13097 --- linux-3.4.83/include/linux/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
13098 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/network_cmd.h  2012-05-21 16:15:05.000000000 +0000
13099 @@ -0,0 +1,164 @@
13100 +#ifndef _VX_NETWORK_CMD_H
13101 +#define _VX_NETWORK_CMD_H
13102 +
13103 +
13104 +/* vinfo commands */
13105 +
13106 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13107 +
13108 +#ifdef __KERNEL__
13109 +extern int vc_task_nid(uint32_t);
13110 +
13111 +#endif /* __KERNEL__ */
13112 +
13113 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13114 +
13115 +struct vcmd_nx_info_v0 {
13116 +       uint32_t nid;
13117 +       /* more to come */
13118 +};
13119 +
13120 +#ifdef __KERNEL__
13121 +extern int vc_nx_info(struct nx_info *, void __user *);
13122 +
13123 +#endif /* __KERNEL__ */
13124 +
13125 +#include <linux/in.h>
13126 +#include <linux/in6.h>
13127 +
13128 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13129 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13130 +
13131 +struct  vcmd_net_create {
13132 +       uint64_t flagword;
13133 +};
13134 +
13135 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13136 +
13137 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13138 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13139 +
13140 +struct vcmd_net_addr_v0 {
13141 +       uint16_t type;
13142 +       uint16_t count;
13143 +       struct in_addr ip[4];
13144 +       struct in_addr mask[4];
13145 +};
13146 +
13147 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13148 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13149 +
13150 +struct vcmd_net_addr_ipv4_v1 {
13151 +       uint16_t type;
13152 +       uint16_t flags;
13153 +       struct in_addr ip;
13154 +       struct in_addr mask;
13155 +};
13156 +
13157 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13158 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13159 +
13160 +struct vcmd_net_addr_ipv4_v2 {
13161 +       uint16_t type;
13162 +       uint16_t flags;
13163 +       struct in_addr ip;
13164 +       struct in_addr ip2;
13165 +       struct in_addr mask;
13166 +};
13167 +
13168 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13169 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13170 +
13171 +struct vcmd_net_addr_ipv6_v1 {
13172 +       uint16_t type;
13173 +       uint16_t flags;
13174 +       uint32_t prefix;
13175 +       struct in6_addr ip;
13176 +       struct in6_addr mask;
13177 +};
13178 +
13179 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13180 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13181 +
13182 +struct vcmd_match_ipv4_v0 {
13183 +       uint16_t type;
13184 +       uint16_t flags;
13185 +       uint16_t parent;
13186 +       uint16_t prefix;
13187 +       struct in_addr ip;
13188 +       struct in_addr ip2;
13189 +       struct in_addr mask;
13190 +};
13191 +
13192 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13193 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13194 +
13195 +struct vcmd_match_ipv6_v0 {
13196 +       uint16_t type;
13197 +       uint16_t flags;
13198 +       uint16_t parent;
13199 +       uint16_t prefix;
13200 +       struct in6_addr ip;
13201 +       struct in6_addr ip2;
13202 +       struct in6_addr mask;
13203 +};
13204 +
13205 +
13206 +#ifdef __KERNEL__
13207 +extern int vc_net_create(uint32_t, void __user *);
13208 +extern int vc_net_migrate(struct nx_info *, void __user *);
13209 +
13210 +extern int vc_net_add(struct nx_info *, void __user *);
13211 +extern int vc_net_remove(struct nx_info *, void __user *);
13212 +
13213 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13214 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13215 +
13216 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13217 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13218 +
13219 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13220 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13221 +
13222 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13223 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13224 +
13225 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13226 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13227 +
13228 +#endif /* __KERNEL__ */
13229 +
13230 +
13231 +/* flag commands */
13232 +
13233 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13234 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13235 +
13236 +struct vcmd_net_flags_v0 {
13237 +       uint64_t flagword;
13238 +       uint64_t mask;
13239 +};
13240 +
13241 +#ifdef __KERNEL__
13242 +extern int vc_get_nflags(struct nx_info *, void __user *);
13243 +extern int vc_set_nflags(struct nx_info *, void __user *);
13244 +
13245 +#endif /* __KERNEL__ */
13246 +
13247 +
13248 +/* network caps commands */
13249 +
13250 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13251 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13252 +
13253 +struct vcmd_net_caps_v0 {
13254 +       uint64_t ncaps;
13255 +       uint64_t cmask;
13256 +};
13257 +
13258 +#ifdef __KERNEL__
13259 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13260 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13261 +
13262 +#endif /* __KERNEL__ */
13263 +#endif /* _VX_CONTEXT_CMD_H */
13264 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/percpu.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/percpu.h
13265 --- linux-3.4.83/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
13266 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/percpu.h       2012-05-21 16:15:05.000000000 +0000
13267 @@ -0,0 +1,14 @@
13268 +#ifndef _VX_PERCPU_H
13269 +#define _VX_PERCPU_H
13270 +
13271 +#include "cvirt_def.h"
13272 +#include "sched_def.h"
13273 +
13274 +struct _vx_percpu {
13275 +       struct _vx_cvirt_pc cvirt;
13276 +       struct _vx_sched_pc sched;
13277 +};
13278 +
13279 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13280 +
13281 +#endif /* _VX_PERCPU_H */
13282 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/pid.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/pid.h
13283 --- linux-3.4.83/include/linux/vserver/pid.h    1970-01-01 00:00:00.000000000 +0000
13284 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/pid.h  2012-05-21 16:15:05.000000000 +0000
13285 @@ -0,0 +1,51 @@
13286 +#ifndef _VSERVER_PID_H
13287 +#define _VSERVER_PID_H
13288 +
13289 +/* pid faking stuff */
13290 +
13291 +#define vx_info_map_pid(v, p) \
13292 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13293 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13294 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13295 +#define vx_map_tgid(p) vx_map_pid(p)
13296 +
13297 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13298 +       const char *func, const char *file, int line)
13299 +{
13300 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13301 +               vxfprintk(VXD_CBIT(cvirt, 2),
13302 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13303 +                       vxi, (long long)vxi->vx_flags, pid,
13304 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13305 +                       func, file, line);
13306 +               if (pid == 0)
13307 +                       return 0;
13308 +               if (pid == vxi->vx_initpid)
13309 +                       return 1;
13310 +       }
13311 +       return pid;
13312 +}
13313 +
13314 +#define vx_info_rmap_pid(v, p) \
13315 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13316 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13317 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13318 +
13319 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13320 +       const char *func, const char *file, int line)
13321 +{
13322 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13323 +               vxfprintk(VXD_CBIT(cvirt, 2),
13324 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13325 +                       vxi, (long long)vxi->vx_flags, pid,
13326 +                       (pid == 1) ? vxi->vx_initpid : pid,
13327 +                       func, file, line);
13328 +               if ((pid == 1) && vxi->vx_initpid)
13329 +                       return vxi->vx_initpid;
13330 +               if (pid == vxi->vx_initpid)
13331 +                       return ~0U;
13332 +       }
13333 +       return pid;
13334 +}
13335 +
13336 +#endif
13337 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/sched.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/sched.h
13338 --- linux-3.4.83/include/linux/vserver/sched.h  1970-01-01 00:00:00.000000000 +0000
13339 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/sched.h        2012-05-21 16:15:05.000000000 +0000
13340 @@ -0,0 +1,23 @@
13341 +#ifndef _VX_SCHED_H
13342 +#define _VX_SCHED_H
13343 +
13344 +
13345 +#ifdef __KERNEL__
13346 +
13347 +struct timespec;
13348 +
13349 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13350 +
13351 +
13352 +struct vx_info;
13353 +
13354 +void vx_update_load(struct vx_info *);
13355 +
13356 +
13357 +void vx_update_sched_param(struct _vx_sched *sched,
13358 +       struct _vx_sched_pc *sched_pc);
13359 +
13360 +#endif /* __KERNEL__ */
13361 +#else  /* _VX_SCHED_H */
13362 +#warning duplicate inclusion
13363 +#endif /* _VX_SCHED_H */
13364 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/sched_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/sched_cmd.h
13365 --- linux-3.4.83/include/linux/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
13366 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/sched_cmd.h    2012-05-21 16:15:05.000000000 +0000
13367 @@ -0,0 +1,21 @@
13368 +#ifndef _VX_SCHED_CMD_H
13369 +#define _VX_SCHED_CMD_H
13370 +
13371 +
13372 +struct vcmd_prio_bias {
13373 +       int32_t cpu_id;
13374 +       int32_t prio_bias;
13375 +};
13376 +
13377 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13378 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13379 +
13380 +#ifdef __KERNEL__
13381 +
13382 +#include <linux/compiler.h>
13383 +
13384 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13385 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13386 +
13387 +#endif /* __KERNEL__ */
13388 +#endif /* _VX_SCHED_CMD_H */
13389 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/sched_def.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/sched_def.h
13390 --- linux-3.4.83/include/linux/vserver/sched_def.h      1970-01-01 00:00:00.000000000 +0000
13391 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/sched_def.h    2012-05-21 16:15:05.000000000 +0000
13392 @@ -0,0 +1,38 @@
13393 +#ifndef _VX_SCHED_DEF_H
13394 +#define _VX_SCHED_DEF_H
13395 +
13396 +#include <linux/spinlock.h>
13397 +#include <linux/jiffies.h>
13398 +#include <linux/cpumask.h>
13399 +#include <asm/atomic.h>
13400 +#include <asm/param.h>
13401 +
13402 +
13403 +/* context sub struct */
13404 +
13405 +struct _vx_sched {
13406 +       int prio_bias;                  /* bias offset for priority */
13407 +
13408 +       cpumask_t update;               /* CPUs which should update */
13409 +};
13410 +
13411 +struct _vx_sched_pc {
13412 +       int prio_bias;                  /* bias offset for priority */
13413 +
13414 +       uint64_t user_ticks;            /* token tick events */
13415 +       uint64_t sys_ticks;             /* token tick events */
13416 +       uint64_t hold_ticks;            /* token ticks paused */
13417 +};
13418 +
13419 +
13420 +#ifdef CONFIG_VSERVER_DEBUG
13421 +
13422 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13423 +{
13424 +       printk("\t_vx_sched:\n");
13425 +       printk("\t priority = %4d\n", sched->prio_bias);
13426 +}
13427 +
13428 +#endif
13429 +
13430 +#endif /* _VX_SCHED_DEF_H */
13431 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/signal.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/signal.h
13432 --- linux-3.4.83/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
13433 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/signal.h       2012-05-21 16:15:05.000000000 +0000
13434 @@ -0,0 +1,14 @@
13435 +#ifndef _VX_SIGNAL_H
13436 +#define _VX_SIGNAL_H
13437 +
13438 +
13439 +#ifdef __KERNEL__
13440 +
13441 +struct vx_info;
13442 +
13443 +int vx_info_kill(struct vx_info *, int, int);
13444 +
13445 +#endif /* __KERNEL__ */
13446 +#else  /* _VX_SIGNAL_H */
13447 +#warning duplicate inclusion
13448 +#endif /* _VX_SIGNAL_H */
13449 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/signal_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/signal_cmd.h
13450 --- linux-3.4.83/include/linux/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
13451 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/signal_cmd.h   2012-05-21 16:15:05.000000000 +0000
13452 @@ -0,0 +1,43 @@
13453 +#ifndef _VX_SIGNAL_CMD_H
13454 +#define _VX_SIGNAL_CMD_H
13455 +
13456 +
13457 +/*  signalling vserver commands */
13458 +
13459 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13460 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13461 +
13462 +struct vcmd_ctx_kill_v0 {
13463 +       int32_t pid;
13464 +       int32_t sig;
13465 +};
13466 +
13467 +struct vcmd_wait_exit_v0 {
13468 +       int32_t reboot_cmd;
13469 +       int32_t exit_code;
13470 +};
13471 +
13472 +#ifdef __KERNEL__
13473 +
13474 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13475 +extern int vc_wait_exit(struct vx_info *, void __user *);
13476 +
13477 +#endif /* __KERNEL__ */
13478 +
13479 +/*  process alteration commands */
13480 +
13481 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13482 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13483 +
13484 +struct vcmd_pflags_v0 {
13485 +       uint32_t flagword;
13486 +       uint32_t mask;
13487 +};
13488 +
13489 +#ifdef __KERNEL__
13490 +
13491 +extern int vc_get_pflags(uint32_t pid, void __user *);
13492 +extern int vc_set_pflags(uint32_t pid, void __user *);
13493 +
13494 +#endif /* __KERNEL__ */
13495 +#endif /* _VX_SIGNAL_CMD_H */
13496 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/space.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/space.h
13497 --- linux-3.4.83/include/linux/vserver/space.h  1970-01-01 00:00:00.000000000 +0000
13498 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/space.h        2012-05-21 16:15:05.000000000 +0000
13499 @@ -0,0 +1,12 @@
13500 +#ifndef _VX_SPACE_H
13501 +#define _VX_SPACE_H
13502 +
13503 +#include <linux/types.h>
13504 +
13505 +struct vx_info;
13506 +
13507 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13508 +
13509 +#else  /* _VX_SPACE_H */
13510 +#warning duplicate inclusion
13511 +#endif /* _VX_SPACE_H */
13512 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/space_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/space_cmd.h
13513 --- linux-3.4.83/include/linux/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
13514 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/space_cmd.h    2012-05-21 16:15:05.000000000 +0000
13515 @@ -0,0 +1,38 @@
13516 +#ifndef _VX_SPACE_CMD_H
13517 +#define _VX_SPACE_CMD_H
13518 +
13519 +
13520 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13521 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13522 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13523 +
13524 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13525 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13526 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13527 +
13528 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13529 +
13530 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13531 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13532 +
13533 +
13534 +struct vcmd_space_mask_v1 {
13535 +       uint64_t mask;
13536 +};
13537 +
13538 +struct vcmd_space_mask_v2 {
13539 +       uint64_t mask;
13540 +       uint32_t index;
13541 +};
13542 +
13543 +
13544 +#ifdef __KERNEL__
13545 +
13546 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13547 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13548 +extern int vc_enter_space(struct vx_info *, void __user *);
13549 +extern int vc_set_space(struct vx_info *, void __user *);
13550 +extern int vc_get_space_mask(void __user *, int);
13551 +
13552 +#endif /* __KERNEL__ */
13553 +#endif /* _VX_SPACE_CMD_H */
13554 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/switch.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/switch.h
13555 --- linux-3.4.83/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13556 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/switch.h       2012-05-21 16:15:05.000000000 +0000
13557 @@ -0,0 +1,98 @@
13558 +#ifndef _VX_SWITCH_H
13559 +#define _VX_SWITCH_H
13560 +
13561 +#include <linux/types.h>
13562 +
13563 +
13564 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13565 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13566 +#define VC_VERSION(c)          ((c) & 0xFFF)
13567 +
13568 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13569 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13570 +
13571 +/*
13572 +
13573 +  Syscall Matrix V2.8
13574 +
13575 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13576 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13577 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13578 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13579 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13580 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13581 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13582 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13583 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13584 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13585 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13586 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13587 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13588 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13589 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13590 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13591 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13592 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13593 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13594 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13595 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13596 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13597 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13598 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13599 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13600 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13601 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13602 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13603 +
13604 +*/
13605 +
13606 +#define VC_CAT_VERSION         0
13607 +
13608 +#define VC_CAT_VSETUP          1
13609 +#define VC_CAT_VHOST           2
13610 +
13611 +#define VC_CAT_DEVICE          6
13612 +
13613 +#define VC_CAT_VPROC           9
13614 +#define VC_CAT_PROCALT         10
13615 +#define VC_CAT_PROCMIG         11
13616 +#define VC_CAT_PROCTRL         12
13617 +
13618 +#define VC_CAT_SCHED           14
13619 +#define VC_CAT_MEMCTRL         20
13620 +
13621 +#define VC_CAT_VNET            25
13622 +#define VC_CAT_NETALT          26
13623 +#define VC_CAT_NETMIG          27
13624 +#define VC_CAT_NETCTRL         28
13625 +
13626 +#define VC_CAT_TAGMIG          35
13627 +#define VC_CAT_DLIMIT          36
13628 +#define VC_CAT_INODE           38
13629 +
13630 +#define VC_CAT_VSTAT           40
13631 +#define VC_CAT_VINFO           46
13632 +#define VC_CAT_EVENT           48
13633 +
13634 +#define VC_CAT_FLAGS           52
13635 +#define VC_CAT_VSPACE          54
13636 +#define VC_CAT_DEBUG           56
13637 +#define VC_CAT_RLIMIT          60
13638 +
13639 +#define VC_CAT_SYSTEST         61
13640 +#define VC_CAT_COMPAT          63
13641 +
13642 +/*  query version */
13643 +
13644 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13645 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13646 +
13647 +
13648 +#ifdef __KERNEL__
13649 +
13650 +#include <linux/errno.h>
13651 +
13652 +#endif /* __KERNEL__ */
13653 +
13654 +#endif /* _VX_SWITCH_H */
13655 +
13656 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/tag.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/tag.h
13657 --- linux-3.4.83/include/linux/vserver/tag.h    1970-01-01 00:00:00.000000000 +0000
13658 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/tag.h  2012-05-21 16:15:05.000000000 +0000
13659 @@ -0,0 +1,143 @@
13660 +#ifndef _DX_TAG_H
13661 +#define _DX_TAG_H
13662 +
13663 +#include <linux/types.h>
13664 +
13665 +
13666 +#define DX_TAG(in)     (IS_TAGGED(in))
13667 +
13668 +
13669 +#ifdef CONFIG_TAG_NFSD
13670 +#define DX_TAG_NFSD    1
13671 +#else
13672 +#define DX_TAG_NFSD    0
13673 +#endif
13674 +
13675 +
13676 +#ifdef CONFIG_TAGGING_NONE
13677 +
13678 +#define MAX_UID                0xFFFFFFFF
13679 +#define MAX_GID                0xFFFFFFFF
13680 +
13681 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13682 +
13683 +#define TAGINO_UID(cond, uid, tag)     (uid)
13684 +#define TAGINO_GID(cond, gid, tag)     (gid)
13685 +
13686 +#endif
13687 +
13688 +
13689 +#ifdef CONFIG_TAGGING_GID16
13690 +
13691 +#define MAX_UID                0xFFFFFFFF
13692 +#define MAX_GID                0x0000FFFF
13693 +
13694 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13695 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13696 +
13697 +#define TAGINO_UID(cond, uid, tag)     (uid)
13698 +#define TAGINO_GID(cond, gid, tag)     \
13699 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13700 +
13701 +#endif
13702 +
13703 +
13704 +#ifdef CONFIG_TAGGING_ID24
13705 +
13706 +#define MAX_UID                0x00FFFFFF
13707 +#define MAX_GID                0x00FFFFFF
13708 +
13709 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13710 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13711 +
13712 +#define TAGINO_UID(cond, uid, tag)     \
13713 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13714 +#define TAGINO_GID(cond, gid, tag)     \
13715 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13716 +
13717 +#endif
13718 +
13719 +
13720 +#ifdef CONFIG_TAGGING_UID16
13721 +
13722 +#define MAX_UID                0x0000FFFF
13723 +#define MAX_GID                0xFFFFFFFF
13724 +
13725 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13726 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13727 +
13728 +#define TAGINO_UID(cond, uid, tag)     \
13729 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13730 +#define TAGINO_GID(cond, gid, tag)     (gid)
13731 +
13732 +#endif
13733 +
13734 +
13735 +#ifdef CONFIG_TAGGING_INTERN
13736 +
13737 +#define MAX_UID                0xFFFFFFFF
13738 +#define MAX_GID                0xFFFFFFFF
13739 +
13740 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13741 +       ((cond) ? (tag) : 0)
13742 +
13743 +#define TAGINO_UID(cond, uid, tag)     (uid)
13744 +#define TAGINO_GID(cond, gid, tag)     (gid)
13745 +
13746 +#endif
13747 +
13748 +
13749 +#ifndef CONFIG_TAGGING_NONE
13750 +#define dx_current_fstag(sb)   \
13751 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13752 +#else
13753 +#define dx_current_fstag(sb)   (0)
13754 +#endif
13755 +
13756 +#ifndef CONFIG_TAGGING_INTERN
13757 +#define TAGINO_TAG(cond, tag)  (0)
13758 +#else
13759 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13760 +#endif
13761 +
13762 +#define INOTAG_UID(cond, uid, gid)     \
13763 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13764 +#define INOTAG_GID(cond, uid, gid)     \
13765 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13766 +
13767 +
13768 +static inline uid_t dx_map_uid(uid_t uid)
13769 +{
13770 +       if ((uid > MAX_UID) && (uid != -1))
13771 +               uid = -2;
13772 +       return (uid & MAX_UID);
13773 +}
13774 +
13775 +static inline gid_t dx_map_gid(gid_t gid)
13776 +{
13777 +       if ((gid > MAX_GID) && (gid != -1))
13778 +               gid = -2;
13779 +       return (gid & MAX_GID);
13780 +}
13781 +
13782 +struct peer_tag {
13783 +       int32_t xid;
13784 +       int32_t nid;
13785 +};
13786 +
13787 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13788 +
13789 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13790 +                unsigned long *flags);
13791 +
13792 +#ifdef CONFIG_PROPAGATE
13793 +
13794 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13795 +
13796 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13797 +
13798 +#else
13799 +#define dx_propagate_tag(n, i) do { } while (0)
13800 +#endif
13801 +
13802 +#endif /* _DX_TAG_H */
13803 diff -NurpP --minimal linux-3.4.83/include/linux/vserver/tag_cmd.h linux-3.4.83-vs2.3.3.9/include/linux/vserver/tag_cmd.h
13804 --- linux-3.4.83/include/linux/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
13805 +++ linux-3.4.83-vs2.3.3.9/include/linux/vserver/tag_cmd.h      2012-05-21 16:15:05.000000000 +0000
13806 @@ -0,0 +1,22 @@
13807 +#ifndef _VX_TAG_CMD_H
13808 +#define _VX_TAG_CMD_H
13809 +
13810 +
13811 +/* vinfo commands */
13812 +
13813 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13814 +
13815 +#ifdef __KERNEL__
13816 +extern int vc_task_tag(uint32_t);
13817 +
13818 +#endif /* __KERNEL__ */
13819 +
13820 +/* context commands */
13821 +
13822 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13823 +
13824 +#ifdef __KERNEL__
13825 +extern int vc_tag_migrate(uint32_t);
13826 +
13827 +#endif /* __KERNEL__ */
13828 +#endif /* _VX_TAG_CMD_H */
13829 diff -NurpP --minimal linux-3.4.83/include/net/addrconf.h linux-3.4.83-vs2.3.3.9/include/net/addrconf.h
13830 --- linux-3.4.83/include/net/addrconf.h 2014-03-12 09:48:20.000000000 +0000
13831 +++ linux-3.4.83-vs2.3.3.9/include/net/addrconf.h       2013-08-13 17:08:10.000000000 +0000
13832 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13833                                                struct net_device *dev,
13834                                                const struct in6_addr *daddr,
13835                                                unsigned int srcprefs,
13836 -                                              struct in6_addr *saddr);
13837 +                                              struct in6_addr *saddr,
13838 +                                              struct nx_info *nxi);
13839  extern int                     __ipv6_get_lladdr(struct inet6_dev *idev,
13840                                                   struct in6_addr *addr,
13841                                                   unsigned char banned_flags);
13842 diff -NurpP --minimal linux-3.4.83/include/net/af_unix.h linux-3.4.83-vs2.3.3.9/include/net/af_unix.h
13843 --- linux-3.4.83/include/net/af_unix.h  2012-05-21 16:07:33.000000000 +0000
13844 +++ linux-3.4.83-vs2.3.3.9/include/net/af_unix.h        2012-05-21 16:15:05.000000000 +0000
13845 @@ -4,6 +4,7 @@
13846  #include <linux/socket.h>
13847  #include <linux/un.h>
13848  #include <linux/mutex.h>
13849 +#include <linux/vs_base.h>
13850  #include <net/sock.h>
13851  
13852  extern void unix_inflight(struct file *fp);
13853 diff -NurpP --minimal linux-3.4.83/include/net/inet_timewait_sock.h linux-3.4.83-vs2.3.3.9/include/net/inet_timewait_sock.h
13854 --- linux-3.4.83/include/net/inet_timewait_sock.h       2012-03-19 18:47:29.000000000 +0000
13855 +++ linux-3.4.83-vs2.3.3.9/include/net/inet_timewait_sock.h     2012-05-21 16:15:05.000000000 +0000
13856 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13857  #define tw_net                 __tw_common.skc_net
13858  #define tw_daddr               __tw_common.skc_daddr
13859  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13860 +#define tw_xid                 __tw_common.skc_xid
13861 +#define tw_vx_info             __tw_common.skc_vx_info
13862 +#define tw_nid                 __tw_common.skc_nid
13863 +#define tw_nx_info             __tw_common.skc_nx_info
13864         int                     tw_timeout;
13865         volatile unsigned char  tw_substate;
13866         unsigned char           tw_rcv_wscale;
13867 diff -NurpP --minimal linux-3.4.83/include/net/ip6_route.h linux-3.4.83-vs2.3.3.9/include/net/ip6_route.h
13868 --- linux-3.4.83/include/net/ip6_route.h        2012-03-19 18:47:29.000000000 +0000
13869 +++ linux-3.4.83-vs2.3.3.9/include/net/ip6_route.h      2012-05-21 16:15:05.000000000 +0000
13870 @@ -88,7 +88,8 @@ extern int                    ip6_route_get_saddr(struct
13871                                                     struct rt6_info *rt,
13872                                                     const struct in6_addr *daddr,
13873                                                     unsigned int prefs,
13874 -                                                   struct in6_addr *saddr);
13875 +                                                   struct in6_addr *saddr,
13876 +                                                   struct nx_info *nxi);
13877  
13878  extern struct rt6_info         *rt6_lookup(struct net *net,
13879                                             const struct in6_addr *daddr,
13880 diff -NurpP --minimal linux-3.4.83/include/net/route.h linux-3.4.83-vs2.3.3.9/include/net/route.h
13881 --- linux-3.4.83/include/net/route.h    2012-03-19 18:47:29.000000000 +0000
13882 +++ linux-3.4.83-vs2.3.3.9/include/net/route.h  2012-05-21 16:15:05.000000000 +0000
13883 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13884                 dst_release(&rt->dst);
13885  }
13886  
13887 +#include <linux/vs_base.h>
13888 +#include <linux/vs_inet.h>
13889 +
13890  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13891  
13892  extern const __u8 ip_tos2prio[16];
13893 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13894                            protocol, flow_flags, dst, src, dport, sport);
13895  }
13896  
13897 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13898 +       struct flowi4 *);
13899 +
13900  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13901                                               __be32 dst, __be32 src, u32 tos,
13902                                               int oif, u8 protocol,
13903 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13904  {
13905         struct net *net = sock_net(sk);
13906         struct rtable *rt;
13907 +       struct nx_info *nx_info = current_nx_info();
13908  
13909         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13910                               sport, dport, sk, can_sleep);
13911  
13912 -       if (!dst || !src) {
13913 +       if (sk)
13914 +               nx_info = sk->sk_nx_info;
13915 +
13916 +       vxdprintk(VXD_CBIT(net, 4),
13917 +               "ip_route_connect(%p) %p,%p;%lx",
13918 +               sk, nx_info, sk->sk_socket,
13919 +               (sk->sk_socket?sk->sk_socket->flags:0));
13920 +
13921 +       rt = ip_v4_find_src(net, nx_info, fl4);
13922 +       if (IS_ERR(rt))
13923 +               return rt;
13924 +       ip_rt_put(rt);
13925 +
13926 +       if (!fl4->daddr || !fl4->saddr) {
13927                 rt = __ip_route_output_key(net, fl4);
13928                 if (IS_ERR(rt))
13929                         return rt;
13930 diff -NurpP --minimal linux-3.4.83/include/net/sock.h linux-3.4.83-vs2.3.3.9/include/net/sock.h
13931 --- linux-3.4.83/include/net/sock.h     2014-03-12 09:48:20.000000000 +0000
13932 +++ linux-3.4.83-vs2.3.3.9/include/net/sock.h   2013-07-14 13:38:35.000000000 +0000
13933 @@ -170,6 +170,10 @@ struct sock_common {
13934  #ifdef CONFIG_NET_NS
13935         struct net              *skc_net;
13936  #endif
13937 +       xid_t                   skc_xid;
13938 +       struct vx_info          *skc_vx_info;
13939 +       nid_t                   skc_nid;
13940 +       struct nx_info          *skc_nx_info;
13941         /*
13942          * fields between dontcopy_begin/dontcopy_end
13943          * are not copied in sock_copy()
13944 @@ -282,6 +286,10 @@ struct sock {
13945  #define sk_bind_node           __sk_common.skc_bind_node
13946  #define sk_prot                        __sk_common.skc_prot
13947  #define sk_net                 __sk_common.skc_net
13948 +#define sk_xid                 __sk_common.skc_xid
13949 +#define sk_vx_info             __sk_common.skc_vx_info
13950 +#define sk_nid                 __sk_common.skc_nid
13951 +#define sk_nx_info             __sk_common.skc_nx_info
13952         socket_lock_t           sk_lock;
13953         struct sk_buff_head     sk_receive_queue;
13954         /*
13955 diff -NurpP --minimal linux-3.4.83/init/Kconfig linux-3.4.83-vs2.3.3.9/init/Kconfig
13956 --- linux-3.4.83/init/Kconfig   2012-05-21 16:07:33.000000000 +0000
13957 +++ linux-3.4.83-vs2.3.3.9/init/Kconfig 2012-05-21 16:15:05.000000000 +0000
13958 @@ -579,6 +579,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13959  menuconfig CGROUPS
13960         boolean "Control Group support"
13961         depends on EVENTFD
13962 +       default y
13963         help
13964           This option adds support for grouping sets of processes together, for
13965           use with process control subsystems such as Cpusets, CFS, memory
13966 @@ -828,6 +829,7 @@ config IPC_NS
13967  config USER_NS
13968         bool "User namespace (EXPERIMENTAL)"
13969         depends on EXPERIMENTAL
13970 +       depends on VSERVER_DISABLED
13971         default y
13972         help
13973           This allows containers, i.e. vservers, to use user namespaces
13974 diff -NurpP --minimal linux-3.4.83/init/main.c linux-3.4.83-vs2.3.3.9/init/main.c
13975 --- linux-3.4.83/init/main.c    2014-03-12 09:48:21.000000000 +0000
13976 +++ linux-3.4.83-vs2.3.3.9/init/main.c  2013-10-26 18:10:57.000000000 +0000
13977 @@ -69,6 +69,7 @@
13978  #include <linux/slab.h>
13979  #include <linux/perf_event.h>
13980  #include <linux/random.h>
13981 +#include <linux/vserver/percpu.h>
13982  
13983  #include <asm/io.h>
13984  #include <asm/bugs.h>
13985 diff -NurpP --minimal linux-3.4.83/ipc/mqueue.c linux-3.4.83-vs2.3.3.9/ipc/mqueue.c
13986 --- linux-3.4.83/ipc/mqueue.c   2012-05-21 16:07:34.000000000 +0000
13987 +++ linux-3.4.83-vs2.3.3.9/ipc/mqueue.c 2012-05-21 16:15:05.000000000 +0000
13988 @@ -34,6 +34,8 @@
13989  #include <linux/ipc_namespace.h>
13990  #include <linux/user_namespace.h>
13991  #include <linux/slab.h>
13992 +#include <linux/vs_context.h>
13993 +#include <linux/vs_limit.h>
13994  
13995  #include <net/sock.h>
13996  #include "util.h"
13997 @@ -67,6 +69,7 @@ struct mqueue_inode_info {
13998         struct sigevent notify;
13999         struct pid* notify_owner;
14000         struct user_struct *user;       /* user who created, for accounting */
14001 +       struct vx_info *vxi;
14002         struct sock *notify_sock;
14003         struct sk_buff *notify_cookie;
14004  
14005 @@ -129,6 +132,7 @@ static struct inode *mqueue_get_inode(st
14006         if (S_ISREG(mode)) {
14007                 struct mqueue_inode_info *info;
14008                 unsigned long mq_bytes, mq_msg_tblsz;
14009 +               struct vx_info *vxi = current_vx_info();
14010  
14011                 inode->i_fop = &mqueue_file_operations;
14012                 inode->i_size = FILENT_SIZE;
14013 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14014                 info->notify_owner = NULL;
14015                 info->qsize = 0;
14016                 info->user = NULL;      /* set when all is ok */
14017 +               info->vxi = NULL;
14018                 memset(&info->attr, 0, sizeof(info->attr));
14019                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14020                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14021 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14022  
14023                 spin_lock(&mq_lock);
14024                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14025 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
14026 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
14027 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14028                         spin_unlock(&mq_lock);
14029                         /* mqueue_evict_inode() releases info->messages */
14030                         ret = -EMFILE;
14031                         goto out_inode;
14032                 }
14033                 u->mq_bytes += mq_bytes;
14034 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14035                 spin_unlock(&mq_lock);
14036  
14037                 /* all is ok */
14038                 info->user = get_uid(u);
14039 +               info->vxi = get_vx_info(vxi);
14040         } else if (S_ISDIR(mode)) {
14041                 inc_nlink(inode);
14042                 /* Some things misbehave if size == 0 on a directory */
14043 @@ -267,8 +275,11 @@ static void mqueue_evict_inode(struct in
14044             + info->attr.mq_msgsize);
14045         user = info->user;
14046         if (user) {
14047 +               struct vx_info *vxi = info->vxi;
14048 +
14049                 spin_lock(&mq_lock);
14050                 user->mq_bytes -= mq_bytes;
14051 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14052                 /*
14053                  * get_ns_from_inode() ensures that the
14054                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14055 @@ -278,6 +289,7 @@ static void mqueue_evict_inode(struct in
14056                 if (ipc_ns)
14057                         ipc_ns->mq_queues_count--;
14058                 spin_unlock(&mq_lock);
14059 +               put_vx_info(vxi);
14060                 free_uid(user);
14061         }
14062         if (ipc_ns)
14063 diff -NurpP --minimal linux-3.4.83/ipc/msg.c linux-3.4.83-vs2.3.3.9/ipc/msg.c
14064 --- linux-3.4.83/ipc/msg.c      2011-05-22 14:17:59.000000000 +0000
14065 +++ linux-3.4.83-vs2.3.3.9/ipc/msg.c    2012-05-21 16:15:05.000000000 +0000
14066 @@ -37,6 +37,7 @@
14067  #include <linux/rwsem.h>
14068  #include <linux/nsproxy.h>
14069  #include <linux/ipc_namespace.h>
14070 +#include <linux/vs_base.h>
14071  
14072  #include <asm/current.h>
14073  #include <asm/uaccess.h>
14074 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14075  
14076         msq->q_perm.mode = msgflg & S_IRWXUGO;
14077         msq->q_perm.key = key;
14078 +       msq->q_perm.xid = vx_current_xid();
14079  
14080         msq->q_perm.security = NULL;
14081         retval = security_msg_queue_alloc(msq);
14082 diff -NurpP --minimal linux-3.4.83/ipc/namespace.c linux-3.4.83-vs2.3.3.9/ipc/namespace.c
14083 --- linux-3.4.83/ipc/namespace.c        2011-07-22 09:18:12.000000000 +0000
14084 +++ linux-3.4.83-vs2.3.3.9/ipc/namespace.c      2012-05-21 16:15:05.000000000 +0000
14085 @@ -13,11 +13,12 @@
14086  #include <linux/mount.h>
14087  #include <linux/user_namespace.h>
14088  #include <linux/proc_fs.h>
14089 +#include <linux/vs_base.h>
14090 +#include <linux/vserver/global.h>
14091  
14092  #include "util.h"
14093  
14094 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14095 -                                          struct ipc_namespace *old_ns)
14096 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14097  {
14098         struct ipc_namespace *ns;
14099         int err;
14100 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14101         ipcns_notify(IPCNS_CREATED);
14102         register_ipcns_notifier(ns);
14103  
14104 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14105 +       ns->user_ns = get_user_ns(user_ns);
14106  
14107         return ns;
14108  }
14109  
14110  struct ipc_namespace *copy_ipcs(unsigned long flags,
14111 -                               struct task_struct *tsk)
14112 +                               struct ipc_namespace *old_ns,
14113 +                               struct user_namespace *user_ns)
14114  {
14115 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14116 -
14117         if (!(flags & CLONE_NEWIPC))
14118 -               return get_ipc_ns(ns);
14119 -       return create_ipc_ns(tsk, ns);
14120 +               return get_ipc_ns(old_ns);
14121 +       return create_ipc_ns(user_ns);
14122  }
14123  
14124  /*
14125 diff -NurpP --minimal linux-3.4.83/ipc/sem.c linux-3.4.83-vs2.3.3.9/ipc/sem.c
14126 --- linux-3.4.83/ipc/sem.c      2012-01-09 15:14:59.000000000 +0000
14127 +++ linux-3.4.83-vs2.3.3.9/ipc/sem.c    2012-05-21 16:15:05.000000000 +0000
14128 @@ -86,6 +86,8 @@
14129  #include <linux/rwsem.h>
14130  #include <linux/nsproxy.h>
14131  #include <linux/ipc_namespace.h>
14132 +#include <linux/vs_base.h>
14133 +#include <linux/vs_limit.h>
14134  
14135  #include <asm/uaccess.h>
14136  #include "util.h"
14137 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14138  
14139         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14140         sma->sem_perm.key = key;
14141 +       sma->sem_perm.xid = vx_current_xid();
14142  
14143         sma->sem_perm.security = NULL;
14144         retval = security_sem_alloc(sma);
14145 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14146                 return id;
14147         }
14148         ns->used_sems += nsems;
14149 +       /* FIXME: obsoleted? */
14150 +       vx_semary_inc(sma);
14151 +       vx_nsems_add(sma, nsems);
14152  
14153         sma->sem_base = (struct sem *) &sma[1];
14154  
14155 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14156  
14157         wake_up_sem_queue_do(&tasks);
14158         ns->used_sems -= sma->sem_nsems;
14159 +       /* FIXME: obsoleted? */
14160 +       vx_nsems_sub(sma, sma->sem_nsems);
14161 +       vx_semary_dec(sma);
14162         security_sem_free(sma);
14163         ipc_rcu_putref(sma);
14164  }
14165 diff -NurpP --minimal linux-3.4.83/ipc/shm.c linux-3.4.83-vs2.3.3.9/ipc/shm.c
14166 --- linux-3.4.83/ipc/shm.c      2014-03-12 09:48:21.000000000 +0000
14167 +++ linux-3.4.83-vs2.3.3.9/ipc/shm.c    2013-07-14 13:38:36.000000000 +0000
14168 @@ -39,6 +39,8 @@
14169  #include <linux/nsproxy.h>
14170  #include <linux/mount.h>
14171  #include <linux/ipc_namespace.h>
14172 +#include <linux/vs_context.h>
14173 +#include <linux/vs_limit.h>
14174  
14175  #include <asm/uaccess.h>
14176  
14177 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14178   */
14179  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14180  {
14181 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14182 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14183 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14184 +
14185 +       vx_ipcshm_sub(vxi, shp, numpages);
14186 +       ns->shm_tot -= numpages;
14187 +
14188         shm_rmid(ns, shp);
14189         shm_unlock(shp);
14190         if (!is_file_hugepages(shp->shm_file))
14191 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14192                                                 shp->mlock_user);
14193         fput (shp->shm_file);
14194         security_shm_free(shp);
14195 +       put_vx_info(vxi);
14196         ipc_rcu_putref(shp);
14197  }
14198  
14199 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14200         if (ns->shm_tot + numpages > ns->shm_ctlall)
14201                 return -ENOSPC;
14202  
14203 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14204 +               return -ENOSPC;
14205 +
14206         shp = ipc_rcu_alloc(sizeof(*shp));
14207         if (!shp)
14208                 return -ENOMEM;
14209  
14210         shp->shm_perm.key = key;
14211 +       shp->shm_perm.xid = vx_current_xid();
14212         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14213         shp->mlock_user = NULL;
14214  
14215 @@ -523,6 +535,7 @@ static int newseg(struct ipc_namespace *
14216         ns->shm_tot += numpages;
14217         error = shp->shm_perm.id;
14218         shm_unlock(shp);
14219 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14220         return error;
14221  
14222  no_id:
14223 diff -NurpP --minimal linux-3.4.83/kernel/Makefile linux-3.4.83-vs2.3.3.9/kernel/Makefile
14224 --- linux-3.4.83/kernel/Makefile        2012-05-21 16:07:34.000000000 +0000
14225 +++ linux-3.4.83-vs2.3.3.9/kernel/Makefile      2012-05-21 16:15:05.000000000 +0000
14226 @@ -25,6 +25,7 @@ endif
14227  obj-y += sched/
14228  obj-y += power/
14229  
14230 +obj-y += vserver/
14231  obj-$(CONFIG_FREEZER) += freezer.o
14232  obj-$(CONFIG_PROFILING) += profile.o
14233  obj-$(CONFIG_STACKTRACE) += stacktrace.o
14234 diff -NurpP --minimal linux-3.4.83/kernel/auditsc.c linux-3.4.83-vs2.3.3.9/kernel/auditsc.c
14235 --- linux-3.4.83/kernel/auditsc.c       2012-03-19 18:47:29.000000000 +0000
14236 +++ linux-3.4.83-vs2.3.3.9/kernel/auditsc.c     2012-05-21 16:15:05.000000000 +0000
14237 @@ -2308,7 +2308,7 @@ int audit_set_loginuid(uid_t loginuid)
14238         if (task->loginuid != -1)
14239                 return -EPERM;
14240  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14241 -       if (!capable(CAP_AUDIT_CONTROL))
14242 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14243                 return -EPERM;
14244  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14245  
14246 diff -NurpP --minimal linux-3.4.83/kernel/capability.c linux-3.4.83-vs2.3.3.9/kernel/capability.c
14247 --- linux-3.4.83/kernel/capability.c    2012-03-19 18:47:29.000000000 +0000
14248 +++ linux-3.4.83-vs2.3.3.9/kernel/capability.c  2012-05-21 16:15:05.000000000 +0000
14249 @@ -15,6 +15,7 @@
14250  #include <linux/syscalls.h>
14251  #include <linux/pid_namespace.h>
14252  #include <linux/user_namespace.h>
14253 +#include <linux/vs_context.h>
14254  #include <asm/uaccess.h>
14255  
14256  /*
14257 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14258         return 0;
14259  }
14260  
14261 +
14262  /*
14263   * The only thing that can change the capabilities of the current
14264   * process is the current process. As such, we can't be in this code
14265 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14266         return (ret == 0);
14267  }
14268  
14269 +#include <linux/vserver/base.h>
14270 +
14271  /**
14272   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14273   * initial user ns
14274 diff -NurpP --minimal linux-3.4.83/kernel/compat.c linux-3.4.83-vs2.3.3.9/kernel/compat.c
14275 --- linux-3.4.83/kernel/compat.c        2012-05-21 16:07:34.000000000 +0000
14276 +++ linux-3.4.83-vs2.3.3.9/kernel/compat.c      2012-05-21 16:15:05.000000000 +0000
14277 @@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14278         if (err)
14279                 return err;
14280  
14281 -       do_settimeofday(&tv);
14282 +       vx_settimeofday(&tv);
14283         return 0;
14284  }
14285  
14286 diff -NurpP --minimal linux-3.4.83/kernel/cred.c linux-3.4.83-vs2.3.3.9/kernel/cred.c
14287 --- linux-3.4.83/kernel/cred.c  2012-05-21 16:07:34.000000000 +0000
14288 +++ linux-3.4.83-vs2.3.3.9/kernel/cred.c        2012-05-21 16:15:05.000000000 +0000
14289 @@ -62,31 +62,6 @@ struct cred init_cred = {
14290  #endif
14291  };
14292  
14293 -static inline void set_cred_subscribers(struct cred *cred, int n)
14294 -{
14295 -#ifdef CONFIG_DEBUG_CREDENTIALS
14296 -       atomic_set(&cred->subscribers, n);
14297 -#endif
14298 -}
14299 -
14300 -static inline int read_cred_subscribers(const struct cred *cred)
14301 -{
14302 -#ifdef CONFIG_DEBUG_CREDENTIALS
14303 -       return atomic_read(&cred->subscribers);
14304 -#else
14305 -       return 0;
14306 -#endif
14307 -}
14308 -
14309 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14310 -{
14311 -#ifdef CONFIG_DEBUG_CREDENTIALS
14312 -       struct cred *cred = (struct cred *) _cred;
14313 -
14314 -       atomic_add(n, &cred->subscribers);
14315 -#endif
14316 -}
14317 -
14318  /*
14319   * Dispose of the shared task group credentials
14320   */
14321 @@ -282,21 +257,16 @@ error:
14322   *
14323   * Call commit_creds() or abort_creds() to clean up.
14324   */
14325 -struct cred *prepare_creds(void)
14326 +struct cred *__prepare_creds(const struct cred *old)
14327  {
14328 -       struct task_struct *task = current;
14329 -       const struct cred *old;
14330         struct cred *new;
14331  
14332 -       validate_process_creds();
14333 -
14334         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14335         if (!new)
14336                 return NULL;
14337  
14338         kdebug("prepare_creds() alloc %p", new);
14339  
14340 -       old = task->cred;
14341         memcpy(new, old, sizeof(struct cred));
14342  
14343         atomic_set(&new->usage, 1);
14344 @@ -323,6 +293,13 @@ error:
14345         abort_creds(new);
14346         return NULL;
14347  }
14348 +
14349 +struct cred *prepare_creds(void)
14350 +{
14351 +       validate_process_creds();
14352 +
14353 +       return __prepare_creds(current->cred);
14354 +}
14355  EXPORT_SYMBOL(prepare_creds);
14356  
14357  /*
14358 diff -NurpP --minimal linux-3.4.83/kernel/exit.c linux-3.4.83-vs2.3.3.9/kernel/exit.c
14359 --- linux-3.4.83/kernel/exit.c  2014-03-12 09:48:21.000000000 +0000
14360 +++ linux-3.4.83-vs2.3.3.9/kernel/exit.c        2012-12-08 00:54:06.000000000 +0000
14361 @@ -48,6 +48,10 @@
14362  #include <linux/fs_struct.h>
14363  #include <linux/init_task.h>
14364  #include <linux/perf_event.h>
14365 +#include <linux/vs_limit.h>
14366 +#include <linux/vs_context.h>
14367 +#include <linux/vs_network.h>
14368 +#include <linux/vs_pid.h>
14369  #include <trace/events/sched.h>
14370  #include <linux/hw_breakpoint.h>
14371  #include <linux/oom.h>
14372 @@ -482,9 +486,11 @@ static void close_files(struct files_str
14373                                         filp_close(file, files);
14374                                         cond_resched();
14375                                 }
14376 +                               vx_openfd_dec(i);
14377                         }
14378                         i++;
14379                         set >>= 1;
14380 +                       cond_resched();
14381                 }
14382         }
14383  }
14384 @@ -699,15 +705,25 @@ static struct task_struct *find_new_reap
14385         __acquires(&tasklist_lock)
14386  {
14387         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14388 -       struct task_struct *thread;
14389 +       struct vx_info *vxi = task_get_vx_info(father);
14390 +       struct task_struct *thread = father;
14391 +       struct task_struct *reaper;
14392  
14393 -       thread = father;
14394         while_each_thread(father, thread) {
14395                 if (thread->flags & PF_EXITING)
14396                         continue;
14397                 if (unlikely(pid_ns->child_reaper == father))
14398                         pid_ns->child_reaper = thread;
14399 -               return thread;
14400 +               reaper = thread;
14401 +               goto out_put;
14402 +       }
14403 +
14404 +       reaper = pid_ns->child_reaper;
14405 +       if (vxi) {
14406 +               BUG_ON(!vxi->vx_reaper);
14407 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14408 +                   vxi->vx_reaper != father)
14409 +                       reaper = vxi->vx_reaper;
14410         }
14411  
14412         if (unlikely(pid_ns->child_reaper == father)) {
14413 @@ -751,7 +767,9 @@ static struct task_struct *find_new_reap
14414                 }
14415         }
14416  
14417 -       return pid_ns->child_reaper;
14418 +out_put:
14419 +       put_vx_info(vxi);
14420 +       return reaper;
14421  }
14422  
14423  /*
14424 @@ -802,10 +820,15 @@ static void forget_original_parent(struc
14425         list_for_each_entry_safe(p, n, &father->children, sibling) {
14426                 struct task_struct *t = p;
14427                 do {
14428 -                       t->real_parent = reaper;
14429 +                       struct task_struct *new_parent = reaper;
14430 +
14431 +                       if (unlikely(p == reaper))
14432 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14433 +
14434 +                       t->real_parent = new_parent;
14435                         if (t->parent == father) {
14436                                 BUG_ON(t->ptrace);
14437 -                               t->parent = t->real_parent;
14438 +                               t->parent = new_parent;
14439                         }
14440                         if (t->pdeath_signal)
14441                                 group_send_sig_info(t->pdeath_signal,
14442 @@ -1013,6 +1036,9 @@ void do_exit(long code)
14443          */
14444         ptrace_put_breakpoints(tsk);
14445  
14446 +       /* needs to stay before exit_notify() */
14447 +       exit_vx_info_early(tsk, code);
14448 +
14449         exit_notify(tsk, group_dead);
14450  #ifdef CONFIG_NUMA
14451         task_lock(tsk);
14452 @@ -1063,10 +1089,15 @@ void do_exit(long code)
14453         smp_mb();
14454         raw_spin_unlock_wait(&tsk->pi_lock);
14455  
14456 +       /* needs to stay after exit_notify() */
14457 +       exit_vx_info(tsk, code);
14458 +       exit_nx_info(tsk);
14459 +
14460         /* causes final put_task_struct in finish_task_switch(). */
14461         tsk->state = TASK_DEAD;
14462         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14463         schedule();
14464 +       printk("bad task: %p [%lx]\n", current, current->state);
14465         BUG();
14466         /* Avoid "noreturn function does return".  */
14467         for (;;)
14468 diff -NurpP --minimal linux-3.4.83/kernel/fork.c linux-3.4.83-vs2.3.3.9/kernel/fork.c
14469 --- linux-3.4.83/kernel/fork.c  2014-03-12 09:48:21.000000000 +0000
14470 +++ linux-3.4.83-vs2.3.3.9/kernel/fork.c        2014-03-12 09:56:10.000000000 +0000
14471 @@ -68,6 +68,9 @@
14472  #include <linux/oom.h>
14473  #include <linux/khugepaged.h>
14474  #include <linux/signalfd.h>
14475 +#include <linux/vs_context.h>
14476 +#include <linux/vs_network.h>
14477 +#include <linux/vs_limit.h>
14478  
14479  #include <asm/pgtable.h>
14480  #include <asm/pgalloc.h>
14481 @@ -170,6 +173,8 @@ void free_task(struct task_struct *tsk)
14482         account_kernel_stack(tsk->stack, -1);
14483         free_thread_info(tsk->stack);
14484         rt_mutex_debug_task_free(tsk);
14485 +       clr_vx_info(&tsk->vx_info);
14486 +       clr_nx_info(&tsk->nx_info);
14487         ftrace_graph_exit_task(tsk);
14488         free_task_struct(tsk);
14489  }
14490 @@ -507,6 +512,7 @@ static struct mm_struct *mm_init(struct
14491         if (likely(!mm_alloc_pgd(mm))) {
14492                 mm->def_flags = 0;
14493                 mmu_notifier_mm_init(mm);
14494 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14495                 return mm;
14496         }
14497  
14498 @@ -559,6 +565,7 @@ void __mmdrop(struct mm_struct *mm)
14499         destroy_context(mm);
14500         mmu_notifier_mm_destroy(mm);
14501         check_mm(mm);
14502 +       clr_vx_info(&mm->mm_vx_info);
14503         free_mm(mm);
14504  }
14505  EXPORT_SYMBOL_GPL(__mmdrop);
14506 @@ -794,6 +801,7 @@ struct mm_struct *dup_mm(struct task_str
14507                 goto fail_nomem;
14508  
14509         memcpy(mm, oldmm, sizeof(*mm));
14510 +       mm->mm_vx_info = NULL;
14511         mm_init_cpumask(mm);
14512  
14513         /* Initializing for Swap token stuff */
14514 @@ -837,6 +845,7 @@ fail_nocontext:
14515          * If init_new_context() failed, we cannot use mmput() to free the mm
14516          * because it calls destroy_context()
14517          */
14518 +       clr_vx_info(&mm->mm_vx_info);
14519         mm_free_pgd(mm);
14520         free_mm(mm);
14521         return NULL;
14522 @@ -1124,6 +1133,8 @@ static struct task_struct *copy_process(
14523  {
14524         int retval;
14525         struct task_struct *p;
14526 +       struct vx_info *vxi;
14527 +       struct nx_info *nxi;
14528  
14529         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14530                 return ERR_PTR(-EINVAL);
14531 @@ -1170,7 +1181,12 @@ static struct task_struct *copy_process(
14532         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14533         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14534  #endif
14535 +       init_vx_info(&p->vx_info, current_vx_info());
14536 +       init_nx_info(&p->nx_info, current_nx_info());
14537 +
14538         retval = -EAGAIN;
14539 +       if (!vx_nproc_avail(1))
14540 +               goto bad_fork_free;
14541         if (atomic_read(&p->real_cred->user->processes) >=
14542                         task_rlimit(p, RLIMIT_NPROC)) {
14543                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14544 @@ -1441,6 +1457,18 @@ static struct task_struct *copy_process(
14545  
14546         total_forks++;
14547         spin_unlock(&current->sighand->siglock);
14548 +
14549 +       /* p is copy of current */
14550 +       vxi = p->vx_info;
14551 +       if (vxi) {
14552 +               claim_vx_info(vxi, p);
14553 +               atomic_inc(&vxi->cvirt.nr_threads);
14554 +               atomic_inc(&vxi->cvirt.total_forks);
14555 +               vx_nproc_inc(p);
14556 +       }
14557 +       nxi = p->nx_info;
14558 +       if (nxi)
14559 +               claim_nx_info(nxi, p);
14560         write_unlock_irq(&tasklist_lock);
14561         proc_fork_connector(p);
14562         cgroup_post_fork(p);
14563 diff -NurpP --minimal linux-3.4.83/kernel/kthread.c linux-3.4.83-vs2.3.3.9/kernel/kthread.c
14564 --- linux-3.4.83/kernel/kthread.c       2014-03-12 09:48:21.000000000 +0000
14565 +++ linux-3.4.83-vs2.3.3.9/kernel/kthread.c     2012-10-22 13:09:53.000000000 +0000
14566 @@ -16,6 +16,7 @@
14567  #include <linux/mutex.h>
14568  #include <linux/slab.h>
14569  #include <linux/freezer.h>
14570 +#include <linux/vs_pid.h>
14571  #include <trace/events/sched.h>
14572  
14573  static DEFINE_SPINLOCK(kthread_create_lock);
14574 diff -NurpP --minimal linux-3.4.83/kernel/nsproxy.c linux-3.4.83-vs2.3.3.9/kernel/nsproxy.c
14575 --- linux-3.4.83/kernel/nsproxy.c       2012-01-09 15:15:00.000000000 +0000
14576 +++ linux-3.4.83-vs2.3.3.9/kernel/nsproxy.c     2012-05-21 16:15:05.000000000 +0000
14577 @@ -20,11 +20,14 @@
14578  #include <linux/mnt_namespace.h>
14579  #include <linux/utsname.h>
14580  #include <linux/pid_namespace.h>
14581 +#include <linux/vserver/global.h>
14582 +#include <linux/vserver/debug.h>
14583  #include <net/net_namespace.h>
14584  #include <linux/ipc_namespace.h>
14585  #include <linux/proc_fs.h>
14586  #include <linux/file.h>
14587  #include <linux/syscalls.h>
14588 +#include "../fs/mount.h"
14589  
14590  static struct kmem_cache *nsproxy_cachep;
14591  
14592 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14593         struct nsproxy *nsproxy;
14594  
14595         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14596 -       if (nsproxy)
14597 +       if (nsproxy) {
14598                 atomic_set(&nsproxy->count, 1);
14599 +               atomic_inc(&vs_global_nsproxy);
14600 +       }
14601 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14602         return nsproxy;
14603  }
14604  
14605 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14606   * Return the newly created nsproxy.  Do not attach this to the task,
14607   * leave it to the caller to do proper locking and attach it to task.
14608   */
14609 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14610 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14611 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14612 +                       struct nsproxy *orig,
14613 +                       struct fs_struct *new_fs,
14614 +                       struct user_namespace *new_user,
14615 +                       struct pid_namespace *new_pid)
14616  {
14617         struct nsproxy *new_nsp;
14618         int err;
14619 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14620         if (!new_nsp)
14621                 return ERR_PTR(-ENOMEM);
14622  
14623 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14624 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14625         if (IS_ERR(new_nsp->mnt_ns)) {
14626                 err = PTR_ERR(new_nsp->mnt_ns);
14627                 goto out_ns;
14628         }
14629  
14630 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14631 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14632         if (IS_ERR(new_nsp->uts_ns)) {
14633                 err = PTR_ERR(new_nsp->uts_ns);
14634                 goto out_uts;
14635         }
14636  
14637 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14638 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14639         if (IS_ERR(new_nsp->ipc_ns)) {
14640                 err = PTR_ERR(new_nsp->ipc_ns);
14641                 goto out_ipc;
14642         }
14643  
14644 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14645 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14646         if (IS_ERR(new_nsp->pid_ns)) {
14647                 err = PTR_ERR(new_nsp->pid_ns);
14648                 goto out_pid;
14649         }
14650  
14651 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14652 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14653         if (IS_ERR(new_nsp->net_ns)) {
14654                 err = PTR_ERR(new_nsp->net_ns);
14655                 goto out_net;
14656 @@ -115,6 +124,40 @@ out_ns:
14657         return ERR_PTR(err);
14658  }
14659  
14660 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14661 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14662 +{
14663 +       return unshare_namespaces(flags, tsk->nsproxy,
14664 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14665 +               task_active_pid_ns(tsk));
14666 +}
14667 +
14668 +/*
14669 + * copies the nsproxy, setting refcount to 1, and grabbing a
14670 + * reference to all contained namespaces.
14671 + */
14672 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14673 +{
14674 +       struct nsproxy *ns = create_nsproxy();
14675 +
14676 +       if (ns) {
14677 +               memcpy(ns, orig, sizeof(struct nsproxy));
14678 +               atomic_set(&ns->count, 1);
14679 +
14680 +               if (ns->mnt_ns)
14681 +                       get_mnt_ns(ns->mnt_ns);
14682 +               if (ns->uts_ns)
14683 +                       get_uts_ns(ns->uts_ns);
14684 +               if (ns->ipc_ns)
14685 +                       get_ipc_ns(ns->ipc_ns);
14686 +               if (ns->pid_ns)
14687 +                       get_pid_ns(ns->pid_ns);
14688 +               if (ns->net_ns)
14689 +                       get_net(ns->net_ns);
14690 +       }
14691 +       return ns;
14692 +}
14693 +
14694  /*
14695   * called from clone.  This now handles copy for nsproxy and all
14696   * namespaces therein.
14697 @@ -122,9 +165,12 @@ out_ns:
14698  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14699  {
14700         struct nsproxy *old_ns = tsk->nsproxy;
14701 -       struct nsproxy *new_ns;
14702 +       struct nsproxy *new_ns = NULL;
14703         int err = 0;
14704  
14705 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14706 +               flags, tsk, old_ns);
14707 +
14708         if (!old_ns)
14709                 return 0;
14710  
14711 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14712                                 CLONE_NEWPID | CLONE_NEWNET)))
14713                 return 0;
14714  
14715 -       if (!capable(CAP_SYS_ADMIN)) {
14716 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14717                 err = -EPERM;
14718                 goto out;
14719         }
14720 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14721  
14722  out:
14723         put_nsproxy(old_ns);
14724 +       vxdprintk(VXD_CBIT(space, 3),
14725 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14726 +               flags, tsk, old_ns, err, new_ns);
14727         return err;
14728  }
14729  
14730 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14731                 put_ipc_ns(ns->ipc_ns);
14732         if (ns->pid_ns)
14733                 put_pid_ns(ns->pid_ns);
14734 -       put_net(ns->net_ns);
14735 +       if (ns->net_ns)
14736 +               put_net(ns->net_ns);
14737 +       atomic_dec(&vs_global_nsproxy);
14738         kmem_cache_free(nsproxy_cachep, ns);
14739  }
14740  
14741 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned
14742  {
14743         int err = 0;
14744  
14745 +       vxdprintk(VXD_CBIT(space, 4),
14746 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14747 +               unshare_flags, current->nsproxy);
14748 +
14749         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14750                                CLONE_NEWNET)))
14751                 return 0;
14752  
14753 -       if (!capable(CAP_SYS_ADMIN))
14754 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14755                 return -EPERM;
14756  
14757         *new_nsp = create_new_namespaces(unshare_flags, current,
14758 diff -NurpP --minimal linux-3.4.83/kernel/pid.c linux-3.4.83-vs2.3.3.9/kernel/pid.c
14759 --- linux-3.4.83/kernel/pid.c   2012-03-19 18:47:30.000000000 +0000
14760 +++ linux-3.4.83-vs2.3.3.9/kernel/pid.c 2012-05-21 16:15:05.000000000 +0000
14761 @@ -36,6 +36,7 @@
14762  #include <linux/pid_namespace.h>
14763  #include <linux/init_task.h>
14764  #include <linux/syscalls.h>
14765 +#include <linux/vs_pid.h>
14766  
14767  #define pid_hashfn(nr, ns)     \
14768         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14769 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14770  
14771  struct pid *find_vpid(int nr)
14772  {
14773 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14774 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14775  }
14776  EXPORT_SYMBOL_GPL(find_vpid);
14777  
14778 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14779  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14780  {
14781         struct task_struct *result = NULL;
14782 +
14783 +       if (type == PIDTYPE_REALPID)
14784 +               type = PIDTYPE_PID;
14785         if (pid) {
14786                 struct hlist_node *first;
14787                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14788 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14789         rcu_lockdep_assert(rcu_read_lock_held(),
14790                            "find_task_by_pid_ns() needs rcu_read_lock()"
14791                            " protection");
14792 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14793 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14794  }
14795  
14796  struct task_struct *find_task_by_vpid(pid_t vnr)
14797 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14798  }
14799  EXPORT_SYMBOL_GPL(find_get_pid);
14800  
14801 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14802 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14803  {
14804         struct upid *upid;
14805         pid_t nr = 0;
14806 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14807         return nr;
14808  }
14809  
14810 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14811 +{
14812 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14813 +}
14814 +
14815  pid_t pid_vnr(struct pid *pid)
14816  {
14817         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14818 diff -NurpP --minimal linux-3.4.83/kernel/pid_namespace.c linux-3.4.83-vs2.3.3.9/kernel/pid_namespace.c
14819 --- linux-3.4.83/kernel/pid_namespace.c 2012-05-21 16:07:34.000000000 +0000
14820 +++ linux-3.4.83-vs2.3.3.9/kernel/pid_namespace.c       2012-05-21 16:15:05.000000000 +0000
14821 @@ -16,6 +16,7 @@
14822  #include <linux/slab.h>
14823  #include <linux/proc_fs.h>
14824  #include <linux/reboot.h>
14825 +#include <linux/vserver/global.h>
14826  
14827  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14828  
14829 @@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14830                 goto out_free_map;
14831  
14832         kref_init(&ns->kref);
14833 +       atomic_inc(&vs_global_pid_ns);
14834         ns->level = level;
14835         ns->parent = get_pid_ns(parent_pid_ns);
14836  
14837 @@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14838  
14839         for (i = 0; i < PIDMAP_ENTRIES; i++)
14840                 kfree(ns->pidmap[i].page);
14841 +       atomic_dec(&vs_global_pid_ns);
14842         kmem_cache_free(pid_ns_cachep, ns);
14843  }
14844  
14845 diff -NurpP --minimal linux-3.4.83/kernel/posix-timers.c linux-3.4.83-vs2.3.3.9/kernel/posix-timers.c
14846 --- linux-3.4.83/kernel/posix-timers.c  2014-03-12 09:48:21.000000000 +0000
14847 +++ linux-3.4.83-vs2.3.3.9/kernel/posix-timers.c        2013-03-30 21:29:17.000000000 +0000
14848 @@ -47,6 +47,7 @@
14849  #include <linux/wait.h>
14850  #include <linux/workqueue.h>
14851  #include <linux/export.h>
14852 +#include <linux/vs_context.h>
14853  
14854  /*
14855   * Management arrays for POSIX timers.  Timers are kept in slab memory
14856 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14857  {
14858         struct task_struct *task;
14859         int shared, ret = -1;
14860 +
14861         /*
14862          * FIXME: if ->sigq is queued we can race with
14863          * dequeue_signal()->do_schedule_next_timer().
14864 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14865         rcu_read_lock();
14866         task = pid_task(timr->it_pid, PIDTYPE_PID);
14867         if (task) {
14868 +               struct vx_info_save vxis;
14869 +               struct vx_info *vxi;
14870 +
14871 +               vxi = get_vx_info(task->vx_info);
14872 +               enter_vx_info(vxi, &vxis);
14873                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14874                 ret = send_sigqueue(timr->sigq, task, shared);
14875 +               leave_vx_info(&vxis);
14876 +               put_vx_info(vxi);
14877         }
14878         rcu_read_unlock();
14879 +
14880         /* If we failed to send the signal the timer stops. */
14881         return ret > 0;
14882  }
14883 diff -NurpP --minimal linux-3.4.83/kernel/printk.c linux-3.4.83-vs2.3.3.9/kernel/printk.c
14884 --- linux-3.4.83/kernel/printk.c        2014-03-12 09:48:21.000000000 +0000
14885 +++ linux-3.4.83-vs2.3.3.9/kernel/printk.c      2014-03-12 09:55:28.000000000 +0000
14886 @@ -41,6 +41,7 @@
14887  #include <linux/cpu.h>
14888  #include <linux/notifier.h>
14889  #include <linux/rculist.h>
14890 +#include <linux/vs_cvirt.h>
14891  
14892  #include <asm/uaccess.h>
14893  
14894 @@ -317,7 +318,7 @@ static int check_syslog_permissions(int
14895                 return 0;
14896  
14897         if (syslog_action_restricted(type)) {
14898 -               if (capable(CAP_SYSLOG))
14899 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14900                         return 0;
14901                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14902                 if (capable(CAP_SYS_ADMIN)) {
14903 @@ -347,12 +348,9 @@ int do_syslog(int type, char __user *buf
14904         if (error)
14905                 return error;
14906  
14907 -       switch (type) {
14908 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14909 -               break;
14910 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14911 -               break;
14912 -       case SYSLOG_ACTION_READ:        /* Read from log */
14913 +       if ((type == SYSLOG_ACTION_READ) ||
14914 +           (type == SYSLOG_ACTION_READ_ALL) ||
14915 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14916                 error = -EINVAL;
14917                 if (!buf || len < 0)
14918                         goto out;
14919 @@ -363,6 +361,16 @@ int do_syslog(int type, char __user *buf
14920                         error = -EFAULT;
14921                         goto out;
14922                 }
14923 +       }
14924 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14925 +               return vx_do_syslog(type, buf, len);
14926 +
14927 +       switch (type) {
14928 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14929 +               break;
14930 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14931 +               break;
14932 +       case SYSLOG_ACTION_READ:        /* Read from log */
14933                 error = wait_event_interruptible(log_wait,
14934                                                         (log_start - log_end));
14935                 if (error)
14936 @@ -389,16 +397,6 @@ int do_syslog(int type, char __user *buf
14937                 /* FALL THRU */
14938         /* Read last kernel messages */
14939         case SYSLOG_ACTION_READ_ALL:
14940 -               error = -EINVAL;
14941 -               if (!buf || len < 0)
14942 -                       goto out;
14943 -               error = 0;
14944 -               if (!len)
14945 -                       goto out;
14946 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14947 -                       error = -EFAULT;
14948 -                       goto out;
14949 -               }
14950                 count = len;
14951                 if (count > log_buf_len)
14952                         count = log_buf_len;
14953 diff -NurpP --minimal linux-3.4.83/kernel/ptrace.c linux-3.4.83-vs2.3.3.9/kernel/ptrace.c
14954 --- linux-3.4.83/kernel/ptrace.c        2014-03-12 09:48:21.000000000 +0000
14955 +++ linux-3.4.83-vs2.3.3.9/kernel/ptrace.c      2014-03-12 09:55:28.000000000 +0000
14956 @@ -22,6 +22,7 @@
14957  #include <linux/syscalls.h>
14958  #include <linux/uaccess.h>
14959  #include <linux/regset.h>
14960 +#include <linux/vs_context.h>
14961  #include <linux/hw_breakpoint.h>
14962  #include <linux/cn_proc.h>
14963  
14964 @@ -257,6 +258,11 @@ ok:
14965         if (dumpable != SUID_DUMP_USER &&
14966             !ptrace_has_cap(task_user_ns(task), mode))
14967                 return -EPERM;
14968 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14969 +               return -EPERM;
14970 +       if (!vx_check(task->xid, VS_IDENT) &&
14971 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14972 +               return -EACCES;
14973  
14974         return security_ptrace_access_check(task, mode);
14975  }
14976 diff -NurpP --minimal linux-3.4.83/kernel/sched/core.c linux-3.4.83-vs2.3.3.9/kernel/sched/core.c
14977 --- linux-3.4.83/kernel/sched/core.c    2014-03-12 09:48:22.000000000 +0000
14978 +++ linux-3.4.83-vs2.3.3.9/kernel/sched/core.c  2014-03-12 09:55:28.000000000 +0000
14979 @@ -72,6 +72,8 @@
14980  #include <linux/slab.h>
14981  #include <linux/init_task.h>
14982  #include <linux/binfmts.h>
14983 +#include <linux/vs_sched.h>
14984 +#include <linux/vs_cvirt.h>
14985  
14986  #include <asm/switch_to.h>
14987  #include <asm/tlb.h>
14988 @@ -2226,9 +2228,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14989   */
14990  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14991  {
14992 -       loads[0] = (avenrun[0] + offset) << shift;
14993 -       loads[1] = (avenrun[1] + offset) << shift;
14994 -       loads[2] = (avenrun[2] + offset) << shift;
14995 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14996 +               struct vx_info *vxi = current_vx_info();
14997 +
14998 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14999 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15000 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15001 +       } else {
15002 +               loads[0] = (avenrun[0] + offset) << shift;
15003 +               loads[1] = (avenrun[1] + offset) << shift;
15004 +               loads[2] = (avenrun[2] + offset) << shift;
15005 +       }
15006  }
15007  
15008  static long calc_load_fold_active(struct rq *this_rq)
15009 @@ -2857,14 +2867,17 @@ static inline void task_group_account_fi
15010  void account_user_time(struct task_struct *p, cputime_t cputime,
15011                        cputime_t cputime_scaled)
15012  {
15013 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15014 +       int nice = (TASK_NICE(p) > 0);
15015         int index;
15016  
15017         /* Add user time to process. */
15018         p->utime += cputime;
15019         p->utimescaled += cputime_scaled;
15020 +       vx_account_user(vxi, cputime, nice);
15021         account_group_user_time(p, cputime);
15022  
15023 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
15024 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
15025  
15026         /* Add user time to cpustat. */
15027         task_group_account_field(p, index, (__force u64) cputime);
15028 @@ -2911,9 +2924,12 @@ static inline
15029  void __account_system_time(struct task_struct *p, cputime_t cputime,
15030                         cputime_t cputime_scaled, int index)
15031  {
15032 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15033 +
15034         /* Add system time to process. */
15035         p->stime += cputime;
15036         p->stimescaled += cputime_scaled;
15037 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15038         account_group_system_time(p, cputime);
15039  
15040         /* Add system time to cpustat. */
15041 @@ -4139,7 +4155,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15042                 nice = 19;
15043  
15044         if (increment < 0 && !can_nice(current, nice))
15045 -               return -EPERM;
15046 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15047  
15048         retval = security_task_setnice(current, nice);
15049         if (retval)
15050 diff -NurpP --minimal linux-3.4.83/kernel/sched/fair.c linux-3.4.83-vs2.3.3.9/kernel/sched/fair.c
15051 --- linux-3.4.83/kernel/sched/fair.c    2014-03-12 09:48:22.000000000 +0000
15052 +++ linux-3.4.83-vs2.3.3.9/kernel/sched/fair.c  2014-03-12 09:55:28.000000000 +0000
15053 @@ -26,6 +26,7 @@
15054  #include <linux/slab.h>
15055  #include <linux/profile.h>
15056  #include <linux/interrupt.h>
15057 +#include <linux/vs_cvirt.h>
15058  
15059  #include <trace/events/sched.h>
15060  
15061 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15062                 __enqueue_entity(cfs_rq, se);
15063         se->on_rq = 1;
15064  
15065 +       if (entity_is_task(se))
15066 +               vx_activate_task(task_of(se));
15067         if (cfs_rq->nr_running == 1) {
15068                 list_add_leaf_cfs_rq(cfs_rq);
15069                 check_enqueue_throttle(cfs_rq);
15070 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15071         if (se != cfs_rq->curr)
15072                 __dequeue_entity(cfs_rq, se);
15073         se->on_rq = 0;
15074 +       if (entity_is_task(se))
15075 +               vx_deactivate_task(task_of(se));
15076         update_cfs_load(cfs_rq, 0);
15077         account_entity_dequeue(cfs_rq, se);
15078  
15079 diff -NurpP --minimal linux-3.4.83/kernel/signal.c linux-3.4.83-vs2.3.3.9/kernel/signal.c
15080 --- linux-3.4.83/kernel/signal.c        2014-03-12 09:48:22.000000000 +0000
15081 +++ linux-3.4.83-vs2.3.3.9/kernel/signal.c      2013-07-14 13:38:36.000000000 +0000
15082 @@ -29,6 +29,8 @@
15083  #include <linux/pid_namespace.h>
15084  #include <linux/nsproxy.h>
15085  #include <linux/user_namespace.h>
15086 +#include <linux/vs_context.h>
15087 +#include <linux/vs_pid.h>
15088  #define CREATE_TRACE_POINTS
15089  #include <trace/events/signal.h>
15090  
15091 @@ -787,9 +789,18 @@ static int check_kill_permission(int sig
15092         struct pid *sid;
15093         int error;
15094  
15095 +       vxdprintk(VXD_CBIT(misc, 7),
15096 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15097 +               sig, info, t, vx_task_xid(t), t->pid);
15098 +
15099         if (!valid_signal(sig))
15100                 return -EINVAL;
15101  
15102 +/*     FIXME: needed? if so, why?
15103 +       if ((info != SEND_SIG_NOINFO) &&
15104 +               (is_si_special(info) || !si_fromuser(info)))
15105 +               goto skip;      */
15106 +
15107         if (!si_fromuser(info))
15108                 return 0;
15109  
15110 @@ -813,6 +824,20 @@ static int check_kill_permission(int sig
15111                 }
15112         }
15113  
15114 +       error = -EPERM;
15115 +       if (t->pid == 1 && current->xid)
15116 +               return error;
15117 +
15118 +       error = -ESRCH;
15119 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15120 +                 loops, maybe ENOENT or EACCES? */
15121 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15122 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15123 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15124 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15125 +               return error;
15126 +       }
15127 +/* skip: */
15128         return security_task_kill(t, info, sig, 0);
15129  }
15130  
15131 @@ -1355,7 +1380,7 @@ int kill_pid_info(int sig, struct siginf
15132         rcu_read_lock();
15133  retry:
15134         p = pid_task(pid, PIDTYPE_PID);
15135 -       if (p) {
15136 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15137                 error = group_send_sig_info(sig, info, p);
15138                 if (unlikely(error == -ESRCH))
15139                         /*
15140 @@ -1405,7 +1430,7 @@ int kill_pid_info_as_cred(int sig, struc
15141  
15142         rcu_read_lock();
15143         p = pid_task(pid, PIDTYPE_PID);
15144 -       if (!p) {
15145 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15146                 ret = -ESRCH;
15147                 goto out_unlock;
15148         }
15149 @@ -1457,8 +1482,10 @@ static int kill_something_info(int sig,
15150                 struct task_struct * p;
15151  
15152                 for_each_process(p) {
15153 -                       if (task_pid_vnr(p) > 1 &&
15154 -                                       !same_thread_group(p, current)) {
15155 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15156 +                               task_pid_vnr(p) > 1 &&
15157 +                               !same_thread_group(p, current) &&
15158 +                               !vx_current_initpid(p->pid)) {
15159                                 int err = group_send_sig_info(sig, info, p);
15160                                 ++count;
15161                                 if (err != -EPERM)
15162 @@ -2312,6 +2339,11 @@ relock:
15163                                 !sig_kernel_only(signr))
15164                         continue;
15165  
15166 +               /* virtual init is protected against user signals */
15167 +               if ((info->si_code == SI_USER) &&
15168 +                       vx_current_initpid(current->pid))
15169 +                       continue;
15170 +
15171                 if (sig_kernel_stop(signr)) {
15172                         /*
15173                          * The default action is to stop all threads in
15174 diff -NurpP --minimal linux-3.4.83/kernel/softirq.c linux-3.4.83-vs2.3.3.9/kernel/softirq.c
15175 --- linux-3.4.83/kernel/softirq.c       2012-05-21 16:07:34.000000000 +0000
15176 +++ linux-3.4.83-vs2.3.3.9/kernel/softirq.c     2012-05-21 16:15:05.000000000 +0000
15177 @@ -24,6 +24,7 @@
15178  #include <linux/ftrace.h>
15179  #include <linux/smp.h>
15180  #include <linux/tick.h>
15181 +#include <linux/vs_context.h>
15182  
15183  #define CREATE_TRACE_POINTS
15184  #include <trace/events/irq.h>
15185 diff -NurpP --minimal linux-3.4.83/kernel/sys.c linux-3.4.83-vs2.3.3.9/kernel/sys.c
15186 --- linux-3.4.83/kernel/sys.c   2014-03-12 09:48:22.000000000 +0000
15187 +++ linux-3.4.83-vs2.3.3.9/kernel/sys.c 2013-07-14 13:38:36.000000000 +0000
15188 @@ -45,6 +45,7 @@
15189  #include <linux/syscalls.h>
15190  #include <linux/kprobes.h>
15191  #include <linux/user_namespace.h>
15192 +#include <linux/vs_pid.h>
15193  
15194  #include <linux/kmsg_dump.h>
15195  /* Move somewhere else to avoid recompiling? */
15196 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15197                 goto out;
15198         }
15199         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15200 -               error = -EACCES;
15201 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15202 +                       error = 0;
15203 +               else
15204 +                       error = -EACCES;
15205                 goto out;
15206         }
15207         no_nice = security_task_setnice(p, niceval);
15208 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15209                         else
15210                                 pgrp = task_pgrp(current);
15211                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15212 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15213 +                                       continue;
15214                                 error = set_one_prio(p, niceval, error);
15215                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15216                         break;
15217 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15218                         else
15219                                 pgrp = task_pgrp(current);
15220                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15221 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15222 +                                       continue;
15223                                 niceval = 20 - task_nice(p);
15224                                 if (niceval > retval)
15225                                         retval = niceval;
15226 @@ -443,6 +451,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15227  
15228  static DEFINE_MUTEX(reboot_mutex);
15229  
15230 +long vs_reboot(unsigned int, void __user *);
15231 +
15232  /*
15233   * Reboot system call: for obvious reasons only root may call it,
15234   * and even root needs to set up some magic numbers in the registers
15235 @@ -484,6 +494,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15236         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15237                 cmd = LINUX_REBOOT_CMD_HALT;
15238  
15239 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15240 +               return vs_reboot(cmd, arg);
15241 +
15242         mutex_lock(&reboot_mutex);
15243         switch (cmd) {
15244         case LINUX_REBOOT_CMD_RESTART:
15245 @@ -1309,7 +1322,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15246         int errno;
15247         char tmp[__NEW_UTS_LEN];
15248  
15249 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15250 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15251 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15252                 return -EPERM;
15253  
15254         if (len < 0 || len > __NEW_UTS_LEN)
15255 @@ -1360,7 +1374,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15256         int errno;
15257         char tmp[__NEW_UTS_LEN];
15258  
15259 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15260 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15261 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15262                 return -EPERM;
15263         if (len < 0 || len > __NEW_UTS_LEN)
15264                 return -EINVAL;
15265 @@ -1479,7 +1494,7 @@ int do_prlimit(struct task_struct *tsk,
15266                 /* Keep the capable check against init_user_ns until
15267                    cgroups can contain all limits */
15268                 if (new_rlim->rlim_max > rlim->rlim_max &&
15269 -                               !capable(CAP_SYS_RESOURCE))
15270 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15271                         retval = -EPERM;
15272                 if (!retval)
15273                         retval = security_task_setrlimit(tsk->group_leader,
15274 @@ -1533,7 +1548,8 @@ static int check_prlimit_permission(stru
15275              cred->gid == tcred->sgid &&
15276              cred->gid == tcred->gid))
15277                 return 0;
15278 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15279 +       if (vx_ns_capable(tcred->user->user_ns,
15280 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15281                 return 0;
15282  
15283         return -EPERM;
15284 diff -NurpP --minimal linux-3.4.83/kernel/sysctl.c linux-3.4.83-vs2.3.3.9/kernel/sysctl.c
15285 --- linux-3.4.83/kernel/sysctl.c        2012-05-21 16:07:34.000000000 +0000
15286 +++ linux-3.4.83-vs2.3.3.9/kernel/sysctl.c      2012-05-21 16:15:05.000000000 +0000
15287 @@ -81,6 +81,7 @@
15288  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15289  #include <linux/lockdep.h>
15290  #endif
15291 +extern char vshelper_path[];
15292  #ifdef CONFIG_CHR_DEV_SG
15293  #include <scsi/sg.h>
15294  #endif
15295 @@ -562,6 +563,13 @@ static struct ctl_table kern_table[] = {
15296                 .proc_handler   = proc_dostring,
15297         },
15298  #endif
15299 +       {
15300 +               .procname       = "vshelper",
15301 +               .data           = &vshelper_path,
15302 +               .maxlen         = 256,
15303 +               .mode           = 0644,
15304 +               .proc_handler   = &proc_dostring,
15305 +       },
15306  #ifdef CONFIG_CHR_DEV_SG
15307         {
15308                 .procname       = "sg-big-buff",
15309 diff -NurpP --minimal linux-3.4.83/kernel/sysctl_binary.c linux-3.4.83-vs2.3.3.9/kernel/sysctl_binary.c
15310 --- linux-3.4.83/kernel/sysctl_binary.c 2014-03-12 09:48:22.000000000 +0000
15311 +++ linux-3.4.83-vs2.3.3.9/kernel/sysctl_binary.c       2013-03-30 21:29:17.000000000 +0000
15312 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15313  
15314         { CTL_INT,      KERN_PANIC,                     "panic" },
15315         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15316 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15317  
15318         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15319         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15320 diff -NurpP --minimal linux-3.4.83/kernel/time/timekeeping.c linux-3.4.83-vs2.3.3.9/kernel/time/timekeeping.c
15321 --- linux-3.4.83/kernel/time/timekeeping.c      2014-03-12 09:48:22.000000000 +0000
15322 +++ linux-3.4.83-vs2.3.3.9/kernel/time/timekeeping.c    2014-03-12 09:55:28.000000000 +0000
15323 @@ -254,6 +254,7 @@ void getnstimeofday(struct timespec *ts)
15324         } while (read_seqretry(&timekeeper.lock, seq));
15325  
15326         timespec_add_ns(ts, nsecs);
15327 +       vx_adjust_timespec(ts);
15328  }
15329  
15330  EXPORT_SYMBOL(getnstimeofday);
15331 diff -NurpP --minimal linux-3.4.83/kernel/time.c linux-3.4.83-vs2.3.3.9/kernel/time.c
15332 --- linux-3.4.83/kernel/time.c  2012-05-21 16:07:34.000000000 +0000
15333 +++ linux-3.4.83-vs2.3.3.9/kernel/time.c        2012-05-21 16:15:05.000000000 +0000
15334 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15335         if (err)
15336                 return err;
15337  
15338 -       do_settimeofday(&tv);
15339 +       vx_settimeofday(&tv);
15340         return 0;
15341  }
15342  
15343 @@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15344                 }
15345         }
15346         if (tv)
15347 -               return do_settimeofday(tv);
15348 +               return vx_settimeofday(tv);
15349         return 0;
15350  }
15351  
15352 diff -NurpP --minimal linux-3.4.83/kernel/timer.c linux-3.4.83-vs2.3.3.9/kernel/timer.c
15353 --- linux-3.4.83/kernel/timer.c 2014-03-12 09:48:22.000000000 +0000
15354 +++ linux-3.4.83-vs2.3.3.9/kernel/timer.c       2013-08-13 17:07:37.000000000 +0000
15355 @@ -40,6 +40,10 @@
15356  #include <linux/irq_work.h>
15357  #include <linux/sched.h>
15358  #include <linux/slab.h>
15359 +#include <linux/vs_base.h>
15360 +#include <linux/vs_cvirt.h>
15361 +#include <linux/vs_pid.h>
15362 +#include <linux/vserver/sched.h>
15363  
15364  #include <asm/uaccess.h>
15365  #include <asm/unistd.h>
15366 @@ -1390,12 +1394,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15367  
15368  #endif
15369  
15370 -#ifndef __alpha__
15371 -
15372 -/*
15373 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15374 - * should be moved into arch/i386 instead?
15375 - */
15376  
15377  /**
15378   * sys_getpid - return the thread group id of the current process
15379 @@ -1424,10 +1422,23 @@ SYSCALL_DEFINE0(getppid)
15380         rcu_read_lock();
15381         pid = task_tgid_vnr(rcu_dereference(current->real_parent));
15382         rcu_read_unlock();
15383 +       return vx_map_pid(pid);
15384 +}
15385  
15386 -       return pid;
15387 +#ifdef __alpha__
15388 +
15389 +/*
15390 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15391 + */
15392 +
15393 +asmlinkage long do_getxpid(long *ppid)
15394 +{
15395 +       *ppid = sys_getppid();
15396 +       return sys_getpid();
15397  }
15398  
15399 +#else /* _alpha_ */
15400 +
15401  SYSCALL_DEFINE0(getuid)
15402  {
15403         /* Only we change this so SMP safe */
15404 diff -NurpP --minimal linux-3.4.83/kernel/user_namespace.c linux-3.4.83-vs2.3.3.9/kernel/user_namespace.c
15405 --- linux-3.4.83/kernel/user_namespace.c        2012-01-09 15:15:00.000000000 +0000
15406 +++ linux-3.4.83-vs2.3.3.9/kernel/user_namespace.c      2012-05-21 16:15:05.000000000 +0000
15407 @@ -11,6 +11,7 @@
15408  #include <linux/user_namespace.h>
15409  #include <linux/highuid.h>
15410  #include <linux/cred.h>
15411 +#include <linux/vserver/global.h>
15412  
15413  static struct kmem_cache *user_ns_cachep __read_mostly;
15414  
15415 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15416                 return -ENOMEM;
15417  
15418         kref_init(&ns->kref);
15419 +       atomic_inc(&vs_global_user_ns);
15420  
15421         for (n = 0; n < UIDHASH_SZ; ++n)
15422                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15423 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15424         struct user_namespace *ns =
15425                 container_of(kref, struct user_namespace, kref);
15426  
15427 +       /* FIXME: maybe move into destroyer? */
15428 +       atomic_dec(&vs_global_user_ns);
15429         INIT_WORK(&ns->destroyer, free_user_ns_work);
15430         schedule_work(&ns->destroyer);
15431  }
15432 diff -NurpP --minimal linux-3.4.83/kernel/utsname.c linux-3.4.83-vs2.3.3.9/kernel/utsname.c
15433 --- linux-3.4.83/kernel/utsname.c       2012-01-09 15:15:00.000000000 +0000
15434 +++ linux-3.4.83-vs2.3.3.9/kernel/utsname.c     2012-05-21 16:15:05.000000000 +0000
15435 @@ -16,14 +16,17 @@
15436  #include <linux/slab.h>
15437  #include <linux/user_namespace.h>
15438  #include <linux/proc_fs.h>
15439 +#include <linux/vserver/global.h>
15440  
15441  static struct uts_namespace *create_uts_ns(void)
15442  {
15443         struct uts_namespace *uts_ns;
15444  
15445         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15446 -       if (uts_ns)
15447 +       if (uts_ns) {
15448                 kref_init(&uts_ns->kref);
15449 +               atomic_inc(&vs_global_uts_ns);
15450 +       }
15451         return uts_ns;
15452  }
15453  
15454 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15455   * @old_ns: namespace to clone
15456   * Return NULL on error (failure to kmalloc), new ns otherwise
15457   */
15458 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15459 -                                         struct uts_namespace *old_ns)
15460 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15461 +                                         struct user_namespace *old_user)
15462  {
15463         struct uts_namespace *ns;
15464  
15465 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15466  
15467         down_read(&uts_sem);
15468         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15469 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15470 +       ns->user_ns = get_user_ns(old_user);
15471         up_read(&uts_sem);
15472         return ns;
15473  }
15474 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15475   * versa.
15476   */
15477  struct uts_namespace *copy_utsname(unsigned long flags,
15478 -                                  struct task_struct *tsk)
15479 +                                  struct uts_namespace *old_ns,
15480 +                                  struct user_namespace *user_ns)
15481  {
15482 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15483         struct uts_namespace *new_ns;
15484  
15485         BUG_ON(!old_ns);
15486 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15487         if (!(flags & CLONE_NEWUTS))
15488                 return old_ns;
15489  
15490 -       new_ns = clone_uts_ns(tsk, old_ns);
15491 +       new_ns = clone_uts_ns(old_ns, user_ns);
15492  
15493         put_uts_ns(old_ns);
15494         return new_ns;
15495 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15496  
15497         ns = container_of(kref, struct uts_namespace, kref);
15498         put_user_ns(ns->user_ns);
15499 +       atomic_dec(&vs_global_uts_ns);
15500         kfree(ns);
15501  }
15502  
15503 diff -NurpP --minimal linux-3.4.83/kernel/vserver/Kconfig linux-3.4.83-vs2.3.3.9/kernel/vserver/Kconfig
15504 --- linux-3.4.83/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
15505 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/Kconfig       2012-05-21 16:15:05.000000000 +0000
15506 @@ -0,0 +1,224 @@
15507 +#
15508 +# Linux VServer configuration
15509 +#
15510 +
15511 +menu "Linux VServer"
15512 +
15513 +config VSERVER_AUTO_LBACK
15514 +       bool    "Automatically Assign Loopback IP"
15515 +       default y
15516 +       help
15517 +         Automatically assign a guest specific loopback
15518 +         IP and add it to the kernel network stack on
15519 +         startup.
15520 +
15521 +config VSERVER_AUTO_SINGLE
15522 +       bool    "Automatic Single IP Special Casing"
15523 +       depends on EXPERIMENTAL
15524 +       default y
15525 +       help
15526 +         This allows network contexts with a single IP to
15527 +         automatically remap 0.0.0.0 bindings to that IP,
15528 +         avoiding further network checks and improving
15529 +         performance.
15530 +
15531 +         (note: such guests do not allow to change the ip
15532 +          on the fly and do not show loopback addresses)
15533 +
15534 +config VSERVER_COWBL
15535 +       bool    "Enable COW Immutable Link Breaking"
15536 +       default y
15537 +       help
15538 +         This enables the COW (Copy-On-Write) link break code.
15539 +         It allows you to treat unified files like normal files
15540 +         when writing to them (which will implicitely break the
15541 +         link and create a copy of the unified file)
15542 +
15543 +config VSERVER_VTIME
15544 +       bool    "Enable Virtualized Guest Time"
15545 +       depends on EXPERIMENTAL
15546 +       default n
15547 +       help
15548 +         This enables per guest time offsets to allow for
15549 +         adjusting the system clock individually per guest.
15550 +         this adds some overhead to the time functions and
15551 +         therefore should not be enabled without good reason.
15552 +
15553 +config VSERVER_DEVICE
15554 +       bool    "Enable Guest Device Mapping"
15555 +       depends on EXPERIMENTAL
15556 +       default n
15557 +       help
15558 +         This enables generic device remapping.
15559 +
15560 +config VSERVER_PROC_SECURE
15561 +       bool    "Enable Proc Security"
15562 +       depends on PROC_FS
15563 +       default y
15564 +       help
15565 +         This configures ProcFS security to initially hide
15566 +         non-process entries for all contexts except the main and
15567 +         spectator context (i.e. for all guests), which is a secure
15568 +         default.
15569 +
15570 +         (note: on 1.2x the entries were visible by default)
15571 +
15572 +choice
15573 +       prompt  "Persistent Inode Tagging"
15574 +       default TAGGING_ID24
15575 +       help
15576 +         This adds persistent context information to filesystems
15577 +         mounted with the tagxid option. Tagging is a requirement
15578 +         for per-context disk limits and per-context quota.
15579 +
15580 +
15581 +config TAGGING_NONE
15582 +       bool    "Disabled"
15583 +       help
15584 +         do not store per-context information in inodes.
15585 +
15586 +config TAGGING_UID16
15587 +       bool    "UID16/GID32"
15588 +       help
15589 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15590 +
15591 +config TAGGING_GID16
15592 +       bool    "UID32/GID16"
15593 +       help
15594 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15595 +
15596 +config TAGGING_ID24
15597 +       bool    "UID24/GID24"
15598 +       help
15599 +         uses the upper 8bit from UID and GID for XID tagging
15600 +         which leaves 24bit for UID/GID each, which should be
15601 +         more than sufficient for normal use.
15602 +
15603 +config TAGGING_INTERN
15604 +       bool    "UID32/GID32"
15605 +       help
15606 +         this uses otherwise reserved inode fields in the on
15607 +         disk representation, which limits the use to a few
15608 +         filesystems (currently ext2 and ext3)
15609 +
15610 +endchoice
15611 +
15612 +config TAG_NFSD
15613 +       bool    "Tag NFSD User Auth and Files"
15614 +       default n
15615 +       help
15616 +         Enable this if you do want the in-kernel NFS
15617 +         Server to use the tagging specified above.
15618 +         (will require patched clients too)
15619 +
15620 +config VSERVER_PRIVACY
15621 +       bool    "Honor Privacy Aspects of Guests"
15622 +       default n
15623 +       help
15624 +         When enabled, most context checks will disallow
15625 +         access to structures assigned to a specific context,
15626 +         like ptys or loop devices.
15627 +
15628 +config VSERVER_CONTEXTS
15629 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15630 +       range 1 65533
15631 +       default "768"   if 64BIT
15632 +       default "256"
15633 +       help
15634 +         This setting will optimize certain data structures
15635 +         and memory allocations according to the expected
15636 +         maximum.
15637 +
15638 +         note: this is not a strict upper limit.
15639 +
15640 +config VSERVER_WARN
15641 +       bool    "VServer Warnings"
15642 +       default y
15643 +       help
15644 +         This enables various runtime warnings, which will
15645 +         notify about potential manipulation attempts or
15646 +         resource shortage. It is generally considered to
15647 +         be a good idea to have that enabled.
15648 +
15649 +config VSERVER_WARN_DEVPTS
15650 +       bool    "VServer DevPTS Warnings"
15651 +       depends on VSERVER_WARN
15652 +       default y
15653 +       help
15654 +         This enables DevPTS related warnings, issued when a
15655 +         process inside a context tries to lookup or access
15656 +         a dynamic pts from the host or a different context.
15657 +
15658 +config VSERVER_DEBUG
15659 +       bool    "VServer Debugging Code"
15660 +       default n
15661 +       help
15662 +         Set this to yes if you want to be able to activate
15663 +         debugging output at runtime. It adds a very small
15664 +         overhead to all vserver related functions and
15665 +         increases the kernel size by about 20k.
15666 +
15667 +config VSERVER_HISTORY
15668 +       bool    "VServer History Tracing"
15669 +       depends on VSERVER_DEBUG
15670 +       default n
15671 +       help
15672 +         Set this to yes if you want to record the history of
15673 +         linux-vserver activities, so they can be replayed in
15674 +         the event of a kernel panic or oops.
15675 +
15676 +config VSERVER_HISTORY_SIZE
15677 +       int     "Per-CPU History Size (32-65536)"
15678 +       depends on VSERVER_HISTORY
15679 +       range 32 65536
15680 +       default 64
15681 +       help
15682 +         This allows you to specify the number of entries in
15683 +         the per-CPU history buffer.
15684 +
15685 +choice
15686 +       prompt  "Quotes used in debug and warn messages"
15687 +       default QUOTES_ISO8859
15688 +
15689 +config QUOTES_ISO8859
15690 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15691 +       help
15692 +         This uses the extended ASCII characters \xbb
15693 +         and \xab for quoting file and process names.
15694 +
15695 +config QUOTES_UTF8
15696 +       bool    "UTF-8 angle quotes"
15697 +       help
15698 +         This uses the the UTF-8 sequences for angle
15699 +         quotes to quote file and process names.
15700 +
15701 +config QUOTES_ASCII
15702 +       bool    "ASCII single quotes"
15703 +       help
15704 +         This uses the ASCII single quote character
15705 +         (\x27) to quote file and process names.
15706 +
15707 +endchoice
15708 +
15709 +endmenu
15710 +
15711 +
15712 +config VSERVER
15713 +       bool
15714 +       default y
15715 +       select NAMESPACES
15716 +       select UTS_NS
15717 +       select IPC_NS
15718 +#      select USER_NS
15719 +       select SYSVIPC
15720 +
15721 +config VSERVER_SECURITY
15722 +       bool
15723 +       depends on SECURITY
15724 +       default y
15725 +       select SECURITY_CAPABILITIES
15726 +
15727 +config VSERVER_DISABLED
15728 +       bool
15729 +       default n
15730 +
15731 diff -NurpP --minimal linux-3.4.83/kernel/vserver/Makefile linux-3.4.83-vs2.3.3.9/kernel/vserver/Makefile
15732 --- linux-3.4.83/kernel/vserver/Makefile        1970-01-01 00:00:00.000000000 +0000
15733 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/Makefile      2012-05-21 16:15:05.000000000 +0000
15734 @@ -0,0 +1,18 @@
15735 +#
15736 +# Makefile for the Linux vserver routines.
15737 +#
15738 +
15739 +
15740 +obj-y          += vserver.o
15741 +
15742 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15743 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15744 +                  dlimit.o tag.o
15745 +
15746 +vserver-$(CONFIG_INET) += inet.o
15747 +vserver-$(CONFIG_PROC_FS) += proc.o
15748 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15749 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15750 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15751 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15752 +
15753 diff -NurpP --minimal linux-3.4.83/kernel/vserver/cacct.c linux-3.4.83-vs2.3.3.9/kernel/vserver/cacct.c
15754 --- linux-3.4.83/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
15755 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/cacct.c       2012-05-21 16:15:05.000000000 +0000
15756 @@ -0,0 +1,42 @@
15757 +/*
15758 + *  linux/kernel/vserver/cacct.c
15759 + *
15760 + *  Virtual Server: Context Accounting
15761 + *
15762 + *  Copyright (C) 2006-2007 Herbert Pötzl
15763 + *
15764 + *  V0.01  added accounting stats
15765 + *
15766 + */
15767 +
15768 +#include <linux/types.h>
15769 +#include <linux/vs_context.h>
15770 +#include <linux/vserver/cacct_cmd.h>
15771 +#include <linux/vserver/cacct_int.h>
15772 +
15773 +#include <asm/errno.h>
15774 +#include <asm/uaccess.h>
15775 +
15776 +
15777 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15778 +{
15779 +       struct vcmd_sock_stat_v0 vc_data;
15780 +       int j, field;
15781 +
15782 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15783 +               return -EFAULT;
15784 +
15785 +       field = vc_data.field;
15786 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15787 +               return -EINVAL;
15788 +
15789 +       for (j = 0; j < 3; j++) {
15790 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15791 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15792 +       }
15793 +
15794 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15795 +               return -EFAULT;
15796 +       return 0;
15797 +}
15798 +
15799 diff -NurpP --minimal linux-3.4.83/kernel/vserver/cacct_init.h linux-3.4.83-vs2.3.3.9/kernel/vserver/cacct_init.h
15800 --- linux-3.4.83/kernel/vserver/cacct_init.h    1970-01-01 00:00:00.000000000 +0000
15801 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/cacct_init.h  2012-05-21 16:15:05.000000000 +0000
15802 @@ -0,0 +1,25 @@
15803 +
15804 +
15805 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15806 +{
15807 +       int i, j;
15808 +
15809 +
15810 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15811 +               for (j = 0; j < 3; j++) {
15812 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15813 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15814 +               }
15815 +       }
15816 +       for (i = 0; i < 8; i++)
15817 +               atomic_set(&cacct->slab[i], 0);
15818 +       for (i = 0; i < 5; i++)
15819 +               for (j = 0; j < 4; j++)
15820 +                       atomic_set(&cacct->page[i][j], 0);
15821 +}
15822 +
15823 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15824 +{
15825 +       return;
15826 +}
15827 +
15828 diff -NurpP --minimal linux-3.4.83/kernel/vserver/cacct_proc.h linux-3.4.83-vs2.3.3.9/kernel/vserver/cacct_proc.h
15829 --- linux-3.4.83/kernel/vserver/cacct_proc.h    1970-01-01 00:00:00.000000000 +0000
15830 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/cacct_proc.h  2012-05-21 16:15:05.000000000 +0000
15831 @@ -0,0 +1,53 @@
15832 +#ifndef _VX_CACCT_PROC_H
15833 +#define _VX_CACCT_PROC_H
15834 +
15835 +#include <linux/vserver/cacct_int.h>
15836 +
15837 +
15838 +#define VX_SOCKA_TOP   \
15839 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15840 +
15841 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15842 +{
15843 +       int i, j, length = 0;
15844 +       static char *type[VXA_SOCK_SIZE] = {
15845 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15846 +       };
15847 +
15848 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15849 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15850 +               length += sprintf(buffer + length, "%s:", type[i]);
15851 +               for (j = 0; j < 3; j++) {
15852 +                       length += sprintf(buffer + length,
15853 +                               "\t%10lu/%-10lu",
15854 +                               vx_sock_count(cacct, i, j),
15855 +                               vx_sock_total(cacct, i, j));
15856 +               }
15857 +               buffer[length++] = '\n';
15858 +       }
15859 +
15860 +       length += sprintf(buffer + length, "\n");
15861 +       length += sprintf(buffer + length,
15862 +               "slab:\t %8u %8u %8u %8u\n",
15863 +               atomic_read(&cacct->slab[1]),
15864 +               atomic_read(&cacct->slab[4]),
15865 +               atomic_read(&cacct->slab[0]),
15866 +               atomic_read(&cacct->slab[2]));
15867 +
15868 +       length += sprintf(buffer + length, "\n");
15869 +       for (i = 0; i < 5; i++) {
15870 +               length += sprintf(buffer + length,
15871 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15872 +                       atomic_read(&cacct->page[i][0]),
15873 +                       atomic_read(&cacct->page[i][1]),
15874 +                       atomic_read(&cacct->page[i][2]),
15875 +                       atomic_read(&cacct->page[i][3]),
15876 +                       atomic_read(&cacct->page[i][4]),
15877 +                       atomic_read(&cacct->page[i][5]),
15878 +                       atomic_read(&cacct->page[i][6]),
15879 +                       atomic_read(&cacct->page[i][7]));
15880 +       }
15881 +       return length;
15882 +}
15883 +
15884 +#endif /* _VX_CACCT_PROC_H */
15885 diff -NurpP --minimal linux-3.4.83/kernel/vserver/context.c linux-3.4.83-vs2.3.3.9/kernel/vserver/context.c
15886 --- linux-3.4.83/kernel/vserver/context.c       1970-01-01 00:00:00.000000000 +0000
15887 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/context.c     2012-06-28 14:45:48.000000000 +0000
15888 @@ -0,0 +1,1119 @@
15889 +/*
15890 + *  linux/kernel/vserver/context.c
15891 + *
15892 + *  Virtual Server: Context Support
15893 + *
15894 + *  Copyright (C) 2003-2011  Herbert Pötzl
15895 + *
15896 + *  V0.01  context helper
15897 + *  V0.02  vx_ctx_kill syscall command
15898 + *  V0.03  replaced context_info calls
15899 + *  V0.04  redesign of struct (de)alloc
15900 + *  V0.05  rlimit basic implementation
15901 + *  V0.06  task_xid and info commands
15902 + *  V0.07  context flags and caps
15903 + *  V0.08  switch to RCU based hash
15904 + *  V0.09  revert to non RCU for now
15905 + *  V0.10  and back to working RCU hash
15906 + *  V0.11  and back to locking again
15907 + *  V0.12  referenced context store
15908 + *  V0.13  separate per cpu data
15909 + *  V0.14  changed vcmds to vxi arg
15910 + *  V0.15  added context stat
15911 + *  V0.16  have __create claim() the vxi
15912 + *  V0.17  removed older and legacy stuff
15913 + *  V0.18  added user credentials
15914 + *  V0.19  added warn mask
15915 + *
15916 + */
15917 +
15918 +#include <linux/slab.h>
15919 +#include <linux/types.h>
15920 +#include <linux/security.h>
15921 +#include <linux/pid_namespace.h>
15922 +#include <linux/capability.h>
15923 +
15924 +#include <linux/vserver/context.h>
15925 +#include <linux/vserver/network.h>
15926 +#include <linux/vserver/debug.h>
15927 +#include <linux/vserver/limit.h>
15928 +#include <linux/vserver/limit_int.h>
15929 +#include <linux/vserver/space.h>
15930 +#include <linux/init_task.h>
15931 +#include <linux/fs_struct.h>
15932 +#include <linux/cred.h>
15933 +
15934 +#include <linux/vs_context.h>
15935 +#include <linux/vs_limit.h>
15936 +#include <linux/vs_pid.h>
15937 +#include <linux/vserver/context_cmd.h>
15938 +
15939 +#include "cvirt_init.h"
15940 +#include "cacct_init.h"
15941 +#include "limit_init.h"
15942 +#include "sched_init.h"
15943 +
15944 +
15945 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15946 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15947 +
15948 +
15949 +/*     now inactive context structures */
15950 +
15951 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15952 +
15953 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15954 +
15955 +
15956 +/*     __alloc_vx_info()
15957 +
15958 +       * allocate an initialized vx_info struct
15959 +       * doesn't make it visible (hash)                        */
15960 +
15961 +static struct vx_info *__alloc_vx_info(xid_t xid)
15962 +{
15963 +       struct vx_info *new = NULL;
15964 +       int cpu, index;
15965 +
15966 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15967 +
15968 +       /* would this benefit from a slab cache? */
15969 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15970 +       if (!new)
15971 +               return 0;
15972 +
15973 +       memset(new, 0, sizeof(struct vx_info));
15974 +#ifdef CONFIG_SMP
15975 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15976 +       if (!new->ptr_pc)
15977 +               goto error;
15978 +#endif
15979 +       new->vx_id = xid;
15980 +       INIT_HLIST_NODE(&new->vx_hlist);
15981 +       atomic_set(&new->vx_usecnt, 0);
15982 +       atomic_set(&new->vx_tasks, 0);
15983 +       new->vx_parent = NULL;
15984 +       new->vx_state = 0;
15985 +       init_waitqueue_head(&new->vx_wait);
15986 +
15987 +       /* prepare reaper */
15988 +       get_task_struct(init_pid_ns.child_reaper);
15989 +       new->vx_reaper = init_pid_ns.child_reaper;
15990 +       new->vx_badness_bias = 0;
15991 +
15992 +       /* rest of init goes here */
15993 +       vx_info_init_limit(&new->limit);
15994 +       vx_info_init_sched(&new->sched);
15995 +       vx_info_init_cvirt(&new->cvirt);
15996 +       vx_info_init_cacct(&new->cacct);
15997 +
15998 +       /* per cpu data structures */
15999 +       for_each_possible_cpu(cpu) {
16000 +               vx_info_init_sched_pc(
16001 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16002 +               vx_info_init_cvirt_pc(
16003 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16004 +       }
16005 +
16006 +       new->vx_flags = VXF_INIT_SET;
16007 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
16008 +       new->vx_ccaps = 0;
16009 +       new->vx_umask = 0;
16010 +       new->vx_wmask = 0;
16011 +
16012 +       new->reboot_cmd = 0;
16013 +       new->exit_code = 0;
16014 +
16015 +       // preconfig spaces
16016 +       for (index = 0; index < VX_SPACES; index++) {
16017 +               struct _vx_space *space = &new->space[index];
16018 +
16019 +               // filesystem
16020 +               spin_lock(&init_fs.lock);
16021 +               init_fs.users++;
16022 +               spin_unlock(&init_fs.lock);
16023 +               space->vx_fs = &init_fs;
16024 +
16025 +               /* FIXME: do we want defaults? */
16026 +               // space->vx_real_cred = 0;
16027 +               // space->vx_cred = 0;
16028 +       }
16029 +
16030 +
16031 +       vxdprintk(VXD_CBIT(xid, 0),
16032 +               "alloc_vx_info(%d) = %p", xid, new);
16033 +       vxh_alloc_vx_info(new);
16034 +       atomic_inc(&vx_global_ctotal);
16035 +       return new;
16036 +#ifdef CONFIG_SMP
16037 +error:
16038 +       kfree(new);
16039 +       return 0;
16040 +#endif
16041 +}
16042 +
16043 +/*     __dealloc_vx_info()
16044 +
16045 +       * final disposal of vx_info                             */
16046 +
16047 +static void __dealloc_vx_info(struct vx_info *vxi)
16048 +{
16049 +#ifdef CONFIG_VSERVER_WARN
16050 +       struct vx_info_save vxis;
16051 +       int cpu;
16052 +#endif
16053 +       vxdprintk(VXD_CBIT(xid, 0),
16054 +               "dealloc_vx_info(%p)", vxi);
16055 +       vxh_dealloc_vx_info(vxi);
16056 +
16057 +#ifdef CONFIG_VSERVER_WARN
16058 +       enter_vx_info(vxi, &vxis);
16059 +       vx_info_exit_limit(&vxi->limit);
16060 +       vx_info_exit_sched(&vxi->sched);
16061 +       vx_info_exit_cvirt(&vxi->cvirt);
16062 +       vx_info_exit_cacct(&vxi->cacct);
16063 +
16064 +       for_each_possible_cpu(cpu) {
16065 +               vx_info_exit_sched_pc(
16066 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16067 +               vx_info_exit_cvirt_pc(
16068 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16069 +       }
16070 +       leave_vx_info(&vxis);
16071 +#endif
16072 +
16073 +       vxi->vx_id = -1;
16074 +       vxi->vx_state |= VXS_RELEASED;
16075 +
16076 +#ifdef CONFIG_SMP
16077 +       free_percpu(vxi->ptr_pc);
16078 +#endif
16079 +       kfree(vxi);
16080 +       atomic_dec(&vx_global_ctotal);
16081 +}
16082 +
16083 +static void __shutdown_vx_info(struct vx_info *vxi)
16084 +{
16085 +       struct nsproxy *nsproxy;
16086 +       struct fs_struct *fs;
16087 +       struct cred *cred;
16088 +       int index, kill;
16089 +
16090 +       might_sleep();
16091 +
16092 +       vxi->vx_state |= VXS_SHUTDOWN;
16093 +       vs_state_change(vxi, VSC_SHUTDOWN);
16094 +
16095 +       for (index = 0; index < VX_SPACES; index++) {
16096 +               struct _vx_space *space = &vxi->space[index];
16097 +
16098 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16099 +               if (nsproxy)
16100 +                       put_nsproxy(nsproxy);
16101 +
16102 +               fs = xchg(&space->vx_fs, NULL);
16103 +               spin_lock(&fs->lock);
16104 +               kill = !--fs->users;
16105 +               spin_unlock(&fs->lock);
16106 +               if (kill)
16107 +                       free_fs_struct(fs);
16108 +
16109 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16110 +               if (cred)
16111 +                       abort_creds(cred);
16112 +       }
16113 +}
16114 +
16115 +/* exported stuff */
16116 +
16117 +void free_vx_info(struct vx_info *vxi)
16118 +{
16119 +       unsigned long flags;
16120 +       unsigned index;
16121 +
16122 +       /* check for reference counts first */
16123 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16124 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16125 +
16126 +       /* context must not be hashed */
16127 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16128 +
16129 +       /* context shutdown is mandatory */
16130 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16131 +
16132 +       /* spaces check */
16133 +       for (index = 0; index < VX_SPACES; index++) {
16134 +               struct _vx_space *space = &vxi->space[index];
16135 +
16136 +               BUG_ON(space->vx_nsproxy);
16137 +               BUG_ON(space->vx_fs);
16138 +               // BUG_ON(space->vx_real_cred);
16139 +               // BUG_ON(space->vx_cred);
16140 +       }
16141 +
16142 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16143 +       hlist_del(&vxi->vx_hlist);
16144 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16145 +
16146 +       __dealloc_vx_info(vxi);
16147 +}
16148 +
16149 +
16150 +/*     hash table for vx_info hash */
16151 +
16152 +#define VX_HASH_SIZE   13
16153 +
16154 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16155 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16156 +
16157 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16158 +
16159 +
16160 +static inline unsigned int __hashval(xid_t xid)
16161 +{
16162 +       return (xid % VX_HASH_SIZE);
16163 +}
16164 +
16165 +
16166 +
16167 +/*     __hash_vx_info()
16168 +
16169 +       * add the vxi to the global hash table
16170 +       * requires the hash_lock to be held                     */
16171 +
16172 +static inline void __hash_vx_info(struct vx_info *vxi)
16173 +{
16174 +       struct hlist_head *head;
16175 +
16176 +       vxd_assert_lock(&vx_info_hash_lock);
16177 +       vxdprintk(VXD_CBIT(xid, 4),
16178 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16179 +       vxh_hash_vx_info(vxi);
16180 +
16181 +       /* context must not be hashed */
16182 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16183 +
16184 +       vxi->vx_state |= VXS_HASHED;
16185 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16186 +       hlist_add_head(&vxi->vx_hlist, head);
16187 +       atomic_inc(&vx_global_cactive);
16188 +}
16189 +
16190 +/*     __unhash_vx_info()
16191 +
16192 +       * remove the vxi from the global hash table
16193 +       * requires the hash_lock to be held                     */
16194 +
16195 +static inline void __unhash_vx_info(struct vx_info *vxi)
16196 +{
16197 +       unsigned long flags;
16198 +
16199 +       vxd_assert_lock(&vx_info_hash_lock);
16200 +       vxdprintk(VXD_CBIT(xid, 4),
16201 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16202 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16203 +       vxh_unhash_vx_info(vxi);
16204 +
16205 +       /* context must be hashed */
16206 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16207 +       /* but without tasks */
16208 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16209 +
16210 +       vxi->vx_state &= ~VXS_HASHED;
16211 +       hlist_del_init(&vxi->vx_hlist);
16212 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16213 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16214 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16215 +       atomic_dec(&vx_global_cactive);
16216 +}
16217 +
16218 +
16219 +/*     __lookup_vx_info()
16220 +
16221 +       * requires the hash_lock to be held
16222 +       * doesn't increment the vx_refcnt                       */
16223 +
16224 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16225 +{
16226 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16227 +       struct hlist_node *pos;
16228 +       struct vx_info *vxi;
16229 +
16230 +       vxd_assert_lock(&vx_info_hash_lock);
16231 +       hlist_for_each(pos, head) {
16232 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16233 +
16234 +               if (vxi->vx_id == xid)
16235 +                       goto found;
16236 +       }
16237 +       vxi = NULL;
16238 +found:
16239 +       vxdprintk(VXD_CBIT(xid, 0),
16240 +               "__lookup_vx_info(#%u): %p[#%u]",
16241 +               xid, vxi, vxi ? vxi->vx_id : 0);
16242 +       vxh_lookup_vx_info(vxi, xid);
16243 +       return vxi;
16244 +}
16245 +
16246 +
16247 +/*     __create_vx_info()
16248 +
16249 +       * create the requested context
16250 +       * get(), claim() and hash it                            */
16251 +
16252 +static struct vx_info *__create_vx_info(int id)
16253 +{
16254 +       struct vx_info *new, *vxi = NULL;
16255 +
16256 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16257 +
16258 +       if (!(new = __alloc_vx_info(id)))
16259 +               return ERR_PTR(-ENOMEM);
16260 +
16261 +       /* required to make dynamic xids unique */
16262 +       spin_lock(&vx_info_hash_lock);
16263 +
16264 +       /* static context requested */
16265 +       if ((vxi = __lookup_vx_info(id))) {
16266 +               vxdprintk(VXD_CBIT(xid, 0),
16267 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16268 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16269 +                       vxi = ERR_PTR(-EBUSY);
16270 +               else
16271 +                       vxi = ERR_PTR(-EEXIST);
16272 +               goto out_unlock;
16273 +       }
16274 +       /* new context */
16275 +       vxdprintk(VXD_CBIT(xid, 0),
16276 +               "create_vx_info(%d) = %p (new)", id, new);
16277 +       claim_vx_info(new, NULL);
16278 +       __hash_vx_info(get_vx_info(new));
16279 +       vxi = new, new = NULL;
16280 +
16281 +out_unlock:
16282 +       spin_unlock(&vx_info_hash_lock);
16283 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16284 +       if (new)
16285 +               __dealloc_vx_info(new);
16286 +       return vxi;
16287 +}
16288 +
16289 +
16290 +/*     exported stuff                                          */
16291 +
16292 +
16293 +void unhash_vx_info(struct vx_info *vxi)
16294 +{
16295 +       spin_lock(&vx_info_hash_lock);
16296 +       __unhash_vx_info(vxi);
16297 +       spin_unlock(&vx_info_hash_lock);
16298 +       __shutdown_vx_info(vxi);
16299 +       __wakeup_vx_info(vxi);
16300 +}
16301 +
16302 +
16303 +/*     lookup_vx_info()
16304 +
16305 +       * search for a vx_info and get() it
16306 +       * negative id means current                             */
16307 +
16308 +struct vx_info *lookup_vx_info(int id)
16309 +{
16310 +       struct vx_info *vxi = NULL;
16311 +
16312 +       if (id < 0) {
16313 +               vxi = get_vx_info(current_vx_info());
16314 +       } else if (id > 1) {
16315 +               spin_lock(&vx_info_hash_lock);
16316 +               vxi = get_vx_info(__lookup_vx_info(id));
16317 +               spin_unlock(&vx_info_hash_lock);
16318 +       }
16319 +       return vxi;
16320 +}
16321 +
16322 +/*     xid_is_hashed()
16323 +
16324 +       * verify that xid is still hashed                       */
16325 +
16326 +int xid_is_hashed(xid_t xid)
16327 +{
16328 +       int hashed;
16329 +
16330 +       spin_lock(&vx_info_hash_lock);
16331 +       hashed = (__lookup_vx_info(xid) != NULL);
16332 +       spin_unlock(&vx_info_hash_lock);
16333 +       return hashed;
16334 +}
16335 +
16336 +#ifdef CONFIG_PROC_FS
16337 +
16338 +/*     get_xid_list()
16339 +
16340 +       * get a subset of hashed xids for proc
16341 +       * assumes size is at least one                          */
16342 +
16343 +int get_xid_list(int index, unsigned int *xids, int size)
16344 +{
16345 +       int hindex, nr_xids = 0;
16346 +
16347 +       /* only show current and children */
16348 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16349 +               if (index > 0)
16350 +                       return 0;
16351 +               xids[nr_xids] = vx_current_xid();
16352 +               return 1;
16353 +       }
16354 +
16355 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16356 +               struct hlist_head *head = &vx_info_hash[hindex];
16357 +               struct hlist_node *pos;
16358 +
16359 +               spin_lock(&vx_info_hash_lock);
16360 +               hlist_for_each(pos, head) {
16361 +                       struct vx_info *vxi;
16362 +
16363 +                       if (--index > 0)
16364 +                               continue;
16365 +
16366 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16367 +                       xids[nr_xids] = vxi->vx_id;
16368 +                       if (++nr_xids >= size) {
16369 +                               spin_unlock(&vx_info_hash_lock);
16370 +                               goto out;
16371 +                       }
16372 +               }
16373 +               /* keep the lock time short */
16374 +               spin_unlock(&vx_info_hash_lock);
16375 +       }
16376 +out:
16377 +       return nr_xids;
16378 +}
16379 +#endif
16380 +
16381 +#ifdef CONFIG_VSERVER_DEBUG
16382 +
16383 +void   dump_vx_info_inactive(int level)
16384 +{
16385 +       struct hlist_node *entry, *next;
16386 +
16387 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16388 +               struct vx_info *vxi =
16389 +                       list_entry(entry, struct vx_info, vx_hlist);
16390 +
16391 +               dump_vx_info(vxi, level);
16392 +       }
16393 +}
16394 +
16395 +#endif
16396 +
16397 +#if 0
16398 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16399 +{
16400 +       struct user_struct *new_user, *old_user;
16401 +
16402 +       if (!p || !vxi)
16403 +               BUG();
16404 +
16405 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16406 +               return -EACCES;
16407 +
16408 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16409 +       if (!new_user)
16410 +               return -ENOMEM;
16411 +
16412 +       old_user = p->user;
16413 +       if (new_user != old_user) {
16414 +               atomic_inc(&new_user->processes);
16415 +               atomic_dec(&old_user->processes);
16416 +               p->user = new_user;
16417 +       }
16418 +       free_uid(old_user);
16419 +       return 0;
16420 +}
16421 +#endif
16422 +
16423 +#if 0
16424 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16425 +{
16426 +       // p->cap_effective &= vxi->vx_cap_bset;
16427 +       p->cap_effective =
16428 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16429 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16430 +       p->cap_inheritable =
16431 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16432 +       // p->cap_permitted &= vxi->vx_cap_bset;
16433 +       p->cap_permitted =
16434 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16435 +}
16436 +#endif
16437 +
16438 +
16439 +#include <linux/file.h>
16440 +#include <linux/fdtable.h>
16441 +
16442 +static int vx_openfd_task(struct task_struct *tsk)
16443 +{
16444 +       struct files_struct *files = tsk->files;
16445 +       struct fdtable *fdt;
16446 +       const unsigned long *bptr;
16447 +       int count, total;
16448 +
16449 +       /* no rcu_read_lock() because of spin_lock() */
16450 +       spin_lock(&files->file_lock);
16451 +       fdt = files_fdtable(files);
16452 +       bptr = fdt->open_fds;
16453 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16454 +       for (total = 0; count > 0; count--) {
16455 +               if (*bptr)
16456 +                       total += hweight_long(*bptr);
16457 +               bptr++;
16458 +       }
16459 +       spin_unlock(&files->file_lock);
16460 +       return total;
16461 +}
16462 +
16463 +
16464 +/*     for *space compatibility */
16465 +
16466 +asmlinkage long sys_unshare(unsigned long);
16467 +
16468 +/*
16469 + *     migrate task to new context
16470 + *     gets vxi, puts old_vxi on change
16471 + *     optionally unshares namespaces (hack)
16472 + */
16473 +
16474 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16475 +{
16476 +       struct vx_info *old_vxi;
16477 +       int ret = 0;
16478 +
16479 +       if (!p || !vxi)
16480 +               BUG();
16481 +
16482 +       vxdprintk(VXD_CBIT(xid, 5),
16483 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16484 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16485 +
16486 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16487 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16488 +               return -EACCES;
16489 +
16490 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16491 +               return -EFAULT;
16492 +
16493 +       old_vxi = task_get_vx_info(p);
16494 +       if (old_vxi == vxi)
16495 +               goto out;
16496 +
16497 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16498 +       {
16499 +               int openfd;
16500 +
16501 +               task_lock(p);
16502 +               openfd = vx_openfd_task(p);
16503 +
16504 +               if (old_vxi) {
16505 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16506 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16507 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16508 +                       /* FIXME: what about the struct files here? */
16509 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16510 +                       /* account for the executable */
16511 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16512 +               }
16513 +               atomic_inc(&vxi->cvirt.nr_threads);
16514 +               atomic_inc(&vxi->cvirt.nr_running);
16515 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16516 +               /* FIXME: what about the struct files here? */
16517 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16518 +               /* account for the executable */
16519 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16520 +
16521 +               if (old_vxi) {
16522 +                       release_vx_info(old_vxi, p);
16523 +                       clr_vx_info(&p->vx_info);
16524 +               }
16525 +               claim_vx_info(vxi, p);
16526 +               set_vx_info(&p->vx_info, vxi);
16527 +               p->xid = vxi->vx_id;
16528 +
16529 +               vxdprintk(VXD_CBIT(xid, 5),
16530 +                       "moved task %p into vxi:%p[#%d]",
16531 +                       p, vxi, vxi->vx_id);
16532 +
16533 +               // vx_mask_cap_bset(vxi, p);
16534 +               task_unlock(p);
16535 +
16536 +               /* hack for *spaces to provide compatibility */
16537 +               if (unshare) {
16538 +                       struct nsproxy *old_nsp, *new_nsp;
16539 +
16540 +                       ret = unshare_nsproxy_namespaces(
16541 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16542 +                               &new_nsp, NULL);
16543 +                       if (ret)
16544 +                               goto out;
16545 +
16546 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16547 +                       vx_set_space(vxi,
16548 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16549 +                       put_nsproxy(old_nsp);
16550 +               }
16551 +       }
16552 +out:
16553 +       put_vx_info(old_vxi);
16554 +       return ret;
16555 +}
16556 +
16557 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16558 +{
16559 +       struct task_struct *old_reaper;
16560 +       struct vx_info *reaper_vxi;
16561 +
16562 +       if (!vxi)
16563 +               return -EINVAL;
16564 +
16565 +       vxdprintk(VXD_CBIT(xid, 6),
16566 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16567 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16568 +
16569 +       old_reaper = vxi->vx_reaper;
16570 +       if (old_reaper == p)
16571 +               return 0;
16572 +
16573 +       reaper_vxi = task_get_vx_info(p);
16574 +       if (reaper_vxi && reaper_vxi != vxi) {
16575 +               vxwprintk(1,
16576 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16577 +                       "for [xid #%u]",
16578 +                       p->comm, p->pid, p->xid, vx_current_xid());
16579 +               goto out;
16580 +       }
16581 +
16582 +       /* set new child reaper */
16583 +       get_task_struct(p);
16584 +       vxi->vx_reaper = p;
16585 +       put_task_struct(old_reaper);
16586 +out:
16587 +       put_vx_info(reaper_vxi);
16588 +       return 0;
16589 +}
16590 +
16591 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16592 +{
16593 +       if (!vxi)
16594 +               return -EINVAL;
16595 +
16596 +       vxdprintk(VXD_CBIT(xid, 6),
16597 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16598 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16599 +
16600 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16601 +       // vxi->vx_initpid = p->tgid;
16602 +       vxi->vx_initpid = p->pid;
16603 +       return 0;
16604 +}
16605 +
16606 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16607 +{
16608 +       vxdprintk(VXD_CBIT(xid, 6),
16609 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16610 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16611 +
16612 +       vxi->exit_code = code;
16613 +       vxi->vx_initpid = 0;
16614 +}
16615 +
16616 +
16617 +void vx_set_persistent(struct vx_info *vxi)
16618 +{
16619 +       vxdprintk(VXD_CBIT(xid, 6),
16620 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16621 +
16622 +       get_vx_info(vxi);
16623 +       claim_vx_info(vxi, NULL);
16624 +}
16625 +
16626 +void vx_clear_persistent(struct vx_info *vxi)
16627 +{
16628 +       vxdprintk(VXD_CBIT(xid, 6),
16629 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16630 +
16631 +       release_vx_info(vxi, NULL);
16632 +       put_vx_info(vxi);
16633 +}
16634 +
16635 +void vx_update_persistent(struct vx_info *vxi)
16636 +{
16637 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16638 +               vx_set_persistent(vxi);
16639 +       else
16640 +               vx_clear_persistent(vxi);
16641 +}
16642 +
16643 +
16644 +/*     task must be current or locked          */
16645 +
16646 +void   exit_vx_info(struct task_struct *p, int code)
16647 +{
16648 +       struct vx_info *vxi = p->vx_info;
16649 +
16650 +       if (vxi) {
16651 +               atomic_dec(&vxi->cvirt.nr_threads);
16652 +               vx_nproc_dec(p);
16653 +
16654 +               vxi->exit_code = code;
16655 +               release_vx_info(vxi, p);
16656 +       }
16657 +}
16658 +
16659 +void   exit_vx_info_early(struct task_struct *p, int code)
16660 +{
16661 +       struct vx_info *vxi = p->vx_info;
16662 +
16663 +       if (vxi) {
16664 +               if (vxi->vx_initpid == p->pid)
16665 +                       vx_exit_init(vxi, p, code);
16666 +               if (vxi->vx_reaper == p)
16667 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16668 +       }
16669 +}
16670 +
16671 +
16672 +/* vserver syscall commands below here */
16673 +
16674 +/* taks xid and vx_info functions */
16675 +
16676 +#include <asm/uaccess.h>
16677 +
16678 +
16679 +int vc_task_xid(uint32_t id)
16680 +{
16681 +       xid_t xid;
16682 +
16683 +       if (id) {
16684 +               struct task_struct *tsk;
16685 +
16686 +               rcu_read_lock();
16687 +               tsk = find_task_by_real_pid(id);
16688 +               xid = (tsk) ? tsk->xid : -ESRCH;
16689 +               rcu_read_unlock();
16690 +       } else
16691 +               xid = vx_current_xid();
16692 +       return xid;
16693 +}
16694 +
16695 +
16696 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16697 +{
16698 +       struct vcmd_vx_info_v0 vc_data;
16699 +
16700 +       vc_data.xid = vxi->vx_id;
16701 +       vc_data.initpid = vxi->vx_initpid;
16702 +
16703 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16704 +               return -EFAULT;
16705 +       return 0;
16706 +}
16707 +
16708 +
16709 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16710 +{
16711 +       struct vcmd_ctx_stat_v0 vc_data;
16712 +
16713 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16714 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16715 +
16716 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16717 +               return -EFAULT;
16718 +       return 0;
16719 +}
16720 +
16721 +
16722 +/* context functions */
16723 +
16724 +int vc_ctx_create(uint32_t xid, void __user *data)
16725 +{
16726 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16727 +       struct vx_info *new_vxi;
16728 +       int ret;
16729 +
16730 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16731 +               return -EFAULT;
16732 +
16733 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16734 +               return -EINVAL;
16735 +
16736 +       new_vxi = __create_vx_info(xid);
16737 +       if (IS_ERR(new_vxi))
16738 +               return PTR_ERR(new_vxi);
16739 +
16740 +       /* initial flags */
16741 +       new_vxi->vx_flags = vc_data.flagword;
16742 +
16743 +       ret = -ENOEXEC;
16744 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16745 +               goto out;
16746 +
16747 +       ret = vx_migrate_task(current, new_vxi, (!data));
16748 +       if (ret)
16749 +               goto out;
16750 +
16751 +       /* return context id on success */
16752 +       ret = new_vxi->vx_id;
16753 +
16754 +       /* get a reference for persistent contexts */
16755 +       if ((vc_data.flagword & VXF_PERSISTENT))
16756 +               vx_set_persistent(new_vxi);
16757 +out:
16758 +       release_vx_info(new_vxi, NULL);
16759 +       put_vx_info(new_vxi);
16760 +       return ret;
16761 +}
16762 +
16763 +
16764 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16765 +{
16766 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16767 +       int ret;
16768 +
16769 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16770 +               return -EFAULT;
16771 +
16772 +       ret = vx_migrate_task(current, vxi, 0);
16773 +       if (ret)
16774 +               return ret;
16775 +       if (vc_data.flagword & VXM_SET_INIT)
16776 +               ret = vx_set_init(vxi, current);
16777 +       if (ret)
16778 +               return ret;
16779 +       if (vc_data.flagword & VXM_SET_REAPER)
16780 +               ret = vx_set_reaper(vxi, current);
16781 +       return ret;
16782 +}
16783 +
16784 +
16785 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16786 +{
16787 +       struct vcmd_ctx_flags_v0 vc_data;
16788 +
16789 +       vc_data.flagword = vxi->vx_flags;
16790 +
16791 +       /* special STATE flag handling */
16792 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16793 +
16794 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16795 +               return -EFAULT;
16796 +       return 0;
16797 +}
16798 +
16799 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16800 +{
16801 +       struct vcmd_ctx_flags_v0 vc_data;
16802 +       uint64_t mask, trigger;
16803 +
16804 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16805 +               return -EFAULT;
16806 +
16807 +       /* special STATE flag handling */
16808 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16809 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16810 +
16811 +       if (vxi == current_vx_info()) {
16812 +               /* if (trigger & VXF_STATE_SETUP)
16813 +                       vx_mask_cap_bset(vxi, current); */
16814 +               if (trigger & VXF_STATE_INIT) {
16815 +                       int ret;
16816 +
16817 +                       ret = vx_set_init(vxi, current);
16818 +                       if (ret)
16819 +                               return ret;
16820 +                       ret = vx_set_reaper(vxi, current);
16821 +                       if (ret)
16822 +                               return ret;
16823 +               }
16824 +       }
16825 +
16826 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16827 +               vc_data.flagword, mask);
16828 +       if (trigger & VXF_PERSISTENT)
16829 +               vx_update_persistent(vxi);
16830 +
16831 +       return 0;
16832 +}
16833 +
16834 +
16835 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16836 +{
16837 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16838 +
16839 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16840 +       return v;
16841 +}
16842 +
16843 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16844 +{
16845 +       kernel_cap_t c = __cap_empty_set;
16846 +
16847 +       c.cap[0] = v & 0xFFFFFFFF;
16848 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16849 +
16850 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16851 +       return c;
16852 +}
16853 +
16854 +
16855 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16856 +{
16857 +       if (bcaps)
16858 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16859 +       if (ccaps)
16860 +               *ccaps = vxi->vx_ccaps;
16861 +
16862 +       return 0;
16863 +}
16864 +
16865 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16866 +{
16867 +       struct vcmd_ctx_caps_v1 vc_data;
16868 +       int ret;
16869 +
16870 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16871 +       if (ret)
16872 +               return ret;
16873 +       vc_data.cmask = ~0ULL;
16874 +
16875 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16876 +               return -EFAULT;
16877 +       return 0;
16878 +}
16879 +
16880 +static int do_set_caps(struct vx_info *vxi,
16881 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16882 +{
16883 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16884 +
16885 +#if 0
16886 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16887 +               bcaps, bmask, ccaps, cmask);
16888 +#endif
16889 +       vxi->vx_bcaps = cap_t_from_caps(
16890 +               vs_mask_flags(bcold, bcaps, bmask));
16891 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16892 +
16893 +       return 0;
16894 +}
16895 +
16896 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16897 +{
16898 +       struct vcmd_ctx_caps_v1 vc_data;
16899 +
16900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16901 +               return -EFAULT;
16902 +
16903 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16904 +}
16905 +
16906 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16907 +{
16908 +       struct vcmd_bcaps vc_data;
16909 +       int ret;
16910 +
16911 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16912 +       if (ret)
16913 +               return ret;
16914 +       vc_data.bmask = ~0ULL;
16915 +
16916 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16917 +               return -EFAULT;
16918 +       return 0;
16919 +}
16920 +
16921 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16922 +{
16923 +       struct vcmd_bcaps vc_data;
16924 +
16925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16926 +               return -EFAULT;
16927 +
16928 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16929 +}
16930 +
16931 +
16932 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16933 +{
16934 +       struct vcmd_umask vc_data;
16935 +
16936 +       vc_data.umask = vxi->vx_umask;
16937 +       vc_data.mask = ~0ULL;
16938 +
16939 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16940 +               return -EFAULT;
16941 +       return 0;
16942 +}
16943 +
16944 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16945 +{
16946 +       struct vcmd_umask vc_data;
16947 +
16948 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16949 +               return -EFAULT;
16950 +
16951 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16952 +               vc_data.umask, vc_data.mask);
16953 +       return 0;
16954 +}
16955 +
16956 +
16957 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16958 +{
16959 +       struct vcmd_wmask vc_data;
16960 +
16961 +       vc_data.wmask = vxi->vx_wmask;
16962 +       vc_data.mask = ~0ULL;
16963 +
16964 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16965 +               return -EFAULT;
16966 +       return 0;
16967 +}
16968 +
16969 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16970 +{
16971 +       struct vcmd_wmask vc_data;
16972 +
16973 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16974 +               return -EFAULT;
16975 +
16976 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16977 +               vc_data.wmask, vc_data.mask);
16978 +       return 0;
16979 +}
16980 +
16981 +
16982 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16983 +{
16984 +       struct vcmd_badness_v0 vc_data;
16985 +
16986 +       vc_data.bias = vxi->vx_badness_bias;
16987 +
16988 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16989 +               return -EFAULT;
16990 +       return 0;
16991 +}
16992 +
16993 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16994 +{
16995 +       struct vcmd_badness_v0 vc_data;
16996 +
16997 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16998 +               return -EFAULT;
16999 +
17000 +       vxi->vx_badness_bias = vc_data.bias;
17001 +       return 0;
17002 +}
17003 +
17004 +#include <linux/module.h>
17005 +
17006 +EXPORT_SYMBOL_GPL(free_vx_info);
17007 +
17008 diff -NurpP --minimal linux-3.4.83/kernel/vserver/cvirt.c linux-3.4.83-vs2.3.3.9/kernel/vserver/cvirt.c
17009 --- linux-3.4.83/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
17010 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/cvirt.c       2012-05-21 16:15:05.000000000 +0000
17011 @@ -0,0 +1,313 @@
17012 +/*
17013 + *  linux/kernel/vserver/cvirt.c
17014 + *
17015 + *  Virtual Server: Context Virtualization
17016 + *
17017 + *  Copyright (C) 2004-2007  Herbert Pötzl
17018 + *
17019 + *  V0.01  broken out from limit.c
17020 + *  V0.02  added utsname stuff
17021 + *  V0.03  changed vcmds to vxi arg
17022 + *
17023 + */
17024 +
17025 +#include <linux/types.h>
17026 +#include <linux/utsname.h>
17027 +#include <linux/vs_cvirt.h>
17028 +#include <linux/vserver/switch.h>
17029 +#include <linux/vserver/cvirt_cmd.h>
17030 +
17031 +#include <asm/uaccess.h>
17032 +
17033 +
17034 +void vx_vsi_boottime(struct timespec *boottime)
17035 +{
17036 +       struct vx_info *vxi = current_vx_info();
17037 +
17038 +       set_normalized_timespec(boottime,
17039 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
17040 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
17041 +       return;
17042 +}
17043 +
17044 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17045 +{
17046 +       struct vx_info *vxi = current_vx_info();
17047 +
17048 +       set_normalized_timespec(uptime,
17049 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17050 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17051 +       if (!idle)
17052 +               return;
17053 +       set_normalized_timespec(idle,
17054 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17055 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17056 +       return;
17057 +}
17058 +
17059 +uint64_t vx_idle_jiffies(void)
17060 +{
17061 +       return init_task.utime + init_task.stime;
17062 +}
17063 +
17064 +
17065 +
17066 +static inline uint32_t __update_loadavg(uint32_t load,
17067 +       int wsize, int delta, int n)
17068 +{
17069 +       unsigned long long calc, prev;
17070 +
17071 +       /* just set it to n */
17072 +       if (unlikely(delta >= wsize))
17073 +               return (n << FSHIFT);
17074 +
17075 +       calc = delta * n;
17076 +       calc <<= FSHIFT;
17077 +       prev = (wsize - delta);
17078 +       prev *= load;
17079 +       calc += prev;
17080 +       do_div(calc, wsize);
17081 +       return calc;
17082 +}
17083 +
17084 +
17085 +void vx_update_load(struct vx_info *vxi)
17086 +{
17087 +       uint32_t now, last, delta;
17088 +       unsigned int nr_running, nr_uninterruptible;
17089 +       unsigned int total;
17090 +       unsigned long flags;
17091 +
17092 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17093 +
17094 +       now = jiffies;
17095 +       last = vxi->cvirt.load_last;
17096 +       delta = now - last;
17097 +
17098 +       if (delta < 5*HZ)
17099 +               goto out;
17100 +
17101 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17102 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17103 +       total = nr_running + nr_uninterruptible;
17104 +
17105 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17106 +               60*HZ, delta, total);
17107 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17108 +               5*60*HZ, delta, total);
17109 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17110 +               15*60*HZ, delta, total);
17111 +
17112 +       vxi->cvirt.load_last = now;
17113 +out:
17114 +       atomic_inc(&vxi->cvirt.load_updates);
17115 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17116 +}
17117 +
17118 +
17119 +/*
17120 + * Commands to do_syslog:
17121 + *
17122 + *      0 -- Close the log.  Currently a NOP.
17123 + *      1 -- Open the log. Currently a NOP.
17124 + *      2 -- Read from the log.
17125 + *      3 -- Read all messages remaining in the ring buffer.
17126 + *      4 -- Read and clear all messages remaining in the ring buffer
17127 + *      5 -- Clear ring buffer.
17128 + *      6 -- Disable printk's to console
17129 + *      7 -- Enable printk's to console
17130 + *      8 -- Set level of messages printed to console
17131 + *      9 -- Return number of unread characters in the log buffer
17132 + *     10 -- Return size of the log buffer
17133 + */
17134 +int vx_do_syslog(int type, char __user *buf, int len)
17135 +{
17136 +       int error = 0;
17137 +       int do_clear = 0;
17138 +       struct vx_info *vxi = current_vx_info();
17139 +       struct _vx_syslog *log;
17140 +
17141 +       if (!vxi)
17142 +               return -EINVAL;
17143 +       log = &vxi->cvirt.syslog;
17144 +
17145 +       switch (type) {
17146 +       case 0:         /* Close log */
17147 +       case 1:         /* Open log */
17148 +               break;
17149 +       case 2:         /* Read from log */
17150 +               error = wait_event_interruptible(log->log_wait,
17151 +                       (log->log_start - log->log_end));
17152 +               if (error)
17153 +                       break;
17154 +               spin_lock_irq(&log->logbuf_lock);
17155 +               spin_unlock_irq(&log->logbuf_lock);
17156 +               break;
17157 +       case 4:         /* Read/clear last kernel messages */
17158 +               do_clear = 1;
17159 +               /* fall through */
17160 +       case 3:         /* Read last kernel messages */
17161 +               return 0;
17162 +
17163 +       case 5:         /* Clear ring buffer */
17164 +               return 0;
17165 +
17166 +       case 6:         /* Disable logging to console */
17167 +       case 7:         /* Enable logging to console */
17168 +       case 8:         /* Set level of messages printed to console */
17169 +               break;
17170 +
17171 +       case 9:         /* Number of chars in the log buffer */
17172 +               return 0;
17173 +       case 10:        /* Size of the log buffer */
17174 +               return 0;
17175 +       default:
17176 +               error = -EINVAL;
17177 +               break;
17178 +       }
17179 +       return error;
17180 +}
17181 +
17182 +
17183 +/* virtual host info names */
17184 +
17185 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17186 +{
17187 +       struct nsproxy *nsproxy;
17188 +       struct uts_namespace *uts;
17189 +
17190 +       if (id == VHIN_CONTEXT)
17191 +               return vxi->vx_name;
17192 +
17193 +       nsproxy = vxi->space[0].vx_nsproxy;
17194 +       if (!nsproxy)
17195 +               return NULL;
17196 +
17197 +       uts = nsproxy->uts_ns;
17198 +       if (!uts)
17199 +               return NULL;
17200 +
17201 +       switch (id) {
17202 +       case VHIN_SYSNAME:
17203 +               return uts->name.sysname;
17204 +       case VHIN_NODENAME:
17205 +               return uts->name.nodename;
17206 +       case VHIN_RELEASE:
17207 +               return uts->name.release;
17208 +       case VHIN_VERSION:
17209 +               return uts->name.version;
17210 +       case VHIN_MACHINE:
17211 +               return uts->name.machine;
17212 +       case VHIN_DOMAINNAME:
17213 +               return uts->name.domainname;
17214 +       default:
17215 +               return NULL;
17216 +       }
17217 +       return NULL;
17218 +}
17219 +
17220 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17221 +{
17222 +       struct vcmd_vhi_name_v0 vc_data;
17223 +       char *name;
17224 +
17225 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17226 +               return -EFAULT;
17227 +
17228 +       name = vx_vhi_name(vxi, vc_data.field);
17229 +       if (!name)
17230 +               return -EINVAL;
17231 +
17232 +       memcpy(name, vc_data.name, 65);
17233 +       return 0;
17234 +}
17235 +
17236 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17237 +{
17238 +       struct vcmd_vhi_name_v0 vc_data;
17239 +       char *name;
17240 +
17241 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17242 +               return -EFAULT;
17243 +
17244 +       name = vx_vhi_name(vxi, vc_data.field);
17245 +       if (!name)
17246 +               return -EINVAL;
17247 +
17248 +       memcpy(vc_data.name, name, 65);
17249 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17250 +               return -EFAULT;
17251 +       return 0;
17252 +}
17253 +
17254 +
17255 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17256 +{
17257 +       struct vcmd_virt_stat_v0 vc_data;
17258 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17259 +       struct timespec uptime;
17260 +
17261 +       do_posix_clock_monotonic_gettime(&uptime);
17262 +       set_normalized_timespec(&uptime,
17263 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17264 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17265 +
17266 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17267 +       vc_data.uptime = timespec_to_ns(&uptime);
17268 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17269 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17270 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17271 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17272 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17273 +       vc_data.load[0] = cvirt->load[0];
17274 +       vc_data.load[1] = cvirt->load[1];
17275 +       vc_data.load[2] = cvirt->load[2];
17276 +
17277 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17278 +               return -EFAULT;
17279 +       return 0;
17280 +}
17281 +
17282 +
17283 +#ifdef CONFIG_VSERVER_VTIME
17284 +
17285 +/* virtualized time base */
17286 +
17287 +void vx_adjust_timespec(struct timespec *ts)
17288 +{
17289 +       struct vx_info *vxi;
17290 +
17291 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17292 +               return;
17293 +
17294 +       vxi = current_vx_info();
17295 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17296 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17297 +
17298 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17299 +               ts->tv_sec++;
17300 +               ts->tv_nsec -= NSEC_PER_SEC;
17301 +       } else if (ts->tv_nsec < 0) {
17302 +               ts->tv_sec--;
17303 +               ts->tv_nsec += NSEC_PER_SEC;
17304 +       }
17305 +}
17306 +
17307 +int vx_settimeofday(const struct timespec *ts)
17308 +{
17309 +       struct timespec ats, delta;
17310 +       struct vx_info *vxi;
17311 +
17312 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17313 +               return do_settimeofday(ts);
17314 +
17315 +       getnstimeofday(&ats);
17316 +       delta = timespec_sub(*ts, ats);
17317 +
17318 +       vxi = current_vx_info();
17319 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17320 +       return 0;
17321 +}
17322 +
17323 +#endif
17324 +
17325 diff -NurpP --minimal linux-3.4.83/kernel/vserver/cvirt_init.h linux-3.4.83-vs2.3.3.9/kernel/vserver/cvirt_init.h
17326 --- linux-3.4.83/kernel/vserver/cvirt_init.h    1970-01-01 00:00:00.000000000 +0000
17327 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/cvirt_init.h  2012-05-21 16:15:05.000000000 +0000
17328 @@ -0,0 +1,70 @@
17329 +
17330 +
17331 +extern uint64_t vx_idle_jiffies(void);
17332 +
17333 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17334 +{
17335 +       uint64_t idle_jiffies = vx_idle_jiffies();
17336 +       uint64_t nsuptime;
17337 +
17338 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17339 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17340 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17341 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17342 +       cvirt->bias_ts.tv_sec = 0;
17343 +       cvirt->bias_ts.tv_nsec = 0;
17344 +
17345 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17346 +       atomic_set(&cvirt->nr_threads, 0);
17347 +       atomic_set(&cvirt->nr_running, 0);
17348 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17349 +       atomic_set(&cvirt->nr_onhold, 0);
17350 +
17351 +       spin_lock_init(&cvirt->load_lock);
17352 +       cvirt->load_last = jiffies;
17353 +       atomic_set(&cvirt->load_updates, 0);
17354 +       cvirt->load[0] = 0;
17355 +       cvirt->load[1] = 0;
17356 +       cvirt->load[2] = 0;
17357 +       atomic_set(&cvirt->total_forks, 0);
17358 +
17359 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17360 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17361 +       cvirt->syslog.log_start = 0;
17362 +       cvirt->syslog.log_end = 0;
17363 +       cvirt->syslog.con_start = 0;
17364 +       cvirt->syslog.logged_chars = 0;
17365 +}
17366 +
17367 +static inline
17368 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17369 +{
17370 +       // cvirt_pc->cpustat = { 0 };
17371 +}
17372 +
17373 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17374 +{
17375 +#ifdef CONFIG_VSERVER_WARN
17376 +       int value;
17377 +#endif
17378 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17379 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17380 +               cvirt, value);
17381 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17382 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17383 +               cvirt, value);
17384 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17385 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17386 +               cvirt, value);
17387 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17388 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17389 +               cvirt, value);
17390 +       return;
17391 +}
17392 +
17393 +static inline
17394 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17395 +{
17396 +       return;
17397 +}
17398 +
17399 diff -NurpP --minimal linux-3.4.83/kernel/vserver/cvirt_proc.h linux-3.4.83-vs2.3.3.9/kernel/vserver/cvirt_proc.h
17400 --- linux-3.4.83/kernel/vserver/cvirt_proc.h    1970-01-01 00:00:00.000000000 +0000
17401 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/cvirt_proc.h  2013-08-13 17:48:39.000000000 +0000
17402 @@ -0,0 +1,123 @@
17403 +#ifndef _VX_CVIRT_PROC_H
17404 +#define _VX_CVIRT_PROC_H
17405 +
17406 +#include <linux/nsproxy.h>
17407 +#include <linux/mnt_namespace.h>
17408 +#include <linux/ipc_namespace.h>
17409 +#include <linux/utsname.h>
17410 +#include <linux/ipc.h>
17411 +
17412 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17413 +
17414 +static inline
17415 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17416 +{
17417 +       struct mnt_namespace *ns;
17418 +       struct uts_namespace *uts;
17419 +       struct ipc_namespace *ipc;
17420 +       int length = 0;
17421 +
17422 +       if (!nsproxy)
17423 +               goto out;
17424 +
17425 +       length += sprintf(buffer + length,
17426 +               "NSProxy:\t%p [%p,%p,%p]\n",
17427 +               nsproxy, nsproxy->mnt_ns,
17428 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17429 +
17430 +       ns = nsproxy->mnt_ns;
17431 +       if (!ns)
17432 +               goto skip_ns;
17433 +
17434 +       length += vx_info_mnt_namespace(ns, buffer + length);
17435 +
17436 +skip_ns:
17437 +
17438 +       uts = nsproxy->uts_ns;
17439 +       if (!uts)
17440 +               goto skip_uts;
17441 +
17442 +       length += sprintf(buffer + length,
17443 +               "SysName:\t%.*s\n"
17444 +               "NodeName:\t%.*s\n"
17445 +               "Release:\t%.*s\n"
17446 +               "Version:\t%.*s\n"
17447 +               "Machine:\t%.*s\n"
17448 +               "DomainName:\t%.*s\n",
17449 +               __NEW_UTS_LEN, uts->name.sysname,
17450 +               __NEW_UTS_LEN, uts->name.nodename,
17451 +               __NEW_UTS_LEN, uts->name.release,
17452 +               __NEW_UTS_LEN, uts->name.version,
17453 +               __NEW_UTS_LEN, uts->name.machine,
17454 +               __NEW_UTS_LEN, uts->name.domainname);
17455 +skip_uts:
17456 +
17457 +       ipc = nsproxy->ipc_ns;
17458 +       if (!ipc)
17459 +               goto skip_ipc;
17460 +
17461 +       length += sprintf(buffer + length,
17462 +               "SEMS:\t\t%d %d %d %d  %d\n"
17463 +               "MSG:\t\t%d %d %d\n"
17464 +               "SHM:\t\t%lu %lu  %d %ld\n",
17465 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17466 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17467 +               ipc->used_sems,
17468 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17469 +               (unsigned long)ipc->shm_ctlmax,
17470 +               (unsigned long)ipc->shm_ctlall,
17471 +               ipc->shm_ctlmni, ipc->shm_tot);
17472 +skip_ipc:
17473 +out:
17474 +       return length;
17475 +}
17476 +
17477 +
17478 +#include <linux/sched.h>
17479 +
17480 +#define LOAD_INT(x) ((x) >> FSHIFT)
17481 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17482 +
17483 +static inline
17484 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17485 +{
17486 +       int length = 0;
17487 +       int a, b, c;
17488 +
17489 +       length += sprintf(buffer + length,
17490 +               "BiasUptime:\t%lu.%02lu\n",
17491 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17492 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17493 +
17494 +       a = cvirt->load[0] + (FIXED_1 / 200);
17495 +       b = cvirt->load[1] + (FIXED_1 / 200);
17496 +       c = cvirt->load[2] + (FIXED_1 / 200);
17497 +       length += sprintf(buffer + length,
17498 +               "nr_threads:\t%d\n"
17499 +               "nr_running:\t%d\n"
17500 +               "nr_unintr:\t%d\n"
17501 +               "nr_onhold:\t%d\n"
17502 +               "load_updates:\t%d\n"
17503 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17504 +               "total_forks:\t%d\n",
17505 +               atomic_read(&cvirt->nr_threads),
17506 +               atomic_read(&cvirt->nr_running),
17507 +               atomic_read(&cvirt->nr_uninterruptible),
17508 +               atomic_read(&cvirt->nr_onhold),
17509 +               atomic_read(&cvirt->load_updates),
17510 +               LOAD_INT(a), LOAD_FRAC(a),
17511 +               LOAD_INT(b), LOAD_FRAC(b),
17512 +               LOAD_INT(c), LOAD_FRAC(c),
17513 +               atomic_read(&cvirt->total_forks));
17514 +       return length;
17515 +}
17516 +
17517 +static inline
17518 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17519 +       char *buffer, int cpu)
17520 +{
17521 +       int length = 0;
17522 +       return length;
17523 +}
17524 +
17525 +#endif /* _VX_CVIRT_PROC_H */
17526 diff -NurpP --minimal linux-3.4.83/kernel/vserver/debug.c linux-3.4.83-vs2.3.3.9/kernel/vserver/debug.c
17527 --- linux-3.4.83/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
17528 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/debug.c       2012-05-21 16:15:05.000000000 +0000
17529 @@ -0,0 +1,32 @@
17530 +/*
17531 + *  kernel/vserver/debug.c
17532 + *
17533 + *  Copyright (C) 2005-2007 Herbert Pötzl
17534 + *
17535 + *  V0.01  vx_info dump support
17536 + *
17537 + */
17538 +
17539 +#include <linux/module.h>
17540 +
17541 +#include <linux/vserver/context.h>
17542 +
17543 +
17544 +void   dump_vx_info(struct vx_info *vxi, int level)
17545 +{
17546 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17547 +               atomic_read(&vxi->vx_usecnt),
17548 +               atomic_read(&vxi->vx_tasks),
17549 +               vxi->vx_state);
17550 +       if (level > 0) {
17551 +               __dump_vx_limit(&vxi->limit);
17552 +               __dump_vx_sched(&vxi->sched);
17553 +               __dump_vx_cvirt(&vxi->cvirt);
17554 +               __dump_vx_cacct(&vxi->cacct);
17555 +       }
17556 +       printk("---\n");
17557 +}
17558 +
17559 +
17560 +EXPORT_SYMBOL_GPL(dump_vx_info);
17561 +
17562 diff -NurpP --minimal linux-3.4.83/kernel/vserver/device.c linux-3.4.83-vs2.3.3.9/kernel/vserver/device.c
17563 --- linux-3.4.83/kernel/vserver/device.c        1970-01-01 00:00:00.000000000 +0000
17564 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/device.c      2012-05-21 16:15:05.000000000 +0000
17565 @@ -0,0 +1,443 @@
17566 +/*
17567 + *  linux/kernel/vserver/device.c
17568 + *
17569 + *  Linux-VServer: Device Support
17570 + *
17571 + *  Copyright (C) 2006  Herbert Pötzl
17572 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17573 + *
17574 + *  V0.01  device mapping basics
17575 + *  V0.02  added defaults
17576 + *
17577 + */
17578 +
17579 +#include <linux/slab.h>
17580 +#include <linux/rcupdate.h>
17581 +#include <linux/fs.h>
17582 +#include <linux/namei.h>
17583 +#include <linux/hash.h>
17584 +
17585 +#include <asm/errno.h>
17586 +#include <asm/uaccess.h>
17587 +#include <linux/vserver/base.h>
17588 +#include <linux/vserver/debug.h>
17589 +#include <linux/vserver/context.h>
17590 +#include <linux/vserver/device.h>
17591 +#include <linux/vserver/device_cmd.h>
17592 +
17593 +
17594 +#define DMAP_HASH_BITS 4
17595 +
17596 +
17597 +struct vs_mapping {
17598 +       union {
17599 +               struct hlist_node hlist;
17600 +               struct list_head list;
17601 +       } u;
17602 +#define dm_hlist       u.hlist
17603 +#define dm_list                u.list
17604 +       xid_t xid;
17605 +       dev_t device;
17606 +       struct vx_dmap_target target;
17607 +};
17608 +
17609 +
17610 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17611 +
17612 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17613 +
17614 +static struct vx_dmap_target dmap_defaults[2] = {
17615 +       { .flags = DATTR_OPEN },
17616 +       { .flags = DATTR_OPEN },
17617 +};
17618 +
17619 +
17620 +struct kmem_cache *dmap_cachep __read_mostly;
17621 +
17622 +int __init dmap_cache_init(void)
17623 +{
17624 +       dmap_cachep = kmem_cache_create("dmap_cache",
17625 +               sizeof(struct vs_mapping), 0,
17626 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17627 +       return 0;
17628 +}
17629 +
17630 +__initcall(dmap_cache_init);
17631 +
17632 +
17633 +static inline unsigned int __hashval(dev_t dev, int bits)
17634 +{
17635 +       return hash_long((unsigned long)dev, bits);
17636 +}
17637 +
17638 +
17639 +/*     __hash_mapping()
17640 + *     add the mapping to the hash table
17641 + */
17642 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17643 +{
17644 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17645 +       struct hlist_head *head, *hash = dmap_main_hash;
17646 +       int device = vdm->device;
17647 +
17648 +       spin_lock(hash_lock);
17649 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17650 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17651 +
17652 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17653 +       hlist_add_head(&vdm->dm_hlist, head);
17654 +       spin_unlock(hash_lock);
17655 +}
17656 +
17657 +
17658 +static inline int __mode_to_default(umode_t mode)
17659 +{
17660 +       switch (mode) {
17661 +       case S_IFBLK:
17662 +               return 0;
17663 +       case S_IFCHR:
17664 +               return 1;
17665 +       default:
17666 +               BUG();
17667 +       }
17668 +}
17669 +
17670 +
17671 +/*     __set_default()
17672 + *     set a default
17673 + */
17674 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17675 +       struct vx_dmap_target *vdmt)
17676 +{
17677 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17678 +       spin_lock(hash_lock);
17679 +
17680 +       if (vxi)
17681 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17682 +       else
17683 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17684 +
17685 +
17686 +       spin_unlock(hash_lock);
17687 +
17688 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17689 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17690 +}
17691 +
17692 +
17693 +/*     __remove_default()
17694 + *     remove a default
17695 + */
17696 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17697 +{
17698 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17699 +       spin_lock(hash_lock);
17700 +
17701 +       if (vxi)
17702 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17703 +       else    /* remove == reset */
17704 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17705 +
17706 +       spin_unlock(hash_lock);
17707 +       return 0;
17708 +}
17709 +
17710 +
17711 +/*     __find_mapping()
17712 + *     find a mapping in the hash table
17713 + *
17714 + *     caller must hold hash_lock
17715 + */
17716 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17717 +       struct vs_mapping **local, struct vs_mapping **global)
17718 +{
17719 +       struct hlist_head *hash = dmap_main_hash;
17720 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17721 +       struct hlist_node *pos;
17722 +       struct vs_mapping *vdm;
17723 +
17724 +       *local = NULL;
17725 +       if (global)
17726 +               *global = NULL;
17727 +
17728 +       hlist_for_each(pos, head) {
17729 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17730 +
17731 +               if ((vdm->device == device) &&
17732 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17733 +                       if (vdm->xid == xid) {
17734 +                               *local = vdm;
17735 +                               return 1;
17736 +                       } else if (global && vdm->xid == 0)
17737 +                               *global = vdm;
17738 +               }
17739 +       }
17740 +
17741 +       if (global && *global)
17742 +               return 0;
17743 +       else
17744 +               return -ENOENT;
17745 +}
17746 +
17747 +
17748 +/*     __lookup_mapping()
17749 + *     find a mapping and store the result in target and flags
17750 + */
17751 +static inline int __lookup_mapping(struct vx_info *vxi,
17752 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17753 +{
17754 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17755 +       struct vs_mapping *vdm, *global;
17756 +       struct vx_dmap_target *vdmt;
17757 +       int ret = 0;
17758 +       xid_t xid = vxi->vx_id;
17759 +       int index;
17760 +
17761 +       spin_lock(hash_lock);
17762 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17763 +               ret = 1;
17764 +               vdmt = &vdm->target;
17765 +               goto found;
17766 +       }
17767 +
17768 +       index = __mode_to_default(mode);
17769 +       if (vxi && vxi->dmap.targets[index].flags) {
17770 +               ret = 2;
17771 +               vdmt = &vxi->dmap.targets[index];
17772 +       } else if (global) {
17773 +               ret = 3;
17774 +               vdmt = &global->target;
17775 +               goto found;
17776 +       } else {
17777 +               ret = 4;
17778 +               vdmt = &dmap_defaults[index];
17779 +       }
17780 +
17781 +found:
17782 +       if (target && (vdmt->flags & DATTR_REMAP))
17783 +               *target = vdmt->target;
17784 +       else if (target)
17785 +               *target = device;
17786 +       if (flags)
17787 +               *flags = vdmt->flags;
17788 +
17789 +       spin_unlock(hash_lock);
17790 +
17791 +       return ret;
17792 +}
17793 +
17794 +
17795 +/*     __remove_mapping()
17796 + *     remove a mapping from the hash table
17797 + */
17798 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17799 +       umode_t mode)
17800 +{
17801 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17802 +       struct vs_mapping *vdm = NULL;
17803 +       int ret = 0;
17804 +
17805 +       spin_lock(hash_lock);
17806 +
17807 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17808 +               NULL);
17809 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17810 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17811 +       if (ret < 0)
17812 +               goto out;
17813 +       hlist_del(&vdm->dm_hlist);
17814 +
17815 +out:
17816 +       spin_unlock(hash_lock);
17817 +       if (vdm)
17818 +               kmem_cache_free(dmap_cachep, vdm);
17819 +       return ret;
17820 +}
17821 +
17822 +
17823 +
17824 +int vs_map_device(struct vx_info *vxi,
17825 +       dev_t device, dev_t *target, umode_t mode)
17826 +{
17827 +       int ret, flags = DATTR_MASK;
17828 +
17829 +       if (!vxi) {
17830 +               if (target)
17831 +                       *target = device;
17832 +               goto out;
17833 +       }
17834 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17835 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17836 +               device, target ? *target : 0, flags, mode, ret);
17837 +out:
17838 +       return (flags & DATTR_MASK);
17839 +}
17840 +
17841 +
17842 +
17843 +static int do_set_mapping(struct vx_info *vxi,
17844 +       dev_t device, dev_t target, int flags, umode_t mode)
17845 +{
17846 +       if (device) {
17847 +               struct vs_mapping *new;
17848 +
17849 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17850 +               if (!new)
17851 +                       return -ENOMEM;
17852 +
17853 +               INIT_HLIST_NODE(&new->dm_hlist);
17854 +               new->device = device;
17855 +               new->target.target = target;
17856 +               new->target.flags = flags | mode;
17857 +               new->xid = (vxi ? vxi->vx_id : 0);
17858 +
17859 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17860 +               __hash_mapping(vxi, new);
17861 +       } else {
17862 +               struct vx_dmap_target new = {
17863 +                       .target = target,
17864 +                       .flags = flags | mode,
17865 +               };
17866 +               __set_default(vxi, mode, &new);
17867 +       }
17868 +       return 0;
17869 +}
17870 +
17871 +
17872 +static int do_unset_mapping(struct vx_info *vxi,
17873 +       dev_t device, dev_t target, int flags, umode_t mode)
17874 +{
17875 +       int ret = -EINVAL;
17876 +
17877 +       if (device) {
17878 +               ret = __remove_mapping(vxi, device, mode);
17879 +               if (ret < 0)
17880 +                       goto out;
17881 +       } else {
17882 +               ret = __remove_default(vxi, mode);
17883 +               if (ret < 0)
17884 +                       goto out;
17885 +       }
17886 +
17887 +out:
17888 +       return ret;
17889 +}
17890 +
17891 +
17892 +static inline int __user_device(const char __user *name, dev_t *dev,
17893 +       umode_t *mode)
17894 +{
17895 +       struct nameidata nd;
17896 +       int ret;
17897 +
17898 +       if (!name) {
17899 +               *dev = 0;
17900 +               return 0;
17901 +       }
17902 +       ret = user_lpath(name, &nd.path);
17903 +       if (ret)
17904 +               return ret;
17905 +       if (nd.path.dentry->d_inode) {
17906 +               *dev = nd.path.dentry->d_inode->i_rdev;
17907 +               *mode = nd.path.dentry->d_inode->i_mode;
17908 +       }
17909 +       path_put(&nd.path);
17910 +       return 0;
17911 +}
17912 +
17913 +static inline int __mapping_mode(dev_t device, dev_t target,
17914 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17915 +{
17916 +       if (device)
17917 +               *mode = device_mode & S_IFMT;
17918 +       else if (target)
17919 +               *mode = target_mode & S_IFMT;
17920 +       else
17921 +               return -EINVAL;
17922 +
17923 +       /* if both given, device and target mode have to match */
17924 +       if (device && target &&
17925 +               ((device_mode ^ target_mode) & S_IFMT))
17926 +               return -EINVAL;
17927 +       return 0;
17928 +}
17929 +
17930 +
17931 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17932 +       const char __user *target_path, int flags, int set)
17933 +{
17934 +       dev_t device = ~0, target = ~0;
17935 +       umode_t device_mode = 0, target_mode = 0, mode;
17936 +       int ret;
17937 +
17938 +       ret = __user_device(device_path, &device, &device_mode);
17939 +       if (ret)
17940 +               return ret;
17941 +       ret = __user_device(target_path, &target, &target_mode);
17942 +       if (ret)
17943 +               return ret;
17944 +
17945 +       ret = __mapping_mode(device, target,
17946 +               device_mode, target_mode, &mode);
17947 +       if (ret)
17948 +               return ret;
17949 +
17950 +       if (set)
17951 +               return do_set_mapping(vxi, device, target,
17952 +                       flags, mode);
17953 +       else
17954 +               return do_unset_mapping(vxi, device, target,
17955 +                       flags, mode);
17956 +}
17957 +
17958 +
17959 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17960 +{
17961 +       struct vcmd_set_mapping_v0 vc_data;
17962 +
17963 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17964 +               return -EFAULT;
17965 +
17966 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17967 +               vc_data.flags, 1);
17968 +}
17969 +
17970 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17971 +{
17972 +       struct vcmd_set_mapping_v0 vc_data;
17973 +
17974 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17975 +               return -EFAULT;
17976 +
17977 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17978 +               vc_data.flags, 0);
17979 +}
17980 +
17981 +
17982 +#ifdef CONFIG_COMPAT
17983 +
17984 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17985 +{
17986 +       struct vcmd_set_mapping_v0_x32 vc_data;
17987 +
17988 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17989 +               return -EFAULT;
17990 +
17991 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17992 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17993 +}
17994 +
17995 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17996 +{
17997 +       struct vcmd_set_mapping_v0_x32 vc_data;
17998 +
17999 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18000 +               return -EFAULT;
18001 +
18002 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18003 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18004 +}
18005 +
18006 +#endif /* CONFIG_COMPAT */
18007 +
18008 +
18009 diff -NurpP --minimal linux-3.4.83/kernel/vserver/dlimit.c linux-3.4.83-vs2.3.3.9/kernel/vserver/dlimit.c
18010 --- linux-3.4.83/kernel/vserver/dlimit.c        1970-01-01 00:00:00.000000000 +0000
18011 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/dlimit.c      2012-05-21 16:15:05.000000000 +0000
18012 @@ -0,0 +1,531 @@
18013 +/*
18014 + *  linux/kernel/vserver/dlimit.c
18015 + *
18016 + *  Virtual Server: Context Disk Limits
18017 + *
18018 + *  Copyright (C) 2004-2009  Herbert Pötzl
18019 + *
18020 + *  V0.01  initial version
18021 + *  V0.02  compat32 splitup
18022 + *  V0.03  extended interface
18023 + *
18024 + */
18025 +
18026 +#include <linux/statfs.h>
18027 +#include <linux/sched.h>
18028 +#include <linux/namei.h>
18029 +#include <linux/vs_tag.h>
18030 +#include <linux/vs_dlimit.h>
18031 +#include <linux/vserver/dlimit_cmd.h>
18032 +#include <linux/slab.h>
18033 +// #include <linux/gfp.h>
18034 +
18035 +#include <asm/uaccess.h>
18036 +
18037 +/*     __alloc_dl_info()
18038 +
18039 +       * allocate an initialized dl_info struct
18040 +       * doesn't make it visible (hash)                        */
18041 +
18042 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18043 +{
18044 +       struct dl_info *new = NULL;
18045 +
18046 +       vxdprintk(VXD_CBIT(dlim, 5),
18047 +               "alloc_dl_info(%p,%d)*", sb, tag);
18048 +
18049 +       /* would this benefit from a slab cache? */
18050 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18051 +       if (!new)
18052 +               return 0;
18053 +
18054 +       memset(new, 0, sizeof(struct dl_info));
18055 +       new->dl_tag = tag;
18056 +       new->dl_sb = sb;
18057 +       // INIT_RCU_HEAD(&new->dl_rcu);
18058 +       INIT_HLIST_NODE(&new->dl_hlist);
18059 +       spin_lock_init(&new->dl_lock);
18060 +       atomic_set(&new->dl_refcnt, 0);
18061 +       atomic_set(&new->dl_usecnt, 0);
18062 +
18063 +       /* rest of init goes here */
18064 +
18065 +       vxdprintk(VXD_CBIT(dlim, 4),
18066 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18067 +       return new;
18068 +}
18069 +
18070 +/*     __dealloc_dl_info()
18071 +
18072 +       * final disposal of dl_info                             */
18073 +
18074 +static void __dealloc_dl_info(struct dl_info *dli)
18075 +{
18076 +       vxdprintk(VXD_CBIT(dlim, 4),
18077 +               "dealloc_dl_info(%p)", dli);
18078 +
18079 +       dli->dl_hlist.next = LIST_POISON1;
18080 +       dli->dl_tag = -1;
18081 +       dli->dl_sb = 0;
18082 +
18083 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18084 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18085 +
18086 +       kfree(dli);
18087 +}
18088 +
18089 +
18090 +/*     hash table for dl_info hash */
18091 +
18092 +#define DL_HASH_SIZE   13
18093 +
18094 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18095 +
18096 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18097 +
18098 +
18099 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18100 +{
18101 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18102 +}
18103 +
18104 +
18105 +
18106 +/*     __hash_dl_info()
18107 +
18108 +       * add the dli to the global hash table
18109 +       * requires the hash_lock to be held                     */
18110 +
18111 +static inline void __hash_dl_info(struct dl_info *dli)
18112 +{
18113 +       struct hlist_head *head;
18114 +
18115 +       vxdprintk(VXD_CBIT(dlim, 6),
18116 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18117 +       get_dl_info(dli);
18118 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18119 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18120 +}
18121 +
18122 +/*     __unhash_dl_info()
18123 +
18124 +       * remove the dli from the global hash table
18125 +       * requires the hash_lock to be held                     */
18126 +
18127 +static inline void __unhash_dl_info(struct dl_info *dli)
18128 +{
18129 +       vxdprintk(VXD_CBIT(dlim, 6),
18130 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18131 +       hlist_del_rcu(&dli->dl_hlist);
18132 +       put_dl_info(dli);
18133 +}
18134 +
18135 +
18136 +/*     __lookup_dl_info()
18137 +
18138 +       * requires the rcu_read_lock()
18139 +       * doesn't increment the dl_refcnt                       */
18140 +
18141 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18142 +{
18143 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18144 +       struct hlist_node *pos;
18145 +       struct dl_info *dli;
18146 +
18147 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18148 +
18149 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18150 +                       return dli;
18151 +               }
18152 +       }
18153 +       return NULL;
18154 +}
18155 +
18156 +
18157 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18158 +{
18159 +       struct dl_info *dli;
18160 +
18161 +       rcu_read_lock();
18162 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18163 +       vxdprintk(VXD_CBIT(dlim, 7),
18164 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18165 +       rcu_read_unlock();
18166 +       return dli;
18167 +}
18168 +
18169 +void rcu_free_dl_info(struct rcu_head *head)
18170 +{
18171 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18172 +       int usecnt, refcnt;
18173 +
18174 +       BUG_ON(!dli || !head);
18175 +
18176 +       usecnt = atomic_read(&dli->dl_usecnt);
18177 +       BUG_ON(usecnt < 0);
18178 +
18179 +       refcnt = atomic_read(&dli->dl_refcnt);
18180 +       BUG_ON(refcnt < 0);
18181 +
18182 +       vxdprintk(VXD_CBIT(dlim, 3),
18183 +               "rcu_free_dl_info(%p)", dli);
18184 +       if (!usecnt)
18185 +               __dealloc_dl_info(dli);
18186 +       else
18187 +               printk("!!! rcu didn't free\n");
18188 +}
18189 +
18190 +
18191 +
18192 +
18193 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18194 +       uint32_t flags, int add)
18195 +{
18196 +       struct path path;
18197 +       int ret;
18198 +
18199 +       ret = user_lpath(name, &path);
18200 +       if (!ret) {
18201 +               struct super_block *sb;
18202 +               struct dl_info *dli;
18203 +
18204 +               ret = -EINVAL;
18205 +               if (!path.dentry->d_inode)
18206 +                       goto out_release;
18207 +               if (!(sb = path.dentry->d_inode->i_sb))
18208 +                       goto out_release;
18209 +
18210 +               if (add) {
18211 +                       dli = __alloc_dl_info(sb, id);
18212 +                       spin_lock(&dl_info_hash_lock);
18213 +
18214 +                       ret = -EEXIST;
18215 +                       if (__lookup_dl_info(sb, id))
18216 +                               goto out_unlock;
18217 +                       __hash_dl_info(dli);
18218 +                       dli = NULL;
18219 +               } else {
18220 +                       spin_lock(&dl_info_hash_lock);
18221 +                       dli = __lookup_dl_info(sb, id);
18222 +
18223 +                       ret = -ESRCH;
18224 +                       if (!dli)
18225 +                               goto out_unlock;
18226 +                       __unhash_dl_info(dli);
18227 +               }
18228 +               ret = 0;
18229 +       out_unlock:
18230 +               spin_unlock(&dl_info_hash_lock);
18231 +               if (add && dli)
18232 +                       __dealloc_dl_info(dli);
18233 +       out_release:
18234 +               path_put(&path);
18235 +       }
18236 +       return ret;
18237 +}
18238 +
18239 +int vc_add_dlimit(uint32_t id, void __user *data)
18240 +{
18241 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18242 +
18243 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18244 +               return -EFAULT;
18245 +
18246 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18247 +}
18248 +
18249 +int vc_rem_dlimit(uint32_t id, void __user *data)
18250 +{
18251 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18252 +
18253 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18254 +               return -EFAULT;
18255 +
18256 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18257 +}
18258 +
18259 +#ifdef CONFIG_COMPAT
18260 +
18261 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18262 +{
18263 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18264 +
18265 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18266 +               return -EFAULT;
18267 +
18268 +       return do_addrem_dlimit(id,
18269 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18270 +}
18271 +
18272 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18273 +{
18274 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18275 +
18276 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18277 +               return -EFAULT;
18278 +
18279 +       return do_addrem_dlimit(id,
18280 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18281 +}
18282 +
18283 +#endif /* CONFIG_COMPAT */
18284 +
18285 +
18286 +static inline
18287 +int do_set_dlimit(uint32_t id, const char __user *name,
18288 +       uint32_t space_used, uint32_t space_total,
18289 +       uint32_t inodes_used, uint32_t inodes_total,
18290 +       uint32_t reserved, uint32_t flags)
18291 +{
18292 +       struct path path;
18293 +       int ret;
18294 +
18295 +       ret = user_lpath(name, &path);
18296 +       if (!ret) {
18297 +               struct super_block *sb;
18298 +               struct dl_info *dli;
18299 +
18300 +               ret = -EINVAL;
18301 +               if (!path.dentry->d_inode)
18302 +                       goto out_release;
18303 +               if (!(sb = path.dentry->d_inode->i_sb))
18304 +                       goto out_release;
18305 +
18306 +               /* sanity checks */
18307 +               if ((reserved != CDLIM_KEEP &&
18308 +                       reserved > 100) ||
18309 +                       (inodes_used != CDLIM_KEEP &&
18310 +                       inodes_used > inodes_total) ||
18311 +                       (space_used != CDLIM_KEEP &&
18312 +                       space_used > space_total))
18313 +                       goto out_release;
18314 +
18315 +               ret = -ESRCH;
18316 +               dli = locate_dl_info(sb, id);
18317 +               if (!dli)
18318 +                       goto out_release;
18319 +
18320 +               spin_lock(&dli->dl_lock);
18321 +
18322 +               if (inodes_used != CDLIM_KEEP)
18323 +                       dli->dl_inodes_used = inodes_used;
18324 +               if (inodes_total != CDLIM_KEEP)
18325 +                       dli->dl_inodes_total = inodes_total;
18326 +               if (space_used != CDLIM_KEEP)
18327 +                       dli->dl_space_used = dlimit_space_32to64(
18328 +                               space_used, flags, DLIMS_USED);
18329 +
18330 +               if (space_total == CDLIM_INFINITY)
18331 +                       dli->dl_space_total = DLIM_INFINITY;
18332 +               else if (space_total != CDLIM_KEEP)
18333 +                       dli->dl_space_total = dlimit_space_32to64(
18334 +                               space_total, flags, DLIMS_TOTAL);
18335 +
18336 +               if (reserved != CDLIM_KEEP)
18337 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18338 +
18339 +               spin_unlock(&dli->dl_lock);
18340 +
18341 +               put_dl_info(dli);
18342 +               ret = 0;
18343 +
18344 +       out_release:
18345 +               path_put(&path);
18346 +       }
18347 +       return ret;
18348 +}
18349 +
18350 +int vc_set_dlimit(uint32_t id, void __user *data)
18351 +{
18352 +       struct vcmd_ctx_dlimit_v0 vc_data;
18353 +
18354 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18355 +               return -EFAULT;
18356 +
18357 +       return do_set_dlimit(id, vc_data.name,
18358 +               vc_data.space_used, vc_data.space_total,
18359 +               vc_data.inodes_used, vc_data.inodes_total,
18360 +               vc_data.reserved, vc_data.flags);
18361 +}
18362 +
18363 +#ifdef CONFIG_COMPAT
18364 +
18365 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18366 +{
18367 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18368 +
18369 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18370 +               return -EFAULT;
18371 +
18372 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18373 +               vc_data.space_used, vc_data.space_total,
18374 +               vc_data.inodes_used, vc_data.inodes_total,
18375 +               vc_data.reserved, vc_data.flags);
18376 +}
18377 +
18378 +#endif /* CONFIG_COMPAT */
18379 +
18380 +
18381 +static inline
18382 +int do_get_dlimit(uint32_t id, const char __user *name,
18383 +       uint32_t *space_used, uint32_t *space_total,
18384 +       uint32_t *inodes_used, uint32_t *inodes_total,
18385 +       uint32_t *reserved, uint32_t *flags)
18386 +{
18387 +       struct path path;
18388 +       int ret;
18389 +
18390 +       ret = user_lpath(name, &path);
18391 +       if (!ret) {
18392 +               struct super_block *sb;
18393 +               struct dl_info *dli;
18394 +
18395 +               ret = -EINVAL;
18396 +               if (!path.dentry->d_inode)
18397 +                       goto out_release;
18398 +               if (!(sb = path.dentry->d_inode->i_sb))
18399 +                       goto out_release;
18400 +
18401 +               ret = -ESRCH;
18402 +               dli = locate_dl_info(sb, id);
18403 +               if (!dli)
18404 +                       goto out_release;
18405 +
18406 +               spin_lock(&dli->dl_lock);
18407 +               *inodes_used = dli->dl_inodes_used;
18408 +               *inodes_total = dli->dl_inodes_total;
18409 +
18410 +               *space_used = dlimit_space_64to32(
18411 +                       dli->dl_space_used, flags, DLIMS_USED);
18412 +
18413 +               if (dli->dl_space_total == DLIM_INFINITY)
18414 +                       *space_total = CDLIM_INFINITY;
18415 +               else
18416 +                       *space_total = dlimit_space_64to32(
18417 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18418 +
18419 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18420 +               spin_unlock(&dli->dl_lock);
18421 +
18422 +               put_dl_info(dli);
18423 +               ret = -EFAULT;
18424 +
18425 +               ret = 0;
18426 +       out_release:
18427 +               path_put(&path);
18428 +       }
18429 +       return ret;
18430 +}
18431 +
18432 +
18433 +int vc_get_dlimit(uint32_t id, void __user *data)
18434 +{
18435 +       struct vcmd_ctx_dlimit_v0 vc_data;
18436 +       int ret;
18437 +
18438 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18439 +               return -EFAULT;
18440 +
18441 +       ret = do_get_dlimit(id, vc_data.name,
18442 +               &vc_data.space_used, &vc_data.space_total,
18443 +               &vc_data.inodes_used, &vc_data.inodes_total,
18444 +               &vc_data.reserved, &vc_data.flags);
18445 +       if (ret)
18446 +               return ret;
18447 +
18448 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18449 +               return -EFAULT;
18450 +       return 0;
18451 +}
18452 +
18453 +#ifdef CONFIG_COMPAT
18454 +
18455 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18456 +{
18457 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18458 +       int ret;
18459 +
18460 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18461 +               return -EFAULT;
18462 +
18463 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18464 +               &vc_data.space_used, &vc_data.space_total,
18465 +               &vc_data.inodes_used, &vc_data.inodes_total,
18466 +               &vc_data.reserved, &vc_data.flags);
18467 +       if (ret)
18468 +               return ret;
18469 +
18470 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18471 +               return -EFAULT;
18472 +       return 0;
18473 +}
18474 +
18475 +#endif /* CONFIG_COMPAT */
18476 +
18477 +
18478 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18479 +{
18480 +       struct dl_info *dli;
18481 +       __u64 blimit, bfree, bavail;
18482 +       __u32 ifree;
18483 +
18484 +       dli = locate_dl_info(sb, dx_current_tag());
18485 +       if (!dli)
18486 +               return;
18487 +
18488 +       spin_lock(&dli->dl_lock);
18489 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18490 +               goto no_ilim;
18491 +
18492 +       /* reduce max inodes available to limit */
18493 +       if (buf->f_files > dli->dl_inodes_total)
18494 +               buf->f_files = dli->dl_inodes_total;
18495 +
18496 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18497 +       /* reduce free inodes to min */
18498 +       if (ifree < buf->f_ffree)
18499 +               buf->f_ffree = ifree;
18500 +
18501 +no_ilim:
18502 +       if (dli->dl_space_total == DLIM_INFINITY)
18503 +               goto no_blim;
18504 +
18505 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18506 +
18507 +       if (dli->dl_space_total < dli->dl_space_used)
18508 +               bfree = 0;
18509 +       else
18510 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18511 +                       >> sb->s_blocksize_bits;
18512 +
18513 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18514 +       if (bavail < dli->dl_space_used)
18515 +               bavail = 0;
18516 +       else
18517 +               bavail = (bavail - dli->dl_space_used)
18518 +                       >> sb->s_blocksize_bits;
18519 +
18520 +       /* reduce max space available to limit */
18521 +       if (buf->f_blocks > blimit)
18522 +               buf->f_blocks = blimit;
18523 +
18524 +       /* reduce free space to min */
18525 +       if (bfree < buf->f_bfree)
18526 +               buf->f_bfree = bfree;
18527 +
18528 +       /* reduce avail space to min */
18529 +       if (bavail < buf->f_bavail)
18530 +               buf->f_bavail = bavail;
18531 +
18532 +no_blim:
18533 +       spin_unlock(&dli->dl_lock);
18534 +       put_dl_info(dli);
18535 +
18536 +       return;
18537 +}
18538 +
18539 +#include <linux/module.h>
18540 +
18541 +EXPORT_SYMBOL_GPL(locate_dl_info);
18542 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18543 +
18544 diff -NurpP --minimal linux-3.4.83/kernel/vserver/helper.c linux-3.4.83-vs2.3.3.9/kernel/vserver/helper.c
18545 --- linux-3.4.83/kernel/vserver/helper.c        1970-01-01 00:00:00.000000000 +0000
18546 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/helper.c      2012-09-16 18:49:44.000000000 +0000
18547 @@ -0,0 +1,229 @@
18548 +/*
18549 + *  linux/kernel/vserver/helper.c
18550 + *
18551 + *  Virtual Context Support
18552 + *
18553 + *  Copyright (C) 2004-2007  Herbert Pötzl
18554 + *
18555 + *  V0.01  basic helper
18556 + *
18557 + */
18558 +
18559 +#include <linux/kmod.h>
18560 +#include <linux/reboot.h>
18561 +#include <linux/vs_context.h>
18562 +#include <linux/vs_network.h>
18563 +#include <linux/vserver/signal.h>
18564 +
18565 +
18566 +char vshelper_path[255] = "/sbin/vshelper";
18567 +
18568 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18569 +{
18570 +       current->flags &= ~PF_THREAD_BOUND;
18571 +       return 0;
18572 +}
18573 +
18574 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18575 +{
18576 +       int ret;
18577 +
18578 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18579 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18580 +               vshelper_init, NULL, NULL))) {
18581 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18582 +                       name, argv[1], argv[2],
18583 +                       sync ? "sync" : "async", ret);
18584 +       }
18585 +       vxdprintk(VXD_CBIT(switch, 4),
18586 +               "%s: (%s %s) returned %s with %d",
18587 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18588 +       return ret;
18589 +}
18590 +
18591 +/*
18592 + *      vshelper path is set via /proc/sys
18593 + *      invoked by vserver sys_reboot(), with
18594 + *      the following arguments
18595 + *
18596 + *      argv [0] = vshelper_path;
18597 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18598 + *      argv [2] = context identifier
18599 + *
18600 + *      envp [*] = type-specific parameters
18601 + */
18602 +
18603 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18604 +{
18605 +       char id_buf[8], cmd_buf[16];
18606 +       char uid_buf[16], pid_buf[16];
18607 +       int ret;
18608 +
18609 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18610 +       char *envp[] = {"HOME=/", "TERM=linux",
18611 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18612 +                       uid_buf, pid_buf, cmd_buf, 0};
18613 +
18614 +       if (vx_info_state(vxi, VXS_HELPER))
18615 +               return -EAGAIN;
18616 +       vxi->vx_state |= VXS_HELPER;
18617 +
18618 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18619 +
18620 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18621 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18622 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18623 +
18624 +       switch (cmd) {
18625 +       case LINUX_REBOOT_CMD_RESTART:
18626 +               argv[1] = "restart";
18627 +               break;
18628 +
18629 +       case LINUX_REBOOT_CMD_HALT:
18630 +               argv[1] = "halt";
18631 +               break;
18632 +
18633 +       case LINUX_REBOOT_CMD_POWER_OFF:
18634 +               argv[1] = "poweroff";
18635 +               break;
18636 +
18637 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18638 +               argv[1] = "swsusp";
18639 +               break;
18640 +
18641 +       case LINUX_REBOOT_CMD_OOM:
18642 +               argv[1] = "oom";
18643 +               break;
18644 +
18645 +       default:
18646 +               vxi->vx_state &= ~VXS_HELPER;
18647 +               return 0;
18648 +       }
18649 +
18650 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18651 +       vxi->vx_state &= ~VXS_HELPER;
18652 +       __wakeup_vx_info(vxi);
18653 +       return (ret) ? -EPERM : 0;
18654 +}
18655 +
18656 +
18657 +long vs_reboot(unsigned int cmd, void __user *arg)
18658 +{
18659 +       struct vx_info *vxi = current_vx_info();
18660 +       long ret = 0;
18661 +
18662 +       vxdprintk(VXD_CBIT(misc, 5),
18663 +               "vs_reboot(%p[#%d],%u)",
18664 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18665 +
18666 +       ret = vs_reboot_helper(vxi, cmd, arg);
18667 +       if (ret)
18668 +               return ret;
18669 +
18670 +       vxi->reboot_cmd = cmd;
18671 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18672 +               switch (cmd) {
18673 +               case LINUX_REBOOT_CMD_RESTART:
18674 +               case LINUX_REBOOT_CMD_HALT:
18675 +               case LINUX_REBOOT_CMD_POWER_OFF:
18676 +                       vx_info_kill(vxi, 0, SIGKILL);
18677 +                       vx_info_kill(vxi, 1, SIGKILL);
18678 +               default:
18679 +                       break;
18680 +               }
18681 +       }
18682 +       return 0;
18683 +}
18684 +
18685 +long vs_oom_action(unsigned int cmd)
18686 +{
18687 +       struct vx_info *vxi = current_vx_info();
18688 +       long ret = 0;
18689 +
18690 +       vxdprintk(VXD_CBIT(misc, 5),
18691 +               "vs_oom_action(%p[#%d],%u)",
18692 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18693 +
18694 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18695 +       if (ret)
18696 +               return ret;
18697 +
18698 +       vxi->reboot_cmd = cmd;
18699 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18700 +               vx_info_kill(vxi, 0, SIGKILL);
18701 +               vx_info_kill(vxi, 1, SIGKILL);
18702 +       }
18703 +       return 0;
18704 +}
18705 +
18706 +/*
18707 + *      argv [0] = vshelper_path;
18708 + *      argv [1] = action: "startup", "shutdown"
18709 + *      argv [2] = context identifier
18710 + *
18711 + *      envp [*] = type-specific parameters
18712 + */
18713 +
18714 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18715 +{
18716 +       char id_buf[8], cmd_buf[16];
18717 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18718 +       char *envp[] = {"HOME=/", "TERM=linux",
18719 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18720 +
18721 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18722 +               return 0;
18723 +
18724 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18725 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18726 +
18727 +       switch (cmd) {
18728 +       case VSC_STARTUP:
18729 +               argv[1] = "startup";
18730 +               break;
18731 +       case VSC_SHUTDOWN:
18732 +               argv[1] = "shutdown";
18733 +               break;
18734 +       default:
18735 +               return 0;
18736 +       }
18737 +
18738 +       return do_vshelper(vshelper_path, argv, envp, 1);
18739 +}
18740 +
18741 +
18742 +/*
18743 + *      argv [0] = vshelper_path;
18744 + *      argv [1] = action: "netup", "netdown"
18745 + *      argv [2] = context identifier
18746 + *
18747 + *      envp [*] = type-specific parameters
18748 + */
18749 +
18750 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18751 +{
18752 +       char id_buf[8], cmd_buf[16];
18753 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18754 +       char *envp[] = {"HOME=/", "TERM=linux",
18755 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18756 +
18757 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18758 +               return 0;
18759 +
18760 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18761 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18762 +
18763 +       switch (cmd) {
18764 +       case VSC_NETUP:
18765 +               argv[1] = "netup";
18766 +               break;
18767 +       case VSC_NETDOWN:
18768 +               argv[1] = "netdown";
18769 +               break;
18770 +       default:
18771 +               return 0;
18772 +       }
18773 +
18774 +       return do_vshelper(vshelper_path, argv, envp, 1);
18775 +}
18776 +
18777 diff -NurpP --minimal linux-3.4.83/kernel/vserver/history.c linux-3.4.83-vs2.3.3.9/kernel/vserver/history.c
18778 --- linux-3.4.83/kernel/vserver/history.c       1970-01-01 00:00:00.000000000 +0000
18779 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/history.c     2012-05-21 16:15:05.000000000 +0000
18780 @@ -0,0 +1,258 @@
18781 +/*
18782 + *  kernel/vserver/history.c
18783 + *
18784 + *  Virtual Context History Backtrace
18785 + *
18786 + *  Copyright (C) 2004-2007  Herbert Pötzl
18787 + *
18788 + *  V0.01  basic structure
18789 + *  V0.02  hash/unhash and trace
18790 + *  V0.03  preemption fixes
18791 + *
18792 + */
18793 +
18794 +#include <linux/module.h>
18795 +#include <asm/uaccess.h>
18796 +
18797 +#include <linux/vserver/context.h>
18798 +#include <linux/vserver/debug.h>
18799 +#include <linux/vserver/debug_cmd.h>
18800 +#include <linux/vserver/history.h>
18801 +
18802 +
18803 +#ifdef CONFIG_VSERVER_HISTORY
18804 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18805 +#else
18806 +#define VXH_SIZE       64
18807 +#endif
18808 +
18809 +struct _vx_history {
18810 +       unsigned int counter;
18811 +
18812 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18813 +};
18814 +
18815 +
18816 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18817 +
18818 +unsigned volatile int vxh_active = 1;
18819 +
18820 +static atomic_t sequence = ATOMIC_INIT(0);
18821 +
18822 +
18823 +/*     vxh_advance()
18824 +
18825 +       * requires disabled preemption                          */
18826 +
18827 +struct _vx_hist_entry *vxh_advance(void *loc)
18828 +{
18829 +       unsigned int cpu = smp_processor_id();
18830 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18831 +       struct _vx_hist_entry *entry;
18832 +       unsigned int index;
18833 +
18834 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18835 +       entry = &hist->entry[index];
18836 +
18837 +       entry->seq = atomic_inc_return(&sequence);
18838 +       entry->loc = loc;
18839 +       return entry;
18840 +}
18841 +
18842 +EXPORT_SYMBOL_GPL(vxh_advance);
18843 +
18844 +
18845 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18846 +
18847 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18848 +
18849 +
18850 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18851 +
18852 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18853 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18854 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18855 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18856 +
18857 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18858 +{
18859 +       switch (e->type) {
18860 +       case VXH_THROW_OOPS:
18861 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18862 +               break;
18863 +
18864 +       case VXH_GET_VX_INFO:
18865 +       case VXH_PUT_VX_INFO:
18866 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18867 +                       VXH_LOC_ARGS(e),
18868 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18869 +                       VXH_VXI_ARGS(e));
18870 +               break;
18871 +
18872 +       case VXH_INIT_VX_INFO:
18873 +       case VXH_SET_VX_INFO:
18874 +       case VXH_CLR_VX_INFO:
18875 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18876 +                       VXH_LOC_ARGS(e),
18877 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18878 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18879 +                       VXH_VXI_ARGS(e), e->sc.data);
18880 +               break;
18881 +
18882 +       case VXH_CLAIM_VX_INFO:
18883 +       case VXH_RELEASE_VX_INFO:
18884 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18885 +                       VXH_LOC_ARGS(e),
18886 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18887 +                       VXH_VXI_ARGS(e), e->sc.data);
18888 +               break;
18889 +
18890 +       case VXH_ALLOC_VX_INFO:
18891 +       case VXH_DEALLOC_VX_INFO:
18892 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18893 +                       VXH_LOC_ARGS(e),
18894 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18895 +                       VXH_VXI_ARGS(e));
18896 +               break;
18897 +
18898 +       case VXH_HASH_VX_INFO:
18899 +       case VXH_UNHASH_VX_INFO:
18900 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18901 +                       VXH_LOC_ARGS(e),
18902 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18903 +                       VXH_VXI_ARGS(e));
18904 +               break;
18905 +
18906 +       case VXH_LOC_VX_INFO:
18907 +       case VXH_LOOKUP_VX_INFO:
18908 +       case VXH_CREATE_VX_INFO:
18909 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18910 +                       VXH_LOC_ARGS(e),
18911 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18912 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18913 +                       e->ll.arg, VXH_VXI_ARGS(e));
18914 +               break;
18915 +       }
18916 +}
18917 +
18918 +static void __vxh_dump_history(void)
18919 +{
18920 +       unsigned int i, cpu;
18921 +
18922 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18923 +               atomic_read(&sequence), NR_CPUS);
18924 +
18925 +       for (i = 0; i < VXH_SIZE; i++) {
18926 +               for_each_online_cpu(cpu) {
18927 +                       struct _vx_history *hist =
18928 +                               &per_cpu(vx_history_buffer, cpu);
18929 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18930 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18931 +
18932 +                       vxh_dump_entry(entry, cpu);
18933 +               }
18934 +       }
18935 +}
18936 +
18937 +void   vxh_dump_history(void)
18938 +{
18939 +       vxh_active = 0;
18940 +#ifdef CONFIG_SMP
18941 +       local_irq_enable();
18942 +       smp_send_stop();
18943 +       local_irq_disable();
18944 +#endif
18945 +       __vxh_dump_history();
18946 +}
18947 +
18948 +
18949 +/* vserver syscall commands below here */
18950 +
18951 +
18952 +int vc_dump_history(uint32_t id)
18953 +{
18954 +       vxh_active = 0;
18955 +       __vxh_dump_history();
18956 +       vxh_active = 1;
18957 +
18958 +       return 0;
18959 +}
18960 +
18961 +
18962 +int do_read_history(struct __user _vx_hist_entry *data,
18963 +       int cpu, uint32_t *index, uint32_t *count)
18964 +{
18965 +       int pos, ret = 0;
18966 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18967 +       int end = hist->counter;
18968 +       int start = end - VXH_SIZE + 2;
18969 +       int idx = *index;
18970 +
18971 +       /* special case: get current pos */
18972 +       if (!*count) {
18973 +               *index = end;
18974 +               return 0;
18975 +       }
18976 +
18977 +       /* have we lost some data? */
18978 +       if (idx < start)
18979 +               idx = start;
18980 +
18981 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18982 +               struct _vx_hist_entry *entry =
18983 +                       &hist->entry[idx % VXH_SIZE];
18984 +
18985 +               /* send entry to userspace */
18986 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18987 +               if (ret)
18988 +                       break;
18989 +       }
18990 +       /* save new index and count */
18991 +       *index = idx;
18992 +       *count = pos;
18993 +       return ret ? ret : (*index < end);
18994 +}
18995 +
18996 +int vc_read_history(uint32_t id, void __user *data)
18997 +{
18998 +       struct vcmd_read_history_v0 vc_data;
18999 +       int ret;
19000 +
19001 +       if (id >= NR_CPUS)
19002 +               return -EINVAL;
19003 +
19004 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19005 +               return -EFAULT;
19006 +
19007 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19008 +               id, &vc_data.index, &vc_data.count);
19009 +
19010 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19011 +               return -EFAULT;
19012 +       return ret;
19013 +}
19014 +
19015 +#ifdef CONFIG_COMPAT
19016 +
19017 +int vc_read_history_x32(uint32_t id, void __user *data)
19018 +{
19019 +       struct vcmd_read_history_v0_x32 vc_data;
19020 +       int ret;
19021 +
19022 +       if (id >= NR_CPUS)
19023 +               return -EINVAL;
19024 +
19025 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19026 +               return -EFAULT;
19027 +
19028 +       ret = do_read_history((struct __user _vx_hist_entry *)
19029 +               compat_ptr(vc_data.data_ptr),
19030 +               id, &vc_data.index, &vc_data.count);
19031 +
19032 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19033 +               return -EFAULT;
19034 +       return ret;
19035 +}
19036 +
19037 +#endif /* CONFIG_COMPAT */
19038 +
19039 diff -NurpP --minimal linux-3.4.83/kernel/vserver/inet.c linux-3.4.83-vs2.3.3.9/kernel/vserver/inet.c
19040 --- linux-3.4.83/kernel/vserver/inet.c  1970-01-01 00:00:00.000000000 +0000
19041 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/inet.c        2012-05-21 16:15:05.000000000 +0000
19042 @@ -0,0 +1,226 @@
19043 +
19044 +#include <linux/in.h>
19045 +#include <linux/inetdevice.h>
19046 +#include <linux/export.h>
19047 +#include <linux/vs_inet.h>
19048 +#include <linux/vs_inet6.h>
19049 +#include <linux/vserver/debug.h>
19050 +#include <net/route.h>
19051 +#include <net/addrconf.h>
19052 +
19053 +
19054 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19055 +{
19056 +       int ret = 0;
19057 +
19058 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19059 +               ret = 1;
19060 +       else {
19061 +               struct nx_addr_v4 *ptr;
19062 +
19063 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19064 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19065 +                               ret = 1;
19066 +                               break;
19067 +                       }
19068 +               }
19069 +       }
19070 +
19071 +       vxdprintk(VXD_CBIT(net, 2),
19072 +               "nx_v4_addr_conflict(%p,%p): %d",
19073 +               nxi1, nxi2, ret);
19074 +
19075 +       return ret;
19076 +}
19077 +
19078 +
19079 +#ifdef CONFIG_IPV6
19080 +
19081 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19082 +{
19083 +       int ret = 0;
19084 +
19085 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19086 +               ret = 1;
19087 +       else {
19088 +               struct nx_addr_v6 *ptr;
19089 +
19090 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19091 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19092 +                               ret = 1;
19093 +                               break;
19094 +                       }
19095 +               }
19096 +       }
19097 +
19098 +       vxdprintk(VXD_CBIT(net, 2),
19099 +               "nx_v6_addr_conflict(%p,%p): %d",
19100 +               nxi1, nxi2, ret);
19101 +
19102 +       return ret;
19103 +}
19104 +
19105 +#endif
19106 +
19107 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19108 +{
19109 +       struct in_device *in_dev;
19110 +       struct in_ifaddr **ifap;
19111 +       struct in_ifaddr *ifa;
19112 +       int ret = 0;
19113 +
19114 +       if (!dev)
19115 +               goto out;
19116 +       in_dev = in_dev_get(dev);
19117 +       if (!in_dev)
19118 +               goto out;
19119 +
19120 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19121 +               ifap = &ifa->ifa_next) {
19122 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19123 +                       ret = 1;
19124 +                       break;
19125 +               }
19126 +       }
19127 +       in_dev_put(in_dev);
19128 +out:
19129 +       return ret;
19130 +}
19131 +
19132 +
19133 +#ifdef CONFIG_IPV6
19134 +
19135 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19136 +{
19137 +       struct inet6_dev *in_dev;
19138 +       struct inet6_ifaddr *ifa;
19139 +       int ret = 0;
19140 +
19141 +       if (!dev)
19142 +               goto out;
19143 +       in_dev = in6_dev_get(dev);
19144 +       if (!in_dev)
19145 +               goto out;
19146 +
19147 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19148 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19149 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19150 +                       ret = 1;
19151 +                       break;
19152 +               }
19153 +       }
19154 +       in6_dev_put(in_dev);
19155 +out:
19156 +       return ret;
19157 +}
19158 +
19159 +#endif
19160 +
19161 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19162 +{
19163 +       int ret = 1;
19164 +
19165 +       if (!nxi)
19166 +               goto out;
19167 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19168 +               goto out;
19169 +#ifdef CONFIG_IPV6
19170 +       ret = 2;
19171 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19172 +               goto out;
19173 +#endif
19174 +       ret = 0;
19175 +out:
19176 +       vxdprintk(VXD_CBIT(net, 3),
19177 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19178 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19179 +       return ret;
19180 +}
19181 +
19182 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19183 +       struct flowi4 *fl4)
19184 +{
19185 +       struct rtable *rt;
19186 +
19187 +       if (!nxi)
19188 +               return NULL;
19189 +
19190 +       /* FIXME: handle lback only case */
19191 +       if (!NX_IPV4(nxi))
19192 +               return ERR_PTR(-EPERM);
19193 +
19194 +       vxdprintk(VXD_CBIT(net, 4),
19195 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19196 +               nxi, nxi ? nxi->nx_id : 0,
19197 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19198 +
19199 +       /* single IP is unconditional */
19200 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19201 +               (fl4->saddr == INADDR_ANY))
19202 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19203 +
19204 +       if (fl4->saddr == INADDR_ANY) {
19205 +               struct nx_addr_v4 *ptr;
19206 +               __be32 found = 0;
19207 +
19208 +               rt = __ip_route_output_key(net, fl4);
19209 +               if (!IS_ERR(rt)) {
19210 +                       found = fl4->saddr;
19211 +                       ip_rt_put(rt);
19212 +                       vxdprintk(VXD_CBIT(net, 4),
19213 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19214 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19215 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19216 +                               goto found;
19217 +               }
19218 +
19219 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19220 +                       __be32 primary = ptr->ip[0].s_addr;
19221 +                       __be32 mask = ptr->mask.s_addr;
19222 +                       __be32 neta = primary & mask;
19223 +
19224 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19225 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19226 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19227 +                               NIPQUAD(mask), NIPQUAD(neta));
19228 +                       if ((found & mask) != neta)
19229 +                               continue;
19230 +
19231 +                       fl4->saddr = primary;
19232 +                       rt = __ip_route_output_key(net, fl4);
19233 +                       vxdprintk(VXD_CBIT(net, 4),
19234 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19235 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19236 +                       if (!IS_ERR(rt)) {
19237 +                               found = fl4->saddr;
19238 +                               ip_rt_put(rt);
19239 +                               if (found == primary)
19240 +                                       goto found;
19241 +                       }
19242 +               }
19243 +               /* still no source ip? */
19244 +               found = ipv4_is_loopback(fl4->daddr)
19245 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19246 +       found:
19247 +               /* assign src ip to flow */
19248 +               fl4->saddr = found;
19249 +
19250 +       } else {
19251 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19252 +                       return ERR_PTR(-EPERM);
19253 +       }
19254 +
19255 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19256 +               if (ipv4_is_loopback(fl4->daddr))
19257 +                       fl4->daddr = nxi->v4_lback.s_addr;
19258 +               if (ipv4_is_loopback(fl4->saddr))
19259 +                       fl4->saddr = nxi->v4_lback.s_addr;
19260 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19261 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19262 +               return ERR_PTR(-EPERM);
19263 +
19264 +       return NULL;
19265 +}
19266 +
19267 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19268 +
19269 diff -NurpP --minimal linux-3.4.83/kernel/vserver/init.c linux-3.4.83-vs2.3.3.9/kernel/vserver/init.c
19270 --- linux-3.4.83/kernel/vserver/init.c  1970-01-01 00:00:00.000000000 +0000
19271 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/init.c        2012-05-21 16:15:05.000000000 +0000
19272 @@ -0,0 +1,45 @@
19273 +/*
19274 + *  linux/kernel/init.c
19275 + *
19276 + *  Virtual Server Init
19277 + *
19278 + *  Copyright (C) 2004-2007  Herbert Pötzl
19279 + *
19280 + *  V0.01  basic structure
19281 + *
19282 + */
19283 +
19284 +#include <linux/init.h>
19285 +
19286 +int    vserver_register_sysctl(void);
19287 +void   vserver_unregister_sysctl(void);
19288 +
19289 +
19290 +static int __init init_vserver(void)
19291 +{
19292 +       int ret = 0;
19293 +
19294 +#ifdef CONFIG_VSERVER_DEBUG
19295 +       vserver_register_sysctl();
19296 +#endif
19297 +       return ret;
19298 +}
19299 +
19300 +
19301 +static void __exit exit_vserver(void)
19302 +{
19303 +
19304 +#ifdef CONFIG_VSERVER_DEBUG
19305 +       vserver_unregister_sysctl();
19306 +#endif
19307 +       return;
19308 +}
19309 +
19310 +/* FIXME: GFP_ZONETYPES gone
19311 +long vx_slab[GFP_ZONETYPES]; */
19312 +long vx_area;
19313 +
19314 +
19315 +module_init(init_vserver);
19316 +module_exit(exit_vserver);
19317 +
19318 diff -NurpP --minimal linux-3.4.83/kernel/vserver/inode.c linux-3.4.83-vs2.3.3.9/kernel/vserver/inode.c
19319 --- linux-3.4.83/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
19320 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/inode.c       2012-05-21 16:15:05.000000000 +0000
19321 @@ -0,0 +1,437 @@
19322 +/*
19323 + *  linux/kernel/vserver/inode.c
19324 + *
19325 + *  Virtual Server: File System Support
19326 + *
19327 + *  Copyright (C) 2004-2007  Herbert Pötzl
19328 + *
19329 + *  V0.01  separated from vcontext V0.05
19330 + *  V0.02  moved to tag (instead of xid)
19331 + *
19332 + */
19333 +
19334 +#include <linux/tty.h>
19335 +#include <linux/proc_fs.h>
19336 +#include <linux/devpts_fs.h>
19337 +#include <linux/fs.h>
19338 +#include <linux/file.h>
19339 +#include <linux/mount.h>
19340 +#include <linux/parser.h>
19341 +#include <linux/namei.h>
19342 +#include <linux/vserver/inode.h>
19343 +#include <linux/vserver/inode_cmd.h>
19344 +#include <linux/vs_base.h>
19345 +#include <linux/vs_tag.h>
19346 +
19347 +#include <asm/uaccess.h>
19348 +
19349 +
19350 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19351 +{
19352 +       struct proc_dir_entry *entry;
19353 +
19354 +       if (!in || !in->i_sb)
19355 +               return -ESRCH;
19356 +
19357 +       *flags = IATTR_TAG
19358 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19359 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19360 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19361 +               | (IS_COW(in) ? IATTR_COW : 0);
19362 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19363 +
19364 +       if (S_ISDIR(in->i_mode))
19365 +               *mask |= IATTR_BARRIER;
19366 +
19367 +       if (IS_TAGGED(in)) {
19368 +               *tag = in->i_tag;
19369 +               *mask |= IATTR_TAG;
19370 +       }
19371 +
19372 +       switch (in->i_sb->s_magic) {
19373 +       case PROC_SUPER_MAGIC:
19374 +               entry = PROC_I(in)->pde;
19375 +
19376 +               /* check for specific inodes? */
19377 +               if (entry)
19378 +                       *mask |= IATTR_FLAGS;
19379 +               if (entry)
19380 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19381 +               else
19382 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19383 +               break;
19384 +
19385 +       case DEVPTS_SUPER_MAGIC:
19386 +               *tag = in->i_tag;
19387 +               *mask |= IATTR_TAG;
19388 +               break;
19389 +
19390 +       default:
19391 +               break;
19392 +       }
19393 +       return 0;
19394 +}
19395 +
19396 +int vc_get_iattr(void __user *data)
19397 +{
19398 +       struct path path;
19399 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19400 +       int ret;
19401 +
19402 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19403 +               return -EFAULT;
19404 +
19405 +       ret = user_lpath(vc_data.name, &path);
19406 +       if (!ret) {
19407 +               ret = __vc_get_iattr(path.dentry->d_inode,
19408 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19409 +               path_put(&path);
19410 +       }
19411 +       if (ret)
19412 +               return ret;
19413 +
19414 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19415 +               ret = -EFAULT;
19416 +       return ret;
19417 +}
19418 +
19419 +#ifdef CONFIG_COMPAT
19420 +
19421 +int vc_get_iattr_x32(void __user *data)
19422 +{
19423 +       struct path path;
19424 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19425 +       int ret;
19426 +
19427 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19428 +               return -EFAULT;
19429 +
19430 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19431 +       if (!ret) {
19432 +               ret = __vc_get_iattr(path.dentry->d_inode,
19433 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19434 +               path_put(&path);
19435 +       }
19436 +       if (ret)
19437 +               return ret;
19438 +
19439 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19440 +               ret = -EFAULT;
19441 +       return ret;
19442 +}
19443 +
19444 +#endif /* CONFIG_COMPAT */
19445 +
19446 +
19447 +int vc_fget_iattr(uint32_t fd, void __user *data)
19448 +{
19449 +       struct file *filp;
19450 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19451 +       int ret;
19452 +
19453 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19454 +               return -EFAULT;
19455 +
19456 +       filp = fget(fd);
19457 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19458 +               return -EBADF;
19459 +
19460 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19461 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19462 +
19463 +       fput(filp);
19464 +
19465 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19466 +               ret = -EFAULT;
19467 +       return ret;
19468 +}
19469 +
19470 +
19471 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19472 +{
19473 +       struct inode *in = de->d_inode;
19474 +       int error = 0, is_proc = 0, has_tag = 0;
19475 +       struct iattr attr = { 0 };
19476 +
19477 +       if (!in || !in->i_sb)
19478 +               return -ESRCH;
19479 +
19480 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19481 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19482 +               return -EINVAL;
19483 +
19484 +       has_tag = IS_TAGGED(in) ||
19485 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19486 +       if ((*mask & IATTR_TAG) && !has_tag)
19487 +               return -EINVAL;
19488 +
19489 +       mutex_lock(&in->i_mutex);
19490 +       if (*mask & IATTR_TAG) {
19491 +               attr.ia_tag = *tag;
19492 +               attr.ia_valid |= ATTR_TAG;
19493 +       }
19494 +
19495 +       if (*mask & IATTR_FLAGS) {
19496 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19497 +               unsigned int iflags = PROC_I(in)->vx_flags;
19498 +
19499 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19500 +                       | (*flags & IATTR_FLAGS);
19501 +               PROC_I(in)->vx_flags = iflags;
19502 +               if (entry)
19503 +                       entry->vx_flags = iflags;
19504 +       }
19505 +
19506 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19507 +               IATTR_BARRIER | IATTR_COW)) {
19508 +               int iflags = in->i_flags;
19509 +               int vflags = in->i_vflags;
19510 +
19511 +               if (*mask & IATTR_IMMUTABLE) {
19512 +                       if (*flags & IATTR_IMMUTABLE)
19513 +                               iflags |= S_IMMUTABLE;
19514 +                       else
19515 +                               iflags &= ~S_IMMUTABLE;
19516 +               }
19517 +               if (*mask & IATTR_IXUNLINK) {
19518 +                       if (*flags & IATTR_IXUNLINK)
19519 +                               iflags |= S_IXUNLINK;
19520 +                       else
19521 +                               iflags &= ~S_IXUNLINK;
19522 +               }
19523 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19524 +                       if (*flags & IATTR_BARRIER)
19525 +                               vflags |= V_BARRIER;
19526 +                       else
19527 +                               vflags &= ~V_BARRIER;
19528 +               }
19529 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19530 +                       if (*flags & IATTR_COW)
19531 +                               vflags |= V_COW;
19532 +                       else
19533 +                               vflags &= ~V_COW;
19534 +               }
19535 +               if (in->i_op && in->i_op->sync_flags) {
19536 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19537 +                       if (error)
19538 +                               goto out;
19539 +               }
19540 +       }
19541 +
19542 +       if (attr.ia_valid) {
19543 +               if (in->i_op && in->i_op->setattr)
19544 +                       error = in->i_op->setattr(de, &attr);
19545 +               else {
19546 +                       error = inode_change_ok(in, &attr);
19547 +                       if (!error) {
19548 +                               setattr_copy(in, &attr);
19549 +                               mark_inode_dirty(in);
19550 +                       }
19551 +               }
19552 +       }
19553 +
19554 +out:
19555 +       mutex_unlock(&in->i_mutex);
19556 +       return error;
19557 +}
19558 +
19559 +int vc_set_iattr(void __user *data)
19560 +{
19561 +       struct path path;
19562 +       struct vcmd_ctx_iattr_v1 vc_data;
19563 +       int ret;
19564 +
19565 +       if (!capable(CAP_LINUX_IMMUTABLE))
19566 +               return -EPERM;
19567 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19568 +               return -EFAULT;
19569 +
19570 +       ret = user_lpath(vc_data.name, &path);
19571 +       if (!ret) {
19572 +               ret = __vc_set_iattr(path.dentry,
19573 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19574 +               path_put(&path);
19575 +       }
19576 +
19577 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19578 +               ret = -EFAULT;
19579 +       return ret;
19580 +}
19581 +
19582 +#ifdef CONFIG_COMPAT
19583 +
19584 +int vc_set_iattr_x32(void __user *data)
19585 +{
19586 +       struct path path;
19587 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19588 +       int ret;
19589 +
19590 +       if (!capable(CAP_LINUX_IMMUTABLE))
19591 +               return -EPERM;
19592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19593 +               return -EFAULT;
19594 +
19595 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19596 +       if (!ret) {
19597 +               ret = __vc_set_iattr(path.dentry,
19598 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19599 +               path_put(&path);
19600 +       }
19601 +
19602 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19603 +               ret = -EFAULT;
19604 +       return ret;
19605 +}
19606 +
19607 +#endif /* CONFIG_COMPAT */
19608 +
19609 +int vc_fset_iattr(uint32_t fd, void __user *data)
19610 +{
19611 +       struct file *filp;
19612 +       struct vcmd_ctx_fiattr_v0 vc_data;
19613 +       int ret;
19614 +
19615 +       if (!capable(CAP_LINUX_IMMUTABLE))
19616 +               return -EPERM;
19617 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19618 +               return -EFAULT;
19619 +
19620 +       filp = fget(fd);
19621 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19622 +               return -EBADF;
19623 +
19624 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19625 +               &vc_data.flags, &vc_data.mask);
19626 +
19627 +       fput(filp);
19628 +
19629 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19630 +               return -EFAULT;
19631 +       return ret;
19632 +}
19633 +
19634 +
19635 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19636 +
19637 +static match_table_t tokens = {
19638 +       {Opt_notagcheck, "notagcheck"},
19639 +#ifdef CONFIG_PROPAGATE
19640 +       {Opt_notag, "notag"},
19641 +       {Opt_tag, "tag"},
19642 +       {Opt_tagid, "tagid=%u"},
19643 +#endif
19644 +       {Opt_err, NULL}
19645 +};
19646 +
19647 +
19648 +static void __dx_parse_remove(char *string, char *opt)
19649 +{
19650 +       char *p = strstr(string, opt);
19651 +       char *q = p;
19652 +
19653 +       if (p) {
19654 +               while (*q != '\0' && *q != ',')
19655 +                       q++;
19656 +               while (*q)
19657 +                       *p++ = *q++;
19658 +               while (*p)
19659 +                       *p++ = '\0';
19660 +       }
19661 +}
19662 +
19663 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19664 +                unsigned long *flags)
19665 +{
19666 +       int set = 0;
19667 +       substring_t args[MAX_OPT_ARGS];
19668 +       int token;
19669 +       char *s, *p, *opts;
19670 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19671 +       int option = 0;
19672 +#endif
19673 +
19674 +       if (!string)
19675 +               return 0;
19676 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19677 +       if (!s)
19678 +               return 0;
19679 +
19680 +       opts = s;
19681 +       while ((p = strsep(&opts, ",")) != NULL) {
19682 +               token = match_token(p, tokens, args);
19683 +
19684 +               switch (token) {
19685 +#ifdef CONFIG_PROPAGATE
19686 +               case Opt_tag:
19687 +                       if (tag)
19688 +                               *tag = 0;
19689 +                       if (remove)
19690 +                               __dx_parse_remove(s, "tag");
19691 +                       *mnt_flags |= MNT_TAGID;
19692 +                       set |= MNT_TAGID;
19693 +                       break;
19694 +               case Opt_notag:
19695 +                       if (remove)
19696 +                               __dx_parse_remove(s, "notag");
19697 +                       *mnt_flags |= MNT_NOTAG;
19698 +                       set |= MNT_NOTAG;
19699 +                       break;
19700 +               case Opt_tagid:
19701 +                       if (tag && !match_int(args, &option))
19702 +                               *tag = option;
19703 +                       if (remove)
19704 +                               __dx_parse_remove(s, "tagid");
19705 +                       *mnt_flags |= MNT_TAGID;
19706 +                       set |= MNT_TAGID;
19707 +                       break;
19708 +#endif /* CONFIG_PROPAGATE */
19709 +               case Opt_notagcheck:
19710 +                       if (remove)
19711 +                               __dx_parse_remove(s, "notagcheck");
19712 +                       *flags |= MS_NOTAGCHECK;
19713 +                       set |= MS_NOTAGCHECK;
19714 +                       break;
19715 +               }
19716 +               vxdprintk(VXD_CBIT(tag, 7),
19717 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19718 +                       p, token, option);
19719 +       }
19720 +       if (set)
19721 +               strcpy(string, s);
19722 +       kfree(s);
19723 +       return set;
19724 +}
19725 +
19726 +#ifdef CONFIG_PROPAGATE
19727 +
19728 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19729 +{
19730 +       tag_t new_tag = 0;
19731 +       struct vfsmount *mnt;
19732 +       int propagate;
19733 +
19734 +       if (!nd)
19735 +               return;
19736 +       mnt = nd->path.mnt;
19737 +       if (!mnt)
19738 +               return;
19739 +
19740 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19741 +       if (propagate)
19742 +               new_tag = mnt->mnt_tag;
19743 +
19744 +       vxdprintk(VXD_CBIT(tag, 7),
19745 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19746 +               inode, inode->i_ino, inode->i_tag,
19747 +               new_tag, (propagate) ? 1 : 0);
19748 +
19749 +       if (propagate)
19750 +               inode->i_tag = new_tag;
19751 +}
19752 +
19753 +#include <linux/module.h>
19754 +
19755 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19756 +
19757 +#endif /* CONFIG_PROPAGATE */
19758 +
19759 diff -NurpP --minimal linux-3.4.83/kernel/vserver/limit.c linux-3.4.83-vs2.3.3.9/kernel/vserver/limit.c
19760 --- linux-3.4.83/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
19761 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/limit.c       2012-09-01 09:15:21.000000000 +0000
19762 @@ -0,0 +1,345 @@
19763 +/*
19764 + *  linux/kernel/vserver/limit.c
19765 + *
19766 + *  Virtual Server: Context Limits
19767 + *
19768 + *  Copyright (C) 2004-2010  Herbert Pötzl
19769 + *
19770 + *  V0.01  broken out from vcontext V0.05
19771 + *  V0.02  changed vcmds to vxi arg
19772 + *  V0.03  added memory cgroup support
19773 + *
19774 + */
19775 +
19776 +#include <linux/sched.h>
19777 +#include <linux/module.h>
19778 +#include <linux/memcontrol.h>
19779 +#include <linux/res_counter.h>
19780 +#include <linux/vs_limit.h>
19781 +#include <linux/vserver/limit.h>
19782 +#include <linux/vserver/limit_cmd.h>
19783 +
19784 +#include <asm/uaccess.h>
19785 +
19786 +
19787 +const char *vlimit_name[NUM_LIMITS] = {
19788 +       [RLIMIT_CPU]            = "CPU",
19789 +       [RLIMIT_NPROC]          = "NPROC",
19790 +       [RLIMIT_NOFILE]         = "NOFILE",
19791 +       [RLIMIT_LOCKS]          = "LOCKS",
19792 +       [RLIMIT_SIGPENDING]     = "SIGP",
19793 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19794 +
19795 +       [VLIMIT_NSOCK]          = "NSOCK",
19796 +       [VLIMIT_OPENFD]         = "OPENFD",
19797 +       [VLIMIT_SHMEM]          = "SHMEM",
19798 +       [VLIMIT_DENTRY]         = "DENTRY",
19799 +};
19800 +
19801 +EXPORT_SYMBOL_GPL(vlimit_name);
19802 +
19803 +#define MASK_ENTRY(x)  (1 << (x))
19804 +
19805 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19806 +               /* minimum */
19807 +       0
19808 +       ,       /* softlimit */
19809 +       0
19810 +       ,       /* maximum */
19811 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19812 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19813 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19814 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19815 +
19816 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19817 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19818 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19819 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19820 +       0
19821 +};
19822 +               /* accounting only */
19823 +uint32_t account_mask =
19824 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19825 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19826 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19827 +       0;
19828 +
19829 +
19830 +static int is_valid_vlimit(int id)
19831 +{
19832 +       uint32_t mask = vlimit_mask.minimum |
19833 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19834 +       return mask & (1 << id);
19835 +}
19836 +
19837 +static int is_accounted_vlimit(int id)
19838 +{
19839 +       if (is_valid_vlimit(id))
19840 +               return 1;
19841 +       return account_mask & (1 << id);
19842 +}
19843 +
19844 +
19845 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19846 +{
19847 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19848 +       return VX_VLIM(limit);
19849 +}
19850 +
19851 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19852 +{
19853 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19854 +       return VX_VLIM(limit);
19855 +}
19856 +
19857 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19858 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19859 +{
19860 +       if (!is_valid_vlimit(id))
19861 +               return -EINVAL;
19862 +
19863 +       if (minimum)
19864 +               *minimum = CRLIM_UNSET;
19865 +       if (softlimit)
19866 +               *softlimit = vc_get_soft(vxi, id);
19867 +       if (maximum)
19868 +               *maximum = vc_get_hard(vxi, id);
19869 +       return 0;
19870 +}
19871 +
19872 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19873 +{
19874 +       struct vcmd_ctx_rlimit_v0 vc_data;
19875 +       int ret;
19876 +
19877 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19878 +               return -EFAULT;
19879 +
19880 +       ret = do_get_rlimit(vxi, vc_data.id,
19881 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19882 +       if (ret)
19883 +               return ret;
19884 +
19885 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19886 +               return -EFAULT;
19887 +       return 0;
19888 +}
19889 +
19890 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19891 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19892 +{
19893 +       if (!is_valid_vlimit(id))
19894 +               return -EINVAL;
19895 +
19896 +       if (maximum != CRLIM_KEEP)
19897 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19898 +       if (softlimit != CRLIM_KEEP)
19899 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19900 +
19901 +       /* clamp soft limit */
19902 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19903 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19904 +
19905 +       return 0;
19906 +}
19907 +
19908 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19909 +{
19910 +       struct vcmd_ctx_rlimit_v0 vc_data;
19911 +
19912 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19913 +               return -EFAULT;
19914 +
19915 +       return do_set_rlimit(vxi, vc_data.id,
19916 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19917 +}
19918 +
19919 +#ifdef CONFIG_IA32_EMULATION
19920 +
19921 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19922 +{
19923 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19924 +
19925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19926 +               return -EFAULT;
19927 +
19928 +       return do_set_rlimit(vxi, vc_data.id,
19929 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19930 +}
19931 +
19932 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19933 +{
19934 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19935 +       int ret;
19936 +
19937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19938 +               return -EFAULT;
19939 +
19940 +       ret = do_get_rlimit(vxi, vc_data.id,
19941 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19942 +       if (ret)
19943 +               return ret;
19944 +
19945 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19946 +               return -EFAULT;
19947 +       return 0;
19948 +}
19949 +
19950 +#endif /* CONFIG_IA32_EMULATION */
19951 +
19952 +
19953 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19954 +{
19955 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19956 +               return -EFAULT;
19957 +       return 0;
19958 +}
19959 +
19960 +
19961 +static inline void vx_reset_hits(struct _vx_limit *limit)
19962 +{
19963 +       int lim;
19964 +
19965 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19966 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19967 +       }
19968 +}
19969 +
19970 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19971 +{
19972 +       vx_reset_hits(&vxi->limit);
19973 +       return 0;
19974 +}
19975 +
19976 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19977 +{
19978 +       rlim_t value;
19979 +       int lim;
19980 +
19981 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19982 +               value = __rlim_get(limit, lim);
19983 +               __rlim_rmax(limit, lim) = value;
19984 +               __rlim_rmin(limit, lim) = value;
19985 +       }
19986 +}
19987 +
19988 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19989 +{
19990 +       vx_reset_minmax(&vxi->limit);
19991 +       return 0;
19992 +}
19993 +
19994 +
19995 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19996 +{
19997 +       struct vcmd_rlimit_stat_v0 vc_data;
19998 +       struct _vx_limit *limit = &vxi->limit;
19999 +       int id;
20000 +
20001 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20002 +               return -EFAULT;
20003 +
20004 +       id = vc_data.id;
20005 +       if (!is_accounted_vlimit(id))
20006 +               return -EINVAL;
20007 +
20008 +       vx_limit_fixup(limit, id);
20009 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20010 +       vc_data.value = __rlim_get(limit, id);
20011 +       vc_data.minimum = __rlim_rmin(limit, id);
20012 +       vc_data.maximum = __rlim_rmax(limit, id);
20013 +
20014 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20015 +               return -EFAULT;
20016 +       return 0;
20017 +}
20018 +
20019 +
20020 +void vx_vsi_meminfo(struct sysinfo *val)
20021 +{
20022 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20023 +       struct mem_cgroup *mcg;
20024 +       u64 res_limit, res_usage;
20025 +
20026 +       rcu_read_lock();
20027 +       mcg = mem_cgroup_from_task(current);
20028 +       if (!mcg)
20029 +               goto out;
20030 +
20031 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20032 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20033 +
20034 +       if (res_limit != RESOURCE_MAX)
20035 +               val->totalram = (res_limit >> PAGE_SHIFT);
20036 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20037 +       val->bufferram = 0;
20038 +       val->totalhigh = 0;
20039 +       val->freehigh = 0;
20040 +out:
20041 +       rcu_read_unlock();
20042 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20043 +       return;
20044 +}
20045 +
20046 +void vx_vsi_swapinfo(struct sysinfo *val)
20047 +{
20048 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20049 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20050 +       struct mem_cgroup *mcg;
20051 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20052 +       s64 swap_limit, swap_usage;
20053 +
20054 +       rcu_read_lock();
20055 +       mcg = mem_cgroup_from_task(current);
20056 +       if (!mcg)
20057 +               goto out;
20058 +
20059 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20060 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20061 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20062 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20063 +
20064 +       /* memory unlimited */
20065 +       if (res_limit == RESOURCE_MAX)
20066 +               goto out;
20067 +
20068 +       swap_limit = memsw_limit - res_limit;
20069 +       /* we have a swap limit? */
20070 +       if (memsw_limit != RESOURCE_MAX)
20071 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20072 +
20073 +       /* calculate swap part */
20074 +       swap_usage = (memsw_usage > res_usage) ?
20075 +               memsw_usage - res_usage : 0;
20076 +
20077 +       /* total shown minus usage gives free swap */
20078 +       val->freeswap = (swap_usage < swap_limit) ?
20079 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20080 +out:
20081 +       rcu_read_unlock();
20082 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20083 +       val->totalswap = 0;
20084 +       val->freeswap = 0;
20085 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20086 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20087 +       return;
20088 +}
20089 +
20090 +long vx_vsi_cached(struct sysinfo *val)
20091 +{
20092 +       long cache = 0;
20093 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20094 +       struct mem_cgroup *mcg;
20095 +
20096 +       rcu_read_lock();
20097 +       mcg = mem_cgroup_from_task(current);
20098 +       if (!mcg)
20099 +               goto out;
20100 +
20101 +       cache = mem_cgroup_stat_read_cache(mcg);
20102 +out:
20103 +       rcu_read_unlock();
20104 +#endif
20105 +       return cache;
20106 +}
20107 +
20108 diff -NurpP --minimal linux-3.4.83/kernel/vserver/limit_init.h linux-3.4.83-vs2.3.3.9/kernel/vserver/limit_init.h
20109 --- linux-3.4.83/kernel/vserver/limit_init.h    1970-01-01 00:00:00.000000000 +0000
20110 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/limit_init.h  2012-05-21 16:15:05.000000000 +0000
20111 @@ -0,0 +1,31 @@
20112 +
20113 +
20114 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20115 +{
20116 +       int lim;
20117 +
20118 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20119 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20120 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20121 +               __rlim_set(limit, lim, 0);
20122 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20123 +               __rlim_rmin(limit, lim) = 0;
20124 +               __rlim_rmax(limit, lim) = 0;
20125 +       }
20126 +}
20127 +
20128 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20129 +{
20130 +       rlim_t value;
20131 +       int lim;
20132 +
20133 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20134 +               if ((1 << lim) & VLIM_NOCHECK)
20135 +                       continue;
20136 +               value = __rlim_get(limit, lim);
20137 +               vxwprintk_xid(value,
20138 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20139 +                       limit, vlimit_name[lim], lim, (long)value);
20140 +       }
20141 +}
20142 +
20143 diff -NurpP --minimal linux-3.4.83/kernel/vserver/limit_proc.h linux-3.4.83-vs2.3.3.9/kernel/vserver/limit_proc.h
20144 --- linux-3.4.83/kernel/vserver/limit_proc.h    1970-01-01 00:00:00.000000000 +0000
20145 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/limit_proc.h  2012-05-21 16:15:05.000000000 +0000
20146 @@ -0,0 +1,57 @@
20147 +#ifndef _VX_LIMIT_PROC_H
20148 +#define _VX_LIMIT_PROC_H
20149 +
20150 +#include <linux/vserver/limit_int.h>
20151 +
20152 +
20153 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20154 +#define VX_LIMIT_TOP   \
20155 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20156 +
20157 +#define VX_LIMIT_ARG(r)                                \
20158 +       (unsigned long)__rlim_get(limit, r),    \
20159 +       (unsigned long)__rlim_rmin(limit, r),   \
20160 +       (unsigned long)__rlim_rmax(limit, r),   \
20161 +       VX_VLIM(__rlim_soft(limit, r)),         \
20162 +       VX_VLIM(__rlim_hard(limit, r)),         \
20163 +       atomic_read(&__rlim_lhit(limit, r))
20164 +
20165 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20166 +{
20167 +       vx_limit_fixup(limit, -1);
20168 +       return sprintf(buffer, VX_LIMIT_TOP
20169 +               "PROC"  VX_LIMIT_FMT
20170 +               "VM"    VX_LIMIT_FMT
20171 +               "VML"   VX_LIMIT_FMT
20172 +               "RSS"   VX_LIMIT_FMT
20173 +               "ANON"  VX_LIMIT_FMT
20174 +               "RMAP"  VX_LIMIT_FMT
20175 +               "FILES" VX_LIMIT_FMT
20176 +               "OFD"   VX_LIMIT_FMT
20177 +               "LOCKS" VX_LIMIT_FMT
20178 +               "SOCK"  VX_LIMIT_FMT
20179 +               "MSGQ"  VX_LIMIT_FMT
20180 +               "SHM"   VX_LIMIT_FMT
20181 +               "SEMA"  VX_LIMIT_FMT
20182 +               "SEMS"  VX_LIMIT_FMT
20183 +               "DENT"  VX_LIMIT_FMT,
20184 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20185 +               VX_LIMIT_ARG(RLIMIT_AS),
20186 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20187 +               VX_LIMIT_ARG(RLIMIT_RSS),
20188 +               VX_LIMIT_ARG(VLIMIT_ANON),
20189 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20190 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20191 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20192 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20193 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20194 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20195 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20196 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20197 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20198 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20199 +}
20200 +
20201 +#endif /* _VX_LIMIT_PROC_H */
20202 +
20203 +
20204 diff -NurpP --minimal linux-3.4.83/kernel/vserver/network.c linux-3.4.83-vs2.3.3.9/kernel/vserver/network.c
20205 --- linux-3.4.83/kernel/vserver/network.c       1970-01-01 00:00:00.000000000 +0000
20206 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/network.c     2012-05-21 16:15:05.000000000 +0000
20207 @@ -0,0 +1,912 @@
20208 +/*
20209 + *  linux/kernel/vserver/network.c
20210 + *
20211 + *  Virtual Server: Network Support
20212 + *
20213 + *  Copyright (C) 2003-2007  Herbert Pötzl
20214 + *
20215 + *  V0.01  broken out from vcontext V0.05
20216 + *  V0.02  cleaned up implementation
20217 + *  V0.03  added equiv nx commands
20218 + *  V0.04  switch to RCU based hash
20219 + *  V0.05  and back to locking again
20220 + *  V0.06  changed vcmds to nxi arg
20221 + *  V0.07  have __create claim() the nxi
20222 + *
20223 + */
20224 +
20225 +#include <linux/err.h>
20226 +#include <linux/slab.h>
20227 +#include <linux/rcupdate.h>
20228 +
20229 +#include <linux/vs_network.h>
20230 +#include <linux/vs_pid.h>
20231 +#include <linux/vserver/network_cmd.h>
20232 +
20233 +
20234 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20235 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20236 +
20237 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20238 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20239 +
20240 +
20241 +static int __init init_network(void)
20242 +{
20243 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20244 +               sizeof(struct nx_addr_v4), 0,
20245 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20246 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20247 +               sizeof(struct nx_addr_v6), 0,
20248 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20249 +       return 0;
20250 +}
20251 +
20252 +
20253 +/*     __alloc_nx_addr_v4()                                    */
20254 +
20255 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20256 +{
20257 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20258 +               nx_addr_v4_cachep, GFP_KERNEL);
20259 +
20260 +       if (!IS_ERR(nxa))
20261 +               memset(nxa, 0, sizeof(*nxa));
20262 +       return nxa;
20263 +}
20264 +
20265 +/*     __dealloc_nx_addr_v4()                                  */
20266 +
20267 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20268 +{
20269 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20270 +}
20271 +
20272 +/*     __dealloc_nx_addr_v4_all()                              */
20273 +
20274 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20275 +{
20276 +       while (nxa) {
20277 +               struct nx_addr_v4 *next = nxa->next;
20278 +
20279 +               __dealloc_nx_addr_v4(nxa);
20280 +               nxa = next;
20281 +       }
20282 +}
20283 +
20284 +
20285 +#ifdef CONFIG_IPV6
20286 +
20287 +/*     __alloc_nx_addr_v6()                                    */
20288 +
20289 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20290 +{
20291 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20292 +               nx_addr_v6_cachep, GFP_KERNEL);
20293 +
20294 +       if (!IS_ERR(nxa))
20295 +               memset(nxa, 0, sizeof(*nxa));
20296 +       return nxa;
20297 +}
20298 +
20299 +/*     __dealloc_nx_addr_v6()                                  */
20300 +
20301 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20302 +{
20303 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20304 +}
20305 +
20306 +/*     __dealloc_nx_addr_v6_all()                              */
20307 +
20308 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20309 +{
20310 +       while (nxa) {
20311 +               struct nx_addr_v6 *next = nxa->next;
20312 +
20313 +               __dealloc_nx_addr_v6(nxa);
20314 +               nxa = next;
20315 +       }
20316 +}
20317 +
20318 +#endif /* CONFIG_IPV6 */
20319 +
20320 +/*     __alloc_nx_info()
20321 +
20322 +       * allocate an initialized nx_info struct
20323 +       * doesn't make it visible (hash)                        */
20324 +
20325 +static struct nx_info *__alloc_nx_info(nid_t nid)
20326 +{
20327 +       struct nx_info *new = NULL;
20328 +
20329 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20330 +
20331 +       /* would this benefit from a slab cache? */
20332 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20333 +       if (!new)
20334 +               return 0;
20335 +
20336 +       memset(new, 0, sizeof(struct nx_info));
20337 +       new->nx_id = nid;
20338 +       INIT_HLIST_NODE(&new->nx_hlist);
20339 +       atomic_set(&new->nx_usecnt, 0);
20340 +       atomic_set(&new->nx_tasks, 0);
20341 +       new->nx_state = 0;
20342 +
20343 +       new->nx_flags = NXF_INIT_SET;
20344 +
20345 +       /* rest of init goes here */
20346 +
20347 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20348 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20349 +
20350 +       vxdprintk(VXD_CBIT(nid, 0),
20351 +               "alloc_nx_info(%d) = %p", nid, new);
20352 +       atomic_inc(&nx_global_ctotal);
20353 +       return new;
20354 +}
20355 +
20356 +/*     __dealloc_nx_info()
20357 +
20358 +       * final disposal of nx_info                             */
20359 +
20360 +static void __dealloc_nx_info(struct nx_info *nxi)
20361 +{
20362 +       vxdprintk(VXD_CBIT(nid, 0),
20363 +               "dealloc_nx_info(%p)", nxi);
20364 +
20365 +       nxi->nx_hlist.next = LIST_POISON1;
20366 +       nxi->nx_id = -1;
20367 +
20368 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20369 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20370 +
20371 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20372 +
20373 +       nxi->nx_state |= NXS_RELEASED;
20374 +       kfree(nxi);
20375 +       atomic_dec(&nx_global_ctotal);
20376 +}
20377 +
20378 +static void __shutdown_nx_info(struct nx_info *nxi)
20379 +{
20380 +       nxi->nx_state |= NXS_SHUTDOWN;
20381 +       vs_net_change(nxi, VSC_NETDOWN);
20382 +}
20383 +
20384 +/*     exported stuff                                          */
20385 +
20386 +void free_nx_info(struct nx_info *nxi)
20387 +{
20388 +       /* context shutdown is mandatory */
20389 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20390 +
20391 +       /* context must not be hashed */
20392 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20393 +
20394 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20395 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20396 +
20397 +       __dealloc_nx_info(nxi);
20398 +}
20399 +
20400 +
20401 +void __nx_set_lback(struct nx_info *nxi)
20402 +{
20403 +       int nid = nxi->nx_id;
20404 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20405 +
20406 +       nxi->v4_lback.s_addr = lback;
20407 +}
20408 +
20409 +extern int __nx_inet_add_lback(__be32 addr);
20410 +extern int __nx_inet_del_lback(__be32 addr);
20411 +
20412 +
20413 +/*     hash table for nx_info hash */
20414 +
20415 +#define NX_HASH_SIZE   13
20416 +
20417 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20418 +
20419 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20420 +
20421 +
20422 +static inline unsigned int __hashval(nid_t nid)
20423 +{
20424 +       return (nid % NX_HASH_SIZE);
20425 +}
20426 +
20427 +
20428 +
20429 +/*     __hash_nx_info()
20430 +
20431 +       * add the nxi to the global hash table
20432 +       * requires the hash_lock to be held                     */
20433 +
20434 +static inline void __hash_nx_info(struct nx_info *nxi)
20435 +{
20436 +       struct hlist_head *head;
20437 +
20438 +       vxd_assert_lock(&nx_info_hash_lock);
20439 +       vxdprintk(VXD_CBIT(nid, 4),
20440 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20441 +
20442 +       /* context must not be hashed */
20443 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20444 +
20445 +       nxi->nx_state |= NXS_HASHED;
20446 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20447 +       hlist_add_head(&nxi->nx_hlist, head);
20448 +       atomic_inc(&nx_global_cactive);
20449 +}
20450 +
20451 +/*     __unhash_nx_info()
20452 +
20453 +       * remove the nxi from the global hash table
20454 +       * requires the hash_lock to be held                     */
20455 +
20456 +static inline void __unhash_nx_info(struct nx_info *nxi)
20457 +{
20458 +       vxd_assert_lock(&nx_info_hash_lock);
20459 +       vxdprintk(VXD_CBIT(nid, 4),
20460 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20461 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20462 +
20463 +       /* context must be hashed */
20464 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20465 +       /* but without tasks */
20466 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20467 +
20468 +       nxi->nx_state &= ~NXS_HASHED;
20469 +       hlist_del(&nxi->nx_hlist);
20470 +       atomic_dec(&nx_global_cactive);
20471 +}
20472 +
20473 +
20474 +/*     __lookup_nx_info()
20475 +
20476 +       * requires the hash_lock to be held
20477 +       * doesn't increment the nx_refcnt                       */
20478 +
20479 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20480 +{
20481 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20482 +       struct hlist_node *pos;
20483 +       struct nx_info *nxi;
20484 +
20485 +       vxd_assert_lock(&nx_info_hash_lock);
20486 +       hlist_for_each(pos, head) {
20487 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20488 +
20489 +               if (nxi->nx_id == nid)
20490 +                       goto found;
20491 +       }
20492 +       nxi = NULL;
20493 +found:
20494 +       vxdprintk(VXD_CBIT(nid, 0),
20495 +               "__lookup_nx_info(#%u): %p[#%u]",
20496 +               nid, nxi, nxi ? nxi->nx_id : 0);
20497 +       return nxi;
20498 +}
20499 +
20500 +
20501 +/*     __create_nx_info()
20502 +
20503 +       * create the requested context
20504 +       * get(), claim() and hash it                            */
20505 +
20506 +static struct nx_info *__create_nx_info(int id)
20507 +{
20508 +       struct nx_info *new, *nxi = NULL;
20509 +
20510 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20511 +
20512 +       if (!(new = __alloc_nx_info(id)))
20513 +               return ERR_PTR(-ENOMEM);
20514 +
20515 +       /* required to make dynamic xids unique */
20516 +       spin_lock(&nx_info_hash_lock);
20517 +
20518 +       /* static context requested */
20519 +       if ((nxi = __lookup_nx_info(id))) {
20520 +               vxdprintk(VXD_CBIT(nid, 0),
20521 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20522 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20523 +                       nxi = ERR_PTR(-EBUSY);
20524 +               else
20525 +                       nxi = ERR_PTR(-EEXIST);
20526 +               goto out_unlock;
20527 +       }
20528 +       /* new context */
20529 +       vxdprintk(VXD_CBIT(nid, 0),
20530 +               "create_nx_info(%d) = %p (new)", id, new);
20531 +       claim_nx_info(new, NULL);
20532 +       __nx_set_lback(new);
20533 +       __hash_nx_info(get_nx_info(new));
20534 +       nxi = new, new = NULL;
20535 +
20536 +out_unlock:
20537 +       spin_unlock(&nx_info_hash_lock);
20538 +       if (new)
20539 +               __dealloc_nx_info(new);
20540 +       return nxi;
20541 +}
20542 +
20543 +
20544 +
20545 +/*     exported stuff                                          */
20546 +
20547 +
20548 +void unhash_nx_info(struct nx_info *nxi)
20549 +{
20550 +       __shutdown_nx_info(nxi);
20551 +       spin_lock(&nx_info_hash_lock);
20552 +       __unhash_nx_info(nxi);
20553 +       spin_unlock(&nx_info_hash_lock);
20554 +}
20555 +
20556 +/*     lookup_nx_info()
20557 +
20558 +       * search for a nx_info and get() it
20559 +       * negative id means current                             */
20560 +
20561 +struct nx_info *lookup_nx_info(int id)
20562 +{
20563 +       struct nx_info *nxi = NULL;
20564 +
20565 +       if (id < 0) {
20566 +               nxi = get_nx_info(current_nx_info());
20567 +       } else if (id > 1) {
20568 +               spin_lock(&nx_info_hash_lock);
20569 +               nxi = get_nx_info(__lookup_nx_info(id));
20570 +               spin_unlock(&nx_info_hash_lock);
20571 +       }
20572 +       return nxi;
20573 +}
20574 +
20575 +/*     nid_is_hashed()
20576 +
20577 +       * verify that nid is still hashed                       */
20578 +
20579 +int nid_is_hashed(nid_t nid)
20580 +{
20581 +       int hashed;
20582 +
20583 +       spin_lock(&nx_info_hash_lock);
20584 +       hashed = (__lookup_nx_info(nid) != NULL);
20585 +       spin_unlock(&nx_info_hash_lock);
20586 +       return hashed;
20587 +}
20588 +
20589 +
20590 +#ifdef CONFIG_PROC_FS
20591 +
20592 +/*     get_nid_list()
20593 +
20594 +       * get a subset of hashed nids for proc
20595 +       * assumes size is at least one                          */
20596 +
20597 +int get_nid_list(int index, unsigned int *nids, int size)
20598 +{
20599 +       int hindex, nr_nids = 0;
20600 +
20601 +       /* only show current and children */
20602 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20603 +               if (index > 0)
20604 +                       return 0;
20605 +               nids[nr_nids] = nx_current_nid();
20606 +               return 1;
20607 +       }
20608 +
20609 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20610 +               struct hlist_head *head = &nx_info_hash[hindex];
20611 +               struct hlist_node *pos;
20612 +
20613 +               spin_lock(&nx_info_hash_lock);
20614 +               hlist_for_each(pos, head) {
20615 +                       struct nx_info *nxi;
20616 +
20617 +                       if (--index > 0)
20618 +                               continue;
20619 +
20620 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20621 +                       nids[nr_nids] = nxi->nx_id;
20622 +                       if (++nr_nids >= size) {
20623 +                               spin_unlock(&nx_info_hash_lock);
20624 +                               goto out;
20625 +                       }
20626 +               }
20627 +               /* keep the lock time short */
20628 +               spin_unlock(&nx_info_hash_lock);
20629 +       }
20630 +out:
20631 +       return nr_nids;
20632 +}
20633 +#endif
20634 +
20635 +
20636 +/*
20637 + *     migrate task to new network
20638 + *     gets nxi, puts old_nxi on change
20639 + */
20640 +
20641 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20642 +{
20643 +       struct nx_info *old_nxi;
20644 +       int ret = 0;
20645 +
20646 +       if (!p || !nxi)
20647 +               BUG();
20648 +
20649 +       vxdprintk(VXD_CBIT(nid, 5),
20650 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20651 +               p, nxi, nxi->nx_id,
20652 +               atomic_read(&nxi->nx_usecnt),
20653 +               atomic_read(&nxi->nx_tasks));
20654 +
20655 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20656 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20657 +               return -EACCES;
20658 +
20659 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20660 +               return -EFAULT;
20661 +
20662 +       /* maybe disallow this completely? */
20663 +       old_nxi = task_get_nx_info(p);
20664 +       if (old_nxi == nxi)
20665 +               goto out;
20666 +
20667 +       task_lock(p);
20668 +       if (old_nxi)
20669 +               clr_nx_info(&p->nx_info);
20670 +       claim_nx_info(nxi, p);
20671 +       set_nx_info(&p->nx_info, nxi);
20672 +       p->nid = nxi->nx_id;
20673 +       task_unlock(p);
20674 +
20675 +       vxdprintk(VXD_CBIT(nid, 5),
20676 +               "moved task %p into nxi:%p[#%d]",
20677 +               p, nxi, nxi->nx_id);
20678 +
20679 +       if (old_nxi)
20680 +               release_nx_info(old_nxi, p);
20681 +       ret = 0;
20682 +out:
20683 +       put_nx_info(old_nxi);
20684 +       return ret;
20685 +}
20686 +
20687 +
20688 +void nx_set_persistent(struct nx_info *nxi)
20689 +{
20690 +       vxdprintk(VXD_CBIT(nid, 6),
20691 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20692 +
20693 +       get_nx_info(nxi);
20694 +       claim_nx_info(nxi, NULL);
20695 +}
20696 +
20697 +void nx_clear_persistent(struct nx_info *nxi)
20698 +{
20699 +       vxdprintk(VXD_CBIT(nid, 6),
20700 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20701 +
20702 +       release_nx_info(nxi, NULL);
20703 +       put_nx_info(nxi);
20704 +}
20705 +
20706 +void nx_update_persistent(struct nx_info *nxi)
20707 +{
20708 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20709 +               nx_set_persistent(nxi);
20710 +       else
20711 +               nx_clear_persistent(nxi);
20712 +}
20713 +
20714 +/* vserver syscall commands below here */
20715 +
20716 +/* taks nid and nx_info functions */
20717 +
20718 +#include <asm/uaccess.h>
20719 +
20720 +
20721 +int vc_task_nid(uint32_t id)
20722 +{
20723 +       nid_t nid;
20724 +
20725 +       if (id) {
20726 +               struct task_struct *tsk;
20727 +
20728 +               rcu_read_lock();
20729 +               tsk = find_task_by_real_pid(id);
20730 +               nid = (tsk) ? tsk->nid : -ESRCH;
20731 +               rcu_read_unlock();
20732 +       } else
20733 +               nid = nx_current_nid();
20734 +       return nid;
20735 +}
20736 +
20737 +
20738 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20739 +{
20740 +       struct vcmd_nx_info_v0 vc_data;
20741 +
20742 +       vc_data.nid = nxi->nx_id;
20743 +
20744 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20745 +               return -EFAULT;
20746 +       return 0;
20747 +}
20748 +
20749 +
20750 +/* network functions */
20751 +
20752 +int vc_net_create(uint32_t nid, void __user *data)
20753 +{
20754 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20755 +       struct nx_info *new_nxi;
20756 +       int ret;
20757 +
20758 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20759 +               return -EFAULT;
20760 +
20761 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20762 +               return -EINVAL;
20763 +
20764 +       new_nxi = __create_nx_info(nid);
20765 +       if (IS_ERR(new_nxi))
20766 +               return PTR_ERR(new_nxi);
20767 +
20768 +       /* initial flags */
20769 +       new_nxi->nx_flags = vc_data.flagword;
20770 +
20771 +       ret = -ENOEXEC;
20772 +       if (vs_net_change(new_nxi, VSC_NETUP))
20773 +               goto out;
20774 +
20775 +       ret = nx_migrate_task(current, new_nxi);
20776 +       if (ret)
20777 +               goto out;
20778 +
20779 +       /* return context id on success */
20780 +       ret = new_nxi->nx_id;
20781 +
20782 +       /* get a reference for persistent contexts */
20783 +       if ((vc_data.flagword & NXF_PERSISTENT))
20784 +               nx_set_persistent(new_nxi);
20785 +out:
20786 +       release_nx_info(new_nxi, NULL);
20787 +       put_nx_info(new_nxi);
20788 +       return ret;
20789 +}
20790 +
20791 +
20792 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20793 +{
20794 +       return nx_migrate_task(current, nxi);
20795 +}
20796 +
20797 +
20798 +
20799 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20800 +       uint16_t type, uint16_t flags)
20801 +{
20802 +       struct nx_addr_v4 *nxa = &nxi->v4;
20803 +
20804 +       if (NX_IPV4(nxi)) {
20805 +               /* locate last entry */
20806 +               for (; nxa->next; nxa = nxa->next);
20807 +               nxa->next = __alloc_nx_addr_v4();
20808 +               nxa = nxa->next;
20809 +
20810 +               if (IS_ERR(nxa))
20811 +                       return PTR_ERR(nxa);
20812 +       }
20813 +
20814 +       if (nxi->v4.next)
20815 +               /* remove single ip for ip list */
20816 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20817 +
20818 +       nxa->ip[0].s_addr = ip;
20819 +       nxa->ip[1].s_addr = ip2;
20820 +       nxa->mask.s_addr = mask;
20821 +       nxa->type = type;
20822 +       nxa->flags = flags;
20823 +       return 0;
20824 +}
20825 +
20826 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20827 +       uint16_t type, uint16_t flags)
20828 +{
20829 +       struct nx_addr_v4 *nxa = &nxi->v4;
20830 +
20831 +       switch (type) {
20832 +/*     case NXA_TYPE_ADDR:
20833 +               break;          */
20834 +
20835 +       case NXA_TYPE_ANY:
20836 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20837 +               memset(nxa, 0, sizeof(*nxa));
20838 +               break;
20839 +
20840 +       default:
20841 +               return -EINVAL;
20842 +       }
20843 +       return 0;
20844 +}
20845 +
20846 +
20847 +int vc_net_add(struct nx_info *nxi, void __user *data)
20848 +{
20849 +       struct vcmd_net_addr_v0 vc_data;
20850 +       int index, ret = 0;
20851 +
20852 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20853 +               return -EFAULT;
20854 +
20855 +       switch (vc_data.type) {
20856 +       case NXA_TYPE_IPV4:
20857 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20858 +                       return -EINVAL;
20859 +
20860 +               index = 0;
20861 +               while (index < vc_data.count) {
20862 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20863 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20864 +                       if (ret)
20865 +                               return ret;
20866 +                       index++;
20867 +               }
20868 +               ret = index;
20869 +               break;
20870 +
20871 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20872 +               nxi->v4_bcast = vc_data.ip[0];
20873 +               ret = 1;
20874 +               break;
20875 +
20876 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20877 +               nxi->v4_lback = vc_data.ip[0];
20878 +               ret = 1;
20879 +               break;
20880 +
20881 +       default:
20882 +               ret = -EINVAL;
20883 +               break;
20884 +       }
20885 +       return ret;
20886 +}
20887 +
20888 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20889 +{
20890 +       struct vcmd_net_addr_v0 vc_data;
20891 +
20892 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20893 +               return -EFAULT;
20894 +
20895 +       switch (vc_data.type) {
20896 +       case NXA_TYPE_ANY:
20897 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20898 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20899 +               break;
20900 +
20901 +       default:
20902 +               return -EINVAL;
20903 +       }
20904 +       return 0;
20905 +}
20906 +
20907 +
20908 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20909 +{
20910 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20911 +
20912 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20913 +               return -EFAULT;
20914 +
20915 +       switch (vc_data.type) {
20916 +       case NXA_TYPE_ADDR:
20917 +       case NXA_TYPE_MASK:
20918 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20919 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20920 +
20921 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20922 +               nxi->v4_bcast = vc_data.ip;
20923 +               break;
20924 +
20925 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20926 +               nxi->v4_lback = vc_data.ip;
20927 +               break;
20928 +
20929 +       default:
20930 +               return -EINVAL;
20931 +       }
20932 +       return 0;
20933 +}
20934 +
20935 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20936 +{
20937 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20938 +
20939 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20940 +               return -EFAULT;
20941 +
20942 +       switch (vc_data.type) {
20943 +       case NXA_TYPE_ADDR:
20944 +       case NXA_TYPE_MASK:
20945 +       case NXA_TYPE_RANGE:
20946 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20947 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20948 +
20949 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20950 +               nxi->v4_bcast = vc_data.ip;
20951 +               break;
20952 +
20953 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20954 +               nxi->v4_lback = vc_data.ip;
20955 +               break;
20956 +
20957 +       default:
20958 +               return -EINVAL;
20959 +       }
20960 +       return 0;
20961 +}
20962 +
20963 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20964 +{
20965 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20966 +
20967 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20968 +               return -EFAULT;
20969 +
20970 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20971 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20972 +}
20973 +
20974 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20975 +{
20976 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20977 +
20978 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20979 +               return -EFAULT;
20980 +
20981 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20982 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20983 +}
20984 +
20985 +#ifdef CONFIG_IPV6
20986 +
20987 +int do_add_v6_addr(struct nx_info *nxi,
20988 +       struct in6_addr *ip, struct in6_addr *mask,
20989 +       uint32_t prefix, uint16_t type, uint16_t flags)
20990 +{
20991 +       struct nx_addr_v6 *nxa = &nxi->v6;
20992 +
20993 +       if (NX_IPV6(nxi)) {
20994 +               /* locate last entry */
20995 +               for (; nxa->next; nxa = nxa->next);
20996 +               nxa->next = __alloc_nx_addr_v6();
20997 +               nxa = nxa->next;
20998 +
20999 +               if (IS_ERR(nxa))
21000 +                       return PTR_ERR(nxa);
21001 +       }
21002 +
21003 +       nxa->ip = *ip;
21004 +       nxa->mask = *mask;
21005 +       nxa->prefix = prefix;
21006 +       nxa->type = type;
21007 +       nxa->flags = flags;
21008 +       return 0;
21009 +}
21010 +
21011 +
21012 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21013 +{
21014 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21015 +
21016 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21017 +               return -EFAULT;
21018 +
21019 +       switch (vc_data.type) {
21020 +       case NXA_TYPE_ADDR:
21021 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21022 +               /* fallthrough */
21023 +       case NXA_TYPE_MASK:
21024 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21025 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21026 +       default:
21027 +               return -EINVAL;
21028 +       }
21029 +       return 0;
21030 +}
21031 +
21032 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21033 +{
21034 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21035 +
21036 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21037 +               return -EFAULT;
21038 +
21039 +       switch (vc_data.type) {
21040 +       case NXA_TYPE_ANY:
21041 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21042 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21043 +               break;
21044 +
21045 +       default:
21046 +               return -EINVAL;
21047 +       }
21048 +       return 0;
21049 +}
21050 +
21051 +#endif /* CONFIG_IPV6 */
21052 +
21053 +
21054 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21055 +{
21056 +       struct vcmd_net_flags_v0 vc_data;
21057 +
21058 +       vc_data.flagword = nxi->nx_flags;
21059 +
21060 +       /* special STATE flag handling */
21061 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21062 +
21063 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21064 +               return -EFAULT;
21065 +       return 0;
21066 +}
21067 +
21068 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21069 +{
21070 +       struct vcmd_net_flags_v0 vc_data;
21071 +       uint64_t mask, trigger;
21072 +
21073 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21074 +               return -EFAULT;
21075 +
21076 +       /* special STATE flag handling */
21077 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21078 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21079 +
21080 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21081 +               vc_data.flagword, mask);
21082 +       if (trigger & NXF_PERSISTENT)
21083 +               nx_update_persistent(nxi);
21084 +
21085 +       return 0;
21086 +}
21087 +
21088 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21089 +{
21090 +       struct vcmd_net_caps_v0 vc_data;
21091 +
21092 +       vc_data.ncaps = nxi->nx_ncaps;
21093 +       vc_data.cmask = ~0ULL;
21094 +
21095 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21096 +               return -EFAULT;
21097 +       return 0;
21098 +}
21099 +
21100 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21101 +{
21102 +       struct vcmd_net_caps_v0 vc_data;
21103 +
21104 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21105 +               return -EFAULT;
21106 +
21107 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21108 +               vc_data.ncaps, vc_data.cmask);
21109 +       return 0;
21110 +}
21111 +
21112 +
21113 +#include <linux/module.h>
21114 +
21115 +module_init(init_network);
21116 +
21117 +EXPORT_SYMBOL_GPL(free_nx_info);
21118 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21119 +
21120 diff -NurpP --minimal linux-3.4.83/kernel/vserver/proc.c linux-3.4.83-vs2.3.3.9/kernel/vserver/proc.c
21121 --- linux-3.4.83/kernel/vserver/proc.c  1970-01-01 00:00:00.000000000 +0000
21122 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/proc.c        2012-05-21 16:15:05.000000000 +0000
21123 @@ -0,0 +1,1103 @@
21124 +/*
21125 + *  linux/kernel/vserver/proc.c
21126 + *
21127 + *  Virtual Context Support
21128 + *
21129 + *  Copyright (C) 2003-2011  Herbert Pötzl
21130 + *
21131 + *  V0.01  basic structure
21132 + *  V0.02  adaptation vs1.3.0
21133 + *  V0.03  proc permissions
21134 + *  V0.04  locking/generic
21135 + *  V0.05  next generation procfs
21136 + *  V0.06  inode validation
21137 + *  V0.07  generic rewrite vid
21138 + *  V0.08  remove inode type
21139 + *  V0.09  added u/wmask info
21140 + *
21141 + */
21142 +
21143 +#include <linux/proc_fs.h>
21144 +#include <linux/fs_struct.h>
21145 +#include <linux/mount.h>
21146 +#include <asm/unistd.h>
21147 +
21148 +#include <linux/vs_context.h>
21149 +#include <linux/vs_network.h>
21150 +#include <linux/vs_cvirt.h>
21151 +
21152 +#include <linux/in.h>
21153 +#include <linux/inetdevice.h>
21154 +#include <linux/vs_inet.h>
21155 +#include <linux/vs_inet6.h>
21156 +
21157 +#include <linux/vserver/global.h>
21158 +
21159 +#include "cvirt_proc.h"
21160 +#include "cacct_proc.h"
21161 +#include "limit_proc.h"
21162 +#include "sched_proc.h"
21163 +#include "vci_config.h"
21164 +
21165 +
21166 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21167 +{
21168 +       unsigned __capi;
21169 +
21170 +       CAP_FOR_EACH_U32(__capi) {
21171 +               buffer += sprintf(buffer, "%08x",
21172 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21173 +       }
21174 +       return buffer;
21175 +}
21176 +
21177 +
21178 +static struct proc_dir_entry *proc_virtual;
21179 +
21180 +static struct proc_dir_entry *proc_virtnet;
21181 +
21182 +
21183 +/* first the actual feeds */
21184 +
21185 +
21186 +static int proc_vci(char *buffer)
21187 +{
21188 +       return sprintf(buffer,
21189 +               "VCIVersion:\t%04x:%04x\n"
21190 +               "VCISyscall:\t%d\n"
21191 +               "VCIKernel:\t%08x\n",
21192 +               VCI_VERSION >> 16,
21193 +               VCI_VERSION & 0xFFFF,
21194 +               __NR_vserver,
21195 +               vci_kernel_config());
21196 +}
21197 +
21198 +static int proc_virtual_info(char *buffer)
21199 +{
21200 +       return proc_vci(buffer);
21201 +}
21202 +
21203 +static int proc_virtual_status(char *buffer)
21204 +{
21205 +       return sprintf(buffer,
21206 +               "#CTotal:\t%d\n"
21207 +               "#CActive:\t%d\n"
21208 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21209 +               "#InitTask:\t%d\t%d %d\n",
21210 +               atomic_read(&vx_global_ctotal),
21211 +               atomic_read(&vx_global_cactive),
21212 +               atomic_read(&vs_global_nsproxy),
21213 +               atomic_read(&vs_global_fs),
21214 +               atomic_read(&vs_global_mnt_ns),
21215 +               atomic_read(&vs_global_uts_ns),
21216 +               atomic_read(&nr_ipc_ns),
21217 +               atomic_read(&vs_global_user_ns),
21218 +               atomic_read(&vs_global_pid_ns),
21219 +               atomic_read(&init_task.usage),
21220 +               atomic_read(&init_task.nsproxy->count),
21221 +               init_task.fs->users);
21222 +}
21223 +
21224 +
21225 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21226 +{
21227 +       int length;
21228 +
21229 +       length = sprintf(buffer,
21230 +               "ID:\t%d\n"
21231 +               "Info:\t%p\n"
21232 +               "Init:\t%d\n"
21233 +               "OOM:\t%lld\n",
21234 +               vxi->vx_id,
21235 +               vxi,
21236 +               vxi->vx_initpid,
21237 +               vxi->vx_badness_bias);
21238 +       return length;
21239 +}
21240 +
21241 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21242 +{
21243 +       char *orig = buffer;
21244 +
21245 +       buffer += sprintf(buffer,
21246 +               "UseCnt:\t%d\n"
21247 +               "Tasks:\t%d\n"
21248 +               "Flags:\t%016llx\n",
21249 +               atomic_read(&vxi->vx_usecnt),
21250 +               atomic_read(&vxi->vx_tasks),
21251 +               (unsigned long long)vxi->vx_flags);
21252 +
21253 +       buffer += sprintf(buffer, "BCaps:\t");
21254 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21255 +       buffer += sprintf(buffer, "\n");
21256 +
21257 +       buffer += sprintf(buffer,
21258 +               "CCaps:\t%016llx\n"
21259 +               "Umask:\t%16llx\n"
21260 +               "Wmask:\t%16llx\n"
21261 +               "Spaces:\t%08lx %08lx\n",
21262 +               (unsigned long long)vxi->vx_ccaps,
21263 +               (unsigned long long)vxi->vx_umask,
21264 +               (unsigned long long)vxi->vx_wmask,
21265 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21266 +       return buffer - orig;
21267 +}
21268 +
21269 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21270 +{
21271 +       return vx_info_proc_limit(&vxi->limit, buffer);
21272 +}
21273 +
21274 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21275 +{
21276 +       int cpu, length;
21277 +
21278 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21279 +       for_each_online_cpu(cpu) {
21280 +               length += vx_info_proc_sched_pc(
21281 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21282 +                       buffer + length, cpu);
21283 +       }
21284 +       return length;
21285 +}
21286 +
21287 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21288 +{
21289 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21290 +}
21291 +
21292 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21293 +{
21294 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21295 +}
21296 +
21297 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21298 +{
21299 +       int cpu, length;
21300 +
21301 +       vx_update_load(vxi);
21302 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21303 +       for_each_online_cpu(cpu) {
21304 +               length += vx_info_proc_cvirt_pc(
21305 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21306 +                       buffer + length, cpu);
21307 +       }
21308 +       return length;
21309 +}
21310 +
21311 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21312 +{
21313 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21314 +}
21315 +
21316 +
21317 +static int proc_virtnet_info(char *buffer)
21318 +{
21319 +       return proc_vci(buffer);
21320 +}
21321 +
21322 +static int proc_virtnet_status(char *buffer)
21323 +{
21324 +       return sprintf(buffer,
21325 +               "#CTotal:\t%d\n"
21326 +               "#CActive:\t%d\n",
21327 +               atomic_read(&nx_global_ctotal),
21328 +               atomic_read(&nx_global_cactive));
21329 +}
21330 +
21331 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21332 +{
21333 +       struct nx_addr_v4 *v4a;
21334 +#ifdef CONFIG_IPV6
21335 +       struct nx_addr_v6 *v6a;
21336 +#endif
21337 +       int length, i;
21338 +
21339 +       length = sprintf(buffer,
21340 +               "ID:\t%d\n"
21341 +               "Info:\t%p\n"
21342 +               "Bcast:\t" NIPQUAD_FMT "\n"
21343 +               "Lback:\t" NIPQUAD_FMT "\n",
21344 +               nxi->nx_id,
21345 +               nxi,
21346 +               NIPQUAD(nxi->v4_bcast.s_addr),
21347 +               NIPQUAD(nxi->v4_lback.s_addr));
21348 +
21349 +       if (!NX_IPV4(nxi))
21350 +               goto skip_v4;
21351 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21352 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21353 +                       i, NXAV4(v4a));
21354 +skip_v4:
21355 +#ifdef CONFIG_IPV6
21356 +       if (!NX_IPV6(nxi))
21357 +               goto skip_v6;
21358 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21359 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21360 +                       i, NXAV6(v6a));
21361 +skip_v6:
21362 +#endif
21363 +       return length;
21364 +}
21365 +
21366 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21367 +{
21368 +       int length;
21369 +
21370 +       length = sprintf(buffer,
21371 +               "UseCnt:\t%d\n"
21372 +               "Tasks:\t%d\n"
21373 +               "Flags:\t%016llx\n"
21374 +               "NCaps:\t%016llx\n",
21375 +               atomic_read(&nxi->nx_usecnt),
21376 +               atomic_read(&nxi->nx_tasks),
21377 +               (unsigned long long)nxi->nx_flags,
21378 +               (unsigned long long)nxi->nx_ncaps);
21379 +       return length;
21380 +}
21381 +
21382 +
21383 +
21384 +/* here the inode helpers */
21385 +
21386 +struct vs_entry {
21387 +       int len;
21388 +       char *name;
21389 +       mode_t mode;
21390 +       struct inode_operations *iop;
21391 +       struct file_operations *fop;
21392 +       union proc_op op;
21393 +};
21394 +
21395 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21396 +{
21397 +       struct inode *inode = new_inode(sb);
21398 +
21399 +       if (!inode)
21400 +               goto out;
21401 +
21402 +       inode->i_mode = p->mode;
21403 +       if (p->iop)
21404 +               inode->i_op = p->iop;
21405 +       if (p->fop)
21406 +               inode->i_fop = p->fop;
21407 +
21408 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21409 +       inode->i_flags |= S_IMMUTABLE;
21410 +
21411 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21412 +
21413 +       inode->i_uid = 0;
21414 +       inode->i_gid = 0;
21415 +       inode->i_tag = 0;
21416 +out:
21417 +       return inode;
21418 +}
21419 +
21420 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21421 +       struct dentry *dentry, int id, void *ptr)
21422 +{
21423 +       struct vs_entry *p = ptr;
21424 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21425 +       struct dentry *error = ERR_PTR(-EINVAL);
21426 +
21427 +       if (!inode)
21428 +               goto out;
21429 +
21430 +       PROC_I(inode)->op = p->op;
21431 +       PROC_I(inode)->fd = id;
21432 +       d_add(dentry, inode);
21433 +       error = NULL;
21434 +out:
21435 +       return error;
21436 +}
21437 +
21438 +/* Lookups */
21439 +
21440 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21441 +
21442 +/*
21443 + * Fill a directory entry.
21444 + *
21445 + * If possible create the dcache entry and derive our inode number and
21446 + * file type from dcache entry.
21447 + *
21448 + * Since all of the proc inode numbers are dynamically generated, the inode
21449 + * numbers do not exist until the inode is cache.  This means creating the
21450 + * the dcache entry in readdir is necessary to keep the inode numbers
21451 + * reported by readdir in sync with the inode numbers reported
21452 + * by stat.
21453 + */
21454 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21455 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21456 +{
21457 +       struct dentry *child, *dir = filp->f_dentry;
21458 +       struct inode *inode;
21459 +       struct qstr qname;
21460 +       ino_t ino = 0;
21461 +       unsigned type = DT_UNKNOWN;
21462 +
21463 +       qname.name = name;
21464 +       qname.len  = len;
21465 +       qname.hash = full_name_hash(name, len);
21466 +
21467 +       child = d_lookup(dir, &qname);
21468 +       if (!child) {
21469 +               struct dentry *new;
21470 +               new = d_alloc(dir, &qname);
21471 +               if (new) {
21472 +                       child = instantiate(dir->d_inode, new, id, ptr);
21473 +                       if (child)
21474 +                               dput(new);
21475 +                       else
21476 +                               child = new;
21477 +               }
21478 +       }
21479 +       if (!child || IS_ERR(child) || !child->d_inode)
21480 +               goto end_instantiate;
21481 +       inode = child->d_inode;
21482 +       if (inode) {
21483 +               ino = inode->i_ino;
21484 +               type = inode->i_mode >> 12;
21485 +       }
21486 +       dput(child);
21487 +end_instantiate:
21488 +       if (!ino)
21489 +               ino = find_inode_number(dir, &qname);
21490 +       if (!ino)
21491 +               ino = 1;
21492 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21493 +}
21494 +
21495 +
21496 +
21497 +/* get and revalidate vx_info/xid */
21498 +
21499 +static inline
21500 +struct vx_info *get_proc_vx_info(struct inode *inode)
21501 +{
21502 +       return lookup_vx_info(PROC_I(inode)->fd);
21503 +}
21504 +
21505 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21506 +{
21507 +       struct inode *inode = dentry->d_inode;
21508 +       xid_t xid = PROC_I(inode)->fd;
21509 +
21510 +       if (!xid || xid_is_hashed(xid))
21511 +               return 1;
21512 +       d_drop(dentry);
21513 +       return 0;
21514 +}
21515 +
21516 +
21517 +/* get and revalidate nx_info/nid */
21518 +
21519 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21520 +{
21521 +       struct inode *inode = dentry->d_inode;
21522 +       nid_t nid = PROC_I(inode)->fd;
21523 +
21524 +       if (!nid || nid_is_hashed(nid))
21525 +               return 1;
21526 +       d_drop(dentry);
21527 +       return 0;
21528 +}
21529 +
21530 +
21531 +
21532 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21533 +
21534 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21535 +                         size_t count, loff_t *ppos)
21536 +{
21537 +       struct inode *inode = file->f_dentry->d_inode;
21538 +       unsigned long page;
21539 +       ssize_t length = 0;
21540 +
21541 +       if (count > PROC_BLOCK_SIZE)
21542 +               count = PROC_BLOCK_SIZE;
21543 +
21544 +       /* fade that out as soon as stable */
21545 +       WARN_ON(PROC_I(inode)->fd);
21546 +
21547 +       if (!(page = __get_free_page(GFP_KERNEL)))
21548 +               return -ENOMEM;
21549 +
21550 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21551 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21552 +
21553 +       if (length >= 0)
21554 +               length = simple_read_from_buffer(buf, count, ppos,
21555 +                       (char *)page, length);
21556 +
21557 +       free_page(page);
21558 +       return length;
21559 +}
21560 +
21561 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21562 +                         size_t count, loff_t *ppos)
21563 +{
21564 +       struct inode *inode = file->f_dentry->d_inode;
21565 +       struct vx_info *vxi = NULL;
21566 +       xid_t xid = PROC_I(inode)->fd;
21567 +       unsigned long page;
21568 +       ssize_t length = 0;
21569 +
21570 +       if (count > PROC_BLOCK_SIZE)
21571 +               count = PROC_BLOCK_SIZE;
21572 +
21573 +       /* fade that out as soon as stable */
21574 +       WARN_ON(!xid);
21575 +       vxi = lookup_vx_info(xid);
21576 +       if (!vxi)
21577 +               goto out;
21578 +
21579 +       length = -ENOMEM;
21580 +       if (!(page = __get_free_page(GFP_KERNEL)))
21581 +               goto out_put;
21582 +
21583 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21584 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21585 +
21586 +       if (length >= 0)
21587 +               length = simple_read_from_buffer(buf, count, ppos,
21588 +                       (char *)page, length);
21589 +
21590 +       free_page(page);
21591 +out_put:
21592 +       put_vx_info(vxi);
21593 +out:
21594 +       return length;
21595 +}
21596 +
21597 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21598 +                         size_t count, loff_t *ppos)
21599 +{
21600 +       struct inode *inode = file->f_dentry->d_inode;
21601 +       struct nx_info *nxi = NULL;
21602 +       nid_t nid = PROC_I(inode)->fd;
21603 +       unsigned long page;
21604 +       ssize_t length = 0;
21605 +
21606 +       if (count > PROC_BLOCK_SIZE)
21607 +               count = PROC_BLOCK_SIZE;
21608 +
21609 +       /* fade that out as soon as stable */
21610 +       WARN_ON(!nid);
21611 +       nxi = lookup_nx_info(nid);
21612 +       if (!nxi)
21613 +               goto out;
21614 +
21615 +       length = -ENOMEM;
21616 +       if (!(page = __get_free_page(GFP_KERNEL)))
21617 +               goto out_put;
21618 +
21619 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21620 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21621 +
21622 +       if (length >= 0)
21623 +               length = simple_read_from_buffer(buf, count, ppos,
21624 +                       (char *)page, length);
21625 +
21626 +       free_page(page);
21627 +out_put:
21628 +       put_nx_info(nxi);
21629 +out:
21630 +       return length;
21631 +}
21632 +
21633 +
21634 +
21635 +/* here comes the lower level */
21636 +
21637 +
21638 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21639 +       .len  = sizeof(NAME) - 1,       \
21640 +       .name = (NAME),                 \
21641 +       .mode = MODE,                   \
21642 +       .iop  = IOP,                    \
21643 +       .fop  = FOP,                    \
21644 +       .op   = OP,                     \
21645 +}
21646 +
21647 +
21648 +#define DIR(NAME, MODE, OTYPE)                         \
21649 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21650 +               &proc_ ## OTYPE ## _inode_operations,   \
21651 +               &proc_ ## OTYPE ## _file_operations, { } )
21652 +
21653 +#define INF(NAME, MODE, OTYPE)                         \
21654 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21655 +               &proc_vs_info_file_operations,          \
21656 +               { .proc_vs_read = &proc_##OTYPE } )
21657 +
21658 +#define VINF(NAME, MODE, OTYPE)                                \
21659 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21660 +               &proc_vx_info_file_operations,          \
21661 +               { .proc_vxi_read = &proc_##OTYPE } )
21662 +
21663 +#define NINF(NAME, MODE, OTYPE)                                \
21664 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21665 +               &proc_nx_info_file_operations,          \
21666 +               { .proc_nxi_read = &proc_##OTYPE } )
21667 +
21668 +
21669 +static struct file_operations proc_vs_info_file_operations = {
21670 +       .read =         proc_vs_info_read,
21671 +};
21672 +
21673 +static struct file_operations proc_vx_info_file_operations = {
21674 +       .read =         proc_vx_info_read,
21675 +};
21676 +
21677 +static struct dentry_operations proc_xid_dentry_operations = {
21678 +       .d_revalidate = proc_xid_revalidate,
21679 +};
21680 +
21681 +static struct vs_entry vx_base_stuff[] = {
21682 +       VINF("info",    S_IRUGO, vxi_info),
21683 +       VINF("status",  S_IRUGO, vxi_status),
21684 +       VINF("limit",   S_IRUGO, vxi_limit),
21685 +       VINF("sched",   S_IRUGO, vxi_sched),
21686 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21687 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21688 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21689 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21690 +       {}
21691 +};
21692 +
21693 +
21694 +
21695 +
21696 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21697 +       struct dentry *dentry, int id, void *ptr)
21698 +{
21699 +       dentry->d_op = &proc_xid_dentry_operations;
21700 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21701 +}
21702 +
21703 +static struct dentry *proc_xid_lookup(struct inode *dir,
21704 +       struct dentry *dentry, struct nameidata *nd)
21705 +{
21706 +       struct vs_entry *p = vx_base_stuff;
21707 +       struct dentry *error = ERR_PTR(-ENOENT);
21708 +
21709 +       for (; p->name; p++) {
21710 +               if (p->len != dentry->d_name.len)
21711 +                       continue;
21712 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21713 +                       break;
21714 +       }
21715 +       if (!p->name)
21716 +               goto out;
21717 +
21718 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21719 +out:
21720 +       return error;
21721 +}
21722 +
21723 +static int proc_xid_readdir(struct file *filp,
21724 +       void *dirent, filldir_t filldir)
21725 +{
21726 +       struct dentry *dentry = filp->f_dentry;
21727 +       struct inode *inode = dentry->d_inode;
21728 +       struct vs_entry *p = vx_base_stuff;
21729 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21730 +       int pos, index;
21731 +       u64 ino;
21732 +
21733 +       pos = filp->f_pos;
21734 +       switch (pos) {
21735 +       case 0:
21736 +               ino = inode->i_ino;
21737 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21738 +                       goto out;
21739 +               pos++;
21740 +               /* fall through */
21741 +       case 1:
21742 +               ino = parent_ino(dentry);
21743 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21744 +                       goto out;
21745 +               pos++;
21746 +               /* fall through */
21747 +       default:
21748 +               index = pos - 2;
21749 +               if (index >= size)
21750 +                       goto out;
21751 +               for (p += index; p->name; p++) {
21752 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21753 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21754 +                               goto out;
21755 +                       pos++;
21756 +               }
21757 +       }
21758 +out:
21759 +       filp->f_pos = pos;
21760 +       return 1;
21761 +}
21762 +
21763 +
21764 +
21765 +static struct file_operations proc_nx_info_file_operations = {
21766 +       .read =         proc_nx_info_read,
21767 +};
21768 +
21769 +static struct dentry_operations proc_nid_dentry_operations = {
21770 +       .d_revalidate = proc_nid_revalidate,
21771 +};
21772 +
21773 +static struct vs_entry nx_base_stuff[] = {
21774 +       NINF("info",    S_IRUGO, nxi_info),
21775 +       NINF("status",  S_IRUGO, nxi_status),
21776 +       {}
21777 +};
21778 +
21779 +
21780 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21781 +       struct dentry *dentry, int id, void *ptr)
21782 +{
21783 +       dentry->d_op = &proc_nid_dentry_operations;
21784 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21785 +}
21786 +
21787 +static struct dentry *proc_nid_lookup(struct inode *dir,
21788 +       struct dentry *dentry, struct nameidata *nd)
21789 +{
21790 +       struct vs_entry *p = nx_base_stuff;
21791 +       struct dentry *error = ERR_PTR(-ENOENT);
21792 +
21793 +       for (; p->name; p++) {
21794 +               if (p->len != dentry->d_name.len)
21795 +                       continue;
21796 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21797 +                       break;
21798 +       }
21799 +       if (!p->name)
21800 +               goto out;
21801 +
21802 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21803 +out:
21804 +       return error;
21805 +}
21806 +
21807 +static int proc_nid_readdir(struct file *filp,
21808 +       void *dirent, filldir_t filldir)
21809 +{
21810 +       struct dentry *dentry = filp->f_dentry;
21811 +       struct inode *inode = dentry->d_inode;
21812 +       struct vs_entry *p = nx_base_stuff;
21813 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21814 +       int pos, index;
21815 +       u64 ino;
21816 +
21817 +       pos = filp->f_pos;
21818 +       switch (pos) {
21819 +       case 0:
21820 +               ino = inode->i_ino;
21821 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21822 +                       goto out;
21823 +               pos++;
21824 +               /* fall through */
21825 +       case 1:
21826 +               ino = parent_ino(dentry);
21827 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21828 +                       goto out;
21829 +               pos++;
21830 +               /* fall through */
21831 +       default:
21832 +               index = pos - 2;
21833 +               if (index >= size)
21834 +                       goto out;
21835 +               for (p += index; p->name; p++) {
21836 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21837 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21838 +                               goto out;
21839 +                       pos++;
21840 +               }
21841 +       }
21842 +out:
21843 +       filp->f_pos = pos;
21844 +       return 1;
21845 +}
21846 +
21847 +
21848 +#define MAX_MULBY10    ((~0U - 9) / 10)
21849 +
21850 +static inline int atovid(const char *str, int len)
21851 +{
21852 +       int vid, c;
21853 +
21854 +       vid = 0;
21855 +       while (len-- > 0) {
21856 +               c = *str - '0';
21857 +               str++;
21858 +               if (c > 9)
21859 +                       return -1;
21860 +               if (vid >= MAX_MULBY10)
21861 +                       return -1;
21862 +               vid *= 10;
21863 +               vid += c;
21864 +               if (!vid)
21865 +                       return -1;
21866 +       }
21867 +       return vid;
21868 +}
21869 +
21870 +/* now the upper level (virtual) */
21871 +
21872 +
21873 +static struct file_operations proc_xid_file_operations = {
21874 +       .read =         generic_read_dir,
21875 +       .readdir =      proc_xid_readdir,
21876 +};
21877 +
21878 +static struct inode_operations proc_xid_inode_operations = {
21879 +       .lookup =       proc_xid_lookup,
21880 +};
21881 +
21882 +static struct vs_entry vx_virtual_stuff[] = {
21883 +       INF("info",     S_IRUGO, virtual_info),
21884 +       INF("status",   S_IRUGO, virtual_status),
21885 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21886 +};
21887 +
21888 +
21889 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21890 +       struct dentry *dentry, struct nameidata *nd)
21891 +{
21892 +       struct vs_entry *p = vx_virtual_stuff;
21893 +       struct dentry *error = ERR_PTR(-ENOENT);
21894 +       int id = 0;
21895 +
21896 +       for (; p->name; p++) {
21897 +               if (p->len != dentry->d_name.len)
21898 +                       continue;
21899 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21900 +                       break;
21901 +       }
21902 +       if (p->name)
21903 +               goto instantiate;
21904 +
21905 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21906 +       if ((id < 0) || !xid_is_hashed(id))
21907 +               goto out;
21908 +
21909 +instantiate:
21910 +       error = proc_xid_instantiate(dir, dentry, id, p);
21911 +out:
21912 +       return error;
21913 +}
21914 +
21915 +static struct file_operations proc_nid_file_operations = {
21916 +       .read =         generic_read_dir,
21917 +       .readdir =      proc_nid_readdir,
21918 +};
21919 +
21920 +static struct inode_operations proc_nid_inode_operations = {
21921 +       .lookup =       proc_nid_lookup,
21922 +};
21923 +
21924 +static struct vs_entry nx_virtnet_stuff[] = {
21925 +       INF("info",     S_IRUGO, virtnet_info),
21926 +       INF("status",   S_IRUGO, virtnet_status),
21927 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21928 +};
21929 +
21930 +
21931 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21932 +       struct dentry *dentry, struct nameidata *nd)
21933 +{
21934 +       struct vs_entry *p = nx_virtnet_stuff;
21935 +       struct dentry *error = ERR_PTR(-ENOENT);
21936 +       int id = 0;
21937 +
21938 +       for (; p->name; p++) {
21939 +               if (p->len != dentry->d_name.len)
21940 +                       continue;
21941 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21942 +                       break;
21943 +       }
21944 +       if (p->name)
21945 +               goto instantiate;
21946 +
21947 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21948 +       if ((id < 0) || !nid_is_hashed(id))
21949 +               goto out;
21950 +
21951 +instantiate:
21952 +       error = proc_nid_instantiate(dir, dentry, id, p);
21953 +out:
21954 +       return error;
21955 +}
21956 +
21957 +
21958 +#define PROC_MAXVIDS 32
21959 +
21960 +int proc_virtual_readdir(struct file *filp,
21961 +       void *dirent, filldir_t filldir)
21962 +{
21963 +       struct dentry *dentry = filp->f_dentry;
21964 +       struct inode *inode = dentry->d_inode;
21965 +       struct vs_entry *p = vx_virtual_stuff;
21966 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21967 +       int pos, index;
21968 +       unsigned int xid_array[PROC_MAXVIDS];
21969 +       char buf[PROC_NUMBUF];
21970 +       unsigned int nr_xids, i;
21971 +       u64 ino;
21972 +
21973 +       pos = filp->f_pos;
21974 +       switch (pos) {
21975 +       case 0:
21976 +               ino = inode->i_ino;
21977 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21978 +                       goto out;
21979 +               pos++;
21980 +               /* fall through */
21981 +       case 1:
21982 +               ino = parent_ino(dentry);
21983 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21984 +                       goto out;
21985 +               pos++;
21986 +               /* fall through */
21987 +       default:
21988 +               index = pos - 2;
21989 +               if (index >= size)
21990 +                       goto entries;
21991 +               for (p += index; p->name; p++) {
21992 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21993 +                               vs_proc_instantiate, 0, p))
21994 +                               goto out;
21995 +                       pos++;
21996 +               }
21997 +       entries:
21998 +               index = pos - size;
21999 +               p = &vx_virtual_stuff[size - 1];
22000 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22001 +               for (i = 0; i < nr_xids; i++) {
22002 +                       int n, xid = xid_array[i];
22003 +                       unsigned int j = PROC_NUMBUF;
22004 +
22005 +                       n = xid;
22006 +                       do
22007 +                               buf[--j] = '0' + (n % 10);
22008 +                       while (n /= 10);
22009 +
22010 +                       if (proc_fill_cache(filp, dirent, filldir,
22011 +                               buf + j, PROC_NUMBUF - j,
22012 +                               vs_proc_instantiate, xid, p))
22013 +                               goto out;
22014 +                       pos++;
22015 +               }
22016 +       }
22017 +out:
22018 +       filp->f_pos = pos;
22019 +       return 0;
22020 +}
22021 +
22022 +static int proc_virtual_getattr(struct vfsmount *mnt,
22023 +       struct dentry *dentry, struct kstat *stat)
22024 +{
22025 +       struct inode *inode = dentry->d_inode;
22026 +
22027 +       generic_fillattr(inode, stat);
22028 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22029 +       return 0;
22030 +}
22031 +
22032 +static struct file_operations proc_virtual_dir_operations = {
22033 +       .read =         generic_read_dir,
22034 +       .readdir =      proc_virtual_readdir,
22035 +};
22036 +
22037 +static struct inode_operations proc_virtual_dir_inode_operations = {
22038 +       .getattr =      proc_virtual_getattr,
22039 +       .lookup =       proc_virtual_lookup,
22040 +};
22041 +
22042 +
22043 +
22044 +
22045 +
22046 +int proc_virtnet_readdir(struct file *filp,
22047 +       void *dirent, filldir_t filldir)
22048 +{
22049 +       struct dentry *dentry = filp->f_dentry;
22050 +       struct inode *inode = dentry->d_inode;
22051 +       struct vs_entry *p = nx_virtnet_stuff;
22052 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22053 +       int pos, index;
22054 +       unsigned int nid_array[PROC_MAXVIDS];
22055 +       char buf[PROC_NUMBUF];
22056 +       unsigned int nr_nids, i;
22057 +       u64 ino;
22058 +
22059 +       pos = filp->f_pos;
22060 +       switch (pos) {
22061 +       case 0:
22062 +               ino = inode->i_ino;
22063 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22064 +                       goto out;
22065 +               pos++;
22066 +               /* fall through */
22067 +       case 1:
22068 +               ino = parent_ino(dentry);
22069 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22070 +                       goto out;
22071 +               pos++;
22072 +               /* fall through */
22073 +       default:
22074 +               index = pos - 2;
22075 +               if (index >= size)
22076 +                       goto entries;
22077 +               for (p += index; p->name; p++) {
22078 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22079 +                               vs_proc_instantiate, 0, p))
22080 +                               goto out;
22081 +                       pos++;
22082 +               }
22083 +       entries:
22084 +               index = pos - size;
22085 +               p = &nx_virtnet_stuff[size - 1];
22086 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22087 +               for (i = 0; i < nr_nids; i++) {
22088 +                       int n, nid = nid_array[i];
22089 +                       unsigned int j = PROC_NUMBUF;
22090 +
22091 +                       n = nid;
22092 +                       do
22093 +                               buf[--j] = '0' + (n % 10);
22094 +                       while (n /= 10);
22095 +
22096 +                       if (proc_fill_cache(filp, dirent, filldir,
22097 +                               buf + j, PROC_NUMBUF - j,
22098 +                               vs_proc_instantiate, nid, p))
22099 +                               goto out;
22100 +                       pos++;
22101 +               }
22102 +       }
22103 +out:
22104 +       filp->f_pos = pos;
22105 +       return 0;
22106 +}
22107 +
22108 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22109 +       struct dentry *dentry, struct kstat *stat)
22110 +{
22111 +       struct inode *inode = dentry->d_inode;
22112 +
22113 +       generic_fillattr(inode, stat);
22114 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22115 +       return 0;
22116 +}
22117 +
22118 +static struct file_operations proc_virtnet_dir_operations = {
22119 +       .read =         generic_read_dir,
22120 +       .readdir =      proc_virtnet_readdir,
22121 +};
22122 +
22123 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22124 +       .getattr =      proc_virtnet_getattr,
22125 +       .lookup =       proc_virtnet_lookup,
22126 +};
22127 +
22128 +
22129 +
22130 +void proc_vx_init(void)
22131 +{
22132 +       struct proc_dir_entry *ent;
22133 +
22134 +       ent = proc_mkdir("virtual", 0);
22135 +       if (ent) {
22136 +               ent->proc_fops = &proc_virtual_dir_operations;
22137 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22138 +       }
22139 +       proc_virtual = ent;
22140 +
22141 +       ent = proc_mkdir("virtnet", 0);
22142 +       if (ent) {
22143 +               ent->proc_fops = &proc_virtnet_dir_operations;
22144 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22145 +       }
22146 +       proc_virtnet = ent;
22147 +}
22148 +
22149 +
22150 +
22151 +
22152 +/* per pid info */
22153 +
22154 +
22155 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22156 +{
22157 +       struct vx_info *vxi;
22158 +       char *orig = buffer;
22159 +
22160 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22161 +
22162 +       vxi = task_get_vx_info(p);
22163 +       if (!vxi)
22164 +               goto out;
22165 +
22166 +       buffer += sprintf(buffer, "BCaps:\t");
22167 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22168 +       buffer += sprintf(buffer, "\n");
22169 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22170 +               (unsigned long long)vxi->vx_ccaps);
22171 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22172 +               (unsigned long long)vxi->vx_flags);
22173 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22174 +
22175 +       put_vx_info(vxi);
22176 +out:
22177 +       return buffer - orig;
22178 +}
22179 +
22180 +
22181 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22182 +{
22183 +       struct nx_info *nxi;
22184 +       struct nx_addr_v4 *v4a;
22185 +#ifdef CONFIG_IPV6
22186 +       struct nx_addr_v6 *v6a;
22187 +#endif
22188 +       char *orig = buffer;
22189 +       int i;
22190 +
22191 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22192 +
22193 +       nxi = task_get_nx_info(p);
22194 +       if (!nxi)
22195 +               goto out;
22196 +
22197 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22198 +               (unsigned long long)nxi->nx_ncaps);
22199 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22200 +               (unsigned long long)nxi->nx_flags);
22201 +
22202 +       buffer += sprintf(buffer,
22203 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22204 +               NIPQUAD(nxi->v4_bcast.s_addr));
22205 +       buffer += sprintf (buffer,
22206 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22207 +               NIPQUAD(nxi->v4_lback.s_addr));
22208 +       if (!NX_IPV4(nxi))
22209 +               goto skip_v4;
22210 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22211 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22212 +                       i, NXAV4(v4a));
22213 +skip_v4:
22214 +#ifdef CONFIG_IPV6
22215 +       if (!NX_IPV6(nxi))
22216 +               goto skip_v6;
22217 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22218 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22219 +                       i, NXAV6(v6a));
22220 +skip_v6:
22221 +#endif
22222 +       put_nx_info(nxi);
22223 +out:
22224 +       return buffer - orig;
22225 +}
22226 +
22227 diff -NurpP --minimal linux-3.4.83/kernel/vserver/sched.c linux-3.4.83-vs2.3.3.9/kernel/vserver/sched.c
22228 --- linux-3.4.83/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
22229 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/sched.c       2012-05-21 16:25:11.000000000 +0000
22230 @@ -0,0 +1,83 @@
22231 +/*
22232 + *  linux/kernel/vserver/sched.c
22233 + *
22234 + *  Virtual Server: Scheduler Support
22235 + *
22236 + *  Copyright (C) 2004-2010  Herbert Pötzl
22237 + *
22238 + *  V0.01  adapted Sam Vilains version to 2.6.3
22239 + *  V0.02  removed legacy interface
22240 + *  V0.03  changed vcmds to vxi arg
22241 + *  V0.04  removed older and legacy interfaces
22242 + *  V0.05  removed scheduler code/commands
22243 + *
22244 + */
22245 +
22246 +#include <linux/vs_context.h>
22247 +#include <linux/vs_sched.h>
22248 +#include <linux/cpumask.h>
22249 +#include <linux/vserver/sched_cmd.h>
22250 +
22251 +#include <asm/uaccess.h>
22252 +
22253 +
22254 +void vx_update_sched_param(struct _vx_sched *sched,
22255 +       struct _vx_sched_pc *sched_pc)
22256 +{
22257 +       sched_pc->prio_bias = sched->prio_bias;
22258 +}
22259 +
22260 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22261 +{
22262 +       int cpu;
22263 +
22264 +       if (data->prio_bias > MAX_PRIO_BIAS)
22265 +               data->prio_bias = MAX_PRIO_BIAS;
22266 +       if (data->prio_bias < MIN_PRIO_BIAS)
22267 +               data->prio_bias = MIN_PRIO_BIAS;
22268 +
22269 +       if (data->cpu_id != ~0) {
22270 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22271 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22272 +                       cpu_online_mask);
22273 +       } else
22274 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22275 +
22276 +       for_each_cpu_mask(cpu, vxi->sched.update)
22277 +               vx_update_sched_param(&vxi->sched,
22278 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22279 +       return 0;
22280 +}
22281 +
22282 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22283 +{
22284 +       struct vcmd_prio_bias vc_data;
22285 +
22286 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22287 +               return -EFAULT;
22288 +
22289 +       return do_set_prio_bias(vxi, &vc_data);
22290 +}
22291 +
22292 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22293 +{
22294 +       struct vcmd_prio_bias vc_data;
22295 +       struct _vx_sched_pc *pcd;
22296 +       int cpu;
22297 +
22298 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22299 +               return -EFAULT;
22300 +
22301 +       cpu = vc_data.cpu_id;
22302 +
22303 +       if (!cpu_possible(cpu))
22304 +               return -EINVAL;
22305 +
22306 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22307 +       vc_data.prio_bias = pcd->prio_bias;
22308 +
22309 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22310 +               return -EFAULT;
22311 +       return 0;
22312 +}
22313 +
22314 diff -NurpP --minimal linux-3.4.83/kernel/vserver/sched_init.h linux-3.4.83-vs2.3.3.9/kernel/vserver/sched_init.h
22315 --- linux-3.4.83/kernel/vserver/sched_init.h    1970-01-01 00:00:00.000000000 +0000
22316 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/sched_init.h  2012-05-21 16:15:05.000000000 +0000
22317 @@ -0,0 +1,27 @@
22318 +
22319 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22320 +{
22321 +       /* scheduling; hard code starting values as constants */
22322 +       sched->prio_bias = 0;
22323 +}
22324 +
22325 +static inline
22326 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22327 +{
22328 +       sched_pc->prio_bias = 0;
22329 +
22330 +       sched_pc->user_ticks = 0;
22331 +       sched_pc->sys_ticks = 0;
22332 +       sched_pc->hold_ticks = 0;
22333 +}
22334 +
22335 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22336 +{
22337 +       return;
22338 +}
22339 +
22340 +static inline
22341 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22342 +{
22343 +       return;
22344 +}
22345 diff -NurpP --minimal linux-3.4.83/kernel/vserver/sched_proc.h linux-3.4.83-vs2.3.3.9/kernel/vserver/sched_proc.h
22346 --- linux-3.4.83/kernel/vserver/sched_proc.h    1970-01-01 00:00:00.000000000 +0000
22347 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/sched_proc.h  2012-05-21 16:15:05.000000000 +0000
22348 @@ -0,0 +1,32 @@
22349 +#ifndef _VX_SCHED_PROC_H
22350 +#define _VX_SCHED_PROC_H
22351 +
22352 +
22353 +static inline
22354 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22355 +{
22356 +       int length = 0;
22357 +
22358 +       length += sprintf(buffer,
22359 +               "PrioBias:\t%8d\n",
22360 +               sched->prio_bias);
22361 +       return length;
22362 +}
22363 +
22364 +static inline
22365 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22366 +       char *buffer, int cpu)
22367 +{
22368 +       int length = 0;
22369 +
22370 +       length += sprintf(buffer + length,
22371 +               "cpu %d: %lld %lld %lld", cpu,
22372 +               (unsigned long long)sched_pc->user_ticks,
22373 +               (unsigned long long)sched_pc->sys_ticks,
22374 +               (unsigned long long)sched_pc->hold_ticks);
22375 +       length += sprintf(buffer + length,
22376 +               " %d\n", sched_pc->prio_bias);
22377 +       return length;
22378 +}
22379 +
22380 +#endif /* _VX_SCHED_PROC_H */
22381 diff -NurpP --minimal linux-3.4.83/kernel/vserver/signal.c linux-3.4.83-vs2.3.3.9/kernel/vserver/signal.c
22382 --- linux-3.4.83/kernel/vserver/signal.c        1970-01-01 00:00:00.000000000 +0000
22383 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/signal.c      2012-05-21 16:15:05.000000000 +0000
22384 @@ -0,0 +1,134 @@
22385 +/*
22386 + *  linux/kernel/vserver/signal.c
22387 + *
22388 + *  Virtual Server: Signal Support
22389 + *
22390 + *  Copyright (C) 2003-2007  Herbert Pötzl
22391 + *
22392 + *  V0.01  broken out from vcontext V0.05
22393 + *  V0.02  changed vcmds to vxi arg
22394 + *  V0.03  adjusted siginfo for kill
22395 + *
22396 + */
22397 +
22398 +#include <asm/uaccess.h>
22399 +
22400 +#include <linux/vs_context.h>
22401 +#include <linux/vs_pid.h>
22402 +#include <linux/vserver/signal_cmd.h>
22403 +
22404 +
22405 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22406 +{
22407 +       int retval, count = 0;
22408 +       struct task_struct *p;
22409 +       struct siginfo *sip = SEND_SIG_PRIV;
22410 +
22411 +       retval = -ESRCH;
22412 +       vxdprintk(VXD_CBIT(misc, 4),
22413 +               "vx_info_kill(%p[#%d],%d,%d)*",
22414 +               vxi, vxi->vx_id, pid, sig);
22415 +       read_lock(&tasklist_lock);
22416 +       switch (pid) {
22417 +       case  0:
22418 +       case -1:
22419 +               for_each_process(p) {
22420 +                       int err = 0;
22421 +
22422 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22423 +                               (pid && vxi->vx_initpid == p->pid))
22424 +                               continue;
22425 +
22426 +                       err = group_send_sig_info(sig, sip, p);
22427 +                       ++count;
22428 +                       if (err != -EPERM)
22429 +                               retval = err;
22430 +               }
22431 +               break;
22432 +
22433 +       case 1:
22434 +               if (vxi->vx_initpid) {
22435 +                       pid = vxi->vx_initpid;
22436 +                       /* for now, only SIGINT to private init ... */
22437 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22438 +                               /* ... as long as there are tasks left */
22439 +                               (atomic_read(&vxi->vx_tasks) > 1))
22440 +                               sig = SIGINT;
22441 +               }
22442 +               /* fallthrough */
22443 +       default:
22444 +               rcu_read_lock();
22445 +               p = find_task_by_real_pid(pid);
22446 +               rcu_read_unlock();
22447 +               if (p) {
22448 +                       if (vx_task_xid(p) == vxi->vx_id)
22449 +                               retval = group_send_sig_info(sig, sip, p);
22450 +               }
22451 +               break;
22452 +       }
22453 +       read_unlock(&tasklist_lock);
22454 +       vxdprintk(VXD_CBIT(misc, 4),
22455 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22456 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22457 +       return retval;
22458 +}
22459 +
22460 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22461 +{
22462 +       struct vcmd_ctx_kill_v0 vc_data;
22463 +
22464 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22465 +               return -EFAULT;
22466 +
22467 +       /* special check to allow guest shutdown */
22468 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22469 +               /* forbid killall pid=0 when init is present */
22470 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22471 +               (vc_data.pid > 1)))
22472 +               return -EACCES;
22473 +
22474 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22475 +}
22476 +
22477 +
22478 +static int __wait_exit(struct vx_info *vxi)
22479 +{
22480 +       DECLARE_WAITQUEUE(wait, current);
22481 +       int ret = 0;
22482 +
22483 +       add_wait_queue(&vxi->vx_wait, &wait);
22484 +       set_current_state(TASK_INTERRUPTIBLE);
22485 +
22486 +wait:
22487 +       if (vx_info_state(vxi,
22488 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22489 +               goto out;
22490 +       if (signal_pending(current)) {
22491 +               ret = -ERESTARTSYS;
22492 +               goto out;
22493 +       }
22494 +       schedule();
22495 +       goto wait;
22496 +
22497 +out:
22498 +       set_current_state(TASK_RUNNING);
22499 +       remove_wait_queue(&vxi->vx_wait, &wait);
22500 +       return ret;
22501 +}
22502 +
22503 +
22504 +
22505 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22506 +{
22507 +       struct vcmd_wait_exit_v0 vc_data;
22508 +       int ret;
22509 +
22510 +       ret = __wait_exit(vxi);
22511 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22512 +       vc_data.exit_code = vxi->exit_code;
22513 +
22514 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22515 +               ret = -EFAULT;
22516 +       return ret;
22517 +}
22518 +
22519 diff -NurpP --minimal linux-3.4.83/kernel/vserver/space.c linux-3.4.83-vs2.3.3.9/kernel/vserver/space.c
22520 --- linux-3.4.83/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
22521 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/space.c       2013-02-12 00:16:04.000000000 +0000
22522 @@ -0,0 +1,436 @@
22523 +/*
22524 + *  linux/kernel/vserver/space.c
22525 + *
22526 + *  Virtual Server: Context Space Support
22527 + *
22528 + *  Copyright (C) 2003-2010  Herbert Pötzl
22529 + *
22530 + *  V0.01  broken out from context.c 0.07
22531 + *  V0.02  added task locking for namespace
22532 + *  V0.03  broken out vx_enter_namespace
22533 + *  V0.04  added *space support and commands
22534 + *  V0.05  added credential support
22535 + *
22536 + */
22537 +
22538 +#include <linux/utsname.h>
22539 +#include <linux/nsproxy.h>
22540 +#include <linux/err.h>
22541 +#include <linux/fs_struct.h>
22542 +#include <linux/cred.h>
22543 +#include <asm/uaccess.h>
22544 +
22545 +#include <linux/vs_context.h>
22546 +#include <linux/vserver/space.h>
22547 +#include <linux/vserver/space_cmd.h>
22548 +
22549 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22550 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22551 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22552 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22553 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22554 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22555 +
22556 +
22557 +/* namespace functions */
22558 +
22559 +#include <linux/mnt_namespace.h>
22560 +#include <linux/user_namespace.h>
22561 +#include <linux/pid_namespace.h>
22562 +#include <linux/ipc_namespace.h>
22563 +#include <net/net_namespace.h>
22564 +#include "../fs/mount.h"
22565 +
22566 +
22567 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22568 +       .mask = CLONE_FS |
22569 +               CLONE_NEWNS |
22570 +#ifdef CONFIG_UTS_NS
22571 +               CLONE_NEWUTS |
22572 +#endif
22573 +#ifdef CONFIG_IPC_NS
22574 +               CLONE_NEWIPC |
22575 +#endif
22576 +#ifdef CONFIG_USER_NS
22577 +               CLONE_NEWUSER |
22578 +#endif
22579 +               0
22580 +};
22581 +
22582 +static const struct vcmd_space_mask_v1 space_mask = {
22583 +       .mask = CLONE_FS |
22584 +               CLONE_NEWNS |
22585 +#ifdef CONFIG_UTS_NS
22586 +               CLONE_NEWUTS |
22587 +#endif
22588 +#ifdef CONFIG_IPC_NS
22589 +               CLONE_NEWIPC |
22590 +#endif
22591 +#ifdef CONFIG_USER_NS
22592 +               CLONE_NEWUSER |
22593 +#endif
22594 +#ifdef CONFIG_PID_NS
22595 +               CLONE_NEWPID |
22596 +#endif
22597 +#ifdef CONFIG_NET_NS
22598 +               CLONE_NEWNET |
22599 +#endif
22600 +               0
22601 +};
22602 +
22603 +static const struct vcmd_space_mask_v1 default_space_mask = {
22604 +       .mask = CLONE_FS |
22605 +               CLONE_NEWNS |
22606 +#ifdef CONFIG_UTS_NS
22607 +               CLONE_NEWUTS |
22608 +#endif
22609 +#ifdef CONFIG_IPC_NS
22610 +               CLONE_NEWIPC |
22611 +#endif
22612 +#ifdef CONFIG_USER_NS
22613 +               CLONE_NEWUSER |
22614 +#endif
22615 +#ifdef CONFIG_PID_NS
22616 +//             CLONE_NEWPID |
22617 +#endif
22618 +               0
22619 +};
22620 +
22621 +/*
22622 + *     build a new nsproxy mix
22623 + *      assumes that both proxies are 'const'
22624 + *     does not touch nsproxy refcounts
22625 + *     will hold a reference on the result.
22626 + */
22627 +
22628 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22629 +       struct nsproxy *new_nsproxy, unsigned long mask)
22630 +{
22631 +       struct mnt_namespace *old_ns;
22632 +       struct uts_namespace *old_uts;
22633 +       struct ipc_namespace *old_ipc;
22634 +#ifdef CONFIG_PID_NS
22635 +       struct pid_namespace *old_pid;
22636 +#endif
22637 +#ifdef CONFIG_NET_NS
22638 +       struct net *old_net;
22639 +#endif
22640 +       struct nsproxy *nsproxy;
22641 +
22642 +       nsproxy = copy_nsproxy(old_nsproxy);
22643 +       if (!nsproxy)
22644 +               goto out;
22645 +
22646 +       if (mask & CLONE_NEWNS) {
22647 +               old_ns = nsproxy->mnt_ns;
22648 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22649 +               if (nsproxy->mnt_ns)
22650 +                       get_mnt_ns(nsproxy->mnt_ns);
22651 +       } else
22652 +               old_ns = NULL;
22653 +
22654 +       if (mask & CLONE_NEWUTS) {
22655 +               old_uts = nsproxy->uts_ns;
22656 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22657 +               if (nsproxy->uts_ns)
22658 +                       get_uts_ns(nsproxy->uts_ns);
22659 +       } else
22660 +               old_uts = NULL;
22661 +
22662 +       if (mask & CLONE_NEWIPC) {
22663 +               old_ipc = nsproxy->ipc_ns;
22664 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22665 +               if (nsproxy->ipc_ns)
22666 +                       get_ipc_ns(nsproxy->ipc_ns);
22667 +       } else
22668 +               old_ipc = NULL;
22669 +
22670 +#ifdef CONFIG_PID_NS
22671 +       if (mask & CLONE_NEWPID) {
22672 +               old_pid = nsproxy->pid_ns;
22673 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22674 +               if (nsproxy->pid_ns)
22675 +                       get_pid_ns(nsproxy->pid_ns);
22676 +       } else
22677 +               old_pid = NULL;
22678 +#endif
22679 +#ifdef CONFIG_NET_NS
22680 +       if (mask & CLONE_NEWNET) {
22681 +               old_net = nsproxy->net_ns;
22682 +               nsproxy->net_ns = new_nsproxy->net_ns;
22683 +               if (nsproxy->net_ns)
22684 +                       get_net(nsproxy->net_ns);
22685 +       } else
22686 +               old_net = NULL;
22687 +#endif
22688 +       if (old_ns)
22689 +               put_mnt_ns(old_ns);
22690 +       if (old_uts)
22691 +               put_uts_ns(old_uts);
22692 +       if (old_ipc)
22693 +               put_ipc_ns(old_ipc);
22694 +#ifdef CONFIG_PID_NS
22695 +       if (old_pid)
22696 +               put_pid_ns(old_pid);
22697 +#endif
22698 +#ifdef CONFIG_NET_NS
22699 +       if (old_net)
22700 +               put_net(old_net);
22701 +#endif
22702 +out:
22703 +       return nsproxy;
22704 +}
22705 +
22706 +
22707 +/*
22708 + *     merge two nsproxy structs into a new one.
22709 + *     will hold a reference on the result.
22710 + */
22711 +
22712 +static inline
22713 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22714 +       struct nsproxy *proxy, unsigned long mask)
22715 +{
22716 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22717 +
22718 +       if (!proxy)
22719 +               return NULL;
22720 +
22721 +       if (mask) {
22722 +               /* vs_mix_nsproxy returns with reference */
22723 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22724 +                       proxy, mask);
22725 +       }
22726 +       get_nsproxy(proxy);
22727 +       return proxy;
22728 +}
22729 +
22730 +
22731 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22732 +{
22733 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22734 +       struct fs_struct *fs_cur, *fs = NULL;
22735 +       struct _vx_space *space;
22736 +       int ret, kill = 0;
22737 +
22738 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22739 +               vxi, vxi->vx_id, mask, index);
22740 +
22741 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22742 +               return -EACCES;
22743 +
22744 +       if (index >= VX_SPACES)
22745 +               return -EINVAL;
22746 +
22747 +       space = &vxi->space[index];
22748 +
22749 +       if (!mask)
22750 +               mask = space->vx_nsmask;
22751 +
22752 +       if ((mask & space->vx_nsmask) != mask)
22753 +               return -EINVAL;
22754 +
22755 +       if (mask & CLONE_FS) {
22756 +               fs = copy_fs_struct(space->vx_fs);
22757 +               if (!fs)
22758 +                       return -ENOMEM;
22759 +       }
22760 +       proxy = space->vx_nsproxy;
22761 +
22762 +       vxdprintk(VXD_CBIT(space, 9),
22763 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22764 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22765 +
22766 +       task_lock(current);
22767 +       fs_cur = current->fs;
22768 +
22769 +       if (mask & CLONE_FS) {
22770 +               spin_lock(&fs_cur->lock);
22771 +               current->fs = fs;
22772 +               kill = !--fs_cur->users;
22773 +               spin_unlock(&fs_cur->lock);
22774 +       }
22775 +
22776 +       proxy_cur = current->nsproxy;
22777 +       get_nsproxy(proxy_cur);
22778 +       task_unlock(current);
22779 +
22780 +       if (kill)
22781 +               free_fs_struct(fs_cur);
22782 +
22783 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22784 +       if (IS_ERR(proxy_new)) {
22785 +               ret = PTR_ERR(proxy_new);
22786 +               goto out_put;
22787 +       }
22788 +
22789 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22790 +
22791 +       if (mask & CLONE_NEWUSER) {
22792 +               struct cred *cred;
22793 +
22794 +               vxdprintk(VXD_CBIT(space, 10),
22795 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22796 +                       vxi, vxi->vx_id, space->vx_cred,
22797 +                       current->real_cred, current->cred);
22798 +
22799 +               if (space->vx_cred) {
22800 +                       cred = __prepare_creds(space->vx_cred);
22801 +                       if (cred)
22802 +                               commit_creds(cred);
22803 +               }
22804 +       }
22805 +
22806 +       ret = 0;
22807 +
22808 +       if (proxy_new)
22809 +               put_nsproxy(proxy_new);
22810 +out_put:
22811 +       if (proxy_cur)
22812 +               put_nsproxy(proxy_cur);
22813 +       return ret;
22814 +}
22815 +
22816 +
22817 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22818 +{
22819 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22820 +       struct fs_struct *fs_vxi, *fs = NULL;
22821 +       struct _vx_space *space;
22822 +       int ret, kill = 0;
22823 +
22824 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22825 +               vxi, vxi->vx_id, mask, index);
22826 +
22827 +       if ((mask & space_mask.mask) != mask)
22828 +               return -EINVAL;
22829 +
22830 +       if (index >= VX_SPACES)
22831 +               return -EINVAL;
22832 +
22833 +       space = &vxi->space[index];
22834 +
22835 +       proxy_vxi = space->vx_nsproxy;
22836 +       fs_vxi = space->vx_fs;
22837 +
22838 +       if (mask & CLONE_FS) {
22839 +               fs = copy_fs_struct(current->fs);
22840 +               if (!fs)
22841 +                       return -ENOMEM;
22842 +       }
22843 +
22844 +       task_lock(current);
22845 +
22846 +       if (mask & CLONE_FS) {
22847 +               spin_lock(&fs_vxi->lock);
22848 +               space->vx_fs = fs;
22849 +               kill = !--fs_vxi->users;
22850 +               spin_unlock(&fs_vxi->lock);
22851 +       }
22852 +
22853 +       proxy_cur = current->nsproxy;
22854 +       get_nsproxy(proxy_cur);
22855 +       task_unlock(current);
22856 +
22857 +       if (kill)
22858 +               free_fs_struct(fs_vxi);
22859 +
22860 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22861 +       if (IS_ERR(proxy_new)) {
22862 +               ret = PTR_ERR(proxy_new);
22863 +               goto out_put;
22864 +       }
22865 +
22866 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22867 +       space->vx_nsmask |= mask;
22868 +
22869 +       if (mask & CLONE_NEWUSER) {
22870 +               struct cred *cred;
22871 +
22872 +               vxdprintk(VXD_CBIT(space, 10),
22873 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22874 +                       vxi, vxi->vx_id, space->vx_cred,
22875 +                       current->real_cred, current->cred);
22876 +
22877 +               cred = prepare_creds();
22878 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22879 +               if (cred)
22880 +                       abort_creds(cred);
22881 +       }
22882 +
22883 +       ret = 0;
22884 +
22885 +       if (proxy_new)
22886 +               put_nsproxy(proxy_new);
22887 +out_put:
22888 +       if (proxy_cur)
22889 +               put_nsproxy(proxy_cur);
22890 +       return ret;
22891 +}
22892 +
22893 +
22894 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22895 +{
22896 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22897 +
22898 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22899 +               return -EFAULT;
22900 +
22901 +       return vx_enter_space(vxi, vc_data.mask, 0);
22902 +}
22903 +
22904 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22905 +{
22906 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22907 +
22908 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22909 +               return -EFAULT;
22910 +
22911 +       if (vc_data.index >= VX_SPACES)
22912 +               return -EINVAL;
22913 +
22914 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22915 +}
22916 +
22917 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22918 +{
22919 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22920 +
22921 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22922 +               return -EFAULT;
22923 +
22924 +       return vx_set_space(vxi, vc_data.mask, 0);
22925 +}
22926 +
22927 +int vc_set_space(struct vx_info *vxi, void __user *data)
22928 +{
22929 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22930 +
22931 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22932 +               return -EFAULT;
22933 +
22934 +       if (vc_data.index >= VX_SPACES)
22935 +               return -EINVAL;
22936 +
22937 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22938 +}
22939 +
22940 +int vc_get_space_mask(void __user *data, int type)
22941 +{
22942 +       const struct vcmd_space_mask_v1 *mask;
22943 +
22944 +       if (type == 0)
22945 +               mask = &space_mask_v0;
22946 +       else if (type == 1)
22947 +               mask = &space_mask;
22948 +       else
22949 +               mask = &default_space_mask;
22950 +
22951 +       vxdprintk(VXD_CBIT(space, 10),
22952 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22953 +
22954 +       if (copy_to_user(data, mask, sizeof(*mask)))
22955 +               return -EFAULT;
22956 +       return 0;
22957 +}
22958 +
22959 diff -NurpP --minimal linux-3.4.83/kernel/vserver/switch.c linux-3.4.83-vs2.3.3.9/kernel/vserver/switch.c
22960 --- linux-3.4.83/kernel/vserver/switch.c        1970-01-01 00:00:00.000000000 +0000
22961 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/switch.c      2012-05-21 16:15:05.000000000 +0000
22962 @@ -0,0 +1,556 @@
22963 +/*
22964 + *  linux/kernel/vserver/switch.c
22965 + *
22966 + *  Virtual Server: Syscall Switch
22967 + *
22968 + *  Copyright (C) 2003-2011  Herbert Pötzl
22969 + *
22970 + *  V0.01  syscall switch
22971 + *  V0.02  added signal to context
22972 + *  V0.03  added rlimit functions
22973 + *  V0.04  added iattr, task/xid functions
22974 + *  V0.05  added debug/history stuff
22975 + *  V0.06  added compat32 layer
22976 + *  V0.07  vcmd args and perms
22977 + *  V0.08  added status commands
22978 + *  V0.09  added tag commands
22979 + *  V0.10  added oom bias
22980 + *  V0.11  added device commands
22981 + *  V0.12  added warn mask
22982 + *
22983 + */
22984 +
22985 +#include <linux/vs_context.h>
22986 +#include <linux/vs_network.h>
22987 +#include <linux/vserver/switch.h>
22988 +
22989 +#include "vci_config.h"
22990 +
22991 +
22992 +static inline
22993 +int vc_get_version(uint32_t id)
22994 +{
22995 +       return VCI_VERSION;
22996 +}
22997 +
22998 +static inline
22999 +int vc_get_vci(uint32_t id)
23000 +{
23001 +       return vci_kernel_config();
23002 +}
23003 +
23004 +#include <linux/vserver/context_cmd.h>
23005 +#include <linux/vserver/cvirt_cmd.h>
23006 +#include <linux/vserver/cacct_cmd.h>
23007 +#include <linux/vserver/limit_cmd.h>
23008 +#include <linux/vserver/network_cmd.h>
23009 +#include <linux/vserver/sched_cmd.h>
23010 +#include <linux/vserver/debug_cmd.h>
23011 +#include <linux/vserver/inode_cmd.h>
23012 +#include <linux/vserver/dlimit_cmd.h>
23013 +#include <linux/vserver/signal_cmd.h>
23014 +#include <linux/vserver/space_cmd.h>
23015 +#include <linux/vserver/tag_cmd.h>
23016 +#include <linux/vserver/device_cmd.h>
23017 +
23018 +#include <linux/vserver/inode.h>
23019 +#include <linux/vserver/dlimit.h>
23020 +
23021 +
23022 +#ifdef CONFIG_COMPAT
23023 +#define __COMPAT(name, id, data, compat)       \
23024 +       (compat) ? name ## _x32(id, data) : name(id, data)
23025 +#define __COMPAT_NO_ID(name, data, compat)     \
23026 +       (compat) ? name ## _x32(data) : name(data)
23027 +#else
23028 +#define __COMPAT(name, id, data, compat)       \
23029 +       name(id, data)
23030 +#define __COMPAT_NO_ID(name, data, compat)     \
23031 +       name(data)
23032 +#endif
23033 +
23034 +
23035 +static inline
23036 +long do_vcmd(uint32_t cmd, uint32_t id,
23037 +       struct vx_info *vxi, struct nx_info *nxi,
23038 +       void __user *data, int compat)
23039 +{
23040 +       switch (cmd) {
23041 +
23042 +       case VCMD_get_version:
23043 +               return vc_get_version(id);
23044 +       case VCMD_get_vci:
23045 +               return vc_get_vci(id);
23046 +
23047 +       case VCMD_task_xid:
23048 +               return vc_task_xid(id);
23049 +       case VCMD_vx_info:
23050 +               return vc_vx_info(vxi, data);
23051 +
23052 +       case VCMD_task_nid:
23053 +               return vc_task_nid(id);
23054 +       case VCMD_nx_info:
23055 +               return vc_nx_info(nxi, data);
23056 +
23057 +       case VCMD_task_tag:
23058 +               return vc_task_tag(id);
23059 +
23060 +       case VCMD_set_space_v1:
23061 +               return vc_set_space_v1(vxi, data);
23062 +       /* this is version 2 */
23063 +       case VCMD_set_space:
23064 +               return vc_set_space(vxi, data);
23065 +
23066 +       case VCMD_get_space_mask_v0:
23067 +               return vc_get_space_mask(data, 0);
23068 +       /* this is version 1 */
23069 +       case VCMD_get_space_mask:
23070 +               return vc_get_space_mask(data, 1);
23071 +
23072 +       case VCMD_get_space_default:
23073 +               return vc_get_space_mask(data, -1);
23074 +
23075 +       case VCMD_set_umask:
23076 +               return vc_set_umask(vxi, data);
23077 +
23078 +       case VCMD_get_umask:
23079 +               return vc_get_umask(vxi, data);
23080 +
23081 +       case VCMD_set_wmask:
23082 +               return vc_set_wmask(vxi, data);
23083 +
23084 +       case VCMD_get_wmask:
23085 +               return vc_get_wmask(vxi, data);
23086 +#ifdef CONFIG_IA32_EMULATION
23087 +       case VCMD_get_rlimit:
23088 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23089 +       case VCMD_set_rlimit:
23090 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23091 +#else
23092 +       case VCMD_get_rlimit:
23093 +               return vc_get_rlimit(vxi, data);
23094 +       case VCMD_set_rlimit:
23095 +               return vc_set_rlimit(vxi, data);
23096 +#endif
23097 +       case VCMD_get_rlimit_mask:
23098 +               return vc_get_rlimit_mask(id, data);
23099 +       case VCMD_reset_hits:
23100 +               return vc_reset_hits(vxi, data);
23101 +       case VCMD_reset_minmax:
23102 +               return vc_reset_minmax(vxi, data);
23103 +
23104 +       case VCMD_get_vhi_name:
23105 +               return vc_get_vhi_name(vxi, data);
23106 +       case VCMD_set_vhi_name:
23107 +               return vc_set_vhi_name(vxi, data);
23108 +
23109 +       case VCMD_ctx_stat:
23110 +               return vc_ctx_stat(vxi, data);
23111 +       case VCMD_virt_stat:
23112 +               return vc_virt_stat(vxi, data);
23113 +       case VCMD_sock_stat:
23114 +               return vc_sock_stat(vxi, data);
23115 +       case VCMD_rlimit_stat:
23116 +               return vc_rlimit_stat(vxi, data);
23117 +
23118 +       case VCMD_set_cflags:
23119 +               return vc_set_cflags(vxi, data);
23120 +       case VCMD_get_cflags:
23121 +               return vc_get_cflags(vxi, data);
23122 +
23123 +       /* this is version 1 */
23124 +       case VCMD_set_ccaps:
23125 +               return vc_set_ccaps(vxi, data);
23126 +       /* this is version 1 */
23127 +       case VCMD_get_ccaps:
23128 +               return vc_get_ccaps(vxi, data);
23129 +       case VCMD_set_bcaps:
23130 +               return vc_set_bcaps(vxi, data);
23131 +       case VCMD_get_bcaps:
23132 +               return vc_get_bcaps(vxi, data);
23133 +
23134 +       case VCMD_set_badness:
23135 +               return vc_set_badness(vxi, data);
23136 +       case VCMD_get_badness:
23137 +               return vc_get_badness(vxi, data);
23138 +
23139 +       case VCMD_set_nflags:
23140 +               return vc_set_nflags(nxi, data);
23141 +       case VCMD_get_nflags:
23142 +               return vc_get_nflags(nxi, data);
23143 +
23144 +       case VCMD_set_ncaps:
23145 +               return vc_set_ncaps(nxi, data);
23146 +       case VCMD_get_ncaps:
23147 +               return vc_get_ncaps(nxi, data);
23148 +
23149 +       case VCMD_set_prio_bias:
23150 +               return vc_set_prio_bias(vxi, data);
23151 +       case VCMD_get_prio_bias:
23152 +               return vc_get_prio_bias(vxi, data);
23153 +       case VCMD_add_dlimit:
23154 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23155 +       case VCMD_rem_dlimit:
23156 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23157 +       case VCMD_set_dlimit:
23158 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23159 +       case VCMD_get_dlimit:
23160 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23161 +
23162 +       case VCMD_ctx_kill:
23163 +               return vc_ctx_kill(vxi, data);
23164 +
23165 +       case VCMD_wait_exit:
23166 +               return vc_wait_exit(vxi, data);
23167 +
23168 +       case VCMD_get_iattr:
23169 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23170 +       case VCMD_set_iattr:
23171 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23172 +
23173 +       case VCMD_fget_iattr:
23174 +               return vc_fget_iattr(id, data);
23175 +       case VCMD_fset_iattr:
23176 +               return vc_fset_iattr(id, data);
23177 +
23178 +       case VCMD_enter_space_v0:
23179 +               return vc_enter_space_v1(vxi, NULL);
23180 +       case VCMD_enter_space_v1:
23181 +               return vc_enter_space_v1(vxi, data);
23182 +       /* this is version 2 */
23183 +       case VCMD_enter_space:
23184 +               return vc_enter_space(vxi, data);
23185 +
23186 +       case VCMD_ctx_create_v0:
23187 +               return vc_ctx_create(id, NULL);
23188 +       case VCMD_ctx_create:
23189 +               return vc_ctx_create(id, data);
23190 +       case VCMD_ctx_migrate_v0:
23191 +               return vc_ctx_migrate(vxi, NULL);
23192 +       case VCMD_ctx_migrate:
23193 +               return vc_ctx_migrate(vxi, data);
23194 +
23195 +       case VCMD_net_create_v0:
23196 +               return vc_net_create(id, NULL);
23197 +       case VCMD_net_create:
23198 +               return vc_net_create(id, data);
23199 +       case VCMD_net_migrate:
23200 +               return vc_net_migrate(nxi, data);
23201 +
23202 +       case VCMD_tag_migrate:
23203 +               return vc_tag_migrate(id);
23204 +
23205 +       case VCMD_net_add:
23206 +               return vc_net_add(nxi, data);
23207 +       case VCMD_net_remove:
23208 +               return vc_net_remove(nxi, data);
23209 +
23210 +       case VCMD_net_add_ipv4_v1:
23211 +               return vc_net_add_ipv4_v1(nxi, data);
23212 +       /* this is version 2 */
23213 +       case VCMD_net_add_ipv4:
23214 +               return vc_net_add_ipv4(nxi, data);
23215 +
23216 +       case VCMD_net_rem_ipv4_v1:
23217 +               return vc_net_rem_ipv4_v1(nxi, data);
23218 +       /* this is version 2 */
23219 +       case VCMD_net_rem_ipv4:
23220 +               return vc_net_rem_ipv4(nxi, data);
23221 +#ifdef CONFIG_IPV6
23222 +       case VCMD_net_add_ipv6:
23223 +               return vc_net_add_ipv6(nxi, data);
23224 +       case VCMD_net_remove_ipv6:
23225 +               return vc_net_remove_ipv6(nxi, data);
23226 +#endif
23227 +/*     case VCMD_add_match_ipv4:
23228 +               return vc_add_match_ipv4(nxi, data);
23229 +       case VCMD_get_match_ipv4:
23230 +               return vc_get_match_ipv4(nxi, data);
23231 +#ifdef CONFIG_IPV6
23232 +       case VCMD_add_match_ipv6:
23233 +               return vc_add_match_ipv6(nxi, data);
23234 +       case VCMD_get_match_ipv6:
23235 +               return vc_get_match_ipv6(nxi, data);
23236 +#endif */
23237 +
23238 +#ifdef CONFIG_VSERVER_DEVICE
23239 +       case VCMD_set_mapping:
23240 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23241 +       case VCMD_unset_mapping:
23242 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23243 +#endif
23244 +#ifdef CONFIG_VSERVER_HISTORY
23245 +       case VCMD_dump_history:
23246 +               return vc_dump_history(id);
23247 +       case VCMD_read_history:
23248 +               return __COMPAT(vc_read_history, id, data, compat);
23249 +#endif
23250 +       default:
23251 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23252 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23253 +       }
23254 +       return -ENOSYS;
23255 +}
23256 +
23257 +
23258 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23259 +       case VCMD_ ## vcmd: perm = _perm;               \
23260 +               args = _args; flags = _flags; break
23261 +
23262 +
23263 +#define VCA_NONE       0x00
23264 +#define VCA_VXI                0x01
23265 +#define VCA_NXI                0x02
23266 +
23267 +#define VCF_NONE       0x00
23268 +#define VCF_INFO       0x01
23269 +#define VCF_ADMIN      0x02
23270 +#define VCF_ARES       0x06    /* includes admin */
23271 +#define VCF_SETUP      0x08
23272 +
23273 +#define VCF_ZIDOK      0x10    /* zero id okay */
23274 +
23275 +
23276 +static inline
23277 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23278 +{
23279 +       long ret;
23280 +       int permit = -1, state = 0;
23281 +       int perm = -1, args = 0, flags = 0;
23282 +       struct vx_info *vxi = NULL;
23283 +       struct nx_info *nxi = NULL;
23284 +
23285 +       switch (cmd) {
23286 +       /* unpriviledged commands */
23287 +       __VCMD(get_version,      0, VCA_NONE,   0);
23288 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23289 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23290 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23291 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23292 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23293 +
23294 +       /* info commands */
23295 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23296 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23297 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23298 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23299 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23300 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23301 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23302 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23303 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23304 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23305 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23306 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23307 +
23308 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23309 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23310 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23311 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23312 +
23313 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23314 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23315 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23316 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23317 +
23318 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23319 +
23320 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23321 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23322 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23323 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23324 +
23325 +       /* lower admin commands */
23326 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23327 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23328 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23329 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23330 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23331 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23332 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23333 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23334 +
23335 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23336 +       __VCMD(net_create,       5, VCA_NONE,   0);
23337 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23338 +
23339 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23340 +
23341 +       /* higher admin commands */
23342 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23343 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23344 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23345 +
23346 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23347 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23348 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23349 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23350 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23351 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23352 +
23353 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23354 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23355 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23356 +
23357 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23358 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23359 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23360 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23361 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23362 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23363 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23364 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23365 +#ifdef CONFIG_IPV6
23366 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23367 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23368 +#endif
23369 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23370 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23371 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23372 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23373 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23374 +
23375 +#ifdef CONFIG_VSERVER_DEVICE
23376 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23377 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23378 +#endif
23379 +       /* debug level admin commands */
23380 +#ifdef CONFIG_VSERVER_HISTORY
23381 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23382 +       __VCMD(read_history,     9, VCA_NONE,   0);
23383 +#endif
23384 +
23385 +       default:
23386 +               perm = -1;
23387 +       }
23388 +
23389 +       vxdprintk(VXD_CBIT(switch, 0),
23390 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23391 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23392 +               VC_VERSION(cmd), id, data, compat,
23393 +               perm, args, flags);
23394 +
23395 +       ret = -ENOSYS;
23396 +       if (perm < 0)
23397 +               goto out;
23398 +
23399 +       state = 1;
23400 +       if (!capable(CAP_CONTEXT))
23401 +               goto out;
23402 +
23403 +       state = 2;
23404 +       /* moved here from the individual commands */
23405 +       ret = -EPERM;
23406 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23407 +               goto out;
23408 +
23409 +       state = 3;
23410 +       /* vcmd involves resource management  */
23411 +       ret = -EPERM;
23412 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23413 +               goto out;
23414 +
23415 +       state = 4;
23416 +       /* various legacy exceptions */
23417 +       switch (cmd) {
23418 +       /* will go away when spectator is a cap */
23419 +       case VCMD_ctx_migrate_v0:
23420 +       case VCMD_ctx_migrate:
23421 +               if (id == 1) {
23422 +                       current->xid = 1;
23423 +                       ret = 1;
23424 +                       goto out;
23425 +               }
23426 +               break;
23427 +
23428 +       /* will go away when spectator is a cap */
23429 +       case VCMD_net_migrate:
23430 +               if (id == 1) {
23431 +                       current->nid = 1;
23432 +                       ret = 1;
23433 +                       goto out;
23434 +               }
23435 +               break;
23436 +       }
23437 +
23438 +       /* vcmds are fine by default */
23439 +       permit = 1;
23440 +
23441 +       /* admin type vcmds require admin ... */
23442 +       if (flags & VCF_ADMIN)
23443 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23444 +
23445 +       /* ... but setup type vcmds override that */
23446 +       if (!permit && (flags & VCF_SETUP))
23447 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23448 +
23449 +       state = 5;
23450 +       ret = -EPERM;
23451 +       if (!permit)
23452 +               goto out;
23453 +
23454 +       state = 6;
23455 +       if (!id && (flags & VCF_ZIDOK))
23456 +               goto skip_id;
23457 +
23458 +       ret = -ESRCH;
23459 +       if (args & VCA_VXI) {
23460 +               vxi = lookup_vx_info(id);
23461 +               if (!vxi)
23462 +                       goto out;
23463 +
23464 +               if ((flags & VCF_ADMIN) &&
23465 +                       /* special case kill for shutdown */
23466 +                       (cmd != VCMD_ctx_kill) &&
23467 +                       /* can context be administrated? */
23468 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23469 +                       ret = -EACCES;
23470 +                       goto out_vxi;
23471 +               }
23472 +       }
23473 +       state = 7;
23474 +       if (args & VCA_NXI) {
23475 +               nxi = lookup_nx_info(id);
23476 +               if (!nxi)
23477 +                       goto out_vxi;
23478 +
23479 +               if ((flags & VCF_ADMIN) &&
23480 +                       /* can context be administrated? */
23481 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23482 +                       ret = -EACCES;
23483 +                       goto out_nxi;
23484 +               }
23485 +       }
23486 +skip_id:
23487 +       state = 8;
23488 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23489 +
23490 +out_nxi:
23491 +       if ((args & VCA_NXI) && nxi)
23492 +               put_nx_info(nxi);
23493 +out_vxi:
23494 +       if ((args & VCA_VXI) && vxi)
23495 +               put_vx_info(vxi);
23496 +out:
23497 +       vxdprintk(VXD_CBIT(switch, 1),
23498 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23499 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23500 +               VC_VERSION(cmd), ret, ret, state, permit);
23501 +       return ret;
23502 +}
23503 +
23504 +asmlinkage long
23505 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23506 +{
23507 +       return do_vserver(cmd, id, data, 0);
23508 +}
23509 +
23510 +#ifdef CONFIG_COMPAT
23511 +
23512 +asmlinkage long
23513 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23514 +{
23515 +       return do_vserver(cmd, id, data, 1);
23516 +}
23517 +
23518 +#endif /* CONFIG_COMPAT */
23519 diff -NurpP --minimal linux-3.4.83/kernel/vserver/sysctl.c linux-3.4.83-vs2.3.3.9/kernel/vserver/sysctl.c
23520 --- linux-3.4.83/kernel/vserver/sysctl.c        1970-01-01 00:00:00.000000000 +0000
23521 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/sysctl.c      2012-05-21 16:15:05.000000000 +0000
23522 @@ -0,0 +1,247 @@
23523 +/*
23524 + *  kernel/vserver/sysctl.c
23525 + *
23526 + *  Virtual Context Support
23527 + *
23528 + *  Copyright (C) 2004-2007  Herbert Pötzl
23529 + *
23530 + *  V0.01  basic structure
23531 + *
23532 + */
23533 +
23534 +#include <linux/module.h>
23535 +#include <linux/ctype.h>
23536 +#include <linux/sysctl.h>
23537 +#include <linux/parser.h>
23538 +#include <asm/uaccess.h>
23539 +
23540 +enum {
23541 +       CTL_DEBUG_ERROR         = 0,
23542 +       CTL_DEBUG_SWITCH        = 1,
23543 +       CTL_DEBUG_XID,
23544 +       CTL_DEBUG_NID,
23545 +       CTL_DEBUG_TAG,
23546 +       CTL_DEBUG_NET,
23547 +       CTL_DEBUG_LIMIT,
23548 +       CTL_DEBUG_CRES,
23549 +       CTL_DEBUG_DLIM,
23550 +       CTL_DEBUG_QUOTA,
23551 +       CTL_DEBUG_CVIRT,
23552 +       CTL_DEBUG_SPACE,
23553 +       CTL_DEBUG_PERM,
23554 +       CTL_DEBUG_MISC,
23555 +};
23556 +
23557 +
23558 +unsigned int vs_debug_switch   = 0;
23559 +unsigned int vs_debug_xid      = 0;
23560 +unsigned int vs_debug_nid      = 0;
23561 +unsigned int vs_debug_tag      = 0;
23562 +unsigned int vs_debug_net      = 0;
23563 +unsigned int vs_debug_limit    = 0;
23564 +unsigned int vs_debug_cres     = 0;
23565 +unsigned int vs_debug_dlim     = 0;
23566 +unsigned int vs_debug_quota    = 0;
23567 +unsigned int vs_debug_cvirt    = 0;
23568 +unsigned int vs_debug_space    = 0;
23569 +unsigned int vs_debug_perm     = 0;
23570 +unsigned int vs_debug_misc     = 0;
23571 +
23572 +
23573 +static struct ctl_table_header *vserver_table_header;
23574 +static ctl_table vserver_root_table[];
23575 +
23576 +
23577 +void vserver_register_sysctl(void)
23578 +{
23579 +       if (!vserver_table_header) {
23580 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23581 +       }
23582 +
23583 +}
23584 +
23585 +void vserver_unregister_sysctl(void)
23586 +{
23587 +       if (vserver_table_header) {
23588 +               unregister_sysctl_table(vserver_table_header);
23589 +               vserver_table_header = NULL;
23590 +       }
23591 +}
23592 +
23593 +
23594 +static int proc_dodebug(ctl_table *table, int write,
23595 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23596 +{
23597 +       char            tmpbuf[20], *p, c;
23598 +       unsigned int    value;
23599 +       size_t          left, len;
23600 +
23601 +       if ((*ppos && !write) || !*lenp) {
23602 +               *lenp = 0;
23603 +               return 0;
23604 +       }
23605 +
23606 +       left = *lenp;
23607 +
23608 +       if (write) {
23609 +               if (!access_ok(VERIFY_READ, buffer, left))
23610 +                       return -EFAULT;
23611 +               p = (char *)buffer;
23612 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23613 +                       left--, p++;
23614 +               if (!left)
23615 +                       goto done;
23616 +
23617 +               if (left > sizeof(tmpbuf) - 1)
23618 +                       return -EINVAL;
23619 +               if (copy_from_user(tmpbuf, p, left))
23620 +                       return -EFAULT;
23621 +               tmpbuf[left] = '\0';
23622 +
23623 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23624 +                       value = 10 * value + (*p - '0');
23625 +               if (*p && !isspace(*p))
23626 +                       return -EINVAL;
23627 +               while (left && isspace(*p))
23628 +                       left--, p++;
23629 +               *(unsigned int *)table->data = value;
23630 +       } else {
23631 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23632 +                       return -EFAULT;
23633 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23634 +               if (len > left)
23635 +                       len = left;
23636 +               if (__copy_to_user(buffer, tmpbuf, len))
23637 +                       return -EFAULT;
23638 +               if ((left -= len) > 0) {
23639 +                       if (put_user('\n', (char *)buffer + len))
23640 +                               return -EFAULT;
23641 +                       left--;
23642 +               }
23643 +       }
23644 +
23645 +done:
23646 +       *lenp -= left;
23647 +       *ppos += *lenp;
23648 +       return 0;
23649 +}
23650 +
23651 +static int zero;
23652 +
23653 +#define        CTL_ENTRY(ctl, name)                            \
23654 +       {                                               \
23655 +               .procname       = #name,                \
23656 +               .data           = &vs_ ## name,         \
23657 +               .maxlen         = sizeof(int),          \
23658 +               .mode           = 0644,                 \
23659 +               .proc_handler   = &proc_dodebug,        \
23660 +               .extra1         = &zero,                \
23661 +               .extra2         = &zero,                \
23662 +       }
23663 +
23664 +static ctl_table vserver_debug_table[] = {
23665 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23666 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23667 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23668 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23669 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23670 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23671 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23672 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23673 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23674 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23675 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23676 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23677 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23678 +       { 0 }
23679 +};
23680 +
23681 +static ctl_table vserver_root_table[] = {
23682 +       {
23683 +               .procname       = "vserver",
23684 +               .mode           = 0555,
23685 +               .child          = vserver_debug_table
23686 +       },
23687 +       { 0 }
23688 +};
23689 +
23690 +
23691 +static match_table_t tokens = {
23692 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23693 +       { CTL_DEBUG_XID,        "xid=%x"        },
23694 +       { CTL_DEBUG_NID,        "nid=%x"        },
23695 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23696 +       { CTL_DEBUG_NET,        "net=%x"        },
23697 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23698 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23699 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23700 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23701 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23702 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23703 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23704 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23705 +       { CTL_DEBUG_ERROR,      NULL            }
23706 +};
23707 +
23708 +#define        HANDLE_CASE(id, name, val)                              \
23709 +       case CTL_DEBUG_ ## id:                                  \
23710 +               vs_debug_ ## name = val;                        \
23711 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23712 +               break
23713 +
23714 +
23715 +static int __init vs_debug_setup(char *str)
23716 +{
23717 +       char *p;
23718 +       int token;
23719 +
23720 +       printk("vs_debug_setup(%s)\n", str);
23721 +       while ((p = strsep(&str, ",")) != NULL) {
23722 +               substring_t args[MAX_OPT_ARGS];
23723 +               unsigned int value;
23724 +
23725 +               if (!*p)
23726 +                       continue;
23727 +
23728 +               token = match_token(p, tokens, args);
23729 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23730 +
23731 +               switch (token) {
23732 +               HANDLE_CASE(SWITCH, switch, value);
23733 +               HANDLE_CASE(XID,    xid,    value);
23734 +               HANDLE_CASE(NID,    nid,    value);
23735 +               HANDLE_CASE(TAG,    tag,    value);
23736 +               HANDLE_CASE(NET,    net,    value);
23737 +               HANDLE_CASE(LIMIT,  limit,  value);
23738 +               HANDLE_CASE(CRES,   cres,   value);
23739 +               HANDLE_CASE(DLIM,   dlim,   value);
23740 +               HANDLE_CASE(QUOTA,  quota,  value);
23741 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23742 +               HANDLE_CASE(SPACE,  space,  value);
23743 +               HANDLE_CASE(PERM,   perm,   value);
23744 +               HANDLE_CASE(MISC,   misc,   value);
23745 +               default:
23746 +                       return -EINVAL;
23747 +                       break;
23748 +               }
23749 +       }
23750 +       return 1;
23751 +}
23752 +
23753 +__setup("vsdebug=", vs_debug_setup);
23754 +
23755 +
23756 +
23757 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23758 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23759 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23760 +EXPORT_SYMBOL_GPL(vs_debug_net);
23761 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23762 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23763 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23764 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23765 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23766 +EXPORT_SYMBOL_GPL(vs_debug_space);
23767 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23768 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23769 +
23770 diff -NurpP --minimal linux-3.4.83/kernel/vserver/tag.c linux-3.4.83-vs2.3.3.9/kernel/vserver/tag.c
23771 --- linux-3.4.83/kernel/vserver/tag.c   1970-01-01 00:00:00.000000000 +0000
23772 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/tag.c 2012-05-21 16:15:05.000000000 +0000
23773 @@ -0,0 +1,63 @@
23774 +/*
23775 + *  linux/kernel/vserver/tag.c
23776 + *
23777 + *  Virtual Server: Shallow Tag Space
23778 + *
23779 + *  Copyright (C) 2007  Herbert Pötzl
23780 + *
23781 + *  V0.01  basic implementation
23782 + *
23783 + */
23784 +
23785 +#include <linux/sched.h>
23786 +#include <linux/vserver/debug.h>
23787 +#include <linux/vs_pid.h>
23788 +#include <linux/vs_tag.h>
23789 +
23790 +#include <linux/vserver/tag_cmd.h>
23791 +
23792 +
23793 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23794 +{
23795 +       if (!p)
23796 +               BUG();
23797 +
23798 +       vxdprintk(VXD_CBIT(tag, 5),
23799 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23800 +
23801 +       task_lock(p);
23802 +       p->tag = tag;
23803 +       task_unlock(p);
23804 +
23805 +       vxdprintk(VXD_CBIT(tag, 5),
23806 +               "moved task %p into [#%d]", p, tag);
23807 +       return 0;
23808 +}
23809 +
23810 +/* vserver syscall commands below here */
23811 +
23812 +/* taks xid and vx_info functions */
23813 +
23814 +
23815 +int vc_task_tag(uint32_t id)
23816 +{
23817 +       tag_t tag;
23818 +
23819 +       if (id) {
23820 +               struct task_struct *tsk;
23821 +               rcu_read_lock();
23822 +               tsk = find_task_by_real_pid(id);
23823 +               tag = (tsk) ? tsk->tag : -ESRCH;
23824 +               rcu_read_unlock();
23825 +       } else
23826 +               tag = dx_current_tag();
23827 +       return tag;
23828 +}
23829 +
23830 +
23831 +int vc_tag_migrate(uint32_t tag)
23832 +{
23833 +       return dx_migrate_task(current, tag & 0xFFFF);
23834 +}
23835 +
23836 +
23837 diff -NurpP --minimal linux-3.4.83/kernel/vserver/vci_config.h linux-3.4.83-vs2.3.3.9/kernel/vserver/vci_config.h
23838 --- linux-3.4.83/kernel/vserver/vci_config.h    1970-01-01 00:00:00.000000000 +0000
23839 +++ linux-3.4.83-vs2.3.3.9/kernel/vserver/vci_config.h  2012-05-21 16:15:05.000000000 +0000
23840 @@ -0,0 +1,76 @@
23841 +
23842 +/*  interface version */
23843 +
23844 +#define VCI_VERSION            0x00020308
23845 +
23846 +
23847 +enum {
23848 +       VCI_KCBIT_NO_DYNAMIC = 0,
23849 +
23850 +       VCI_KCBIT_PROC_SECURE = 4,
23851 +       /* VCI_KCBIT_HARDCPU = 5, */
23852 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23853 +       /* VCI_KCBIT_IDLETIME = 7, */
23854 +
23855 +       VCI_KCBIT_COWBL = 8,
23856 +       VCI_KCBIT_FULLCOWBL = 9,
23857 +       VCI_KCBIT_SPACES = 10,
23858 +       VCI_KCBIT_NETV2 = 11,
23859 +       VCI_KCBIT_MEMCG = 12,
23860 +
23861 +       VCI_KCBIT_DEBUG = 16,
23862 +       VCI_KCBIT_HISTORY = 20,
23863 +       VCI_KCBIT_TAGGED = 24,
23864 +       VCI_KCBIT_PPTAG = 28,
23865 +
23866 +       VCI_KCBIT_MORE = 31,
23867 +};
23868 +
23869 +
23870 +static inline uint32_t vci_kernel_config(void)
23871 +{
23872 +       return
23873 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23874 +
23875 +       /* configured features */
23876 +#ifdef CONFIG_VSERVER_PROC_SECURE
23877 +       (1 << VCI_KCBIT_PROC_SECURE) |
23878 +#endif
23879 +#ifdef CONFIG_VSERVER_COWBL
23880 +       (1 << VCI_KCBIT_COWBL) |
23881 +       (1 << VCI_KCBIT_FULLCOWBL) |
23882 +#endif
23883 +       (1 << VCI_KCBIT_SPACES) |
23884 +       (1 << VCI_KCBIT_NETV2) |
23885 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23886 +       (1 << VCI_KCBIT_MEMCG) |
23887 +#endif
23888 +
23889 +       /* debug options */
23890 +#ifdef CONFIG_VSERVER_DEBUG
23891 +       (1 << VCI_KCBIT_DEBUG) |
23892 +#endif
23893 +#ifdef CONFIG_VSERVER_HISTORY
23894 +       (1 << VCI_KCBIT_HISTORY) |
23895 +#endif
23896 +
23897 +       /* inode context tagging */
23898 +#if    defined(CONFIG_TAGGING_NONE)
23899 +       (0 << VCI_KCBIT_TAGGED) |
23900 +#elif  defined(CONFIG_TAGGING_UID16)
23901 +       (1 << VCI_KCBIT_TAGGED) |
23902 +#elif  defined(CONFIG_TAGGING_GID16)
23903 +       (2 << VCI_KCBIT_TAGGED) |
23904 +#elif  defined(CONFIG_TAGGING_ID24)
23905 +       (3 << VCI_KCBIT_TAGGED) |
23906 +#elif  defined(CONFIG_TAGGING_INTERN)
23907 +       (4 << VCI_KCBIT_TAGGED) |
23908 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23909 +       (5 << VCI_KCBIT_TAGGED) |
23910 +#else
23911 +       (7 << VCI_KCBIT_TAGGED) |
23912 +#endif
23913 +       (1 << VCI_KCBIT_PPTAG) |
23914 +       0;
23915 +}
23916 +
23917 diff -NurpP --minimal linux-3.4.83/mm/memcontrol.c linux-3.4.83-vs2.3.3.9/mm/memcontrol.c
23918 --- linux-3.4.83/mm/memcontrol.c        2014-03-12 09:48:23.000000000 +0000
23919 +++ linux-3.4.83-vs2.3.3.9/mm/memcontrol.c      2013-10-26 18:10:23.000000000 +0000
23920 @@ -846,6 +846,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23921                                 struct mem_cgroup, css);
23922  }
23923  
23924 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23925 +{
23926 +       return res_counter_read_u64(&mem->res, member);
23927 +}
23928 +
23929 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23930 +{
23931 +       return res_counter_read_u64(&mem->memsw, member);
23932 +}
23933 +
23934 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23935 +{
23936 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23937 +}
23938 +
23939 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23940 +{
23941 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23942 +}
23943 +
23944 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23945 +{
23946 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23947 +}
23948 +
23949  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23950  {
23951         struct mem_cgroup *memcg = NULL;
23952 diff -NurpP --minimal linux-3.4.83/mm/oom_kill.c linux-3.4.83-vs2.3.3.9/mm/oom_kill.c
23953 --- linux-3.4.83/mm/oom_kill.c  2014-03-12 09:48:23.000000000 +0000
23954 +++ linux-3.4.83-vs2.3.3.9/mm/oom_kill.c        2013-10-26 18:10:23.000000000 +0000
23955 @@ -35,6 +35,8 @@
23956  #include <linux/freezer.h>
23957  #include <linux/ftrace.h>
23958  #include <linux/ratelimit.h>
23959 +#include <linux/reboot.h>
23960 +#include <linux/vs_context.h>
23961  
23962  #define CREATE_TRACE_POINTS
23963  #include <trace/events/oom.h>
23964 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23965  static bool oom_unkillable_task(struct task_struct *p,
23966                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23967  {
23968 -       if (is_global_init(p))
23969 +       unsigned xid = vx_current_xid();
23970 +
23971 +       /* skip the init task, global and per guest */
23972 +       if (task_is_init(p))
23973                 return true;
23974         if (p->flags & PF_KTHREAD)
23975                 return true;
23976  
23977 +       /* skip other guest and host processes if oom in guest */
23978 +       if (xid && vx_task_xid(p) != xid)
23979 +               return true;
23980 +
23981         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23982         if (memcg && !task_in_mem_cgroup(p, memcg))
23983                 return true;
23984 @@ -462,8 +471,8 @@ static void oom_kill_process(struct task
23985                 dump_header(p, gfp_mask, order, memcg, nodemask);
23986  
23987         task_lock(p);
23988 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23989 -               message, task_pid_nr(p), p->comm, points);
23990 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23991 +               message, task_pid_nr(p), p->xid, p->comm, points);
23992         task_unlock(p);
23993  
23994         /*
23995 @@ -496,8 +505,8 @@ static void oom_kill_process(struct task
23996  
23997         /* mm cannot safely be dereferenced after task_unlock(victim) */
23998         mm = victim->mm;
23999 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24000 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
24001 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24002 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
24003                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
24004                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
24005         task_unlock(victim);
24006 @@ -596,6 +605,8 @@ int unregister_oom_notifier(struct notif
24007  }
24008  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24009  
24010 +long vs_oom_action(unsigned int);
24011 +
24012  /*
24013   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24014   * if a parallel OOM killing is already taking place that includes a zone in
24015 @@ -747,7 +758,12 @@ void out_of_memory(struct zonelist *zone
24016         if (!p) {
24017                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24018                 read_unlock(&tasklist_lock);
24019 -               panic("Out of memory and no killable processes...\n");
24020 +
24021 +               /* avoid panic for guest OOM */
24022 +               if (current->xid)
24023 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24024 +               else
24025 +                       panic("Out of memory and no killable processes...\n");
24026         }
24027         if (PTR_ERR(p) != -1UL) {
24028                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24029 diff -NurpP --minimal linux-3.4.83/mm/page_alloc.c linux-3.4.83-vs2.3.3.9/mm/page_alloc.c
24030 --- linux-3.4.83/mm/page_alloc.c        2014-03-12 09:48:23.000000000 +0000
24031 +++ linux-3.4.83-vs2.3.3.9/mm/page_alloc.c      2014-03-12 09:55:28.000000000 +0000
24032 @@ -58,6 +58,8 @@
24033  #include <linux/memcontrol.h>
24034  #include <linux/prefetch.h>
24035  #include <linux/page-debug-flags.h>
24036 +#include <linux/vs_base.h>
24037 +#include <linux/vs_limit.h>
24038  
24039  #include <asm/tlbflush.h>
24040  #include <asm/div64.h>
24041 @@ -2662,6 +2664,9 @@ void si_meminfo(struct sysinfo *val)
24042         val->totalhigh = totalhigh_pages;
24043         val->freehigh = nr_free_highpages();
24044         val->mem_unit = PAGE_SIZE;
24045 +
24046 +       if (vx_flags(VXF_VIRT_MEM, 0))
24047 +               vx_vsi_meminfo(val);
24048  }
24049  
24050  EXPORT_SYMBOL(si_meminfo);
24051 @@ -2682,6 +2687,9 @@ void si_meminfo_node(struct sysinfo *val
24052         val->freehigh = 0;
24053  #endif
24054         val->mem_unit = PAGE_SIZE;
24055 +
24056 +       if (vx_flags(VXF_VIRT_MEM, 0))
24057 +               vx_vsi_meminfo(val);
24058  }
24059  #endif
24060  
24061 diff -NurpP --minimal linux-3.4.83/mm/pgtable-generic.c linux-3.4.83-vs2.3.3.9/mm/pgtable-generic.c
24062 --- linux-3.4.83/mm/pgtable-generic.c   2012-05-21 16:07:35.000000000 +0000
24063 +++ linux-3.4.83-vs2.3.3.9/mm/pgtable-generic.c 2012-05-21 16:15:05.000000000 +0000
24064 @@ -6,6 +6,8 @@
24065   *  Copyright (C) 2010  Linus Torvalds
24066   */
24067  
24068 +#include <linux/mm.h>
24069 +
24070  #include <linux/pagemap.h>
24071  #include <asm/tlb.h>
24072  #include <asm-generic/pgtable.h>
24073 diff -NurpP --minimal linux-3.4.83/mm/shmem.c linux-3.4.83-vs2.3.3.9/mm/shmem.c
24074 --- linux-3.4.83/mm/shmem.c     2014-03-12 09:48:23.000000000 +0000
24075 +++ linux-3.4.83-vs2.3.3.9/mm/shmem.c   2013-03-02 15:26:44.000000000 +0000
24076 @@ -1473,7 +1473,7 @@ static int shmem_statfs(struct dentry *d
24077  {
24078         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24079  
24080 -       buf->f_type = TMPFS_MAGIC;
24081 +       buf->f_type = TMPFS_SUPER_MAGIC;
24082         buf->f_bsize = PAGE_CACHE_SIZE;
24083         buf->f_namelen = NAME_MAX;
24084         if (sbinfo->max_blocks) {
24085 @@ -2287,7 +2287,7 @@ int shmem_fill_super(struct super_block
24086         sb->s_maxbytes = MAX_LFS_FILESIZE;
24087         sb->s_blocksize = PAGE_CACHE_SIZE;
24088         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24089 -       sb->s_magic = TMPFS_MAGIC;
24090 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24091         sb->s_op = &shmem_ops;
24092         sb->s_time_gran = 1;
24093  #ifdef CONFIG_TMPFS_XATTR
24094 diff -NurpP --minimal linux-3.4.83/mm/slab.c linux-3.4.83-vs2.3.3.9/mm/slab.c
24095 --- linux-3.4.83/mm/slab.c      2014-03-12 09:48:23.000000000 +0000
24096 +++ linux-3.4.83-vs2.3.3.9/mm/slab.c    2012-10-22 13:09:53.000000000 +0000
24097 @@ -413,6 +413,8 @@ static void kmem_list3_init(struct kmem_
24098  #define STATS_INC_FREEMISS(x)  do { } while (0)
24099  #endif
24100  
24101 +#include "slab_vs.h"
24102 +
24103  #if DEBUG
24104  
24105  /*
24106 @@ -3466,6 +3468,7 @@ retry:
24107  
24108         obj = slab_get_obj(cachep, slabp, nodeid);
24109         check_slabp(cachep, slabp);
24110 +       vx_slab_alloc(cachep, flags);
24111         l3->free_objects--;
24112         /* move slabp to correct slabp list: */
24113         list_del(&slabp->list);
24114 @@ -3543,6 +3546,7 @@ __cache_alloc_node(struct kmem_cache *ca
24115         /* ___cache_alloc_node can fall back to other nodes */
24116         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24117    out:
24118 +       vx_slab_alloc(cachep, flags);
24119         local_irq_restore(save_flags);
24120         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24121         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24122 @@ -3730,6 +3734,7 @@ static inline void __cache_free(struct k
24123         check_irq_off();
24124         kmemleak_free_recursive(objp, cachep->flags);
24125         objp = cache_free_debugcheck(cachep, objp, caller);
24126 +       vx_slab_free(cachep);
24127  
24128         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24129  
24130 diff -NurpP --minimal linux-3.4.83/mm/slab_vs.h linux-3.4.83-vs2.3.3.9/mm/slab_vs.h
24131 --- linux-3.4.83/mm/slab_vs.h   1970-01-01 00:00:00.000000000 +0000
24132 +++ linux-3.4.83-vs2.3.3.9/mm/slab_vs.h 2012-05-21 16:15:05.000000000 +0000
24133 @@ -0,0 +1,29 @@
24134 +
24135 +#include <linux/vserver/context.h>
24136 +
24137 +#include <linux/vs_context.h>
24138 +
24139 +static inline
24140 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24141 +{
24142 +       int what = gfp_zone(cachep->gfpflags);
24143 +       struct vx_info *vxi = current_vx_info();
24144 +
24145 +       if (!vxi)
24146 +               return;
24147 +
24148 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24149 +}
24150 +
24151 +static inline
24152 +void vx_slab_free(struct kmem_cache *cachep)
24153 +{
24154 +       int what = gfp_zone(cachep->gfpflags);
24155 +       struct vx_info *vxi = current_vx_info();
24156 +
24157 +       if (!vxi)
24158 +               return;
24159 +
24160 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24161 +}
24162 +
24163 diff -NurpP --minimal linux-3.4.83/mm/swapfile.c linux-3.4.83-vs2.3.3.9/mm/swapfile.c
24164 --- linux-3.4.83/mm/swapfile.c  2014-03-12 09:48:23.000000000 +0000
24165 +++ linux-3.4.83-vs2.3.3.9/mm/swapfile.c        2012-06-28 14:45:07.000000000 +0000
24166 @@ -36,6 +36,7 @@
24167  #include <asm/tlbflush.h>
24168  #include <linux/swapops.h>
24169  #include <linux/page_cgroup.h>
24170 +#include <linux/vs_base.h>
24171  
24172  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24173                                  unsigned char);
24174 @@ -1754,6 +1755,16 @@ static int swap_show(struct seq_file *sw
24175  
24176         if (si == SEQ_START_TOKEN) {
24177                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24178 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24179 +                       struct sysinfo si;
24180 +
24181 +                       vx_vsi_swapinfo(&si);
24182 +                       if (si.totalswap < (1 << 10))
24183 +                               return 0;
24184 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24185 +                               "hdv0", "partition", si.totalswap >> 10,
24186 +                               (si.totalswap - si.freeswap) >> 10, -1);
24187 +               }
24188                 return 0;
24189         }
24190  
24191 @@ -2176,6 +2187,8 @@ void si_swapinfo(struct sysinfo *val)
24192         val->freeswap = nr_swap_pages + nr_to_be_unused;
24193         val->totalswap = total_swap_pages + nr_to_be_unused;
24194         spin_unlock(&swap_lock);
24195 +       if (vx_flags(VXF_VIRT_MEM, 0))
24196 +               vx_vsi_swapinfo(val);
24197  }
24198  
24199  /*
24200 diff -NurpP --minimal linux-3.4.83/net/bridge/br_multicast.c linux-3.4.83-vs2.3.3.9/net/bridge/br_multicast.c
24201 --- linux-3.4.83/net/bridge/br_multicast.c      2014-03-12 09:48:24.000000000 +0000
24202 +++ linux-3.4.83-vs2.3.3.9/net/bridge/br_multicast.c    2014-03-12 09:55:28.000000000 +0000
24203 @@ -445,7 +445,7 @@ static struct sk_buff *br_ip6_multicast_
24204         ip6h->hop_limit = 1;
24205         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24206         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24207 -                              &ip6h->saddr)) {
24208 +                              &ip6h->saddr, NULL)) {
24209                 kfree_skb(skb);
24210                 return NULL;
24211         }
24212 diff -NurpP --minimal linux-3.4.83/net/core/dev.c linux-3.4.83-vs2.3.3.9/net/core/dev.c
24213 --- linux-3.4.83/net/core/dev.c 2014-03-12 09:48:25.000000000 +0000
24214 +++ linux-3.4.83-vs2.3.3.9/net/core/dev.c       2014-03-12 09:55:28.000000000 +0000
24215 @@ -126,6 +126,7 @@
24216  #include <linux/in.h>
24217  #include <linux/jhash.h>
24218  #include <linux/random.h>
24219 +#include <linux/vs_inet.h>
24220  #include <trace/events/napi.h>
24221  #include <trace/events/net.h>
24222  #include <trace/events/skb.h>
24223 @@ -621,7 +622,8 @@ struct net_device *__dev_get_by_name(str
24224         struct hlist_head *head = dev_name_hash(net, name);
24225  
24226         hlist_for_each_entry(dev, p, head, name_hlist)
24227 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24228 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24229 +                   nx_dev_visible(current_nx_info(), dev))
24230                         return dev;
24231  
24232         return NULL;
24233 @@ -647,7 +649,8 @@ struct net_device *dev_get_by_name_rcu(s
24234         struct hlist_head *head = dev_name_hash(net, name);
24235  
24236         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24237 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24238 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24239 +                   nx_dev_visible(current_nx_info(), dev))
24240                         return dev;
24241  
24242         return NULL;
24243 @@ -698,7 +701,8 @@ struct net_device *__dev_get_by_index(st
24244         struct hlist_head *head = dev_index_hash(net, ifindex);
24245  
24246         hlist_for_each_entry(dev, p, head, index_hlist)
24247 -               if (dev->ifindex == ifindex)
24248 +               if ((dev->ifindex == ifindex) &&
24249 +                   nx_dev_visible(current_nx_info(), dev))
24250                         return dev;
24251  
24252         return NULL;
24253 @@ -716,7 +720,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24254   *     about locking. The caller must hold RCU lock.
24255   */
24256  
24257 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24258 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24259  {
24260         struct hlist_node *p;
24261         struct net_device *dev;
24262 @@ -728,6 +732,16 @@ struct net_device *dev_get_by_index_rcu(
24263  
24264         return NULL;
24265  }
24266 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24267 +
24268 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24269 +{
24270 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24271 +
24272 +       if (nx_dev_visible(current_nx_info(), dev))
24273 +               return dev;
24274 +       return NULL;
24275 +}
24276  EXPORT_SYMBOL(dev_get_by_index_rcu);
24277  
24278  
24279 @@ -776,7 +790,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24280  
24281         for_each_netdev_rcu(net, dev)
24282                 if (dev->type == type &&
24283 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24284 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24285 +                   nx_dev_visible(current_nx_info(), dev))
24286                         return dev;
24287  
24288         return NULL;
24289 @@ -788,9 +803,11 @@ struct net_device *__dev_getfirstbyhwtyp
24290         struct net_device *dev;
24291  
24292         ASSERT_RTNL();
24293 -       for_each_netdev(net, dev)
24294 -               if (dev->type == type)
24295 +       for_each_netdev(net, dev) {
24296 +               if ((dev->type == type) &&
24297 +                   nx_dev_visible(current_nx_info(), dev))
24298                         return dev;
24299 +       }
24300  
24301         return NULL;
24302  }
24303 @@ -908,6 +925,8 @@ static int __dev_alloc_name(struct net *
24304                                 continue;
24305                         if (i < 0 || i >= max_netdevices)
24306                                 continue;
24307 +                       if (!nx_dev_visible(current_nx_info(), d))
24308 +                               continue;
24309  
24310                         /*  avoid cases where sscanf is not exact inverse of printf */
24311                         snprintf(buf, IFNAMSIZ, name, i);
24312 @@ -4009,6 +4028,8 @@ static int dev_ifconf(struct net *net, c
24313  
24314         total = 0;
24315         for_each_netdev(net, dev) {
24316 +               if (!nx_dev_visible(current_nx_info(), dev))
24317 +                       continue;
24318                 for (i = 0; i < NPROTO; i++) {
24319                         if (gifconf_list[i]) {
24320                                 int done;
24321 @@ -4111,6 +4132,10 @@ static void dev_seq_printf_stats(struct
24322         struct rtnl_link_stats64 temp;
24323         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24324  
24325 +       /* device visible inside network context? */
24326 +       if (!nx_dev_visible(current_nx_info(), dev))
24327 +               return;
24328 +
24329         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24330                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24331                    dev->name, stats->rx_bytes, stats->rx_packets,
24332 diff -NurpP --minimal linux-3.4.83/net/core/rtnetlink.c linux-3.4.83-vs2.3.3.9/net/core/rtnetlink.c
24333 --- linux-3.4.83/net/core/rtnetlink.c   2014-03-12 09:48:25.000000000 +0000
24334 +++ linux-3.4.83-vs2.3.3.9/net/core/rtnetlink.c 2013-07-14 13:38:37.000000000 +0000
24335 @@ -1079,6 +1079,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24336                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24337                         if (idx < s_idx)
24338                                 goto cont;
24339 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24340 +                               continue;
24341                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24342                                              NETLINK_CB(cb->skb).pid,
24343                                              cb->nlh->nlmsg_seq, 0,
24344 @@ -1962,6 +1964,9 @@ void rtmsg_ifinfo(int type, struct net_d
24345         int err = -ENOBUFS;
24346         size_t if_info_size;
24347  
24348 +       if (!nx_dev_visible(current_nx_info(), dev))
24349 +               return;
24350 +
24351         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24352         if (skb == NULL)
24353                 goto errout;
24354 diff -NurpP --minimal linux-3.4.83/net/core/sock.c linux-3.4.83-vs2.3.3.9/net/core/sock.c
24355 --- linux-3.4.83/net/core/sock.c        2014-03-12 09:48:25.000000000 +0000
24356 +++ linux-3.4.83-vs2.3.3.9/net/core/sock.c      2014-03-12 09:55:28.000000000 +0000
24357 @@ -129,6 +129,10 @@
24358  #include <net/netprio_cgroup.h>
24359  
24360  #include <linux/filter.h>
24361 +#include <linux/vs_socket.h>
24362 +#include <linux/vs_limit.h>
24363 +#include <linux/vs_context.h>
24364 +#include <linux/vs_network.h>
24365  
24366  #include <trace/events/sock.h>
24367  
24368 @@ -1141,6 +1145,8 @@ static struct sock *sk_prot_alloc(struct
24369                         goto out_free_sec;
24370                 sk_tx_queue_clear(sk);
24371         }
24372 +               sock_vx_init(sk);
24373 +               sock_nx_init(sk);
24374  
24375         return sk;
24376  
24377 @@ -1249,6 +1255,11 @@ static void __sk_free(struct sock *sk)
24378                 put_cred(sk->sk_peer_cred);
24379         put_pid(sk->sk_peer_pid);
24380         put_net(sock_net(sk));
24381 +       vx_sock_dec(sk);
24382 +       clr_vx_info(&sk->sk_vx_info);
24383 +       sk->sk_xid = -1;
24384 +       clr_nx_info(&sk->sk_nx_info);
24385 +       sk->sk_nid = -1;
24386         sk_prot_free(sk->sk_prot_creator, sk);
24387  }
24388  
24389 @@ -1309,6 +1320,8 @@ struct sock *sk_clone_lock(const struct
24390  
24391                 /* SANITY */
24392                 get_net(sock_net(newsk));
24393 +               sock_vx_init(newsk);
24394 +               sock_nx_init(newsk);
24395                 sk_node_init(&newsk->sk_node);
24396                 sock_lock_init(newsk);
24397                 bh_lock_sock(newsk);
24398 @@ -1365,6 +1378,12 @@ struct sock *sk_clone_lock(const struct
24399                 smp_wmb();
24400                 atomic_set(&newsk->sk_refcnt, 2);
24401  
24402 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24403 +               newsk->sk_xid = sk->sk_xid;
24404 +               vx_sock_inc(newsk);
24405 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24406 +               newsk->sk_nid = sk->sk_nid;
24407 +
24408                 /*
24409                  * Increment the counter in the same struct proto as the master
24410                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24411 @@ -2121,6 +2140,12 @@ void sock_init_data(struct socket *sock,
24412  
24413         sk->sk_stamp = ktime_set(-1L, 0);
24414  
24415 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24416 +       sk->sk_xid = vx_current_xid();
24417 +       vx_sock_inc(sk);
24418 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24419 +       sk->sk_nid = nx_current_nid();
24420 +
24421         /*
24422          * Before updating sk_refcnt, we must commit prior changes to memory
24423          * (Documentation/RCU/rculist_nulls.txt for details)
24424 diff -NurpP --minimal linux-3.4.83/net/ipv4/af_inet.c linux-3.4.83-vs2.3.3.9/net/ipv4/af_inet.c
24425 --- linux-3.4.83/net/ipv4/af_inet.c     2014-03-12 09:48:25.000000000 +0000
24426 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/af_inet.c   2013-03-02 15:26:44.000000000 +0000
24427 @@ -118,6 +118,7 @@
24428  #ifdef CONFIG_IP_MROUTE
24429  #include <linux/mroute.h>
24430  #endif
24431 +#include <linux/vs_limit.h>
24432  
24433  
24434  /* The inetsw table contains everything that inet_create needs to
24435 @@ -332,9 +333,13 @@ lookup_protocol:
24436         }
24437  
24438         err = -EPERM;
24439 +       if ((protocol == IPPROTO_ICMP) &&
24440 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24441 +               goto override;
24442 +
24443         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24444                 goto out_rcu_unlock;
24445 -
24446 +override:
24447         err = -EAFNOSUPPORT;
24448         if (!inet_netns_ok(net, protocol))
24449                 goto out_rcu_unlock;
24450 @@ -459,6 +464,7 @@ int inet_bind(struct socket *sock, struc
24451         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24452         struct sock *sk = sock->sk;
24453         struct inet_sock *inet = inet_sk(sk);
24454 +       struct nx_v4_sock_addr nsa;
24455         unsigned short snum;
24456         int chk_addr_ret;
24457         int err;
24458 @@ -482,7 +488,11 @@ int inet_bind(struct socket *sock, struc
24459                         goto out;
24460         }
24461  
24462 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24463 +       err = v4_map_sock_addr(inet, addr, &nsa);
24464 +       if (err)
24465 +               goto out;
24466 +
24467 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24468  
24469         /* Not specified by any standard per-se, however it breaks too
24470          * many applications when removed.  It is unfortunate since
24471 @@ -494,7 +504,7 @@ int inet_bind(struct socket *sock, struc
24472         err = -EADDRNOTAVAIL;
24473         if (!sysctl_ip_nonlocal_bind &&
24474             !(inet->freebind || inet->transparent) &&
24475 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24476 +           nsa.saddr != htonl(INADDR_ANY) &&
24477             chk_addr_ret != RTN_LOCAL &&
24478             chk_addr_ret != RTN_MULTICAST &&
24479             chk_addr_ret != RTN_BROADCAST)
24480 @@ -519,7 +529,7 @@ int inet_bind(struct socket *sock, struc
24481         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24482                 goto out_release_sock;
24483  
24484 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24485 +       v4_set_sock_addr(inet, &nsa);
24486         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24487                 inet->inet_saddr = 0;  /* Use device */
24488  
24489 @@ -722,11 +732,13 @@ int inet_getname(struct socket *sock, st
24490                      peer == 1))
24491                         return -ENOTCONN;
24492                 sin->sin_port = inet->inet_dport;
24493 -               sin->sin_addr.s_addr = inet->inet_daddr;
24494 +               sin->sin_addr.s_addr =
24495 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24496         } else {
24497                 __be32 addr = inet->inet_rcv_saddr;
24498                 if (!addr)
24499                         addr = inet->inet_saddr;
24500 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24501                 sin->sin_port = inet->inet_sport;
24502                 sin->sin_addr.s_addr = addr;
24503         }
24504 diff -NurpP --minimal linux-3.4.83/net/ipv4/arp.c linux-3.4.83-vs2.3.3.9/net/ipv4/arp.c
24505 --- linux-3.4.83/net/ipv4/arp.c 2012-05-21 16:07:40.000000000 +0000
24506 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/arp.c       2012-05-21 16:15:05.000000000 +0000
24507 @@ -1328,6 +1328,7 @@ static void arp_format_neigh_entry(struc
24508         struct net_device *dev = n->dev;
24509         int hatype = dev->type;
24510  
24511 +       /* FIXME: check for network context */
24512         read_lock(&n->lock);
24513         /* Convert hardware address to XX:XX:XX:XX ... form. */
24514  #if IS_ENABLED(CONFIG_AX25)
24515 @@ -1359,6 +1360,7 @@ static void arp_format_pneigh_entry(stru
24516         int hatype = dev ? dev->type : 0;
24517         char tbuf[16];
24518  
24519 +       /* FIXME: check for network context */
24520         sprintf(tbuf, "%pI4", n->key);
24521         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24522                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24523 diff -NurpP --minimal linux-3.4.83/net/ipv4/devinet.c linux-3.4.83-vs2.3.3.9/net/ipv4/devinet.c
24524 --- linux-3.4.83/net/ipv4/devinet.c     2012-05-21 16:07:40.000000000 +0000
24525 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/devinet.c   2012-05-21 16:15:05.000000000 +0000
24526 @@ -517,6 +517,7 @@ struct in_device *inetdev_by_index(struc
24527  }
24528  EXPORT_SYMBOL(inetdev_by_index);
24529  
24530 +
24531  /* Called only from RTNL semaphored context. No locks. */
24532  
24533  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24534 @@ -758,6 +759,8 @@ int devinet_ioctl(struct net *net, unsig
24535  
24536         in_dev = __in_dev_get_rtnl(dev);
24537         if (in_dev) {
24538 +               struct nx_info *nxi = current_nx_info();
24539 +
24540                 if (tryaddrmatch) {
24541                         /* Matthias Andree */
24542                         /* compare label and address (4.4BSD style) */
24543 @@ -766,6 +769,8 @@ int devinet_ioctl(struct net *net, unsig
24544                            This is checked above. */
24545                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24546                              ifap = &ifa->ifa_next) {
24547 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24548 +                                       continue;
24549                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24550                                     sin_orig.sin_addr.s_addr ==
24551                                                         ifa->ifa_local) {
24552 @@ -778,9 +783,12 @@ int devinet_ioctl(struct net *net, unsig
24553                    comparing just the label */
24554                 if (!ifa) {
24555                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24556 -                            ifap = &ifa->ifa_next)
24557 +                            ifap = &ifa->ifa_next) {
24558 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24559 +                                       continue;
24560                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24561                                         break;
24562 +                       }
24563                 }
24564         }
24565  
24566 @@ -933,6 +941,8 @@ static int inet_gifconf(struct net_devic
24567                 goto out;
24568  
24569         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24570 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24571 +                       continue;
24572                 if (!buf) {
24573                         done += sizeof(ifr);
24574                         continue;
24575 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24576         struct net_device *dev;
24577         struct in_device *in_dev;
24578         struct in_ifaddr *ifa;
24579 +       struct sock *sk = skb->sk;
24580         struct hlist_head *head;
24581         struct hlist_node *node;
24582  
24583 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24584  
24585                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24586                              ifa = ifa->ifa_next, ip_idx++) {
24587 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24588 +                               continue;
24589                                 if (ip_idx < s_ip_idx)
24590                                         continue;
24591                                 if (inet_fill_ifaddr(skb, ifa,
24592 diff -NurpP --minimal linux-3.4.83/net/ipv4/fib_trie.c linux-3.4.83-vs2.3.3.9/net/ipv4/fib_trie.c
24593 --- linux-3.4.83/net/ipv4/fib_trie.c    2014-03-12 09:48:25.000000000 +0000
24594 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/fib_trie.c  2013-10-26 18:10:23.000000000 +0000
24595 @@ -2553,6 +2553,7 @@ static int fib_route_seq_show(struct seq
24596                             || fa->fa_type == RTN_MULTICAST)
24597                                 continue;
24598  
24599 +                       /* FIXME: check for network context? */
24600                         if (fi)
24601                                 seq_printf(seq,
24602                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24603 diff -NurpP --minimal linux-3.4.83/net/ipv4/inet_connection_sock.c linux-3.4.83-vs2.3.3.9/net/ipv4/inet_connection_sock.c
24604 --- linux-3.4.83/net/ipv4/inet_connection_sock.c        2014-03-12 09:48:25.000000000 +0000
24605 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/inet_connection_sock.c      2013-01-16 00:15:57.000000000 +0000
24606 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24607  }
24608  EXPORT_SYMBOL(inet_get_local_port_range);
24609  
24610 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24611 +{
24612 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24613 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24614 +
24615 +       if (inet_v6_ipv6only(sk2))
24616 +               return 0;
24617 +
24618 +       if (sk1_rcv_saddr &&
24619 +           sk2_rcv_saddr &&
24620 +           sk1_rcv_saddr == sk2_rcv_saddr)
24621 +               return 1;
24622 +
24623 +       if (sk1_rcv_saddr &&
24624 +           !sk2_rcv_saddr &&
24625 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24626 +               return 1;
24627 +
24628 +       if (sk2_rcv_saddr &&
24629 +           !sk1_rcv_saddr &&
24630 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24631 +               return 1;
24632 +
24633 +       if (!sk1_rcv_saddr &&
24634 +           !sk2_rcv_saddr &&
24635 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24636 +               return 1;
24637 +
24638 +       return 0;
24639 +}
24640 +
24641  int inet_csk_bind_conflict(const struct sock *sk,
24642                            const struct inet_bind_bucket *tb)
24643  {
24644 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct
24645                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24646                         if (!reuse || !sk2->sk_reuse ||
24647                             sk2->sk_state == TCP_LISTEN) {
24648 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24649 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24650 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24651 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24652                                         break;
24653                         }
24654                 }
24655 diff -NurpP --minimal linux-3.4.83/net/ipv4/inet_diag.c linux-3.4.83-vs2.3.3.9/net/ipv4/inet_diag.c
24656 --- linux-3.4.83/net/ipv4/inet_diag.c   2014-03-12 09:48:25.000000000 +0000
24657 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/inet_diag.c 2014-03-12 09:58:38.000000000 +0000
24658 @@ -31,6 +31,8 @@
24659  
24660  #include <linux/inet.h>
24661  #include <linux/stddef.h>
24662 +#include <linux/vs_network.h>
24663 +#include <linux/vs_inet.h>
24664  
24665  #include <linux/inet_diag.h>
24666  #include <linux/sock_diag.h>
24667 @@ -114,8 +116,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24668         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24669         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24670  
24671 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24672 -       r->id.idiag_dst[0] = inet->inet_daddr;
24673 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24674 +               inet->inet_rcv_saddr);
24675 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24676 +               inet->inet_daddr);
24677  
24678         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24679          * hence this needs to be included regardless of socket family.
24680 @@ -241,8 +245,8 @@ static int inet_twsk_diag_fill(struct in
24681         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24682         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24683  
24684 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24685 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24686 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24687 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24688  
24689         r->idiag_state        = tw->tw_substate;
24690         r->idiag_timer        = 3;
24691 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24692  
24693         err = -EINVAL;
24694         if (req->sdiag_family == AF_INET) {
24695 +               /* TODO: lback */
24696                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24697                                  req->id.idiag_dport, req->id.idiag_src[0],
24698                                  req->id.idiag_sport, req->id.idiag_if);
24699         }
24700  #if IS_ENABLED(CONFIG_IPV6)
24701         else if (req->sdiag_family == AF_INET6) {
24702 +               /* TODO: lback */
24703                 sk = inet6_lookup(&init_net, hashinfo,
24704                                   (struct in6_addr *)req->id.idiag_dst,
24705                                   req->id.idiag_dport,
24706 @@ -493,6 +499,7 @@ int inet_diag_bc_sk(const struct nlattr
24707         } else
24708  #endif
24709         {
24710 +                       /* TODO: lback */
24711                 entry.saddr = &inet->inet_rcv_saddr;
24712                 entry.daddr = &inet->inet_daddr;
24713         }
24714 @@ -650,6 +657,7 @@ static int inet_twsk_diag_dump(struct in
24715                 } else
24716  #endif
24717                 {
24718 +                       /* TODO: lback */
24719                         entry.saddr = &tw->tw_rcv_saddr;
24720                         entry.daddr = &tw->tw_daddr;
24721                 }
24722 @@ -729,8 +737,8 @@ static int inet_diag_fill_req(struct sk_
24723         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24724         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24725  
24726 -       r->id.idiag_src[0] = ireq->loc_addr;
24727 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24728 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24729 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24730  
24731         r->idiag_expires = jiffies_to_msecs(tmo);
24732         r->idiag_rqueue = 0;
24733 @@ -800,6 +808,7 @@ static int inet_diag_dump_reqs(struct sk
24734                                 continue;
24735  
24736                         if (bc) {
24737 +                               /* TODO: lback */
24738                                 inet_diag_req_addrs(sk, req, &entry);
24739                                 entry.dport = ntohs(ireq->rmt_port);
24740  
24741 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24742                         sk_nulls_for_each(sk, node, &ilb->head) {
24743                                 struct inet_sock *inet = inet_sk(sk);
24744  
24745 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24746 +                                       continue;
24747                                 if (num < s_num) {
24748                                         num++;
24749                                         continue;
24750 @@ -920,6 +931,8 @@ skip_listen_ht:
24751                 sk_nulls_for_each(sk, node, &head->chain) {
24752                         struct inet_sock *inet = inet_sk(sk);
24753  
24754 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24755 +                               continue;
24756                         if (num < s_num)
24757                                 goto next_normal;
24758                         if (!(r->idiag_states & (1 << sk->sk_state)))
24759 @@ -947,6 +960,8 @@ next_normal:
24760                         inet_twsk_for_each(tw, node,
24761                                     &head->twchain) {
24762  
24763 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24764 +                                       continue;
24765                                 if (num < s_num)
24766                                         goto next_dying;
24767                                 if (!(r->idiag_states & (1 << tw->tw_substate)))
24768 diff -NurpP --minimal linux-3.4.83/net/ipv4/inet_hashtables.c linux-3.4.83-vs2.3.3.9/net/ipv4/inet_hashtables.c
24769 --- linux-3.4.83/net/ipv4/inet_hashtables.c     2014-03-12 09:48:25.000000000 +0000
24770 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/inet_hashtables.c   2014-03-12 09:55:28.000000000 +0000
24771 @@ -22,6 +22,7 @@
24772  #include <net/inet_connection_sock.h>
24773  #include <net/inet_hashtables.h>
24774  #include <net/secure_seq.h>
24775 +#include <net/route.h>
24776  #include <net/ip.h>
24777  
24778  /*
24779 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24780                         if (rcv_saddr != daddr)
24781                                 return -1;
24782                         score += 2;
24783 +               } else {
24784 +                       /* block non nx_info ips */
24785 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24786 +                               daddr, NXA_MASK_BIND))
24787 +                               return -1;
24788                 }
24789                 if (sk->sk_bound_dev_if) {
24790                         if (sk->sk_bound_dev_if != dif)
24791 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24792   * wildcarded during the search since they can never be otherwise.
24793   */
24794  
24795 -
24796  struct sock *__inet_lookup_listener(struct net *net,
24797                                     struct inet_hashinfo *hashinfo,
24798                                     const __be32 daddr, const unsigned short hnum,
24799 @@ -196,6 +201,7 @@ begin:
24800                         hiscore = score;
24801                 }
24802         }
24803 +
24804         /*
24805          * if the nulls value we got at the end of this lookup is
24806          * not the expected one, we must restart lookup.
24807 diff -NurpP --minimal linux-3.4.83/net/ipv4/netfilter/nf_nat_helper.c linux-3.4.83-vs2.3.3.9/net/ipv4/netfilter/nf_nat_helper.c
24808 --- linux-3.4.83/net/ipv4/netfilter/nf_nat_helper.c     2012-03-19 18:47:33.000000000 +0000
24809 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/netfilter/nf_nat_helper.c   2012-05-21 16:15:05.000000000 +0000
24810 @@ -20,6 +20,7 @@
24811  #include <net/route.h>
24812  
24813  #include <linux/netfilter_ipv4.h>
24814 +#include <net/route.h>
24815  #include <net/netfilter/nf_conntrack.h>
24816  #include <net/netfilter/nf_conntrack_helper.h>
24817  #include <net/netfilter/nf_conntrack_ecache.h>
24818 diff -NurpP --minimal linux-3.4.83/net/ipv4/netfilter.c linux-3.4.83-vs2.3.3.9/net/ipv4/netfilter.c
24819 --- linux-3.4.83/net/ipv4/netfilter.c   2012-01-09 15:15:03.000000000 +0000
24820 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/netfilter.c 2012-05-21 16:15:05.000000000 +0000
24821 @@ -6,7 +6,7 @@
24822  #include <linux/skbuff.h>
24823  #include <linux/gfp.h>
24824  #include <linux/export.h>
24825 -#include <net/route.h>
24826 +// #include <net/route.h>
24827  #include <net/xfrm.h>
24828  #include <net/ip.h>
24829  #include <net/netfilter/nf_queue.h>
24830 diff -NurpP --minimal linux-3.4.83/net/ipv4/raw.c linux-3.4.83-vs2.3.3.9/net/ipv4/raw.c
24831 --- linux-3.4.83/net/ipv4/raw.c 2014-03-12 09:48:26.000000000 +0000
24832 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/raw.c       2014-03-12 09:55:28.000000000 +0000
24833 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24834  
24835                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24836                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24837 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24838 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24839                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24840                         goto found; /* gotcha */
24841         }
24842 @@ -392,6 +392,12 @@ static int raw_send_hdrinc(struct sock *
24843                 icmp_out_count(net, ((struct icmphdr *)
24844                         skb_transport_header(skb))->type);
24845  
24846 +       err = -EPERM;
24847 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24848 +               sk->sk_nx_info &&
24849 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24850 +               goto error_free;
24851 +
24852         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24853                       rt->dst.dev, dst_output);
24854         if (err > 0)
24855 @@ -577,6 +583,16 @@ static int raw_sendmsg(struct kiocb *ioc
24856                         goto done;
24857         }
24858  
24859 +       if (sk->sk_nx_info) {
24860 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24861 +               if (IS_ERR(rt)) {
24862 +                       err = PTR_ERR(rt);
24863 +                       rt = NULL;
24864 +                       goto done;
24865 +               }
24866 +               ip_rt_put(rt);
24867 +       }
24868 +
24869         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24870         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24871         if (IS_ERR(rt)) {
24872 @@ -653,17 +669,19 @@ static int raw_bind(struct sock *sk, str
24873  {
24874         struct inet_sock *inet = inet_sk(sk);
24875         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24876 +       struct nx_v4_sock_addr nsa = { 0 };
24877         int ret = -EINVAL;
24878         int chk_addr_ret;
24879  
24880         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24881                 goto out;
24882 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24883 +       v4_map_sock_addr(inet, addr, &nsa);
24884 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24885         ret = -EADDRNOTAVAIL;
24886 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24887 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24888             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24889                 goto out;
24890 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24891 +       v4_set_sock_addr(inet, &nsa);
24892         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24893                 inet->inet_saddr = 0;  /* Use device */
24894         sk_dst_reset(sk);
24895 @@ -712,7 +730,8 @@ static int raw_recvmsg(struct kiocb *ioc
24896         /* Copy the address. */
24897         if (sin) {
24898                 sin->sin_family = AF_INET;
24899 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24900 +               sin->sin_addr.s_addr =
24901 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24902                 sin->sin_port = 0;
24903                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24904                 *addr_len = sizeof(*sin);
24905 @@ -909,7 +928,8 @@ static struct sock *raw_get_first(struct
24906                 struct hlist_node *node;
24907  
24908                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24909 -                       if (sock_net(sk) == seq_file_net(seq))
24910 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24911 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24912                                 goto found;
24913         }
24914         sk = NULL;
24915 @@ -925,7 +945,8 @@ static struct sock *raw_get_next(struct
24916                 sk = sk_next(sk);
24917  try_again:
24918                 ;
24919 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24920 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24921 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24922  
24923         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24924                 sk = sk_head(&state->h->ht[state->bucket]);
24925 diff -NurpP --minimal linux-3.4.83/net/ipv4/route.c linux-3.4.83-vs2.3.3.9/net/ipv4/route.c
24926 --- linux-3.4.83/net/ipv4/route.c       2014-03-12 09:48:26.000000000 +0000
24927 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/route.c     2014-03-12 09:55:28.000000000 +0000
24928 @@ -2696,7 +2696,7 @@ static struct rtable *ip_route_output_sl
24929  
24930  
24931         if (fl4->flowi4_oif) {
24932 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24933 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24934                 rth = ERR_PTR(-ENODEV);
24935                 if (dev_out == NULL)
24936                         goto out;
24937 diff -NurpP --minimal linux-3.4.83/net/ipv4/tcp.c linux-3.4.83-vs2.3.3.9/net/ipv4/tcp.c
24938 --- linux-3.4.83/net/ipv4/tcp.c 2014-03-12 09:48:28.000000000 +0000
24939 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/tcp.c       2013-07-14 13:38:37.000000000 +0000
24940 @@ -268,6 +268,7 @@
24941  #include <linux/crypto.h>
24942  #include <linux/time.h>
24943  #include <linux/slab.h>
24944 +#include <linux/in.h>
24945  
24946  #include <net/icmp.h>
24947  #include <net/tcp.h>
24948 diff -NurpP --minimal linux-3.4.83/net/ipv4/tcp_ipv4.c linux-3.4.83-vs2.3.3.9/net/ipv4/tcp_ipv4.c
24949 --- linux-3.4.83/net/ipv4/tcp_ipv4.c    2014-03-12 09:48:28.000000000 +0000
24950 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/tcp_ipv4.c  2014-03-12 09:55:28.000000000 +0000
24951 @@ -2037,6 +2037,12 @@ static void *listening_get_next(struct s
24952                 req = req->dl_next;
24953                 while (1) {
24954                         while (req) {
24955 +                               vxdprintk(VXD_CBIT(net, 6),
24956 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24957 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24958 +                               if (req->sk &&
24959 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24960 +                                       continue;
24961                                 if (req->rsk_ops->family == st->family) {
24962                                         cur = req;
24963                                         goto out;
24964 @@ -2061,6 +2067,10 @@ get_req:
24965         }
24966  get_sk:
24967         sk_nulls_for_each_from(sk, node) {
24968 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24969 +                       sk, sk->sk_nid, nx_current_nid());
24970 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24971 +                       continue;
24972                 if (!net_eq(sock_net(sk), net))
24973                         continue;
24974                 if (sk->sk_family == st->family) {
24975 @@ -2137,6 +2147,11 @@ static void *established_get_first(struc
24976  
24977                 spin_lock_bh(lock);
24978                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24979 +                       vxdprintk(VXD_CBIT(net, 6),
24980 +                               "sk,egf: %p [#%d] (from %d)",
24981 +                               sk, sk->sk_nid, nx_current_nid());
24982 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24983 +                               continue;
24984                         if (sk->sk_family != st->family ||
24985                             !net_eq(sock_net(sk), net)) {
24986                                 continue;
24987 @@ -2147,6 +2162,11 @@ static void *established_get_first(struc
24988                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24989                 inet_twsk_for_each(tw, node,
24990                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24991 +                       vxdprintk(VXD_CBIT(net, 6),
24992 +                               "tw: %p [#%d] (from %d)",
24993 +                               tw, tw->tw_nid, nx_current_nid());
24994 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24995 +                               continue;
24996                         if (tw->tw_family != st->family ||
24997                             !net_eq(twsk_net(tw), net)) {
24998                                 continue;
24999 @@ -2176,7 +2196,9 @@ static void *established_get_next(struct
25000                 tw = cur;
25001                 tw = tw_next(tw);
25002  get_tw:
25003 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25004 +               while (tw && (tw->tw_family != st->family ||
25005 +                       !net_eq(twsk_net(tw), net) ||
25006 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25007                         tw = tw_next(tw);
25008                 }
25009                 if (tw) {
25010 @@ -2200,6 +2222,11 @@ get_tw:
25011                 sk = sk_nulls_next(sk);
25012  
25013         sk_nulls_for_each_from(sk, node) {
25014 +               vxdprintk(VXD_CBIT(net, 6),
25015 +                       "sk,egn: %p [#%d] (from %d)",
25016 +                       sk, sk->sk_nid, nx_current_nid());
25017 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25018 +                       continue;
25019                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25020                         goto found;
25021         }
25022 @@ -2405,9 +2432,9 @@ static void get_openreq4(const struct so
25023         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25024                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25025                 i,
25026 -               ireq->loc_addr,
25027 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25028                 ntohs(inet_sk(sk)->inet_sport),
25029 -               ireq->rmt_addr,
25030 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25031                 ntohs(ireq->rmt_port),
25032                 TCP_SYN_RECV,
25033                 0, 0, /* could print option size, but that is af dependent. */
25034 @@ -2429,8 +2456,8 @@ static void get_tcp4_sock(struct sock *s
25035         const struct tcp_sock *tp = tcp_sk(sk);
25036         const struct inet_connection_sock *icsk = inet_csk(sk);
25037         const struct inet_sock *inet = inet_sk(sk);
25038 -       __be32 dest = inet->inet_daddr;
25039 -       __be32 src = inet->inet_rcv_saddr;
25040 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25041 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25042         __u16 destp = ntohs(inet->inet_dport);
25043         __u16 srcp = ntohs(inet->inet_sport);
25044         int rx_queue;
25045 @@ -2487,8 +2514,8 @@ static void get_timewait4_sock(const str
25046         if (ttd < 0)
25047                 ttd = 0;
25048  
25049 -       dest  = tw->tw_daddr;
25050 -       src   = tw->tw_rcv_saddr;
25051 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
25052 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
25053         destp = ntohs(tw->tw_dport);
25054         srcp  = ntohs(tw->tw_sport);
25055  
25056 diff -NurpP --minimal linux-3.4.83/net/ipv4/tcp_minisocks.c linux-3.4.83-vs2.3.3.9/net/ipv4/tcp_minisocks.c
25057 --- linux-3.4.83/net/ipv4/tcp_minisocks.c       2012-05-21 16:07:40.000000000 +0000
25058 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/tcp_minisocks.c     2012-05-21 16:15:05.000000000 +0000
25059 @@ -23,6 +23,9 @@
25060  #include <linux/slab.h>
25061  #include <linux/sysctl.h>
25062  #include <linux/workqueue.h>
25063 +#include <linux/vs_limit.h>
25064 +#include <linux/vs_socket.h>
25065 +#include <linux/vs_context.h>
25066  #include <net/tcp.h>
25067  #include <net/inet_common.h>
25068  #include <net/xfrm.h>
25069 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int
25070                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25071                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25072  
25073 +               tw->tw_xid              = sk->sk_xid;
25074 +               tw->tw_vx_info          = NULL;
25075 +               tw->tw_nid              = sk->sk_nid;
25076 +               tw->tw_nx_info          = NULL;
25077 +
25078  #if IS_ENABLED(CONFIG_IPV6)
25079                 if (tw->tw_family == PF_INET6) {
25080                         struct ipv6_pinfo *np = inet6_sk(sk);
25081 diff -NurpP --minimal linux-3.4.83/net/ipv4/udp.c linux-3.4.83-vs2.3.3.9/net/ipv4/udp.c
25082 --- linux-3.4.83/net/ipv4/udp.c 2014-03-12 09:48:28.000000000 +0000
25083 +++ linux-3.4.83-vs2.3.3.9/net/ipv4/udp.c       2014-03-12 09:55:28.000000000 +0000
25084 @@ -298,14 +298,7 @@ fail:
25085  }
25086  EXPORT_SYMBOL(udp_lib_get_port);
25087  
25088 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25089 -{
25090 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25091 -
25092 -       return  (!ipv6_only_sock(sk2)  &&
25093 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25094 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25095 -}
25096 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25097  
25098  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25099                                        unsigned int port)
25100 @@ -340,6 +333,11 @@ static inline int compute_score(struct s
25101                         if (inet->inet_rcv_saddr != daddr)
25102                                 return -1;
25103                         score += 2;
25104 +               } else {
25105 +                       /* block non nx_info ips */
25106 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25107 +                               daddr, NXA_MASK_BIND))
25108 +                               return -1;
25109                 }
25110                 if (inet->inet_daddr) {
25111                         if (inet->inet_daddr != saddr)
25112 @@ -443,6 +441,7 @@ exact_match:
25113         return result;
25114  }
25115  
25116 +
25117  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25118   * harder than this. -DaveM
25119   */
25120 @@ -488,6 +487,11 @@ begin:
25121         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25122                 score = compute_score(sk, net, saddr, hnum, sport,
25123                                       daddr, dport, dif);
25124 +               /* FIXME: disabled?
25125 +               if (score == 9) {
25126 +                       result = sk;
25127 +                       break;
25128 +               } else */
25129                 if (score > badness) {
25130                         result = sk;
25131                         badness = score;
25132 @@ -501,6 +505,7 @@ begin:
25133         if (get_nulls_value(node) != slot)
25134                 goto begin;
25135  
25136 +
25137         if (result) {
25138                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25139                         result = NULL;
25140 @@ -510,6 +515,7 @@ begin:
25141                         goto begin;
25142                 }
25143         }
25144 +
25145         rcu_read_unlock();
25146         return result;
25147  }
25148 @@ -553,8 +559,7 @@ static inline struct sock *udp_v4_mcast_
25149                     udp_sk(s)->udp_port_hash != hnum ||
25150                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25151                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25152 -                   (inet->inet_rcv_saddr &&
25153 -                    inet->inet_rcv_saddr != loc_addr) ||
25154 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25155                     ipv6_only_sock(s) ||
25156                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25157                         continue;
25158 @@ -934,6 +939,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25159                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25160                                    faddr, saddr, dport, inet->inet_sport);
25161  
25162 +               if (sk->sk_nx_info) {
25163 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25164 +                       if (IS_ERR(rt)) {
25165 +                               err = PTR_ERR(rt);
25166 +                               rt = NULL;
25167 +                               goto out;
25168 +                       }
25169 +                       ip_rt_put(rt);
25170 +               }
25171 +
25172                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25173                 rt = ip_route_output_flow(net, fl4, sk);
25174                 if (IS_ERR(rt)) {
25175 @@ -1229,7 +1244,8 @@ try_again:
25176         if (sin) {
25177                 sin->sin_family = AF_INET;
25178                 sin->sin_port = udp_hdr(skb)->source;
25179 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25180 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25181 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25182                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25183                 *addr_len = sizeof(*sin);
25184         }
25185 @@ -1969,6 +1985,8 @@ static struct sock *udp_get_first(struct
25186                 sk_nulls_for_each(sk, node, &hslot->head) {
25187                         if (!net_eq(sock_net(sk), net))
25188                                 continue;
25189 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25190 +                               continue;
25191                         if (sk->sk_family == state->family)
25192                                 goto found;
25193                 }
25194 @@ -1986,7 +2004,9 @@ static struct sock *udp_get_next(struct
25195  
25196         do {
25197                 sk = sk_nulls_next(sk);
25198 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25199 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25200 +               sk->sk_family != state->family ||
25201 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25202  
25203         if (!sk) {
25204                 if (state->bucket <= state->udp_table->mask)
25205 @@ -2082,8 +2102,8 @@ static void udp4_format_sock(struct sock
25206                 int bucket, int *len)
25207  {
25208         struct inet_sock *inet = inet_sk(sp);
25209 -       __be32 dest = inet->inet_daddr;
25210 -       __be32 src  = inet->inet_rcv_saddr;
25211 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25212 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25213         __u16 destp       = ntohs(inet->inet_dport);
25214         __u16 srcp        = ntohs(inet->inet_sport);
25215  
25216 diff -NurpP --minimal linux-3.4.83/net/ipv6/Kconfig linux-3.4.83-vs2.3.3.9/net/ipv6/Kconfig
25217 --- linux-3.4.83/net/ipv6/Kconfig       2010-08-02 14:52:59.000000000 +0000
25218 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/Kconfig     2012-05-21 16:15:05.000000000 +0000
25219 @@ -4,8 +4,8 @@
25220  
25221  #   IPv6 as module will cause a CRASH if you try to unload it
25222  menuconfig IPV6
25223 -       tristate "The IPv6 protocol"
25224 -       default m
25225 +       bool "The IPv6 protocol"
25226 +       default n
25227         ---help---
25228           This is complemental support for the IP version 6.
25229           You will still be able to do traditional IPv4 networking as well.
25230 diff -NurpP --minimal linux-3.4.83/net/ipv6/addrconf.c linux-3.4.83-vs2.3.3.9/net/ipv6/addrconf.c
25231 --- linux-3.4.83/net/ipv6/addrconf.c    2014-03-12 09:48:28.000000000 +0000
25232 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/addrconf.c  2013-10-26 18:10:23.000000000 +0000
25233 @@ -88,6 +88,8 @@
25234  #include <linux/proc_fs.h>
25235  #include <linux/seq_file.h>
25236  #include <linux/export.h>
25237 +#include <linux/vs_network.h>
25238 +#include <linux/vs_inet6.h>
25239  
25240  /* Set to 3 to get tracing... */
25241  #define ACONF_DEBUG 2
25242 @@ -1106,7 +1108,7 @@ out:
25243  
25244  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25245                        const struct in6_addr *daddr, unsigned int prefs,
25246 -                      struct in6_addr *saddr)
25247 +                      struct in6_addr *saddr, struct nx_info *nxi)
25248  {
25249         struct ipv6_saddr_score scores[2],
25250                                 *score = &scores[0], *hiscore = &scores[1];
25251 @@ -1178,6 +1180,8 @@ int ipv6_dev_get_saddr(struct net *net,
25252                                                dev->name);
25253                                 continue;
25254                         }
25255 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25256 +                               continue;
25257  
25258                         score->rule = -1;
25259                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25260 @@ -3204,7 +3208,10 @@ static void if6_seq_stop(struct seq_file
25261  static int if6_seq_show(struct seq_file *seq, void *v)
25262  {
25263         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25264 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25265 +
25266 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25267 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25268 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25269                    &ifp->addr,
25270                    ifp->idev->dev->ifindex,
25271                    ifp->prefix_len,
25272 @@ -3710,6 +3717,11 @@ static int in6_dump_addrs(struct inet6_d
25273         struct ifacaddr6 *ifaca;
25274         int err = 1;
25275         int ip_idx = *p_ip_idx;
25276 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25277 +
25278 +       /* disable ipv6 on non v6 guests */
25279 +       if (nxi && !nx_info_has_v6(nxi))
25280 +               return skb->len;
25281  
25282         read_lock_bh(&idev->lock);
25283         switch (type) {
25284 @@ -3720,6 +3732,8 @@ static int in6_dump_addrs(struct inet6_d
25285                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25286                         if (++ip_idx < s_ip_idx)
25287                                 continue;
25288 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25289 +                                       continue;
25290                         err = inet6_fill_ifaddr(skb, ifa,
25291                                                 NETLINK_CB(cb->skb).pid,
25292                                                 cb->nlh->nlmsg_seq,
25293 @@ -3736,6 +3750,8 @@ static int in6_dump_addrs(struct inet6_d
25294                      ifmca = ifmca->next, ip_idx++) {
25295                         if (ip_idx < s_ip_idx)
25296                                 continue;
25297 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25298 +                                       continue;
25299                         err = inet6_fill_ifmcaddr(skb, ifmca,
25300                                                   NETLINK_CB(cb->skb).pid,
25301                                                   cb->nlh->nlmsg_seq,
25302 @@ -3751,6 +3767,8 @@ static int in6_dump_addrs(struct inet6_d
25303                      ifaca = ifaca->aca_next, ip_idx++) {
25304                         if (ip_idx < s_ip_idx)
25305                                 continue;
25306 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25307 +                                       continue;
25308                         err = inet6_fill_ifacaddr(skb, ifaca,
25309                                                   NETLINK_CB(cb->skb).pid,
25310                                                   cb->nlh->nlmsg_seq,
25311 @@ -4136,6 +4154,11 @@ static int inet6_dump_ifinfo(struct sk_b
25312         struct inet6_dev *idev;
25313         struct hlist_head *head;
25314         struct hlist_node *node;
25315 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25316 +
25317 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25318 +       if (skb->sk && skb->sk->sk_vx_info)
25319 +               return skb->len; */
25320  
25321         s_h = cb->args[0];
25322         s_idx = cb->args[1];
25323 @@ -4147,6 +4170,8 @@ static int inet6_dump_ifinfo(struct sk_b
25324                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25325                         if (idx < s_idx)
25326                                 goto cont;
25327 +                       if (!v6_dev_in_nx_info(dev, nxi))
25328 +                               goto cont;
25329                         idev = __in6_dev_get(dev);
25330                         if (!idev)
25331                                 goto cont;
25332 diff -NurpP --minimal linux-3.4.83/net/ipv6/af_inet6.c linux-3.4.83-vs2.3.3.9/net/ipv6/af_inet6.c
25333 --- linux-3.4.83/net/ipv6/af_inet6.c    2012-05-21 16:07:40.000000000 +0000
25334 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/af_inet6.c  2012-09-01 09:15:04.000000000 +0000
25335 @@ -42,6 +42,8 @@
25336  #include <linux/netdevice.h>
25337  #include <linux/icmpv6.h>
25338  #include <linux/netfilter_ipv6.h>
25339 +#include <linux/vs_inet.h>
25340 +#include <linux/vs_inet6.h>
25341  
25342  #include <net/ip.h>
25343  #include <net/ipv6.h>
25344 @@ -159,9 +161,12 @@ lookup_protocol:
25345         }
25346  
25347         err = -EPERM;
25348 +       if ((protocol == IPPROTO_ICMPV6) &&
25349 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25350 +               goto override;
25351         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25352                 goto out_rcu_unlock;
25353 -
25354 +override:
25355         sock->ops = answer->ops;
25356         answer_prot = answer->prot;
25357         answer_no_check = answer->no_check;
25358 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25359         struct inet_sock *inet = inet_sk(sk);
25360         struct ipv6_pinfo *np = inet6_sk(sk);
25361         struct net *net = sock_net(sk);
25362 +       struct nx_v6_sock_addr nsa;
25363         __be32 v4addr = 0;
25364         unsigned short snum;
25365         int addr_type = 0;
25366 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25367         if (addr->sin6_family != AF_INET6)
25368                 return -EAFNOSUPPORT;
25369  
25370 +       err = v6_map_sock_addr(inet, addr, &nsa);
25371 +       if (err)
25372 +               return err;
25373 +
25374         addr_type = ipv6_addr_type(&addr->sin6_addr);
25375         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25376                 return -EINVAL;
25377 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25378                 /* Reproduce AF_INET checks to make the bindings consistent */
25379                 v4addr = addr->sin6_addr.s6_addr32[3];
25380                 chk_addr_ret = inet_addr_type(net, v4addr);
25381 +
25382                 if (!sysctl_ip_nonlocal_bind &&
25383                     !(inet->freebind || inet->transparent) &&
25384                     v4addr != htonl(INADDR_ANY) &&
25385 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25386                         err = -EADDRNOTAVAIL;
25387                         goto out;
25388                 }
25389 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25390 +                       err = -EADDRNOTAVAIL;
25391 +                       goto out;
25392 +               }
25393         } else {
25394                 if (addr_type != IPV6_ADDR_ANY) {
25395                         struct net_device *dev = NULL;
25396 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25397                                 }
25398                         }
25399  
25400 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25401 +                               err = -EADDRNOTAVAIL;
25402 +                               goto out_unlock;
25403 +                       }
25404 +
25405                         /* ipv4 addr of the socket is invalid.  Only the
25406                          * unspecified and mapped address have a v4 equivalent.
25407                          */
25408 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25409                 }
25410         }
25411  
25412 +       /* what's that for? */
25413 +       v6_set_sock_addr(inet, &nsa);
25414 +
25415         inet->inet_rcv_saddr = v4addr;
25416         inet->inet_saddr = v4addr;
25417  
25418 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25419                         return -ENOTCONN;
25420                 sin->sin6_port = inet->inet_dport;
25421                 sin->sin6_addr = np->daddr;
25422 +               /* FIXME: remap lback? */
25423                 if (np->sndflow)
25424                         sin->sin6_flowinfo = np->flow_label;
25425         } else {
25426 +               /* FIXME: remap lback? */
25427                 if (ipv6_addr_any(&np->rcv_saddr))
25428                         sin->sin6_addr = np->saddr;
25429                 else
25430 diff -NurpP --minimal linux-3.4.83/net/ipv6/datagram.c linux-3.4.83-vs2.3.3.9/net/ipv6/datagram.c
25431 --- linux-3.4.83/net/ipv6/datagram.c    2014-03-12 09:48:28.000000000 +0000
25432 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/datagram.c  2014-03-12 09:55:28.000000000 +0000
25433 @@ -646,7 +646,7 @@ int datagram_send_ctl(struct net *net, s
25434  
25435                         rcu_read_lock();
25436                         if (fl6->flowi6_oif) {
25437 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25438 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25439                                 if (!dev) {
25440                                         rcu_read_unlock();
25441                                         return -ENODEV;
25442 diff -NurpP --minimal linux-3.4.83/net/ipv6/fib6_rules.c linux-3.4.83-vs2.3.3.9/net/ipv6/fib6_rules.c
25443 --- linux-3.4.83/net/ipv6/fib6_rules.c  2012-03-19 18:47:33.000000000 +0000
25444 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/fib6_rules.c        2012-05-21 16:15:05.000000000 +0000
25445 @@ -91,7 +91,7 @@ static int fib6_rule_action(struct fib_r
25446                                                ip6_dst_idev(&rt->dst)->dev,
25447                                                &flp6->daddr,
25448                                                rt6_flags2srcprefs(flags),
25449 -                                              &saddr))
25450 +                                              &saddr, NULL))
25451                                 goto again;
25452                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25453                                                r->src.plen))
25454 diff -NurpP --minimal linux-3.4.83/net/ipv6/inet6_hashtables.c linux-3.4.83-vs2.3.3.9/net/ipv6/inet6_hashtables.c
25455 --- linux-3.4.83/net/ipv6/inet6_hashtables.c    2014-03-12 09:48:28.000000000 +0000
25456 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/inet6_hashtables.c  2014-03-12 09:55:28.000000000 +0000
25457 @@ -16,6 +16,7 @@
25458  
25459  #include <linux/module.h>
25460  #include <linux/random.h>
25461 +#include <linux/vs_inet6.h>
25462  
25463  #include <net/inet_connection_sock.h>
25464  #include <net/inet_hashtables.h>
25465 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25466         unsigned int slot = hash & hashinfo->ehash_mask;
25467         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25468  
25469 -
25470         rcu_read_lock();
25471  begin:
25472         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25473 @@ -95,7 +95,7 @@ begin:
25474                                 sock_put(sk);
25475                                 goto begin;
25476                         }
25477 -               goto out;
25478 +                       goto out;
25479                 }
25480         }
25481         if (get_nulls_value(node) != slot)
25482 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25483                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25484                                 return -1;
25485                         score++;
25486 +               } else {
25487 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25488 +                               return -1;
25489                 }
25490                 if (sk->sk_bound_dev_if) {
25491                         if (sk->sk_bound_dev_if != dif)
25492 diff -NurpP --minimal linux-3.4.83/net/ipv6/ip6_output.c linux-3.4.83-vs2.3.3.9/net/ipv6/ip6_output.c
25493 --- linux-3.4.83/net/ipv6/ip6_output.c  2014-03-12 09:48:28.000000000 +0000
25494 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/ip6_output.c        2014-03-12 09:55:28.000000000 +0000
25495 @@ -983,7 +983,8 @@ static int ip6_dst_lookup_tail(struct so
25496                 struct rt6_info *rt = (struct rt6_info *) *dst;
25497                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25498                                           sk ? inet6_sk(sk)->srcprefs : 0,
25499 -                                         &fl6->saddr);
25500 +                                         &fl6->saddr,
25501 +                                         sk ? sk->sk_nx_info : NULL);
25502                 if (err)
25503                         goto out_err_release;
25504         }
25505 diff -NurpP --minimal linux-3.4.83/net/ipv6/ndisc.c linux-3.4.83-vs2.3.3.9/net/ipv6/ndisc.c
25506 --- linux-3.4.83/net/ipv6/ndisc.c       2014-03-12 09:48:28.000000000 +0000
25507 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/ndisc.c     2013-10-26 18:10:23.000000000 +0000
25508 @@ -577,7 +577,7 @@ static void ndisc_send_na(struct net_dev
25509         } else {
25510                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25511                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25512 -                                      &tmpaddr))
25513 +                                      &tmpaddr, NULL))
25514                         return;
25515                 src_addr = &tmpaddr;
25516         }
25517 diff -NurpP --minimal linux-3.4.83/net/ipv6/raw.c linux-3.4.83-vs2.3.3.9/net/ipv6/raw.c
25518 --- linux-3.4.83/net/ipv6/raw.c 2014-03-12 09:48:28.000000000 +0000
25519 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/raw.c       2014-03-12 09:55:28.000000000 +0000
25520 @@ -30,6 +30,7 @@
25521  #include <linux/icmpv6.h>
25522  #include <linux/netfilter.h>
25523  #include <linux/netfilter_ipv6.h>
25524 +#include <linux/vs_inet6.h>
25525  #include <linux/skbuff.h>
25526  #include <linux/compat.h>
25527  #include <asm/uaccess.h>
25528 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25529                                 goto out_unlock;
25530                 }
25531  
25532 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25533 +                       err = -EADDRNOTAVAIL;
25534 +                       if (dev)
25535 +                               dev_put(dev);
25536 +                       goto out;
25537 +               }
25538 +
25539                 /* ipv4 addr of the socket is invalid.  Only the
25540                  * unspecified and mapped address have a v4 equivalent.
25541                  */
25542 diff -NurpP --minimal linux-3.4.83/net/ipv6/route.c linux-3.4.83-vs2.3.3.9/net/ipv6/route.c
25543 --- linux-3.4.83/net/ipv6/route.c       2014-03-12 09:48:28.000000000 +0000
25544 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/route.c     2014-03-12 09:55:28.000000000 +0000
25545 @@ -55,6 +55,7 @@
25546  #include <net/xfrm.h>
25547  #include <net/netevent.h>
25548  #include <net/netlink.h>
25549 +#include <linux/vs_inet6.h>
25550  
25551  #include <asm/uaccess.h>
25552  
25553 @@ -2152,15 +2153,17 @@ int ip6_route_get_saddr(struct net *net,
25554                         struct rt6_info *rt,
25555                         const struct in6_addr *daddr,
25556                         unsigned int prefs,
25557 -                       struct in6_addr *saddr)
25558 +                       struct in6_addr *saddr,
25559 +                       struct nx_info *nxi)
25560  {
25561         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25562         int err = 0;
25563 -       if (rt->rt6i_prefsrc.plen)
25564 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25565 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25566                 *saddr = rt->rt6i_prefsrc.addr;
25567         else
25568                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25569 -                                        daddr, prefs, saddr);
25570 +                                        daddr, prefs, saddr, nxi);
25571         return err;
25572  }
25573  
25574 @@ -2491,7 +2494,8 @@ static int rt6_fill_node(struct net *net
25575                         NLA_PUT_U32(skb, RTA_IIF, iif);
25576         } else if (dst) {
25577                 struct in6_addr saddr_buf;
25578 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25579 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25580 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25581                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25582         }
25583  
25584 @@ -2718,6 +2722,7 @@ static int rt6_info_route(struct rt6_inf
25585         struct seq_file *m = p_arg;
25586         struct neighbour *n;
25587  
25588 +       /* FIXME: check for network context? */
25589         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25590  
25591  #ifdef CONFIG_IPV6_SUBTREES
25592 diff -NurpP --minimal linux-3.4.83/net/ipv6/tcp_ipv6.c linux-3.4.83-vs2.3.3.9/net/ipv6/tcp_ipv6.c
25593 --- linux-3.4.83/net/ipv6/tcp_ipv6.c    2014-03-12 09:48:28.000000000 +0000
25594 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/tcp_ipv6.c  2013-10-26 18:10:23.000000000 +0000
25595 @@ -71,6 +71,7 @@
25596  
25597  #include <linux/crypto.h>
25598  #include <linux/scatterlist.h>
25599 +#include <linux/vs_inet6.h>
25600  
25601  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25602  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25603 @@ -163,8 +164,15 @@ static int tcp_v6_connect(struct sock *s
25604          *      connect() to INADDR_ANY means loopback (BSD'ism).
25605          */
25606  
25607 -       if(ipv6_addr_any(&usin->sin6_addr))
25608 -               usin->sin6_addr.s6_addr[15] = 0x1;
25609 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25610 +               struct nx_info *nxi =  sk->sk_nx_info;
25611 +
25612 +               if (nxi && nx_info_has_v6(nxi))
25613 +                       /* FIXME: remap lback? */
25614 +                       usin->sin6_addr = nxi->v6.ip;
25615 +               else
25616 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25617 +       }
25618  
25619         addr_type = ipv6_addr_type(&usin->sin6_addr);
25620  
25621 diff -NurpP --minimal linux-3.4.83/net/ipv6/udp.c linux-3.4.83-vs2.3.3.9/net/ipv6/udp.c
25622 --- linux-3.4.83/net/ipv6/udp.c 2014-03-12 09:48:28.000000000 +0000
25623 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/udp.c       2014-03-12 09:55:28.000000000 +0000
25624 @@ -45,41 +45,67 @@
25625  #include <net/tcp_states.h>
25626  #include <net/ip6_checksum.h>
25627  #include <net/xfrm.h>
25628 +#include <linux/vs_inet6.h>
25629  
25630  #include <linux/proc_fs.h>
25631  #include <linux/seq_file.h>
25632  #include "udp_impl.h"
25633  
25634 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25635 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25636  {
25637 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25638 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25639         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25640 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25641 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25642         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25643 -       int sk_ipv6only = ipv6_only_sock(sk);
25644 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25645         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25646 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25647 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25648         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25649  
25650         /* if both are mapped, treat as IPv4 */
25651 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25652 -               return (!sk2_ipv6only &&
25653 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25654 +               if (!sk2_ipv6only &&
25655                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25656 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25657 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25658 +                       goto vs_v4;
25659 +               else
25660 +                       return 0;
25661 +       }
25662  
25663         if (addr_type2 == IPV6_ADDR_ANY &&
25664             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25665 -               return 1;
25666 +               goto vs;
25667  
25668         if (addr_type == IPV6_ADDR_ANY &&
25669 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25670 -               return 1;
25671 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25672 +               goto vs;
25673  
25674         if (sk2_rcv_saddr6 &&
25675 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25676 -               return 1;
25677 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25678 +               goto vs;
25679  
25680         return 0;
25681 +
25682 +vs_v4:
25683 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25684 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25685 +       if (!sk2_rcv_saddr)
25686 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25687 +       if (!sk1_rcv_saddr)
25688 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25689 +       return 1;
25690 +vs:
25691 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25692 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25693 +       else if (addr_type2 == IPV6_ADDR_ANY)
25694 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25695 +       else if (addr_type == IPV6_ADDR_ANY) {
25696 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25697 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25698 +               else
25699 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25700 +       }
25701 +       return 1;
25702  }
25703  
25704  static unsigned int udp6_portaddr_hash(struct net *net,
25705 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25706                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25707                                 return -1;
25708                         score++;
25709 +               } else {
25710 +                       /* block non nx_info ips */
25711 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25712 +                               return -1;
25713                 }
25714                 if (!ipv6_addr_any(&np->daddr)) {
25715                         if (!ipv6_addr_equal(&np->daddr, saddr))
25716 diff -NurpP --minimal linux-3.4.83/net/ipv6/xfrm6_policy.c linux-3.4.83-vs2.3.3.9/net/ipv6/xfrm6_policy.c
25717 --- linux-3.4.83/net/ipv6/xfrm6_policy.c        2014-03-12 09:48:28.000000000 +0000
25718 +++ linux-3.4.83-vs2.3.3.9/net/ipv6/xfrm6_policy.c      2013-07-14 13:38:37.000000000 +0000
25719 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25720         dev = ip6_dst_idev(dst)->dev;
25721         ipv6_dev_get_saddr(dev_net(dev), dev,
25722                            (struct in6_addr *)&daddr->a6, 0,
25723 -                          (struct in6_addr *)&saddr->a6);
25724 +                          (struct in6_addr *)&saddr->a6, NULL);
25725         dst_release(dst);
25726         return 0;
25727  }
25728 diff -NurpP --minimal linux-3.4.83/net/netfilter/ipvs/ip_vs_xmit.c linux-3.4.83-vs2.3.3.9/net/netfilter/ipvs/ip_vs_xmit.c
25729 --- linux-3.4.83/net/netfilter/ipvs/ip_vs_xmit.c        2014-03-12 09:48:29.000000000 +0000
25730 +++ linux-3.4.83-vs2.3.3.9/net/netfilter/ipvs/ip_vs_xmit.c      2013-10-26 18:10:23.000000000 +0000
25731 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25732                 return dst;
25733         if (ipv6_addr_any(&fl6.saddr) &&
25734             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25735 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25736 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25737                 goto out_err;
25738         if (do_xfrm) {
25739                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25740 diff -NurpP --minimal linux-3.4.83/net/netlink/af_netlink.c linux-3.4.83-vs2.3.3.9/net/netlink/af_netlink.c
25741 --- linux-3.4.83/net/netlink/af_netlink.c       2014-03-12 09:48:29.000000000 +0000
25742 +++ linux-3.4.83-vs2.3.3.9/net/netlink/af_netlink.c     2014-03-12 09:55:29.000000000 +0000
25743 @@ -55,6 +55,9 @@
25744  #include <linux/types.h>
25745  #include <linux/audit.h>
25746  #include <linux/mutex.h>
25747 +#include <linux/vs_context.h>
25748 +#include <linux/vs_network.h>
25749 +#include <linux/vs_limit.h>
25750  
25751  #include <net/net_namespace.h>
25752  #include <net/sock.h>
25753 @@ -1949,6 +1952,8 @@ static struct sock *netlink_seq_socket_i
25754                         sk_for_each(s, node, &hash->table[j]) {
25755                                 if (sock_net(s) != seq_file_net(seq))
25756                                         continue;
25757 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25758 +                                       continue;
25759                                 if (off == pos) {
25760                                         iter->link = i;
25761                                         iter->hash_idx = j;
25762 @@ -1983,7 +1988,8 @@ static void *netlink_seq_next(struct seq
25763         s = v;
25764         do {
25765                 s = sk_next(s);
25766 -       } while (s && sock_net(s) != seq_file_net(seq));
25767 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25768 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25769         if (s)
25770                 return s;
25771  
25772 @@ -1995,7 +2001,8 @@ static void *netlink_seq_next(struct seq
25773  
25774                 for (; j <= hash->mask; j++) {
25775                         s = sk_head(&hash->table[j]);
25776 -                       while (s && sock_net(s) != seq_file_net(seq))
25777 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25778 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25779                                 s = sk_next(s);
25780                         if (s) {
25781                                 iter->link = i;
25782 diff -NurpP --minimal linux-3.4.83/net/socket.c linux-3.4.83-vs2.3.3.9/net/socket.c
25783 --- linux-3.4.83/net/socket.c   2014-03-12 09:48:30.000000000 +0000
25784 +++ linux-3.4.83-vs2.3.3.9/net/socket.c 2014-03-12 09:55:29.000000000 +0000
25785 @@ -98,6 +98,10 @@
25786  
25787  #include <net/sock.h>
25788  #include <linux/netfilter.h>
25789 +#include <linux/vs_base.h>
25790 +#include <linux/vs_socket.h>
25791 +#include <linux/vs_inet.h>
25792 +#include <linux/vs_inet6.h>
25793  
25794  #include <linux/if_tun.h>
25795  #include <linux/ipv6_route.h>
25796 @@ -552,6 +556,7 @@ static inline int __sock_sendmsg_nosec(s
25797                                        struct msghdr *msg, size_t size)
25798  {
25799         struct sock_iocb *si = kiocb_to_siocb(iocb);
25800 +       size_t len;
25801  
25802         sock_update_classid(sock->sk);
25803  
25804 @@ -562,7 +567,22 @@ static inline int __sock_sendmsg_nosec(s
25805         si->msg = msg;
25806         si->size = size;
25807  
25808 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25809 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25810 +       if (sock->sk) {
25811 +               if (len == size)
25812 +                       vx_sock_send(sock->sk, size);
25813 +               else
25814 +                       vx_sock_fail(sock->sk, size);
25815 +       }
25816 +       vxdprintk(VXD_CBIT(net, 7),
25817 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25818 +               sock, sock->sk,
25819 +               (sock->sk)?sock->sk->sk_nx_info:0,
25820 +               (sock->sk)?sock->sk->sk_vx_info:0,
25821 +               (sock->sk)?sock->sk->sk_xid:0,
25822 +               (sock->sk)?sock->sk->sk_nid:0,
25823 +               (unsigned int)size, len);
25824 +       return len;
25825  }
25826  
25827  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25828 @@ -718,6 +738,7 @@ static inline int __sock_recvmsg_nosec(s
25829                                        struct msghdr *msg, size_t size, int flags)
25830  {
25831         struct sock_iocb *si = kiocb_to_siocb(iocb);
25832 +       int len;
25833  
25834         sock_update_classid(sock->sk);
25835  
25836 @@ -727,7 +748,18 @@ static inline int __sock_recvmsg_nosec(s
25837         si->size = size;
25838         si->flags = flags;
25839  
25840 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25841 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25842 +       if ((len >= 0) && sock->sk)
25843 +               vx_sock_recv(sock->sk, len);
25844 +       vxdprintk(VXD_CBIT(net, 7),
25845 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25846 +               sock, sock->sk,
25847 +               (sock->sk)?sock->sk->sk_nx_info:0,
25848 +               (sock->sk)?sock->sk->sk_vx_info:0,
25849 +               (sock->sk)?sock->sk->sk_xid:0,
25850 +               (sock->sk)?sock->sk->sk_nid:0,
25851 +               (unsigned int)size, len);
25852 +       return len;
25853  }
25854  
25855  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25856 @@ -1212,6 +1244,13 @@ int __sock_create(struct net *net, int f
25857         if (type < 0 || type >= SOCK_MAX)
25858                 return -EINVAL;
25859  
25860 +       if (!nx_check(0, VS_ADMIN)) {
25861 +               if (family == PF_INET && !current_nx_info_has_v4())
25862 +                       return -EAFNOSUPPORT;
25863 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25864 +                       return -EAFNOSUPPORT;
25865 +       }
25866 +
25867         /* Compatibility.
25868  
25869            This uglymoron is moved from INET layer to here to avoid
25870 @@ -1347,6 +1386,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25871         if (retval < 0)
25872                 goto out;
25873  
25874 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25875         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25876         if (retval < 0)
25877                 goto out_release;
25878 @@ -1388,10 +1428,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25879         err = sock_create(family, type, protocol, &sock1);
25880         if (err < 0)
25881                 goto out;
25882 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25883  
25884         err = sock_create(family, type, protocol, &sock2);
25885         if (err < 0)
25886                 goto out_release_1;
25887 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25888  
25889         err = sock1->ops->socketpair(sock1, sock2);
25890         if (err < 0)
25891 diff -NurpP --minimal linux-3.4.83/net/sunrpc/auth.c linux-3.4.83-vs2.3.3.9/net/sunrpc/auth.c
25892 --- linux-3.4.83/net/sunrpc/auth.c      2011-10-24 16:45:34.000000000 +0000
25893 +++ linux-3.4.83-vs2.3.3.9/net/sunrpc/auth.c    2012-05-21 16:15:05.000000000 +0000
25894 @@ -14,6 +14,7 @@
25895  #include <linux/hash.h>
25896  #include <linux/sunrpc/clnt.h>
25897  #include <linux/spinlock.h>
25898 +#include <linux/vs_tag.h>
25899  
25900  #ifdef RPC_DEBUG
25901  # define RPCDBG_FACILITY       RPCDBG_AUTH
25902 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25903         memset(&acred, 0, sizeof(acred));
25904         acred.uid = cred->fsuid;
25905         acred.gid = cred->fsgid;
25906 +       acred.tag = dx_current_tag();
25907         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25908  
25909         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25910 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25911         struct auth_cred acred = {
25912                 .uid = 0,
25913                 .gid = 0,
25914 +               .tag = dx_current_tag(),
25915         };
25916  
25917         dprintk("RPC: %5u looking up %s cred\n",
25918 diff -NurpP --minimal linux-3.4.83/net/sunrpc/auth_unix.c linux-3.4.83-vs2.3.3.9/net/sunrpc/auth_unix.c
25919 --- linux-3.4.83/net/sunrpc/auth_unix.c 2012-01-09 15:15:04.000000000 +0000
25920 +++ linux-3.4.83-vs2.3.3.9/net/sunrpc/auth_unix.c       2012-05-21 16:15:05.000000000 +0000
25921 @@ -12,12 +12,14 @@
25922  #include <linux/module.h>
25923  #include <linux/sunrpc/clnt.h>
25924  #include <linux/sunrpc/auth.h>
25925 +#include <linux/vs_tag.h>
25926  
25927  #define NFS_NGROUPS    16
25928  
25929  struct unx_cred {
25930         struct rpc_cred         uc_base;
25931         gid_t                   uc_gid;
25932 +       tag_t                   uc_tag;
25933         gid_t                   uc_gids[NFS_NGROUPS];
25934  };
25935  #define uc_uid                 uc_base.cr_uid
25936 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
25937                 groups = NFS_NGROUPS;
25938  
25939         cred->uc_gid = acred->gid;
25940 +       cred->uc_tag = acred->tag;
25941         for (i = 0; i < groups; i++)
25942                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25943         if (i < NFS_NGROUPS)
25944 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
25945         unsigned int i;
25946  
25947  
25948 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25949 +       if (cred->uc_uid != acred->uid ||
25950 +               cred->uc_gid != acred->gid ||
25951 +               cred->uc_tag != acred->tag)
25952                 return 0;
25953  
25954         if (acred->group_info != NULL)
25955 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
25956         struct rpc_clnt *clnt = task->tk_client;
25957         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25958         __be32          *base, *hold;
25959 -       int             i;
25960 +       int             i, tag;
25961  
25962         *p++ = htonl(RPC_AUTH_UNIX);
25963         base = p++;
25964 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
25965          * Copy the UTS nodename captured when the client was created.
25966          */
25967         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25968 +       tag = task->tk_client->cl_tag;
25969  
25970 -       *p++ = htonl((u32) cred->uc_uid);
25971 -       *p++ = htonl((u32) cred->uc_gid);
25972 +       *p++ = htonl((u32) TAGINO_UID(tag,
25973 +               cred->uc_uid, cred->uc_tag));
25974 +       *p++ = htonl((u32) TAGINO_GID(tag,
25975 +               cred->uc_gid, cred->uc_tag));
25976         hold = p++;
25977         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25978                 *p++ = htonl((u32) cred->uc_gids[i]);
25979 diff -NurpP --minimal linux-3.4.83/net/sunrpc/clnt.c linux-3.4.83-vs2.3.3.9/net/sunrpc/clnt.c
25980 --- linux-3.4.83/net/sunrpc/clnt.c      2014-03-12 09:48:30.000000000 +0000
25981 +++ linux-3.4.83-vs2.3.3.9/net/sunrpc/clnt.c    2014-03-12 09:55:29.000000000 +0000
25982 @@ -31,6 +31,7 @@
25983  #include <linux/in6.h>
25984  #include <linux/un.h>
25985  #include <linux/rcupdate.h>
25986 +#include <linux/vs_cvirt.h>
25987  
25988  #include <linux/sunrpc/clnt.h>
25989  #include <linux/sunrpc/rpc_pipe_fs.h>
25990 @@ -483,6 +484,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25991         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25992                 clnt->cl_chatty = 1;
25993  
25994 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25995 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25996 +               clnt->cl_tag = 1; */
25997         return clnt;
25998  }
25999  EXPORT_SYMBOL_GPL(rpc_create);
26000 diff -NurpP --minimal linux-3.4.83/net/unix/af_unix.c linux-3.4.83-vs2.3.3.9/net/unix/af_unix.c
26001 --- linux-3.4.83/net/unix/af_unix.c     2014-03-12 09:48:31.000000000 +0000
26002 +++ linux-3.4.83-vs2.3.3.9/net/unix/af_unix.c   2014-03-12 09:55:29.000000000 +0000
26003 @@ -114,6 +114,8 @@
26004  #include <linux/mount.h>
26005  #include <net/checksum.h>
26006  #include <linux/security.h>
26007 +#include <linux/vs_context.h>
26008 +#include <linux/vs_limit.h>
26009  
26010  struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26011  EXPORT_SYMBOL_GPL(unix_socket_table);
26012 @@ -261,6 +263,8 @@ static struct sock *__unix_find_socket_b
26013                 if (!net_eq(sock_net(s), net))
26014                         continue;
26015  
26016 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26017 +                       continue;
26018                 if (u->addr->len == len &&
26019                     !memcmp(u->addr->name, sunname, len))
26020                         goto found;
26021 @@ -2278,6 +2282,8 @@ static struct sock *unix_seq_idx(struct
26022         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26023                 if (sock_net(s) != seq_file_net(seq))
26024                         continue;
26025 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26026 +                       continue;
26027                 if (off == pos)
26028                         return s;
26029                 ++off;
26030 @@ -2302,7 +2308,8 @@ static void *unix_seq_next(struct seq_fi
26031                 sk = first_unix_socket(&iter->i);
26032         else
26033                 sk = next_unix_socket(&iter->i, sk);
26034 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26035 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26036 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26037                 sk = next_unix_socket(&iter->i, sk);
26038         return sk;
26039  }
26040 diff -NurpP --minimal linux-3.4.83/scripts/checksyscalls.sh linux-3.4.83-vs2.3.3.9/scripts/checksyscalls.sh
26041 --- linux-3.4.83/scripts/checksyscalls.sh       2012-03-19 18:47:34.000000000 +0000
26042 +++ linux-3.4.83-vs2.3.3.9/scripts/checksyscalls.sh     2012-05-21 16:15:05.000000000 +0000
26043 @@ -193,7 +193,6 @@ cat << EOF
26044  #define __IGNORE_afs_syscall
26045  #define __IGNORE_getpmsg
26046  #define __IGNORE_putpmsg
26047 -#define __IGNORE_vserver
26048  EOF
26049  }
26050  
26051 diff -NurpP --minimal linux-3.4.83/security/commoncap.c linux-3.4.83-vs2.3.3.9/security/commoncap.c
26052 --- linux-3.4.83/security/commoncap.c   2012-05-21 16:07:41.000000000 +0000
26053 +++ linux-3.4.83-vs2.3.3.9/security/commoncap.c 2012-05-21 16:15:05.000000000 +0000
26054 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
26055  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26056                 int cap, int audit)
26057  {
26058 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26059 +
26060         for (;;) {
26061                 /* The creator of the user namespace has all caps. */
26062                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
26063                         return 0;
26064  
26065                 /* Do we have the necessary capabilities? */
26066 -               if (targ_ns == cred->user->user_ns)
26067 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26068 +               if (targ_ns == cred->user->user_ns) {
26069 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26070 +                           cap_raised(cred->cap_effective, cap))
26071 +                               return 0;
26072 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26073 +               }
26074  
26075                 /* Have we tried all of the parent namespaces? */
26076                 if (targ_ns == &init_user_ns)
26077 @@ -612,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
26078  
26079         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26080                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26081 -           !capable(CAP_SYS_ADMIN))
26082 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26083                 return -EPERM;
26084         return 0;
26085  }
26086 @@ -638,7 +644,7 @@ int cap_inode_removexattr(struct dentry
26087  
26088         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26089                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26090 -           !capable(CAP_SYS_ADMIN))
26091 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26092                 return -EPERM;
26093         return 0;
26094  }
26095 diff -NurpP --minimal linux-3.4.83/security/selinux/hooks.c linux-3.4.83-vs2.3.3.9/security/selinux/hooks.c
26096 --- linux-3.4.83/security/selinux/hooks.c       2014-03-12 09:48:31.000000000 +0000
26097 +++ linux-3.4.83-vs2.3.3.9/security/selinux/hooks.c     2014-03-12 09:55:29.000000000 +0000
26098 @@ -67,7 +67,6 @@
26099  #include <linux/dccp.h>
26100  #include <linux/quota.h>
26101  #include <linux/un.h>          /* for Unix socket types */
26102 -#include <net/af_unix.h>       /* for Unix socket types */
26103  #include <linux/parser.h>
26104  #include <linux/nfs_mount.h>
26105  #include <net/ipv6.h>
This page took 2.201338 seconds and 3 git commands to generate.