]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
d740681942728e7b10e11b420f59cf4c0b0f5ba0
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.13.10/Documentation/vserver/debug.txt linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt
2 --- linux-3.13.10/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt    2014-01-31 20:38:03.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.13.10/arch/alpha/Kconfig linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig
160 --- linux-3.13.10/arch/alpha/Kconfig    2014-01-22 20:38:09.000000000 +0000
161 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig 2014-01-31 20:38:03.000000000 +0000
162 @@ -735,6 +735,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.13.10/arch/alpha/kernel/systbls.S linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S
172 --- linux-3.13.10/arch/alpha/kernel/systbls.S   2013-11-25 15:44:11.000000000 +0000
173 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S        2014-01-31 20:38:03.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175         .quad sys_stat64                        /* 425 */
176         .quad sys_lstat64
177         .quad sys_fstat64
178 -       .quad sys_ni_syscall                    /* sys_vserver */
179 +       .quad sys_vserver                       /* sys_vserver */
180         .quad sys_ni_syscall                    /* sys_mbind */
181         .quad sys_ni_syscall                    /* sys_get_mempolicy */
182         .quad sys_ni_syscall                    /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c
184 --- linux-3.13.10/arch/alpha/kernel/traps.c     2014-01-22 20:38:10.000000000 +0000
185 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c  2014-01-31 20:38:03.000000000 +0000
186 @@ -175,7 +175,8 @@ die_if_kernel(char * str, struct pt_regs
187  #ifdef CONFIG_SMP
188         printk("CPU %d ", hard_smp_processor_id());
189  #endif
190 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 +       printk("%s(%d:#%u): %s %ld\n", current->comm,
192 +               task_pid_nr(current), current->xid, str, err);
193         dik_show_regs(regs, r9_15);
194         add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
195         dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-3.13.10/arch/arm/Kconfig linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig
197 --- linux-3.13.10/arch/arm/Kconfig      2014-04-17 01:12:06.000000000 +0000
198 +++ linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig   2014-04-17 01:17:10.000000000 +0000
199 @@ -2267,6 +2267,8 @@ source "fs/Kconfig"
200  
201  source "arch/arm/Kconfig.debug"
202  
203 +source "kernel/vserver/Kconfig"
204 +
205  source "security/Kconfig"
206  
207  source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.13.10/arch/arm/kernel/calls.S linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S
209 --- linux-3.13.10/arch/arm/kernel/calls.S       2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S    2014-01-31 20:38:03.000000000 +0000
211 @@ -322,7 +322,7 @@
212  /* 310 */      CALL(sys_request_key)
213                 CALL(sys_keyctl)
214                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */  CALL(sys_ni_syscall)
216 +               CALL(sys_vserver)
217                 CALL(sys_ioprio_set)
218  /* 315 */      CALL(sys_ioprio_get)
219                 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.13.10/arch/arm/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c
221 --- linux-3.13.10/arch/arm/kernel/traps.c       2014-01-22 20:38:11.000000000 +0000
222 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c    2014-01-31 20:38:03.000000000 +0000
223 @@ -247,8 +247,8 @@ static int __die(const char *str, int er
224  
225         print_modules();
226         __show_regs(regs);
227 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
228 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
229 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
230 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
231  
232         if (!user_mode(regs) || in_interrupt()) {
233                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-3.13.10/arch/cris/Kconfig linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig
235 --- linux-3.13.10/arch/cris/Kconfig     2014-01-22 20:38:15.000000000 +0000
236 +++ linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig  2014-01-31 20:38:03.000000000 +0000
237 @@ -561,6 +561,8 @@ source "fs/Kconfig"
238  
239  source "arch/cris/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-3.13.10/arch/ia64/Kconfig linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig
247 --- linux-3.13.10/arch/ia64/Kconfig     2014-01-22 20:38:16.000000000 +0000
248 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig  2014-01-31 20:38:03.000000000 +0000
249 @@ -641,6 +641,8 @@ source "fs/Kconfig"
250  
251  source "arch/ia64/Kconfig.debug"
252  
253 +source "kernel/vserver/Kconfig"
254 +
255  source "security/Kconfig"
256  
257  source "crypto/Kconfig"
258 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/entry.S linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S
259 --- linux-3.13.10/arch/ia64/kernel/entry.S      2014-01-22 20:38:16.000000000 +0000
260 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S   2014-01-31 20:38:03.000000000 +0000
261 @@ -1706,7 +1706,7 @@ sys_call_table:
262         data8 sys_mq_notify
263         data8 sys_mq_getsetattr
264         data8 sys_kexec_load
265 -       data8 sys_ni_syscall                    // reserved for vserver
266 +       data8 sys_vserver
267         data8 sys_waitid                        // 1270
268         data8 sys_add_key
269         data8 sys_request_key
270 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c
271 --- linux-3.13.10/arch/ia64/kernel/ptrace.c     2013-02-19 13:56:51.000000000 +0000
272 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c  2014-01-31 20:38:03.000000000 +0000
273 @@ -21,6 +21,7 @@
274  #include <linux/regset.h>
275  #include <linux/elf.h>
276  #include <linux/tracehook.h>
277 +#include <linux/vs_base.h>
278  
279  #include <asm/pgtable.h>
280  #include <asm/processor.h>
281 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c
282 --- linux-3.13.10/arch/ia64/kernel/traps.c      2013-11-25 15:44:20.000000000 +0000
283 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c   2014-01-31 20:38:03.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
285         put_cpu();
286  
287         if (++die.lock_owner_depth < 3) {
288 -               printk("%s[%d]: %s %ld [%d]\n",
289 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
290 +               printk("%s[%d:#%u]: %s %ld [%d]\n",
291 +                       current->comm, task_pid_nr(current), current->xid,
292 +                       str, err, ++die_counter);
293                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
294                     != NOTIFY_STOP)
295                         show_regs(regs);
296 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
297                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
298                                 last.time = current_jiffies + 5 * HZ;
299                                 printk(KERN_WARNING
300 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
301 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
302 +                                       "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
303 +                                       current->comm, task_pid_nr(current), current->xid,
304 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
305                         }
306                 }
307         }
308 diff -NurpP --minimal linux-3.13.10/arch/m32r/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c
309 --- linux-3.13.10/arch/m32r/kernel/traps.c      2013-07-14 17:00:26.000000000 +0000
310 +++ linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c   2014-01-31 20:38:03.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
312         } else {
313                 printk("SPI: %08lx\n", sp);
314         }
315 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
316 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
317 +       printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
318 +               current->comm, task_pid_nr(current), current->xid,
319 +               0xffff & i, 4096+(unsigned long)current);
320  
321         /*
322          * When in-kernel, we also print out the stack and code at the
323 diff -NurpP --minimal linux-3.13.10/arch/m68k/Kconfig linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig
324 --- linux-3.13.10/arch/m68k/Kconfig     2014-04-17 01:12:07.000000000 +0000
325 +++ linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig  2014-04-17 01:17:10.000000000 +0000
326 @@ -135,6 +135,8 @@ source "fs/Kconfig"
327  
328  source "arch/m68k/Kconfig.debug"
329  
330 +source "kernel/vserver/Kconfig"
331 +
332  source "security/Kconfig"
333  
334  source "crypto/Kconfig"
335 diff -NurpP --minimal linux-3.13.10/arch/mips/Kconfig linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig
336 --- linux-3.13.10/arch/mips/Kconfig     2014-01-22 20:38:16.000000000 +0000
337 +++ linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig  2014-01-31 20:38:03.000000000 +0000
338 @@ -2539,6 +2539,8 @@ source "fs/Kconfig"
339  
340  source "arch/mips/Kconfig.debug"
341  
342 +source "kernel/vserver/Kconfig"
343 +
344  source "security/Kconfig"
345  
346  source "crypto/Kconfig"
347 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c
348 --- linux-3.13.10/arch/mips/kernel/ptrace.c     2014-01-22 20:38:17.000000000 +0000
349 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c  2014-01-31 20:53:13.000000000 +0000
350 @@ -30,6 +30,7 @@
351  #include <linux/audit.h>
352  #include <linux/seccomp.h>
353  #include <linux/ftrace.h>
354 +#include <linux/vs_base.h>
355  
356  #include <asm/byteorder.h>
357  #include <asm/cpu.h>
358 @@ -398,6 +399,9 @@ long arch_ptrace(struct task_struct *chi
359         void __user *datavp = (void __user *) data;
360         unsigned long __user *datalp = (void __user *) data;
361  
362 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
363 +               goto out;
364 +
365         switch (request) {
366         /* when I and D space are separate, these will need to be fixed. */
367         case PTRACE_PEEKTEXT: /* read word at location addr. */
368 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall32-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S
369 --- linux-3.13.10/arch/mips/kernel/scall32-o32.S        2014-01-22 20:38:17.000000000 +0000
370 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S     2014-01-31 20:48:18.000000000 +0000
371 @@ -491,7 +491,7 @@ EXPORT(sys_call_table)
372         PTR     sys_mq_timedreceive
373         PTR     sys_mq_notify                   /* 4275 */
374         PTR     sys_mq_getsetattr
375 -       PTR     sys_ni_syscall                  /* sys_vserver */
376 +       PTR     sys_vserver
377         PTR     sys_waitid
378         PTR     sys_ni_syscall                  /* available, was setaltroot */
379         PTR     sys_add_key                     /* 4280 */
380 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-64.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S
381 --- linux-3.13.10/arch/mips/kernel/scall64-64.S 2014-01-22 20:38:17.000000000 +0000
382 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S      2014-01-31 20:38:03.000000000 +0000
383 @@ -352,7 +352,7 @@ EXPORT(sys_call_table)
384         PTR     sys_mq_timedreceive
385         PTR     sys_mq_notify
386         PTR     sys_mq_getsetattr               /* 5235 */
387 -       PTR     sys_ni_syscall                  /* sys_vserver */
388 +       PTR     sys_vserver
389         PTR     sys_waitid
390         PTR     sys_ni_syscall                  /* available, was setaltroot */
391         PTR     sys_add_key
392 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-n32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S
393 --- linux-3.13.10/arch/mips/kernel/scall64-n32.S        2014-01-22 20:38:17.000000000 +0000
394 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S     2014-01-31 20:38:03.000000000 +0000
395 @@ -345,7 +345,7 @@ EXPORT(sysn32_call_table)
396         PTR     compat_sys_mq_timedreceive
397         PTR     compat_sys_mq_notify
398         PTR     compat_sys_mq_getsetattr
399 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
400 +       PTR     sys32_vserver                   /* 6240 */
401         PTR     compat_sys_waitid
402         PTR     sys_ni_syscall                  /* available, was setaltroot */
403         PTR     sys_add_key
404 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S
405 --- linux-3.13.10/arch/mips/kernel/scall64-o32.S        2014-01-22 20:38:17.000000000 +0000
406 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S     2014-01-31 20:38:03.000000000 +0000
407 @@ -469,7 +469,7 @@ EXPORT(sys32_call_table)
408         PTR     compat_sys_mq_timedreceive
409         PTR     compat_sys_mq_notify            /* 4275 */
410         PTR     compat_sys_mq_getsetattr
411 -       PTR     sys_ni_syscall                  /* sys_vserver */
412 +       PTR     sys32_vserver
413         PTR     compat_sys_waitid
414         PTR     sys_ni_syscall                  /* available, was setaltroot */
415         PTR     sys_add_key                     /* 4280 */
416 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c
417 --- linux-3.13.10/arch/mips/kernel/traps.c      2014-01-22 20:38:17.000000000 +0000
418 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c   2014-01-31 20:38:03.000000000 +0000
419 @@ -334,9 +334,10 @@ void show_registers(struct pt_regs *regs
420  
421         __show_regs(regs);
422         print_modules();
423 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
424 -              current->comm, current->pid, current_thread_info(), current,
425 -             field, current_thread_info()->tp_value);
426 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
427 +               current->comm, task_pid_nr(current), current->xid,
428 +               current_thread_info(), current,
429 +               field, current_thread_info()->tp_value);
430         if (cpu_has_userlocal) {
431                 unsigned long tls;
432  
433 diff -NurpP --minimal linux-3.13.10/arch/parisc/Kconfig linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig
434 --- linux-3.13.10/arch/parisc/Kconfig   2014-01-22 20:38:18.000000000 +0000
435 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig        2014-01-31 20:38:03.000000000 +0000
436 @@ -320,6 +320,8 @@ source "fs/Kconfig"
437  
438  source "arch/parisc/Kconfig.debug"
439  
440 +source "kernel/vserver/Kconfig"
441 +
442  source "security/Kconfig"
443  
444  source "crypto/Kconfig"
445 diff -NurpP --minimal linux-3.13.10/arch/parisc/kernel/syscall_table.S linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S
446 --- linux-3.13.10/arch/parisc/kernel/syscall_table.S    2013-07-14 17:00:31.000000000 +0000
447 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S 2014-01-31 20:38:03.000000000 +0000
448 @@ -358,7 +358,7 @@
449         ENTRY_COMP(mbind)               /* 260 */
450         ENTRY_COMP(get_mempolicy)
451         ENTRY_COMP(set_mempolicy)
452 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
453 +       ENTRY_DIFF(vserver)
454         ENTRY_SAME(add_key)
455         ENTRY_SAME(request_key)         /* 265 */
456         ENTRY_SAME(keyctl)
457 diff -NurpP --minimal linux-3.13.10/arch/parisc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c
458 --- linux-3.13.10/arch/parisc/kernel/traps.c    2013-11-25 15:46:28.000000000 +0000
459 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
460 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
461                         return; /* STFU */
462  
463                 parisc_printk_ratelimited(1, regs,
464 -                       KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 +                       KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
467 +                       current->comm, task_pid_nr(current), current->xid,
468 +                       str, err, regs->iaoq[0]);
469  
470                 return;
471         }
472 @@ -263,8 +264,8 @@ void die_if_kernel(char *str, struct pt_
473                 pdc_console_restart();
474         
475         if (err)
476 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
477 -                       current->comm, task_pid_nr(current), str, err);
478 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
479 +                       current->comm, task_pid_nr(current), current->xid, str, err);
480  
481         /* Wot's wrong wif bein' racy? */
482         if (current->thread.flags & PARISC_KERNEL_DEATH) {
483 diff -NurpP --minimal linux-3.13.10/arch/powerpc/Kconfig linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig
484 --- linux-3.13.10/arch/powerpc/Kconfig  2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig       2014-01-31 20:38:03.000000000 +0000
486 @@ -1028,6 +1028,8 @@ source "lib/Kconfig"
487  
488  source "arch/powerpc/Kconfig.debug"
489  
490 +source "kernel/vserver/Kconfig"
491 +
492  source "security/Kconfig"
493  
494  config KEYS_COMPAT
495 diff -NurpP --minimal linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h
496 --- linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h        2013-05-31 13:44:44.000000000 +0000
497 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h     2014-01-31 20:38:03.000000000 +0000
498 @@ -275,7 +275,7 @@
499  #endif
500  #define __NR_rtas              255
501  #define __NR_sys_debug_setcontext 256
502 -/* Number 257 is reserved for vserver */
503 +#define __NR_vserver           257
504  #define __NR_migrate_pages     258
505  #define __NR_mbind             259
506  #define __NR_get_mempolicy     260
507 diff -NurpP --minimal linux-3.13.10/arch/powerpc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c
508 --- linux-3.13.10/arch/powerpc/kernel/traps.c   2014-01-22 20:38:23.000000000 +0000
509 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c        2014-01-31 20:38:03.000000000 +0000
510 @@ -1272,8 +1272,9 @@ void nonrecoverable_exception(struct pt_
511  
512  void trace_syscall(struct pt_regs *regs)
513  {
514 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
515 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
516 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
517 +              current, task_pid_nr(current), current->xid,
518 +              regs->nip, regs->link, regs->gpr[0],
519                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
520  }
521  
522 diff -NurpP --minimal linux-3.13.10/arch/s390/Kconfig linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig
523 --- linux-3.13.10/arch/s390/Kconfig     2014-04-17 01:12:08.000000000 +0000
524 +++ linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig  2014-04-17 01:17:10.000000000 +0000
525 @@ -650,6 +650,8 @@ source "fs/Kconfig"
526  
527  source "arch/s390/Kconfig.debug"
528  
529 +source "kernel/vserver/Kconfig"
530 +
531  source "security/Kconfig"
532  
533  source "crypto/Kconfig"
534 diff -NurpP --minimal linux-3.13.10/arch/s390/include/asm/tlb.h linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h
535 --- linux-3.13.10/arch/s390/include/asm/tlb.h   2013-11-25 15:46:29.000000000 +0000
536 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h        2014-01-31 20:38:03.000000000 +0000
537 @@ -24,6 +24,7 @@
538  #include <linux/mm.h>
539  #include <linux/pagemap.h>
540  #include <linux/swap.h>
541 +
542  #include <asm/processor.h>
543  #include <asm/pgalloc.h>
544  #include <asm/tlbflush.h>
545 diff -NurpP --minimal linux-3.13.10/arch/s390/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h
546 --- linux-3.13.10/arch/s390/include/uapi/asm/unistd.h   2013-02-19 13:57:16.000000000 +0000
547 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h        2014-01-31 20:38:03.000000000 +0000
548 @@ -200,7 +200,7 @@
549  #define __NR_clock_gettime     (__NR_timer_create+6)
550  #define __NR_clock_getres      (__NR_timer_create+7)
551  #define __NR_clock_nanosleep   (__NR_timer_create+8)
552 -/* Number 263 is reserved for vserver */
553 +#define __NR_vserver           263
554  #define __NR_statfs64          265
555  #define __NR_fstatfs64         266
556  #define __NR_remap_file_pages  267
557 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c
558 --- linux-3.13.10/arch/s390/kernel/ptrace.c     2014-01-22 20:38:24.000000000 +0000
559 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c  2014-01-31 20:38:03.000000000 +0000
560 @@ -21,6 +21,7 @@
561  #include <linux/tracehook.h>
562  #include <linux/seccomp.h>
563  #include <linux/compat.h>
564 +#include <linux/vs_base.h>
565  #include <trace/syscall.h>
566  #include <asm/segment.h>
567  #include <asm/page.h>
568 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/syscalls.S linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S
569 --- linux-3.13.10/arch/s390/kernel/syscalls.S   2013-07-14 17:00:34.000000000 +0000
570 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S        2014-01-31 20:38:03.000000000 +0000
571 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
572  SYSCALL(sys_clock_gettime,sys_clock_gettime,compat_sys_clock_gettime)  /* 260 */
573  SYSCALL(sys_clock_getres,sys_clock_getres,compat_sys_clock_getres)
574  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,compat_sys_clock_nanosleep)
575 -NI_SYSCALL                                                     /* reserved for vserver */
576 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
577  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,compat_sys_s390_fadvise64_64)
578  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64)
579  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64)
580 diff -NurpP --minimal linux-3.13.10/arch/sh/Kconfig linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig
581 --- linux-3.13.10/arch/sh/Kconfig       2014-01-22 20:38:24.000000000 +0000
582 +++ linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig    2014-01-31 20:38:03.000000000 +0000
583 @@ -927,6 +927,8 @@ source "fs/Kconfig"
584  
585  source "arch/sh/Kconfig.debug"
586  
587 +source "kernel/vserver/Kconfig"
588 +
589  source "security/Kconfig"
590  
591  source "crypto/Kconfig"
592 diff -NurpP --minimal linux-3.13.10/arch/sh/kernel/irq.c linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c
593 --- linux-3.13.10/arch/sh/kernel/irq.c  2014-01-22 20:38:24.000000000 +0000
594 +++ linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c       2014-01-31 20:38:03.000000000 +0000
595 @@ -14,6 +14,7 @@
596  #include <linux/ftrace.h>
597  #include <linux/delay.h>
598  #include <linux/ratelimit.h>
599 +// #include <linux/vs_context.h>
600  #include <asm/processor.h>
601  #include <asm/machvec.h>
602  #include <asm/uaccess.h>
603 diff -NurpP --minimal linux-3.13.10/arch/sparc/Kconfig linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig
604 --- linux-3.13.10/arch/sparc/Kconfig    2014-01-22 20:38:24.000000000 +0000
605 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig 2014-01-31 20:38:03.000000000 +0000
606 @@ -553,6 +553,8 @@ source "fs/Kconfig"
607  
608  source "arch/sparc/Kconfig.debug"
609  
610 +source "kernel/vserver/Kconfig"
611 +
612  source "security/Kconfig"
613  
614  source "crypto/Kconfig"
615 diff -NurpP --minimal linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h
616 --- linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h  2013-02-19 13:57:17.000000000 +0000
617 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h       2014-01-31 20:38:03.000000000 +0000
618 @@ -332,7 +332,7 @@
619  #define __NR_timer_getoverrun  264
620  #define __NR_timer_delete      265
621  #define __NR_timer_create      266
622 -/* #define __NR_vserver                267 Reserved for VSERVER */
623 +#define __NR_vserver           267
624  #define __NR_io_setup          268
625  #define __NR_io_destroy                269
626  #define __NR_io_submit         270
627 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_32.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S
628 --- linux-3.13.10/arch/sparc/kernel/systbls_32.S        2013-05-31 13:44:48.000000000 +0000
629 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S     2014-01-31 20:38:03.000000000 +0000
630 @@ -70,7 +70,7 @@ sys_call_table:
631  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
632  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
633  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
634 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
635 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
636  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
637  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
638  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
639 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_64.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S
640 --- linux-3.13.10/arch/sparc/kernel/systbls_64.S        2013-07-14 17:00:35.000000000 +0000
641 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S     2014-01-31 20:38:03.000000000 +0000
642 @@ -71,7 +71,7 @@ sys_call_table32:
643  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
644         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
645  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
646 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
647 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
648  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
649         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
650  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
651 @@ -149,7 +149,7 @@ sys_call_table:
652  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
653         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
654  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
655 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
656 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
657  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
658         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
659  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
660 diff -NurpP --minimal linux-3.13.10/arch/um/Kconfig.rest linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest
661 --- linux-3.13.10/arch/um/Kconfig.rest  2012-12-11 03:30:57.000000000 +0000
662 +++ linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest       2014-01-31 20:38:03.000000000 +0000
663 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
664  
665  source "fs/Kconfig"
666  
667 +source "kernel/vserver/Kconfig"
668 +
669  source "security/Kconfig"
670  
671  source "crypto/Kconfig"
672 diff -NurpP --minimal linux-3.13.10/arch/x86/Kconfig linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig
673 --- linux-3.13.10/arch/x86/Kconfig      2014-01-22 20:38:25.000000000 +0000
674 +++ linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig   2014-01-31 20:38:03.000000000 +0000
675 @@ -2403,6 +2403,8 @@ source "fs/Kconfig"
676  
677  source "arch/x86/Kconfig.debug"
678  
679 +source "kernel/vserver/Kconfig"
680 +
681  source "security/Kconfig"
682  
683  source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_32.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl
685 --- linux-3.13.10/arch/x86/syscalls/syscall_32.tbl      2013-07-14 17:00:37.000000000 +0000
686 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl   2014-01-31 20:38:03.000000000 +0000
687 @@ -279,7 +279,7 @@
688  270    i386    tgkill                  sys_tgkill
689  271    i386    utimes                  sys_utimes                      compat_sys_utimes
690  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
691 -273    i386    vserver
692 +273    i386    vserver                 sys_vserver                     sys32_vserver
693  274    i386    mbind                   sys_mbind
694  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
695  276    i386    set_mempolicy           sys_set_mempolicy
696 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_64.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl
697 --- linux-3.13.10/arch/x86/syscalls/syscall_64.tbl      2013-05-31 13:44:50.000000000 +0000
698 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl   2014-01-31 20:38:03.000000000 +0000
699 @@ -242,7 +242,7 @@
700  233    common  epoll_ctl               sys_epoll_ctl
701  234    common  tgkill                  sys_tgkill
702  235    common  utimes                  sys_utimes
703 -236    64      vserver
704 +236    64      vserver                 sys_vserver
705  237    common  mbind                   sys_mbind
706  238    common  set_mempolicy           sys_set_mempolicy
707  239    common  get_mempolicy           sys_get_mempolicy
708 diff -NurpP --minimal linux-3.13.10/drivers/block/Kconfig linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig
709 --- linux-3.13.10/drivers/block/Kconfig 2014-01-22 20:38:27.000000000 +0000
710 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig      2014-01-31 20:38:03.000000000 +0000
711 @@ -281,6 +281,13 @@ config BLK_DEV_CRYPTOLOOP
712  
713  source "drivers/block/drbd/Kconfig"
714  
715 +config BLK_DEV_VROOT
716 +       tristate "Virtual Root device support"
717 +       depends on QUOTACTL
718 +       ---help---
719 +         Saying Y here will allow you to use quota/fs ioctls on a shared
720 +         partition within a virtual server without compromising security.
721 +
722  config BLK_DEV_NBD
723         tristate "Network block device support"
724         depends on NET
725 diff -NurpP --minimal linux-3.13.10/drivers/block/Makefile linux-3.13.10-vs2.3.6.11/drivers/block/Makefile
726 --- linux-3.13.10/drivers/block/Makefile        2014-01-22 20:38:27.000000000 +0000
727 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Makefile     2014-01-31 20:38:03.000000000 +0000
728 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
729  obj-$(CONFIG_VIODASD)          += viodasd.o
730  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
731  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
732 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
733  
734  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
735  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
736 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.c linux-3.13.10-vs2.3.6.11/drivers/block/loop.c
737 --- linux-3.13.10/drivers/block/loop.c  2014-01-22 20:38:27.000000000 +0000
738 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.c       2014-01-31 20:55:14.000000000 +0000
739 @@ -75,6 +75,7 @@
740  #include <linux/sysfs.h>
741  #include <linux/miscdevice.h>
742  #include <linux/falloc.h>
743 +#include <linux/vs_context.h>
744  #include "loop.h"
745  
746  #include <asm/uaccess.h>
747 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
748         lo->lo_blocksize = lo_blocksize;
749         lo->lo_device = bdev;
750         lo->lo_flags = lo_flags;
751 +       lo->lo_xid = vx_current_xid();
752         lo->lo_backing_file = file;
753         lo->transfer = transfer_none;
754         lo->ioctl = NULL;
755 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
756         lo->lo_sizelimit = 0;
757         lo->lo_encrypt_key_size = 0;
758         lo->lo_thread = NULL;
759 +       lo->lo_xid = 0;
760         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
761         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
762         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
763 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
764  
765         if (lo->lo_encrypt_key_size &&
766             !uid_eq(lo->lo_key_owner, uid) &&
767 -           !capable(CAP_SYS_ADMIN))
768 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
769                 return -EPERM;
770         if (lo->lo_state != Lo_bound)
771                 return -ENXIO;
772 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
773         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
774         info->lo_encrypt_type =
775                 lo->lo_encryption ? lo->lo_encryption->number : 0;
776 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
777 +       if (lo->lo_encrypt_key_size &&
778 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
779                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
780                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
781                        lo->lo_encrypt_key_size);
782 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
783                 goto out;
784         }
785  
786 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
787 +               err = -EACCES;
788 +               goto out;
789 +       }
790 +
791         mutex_lock(&lo->lo_ctl_mutex);
792         lo->lo_refcnt++;
793         mutex_unlock(&lo->lo_ctl_mutex);
794 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.h linux-3.13.10-vs2.3.6.11/drivers/block/loop.h
795 --- linux-3.13.10/drivers/block/loop.h  2013-11-25 15:44:28.000000000 +0000
796 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.h       2014-02-01 01:57:49.000000000 +0000
797 @@ -41,6 +41,7 @@ struct loop_device {
798         struct loop_func_table *lo_encryption;
799         __u32           lo_init[2];
800         kuid_t          lo_key_owner;   /* Who set the key */
801 +       vxid_t          lo_xid;
802         int             (*ioctl)(struct loop_device *, int cmd, 
803                                  unsigned long arg); 
804  
805 diff -NurpP --minimal linux-3.13.10/drivers/block/vroot.c linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c
806 --- linux-3.13.10/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
807 +++ linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c      2014-01-31 20:38:03.000000000 +0000
808 @@ -0,0 +1,290 @@
809 +/*
810 + *  linux/drivers/block/vroot.c
811 + *
812 + *  written by Herbert Pötzl, 9/11/2002
813 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
814 + *
815 + *  based on the loop.c code by Theodore Ts'o.
816 + *
817 + * Copyright (C) 2002-2007 by Herbert Pötzl.
818 + * Redistribution of this file is permitted under the
819 + * GNU General Public License.
820 + *
821 + */
822 +
823 +#include <linux/module.h>
824 +#include <linux/moduleparam.h>
825 +#include <linux/file.h>
826 +#include <linux/major.h>
827 +#include <linux/blkdev.h>
828 +#include <linux/slab.h>
829 +
830 +#include <linux/vroot.h>
831 +#include <linux/vs_context.h>
832 +
833 +
834 +static int max_vroot = 8;
835 +
836 +static struct vroot_device *vroot_dev;
837 +static struct gendisk **disks;
838 +
839 +
840 +static int vroot_set_dev(
841 +       struct vroot_device *vr,
842 +       struct block_device *bdev,
843 +       unsigned int arg)
844 +{
845 +       struct block_device *real_bdev;
846 +       struct file *file;
847 +       struct inode *inode;
848 +       int error;
849 +
850 +       error = -EBUSY;
851 +       if (vr->vr_state != Vr_unbound)
852 +               goto out;
853 +
854 +       error = -EBADF;
855 +       file = fget(arg);
856 +       if (!file)
857 +               goto out;
858 +
859 +       error = -EINVAL;
860 +       inode = file->f_dentry->d_inode;
861 +
862 +
863 +       if (S_ISBLK(inode->i_mode)) {
864 +               real_bdev = inode->i_bdev;
865 +               vr->vr_device = real_bdev;
866 +               __iget(real_bdev->bd_inode);
867 +       } else
868 +               goto out_fput;
869 +
870 +       vxdprintk(VXD_CBIT(misc, 0),
871 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
872 +               vr->vr_number, VXD_DEV(real_bdev));
873 +
874 +       vr->vr_state = Vr_bound;
875 +       error = 0;
876 +
877 + out_fput:
878 +       fput(file);
879 + out:
880 +       return error;
881 +}
882 +
883 +static int vroot_clr_dev(
884 +       struct vroot_device *vr,
885 +       struct block_device *bdev)
886 +{
887 +       struct block_device *real_bdev;
888 +
889 +       if (vr->vr_state != Vr_bound)
890 +               return -ENXIO;
891 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
892 +               return -EBUSY;
893 +
894 +       real_bdev = vr->vr_device;
895 +
896 +       vxdprintk(VXD_CBIT(misc, 0),
897 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
898 +               vr->vr_number, VXD_DEV(real_bdev));
899 +
900 +       bdput(real_bdev);
901 +       vr->vr_state = Vr_unbound;
902 +       vr->vr_device = NULL;
903 +       return 0;
904 +}
905 +
906 +
907 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
908 +       unsigned int cmd, unsigned long arg)
909 +{
910 +       struct vroot_device *vr = bdev->bd_disk->private_data;
911 +       int err;
912 +
913 +       down(&vr->vr_ctl_mutex);
914 +       switch (cmd) {
915 +       case VROOT_SET_DEV:
916 +               err = vroot_set_dev(vr, bdev, arg);
917 +               break;
918 +       case VROOT_CLR_DEV:
919 +               err = vroot_clr_dev(vr, bdev);
920 +               break;
921 +       default:
922 +               err = -EINVAL;
923 +               break;
924 +       }
925 +       up(&vr->vr_ctl_mutex);
926 +       return err;
927 +}
928 +
929 +static int vr_open(struct block_device *bdev, fmode_t mode)
930 +{
931 +       struct vroot_device *vr = bdev->bd_disk->private_data;
932 +
933 +       down(&vr->vr_ctl_mutex);
934 +       vr->vr_refcnt++;
935 +       up(&vr->vr_ctl_mutex);
936 +       return 0;
937 +}
938 +
939 +static void vr_release(struct gendisk *disk, fmode_t mode)
940 +{
941 +       struct vroot_device *vr = disk->private_data;
942 +
943 +       down(&vr->vr_ctl_mutex);
944 +       --vr->vr_refcnt;
945 +       up(&vr->vr_ctl_mutex);
946 +}
947 +
948 +static struct block_device_operations vr_fops = {
949 +       .owner =        THIS_MODULE,
950 +       .open =         vr_open,
951 +       .release =      vr_release,
952 +       .ioctl =        vr_ioctl,
953 +};
954 +
955 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
956 +{
957 +       printk("vroot_make_request %p, %p\n", q, bio);
958 +       bio_io_error(bio);
959 +}
960 +
961 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
962 +{
963 +       struct inode *inode = bdev->bd_inode;
964 +       struct vroot_device *vr;
965 +       struct block_device *real_bdev;
966 +       int minor = iminor(inode);
967 +
968 +       vr = &vroot_dev[minor];
969 +       real_bdev = vr->vr_device;
970 +
971 +       vxdprintk(VXD_CBIT(misc, 0),
972 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
973 +               vr->vr_number, VXD_DEV(real_bdev));
974 +
975 +       if (vr->vr_state != Vr_bound)
976 +               return ERR_PTR(-ENXIO);
977 +
978 +       __iget(real_bdev->bd_inode);
979 +       return real_bdev;
980 +}
981 +
982 +
983 +
984 +/*
985 + * And now the modules code and kernel interface.
986 + */
987 +
988 +module_param(max_vroot, int, 0);
989 +
990 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
991 +MODULE_LICENSE("GPL");
992 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
993 +
994 +MODULE_AUTHOR ("Herbert Pötzl");
995 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
996 +
997 +
998 +int __init vroot_init(void)
999 +{
1000 +       int err, i;
1001 +
1002 +       if (max_vroot < 1 || max_vroot > 256) {
1003 +               max_vroot = MAX_VROOT_DEFAULT;
1004 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1005 +                       "(must be between 1 and 256), "
1006 +                       "using default (%d)\n", max_vroot);
1007 +       }
1008 +
1009 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1010 +               return -EIO;
1011 +
1012 +       err = -ENOMEM;
1013 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1014 +       if (!vroot_dev)
1015 +               goto out_mem1;
1016 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1017 +
1018 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1019 +       if (!disks)
1020 +               goto out_mem2;
1021 +
1022 +       for (i = 0; i < max_vroot; i++) {
1023 +               disks[i] = alloc_disk(1);
1024 +               if (!disks[i])
1025 +                       goto out_mem3;
1026 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1027 +               if (!disks[i]->queue)
1028 +                       goto out_mem3;
1029 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1030 +       }
1031 +
1032 +       for (i = 0; i < max_vroot; i++) {
1033 +               struct vroot_device *vr = &vroot_dev[i];
1034 +               struct gendisk *disk = disks[i];
1035 +
1036 +               memset(vr, 0, sizeof(*vr));
1037 +               sema_init(&vr->vr_ctl_mutex, 1);
1038 +               vr->vr_number = i;
1039 +               disk->major = VROOT_MAJOR;
1040 +               disk->first_minor = i;
1041 +               disk->fops = &vr_fops;
1042 +               sprintf(disk->disk_name, "vroot%d", i);
1043 +               disk->private_data = vr;
1044 +       }
1045 +
1046 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1047 +       if (err)
1048 +               goto out_mem3;
1049 +
1050 +       for (i = 0; i < max_vroot; i++)
1051 +               add_disk(disks[i]);
1052 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1053 +       return 0;
1054 +
1055 +out_mem3:
1056 +       while (i--)
1057 +               put_disk(disks[i]);
1058 +       kfree(disks);
1059 +out_mem2:
1060 +       kfree(vroot_dev);
1061 +out_mem1:
1062 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1063 +       printk(KERN_ERR "vroot: ran out of memory\n");
1064 +       return err;
1065 +}
1066 +
1067 +void vroot_exit(void)
1068 +{
1069 +       int i;
1070 +
1071 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1072 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1073 +
1074 +       for (i = 0; i < max_vroot; i++) {
1075 +               del_gendisk(disks[i]);
1076 +               put_disk(disks[i]);
1077 +       }
1078 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1079 +
1080 +       kfree(disks);
1081 +       kfree(vroot_dev);
1082 +}
1083 +
1084 +module_init(vroot_init);
1085 +module_exit(vroot_exit);
1086 +
1087 +#ifndef MODULE
1088 +
1089 +static int __init max_vroot_setup(char *str)
1090 +{
1091 +       max_vroot = simple_strtol(str, NULL, 0);
1092 +       return 1;
1093 +}
1094 +
1095 +__setup("max_vroot=", max_vroot_setup);
1096 +
1097 +#endif
1098 +
1099 diff -NurpP --minimal linux-3.13.10/drivers/infiniband/core/addr.c linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c
1100 --- linux-3.13.10/drivers/infiniband/core/addr.c        2013-11-25 15:44:35.000000000 +0000
1101 +++ linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c     2014-01-31 20:38:03.000000000 +0000
1102 @@ -277,7 +277,7 @@ static int addr6_resolve(struct sockaddr
1103  
1104         if (ipv6_addr_any(&fl6.saddr)) {
1105                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1106 -                                        &fl6.daddr, 0, &fl6.saddr);
1107 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1108                 if (ret)
1109                         goto put;
1110  
1111 diff -NurpP --minimal linux-3.13.10/drivers/md/dm-ioctl.c linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c
1112 --- linux-3.13.10/drivers/md/dm-ioctl.c 2014-01-22 20:38:36.000000000 +0000
1113 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c      2014-01-31 21:01:49.000000000 +0000
1114 @@ -16,6 +16,7 @@
1115  #include <linux/dm-ioctl.h>
1116  #include <linux/hdreg.h>
1117  #include <linux/compat.h>
1118 +#include <linux/vs_context.h>
1119  
1120  #include <asm/uaccess.h>
1121  
1122 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1123         unsigned int h = hash_str(str);
1124  
1125         list_for_each_entry (hc, _name_buckets + h, name_list)
1126 -               if (!strcmp(hc->name, str)) {
1127 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1128 +                       !strcmp(hc->name, str)) {
1129                         dm_get(hc->md);
1130                         return hc;
1131                 }
1132 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1133         unsigned int h = hash_str(str);
1134  
1135         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1136 -               if (!strcmp(hc->uuid, str)) {
1137 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1138 +                       !strcmp(hc->uuid, str)) {
1139                         dm_get(hc->md);
1140                         return hc;
1141                 }
1142 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1143  static struct hash_cell *__get_dev_cell(uint64_t dev)
1144  {
1145         struct mapped_device *md;
1146 -       struct hash_cell *hc;
1147 +       struct hash_cell *hc = NULL;
1148  
1149         md = dm_get_md(huge_decode_dev(dev));
1150         if (!md)
1151                 return NULL;
1152  
1153 -       hc = dm_get_mdptr(md);
1154 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1155 +               hc = dm_get_mdptr(md);
1156 +
1157         if (!hc) {
1158                 dm_put(md);
1159                 return NULL;
1160 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1161  
1162  static int remove_all(struct dm_ioctl *param, size_t param_size)
1163  {
1164 +       if (!vx_check(0, VS_ADMIN))
1165 +               return -EPERM;
1166 +
1167         dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1168         param->data_size = 0;
1169         return 0;
1170 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1171          */
1172         for (i = 0; i < NUM_BUCKETS; i++) {
1173                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1174 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1175 +                               continue;
1176                         needed += sizeof(struct dm_name_list);
1177                         needed += strlen(hc->name) + 1;
1178                         needed += ALIGN_MASK;
1179 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1180          */
1181         for (i = 0; i < NUM_BUCKETS; i++) {
1182                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1183 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1184 +                               continue;
1185                         if (old_nl)
1186                                 old_nl->next = (uint32_t) ((void *) nl -
1187                                                            (void *) old_nl);
1188 @@ -1797,8 +1809,8 @@ static int ctl_ioctl(uint command, struc
1189         size_t input_param_size;
1190         struct dm_ioctl param_kernel;
1191  
1192 -       /* only root can play with this */
1193 -       if (!capable(CAP_SYS_ADMIN))
1194 +       /* only root and certain contexts can play with this */
1195 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1196                 return -EACCES;
1197  
1198         if (_IOC_TYPE(command) != DM_IOCTL)
1199 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.c linux-3.13.10-vs2.3.6.11/drivers/md/dm.c
1200 --- linux-3.13.10/drivers/md/dm.c       2014-04-17 01:12:19.000000000 +0000
1201 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.c    2014-02-25 11:26:09.000000000 +0000
1202 @@ -19,6 +19,7 @@
1203  #include <linux/idr.h>
1204  #include <linux/hdreg.h>
1205  #include <linux/delay.h>
1206 +#include <linux/vs_base.h>
1207  
1208  #include <trace/events/block.h>
1209  
1210 @@ -139,6 +140,7 @@ struct mapped_device {
1211         struct mutex suspend_lock;
1212         atomic_t holders;
1213         atomic_t open_count;
1214 +       vxid_t xid;
1215  
1216         /*
1217          * The current mapping.
1218 @@ -384,6 +386,7 @@ int dm_deleting_md(struct mapped_device
1219  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1220  {
1221         struct mapped_device *md;
1222 +       int ret = -ENXIO;
1223  
1224         spin_lock(&_minor_lock);
1225  
1226 @@ -392,18 +395,19 @@ static int dm_blk_open(struct block_devi
1227                 goto out;
1228  
1229         if (test_bit(DMF_FREEING, &md->flags) ||
1230 -           dm_deleting_md(md)) {
1231 -               md = NULL;
1232 +           dm_deleting_md(md))
1233 +               goto out;
1234 +
1235 +       ret = -EACCES;
1236 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1237                 goto out;
1238 -       }
1239  
1240         dm_get(md);
1241         atomic_inc(&md->open_count);
1242 -
1243 +       ret = 0;
1244  out:
1245         spin_unlock(&_minor_lock);
1246 -
1247 -       return md ? 0 : -ENXIO;
1248 +       return ret;
1249  }
1250  
1251  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1252 @@ -687,6 +691,14 @@ int dm_set_geometry(struct mapped_device
1253         return 0;
1254  }
1255  
1256 +/*
1257 + * Get the xid associated with a dm device
1258 + */
1259 +vxid_t dm_get_xid(struct mapped_device *md)
1260 +{
1261 +       return md->xid;
1262 +}
1263 +
1264  /*-----------------------------------------------------------------
1265   * CRUD START:
1266   *   A more elegant soln is in the works that uses the queue
1267 @@ -2026,6 +2038,7 @@ static struct mapped_device *alloc_dev(i
1268         INIT_LIST_HEAD(&md->uevent_list);
1269         spin_lock_init(&md->uevent_lock);
1270  
1271 +       md->xid = vx_current_xid();
1272         md->queue = blk_alloc_queue(GFP_KERNEL);
1273         if (!md->queue)
1274                 goto bad_queue;
1275 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.h linux-3.13.10-vs2.3.6.11/drivers/md/dm.h
1276 --- linux-3.13.10/drivers/md/dm.h       2014-04-17 01:12:19.000000000 +0000
1277 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.h    2014-02-25 11:26:09.000000000 +0000
1278 @@ -50,6 +50,8 @@ struct dm_dev_internal {
1279  struct dm_table;
1280  struct dm_md_mempools;
1281  
1282 +vxid_t dm_get_xid(struct mapped_device *md);
1283 +
1284  /*-----------------------------------------------------------------
1285   * Internal table functions.
1286   *---------------------------------------------------------------*/
1287 diff -NurpP --minimal linux-3.13.10/drivers/net/tun.c linux-3.13.10-vs2.3.6.11/drivers/net/tun.c
1288 --- linux-3.13.10/drivers/net/tun.c     2014-04-17 01:12:21.000000000 +0000
1289 +++ linux-3.13.10-vs2.3.6.11/drivers/net/tun.c  2014-04-17 01:17:10.000000000 +0000
1290 @@ -65,6 +65,7 @@
1291  #include <linux/nsproxy.h>
1292  #include <linux/virtio_net.h>
1293  #include <linux/rcupdate.h>
1294 +#include <linux/vs_network.h>
1295  #include <net/net_namespace.h>
1296  #include <net/netns/generic.h>
1297  #include <net/rtnetlink.h>
1298 @@ -168,6 +169,7 @@ struct tun_struct {
1299         unsigned int            flags;
1300         kuid_t                  owner;
1301         kgid_t                  group;
1302 +       vnid_t                  nid;
1303  
1304         struct net_device       *dev;
1305         netdev_features_t       set_features;
1306 @@ -385,6 +387,7 @@ static inline bool tun_not_capable(struc
1307         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1308                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1309                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1310 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1311  }
1312  
1313  static void tun_set_real_num_queues(struct tun_struct *tun)
1314 @@ -1382,6 +1385,7 @@ static void tun_setup(struct net_device
1315  
1316         tun->owner = INVALID_UID;
1317         tun->group = INVALID_GID;
1318 +       tun->nid = nx_current_nid();
1319  
1320         dev->ethtool_ops = &tun_ethtool_ops;
1321         dev->destructor = tun_free_netdev;
1322 @@ -1598,7 +1602,7 @@ static int tun_set_iff(struct net *net,
1323                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1324                              MAX_TAP_QUEUES : 1;
1325  
1326 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1327 +               if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1328                         return -EPERM;
1329                 err = security_tun_dev_create();
1330                 if (err < 0)
1331 @@ -1969,6 +1973,16 @@ static long __tun_chr_ioctl(struct file
1332                           from_kgid(&init_user_ns, tun->group));
1333                 break;
1334  
1335 +       case TUNSETNID:
1336 +               if (!capable(CAP_CONTEXT))
1337 +                       return -EPERM;
1338 +
1339 +               /* Set nid owner of the device */
1340 +               tun->nid = (vnid_t) arg;
1341 +
1342 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1343 +               break;
1344 +
1345         case TUNSETLINK:
1346                 /* Only allow setting the type when the interface is down */
1347                 if (tun->dev->flags & IFF_UP) {
1348 diff -NurpP --minimal linux-3.13.10/drivers/tty/sysrq.c linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c
1349 --- linux-3.13.10/drivers/tty/sysrq.c   2014-01-22 20:39:02.000000000 +0000
1350 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c        2014-01-31 20:55:49.000000000 +0000
1351 @@ -46,6 +46,7 @@
1352  #include <linux/jiffies.h>
1353  #include <linux/syscalls.h>
1354  #include <linux/of.h>
1355 +#include <linux/vserver/debug.h>
1356  
1357  #include <asm/ptrace.h>
1358  #include <asm/irq_regs.h>
1359 @@ -407,6 +408,21 @@ static struct sysrq_key_op sysrq_unrt_op
1360         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1361  };
1362  
1363 +
1364 +#ifdef CONFIG_VSERVER_DEBUG
1365 +static void sysrq_handle_vxinfo(int key)
1366 +{
1367 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1368 +}
1369 +
1370 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1371 +       .handler        = sysrq_handle_vxinfo,
1372 +       .help_msg       = "conteXt",
1373 +       .action_msg     = "Show Context Info",
1374 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1375 +};
1376 +#endif
1377 +
1378  /* Key Operations table and lock */
1379  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1380  
1381 @@ -462,7 +478,11 @@ static struct sysrq_key_op *sysrq_key_ta
1382         &sysrq_showstate_blocked_op,    /* w */
1383         /* x: May be registered on ppc/powerpc for xmon */
1384         /* x: May be registered on sparc64 for global PMU dump */
1385 +#ifdef CONFIG_VSERVER_DEBUG
1386 +       &sysrq_showvxinfo_op,           /* x */
1387 +#else
1388         NULL,                           /* x */
1389 +#endif
1390         /* y: May be registered on sparc64 for global register dump */
1391         NULL,                           /* y */
1392         &sysrq_ftrace_dump_op,          /* z */
1393 @@ -477,6 +497,8 @@ static int sysrq_key_table_key2index(int
1394                 retval = key - '0';
1395         else if ((key >= 'a') && (key <= 'z'))
1396                 retval = key + 10 - 'a';
1397 +       else if ((key >= 'A') && (key <= 'Z'))
1398 +               retval = key + 10 - 'A';
1399         else
1400                 retval = -1;
1401         return retval;
1402 diff -NurpP --minimal linux-3.13.10/drivers/tty/tty_io.c linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c
1403 --- linux-3.13.10/drivers/tty/tty_io.c  2014-01-22 20:39:02.000000000 +0000
1404 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c       2014-01-31 20:38:03.000000000 +0000
1405 @@ -104,6 +104,7 @@
1406  
1407  #include <linux/kmod.h>
1408  #include <linux/nsproxy.h>
1409 +#include <linux/vs_pid.h>
1410  
1411  #undef TTY_DEBUG_HANGUP
1412  
1413 @@ -2218,7 +2219,8 @@ static int tiocsti(struct tty_struct *tt
1414         char ch, mbz = 0;
1415         struct tty_ldisc *ld;
1416  
1417 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1418 +       if (((current->signal->tty != tty) &&
1419 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1420                 return -EPERM;
1421         if (get_user(ch, p))
1422                 return -EFAULT;
1423 @@ -2506,6 +2508,7 @@ static int tiocspgrp(struct tty_struct *
1424                 return -ENOTTY;
1425         if (get_user(pgrp_nr, p))
1426                 return -EFAULT;
1427 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1428         if (pgrp_nr < 0)
1429                 return -EINVAL;
1430         rcu_read_lock();
1431 diff -NurpP --minimal linux-3.13.10/fs/attr.c linux-3.13.10-vs2.3.6.11/fs/attr.c
1432 --- linux-3.13.10/fs/attr.c     2014-04-17 01:12:31.000000000 +0000
1433 +++ linux-3.13.10-vs2.3.6.11/fs/attr.c  2014-03-12 15:51:07.000000000 +0000
1434 @@ -15,6 +15,9 @@
1435  #include <linux/security.h>
1436  #include <linux/evm.h>
1437  #include <linux/ima.h>
1438 +#include <linux/proc_fs.h>
1439 +#include <linux/devpts_fs.h>
1440 +#include <linux/vs_tag.h>
1441  
1442  /**
1443   * inode_change_ok - check if attribute changes to an inode are allowed
1444 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1445                         return -EPERM;
1446         }
1447  
1448 +       /* check for inode tag permission */
1449 +       if (dx_permission(inode, MAY_WRITE))
1450 +               return -EACCES;
1451 +
1452         return 0;
1453  }
1454  EXPORT_SYMBOL(inode_change_ok);
1455 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1456                 inode->i_uid = attr->ia_uid;
1457         if (ia_valid & ATTR_GID)
1458                 inode->i_gid = attr->ia_gid;
1459 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1460 +               inode->i_tag = attr->ia_tag;
1461         if (ia_valid & ATTR_ATIME)
1462                 inode->i_atime = timespec_trunc(attr->ia_atime,
1463                                                 inode->i_sb->s_time_gran);
1464 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1465  
1466         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1467  
1468 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1469 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1470 +               ATTR_TAG | ATTR_TIMES_SET)) {
1471                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1472                         return -EPERM;
1473         }
1474 diff -NurpP --minimal linux-3.13.10/fs/block_dev.c linux-3.13.10-vs2.3.6.11/fs/block_dev.c
1475 --- linux-3.13.10/fs/block_dev.c        2013-11-25 15:46:58.000000000 +0000
1476 +++ linux-3.13.10-vs2.3.6.11/fs/block_dev.c     2014-01-31 20:38:03.000000000 +0000
1477 @@ -28,6 +28,7 @@
1478  #include <linux/log2.h>
1479  #include <linux/cleancache.h>
1480  #include <linux/aio.h>
1481 +#include <linux/vs_device.h>
1482  #include <asm/uaccess.h>
1483  #include "internal.h"
1484  
1485 @@ -515,6 +516,7 @@ struct block_device *bdget(dev_t dev)
1486                 bdev->bd_invalidated = 0;
1487                 inode->i_mode = S_IFBLK;
1488                 inode->i_rdev = dev;
1489 +               inode->i_mdev = dev;
1490                 inode->i_bdev = bdev;
1491                 inode->i_data.a_ops = &def_blk_aops;
1492                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1493 @@ -562,6 +564,11 @@ EXPORT_SYMBOL(bdput);
1494  static struct block_device *bd_acquire(struct inode *inode)
1495  {
1496         struct block_device *bdev;
1497 +       dev_t mdev;
1498 +
1499 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1500 +               return NULL;
1501 +       inode->i_mdev = mdev;
1502  
1503         spin_lock(&bdev_lock);
1504         bdev = inode->i_bdev;
1505 @@ -572,7 +579,7 @@ static struct block_device *bd_acquire(s
1506         }
1507         spin_unlock(&bdev_lock);
1508  
1509 -       bdev = bdget(inode->i_rdev);
1510 +       bdev = bdget(mdev);
1511         if (bdev) {
1512                 spin_lock(&bdev_lock);
1513                 if (!inode->i_bdev) {
1514 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ctree.h linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h
1515 --- linux-3.13.10/fs/btrfs/ctree.h      2014-01-22 20:39:05.000000000 +0000
1516 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h   2014-01-31 23:58:35.000000000 +0000
1517 @@ -718,11 +718,14 @@ struct btrfs_inode_item {
1518         /* modification sequence number for NFS */
1519         __le64 sequence;
1520  
1521 +       __le16 tag;
1522         /*
1523          * a little future expansion, for more than this we can
1524          * just grow the inode item and version it
1525          */
1526 -       __le64 reserved[4];
1527 +       __le16 reserved16;
1528 +       __le32 reserved32;
1529 +       __le64 reserved[3];
1530         struct btrfs_timespec atime;
1531         struct btrfs_timespec ctime;
1532         struct btrfs_timespec mtime;
1533 @@ -2000,6 +2003,8 @@ struct btrfs_ioctl_defrag_range_args {
1534  
1535  #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
1536  
1537 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1538 +
1539  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1540  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1541  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1542 @@ -2269,6 +2274,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1543  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1544  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1545  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1546 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1547  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1548  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1549  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1550 @@ -2341,6 +2347,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1551  
1552  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1553  
1554 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1555 +#define BTRFS_INODE_BARRIER            (1 << 25)
1556 +#define BTRFS_INODE_COW                        (1 << 26)
1557 +
1558  
1559  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1560  
1561 @@ -3722,6 +3732,7 @@ long btrfs_ioctl(struct file *file, unsi
1562  void btrfs_update_iflags(struct inode *inode);
1563  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1564  int btrfs_is_empty_uuid(u8 *uuid);
1565 +int btrfs_sync_flags(struct inode *inode, int, int);
1566  int btrfs_defrag_file(struct inode *inode, struct file *file,
1567                       struct btrfs_ioctl_defrag_range_args *range,
1568                       u64 newer_than, unsigned long max_pages);
1569 diff -NurpP --minimal linux-3.13.10/fs/btrfs/disk-io.c linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c
1570 --- linux-3.13.10/fs/btrfs/disk-io.c    2014-01-22 20:39:05.000000000 +0000
1571 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c 2014-01-31 20:38:03.000000000 +0000
1572 @@ -2388,6 +2388,9 @@ int open_ctree(struct super_block *sb,
1573                 goto fail_alloc;
1574         }
1575  
1576 +       if (btrfs_test_opt(tree_root, TAGGED))
1577 +               sb->s_flags |= MS_TAGGED;
1578 +
1579         features = btrfs_super_incompat_flags(disk_super) &
1580                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1581         if (features) {
1582 diff -NurpP --minimal linux-3.13.10/fs/btrfs/inode.c linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c
1583 --- linux-3.13.10/fs/btrfs/inode.c      2014-04-17 01:12:31.000000000 +0000
1584 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c   2014-03-12 15:51:07.000000000 +0000
1585 @@ -43,6 +43,7 @@
1586  #include <linux/btrfs.h>
1587  #include <linux/blkdev.h>
1588  #include <linux/posix_acl_xattr.h>
1589 +#include <linux/vs_tag.h>
1590  #include "ctree.h"
1591  #include "disk-io.h"
1592  #include "transaction.h"
1593 @@ -3317,6 +3318,9 @@ static void btrfs_read_locked_inode(stru
1594         struct btrfs_key location;
1595         int maybe_acls;
1596         u32 rdev;
1597 +       kuid_t kuid;
1598 +       kgid_t kgid;
1599 +       ktag_t ktag;
1600         int ret;
1601         bool filled = false;
1602  
1603 @@ -3344,8 +3348,14 @@ static void btrfs_read_locked_inode(stru
1604                                     struct btrfs_inode_item);
1605         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1606         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1607 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1608 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1609 +
1610 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1611 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1612 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1613 +
1614 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1615 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1616 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1617         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1618  
1619         tspec = btrfs_inode_atime(inode_item);
1620 @@ -3436,11 +3446,18 @@ static void fill_inode_item(struct btrfs
1621                             struct inode *inode)
1622  {
1623         struct btrfs_map_token token;
1624 +       uid_t uid = from_kuid(&init_user_ns,
1625 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1626 +       gid_t gid = from_kgid(&init_user_ns,
1627 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1628  
1629         btrfs_init_map_token(&token);
1630  
1631 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1632 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1633 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1634 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1635 +#ifdef CONFIG_TAGGING_INTERN
1636 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1637 +#endif
1638         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1639                                    &token);
1640         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1641 @@ -8652,14 +8669,17 @@ static const struct inode_operations btr
1642         .listxattr      = btrfs_listxattr,
1643         .removexattr    = btrfs_removexattr,
1644         .permission     = btrfs_permission,
1645 +       .sync_flags     = btrfs_sync_flags,
1646         .get_acl        = btrfs_get_acl,
1647         .set_acl        = btrfs_set_acl,
1648         .update_time    = btrfs_update_time,
1649  };
1650 +
1651  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1652         .lookup         = btrfs_lookup,
1653         .permission     = btrfs_permission,
1654 +       .sync_flags     = btrfs_sync_flags,
1655         .get_acl        = btrfs_get_acl,
1656         .set_acl        = btrfs_set_acl,
1657         .update_time    = btrfs_update_time,
1658  };
1659 @@ -8727,6 +8747,7 @@ static const struct inode_operations btr
1660         .removexattr    = btrfs_removexattr,
1661         .permission     = btrfs_permission,
1662         .fiemap         = btrfs_fiemap,
1663 +       .sync_flags     = btrfs_sync_flags,
1664         .get_acl        = btrfs_get_acl,
1665         .update_time    = btrfs_update_time,
1666  };
1667 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c
1668 --- linux-3.13.10/fs/btrfs/ioctl.c      2014-04-17 01:12:31.000000000 +0000
1669 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c   2014-02-25 11:26:09.000000000 +0000
1670 @@ -78,10 +78,13 @@ static unsigned int btrfs_flags_to_ioctl
1671  {
1672         unsigned int iflags = 0;
1673  
1674 -       if (flags & BTRFS_INODE_SYNC)
1675 -               iflags |= FS_SYNC_FL;
1676         if (flags & BTRFS_INODE_IMMUTABLE)
1677                 iflags |= FS_IMMUTABLE_FL;
1678 +       if (flags & BTRFS_INODE_IXUNLINK)
1679 +               iflags |= FS_IXUNLINK_FL;
1680 +
1681 +       if (flags & BTRFS_INODE_SYNC)
1682 +               iflags |= FS_SYNC_FL;
1683         if (flags & BTRFS_INODE_APPEND)
1684                 iflags |= FS_APPEND_FL;
1685         if (flags & BTRFS_INODE_NODUMP)
1686 @@ -98,28 +101,78 @@ static unsigned int btrfs_flags_to_ioctl
1687         else if (flags & BTRFS_INODE_NOCOMPRESS)
1688                 iflags |= FS_NOCOMP_FL;
1689  
1690 +       if (flags & BTRFS_INODE_BARRIER)
1691 +               iflags |= FS_BARRIER_FL;
1692 +       if (flags & BTRFS_INODE_COW)
1693 +               iflags |= FS_COW_FL;
1694         return iflags;
1695  }
1696  
1697  /*
1698 - * Update inode->i_flags based on the btrfs internal flags.
1699 + * Update inode->i_(v)flags based on the btrfs internal flags.
1700   */
1701  void btrfs_update_iflags(struct inode *inode)
1702  {
1703         struct btrfs_inode *ip = BTRFS_I(inode);
1704  
1705 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1706 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1707 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1708  
1709 -       if (ip->flags & BTRFS_INODE_SYNC)
1710 -               inode->i_flags |= S_SYNC;
1711         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1712                 inode->i_flags |= S_IMMUTABLE;
1713 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1714 +               inode->i_flags |= S_IXUNLINK;
1715 +
1716 +       if (ip->flags & BTRFS_INODE_SYNC)
1717 +               inode->i_flags |= S_SYNC;
1718         if (ip->flags & BTRFS_INODE_APPEND)
1719                 inode->i_flags |= S_APPEND;
1720         if (ip->flags & BTRFS_INODE_NOATIME)
1721                 inode->i_flags |= S_NOATIME;
1722         if (ip->flags & BTRFS_INODE_DIRSYNC)
1723                 inode->i_flags |= S_DIRSYNC;
1724 +
1725 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1726 +
1727 +       if (ip->flags & BTRFS_INODE_BARRIER)
1728 +               inode->i_vflags |= V_BARRIER;
1729 +       if (ip->flags & BTRFS_INODE_COW)
1730 +               inode->i_vflags |= V_COW;
1731 +}
1732 +
1733 +/*
1734 + * Update btrfs internal flags from inode->i_(v)flags.
1735 + */
1736 +void btrfs_update_flags(struct inode *inode)
1737 +{
1738 +       struct btrfs_inode *ip = BTRFS_I(inode);
1739 +
1740 +       unsigned int flags = inode->i_flags;
1741 +       unsigned int vflags = inode->i_vflags;
1742 +
1743 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1744 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1745 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1746 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1747 +
1748 +       if (flags & S_IMMUTABLE)
1749 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1750 +       if (flags & S_IXUNLINK)
1751 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1752 +
1753 +       if (flags & S_SYNC)
1754 +               ip->flags |= BTRFS_INODE_SYNC;
1755 +       if (flags & S_APPEND)
1756 +               ip->flags |= BTRFS_INODE_APPEND;
1757 +       if (flags & S_NOATIME)
1758 +               ip->flags |= BTRFS_INODE_NOATIME;
1759 +       if (flags & S_DIRSYNC)
1760 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1761 +
1762 +       if (vflags & V_BARRIER)
1763 +               ip->flags |= BTRFS_INODE_BARRIER;
1764 +       if (vflags & V_COW)
1765 +               ip->flags |= BTRFS_INODE_COW;
1766  }
1767  
1768  /*
1769 @@ -135,6 +188,7 @@ void btrfs_inherit_iflags(struct inode *
1770                 return;
1771  
1772         flags = BTRFS_I(dir)->flags;
1773 +       flags &= ~BTRFS_INODE_BARRIER;
1774  
1775         if (flags & BTRFS_INODE_NOCOMPRESS) {
1776                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1777 @@ -153,6 +207,30 @@ void btrfs_inherit_iflags(struct inode *
1778         btrfs_update_iflags(inode);
1779  }
1780  
1781 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1782 +{
1783 +       struct btrfs_inode *ip = BTRFS_I(inode);
1784 +       struct btrfs_root *root = ip->root;
1785 +       struct btrfs_trans_handle *trans;
1786 +       int ret;
1787 +
1788 +       trans = btrfs_join_transaction(root);
1789 +       BUG_ON(!trans);
1790 +
1791 +       inode->i_flags = flags;
1792 +       inode->i_vflags = vflags;
1793 +       btrfs_update_flags(inode);
1794 +
1795 +       ret = btrfs_update_inode(trans, root, inode);
1796 +       BUG_ON(ret);
1797 +
1798 +       btrfs_update_iflags(inode);
1799 +       inode->i_ctime = CURRENT_TIME;
1800 +       btrfs_end_transaction(trans, root);
1801 +
1802 +       return 0;
1803 +}
1804 +
1805  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1806  {
1807         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1808 @@ -215,21 +293,27 @@ static int btrfs_ioctl_setflags(struct f
1809  
1810         flags = btrfs_mask_flags(inode->i_mode, flags);
1811         oldflags = btrfs_flags_to_ioctl(ip->flags);
1812 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1813 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1814 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1815                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1816                         ret = -EPERM;
1817                         goto out_unlock;
1818                 }
1819         }
1820  
1821 -       if (flags & FS_SYNC_FL)
1822 -               ip->flags |= BTRFS_INODE_SYNC;
1823 -       else
1824 -               ip->flags &= ~BTRFS_INODE_SYNC;
1825         if (flags & FS_IMMUTABLE_FL)
1826                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1827         else
1828                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1829 +       if (flags & FS_IXUNLINK_FL)
1830 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1831 +       else
1832 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1833 +
1834 +       if (flags & FS_SYNC_FL)
1835 +               ip->flags |= BTRFS_INODE_SYNC;
1836 +       else
1837 +               ip->flags &= ~BTRFS_INODE_SYNC;
1838         if (flags & FS_APPEND_FL)
1839                 ip->flags |= BTRFS_INODE_APPEND;
1840         else
1841 diff -NurpP --minimal linux-3.13.10/fs/btrfs/super.c linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c
1842 --- linux-3.13.10/fs/btrfs/super.c      2014-01-22 20:39:05.000000000 +0000
1843 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c   2014-01-31 23:58:08.000000000 +0000
1844 @@ -323,7 +323,7 @@ enum {
1845         Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
1846         Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
1847         Opt_datasum, Opt_treelog, Opt_noinode_cache,
1848 -       Opt_err,
1849 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1850  };
1851  
1852  static match_table_t tokens = {
1853 @@ -365,6 +365,9 @@ static match_table_t tokens = {
1854         {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
1855         {Opt_fatal_errors, "fatal_errors=%s"},
1856         {Opt_commit_interval, "commit=%d"},
1857 +       {Opt_tag, "tag"},
1858 +       {Opt_notag, "notag"},
1859 +       {Opt_tagid, "tagid=%u"},
1860         {Opt_err, NULL},
1861  };
1862  
1863 @@ -674,6 +677,22 @@ int btrfs_parse_options(struct btrfs_roo
1864                                 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
1865                         }
1866                         break;
1867 +#ifndef CONFIG_TAGGING_NONE
1868 +               case Opt_tag:
1869 +                       printk(KERN_INFO "btrfs: use tagging\n");
1870 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1871 +                       break;
1872 +               case Opt_notag:
1873 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1874 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1875 +                       break;
1876 +#endif
1877 +#ifdef CONFIG_PROPAGATE
1878 +               case Opt_tagid:
1879 +                       /* use args[0] */
1880 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1881 +                       break;
1882 +#endif
1883                 case Opt_err:
1884                         printk(KERN_INFO "btrfs: unrecognized mount option "
1885                                "'%s'\n", p);
1886 @@ -1320,6 +1339,12 @@ static int btrfs_remount(struct super_bl
1887         btrfs_resize_thread_pool(fs_info,
1888                 fs_info->thread_pool_size, old_thread_pool_size);
1889  
1890 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1891 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1892 +                       sb->s_id);
1893 +               return -EINVAL;
1894 +       }
1895 +
1896         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1897                 goto out;
1898  
1899 diff -NurpP --minimal linux-3.13.10/fs/char_dev.c linux-3.13.10-vs2.3.6.11/fs/char_dev.c
1900 --- linux-3.13.10/fs/char_dev.c 2014-01-22 20:39:05.000000000 +0000
1901 +++ linux-3.13.10-vs2.3.6.11/fs/char_dev.c      2014-01-31 20:38:03.000000000 +0000
1902 @@ -21,6 +21,8 @@
1903  #include <linux/mutex.h>
1904  #include <linux/backing-dev.h>
1905  #include <linux/tty.h>
1906 +#include <linux/vs_context.h>
1907 +#include <linux/vs_device.h>
1908  
1909  #include "internal.h"
1910  
1911 @@ -372,14 +374,21 @@ static int chrdev_open(struct inode *ino
1912         struct cdev *p;
1913         struct cdev *new = NULL;
1914         int ret = 0;
1915 +       dev_t mdev;
1916 +
1917 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1918 +               return -EPERM;
1919 +       inode->i_mdev = mdev;
1920  
1921         spin_lock(&cdev_lock);
1922         p = inode->i_cdev;
1923         if (!p) {
1924                 struct kobject *kobj;
1925                 int idx;
1926 +
1927                 spin_unlock(&cdev_lock);
1928 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1929 +
1930 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1931                 if (!kobj)
1932                         return -ENXIO;
1933                 new = container_of(kobj, struct cdev, kobj);
1934 diff -NurpP --minimal linux-3.13.10/fs/dcache.c linux-3.13.10-vs2.3.6.11/fs/dcache.c
1935 --- linux-3.13.10/fs/dcache.c   2014-04-17 01:12:32.000000000 +0000
1936 +++ linux-3.13.10-vs2.3.6.11/fs/dcache.c        2014-04-17 01:17:10.000000000 +0000
1937 @@ -38,6 +38,7 @@
1938  #include <linux/prefetch.h>
1939  #include <linux/ratelimit.h>
1940  #include <linux/list_lru.h>
1941 +#include <linux/vs_limit.h>
1942  #include "internal.h"
1943  #include "mount.h"
1944  
1945 @@ -640,6 +641,8 @@ int d_invalidate(struct dentry * dentry)
1946                 spin_lock(&dentry->d_lock);
1947         }
1948  
1949 +       vx_dentry_dec(dentry);
1950 +
1951         /*
1952          * Somebody else still using it?
1953          *
1954 @@ -669,6 +672,7 @@ EXPORT_SYMBOL(d_invalidate);
1955  static inline void __dget_dlock(struct dentry *dentry)
1956  {
1957         dentry->d_lockref.count++;
1958 +       vx_dentry_inc(dentry);
1959  }
1960  
1961  static inline void __dget(struct dentry *dentry)
1962 @@ -1483,6 +1487,9 @@ struct dentry *__d_alloc(struct super_bl
1963         struct dentry *dentry;
1964         char *dname;
1965  
1966 +       if (!vx_dentry_avail(1))
1967 +               return NULL;
1968 +
1969         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1970         if (!dentry)
1971                 return NULL;
1972 @@ -1515,6 +1522,7 @@ struct dentry *__d_alloc(struct super_bl
1973  
1974         dentry->d_lockref.count = 1;
1975         dentry->d_flags = 0;
1976 +       vx_dentry_inc(dentry);
1977         spin_lock_init(&dentry->d_lock);
1978         seqcount_init(&dentry->d_seq);
1979         dentry->d_inode = NULL;
1980 @@ -2278,6 +2286,7 @@ struct dentry *__d_lookup(const struct d
1981                 }
1982  
1983                 dentry->d_lockref.count++;
1984 +               vx_dentry_inc(dentry);
1985                 found = dentry;
1986                 spin_unlock(&dentry->d_lock);
1987                 break;
1988 diff -NurpP --minimal linux-3.13.10/fs/devpts/inode.c linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c
1989 --- linux-3.13.10/fs/devpts/inode.c     2014-01-22 20:39:06.000000000 +0000
1990 +++ linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c  2014-02-01 01:40:53.000000000 +0000
1991 @@ -25,6 +25,7 @@
1992  #include <linux/parser.h>
1993  #include <linux/fsnotify.h>
1994  #include <linux/seq_file.h>
1995 +#include <linux/vs_base.h>
1996  
1997  #define DEVPTS_DEFAULT_MODE 0600
1998  /*
1999 @@ -36,6 +37,21 @@
2000  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2001  #define PTMX_MINOR     2
2002  
2003 +static int devpts_permission(struct inode *inode, int mask)
2004 +{
2005 +       int ret = -EACCES;
2006 +
2007 +       /* devpts is xid tagged */
2008 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2009 +               ret = generic_permission(inode, mask);
2010 +       return ret;
2011 +}
2012 +
2013 +static struct inode_operations devpts_file_inode_operations = {
2014 +       .permission     = devpts_permission,
2015 +};
2016 +
2017 +
2018  /*
2019   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2020   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2021 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2022         return 0;
2023  }
2024  
2025 +static int devpts_filter(struct dentry *de)
2026 +{
2027 +       vxid_t xid = 0;
2028 +
2029 +       /* devpts is xid tagged */
2030 +       if (de && de->d_inode)
2031 +               xid = (vxid_t)i_tag_read(de->d_inode);
2032 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2033 +       else
2034 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2035 +                       de->d_name.len, de->d_name.name);
2036 +#endif
2037 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2038 +}
2039 +
2040 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2041 +{
2042 +       return dcache_readdir_filter(filp, ctx, devpts_filter);
2043 +}
2044 +
2045 +static struct file_operations devpts_dir_operations = {
2046 +       .open           = dcache_dir_open,
2047 +       .release        = dcache_dir_close,
2048 +       .llseek         = dcache_dir_lseek,
2049 +       .read           = generic_read_dir,
2050 +       .iterate        = devpts_readdir,
2051 +};
2052 +
2053  static const struct super_operations devpts_sops = {
2054         .statfs         = simple_statfs,
2055         .remount_fs     = devpts_remount,
2056 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2057         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2058         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2059         inode->i_op = &simple_dir_inode_operations;
2060 -       inode->i_fop = &simple_dir_operations;
2061 +       inode->i_fop = &devpts_dir_operations;
2062         set_nlink(inode, 2);
2063 +       /* devpts is xid tagged */
2064 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2065  
2066         s->s_root = d_make_root(inode);
2067         if (s->s_root)
2068 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2069         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2070         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2071         init_special_inode(inode, S_IFCHR|opts->mode, device);
2072 +       /* devpts is xid tagged */
2073 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2074 +       inode->i_op = &devpts_file_inode_operations;
2075         inode->i_private = priv;
2076  
2077         sprintf(s, "%d", index);
2078 diff -NurpP --minimal linux-3.13.10/fs/ext2/balloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c
2079 --- linux-3.13.10/fs/ext2/balloc.c      2013-05-31 13:45:23.000000000 +0000
2080 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c   2014-01-31 20:38:03.000000000 +0000
2081 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2082                         start = 0;
2083                 end = EXT2_BLOCKS_PER_GROUP(sb);
2084         }
2085 -
2086         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2087  
2088  repeat:
2089 diff -NurpP --minimal linux-3.13.10/fs/ext2/ext2.h linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h
2090 --- linux-3.13.10/fs/ext2/ext2.h        2012-12-11 03:30:57.000000000 +0000
2091 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h     2014-01-31 20:38:03.000000000 +0000
2092 @@ -244,8 +244,12 @@ struct ext2_group_desc
2093  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2094  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2095  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2096 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2097  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2098  
2099 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2100 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2101 +
2102  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2103  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2104  
2105 @@ -329,7 +333,8 @@ struct ext2_inode {
2106                         __u16   i_pad1;
2107                         __le16  l_i_uid_high;   /* these 2 fields    */
2108                         __le16  l_i_gid_high;   /* were reserved2[0] */
2109 -                       __u32   l_i_reserved2;
2110 +                       __le16  l_i_tag;        /* Context Tag */
2111 +                       __u16   l_i_reserved2;
2112                 } linux2;
2113                 struct {
2114                         __u8    h_i_frag;       /* Fragment number */
2115 @@ -357,6 +362,7 @@ struct ext2_inode {
2116  #define i_gid_low      i_gid
2117  #define i_uid_high     osd2.linux2.l_i_uid_high
2118  #define i_gid_high     osd2.linux2.l_i_gid_high
2119 +#define i_raw_tag      osd2.linux2.l_i_tag
2120  #define i_reserved2    osd2.linux2.l_i_reserved2
2121  
2122  /*
2123 @@ -384,6 +390,7 @@ struct ext2_inode {
2124  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2125  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2126  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2127 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2128  
2129  
2130  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2131 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2132  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2133  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2134                        u64 start, u64 len);
2135 +extern int ext2_sync_flags(struct inode *, int, int);
2136  
2137  /* ioctl.c */
2138  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2139 diff -NurpP --minimal linux-3.13.10/fs/ext2/file.c linux-3.13.10-vs2.3.6.11/fs/ext2/file.c
2140 --- linux-3.13.10/fs/ext2/file.c        2012-12-11 03:30:57.000000000 +0000
2141 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/file.c     2014-01-31 20:38:03.000000000 +0000
2142 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2143         .setattr        = ext2_setattr,
2144         .get_acl        = ext2_get_acl,
2145         .fiemap         = ext2_fiemap,
2146 +       .sync_flags     = ext2_sync_flags,
2147  };
2148 diff -NurpP --minimal linux-3.13.10/fs/ext2/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c
2149 --- linux-3.13.10/fs/ext2/ialloc.c      2013-05-31 13:45:23.000000000 +0000
2150 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2151 @@ -17,6 +17,7 @@
2152  #include <linux/backing-dev.h>
2153  #include <linux/buffer_head.h>
2154  #include <linux/random.h>
2155 +#include <linux/vs_tag.h>
2156  #include "ext2.h"
2157  #include "xattr.h"
2158  #include "acl.h"
2159 @@ -546,6 +547,7 @@ got:
2160                 inode->i_mode = mode;
2161                 inode->i_uid = current_fsuid();
2162                 inode->i_gid = dir->i_gid;
2163 +               i_tag_write(inode, dx_current_fstag(sb));
2164         } else
2165                 inode_init_owner(inode, dir, mode);
2166  
2167 diff -NurpP --minimal linux-3.13.10/fs/ext2/inode.c linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c
2168 --- linux-3.13.10/fs/ext2/inode.c       2014-01-22 20:39:06.000000000 +0000
2169 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c    2014-01-31 20:38:03.000000000 +0000
2170 @@ -32,6 +32,7 @@
2171  #include <linux/fiemap.h>
2172  #include <linux/namei.h>
2173  #include <linux/aio.h>
2174 +#include <linux/vs_tag.h>
2175  #include "ext2.h"
2176  #include "acl.h"
2177  #include "xip.h"
2178 @@ -1182,7 +1183,7 @@ static void ext2_truncate_blocks(struct
2179                 return;
2180         if (ext2_inode_is_fast_symlink(inode))
2181                 return;
2182 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2183 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2184                 return;
2185         __ext2_truncate_blocks(inode, offset);
2186  }
2187 @@ -1273,36 +1274,61 @@ void ext2_set_inode_flags(struct inode *
2188  {
2189         unsigned int flags = EXT2_I(inode)->i_flags;
2190  
2191 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2192 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2193 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2194 +
2195 +
2196 +       if (flags & EXT2_IMMUTABLE_FL)
2197 +               inode->i_flags |= S_IMMUTABLE;
2198 +       if (flags & EXT2_IXUNLINK_FL)
2199 +               inode->i_flags |= S_IXUNLINK;
2200 +
2201         if (flags & EXT2_SYNC_FL)
2202                 inode->i_flags |= S_SYNC;
2203         if (flags & EXT2_APPEND_FL)
2204                 inode->i_flags |= S_APPEND;
2205 -       if (flags & EXT2_IMMUTABLE_FL)
2206 -               inode->i_flags |= S_IMMUTABLE;
2207         if (flags & EXT2_NOATIME_FL)
2208                 inode->i_flags |= S_NOATIME;
2209         if (flags & EXT2_DIRSYNC_FL)
2210                 inode->i_flags |= S_DIRSYNC;
2211 +
2212 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2213 +
2214 +       if (flags & EXT2_BARRIER_FL)
2215 +               inode->i_vflags |= V_BARRIER;
2216 +       if (flags & EXT2_COW_FL)
2217 +               inode->i_vflags |= V_COW;
2218  }
2219  
2220  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2221  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2222  {
2223         unsigned int flags = ei->vfs_inode.i_flags;
2224 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2225 +
2226 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2227 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2228 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2229 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2230 +
2231 +       if (flags & S_IMMUTABLE)
2232 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2233 +       if (flags & S_IXUNLINK)
2234 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2235  
2236 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2237 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2238         if (flags & S_SYNC)
2239                 ei->i_flags |= EXT2_SYNC_FL;
2240         if (flags & S_APPEND)
2241                 ei->i_flags |= EXT2_APPEND_FL;
2242 -       if (flags & S_IMMUTABLE)
2243 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2244         if (flags & S_NOATIME)
2245                 ei->i_flags |= EXT2_NOATIME_FL;
2246         if (flags & S_DIRSYNC)
2247                 ei->i_flags |= EXT2_DIRSYNC_FL;
2248 +
2249 +       if (vflags & V_BARRIER)
2250 +               ei->i_flags |= EXT2_BARRIER_FL;
2251 +       if (vflags & V_COW)
2252 +               ei->i_flags |= EXT2_COW_FL;
2253  }
2254  
2255  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2256 @@ -1338,8 +1364,10 @@ struct inode *ext2_iget (struct super_bl
2257                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2258                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2259         }
2260 -       i_uid_write(inode, i_uid);
2261 -       i_gid_write(inode, i_gid);
2262 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2263 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2264 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2265 +               le16_to_cpu(raw_inode->i_raw_tag)));
2266         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2267         inode->i_size = le32_to_cpu(raw_inode->i_size);
2268         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2269 @@ -1437,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2270         struct ext2_inode_info *ei = EXT2_I(inode);
2271         struct super_block *sb = inode->i_sb;
2272         ino_t ino = inode->i_ino;
2273 -       uid_t uid = i_uid_read(inode);
2274 -       gid_t gid = i_gid_read(inode);
2275 +       uid_t uid = from_kuid(&init_user_ns,
2276 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2277 +       gid_t gid = from_kgid(&init_user_ns,
2278 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2279         struct buffer_head * bh;
2280         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2281         int n;
2282 @@ -1474,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2283                 raw_inode->i_uid_high = 0;
2284                 raw_inode->i_gid_high = 0;
2285         }
2286 +#ifdef CONFIG_TAGGING_INTERN
2287 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2288 +#endif
2289         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2290         raw_inode->i_size = cpu_to_le32(inode->i_size);
2291         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2292 @@ -1554,7 +1587,8 @@ int ext2_setattr(struct dentry *dentry,
2293         if (is_quota_modification(inode, iattr))
2294                 dquot_initialize(inode);
2295         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2296 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2297 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2298 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2299                 error = dquot_transfer(inode, iattr);
2300                 if (error)
2301                         return error;
2302 diff -NurpP --minimal linux-3.13.10/fs/ext2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c
2303 --- linux-3.13.10/fs/ext2/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2304 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c    2014-01-31 20:38:03.000000000 +0000
2305 @@ -17,6 +17,16 @@
2306  #include <asm/uaccess.h>
2307  
2308  
2309 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2310 +{
2311 +       inode->i_flags = flags;
2312 +       inode->i_vflags = vflags;
2313 +       ext2_get_inode_flags(EXT2_I(inode));
2314 +       inode->i_ctime = CURRENT_TIME_SEC;
2315 +       mark_inode_dirty(inode);
2316 +       return 0;
2317 +}
2318 +
2319  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2320  {
2321         struct inode *inode = file_inode(filp);
2322 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2323  
2324                 flags = ext2_mask_flags(inode->i_mode, flags);
2325  
2326 +               if (IS_BARRIER(inode)) {
2327 +                       vxwprintk_task(1, "messing with the barrier.");
2328 +                       return -EACCES;
2329 +               }
2330 +
2331                 mutex_lock(&inode->i_mutex);
2332                 /* Is it quota file? Do not allow user to mess with it */
2333                 if (IS_NOQUOTA(inode)) {
2334 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2335                  *
2336                  * This test looks nicer. Thanks to Pauline Middelink
2337                  */
2338 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2339 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2340 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2341 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2342                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2343                                 mutex_unlock(&inode->i_mutex);
2344                                 ret = -EPERM;
2345 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2346                         }
2347                 }
2348  
2349 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2350 +               flags &= EXT2_FL_USER_MODIFIABLE;
2351                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2352                 ei->i_flags = flags;
2353  
2354 diff -NurpP --minimal linux-3.13.10/fs/ext2/namei.c linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c
2355 --- linux-3.13.10/fs/ext2/namei.c       2013-11-25 15:45:01.000000000 +0000
2356 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c    2014-01-31 20:38:03.000000000 +0000
2357 @@ -32,6 +32,7 @@
2358  
2359  #include <linux/pagemap.h>
2360  #include <linux/quotaops.h>
2361 +#include <linux/vs_tag.h>
2362  #include "ext2.h"
2363  #include "xattr.h"
2364  #include "acl.h"
2365 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2366                                         (unsigned long) ino);
2367                         return ERR_PTR(-EIO);
2368                 }
2369 +               dx_propagate_tag(nd, inode);
2370         }
2371         return d_splice_alias(inode, dentry);
2372  }
2373 @@ -432,5 +434,6 @@ const struct inode_operations ext2_speci
2374         .removexattr    = generic_removexattr,
2375  #endif
2376         .setattr        = ext2_setattr,
2377 +       .sync_flags     = ext2_sync_flags,
2378         .get_acl        = ext2_get_acl,
2379  };
2380 diff -NurpP --minimal linux-3.13.10/fs/ext2/super.c linux-3.13.10-vs2.3.6.11/fs/ext2/super.c
2381 --- linux-3.13.10/fs/ext2/super.c       2014-01-22 20:39:06.000000000 +0000
2382 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/super.c    2014-01-31 20:38:03.000000000 +0000
2383 @@ -395,7 +395,8 @@ enum {
2384         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2385         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2386         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2387 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2388 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2389 +       Opt_tag, Opt_notag, Opt_tagid
2390  };
2391  
2392  static const match_table_t tokens = {
2393 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2394         {Opt_acl, "acl"},
2395         {Opt_noacl, "noacl"},
2396         {Opt_xip, "xip"},
2397 +       {Opt_tag, "tag"},
2398 +       {Opt_notag, "notag"},
2399 +       {Opt_tagid, "tagid=%u"},
2400         {Opt_grpquota, "grpquota"},
2401         {Opt_ignore, "noquota"},
2402         {Opt_quota, "quota"},
2403 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2404                 case Opt_nouid32:
2405                         set_opt (sbi->s_mount_opt, NO_UID32);
2406                         break;
2407 +#ifndef CONFIG_TAGGING_NONE
2408 +               case Opt_tag:
2409 +                       set_opt (sbi->s_mount_opt, TAGGED);
2410 +                       break;
2411 +               case Opt_notag:
2412 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2413 +                       break;
2414 +#endif
2415 +#ifdef CONFIG_PROPAGATE
2416 +               case Opt_tagid:
2417 +                       /* use args[0] */
2418 +                       set_opt (sbi->s_mount_opt, TAGGED);
2419 +                       break;
2420 +#endif
2421                 case Opt_nocheck:
2422                         clear_opt (sbi->s_mount_opt, CHECK);
2423                         break;
2424 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2425         if (!parse_options((char *) data, sb))
2426                 goto failed_mount;
2427  
2428 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2429 +               sb->s_flags |= MS_TAGGED;
2430         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2431                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2432                  MS_POSIXACL : 0);
2433 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2434                 err = -EINVAL;
2435                 goto restore_opts;
2436         }
2437 +
2438 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2439 +               !(sb->s_flags & MS_TAGGED)) {
2440 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2441 +                      sb->s_id);
2442 +               err = -EINVAL;
2443 +               goto restore_opts;
2444 +       }
2445  
2446         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2447                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2448 diff -NurpP --minimal linux-3.13.10/fs/ext3/ext3.h linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h
2449 --- linux-3.13.10/fs/ext3/ext3.h        2012-12-11 03:30:57.000000000 +0000
2450 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h     2014-01-31 20:38:03.000000000 +0000
2451 @@ -151,10 +151,14 @@ struct ext3_group_desc
2452  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2453  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2454  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2455 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2456  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2457  
2458 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2459 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2460 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2461 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2462 +
2463 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2464 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2465  
2466  /* Flags that should be inherited by new inodes from their parent. */
2467  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2468 @@ -290,7 +294,8 @@ struct ext3_inode {
2469                         __u16   i_pad1;
2470                         __le16  l_i_uid_high;   /* these 2 fields    */
2471                         __le16  l_i_gid_high;   /* were reserved2[0] */
2472 -                       __u32   l_i_reserved2;
2473 +                       __le16  l_i_tag;        /* Context Tag */
2474 +                       __u16   l_i_reserved2;
2475                 } linux2;
2476                 struct {
2477                         __u8    h_i_frag;       /* Fragment number */
2478 @@ -320,6 +325,7 @@ struct ext3_inode {
2479  #define i_gid_low      i_gid
2480  #define i_uid_high     osd2.linux2.l_i_uid_high
2481  #define i_gid_high     osd2.linux2.l_i_gid_high
2482 +#define i_raw_tag      osd2.linux2.l_i_tag
2483  #define i_reserved2    osd2.linux2.l_i_reserved2
2484  
2485  /*
2486 @@ -364,6 +370,7 @@ struct ext3_inode {
2487  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2488  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2489                                                   * error in ordered mode */
2490 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2491  
2492  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2493  #ifndef _LINUX_EXT2_FS_H
2494 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2495  extern void ext3_set_aops(struct inode *inode);
2496  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2497                        u64 start, u64 len);
2498 +extern int ext3_sync_flags(struct inode *, int, int);
2499  
2500  /* ioctl.c */
2501  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2502 diff -NurpP --minimal linux-3.13.10/fs/ext3/file.c linux-3.13.10-vs2.3.6.11/fs/ext3/file.c
2503 --- linux-3.13.10/fs/ext3/file.c        2012-12-11 03:30:57.000000000 +0000
2504 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/file.c     2014-01-31 20:38:03.000000000 +0000
2505 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2506  #endif
2507         .get_acl        = ext3_get_acl,
2508         .fiemap         = ext3_fiemap,
2509 +       .sync_flags     = ext3_sync_flags,
2510  };
2511  
2512 diff -NurpP --minimal linux-3.13.10/fs/ext3/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c
2513 --- linux-3.13.10/fs/ext3/ialloc.c      2012-12-11 03:30:57.000000000 +0000
2514 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2515 @@ -14,6 +14,7 @@
2516  
2517  #include <linux/quotaops.h>
2518  #include <linux/random.h>
2519 +#include <linux/vs_tag.h>
2520  
2521  #include "ext3.h"
2522  #include "xattr.h"
2523 @@ -469,6 +470,7 @@ got:
2524                 inode->i_mode = mode;
2525                 inode->i_uid = current_fsuid();
2526                 inode->i_gid = dir->i_gid;
2527 +               i_tag_write(inode, dx_current_fstag(sb));
2528         } else
2529                 inode_init_owner(inode, dir, mode);
2530  
2531 diff -NurpP --minimal linux-3.13.10/fs/ext3/inode.c linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c
2532 --- linux-3.13.10/fs/ext3/inode.c       2013-11-25 15:45:01.000000000 +0000
2533 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c    2014-01-31 20:38:03.000000000 +0000
2534 @@ -28,6 +28,8 @@
2535  #include <linux/mpage.h>
2536  #include <linux/namei.h>
2537  #include <linux/aio.h>
2538 +#include <linux/vs_tag.h>
2539 +
2540  #include "ext3.h"
2541  #include "xattr.h"
2542  #include "acl.h"
2543 @@ -2855,36 +2857,60 @@ void ext3_set_inode_flags(struct inode *
2544  {
2545         unsigned int flags = EXT3_I(inode)->i_flags;
2546  
2547 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2548 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2549 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2550 +
2551 +       if (flags & EXT3_IMMUTABLE_FL)
2552 +               inode->i_flags |= S_IMMUTABLE;
2553 +       if (flags & EXT3_IXUNLINK_FL)
2554 +               inode->i_flags |= S_IXUNLINK;
2555 +
2556         if (flags & EXT3_SYNC_FL)
2557                 inode->i_flags |= S_SYNC;
2558         if (flags & EXT3_APPEND_FL)
2559                 inode->i_flags |= S_APPEND;
2560 -       if (flags & EXT3_IMMUTABLE_FL)
2561 -               inode->i_flags |= S_IMMUTABLE;
2562         if (flags & EXT3_NOATIME_FL)
2563                 inode->i_flags |= S_NOATIME;
2564         if (flags & EXT3_DIRSYNC_FL)
2565                 inode->i_flags |= S_DIRSYNC;
2566 +
2567 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2568 +
2569 +       if (flags & EXT3_BARRIER_FL)
2570 +               inode->i_vflags |= V_BARRIER;
2571 +       if (flags & EXT3_COW_FL)
2572 +               inode->i_vflags |= V_COW;
2573  }
2574  
2575  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2576  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2577  {
2578         unsigned int flags = ei->vfs_inode.i_flags;
2579 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2580 +
2581 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2582 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2583 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2584 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2585 +
2586 +       if (flags & S_IMMUTABLE)
2587 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2588 +       if (flags & S_IXUNLINK)
2589 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2590  
2591 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2592 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2593         if (flags & S_SYNC)
2594                 ei->i_flags |= EXT3_SYNC_FL;
2595         if (flags & S_APPEND)
2596                 ei->i_flags |= EXT3_APPEND_FL;
2597 -       if (flags & S_IMMUTABLE)
2598 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2599         if (flags & S_NOATIME)
2600                 ei->i_flags |= EXT3_NOATIME_FL;
2601         if (flags & S_DIRSYNC)
2602                 ei->i_flags |= EXT3_DIRSYNC_FL;
2603 +
2604 +       if (vflags & V_BARRIER)
2605 +               ei->i_flags |= EXT3_BARRIER_FL;
2606 +       if (vflags & V_COW)
2607 +               ei->i_flags |= EXT3_COW_FL;
2608  }
2609  
2610  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2611 @@ -2922,8 +2948,10 @@ struct inode *ext3_iget(struct super_blo
2612                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2613                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2614         }
2615 -       i_uid_write(inode, i_uid);
2616 -       i_gid_write(inode, i_gid);
2617 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2618 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2619 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2620 +               le16_to_cpu(raw_inode->i_raw_tag)));
2621         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2622         inode->i_size = le32_to_cpu(raw_inode->i_size);
2623         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2624 @@ -3095,8 +3123,10 @@ again:
2625  
2626         ext3_get_inode_flags(ei);
2627         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2628 -       i_uid = i_uid_read(inode);
2629 -       i_gid = i_gid_read(inode);
2630 +       i_uid = from_kuid(&init_user_ns,
2631 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2632 +       i_gid = from_kgid(&init_user_ns,
2633 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2634         if(!(test_opt(inode->i_sb, NO_UID32))) {
2635                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2636                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2637 @@ -3121,6 +3151,9 @@ again:
2638                 raw_inode->i_uid_high = 0;
2639                 raw_inode->i_gid_high = 0;
2640         }
2641 +#ifdef CONFIG_TAGGING_INTERN
2642 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2643 +#endif
2644         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2645         disksize = cpu_to_le32(ei->i_disksize);
2646         if (disksize != raw_inode->i_size) {
2647 @@ -3289,7 +3322,8 @@ int ext3_setattr(struct dentry *dentry,
2648         if (is_quota_modification(inode, attr))
2649                 dquot_initialize(inode);
2650         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2651 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2652 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2653 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2654                 handle_t *handle;
2655  
2656                 /* (user+group)*(old+new) structure, inode write (sb,
2657 @@ -3311,6 +3345,8 @@ int ext3_setattr(struct dentry *dentry,
2658                         inode->i_uid = attr->ia_uid;
2659                 if (attr->ia_valid & ATTR_GID)
2660                         inode->i_gid = attr->ia_gid;
2661 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2662 +                       inode->i_tag = attr->ia_tag;
2663                 error = ext3_mark_inode_dirty(handle, inode);
2664                 ext3_journal_stop(handle);
2665         }
2666 diff -NurpP --minimal linux-3.13.10/fs/ext3/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c
2667 --- linux-3.13.10/fs/ext3/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2668 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c    2014-01-31 20:38:03.000000000 +0000
2669 @@ -12,6 +12,34 @@
2670  #include <asm/uaccess.h>
2671  #include "ext3.h"
2672  
2673 +
2674 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2675 +{
2676 +       handle_t *handle = NULL;
2677 +       struct ext3_iloc iloc;
2678 +       int err;
2679 +
2680 +       handle = ext3_journal_start(inode, 1);
2681 +       if (IS_ERR(handle))
2682 +               return PTR_ERR(handle);
2683 +
2684 +       if (IS_SYNC(inode))
2685 +               handle->h_sync = 1;
2686 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2687 +       if (err)
2688 +               goto flags_err;
2689 +
2690 +       inode->i_flags = flags;
2691 +       inode->i_vflags = vflags;
2692 +       ext3_get_inode_flags(EXT3_I(inode));
2693 +       inode->i_ctime = CURRENT_TIME_SEC;
2694 +
2695 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2696 +flags_err:
2697 +       ext3_journal_stop(handle);
2698 +       return err;
2699 +}
2700 +
2701  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2702  {
2703         struct inode *inode = file_inode(filp);
2704 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2705  
2706                 flags = ext3_mask_flags(inode->i_mode, flags);
2707  
2708 +               if (IS_BARRIER(inode)) {
2709 +                       vxwprintk_task(1, "messing with the barrier.");
2710 +                       return -EACCES;
2711 +               }
2712 +
2713                 mutex_lock(&inode->i_mutex);
2714  
2715                 /* Is it quota file? Do not allow user to mess with it */
2716 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2717                  *
2718                  * This test looks nicer. Thanks to Pauline Middelink
2719                  */
2720 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2721 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2722 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2723 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2724                         if (!capable(CAP_LINUX_IMMUTABLE))
2725                                 goto flags_out;
2726                 }
2727 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2728                 if (err)
2729                         goto flags_err;
2730  
2731 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2732 +               flags &= EXT3_FL_USER_MODIFIABLE;
2733                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2734                 ei->i_flags = flags;
2735  
2736 diff -NurpP --minimal linux-3.13.10/fs/ext3/namei.c linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c
2737 --- linux-3.13.10/fs/ext3/namei.c       2013-11-25 15:46:59.000000000 +0000
2738 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c    2014-01-31 20:38:03.000000000 +0000
2739 @@ -25,6 +25,8 @@
2740   */
2741  
2742  #include <linux/quotaops.h>
2743 +#include <linux/vs_tag.h>
2744 +
2745  #include "ext3.h"
2746  #include "namei.h"
2747  #include "xattr.h"
2748 @@ -915,6 +917,7 @@ restart:
2749                                         submit_bh(READ | REQ_META | REQ_PRIO,
2750                                                   bh);
2751                                 }
2752 +               dx_propagate_tag(nd, inode);
2753                         }
2754                 }
2755                 if ((bh = bh_use[ra_ptr++]) == NULL)
2756 @@ -2568,6 +2571,7 @@ const struct inode_operations ext3_dir_i
2757         .listxattr      = ext3_listxattr,
2758         .removexattr    = generic_removexattr,
2759  #endif
2760 +       .sync_flags     = ext3_sync_flags,
2761         .get_acl        = ext3_get_acl,
2762  };
2763  
2764 diff -NurpP --minimal linux-3.13.10/fs/ext3/super.c linux-3.13.10-vs2.3.6.11/fs/ext3/super.c
2765 --- linux-3.13.10/fs/ext3/super.c       2014-01-22 20:39:06.000000000 +0000
2766 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/super.c    2014-01-31 20:38:03.000000000 +0000
2767 @@ -826,7 +826,8 @@ enum {
2768         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2769         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2770         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2771 -       Opt_resize, Opt_usrquota, Opt_grpquota
2772 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2773 +       Opt_tag, Opt_notag, Opt_tagid
2774  };
2775  
2776  static const match_table_t tokens = {
2777 @@ -884,6 +885,9 @@ static const match_table_t tokens = {
2778         {Opt_barrier, "barrier"},
2779         {Opt_nobarrier, "nobarrier"},
2780         {Opt_resize, "resize"},
2781 +       {Opt_tag, "tag"},
2782 +       {Opt_notag, "notag"},
2783 +       {Opt_tagid, "tagid=%u"},
2784         {Opt_err, NULL},
2785  };
2786  
2787 @@ -1056,6 +1060,20 @@ static int parse_options (char *options,
2788                 case Opt_nouid32:
2789                         set_opt (sbi->s_mount_opt, NO_UID32);
2790                         break;
2791 +#ifndef CONFIG_TAGGING_NONE
2792 +               case Opt_tag:
2793 +                       set_opt (sbi->s_mount_opt, TAGGED);
2794 +                       break;
2795 +               case Opt_notag:
2796 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2797 +                       break;
2798 +#endif
2799 +#ifdef CONFIG_PROPAGATE
2800 +               case Opt_tagid:
2801 +                       /* use args[0] */
2802 +                       set_opt (sbi->s_mount_opt, TAGGED);
2803 +                       break;
2804 +#endif
2805                 case Opt_nocheck:
2806                         clear_opt (sbi->s_mount_opt, CHECK);
2807                         break;
2808 @@ -1788,6 +1806,9 @@ static int ext3_fill_super (struct super
2809                             NULL, 0))
2810                 goto failed_mount;
2811  
2812 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2813 +               sb->s_flags |= MS_TAGGED;
2814 +
2815         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2816                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2817  
2818 @@ -2683,6 +2704,14 @@ static int ext3_remount (struct super_bl
2819         if (test_opt(sb, ABORT))
2820                 ext3_abort(sb, __func__, "Abort forced by user");
2821  
2822 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2823 +               !(sb->s_flags & MS_TAGGED)) {
2824 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2825 +                       sb->s_id);
2826 +               err = -EINVAL;
2827 +               goto restore_opts;
2828 +       }
2829 +
2830         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2831                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2832  
2833 diff -NurpP --minimal linux-3.13.10/fs/ext4/ext4.h linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h
2834 --- linux-3.13.10/fs/ext4/ext4.h        2014-04-17 01:12:32.000000000 +0000
2835 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h     2014-03-12 15:51:07.000000000 +0000
2836 @@ -385,7 +385,10 @@ struct flex_groups {
2837  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2838  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2839  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2840 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2841 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2842  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2843 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2844  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2845  
2846  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2847 @@ -670,7 +673,7 @@ struct ext4_inode {
2848                         __le16  l_i_uid_high;   /* these 2 fields */
2849                         __le16  l_i_gid_high;   /* were reserved2[0] */
2850                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2851 -                       __le16  l_i_reserved;
2852 +                       __le16  l_i_tag;        /* Context Tag */
2853                 } linux2;
2854                 struct {
2855                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2856 @@ -790,6 +793,7 @@ do {                                                                               \
2857  #define i_gid_low      i_gid
2858  #define i_uid_high     osd2.linux2.l_i_uid_high
2859  #define i_gid_high     osd2.linux2.l_i_gid_high
2860 +#define i_raw_tag      osd2.linux2.l_i_tag
2861  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2862  
2863  #elif defined(__GNU__)
2864 @@ -976,6 +980,7 @@ struct ext4_inode_info {
2865  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2866  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2867  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2868 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2869  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2870  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2871  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2872 @@ -2653,6 +2658,7 @@ extern struct buffer_head *ext4_get_firs
2873  extern int ext4_inline_data_fiemap(struct inode *inode,
2874                                    struct fiemap_extent_info *fieinfo,
2875                                    int *has_inline);
2876 +extern int ext4_sync_flags(struct inode *, int, int);
2877  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2878                                          struct inode *inode,
2879                                          int needed);
2880 diff -NurpP --minimal linux-3.13.10/fs/ext4/file.c linux-3.13.10-vs2.3.6.11/fs/ext4/file.c
2881 --- linux-3.13.10/fs/ext4/file.c        2013-11-25 15:46:59.000000000 +0000
2882 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/file.c     2014-01-31 20:38:03.000000000 +0000
2883 @@ -618,5 +618,6 @@ const struct inode_operations ext4_file_
2884         .removexattr    = generic_removexattr,
2885         .get_acl        = ext4_get_acl,
2886         .fiemap         = ext4_fiemap,
2887 +       .sync_flags     = ext4_sync_flags,
2888  };
2889  
2890 diff -NurpP --minimal linux-3.13.10/fs/ext4/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c
2891 --- linux-3.13.10/fs/ext4/ialloc.c      2014-01-22 20:39:06.000000000 +0000
2892 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2893 @@ -22,6 +22,7 @@
2894  #include <linux/random.h>
2895  #include <linux/bitops.h>
2896  #include <linux/blkdev.h>
2897 +#include <linux/vs_tag.h>
2898  #include <asm/byteorder.h>
2899  
2900  #include "ext4.h"
2901 @@ -731,6 +732,7 @@ struct inode *__ext4_new_inode(handle_t
2902                 inode->i_mode = mode;
2903                 inode->i_uid = current_fsuid();
2904                 inode->i_gid = dir->i_gid;
2905 +               i_tag_write(inode, dx_current_fstag(sb));
2906         } else
2907                 inode_init_owner(inode, dir, mode);
2908         dquot_initialize(inode);
2909 diff -NurpP --minimal linux-3.13.10/fs/ext4/inode.c linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c
2910 --- linux-3.13.10/fs/ext4/inode.c       2014-04-17 01:12:32.000000000 +0000
2911 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c    2014-04-17 01:28:13.000000000 +0000
2912 @@ -39,6 +39,7 @@
2913  #include <linux/ratelimit.h>
2914  #include <linux/aio.h>
2915  #include <linux/bitops.h>
2916 +#include <linux/vs_tag.h>
2917  
2918  #include "ext4_jbd2.h"
2919  #include "xattr.h"
2920 @@ -3929,42 +3930,67 @@ void ext4_set_inode_flags(struct inode *
2921         unsigned int flags = EXT4_I(inode)->i_flags;
2922         unsigned int new_fl = 0;
2923  
2924 +       if (flags & EXT4_IMMUTABLE_FL)
2925 +               new_fl |= S_IMMUTABLE;
2926 +       if (flags & EXT4_IXUNLINK_FL)
2927 +               new_fl |= S_IXUNLINK;
2928 +
2929         if (flags & EXT4_SYNC_FL)
2930                 new_fl |= S_SYNC;
2931         if (flags & EXT4_APPEND_FL)
2932                 new_fl |= S_APPEND;
2933 -       if (flags & EXT4_IMMUTABLE_FL)
2934 -               new_fl |= S_IMMUTABLE;
2935         if (flags & EXT4_NOATIME_FL)
2936                 new_fl |= S_NOATIME;
2937         if (flags & EXT4_DIRSYNC_FL)
2938                 new_fl |= S_DIRSYNC;
2939 +
2940         set_mask_bits(&inode->i_flags,
2941 -                     S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2942 +               S_IXUNLINK | S_IMMUTABLE |
2943 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC, new_fl);
2944 +
2945 +       new_fl = 0;
2946 +       if (flags & EXT4_BARRIER_FL)
2947 +               new_fl |= V_BARRIER;
2948 +       if (flags & EXT4_COW_FL)
2949 +               new_fl |= V_COW;
2950 +
2951 +       set_mask_bits(&inode->i_vflags,
2952 +               V_BARRIER | V_COW, new_fl);
2953  }
2954  
2955  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2956  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2957  {
2958 -       unsigned int vfs_fl;
2959 +       unsigned int vfs_fl, vfs_vf;
2960         unsigned long old_fl, new_fl;
2961  
2962         do {
2963                 vfs_fl = ei->vfs_inode.i_flags;
2964 +               vfs_vf = ei->vfs_inode.i_vflags;
2965                 old_fl = ei->i_flags;
2966                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2967                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2968 -                               EXT4_DIRSYNC_FL);
2969 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2970 +                               EXT4_COW_FL);
2971 +
2972 +               if (vfs_fl & S_IMMUTABLE)
2973 +                       new_fl |= EXT4_IMMUTABLE_FL;
2974 +               if (vfs_fl & S_IXUNLINK)
2975 +                       new_fl |= EXT4_IXUNLINK_FL;
2976 +
2977                 if (vfs_fl & S_SYNC)
2978                         new_fl |= EXT4_SYNC_FL;
2979                 if (vfs_fl & S_APPEND)
2980                         new_fl |= EXT4_APPEND_FL;
2981 -               if (vfs_fl & S_IMMUTABLE)
2982 -                       new_fl |= EXT4_IMMUTABLE_FL;
2983                 if (vfs_fl & S_NOATIME)
2984                         new_fl |= EXT4_NOATIME_FL;
2985                 if (vfs_fl & S_DIRSYNC)
2986                         new_fl |= EXT4_DIRSYNC_FL;
2987 +
2988 +               if (vfs_vf & V_BARRIER)
2989 +                       new_fl |= EXT4_BARRIER_FL;
2990 +               if (vfs_vf & V_COW)
2991 +                       new_fl |= EXT4_COW_FL;
2992         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
2993  }
2994  
2995 @@ -4069,8 +4095,10 @@ struct inode *ext4_iget(struct super_blo
2996                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2997                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2998         }
2999 -       i_uid_write(inode, i_uid);
3000 -       i_gid_write(inode, i_gid);
3001 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3002 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3003 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3004 +               le16_to_cpu(raw_inode->i_raw_tag)));
3005         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3006  
3007         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3008 @@ -4298,8 +4326,10 @@ static int ext4_do_update_inode(handle_t
3009  
3010         ext4_get_inode_flags(ei);
3011         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3012 -       i_uid = i_uid_read(inode);
3013 -       i_gid = i_gid_read(inode);
3014 +       i_uid = from_kuid(&init_user_ns,
3015 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3016 +       i_gid = from_kgid(&init_user_ns,
3017 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3018         if (!(test_opt(inode->i_sb, NO_UID32))) {
3019                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3020                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3021 @@ -4322,6 +4352,9 @@ static int ext4_do_update_inode(handle_t
3022                 raw_inode->i_uid_high = 0;
3023                 raw_inode->i_gid_high = 0;
3024         }
3025 +#ifdef CONFIG_TAGGING_INTERN
3026 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3027 +#endif
3028         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3029  
3030         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3031 @@ -4553,7 +4586,8 @@ int ext4_setattr(struct dentry *dentry,
3032         if (is_quota_modification(inode, attr))
3033                 dquot_initialize(inode);
3034         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3035 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3036 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3037 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3038                 handle_t *handle;
3039  
3040                 /* (user+group)*(old+new) structure, inode write (sb,
3041 @@ -4576,6 +4610,8 @@ int ext4_setattr(struct dentry *dentry,
3042                         inode->i_uid = attr->ia_uid;
3043                 if (attr->ia_valid & ATTR_GID)
3044                         inode->i_gid = attr->ia_gid;
3045 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3046 +                       inode->i_tag = attr->ia_tag;
3047                 error = ext4_mark_inode_dirty(handle, inode);
3048                 ext4_journal_stop(handle);
3049         }
3050 diff -NurpP --minimal linux-3.13.10/fs/ext4/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c
3051 --- linux-3.13.10/fs/ext4/ioctl.c       2014-04-17 01:12:32.000000000 +0000
3052 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c    2014-03-12 15:51:07.000000000 +0000
3053 @@ -14,6 +14,7 @@
3054  #include <linux/compat.h>
3055  #include <linux/mount.h>
3056  #include <linux/file.h>
3057 +#include <linux/vs_tag.h>
3058  #include <asm/uaccess.h>
3059  #include "ext4_jbd2.h"
3060  #include "ext4.h"
3061 @@ -214,6 +215,33 @@ swap_boot_out:
3062         return err;
3063  }
3064  
3065 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3066 +{
3067 +       handle_t *handle = NULL;
3068 +       struct ext4_iloc iloc;
3069 +       int err;
3070 +
3071 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3072 +       if (IS_ERR(handle))
3073 +               return PTR_ERR(handle);
3074 +
3075 +       if (IS_SYNC(inode))
3076 +               ext4_handle_sync(handle);
3077 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3078 +       if (err)
3079 +               goto flags_err;
3080 +
3081 +       inode->i_flags = flags;
3082 +       inode->i_vflags = vflags;
3083 +       ext4_get_inode_flags(EXT4_I(inode));
3084 +       inode->i_ctime = ext4_current_time(inode);
3085 +
3086 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3087 +flags_err:
3088 +       ext4_journal_stop(handle);
3089 +       return err;
3090 +}
3091 +
3092  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3093  {
3094         struct inode *inode = file_inode(filp);
3095 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3096  
3097                 flags = ext4_mask_flags(inode->i_mode, flags);
3098  
3099 +               if (IS_BARRIER(inode)) {
3100 +                       vxwprintk_task(1, "messing with the barrier.");
3101 +                       return -EACCES;
3102 +               }
3103 +
3104                 err = -EPERM;
3105                 mutex_lock(&inode->i_mutex);
3106                 /* Is it quota file? Do not allow user to mess with it */
3107 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3108                  *
3109                  * This test looks nicer. Thanks to Pauline Middelink
3110                  */
3111 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3112 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3113 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3114 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3115                         if (!capable(CAP_LINUX_IMMUTABLE))
3116                                 goto flags_out;
3117                 }
3118 diff -NurpP --minimal linux-3.13.10/fs/ext4/namei.c linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c
3119 --- linux-3.13.10/fs/ext4/namei.c       2013-11-25 15:46:59.000000000 +0000
3120 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c    2014-01-31 20:38:03.000000000 +0000
3121 @@ -34,6 +34,7 @@
3122  #include <linux/quotaops.h>
3123  #include <linux/buffer_head.h>
3124  #include <linux/bio.h>
3125 +#include <linux/vs_tag.h>
3126  #include "ext4.h"
3127  #include "ext4_jbd2.h"
3128  
3129 @@ -1299,6 +1300,7 @@ restart:
3130                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3131                                                     1, &bh);
3132                         }
3133 +               dx_propagate_tag(nd, inode);
3134                 }
3135                 if ((bh = bh_use[ra_ptr++]) == NULL)
3136                         goto next;
3137 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3138         .removexattr    = generic_removexattr,
3139         .get_acl        = ext4_get_acl,
3140         .fiemap         = ext4_fiemap,
3141 +       .sync_flags     = ext4_sync_flags,
3142  };
3143  
3144  const struct inode_operations ext4_special_inode_operations = {
3145 diff -NurpP --minimal linux-3.13.10/fs/ext4/super.c linux-3.13.10-vs2.3.6.11/fs/ext4/super.c
3146 --- linux-3.13.10/fs/ext4/super.c       2014-04-17 01:12:32.000000000 +0000
3147 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/super.c    2014-03-12 15:51:07.000000000 +0000
3148 @@ -1162,7 +1162,7 @@ enum {
3149         Opt_inode_readahead_blks, Opt_journal_ioprio,
3150         Opt_dioread_nolock, Opt_dioread_lock,
3151         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3152 -       Opt_max_dir_size_kb,
3153 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3154  };
3155  
3156  static const match_table_t tokens = {
3157 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3158         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3159         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3160         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3161 +       {Opt_tag, "tag"},
3162 +       {Opt_notag, "notag"},
3163 +       {Opt_tagid, "tagid=%u"},
3164         {Opt_err, NULL},
3165  };
3166  
3167 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3168         case Opt_i_version:
3169                 sb->s_flags |= MS_I_VERSION;
3170                 return 1;
3171 +#ifndef CONFIG_TAGGING_NONE
3172 +       case Opt_tag:
3173 +               set_opt(sb, TAGGED);
3174 +               return 1;
3175 +       case Opt_notag:
3176 +               clear_opt(sb, TAGGED);
3177 +               return 1;
3178 +#endif
3179 +#ifdef CONFIG_PROPAGATE
3180 +       case Opt_tagid:
3181 +               /* use args[0] */
3182 +               set_opt(sb, TAGGED);
3183 +               return 1;
3184 +#endif
3185         }
3186  
3187         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3188 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3189                         clear_opt(sb, DELALLOC);
3190         }
3191  
3192 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3193 +               sb->s_flags |= MS_TAGGED;
3194 +
3195         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3196                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3197  
3198 @@ -4818,6 +4838,14 @@ static int ext4_remount(struct super_blo
3199         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3200                 ext4_abort(sb, "Abort forced by user");
3201  
3202 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3203 +               !(sb->s_flags & MS_TAGGED)) {
3204 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3205 +                       sb->s_id);
3206 +               err = -EINVAL;
3207 +               goto restore_opts;
3208 +       }
3209 +
3210         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3211                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3212  
3213 diff -NurpP --minimal linux-3.13.10/fs/fcntl.c linux-3.13.10-vs2.3.6.11/fs/fcntl.c
3214 --- linux-3.13.10/fs/fcntl.c    2014-01-22 20:39:06.000000000 +0000
3215 +++ linux-3.13.10-vs2.3.6.11/fs/fcntl.c 2014-01-31 20:38:03.000000000 +0000
3216 @@ -21,6 +21,7 @@
3217  #include <linux/rcupdate.h>
3218  #include <linux/pid_namespace.h>
3219  #include <linux/user_namespace.h>
3220 +#include <linux/vs_limit.h>
3221  
3222  #include <asm/poll.h>
3223  #include <asm/siginfo.h>
3224 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3225  
3226         if (!f.file)
3227                 goto out;
3228 +       if (!vx_files_avail(1))
3229 +               goto out;
3230  
3231         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3232                 if (!check_fcntl_cmd(cmd))
3233 diff -NurpP --minimal linux-3.13.10/fs/file.c linux-3.13.10-vs2.3.6.11/fs/file.c
3234 --- linux-3.13.10/fs/file.c     2014-04-17 01:12:32.000000000 +0000
3235 +++ linux-3.13.10-vs2.3.6.11/fs/file.c  2014-02-25 11:26:09.000000000 +0000
3236 @@ -22,6 +22,7 @@
3237  #include <linux/spinlock.h>
3238  #include <linux/rcupdate.h>
3239  #include <linux/workqueue.h>
3240 +#include <linux/vs_limit.h>
3241  
3242  int sysctl_nr_open __read_mostly = 1024*1024;
3243  int sysctl_nr_open_min = BITS_PER_LONG;
3244 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3245                 struct file *f = *old_fds++;
3246                 if (f) {
3247                         get_file(f);
3248 +                       /* TODO: sum it first for check and performance */
3249 +                       vx_openfd_inc(open_files - i);
3250                 } else {
3251                         /*
3252                          * The fd may be claimed in the fd bitmap but not yet
3253 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3254                                         filp_close(file, files);
3255                                         cond_resched();
3256                                 }
3257 +                               vx_openfd_dec(i);
3258                         }
3259                         i++;
3260                         set >>= 1;
3261 +                       cond_resched();
3262                 }
3263         }
3264  }
3265 @@ -503,6 +508,7 @@ repeat:
3266         else
3267                 __clear_close_on_exec(fd, fdt);
3268         error = fd;
3269 +       vx_openfd_inc(fd);
3270  #if 1
3271         /* Sanity check */
3272         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3273 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3274         __clear_open_fd(fd, fdt);
3275         if (fd < files->next_fd)
3276                 files->next_fd = fd;
3277 +       vx_openfd_dec(fd);
3278  }
3279  
3280  void put_unused_fd(unsigned int fd)
3281 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3282  
3283         if (tofree)
3284                 filp_close(tofree, files);
3285 +       else
3286 +               vx_openfd_inc(fd);      /* fd was unused */
3287  
3288         return fd;
3289  
3290 diff -NurpP --minimal linux-3.13.10/fs/file_table.c linux-3.13.10-vs2.3.6.11/fs/file_table.c
3291 --- linux-3.13.10/fs/file_table.c       2014-01-22 20:39:06.000000000 +0000
3292 +++ linux-3.13.10-vs2.3.6.11/fs/file_table.c    2014-02-01 00:00:01.000000000 +0000
3293 @@ -26,6 +26,8 @@
3294  #include <linux/hardirq.h>
3295  #include <linux/task_work.h>
3296  #include <linux/ima.h>
3297 +#include <linux/vs_limit.h>
3298 +#include <linux/vs_context.h>
3299  
3300  #include <linux/atomic.h>
3301  
3302 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3303         spin_lock_init(&f->f_lock);
3304         eventpoll_init_file(f);
3305         /* f->f_version: 0 */
3306 +       f->f_xid = vx_current_xid();
3307 +       vx_files_inc(f);
3308         return f;
3309  
3310  over:
3311 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3312                 put_write_access(inode);
3313                 __mnt_drop_write(mnt);
3314         }
3315 +       vx_files_dec(file);
3316 +       file->f_xid = 0;
3317         file->f_path.dentry = NULL;
3318         file->f_path.mnt = NULL;
3319         file->f_inode = NULL;
3320 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3321  {
3322         if (atomic_long_dec_and_test(&file->f_count)) {
3323                 security_file_free(file);
3324 +               vx_files_dec(file);
3325 +               file->f_xid = 0;
3326                 file_free(file);
3327         }
3328  }
3329 diff -NurpP --minimal linux-3.13.10/fs/fs_struct.c linux-3.13.10-vs2.3.6.11/fs/fs_struct.c
3330 --- linux-3.13.10/fs/fs_struct.c        2014-01-22 20:39:06.000000000 +0000
3331 +++ linux-3.13.10-vs2.3.6.11/fs/fs_struct.c     2014-01-31 20:38:03.000000000 +0000
3332 @@ -4,6 +4,7 @@
3333  #include <linux/path.h>
3334  #include <linux/slab.h>
3335  #include <linux/fs_struct.h>
3336 +#include <linux/vserver/global.h>
3337  #include "internal.h"
3338  
3339  /*
3340 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3341  {
3342         path_put(&fs->root);
3343         path_put(&fs->pwd);
3344 +       atomic_dec(&vs_global_fs);
3345         kmem_cache_free(fs_cachep, fs);
3346  }
3347  
3348 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3349                 fs->pwd = old->pwd;
3350                 path_get(&fs->pwd);
3351                 spin_unlock(&old->lock);
3352 +               atomic_inc(&vs_global_fs);
3353         }
3354         return fs;
3355  }
3356 diff -NurpP --minimal linux-3.13.10/fs/gfs2/file.c linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c
3357 --- linux-3.13.10/fs/gfs2/file.c        2014-01-22 20:39:06.000000000 +0000
3358 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c     2014-01-31 20:38:03.000000000 +0000
3359 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3360         [12] = GFS2_DIF_EXHASH,
3361         [14] = GFS2_DIF_INHERIT_JDATA,
3362         [17] = GFS2_DIF_TOPDIR,
3363 +       [27] = GFS2_DIF_IXUNLINK,
3364 +       [26] = GFS2_DIF_BARRIER,
3365 +       [29] = GFS2_DIF_COW,
3366  };
3367  
3368  static const u32 gfs2_to_fsflags[32] = {
3369 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3370         [gfs2fl_ExHash] = FS_INDEX_FL,
3371         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3372         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3373 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3374 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3375 +       [gfs2fl_Cow] = FS_COW_FL,
3376  };
3377  
3378  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3379 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3380  {
3381         struct gfs2_inode *ip = GFS2_I(inode);
3382         unsigned int flags = inode->i_flags;
3383 +       unsigned int vflags = inode->i_vflags;
3384 +
3385 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3386 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3387  
3388 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3389         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3390                 inode->i_flags |= S_NOSEC;
3391         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3392                 flags |= S_IMMUTABLE;
3393 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3394 +               flags |= S_IXUNLINK;
3395 +
3396         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3397                 flags |= S_APPEND;
3398         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3399 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3400         if (ip->i_diskflags & GFS2_DIF_SYNC)
3401                 flags |= S_SYNC;
3402         inode->i_flags = flags;
3403 +
3404 +       vflags &= ~(V_BARRIER | V_COW);
3405 +
3406 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3407 +               vflags |= V_BARRIER;
3408 +       if (ip->i_diskflags & GFS2_DIF_COW)
3409 +               vflags |= V_COW;
3410 +       inode->i_vflags = vflags;
3411 +}
3412 +
3413 +void gfs2_get_inode_flags(struct inode *inode)
3414 +{
3415 +       struct gfs2_inode *ip = GFS2_I(inode);
3416 +       unsigned int flags = inode->i_flags;
3417 +       unsigned int vflags = inode->i_vflags;
3418 +
3419 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3420 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3421 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3422 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3423 +
3424 +       if (flags & S_IMMUTABLE)
3425 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3426 +       if (flags & S_IXUNLINK)
3427 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3428 +
3429 +       if (flags & S_APPEND)
3430 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3431 +       if (flags & S_NOATIME)
3432 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3433 +       if (flags & S_SYNC)
3434 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3435 +
3436 +       if (vflags & V_BARRIER)
3437 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3438 +       if (vflags & V_COW)
3439 +               ip->i_diskflags |= GFS2_DIF_COW;
3440  }
3441  
3442  /* Flags that can be set by user space */
3443 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3444         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3445  }
3446  
3447 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3448 +{
3449 +       struct gfs2_inode *ip = GFS2_I(inode);
3450 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3451 +       struct buffer_head *bh;
3452 +       struct gfs2_holder gh;
3453 +       int error;
3454 +
3455 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3456 +       if (error)
3457 +               return error;
3458 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3459 +       if (error)
3460 +               goto out;
3461 +       error = gfs2_meta_inode_buffer(ip, &bh);
3462 +       if (error)
3463 +               goto out_trans_end;
3464 +       gfs2_trans_add_meta(ip->i_gl, bh);
3465 +       inode->i_flags = flags;
3466 +       inode->i_vflags = vflags;
3467 +       gfs2_get_inode_flags(inode);
3468 +       gfs2_dinode_out(ip, bh->b_data);
3469 +       brelse(bh);
3470 +       gfs2_set_aops(inode);
3471 +out_trans_end:
3472 +       gfs2_trans_end(sdp);
3473 +out:
3474 +       gfs2_glock_dq_uninit(&gh);
3475 +       return error;
3476 +}
3477 +
3478  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3479  {
3480         switch(cmd) {
3481 diff -NurpP --minimal linux-3.13.10/fs/gfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h
3482 --- linux-3.13.10/fs/gfs2/inode.h       2013-11-25 15:45:01.000000000 +0000
3483 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h    2014-01-31 20:38:03.000000000 +0000
3484 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3485  extern const struct file_operations gfs2_dir_fops_nolock;
3486  
3487  extern void gfs2_set_inode_flags(struct inode *inode);
3488 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3489   
3490  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3491  extern const struct file_operations gfs2_file_fops;
3492 diff -NurpP --minimal linux-3.13.10/fs/hostfs/hostfs.h linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h
3493 --- linux-3.13.10/fs/hostfs/hostfs.h    2012-12-11 03:30:57.000000000 +0000
3494 +++ linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h 2014-01-31 20:38:03.000000000 +0000
3495 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3496         unsigned short  ia_mode;
3497         uid_t           ia_uid;
3498         gid_t           ia_gid;
3499 +       vtag_t          ia_tag;
3500         loff_t          ia_size;
3501         struct timespec ia_atime;
3502         struct timespec ia_mtime;
3503 diff -NurpP --minimal linux-3.13.10/fs/inode.c linux-3.13.10-vs2.3.6.11/fs/inode.c
3504 --- linux-3.13.10/fs/inode.c    2014-01-22 20:39:06.000000000 +0000
3505 +++ linux-3.13.10-vs2.3.6.11/fs/inode.c 2014-01-31 23:33:47.000000000 +0000
3506 @@ -18,6 +18,7 @@
3507  #include <linux/buffer_head.h> /* for inode_has_buffers */
3508  #include <linux/ratelimit.h>
3509  #include <linux/list_lru.h>
3510 +#include <linux/vs_tag.h>
3511  #include "internal.h"
3512  
3513  /*
3514 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3515         struct address_space *const mapping = &inode->i_data;
3516  
3517         inode->i_sb = sb;
3518 +
3519 +       /* essential because of inode slab reuse */
3520         inode->i_blkbits = sb->s_blocksize_bits;
3521         inode->i_flags = 0;
3522         atomic_set(&inode->i_count, 1);
3523 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3524         inode->i_opflags = 0;
3525         i_uid_write(inode, 0);
3526         i_gid_write(inode, 0);
3527 +       i_tag_write(inode, 0);
3528         atomic_set(&inode->i_writecount, 0);
3529         inode->i_size = 0;
3530         inode->i_blocks = 0;
3531 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3532         inode->i_bdev = NULL;
3533         inode->i_cdev = NULL;
3534         inode->i_rdev = 0;
3535 +       inode->i_mdev = 0;
3536         inode->dirtied_when = 0;
3537  
3538         if (security_inode_alloc(inode))
3539 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3540  }
3541  EXPORT_SYMBOL(__insert_inode_hash);
3542  
3543 +EXPORT_SYMBOL_GPL(__iget);
3544 +
3545  /**
3546   *     __remove_inode_hash - remove an inode from the hash
3547   *     @inode: inode to unhash
3548 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3549         if (S_ISCHR(mode)) {
3550                 inode->i_fop = &def_chr_fops;
3551                 inode->i_rdev = rdev;
3552 +               inode->i_mdev = rdev;
3553         } else if (S_ISBLK(mode)) {
3554                 inode->i_fop = &def_blk_fops;
3555                 inode->i_rdev = rdev;
3556 +               inode->i_mdev = rdev;
3557         } else if (S_ISFIFO(mode))
3558                 inode->i_fop = &pipefifo_fops;
3559         else if (S_ISSOCK(mode))
3560 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3561         } else
3562                 inode->i_gid = current_fsgid();
3563         inode->i_mode = mode;
3564 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3565  }
3566  EXPORT_SYMBOL(inode_init_owner);
3567  
3568 diff -NurpP --minimal linux-3.13.10/fs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ioctl.c
3569 --- linux-3.13.10/fs/ioctl.c    2014-01-22 20:39:06.000000000 +0000
3570 +++ linux-3.13.10-vs2.3.6.11/fs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3571 @@ -15,6 +15,9 @@
3572  #include <linux/writeback.h>
3573  #include <linux/buffer_head.h>
3574  #include <linux/falloc.h>
3575 +#include <linux/proc_fs.h>
3576 +#include <linux/vserver/inode.h>
3577 +#include <linux/vs_tag.h>
3578  
3579  #include <asm/ioctls.h>
3580  
3581 diff -NurpP --minimal linux-3.13.10/fs/ioprio.c linux-3.13.10-vs2.3.6.11/fs/ioprio.c
3582 --- linux-3.13.10/fs/ioprio.c   2012-12-11 03:30:57.000000000 +0000
3583 +++ linux-3.13.10-vs2.3.6.11/fs/ioprio.c        2014-01-31 20:38:03.000000000 +0000
3584 @@ -28,6 +28,7 @@
3585  #include <linux/syscalls.h>
3586  #include <linux/security.h>
3587  #include <linux/pid_namespace.h>
3588 +#include <linux/vs_base.h>
3589  
3590  int set_task_ioprio(struct task_struct *task, int ioprio)
3591  {
3592 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3593                         else
3594                                 pgrp = find_vpid(who);
3595                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3596 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3597 +                                       continue;
3598                                 ret = set_task_ioprio(p, ioprio);
3599                                 if (ret)
3600                                         break;
3601 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3602                         else
3603                                 pgrp = find_vpid(who);
3604                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3605 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3606 +                                       continue;
3607                                 tmpio = get_task_ioprio(p);
3608                                 if (tmpio < 0)
3609                                         continue;
3610 diff -NurpP --minimal linux-3.13.10/fs/jfs/file.c linux-3.13.10-vs2.3.6.11/fs/jfs/file.c
3611 --- linux-3.13.10/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3612 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/file.c      2014-01-31 20:38:03.000000000 +0000
3613 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3614         if (is_quota_modification(inode, iattr))
3615                 dquot_initialize(inode);
3616         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3617 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3618 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3619 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3620                 rc = dquot_transfer(inode, iattr);
3621                 if (rc)
3622                         return rc;
3623 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3624  #ifdef CONFIG_JFS_POSIX_ACL
3625         .get_acl        = jfs_get_acl,
3626  #endif
3627 +       .sync_flags     = jfs_sync_flags,
3628  };
3629  
3630  const struct file_operations jfs_file_operations = {
3631 diff -NurpP --minimal linux-3.13.10/fs/jfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c
3632 --- linux-3.13.10/fs/jfs/ioctl.c        2013-05-31 13:45:24.000000000 +0000
3633 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c     2014-01-31 20:38:03.000000000 +0000
3634 @@ -12,6 +12,7 @@
3635  #include <linux/time.h>
3636  #include <linux/sched.h>
3637  #include <linux/blkdev.h>
3638 +#include <linux/mount.h>
3639  #include <asm/current.h>
3640  #include <asm/uaccess.h>
3641  
3642 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3643  }
3644  
3645  
3646 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3647 +{
3648 +       inode->i_flags = flags;
3649 +       inode->i_vflags = vflags;
3650 +       jfs_get_inode_flags(JFS_IP(inode));
3651 +       inode->i_ctime = CURRENT_TIME_SEC;
3652 +       mark_inode_dirty(inode);
3653 +       return 0;
3654 +}
3655 +
3656  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3657  {
3658         struct inode *inode = file_inode(filp);
3659 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3660                 if (!S_ISDIR(inode->i_mode))
3661                         flags &= ~JFS_DIRSYNC_FL;
3662  
3663 +               if (IS_BARRIER(inode)) {
3664 +                       vxwprintk_task(1, "messing with the barrier.");
3665 +                       return -EACCES;
3666 +               }
3667 +
3668                 /* Is it quota file? Do not allow user to mess with it */
3669                 if (IS_NOQUOTA(inode)) {
3670                         err = -EPERM;
3671 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3672                  * the relevant capability.
3673                  */
3674                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3675 -                       ((flags ^ oldflags) &
3676 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3677 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3678 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3679                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3680                                 mutex_unlock(&inode->i_mutex);
3681                                 err = -EPERM;
3682 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3683                         }
3684                 }
3685  
3686 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3687 +               flags &= JFS_FL_USER_MODIFIABLE;
3688                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3689                 jfs_inode->mode2 = flags;
3690  
3691 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_dinode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h
3692 --- linux-3.13.10/fs/jfs/jfs_dinode.h   2012-12-11 03:30:57.000000000 +0000
3693 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h        2014-01-31 20:38:03.000000000 +0000
3694 @@ -161,9 +161,13 @@ struct dinode {
3695  
3696  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3697  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3698 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3699  
3700 -#define JFS_FL_USER_VISIBLE    0x03F80000
3701 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3702 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3703 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3704 +
3705 +#define JFS_FL_USER_VISIBLE    0x07F80000
3706 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3707  #define JFS_FL_INHERIT         0x03C80000
3708  
3709  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3710 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_filsys.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h
3711 --- linux-3.13.10/fs/jfs/jfs_filsys.h   2012-12-11 03:30:57.000000000 +0000
3712 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h        2014-01-31 20:38:03.000000000 +0000
3713 @@ -266,6 +266,7 @@
3714  #define JFS_NAME_MAX   255
3715  #define JFS_PATH_MAX   BPSIZE
3716  
3717 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3718  
3719  /*
3720   *     file system state (superblock state)
3721 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_imap.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c
3722 --- linux-3.13.10/fs/jfs/jfs_imap.c     2013-11-25 15:45:01.000000000 +0000
3723 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c  2014-01-31 20:38:03.000000000 +0000
3724 @@ -46,6 +46,7 @@
3725  #include <linux/pagemap.h>
3726  #include <linux/quotaops.h>
3727  #include <linux/slab.h>
3728 +#include <linux/vs_tag.h>
3729  
3730  #include "jfs_incore.h"
3731  #include "jfs_inode.h"
3732 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3733  {
3734         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3735         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3736 +       kuid_t kuid;
3737 +       kgid_t kgid;
3738  
3739         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3740         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3741 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3742         }
3743         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3744  
3745 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3746 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3747 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3748 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3749 +
3750 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3751         if (!uid_valid(sbi->uid))
3752                 ip->i_uid = jfs_ip->saved_uid;
3753         else {
3754                 ip->i_uid = sbi->uid;
3755         }
3756  
3757 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3758 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3759         if (!gid_valid(sbi->gid))
3760                 ip->i_gid = jfs_ip->saved_gid;
3761         else {
3762 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3763         dip->di_size = cpu_to_le64(ip->i_size);
3764         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3765         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3766 -       if (!uid_valid(sbi->uid))
3767 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3768 -       else
3769 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3770 -                                                  jfs_ip->saved_uid));
3771 -       if (!gid_valid(sbi->gid))
3772 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3773 -       else
3774 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3775 -                                                   jfs_ip->saved_gid));
3776 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3777 +               TAGINO_KUID(DX_TAG(ip),
3778 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3779 +               ip->i_tag)));
3780 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3781 +               TAGINO_KGID(DX_TAG(ip),
3782 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3783 +               ip->i_tag)));
3784         jfs_get_inode_flags(jfs_ip);
3785         /*
3786          * mode2 is only needed for storing the higher order bits.
3787 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c
3788 --- linux-3.13.10/fs/jfs/jfs_inode.c    2013-11-25 15:46:59.000000000 +0000
3789 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c 2014-01-31 20:38:03.000000000 +0000
3790 @@ -18,6 +18,7 @@
3791  
3792  #include <linux/fs.h>
3793  #include <linux/quotaops.h>
3794 +#include <linux/vs_tag.h>
3795  #include "jfs_incore.h"
3796  #include "jfs_inode.h"
3797  #include "jfs_filsys.h"
3798 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3799  {
3800         unsigned int flags = JFS_IP(inode)->mode2;
3801  
3802 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3803 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3804 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3805 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3806  
3807         if (flags & JFS_IMMUTABLE_FL)
3808                 inode->i_flags |= S_IMMUTABLE;
3809 +       if (flags & JFS_IXUNLINK_FL)
3810 +               inode->i_flags |= S_IXUNLINK;
3811 +
3812 +       if (flags & JFS_SYNC_FL)
3813 +               inode->i_flags |= S_SYNC;
3814         if (flags & JFS_APPEND_FL)
3815                 inode->i_flags |= S_APPEND;
3816         if (flags & JFS_NOATIME_FL)
3817                 inode->i_flags |= S_NOATIME;
3818         if (flags & JFS_DIRSYNC_FL)
3819                 inode->i_flags |= S_DIRSYNC;
3820 -       if (flags & JFS_SYNC_FL)
3821 -               inode->i_flags |= S_SYNC;
3822 +
3823 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3824 +
3825 +       if (flags & JFS_BARRIER_FL)
3826 +               inode->i_vflags |= V_BARRIER;
3827 +       if (flags & JFS_COW_FL)
3828 +               inode->i_vflags |= V_COW;
3829  }
3830  
3831  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3832  {
3833         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3834 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3835 +
3836 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3837 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3838 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3839 +                          JFS_BARRIER_FL | JFS_COW_FL);
3840  
3841 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3842 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3843         if (flags & S_IMMUTABLE)
3844                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3845 +       if (flags & S_IXUNLINK)
3846 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3847 +
3848         if (flags & S_APPEND)
3849                 jfs_ip->mode2 |= JFS_APPEND_FL;
3850         if (flags & S_NOATIME)
3851 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3852                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3853         if (flags & S_SYNC)
3854                 jfs_ip->mode2 |= JFS_SYNC_FL;
3855 +
3856 +       if (vflags & V_BARRIER)
3857 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3858 +       if (vflags & V_COW)
3859 +               jfs_ip->mode2 |= JFS_COW_FL;
3860  }
3861  
3862  /*
3863 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h
3864 --- linux-3.13.10/fs/jfs/jfs_inode.h    2012-12-11 03:30:57.000000000 +0000
3865 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h 2014-01-31 20:38:03.000000000 +0000
3866 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3867  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3868         int fh_len, int fh_type);
3869  extern void jfs_set_inode_flags(struct inode *);
3870 +extern int jfs_sync_flags(struct inode *, int, int);
3871  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3872  extern int jfs_setattr(struct dentry *, struct iattr *);
3873  
3874 diff -NurpP --minimal linux-3.13.10/fs/jfs/namei.c linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c
3875 --- linux-3.13.10/fs/jfs/namei.c        2013-11-25 15:45:01.000000000 +0000
3876 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c     2014-01-31 20:38:03.000000000 +0000
3877 @@ -22,6 +22,7 @@
3878  #include <linux/ctype.h>
3879  #include <linux/quotaops.h>
3880  #include <linux/exportfs.h>
3881 +#include <linux/vs_tag.h>
3882  #include "jfs_incore.h"
3883  #include "jfs_superblock.h"
3884  #include "jfs_inode.h"
3885 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3886                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3887         }
3888  
3889 +       dx_propagate_tag(nd, ip);
3890         return d_splice_alias(ip, dentry);
3891  }
3892  
3893 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3894  #ifdef CONFIG_JFS_POSIX_ACL
3895         .get_acl        = jfs_get_acl,
3896  #endif
3897 +       .sync_flags     = jfs_sync_flags,
3898  };
3899  
3900  const struct file_operations jfs_dir_operations = {
3901 diff -NurpP --minimal linux-3.13.10/fs/jfs/super.c linux-3.13.10-vs2.3.6.11/fs/jfs/super.c
3902 --- linux-3.13.10/fs/jfs/super.c        2013-11-25 15:45:01.000000000 +0000
3903 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/super.c     2014-01-31 20:38:03.000000000 +0000
3904 @@ -203,7 +203,8 @@ enum {
3905         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3906         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3907         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3908 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3909 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3910 +       Opt_tag, Opt_notag, Opt_tagid
3911  };
3912  
3913  static const match_table_t tokens = {
3914 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3915         {Opt_resize, "resize=%u"},
3916         {Opt_resize_nosize, "resize"},
3917         {Opt_errors, "errors=%s"},
3918 +       {Opt_tag, "tag"},
3919 +       {Opt_notag, "notag"},
3920 +       {Opt_tagid, "tagid=%u"},
3921 +       {Opt_tag, "tagxid"},
3922         {Opt_ignore, "noquota"},
3923         {Opt_ignore, "quota"},
3924         {Opt_usrquota, "usrquota"},
3925 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3926                         }
3927                         break;
3928                 }
3929 -
3930 +#ifndef CONFIG_TAGGING_NONE
3931 +               case Opt_tag:
3932 +                       *flag |= JFS_TAGGED;
3933 +                       break;
3934 +               case Opt_notag:
3935 +                       *flag &= JFS_TAGGED;
3936 +                       break;
3937 +#endif
3938 +#ifdef CONFIG_PROPAGATE
3939 +               case Opt_tagid:
3940 +                       /* use args[0] */
3941 +                       *flag |= JFS_TAGGED;
3942 +                       break;
3943 +#endif
3944                 default:
3945                         printk("jfs: Unrecognized mount option \"%s\" "
3946                                         " or missing value\n", p);
3947 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3948                 return -EINVAL;
3949         }
3950  
3951 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3952 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3953 +                       sb->s_id);
3954 +               return -EINVAL;
3955 +       }
3956 +
3957         if (newLVSize) {
3958                 if (sb->s_flags & MS_RDONLY) {
3959                         pr_err("JFS: resize requires volume" \
3960 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3961  #ifdef CONFIG_JFS_POSIX_ACL
3962         sb->s_flags |= MS_POSIXACL;
3963  #endif
3964 +       /* map mount option tagxid */
3965 +       if (sbi->flag & JFS_TAGGED)
3966 +               sb->s_flags |= MS_TAGGED;
3967  
3968         if (newLVSize) {
3969                 pr_err("resize option for remount only\n");
3970 diff -NurpP --minimal linux-3.13.10/fs/libfs.c linux-3.13.10-vs2.3.6.11/fs/libfs.c
3971 --- linux-3.13.10/fs/libfs.c    2014-01-22 20:39:06.000000000 +0000
3972 +++ linux-3.13.10-vs2.3.6.11/fs/libfs.c 2014-02-01 01:35:46.000000000 +0000
3973 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3974   * both impossible due to the lock on directory.
3975   */
3976  
3977 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3978 +static inline int do_dcache_readdir_filter(struct file *filp,
3979 +       struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3980  {
3981 -       struct dentry *dentry = file->f_path.dentry;
3982 -       struct dentry *cursor = file->private_data;
3983 +       struct dentry *dentry = filp->f_path.dentry;
3984 +       struct dentry *cursor = filp->private_data;
3985         struct list_head *p, *q = &cursor->d_u.d_child;
3986  
3987 -       if (!dir_emit_dots(file, ctx))
3988 +       if (!dir_emit_dots(filp, ctx))
3989                 return 0;
3990         spin_lock(&dentry->d_lock);
3991         if (ctx->pos == 2)
3992 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
3993  
3994         for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
3995                 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
3996 +               if (filter && !filter(next))
3997 +                       continue;
3998                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
3999                 if (!simple_positive(next)) {
4000                         spin_unlock(&next->d_lock);
4001 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4002         spin_unlock(&dentry->d_lock);
4003         return 0;
4004  }
4005 +
4006  EXPORT_SYMBOL(dcache_readdir);
4007  
4008 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4009 +{
4010 +       return do_dcache_readdir_filter(filp, ctx, NULL);
4011 +}
4012 +
4013 +EXPORT_SYMBOL(dcache_readdir_filter);
4014 +
4015 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4016 +       int (*filter)(struct dentry *))
4017 +{
4018 +       return do_dcache_readdir_filter(filp, ctx, filter);
4019 +}
4020 +
4021  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4022  {
4023         return -EISDIR;
4024 diff -NurpP --minimal linux-3.13.10/fs/locks.c linux-3.13.10-vs2.3.6.11/fs/locks.c
4025 --- linux-3.13.10/fs/locks.c    2014-01-22 20:39:06.000000000 +0000
4026 +++ linux-3.13.10-vs2.3.6.11/fs/locks.c 2014-01-31 23:51:55.000000000 +0000
4027 @@ -129,6 +129,8 @@
4028  #include <linux/hashtable.h>
4029  #include <linux/percpu.h>
4030  #include <linux/lglock.h>
4031 +#include <linux/vs_base.h>
4032 +#include <linux/vs_limit.h>
4033  
4034  #include <asm/uaccess.h>
4035  
4036 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4037  /* Allocate an empty lock structure. */
4038  struct file_lock *locks_alloc_lock(void)
4039  {
4040 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4041 +       struct file_lock *fl;
4042  
4043 -       if (fl)
4044 -               locks_init_lock_heads(fl);
4045 +       if (!vx_locks_avail(1))
4046 +               return NULL;
4047  
4048 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4049 +
4050 +       if (fl) {
4051 +               locks_init_lock_heads(fl);
4052 +               fl->fl_xid = -1;
4053 +       }
4054         return fl;
4055  }
4056  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4057 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4058         BUG_ON(!list_empty(&fl->fl_block));
4059         BUG_ON(!hlist_unhashed(&fl->fl_link));
4060  
4061 +       vx_locks_dec(fl);
4062         locks_release_private(fl);
4063         kmem_cache_free(filelock_cache, fl);
4064  }
4065 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4066  {
4067         memset(fl, 0, sizeof(struct file_lock));
4068         locks_init_lock_heads(fl);
4069 +       fl->fl_xid = -1;
4070  }
4071  
4072  EXPORT_SYMBOL(locks_init_lock);
4073 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4074         new->fl_file = fl->fl_file;
4075         new->fl_ops = fl->fl_ops;
4076         new->fl_lmops = fl->fl_lmops;
4077 +       new->fl_xid = fl->fl_xid;
4078  
4079         locks_copy_private(new, fl);
4080  }
4081 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4082         fl->fl_flags = FL_FLOCK;
4083         fl->fl_type = type;
4084         fl->fl_end = OFFSET_MAX;
4085 +
4086 +       vxd_assert(filp->f_xid == vx_current_xid(),
4087 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4088 +       fl->fl_xid = filp->f_xid;
4089 +       vx_locks_inc(fl);
4090         
4091         *lock = fl;
4092         return 0;
4093 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4094  
4095         fl->fl_owner = current->files;
4096         fl->fl_pid = current->tgid;
4097 +       fl->fl_xid = vx_current_xid();
4098  
4099         fl->fl_file = filp;
4100         fl->fl_flags = FL_LEASE;
4101 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4102         if (fl == NULL)
4103                 return ERR_PTR(error);
4104  
4105 +       fl->fl_xid = vx_current_xid();
4106 +       if (filp)
4107 +               vxd_assert(filp->f_xid == fl->fl_xid,
4108 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4109 +       vx_locks_inc(fl);
4110         error = lease_init(filp, type, fl);
4111         if (error) {
4112                 locks_free_lock(fl);
4113 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4114                 spin_lock(&inode->i_lock);
4115         }
4116  
4117 +       new_fl->fl_xid = -1;
4118  find_conflict:
4119         for_each_lock(inode, before) {
4120                 struct file_lock *fl = *before;
4121 @@ -878,6 +901,7 @@ find_conflict:
4122                 goto out;
4123         locks_copy_lock(new_fl, request);
4124         locks_insert_lock(before, new_fl);
4125 +       vx_locks_inc(new_fl);
4126         new_fl = NULL;
4127         error = 0;
4128  
4129 @@ -888,7 +912,8 @@ out:
4130         return error;
4131  }
4132  
4133 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4134 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4135 +       struct file_lock *conflock, vxid_t xid)
4136  {
4137         struct file_lock *fl;
4138         struct file_lock *new_fl = NULL;
4139 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4140         int error;
4141         bool added = false;
4142  
4143 +       vxd_assert(xid == vx_current_xid(),
4144 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4145         /*
4146          * We may need two file_lock structures for this operation,
4147          * so we get them in advance to avoid races.
4148 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4149             (request->fl_type != F_UNLCK ||
4150              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4151                 new_fl = locks_alloc_lock();
4152 +               new_fl->fl_xid = xid;
4153 +               vx_locks_inc(new_fl);
4154                 new_fl2 = locks_alloc_lock();
4155 +               new_fl2->fl_xid = xid;
4156 +               vx_locks_inc(new_fl2);
4157         }
4158  
4159         spin_lock(&inode->i_lock);
4160 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4161  int posix_lock_file(struct file *filp, struct file_lock *fl,
4162                         struct file_lock *conflock)
4163  {
4164 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4165 +       return __posix_lock_file(file_inode(filp),
4166 +               fl, conflock, filp->f_xid);
4167  }
4168  EXPORT_SYMBOL(posix_lock_file);
4169  
4170 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4171         fl.fl_end = offset + count - 1;
4172  
4173         for (;;) {
4174 -               error = __posix_lock_file(inode, &fl, NULL);
4175 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4176                 if (error != FILE_LOCK_DEFERRED)
4177                         break;
4178                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4179 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4180                 goto out;
4181  
4182         locks_insert_lock(before, lease);
4183 +       vx_locks_inc(lease);
4184         error = 0;
4185  out:
4186         if (is_deleg)
4187 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4188         if (file_lock == NULL)
4189                 return -ENOLCK;
4190  
4191 +       vxd_assert(filp->f_xid == vx_current_xid(),
4192 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4193 +       file_lock->fl_xid = filp->f_xid;
4194 +       vx_locks_inc(file_lock);
4195 +
4196         /*
4197          * This might block, so we do it before checking the inode.
4198          */
4199 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4200         if (file_lock == NULL)
4201                 return -ENOLCK;
4202  
4203 +       vxd_assert(filp->f_xid == vx_current_xid(),
4204 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4205 +       file_lock->fl_xid = filp->f_xid;
4206 +       vx_locks_inc(file_lock);
4207 +
4208         /*
4209          * This might block, so we do it before checking the inode.
4210          */
4211 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4212  
4213         lock_get_status(f, fl, iter->li_pos, "");
4214  
4215 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4216 -               lock_get_status(f, bfl, iter->li_pos, " ->");
4217 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4218 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4219 +                       continue;
4220 +               lock_get_status(f, bfl, iter->li_pos, " ->");
4221 +       }
4222  
4223         return 0;
4224  }
4225 diff -NurpP --minimal linux-3.13.10/fs/mount.h linux-3.13.10-vs2.3.6.11/fs/mount.h
4226 --- linux-3.13.10/fs/mount.h    2014-04-17 01:12:32.000000000 +0000
4227 +++ linux-3.13.10-vs2.3.6.11/fs/mount.h 2014-04-17 01:17:10.000000000 +0000
4228 @@ -57,6 +57,7 @@ struct mount {
4229         int mnt_expiry_mark;            /* true if marked for expiry */
4230         int mnt_pinned;
4231         struct path mnt_ex_mountpoint;
4232 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4233  };
4234  
4235  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4236 diff -NurpP --minimal linux-3.13.10/fs/namei.c linux-3.13.10-vs2.3.6.11/fs/namei.c
4237 --- linux-3.13.10/fs/namei.c    2014-04-17 01:12:32.000000000 +0000
4238 +++ linux-3.13.10-vs2.3.6.11/fs/namei.c 2014-04-17 01:17:10.000000000 +0000
4239 @@ -34,9 +34,19 @@
4240  #include <linux/device_cgroup.h>
4241  #include <linux/fs_struct.h>
4242  #include <linux/posix_acl.h>
4243 +#include <linux/proc_fs.h>
4244 +#include <linux/magic.h>
4245 +#include <linux/vserver/inode.h>
4246 +#include <linux/vs_base.h>
4247 +#include <linux/vs_tag.h>
4248 +#include <linux/vs_cowbl.h>
4249 +#include <linux/vs_device.h>
4250 +#include <linux/vs_context.h>
4251 +#include <linux/pid_namespace.h>
4252  #include <asm/uaccess.h>
4253  
4254  #include "internal.h"
4255 +#include "proc/internal.h"
4256  #include "mount.h"
4257  
4258  /* [Feb-1997 T. Schoebel-Theuer]
4259 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4260         return -EAGAIN;
4261  }
4262  
4263 +static inline int dx_barrier(const struct inode *inode)
4264 +{
4265 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4266 +               vxwprintk_task(1, "did hit the barrier.");
4267 +               return 1;
4268 +       }
4269 +       return 0;
4270 +}
4271 +
4272 +static int __dx_permission(const struct inode *inode, int mask)
4273 +{
4274 +       if (dx_barrier(inode))
4275 +               return -EACCES;
4276 +
4277 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4278 +               /* devpts is xid tagged */
4279 +               if (S_ISDIR(inode->i_mode) ||
4280 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4281 +                       return 0;
4282 +
4283 +               /* just pretend we didn't find anything */
4284 +               return -ENOENT;
4285 +       }
4286 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4287 +               struct proc_dir_entry *de = PDE(inode);
4288 +
4289 +               if (de && !vx_hide_check(0, de->vx_flags))
4290 +                       goto out;
4291 +
4292 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4293 +                       struct pid *pid;
4294 +                       struct task_struct *tsk;
4295 +
4296 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4297 +                           vx_flags(VXF_STATE_SETUP, 0))
4298 +                               return 0;
4299 +
4300 +                       pid = PROC_I(inode)->pid;
4301 +                       if (!pid)
4302 +                               goto out;
4303 +
4304 +                       rcu_read_lock();
4305 +                       tsk = pid_task(pid, PIDTYPE_PID);
4306 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4307 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4308 +                       if (tsk &&
4309 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4310 +                               rcu_read_unlock();
4311 +                               return 0;
4312 +                       }
4313 +                       rcu_read_unlock();
4314 +               }
4315 +               else {
4316 +                       /* FIXME: Should we block some entries here? */
4317 +                       return 0;
4318 +               }
4319 +       }
4320 +       else {
4321 +               if (dx_notagcheck(inode->i_sb) ||
4322 +                   dx_check((vxid_t)i_tag_read(inode),
4323 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4324 +                       return 0;
4325 +       }
4326 +
4327 +out:
4328 +       return -EACCES;
4329 +}
4330 +
4331 +int dx_permission(const struct inode *inode, int mask)
4332 +{
4333 +       int ret = __dx_permission(inode, mask);
4334 +       if (unlikely(ret)) {
4335 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4336 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4337 +#endif
4338 +                   vxwprintk_task(1,
4339 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4340 +                       mask, inode->i_sb->s_id, inode,
4341 +                       i_tag_read(inode), inode->i_ino);
4342 +       }
4343 +       return ret;
4344 +}
4345 +
4346  /*
4347   * This does the basic permission checking
4348   */
4349 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4350                 /*
4351                  * Nobody gets write access to an immutable file.
4352                  */
4353 -               if (IS_IMMUTABLE(inode))
4354 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4355                         return -EACCES;
4356         }
4357  
4358 +       retval = dx_permission(inode, mask);
4359 +       if (retval)
4360 +               return retval;
4361 +
4362         retval = do_inode_permission(inode, mask);
4363         if (retval)
4364                 return retval;
4365 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4366  
4367                 if (nd->path.dentry == nd->root.dentry &&
4368                     nd->path.mnt == nd->root.mnt) {
4369 -                       break;
4370 +                       /* for sane '/' avoid follow_mount() */
4371 +                       return;
4372                 }
4373                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4374                         /* rare case of legitimate dget_parent()... */
4375 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4376                                 goto unlazy;
4377                         }
4378                 }
4379 +
4380 +               /* FIXME: check dx permission */
4381 +
4382                 path->mnt = mnt;
4383                 path->dentry = dentry;
4384                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4385 @@ -1413,6 +1514,8 @@ unlazy:
4386                 }
4387         }
4388  
4389 +       /* FIXME: check dx permission */
4390 +
4391         path->mnt = mnt;
4392         path->dentry = dentry;
4393         err = follow_managed(path, nd->flags);
4394 @@ -2400,7 +2503,7 @@ static int may_delete(struct inode *dir,
4395                 return -EPERM;
4396  
4397         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4398 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4399 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4400                 return -EPERM;
4401         if (isdir) {
4402                 if (!d_is_directory(victim) && !d_is_autodir(victim))
4403 @@ -2480,19 +2583,25 @@ int vfs_create(struct inode *dir, struct
4404                 bool want_excl)
4405  {
4406         int error = may_create(dir, dentry);
4407 -       if (error)
4408 +       if (error) {
4409 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4410                 return error;
4411 +       }
4412  
4413         if (!dir->i_op->create)
4414                 return -EACCES; /* shouldn't it be ENOSYS? */
4415         mode &= S_IALLUGO;
4416         mode |= S_IFREG;
4417         error = security_inode_create(dir, dentry, mode);
4418 -       if (error)
4419 +       if (error) {
4420 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4421                 return error;
4422 +       }
4423         error = dir->i_op->create(dir, dentry, mode, want_excl);
4424         if (!error)
4425                 fsnotify_create(dir, dentry);
4426 +       else
4427 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4428         return error;
4429  }
4430  
4431 @@ -2527,6 +2636,15 @@ static int may_open(struct path *path, i
4432                 break;
4433         }
4434  
4435 +#ifdef CONFIG_VSERVER_COWBL
4436 +       if (IS_COW(inode) &&
4437 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4438 +               if (IS_COW_LINK(inode))
4439 +                       return -EMLINK;
4440 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4441 +               mark_inode_dirty(inode);
4442 +       }
4443 +#endif
4444         error = inode_permission(inode, acc_mode);
4445         if (error)
4446                 return error;
4447 @@ -3022,6 +3140,16 @@ finish_open:
4448         }
4449  finish_open_created:
4450         error = may_open(&nd->path, acc_mode, open_flag);
4451 +#ifdef CONFIG_VSERVER_COWBL
4452 +       if (error == -EMLINK) {
4453 +               struct dentry *dentry;
4454 +               dentry = cow_break_link(name->name);
4455 +               if (IS_ERR(dentry))
4456 +                       error = PTR_ERR(dentry);
4457 +               else
4458 +                       dput(dentry);
4459 +       }
4460 +#endif
4461         if (error)
4462                 goto out;
4463         file->f_path.mnt = nd->path.mnt;
4464 @@ -3147,6 +3275,7 @@ static struct file *path_openat(int dfd,
4465         int opened = 0;
4466         int error;
4467  
4468 +restart:
4469         file = get_empty_filp();
4470         if (IS_ERR(file))
4471                 return file;
4472 @@ -3188,6 +3317,16 @@ static struct file *path_openat(int dfd,
4473                 error = do_last(nd, &path, file, op, &opened, pathname);
4474                 put_link(nd, &link, cookie);
4475         }
4476 +
4477 +#ifdef CONFIG_VSERVER_COWBL
4478 +       if (error == -EMLINK) {
4479 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4480 +                       path_put(&nd->root);
4481 +               if (base)
4482 +                       fput(base);
4483 +               goto restart;
4484 +       }
4485 +#endif
4486  out:
4487         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4488                 path_put(&nd->root);
4489 @@ -3303,6 +3442,11 @@ struct dentry *kern_path_create(int dfd,
4490                 goto fail;
4491         }
4492         *path = nd.path;
4493 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4494 +               path->dentry, path->dentry->d_name.len,
4495 +               path->dentry->d_name.name, dentry,
4496 +               dentry->d_name.len, dentry->d_name.name,
4497 +               path->dentry->d_inode);
4498         return dentry;
4499  fail:
4500         dput(dentry);
4501 @@ -3850,7 +3994,7 @@ int vfs_link(struct dentry *old_dentry,
4502         /*
4503          * A link to an append-only or immutable file cannot be created.
4504          */
4505 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4506 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4507                 return -EPERM;
4508         if (!dir->i_op->link)
4509                 return -EPERM;
4510 @@ -4305,6 +4449,288 @@ int generic_readlink(struct dentry *dent
4511         return res;
4512  }
4513  
4514 +
4515 +#ifdef CONFIG_VSERVER_COWBL
4516 +
4517 +static inline
4518 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4519 +{
4520 +       loff_t ppos = 0;
4521 +       loff_t opos = 0;
4522 +
4523 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4524 +}
4525 +
4526 +struct dentry *cow_break_link(const char *pathname)
4527 +{
4528 +       int ret, mode, pathlen, redo = 0, drop = 1;
4529 +       struct nameidata old_nd, dir_nd;
4530 +       struct path dir_path, *old_path, *new_path;
4531 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4532 +       struct file *old_file;
4533 +       struct file *new_file;
4534 +       char *to, *path, pad='\251';
4535 +       loff_t size;
4536 +
4537 +       vxdprintk(VXD_CBIT(misc, 1),
4538 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4539 +
4540 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4541 +       ret = -ENOMEM;
4542 +       if (!path)
4543 +               goto out;
4544 +
4545 +       /* old_nd.path will have refs to dentry and mnt */
4546 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4547 +       vxdprintk(VXD_CBIT(misc, 2),
4548 +               "do_path_lookup(old): %d", ret);
4549 +       if (ret < 0)
4550 +               goto out_free_path;
4551 +
4552 +       /* dentry/mnt refs handed over to old_path */
4553 +       old_path = &old_nd.path;
4554 +       /* no explicit reference for old_dentry here */
4555 +       old_dentry = old_path->dentry;
4556 +
4557 +       mode = old_dentry->d_inode->i_mode;
4558 +       to = d_path(old_path, path, PATH_MAX-2);
4559 +       pathlen = strlen(to);
4560 +       vxdprintk(VXD_CBIT(misc, 2),
4561 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4562 +               old_dentry,
4563 +               old_dentry->d_name.len, old_dentry->d_name.name,
4564 +               old_dentry->d_name.len);
4565 +
4566 +       to[pathlen + 1] = 0;
4567 +retry:
4568 +       new_dentry = NULL;
4569 +       to[pathlen] = pad--;
4570 +       ret = -ELOOP;
4571 +       if (pad <= '\240')
4572 +               goto out_rel_old;
4573 +
4574 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4575 +
4576 +       /* dir_nd.path will have refs to dentry and mnt */
4577 +       ret = do_path_lookup(AT_FDCWD, to,
4578 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4579 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4580 +       if (ret < 0)
4581 +               goto retry;
4582 +
4583 +       /* this puppy downs the dir inode mutex if successful.
4584 +          dir_path will hold refs to dentry and mnt and
4585 +          we'll have write access to the mnt */
4586 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4587 +       if (!new_dentry || IS_ERR(new_dentry)) {
4588 +               path_put(&dir_nd.path);
4589 +               vxdprintk(VXD_CBIT(misc, 2),
4590 +                       "kern_path_create(new) failed with %ld",
4591 +                       PTR_ERR(new_dentry));
4592 +               goto retry;
4593 +       }
4594 +       vxdprintk(VXD_CBIT(misc, 2),
4595 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4596 +               new_dentry,
4597 +               new_dentry->d_name.len, new_dentry->d_name.name,
4598 +               new_dentry->d_name.len);
4599 +
4600 +       /* take a reference on new_dentry */
4601 +       dget(new_dentry);
4602 +
4603 +       /* dentry/mnt refs handed over to new_path */
4604 +       new_path = &dir_path;
4605 +
4606 +       /* dentry for old/new dir */
4607 +       dir = dir_nd.path.dentry;
4608 +
4609 +       /* give up reference on dir */
4610 +       dput(new_path->dentry);
4611 +
4612 +       /* new_dentry already has a reference */
4613 +       new_path->dentry = new_dentry;
4614 +
4615 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4616 +       vxdprintk(VXD_CBIT(misc, 2),
4617 +               "vfs_create(new): %d", ret);
4618 +       if (ret == -EEXIST) {
4619 +               path_put(&dir_nd.path);
4620 +               mutex_unlock(&dir->d_inode->i_mutex);
4621 +               mnt_drop_write(new_path->mnt);
4622 +               path_put(new_path);
4623 +               new_dentry = NULL;
4624 +               goto retry;
4625 +       }
4626 +       else if (ret < 0)
4627 +               goto out_unlock_new;
4628 +
4629 +       /* drop out early, ret passes ENOENT */
4630 +       ret = -ENOENT;
4631 +       if ((redo = d_unhashed(old_dentry)))
4632 +               goto out_unlock_new;
4633 +
4634 +       /* doesn't change refs for old_path */
4635 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4636 +       vxdprintk(VXD_CBIT(misc, 2),
4637 +               "dentry_open(old): %p", old_file);
4638 +       if (IS_ERR(old_file)) {
4639 +               ret = PTR_ERR(old_file);
4640 +               goto out_unlock_new;
4641 +       }
4642 +
4643 +       /* doesn't change refs for new_path */
4644 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4645 +       vxdprintk(VXD_CBIT(misc, 2),
4646 +               "dentry_open(new): %p", new_file);
4647 +       if (IS_ERR(new_file)) {
4648 +               ret = PTR_ERR(new_file);
4649 +               goto out_fput_old;
4650 +       }
4651 +
4652 +       /* unlock the inode mutex from kern_path_create() */
4653 +       mutex_unlock(&dir->d_inode->i_mutex);
4654 +
4655 +       /* drop write access to mnt */
4656 +       mnt_drop_write(new_path->mnt);
4657 +
4658 +       drop = 0;
4659 +
4660 +       size = i_size_read(old_file->f_dentry->d_inode);
4661 +       ret = do_cow_splice(old_file, new_file, size);
4662 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4663 +       if (ret < 0) {
4664 +               goto out_fput_both;
4665 +       } else if (ret < size) {
4666 +               ret = -ENOSPC;
4667 +               goto out_fput_both;
4668 +       } else {
4669 +               struct inode *old_inode = old_dentry->d_inode;
4670 +               struct inode *new_inode = new_dentry->d_inode;
4671 +               struct iattr attr = {
4672 +                       .ia_uid = old_inode->i_uid,
4673 +                       .ia_gid = old_inode->i_gid,
4674 +                       .ia_valid = ATTR_UID | ATTR_GID
4675 +                       };
4676 +
4677 +               setattr_copy(new_inode, &attr);
4678 +               mark_inode_dirty(new_inode);
4679 +       }
4680 +
4681 +       /* lock rename mutex */
4682 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4683 +
4684 +       /* drop out late */
4685 +       ret = -ENOENT;
4686 +       if ((redo = d_unhashed(old_dentry)))
4687 +               goto out_unlock;
4688 +
4689 +       vxdprintk(VXD_CBIT(misc, 2),
4690 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4691 +               new_dentry->d_name.len, new_dentry->d_name.name,
4692 +               new_dentry->d_name.len,
4693 +               old_dentry->d_name.len, old_dentry->d_name.name,
4694 +               old_dentry->d_name.len);
4695 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4696 +               old_dentry->d_parent->d_inode, old_dentry, NULL);
4697 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4698 +
4699 +out_unlock:
4700 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4701 +
4702 +out_fput_both:
4703 +       vxdprintk(VXD_CBIT(misc, 3),
4704 +               "fput(new_file=%p[#%ld])", new_file,
4705 +               atomic_long_read(&new_file->f_count));
4706 +       fput(new_file);
4707 +
4708 +out_fput_old:
4709 +       vxdprintk(VXD_CBIT(misc, 3),
4710 +               "fput(old_file=%p[#%ld])", old_file,
4711 +               atomic_long_read(&old_file->f_count));
4712 +       fput(old_file);
4713 +
4714 +out_unlock_new:
4715 +       /* drop references from dir_nd.path */
4716 +       path_put(&dir_nd.path);
4717 +
4718 +       if (drop) {
4719 +               /* unlock the inode mutex from kern_path_create() */
4720 +               mutex_unlock(&dir->d_inode->i_mutex);
4721 +
4722 +               /* drop write access to mnt */
4723 +               mnt_drop_write(new_path->mnt);
4724 +       }
4725 +
4726 +       if (!ret)
4727 +               goto out_redo;
4728 +
4729 +       /* error path cleanup */
4730 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4731 +
4732 +out_redo:
4733 +       if (!redo)
4734 +               goto out_rel_both;
4735 +
4736 +       /* lookup dentry once again
4737 +          old_nd.path will be freed as old_path in out_rel_old */
4738 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4739 +       if (ret)
4740 +               goto out_rel_both;
4741 +
4742 +       /* drop reference on new_dentry */
4743 +       dput(new_dentry);
4744 +       new_dentry = old_path->dentry;
4745 +       dget(new_dentry);
4746 +       vxdprintk(VXD_CBIT(misc, 2),
4747 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4748 +               new_dentry,
4749 +               new_dentry->d_name.len, new_dentry->d_name.name,
4750 +               new_dentry->d_name.len);
4751 +
4752 +out_rel_both:
4753 +       if (new_path)
4754 +               path_put(new_path);
4755 +out_rel_old:
4756 +       path_put(old_path);
4757 +out_free_path:
4758 +       kfree(path);
4759 +out:
4760 +       if (ret) {
4761 +               dput(new_dentry);
4762 +               new_dentry = ERR_PTR(ret);
4763 +       }
4764 +       vxdprintk(VXD_CBIT(misc, 3),
4765 +               "cow_break_link returning with %p", new_dentry);
4766 +       return new_dentry;
4767 +}
4768 +
4769 +#endif
4770 +
4771 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4772 +{
4773 +       struct path path;
4774 +       struct vfsmount *vmnt;
4775 +       char *pstr, *root;
4776 +       int length = 0;
4777 +
4778 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4779 +       if (!pstr)
4780 +               return 0;
4781 +
4782 +       vmnt = &ns->root->mnt;
4783 +       path.mnt = vmnt;
4784 +       path.dentry = vmnt->mnt_root;
4785 +       root = d_path(&path, pstr, PATH_MAX - 2);
4786 +       length = sprintf(buffer + length,
4787 +               "Namespace:\t%p [#%u]\n"
4788 +               "RootPath:\t%s\n",
4789 +               ns, atomic_read(&ns->count),
4790 +               root);
4791 +       kfree(pstr);
4792 +       return length;
4793 +}
4794 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4795 +
4796  /* get the link contents into pagecache */
4797  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4798  {
4799 diff -NurpP --minimal linux-3.13.10/fs/namespace.c linux-3.13.10-vs2.3.6.11/fs/namespace.c
4800 --- linux-3.13.10/fs/namespace.c        2014-04-17 01:12:32.000000000 +0000
4801 +++ linux-3.13.10-vs2.3.6.11/fs/namespace.c     2014-04-17 01:18:37.000000000 +0000
4802 @@ -24,6 +24,11 @@
4803  #include <linux/proc_ns.h>
4804  #include <linux/magic.h>
4805  #include <linux/bootmem.h>
4806 +#include <linux/vs_base.h>
4807 +#include <linux/vs_context.h>
4808 +#include <linux/vs_tag.h>
4809 +#include <linux/vserver/space.h>
4810 +#include <linux/vserver/global.h>
4811  #include "pnode.h"
4812  #include "internal.h"
4813  
4814 @@ -839,6 +844,10 @@ vfs_kern_mount(struct file_system_type *
4815         if (!type)
4816                 return ERR_PTR(-ENODEV);
4817  
4818 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4819 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4820 +               return ERR_PTR(-EPERM);
4821 +
4822         mnt = alloc_vfsmnt(name);
4823         if (!mnt)
4824                 return ERR_PTR(-ENOMEM);
4825 @@ -899,6 +908,7 @@ static struct mount *clone_mnt(struct mo
4826         mnt->mnt.mnt_root = dget(root);
4827         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4828         mnt->mnt_parent = mnt;
4829 +       mnt->mnt_tag = old->mnt_tag;
4830         lock_mount_hash();
4831         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4832         unlock_mount_hash();
4833 @@ -1369,7 +1379,8 @@ static int do_umount(struct mount *mnt,
4834   */
4835  static inline bool may_mount(void)
4836  {
4837 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4838 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4839 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4840  }
4841  
4842  /*
4843 @@ -1785,6 +1796,7 @@ static int do_change_type(struct path *p
4844                 if (err)
4845                         goto out_unlock;
4846         }
4847 +       // mnt->mnt_flags = mnt_flags;
4848  
4849         lock_mount_hash();
4850         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4851 @@ -1813,12 +1825,14 @@ static bool has_locked_children(struct m
4852   * do loopback mount.
4853   */
4854  static int do_loopback(struct path *path, const char *old_name,
4855 -                               int recurse)
4856 +       vtag_t tag, unsigned long flags, int mnt_flags)
4857  {
4858         struct path old_path;
4859         struct mount *mnt = NULL, *old, *parent;
4860         struct mountpoint *mp;
4861 +       int recurse = flags & MS_REC;
4862         int err;
4863 +
4864         if (!old_name || !*old_name)
4865                 return -EINVAL;
4866         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4867 @@ -1898,7 +1912,7 @@ static int change_mount_flags(struct vfs
4868   * on it - tough luck.
4869   */
4870  static int do_remount(struct path *path, int flags, int mnt_flags,
4871 -                     void *data)
4872 +       void *data, vxid_t xid)
4873  {
4874         int err;
4875         struct super_block *sb = path->mnt->mnt_sb;
4876 @@ -2377,6 +2391,7 @@ long do_mount(const char *dev_name, cons
4877         struct path path;
4878         int retval = 0;
4879         int mnt_flags = 0;
4880 +       vtag_t tag = 0;
4881  
4882         /* Discard magic */
4883         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4884 @@ -2406,6 +2421,12 @@ long do_mount(const char *dev_name, cons
4885         if (!(flags & MS_NOATIME))
4886                 mnt_flags |= MNT_RELATIME;
4887  
4888 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4889 +               /* FIXME: bind and re-mounts get the tag flag? */
4890 +               if (flags & (MS_BIND|MS_REMOUNT))
4891 +                       flags |= MS_TAGID;
4892 +       }
4893 +
4894         /* Separate the per-mountpoint flags */
4895         if (flags & MS_NOSUID)
4896                 mnt_flags |= MNT_NOSUID;
4897 @@ -2422,15 +2443,17 @@ long do_mount(const char *dev_name, cons
4898         if (flags & MS_RDONLY)
4899                 mnt_flags |= MNT_READONLY;
4900  
4901 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4902 +               mnt_flags |= MNT_NODEV;
4903         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4904                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4905                    MS_STRICTATIME);
4906  
4907         if (flags & MS_REMOUNT)
4908                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4909 -                                   data_page);
4910 +                                   data_page, tag);
4911         else if (flags & MS_BIND)
4912 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4913 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4914         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4915                 retval = do_change_type(&path, flags);
4916         else if (flags & MS_MOVE)
4917 @@ -2546,6 +2569,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4918                         p = next_mnt(p, old);
4919         }
4920         namespace_unlock();
4921 +       atomic_inc(&vs_global_mnt_ns);
4922  
4923         if (rootmnt)
4924                 mntput(rootmnt);
4925 @@ -2727,9 +2751,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4926         new_mnt = real_mount(new.mnt);
4927         root_mnt = real_mount(root.mnt);
4928         old_mnt = real_mount(old.mnt);
4929 -       if (IS_MNT_SHARED(old_mnt) ||
4930 +       if ((IS_MNT_SHARED(old_mnt) ||
4931                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4932 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4933 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4934 +               !vx_flags(VXF_STATE_SETUP, 0))
4935                 goto out4;
4936         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4937                 goto out4;
4938 @@ -2859,6 +2884,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4939         if (!atomic_dec_and_test(&ns->count))
4940                 return;
4941         drop_collected_mounts(&ns->root->mnt);
4942 +       atomic_dec(&vs_global_mnt_ns);
4943         free_mnt_ns(ns);
4944  }
4945  
4946 diff -NurpP --minimal linux-3.13.10/fs/nfs/client.c linux-3.13.10-vs2.3.6.11/fs/nfs/client.c
4947 --- linux-3.13.10/fs/nfs/client.c       2014-01-22 20:39:06.000000000 +0000
4948 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/client.c    2014-01-31 20:38:03.000000000 +0000
4949 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4950         if (server->flags & NFS_MOUNT_SOFT)
4951                 server->client->cl_softrtry = 1;
4952  
4953 +       server->client->cl_tag = 0;
4954 +       if (server->flags & NFS_MOUNT_TAGGED)
4955 +               server->client->cl_tag = 1;
4956         return 0;
4957  }
4958  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4959 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4960                 server->acdirmin = server->acdirmax = 0;
4961         }
4962  
4963 +       /* FIXME: needs fsinfo
4964 +       if (server->flags & NFS_MOUNT_TAGGED)
4965 +               sb->s_flags |= MS_TAGGED;       */
4966 +
4967         server->maxfilesize = fsinfo->maxfilesize;
4968  
4969         server->time_delta = fsinfo->time_delta;
4970 diff -NurpP --minimal linux-3.13.10/fs/nfs/dir.c linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c
4971 --- linux-3.13.10/fs/nfs/dir.c  2014-04-17 01:12:32.000000000 +0000
4972 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c       2014-02-25 11:26:10.000000000 +0000
4973 @@ -37,6 +37,7 @@
4974  #include <linux/sched.h>
4975  #include <linux/kmemleak.h>
4976  #include <linux/xattr.h>
4977 +#include <linux/vs_tag.h>
4978  
4979  #include "delegation.h"
4980  #include "iostat.h"
4981 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
4982         /* Success: notify readdir to use READDIRPLUS */
4983         nfs_advise_use_readdirplus(dir);
4984  
4985 +       dx_propagate_tag(nd, inode);
4986  no_entry:
4987         res = d_materialise_unique(dentry, inode);
4988         if (res != NULL) {
4989 diff -NurpP --minimal linux-3.13.10/fs/nfs/inode.c linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c
4990 --- linux-3.13.10/fs/nfs/inode.c        2014-04-17 01:12:32.000000000 +0000
4991 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c     2014-03-12 15:51:07.000000000 +0000
4992 @@ -38,6 +38,7 @@
4993  #include <linux/slab.h>
4994  #include <linux/compat.h>
4995  #include <linux/freezer.h>
4996 +#include <linux/vs_tag.h>
4997  
4998  #include <asm/uaccess.h>
4999  
5000 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5001         if (inode->i_state & I_NEW) {
5002                 struct nfs_inode *nfsi = NFS_I(inode);
5003                 unsigned long now = jiffies;
5004 +               kuid_t kuid;
5005 +               kgid_t kgid;
5006  
5007                 /* We set i_ino for the few things that still rely on it,
5008                  * such as stat(2) */
5009 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5010                 inode->i_version = 0;
5011                 inode->i_size = 0;
5012                 clear_nlink(inode);
5013 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5014 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5015 +               kuid = make_kuid(&init_user_ns, -2);
5016 +               kgid = make_kgid(&init_user_ns, -2);
5017                 inode->i_blocks = 0;
5018                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5019                 nfsi->write_io = 0;
5020 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5021                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5022                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5023                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5024 -                       inode->i_uid = fattr->uid;
5025 +                       kuid = fattr->uid;
5026                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5027                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5028                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5029 -                       inode->i_gid = fattr->gid;
5030 +                       kgid = fattr->gid;
5031                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5032                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5033                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5034 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5035                          */
5036                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5037                 }
5038 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5039 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5040 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5041 +                               /* maybe fattr->xid someday */
5042  
5043                 nfs_setsecurity(inode, fattr, label);
5044  
5045 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5046                         inode->i_uid = attr->ia_uid;
5047                 if ((attr->ia_valid & ATTR_GID) != 0)
5048                         inode->i_gid = attr->ia_gid;
5049 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5050 +                       inode->i_tag = attr->ia_tag;
5051                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5052                 spin_unlock(&inode->i_lock);
5053         }
5054 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5055         struct nfs_inode *nfsi = NFS_I(inode);
5056         loff_t cur_size, new_isize;
5057         unsigned long invalid = 0;
5058 -
5059 +       kuid_t kuid;
5060 +       kgid_t kgid;
5061 +       ktag_t ktag;
5062  
5063         if (nfs_have_delegated_attributes(inode))
5064                 return 0;
5065 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5066                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5067         }
5068  
5069 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5070 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5071 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5072 +
5073         /* Have any file permissions changed? */
5074         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5075                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5076 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5077 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5078                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5079 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5080 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5081                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5082 +               /* maybe check for tag too? */
5083  
5084         /* Has the link count changed? */
5085         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5086 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5087         unsigned long invalid = 0;
5088         unsigned long now = jiffies;
5089         unsigned long save_cache_validity;
5090 +       kuid_t kuid;
5091 +       kgid_t kgid;
5092 +       ktag_t ktag;
5093  
5094         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5095                         __func__, inode->i_sb->s_id, inode->i_ino,
5096 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5097                                 | NFS_INO_REVAL_PAGECACHE
5098                                 | NFS_INO_REVAL_FORCED);
5099  
5100 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5101 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5102 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5103  
5104         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5105                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5106 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5107                                 | NFS_INO_INVALID_ACL
5108                                 | NFS_INO_REVAL_FORCED);
5109  
5110 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5111 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5112 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5113 +
5114         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5115                 if (inode->i_nlink != fattr->nlink) {
5116                         invalid |= NFS_INO_INVALID_ATTR;
5117 diff -NurpP --minimal linux-3.13.10/fs/nfs/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c
5118 --- linux-3.13.10/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5119 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c   2014-01-31 20:38:03.000000000 +0000
5120 @@ -20,6 +20,7 @@
5121  #include <linux/nfs3.h>
5122  #include <linux/nfs_fs.h>
5123  #include <linux/nfsacl.h>
5124 +#include <linux/vs_tag.h>
5125  #include "internal.h"
5126  
5127  #define NFSDBG_FACILITY                NFSDBG_XDR
5128 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5129   *             set_mtime       mtime;
5130   *     };
5131   */
5132 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5133 +static void encode_sattr3(struct xdr_stream *xdr,
5134 +       const struct iattr *attr, int tag)
5135  {
5136         u32 nbytes;
5137         __be32 *p;
5138 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5139         } else
5140                 *p++ = xdr_zero;
5141  
5142 -       if (attr->ia_valid & ATTR_UID) {
5143 +       if (attr->ia_valid & ATTR_UID ||
5144 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5145                 *p++ = xdr_one;
5146 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5147 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5148 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5149         } else
5150                 *p++ = xdr_zero;
5151  
5152 -       if (attr->ia_valid & ATTR_GID) {
5153 +       if (attr->ia_valid & ATTR_GID ||
5154 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5155                 *p++ = xdr_one;
5156 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5157 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5158 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5159         } else
5160                 *p++ = xdr_zero;
5161  
5162 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5163                                       const struct nfs3_sattrargs *args)
5164  {
5165         encode_nfs_fh3(xdr, args->fh);
5166 -       encode_sattr3(xdr, args->sattr);
5167 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5168         encode_sattrguard3(xdr, args);
5169  }
5170  
5171 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5172   *     };
5173   */
5174  static void encode_createhow3(struct xdr_stream *xdr,
5175 -                             const struct nfs3_createargs *args)
5176 +       const struct nfs3_createargs *args, int tag)
5177  {
5178         encode_uint32(xdr, args->createmode);
5179         switch (args->createmode) {
5180         case NFS3_CREATE_UNCHECKED:
5181         case NFS3_CREATE_GUARDED:
5182 -               encode_sattr3(xdr, args->sattr);
5183 +               encode_sattr3(xdr, args->sattr, tag);
5184                 break;
5185         case NFS3_CREATE_EXCLUSIVE:
5186                 encode_createverf3(xdr, args->verifier);
5187 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5188                                      const struct nfs3_createargs *args)
5189  {
5190         encode_diropargs3(xdr, args->fh, args->name, args->len);
5191 -       encode_createhow3(xdr, args);
5192 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5193  }
5194  
5195  /*
5196 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5197                                     const struct nfs3_mkdirargs *args)
5198  {
5199         encode_diropargs3(xdr, args->fh, args->name, args->len);
5200 -       encode_sattr3(xdr, args->sattr);
5201 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5202  }
5203  
5204  /*
5205 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5206   *     };
5207   */
5208  static void encode_symlinkdata3(struct xdr_stream *xdr,
5209 -                               const struct nfs3_symlinkargs *args)
5210 +       const struct nfs3_symlinkargs *args, int tag)
5211  {
5212 -       encode_sattr3(xdr, args->sattr);
5213 +       encode_sattr3(xdr, args->sattr, tag);
5214         encode_nfspath3(xdr, args->pages, args->pathlen);
5215  }
5216  
5217 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5218                                       const struct nfs3_symlinkargs *args)
5219  {
5220         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5221 -       encode_symlinkdata3(xdr, args);
5222 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5223  }
5224  
5225  /*
5226 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5227   *     };
5228   */
5229  static void encode_devicedata3(struct xdr_stream *xdr,
5230 -                              const struct nfs3_mknodargs *args)
5231 +       const struct nfs3_mknodargs *args, int tag)
5232  {
5233 -       encode_sattr3(xdr, args->sattr);
5234 +       encode_sattr3(xdr, args->sattr, tag);
5235         encode_specdata3(xdr, args->rdev);
5236  }
5237  
5238  static void encode_mknoddata3(struct xdr_stream *xdr,
5239 -                             const struct nfs3_mknodargs *args)
5240 +       const struct nfs3_mknodargs *args, int tag)
5241  {
5242         encode_ftype3(xdr, args->type);
5243         switch (args->type) {
5244         case NF3CHR:
5245         case NF3BLK:
5246 -               encode_devicedata3(xdr, args);
5247 +               encode_devicedata3(xdr, args, tag);
5248                 break;
5249         case NF3SOCK:
5250         case NF3FIFO:
5251 -               encode_sattr3(xdr, args->sattr);
5252 +               encode_sattr3(xdr, args->sattr, tag);
5253                 break;
5254         case NF3REG:
5255         case NF3DIR:
5256 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5257                                     const struct nfs3_mknodargs *args)
5258  {
5259         encode_diropargs3(xdr, args->fh, args->name, args->len);
5260 -       encode_mknoddata3(xdr, args);
5261 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5262  }
5263  
5264  /*
5265 diff -NurpP --minimal linux-3.13.10/fs/nfs/super.c linux-3.13.10-vs2.3.6.11/fs/nfs/super.c
5266 --- linux-3.13.10/fs/nfs/super.c        2014-01-22 20:39:06.000000000 +0000
5267 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/super.c     2014-01-31 20:38:03.000000000 +0000
5268 @@ -55,6 +55,7 @@
5269  #include <linux/parser.h>
5270  #include <linux/nsproxy.h>
5271  #include <linux/rcupdate.h>
5272 +#include <linux/vs_tag.h>
5273  
5274  #include <asm/uaccess.h>
5275  
5276 @@ -103,6 +104,7 @@ enum {
5277         Opt_mountport,
5278         Opt_mountvers,
5279         Opt_minorversion,
5280 +       Opt_tagid,
5281  
5282         /* Mount options that take string arguments */
5283         Opt_nfsvers,
5284 @@ -115,6 +117,9 @@ enum {
5285         /* Special mount options */
5286         Opt_userspace, Opt_deprecated, Opt_sloppy,
5287  
5288 +       /* Linux-VServer tagging options */
5289 +       Opt_tag, Opt_notag,
5290 +
5291         Opt_err
5292  };
5293  
5294 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5295         { Opt_fscache_uniq, "fsc=%s" },
5296         { Opt_local_lock, "local_lock=%s" },
5297  
5298 +       { Opt_tag, "tag" },
5299 +       { Opt_notag, "notag" },
5300 +       { Opt_tagid, "tagid=%u" },
5301 +
5302         /* The following needs to be listed after all other options */
5303         { Opt_nfsvers, "v%s" },
5304  
5305 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5306                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5307                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5308                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5309 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5310                 { 0, NULL, NULL }
5311         };
5312         const struct proc_nfs_info *nfs_infop;
5313 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5314                 case Opt_nomigration:
5315                         mnt->options &= NFS_OPTION_MIGRATION;
5316                         break;
5317 +#ifndef CONFIG_TAGGING_NONE
5318 +               case Opt_tag:
5319 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5320 +                       break;
5321 +               case Opt_notag:
5322 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5323 +                       break;
5324 +#endif
5325  
5326                 /*
5327                  * options that take numeric values
5328 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5329                                 goto out_invalid_value;
5330                         mnt->minorversion = option;
5331                         break;
5332 +#ifdef CONFIG_PROPAGATE
5333 +               case Opt_tagid:
5334 +                       /* use args[0] */
5335 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5336 +                       break;
5337 +#endif
5338  
5339                 /*
5340                  * options that take text values
5341 diff -NurpP --minimal linux-3.13.10/fs/nfsd/auth.c linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c
5342 --- linux-3.13.10/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5343 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c     2014-01-31 20:38:03.000000000 +0000
5344 @@ -2,6 +2,7 @@
5345  
5346  #include <linux/sched.h>
5347  #include <linux/user_namespace.h>
5348 +#include <linux/vs_tag.h>
5349  #include "nfsd.h"
5350  #include "auth.h"
5351  
5352 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5353  
5354         new->fsuid = rqstp->rq_cred.cr_uid;
5355         new->fsgid = rqstp->rq_cred.cr_gid;
5356 +       /* FIXME: this desperately needs a tag :)
5357 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5358 +                       */
5359  
5360         rqgi = rqstp->rq_cred.cr_group_info;
5361  
5362 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5363 --- linux-3.13.10/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5364 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c  2014-01-31 20:38:03.000000000 +0000
5365 @@ -8,6 +8,7 @@
5366  
5367  #include <linux/namei.h>
5368  #include <linux/sunrpc/svc_xprt.h>
5369 +#include <linux/vs_tag.h>
5370  #include "xdr3.h"
5371  #include "auth.h"
5372  #include "netns.h"
5373 @@ -98,6 +99,8 @@ static __be32 *
5374  decode_sattr3(__be32 *p, struct iattr *iap)
5375  {
5376         u32     tmp;
5377 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5378 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5379  
5380         iap->ia_valid = 0;
5381  
5382 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5383                 iap->ia_mode = ntohl(*p++);
5384         }
5385         if (*p++) {
5386 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5387 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5388                 if (uid_valid(iap->ia_uid))
5389                         iap->ia_valid |= ATTR_UID;
5390         }
5391         if (*p++) {
5392 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5393 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5394                 if (gid_valid(iap->ia_gid))
5395                         iap->ia_valid |= ATTR_GID;
5396         }
5397 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5398 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5399 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5400         if (*p++) {
5401                 u64     newsize;
5402  
5403 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5404         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5405         *p++ = htonl((u32) stat->mode);
5406         *p++ = htonl((u32) stat->nlink);
5407 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5408 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5409 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5410 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5411 +               stat->uid, stat->tag)));
5412 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5413 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5414 +               stat->gid, stat->tag)));
5415         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5416                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5417         } else {
5418 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs4xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5419 --- linux-3.13.10/fs/nfsd/nfs4xdr.c     2014-01-22 20:39:06.000000000 +0000
5420 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c  2014-01-31 20:38:03.000000000 +0000
5421 @@ -46,6 +46,7 @@
5422  #include <linux/utsname.h>
5423  #include <linux/pagemap.h>
5424  #include <linux/sunrpc/svcauth_gss.h>
5425 +#include <linux/vs_tag.h>
5426  
5427  #include "idmap.h"
5428  #include "acl.h"
5429 @@ -2430,10 +2431,14 @@ out_acl:
5430                 WRITE32(stat.nlink);
5431         }
5432         if (bmval1 & FATTR4_WORD1_OWNER) {
5433 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5434 +               status = nfsd4_encode_user(rqstp,
5435 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5436 +                       stat.uid, stat.tag), &p, &buflen);
5437                 if (status)
5438                         goto out;
5439         }
5440         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5441 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5442 +               status = nfsd4_encode_group(rqstp,
5443 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5444 +                       stat.gid, stat.tag), &p, &buflen);
5445                 if (status)
5446                         goto out;
5447         }
5448 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfsxdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c
5449 --- linux-3.13.10/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5450 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c   2014-01-31 20:38:03.000000000 +0000
5451 @@ -7,6 +7,7 @@
5452  #include "vfs.h"
5453  #include "xdr.h"
5454  #include "auth.h"
5455 +#include <linux/vs_tag.h>
5456  
5457  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5458  
5459 @@ -89,6 +90,8 @@ static __be32 *
5460  decode_sattr(__be32 *p, struct iattr *iap)
5461  {
5462         u32     tmp, tmp1;
5463 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5464 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5465  
5466         iap->ia_valid = 0;
5467  
5468 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5469                 iap->ia_mode = tmp;
5470         }
5471         if ((tmp = ntohl(*p++)) != (u32)-1) {
5472 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5473 +               kuid = make_kuid(&init_user_ns, tmp);
5474                 if (uid_valid(iap->ia_uid))
5475                         iap->ia_valid |= ATTR_UID;
5476         }
5477         if ((tmp = ntohl(*p++)) != (u32)-1) {
5478 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5479 +               kgid = make_kgid(&init_user_ns, tmp);
5480                 if (gid_valid(iap->ia_gid))
5481                         iap->ia_valid |= ATTR_GID;
5482         }
5483 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5484 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5485 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5486         if ((tmp = ntohl(*p++)) != (u32)-1) {
5487                 iap->ia_valid |= ATTR_SIZE;
5488                 iap->ia_size = tmp;
5489 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5490         *p++ = htonl(nfs_ftypes[type >> 12]);
5491         *p++ = htonl((u32) stat->mode);
5492         *p++ = htonl((u32) stat->nlink);
5493 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5494 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5495 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5496 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5497 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5498 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5499  
5500         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5501                 *p++ = htonl(NFS_MAXPATHLEN);
5502 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c
5503 --- linux-3.13.10/fs/ocfs2/dlmglue.c    2014-01-22 20:39:07.000000000 +0000
5504 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5505 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5506         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5507         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5508         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5509 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5510         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5511         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5512         lvb->lvb_iatime_packed  =
5513 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5514  
5515         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5516         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5517 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5518         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5519         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5520         ocfs2_unpack_timespec(&inode->i_atime,
5521 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h
5522 --- linux-3.13.10/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5523 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5524 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5525         __be16       lvb_inlink;
5526         __be32       lvb_iattr;
5527         __be32       lvb_igeneration;
5528 -       __be32       lvb_reserved2;
5529 +       __be16       lvb_itag;
5530 +       __be16       lvb_reserved2;
5531  };
5532  
5533  #define OCFS2_QINFO_LVB_VERSION 1
5534 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/file.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c
5535 --- linux-3.13.10/fs/ocfs2/file.c       2014-04-17 01:12:32.000000000 +0000
5536 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c    2014-04-17 01:17:10.000000000 +0000
5537 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5538                 attr->ia_valid &= ~ATTR_SIZE;
5539  
5540  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5541 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5542 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5543         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5544                 return 0;
5545  
5546 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c
5547 --- linux-3.13.10/fs/ocfs2/inode.c      2014-01-22 20:39:07.000000000 +0000
5548 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c   2014-01-31 20:38:03.000000000 +0000
5549 @@ -28,6 +28,7 @@
5550  #include <linux/highmem.h>
5551  #include <linux/pagemap.h>
5552  #include <linux/quotaops.h>
5553 +#include <linux/vs_tag.h>
5554  
5555  #include <asm/byteorder.h>
5556  
5557 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5558  {
5559         unsigned int flags = OCFS2_I(inode)->ip_attr;
5560  
5561 -       inode->i_flags &= ~(S_IMMUTABLE |
5562 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5563                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5564  
5565         if (flags & OCFS2_IMMUTABLE_FL)
5566                 inode->i_flags |= S_IMMUTABLE;
5567 +       if (flags & OCFS2_IXUNLINK_FL)
5568 +               inode->i_flags |= S_IXUNLINK;
5569  
5570         if (flags & OCFS2_SYNC_FL)
5571                 inode->i_flags |= S_SYNC;
5572 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5573                 inode->i_flags |= S_NOATIME;
5574         if (flags & OCFS2_DIRSYNC_FL)
5575                 inode->i_flags |= S_DIRSYNC;
5576 +
5577 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5578 +
5579 +       if (flags & OCFS2_BARRIER_FL)
5580 +               inode->i_vflags |= V_BARRIER;
5581 +       if (flags & OCFS2_COW_FL)
5582 +               inode->i_vflags |= V_COW;
5583  }
5584  
5585  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5586  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5587  {
5588         unsigned int flags = oi->vfs_inode.i_flags;
5589 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5590 +
5591 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5592 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5593 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5594 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5595 +
5596 +       if (flags & S_IMMUTABLE)
5597 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5598 +       if (flags & S_IXUNLINK)
5599 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5600  
5601 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5602 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5603         if (flags & S_SYNC)
5604                 oi->ip_attr |= OCFS2_SYNC_FL;
5605         if (flags & S_APPEND)
5606                 oi->ip_attr |= OCFS2_APPEND_FL;
5607 -       if (flags & S_IMMUTABLE)
5608 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5609         if (flags & S_NOATIME)
5610                 oi->ip_attr |= OCFS2_NOATIME_FL;
5611         if (flags & S_DIRSYNC)
5612                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5613 +
5614 +       if (vflags & V_BARRIER)
5615 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5616 +       if (vflags & V_COW)
5617 +               oi->ip_attr |= OCFS2_COW_FL;
5618  }
5619  
5620  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5621 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5622         struct super_block *sb;
5623         struct ocfs2_super *osb;
5624         int use_plocks = 1;
5625 +       uid_t uid;
5626 +       gid_t gid;
5627  
5628         sb = inode->i_sb;
5629         osb = OCFS2_SB(sb);
5630 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5631         inode->i_generation = le32_to_cpu(fe->i_generation);
5632         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5633         inode->i_mode = le16_to_cpu(fe->i_mode);
5634 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5635 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5636 +       uid = le32_to_cpu(fe->i_uid);
5637 +       gid = le32_to_cpu(fe->i_gid);
5638 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5639 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5640 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5641 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5642  
5643         /* Fast symlinks will have i_size but no allocated clusters. */
5644         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5645 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h
5646 --- linux-3.13.10/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5647 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h   2014-01-31 20:38:03.000000000 +0000
5648 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5649  
5650  void ocfs2_set_inode_flags(struct inode *inode);
5651  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5652 +int ocfs2_sync_flags(struct inode *inode, int, int);
5653  
5654  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5655  {
5656 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c
5657 --- linux-3.13.10/fs/ocfs2/ioctl.c      2013-11-25 15:47:00.000000000 +0000
5658 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c   2014-01-31 20:38:03.000000000 +0000
5659 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5660         return status;
5661  }
5662  
5663 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5664 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5665 +{
5666 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5667 +       struct buffer_head *bh = NULL;
5668 +       handle_t *handle = NULL;
5669 +       int status;
5670 +
5671 +       status = ocfs2_inode_lock(inode, &bh, 1);
5672 +       if (status < 0) {
5673 +               mlog_errno(status);
5674 +               return status;
5675 +       }
5676 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5677 +       if (IS_ERR(handle)) {
5678 +               status = PTR_ERR(handle);
5679 +               mlog_errno(status);
5680 +               goto bail_unlock;
5681 +       }
5682 +
5683 +       inode->i_flags = flags;
5684 +       inode->i_vflags = vflags;
5685 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5686 +
5687 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5688 +       if (status < 0)
5689 +               mlog_errno(status);
5690 +
5691 +       ocfs2_commit_trans(osb, handle);
5692 +bail_unlock:
5693 +       ocfs2_inode_unlock(inode, 1);
5694 +       brelse(bh);
5695 +       return status;
5696 +}
5697 +
5698 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5699                                 unsigned mask)
5700  {
5701         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5702 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5703                         goto bail_unlock;
5704         }
5705  
5706 +       if (IS_BARRIER(inode)) {
5707 +               vxwprintk_task(1, "messing with the barrier.");
5708 +               goto bail_unlock;
5709 +       }
5710 +
5711         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5712         if (IS_ERR(handle)) {
5713                 status = PTR_ERR(handle);
5714 @@ -881,6 +920,7 @@ bail:
5715         return status;
5716  }
5717  
5718 +
5719  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5720  {
5721         struct inode *inode = file_inode(filp);
5722 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/namei.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c
5723 --- linux-3.13.10/fs/ocfs2/namei.c      2014-01-22 20:39:07.000000000 +0000
5724 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c   2014-01-31 20:38:03.000000000 +0000
5725 @@ -41,6 +41,7 @@
5726  #include <linux/slab.h>
5727  #include <linux/highmem.h>
5728  #include <linux/quotaops.h>
5729 +#include <linux/vs_tag.h>
5730  
5731  #include <cluster/masklog.h>
5732  
5733 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5734         struct ocfs2_extent_list *fel;
5735         u16 feat;
5736         struct ocfs2_inode_info *oi = OCFS2_I(inode);
5737 +       ktag_t ktag;
5738  
5739         *new_fe_bh = NULL;
5740  
5741 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5742         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5743         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5744         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5745 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5746 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5747 +
5748 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5749 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5750 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5751 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5752 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5753 +       inode->i_tag = ktag; /* is this correct? */
5754         fe->i_mode = cpu_to_le16(inode->i_mode);
5755         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5756                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5757 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h
5758 --- linux-3.13.10/fs/ocfs2/ocfs2.h      2013-11-25 15:45:04.000000000 +0000
5759 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h   2014-01-31 20:38:03.000000000 +0000
5760 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5761                                                      writes */
5762         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5763         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5764 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5765  };
5766  
5767  #define OCFS2_OSB_SOFT_RO                      0x0001
5768 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2_fs.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h
5769 --- linux-3.13.10/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5770 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h        2014-01-31 20:38:03.000000000 +0000
5771 @@ -266,6 +266,11 @@
5772  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5773  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5774  
5775 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5776 +
5777 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5778 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5779 +
5780  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5781  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5782  
5783 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/super.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c
5784 --- linux-3.13.10/fs/ocfs2/super.c      2014-01-22 20:39:07.000000000 +0000
5785 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c   2014-01-31 20:38:03.000000000 +0000
5786 @@ -185,6 +185,7 @@ enum {
5787         Opt_coherency_full,
5788         Opt_resv_level,
5789         Opt_dir_resv_level,
5790 +       Opt_tag, Opt_notag, Opt_tagid,
5791         Opt_err,
5792  };
5793  
5794 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5795         {Opt_coherency_full, "coherency=full"},
5796         {Opt_resv_level, "resv_level=%u"},
5797         {Opt_dir_resv_level, "dir_resv_level=%u"},
5798 +       {Opt_tag, "tag"},
5799 +       {Opt_notag, "notag"},
5800 +       {Opt_tagid, "tagid=%u"},
5801         {Opt_err, NULL}
5802  };
5803  
5804 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5805                 goto out;
5806         }
5807  
5808 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5809 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5810 +               ret = -EINVAL;
5811 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5812 +               goto out;
5813 +       }
5814 +
5815         /* We're going to/from readonly mode. */
5816         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5817                 /* Disable quota accounting before remounting RO */
5818 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5819  
5820         ocfs2_complete_mount_recovery(osb);
5821  
5822 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5823 +               sb->s_flags |= MS_TAGGED;
5824 +
5825         if (ocfs2_mount_local(osb))
5826                 snprintf(nodestr, sizeof(nodestr), "local");
5827         else
5828 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5829                             option < OCFS2_MAX_RESV_LEVEL)
5830                                 mopt->dir_resv_level = option;
5831                         break;
5832 +#ifndef CONFIG_TAGGING_NONE
5833 +               case Opt_tag:
5834 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5835 +                       break;
5836 +               case Opt_notag:
5837 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5838 +                       break;
5839 +#endif
5840 +#ifdef CONFIG_PROPAGATE
5841 +               case Opt_tagid:
5842 +                       /* use args[0] */
5843 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5844 +                       break;
5845 +#endif
5846                 default:
5847                         mlog(ML_ERROR,
5848                              "Unrecognized mount option \"%s\" "
5849 diff -NurpP --minimal linux-3.13.10/fs/open.c linux-3.13.10-vs2.3.6.11/fs/open.c
5850 --- linux-3.13.10/fs/open.c     2014-01-22 20:39:07.000000000 +0000
5851 +++ linux-3.13.10-vs2.3.6.11/fs/open.c  2014-01-31 20:38:03.000000000 +0000
5852 @@ -31,6 +31,11 @@
5853  #include <linux/ima.h>
5854  #include <linux/dnotify.h>
5855  #include <linux/compat.h>
5856 +#include <linux/vs_base.h>
5857 +#include <linux/vs_limit.h>
5858 +#include <linux/vs_tag.h>
5859 +#include <linux/vs_cowbl.h>
5860 +#include <linux/vserver/dlimit.h>
5861  
5862  #include "internal.h"
5863  
5864 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5865         struct inode *inode;
5866         long error;
5867  
5868 +#ifdef CONFIG_VSERVER_COWBL
5869 +       error = cow_check_and_break(path);
5870 +       if (error)
5871 +               goto out;
5872 +#endif
5873         inode = path->dentry->d_inode;
5874  
5875         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5876 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5877         unsigned int lookup_flags = LOOKUP_FOLLOW;
5878  retry:
5879         error = user_path_at(dfd, filename, lookup_flags, &path);
5880 +#ifdef CONFIG_VSERVER_COWBL
5881 +       if (!error) {
5882 +               error = cow_check_and_break(&path);
5883 +               if (error)
5884 +                       path_put(&path);
5885 +       }
5886 +#endif
5887         if (!error) {
5888                 error = chmod_common(&path, mode);
5889                 path_put(&path);
5890 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5891                 if (!uid_valid(uid))
5892                         return -EINVAL;
5893                 newattrs.ia_valid |= ATTR_UID;
5894 -               newattrs.ia_uid = uid;
5895 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5896 +                       dx_map_uid(user));
5897         }
5898         if (group != (gid_t) -1) {
5899                 if (!gid_valid(gid))
5900                         return -EINVAL;
5901                 newattrs.ia_valid |= ATTR_GID;
5902 -               newattrs.ia_gid = gid;
5903 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5904 +                       dx_map_gid(group));
5905         }
5906         if (!S_ISDIR(inode->i_mode))
5907                 newattrs.ia_valid |=
5908 @@ -589,6 +608,18 @@ retry:
5909         error = mnt_want_write(path.mnt);
5910         if (error)
5911                 goto out_release;
5912 +#ifdef CONFIG_VSERVER_COWBL
5913 +       error = cow_check_and_break(&path);
5914 +       if (!error)
5915 +#endif
5916 +#ifdef CONFIG_VSERVER_COWBL
5917 +       error = cow_check_and_break(&path);
5918 +       if (!error)
5919 +#endif
5920 +#ifdef CONFIG_VSERVER_COWBL
5921 +       error = cow_check_and_break(&path);
5922 +       if (!error)
5923 +#endif
5924         error = chown_common(&path, user, group);
5925         mnt_drop_write(path.mnt);
5926  out_release:
5927 diff -NurpP --minimal linux-3.13.10/fs/proc/array.c linux-3.13.10-vs2.3.6.11/fs/proc/array.c
5928 --- linux-3.13.10/fs/proc/array.c       2014-01-22 20:39:07.000000000 +0000
5929 +++ linux-3.13.10-vs2.3.6.11/fs/proc/array.c    2014-02-01 01:44:54.000000000 +0000
5930 @@ -82,6 +82,8 @@
5931  #include <linux/ptrace.h>
5932  #include <linux/tracehook.h>
5933  #include <linux/user_namespace.h>
5934 +#include <linux/vs_context.h>
5935 +#include <linux/vs_network.h>
5936  
5937  #include <asm/pgtable.h>
5938  #include <asm/processor.h>
5939 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5940         rcu_read_lock();
5941         ppid = pid_alive(p) ?
5942                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5943 +       if (unlikely(vx_current_initpid(p->pid)))
5944 +               ppid = 0;
5945 +
5946         tpid = 0;
5947         if (pid_alive(p)) {
5948                 struct task_struct *tracer = ptrace_parent(p);
5949 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5950  }
5951  
5952  static void render_cap_t(struct seq_file *m, const char *header,
5953 -                       kernel_cap_t *a)
5954 +                       struct vx_info *vxi, kernel_cap_t *a)
5955  {
5956         unsigned __capi;
5957  
5958 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5959         NORM_CAPS(cap_effective);
5960         NORM_CAPS(cap_bset);
5961  
5962 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5963 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5964 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5965 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5966 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5967 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5968 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5969 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5970 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5971  }
5972  
5973  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5974 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
5975         seq_putc(m, '\n');
5976  }
5977  
5978 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5979 +                       struct pid *pid, struct task_struct *task)
5980 +{
5981 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
5982 +                       "Count:\t%u\n"
5983 +                       "uts:\t%p(%c)\n"
5984 +                       "ipc:\t%p(%c)\n"
5985 +                       "mnt:\t%p(%c)\n"
5986 +                       "pid:\t%p(%c)\n"
5987 +                       "net:\t%p(%c)\n",
5988 +                       task->nsproxy,
5989 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
5990 +                       atomic_read(&task->nsproxy->count),
5991 +                       task->nsproxy->uts_ns,
5992 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
5993 +                       task->nsproxy->ipc_ns,
5994 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
5995 +                       task->nsproxy->mnt_ns,
5996 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
5997 +                       task->nsproxy->pid_ns_for_children,
5998 +                       (task->nsproxy->pid_ns_for_children ==
5999 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6000 +                       task->nsproxy->net_ns,
6001 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6002 +       return 0;
6003 +}
6004 +
6005 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6006 +{
6007 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6008 +               return;
6009 +
6010 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6011 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6012 +}
6013 +
6014 +
6015  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6016                         struct pid *pid, struct task_struct *task)
6017  {
6018 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6019         task_seccomp(m, task);
6020         task_cpus_allowed(m, task);
6021         cpuset_task_status_allowed(m, task);
6022 +       task_vs_id(m, task);
6023         task_context_switch_counts(m, task);
6024         return 0;
6025  }
6026 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6027         /* convert nsec -> ticks */
6028         start_time = nsec_to_clock_t(start_time);
6029  
6030 +       /* fixup start time for virt uptime */
6031 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6032 +               unsigned long long bias =
6033 +                       current->vx_info->cvirt.bias_clock;
6034 +
6035 +               if (start_time > bias)
6036 +                       start_time -= bias;
6037 +               else
6038 +                       start_time = 0;
6039 +       }
6040 +
6041         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6042         seq_put_decimal_ll(m, ' ', ppid);
6043         seq_put_decimal_ll(m, ' ', pgid);
6044 diff -NurpP --minimal linux-3.13.10/fs/proc/base.c linux-3.13.10-vs2.3.6.11/fs/proc/base.c
6045 --- linux-3.13.10/fs/proc/base.c        2014-04-17 01:12:32.000000000 +0000
6046 +++ linux-3.13.10-vs2.3.6.11/fs/proc/base.c     2014-04-17 01:17:10.000000000 +0000
6047 @@ -87,6 +87,8 @@
6048  #include <linux/slab.h>
6049  #include <linux/flex_array.h>
6050  #include <linux/posix-timers.h>
6051 +#include <linux/vs_context.h>
6052 +#include <linux/vs_network.h>
6053  #ifdef CONFIG_HARDWALL
6054  #include <asm/hardwall.h>
6055  #endif
6056 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6057                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6058  
6059         if (oom_adj < task->signal->oom_score_adj &&
6060 -           !capable(CAP_SYS_RESOURCE)) {
6061 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6062                 err = -EACCES;
6063                 goto err_sighand;
6064         }
6065  
6066 +       /* prevent guest processes from circumventing the oom killer */
6067 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6068 +               oom_adj = OOM_ADJUST_MIN;
6069 +
6070         /*
6071          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6072          * /proc/pid/oom_score_adj instead.
6073 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6074                 inode->i_gid = cred->egid;
6075                 rcu_read_unlock();
6076         }
6077 +       /* procfs is xid tagged */
6078 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6079         security_task_to_inode(task, inode);
6080  
6081  out:
6082 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6083  
6084  /* dentry stuff */
6085  
6086 +static unsigned name_to_int(struct dentry *dentry);
6087 +
6088  /*
6089   *     Exceptional case: normally we are not allowed to unhash a busy
6090   * directory. In this case, however, we can do it - no aliasing problems
6091 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6092         task = get_proc_task(inode);
6093  
6094         if (task) {
6095 +               unsigned pid = name_to_int(dentry);
6096 +
6097 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6098 +                       put_task_struct(task);
6099 +                       goto drop;
6100 +               }
6101                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6102                     task_dumpable(task)) {
6103                         rcu_read_lock();
6104 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6105                 put_task_struct(task);
6106                 return 1;
6107         }
6108 +drop:
6109         d_drop(dentry);
6110         return 0;
6111  }
6112 @@ -2173,6 +2190,13 @@ static struct dentry *proc_pident_lookup
6113         if (!task)
6114                 goto out_no_task;
6115  
6116 +       /* TODO: maybe we can come up with a generic approach? */
6117 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6118 +               (dentry->d_name.len == 5) &&
6119 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6120 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6121 +               goto out;
6122 +
6123         /*
6124          * Yes, it does not scale. And it should not. Don't add
6125          * new entries into /proc/<tgid>/ without very good reasons.
6126 @@ -2569,6 +2593,9 @@ static int proc_pid_personality(struct s
6127  static const struct file_operations proc_task_operations;
6128  static const struct inode_operations proc_task_inode_operations;
6129  
6130 +extern int proc_pid_vx_info(struct task_struct *, char *);
6131 +extern int proc_pid_nx_info(struct task_struct *, char *);
6132 +
6133  static const struct pid_entry tgid_base_stuff[] = {
6134         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6135         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6136 @@ -2635,6 +2662,8 @@ static const struct pid_entry tgid_base_
6137  #ifdef CONFIG_CGROUPS
6138         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6139  #endif
6140 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6141 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6142         INF("oom_score",  S_IRUGO, proc_oom_score),
6143         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6144         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6145 @@ -2847,7 +2876,7 @@ retry:
6146         iter.task = NULL;
6147         pid = find_ge_pid(iter.tgid, ns);
6148         if (pid) {
6149 -               iter.tgid = pid_nr_ns(pid, ns);
6150 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6151                 iter.task = pid_task(pid, PIDTYPE_PID);
6152                 /* What we to know is if the pid we have find is the
6153                  * pid of a thread_group_leader.  Testing for task
6154 @@ -2900,8 +2929,10 @@ int proc_pid_readdir(struct file *file,
6155                 if (!has_pid_permissions(ns, iter.task, 2))
6156                         continue;
6157  
6158 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
6159 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6160                 ctx->pos = iter.tgid + TGID_OFFSET;
6161 +               if (!vx_proc_task_visible(iter.task))
6162 +                       continue;
6163                 if (!proc_fill_cache(file, ctx, name, len,
6164                                      proc_pid_instantiate, iter.task, NULL)) {
6165                         put_task_struct(iter.task);
6166 @@ -2994,6 +3025,7 @@ static const struct pid_entry tid_base_s
6167         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6168         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6169  #endif
6170 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6171  };
6172  
6173  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6174 @@ -3060,6 +3092,8 @@ static struct dentry *proc_task_lookup(s
6175         tid = name_to_int(dentry);
6176         if (tid == ~0U)
6177                 goto out;
6178 +       if (vx_current_initpid(tid))
6179 +               goto out;
6180  
6181         ns = dentry->d_sb->s_fs_info;
6182         rcu_read_lock();
6183 diff -NurpP --minimal linux-3.13.10/fs/proc/generic.c linux-3.13.10-vs2.3.6.11/fs/proc/generic.c
6184 --- linux-3.13.10/fs/proc/generic.c     2014-01-22 20:39:07.000000000 +0000
6185 +++ linux-3.13.10-vs2.3.6.11/fs/proc/generic.c  2014-02-01 00:07:40.000000000 +0000
6186 @@ -23,6 +23,7 @@
6187  #include <linux/bitops.h>
6188  #include <linux/spinlock.h>
6189  #include <linux/completion.h>
6190 +#include <linux/vserver/inode.h>
6191  #include <asm/uaccess.h>
6192  
6193  #include "internal.h"
6194 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6195         for (de = de->subdir; de ; de = de->next) {
6196                 if (de->namelen != dentry->d_name.len)
6197                         continue;
6198 +               if (!vx_hide_check(0, de->vx_flags))
6199 +                       continue;
6200                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6201                         pde_get(de);
6202                         spin_unlock(&proc_subdir_lock);
6203 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6204                                 return ERR_PTR(-ENOMEM);
6205                         d_set_d_op(dentry, &simple_dentry_operations);
6206                         d_add(dentry, inode);
6207 +                       /* generic proc entries belong to the host */
6208 +                       i_tag_write(inode, 0);
6209                         return NULL;
6210                 }
6211         }
6212 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6213         do {
6214                 struct proc_dir_entry *next;
6215                 pde_get(de);
6216 +
6217 +               if (!vx_hide_check(0, de->vx_flags))
6218 +                       goto skip;
6219                 spin_unlock(&proc_subdir_lock);
6220                 if (!dir_emit(ctx, de->name, de->namelen,
6221                             de->low_ino, de->mode >> 12)) {
6222 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6223                         return 0;
6224                 }
6225                 spin_lock(&proc_subdir_lock);
6226 +       skip:
6227                 ctx->pos++;
6228                 next = de->next;
6229                 pde_put(de);
6230 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6231         ent->namelen = len;
6232         ent->mode = mode;
6233         ent->nlink = nlink;
6234 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6235         atomic_set(&ent->count, 1);
6236         spin_lock_init(&ent->pde_unload_lock);
6237         INIT_LIST_HEAD(&ent->pde_openers);
6238 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6239                                 kfree(ent->data);
6240                                 kfree(ent);
6241                                 ent = NULL;
6242 -                       }
6243 +                       } else
6244 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6245                 } else {
6246                         kfree(ent);
6247                         ent = NULL;
6248 diff -NurpP --minimal linux-3.13.10/fs/proc/inode.c linux-3.13.10-vs2.3.6.11/fs/proc/inode.c
6249 --- linux-3.13.10/fs/proc/inode.c       2014-01-22 20:39:07.000000000 +0000
6250 +++ linux-3.13.10-vs2.3.6.11/fs/proc/inode.c    2014-01-31 20:38:03.000000000 +0000
6251 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6252                         inode->i_uid = de->uid;
6253                         inode->i_gid = de->gid;
6254                 }
6255 +               if (de->vx_flags)
6256 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6257                 if (de->size)
6258                         inode->i_size = de->size;
6259                 if (de->nlink)
6260 diff -NurpP --minimal linux-3.13.10/fs/proc/internal.h linux-3.13.10-vs2.3.6.11/fs/proc/internal.h
6261 --- linux-3.13.10/fs/proc/internal.h    2013-11-25 15:45:04.000000000 +0000
6262 +++ linux-3.13.10-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6263 @@ -14,6 +14,7 @@
6264  #include <linux/spinlock.h>
6265  #include <linux/atomic.h>
6266  #include <linux/binfmts.h>
6267 +#include <linux/vs_pid.h>
6268  
6269  struct ctl_table_header;
6270  struct mempolicy;
6271 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6272         nlink_t nlink;
6273         kuid_t uid;
6274         kgid_t gid;
6275 +       int vx_flags;
6276         loff_t size;
6277         const struct inode_operations *proc_iops;
6278         const struct file_operations *proc_fops;
6279 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6280         char name[];
6281  };
6282  
6283 +struct vx_info;
6284 +struct nx_info;
6285 +
6286  union proc_op {
6287         int (*proc_get_link)(struct dentry *, struct path *);
6288         int (*proc_read)(struct task_struct *task, char *page);
6289         int (*proc_show)(struct seq_file *m,
6290                 struct pid_namespace *ns, struct pid *pid,
6291                 struct task_struct *task);
6292 +       int (*proc_vs_read)(char *page);
6293 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6294 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6295  };
6296  
6297  struct proc_inode {
6298         struct pid *pid;
6299 +       int vx_flags;
6300         int fd;
6301         union proc_op op;
6302         struct proc_dir_entry *pde;
6303 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6304         return PROC_I(inode)->pid;
6305  }
6306  
6307 -static inline struct task_struct *get_proc_task(struct inode *inode)
6308 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6309  {
6310         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6311  }
6312  
6313 +static inline struct task_struct *get_proc_task(struct inode *inode)
6314 +{
6315 +       return vx_get_proc_task(inode, proc_pid(inode));
6316 +}
6317 +
6318  static inline int task_dumpable(struct task_struct *task)
6319  {
6320         int dumpable = 0;
6321 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6322                            struct pid *, struct task_struct *);
6323  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6324                           struct pid *, struct task_struct *);
6325 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6326 +                           struct pid *pid, struct task_struct *task);
6327  
6328  /*
6329   * base.c
6330 diff -NurpP --minimal linux-3.13.10/fs/proc/loadavg.c linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c
6331 --- linux-3.13.10/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6332 +++ linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c  2014-01-31 20:38:03.000000000 +0000
6333 @@ -12,15 +12,27 @@
6334  
6335  static int loadavg_proc_show(struct seq_file *m, void *v)
6336  {
6337 +       unsigned long running;
6338 +       unsigned int threads;
6339         unsigned long avnrun[3];
6340  
6341         get_avenrun(avnrun, FIXED_1/200, 0);
6342  
6343 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6344 +               struct vx_info *vxi = current_vx_info();
6345 +
6346 +               running = atomic_read(&vxi->cvirt.nr_running);
6347 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6348 +       } else {
6349 +               running = nr_running();
6350 +               threads = nr_threads;
6351 +       }
6352 +
6353         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6354                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6355                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6356                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6357 -               nr_running(), nr_threads,
6358 +               running, threads,
6359                 task_active_pid_ns(current)->last_pid);
6360         return 0;
6361  }
6362 diff -NurpP --minimal linux-3.13.10/fs/proc/meminfo.c linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c
6363 --- linux-3.13.10/fs/proc/meminfo.c     2014-01-22 20:39:07.000000000 +0000
6364 +++ linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c  2014-01-31 20:38:03.000000000 +0000
6365 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6366         si_swapinfo(&i);
6367         committed = percpu_counter_read_positive(&vm_committed_as);
6368  
6369 -       cached = global_page_state(NR_FILE_PAGES) -
6370 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6371 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6372                         total_swapcache_pages() - i.bufferram;
6373         if (cached < 0)
6374                 cached = 0;
6375 diff -NurpP --minimal linux-3.13.10/fs/proc/root.c linux-3.13.10-vs2.3.6.11/fs/proc/root.c
6376 --- linux-3.13.10/fs/proc/root.c        2013-11-25 15:47:00.000000000 +0000
6377 +++ linux-3.13.10-vs2.3.6.11/fs/proc/root.c     2014-02-01 00:02:11.000000000 +0000
6378 @@ -20,9 +20,14 @@
6379  #include <linux/mount.h>
6380  #include <linux/pid_namespace.h>
6381  #include <linux/parser.h>
6382 +#include <linux/vserver/inode.h>
6383  
6384  #include "internal.h"
6385  
6386 +struct proc_dir_entry *proc_virtual;
6387 +
6388 +extern void proc_vx_init(void);
6389 +
6390  static int proc_test_super(struct super_block *sb, void *data)
6391  {
6392         return sb->s_fs_info == data;
6393 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6394                         return ERR_PTR(-EPERM);
6395  
6396                 /* Does the mounter have privilege over the pid namespace? */
6397 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6398 +               if (!vx_ns_capable(ns->user_ns,
6399 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6400                         return ERR_PTR(-EPERM);
6401         }
6402  
6403 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6404  #endif
6405         proc_mkdir("bus", NULL);
6406         proc_sys_init();
6407 +       proc_vx_init();
6408  }
6409  
6410  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6411 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6412         .proc_iops      = &proc_root_inode_operations, 
6413         .proc_fops      = &proc_root_operations,
6414         .parent         = &proc_root,
6415 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6416         .name           = "/proc",
6417  };
6418  
6419 diff -NurpP --minimal linux-3.13.10/fs/proc/self.c linux-3.13.10-vs2.3.6.11/fs/proc/self.c
6420 --- linux-3.13.10/fs/proc/self.c        2014-01-22 20:39:07.000000000 +0000
6421 +++ linux-3.13.10-vs2.3.6.11/fs/proc/self.c     2014-01-31 20:38:03.000000000 +0000
6422 @@ -2,6 +2,7 @@
6423  #include <linux/namei.h>
6424  #include <linux/slab.h>
6425  #include <linux/pid_namespace.h>
6426 +#include <linux/vserver/inode.h>
6427  #include "internal.h"
6428  
6429  /*
6430 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6431         self = d_alloc_name(s->s_root, "self");
6432         if (self) {
6433                 struct inode *inode = new_inode_pseudo(s);
6434 +
6435 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6436                 if (inode) {
6437                         inode->i_ino = self_inum;
6438                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6439 diff -NurpP --minimal linux-3.13.10/fs/proc/stat.c linux-3.13.10-vs2.3.6.11/fs/proc/stat.c
6440 --- linux-3.13.10/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6441 +++ linux-3.13.10-vs2.3.6.11/fs/proc/stat.c     2014-01-31 20:38:03.000000000 +0000
6442 @@ -9,8 +9,10 @@
6443  #include <linux/slab.h>
6444  #include <linux/time.h>
6445  #include <linux/irqnr.h>
6446 +#include <linux/vserver/cvirt.h>
6447  #include <linux/cputime.h>
6448  #include <linux/tick.h>
6449 +#include <linux/cpuset.h>
6450  
6451  #ifndef arch_irq_stat_cpu
6452  #define arch_irq_stat_cpu(cpu) 0
6453 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6454         u64 sum_softirq = 0;
6455         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6456         struct timespec boottime;
6457 +       cpumask_var_t cpus_allowed;
6458 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6459  
6460         user = nice = system = idle = iowait =
6461                 irq = softirq = steal = 0;
6462         guest = guest_nice = 0;
6463         getboottime(&boottime);
6464 +
6465 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6466 +               vx_vsi_boottime(&boottime);
6467 +
6468 +       if (virt_cpu)
6469 +               cpuset_cpus_allowed(current, cpus_allowed);
6470 +
6471         jif = boottime.tv_sec;
6472  
6473         for_each_possible_cpu(i) {
6474 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6475 +                       continue;
6476 +
6477                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6478                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6479                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6480 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6481         seq_putc(p, '\n');
6482  
6483         for_each_online_cpu(i) {
6484 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6485 +                       continue;
6486 +
6487                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6488                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6489                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6490 diff -NurpP --minimal linux-3.13.10/fs/proc/uptime.c linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c
6491 --- linux-3.13.10/fs/proc/uptime.c      2013-11-25 15:45:04.000000000 +0000
6492 +++ linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c   2014-01-31 20:38:03.000000000 +0000
6493 @@ -5,6 +5,7 @@
6494  #include <linux/seq_file.h>
6495  #include <linux/time.h>
6496  #include <linux/kernel_stat.h>
6497 +#include <linux/vserver/cvirt.h>
6498  #include <linux/cputime.h>
6499  
6500  static int uptime_proc_show(struct seq_file *m, void *v)
6501 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6502         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6503         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6504         idle.tv_nsec = rem;
6505 +
6506 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6507 +               vx_vsi_uptime(&uptime, &idle);
6508 +
6509         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6510                         (unsigned long) uptime.tv_sec,
6511                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6512 diff -NurpP --minimal linux-3.13.10/fs/proc_namespace.c linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c
6513 --- linux-3.13.10/fs/proc_namespace.c   2014-01-22 20:39:07.000000000 +0000
6514 +++ linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c        2014-02-25 12:43:16.000000000 +0000
6515 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6516                 { MS_SYNCHRONOUS, ",sync" },
6517                 { MS_DIRSYNC, ",dirsync" },
6518                 { MS_MANDLOCK, ",mand" },
6519 +               { MS_TAGGED, ",tag" },
6520 +               { MS_NOTAGCHECK, ",notagcheck" },
6521                 { 0, NULL }
6522         };
6523         const struct proc_fs_info *fs_infop;
6524 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6525         seq_escape(m, s, " \t\n\\");
6526  }
6527  
6528 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6529 +
6530 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6531 +{
6532 +       struct path root;
6533 +       struct dentry *point;
6534 +       struct mount *mnt = real_mount(vfsmnt);
6535 +       struct mount *root_mnt;
6536 +       int ret;
6537 +
6538 +       if (mnt == mnt->mnt_ns->root)
6539 +               return 1;
6540 +
6541 +       rcu_read_lock();
6542 +       root = current->fs->root;
6543 +       root_mnt = real_mount(root.mnt);
6544 +       point = root.dentry;
6545 +
6546 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6547 +               point = mnt->mnt_mountpoint;
6548 +               mnt = mnt->mnt_parent;
6549 +       }
6550 +       rcu_read_unlock();
6551 +
6552 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6553 +       return ret;
6554 +}
6555 +
6556 +#else
6557 +#define        mnt_is_reachable(v)     (1)
6558 +#endif
6559 +
6560  static void show_type(struct seq_file *m, struct super_block *sb)
6561  {
6562         mangle(m, sb->s_type->name);
6563 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6564         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6565         struct super_block *sb = mnt_path.dentry->d_sb;
6566  
6567 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6568 +               return SEQ_SKIP;
6569 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6570 +               return SEQ_SKIP;
6571 +
6572 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6573 +               mnt == current->fs->root.mnt) {
6574 +               seq_puts(m, "/dev/root / ");
6575 +               goto type;
6576 +       }
6577 +
6578         if (sb->s_op->show_devname) {
6579                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6580                 if (err)
6581 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6582         seq_putc(m, ' ');
6583         seq_path(m, &mnt_path, " \t\n\\");
6584         seq_putc(m, ' ');
6585 +type:
6586         show_type(m, sb);
6587         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6588         err = show_sb_opts(m, sb);
6589 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6590         struct path root = p->root;
6591         int err = 0;
6592  
6593 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6594 +               return SEQ_SKIP;
6595 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6596 +               return SEQ_SKIP;
6597 +
6598         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6599                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6600         if (sb->s_op->show_path)
6601 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6602         struct super_block *sb = mnt_path.dentry->d_sb;
6603         int err = 0;
6604  
6605 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6606 +               return SEQ_SKIP;
6607 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6608 +               return SEQ_SKIP;
6609 +
6610 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6611 +               mnt == current->fs->root.mnt) {
6612 +               seq_puts(m, "device /dev/root mounted on / ");
6613 +               goto type;
6614 +       }
6615 +
6616         /* device */
6617         if (sb->s_op->show_devname) {
6618                 seq_puts(m, "device ");
6619 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6620         seq_puts(m, " mounted on ");
6621         seq_path(m, &mnt_path, " \t\n\\");
6622         seq_putc(m, ' ');
6623 -
6624 +type:
6625         /* file system type */
6626         seq_puts(m, "with fstype ");
6627         show_type(m, sb);
6628 diff -NurpP --minimal linux-3.13.10/fs/quota/dquot.c linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c
6629 --- linux-3.13.10/fs/quota/dquot.c      2014-04-17 01:12:34.000000000 +0000
6630 +++ linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c   2014-03-12 15:51:07.000000000 +0000
6631 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6632         struct dquot **dquots = inode->i_dquot;
6633         int reserve = flags & DQUOT_SPACE_RESERVE;
6634  
6635 +       if ((ret = dl_alloc_space(inode, number)))
6636 +               return ret;
6637 +
6638         /*
6639          * First test before acquiring mutex - solves deadlocks when we
6640          * re-enter the quota code and are already holding the mutex
6641 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6642         struct dquot_warn warn[MAXQUOTAS];
6643         struct dquot * const *dquots = inode->i_dquot;
6644  
6645 +       if ((ret = dl_alloc_inode(inode)))
6646 +               return ret;
6647 +
6648         /* First test before acquiring mutex - solves deadlocks when we
6649           * re-enter the quota code and are already holding the mutex */
6650         if (!dquot_active(inode))
6651 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6652         struct dquot **dquots = inode->i_dquot;
6653         int reserve = flags & DQUOT_SPACE_RESERVE;
6654  
6655 +       dl_free_space(inode, number);
6656 +
6657         /* First test before acquiring mutex - solves deadlocks when we
6658           * re-enter the quota code and are already holding the mutex */
6659         if (!dquot_active(inode)) {
6660 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6661         struct dquot_warn warn[MAXQUOTAS];
6662         struct dquot * const *dquots = inode->i_dquot;
6663  
6664 +       dl_free_inode(inode);
6665 +
6666         /* First test before acquiring mutex - solves deadlocks when we
6667           * re-enter the quota code and are already holding the mutex */
6668         if (!dquot_active(inode))
6669 diff -NurpP --minimal linux-3.13.10/fs/quota/quota.c linux-3.13.10-vs2.3.6.11/fs/quota/quota.c
6670 --- linux-3.13.10/fs/quota/quota.c      2014-01-22 20:39:07.000000000 +0000
6671 +++ linux-3.13.10-vs2.3.6.11/fs/quota/quota.c   2014-01-31 20:38:03.000000000 +0000
6672 @@ -8,6 +8,7 @@
6673  #include <linux/fs.h>
6674  #include <linux/namei.h>
6675  #include <linux/slab.h>
6676 +#include <linux/vs_context.h>
6677  #include <asm/current.h>
6678  #include <linux/uaccess.h>
6679  #include <linux/kernel.h>
6680 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6681                         break;
6682                 /*FALLTHROUGH*/
6683         default:
6684 -               if (!capable(CAP_SYS_ADMIN))
6685 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6686                         return -EPERM;
6687         }
6688  
6689 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6690  
6691  #ifdef CONFIG_BLOCK
6692  
6693 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6694 +
6695 +#include <linux/vroot.h>
6696 +#include <linux/major.h>
6697 +#include <linux/module.h>
6698 +#include <linux/kallsyms.h>
6699 +#include <linux/vserver/debug.h>
6700 +
6701 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6702 +
6703 +static DEFINE_SPINLOCK(vroot_grb_lock);
6704 +
6705 +int register_vroot_grb(vroot_grb_func *func) {
6706 +       int ret = -EBUSY;
6707 +
6708 +       spin_lock(&vroot_grb_lock);
6709 +       if (!vroot_get_real_bdev) {
6710 +               vroot_get_real_bdev = func;
6711 +               ret = 0;
6712 +       }
6713 +       spin_unlock(&vroot_grb_lock);
6714 +       return ret;
6715 +}
6716 +EXPORT_SYMBOL(register_vroot_grb);
6717 +
6718 +int unregister_vroot_grb(vroot_grb_func *func) {
6719 +       int ret = -EINVAL;
6720 +
6721 +       spin_lock(&vroot_grb_lock);
6722 +       if (vroot_get_real_bdev) {
6723 +               vroot_get_real_bdev = NULL;
6724 +               ret = 0;
6725 +       }
6726 +       spin_unlock(&vroot_grb_lock);
6727 +       return ret;
6728 +}
6729 +EXPORT_SYMBOL(unregister_vroot_grb);
6730 +
6731 +#endif
6732 +
6733  /* Return 1 if 'cmd' will block on frozen filesystem */
6734  static int quotactl_cmd_write(int cmd)
6735  {
6736 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6737         putname(tmp);
6738         if (IS_ERR(bdev))
6739                 return ERR_CAST(bdev);
6740 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6741 +       if (bdev && bdev->bd_inode &&
6742 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6743 +               struct block_device *bdnew = (void *)-EINVAL;
6744 +
6745 +               if (vroot_get_real_bdev)
6746 +                       bdnew = vroot_get_real_bdev(bdev);
6747 +               else
6748 +                       vxdprintk(VXD_CBIT(misc, 0),
6749 +                                       "vroot_get_real_bdev not set");
6750 +               bdput(bdev);
6751 +               if (IS_ERR(bdnew))
6752 +                       return ERR_PTR(PTR_ERR(bdnew));
6753 +               bdev = bdnew;
6754 +       }
6755 +#endif
6756         if (quotactl_cmd_write(cmd))
6757                 sb = get_super_thawed(bdev);
6758         else
6759 diff -NurpP --minimal linux-3.13.10/fs/stat.c linux-3.13.10-vs2.3.6.11/fs/stat.c
6760 --- linux-3.13.10/fs/stat.c     2014-01-22 20:39:07.000000000 +0000
6761 +++ linux-3.13.10-vs2.3.6.11/fs/stat.c  2014-01-31 20:38:03.000000000 +0000
6762 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6763         stat->nlink = inode->i_nlink;
6764         stat->uid = inode->i_uid;
6765         stat->gid = inode->i_gid;
6766 +       stat->tag = inode->i_tag;
6767         stat->rdev = inode->i_rdev;
6768         stat->size = i_size_read(inode);
6769         stat->atime = inode->i_atime;
6770 diff -NurpP --minimal linux-3.13.10/fs/statfs.c linux-3.13.10-vs2.3.6.11/fs/statfs.c
6771 --- linux-3.13.10/fs/statfs.c   2013-11-25 15:47:00.000000000 +0000
6772 +++ linux-3.13.10-vs2.3.6.11/fs/statfs.c        2014-01-31 20:38:03.000000000 +0000
6773 @@ -7,6 +7,8 @@
6774  #include <linux/statfs.h>
6775  #include <linux/security.h>
6776  #include <linux/uaccess.h>
6777 +#include <linux/vs_base.h>
6778 +#include <linux/vs_dlimit.h>
6779  #include "internal.h"
6780  
6781  static int flags_by_mnt(int mnt_flags)
6782 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6783         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6784         if (retval == 0 && buf->f_frsize == 0)
6785                 buf->f_frsize = buf->f_bsize;
6786 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6787 +               vx_vsi_statfs(dentry->d_sb, buf);
6788         return retval;
6789  }
6790  
6791 diff -NurpP --minimal linux-3.13.10/fs/super.c linux-3.13.10-vs2.3.6.11/fs/super.c
6792 --- linux-3.13.10/fs/super.c    2014-01-22 20:39:07.000000000 +0000
6793 +++ linux-3.13.10-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6794 @@ -34,6 +34,8 @@
6795  #include <linux/cleancache.h>
6796  #include <linux/fsnotify.h>
6797  #include <linux/lockdep.h>
6798 +#include <linux/magic.h>
6799 +#include <linux/vs_context.h>
6800  #include "internal.h"
6801  
6802  
6803 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6804         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6805         sb->s_flags |= MS_BORN;
6806  
6807 +       error = -EPERM;
6808 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6809 +               !sb->s_bdev &&
6810 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6811 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6812 +               goto out_sb;
6813 +
6814         error = security_sb_kern_mount(sb, flags, secdata);
6815         if (error)
6816                 goto out_sb;
6817 diff -NurpP --minimal linux-3.13.10/fs/kernfs/mount.c linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c
6818 --- linux-3.13.10/fs/kernfs/mount.c     2013-11-25 15:47:00.000000000 +0000
6819 +++ linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c  2014-01-31 20:38:03.000000000 +0000
6820 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6821  
6822         sb->s_blocksize = PAGE_CACHE_SIZE;
6823         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6824 -       sb->s_magic = SYSFS_MAGIC;
6825 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6826         sb->s_op = &kernfs_sops;
6827         sb->s_time_gran = 1;
6828  
6829 diff -NurpP --minimal linux-3.13.10/fs/utimes.c linux-3.13.10-vs2.3.6.11/fs/utimes.c
6830 --- linux-3.13.10/fs/utimes.c   2014-01-22 20:39:07.000000000 +0000
6831 +++ linux-3.13.10-vs2.3.6.11/fs/utimes.c        2014-01-31 23:49:14.000000000 +0000
6832 @@ -8,6 +8,8 @@
6833  #include <linux/stat.h>
6834  #include <linux/utime.h>
6835  #include <linux/syscalls.h>
6836 +#include <linux/mount.h>
6837 +#include <linux/vs_cowbl.h>
6838  #include <asm/uaccess.h>
6839  #include <asm/unistd.h>
6840  
6841 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6842  {
6843         int error;
6844         struct iattr newattrs;
6845 -       struct inode *inode = path->dentry->d_inode;
6846         struct inode *delegated_inode = NULL;
6847 +       struct inode *inode;
6848 +
6849 +       error = cow_check_and_break(path);
6850 +       if (error)
6851 +               goto out;
6852  
6853         error = mnt_want_write(path->mnt);
6854         if (error)
6855                 goto out;
6856  
6857 +       inode = path->dentry->d_inode;
6858 +
6859         if (times && times[0].tv_nsec == UTIME_NOW &&
6860                      times[1].tv_nsec == UTIME_NOW)
6861                 times = NULL;
6862 diff -NurpP --minimal linux-3.13.10/fs/xattr.c linux-3.13.10-vs2.3.6.11/fs/xattr.c
6863 --- linux-3.13.10/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6864 +++ linux-3.13.10-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6865 @@ -21,6 +21,7 @@
6866  #include <linux/audit.h>
6867  #include <linux/vmalloc.h>
6868  #include <linux/posix_acl_xattr.h>
6869 +#include <linux/mount.h>
6870  
6871  #include <asm/uaccess.h>
6872  
6873 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6874          * The trusted.* namespace can only be accessed by privileged users.
6875          */
6876         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6877 -               if (!capable(CAP_SYS_ADMIN))
6878 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6879                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6880                 return 0;
6881         }
6882 diff -NurpP --minimal linux-3.13.10/include/linux/cred.h linux-3.13.10-vs2.3.6.11/include/linux/cred.h
6883 --- linux-3.13.10/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
6884 +++ linux-3.13.10-vs2.3.6.11/include/linux/cred.h       2014-01-31 20:38:03.000000000 +0000
6885 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6886  extern int copy_creds(struct task_struct *, unsigned long);
6887  extern const struct cred *get_task_cred(struct task_struct *);
6888  extern struct cred *cred_alloc_blank(void);
6889 +extern struct cred *__prepare_creds(const struct cred *);
6890  extern struct cred *prepare_creds(void);
6891  extern struct cred *prepare_exec_creds(void);
6892  extern int commit_creds(struct cred *);
6893 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6894  }
6895  #endif
6896  
6897 +static inline void set_cred_subscribers(struct cred *cred, int n)
6898 +{
6899 +#ifdef CONFIG_DEBUG_CREDENTIALS
6900 +       atomic_set(&cred->subscribers, n);
6901 +#endif
6902 +}
6903 +
6904 +static inline int read_cred_subscribers(const struct cred *cred)
6905 +{
6906 +#ifdef CONFIG_DEBUG_CREDENTIALS
6907 +       return atomic_read(&cred->subscribers);
6908 +#else
6909 +       return 0;
6910 +#endif
6911 +}
6912 +
6913 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6914 +{
6915 +#ifdef CONFIG_DEBUG_CREDENTIALS
6916 +       struct cred *cred = (struct cred *) _cred;
6917 +
6918 +       atomic_add(n, &cred->subscribers);
6919 +#endif
6920 +}
6921 +
6922  /**
6923   * get_new_cred - Get a reference on a new set of credentials
6924   * @cred: The new credentials to reference
6925 diff -NurpP --minimal linux-3.13.10/include/linux/devpts_fs.h linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h
6926 --- linux-3.13.10/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
6927 +++ linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h  2014-01-31 20:38:03.000000000 +0000
6928 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6929  
6930  #endif
6931  
6932 -
6933  #endif /* _LINUX_DEVPTS_FS_H */
6934 diff -NurpP --minimal linux-3.13.10/include/linux/fs.h linux-3.13.10-vs2.3.6.11/include/linux/fs.h
6935 --- linux-3.13.10/include/linux/fs.h    2014-01-22 20:39:10.000000000 +0000
6936 +++ linux-3.13.10-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6937 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6938  #define ATTR_KILL_PRIV (1 << 14)
6939  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6940  #define ATTR_TIMES_SET (1 << 16)
6941 +#define ATTR_TAG       (1 << 17)
6942  
6943  /*
6944   * This is the Inode Attributes structure, used for notify_change().  It
6945 @@ -228,6 +229,7 @@ struct iattr {
6946         umode_t         ia_mode;
6947         kuid_t          ia_uid;
6948         kgid_t          ia_gid;
6949 +       ktag_t          ia_tag;
6950         loff_t          ia_size;
6951         struct timespec ia_atime;
6952         struct timespec ia_mtime;
6953 @@ -526,7 +528,9 @@ struct inode {
6954         unsigned short          i_opflags;
6955         kuid_t                  i_uid;
6956         kgid_t                  i_gid;
6957 -       unsigned int            i_flags;
6958 +       ktag_t                  i_tag;
6959 +       unsigned short          i_flags;
6960 +       unsigned short          i_vflags;
6961  
6962  #ifdef CONFIG_FS_POSIX_ACL
6963         struct posix_acl        *i_acl;
6964 @@ -555,6 +559,7 @@ struct inode {
6965                 unsigned int __i_nlink;
6966         };
6967         dev_t                   i_rdev;
6968 +       dev_t                   i_mdev;
6969         loff_t                  i_size;
6970         struct timespec         i_atime;
6971         struct timespec         i_mtime;
6972 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
6973         return from_kgid(&init_user_ns, inode->i_gid);
6974  }
6975  
6976 +static inline vtag_t i_tag_read(const struct inode *inode)
6977 +{
6978 +       return from_ktag(&init_user_ns, inode->i_tag);
6979 +}
6980 +
6981  static inline void i_uid_write(struct inode *inode, uid_t uid)
6982  {
6983         inode->i_uid = make_kuid(&init_user_ns, uid);
6984 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
6985         inode->i_gid = make_kgid(&init_user_ns, gid);
6986  }
6987  
6988 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
6989 +{
6990 +       inode->i_tag = make_ktag(&init_user_ns, tag);
6991 +}
6992 +
6993  static inline unsigned iminor(const struct inode *inode)
6994  {
6995 -       return MINOR(inode->i_rdev);
6996 +       return MINOR(inode->i_mdev);
6997  }
6998  
6999  static inline unsigned imajor(const struct inode *inode)
7000  {
7001 -       return MAJOR(inode->i_rdev);
7002 +       return MAJOR(inode->i_mdev);
7003  }
7004  
7005  extern struct block_device *I_BDEV(struct inode *inode);
7006 @@ -790,6 +805,7 @@ struct file {
7007         loff_t                  f_pos;
7008         struct fown_struct      f_owner;
7009         const struct cred       *f_cred;
7010 +       vxid_t                  f_xid;
7011         struct file_ra_state    f_ra;
7012  
7013         u64                     f_version;
7014 @@ -962,6 +978,7 @@ struct file_lock {
7015         struct file *fl_file;
7016         loff_t fl_start;
7017         loff_t fl_end;
7018 +       vxid_t fl_xid;
7019  
7020         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7021         /* for lease breaks: */
7022 @@ -1573,6 +1590,7 @@ struct inode_operations {
7023         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7024         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7025         int (*removexattr) (struct dentry *, const char *);
7026 +       int (*sync_flags) (struct inode *, int, int);
7027         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7028                       u64 len);
7029         int (*update_time)(struct inode *, struct timespec *, int);
7030 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7031                               unsigned long nr_segs, unsigned long fast_segs,
7032                               struct iovec *fast_pointer,
7033                               struct iovec **ret_pointer);
7034 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7035  
7036  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7037  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7038 @@ -1639,6 +1658,14 @@ struct super_operations {
7039  #define S_IMA          1024    /* Inode has an associated IMA struct */
7040  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7041  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7042 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7043 +
7044 +/* Linux-VServer related Inode flags */
7045 +
7046 +#define V_VALID                1
7047 +#define V_XATTR                2
7048 +#define V_BARRIER      4       /* Barrier for chroot() */
7049 +#define V_COW          8       /* Copy on Write */
7050  
7051  /*
7052   * Note that nosuid etc flags are inode-specific: setting some file-system
7053 @@ -1663,10 +1690,13 @@ struct super_operations {
7054  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7055  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7056  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7057 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7058  
7059  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7060  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7061  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7062 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7063 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7064  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7065  
7066  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7067 @@ -1677,6 +1707,16 @@ struct super_operations {
7068  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7069  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7070  
7071 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7072 +
7073 +#ifdef CONFIG_VSERVER_COWBL
7074 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7075 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7076 +#else
7077 +#  define IS_COW(inode)                (0)
7078 +#  define IS_COW_LINK(inode)   (0)
7079 +#endif
7080 +
7081  /*
7082   * Inode state bits.  Protected by inode->i_lock
7083   *
7084 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7085  extern int locks_mandatory_locked(struct inode *);
7086  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7087  
7088 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7089 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7090 +
7091  /*
7092   * Candidates for mandatory locking have the setgid bit set
7093   * but no group execute bit -  an otherwise meaningless combination.
7094 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7095  extern int dcache_dir_close(struct inode *, struct file *);
7096  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7097  extern int dcache_readdir(struct file *, struct dir_context *);
7098 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7099  extern int simple_setattr(struct dentry *, struct iattr *);
7100  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7101  extern int simple_statfs(struct dentry *, struct kstatfs *);
7102 diff -NurpP --minimal linux-3.13.10/include/linux/init_task.h linux-3.13.10-vs2.3.6.11/include/linux/init_task.h
7103 --- linux-3.13.10/include/linux/init_task.h     2014-01-22 20:39:11.000000000 +0000
7104 +++ linux-3.13.10-vs2.3.6.11/include/linux/init_task.h  2014-01-31 20:38:03.000000000 +0000
7105 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7106         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7107         INIT_CPUSET_SEQ(tsk)                                            \
7108         INIT_VTIME(tsk)                                                 \
7109 +       .xid            = 0,                                            \
7110 +       .vx_info        = NULL,                                         \
7111 +       .nid            = 0,                                            \
7112 +       .nx_info        = NULL,                                         \
7113  }
7114  
7115  
7116 diff -NurpP --minimal linux-3.13.10/include/linux/ipc.h linux-3.13.10-vs2.3.6.11/include/linux/ipc.h
7117 --- linux-3.13.10/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7118 +++ linux-3.13.10-vs2.3.6.11/include/linux/ipc.h        2014-01-31 20:38:03.000000000 +0000
7119 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7120         key_t           key;
7121         kuid_t          uid;
7122         kgid_t          gid;
7123 +       vxid_t          xid;
7124         kuid_t          cuid;
7125         kgid_t          cgid;
7126         umode_t         mode; 
7127 diff -NurpP --minimal linux-3.13.10/include/linux/memcontrol.h linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h
7128 --- linux-3.13.10/include/linux/memcontrol.h    2013-11-25 15:47:01.000000000 +0000
7129 +++ linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7130 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7131  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7132  extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7133  
7134 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7135 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7136 +
7137 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7138 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7139 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7140 +
7141  static inline
7142  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7143  {
7144 diff -NurpP --minimal linux-3.13.10/include/linux/mm_types.h linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h
7145 --- linux-3.13.10/include/linux/mm_types.h      2014-01-22 20:39:11.000000000 +0000
7146 +++ linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h   2014-01-31 20:38:03.000000000 +0000
7147 @@ -397,6 +397,7 @@ struct mm_struct {
7148  
7149         /* Architecture-specific MM context */
7150         mm_context_t context;
7151 +       struct vx_info *mm_vx_info;
7152  
7153         unsigned long flags; /* Must use atomic bitops to access the bits */
7154  
7155 diff -NurpP --minimal linux-3.13.10/include/linux/mount.h linux-3.13.10-vs2.3.6.11/include/linux/mount.h
7156 --- linux-3.13.10/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7157 +++ linux-3.13.10-vs2.3.6.11/include/linux/mount.h      2014-01-31 20:38:03.000000000 +0000
7158 @@ -52,6 +52,9 @@ struct mnt_namespace;
7159  #define MNT_DOOMED             0x1000000
7160  #define MNT_SYNC_UMOUNT                0x2000000
7161  
7162 +#define MNT_TAGID      0x10000
7163 +#define MNT_NOTAG      0x20000
7164 +
7165  struct vfsmount {
7166         struct dentry *mnt_root;        /* root of the mounted tree */
7167         struct super_block *mnt_sb;     /* pointer to superblock */
7168 diff -NurpP --minimal linux-3.13.10/include/linux/net.h linux-3.13.10-vs2.3.6.11/include/linux/net.h
7169 --- linux-3.13.10/include/linux/net.h   2014-01-22 20:39:11.000000000 +0000
7170 +++ linux-3.13.10-vs2.3.6.11/include/linux/net.h        2014-01-31 20:38:03.000000000 +0000
7171 @@ -39,6 +39,7 @@ struct net;
7172  #define SOCK_PASSCRED          3
7173  #define SOCK_PASSSEC           4
7174  #define SOCK_EXTERNALLY_ALLOCATED 5
7175 +#define SOCK_USER_SOCKET       6
7176  
7177  #ifndef ARCH_HAS_SOCKET_TYPES
7178  /**
7179 diff -NurpP --minimal linux-3.13.10/include/linux/netdevice.h linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h
7180 --- linux-3.13.10/include/linux/netdevice.h     2014-04-17 01:12:37.000000000 +0000
7181 +++ linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h  2014-03-12 15:51:07.000000000 +0000
7182 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7183  
7184  struct net_device *dev_get_by_index(struct net *net, int ifindex);
7185  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7186 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7187  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7188  int netdev_get_name(struct net *net, char *name, int ifindex);
7189  int dev_restart(struct net_device *dev);
7190 diff -NurpP --minimal linux-3.13.10/include/linux/nsproxy.h linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h
7191 --- linux-3.13.10/include/linux/nsproxy.h       2013-11-25 15:45:06.000000000 +0000
7192 +++ linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h    2014-01-31 20:38:03.000000000 +0000
7193 @@ -3,6 +3,7 @@
7194  
7195  #include <linux/spinlock.h>
7196  #include <linux/sched.h>
7197 +#include <linux/vserver/debug.h>
7198  
7199  struct mnt_namespace;
7200  struct uts_namespace;
7201 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7202  }
7203  
7204  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7205 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7206  void exit_task_namespaces(struct task_struct *tsk);
7207  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7208  void free_nsproxy(struct nsproxy *ns);
7209 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7210         struct cred *, struct fs_struct *);
7211  int __init nsproxy_cache_init(void);
7212  
7213 -static inline void put_nsproxy(struct nsproxy *ns)
7214 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7215 +
7216 +static inline void __get_nsproxy(struct nsproxy *ns,
7217 +       const char *_file, int _line)
7218  {
7219 -       if (atomic_dec_and_test(&ns->count)) {
7220 -               free_nsproxy(ns);
7221 -       }
7222 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7223 +               ns, atomic_read(&ns->count), _file, _line);
7224 +       atomic_inc(&ns->count);
7225  }
7226  
7227 -static inline void get_nsproxy(struct nsproxy *ns)
7228 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7229 +
7230 +static inline void __put_nsproxy(struct nsproxy *ns,
7231 +       const char *_file, int _line)
7232  {
7233 -       atomic_inc(&ns->count);
7234 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7235 +               ns, atomic_read(&ns->count), _file, _line);
7236 +       if (atomic_dec_and_test(&ns->count)) {
7237 +               free_nsproxy(ns);
7238 +       }
7239  }
7240  
7241  #endif
7242 diff -NurpP --minimal linux-3.13.10/include/linux/pid.h linux-3.13.10-vs2.3.6.11/include/linux/pid.h
7243 --- linux-3.13.10/include/linux/pid.h   2013-11-25 15:45:06.000000000 +0000
7244 +++ linux-3.13.10-vs2.3.6.11/include/linux/pid.h        2014-01-31 20:38:03.000000000 +0000
7245 @@ -8,7 +8,8 @@ enum pid_type
7246         PIDTYPE_PID,
7247         PIDTYPE_PGID,
7248         PIDTYPE_SID,
7249 -       PIDTYPE_MAX
7250 +       PIDTYPE_MAX,
7251 +       PIDTYPE_REALPID
7252  };
7253  
7254  /*
7255 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7256  }
7257  
7258  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7259 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7260  pid_t pid_vnr(struct pid *pid);
7261  
7262  #define do_each_pid_task(pid, type, task)                              \
7263 diff -NurpP --minimal linux-3.13.10/include/linux/quotaops.h linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h
7264 --- linux-3.13.10/include/linux/quotaops.h      2013-11-25 15:47:02.000000000 +0000
7265 +++ linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h   2014-01-31 20:38:03.000000000 +0000
7266 @@ -8,6 +8,7 @@
7267  #define _LINUX_QUOTAOPS_
7268  
7269  #include <linux/fs.h>
7270 +#include <linux/vs_dlimit.h>
7271  
7272  #define DQUOT_SPACE_WARN       0x1
7273  #define DQUOT_SPACE_RESERVE    0x2
7274 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7275  
7276  static inline int dquot_alloc_inode(const struct inode *inode)
7277  {
7278 -       return 0;
7279 +       return dl_alloc_inode(inode);
7280  }
7281  
7282  static inline void dquot_free_inode(const struct inode *inode)
7283  {
7284 +       dl_free_inode(inode);
7285  }
7286  
7287  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7288 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7289  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7290                 int flags)
7291  {
7292 +       int ret = 0;
7293 +
7294 +       if ((ret = dl_alloc_space(inode, number)))
7295 +               return ret;
7296         if (!(flags & DQUOT_SPACE_RESERVE))
7297                 inode_add_bytes(inode, number);
7298         return 0;
7299 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7300  {
7301         if (!(flags & DQUOT_SPACE_RESERVE))
7302                 inode_sub_bytes(inode, number);
7303 +       dl_free_space(inode, number);
7304  }
7305  
7306  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7307 diff -NurpP --minimal linux-3.13.10/include/linux/sched.h linux-3.13.10-vs2.3.6.11/include/linux/sched.h
7308 --- linux-3.13.10/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7309 +++ linux-3.13.10-vs2.3.6.11/include/linux/sched.h      2014-01-31 20:38:03.000000000 +0000
7310 @@ -1237,6 +1237,14 @@ struct task_struct {
7311  #endif
7312         struct seccomp seccomp;
7313  
7314 +/* vserver context data */
7315 +       struct vx_info *vx_info;
7316 +       struct nx_info *nx_info;
7317 +
7318 +       vxid_t xid;
7319 +       vnid_t nid;
7320 +       vtag_t tag;
7321 +
7322  /* Thread group tracking */
7323         u32 parent_exec_id;
7324         u32 self_exec_id;
7325 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7326  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7327                         struct pid_namespace *ns);
7328  
7329 +#include <linux/vserver/base.h>
7330 +#include <linux/vserver/context.h>
7331 +#include <linux/vserver/debug.h>
7332 +#include <linux/vserver/pid.h>
7333 +
7334  static inline pid_t task_pid_nr(struct task_struct *tsk)
7335  {
7336         return tsk->pid;
7337 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7338  
7339  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7340  {
7341 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7342 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7343 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7344  }
7345  
7346  
7347 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7348  
7349  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7350  {
7351 -       return pid_vnr(task_tgid(tsk));
7352 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7353  }
7354  
7355  
7356 diff -NurpP --minimal linux-3.13.10/include/linux/shmem_fs.h linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h
7357 --- linux-3.13.10/include/linux/shmem_fs.h      2014-01-22 20:39:11.000000000 +0000
7358 +++ linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h   2014-01-31 20:38:03.000000000 +0000
7359 @@ -9,6 +9,9 @@
7360  
7361  /* inode in-kernel data */
7362  
7363 +#define TMPFS_SUPER_MAGIC      0x01021994
7364 +
7365 +
7366  struct shmem_inode_info {
7367         spinlock_t              lock;
7368         unsigned long           flags;
7369 diff -NurpP --minimal linux-3.13.10/include/linux/stat.h linux-3.13.10-vs2.3.6.11/include/linux/stat.h
7370 --- linux-3.13.10/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
7371 +++ linux-3.13.10-vs2.3.6.11/include/linux/stat.h       2014-01-31 20:38:03.000000000 +0000
7372 @@ -25,6 +25,7 @@ struct kstat {
7373         unsigned int    nlink;
7374         kuid_t          uid;
7375         kgid_t          gid;
7376 +       ktag_t          tag;
7377         dev_t           rdev;
7378         loff_t          size;
7379         struct timespec  atime;
7380 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/auth.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h
7381 --- linux-3.13.10/include/linux/sunrpc/auth.h   2013-11-25 15:47:02.000000000 +0000
7382 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h        2014-01-31 20:38:03.000000000 +0000
7383 @@ -36,6 +36,7 @@ enum {
7384  struct auth_cred {
7385         kuid_t  uid;
7386         kgid_t  gid;
7387 +       ktag_t  tag;
7388         struct group_info *group_info;
7389         const char *principal;
7390         unsigned long ac_flags;
7391 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/clnt.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h
7392 --- linux-3.13.10/include/linux/sunrpc/clnt.h   2014-01-22 20:39:11.000000000 +0000
7393 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h        2014-01-31 20:38:03.000000000 +0000
7394 @@ -51,7 +51,8 @@ struct rpc_clnt {
7395                                 cl_discrtry : 1,/* disconnect before retry */
7396                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7397                                 cl_autobind : 1,/* use getport() */
7398 -                               cl_chatty   : 1;/* be verbose */
7399 +                               cl_chatty   : 1,/* be verbose */
7400 +                               cl_tag      : 1;/* context tagging */
7401  
7402         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7403         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7404 diff -NurpP --minimal linux-3.13.10/include/linux/sysfs.h linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h
7405 --- linux-3.13.10/include/linux/sysfs.h 2014-01-22 20:39:11.000000000 +0000
7406 +++ linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h      2014-01-31 20:38:03.000000000 +0000
7407 @@ -20,6 +20,8 @@
7408  #include <linux/stat.h>
7409  #include <linux/atomic.h>
7410  
7411 +#define SYSFS_SUPER_MAGIC      0x62656572
7412 +
7413  struct kobject;
7414  struct module;
7415  struct bin_attribute;
7416 diff -NurpP --minimal linux-3.13.10/include/linux/types.h linux-3.13.10-vs2.3.6.11/include/linux/types.h
7417 --- linux-3.13.10/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7418 +++ linux-3.13.10-vs2.3.6.11/include/linux/types.h      2014-01-31 20:38:03.000000000 +0000
7419 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7420  typedef __kernel_gid32_t       gid_t;
7421  typedef __kernel_uid16_t        uid16_t;
7422  typedef __kernel_gid16_t        gid16_t;
7423 +typedef unsigned int           vxid_t;
7424 +typedef unsigned int           vnid_t;
7425 +typedef unsigned int           vtag_t;
7426  
7427  typedef unsigned long          uintptr_t;
7428  
7429 diff -NurpP --minimal linux-3.13.10/include/linux/uidgid.h linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h
7430 --- linux-3.13.10/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
7431 +++ linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h     2014-01-31 20:38:03.000000000 +0000
7432 @@ -23,13 +23,17 @@ typedef struct {
7433         uid_t val;
7434  } kuid_t;
7435  
7436 -
7437  typedef struct {
7438         gid_t val;
7439  } kgid_t;
7440  
7441 +typedef struct {
7442 +       vtag_t val;
7443 +} ktag_t;
7444 +
7445  #define KUIDT_INIT(value) (kuid_t){ value }
7446  #define KGIDT_INIT(value) (kgid_t){ value }
7447 +#define KTAGT_INIT(value) (ktag_t){ value }
7448  
7449  static inline uid_t __kuid_val(kuid_t uid)
7450  {
7451 @@ -41,11 +45,18 @@ static inline gid_t __kgid_val(kgid_t gi
7452         return gid.val;
7453  }
7454  
7455 +static inline vtag_t __ktag_val(ktag_t tag)
7456 +{
7457 +       return tag.val;
7458 +}
7459 +
7460  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7461  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7462 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7463  
7464  #define INVALID_UID KUIDT_INIT(-1)
7465  #define INVALID_GID KGIDT_INIT(-1)
7466 +#define INVALID_TAG KTAGT_INIT(-1)
7467  
7468  static inline bool uid_eq(kuid_t left, kuid_t right)
7469  {
7470 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7471         return __kgid_val(left) == __kgid_val(right);
7472  }
7473  
7474 +static inline bool tag_eq(ktag_t left, ktag_t right)
7475 +{
7476 +       return __ktag_val(left) == __ktag_val(right);
7477 +}
7478 +
7479  static inline bool uid_gt(kuid_t left, kuid_t right)
7480  {
7481         return __kuid_val(left) > __kuid_val(right);
7482 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7483         return !gid_eq(gid, INVALID_GID);
7484  }
7485  
7486 +static inline bool tag_valid(ktag_t tag)
7487 +{
7488 +       return !tag_eq(tag, INVALID_TAG);
7489 +}
7490 +
7491  #ifdef CONFIG_USER_NS
7492  
7493  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7494  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7495 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7496  
7497  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7498  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7499 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7500 +
7501  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7502  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7503  
7504 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7505         return KGIDT_INIT(gid);
7506  }
7507  
7508 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7509 +{
7510 +       return KTAGT_INIT(tag);
7511 +}
7512 +
7513  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7514  {
7515         return __kuid_val(kuid);
7516 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7517         return __kgid_val(kgid);
7518  }
7519  
7520 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7521 +{
7522 +       return __ktag_val(ktag);
7523 +}
7524 +
7525  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7526  {
7527         uid_t uid = from_kuid(to, kuid);
7528 diff -NurpP --minimal linux-3.13.10/include/linux/vroot.h linux-3.13.10-vs2.3.6.11/include/linux/vroot.h
7529 --- linux-3.13.10/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7530 +++ linux-3.13.10-vs2.3.6.11/include/linux/vroot.h      2014-01-31 20:38:03.000000000 +0000
7531 @@ -0,0 +1,51 @@
7532 +
7533 +/*
7534 + * include/linux/vroot.h
7535 + *
7536 + * written by Herbert Pötzl, 9/11/2002
7537 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7538 + *
7539 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7540 + * Redistribution of this file is permitted under the
7541 + * GNU General Public License.
7542 + */
7543 +
7544 +#ifndef _LINUX_VROOT_H
7545 +#define _LINUX_VROOT_H
7546 +
7547 +
7548 +#ifdef __KERNEL__
7549 +
7550 +/* Possible states of device */
7551 +enum {
7552 +       Vr_unbound,
7553 +       Vr_bound,
7554 +};
7555 +
7556 +struct vroot_device {
7557 +       int             vr_number;
7558 +       int             vr_refcnt;
7559 +
7560 +       struct semaphore        vr_ctl_mutex;
7561 +       struct block_device    *vr_device;
7562 +       int                     vr_state;
7563 +};
7564 +
7565 +
7566 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7567 +
7568 +extern int register_vroot_grb(vroot_grb_func *);
7569 +extern int unregister_vroot_grb(vroot_grb_func *);
7570 +
7571 +#endif /* __KERNEL__ */
7572 +
7573 +#define MAX_VROOT_DEFAULT      8
7574 +
7575 +/*
7576 + * IOCTL commands --- we will commandeer 0x56 ('V')
7577 + */
7578 +
7579 +#define VROOT_SET_DEV          0x5600
7580 +#define VROOT_CLR_DEV          0x5601
7581 +
7582 +#endif /* _LINUX_VROOT_H */
7583 diff -NurpP --minimal linux-3.13.10/include/linux/vs_base.h linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h
7584 --- linux-3.13.10/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7585 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h    2014-01-31 20:38:03.000000000 +0000
7586 @@ -0,0 +1,10 @@
7587 +#ifndef _VS_BASE_H
7588 +#define _VS_BASE_H
7589 +
7590 +#include "vserver/base.h"
7591 +#include "vserver/check.h"
7592 +#include "vserver/debug.h"
7593 +
7594 +#else
7595 +#warning duplicate inclusion
7596 +#endif
7597 diff -NurpP --minimal linux-3.13.10/include/linux/vs_context.h linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h
7598 --- linux-3.13.10/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7599 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7600 @@ -0,0 +1,242 @@
7601 +#ifndef _VS_CONTEXT_H
7602 +#define _VS_CONTEXT_H
7603 +
7604 +#include "vserver/base.h"
7605 +#include "vserver/check.h"
7606 +#include "vserver/context.h"
7607 +#include "vserver/history.h"
7608 +#include "vserver/debug.h"
7609 +
7610 +#include <linux/sched.h>
7611 +
7612 +
7613 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7614 +
7615 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7616 +       const char *_file, int _line, void *_here)
7617 +{
7618 +       if (!vxi)
7619 +               return NULL;
7620 +
7621 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7622 +               vxi, vxi ? vxi->vx_id : 0,
7623 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7624 +               _file, _line);
7625 +       __vxh_get_vx_info(vxi, _here);
7626 +
7627 +       atomic_inc(&vxi->vx_usecnt);
7628 +       return vxi;
7629 +}
7630 +
7631 +
7632 +extern void free_vx_info(struct vx_info *);
7633 +
7634 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7635 +
7636 +static inline void __put_vx_info(struct vx_info *vxi,
7637 +       const char *_file, int _line, void *_here)
7638 +{
7639 +       if (!vxi)
7640 +               return;
7641 +
7642 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7643 +               vxi, vxi ? vxi->vx_id : 0,
7644 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7645 +               _file, _line);
7646 +       __vxh_put_vx_info(vxi, _here);
7647 +
7648 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7649 +               free_vx_info(vxi);
7650 +}
7651 +
7652 +
7653 +#define init_vx_info(p, i) \
7654 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7655 +
7656 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7657 +       const char *_file, int _line, void *_here)
7658 +{
7659 +       if (vxi) {
7660 +               vxlprintk(VXD_CBIT(xid, 3),
7661 +                       "init_vx_info(%p[#%d.%d])",
7662 +                       vxi, vxi ? vxi->vx_id : 0,
7663 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7664 +                       _file, _line);
7665 +               __vxh_init_vx_info(vxi, vxp, _here);
7666 +
7667 +               atomic_inc(&vxi->vx_usecnt);
7668 +       }
7669 +       *vxp = vxi;
7670 +}
7671 +
7672 +
7673 +#define set_vx_info(p, i) \
7674 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7675 +
7676 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7677 +       const char *_file, int _line, void *_here)
7678 +{
7679 +       struct vx_info *vxo;
7680 +
7681 +       if (!vxi)
7682 +               return;
7683 +
7684 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7685 +               vxi, vxi ? vxi->vx_id : 0,
7686 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7687 +               _file, _line);
7688 +       __vxh_set_vx_info(vxi, vxp, _here);
7689 +
7690 +       atomic_inc(&vxi->vx_usecnt);
7691 +       vxo = xchg(vxp, vxi);
7692 +       BUG_ON(vxo);
7693 +}
7694 +
7695 +
7696 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7697 +
7698 +static inline void __clr_vx_info(struct vx_info **vxp,
7699 +       const char *_file, int _line, void *_here)
7700 +{
7701 +       struct vx_info *vxo;
7702 +
7703 +       vxo = xchg(vxp, NULL);
7704 +       if (!vxo)
7705 +               return;
7706 +
7707 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7708 +               vxo, vxo ? vxo->vx_id : 0,
7709 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7710 +               _file, _line);
7711 +       __vxh_clr_vx_info(vxo, vxp, _here);
7712 +
7713 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7714 +               free_vx_info(vxo);
7715 +}
7716 +
7717 +
7718 +#define claim_vx_info(v, p) \
7719 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7720 +
7721 +static inline void __claim_vx_info(struct vx_info *vxi,
7722 +       struct task_struct *task,
7723 +       const char *_file, int _line, void *_here)
7724 +{
7725 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7726 +               vxi, vxi ? vxi->vx_id : 0,
7727 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7728 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7729 +               task, _file, _line);
7730 +       __vxh_claim_vx_info(vxi, task, _here);
7731 +
7732 +       atomic_inc(&vxi->vx_tasks);
7733 +}
7734 +
7735 +
7736 +extern void unhash_vx_info(struct vx_info *);
7737 +
7738 +#define release_vx_info(v, p) \
7739 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7740 +
7741 +static inline void __release_vx_info(struct vx_info *vxi,
7742 +       struct task_struct *task,
7743 +       const char *_file, int _line, void *_here)
7744 +{
7745 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7746 +               vxi, vxi ? vxi->vx_id : 0,
7747 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7748 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7749 +               task, _file, _line);
7750 +       __vxh_release_vx_info(vxi, task, _here);
7751 +
7752 +       might_sleep();
7753 +
7754 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7755 +               unhash_vx_info(vxi);
7756 +}
7757 +
7758 +
7759 +#define task_get_vx_info(p) \
7760 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7761 +
7762 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7763 +       const char *_file, int _line, void *_here)
7764 +{
7765 +       struct vx_info *vxi;
7766 +
7767 +       task_lock(p);
7768 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7769 +               p, _file, _line);
7770 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7771 +       task_unlock(p);
7772 +       return vxi;
7773 +}
7774 +
7775 +
7776 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7777 +{
7778 +       if (waitqueue_active(&vxi->vx_wait))
7779 +               wake_up_interruptible(&vxi->vx_wait);
7780 +}
7781 +
7782 +
7783 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7784 +
7785 +static inline void __enter_vx_info(struct vx_info *vxi,
7786 +       struct vx_info_save *vxis, const char *_file, int _line)
7787 +{
7788 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7789 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7790 +               current->xid, current->vx_info, _file, _line);
7791 +       vxis->vxi = xchg(&current->vx_info, vxi);
7792 +       vxis->xid = current->xid;
7793 +       current->xid = vxi ? vxi->vx_id : 0;
7794 +}
7795 +
7796 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7797 +
7798 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7799 +       const char *_file, int _line)
7800 +{
7801 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7802 +               vxis, vxis->xid, vxis->vxi, current,
7803 +               current->xid, current->vx_info, _file, _line);
7804 +       (void)xchg(&current->vx_info, vxis->vxi);
7805 +       current->xid = vxis->xid;
7806 +}
7807 +
7808 +
7809 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7810 +{
7811 +       vxis->vxi = xchg(&current->vx_info, NULL);
7812 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7813 +}
7814 +
7815 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7816 +{
7817 +       (void)xchg(&current->xid, vxis->xid);
7818 +       (void)xchg(&current->vx_info, vxis->vxi);
7819 +}
7820 +
7821 +#define task_is_init(p) \
7822 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7823 +
7824 +static inline int __task_is_init(struct task_struct *p,
7825 +       const char *_file, int _line, void *_here)
7826 +{
7827 +       int is_init = is_global_init(p);
7828 +
7829 +       task_lock(p);
7830 +       if (p->vx_info)
7831 +               is_init = p->vx_info->vx_initpid == p->pid;
7832 +       task_unlock(p);
7833 +       return is_init;
7834 +}
7835 +
7836 +extern void exit_vx_info(struct task_struct *, int);
7837 +extern void exit_vx_info_early(struct task_struct *, int);
7838 +
7839 +
7840 +#else
7841 +#warning duplicate inclusion
7842 +#endif
7843 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cowbl.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h
7844 --- linux-3.13.10/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7845 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h   2014-01-31 20:38:03.000000000 +0000
7846 @@ -0,0 +1,48 @@
7847 +#ifndef _VS_COWBL_H
7848 +#define _VS_COWBL_H
7849 +
7850 +#include <linux/fs.h>
7851 +#include <linux/dcache.h>
7852 +#include <linux/namei.h>
7853 +#include <linux/slab.h>
7854 +
7855 +extern struct dentry *cow_break_link(const char *pathname);
7856 +
7857 +static inline int cow_check_and_break(struct path *path)
7858 +{
7859 +       struct inode *inode = path->dentry->d_inode;
7860 +       int error = 0;
7861 +
7862 +       /* do we need this check? */
7863 +       if (IS_RDONLY(inode))
7864 +               return -EROFS;
7865 +
7866 +       if (IS_COW(inode)) {
7867 +               if (IS_COW_LINK(inode)) {
7868 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7869 +                       char *pp, *buf;
7870 +
7871 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7872 +                       if (!buf) {
7873 +                               return -ENOMEM;
7874 +                       }
7875 +                       pp = d_path(path, buf, PATH_MAX);
7876 +                       new_dentry = cow_break_link(pp);
7877 +                       kfree(buf);
7878 +                       if (!IS_ERR(new_dentry)) {
7879 +                               path->dentry = new_dentry;
7880 +                               dput(old_dentry);
7881 +                       } else
7882 +                               error = PTR_ERR(new_dentry);
7883 +               } else {
7884 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7885 +                       inode->i_ctime = CURRENT_TIME;
7886 +                       mark_inode_dirty(inode);
7887 +               }
7888 +       }
7889 +       return error;
7890 +}
7891 +
7892 +#else
7893 +#warning duplicate inclusion
7894 +#endif
7895 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h
7896 --- linux-3.13.10/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7897 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h   2014-01-31 20:38:03.000000000 +0000
7898 @@ -0,0 +1,50 @@
7899 +#ifndef _VS_CVIRT_H
7900 +#define _VS_CVIRT_H
7901 +
7902 +#include "vserver/cvirt.h"
7903 +#include "vserver/context.h"
7904 +#include "vserver/base.h"
7905 +#include "vserver/check.h"
7906 +#include "vserver/debug.h"
7907 +
7908 +
7909 +static inline void vx_activate_task(struct task_struct *p)
7910 +{
7911 +       struct vx_info *vxi;
7912 +
7913 +       if ((vxi = p->vx_info)) {
7914 +               vx_update_load(vxi);
7915 +               atomic_inc(&vxi->cvirt.nr_running);
7916 +       }
7917 +}
7918 +
7919 +static inline void vx_deactivate_task(struct task_struct *p)
7920 +{
7921 +       struct vx_info *vxi;
7922 +
7923 +       if ((vxi = p->vx_info)) {
7924 +               vx_update_load(vxi);
7925 +               atomic_dec(&vxi->cvirt.nr_running);
7926 +       }
7927 +}
7928 +
7929 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7930 +{
7931 +       struct vx_info *vxi;
7932 +
7933 +       if ((vxi = p->vx_info))
7934 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7935 +}
7936 +
7937 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7938 +{
7939 +       struct vx_info *vxi;
7940 +
7941 +       if ((vxi = p->vx_info))
7942 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7943 +}
7944 +
7945 +
7946 +#else
7947 +#warning duplicate inclusion
7948 +#endif
7949 diff -NurpP --minimal linux-3.13.10/include/linux/vs_device.h linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h
7950 --- linux-3.13.10/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
7951 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h  2014-01-31 20:38:03.000000000 +0000
7952 @@ -0,0 +1,45 @@
7953 +#ifndef _VS_DEVICE_H
7954 +#define _VS_DEVICE_H
7955 +
7956 +#include "vserver/base.h"
7957 +#include "vserver/device.h"
7958 +#include "vserver/debug.h"
7959 +
7960 +
7961 +#ifdef CONFIG_VSERVER_DEVICE
7962 +
7963 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7964 +
7965 +#define vs_device_perm(v, d, m, p) \
7966 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7967 +
7968 +#else
7969 +
7970 +static inline
7971 +int vs_map_device(struct vx_info *vxi,
7972 +       dev_t device, dev_t *target, umode_t mode)
7973 +{
7974 +       if (target)
7975 +               *target = device;
7976 +       return ~0;
7977 +}
7978 +
7979 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7980 +
7981 +#endif
7982 +
7983 +
7984 +#define vs_map_chrdev(d, t, p) \
7985 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7986 +#define vs_map_blkdev(d, t, p) \
7987 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7988 +
7989 +#define vs_chrdev_perm(d, p) \
7990 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7991 +#define vs_blkdev_perm(d, p) \
7992 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
7993 +
7994 +
7995 +#else
7996 +#warning duplicate inclusion
7997 +#endif
7998 diff -NurpP --minimal linux-3.13.10/include/linux/vs_dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h
7999 --- linux-3.13.10/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8000 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h  2014-01-31 20:38:03.000000000 +0000
8001 @@ -0,0 +1,215 @@
8002 +#ifndef _VS_DLIMIT_H
8003 +#define _VS_DLIMIT_H
8004 +
8005 +#include <linux/fs.h>
8006 +
8007 +#include "vserver/dlimit.h"
8008 +#include "vserver/base.h"
8009 +#include "vserver/debug.h"
8010 +
8011 +
8012 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8013 +
8014 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8015 +       const char *_file, int _line)
8016 +{
8017 +       if (!dli)
8018 +               return NULL;
8019 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8020 +               dli, dli ? dli->dl_tag : 0,
8021 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8022 +               _file, _line);
8023 +       atomic_inc(&dli->dl_usecnt);
8024 +       return dli;
8025 +}
8026 +
8027 +
8028 +#define free_dl_info(i) \
8029 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8030 +
8031 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8032 +
8033 +static inline void __put_dl_info(struct dl_info *dli,
8034 +       const char *_file, int _line)
8035 +{
8036 +       if (!dli)
8037 +               return;
8038 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8039 +               dli, dli ? dli->dl_tag : 0,
8040 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8041 +               _file, _line);
8042 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8043 +               free_dl_info(dli);
8044 +}
8045 +
8046 +
8047 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8048 +
8049 +static inline int __dl_alloc_space(struct super_block *sb,
8050 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8051 +{
8052 +       struct dl_info *dli = NULL;
8053 +       int ret = 0;
8054 +
8055 +       if (nr == 0)
8056 +               goto out;
8057 +       dli = locate_dl_info(sb, tag);
8058 +       if (!dli)
8059 +               goto out;
8060 +
8061 +       spin_lock(&dli->dl_lock);
8062 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8063 +       if (!ret)
8064 +               dli->dl_space_used += nr;
8065 +       spin_unlock(&dli->dl_lock);
8066 +       put_dl_info(dli);
8067 +out:
8068 +       vxlprintk(VXD_CBIT(dlim, 1),
8069 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8070 +               sb, tag, __dlimit_char(dli), (long long)nr,
8071 +               ret, file, line);
8072 +       return ret ? -ENOSPC : 0;
8073 +}
8074 +
8075 +static inline void __dl_free_space(struct super_block *sb,
8076 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8077 +{
8078 +       struct dl_info *dli = NULL;
8079 +
8080 +       if (nr == 0)
8081 +               goto out;
8082 +       dli = locate_dl_info(sb, tag);
8083 +       if (!dli)
8084 +               goto out;
8085 +
8086 +       spin_lock(&dli->dl_lock);
8087 +       if (dli->dl_space_used > nr)
8088 +               dli->dl_space_used -= nr;
8089 +       else
8090 +               dli->dl_space_used = 0;
8091 +       spin_unlock(&dli->dl_lock);
8092 +       put_dl_info(dli);
8093 +out:
8094 +       vxlprintk(VXD_CBIT(dlim, 1),
8095 +               "FREE  (%p,#%d)%c %lld bytes",
8096 +               sb, tag, __dlimit_char(dli), (long long)nr,
8097 +               _file, _line);
8098 +}
8099 +
8100 +static inline int __dl_alloc_inode(struct super_block *sb,
8101 +       vtag_t tag, const char *_file, int _line)
8102 +{
8103 +       struct dl_info *dli;
8104 +       int ret = 0;
8105 +
8106 +       dli = locate_dl_info(sb, tag);
8107 +       if (!dli)
8108 +               goto out;
8109 +
8110 +       spin_lock(&dli->dl_lock);
8111 +       dli->dl_inodes_used++;
8112 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8113 +       spin_unlock(&dli->dl_lock);
8114 +       put_dl_info(dli);
8115 +out:
8116 +       vxlprintk(VXD_CBIT(dlim, 0),
8117 +               "ALLOC (%p,#%d)%c inode (%d)",
8118 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8119 +       return ret ? -ENOSPC : 0;
8120 +}
8121 +
8122 +static inline void __dl_free_inode(struct super_block *sb,
8123 +       vtag_t tag, const char *_file, int _line)
8124 +{
8125 +       struct dl_info *dli;
8126 +
8127 +       dli = locate_dl_info(sb, tag);
8128 +       if (!dli)
8129 +               goto out;
8130 +
8131 +       spin_lock(&dli->dl_lock);
8132 +       if (dli->dl_inodes_used > 1)
8133 +               dli->dl_inodes_used--;
8134 +       else
8135 +               dli->dl_inodes_used = 0;
8136 +       spin_unlock(&dli->dl_lock);
8137 +       put_dl_info(dli);
8138 +out:
8139 +       vxlprintk(VXD_CBIT(dlim, 0),
8140 +               "FREE  (%p,#%d)%c inode",
8141 +               sb, tag, __dlimit_char(dli), _file, _line);
8142 +}
8143 +
8144 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8145 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8146 +       const char *_file, int _line)
8147 +{
8148 +       struct dl_info *dli;
8149 +       uint64_t broot, bfree;
8150 +
8151 +       dli = locate_dl_info(sb, tag);
8152 +       if (!dli)
8153 +               return;
8154 +
8155 +       spin_lock(&dli->dl_lock);
8156 +       broot = (dli->dl_space_total -
8157 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8158 +               >> sb->s_blocksize_bits;
8159 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8160 +                       >> sb->s_blocksize_bits;
8161 +       spin_unlock(&dli->dl_lock);
8162 +
8163 +       vxlprintk(VXD_CBIT(dlim, 2),
8164 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8165 +               (long long)bfree, (long long)broot,
8166 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8167 +               _file, _line);
8168 +       if (free_blocks) {
8169 +               if (*free_blocks > bfree)
8170 +                       *free_blocks = bfree;
8171 +       }
8172 +       if (root_blocks) {
8173 +               if (*root_blocks > broot)
8174 +                       *root_blocks = broot;
8175 +       }
8176 +       put_dl_info(dli);
8177 +}
8178 +
8179 +#define dl_prealloc_space(in, bytes) \
8180 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8181 +               __FILE__, __LINE__ )
8182 +
8183 +#define dl_alloc_space(in, bytes) \
8184 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8185 +               __FILE__, __LINE__ )
8186 +
8187 +#define dl_reserve_space(in, bytes) \
8188 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8189 +               __FILE__, __LINE__ )
8190 +
8191 +#define dl_claim_space(in, bytes) (0)
8192 +
8193 +#define dl_release_space(in, bytes) \
8194 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8195 +               __FILE__, __LINE__ )
8196 +
8197 +#define dl_free_space(in, bytes) \
8198 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8199 +               __FILE__, __LINE__ )
8200 +
8201 +
8202 +
8203 +#define dl_alloc_inode(in) \
8204 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8205 +
8206 +#define dl_free_inode(in) \
8207 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8208 +
8209 +
8210 +#define dl_adjust_block(sb, tag, fb, rb) \
8211 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8212 +
8213 +
8214 +#else
8215 +#warning duplicate inclusion
8216 +#endif
8217 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h
8218 --- linux-3.13.10/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8219 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h    2014-02-01 00:32:45.000000000 +0000
8220 @@ -0,0 +1,364 @@
8221 +#ifndef _VS_INET_H
8222 +#define _VS_INET_H
8223 +
8224 +#include "vserver/base.h"
8225 +#include "vserver/network.h"
8226 +#include "vserver/debug.h"
8227 +
8228 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8229 +
8230 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8231 +                       NIPQUAD((a)->mask), (a)->type
8232 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8233 +
8234 +#define NIPQUAD(addr) \
8235 +       ((unsigned char *)&addr)[0], \
8236 +       ((unsigned char *)&addr)[1], \
8237 +       ((unsigned char *)&addr)[2], \
8238 +       ((unsigned char *)&addr)[3]
8239 +
8240 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8241 +
8242 +
8243 +static inline
8244 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8245 +{
8246 +       __be32 ip = nxa->ip[0].s_addr;
8247 +       __be32 mask = nxa->mask.s_addr;
8248 +       __be32 bcast = ip | ~mask;
8249 +       int ret = 0;
8250 +
8251 +       switch (nxa->type & tmask) {
8252 +       case NXA_TYPE_MASK:
8253 +               ret = (ip == (addr & mask));
8254 +               break;
8255 +       case NXA_TYPE_ADDR:
8256 +               ret = 3;
8257 +               if (addr == ip)
8258 +                       break;
8259 +               /* fall through to broadcast */
8260 +       case NXA_MOD_BCAST:
8261 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8262 +               break;
8263 +       case NXA_TYPE_RANGE:
8264 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8265 +                       (nxa->ip[1].s_addr > addr));
8266 +               break;
8267 +       case NXA_TYPE_ANY:
8268 +               ret = 2;
8269 +               break;
8270 +       }
8271 +
8272 +       vxdprintk(VXD_CBIT(net, 0),
8273 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8274 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8275 +       return ret;
8276 +}
8277 +
8278 +static inline
8279 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8280 +{
8281 +       struct nx_addr_v4 *nxa;
8282 +       unsigned long irqflags;
8283 +       int ret = 1;
8284 +
8285 +       if (!nxi)
8286 +               goto out;
8287 +
8288 +       ret = 2;
8289 +       /* allow 127.0.0.1 when remapping lback */
8290 +       if ((tmask & NXA_LOOPBACK) &&
8291 +               (addr == IPI_LOOPBACK) &&
8292 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8293 +               goto out;
8294 +       ret = 3;
8295 +       /* check for lback address */
8296 +       if ((tmask & NXA_MOD_LBACK) &&
8297 +               (nxi->v4_lback.s_addr == addr))
8298 +               goto out;
8299 +       ret = 4;
8300 +       /* check for broadcast address */
8301 +       if ((tmask & NXA_MOD_BCAST) &&
8302 +               (nxi->v4_bcast.s_addr == addr))
8303 +               goto out;
8304 +       ret = 5;
8305 +
8306 +       /* check for v4 addresses */
8307 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8308 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8309 +               if (v4_addr_match(nxa, addr, tmask))
8310 +                       goto out_unlock;
8311 +       ret = 0;
8312 +out_unlock:
8313 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8314 +out:
8315 +       vxdprintk(VXD_CBIT(net, 0),
8316 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8317 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8318 +       return ret;
8319 +}
8320 +
8321 +static inline
8322 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8323 +{
8324 +       /* FIXME: needs full range checks */
8325 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8326 +}
8327 +
8328 +static inline
8329 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8330 +{
8331 +       struct nx_addr_v4 *ptr;
8332 +       unsigned long irqflags;
8333 +       int ret = 1;
8334 +
8335 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8336 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8337 +               if (v4_nx_addr_match(ptr, nxa, mask))
8338 +                       goto out_unlock;
8339 +       ret = 0;
8340 +out_unlock:
8341 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8342 +       return ret;
8343 +}
8344 +
8345 +#include <net/inet_sock.h>
8346 +
8347 +/*
8348 + *     Check if a given address matches for a socket
8349 + *
8350 + *     nxi:            the socket's nx_info if any
8351 + *     addr:           to be verified address
8352 + */
8353 +static inline
8354 +int v4_sock_addr_match (
8355 +       struct nx_info *nxi,
8356 +       struct inet_sock *inet,
8357 +       __be32 addr)
8358 +{
8359 +       __be32 saddr = inet->inet_rcv_saddr;
8360 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8361 +
8362 +       if (addr && (saddr == addr || bcast == addr))
8363 +               return 1;
8364 +       if (!saddr)
8365 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8366 +       return 0;
8367 +}
8368 +
8369 +
8370 +/* inet related checks and helpers */
8371 +
8372 +
8373 +struct in_ifaddr;
8374 +struct net_device;
8375 +struct sock;
8376 +
8377 +#ifdef CONFIG_INET
8378 +
8379 +#include <linux/netdevice.h>
8380 +#include <linux/inetdevice.h>
8381 +#include <net/inet_sock.h>
8382 +#include <net/inet_timewait_sock.h>
8383 +
8384 +
8385 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8386 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8387 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8388 +
8389 +
8390 +/*
8391 + *     check if address is covered by socket
8392 + *
8393 + *     sk:     the socket to check against
8394 + *     addr:   the address in question (must be != 0)
8395 + */
8396 +
8397 +static inline
8398 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8399 +{
8400 +       struct nx_info *nxi = sk->sk_nx_info;
8401 +       __be32 saddr = sk->sk_rcv_saddr;
8402 +
8403 +       vxdprintk(VXD_CBIT(net, 5),
8404 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8405 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8406 +               (sk->sk_socket?sk->sk_socket->flags:0));
8407 +
8408 +       if (saddr) {            /* direct address match */
8409 +               return v4_addr_match(nxa, saddr, -1);
8410 +       } else if (nxi) {       /* match against nx_info */
8411 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8412 +       } else {                /* unrestricted any socket */
8413 +               return 1;
8414 +       }
8415 +}
8416 +
8417 +
8418 +
8419 +static inline
8420 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8421 +{
8422 +       vxdprintk(VXD_CBIT(net, 1),
8423 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8424 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8425 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8426 +
8427 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8428 +               return 1;
8429 +       if (dev_in_nx_info(dev, nxi))
8430 +               return 1;
8431 +       return 0;
8432 +}
8433 +
8434 +
8435 +static inline
8436 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8437 +{
8438 +       if (!nxi)
8439 +               return 1;
8440 +       if (!ifa)
8441 +               return 0;
8442 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8443 +}
8444 +
8445 +static inline
8446 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8447 +{
8448 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8449 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8450 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8451 +
8452 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8453 +               return 1;
8454 +       if (v4_ifa_in_nx_info(ifa, nxi))
8455 +               return 1;
8456 +       return 0;
8457 +}
8458 +
8459 +
8460 +struct nx_v4_sock_addr {
8461 +       __be32 saddr;   /* Address used for validation */
8462 +       __be32 baddr;   /* Address used for socket bind */
8463 +};
8464 +
8465 +static inline
8466 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8467 +       struct nx_v4_sock_addr *nsa)
8468 +{
8469 +       struct sock *sk = &inet->sk;
8470 +       struct nx_info *nxi = sk->sk_nx_info;
8471 +       __be32 saddr = addr->sin_addr.s_addr;
8472 +       __be32 baddr = saddr;
8473 +
8474 +       vxdprintk(VXD_CBIT(net, 3),
8475 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8476 +               sk, sk->sk_nx_info, sk->sk_socket,
8477 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8478 +               NIPQUAD(saddr));
8479 +
8480 +       if (nxi) {
8481 +               if (saddr == INADDR_ANY) {
8482 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8483 +                               baddr = nxi->v4.ip[0].s_addr;
8484 +               } else if (saddr == IPI_LOOPBACK) {
8485 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8486 +                               baddr = nxi->v4_lback.s_addr;
8487 +               } else if (!ipv4_is_multicast(saddr) ||
8488 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8489 +                       /* normal address bind */
8490 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8491 +                               return -EADDRNOTAVAIL;
8492 +               }
8493 +       }
8494 +
8495 +       vxdprintk(VXD_CBIT(net, 3),
8496 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8497 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8498 +
8499 +       nsa->saddr = saddr;
8500 +       nsa->baddr = baddr;
8501 +       return 0;
8502 +}
8503 +
8504 +static inline
8505 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8506 +{
8507 +       inet->inet_saddr = nsa->baddr;
8508 +       inet->inet_rcv_saddr = nsa->baddr;
8509 +}
8510 +
8511 +
8512 +/*
8513 + *      helper to simplify inet_lookup_listener
8514 + *
8515 + *      nxi:   the socket's nx_info if any
8516 + *      addr:  to be verified address
8517 + *      saddr: socket address
8518 + */
8519 +static inline int v4_inet_addr_match (
8520 +       struct nx_info *nxi,
8521 +       __be32 addr,
8522 +       __be32 saddr)
8523 +{
8524 +       if (addr && (saddr == addr))
8525 +               return 1;
8526 +       if (!saddr)
8527 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8528 +       return 0;
8529 +}
8530 +
8531 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8532 +{
8533 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8534 +               (addr == nxi->v4_lback.s_addr))
8535 +               return IPI_LOOPBACK;
8536 +       return addr;
8537 +}
8538 +
8539 +static inline
8540 +int nx_info_has_v4(struct nx_info *nxi)
8541 +{
8542 +       if (!nxi)
8543 +               return 1;
8544 +       if (NX_IPV4(nxi))
8545 +               return 1;
8546 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8547 +               return 1;
8548 +       return 0;
8549 +}
8550 +
8551 +#else /* CONFIG_INET */
8552 +
8553 +static inline
8554 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8555 +{
8556 +       return 1;
8557 +}
8558 +
8559 +static inline
8560 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8561 +{
8562 +       return 1;
8563 +}
8564 +
8565 +static inline
8566 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8567 +{
8568 +       return 1;
8569 +}
8570 +
8571 +static inline
8572 +int nx_info_has_v4(struct nx_info *nxi)
8573 +{
8574 +       return 0;
8575 +}
8576 +
8577 +#endif /* CONFIG_INET */
8578 +
8579 +#define current_nx_info_has_v4() \
8580 +       nx_info_has_v4(current_nx_info())
8581 +
8582 +#else
8583 +// #warning duplicate inclusion
8584 +#endif
8585 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet6.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h
8586 --- linux-3.13.10/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8587 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h   2014-02-01 00:35:02.000000000 +0000
8588 @@ -0,0 +1,257 @@
8589 +#ifndef _VS_INET6_H
8590 +#define _VS_INET6_H
8591 +
8592 +#include "vserver/base.h"
8593 +#include "vserver/network.h"
8594 +#include "vserver/debug.h"
8595 +
8596 +#include <net/ipv6.h>
8597 +
8598 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8599 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8600 +
8601 +
8602 +#ifdef CONFIG_IPV6
8603 +
8604 +static inline
8605 +int v6_addr_match(struct nx_addr_v6 *nxa,
8606 +       const struct in6_addr *addr, uint16_t mask)
8607 +{
8608 +       int ret = 0;
8609 +
8610 +       switch (nxa->type & mask) {
8611 +       case NXA_TYPE_MASK:
8612 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8613 +               break;
8614 +       case NXA_TYPE_ADDR:
8615 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8616 +               break;
8617 +       case NXA_TYPE_ANY:
8618 +               ret = 1;
8619 +               break;
8620 +       }
8621 +       vxdprintk(VXD_CBIT(net, 0),
8622 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8623 +               nxa, NXAV6(nxa), addr, mask, ret);
8624 +       return ret;
8625 +}
8626 +
8627 +static inline
8628 +int v6_addr_in_nx_info(struct nx_info *nxi,
8629 +       const struct in6_addr *addr, uint16_t mask)
8630 +{
8631 +       struct nx_addr_v6 *nxa;
8632 +       unsigned long irqflags;
8633 +       int ret = 1;
8634 +
8635 +       if (!nxi)
8636 +               goto out;
8637 +
8638 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8639 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8640 +               if (v6_addr_match(nxa, addr, mask))
8641 +                       goto out_unlock;
8642 +       ret = 0;
8643 +out_unlock:
8644 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8645 +out:
8646 +       vxdprintk(VXD_CBIT(net, 0),
8647 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8648 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8649 +       return ret;
8650 +}
8651 +
8652 +static inline
8653 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8654 +{
8655 +       /* FIXME: needs full range checks */
8656 +       return v6_addr_match(nxa, &addr->ip, mask);
8657 +}
8658 +
8659 +static inline
8660 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8661 +{
8662 +       struct nx_addr_v6 *ptr;
8663 +       unsigned long irqflags;
8664 +       int ret = 1;
8665 +
8666 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8667 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8668 +               if (v6_nx_addr_match(ptr, nxa, mask))
8669 +                       goto out_unlock;
8670 +       ret = 0;
8671 +out_unlock:
8672 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8673 +       return ret;
8674 +}
8675 +
8676 +
8677 +/*
8678 + *     Check if a given address matches for a socket
8679 + *
8680 + *     nxi:            the socket's nx_info if any
8681 + *     addr:           to be verified address
8682 + */
8683 +static inline
8684 +int v6_sock_addr_match (
8685 +       struct nx_info *nxi,
8686 +       struct inet_sock *inet,
8687 +       struct in6_addr *addr)
8688 +{
8689 +       struct sock *sk = &inet->sk;
8690 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8691 +
8692 +       if (!ipv6_addr_any(addr) &&
8693 +               ipv6_addr_equal(saddr, addr))
8694 +               return 1;
8695 +       if (ipv6_addr_any(saddr))
8696 +               return v6_addr_in_nx_info(nxi, addr, -1);
8697 +       return 0;
8698 +}
8699 +
8700 +/*
8701 + *     check if address is covered by socket
8702 + *
8703 + *     sk:     the socket to check against
8704 + *     addr:   the address in question (must be != 0)
8705 + */
8706 +
8707 +static inline
8708 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8709 +{
8710 +       struct nx_info *nxi = sk->sk_nx_info;
8711 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8712 +
8713 +       vxdprintk(VXD_CBIT(net, 5),
8714 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8715 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8716 +               (sk->sk_socket?sk->sk_socket->flags:0));
8717 +
8718 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8719 +               return v6_addr_match(nxa, saddr, -1);
8720 +       } else if (nxi) {               /* match against nx_info */
8721 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8722 +       } else {                        /* unrestricted any socket */
8723 +               return 1;
8724 +       }
8725 +}
8726 +
8727 +
8728 +/* inet related checks and helpers */
8729 +
8730 +
8731 +struct in_ifaddr;
8732 +struct net_device;
8733 +struct sock;
8734 +
8735 +
8736 +#include <linux/netdevice.h>
8737 +#include <linux/inetdevice.h>
8738 +#include <net/inet_timewait_sock.h>
8739 +
8740 +
8741 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8742 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8743 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8744 +
8745 +
8746 +
8747 +static inline
8748 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8749 +{
8750 +       if (!nxi)
8751 +               return 1;
8752 +       if (!ifa)
8753 +               return 0;
8754 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8755 +}
8756 +
8757 +static inline
8758 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8759 +{
8760 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8761 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8762 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8763 +
8764 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8765 +               return 1;
8766 +       if (v6_ifa_in_nx_info(ifa, nxi))
8767 +               return 1;
8768 +       return 0;
8769 +}
8770 +
8771 +
8772 +struct nx_v6_sock_addr {
8773 +       struct in6_addr saddr;  /* Address used for validation */
8774 +       struct in6_addr baddr;  /* Address used for socket bind */
8775 +};
8776 +
8777 +static inline
8778 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8779 +       struct nx_v6_sock_addr *nsa)
8780 +{
8781 +       // struct sock *sk = &inet->sk;
8782 +       // struct nx_info *nxi = sk->sk_nx_info;
8783 +       struct in6_addr saddr = addr->sin6_addr;
8784 +       struct in6_addr baddr = saddr;
8785 +
8786 +       nsa->saddr = saddr;
8787 +       nsa->baddr = baddr;
8788 +       return 0;
8789 +}
8790 +
8791 +static inline
8792 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8793 +{
8794 +       // struct sock *sk = &inet->sk;
8795 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8796 +
8797 +       // *saddr = nsa->baddr;
8798 +       // inet->inet_saddr = nsa->baddr;
8799 +}
8800 +
8801 +static inline
8802 +int nx_info_has_v6(struct nx_info *nxi)
8803 +{
8804 +       if (!nxi)
8805 +               return 1;
8806 +       if (NX_IPV6(nxi))
8807 +               return 1;
8808 +       return 0;
8809 +}
8810 +
8811 +#else /* CONFIG_IPV6 */
8812 +
8813 +static inline
8814 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8815 +{
8816 +       return 1;
8817 +}
8818 +
8819 +
8820 +static inline
8821 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8822 +{
8823 +       return 1;
8824 +}
8825 +
8826 +static inline
8827 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8828 +{
8829 +       return 1;
8830 +}
8831 +
8832 +static inline
8833 +int nx_info_has_v6(struct nx_info *nxi)
8834 +{
8835 +       return 0;
8836 +}
8837 +
8838 +#endif /* CONFIG_IPV6 */
8839 +
8840 +#define current_nx_info_has_v6() \
8841 +       nx_info_has_v6(current_nx_info())
8842 +
8843 +#else
8844 +#warning duplicate inclusion
8845 +#endif
8846 diff -NurpP --minimal linux-3.13.10/include/linux/vs_limit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h
8847 --- linux-3.13.10/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8848 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h   2014-02-01 01:29:43.000000000 +0000
8849 @@ -0,0 +1,140 @@
8850 +#ifndef _VS_LIMIT_H
8851 +#define _VS_LIMIT_H
8852 +
8853 +#include "vserver/limit.h"
8854 +#include "vserver/base.h"
8855 +#include "vserver/context.h"
8856 +#include "vserver/debug.h"
8857 +#include "vserver/context.h"
8858 +#include "vserver/limit_int.h"
8859 +
8860 +
8861 +#define vx_acc_cres(v, d, p, r) \
8862 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8863 +
8864 +#define vx_acc_cres_cond(x, d, p, r) \
8865 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8866 +       r, d, p, __FILE__, __LINE__)
8867 +
8868 +
8869 +#define vx_add_cres(v, a, p, r) \
8870 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8871 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8872 +
8873 +#define vx_add_cres_cond(x, a, p, r) \
8874 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8875 +       r, a, p, __FILE__, __LINE__)
8876 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8877 +
8878 +
8879 +/* process and file limits */
8880 +
8881 +#define vx_nproc_inc(p) \
8882 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8883 +
8884 +#define vx_nproc_dec(p) \
8885 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8886 +
8887 +#define vx_files_inc(f) \
8888 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8889 +
8890 +#define vx_files_dec(f) \
8891 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8892 +
8893 +#define vx_locks_inc(l) \
8894 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8895 +
8896 +#define vx_locks_dec(l) \
8897 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8898 +
8899 +#define vx_openfd_inc(f) \
8900 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8901 +
8902 +#define vx_openfd_dec(f) \
8903 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8904 +
8905 +
8906 +#define vx_cres_avail(v, n, r) \
8907 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8908 +
8909 +
8910 +#define vx_nproc_avail(n) \
8911 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8912 +
8913 +#define vx_files_avail(n) \
8914 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8915 +
8916 +#define vx_locks_avail(n) \
8917 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8918 +
8919 +#define vx_openfd_avail(n) \
8920 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8921 +
8922 +
8923 +/* dentry limits */
8924 +
8925 +#define vx_dentry_inc(d) do {                                          \
8926 +       if (d_count(d) == 1)                                            \
8927 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8928 +       } while (0)
8929 +
8930 +#define vx_dentry_dec(d) do {                                          \
8931 +       if (d_count(d) == 0)                                            \
8932 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8933 +       } while (0)
8934 +
8935 +#define vx_dentry_avail(n) \
8936 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8937 +
8938 +
8939 +/* socket limits */
8940 +
8941 +#define vx_sock_inc(s) \
8942 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8943 +
8944 +#define vx_sock_dec(s) \
8945 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8946 +
8947 +#define vx_sock_avail(n) \
8948 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8949 +
8950 +
8951 +/* ipc resource limits */
8952 +
8953 +#define vx_ipcmsg_add(v, u, a) \
8954 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8955 +
8956 +#define vx_ipcmsg_sub(v, u, a) \
8957 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8958 +
8959 +#define vx_ipcmsg_avail(v, a) \
8960 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8961 +
8962 +
8963 +#define vx_ipcshm_add(v, k, a) \
8964 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8965 +
8966 +#define vx_ipcshm_sub(v, k, a) \
8967 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8968 +
8969 +#define vx_ipcshm_avail(v, a) \
8970 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
8971 +
8972 +
8973 +#define vx_semary_inc(a) \
8974 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8975 +
8976 +#define vx_semary_dec(a) \
8977 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8978 +
8979 +
8980 +#define vx_nsems_add(a,n) \
8981 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8982 +
8983 +#define vx_nsems_sub(a,n) \
8984 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8985 +
8986 +
8987 +#else
8988 +#warning duplicate inclusion
8989 +#endif
8990 diff -NurpP --minimal linux-3.13.10/include/linux/vs_network.h linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h
8991 --- linux-3.13.10/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
8992 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
8993 @@ -0,0 +1,169 @@
8994 +#ifndef _NX_VS_NETWORK_H
8995 +#define _NX_VS_NETWORK_H
8996 +
8997 +#include "vserver/context.h"
8998 +#include "vserver/network.h"
8999 +#include "vserver/base.h"
9000 +#include "vserver/check.h"
9001 +#include "vserver/debug.h"
9002 +
9003 +#include <linux/sched.h>
9004 +
9005 +
9006 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9007 +
9008 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9009 +       const char *_file, int _line)
9010 +{
9011 +       if (!nxi)
9012 +               return NULL;
9013 +
9014 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9015 +               nxi, nxi ? nxi->nx_id : 0,
9016 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9017 +               _file, _line);
9018 +
9019 +       atomic_inc(&nxi->nx_usecnt);
9020 +       return nxi;
9021 +}
9022 +
9023 +
9024 +extern void free_nx_info(struct nx_info *);
9025 +
9026 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9027 +
9028 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9029 +{
9030 +       if (!nxi)
9031 +               return;
9032 +
9033 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9034 +               nxi, nxi ? nxi->nx_id : 0,
9035 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9036 +               _file, _line);
9037 +
9038 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9039 +               free_nx_info(nxi);
9040 +}
9041 +
9042 +
9043 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9044 +
9045 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9046 +               const char *_file, int _line)
9047 +{
9048 +       if (nxi) {
9049 +               vxlprintk(VXD_CBIT(nid, 3),
9050 +                       "init_nx_info(%p[#%d.%d])",
9051 +                       nxi, nxi ? nxi->nx_id : 0,
9052 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9053 +                       _file, _line);
9054 +
9055 +               atomic_inc(&nxi->nx_usecnt);
9056 +       }
9057 +       *nxp = nxi;
9058 +}
9059 +
9060 +
9061 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9062 +
9063 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9064 +       const char *_file, int _line)
9065 +{
9066 +       struct nx_info *nxo;
9067 +
9068 +       if (!nxi)
9069 +               return;
9070 +
9071 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9072 +               nxi, nxi ? nxi->nx_id : 0,
9073 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9074 +               _file, _line);
9075 +
9076 +       atomic_inc(&nxi->nx_usecnt);
9077 +       nxo = xchg(nxp, nxi);
9078 +       BUG_ON(nxo);
9079 +}
9080 +
9081 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9082 +
9083 +static inline void __clr_nx_info(struct nx_info **nxp,
9084 +       const char *_file, int _line)
9085 +{
9086 +       struct nx_info *nxo;
9087 +
9088 +       nxo = xchg(nxp, NULL);
9089 +       if (!nxo)
9090 +               return;
9091 +
9092 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9093 +               nxo, nxo ? nxo->nx_id : 0,
9094 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9095 +               _file, _line);
9096 +
9097 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9098 +               free_nx_info(nxo);
9099 +}
9100 +
9101 +
9102 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9103 +
9104 +static inline void __claim_nx_info(struct nx_info *nxi,
9105 +       struct task_struct *task, const char *_file, int _line)
9106 +{
9107 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9108 +               nxi, nxi ? nxi->nx_id : 0,
9109 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9110 +               nxi?atomic_read(&nxi->nx_tasks):0,
9111 +               task, _file, _line);
9112 +
9113 +       atomic_inc(&nxi->nx_tasks);
9114 +}
9115 +
9116 +
9117 +extern void unhash_nx_info(struct nx_info *);
9118 +
9119 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9120 +
9121 +static inline void __release_nx_info(struct nx_info *nxi,
9122 +       struct task_struct *task, const char *_file, int _line)
9123 +{
9124 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9125 +               nxi, nxi ? nxi->nx_id : 0,
9126 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9127 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9128 +               task, _file, _line);
9129 +
9130 +       might_sleep();
9131 +
9132 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9133 +               unhash_nx_info(nxi);
9134 +}
9135 +
9136 +
9137 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9138 +
9139 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9140 +       const char *_file, int _line)
9141 +{
9142 +       struct nx_info *nxi;
9143 +
9144 +       task_lock(p);
9145 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9146 +               p, _file, _line);
9147 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9148 +       task_unlock(p);
9149 +       return nxi;
9150 +}
9151 +
9152 +
9153 +static inline void exit_nx_info(struct task_struct *p)
9154 +{
9155 +       if (p->nx_info)
9156 +               release_nx_info(p->nx_info, p);
9157 +}
9158 +
9159 +
9160 +#else
9161 +#warning duplicate inclusion
9162 +#endif
9163 diff -NurpP --minimal linux-3.13.10/include/linux/vs_pid.h linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h
9164 --- linux-3.13.10/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9165 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h     2014-01-31 20:38:03.000000000 +0000
9166 @@ -0,0 +1,50 @@
9167 +#ifndef _VS_PID_H
9168 +#define _VS_PID_H
9169 +
9170 +#include "vserver/base.h"
9171 +#include "vserver/check.h"
9172 +#include "vserver/context.h"
9173 +#include "vserver/debug.h"
9174 +#include "vserver/pid.h"
9175 +#include <linux/pid_namespace.h>
9176 +
9177 +
9178 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9179 +
9180 +static inline
9181 +int vx_proc_task_visible(struct task_struct *task)
9182 +{
9183 +       if ((task->pid == 1) &&
9184 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9185 +               /* show a blend through init */
9186 +               goto visible;
9187 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9188 +               goto visible;
9189 +       return 0;
9190 +visible:
9191 +       return 1;
9192 +}
9193 +
9194 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9195 +
9196 +
9197 +static inline
9198 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9199 +{
9200 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9201 +
9202 +       if (task && !vx_proc_task_visible(task)) {
9203 +               vxdprintk(VXD_CBIT(misc, 6),
9204 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9205 +                       task, task->xid, task->pid,
9206 +                       current, current->xid, current->pid);
9207 +               put_task_struct(task);
9208 +               task = NULL;
9209 +       }
9210 +       return task;
9211 +}
9212 +
9213 +
9214 +#else
9215 +#warning duplicate inclusion
9216 +#endif
9217 diff -NurpP --minimal linux-3.13.10/include/linux/vs_sched.h linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h
9218 --- linux-3.13.10/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9219 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h   2014-01-31 20:38:03.000000000 +0000
9220 @@ -0,0 +1,40 @@
9221 +#ifndef _VS_SCHED_H
9222 +#define _VS_SCHED_H
9223 +
9224 +#include "vserver/base.h"
9225 +#include "vserver/context.h"
9226 +#include "vserver/sched.h"
9227 +
9228 +
9229 +#define MAX_PRIO_BIAS           20
9230 +#define MIN_PRIO_BIAS          -20
9231 +
9232 +static inline
9233 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9234 +{
9235 +       struct vx_info *vxi = p->vx_info;
9236 +
9237 +       if (vxi)
9238 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9239 +       return prio;
9240 +}
9241 +
9242 +static inline void vx_account_user(struct vx_info *vxi,
9243 +       cputime_t cputime, int nice)
9244 +{
9245 +       if (!vxi)
9246 +               return;
9247 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9248 +}
9249 +
9250 +static inline void vx_account_system(struct vx_info *vxi,
9251 +       cputime_t cputime, int idle)
9252 +{
9253 +       if (!vxi)
9254 +               return;
9255 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9256 +}
9257 +
9258 +#else
9259 +#warning duplicate inclusion
9260 +#endif
9261 diff -NurpP --minimal linux-3.13.10/include/linux/vs_socket.h linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h
9262 --- linux-3.13.10/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9263 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h  2014-01-31 20:38:03.000000000 +0000
9264 @@ -0,0 +1,67 @@
9265 +#ifndef _VS_SOCKET_H
9266 +#define _VS_SOCKET_H
9267 +
9268 +#include "vserver/debug.h"
9269 +#include "vserver/base.h"
9270 +#include "vserver/cacct.h"
9271 +#include "vserver/context.h"
9272 +#include "vserver/tag.h"
9273 +
9274 +
9275 +/* socket accounting */
9276 +
9277 +#include <linux/socket.h>
9278 +
9279 +static inline int vx_sock_type(int family)
9280 +{
9281 +       switch (family) {
9282 +       case PF_UNSPEC:
9283 +               return VXA_SOCK_UNSPEC;
9284 +       case PF_UNIX:
9285 +               return VXA_SOCK_UNIX;
9286 +       case PF_INET:
9287 +               return VXA_SOCK_INET;
9288 +       case PF_INET6:
9289 +               return VXA_SOCK_INET6;
9290 +       case PF_PACKET:
9291 +               return VXA_SOCK_PACKET;
9292 +       default:
9293 +               return VXA_SOCK_OTHER;
9294 +       }
9295 +}
9296 +
9297 +#define vx_acc_sock(v, f, p, s) \
9298 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9299 +
9300 +static inline void __vx_acc_sock(struct vx_info *vxi,
9301 +       int family, int pos, int size, char *file, int line)
9302 +{
9303 +       if (vxi) {
9304 +               int type = vx_sock_type(family);
9305 +
9306 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9307 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9308 +       }
9309 +}
9310 +
9311 +#define vx_sock_recv(sk, s) \
9312 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9313 +#define vx_sock_send(sk, s) \
9314 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9315 +#define vx_sock_fail(sk, s) \
9316 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9317 +
9318 +
9319 +#define sock_vx_init(s) do {           \
9320 +       (s)->sk_xid = 0;                \
9321 +       (s)->sk_vx_info = NULL;         \
9322 +       } while (0)
9323 +
9324 +#define sock_nx_init(s) do {           \
9325 +       (s)->sk_nid = 0;                \
9326 +       (s)->sk_nx_info = NULL;         \
9327 +       } while (0)
9328 +
9329 +#else
9330 +#warning duplicate inclusion
9331 +#endif
9332 diff -NurpP --minimal linux-3.13.10/include/linux/vs_tag.h linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h
9333 --- linux-3.13.10/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9334 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h     2014-01-31 20:38:03.000000000 +0000
9335 @@ -0,0 +1,47 @@
9336 +#ifndef _VS_TAG_H
9337 +#define _VS_TAG_H
9338 +
9339 +#include <linux/vserver/tag.h>
9340 +
9341 +/* check conditions */
9342 +
9343 +#define DX_ADMIN       0x0001
9344 +#define DX_WATCH       0x0002
9345 +#define DX_HOSTID      0x0008
9346 +
9347 +#define DX_IDENT       0x0010
9348 +
9349 +#define DX_ARG_MASK    0x0010
9350 +
9351 +
9352 +#define dx_task_tag(t) ((t)->tag)
9353 +
9354 +#define dx_current_tag() dx_task_tag(current)
9355 +
9356 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9357 +
9358 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9359 +
9360 +
9361 +/*
9362 + * check current context for ADMIN/WATCH and
9363 + * optionally against supplied argument
9364 + */
9365 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9366 +{
9367 +       if (mode & DX_ARG_MASK) {
9368 +               if ((mode & DX_IDENT) && (id == cid))
9369 +                       return 1;
9370 +       }
9371 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9372 +               ((mode & DX_WATCH) && (cid == 1)) ||
9373 +               ((mode & DX_HOSTID) && (id == 0)));
9374 +}
9375 +
9376 +struct inode;
9377 +int dx_permission(const struct inode *inode, int mask);
9378 +
9379 +
9380 +#else
9381 +#warning duplicate inclusion
9382 +#endif
9383 diff -NurpP --minimal linux-3.13.10/include/linux/vs_time.h linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h
9384 --- linux-3.13.10/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9385 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h    2014-01-31 20:38:03.000000000 +0000
9386 @@ -0,0 +1,19 @@
9387 +#ifndef _VS_TIME_H
9388 +#define _VS_TIME_H
9389 +
9390 +
9391 +/* time faking stuff */
9392 +
9393 +#ifdef CONFIG_VSERVER_VTIME
9394 +
9395 +extern void vx_adjust_timespec(struct timespec *ts);
9396 +extern int vx_settimeofday(const struct timespec *ts);
9397 +
9398 +#else
9399 +#define        vx_adjust_timespec(t)   do { } while (0)
9400 +#define        vx_settimeofday(t)      do_settimeofday(t)
9401 +#endif
9402 +
9403 +#else
9404 +#warning duplicate inclusion
9405 +#endif
9406 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/base.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h
9407 --- linux-3.13.10/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9408 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h       2014-01-31 20:38:03.000000000 +0000
9409 @@ -0,0 +1,184 @@
9410 +#ifndef _VSERVER_BASE_H
9411 +#define _VSERVER_BASE_H
9412 +
9413 +
9414 +/* context state changes */
9415 +
9416 +enum {
9417 +       VSC_STARTUP = 1,
9418 +       VSC_SHUTDOWN,
9419 +
9420 +       VSC_NETUP,
9421 +       VSC_NETDOWN,
9422 +};
9423 +
9424 +
9425 +
9426 +#define vx_task_xid(t) ((t)->xid)
9427 +
9428 +#define vx_current_xid() vx_task_xid(current)
9429 +
9430 +#define current_vx_info() (current->vx_info)
9431 +
9432 +
9433 +#define nx_task_nid(t) ((t)->nid)
9434 +
9435 +#define nx_current_nid() nx_task_nid(current)
9436 +
9437 +#define current_nx_info() (current->nx_info)
9438 +
9439 +
9440 +/* generic flag merging */
9441 +
9442 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9443 +
9444 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9445 +
9446 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9447 +
9448 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9449 +
9450 +
9451 +/* context flags */
9452 +
9453 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9454 +
9455 +#define vx_current_flags()     __vx_flags(current_vx_info())
9456 +
9457 +#define vx_info_flags(v, m, f) \
9458 +       vs_check_flags(__vx_flags(v), m, f)
9459 +
9460 +#define task_vx_flags(t, m, f) \
9461 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9462 +
9463 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9464 +
9465 +
9466 +/* context caps */
9467 +
9468 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9469 +
9470 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9471 +
9472 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9473 +
9474 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9475 +
9476 +
9477 +
9478 +/* network flags */
9479 +
9480 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9481 +
9482 +#define nx_current_flags()     __nx_flags(current_nx_info())
9483 +
9484 +#define nx_info_flags(n, m, f) \
9485 +       vs_check_flags(__nx_flags(n), m, f)
9486 +
9487 +#define task_nx_flags(t, m, f) \
9488 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9489 +
9490 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9491 +
9492 +
9493 +/* network caps */
9494 +
9495 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9496 +
9497 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9498 +
9499 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9500 +
9501 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9502 +
9503 +
9504 +/* context mask capabilities */
9505 +
9506 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9507 +
9508 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9509 +
9510 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9511 +
9512 +
9513 +/* context bcap mask */
9514 +
9515 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9516 +
9517 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9518 +
9519 +
9520 +/* mask given bcaps */
9521 +
9522 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9523 +
9524 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9525 +
9526 +
9527 +/* masked cap_bset */
9528 +
9529 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9530 +
9531 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9532 +
9533 +#if 0
9534 +#define vx_info_mbcap(v, b) \
9535 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9536 +       vx_info_bcaps(v, b) : (b))
9537 +
9538 +#define task_vx_mbcap(t, b) \
9539 +       vx_info_mbcap((t)->vx_info, (t)->b)
9540 +
9541 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9542 +#endif
9543 +
9544 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9545 +
9546 +#define vx_capable(b, c) (capable(b) || \
9547 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9548 +
9549 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9550 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9551 +
9552 +#define nx_capable(b, c) (capable(b) || \
9553 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9554 +
9555 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9556 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9557 +
9558 +#define vx_task_initpid(t, n) \
9559 +       ((t)->vx_info && \
9560 +       ((t)->vx_info->vx_initpid == (n)))
9561 +
9562 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9563 +
9564 +
9565 +/* context unshare mask */
9566 +
9567 +#define __vx_umask(v)          ((v)->vx_umask)
9568 +
9569 +#define vx_current_umask()     __vx_umask(current_vx_info())
9570 +
9571 +#define vx_can_unshare(b, f) (capable(b) || \
9572 +       (cap_raised(current_cap(), b) && \
9573 +       !((f) & ~vx_current_umask())))
9574 +
9575 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9576 +       (cap_raised(current_cap(), b) && \
9577 +       !((f) & ~vx_current_umask())))
9578 +
9579 +#define __vx_wmask(v)          ((v)->vx_wmask)
9580 +
9581 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9582 +
9583 +
9584 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9585 +
9586 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9587 +
9588 +
9589 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9590 +
9591 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9592 +
9593 +#endif
9594 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h
9595 --- linux-3.13.10/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9596 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h      2014-01-31 20:38:03.000000000 +0000
9597 @@ -0,0 +1,15 @@
9598 +#ifndef _VSERVER_CACCT_H
9599 +#define _VSERVER_CACCT_H
9600 +
9601 +
9602 +enum sock_acc_field {
9603 +       VXA_SOCK_UNSPEC = 0,
9604 +       VXA_SOCK_UNIX,
9605 +       VXA_SOCK_INET,
9606 +       VXA_SOCK_INET6,
9607 +       VXA_SOCK_PACKET,
9608 +       VXA_SOCK_OTHER,
9609 +       VXA_SOCK_SIZE   /* array size */
9610 +};
9611 +
9612 +#endif /* _VSERVER_CACCT_H */
9613 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h
9614 --- linux-3.13.10/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9615 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h  2014-01-31 20:38:03.000000000 +0000
9616 @@ -0,0 +1,10 @@
9617 +#ifndef _VSERVER_CACCT_CMD_H
9618 +#define _VSERVER_CACCT_CMD_H
9619 +
9620 +
9621 +#include <linux/compiler.h>
9622 +#include <uapi/vserver/cacct_cmd.h>
9623 +
9624 +extern int vc_sock_stat(struct vx_info *, void __user *);
9625 +
9626 +#endif /* _VSERVER_CACCT_CMD_H */
9627 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h
9628 --- linux-3.13.10/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9629 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h  2014-01-31 20:38:03.000000000 +0000
9630 @@ -0,0 +1,43 @@
9631 +#ifndef _VSERVER_CACCT_DEF_H
9632 +#define _VSERVER_CACCT_DEF_H
9633 +
9634 +#include <asm/atomic.h>
9635 +#include <linux/vserver/cacct.h>
9636 +
9637 +
9638 +struct _vx_sock_acc {
9639 +       atomic_long_t count;
9640 +       atomic_long_t total;
9641 +};
9642 +
9643 +/* context sub struct */
9644 +
9645 +struct _vx_cacct {
9646 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9647 +       atomic_t slab[8];
9648 +       atomic_t page[6][8];
9649 +};
9650 +
9651 +#ifdef CONFIG_VSERVER_DEBUG
9652 +
9653 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9654 +{
9655 +       int i, j;
9656 +
9657 +       printk("\t_vx_cacct:");
9658 +       for (i = 0; i < 6; i++) {
9659 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9660 +
9661 +               printk("\t [%d] =", i);
9662 +               for (j = 0; j < 3; j++) {
9663 +                       printk(" [%d] = %8lu, %8lu", j,
9664 +                               atomic_long_read(&ptr[j].count),
9665 +                               atomic_long_read(&ptr[j].total));
9666 +               }
9667 +               printk("\n");
9668 +       }
9669 +}
9670 +
9671 +#endif
9672 +
9673 +#endif /* _VSERVER_CACCT_DEF_H */
9674 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h
9675 --- linux-3.13.10/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9676 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h  2014-01-31 20:38:03.000000000 +0000
9677 @@ -0,0 +1,17 @@
9678 +#ifndef _VSERVER_CACCT_INT_H
9679 +#define _VSERVER_CACCT_INT_H
9680 +
9681 +static inline
9682 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9683 +{
9684 +       return atomic_long_read(&cacct->sock[type][pos].count);
9685 +}
9686 +
9687 +
9688 +static inline
9689 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9690 +{
9691 +       return atomic_long_read(&cacct->sock[type][pos].total);
9692 +}
9693 +
9694 +#endif /* _VSERVER_CACCT_INT_H */
9695 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/check.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h
9696 --- linux-3.13.10/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9697 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h      2014-01-31 20:38:03.000000000 +0000
9698 @@ -0,0 +1,89 @@
9699 +#ifndef _VSERVER_CHECK_H
9700 +#define _VSERVER_CHECK_H
9701 +
9702 +
9703 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9704 +
9705 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9706 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9707 +#else
9708 +#define MIN_D_CONTEXT  65536
9709 +#endif
9710 +
9711 +/* check conditions */
9712 +
9713 +#define VS_ADMIN       0x0001
9714 +#define VS_WATCH       0x0002
9715 +#define VS_HIDE                0x0004
9716 +#define VS_HOSTID      0x0008
9717 +
9718 +#define VS_IDENT       0x0010
9719 +#define VS_EQUIV       0x0020
9720 +#define VS_PARENT      0x0040
9721 +#define VS_CHILD       0x0080
9722 +
9723 +#define VS_ARG_MASK    0x00F0
9724 +
9725 +#define VS_DYNAMIC     0x0100
9726 +#define VS_STATIC      0x0200
9727 +
9728 +#define VS_ATR_MASK    0x0F00
9729 +
9730 +#ifdef CONFIG_VSERVER_PRIVACY
9731 +#define VS_ADMIN_P     (0)
9732 +#define VS_WATCH_P     (0)
9733 +#else
9734 +#define VS_ADMIN_P     VS_ADMIN
9735 +#define VS_WATCH_P     VS_WATCH
9736 +#endif
9737 +
9738 +#define VS_HARDIRQ     0x1000
9739 +#define VS_SOFTIRQ     0x2000
9740 +#define VS_IRQ         0x4000
9741 +
9742 +#define VS_IRQ_MASK    0xF000
9743 +
9744 +#include <linux/hardirq.h>
9745 +
9746 +/*
9747 + * check current context for ADMIN/WATCH and
9748 + * optionally against supplied argument
9749 + */
9750 +static inline int __vs_check(int cid, int id, unsigned int mode)
9751 +{
9752 +       if (mode & VS_ARG_MASK) {
9753 +               if ((mode & VS_IDENT) && (id == cid))
9754 +                       return 1;
9755 +       }
9756 +       if (mode & VS_ATR_MASK) {
9757 +               if ((mode & VS_DYNAMIC) &&
9758 +                       (id >= MIN_D_CONTEXT) &&
9759 +                       (id <= MAX_S_CONTEXT))
9760 +                       return 1;
9761 +               if ((mode & VS_STATIC) &&
9762 +                       (id > 1) && (id < MIN_D_CONTEXT))
9763 +                       return 1;
9764 +       }
9765 +       if (mode & VS_IRQ_MASK) {
9766 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9767 +                       return 1;
9768 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9769 +                       return 1;
9770 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9771 +                       return 1;
9772 +       }
9773 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9774 +               ((mode & VS_WATCH) && (cid == 1)) ||
9775 +               ((mode & VS_HOSTID) && (id == 0)));
9776 +}
9777 +
9778 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9779 +
9780 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9781 +
9782 +
9783 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9784 +
9785 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9786 +
9787 +#endif
9788 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h
9789 --- linux-3.13.10/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9790 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h    2014-01-31 20:38:03.000000000 +0000
9791 @@ -0,0 +1,110 @@
9792 +#ifndef _VSERVER_CONTEXT_H
9793 +#define _VSERVER_CONTEXT_H
9794 +
9795 +
9796 +#include <linux/list.h>
9797 +#include <linux/spinlock.h>
9798 +#include <linux/rcupdate.h>
9799 +#include <uapi/vserver/context.h>
9800 +
9801 +#include "limit_def.h"
9802 +#include "sched_def.h"
9803 +#include "cvirt_def.h"
9804 +#include "cacct_def.h"
9805 +#include "device_def.h"
9806 +
9807 +#define VX_SPACES      2
9808 +
9809 +struct _vx_info_pc {
9810 +       struct _vx_sched_pc sched_pc;
9811 +       struct _vx_cvirt_pc cvirt_pc;
9812 +};
9813 +
9814 +struct _vx_space {
9815 +       unsigned long vx_nsmask;                /* assignment mask */
9816 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9817 +       struct fs_struct *vx_fs;                /* private namespace fs */
9818 +       const struct cred *vx_cred;             /* task credentials */
9819 +};
9820 +
9821 +struct vx_info {
9822 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9823 +       vxid_t vx_id;                           /* context id */
9824 +       atomic_t vx_usecnt;                     /* usage count */
9825 +       atomic_t vx_tasks;                      /* tasks count */
9826 +       struct vx_info *vx_parent;              /* parent context */
9827 +       int vx_state;                           /* context state */
9828 +
9829 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9830 +
9831 +       uint64_t vx_flags;                      /* context flags */
9832 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9833 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9834 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9835 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9836 +
9837 +       struct task_struct *vx_reaper;          /* guest reaper process */
9838 +       pid_t vx_initpid;                       /* PID of guest init */
9839 +       int64_t vx_badness_bias;                /* OOM points bias */
9840 +
9841 +       struct _vx_limit limit;                 /* vserver limits */
9842 +       struct _vx_sched sched;                 /* vserver scheduler */
9843 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9844 +       struct _vx_cacct cacct;                 /* context accounting */
9845 +
9846 +       struct _vx_device dmap;                 /* default device map targets */
9847 +
9848 +#ifndef CONFIG_SMP
9849 +       struct _vx_info_pc info_pc;             /* per cpu data */
9850 +#else
9851 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9852 +#endif
9853 +
9854 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9855 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9856 +       int exit_code;                          /* last process exit code */
9857 +
9858 +       char vx_name[65];                       /* vserver name */
9859 +};
9860 +
9861 +#ifndef CONFIG_SMP
9862 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9863 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9864 +#else
9865 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9866 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9867 +#endif
9868 +
9869 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9870 +
9871 +
9872 +struct vx_info_save {
9873 +       struct vx_info *vxi;
9874 +       vxid_t xid;
9875 +};
9876 +
9877 +
9878 +/* status flags */
9879 +
9880 +#define VXS_HASHED     0x0001
9881 +#define VXS_PAUSED     0x0010
9882 +#define VXS_SHUTDOWN   0x0100
9883 +#define VXS_HELPER     0x1000
9884 +#define VXS_RELEASED   0x8000
9885 +
9886 +
9887 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9888 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9889 +
9890 +extern struct vx_info *lookup_vx_info(int);
9891 +extern struct vx_info *lookup_or_create_vx_info(int);
9892 +
9893 +extern int get_xid_list(int, unsigned int *, int);
9894 +extern int xid_is_hashed(vxid_t);
9895 +
9896 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9897 +
9898 +extern long vs_state_change(struct vx_info *, unsigned int);
9899 +
9900 +
9901 +#endif /* _VSERVER_CONTEXT_H */
9902 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h
9903 --- linux-3.13.10/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9904 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h        2014-01-31 20:38:03.000000000 +0000
9905 @@ -0,0 +1,33 @@
9906 +#ifndef _VSERVER_CONTEXT_CMD_H
9907 +#define _VSERVER_CONTEXT_CMD_H
9908 +
9909 +#include <uapi/vserver/context_cmd.h>
9910 +
9911 +extern int vc_task_xid(uint32_t);
9912 +
9913 +extern int vc_vx_info(struct vx_info *, void __user *);
9914 +
9915 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9916 +
9917 +extern int vc_ctx_create(uint32_t, void __user *);
9918 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9919 +
9920 +extern int vc_get_cflags(struct vx_info *, void __user *);
9921 +extern int vc_set_cflags(struct vx_info *, void __user *);
9922 +
9923 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9924 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9925 +
9926 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9927 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9928 +
9929 +extern int vc_get_umask(struct vx_info *, void __user *);
9930 +extern int vc_set_umask(struct vx_info *, void __user *);
9931 +
9932 +extern int vc_get_wmask(struct vx_info *, void __user *);
9933 +extern int vc_set_wmask(struct vx_info *, void __user *);
9934 +
9935 +extern int vc_get_badness(struct vx_info *, void __user *);
9936 +extern int vc_set_badness(struct vx_info *, void __user *);
9937 +
9938 +#endif /* _VSERVER_CONTEXT_CMD_H */
9939 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h
9940 --- linux-3.13.10/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9941 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h      2014-01-31 20:38:03.000000000 +0000
9942 @@ -0,0 +1,18 @@
9943 +#ifndef _VSERVER_CVIRT_H
9944 +#define _VSERVER_CVIRT_H
9945 +
9946 +struct timespec;
9947 +
9948 +void vx_vsi_boottime(struct timespec *);
9949 +
9950 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9951 +
9952 +
9953 +struct vx_info;
9954 +
9955 +void vx_update_load(struct vx_info *);
9956 +
9957 +
9958 +int vx_do_syslog(int, char __user *, int);
9959 +
9960 +#endif /* _VSERVER_CVIRT_H */
9961 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h
9962 --- linux-3.13.10/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
9963 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h  2014-01-31 20:38:03.000000000 +0000
9964 @@ -0,0 +1,13 @@
9965 +#ifndef _VSERVER_CVIRT_CMD_H
9966 +#define _VSERVER_CVIRT_CMD_H
9967 +
9968 +
9969 +#include <linux/compiler.h>
9970 +#include <uapi/vserver/cvirt_cmd.h>
9971 +
9972 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9973 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9974 +
9975 +extern int vc_virt_stat(struct vx_info *, void __user *);
9976 +
9977 +#endif /* _VSERVER_CVIRT_CMD_H */
9978 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h
9979 --- linux-3.13.10/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
9980 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h  2014-01-31 20:38:03.000000000 +0000
9981 @@ -0,0 +1,80 @@
9982 +#ifndef _VSERVER_CVIRT_DEF_H
9983 +#define _VSERVER_CVIRT_DEF_H
9984 +
9985 +#include <linux/jiffies.h>
9986 +#include <linux/spinlock.h>
9987 +#include <linux/wait.h>
9988 +#include <linux/time.h>
9989 +#include <asm/atomic.h>
9990 +
9991 +
9992 +struct _vx_usage_stat {
9993 +       uint64_t user;
9994 +       uint64_t nice;
9995 +       uint64_t system;
9996 +       uint64_t softirq;
9997 +       uint64_t irq;
9998 +       uint64_t idle;
9999 +       uint64_t iowait;
10000 +};
10001 +
10002 +struct _vx_syslog {
10003 +       wait_queue_head_t log_wait;
10004 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10005 +
10006 +       unsigned long log_start;        /* next char to be read by syslog() */
10007 +       unsigned long con_start;        /* next char to be sent to consoles */
10008 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10009 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10010 +
10011 +       char log_buf[1024];
10012 +};
10013 +
10014 +
10015 +/* context sub struct */
10016 +
10017 +struct _vx_cvirt {
10018 +       atomic_t nr_threads;            /* number of current threads */
10019 +       atomic_t nr_running;            /* number of running threads */
10020 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10021 +
10022 +       atomic_t nr_onhold;             /* processes on hold */
10023 +       uint32_t onhold_last;           /* jiffies when put on hold */
10024 +
10025 +       struct timespec bias_ts;        /* time offset to the host */
10026 +       struct timespec bias_idle;
10027 +       struct timespec bias_uptime;    /* context creation point */
10028 +       uint64_t bias_clock;            /* offset in clock_t */
10029 +
10030 +       spinlock_t load_lock;           /* lock for the load averages */
10031 +       atomic_t load_updates;          /* nr of load updates done so far */
10032 +       uint32_t load_last;             /* last time load was calculated */
10033 +       uint32_t load[3];               /* load averages 1,5,15 */
10034 +
10035 +       atomic_t total_forks;           /* number of forks so far */
10036 +
10037 +       struct _vx_syslog syslog;
10038 +};
10039 +
10040 +struct _vx_cvirt_pc {
10041 +       struct _vx_usage_stat cpustat;
10042 +};
10043 +
10044 +
10045 +#ifdef CONFIG_VSERVER_DEBUG
10046 +
10047 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10048 +{
10049 +       printk("\t_vx_cvirt:\n");
10050 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10051 +               atomic_read(&cvirt->nr_threads),
10052 +               atomic_read(&cvirt->nr_running),
10053 +               atomic_read(&cvirt->nr_uninterruptible),
10054 +               atomic_read(&cvirt->nr_onhold));
10055 +       /* add rest here */
10056 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10057 +}
10058 +
10059 +#endif
10060 +
10061 +#endif /* _VSERVER_CVIRT_DEF_H */
10062 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h
10063 --- linux-3.13.10/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10064 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h      2014-01-31 20:38:03.000000000 +0000
10065 @@ -0,0 +1,146 @@
10066 +#ifndef _VSERVER_DEBUG_H
10067 +#define _VSERVER_DEBUG_H
10068 +
10069 +
10070 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10071 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10072 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10073 +
10074 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10075 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10076 +#define VXF_DEV                "%p[%lu,%d:%d]"
10077 +
10078 +#if    defined(CONFIG_QUOTES_UTF8)
10079 +#define        VS_Q_LQM        "\xc2\xbb"
10080 +#define        VS_Q_RQM        "\xc2\xab"
10081 +#elif  defined(CONFIG_QUOTES_ASCII)
10082 +#define        VS_Q_LQM        "\x27"
10083 +#define        VS_Q_RQM        "\x27"
10084 +#else
10085 +#define        VS_Q_LQM        "\xbb"
10086 +#define        VS_Q_RQM        "\xab"
10087 +#endif
10088 +
10089 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10090 +
10091 +
10092 +#define vxd_path(p)                                            \
10093 +       ({ static char _buffer[PATH_MAX];                       \
10094 +          d_path(p, _buffer, sizeof(_buffer)); })
10095 +
10096 +#define vxd_cond_path(n)                                       \
10097 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10098 +
10099 +
10100 +#ifdef CONFIG_VSERVER_DEBUG
10101 +
10102 +extern unsigned int vs_debug_switch;
10103 +extern unsigned int vs_debug_xid;
10104 +extern unsigned int vs_debug_nid;
10105 +extern unsigned int vs_debug_tag;
10106 +extern unsigned int vs_debug_net;
10107 +extern unsigned int vs_debug_limit;
10108 +extern unsigned int vs_debug_cres;
10109 +extern unsigned int vs_debug_dlim;
10110 +extern unsigned int vs_debug_quota;
10111 +extern unsigned int vs_debug_cvirt;
10112 +extern unsigned int vs_debug_space;
10113 +extern unsigned int vs_debug_perm;
10114 +extern unsigned int vs_debug_misc;
10115 +
10116 +
10117 +#define VX_LOGLEVEL    "vxD: "
10118 +#define VX_PROC_FMT    "%p: "
10119 +#define VX_PROCESS     current
10120 +
10121 +#define vxdprintk(c, f, x...)                                  \
10122 +       do {                                                    \
10123 +               if (c)                                          \
10124 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10125 +                               VX_PROCESS , ##x);              \
10126 +       } while (0)
10127 +
10128 +#define vxlprintk(c, f, x...)                                  \
10129 +       do {                                                    \
10130 +               if (c)                                          \
10131 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10132 +       } while (0)
10133 +
10134 +#define vxfprintk(c, f, x...)                                  \
10135 +       do {                                                    \
10136 +               if (c)                                          \
10137 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10138 +       } while (0)
10139 +
10140 +
10141 +struct vx_info;
10142 +
10143 +void dump_vx_info(struct vx_info *, int);
10144 +void dump_vx_info_inactive(int);
10145 +
10146 +#else  /* CONFIG_VSERVER_DEBUG */
10147 +
10148 +#define vs_debug_switch        0
10149 +#define vs_debug_xid   0
10150 +#define vs_debug_nid   0
10151 +#define vs_debug_tag   0
10152 +#define vs_debug_net   0
10153 +#define vs_debug_limit 0
10154 +#define vs_debug_cres  0
10155 +#define vs_debug_dlim  0
10156 +#define vs_debug_quota 0
10157 +#define vs_debug_cvirt 0
10158 +#define vs_debug_space 0
10159 +#define vs_debug_perm  0
10160 +#define vs_debug_misc  0
10161 +
10162 +#define vxdprintk(x...) do { } while (0)
10163 +#define vxlprintk(x...) do { } while (0)
10164 +#define vxfprintk(x...) do { } while (0)
10165 +
10166 +#endif /* CONFIG_VSERVER_DEBUG */
10167 +
10168 +
10169 +#ifdef CONFIG_VSERVER_WARN
10170 +
10171 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10172 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10173 +#define VX_WARN_XID    "[xid #%u] "
10174 +#define VX_WARN_NID    "[nid #%u] "
10175 +#define VX_WARN_TAG    "[tag #%u] "
10176 +
10177 +#define vxwprintk(c, f, x...)                                  \
10178 +       do {                                                    \
10179 +               if (c)                                          \
10180 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10181 +       } while (0)
10182 +
10183 +#else  /* CONFIG_VSERVER_WARN */
10184 +
10185 +#define vxwprintk(x...) do { } while (0)
10186 +
10187 +#endif /* CONFIG_VSERVER_WARN */
10188 +
10189 +#define vxwprintk_task(c, f, x...)                             \
10190 +       vxwprintk(c, VX_WARN_TASK f,                            \
10191 +               current->comm, current->pid,                    \
10192 +               current->xid, current->nid,                     \
10193 +               current->tag, ##x)
10194 +#define vxwprintk_xid(c, f, x...)                              \
10195 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10196 +#define vxwprintk_nid(c, f, x...)                              \
10197 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10198 +#define vxwprintk_tag(c, f, x...)                              \
10199 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10200 +
10201 +#ifdef CONFIG_VSERVER_DEBUG
10202 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10203 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10204 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10205 +#else
10206 +#define vxd_assert_lock(l)     do { } while (0)
10207 +#define vxd_assert(c, f, x...) do { } while (0)
10208 +#endif
10209 +
10210 +
10211 +#endif /* _VSERVER_DEBUG_H */
10212 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h
10213 --- linux-3.13.10/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10214 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h  2014-01-31 20:38:03.000000000 +0000
10215 @@ -0,0 +1,37 @@
10216 +#ifndef _VSERVER_DEBUG_CMD_H
10217 +#define _VSERVER_DEBUG_CMD_H
10218 +
10219 +#include <uapi/vserver/debug_cmd.h>
10220 +
10221 +
10222 +#ifdef CONFIG_COMPAT
10223 +
10224 +#include <asm/compat.h>
10225 +
10226 +struct vcmd_read_history_v0_x32 {
10227 +       uint32_t index;
10228 +       uint32_t count;
10229 +       compat_uptr_t data_ptr;
10230 +};
10231 +
10232 +struct vcmd_read_monitor_v0_x32 {
10233 +       uint32_t index;
10234 +       uint32_t count;
10235 +       compat_uptr_t data_ptr;
10236 +};
10237 +
10238 +#endif  /* CONFIG_COMPAT */
10239 +
10240 +extern int vc_dump_history(uint32_t);
10241 +
10242 +extern int vc_read_history(uint32_t, void __user *);
10243 +extern int vc_read_monitor(uint32_t, void __user *);
10244 +
10245 +#ifdef CONFIG_COMPAT
10246 +
10247 +extern int vc_read_history_x32(uint32_t, void __user *);
10248 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10249 +
10250 +#endif  /* CONFIG_COMPAT */
10251 +
10252 +#endif /* _VSERVER_DEBUG_CMD_H */
10253 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h
10254 --- linux-3.13.10/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10255 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h     2014-01-31 20:38:03.000000000 +0000
10256 @@ -0,0 +1,9 @@
10257 +#ifndef _VSERVER_DEVICE_H
10258 +#define _VSERVER_DEVICE_H
10259 +
10260 +
10261 +#include <uapi/vserver/device.h>
10262 +
10263 +#else  /* _VSERVER_DEVICE_H */
10264 +#warning duplicate inclusion
10265 +#endif /* _VSERVER_DEVICE_H */
10266 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h
10267 --- linux-3.13.10/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10268 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10269 @@ -0,0 +1,31 @@
10270 +#ifndef _VSERVER_DEVICE_CMD_H
10271 +#define _VSERVER_DEVICE_CMD_H
10272 +
10273 +#include <uapi/vserver/device_cmd.h>
10274 +
10275 +
10276 +#ifdef CONFIG_COMPAT
10277 +
10278 +#include <asm/compat.h>
10279 +
10280 +struct vcmd_set_mapping_v0_x32 {
10281 +       compat_uptr_t device_ptr;
10282 +       compat_uptr_t target_ptr;
10283 +       uint32_t flags;
10284 +};
10285 +
10286 +#endif /* CONFIG_COMPAT */
10287 +
10288 +#include <linux/compiler.h>
10289 +
10290 +extern int vc_set_mapping(struct vx_info *, void __user *);
10291 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10292 +
10293 +#ifdef CONFIG_COMPAT
10294 +
10295 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10296 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10297 +
10298 +#endif /* CONFIG_COMPAT */
10299 +
10300 +#endif /* _VSERVER_DEVICE_CMD_H */
10301 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h
10302 --- linux-3.13.10/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
10303 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10304 @@ -0,0 +1,17 @@
10305 +#ifndef _VSERVER_DEVICE_DEF_H
10306 +#define _VSERVER_DEVICE_DEF_H
10307 +
10308 +#include <linux/types.h>
10309 +
10310 +struct vx_dmap_target {
10311 +       dev_t target;
10312 +       uint32_t flags;
10313 +};
10314 +
10315 +struct _vx_device {
10316 +#ifdef CONFIG_VSERVER_DEVICE
10317 +       struct vx_dmap_target targets[2];
10318 +#endif
10319 +};
10320 +
10321 +#endif /* _VSERVER_DEVICE_DEF_H */
10322 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h
10323 --- linux-3.13.10/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10324 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h     2014-01-31 20:38:03.000000000 +0000
10325 @@ -0,0 +1,54 @@
10326 +#ifndef _VSERVER_DLIMIT_H
10327 +#define _VSERVER_DLIMIT_H
10328 +
10329 +#include "switch.h"
10330 +
10331 +
10332 +#ifdef __KERNEL__
10333 +
10334 +/*      keep in sync with CDLIM_INFINITY       */
10335 +
10336 +#define DLIM_INFINITY          (~0ULL)
10337 +
10338 +#include <linux/spinlock.h>
10339 +#include <linux/rcupdate.h>
10340 +
10341 +struct super_block;
10342 +
10343 +struct dl_info {
10344 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10345 +       struct rcu_head dl_rcu;                 /* the rcu head */
10346 +       vtag_t dl_tag;                          /* context tag */
10347 +       atomic_t dl_usecnt;                     /* usage count */
10348 +       atomic_t dl_refcnt;                     /* reference count */
10349 +
10350 +       struct super_block *dl_sb;              /* associated superblock */
10351 +
10352 +       spinlock_t dl_lock;                     /* protect the values */
10353 +
10354 +       unsigned long long dl_space_used;       /* used space in bytes */
10355 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10356 +       unsigned long dl_inodes_used;           /* used inodes */
10357 +       unsigned long dl_inodes_total;          /* maximum inodes */
10358 +
10359 +       unsigned int dl_nrlmult;                /* non root limit mult */
10360 +};
10361 +
10362 +struct rcu_head;
10363 +
10364 +extern void rcu_free_dl_info(struct rcu_head *);
10365 +extern void unhash_dl_info(struct dl_info *);
10366 +
10367 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10368 +
10369 +
10370 +struct kstatfs;
10371 +
10372 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10373 +
10374 +typedef uint64_t dlsize_t;
10375 +
10376 +#endif /* __KERNEL__ */
10377 +#else  /* _VSERVER_DLIMIT_H */
10378 +#warning duplicate inclusion
10379 +#endif /* _VSERVER_DLIMIT_H */
10380 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h
10381 --- linux-3.13.10/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10382 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10383 @@ -0,0 +1,46 @@
10384 +#ifndef _VSERVER_DLIMIT_CMD_H
10385 +#define _VSERVER_DLIMIT_CMD_H
10386 +
10387 +#include <uapi/vserver/dlimit_cmd.h>
10388 +
10389 +
10390 +#ifdef CONFIG_COMPAT
10391 +
10392 +#include <asm/compat.h>
10393 +
10394 +struct vcmd_ctx_dlimit_base_v0_x32 {
10395 +       compat_uptr_t name_ptr;
10396 +       uint32_t flags;
10397 +};
10398 +
10399 +struct vcmd_ctx_dlimit_v0_x32 {
10400 +       compat_uptr_t name_ptr;
10401 +       uint32_t space_used;                    /* used space in kbytes */
10402 +       uint32_t space_total;                   /* maximum space in kbytes */
10403 +       uint32_t inodes_used;                   /* used inodes */
10404 +       uint32_t inodes_total;                  /* maximum inodes */
10405 +       uint32_t reserved;                      /* reserved for root in % */
10406 +       uint32_t flags;
10407 +};
10408 +
10409 +#endif /* CONFIG_COMPAT */
10410 +
10411 +#include <linux/compiler.h>
10412 +
10413 +extern int vc_add_dlimit(uint32_t, void __user *);
10414 +extern int vc_rem_dlimit(uint32_t, void __user *);
10415 +
10416 +extern int vc_set_dlimit(uint32_t, void __user *);
10417 +extern int vc_get_dlimit(uint32_t, void __user *);
10418 +
10419 +#ifdef CONFIG_COMPAT
10420 +
10421 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10422 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10423 +
10424 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10425 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10426 +
10427 +#endif /* CONFIG_COMPAT */
10428 +
10429 +#endif /* _VSERVER_DLIMIT_CMD_H */
10430 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/global.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h
10431 --- linux-3.13.10/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10432 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h     2014-01-31 20:38:03.000000000 +0000
10433 @@ -0,0 +1,19 @@
10434 +#ifndef _VSERVER_GLOBAL_H
10435 +#define _VSERVER_GLOBAL_H
10436 +
10437 +
10438 +extern atomic_t vx_global_ctotal;
10439 +extern atomic_t vx_global_cactive;
10440 +
10441 +extern atomic_t nx_global_ctotal;
10442 +extern atomic_t nx_global_cactive;
10443 +
10444 +extern atomic_t vs_global_nsproxy;
10445 +extern atomic_t vs_global_fs;
10446 +extern atomic_t vs_global_mnt_ns;
10447 +extern atomic_t vs_global_uts_ns;
10448 +extern atomic_t vs_global_user_ns;
10449 +extern atomic_t vs_global_pid_ns;
10450 +
10451 +
10452 +#endif /* _VSERVER_GLOBAL_H */
10453 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/history.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h
10454 --- linux-3.13.10/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10455 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h    2014-01-31 20:38:03.000000000 +0000
10456 @@ -0,0 +1,197 @@
10457 +#ifndef _VSERVER_HISTORY_H
10458 +#define _VSERVER_HISTORY_H
10459 +
10460 +
10461 +enum {
10462 +       VXH_UNUSED = 0,
10463 +       VXH_THROW_OOPS = 1,
10464 +
10465 +       VXH_GET_VX_INFO,
10466 +       VXH_PUT_VX_INFO,
10467 +       VXH_INIT_VX_INFO,
10468 +       VXH_SET_VX_INFO,
10469 +       VXH_CLR_VX_INFO,
10470 +       VXH_CLAIM_VX_INFO,
10471 +       VXH_RELEASE_VX_INFO,
10472 +       VXH_ALLOC_VX_INFO,
10473 +       VXH_DEALLOC_VX_INFO,
10474 +       VXH_HASH_VX_INFO,
10475 +       VXH_UNHASH_VX_INFO,
10476 +       VXH_LOC_VX_INFO,
10477 +       VXH_LOOKUP_VX_INFO,
10478 +       VXH_CREATE_VX_INFO,
10479 +};
10480 +
10481 +struct _vxhe_vxi {
10482 +       struct vx_info *ptr;
10483 +       unsigned xid;
10484 +       unsigned usecnt;
10485 +       unsigned tasks;
10486 +};
10487 +
10488 +struct _vxhe_set_clr {
10489 +       void *data;
10490 +};
10491 +
10492 +struct _vxhe_loc_lookup {
10493 +       unsigned arg;
10494 +};
10495 +
10496 +struct _vx_hist_entry {
10497 +       void *loc;
10498 +       unsigned short seq;
10499 +       unsigned short type;
10500 +       struct _vxhe_vxi vxi;
10501 +       union {
10502 +               struct _vxhe_set_clr sc;
10503 +               struct _vxhe_loc_lookup ll;
10504 +       };
10505 +};
10506 +
10507 +#ifdef CONFIG_VSERVER_HISTORY
10508 +
10509 +extern unsigned volatile int vxh_active;
10510 +
10511 +struct _vx_hist_entry *vxh_advance(void *loc);
10512 +
10513 +
10514 +static inline
10515 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10516 +{
10517 +       entry->vxi.ptr = vxi;
10518 +       if (vxi) {
10519 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10520 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10521 +               entry->vxi.xid = vxi->vx_id;
10522 +       }
10523 +}
10524 +
10525 +
10526 +#define        __HERE__ current_text_addr()
10527 +
10528 +#define __VXH_BODY(__type, __data, __here)     \
10529 +       struct _vx_hist_entry *entry;           \
10530 +                                               \
10531 +       preempt_disable();                      \
10532 +       entry = vxh_advance(__here);            \
10533 +       __data;                                 \
10534 +       entry->type = __type;                   \
10535 +       preempt_enable();
10536 +
10537 +
10538 +       /* pass vxi only */
10539 +
10540 +#define __VXH_SMPL                             \
10541 +       __vxh_copy_vxi(entry, vxi)
10542 +
10543 +static inline
10544 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10545 +{
10546 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10547 +}
10548 +
10549 +       /* pass vxi and data (void *) */
10550 +
10551 +#define __VXH_DATA                             \
10552 +       __vxh_copy_vxi(entry, vxi);             \
10553 +       entry->sc.data = data
10554 +
10555 +static inline
10556 +void   __vxh_data(struct vx_info *vxi, void *data,
10557 +                       int __type, void *__here)
10558 +{
10559 +       __VXH_BODY(__type, __VXH_DATA, __here)
10560 +}
10561 +
10562 +       /* pass vxi and arg (long) */
10563 +
10564 +#define __VXH_LONG                             \
10565 +       __vxh_copy_vxi(entry, vxi);             \
10566 +       entry->ll.arg = arg
10567 +
10568 +static inline
10569 +void   __vxh_long(struct vx_info *vxi, long arg,
10570 +                       int __type, void *__here)
10571 +{
10572 +       __VXH_BODY(__type, __VXH_LONG, __here)
10573 +}
10574 +
10575 +
10576 +static inline
10577 +void   __vxh_throw_oops(void *__here)
10578 +{
10579 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10580 +       /* prevent further acquisition */
10581 +       vxh_active = 0;
10582 +}
10583 +
10584 +
10585 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10586 +
10587 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10588 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10589 +
10590 +#define __vxh_init_vx_info(v, d, h) \
10591 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10592 +#define __vxh_set_vx_info(v, d, h) \
10593 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10594 +#define __vxh_clr_vx_info(v, d, h) \
10595 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10596 +
10597 +#define __vxh_claim_vx_info(v, d, h) \
10598 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10599 +#define __vxh_release_vx_info(v, d, h) \
10600 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10601 +
10602 +#define vxh_alloc_vx_info(v) \
10603 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10604 +#define vxh_dealloc_vx_info(v) \
10605 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10606 +
10607 +#define vxh_hash_vx_info(v) \
10608 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10609 +#define vxh_unhash_vx_info(v) \
10610 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10611 +
10612 +#define vxh_loc_vx_info(v, l) \
10613 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10614 +#define vxh_lookup_vx_info(v, l) \
10615 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10616 +#define vxh_create_vx_info(v, l) \
10617 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10618 +
10619 +extern void vxh_dump_history(void);
10620 +
10621 +
10622 +#else  /* CONFIG_VSERVER_HISTORY */
10623 +
10624 +#define        __HERE__        0
10625 +
10626 +#define vxh_throw_oops()               do { } while (0)
10627 +
10628 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10629 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10630 +
10631 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10632 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10633 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10634 +
10635 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10636 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10637 +
10638 +#define vxh_alloc_vx_info(v)           do { } while (0)
10639 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10640 +
10641 +#define vxh_hash_vx_info(v)            do { } while (0)
10642 +#define vxh_unhash_vx_info(v)          do { } while (0)
10643 +
10644 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10645 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10646 +#define vxh_create_vx_info(v, l)       do { } while (0)
10647 +
10648 +#define vxh_dump_history()             do { } while (0)
10649 +
10650 +
10651 +#endif /* CONFIG_VSERVER_HISTORY */
10652 +
10653 +#endif /* _VSERVER_HISTORY_H */
10654 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h
10655 --- linux-3.13.10/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10656 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h      2014-01-31 20:38:03.000000000 +0000
10657 @@ -0,0 +1,19 @@
10658 +#ifndef _VSERVER_INODE_H
10659 +#define _VSERVER_INODE_H
10660 +
10661 +#include <uapi/vserver/inode.h>
10662 +
10663 +
10664 +#ifdef CONFIG_VSERVER_PROC_SECURE
10665 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10666 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10667 +#else
10668 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10669 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10670 +#endif
10671 +
10672 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10673 +
10674 +#else  /* _VSERVER_INODE_H */
10675 +#warning duplicate inclusion
10676 +#endif /* _VSERVER_INODE_H */
10677 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h
10678 --- linux-3.13.10/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10679 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h  2014-01-31 20:38:03.000000000 +0000
10680 @@ -0,0 +1,36 @@
10681 +#ifndef _VSERVER_INODE_CMD_H
10682 +#define _VSERVER_INODE_CMD_H
10683 +
10684 +#include <uapi/vserver/inode_cmd.h>
10685 +
10686 +
10687 +
10688 +#ifdef CONFIG_COMPAT
10689 +
10690 +#include <asm/compat.h>
10691 +
10692 +struct vcmd_ctx_iattr_v1_x32 {
10693 +       compat_uptr_t name_ptr;
10694 +       uint32_t tag;
10695 +       uint32_t flags;
10696 +       uint32_t mask;
10697 +};
10698 +
10699 +#endif /* CONFIG_COMPAT */
10700 +
10701 +#include <linux/compiler.h>
10702 +
10703 +extern int vc_get_iattr(void __user *);
10704 +extern int vc_set_iattr(void __user *);
10705 +
10706 +extern int vc_fget_iattr(uint32_t, void __user *);
10707 +extern int vc_fset_iattr(uint32_t, void __user *);
10708 +
10709 +#ifdef CONFIG_COMPAT
10710 +
10711 +extern int vc_get_iattr_x32(void __user *);
10712 +extern int vc_set_iattr_x32(void __user *);
10713 +
10714 +#endif /* CONFIG_COMPAT */
10715 +
10716 +#endif /* _VSERVER_INODE_CMD_H */
10717 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h
10718 --- linux-3.13.10/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10719 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h      2014-01-31 20:38:03.000000000 +0000
10720 @@ -0,0 +1,61 @@
10721 +#ifndef _VSERVER_LIMIT_H
10722 +#define _VSERVER_LIMIT_H
10723 +
10724 +#include <uapi/vserver/limit.h>
10725 +
10726 +
10727 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10728 +
10729 +/*     keep in sync with CRLIM_INFINITY */
10730 +
10731 +#define        VLIM_INFINITY   (~0ULL)
10732 +
10733 +#include <asm/atomic.h>
10734 +#include <asm/resource.h>
10735 +
10736 +#ifndef RLIM_INFINITY
10737 +#warning RLIM_INFINITY is undefined
10738 +#endif
10739 +
10740 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10741 +
10742 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10743 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10744 +
10745 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10746 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10747 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10748 +
10749 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10750 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10751 +
10752 +typedef atomic_long_t rlim_atomic_t;
10753 +typedef unsigned long rlim_t;
10754 +
10755 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10756 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10757 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10758 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10759 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10760 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10761 +
10762 +
10763 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10764 +#define        VX_VLIM(r) ((long long)(long)(r))
10765 +#define        VX_RLIM(v) ((rlim_t)(v))
10766 +#else
10767 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10768 +               ? VLIM_INFINITY : (long long)(r))
10769 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10770 +               ? RLIM_INFINITY : (rlim_t)(v))
10771 +#endif
10772 +
10773 +struct sysinfo;
10774 +
10775 +void vx_vsi_meminfo(struct sysinfo *);
10776 +void vx_vsi_swapinfo(struct sysinfo *);
10777 +long vx_vsi_cached(struct sysinfo *);
10778 +
10779 +#define NUM_LIMITS     24
10780 +
10781 +#endif /* _VSERVER_LIMIT_H */
10782 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h
10783 --- linux-3.13.10/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10784 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h  2014-01-31 20:38:03.000000000 +0000
10785 @@ -0,0 +1,35 @@
10786 +#ifndef _VSERVER_LIMIT_CMD_H
10787 +#define _VSERVER_LIMIT_CMD_H
10788 +
10789 +#include <uapi/vserver/limit_cmd.h>
10790 +
10791 +
10792 +#ifdef CONFIG_IA32_EMULATION
10793 +
10794 +struct vcmd_ctx_rlimit_v0_x32 {
10795 +       uint32_t id;
10796 +       uint64_t minimum;
10797 +       uint64_t softlimit;
10798 +       uint64_t maximum;
10799 +} __attribute__ ((packed));
10800 +
10801 +#endif /* CONFIG_IA32_EMULATION */
10802 +
10803 +#include <linux/compiler.h>
10804 +
10805 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10806 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10807 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10808 +extern int vc_reset_hits(struct vx_info *, void __user *);
10809 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10810 +
10811 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10812 +
10813 +#ifdef CONFIG_IA32_EMULATION
10814 +
10815 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10816 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10817 +
10818 +#endif /* CONFIG_IA32_EMULATION */
10819 +
10820 +#endif /* _VSERVER_LIMIT_CMD_H */
10821 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h
10822 --- linux-3.13.10/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10823 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h  2014-01-31 20:38:03.000000000 +0000
10824 @@ -0,0 +1,47 @@
10825 +#ifndef _VSERVER_LIMIT_DEF_H
10826 +#define _VSERVER_LIMIT_DEF_H
10827 +
10828 +#include <asm/atomic.h>
10829 +#include <asm/resource.h>
10830 +
10831 +#include "limit.h"
10832 +
10833 +
10834 +struct _vx_res_limit {
10835 +       rlim_t soft;            /* Context soft limit */
10836 +       rlim_t hard;            /* Context hard limit */
10837 +
10838 +       rlim_atomic_t rcur;     /* Current value */
10839 +       rlim_t rmin;            /* Context minimum */
10840 +       rlim_t rmax;            /* Context maximum */
10841 +
10842 +       atomic_t lhit;          /* Limit hits */
10843 +};
10844 +
10845 +/* context sub struct */
10846 +
10847 +struct _vx_limit {
10848 +       struct _vx_res_limit res[NUM_LIMITS];
10849 +};
10850 +
10851 +#ifdef CONFIG_VSERVER_DEBUG
10852 +
10853 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10854 +{
10855 +       int i;
10856 +
10857 +       printk("\t_vx_limit:");
10858 +       for (i = 0; i < NUM_LIMITS; i++) {
10859 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10860 +                       i, (unsigned long)__rlim_get(limit, i),
10861 +                       (unsigned long)__rlim_rmin(limit, i),
10862 +                       (unsigned long)__rlim_rmax(limit, i),
10863 +                       (long)__rlim_soft(limit, i),
10864 +                       (long)__rlim_hard(limit, i),
10865 +                       atomic_read(&__rlim_lhit(limit, i)));
10866 +       }
10867 +}
10868 +
10869 +#endif
10870 +
10871 +#endif /* _VSERVER_LIMIT_DEF_H */
10872 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h
10873 --- linux-3.13.10/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10874 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h  2014-01-31 20:38:03.000000000 +0000
10875 @@ -0,0 +1,193 @@
10876 +#ifndef _VSERVER_LIMIT_INT_H
10877 +#define _VSERVER_LIMIT_INT_H
10878 +
10879 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10880 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10881 +
10882 +extern const char *vlimit_name[NUM_LIMITS];
10883 +
10884 +static inline void __vx_acc_cres(struct vx_info *vxi,
10885 +       int res, int dir, void *_data, char *_file, int _line)
10886 +{
10887 +       if (VXD_RCRES_COND(res))
10888 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10889 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10890 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10891 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10892 +       if (!vxi)
10893 +               return;
10894 +
10895 +       if (dir > 0)
10896 +               __rlim_inc(&vxi->limit, res);
10897 +       else
10898 +               __rlim_dec(&vxi->limit, res);
10899 +}
10900 +
10901 +static inline void __vx_add_cres(struct vx_info *vxi,
10902 +       int res, int amount, void *_data, char *_file, int _line)
10903 +{
10904 +       if (VXD_RCRES_COND(res))
10905 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10906 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10907 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10908 +                       amount, _data, _file, _line);
10909 +       if (amount == 0)
10910 +               return;
10911 +       if (!vxi)
10912 +               return;
10913 +       __rlim_add(&vxi->limit, res, amount);
10914 +}
10915 +
10916 +static inline
10917 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10918 +{
10919 +       int cond = (value > __rlim_rmax(limit, res));
10920 +
10921 +       if (cond)
10922 +               __rlim_rmax(limit, res) = value;
10923 +       return cond;
10924 +}
10925 +
10926 +static inline
10927 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10928 +{
10929 +       int cond = (value < __rlim_rmin(limit, res));
10930 +
10931 +       if (cond)
10932 +               __rlim_rmin(limit, res) = value;
10933 +       return cond;
10934 +}
10935 +
10936 +static inline
10937 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10938 +{
10939 +       if (!__vx_cres_adjust_max(limit, res, value))
10940 +               __vx_cres_adjust_min(limit, res, value);
10941 +}
10942 +
10943 +
10944 +/*     return values:
10945 +        +1 ... no limit hit
10946 +        -1 ... over soft limit
10947 +         0 ... over hard limit         */
10948 +
10949 +static inline int __vx_cres_avail(struct vx_info *vxi,
10950 +       int res, int num, char *_file, int _line)
10951 +{
10952 +       struct _vx_limit *limit;
10953 +       rlim_t value;
10954 +
10955 +       if (VXD_RLIMIT_COND(res))
10956 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10957 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10958 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10959 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10960 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10961 +                       num, _file, _line);
10962 +       if (!vxi)
10963 +               return 1;
10964 +
10965 +       limit = &vxi->limit;
10966 +       value = __rlim_get(limit, res);
10967 +
10968 +       if (!__vx_cres_adjust_max(limit, res, value))
10969 +               __vx_cres_adjust_min(limit, res, value);
10970 +
10971 +       if (num == 0)
10972 +               return 1;
10973 +
10974 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
10975 +               return -1;
10976 +       if (value + num <= __rlim_soft(limit, res))
10977 +               return -1;
10978 +
10979 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
10980 +               return 1;
10981 +       if (value + num <= __rlim_hard(limit, res))
10982 +               return 1;
10983 +
10984 +       __rlim_hit(limit, res);
10985 +       return 0;
10986 +}
10987 +
10988 +
10989 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10990 +
10991 +static inline
10992 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10993 +{
10994 +       rlim_t value, sum = 0;
10995 +       int res;
10996 +
10997 +       while ((res = *array++)) {
10998 +               value = __rlim_get(limit, res);
10999 +               __vx_cres_fixup(limit, res, value);
11000 +               sum += value;
11001 +       }
11002 +       return sum;
11003 +}
11004 +
11005 +static inline
11006 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11007 +{
11008 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11009 +       int res = *array;
11010 +
11011 +       if (value == __rlim_get(limit, res))
11012 +               return value;
11013 +
11014 +       __rlim_set(limit, res, value);
11015 +       /* now adjust min/max */
11016 +       if (!__vx_cres_adjust_max(limit, res, value))
11017 +               __vx_cres_adjust_min(limit, res, value);
11018 +
11019 +       return value;
11020 +}
11021 +
11022 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11023 +       const int *array, int num, char *_file, int _line)
11024 +{
11025 +       struct _vx_limit *limit;
11026 +       rlim_t value = 0;
11027 +       int res;
11028 +
11029 +       if (num == 0)
11030 +               return 1;
11031 +       if (!vxi)
11032 +               return 1;
11033 +
11034 +       limit = &vxi->limit;
11035 +       res = *array;
11036 +       value = __vx_cres_array_sum(limit, array + 1);
11037 +
11038 +       __rlim_set(limit, res, value);
11039 +       __vx_cres_fixup(limit, res, value);
11040 +
11041 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11042 +}
11043 +
11044 +
11045 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11046 +{
11047 +       rlim_t value;
11048 +       int res;
11049 +
11050 +       /* complex resources first */
11051 +       if ((id < 0) || (id == RLIMIT_RSS))
11052 +               __vx_cres_array_fixup(limit, VLA_RSS);
11053 +
11054 +       for (res = 0; res < NUM_LIMITS; res++) {
11055 +               if ((id > 0) && (res != id))
11056 +                       continue;
11057 +
11058 +               value = __rlim_get(limit, res);
11059 +               __vx_cres_fixup(limit, res, value);
11060 +
11061 +               /* not supposed to happen, maybe warn? */
11062 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11063 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11064 +       }
11065 +}
11066 +
11067 +
11068 +#endif /* _VSERVER_LIMIT_INT_H */
11069 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h
11070 --- linux-3.13.10/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11071 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h    2014-01-31 20:38:03.000000000 +0000
11072 @@ -0,0 +1,6 @@
11073 +#ifndef _VSERVER_MONITOR_H
11074 +#define _VSERVER_MONITOR_H
11075 +
11076 +#include <uapi/vserver/monitor.h>
11077 +
11078 +#endif /* _VSERVER_MONITOR_H */
11079 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h
11080 --- linux-3.13.10/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11081 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h    2014-01-31 20:38:03.000000000 +0000
11082 @@ -0,0 +1,76 @@
11083 +#ifndef _VSERVER_NETWORK_H
11084 +#define _VSERVER_NETWORK_H
11085 +
11086 +
11087 +#include <linux/list.h>
11088 +#include <linux/spinlock.h>
11089 +#include <linux/rcupdate.h>
11090 +#include <linux/in.h>
11091 +#include <linux/in6.h>
11092 +#include <asm/atomic.h>
11093 +#include <uapi/vserver/network.h>
11094 +
11095 +struct nx_addr_v4 {
11096 +       struct nx_addr_v4 *next;
11097 +       struct in_addr ip[2];
11098 +       struct in_addr mask;
11099 +       uint16_t type;
11100 +       uint16_t flags;
11101 +};
11102 +
11103 +struct nx_addr_v6 {
11104 +       struct nx_addr_v6 *next;
11105 +       struct in6_addr ip;
11106 +       struct in6_addr mask;
11107 +       uint32_t prefix;
11108 +       uint16_t type;
11109 +       uint16_t flags;
11110 +};
11111 +
11112 +struct nx_info {
11113 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11114 +       vnid_t nx_id;                   /* vnet id */
11115 +       atomic_t nx_usecnt;             /* usage count */
11116 +       atomic_t nx_tasks;              /* tasks count */
11117 +       int nx_state;                   /* context state */
11118 +
11119 +       uint64_t nx_flags;              /* network flag word */
11120 +       uint64_t nx_ncaps;              /* network capabilities */
11121 +
11122 +       spinlock_t addr_lock;           /* protect address changes */
11123 +       struct in_addr v4_lback;        /* Loopback address */
11124 +       struct in_addr v4_bcast;        /* Broadcast address */
11125 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11126 +#ifdef CONFIG_IPV6
11127 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11128 +#endif
11129 +       char nx_name[65];               /* network context name */
11130 +};
11131 +
11132 +
11133 +/* status flags */
11134 +
11135 +#define NXS_HASHED      0x0001
11136 +#define NXS_SHUTDOWN    0x0100
11137 +#define NXS_RELEASED    0x8000
11138 +
11139 +extern struct nx_info *lookup_nx_info(int);
11140 +
11141 +extern int get_nid_list(int, unsigned int *, int);
11142 +extern int nid_is_hashed(vnid_t);
11143 +
11144 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11145 +
11146 +extern long vs_net_change(struct nx_info *, unsigned int);
11147 +
11148 +struct sock;
11149 +
11150 +
11151 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11152 +#ifdef  CONFIG_IPV6
11153 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11154 +#else
11155 +#define NX_IPV6(n)     (0)
11156 +#endif
11157 +
11158 +#endif /* _VSERVER_NETWORK_H */
11159 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h
11160 --- linux-3.13.10/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11161 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h        2014-01-31 20:38:03.000000000 +0000
11162 @@ -0,0 +1,37 @@
11163 +#ifndef _VSERVER_NETWORK_CMD_H
11164 +#define _VSERVER_NETWORK_CMD_H
11165 +
11166 +#include <uapi/vserver/network_cmd.h>
11167 +
11168 +extern int vc_task_nid(uint32_t);
11169 +
11170 +extern int vc_nx_info(struct nx_info *, void __user *);
11171 +
11172 +extern int vc_net_create(uint32_t, void __user *);
11173 +extern int vc_net_migrate(struct nx_info *, void __user *);
11174 +
11175 +extern int vc_net_add(struct nx_info *, void __user *);
11176 +extern int vc_net_remove(struct nx_info *, void __user *);
11177 +
11178 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11179 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11180 +
11181 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11182 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11183 +
11184 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11185 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11186 +
11187 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11188 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11189 +
11190 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11191 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11192 +
11193 +extern int vc_get_nflags(struct nx_info *, void __user *);
11194 +extern int vc_set_nflags(struct nx_info *, void __user *);
11195 +
11196 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11197 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11198 +
11199 +#endif /* _VSERVER_CONTEXT_CMD_H */
11200 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/percpu.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h
11201 --- linux-3.13.10/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11202 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h     2014-01-31 20:38:03.000000000 +0000
11203 @@ -0,0 +1,14 @@
11204 +#ifndef _VSERVER_PERCPU_H
11205 +#define _VSERVER_PERCPU_H
11206 +
11207 +#include "cvirt_def.h"
11208 +#include "sched_def.h"
11209 +
11210 +struct _vx_percpu {
11211 +       struct _vx_cvirt_pc cvirt;
11212 +       struct _vx_sched_pc sched;
11213 +};
11214 +
11215 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11216 +
11217 +#endif /* _VSERVER_PERCPU_H */
11218 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/pid.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h
11219 --- linux-3.13.10/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11220 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h        2014-01-31 20:38:03.000000000 +0000
11221 @@ -0,0 +1,51 @@
11222 +#ifndef _VSERVER_PID_H
11223 +#define _VSERVER_PID_H
11224 +
11225 +/* pid faking stuff */
11226 +
11227 +#define vx_info_map_pid(v, p) \
11228 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11229 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11230 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11231 +#define vx_map_tgid(p) vx_map_pid(p)
11232 +
11233 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11234 +       const char *func, const char *file, int line)
11235 +{
11236 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11237 +               vxfprintk(VXD_CBIT(cvirt, 2),
11238 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11239 +                       vxi, (long long)vxi->vx_flags, pid,
11240 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11241 +                       func, file, line);
11242 +               if (pid == 0)
11243 +                       return 0;
11244 +               if (pid == vxi->vx_initpid)
11245 +                       return 1;
11246 +       }
11247 +       return pid;
11248 +}
11249 +
11250 +#define vx_info_rmap_pid(v, p) \
11251 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11252 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11253 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11254 +
11255 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11256 +       const char *func, const char *file, int line)
11257 +{
11258 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11259 +               vxfprintk(VXD_CBIT(cvirt, 2),
11260 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11261 +                       vxi, (long long)vxi->vx_flags, pid,
11262 +                       (pid == 1) ? vxi->vx_initpid : pid,
11263 +                       func, file, line);
11264 +               if ((pid == 1) && vxi->vx_initpid)
11265 +                       return vxi->vx_initpid;
11266 +               if (pid == vxi->vx_initpid)
11267 +                       return ~0U;
11268 +       }
11269 +       return pid;
11270 +}
11271 +
11272 +#endif
11273 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h
11274 --- linux-3.13.10/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11275 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h      2014-01-31 20:38:03.000000000 +0000
11276 @@ -0,0 +1,23 @@
11277 +#ifndef _VSERVER_SCHED_H
11278 +#define _VSERVER_SCHED_H
11279 +
11280 +
11281 +#ifdef __KERNEL__
11282 +
11283 +struct timespec;
11284 +
11285 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11286 +
11287 +
11288 +struct vx_info;
11289 +
11290 +void vx_update_load(struct vx_info *);
11291 +
11292 +
11293 +void vx_update_sched_param(struct _vx_sched *sched,
11294 +       struct _vx_sched_pc *sched_pc);
11295 +
11296 +#endif /* __KERNEL__ */
11297 +#else  /* _VSERVER_SCHED_H */
11298 +#warning duplicate inclusion
11299 +#endif /* _VSERVER_SCHED_H */
11300 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h
11301 --- linux-3.13.10/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
11302 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h  2014-01-31 20:38:03.000000000 +0000
11303 @@ -0,0 +1,11 @@
11304 +#ifndef _VSERVER_SCHED_CMD_H
11305 +#define _VSERVER_SCHED_CMD_H
11306 +
11307 +
11308 +#include <linux/compiler.h>
11309 +#include <uapi/vserver/sched_cmd.h>
11310 +
11311 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11312 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11313 +
11314 +#endif /* _VSERVER_SCHED_CMD_H */
11315 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h
11316 --- linux-3.13.10/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11317 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h  2014-01-31 20:38:03.000000000 +0000
11318 @@ -0,0 +1,38 @@
11319 +#ifndef _VSERVER_SCHED_DEF_H
11320 +#define _VSERVER_SCHED_DEF_H
11321 +
11322 +#include <linux/spinlock.h>
11323 +#include <linux/jiffies.h>
11324 +#include <linux/cpumask.h>
11325 +#include <asm/atomic.h>
11326 +#include <asm/param.h>
11327 +
11328 +
11329 +/* context sub struct */
11330 +
11331 +struct _vx_sched {
11332 +       int prio_bias;                  /* bias offset for priority */
11333 +
11334 +       cpumask_t update;               /* CPUs which should update */
11335 +};
11336 +
11337 +struct _vx_sched_pc {
11338 +       int prio_bias;                  /* bias offset for priority */
11339 +
11340 +       uint64_t user_ticks;            /* token tick events */
11341 +       uint64_t sys_ticks;             /* token tick events */
11342 +       uint64_t hold_ticks;            /* token ticks paused */
11343 +};
11344 +
11345 +
11346 +#ifdef CONFIG_VSERVER_DEBUG
11347 +
11348 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11349 +{
11350 +       printk("\t_vx_sched:\n");
11351 +       printk("\t priority = %4d\n", sched->prio_bias);
11352 +}
11353 +
11354 +#endif
11355 +
11356 +#endif /* _VSERVER_SCHED_DEF_H */
11357 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h
11358 --- linux-3.13.10/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11359 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h     2014-01-31 20:38:03.000000000 +0000
11360 @@ -0,0 +1,14 @@
11361 +#ifndef _VSERVER_SIGNAL_H
11362 +#define _VSERVER_SIGNAL_H
11363 +
11364 +
11365 +#ifdef __KERNEL__
11366 +
11367 +struct vx_info;
11368 +
11369 +int vx_info_kill(struct vx_info *, int, int);
11370 +
11371 +#endif /* __KERNEL__ */
11372 +#else  /* _VSERVER_SIGNAL_H */
11373 +#warning duplicate inclusion
11374 +#endif /* _VSERVER_SIGNAL_H */
11375 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h
11376 --- linux-3.13.10/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11377 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11378 @@ -0,0 +1,14 @@
11379 +#ifndef _VSERVER_SIGNAL_CMD_H
11380 +#define _VSERVER_SIGNAL_CMD_H
11381 +
11382 +#include <uapi/vserver/signal_cmd.h>
11383 +
11384 +
11385 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11386 +extern int vc_wait_exit(struct vx_info *, void __user *);
11387 +
11388 +
11389 +extern int vc_get_pflags(uint32_t pid, void __user *);
11390 +extern int vc_set_pflags(uint32_t pid, void __user *);
11391 +
11392 +#endif /* _VSERVER_SIGNAL_CMD_H */
11393 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h
11394 --- linux-3.13.10/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11395 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h      2014-01-31 20:38:03.000000000 +0000
11396 @@ -0,0 +1,12 @@
11397 +#ifndef _VSERVER_SPACE_H
11398 +#define _VSERVER_SPACE_H
11399 +
11400 +#include <linux/types.h>
11401 +
11402 +struct vx_info;
11403 +
11404 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11405 +
11406 +#else  /* _VSERVER_SPACE_H */
11407 +#warning duplicate inclusion
11408 +#endif /* _VSERVER_SPACE_H */
11409 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h
11410 --- linux-3.13.10/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11411 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h  2014-01-31 20:38:03.000000000 +0000
11412 @@ -0,0 +1,13 @@
11413 +#ifndef _VSERVER_SPACE_CMD_H
11414 +#define _VSERVER_SPACE_CMD_H
11415 +
11416 +#include <uapi/vserver/space_cmd.h>
11417 +
11418 +
11419 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11420 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11421 +extern int vc_enter_space(struct vx_info *, void __user *);
11422 +extern int vc_set_space(struct vx_info *, void __user *);
11423 +extern int vc_get_space_mask(void __user *, int);
11424 +
11425 +#endif /* _VSERVER_SPACE_CMD_H */
11426 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h
11427 --- linux-3.13.10/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11428 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h     2014-01-31 20:38:03.000000000 +0000
11429 @@ -0,0 +1,8 @@
11430 +#ifndef _VSERVER_SWITCH_H
11431 +#define _VSERVER_SWITCH_H
11432 +
11433 +
11434 +#include <linux/errno.h>
11435 +#include <uapi/vserver/switch.h>
11436 +
11437 +#endif /* _VSERVER_SWITCH_H */
11438 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h
11439 --- linux-3.13.10/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11440 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h        2014-01-31 20:38:03.000000000 +0000
11441 @@ -0,0 +1,160 @@
11442 +#ifndef _DX_TAG_H
11443 +#define _DX_TAG_H
11444 +
11445 +#include <linux/types.h>
11446 +#include <linux/uidgid.h>
11447 +
11448 +
11449 +#define DX_TAG(in)     (IS_TAGGED(in))
11450 +
11451 +
11452 +#ifdef CONFIG_TAG_NFSD
11453 +#define DX_TAG_NFSD    1
11454 +#else
11455 +#define DX_TAG_NFSD    0
11456 +#endif
11457 +
11458 +
11459 +#ifdef CONFIG_TAGGING_NONE
11460 +
11461 +#define MAX_UID                0xFFFFFFFF
11462 +#define MAX_GID                0xFFFFFFFF
11463 +
11464 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11465 +
11466 +#define TAGINO_UID(cond, uid, tag)     (uid)
11467 +#define TAGINO_GID(cond, gid, tag)     (gid)
11468 +
11469 +#endif
11470 +
11471 +
11472 +#ifdef CONFIG_TAGGING_GID16
11473 +
11474 +#define MAX_UID                0xFFFFFFFF
11475 +#define MAX_GID                0x0000FFFF
11476 +
11477 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11478 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11479 +
11480 +#define TAGINO_UID(cond, uid, tag)     (uid)
11481 +#define TAGINO_GID(cond, gid, tag)     \
11482 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11483 +
11484 +#endif
11485 +
11486 +
11487 +#ifdef CONFIG_TAGGING_ID24
11488 +
11489 +#define MAX_UID                0x00FFFFFF
11490 +#define MAX_GID                0x00FFFFFF
11491 +
11492 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11493 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11494 +
11495 +#define TAGINO_UID(cond, uid, tag)     \
11496 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11497 +#define TAGINO_GID(cond, gid, tag)     \
11498 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11499 +
11500 +#endif
11501 +
11502 +
11503 +#ifdef CONFIG_TAGGING_UID16
11504 +
11505 +#define MAX_UID                0x0000FFFF
11506 +#define MAX_GID                0xFFFFFFFF
11507 +
11508 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11509 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11510 +
11511 +#define TAGINO_UID(cond, uid, tag)     \
11512 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11513 +#define TAGINO_GID(cond, gid, tag)     (gid)
11514 +
11515 +#endif
11516 +
11517 +
11518 +#ifdef CONFIG_TAGGING_INTERN
11519 +
11520 +#define MAX_UID                0xFFFFFFFF
11521 +#define MAX_GID                0xFFFFFFFF
11522 +
11523 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11524 +       ((cond) ? (tag) : 0)
11525 +
11526 +#define TAGINO_UID(cond, uid, tag)     (uid)
11527 +#define TAGINO_GID(cond, gid, tag)     (gid)
11528 +
11529 +#endif
11530 +
11531 +
11532 +#ifndef CONFIG_TAGGING_NONE
11533 +#define dx_current_fstag(sb)   \
11534 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11535 +#else
11536 +#define dx_current_fstag(sb)   (0)
11537 +#endif
11538 +
11539 +#ifndef CONFIG_TAGGING_INTERN
11540 +#define TAGINO_TAG(cond, tag)  (0)
11541 +#else
11542 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11543 +#endif
11544 +
11545 +#define TAGINO_KUID(cond, kuid, ktag)  \
11546 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11547 +#define TAGINO_KGID(cond, kgid, ktag)  \
11548 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11549 +#define TAGINO_KTAG(cond, ktag)                \
11550 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11551 +
11552 +
11553 +#define INOTAG_UID(cond, uid, gid)     \
11554 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11555 +#define INOTAG_GID(cond, uid, gid)     \
11556 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11557 +
11558 +#define INOTAG_KUID(cond, kuid, kgid)  \
11559 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11560 +#define INOTAG_KGID(cond, kuid, kgid)  \
11561 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11562 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11563 +       KTAGT_INIT(INOTAG_TAG(cond, \
11564 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11565 +
11566 +
11567 +static inline uid_t dx_map_uid(uid_t uid)
11568 +{
11569 +       if ((uid > MAX_UID) && (uid != -1))
11570 +               uid = -2;
11571 +       return (uid & MAX_UID);
11572 +}
11573 +
11574 +static inline gid_t dx_map_gid(gid_t gid)
11575 +{
11576 +       if ((gid > MAX_GID) && (gid != -1))
11577 +               gid = -2;
11578 +       return (gid & MAX_GID);
11579 +}
11580 +
11581 +struct peer_tag {
11582 +       int32_t xid;
11583 +       int32_t nid;
11584 +};
11585 +
11586 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11587 +
11588 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11589 +                unsigned long *flags);
11590 +
11591 +#ifdef CONFIG_PROPAGATE
11592 +
11593 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11594 +
11595 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11596 +
11597 +#else
11598 +#define dx_propagate_tag(n, i) do { } while (0)
11599 +#endif
11600 +
11601 +#endif /* _DX_TAG_H */
11602 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h
11603 --- linux-3.13.10/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11604 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h    2014-01-31 20:38:03.000000000 +0000
11605 @@ -0,0 +1,10 @@
11606 +#ifndef _VSERVER_TAG_CMD_H
11607 +#define _VSERVER_TAG_CMD_H
11608 +
11609 +#include <uapi/vserver/tag_cmd.h>
11610 +
11611 +extern int vc_task_tag(uint32_t);
11612 +
11613 +extern int vc_tag_migrate(uint32_t);
11614 +
11615 +#endif /* _VSERVER_TAG_CMD_H */
11616 diff -NurpP --minimal linux-3.13.10/include/net/addrconf.h linux-3.13.10-vs2.3.6.11/include/net/addrconf.h
11617 --- linux-3.13.10/include/net/addrconf.h        2013-11-25 15:47:02.000000000 +0000
11618 +++ linux-3.13.10-vs2.3.6.11/include/net/addrconf.h     2014-01-31 20:39:35.000000000 +0000
11619 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11620  
11621  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11622                        const struct in6_addr *daddr, unsigned int srcprefs,
11623 -                      struct in6_addr *saddr);
11624 +                      struct in6_addr *saddr, struct nx_info *nxi);
11625  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11626                       unsigned char banned_flags);
11627  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11628 diff -NurpP --minimal linux-3.13.10/include/net/af_unix.h linux-3.13.10-vs2.3.6.11/include/net/af_unix.h
11629 --- linux-3.13.10/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11630 +++ linux-3.13.10-vs2.3.6.11/include/net/af_unix.h      2014-01-31 20:38:03.000000000 +0000
11631 @@ -4,6 +4,7 @@
11632  #include <linux/socket.h>
11633  #include <linux/un.h>
11634  #include <linux/mutex.h>
11635 +#include <linux/vs_base.h>
11636  #include <net/sock.h>
11637  
11638  void unix_inflight(struct file *fp);
11639 diff -NurpP --minimal linux-3.13.10/include/net/inet_timewait_sock.h linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h
11640 --- linux-3.13.10/include/net/inet_timewait_sock.h      2014-01-22 20:39:11.000000000 +0000
11641 +++ linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h   2014-01-31 20:40:30.000000000 +0000
11642 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11643  #define tw_v6_rcv_saddr        __tw_common.skc_v6_rcv_saddr
11644  #define tw_dport               __tw_common.skc_dport
11645  #define tw_num                 __tw_common.skc_num
11646 +#define tw_xid                 __tw_common.skc_xid
11647 +#define tw_vx_info             __tw_common.skc_vx_info
11648 +#define tw_nid                 __tw_common.skc_nid
11649 +#define tw_nx_info             __tw_common.skc_nx_info
11650  
11651         int                     tw_timeout;
11652         volatile unsigned char  tw_substate;
11653 diff -NurpP --minimal linux-3.13.10/include/net/ip6_route.h linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h
11654 --- linux-3.13.10/include/net/ip6_route.h       2014-01-22 20:39:11.000000000 +0000
11655 +++ linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h    2014-01-31 20:41:10.000000000 +0000
11656 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11657  
11658  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11659                         const struct in6_addr *daddr, unsigned int prefs,
11660 -                       struct in6_addr *saddr);
11661 +                       struct in6_addr *saddr, struct nx_info *nxi);
11662  
11663  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11664                             const struct in6_addr *saddr, int oif, int flags);
11665 diff -NurpP --minimal linux-3.13.10/include/net/route.h linux-3.13.10-vs2.3.6.11/include/net/route.h
11666 --- linux-3.13.10/include/net/route.h   2014-01-22 20:39:12.000000000 +0000
11667 +++ linux-3.13.10-vs2.3.6.11/include/net/route.h        2014-02-01 12:30:58.000000000 +0000
11668 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11669         dst_release(&rt->dst);
11670  }
11671  
11672 +#include <linux/vs_base.h>
11673 +#include <linux/vs_inet.h>
11674 +
11675  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11676  
11677  extern const __u8 ip_tos2prio[16];
11678 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11679                            protocol, flow_flags, dst, src, dport, sport);
11680  }
11681  
11682 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11683 +       struct flowi4 *);
11684 +
11685  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11686                                               __be32 dst, __be32 src, u32 tos,
11687                                               int oif, u8 protocol,
11688 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11689  {
11690         struct net *net = sock_net(sk);
11691         struct rtable *rt;
11692 +       struct nx_info *nx_info = current_nx_info();
11693  
11694         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11695                               sport, dport, sk);
11696  
11697 -       if (!dst || !src) {
11698 +       if (sk)
11699 +               nx_info = sk->sk_nx_info;
11700 +
11701 +       vxdprintk(VXD_CBIT(net, 4),
11702 +               "ip_route_connect(%p) %p,%p;%lx",
11703 +               sk, nx_info, sk->sk_socket,
11704 +               (sk->sk_socket?sk->sk_socket->flags:0));
11705 +
11706 +       rt = ip_v4_find_src(net, nx_info, fl4);
11707 +       if (IS_ERR(rt))
11708 +               return rt;
11709 +       ip_rt_put(rt);
11710 +
11711 +       if (!fl4->daddr || !fl4->saddr) {
11712                 rt = __ip_route_output_key(net, fl4);
11713                 if (IS_ERR(rt))
11714                         return rt;
11715 diff -NurpP --minimal linux-3.13.10/include/net/sock.h linux-3.13.10-vs2.3.6.11/include/net/sock.h
11716 --- linux-3.13.10/include/net/sock.h    2014-04-17 01:12:39.000000000 +0000
11717 +++ linux-3.13.10-vs2.3.6.11/include/net/sock.h 2014-04-17 01:17:10.000000000 +0000
11718 @@ -191,6 +191,10 @@ struct sock_common {
11719  #ifdef CONFIG_NET_NS
11720         struct net              *skc_net;
11721  #endif
11722 +       vxid_t                  skc_xid;
11723 +       struct vx_info          *skc_vx_info;
11724 +       vnid_t                  skc_nid;
11725 +       struct nx_info          *skc_nx_info;
11726  
11727  #if IS_ENABLED(CONFIG_IPV6)
11728         struct in6_addr         skc_v6_daddr;
11729 @@ -321,7 +325,11 @@ struct sock {
11730  #define sk_prot                        __sk_common.skc_prot
11731  #define sk_net                 __sk_common.skc_net
11732  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11733 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11734 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11735 +#define sk_xid                 __sk_common.skc_xid
11736 +#define sk_vx_info             __sk_common.skc_vx_info
11737 +#define sk_nid                 __sk_common.skc_nid
11738 +#define sk_nx_info             __sk_common.skc_nx_info
11739  
11740         socket_lock_t           sk_lock;
11741         struct sk_buff_head     sk_receive_queue;
11742 diff -NurpP --minimal linux-3.13.10/include/uapi/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild
11743 --- linux-3.13.10/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
11744 +++ linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild        2014-01-31 20:38:03.000000000 +0000
11745 @@ -12,3 +12,4 @@ header-y += video/
11746  header-y += drm/
11747  header-y += xen/
11748  header-y += scsi/
11749 +header-y += vserver/
11750 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/capability.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h
11751 --- linux-3.13.10/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
11752 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h    2014-01-31 20:38:03.000000000 +0000
11753 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11754     arbitrary SCSI commands */
11755  /* Allow setting encryption key on loopback filesystem */
11756  /* Allow setting zone reclaim policy */
11757 +/* Allow the selection of a security context */
11758  
11759  #define CAP_SYS_ADMIN        21
11760  
11761 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11762  
11763  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
11764  
11765 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11766 +/* Allow context manipulations */
11767 +/* Allow changing context info on files */
11768 +
11769 +#define CAP_CONTEXT         63
11770 +
11771 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11772  
11773  /*
11774   * Bit location of each capability (used by user-space library and kernel)
11775 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/fs.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h
11776 --- linux-3.13.10/include/uapi/linux/fs.h       2013-11-25 15:47:02.000000000 +0000
11777 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h    2014-01-31 20:38:03.000000000 +0000
11778 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11779  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
11780  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11781  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11782 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11783 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11784 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11785  
11786  /* These sb flags are internal to the kernel */
11787  #define MS_NOSEC       (1<<28)
11788 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11789  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11790  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11791  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11792 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11793  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11794  
11795 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11796 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11797 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11798 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11799  
11800 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11801 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11802  
11803  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11804  #define SYNC_FILE_RANGE_WRITE          2
11805 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/gfs2_ondisk.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h
11806 --- linux-3.13.10/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
11807 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h   2014-01-31 20:38:03.000000000 +0000
11808 @@ -225,6 +225,9 @@ enum {
11809         gfs2fl_Sync             = 8,
11810         gfs2fl_System           = 9,
11811         gfs2fl_TopLevel         = 10,
11812 +       gfs2fl_IXUnlink         = 16,
11813 +       gfs2fl_Barrier          = 17,
11814 +       gfs2fl_Cow              = 18,
11815         gfs2fl_TruncInProg      = 29,
11816         gfs2fl_InheritDirectio  = 30,
11817         gfs2fl_InheritJdata     = 31,
11818 @@ -242,6 +245,9 @@ enum {
11819  #define GFS2_DIF_SYNC                  0x00000100
11820  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11821  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11822 +#define GFS2_DIF_IXUNLINK               0x00010000
11823 +#define GFS2_DIF_BARRIER                0x00020000
11824 +#define GFS2_DIF_COW                    0x00040000
11825  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11826  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11827  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11828 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/if_tun.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h
11829 --- linux-3.13.10/include/uapi/linux/if_tun.h   2013-11-25 15:47:02.000000000 +0000
11830 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h        2014-01-31 20:45:49.000000000 +0000
11831 @@ -58,6 +58,7 @@
11832  #define TUNSETQUEUE  _IOW('T', 217, int)
11833  #define TUNSETIFINDEX  _IOW('T', 218, unsigned int)
11834  #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11835 +#define TUNSETNID     _IOW('T', 220, int)
11836  
11837  /* TUNSETIFF ifr flags */
11838  #define IFF_TUN                0x0001
11839 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/major.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h
11840 --- linux-3.13.10/include/uapi/linux/major.h    2014-01-22 20:39:12.000000000 +0000
11841 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11842 @@ -15,6 +15,7 @@
11843  #define HD_MAJOR               IDE0_MAJOR
11844  #define PTY_SLAVE_MAJOR                3
11845  #define TTY_MAJOR              4
11846 +#define VROOT_MAJOR            4
11847  #define TTYAUX_MAJOR           5
11848  #define LP_MAJOR               6
11849  #define VCS_MAJOR              7
11850 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/nfs_mount.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h
11851 --- linux-3.13.10/include/uapi/linux/nfs_mount.h        2014-01-22 20:39:12.000000000 +0000
11852 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h     2014-01-31 20:38:03.000000000 +0000
11853 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11854  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11855  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11856  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11857 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11858 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11859 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11860  
11861  /* The following are for internal use only */
11862  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11863 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/reboot.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h
11864 --- linux-3.13.10/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
11865 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h        2014-01-31 20:38:03.000000000 +0000
11866 @@ -33,7 +33,7 @@
11867  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11868  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11869  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11870 -
11871 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11872  
11873  
11874  #endif /* _UAPI_LINUX_REBOOT_H */
11875 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/sysctl.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h
11876 --- linux-3.13.10/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
11877 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h        2014-01-31 20:38:03.000000000 +0000
11878 @@ -60,6 +60,7 @@ enum
11879         CTL_ABI=9,              /* Binary emulation */
11880         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11881         CTL_ARLAN=254,          /* arlan wireless driver */
11882 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11883         CTL_S390DBF=5677,       /* s390 debug */
11884         CTL_SUNRPC=7249,        /* sunrpc debug */
11885         CTL_PM=9899,            /* frv power management */
11886 @@ -94,6 +95,7 @@ enum
11887  
11888         KERN_PANIC=15,          /* int: panic timeout */
11889         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11890 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11891  
11892         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11893         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11894 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild
11895 --- linux-3.13.10/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11896 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild        2014-01-31 20:38:03.000000000 +0000
11897 @@ -0,0 +1,9 @@
11898 +
11899 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11900 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11901 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11902 +       debug_cmd.h device_cmd.h
11903 +
11904 +header-y += switch.h context.h network.h monitor.h \
11905 +       limit.h inode.h device.h
11906 +
11907 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h
11908 --- linux-3.13.10/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11909 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h   2014-01-31 20:38:03.000000000 +0000
11910 @@ -0,0 +1,15 @@
11911 +#ifndef _UAPI_VS_CACCT_CMD_H
11912 +#define _UAPI_VS_CACCT_CMD_H
11913 +
11914 +
11915 +/* virtual host info name commands */
11916 +
11917 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11918 +
11919 +struct vcmd_sock_stat_v0 {
11920 +       uint32_t field;
11921 +       uint32_t count[3];
11922 +       uint64_t total[3];
11923 +};
11924 +
11925 +#endif /* _UAPI_VS_CACCT_CMD_H */
11926 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h
11927 --- linux-3.13.10/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11928 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h     2014-01-31 20:38:03.000000000 +0000
11929 @@ -0,0 +1,81 @@
11930 +#ifndef _UAPI_VS_CONTEXT_H
11931 +#define _UAPI_VS_CONTEXT_H
11932 +
11933 +#include <linux/types.h>
11934 +#include <linux/capability.h>
11935 +
11936 +
11937 +/* context flags */
11938 +
11939 +#define VXF_INFO_SCHED         0x00000002
11940 +#define VXF_INFO_NPROC         0x00000004
11941 +#define VXF_INFO_PRIVATE       0x00000008
11942 +
11943 +#define VXF_INFO_INIT          0x00000010
11944 +#define VXF_INFO_HIDE          0x00000020
11945 +#define VXF_INFO_ULIMIT                0x00000040
11946 +#define VXF_INFO_NSPACE                0x00000080
11947 +
11948 +#define VXF_SCHED_HARD         0x00000100
11949 +#define VXF_SCHED_PRIO         0x00000200
11950 +#define VXF_SCHED_PAUSE                0x00000400
11951 +
11952 +#define VXF_VIRT_MEM           0x00010000
11953 +#define VXF_VIRT_UPTIME                0x00020000
11954 +#define VXF_VIRT_CPU           0x00040000
11955 +#define VXF_VIRT_LOAD          0x00080000
11956 +#define VXF_VIRT_TIME          0x00100000
11957 +
11958 +#define VXF_HIDE_MOUNT         0x01000000
11959 +/* was VXF_HIDE_NETIF          0x02000000 */
11960 +#define VXF_HIDE_VINFO         0x04000000
11961 +
11962 +#define VXF_STATE_SETUP                (1ULL << 32)
11963 +#define VXF_STATE_INIT         (1ULL << 33)
11964 +#define VXF_STATE_ADMIN                (1ULL << 34)
11965 +
11966 +#define VXF_SC_HELPER          (1ULL << 36)
11967 +#define VXF_REBOOT_KILL                (1ULL << 37)
11968 +#define VXF_PERSISTENT         (1ULL << 38)
11969 +
11970 +#define VXF_FORK_RSS           (1ULL << 48)
11971 +#define VXF_PROLIFIC           (1ULL << 49)
11972 +
11973 +#define VXF_IGNEG_NICE         (1ULL << 52)
11974 +
11975 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11976 +
11977 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11978 +
11979 +
11980 +/* context migration */
11981 +
11982 +#define VXM_SET_INIT           0x00000001
11983 +#define VXM_SET_REAPER         0x00000002
11984 +
11985 +/* context caps */
11986 +
11987 +#define VXC_SET_UTSNAME                0x00000001
11988 +#define VXC_SET_RLIMIT         0x00000002
11989 +#define VXC_FS_SECURITY                0x00000004
11990 +#define VXC_FS_TRUSTED         0x00000008
11991 +#define VXC_TIOCSTI            0x00000010
11992 +
11993 +/* was VXC_RAW_ICMP            0x00000100 */
11994 +#define VXC_SYSLOG             0x00001000
11995 +#define VXC_OOM_ADJUST         0x00002000
11996 +#define VXC_AUDIT_CONTROL      0x00004000
11997 +
11998 +#define VXC_SECURE_MOUNT       0x00010000
11999 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12000 +#define VXC_BINARY_MOUNT       0x00040000
12001 +#define VXC_DEV_MOUNT          0x00080000
12002 +
12003 +#define VXC_QUOTA_CTL          0x00100000
12004 +#define VXC_ADMIN_MAPPER       0x00200000
12005 +#define VXC_ADMIN_CLOOP                0x00400000
12006 +
12007 +#define VXC_KTHREAD            0x01000000
12008 +#define VXC_NAMESPACE          0x02000000
12009 +
12010 +#endif /* _UAPI_VS_CONTEXT_H */
12011 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h
12012 --- linux-3.13.10/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12013 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12014 @@ -0,0 +1,115 @@
12015 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12016 +#define _UAPI_VS_CONTEXT_CMD_H
12017 +
12018 +
12019 +/* vinfo commands */
12020 +
12021 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12022 +
12023 +
12024 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12025 +
12026 +struct vcmd_vx_info_v0 {
12027 +       uint32_t xid;
12028 +       uint32_t initpid;
12029 +       /* more to come */
12030 +};
12031 +
12032 +
12033 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12034 +
12035 +struct vcmd_ctx_stat_v0 {
12036 +       uint32_t usecnt;
12037 +       uint32_t tasks;
12038 +       /* more to come */
12039 +};
12040 +
12041 +
12042 +/* context commands */
12043 +
12044 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12045 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12046 +
12047 +struct vcmd_ctx_create {
12048 +       uint64_t flagword;
12049 +};
12050 +
12051 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12052 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12053 +
12054 +struct vcmd_ctx_migrate {
12055 +       uint64_t flagword;
12056 +};
12057 +
12058 +
12059 +
12060 +/* flag commands */
12061 +
12062 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12063 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12064 +
12065 +struct vcmd_ctx_flags_v0 {
12066 +       uint64_t flagword;
12067 +       uint64_t mask;
12068 +};
12069 +
12070 +
12071 +
12072 +/* context caps commands */
12073 +
12074 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12075 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12076 +
12077 +struct vcmd_ctx_caps_v1 {
12078 +       uint64_t ccaps;
12079 +       uint64_t cmask;
12080 +};
12081 +
12082 +
12083 +
12084 +/* bcaps commands */
12085 +
12086 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12087 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12088 +
12089 +struct vcmd_bcaps {
12090 +       uint64_t bcaps;
12091 +       uint64_t bmask;
12092 +};
12093 +
12094 +
12095 +
12096 +/* umask commands */
12097 +
12098 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12099 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12100 +
12101 +struct vcmd_umask {
12102 +       uint64_t umask;
12103 +       uint64_t mask;
12104 +};
12105 +
12106 +
12107 +
12108 +/* wmask commands */
12109 +
12110 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12111 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12112 +
12113 +struct vcmd_wmask {
12114 +       uint64_t wmask;
12115 +       uint64_t mask;
12116 +};
12117 +
12118 +
12119 +
12120 +/* OOM badness */
12121 +
12122 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12123 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12124 +
12125 +struct vcmd_badness_v0 {
12126 +       int64_t bias;
12127 +};
12128 +
12129 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12130 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h
12131 --- linux-3.13.10/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12132 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h   2014-01-31 20:38:03.000000000 +0000
12133 @@ -0,0 +1,41 @@
12134 +#ifndef _UAPI_VS_CVIRT_CMD_H
12135 +#define _UAPI_VS_CVIRT_CMD_H
12136 +
12137 +
12138 +/* virtual host info name commands */
12139 +
12140 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12141 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12142 +
12143 +struct vcmd_vhi_name_v0 {
12144 +       uint32_t field;
12145 +       char name[65];
12146 +};
12147 +
12148 +
12149 +enum vhi_name_field {
12150 +       VHIN_CONTEXT = 0,
12151 +       VHIN_SYSNAME,
12152 +       VHIN_NODENAME,
12153 +       VHIN_RELEASE,
12154 +       VHIN_VERSION,
12155 +       VHIN_MACHINE,
12156 +       VHIN_DOMAINNAME,
12157 +};
12158 +
12159 +
12160 +
12161 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12162 +
12163 +struct vcmd_virt_stat_v0 {
12164 +       uint64_t offset;
12165 +       uint64_t uptime;
12166 +       uint32_t nr_threads;
12167 +       uint32_t nr_running;
12168 +       uint32_t nr_uninterruptible;
12169 +       uint32_t nr_onhold;
12170 +       uint32_t nr_forks;
12171 +       uint32_t load[3];
12172 +};
12173 +
12174 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12175 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h
12176 --- linux-3.13.10/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12177 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h   2014-01-31 20:38:03.000000000 +0000
12178 @@ -0,0 +1,24 @@
12179 +#ifndef _UAPI_VS_DEBUG_CMD_H
12180 +#define _UAPI_VS_DEBUG_CMD_H
12181 +
12182 +
12183 +/* debug commands */
12184 +
12185 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12186 +
12187 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12188 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12189 +
12190 +struct  vcmd_read_history_v0 {
12191 +       uint32_t index;
12192 +       uint32_t count;
12193 +       char __user *data;
12194 +};
12195 +
12196 +struct  vcmd_read_monitor_v0 {
12197 +       uint32_t index;
12198 +       uint32_t count;
12199 +       char __user *data;
12200 +};
12201 +
12202 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12203 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h
12204 --- linux-3.13.10/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12205 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h      2014-01-31 20:38:03.000000000 +0000
12206 @@ -0,0 +1,12 @@
12207 +#ifndef _UAPI_VS_DEVICE_H
12208 +#define _UAPI_VS_DEVICE_H
12209 +
12210 +
12211 +#define DATTR_CREATE   0x00000001
12212 +#define DATTR_OPEN     0x00000002
12213 +
12214 +#define DATTR_REMAP    0x00000010
12215 +
12216 +#define DATTR_MASK     0x00000013
12217 +
12218 +#endif /* _UAPI_VS_DEVICE_H */
12219 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h
12220 --- linux-3.13.10/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12221 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h  2014-01-31 20:38:03.000000000 +0000
12222 @@ -0,0 +1,16 @@
12223 +#ifndef _UAPI_VS_DEVICE_CMD_H
12224 +#define _UAPI_VS_DEVICE_CMD_H
12225 +
12226 +
12227 +/*  device vserver commands */
12228 +
12229 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12230 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12231 +
12232 +struct vcmd_set_mapping_v0 {
12233 +       const char __user *device;
12234 +       const char __user *target;
12235 +       uint32_t flags;
12236 +};
12237 +
12238 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12239 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h
12240 --- linux-3.13.10/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12241 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h  2014-01-31 20:38:03.000000000 +0000
12242 @@ -0,0 +1,67 @@
12243 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12244 +#define _UAPI_VS_DLIMIT_CMD_H
12245 +
12246 +
12247 +/*  dlimit vserver commands */
12248 +
12249 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12250 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12251 +
12252 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12253 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12254 +
12255 +struct vcmd_ctx_dlimit_base_v0 {
12256 +       const char __user *name;
12257 +       uint32_t flags;
12258 +};
12259 +
12260 +struct vcmd_ctx_dlimit_v0 {
12261 +       const char __user *name;
12262 +       uint32_t space_used;                    /* used space in kbytes */
12263 +       uint32_t space_total;                   /* maximum space in kbytes */
12264 +       uint32_t inodes_used;                   /* used inodes */
12265 +       uint32_t inodes_total;                  /* maximum inodes */
12266 +       uint32_t reserved;                      /* reserved for root in % */
12267 +       uint32_t flags;
12268 +};
12269 +
12270 +#define CDLIM_UNSET            ((uint32_t)0UL)
12271 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12272 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12273 +
12274 +#define DLIME_UNIT     0
12275 +#define DLIME_KILO     1
12276 +#define DLIME_MEGA     2
12277 +#define DLIME_GIGA     3
12278 +
12279 +#define DLIMF_SHIFT    0x10
12280 +
12281 +#define DLIMS_USED     0
12282 +#define DLIMS_TOTAL    2
12283 +
12284 +static inline
12285 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12286 +{
12287 +       int exp = (flags & DLIMF_SHIFT) ?
12288 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12289 +       return ((uint64_t)val) << (10 * exp);
12290 +}
12291 +
12292 +static inline
12293 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12294 +{
12295 +       int exp = 0;
12296 +
12297 +       if (*flags & DLIMF_SHIFT) {
12298 +               while (val > (1LL << 32) && (exp < 3)) {
12299 +                       val >>= 10;
12300 +                       exp++;
12301 +               }
12302 +               *flags &= ~(DLIME_GIGA << shift);
12303 +               *flags |= exp << shift;
12304 +       } else
12305 +               val >>= 10;
12306 +       return val;
12307 +}
12308 +
12309 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12310 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h
12311 --- linux-3.13.10/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12312 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h       2014-01-31 20:38:03.000000000 +0000
12313 @@ -0,0 +1,23 @@
12314 +#ifndef _UAPI_VS_INODE_H
12315 +#define _UAPI_VS_INODE_H
12316 +
12317 +
12318 +#define IATTR_TAG      0x01000000
12319 +
12320 +#define IATTR_ADMIN    0x00000001
12321 +#define IATTR_WATCH    0x00000002
12322 +#define IATTR_HIDE     0x00000004
12323 +#define IATTR_FLAGS    0x00000007
12324 +
12325 +#define IATTR_BARRIER  0x00010000
12326 +#define IATTR_IXUNLINK 0x00020000
12327 +#define IATTR_IMMUTABLE 0x00040000
12328 +#define IATTR_COW      0x00080000
12329 +
12330 +
12331 +/* inode ioctls */
12332 +
12333 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12334 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12335 +
12336 +#endif /* _UAPI_VS_INODE_H */
12337 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h
12338 --- linux-3.13.10/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12339 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h   2014-01-31 20:38:03.000000000 +0000
12340 @@ -0,0 +1,26 @@
12341 +#ifndef _UAPI_VS_INODE_CMD_H
12342 +#define _UAPI_VS_INODE_CMD_H
12343 +
12344 +
12345 +/*  inode vserver commands */
12346 +
12347 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12348 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12349 +
12350 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12351 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12352 +
12353 +struct vcmd_ctx_iattr_v1 {
12354 +       const char __user *name;
12355 +       uint32_t tag;
12356 +       uint32_t flags;
12357 +       uint32_t mask;
12358 +};
12359 +
12360 +struct vcmd_ctx_fiattr_v0 {
12361 +       uint32_t tag;
12362 +       uint32_t flags;
12363 +       uint32_t mask;
12364 +};
12365 +
12366 +#endif /* _UAPI_VS_INODE_CMD_H */
12367 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h
12368 --- linux-3.13.10/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12369 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h       2014-01-31 20:38:03.000000000 +0000
12370 @@ -0,0 +1,14 @@
12371 +#ifndef _UAPI_VS_LIMIT_H
12372 +#define _UAPI_VS_LIMIT_H
12373 +
12374 +
12375 +#define VLIMIT_NSOCK   16
12376 +#define VLIMIT_OPENFD  17
12377 +#define VLIMIT_ANON    18
12378 +#define VLIMIT_SHMEM   19
12379 +#define VLIMIT_SEMARY  20
12380 +#define VLIMIT_NSEMS   21
12381 +#define VLIMIT_DENTRY  22
12382 +#define VLIMIT_MAPPED  23
12383 +
12384 +#endif /* _UAPI_VS_LIMIT_H */
12385 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h
12386 --- linux-3.13.10/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12387 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h   2014-01-31 20:38:03.000000000 +0000
12388 @@ -0,0 +1,40 @@
12389 +#ifndef _UAPI_VS_LIMIT_CMD_H
12390 +#define _UAPI_VS_LIMIT_CMD_H
12391 +
12392 +
12393 +/*  rlimit vserver commands */
12394 +
12395 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12396 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12397 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12398 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12399 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12400 +
12401 +struct vcmd_ctx_rlimit_v0 {
12402 +       uint32_t id;
12403 +       uint64_t minimum;
12404 +       uint64_t softlimit;
12405 +       uint64_t maximum;
12406 +};
12407 +
12408 +struct vcmd_ctx_rlimit_mask_v0 {
12409 +       uint32_t minimum;
12410 +       uint32_t softlimit;
12411 +       uint32_t maximum;
12412 +};
12413 +
12414 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12415 +
12416 +struct vcmd_rlimit_stat_v0 {
12417 +       uint32_t id;
12418 +       uint32_t hits;
12419 +       uint64_t value;
12420 +       uint64_t minimum;
12421 +       uint64_t maximum;
12422 +};
12423 +
12424 +#define CRLIM_UNSET            (0ULL)
12425 +#define CRLIM_INFINITY         (~0ULL)
12426 +#define CRLIM_KEEP             (~1ULL)
12427 +
12428 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12429 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h
12430 --- linux-3.13.10/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12431 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h     2014-01-31 20:38:03.000000000 +0000
12432 @@ -0,0 +1,96 @@
12433 +#ifndef _UAPI_VS_MONITOR_H
12434 +#define _UAPI_VS_MONITOR_H
12435 +
12436 +#include <linux/types.h>
12437 +
12438 +
12439 +enum {
12440 +       VXM_UNUSED = 0,
12441 +
12442 +       VXM_SYNC = 0x10,
12443 +
12444 +       VXM_UPDATE = 0x20,
12445 +       VXM_UPDATE_1,
12446 +       VXM_UPDATE_2,
12447 +
12448 +       VXM_RQINFO_1 = 0x24,
12449 +       VXM_RQINFO_2,
12450 +
12451 +       VXM_ACTIVATE = 0x40,
12452 +       VXM_DEACTIVATE,
12453 +       VXM_IDLE,
12454 +
12455 +       VXM_HOLD = 0x44,
12456 +       VXM_UNHOLD,
12457 +
12458 +       VXM_MIGRATE = 0x48,
12459 +       VXM_RESCHED,
12460 +
12461 +       /* all other bits are flags */
12462 +       VXM_SCHED = 0x80,
12463 +};
12464 +
12465 +struct _vxm_update_1 {
12466 +       uint32_t tokens_max;
12467 +       uint32_t fill_rate;
12468 +       uint32_t interval;
12469 +};
12470 +
12471 +struct _vxm_update_2 {
12472 +       uint32_t tokens_min;
12473 +       uint32_t fill_rate;
12474 +       uint32_t interval;
12475 +};
12476 +
12477 +struct _vxm_rqinfo_1 {
12478 +       uint16_t running;
12479 +       uint16_t onhold;
12480 +       uint16_t iowait;
12481 +       uint16_t uintr;
12482 +       uint32_t idle_tokens;
12483 +};
12484 +
12485 +struct _vxm_rqinfo_2 {
12486 +       uint32_t norm_time;
12487 +       uint32_t idle_time;
12488 +       uint32_t idle_skip;
12489 +};
12490 +
12491 +struct _vxm_sched {
12492 +       uint32_t tokens;
12493 +       uint32_t norm_time;
12494 +       uint32_t idle_time;
12495 +};
12496 +
12497 +struct _vxm_task {
12498 +       uint16_t pid;
12499 +       uint16_t state;
12500 +};
12501 +
12502 +struct _vxm_event {
12503 +       uint32_t jif;
12504 +       union {
12505 +               uint32_t seq;
12506 +               uint32_t sec;
12507 +       };
12508 +       union {
12509 +               uint32_t tokens;
12510 +               uint32_t nsec;
12511 +               struct _vxm_task tsk;
12512 +       };
12513 +};
12514 +
12515 +struct _vx_mon_entry {
12516 +       uint16_t type;
12517 +       uint16_t xid;
12518 +       union {
12519 +               struct _vxm_event ev;
12520 +               struct _vxm_sched sd;
12521 +               struct _vxm_update_1 u1;
12522 +               struct _vxm_update_2 u2;
12523 +               struct _vxm_rqinfo_1 q1;
12524 +               struct _vxm_rqinfo_2 q2;
12525 +       };
12526 +};
12527 +
12528 +#endif /* _UAPI_VS_MONITOR_H */
12529 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h
12530 --- linux-3.13.10/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12531 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h     2014-01-31 20:38:03.000000000 +0000
12532 @@ -0,0 +1,76 @@
12533 +#ifndef _UAPI_VS_NETWORK_H
12534 +#define _UAPI_VS_NETWORK_H
12535 +
12536 +#include <linux/types.h>
12537 +
12538 +
12539 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12540 +
12541 +
12542 +/* network flags */
12543 +
12544 +#define NXF_INFO_PRIVATE       0x00000008
12545 +
12546 +#define NXF_SINGLE_IP          0x00000100
12547 +#define NXF_LBACK_REMAP                0x00000200
12548 +#define NXF_LBACK_ALLOW                0x00000400
12549 +
12550 +#define NXF_HIDE_NETIF         0x02000000
12551 +#define NXF_HIDE_LBACK         0x04000000
12552 +
12553 +#define NXF_STATE_SETUP                (1ULL << 32)
12554 +#define NXF_STATE_ADMIN                (1ULL << 34)
12555 +
12556 +#define NXF_SC_HELPER          (1ULL << 36)
12557 +#define NXF_PERSISTENT         (1ULL << 38)
12558 +
12559 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12560 +
12561 +
12562 +#define        NXF_INIT_SET            (__nxf_init_set())
12563 +
12564 +static inline uint64_t __nxf_init_set(void) {
12565 +       return    NXF_STATE_ADMIN
12566 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12567 +               | NXF_LBACK_REMAP
12568 +               | NXF_HIDE_LBACK
12569 +#endif
12570 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12571 +               | NXF_SINGLE_IP
12572 +#endif
12573 +               | NXF_HIDE_NETIF;
12574 +}
12575 +
12576 +
12577 +/* network caps */
12578 +
12579 +#define NXC_TUN_CREATE         0x00000001
12580 +
12581 +#define NXC_RAW_ICMP           0x00000100
12582 +
12583 +#define NXC_MULTICAST          0x00001000
12584 +
12585 +
12586 +/* address types */
12587 +
12588 +#define NXA_TYPE_IPV4          0x0001
12589 +#define NXA_TYPE_IPV6          0x0002
12590 +
12591 +#define NXA_TYPE_NONE          0x0000
12592 +#define NXA_TYPE_ANY           0x00FF
12593 +
12594 +#define NXA_TYPE_ADDR          0x0010
12595 +#define NXA_TYPE_MASK          0x0020
12596 +#define NXA_TYPE_RANGE         0x0040
12597 +
12598 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12599 +
12600 +#define NXA_MOD_BCAST          0x0100
12601 +#define NXA_MOD_LBACK          0x0200
12602 +
12603 +#define NXA_LOOPBACK           0x1000
12604 +
12605 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12606 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12607 +
12608 +#endif /* _UAPI_VS_NETWORK_H */
12609 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h
12610 --- linux-3.13.10/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12611 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12612 @@ -0,0 +1,123 @@
12613 +#ifndef _UAPI_VS_NETWORK_CMD_H
12614 +#define _UAPI_VS_NETWORK_CMD_H
12615 +
12616 +
12617 +/* vinfo commands */
12618 +
12619 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12620 +
12621 +
12622 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12623 +
12624 +struct vcmd_nx_info_v0 {
12625 +       uint32_t nid;
12626 +       /* more to come */
12627 +};
12628 +
12629 +
12630 +#include <linux/in.h>
12631 +#include <linux/in6.h>
12632 +
12633 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12634 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12635 +
12636 +struct  vcmd_net_create {
12637 +       uint64_t flagword;
12638 +};
12639 +
12640 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12641 +
12642 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12643 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12644 +
12645 +struct vcmd_net_addr_v0 {
12646 +       uint16_t type;
12647 +       uint16_t count;
12648 +       struct in_addr ip[4];
12649 +       struct in_addr mask[4];
12650 +};
12651 +
12652 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12653 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12654 +
12655 +struct vcmd_net_addr_ipv4_v1 {
12656 +       uint16_t type;
12657 +       uint16_t flags;
12658 +       struct in_addr ip;
12659 +       struct in_addr mask;
12660 +};
12661 +
12662 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12663 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12664 +
12665 +struct vcmd_net_addr_ipv4_v2 {
12666 +       uint16_t type;
12667 +       uint16_t flags;
12668 +       struct in_addr ip;
12669 +       struct in_addr ip2;
12670 +       struct in_addr mask;
12671 +};
12672 +
12673 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12674 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12675 +
12676 +struct vcmd_net_addr_ipv6_v1 {
12677 +       uint16_t type;
12678 +       uint16_t flags;
12679 +       uint32_t prefix;
12680 +       struct in6_addr ip;
12681 +       struct in6_addr mask;
12682 +};
12683 +
12684 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12685 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12686 +
12687 +struct vcmd_match_ipv4_v0 {
12688 +       uint16_t type;
12689 +       uint16_t flags;
12690 +       uint16_t parent;
12691 +       uint16_t prefix;
12692 +       struct in_addr ip;
12693 +       struct in_addr ip2;
12694 +       struct in_addr mask;
12695 +};
12696 +
12697 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12698 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12699 +
12700 +struct vcmd_match_ipv6_v0 {
12701 +       uint16_t type;
12702 +       uint16_t flags;
12703 +       uint16_t parent;
12704 +       uint16_t prefix;
12705 +       struct in6_addr ip;
12706 +       struct in6_addr ip2;
12707 +       struct in6_addr mask;
12708 +};
12709 +
12710 +
12711 +
12712 +
12713 +/* flag commands */
12714 +
12715 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12716 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12717 +
12718 +struct vcmd_net_flags_v0 {
12719 +       uint64_t flagword;
12720 +       uint64_t mask;
12721 +};
12722 +
12723 +
12724 +
12725 +/* network caps commands */
12726 +
12727 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12728 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12729 +
12730 +struct vcmd_net_caps_v0 {
12731 +       uint64_t ncaps;
12732 +       uint64_t cmask;
12733 +};
12734 +
12735 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12736 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h
12737 --- linux-3.13.10/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12738 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h   2014-01-31 20:38:03.000000000 +0000
12739 @@ -0,0 +1,13 @@
12740 +#ifndef _UAPI_VS_SCHED_CMD_H
12741 +#define _UAPI_VS_SCHED_CMD_H
12742 +
12743 +
12744 +struct vcmd_prio_bias {
12745 +       int32_t cpu_id;
12746 +       int32_t prio_bias;
12747 +};
12748 +
12749 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12750 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12751 +
12752 +#endif /* _UAPI_VS_SCHED_CMD_H */
12753 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h
12754 --- linux-3.13.10/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12755 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h  2014-01-31 20:38:03.000000000 +0000
12756 @@ -0,0 +1,31 @@
12757 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12758 +#define _UAPI_VS_SIGNAL_CMD_H
12759 +
12760 +
12761 +/*  signalling vserver commands */
12762 +
12763 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12764 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12765 +
12766 +struct vcmd_ctx_kill_v0 {
12767 +       int32_t pid;
12768 +       int32_t sig;
12769 +};
12770 +
12771 +struct vcmd_wait_exit_v0 {
12772 +       int32_t reboot_cmd;
12773 +       int32_t exit_code;
12774 +};
12775 +
12776 +
12777 +/*  process alteration commands */
12778 +
12779 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12780 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12781 +
12782 +struct vcmd_pflags_v0 {
12783 +       uint32_t flagword;
12784 +       uint32_t mask;
12785 +};
12786 +
12787 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12788 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h
12789 --- linux-3.13.10/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12790 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h   2014-01-31 20:38:03.000000000 +0000
12791 @@ -0,0 +1,28 @@
12792 +#ifndef _UAPI_VS_SPACE_CMD_H
12793 +#define _UAPI_VS_SPACE_CMD_H
12794 +
12795 +
12796 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12797 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12798 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12799 +
12800 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12801 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12802 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12803 +
12804 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12805 +
12806 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12807 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12808 +
12809 +
12810 +struct vcmd_space_mask_v1 {
12811 +       uint64_t mask;
12812 +};
12813 +
12814 +struct vcmd_space_mask_v2 {
12815 +       uint64_t mask;
12816 +       uint32_t index;
12817 +};
12818 +
12819 +#endif /* _UAPI_VS_SPACE_CMD_H */
12820 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h
12821 --- linux-3.13.10/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12822 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h      2014-01-31 20:38:03.000000000 +0000
12823 @@ -0,0 +1,90 @@
12824 +#ifndef _UAPI_VS_SWITCH_H
12825 +#define _UAPI_VS_SWITCH_H
12826 +
12827 +#include <linux/types.h>
12828 +
12829 +
12830 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12831 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12832 +#define VC_VERSION(c)          ((c) & 0xFFF)
12833 +
12834 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12835 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12836 +
12837 +/*
12838 +
12839 +  Syscall Matrix V2.8
12840 +
12841 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12842 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12843 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12844 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12845 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12846 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12847 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12848 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12849 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12850 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12851 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12852 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12853 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12854 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12855 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12856 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12857 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12858 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12859 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12860 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12861 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12862 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12863 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12864 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12865 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12866 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12867 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12868 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12869 +
12870 +*/
12871 +
12872 +#define VC_CAT_VERSION         0
12873 +
12874 +#define VC_CAT_VSETUP          1
12875 +#define VC_CAT_VHOST           2
12876 +
12877 +#define VC_CAT_DEVICE          6
12878 +
12879 +#define VC_CAT_VPROC           9
12880 +#define VC_CAT_PROCALT         10
12881 +#define VC_CAT_PROCMIG         11
12882 +#define VC_CAT_PROCTRL         12
12883 +
12884 +#define VC_CAT_SCHED           14
12885 +#define VC_CAT_MEMCTRL         20
12886 +
12887 +#define VC_CAT_VNET            25
12888 +#define VC_CAT_NETALT          26
12889 +#define VC_CAT_NETMIG          27
12890 +#define VC_CAT_NETCTRL         28
12891 +
12892 +#define VC_CAT_TAGMIG          35
12893 +#define VC_CAT_DLIMIT          36
12894 +#define VC_CAT_INODE           38
12895 +
12896 +#define VC_CAT_VSTAT           40
12897 +#define VC_CAT_VINFO           46
12898 +#define VC_CAT_EVENT           48
12899 +
12900 +#define VC_CAT_FLAGS           52
12901 +#define VC_CAT_VSPACE          54
12902 +#define VC_CAT_DEBUG           56
12903 +#define VC_CAT_RLIMIT          60
12904 +
12905 +#define VC_CAT_SYSTEST         61
12906 +#define VC_CAT_COMPAT          63
12907 +
12908 +/*  query version */
12909 +
12910 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12911 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12912 +
12913 +#endif /* _UAPI_VS_SWITCH_H */
12914 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h
12915 --- linux-3.13.10/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12916 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h     2014-01-31 20:38:03.000000000 +0000
12917 @@ -0,0 +1,14 @@
12918 +#ifndef _UAPI_VS_TAG_CMD_H
12919 +#define _UAPI_VS_TAG_CMD_H
12920 +
12921 +
12922 +/* vinfo commands */
12923 +
12924 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12925 +
12926 +
12927 +/* context commands */
12928 +
12929 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12930 +
12931 +#endif /* _UAPI_VS_TAG_CMD_H */
12932 diff -NurpP --minimal linux-3.13.10/init/Kconfig linux-3.13.10-vs2.3.6.11/init/Kconfig
12933 --- linux-3.13.10/init/Kconfig  2014-04-17 01:12:39.000000000 +0000
12934 +++ linux-3.13.10-vs2.3.6.11/init/Kconfig       2014-04-17 01:17:11.000000000 +0000
12935 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12936  menuconfig CGROUPS
12937         boolean "Control Group support"
12938         select KERNFS
12939 +       default y
12940         help
12941           This option adds support for grouping sets of processes together, for
12942           use with process control subsystems such as Cpusets, CFS, memory
12943 @@ -1117,6 +1118,7 @@ config IPC_NS
12944  
12945  config USER_NS
12946         bool "User namespace"
12947 +       depends on VSERVER_DISABLED
12948         default n
12949         help
12950           This allows containers, i.e. vservers, to use user namespaces
12951 diff -NurpP --minimal linux-3.13.10/init/main.c linux-3.13.10-vs2.3.6.11/init/main.c
12952 --- linux-3.13.10/init/main.c   2014-01-22 20:39:12.000000000 +0000
12953 +++ linux-3.13.10-vs2.3.6.11/init/main.c        2014-01-31 20:38:03.000000000 +0000
12954 @@ -77,6 +77,7 @@
12955  #include <linux/sched_clock.h>
12956  #include <linux/context_tracking.h>
12957  #include <linux/random.h>
12958 +#include <linux/vserver/percpu.h>
12959  
12960  #include <asm/io.h>
12961  #include <asm/bugs.h>
12962 diff -NurpP --minimal linux-3.13.10/ipc/mqueue.c linux-3.13.10-vs2.3.6.11/ipc/mqueue.c
12963 --- linux-3.13.10/ipc/mqueue.c  2014-04-17 01:12:39.000000000 +0000
12964 +++ linux-3.13.10-vs2.3.6.11/ipc/mqueue.c       2014-03-12 15:51:08.000000000 +0000
12965 @@ -35,6 +35,8 @@
12966  #include <linux/ipc_namespace.h>
12967  #include <linux/user_namespace.h>
12968  #include <linux/slab.h>
12969 +#include <linux/vs_context.h>
12970 +#include <linux/vs_limit.h>
12971  
12972  #include <net/sock.h>
12973  #include "util.h"
12974 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
12975         struct pid* notify_owner;
12976         struct user_namespace *notify_user_ns;
12977         struct user_struct *user;       /* user who created, for accounting */
12978 +       struct vx_info *vxi;
12979         struct sock *notify_sock;
12980         struct sk_buff *notify_cookie;
12981  
12982 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
12983         if (S_ISREG(mode)) {
12984                 struct mqueue_inode_info *info;
12985                 unsigned long mq_bytes, mq_treesize;
12986 +               struct vx_info *vxi = current_vx_info();
12987  
12988                 inode->i_fop = &mqueue_file_operations;
12989                 inode->i_size = FILENT_SIZE;
12990 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
12991                 info->notify_user_ns = NULL;
12992                 info->qsize = 0;
12993                 info->user = NULL;      /* set when all is ok */
12994 +               info->vxi = NULL;
12995                 info->msg_tree = RB_ROOT;
12996                 info->node_cache = NULL;
12997                 memset(&info->attr, 0, sizeof(info->attr));
12998 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
12999  
13000                 spin_lock(&mq_lock);
13001                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13002 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13003 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13004 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13005                         spin_unlock(&mq_lock);
13006                         /* mqueue_evict_inode() releases info->messages */
13007                         ret = -EMFILE;
13008                         goto out_inode;
13009                 }
13010                 u->mq_bytes += mq_bytes;
13011 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13012                 spin_unlock(&mq_lock);
13013  
13014                 /* all is ok */
13015                 info->user = get_uid(u);
13016 +               info->vxi = get_vx_info(vxi);
13017         } else if (S_ISDIR(mode)) {
13018                 inc_nlink(inode);
13019                 /* Some things misbehave if size == 0 on a directory */
13020 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13021  
13022         user = info->user;
13023         if (user) {
13024 +               struct vx_info *vxi = info->vxi;
13025 +
13026                 spin_lock(&mq_lock);
13027                 user->mq_bytes -= mq_bytes;
13028 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13029                 /*
13030                  * get_ns_from_inode() ensures that the
13031                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13032 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13033                 if (ipc_ns)
13034                         ipc_ns->mq_queues_count--;
13035                 spin_unlock(&mq_lock);
13036 +               put_vx_info(vxi);
13037                 free_uid(user);
13038         }
13039         if (ipc_ns)
13040 diff -NurpP --minimal linux-3.13.10/ipc/msg.c linux-3.13.10-vs2.3.6.11/ipc/msg.c
13041 --- linux-3.13.10/ipc/msg.c     2014-04-17 01:12:39.000000000 +0000
13042 +++ linux-3.13.10-vs2.3.6.11/ipc/msg.c  2014-04-17 01:17:11.000000000 +0000
13043 @@ -37,6 +37,7 @@
13044  #include <linux/rwsem.h>
13045  #include <linux/nsproxy.h>
13046  #include <linux/ipc_namespace.h>
13047 +#include <linux/vs_base.h>
13048  
13049  #include <asm/current.h>
13050  #include <asm/uaccess.h>
13051 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13052  
13053         msq->q_perm.mode = msgflg & S_IRWXUGO;
13054         msq->q_perm.key = key;
13055 +       msq->q_perm.xid = vx_current_xid();
13056  
13057         msq->q_perm.security = NULL;
13058         retval = security_msg_queue_alloc(msq);
13059 diff -NurpP --minimal linux-3.13.10/ipc/sem.c linux-3.13.10-vs2.3.6.11/ipc/sem.c
13060 --- linux-3.13.10/ipc/sem.c     2013-11-25 15:47:03.000000000 +0000
13061 +++ linux-3.13.10-vs2.3.6.11/ipc/sem.c  2014-01-31 20:38:03.000000000 +0000
13062 @@ -86,6 +86,8 @@
13063  #include <linux/rwsem.h>
13064  #include <linux/nsproxy.h>
13065  #include <linux/ipc_namespace.h>
13066 +#include <linux/vs_base.h>
13067 +#include <linux/vs_limit.h>
13068  
13069  #include <asm/uaccess.h>
13070  #include "util.h"
13071 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13072  
13073         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13074         sma->sem_perm.key = key;
13075 +       sma->sem_perm.xid = vx_current_xid();
13076  
13077         sma->sem_perm.security = NULL;
13078         retval = security_sem_alloc(sma);
13079 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13080                 return id;
13081         }
13082         ns->used_sems += nsems;
13083 +       /* FIXME: obsoleted? */
13084 +       vx_semary_inc(sma);
13085 +       vx_nsems_add(sma, nsems);
13086  
13087         sma->sem_base = (struct sem *) &sma[1];
13088  
13089 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13090  
13091         wake_up_sem_queue_do(&tasks);
13092         ns->used_sems -= sma->sem_nsems;
13093 +       /* FIXME: obsoleted? */
13094 +       vx_nsems_sub(sma, sma->sem_nsems);
13095 +       vx_semary_dec(sma);
13096         ipc_rcu_putref(sma, sem_rcu_free);
13097  }
13098  
13099 diff -NurpP --minimal linux-3.13.10/ipc/shm.c linux-3.13.10-vs2.3.6.11/ipc/shm.c
13100 --- linux-3.13.10/ipc/shm.c     2014-01-22 20:39:12.000000000 +0000
13101 +++ linux-3.13.10-vs2.3.6.11/ipc/shm.c  2014-01-31 20:38:03.000000000 +0000
13102 @@ -42,6 +42,8 @@
13103  #include <linux/nsproxy.h>
13104  #include <linux/mount.h>
13105  #include <linux/ipc_namespace.h>
13106 +#include <linux/vs_context.h>
13107 +#include <linux/vs_limit.h>
13108  
13109  #include <asm/uaccess.h>
13110  
13111 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13112  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13113  {
13114         struct file *shm_file;
13115 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13116 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13117  
13118         shm_file = shp->shm_file;
13119         shp->shm_file = NULL;
13120 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13121 +       vx_ipcshm_sub(vxi, shp, numpages);
13122 +       ns->shm_tot -= numpages;
13123 +
13124         shm_rmid(ns, shp);
13125         shm_unlock(shp);
13126         if (!is_file_hugepages(shm_file))
13127 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13128         else if (shp->mlock_user)
13129                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13130         fput(shm_file);
13131 +       put_vx_info(vxi);
13132         ipc_rcu_putref(shp, shm_rcu_free);
13133  }
13134  
13135 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13136         if (ns->shm_tot + numpages > ns->shm_ctlall)
13137                 return -ENOSPC;
13138  
13139 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13140 +               return -ENOSPC;
13141 +
13142         shp = ipc_rcu_alloc(sizeof(*shp));
13143         if (!shp)
13144                 return -ENOMEM;
13145  
13146         shp->shm_perm.key = key;
13147 +       shp->shm_perm.xid = vx_current_xid();
13148         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13149         shp->mlock_user = NULL;
13150  
13151 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13152  
13153         ipc_unlock_object(&shp->shm_perm);
13154         rcu_read_unlock();
13155 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13156         return error;
13157  
13158  no_id:
13159 diff -NurpP --minimal linux-3.13.10/kernel/Makefile linux-3.13.10-vs2.3.6.11/kernel/Makefile
13160 --- linux-3.13.10/kernel/Makefile       2014-01-22 20:39:12.000000000 +0000
13161 +++ linux-3.13.10-vs2.3.6.11/kernel/Makefile    2014-01-31 21:36:22.000000000 +0000
13162 @@ -25,6 +25,7 @@ obj-y += printk/
13163  obj-y += cpu/
13164  obj-y += irq/
13165  obj-y += rcu/
13166 +obj-y += vserver/
13167  
13168  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13169  obj-$(CONFIG_FREEZER) += freezer.o
13170 diff -NurpP --minimal linux-3.13.10/kernel/auditsc.c linux-3.13.10-vs2.3.6.11/kernel/auditsc.c
13171 --- linux-3.13.10/kernel/auditsc.c      2014-04-17 01:12:39.000000000 +0000
13172 +++ linux-3.13.10-vs2.3.6.11/kernel/auditsc.c   2014-04-17 01:17:11.000000000 +0000
13173 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13174         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13175                 return -EPERM;
13176         /* it is set, you need permission */
13177 -       if (!capable(CAP_AUDIT_CONTROL))
13178 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13179                 return -EPERM;
13180         /* reject if this is not an unset and we don't allow that */
13181         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13182 diff -NurpP --minimal linux-3.13.10/kernel/capability.c linux-3.13.10-vs2.3.6.11/kernel/capability.c
13183 --- linux-3.13.10/kernel/capability.c   2013-11-25 15:47:03.000000000 +0000
13184 +++ linux-3.13.10-vs2.3.6.11/kernel/capability.c        2014-01-31 20:38:03.000000000 +0000
13185 @@ -15,6 +15,7 @@
13186  #include <linux/syscalls.h>
13187  #include <linux/pid_namespace.h>
13188  #include <linux/user_namespace.h>
13189 +#include <linux/vs_context.h>
13190  #include <asm/uaccess.h>
13191  
13192  /*
13193 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13194         return 0;
13195  }
13196  
13197 +
13198  /*
13199   * The only thing that can change the capabilities of the current
13200   * process is the current process. As such, we can't be in this code
13201 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13202         return (ret == 0);
13203  }
13204  
13205 +#include <linux/vserver/base.h>
13206 +
13207  /**
13208   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13209   * initial user ns
13210 diff -NurpP --minimal linux-3.13.10/kernel/compat.c linux-3.13.10-vs2.3.6.11/kernel/compat.c
13211 --- linux-3.13.10/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13212 +++ linux-3.13.10-vs2.3.6.11/kernel/compat.c    2014-01-31 20:38:03.000000000 +0000
13213 @@ -27,6 +27,7 @@
13214  #include <linux/times.h>
13215  #include <linux/ptrace.h>
13216  #include <linux/gfp.h>
13217 +#include <linux/vs_time.h>
13218  
13219  #include <asm/uaccess.h>
13220  
13221 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13222         if (err)
13223                 return err;
13224  
13225 -       do_settimeofday(&tv);
13226 +       vx_settimeofday(&tv);
13227         return 0;
13228  }
13229  
13230 diff -NurpP --minimal linux-3.13.10/kernel/cred.c linux-3.13.10-vs2.3.6.11/kernel/cred.c
13231 --- linux-3.13.10/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13232 +++ linux-3.13.10-vs2.3.6.11/kernel/cred.c      2014-01-31 20:38:03.000000000 +0000
13233 @@ -56,31 +56,6 @@ struct cred init_cred = {
13234         .group_info             = &init_groups,
13235  };
13236  
13237 -static inline void set_cred_subscribers(struct cred *cred, int n)
13238 -{
13239 -#ifdef CONFIG_DEBUG_CREDENTIALS
13240 -       atomic_set(&cred->subscribers, n);
13241 -#endif
13242 -}
13243 -
13244 -static inline int read_cred_subscribers(const struct cred *cred)
13245 -{
13246 -#ifdef CONFIG_DEBUG_CREDENTIALS
13247 -       return atomic_read(&cred->subscribers);
13248 -#else
13249 -       return 0;
13250 -#endif
13251 -}
13252 -
13253 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13254 -{
13255 -#ifdef CONFIG_DEBUG_CREDENTIALS
13256 -       struct cred *cred = (struct cred *) _cred;
13257 -
13258 -       atomic_add(n, &cred->subscribers);
13259 -#endif
13260 -}
13261 -
13262  /*
13263   * The RCU callback to actually dispose of a set of credentials
13264   */
13265 @@ -232,21 +207,16 @@ error:
13266   *
13267   * Call commit_creds() or abort_creds() to clean up.
13268   */
13269 -struct cred *prepare_creds(void)
13270 +struct cred *__prepare_creds(const struct cred *old)
13271  {
13272 -       struct task_struct *task = current;
13273 -       const struct cred *old;
13274         struct cred *new;
13275  
13276 -       validate_process_creds();
13277 -
13278         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13279         if (!new)
13280                 return NULL;
13281  
13282         kdebug("prepare_creds() alloc %p", new);
13283  
13284 -       old = task->cred;
13285         memcpy(new, old, sizeof(struct cred));
13286  
13287         atomic_set(&new->usage, 1);
13288 @@ -275,6 +245,13 @@ error:
13289         abort_creds(new);
13290         return NULL;
13291  }
13292 +
13293 +struct cred *prepare_creds(void)
13294 +{
13295 +       validate_process_creds();
13296 +
13297 +       return __prepare_creds(current->cred);
13298 +}
13299  EXPORT_SYMBOL(prepare_creds);
13300  
13301  /*
13302 diff -NurpP --minimal linux-3.13.10/kernel/exit.c linux-3.13.10-vs2.3.6.11/kernel/exit.c
13303 --- linux-3.13.10/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13304 +++ linux-3.13.10-vs2.3.6.11/kernel/exit.c      2014-01-31 20:38:03.000000000 +0000
13305 @@ -48,6 +48,10 @@
13306  #include <linux/fs_struct.h>
13307  #include <linux/init_task.h>
13308  #include <linux/perf_event.h>
13309 +#include <linux/vs_limit.h>
13310 +#include <linux/vs_context.h>
13311 +#include <linux/vs_network.h>
13312 +#include <linux/vs_pid.h>
13313  #include <trace/events/sched.h>
13314  #include <linux/hw_breakpoint.h>
13315  #include <linux/oom.h>
13316 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13317         __acquires(&tasklist_lock)
13318  {
13319         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13320 -       struct task_struct *thread;
13321 +       struct vx_info *vxi = task_get_vx_info(father);
13322 +       struct task_struct *thread = father;
13323 +       struct task_struct *reaper;
13324  
13325 -       thread = father;
13326         while_each_thread(father, thread) {
13327                 if (thread->flags & PF_EXITING)
13328                         continue;
13329                 if (unlikely(pid_ns->child_reaper == father))
13330                         pid_ns->child_reaper = thread;
13331 -               return thread;
13332 +               reaper = thread;
13333 +               goto out_put;
13334 +       }
13335 +
13336 +       reaper = pid_ns->child_reaper;
13337 +       if (vxi) {
13338 +               BUG_ON(!vxi->vx_reaper);
13339 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13340 +                   vxi->vx_reaper != father)
13341 +                       reaper = vxi->vx_reaper;
13342         }
13343  
13344         if (unlikely(pid_ns->child_reaper == father)) {
13345 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13346                 }
13347         }
13348  
13349 -       return pid_ns->child_reaper;
13350 +out_put:
13351 +       put_vx_info(vxi);
13352 +       return reaper;
13353  }
13354  
13355  /*
13356 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13357         list_for_each_entry_safe(p, n, &father->children, sibling) {
13358                 struct task_struct *t = p;
13359                 do {
13360 -                       t->real_parent = reaper;
13361 +                       struct task_struct *new_parent = reaper;
13362 +
13363 +                       if (unlikely(p == reaper))
13364 +                               new_parent = task_active_pid_ns(p)->child_reaper;
13365 +
13366 +                       t->real_parent = new_parent;
13367                         if (t->parent == father) {
13368                                 BUG_ON(t->ptrace);
13369 -                               t->parent = t->real_parent;
13370 +                               t->parent = new_parent;
13371                         }
13372                         if (t->pdeath_signal)
13373                                 group_send_sig_info(t->pdeath_signal,
13374 @@ -810,6 +831,9 @@ void do_exit(long code)
13375          */
13376         flush_ptrace_hw_breakpoint(tsk);
13377  
13378 +       /* needs to stay before exit_notify() */
13379 +       exit_vx_info_early(tsk, code);
13380 +
13381         exit_notify(tsk, group_dead);
13382  #ifdef CONFIG_NUMA
13383         task_lock(tsk);
13384 @@ -863,10 +887,15 @@ void do_exit(long code)
13385         smp_mb();
13386         raw_spin_unlock_wait(&tsk->pi_lock);
13387  
13388 +       /* needs to stay after exit_notify() */
13389 +       exit_vx_info(tsk, code);
13390 +       exit_nx_info(tsk);
13391 +
13392         /* causes final put_task_struct in finish_task_switch(). */
13393         tsk->state = TASK_DEAD;
13394         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13395         schedule();
13396 +       printk("bad task: %p [%lx]\n", current, current->state);
13397         BUG();
13398         /* Avoid "noreturn function does return".  */
13399         for (;;)
13400 diff -NurpP --minimal linux-3.13.10/kernel/fork.c linux-3.13.10-vs2.3.6.11/kernel/fork.c
13401 --- linux-3.13.10/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13402 +++ linux-3.13.10-vs2.3.6.11/kernel/fork.c      2014-01-31 20:38:03.000000000 +0000
13403 @@ -71,6 +71,9 @@
13404  #include <linux/uprobes.h>
13405  #include <linux/aio.h>
13406  #include <linux/compiler.h>
13407 +#include <linux/vs_context.h>
13408 +#include <linux/vs_network.h>
13409 +#include <linux/vs_limit.h>
13410  
13411  #include <asm/pgtable.h>
13412  #include <asm/pgalloc.h>
13413 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13414         arch_release_thread_info(tsk->stack);
13415         free_thread_info(tsk->stack);
13416         rt_mutex_debug_task_free(tsk);
13417 +       clr_vx_info(&tsk->vx_info);
13418 +       clr_nx_info(&tsk->nx_info);
13419         ftrace_graph_exit_task(tsk);
13420         put_seccomp_filter(tsk);
13421         arch_release_task_struct(tsk);
13422 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13423         if (likely(!mm_alloc_pgd(mm))) {
13424                 mm->def_flags = 0;
13425                 mmu_notifier_mm_init(mm);
13426 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
13427                 return mm;
13428         }
13429  
13430 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13431         destroy_context(mm);
13432         mmu_notifier_mm_destroy(mm);
13433         check_mm(mm);
13434 +       clr_vx_info(&mm->mm_vx_info);
13435         free_mm(mm);
13436  }
13437  EXPORT_SYMBOL_GPL(__mmdrop);
13438 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13439                 goto fail_nomem;
13440  
13441         memcpy(mm, oldmm, sizeof(*mm));
13442 +       mm->mm_vx_info = NULL;
13443         mm_init_cpumask(mm);
13444  
13445  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13446 @@ -851,6 +859,7 @@ fail_nocontext:
13447          * If init_new_context() failed, we cannot use mmput() to free the mm
13448          * because it calls destroy_context()
13449          */
13450 +       clr_vx_info(&mm->mm_vx_info);
13451         mm_free_pgd(mm);
13452         free_mm(mm);
13453         return NULL;
13454 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13455  {
13456         int retval;
13457         struct task_struct *p;
13458 +       struct vx_info *vxi;
13459 +       struct nx_info *nxi;
13460  
13461         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13462                 return ERR_PTR(-EINVAL);
13463 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13464         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13465         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13466  #endif
13467 +       init_vx_info(&p->vx_info, current_vx_info());
13468 +       init_nx_info(&p->nx_info, current_nx_info());
13469 +
13470         retval = -EAGAIN;
13471 +       if (!vx_nproc_avail(1))
13472 +               goto bad_fork_free;
13473         if (atomic_read(&p->real_cred->user->processes) >=
13474                         task_rlimit(p, RLIMIT_NPROC)) {
13475                 if (p->real_cred->user != INIT_USER &&
13476 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13477  
13478         total_forks++;
13479         spin_unlock(&current->sighand->siglock);
13480 +
13481 +       /* p is copy of current */
13482 +       vxi = p->vx_info;
13483 +       if (vxi) {
13484 +               claim_vx_info(vxi, p);
13485 +               atomic_inc(&vxi->cvirt.nr_threads);
13486 +               atomic_inc(&vxi->cvirt.total_forks);
13487 +               vx_nproc_inc(p);
13488 +       }
13489 +       nxi = p->nx_info;
13490 +       if (nxi)
13491 +               claim_nx_info(nxi, p);
13492         write_unlock_irq(&tasklist_lock);
13493         proc_fork_connector(p);
13494         cgroup_post_fork(p);
13495 diff -NurpP --minimal linux-3.13.10/kernel/kthread.c linux-3.13.10-vs2.3.6.11/kernel/kthread.c
13496 --- linux-3.13.10/kernel/kthread.c      2014-01-22 20:39:13.000000000 +0000
13497 +++ linux-3.13.10-vs2.3.6.11/kernel/kthread.c   2014-01-31 20:38:03.000000000 +0000
13498 @@ -18,6 +18,7 @@
13499  #include <linux/freezer.h>
13500  #include <linux/ptrace.h>
13501  #include <linux/uaccess.h>
13502 +#include <linux/vs_pid.h>
13503  #include <trace/events/sched.h>
13504  
13505  static DEFINE_SPINLOCK(kthread_create_lock);
13506 diff -NurpP --minimal linux-3.13.10/kernel/nsproxy.c linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c
13507 --- linux-3.13.10/kernel/nsproxy.c      2013-11-25 15:47:03.000000000 +0000
13508 +++ linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c   2014-02-01 00:17:43.000000000 +0000
13509 @@ -20,11 +20,14 @@
13510  #include <linux/mnt_namespace.h>
13511  #include <linux/utsname.h>
13512  #include <linux/pid_namespace.h>
13513 +#include <linux/vserver/global.h>
13514 +#include <linux/vserver/debug.h>
13515  #include <net/net_namespace.h>
13516  #include <linux/ipc_namespace.h>
13517  #include <linux/proc_ns.h>
13518  #include <linux/file.h>
13519  #include <linux/syscalls.h>
13520 +#include "../fs/mount.h"
13521  
13522  static struct kmem_cache *nsproxy_cachep;
13523  
13524 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13525         struct nsproxy *nsproxy;
13526  
13527         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13528 -       if (nsproxy)
13529 +       if (nsproxy) {
13530                 atomic_set(&nsproxy->count, 1);
13531 +               atomic_inc(&vs_global_nsproxy);
13532 +       }
13533 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13534         return nsproxy;
13535  }
13536  
13537 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13538   * Return the newly created nsproxy.  Do not attach this to the task,
13539   * leave it to the caller to do proper locking and attach it to task.
13540   */
13541 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13542 -       struct task_struct *tsk, struct user_namespace *user_ns,
13543 -       struct fs_struct *new_fs)
13544 +static struct nsproxy *unshare_namespaces(
13545 +       unsigned long flags,
13546 +       struct nsproxy *orig,
13547 +       struct fs_struct *new_fs,
13548 +       struct user_namespace *new_user,
13549 +       struct pid_namespace *new_pid)
13550  {
13551         struct nsproxy *new_nsp;
13552         int err;
13553 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13554         if (!new_nsp)
13555                 return ERR_PTR(-ENOMEM);
13556  
13557 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13558 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13559         if (IS_ERR(new_nsp->mnt_ns)) {
13560                 err = PTR_ERR(new_nsp->mnt_ns);
13561                 goto out_ns;
13562         }
13563  
13564 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13565 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13566         if (IS_ERR(new_nsp->uts_ns)) {
13567                 err = PTR_ERR(new_nsp->uts_ns);
13568                 goto out_uts;
13569         }
13570  
13571 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13572 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13573         if (IS_ERR(new_nsp->ipc_ns)) {
13574                 err = PTR_ERR(new_nsp->ipc_ns);
13575                 goto out_ipc;
13576         }
13577  
13578 -       new_nsp->pid_ns_for_children =
13579 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13580 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13581         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13582                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13583                 goto out_pid;
13584         }
13585  
13586 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13587 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13588         if (IS_ERR(new_nsp->net_ns)) {
13589                 err = PTR_ERR(new_nsp->net_ns);
13590                 goto out_net;
13591 @@ -117,6 +125,41 @@ out_ns:
13592         return ERR_PTR(err);
13593  }
13594  
13595 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13596 +       struct task_struct *tsk, struct user_namespace *user_ns,
13597 +       struct fs_struct *new_fs)
13598 +
13599 +{
13600 +       return unshare_namespaces(flags, tsk->nsproxy,
13601 +               new_fs, user_ns, task_active_pid_ns(tsk));
13602 +}
13603 +
13604 +/*
13605 + * copies the nsproxy, setting refcount to 1, and grabbing a
13606 + * reference to all contained namespaces.
13607 + */
13608 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13609 +{
13610 +       struct nsproxy *ns = create_nsproxy();
13611 +
13612 +       if (ns) {
13613 +               memcpy(ns, orig, sizeof(struct nsproxy));
13614 +               atomic_set(&ns->count, 1);
13615 +
13616 +               if (ns->mnt_ns)
13617 +                       get_mnt_ns(ns->mnt_ns);
13618 +               if (ns->uts_ns)
13619 +                       get_uts_ns(ns->uts_ns);
13620 +               if (ns->ipc_ns)
13621 +                       get_ipc_ns(ns->ipc_ns);
13622 +               if (ns->pid_ns_for_children)
13623 +                       get_pid_ns(ns->pid_ns_for_children);
13624 +               if (ns->net_ns)
13625 +                       get_net(ns->net_ns);
13626 +       }
13627 +       return ns;
13628 +}
13629 +
13630  /*
13631   * called from clone.  This now handles copy for nsproxy and all
13632   * namespaces therein.
13633 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13634  {
13635         struct nsproxy *old_ns = tsk->nsproxy;
13636         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13637 -       struct nsproxy *new_ns;
13638 +       struct nsproxy *new_ns = NULL;
13639 +
13640 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13641 +               flags, tsk, old_ns);
13642  
13643         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13644                               CLONE_NEWPID | CLONE_NEWNET)))) {
13645 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13646                 return 0;
13647         }
13648  
13649 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13650 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13651                 return -EPERM;
13652  
13653         /*
13654 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13655                 return  PTR_ERR(new_ns);
13656  
13657         tsk->nsproxy = new_ns;
13658 +       vxdprintk(VXD_CBIT(space, 3),
13659 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13660 +               flags, tsk, old_ns, new_ns);
13661         return 0;
13662  }
13663  
13664 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13665                 put_ipc_ns(ns->ipc_ns);
13666         if (ns->pid_ns_for_children)
13667                 put_pid_ns(ns->pid_ns_for_children);
13668 -       put_net(ns->net_ns);
13669 +       if (ns->net_ns)
13670 +               put_net(ns->net_ns);
13671 +       atomic_dec(&vs_global_nsproxy);
13672         kmem_cache_free(nsproxy_cachep, ns);
13673  }
13674  
13675 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13676         struct user_namespace *user_ns;
13677         int err = 0;
13678  
13679 +       vxdprintk(VXD_CBIT(space, 4),
13680 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13681 +               unshare_flags, current->nsproxy);
13682 +
13683         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13684                                CLONE_NEWNET | CLONE_NEWPID)))
13685                 return 0;
13686  
13687         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13688 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13689 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13690                 return -EPERM;
13691  
13692         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13693 diff -NurpP --minimal linux-3.13.10/kernel/pid.c linux-3.13.10-vs2.3.6.11/kernel/pid.c
13694 --- linux-3.13.10/kernel/pid.c  2013-11-25 15:47:03.000000000 +0000
13695 +++ linux-3.13.10-vs2.3.6.11/kernel/pid.c       2014-01-31 20:38:03.000000000 +0000
13696 @@ -38,6 +38,7 @@
13697  #include <linux/syscalls.h>
13698  #include <linux/proc_ns.h>
13699  #include <linux/proc_fs.h>
13700 +#include <linux/vs_pid.h>
13701  
13702  #define pid_hashfn(nr, ns)     \
13703         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13704 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13705  
13706  struct pid *find_vpid(int nr)
13707  {
13708 -       return find_pid_ns(nr, task_active_pid_ns(current));
13709 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13710  }
13711  EXPORT_SYMBOL_GPL(find_vpid);
13712  
13713 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13714  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13715  {
13716         struct task_struct *result = NULL;
13717 +
13718 +       if (type == PIDTYPE_REALPID)
13719 +               type = PIDTYPE_PID;
13720         if (pid) {
13721                 struct hlist_node *first;
13722                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13723 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13724         rcu_lockdep_assert(rcu_read_lock_held(),
13725                            "find_task_by_pid_ns() needs rcu_read_lock()"
13726                            " protection");
13727 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13728 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13729  }
13730  
13731  struct task_struct *find_task_by_vpid(pid_t vnr)
13732 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13733  }
13734  EXPORT_SYMBOL_GPL(find_get_pid);
13735  
13736 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13737 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13738  {
13739         struct upid *upid;
13740         pid_t nr = 0;
13741 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13742  }
13743  EXPORT_SYMBOL_GPL(pid_nr_ns);
13744  
13745 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13746 +{
13747 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13748 +}
13749 +
13750  pid_t pid_vnr(struct pid *pid)
13751  {
13752         return pid_nr_ns(pid, task_active_pid_ns(current));
13753 diff -NurpP --minimal linux-3.13.10/kernel/pid_namespace.c linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c
13754 --- linux-3.13.10/kernel/pid_namespace.c        2014-01-22 20:39:13.000000000 +0000
13755 +++ linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c     2014-02-01 12:23:11.000000000 +0000
13756 @@ -18,6 +18,7 @@
13757  #include <linux/proc_ns.h>
13758  #include <linux/reboot.h>
13759  #include <linux/export.h>
13760 +#include <linux/vserver/global.h>
13761  
13762  struct pid_cache {
13763         int nr_ids;
13764 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13765                 goto out_free_map;
13766  
13767         kref_init(&ns->kref);
13768 +       atomic_inc(&vs_global_pid_ns);
13769         ns->level = level;
13770         ns->parent = get_pid_ns(parent_pid_ns);
13771         ns->user_ns = get_user_ns(user_ns);
13772 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13773  out_free_map:
13774         kfree(ns->pidmap[0].page);
13775  out_free:
13776 +       atomic_dec(&vs_global_pid_ns);
13777         kmem_cache_free(pid_ns_cachep, ns);
13778  out:
13779         return ERR_PTR(err);
13780 diff -NurpP --minimal linux-3.13.10/kernel/posix-timers.c linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c
13781 --- linux-3.13.10/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13782 +++ linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c      2014-01-31 20:38:03.000000000 +0000
13783 @@ -48,6 +48,7 @@
13784  #include <linux/workqueue.h>
13785  #include <linux/export.h>
13786  #include <linux/hashtable.h>
13787 +#include <linux/vs_context.h>
13788  
13789  /*
13790   * Management arrays for POSIX timers. Timers are now kept in static hash table
13791 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13792  {
13793         struct task_struct *task;
13794         int shared, ret = -1;
13795 +
13796         /*
13797          * FIXME: if ->sigq is queued we can race with
13798          * dequeue_signal()->do_schedule_next_timer().
13799 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13800         rcu_read_lock();
13801         task = pid_task(timr->it_pid, PIDTYPE_PID);
13802         if (task) {
13803 +               struct vx_info_save vxis;
13804 +               struct vx_info *vxi;
13805 +
13806 +               vxi = get_vx_info(task->vx_info);
13807 +               enter_vx_info(vxi, &vxis);
13808                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13809                 ret = send_sigqueue(timr->sigq, task, shared);
13810 +               leave_vx_info(&vxis);
13811 +               put_vx_info(vxi);
13812         }
13813         rcu_read_unlock();
13814 +
13815         /* If we failed to send the signal the timer stops. */
13816         return ret > 0;
13817  }
13818 diff -NurpP --minimal linux-3.13.10/kernel/printk/printk.c linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c
13819 --- linux-3.13.10/kernel/printk/printk.c        2014-04-17 01:12:39.000000000 +0000
13820 +++ linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c     2014-04-17 01:17:11.000000000 +0000
13821 @@ -45,6 +45,7 @@
13822  #include <linux/poll.h>
13823  #include <linux/irq_work.h>
13824  #include <linux/utsname.h>
13825 +#include <linux/vs_cvirt.h>
13826  
13827  #include <asm/uaccess.h>
13828  
13829 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13830                 return 0;
13831  
13832         if (syslog_action_restricted(type)) {
13833 -               if (capable(CAP_SYSLOG))
13834 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13835                         return 0;
13836                 /*
13837                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13838 @@ -1134,12 +1135,9 @@ int do_syslog(int type, char __user *buf
13839         if (error)
13840                 return error;
13841  
13842 -       switch (type) {
13843 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13844 -               break;
13845 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13846 -               break;
13847 -       case SYSLOG_ACTION_READ:        /* Read from log */
13848 +       if ((type == SYSLOG_ACTION_READ) ||
13849 +           (type == SYSLOG_ACTION_READ_ALL) ||
13850 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13851                 error = -EINVAL;
13852                 if (!buf || len < 0)
13853                         goto out;
13854 @@ -1150,6 +1148,16 @@ int do_syslog(int type, char __user *buf
13855                         error = -EFAULT;
13856                         goto out;
13857                 }
13858 +       }
13859 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13860 +               return vx_do_syslog(type, buf, len);
13861 +
13862 +       switch (type) {
13863 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13864 +               break;
13865 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13866 +               break;
13867 +       case SYSLOG_ACTION_READ:        /* Read from log */
13868                 error = wait_event_interruptible(log_wait,
13869                                                  syslog_seq != log_next_seq);
13870                 if (error)
13871 @@ -1162,16 +1170,6 @@ int do_syslog(int type, char __user *buf
13872                 /* FALL THRU */
13873         /* Read last kernel messages */
13874         case SYSLOG_ACTION_READ_ALL:
13875 -               error = -EINVAL;
13876 -               if (!buf || len < 0)
13877 -                       goto out;
13878 -               error = 0;
13879 -               if (!len)
13880 -                       goto out;
13881 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13882 -                       error = -EFAULT;
13883 -                       goto out;
13884 -               }
13885                 error = syslog_print_all(buf, len, clear);
13886                 break;
13887         /* Clear ring buffer */
13888 diff -NurpP --minimal linux-3.13.10/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/kernel/ptrace.c
13889 --- linux-3.13.10/kernel/ptrace.c       2014-01-22 20:39:13.000000000 +0000
13890 +++ linux-3.13.10-vs2.3.6.11/kernel/ptrace.c    2014-01-31 20:38:03.000000000 +0000
13891 @@ -23,6 +23,7 @@
13892  #include <linux/syscalls.h>
13893  #include <linux/uaccess.h>
13894  #include <linux/regset.h>
13895 +#include <linux/vs_context.h>
13896  #include <linux/hw_breakpoint.h>
13897  #include <linux/cn_proc.h>
13898  #include <linux/compat.h>
13899 @@ -264,6 +265,11 @@ ok:
13900         }
13901         rcu_read_unlock();
13902  
13903 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13904 +               return -EPERM;
13905 +       if (!vx_check(task->xid, VS_IDENT) &&
13906 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13907 +               return -EACCES;
13908         return security_ptrace_access_check(task, mode);
13909  }
13910  
13911 diff -NurpP --minimal linux-3.13.10/kernel/reboot.c linux-3.13.10-vs2.3.6.11/kernel/reboot.c
13912 --- linux-3.13.10/kernel/reboot.c       2014-01-22 20:39:13.000000000 +0000
13913 +++ linux-3.13.10-vs2.3.6.11/kernel/reboot.c    2014-02-01 00:19:40.000000000 +0000
13914 @@ -16,6 +16,7 @@
13915  #include <linux/syscalls.h>
13916  #include <linux/syscore_ops.h>
13917  #include <linux/uaccess.h>
13918 +#include <linux/vs_pid.h>
13919  
13920  /*
13921   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13922 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13923  
13924  static DEFINE_MUTEX(reboot_mutex);
13925  
13926 +long vs_reboot(unsigned int, void __user *);
13927 +
13928  /*
13929   * Reboot system call: for obvious reasons only root may call it,
13930   * and even root needs to set up some magic numbers in the registers
13931 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13932         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13933                 cmd = LINUX_REBOOT_CMD_HALT;
13934  
13935 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13936 +               return vs_reboot(cmd, arg);
13937 +
13938         mutex_lock(&reboot_mutex);
13939         switch (cmd) {
13940         case LINUX_REBOOT_CMD_RESTART:
13941 diff -NurpP --minimal linux-3.13.10/kernel/sched/core.c linux-3.13.10-vs2.3.6.11/kernel/sched/core.c
13942 --- linux-3.13.10/kernel/sched/core.c   2014-04-17 01:12:39.000000000 +0000
13943 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/core.c        2014-02-25 11:26:10.000000000 +0000
13944 @@ -73,6 +73,8 @@
13945  #include <linux/binfmts.h>
13946  #include <linux/context_tracking.h>
13947  #include <linux/compiler.h>
13948 +#include <linux/vs_sched.h>
13949 +#include <linux/vs_cvirt.h>
13950  
13951  #include <asm/switch_to.h>
13952  #include <asm/tlb.h>
13953 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13954                 nice = 19;
13955  
13956         if (increment < 0 && !can_nice(current, nice))
13957 -               return -EPERM;
13958 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13959  
13960         retval = security_task_setnice(current, nice);
13961         if (retval)
13962 diff -NurpP --minimal linux-3.13.10/kernel/sched/cputime.c linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c
13963 --- linux-3.13.10/kernel/sched/cputime.c        2013-11-25 15:47:03.000000000 +0000
13964 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c     2014-01-31 20:38:03.000000000 +0000
13965 @@ -4,6 +4,7 @@
13966  #include <linux/kernel_stat.h>
13967  #include <linux/static_key.h>
13968  #include <linux/context_tracking.h>
13969 +#include <linux/vs_sched.h>
13970  #include "sched.h"
13971  
13972  
13973 @@ -189,9 +193,12 @@ static inline
13974  void __account_system_time(struct task_struct *p, cputime_t cputime,
13975                         cputime_t cputime_scaled, int index)
13976  {
13977 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13978 +
13979         /* Add system time to process. */
13980         p->stime += cputime;
13981         p->stimescaled += cputime_scaled;
13982 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
13983         account_group_system_time(p, cputime);
13984  
13985         /* Add system time to cpustat. */
13986 @@ -215,14 +216,17 @@ static inline void task_group_account_fi
13987  void account_user_time(struct task_struct *p, cputime_t cputime,
13988                        cputime_t cputime_scaled)
13989  {
13990 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13991 +       int nice = (TASK_NICE(p) > 0);
13992         int index;
13993  
13994         /* Add user time to process. */
13995         p->utime += cputime;
13996         p->utimescaled += cputime_scaled;
13997 +       vx_account_user(vxi, cputime, nice);
13998         account_group_user_time(p, cputime);
13999  
14000 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14001 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14002  
14003         /* Add user time to cpustat. */
14004         task_group_account_field(p, index, (__force u64) cputime);
14005 diff -NurpP --minimal linux-3.13.10/kernel/sched/fair.c linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c
14006 --- linux-3.13.10/kernel/sched/fair.c   2014-04-17 01:12:40.000000000 +0000
14007 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c        2014-04-17 01:17:11.000000000 +0000
14008 @@ -29,6 +29,7 @@
14009  #include <linux/mempolicy.h>
14010  #include <linux/migrate.h>
14011  #include <linux/task_work.h>
14012 +#include <linux/vs_cvirt.h>
14013  
14014  #include <trace/events/sched.h>
14015  
14016 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14017                 __enqueue_entity(cfs_rq, se);
14018         se->on_rq = 1;
14019  
14020 +       if (entity_is_task(se))
14021 +               vx_activate_task(task_of(se));
14022         if (cfs_rq->nr_running == 1) {
14023                 list_add_leaf_cfs_rq(cfs_rq);
14024                 check_enqueue_throttle(cfs_rq);
14025 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14026         if (se != cfs_rq->curr)
14027                 __dequeue_entity(cfs_rq, se);
14028         se->on_rq = 0;
14029 +       if (entity_is_task(se))
14030 +               vx_deactivate_task(task_of(se));
14031         account_entity_dequeue(cfs_rq, se);
14032  
14033         /*
14034 diff -NurpP --minimal linux-3.13.10/kernel/sched/proc.c linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c
14035 --- linux-3.13.10/kernel/sched/proc.c   2013-11-25 15:45:08.000000000 +0000
14036 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c        2014-01-31 21:22:36.000000000 +0000
14037 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14038   */
14039  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14040  {
14041 -       loads[0] = (avenrun[0] + offset) << shift;
14042 -       loads[1] = (avenrun[1] + offset) << shift;
14043 -       loads[2] = (avenrun[2] + offset) << shift;
14044 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14045 +               struct vx_info *vxi = current_vx_info();
14046 +
14047 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14048 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14049 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14050 +       } else {
14051 +               loads[0] = (avenrun[0] + offset) << shift;
14052 +               loads[1] = (avenrun[1] + offset) << shift;
14053 +               loads[2] = (avenrun[2] + offset) << shift;
14054 +       }
14055  }
14056  
14057  long calc_load_fold_active(struct rq *this_rq)
14058 diff -NurpP --minimal linux-3.13.10/kernel/signal.c linux-3.13.10-vs2.3.6.11/kernel/signal.c
14059 --- linux-3.13.10/kernel/signal.c       2014-01-22 20:39:13.000000000 +0000
14060 +++ linux-3.13.10-vs2.3.6.11/kernel/signal.c    2014-01-31 20:38:03.000000000 +0000
14061 @@ -33,6 +33,8 @@
14062  #include <linux/compat.h>
14063  #include <linux/cn_proc.h>
14064  #include <linux/compiler.h>
14065 +#include <linux/vs_context.h>
14066 +#include <linux/vs_pid.h>
14067  
14068  #define CREATE_TRACE_POINTS
14069  #include <trace/events/signal.h>
14070 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14071         struct pid *sid;
14072         int error;
14073  
14074 +       vxdprintk(VXD_CBIT(misc, 7),
14075 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14076 +               sig, info, t, vx_task_xid(t), t->pid);
14077 +
14078         if (!valid_signal(sig))
14079                 return -EINVAL;
14080  
14081 +/*     FIXME: needed? if so, why?
14082 +       if ((info != SEND_SIG_NOINFO) &&
14083 +               (is_si_special(info) || !si_fromuser(info)))
14084 +               goto skip;      */
14085 +
14086         if (!si_fromuser(info))
14087                 return 0;
14088  
14089 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14090                 }
14091         }
14092  
14093 +       error = -EPERM;
14094 +       if (t->pid == 1 && current->xid)
14095 +               return error;
14096 +
14097 +       error = -ESRCH;
14098 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14099 +                 loops, maybe ENOENT or EACCES? */
14100 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14101 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14102 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14103 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14104 +               return error;
14105 +       }
14106 +/* skip: */
14107         return security_task_kill(t, info, sig, 0);
14108  }
14109  
14110 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14111         rcu_read_lock();
14112  retry:
14113         p = pid_task(pid, PIDTYPE_PID);
14114 -       if (p) {
14115 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14116                 error = group_send_sig_info(sig, info, p);
14117                 if (unlikely(error == -ESRCH))
14118                         /*
14119 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14120  
14121         rcu_read_lock();
14122         p = pid_task(pid, PIDTYPE_PID);
14123 -       if (!p) {
14124 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14125                 ret = -ESRCH;
14126                 goto out_unlock;
14127         }
14128 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14129                 struct task_struct * p;
14130  
14131                 for_each_process(p) {
14132 -                       if (task_pid_vnr(p) > 1 &&
14133 -                                       !same_thread_group(p, current)) {
14134 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14135 +                               task_pid_vnr(p) > 1 &&
14136 +                               !same_thread_group(p, current) &&
14137 +                               !vx_current_initpid(p->pid)) {
14138                                 int err = group_send_sig_info(sig, info, p);
14139                                 ++count;
14140                                 if (err != -EPERM)
14141 @@ -2308,6 +2335,11 @@ relock:
14142                                 !sig_kernel_only(signr))
14143                         continue;
14144  
14145 +               /* virtual init is protected against user signals */
14146 +               if ((info->si_code == SI_USER) &&
14147 +                       vx_current_initpid(current->pid))
14148 +                       continue;
14149 +
14150                 if (sig_kernel_stop(signr)) {
14151                         /*
14152                          * The default action is to stop all threads in
14153 diff -NurpP --minimal linux-3.13.10/kernel/softirq.c linux-3.13.10-vs2.3.6.11/kernel/softirq.c
14154 --- linux-3.13.10/kernel/softirq.c      2014-01-22 20:39:13.000000000 +0000
14155 +++ linux-3.13.10-vs2.3.6.11/kernel/softirq.c   2014-01-31 20:38:03.000000000 +0000
14156 @@ -23,6 +23,7 @@
14157  #include <linux/smpboot.h>
14158  #include <linux/tick.h>
14159  #include <linux/irq.h>
14160 +#include <linux/vs_context.h>
14161  
14162  #define CREATE_TRACE_POINTS
14163  #include <trace/events/irq.h>
14164 diff -NurpP --minimal linux-3.13.10/kernel/sys.c linux-3.13.10-vs2.3.6.11/kernel/sys.c
14165 --- linux-3.13.10/kernel/sys.c  2014-01-22 20:39:13.000000000 +0000
14166 +++ linux-3.13.10-vs2.3.6.11/kernel/sys.c       2014-02-01 00:19:29.000000000 +0000
14167 @@ -54,6 +54,7 @@
14168  #include <linux/cred.h>
14169  
14170  #include <linux/kmsg_dump.h>
14171 +#include <linux/vs_pid.h>
14172  /* Move somewhere else to avoid recompiling? */
14173  #include <generated/utsrelease.h>
14174  
14175 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14176                 goto out;
14177         }
14178         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14179 -               error = -EACCES;
14180 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14181 +                       error = 0;
14182 +               else
14183 +                       error = -EACCES;
14184                 goto out;
14185         }
14186         no_nice = security_task_setnice(p, niceval);
14187 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14188                         else
14189                                 pgrp = task_pgrp(current);
14190                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14191 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14192 +                                       continue;
14193                                 error = set_one_prio(p, niceval, error);
14194                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14195                         break;
14196 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14197                         else
14198                                 pgrp = task_pgrp(current);
14199                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14200 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14201 +                                       continue;
14202                                 niceval = 20 - task_nice(p);
14203                                 if (niceval > retval)
14204                                         retval = niceval;
14205 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14206         int errno;
14207         char tmp[__NEW_UTS_LEN];
14208  
14209 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14210 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14211 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14212                 return -EPERM;
14213  
14214         if (len < 0 || len > __NEW_UTS_LEN)
14215 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14216         int errno;
14217         char tmp[__NEW_UTS_LEN];
14218  
14219 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14220 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14221 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14222                 return -EPERM;
14223         if (len < 0 || len > __NEW_UTS_LEN)
14224                 return -EINVAL;
14225 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14226                 /* Keep the capable check against init_user_ns until
14227                    cgroups can contain all limits */
14228                 if (new_rlim->rlim_max > rlim->rlim_max &&
14229 -                               !capable(CAP_SYS_RESOURCE))
14230 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14231                         retval = -EPERM;
14232                 if (!retval)
14233                         retval = security_task_setrlimit(tsk->group_leader,
14234 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14235             gid_eq(cred->gid, tcred->sgid) &&
14236             gid_eq(cred->gid, tcred->gid))
14237                 return 0;
14238 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14239 +       if (vx_ns_capable(tcred->user_ns,
14240 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14241                 return 0;
14242  
14243         return -EPERM;
14244 diff -NurpP --minimal linux-3.13.10/kernel/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/sysctl.c
14245 --- linux-3.13.10/kernel/sysctl.c       2014-04-17 01:12:40.000000000 +0000
14246 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl.c    2014-02-25 11:26:10.000000000 +0000
14247 @@ -83,6 +83,7 @@
14248  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14249  #include <linux/lockdep.h>
14250  #endif
14251 +extern char vshelper_path[];
14252  #ifdef CONFIG_CHR_DEV_SG
14253  #include <scsi/sg.h>
14254  #endif
14255 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14256                 .mode           = 0644,
14257                 .proc_handler   = proc_dostring,
14258         },
14259 +       {
14260 +               .procname       = "vshelper",
14261 +               .data           = &vshelper_path,
14262 +               .maxlen         = 256,
14263 +               .mode           = 0644,
14264 +               .proc_handler   = &proc_dostring,
14265 +       },
14266  
14267  #ifdef CONFIG_CHR_DEV_SG
14268         {
14269 diff -NurpP --minimal linux-3.13.10/kernel/sysctl_binary.c linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c
14270 --- linux-3.13.10/kernel/sysctl_binary.c        2014-01-22 20:39:13.000000000 +0000
14271 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c     2014-01-31 20:38:03.000000000 +0000
14272 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14273  
14274         { CTL_INT,      KERN_PANIC,                     "panic" },
14275         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14276 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14277  
14278         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14279         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14280 diff -NurpP --minimal linux-3.13.10/kernel/time/timekeeping.c linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c
14281 --- linux-3.13.10/kernel/time/timekeeping.c     2014-04-17 01:12:40.000000000 +0000
14282 +++ linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c  2014-02-25 11:26:10.000000000 +0000
14283 @@ -22,6 +22,7 @@
14284  #include <linux/stop_machine.h>
14285  #include <linux/pvclock_gtod.h>
14286  #include <linux/compiler.h>
14287 +#include <linux/vs_time.h>
14288  
14289  #include "tick-internal.h"
14290  #include "ntp_internal.h"
14291 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14292         } while (read_seqcount_retry(&timekeeper_seq, seq));
14293  
14294         timespec_add_ns(ts, nsecs);
14295 +       vx_adjust_timespec(ts);
14296  }
14297  EXPORT_SYMBOL(getrawmonotonic);
14298  
14299 diff -NurpP --minimal linux-3.13.10/kernel/time.c linux-3.13.10-vs2.3.6.11/kernel/time.c
14300 --- linux-3.13.10/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14301 +++ linux-3.13.10-vs2.3.6.11/kernel/time.c      2014-01-31 20:38:03.000000000 +0000
14302 @@ -37,6 +37,7 @@
14303  #include <linux/fs.h>
14304  #include <linux/math64.h>
14305  #include <linux/ptrace.h>
14306 +#include <linux/vs_time.h>
14307  
14308  #include <asm/uaccess.h>
14309  #include <asm/unistd.h>
14310 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14311         if (err)
14312                 return err;
14313  
14314 -       do_settimeofday(&tv);
14315 +       vx_settimeofday(&tv);
14316         return 0;
14317  }
14318  
14319 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14320                 }
14321         }
14322         if (tv)
14323 -               return do_settimeofday(tv);
14324 +               return vx_settimeofday(tv);
14325         return 0;
14326  }
14327  
14328 diff -NurpP --minimal linux-3.13.10/kernel/timer.c linux-3.13.10-vs2.3.6.11/kernel/timer.c
14329 --- linux-3.13.10/kernel/timer.c        2014-01-22 20:39:13.000000000 +0000
14330 +++ linux-3.13.10-vs2.3.6.11/kernel/timer.c     2014-01-31 20:38:03.000000000 +0000
14331 @@ -42,6 +42,10 @@
14332  #include <linux/sched/sysctl.h>
14333  #include <linux/slab.h>
14334  #include <linux/compat.h>
14335 +#include <linux/vs_base.h>
14336 +#include <linux/vs_cvirt.h>
14337 +#include <linux/vs_pid.h>
14338 +#include <linux/vserver/sched.h>
14339  
14340  #include <asm/uaccess.h>
14341  #include <asm/unistd.h>
14342 diff -NurpP --minimal linux-3.13.10/kernel/user_namespace.c linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c
14343 --- linux-3.13.10/kernel/user_namespace.c       2014-01-22 20:39:13.000000000 +0000
14344 +++ linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c    2014-01-31 20:38:03.000000000 +0000
14345 @@ -22,6 +22,7 @@
14346  #include <linux/ctype.h>
14347  #include <linux/projid.h>
14348  #include <linux/fs_struct.h>
14349 +#include <linux/vserver/global.h>
14350  
14351  static struct kmem_cache *user_ns_cachep __read_mostly;
14352  
14353 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14354  
14355         atomic_set(&ns->count, 1);
14356         /* Leave the new->user_ns reference with the new user namespace. */
14357 +       atomic_inc(&vs_global_user_ns);
14358         ns->parent = parent_ns;
14359         ns->level = parent_ns->level + 1;
14360         ns->owner = owner;
14361 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14362  
14363  static void userns_put(void *ns)
14364  {
14365 +       /* FIXME: maybe move into destroyer? */
14366 +       atomic_dec(&vs_global_user_ns);
14367         put_user_ns(ns);
14368  }
14369  
14370 diff -NurpP --minimal linux-3.13.10/kernel/utsname.c linux-3.13.10-vs2.3.6.11/kernel/utsname.c
14371 --- linux-3.13.10/kernel/utsname.c      2013-11-25 15:47:03.000000000 +0000
14372 +++ linux-3.13.10-vs2.3.6.11/kernel/utsname.c   2014-01-31 20:38:03.000000000 +0000
14373 @@ -16,14 +16,17 @@
14374  #include <linux/slab.h>
14375  #include <linux/user_namespace.h>
14376  #include <linux/proc_ns.h>
14377 +#include <linux/vserver/global.h>
14378  
14379  static struct uts_namespace *create_uts_ns(void)
14380  {
14381         struct uts_namespace *uts_ns;
14382  
14383         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14384 -       if (uts_ns)
14385 +       if (uts_ns) {
14386                 kref_init(&uts_ns->kref);
14387 +               atomic_inc(&vs_global_uts_ns);
14388 +       }
14389         return uts_ns;
14390  }
14391  
14392 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14393         ns = container_of(kref, struct uts_namespace, kref);
14394         put_user_ns(ns->user_ns);
14395         proc_free_inum(ns->proc_inum);
14396 +       atomic_dec(&vs_global_uts_ns);
14397         kfree(ns);
14398  }
14399  
14400 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Kconfig linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig
14401 --- linux-3.13.10/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14402 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig     2014-01-31 20:38:03.000000000 +0000
14403 @@ -0,0 +1,230 @@
14404 +#
14405 +# Linux VServer configuration
14406 +#
14407 +
14408 +menu "Linux VServer"
14409 +
14410 +config VSERVER_AUTO_LBACK
14411 +       bool    "Automatically Assign Loopback IP"
14412 +       default y
14413 +       help
14414 +         Automatically assign a guest specific loopback
14415 +         IP and add it to the kernel network stack on
14416 +         startup.
14417 +
14418 +config VSERVER_AUTO_SINGLE
14419 +       bool    "Automatic Single IP Special Casing"
14420 +       default n
14421 +       help
14422 +         This allows network contexts with a single IP to
14423 +         automatically remap 0.0.0.0 bindings to that IP,
14424 +         avoiding further network checks and improving
14425 +         performance.
14426 +
14427 +         (note: such guests do not allow to change the ip
14428 +          on the fly and do not show loopback addresses)
14429 +
14430 +config VSERVER_COWBL
14431 +       bool    "Enable COW Immutable Link Breaking"
14432 +       default y
14433 +       help
14434 +         This enables the COW (Copy-On-Write) link break code.
14435 +         It allows you to treat unified files like normal files
14436 +         when writing to them (which will implicitely break the
14437 +         link and create a copy of the unified file)
14438 +
14439 +config VSERVER_VTIME
14440 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14441 +       default n
14442 +       help
14443 +         This enables per guest time offsets to allow for
14444 +         adjusting the system clock individually per guest.
14445 +         this adds some overhead to the time functions and
14446 +         therefore should not be enabled without good reason.
14447 +
14448 +config VSERVER_DEVICE
14449 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14450 +       default n
14451 +       help
14452 +         This enables generic device remapping.
14453 +
14454 +config VSERVER_PROC_SECURE
14455 +       bool    "Enable Proc Security"
14456 +       depends on PROC_FS
14457 +       default y
14458 +       help
14459 +         This configures ProcFS security to initially hide
14460 +         non-process entries for all contexts except the main and
14461 +         spectator context (i.e. for all guests), which is a secure
14462 +         default.
14463 +
14464 +         (note: on 1.2x the entries were visible by default)
14465 +
14466 +choice
14467 +       prompt  "Persistent Inode Tagging"
14468 +       default TAGGING_ID24
14469 +       help
14470 +         This adds persistent context information to filesystems
14471 +         mounted with the tagxid option. Tagging is a requirement
14472 +         for per-context disk limits and per-context quota.
14473 +
14474 +
14475 +config TAGGING_NONE
14476 +       bool    "Disabled"
14477 +       help
14478 +         do not store per-context information in inodes.
14479 +
14480 +config TAGGING_UID16
14481 +       bool    "UID16/GID32"
14482 +       help
14483 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14484 +
14485 +config TAGGING_GID16
14486 +       bool    "UID32/GID16"
14487 +       help
14488 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14489 +
14490 +config TAGGING_ID24
14491 +       bool    "UID24/GID24"
14492 +       help
14493 +         uses the upper 8bit from UID and GID for XID tagging
14494 +         which leaves 24bit for UID/GID each, which should be
14495 +         more than sufficient for normal use.
14496 +
14497 +config TAGGING_INTERN
14498 +       bool    "UID32/GID32"
14499 +       help
14500 +         this uses otherwise reserved inode fields in the on
14501 +         disk representation, which limits the use to a few
14502 +         filesystems (currently ext2 and ext3)
14503 +
14504 +endchoice
14505 +
14506 +config TAG_NFSD
14507 +       bool    "Tag NFSD User Auth and Files"
14508 +       default n
14509 +       help
14510 +         Enable this if you do want the in-kernel NFS
14511 +         Server to use the tagging specified above.
14512 +         (will require patched clients too)
14513 +
14514 +config VSERVER_PRIVACY
14515 +       bool    "Honor Privacy Aspects of Guests"
14516 +       default n
14517 +       help
14518 +         When enabled, most context checks will disallow
14519 +         access to structures assigned to a specific context,
14520 +         like ptys or loop devices.
14521 +
14522 +config VSERVER_CONTEXTS
14523 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14524 +       range 1 65533
14525 +       default "768"   if 64BIT
14526 +       default "256"
14527 +       help
14528 +         This setting will optimize certain data structures
14529 +         and memory allocations according to the expected
14530 +         maximum.
14531 +
14532 +         note: this is not a strict upper limit.
14533 +
14534 +config VSERVER_WARN
14535 +       bool    "VServer Warnings"
14536 +       default y
14537 +       help
14538 +         This enables various runtime warnings, which will
14539 +         notify about potential manipulation attempts or
14540 +         resource shortage. It is generally considered to
14541 +         be a good idea to have that enabled.
14542 +
14543 +config VSERVER_WARN_DEVPTS
14544 +       bool    "VServer DevPTS Warnings"
14545 +       depends on VSERVER_WARN
14546 +       default y
14547 +       help
14548 +         This enables DevPTS related warnings, issued when a
14549 +         process inside a context tries to lookup or access
14550 +         a dynamic pts from the host or a different context.
14551 +
14552 +config VSERVER_DEBUG
14553 +       bool    "VServer Debugging Code"
14554 +       default n
14555 +       help
14556 +         Set this to yes if you want to be able to activate
14557 +         debugging output at runtime. It adds a very small
14558 +         overhead to all vserver related functions and
14559 +         increases the kernel size by about 20k.
14560 +
14561 +config VSERVER_HISTORY
14562 +       bool    "VServer History Tracing"
14563 +       depends on VSERVER_DEBUG
14564 +       default n
14565 +       help
14566 +         Set this to yes if you want to record the history of
14567 +         linux-vserver activities, so they can be replayed in
14568 +         the event of a kernel panic or oops.
14569 +
14570 +config VSERVER_HISTORY_SIZE
14571 +       int     "Per-CPU History Size (32-65536)"
14572 +       depends on VSERVER_HISTORY
14573 +       range 32 65536
14574 +       default 64
14575 +       help
14576 +         This allows you to specify the number of entries in
14577 +         the per-CPU history buffer.
14578 +
14579 +config VSERVER_EXTRA_MNT_CHECK
14580 +       bool    "Extra Checks for Reachability"
14581 +       default n
14582 +       help
14583 +         Set this to yes if you want to do extra checks for
14584 +         vfsmount reachability in the proc filesystem code.
14585 +         This shouldn't be required on any setup utilizing
14586 +         mnt namespaces.
14587 +
14588 +choice
14589 +       prompt  "Quotes used in debug and warn messages"
14590 +       default QUOTES_ISO8859
14591 +
14592 +config QUOTES_ISO8859
14593 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14594 +       help
14595 +         This uses the extended ASCII characters \xbb
14596 +         and \xab for quoting file and process names.
14597 +
14598 +config QUOTES_UTF8
14599 +       bool    "UTF-8 angle quotes"
14600 +       help
14601 +         This uses the the UTF-8 sequences for angle
14602 +         quotes to quote file and process names.
14603 +
14604 +config QUOTES_ASCII
14605 +       bool    "ASCII single quotes"
14606 +       help
14607 +         This uses the ASCII single quote character
14608 +         (\x27) to quote file and process names.
14609 +
14610 +endchoice
14611 +
14612 +endmenu
14613 +
14614 +
14615 +config VSERVER
14616 +       bool
14617 +       default y
14618 +       select NAMESPACES
14619 +       select UTS_NS
14620 +       select IPC_NS
14621 +#      select USER_NS
14622 +       select SYSVIPC
14623 +
14624 +config VSERVER_SECURITY
14625 +       bool
14626 +       depends on SECURITY
14627 +       default y
14628 +       select SECURITY_CAPABILITIES
14629 +
14630 +config VSERVER_DISABLED
14631 +       bool
14632 +       default n
14633 +
14634 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Makefile linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile
14635 --- linux-3.13.10/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14636 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile    2014-01-31 20:38:03.000000000 +0000
14637 @@ -0,0 +1,18 @@
14638 +#
14639 +# Makefile for the Linux vserver routines.
14640 +#
14641 +
14642 +
14643 +obj-y          += vserver.o
14644 +
14645 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14646 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14647 +                  dlimit.o tag.o
14648 +
14649 +vserver-$(CONFIG_INET) += inet.o
14650 +vserver-$(CONFIG_PROC_FS) += proc.o
14651 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14652 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14653 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14654 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14655 +
14656 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c
14657 --- linux-3.13.10/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14658 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c     2014-01-31 20:38:03.000000000 +0000
14659 @@ -0,0 +1,42 @@
14660 +/*
14661 + *  linux/kernel/vserver/cacct.c
14662 + *
14663 + *  Virtual Server: Context Accounting
14664 + *
14665 + *  Copyright (C) 2006-2007 Herbert Pötzl
14666 + *
14667 + *  V0.01  added accounting stats
14668 + *
14669 + */
14670 +
14671 +#include <linux/types.h>
14672 +#include <linux/vs_context.h>
14673 +#include <linux/vserver/cacct_cmd.h>
14674 +#include <linux/vserver/cacct_int.h>
14675 +
14676 +#include <asm/errno.h>
14677 +#include <asm/uaccess.h>
14678 +
14679 +
14680 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14681 +{
14682 +       struct vcmd_sock_stat_v0 vc_data;
14683 +       int j, field;
14684 +
14685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14686 +               return -EFAULT;
14687 +
14688 +       field = vc_data.field;
14689 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14690 +               return -EINVAL;
14691 +
14692 +       for (j = 0; j < 3; j++) {
14693 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14694 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14695 +       }
14696 +
14697 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14698 +               return -EFAULT;
14699 +       return 0;
14700 +}
14701 +
14702 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h
14703 --- linux-3.13.10/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14704 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h        2014-01-31 20:38:03.000000000 +0000
14705 @@ -0,0 +1,25 @@
14706 +
14707 +
14708 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14709 +{
14710 +       int i, j;
14711 +
14712 +
14713 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14714 +               for (j = 0; j < 3; j++) {
14715 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14716 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14717 +               }
14718 +       }
14719 +       for (i = 0; i < 8; i++)
14720 +               atomic_set(&cacct->slab[i], 0);
14721 +       for (i = 0; i < 5; i++)
14722 +               for (j = 0; j < 4; j++)
14723 +                       atomic_set(&cacct->page[i][j], 0);
14724 +}
14725 +
14726 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14727 +{
14728 +       return;
14729 +}
14730 +
14731 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h
14732 --- linux-3.13.10/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14733 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h        2014-01-31 20:38:03.000000000 +0000
14734 @@ -0,0 +1,53 @@
14735 +#ifndef _VX_CACCT_PROC_H
14736 +#define _VX_CACCT_PROC_H
14737 +
14738 +#include <linux/vserver/cacct_int.h>
14739 +
14740 +
14741 +#define VX_SOCKA_TOP   \
14742 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14743 +
14744 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14745 +{
14746 +       int i, j, length = 0;
14747 +       static char *type[VXA_SOCK_SIZE] = {
14748 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14749 +       };
14750 +
14751 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14752 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14753 +               length += sprintf(buffer + length, "%s:", type[i]);
14754 +               for (j = 0; j < 3; j++) {
14755 +                       length += sprintf(buffer + length,
14756 +                               "\t%10lu/%-10lu",
14757 +                               vx_sock_count(cacct, i, j),
14758 +                               vx_sock_total(cacct, i, j));
14759 +               }
14760 +               buffer[length++] = '\n';
14761 +       }
14762 +
14763 +       length += sprintf(buffer + length, "\n");
14764 +       length += sprintf(buffer + length,
14765 +               "slab:\t %8u %8u %8u %8u\n",
14766 +               atomic_read(&cacct->slab[1]),
14767 +               atomic_read(&cacct->slab[4]),
14768 +               atomic_read(&cacct->slab[0]),
14769 +               atomic_read(&cacct->slab[2]));
14770 +
14771 +       length += sprintf(buffer + length, "\n");
14772 +       for (i = 0; i < 5; i++) {
14773 +               length += sprintf(buffer + length,
14774 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14775 +                       atomic_read(&cacct->page[i][0]),
14776 +                       atomic_read(&cacct->page[i][1]),
14777 +                       atomic_read(&cacct->page[i][2]),
14778 +                       atomic_read(&cacct->page[i][3]),
14779 +                       atomic_read(&cacct->page[i][4]),
14780 +                       atomic_read(&cacct->page[i][5]),
14781 +                       atomic_read(&cacct->page[i][6]),
14782 +                       atomic_read(&cacct->page[i][7]));
14783 +       }
14784 +       return length;
14785 +}
14786 +
14787 +#endif /* _VX_CACCT_PROC_H */
14788 diff -NurpP --minimal linux-3.13.10/kernel/vserver/context.c linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c
14789 --- linux-3.13.10/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14790 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c   2014-01-31 20:38:03.000000000 +0000
14791 @@ -0,0 +1,1119 @@
14792 +/*
14793 + *  linux/kernel/vserver/context.c
14794 + *
14795 + *  Virtual Server: Context Support
14796 + *
14797 + *  Copyright (C) 2003-2011  Herbert Pötzl
14798 + *
14799 + *  V0.01  context helper
14800 + *  V0.02  vx_ctx_kill syscall command
14801 + *  V0.03  replaced context_info calls
14802 + *  V0.04  redesign of struct (de)alloc
14803 + *  V0.05  rlimit basic implementation
14804 + *  V0.06  task_xid and info commands
14805 + *  V0.07  context flags and caps
14806 + *  V0.08  switch to RCU based hash
14807 + *  V0.09  revert to non RCU for now
14808 + *  V0.10  and back to working RCU hash
14809 + *  V0.11  and back to locking again
14810 + *  V0.12  referenced context store
14811 + *  V0.13  separate per cpu data
14812 + *  V0.14  changed vcmds to vxi arg
14813 + *  V0.15  added context stat
14814 + *  V0.16  have __create claim() the vxi
14815 + *  V0.17  removed older and legacy stuff
14816 + *  V0.18  added user credentials
14817 + *  V0.19  added warn mask
14818 + *
14819 + */
14820 +
14821 +#include <linux/slab.h>
14822 +#include <linux/types.h>
14823 +#include <linux/security.h>
14824 +#include <linux/pid_namespace.h>
14825 +#include <linux/capability.h>
14826 +
14827 +#include <linux/vserver/context.h>
14828 +#include <linux/vserver/network.h>
14829 +#include <linux/vserver/debug.h>
14830 +#include <linux/vserver/limit.h>
14831 +#include <linux/vserver/limit_int.h>
14832 +#include <linux/vserver/space.h>
14833 +#include <linux/init_task.h>
14834 +#include <linux/fs_struct.h>
14835 +#include <linux/cred.h>
14836 +
14837 +#include <linux/vs_context.h>
14838 +#include <linux/vs_limit.h>
14839 +#include <linux/vs_pid.h>
14840 +#include <linux/vserver/context_cmd.h>
14841 +
14842 +#include "cvirt_init.h"
14843 +#include "cacct_init.h"
14844 +#include "limit_init.h"
14845 +#include "sched_init.h"
14846 +
14847 +
14848 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14849 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14850 +
14851 +
14852 +/*     now inactive context structures */
14853 +
14854 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14855 +
14856 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14857 +
14858 +
14859 +/*     __alloc_vx_info()
14860 +
14861 +       * allocate an initialized vx_info struct
14862 +       * doesn't make it visible (hash)                        */
14863 +
14864 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14865 +{
14866 +       struct vx_info *new = NULL;
14867 +       int cpu, index;
14868 +
14869 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14870 +
14871 +       /* would this benefit from a slab cache? */
14872 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14873 +       if (!new)
14874 +               return 0;
14875 +
14876 +       memset(new, 0, sizeof(struct vx_info));
14877 +#ifdef CONFIG_SMP
14878 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14879 +       if (!new->ptr_pc)
14880 +               goto error;
14881 +#endif
14882 +       new->vx_id = xid;
14883 +       INIT_HLIST_NODE(&new->vx_hlist);
14884 +       atomic_set(&new->vx_usecnt, 0);
14885 +       atomic_set(&new->vx_tasks, 0);
14886 +       new->vx_parent = NULL;
14887 +       new->vx_state = 0;
14888 +       init_waitqueue_head(&new->vx_wait);
14889 +
14890 +       /* prepare reaper */
14891 +       get_task_struct(init_pid_ns.child_reaper);
14892 +       new->vx_reaper = init_pid_ns.child_reaper;
14893 +       new->vx_badness_bias = 0;
14894 +
14895 +       /* rest of init goes here */
14896 +       vx_info_init_limit(&new->limit);
14897 +       vx_info_init_sched(&new->sched);
14898 +       vx_info_init_cvirt(&new->cvirt);
14899 +       vx_info_init_cacct(&new->cacct);
14900 +
14901 +       /* per cpu data structures */
14902 +       for_each_possible_cpu(cpu) {
14903 +               vx_info_init_sched_pc(
14904 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14905 +               vx_info_init_cvirt_pc(
14906 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14907 +       }
14908 +
14909 +       new->vx_flags = VXF_INIT_SET;
14910 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14911 +       new->vx_ccaps = 0;
14912 +       new->vx_umask = 0;
14913 +       new->vx_wmask = 0;
14914 +
14915 +       new->reboot_cmd = 0;
14916 +       new->exit_code = 0;
14917 +
14918 +       // preconfig spaces
14919 +       for (index = 0; index < VX_SPACES; index++) {
14920 +               struct _vx_space *space = &new->space[index];
14921 +
14922 +               // filesystem
14923 +               spin_lock(&init_fs.lock);
14924 +               init_fs.users++;
14925 +               spin_unlock(&init_fs.lock);
14926 +               space->vx_fs = &init_fs;
14927 +
14928 +               /* FIXME: do we want defaults? */
14929 +               // space->vx_real_cred = 0;
14930 +               // space->vx_cred = 0;
14931 +       }
14932 +
14933 +
14934 +       vxdprintk(VXD_CBIT(xid, 0),
14935 +               "alloc_vx_info(%d) = %p", xid, new);
14936 +       vxh_alloc_vx_info(new);
14937 +       atomic_inc(&vx_global_ctotal);
14938 +       return new;
14939 +#ifdef CONFIG_SMP
14940 +error:
14941 +       kfree(new);
14942 +       return 0;
14943 +#endif
14944 +}
14945 +
14946 +/*     __dealloc_vx_info()
14947 +
14948 +       * final disposal of vx_info                             */
14949 +
14950 +static void __dealloc_vx_info(struct vx_info *vxi)
14951 +{
14952 +#ifdef CONFIG_VSERVER_WARN
14953 +       struct vx_info_save vxis;
14954 +       int cpu;
14955 +#endif
14956 +       vxdprintk(VXD_CBIT(xid, 0),
14957 +               "dealloc_vx_info(%p)", vxi);
14958 +       vxh_dealloc_vx_info(vxi);
14959 +
14960 +#ifdef CONFIG_VSERVER_WARN
14961 +       enter_vx_info(vxi, &vxis);
14962 +       vx_info_exit_limit(&vxi->limit);
14963 +       vx_info_exit_sched(&vxi->sched);
14964 +       vx_info_exit_cvirt(&vxi->cvirt);
14965 +       vx_info_exit_cacct(&vxi->cacct);
14966 +
14967 +       for_each_possible_cpu(cpu) {
14968 +               vx_info_exit_sched_pc(
14969 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14970 +               vx_info_exit_cvirt_pc(
14971 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14972 +       }
14973 +       leave_vx_info(&vxis);
14974 +#endif
14975 +
14976 +       vxi->vx_id = -1;
14977 +       vxi->vx_state |= VXS_RELEASED;
14978 +
14979 +#ifdef CONFIG_SMP
14980 +       free_percpu(vxi->ptr_pc);
14981 +#endif
14982 +       kfree(vxi);
14983 +       atomic_dec(&vx_global_ctotal);
14984 +}
14985 +
14986 +static void __shutdown_vx_info(struct vx_info *vxi)
14987 +{
14988 +       struct nsproxy *nsproxy;
14989 +       struct fs_struct *fs;
14990 +       struct cred *cred;
14991 +       int index, kill;
14992 +
14993 +       might_sleep();
14994 +
14995 +       vxi->vx_state |= VXS_SHUTDOWN;
14996 +       vs_state_change(vxi, VSC_SHUTDOWN);
14997 +
14998 +       for (index = 0; index < VX_SPACES; index++) {
14999 +               struct _vx_space *space = &vxi->space[index];
15000 +
15001 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15002 +               if (nsproxy)
15003 +                       put_nsproxy(nsproxy);
15004 +
15005 +               fs = xchg(&space->vx_fs, NULL);
15006 +               spin_lock(&fs->lock);
15007 +               kill = !--fs->users;
15008 +               spin_unlock(&fs->lock);
15009 +               if (kill)
15010 +                       free_fs_struct(fs);
15011 +
15012 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15013 +               if (cred)
15014 +                       abort_creds(cred);
15015 +       }
15016 +}
15017 +
15018 +/* exported stuff */
15019 +
15020 +void free_vx_info(struct vx_info *vxi)
15021 +{
15022 +       unsigned long flags;
15023 +       unsigned index;
15024 +
15025 +       /* check for reference counts first */
15026 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15027 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15028 +
15029 +       /* context must not be hashed */
15030 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15031 +
15032 +       /* context shutdown is mandatory */
15033 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15034 +
15035 +       /* spaces check */
15036 +       for (index = 0; index < VX_SPACES; index++) {
15037 +               struct _vx_space *space = &vxi->space[index];
15038 +
15039 +               BUG_ON(space->vx_nsproxy);
15040 +               BUG_ON(space->vx_fs);
15041 +               // BUG_ON(space->vx_real_cred);
15042 +               // BUG_ON(space->vx_cred);
15043 +       }
15044 +
15045 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15046 +       hlist_del(&vxi->vx_hlist);
15047 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15048 +
15049 +       __dealloc_vx_info(vxi);
15050 +}
15051 +
15052 +
15053 +/*     hash table for vx_info hash */
15054 +
15055 +#define VX_HASH_SIZE   13
15056 +
15057 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15058 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15059 +
15060 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15061 +
15062 +
15063 +static inline unsigned int __hashval(vxid_t xid)
15064 +{
15065 +       return (xid % VX_HASH_SIZE);
15066 +}
15067 +
15068 +
15069 +
15070 +/*     __hash_vx_info()
15071 +
15072 +       * add the vxi to the global hash table
15073 +       * requires the hash_lock to be held                     */
15074 +
15075 +static inline void __hash_vx_info(struct vx_info *vxi)
15076 +{
15077 +       struct hlist_head *head;
15078 +
15079 +       vxd_assert_lock(&vx_info_hash_lock);
15080 +       vxdprintk(VXD_CBIT(xid, 4),
15081 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15082 +       vxh_hash_vx_info(vxi);
15083 +
15084 +       /* context must not be hashed */
15085 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15086 +
15087 +       vxi->vx_state |= VXS_HASHED;
15088 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15089 +       hlist_add_head(&vxi->vx_hlist, head);
15090 +       atomic_inc(&vx_global_cactive);
15091 +}
15092 +
15093 +/*     __unhash_vx_info()
15094 +
15095 +       * remove the vxi from the global hash table
15096 +       * requires the hash_lock to be held                     */
15097 +
15098 +static inline void __unhash_vx_info(struct vx_info *vxi)
15099 +{
15100 +       unsigned long flags;
15101 +
15102 +       vxd_assert_lock(&vx_info_hash_lock);
15103 +       vxdprintk(VXD_CBIT(xid, 4),
15104 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15105 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15106 +       vxh_unhash_vx_info(vxi);
15107 +
15108 +       /* context must be hashed */
15109 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15110 +       /* but without tasks */
15111 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15112 +
15113 +       vxi->vx_state &= ~VXS_HASHED;
15114 +       hlist_del_init(&vxi->vx_hlist);
15115 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15116 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15117 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15118 +       atomic_dec(&vx_global_cactive);
15119 +}
15120 +
15121 +
15122 +/*     __lookup_vx_info()
15123 +
15124 +       * requires the hash_lock to be held
15125 +       * doesn't increment the vx_refcnt                       */
15126 +
15127 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15128 +{
15129 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15130 +       struct hlist_node *pos;
15131 +       struct vx_info *vxi;
15132 +
15133 +       vxd_assert_lock(&vx_info_hash_lock);
15134 +       hlist_for_each(pos, head) {
15135 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15136 +
15137 +               if (vxi->vx_id == xid)
15138 +                       goto found;
15139 +       }
15140 +       vxi = NULL;
15141 +found:
15142 +       vxdprintk(VXD_CBIT(xid, 0),
15143 +               "__lookup_vx_info(#%u): %p[#%u]",
15144 +               xid, vxi, vxi ? vxi->vx_id : 0);
15145 +       vxh_lookup_vx_info(vxi, xid);
15146 +       return vxi;
15147 +}
15148 +
15149 +
15150 +/*     __create_vx_info()
15151 +
15152 +       * create the requested context
15153 +       * get(), claim() and hash it                            */
15154 +
15155 +static struct vx_info *__create_vx_info(int id)
15156 +{
15157 +       struct vx_info *new, *vxi = NULL;
15158 +
15159 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15160 +
15161 +       if (!(new = __alloc_vx_info(id)))
15162 +               return ERR_PTR(-ENOMEM);
15163 +
15164 +       /* required to make dynamic xids unique */
15165 +       spin_lock(&vx_info_hash_lock);
15166 +
15167 +       /* static context requested */
15168 +       if ((vxi = __lookup_vx_info(id))) {
15169 +               vxdprintk(VXD_CBIT(xid, 0),
15170 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15171 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15172 +                       vxi = ERR_PTR(-EBUSY);
15173 +               else
15174 +                       vxi = ERR_PTR(-EEXIST);
15175 +               goto out_unlock;
15176 +       }
15177 +       /* new context */
15178 +       vxdprintk(VXD_CBIT(xid, 0),
15179 +               "create_vx_info(%d) = %p (new)", id, new);
15180 +       claim_vx_info(new, NULL);
15181 +       __hash_vx_info(get_vx_info(new));
15182 +       vxi = new, new = NULL;
15183 +
15184 +out_unlock:
15185 +       spin_unlock(&vx_info_hash_lock);
15186 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15187 +       if (new)
15188 +               __dealloc_vx_info(new);
15189 +       return vxi;
15190 +}
15191 +
15192 +
15193 +/*     exported stuff                                          */
15194 +
15195 +
15196 +void unhash_vx_info(struct vx_info *vxi)
15197 +{
15198 +       spin_lock(&vx_info_hash_lock);
15199 +       __unhash_vx_info(vxi);
15200 +       spin_unlock(&vx_info_hash_lock);
15201 +       __shutdown_vx_info(vxi);
15202 +       __wakeup_vx_info(vxi);
15203 +}
15204 +
15205 +
15206 +/*     lookup_vx_info()
15207 +
15208 +       * search for a vx_info and get() it
15209 +       * negative id means current                             */
15210 +
15211 +struct vx_info *lookup_vx_info(int id)
15212 +{
15213 +       struct vx_info *vxi = NULL;
15214 +
15215 +       if (id < 0) {
15216 +               vxi = get_vx_info(current_vx_info());
15217 +       } else if (id > 1) {
15218 +               spin_lock(&vx_info_hash_lock);
15219 +               vxi = get_vx_info(__lookup_vx_info(id));
15220 +               spin_unlock(&vx_info_hash_lock);
15221 +       }
15222 +       return vxi;
15223 +}
15224 +
15225 +/*     xid_is_hashed()
15226 +
15227 +       * verify that xid is still hashed                       */
15228 +
15229 +int xid_is_hashed(vxid_t xid)
15230 +{
15231 +       int hashed;
15232 +
15233 +       spin_lock(&vx_info_hash_lock);
15234 +       hashed = (__lookup_vx_info(xid) != NULL);
15235 +       spin_unlock(&vx_info_hash_lock);
15236 +       return hashed;
15237 +}
15238 +
15239 +#ifdef CONFIG_PROC_FS
15240 +
15241 +/*     get_xid_list()
15242 +
15243 +       * get a subset of hashed xids for proc
15244 +       * assumes size is at least one                          */
15245 +
15246 +int get_xid_list(int index, unsigned int *xids, int size)
15247 +{
15248 +       int hindex, nr_xids = 0;
15249 +
15250 +       /* only show current and children */
15251 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15252 +               if (index > 0)
15253 +                       return 0;
15254 +               xids[nr_xids] = vx_current_xid();
15255 +               return 1;
15256 +       }
15257 +
15258 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15259 +               struct hlist_head *head = &vx_info_hash[hindex];
15260 +               struct hlist_node *pos;
15261 +
15262 +               spin_lock(&vx_info_hash_lock);
15263 +               hlist_for_each(pos, head) {
15264 +                       struct vx_info *vxi;
15265 +
15266 +                       if (--index > 0)
15267 +                               continue;
15268 +
15269 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15270 +                       xids[nr_xids] = vxi->vx_id;
15271 +                       if (++nr_xids >= size) {
15272 +                               spin_unlock(&vx_info_hash_lock);
15273 +                               goto out;
15274 +                       }
15275 +               }
15276 +               /* keep the lock time short */
15277 +               spin_unlock(&vx_info_hash_lock);
15278 +       }
15279 +out:
15280 +       return nr_xids;
15281 +}
15282 +#endif
15283 +
15284 +#ifdef CONFIG_VSERVER_DEBUG
15285 +
15286 +void   dump_vx_info_inactive(int level)
15287 +{
15288 +       struct hlist_node *entry, *next;
15289 +
15290 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15291 +               struct vx_info *vxi =
15292 +                       list_entry(entry, struct vx_info, vx_hlist);
15293 +
15294 +               dump_vx_info(vxi, level);
15295 +       }
15296 +}
15297 +
15298 +#endif
15299 +
15300 +#if 0
15301 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15302 +{
15303 +       struct user_struct *new_user, *old_user;
15304 +
15305 +       if (!p || !vxi)
15306 +               BUG();
15307 +
15308 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15309 +               return -EACCES;
15310 +
15311 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15312 +       if (!new_user)
15313 +               return -ENOMEM;
15314 +
15315 +       old_user = p->user;
15316 +       if (new_user != old_user) {
15317 +               atomic_inc(&new_user->processes);
15318 +               atomic_dec(&old_user->processes);
15319 +               p->user = new_user;
15320 +       }
15321 +       free_uid(old_user);
15322 +       return 0;
15323 +}
15324 +#endif
15325 +
15326 +#if 0
15327 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15328 +{
15329 +       // p->cap_effective &= vxi->vx_cap_bset;
15330 +       p->cap_effective =
15331 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15332 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15333 +       p->cap_inheritable =
15334 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15335 +       // p->cap_permitted &= vxi->vx_cap_bset;
15336 +       p->cap_permitted =
15337 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15338 +}
15339 +#endif
15340 +
15341 +
15342 +#include <linux/file.h>
15343 +#include <linux/fdtable.h>
15344 +
15345 +static int vx_openfd_task(struct task_struct *tsk)
15346 +{
15347 +       struct files_struct *files = tsk->files;
15348 +       struct fdtable *fdt;
15349 +       const unsigned long *bptr;
15350 +       int count, total;
15351 +
15352 +       /* no rcu_read_lock() because of spin_lock() */
15353 +       spin_lock(&files->file_lock);
15354 +       fdt = files_fdtable(files);
15355 +       bptr = fdt->open_fds;
15356 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15357 +       for (total = 0; count > 0; count--) {
15358 +               if (*bptr)
15359 +                       total += hweight_long(*bptr);
15360 +               bptr++;
15361 +       }
15362 +       spin_unlock(&files->file_lock);
15363 +       return total;
15364 +}
15365 +
15366 +
15367 +/*     for *space compatibility */
15368 +
15369 +asmlinkage long sys_unshare(unsigned long);
15370 +
15371 +/*
15372 + *     migrate task to new context
15373 + *     gets vxi, puts old_vxi on change
15374 + *     optionally unshares namespaces (hack)
15375 + */
15376 +
15377 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15378 +{
15379 +       struct vx_info *old_vxi;
15380 +       int ret = 0;
15381 +
15382 +       if (!p || !vxi)
15383 +               BUG();
15384 +
15385 +       vxdprintk(VXD_CBIT(xid, 5),
15386 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15387 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15388 +
15389 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15390 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15391 +               return -EACCES;
15392 +
15393 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15394 +               return -EFAULT;
15395 +
15396 +       old_vxi = task_get_vx_info(p);
15397 +       if (old_vxi == vxi)
15398 +               goto out;
15399 +
15400 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15401 +       {
15402 +               int openfd;
15403 +
15404 +               task_lock(p);
15405 +               openfd = vx_openfd_task(p);
15406 +
15407 +               if (old_vxi) {
15408 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15409 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15410 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15411 +                       /* FIXME: what about the struct files here? */
15412 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15413 +                       /* account for the executable */
15414 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15415 +               }
15416 +               atomic_inc(&vxi->cvirt.nr_threads);
15417 +               atomic_inc(&vxi->cvirt.nr_running);
15418 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15419 +               /* FIXME: what about the struct files here? */
15420 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15421 +               /* account for the executable */
15422 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15423 +
15424 +               if (old_vxi) {
15425 +                       release_vx_info(old_vxi, p);
15426 +                       clr_vx_info(&p->vx_info);
15427 +               }
15428 +               claim_vx_info(vxi, p);
15429 +               set_vx_info(&p->vx_info, vxi);
15430 +               p->xid = vxi->vx_id;
15431 +
15432 +               vxdprintk(VXD_CBIT(xid, 5),
15433 +                       "moved task %p into vxi:%p[#%d]",
15434 +                       p, vxi, vxi->vx_id);
15435 +
15436 +               // vx_mask_cap_bset(vxi, p);
15437 +               task_unlock(p);
15438 +
15439 +               /* hack for *spaces to provide compatibility */
15440 +               if (unshare) {
15441 +                       struct nsproxy *old_nsp, *new_nsp;
15442 +
15443 +                       ret = unshare_nsproxy_namespaces(
15444 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15445 +                               &new_nsp, NULL, NULL);
15446 +                       if (ret)
15447 +                               goto out;
15448 +
15449 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15450 +                       vx_set_space(vxi,
15451 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15452 +                       put_nsproxy(old_nsp);
15453 +               }
15454 +       }
15455 +out:
15456 +       put_vx_info(old_vxi);
15457 +       return ret;
15458 +}
15459 +
15460 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15461 +{
15462 +       struct task_struct *old_reaper;
15463 +       struct vx_info *reaper_vxi;
15464 +
15465 +       if (!vxi)
15466 +               return -EINVAL;
15467 +
15468 +       vxdprintk(VXD_CBIT(xid, 6),
15469 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15470 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15471 +
15472 +       old_reaper = vxi->vx_reaper;
15473 +       if (old_reaper == p)
15474 +               return 0;
15475 +
15476 +       reaper_vxi = task_get_vx_info(p);
15477 +       if (reaper_vxi && reaper_vxi != vxi) {
15478 +               vxwprintk(1,
15479 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15480 +                       "for [xid #%u]",
15481 +                       p->comm, p->pid, p->xid, vx_current_xid());
15482 +               goto out;
15483 +       }
15484 +
15485 +       /* set new child reaper */
15486 +       get_task_struct(p);
15487 +       vxi->vx_reaper = p;
15488 +       put_task_struct(old_reaper);
15489 +out:
15490 +       put_vx_info(reaper_vxi);
15491 +       return 0;
15492 +}
15493 +
15494 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15495 +{
15496 +       if (!vxi)
15497 +               return -EINVAL;
15498 +
15499 +       vxdprintk(VXD_CBIT(xid, 6),
15500 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15501 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15502 +
15503 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15504 +       // vxi->vx_initpid = p->tgid;
15505 +       vxi->vx_initpid = p->pid;
15506 +       return 0;
15507 +}
15508 +
15509 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15510 +{
15511 +       vxdprintk(VXD_CBIT(xid, 6),
15512 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15513 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15514 +
15515 +       vxi->exit_code = code;
15516 +       vxi->vx_initpid = 0;
15517 +}
15518 +
15519 +
15520 +void vx_set_persistent(struct vx_info *vxi)
15521 +{
15522 +       vxdprintk(VXD_CBIT(xid, 6),
15523 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15524 +
15525 +       get_vx_info(vxi);
15526 +       claim_vx_info(vxi, NULL);
15527 +}
15528 +
15529 +void vx_clear_persistent(struct vx_info *vxi)
15530 +{
15531 +       vxdprintk(VXD_CBIT(xid, 6),
15532 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15533 +
15534 +       release_vx_info(vxi, NULL);
15535 +       put_vx_info(vxi);
15536 +}
15537 +
15538 +void vx_update_persistent(struct vx_info *vxi)
15539 +{
15540 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15541 +               vx_set_persistent(vxi);
15542 +       else
15543 +               vx_clear_persistent(vxi);
15544 +}
15545 +
15546 +
15547 +/*     task must be current or locked          */
15548 +
15549 +void   exit_vx_info(struct task_struct *p, int code)
15550 +{
15551 +       struct vx_info *vxi = p->vx_info;
15552 +
15553 +       if (vxi) {
15554 +               atomic_dec(&vxi->cvirt.nr_threads);
15555 +               vx_nproc_dec(p);
15556 +
15557 +               vxi->exit_code = code;
15558 +               release_vx_info(vxi, p);
15559 +       }
15560 +}
15561 +
15562 +void   exit_vx_info_early(struct task_struct *p, int code)
15563 +{
15564 +       struct vx_info *vxi = p->vx_info;
15565 +
15566 +       if (vxi) {
15567 +               if (vxi->vx_initpid == p->pid)
15568 +                       vx_exit_init(vxi, p, code);
15569 +               if (vxi->vx_reaper == p)
15570 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15571 +       }
15572 +}
15573 +
15574 +
15575 +/* vserver syscall commands below here */
15576 +
15577 +/* taks xid and vx_info functions */
15578 +
15579 +#include <asm/uaccess.h>
15580 +
15581 +
15582 +int vc_task_xid(uint32_t id)
15583 +{
15584 +       vxid_t xid;
15585 +
15586 +       if (id) {
15587 +               struct task_struct *tsk;
15588 +
15589 +               rcu_read_lock();
15590 +               tsk = find_task_by_real_pid(id);
15591 +               xid = (tsk) ? tsk->xid : -ESRCH;
15592 +               rcu_read_unlock();
15593 +       } else
15594 +               xid = vx_current_xid();
15595 +       return xid;
15596 +}
15597 +
15598 +
15599 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15600 +{
15601 +       struct vcmd_vx_info_v0 vc_data;
15602 +
15603 +       vc_data.xid = vxi->vx_id;
15604 +       vc_data.initpid = vxi->vx_initpid;
15605 +
15606 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15607 +               return -EFAULT;
15608 +       return 0;
15609 +}
15610 +
15611 +
15612 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15613 +{
15614 +       struct vcmd_ctx_stat_v0 vc_data;
15615 +
15616 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15617 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15618 +
15619 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15620 +               return -EFAULT;
15621 +       return 0;
15622 +}
15623 +
15624 +
15625 +/* context functions */
15626 +
15627 +int vc_ctx_create(uint32_t xid, void __user *data)
15628 +{
15629 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15630 +       struct vx_info *new_vxi;
15631 +       int ret;
15632 +
15633 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15634 +               return -EFAULT;
15635 +
15636 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15637 +               return -EINVAL;
15638 +
15639 +       new_vxi = __create_vx_info(xid);
15640 +       if (IS_ERR(new_vxi))
15641 +               return PTR_ERR(new_vxi);
15642 +
15643 +       /* initial flags */
15644 +       new_vxi->vx_flags = vc_data.flagword;
15645 +
15646 +       ret = -ENOEXEC;
15647 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15648 +               goto out;
15649 +
15650 +       ret = vx_migrate_task(current, new_vxi, (!data));
15651 +       if (ret)
15652 +               goto out;
15653 +
15654 +       /* return context id on success */
15655 +       ret = new_vxi->vx_id;
15656 +
15657 +       /* get a reference for persistent contexts */
15658 +       if ((vc_data.flagword & VXF_PERSISTENT))
15659 +               vx_set_persistent(new_vxi);
15660 +out:
15661 +       release_vx_info(new_vxi, NULL);
15662 +       put_vx_info(new_vxi);
15663 +       return ret;
15664 +}
15665 +
15666 +
15667 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15668 +{
15669 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15670 +       int ret;
15671 +
15672 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15673 +               return -EFAULT;
15674 +
15675 +       ret = vx_migrate_task(current, vxi, 0);
15676 +       if (ret)
15677 +               return ret;
15678 +       if (vc_data.flagword & VXM_SET_INIT)
15679 +               ret = vx_set_init(vxi, current);
15680 +       if (ret)
15681 +               return ret;
15682 +       if (vc_data.flagword & VXM_SET_REAPER)
15683 +               ret = vx_set_reaper(vxi, current);
15684 +       return ret;
15685 +}
15686 +
15687 +
15688 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15689 +{
15690 +       struct vcmd_ctx_flags_v0 vc_data;
15691 +
15692 +       vc_data.flagword = vxi->vx_flags;
15693 +
15694 +       /* special STATE flag handling */
15695 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15696 +
15697 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15698 +               return -EFAULT;
15699 +       return 0;
15700 +}
15701 +
15702 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15703 +{
15704 +       struct vcmd_ctx_flags_v0 vc_data;
15705 +       uint64_t mask, trigger;
15706 +
15707 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15708 +               return -EFAULT;
15709 +
15710 +       /* special STATE flag handling */
15711 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15712 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15713 +
15714 +       if (vxi == current_vx_info()) {
15715 +               /* if (trigger & VXF_STATE_SETUP)
15716 +                       vx_mask_cap_bset(vxi, current); */
15717 +               if (trigger & VXF_STATE_INIT) {
15718 +                       int ret;
15719 +
15720 +                       ret = vx_set_init(vxi, current);
15721 +                       if (ret)
15722 +                               return ret;
15723 +                       ret = vx_set_reaper(vxi, current);
15724 +                       if (ret)
15725 +                               return ret;
15726 +               }
15727 +       }
15728 +
15729 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15730 +               vc_data.flagword, mask);
15731 +       if (trigger & VXF_PERSISTENT)
15732 +               vx_update_persistent(vxi);
15733 +
15734 +       return 0;
15735 +}
15736 +
15737 +
15738 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15739 +{
15740 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15741 +
15742 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15743 +       return v;
15744 +}
15745 +
15746 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15747 +{
15748 +       kernel_cap_t c = __cap_empty_set;
15749 +
15750 +       c.cap[0] = v & 0xFFFFFFFF;
15751 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15752 +
15753 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15754 +       return c;
15755 +}
15756 +
15757 +
15758 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15759 +{
15760 +       if (bcaps)
15761 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15762 +       if (ccaps)
15763 +               *ccaps = vxi->vx_ccaps;
15764 +
15765 +       return 0;
15766 +}
15767 +
15768 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15769 +{
15770 +       struct vcmd_ctx_caps_v1 vc_data;
15771 +       int ret;
15772 +
15773 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15774 +       if (ret)
15775 +               return ret;
15776 +       vc_data.cmask = ~0ULL;
15777 +
15778 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15779 +               return -EFAULT;
15780 +       return 0;
15781 +}
15782 +
15783 +static int do_set_caps(struct vx_info *vxi,
15784 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15785 +{
15786 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15787 +
15788 +#if 0
15789 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15790 +               bcaps, bmask, ccaps, cmask);
15791 +#endif
15792 +       vxi->vx_bcaps = cap_t_from_caps(
15793 +               vs_mask_flags(bcold, bcaps, bmask));
15794 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15795 +
15796 +       return 0;
15797 +}
15798 +
15799 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15800 +{
15801 +       struct vcmd_ctx_caps_v1 vc_data;
15802 +
15803 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15804 +               return -EFAULT;
15805 +
15806 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15807 +}
15808 +
15809 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15810 +{
15811 +       struct vcmd_bcaps vc_data;
15812 +       int ret;
15813 +
15814 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15815 +       if (ret)
15816 +               return ret;
15817 +       vc_data.bmask = ~0ULL;
15818 +
15819 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15820 +               return -EFAULT;
15821 +       return 0;
15822 +}
15823 +
15824 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15825 +{
15826 +       struct vcmd_bcaps vc_data;
15827 +
15828 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15829 +               return -EFAULT;
15830 +
15831 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15832 +}
15833 +
15834 +
15835 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15836 +{
15837 +       struct vcmd_umask vc_data;
15838 +
15839 +       vc_data.umask = vxi->vx_umask;
15840 +       vc_data.mask = ~0ULL;
15841 +
15842 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15843 +               return -EFAULT;
15844 +       return 0;
15845 +}
15846 +
15847 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15848 +{
15849 +       struct vcmd_umask vc_data;
15850 +
15851 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15852 +               return -EFAULT;
15853 +
15854 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15855 +               vc_data.umask, vc_data.mask);
15856 +       return 0;
15857 +}
15858 +
15859 +
15860 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15861 +{
15862 +       struct vcmd_wmask vc_data;
15863 +
15864 +       vc_data.wmask = vxi->vx_wmask;
15865 +       vc_data.mask = ~0ULL;
15866 +
15867 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15868 +               return -EFAULT;
15869 +       return 0;
15870 +}
15871 +
15872 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15873 +{
15874 +       struct vcmd_wmask vc_data;
15875 +
15876 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15877 +               return -EFAULT;
15878 +
15879 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15880 +               vc_data.wmask, vc_data.mask);
15881 +       return 0;
15882 +}
15883 +
15884 +
15885 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15886 +{
15887 +       struct vcmd_badness_v0 vc_data;
15888 +
15889 +       vc_data.bias = vxi->vx_badness_bias;
15890 +
15891 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15892 +               return -EFAULT;
15893 +       return 0;
15894 +}
15895 +
15896 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15897 +{
15898 +       struct vcmd_badness_v0 vc_data;
15899 +
15900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15901 +               return -EFAULT;
15902 +
15903 +       vxi->vx_badness_bias = vc_data.bias;
15904 +       return 0;
15905 +}
15906 +
15907 +#include <linux/module.h>
15908 +
15909 +EXPORT_SYMBOL_GPL(free_vx_info);
15910 +
15911 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c
15912 --- linux-3.13.10/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15913 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c     2014-01-31 20:38:04.000000000 +0000
15914 @@ -0,0 +1,313 @@
15915 +/*
15916 + *  linux/kernel/vserver/cvirt.c
15917 + *
15918 + *  Virtual Server: Context Virtualization
15919 + *
15920 + *  Copyright (C) 2004-2007  Herbert Pötzl
15921 + *
15922 + *  V0.01  broken out from limit.c
15923 + *  V0.02  added utsname stuff
15924 + *  V0.03  changed vcmds to vxi arg
15925 + *
15926 + */
15927 +
15928 +#include <linux/types.h>
15929 +#include <linux/utsname.h>
15930 +#include <linux/vs_cvirt.h>
15931 +#include <linux/vserver/switch.h>
15932 +#include <linux/vserver/cvirt_cmd.h>
15933 +
15934 +#include <asm/uaccess.h>
15935 +
15936 +
15937 +void vx_vsi_boottime(struct timespec *boottime)
15938 +{
15939 +       struct vx_info *vxi = current_vx_info();
15940 +
15941 +       set_normalized_timespec(boottime,
15942 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15943 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15944 +       return;
15945 +}
15946 +
15947 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15948 +{
15949 +       struct vx_info *vxi = current_vx_info();
15950 +
15951 +       set_normalized_timespec(uptime,
15952 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15953 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15954 +       if (!idle)
15955 +               return;
15956 +       set_normalized_timespec(idle,
15957 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15958 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15959 +       return;
15960 +}
15961 +
15962 +uint64_t vx_idle_jiffies(void)
15963 +{
15964 +       return init_task.utime + init_task.stime;
15965 +}
15966 +
15967 +
15968 +
15969 +static inline uint32_t __update_loadavg(uint32_t load,
15970 +       int wsize, int delta, int n)
15971 +{
15972 +       unsigned long long calc, prev;
15973 +
15974 +       /* just set it to n */
15975 +       if (unlikely(delta >= wsize))
15976 +               return (n << FSHIFT);
15977 +
15978 +       calc = delta * n;
15979 +       calc <<= FSHIFT;
15980 +       prev = (wsize - delta);
15981 +       prev *= load;
15982 +       calc += prev;
15983 +       do_div(calc, wsize);
15984 +       return calc;
15985 +}
15986 +
15987 +
15988 +void vx_update_load(struct vx_info *vxi)
15989 +{
15990 +       uint32_t now, last, delta;
15991 +       unsigned int nr_running, nr_uninterruptible;
15992 +       unsigned int total;
15993 +       unsigned long flags;
15994 +
15995 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
15996 +
15997 +       now = jiffies;
15998 +       last = vxi->cvirt.load_last;
15999 +       delta = now - last;
16000 +
16001 +       if (delta < 5*HZ)
16002 +               goto out;
16003 +
16004 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16005 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16006 +       total = nr_running + nr_uninterruptible;
16007 +
16008 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16009 +               60*HZ, delta, total);
16010 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16011 +               5*60*HZ, delta, total);
16012 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16013 +               15*60*HZ, delta, total);
16014 +
16015 +       vxi->cvirt.load_last = now;
16016 +out:
16017 +       atomic_inc(&vxi->cvirt.load_updates);
16018 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16019 +}
16020 +
16021 +
16022 +/*
16023 + * Commands to do_syslog:
16024 + *
16025 + *      0 -- Close the log.  Currently a NOP.
16026 + *      1 -- Open the log. Currently a NOP.
16027 + *      2 -- Read from the log.
16028 + *      3 -- Read all messages remaining in the ring buffer.
16029 + *      4 -- Read and clear all messages remaining in the ring buffer
16030 + *      5 -- Clear ring buffer.
16031 + *      6 -- Disable printk's to console
16032 + *      7 -- Enable printk's to console
16033 + *      8 -- Set level of messages printed to console
16034 + *      9 -- Return number of unread characters in the log buffer
16035 + *     10 -- Return size of the log buffer
16036 + */
16037 +int vx_do_syslog(int type, char __user *buf, int len)
16038 +{
16039 +       int error = 0;
16040 +       int do_clear = 0;
16041 +       struct vx_info *vxi = current_vx_info();
16042 +       struct _vx_syslog *log;
16043 +
16044 +       if (!vxi)
16045 +               return -EINVAL;
16046 +       log = &vxi->cvirt.syslog;
16047 +
16048 +       switch (type) {
16049 +       case 0:         /* Close log */
16050 +       case 1:         /* Open log */
16051 +               break;
16052 +       case 2:         /* Read from log */
16053 +               error = wait_event_interruptible(log->log_wait,
16054 +                       (log->log_start - log->log_end));
16055 +               if (error)
16056 +                       break;
16057 +               spin_lock_irq(&log->logbuf_lock);
16058 +               spin_unlock_irq(&log->logbuf_lock);
16059 +               break;
16060 +       case 4:         /* Read/clear last kernel messages */
16061 +               do_clear = 1;
16062 +               /* fall through */
16063 +       case 3:         /* Read last kernel messages */
16064 +               return 0;
16065 +
16066 +       case 5:         /* Clear ring buffer */
16067 +               return 0;
16068 +
16069 +       case 6:         /* Disable logging to console */
16070 +       case 7:         /* Enable logging to console */
16071 +       case 8:         /* Set level of messages printed to console */
16072 +               break;
16073 +
16074 +       case 9:         /* Number of chars in the log buffer */
16075 +               return 0;
16076 +       case 10:        /* Size of the log buffer */
16077 +               return 0;
16078 +       default:
16079 +               error = -EINVAL;
16080 +               break;
16081 +       }
16082 +       return error;
16083 +}
16084 +
16085 +
16086 +/* virtual host info names */
16087 +
16088 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16089 +{
16090 +       struct nsproxy *nsproxy;
16091 +       struct uts_namespace *uts;
16092 +
16093 +       if (id == VHIN_CONTEXT)
16094 +               return vxi->vx_name;
16095 +
16096 +       nsproxy = vxi->space[0].vx_nsproxy;
16097 +       if (!nsproxy)
16098 +               return NULL;
16099 +
16100 +       uts = nsproxy->uts_ns;
16101 +       if (!uts)
16102 +               return NULL;
16103 +
16104 +       switch (id) {
16105 +       case VHIN_SYSNAME:
16106 +               return uts->name.sysname;
16107 +       case VHIN_NODENAME:
16108 +               return uts->name.nodename;
16109 +       case VHIN_RELEASE:
16110 +               return uts->name.release;
16111 +       case VHIN_VERSION:
16112 +               return uts->name.version;
16113 +       case VHIN_MACHINE:
16114 +               return uts->name.machine;
16115 +       case VHIN_DOMAINNAME:
16116 +               return uts->name.domainname;
16117 +       default:
16118 +               return NULL;
16119 +       }
16120 +       return NULL;
16121 +}
16122 +
16123 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16124 +{
16125 +       struct vcmd_vhi_name_v0 vc_data;
16126 +       char *name;
16127 +
16128 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16129 +               return -EFAULT;
16130 +
16131 +       name = vx_vhi_name(vxi, vc_data.field);
16132 +       if (!name)
16133 +               return -EINVAL;
16134 +
16135 +       memcpy(name, vc_data.name, 65);
16136 +       return 0;
16137 +}
16138 +
16139 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16140 +{
16141 +       struct vcmd_vhi_name_v0 vc_data;
16142 +       char *name;
16143 +
16144 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16145 +               return -EFAULT;
16146 +
16147 +       name = vx_vhi_name(vxi, vc_data.field);
16148 +       if (!name)
16149 +               return -EINVAL;
16150 +
16151 +       memcpy(vc_data.name, name, 65);
16152 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16153 +               return -EFAULT;
16154 +       return 0;
16155 +}
16156 +
16157 +
16158 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16159 +{
16160 +       struct vcmd_virt_stat_v0 vc_data;
16161 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16162 +       struct timespec uptime;
16163 +
16164 +       do_posix_clock_monotonic_gettime(&uptime);
16165 +       set_normalized_timespec(&uptime,
16166 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16167 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16168 +
16169 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16170 +       vc_data.uptime = timespec_to_ns(&uptime);
16171 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16172 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16173 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16174 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16175 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16176 +       vc_data.load[0] = cvirt->load[0];
16177 +       vc_data.load[1] = cvirt->load[1];
16178 +       vc_data.load[2] = cvirt->load[2];
16179 +
16180 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16181 +               return -EFAULT;
16182 +       return 0;
16183 +}
16184 +
16185 +
16186 +#ifdef CONFIG_VSERVER_VTIME
16187 +
16188 +/* virtualized time base */
16189 +
16190 +void vx_adjust_timespec(struct timespec *ts)
16191 +{
16192 +       struct vx_info *vxi;
16193 +
16194 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16195 +               return;
16196 +
16197 +       vxi = current_vx_info();
16198 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16199 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16200 +
16201 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16202 +               ts->tv_sec++;
16203 +               ts->tv_nsec -= NSEC_PER_SEC;
16204 +       } else if (ts->tv_nsec < 0) {
16205 +               ts->tv_sec--;
16206 +               ts->tv_nsec += NSEC_PER_SEC;
16207 +       }
16208 +}
16209 +
16210 +int vx_settimeofday(const struct timespec *ts)
16211 +{
16212 +       struct timespec ats, delta;
16213 +       struct vx_info *vxi;
16214 +
16215 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16216 +               return do_settimeofday(ts);
16217 +
16218 +       getnstimeofday(&ats);
16219 +       delta = timespec_sub(*ts, ats);
16220 +
16221 +       vxi = current_vx_info();
16222 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16223 +       return 0;
16224 +}
16225 +
16226 +#endif
16227 +
16228 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h
16229 --- linux-3.13.10/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16230 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h        2014-01-31 20:38:04.000000000 +0000
16231 @@ -0,0 +1,70 @@
16232 +
16233 +
16234 +extern uint64_t vx_idle_jiffies(void);
16235 +
16236 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16237 +{
16238 +       uint64_t idle_jiffies = vx_idle_jiffies();
16239 +       uint64_t nsuptime;
16240 +
16241 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16242 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16243 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16244 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16245 +       cvirt->bias_ts.tv_sec = 0;
16246 +       cvirt->bias_ts.tv_nsec = 0;
16247 +
16248 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16249 +       atomic_set(&cvirt->nr_threads, 0);
16250 +       atomic_set(&cvirt->nr_running, 0);
16251 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16252 +       atomic_set(&cvirt->nr_onhold, 0);
16253 +
16254 +       spin_lock_init(&cvirt->load_lock);
16255 +       cvirt->load_last = jiffies;
16256 +       atomic_set(&cvirt->load_updates, 0);
16257 +       cvirt->load[0] = 0;
16258 +       cvirt->load[1] = 0;
16259 +       cvirt->load[2] = 0;
16260 +       atomic_set(&cvirt->total_forks, 0);
16261 +
16262 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16263 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16264 +       cvirt->syslog.log_start = 0;
16265 +       cvirt->syslog.log_end = 0;
16266 +       cvirt->syslog.con_start = 0;
16267 +       cvirt->syslog.logged_chars = 0;
16268 +}
16269 +
16270 +static inline
16271 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16272 +{
16273 +       // cvirt_pc->cpustat = { 0 };
16274 +}
16275 +
16276 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16277 +{
16278 +#ifdef CONFIG_VSERVER_WARN
16279 +       int value;
16280 +#endif
16281 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16282 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16283 +               cvirt, value);
16284 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16285 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16286 +               cvirt, value);
16287 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16288 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16289 +               cvirt, value);
16290 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16291 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16292 +               cvirt, value);
16293 +       return;
16294 +}
16295 +
16296 +static inline
16297 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16298 +{
16299 +       return;
16300 +}
16301 +
16302 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h
16303 --- linux-3.13.10/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
16304 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h        2014-01-31 20:38:04.000000000 +0000
16305 @@ -0,0 +1,123 @@
16306 +#ifndef _VX_CVIRT_PROC_H
16307 +#define _VX_CVIRT_PROC_H
16308 +
16309 +#include <linux/nsproxy.h>
16310 +#include <linux/mnt_namespace.h>
16311 +#include <linux/ipc_namespace.h>
16312 +#include <linux/utsname.h>
16313 +#include <linux/ipc.h>
16314 +
16315 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16316 +
16317 +static inline
16318 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16319 +{
16320 +       struct mnt_namespace *ns;
16321 +       struct uts_namespace *uts;
16322 +       struct ipc_namespace *ipc;
16323 +       int length = 0;
16324 +
16325 +       if (!nsproxy)
16326 +               goto out;
16327 +
16328 +       length += sprintf(buffer + length,
16329 +               "NSProxy:\t%p [%p,%p,%p]\n",
16330 +               nsproxy, nsproxy->mnt_ns,
16331 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16332 +
16333 +       ns = nsproxy->mnt_ns;
16334 +       if (!ns)
16335 +               goto skip_ns;
16336 +
16337 +       length += vx_info_mnt_namespace(ns, buffer + length);
16338 +
16339 +skip_ns:
16340 +
16341 +       uts = nsproxy->uts_ns;
16342 +       if (!uts)
16343 +               goto skip_uts;
16344 +
16345 +       length += sprintf(buffer + length,
16346 +               "SysName:\t%.*s\n"
16347 +               "NodeName:\t%.*s\n"
16348 +               "Release:\t%.*s\n"
16349 +               "Version:\t%.*s\n"
16350 +               "Machine:\t%.*s\n"
16351 +               "DomainName:\t%.*s\n",
16352 +               __NEW_UTS_LEN, uts->name.sysname,
16353 +               __NEW_UTS_LEN, uts->name.nodename,
16354 +               __NEW_UTS_LEN, uts->name.release,
16355 +               __NEW_UTS_LEN, uts->name.version,
16356 +               __NEW_UTS_LEN, uts->name.machine,
16357 +               __NEW_UTS_LEN, uts->name.domainname);
16358 +skip_uts:
16359 +
16360 +       ipc = nsproxy->ipc_ns;
16361 +       if (!ipc)
16362 +               goto skip_ipc;
16363 +
16364 +       length += sprintf(buffer + length,
16365 +               "SEMS:\t\t%d %d %d %d  %d\n"
16366 +               "MSG:\t\t%d %d %d\n"
16367 +               "SHM:\t\t%lu %lu  %d %ld\n",
16368 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16369 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16370 +               ipc->used_sems,
16371 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16372 +               (unsigned long)ipc->shm_ctlmax,
16373 +               (unsigned long)ipc->shm_ctlall,
16374 +               ipc->shm_ctlmni, ipc->shm_tot);
16375 +skip_ipc:
16376 +out:
16377 +       return length;
16378 +}
16379 +
16380 +
16381 +#include <linux/sched.h>
16382 +
16383 +#define LOAD_INT(x) ((x) >> FSHIFT)
16384 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16385 +
16386 +static inline
16387 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16388 +{
16389 +       int length = 0;
16390 +       int a, b, c;
16391 +
16392 +       length += sprintf(buffer + length,
16393 +               "BiasUptime:\t%lu.%02lu\n",
16394 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16395 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16396 +
16397 +       a = cvirt->load[0] + (FIXED_1 / 200);
16398 +       b = cvirt->load[1] + (FIXED_1 / 200);
16399 +       c = cvirt->load[2] + (FIXED_1 / 200);
16400 +       length += sprintf(buffer + length,
16401 +               "nr_threads:\t%d\n"
16402 +               "nr_running:\t%d\n"
16403 +               "nr_unintr:\t%d\n"
16404 +               "nr_onhold:\t%d\n"
16405 +               "load_updates:\t%d\n"
16406 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16407 +               "total_forks:\t%d\n",
16408 +               atomic_read(&cvirt->nr_threads),
16409 +               atomic_read(&cvirt->nr_running),
16410 +               atomic_read(&cvirt->nr_uninterruptible),
16411 +               atomic_read(&cvirt->nr_onhold),
16412 +               atomic_read(&cvirt->load_updates),
16413 +               LOAD_INT(a), LOAD_FRAC(a),
16414 +               LOAD_INT(b), LOAD_FRAC(b),
16415 +               LOAD_INT(c), LOAD_FRAC(c),
16416 +               atomic_read(&cvirt->total_forks));
16417 +       return length;
16418 +}
16419 +
16420 +static inline
16421 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16422 +       char *buffer, int cpu)
16423 +{
16424 +       int length = 0;
16425 +       return length;
16426 +}
16427 +
16428 +#endif /* _VX_CVIRT_PROC_H */
16429 diff -NurpP --minimal linux-3.13.10/kernel/vserver/debug.c linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c
16430 --- linux-3.13.10/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16431 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c     2014-01-31 20:38:04.000000000 +0000
16432 @@ -0,0 +1,32 @@
16433 +/*
16434 + *  kernel/vserver/debug.c
16435 + *
16436 + *  Copyright (C) 2005-2007 Herbert Pötzl
16437 + *
16438 + *  V0.01  vx_info dump support
16439 + *
16440 + */
16441 +
16442 +#include <linux/module.h>
16443 +
16444 +#include <linux/vserver/context.h>
16445 +
16446 +
16447 +void   dump_vx_info(struct vx_info *vxi, int level)
16448 +{
16449 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16450 +               atomic_read(&vxi->vx_usecnt),
16451 +               atomic_read(&vxi->vx_tasks),
16452 +               vxi->vx_state);
16453 +       if (level > 0) {
16454 +               __dump_vx_limit(&vxi->limit);
16455 +               __dump_vx_sched(&vxi->sched);
16456 +               __dump_vx_cvirt(&vxi->cvirt);
16457 +               __dump_vx_cacct(&vxi->cacct);
16458 +       }
16459 +       printk("---\n");
16460 +}
16461 +
16462 +
16463 +EXPORT_SYMBOL_GPL(dump_vx_info);
16464 +
16465 diff -NurpP --minimal linux-3.13.10/kernel/vserver/device.c linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c
16466 --- linux-3.13.10/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16467 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c    2014-01-31 20:38:04.000000000 +0000
16468 @@ -0,0 +1,443 @@
16469 +/*
16470 + *  linux/kernel/vserver/device.c
16471 + *
16472 + *  Linux-VServer: Device Support
16473 + *
16474 + *  Copyright (C) 2006  Herbert Pötzl
16475 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16476 + *
16477 + *  V0.01  device mapping basics
16478 + *  V0.02  added defaults
16479 + *
16480 + */
16481 +
16482 +#include <linux/slab.h>
16483 +#include <linux/rcupdate.h>
16484 +#include <linux/fs.h>
16485 +#include <linux/namei.h>
16486 +#include <linux/hash.h>
16487 +
16488 +#include <asm/errno.h>
16489 +#include <asm/uaccess.h>
16490 +#include <linux/vserver/base.h>
16491 +#include <linux/vserver/debug.h>
16492 +#include <linux/vserver/context.h>
16493 +#include <linux/vserver/device.h>
16494 +#include <linux/vserver/device_cmd.h>
16495 +
16496 +
16497 +#define DMAP_HASH_BITS 4
16498 +
16499 +
16500 +struct vs_mapping {
16501 +       union {
16502 +               struct hlist_node hlist;
16503 +               struct list_head list;
16504 +       } u;
16505 +#define dm_hlist       u.hlist
16506 +#define dm_list                u.list
16507 +       vxid_t xid;
16508 +       dev_t device;
16509 +       struct vx_dmap_target target;
16510 +};
16511 +
16512 +
16513 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16514 +
16515 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16516 +
16517 +static struct vx_dmap_target dmap_defaults[2] = {
16518 +       { .flags = DATTR_OPEN },
16519 +       { .flags = DATTR_OPEN },
16520 +};
16521 +
16522 +
16523 +struct kmem_cache *dmap_cachep __read_mostly;
16524 +
16525 +int __init dmap_cache_init(void)
16526 +{
16527 +       dmap_cachep = kmem_cache_create("dmap_cache",
16528 +               sizeof(struct vs_mapping), 0,
16529 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16530 +       return 0;
16531 +}
16532 +
16533 +__initcall(dmap_cache_init);
16534 +
16535 +
16536 +static inline unsigned int __hashval(dev_t dev, int bits)
16537 +{
16538 +       return hash_long((unsigned long)dev, bits);
16539 +}
16540 +
16541 +
16542 +/*     __hash_mapping()
16543 + *     add the mapping to the hash table
16544 + */
16545 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16546 +{
16547 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16548 +       struct hlist_head *head, *hash = dmap_main_hash;
16549 +       int device = vdm->device;
16550 +
16551 +       spin_lock(hash_lock);
16552 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16553 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16554 +
16555 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16556 +       hlist_add_head(&vdm->dm_hlist, head);
16557 +       spin_unlock(hash_lock);
16558 +}
16559 +
16560 +
16561 +static inline int __mode_to_default(umode_t mode)
16562 +{
16563 +       switch (mode) {
16564 +       case S_IFBLK:
16565 +               return 0;
16566 +       case S_IFCHR:
16567 +               return 1;
16568 +       default:
16569 +               BUG();
16570 +       }
16571 +}
16572 +
16573 +
16574 +/*     __set_default()
16575 + *     set a default
16576 + */
16577 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16578 +       struct vx_dmap_target *vdmt)
16579 +{
16580 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16581 +       spin_lock(hash_lock);
16582 +
16583 +       if (vxi)
16584 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16585 +       else
16586 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16587 +
16588 +
16589 +       spin_unlock(hash_lock);
16590 +
16591 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16592 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16593 +}
16594 +
16595 +
16596 +/*     __remove_default()
16597 + *     remove a default
16598 + */
16599 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16600 +{
16601 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16602 +       spin_lock(hash_lock);
16603 +
16604 +       if (vxi)
16605 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16606 +       else    /* remove == reset */
16607 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16608 +
16609 +       spin_unlock(hash_lock);
16610 +       return 0;
16611 +}
16612 +
16613 +
16614 +/*     __find_mapping()
16615 + *     find a mapping in the hash table
16616 + *
16617 + *     caller must hold hash_lock
16618 + */
16619 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16620 +       struct vs_mapping **local, struct vs_mapping **global)
16621 +{
16622 +       struct hlist_head *hash = dmap_main_hash;
16623 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16624 +       struct hlist_node *pos;
16625 +       struct vs_mapping *vdm;
16626 +
16627 +       *local = NULL;
16628 +       if (global)
16629 +               *global = NULL;
16630 +
16631 +       hlist_for_each(pos, head) {
16632 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16633 +
16634 +               if ((vdm->device == device) &&
16635 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16636 +                       if (vdm->xid == xid) {
16637 +                               *local = vdm;
16638 +                               return 1;
16639 +                       } else if (global && vdm->xid == 0)
16640 +                               *global = vdm;
16641 +               }
16642 +       }
16643 +
16644 +       if (global && *global)
16645 +               return 0;
16646 +       else
16647 +               return -ENOENT;
16648 +}
16649 +
16650 +
16651 +/*     __lookup_mapping()
16652 + *     find a mapping and store the result in target and flags
16653 + */
16654 +static inline int __lookup_mapping(struct vx_info *vxi,
16655 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16656 +{
16657 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16658 +       struct vs_mapping *vdm, *global;
16659 +       struct vx_dmap_target *vdmt;
16660 +       int ret = 0;
16661 +       vxid_t xid = vxi->vx_id;
16662 +       int index;
16663 +
16664 +       spin_lock(hash_lock);
16665 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16666 +               ret = 1;
16667 +               vdmt = &vdm->target;
16668 +               goto found;
16669 +       }
16670 +
16671 +       index = __mode_to_default(mode);
16672 +       if (vxi && vxi->dmap.targets[index].flags) {
16673 +               ret = 2;
16674 +               vdmt = &vxi->dmap.targets[index];
16675 +       } else if (global) {
16676 +               ret = 3;
16677 +               vdmt = &global->target;
16678 +               goto found;
16679 +       } else {
16680 +               ret = 4;
16681 +               vdmt = &dmap_defaults[index];
16682 +       }
16683 +
16684 +found:
16685 +       if (target && (vdmt->flags & DATTR_REMAP))
16686 +               *target = vdmt->target;
16687 +       else if (target)
16688 +               *target = device;
16689 +       if (flags)
16690 +               *flags = vdmt->flags;
16691 +
16692 +       spin_unlock(hash_lock);
16693 +
16694 +       return ret;
16695 +}
16696 +
16697 +
16698 +/*     __remove_mapping()
16699 + *     remove a mapping from the hash table
16700 + */
16701 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16702 +       umode_t mode)
16703 +{
16704 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16705 +       struct vs_mapping *vdm = NULL;
16706 +       int ret = 0;
16707 +
16708 +       spin_lock(hash_lock);
16709 +
16710 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16711 +               NULL);
16712 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16713 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16714 +       if (ret < 0)
16715 +               goto out;
16716 +       hlist_del(&vdm->dm_hlist);
16717 +
16718 +out:
16719 +       spin_unlock(hash_lock);
16720 +       if (vdm)
16721 +               kmem_cache_free(dmap_cachep, vdm);
16722 +       return ret;
16723 +}
16724 +
16725 +
16726 +
16727 +int vs_map_device(struct vx_info *vxi,
16728 +       dev_t device, dev_t *target, umode_t mode)
16729 +{
16730 +       int ret, flags = DATTR_MASK;
16731 +
16732 +       if (!vxi) {
16733 +               if (target)
16734 +                       *target = device;
16735 +               goto out;
16736 +       }
16737 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16738 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16739 +               device, target ? *target : 0, flags, mode, ret);
16740 +out:
16741 +       return (flags & DATTR_MASK);
16742 +}
16743 +
16744 +
16745 +
16746 +static int do_set_mapping(struct vx_info *vxi,
16747 +       dev_t device, dev_t target, int flags, umode_t mode)
16748 +{
16749 +       if (device) {
16750 +               struct vs_mapping *new;
16751 +
16752 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16753 +               if (!new)
16754 +                       return -ENOMEM;
16755 +
16756 +               INIT_HLIST_NODE(&new->dm_hlist);
16757 +               new->device = device;
16758 +               new->target.target = target;
16759 +               new->target.flags = flags | mode;
16760 +               new->xid = (vxi ? vxi->vx_id : 0);
16761 +
16762 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16763 +               __hash_mapping(vxi, new);
16764 +       } else {
16765 +               struct vx_dmap_target new = {
16766 +                       .target = target,
16767 +                       .flags = flags | mode,
16768 +               };
16769 +               __set_default(vxi, mode, &new);
16770 +       }
16771 +       return 0;
16772 +}
16773 +
16774 +
16775 +static int do_unset_mapping(struct vx_info *vxi,
16776 +       dev_t device, dev_t target, int flags, umode_t mode)
16777 +{
16778 +       int ret = -EINVAL;
16779 +
16780 +       if (device) {
16781 +               ret = __remove_mapping(vxi, device, mode);
16782 +               if (ret < 0)
16783 +                       goto out;
16784 +       } else {
16785 +               ret = __remove_default(vxi, mode);
16786 +               if (ret < 0)
16787 +                       goto out;
16788 +       }
16789 +
16790 +out:
16791 +       return ret;
16792 +}
16793 +
16794 +
16795 +static inline int __user_device(const char __user *name, dev_t *dev,
16796 +       umode_t *mode)
16797 +{
16798 +       struct nameidata nd;
16799 +       int ret;
16800 +
16801 +       if (!name) {
16802 +               *dev = 0;
16803 +               return 0;
16804 +       }
16805 +       ret = user_lpath(name, &nd.path);
16806 +       if (ret)
16807 +               return ret;
16808 +       if (nd.path.dentry->d_inode) {
16809 +               *dev = nd.path.dentry->d_inode->i_rdev;
16810 +               *mode = nd.path.dentry->d_inode->i_mode;
16811 +       }
16812 +       path_put(&nd.path);
16813 +       return 0;
16814 +}
16815 +
16816 +static inline int __mapping_mode(dev_t device, dev_t target,
16817 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16818 +{
16819 +       if (device)
16820 +               *mode = device_mode & S_IFMT;
16821 +       else if (target)
16822 +               *mode = target_mode & S_IFMT;
16823 +       else
16824 +               return -EINVAL;
16825 +
16826 +       /* if both given, device and target mode have to match */
16827 +       if (device && target &&
16828 +               ((device_mode ^ target_mode) & S_IFMT))
16829 +               return -EINVAL;
16830 +       return 0;
16831 +}
16832 +
16833 +
16834 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16835 +       const char __user *target_path, int flags, int set)
16836 +{
16837 +       dev_t device = ~0, target = ~0;
16838 +       umode_t device_mode = 0, target_mode = 0, mode;
16839 +       int ret;
16840 +
16841 +       ret = __user_device(device_path, &device, &device_mode);
16842 +       if (ret)
16843 +               return ret;
16844 +       ret = __user_device(target_path, &target, &target_mode);
16845 +       if (ret)
16846 +               return ret;
16847 +
16848 +       ret = __mapping_mode(device, target,
16849 +               device_mode, target_mode, &mode);
16850 +       if (ret)
16851 +               return ret;
16852 +
16853 +       if (set)
16854 +               return do_set_mapping(vxi, device, target,
16855 +                       flags, mode);
16856 +       else
16857 +               return do_unset_mapping(vxi, device, target,
16858 +                       flags, mode);
16859 +}
16860 +
16861 +
16862 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16863 +{
16864 +       struct vcmd_set_mapping_v0 vc_data;
16865 +
16866 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16867 +               return -EFAULT;
16868 +
16869 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16870 +               vc_data.flags, 1);
16871 +}
16872 +
16873 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16874 +{
16875 +       struct vcmd_set_mapping_v0 vc_data;
16876 +
16877 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16878 +               return -EFAULT;
16879 +
16880 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16881 +               vc_data.flags, 0);
16882 +}
16883 +
16884 +
16885 +#ifdef CONFIG_COMPAT
16886 +
16887 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16888 +{
16889 +       struct vcmd_set_mapping_v0_x32 vc_data;
16890 +
16891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16892 +               return -EFAULT;
16893 +
16894 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16895 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16896 +}
16897 +
16898 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16899 +{
16900 +       struct vcmd_set_mapping_v0_x32 vc_data;
16901 +
16902 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16903 +               return -EFAULT;
16904 +
16905 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16906 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16907 +}
16908 +
16909 +#endif /* CONFIG_COMPAT */
16910 +
16911 +
16912 diff -NurpP --minimal linux-3.13.10/kernel/vserver/dlimit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c
16913 --- linux-3.13.10/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16914 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c    2014-01-31 20:38:04.000000000 +0000
16915 @@ -0,0 +1,528 @@
16916 +/*
16917 + *  linux/kernel/vserver/dlimit.c
16918 + *
16919 + *  Virtual Server: Context Disk Limits
16920 + *
16921 + *  Copyright (C) 2004-2009  Herbert Pötzl
16922 + *
16923 + *  V0.01  initial version
16924 + *  V0.02  compat32 splitup
16925 + *  V0.03  extended interface
16926 + *
16927 + */
16928 +
16929 +#include <linux/statfs.h>
16930 +#include <linux/sched.h>
16931 +#include <linux/namei.h>
16932 +#include <linux/vs_tag.h>
16933 +#include <linux/vs_dlimit.h>
16934 +#include <linux/vserver/dlimit_cmd.h>
16935 +#include <linux/slab.h>
16936 +// #include <linux/gfp.h>
16937 +
16938 +#include <asm/uaccess.h>
16939 +
16940 +/*     __alloc_dl_info()
16941 +
16942 +       * allocate an initialized dl_info struct
16943 +       * doesn't make it visible (hash)                        */
16944 +
16945 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16946 +{
16947 +       struct dl_info *new = NULL;
16948 +
16949 +       vxdprintk(VXD_CBIT(dlim, 5),
16950 +               "alloc_dl_info(%p,%d)*", sb, tag);
16951 +
16952 +       /* would this benefit from a slab cache? */
16953 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16954 +       if (!new)
16955 +               return 0;
16956 +
16957 +       memset(new, 0, sizeof(struct dl_info));
16958 +       new->dl_tag = tag;
16959 +       new->dl_sb = sb;
16960 +       // INIT_RCU_HEAD(&new->dl_rcu);
16961 +       INIT_HLIST_NODE(&new->dl_hlist);
16962 +       spin_lock_init(&new->dl_lock);
16963 +       atomic_set(&new->dl_refcnt, 0);
16964 +       atomic_set(&new->dl_usecnt, 0);
16965 +
16966 +       /* rest of init goes here */
16967 +
16968 +       vxdprintk(VXD_CBIT(dlim, 4),
16969 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16970 +       return new;
16971 +}
16972 +
16973 +/*     __dealloc_dl_info()
16974 +
16975 +       * final disposal of dl_info                             */
16976 +
16977 +static void __dealloc_dl_info(struct dl_info *dli)
16978 +{
16979 +       vxdprintk(VXD_CBIT(dlim, 4),
16980 +               "dealloc_dl_info(%p)", dli);
16981 +
16982 +       dli->dl_hlist.next = LIST_POISON1;
16983 +       dli->dl_tag = -1;
16984 +       dli->dl_sb = 0;
16985 +
16986 +       BUG_ON(atomic_read(&dli->dl_usecnt));
16987 +       BUG_ON(atomic_read(&dli->dl_refcnt));
16988 +
16989 +       kfree(dli);
16990 +}
16991 +
16992 +
16993 +/*     hash table for dl_info hash */
16994 +
16995 +#define DL_HASH_SIZE   13
16996 +
16997 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
16998 +
16999 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17000 +
17001 +
17002 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17003 +{
17004 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17005 +}
17006 +
17007 +
17008 +
17009 +/*     __hash_dl_info()
17010 +
17011 +       * add the dli to the global hash table
17012 +       * requires the hash_lock to be held                     */
17013 +
17014 +static inline void __hash_dl_info(struct dl_info *dli)
17015 +{
17016 +       struct hlist_head *head;
17017 +
17018 +       vxdprintk(VXD_CBIT(dlim, 6),
17019 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17020 +       get_dl_info(dli);
17021 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17022 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17023 +}
17024 +
17025 +/*     __unhash_dl_info()
17026 +
17027 +       * remove the dli from the global hash table
17028 +       * requires the hash_lock to be held                     */
17029 +
17030 +static inline void __unhash_dl_info(struct dl_info *dli)
17031 +{
17032 +       vxdprintk(VXD_CBIT(dlim, 6),
17033 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17034 +       hlist_del_rcu(&dli->dl_hlist);
17035 +       put_dl_info(dli);
17036 +}
17037 +
17038 +
17039 +/*     __lookup_dl_info()
17040 +
17041 +       * requires the rcu_read_lock()
17042 +       * doesn't increment the dl_refcnt                       */
17043 +
17044 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17045 +{
17046 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17047 +       struct dl_info *dli;
17048 +
17049 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17050 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17051 +                       return dli;
17052 +       }
17053 +       return NULL;
17054 +}
17055 +
17056 +
17057 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17058 +{
17059 +       struct dl_info *dli;
17060 +
17061 +       rcu_read_lock();
17062 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17063 +       vxdprintk(VXD_CBIT(dlim, 7),
17064 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17065 +       rcu_read_unlock();
17066 +       return dli;
17067 +}
17068 +
17069 +void rcu_free_dl_info(struct rcu_head *head)
17070 +{
17071 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17072 +       int usecnt, refcnt;
17073 +
17074 +       BUG_ON(!dli || !head);
17075 +
17076 +       usecnt = atomic_read(&dli->dl_usecnt);
17077 +       BUG_ON(usecnt < 0);
17078 +
17079 +       refcnt = atomic_read(&dli->dl_refcnt);
17080 +       BUG_ON(refcnt < 0);
17081 +
17082 +       vxdprintk(VXD_CBIT(dlim, 3),
17083 +               "rcu_free_dl_info(%p)", dli);
17084 +       if (!usecnt)
17085 +               __dealloc_dl_info(dli);
17086 +       else
17087 +               printk("!!! rcu didn't free\n");
17088 +}
17089 +
17090 +
17091 +
17092 +
17093 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17094 +       uint32_t flags, int add)
17095 +{
17096 +       struct path path;
17097 +       int ret;
17098 +
17099 +       ret = user_lpath(name, &path);
17100 +       if (!ret) {
17101 +               struct super_block *sb;
17102 +               struct dl_info *dli;
17103 +
17104 +               ret = -EINVAL;
17105 +               if (!path.dentry->d_inode)
17106 +                       goto out_release;
17107 +               if (!(sb = path.dentry->d_inode->i_sb))
17108 +                       goto out_release;
17109 +
17110 +               if (add) {
17111 +                       dli = __alloc_dl_info(sb, id);
17112 +                       spin_lock(&dl_info_hash_lock);
17113 +
17114 +                       ret = -EEXIST;
17115 +                       if (__lookup_dl_info(sb, id))
17116 +                               goto out_unlock;
17117 +                       __hash_dl_info(dli);
17118 +                       dli = NULL;
17119 +               } else {
17120 +                       spin_lock(&dl_info_hash_lock);
17121 +                       dli = __lookup_dl_info(sb, id);
17122 +
17123 +                       ret = -ESRCH;
17124 +                       if (!dli)
17125 +                               goto out_unlock;
17126 +                       __unhash_dl_info(dli);
17127 +               }
17128 +               ret = 0;
17129 +       out_unlock:
17130 +               spin_unlock(&dl_info_hash_lock);
17131 +               if (add && dli)
17132 +                       __dealloc_dl_info(dli);
17133 +       out_release:
17134 +               path_put(&path);
17135 +       }
17136 +       return ret;
17137 +}
17138 +
17139 +int vc_add_dlimit(uint32_t id, void __user *data)
17140 +{
17141 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17142 +
17143 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17144 +               return -EFAULT;
17145 +
17146 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17147 +}
17148 +
17149 +int vc_rem_dlimit(uint32_t id, void __user *data)
17150 +{
17151 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17152 +
17153 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17154 +               return -EFAULT;
17155 +
17156 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17157 +}
17158 +
17159 +#ifdef CONFIG_COMPAT
17160 +
17161 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17162 +{
17163 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17164 +
17165 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17166 +               return -EFAULT;
17167 +
17168 +       return do_addrem_dlimit(id,
17169 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17170 +}
17171 +
17172 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17173 +{
17174 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17175 +
17176 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17177 +               return -EFAULT;
17178 +
17179 +       return do_addrem_dlimit(id,
17180 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17181 +}
17182 +
17183 +#endif /* CONFIG_COMPAT */
17184 +
17185 +
17186 +static inline
17187 +int do_set_dlimit(uint32_t id, const char __user *name,
17188 +       uint32_t space_used, uint32_t space_total,
17189 +       uint32_t inodes_used, uint32_t inodes_total,
17190 +       uint32_t reserved, uint32_t flags)
17191 +{
17192 +       struct path path;
17193 +       int ret;
17194 +
17195 +       ret = user_lpath(name, &path);
17196 +       if (!ret) {
17197 +               struct super_block *sb;
17198 +               struct dl_info *dli;
17199 +
17200 +               ret = -EINVAL;
17201 +               if (!path.dentry->d_inode)
17202 +                       goto out_release;
17203 +               if (!(sb = path.dentry->d_inode->i_sb))
17204 +                       goto out_release;
17205 +
17206 +               /* sanity checks */
17207 +               if ((reserved != CDLIM_KEEP &&
17208 +                       reserved > 100) ||
17209 +                       (inodes_used != CDLIM_KEEP &&
17210 +                       inodes_used > inodes_total) ||
17211 +                       (space_used != CDLIM_KEEP &&
17212 +                       space_used > space_total))
17213 +                       goto out_release;
17214 +
17215 +               ret = -ESRCH;
17216 +               dli = locate_dl_info(sb, id);
17217 +               if (!dli)
17218 +                       goto out_release;
17219 +
17220 +               spin_lock(&dli->dl_lock);
17221 +
17222 +               if (inodes_used != CDLIM_KEEP)
17223 +                       dli->dl_inodes_used = inodes_used;
17224 +               if (inodes_total != CDLIM_KEEP)
17225 +                       dli->dl_inodes_total = inodes_total;
17226 +               if (space_used != CDLIM_KEEP)
17227 +                       dli->dl_space_used = dlimit_space_32to64(
17228 +                               space_used, flags, DLIMS_USED);
17229 +
17230 +               if (space_total == CDLIM_INFINITY)
17231 +                       dli->dl_space_total = DLIM_INFINITY;
17232 +               else if (space_total != CDLIM_KEEP)
17233 +                       dli->dl_space_total = dlimit_space_32to64(
17234 +                               space_total, flags, DLIMS_TOTAL);
17235 +
17236 +               if (reserved != CDLIM_KEEP)
17237 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17238 +
17239 +               spin_unlock(&dli->dl_lock);
17240 +
17241 +               put_dl_info(dli);
17242 +               ret = 0;
17243 +
17244 +       out_release:
17245 +               path_put(&path);
17246 +       }
17247 +       return ret;
17248 +}
17249 +
17250 +int vc_set_dlimit(uint32_t id, void __user *data)
17251 +{
17252 +       struct vcmd_ctx_dlimit_v0 vc_data;
17253 +
17254 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17255 +               return -EFAULT;
17256 +
17257 +       return do_set_dlimit(id, vc_data.name,
17258 +               vc_data.space_used, vc_data.space_total,
17259 +               vc_data.inodes_used, vc_data.inodes_total,
17260 +               vc_data.reserved, vc_data.flags);
17261 +}
17262 +
17263 +#ifdef CONFIG_COMPAT
17264 +
17265 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17266 +{
17267 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17268 +
17269 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17270 +               return -EFAULT;
17271 +
17272 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17273 +               vc_data.space_used, vc_data.space_total,
17274 +               vc_data.inodes_used, vc_data.inodes_total,
17275 +               vc_data.reserved, vc_data.flags);
17276 +}
17277 +
17278 +#endif /* CONFIG_COMPAT */
17279 +
17280 +
17281 +static inline
17282 +int do_get_dlimit(uint32_t id, const char __user *name,
17283 +       uint32_t *space_used, uint32_t *space_total,
17284 +       uint32_t *inodes_used, uint32_t *inodes_total,
17285 +       uint32_t *reserved, uint32_t *flags)
17286 +{
17287 +       struct path path;
17288 +       int ret;
17289 +
17290 +       ret = user_lpath(name, &path);
17291 +       if (!ret) {
17292 +               struct super_block *sb;
17293 +               struct dl_info *dli;
17294 +
17295 +               ret = -EINVAL;
17296 +               if (!path.dentry->d_inode)
17297 +                       goto out_release;
17298 +               if (!(sb = path.dentry->d_inode->i_sb))
17299 +                       goto out_release;
17300 +
17301 +               ret = -ESRCH;
17302 +               dli = locate_dl_info(sb, id);
17303 +               if (!dli)
17304 +                       goto out_release;
17305 +
17306 +               spin_lock(&dli->dl_lock);
17307 +               *inodes_used = dli->dl_inodes_used;
17308 +               *inodes_total = dli->dl_inodes_total;
17309 +
17310 +               *space_used = dlimit_space_64to32(
17311 +                       dli->dl_space_used, flags, DLIMS_USED);
17312 +
17313 +               if (dli->dl_space_total == DLIM_INFINITY)
17314 +                       *space_total = CDLIM_INFINITY;
17315 +               else
17316 +                       *space_total = dlimit_space_64to32(
17317 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17318 +
17319 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17320 +               spin_unlock(&dli->dl_lock);
17321 +
17322 +               put_dl_info(dli);
17323 +               ret = -EFAULT;
17324 +
17325 +               ret = 0;
17326 +       out_release:
17327 +               path_put(&path);
17328 +       }
17329 +       return ret;
17330 +}
17331 +
17332 +
17333 +int vc_get_dlimit(uint32_t id, void __user *data)
17334 +{
17335 +       struct vcmd_ctx_dlimit_v0 vc_data;
17336 +       int ret;
17337 +
17338 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17339 +               return -EFAULT;
17340 +
17341 +       ret = do_get_dlimit(id, vc_data.name,
17342 +               &vc_data.space_used, &vc_data.space_total,
17343 +               &vc_data.inodes_used, &vc_data.inodes_total,
17344 +               &vc_data.reserved, &vc_data.flags);
17345 +       if (ret)
17346 +               return ret;
17347 +
17348 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17349 +               return -EFAULT;
17350 +       return 0;
17351 +}
17352 +
17353 +#ifdef CONFIG_COMPAT
17354 +
17355 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17356 +{
17357 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17358 +       int ret;
17359 +
17360 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17361 +               return -EFAULT;
17362 +
17363 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17364 +               &vc_data.space_used, &vc_data.space_total,
17365 +               &vc_data.inodes_used, &vc_data.inodes_total,
17366 +               &vc_data.reserved, &vc_data.flags);
17367 +       if (ret)
17368 +               return ret;
17369 +
17370 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17371 +               return -EFAULT;
17372 +       return 0;
17373 +}
17374 +
17375 +#endif /* CONFIG_COMPAT */
17376 +
17377 +
17378 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17379 +{
17380 +       struct dl_info *dli;
17381 +       __u64 blimit, bfree, bavail;
17382 +       __u32 ifree;
17383 +
17384 +       dli = locate_dl_info(sb, dx_current_tag());
17385 +       if (!dli)
17386 +               return;
17387 +
17388 +       spin_lock(&dli->dl_lock);
17389 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17390 +               goto no_ilim;
17391 +
17392 +       /* reduce max inodes available to limit */
17393 +       if (buf->f_files > dli->dl_inodes_total)
17394 +               buf->f_files = dli->dl_inodes_total;
17395 +
17396 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17397 +       /* reduce free inodes to min */
17398 +       if (ifree < buf->f_ffree)
17399 +               buf->f_ffree = ifree;
17400 +
17401 +no_ilim:
17402 +       if (dli->dl_space_total == DLIM_INFINITY)
17403 +               goto no_blim;
17404 +
17405 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17406 +
17407 +       if (dli->dl_space_total < dli->dl_space_used)
17408 +               bfree = 0;
17409 +       else
17410 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17411 +                       >> sb->s_blocksize_bits;
17412 +
17413 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17414 +       if (bavail < dli->dl_space_used)
17415 +               bavail = 0;
17416 +       else
17417 +               bavail = (bavail - dli->dl_space_used)
17418 +                       >> sb->s_blocksize_bits;
17419 +
17420 +       /* reduce max space available to limit */
17421 +       if (buf->f_blocks > blimit)
17422 +               buf->f_blocks = blimit;
17423 +
17424 +       /* reduce free space to min */
17425 +       if (bfree < buf->f_bfree)
17426 +               buf->f_bfree = bfree;
17427 +
17428 +       /* reduce avail space to min */
17429 +       if (bavail < buf->f_bavail)
17430 +               buf->f_bavail = bavail;
17431 +
17432 +no_blim:
17433 +       spin_unlock(&dli->dl_lock);
17434 +       put_dl_info(dli);
17435 +
17436 +       return;
17437 +}
17438 +
17439 +#include <linux/module.h>
17440 +
17441 +EXPORT_SYMBOL_GPL(locate_dl_info);
17442 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17443 +
17444 diff -NurpP --minimal linux-3.13.10/kernel/vserver/helper.c linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c
17445 --- linux-3.13.10/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17446 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c    2014-01-31 20:38:04.000000000 +0000
17447 @@ -0,0 +1,242 @@
17448 +/*
17449 + *  linux/kernel/vserver/helper.c
17450 + *
17451 + *  Virtual Context Support
17452 + *
17453 + *  Copyright (C) 2004-2007  Herbert Pötzl
17454 + *
17455 + *  V0.01  basic helper
17456 + *
17457 + */
17458 +
17459 +#include <linux/kmod.h>
17460 +#include <linux/reboot.h>
17461 +#include <linux/vs_context.h>
17462 +#include <linux/vs_network.h>
17463 +#include <linux/vserver/signal.h>
17464 +
17465 +
17466 +char vshelper_path[255] = "/sbin/vshelper";
17467 +
17468 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17469 +{
17470 +       current->flags &= ~PF_NO_SETAFFINITY;
17471 +       return 0;
17472 +}
17473 +
17474 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17475 +{
17476 +       struct subprocess_info *info;
17477 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17478 +
17479 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17480 +                                        vshelper_init, NULL, NULL);
17481 +       if (info == NULL)
17482 +               return -ENOMEM;
17483 +
17484 +       return call_usermodehelper_exec(info, wait);
17485 +}
17486 +
17487 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17488 +{
17489 +       int ret;
17490 +
17491 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17492 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17493 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17494 +                       name, argv[1], argv[2],
17495 +                       sync ? "sync" : "async", ret);
17496 +       }
17497 +       vxdprintk(VXD_CBIT(switch, 4),
17498 +               "%s: (%s %s) returned %s with %d",
17499 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17500 +       return ret;
17501 +}
17502 +
17503 +/*
17504 + *      vshelper path is set via /proc/sys
17505 + *      invoked by vserver sys_reboot(), with
17506 + *      the following arguments
17507 + *
17508 + *      argv [0] = vshelper_path;
17509 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17510 + *      argv [2] = context identifier
17511 + *
17512 + *      envp [*] = type-specific parameters
17513 + */
17514 +
17515 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17516 +{
17517 +       char id_buf[8], cmd_buf[16];
17518 +       char uid_buf[16], pid_buf[16];
17519 +       int ret;
17520 +
17521 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17522 +       char *envp[] = {"HOME=/", "TERM=linux",
17523 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17524 +                       uid_buf, pid_buf, cmd_buf, 0};
17525 +
17526 +       if (vx_info_state(vxi, VXS_HELPER))
17527 +               return -EAGAIN;
17528 +       vxi->vx_state |= VXS_HELPER;
17529 +
17530 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17531 +
17532 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17533 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17534 +               from_kuid(&init_user_ns, current_uid()));
17535 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17536 +
17537 +       switch (cmd) {
17538 +       case LINUX_REBOOT_CMD_RESTART:
17539 +               argv[1] = "restart";
17540 +               break;
17541 +
17542 +       case LINUX_REBOOT_CMD_HALT:
17543 +               argv[1] = "halt";
17544 +               break;
17545 +
17546 +       case LINUX_REBOOT_CMD_POWER_OFF:
17547 +               argv[1] = "poweroff";
17548 +               break;
17549 +
17550 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17551 +               argv[1] = "swsusp";
17552 +               break;
17553 +
17554 +       case LINUX_REBOOT_CMD_OOM:
17555 +               argv[1] = "oom";
17556 +               break;
17557 +
17558 +       default:
17559 +               vxi->vx_state &= ~VXS_HELPER;
17560 +               return 0;
17561 +       }
17562 +
17563 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17564 +       vxi->vx_state &= ~VXS_HELPER;
17565 +       __wakeup_vx_info(vxi);
17566 +       return (ret) ? -EPERM : 0;
17567 +}
17568 +
17569 +
17570 +long vs_reboot(unsigned int cmd, void __user *arg)
17571 +{
17572 +       struct vx_info *vxi = current_vx_info();
17573 +       long ret = 0;
17574 +
17575 +       vxdprintk(VXD_CBIT(misc, 5),
17576 +               "vs_reboot(%p[#%d],%u)",
17577 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17578 +
17579 +       ret = vs_reboot_helper(vxi, cmd, arg);
17580 +       if (ret)
17581 +               return ret;
17582 +
17583 +       vxi->reboot_cmd = cmd;
17584 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17585 +               switch (cmd) {
17586 +               case LINUX_REBOOT_CMD_RESTART:
17587 +               case LINUX_REBOOT_CMD_HALT:
17588 +               case LINUX_REBOOT_CMD_POWER_OFF:
17589 +                       vx_info_kill(vxi, 0, SIGKILL);
17590 +                       vx_info_kill(vxi, 1, SIGKILL);
17591 +               default:
17592 +                       break;
17593 +               }
17594 +       }
17595 +       return 0;
17596 +}
17597 +
17598 +long vs_oom_action(unsigned int cmd)
17599 +{
17600 +       struct vx_info *vxi = current_vx_info();
17601 +       long ret = 0;
17602 +
17603 +       vxdprintk(VXD_CBIT(misc, 5),
17604 +               "vs_oom_action(%p[#%d],%u)",
17605 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17606 +
17607 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17608 +       if (ret)
17609 +               return ret;
17610 +
17611 +       vxi->reboot_cmd = cmd;
17612 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17613 +               vx_info_kill(vxi, 0, SIGKILL);
17614 +               vx_info_kill(vxi, 1, SIGKILL);
17615 +       }
17616 +       return 0;
17617 +}
17618 +
17619 +/*
17620 + *      argv [0] = vshelper_path;
17621 + *      argv [1] = action: "startup", "shutdown"
17622 + *      argv [2] = context identifier
17623 + *
17624 + *      envp [*] = type-specific parameters
17625 + */
17626 +
17627 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17628 +{
17629 +       char id_buf[8], cmd_buf[16];
17630 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17631 +       char *envp[] = {"HOME=/", "TERM=linux",
17632 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17633 +
17634 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17635 +               return 0;
17636 +
17637 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17638 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17639 +
17640 +       switch (cmd) {
17641 +       case VSC_STARTUP:
17642 +               argv[1] = "startup";
17643 +               break;
17644 +       case VSC_SHUTDOWN:
17645 +               argv[1] = "shutdown";
17646 +               break;
17647 +       default:
17648 +               return 0;
17649 +       }
17650 +
17651 +       return do_vshelper(vshelper_path, argv, envp, 1);
17652 +}
17653 +
17654 +
17655 +/*
17656 + *      argv [0] = vshelper_path;
17657 + *      argv [1] = action: "netup", "netdown"
17658 + *      argv [2] = context identifier
17659 + *
17660 + *      envp [*] = type-specific parameters
17661 + */
17662 +
17663 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17664 +{
17665 +       char id_buf[8], cmd_buf[16];
17666 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17667 +       char *envp[] = {"HOME=/", "TERM=linux",
17668 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17669 +
17670 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17671 +               return 0;
17672 +
17673 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17674 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17675 +
17676 +       switch (cmd) {
17677 +       case VSC_NETUP:
17678 +               argv[1] = "netup";
17679 +               break;
17680 +       case VSC_NETDOWN:
17681 +               argv[1] = "netdown";
17682 +               break;
17683 +       default:
17684 +               return 0;
17685 +       }
17686 +
17687 +       return do_vshelper(vshelper_path, argv, envp, 1);
17688 +}
17689 +
17690 diff -NurpP --minimal linux-3.13.10/kernel/vserver/history.c linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c
17691 --- linux-3.13.10/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17692 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c   2014-01-31 20:38:04.000000000 +0000
17693 @@ -0,0 +1,258 @@
17694 +/*
17695 + *  kernel/vserver/history.c
17696 + *
17697 + *  Virtual Context History Backtrace
17698 + *
17699 + *  Copyright (C) 2004-2007  Herbert Pötzl
17700 + *
17701 + *  V0.01  basic structure
17702 + *  V0.02  hash/unhash and trace
17703 + *  V0.03  preemption fixes
17704 + *
17705 + */
17706 +
17707 +#include <linux/module.h>
17708 +#include <asm/uaccess.h>
17709 +
17710 +#include <linux/vserver/context.h>
17711 +#include <linux/vserver/debug.h>
17712 +#include <linux/vserver/debug_cmd.h>
17713 +#include <linux/vserver/history.h>
17714 +
17715 +
17716 +#ifdef CONFIG_VSERVER_HISTORY
17717 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17718 +#else
17719 +#define VXH_SIZE       64
17720 +#endif
17721 +
17722 +struct _vx_history {
17723 +       unsigned int counter;
17724 +
17725 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17726 +};
17727 +
17728 +
17729 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17730 +
17731 +unsigned volatile int vxh_active = 1;
17732 +
17733 +static atomic_t sequence = ATOMIC_INIT(0);
17734 +
17735 +
17736 +/*     vxh_advance()
17737 +
17738 +       * requires disabled preemption                          */
17739 +
17740 +struct _vx_hist_entry *vxh_advance(void *loc)
17741 +{
17742 +       unsigned int cpu = smp_processor_id();
17743 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17744 +       struct _vx_hist_entry *entry;
17745 +       unsigned int index;
17746 +
17747 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17748 +       entry = &hist->entry[index];
17749 +
17750 +       entry->seq = atomic_inc_return(&sequence);
17751 +       entry->loc = loc;
17752 +       return entry;
17753 +}
17754 +
17755 +EXPORT_SYMBOL_GPL(vxh_advance);
17756 +
17757 +
17758 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17759 +
17760 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17761 +
17762 +
17763 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17764 +
17765 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17766 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17767 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17768 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17769 +
17770 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17771 +{
17772 +       switch (e->type) {
17773 +       case VXH_THROW_OOPS:
17774 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17775 +               break;
17776 +
17777 +       case VXH_GET_VX_INFO:
17778 +       case VXH_PUT_VX_INFO:
17779 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17780 +                       VXH_LOC_ARGS(e),
17781 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17782 +                       VXH_VXI_ARGS(e));
17783 +               break;
17784 +
17785 +       case VXH_INIT_VX_INFO:
17786 +       case VXH_SET_VX_INFO:
17787 +       case VXH_CLR_VX_INFO:
17788 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17789 +                       VXH_LOC_ARGS(e),
17790 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17791 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17792 +                       VXH_VXI_ARGS(e), e->sc.data);
17793 +               break;
17794 +
17795 +       case VXH_CLAIM_VX_INFO:
17796 +       case VXH_RELEASE_VX_INFO:
17797 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17798 +                       VXH_LOC_ARGS(e),
17799 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17800 +                       VXH_VXI_ARGS(e), e->sc.data);
17801 +               break;
17802 +
17803 +       case VXH_ALLOC_VX_INFO:
17804 +       case VXH_DEALLOC_VX_INFO:
17805 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17806 +                       VXH_LOC_ARGS(e),
17807 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17808 +                       VXH_VXI_ARGS(e));
17809 +               break;
17810 +
17811 +       case VXH_HASH_VX_INFO:
17812 +       case VXH_UNHASH_VX_INFO:
17813 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17814 +                       VXH_LOC_ARGS(e),
17815 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17816 +                       VXH_VXI_ARGS(e));
17817 +               break;
17818 +
17819 +       case VXH_LOC_VX_INFO:
17820 +       case VXH_LOOKUP_VX_INFO:
17821 +       case VXH_CREATE_VX_INFO:
17822 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17823 +                       VXH_LOC_ARGS(e),
17824 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17825 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17826 +                       e->ll.arg, VXH_VXI_ARGS(e));
17827 +               break;
17828 +       }
17829 +}
17830 +
17831 +static void __vxh_dump_history(void)
17832 +{
17833 +       unsigned int i, cpu;
17834 +
17835 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17836 +               atomic_read(&sequence), NR_CPUS);
17837 +
17838 +       for (i = 0; i < VXH_SIZE; i++) {
17839 +               for_each_online_cpu(cpu) {
17840 +                       struct _vx_history *hist =
17841 +                               &per_cpu(vx_history_buffer, cpu);
17842 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17843 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17844 +
17845 +                       vxh_dump_entry(entry, cpu);
17846 +               }
17847 +       }
17848 +}
17849 +
17850 +void   vxh_dump_history(void)
17851 +{
17852 +       vxh_active = 0;
17853 +#ifdef CONFIG_SMP
17854 +       local_irq_enable();
17855 +       smp_send_stop();
17856 +       local_irq_disable();
17857 +#endif
17858 +       __vxh_dump_history();
17859 +}
17860 +
17861 +
17862 +/* vserver syscall commands below here */
17863 +
17864 +
17865 +int vc_dump_history(uint32_t id)
17866 +{
17867 +       vxh_active = 0;
17868 +       __vxh_dump_history();
17869 +       vxh_active = 1;
17870 +
17871 +       return 0;
17872 +}
17873 +
17874 +
17875 +int do_read_history(struct __user _vx_hist_entry *data,
17876 +       int cpu, uint32_t *index, uint32_t *count)
17877 +{
17878 +       int pos, ret = 0;
17879 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17880 +       int end = hist->counter;
17881 +       int start = end - VXH_SIZE + 2;
17882 +       int idx = *index;
17883 +
17884 +       /* special case: get current pos */
17885 +       if (!*count) {
17886 +               *index = end;
17887 +               return 0;
17888 +       }
17889 +
17890 +       /* have we lost some data? */
17891 +       if (idx < start)
17892 +               idx = start;
17893 +
17894 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17895 +               struct _vx_hist_entry *entry =
17896 +                       &hist->entry[idx % VXH_SIZE];
17897 +
17898 +               /* send entry to userspace */
17899 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17900 +               if (ret)
17901 +                       break;
17902 +       }
17903 +       /* save new index and count */
17904 +       *index = idx;
17905 +       *count = pos;
17906 +       return ret ? ret : (*index < end);
17907 +}
17908 +
17909 +int vc_read_history(uint32_t id, void __user *data)
17910 +{
17911 +       struct vcmd_read_history_v0 vc_data;
17912 +       int ret;
17913 +
17914 +       if (id >= NR_CPUS)
17915 +               return -EINVAL;
17916 +
17917 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17918 +               return -EFAULT;
17919 +
17920 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17921 +               id, &vc_data.index, &vc_data.count);
17922 +
17923 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17924 +               return -EFAULT;
17925 +       return ret;
17926 +}
17927 +
17928 +#ifdef CONFIG_COMPAT
17929 +
17930 +int vc_read_history_x32(uint32_t id, void __user *data)
17931 +{
17932 +       struct vcmd_read_history_v0_x32 vc_data;
17933 +       int ret;
17934 +
17935 +       if (id >= NR_CPUS)
17936 +               return -EINVAL;
17937 +
17938 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17939 +               return -EFAULT;
17940 +
17941 +       ret = do_read_history((struct __user _vx_hist_entry *)
17942 +               compat_ptr(vc_data.data_ptr),
17943 +               id, &vc_data.index, &vc_data.count);
17944 +
17945 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17946 +               return -EFAULT;
17947 +       return ret;
17948 +}
17949 +
17950 +#endif /* CONFIG_COMPAT */
17951 +
17952 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inet.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c
17953 --- linux-3.13.10/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17954 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c      2014-02-01 00:26:40.000000000 +0000
17955 @@ -0,0 +1,236 @@
17956 +
17957 +#include <linux/in.h>
17958 +#include <linux/inetdevice.h>
17959 +#include <linux/export.h>
17960 +#include <linux/vs_inet.h>
17961 +#include <linux/vs_inet6.h>
17962 +#include <linux/vserver/debug.h>
17963 +#include <net/route.h>
17964 +#include <net/addrconf.h>
17965 +
17966 +
17967 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17968 +{
17969 +       int ret = 0;
17970 +
17971 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17972 +               ret = 1;
17973 +       else {
17974 +               struct nx_addr_v4 *ptr;
17975 +               unsigned long irqflags;
17976 +
17977 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17978 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17979 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17980 +                               ret = 1;
17981 +                               break;
17982 +                       }
17983 +               }
17984 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17985 +       }
17986 +
17987 +       vxdprintk(VXD_CBIT(net, 2),
17988 +               "nx_v4_addr_conflict(%p,%p): %d",
17989 +               nxi1, nxi2, ret);
17990 +
17991 +       return ret;
17992 +}
17993 +
17994 +
17995 +#ifdef CONFIG_IPV6
17996 +
17997 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17998 +{
17999 +       int ret = 0;
18000 +
18001 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18002 +               ret = 1;
18003 +       else {
18004 +               struct nx_addr_v6 *ptr;
18005 +               unsigned long irqflags;
18006 +
18007 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18008 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18009 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18010 +                               ret = 1;
18011 +                               break;
18012 +                       }
18013 +               }
18014 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18015 +       }
18016 +
18017 +       vxdprintk(VXD_CBIT(net, 2),
18018 +               "nx_v6_addr_conflict(%p,%p): %d",
18019 +               nxi1, nxi2, ret);
18020 +
18021 +       return ret;
18022 +}
18023 +
18024 +#endif
18025 +
18026 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18027 +{
18028 +       struct in_device *in_dev;
18029 +       struct in_ifaddr **ifap;
18030 +       struct in_ifaddr *ifa;
18031 +       int ret = 0;
18032 +
18033 +       if (!dev)
18034 +               goto out;
18035 +       in_dev = in_dev_get(dev);
18036 +       if (!in_dev)
18037 +               goto out;
18038 +
18039 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18040 +               ifap = &ifa->ifa_next) {
18041 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18042 +                       ret = 1;
18043 +                       break;
18044 +               }
18045 +       }
18046 +       in_dev_put(in_dev);
18047 +out:
18048 +       return ret;
18049 +}
18050 +
18051 +
18052 +#ifdef CONFIG_IPV6
18053 +
18054 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18055 +{
18056 +       struct inet6_dev *in_dev;
18057 +       struct inet6_ifaddr *ifa;
18058 +       int ret = 0;
18059 +
18060 +       if (!dev)
18061 +               goto out;
18062 +       in_dev = in6_dev_get(dev);
18063 +       if (!in_dev)
18064 +               goto out;
18065 +
18066 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18067 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18068 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18069 +                       ret = 1;
18070 +                       break;
18071 +               }
18072 +       }
18073 +       in6_dev_put(in_dev);
18074 +out:
18075 +       return ret;
18076 +}
18077 +
18078 +#endif
18079 +
18080 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18081 +{
18082 +       int ret = 1;
18083 +
18084 +       if (!nxi)
18085 +               goto out;
18086 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18087 +               goto out;
18088 +#ifdef CONFIG_IPV6
18089 +       ret = 2;
18090 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18091 +               goto out;
18092 +#endif
18093 +       ret = 0;
18094 +out:
18095 +       vxdprintk(VXD_CBIT(net, 3),
18096 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18097 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18098 +       return ret;
18099 +}
18100 +
18101 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18102 +       struct flowi4 *fl4)
18103 +{
18104 +       struct rtable *rt;
18105 +
18106 +       if (!nxi)
18107 +               return NULL;
18108 +
18109 +       /* FIXME: handle lback only case */
18110 +       if (!NX_IPV4(nxi))
18111 +               return ERR_PTR(-EPERM);
18112 +
18113 +       vxdprintk(VXD_CBIT(net, 4),
18114 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18115 +               nxi, nxi ? nxi->nx_id : 0,
18116 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18117 +
18118 +       /* single IP is unconditional */
18119 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18120 +               (fl4->saddr == INADDR_ANY))
18121 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18122 +
18123 +       if (fl4->saddr == INADDR_ANY) {
18124 +               struct nx_addr_v4 *ptr;
18125 +               __be32 found = 0;
18126 +
18127 +               rt = __ip_route_output_key(net, fl4);
18128 +               if (!IS_ERR(rt)) {
18129 +                       found = fl4->saddr;
18130 +                       ip_rt_put(rt);
18131 +                       vxdprintk(VXD_CBIT(net, 4),
18132 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18133 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18134 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18135 +                               goto found;
18136 +               }
18137 +
18138 +               WARN_ON_ONCE(in_irq());
18139 +               spin_lock_bh(&nxi->addr_lock);
18140 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18141 +                       __be32 primary = ptr->ip[0].s_addr;
18142 +                       __be32 mask = ptr->mask.s_addr;
18143 +                       __be32 neta = primary & mask;
18144 +
18145 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18146 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18147 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18148 +                               NIPQUAD(mask), NIPQUAD(neta));
18149 +                       if ((found & mask) != neta)
18150 +                               continue;
18151 +
18152 +                       fl4->saddr = primary;
18153 +                       rt = __ip_route_output_key(net, fl4);
18154 +                       vxdprintk(VXD_CBIT(net, 4),
18155 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18156 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18157 +                       if (!IS_ERR(rt)) {
18158 +                               found = fl4->saddr;
18159 +                               ip_rt_put(rt);
18160 +                               if (found == primary)
18161 +                                       goto found_unlock;
18162 +                       }
18163 +               }
18164 +               /* still no source ip? */
18165 +               found = ipv4_is_loopback(fl4->daddr)
18166 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18167 +       found_unlock:
18168 +               spin_unlock_bh(&nxi->addr_lock);
18169 +       found:
18170 +               /* assign src ip to flow */
18171 +               fl4->saddr = found;
18172 +
18173 +       } else {
18174 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18175 +                       return ERR_PTR(-EPERM);
18176 +       }
18177 +
18178 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18179 +               if (ipv4_is_loopback(fl4->daddr))
18180 +                       fl4->daddr = nxi->v4_lback.s_addr;
18181 +               if (ipv4_is_loopback(fl4->saddr))
18182 +                       fl4->saddr = nxi->v4_lback.s_addr;
18183 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18184 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18185 +               return ERR_PTR(-EPERM);
18186 +
18187 +       return NULL;
18188 +}
18189 +
18190 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18191 +
18192 diff -NurpP --minimal linux-3.13.10/kernel/vserver/init.c linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c
18193 --- linux-3.13.10/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18194 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c      2014-01-31 20:38:04.000000000 +0000
18195 @@ -0,0 +1,45 @@
18196 +/*
18197 + *  linux/kernel/init.c
18198 + *
18199 + *  Virtual Server Init
18200 + *
18201 + *  Copyright (C) 2004-2007  Herbert Pötzl
18202 + *
18203 + *  V0.01  basic structure
18204 + *
18205 + */
18206 +
18207 +#include <linux/init.h>
18208 +
18209 +int    vserver_register_sysctl(void);
18210 +void   vserver_unregister_sysctl(void);
18211 +
18212 +
18213 +static int __init init_vserver(void)
18214 +{
18215 +       int ret = 0;
18216 +
18217 +#ifdef CONFIG_VSERVER_DEBUG
18218 +       vserver_register_sysctl();
18219 +#endif
18220 +       return ret;
18221 +}
18222 +
18223 +
18224 +static void __exit exit_vserver(void)
18225 +{
18226 +
18227 +#ifdef CONFIG_VSERVER_DEBUG
18228 +       vserver_unregister_sysctl();
18229 +#endif
18230 +       return;
18231 +}
18232 +
18233 +/* FIXME: GFP_ZONETYPES gone
18234 +long vx_slab[GFP_ZONETYPES]; */
18235 +long vx_area;
18236 +
18237 +
18238 +module_init(init_vserver);
18239 +module_exit(exit_vserver);
18240 +
18241 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inode.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c
18242 --- linux-3.13.10/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18243 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c     2014-01-31 20:38:04.000000000 +0000
18244 @@ -0,0 +1,440 @@
18245 +/*
18246 + *  linux/kernel/vserver/inode.c
18247 + *
18248 + *  Virtual Server: File System Support
18249 + *
18250 + *  Copyright (C) 2004-2007  Herbert Pötzl
18251 + *
18252 + *  V0.01  separated from vcontext V0.05
18253 + *  V0.02  moved to tag (instead of xid)
18254 + *
18255 + */
18256 +
18257 +#include <linux/tty.h>
18258 +#include <linux/proc_fs.h>
18259 +#include <linux/devpts_fs.h>
18260 +#include <linux/fs.h>
18261 +#include <linux/file.h>
18262 +#include <linux/mount.h>
18263 +#include <linux/parser.h>
18264 +#include <linux/namei.h>
18265 +#include <linux/magic.h>
18266 +#include <linux/slab.h>
18267 +#include <linux/vserver/inode.h>
18268 +#include <linux/vserver/inode_cmd.h>
18269 +#include <linux/vs_base.h>
18270 +#include <linux/vs_tag.h>
18271 +
18272 +#include <asm/uaccess.h>
18273 +#include <../../fs/proc/internal.h>
18274 +
18275 +
18276 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18277 +{
18278 +       struct proc_dir_entry *entry;
18279 +
18280 +       if (!in || !in->i_sb)
18281 +               return -ESRCH;
18282 +
18283 +       *flags = IATTR_TAG
18284 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18285 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18286 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18287 +               | (IS_COW(in) ? IATTR_COW : 0);
18288 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18289 +
18290 +       if (S_ISDIR(in->i_mode))
18291 +               *mask |= IATTR_BARRIER;
18292 +
18293 +       if (IS_TAGGED(in)) {
18294 +               *tag = i_tag_read(in);
18295 +               *mask |= IATTR_TAG;
18296 +       }
18297 +
18298 +       switch (in->i_sb->s_magic) {
18299 +       case PROC_SUPER_MAGIC:
18300 +               entry = PROC_I(in)->pde;
18301 +
18302 +               /* check for specific inodes? */
18303 +               if (entry)
18304 +                       *mask |= IATTR_FLAGS;
18305 +               if (entry)
18306 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18307 +               else
18308 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18309 +               break;
18310 +
18311 +       case DEVPTS_SUPER_MAGIC:
18312 +               *tag = i_tag_read(in);
18313 +               *mask |= IATTR_TAG;
18314 +               break;
18315 +
18316 +       default:
18317 +               break;
18318 +       }
18319 +       return 0;
18320 +}
18321 +
18322 +int vc_get_iattr(void __user *data)
18323 +{
18324 +       struct path path;
18325 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18326 +       int ret;
18327 +
18328 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18329 +               return -EFAULT;
18330 +
18331 +       ret = user_lpath(vc_data.name, &path);
18332 +       if (!ret) {
18333 +               ret = __vc_get_iattr(path.dentry->d_inode,
18334 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18335 +               path_put(&path);
18336 +       }
18337 +       if (ret)
18338 +               return ret;
18339 +
18340 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18341 +               ret = -EFAULT;
18342 +       return ret;
18343 +}
18344 +
18345 +#ifdef CONFIG_COMPAT
18346 +
18347 +int vc_get_iattr_x32(void __user *data)
18348 +{
18349 +       struct path path;
18350 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18351 +       int ret;
18352 +
18353 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18354 +               return -EFAULT;
18355 +
18356 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18357 +       if (!ret) {
18358 +               ret = __vc_get_iattr(path.dentry->d_inode,
18359 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18360 +               path_put(&path);
18361 +       }
18362 +       if (ret)
18363 +               return ret;
18364 +
18365 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18366 +               ret = -EFAULT;
18367 +       return ret;
18368 +}
18369 +
18370 +#endif /* CONFIG_COMPAT */
18371 +
18372 +
18373 +int vc_fget_iattr(uint32_t fd, void __user *data)
18374 +{
18375 +       struct file *filp;
18376 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18377 +       int ret;
18378 +
18379 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18380 +               return -EFAULT;
18381 +
18382 +       filp = fget(fd);
18383 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18384 +               return -EBADF;
18385 +
18386 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
18387 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18388 +
18389 +       fput(filp);
18390 +
18391 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18392 +               ret = -EFAULT;
18393 +       return ret;
18394 +}
18395 +
18396 +
18397 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18398 +{
18399 +       struct inode *in = de->d_inode;
18400 +       int error = 0, is_proc = 0, has_tag = 0;
18401 +       struct iattr attr = { 0 };
18402 +
18403 +       if (!in || !in->i_sb)
18404 +               return -ESRCH;
18405 +
18406 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18407 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18408 +               return -EINVAL;
18409 +
18410 +       has_tag = IS_TAGGED(in) ||
18411 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18412 +       if ((*mask & IATTR_TAG) && !has_tag)
18413 +               return -EINVAL;
18414 +
18415 +       mutex_lock(&in->i_mutex);
18416 +       if (*mask & IATTR_TAG) {
18417 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18418 +               attr.ia_valid |= ATTR_TAG;
18419 +       }
18420 +
18421 +       if (*mask & IATTR_FLAGS) {
18422 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18423 +               unsigned int iflags = PROC_I(in)->vx_flags;
18424 +
18425 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18426 +                       | (*flags & IATTR_FLAGS);
18427 +               PROC_I(in)->vx_flags = iflags;
18428 +               if (entry)
18429 +                       entry->vx_flags = iflags;
18430 +       }
18431 +
18432 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18433 +               IATTR_BARRIER | IATTR_COW)) {
18434 +               int iflags = in->i_flags;
18435 +               int vflags = in->i_vflags;
18436 +
18437 +               if (*mask & IATTR_IMMUTABLE) {
18438 +                       if (*flags & IATTR_IMMUTABLE)
18439 +                               iflags |= S_IMMUTABLE;
18440 +                       else
18441 +                               iflags &= ~S_IMMUTABLE;
18442 +               }
18443 +               if (*mask & IATTR_IXUNLINK) {
18444 +                       if (*flags & IATTR_IXUNLINK)
18445 +                               iflags |= S_IXUNLINK;
18446 +                       else
18447 +                               iflags &= ~S_IXUNLINK;
18448 +               }
18449 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18450 +                       if (*flags & IATTR_BARRIER)
18451 +                               vflags |= V_BARRIER;
18452 +                       else
18453 +                               vflags &= ~V_BARRIER;
18454 +               }
18455 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18456 +                       if (*flags & IATTR_COW)
18457 +                               vflags |= V_COW;
18458 +                       else
18459 +                               vflags &= ~V_COW;
18460 +               }
18461 +               if (in->i_op && in->i_op->sync_flags) {
18462 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18463 +                       if (error)
18464 +                               goto out;
18465 +               }
18466 +       }
18467 +
18468 +       if (attr.ia_valid) {
18469 +               if (in->i_op && in->i_op->setattr)
18470 +                       error = in->i_op->setattr(de, &attr);
18471 +               else {
18472 +                       error = inode_change_ok(in, &attr);
18473 +                       if (!error) {
18474 +                               setattr_copy(in, &attr);
18475 +                               mark_inode_dirty(in);
18476 +                       }
18477 +               }
18478 +       }
18479 +
18480 +out:
18481 +       mutex_unlock(&in->i_mutex);
18482 +       return error;
18483 +}
18484 +
18485 +int vc_set_iattr(void __user *data)
18486 +{
18487 +       struct path path;
18488 +       struct vcmd_ctx_iattr_v1 vc_data;
18489 +       int ret;
18490 +
18491 +       if (!capable(CAP_LINUX_IMMUTABLE))
18492 +               return -EPERM;
18493 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18494 +               return -EFAULT;
18495 +
18496 +       ret = user_lpath(vc_data.name, &path);
18497 +       if (!ret) {
18498 +               ret = __vc_set_iattr(path.dentry,
18499 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18500 +               path_put(&path);
18501 +       }
18502 +
18503 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18504 +               ret = -EFAULT;
18505 +       return ret;
18506 +}
18507 +
18508 +#ifdef CONFIG_COMPAT
18509 +
18510 +int vc_set_iattr_x32(void __user *data)
18511 +{
18512 +       struct path path;
18513 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18514 +       int ret;
18515 +
18516 +       if (!capable(CAP_LINUX_IMMUTABLE))
18517 +               return -EPERM;
18518 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18519 +               return -EFAULT;
18520 +
18521 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18522 +       if (!ret) {
18523 +               ret = __vc_set_iattr(path.dentry,
18524 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18525 +               path_put(&path);
18526 +       }
18527 +
18528 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18529 +               ret = -EFAULT;
18530 +       return ret;
18531 +}
18532 +
18533 +#endif /* CONFIG_COMPAT */
18534 +
18535 +int vc_fset_iattr(uint32_t fd, void __user *data)
18536 +{
18537 +       struct file *filp;
18538 +       struct vcmd_ctx_fiattr_v0 vc_data;
18539 +       int ret;
18540 +
18541 +       if (!capable(CAP_LINUX_IMMUTABLE))
18542 +               return -EPERM;
18543 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18544 +               return -EFAULT;
18545 +
18546 +       filp = fget(fd);
18547 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18548 +               return -EBADF;
18549 +
18550 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18551 +               &vc_data.flags, &vc_data.mask);
18552 +
18553 +       fput(filp);
18554 +
18555 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18556 +               return -EFAULT;
18557 +       return ret;
18558 +}
18559 +
18560 +
18561 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18562 +
18563 +static match_table_t tokens = {
18564 +       {Opt_notagcheck, "notagcheck"},
18565 +#ifdef CONFIG_PROPAGATE
18566 +       {Opt_notag, "notag"},
18567 +       {Opt_tag, "tag"},
18568 +       {Opt_tagid, "tagid=%u"},
18569 +#endif
18570 +       {Opt_err, NULL}
18571 +};
18572 +
18573 +
18574 +static void __dx_parse_remove(char *string, char *opt)
18575 +{
18576 +       char *p = strstr(string, opt);
18577 +       char *q = p;
18578 +
18579 +       if (p) {
18580 +               while (*q != '\0' && *q != ',')
18581 +                       q++;
18582 +               while (*q)
18583 +                       *p++ = *q++;
18584 +               while (*p)
18585 +                       *p++ = '\0';
18586 +       }
18587 +}
18588 +
18589 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18590 +                unsigned long *flags)
18591 +{
18592 +       int set = 0;
18593 +       substring_t args[MAX_OPT_ARGS];
18594 +       int token;
18595 +       char *s, *p, *opts;
18596 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18597 +       int option = 0;
18598 +#endif
18599 +
18600 +       if (!string)
18601 +               return 0;
18602 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18603 +       if (!s)
18604 +               return 0;
18605 +
18606 +       opts = s;
18607 +       while ((p = strsep(&opts, ",")) != NULL) {
18608 +               token = match_token(p, tokens, args);
18609 +
18610 +               switch (token) {
18611 +#ifdef CONFIG_PROPAGATE
18612 +               case Opt_tag:
18613 +                       if (tag)
18614 +                               *tag = 0;
18615 +                       if (remove)
18616 +                               __dx_parse_remove(s, "tag");
18617 +                       *mnt_flags |= MNT_TAGID;
18618 +                       set |= MNT_TAGID;
18619 +                       break;
18620 +               case Opt_notag:
18621 +                       if (remove)
18622 +                               __dx_parse_remove(s, "notag");
18623 +                       *mnt_flags |= MNT_NOTAG;
18624 +                       set |= MNT_NOTAG;
18625 +                       break;
18626 +               case Opt_tagid:
18627 +                       if (tag && !match_int(args, &option))
18628 +                               *tag = option;
18629 +                       if (remove)
18630 +                               __dx_parse_remove(s, "tagid");
18631 +                       *mnt_flags |= MNT_TAGID;
18632 +                       set |= MNT_TAGID;
18633 +                       break;
18634 +#endif /* CONFIG_PROPAGATE */
18635 +               case Opt_notagcheck:
18636 +                       if (remove)
18637 +                               __dx_parse_remove(s, "notagcheck");
18638 +                       *flags |= MS_NOTAGCHECK;
18639 +                       set |= MS_NOTAGCHECK;
18640 +                       break;
18641 +               }
18642 +               vxdprintk(VXD_CBIT(tag, 7),
18643 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18644 +                       p, token, option);
18645 +       }
18646 +       if (set)
18647 +               strcpy(string, s);
18648 +       kfree(s);
18649 +       return set;
18650 +}
18651 +
18652 +#ifdef CONFIG_PROPAGATE
18653 +
18654 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18655 +{
18656 +       vtag_t new_tag = 0;
18657 +       struct vfsmount *mnt;
18658 +       int propagate;
18659 +
18660 +       if (!nd)
18661 +               return;
18662 +       mnt = nd->path.mnt;
18663 +       if (!mnt)
18664 +               return;
18665 +
18666 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18667 +       if (propagate)
18668 +               new_tag = mnt->mnt_tag;
18669 +
18670 +       vxdprintk(VXD_CBIT(tag, 7),
18671 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18672 +               inode, inode->i_ino, inode->i_tag,
18673 +               new_tag, (propagate) ? 1 : 0);
18674 +
18675 +       if (propagate)
18676 +               i_tag_write(inode, new_tag);
18677 +}
18678 +
18679 +#include <linux/module.h>
18680 +
18681 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18682 +
18683 +#endif /* CONFIG_PROPAGATE */
18684 +
18685 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c
18686 --- linux-3.13.10/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18687 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c     2014-02-01 00:22:08.000000000 +0000
18688 @@ -0,0 +1,345 @@
18689 +/*
18690 + *  linux/kernel/vserver/limit.c
18691 + *
18692 + *  Virtual Server: Context Limits
18693 + *
18694 + *  Copyright (C) 2004-2010  Herbert Pötzl
18695 + *
18696 + *  V0.01  broken out from vcontext V0.05
18697 + *  V0.02  changed vcmds to vxi arg
18698 + *  V0.03  added memory cgroup support
18699 + *
18700 + */
18701 +
18702 +#include <linux/sched.h>
18703 +#include <linux/module.h>
18704 +#include <linux/memcontrol.h>
18705 +#include <linux/res_counter.h>
18706 +#include <linux/vs_limit.h>
18707 +#include <linux/vserver/limit.h>
18708 +#include <linux/vserver/limit_cmd.h>
18709 +
18710 +#include <asm/uaccess.h>
18711 +
18712 +
18713 +const char *vlimit_name[NUM_LIMITS] = {
18714 +       [RLIMIT_CPU]            = "CPU",
18715 +       [RLIMIT_NPROC]          = "NPROC",
18716 +       [RLIMIT_NOFILE]         = "NOFILE",
18717 +       [RLIMIT_LOCKS]          = "LOCKS",
18718 +       [RLIMIT_SIGPENDING]     = "SIGP",
18719 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18720 +
18721 +       [VLIMIT_NSOCK]          = "NSOCK",
18722 +       [VLIMIT_OPENFD]         = "OPENFD",
18723 +       [VLIMIT_SHMEM]          = "SHMEM",
18724 +       [VLIMIT_DENTRY]         = "DENTRY",
18725 +};
18726 +
18727 +EXPORT_SYMBOL_GPL(vlimit_name);
18728 +
18729 +#define MASK_ENTRY(x)  (1 << (x))
18730 +
18731 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18732 +               /* minimum */
18733 +       0
18734 +       ,       /* softlimit */
18735 +       0
18736 +       ,       /* maximum */
18737 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18738 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18739 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18740 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18741 +
18742 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18743 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18744 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18745 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18746 +       0
18747 +};
18748 +               /* accounting only */
18749 +uint32_t account_mask =
18750 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18751 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18752 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18753 +       0;
18754 +
18755 +
18756 +static int is_valid_vlimit(int id)
18757 +{
18758 +       uint32_t mask = vlimit_mask.minimum |
18759 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18760 +       return mask & (1 << id);
18761 +}
18762 +
18763 +static int is_accounted_vlimit(int id)
18764 +{
18765 +       if (is_valid_vlimit(id))
18766 +               return 1;
18767 +       return account_mask & (1 << id);
18768 +}
18769 +
18770 +
18771 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18772 +{
18773 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18774 +       return VX_VLIM(limit);
18775 +}
18776 +
18777 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18778 +{
18779 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18780 +       return VX_VLIM(limit);
18781 +}
18782 +
18783 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18784 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18785 +{
18786 +       if (!is_valid_vlimit(id))
18787 +               return -EINVAL;
18788 +
18789 +       if (minimum)
18790 +               *minimum = CRLIM_UNSET;
18791 +       if (softlimit)
18792 +               *softlimit = vc_get_soft(vxi, id);
18793 +       if (maximum)
18794 +               *maximum = vc_get_hard(vxi, id);
18795 +       return 0;
18796 +}
18797 +
18798 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18799 +{
18800 +       struct vcmd_ctx_rlimit_v0 vc_data;
18801 +       int ret;
18802 +
18803 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18804 +               return -EFAULT;
18805 +
18806 +       ret = do_get_rlimit(vxi, vc_data.id,
18807 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18808 +       if (ret)
18809 +               return ret;
18810 +
18811 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18812 +               return -EFAULT;
18813 +       return 0;
18814 +}
18815 +
18816 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18817 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18818 +{
18819 +       if (!is_valid_vlimit(id))
18820 +               return -EINVAL;
18821 +
18822 +       if (maximum != CRLIM_KEEP)
18823 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18824 +       if (softlimit != CRLIM_KEEP)
18825 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18826 +
18827 +       /* clamp soft limit */
18828 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18829 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18830 +
18831 +       return 0;
18832 +}
18833 +
18834 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18835 +{
18836 +       struct vcmd_ctx_rlimit_v0 vc_data;
18837 +
18838 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18839 +               return -EFAULT;
18840 +
18841 +       return do_set_rlimit(vxi, vc_data.id,
18842 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18843 +}
18844 +
18845 +#ifdef CONFIG_IA32_EMULATION
18846 +
18847 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18848 +{
18849 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18850 +
18851 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18852 +               return -EFAULT;
18853 +
18854 +       return do_set_rlimit(vxi, vc_data.id,
18855 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18856 +}
18857 +
18858 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18859 +{
18860 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18861 +       int ret;
18862 +
18863 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18864 +               return -EFAULT;
18865 +
18866 +       ret = do_get_rlimit(vxi, vc_data.id,
18867 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18868 +       if (ret)
18869 +               return ret;
18870 +
18871 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18872 +               return -EFAULT;
18873 +       return 0;
18874 +}
18875 +
18876 +#endif /* CONFIG_IA32_EMULATION */
18877 +
18878 +
18879 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18880 +{
18881 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18882 +               return -EFAULT;
18883 +       return 0;
18884 +}
18885 +
18886 +
18887 +static inline void vx_reset_hits(struct _vx_limit *limit)
18888 +{
18889 +       int lim;
18890 +
18891 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18892 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18893 +       }
18894 +}
18895 +
18896 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18897 +{
18898 +       vx_reset_hits(&vxi->limit);
18899 +       return 0;
18900 +}
18901 +
18902 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18903 +{
18904 +       rlim_t value;
18905 +       int lim;
18906 +
18907 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18908 +               value = __rlim_get(limit, lim);
18909 +               __rlim_rmax(limit, lim) = value;
18910 +               __rlim_rmin(limit, lim) = value;
18911 +       }
18912 +}
18913 +
18914 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18915 +{
18916 +       vx_reset_minmax(&vxi->limit);
18917 +       return 0;
18918 +}
18919 +
18920 +
18921 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18922 +{
18923 +       struct vcmd_rlimit_stat_v0 vc_data;
18924 +       struct _vx_limit *limit = &vxi->limit;
18925 +       int id;
18926 +
18927 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18928 +               return -EFAULT;
18929 +
18930 +       id = vc_data.id;
18931 +       if (!is_accounted_vlimit(id))
18932 +               return -EINVAL;
18933 +
18934 +       vx_limit_fixup(limit, id);
18935 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18936 +       vc_data.value = __rlim_get(limit, id);
18937 +       vc_data.minimum = __rlim_rmin(limit, id);
18938 +       vc_data.maximum = __rlim_rmax(limit, id);
18939 +
18940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18941 +               return -EFAULT;
18942 +       return 0;
18943 +}
18944 +
18945 +
18946 +void vx_vsi_meminfo(struct sysinfo *val)
18947 +{
18948 +#ifdef CONFIG_MEMCG
18949 +       struct mem_cgroup *mcg;
18950 +       u64 res_limit, res_usage;
18951 +
18952 +       rcu_read_lock();
18953 +       mcg = mem_cgroup_from_task(current);
18954 +       rcu_read_unlock();
18955 +       if (!mcg)
18956 +               goto out;
18957 +
18958 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18959 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18960 +
18961 +       if (res_limit != RES_COUNTER_MAX)
18962 +               val->totalram = (res_limit >> PAGE_SHIFT);
18963 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
18964 +       val->bufferram = 0;
18965 +       val->totalhigh = 0;
18966 +       val->freehigh = 0;
18967 +out:
18968 +#endif /* CONFIG_MEMCG */
18969 +       return;
18970 +}
18971 +
18972 +void vx_vsi_swapinfo(struct sysinfo *val)
18973 +{
18974 +#ifdef CONFIG_MEMCG
18975 +#ifdef CONFIG_MEMCG_SWAP
18976 +       struct mem_cgroup *mcg;
18977 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
18978 +       s64 swap_limit, swap_usage;
18979 +
18980 +       rcu_read_lock();
18981 +       mcg = mem_cgroup_from_task(current);
18982 +       rcu_read_unlock();
18983 +       if (!mcg)
18984 +               goto out;
18985 +
18986 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18987 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18988 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
18989 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
18990 +
18991 +       /* memory unlimited */
18992 +       if (res_limit == RES_COUNTER_MAX)
18993 +               goto out;
18994 +
18995 +       swap_limit = memsw_limit - res_limit;
18996 +       /* we have a swap limit? */
18997 +       if (memsw_limit != RES_COUNTER_MAX)
18998 +               val->totalswap = swap_limit >> PAGE_SHIFT;
18999 +
19000 +       /* calculate swap part */
19001 +       swap_usage = (memsw_usage > res_usage) ?
19002 +               memsw_usage - res_usage : 0;
19003 +
19004 +       /* total shown minus usage gives free swap */
19005 +       val->freeswap = (swap_usage < swap_limit) ?
19006 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19007 +out:
19008 +#else  /* !CONFIG_MEMCG_SWAP */
19009 +       val->totalswap = 0;
19010 +       val->freeswap = 0;
19011 +#endif /* !CONFIG_MEMCG_SWAP */
19012 +#endif /* CONFIG_MEMCG */
19013 +       return;
19014 +}
19015 +
19016 +long vx_vsi_cached(struct sysinfo *val)
19017 +{
19018 +       long cache = 0;
19019 +#ifdef CONFIG_MEMCG
19020 +       struct mem_cgroup *mcg;
19021 +
19022 +       rcu_read_lock();
19023 +       mcg = mem_cgroup_from_task(current);
19024 +       rcu_read_unlock();
19025 +       if (!mcg)
19026 +               goto out;
19027 +
19028 +       cache = mem_cgroup_stat_read_cache(mcg);
19029 +out:
19030 +#endif
19031 +       return cache;
19032 +}
19033 +
19034 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h
19035 --- linux-3.13.10/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19036 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h        2014-01-31 20:38:04.000000000 +0000
19037 @@ -0,0 +1,31 @@
19038 +
19039 +
19040 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19041 +{
19042 +       int lim;
19043 +
19044 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19045 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19046 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19047 +               __rlim_set(limit, lim, 0);
19048 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19049 +               __rlim_rmin(limit, lim) = 0;
19050 +               __rlim_rmax(limit, lim) = 0;
19051 +       }
19052 +}
19053 +
19054 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19055 +{
19056 +       rlim_t value;
19057 +       int lim;
19058 +
19059 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19060 +               if ((1 << lim) & VLIM_NOCHECK)
19061 +                       continue;
19062 +               value = __rlim_get(limit, lim);
19063 +               vxwprintk_xid(value,
19064 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19065 +                       limit, vlimit_name[lim], lim, (long)value);
19066 +       }
19067 +}
19068 +
19069 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h
19070 --- linux-3.13.10/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19071 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h        2014-01-31 20:38:04.000000000 +0000
19072 @@ -0,0 +1,57 @@
19073 +#ifndef _VX_LIMIT_PROC_H
19074 +#define _VX_LIMIT_PROC_H
19075 +
19076 +#include <linux/vserver/limit_int.h>
19077 +
19078 +
19079 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19080 +#define VX_LIMIT_TOP   \
19081 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19082 +
19083 +#define VX_LIMIT_ARG(r)                                \
19084 +       (unsigned long)__rlim_get(limit, r),    \
19085 +       (unsigned long)__rlim_rmin(limit, r),   \
19086 +       (unsigned long)__rlim_rmax(limit, r),   \
19087 +       VX_VLIM(__rlim_soft(limit, r)),         \
19088 +       VX_VLIM(__rlim_hard(limit, r)),         \
19089 +       atomic_read(&__rlim_lhit(limit, r))
19090 +
19091 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19092 +{
19093 +       vx_limit_fixup(limit, -1);
19094 +       return sprintf(buffer, VX_LIMIT_TOP
19095 +               "PROC"  VX_LIMIT_FMT
19096 +               "VM"    VX_LIMIT_FMT
19097 +               "VML"   VX_LIMIT_FMT
19098 +               "RSS"   VX_LIMIT_FMT
19099 +               "ANON"  VX_LIMIT_FMT
19100 +               "RMAP"  VX_LIMIT_FMT
19101 +               "FILES" VX_LIMIT_FMT
19102 +               "OFD"   VX_LIMIT_FMT
19103 +               "LOCKS" VX_LIMIT_FMT
19104 +               "SOCK"  VX_LIMIT_FMT
19105 +               "MSGQ"  VX_LIMIT_FMT
19106 +               "SHM"   VX_LIMIT_FMT
19107 +               "SEMA"  VX_LIMIT_FMT
19108 +               "SEMS"  VX_LIMIT_FMT
19109 +               "DENT"  VX_LIMIT_FMT,
19110 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19111 +               VX_LIMIT_ARG(RLIMIT_AS),
19112 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19113 +               VX_LIMIT_ARG(RLIMIT_RSS),
19114 +               VX_LIMIT_ARG(VLIMIT_ANON),
19115 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19116 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19117 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19118 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19119 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19120 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19121 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19122 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19123 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19124 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19125 +}
19126 +
19127 +#endif /* _VX_LIMIT_PROC_H */
19128 +
19129 +
19130 diff -NurpP --minimal linux-3.13.10/kernel/vserver/network.c linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c
19131 --- linux-3.13.10/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19132 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c   2014-01-31 20:38:04.000000000 +0000
19133 @@ -0,0 +1,1053 @@
19134 +/*
19135 + *  linux/kernel/vserver/network.c
19136 + *
19137 + *  Virtual Server: Network Support
19138 + *
19139 + *  Copyright (C) 2003-2007  Herbert Pötzl
19140 + *
19141 + *  V0.01  broken out from vcontext V0.05
19142 + *  V0.02  cleaned up implementation
19143 + *  V0.03  added equiv nx commands
19144 + *  V0.04  switch to RCU based hash
19145 + *  V0.05  and back to locking again
19146 + *  V0.06  changed vcmds to nxi arg
19147 + *  V0.07  have __create claim() the nxi
19148 + *
19149 + */
19150 +
19151 +#include <linux/err.h>
19152 +#include <linux/slab.h>
19153 +#include <linux/rcupdate.h>
19154 +#include <net/ipv6.h>
19155 +
19156 +#include <linux/vs_network.h>
19157 +#include <linux/vs_pid.h>
19158 +#include <linux/vserver/network_cmd.h>
19159 +
19160 +
19161 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19162 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19163 +
19164 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19165 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19166 +
19167 +
19168 +static int __init init_network(void)
19169 +{
19170 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19171 +               sizeof(struct nx_addr_v4), 0,
19172 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19173 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19174 +               sizeof(struct nx_addr_v6), 0,
19175 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19176 +       return 0;
19177 +}
19178 +
19179 +
19180 +/*     __alloc_nx_addr_v4()                                    */
19181 +
19182 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19183 +{
19184 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19185 +               nx_addr_v4_cachep, GFP_KERNEL);
19186 +
19187 +       if (!IS_ERR(nxa))
19188 +               memset(nxa, 0, sizeof(*nxa));
19189 +       return nxa;
19190 +}
19191 +
19192 +/*     __dealloc_nx_addr_v4()                                  */
19193 +
19194 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19195 +{
19196 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19197 +}
19198 +
19199 +/*     __dealloc_nx_addr_v4_all()                              */
19200 +
19201 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19202 +{
19203 +       while (nxa) {
19204 +               struct nx_addr_v4 *next = nxa->next;
19205 +
19206 +               __dealloc_nx_addr_v4(nxa);
19207 +               nxa = next;
19208 +       }
19209 +}
19210 +
19211 +
19212 +#ifdef CONFIG_IPV6
19213 +
19214 +/*     __alloc_nx_addr_v6()                                    */
19215 +
19216 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19217 +{
19218 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19219 +               nx_addr_v6_cachep, GFP_KERNEL);
19220 +
19221 +       if (!IS_ERR(nxa))
19222 +               memset(nxa, 0, sizeof(*nxa));
19223 +       return nxa;
19224 +}
19225 +
19226 +/*     __dealloc_nx_addr_v6()                                  */
19227 +
19228 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19229 +{
19230 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19231 +}
19232 +
19233 +/*     __dealloc_nx_addr_v6_all()                              */
19234 +
19235 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19236 +{
19237 +       while (nxa) {
19238 +               struct nx_addr_v6 *next = nxa->next;
19239 +
19240 +               __dealloc_nx_addr_v6(nxa);
19241 +               nxa = next;
19242 +       }
19243 +}
19244 +
19245 +#endif /* CONFIG_IPV6 */
19246 +
19247 +/*     __alloc_nx_info()
19248 +
19249 +       * allocate an initialized nx_info struct
19250 +       * doesn't make it visible (hash)                        */
19251 +
19252 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19253 +{
19254 +       struct nx_info *new = NULL;
19255 +
19256 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19257 +
19258 +       /* would this benefit from a slab cache? */
19259 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19260 +       if (!new)
19261 +               return 0;
19262 +
19263 +       memset(new, 0, sizeof(struct nx_info));
19264 +       new->nx_id = nid;
19265 +       INIT_HLIST_NODE(&new->nx_hlist);
19266 +       atomic_set(&new->nx_usecnt, 0);
19267 +       atomic_set(&new->nx_tasks, 0);
19268 +       spin_lock_init(&new->addr_lock);
19269 +       new->nx_state = 0;
19270 +
19271 +       new->nx_flags = NXF_INIT_SET;
19272 +
19273 +       /* rest of init goes here */
19274 +
19275 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19276 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19277 +
19278 +       vxdprintk(VXD_CBIT(nid, 0),
19279 +               "alloc_nx_info(%d) = %p", nid, new);
19280 +       atomic_inc(&nx_global_ctotal);
19281 +       return new;
19282 +}
19283 +
19284 +/*     __dealloc_nx_info()
19285 +
19286 +       * final disposal of nx_info                             */
19287 +
19288 +static void __dealloc_nx_info(struct nx_info *nxi)
19289 +{
19290 +       vxdprintk(VXD_CBIT(nid, 0),
19291 +               "dealloc_nx_info(%p)", nxi);
19292 +
19293 +       nxi->nx_hlist.next = LIST_POISON1;
19294 +       nxi->nx_id = -1;
19295 +
19296 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19297 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19298 +
19299 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19300 +#ifdef CONFIG_IPV6
19301 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19302 +#endif
19303 +
19304 +       nxi->nx_state |= NXS_RELEASED;
19305 +       kfree(nxi);
19306 +       atomic_dec(&nx_global_ctotal);
19307 +}
19308 +
19309 +static void __shutdown_nx_info(struct nx_info *nxi)
19310 +{
19311 +       nxi->nx_state |= NXS_SHUTDOWN;
19312 +       vs_net_change(nxi, VSC_NETDOWN);
19313 +}
19314 +
19315 +/*     exported stuff                                          */
19316 +
19317 +void free_nx_info(struct nx_info *nxi)
19318 +{
19319 +       /* context shutdown is mandatory */
19320 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19321 +
19322 +       /* context must not be hashed */
19323 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19324 +
19325 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19326 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19327 +
19328 +       __dealloc_nx_info(nxi);
19329 +}
19330 +
19331 +
19332 +void __nx_set_lback(struct nx_info *nxi)
19333 +{
19334 +       int nid = nxi->nx_id;
19335 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19336 +
19337 +       nxi->v4_lback.s_addr = lback;
19338 +}
19339 +
19340 +extern int __nx_inet_add_lback(__be32 addr);
19341 +extern int __nx_inet_del_lback(__be32 addr);
19342 +
19343 +
19344 +/*     hash table for nx_info hash */
19345 +
19346 +#define NX_HASH_SIZE   13
19347 +
19348 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19349 +
19350 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19351 +
19352 +
19353 +static inline unsigned int __hashval(vnid_t nid)
19354 +{
19355 +       return (nid % NX_HASH_SIZE);
19356 +}
19357 +
19358 +
19359 +
19360 +/*     __hash_nx_info()
19361 +
19362 +       * add the nxi to the global hash table
19363 +       * requires the hash_lock to be held                     */
19364 +
19365 +static inline void __hash_nx_info(struct nx_info *nxi)
19366 +{
19367 +       struct hlist_head *head;
19368 +
19369 +       vxd_assert_lock(&nx_info_hash_lock);
19370 +       vxdprintk(VXD_CBIT(nid, 4),
19371 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19372 +
19373 +       /* context must not be hashed */
19374 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19375 +
19376 +       nxi->nx_state |= NXS_HASHED;
19377 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19378 +       hlist_add_head(&nxi->nx_hlist, head);
19379 +       atomic_inc(&nx_global_cactive);
19380 +}
19381 +
19382 +/*     __unhash_nx_info()
19383 +
19384 +       * remove the nxi from the global hash table
19385 +       * requires the hash_lock to be held                     */
19386 +
19387 +static inline void __unhash_nx_info(struct nx_info *nxi)
19388 +{
19389 +       vxd_assert_lock(&nx_info_hash_lock);
19390 +       vxdprintk(VXD_CBIT(nid, 4),
19391 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19392 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19393 +
19394 +       /* context must be hashed */
19395 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19396 +       /* but without tasks */
19397 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19398 +
19399 +       nxi->nx_state &= ~NXS_HASHED;
19400 +       hlist_del(&nxi->nx_hlist);
19401 +       atomic_dec(&nx_global_cactive);
19402 +}
19403 +
19404 +
19405 +/*     __lookup_nx_info()
19406 +
19407 +       * requires the hash_lock to be held
19408 +       * doesn't increment the nx_refcnt                       */
19409 +
19410 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19411 +{
19412 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19413 +       struct hlist_node *pos;
19414 +       struct nx_info *nxi;
19415 +
19416 +       vxd_assert_lock(&nx_info_hash_lock);
19417 +       hlist_for_each(pos, head) {
19418 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19419 +
19420 +               if (nxi->nx_id == nid)
19421 +                       goto found;
19422 +       }
19423 +       nxi = NULL;
19424 +found:
19425 +       vxdprintk(VXD_CBIT(nid, 0),
19426 +               "__lookup_nx_info(#%u): %p[#%u]",
19427 +               nid, nxi, nxi ? nxi->nx_id : 0);
19428 +       return nxi;
19429 +}
19430 +
19431 +
19432 +/*     __create_nx_info()
19433 +
19434 +       * create the requested context
19435 +       * get(), claim() and hash it                            */
19436 +
19437 +static struct nx_info *__create_nx_info(int id)
19438 +{
19439 +       struct nx_info *new, *nxi = NULL;
19440 +
19441 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19442 +
19443 +       if (!(new = __alloc_nx_info(id)))
19444 +               return ERR_PTR(-ENOMEM);
19445 +
19446 +       /* required to make dynamic xids unique */
19447 +       spin_lock(&nx_info_hash_lock);
19448 +
19449 +       /* static context requested */
19450 +       if ((nxi = __lookup_nx_info(id))) {
19451 +               vxdprintk(VXD_CBIT(nid, 0),
19452 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19453 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19454 +                       nxi = ERR_PTR(-EBUSY);
19455 +               else
19456 +                       nxi = ERR_PTR(-EEXIST);
19457 +               goto out_unlock;
19458 +       }
19459 +       /* new context */
19460 +       vxdprintk(VXD_CBIT(nid, 0),
19461 +               "create_nx_info(%d) = %p (new)", id, new);
19462 +       claim_nx_info(new, NULL);
19463 +       __nx_set_lback(new);
19464 +       __hash_nx_info(get_nx_info(new));
19465 +       nxi = new, new = NULL;
19466 +
19467 +out_unlock:
19468 +       spin_unlock(&nx_info_hash_lock);
19469 +       if (new)
19470 +               __dealloc_nx_info(new);
19471 +       return nxi;
19472 +}
19473 +
19474 +
19475 +
19476 +/*     exported stuff                                          */
19477 +
19478 +
19479 +void unhash_nx_info(struct nx_info *nxi)
19480 +{
19481 +       __shutdown_nx_info(nxi);
19482 +       spin_lock(&nx_info_hash_lock);
19483 +       __unhash_nx_info(nxi);
19484 +       spin_unlock(&nx_info_hash_lock);
19485 +}
19486 +
19487 +/*     lookup_nx_info()
19488 +
19489 +       * search for a nx_info and get() it
19490 +       * negative id means current                             */
19491 +
19492 +struct nx_info *lookup_nx_info(int id)
19493 +{
19494 +       struct nx_info *nxi = NULL;
19495 +
19496 +       if (id < 0) {
19497 +               nxi = get_nx_info(current_nx_info());
19498 +       } else if (id > 1) {
19499 +               spin_lock(&nx_info_hash_lock);
19500 +               nxi = get_nx_info(__lookup_nx_info(id));
19501 +               spin_unlock(&nx_info_hash_lock);
19502 +       }
19503 +       return nxi;
19504 +}
19505 +
19506 +/*     nid_is_hashed()
19507 +
19508 +       * verify that nid is still hashed                       */
19509 +
19510 +int nid_is_hashed(vnid_t nid)
19511 +{
19512 +       int hashed;
19513 +
19514 +       spin_lock(&nx_info_hash_lock);
19515 +       hashed = (__lookup_nx_info(nid) != NULL);
19516 +       spin_unlock(&nx_info_hash_lock);
19517 +       return hashed;
19518 +}
19519 +
19520 +
19521 +#ifdef CONFIG_PROC_FS
19522 +
19523 +/*     get_nid_list()
19524 +
19525 +       * get a subset of hashed nids for proc
19526 +       * assumes size is at least one                          */
19527 +
19528 +int get_nid_list(int index, unsigned int *nids, int size)
19529 +{
19530 +       int hindex, nr_nids = 0;
19531 +
19532 +       /* only show current and children */
19533 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19534 +               if (index > 0)
19535 +                       return 0;
19536 +               nids[nr_nids] = nx_current_nid();
19537 +               return 1;
19538 +       }
19539 +
19540 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19541 +               struct hlist_head *head = &nx_info_hash[hindex];
19542 +               struct hlist_node *pos;
19543 +
19544 +               spin_lock(&nx_info_hash_lock);
19545 +               hlist_for_each(pos, head) {
19546 +                       struct nx_info *nxi;
19547 +
19548 +                       if (--index > 0)
19549 +                               continue;
19550 +
19551 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19552 +                       nids[nr_nids] = nxi->nx_id;
19553 +                       if (++nr_nids >= size) {
19554 +                               spin_unlock(&nx_info_hash_lock);
19555 +                               goto out;
19556 +                       }
19557 +               }
19558 +               /* keep the lock time short */
19559 +               spin_unlock(&nx_info_hash_lock);
19560 +       }
19561 +out:
19562 +       return nr_nids;
19563 +}
19564 +#endif
19565 +
19566 +
19567 +/*
19568 + *     migrate task to new network
19569 + *     gets nxi, puts old_nxi on change
19570 + */
19571 +
19572 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19573 +{
19574 +       struct nx_info *old_nxi;
19575 +       int ret = 0;
19576 +
19577 +       if (!p || !nxi)
19578 +               BUG();
19579 +
19580 +       vxdprintk(VXD_CBIT(nid, 5),
19581 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19582 +               p, nxi, nxi->nx_id,
19583 +               atomic_read(&nxi->nx_usecnt),
19584 +               atomic_read(&nxi->nx_tasks));
19585 +
19586 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19587 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19588 +               return -EACCES;
19589 +
19590 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19591 +               return -EFAULT;
19592 +
19593 +       /* maybe disallow this completely? */
19594 +       old_nxi = task_get_nx_info(p);
19595 +       if (old_nxi == nxi)
19596 +               goto out;
19597 +
19598 +       task_lock(p);
19599 +       if (old_nxi)
19600 +               clr_nx_info(&p->nx_info);
19601 +       claim_nx_info(nxi, p);
19602 +       set_nx_info(&p->nx_info, nxi);
19603 +       p->nid = nxi->nx_id;
19604 +       task_unlock(p);
19605 +
19606 +       vxdprintk(VXD_CBIT(nid, 5),
19607 +               "moved task %p into nxi:%p[#%d]",
19608 +               p, nxi, nxi->nx_id);
19609 +
19610 +       if (old_nxi)
19611 +               release_nx_info(old_nxi, p);
19612 +       ret = 0;
19613 +out:
19614 +       put_nx_info(old_nxi);
19615 +       return ret;
19616 +}
19617 +
19618 +
19619 +void nx_set_persistent(struct nx_info *nxi)
19620 +{
19621 +       vxdprintk(VXD_CBIT(nid, 6),
19622 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19623 +
19624 +       get_nx_info(nxi);
19625 +       claim_nx_info(nxi, NULL);
19626 +}
19627 +
19628 +void nx_clear_persistent(struct nx_info *nxi)
19629 +{
19630 +       vxdprintk(VXD_CBIT(nid, 6),
19631 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19632 +
19633 +       release_nx_info(nxi, NULL);
19634 +       put_nx_info(nxi);
19635 +}
19636 +
19637 +void nx_update_persistent(struct nx_info *nxi)
19638 +{
19639 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19640 +               nx_set_persistent(nxi);
19641 +       else
19642 +               nx_clear_persistent(nxi);
19643 +}
19644 +
19645 +/* vserver syscall commands below here */
19646 +
19647 +/* taks nid and nx_info functions */
19648 +
19649 +#include <asm/uaccess.h>
19650 +
19651 +
19652 +int vc_task_nid(uint32_t id)
19653 +{
19654 +       vnid_t nid;
19655 +
19656 +       if (id) {
19657 +               struct task_struct *tsk;
19658 +
19659 +               rcu_read_lock();
19660 +               tsk = find_task_by_real_pid(id);
19661 +               nid = (tsk) ? tsk->nid : -ESRCH;
19662 +               rcu_read_unlock();
19663 +       } else
19664 +               nid = nx_current_nid();
19665 +       return nid;
19666 +}
19667 +
19668 +
19669 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19670 +{
19671 +       struct vcmd_nx_info_v0 vc_data;
19672 +
19673 +       vc_data.nid = nxi->nx_id;
19674 +
19675 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19676 +               return -EFAULT;
19677 +       return 0;
19678 +}
19679 +
19680 +
19681 +/* network functions */
19682 +
19683 +int vc_net_create(uint32_t nid, void __user *data)
19684 +{
19685 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19686 +       struct nx_info *new_nxi;
19687 +       int ret;
19688 +
19689 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19690 +               return -EFAULT;
19691 +
19692 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19693 +               return -EINVAL;
19694 +
19695 +       new_nxi = __create_nx_info(nid);
19696 +       if (IS_ERR(new_nxi))
19697 +               return PTR_ERR(new_nxi);
19698 +
19699 +       /* initial flags */
19700 +       new_nxi->nx_flags = vc_data.flagword;
19701 +
19702 +       ret = -ENOEXEC;
19703 +       if (vs_net_change(new_nxi, VSC_NETUP))
19704 +               goto out;
19705 +
19706 +       ret = nx_migrate_task(current, new_nxi);
19707 +       if (ret)
19708 +               goto out;
19709 +
19710 +       /* return context id on success */
19711 +       ret = new_nxi->nx_id;
19712 +
19713 +       /* get a reference for persistent contexts */
19714 +       if ((vc_data.flagword & NXF_PERSISTENT))
19715 +               nx_set_persistent(new_nxi);
19716 +out:
19717 +       release_nx_info(new_nxi, NULL);
19718 +       put_nx_info(new_nxi);
19719 +       return ret;
19720 +}
19721 +
19722 +
19723 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19724 +{
19725 +       return nx_migrate_task(current, nxi);
19726 +}
19727 +
19728 +
19729 +static inline
19730 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19731 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19732 +       struct nx_addr_v4 **prev)
19733 +{
19734 +       struct nx_addr_v4 *nxa = &nxi->v4;
19735 +
19736 +       for (; nxa; nxa = nxa->next) {
19737 +               if ((nxa->ip[0].s_addr == ip) &&
19738 +                   (nxa->ip[1].s_addr == ip2) &&
19739 +                   (nxa->mask.s_addr == mask) &&
19740 +                   (nxa->type == type) &&
19741 +                   (nxa->flags == flags))
19742 +                   return nxa;
19743 +
19744 +               /* save previous entry */
19745 +               if (prev)
19746 +                       *prev = nxa;
19747 +       }
19748 +       return NULL;
19749 +}
19750 +
19751 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19752 +       uint16_t type, uint16_t flags)
19753 +{
19754 +       struct nx_addr_v4 *nxa = NULL;
19755 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19756 +       unsigned long irqflags;
19757 +       int ret = -EEXIST;
19758 +
19759 +       if (IS_ERR(new))
19760 +               return PTR_ERR(new);
19761 +
19762 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19763 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19764 +               goto out_unlock;
19765 +
19766 +       if (NX_IPV4(nxi)) {
19767 +               nxa->next = new;
19768 +               nxa = new;
19769 +               new = NULL;
19770 +
19771 +               /* remove single ip for ip list */
19772 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19773 +       }
19774 +
19775 +       nxa->ip[0].s_addr = ip;
19776 +       nxa->ip[1].s_addr = ip2;
19777 +       nxa->mask.s_addr = mask;
19778 +       nxa->type = type;
19779 +       nxa->flags = flags;
19780 +       ret = 0;
19781 +out_unlock:
19782 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19783 +       if (new)
19784 +               __dealloc_nx_addr_v4(new);
19785 +       return ret;
19786 +}
19787 +
19788 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19789 +       uint16_t type, uint16_t flags)
19790 +{
19791 +       struct nx_addr_v4 *nxa = NULL;
19792 +       struct nx_addr_v4 *old = NULL;
19793 +       unsigned long irqflags;
19794 +       int ret = 0;
19795 +
19796 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19797 +       switch (type) {
19798 +       case NXA_TYPE_ADDR:
19799 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19800 +               if (old) {
19801 +                       if (nxa) {
19802 +                               nxa->next = old->next;
19803 +                               old->next = NULL;
19804 +                       } else {
19805 +                               if (old->next) {
19806 +                                       nxa = old;
19807 +                                       old = old->next;
19808 +                                       *nxa = *old;
19809 +                                       old->next = NULL;
19810 +                               } else {
19811 +                                       memset(old, 0, sizeof(*old));
19812 +                                       old = NULL;
19813 +                               }
19814 +                       }
19815 +               } else
19816 +                       ret = -ESRCH;
19817 +               break;
19818 +
19819 +       case NXA_TYPE_ANY:
19820 +               nxa = &nxi->v4;
19821 +               old = nxa->next;
19822 +               memset(nxa, 0, sizeof(*nxa));
19823 +               break;
19824 +
19825 +       default:
19826 +               ret = -EINVAL;
19827 +       }
19828 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19829 +       __dealloc_nx_addr_v4_all(old);
19830 +       return ret;
19831 +}
19832 +
19833 +
19834 +int vc_net_add(struct nx_info *nxi, void __user *data)
19835 +{
19836 +       struct vcmd_net_addr_v0 vc_data;
19837 +       int index, ret = 0;
19838 +
19839 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19840 +               return -EFAULT;
19841 +
19842 +       switch (vc_data.type) {
19843 +       case NXA_TYPE_IPV4:
19844 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19845 +                       return -EINVAL;
19846 +
19847 +               index = 0;
19848 +               while (index < vc_data.count) {
19849 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19850 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19851 +                       if (ret)
19852 +                               return ret;
19853 +                       index++;
19854 +               }
19855 +               ret = index;
19856 +               break;
19857 +
19858 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19859 +               nxi->v4_bcast = vc_data.ip[0];
19860 +               ret = 1;
19861 +               break;
19862 +
19863 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19864 +               nxi->v4_lback = vc_data.ip[0];
19865 +               ret = 1;
19866 +               break;
19867 +
19868 +       default:
19869 +               ret = -EINVAL;
19870 +               break;
19871 +       }
19872 +       return ret;
19873 +}
19874 +
19875 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19876 +{
19877 +       struct vcmd_net_addr_v0 vc_data;
19878 +
19879 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19880 +               return -EFAULT;
19881 +
19882 +       switch (vc_data.type) {
19883 +       case NXA_TYPE_ANY:
19884 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19885 +       default:
19886 +               return -EINVAL;
19887 +       }
19888 +       return 0;
19889 +}
19890 +
19891 +
19892 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19893 +{
19894 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19895 +
19896 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19897 +               return -EFAULT;
19898 +
19899 +       switch (vc_data.type) {
19900 +       case NXA_TYPE_ADDR:
19901 +       case NXA_TYPE_MASK:
19902 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19903 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19904 +
19905 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19906 +               nxi->v4_bcast = vc_data.ip;
19907 +               break;
19908 +
19909 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19910 +               nxi->v4_lback = vc_data.ip;
19911 +               break;
19912 +
19913 +       default:
19914 +               return -EINVAL;
19915 +       }
19916 +       return 0;
19917 +}
19918 +
19919 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19920 +{
19921 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19922 +
19923 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19924 +               return -EFAULT;
19925 +
19926 +       switch (vc_data.type) {
19927 +       case NXA_TYPE_ADDR:
19928 +       case NXA_TYPE_MASK:
19929 +       case NXA_TYPE_RANGE:
19930 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19931 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19932 +
19933 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19934 +               nxi->v4_bcast = vc_data.ip;
19935 +               break;
19936 +
19937 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19938 +               nxi->v4_lback = vc_data.ip;
19939 +               break;
19940 +
19941 +       default:
19942 +               return -EINVAL;
19943 +       }
19944 +       return 0;
19945 +}
19946 +
19947 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19948 +{
19949 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19950 +
19951 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19952 +               return -EFAULT;
19953 +
19954 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19955 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19956 +}
19957 +
19958 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19959 +{
19960 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19961 +
19962 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19963 +               return -EFAULT;
19964 +
19965 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19966 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19967 +}
19968 +
19969 +#ifdef CONFIG_IPV6
19970 +
19971 +static inline
19972 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19973 +       struct in6_addr *ip, struct in6_addr *mask,
19974 +       uint32_t prefix, uint16_t type, uint16_t flags,
19975 +       struct nx_addr_v6 **prev)
19976 +{
19977 +       struct nx_addr_v6 *nxa = &nxi->v6;
19978 +
19979 +       for (; nxa; nxa = nxa->next) {
19980 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
19981 +                   ipv6_addr_equal(&nxa->mask, mask) &&
19982 +                   (nxa->prefix == prefix) &&
19983 +                   (nxa->type == type) &&
19984 +                   (nxa->flags == flags))
19985 +                   return nxa;
19986 +
19987 +               /* save previous entry */
19988 +               if (prev)
19989 +                       *prev = nxa;
19990 +       }
19991 +       return NULL;
19992 +}
19993 +
19994 +
19995 +int do_add_v6_addr(struct nx_info *nxi,
19996 +       struct in6_addr *ip, struct in6_addr *mask,
19997 +       uint32_t prefix, uint16_t type, uint16_t flags)
19998 +{
19999 +       struct nx_addr_v6 *nxa = NULL;
20000 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20001 +       unsigned long irqflags;
20002 +       int ret = -EEXIST;
20003 +
20004 +       if (IS_ERR(new))
20005 +               return PTR_ERR(new);
20006 +
20007 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20008 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20009 +               goto out_unlock;
20010 +
20011 +       if (NX_IPV6(nxi)) {
20012 +               nxa->next = new;
20013 +               nxa = new;
20014 +               new = NULL;
20015 +       }
20016 +
20017 +       nxa->ip = *ip;
20018 +       nxa->mask = *mask;
20019 +       nxa->prefix = prefix;
20020 +       nxa->type = type;
20021 +       nxa->flags = flags;
20022 +       ret = 0;
20023 +out_unlock:
20024 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20025 +       if (new)
20026 +               __dealloc_nx_addr_v6(new);
20027 +       return ret;
20028 +}
20029 +
20030 +int do_remove_v6_addr(struct nx_info *nxi,
20031 +       struct in6_addr *ip, struct in6_addr *mask,
20032 +       uint32_t prefix, uint16_t type, uint16_t flags)
20033 +{
20034 +       struct nx_addr_v6 *nxa = NULL;
20035 +       struct nx_addr_v6 *old = NULL;
20036 +       unsigned long irqflags;
20037 +       int ret = 0;
20038 +
20039 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20040 +       switch (type) {
20041 +       case NXA_TYPE_ADDR:
20042 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20043 +               if (old) {
20044 +                       if (nxa) {
20045 +                               nxa->next = old->next;
20046 +                               old->next = NULL;
20047 +                       } else {
20048 +                               if (old->next) {
20049 +                                       nxa = old;
20050 +                                       old = old->next;
20051 +                                       *nxa = *old;
20052 +                                       old->next = NULL;
20053 +                               } else {
20054 +                                       memset(old, 0, sizeof(*old));
20055 +                                       old = NULL;
20056 +                               }
20057 +                       }
20058 +               } else
20059 +                       ret = -ESRCH;
20060 +               break;
20061 +
20062 +       case NXA_TYPE_ANY:
20063 +               nxa = &nxi->v6;
20064 +               old = nxa->next;
20065 +               memset(nxa, 0, sizeof(*nxa));
20066 +               break;
20067 +
20068 +       default:
20069 +               ret = -EINVAL;
20070 +       }
20071 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20072 +       __dealloc_nx_addr_v6_all(old);
20073 +       return ret;
20074 +}
20075 +
20076 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20077 +{
20078 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20079 +
20080 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20081 +               return -EFAULT;
20082 +
20083 +       switch (vc_data.type) {
20084 +       case NXA_TYPE_ADDR:
20085 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20086 +               /* fallthrough */
20087 +       case NXA_TYPE_MASK:
20088 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20089 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20090 +       default:
20091 +               return -EINVAL;
20092 +       }
20093 +       return 0;
20094 +}
20095 +
20096 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20097 +{
20098 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20099 +
20100 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20101 +               return -EFAULT;
20102 +
20103 +       switch (vc_data.type) {
20104 +       case NXA_TYPE_ADDR:
20105 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20106 +               /* fallthrough */
20107 +       case NXA_TYPE_MASK:
20108 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20109 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20110 +       case NXA_TYPE_ANY:
20111 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20112 +       default:
20113 +               return -EINVAL;
20114 +       }
20115 +       return 0;
20116 +}
20117 +
20118 +#endif /* CONFIG_IPV6 */
20119 +
20120 +
20121 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20122 +{
20123 +       struct vcmd_net_flags_v0 vc_data;
20124 +
20125 +       vc_data.flagword = nxi->nx_flags;
20126 +
20127 +       /* special STATE flag handling */
20128 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20129 +
20130 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20131 +               return -EFAULT;
20132 +       return 0;
20133 +}
20134 +
20135 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20136 +{
20137 +       struct vcmd_net_flags_v0 vc_data;
20138 +       uint64_t mask, trigger;
20139 +
20140 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20141 +               return -EFAULT;
20142 +
20143 +       /* special STATE flag handling */
20144 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20145 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20146 +
20147 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20148 +               vc_data.flagword, mask);
20149 +       if (trigger & NXF_PERSISTENT)
20150 +               nx_update_persistent(nxi);
20151 +
20152 +       return 0;
20153 +}
20154 +
20155 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20156 +{
20157 +       struct vcmd_net_caps_v0 vc_data;
20158 +
20159 +       vc_data.ncaps = nxi->nx_ncaps;
20160 +       vc_data.cmask = ~0ULL;
20161 +
20162 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20163 +               return -EFAULT;
20164 +       return 0;
20165 +}
20166 +
20167 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20168 +{
20169 +       struct vcmd_net_caps_v0 vc_data;
20170 +
20171 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20172 +               return -EFAULT;
20173 +
20174 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20175 +               vc_data.ncaps, vc_data.cmask);
20176 +       return 0;
20177 +}
20178 +
20179 +
20180 +#include <linux/module.h>
20181 +
20182 +module_init(init_network);
20183 +
20184 +EXPORT_SYMBOL_GPL(free_nx_info);
20185 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20186 +
20187 diff -NurpP --minimal linux-3.13.10/kernel/vserver/proc.c linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c
20188 --- linux-3.13.10/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20189 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c      2014-02-01 01:21:49.000000000 +0000
20190 @@ -0,0 +1,1097 @@
20191 +/*
20192 + *  linux/kernel/vserver/proc.c
20193 + *
20194 + *  Virtual Context Support
20195 + *
20196 + *  Copyright (C) 2003-2011  Herbert Pötzl
20197 + *
20198 + *  V0.01  basic structure
20199 + *  V0.02  adaptation vs1.3.0
20200 + *  V0.03  proc permissions
20201 + *  V0.04  locking/generic
20202 + *  V0.05  next generation procfs
20203 + *  V0.06  inode validation
20204 + *  V0.07  generic rewrite vid
20205 + *  V0.08  remove inode type
20206 + *  V0.09  added u/wmask info
20207 + *
20208 + */
20209 +
20210 +#include <linux/proc_fs.h>
20211 +#include <linux/fs_struct.h>
20212 +#include <linux/mount.h>
20213 +#include <linux/namei.h>
20214 +#include <asm/unistd.h>
20215 +
20216 +#include <linux/vs_context.h>
20217 +#include <linux/vs_network.h>
20218 +#include <linux/vs_cvirt.h>
20219 +
20220 +#include <linux/in.h>
20221 +#include <linux/inetdevice.h>
20222 +#include <linux/vs_inet.h>
20223 +#include <linux/vs_inet6.h>
20224 +
20225 +#include <linux/vserver/global.h>
20226 +
20227 +#include "cvirt_proc.h"
20228 +#include "cacct_proc.h"
20229 +#include "limit_proc.h"
20230 +#include "sched_proc.h"
20231 +#include "vci_config.h"
20232 +
20233 +#include <../../fs/proc/internal.h>
20234 +
20235 +
20236 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20237 +{
20238 +       unsigned __capi;
20239 +
20240 +       CAP_FOR_EACH_U32(__capi) {
20241 +               buffer += sprintf(buffer, "%08x",
20242 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20243 +       }
20244 +       return buffer;
20245 +}
20246 +
20247 +
20248 +static struct proc_dir_entry *proc_virtual;
20249 +
20250 +static struct proc_dir_entry *proc_virtnet;
20251 +
20252 +
20253 +/* first the actual feeds */
20254 +
20255 +
20256 +static int proc_vci(char *buffer)
20257 +{
20258 +       return sprintf(buffer,
20259 +               "VCIVersion:\t%04x:%04x\n"
20260 +               "VCISyscall:\t%d\n"
20261 +               "VCIKernel:\t%08x\n",
20262 +               VCI_VERSION >> 16,
20263 +               VCI_VERSION & 0xFFFF,
20264 +               __NR_vserver,
20265 +               vci_kernel_config());
20266 +}
20267 +
20268 +static int proc_virtual_info(char *buffer)
20269 +{
20270 +       return proc_vci(buffer);
20271 +}
20272 +
20273 +static int proc_virtual_status(char *buffer)
20274 +{
20275 +       return sprintf(buffer,
20276 +               "#CTotal:\t%d\n"
20277 +               "#CActive:\t%d\n"
20278 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20279 +               "#InitTask:\t%d\t%d %d\n",
20280 +               atomic_read(&vx_global_ctotal),
20281 +               atomic_read(&vx_global_cactive),
20282 +               atomic_read(&vs_global_nsproxy),
20283 +               atomic_read(&vs_global_fs),
20284 +               atomic_read(&vs_global_mnt_ns),
20285 +               atomic_read(&vs_global_uts_ns),
20286 +               atomic_read(&nr_ipc_ns),
20287 +               atomic_read(&vs_global_user_ns),
20288 +               atomic_read(&vs_global_pid_ns),
20289 +               atomic_read(&init_task.usage),
20290 +               atomic_read(&init_task.nsproxy->count),
20291 +               init_task.fs->users);
20292 +}
20293 +
20294 +
20295 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20296 +{
20297 +       int length;
20298 +
20299 +       length = sprintf(buffer,
20300 +               "ID:\t%d\n"
20301 +               "Info:\t%p\n"
20302 +               "Init:\t%d\n"
20303 +               "OOM:\t%lld\n",
20304 +               vxi->vx_id,
20305 +               vxi,
20306 +               vxi->vx_initpid,
20307 +               vxi->vx_badness_bias);
20308 +       return length;
20309 +}
20310 +
20311 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20312 +{
20313 +       char *orig = buffer;
20314 +
20315 +       buffer += sprintf(buffer,
20316 +               "UseCnt:\t%d\n"
20317 +               "Tasks:\t%d\n"
20318 +               "Flags:\t%016llx\n",
20319 +               atomic_read(&vxi->vx_usecnt),
20320 +               atomic_read(&vxi->vx_tasks),
20321 +               (unsigned long long)vxi->vx_flags);
20322 +
20323 +       buffer += sprintf(buffer, "BCaps:\t");
20324 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20325 +       buffer += sprintf(buffer, "\n");
20326 +
20327 +       buffer += sprintf(buffer,
20328 +               "CCaps:\t%016llx\n"
20329 +               "Umask:\t%16llx\n"
20330 +               "Wmask:\t%16llx\n"
20331 +               "Spaces:\t%08lx %08lx\n",
20332 +               (unsigned long long)vxi->vx_ccaps,
20333 +               (unsigned long long)vxi->vx_umask,
20334 +               (unsigned long long)vxi->vx_wmask,
20335 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20336 +       return buffer - orig;
20337 +}
20338 +
20339 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20340 +{
20341 +       return vx_info_proc_limit(&vxi->limit, buffer);
20342 +}
20343 +
20344 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20345 +{
20346 +       int cpu, length;
20347 +
20348 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20349 +       for_each_online_cpu(cpu) {
20350 +               length += vx_info_proc_sched_pc(
20351 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20352 +                       buffer + length, cpu);
20353 +       }
20354 +       return length;
20355 +}
20356 +
20357 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20358 +{
20359 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20360 +}
20361 +
20362 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20363 +{
20364 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20365 +}
20366 +
20367 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20368 +{
20369 +       int cpu, length;
20370 +
20371 +       vx_update_load(vxi);
20372 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20373 +       for_each_online_cpu(cpu) {
20374 +               length += vx_info_proc_cvirt_pc(
20375 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20376 +                       buffer + length, cpu);
20377 +       }
20378 +       return length;
20379 +}
20380 +
20381 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20382 +{
20383 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20384 +}
20385 +
20386 +
20387 +static int proc_virtnet_info(char *buffer)
20388 +{
20389 +       return proc_vci(buffer);
20390 +}
20391 +
20392 +static int proc_virtnet_status(char *buffer)
20393 +{
20394 +       return sprintf(buffer,
20395 +               "#CTotal:\t%d\n"
20396 +               "#CActive:\t%d\n",
20397 +               atomic_read(&nx_global_ctotal),
20398 +               atomic_read(&nx_global_cactive));
20399 +}
20400 +
20401 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20402 +{
20403 +       struct nx_addr_v4 *v4a;
20404 +#ifdef CONFIG_IPV6
20405 +       struct nx_addr_v6 *v6a;
20406 +#endif
20407 +       int length, i;
20408 +
20409 +       length = sprintf(buffer,
20410 +               "ID:\t%d\n"
20411 +               "Info:\t%p\n"
20412 +               "Bcast:\t" NIPQUAD_FMT "\n"
20413 +               "Lback:\t" NIPQUAD_FMT "\n",
20414 +               nxi->nx_id,
20415 +               nxi,
20416 +               NIPQUAD(nxi->v4_bcast.s_addr),
20417 +               NIPQUAD(nxi->v4_lback.s_addr));
20418 +
20419 +       if (!NX_IPV4(nxi))
20420 +               goto skip_v4;
20421 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20422 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20423 +                       i, NXAV4(v4a));
20424 +skip_v4:
20425 +#ifdef CONFIG_IPV6
20426 +       if (!NX_IPV6(nxi))
20427 +               goto skip_v6;
20428 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20429 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20430 +                       i, NXAV6(v6a));
20431 +skip_v6:
20432 +#endif
20433 +       return length;
20434 +}
20435 +
20436 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20437 +{
20438 +       int length;
20439 +
20440 +       length = sprintf(buffer,
20441 +               "UseCnt:\t%d\n"
20442 +               "Tasks:\t%d\n"
20443 +               "Flags:\t%016llx\n"
20444 +               "NCaps:\t%016llx\n",
20445 +               atomic_read(&nxi->nx_usecnt),
20446 +               atomic_read(&nxi->nx_tasks),
20447 +               (unsigned long long)nxi->nx_flags,
20448 +               (unsigned long long)nxi->nx_ncaps);
20449 +       return length;
20450 +}
20451 +
20452 +
20453 +
20454 +/* here the inode helpers */
20455 +
20456 +struct vs_entry {
20457 +       int len;
20458 +       char *name;
20459 +       mode_t mode;
20460 +       struct inode_operations *iop;
20461 +       struct file_operations *fop;
20462 +       union proc_op op;
20463 +};
20464 +
20465 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20466 +{
20467 +       struct inode *inode = new_inode(sb);
20468 +
20469 +       if (!inode)
20470 +               goto out;
20471 +
20472 +       inode->i_mode = p->mode;
20473 +       if (p->iop)
20474 +               inode->i_op = p->iop;
20475 +       if (p->fop)
20476 +               inode->i_fop = p->fop;
20477 +
20478 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20479 +       inode->i_flags |= S_IMMUTABLE;
20480 +
20481 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20482 +
20483 +       i_uid_write(inode, 0);
20484 +       i_gid_write(inode, 0);
20485 +       i_tag_write(inode, 0);
20486 +out:
20487 +       return inode;
20488 +}
20489 +
20490 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20491 +       struct dentry *dentry, int id, void *ptr)
20492 +{
20493 +       struct vs_entry *p = ptr;
20494 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20495 +       struct dentry *error = ERR_PTR(-EINVAL);
20496 +
20497 +       if (!inode)
20498 +               goto out;
20499 +
20500 +       PROC_I(inode)->op = p->op;
20501 +       PROC_I(inode)->fd = id;
20502 +       d_add(dentry, inode);
20503 +       error = NULL;
20504 +out:
20505 +       return error;
20506 +}
20507 +
20508 +/* Lookups */
20509 +
20510 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20511 +
20512 +
20513 +/*
20514 + * Fill a directory entry.
20515 + *
20516 + * If possible create the dcache entry and derive our inode number and
20517 + * file type from dcache entry.
20518 + *
20519 + * Since all of the proc inode numbers are dynamically generated, the inode
20520 + * numbers do not exist until the inode is cache.  This means creating the
20521 + * the dcache entry in iterate is necessary to keep the inode numbers
20522 + * reported by iterate in sync with the inode numbers reported
20523 + * by stat.
20524 + */
20525 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20526 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20527 +{
20528 +       struct dentry *child, *dir = filp->f_dentry;
20529 +       struct inode *inode;
20530 +       struct qstr qname;
20531 +       ino_t ino = 0;
20532 +       unsigned type = DT_UNKNOWN;
20533 +
20534 +       qname.name = name;
20535 +       qname.len  = len;
20536 +       qname.hash = full_name_hash(name, len);
20537 +
20538 +       child = d_lookup(dir, &qname);
20539 +       if (!child) {
20540 +               struct dentry *new;
20541 +               new = d_alloc(dir, &qname);
20542 +               if (new) {
20543 +                       child = instantiate(dir->d_inode, new, id, ptr);
20544 +                       if (child)
20545 +                               dput(new);
20546 +                       else
20547 +                               child = new;
20548 +               }
20549 +       }
20550 +       if (!child || IS_ERR(child) || !child->d_inode)
20551 +               goto end_instantiate;
20552 +       inode = child->d_inode;
20553 +       if (inode) {
20554 +               ino = inode->i_ino;
20555 +               type = inode->i_mode >> 12;
20556 +       }
20557 +       dput(child);
20558 +end_instantiate:
20559 +       if (!ino)
20560 +               ino = 1;
20561 +       return !dir_emit(ctx, name, len, ino, type);
20562 +}
20563 +
20564 +
20565 +
20566 +/* get and revalidate vx_info/xid */
20567 +
20568 +static inline
20569 +struct vx_info *get_proc_vx_info(struct inode *inode)
20570 +{
20571 +       return lookup_vx_info(PROC_I(inode)->fd);
20572 +}
20573 +
20574 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20575 +{
20576 +       struct inode *inode = dentry->d_inode;
20577 +       vxid_t xid = PROC_I(inode)->fd;
20578 +
20579 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20580 +               return -ECHILD;
20581 +
20582 +       if (!xid || xid_is_hashed(xid))
20583 +               return 1;
20584 +       d_drop(dentry);
20585 +       return 0;
20586 +}
20587 +
20588 +
20589 +/* get and revalidate nx_info/nid */
20590 +
20591 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20592 +{
20593 +       struct inode *inode = dentry->d_inode;
20594 +       vnid_t nid = PROC_I(inode)->fd;
20595 +
20596 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20597 +               return -ECHILD;
20598 +
20599 +       if (!nid || nid_is_hashed(nid))
20600 +               return 1;
20601 +       d_drop(dentry);
20602 +       return 0;
20603 +}
20604 +
20605 +
20606 +
20607 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20608 +
20609 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20610 +                         size_t count, loff_t *ppos)
20611 +{
20612 +       struct inode *inode = file->f_dentry->d_inode;
20613 +       unsigned long page;
20614 +       ssize_t length = 0;
20615 +
20616 +       if (count > PROC_BLOCK_SIZE)
20617 +               count = PROC_BLOCK_SIZE;
20618 +
20619 +       /* fade that out as soon as stable */
20620 +       WARN_ON(PROC_I(inode)->fd);
20621 +
20622 +       if (!(page = __get_free_page(GFP_KERNEL)))
20623 +               return -ENOMEM;
20624 +
20625 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20626 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20627 +
20628 +       if (length >= 0)
20629 +               length = simple_read_from_buffer(buf, count, ppos,
20630 +                       (char *)page, length);
20631 +
20632 +       free_page(page);
20633 +       return length;
20634 +}
20635 +
20636 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20637 +                         size_t count, loff_t *ppos)
20638 +{
20639 +       struct inode *inode = file->f_dentry->d_inode;
20640 +       struct vx_info *vxi = NULL;
20641 +       vxid_t xid = PROC_I(inode)->fd;
20642 +       unsigned long page;
20643 +       ssize_t length = 0;
20644 +
20645 +       if (count > PROC_BLOCK_SIZE)
20646 +               count = PROC_BLOCK_SIZE;
20647 +
20648 +       /* fade that out as soon as stable */
20649 +       WARN_ON(!xid);
20650 +       vxi = lookup_vx_info(xid);
20651 +       if (!vxi)
20652 +               goto out;
20653 +
20654 +       length = -ENOMEM;
20655 +       if (!(page = __get_free_page(GFP_KERNEL)))
20656 +               goto out_put;
20657 +
20658 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20659 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20660 +
20661 +       if (length >= 0)
20662 +               length = simple_read_from_buffer(buf, count, ppos,
20663 +                       (char *)page, length);
20664 +
20665 +       free_page(page);
20666 +out_put:
20667 +       put_vx_info(vxi);
20668 +out:
20669 +       return length;
20670 +}
20671 +
20672 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20673 +                         size_t count, loff_t *ppos)
20674 +{
20675 +       struct inode *inode = file->f_dentry->d_inode;
20676 +       struct nx_info *nxi = NULL;
20677 +       vnid_t nid = PROC_I(inode)->fd;
20678 +       unsigned long page;
20679 +       ssize_t length = 0;
20680 +
20681 +       if (count > PROC_BLOCK_SIZE)
20682 +               count = PROC_BLOCK_SIZE;
20683 +
20684 +       /* fade that out as soon as stable */
20685 +       WARN_ON(!nid);
20686 +       nxi = lookup_nx_info(nid);
20687 +       if (!nxi)
20688 +               goto out;
20689 +
20690 +       length = -ENOMEM;
20691 +       if (!(page = __get_free_page(GFP_KERNEL)))
20692 +               goto out_put;
20693 +
20694 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20695 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20696 +
20697 +       if (length >= 0)
20698 +               length = simple_read_from_buffer(buf, count, ppos,
20699 +                       (char *)page, length);
20700 +
20701 +       free_page(page);
20702 +out_put:
20703 +       put_nx_info(nxi);
20704 +out:
20705 +       return length;
20706 +}
20707 +
20708 +
20709 +
20710 +/* here comes the lower level */
20711 +
20712 +
20713 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20714 +       .len  = sizeof(NAME) - 1,       \
20715 +       .name = (NAME),                 \
20716 +       .mode = MODE,                   \
20717 +       .iop  = IOP,                    \
20718 +       .fop  = FOP,                    \
20719 +       .op   = OP,                     \
20720 +}
20721 +
20722 +
20723 +#define DIR(NAME, MODE, OTYPE)                         \
20724 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20725 +               &proc_ ## OTYPE ## _inode_operations,   \
20726 +               &proc_ ## OTYPE ## _file_operations, { } )
20727 +
20728 +#define INF(NAME, MODE, OTYPE)                         \
20729 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20730 +               &proc_vs_info_file_operations,          \
20731 +               { .proc_vs_read = &proc_##OTYPE } )
20732 +
20733 +#define VINF(NAME, MODE, OTYPE)                                \
20734 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20735 +               &proc_vx_info_file_operations,          \
20736 +               { .proc_vxi_read = &proc_##OTYPE } )
20737 +
20738 +#define NINF(NAME, MODE, OTYPE)                                \
20739 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20740 +               &proc_nx_info_file_operations,          \
20741 +               { .proc_nxi_read = &proc_##OTYPE } )
20742 +
20743 +
20744 +static struct file_operations proc_vs_info_file_operations = {
20745 +       .read =         proc_vs_info_read,
20746 +};
20747 +
20748 +static struct file_operations proc_vx_info_file_operations = {
20749 +       .read =         proc_vx_info_read,
20750 +};
20751 +
20752 +static struct dentry_operations proc_xid_dentry_operations = {
20753 +       .d_revalidate = proc_xid_revalidate,
20754 +};
20755 +
20756 +static struct vs_entry vx_base_stuff[] = {
20757 +       VINF("info",    S_IRUGO, vxi_info),
20758 +       VINF("status",  S_IRUGO, vxi_status),
20759 +       VINF("limit",   S_IRUGO, vxi_limit),
20760 +       VINF("sched",   S_IRUGO, vxi_sched),
20761 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20762 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20763 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20764 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20765 +       {}
20766 +};
20767 +
20768 +
20769 +
20770 +
20771 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20772 +       struct dentry *dentry, int id, void *ptr)
20773 +{
20774 +       dentry->d_op = &proc_xid_dentry_operations;
20775 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20776 +}
20777 +
20778 +static struct dentry *proc_xid_lookup(struct inode *dir,
20779 +       struct dentry *dentry, unsigned int flags)
20780 +{
20781 +       struct vs_entry *p = vx_base_stuff;
20782 +       struct dentry *error = ERR_PTR(-ENOENT);
20783 +
20784 +       for (; p->name; p++) {
20785 +               if (p->len != dentry->d_name.len)
20786 +                       continue;
20787 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20788 +                       break;
20789 +       }
20790 +       if (!p->name)
20791 +               goto out;
20792 +
20793 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20794 +out:
20795 +       return error;
20796 +}
20797 +
20798 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20799 +{
20800 +       struct dentry *dentry = filp->f_dentry;
20801 +       struct inode *inode = dentry->d_inode;
20802 +       struct vs_entry *p = vx_base_stuff;
20803 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20804 +       int index;
20805 +       u64 ino;
20806 +
20807 +       switch (ctx->pos) {
20808 +       case 0:
20809 +               ino = inode->i_ino;
20810 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20811 +                       goto out;
20812 +               ctx->pos++;
20813 +               /* fall through */
20814 +       case 1:
20815 +               ino = parent_ino(dentry);
20816 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20817 +                       goto out;
20818 +               ctx->pos++;
20819 +               /* fall through */
20820 +       default:
20821 +               index = ctx->pos - 2;
20822 +               if (index >= size)
20823 +                       goto out;
20824 +               for (p += index; p->name; p++) {
20825 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20826 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20827 +                               goto out;
20828 +                       ctx->pos++;
20829 +               }
20830 +       }
20831 +out:
20832 +       return 1;
20833 +}
20834 +
20835 +
20836 +
20837 +static struct file_operations proc_nx_info_file_operations = {
20838 +       .read =         proc_nx_info_read,
20839 +};
20840 +
20841 +static struct dentry_operations proc_nid_dentry_operations = {
20842 +       .d_revalidate = proc_nid_revalidate,
20843 +};
20844 +
20845 +static struct vs_entry nx_base_stuff[] = {
20846 +       NINF("info",    S_IRUGO, nxi_info),
20847 +       NINF("status",  S_IRUGO, nxi_status),
20848 +       {}
20849 +};
20850 +
20851 +
20852 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20853 +       struct dentry *dentry, int id, void *ptr)
20854 +{
20855 +       dentry->d_op = &proc_nid_dentry_operations;
20856 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20857 +}
20858 +
20859 +static struct dentry *proc_nid_lookup(struct inode *dir,
20860 +       struct dentry *dentry, unsigned int flags)
20861 +{
20862 +       struct vs_entry *p = nx_base_stuff;
20863 +       struct dentry *error = ERR_PTR(-ENOENT);
20864 +
20865 +       for (; p->name; p++) {
20866 +               if (p->len != dentry->d_name.len)
20867 +                       continue;
20868 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20869 +                       break;
20870 +       }
20871 +       if (!p->name)
20872 +               goto out;
20873 +
20874 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20875 +out:
20876 +       return error;
20877 +}
20878 +
20879 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20880 +{
20881 +       struct dentry *dentry = filp->f_dentry;
20882 +       struct inode *inode = dentry->d_inode;
20883 +       struct vs_entry *p = nx_base_stuff;
20884 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20885 +       int index;
20886 +       u64 ino;
20887 +
20888 +       switch (ctx->pos) {
20889 +       case 0:
20890 +               ino = inode->i_ino;
20891 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20892 +                       goto out;
20893 +               ctx->pos++;
20894 +               /* fall through */
20895 +       case 1:
20896 +               ino = parent_ino(dentry);
20897 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20898 +                       goto out;
20899 +               ctx->pos++;
20900 +               /* fall through */
20901 +       default:
20902 +               index = ctx->pos - 2;
20903 +               if (index >= size)
20904 +                       goto out;
20905 +               for (p += index; p->name; p++) {
20906 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20907 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20908 +                               goto out;
20909 +                       ctx->pos++;
20910 +               }
20911 +       }
20912 +out:
20913 +       return 1;
20914 +}
20915 +
20916 +
20917 +#define MAX_MULBY10    ((~0U - 9) / 10)
20918 +
20919 +static inline int atovid(const char *str, int len)
20920 +{
20921 +       int vid, c;
20922 +
20923 +       vid = 0;
20924 +       while (len-- > 0) {
20925 +               c = *str - '0';
20926 +               str++;
20927 +               if (c > 9)
20928 +                       return -1;
20929 +               if (vid >= MAX_MULBY10)
20930 +                       return -1;
20931 +               vid *= 10;
20932 +               vid += c;
20933 +               if (!vid)
20934 +                       return -1;
20935 +       }
20936 +       return vid;
20937 +}
20938 +
20939 +/* now the upper level (virtual) */
20940 +
20941 +
20942 +static struct file_operations proc_xid_file_operations = {
20943 +       .read =         generic_read_dir,
20944 +       .iterate =      proc_xid_iterate,
20945 +};
20946 +
20947 +static struct inode_operations proc_xid_inode_operations = {
20948 +       .lookup =       proc_xid_lookup,
20949 +};
20950 +
20951 +static struct vs_entry vx_virtual_stuff[] = {
20952 +       INF("info",     S_IRUGO, virtual_info),
20953 +       INF("status",   S_IRUGO, virtual_status),
20954 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
20955 +};
20956 +
20957 +
20958 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20959 +       struct dentry *dentry, unsigned int flags)
20960 +{
20961 +       struct vs_entry *p = vx_virtual_stuff;
20962 +       struct dentry *error = ERR_PTR(-ENOENT);
20963 +       int id = 0;
20964 +
20965 +       for (; p->name; p++) {
20966 +               if (p->len != dentry->d_name.len)
20967 +                       continue;
20968 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20969 +                       break;
20970 +       }
20971 +       if (p->name)
20972 +               goto instantiate;
20973 +
20974 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20975 +       if ((id < 0) || !xid_is_hashed(id))
20976 +               goto out;
20977 +
20978 +instantiate:
20979 +       error = proc_xid_instantiate(dir, dentry, id, p);
20980 +out:
20981 +       return error;
20982 +}
20983 +
20984 +static struct file_operations proc_nid_file_operations = {
20985 +       .read =         generic_read_dir,
20986 +       .iterate =      proc_nid_iterate,
20987 +};
20988 +
20989 +static struct inode_operations proc_nid_inode_operations = {
20990 +       .lookup =       proc_nid_lookup,
20991 +};
20992 +
20993 +static struct vs_entry nx_virtnet_stuff[] = {
20994 +       INF("info",     S_IRUGO, virtnet_info),
20995 +       INF("status",   S_IRUGO, virtnet_status),
20996 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
20997 +};
20998 +
20999 +
21000 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21001 +       struct dentry *dentry, unsigned int flags)
21002 +{
21003 +       struct vs_entry *p = nx_virtnet_stuff;
21004 +       struct dentry *error = ERR_PTR(-ENOENT);
21005 +       int id = 0;
21006 +
21007 +       for (; p->name; p++) {
21008 +               if (p->len != dentry->d_name.len)
21009 +                       continue;
21010 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21011 +                       break;
21012 +       }
21013 +       if (p->name)
21014 +               goto instantiate;
21015 +
21016 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21017 +       if ((id < 0) || !nid_is_hashed(id))
21018 +               goto out;
21019 +
21020 +instantiate:
21021 +       error = proc_nid_instantiate(dir, dentry, id, p);
21022 +out:
21023 +       return error;
21024 +}
21025 +
21026 +
21027 +#define PROC_MAXVIDS 32
21028 +
21029 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21030 +{
21031 +       struct dentry *dentry = filp->f_dentry;
21032 +       struct inode *inode = dentry->d_inode;
21033 +       struct vs_entry *p = vx_virtual_stuff;
21034 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21035 +       int index;
21036 +       unsigned int xid_array[PROC_MAXVIDS];
21037 +       char buf[PROC_NUMBUF];
21038 +       unsigned int nr_xids, i;
21039 +       u64 ino;
21040 +
21041 +       switch (ctx->pos) {
21042 +       case 0:
21043 +               ino = inode->i_ino;
21044 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21045 +                       goto out;
21046 +               ctx->pos++;
21047 +               /* fall through */
21048 +       case 1:
21049 +               ino = parent_ino(dentry);
21050 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21051 +                       goto out;
21052 +               ctx->pos++;
21053 +               /* fall through */
21054 +       default:
21055 +               index = ctx->pos - 2;
21056 +               if (index >= size)
21057 +                       goto entries;
21058 +               for (p += index; p->name; p++) {
21059 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21060 +                               vs_proc_instantiate, 0, p))
21061 +                               goto out;
21062 +                       ctx->pos++;
21063 +               }
21064 +       entries:
21065 +               index = ctx->pos - size;
21066 +               p = &vx_virtual_stuff[size - 1];
21067 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21068 +               for (i = 0; i < nr_xids; i++) {
21069 +                       int n, xid = xid_array[i];
21070 +                       unsigned int j = PROC_NUMBUF;
21071 +
21072 +                       n = xid;
21073 +                       do
21074 +                               buf[--j] = '0' + (n % 10);
21075 +                       while (n /= 10);
21076 +
21077 +                       if (vx_proc_fill_cache(filp, ctx,
21078 +                               buf + j, PROC_NUMBUF - j,
21079 +                               vs_proc_instantiate, xid, p))
21080 +                               goto out;
21081 +                       ctx->pos++;
21082 +               }
21083 +       }
21084 +out:
21085 +       return 0;
21086 +}
21087 +
21088 +static int proc_virtual_getattr(struct vfsmount *mnt,
21089 +       struct dentry *dentry, struct kstat *stat)
21090 +{
21091 +       struct inode *inode = dentry->d_inode;
21092 +
21093 +       generic_fillattr(inode, stat);
21094 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21095 +       return 0;
21096 +}
21097 +
21098 +static struct file_operations proc_virtual_dir_operations = {
21099 +       .read =         generic_read_dir,
21100 +       .iterate =      proc_virtual_iterate,
21101 +};
21102 +
21103 +static struct inode_operations proc_virtual_dir_inode_operations = {
21104 +       .getattr =      proc_virtual_getattr,
21105 +       .lookup =       proc_virtual_lookup,
21106 +};
21107 +
21108 +
21109 +
21110 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21111 +{
21112 +       struct dentry *dentry = filp->f_dentry;
21113 +       struct inode *inode = dentry->d_inode;
21114 +       struct vs_entry *p = nx_virtnet_stuff;
21115 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21116 +       int index;
21117 +       unsigned int nid_array[PROC_MAXVIDS];
21118 +       char buf[PROC_NUMBUF];
21119 +       unsigned int nr_nids, i;
21120 +       u64 ino;
21121 +
21122 +       switch (ctx->pos) {
21123 +       case 0:
21124 +               ino = inode->i_ino;
21125 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21126 +                       goto out;
21127 +               ctx->pos++;
21128 +               /* fall through */
21129 +       case 1:
21130 +               ino = parent_ino(dentry);
21131 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21132 +                       goto out;
21133 +               ctx->pos++;
21134 +               /* fall through */
21135 +       default:
21136 +               index = ctx->pos - 2;
21137 +               if (index >= size)
21138 +                       goto entries;
21139 +               for (p += index; p->name; p++) {
21140 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21141 +                               vs_proc_instantiate, 0, p))
21142 +                               goto out;
21143 +                       ctx->pos++;
21144 +               }
21145 +       entries:
21146 +               index = ctx->pos - size;
21147 +               p = &nx_virtnet_stuff[size - 1];
21148 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21149 +               for (i = 0; i < nr_nids; i++) {
21150 +                       int n, nid = nid_array[i];
21151 +                       unsigned int j = PROC_NUMBUF;
21152 +
21153 +                       n = nid;
21154 +                       do
21155 +                               buf[--j] = '0' + (n % 10);
21156 +                       while (n /= 10);
21157 +
21158 +                       if (vx_proc_fill_cache(filp, ctx,
21159 +                               buf + j, PROC_NUMBUF - j,
21160 +                               vs_proc_instantiate, nid, p))
21161 +                               goto out;
21162 +                       ctx->pos++;
21163 +               }
21164 +       }
21165 +out:
21166 +       return 0;
21167 +}
21168 +
21169 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21170 +       struct dentry *dentry, struct kstat *stat)
21171 +{
21172 +       struct inode *inode = dentry->d_inode;
21173 +
21174 +       generic_fillattr(inode, stat);
21175 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21176 +       return 0;
21177 +}
21178 +
21179 +static struct file_operations proc_virtnet_dir_operations = {
21180 +       .read =         generic_read_dir,
21181 +       .iterate =      proc_virtnet_iterate,
21182 +};
21183 +
21184 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21185 +       .getattr =      proc_virtnet_getattr,
21186 +       .lookup =       proc_virtnet_lookup,
21187 +};
21188 +
21189 +
21190 +
21191 +void proc_vx_init(void)
21192 +{
21193 +       struct proc_dir_entry *ent;
21194 +
21195 +       ent = proc_mkdir("virtual", 0);
21196 +       if (ent) {
21197 +               ent->proc_fops = &proc_virtual_dir_operations;
21198 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21199 +       }
21200 +       proc_virtual = ent;
21201 +
21202 +       ent = proc_mkdir("virtnet", 0);
21203 +       if (ent) {
21204 +               ent->proc_fops = &proc_virtnet_dir_operations;
21205 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21206 +       }
21207 +       proc_virtnet = ent;
21208 +}
21209 +
21210 +
21211 +
21212 +
21213 +/* per pid info */
21214 +
21215 +
21216 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21217 +{
21218 +       struct vx_info *vxi;
21219 +       char *orig = buffer;
21220 +
21221 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21222 +
21223 +       vxi = task_get_vx_info(p);
21224 +       if (!vxi)
21225 +               goto out;
21226 +
21227 +       buffer += sprintf(buffer, "BCaps:\t");
21228 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21229 +       buffer += sprintf(buffer, "\n");
21230 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21231 +               (unsigned long long)vxi->vx_ccaps);
21232 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21233 +               (unsigned long long)vxi->vx_flags);
21234 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21235 +
21236 +       put_vx_info(vxi);
21237 +out:
21238 +       return buffer - orig;
21239 +}
21240 +
21241 +
21242 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21243 +{
21244 +       struct nx_info *nxi;
21245 +       struct nx_addr_v4 *v4a;
21246 +#ifdef CONFIG_IPV6
21247 +       struct nx_addr_v6 *v6a;
21248 +#endif
21249 +       char *orig = buffer;
21250 +       int i;
21251 +
21252 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21253 +
21254 +       nxi = task_get_nx_info(p);
21255 +       if (!nxi)
21256 +               goto out;
21257 +
21258 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21259 +               (unsigned long long)nxi->nx_ncaps);
21260 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21261 +               (unsigned long long)nxi->nx_flags);
21262 +
21263 +       buffer += sprintf(buffer,
21264 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21265 +               NIPQUAD(nxi->v4_bcast.s_addr));
21266 +       buffer += sprintf (buffer,
21267 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21268 +               NIPQUAD(nxi->v4_lback.s_addr));
21269 +       if (!NX_IPV4(nxi))
21270 +               goto skip_v4;
21271 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21272 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21273 +                       i, NXAV4(v4a));
21274 +skip_v4:
21275 +#ifdef CONFIG_IPV6
21276 +       if (!NX_IPV6(nxi))
21277 +               goto skip_v6;
21278 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21279 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21280 +                       i, NXAV6(v6a));
21281 +skip_v6:
21282 +#endif
21283 +       put_nx_info(nxi);
21284 +out:
21285 +       return buffer - orig;
21286 +}
21287 +
21288 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c
21289 --- linux-3.13.10/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
21290 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c     2014-01-31 20:38:04.000000000 +0000
21291 @@ -0,0 +1,83 @@
21292 +/*
21293 + *  linux/kernel/vserver/sched.c
21294 + *
21295 + *  Virtual Server: Scheduler Support
21296 + *
21297 + *  Copyright (C) 2004-2010  Herbert Pötzl
21298 + *
21299 + *  V0.01  adapted Sam Vilains version to 2.6.3
21300 + *  V0.02  removed legacy interface
21301 + *  V0.03  changed vcmds to vxi arg
21302 + *  V0.04  removed older and legacy interfaces
21303 + *  V0.05  removed scheduler code/commands
21304 + *
21305 + */
21306 +
21307 +#include <linux/vs_context.h>
21308 +#include <linux/vs_sched.h>
21309 +#include <linux/cpumask.h>
21310 +#include <linux/vserver/sched_cmd.h>
21311 +
21312 +#include <asm/uaccess.h>
21313 +
21314 +
21315 +void vx_update_sched_param(struct _vx_sched *sched,
21316 +       struct _vx_sched_pc *sched_pc)
21317 +{
21318 +       sched_pc->prio_bias = sched->prio_bias;
21319 +}
21320 +
21321 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21322 +{
21323 +       int cpu;
21324 +
21325 +       if (data->prio_bias > MAX_PRIO_BIAS)
21326 +               data->prio_bias = MAX_PRIO_BIAS;
21327 +       if (data->prio_bias < MIN_PRIO_BIAS)
21328 +               data->prio_bias = MIN_PRIO_BIAS;
21329 +
21330 +       if (data->cpu_id != ~0) {
21331 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21332 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21333 +                       cpu_online_mask);
21334 +       } else
21335 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21336 +
21337 +       for_each_cpu_mask(cpu, vxi->sched.update)
21338 +               vx_update_sched_param(&vxi->sched,
21339 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21340 +       return 0;
21341 +}
21342 +
21343 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21344 +{
21345 +       struct vcmd_prio_bias vc_data;
21346 +
21347 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21348 +               return -EFAULT;
21349 +
21350 +       return do_set_prio_bias(vxi, &vc_data);
21351 +}
21352 +
21353 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21354 +{
21355 +       struct vcmd_prio_bias vc_data;
21356 +       struct _vx_sched_pc *pcd;
21357 +       int cpu;
21358 +
21359 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21360 +               return -EFAULT;
21361 +
21362 +       cpu = vc_data.cpu_id;
21363 +
21364 +       if (!cpu_possible(cpu))
21365 +               return -EINVAL;
21366 +
21367 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21368 +       vc_data.prio_bias = pcd->prio_bias;
21369 +
21370 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21371 +               return -EFAULT;
21372 +       return 0;
21373 +}
21374 +
21375 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h
21376 --- linux-3.13.10/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21377 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h        2014-01-31 20:38:04.000000000 +0000
21378 @@ -0,0 +1,27 @@
21379 +
21380 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21381 +{
21382 +       /* scheduling; hard code starting values as constants */
21383 +       sched->prio_bias = 0;
21384 +}
21385 +
21386 +static inline
21387 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21388 +{
21389 +       sched_pc->prio_bias = 0;
21390 +
21391 +       sched_pc->user_ticks = 0;
21392 +       sched_pc->sys_ticks = 0;
21393 +       sched_pc->hold_ticks = 0;
21394 +}
21395 +
21396 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21397 +{
21398 +       return;
21399 +}
21400 +
21401 +static inline
21402 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21403 +{
21404 +       return;
21405 +}
21406 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h
21407 --- linux-3.13.10/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21408 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h        2014-01-31 20:38:04.000000000 +0000
21409 @@ -0,0 +1,32 @@
21410 +#ifndef _VX_SCHED_PROC_H
21411 +#define _VX_SCHED_PROC_H
21412 +
21413 +
21414 +static inline
21415 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21416 +{
21417 +       int length = 0;
21418 +
21419 +       length += sprintf(buffer,
21420 +               "PrioBias:\t%8d\n",
21421 +               sched->prio_bias);
21422 +       return length;
21423 +}
21424 +
21425 +static inline
21426 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21427 +       char *buffer, int cpu)
21428 +{
21429 +       int length = 0;
21430 +
21431 +       length += sprintf(buffer + length,
21432 +               "cpu %d: %lld %lld %lld", cpu,
21433 +               (unsigned long long)sched_pc->user_ticks,
21434 +               (unsigned long long)sched_pc->sys_ticks,
21435 +               (unsigned long long)sched_pc->hold_ticks);
21436 +       length += sprintf(buffer + length,
21437 +               " %d\n", sched_pc->prio_bias);
21438 +       return length;
21439 +}
21440 +
21441 +#endif /* _VX_SCHED_PROC_H */
21442 diff -NurpP --minimal linux-3.13.10/kernel/vserver/signal.c linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c
21443 --- linux-3.13.10/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21444 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c    2014-01-31 20:38:04.000000000 +0000
21445 @@ -0,0 +1,134 @@
21446 +/*
21447 + *  linux/kernel/vserver/signal.c
21448 + *
21449 + *  Virtual Server: Signal Support
21450 + *
21451 + *  Copyright (C) 2003-2007  Herbert Pötzl
21452 + *
21453 + *  V0.01  broken out from vcontext V0.05
21454 + *  V0.02  changed vcmds to vxi arg
21455 + *  V0.03  adjusted siginfo for kill
21456 + *
21457 + */
21458 +
21459 +#include <asm/uaccess.h>
21460 +
21461 +#include <linux/vs_context.h>
21462 +#include <linux/vs_pid.h>
21463 +#include <linux/vserver/signal_cmd.h>
21464 +
21465 +
21466 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21467 +{
21468 +       int retval, count = 0;
21469 +       struct task_struct *p;
21470 +       struct siginfo *sip = SEND_SIG_PRIV;
21471 +
21472 +       retval = -ESRCH;
21473 +       vxdprintk(VXD_CBIT(misc, 4),
21474 +               "vx_info_kill(%p[#%d],%d,%d)*",
21475 +               vxi, vxi->vx_id, pid, sig);
21476 +       read_lock(&tasklist_lock);
21477 +       switch (pid) {
21478 +       case  0:
21479 +       case -1:
21480 +               for_each_process(p) {
21481 +                       int err = 0;
21482 +
21483 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21484 +                               (pid && vxi->vx_initpid == p->pid))
21485 +                               continue;
21486 +
21487 +                       err = group_send_sig_info(sig, sip, p);
21488 +                       ++count;
21489 +                       if (err != -EPERM)
21490 +                               retval = err;
21491 +               }
21492 +               break;
21493 +
21494 +       case 1:
21495 +               if (vxi->vx_initpid) {
21496 +                       pid = vxi->vx_initpid;
21497 +                       /* for now, only SIGINT to private init ... */
21498 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21499 +                               /* ... as long as there are tasks left */
21500 +                               (atomic_read(&vxi->vx_tasks) > 1))
21501 +                               sig = SIGINT;
21502 +               }
21503 +               /* fallthrough */
21504 +       default:
21505 +               rcu_read_lock();
21506 +               p = find_task_by_real_pid(pid);
21507 +               rcu_read_unlock();
21508 +               if (p) {
21509 +                       if (vx_task_xid(p) == vxi->vx_id)
21510 +                               retval = group_send_sig_info(sig, sip, p);
21511 +               }
21512 +               break;
21513 +       }
21514 +       read_unlock(&tasklist_lock);
21515 +       vxdprintk(VXD_CBIT(misc, 4),
21516 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21517 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21518 +       return retval;
21519 +}
21520 +
21521 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21522 +{
21523 +       struct vcmd_ctx_kill_v0 vc_data;
21524 +
21525 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21526 +               return -EFAULT;
21527 +
21528 +       /* special check to allow guest shutdown */
21529 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21530 +               /* forbid killall pid=0 when init is present */
21531 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21532 +               (vc_data.pid > 1)))
21533 +               return -EACCES;
21534 +
21535 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21536 +}
21537 +
21538 +
21539 +static int __wait_exit(struct vx_info *vxi)
21540 +{
21541 +       DECLARE_WAITQUEUE(wait, current);
21542 +       int ret = 0;
21543 +
21544 +       add_wait_queue(&vxi->vx_wait, &wait);
21545 +       set_current_state(TASK_INTERRUPTIBLE);
21546 +
21547 +wait:
21548 +       if (vx_info_state(vxi,
21549 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21550 +               goto out;
21551 +       if (signal_pending(current)) {
21552 +               ret = -ERESTARTSYS;
21553 +               goto out;
21554 +       }
21555 +       schedule();
21556 +       goto wait;
21557 +
21558 +out:
21559 +       set_current_state(TASK_RUNNING);
21560 +       remove_wait_queue(&vxi->vx_wait, &wait);
21561 +       return ret;
21562 +}
21563 +
21564 +
21565 +
21566 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21567 +{
21568 +       struct vcmd_wait_exit_v0 vc_data;
21569 +       int ret;
21570 +
21571 +       ret = __wait_exit(vxi);
21572 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21573 +       vc_data.exit_code = vxi->exit_code;
21574 +
21575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21576 +               ret = -EFAULT;
21577 +       return ret;
21578 +}
21579 +
21580 diff -NurpP --minimal linux-3.13.10/kernel/vserver/space.c linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c
21581 --- linux-3.13.10/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21582 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c     2014-02-01 12:21:24.000000000 +0000
21583 @@ -0,0 +1,436 @@
21584 +/*
21585 + *  linux/kernel/vserver/space.c
21586 + *
21587 + *  Virtual Server: Context Space Support
21588 + *
21589 + *  Copyright (C) 2003-2010  Herbert Pötzl
21590 + *
21591 + *  V0.01  broken out from context.c 0.07
21592 + *  V0.02  added task locking for namespace
21593 + *  V0.03  broken out vx_enter_namespace
21594 + *  V0.04  added *space support and commands
21595 + *  V0.05  added credential support
21596 + *
21597 + */
21598 +
21599 +#include <linux/utsname.h>
21600 +#include <linux/nsproxy.h>
21601 +#include <linux/err.h>
21602 +#include <linux/fs_struct.h>
21603 +#include <linux/cred.h>
21604 +#include <asm/uaccess.h>
21605 +
21606 +#include <linux/vs_context.h>
21607 +#include <linux/vserver/space.h>
21608 +#include <linux/vserver/space_cmd.h>
21609 +
21610 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21611 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21612 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21613 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21614 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21615 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21616 +
21617 +
21618 +/* namespace functions */
21619 +
21620 +#include <linux/mnt_namespace.h>
21621 +#include <linux/user_namespace.h>
21622 +#include <linux/pid_namespace.h>
21623 +#include <linux/ipc_namespace.h>
21624 +#include <net/net_namespace.h>
21625 +#include "../fs/mount.h"
21626 +
21627 +
21628 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21629 +       .mask = CLONE_FS |
21630 +               CLONE_NEWNS |
21631 +#ifdef CONFIG_UTS_NS
21632 +               CLONE_NEWUTS |
21633 +#endif
21634 +#ifdef CONFIG_IPC_NS
21635 +               CLONE_NEWIPC |
21636 +#endif
21637 +#ifdef CONFIG_USER_NS
21638 +               CLONE_NEWUSER |
21639 +#endif
21640 +               0
21641 +};
21642 +
21643 +static const struct vcmd_space_mask_v1 space_mask = {
21644 +       .mask = CLONE_FS |
21645 +               CLONE_NEWNS |
21646 +#ifdef CONFIG_UTS_NS
21647 +               CLONE_NEWUTS |
21648 +#endif
21649 +#ifdef CONFIG_IPC_NS
21650 +               CLONE_NEWIPC |
21651 +#endif
21652 +#ifdef CONFIG_USER_NS
21653 +               CLONE_NEWUSER |
21654 +#endif
21655 +#ifdef CONFIG_PID_NS
21656 +               CLONE_NEWPID |
21657 +#endif
21658 +#ifdef CONFIG_NET_NS
21659 +               CLONE_NEWNET |
21660 +#endif
21661 +               0
21662 +};
21663 +
21664 +static const struct vcmd_space_mask_v1 default_space_mask = {
21665 +       .mask = CLONE_FS |
21666 +               CLONE_NEWNS |
21667 +#ifdef CONFIG_UTS_NS
21668 +               CLONE_NEWUTS |
21669 +#endif
21670 +#ifdef CONFIG_IPC_NS
21671 +               CLONE_NEWIPC |
21672 +#endif
21673 +#ifdef CONFIG_USER_NS
21674 +               CLONE_NEWUSER |
21675 +#endif
21676 +#ifdef CONFIG_PID_NS
21677 +//             CLONE_NEWPID |
21678 +#endif
21679 +               0
21680 +};
21681 +
21682 +/*
21683 + *     build a new nsproxy mix
21684 + *      assumes that both proxies are 'const'
21685 + *     does not touch nsproxy refcounts
21686 + *     will hold a reference on the result.
21687 + */
21688 +
21689 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21690 +       struct nsproxy *new_nsproxy, unsigned long mask)
21691 +{
21692 +       struct mnt_namespace *old_ns;
21693 +       struct uts_namespace *old_uts;
21694 +       struct ipc_namespace *old_ipc;
21695 +#ifdef CONFIG_PID_NS
21696 +       struct pid_namespace *old_pid;
21697 +#endif
21698 +#ifdef CONFIG_NET_NS
21699 +       struct net *old_net;
21700 +#endif
21701 +       struct nsproxy *nsproxy;
21702 +
21703 +       nsproxy = copy_nsproxy(old_nsproxy);
21704 +       if (!nsproxy)
21705 +               goto out;
21706 +
21707 +       if (mask & CLONE_NEWNS) {
21708 +               old_ns = nsproxy->mnt_ns;
21709 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21710 +               if (nsproxy->mnt_ns)
21711 +                       get_mnt_ns(nsproxy->mnt_ns);
21712 +       } else
21713 +               old_ns = NULL;
21714 +
21715 +       if (mask & CLONE_NEWUTS) {
21716 +               old_uts = nsproxy->uts_ns;
21717 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21718 +               if (nsproxy->uts_ns)
21719 +                       get_uts_ns(nsproxy->uts_ns);
21720 +       } else
21721 +               old_uts = NULL;
21722 +
21723 +       if (mask & CLONE_NEWIPC) {
21724 +               old_ipc = nsproxy->ipc_ns;
21725 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21726 +               if (nsproxy->ipc_ns)
21727 +                       get_ipc_ns(nsproxy->ipc_ns);
21728 +       } else
21729 +               old_ipc = NULL;
21730 +
21731 +#ifdef CONFIG_PID_NS
21732 +       if (mask & CLONE_NEWPID) {
21733 +               old_pid = nsproxy->pid_ns_for_children;
21734 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21735 +               if (nsproxy->pid_ns_for_children)
21736 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21737 +       } else
21738 +               old_pid = NULL;
21739 +#endif
21740 +#ifdef CONFIG_NET_NS
21741 +       if (mask & CLONE_NEWNET) {
21742 +               old_net = nsproxy->net_ns;
21743 +               nsproxy->net_ns = new_nsproxy->net_ns;
21744 +               if (nsproxy->net_ns)
21745 +                       get_net(nsproxy->net_ns);
21746 +       } else
21747 +               old_net = NULL;
21748 +#endif
21749 +       if (old_ns)
21750 +               put_mnt_ns(old_ns);
21751 +       if (old_uts)
21752 +               put_uts_ns(old_uts);
21753 +       if (old_ipc)
21754 +               put_ipc_ns(old_ipc);
21755 +#ifdef CONFIG_PID_NS
21756 +       if (old_pid)
21757 +               put_pid_ns(old_pid);
21758 +#endif
21759 +#ifdef CONFIG_NET_NS
21760 +       if (old_net)
21761 +               put_net(old_net);
21762 +#endif
21763 +out:
21764 +       return nsproxy;
21765 +}
21766 +
21767 +
21768 +/*
21769 + *     merge two nsproxy structs into a new one.
21770 + *     will hold a reference on the result.
21771 + */
21772 +
21773 +static inline
21774 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21775 +       struct nsproxy *proxy, unsigned long mask)
21776 +{
21777 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21778 +
21779 +       if (!proxy)
21780 +               return NULL;
21781 +
21782 +       if (mask) {
21783 +               /* vs_mix_nsproxy returns with reference */
21784 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21785 +                       proxy, mask);
21786 +       }
21787 +       get_nsproxy(proxy);
21788 +       return proxy;
21789 +}
21790 +
21791 +
21792 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21793 +{
21794 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21795 +       struct fs_struct *fs_cur, *fs = NULL;
21796 +       struct _vx_space *space;
21797 +       int ret, kill = 0;
21798 +
21799 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21800 +               vxi, vxi->vx_id, mask, index);
21801 +
21802 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21803 +               return -EACCES;
21804 +
21805 +       if (index >= VX_SPACES)
21806 +               return -EINVAL;
21807 +
21808 +       space = &vxi->space[index];
21809 +
21810 +       if (!mask)
21811 +               mask = space->vx_nsmask;
21812 +
21813 +       if ((mask & space->vx_nsmask) != mask)
21814 +               return -EINVAL;
21815 +
21816 +       if (mask & CLONE_FS) {
21817 +               fs = copy_fs_struct(space->vx_fs);
21818 +               if (!fs)
21819 +                       return -ENOMEM;
21820 +       }
21821 +       proxy = space->vx_nsproxy;
21822 +
21823 +       vxdprintk(VXD_CBIT(space, 9),
21824 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21825 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21826 +
21827 +       task_lock(current);
21828 +       fs_cur = current->fs;
21829 +
21830 +       if (mask & CLONE_FS) {
21831 +               spin_lock(&fs_cur->lock);
21832 +               current->fs = fs;
21833 +               kill = !--fs_cur->users;
21834 +               spin_unlock(&fs_cur->lock);
21835 +       }
21836 +
21837 +       proxy_cur = current->nsproxy;
21838 +       get_nsproxy(proxy_cur);
21839 +       task_unlock(current);
21840 +
21841 +       if (kill)
21842 +               free_fs_struct(fs_cur);
21843 +
21844 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21845 +       if (IS_ERR(proxy_new)) {
21846 +               ret = PTR_ERR(proxy_new);
21847 +               goto out_put;
21848 +       }
21849 +
21850 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21851 +
21852 +       if (mask & CLONE_NEWUSER) {
21853 +               struct cred *cred;
21854 +
21855 +               vxdprintk(VXD_CBIT(space, 10),
21856 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21857 +                       vxi, vxi->vx_id, space->vx_cred,
21858 +                       current->real_cred, current->cred);
21859 +
21860 +               if (space->vx_cred) {
21861 +                       cred = __prepare_creds(space->vx_cred);
21862 +                       if (cred)
21863 +                               commit_creds(cred);
21864 +               }
21865 +       }
21866 +
21867 +       ret = 0;
21868 +
21869 +       if (proxy_new)
21870 +               put_nsproxy(proxy_new);
21871 +out_put:
21872 +       if (proxy_cur)
21873 +               put_nsproxy(proxy_cur);
21874 +       return ret;
21875 +}
21876 +
21877 +
21878 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21879 +{
21880 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21881 +       struct fs_struct *fs_vxi, *fs = NULL;
21882 +       struct _vx_space *space;
21883 +       int ret, kill = 0;
21884 +
21885 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21886 +               vxi, vxi->vx_id, mask, index);
21887 +
21888 +       if ((mask & space_mask.mask) != mask)
21889 +               return -EINVAL;
21890 +
21891 +       if (index >= VX_SPACES)
21892 +               return -EINVAL;
21893 +
21894 +       space = &vxi->space[index];
21895 +
21896 +       proxy_vxi = space->vx_nsproxy;
21897 +       fs_vxi = space->vx_fs;
21898 +
21899 +       if (mask & CLONE_FS) {
21900 +               fs = copy_fs_struct(current->fs);
21901 +               if (!fs)
21902 +                       return -ENOMEM;
21903 +       }
21904 +
21905 +       task_lock(current);
21906 +
21907 +       if (mask & CLONE_FS) {
21908 +               spin_lock(&fs_vxi->lock);
21909 +               space->vx_fs = fs;
21910 +               kill = !--fs_vxi->users;
21911 +               spin_unlock(&fs_vxi->lock);
21912 +       }
21913 +
21914 +       proxy_cur = current->nsproxy;
21915 +       get_nsproxy(proxy_cur);
21916 +       task_unlock(current);
21917 +
21918 +       if (kill)
21919 +               free_fs_struct(fs_vxi);
21920 +
21921 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21922 +       if (IS_ERR(proxy_new)) {
21923 +               ret = PTR_ERR(proxy_new);
21924 +               goto out_put;
21925 +       }
21926 +
21927 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21928 +       space->vx_nsmask |= mask;
21929 +
21930 +       if (mask & CLONE_NEWUSER) {
21931 +               struct cred *cred;
21932 +
21933 +               vxdprintk(VXD_CBIT(space, 10),
21934 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21935 +                       vxi, vxi->vx_id, space->vx_cred,
21936 +                       current->real_cred, current->cred);
21937 +
21938 +               cred = prepare_creds();
21939 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21940 +               if (cred)
21941 +                       abort_creds(cred);
21942 +       }
21943 +
21944 +       ret = 0;
21945 +
21946 +       if (proxy_new)
21947 +               put_nsproxy(proxy_new);
21948 +out_put:
21949 +       if (proxy_cur)
21950 +               put_nsproxy(proxy_cur);
21951 +       return ret;
21952 +}
21953 +
21954 +
21955 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21956 +{
21957 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21958 +
21959 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21960 +               return -EFAULT;
21961 +
21962 +       return vx_enter_space(vxi, vc_data.mask, 0);
21963 +}
21964 +
21965 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21966 +{
21967 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21968 +
21969 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21970 +               return -EFAULT;
21971 +
21972 +       if (vc_data.index >= VX_SPACES)
21973 +               return -EINVAL;
21974 +
21975 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21976 +}
21977 +
21978 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21979 +{
21980 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21981 +
21982 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21983 +               return -EFAULT;
21984 +
21985 +       return vx_set_space(vxi, vc_data.mask, 0);
21986 +}
21987 +
21988 +int vc_set_space(struct vx_info *vxi, void __user *data)
21989 +{
21990 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21991 +
21992 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21993 +               return -EFAULT;
21994 +
21995 +       if (vc_data.index >= VX_SPACES)
21996 +               return -EINVAL;
21997 +
21998 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
21999 +}
22000 +
22001 +int vc_get_space_mask(void __user *data, int type)
22002 +{
22003 +       const struct vcmd_space_mask_v1 *mask;
22004 +
22005 +       if (type == 0)
22006 +               mask = &space_mask_v0;
22007 +       else if (type == 1)
22008 +               mask = &space_mask;
22009 +       else
22010 +               mask = &default_space_mask;
22011 +
22012 +       vxdprintk(VXD_CBIT(space, 10),
22013 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22014 +
22015 +       if (copy_to_user(data, mask, sizeof(*mask)))
22016 +               return -EFAULT;
22017 +       return 0;
22018 +}
22019 +
22020 diff -NurpP --minimal linux-3.13.10/kernel/vserver/switch.c linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c
22021 --- linux-3.13.10/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22022 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c    2014-01-31 20:38:04.000000000 +0000
22023 @@ -0,0 +1,556 @@
22024 +/*
22025 + *  linux/kernel/vserver/switch.c
22026 + *
22027 + *  Virtual Server: Syscall Switch
22028 + *
22029 + *  Copyright (C) 2003-2011  Herbert Pötzl
22030 + *
22031 + *  V0.01  syscall switch
22032 + *  V0.02  added signal to context
22033 + *  V0.03  added rlimit functions
22034 + *  V0.04  added iattr, task/xid functions
22035 + *  V0.05  added debug/history stuff
22036 + *  V0.06  added compat32 layer
22037 + *  V0.07  vcmd args and perms
22038 + *  V0.08  added status commands
22039 + *  V0.09  added tag commands
22040 + *  V0.10  added oom bias
22041 + *  V0.11  added device commands
22042 + *  V0.12  added warn mask
22043 + *
22044 + */
22045 +
22046 +#include <linux/vs_context.h>
22047 +#include <linux/vs_network.h>
22048 +#include <linux/vserver/switch.h>
22049 +
22050 +#include "vci_config.h"
22051 +
22052 +
22053 +static inline
22054 +int vc_get_version(uint32_t id)
22055 +{
22056 +       return VCI_VERSION;
22057 +}
22058 +
22059 +static inline
22060 +int vc_get_vci(uint32_t id)
22061 +{
22062 +       return vci_kernel_config();
22063 +}
22064 +
22065 +#include <linux/vserver/context_cmd.h>
22066 +#include <linux/vserver/cvirt_cmd.h>
22067 +#include <linux/vserver/cacct_cmd.h>
22068 +#include <linux/vserver/limit_cmd.h>
22069 +#include <linux/vserver/network_cmd.h>
22070 +#include <linux/vserver/sched_cmd.h>
22071 +#include <linux/vserver/debug_cmd.h>
22072 +#include <linux/vserver/inode_cmd.h>
22073 +#include <linux/vserver/dlimit_cmd.h>
22074 +#include <linux/vserver/signal_cmd.h>
22075 +#include <linux/vserver/space_cmd.h>
22076 +#include <linux/vserver/tag_cmd.h>
22077 +#include <linux/vserver/device_cmd.h>
22078 +
22079 +#include <linux/vserver/inode.h>
22080 +#include <linux/vserver/dlimit.h>
22081 +
22082 +
22083 +#ifdef CONFIG_COMPAT
22084 +#define __COMPAT(name, id, data, compat)       \
22085 +       (compat) ? name ## _x32(id, data) : name(id, data)
22086 +#define __COMPAT_NO_ID(name, data, compat)     \
22087 +       (compat) ? name ## _x32(data) : name(data)
22088 +#else
22089 +#define __COMPAT(name, id, data, compat)       \
22090 +       name(id, data)
22091 +#define __COMPAT_NO_ID(name, data, compat)     \
22092 +       name(data)
22093 +#endif
22094 +
22095 +
22096 +static inline
22097 +long do_vcmd(uint32_t cmd, uint32_t id,
22098 +       struct vx_info *vxi, struct nx_info *nxi,
22099 +       void __user *data, int compat)
22100 +{
22101 +       switch (cmd) {
22102 +
22103 +       case VCMD_get_version:
22104 +               return vc_get_version(id);
22105 +       case VCMD_get_vci:
22106 +               return vc_get_vci(id);
22107 +
22108 +       case VCMD_task_xid:
22109 +               return vc_task_xid(id);
22110 +       case VCMD_vx_info:
22111 +               return vc_vx_info(vxi, data);
22112 +
22113 +       case VCMD_task_nid:
22114 +               return vc_task_nid(id);
22115 +       case VCMD_nx_info:
22116 +               return vc_nx_info(nxi, data);
22117 +
22118 +       case VCMD_task_tag:
22119 +               return vc_task_tag(id);
22120 +
22121 +       case VCMD_set_space_v1:
22122 +               return vc_set_space_v1(vxi, data);
22123 +       /* this is version 2 */
22124 +       case VCMD_set_space:
22125 +               return vc_set_space(vxi, data);
22126 +
22127 +       case VCMD_get_space_mask_v0:
22128 +               return vc_get_space_mask(data, 0);
22129 +       /* this is version 1 */
22130 +       case VCMD_get_space_mask:
22131 +               return vc_get_space_mask(data, 1);
22132 +
22133 +       case VCMD_get_space_default:
22134 +               return vc_get_space_mask(data, -1);
22135 +
22136 +       case VCMD_set_umask:
22137 +               return vc_set_umask(vxi, data);
22138 +
22139 +       case VCMD_get_umask:
22140 +               return vc_get_umask(vxi, data);
22141 +
22142 +       case VCMD_set_wmask:
22143 +               return vc_set_wmask(vxi, data);
22144 +
22145 +       case VCMD_get_wmask:
22146 +               return vc_get_wmask(vxi, data);
22147 +#ifdef CONFIG_IA32_EMULATION
22148 +       case VCMD_get_rlimit:
22149 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22150 +       case VCMD_set_rlimit:
22151 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22152 +#else
22153 +       case VCMD_get_rlimit:
22154 +               return vc_get_rlimit(vxi, data);
22155 +       case VCMD_set_rlimit:
22156 +               return vc_set_rlimit(vxi, data);
22157 +#endif
22158 +       case VCMD_get_rlimit_mask:
22159 +               return vc_get_rlimit_mask(id, data);
22160 +       case VCMD_reset_hits:
22161 +               return vc_reset_hits(vxi, data);
22162 +       case VCMD_reset_minmax:
22163 +               return vc_reset_minmax(vxi, data);
22164 +
22165 +       case VCMD_get_vhi_name:
22166 +               return vc_get_vhi_name(vxi, data);
22167 +       case VCMD_set_vhi_name:
22168 +               return vc_set_vhi_name(vxi, data);
22169 +
22170 +       case VCMD_ctx_stat:
22171 +               return vc_ctx_stat(vxi, data);
22172 +       case VCMD_virt_stat:
22173 +               return vc_virt_stat(vxi, data);
22174 +       case VCMD_sock_stat:
22175 +               return vc_sock_stat(vxi, data);
22176 +       case VCMD_rlimit_stat:
22177 +               return vc_rlimit_stat(vxi, data);
22178 +
22179 +       case VCMD_set_cflags:
22180 +               return vc_set_cflags(vxi, data);
22181 +       case VCMD_get_cflags:
22182 +               return vc_get_cflags(vxi, data);
22183 +
22184 +       /* this is version 1 */
22185 +       case VCMD_set_ccaps:
22186 +               return vc_set_ccaps(vxi, data);
22187 +       /* this is version 1 */
22188 +       case VCMD_get_ccaps:
22189 +               return vc_get_ccaps(vxi, data);
22190 +       case VCMD_set_bcaps:
22191 +               return vc_set_bcaps(vxi, data);
22192 +       case VCMD_get_bcaps:
22193 +               return vc_get_bcaps(vxi, data);
22194 +
22195 +       case VCMD_set_badness:
22196 +               return vc_set_badness(vxi, data);
22197 +       case VCMD_get_badness:
22198 +               return vc_get_badness(vxi, data);
22199 +
22200 +       case VCMD_set_nflags:
22201 +               return vc_set_nflags(nxi, data);
22202 +       case VCMD_get_nflags:
22203 +               return vc_get_nflags(nxi, data);
22204 +
22205 +       case VCMD_set_ncaps:
22206 +               return vc_set_ncaps(nxi, data);
22207 +       case VCMD_get_ncaps:
22208 +               return vc_get_ncaps(nxi, data);
22209 +
22210 +       case VCMD_set_prio_bias:
22211 +               return vc_set_prio_bias(vxi, data);
22212 +       case VCMD_get_prio_bias:
22213 +               return vc_get_prio_bias(vxi, data);
22214 +       case VCMD_add_dlimit:
22215 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22216 +       case VCMD_rem_dlimit:
22217 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22218 +       case VCMD_set_dlimit:
22219 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22220 +       case VCMD_get_dlimit:
22221 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22222 +
22223 +       case VCMD_ctx_kill:
22224 +               return vc_ctx_kill(vxi, data);
22225 +
22226 +       case VCMD_wait_exit:
22227 +               return vc_wait_exit(vxi, data);
22228 +
22229 +       case VCMD_get_iattr:
22230 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22231 +       case VCMD_set_iattr:
22232 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22233 +
22234 +       case VCMD_fget_iattr:
22235 +               return vc_fget_iattr(id, data);
22236 +       case VCMD_fset_iattr:
22237 +               return vc_fset_iattr(id, data);
22238 +
22239 +       case VCMD_enter_space_v0:
22240 +               return vc_enter_space_v1(vxi, NULL);
22241 +       case VCMD_enter_space_v1:
22242 +               return vc_enter_space_v1(vxi, data);
22243 +       /* this is version 2 */
22244 +       case VCMD_enter_space:
22245 +               return vc_enter_space(vxi, data);
22246 +
22247 +       case VCMD_ctx_create_v0:
22248 +               return vc_ctx_create(id, NULL);
22249 +       case VCMD_ctx_create:
22250 +               return vc_ctx_create(id, data);
22251 +       case VCMD_ctx_migrate_v0:
22252 +               return vc_ctx_migrate(vxi, NULL);
22253 +       case VCMD_ctx_migrate:
22254 +               return vc_ctx_migrate(vxi, data);
22255 +
22256 +       case VCMD_net_create_v0:
22257 +               return vc_net_create(id, NULL);
22258 +       case VCMD_net_create:
22259 +               return vc_net_create(id, data);
22260 +       case VCMD_net_migrate:
22261 +               return vc_net_migrate(nxi, data);
22262 +
22263 +       case VCMD_tag_migrate:
22264 +               return vc_tag_migrate(id);
22265 +
22266 +       case VCMD_net_add:
22267 +               return vc_net_add(nxi, data);
22268 +       case VCMD_net_remove:
22269 +               return vc_net_remove(nxi, data);
22270 +
22271 +       case VCMD_net_add_ipv4_v1:
22272 +               return vc_net_add_ipv4_v1(nxi, data);
22273 +       /* this is version 2 */
22274 +       case VCMD_net_add_ipv4:
22275 +               return vc_net_add_ipv4(nxi, data);
22276 +
22277 +       case VCMD_net_rem_ipv4_v1:
22278 +               return vc_net_rem_ipv4_v1(nxi, data);
22279 +       /* this is version 2 */
22280 +       case VCMD_net_rem_ipv4:
22281 +               return vc_net_rem_ipv4(nxi, data);
22282 +#ifdef CONFIG_IPV6
22283 +       case VCMD_net_add_ipv6:
22284 +               return vc_net_add_ipv6(nxi, data);
22285 +       case VCMD_net_remove_ipv6:
22286 +               return vc_net_remove_ipv6(nxi, data);
22287 +#endif
22288 +/*     case VCMD_add_match_ipv4:
22289 +               return vc_add_match_ipv4(nxi, data);
22290 +       case VCMD_get_match_ipv4:
22291 +               return vc_get_match_ipv4(nxi, data);
22292 +#ifdef CONFIG_IPV6
22293 +       case VCMD_add_match_ipv6:
22294 +               return vc_add_match_ipv6(nxi, data);
22295 +       case VCMD_get_match_ipv6:
22296 +               return vc_get_match_ipv6(nxi, data);
22297 +#endif */
22298 +
22299 +#ifdef CONFIG_VSERVER_DEVICE
22300 +       case VCMD_set_mapping:
22301 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22302 +       case VCMD_unset_mapping:
22303 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22304 +#endif
22305 +#ifdef CONFIG_VSERVER_HISTORY
22306 +       case VCMD_dump_history:
22307 +               return vc_dump_history(id);
22308 +       case VCMD_read_history:
22309 +               return __COMPAT(vc_read_history, id, data, compat);
22310 +#endif
22311 +       default:
22312 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22313 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22314 +       }
22315 +       return -ENOSYS;
22316 +}
22317 +
22318 +
22319 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22320 +       case VCMD_ ## vcmd: perm = _perm;               \
22321 +               args = _args; flags = _flags; break
22322 +
22323 +
22324 +#define VCA_NONE       0x00
22325 +#define VCA_VXI                0x01
22326 +#define VCA_NXI                0x02
22327 +
22328 +#define VCF_NONE       0x00
22329 +#define VCF_INFO       0x01
22330 +#define VCF_ADMIN      0x02
22331 +#define VCF_ARES       0x06    /* includes admin */
22332 +#define VCF_SETUP      0x08
22333 +
22334 +#define VCF_ZIDOK      0x10    /* zero id okay */
22335 +
22336 +
22337 +static inline
22338 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22339 +{
22340 +       long ret;
22341 +       int permit = -1, state = 0;
22342 +       int perm = -1, args = 0, flags = 0;
22343 +       struct vx_info *vxi = NULL;
22344 +       struct nx_info *nxi = NULL;
22345 +
22346 +       switch (cmd) {
22347 +       /* unpriviledged commands */
22348 +       __VCMD(get_version,      0, VCA_NONE,   0);
22349 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22350 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22351 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22352 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22353 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22354 +
22355 +       /* info commands */
22356 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22357 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22358 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22359 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22360 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22361 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22362 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22363 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22364 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22365 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22366 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22367 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22368 +
22369 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22370 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22371 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22372 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22373 +
22374 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22375 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22376 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22377 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22378 +
22379 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22380 +
22381 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22382 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22383 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22384 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22385 +
22386 +       /* lower admin commands */
22387 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22388 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22389 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22390 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22391 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22392 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22393 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22394 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22395 +
22396 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22397 +       __VCMD(net_create,       5, VCA_NONE,   0);
22398 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22399 +
22400 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22401 +
22402 +       /* higher admin commands */
22403 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22404 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22405 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22406 +
22407 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22408 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22409 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22410 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22411 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22412 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22413 +
22414 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22415 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22416 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22417 +
22418 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22419 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22420 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22421 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22422 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22423 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22424 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22425 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22426 +#ifdef CONFIG_IPV6
22427 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22428 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22429 +#endif
22430 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22431 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22432 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22433 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22434 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22435 +
22436 +#ifdef CONFIG_VSERVER_DEVICE
22437 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22438 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22439 +#endif
22440 +       /* debug level admin commands */
22441 +#ifdef CONFIG_VSERVER_HISTORY
22442 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22443 +       __VCMD(read_history,     9, VCA_NONE,   0);
22444 +#endif
22445 +
22446 +       default:
22447 +               perm = -1;
22448 +       }
22449 +
22450 +       vxdprintk(VXD_CBIT(switch, 0),
22451 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22452 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22453 +               VC_VERSION(cmd), id, data, compat,
22454 +               perm, args, flags);
22455 +
22456 +       ret = -ENOSYS;
22457 +       if (perm < 0)
22458 +               goto out;
22459 +
22460 +       state = 1;
22461 +       if (!capable(CAP_CONTEXT))
22462 +               goto out;
22463 +
22464 +       state = 2;
22465 +       /* moved here from the individual commands */
22466 +       ret = -EPERM;
22467 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22468 +               goto out;
22469 +
22470 +       state = 3;
22471 +       /* vcmd involves resource management  */
22472 +       ret = -EPERM;
22473 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22474 +               goto out;
22475 +
22476 +       state = 4;
22477 +       /* various legacy exceptions */
22478 +       switch (cmd) {
22479 +       /* will go away when spectator is a cap */
22480 +       case VCMD_ctx_migrate_v0:
22481 +       case VCMD_ctx_migrate:
22482 +               if (id == 1) {
22483 +                       current->xid = 1;
22484 +                       ret = 1;
22485 +                       goto out;
22486 +               }
22487 +               break;
22488 +
22489 +       /* will go away when spectator is a cap */
22490 +       case VCMD_net_migrate:
22491 +               if (id == 1) {
22492 +                       current->nid = 1;
22493 +                       ret = 1;
22494 +                       goto out;
22495 +               }
22496 +               break;
22497 +       }
22498 +
22499 +       /* vcmds are fine by default */
22500 +       permit = 1;
22501 +
22502 +       /* admin type vcmds require admin ... */
22503 +       if (flags & VCF_ADMIN)
22504 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22505 +
22506 +       /* ... but setup type vcmds override that */
22507 +       if (!permit && (flags & VCF_SETUP))
22508 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22509 +
22510 +       state = 5;
22511 +       ret = -EPERM;
22512 +       if (!permit)
22513 +               goto out;
22514 +
22515 +       state = 6;
22516 +       if (!id && (flags & VCF_ZIDOK))
22517 +               goto skip_id;
22518 +
22519 +       ret = -ESRCH;
22520 +       if (args & VCA_VXI) {
22521 +               vxi = lookup_vx_info(id);
22522 +               if (!vxi)
22523 +                       goto out;
22524 +
22525 +               if ((flags & VCF_ADMIN) &&
22526 +                       /* special case kill for shutdown */
22527 +                       (cmd != VCMD_ctx_kill) &&
22528 +                       /* can context be administrated? */
22529 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22530 +                       ret = -EACCES;
22531 +                       goto out_vxi;
22532 +               }
22533 +       }
22534 +       state = 7;
22535 +       if (args & VCA_NXI) {
22536 +               nxi = lookup_nx_info(id);
22537 +               if (!nxi)
22538 +                       goto out_vxi;
22539 +
22540 +               if ((flags & VCF_ADMIN) &&
22541 +                       /* can context be administrated? */
22542 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22543 +                       ret = -EACCES;
22544 +                       goto out_nxi;
22545 +               }
22546 +       }
22547 +skip_id:
22548 +       state = 8;
22549 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22550 +
22551 +out_nxi:
22552 +       if ((args & VCA_NXI) && nxi)
22553 +               put_nx_info(nxi);
22554 +out_vxi:
22555 +       if ((args & VCA_VXI) && vxi)
22556 +               put_vx_info(vxi);
22557 +out:
22558 +       vxdprintk(VXD_CBIT(switch, 1),
22559 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22560 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22561 +               VC_VERSION(cmd), ret, ret, state, permit);
22562 +       return ret;
22563 +}
22564 +
22565 +asmlinkage long
22566 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22567 +{
22568 +       return do_vserver(cmd, id, data, 0);
22569 +}
22570 +
22571 +#ifdef CONFIG_COMPAT
22572 +
22573 +asmlinkage long
22574 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22575 +{
22576 +       return do_vserver(cmd, id, data, 1);
22577 +}
22578 +
22579 +#endif /* CONFIG_COMPAT */
22580 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c
22581 --- linux-3.13.10/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22582 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c    2014-01-31 20:38:04.000000000 +0000
22583 @@ -0,0 +1,247 @@
22584 +/*
22585 + *  kernel/vserver/sysctl.c
22586 + *
22587 + *  Virtual Context Support
22588 + *
22589 + *  Copyright (C) 2004-2007  Herbert Pötzl
22590 + *
22591 + *  V0.01  basic structure
22592 + *
22593 + */
22594 +
22595 +#include <linux/module.h>
22596 +#include <linux/ctype.h>
22597 +#include <linux/sysctl.h>
22598 +#include <linux/parser.h>
22599 +#include <asm/uaccess.h>
22600 +
22601 +enum {
22602 +       CTL_DEBUG_ERROR         = 0,
22603 +       CTL_DEBUG_SWITCH        = 1,
22604 +       CTL_DEBUG_XID,
22605 +       CTL_DEBUG_NID,
22606 +       CTL_DEBUG_TAG,
22607 +       CTL_DEBUG_NET,
22608 +       CTL_DEBUG_LIMIT,
22609 +       CTL_DEBUG_CRES,
22610 +       CTL_DEBUG_DLIM,
22611 +       CTL_DEBUG_QUOTA,
22612 +       CTL_DEBUG_CVIRT,
22613 +       CTL_DEBUG_SPACE,
22614 +       CTL_DEBUG_PERM,
22615 +       CTL_DEBUG_MISC,
22616 +};
22617 +
22618 +
22619 +unsigned int vs_debug_switch   = 0;
22620 +unsigned int vs_debug_xid      = 0;
22621 +unsigned int vs_debug_nid      = 0;
22622 +unsigned int vs_debug_tag      = 0;
22623 +unsigned int vs_debug_net      = 0;
22624 +unsigned int vs_debug_limit    = 0;
22625 +unsigned int vs_debug_cres     = 0;
22626 +unsigned int vs_debug_dlim     = 0;
22627 +unsigned int vs_debug_quota    = 0;
22628 +unsigned int vs_debug_cvirt    = 0;
22629 +unsigned int vs_debug_space    = 0;
22630 +unsigned int vs_debug_perm     = 0;
22631 +unsigned int vs_debug_misc     = 0;
22632 +
22633 +
22634 +static struct ctl_table_header *vserver_table_header;
22635 +static ctl_table vserver_root_table[];
22636 +
22637 +
22638 +void vserver_register_sysctl(void)
22639 +{
22640 +       if (!vserver_table_header) {
22641 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22642 +       }
22643 +
22644 +}
22645 +
22646 +void vserver_unregister_sysctl(void)
22647 +{
22648 +       if (vserver_table_header) {
22649 +               unregister_sysctl_table(vserver_table_header);
22650 +               vserver_table_header = NULL;
22651 +       }
22652 +}
22653 +
22654 +
22655 +static int proc_dodebug(ctl_table *table, int write,
22656 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22657 +{
22658 +       char            tmpbuf[20], *p, c;
22659 +       unsigned int    value;
22660 +       size_t          left, len;
22661 +
22662 +       if ((*ppos && !write) || !*lenp) {
22663 +               *lenp = 0;
22664 +               return 0;
22665 +       }
22666 +
22667 +       left = *lenp;
22668 +
22669 +       if (write) {
22670 +               if (!access_ok(VERIFY_READ, buffer, left))
22671 +                       return -EFAULT;
22672 +               p = (char *)buffer;
22673 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22674 +                       left--, p++;
22675 +               if (!left)
22676 +                       goto done;
22677 +
22678 +               if (left > sizeof(tmpbuf) - 1)
22679 +                       return -EINVAL;
22680 +               if (copy_from_user(tmpbuf, p, left))
22681 +                       return -EFAULT;
22682 +               tmpbuf[left] = '\0';
22683 +
22684 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22685 +                       value = 10 * value + (*p - '0');
22686 +               if (*p && !isspace(*p))
22687 +                       return -EINVAL;
22688 +               while (left && isspace(*p))
22689 +                       left--, p++;
22690 +               *(unsigned int *)table->data = value;
22691 +       } else {
22692 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22693 +                       return -EFAULT;
22694 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22695 +               if (len > left)
22696 +                       len = left;
22697 +               if (__copy_to_user(buffer, tmpbuf, len))
22698 +                       return -EFAULT;
22699 +               if ((left -= len) > 0) {
22700 +                       if (put_user('\n', (char *)buffer + len))
22701 +                               return -EFAULT;
22702 +                       left--;
22703 +               }
22704 +       }
22705 +
22706 +done:
22707 +       *lenp -= left;
22708 +       *ppos += *lenp;
22709 +       return 0;
22710 +}
22711 +
22712 +static int zero;
22713 +
22714 +#define        CTL_ENTRY(ctl, name)                            \
22715 +       {                                               \
22716 +               .procname       = #name,                \
22717 +               .data           = &vs_ ## name,         \
22718 +               .maxlen         = sizeof(int),          \
22719 +               .mode           = 0644,                 \
22720 +               .proc_handler   = &proc_dodebug,        \
22721 +               .extra1         = &zero,                \
22722 +               .extra2         = &zero,                \
22723 +       }
22724 +
22725 +static ctl_table vserver_debug_table[] = {
22726 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22727 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22728 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22729 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22730 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22731 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22732 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22733 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22734 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22735 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22736 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22737 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22738 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22739 +       { 0 }
22740 +};
22741 +
22742 +static ctl_table vserver_root_table[] = {
22743 +       {
22744 +               .procname       = "vserver",
22745 +               .mode           = 0555,
22746 +               .child          = vserver_debug_table
22747 +       },
22748 +       { 0 }
22749 +};
22750 +
22751 +
22752 +static match_table_t tokens = {
22753 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22754 +       { CTL_DEBUG_XID,        "xid=%x"        },
22755 +       { CTL_DEBUG_NID,        "nid=%x"        },
22756 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22757 +       { CTL_DEBUG_NET,        "net=%x"        },
22758 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22759 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22760 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22761 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22762 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22763 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22764 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22765 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22766 +       { CTL_DEBUG_ERROR,      NULL            }
22767 +};
22768 +
22769 +#define        HANDLE_CASE(id, name, val)                              \
22770 +       case CTL_DEBUG_ ## id:                                  \
22771 +               vs_debug_ ## name = val;                        \
22772 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22773 +               break
22774 +
22775 +
22776 +static int __init vs_debug_setup(char *str)
22777 +{
22778 +       char *p;
22779 +       int token;
22780 +
22781 +       printk("vs_debug_setup(%s)\n", str);
22782 +       while ((p = strsep(&str, ",")) != NULL) {
22783 +               substring_t args[MAX_OPT_ARGS];
22784 +               unsigned int value;
22785 +
22786 +               if (!*p)
22787 +                       continue;
22788 +
22789 +               token = match_token(p, tokens, args);
22790 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22791 +
22792 +               switch (token) {
22793 +               HANDLE_CASE(SWITCH, switch, value);
22794 +               HANDLE_CASE(XID,    xid,    value);
22795 +               HANDLE_CASE(NID,    nid,    value);
22796 +               HANDLE_CASE(TAG,    tag,    value);
22797 +               HANDLE_CASE(NET,    net,    value);
22798 +               HANDLE_CASE(LIMIT,  limit,  value);
22799 +               HANDLE_CASE(CRES,   cres,   value);
22800 +               HANDLE_CASE(DLIM,   dlim,   value);
22801 +               HANDLE_CASE(QUOTA,  quota,  value);
22802 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22803 +               HANDLE_CASE(SPACE,  space,  value);
22804 +               HANDLE_CASE(PERM,   perm,   value);
22805 +               HANDLE_CASE(MISC,   misc,   value);
22806 +               default:
22807 +                       return -EINVAL;
22808 +                       break;
22809 +               }
22810 +       }
22811 +       return 1;
22812 +}
22813 +
22814 +__setup("vsdebug=", vs_debug_setup);
22815 +
22816 +
22817 +
22818 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22819 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22820 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22821 +EXPORT_SYMBOL_GPL(vs_debug_net);
22822 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22823 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22824 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22825 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22826 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22827 +EXPORT_SYMBOL_GPL(vs_debug_space);
22828 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22829 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22830 +
22831 diff -NurpP --minimal linux-3.13.10/kernel/vserver/tag.c linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c
22832 --- linux-3.13.10/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22833 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c       2014-01-31 20:38:04.000000000 +0000
22834 @@ -0,0 +1,63 @@
22835 +/*
22836 + *  linux/kernel/vserver/tag.c
22837 + *
22838 + *  Virtual Server: Shallow Tag Space
22839 + *
22840 + *  Copyright (C) 2007  Herbert Pötzl
22841 + *
22842 + *  V0.01  basic implementation
22843 + *
22844 + */
22845 +
22846 +#include <linux/sched.h>
22847 +#include <linux/vserver/debug.h>
22848 +#include <linux/vs_pid.h>
22849 +#include <linux/vs_tag.h>
22850 +
22851 +#include <linux/vserver/tag_cmd.h>
22852 +
22853 +
22854 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22855 +{
22856 +       if (!p)
22857 +               BUG();
22858 +
22859 +       vxdprintk(VXD_CBIT(tag, 5),
22860 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22861 +
22862 +       task_lock(p);
22863 +       p->tag = tag;
22864 +       task_unlock(p);
22865 +
22866 +       vxdprintk(VXD_CBIT(tag, 5),
22867 +               "moved task %p into [#%d]", p, tag);
22868 +       return 0;
22869 +}
22870 +
22871 +/* vserver syscall commands below here */
22872 +
22873 +/* taks xid and vx_info functions */
22874 +
22875 +
22876 +int vc_task_tag(uint32_t id)
22877 +{
22878 +       vtag_t tag;
22879 +
22880 +       if (id) {
22881 +               struct task_struct *tsk;
22882 +               rcu_read_lock();
22883 +               tsk = find_task_by_real_pid(id);
22884 +               tag = (tsk) ? tsk->tag : -ESRCH;
22885 +               rcu_read_unlock();
22886 +       } else
22887 +               tag = dx_current_tag();
22888 +       return tag;
22889 +}
22890 +
22891 +
22892 +int vc_tag_migrate(uint32_t tag)
22893 +{
22894 +       return dx_migrate_task(current, tag & 0xFFFF);
22895 +}
22896 +
22897 +
22898 diff -NurpP --minimal linux-3.13.10/kernel/vserver/vci_config.h linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h
22899 --- linux-3.13.10/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22900 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h        2014-01-31 20:38:04.000000000 +0000
22901 @@ -0,0 +1,80 @@
22902 +
22903 +/*  interface version */
22904 +
22905 +#define VCI_VERSION            0x00020308
22906 +
22907 +
22908 +enum {
22909 +       VCI_KCBIT_NO_DYNAMIC = 0,
22910 +
22911 +       VCI_KCBIT_PROC_SECURE = 4,
22912 +       /* VCI_KCBIT_HARDCPU = 5, */
22913 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22914 +       /* VCI_KCBIT_IDLETIME = 7, */
22915 +
22916 +       VCI_KCBIT_COWBL = 8,
22917 +       VCI_KCBIT_FULLCOWBL = 9,
22918 +       VCI_KCBIT_SPACES = 10,
22919 +       VCI_KCBIT_NETV2 = 11,
22920 +       VCI_KCBIT_MEMCG = 12,
22921 +       VCI_KCBIT_MEMCG_SWAP = 13,
22922 +
22923 +       VCI_KCBIT_DEBUG = 16,
22924 +       VCI_KCBIT_HISTORY = 20,
22925 +       VCI_KCBIT_TAGGED = 24,
22926 +       VCI_KCBIT_PPTAG = 28,
22927 +
22928 +       VCI_KCBIT_MORE = 31,
22929 +};
22930 +
22931 +
22932 +static inline uint32_t vci_kernel_config(void)
22933 +{
22934 +       return
22935 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22936 +
22937 +       /* configured features */
22938 +#ifdef CONFIG_VSERVER_PROC_SECURE
22939 +       (1 << VCI_KCBIT_PROC_SECURE) |
22940 +#endif
22941 +#ifdef CONFIG_VSERVER_COWBL
22942 +       (1 << VCI_KCBIT_COWBL) |
22943 +       (1 << VCI_KCBIT_FULLCOWBL) |
22944 +#endif
22945 +       (1 << VCI_KCBIT_SPACES) |
22946 +       (1 << VCI_KCBIT_NETV2) |
22947 +#ifdef CONFIG_MEMCG
22948 +       (1 << VCI_KCBIT_MEMCG) |
22949 +#endif
22950 +#ifdef CONFIG_MEMCG_SWAP
22951 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
22952 +#endif
22953 +
22954 +       /* debug options */
22955 +#ifdef CONFIG_VSERVER_DEBUG
22956 +       (1 << VCI_KCBIT_DEBUG) |
22957 +#endif
22958 +#ifdef CONFIG_VSERVER_HISTORY
22959 +       (1 << VCI_KCBIT_HISTORY) |
22960 +#endif
22961 +
22962 +       /* inode context tagging */
22963 +#if    defined(CONFIG_TAGGING_NONE)
22964 +       (0 << VCI_KCBIT_TAGGED) |
22965 +#elif  defined(CONFIG_TAGGING_UID16)
22966 +       (1 << VCI_KCBIT_TAGGED) |
22967 +#elif  defined(CONFIG_TAGGING_GID16)
22968 +       (2 << VCI_KCBIT_TAGGED) |
22969 +#elif  defined(CONFIG_TAGGING_ID24)
22970 +       (3 << VCI_KCBIT_TAGGED) |
22971 +#elif  defined(CONFIG_TAGGING_INTERN)
22972 +       (4 << VCI_KCBIT_TAGGED) |
22973 +#elif  defined(CONFIG_TAGGING_RUNTIME)
22974 +       (5 << VCI_KCBIT_TAGGED) |
22975 +#else
22976 +       (7 << VCI_KCBIT_TAGGED) |
22977 +#endif
22978 +       (1 << VCI_KCBIT_PPTAG) |
22979 +       0;
22980 +}
22981 +
22982 diff -NurpP --minimal linux-3.13.10/mm/memcontrol.c linux-3.13.10-vs2.3.6.11/mm/memcontrol.c
22983 --- linux-3.13.10/mm/memcontrol.c       2014-04-17 01:12:40.000000000 +0000
22984 +++ linux-3.13.10-vs2.3.6.11/mm/memcontrol.c    2014-04-17 01:17:11.000000000 +0000
22985 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
22986         return mem_cgroup_from_css(task_css(p, memory_cgrp_id));
22987  }
22988  
22989 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
22990 +{
22991 +       return res_counter_read_u64(&mem->res, member);
22992 +}
22993 +
22994 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
22995 +{
22996 +       return res_counter_read_u64(&mem->memsw, member);
22997 +}
22998 +
22999 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23000 +{
23001 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23002 +}
23003 +
23004 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23005 +{
23006 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23007 +}
23008 +
23009 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23010 +{
23011 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23012 +}
23013 +
23014  static struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
23015  {
23016         struct mem_cgroup *memcg = NULL;
23017 diff -NurpP --minimal linux-3.13.10/mm/oom_kill.c linux-3.13.10-vs2.3.6.11/mm/oom_kill.c
23018 --- linux-3.13.10/mm/oom_kill.c 2014-04-17 01:12:40.000000000 +0000
23019 +++ linux-3.13.10-vs2.3.6.11/mm/oom_kill.c      2014-02-25 11:26:10.000000000 +0000
23020 @@ -35,6 +35,8 @@
23021  #include <linux/freezer.h>
23022  #include <linux/ftrace.h>
23023  #include <linux/ratelimit.h>
23024 +#include <linux/reboot.h>
23025 +#include <linux/vs_context.h>
23026  
23027  #define CREATE_TRACE_POINTS
23028  #include <trace/events/oom.h>
23029 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23030  static bool oom_unkillable_task(struct task_struct *p,
23031                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23032  {
23033 -       if (is_global_init(p))
23034 +       unsigned xid = vx_current_xid();
23035 +
23036 +       /* skip the init task, global and per guest */
23037 +       if (task_is_init(p))
23038                 return true;
23039         if (p->flags & PF_KTHREAD)
23040                 return true;
23041  
23042 +       /* skip other guest and host processes if oom in guest */
23043 +       if (xid && vx_task_xid(p) != xid)
23044 +               return true;
23045 +
23046         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23047         if (memcg && !task_in_mem_cgroup(p, memcg))
23048                 return true;
23049 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23050                 dump_header(p, gfp_mask, order, memcg, nodemask);
23051  
23052         task_lock(p);
23053 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23054 -               message, task_pid_nr(p), p->comm, points);
23055 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23056 +               message, task_pid_nr(p), p->xid, p->comm, points);
23057         task_unlock(p);
23058  
23059         /*
23060 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23061  
23062         /* mm cannot safely be dereferenced after task_unlock(victim) */
23063         mm = victim->mm;
23064 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23065 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23066 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23067 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23068                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23069                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23070         task_unlock(victim);
23071 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23072  }
23073  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23074  
23075 +long vs_oom_action(unsigned int);
23076 +
23077  /*
23078   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23079   * if a parallel OOM killing is already taking place that includes a zone in
23080 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23081         /* Found nothing?!?! Either we hang forever, or we panic. */
23082         if (!p) {
23083                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23084 -               panic("Out of memory and no killable processes...\n");
23085 +
23086 +               /* avoid panic for guest OOM */
23087 +               if (vx_current_xid())
23088 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23089 +               else
23090 +                       panic("Out of memory and no killable processes...\n");
23091         }
23092         if (p != (void *)-1UL) {
23093                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23094 diff -NurpP --minimal linux-3.13.10/mm/page_alloc.c linux-3.13.10-vs2.3.6.11/mm/page_alloc.c
23095 --- linux-3.13.10/mm/page_alloc.c       2014-04-17 01:12:40.000000000 +0000
23096 +++ linux-3.13.10-vs2.3.6.11/mm/page_alloc.c    2014-04-17 01:17:11.000000000 +0000
23097 @@ -61,6 +61,8 @@
23098  #include <linux/page-debug-flags.h>
23099  #include <linux/hugetlb.h>
23100  #include <linux/sched/rt.h>
23101 +#include <linux/vs_base.h>
23102 +#include <linux/vs_limit.h>
23103  
23104  #include <asm/sections.h>
23105  #include <asm/tlbflush.h>
23106 @@ -2983,6 +2985,9 @@ void si_meminfo(struct sysinfo *val)
23107         val->totalhigh = totalhigh_pages;
23108         val->freehigh = nr_free_highpages();
23109         val->mem_unit = PAGE_SIZE;
23110 +
23111 +       if (vx_flags(VXF_VIRT_MEM, 0))
23112 +               vx_vsi_meminfo(val);
23113  }
23114  
23115  EXPORT_SYMBOL(si_meminfo);
23116 @@ -3007,6 +3012,9 @@ void si_meminfo_node(struct sysinfo *val
23117         val->freehigh = 0;
23118  #endif
23119         val->mem_unit = PAGE_SIZE;
23120 +
23121 +       if (vx_flags(VXF_VIRT_MEM, 0))
23122 +               vx_vsi_meminfo(val);
23123  }
23124  #endif
23125  
23126 diff -NurpP --minimal linux-3.13.10/mm/pgtable-generic.c linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c
23127 --- linux-3.13.10/mm/pgtable-generic.c  2014-01-22 20:39:14.000000000 +0000
23128 +++ linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c       2014-01-31 20:38:04.000000000 +0000
23129 @@ -6,6 +6,8 @@
23130   *  Copyright (C) 2010  Linus Torvalds
23131   */
23132  
23133 +#include <linux/mm.h>
23134 +
23135  #include <linux/pagemap.h>
23136  #include <asm/tlb.h>
23137  #include <asm-generic/pgtable.h>
23138 diff -NurpP --minimal linux-3.13.10/mm/shmem.c linux-3.13.10-vs2.3.6.11/mm/shmem.c
23139 --- linux-3.13.10/mm/shmem.c    2014-01-22 20:39:14.000000000 +0000
23140 +++ linux-3.13.10-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23141 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23142  {
23143         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23144  
23145 -       buf->f_type = TMPFS_MAGIC;
23146 +       buf->f_type = TMPFS_SUPER_MAGIC;
23147         buf->f_bsize = PAGE_CACHE_SIZE;
23148         buf->f_namelen = NAME_MAX;
23149         if (sbinfo->max_blocks) {
23150 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23151         sb->s_maxbytes = MAX_LFS_FILESIZE;
23152         sb->s_blocksize = PAGE_CACHE_SIZE;
23153         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23154 -       sb->s_magic = TMPFS_MAGIC;
23155 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23156         sb->s_op = &shmem_ops;
23157         sb->s_time_gran = 1;
23158  #ifdef CONFIG_TMPFS_XATTR
23159 diff -NurpP --minimal linux-3.13.10/mm/slab.c linux-3.13.10-vs2.3.6.11/mm/slab.c
23160 --- linux-3.13.10/mm/slab.c     2014-01-22 20:39:14.000000000 +0000
23161 +++ linux-3.13.10-vs2.3.6.11/mm/slab.c  2014-01-31 20:38:04.000000000 +0000
23162 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23163  #define STATS_INC_FREEMISS(x)  do { } while (0)
23164  #endif
23165  
23166 +#include "slab_vs.h"
23167 +
23168  #if DEBUG
23169  
23170  /*
23171 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23172         /* ___cache_alloc_node can fall back to other nodes */
23173         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23174    out:
23175 +       vx_slab_alloc(cachep, flags);
23176         local_irq_restore(save_flags);
23177         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23178         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23179 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23180         check_irq_off();
23181         kmemleak_free_recursive(objp, cachep->flags);
23182         objp = cache_free_debugcheck(cachep, objp, caller);
23183 +       vx_slab_free(cachep);
23184  
23185         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23186  
23187 diff -NurpP --minimal linux-3.13.10/mm/slab_vs.h linux-3.13.10-vs2.3.6.11/mm/slab_vs.h
23188 --- linux-3.13.10/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23189 +++ linux-3.13.10-vs2.3.6.11/mm/slab_vs.h       2014-01-31 20:38:04.000000000 +0000
23190 @@ -0,0 +1,29 @@
23191 +
23192 +#include <linux/vserver/context.h>
23193 +
23194 +#include <linux/vs_context.h>
23195 +
23196 +static inline
23197 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23198 +{
23199 +       int what = gfp_zone(cachep->allocflags);
23200 +       struct vx_info *vxi = current_vx_info();
23201 +
23202 +       if (!vxi)
23203 +               return;
23204 +
23205 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23206 +}
23207 +
23208 +static inline
23209 +void vx_slab_free(struct kmem_cache *cachep)
23210 +{
23211 +       int what = gfp_zone(cachep->allocflags);
23212 +       struct vx_info *vxi = current_vx_info();
23213 +
23214 +       if (!vxi)
23215 +               return;
23216 +
23217 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23218 +}
23219 +
23220 diff -NurpP --minimal linux-3.13.10/mm/swapfile.c linux-3.13.10-vs2.3.6.11/mm/swapfile.c
23221 --- linux-3.13.10/mm/swapfile.c 2014-04-17 01:12:40.000000000 +0000
23222 +++ linux-3.13.10-vs2.3.6.11/mm/swapfile.c      2014-02-25 11:26:10.000000000 +0000
23223 @@ -39,6 +39,7 @@
23224  #include <asm/tlbflush.h>
23225  #include <linux/swapops.h>
23226  #include <linux/page_cgroup.h>
23227 +#include <linux/vs_base.h>
23228  
23229  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23230                                  unsigned char);
23231 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23232  
23233         if (si == SEQ_START_TOKEN) {
23234                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23235 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23236 +                       struct sysinfo si;
23237 +
23238 +                       vx_vsi_swapinfo(&si);
23239 +                       if (si.totalswap < (1 << 10))
23240 +                               return 0;
23241 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23242 +                               "hdv0", "partition", si.totalswap >> 10,
23243 +                               (si.totalswap - si.freeswap) >> 10, -1);
23244 +               }
23245                 return 0;
23246         }
23247  
23248 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23249         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23250         val->totalswap = total_swap_pages + nr_to_be_unused;
23251         spin_unlock(&swap_lock);
23252 +       if (vx_flags(VXF_VIRT_MEM, 0))
23253 +               vx_vsi_swapinfo(val);
23254  }
23255  
23256  /*
23257 diff -NurpP --minimal linux-3.13.10/net/bridge/br_multicast.c linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c
23258 --- linux-3.13.10/net/bridge/br_multicast.c     2014-04-17 01:12:40.000000000 +0000
23259 +++ linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c  2014-04-17 01:17:11.000000000 +0000
23260 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23261         ip6h->hop_limit = 1;
23262         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23263         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23264 -                              &ip6h->saddr)) {
23265 +                              &ip6h->saddr, NULL)) {
23266                 kfree_skb(skb);
23267                 return NULL;
23268         }
23269 diff -NurpP --minimal linux-3.13.10/net/core/dev.c linux-3.13.10-vs2.3.6.11/net/core/dev.c
23270 --- linux-3.13.10/net/core/dev.c        2014-04-17 01:12:41.000000000 +0000
23271 +++ linux-3.13.10-vs2.3.6.11/net/core/dev.c     2014-03-12 15:51:08.000000000 +0000
23272 @@ -122,6 +122,7 @@
23273  #include <linux/in.h>
23274  #include <linux/jhash.h>
23275  #include <linux/random.h>
23276 +#include <linux/vs_inet.h>
23277  #include <trace/events/napi.h>
23278  #include <trace/events/net.h>
23279  #include <trace/events/skb.h>
23280 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23281         struct hlist_head *head = dev_name_hash(net, name);
23282  
23283         hlist_for_each_entry(dev, head, name_hlist)
23284 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23285 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23286 +                   nx_dev_visible(current_nx_info(), dev))
23287                         return dev;
23288  
23289         return NULL;
23290 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23291         struct hlist_head *head = dev_name_hash(net, name);
23292  
23293         hlist_for_each_entry_rcu(dev, head, name_hlist)
23294 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23295 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23296 +                   nx_dev_visible(current_nx_info(), dev))
23297                         return dev;
23298  
23299         return NULL;
23300 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23301         struct hlist_head *head = dev_index_hash(net, ifindex);
23302  
23303         hlist_for_each_entry(dev, head, index_hlist)
23304 -               if (dev->ifindex == ifindex)
23305 +               if ((dev->ifindex == ifindex) &&
23306 +                   nx_dev_visible(current_nx_info(), dev))
23307                         return dev;
23308  
23309         return NULL;
23310 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23311   *     about locking. The caller must hold RCU lock.
23312   */
23313  
23314 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23315 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23316  {
23317         struct net_device *dev;
23318         struct hlist_head *head = dev_index_hash(net, ifindex);
23319 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23320  
23321         return NULL;
23322  }
23323 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23324 +
23325 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23326 +{
23327 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23328 +
23329 +       if (nx_dev_visible(current_nx_info(), dev))
23330 +               return dev;
23331 +       return NULL;
23332 +}
23333  EXPORT_SYMBOL(dev_get_by_index_rcu);
23334  
23335  
23336 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23337  
23338         for_each_netdev_rcu(net, dev)
23339                 if (dev->type == type &&
23340 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23341 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23342 +                   nx_dev_visible(current_nx_info(), dev))
23343                         return dev;
23344  
23345         return NULL;
23346 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23347         struct net_device *dev;
23348  
23349         ASSERT_RTNL();
23350 -       for_each_netdev(net, dev)
23351 -               if (dev->type == type)
23352 +       for_each_netdev(net, dev) {
23353 +               if ((dev->type == type) &&
23354 +                   nx_dev_visible(current_nx_info(), dev))
23355                         return dev;
23356 +       }
23357  
23358         return NULL;
23359  }
23360 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23361  
23362         rcu_read_lock();
23363         for_each_netdev_rcu(net, dev)
23364 -               if (dev->type == type) {
23365 +               if ((dev->type == type) &&
23366 +                   nx_dev_visible(current_nx_info(), dev)) {
23367                         dev_hold(dev);
23368                         ret = dev;
23369                         break;
23370 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23371  
23372         ret = NULL;
23373         for_each_netdev_rcu(net, dev) {
23374 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23375 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23376 +                       nx_dev_visible(current_nx_info(), dev)) {
23377                         ret = dev;
23378                         break;
23379                 }
23380 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23381                                 continue;
23382                         if (i < 0 || i >= max_netdevices)
23383                                 continue;
23384 +                       if (!nx_dev_visible(current_nx_info(), d))
23385 +                               continue;
23386  
23387                         /*  avoid cases where sscanf is not exact inverse of printf */
23388                         snprintf(buf, IFNAMSIZ, name, i);
23389 diff -NurpP --minimal linux-3.13.10/net/core/net-procfs.c linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c
23390 --- linux-3.13.10/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23391 +++ linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c      2014-01-31 20:38:04.000000000 +0000
23392 @@ -1,6 +1,7 @@
23393  #include <linux/netdevice.h>
23394  #include <linux/proc_fs.h>
23395  #include <linux/seq_file.h>
23396 +#include <linux/vs_inet.h>
23397  #include <net/wext.h>
23398  
23399  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23400 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23401  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23402  {
23403         struct rtnl_link_stats64 temp;
23404 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23405 +       const struct rtnl_link_stats64 *stats;
23406 +
23407 +       /* device visible inside network context? */
23408 +       if (!nx_dev_visible(current_nx_info(), dev))
23409 +               return;
23410  
23411 +       stats = dev_get_stats(dev, &temp);
23412         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23413                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23414                    dev->name, stats->rx_bytes, stats->rx_packets,
23415 diff -NurpP --minimal linux-3.13.10/net/core/rtnetlink.c linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c
23416 --- linux-3.13.10/net/core/rtnetlink.c  2014-04-17 01:12:41.000000000 +0000
23417 +++ linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c       2014-04-17 01:17:11.000000000 +0000
23418 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23419                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23420                         if (idx < s_idx)
23421                                 goto cont;
23422 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23423 +                               continue;
23424                         err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23425                                                NETLINK_CB(cb->skb).portid,
23426                                                cb->nlh->nlmsg_seq, 0,
23427 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23428         int err = -ENOBUFS;
23429         size_t if_info_size;
23430  
23431 +       if (!nx_dev_visible(current_nx_info(), dev))
23432 +               return;
23433 +
23434         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23435         if (skb == NULL)
23436                 goto errout;
23437 diff -NurpP --minimal linux-3.13.10/net/core/sock.c linux-3.13.10-vs2.3.6.11/net/core/sock.c
23438 --- linux-3.13.10/net/core/sock.c       2014-04-17 01:12:41.000000000 +0000
23439 +++ linux-3.13.10-vs2.3.6.11/net/core/sock.c    2014-04-17 01:17:11.000000000 +0000
23440 @@ -133,6 +133,10 @@
23441  #include <net/netprio_cgroup.h>
23442  
23443  #include <linux/filter.h>
23444 +#include <linux/vs_socket.h>
23445 +#include <linux/vs_limit.h>
23446 +#include <linux/vs_context.h>
23447 +#include <linux/vs_network.h>
23448  
23449  #include <trace/events/sock.h>
23450  
23451 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23452                         goto out_free_sec;
23453                 sk_tx_queue_clear(sk);
23454         }
23455 +               sock_vx_init(sk);
23456 +               sock_nx_init(sk);
23457  
23458         return sk;
23459  
23460 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23461                 put_cred(sk->sk_peer_cred);
23462         put_pid(sk->sk_peer_pid);
23463         put_net(sock_net(sk));
23464 +       vx_sock_dec(sk);
23465 +       clr_vx_info(&sk->sk_vx_info);
23466 +       sk->sk_xid = -1;
23467 +       clr_nx_info(&sk->sk_nx_info);
23468 +       sk->sk_nid = -1;
23469         sk_prot_free(sk->sk_prot_creator, sk);
23470  }
23471  
23472 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23473  
23474                 /* SANITY */
23475                 get_net(sock_net(newsk));
23476 +               sock_vx_init(newsk);
23477 +               sock_nx_init(newsk);
23478                 sk_node_init(&newsk->sk_node);
23479                 sock_lock_init(newsk);
23480                 bh_lock_sock(newsk);
23481 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23482                 smp_wmb();
23483                 atomic_set(&newsk->sk_refcnt, 2);
23484  
23485 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23486 +               newsk->sk_xid = sk->sk_xid;
23487 +               vx_sock_inc(newsk);
23488 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23489 +               newsk->sk_nid = sk->sk_nid;
23490 +
23491                 /*
23492                  * Increment the counter in the same struct proto as the master
23493                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23494 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23495  
23496         sk->sk_stamp = ktime_set(-1L, 0);
23497  
23498 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23499 +       sk->sk_xid = vx_current_xid();
23500 +       vx_sock_inc(sk);
23501 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23502 +       sk->sk_nid = nx_current_nid();
23503 +
23504  #ifdef CONFIG_NET_RX_BUSY_POLL
23505         sk->sk_napi_id          =       0;
23506         sk->sk_ll_usec          =       sysctl_net_busy_read;
23507 diff -NurpP --minimal linux-3.13.10/net/ipv4/af_inet.c linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c
23508 --- linux-3.13.10/net/ipv4/af_inet.c    2014-04-17 01:12:41.000000000 +0000
23509 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c 2014-04-17 01:17:11.000000000 +0000
23510 @@ -118,6 +118,7 @@
23511  #ifdef CONFIG_IP_MROUTE
23512  #include <linux/mroute.h>
23513  #endif
23514 +#include <linux/vs_limit.h>
23515  
23516  
23517  /* The inetsw table contains everything that inet_create needs to
23518 @@ -309,10 +310,13 @@ lookup_protocol:
23519         }
23520  
23521         err = -EPERM;
23522 +       if ((protocol == IPPROTO_ICMP) &&
23523 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23524 +               goto override;
23525         if (sock->type == SOCK_RAW && !kern &&
23526             !ns_capable(net->user_ns, CAP_NET_RAW))
23527                 goto out_rcu_unlock;
23528 -
23529 +override:
23530         sock->ops = answer->ops;
23531         answer_prot = answer->prot;
23532         answer_no_check = answer->no_check;
23533 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23534         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23535         struct sock *sk = sock->sk;
23536         struct inet_sock *inet = inet_sk(sk);
23537 +       struct nx_v4_sock_addr nsa;
23538         struct net *net = sock_net(sk);
23539         unsigned short snum;
23540         int chk_addr_ret;
23541 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23542                         goto out;
23543         }
23544  
23545 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23546 +       err = v4_map_sock_addr(inet, addr, &nsa);
23547 +       if (err)
23548 +               goto out;
23549 +
23550 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
23551  
23552         /* Not specified by any standard per-se, however it breaks too
23553          * many applications when removed.  It is unfortunate since
23554 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23555         err = -EADDRNOTAVAIL;
23556         if (!sysctl_ip_nonlocal_bind &&
23557             !(inet->freebind || inet->transparent) &&
23558 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23559 +           nsa.saddr != htonl(INADDR_ANY) &&
23560             chk_addr_ret != RTN_LOCAL &&
23561             chk_addr_ret != RTN_MULTICAST &&
23562             chk_addr_ret != RTN_BROADCAST)
23563 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23564         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23565                 goto out_release_sock;
23566  
23567 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23568 +       v4_set_sock_addr(inet, &nsa);
23569         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23570                 inet->inet_saddr = 0;  /* Use device */
23571  
23572 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23573                      peer == 1))
23574                         return -ENOTCONN;
23575                 sin->sin_port = inet->inet_dport;
23576 -               sin->sin_addr.s_addr = inet->inet_daddr;
23577 +               sin->sin_addr.s_addr =
23578 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23579         } else {
23580                 __be32 addr = inet->inet_rcv_saddr;
23581                 if (!addr)
23582                         addr = inet->inet_saddr;
23583 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23584                 sin->sin_port = inet->inet_sport;
23585                 sin->sin_addr.s_addr = addr;
23586         }
23587 diff -NurpP --minimal linux-3.13.10/net/ipv4/arp.c linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c
23588 --- linux-3.13.10/net/ipv4/arp.c        2013-11-25 15:47:06.000000000 +0000
23589 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c     2014-01-31 20:38:04.000000000 +0000
23590 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23591         struct net_device *dev = n->dev;
23592         int hatype = dev->type;
23593  
23594 +       /* FIXME: check for network context */
23595         read_lock(&n->lock);
23596         /* Convert hardware address to XX:XX:XX:XX ... form. */
23597  #if IS_ENABLED(CONFIG_AX25)
23598 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23599         int hatype = dev ? dev->type : 0;
23600         char tbuf[16];
23601  
23602 +       /* FIXME: check for network context */
23603         sprintf(tbuf, "%pI4", n->key);
23604         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23605                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23606 diff -NurpP --minimal linux-3.13.10/net/ipv4/devinet.c linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c
23607 --- linux-3.13.10/net/ipv4/devinet.c    2014-04-17 01:12:41.000000000 +0000
23608 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23609 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23610  }
23611  EXPORT_SYMBOL(inetdev_by_index);
23612  
23613 +
23614  /* Called only from RTNL semaphored context. No locks. */
23615  
23616  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23617 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23618  
23619         in_dev = __in_dev_get_rtnl(dev);
23620         if (in_dev) {
23621 +               struct nx_info *nxi = current_nx_info();
23622 +
23623                 if (tryaddrmatch) {
23624                         /* Matthias Andree */
23625                         /* compare label and address (4.4BSD style) */
23626 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23627                            This is checked above. */
23628                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23629                              ifap = &ifa->ifa_next) {
23630 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23631 +                                       continue;
23632                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23633                                     sin_orig.sin_addr.s_addr ==
23634                                                         ifa->ifa_local) {
23635 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23636                    comparing just the label */
23637                 if (!ifa) {
23638                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23639 -                            ifap = &ifa->ifa_next)
23640 +                            ifap = &ifa->ifa_next) {
23641 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23642 +                                       continue;
23643                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23644                                         break;
23645 +                       }
23646                 }
23647         }
23648  
23649 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23650                 goto out;
23651  
23652         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23653 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23654 +                       continue;
23655                 if (!buf) {
23656                         done += sizeof(ifr);
23657                         continue;
23658 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23659         struct net_device *dev;
23660         struct in_device *in_dev;
23661         struct in_ifaddr *ifa;
23662 +       struct sock *sk = skb->sk;
23663         struct hlist_head *head;
23664  
23665         s_h = cb->args[0];
23666 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23667  
23668                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23669                              ifa = ifa->ifa_next, ip_idx++) {
23670 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23671 +                               continue;
23672                                 if (ip_idx < s_ip_idx)
23673                                         continue;
23674                                 if (inet_fill_ifaddr(skb, ifa,
23675 diff -NurpP --minimal linux-3.13.10/net/ipv4/fib_trie.c linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c
23676 --- linux-3.13.10/net/ipv4/fib_trie.c   2014-01-22 20:39:15.000000000 +0000
23677 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c        2014-01-31 20:38:04.000000000 +0000
23678 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23679  
23680                         seq_setwidth(seq, 127);
23681  
23682 +                       /* FIXME: check for network context? */
23683                         if (fi)
23684                                 seq_printf(seq,
23685                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23686 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_connection_sock.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c
23687 --- linux-3.13.10/net/ipv4/inet_connection_sock.c       2014-01-22 20:39:15.000000000 +0000
23688 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c    2014-02-01 00:33:11.000000000 +0000
23689 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23690  }
23691  EXPORT_SYMBOL(inet_get_local_port_range);
23692  
23693 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23694 +{
23695 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23696 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23697 +
23698 +       if (inet_v6_ipv6only(sk2))
23699 +               return 0;
23700 +
23701 +       if (sk1_rcv_saddr &&
23702 +           sk2_rcv_saddr &&
23703 +           sk1_rcv_saddr == sk2_rcv_saddr)
23704 +               return 1;
23705 +
23706 +       if (sk1_rcv_saddr &&
23707 +           !sk2_rcv_saddr &&
23708 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23709 +               return 1;
23710 +
23711 +       if (sk2_rcv_saddr &&
23712 +           !sk1_rcv_saddr &&
23713 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23714 +               return 1;
23715 +
23716 +       if (!sk1_rcv_saddr &&
23717 +           !sk2_rcv_saddr &&
23718 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23719 +               return 1;
23720 +
23721 +       return 0;
23722 +}
23723 +
23724  int inet_csk_bind_conflict(const struct sock *sk,
23725                            const struct inet_bind_bucket *tb, bool relax)
23726  {
23727 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23728                             (sk2->sk_state != TCP_TIME_WAIT &&
23729                              !uid_eq(uid, sock_i_uid(sk2))))) {
23730  
23731 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23732 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23733 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23734                                         break;
23735                         }
23736                         if (!relax && reuse && sk2->sk_reuse &&
23737                             sk2->sk_state != TCP_LISTEN) {
23738  
23739 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23740 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23741 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23742                                         break;
23743                         }
23744                 }
23745 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_diag.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c
23746 --- linux-3.13.10/net/ipv4/inet_diag.c  2014-02-01 02:17:51.000000000 +0000
23747 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c       2014-02-01 02:32:22.000000000 +0000
23748 @@ -31,6 +31,8 @@
23749  
23750  #include <linux/inet.h>
23751  #include <linux/stddef.h>
23752 +#include <linux/vs_network.h>
23753 +#include <linux/vs_inet.h>
23754  
23755  #include <linux/inet_diag.h>
23756  #include <linux/sock_diag.h>
23757 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23758         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23759         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23760  
23761 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
23762 -       r->id.idiag_dst[0] = inet->inet_daddr;
23763 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23764 +               inet->inet_rcv_saddr);
23765 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23766 +               inet->inet_daddr);
23767  
23768         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23769                 goto errout;
23770 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23771         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23772         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23773  
23774 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
23775 -       r->id.idiag_dst[0]    = tw->tw_daddr;
23776 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23777 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23778  
23779         r->idiag_state        = tw->tw_substate;
23780         r->idiag_timer        = 3;
23781 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23782  
23783         err = -EINVAL;
23784         if (req->sdiag_family == AF_INET) {
23785 +               /* TODO: lback */
23786                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23787                                  req->id.idiag_dport, req->id.idiag_src[0],
23788                                  req->id.idiag_sport, req->id.idiag_if);
23789         }
23790  #if IS_ENABLED(CONFIG_IPV6)
23791         else if (req->sdiag_family == AF_INET6) {
23792 +               /* TODO: lback */
23793                 sk = inet6_lookup(net, hashinfo,
23794                                   (struct in6_addr *)req->id.idiag_dst,
23795                                   req->id.idiag_dport,
23796 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23797         } else
23798  #endif
23799         {
23800 +                       /* TODO: lback */
23801                 entry.saddr = &inet->inet_rcv_saddr;
23802                 entry.daddr = &inet->inet_daddr;
23803         }
23804 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23805                 } else
23806  #endif
23807                 {
23808 +                       /* TODO: lback */
23809                         entry.saddr = &tw->tw_rcv_saddr;
23810                         entry.daddr = &tw->tw_daddr;
23811                 }
23812 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23813         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23814         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23815  
23816 -       r->id.idiag_src[0] = ireq->ir_loc_addr;
23817 -       r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23818 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23819 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23820  
23821         r->idiag_expires = jiffies_to_msecs(tmo);
23822         r->idiag_rqueue = 0;
23823 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23824                             r->id.idiag_dport)
23825                                 continue;
23826  
23827 +                       /* TODO: lback */
23828                         if (bc) {
23829                                 inet_diag_req_addrs(sk, req, &entry);
23830                                 entry.dport = ntohs(ireq->ir_rmt_port);
23831 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23832                                 if (!net_eq(sock_net(sk), net))
23833                                         continue;
23834  
23835 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23836 +                                       continue;
23837                                 if (num < s_num) {
23838                                         num++;
23839                                         continue;
23840 @@ -934,6 +945,8 @@ skip_listen_ht:
23841  
23842                         if (!net_eq(sock_net(sk), net))
23843                                 continue;
23844 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23845 +                               continue;
23846                         if (num < s_num)
23847                                 goto next_normal;
23848                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23849 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c
23850 --- linux-3.13.10/net/ipv4/inet_hashtables.c    2014-01-22 20:39:15.000000000 +0000
23851 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23852 @@ -22,6 +22,7 @@
23853  #include <net/inet_connection_sock.h>
23854  #include <net/inet_hashtables.h>
23855  #include <net/secure_seq.h>
23856 +#include <net/route.h>
23857  #include <net/ip.h>
23858  
23859  static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23860 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23861                         if (rcv_saddr != daddr)
23862                                 return -1;
23863                         score += 4;
23864 +               } else {
23865 +                       /* block non nx_info ips */
23866 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23867 +                               daddr, NXA_MASK_BIND))
23868 +                               return -1;
23869                 }
23870                 if (sk->sk_bound_dev_if) {
23871                         if (sk->sk_bound_dev_if != dif)
23872 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23873   * wildcarded during the search since they can never be otherwise.
23874   */
23875  
23876 -
23877  struct sock *__inet_lookup_listener(struct net *net,
23878                                     struct inet_hashinfo *hashinfo,
23879                                     const __be32 saddr, __be16 sport,
23880 @@ -234,6 +239,7 @@ begin:
23881                         phash = next_pseudo_random32(phash);
23882                 }
23883         }
23884 +
23885         /*
23886          * if the nulls value we got at the end of this lookup is
23887          * not the expected one, we must restart lookup.
23888 diff -NurpP --minimal linux-3.13.10/net/ipv4/netfilter.c linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c
23889 --- linux-3.13.10/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
23890 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c       2014-01-31 20:38:04.000000000 +0000
23891 @@ -11,7 +11,7 @@
23892  #include <linux/skbuff.h>
23893  #include <linux/gfp.h>
23894  #include <linux/export.h>
23895 -#include <net/route.h>
23896 +// #include <net/route.h>
23897  #include <net/xfrm.h>
23898  #include <net/ip.h>
23899  #include <net/netfilter/nf_queue.h>
23900 diff -NurpP --minimal linux-3.13.10/net/ipv4/raw.c linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c
23901 --- linux-3.13.10/net/ipv4/raw.c        2014-01-22 20:39:15.000000000 +0000
23902 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c     2014-01-31 20:38:04.000000000 +0000
23903 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23904  
23905                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23906                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23907 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23908 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23909                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23910                         goto found; /* gotcha */
23911         }
23912 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23913                 icmp_out_count(net, ((struct icmphdr *)
23914                         skb_transport_header(skb))->type);
23915  
23916 +       err = -EPERM;
23917 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23918 +               sk->sk_nx_info &&
23919 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23920 +               goto error_free;
23921 +
23922         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23923                       rt->dst.dev, dst_output);
23924         if (err > 0)
23925 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23926                         goto done;
23927         }
23928  
23929 +       if (sk->sk_nx_info) {
23930 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23931 +               if (IS_ERR(rt)) {
23932 +                       err = PTR_ERR(rt);
23933 +                       rt = NULL;
23934 +                       goto done;
23935 +               }
23936 +               ip_rt_put(rt);
23937 +       }
23938 +
23939         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23940         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23941         if (IS_ERR(rt)) {
23942 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23943  {
23944         struct inet_sock *inet = inet_sk(sk);
23945         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23946 +       struct nx_v4_sock_addr nsa = { 0 };
23947         int ret = -EINVAL;
23948         int chk_addr_ret;
23949  
23950         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23951                 goto out;
23952 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23953 +       v4_map_sock_addr(inet, addr, &nsa);
23954 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23955         ret = -EADDRNOTAVAIL;
23956 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23957 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23958             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23959                 goto out;
23960 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23961 +       v4_set_sock_addr(inet, &nsa);
23962         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23963                 inet->inet_saddr = 0;  /* Use device */
23964         sk_dst_reset(sk);
23965 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
23966         /* Copy the address. */
23967         if (sin) {
23968                 sin->sin_family = AF_INET;
23969 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23970 +               sin->sin_addr.s_addr =
23971 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23972                 sin->sin_port = 0;
23973                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23974                 *addr_len = sizeof(*sin);
23975 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
23976         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23977                         ++state->bucket) {
23978                 sk_for_each(sk, &state->h->ht[state->bucket])
23979 -                       if (sock_net(sk) == seq_file_net(seq))
23980 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
23981 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23982                                 goto found;
23983         }
23984         sk = NULL;
23985 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
23986                 sk = sk_next(sk);
23987  try_again:
23988                 ;
23989 -       } while (sk && sock_net(sk) != seq_file_net(seq));
23990 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23991 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23992  
23993         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23994                 sk = sk_head(&state->h->ht[state->bucket]);
23995 diff -NurpP --minimal linux-3.13.10/net/ipv4/route.c linux-3.13.10-vs2.3.6.11/net/ipv4/route.c
23996 --- linux-3.13.10/net/ipv4/route.c      2014-04-17 01:12:41.000000000 +0000
23997 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/route.c   2014-03-12 15:51:08.000000000 +0000
23998 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
23999  
24000  
24001         if (fl4->flowi4_oif) {
24002 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24003 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24004                 rth = ERR_PTR(-ENODEV);
24005                 if (dev_out == NULL)
24006                         goto out;
24007 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c
24008 --- linux-3.13.10/net/ipv4/tcp.c        2014-04-17 01:12:41.000000000 +0000
24009 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c     2014-04-17 01:17:11.000000000 +0000
24010 @@ -268,6 +268,7 @@
24011  #include <linux/crypto.h>
24012  #include <linux/time.h>
24013  #include <linux/slab.h>
24014 +#include <linux/in.h>
24015  
24016  #include <net/icmp.h>
24017  #include <net/inet_common.h>
24018 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_ipv4.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c
24019 --- linux-3.13.10/net/ipv4/tcp_ipv4.c   2014-04-17 01:12:41.000000000 +0000
24020 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c        2014-04-17 01:17:11.000000000 +0000
24021 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24022                 req = req->dl_next;
24023                 while (1) {
24024                         while (req) {
24025 +                               vxdprintk(VXD_CBIT(net, 6),
24026 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24027 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24028 +                               if (req->sk &&
24029 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24030 +                                       continue;
24031                                 if (req->rsk_ops->family == st->family) {
24032                                         cur = req;
24033                                         goto out;
24034 @@ -2251,6 +2257,10 @@ get_req:
24035         }
24036  get_sk:
24037         sk_nulls_for_each_from(sk, node) {
24038 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24039 +                       sk, sk->sk_nid, nx_current_nid());
24040 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24041 +                       continue;
24042                 if (!net_eq(sock_net(sk), net))
24043                         continue;
24044                 if (sk->sk_family == st->family) {
24045 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24046  
24047                 spin_lock_bh(lock);
24048                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24049 +                       vxdprintk(VXD_CBIT(net, 6),
24050 +                               "sk,egf: %p [#%d] (from %d)",
24051 +                               sk, sk->sk_nid, nx_current_nid());
24052 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24053 +                               continue;
24054                         if (sk->sk_family != st->family ||
24055                             !net_eq(sock_net(sk), net)) {
24056                                 continue;
24057 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24058         sk = sk_nulls_next(sk);
24059  
24060         sk_nulls_for_each_from(sk, node) {
24061 +               vxdprintk(VXD_CBIT(net, 6),
24062 +                       "sk,egn: %p [#%d] (from %d)",
24063 +                       sk, sk->sk_nid, nx_current_nid());
24064 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24065 +                       continue;
24066                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24067                         return sk;
24068         }
24069 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24070         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24071                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24072                 i,
24073 -               ireq->ir_loc_addr,
24074 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24075                 ntohs(inet_sk(sk)->inet_sport),
24076 -               ireq->ir_rmt_addr,
24077 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24078                 ntohs(ireq->ir_rmt_port),
24079                 TCP_SYN_RECV,
24080                 0, 0, /* could print option size, but that is af dependent. */
24081 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24082         const struct inet_connection_sock *icsk = inet_csk(sk);
24083         const struct inet_sock *inet = inet_sk(sk);
24084         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24085 -       __be32 dest = inet->inet_daddr;
24086 -       __be32 src = inet->inet_rcv_saddr;
24087 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24088 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24089         __u16 destp = ntohs(inet->inet_dport);
24090         __u16 srcp = ntohs(inet->inet_sport);
24091         int rx_queue;
24092 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24093         __u16 destp, srcp;
24094         s32 delta = tw->tw_ttd - inet_tw_time_stamp();
24095  
24096 -       dest  = tw->tw_daddr;
24097 -       src   = tw->tw_rcv_saddr;
24098 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24099 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24100         destp = ntohs(tw->tw_dport);
24101         srcp  = ntohs(tw->tw_sport);
24102  
24103 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_minisocks.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c
24104 --- linux-3.13.10/net/ipv4/tcp_minisocks.c      2014-01-22 20:39:15.000000000 +0000
24105 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c   2014-01-31 20:38:04.000000000 +0000
24106 @@ -23,6 +23,9 @@
24107  #include <linux/slab.h>
24108  #include <linux/sysctl.h>
24109  #include <linux/workqueue.h>
24110 +#include <linux/vs_limit.h>
24111 +#include <linux/vs_socket.h>
24112 +#include <linux/vs_context.h>
24113  #include <net/tcp.h>
24114  #include <net/inet_common.h>
24115  #include <net/xfrm.h>
24116 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24117                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24118                 tcptw->tw_ts_offset     = tp->tsoffset;
24119  
24120 +               tw->tw_xid              = sk->sk_xid;
24121 +               tw->tw_vx_info          = NULL;
24122 +               tw->tw_nid              = sk->sk_nid;
24123 +               tw->tw_nx_info          = NULL;
24124 +
24125  #if IS_ENABLED(CONFIG_IPV6)
24126                 if (tw->tw_family == PF_INET6) {
24127                         struct ipv6_pinfo *np = inet6_sk(sk);
24128 diff -NurpP --minimal linux-3.13.10/net/ipv4/udp.c linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c
24129 --- linux-3.13.10/net/ipv4/udp.c        2014-01-22 20:39:15.000000000 +0000
24130 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c     2014-01-31 22:20:27.000000000 +0000
24131 @@ -308,14 +308,7 @@ fail:
24132  }
24133  EXPORT_SYMBOL(udp_lib_get_port);
24134  
24135 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24136 -{
24137 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24138 -
24139 -       return  (!ipv6_only_sock(sk2)  &&
24140 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24141 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24142 -}
24143 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24144  
24145  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24146                                        unsigned int port)
24147 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24148                         if (inet->inet_rcv_saddr != daddr)
24149                                 return -1;
24150                         score += 4;
24151 +               } else {
24152 +                       /* block non nx_info ips */
24153 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24154 +                               daddr, NXA_MASK_BIND))
24155 +                               return -1;
24156                 }
24157                 if (inet->inet_daddr) {
24158                         if (inet->inet_daddr != saddr)
24159 @@ -472,6 +470,7 @@ begin:
24160         return result;
24161  }
24162  
24163 +
24164  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24165   * harder than this. -DaveM
24166   */
24167 @@ -518,6 +517,11 @@ begin:
24168         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24169                 score = compute_score(sk, net, saddr, hnum, sport,
24170                                       daddr, dport, dif);
24171 +               /* FIXME: disabled?
24172 +               if (score == 9) {
24173 +                       result = sk;
24174 +                       break;
24175 +               } else */
24176                 if (score > badness) {
24177                         result = sk;
24178                         badness = score;
24179 @@ -542,6 +546,7 @@ begin:
24180         if (get_nulls_value(node) != slot)
24181                 goto begin;
24182  
24183 +
24184         if (result) {
24185                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24186                         result = NULL;
24187 @@ -551,6 +556,7 @@ begin:
24188                         goto begin;
24189                 }
24190         }
24191 +
24192         rcu_read_unlock();
24193         return result;
24194  }
24195 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24196             udp_sk(sk)->udp_port_hash != hnum ||
24197             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24198             (inet->inet_dport != rmt_port && inet->inet_dport) ||
24199 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24200 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24201             ipv6_only_sock(sk) ||
24202             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24203                 return false;
24204 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24205                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24206                                    faddr, saddr, dport, inet->inet_sport);
24207  
24208 +               if (sk->sk_nx_info) {
24209 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24210 +                       if (IS_ERR(rt)) {
24211 +                               err = PTR_ERR(rt);
24212 +                               rt = NULL;
24213 +                               goto out;
24214 +                       }
24215 +                       ip_rt_put(rt);
24216 +               }
24217 +
24218                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24219                 rt = ip_route_output_flow(net, fl4, sk);
24220                 if (IS_ERR(rt)) {
24221 @@ -1293,7 +1309,8 @@ try_again:
24222         if (sin) {
24223                 sin->sin_family = AF_INET;
24224                 sin->sin_port = udp_hdr(skb)->source;
24225 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24226 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24227 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24228                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24229                 *addr_len = sizeof(*sin);
24230         }
24231 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24232                 sk_nulls_for_each(sk, node, &hslot->head) {
24233                         if (!net_eq(sock_net(sk), net))
24234                                 continue;
24235 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24236 +                               continue;
24237                         if (sk->sk_family == state->family)
24238                                 goto found;
24239                 }
24240 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24241  
24242         do {
24243                 sk = sk_nulls_next(sk);
24244 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24245 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24246 +               sk->sk_family != state->family ||
24247 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24248  
24249         if (!sk) {
24250                 if (state->bucket <= state->udp_table->mask)
24251 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24252                 int bucket)
24253  {
24254         struct inet_sock *inet = inet_sk(sp);
24255 -       __be32 dest = inet->inet_daddr;
24256 -       __be32 src  = inet->inet_rcv_saddr;
24257 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24258 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24259         __u16 destp       = ntohs(inet->inet_dport);
24260         __u16 srcp        = ntohs(inet->inet_sport);
24261  
24262 diff -NurpP --minimal linux-3.13.10/net/ipv6/Kconfig linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig
24263 --- linux-3.13.10/net/ipv6/Kconfig      2014-01-22 20:39:15.000000000 +0000
24264 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig   2014-01-31 20:38:04.000000000 +0000
24265 @@ -4,8 +4,8 @@
24266  
24267  #   IPv6 as module will cause a CRASH if you try to unload it
24268  menuconfig IPV6
24269 -       tristate "The IPv6 protocol"
24270 -       default m
24271 +       bool "The IPv6 protocol"
24272 +       default n
24273         ---help---
24274           This is complemental support for the IP version 6.
24275           You will still be able to do traditional IPv4 networking as well.
24276 diff -NurpP --minimal linux-3.13.10/net/ipv6/addrconf.c linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c
24277 --- linux-3.13.10/net/ipv6/addrconf.c   2014-04-17 01:12:41.000000000 +0000
24278 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c        2014-04-17 01:17:11.000000000 +0000
24279 @@ -90,6 +90,8 @@
24280  #include <linux/proc_fs.h>
24281  #include <linux/seq_file.h>
24282  #include <linux/export.h>
24283 +#include <linux/vs_network.h>
24284 +#include <linux/vs_inet6.h>
24285  
24286  /* Set to 3 to get tracing... */
24287  #define ACONF_DEBUG 2
24288 @@ -1284,7 +1286,7 @@ out:
24289  
24290  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24291                        const struct in6_addr *daddr, unsigned int prefs,
24292 -                      struct in6_addr *saddr)
24293 +                      struct in6_addr *saddr, struct nx_info *nxi)
24294  {
24295         struct ipv6_saddr_score scores[2],
24296                                 *score = &scores[0], *hiscore = &scores[1];
24297 @@ -1356,6 +1358,8 @@ int ipv6_dev_get_saddr(struct net *net,
24298                                                dev->name);
24299                                 continue;
24300                         }
24301 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24302 +                               continue;
24303  
24304                         score->rule = -1;
24305                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24306 @@ -3371,7 +3375,10 @@ static void if6_seq_stop(struct seq_file
24307  static int if6_seq_show(struct seq_file *seq, void *v)
24308  {
24309         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24310 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24311 +
24312 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24313 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24314 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24315                    &ifp->addr,
24316                    ifp->idev->dev->ifindex,
24317                    ifp->prefix_len,
24318 @@ -3892,6 +3899,11 @@ static int in6_dump_addrs(struct inet6_d
24319         struct ifacaddr6 *ifaca;
24320         int err = 1;
24321         int ip_idx = *p_ip_idx;
24322 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24323 +
24324 +       /* disable ipv6 on non v6 guests */
24325 +       if (nxi && !nx_info_has_v6(nxi))
24326 +               return skb->len;
24327  
24328         read_lock_bh(&idev->lock);
24329         switch (type) {
24330 @@ -3902,6 +3914,8 @@ static int in6_dump_addrs(struct inet6_d
24331                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24332                         if (++ip_idx < s_ip_idx)
24333                                 continue;
24334 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24335 +                                       continue;
24336                         err = inet6_fill_ifaddr(skb, ifa,
24337                                                 NETLINK_CB(cb->skb).portid,
24338                                                 cb->nlh->nlmsg_seq,
24339 @@ -3919,6 +3933,8 @@ static int in6_dump_addrs(struct inet6_d
24340                      ifmca = ifmca->next, ip_idx++) {
24341                         if (ip_idx < s_ip_idx)
24342                                 continue;
24343 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24344 +                                       continue;
24345                         err = inet6_fill_ifmcaddr(skb, ifmca,
24346                                                   NETLINK_CB(cb->skb).portid,
24347                                                   cb->nlh->nlmsg_seq,
24348 @@ -3934,6 +3950,8 @@ static int in6_dump_addrs(struct inet6_d
24349                      ifaca = ifaca->aca_next, ip_idx++) {
24350                         if (ip_idx < s_ip_idx)
24351                                 continue;
24352 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24353 +                                       continue;
24354                         err = inet6_fill_ifacaddr(skb, ifaca,
24355                                                   NETLINK_CB(cb->skb).portid,
24356                                                   cb->nlh->nlmsg_seq,
24357 @@ -3962,6 +3980,10 @@ static int inet6_dump_addr(struct sk_buf
24358         struct inet6_dev *idev;
24359         struct hlist_head *head;
24360  
24361 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24362 +       if (skb->sk && skb->sk->sk_vx_info)
24363 +               return skb->len; */
24364 +
24365         s_h = cb->args[0];
24366         s_idx = idx = cb->args[1];
24367         s_ip_idx = ip_idx = cb->args[2];
24368 @@ -4404,6 +4426,7 @@ static int inet6_dump_ifinfo(struct sk_b
24369         struct net_device *dev;
24370         struct inet6_dev *idev;
24371         struct hlist_head *head;
24372 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24373  
24374         s_h = cb->args[0];
24375         s_idx = cb->args[1];
24376 @@ -4415,6 +4438,8 @@ static int inet6_dump_ifinfo(struct sk_b
24377                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24378                         if (idx < s_idx)
24379                                 goto cont;
24380 +                       if (!v6_dev_in_nx_info(dev, nxi))
24381 +                               goto cont;
24382                         idev = __in6_dev_get(dev);
24383                         if (!idev)
24384                                 goto cont;
24385 diff -NurpP --minimal linux-3.13.10/net/ipv6/af_inet6.c linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c
24386 --- linux-3.13.10/net/ipv6/af_inet6.c   2014-01-22 20:39:15.000000000 +0000
24387 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c        2014-01-31 21:39:03.000000000 +0000
24388 @@ -43,6 +43,8 @@
24389  #include <linux/netdevice.h>
24390  #include <linux/icmpv6.h>
24391  #include <linux/netfilter_ipv6.h>
24392 +#include <linux/vs_inet.h>
24393 +#include <linux/vs_inet6.h>
24394  
24395  #include <net/ip.h>
24396  #include <net/ipv6.h>
24397 @@ -156,10 +158,13 @@ lookup_protocol:
24398         }
24399  
24400         err = -EPERM;
24401 +       if ((protocol == IPPROTO_ICMPV6) &&
24402 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24403 +               goto override;
24404         if (sock->type == SOCK_RAW && !kern &&
24405             !ns_capable(net->user_ns, CAP_NET_RAW))
24406                 goto out_rcu_unlock;
24407 -
24408 +override:
24409         sock->ops = answer->ops;
24410         answer_prot = answer->prot;
24411         answer_no_check = answer->no_check;
24412 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24413         struct inet_sock *inet = inet_sk(sk);
24414         struct ipv6_pinfo *np = inet6_sk(sk);
24415         struct net *net = sock_net(sk);
24416 +       struct nx_v6_sock_addr nsa;
24417         __be32 v4addr = 0;
24418         unsigned short snum;
24419         int addr_type = 0;
24420 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24421         if (addr->sin6_family != AF_INET6)
24422                 return -EAFNOSUPPORT;
24423  
24424 +       err = v6_map_sock_addr(inet, addr, &nsa);
24425 +       if (err)
24426 +               return err;
24427 +
24428         addr_type = ipv6_addr_type(&addr->sin6_addr);
24429         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24430                 return -EINVAL;
24431 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24432                 /* Reproduce AF_INET checks to make the bindings consistent */
24433                 v4addr = addr->sin6_addr.s6_addr32[3];
24434                 chk_addr_ret = inet_addr_type(net, v4addr);
24435 +
24436                 if (!sysctl_ip_nonlocal_bind &&
24437                     !(inet->freebind || inet->transparent) &&
24438                     v4addr != htonl(INADDR_ANY) &&
24439 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24440                         err = -EADDRNOTAVAIL;
24441                         goto out;
24442                 }
24443 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24444 +                       err = -EADDRNOTAVAIL;
24445 +                       goto out;
24446 +               }
24447         } else {
24448                 if (addr_type != IPV6_ADDR_ANY) {
24449                         struct net_device *dev = NULL;
24450 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24451                                 }
24452                         }
24453  
24454 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24455 +                               err = -EADDRNOTAVAIL;
24456 +                               goto out_unlock;
24457 +                       }
24458 +
24459                         /* ipv4 addr of the socket is invalid.  Only the
24460                          * unspecified and mapped address have a v4 equivalent.
24461                          */
24462 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24463                 }
24464         }
24465  
24466 +       /* what's that for? */
24467 +       v6_set_sock_addr(inet, &nsa);
24468 +
24469         inet->inet_rcv_saddr = v4addr;
24470         inet->inet_saddr = v4addr;
24471  
24472 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24473                         return -ENOTCONN;
24474                 sin->sin6_port = inet->inet_dport;
24475                 sin->sin6_addr = sk->sk_v6_daddr;
24476 +               /* FIXME: remap lback? */
24477                 if (np->sndflow)
24478                         sin->sin6_flowinfo = np->flow_label;
24479         } else {
24480 +               /* FIXME: remap lback? */
24481                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24482                         sin->sin6_addr = np->saddr;
24483                 else
24484 diff -NurpP --minimal linux-3.13.10/net/ipv6/datagram.c linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c
24485 --- linux-3.13.10/net/ipv6/datagram.c   2014-01-22 20:39:15.000000000 +0000
24486 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c        2014-01-31 20:38:04.000000000 +0000
24487 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24488  
24489                         rcu_read_lock();
24490                         if (fl6->flowi6_oif) {
24491 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24492 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24493                                 if (!dev) {
24494                                         rcu_read_unlock();
24495                                         return -ENODEV;
24496 diff -NurpP --minimal linux-3.13.10/net/ipv6/fib6_rules.c linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c
24497 --- linux-3.13.10/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24498 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c      2014-01-31 20:38:04.000000000 +0000
24499 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24500                                                ip6_dst_idev(&rt->dst)->dev,
24501                                                &flp6->daddr,
24502                                                rt6_flags2srcprefs(flags),
24503 -                                              &saddr))
24504 +                                              &saddr, NULL))
24505                                 goto again;
24506                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24507                                                r->src.plen))
24508 diff -NurpP --minimal linux-3.13.10/net/ipv6/inet6_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c
24509 --- linux-3.13.10/net/ipv6/inet6_hashtables.c   2014-01-22 20:39:15.000000000 +0000
24510 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c        2014-01-31 20:38:04.000000000 +0000
24511 @@ -16,6 +16,7 @@
24512  
24513  #include <linux/module.h>
24514  #include <linux/random.h>
24515 +#include <linux/vs_inet6.h>
24516  
24517  #include <net/inet_connection_sock.h>
24518  #include <net/inet_hashtables.h>
24519 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24520         unsigned int slot = hash & hashinfo->ehash_mask;
24521         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24522  
24523 -
24524         rcu_read_lock();
24525  begin:
24526         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24527 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24528                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24529                                 return -1;
24530                         score++;
24531 +               } else {
24532 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24533 +                               return -1;
24534                 }
24535                 if (sk->sk_bound_dev_if) {
24536                         if (sk->sk_bound_dev_if != dif)
24537 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_fib.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c
24538 --- linux-3.13.10/net/ipv6/ip6_fib.c    2014-01-22 20:39:15.000000000 +0000
24539 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24540 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24541         struct rt6_info *rt = v;
24542         struct ipv6_route_iter *iter = seq->private;
24543  
24544 +       /* FIXME: check for network context? */
24545         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24546  
24547  #ifdef CONFIG_IPV6_SUBTREES
24548 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_output.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c
24549 --- linux-3.13.10/net/ipv6/ip6_output.c 2014-04-17 01:12:41.000000000 +0000
24550 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c      2014-04-17 01:17:11.000000000 +0000
24551 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24552                 struct rt6_info *rt = (struct rt6_info *) *dst;
24553                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24554                                           sk ? inet6_sk(sk)->srcprefs : 0,
24555 -                                         &fl6->saddr);
24556 +                                         &fl6->saddr,
24557 +                                         sk ? sk->sk_nx_info : NULL);
24558                 if (err)
24559                         goto out_err_release;
24560         }
24561 diff -NurpP --minimal linux-3.13.10/net/ipv6/ndisc.c linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c
24562 --- linux-3.13.10/net/ipv6/ndisc.c      2014-01-22 20:39:15.000000000 +0000
24563 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c   2014-01-31 20:38:04.000000000 +0000
24564 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24565         } else {
24566                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24567                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24568 -                                      &tmpaddr))
24569 +                                      &tmpaddr, NULL))
24570                         return;
24571                 src_addr = &tmpaddr;
24572         }
24573 diff -NurpP --minimal linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c
24574 --- linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-11-25 15:47:07.000000000 +0000
24575 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c       2014-01-31 20:38:04.000000000 +0000
24576 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24577                             ctinfo == IP_CT_RELATED_REPLY));
24578  
24579         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24580 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24581 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24582                 return NF_DROP;
24583  
24584         nfct_nat(ct)->masq_index = par->out->ifindex;
24585 diff -NurpP --minimal linux-3.13.10/net/ipv6/raw.c linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c
24586 --- linux-3.13.10/net/ipv6/raw.c        2014-01-22 20:39:15.000000000 +0000
24587 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c     2014-01-31 20:38:04.000000000 +0000
24588 @@ -30,6 +30,7 @@
24589  #include <linux/icmpv6.h>
24590  #include <linux/netfilter.h>
24591  #include <linux/netfilter_ipv6.h>
24592 +#include <linux/vs_inet6.h>
24593  #include <linux/skbuff.h>
24594  #include <linux/compat.h>
24595  #include <asm/uaccess.h>
24596 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24597                                 goto out_unlock;
24598                 }
24599  
24600 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24601 +                       err = -EADDRNOTAVAIL;
24602 +                       if (dev)
24603 +                               dev_put(dev);
24604 +                       goto out;
24605 +               }
24606 +
24607                 /* ipv4 addr of the socket is invalid.  Only the
24608                  * unspecified and mapped address have a v4 equivalent.
24609                  */
24610 diff -NurpP --minimal linux-3.13.10/net/ipv6/route.c linux-3.13.10-vs2.3.6.11/net/ipv6/route.c
24611 --- linux-3.13.10/net/ipv6/route.c      2014-04-17 01:12:41.000000000 +0000
24612 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/route.c   2014-04-17 01:17:11.000000000 +0000
24613 @@ -58,6 +58,7 @@
24614  #include <net/netevent.h>
24615  #include <net/netlink.h>
24616  #include <net/nexthop.h>
24617 +#include <linux/vs_inet6.h>
24618  
24619  #include <asm/uaccess.h>
24620  
24621 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24622                         struct rt6_info *rt,
24623                         const struct in6_addr *daddr,
24624                         unsigned int prefs,
24625 -                       struct in6_addr *saddr)
24626 +                       struct in6_addr *saddr,
24627 +                       struct nx_info *nxi)
24628  {
24629         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24630         int err = 0;
24631 -       if (rt->rt6i_prefsrc.plen)
24632 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
24633 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24634                 *saddr = rt->rt6i_prefsrc.addr;
24635         else
24636                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24637 -                                        daddr, prefs, saddr);
24638 +                                        daddr, prefs, saddr, nxi);
24639         return err;
24640  }
24641  
24642 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24643                                 goto nla_put_failure;
24644         } else if (dst) {
24645                 struct in6_addr saddr_buf;
24646 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24647 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24648 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24649                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24650                         goto nla_put_failure;
24651         }
24652 diff -NurpP --minimal linux-3.13.10/net/ipv6/tcp_ipv6.c linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c
24653 --- linux-3.13.10/net/ipv6/tcp_ipv6.c   2014-01-22 20:39:15.000000000 +0000
24654 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c        2014-01-31 20:38:04.000000000 +0000
24655 @@ -72,6 +72,7 @@
24656  
24657  #include <linux/crypto.h>
24658  #include <linux/scatterlist.h>
24659 +#include <linux/vs_inet6.h>
24660  
24661  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24662  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24663 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24664          *      connect() to INADDR_ANY means loopback (BSD'ism).
24665          */
24666  
24667 -       if (ipv6_addr_any(&usin->sin6_addr))
24668 -               usin->sin6_addr.s6_addr[15] = 0x1;
24669 +       if (ipv6_addr_any(&usin->sin6_addr)) {
24670 +               struct nx_info *nxi =  sk->sk_nx_info;
24671 +
24672 +               if (nxi && nx_info_has_v6(nxi))
24673 +                       /* FIXME: remap lback? */
24674 +                       usin->sin6_addr = nxi->v6.ip;
24675 +               else
24676 +                       usin->sin6_addr.s6_addr[15] = 0x1;
24677 +       }
24678  
24679         addr_type = ipv6_addr_type(&usin->sin6_addr);
24680  
24681 diff -NurpP --minimal linux-3.13.10/net/ipv6/udp.c linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c
24682 --- linux-3.13.10/net/ipv6/udp.c        2014-01-22 20:39:15.000000000 +0000
24683 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c     2014-02-01 02:33:38.000000000 +0000
24684 @@ -47,6 +47,7 @@
24685  #include <net/xfrm.h>
24686  #include <net/inet6_hashtables.h>
24687  #include <net/busy_poll.h>
24688 +#include <linux/vs_inet6.h>
24689  
24690  #include <linux/proc_fs.h>
24691  #include <linux/seq_file.h>
24692 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24693                                udp_ipv6_hash_secret + net_hash_mix(net));
24694  }
24695  
24696 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24697 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24698  {
24699 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24700         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24701 -       int sk_ipv6only = ipv6_only_sock(sk);
24702 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24703 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24704 +       int sk1_ipv6only = ipv6_only_sock(sk1);
24705         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24706 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24707 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24708         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24709  
24710         /* if both are mapped, treat as IPv4 */
24711 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24712 -               return (!sk2_ipv6only &&
24713 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24714 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24715 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24716 +               if (!sk2_ipv6only &&
24717 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24718 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24719 +                       goto vs_v4;
24720 +               else
24721 +                       return 0;
24722 +       }
24723  
24724         if (addr_type2 == IPV6_ADDR_ANY &&
24725 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24726 -               return 1;
24727 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24728 +               goto vs;
24729  
24730 -       if (addr_type == IPV6_ADDR_ANY &&
24731 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24732 -               return 1;
24733 +       if (addr_type1 == IPV6_ADDR_ANY &&
24734 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24735 +               goto vs;
24736  
24737         if (sk2_rcv_saddr6 &&
24738 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24739 -               return 1;
24740 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24741 +               goto vs;
24742  
24743         return 0;
24744 +
24745 +vs_v4:
24746 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24747 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24748 +       if (!sk2_rcv_saddr)
24749 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24750 +       if (!sk1_rcv_saddr)
24751 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24752 +       return 1;
24753 +vs:
24754 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24755 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24756 +       else if (addr_type2 == IPV6_ADDR_ANY)
24757 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24758 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24759 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24760 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24761 +               else
24762 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24763 +       }
24764 +       return 1;
24765  }
24766  
24767  static unsigned int udp6_portaddr_hash(struct net *net,
24768 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24769                         if (inet->inet_dport != sport)
24770                                 return -1;
24771                         score++;
24772 +               } else {
24773 +                       /* block non nx_info ips */
24774 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24775 +                               return -1;
24776                 }
24777                 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24778                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24779 diff -NurpP --minimal linux-3.13.10/net/ipv6/xfrm6_policy.c linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c
24780 --- linux-3.13.10/net/ipv6/xfrm6_policy.c       2014-01-22 20:39:15.000000000 +0000
24781 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c    2014-01-31 20:38:04.000000000 +0000
24782 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24783         dev = ip6_dst_idev(dst)->dev;
24784         ipv6_dev_get_saddr(dev_net(dev), dev,
24785                            (struct in6_addr *)&daddr->a6, 0,
24786 -                          (struct in6_addr *)&saddr->a6);
24787 +                          (struct in6_addr *)&saddr->a6, NULL);
24788         dst_release(dst);
24789         return 0;
24790  }
24791 diff -NurpP --minimal linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c
24792 --- linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c       2013-11-25 15:47:07.000000000 +0000
24793 +++ linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c    2014-01-31 20:38:04.000000000 +0000
24794 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24795                 return dst;
24796         if (ipv6_addr_any(&fl6.saddr) &&
24797             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24798 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24799 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24800                 goto out_err;
24801         if (do_xfrm) {
24802                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24803 diff -NurpP --minimal linux-3.13.10/net/netlink/af_netlink.c linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c
24804 --- linux-3.13.10/net/netlink/af_netlink.c      2014-01-22 20:39:16.000000000 +0000
24805 +++ linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c   2014-02-25 11:47:07.000000000 +0000
24806 @@ -58,6 +58,9 @@
24807  #include <linux/mutex.h>
24808  #include <linux/vmalloc.h>
24809  #include <linux/if_arp.h>
24810 +#include <linux/vs_context.h>
24811 +#include <linux/vs_network.h>
24812 +#include <linux/vs_limit.h>
24813  #include <asm/cacheflush.h>
24814  
24815  #include <net/net_namespace.h>
24816 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24817                         sk_for_each(s, &hash->table[j]) {
24818                                 if (sock_net(s) != seq_file_net(seq))
24819                                         continue;
24820 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24821 +                                       continue;
24822                                 if (off == pos) {
24823                                         iter->link = i;
24824                                         iter->hash_idx = j;
24825 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24826         s = v;
24827         do {
24828                 s = sk_next(s);
24829 -       } while (s && !nl_table[s->sk_protocol].compare(net, s));
24830 +       } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24831 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24832         if (s)
24833                 return s;
24834  
24835 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24836                 for (; j <= hash->mask; j++) {
24837                         s = sk_head(&hash->table[j]);
24838  
24839 -                       while (s && !nl_table[s->sk_protocol].compare(net, s))
24840 +                       while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24841 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24842                                 s = sk_next(s);
24843                         if (s) {
24844                                 iter->link = i;
24845 diff -NurpP --minimal linux-3.13.10/net/socket.c linux-3.13.10-vs2.3.6.11/net/socket.c
24846 --- linux-3.13.10/net/socket.c  2014-04-17 01:12:42.000000000 +0000
24847 +++ linux-3.13.10-vs2.3.6.11/net/socket.c       2014-04-17 01:17:11.000000000 +0000
24848 @@ -98,6 +98,9 @@
24849  
24850  #include <net/sock.h>
24851  #include <linux/netfilter.h>
24852 +#include <linux/vs_socket.h>
24853 +#include <linux/vs_inet.h>
24854 +#include <linux/vs_inet6.h>
24855  
24856  #include <linux/if_tun.h>
24857  #include <linux/ipv6_route.h>
24858 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24859                                        struct msghdr *msg, size_t size)
24860  {
24861         struct sock_iocb *si = kiocb_to_siocb(iocb);
24862 +       size_t len;
24863  
24864         si->sock = sock;
24865         si->scm = NULL;
24866         si->msg = msg;
24867         si->size = size;
24868  
24869 -       return sock->ops->sendmsg(iocb, sock, msg, size);
24870 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
24871 +       if (sock->sk) {
24872 +               if (len == size)
24873 +                       vx_sock_send(sock->sk, size);
24874 +               else
24875 +                       vx_sock_fail(sock->sk, size);
24876 +       }
24877 +       vxdprintk(VXD_CBIT(net, 7),
24878 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24879 +               sock, sock->sk,
24880 +               (sock->sk)?sock->sk->sk_nx_info:0,
24881 +               (sock->sk)?sock->sk->sk_vx_info:0,
24882 +               (sock->sk)?sock->sk->sk_xid:0,
24883 +               (sock->sk)?sock->sk->sk_nid:0,
24884 +               (unsigned int)size, len);
24885 +       return len;
24886  }
24887  
24888  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24889 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24890                                        struct msghdr *msg, size_t size, int flags)
24891  {
24892         struct sock_iocb *si = kiocb_to_siocb(iocb);
24893 +       int len;
24894  
24895         si->sock = sock;
24896         si->scm = NULL;
24897 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24898         si->size = size;
24899         si->flags = flags;
24900  
24901 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24902 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24903 +       if ((len >= 0) && sock->sk)
24904 +               vx_sock_recv(sock->sk, len);
24905 +       vxdprintk(VXD_CBIT(net, 7),
24906 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24907 +               sock, sock->sk,
24908 +               (sock->sk)?sock->sk->sk_nx_info:0,
24909 +               (sock->sk)?sock->sk->sk_vx_info:0,
24910 +               (sock->sk)?sock->sk->sk_xid:0,
24911 +               (sock->sk)?sock->sk->sk_nid:0,
24912 +               (unsigned int)size, len);
24913 +       return len;
24914  }
24915  
24916  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24917 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24918         if (type < 0 || type >= SOCK_MAX)
24919                 return -EINVAL;
24920  
24921 +       if (!nx_check(0, VS_ADMIN)) {
24922 +               if (family == PF_INET && !current_nx_info_has_v4())
24923 +                       return -EAFNOSUPPORT;
24924 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24925 +                       return -EAFNOSUPPORT;
24926 +       }
24927 +
24928         /* Compatibility.
24929  
24930            This uglymoron is moved from INET layer to here to avoid
24931 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24932         if (retval < 0)
24933                 goto out;
24934  
24935 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24936         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24937         if (retval < 0)
24938                 goto out_release;
24939 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24940         err = sock_create(family, type, protocol, &sock1);
24941         if (err < 0)
24942                 goto out;
24943 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24944  
24945         err = sock_create(family, type, protocol, &sock2);
24946         if (err < 0)
24947                 goto out_release_1;
24948 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
24949  
24950         err = sock1->ops->socketpair(sock1, sock2);
24951         if (err < 0)
24952 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c
24953 --- linux-3.13.10/net/sunrpc/auth.c     2013-11-25 15:47:08.000000000 +0000
24954 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c  2014-01-31 20:38:04.000000000 +0000
24955 @@ -15,6 +15,7 @@
24956  #include <linux/sunrpc/clnt.h>
24957  #include <linux/sunrpc/gss_api.h>
24958  #include <linux/spinlock.h>
24959 +#include <linux/vs_tag.h>
24960  
24961  #ifdef RPC_DEBUG
24962  # define RPCDBG_FACILITY       RPCDBG_AUTH
24963 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24964         memset(&acred, 0, sizeof(acred));
24965         acred.uid = cred->fsuid;
24966         acred.gid = cred->fsgid;
24967 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24968         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
24969  
24970         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24971 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24972         struct auth_cred acred = {
24973                 .uid = GLOBAL_ROOT_UID,
24974                 .gid = GLOBAL_ROOT_GID,
24975 +               .tag = KTAGT_INIT(dx_current_tag()),
24976         };
24977  
24978         dprintk("RPC: %5u looking up %s cred\n",
24979 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth_unix.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c
24980 --- linux-3.13.10/net/sunrpc/auth_unix.c        2013-11-25 15:47:08.000000000 +0000
24981 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c     2014-01-31 20:38:04.000000000 +0000
24982 @@ -13,11 +13,13 @@
24983  #include <linux/sunrpc/clnt.h>
24984  #include <linux/sunrpc/auth.h>
24985  #include <linux/user_namespace.h>
24986 +#include <linux/vs_tag.h>
24987  
24988  #define NFS_NGROUPS    16
24989  
24990  struct unx_cred {
24991         struct rpc_cred         uc_base;
24992 +       ktag_t                  uc_tag;
24993         kgid_t                  uc_gid;
24994         kgid_t                  uc_gids[NFS_NGROUPS];
24995  };
24996 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
24997                 groups = NFS_NGROUPS;
24998  
24999         cred->uc_gid = acred->gid;
25000 +       cred->uc_tag = acred->tag;
25001         for (i = 0; i < groups; i++)
25002                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25003         if (i < NFS_NGROUPS)
25004 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25005         unsigned int i;
25006  
25007  
25008 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25009 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25010 +           !gid_eq(cred->uc_gid, acred->gid) ||
25011 +           !tag_eq(cred->uc_tag, acred->tag))
25012                 return 0;
25013  
25014         if (acred->group_info != NULL)
25015 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25016         struct rpc_clnt *clnt = task->tk_client;
25017         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25018         __be32          *base, *hold;
25019 -       int             i;
25020 +       int             i, tag;
25021  
25022         *p++ = htonl(RPC_AUTH_UNIX);
25023         base = p++;
25024 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25025          */
25026         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25027  
25028 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25029 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25030 +       tag = task->tk_client->cl_tag;
25031 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25032 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25033 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25034 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25035         hold = p++;
25036         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25037                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25038 diff -NurpP --minimal linux-3.13.10/net/sunrpc/clnt.c linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c
25039 --- linux-3.13.10/net/sunrpc/clnt.c     2014-04-17 01:12:42.000000000 +0000
25040 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c  2014-02-25 11:26:10.000000000 +0000
25041 @@ -31,6 +31,7 @@
25042  #include <linux/in.h>
25043  #include <linux/in6.h>
25044  #include <linux/un.h>
25045 +#include <linux/vs_cvirt.h>
25046  
25047  #include <linux/sunrpc/clnt.h>
25048  #include <linux/sunrpc/addr.h>
25049 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25050         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25051                 clnt->cl_chatty = 1;
25052  
25053 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25054 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25055 +               clnt->cl_tag = 1; */
25056         return clnt;
25057  }
25058  EXPORT_SYMBOL_GPL(rpc_create);
25059 diff -NurpP --minimal linux-3.13.10/net/unix/af_unix.c linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c
25060 --- linux-3.13.10/net/unix/af_unix.c    2014-04-17 01:12:42.000000000 +0000
25061 +++ linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c 2014-04-17 01:17:11.000000000 +0000
25062 @@ -115,6 +115,8 @@
25063  #include <net/checksum.h>
25064  #include <linux/security.h>
25065  #include <linux/freezer.h>
25066 +#include <linux/vs_context.h>
25067 +#include <linux/vs_limit.h>
25068  
25069  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25070  EXPORT_SYMBOL_GPL(unix_socket_table);
25071 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25072                 if (!net_eq(sock_net(s), net))
25073                         continue;
25074  
25075 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25076 +                       continue;
25077                 if (u->addr->len == len &&
25078                     !memcmp(u->addr->name, sunname, len))
25079                         goto found;
25080 @@ -2275,6 +2279,8 @@ static struct sock *unix_from_bucket(str
25081         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25082                 if (sock_net(sk) != seq_file_net(seq))
25083                         continue;
25084 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25085 +                       continue;
25086                 if (++count == offset)
25087                         break;
25088         }
25089 @@ -2292,6 +2298,8 @@ static struct sock *unix_next_socket(str
25090                 sk = sk_next(sk);
25091                 if (!sk)
25092                         goto next_bucket;
25093 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25094 +                       continue;
25095                 if (sock_net(sk) == seq_file_net(seq))
25096                         return sk;
25097         }
25098 diff -NurpP --minimal linux-3.13.10/scripts/checksyscalls.sh linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh
25099 --- linux-3.13.10/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25100 +++ linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh   2014-01-31 20:38:04.000000000 +0000
25101 @@ -193,7 +193,6 @@ cat << EOF
25102  #define __IGNORE_afs_syscall
25103  #define __IGNORE_getpmsg
25104  #define __IGNORE_putpmsg
25105 -#define __IGNORE_vserver
25106  EOF
25107  }
25108  
25109 diff -NurpP --minimal linux-3.13.10/security/commoncap.c linux-3.13.10-vs2.3.6.11/security/commoncap.c
25110 --- linux-3.13.10/security/commoncap.c  2013-11-25 15:47:08.000000000 +0000
25111 +++ linux-3.13.10-vs2.3.6.11/security/commoncap.c       2014-01-31 20:38:04.000000000 +0000
25112 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25113  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25114                 int cap, int audit)
25115  {
25116 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25117         struct user_namespace *ns = targ_ns;
25118  
25119         /* See if cred has the capability in the target user namespace
25120 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25121          */
25122         for (;;) {
25123                 /* Do we have the necessary capabilities? */
25124 -               if (ns == cred->user_ns)
25125 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25126 +               if (ns == cred->user_ns) {
25127 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25128 +                           cap_raised(cred->cap_effective, cap))
25129 +                               return 0;
25130 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25131 +               }
25132  
25133                 /* Have we tried all of the parent namespaces? */
25134                 if (ns == &init_user_ns)
25135 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25136  
25137         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25138                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25139 -           !capable(CAP_SYS_ADMIN))
25140 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25141                 return -EPERM;
25142         return 0;
25143  }
25144 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25145  
25146         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25147                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25148 -           !capable(CAP_SYS_ADMIN))
25149 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25150                 return -EPERM;
25151         return 0;
25152  }
25153 diff -NurpP --minimal linux-3.13.10/security/selinux/hooks.c linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c
25154 --- linux-3.13.10/security/selinux/hooks.c      2014-04-17 01:12:42.000000000 +0000
25155 +++ linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c   2014-04-17 01:17:11.000000000 +0000
25156 @@ -68,7 +68,6 @@
25157  #include <linux/dccp.h>
25158  #include <linux/quota.h>
25159  #include <linux/un.h>          /* for Unix socket types */
25160 -#include <net/af_unix.h>       /* for Unix socket types */
25161  #include <linux/parser.h>
25162  #include <linux/nfs_mount.h>
25163  #include <net/ipv6.h>
This page took 1.946543 seconds and 3 git commands to generate.