]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
7942b7dd572cafd772a592f97c57e7562b40f68d
[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         inode_set_flags(inode, new_fl,
2941 -                       S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2942 +               S_IXUNLINK | S_IMMUTABLE |
2943 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
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 @@ -1168,6 +1170,7 @@ int locks_mandatory_area(int read_write,
4171         struct file_lock fl;
4172         int error;
4173         bool sleep = false;
4174 +       vxid_t xid;
4175  
4176         locks_init_lock(&fl);
4177         fl.fl_pid = current->tgid;
4178 @@ -1208,20 +1240,24 @@ int locks_mandatory_area(int read_write,
4179         fl.fl_type = (read_write == FLOCK_VERIFY_WRITE) ? F_WRLCK : F_RDLCK;
4180         fl.fl_start = offset;
4181         fl.fl_end = offset + count - 1;
4182 +       if (filp)
4183 +               xid = filp->f_xid;
4184 +       else
4185 +               xid = vx_current_xid();
4186  
4187         for (;;) {
4188                 if (filp) {
4189                         fl.fl_owner = (fl_owner_t)filp;
4190                         fl.fl_flags &= ~FL_SLEEP;
4191 -                       error = __posix_lock_file(inode, &fl, NULL);
4192 +                       error = __posix_lock_file(inode, &fl, NULL, xid);
4193                         if (!error)
4194                                 break;
4195                 }
4196  
4197                 if (sleep)
4198                         fl.fl_flags |= FL_SLEEP;
4199                 fl.fl_owner = current->files;
4200 -               error = __posix_lock_file(inode, &fl, NULL);
4201 +               error = __posix_lock_file(inode, &fl, NULL, xid);
4202                 if (error != FILE_LOCK_DEFERRED)
4203                         break;
4204                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4205 @@ -1549,6 +1581,8 @@ static int generic_add_lease(struct file
4206         error = check_conflicting_open(dentry, arg);
4207         if (error)
4208                 locks_unlink_lock(flp);
4209 +       else
4210 +               vx_locks_inc(lease);
4211  out:
4212         if (is_deleg)
4213                 mutex_unlock(&inode->i_mutex);
4214 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4215         if (file_lock == NULL)
4216                 return -ENOLCK;
4217  
4218 +       vxd_assert(filp->f_xid == vx_current_xid(),
4219 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4220 +       file_lock->fl_xid = filp->f_xid;
4221 +       vx_locks_inc(file_lock);
4222 +
4223         /*
4224          * This might block, so we do it before checking the inode.
4225          */
4226 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4227         if (file_lock == NULL)
4228                 return -ENOLCK;
4229  
4230 +       vxd_assert(filp->f_xid == vx_current_xid(),
4231 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4232 +       file_lock->fl_xid = filp->f_xid;
4233 +       vx_locks_inc(file_lock);
4234 +
4235         /*
4236          * This might block, so we do it before checking the inode.
4237          */
4238 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4239  
4240         lock_get_status(f, fl, iter->li_pos, "");
4241  
4242 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4243 -               lock_get_status(f, bfl, iter->li_pos, " ->");
4244 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4245 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4246 +                       continue;
4247 +               lock_get_status(f, bfl, iter->li_pos, " ->");
4248 +       }
4249  
4250         return 0;
4251  }
4252 diff -NurpP --minimal linux-3.13.10/fs/mount.h linux-3.13.10-vs2.3.6.11/fs/mount.h
4253 --- linux-3.13.10/fs/mount.h    2014-04-17 01:12:32.000000000 +0000
4254 +++ linux-3.13.10-vs2.3.6.11/fs/mount.h 2014-04-17 01:17:10.000000000 +0000
4255 @@ -57,6 +57,7 @@ struct mount {
4256         int mnt_expiry_mark;            /* true if marked for expiry */
4257         int mnt_pinned;
4258         struct path mnt_ex_mountpoint;
4259 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4260  };
4261  
4262  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4263 diff -NurpP --minimal linux-3.13.10/fs/namei.c linux-3.13.10-vs2.3.6.11/fs/namei.c
4264 --- linux-3.13.10/fs/namei.c    2014-04-17 01:12:32.000000000 +0000
4265 +++ linux-3.13.10-vs2.3.6.11/fs/namei.c 2014-04-17 01:17:10.000000000 +0000
4266 @@ -34,9 +34,19 @@
4267  #include <linux/device_cgroup.h>
4268  #include <linux/fs_struct.h>
4269  #include <linux/posix_acl.h>
4270 +#include <linux/proc_fs.h>
4271 +#include <linux/magic.h>
4272 +#include <linux/vserver/inode.h>
4273 +#include <linux/vs_base.h>
4274 +#include <linux/vs_tag.h>
4275 +#include <linux/vs_cowbl.h>
4276 +#include <linux/vs_device.h>
4277 +#include <linux/vs_context.h>
4278 +#include <linux/pid_namespace.h>
4279  #include <asm/uaccess.h>
4280  
4281  #include "internal.h"
4282 +#include "proc/internal.h"
4283  #include "mount.h"
4284  
4285  /* [Feb-1997 T. Schoebel-Theuer]
4286 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4287         return -EAGAIN;
4288  }
4289  
4290 +static inline int dx_barrier(const struct inode *inode)
4291 +{
4292 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4293 +               vxwprintk_task(1, "did hit the barrier.");
4294 +               return 1;
4295 +       }
4296 +       return 0;
4297 +}
4298 +
4299 +static int __dx_permission(const struct inode *inode, int mask)
4300 +{
4301 +       if (dx_barrier(inode))
4302 +               return -EACCES;
4303 +
4304 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4305 +               /* devpts is xid tagged */
4306 +               if (S_ISDIR(inode->i_mode) ||
4307 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4308 +                       return 0;
4309 +
4310 +               /* just pretend we didn't find anything */
4311 +               return -ENOENT;
4312 +       }
4313 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4314 +               struct proc_dir_entry *de = PDE(inode);
4315 +
4316 +               if (de && !vx_hide_check(0, de->vx_flags))
4317 +                       goto out;
4318 +
4319 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4320 +                       struct pid *pid;
4321 +                       struct task_struct *tsk;
4322 +
4323 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4324 +                           vx_flags(VXF_STATE_SETUP, 0))
4325 +                               return 0;
4326 +
4327 +                       pid = PROC_I(inode)->pid;
4328 +                       if (!pid)
4329 +                               goto out;
4330 +
4331 +                       rcu_read_lock();
4332 +                       tsk = pid_task(pid, PIDTYPE_PID);
4333 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4334 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4335 +                       if (tsk &&
4336 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4337 +                               rcu_read_unlock();
4338 +                               return 0;
4339 +                       }
4340 +                       rcu_read_unlock();
4341 +               }
4342 +               else {
4343 +                       /* FIXME: Should we block some entries here? */
4344 +                       return 0;
4345 +               }
4346 +       }
4347 +       else {
4348 +               if (dx_notagcheck(inode->i_sb) ||
4349 +                   dx_check((vxid_t)i_tag_read(inode),
4350 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4351 +                       return 0;
4352 +       }
4353 +
4354 +out:
4355 +       return -EACCES;
4356 +}
4357 +
4358 +int dx_permission(const struct inode *inode, int mask)
4359 +{
4360 +       int ret = __dx_permission(inode, mask);
4361 +       if (unlikely(ret)) {
4362 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4363 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4364 +#endif
4365 +                   vxwprintk_task(1,
4366 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4367 +                       mask, inode->i_sb->s_id, inode,
4368 +                       i_tag_read(inode), inode->i_ino);
4369 +       }
4370 +       return ret;
4371 +}
4372 +
4373  /*
4374   * This does the basic permission checking
4375   */
4376 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4377                 /*
4378                  * Nobody gets write access to an immutable file.
4379                  */
4380 -               if (IS_IMMUTABLE(inode))
4381 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4382                         return -EACCES;
4383         }
4384  
4385 +       retval = dx_permission(inode, mask);
4386 +       if (retval)
4387 +               return retval;
4388 +
4389         retval = do_inode_permission(inode, mask);
4390         if (retval)
4391                 return retval;
4392 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4393  
4394                 if (nd->path.dentry == nd->root.dentry &&
4395                     nd->path.mnt == nd->root.mnt) {
4396 -                       break;
4397 +                       /* for sane '/' avoid follow_mount() */
4398 +                       return;
4399                 }
4400                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4401                         /* rare case of legitimate dget_parent()... */
4402 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4403                                 goto unlazy;
4404                         }
4405                 }
4406 +
4407 +               /* FIXME: check dx permission */
4408 +
4409                 path->mnt = mnt;
4410                 path->dentry = dentry;
4411                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4412 @@ -1413,6 +1514,8 @@ unlazy:
4413                 }
4414         }
4415  
4416 +       /* FIXME: check dx permission */
4417 +
4418         path->mnt = mnt;
4419         path->dentry = dentry;
4420         err = follow_managed(path, nd->flags);
4421 @@ -2400,7 +2503,7 @@ static int may_delete(struct inode *dir,
4422                 return -EPERM;
4423  
4424         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4425 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4426 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4427                 return -EPERM;
4428         if (isdir) {
4429                 if (!d_is_directory(victim) && !d_is_autodir(victim))
4430 @@ -2480,19 +2583,25 @@ int vfs_create(struct inode *dir, struct
4431                 bool want_excl)
4432  {
4433         int error = may_create(dir, dentry);
4434 -       if (error)
4435 +       if (error) {
4436 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4437                 return error;
4438 +       }
4439  
4440         if (!dir->i_op->create)
4441                 return -EACCES; /* shouldn't it be ENOSYS? */
4442         mode &= S_IALLUGO;
4443         mode |= S_IFREG;
4444         error = security_inode_create(dir, dentry, mode);
4445 -       if (error)
4446 +       if (error) {
4447 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4448                 return error;
4449 +       }
4450         error = dir->i_op->create(dir, dentry, mode, want_excl);
4451         if (!error)
4452                 fsnotify_create(dir, dentry);
4453 +       else
4454 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4455         return error;
4456  }
4457  
4458 @@ -2527,6 +2636,15 @@ static int may_open(struct path *path, i
4459                 break;
4460         }
4461  
4462 +#ifdef CONFIG_VSERVER_COWBL
4463 +       if (IS_COW(inode) &&
4464 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4465 +               if (IS_COW_LINK(inode))
4466 +                       return -EMLINK;
4467 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4468 +               mark_inode_dirty(inode);
4469 +       }
4470 +#endif
4471         error = inode_permission(inode, acc_mode);
4472         if (error)
4473                 return error;
4474 @@ -3022,6 +3140,16 @@ finish_open:
4475         }
4476  finish_open_created:
4477         error = may_open(&nd->path, acc_mode, open_flag);
4478 +#ifdef CONFIG_VSERVER_COWBL
4479 +       if (error == -EMLINK) {
4480 +               struct dentry *dentry;
4481 +               dentry = cow_break_link(name->name);
4482 +               if (IS_ERR(dentry))
4483 +                       error = PTR_ERR(dentry);
4484 +               else
4485 +                       dput(dentry);
4486 +       }
4487 +#endif
4488         if (error)
4489                 goto out;
4490         file->f_path.mnt = nd->path.mnt;
4491 @@ -3147,6 +3275,7 @@ static struct file *path_openat(int dfd,
4492         int opened = 0;
4493         int error;
4494  
4495 +restart:
4496         file = get_empty_filp();
4497         if (IS_ERR(file))
4498                 return file;
4499 @@ -3188,6 +3317,16 @@ static struct file *path_openat(int dfd,
4500                 error = do_last(nd, &path, file, op, &opened, pathname);
4501                 put_link(nd, &link, cookie);
4502         }
4503 +
4504 +#ifdef CONFIG_VSERVER_COWBL
4505 +       if (error == -EMLINK) {
4506 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4507 +                       path_put(&nd->root);
4508 +               if (base)
4509 +                       fput(base);
4510 +               goto restart;
4511 +       }
4512 +#endif
4513  out:
4514         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4515                 path_put(&nd->root);
4516 @@ -3303,6 +3442,11 @@ struct dentry *kern_path_create(int dfd,
4517                 goto fail;
4518         }
4519         *path = nd.path;
4520 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4521 +               path->dentry, path->dentry->d_name.len,
4522 +               path->dentry->d_name.name, dentry,
4523 +               dentry->d_name.len, dentry->d_name.name,
4524 +               path->dentry->d_inode);
4525         return dentry;
4526  fail:
4527         dput(dentry);
4528 @@ -3850,7 +3994,7 @@ int vfs_link(struct dentry *old_dentry,
4529         /*
4530          * A link to an append-only or immutable file cannot be created.
4531          */
4532 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4533 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4534                 return -EPERM;
4535         if (!dir->i_op->link)
4536                 return -EPERM;
4537 @@ -4305,6 +4449,288 @@ int generic_readlink(struct dentry *dent
4538         return res;
4539  }
4540  
4541 +
4542 +#ifdef CONFIG_VSERVER_COWBL
4543 +
4544 +static inline
4545 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4546 +{
4547 +       loff_t ppos = 0;
4548 +       loff_t opos = 0;
4549 +
4550 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4551 +}
4552 +
4553 +struct dentry *cow_break_link(const char *pathname)
4554 +{
4555 +       int ret, mode, pathlen, redo = 0, drop = 1;
4556 +       struct nameidata old_nd, dir_nd;
4557 +       struct path dir_path, *old_path, *new_path;
4558 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4559 +       struct file *old_file;
4560 +       struct file *new_file;
4561 +       char *to, *path, pad='\251';
4562 +       loff_t size;
4563 +
4564 +       vxdprintk(VXD_CBIT(misc, 1),
4565 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4566 +
4567 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4568 +       ret = -ENOMEM;
4569 +       if (!path)
4570 +               goto out;
4571 +
4572 +       /* old_nd.path will have refs to dentry and mnt */
4573 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4574 +       vxdprintk(VXD_CBIT(misc, 2),
4575 +               "do_path_lookup(old): %d", ret);
4576 +       if (ret < 0)
4577 +               goto out_free_path;
4578 +
4579 +       /* dentry/mnt refs handed over to old_path */
4580 +       old_path = &old_nd.path;
4581 +       /* no explicit reference for old_dentry here */
4582 +       old_dentry = old_path->dentry;
4583 +
4584 +       mode = old_dentry->d_inode->i_mode;
4585 +       to = d_path(old_path, path, PATH_MAX-2);
4586 +       pathlen = strlen(to);
4587 +       vxdprintk(VXD_CBIT(misc, 2),
4588 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4589 +               old_dentry,
4590 +               old_dentry->d_name.len, old_dentry->d_name.name,
4591 +               old_dentry->d_name.len);
4592 +
4593 +       to[pathlen + 1] = 0;
4594 +retry:
4595 +       new_dentry = NULL;
4596 +       to[pathlen] = pad--;
4597 +       ret = -ELOOP;
4598 +       if (pad <= '\240')
4599 +               goto out_rel_old;
4600 +
4601 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4602 +
4603 +       /* dir_nd.path will have refs to dentry and mnt */
4604 +       ret = do_path_lookup(AT_FDCWD, to,
4605 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4606 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4607 +       if (ret < 0)
4608 +               goto retry;
4609 +
4610 +       /* this puppy downs the dir inode mutex if successful.
4611 +          dir_path will hold refs to dentry and mnt and
4612 +          we'll have write access to the mnt */
4613 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4614 +       if (!new_dentry || IS_ERR(new_dentry)) {
4615 +               path_put(&dir_nd.path);
4616 +               vxdprintk(VXD_CBIT(misc, 2),
4617 +                       "kern_path_create(new) failed with %ld",
4618 +                       PTR_ERR(new_dentry));
4619 +               goto retry;
4620 +       }
4621 +       vxdprintk(VXD_CBIT(misc, 2),
4622 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4623 +               new_dentry,
4624 +               new_dentry->d_name.len, new_dentry->d_name.name,
4625 +               new_dentry->d_name.len);
4626 +
4627 +       /* take a reference on new_dentry */
4628 +       dget(new_dentry);
4629 +
4630 +       /* dentry/mnt refs handed over to new_path */
4631 +       new_path = &dir_path;
4632 +
4633 +       /* dentry for old/new dir */
4634 +       dir = dir_nd.path.dentry;
4635 +
4636 +       /* give up reference on dir */
4637 +       dput(new_path->dentry);
4638 +
4639 +       /* new_dentry already has a reference */
4640 +       new_path->dentry = new_dentry;
4641 +
4642 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4643 +       vxdprintk(VXD_CBIT(misc, 2),
4644 +               "vfs_create(new): %d", ret);
4645 +       if (ret == -EEXIST) {
4646 +               path_put(&dir_nd.path);
4647 +               mutex_unlock(&dir->d_inode->i_mutex);
4648 +               mnt_drop_write(new_path->mnt);
4649 +               path_put(new_path);
4650 +               new_dentry = NULL;
4651 +               goto retry;
4652 +       }
4653 +       else if (ret < 0)
4654 +               goto out_unlock_new;
4655 +
4656 +       /* drop out early, ret passes ENOENT */
4657 +       ret = -ENOENT;
4658 +       if ((redo = d_unhashed(old_dentry)))
4659 +               goto out_unlock_new;
4660 +
4661 +       /* doesn't change refs for old_path */
4662 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4663 +       vxdprintk(VXD_CBIT(misc, 2),
4664 +               "dentry_open(old): %p", old_file);
4665 +       if (IS_ERR(old_file)) {
4666 +               ret = PTR_ERR(old_file);
4667 +               goto out_unlock_new;
4668 +       }
4669 +
4670 +       /* doesn't change refs for new_path */
4671 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4672 +       vxdprintk(VXD_CBIT(misc, 2),
4673 +               "dentry_open(new): %p", new_file);
4674 +       if (IS_ERR(new_file)) {
4675 +               ret = PTR_ERR(new_file);
4676 +               goto out_fput_old;
4677 +       }
4678 +
4679 +       /* unlock the inode mutex from kern_path_create() */
4680 +       mutex_unlock(&dir->d_inode->i_mutex);
4681 +
4682 +       /* drop write access to mnt */
4683 +       mnt_drop_write(new_path->mnt);
4684 +
4685 +       drop = 0;
4686 +
4687 +       size = i_size_read(old_file->f_dentry->d_inode);
4688 +       ret = do_cow_splice(old_file, new_file, size);
4689 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4690 +       if (ret < 0) {
4691 +               goto out_fput_both;
4692 +       } else if (ret < size) {
4693 +               ret = -ENOSPC;
4694 +               goto out_fput_both;
4695 +       } else {
4696 +               struct inode *old_inode = old_dentry->d_inode;
4697 +               struct inode *new_inode = new_dentry->d_inode;
4698 +               struct iattr attr = {
4699 +                       .ia_uid = old_inode->i_uid,
4700 +                       .ia_gid = old_inode->i_gid,
4701 +                       .ia_valid = ATTR_UID | ATTR_GID
4702 +                       };
4703 +
4704 +               setattr_copy(new_inode, &attr);
4705 +               mark_inode_dirty(new_inode);
4706 +       }
4707 +
4708 +       /* lock rename mutex */
4709 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4710 +
4711 +       /* drop out late */
4712 +       ret = -ENOENT;
4713 +       if ((redo = d_unhashed(old_dentry)))
4714 +               goto out_unlock;
4715 +
4716 +       vxdprintk(VXD_CBIT(misc, 2),
4717 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4718 +               new_dentry->d_name.len, new_dentry->d_name.name,
4719 +               new_dentry->d_name.len,
4720 +               old_dentry->d_name.len, old_dentry->d_name.name,
4721 +               old_dentry->d_name.len);
4722 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4723 +               old_dentry->d_parent->d_inode, old_dentry, NULL, 0);
4724 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4725 +
4726 +out_unlock:
4727 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4728 +
4729 +out_fput_both:
4730 +       vxdprintk(VXD_CBIT(misc, 3),
4731 +               "fput(new_file=%p[#%ld])", new_file,
4732 +               atomic_long_read(&new_file->f_count));
4733 +       fput(new_file);
4734 +
4735 +out_fput_old:
4736 +       vxdprintk(VXD_CBIT(misc, 3),
4737 +               "fput(old_file=%p[#%ld])", old_file,
4738 +               atomic_long_read(&old_file->f_count));
4739 +       fput(old_file);
4740 +
4741 +out_unlock_new:
4742 +       /* drop references from dir_nd.path */
4743 +       path_put(&dir_nd.path);
4744 +
4745 +       if (drop) {
4746 +               /* unlock the inode mutex from kern_path_create() */
4747 +               mutex_unlock(&dir->d_inode->i_mutex);
4748 +
4749 +               /* drop write access to mnt */
4750 +               mnt_drop_write(new_path->mnt);
4751 +       }
4752 +
4753 +       if (!ret)
4754 +               goto out_redo;
4755 +
4756 +       /* error path cleanup */
4757 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4758 +
4759 +out_redo:
4760 +       if (!redo)
4761 +               goto out_rel_both;
4762 +
4763 +       /* lookup dentry once again
4764 +          old_nd.path will be freed as old_path in out_rel_old */
4765 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4766 +       if (ret)
4767 +               goto out_rel_both;
4768 +
4769 +       /* drop reference on new_dentry */
4770 +       dput(new_dentry);
4771 +       new_dentry = old_path->dentry;
4772 +       dget(new_dentry);
4773 +       vxdprintk(VXD_CBIT(misc, 2),
4774 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4775 +               new_dentry,
4776 +               new_dentry->d_name.len, new_dentry->d_name.name,
4777 +               new_dentry->d_name.len);
4778 +
4779 +out_rel_both:
4780 +       if (new_path)
4781 +               path_put(new_path);
4782 +out_rel_old:
4783 +       path_put(old_path);
4784 +out_free_path:
4785 +       kfree(path);
4786 +out:
4787 +       if (ret) {
4788 +               dput(new_dentry);
4789 +               new_dentry = ERR_PTR(ret);
4790 +       }
4791 +       vxdprintk(VXD_CBIT(misc, 3),
4792 +               "cow_break_link returning with %p", new_dentry);
4793 +       return new_dentry;
4794 +}
4795 +
4796 +#endif
4797 +
4798 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4799 +{
4800 +       struct path path;
4801 +       struct vfsmount *vmnt;
4802 +       char *pstr, *root;
4803 +       int length = 0;
4804 +
4805 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4806 +       if (!pstr)
4807 +               return 0;
4808 +
4809 +       vmnt = &ns->root->mnt;
4810 +       path.mnt = vmnt;
4811 +       path.dentry = vmnt->mnt_root;
4812 +       root = d_path(&path, pstr, PATH_MAX - 2);
4813 +       length = sprintf(buffer + length,
4814 +               "Namespace:\t%p [#%u]\n"
4815 +               "RootPath:\t%s\n",
4816 +               ns, atomic_read(&ns->count),
4817 +               root);
4818 +       kfree(pstr);
4819 +       return length;
4820 +}
4821 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4822 +
4823  /* get the link contents into pagecache */
4824  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4825  {
4826 diff -NurpP --minimal linux-3.13.10/fs/namespace.c linux-3.13.10-vs2.3.6.11/fs/namespace.c
4827 --- linux-3.13.10/fs/namespace.c        2014-04-17 01:12:32.000000000 +0000
4828 +++ linux-3.13.10-vs2.3.6.11/fs/namespace.c     2014-04-17 01:18:37.000000000 +0000
4829 @@ -24,6 +24,11 @@
4830  #include <linux/proc_ns.h>
4831  #include <linux/magic.h>
4832  #include <linux/bootmem.h>
4833 +#include <linux/vs_base.h>
4834 +#include <linux/vs_context.h>
4835 +#include <linux/vs_tag.h>
4836 +#include <linux/vserver/space.h>
4837 +#include <linux/vserver/global.h>
4838  #include "pnode.h"
4839  #include "internal.h"
4840  
4841 @@ -839,6 +844,10 @@ vfs_kern_mount(struct file_system_type *
4842         if (!type)
4843                 return ERR_PTR(-ENODEV);
4844  
4845 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4846 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4847 +               return ERR_PTR(-EPERM);
4848 +
4849         mnt = alloc_vfsmnt(name);
4850         if (!mnt)
4851                 return ERR_PTR(-ENOMEM);
4852 @@ -899,6 +908,7 @@ static struct mount *clone_mnt(struct mo
4853         mnt->mnt.mnt_root = dget(root);
4854         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4855         mnt->mnt_parent = mnt;
4856 +       mnt->mnt_tag = old->mnt_tag;
4857         lock_mount_hash();
4858         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4859         unlock_mount_hash();
4860 @@ -1369,7 +1379,8 @@ static int do_umount(struct mount *mnt,
4861   */
4862  static inline bool may_mount(void)
4863  {
4864 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4865 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4866 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4867  }
4868  
4869  /*
4870 @@ -1785,6 +1796,7 @@ static int do_change_type(struct path *p
4871                 if (err)
4872                         goto out_unlock;
4873         }
4874 +       // mnt->mnt_flags = mnt_flags;
4875  
4876         lock_mount_hash();
4877         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4878 @@ -1813,12 +1825,14 @@ static bool has_locked_children(struct m
4879   * do loopback mount.
4880   */
4881  static int do_loopback(struct path *path, const char *old_name,
4882 -                               int recurse)
4883 +       vtag_t tag, unsigned long flags, int mnt_flags)
4884  {
4885         struct path old_path;
4886         struct mount *mnt = NULL, *old, *parent;
4887         struct mountpoint *mp;
4888 +       int recurse = flags & MS_REC;
4889         int err;
4890 +
4891         if (!old_name || !*old_name)
4892                 return -EINVAL;
4893         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4894 @@ -1898,7 +1912,7 @@ static int change_mount_flags(struct vfs
4895   * on it - tough luck.
4896   */
4897  static int do_remount(struct path *path, int flags, int mnt_flags,
4898 -                     void *data)
4899 +       void *data, vxid_t xid)
4900  {
4901         int err;
4902         struct super_block *sb = path->mnt->mnt_sb;
4903 @@ -2377,6 +2391,7 @@ long do_mount(const char *dev_name, cons
4904         struct path path;
4905         int retval = 0;
4906         int mnt_flags = 0;
4907 +       vtag_t tag = 0;
4908  
4909         /* Discard magic */
4910         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4911 @@ -2406,6 +2421,12 @@ long do_mount(const char *dev_name, cons
4912         if (!(flags & MS_NOATIME))
4913                 mnt_flags |= MNT_RELATIME;
4914  
4915 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4916 +               /* FIXME: bind and re-mounts get the tag flag? */
4917 +               if (flags & (MS_BIND|MS_REMOUNT))
4918 +                       flags |= MS_TAGID;
4919 +       }
4920 +
4921         /* Separate the per-mountpoint flags */
4922         if (flags & MS_NOSUID)
4923                 mnt_flags |= MNT_NOSUID;
4924 @@ -2422,15 +2443,17 @@ long do_mount(const char *dev_name, cons
4925         if (flags & MS_RDONLY)
4926                 mnt_flags |= MNT_READONLY;
4927  
4928 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4929 +               mnt_flags |= MNT_NODEV;
4930         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4931                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4932                    MS_STRICTATIME);
4933  
4934         if (flags & MS_REMOUNT)
4935                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4936 -                                   data_page);
4937 +                                   data_page, tag);
4938         else if (flags & MS_BIND)
4939 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4940 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4941         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4942                 retval = do_change_type(&path, flags);
4943         else if (flags & MS_MOVE)
4944 @@ -2546,6 +2569,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4945                         p = next_mnt(p, old);
4946         }
4947         namespace_unlock();
4948 +       atomic_inc(&vs_global_mnt_ns);
4949  
4950         if (rootmnt)
4951                 mntput(rootmnt);
4952 @@ -2727,9 +2751,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4953         new_mnt = real_mount(new.mnt);
4954         root_mnt = real_mount(root.mnt);
4955         old_mnt = real_mount(old.mnt);
4956 -       if (IS_MNT_SHARED(old_mnt) ||
4957 +       if ((IS_MNT_SHARED(old_mnt) ||
4958                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4959 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4960 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4961 +               !vx_flags(VXF_STATE_SETUP, 0))
4962                 goto out4;
4963         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4964                 goto out4;
4965 @@ -2859,6 +2884,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4966         if (!atomic_dec_and_test(&ns->count))
4967                 return;
4968         drop_collected_mounts(&ns->root->mnt);
4969 +       atomic_dec(&vs_global_mnt_ns);
4970         free_mnt_ns(ns);
4971  }
4972  
4973 diff -NurpP --minimal linux-3.13.10/fs/nfs/client.c linux-3.13.10-vs2.3.6.11/fs/nfs/client.c
4974 --- linux-3.13.10/fs/nfs/client.c       2014-01-22 20:39:06.000000000 +0000
4975 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/client.c    2014-01-31 20:38:03.000000000 +0000
4976 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4977         if (server->flags & NFS_MOUNT_SOFT)
4978                 server->client->cl_softrtry = 1;
4979  
4980 +       server->client->cl_tag = 0;
4981 +       if (server->flags & NFS_MOUNT_TAGGED)
4982 +               server->client->cl_tag = 1;
4983         return 0;
4984  }
4985  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4986 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4987                 server->acdirmin = server->acdirmax = 0;
4988         }
4989  
4990 +       /* FIXME: needs fsinfo
4991 +       if (server->flags & NFS_MOUNT_TAGGED)
4992 +               sb->s_flags |= MS_TAGGED;       */
4993 +
4994         server->maxfilesize = fsinfo->maxfilesize;
4995  
4996         server->time_delta = fsinfo->time_delta;
4997 diff -NurpP --minimal linux-3.13.10/fs/nfs/dir.c linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c
4998 --- linux-3.13.10/fs/nfs/dir.c  2014-04-17 01:12:32.000000000 +0000
4999 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c       2014-02-25 11:26:10.000000000 +0000
5000 @@ -37,6 +37,7 @@
5001  #include <linux/sched.h>
5002  #include <linux/kmemleak.h>
5003  #include <linux/xattr.h>
5004 +#include <linux/vs_tag.h>
5005  
5006  #include "delegation.h"
5007  #include "iostat.h"
5008 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
5009         /* Success: notify readdir to use READDIRPLUS */
5010         nfs_advise_use_readdirplus(dir);
5011  
5012 +       dx_propagate_tag(nd, inode);
5013  no_entry:
5014         res = d_materialise_unique(dentry, inode);
5015         if (res != NULL) {
5016 diff -NurpP --minimal linux-3.13.10/fs/nfs/inode.c linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c
5017 --- linux-3.13.10/fs/nfs/inode.c        2014-04-17 01:12:32.000000000 +0000
5018 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c     2014-03-12 15:51:07.000000000 +0000
5019 @@ -38,6 +38,7 @@
5020  #include <linux/slab.h>
5021  #include <linux/compat.h>
5022  #include <linux/freezer.h>
5023 +#include <linux/vs_tag.h>
5024  
5025  #include <asm/uaccess.h>
5026  
5027 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5028         if (inode->i_state & I_NEW) {
5029                 struct nfs_inode *nfsi = NFS_I(inode);
5030                 unsigned long now = jiffies;
5031 +               kuid_t kuid;
5032 +               kgid_t kgid;
5033  
5034                 /* We set i_ino for the few things that still rely on it,
5035                  * such as stat(2) */
5036 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5037                 inode->i_version = 0;
5038                 inode->i_size = 0;
5039                 clear_nlink(inode);
5040 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5041 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5042 +               kuid = make_kuid(&init_user_ns, -2);
5043 +               kgid = make_kgid(&init_user_ns, -2);
5044                 inode->i_blocks = 0;
5045                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5046                 nfsi->write_io = 0;
5047 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5048                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5049                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5050                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5051 -                       inode->i_uid = fattr->uid;
5052 +                       kuid = fattr->uid;
5053                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5054                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5055                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5056 -                       inode->i_gid = fattr->gid;
5057 +                       kgid = fattr->gid;
5058                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5059                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5060                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5061 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5062                          */
5063                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5064                 }
5065 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5066 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5067 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5068 +                               /* maybe fattr->xid someday */
5069  
5070                 nfs_setsecurity(inode, fattr, label);
5071  
5072 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5073                         inode->i_uid = attr->ia_uid;
5074                 if ((attr->ia_valid & ATTR_GID) != 0)
5075                         inode->i_gid = attr->ia_gid;
5076 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5077 +                       inode->i_tag = attr->ia_tag;
5078                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5079                 spin_unlock(&inode->i_lock);
5080         }
5081 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5082         struct nfs_inode *nfsi = NFS_I(inode);
5083         loff_t cur_size, new_isize;
5084         unsigned long invalid = 0;
5085 -
5086 +       kuid_t kuid;
5087 +       kgid_t kgid;
5088 +       ktag_t ktag;
5089  
5090         if (nfs_have_delegated_attributes(inode))
5091                 return 0;
5092 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5093                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5094         }
5095  
5096 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5097 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5098 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5099 +
5100         /* Have any file permissions changed? */
5101         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5102                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5103 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5104 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5105                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5106 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5107 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5108                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5109 +               /* maybe check for tag too? */
5110  
5111         /* Has the link count changed? */
5112         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5113 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5114         unsigned long invalid = 0;
5115         unsigned long now = jiffies;
5116         unsigned long save_cache_validity;
5117 +       kuid_t kuid;
5118 +       kgid_t kgid;
5119 +       ktag_t ktag;
5120  
5121         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5122                         __func__, inode->i_sb->s_id, inode->i_ino,
5123 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5124                                 | NFS_INO_REVAL_PAGECACHE
5125                                 | NFS_INO_REVAL_FORCED);
5126  
5127 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5128 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5129 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5130  
5131         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5132                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5133 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5134                                 | NFS_INO_INVALID_ACL
5135                                 | NFS_INO_REVAL_FORCED);
5136  
5137 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5138 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5139 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5140 +
5141         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5142                 if (inode->i_nlink != fattr->nlink) {
5143                         invalid |= NFS_INO_INVALID_ATTR;
5144 diff -NurpP --minimal linux-3.13.10/fs/nfs/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c
5145 --- linux-3.13.10/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5146 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c   2014-01-31 20:38:03.000000000 +0000
5147 @@ -20,6 +20,7 @@
5148  #include <linux/nfs3.h>
5149  #include <linux/nfs_fs.h>
5150  #include <linux/nfsacl.h>
5151 +#include <linux/vs_tag.h>
5152  #include "internal.h"
5153  
5154  #define NFSDBG_FACILITY                NFSDBG_XDR
5155 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5156   *             set_mtime       mtime;
5157   *     };
5158   */
5159 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5160 +static void encode_sattr3(struct xdr_stream *xdr,
5161 +       const struct iattr *attr, int tag)
5162  {
5163         u32 nbytes;
5164         __be32 *p;
5165 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5166         } else
5167                 *p++ = xdr_zero;
5168  
5169 -       if (attr->ia_valid & ATTR_UID) {
5170 +       if (attr->ia_valid & ATTR_UID ||
5171 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5172                 *p++ = xdr_one;
5173 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5174 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5175 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5176         } else
5177                 *p++ = xdr_zero;
5178  
5179 -       if (attr->ia_valid & ATTR_GID) {
5180 +       if (attr->ia_valid & ATTR_GID ||
5181 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5182                 *p++ = xdr_one;
5183 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5184 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5185 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5186         } else
5187                 *p++ = xdr_zero;
5188  
5189 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5190                                       const struct nfs3_sattrargs *args)
5191  {
5192         encode_nfs_fh3(xdr, args->fh);
5193 -       encode_sattr3(xdr, args->sattr);
5194 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5195         encode_sattrguard3(xdr, args);
5196  }
5197  
5198 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5199   *     };
5200   */
5201  static void encode_createhow3(struct xdr_stream *xdr,
5202 -                             const struct nfs3_createargs *args)
5203 +       const struct nfs3_createargs *args, int tag)
5204  {
5205         encode_uint32(xdr, args->createmode);
5206         switch (args->createmode) {
5207         case NFS3_CREATE_UNCHECKED:
5208         case NFS3_CREATE_GUARDED:
5209 -               encode_sattr3(xdr, args->sattr);
5210 +               encode_sattr3(xdr, args->sattr, tag);
5211                 break;
5212         case NFS3_CREATE_EXCLUSIVE:
5213                 encode_createverf3(xdr, args->verifier);
5214 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5215                                      const struct nfs3_createargs *args)
5216  {
5217         encode_diropargs3(xdr, args->fh, args->name, args->len);
5218 -       encode_createhow3(xdr, args);
5219 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5220  }
5221  
5222  /*
5223 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5224                                     const struct nfs3_mkdirargs *args)
5225  {
5226         encode_diropargs3(xdr, args->fh, args->name, args->len);
5227 -       encode_sattr3(xdr, args->sattr);
5228 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5229  }
5230  
5231  /*
5232 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5233   *     };
5234   */
5235  static void encode_symlinkdata3(struct xdr_stream *xdr,
5236 -                               const struct nfs3_symlinkargs *args)
5237 +       const struct nfs3_symlinkargs *args, int tag)
5238  {
5239 -       encode_sattr3(xdr, args->sattr);
5240 +       encode_sattr3(xdr, args->sattr, tag);
5241         encode_nfspath3(xdr, args->pages, args->pathlen);
5242  }
5243  
5244 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5245                                       const struct nfs3_symlinkargs *args)
5246  {
5247         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5248 -       encode_symlinkdata3(xdr, args);
5249 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5250  }
5251  
5252  /*
5253 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5254   *     };
5255   */
5256  static void encode_devicedata3(struct xdr_stream *xdr,
5257 -                              const struct nfs3_mknodargs *args)
5258 +       const struct nfs3_mknodargs *args, int tag)
5259  {
5260 -       encode_sattr3(xdr, args->sattr);
5261 +       encode_sattr3(xdr, args->sattr, tag);
5262         encode_specdata3(xdr, args->rdev);
5263  }
5264  
5265  static void encode_mknoddata3(struct xdr_stream *xdr,
5266 -                             const struct nfs3_mknodargs *args)
5267 +       const struct nfs3_mknodargs *args, int tag)
5268  {
5269         encode_ftype3(xdr, args->type);
5270         switch (args->type) {
5271         case NF3CHR:
5272         case NF3BLK:
5273 -               encode_devicedata3(xdr, args);
5274 +               encode_devicedata3(xdr, args, tag);
5275                 break;
5276         case NF3SOCK:
5277         case NF3FIFO:
5278 -               encode_sattr3(xdr, args->sattr);
5279 +               encode_sattr3(xdr, args->sattr, tag);
5280                 break;
5281         case NF3REG:
5282         case NF3DIR:
5283 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5284                                     const struct nfs3_mknodargs *args)
5285  {
5286         encode_diropargs3(xdr, args->fh, args->name, args->len);
5287 -       encode_mknoddata3(xdr, args);
5288 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5289  }
5290  
5291  /*
5292 diff -NurpP --minimal linux-3.13.10/fs/nfs/super.c linux-3.13.10-vs2.3.6.11/fs/nfs/super.c
5293 --- linux-3.13.10/fs/nfs/super.c        2014-01-22 20:39:06.000000000 +0000
5294 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/super.c     2014-01-31 20:38:03.000000000 +0000
5295 @@ -55,6 +55,7 @@
5296  #include <linux/parser.h>
5297  #include <linux/nsproxy.h>
5298  #include <linux/rcupdate.h>
5299 +#include <linux/vs_tag.h>
5300  
5301  #include <asm/uaccess.h>
5302  
5303 @@ -103,6 +104,7 @@ enum {
5304         Opt_mountport,
5305         Opt_mountvers,
5306         Opt_minorversion,
5307 +       Opt_tagid,
5308  
5309         /* Mount options that take string arguments */
5310         Opt_nfsvers,
5311 @@ -115,6 +117,9 @@ enum {
5312         /* Special mount options */
5313         Opt_userspace, Opt_deprecated, Opt_sloppy,
5314  
5315 +       /* Linux-VServer tagging options */
5316 +       Opt_tag, Opt_notag,
5317 +
5318         Opt_err
5319  };
5320  
5321 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5322         { Opt_fscache_uniq, "fsc=%s" },
5323         { Opt_local_lock, "local_lock=%s" },
5324  
5325 +       { Opt_tag, "tag" },
5326 +       { Opt_notag, "notag" },
5327 +       { Opt_tagid, "tagid=%u" },
5328 +
5329         /* The following needs to be listed after all other options */
5330         { Opt_nfsvers, "v%s" },
5331  
5332 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5333                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5334                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5335                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5336 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5337                 { 0, NULL, NULL }
5338         };
5339         const struct proc_nfs_info *nfs_infop;
5340 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5341                 case Opt_nomigration:
5342                         mnt->options &= NFS_OPTION_MIGRATION;
5343                         break;
5344 +#ifndef CONFIG_TAGGING_NONE
5345 +               case Opt_tag:
5346 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5347 +                       break;
5348 +               case Opt_notag:
5349 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5350 +                       break;
5351 +#endif
5352  
5353                 /*
5354                  * options that take numeric values
5355 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5356                                 goto out_invalid_value;
5357                         mnt->minorversion = option;
5358                         break;
5359 +#ifdef CONFIG_PROPAGATE
5360 +               case Opt_tagid:
5361 +                       /* use args[0] */
5362 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5363 +                       break;
5364 +#endif
5365  
5366                 /*
5367                  * options that take text values
5368 diff -NurpP --minimal linux-3.13.10/fs/nfsd/auth.c linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c
5369 --- linux-3.13.10/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5370 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c     2014-01-31 20:38:03.000000000 +0000
5371 @@ -2,6 +2,7 @@
5372  
5373  #include <linux/sched.h>
5374  #include <linux/user_namespace.h>
5375 +#include <linux/vs_tag.h>
5376  #include "nfsd.h"
5377  #include "auth.h"
5378  
5379 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5380  
5381         new->fsuid = rqstp->rq_cred.cr_uid;
5382         new->fsgid = rqstp->rq_cred.cr_gid;
5383 +       /* FIXME: this desperately needs a tag :)
5384 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5385 +                       */
5386  
5387         rqgi = rqstp->rq_cred.cr_group_info;
5388  
5389 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5390 --- linux-3.13.10/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5391 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c  2014-01-31 20:38:03.000000000 +0000
5392 @@ -8,6 +8,7 @@
5393  
5394  #include <linux/namei.h>
5395  #include <linux/sunrpc/svc_xprt.h>
5396 +#include <linux/vs_tag.h>
5397  #include "xdr3.h"
5398  #include "auth.h"
5399  #include "netns.h"
5400 @@ -98,6 +99,8 @@ static __be32 *
5401  decode_sattr3(__be32 *p, struct iattr *iap)
5402  {
5403         u32     tmp;
5404 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5405 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5406  
5407         iap->ia_valid = 0;
5408  
5409 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5410                 iap->ia_mode = ntohl(*p++);
5411         }
5412         if (*p++) {
5413 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5414 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5415                 if (uid_valid(iap->ia_uid))
5416                         iap->ia_valid |= ATTR_UID;
5417         }
5418         if (*p++) {
5419 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5420 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5421                 if (gid_valid(iap->ia_gid))
5422                         iap->ia_valid |= ATTR_GID;
5423         }
5424 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5425 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5426 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5427         if (*p++) {
5428                 u64     newsize;
5429  
5430 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5431         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5432         *p++ = htonl((u32) stat->mode);
5433         *p++ = htonl((u32) stat->nlink);
5434 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5435 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5436 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5437 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5438 +               stat->uid, stat->tag)));
5439 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5440 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5441 +               stat->gid, stat->tag)));
5442         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5443                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5444         } else {
5445 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs4xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5446 --- linux-3.13.10/fs/nfsd/nfs4xdr.c     2014-01-22 20:39:06.000000000 +0000
5447 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c  2014-01-31 20:38:03.000000000 +0000
5448 @@ -46,6 +46,7 @@
5449  #include <linux/utsname.h>
5450  #include <linux/pagemap.h>
5451  #include <linux/sunrpc/svcauth_gss.h>
5452 +#include <linux/vs_tag.h>
5453  
5454  #include "idmap.h"
5455  #include "acl.h"
5456 @@ -2430,10 +2431,14 @@ out_acl:
5457                 WRITE32(stat.nlink);
5458         }
5459         if (bmval1 & FATTR4_WORD1_OWNER) {
5460 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5461 +               status = nfsd4_encode_user(rqstp,
5462 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5463 +                       stat.uid, stat.tag), &p, &buflen);
5464                 if (status)
5465                         goto out;
5466         }
5467         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5468 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5469 +               status = nfsd4_encode_group(rqstp,
5470 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5471 +                       stat.gid, stat.tag), &p, &buflen);
5472                 if (status)
5473                         goto out;
5474         }
5475 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfsxdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c
5476 --- linux-3.13.10/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5477 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c   2014-01-31 20:38:03.000000000 +0000
5478 @@ -7,6 +7,7 @@
5479  #include "vfs.h"
5480  #include "xdr.h"
5481  #include "auth.h"
5482 +#include <linux/vs_tag.h>
5483  
5484  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5485  
5486 @@ -89,6 +90,8 @@ static __be32 *
5487  decode_sattr(__be32 *p, struct iattr *iap)
5488  {
5489         u32     tmp, tmp1;
5490 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5491 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5492  
5493         iap->ia_valid = 0;
5494  
5495 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5496                 iap->ia_mode = tmp;
5497         }
5498         if ((tmp = ntohl(*p++)) != (u32)-1) {
5499 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5500 +               kuid = make_kuid(&init_user_ns, tmp);
5501                 if (uid_valid(iap->ia_uid))
5502                         iap->ia_valid |= ATTR_UID;
5503         }
5504         if ((tmp = ntohl(*p++)) != (u32)-1) {
5505 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5506 +               kgid = make_kgid(&init_user_ns, tmp);
5507                 if (gid_valid(iap->ia_gid))
5508                         iap->ia_valid |= ATTR_GID;
5509         }
5510 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5511 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5512 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5513         if ((tmp = ntohl(*p++)) != (u32)-1) {
5514                 iap->ia_valid |= ATTR_SIZE;
5515                 iap->ia_size = tmp;
5516 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5517         *p++ = htonl(nfs_ftypes[type >> 12]);
5518         *p++ = htonl((u32) stat->mode);
5519         *p++ = htonl((u32) stat->nlink);
5520 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5521 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5522 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5523 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5524 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5525 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5526  
5527         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5528                 *p++ = htonl(NFS_MAXPATHLEN);
5529 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c
5530 --- linux-3.13.10/fs/ocfs2/dlmglue.c    2014-01-22 20:39:07.000000000 +0000
5531 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5532 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5533         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5534         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5535         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5536 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5537         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5538         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5539         lvb->lvb_iatime_packed  =
5540 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5541  
5542         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5543         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5544 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5545         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5546         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5547         ocfs2_unpack_timespec(&inode->i_atime,
5548 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h
5549 --- linux-3.13.10/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5550 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5551 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5552         __be16       lvb_inlink;
5553         __be32       lvb_iattr;
5554         __be32       lvb_igeneration;
5555 -       __be32       lvb_reserved2;
5556 +       __be16       lvb_itag;
5557 +       __be16       lvb_reserved2;
5558  };
5559  
5560  #define OCFS2_QINFO_LVB_VERSION 1
5561 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/file.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c
5562 --- linux-3.13.10/fs/ocfs2/file.c       2014-04-17 01:12:32.000000000 +0000
5563 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c    2014-04-17 01:17:10.000000000 +0000
5564 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5565                 attr->ia_valid &= ~ATTR_SIZE;
5566  
5567  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5568 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5569 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5570         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5571                 return 0;
5572  
5573 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c
5574 --- linux-3.13.10/fs/ocfs2/inode.c      2014-01-22 20:39:07.000000000 +0000
5575 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c   2014-01-31 20:38:03.000000000 +0000
5576 @@ -28,6 +28,7 @@
5577  #include <linux/highmem.h>
5578  #include <linux/pagemap.h>
5579  #include <linux/quotaops.h>
5580 +#include <linux/vs_tag.h>
5581  
5582  #include <asm/byteorder.h>
5583  
5584 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5585  {
5586         unsigned int flags = OCFS2_I(inode)->ip_attr;
5587  
5588 -       inode->i_flags &= ~(S_IMMUTABLE |
5589 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5590                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5591  
5592         if (flags & OCFS2_IMMUTABLE_FL)
5593                 inode->i_flags |= S_IMMUTABLE;
5594 +       if (flags & OCFS2_IXUNLINK_FL)
5595 +               inode->i_flags |= S_IXUNLINK;
5596  
5597         if (flags & OCFS2_SYNC_FL)
5598                 inode->i_flags |= S_SYNC;
5599 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5600                 inode->i_flags |= S_NOATIME;
5601         if (flags & OCFS2_DIRSYNC_FL)
5602                 inode->i_flags |= S_DIRSYNC;
5603 +
5604 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5605 +
5606 +       if (flags & OCFS2_BARRIER_FL)
5607 +               inode->i_vflags |= V_BARRIER;
5608 +       if (flags & OCFS2_COW_FL)
5609 +               inode->i_vflags |= V_COW;
5610  }
5611  
5612  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5613  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5614  {
5615         unsigned int flags = oi->vfs_inode.i_flags;
5616 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5617 +
5618 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5619 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5620 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5621 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5622 +
5623 +       if (flags & S_IMMUTABLE)
5624 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5625 +       if (flags & S_IXUNLINK)
5626 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5627  
5628 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5629 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5630         if (flags & S_SYNC)
5631                 oi->ip_attr |= OCFS2_SYNC_FL;
5632         if (flags & S_APPEND)
5633                 oi->ip_attr |= OCFS2_APPEND_FL;
5634 -       if (flags & S_IMMUTABLE)
5635 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5636         if (flags & S_NOATIME)
5637                 oi->ip_attr |= OCFS2_NOATIME_FL;
5638         if (flags & S_DIRSYNC)
5639                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5640 +
5641 +       if (vflags & V_BARRIER)
5642 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5643 +       if (vflags & V_COW)
5644 +               oi->ip_attr |= OCFS2_COW_FL;
5645  }
5646  
5647  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5648 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5649         struct super_block *sb;
5650         struct ocfs2_super *osb;
5651         int use_plocks = 1;
5652 +       uid_t uid;
5653 +       gid_t gid;
5654  
5655         sb = inode->i_sb;
5656         osb = OCFS2_SB(sb);
5657 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5658         inode->i_generation = le32_to_cpu(fe->i_generation);
5659         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5660         inode->i_mode = le16_to_cpu(fe->i_mode);
5661 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5662 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5663 +       uid = le32_to_cpu(fe->i_uid);
5664 +       gid = le32_to_cpu(fe->i_gid);
5665 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5666 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5667 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5668 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5669  
5670         /* Fast symlinks will have i_size but no allocated clusters. */
5671         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5672 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h
5673 --- linux-3.13.10/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5674 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h   2014-01-31 20:38:03.000000000 +0000
5675 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5676  
5677  void ocfs2_set_inode_flags(struct inode *inode);
5678  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5679 +int ocfs2_sync_flags(struct inode *inode, int, int);
5680  
5681  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5682  {
5683 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c
5684 --- linux-3.13.10/fs/ocfs2/ioctl.c      2013-11-25 15:47:00.000000000 +0000
5685 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c   2014-01-31 20:38:03.000000000 +0000
5686 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5687         return status;
5688  }
5689  
5690 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5691 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5692 +{
5693 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5694 +       struct buffer_head *bh = NULL;
5695 +       handle_t *handle = NULL;
5696 +       int status;
5697 +
5698 +       status = ocfs2_inode_lock(inode, &bh, 1);
5699 +       if (status < 0) {
5700 +               mlog_errno(status);
5701 +               return status;
5702 +       }
5703 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5704 +       if (IS_ERR(handle)) {
5705 +               status = PTR_ERR(handle);
5706 +               mlog_errno(status);
5707 +               goto bail_unlock;
5708 +       }
5709 +
5710 +       inode->i_flags = flags;
5711 +       inode->i_vflags = vflags;
5712 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5713 +
5714 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5715 +       if (status < 0)
5716 +               mlog_errno(status);
5717 +
5718 +       ocfs2_commit_trans(osb, handle);
5719 +bail_unlock:
5720 +       ocfs2_inode_unlock(inode, 1);
5721 +       brelse(bh);
5722 +       return status;
5723 +}
5724 +
5725 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5726                                 unsigned mask)
5727  {
5728         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5729 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5730                         goto bail_unlock;
5731         }
5732  
5733 +       if (IS_BARRIER(inode)) {
5734 +               vxwprintk_task(1, "messing with the barrier.");
5735 +               goto bail_unlock;
5736 +       }
5737 +
5738         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5739         if (IS_ERR(handle)) {
5740                 status = PTR_ERR(handle);
5741 @@ -881,6 +920,7 @@ bail:
5742         return status;
5743  }
5744  
5745 +
5746  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5747  {
5748         struct inode *inode = file_inode(filp);
5749 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/namei.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c
5750 --- linux-3.13.10/fs/ocfs2/namei.c      2014-01-22 20:39:07.000000000 +0000
5751 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c   2014-01-31 20:38:03.000000000 +0000
5752 @@ -41,6 +41,7 @@
5753  #include <linux/slab.h>
5754  #include <linux/highmem.h>
5755  #include <linux/quotaops.h>
5756 +#include <linux/vs_tag.h>
5757  
5758  #include <cluster/masklog.h>
5759  
5760 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5761         struct ocfs2_extent_list *fel;
5762         u16 feat;
5763         struct ocfs2_inode_info *oi = OCFS2_I(inode);
5764 +       ktag_t ktag;
5765  
5766         *new_fe_bh = NULL;
5767  
5768 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5769         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5770         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5771         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5772 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5773 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5774 +
5775 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5776 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5777 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5778 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5779 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5780 +       inode->i_tag = ktag; /* is this correct? */
5781         fe->i_mode = cpu_to_le16(inode->i_mode);
5782         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5783                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5784 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h
5785 --- linux-3.13.10/fs/ocfs2/ocfs2.h      2013-11-25 15:45:04.000000000 +0000
5786 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h   2014-01-31 20:38:03.000000000 +0000
5787 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5788                                                      writes */
5789         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5790         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5791 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5792  };
5793  
5794  #define OCFS2_OSB_SOFT_RO                      0x0001
5795 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
5796 --- linux-3.13.10/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5797 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h        2014-01-31 20:38:03.000000000 +0000
5798 @@ -266,6 +266,11 @@
5799  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5800  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5801  
5802 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5803 +
5804 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5805 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5806 +
5807  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5808  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5809  
5810 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/super.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c
5811 --- linux-3.13.10/fs/ocfs2/super.c      2014-01-22 20:39:07.000000000 +0000
5812 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c   2014-01-31 20:38:03.000000000 +0000
5813 @@ -185,6 +185,7 @@ enum {
5814         Opt_coherency_full,
5815         Opt_resv_level,
5816         Opt_dir_resv_level,
5817 +       Opt_tag, Opt_notag, Opt_tagid,
5818         Opt_err,
5819  };
5820  
5821 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5822         {Opt_coherency_full, "coherency=full"},
5823         {Opt_resv_level, "resv_level=%u"},
5824         {Opt_dir_resv_level, "dir_resv_level=%u"},
5825 +       {Opt_tag, "tag"},
5826 +       {Opt_notag, "notag"},
5827 +       {Opt_tagid, "tagid=%u"},
5828         {Opt_err, NULL}
5829  };
5830  
5831 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5832                 goto out;
5833         }
5834  
5835 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5836 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5837 +               ret = -EINVAL;
5838 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5839 +               goto out;
5840 +       }
5841 +
5842         /* We're going to/from readonly mode. */
5843         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5844                 /* Disable quota accounting before remounting RO */
5845 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5846  
5847         ocfs2_complete_mount_recovery(osb);
5848  
5849 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5850 +               sb->s_flags |= MS_TAGGED;
5851 +
5852         if (ocfs2_mount_local(osb))
5853                 snprintf(nodestr, sizeof(nodestr), "local");
5854         else
5855 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5856                             option < OCFS2_MAX_RESV_LEVEL)
5857                                 mopt->dir_resv_level = option;
5858                         break;
5859 +#ifndef CONFIG_TAGGING_NONE
5860 +               case Opt_tag:
5861 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5862 +                       break;
5863 +               case Opt_notag:
5864 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5865 +                       break;
5866 +#endif
5867 +#ifdef CONFIG_PROPAGATE
5868 +               case Opt_tagid:
5869 +                       /* use args[0] */
5870 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5871 +                       break;
5872 +#endif
5873                 default:
5874                         mlog(ML_ERROR,
5875                              "Unrecognized mount option \"%s\" "
5876 diff -NurpP --minimal linux-3.13.10/fs/open.c linux-3.13.10-vs2.3.6.11/fs/open.c
5877 --- linux-3.13.10/fs/open.c     2014-01-22 20:39:07.000000000 +0000
5878 +++ linux-3.13.10-vs2.3.6.11/fs/open.c  2014-01-31 20:38:03.000000000 +0000
5879 @@ -31,6 +31,11 @@
5880  #include <linux/ima.h>
5881  #include <linux/dnotify.h>
5882  #include <linux/compat.h>
5883 +#include <linux/vs_base.h>
5884 +#include <linux/vs_limit.h>
5885 +#include <linux/vs_tag.h>
5886 +#include <linux/vs_cowbl.h>
5887 +#include <linux/vserver/dlimit.h>
5888  
5889  #include "internal.h"
5890  
5891 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5892         struct inode *inode;
5893         long error;
5894  
5895 +#ifdef CONFIG_VSERVER_COWBL
5896 +       error = cow_check_and_break(path);
5897 +       if (error)
5898 +               goto out;
5899 +#endif
5900         inode = path->dentry->d_inode;
5901  
5902         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5903 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5904         unsigned int lookup_flags = LOOKUP_FOLLOW;
5905  retry:
5906         error = user_path_at(dfd, filename, lookup_flags, &path);
5907 +#ifdef CONFIG_VSERVER_COWBL
5908 +       if (!error) {
5909 +               error = cow_check_and_break(&path);
5910 +               if (error)
5911 +                       path_put(&path);
5912 +       }
5913 +#endif
5914         if (!error) {
5915                 error = chmod_common(&path, mode);
5916                 path_put(&path);
5917 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5918                 if (!uid_valid(uid))
5919                         return -EINVAL;
5920                 newattrs.ia_valid |= ATTR_UID;
5921 -               newattrs.ia_uid = uid;
5922 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5923 +                       dx_map_uid(user));
5924         }
5925         if (group != (gid_t) -1) {
5926                 if (!gid_valid(gid))
5927                         return -EINVAL;
5928                 newattrs.ia_valid |= ATTR_GID;
5929 -               newattrs.ia_gid = gid;
5930 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5931 +                       dx_map_gid(group));
5932         }
5933         if (!S_ISDIR(inode->i_mode))
5934                 newattrs.ia_valid |=
5935 @@ -589,6 +608,18 @@ retry:
5936         error = mnt_want_write(path.mnt);
5937         if (error)
5938                 goto out_release;
5939 +#ifdef CONFIG_VSERVER_COWBL
5940 +       error = cow_check_and_break(&path);
5941 +       if (!error)
5942 +#endif
5943 +#ifdef CONFIG_VSERVER_COWBL
5944 +       error = cow_check_and_break(&path);
5945 +       if (!error)
5946 +#endif
5947 +#ifdef CONFIG_VSERVER_COWBL
5948 +       error = cow_check_and_break(&path);
5949 +       if (!error)
5950 +#endif
5951         error = chown_common(&path, user, group);
5952         mnt_drop_write(path.mnt);
5953  out_release:
5954 diff -NurpP --minimal linux-3.13.10/fs/proc/array.c linux-3.13.10-vs2.3.6.11/fs/proc/array.c
5955 --- linux-3.13.10/fs/proc/array.c       2014-01-22 20:39:07.000000000 +0000
5956 +++ linux-3.13.10-vs2.3.6.11/fs/proc/array.c    2014-02-01 01:44:54.000000000 +0000
5957 @@ -82,6 +82,8 @@
5958  #include <linux/ptrace.h>
5959  #include <linux/tracehook.h>
5960  #include <linux/user_namespace.h>
5961 +#include <linux/vs_context.h>
5962 +#include <linux/vs_network.h>
5963  
5964  #include <asm/pgtable.h>
5965  #include <asm/processor.h>
5966 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5967         rcu_read_lock();
5968         ppid = pid_alive(p) ?
5969                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5970 +       if (unlikely(vx_current_initpid(p->pid)))
5971 +               ppid = 0;
5972 +
5973         tpid = 0;
5974         if (pid_alive(p)) {
5975                 struct task_struct *tracer = ptrace_parent(p);
5976 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5977  }
5978  
5979  static void render_cap_t(struct seq_file *m, const char *header,
5980 -                       kernel_cap_t *a)
5981 +                       struct vx_info *vxi, kernel_cap_t *a)
5982  {
5983         unsigned __capi;
5984  
5985 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5986         NORM_CAPS(cap_effective);
5987         NORM_CAPS(cap_bset);
5988  
5989 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5990 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5991 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5992 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5993 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5994 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5995 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5996 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5997 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5998  }
5999  
6000  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6001 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
6002         seq_putc(m, '\n');
6003  }
6004  
6005 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6006 +                       struct pid *pid, struct task_struct *task)
6007 +{
6008 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6009 +                       "Count:\t%u\n"
6010 +                       "uts:\t%p(%c)\n"
6011 +                       "ipc:\t%p(%c)\n"
6012 +                       "mnt:\t%p(%c)\n"
6013 +                       "pid:\t%p(%c)\n"
6014 +                       "net:\t%p(%c)\n",
6015 +                       task->nsproxy,
6016 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6017 +                       atomic_read(&task->nsproxy->count),
6018 +                       task->nsproxy->uts_ns,
6019 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6020 +                       task->nsproxy->ipc_ns,
6021 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6022 +                       task->nsproxy->mnt_ns,
6023 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6024 +                       task->nsproxy->pid_ns_for_children,
6025 +                       (task->nsproxy->pid_ns_for_children ==
6026 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6027 +                       task->nsproxy->net_ns,
6028 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6029 +       return 0;
6030 +}
6031 +
6032 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6033 +{
6034 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6035 +               return;
6036 +
6037 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6038 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6039 +}
6040 +
6041 +
6042  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6043                         struct pid *pid, struct task_struct *task)
6044  {
6045 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6046         task_seccomp(m, task);
6047         task_cpus_allowed(m, task);
6048         cpuset_task_status_allowed(m, task);
6049 +       task_vs_id(m, task);
6050         task_context_switch_counts(m, task);
6051         return 0;
6052  }
6053 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6054         /* convert nsec -> ticks */
6055         start_time = nsec_to_clock_t(start_time);
6056  
6057 +       /* fixup start time for virt uptime */
6058 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6059 +               unsigned long long bias =
6060 +                       current->vx_info->cvirt.bias_clock;
6061 +
6062 +               if (start_time > bias)
6063 +                       start_time -= bias;
6064 +               else
6065 +                       start_time = 0;
6066 +       }
6067 +
6068         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6069         seq_put_decimal_ll(m, ' ', ppid);
6070         seq_put_decimal_ll(m, ' ', pgid);
6071 diff -NurpP --minimal linux-3.13.10/fs/proc/base.c linux-3.13.10-vs2.3.6.11/fs/proc/base.c
6072 --- linux-3.13.10/fs/proc/base.c        2014-04-17 01:12:32.000000000 +0000
6073 +++ linux-3.13.10-vs2.3.6.11/fs/proc/base.c     2014-04-17 01:17:10.000000000 +0000
6074 @@ -87,6 +87,8 @@
6075  #include <linux/slab.h>
6076  #include <linux/flex_array.h>
6077  #include <linux/posix-timers.h>
6078 +#include <linux/vs_context.h>
6079 +#include <linux/vs_network.h>
6080  #ifdef CONFIG_HARDWALL
6081  #include <asm/hardwall.h>
6082  #endif
6083 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6084                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6085  
6086         if (oom_adj < task->signal->oom_score_adj &&
6087 -           !capable(CAP_SYS_RESOURCE)) {
6088 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6089                 err = -EACCES;
6090                 goto err_sighand;
6091         }
6092  
6093 +       /* prevent guest processes from circumventing the oom killer */
6094 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6095 +               oom_adj = OOM_ADJUST_MIN;
6096 +
6097         /*
6098          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6099          * /proc/pid/oom_score_adj instead.
6100 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6101                 inode->i_gid = cred->egid;
6102                 rcu_read_unlock();
6103         }
6104 +       /* procfs is xid tagged */
6105 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6106         security_task_to_inode(task, inode);
6107  
6108  out:
6109 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6110  
6111  /* dentry stuff */
6112  
6113 +static unsigned name_to_int(struct dentry *dentry);
6114 +
6115  /*
6116   *     Exceptional case: normally we are not allowed to unhash a busy
6117   * directory. In this case, however, we can do it - no aliasing problems
6118 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6119         task = get_proc_task(inode);
6120  
6121         if (task) {
6122 +               unsigned pid = name_to_int(dentry);
6123 +
6124 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6125 +                       put_task_struct(task);
6126 +                       goto drop;
6127 +               }
6128                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6129                     task_dumpable(task)) {
6130                         rcu_read_lock();
6131 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6132                 put_task_struct(task);
6133                 return 1;
6134         }
6135 +drop:
6136         d_drop(dentry);
6137         return 0;
6138  }
6139 @@ -2173,6 +2190,13 @@ static struct dentry *proc_pident_lookup
6140         if (!task)
6141                 goto out_no_task;
6142  
6143 +       /* TODO: maybe we can come up with a generic approach? */
6144 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6145 +               (dentry->d_name.len == 5) &&
6146 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6147 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6148 +               goto out;
6149 +
6150         /*
6151          * Yes, it does not scale. And it should not. Don't add
6152          * new entries into /proc/<tgid>/ without very good reasons.
6153 @@ -2569,6 +2593,9 @@ static int proc_pid_personality(struct s
6154  static const struct file_operations proc_task_operations;
6155  static const struct inode_operations proc_task_inode_operations;
6156  
6157 +extern int proc_pid_vx_info(struct task_struct *, char *);
6158 +extern int proc_pid_nx_info(struct task_struct *, char *);
6159 +
6160  static const struct pid_entry tgid_base_stuff[] = {
6161         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6162         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6163 @@ -2635,6 +2662,8 @@ static const struct pid_entry tgid_base_
6164  #ifdef CONFIG_CGROUPS
6165         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6166  #endif
6167 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6168 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6169         INF("oom_score",  S_IRUGO, proc_oom_score),
6170         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6171         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6172 @@ -2847,7 +2876,7 @@ retry:
6173         iter.task = NULL;
6174         pid = find_ge_pid(iter.tgid, ns);
6175         if (pid) {
6176 -               iter.tgid = pid_nr_ns(pid, ns);
6177 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6178                 iter.task = pid_task(pid, PIDTYPE_PID);
6179                 /* What we to know is if the pid we have find is the
6180                  * pid of a thread_group_leader.  Testing for task
6181 @@ -2900,8 +2929,10 @@ int proc_pid_readdir(struct file *file,
6182                 if (!has_pid_permissions(ns, iter.task, 2))
6183                         continue;
6184  
6185 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
6186 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6187                 ctx->pos = iter.tgid + TGID_OFFSET;
6188 +               if (!vx_proc_task_visible(iter.task))
6189 +                       continue;
6190                 if (!proc_fill_cache(file, ctx, name, len,
6191                                      proc_pid_instantiate, iter.task, NULL)) {
6192                         put_task_struct(iter.task);
6193 @@ -2994,6 +3025,7 @@ static const struct pid_entry tid_base_s
6194         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6195         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6196  #endif
6197 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6198  };
6199  
6200  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6201 @@ -3060,6 +3092,8 @@ static struct dentry *proc_task_lookup(s
6202         tid = name_to_int(dentry);
6203         if (tid == ~0U)
6204                 goto out;
6205 +       if (vx_current_initpid(tid))
6206 +               goto out;
6207  
6208         ns = dentry->d_sb->s_fs_info;
6209         rcu_read_lock();
6210 diff -NurpP --minimal linux-3.13.10/fs/proc/generic.c linux-3.13.10-vs2.3.6.11/fs/proc/generic.c
6211 --- linux-3.13.10/fs/proc/generic.c     2014-01-22 20:39:07.000000000 +0000
6212 +++ linux-3.13.10-vs2.3.6.11/fs/proc/generic.c  2014-02-01 00:07:40.000000000 +0000
6213 @@ -23,6 +23,7 @@
6214  #include <linux/bitops.h>
6215  #include <linux/spinlock.h>
6216  #include <linux/completion.h>
6217 +#include <linux/vserver/inode.h>
6218  #include <asm/uaccess.h>
6219  
6220  #include "internal.h"
6221 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6222         for (de = de->subdir; de ; de = de->next) {
6223                 if (de->namelen != dentry->d_name.len)
6224                         continue;
6225 +               if (!vx_hide_check(0, de->vx_flags))
6226 +                       continue;
6227                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6228                         pde_get(de);
6229                         spin_unlock(&proc_subdir_lock);
6230 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6231                                 return ERR_PTR(-ENOMEM);
6232                         d_set_d_op(dentry, &simple_dentry_operations);
6233                         d_add(dentry, inode);
6234 +                       /* generic proc entries belong to the host */
6235 +                       i_tag_write(inode, 0);
6236                         return NULL;
6237                 }
6238         }
6239 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6240         do {
6241                 struct proc_dir_entry *next;
6242                 pde_get(de);
6243 +
6244 +               if (!vx_hide_check(0, de->vx_flags))
6245 +                       goto skip;
6246                 spin_unlock(&proc_subdir_lock);
6247                 if (!dir_emit(ctx, de->name, de->namelen,
6248                             de->low_ino, de->mode >> 12)) {
6249 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6250                         return 0;
6251                 }
6252                 spin_lock(&proc_subdir_lock);
6253 +       skip:
6254                 ctx->pos++;
6255                 next = de->next;
6256                 pde_put(de);
6257 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6258         ent->namelen = len;
6259         ent->mode = mode;
6260         ent->nlink = nlink;
6261 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6262         atomic_set(&ent->count, 1);
6263         spin_lock_init(&ent->pde_unload_lock);
6264         INIT_LIST_HEAD(&ent->pde_openers);
6265 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6266                                 kfree(ent->data);
6267                                 kfree(ent);
6268                                 ent = NULL;
6269 -                       }
6270 +                       } else
6271 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6272                 } else {
6273                         kfree(ent);
6274                         ent = NULL;
6275 diff -NurpP --minimal linux-3.13.10/fs/proc/inode.c linux-3.13.10-vs2.3.6.11/fs/proc/inode.c
6276 --- linux-3.13.10/fs/proc/inode.c       2014-01-22 20:39:07.000000000 +0000
6277 +++ linux-3.13.10-vs2.3.6.11/fs/proc/inode.c    2014-01-31 20:38:03.000000000 +0000
6278 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6279                         inode->i_uid = de->uid;
6280                         inode->i_gid = de->gid;
6281                 }
6282 +               if (de->vx_flags)
6283 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6284                 if (de->size)
6285                         inode->i_size = de->size;
6286                 if (de->nlink)
6287 diff -NurpP --minimal linux-3.13.10/fs/proc/internal.h linux-3.13.10-vs2.3.6.11/fs/proc/internal.h
6288 --- linux-3.13.10/fs/proc/internal.h    2013-11-25 15:45:04.000000000 +0000
6289 +++ linux-3.13.10-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6290 @@ -14,6 +14,7 @@
6291  #include <linux/spinlock.h>
6292  #include <linux/atomic.h>
6293  #include <linux/binfmts.h>
6294 +#include <linux/vs_pid.h>
6295  
6296  struct ctl_table_header;
6297  struct mempolicy;
6298 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6299         nlink_t nlink;
6300         kuid_t uid;
6301         kgid_t gid;
6302 +       int vx_flags;
6303         loff_t size;
6304         const struct inode_operations *proc_iops;
6305         const struct file_operations *proc_fops;
6306 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6307         char name[];
6308  };
6309  
6310 +struct vx_info;
6311 +struct nx_info;
6312 +
6313  union proc_op {
6314         int (*proc_get_link)(struct dentry *, struct path *);
6315         int (*proc_read)(struct task_struct *task, char *page);
6316         int (*proc_show)(struct seq_file *m,
6317                 struct pid_namespace *ns, struct pid *pid,
6318                 struct task_struct *task);
6319 +       int (*proc_vs_read)(char *page);
6320 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6321 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6322  };
6323  
6324  struct proc_inode {
6325         struct pid *pid;
6326 +       int vx_flags;
6327         int fd;
6328         union proc_op op;
6329         struct proc_dir_entry *pde;
6330 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6331         return PROC_I(inode)->pid;
6332  }
6333  
6334 -static inline struct task_struct *get_proc_task(struct inode *inode)
6335 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6336  {
6337         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6338  }
6339  
6340 +static inline struct task_struct *get_proc_task(struct inode *inode)
6341 +{
6342 +       return vx_get_proc_task(inode, proc_pid(inode));
6343 +}
6344 +
6345  static inline int task_dumpable(struct task_struct *task)
6346  {
6347         int dumpable = 0;
6348 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6349                            struct pid *, struct task_struct *);
6350  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6351                           struct pid *, struct task_struct *);
6352 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6353 +                           struct pid *pid, struct task_struct *task);
6354  
6355  /*
6356   * base.c
6357 diff -NurpP --minimal linux-3.13.10/fs/proc/loadavg.c linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c
6358 --- linux-3.13.10/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6359 +++ linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c  2014-01-31 20:38:03.000000000 +0000
6360 @@ -12,15 +12,27 @@
6361  
6362  static int loadavg_proc_show(struct seq_file *m, void *v)
6363  {
6364 +       unsigned long running;
6365 +       unsigned int threads;
6366         unsigned long avnrun[3];
6367  
6368         get_avenrun(avnrun, FIXED_1/200, 0);
6369  
6370 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6371 +               struct vx_info *vxi = current_vx_info();
6372 +
6373 +               running = atomic_read(&vxi->cvirt.nr_running);
6374 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6375 +       } else {
6376 +               running = nr_running();
6377 +               threads = nr_threads;
6378 +       }
6379 +
6380         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6381                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6382                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6383                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6384 -               nr_running(), nr_threads,
6385 +               running, threads,
6386                 task_active_pid_ns(current)->last_pid);
6387         return 0;
6388  }
6389 diff -NurpP --minimal linux-3.13.10/fs/proc/meminfo.c linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c
6390 --- linux-3.13.10/fs/proc/meminfo.c     2014-01-22 20:39:07.000000000 +0000
6391 +++ linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c  2014-01-31 20:38:03.000000000 +0000
6392 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6393         si_swapinfo(&i);
6394         committed = percpu_counter_read_positive(&vm_committed_as);
6395  
6396 -       cached = global_page_state(NR_FILE_PAGES) -
6397 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6398 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6399                         total_swapcache_pages() - i.bufferram;
6400         if (cached < 0)
6401                 cached = 0;
6402 diff -NurpP --minimal linux-3.13.10/fs/proc/root.c linux-3.13.10-vs2.3.6.11/fs/proc/root.c
6403 --- linux-3.13.10/fs/proc/root.c        2013-11-25 15:47:00.000000000 +0000
6404 +++ linux-3.13.10-vs2.3.6.11/fs/proc/root.c     2014-02-01 00:02:11.000000000 +0000
6405 @@ -20,9 +20,14 @@
6406  #include <linux/mount.h>
6407  #include <linux/pid_namespace.h>
6408  #include <linux/parser.h>
6409 +#include <linux/vserver/inode.h>
6410  
6411  #include "internal.h"
6412  
6413 +struct proc_dir_entry *proc_virtual;
6414 +
6415 +extern void proc_vx_init(void);
6416 +
6417  static int proc_test_super(struct super_block *sb, void *data)
6418  {
6419         return sb->s_fs_info == data;
6420 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6421                         return ERR_PTR(-EPERM);
6422  
6423                 /* Does the mounter have privilege over the pid namespace? */
6424 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6425 +               if (!vx_ns_capable(ns->user_ns,
6426 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6427                         return ERR_PTR(-EPERM);
6428         }
6429  
6430 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6431  #endif
6432         proc_mkdir("bus", NULL);
6433         proc_sys_init();
6434 +       proc_vx_init();
6435  }
6436  
6437  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6438 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6439         .proc_iops      = &proc_root_inode_operations, 
6440         .proc_fops      = &proc_root_operations,
6441         .parent         = &proc_root,
6442 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6443         .name           = "/proc",
6444  };
6445  
6446 diff -NurpP --minimal linux-3.13.10/fs/proc/self.c linux-3.13.10-vs2.3.6.11/fs/proc/self.c
6447 --- linux-3.13.10/fs/proc/self.c        2014-01-22 20:39:07.000000000 +0000
6448 +++ linux-3.13.10-vs2.3.6.11/fs/proc/self.c     2014-01-31 20:38:03.000000000 +0000
6449 @@ -2,6 +2,7 @@
6450  #include <linux/namei.h>
6451  #include <linux/slab.h>
6452  #include <linux/pid_namespace.h>
6453 +#include <linux/vserver/inode.h>
6454  #include "internal.h"
6455  
6456  /*
6457 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6458         self = d_alloc_name(s->s_root, "self");
6459         if (self) {
6460                 struct inode *inode = new_inode_pseudo(s);
6461 +
6462 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6463                 if (inode) {
6464                         inode->i_ino = self_inum;
6465                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6466 diff -NurpP --minimal linux-3.13.10/fs/proc/stat.c linux-3.13.10-vs2.3.6.11/fs/proc/stat.c
6467 --- linux-3.13.10/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6468 +++ linux-3.13.10-vs2.3.6.11/fs/proc/stat.c     2014-01-31 20:38:03.000000000 +0000
6469 @@ -9,8 +9,10 @@
6470  #include <linux/slab.h>
6471  #include <linux/time.h>
6472  #include <linux/irqnr.h>
6473 +#include <linux/vserver/cvirt.h>
6474  #include <linux/cputime.h>
6475  #include <linux/tick.h>
6476 +#include <linux/cpuset.h>
6477  
6478  #ifndef arch_irq_stat_cpu
6479  #define arch_irq_stat_cpu(cpu) 0
6480 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6481         u64 sum_softirq = 0;
6482         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6483         struct timespec boottime;
6484 +       cpumask_var_t cpus_allowed;
6485 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6486  
6487         user = nice = system = idle = iowait =
6488                 irq = softirq = steal = 0;
6489         guest = guest_nice = 0;
6490         getboottime(&boottime);
6491 +
6492 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6493 +               vx_vsi_boottime(&boottime);
6494 +
6495 +       if (virt_cpu)
6496 +               cpuset_cpus_allowed(current, cpus_allowed);
6497 +
6498         jif = boottime.tv_sec;
6499  
6500         for_each_possible_cpu(i) {
6501 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6502 +                       continue;
6503 +
6504                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6505                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6506                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6507 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6508         seq_putc(p, '\n');
6509  
6510         for_each_online_cpu(i) {
6511 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6512 +                       continue;
6513 +
6514                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6515                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6516                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6517 diff -NurpP --minimal linux-3.13.10/fs/proc/uptime.c linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c
6518 --- linux-3.13.10/fs/proc/uptime.c      2013-11-25 15:45:04.000000000 +0000
6519 +++ linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c   2014-01-31 20:38:03.000000000 +0000
6520 @@ -5,6 +5,7 @@
6521  #include <linux/seq_file.h>
6522  #include <linux/time.h>
6523  #include <linux/kernel_stat.h>
6524 +#include <linux/vserver/cvirt.h>
6525  #include <linux/cputime.h>
6526  
6527  static int uptime_proc_show(struct seq_file *m, void *v)
6528 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6529         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6530         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6531         idle.tv_nsec = rem;
6532 +
6533 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6534 +               vx_vsi_uptime(&uptime, &idle);
6535 +
6536         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6537                         (unsigned long) uptime.tv_sec,
6538                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6539 diff -NurpP --minimal linux-3.13.10/fs/proc_namespace.c linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c
6540 --- linux-3.13.10/fs/proc_namespace.c   2014-01-22 20:39:07.000000000 +0000
6541 +++ linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c        2014-02-25 12:43:16.000000000 +0000
6542 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6543                 { MS_SYNCHRONOUS, ",sync" },
6544                 { MS_DIRSYNC, ",dirsync" },
6545                 { MS_MANDLOCK, ",mand" },
6546 +               { MS_TAGGED, ",tag" },
6547 +               { MS_NOTAGCHECK, ",notagcheck" },
6548                 { 0, NULL }
6549         };
6550         const struct proc_fs_info *fs_infop;
6551 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6552         seq_escape(m, s, " \t\n\\");
6553  }
6554  
6555 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6556 +
6557 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6558 +{
6559 +       struct path root;
6560 +       struct dentry *point;
6561 +       struct mount *mnt = real_mount(vfsmnt);
6562 +       struct mount *root_mnt;
6563 +       int ret;
6564 +
6565 +       if (mnt == mnt->mnt_ns->root)
6566 +               return 1;
6567 +
6568 +       rcu_read_lock();
6569 +       root = current->fs->root;
6570 +       root_mnt = real_mount(root.mnt);
6571 +       point = root.dentry;
6572 +
6573 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6574 +               point = mnt->mnt_mountpoint;
6575 +               mnt = mnt->mnt_parent;
6576 +       }
6577 +       rcu_read_unlock();
6578 +
6579 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6580 +       return ret;
6581 +}
6582 +
6583 +#else
6584 +#define        mnt_is_reachable(v)     (1)
6585 +#endif
6586 +
6587  static void show_type(struct seq_file *m, struct super_block *sb)
6588  {
6589         mangle(m, sb->s_type->name);
6590 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6591         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6592         struct super_block *sb = mnt_path.dentry->d_sb;
6593  
6594 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6595 +               return SEQ_SKIP;
6596 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6597 +               return SEQ_SKIP;
6598 +
6599 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6600 +               mnt == current->fs->root.mnt) {
6601 +               seq_puts(m, "/dev/root / ");
6602 +               goto type;
6603 +       }
6604 +
6605         if (sb->s_op->show_devname) {
6606                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6607                 if (err)
6608 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6609         seq_putc(m, ' ');
6610         seq_path(m, &mnt_path, " \t\n\\");
6611         seq_putc(m, ' ');
6612 +type:
6613         show_type(m, sb);
6614         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6615         err = show_sb_opts(m, sb);
6616 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6617         struct path root = p->root;
6618         int err = 0;
6619  
6620 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6621 +               return SEQ_SKIP;
6622 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6623 +               return SEQ_SKIP;
6624 +
6625         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6626                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6627         if (sb->s_op->show_path)
6628 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6629         struct super_block *sb = mnt_path.dentry->d_sb;
6630         int err = 0;
6631  
6632 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6633 +               return SEQ_SKIP;
6634 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6635 +               return SEQ_SKIP;
6636 +
6637 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6638 +               mnt == current->fs->root.mnt) {
6639 +               seq_puts(m, "device /dev/root mounted on / ");
6640 +               goto type;
6641 +       }
6642 +
6643         /* device */
6644         if (sb->s_op->show_devname) {
6645                 seq_puts(m, "device ");
6646 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6647         seq_puts(m, " mounted on ");
6648         seq_path(m, &mnt_path, " \t\n\\");
6649         seq_putc(m, ' ');
6650 -
6651 +type:
6652         /* file system type */
6653         seq_puts(m, "with fstype ");
6654         show_type(m, sb);
6655 diff -NurpP --minimal linux-3.13.10/fs/quota/dquot.c linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c
6656 --- linux-3.13.10/fs/quota/dquot.c      2014-04-17 01:12:34.000000000 +0000
6657 +++ linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c   2014-03-12 15:51:07.000000000 +0000
6658 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6659         struct dquot **dquots = inode->i_dquot;
6660         int reserve = flags & DQUOT_SPACE_RESERVE;
6661  
6662 +       if ((ret = dl_alloc_space(inode, number)))
6663 +               return ret;
6664 +
6665         /*
6666          * First test before acquiring mutex - solves deadlocks when we
6667          * re-enter the quota code and are already holding the mutex
6668 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6669         struct dquot_warn warn[MAXQUOTAS];
6670         struct dquot * const *dquots = inode->i_dquot;
6671  
6672 +       if ((ret = dl_alloc_inode(inode)))
6673 +               return ret;
6674 +
6675         /* First test before acquiring mutex - solves deadlocks when we
6676           * re-enter the quota code and are already holding the mutex */
6677         if (!dquot_active(inode))
6678 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6679         struct dquot **dquots = inode->i_dquot;
6680         int reserve = flags & DQUOT_SPACE_RESERVE;
6681  
6682 +       dl_free_space(inode, number);
6683 +
6684         /* First test before acquiring mutex - solves deadlocks when we
6685           * re-enter the quota code and are already holding the mutex */
6686         if (!dquot_active(inode)) {
6687 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6688         struct dquot_warn warn[MAXQUOTAS];
6689         struct dquot * const *dquots = inode->i_dquot;
6690  
6691 +       dl_free_inode(inode);
6692 +
6693         /* First test before acquiring mutex - solves deadlocks when we
6694           * re-enter the quota code and are already holding the mutex */
6695         if (!dquot_active(inode))
6696 diff -NurpP --minimal linux-3.13.10/fs/quota/quota.c linux-3.13.10-vs2.3.6.11/fs/quota/quota.c
6697 --- linux-3.13.10/fs/quota/quota.c      2014-01-22 20:39:07.000000000 +0000
6698 +++ linux-3.13.10-vs2.3.6.11/fs/quota/quota.c   2014-01-31 20:38:03.000000000 +0000
6699 @@ -8,6 +8,7 @@
6700  #include <linux/fs.h>
6701  #include <linux/namei.h>
6702  #include <linux/slab.h>
6703 +#include <linux/vs_context.h>
6704  #include <asm/current.h>
6705  #include <linux/uaccess.h>
6706  #include <linux/kernel.h>
6707 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6708                         break;
6709                 /*FALLTHROUGH*/
6710         default:
6711 -               if (!capable(CAP_SYS_ADMIN))
6712 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6713                         return -EPERM;
6714         }
6715  
6716 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6717  
6718  #ifdef CONFIG_BLOCK
6719  
6720 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6721 +
6722 +#include <linux/vroot.h>
6723 +#include <linux/major.h>
6724 +#include <linux/module.h>
6725 +#include <linux/kallsyms.h>
6726 +#include <linux/vserver/debug.h>
6727 +
6728 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6729 +
6730 +static DEFINE_SPINLOCK(vroot_grb_lock);
6731 +
6732 +int register_vroot_grb(vroot_grb_func *func) {
6733 +       int ret = -EBUSY;
6734 +
6735 +       spin_lock(&vroot_grb_lock);
6736 +       if (!vroot_get_real_bdev) {
6737 +               vroot_get_real_bdev = func;
6738 +               ret = 0;
6739 +       }
6740 +       spin_unlock(&vroot_grb_lock);
6741 +       return ret;
6742 +}
6743 +EXPORT_SYMBOL(register_vroot_grb);
6744 +
6745 +int unregister_vroot_grb(vroot_grb_func *func) {
6746 +       int ret = -EINVAL;
6747 +
6748 +       spin_lock(&vroot_grb_lock);
6749 +       if (vroot_get_real_bdev) {
6750 +               vroot_get_real_bdev = NULL;
6751 +               ret = 0;
6752 +       }
6753 +       spin_unlock(&vroot_grb_lock);
6754 +       return ret;
6755 +}
6756 +EXPORT_SYMBOL(unregister_vroot_grb);
6757 +
6758 +#endif
6759 +
6760  /* Return 1 if 'cmd' will block on frozen filesystem */
6761  static int quotactl_cmd_write(int cmd)
6762  {
6763 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6764         putname(tmp);
6765         if (IS_ERR(bdev))
6766                 return ERR_CAST(bdev);
6767 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6768 +       if (bdev && bdev->bd_inode &&
6769 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6770 +               struct block_device *bdnew = (void *)-EINVAL;
6771 +
6772 +               if (vroot_get_real_bdev)
6773 +                       bdnew = vroot_get_real_bdev(bdev);
6774 +               else
6775 +                       vxdprintk(VXD_CBIT(misc, 0),
6776 +                                       "vroot_get_real_bdev not set");
6777 +               bdput(bdev);
6778 +               if (IS_ERR(bdnew))
6779 +                       return ERR_PTR(PTR_ERR(bdnew));
6780 +               bdev = bdnew;
6781 +       }
6782 +#endif
6783         if (quotactl_cmd_write(cmd))
6784                 sb = get_super_thawed(bdev);
6785         else
6786 diff -NurpP --minimal linux-3.13.10/fs/stat.c linux-3.13.10-vs2.3.6.11/fs/stat.c
6787 --- linux-3.13.10/fs/stat.c     2014-01-22 20:39:07.000000000 +0000
6788 +++ linux-3.13.10-vs2.3.6.11/fs/stat.c  2014-01-31 20:38:03.000000000 +0000
6789 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6790         stat->nlink = inode->i_nlink;
6791         stat->uid = inode->i_uid;
6792         stat->gid = inode->i_gid;
6793 +       stat->tag = inode->i_tag;
6794         stat->rdev = inode->i_rdev;
6795         stat->size = i_size_read(inode);
6796         stat->atime = inode->i_atime;
6797 diff -NurpP --minimal linux-3.13.10/fs/statfs.c linux-3.13.10-vs2.3.6.11/fs/statfs.c
6798 --- linux-3.13.10/fs/statfs.c   2013-11-25 15:47:00.000000000 +0000
6799 +++ linux-3.13.10-vs2.3.6.11/fs/statfs.c        2014-01-31 20:38:03.000000000 +0000
6800 @@ -7,6 +7,8 @@
6801  #include <linux/statfs.h>
6802  #include <linux/security.h>
6803  #include <linux/uaccess.h>
6804 +#include <linux/vs_base.h>
6805 +#include <linux/vs_dlimit.h>
6806  #include "internal.h"
6807  
6808  static int flags_by_mnt(int mnt_flags)
6809 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6810         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6811         if (retval == 0 && buf->f_frsize == 0)
6812                 buf->f_frsize = buf->f_bsize;
6813 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6814 +               vx_vsi_statfs(dentry->d_sb, buf);
6815         return retval;
6816  }
6817  
6818 diff -NurpP --minimal linux-3.13.10/fs/super.c linux-3.13.10-vs2.3.6.11/fs/super.c
6819 --- linux-3.13.10/fs/super.c    2014-01-22 20:39:07.000000000 +0000
6820 +++ linux-3.13.10-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6821 @@ -34,6 +34,8 @@
6822  #include <linux/cleancache.h>
6823  #include <linux/fsnotify.h>
6824  #include <linux/lockdep.h>
6825 +#include <linux/magic.h>
6826 +#include <linux/vs_context.h>
6827  #include "internal.h"
6828  
6829  
6830 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6831         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6832         sb->s_flags |= MS_BORN;
6833  
6834 +       error = -EPERM;
6835 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6836 +               !sb->s_bdev &&
6837 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6838 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6839 +               goto out_sb;
6840 +
6841         error = security_sb_kern_mount(sb, flags, secdata);
6842         if (error)
6843                 goto out_sb;
6844 diff -NurpP --minimal linux-3.13.10/fs/utimes.c linux-3.13.10-vs2.3.6.11/fs/utimes.c
6845 --- linux-3.13.10/fs/utimes.c   2014-01-22 20:39:07.000000000 +0000
6846 +++ linux-3.13.10-vs2.3.6.11/fs/utimes.c        2014-01-31 23:49:14.000000000 +0000
6847 @@ -8,6 +8,8 @@
6848  #include <linux/stat.h>
6849  #include <linux/utime.h>
6850  #include <linux/syscalls.h>
6851 +#include <linux/mount.h>
6852 +#include <linux/vs_cowbl.h>
6853  #include <asm/uaccess.h>
6854  #include <asm/unistd.h>
6855  
6856 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6857  {
6858         int error;
6859         struct iattr newattrs;
6860 -       struct inode *inode = path->dentry->d_inode;
6861         struct inode *delegated_inode = NULL;
6862 +       struct inode *inode;
6863 +
6864 +       error = cow_check_and_break(path);
6865 +       if (error)
6866 +               goto out;
6867  
6868         error = mnt_want_write(path->mnt);
6869         if (error)
6870                 goto out;
6871  
6872 +       inode = path->dentry->d_inode;
6873 +
6874         if (times && times[0].tv_nsec == UTIME_NOW &&
6875                      times[1].tv_nsec == UTIME_NOW)
6876                 times = NULL;
6877 diff -NurpP --minimal linux-3.13.10/fs/xattr.c linux-3.13.10-vs2.3.6.11/fs/xattr.c
6878 --- linux-3.13.10/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6879 +++ linux-3.13.10-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6880 @@ -21,6 +21,7 @@
6881  #include <linux/audit.h>
6882  #include <linux/vmalloc.h>
6883  #include <linux/posix_acl_xattr.h>
6884 +#include <linux/mount.h>
6885  
6886  #include <asm/uaccess.h>
6887  
6888 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6889          * The trusted.* namespace can only be accessed by privileged users.
6890          */
6891         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6892 -               if (!capable(CAP_SYS_ADMIN))
6893 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6894                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6895                 return 0;
6896         }
6897 diff -NurpP --minimal linux-3.13.10/include/linux/cred.h linux-3.13.10-vs2.3.6.11/include/linux/cred.h
6898 --- linux-3.13.10/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
6899 +++ linux-3.13.10-vs2.3.6.11/include/linux/cred.h       2014-01-31 20:38:03.000000000 +0000
6900 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6901  extern int copy_creds(struct task_struct *, unsigned long);
6902  extern const struct cred *get_task_cred(struct task_struct *);
6903  extern struct cred *cred_alloc_blank(void);
6904 +extern struct cred *__prepare_creds(const struct cred *);
6905  extern struct cred *prepare_creds(void);
6906  extern struct cred *prepare_exec_creds(void);
6907  extern int commit_creds(struct cred *);
6908 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6909  }
6910  #endif
6911  
6912 +static inline void set_cred_subscribers(struct cred *cred, int n)
6913 +{
6914 +#ifdef CONFIG_DEBUG_CREDENTIALS
6915 +       atomic_set(&cred->subscribers, n);
6916 +#endif
6917 +}
6918 +
6919 +static inline int read_cred_subscribers(const struct cred *cred)
6920 +{
6921 +#ifdef CONFIG_DEBUG_CREDENTIALS
6922 +       return atomic_read(&cred->subscribers);
6923 +#else
6924 +       return 0;
6925 +#endif
6926 +}
6927 +
6928 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6929 +{
6930 +#ifdef CONFIG_DEBUG_CREDENTIALS
6931 +       struct cred *cred = (struct cred *) _cred;
6932 +
6933 +       atomic_add(n, &cred->subscribers);
6934 +#endif
6935 +}
6936 +
6937  /**
6938   * get_new_cred - Get a reference on a new set of credentials
6939   * @cred: The new credentials to reference
6940 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
6941 --- linux-3.13.10/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
6942 +++ linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h  2014-01-31 20:38:03.000000000 +0000
6943 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6944  
6945  #endif
6946  
6947 -
6948  #endif /* _LINUX_DEVPTS_FS_H */
6949 diff -NurpP --minimal linux-3.13.10/include/linux/fs.h linux-3.13.10-vs2.3.6.11/include/linux/fs.h
6950 --- linux-3.13.10/include/linux/fs.h    2014-01-22 20:39:10.000000000 +0000
6951 +++ linux-3.13.10-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6952 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6953  #define ATTR_KILL_PRIV (1 << 14)
6954  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6955  #define ATTR_TIMES_SET (1 << 16)
6956 +#define ATTR_TAG       (1 << 17)
6957  
6958  /*
6959   * This is the Inode Attributes structure, used for notify_change().  It
6960 @@ -228,6 +229,7 @@ struct iattr {
6961         umode_t         ia_mode;
6962         kuid_t          ia_uid;
6963         kgid_t          ia_gid;
6964 +       ktag_t          ia_tag;
6965         loff_t          ia_size;
6966         struct timespec ia_atime;
6967         struct timespec ia_mtime;
6968 @@ -526,7 +528,9 @@ struct inode {
6969         unsigned short          i_opflags;
6970         kuid_t                  i_uid;
6971         kgid_t                  i_gid;
6972 -       unsigned int            i_flags;
6973 +       ktag_t                  i_tag;
6974 +       unsigned short          i_flags;
6975 +       unsigned short          i_vflags;
6976  
6977  #ifdef CONFIG_FS_POSIX_ACL
6978         struct posix_acl        *i_acl;
6979 @@ -555,6 +559,7 @@ struct inode {
6980                 unsigned int __i_nlink;
6981         };
6982         dev_t                   i_rdev;
6983 +       dev_t                   i_mdev;
6984         loff_t                  i_size;
6985         struct timespec         i_atime;
6986         struct timespec         i_mtime;
6987 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
6988         return from_kgid(&init_user_ns, inode->i_gid);
6989  }
6990  
6991 +static inline vtag_t i_tag_read(const struct inode *inode)
6992 +{
6993 +       return from_ktag(&init_user_ns, inode->i_tag);
6994 +}
6995 +
6996  static inline void i_uid_write(struct inode *inode, uid_t uid)
6997  {
6998         inode->i_uid = make_kuid(&init_user_ns, uid);
6999 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
7000         inode->i_gid = make_kgid(&init_user_ns, gid);
7001  }
7002  
7003 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7004 +{
7005 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7006 +}
7007 +
7008  static inline unsigned iminor(const struct inode *inode)
7009  {
7010 -       return MINOR(inode->i_rdev);
7011 +       return MINOR(inode->i_mdev);
7012  }
7013  
7014  static inline unsigned imajor(const struct inode *inode)
7015  {
7016 -       return MAJOR(inode->i_rdev);
7017 +       return MAJOR(inode->i_mdev);
7018  }
7019  
7020  extern struct block_device *I_BDEV(struct inode *inode);
7021 @@ -790,6 +805,7 @@ struct file {
7022         loff_t                  f_pos;
7023         struct fown_struct      f_owner;
7024         const struct cred       *f_cred;
7025 +       vxid_t                  f_xid;
7026         struct file_ra_state    f_ra;
7027  
7028         u64                     f_version;
7029 @@ -962,6 +978,7 @@ struct file_lock {
7030         struct file *fl_file;
7031         loff_t fl_start;
7032         loff_t fl_end;
7033 +       vxid_t fl_xid;
7034  
7035         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7036         /* for lease breaks: */
7037 @@ -1573,6 +1590,7 @@ struct inode_operations {
7038         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7039         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7040         int (*removexattr) (struct dentry *, const char *);
7041 +       int (*sync_flags) (struct inode *, int, int);
7042         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7043                       u64 len);
7044         int (*update_time)(struct inode *, struct timespec *, int);
7045 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7046                               unsigned long nr_segs, unsigned long fast_segs,
7047                               struct iovec *fast_pointer,
7048                               struct iovec **ret_pointer);
7049 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7050  
7051  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7052  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7053 @@ -1639,6 +1658,14 @@ struct super_operations {
7054  #define S_IMA          1024    /* Inode has an associated IMA struct */
7055  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7056  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7057 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7058 +
7059 +/* Linux-VServer related Inode flags */
7060 +
7061 +#define V_VALID                1
7062 +#define V_XATTR                2
7063 +#define V_BARRIER      4       /* Barrier for chroot() */
7064 +#define V_COW          8       /* Copy on Write */
7065  
7066  /*
7067   * Note that nosuid etc flags are inode-specific: setting some file-system
7068 @@ -1663,10 +1690,13 @@ struct super_operations {
7069  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7070  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7071  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7072 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7073  
7074  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7075  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7076  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7077 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7078 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7079  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7080  
7081  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7082 @@ -1677,6 +1707,16 @@ struct super_operations {
7083  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7084  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7085  
7086 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7087 +
7088 +#ifdef CONFIG_VSERVER_COWBL
7089 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7090 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7091 +#else
7092 +#  define IS_COW(inode)                (0)
7093 +#  define IS_COW_LINK(inode)   (0)
7094 +#endif
7095 +
7096  /*
7097   * Inode state bits.  Protected by inode->i_lock
7098   *
7099 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7100  extern int locks_mandatory_locked(struct inode *);
7101  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7102  
7103 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7104 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7105 +
7106  /*
7107   * Candidates for mandatory locking have the setgid bit set
7108   * but no group execute bit -  an otherwise meaningless combination.
7109 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7110  extern int dcache_dir_close(struct inode *, struct file *);
7111  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7112  extern int dcache_readdir(struct file *, struct dir_context *);
7113 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7114  extern int simple_setattr(struct dentry *, struct iattr *);
7115  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7116  extern int simple_statfs(struct dentry *, struct kstatfs *);
7117 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
7118 --- linux-3.13.10/include/linux/init_task.h     2014-01-22 20:39:11.000000000 +0000
7119 +++ linux-3.13.10-vs2.3.6.11/include/linux/init_task.h  2014-01-31 20:38:03.000000000 +0000
7120 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7121         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7122         INIT_CPUSET_SEQ(tsk)                                            \
7123         INIT_VTIME(tsk)                                                 \
7124 +       .xid            = 0,                                            \
7125 +       .vx_info        = NULL,                                         \
7126 +       .nid            = 0,                                            \
7127 +       .nx_info        = NULL,                                         \
7128  }
7129  
7130  
7131 diff -NurpP --minimal linux-3.13.10/include/linux/ipc.h linux-3.13.10-vs2.3.6.11/include/linux/ipc.h
7132 --- linux-3.13.10/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7133 +++ linux-3.13.10-vs2.3.6.11/include/linux/ipc.h        2014-01-31 20:38:03.000000000 +0000
7134 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7135         key_t           key;
7136         kuid_t          uid;
7137         kgid_t          gid;
7138 +       vxid_t          xid;
7139         kuid_t          cuid;
7140         kgid_t          cgid;
7141         umode_t         mode; 
7142 diff -NurpP --minimal linux-3.13.10/include/linux/memcontrol.h linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h
7143 --- linux-3.13.10/include/linux/memcontrol.h    2013-11-25 15:47:01.000000000 +0000
7144 +++ linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7145 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7146  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7147  extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7148  
7149 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7150 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7151 +
7152 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7153 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7154 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7155 +
7156  static inline
7157  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7158  {
7159 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
7160 --- linux-3.13.10/include/linux/mm_types.h      2014-01-22 20:39:11.000000000 +0000
7161 +++ linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h   2014-01-31 20:38:03.000000000 +0000
7162 @@ -397,6 +397,7 @@ struct mm_struct {
7163  
7164         /* Architecture-specific MM context */
7165         mm_context_t context;
7166 +       struct vx_info *mm_vx_info;
7167  
7168         unsigned long flags; /* Must use atomic bitops to access the bits */
7169  
7170 diff -NurpP --minimal linux-3.13.10/include/linux/mount.h linux-3.13.10-vs2.3.6.11/include/linux/mount.h
7171 --- linux-3.13.10/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7172 +++ linux-3.13.10-vs2.3.6.11/include/linux/mount.h      2014-01-31 20:38:03.000000000 +0000
7173 @@ -52,6 +52,9 @@ struct mnt_namespace;
7174  #define MNT_DOOMED             0x1000000
7175  #define MNT_SYNC_UMOUNT                0x2000000
7176  
7177 +#define MNT_TAGID      0x10000
7178 +#define MNT_NOTAG      0x20000
7179 +
7180  struct vfsmount {
7181         struct dentry *mnt_root;        /* root of the mounted tree */
7182         struct super_block *mnt_sb;     /* pointer to superblock */
7183 diff -NurpP --minimal linux-3.13.10/include/linux/net.h linux-3.13.10-vs2.3.6.11/include/linux/net.h
7184 --- linux-3.13.10/include/linux/net.h   2014-01-22 20:39:11.000000000 +0000
7185 +++ linux-3.13.10-vs2.3.6.11/include/linux/net.h        2014-01-31 20:38:03.000000000 +0000
7186 @@ -39,6 +39,7 @@ struct net;
7187  #define SOCK_PASSCRED          3
7188  #define SOCK_PASSSEC           4
7189  #define SOCK_EXTERNALLY_ALLOCATED 5
7190 +#define SOCK_USER_SOCKET       6
7191  
7192  #ifndef ARCH_HAS_SOCKET_TYPES
7193  /**
7194 diff -NurpP --minimal linux-3.13.10/include/linux/netdevice.h linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h
7195 --- linux-3.13.10/include/linux/netdevice.h     2014-04-17 01:12:37.000000000 +0000
7196 +++ linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h  2014-03-12 15:51:07.000000000 +0000
7197 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7198  
7199  struct net_device *dev_get_by_index(struct net *net, int ifindex);
7200  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7201 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7202  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7203  int netdev_get_name(struct net *net, char *name, int ifindex);
7204  int dev_restart(struct net_device *dev);
7205 diff -NurpP --minimal linux-3.13.10/include/linux/nsproxy.h linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h
7206 --- linux-3.13.10/include/linux/nsproxy.h       2013-11-25 15:45:06.000000000 +0000
7207 +++ linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h    2014-01-31 20:38:03.000000000 +0000
7208 @@ -3,6 +3,7 @@
7209  
7210  #include <linux/spinlock.h>
7211  #include <linux/sched.h>
7212 +#include <linux/vserver/debug.h>
7213  
7214  struct mnt_namespace;
7215  struct uts_namespace;
7216 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7217  }
7218  
7219  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7220 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7221  void exit_task_namespaces(struct task_struct *tsk);
7222  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7223  void free_nsproxy(struct nsproxy *ns);
7224 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7225         struct cred *, struct fs_struct *);
7226  int __init nsproxy_cache_init(void);
7227  
7228 -static inline void put_nsproxy(struct nsproxy *ns)
7229 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7230 +
7231 +static inline void __get_nsproxy(struct nsproxy *ns,
7232 +       const char *_file, int _line)
7233  {
7234 -       if (atomic_dec_and_test(&ns->count)) {
7235 -               free_nsproxy(ns);
7236 -       }
7237 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7238 +               ns, atomic_read(&ns->count), _file, _line);
7239 +       atomic_inc(&ns->count);
7240  }
7241  
7242 -static inline void get_nsproxy(struct nsproxy *ns)
7243 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7244 +
7245 +static inline void __put_nsproxy(struct nsproxy *ns,
7246 +       const char *_file, int _line)
7247  {
7248 -       atomic_inc(&ns->count);
7249 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7250 +               ns, atomic_read(&ns->count), _file, _line);
7251 +       if (atomic_dec_and_test(&ns->count)) {
7252 +               free_nsproxy(ns);
7253 +       }
7254  }
7255  
7256  #endif
7257 diff -NurpP --minimal linux-3.13.10/include/linux/pid.h linux-3.13.10-vs2.3.6.11/include/linux/pid.h
7258 --- linux-3.13.10/include/linux/pid.h   2013-11-25 15:45:06.000000000 +0000
7259 +++ linux-3.13.10-vs2.3.6.11/include/linux/pid.h        2014-01-31 20:38:03.000000000 +0000
7260 @@ -8,7 +8,8 @@ enum pid_type
7261         PIDTYPE_PID,
7262         PIDTYPE_PGID,
7263         PIDTYPE_SID,
7264 -       PIDTYPE_MAX
7265 +       PIDTYPE_MAX,
7266 +       PIDTYPE_REALPID
7267  };
7268  
7269  /*
7270 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7271  }
7272  
7273  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7274 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7275  pid_t pid_vnr(struct pid *pid);
7276  
7277  #define do_each_pid_task(pid, type, task)                              \
7278 diff -NurpP --minimal linux-3.13.10/include/linux/quotaops.h linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h
7279 --- linux-3.13.10/include/linux/quotaops.h      2013-11-25 15:47:02.000000000 +0000
7280 +++ linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h   2014-01-31 20:38:03.000000000 +0000
7281 @@ -8,6 +8,7 @@
7282  #define _LINUX_QUOTAOPS_
7283  
7284  #include <linux/fs.h>
7285 +#include <linux/vs_dlimit.h>
7286  
7287  #define DQUOT_SPACE_WARN       0x1
7288  #define DQUOT_SPACE_RESERVE    0x2
7289 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7290  
7291  static inline int dquot_alloc_inode(const struct inode *inode)
7292  {
7293 -       return 0;
7294 +       return dl_alloc_inode(inode);
7295  }
7296  
7297  static inline void dquot_free_inode(const struct inode *inode)
7298  {
7299 +       dl_free_inode(inode);
7300  }
7301  
7302  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7303 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7304  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7305                 int flags)
7306  {
7307 +       int ret = 0;
7308 +
7309 +       if ((ret = dl_alloc_space(inode, number)))
7310 +               return ret;
7311         if (!(flags & DQUOT_SPACE_RESERVE))
7312                 inode_add_bytes(inode, number);
7313         return 0;
7314 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7315  {
7316         if (!(flags & DQUOT_SPACE_RESERVE))
7317                 inode_sub_bytes(inode, number);
7318 +       dl_free_space(inode, number);
7319  }
7320  
7321  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7322 diff -NurpP --minimal linux-3.13.10/include/linux/sched.h linux-3.13.10-vs2.3.6.11/include/linux/sched.h
7323 --- linux-3.13.10/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7324 +++ linux-3.13.10-vs2.3.6.11/include/linux/sched.h      2014-01-31 20:38:03.000000000 +0000
7325 @@ -1237,6 +1237,14 @@ struct task_struct {
7326  #endif
7327         struct seccomp seccomp;
7328  
7329 +/* vserver context data */
7330 +       struct vx_info *vx_info;
7331 +       struct nx_info *nx_info;
7332 +
7333 +       vxid_t xid;
7334 +       vnid_t nid;
7335 +       vtag_t tag;
7336 +
7337  /* Thread group tracking */
7338         u32 parent_exec_id;
7339         u32 self_exec_id;
7340 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7341  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7342                         struct pid_namespace *ns);
7343  
7344 +#include <linux/vserver/base.h>
7345 +#include <linux/vserver/context.h>
7346 +#include <linux/vserver/debug.h>
7347 +#include <linux/vserver/pid.h>
7348 +
7349  static inline pid_t task_pid_nr(struct task_struct *tsk)
7350  {
7351         return tsk->pid;
7352 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7353  
7354  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7355  {
7356 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7357 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7358 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7359  }
7360  
7361  
7362 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7363  
7364  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7365  {
7366 -       return pid_vnr(task_tgid(tsk));
7367 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7368  }
7369  
7370  
7371 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
7372 --- linux-3.13.10/include/linux/shmem_fs.h      2014-01-22 20:39:11.000000000 +0000
7373 +++ linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h   2014-01-31 20:38:03.000000000 +0000
7374 @@ -9,6 +9,9 @@
7375  
7376  /* inode in-kernel data */
7377  
7378 +#define TMPFS_SUPER_MAGIC      0x01021994
7379 +
7380 +
7381  struct shmem_inode_info {
7382         spinlock_t              lock;
7383         unsigned long           flags;
7384 diff -NurpP --minimal linux-3.13.10/include/linux/stat.h linux-3.13.10-vs2.3.6.11/include/linux/stat.h
7385 --- linux-3.13.10/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
7386 +++ linux-3.13.10-vs2.3.6.11/include/linux/stat.h       2014-01-31 20:38:03.000000000 +0000
7387 @@ -25,6 +25,7 @@ struct kstat {
7388         unsigned int    nlink;
7389         kuid_t          uid;
7390         kgid_t          gid;
7391 +       ktag_t          tag;
7392         dev_t           rdev;
7393         loff_t          size;
7394         struct timespec  atime;
7395 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
7396 --- linux-3.13.10/include/linux/sunrpc/auth.h   2013-11-25 15:47:02.000000000 +0000
7397 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h        2014-01-31 20:38:03.000000000 +0000
7398 @@ -36,6 +36,7 @@ enum {
7399  struct auth_cred {
7400         kuid_t  uid;
7401         kgid_t  gid;
7402 +       ktag_t  tag;
7403         struct group_info *group_info;
7404         const char *principal;
7405         unsigned long ac_flags;
7406 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
7407 --- linux-3.13.10/include/linux/sunrpc/clnt.h   2014-01-22 20:39:11.000000000 +0000
7408 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h        2014-01-31 20:38:03.000000000 +0000
7409 @@ -51,7 +51,8 @@ struct rpc_clnt {
7410                                 cl_discrtry : 1,/* disconnect before retry */
7411                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7412                                 cl_autobind : 1,/* use getport() */
7413 -                               cl_chatty   : 1;/* be verbose */
7414 +                               cl_chatty   : 1,/* be verbose */
7415 +                               cl_tag      : 1;/* context tagging */
7416  
7417         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7418         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7419 diff -NurpP --minimal linux-3.13.10/include/linux/types.h linux-3.13.10-vs2.3.6.11/include/linux/types.h
7420 --- linux-3.13.10/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7421 +++ linux-3.13.10-vs2.3.6.11/include/linux/types.h      2014-01-31 20:38:03.000000000 +0000
7422 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7423  typedef __kernel_gid32_t       gid_t;
7424  typedef __kernel_uid16_t        uid16_t;
7425  typedef __kernel_gid16_t        gid16_t;
7426 +typedef unsigned int           vxid_t;
7427 +typedef unsigned int           vnid_t;
7428 +typedef unsigned int           vtag_t;
7429  
7430  typedef unsigned long          uintptr_t;
7431  
7432 diff -NurpP --minimal linux-3.13.10/include/linux/uidgid.h linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h
7433 --- linux-3.13.10/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
7434 +++ linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h     2014-01-31 20:38:03.000000000 +0000
7435 @@ -23,13 +23,17 @@ typedef struct {
7436         uid_t val;
7437  } kuid_t;
7438  
7439 -
7440  typedef struct {
7441         gid_t val;
7442  } kgid_t;
7443  
7444 +typedef struct {
7445 +       vtag_t val;
7446 +} ktag_t;
7447 +
7448  #define KUIDT_INIT(value) (kuid_t){ value }
7449  #define KGIDT_INIT(value) (kgid_t){ value }
7450 +#define KTAGT_INIT(value) (ktag_t){ value }
7451  
7452  static inline uid_t __kuid_val(kuid_t uid)
7453  {
7454 @@ -41,11 +45,18 @@ static inline gid_t __kgid_val(kgid_t gi
7455         return gid.val;
7456  }
7457  
7458 +static inline vtag_t __ktag_val(ktag_t tag)
7459 +{
7460 +       return tag.val;
7461 +}
7462 +
7463  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7464  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7465 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7466  
7467  #define INVALID_UID KUIDT_INIT(-1)
7468  #define INVALID_GID KGIDT_INIT(-1)
7469 +#define INVALID_TAG KTAGT_INIT(-1)
7470  
7471  static inline bool uid_eq(kuid_t left, kuid_t right)
7472  {
7473 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7474         return __kgid_val(left) == __kgid_val(right);
7475  }
7476  
7477 +static inline bool tag_eq(ktag_t left, ktag_t right)
7478 +{
7479 +       return __ktag_val(left) == __ktag_val(right);
7480 +}
7481 +
7482  static inline bool uid_gt(kuid_t left, kuid_t right)
7483  {
7484         return __kuid_val(left) > __kuid_val(right);
7485 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7486         return !gid_eq(gid, INVALID_GID);
7487  }
7488  
7489 +static inline bool tag_valid(ktag_t tag)
7490 +{
7491 +       return !tag_eq(tag, INVALID_TAG);
7492 +}
7493 +
7494  #ifdef CONFIG_USER_NS
7495  
7496  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7497  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7498 +extern ktag_t make_ktag(struct user_namespace *from, gid_t gid);
7499  
7500  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7501  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7502 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7503 +
7504  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7505  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7506  
7507 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7508         return KGIDT_INIT(gid);
7509  }
7510  
7511 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7512 +{
7513 +       return KTAGT_INIT(tag);
7514 +}
7515 +
7516  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7517  {
7518         return __kuid_val(kuid);
7519 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7520         return __kgid_val(kgid);
7521  }
7522  
7523 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7524 +{
7525 +       return __ktag_val(ktag);
7526 +}
7527 +
7528  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7529  {
7530         uid_t uid = from_kuid(to, kuid);
7531 diff -NurpP --minimal linux-3.13.10/include/linux/vroot.h linux-3.13.10-vs2.3.6.11/include/linux/vroot.h
7532 --- linux-3.13.10/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7533 +++ linux-3.13.10-vs2.3.6.11/include/linux/vroot.h      2014-01-31 20:38:03.000000000 +0000
7534 @@ -0,0 +1,51 @@
7535 +
7536 +/*
7537 + * include/linux/vroot.h
7538 + *
7539 + * written by Herbert Pötzl, 9/11/2002
7540 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7541 + *
7542 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7543 + * Redistribution of this file is permitted under the
7544 + * GNU General Public License.
7545 + */
7546 +
7547 +#ifndef _LINUX_VROOT_H
7548 +#define _LINUX_VROOT_H
7549 +
7550 +
7551 +#ifdef __KERNEL__
7552 +
7553 +/* Possible states of device */
7554 +enum {
7555 +       Vr_unbound,
7556 +       Vr_bound,
7557 +};
7558 +
7559 +struct vroot_device {
7560 +       int             vr_number;
7561 +       int             vr_refcnt;
7562 +
7563 +       struct semaphore        vr_ctl_mutex;
7564 +       struct block_device    *vr_device;
7565 +       int                     vr_state;
7566 +};
7567 +
7568 +
7569 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7570 +
7571 +extern int register_vroot_grb(vroot_grb_func *);
7572 +extern int unregister_vroot_grb(vroot_grb_func *);
7573 +
7574 +#endif /* __KERNEL__ */
7575 +
7576 +#define MAX_VROOT_DEFAULT      8
7577 +
7578 +/*
7579 + * IOCTL commands --- we will commandeer 0x56 ('V')
7580 + */
7581 +
7582 +#define VROOT_SET_DEV          0x5600
7583 +#define VROOT_CLR_DEV          0x5601
7584 +
7585 +#endif /* _LINUX_VROOT_H */
7586 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
7587 --- linux-3.13.10/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7588 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h    2014-01-31 20:38:03.000000000 +0000
7589 @@ -0,0 +1,10 @@
7590 +#ifndef _VS_BASE_H
7591 +#define _VS_BASE_H
7592 +
7593 +#include "vserver/base.h"
7594 +#include "vserver/check.h"
7595 +#include "vserver/debug.h"
7596 +
7597 +#else
7598 +#warning duplicate inclusion
7599 +#endif
7600 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
7601 --- linux-3.13.10/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7602 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7603 @@ -0,0 +1,242 @@
7604 +#ifndef _VS_CONTEXT_H
7605 +#define _VS_CONTEXT_H
7606 +
7607 +#include "vserver/base.h"
7608 +#include "vserver/check.h"
7609 +#include "vserver/context.h"
7610 +#include "vserver/history.h"
7611 +#include "vserver/debug.h"
7612 +
7613 +#include <linux/sched.h>
7614 +
7615 +
7616 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7617 +
7618 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7619 +       const char *_file, int _line, void *_here)
7620 +{
7621 +       if (!vxi)
7622 +               return NULL;
7623 +
7624 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7625 +               vxi, vxi ? vxi->vx_id : 0,
7626 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7627 +               _file, _line);
7628 +       __vxh_get_vx_info(vxi, _here);
7629 +
7630 +       atomic_inc(&vxi->vx_usecnt);
7631 +       return vxi;
7632 +}
7633 +
7634 +
7635 +extern void free_vx_info(struct vx_info *);
7636 +
7637 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7638 +
7639 +static inline void __put_vx_info(struct vx_info *vxi,
7640 +       const char *_file, int _line, void *_here)
7641 +{
7642 +       if (!vxi)
7643 +               return;
7644 +
7645 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7646 +               vxi, vxi ? vxi->vx_id : 0,
7647 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7648 +               _file, _line);
7649 +       __vxh_put_vx_info(vxi, _here);
7650 +
7651 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7652 +               free_vx_info(vxi);
7653 +}
7654 +
7655 +
7656 +#define init_vx_info(p, i) \
7657 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7658 +
7659 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7660 +       const char *_file, int _line, void *_here)
7661 +{
7662 +       if (vxi) {
7663 +               vxlprintk(VXD_CBIT(xid, 3),
7664 +                       "init_vx_info(%p[#%d.%d])",
7665 +                       vxi, vxi ? vxi->vx_id : 0,
7666 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7667 +                       _file, _line);
7668 +               __vxh_init_vx_info(vxi, vxp, _here);
7669 +
7670 +               atomic_inc(&vxi->vx_usecnt);
7671 +       }
7672 +       *vxp = vxi;
7673 +}
7674 +
7675 +
7676 +#define set_vx_info(p, i) \
7677 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7678 +
7679 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7680 +       const char *_file, int _line, void *_here)
7681 +{
7682 +       struct vx_info *vxo;
7683 +
7684 +       if (!vxi)
7685 +               return;
7686 +
7687 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7688 +               vxi, vxi ? vxi->vx_id : 0,
7689 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7690 +               _file, _line);
7691 +       __vxh_set_vx_info(vxi, vxp, _here);
7692 +
7693 +       atomic_inc(&vxi->vx_usecnt);
7694 +       vxo = xchg(vxp, vxi);
7695 +       BUG_ON(vxo);
7696 +}
7697 +
7698 +
7699 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7700 +
7701 +static inline void __clr_vx_info(struct vx_info **vxp,
7702 +       const char *_file, int _line, void *_here)
7703 +{
7704 +       struct vx_info *vxo;
7705 +
7706 +       vxo = xchg(vxp, NULL);
7707 +       if (!vxo)
7708 +               return;
7709 +
7710 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7711 +               vxo, vxo ? vxo->vx_id : 0,
7712 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7713 +               _file, _line);
7714 +       __vxh_clr_vx_info(vxo, vxp, _here);
7715 +
7716 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7717 +               free_vx_info(vxo);
7718 +}
7719 +
7720 +
7721 +#define claim_vx_info(v, p) \
7722 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7723 +
7724 +static inline void __claim_vx_info(struct vx_info *vxi,
7725 +       struct task_struct *task,
7726 +       const char *_file, int _line, void *_here)
7727 +{
7728 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7729 +               vxi, vxi ? vxi->vx_id : 0,
7730 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7731 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7732 +               task, _file, _line);
7733 +       __vxh_claim_vx_info(vxi, task, _here);
7734 +
7735 +       atomic_inc(&vxi->vx_tasks);
7736 +}
7737 +
7738 +
7739 +extern void unhash_vx_info(struct vx_info *);
7740 +
7741 +#define release_vx_info(v, p) \
7742 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7743 +
7744 +static inline void __release_vx_info(struct vx_info *vxi,
7745 +       struct task_struct *task,
7746 +       const char *_file, int _line, void *_here)
7747 +{
7748 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7749 +               vxi, vxi ? vxi->vx_id : 0,
7750 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7751 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7752 +               task, _file, _line);
7753 +       __vxh_release_vx_info(vxi, task, _here);
7754 +
7755 +       might_sleep();
7756 +
7757 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7758 +               unhash_vx_info(vxi);
7759 +}
7760 +
7761 +
7762 +#define task_get_vx_info(p) \
7763 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7764 +
7765 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7766 +       const char *_file, int _line, void *_here)
7767 +{
7768 +       struct vx_info *vxi;
7769 +
7770 +       task_lock(p);
7771 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7772 +               p, _file, _line);
7773 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7774 +       task_unlock(p);
7775 +       return vxi;
7776 +}
7777 +
7778 +
7779 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7780 +{
7781 +       if (waitqueue_active(&vxi->vx_wait))
7782 +               wake_up_interruptible(&vxi->vx_wait);
7783 +}
7784 +
7785 +
7786 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7787 +
7788 +static inline void __enter_vx_info(struct vx_info *vxi,
7789 +       struct vx_info_save *vxis, const char *_file, int _line)
7790 +{
7791 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7792 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7793 +               current->xid, current->vx_info, _file, _line);
7794 +       vxis->vxi = xchg(&current->vx_info, vxi);
7795 +       vxis->xid = current->xid;
7796 +       current->xid = vxi ? vxi->vx_id : 0;
7797 +}
7798 +
7799 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7800 +
7801 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7802 +       const char *_file, int _line)
7803 +{
7804 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7805 +               vxis, vxis->xid, vxis->vxi, current,
7806 +               current->xid, current->vx_info, _file, _line);
7807 +       (void)xchg(&current->vx_info, vxis->vxi);
7808 +       current->xid = vxis->xid;
7809 +}
7810 +
7811 +
7812 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7813 +{
7814 +       vxis->vxi = xchg(&current->vx_info, NULL);
7815 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7816 +}
7817 +
7818 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7819 +{
7820 +       (void)xchg(&current->xid, vxis->xid);
7821 +       (void)xchg(&current->vx_info, vxis->vxi);
7822 +}
7823 +
7824 +#define task_is_init(p) \
7825 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7826 +
7827 +static inline int __task_is_init(struct task_struct *p,
7828 +       const char *_file, int _line, void *_here)
7829 +{
7830 +       int is_init = is_global_init(p);
7831 +
7832 +       task_lock(p);
7833 +       if (p->vx_info)
7834 +               is_init = p->vx_info->vx_initpid == p->pid;
7835 +       task_unlock(p);
7836 +       return is_init;
7837 +}
7838 +
7839 +extern void exit_vx_info(struct task_struct *, int);
7840 +extern void exit_vx_info_early(struct task_struct *, int);
7841 +
7842 +
7843 +#else
7844 +#warning duplicate inclusion
7845 +#endif
7846 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
7847 --- linux-3.13.10/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7848 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h   2014-01-31 20:38:03.000000000 +0000
7849 @@ -0,0 +1,48 @@
7850 +#ifndef _VS_COWBL_H
7851 +#define _VS_COWBL_H
7852 +
7853 +#include <linux/fs.h>
7854 +#include <linux/dcache.h>
7855 +#include <linux/namei.h>
7856 +#include <linux/slab.h>
7857 +
7858 +extern struct dentry *cow_break_link(const char *pathname);
7859 +
7860 +static inline int cow_check_and_break(struct path *path)
7861 +{
7862 +       struct inode *inode = path->dentry->d_inode;
7863 +       int error = 0;
7864 +
7865 +       /* do we need this check? */
7866 +       if (IS_RDONLY(inode))
7867 +               return -EROFS;
7868 +
7869 +       if (IS_COW(inode)) {
7870 +               if (IS_COW_LINK(inode)) {
7871 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7872 +                       char *pp, *buf;
7873 +
7874 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7875 +                       if (!buf) {
7876 +                               return -ENOMEM;
7877 +                       }
7878 +                       pp = d_path(path, buf, PATH_MAX);
7879 +                       new_dentry = cow_break_link(pp);
7880 +                       kfree(buf);
7881 +                       if (!IS_ERR(new_dentry)) {
7882 +                               path->dentry = new_dentry;
7883 +                               dput(old_dentry);
7884 +                       } else
7885 +                               error = PTR_ERR(new_dentry);
7886 +               } else {
7887 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7888 +                       inode->i_ctime = CURRENT_TIME;
7889 +                       mark_inode_dirty(inode);
7890 +               }
7891 +       }
7892 +       return error;
7893 +}
7894 +
7895 +#else
7896 +#warning duplicate inclusion
7897 +#endif
7898 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
7899 --- linux-3.13.10/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7900 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h   2014-01-31 20:38:03.000000000 +0000
7901 @@ -0,0 +1,50 @@
7902 +#ifndef _VS_CVIRT_H
7903 +#define _VS_CVIRT_H
7904 +
7905 +#include "vserver/cvirt.h"
7906 +#include "vserver/context.h"
7907 +#include "vserver/base.h"
7908 +#include "vserver/check.h"
7909 +#include "vserver/debug.h"
7910 +
7911 +
7912 +static inline void vx_activate_task(struct task_struct *p)
7913 +{
7914 +       struct vx_info *vxi;
7915 +
7916 +       if ((vxi = p->vx_info)) {
7917 +               vx_update_load(vxi);
7918 +               atomic_inc(&vxi->cvirt.nr_running);
7919 +       }
7920 +}
7921 +
7922 +static inline void vx_deactivate_task(struct task_struct *p)
7923 +{
7924 +       struct vx_info *vxi;
7925 +
7926 +       if ((vxi = p->vx_info)) {
7927 +               vx_update_load(vxi);
7928 +               atomic_dec(&vxi->cvirt.nr_running);
7929 +       }
7930 +}
7931 +
7932 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7933 +{
7934 +       struct vx_info *vxi;
7935 +
7936 +       if ((vxi = p->vx_info))
7937 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7938 +}
7939 +
7940 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7941 +{
7942 +       struct vx_info *vxi;
7943 +
7944 +       if ((vxi = p->vx_info))
7945 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7946 +}
7947 +
7948 +
7949 +#else
7950 +#warning duplicate inclusion
7951 +#endif
7952 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
7953 --- linux-3.13.10/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
7954 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h  2014-01-31 20:38:03.000000000 +0000
7955 @@ -0,0 +1,45 @@
7956 +#ifndef _VS_DEVICE_H
7957 +#define _VS_DEVICE_H
7958 +
7959 +#include "vserver/base.h"
7960 +#include "vserver/device.h"
7961 +#include "vserver/debug.h"
7962 +
7963 +
7964 +#ifdef CONFIG_VSERVER_DEVICE
7965 +
7966 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7967 +
7968 +#define vs_device_perm(v, d, m, p) \
7969 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7970 +
7971 +#else
7972 +
7973 +static inline
7974 +int vs_map_device(struct vx_info *vxi,
7975 +       dev_t device, dev_t *target, umode_t mode)
7976 +{
7977 +       if (target)
7978 +               *target = device;
7979 +       return ~0;
7980 +}
7981 +
7982 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7983 +
7984 +#endif
7985 +
7986 +
7987 +#define vs_map_chrdev(d, t, p) \
7988 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7989 +#define vs_map_blkdev(d, t, p) \
7990 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7991 +
7992 +#define vs_chrdev_perm(d, p) \
7993 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7994 +#define vs_blkdev_perm(d, p) \
7995 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
7996 +
7997 +
7998 +#else
7999 +#warning duplicate inclusion
8000 +#endif
8001 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
8002 --- linux-3.13.10/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8003 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h  2014-01-31 20:38:03.000000000 +0000
8004 @@ -0,0 +1,215 @@
8005 +#ifndef _VS_DLIMIT_H
8006 +#define _VS_DLIMIT_H
8007 +
8008 +#include <linux/fs.h>
8009 +
8010 +#include "vserver/dlimit.h"
8011 +#include "vserver/base.h"
8012 +#include "vserver/debug.h"
8013 +
8014 +
8015 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8016 +
8017 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8018 +       const char *_file, int _line)
8019 +{
8020 +       if (!dli)
8021 +               return NULL;
8022 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8023 +               dli, dli ? dli->dl_tag : 0,
8024 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8025 +               _file, _line);
8026 +       atomic_inc(&dli->dl_usecnt);
8027 +       return dli;
8028 +}
8029 +
8030 +
8031 +#define free_dl_info(i) \
8032 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8033 +
8034 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8035 +
8036 +static inline void __put_dl_info(struct dl_info *dli,
8037 +       const char *_file, int _line)
8038 +{
8039 +       if (!dli)
8040 +               return;
8041 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8042 +               dli, dli ? dli->dl_tag : 0,
8043 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8044 +               _file, _line);
8045 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8046 +               free_dl_info(dli);
8047 +}
8048 +
8049 +
8050 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8051 +
8052 +static inline int __dl_alloc_space(struct super_block *sb,
8053 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8054 +{
8055 +       struct dl_info *dli = NULL;
8056 +       int ret = 0;
8057 +
8058 +       if (nr == 0)
8059 +               goto out;
8060 +       dli = locate_dl_info(sb, tag);
8061 +       if (!dli)
8062 +               goto out;
8063 +
8064 +       spin_lock(&dli->dl_lock);
8065 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8066 +       if (!ret)
8067 +               dli->dl_space_used += nr;
8068 +       spin_unlock(&dli->dl_lock);
8069 +       put_dl_info(dli);
8070 +out:
8071 +       vxlprintk(VXD_CBIT(dlim, 1),
8072 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8073 +               sb, tag, __dlimit_char(dli), (long long)nr,
8074 +               ret, file, line);
8075 +       return ret ? -ENOSPC : 0;
8076 +}
8077 +
8078 +static inline void __dl_free_space(struct super_block *sb,
8079 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8080 +{
8081 +       struct dl_info *dli = NULL;
8082 +
8083 +       if (nr == 0)
8084 +               goto out;
8085 +       dli = locate_dl_info(sb, tag);
8086 +       if (!dli)
8087 +               goto out;
8088 +
8089 +       spin_lock(&dli->dl_lock);
8090 +       if (dli->dl_space_used > nr)
8091 +               dli->dl_space_used -= nr;
8092 +       else
8093 +               dli->dl_space_used = 0;
8094 +       spin_unlock(&dli->dl_lock);
8095 +       put_dl_info(dli);
8096 +out:
8097 +       vxlprintk(VXD_CBIT(dlim, 1),
8098 +               "FREE  (%p,#%d)%c %lld bytes",
8099 +               sb, tag, __dlimit_char(dli), (long long)nr,
8100 +               _file, _line);
8101 +}
8102 +
8103 +static inline int __dl_alloc_inode(struct super_block *sb,
8104 +       vtag_t tag, const char *_file, int _line)
8105 +{
8106 +       struct dl_info *dli;
8107 +       int ret = 0;
8108 +
8109 +       dli = locate_dl_info(sb, tag);
8110 +       if (!dli)
8111 +               goto out;
8112 +
8113 +       spin_lock(&dli->dl_lock);
8114 +       dli->dl_inodes_used++;
8115 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8116 +       spin_unlock(&dli->dl_lock);
8117 +       put_dl_info(dli);
8118 +out:
8119 +       vxlprintk(VXD_CBIT(dlim, 0),
8120 +               "ALLOC (%p,#%d)%c inode (%d)",
8121 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8122 +       return ret ? -ENOSPC : 0;
8123 +}
8124 +
8125 +static inline void __dl_free_inode(struct super_block *sb,
8126 +       vtag_t tag, const char *_file, int _line)
8127 +{
8128 +       struct dl_info *dli;
8129 +
8130 +       dli = locate_dl_info(sb, tag);
8131 +       if (!dli)
8132 +               goto out;
8133 +
8134 +       spin_lock(&dli->dl_lock);
8135 +       if (dli->dl_inodes_used > 1)
8136 +               dli->dl_inodes_used--;
8137 +       else
8138 +               dli->dl_inodes_used = 0;
8139 +       spin_unlock(&dli->dl_lock);
8140 +       put_dl_info(dli);
8141 +out:
8142 +       vxlprintk(VXD_CBIT(dlim, 0),
8143 +               "FREE  (%p,#%d)%c inode",
8144 +               sb, tag, __dlimit_char(dli), _file, _line);
8145 +}
8146 +
8147 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8148 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8149 +       const char *_file, int _line)
8150 +{
8151 +       struct dl_info *dli;
8152 +       uint64_t broot, bfree;
8153 +
8154 +       dli = locate_dl_info(sb, tag);
8155 +       if (!dli)
8156 +               return;
8157 +
8158 +       spin_lock(&dli->dl_lock);
8159 +       broot = (dli->dl_space_total -
8160 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8161 +               >> sb->s_blocksize_bits;
8162 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8163 +                       >> sb->s_blocksize_bits;
8164 +       spin_unlock(&dli->dl_lock);
8165 +
8166 +       vxlprintk(VXD_CBIT(dlim, 2),
8167 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8168 +               (long long)bfree, (long long)broot,
8169 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8170 +               _file, _line);
8171 +       if (free_blocks) {
8172 +               if (*free_blocks > bfree)
8173 +                       *free_blocks = bfree;
8174 +       }
8175 +       if (root_blocks) {
8176 +               if (*root_blocks > broot)
8177 +                       *root_blocks = broot;
8178 +       }
8179 +       put_dl_info(dli);
8180 +}
8181 +
8182 +#define dl_prealloc_space(in, bytes) \
8183 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8184 +               __FILE__, __LINE__ )
8185 +
8186 +#define dl_alloc_space(in, bytes) \
8187 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8188 +               __FILE__, __LINE__ )
8189 +
8190 +#define dl_reserve_space(in, bytes) \
8191 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8192 +               __FILE__, __LINE__ )
8193 +
8194 +#define dl_claim_space(in, bytes) (0)
8195 +
8196 +#define dl_release_space(in, bytes) \
8197 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8198 +               __FILE__, __LINE__ )
8199 +
8200 +#define dl_free_space(in, bytes) \
8201 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8202 +               __FILE__, __LINE__ )
8203 +
8204 +
8205 +
8206 +#define dl_alloc_inode(in) \
8207 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8208 +
8209 +#define dl_free_inode(in) \
8210 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8211 +
8212 +
8213 +#define dl_adjust_block(sb, tag, fb, rb) \
8214 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8215 +
8216 +
8217 +#else
8218 +#warning duplicate inclusion
8219 +#endif
8220 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
8221 --- linux-3.13.10/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8222 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h    2014-02-01 00:32:45.000000000 +0000
8223 @@ -0,0 +1,364 @@
8224 +#ifndef _VS_INET_H
8225 +#define _VS_INET_H
8226 +
8227 +#include "vserver/base.h"
8228 +#include "vserver/network.h"
8229 +#include "vserver/debug.h"
8230 +
8231 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8232 +
8233 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8234 +                       NIPQUAD((a)->mask), (a)->type
8235 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8236 +
8237 +#define NIPQUAD(addr) \
8238 +       ((unsigned char *)&addr)[0], \
8239 +       ((unsigned char *)&addr)[1], \
8240 +       ((unsigned char *)&addr)[2], \
8241 +       ((unsigned char *)&addr)[3]
8242 +
8243 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8244 +
8245 +
8246 +static inline
8247 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8248 +{
8249 +       __be32 ip = nxa->ip[0].s_addr;
8250 +       __be32 mask = nxa->mask.s_addr;
8251 +       __be32 bcast = ip | ~mask;
8252 +       int ret = 0;
8253 +
8254 +       switch (nxa->type & tmask) {
8255 +       case NXA_TYPE_MASK:
8256 +               ret = (ip == (addr & mask));
8257 +               break;
8258 +       case NXA_TYPE_ADDR:
8259 +               ret = 3;
8260 +               if (addr == ip)
8261 +                       break;
8262 +               /* fall through to broadcast */
8263 +       case NXA_MOD_BCAST:
8264 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8265 +               break;
8266 +       case NXA_TYPE_RANGE:
8267 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8268 +                       (nxa->ip[1].s_addr > addr));
8269 +               break;
8270 +       case NXA_TYPE_ANY:
8271 +               ret = 2;
8272 +               break;
8273 +       }
8274 +
8275 +       vxdprintk(VXD_CBIT(net, 0),
8276 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8277 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8278 +       return ret;
8279 +}
8280 +
8281 +static inline
8282 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8283 +{
8284 +       struct nx_addr_v4 *nxa;
8285 +       unsigned long irqflags;
8286 +       int ret = 1;
8287 +
8288 +       if (!nxi)
8289 +               goto out;
8290 +
8291 +       ret = 2;
8292 +       /* allow 127.0.0.1 when remapping lback */
8293 +       if ((tmask & NXA_LOOPBACK) &&
8294 +               (addr == IPI_LOOPBACK) &&
8295 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8296 +               goto out;
8297 +       ret = 3;
8298 +       /* check for lback address */
8299 +       if ((tmask & NXA_MOD_LBACK) &&
8300 +               (nxi->v4_lback.s_addr == addr))
8301 +               goto out;
8302 +       ret = 4;
8303 +       /* check for broadcast address */
8304 +       if ((tmask & NXA_MOD_BCAST) &&
8305 +               (nxi->v4_bcast.s_addr == addr))
8306 +               goto out;
8307 +       ret = 5;
8308 +
8309 +       /* check for v4 addresses */
8310 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8311 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8312 +               if (v4_addr_match(nxa, addr, tmask))
8313 +                       goto out_unlock;
8314 +       ret = 0;
8315 +out_unlock:
8316 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8317 +out:
8318 +       vxdprintk(VXD_CBIT(net, 0),
8319 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8320 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8321 +       return ret;
8322 +}
8323 +
8324 +static inline
8325 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8326 +{
8327 +       /* FIXME: needs full range checks */
8328 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8329 +}
8330 +
8331 +static inline
8332 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8333 +{
8334 +       struct nx_addr_v4 *ptr;
8335 +       unsigned long irqflags;
8336 +       int ret = 1;
8337 +
8338 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8339 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8340 +               if (v4_nx_addr_match(ptr, nxa, mask))
8341 +                       goto out_unlock;
8342 +       ret = 0;
8343 +out_unlock:
8344 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8345 +       return ret;
8346 +}
8347 +
8348 +#include <net/inet_sock.h>
8349 +
8350 +/*
8351 + *     Check if a given address matches for a socket
8352 + *
8353 + *     nxi:            the socket's nx_info if any
8354 + *     addr:           to be verified address
8355 + */
8356 +static inline
8357 +int v4_sock_addr_match (
8358 +       struct nx_info *nxi,
8359 +       struct inet_sock *inet,
8360 +       __be32 addr)
8361 +{
8362 +       __be32 saddr = inet->inet_rcv_saddr;
8363 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8364 +
8365 +       if (addr && (saddr == addr || bcast == addr))
8366 +               return 1;
8367 +       if (!saddr)
8368 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8369 +       return 0;
8370 +}
8371 +
8372 +
8373 +/* inet related checks and helpers */
8374 +
8375 +
8376 +struct in_ifaddr;
8377 +struct net_device;
8378 +struct sock;
8379 +
8380 +#ifdef CONFIG_INET
8381 +
8382 +#include <linux/netdevice.h>
8383 +#include <linux/inetdevice.h>
8384 +#include <net/inet_sock.h>
8385 +#include <net/inet_timewait_sock.h>
8386 +
8387 +
8388 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8389 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8390 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8391 +
8392 +
8393 +/*
8394 + *     check if address is covered by socket
8395 + *
8396 + *     sk:     the socket to check against
8397 + *     addr:   the address in question (must be != 0)
8398 + */
8399 +
8400 +static inline
8401 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8402 +{
8403 +       struct nx_info *nxi = sk->sk_nx_info;
8404 +       __be32 saddr = sk->sk_rcv_saddr;
8405 +
8406 +       vxdprintk(VXD_CBIT(net, 5),
8407 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8408 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8409 +               (sk->sk_socket?sk->sk_socket->flags:0));
8410 +
8411 +       if (saddr) {            /* direct address match */
8412 +               return v4_addr_match(nxa, saddr, -1);
8413 +       } else if (nxi) {       /* match against nx_info */
8414 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8415 +       } else {                /* unrestricted any socket */
8416 +               return 1;
8417 +       }
8418 +}
8419 +
8420 +
8421 +
8422 +static inline
8423 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8424 +{
8425 +       vxdprintk(VXD_CBIT(net, 1),
8426 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8427 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8428 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8429 +
8430 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8431 +               return 1;
8432 +       if (dev_in_nx_info(dev, nxi))
8433 +               return 1;
8434 +       return 0;
8435 +}
8436 +
8437 +
8438 +static inline
8439 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8440 +{
8441 +       if (!nxi)
8442 +               return 1;
8443 +       if (!ifa)
8444 +               return 0;
8445 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8446 +}
8447 +
8448 +static inline
8449 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8450 +{
8451 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8452 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8453 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8454 +
8455 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8456 +               return 1;
8457 +       if (v4_ifa_in_nx_info(ifa, nxi))
8458 +               return 1;
8459 +       return 0;
8460 +}
8461 +
8462 +
8463 +struct nx_v4_sock_addr {
8464 +       __be32 saddr;   /* Address used for validation */
8465 +       __be32 baddr;   /* Address used for socket bind */
8466 +};
8467 +
8468 +static inline
8469 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8470 +       struct nx_v4_sock_addr *nsa)
8471 +{
8472 +       struct sock *sk = &inet->sk;
8473 +       struct nx_info *nxi = sk->sk_nx_info;
8474 +       __be32 saddr = addr->sin_addr.s_addr;
8475 +       __be32 baddr = saddr;
8476 +
8477 +       vxdprintk(VXD_CBIT(net, 3),
8478 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8479 +               sk, sk->sk_nx_info, sk->sk_socket,
8480 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8481 +               NIPQUAD(saddr));
8482 +
8483 +       if (nxi) {
8484 +               if (saddr == INADDR_ANY) {
8485 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8486 +                               baddr = nxi->v4.ip[0].s_addr;
8487 +               } else if (saddr == IPI_LOOPBACK) {
8488 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8489 +                               baddr = nxi->v4_lback.s_addr;
8490 +               } else if (!ipv4_is_multicast(saddr) ||
8491 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8492 +                       /* normal address bind */
8493 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8494 +                               return -EADDRNOTAVAIL;
8495 +               }
8496 +       }
8497 +
8498 +       vxdprintk(VXD_CBIT(net, 3),
8499 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8500 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8501 +
8502 +       nsa->saddr = saddr;
8503 +       nsa->baddr = baddr;
8504 +       return 0;
8505 +}
8506 +
8507 +static inline
8508 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8509 +{
8510 +       inet->inet_saddr = nsa->baddr;
8511 +       inet->inet_rcv_saddr = nsa->baddr;
8512 +}
8513 +
8514 +
8515 +/*
8516 + *      helper to simplify inet_lookup_listener
8517 + *
8518 + *      nxi:   the socket's nx_info if any
8519 + *      addr:  to be verified address
8520 + *      saddr: socket address
8521 + */
8522 +static inline int v4_inet_addr_match (
8523 +       struct nx_info *nxi,
8524 +       __be32 addr,
8525 +       __be32 saddr)
8526 +{
8527 +       if (addr && (saddr == addr))
8528 +               return 1;
8529 +       if (!saddr)
8530 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8531 +       return 0;
8532 +}
8533 +
8534 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8535 +{
8536 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8537 +               (addr == nxi->v4_lback.s_addr))
8538 +               return IPI_LOOPBACK;
8539 +       return addr;
8540 +}
8541 +
8542 +static inline
8543 +int nx_info_has_v4(struct nx_info *nxi)
8544 +{
8545 +       if (!nxi)
8546 +               return 1;
8547 +       if (NX_IPV4(nxi))
8548 +               return 1;
8549 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8550 +               return 1;
8551 +       return 0;
8552 +}
8553 +
8554 +#else /* CONFIG_INET */
8555 +
8556 +static inline
8557 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8558 +{
8559 +       return 1;
8560 +}
8561 +
8562 +static inline
8563 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8564 +{
8565 +       return 1;
8566 +}
8567 +
8568 +static inline
8569 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8570 +{
8571 +       return 1;
8572 +}
8573 +
8574 +static inline
8575 +int nx_info_has_v4(struct nx_info *nxi)
8576 +{
8577 +       return 0;
8578 +}
8579 +
8580 +#endif /* CONFIG_INET */
8581 +
8582 +#define current_nx_info_has_v4() \
8583 +       nx_info_has_v4(current_nx_info())
8584 +
8585 +#else
8586 +// #warning duplicate inclusion
8587 +#endif
8588 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
8589 --- linux-3.13.10/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8590 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h   2014-02-01 00:35:02.000000000 +0000
8591 @@ -0,0 +1,257 @@
8592 +#ifndef _VS_INET6_H
8593 +#define _VS_INET6_H
8594 +
8595 +#include "vserver/base.h"
8596 +#include "vserver/network.h"
8597 +#include "vserver/debug.h"
8598 +
8599 +#include <net/ipv6.h>
8600 +
8601 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8602 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8603 +
8604 +
8605 +#ifdef CONFIG_IPV6
8606 +
8607 +static inline
8608 +int v6_addr_match(struct nx_addr_v6 *nxa,
8609 +       const struct in6_addr *addr, uint16_t mask)
8610 +{
8611 +       int ret = 0;
8612 +
8613 +       switch (nxa->type & mask) {
8614 +       case NXA_TYPE_MASK:
8615 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8616 +               break;
8617 +       case NXA_TYPE_ADDR:
8618 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8619 +               break;
8620 +       case NXA_TYPE_ANY:
8621 +               ret = 1;
8622 +               break;
8623 +       }
8624 +       vxdprintk(VXD_CBIT(net, 0),
8625 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8626 +               nxa, NXAV6(nxa), addr, mask, ret);
8627 +       return ret;
8628 +}
8629 +
8630 +static inline
8631 +int v6_addr_in_nx_info(struct nx_info *nxi,
8632 +       const struct in6_addr *addr, uint16_t mask)
8633 +{
8634 +       struct nx_addr_v6 *nxa;
8635 +       unsigned long irqflags;
8636 +       int ret = 1;
8637 +
8638 +       if (!nxi)
8639 +               goto out;
8640 +
8641 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8642 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8643 +               if (v6_addr_match(nxa, addr, mask))
8644 +                       goto out_unlock;
8645 +       ret = 0;
8646 +out_unlock:
8647 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8648 +out:
8649 +       vxdprintk(VXD_CBIT(net, 0),
8650 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8651 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8652 +       return ret;
8653 +}
8654 +
8655 +static inline
8656 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8657 +{
8658 +       /* FIXME: needs full range checks */
8659 +       return v6_addr_match(nxa, &addr->ip, mask);
8660 +}
8661 +
8662 +static inline
8663 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8664 +{
8665 +       struct nx_addr_v6 *ptr;
8666 +       unsigned long irqflags;
8667 +       int ret = 1;
8668 +
8669 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8670 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8671 +               if (v6_nx_addr_match(ptr, nxa, mask))
8672 +                       goto out_unlock;
8673 +       ret = 0;
8674 +out_unlock:
8675 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8676 +       return ret;
8677 +}
8678 +
8679 +
8680 +/*
8681 + *     Check if a given address matches for a socket
8682 + *
8683 + *     nxi:            the socket's nx_info if any
8684 + *     addr:           to be verified address
8685 + */
8686 +static inline
8687 +int v6_sock_addr_match (
8688 +       struct nx_info *nxi,
8689 +       struct inet_sock *inet,
8690 +       struct in6_addr *addr)
8691 +{
8692 +       struct sock *sk = &inet->sk;
8693 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8694 +
8695 +       if (!ipv6_addr_any(addr) &&
8696 +               ipv6_addr_equal(saddr, addr))
8697 +               return 1;
8698 +       if (ipv6_addr_any(saddr))
8699 +               return v6_addr_in_nx_info(nxi, addr, -1);
8700 +       return 0;
8701 +}
8702 +
8703 +/*
8704 + *     check if address is covered by socket
8705 + *
8706 + *     sk:     the socket to check against
8707 + *     addr:   the address in question (must be != 0)
8708 + */
8709 +
8710 +static inline
8711 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8712 +{
8713 +       struct nx_info *nxi = sk->sk_nx_info;
8714 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8715 +
8716 +       vxdprintk(VXD_CBIT(net, 5),
8717 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8718 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8719 +               (sk->sk_socket?sk->sk_socket->flags:0));
8720 +
8721 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8722 +               return v6_addr_match(nxa, saddr, -1);
8723 +       } else if (nxi) {               /* match against nx_info */
8724 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8725 +       } else {                        /* unrestricted any socket */
8726 +               return 1;
8727 +       }
8728 +}
8729 +
8730 +
8731 +/* inet related checks and helpers */
8732 +
8733 +
8734 +struct in_ifaddr;
8735 +struct net_device;
8736 +struct sock;
8737 +
8738 +
8739 +#include <linux/netdevice.h>
8740 +#include <linux/inetdevice.h>
8741 +#include <net/inet_timewait_sock.h>
8742 +
8743 +
8744 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8745 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8746 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8747 +
8748 +
8749 +
8750 +static inline
8751 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8752 +{
8753 +       if (!nxi)
8754 +               return 1;
8755 +       if (!ifa)
8756 +               return 0;
8757 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8758 +}
8759 +
8760 +static inline
8761 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8762 +{
8763 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8764 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8765 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8766 +
8767 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8768 +               return 1;
8769 +       if (v6_ifa_in_nx_info(ifa, nxi))
8770 +               return 1;
8771 +       return 0;
8772 +}
8773 +
8774 +
8775 +struct nx_v6_sock_addr {
8776 +       struct in6_addr saddr;  /* Address used for validation */
8777 +       struct in6_addr baddr;  /* Address used for socket bind */
8778 +};
8779 +
8780 +static inline
8781 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8782 +       struct nx_v6_sock_addr *nsa)
8783 +{
8784 +       // struct sock *sk = &inet->sk;
8785 +       // struct nx_info *nxi = sk->sk_nx_info;
8786 +       struct in6_addr saddr = addr->sin6_addr;
8787 +       struct in6_addr baddr = saddr;
8788 +
8789 +       nsa->saddr = saddr;
8790 +       nsa->baddr = baddr;
8791 +       return 0;
8792 +}
8793 +
8794 +static inline
8795 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8796 +{
8797 +       // struct sock *sk = &inet->sk;
8798 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8799 +
8800 +       // *saddr = nsa->baddr;
8801 +       // inet->inet_saddr = nsa->baddr;
8802 +}
8803 +
8804 +static inline
8805 +int nx_info_has_v6(struct nx_info *nxi)
8806 +{
8807 +       if (!nxi)
8808 +               return 1;
8809 +       if (NX_IPV6(nxi))
8810 +               return 1;
8811 +       return 0;
8812 +}
8813 +
8814 +#else /* CONFIG_IPV6 */
8815 +
8816 +static inline
8817 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8818 +{
8819 +       return 1;
8820 +}
8821 +
8822 +
8823 +static inline
8824 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8825 +{
8826 +       return 1;
8827 +}
8828 +
8829 +static inline
8830 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8831 +{
8832 +       return 1;
8833 +}
8834 +
8835 +static inline
8836 +int nx_info_has_v6(struct nx_info *nxi)
8837 +{
8838 +       return 0;
8839 +}
8840 +
8841 +#endif /* CONFIG_IPV6 */
8842 +
8843 +#define current_nx_info_has_v6() \
8844 +       nx_info_has_v6(current_nx_info())
8845 +
8846 +#else
8847 +#warning duplicate inclusion
8848 +#endif
8849 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
8850 --- linux-3.13.10/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8851 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h   2014-02-01 01:29:43.000000000 +0000
8852 @@ -0,0 +1,140 @@
8853 +#ifndef _VS_LIMIT_H
8854 +#define _VS_LIMIT_H
8855 +
8856 +#include "vserver/limit.h"
8857 +#include "vserver/base.h"
8858 +#include "vserver/context.h"
8859 +#include "vserver/debug.h"
8860 +#include "vserver/context.h"
8861 +#include "vserver/limit_int.h"
8862 +
8863 +
8864 +#define vx_acc_cres(v, d, p, r) \
8865 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8866 +
8867 +#define vx_acc_cres_cond(x, d, p, r) \
8868 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8869 +       r, d, p, __FILE__, __LINE__)
8870 +
8871 +
8872 +#define vx_add_cres(v, a, p, r) \
8873 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8874 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8875 +
8876 +#define vx_add_cres_cond(x, a, p, r) \
8877 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8878 +       r, a, p, __FILE__, __LINE__)
8879 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8880 +
8881 +
8882 +/* process and file limits */
8883 +
8884 +#define vx_nproc_inc(p) \
8885 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8886 +
8887 +#define vx_nproc_dec(p) \
8888 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8889 +
8890 +#define vx_files_inc(f) \
8891 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8892 +
8893 +#define vx_files_dec(f) \
8894 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8895 +
8896 +#define vx_locks_inc(l) \
8897 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8898 +
8899 +#define vx_locks_dec(l) \
8900 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8901 +
8902 +#define vx_openfd_inc(f) \
8903 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8904 +
8905 +#define vx_openfd_dec(f) \
8906 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8907 +
8908 +
8909 +#define vx_cres_avail(v, n, r) \
8910 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8911 +
8912 +
8913 +#define vx_nproc_avail(n) \
8914 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8915 +
8916 +#define vx_files_avail(n) \
8917 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8918 +
8919 +#define vx_locks_avail(n) \
8920 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8921 +
8922 +#define vx_openfd_avail(n) \
8923 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8924 +
8925 +
8926 +/* dentry limits */
8927 +
8928 +#define vx_dentry_inc(d) do {                                          \
8929 +       if (d_count(d) == 1)                                            \
8930 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8931 +       } while (0)
8932 +
8933 +#define vx_dentry_dec(d) do {                                          \
8934 +       if (d_count(d) == 0)                                            \
8935 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8936 +       } while (0)
8937 +
8938 +#define vx_dentry_avail(n) \
8939 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8940 +
8941 +
8942 +/* socket limits */
8943 +
8944 +#define vx_sock_inc(s) \
8945 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8946 +
8947 +#define vx_sock_dec(s) \
8948 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8949 +
8950 +#define vx_sock_avail(n) \
8951 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8952 +
8953 +
8954 +/* ipc resource limits */
8955 +
8956 +#define vx_ipcmsg_add(v, u, a) \
8957 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8958 +
8959 +#define vx_ipcmsg_sub(v, u, a) \
8960 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8961 +
8962 +#define vx_ipcmsg_avail(v, a) \
8963 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8964 +
8965 +
8966 +#define vx_ipcshm_add(v, k, a) \
8967 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8968 +
8969 +#define vx_ipcshm_sub(v, k, a) \
8970 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8971 +
8972 +#define vx_ipcshm_avail(v, a) \
8973 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
8974 +
8975 +
8976 +#define vx_semary_inc(a) \
8977 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8978 +
8979 +#define vx_semary_dec(a) \
8980 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8981 +
8982 +
8983 +#define vx_nsems_add(a,n) \
8984 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8985 +
8986 +#define vx_nsems_sub(a,n) \
8987 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8988 +
8989 +
8990 +#else
8991 +#warning duplicate inclusion
8992 +#endif
8993 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
8994 --- linux-3.13.10/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
8995 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
8996 @@ -0,0 +1,169 @@
8997 +#ifndef _NX_VS_NETWORK_H
8998 +#define _NX_VS_NETWORK_H
8999 +
9000 +#include "vserver/context.h"
9001 +#include "vserver/network.h"
9002 +#include "vserver/base.h"
9003 +#include "vserver/check.h"
9004 +#include "vserver/debug.h"
9005 +
9006 +#include <linux/sched.h>
9007 +
9008 +
9009 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9010 +
9011 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9012 +       const char *_file, int _line)
9013 +{
9014 +       if (!nxi)
9015 +               return NULL;
9016 +
9017 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9018 +               nxi, nxi ? nxi->nx_id : 0,
9019 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9020 +               _file, _line);
9021 +
9022 +       atomic_inc(&nxi->nx_usecnt);
9023 +       return nxi;
9024 +}
9025 +
9026 +
9027 +extern void free_nx_info(struct nx_info *);
9028 +
9029 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9030 +
9031 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9032 +{
9033 +       if (!nxi)
9034 +               return;
9035 +
9036 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9037 +               nxi, nxi ? nxi->nx_id : 0,
9038 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9039 +               _file, _line);
9040 +
9041 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9042 +               free_nx_info(nxi);
9043 +}
9044 +
9045 +
9046 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9047 +
9048 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9049 +               const char *_file, int _line)
9050 +{
9051 +       if (nxi) {
9052 +               vxlprintk(VXD_CBIT(nid, 3),
9053 +                       "init_nx_info(%p[#%d.%d])",
9054 +                       nxi, nxi ? nxi->nx_id : 0,
9055 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9056 +                       _file, _line);
9057 +
9058 +               atomic_inc(&nxi->nx_usecnt);
9059 +       }
9060 +       *nxp = nxi;
9061 +}
9062 +
9063 +
9064 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9065 +
9066 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9067 +       const char *_file, int _line)
9068 +{
9069 +       struct nx_info *nxo;
9070 +
9071 +       if (!nxi)
9072 +               return;
9073 +
9074 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9075 +               nxi, nxi ? nxi->nx_id : 0,
9076 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9077 +               _file, _line);
9078 +
9079 +       atomic_inc(&nxi->nx_usecnt);
9080 +       nxo = xchg(nxp, nxi);
9081 +       BUG_ON(nxo);
9082 +}
9083 +
9084 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9085 +
9086 +static inline void __clr_nx_info(struct nx_info **nxp,
9087 +       const char *_file, int _line)
9088 +{
9089 +       struct nx_info *nxo;
9090 +
9091 +       nxo = xchg(nxp, NULL);
9092 +       if (!nxo)
9093 +               return;
9094 +
9095 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9096 +               nxo, nxo ? nxo->nx_id : 0,
9097 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9098 +               _file, _line);
9099 +
9100 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9101 +               free_nx_info(nxo);
9102 +}
9103 +
9104 +
9105 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9106 +
9107 +static inline void __claim_nx_info(struct nx_info *nxi,
9108 +       struct task_struct *task, const char *_file, int _line)
9109 +{
9110 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9111 +               nxi, nxi ? nxi->nx_id : 0,
9112 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9113 +               nxi?atomic_read(&nxi->nx_tasks):0,
9114 +               task, _file, _line);
9115 +
9116 +       atomic_inc(&nxi->nx_tasks);
9117 +}
9118 +
9119 +
9120 +extern void unhash_nx_info(struct nx_info *);
9121 +
9122 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9123 +
9124 +static inline void __release_nx_info(struct nx_info *nxi,
9125 +       struct task_struct *task, const char *_file, int _line)
9126 +{
9127 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9128 +               nxi, nxi ? nxi->nx_id : 0,
9129 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9130 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9131 +               task, _file, _line);
9132 +
9133 +       might_sleep();
9134 +
9135 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9136 +               unhash_nx_info(nxi);
9137 +}
9138 +
9139 +
9140 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9141 +
9142 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9143 +       const char *_file, int _line)
9144 +{
9145 +       struct nx_info *nxi;
9146 +
9147 +       task_lock(p);
9148 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9149 +               p, _file, _line);
9150 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9151 +       task_unlock(p);
9152 +       return nxi;
9153 +}
9154 +
9155 +
9156 +static inline void exit_nx_info(struct task_struct *p)
9157 +{
9158 +       if (p->nx_info)
9159 +               release_nx_info(p->nx_info, p);
9160 +}
9161 +
9162 +
9163 +#else
9164 +#warning duplicate inclusion
9165 +#endif
9166 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
9167 --- linux-3.13.10/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9168 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h     2014-01-31 20:38:03.000000000 +0000
9169 @@ -0,0 +1,50 @@
9170 +#ifndef _VS_PID_H
9171 +#define _VS_PID_H
9172 +
9173 +#include "vserver/base.h"
9174 +#include "vserver/check.h"
9175 +#include "vserver/context.h"
9176 +#include "vserver/debug.h"
9177 +#include "vserver/pid.h"
9178 +#include <linux/pid_namespace.h>
9179 +
9180 +
9181 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9182 +
9183 +static inline
9184 +int vx_proc_task_visible(struct task_struct *task)
9185 +{
9186 +       if ((task->pid == 1) &&
9187 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9188 +               /* show a blend through init */
9189 +               goto visible;
9190 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9191 +               goto visible;
9192 +       return 0;
9193 +visible:
9194 +       return 1;
9195 +}
9196 +
9197 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9198 +
9199 +
9200 +static inline
9201 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9202 +{
9203 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9204 +
9205 +       if (task && !vx_proc_task_visible(task)) {
9206 +               vxdprintk(VXD_CBIT(misc, 6),
9207 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9208 +                       task, task->xid, task->pid,
9209 +                       current, current->xid, current->pid);
9210 +               put_task_struct(task);
9211 +               task = NULL;
9212 +       }
9213 +       return task;
9214 +}
9215 +
9216 +
9217 +#else
9218 +#warning duplicate inclusion
9219 +#endif
9220 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
9221 --- linux-3.13.10/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9222 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h   2014-01-31 20:38:03.000000000 +0000
9223 @@ -0,0 +1,40 @@
9224 +#ifndef _VS_SCHED_H
9225 +#define _VS_SCHED_H
9226 +
9227 +#include "vserver/base.h"
9228 +#include "vserver/context.h"
9229 +#include "vserver/sched.h"
9230 +
9231 +
9232 +#define MAX_PRIO_BIAS           20
9233 +#define MIN_PRIO_BIAS          -20
9234 +
9235 +static inline
9236 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9237 +{
9238 +       struct vx_info *vxi = p->vx_info;
9239 +
9240 +       if (vxi)
9241 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9242 +       return prio;
9243 +}
9244 +
9245 +static inline void vx_account_user(struct vx_info *vxi,
9246 +       cputime_t cputime, int nice)
9247 +{
9248 +       if (!vxi)
9249 +               return;
9250 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9251 +}
9252 +
9253 +static inline void vx_account_system(struct vx_info *vxi,
9254 +       cputime_t cputime, int idle)
9255 +{
9256 +       if (!vxi)
9257 +               return;
9258 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9259 +}
9260 +
9261 +#else
9262 +#warning duplicate inclusion
9263 +#endif
9264 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
9265 --- linux-3.13.10/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9266 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h  2014-01-31 20:38:03.000000000 +0000
9267 @@ -0,0 +1,67 @@
9268 +#ifndef _VS_SOCKET_H
9269 +#define _VS_SOCKET_H
9270 +
9271 +#include "vserver/debug.h"
9272 +#include "vserver/base.h"
9273 +#include "vserver/cacct.h"
9274 +#include "vserver/context.h"
9275 +#include "vserver/tag.h"
9276 +
9277 +
9278 +/* socket accounting */
9279 +
9280 +#include <linux/socket.h>
9281 +
9282 +static inline int vx_sock_type(int family)
9283 +{
9284 +       switch (family) {
9285 +       case PF_UNSPEC:
9286 +               return VXA_SOCK_UNSPEC;
9287 +       case PF_UNIX:
9288 +               return VXA_SOCK_UNIX;
9289 +       case PF_INET:
9290 +               return VXA_SOCK_INET;
9291 +       case PF_INET6:
9292 +               return VXA_SOCK_INET6;
9293 +       case PF_PACKET:
9294 +               return VXA_SOCK_PACKET;
9295 +       default:
9296 +               return VXA_SOCK_OTHER;
9297 +       }
9298 +}
9299 +
9300 +#define vx_acc_sock(v, f, p, s) \
9301 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9302 +
9303 +static inline void __vx_acc_sock(struct vx_info *vxi,
9304 +       int family, int pos, int size, char *file, int line)
9305 +{
9306 +       if (vxi) {
9307 +               int type = vx_sock_type(family);
9308 +
9309 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9310 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9311 +       }
9312 +}
9313 +
9314 +#define vx_sock_recv(sk, s) \
9315 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9316 +#define vx_sock_send(sk, s) \
9317 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9318 +#define vx_sock_fail(sk, s) \
9319 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9320 +
9321 +
9322 +#define sock_vx_init(s) do {           \
9323 +       (s)->sk_xid = 0;                \
9324 +       (s)->sk_vx_info = NULL;         \
9325 +       } while (0)
9326 +
9327 +#define sock_nx_init(s) do {           \
9328 +       (s)->sk_nid = 0;                \
9329 +       (s)->sk_nx_info = NULL;         \
9330 +       } while (0)
9331 +
9332 +#else
9333 +#warning duplicate inclusion
9334 +#endif
9335 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
9336 --- linux-3.13.10/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9337 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h     2014-01-31 20:38:03.000000000 +0000
9338 @@ -0,0 +1,47 @@
9339 +#ifndef _VS_TAG_H
9340 +#define _VS_TAG_H
9341 +
9342 +#include <linux/vserver/tag.h>
9343 +
9344 +/* check conditions */
9345 +
9346 +#define DX_ADMIN       0x0001
9347 +#define DX_WATCH       0x0002
9348 +#define DX_HOSTID      0x0008
9349 +
9350 +#define DX_IDENT       0x0010
9351 +
9352 +#define DX_ARG_MASK    0x0010
9353 +
9354 +
9355 +#define dx_task_tag(t) ((t)->tag)
9356 +
9357 +#define dx_current_tag() dx_task_tag(current)
9358 +
9359 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9360 +
9361 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9362 +
9363 +
9364 +/*
9365 + * check current context for ADMIN/WATCH and
9366 + * optionally against supplied argument
9367 + */
9368 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9369 +{
9370 +       if (mode & DX_ARG_MASK) {
9371 +               if ((mode & DX_IDENT) && (id == cid))
9372 +                       return 1;
9373 +       }
9374 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9375 +               ((mode & DX_WATCH) && (cid == 1)) ||
9376 +               ((mode & DX_HOSTID) && (id == 0)));
9377 +}
9378 +
9379 +struct inode;
9380 +int dx_permission(const struct inode *inode, int mask);
9381 +
9382 +
9383 +#else
9384 +#warning duplicate inclusion
9385 +#endif
9386 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
9387 --- linux-3.13.10/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9388 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h    2014-01-31 20:38:03.000000000 +0000
9389 @@ -0,0 +1,19 @@
9390 +#ifndef _VS_TIME_H
9391 +#define _VS_TIME_H
9392 +
9393 +
9394 +/* time faking stuff */
9395 +
9396 +#ifdef CONFIG_VSERVER_VTIME
9397 +
9398 +extern void vx_adjust_timespec(struct timespec *ts);
9399 +extern int vx_settimeofday(const struct timespec *ts);
9400 +
9401 +#else
9402 +#define        vx_adjust_timespec(t)   do { } while (0)
9403 +#define        vx_settimeofday(t)      do_settimeofday(t)
9404 +#endif
9405 +
9406 +#else
9407 +#warning duplicate inclusion
9408 +#endif
9409 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
9410 --- linux-3.13.10/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9411 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h       2014-01-31 20:38:03.000000000 +0000
9412 @@ -0,0 +1,184 @@
9413 +#ifndef _VSERVER_BASE_H
9414 +#define _VSERVER_BASE_H
9415 +
9416 +
9417 +/* context state changes */
9418 +
9419 +enum {
9420 +       VSC_STARTUP = 1,
9421 +       VSC_SHUTDOWN,
9422 +
9423 +       VSC_NETUP,
9424 +       VSC_NETDOWN,
9425 +};
9426 +
9427 +
9428 +
9429 +#define vx_task_xid(t) ((t)->xid)
9430 +
9431 +#define vx_current_xid() vx_task_xid(current)
9432 +
9433 +#define current_vx_info() (current->vx_info)
9434 +
9435 +
9436 +#define nx_task_nid(t) ((t)->nid)
9437 +
9438 +#define nx_current_nid() nx_task_nid(current)
9439 +
9440 +#define current_nx_info() (current->nx_info)
9441 +
9442 +
9443 +/* generic flag merging */
9444 +
9445 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9446 +
9447 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9448 +
9449 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9450 +
9451 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9452 +
9453 +
9454 +/* context flags */
9455 +
9456 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9457 +
9458 +#define vx_current_flags()     __vx_flags(current_vx_info())
9459 +
9460 +#define vx_info_flags(v, m, f) \
9461 +       vs_check_flags(__vx_flags(v), m, f)
9462 +
9463 +#define task_vx_flags(t, m, f) \
9464 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9465 +
9466 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9467 +
9468 +
9469 +/* context caps */
9470 +
9471 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9472 +
9473 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9474 +
9475 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9476 +
9477 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9478 +
9479 +
9480 +
9481 +/* network flags */
9482 +
9483 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9484 +
9485 +#define nx_current_flags()     __nx_flags(current_nx_info())
9486 +
9487 +#define nx_info_flags(n, m, f) \
9488 +       vs_check_flags(__nx_flags(n), m, f)
9489 +
9490 +#define task_nx_flags(t, m, f) \
9491 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9492 +
9493 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9494 +
9495 +
9496 +/* network caps */
9497 +
9498 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9499 +
9500 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9501 +
9502 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9503 +
9504 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9505 +
9506 +
9507 +/* context mask capabilities */
9508 +
9509 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9510 +
9511 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9512 +
9513 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9514 +
9515 +
9516 +/* context bcap mask */
9517 +
9518 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9519 +
9520 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9521 +
9522 +
9523 +/* mask given bcaps */
9524 +
9525 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9526 +
9527 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9528 +
9529 +
9530 +/* masked cap_bset */
9531 +
9532 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9533 +
9534 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9535 +
9536 +#if 0
9537 +#define vx_info_mbcap(v, b) \
9538 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9539 +       vx_info_bcaps(v, b) : (b))
9540 +
9541 +#define task_vx_mbcap(t, b) \
9542 +       vx_info_mbcap((t)->vx_info, (t)->b)
9543 +
9544 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9545 +#endif
9546 +
9547 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9548 +
9549 +#define vx_capable(b, c) (capable(b) || \
9550 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9551 +
9552 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9553 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9554 +
9555 +#define nx_capable(b, c) (capable(b) || \
9556 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9557 +
9558 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9559 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9560 +
9561 +#define vx_task_initpid(t, n) \
9562 +       ((t)->vx_info && \
9563 +       ((t)->vx_info->vx_initpid == (n)))
9564 +
9565 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9566 +
9567 +
9568 +/* context unshare mask */
9569 +
9570 +#define __vx_umask(v)          ((v)->vx_umask)
9571 +
9572 +#define vx_current_umask()     __vx_umask(current_vx_info())
9573 +
9574 +#define vx_can_unshare(b, f) (capable(b) || \
9575 +       (cap_raised(current_cap(), b) && \
9576 +       !((f) & ~vx_current_umask())))
9577 +
9578 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9579 +       (cap_raised(current_cap(), b) && \
9580 +       !((f) & ~vx_current_umask())))
9581 +
9582 +#define __vx_wmask(v)          ((v)->vx_wmask)
9583 +
9584 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9585 +
9586 +
9587 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9588 +
9589 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9590 +
9591 +
9592 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9593 +
9594 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9595 +
9596 +#endif
9597 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
9598 --- linux-3.13.10/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9599 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h      2014-01-31 20:38:03.000000000 +0000
9600 @@ -0,0 +1,15 @@
9601 +#ifndef _VSERVER_CACCT_H
9602 +#define _VSERVER_CACCT_H
9603 +
9604 +
9605 +enum sock_acc_field {
9606 +       VXA_SOCK_UNSPEC = 0,
9607 +       VXA_SOCK_UNIX,
9608 +       VXA_SOCK_INET,
9609 +       VXA_SOCK_INET6,
9610 +       VXA_SOCK_PACKET,
9611 +       VXA_SOCK_OTHER,
9612 +       VXA_SOCK_SIZE   /* array size */
9613 +};
9614 +
9615 +#endif /* _VSERVER_CACCT_H */
9616 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
9617 --- linux-3.13.10/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9618 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h  2014-01-31 20:38:03.000000000 +0000
9619 @@ -0,0 +1,10 @@
9620 +#ifndef _VSERVER_CACCT_CMD_H
9621 +#define _VSERVER_CACCT_CMD_H
9622 +
9623 +
9624 +#include <linux/compiler.h>
9625 +#include <uapi/vserver/cacct_cmd.h>
9626 +
9627 +extern int vc_sock_stat(struct vx_info *, void __user *);
9628 +
9629 +#endif /* _VSERVER_CACCT_CMD_H */
9630 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
9631 --- linux-3.13.10/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9632 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h  2014-01-31 20:38:03.000000000 +0000
9633 @@ -0,0 +1,43 @@
9634 +#ifndef _VSERVER_CACCT_DEF_H
9635 +#define _VSERVER_CACCT_DEF_H
9636 +
9637 +#include <asm/atomic.h>
9638 +#include <linux/vserver/cacct.h>
9639 +
9640 +
9641 +struct _vx_sock_acc {
9642 +       atomic_long_t count;
9643 +       atomic_long_t total;
9644 +};
9645 +
9646 +/* context sub struct */
9647 +
9648 +struct _vx_cacct {
9649 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9650 +       atomic_t slab[8];
9651 +       atomic_t page[6][8];
9652 +};
9653 +
9654 +#ifdef CONFIG_VSERVER_DEBUG
9655 +
9656 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9657 +{
9658 +       int i, j;
9659 +
9660 +       printk("\t_vx_cacct:");
9661 +       for (i = 0; i < 6; i++) {
9662 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9663 +
9664 +               printk("\t [%d] =", i);
9665 +               for (j = 0; j < 3; j++) {
9666 +                       printk(" [%d] = %8lu, %8lu", j,
9667 +                               atomic_long_read(&ptr[j].count),
9668 +                               atomic_long_read(&ptr[j].total));
9669 +               }
9670 +               printk("\n");
9671 +       }
9672 +}
9673 +
9674 +#endif
9675 +
9676 +#endif /* _VSERVER_CACCT_DEF_H */
9677 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
9678 --- linux-3.13.10/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9679 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h  2014-01-31 20:38:03.000000000 +0000
9680 @@ -0,0 +1,17 @@
9681 +#ifndef _VSERVER_CACCT_INT_H
9682 +#define _VSERVER_CACCT_INT_H
9683 +
9684 +static inline
9685 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9686 +{
9687 +       return atomic_long_read(&cacct->sock[type][pos].count);
9688 +}
9689 +
9690 +
9691 +static inline
9692 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9693 +{
9694 +       return atomic_long_read(&cacct->sock[type][pos].total);
9695 +}
9696 +
9697 +#endif /* _VSERVER_CACCT_INT_H */
9698 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
9699 --- linux-3.13.10/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9700 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h      2014-01-31 20:38:03.000000000 +0000
9701 @@ -0,0 +1,89 @@
9702 +#ifndef _VSERVER_CHECK_H
9703 +#define _VSERVER_CHECK_H
9704 +
9705 +
9706 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9707 +
9708 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9709 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9710 +#else
9711 +#define MIN_D_CONTEXT  65536
9712 +#endif
9713 +
9714 +/* check conditions */
9715 +
9716 +#define VS_ADMIN       0x0001
9717 +#define VS_WATCH       0x0002
9718 +#define VS_HIDE                0x0004
9719 +#define VS_HOSTID      0x0008
9720 +
9721 +#define VS_IDENT       0x0010
9722 +#define VS_EQUIV       0x0020
9723 +#define VS_PARENT      0x0040
9724 +#define VS_CHILD       0x0080
9725 +
9726 +#define VS_ARG_MASK    0x00F0
9727 +
9728 +#define VS_DYNAMIC     0x0100
9729 +#define VS_STATIC      0x0200
9730 +
9731 +#define VS_ATR_MASK    0x0F00
9732 +
9733 +#ifdef CONFIG_VSERVER_PRIVACY
9734 +#define VS_ADMIN_P     (0)
9735 +#define VS_WATCH_P     (0)
9736 +#else
9737 +#define VS_ADMIN_P     VS_ADMIN
9738 +#define VS_WATCH_P     VS_WATCH
9739 +#endif
9740 +
9741 +#define VS_HARDIRQ     0x1000
9742 +#define VS_SOFTIRQ     0x2000
9743 +#define VS_IRQ         0x4000
9744 +
9745 +#define VS_IRQ_MASK    0xF000
9746 +
9747 +#include <linux/hardirq.h>
9748 +
9749 +/*
9750 + * check current context for ADMIN/WATCH and
9751 + * optionally against supplied argument
9752 + */
9753 +static inline int __vs_check(int cid, int id, unsigned int mode)
9754 +{
9755 +       if (mode & VS_ARG_MASK) {
9756 +               if ((mode & VS_IDENT) && (id == cid))
9757 +                       return 1;
9758 +       }
9759 +       if (mode & VS_ATR_MASK) {
9760 +               if ((mode & VS_DYNAMIC) &&
9761 +                       (id >= MIN_D_CONTEXT) &&
9762 +                       (id <= MAX_S_CONTEXT))
9763 +                       return 1;
9764 +               if ((mode & VS_STATIC) &&
9765 +                       (id > 1) && (id < MIN_D_CONTEXT))
9766 +                       return 1;
9767 +       }
9768 +       if (mode & VS_IRQ_MASK) {
9769 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9770 +                       return 1;
9771 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9772 +                       return 1;
9773 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9774 +                       return 1;
9775 +       }
9776 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9777 +               ((mode & VS_WATCH) && (cid == 1)) ||
9778 +               ((mode & VS_HOSTID) && (id == 0)));
9779 +}
9780 +
9781 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9782 +
9783 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9784 +
9785 +
9786 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9787 +
9788 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9789 +
9790 +#endif
9791 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
9792 --- linux-3.13.10/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9793 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h    2014-01-31 20:38:03.000000000 +0000
9794 @@ -0,0 +1,110 @@
9795 +#ifndef _VSERVER_CONTEXT_H
9796 +#define _VSERVER_CONTEXT_H
9797 +
9798 +
9799 +#include <linux/list.h>
9800 +#include <linux/spinlock.h>
9801 +#include <linux/rcupdate.h>
9802 +#include <uapi/vserver/context.h>
9803 +
9804 +#include "limit_def.h"
9805 +#include "sched_def.h"
9806 +#include "cvirt_def.h"
9807 +#include "cacct_def.h"
9808 +#include "device_def.h"
9809 +
9810 +#define VX_SPACES      2
9811 +
9812 +struct _vx_info_pc {
9813 +       struct _vx_sched_pc sched_pc;
9814 +       struct _vx_cvirt_pc cvirt_pc;
9815 +};
9816 +
9817 +struct _vx_space {
9818 +       unsigned long vx_nsmask;                /* assignment mask */
9819 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9820 +       struct fs_struct *vx_fs;                /* private namespace fs */
9821 +       const struct cred *vx_cred;             /* task credentials */
9822 +};
9823 +
9824 +struct vx_info {
9825 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9826 +       vxid_t vx_id;                           /* context id */
9827 +       atomic_t vx_usecnt;                     /* usage count */
9828 +       atomic_t vx_tasks;                      /* tasks count */
9829 +       struct vx_info *vx_parent;              /* parent context */
9830 +       int vx_state;                           /* context state */
9831 +
9832 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9833 +
9834 +       uint64_t vx_flags;                      /* context flags */
9835 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9836 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9837 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9838 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9839 +
9840 +       struct task_struct *vx_reaper;          /* guest reaper process */
9841 +       pid_t vx_initpid;                       /* PID of guest init */
9842 +       int64_t vx_badness_bias;                /* OOM points bias */
9843 +
9844 +       struct _vx_limit limit;                 /* vserver limits */
9845 +       struct _vx_sched sched;                 /* vserver scheduler */
9846 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9847 +       struct _vx_cacct cacct;                 /* context accounting */
9848 +
9849 +       struct _vx_device dmap;                 /* default device map targets */
9850 +
9851 +#ifndef CONFIG_SMP
9852 +       struct _vx_info_pc info_pc;             /* per cpu data */
9853 +#else
9854 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9855 +#endif
9856 +
9857 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9858 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9859 +       int exit_code;                          /* last process exit code */
9860 +
9861 +       char vx_name[65];                       /* vserver name */
9862 +};
9863 +
9864 +#ifndef CONFIG_SMP
9865 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9866 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9867 +#else
9868 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9869 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9870 +#endif
9871 +
9872 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9873 +
9874 +
9875 +struct vx_info_save {
9876 +       struct vx_info *vxi;
9877 +       vxid_t xid;
9878 +};
9879 +
9880 +
9881 +/* status flags */
9882 +
9883 +#define VXS_HASHED     0x0001
9884 +#define VXS_PAUSED     0x0010
9885 +#define VXS_SHUTDOWN   0x0100
9886 +#define VXS_HELPER     0x1000
9887 +#define VXS_RELEASED   0x8000
9888 +
9889 +
9890 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9891 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9892 +
9893 +extern struct vx_info *lookup_vx_info(int);
9894 +extern struct vx_info *lookup_or_create_vx_info(int);
9895 +
9896 +extern int get_xid_list(int, unsigned int *, int);
9897 +extern int xid_is_hashed(vxid_t);
9898 +
9899 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9900 +
9901 +extern long vs_state_change(struct vx_info *, unsigned int);
9902 +
9903 +
9904 +#endif /* _VSERVER_CONTEXT_H */
9905 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
9906 --- linux-3.13.10/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9907 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h        2014-01-31 20:38:03.000000000 +0000
9908 @@ -0,0 +1,33 @@
9909 +#ifndef _VSERVER_CONTEXT_CMD_H
9910 +#define _VSERVER_CONTEXT_CMD_H
9911 +
9912 +#include <uapi/vserver/context_cmd.h>
9913 +
9914 +extern int vc_task_xid(uint32_t);
9915 +
9916 +extern int vc_vx_info(struct vx_info *, void __user *);
9917 +
9918 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9919 +
9920 +extern int vc_ctx_create(uint32_t, void __user *);
9921 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9922 +
9923 +extern int vc_get_cflags(struct vx_info *, void __user *);
9924 +extern int vc_set_cflags(struct vx_info *, void __user *);
9925 +
9926 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9927 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9928 +
9929 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9930 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9931 +
9932 +extern int vc_get_umask(struct vx_info *, void __user *);
9933 +extern int vc_set_umask(struct vx_info *, void __user *);
9934 +
9935 +extern int vc_get_wmask(struct vx_info *, void __user *);
9936 +extern int vc_set_wmask(struct vx_info *, void __user *);
9937 +
9938 +extern int vc_get_badness(struct vx_info *, void __user *);
9939 +extern int vc_set_badness(struct vx_info *, void __user *);
9940 +
9941 +#endif /* _VSERVER_CONTEXT_CMD_H */
9942 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
9943 --- linux-3.13.10/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9944 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h      2014-01-31 20:38:03.000000000 +0000
9945 @@ -0,0 +1,18 @@
9946 +#ifndef _VSERVER_CVIRT_H
9947 +#define _VSERVER_CVIRT_H
9948 +
9949 +struct timespec;
9950 +
9951 +void vx_vsi_boottime(struct timespec *);
9952 +
9953 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9954 +
9955 +
9956 +struct vx_info;
9957 +
9958 +void vx_update_load(struct vx_info *);
9959 +
9960 +
9961 +int vx_do_syslog(int, char __user *, int);
9962 +
9963 +#endif /* _VSERVER_CVIRT_H */
9964 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
9965 --- linux-3.13.10/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
9966 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h  2014-01-31 20:38:03.000000000 +0000
9967 @@ -0,0 +1,13 @@
9968 +#ifndef _VSERVER_CVIRT_CMD_H
9969 +#define _VSERVER_CVIRT_CMD_H
9970 +
9971 +
9972 +#include <linux/compiler.h>
9973 +#include <uapi/vserver/cvirt_cmd.h>
9974 +
9975 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9976 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9977 +
9978 +extern int vc_virt_stat(struct vx_info *, void __user *);
9979 +
9980 +#endif /* _VSERVER_CVIRT_CMD_H */
9981 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
9982 --- linux-3.13.10/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
9983 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h  2014-01-31 20:38:03.000000000 +0000
9984 @@ -0,0 +1,80 @@
9985 +#ifndef _VSERVER_CVIRT_DEF_H
9986 +#define _VSERVER_CVIRT_DEF_H
9987 +
9988 +#include <linux/jiffies.h>
9989 +#include <linux/spinlock.h>
9990 +#include <linux/wait.h>
9991 +#include <linux/time.h>
9992 +#include <asm/atomic.h>
9993 +
9994 +
9995 +struct _vx_usage_stat {
9996 +       uint64_t user;
9997 +       uint64_t nice;
9998 +       uint64_t system;
9999 +       uint64_t softirq;
10000 +       uint64_t irq;
10001 +       uint64_t idle;
10002 +       uint64_t iowait;
10003 +};
10004 +
10005 +struct _vx_syslog {
10006 +       wait_queue_head_t log_wait;
10007 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10008 +
10009 +       unsigned long log_start;        /* next char to be read by syslog() */
10010 +       unsigned long con_start;        /* next char to be sent to consoles */
10011 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10012 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10013 +
10014 +       char log_buf[1024];
10015 +};
10016 +
10017 +
10018 +/* context sub struct */
10019 +
10020 +struct _vx_cvirt {
10021 +       atomic_t nr_threads;            /* number of current threads */
10022 +       atomic_t nr_running;            /* number of running threads */
10023 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10024 +
10025 +       atomic_t nr_onhold;             /* processes on hold */
10026 +       uint32_t onhold_last;           /* jiffies when put on hold */
10027 +
10028 +       struct timespec bias_ts;        /* time offset to the host */
10029 +       struct timespec bias_idle;
10030 +       struct timespec bias_uptime;    /* context creation point */
10031 +       uint64_t bias_clock;            /* offset in clock_t */
10032 +
10033 +       spinlock_t load_lock;           /* lock for the load averages */
10034 +       atomic_t load_updates;          /* nr of load updates done so far */
10035 +       uint32_t load_last;             /* last time load was calculated */
10036 +       uint32_t load[3];               /* load averages 1,5,15 */
10037 +
10038 +       atomic_t total_forks;           /* number of forks so far */
10039 +
10040 +       struct _vx_syslog syslog;
10041 +};
10042 +
10043 +struct _vx_cvirt_pc {
10044 +       struct _vx_usage_stat cpustat;
10045 +};
10046 +
10047 +
10048 +#ifdef CONFIG_VSERVER_DEBUG
10049 +
10050 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10051 +{
10052 +       printk("\t_vx_cvirt:\n");
10053 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10054 +               atomic_read(&cvirt->nr_threads),
10055 +               atomic_read(&cvirt->nr_running),
10056 +               atomic_read(&cvirt->nr_uninterruptible),
10057 +               atomic_read(&cvirt->nr_onhold));
10058 +       /* add rest here */
10059 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10060 +}
10061 +
10062 +#endif
10063 +
10064 +#endif /* _VSERVER_CVIRT_DEF_H */
10065 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
10066 --- linux-3.13.10/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10067 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h      2014-01-31 20:38:03.000000000 +0000
10068 @@ -0,0 +1,146 @@
10069 +#ifndef _VSERVER_DEBUG_H
10070 +#define _VSERVER_DEBUG_H
10071 +
10072 +
10073 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10074 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10075 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10076 +
10077 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10078 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10079 +#define VXF_DEV                "%p[%lu,%d:%d]"
10080 +
10081 +#if    defined(CONFIG_QUOTES_UTF8)
10082 +#define        VS_Q_LQM        "\xc2\xbb"
10083 +#define        VS_Q_RQM        "\xc2\xab"
10084 +#elif  defined(CONFIG_QUOTES_ASCII)
10085 +#define        VS_Q_LQM        "\x27"
10086 +#define        VS_Q_RQM        "\x27"
10087 +#else
10088 +#define        VS_Q_LQM        "\xbb"
10089 +#define        VS_Q_RQM        "\xab"
10090 +#endif
10091 +
10092 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10093 +
10094 +
10095 +#define vxd_path(p)                                            \
10096 +       ({ static char _buffer[PATH_MAX];                       \
10097 +          d_path(p, _buffer, sizeof(_buffer)); })
10098 +
10099 +#define vxd_cond_path(n)                                       \
10100 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10101 +
10102 +
10103 +#ifdef CONFIG_VSERVER_DEBUG
10104 +
10105 +extern unsigned int vs_debug_switch;
10106 +extern unsigned int vs_debug_xid;
10107 +extern unsigned int vs_debug_nid;
10108 +extern unsigned int vs_debug_tag;
10109 +extern unsigned int vs_debug_net;
10110 +extern unsigned int vs_debug_limit;
10111 +extern unsigned int vs_debug_cres;
10112 +extern unsigned int vs_debug_dlim;
10113 +extern unsigned int vs_debug_quota;
10114 +extern unsigned int vs_debug_cvirt;
10115 +extern unsigned int vs_debug_space;
10116 +extern unsigned int vs_debug_perm;
10117 +extern unsigned int vs_debug_misc;
10118 +
10119 +
10120 +#define VX_LOGLEVEL    "vxD: "
10121 +#define VX_PROC_FMT    "%p: "
10122 +#define VX_PROCESS     current
10123 +
10124 +#define vxdprintk(c, f, x...)                                  \
10125 +       do {                                                    \
10126 +               if (c)                                          \
10127 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10128 +                               VX_PROCESS , ##x);              \
10129 +       } while (0)
10130 +
10131 +#define vxlprintk(c, f, x...)                                  \
10132 +       do {                                                    \
10133 +               if (c)                                          \
10134 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10135 +       } while (0)
10136 +
10137 +#define vxfprintk(c, f, x...)                                  \
10138 +       do {                                                    \
10139 +               if (c)                                          \
10140 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10141 +       } while (0)
10142 +
10143 +
10144 +struct vx_info;
10145 +
10146 +void dump_vx_info(struct vx_info *, int);
10147 +void dump_vx_info_inactive(int);
10148 +
10149 +#else  /* CONFIG_VSERVER_DEBUG */
10150 +
10151 +#define vs_debug_switch        0
10152 +#define vs_debug_xid   0
10153 +#define vs_debug_nid   0
10154 +#define vs_debug_tag   0
10155 +#define vs_debug_net   0
10156 +#define vs_debug_limit 0
10157 +#define vs_debug_cres  0
10158 +#define vs_debug_dlim  0
10159 +#define vs_debug_quota 0
10160 +#define vs_debug_cvirt 0
10161 +#define vs_debug_space 0
10162 +#define vs_debug_perm  0
10163 +#define vs_debug_misc  0
10164 +
10165 +#define vxdprintk(x...) do { } while (0)
10166 +#define vxlprintk(x...) do { } while (0)
10167 +#define vxfprintk(x...) do { } while (0)
10168 +
10169 +#endif /* CONFIG_VSERVER_DEBUG */
10170 +
10171 +
10172 +#ifdef CONFIG_VSERVER_WARN
10173 +
10174 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10175 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10176 +#define VX_WARN_XID    "[xid #%u] "
10177 +#define VX_WARN_NID    "[nid #%u] "
10178 +#define VX_WARN_TAG    "[tag #%u] "
10179 +
10180 +#define vxwprintk(c, f, x...)                                  \
10181 +       do {                                                    \
10182 +               if (c)                                          \
10183 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10184 +       } while (0)
10185 +
10186 +#else  /* CONFIG_VSERVER_WARN */
10187 +
10188 +#define vxwprintk(x...) do { } while (0)
10189 +
10190 +#endif /* CONFIG_VSERVER_WARN */
10191 +
10192 +#define vxwprintk_task(c, f, x...)                             \
10193 +       vxwprintk(c, VX_WARN_TASK f,                            \
10194 +               current->comm, current->pid,                    \
10195 +               current->xid, current->nid,                     \
10196 +               current->tag, ##x)
10197 +#define vxwprintk_xid(c, f, x...)                              \
10198 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10199 +#define vxwprintk_nid(c, f, x...)                              \
10200 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10201 +#define vxwprintk_tag(c, f, x...)                              \
10202 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10203 +
10204 +#ifdef CONFIG_VSERVER_DEBUG
10205 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10206 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10207 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10208 +#else
10209 +#define vxd_assert_lock(l)     do { } while (0)
10210 +#define vxd_assert(c, f, x...) do { } while (0)
10211 +#endif
10212 +
10213 +
10214 +#endif /* _VSERVER_DEBUG_H */
10215 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
10216 --- linux-3.13.10/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10217 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h  2014-01-31 20:38:03.000000000 +0000
10218 @@ -0,0 +1,37 @@
10219 +#ifndef _VSERVER_DEBUG_CMD_H
10220 +#define _VSERVER_DEBUG_CMD_H
10221 +
10222 +#include <uapi/vserver/debug_cmd.h>
10223 +
10224 +
10225 +#ifdef CONFIG_COMPAT
10226 +
10227 +#include <asm/compat.h>
10228 +
10229 +struct vcmd_read_history_v0_x32 {
10230 +       uint32_t index;
10231 +       uint32_t count;
10232 +       compat_uptr_t data_ptr;
10233 +};
10234 +
10235 +struct vcmd_read_monitor_v0_x32 {
10236 +       uint32_t index;
10237 +       uint32_t count;
10238 +       compat_uptr_t data_ptr;
10239 +};
10240 +
10241 +#endif  /* CONFIG_COMPAT */
10242 +
10243 +extern int vc_dump_history(uint32_t);
10244 +
10245 +extern int vc_read_history(uint32_t, void __user *);
10246 +extern int vc_read_monitor(uint32_t, void __user *);
10247 +
10248 +#ifdef CONFIG_COMPAT
10249 +
10250 +extern int vc_read_history_x32(uint32_t, void __user *);
10251 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10252 +
10253 +#endif  /* CONFIG_COMPAT */
10254 +
10255 +#endif /* _VSERVER_DEBUG_CMD_H */
10256 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
10257 --- linux-3.13.10/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10258 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h     2014-01-31 20:38:03.000000000 +0000
10259 @@ -0,0 +1,9 @@
10260 +#ifndef _VSERVER_DEVICE_H
10261 +#define _VSERVER_DEVICE_H
10262 +
10263 +
10264 +#include <uapi/vserver/device.h>
10265 +
10266 +#else  /* _VSERVER_DEVICE_H */
10267 +#warning duplicate inclusion
10268 +#endif /* _VSERVER_DEVICE_H */
10269 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
10270 --- linux-3.13.10/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10271 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10272 @@ -0,0 +1,31 @@
10273 +#ifndef _VSERVER_DEVICE_CMD_H
10274 +#define _VSERVER_DEVICE_CMD_H
10275 +
10276 +#include <uapi/vserver/device_cmd.h>
10277 +
10278 +
10279 +#ifdef CONFIG_COMPAT
10280 +
10281 +#include <asm/compat.h>
10282 +
10283 +struct vcmd_set_mapping_v0_x32 {
10284 +       compat_uptr_t device_ptr;
10285 +       compat_uptr_t target_ptr;
10286 +       uint32_t flags;
10287 +};
10288 +
10289 +#endif /* CONFIG_COMPAT */
10290 +
10291 +#include <linux/compiler.h>
10292 +
10293 +extern int vc_set_mapping(struct vx_info *, void __user *);
10294 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10295 +
10296 +#ifdef CONFIG_COMPAT
10297 +
10298 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10299 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10300 +
10301 +#endif /* CONFIG_COMPAT */
10302 +
10303 +#endif /* _VSERVER_DEVICE_CMD_H */
10304 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
10305 --- linux-3.13.10/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
10306 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10307 @@ -0,0 +1,17 @@
10308 +#ifndef _VSERVER_DEVICE_DEF_H
10309 +#define _VSERVER_DEVICE_DEF_H
10310 +
10311 +#include <linux/types.h>
10312 +
10313 +struct vx_dmap_target {
10314 +       dev_t target;
10315 +       uint32_t flags;
10316 +};
10317 +
10318 +struct _vx_device {
10319 +#ifdef CONFIG_VSERVER_DEVICE
10320 +       struct vx_dmap_target targets[2];
10321 +#endif
10322 +};
10323 +
10324 +#endif /* _VSERVER_DEVICE_DEF_H */
10325 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
10326 --- linux-3.13.10/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10327 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h     2014-01-31 20:38:03.000000000 +0000
10328 @@ -0,0 +1,54 @@
10329 +#ifndef _VSERVER_DLIMIT_H
10330 +#define _VSERVER_DLIMIT_H
10331 +
10332 +#include "switch.h"
10333 +
10334 +
10335 +#ifdef __KERNEL__
10336 +
10337 +/*      keep in sync with CDLIM_INFINITY       */
10338 +
10339 +#define DLIM_INFINITY          (~0ULL)
10340 +
10341 +#include <linux/spinlock.h>
10342 +#include <linux/rcupdate.h>
10343 +
10344 +struct super_block;
10345 +
10346 +struct dl_info {
10347 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10348 +       struct rcu_head dl_rcu;                 /* the rcu head */
10349 +       vtag_t dl_tag;                          /* context tag */
10350 +       atomic_t dl_usecnt;                     /* usage count */
10351 +       atomic_t dl_refcnt;                     /* reference count */
10352 +
10353 +       struct super_block *dl_sb;              /* associated superblock */
10354 +
10355 +       spinlock_t dl_lock;                     /* protect the values */
10356 +
10357 +       unsigned long long dl_space_used;       /* used space in bytes */
10358 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10359 +       unsigned long dl_inodes_used;           /* used inodes */
10360 +       unsigned long dl_inodes_total;          /* maximum inodes */
10361 +
10362 +       unsigned int dl_nrlmult;                /* non root limit mult */
10363 +};
10364 +
10365 +struct rcu_head;
10366 +
10367 +extern void rcu_free_dl_info(struct rcu_head *);
10368 +extern void unhash_dl_info(struct dl_info *);
10369 +
10370 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10371 +
10372 +
10373 +struct kstatfs;
10374 +
10375 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10376 +
10377 +typedef uint64_t dlsize_t;
10378 +
10379 +#endif /* __KERNEL__ */
10380 +#else  /* _VSERVER_DLIMIT_H */
10381 +#warning duplicate inclusion
10382 +#endif /* _VSERVER_DLIMIT_H */
10383 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
10384 --- linux-3.13.10/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10385 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10386 @@ -0,0 +1,46 @@
10387 +#ifndef _VSERVER_DLIMIT_CMD_H
10388 +#define _VSERVER_DLIMIT_CMD_H
10389 +
10390 +#include <uapi/vserver/dlimit_cmd.h>
10391 +
10392 +
10393 +#ifdef CONFIG_COMPAT
10394 +
10395 +#include <asm/compat.h>
10396 +
10397 +struct vcmd_ctx_dlimit_base_v0_x32 {
10398 +       compat_uptr_t name_ptr;
10399 +       uint32_t flags;
10400 +};
10401 +
10402 +struct vcmd_ctx_dlimit_v0_x32 {
10403 +       compat_uptr_t name_ptr;
10404 +       uint32_t space_used;                    /* used space in kbytes */
10405 +       uint32_t space_total;                   /* maximum space in kbytes */
10406 +       uint32_t inodes_used;                   /* used inodes */
10407 +       uint32_t inodes_total;                  /* maximum inodes */
10408 +       uint32_t reserved;                      /* reserved for root in % */
10409 +       uint32_t flags;
10410 +};
10411 +
10412 +#endif /* CONFIG_COMPAT */
10413 +
10414 +#include <linux/compiler.h>
10415 +
10416 +extern int vc_add_dlimit(uint32_t, void __user *);
10417 +extern int vc_rem_dlimit(uint32_t, void __user *);
10418 +
10419 +extern int vc_set_dlimit(uint32_t, void __user *);
10420 +extern int vc_get_dlimit(uint32_t, void __user *);
10421 +
10422 +#ifdef CONFIG_COMPAT
10423 +
10424 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10425 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10426 +
10427 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10428 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10429 +
10430 +#endif /* CONFIG_COMPAT */
10431 +
10432 +#endif /* _VSERVER_DLIMIT_CMD_H */
10433 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
10434 --- linux-3.13.10/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10435 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h     2014-01-31 20:38:03.000000000 +0000
10436 @@ -0,0 +1,19 @@
10437 +#ifndef _VSERVER_GLOBAL_H
10438 +#define _VSERVER_GLOBAL_H
10439 +
10440 +
10441 +extern atomic_t vx_global_ctotal;
10442 +extern atomic_t vx_global_cactive;
10443 +
10444 +extern atomic_t nx_global_ctotal;
10445 +extern atomic_t nx_global_cactive;
10446 +
10447 +extern atomic_t vs_global_nsproxy;
10448 +extern atomic_t vs_global_fs;
10449 +extern atomic_t vs_global_mnt_ns;
10450 +extern atomic_t vs_global_uts_ns;
10451 +extern atomic_t vs_global_user_ns;
10452 +extern atomic_t vs_global_pid_ns;
10453 +
10454 +
10455 +#endif /* _VSERVER_GLOBAL_H */
10456 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
10457 --- linux-3.13.10/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10458 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h    2014-01-31 20:38:03.000000000 +0000
10459 @@ -0,0 +1,197 @@
10460 +#ifndef _VSERVER_HISTORY_H
10461 +#define _VSERVER_HISTORY_H
10462 +
10463 +
10464 +enum {
10465 +       VXH_UNUSED = 0,
10466 +       VXH_THROW_OOPS = 1,
10467 +
10468 +       VXH_GET_VX_INFO,
10469 +       VXH_PUT_VX_INFO,
10470 +       VXH_INIT_VX_INFO,
10471 +       VXH_SET_VX_INFO,
10472 +       VXH_CLR_VX_INFO,
10473 +       VXH_CLAIM_VX_INFO,
10474 +       VXH_RELEASE_VX_INFO,
10475 +       VXH_ALLOC_VX_INFO,
10476 +       VXH_DEALLOC_VX_INFO,
10477 +       VXH_HASH_VX_INFO,
10478 +       VXH_UNHASH_VX_INFO,
10479 +       VXH_LOC_VX_INFO,
10480 +       VXH_LOOKUP_VX_INFO,
10481 +       VXH_CREATE_VX_INFO,
10482 +};
10483 +
10484 +struct _vxhe_vxi {
10485 +       struct vx_info *ptr;
10486 +       unsigned xid;
10487 +       unsigned usecnt;
10488 +       unsigned tasks;
10489 +};
10490 +
10491 +struct _vxhe_set_clr {
10492 +       void *data;
10493 +};
10494 +
10495 +struct _vxhe_loc_lookup {
10496 +       unsigned arg;
10497 +};
10498 +
10499 +struct _vx_hist_entry {
10500 +       void *loc;
10501 +       unsigned short seq;
10502 +       unsigned short type;
10503 +       struct _vxhe_vxi vxi;
10504 +       union {
10505 +               struct _vxhe_set_clr sc;
10506 +               struct _vxhe_loc_lookup ll;
10507 +       };
10508 +};
10509 +
10510 +#ifdef CONFIG_VSERVER_HISTORY
10511 +
10512 +extern unsigned volatile int vxh_active;
10513 +
10514 +struct _vx_hist_entry *vxh_advance(void *loc);
10515 +
10516 +
10517 +static inline
10518 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10519 +{
10520 +       entry->vxi.ptr = vxi;
10521 +       if (vxi) {
10522 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10523 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10524 +               entry->vxi.xid = vxi->vx_id;
10525 +       }
10526 +}
10527 +
10528 +
10529 +#define        __HERE__ current_text_addr()
10530 +
10531 +#define __VXH_BODY(__type, __data, __here)     \
10532 +       struct _vx_hist_entry *entry;           \
10533 +                                               \
10534 +       preempt_disable();                      \
10535 +       entry = vxh_advance(__here);            \
10536 +       __data;                                 \
10537 +       entry->type = __type;                   \
10538 +       preempt_enable();
10539 +
10540 +
10541 +       /* pass vxi only */
10542 +
10543 +#define __VXH_SMPL                             \
10544 +       __vxh_copy_vxi(entry, vxi)
10545 +
10546 +static inline
10547 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10548 +{
10549 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10550 +}
10551 +
10552 +       /* pass vxi and data (void *) */
10553 +
10554 +#define __VXH_DATA                             \
10555 +       __vxh_copy_vxi(entry, vxi);             \
10556 +       entry->sc.data = data
10557 +
10558 +static inline
10559 +void   __vxh_data(struct vx_info *vxi, void *data,
10560 +                       int __type, void *__here)
10561 +{
10562 +       __VXH_BODY(__type, __VXH_DATA, __here)
10563 +}
10564 +
10565 +       /* pass vxi and arg (long) */
10566 +
10567 +#define __VXH_LONG                             \
10568 +       __vxh_copy_vxi(entry, vxi);             \
10569 +       entry->ll.arg = arg
10570 +
10571 +static inline
10572 +void   __vxh_long(struct vx_info *vxi, long arg,
10573 +                       int __type, void *__here)
10574 +{
10575 +       __VXH_BODY(__type, __VXH_LONG, __here)
10576 +}
10577 +
10578 +
10579 +static inline
10580 +void   __vxh_throw_oops(void *__here)
10581 +{
10582 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10583 +       /* prevent further acquisition */
10584 +       vxh_active = 0;
10585 +}
10586 +
10587 +
10588 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10589 +
10590 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10591 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10592 +
10593 +#define __vxh_init_vx_info(v, d, h) \
10594 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10595 +#define __vxh_set_vx_info(v, d, h) \
10596 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10597 +#define __vxh_clr_vx_info(v, d, h) \
10598 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10599 +
10600 +#define __vxh_claim_vx_info(v, d, h) \
10601 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10602 +#define __vxh_release_vx_info(v, d, h) \
10603 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10604 +
10605 +#define vxh_alloc_vx_info(v) \
10606 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10607 +#define vxh_dealloc_vx_info(v) \
10608 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10609 +
10610 +#define vxh_hash_vx_info(v) \
10611 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10612 +#define vxh_unhash_vx_info(v) \
10613 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10614 +
10615 +#define vxh_loc_vx_info(v, l) \
10616 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10617 +#define vxh_lookup_vx_info(v, l) \
10618 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10619 +#define vxh_create_vx_info(v, l) \
10620 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10621 +
10622 +extern void vxh_dump_history(void);
10623 +
10624 +
10625 +#else  /* CONFIG_VSERVER_HISTORY */
10626 +
10627 +#define        __HERE__        0
10628 +
10629 +#define vxh_throw_oops()               do { } while (0)
10630 +
10631 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10632 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10633 +
10634 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10635 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10636 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10637 +
10638 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10639 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10640 +
10641 +#define vxh_alloc_vx_info(v)           do { } while (0)
10642 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10643 +
10644 +#define vxh_hash_vx_info(v)            do { } while (0)
10645 +#define vxh_unhash_vx_info(v)          do { } while (0)
10646 +
10647 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10648 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10649 +#define vxh_create_vx_info(v, l)       do { } while (0)
10650 +
10651 +#define vxh_dump_history()             do { } while (0)
10652 +
10653 +
10654 +#endif /* CONFIG_VSERVER_HISTORY */
10655 +
10656 +#endif /* _VSERVER_HISTORY_H */
10657 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
10658 --- linux-3.13.10/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10659 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h      2014-01-31 20:38:03.000000000 +0000
10660 @@ -0,0 +1,19 @@
10661 +#ifndef _VSERVER_INODE_H
10662 +#define _VSERVER_INODE_H
10663 +
10664 +#include <uapi/vserver/inode.h>
10665 +
10666 +
10667 +#ifdef CONFIG_VSERVER_PROC_SECURE
10668 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10669 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10670 +#else
10671 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10672 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10673 +#endif
10674 +
10675 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10676 +
10677 +#else  /* _VSERVER_INODE_H */
10678 +#warning duplicate inclusion
10679 +#endif /* _VSERVER_INODE_H */
10680 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
10681 --- linux-3.13.10/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10682 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h  2014-01-31 20:38:03.000000000 +0000
10683 @@ -0,0 +1,36 @@
10684 +#ifndef _VSERVER_INODE_CMD_H
10685 +#define _VSERVER_INODE_CMD_H
10686 +
10687 +#include <uapi/vserver/inode_cmd.h>
10688 +
10689 +
10690 +
10691 +#ifdef CONFIG_COMPAT
10692 +
10693 +#include <asm/compat.h>
10694 +
10695 +struct vcmd_ctx_iattr_v1_x32 {
10696 +       compat_uptr_t name_ptr;
10697 +       uint32_t tag;
10698 +       uint32_t flags;
10699 +       uint32_t mask;
10700 +};
10701 +
10702 +#endif /* CONFIG_COMPAT */
10703 +
10704 +#include <linux/compiler.h>
10705 +
10706 +extern int vc_get_iattr(void __user *);
10707 +extern int vc_set_iattr(void __user *);
10708 +
10709 +extern int vc_fget_iattr(uint32_t, void __user *);
10710 +extern int vc_fset_iattr(uint32_t, void __user *);
10711 +
10712 +#ifdef CONFIG_COMPAT
10713 +
10714 +extern int vc_get_iattr_x32(void __user *);
10715 +extern int vc_set_iattr_x32(void __user *);
10716 +
10717 +#endif /* CONFIG_COMPAT */
10718 +
10719 +#endif /* _VSERVER_INODE_CMD_H */
10720 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
10721 --- linux-3.13.10/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10722 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h      2014-01-31 20:38:03.000000000 +0000
10723 @@ -0,0 +1,61 @@
10724 +#ifndef _VSERVER_LIMIT_H
10725 +#define _VSERVER_LIMIT_H
10726 +
10727 +#include <uapi/vserver/limit.h>
10728 +
10729 +
10730 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10731 +
10732 +/*     keep in sync with CRLIM_INFINITY */
10733 +
10734 +#define        VLIM_INFINITY   (~0ULL)
10735 +
10736 +#include <asm/atomic.h>
10737 +#include <asm/resource.h>
10738 +
10739 +#ifndef RLIM_INFINITY
10740 +#warning RLIM_INFINITY is undefined
10741 +#endif
10742 +
10743 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10744 +
10745 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10746 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10747 +
10748 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10749 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10750 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10751 +
10752 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10753 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10754 +
10755 +typedef atomic_long_t rlim_atomic_t;
10756 +typedef unsigned long rlim_t;
10757 +
10758 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10759 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10760 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10761 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10762 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10763 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10764 +
10765 +
10766 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10767 +#define        VX_VLIM(r) ((long long)(long)(r))
10768 +#define        VX_RLIM(v) ((rlim_t)(v))
10769 +#else
10770 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10771 +               ? VLIM_INFINITY : (long long)(r))
10772 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10773 +               ? RLIM_INFINITY : (rlim_t)(v))
10774 +#endif
10775 +
10776 +struct sysinfo;
10777 +
10778 +void vx_vsi_meminfo(struct sysinfo *);
10779 +void vx_vsi_swapinfo(struct sysinfo *);
10780 +long vx_vsi_cached(struct sysinfo *);
10781 +
10782 +#define NUM_LIMITS     24
10783 +
10784 +#endif /* _VSERVER_LIMIT_H */
10785 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
10786 --- linux-3.13.10/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10787 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h  2014-01-31 20:38:03.000000000 +0000
10788 @@ -0,0 +1,35 @@
10789 +#ifndef _VSERVER_LIMIT_CMD_H
10790 +#define _VSERVER_LIMIT_CMD_H
10791 +
10792 +#include <uapi/vserver/limit_cmd.h>
10793 +
10794 +
10795 +#ifdef CONFIG_IA32_EMULATION
10796 +
10797 +struct vcmd_ctx_rlimit_v0_x32 {
10798 +       uint32_t id;
10799 +       uint64_t minimum;
10800 +       uint64_t softlimit;
10801 +       uint64_t maximum;
10802 +} __attribute__ ((packed));
10803 +
10804 +#endif /* CONFIG_IA32_EMULATION */
10805 +
10806 +#include <linux/compiler.h>
10807 +
10808 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10809 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10810 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10811 +extern int vc_reset_hits(struct vx_info *, void __user *);
10812 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10813 +
10814 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10815 +
10816 +#ifdef CONFIG_IA32_EMULATION
10817 +
10818 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10819 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10820 +
10821 +#endif /* CONFIG_IA32_EMULATION */
10822 +
10823 +#endif /* _VSERVER_LIMIT_CMD_H */
10824 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
10825 --- linux-3.13.10/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10826 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h  2014-01-31 20:38:03.000000000 +0000
10827 @@ -0,0 +1,47 @@
10828 +#ifndef _VSERVER_LIMIT_DEF_H
10829 +#define _VSERVER_LIMIT_DEF_H
10830 +
10831 +#include <asm/atomic.h>
10832 +#include <asm/resource.h>
10833 +
10834 +#include "limit.h"
10835 +
10836 +
10837 +struct _vx_res_limit {
10838 +       rlim_t soft;            /* Context soft limit */
10839 +       rlim_t hard;            /* Context hard limit */
10840 +
10841 +       rlim_atomic_t rcur;     /* Current value */
10842 +       rlim_t rmin;            /* Context minimum */
10843 +       rlim_t rmax;            /* Context maximum */
10844 +
10845 +       atomic_t lhit;          /* Limit hits */
10846 +};
10847 +
10848 +/* context sub struct */
10849 +
10850 +struct _vx_limit {
10851 +       struct _vx_res_limit res[NUM_LIMITS];
10852 +};
10853 +
10854 +#ifdef CONFIG_VSERVER_DEBUG
10855 +
10856 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10857 +{
10858 +       int i;
10859 +
10860 +       printk("\t_vx_limit:");
10861 +       for (i = 0; i < NUM_LIMITS; i++) {
10862 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10863 +                       i, (unsigned long)__rlim_get(limit, i),
10864 +                       (unsigned long)__rlim_rmin(limit, i),
10865 +                       (unsigned long)__rlim_rmax(limit, i),
10866 +                       (long)__rlim_soft(limit, i),
10867 +                       (long)__rlim_hard(limit, i),
10868 +                       atomic_read(&__rlim_lhit(limit, i)));
10869 +       }
10870 +}
10871 +
10872 +#endif
10873 +
10874 +#endif /* _VSERVER_LIMIT_DEF_H */
10875 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
10876 --- linux-3.13.10/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10877 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h  2014-01-31 20:38:03.000000000 +0000
10878 @@ -0,0 +1,193 @@
10879 +#ifndef _VSERVER_LIMIT_INT_H
10880 +#define _VSERVER_LIMIT_INT_H
10881 +
10882 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10883 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10884 +
10885 +extern const char *vlimit_name[NUM_LIMITS];
10886 +
10887 +static inline void __vx_acc_cres(struct vx_info *vxi,
10888 +       int res, int dir, void *_data, char *_file, int _line)
10889 +{
10890 +       if (VXD_RCRES_COND(res))
10891 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10892 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10893 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10894 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10895 +       if (!vxi)
10896 +               return;
10897 +
10898 +       if (dir > 0)
10899 +               __rlim_inc(&vxi->limit, res);
10900 +       else
10901 +               __rlim_dec(&vxi->limit, res);
10902 +}
10903 +
10904 +static inline void __vx_add_cres(struct vx_info *vxi,
10905 +       int res, int amount, void *_data, char *_file, int _line)
10906 +{
10907 +       if (VXD_RCRES_COND(res))
10908 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10909 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10910 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10911 +                       amount, _data, _file, _line);
10912 +       if (amount == 0)
10913 +               return;
10914 +       if (!vxi)
10915 +               return;
10916 +       __rlim_add(&vxi->limit, res, amount);
10917 +}
10918 +
10919 +static inline
10920 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10921 +{
10922 +       int cond = (value > __rlim_rmax(limit, res));
10923 +
10924 +       if (cond)
10925 +               __rlim_rmax(limit, res) = value;
10926 +       return cond;
10927 +}
10928 +
10929 +static inline
10930 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10931 +{
10932 +       int cond = (value < __rlim_rmin(limit, res));
10933 +
10934 +       if (cond)
10935 +               __rlim_rmin(limit, res) = value;
10936 +       return cond;
10937 +}
10938 +
10939 +static inline
10940 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10941 +{
10942 +       if (!__vx_cres_adjust_max(limit, res, value))
10943 +               __vx_cres_adjust_min(limit, res, value);
10944 +}
10945 +
10946 +
10947 +/*     return values:
10948 +        +1 ... no limit hit
10949 +        -1 ... over soft limit
10950 +         0 ... over hard limit         */
10951 +
10952 +static inline int __vx_cres_avail(struct vx_info *vxi,
10953 +       int res, int num, char *_file, int _line)
10954 +{
10955 +       struct _vx_limit *limit;
10956 +       rlim_t value;
10957 +
10958 +       if (VXD_RLIMIT_COND(res))
10959 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10960 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10961 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10962 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10963 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10964 +                       num, _file, _line);
10965 +       if (!vxi)
10966 +               return 1;
10967 +
10968 +       limit = &vxi->limit;
10969 +       value = __rlim_get(limit, res);
10970 +
10971 +       if (!__vx_cres_adjust_max(limit, res, value))
10972 +               __vx_cres_adjust_min(limit, res, value);
10973 +
10974 +       if (num == 0)
10975 +               return 1;
10976 +
10977 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
10978 +               return -1;
10979 +       if (value + num <= __rlim_soft(limit, res))
10980 +               return -1;
10981 +
10982 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
10983 +               return 1;
10984 +       if (value + num <= __rlim_hard(limit, res))
10985 +               return 1;
10986 +
10987 +       __rlim_hit(limit, res);
10988 +       return 0;
10989 +}
10990 +
10991 +
10992 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10993 +
10994 +static inline
10995 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10996 +{
10997 +       rlim_t value, sum = 0;
10998 +       int res;
10999 +
11000 +       while ((res = *array++)) {
11001 +               value = __rlim_get(limit, res);
11002 +               __vx_cres_fixup(limit, res, value);
11003 +               sum += value;
11004 +       }
11005 +       return sum;
11006 +}
11007 +
11008 +static inline
11009 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11010 +{
11011 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11012 +       int res = *array;
11013 +
11014 +       if (value == __rlim_get(limit, res))
11015 +               return value;
11016 +
11017 +       __rlim_set(limit, res, value);
11018 +       /* now adjust min/max */
11019 +       if (!__vx_cres_adjust_max(limit, res, value))
11020 +               __vx_cres_adjust_min(limit, res, value);
11021 +
11022 +       return value;
11023 +}
11024 +
11025 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11026 +       const int *array, int num, char *_file, int _line)
11027 +{
11028 +       struct _vx_limit *limit;
11029 +       rlim_t value = 0;
11030 +       int res;
11031 +
11032 +       if (num == 0)
11033 +               return 1;
11034 +       if (!vxi)
11035 +               return 1;
11036 +
11037 +       limit = &vxi->limit;
11038 +       res = *array;
11039 +       value = __vx_cres_array_sum(limit, array + 1);
11040 +
11041 +       __rlim_set(limit, res, value);
11042 +       __vx_cres_fixup(limit, res, value);
11043 +
11044 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11045 +}
11046 +
11047 +
11048 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11049 +{
11050 +       rlim_t value;
11051 +       int res;
11052 +
11053 +       /* complex resources first */
11054 +       if ((id < 0) || (id == RLIMIT_RSS))
11055 +               __vx_cres_array_fixup(limit, VLA_RSS);
11056 +
11057 +       for (res = 0; res < NUM_LIMITS; res++) {
11058 +               if ((id > 0) && (res != id))
11059 +                       continue;
11060 +
11061 +               value = __rlim_get(limit, res);
11062 +               __vx_cres_fixup(limit, res, value);
11063 +
11064 +               /* not supposed to happen, maybe warn? */
11065 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11066 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11067 +       }
11068 +}
11069 +
11070 +
11071 +#endif /* _VSERVER_LIMIT_INT_H */
11072 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
11073 --- linux-3.13.10/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11074 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h    2014-01-31 20:38:03.000000000 +0000
11075 @@ -0,0 +1,6 @@
11076 +#ifndef _VSERVER_MONITOR_H
11077 +#define _VSERVER_MONITOR_H
11078 +
11079 +#include <uapi/vserver/monitor.h>
11080 +
11081 +#endif /* _VSERVER_MONITOR_H */
11082 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
11083 --- linux-3.13.10/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11084 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h    2014-01-31 20:38:03.000000000 +0000
11085 @@ -0,0 +1,76 @@
11086 +#ifndef _VSERVER_NETWORK_H
11087 +#define _VSERVER_NETWORK_H
11088 +
11089 +
11090 +#include <linux/list.h>
11091 +#include <linux/spinlock.h>
11092 +#include <linux/rcupdate.h>
11093 +#include <linux/in.h>
11094 +#include <linux/in6.h>
11095 +#include <asm/atomic.h>
11096 +#include <uapi/vserver/network.h>
11097 +
11098 +struct nx_addr_v4 {
11099 +       struct nx_addr_v4 *next;
11100 +       struct in_addr ip[2];
11101 +       struct in_addr mask;
11102 +       uint16_t type;
11103 +       uint16_t flags;
11104 +};
11105 +
11106 +struct nx_addr_v6 {
11107 +       struct nx_addr_v6 *next;
11108 +       struct in6_addr ip;
11109 +       struct in6_addr mask;
11110 +       uint32_t prefix;
11111 +       uint16_t type;
11112 +       uint16_t flags;
11113 +};
11114 +
11115 +struct nx_info {
11116 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11117 +       vnid_t nx_id;                   /* vnet id */
11118 +       atomic_t nx_usecnt;             /* usage count */
11119 +       atomic_t nx_tasks;              /* tasks count */
11120 +       int nx_state;                   /* context state */
11121 +
11122 +       uint64_t nx_flags;              /* network flag word */
11123 +       uint64_t nx_ncaps;              /* network capabilities */
11124 +
11125 +       spinlock_t addr_lock;           /* protect address changes */
11126 +       struct in_addr v4_lback;        /* Loopback address */
11127 +       struct in_addr v4_bcast;        /* Broadcast address */
11128 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11129 +#ifdef CONFIG_IPV6
11130 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11131 +#endif
11132 +       char nx_name[65];               /* network context name */
11133 +};
11134 +
11135 +
11136 +/* status flags */
11137 +
11138 +#define NXS_HASHED      0x0001
11139 +#define NXS_SHUTDOWN    0x0100
11140 +#define NXS_RELEASED    0x8000
11141 +
11142 +extern struct nx_info *lookup_nx_info(int);
11143 +
11144 +extern int get_nid_list(int, unsigned int *, int);
11145 +extern int nid_is_hashed(vnid_t);
11146 +
11147 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11148 +
11149 +extern long vs_net_change(struct nx_info *, unsigned int);
11150 +
11151 +struct sock;
11152 +
11153 +
11154 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11155 +#ifdef  CONFIG_IPV6
11156 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11157 +#else
11158 +#define NX_IPV6(n)     (0)
11159 +#endif
11160 +
11161 +#endif /* _VSERVER_NETWORK_H */
11162 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
11163 --- linux-3.13.10/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11164 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h        2014-01-31 20:38:03.000000000 +0000
11165 @@ -0,0 +1,37 @@
11166 +#ifndef _VSERVER_NETWORK_CMD_H
11167 +#define _VSERVER_NETWORK_CMD_H
11168 +
11169 +#include <uapi/vserver/network_cmd.h>
11170 +
11171 +extern int vc_task_nid(uint32_t);
11172 +
11173 +extern int vc_nx_info(struct nx_info *, void __user *);
11174 +
11175 +extern int vc_net_create(uint32_t, void __user *);
11176 +extern int vc_net_migrate(struct nx_info *, void __user *);
11177 +
11178 +extern int vc_net_add(struct nx_info *, void __user *);
11179 +extern int vc_net_remove(struct nx_info *, void __user *);
11180 +
11181 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11182 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11183 +
11184 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11185 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11186 +
11187 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11188 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11189 +
11190 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11191 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11192 +
11193 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11194 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11195 +
11196 +extern int vc_get_nflags(struct nx_info *, void __user *);
11197 +extern int vc_set_nflags(struct nx_info *, void __user *);
11198 +
11199 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11200 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11201 +
11202 +#endif /* _VSERVER_CONTEXT_CMD_H */
11203 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
11204 --- linux-3.13.10/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11205 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h     2014-01-31 20:38:03.000000000 +0000
11206 @@ -0,0 +1,14 @@
11207 +#ifndef _VSERVER_PERCPU_H
11208 +#define _VSERVER_PERCPU_H
11209 +
11210 +#include "cvirt_def.h"
11211 +#include "sched_def.h"
11212 +
11213 +struct _vx_percpu {
11214 +       struct _vx_cvirt_pc cvirt;
11215 +       struct _vx_sched_pc sched;
11216 +};
11217 +
11218 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11219 +
11220 +#endif /* _VSERVER_PERCPU_H */
11221 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
11222 --- linux-3.13.10/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11223 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h        2014-01-31 20:38:03.000000000 +0000
11224 @@ -0,0 +1,51 @@
11225 +#ifndef _VSERVER_PID_H
11226 +#define _VSERVER_PID_H
11227 +
11228 +/* pid faking stuff */
11229 +
11230 +#define vx_info_map_pid(v, p) \
11231 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11232 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11233 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11234 +#define vx_map_tgid(p) vx_map_pid(p)
11235 +
11236 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11237 +       const char *func, const char *file, int line)
11238 +{
11239 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11240 +               vxfprintk(VXD_CBIT(cvirt, 2),
11241 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11242 +                       vxi, (long long)vxi->vx_flags, pid,
11243 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11244 +                       func, file, line);
11245 +               if (pid == 0)
11246 +                       return 0;
11247 +               if (pid == vxi->vx_initpid)
11248 +                       return 1;
11249 +       }
11250 +       return pid;
11251 +}
11252 +
11253 +#define vx_info_rmap_pid(v, p) \
11254 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11255 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11256 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11257 +
11258 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11259 +       const char *func, const char *file, int line)
11260 +{
11261 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11262 +               vxfprintk(VXD_CBIT(cvirt, 2),
11263 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11264 +                       vxi, (long long)vxi->vx_flags, pid,
11265 +                       (pid == 1) ? vxi->vx_initpid : pid,
11266 +                       func, file, line);
11267 +               if ((pid == 1) && vxi->vx_initpid)
11268 +                       return vxi->vx_initpid;
11269 +               if (pid == vxi->vx_initpid)
11270 +                       return ~0U;
11271 +       }
11272 +       return pid;
11273 +}
11274 +
11275 +#endif
11276 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
11277 --- linux-3.13.10/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11278 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h      2014-01-31 20:38:03.000000000 +0000
11279 @@ -0,0 +1,23 @@
11280 +#ifndef _VSERVER_SCHED_H
11281 +#define _VSERVER_SCHED_H
11282 +
11283 +
11284 +#ifdef __KERNEL__
11285 +
11286 +struct timespec;
11287 +
11288 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11289 +
11290 +
11291 +struct vx_info;
11292 +
11293 +void vx_update_load(struct vx_info *);
11294 +
11295 +
11296 +void vx_update_sched_param(struct _vx_sched *sched,
11297 +       struct _vx_sched_pc *sched_pc);
11298 +
11299 +#endif /* __KERNEL__ */
11300 +#else  /* _VSERVER_SCHED_H */
11301 +#warning duplicate inclusion
11302 +#endif /* _VSERVER_SCHED_H */
11303 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
11304 --- linux-3.13.10/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
11305 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h  2014-01-31 20:38:03.000000000 +0000
11306 @@ -0,0 +1,11 @@
11307 +#ifndef _VSERVER_SCHED_CMD_H
11308 +#define _VSERVER_SCHED_CMD_H
11309 +
11310 +
11311 +#include <linux/compiler.h>
11312 +#include <uapi/vserver/sched_cmd.h>
11313 +
11314 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11315 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11316 +
11317 +#endif /* _VSERVER_SCHED_CMD_H */
11318 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
11319 --- linux-3.13.10/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11320 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h  2014-01-31 20:38:03.000000000 +0000
11321 @@ -0,0 +1,38 @@
11322 +#ifndef _VSERVER_SCHED_DEF_H
11323 +#define _VSERVER_SCHED_DEF_H
11324 +
11325 +#include <linux/spinlock.h>
11326 +#include <linux/jiffies.h>
11327 +#include <linux/cpumask.h>
11328 +#include <asm/atomic.h>
11329 +#include <asm/param.h>
11330 +
11331 +
11332 +/* context sub struct */
11333 +
11334 +struct _vx_sched {
11335 +       int prio_bias;                  /* bias offset for priority */
11336 +
11337 +       cpumask_t update;               /* CPUs which should update */
11338 +};
11339 +
11340 +struct _vx_sched_pc {
11341 +       int prio_bias;                  /* bias offset for priority */
11342 +
11343 +       uint64_t user_ticks;            /* token tick events */
11344 +       uint64_t sys_ticks;             /* token tick events */
11345 +       uint64_t hold_ticks;            /* token ticks paused */
11346 +};
11347 +
11348 +
11349 +#ifdef CONFIG_VSERVER_DEBUG
11350 +
11351 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11352 +{
11353 +       printk("\t_vx_sched:\n");
11354 +       printk("\t priority = %4d\n", sched->prio_bias);
11355 +}
11356 +
11357 +#endif
11358 +
11359 +#endif /* _VSERVER_SCHED_DEF_H */
11360 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
11361 --- linux-3.13.10/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11362 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h     2014-01-31 20:38:03.000000000 +0000
11363 @@ -0,0 +1,14 @@
11364 +#ifndef _VSERVER_SIGNAL_H
11365 +#define _VSERVER_SIGNAL_H
11366 +
11367 +
11368 +#ifdef __KERNEL__
11369 +
11370 +struct vx_info;
11371 +
11372 +int vx_info_kill(struct vx_info *, int, int);
11373 +
11374 +#endif /* __KERNEL__ */
11375 +#else  /* _VSERVER_SIGNAL_H */
11376 +#warning duplicate inclusion
11377 +#endif /* _VSERVER_SIGNAL_H */
11378 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
11379 --- linux-3.13.10/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11380 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11381 @@ -0,0 +1,14 @@
11382 +#ifndef _VSERVER_SIGNAL_CMD_H
11383 +#define _VSERVER_SIGNAL_CMD_H
11384 +
11385 +#include <uapi/vserver/signal_cmd.h>
11386 +
11387 +
11388 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11389 +extern int vc_wait_exit(struct vx_info *, void __user *);
11390 +
11391 +
11392 +extern int vc_get_pflags(uint32_t pid, void __user *);
11393 +extern int vc_set_pflags(uint32_t pid, void __user *);
11394 +
11395 +#endif /* _VSERVER_SIGNAL_CMD_H */
11396 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
11397 --- linux-3.13.10/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11398 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h      2014-01-31 20:38:03.000000000 +0000
11399 @@ -0,0 +1,12 @@
11400 +#ifndef _VSERVER_SPACE_H
11401 +#define _VSERVER_SPACE_H
11402 +
11403 +#include <linux/types.h>
11404 +
11405 +struct vx_info;
11406 +
11407 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11408 +
11409 +#else  /* _VSERVER_SPACE_H */
11410 +#warning duplicate inclusion
11411 +#endif /* _VSERVER_SPACE_H */
11412 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
11413 --- linux-3.13.10/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11414 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h  2014-01-31 20:38:03.000000000 +0000
11415 @@ -0,0 +1,13 @@
11416 +#ifndef _VSERVER_SPACE_CMD_H
11417 +#define _VSERVER_SPACE_CMD_H
11418 +
11419 +#include <uapi/vserver/space_cmd.h>
11420 +
11421 +
11422 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11423 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11424 +extern int vc_enter_space(struct vx_info *, void __user *);
11425 +extern int vc_set_space(struct vx_info *, void __user *);
11426 +extern int vc_get_space_mask(void __user *, int);
11427 +
11428 +#endif /* _VSERVER_SPACE_CMD_H */
11429 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
11430 --- linux-3.13.10/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11431 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h     2014-01-31 20:38:03.000000000 +0000
11432 @@ -0,0 +1,8 @@
11433 +#ifndef _VSERVER_SWITCH_H
11434 +#define _VSERVER_SWITCH_H
11435 +
11436 +
11437 +#include <linux/errno.h>
11438 +#include <uapi/vserver/switch.h>
11439 +
11440 +#endif /* _VSERVER_SWITCH_H */
11441 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
11442 --- linux-3.13.10/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11443 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h        2014-01-31 20:38:03.000000000 +0000
11444 @@ -0,0 +1,160 @@
11445 +#ifndef _DX_TAG_H
11446 +#define _DX_TAG_H
11447 +
11448 +#include <linux/types.h>
11449 +#include <linux/uidgid.h>
11450 +
11451 +
11452 +#define DX_TAG(in)     (IS_TAGGED(in))
11453 +
11454 +
11455 +#ifdef CONFIG_TAG_NFSD
11456 +#define DX_TAG_NFSD    1
11457 +#else
11458 +#define DX_TAG_NFSD    0
11459 +#endif
11460 +
11461 +
11462 +#ifdef CONFIG_TAGGING_NONE
11463 +
11464 +#define MAX_UID                0xFFFFFFFF
11465 +#define MAX_GID                0xFFFFFFFF
11466 +
11467 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11468 +
11469 +#define TAGINO_UID(cond, uid, tag)     (uid)
11470 +#define TAGINO_GID(cond, gid, tag)     (gid)
11471 +
11472 +#endif
11473 +
11474 +
11475 +#ifdef CONFIG_TAGGING_GID16
11476 +
11477 +#define MAX_UID                0xFFFFFFFF
11478 +#define MAX_GID                0x0000FFFF
11479 +
11480 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11481 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11482 +
11483 +#define TAGINO_UID(cond, uid, tag)     (uid)
11484 +#define TAGINO_GID(cond, gid, tag)     \
11485 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11486 +
11487 +#endif
11488 +
11489 +
11490 +#ifdef CONFIG_TAGGING_ID24
11491 +
11492 +#define MAX_UID                0x00FFFFFF
11493 +#define MAX_GID                0x00FFFFFF
11494 +
11495 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11496 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11497 +
11498 +#define TAGINO_UID(cond, uid, tag)     \
11499 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11500 +#define TAGINO_GID(cond, gid, tag)     \
11501 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11502 +
11503 +#endif
11504 +
11505 +
11506 +#ifdef CONFIG_TAGGING_UID16
11507 +
11508 +#define MAX_UID                0x0000FFFF
11509 +#define MAX_GID                0xFFFFFFFF
11510 +
11511 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11512 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11513 +
11514 +#define TAGINO_UID(cond, uid, tag)     \
11515 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11516 +#define TAGINO_GID(cond, gid, tag)     (gid)
11517 +
11518 +#endif
11519 +
11520 +
11521 +#ifdef CONFIG_TAGGING_INTERN
11522 +
11523 +#define MAX_UID                0xFFFFFFFF
11524 +#define MAX_GID                0xFFFFFFFF
11525 +
11526 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11527 +       ((cond) ? (tag) : 0)
11528 +
11529 +#define TAGINO_UID(cond, uid, tag)     (uid)
11530 +#define TAGINO_GID(cond, gid, tag)     (gid)
11531 +
11532 +#endif
11533 +
11534 +
11535 +#ifndef CONFIG_TAGGING_NONE
11536 +#define dx_current_fstag(sb)   \
11537 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11538 +#else
11539 +#define dx_current_fstag(sb)   (0)
11540 +#endif
11541 +
11542 +#ifndef CONFIG_TAGGING_INTERN
11543 +#define TAGINO_TAG(cond, tag)  (0)
11544 +#else
11545 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11546 +#endif
11547 +
11548 +#define TAGINO_KUID(cond, kuid, ktag)  \
11549 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11550 +#define TAGINO_KGID(cond, kgid, ktag)  \
11551 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11552 +#define TAGINO_KTAG(cond, ktag)                \
11553 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11554 +
11555 +
11556 +#define INOTAG_UID(cond, uid, gid)     \
11557 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11558 +#define INOTAG_GID(cond, uid, gid)     \
11559 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11560 +
11561 +#define INOTAG_KUID(cond, kuid, kgid)  \
11562 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11563 +#define INOTAG_KGID(cond, kuid, kgid)  \
11564 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11565 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11566 +       KTAGT_INIT(INOTAG_TAG(cond, \
11567 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11568 +
11569 +
11570 +static inline uid_t dx_map_uid(uid_t uid)
11571 +{
11572 +       if ((uid > MAX_UID) && (uid != -1))
11573 +               uid = -2;
11574 +       return (uid & MAX_UID);
11575 +}
11576 +
11577 +static inline gid_t dx_map_gid(gid_t gid)
11578 +{
11579 +       if ((gid > MAX_GID) && (gid != -1))
11580 +               gid = -2;
11581 +       return (gid & MAX_GID);
11582 +}
11583 +
11584 +struct peer_tag {
11585 +       int32_t xid;
11586 +       int32_t nid;
11587 +};
11588 +
11589 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11590 +
11591 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11592 +                unsigned long *flags);
11593 +
11594 +#ifdef CONFIG_PROPAGATE
11595 +
11596 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11597 +
11598 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11599 +
11600 +#else
11601 +#define dx_propagate_tag(n, i) do { } while (0)
11602 +#endif
11603 +
11604 +#endif /* _DX_TAG_H */
11605 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
11606 --- linux-3.13.10/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11607 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h    2014-01-31 20:38:03.000000000 +0000
11608 @@ -0,0 +1,10 @@
11609 +#ifndef _VSERVER_TAG_CMD_H
11610 +#define _VSERVER_TAG_CMD_H
11611 +
11612 +#include <uapi/vserver/tag_cmd.h>
11613 +
11614 +extern int vc_task_tag(uint32_t);
11615 +
11616 +extern int vc_tag_migrate(uint32_t);
11617 +
11618 +#endif /* _VSERVER_TAG_CMD_H */
11619 diff -NurpP --minimal linux-3.13.10/include/net/addrconf.h linux-3.13.10-vs2.3.6.11/include/net/addrconf.h
11620 --- linux-3.13.10/include/net/addrconf.h        2013-11-25 15:47:02.000000000 +0000
11621 +++ linux-3.13.10-vs2.3.6.11/include/net/addrconf.h     2014-01-31 20:39:35.000000000 +0000
11622 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11623  
11624  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11625                        const struct in6_addr *daddr, unsigned int srcprefs,
11626 -                      struct in6_addr *saddr);
11627 +                      struct in6_addr *saddr, struct nx_info *nxi);
11628  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11629                       unsigned char banned_flags);
11630  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11631 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
11632 --- linux-3.13.10/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11633 +++ linux-3.13.10-vs2.3.6.11/include/net/af_unix.h      2014-01-31 20:38:03.000000000 +0000
11634 @@ -4,6 +4,7 @@
11635  #include <linux/socket.h>
11636  #include <linux/un.h>
11637  #include <linux/mutex.h>
11638 +#include <linux/vs_base.h>
11639  #include <net/sock.h>
11640  
11641  void unix_inflight(struct file *fp);
11642 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
11643 --- linux-3.13.10/include/net/inet_timewait_sock.h      2014-01-22 20:39:11.000000000 +0000
11644 +++ linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h   2014-01-31 20:40:30.000000000 +0000
11645 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11646  #define tw_v6_rcv_saddr        __tw_common.skc_v6_rcv_saddr
11647  #define tw_dport               __tw_common.skc_dport
11648  #define tw_num                 __tw_common.skc_num
11649 +#define tw_xid                 __tw_common.skc_xid
11650 +#define tw_vx_info             __tw_common.skc_vx_info
11651 +#define tw_nid                 __tw_common.skc_nid
11652 +#define tw_nx_info             __tw_common.skc_nx_info
11653  
11654         int                     tw_timeout;
11655         volatile unsigned char  tw_substate;
11656 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
11657 --- linux-3.13.10/include/net/ip6_route.h       2014-01-22 20:39:11.000000000 +0000
11658 +++ linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h    2014-01-31 20:41:10.000000000 +0000
11659 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11660  
11661  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11662                         const struct in6_addr *daddr, unsigned int prefs,
11663 -                       struct in6_addr *saddr);
11664 +                       struct in6_addr *saddr, struct nx_info *nxi);
11665  
11666  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11667                             const struct in6_addr *saddr, int oif, int flags);
11668 diff -NurpP --minimal linux-3.13.10/include/net/route.h linux-3.13.10-vs2.3.6.11/include/net/route.h
11669 --- linux-3.13.10/include/net/route.h   2014-01-22 20:39:12.000000000 +0000
11670 +++ linux-3.13.10-vs2.3.6.11/include/net/route.h        2014-02-01 12:30:58.000000000 +0000
11671 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11672         dst_release(&rt->dst);
11673  }
11674  
11675 +#include <linux/vs_base.h>
11676 +#include <linux/vs_inet.h>
11677 +
11678  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11679  
11680  extern const __u8 ip_tos2prio[16];
11681 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11682                            protocol, flow_flags, dst, src, dport, sport);
11683  }
11684  
11685 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11686 +       struct flowi4 *);
11687 +
11688  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11689                                               __be32 dst, __be32 src, u32 tos,
11690                                               int oif, u8 protocol,
11691 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11692  {
11693         struct net *net = sock_net(sk);
11694         struct rtable *rt;
11695 +       struct nx_info *nx_info = current_nx_info();
11696  
11697         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11698                               sport, dport, sk);
11699  
11700 -       if (!dst || !src) {
11701 +       if (sk)
11702 +               nx_info = sk->sk_nx_info;
11703 +
11704 +       vxdprintk(VXD_CBIT(net, 4),
11705 +               "ip_route_connect(%p) %p,%p;%lx",
11706 +               sk, nx_info, sk->sk_socket,
11707 +               (sk->sk_socket?sk->sk_socket->flags:0));
11708 +
11709 +       rt = ip_v4_find_src(net, nx_info, fl4);
11710 +       if (IS_ERR(rt))
11711 +               return rt;
11712 +       ip_rt_put(rt);
11713 +
11714 +       if (!fl4->daddr || !fl4->saddr) {
11715                 rt = __ip_route_output_key(net, fl4);
11716                 if (IS_ERR(rt))
11717                         return rt;
11718 diff -NurpP --minimal linux-3.13.10/include/net/sock.h linux-3.13.10-vs2.3.6.11/include/net/sock.h
11719 --- linux-3.13.10/include/net/sock.h    2014-04-17 01:12:39.000000000 +0000
11720 +++ linux-3.13.10-vs2.3.6.11/include/net/sock.h 2014-04-17 01:17:10.000000000 +0000
11721 @@ -191,6 +191,10 @@ struct sock_common {
11722  #ifdef CONFIG_NET_NS
11723         struct net              *skc_net;
11724  #endif
11725 +       vxid_t                  skc_xid;
11726 +       struct vx_info          *skc_vx_info;
11727 +       vnid_t                  skc_nid;
11728 +       struct nx_info          *skc_nx_info;
11729  
11730  #if IS_ENABLED(CONFIG_IPV6)
11731         struct in6_addr         skc_v6_daddr;
11732 @@ -321,7 +325,11 @@ struct sock {
11733  #define sk_prot                        __sk_common.skc_prot
11734  #define sk_net                 __sk_common.skc_net
11735  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11736 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11737 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11738 +#define sk_xid                 __sk_common.skc_xid
11739 +#define sk_vx_info             __sk_common.skc_vx_info
11740 +#define sk_nid                 __sk_common.skc_nid
11741 +#define sk_nx_info             __sk_common.skc_nx_info
11742  
11743         socket_lock_t           sk_lock;
11744         struct sk_buff_head     sk_receive_queue;
11745 diff -NurpP --minimal linux-3.13.10/include/uapi/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild
11746 --- linux-3.13.10/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
11747 +++ linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild        2014-01-31 20:38:03.000000000 +0000
11748 @@ -12,3 +12,4 @@ header-y += video/
11749  header-y += drm/
11750  header-y += xen/
11751  header-y += scsi/
11752 +header-y += vserver/
11753 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
11754 --- linux-3.13.10/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
11755 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h    2014-01-31 20:38:03.000000000 +0000
11756 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11757     arbitrary SCSI commands */
11758  /* Allow setting encryption key on loopback filesystem */
11759  /* Allow setting zone reclaim policy */
11760 +/* Allow the selection of a security context */
11761  
11762  #define CAP_SYS_ADMIN        21
11763  
11764 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11765  
11766  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
11767  
11768 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11769 +/* Allow context manipulations */
11770 +/* Allow changing context info on files */
11771 +
11772 +#define CAP_CONTEXT         63
11773 +
11774 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11775  
11776  /*
11777   * Bit location of each capability (used by user-space library and kernel)
11778 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
11779 --- linux-3.13.10/include/uapi/linux/fs.h       2013-11-25 15:47:02.000000000 +0000
11780 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h    2014-01-31 20:38:03.000000000 +0000
11781 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11782  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
11783  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11784  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11785 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11786 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11787 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11788  
11789  /* These sb flags are internal to the kernel */
11790  #define MS_NOSEC       (1<<28)
11791 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11792  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11793  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11794  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11795 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11796  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11797  
11798 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11799 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11800 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11801 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11802  
11803 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11804 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11805  
11806  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11807  #define SYNC_FILE_RANGE_WRITE          2
11808 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
11809 --- linux-3.13.10/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
11810 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h   2014-01-31 20:38:03.000000000 +0000
11811 @@ -225,6 +225,9 @@ enum {
11812         gfs2fl_Sync             = 8,
11813         gfs2fl_System           = 9,
11814         gfs2fl_TopLevel         = 10,
11815 +       gfs2fl_IXUnlink         = 16,
11816 +       gfs2fl_Barrier          = 17,
11817 +       gfs2fl_Cow              = 18,
11818         gfs2fl_TruncInProg      = 29,
11819         gfs2fl_InheritDirectio  = 30,
11820         gfs2fl_InheritJdata     = 31,
11821 @@ -242,6 +245,9 @@ enum {
11822  #define GFS2_DIF_SYNC                  0x00000100
11823  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11824  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11825 +#define GFS2_DIF_IXUNLINK               0x00010000
11826 +#define GFS2_DIF_BARRIER                0x00020000
11827 +#define GFS2_DIF_COW                    0x00040000
11828  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11829  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11830  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11831 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
11832 --- linux-3.13.10/include/uapi/linux/if_tun.h   2013-11-25 15:47:02.000000000 +0000
11833 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h        2014-01-31 20:45:49.000000000 +0000
11834 @@ -58,6 +58,7 @@
11835  #define TUNSETQUEUE  _IOW('T', 217, int)
11836  #define TUNSETIFINDEX  _IOW('T', 218, unsigned int)
11837  #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11838 +#define TUNSETNID     _IOW('T', 220, int)
11839  
11840  /* TUNSETIFF ifr flags */
11841  #define IFF_TUN                0x0001
11842 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
11843 --- linux-3.13.10/include/uapi/linux/major.h    2014-01-22 20:39:12.000000000 +0000
11844 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11845 @@ -15,6 +15,7 @@
11846  #define HD_MAJOR               IDE0_MAJOR
11847  #define PTY_SLAVE_MAJOR                3
11848  #define TTY_MAJOR              4
11849 +#define VROOT_MAJOR            4
11850  #define TTYAUX_MAJOR           5
11851  #define LP_MAJOR               6
11852  #define VCS_MAJOR              7
11853 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
11854 --- linux-3.13.10/include/uapi/linux/nfs_mount.h        2014-01-22 20:39:12.000000000 +0000
11855 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h     2014-01-31 20:38:03.000000000 +0000
11856 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11857  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11858  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11859  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11860 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11861 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11862 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11863  
11864  /* The following are for internal use only */
11865  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11866 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
11867 --- linux-3.13.10/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
11868 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h        2014-01-31 20:38:03.000000000 +0000
11869 @@ -33,7 +33,7 @@
11870  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11871  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11872  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11873 -
11874 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11875  
11876  
11877  #endif /* _UAPI_LINUX_REBOOT_H */
11878 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
11879 --- linux-3.13.10/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
11880 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h        2014-01-31 20:38:03.000000000 +0000
11881 @@ -60,6 +60,7 @@ enum
11882         CTL_ABI=9,              /* Binary emulation */
11883         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11884         CTL_ARLAN=254,          /* arlan wireless driver */
11885 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11886         CTL_S390DBF=5677,       /* s390 debug */
11887         CTL_SUNRPC=7249,        /* sunrpc debug */
11888         CTL_PM=9899,            /* frv power management */
11889 @@ -94,6 +95,7 @@ enum
11890  
11891         KERN_PANIC=15,          /* int: panic timeout */
11892         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11893 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11894  
11895         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11896         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11897 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild
11898 --- linux-3.13.10/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11899 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild        2014-01-31 20:38:03.000000000 +0000
11900 @@ -0,0 +1,9 @@
11901 +
11902 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11903 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11904 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11905 +       debug_cmd.h device_cmd.h
11906 +
11907 +header-y += switch.h context.h network.h monitor.h \
11908 +       limit.h inode.h device.h
11909 +
11910 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
11911 --- linux-3.13.10/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11912 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h   2014-01-31 20:38:03.000000000 +0000
11913 @@ -0,0 +1,15 @@
11914 +#ifndef _UAPI_VS_CACCT_CMD_H
11915 +#define _UAPI_VS_CACCT_CMD_H
11916 +
11917 +
11918 +/* virtual host info name commands */
11919 +
11920 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11921 +
11922 +struct vcmd_sock_stat_v0 {
11923 +       uint32_t field;
11924 +       uint32_t count[3];
11925 +       uint64_t total[3];
11926 +};
11927 +
11928 +#endif /* _UAPI_VS_CACCT_CMD_H */
11929 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
11930 --- linux-3.13.10/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11931 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h     2014-01-31 20:38:03.000000000 +0000
11932 @@ -0,0 +1,81 @@
11933 +#ifndef _UAPI_VS_CONTEXT_H
11934 +#define _UAPI_VS_CONTEXT_H
11935 +
11936 +#include <linux/types.h>
11937 +#include <linux/capability.h>
11938 +
11939 +
11940 +/* context flags */
11941 +
11942 +#define VXF_INFO_SCHED         0x00000002
11943 +#define VXF_INFO_NPROC         0x00000004
11944 +#define VXF_INFO_PRIVATE       0x00000008
11945 +
11946 +#define VXF_INFO_INIT          0x00000010
11947 +#define VXF_INFO_HIDE          0x00000020
11948 +#define VXF_INFO_ULIMIT                0x00000040
11949 +#define VXF_INFO_NSPACE                0x00000080
11950 +
11951 +#define VXF_SCHED_HARD         0x00000100
11952 +#define VXF_SCHED_PRIO         0x00000200
11953 +#define VXF_SCHED_PAUSE                0x00000400
11954 +
11955 +#define VXF_VIRT_MEM           0x00010000
11956 +#define VXF_VIRT_UPTIME                0x00020000
11957 +#define VXF_VIRT_CPU           0x00040000
11958 +#define VXF_VIRT_LOAD          0x00080000
11959 +#define VXF_VIRT_TIME          0x00100000
11960 +
11961 +#define VXF_HIDE_MOUNT         0x01000000
11962 +/* was VXF_HIDE_NETIF          0x02000000 */
11963 +#define VXF_HIDE_VINFO         0x04000000
11964 +
11965 +#define VXF_STATE_SETUP                (1ULL << 32)
11966 +#define VXF_STATE_INIT         (1ULL << 33)
11967 +#define VXF_STATE_ADMIN                (1ULL << 34)
11968 +
11969 +#define VXF_SC_HELPER          (1ULL << 36)
11970 +#define VXF_REBOOT_KILL                (1ULL << 37)
11971 +#define VXF_PERSISTENT         (1ULL << 38)
11972 +
11973 +#define VXF_FORK_RSS           (1ULL << 48)
11974 +#define VXF_PROLIFIC           (1ULL << 49)
11975 +
11976 +#define VXF_IGNEG_NICE         (1ULL << 52)
11977 +
11978 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11979 +
11980 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11981 +
11982 +
11983 +/* context migration */
11984 +
11985 +#define VXM_SET_INIT           0x00000001
11986 +#define VXM_SET_REAPER         0x00000002
11987 +
11988 +/* context caps */
11989 +
11990 +#define VXC_SET_UTSNAME                0x00000001
11991 +#define VXC_SET_RLIMIT         0x00000002
11992 +#define VXC_FS_SECURITY                0x00000004
11993 +#define VXC_FS_TRUSTED         0x00000008
11994 +#define VXC_TIOCSTI            0x00000010
11995 +
11996 +/* was VXC_RAW_ICMP            0x00000100 */
11997 +#define VXC_SYSLOG             0x00001000
11998 +#define VXC_OOM_ADJUST         0x00002000
11999 +#define VXC_AUDIT_CONTROL      0x00004000
12000 +
12001 +#define VXC_SECURE_MOUNT       0x00010000
12002 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12003 +#define VXC_BINARY_MOUNT       0x00040000
12004 +#define VXC_DEV_MOUNT          0x00080000
12005 +
12006 +#define VXC_QUOTA_CTL          0x00100000
12007 +#define VXC_ADMIN_MAPPER       0x00200000
12008 +#define VXC_ADMIN_CLOOP                0x00400000
12009 +
12010 +#define VXC_KTHREAD            0x01000000
12011 +#define VXC_NAMESPACE          0x02000000
12012 +
12013 +#endif /* _UAPI_VS_CONTEXT_H */
12014 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
12015 --- linux-3.13.10/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12016 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12017 @@ -0,0 +1,115 @@
12018 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12019 +#define _UAPI_VS_CONTEXT_CMD_H
12020 +
12021 +
12022 +/* vinfo commands */
12023 +
12024 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12025 +
12026 +
12027 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12028 +
12029 +struct vcmd_vx_info_v0 {
12030 +       uint32_t xid;
12031 +       uint32_t initpid;
12032 +       /* more to come */
12033 +};
12034 +
12035 +
12036 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12037 +
12038 +struct vcmd_ctx_stat_v0 {
12039 +       uint32_t usecnt;
12040 +       uint32_t tasks;
12041 +       /* more to come */
12042 +};
12043 +
12044 +
12045 +/* context commands */
12046 +
12047 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12048 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12049 +
12050 +struct vcmd_ctx_create {
12051 +       uint64_t flagword;
12052 +};
12053 +
12054 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12055 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12056 +
12057 +struct vcmd_ctx_migrate {
12058 +       uint64_t flagword;
12059 +};
12060 +
12061 +
12062 +
12063 +/* flag commands */
12064 +
12065 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12066 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12067 +
12068 +struct vcmd_ctx_flags_v0 {
12069 +       uint64_t flagword;
12070 +       uint64_t mask;
12071 +};
12072 +
12073 +
12074 +
12075 +/* context caps commands */
12076 +
12077 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12078 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12079 +
12080 +struct vcmd_ctx_caps_v1 {
12081 +       uint64_t ccaps;
12082 +       uint64_t cmask;
12083 +};
12084 +
12085 +
12086 +
12087 +/* bcaps commands */
12088 +
12089 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12090 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12091 +
12092 +struct vcmd_bcaps {
12093 +       uint64_t bcaps;
12094 +       uint64_t bmask;
12095 +};
12096 +
12097 +
12098 +
12099 +/* umask commands */
12100 +
12101 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12102 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12103 +
12104 +struct vcmd_umask {
12105 +       uint64_t umask;
12106 +       uint64_t mask;
12107 +};
12108 +
12109 +
12110 +
12111 +/* wmask commands */
12112 +
12113 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12114 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12115 +
12116 +struct vcmd_wmask {
12117 +       uint64_t wmask;
12118 +       uint64_t mask;
12119 +};
12120 +
12121 +
12122 +
12123 +/* OOM badness */
12124 +
12125 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12126 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12127 +
12128 +struct vcmd_badness_v0 {
12129 +       int64_t bias;
12130 +};
12131 +
12132 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12133 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
12134 --- linux-3.13.10/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12135 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h   2014-01-31 20:38:03.000000000 +0000
12136 @@ -0,0 +1,41 @@
12137 +#ifndef _UAPI_VS_CVIRT_CMD_H
12138 +#define _UAPI_VS_CVIRT_CMD_H
12139 +
12140 +
12141 +/* virtual host info name commands */
12142 +
12143 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12144 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12145 +
12146 +struct vcmd_vhi_name_v0 {
12147 +       uint32_t field;
12148 +       char name[65];
12149 +};
12150 +
12151 +
12152 +enum vhi_name_field {
12153 +       VHIN_CONTEXT = 0,
12154 +       VHIN_SYSNAME,
12155 +       VHIN_NODENAME,
12156 +       VHIN_RELEASE,
12157 +       VHIN_VERSION,
12158 +       VHIN_MACHINE,
12159 +       VHIN_DOMAINNAME,
12160 +};
12161 +
12162 +
12163 +
12164 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12165 +
12166 +struct vcmd_virt_stat_v0 {
12167 +       uint64_t offset;
12168 +       uint64_t uptime;
12169 +       uint32_t nr_threads;
12170 +       uint32_t nr_running;
12171 +       uint32_t nr_uninterruptible;
12172 +       uint32_t nr_onhold;
12173 +       uint32_t nr_forks;
12174 +       uint32_t load[3];
12175 +};
12176 +
12177 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12178 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
12179 --- linux-3.13.10/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12180 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h   2014-01-31 20:38:03.000000000 +0000
12181 @@ -0,0 +1,24 @@
12182 +#ifndef _UAPI_VS_DEBUG_CMD_H
12183 +#define _UAPI_VS_DEBUG_CMD_H
12184 +
12185 +
12186 +/* debug commands */
12187 +
12188 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12189 +
12190 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12191 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12192 +
12193 +struct  vcmd_read_history_v0 {
12194 +       uint32_t index;
12195 +       uint32_t count;
12196 +       char __user *data;
12197 +};
12198 +
12199 +struct  vcmd_read_monitor_v0 {
12200 +       uint32_t index;
12201 +       uint32_t count;
12202 +       char __user *data;
12203 +};
12204 +
12205 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12206 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
12207 --- linux-3.13.10/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12208 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h      2014-01-31 20:38:03.000000000 +0000
12209 @@ -0,0 +1,12 @@
12210 +#ifndef _UAPI_VS_DEVICE_H
12211 +#define _UAPI_VS_DEVICE_H
12212 +
12213 +
12214 +#define DATTR_CREATE   0x00000001
12215 +#define DATTR_OPEN     0x00000002
12216 +
12217 +#define DATTR_REMAP    0x00000010
12218 +
12219 +#define DATTR_MASK     0x00000013
12220 +
12221 +#endif /* _UAPI_VS_DEVICE_H */
12222 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
12223 --- linux-3.13.10/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12224 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h  2014-01-31 20:38:03.000000000 +0000
12225 @@ -0,0 +1,16 @@
12226 +#ifndef _UAPI_VS_DEVICE_CMD_H
12227 +#define _UAPI_VS_DEVICE_CMD_H
12228 +
12229 +
12230 +/*  device vserver commands */
12231 +
12232 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12233 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12234 +
12235 +struct vcmd_set_mapping_v0 {
12236 +       const char __user *device;
12237 +       const char __user *target;
12238 +       uint32_t flags;
12239 +};
12240 +
12241 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12242 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
12243 --- linux-3.13.10/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12244 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h  2014-01-31 20:38:03.000000000 +0000
12245 @@ -0,0 +1,67 @@
12246 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12247 +#define _UAPI_VS_DLIMIT_CMD_H
12248 +
12249 +
12250 +/*  dlimit vserver commands */
12251 +
12252 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12253 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12254 +
12255 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12256 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12257 +
12258 +struct vcmd_ctx_dlimit_base_v0 {
12259 +       const char __user *name;
12260 +       uint32_t flags;
12261 +};
12262 +
12263 +struct vcmd_ctx_dlimit_v0 {
12264 +       const char __user *name;
12265 +       uint32_t space_used;                    /* used space in kbytes */
12266 +       uint32_t space_total;                   /* maximum space in kbytes */
12267 +       uint32_t inodes_used;                   /* used inodes */
12268 +       uint32_t inodes_total;                  /* maximum inodes */
12269 +       uint32_t reserved;                      /* reserved for root in % */
12270 +       uint32_t flags;
12271 +};
12272 +
12273 +#define CDLIM_UNSET            ((uint32_t)0UL)
12274 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12275 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12276 +
12277 +#define DLIME_UNIT     0
12278 +#define DLIME_KILO     1
12279 +#define DLIME_MEGA     2
12280 +#define DLIME_GIGA     3
12281 +
12282 +#define DLIMF_SHIFT    0x10
12283 +
12284 +#define DLIMS_USED     0
12285 +#define DLIMS_TOTAL    2
12286 +
12287 +static inline
12288 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12289 +{
12290 +       int exp = (flags & DLIMF_SHIFT) ?
12291 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12292 +       return ((uint64_t)val) << (10 * exp);
12293 +}
12294 +
12295 +static inline
12296 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12297 +{
12298 +       int exp = 0;
12299 +
12300 +       if (*flags & DLIMF_SHIFT) {
12301 +               while (val > (1LL << 32) && (exp < 3)) {
12302 +                       val >>= 10;
12303 +                       exp++;
12304 +               }
12305 +               *flags &= ~(DLIME_GIGA << shift);
12306 +               *flags |= exp << shift;
12307 +       } else
12308 +               val >>= 10;
12309 +       return val;
12310 +}
12311 +
12312 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12313 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
12314 --- linux-3.13.10/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12315 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h       2014-01-31 20:38:03.000000000 +0000
12316 @@ -0,0 +1,23 @@
12317 +#ifndef _UAPI_VS_INODE_H
12318 +#define _UAPI_VS_INODE_H
12319 +
12320 +
12321 +#define IATTR_TAG      0x01000000
12322 +
12323 +#define IATTR_ADMIN    0x00000001
12324 +#define IATTR_WATCH    0x00000002
12325 +#define IATTR_HIDE     0x00000004
12326 +#define IATTR_FLAGS    0x00000007
12327 +
12328 +#define IATTR_BARRIER  0x00010000
12329 +#define IATTR_IXUNLINK 0x00020000
12330 +#define IATTR_IMMUTABLE 0x00040000
12331 +#define IATTR_COW      0x00080000
12332 +
12333 +
12334 +/* inode ioctls */
12335 +
12336 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12337 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12338 +
12339 +#endif /* _UAPI_VS_INODE_H */
12340 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
12341 --- linux-3.13.10/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12342 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h   2014-01-31 20:38:03.000000000 +0000
12343 @@ -0,0 +1,26 @@
12344 +#ifndef _UAPI_VS_INODE_CMD_H
12345 +#define _UAPI_VS_INODE_CMD_H
12346 +
12347 +
12348 +/*  inode vserver commands */
12349 +
12350 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12351 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12352 +
12353 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12354 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12355 +
12356 +struct vcmd_ctx_iattr_v1 {
12357 +       const char __user *name;
12358 +       uint32_t tag;
12359 +       uint32_t flags;
12360 +       uint32_t mask;
12361 +};
12362 +
12363 +struct vcmd_ctx_fiattr_v0 {
12364 +       uint32_t tag;
12365 +       uint32_t flags;
12366 +       uint32_t mask;
12367 +};
12368 +
12369 +#endif /* _UAPI_VS_INODE_CMD_H */
12370 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
12371 --- linux-3.13.10/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12372 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h       2014-01-31 20:38:03.000000000 +0000
12373 @@ -0,0 +1,14 @@
12374 +#ifndef _UAPI_VS_LIMIT_H
12375 +#define _UAPI_VS_LIMIT_H
12376 +
12377 +
12378 +#define VLIMIT_NSOCK   16
12379 +#define VLIMIT_OPENFD  17
12380 +#define VLIMIT_ANON    18
12381 +#define VLIMIT_SHMEM   19
12382 +#define VLIMIT_SEMARY  20
12383 +#define VLIMIT_NSEMS   21
12384 +#define VLIMIT_DENTRY  22
12385 +#define VLIMIT_MAPPED  23
12386 +
12387 +#endif /* _UAPI_VS_LIMIT_H */
12388 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
12389 --- linux-3.13.10/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12390 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h   2014-01-31 20:38:03.000000000 +0000
12391 @@ -0,0 +1,40 @@
12392 +#ifndef _UAPI_VS_LIMIT_CMD_H
12393 +#define _UAPI_VS_LIMIT_CMD_H
12394 +
12395 +
12396 +/*  rlimit vserver commands */
12397 +
12398 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12399 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12400 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12401 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12402 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12403 +
12404 +struct vcmd_ctx_rlimit_v0 {
12405 +       uint32_t id;
12406 +       uint64_t minimum;
12407 +       uint64_t softlimit;
12408 +       uint64_t maximum;
12409 +};
12410 +
12411 +struct vcmd_ctx_rlimit_mask_v0 {
12412 +       uint32_t minimum;
12413 +       uint32_t softlimit;
12414 +       uint32_t maximum;
12415 +};
12416 +
12417 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12418 +
12419 +struct vcmd_rlimit_stat_v0 {
12420 +       uint32_t id;
12421 +       uint32_t hits;
12422 +       uint64_t value;
12423 +       uint64_t minimum;
12424 +       uint64_t maximum;
12425 +};
12426 +
12427 +#define CRLIM_UNSET            (0ULL)
12428 +#define CRLIM_INFINITY         (~0ULL)
12429 +#define CRLIM_KEEP             (~1ULL)
12430 +
12431 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12432 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
12433 --- linux-3.13.10/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12434 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h     2014-01-31 20:38:03.000000000 +0000
12435 @@ -0,0 +1,96 @@
12436 +#ifndef _UAPI_VS_MONITOR_H
12437 +#define _UAPI_VS_MONITOR_H
12438 +
12439 +#include <linux/types.h>
12440 +
12441 +
12442 +enum {
12443 +       VXM_UNUSED = 0,
12444 +
12445 +       VXM_SYNC = 0x10,
12446 +
12447 +       VXM_UPDATE = 0x20,
12448 +       VXM_UPDATE_1,
12449 +       VXM_UPDATE_2,
12450 +
12451 +       VXM_RQINFO_1 = 0x24,
12452 +       VXM_RQINFO_2,
12453 +
12454 +       VXM_ACTIVATE = 0x40,
12455 +       VXM_DEACTIVATE,
12456 +       VXM_IDLE,
12457 +
12458 +       VXM_HOLD = 0x44,
12459 +       VXM_UNHOLD,
12460 +
12461 +       VXM_MIGRATE = 0x48,
12462 +       VXM_RESCHED,
12463 +
12464 +       /* all other bits are flags */
12465 +       VXM_SCHED = 0x80,
12466 +};
12467 +
12468 +struct _vxm_update_1 {
12469 +       uint32_t tokens_max;
12470 +       uint32_t fill_rate;
12471 +       uint32_t interval;
12472 +};
12473 +
12474 +struct _vxm_update_2 {
12475 +       uint32_t tokens_min;
12476 +       uint32_t fill_rate;
12477 +       uint32_t interval;
12478 +};
12479 +
12480 +struct _vxm_rqinfo_1 {
12481 +       uint16_t running;
12482 +       uint16_t onhold;
12483 +       uint16_t iowait;
12484 +       uint16_t uintr;
12485 +       uint32_t idle_tokens;
12486 +};
12487 +
12488 +struct _vxm_rqinfo_2 {
12489 +       uint32_t norm_time;
12490 +       uint32_t idle_time;
12491 +       uint32_t idle_skip;
12492 +};
12493 +
12494 +struct _vxm_sched {
12495 +       uint32_t tokens;
12496 +       uint32_t norm_time;
12497 +       uint32_t idle_time;
12498 +};
12499 +
12500 +struct _vxm_task {
12501 +       uint16_t pid;
12502 +       uint16_t state;
12503 +};
12504 +
12505 +struct _vxm_event {
12506 +       uint32_t jif;
12507 +       union {
12508 +               uint32_t seq;
12509 +               uint32_t sec;
12510 +       };
12511 +       union {
12512 +               uint32_t tokens;
12513 +               uint32_t nsec;
12514 +               struct _vxm_task tsk;
12515 +       };
12516 +};
12517 +
12518 +struct _vx_mon_entry {
12519 +       uint16_t type;
12520 +       uint16_t xid;
12521 +       union {
12522 +               struct _vxm_event ev;
12523 +               struct _vxm_sched sd;
12524 +               struct _vxm_update_1 u1;
12525 +               struct _vxm_update_2 u2;
12526 +               struct _vxm_rqinfo_1 q1;
12527 +               struct _vxm_rqinfo_2 q2;
12528 +       };
12529 +};
12530 +
12531 +#endif /* _UAPI_VS_MONITOR_H */
12532 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
12533 --- linux-3.13.10/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12534 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h     2014-01-31 20:38:03.000000000 +0000
12535 @@ -0,0 +1,76 @@
12536 +#ifndef _UAPI_VS_NETWORK_H
12537 +#define _UAPI_VS_NETWORK_H
12538 +
12539 +#include <linux/types.h>
12540 +
12541 +
12542 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12543 +
12544 +
12545 +/* network flags */
12546 +
12547 +#define NXF_INFO_PRIVATE       0x00000008
12548 +
12549 +#define NXF_SINGLE_IP          0x00000100
12550 +#define NXF_LBACK_REMAP                0x00000200
12551 +#define NXF_LBACK_ALLOW                0x00000400
12552 +
12553 +#define NXF_HIDE_NETIF         0x02000000
12554 +#define NXF_HIDE_LBACK         0x04000000
12555 +
12556 +#define NXF_STATE_SETUP                (1ULL << 32)
12557 +#define NXF_STATE_ADMIN                (1ULL << 34)
12558 +
12559 +#define NXF_SC_HELPER          (1ULL << 36)
12560 +#define NXF_PERSISTENT         (1ULL << 38)
12561 +
12562 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12563 +
12564 +
12565 +#define        NXF_INIT_SET            (__nxf_init_set())
12566 +
12567 +static inline uint64_t __nxf_init_set(void) {
12568 +       return    NXF_STATE_ADMIN
12569 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12570 +               | NXF_LBACK_REMAP
12571 +               | NXF_HIDE_LBACK
12572 +#endif
12573 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12574 +               | NXF_SINGLE_IP
12575 +#endif
12576 +               | NXF_HIDE_NETIF;
12577 +}
12578 +
12579 +
12580 +/* network caps */
12581 +
12582 +#define NXC_TUN_CREATE         0x00000001
12583 +
12584 +#define NXC_RAW_ICMP           0x00000100
12585 +
12586 +#define NXC_MULTICAST          0x00001000
12587 +
12588 +
12589 +/* address types */
12590 +
12591 +#define NXA_TYPE_IPV4          0x0001
12592 +#define NXA_TYPE_IPV6          0x0002
12593 +
12594 +#define NXA_TYPE_NONE          0x0000
12595 +#define NXA_TYPE_ANY           0x00FF
12596 +
12597 +#define NXA_TYPE_ADDR          0x0010
12598 +#define NXA_TYPE_MASK          0x0020
12599 +#define NXA_TYPE_RANGE         0x0040
12600 +
12601 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12602 +
12603 +#define NXA_MOD_BCAST          0x0100
12604 +#define NXA_MOD_LBACK          0x0200
12605 +
12606 +#define NXA_LOOPBACK           0x1000
12607 +
12608 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12609 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12610 +
12611 +#endif /* _UAPI_VS_NETWORK_H */
12612 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
12613 --- linux-3.13.10/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12614 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12615 @@ -0,0 +1,123 @@
12616 +#ifndef _UAPI_VS_NETWORK_CMD_H
12617 +#define _UAPI_VS_NETWORK_CMD_H
12618 +
12619 +
12620 +/* vinfo commands */
12621 +
12622 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12623 +
12624 +
12625 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12626 +
12627 +struct vcmd_nx_info_v0 {
12628 +       uint32_t nid;
12629 +       /* more to come */
12630 +};
12631 +
12632 +
12633 +#include <linux/in.h>
12634 +#include <linux/in6.h>
12635 +
12636 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12637 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12638 +
12639 +struct  vcmd_net_create {
12640 +       uint64_t flagword;
12641 +};
12642 +
12643 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12644 +
12645 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12646 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12647 +
12648 +struct vcmd_net_addr_v0 {
12649 +       uint16_t type;
12650 +       uint16_t count;
12651 +       struct in_addr ip[4];
12652 +       struct in_addr mask[4];
12653 +};
12654 +
12655 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12656 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12657 +
12658 +struct vcmd_net_addr_ipv4_v1 {
12659 +       uint16_t type;
12660 +       uint16_t flags;
12661 +       struct in_addr ip;
12662 +       struct in_addr mask;
12663 +};
12664 +
12665 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12666 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12667 +
12668 +struct vcmd_net_addr_ipv4_v2 {
12669 +       uint16_t type;
12670 +       uint16_t flags;
12671 +       struct in_addr ip;
12672 +       struct in_addr ip2;
12673 +       struct in_addr mask;
12674 +};
12675 +
12676 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12677 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12678 +
12679 +struct vcmd_net_addr_ipv6_v1 {
12680 +       uint16_t type;
12681 +       uint16_t flags;
12682 +       uint32_t prefix;
12683 +       struct in6_addr ip;
12684 +       struct in6_addr mask;
12685 +};
12686 +
12687 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12688 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12689 +
12690 +struct vcmd_match_ipv4_v0 {
12691 +       uint16_t type;
12692 +       uint16_t flags;
12693 +       uint16_t parent;
12694 +       uint16_t prefix;
12695 +       struct in_addr ip;
12696 +       struct in_addr ip2;
12697 +       struct in_addr mask;
12698 +};
12699 +
12700 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12701 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12702 +
12703 +struct vcmd_match_ipv6_v0 {
12704 +       uint16_t type;
12705 +       uint16_t flags;
12706 +       uint16_t parent;
12707 +       uint16_t prefix;
12708 +       struct in6_addr ip;
12709 +       struct in6_addr ip2;
12710 +       struct in6_addr mask;
12711 +};
12712 +
12713 +
12714 +
12715 +
12716 +/* flag commands */
12717 +
12718 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12719 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12720 +
12721 +struct vcmd_net_flags_v0 {
12722 +       uint64_t flagword;
12723 +       uint64_t mask;
12724 +};
12725 +
12726 +
12727 +
12728 +/* network caps commands */
12729 +
12730 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12731 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12732 +
12733 +struct vcmd_net_caps_v0 {
12734 +       uint64_t ncaps;
12735 +       uint64_t cmask;
12736 +};
12737 +
12738 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12739 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
12740 --- linux-3.13.10/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12741 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h   2014-01-31 20:38:03.000000000 +0000
12742 @@ -0,0 +1,13 @@
12743 +#ifndef _UAPI_VS_SCHED_CMD_H
12744 +#define _UAPI_VS_SCHED_CMD_H
12745 +
12746 +
12747 +struct vcmd_prio_bias {
12748 +       int32_t cpu_id;
12749 +       int32_t prio_bias;
12750 +};
12751 +
12752 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12753 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12754 +
12755 +#endif /* _UAPI_VS_SCHED_CMD_H */
12756 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
12757 --- linux-3.13.10/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12758 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h  2014-01-31 20:38:03.000000000 +0000
12759 @@ -0,0 +1,31 @@
12760 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12761 +#define _UAPI_VS_SIGNAL_CMD_H
12762 +
12763 +
12764 +/*  signalling vserver commands */
12765 +
12766 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12767 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12768 +
12769 +struct vcmd_ctx_kill_v0 {
12770 +       int32_t pid;
12771 +       int32_t sig;
12772 +};
12773 +
12774 +struct vcmd_wait_exit_v0 {
12775 +       int32_t reboot_cmd;
12776 +       int32_t exit_code;
12777 +};
12778 +
12779 +
12780 +/*  process alteration commands */
12781 +
12782 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12783 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12784 +
12785 +struct vcmd_pflags_v0 {
12786 +       uint32_t flagword;
12787 +       uint32_t mask;
12788 +};
12789 +
12790 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12791 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
12792 --- linux-3.13.10/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12793 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h   2014-01-31 20:38:03.000000000 +0000
12794 @@ -0,0 +1,28 @@
12795 +#ifndef _UAPI_VS_SPACE_CMD_H
12796 +#define _UAPI_VS_SPACE_CMD_H
12797 +
12798 +
12799 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12800 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12801 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12802 +
12803 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12804 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12805 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12806 +
12807 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12808 +
12809 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12810 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12811 +
12812 +
12813 +struct vcmd_space_mask_v1 {
12814 +       uint64_t mask;
12815 +};
12816 +
12817 +struct vcmd_space_mask_v2 {
12818 +       uint64_t mask;
12819 +       uint32_t index;
12820 +};
12821 +
12822 +#endif /* _UAPI_VS_SPACE_CMD_H */
12823 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
12824 --- linux-3.13.10/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12825 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h      2014-01-31 20:38:03.000000000 +0000
12826 @@ -0,0 +1,90 @@
12827 +#ifndef _UAPI_VS_SWITCH_H
12828 +#define _UAPI_VS_SWITCH_H
12829 +
12830 +#include <linux/types.h>
12831 +
12832 +
12833 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12834 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12835 +#define VC_VERSION(c)          ((c) & 0xFFF)
12836 +
12837 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12838 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12839 +
12840 +/*
12841 +
12842 +  Syscall Matrix V2.8
12843 +
12844 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12845 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12846 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12847 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12848 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12849 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12850 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12851 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12852 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12853 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12854 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12855 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12856 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12857 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12858 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12859 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12860 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12861 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12862 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12863 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12864 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12865 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12866 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12867 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12868 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12869 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12870 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12871 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12872 +
12873 +*/
12874 +
12875 +#define VC_CAT_VERSION         0
12876 +
12877 +#define VC_CAT_VSETUP          1
12878 +#define VC_CAT_VHOST           2
12879 +
12880 +#define VC_CAT_DEVICE          6
12881 +
12882 +#define VC_CAT_VPROC           9
12883 +#define VC_CAT_PROCALT         10
12884 +#define VC_CAT_PROCMIG         11
12885 +#define VC_CAT_PROCTRL         12
12886 +
12887 +#define VC_CAT_SCHED           14
12888 +#define VC_CAT_MEMCTRL         20
12889 +
12890 +#define VC_CAT_VNET            25
12891 +#define VC_CAT_NETALT          26
12892 +#define VC_CAT_NETMIG          27
12893 +#define VC_CAT_NETCTRL         28
12894 +
12895 +#define VC_CAT_TAGMIG          35
12896 +#define VC_CAT_DLIMIT          36
12897 +#define VC_CAT_INODE           38
12898 +
12899 +#define VC_CAT_VSTAT           40
12900 +#define VC_CAT_VINFO           46
12901 +#define VC_CAT_EVENT           48
12902 +
12903 +#define VC_CAT_FLAGS           52
12904 +#define VC_CAT_VSPACE          54
12905 +#define VC_CAT_DEBUG           56
12906 +#define VC_CAT_RLIMIT          60
12907 +
12908 +#define VC_CAT_SYSTEST         61
12909 +#define VC_CAT_COMPAT          63
12910 +
12911 +/*  query version */
12912 +
12913 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12914 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12915 +
12916 +#endif /* _UAPI_VS_SWITCH_H */
12917 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
12918 --- linux-3.13.10/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12919 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h     2014-01-31 20:38:03.000000000 +0000
12920 @@ -0,0 +1,14 @@
12921 +#ifndef _UAPI_VS_TAG_CMD_H
12922 +#define _UAPI_VS_TAG_CMD_H
12923 +
12924 +
12925 +/* vinfo commands */
12926 +
12927 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12928 +
12929 +
12930 +/* context commands */
12931 +
12932 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12933 +
12934 +#endif /* _UAPI_VS_TAG_CMD_H */
12935 diff -NurpP --minimal linux-3.13.10/init/Kconfig linux-3.13.10-vs2.3.6.11/init/Kconfig
12936 --- linux-3.13.10/init/Kconfig  2014-04-17 01:12:39.000000000 +0000
12937 +++ linux-3.13.10-vs2.3.6.11/init/Kconfig       2014-04-17 01:17:11.000000000 +0000
12938 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12939  menuconfig CGROUPS
12940         boolean "Control Group support"
12941         select KERNFS
12942 +       default y
12943         help
12944           This option adds support for grouping sets of processes together, for
12945           use with process control subsystems such as Cpusets, CFS, memory
12946 @@ -1117,6 +1118,7 @@ config IPC_NS
12947  
12948  config USER_NS
12949         bool "User namespace"
12950 +       depends on VSERVER_DISABLED
12951         default n
12952         help
12953           This allows containers, i.e. vservers, to use user namespaces
12954 diff -NurpP --minimal linux-3.13.10/init/main.c linux-3.13.10-vs2.3.6.11/init/main.c
12955 --- linux-3.13.10/init/main.c   2014-01-22 20:39:12.000000000 +0000
12956 +++ linux-3.13.10-vs2.3.6.11/init/main.c        2014-01-31 20:38:03.000000000 +0000
12957 @@ -77,6 +77,7 @@
12958  #include <linux/sched_clock.h>
12959  #include <linux/context_tracking.h>
12960  #include <linux/random.h>
12961 +#include <linux/vserver/percpu.h>
12962  
12963  #include <asm/io.h>
12964  #include <asm/bugs.h>
12965 diff -NurpP --minimal linux-3.13.10/ipc/mqueue.c linux-3.13.10-vs2.3.6.11/ipc/mqueue.c
12966 --- linux-3.13.10/ipc/mqueue.c  2014-04-17 01:12:39.000000000 +0000
12967 +++ linux-3.13.10-vs2.3.6.11/ipc/mqueue.c       2014-03-12 15:51:08.000000000 +0000
12968 @@ -35,6 +35,8 @@
12969  #include <linux/ipc_namespace.h>
12970  #include <linux/user_namespace.h>
12971  #include <linux/slab.h>
12972 +#include <linux/vs_context.h>
12973 +#include <linux/vs_limit.h>
12974  
12975  #include <net/sock.h>
12976  #include "util.h"
12977 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
12978         struct pid* notify_owner;
12979         struct user_namespace *notify_user_ns;
12980         struct user_struct *user;       /* user who created, for accounting */
12981 +       struct vx_info *vxi;
12982         struct sock *notify_sock;
12983         struct sk_buff *notify_cookie;
12984  
12985 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
12986         if (S_ISREG(mode)) {
12987                 struct mqueue_inode_info *info;
12988                 unsigned long mq_bytes, mq_treesize;
12989 +               struct vx_info *vxi = current_vx_info();
12990  
12991                 inode->i_fop = &mqueue_file_operations;
12992                 inode->i_size = FILENT_SIZE;
12993 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
12994                 info->notify_user_ns = NULL;
12995                 info->qsize = 0;
12996                 info->user = NULL;      /* set when all is ok */
12997 +               info->vxi = NULL;
12998                 info->msg_tree = RB_ROOT;
12999                 info->node_cache = NULL;
13000                 memset(&info->attr, 0, sizeof(info->attr));
13001 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13002  
13003                 spin_lock(&mq_lock);
13004                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13005 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13006 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13007 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13008                         spin_unlock(&mq_lock);
13009                         /* mqueue_evict_inode() releases info->messages */
13010                         ret = -EMFILE;
13011                         goto out_inode;
13012                 }
13013                 u->mq_bytes += mq_bytes;
13014 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13015                 spin_unlock(&mq_lock);
13016  
13017                 /* all is ok */
13018                 info->user = get_uid(u);
13019 +               info->vxi = get_vx_info(vxi);
13020         } else if (S_ISDIR(mode)) {
13021                 inc_nlink(inode);
13022                 /* Some things misbehave if size == 0 on a directory */
13023 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13024  
13025         user = info->user;
13026         if (user) {
13027 +               struct vx_info *vxi = info->vxi;
13028 +
13029                 spin_lock(&mq_lock);
13030                 user->mq_bytes -= mq_bytes;
13031 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13032                 /*
13033                  * get_ns_from_inode() ensures that the
13034                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13035 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13036                 if (ipc_ns)
13037                         ipc_ns->mq_queues_count--;
13038                 spin_unlock(&mq_lock);
13039 +               put_vx_info(vxi);
13040                 free_uid(user);
13041         }
13042         if (ipc_ns)
13043 diff -NurpP --minimal linux-3.13.10/ipc/msg.c linux-3.13.10-vs2.3.6.11/ipc/msg.c
13044 --- linux-3.13.10/ipc/msg.c     2014-04-17 01:12:39.000000000 +0000
13045 +++ linux-3.13.10-vs2.3.6.11/ipc/msg.c  2014-04-17 01:17:11.000000000 +0000
13046 @@ -37,6 +37,7 @@
13047  #include <linux/rwsem.h>
13048  #include <linux/nsproxy.h>
13049  #include <linux/ipc_namespace.h>
13050 +#include <linux/vs_base.h>
13051  
13052  #include <asm/current.h>
13053  #include <asm/uaccess.h>
13054 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13055  
13056         msq->q_perm.mode = msgflg & S_IRWXUGO;
13057         msq->q_perm.key = key;
13058 +       msq->q_perm.xid = vx_current_xid();
13059  
13060         msq->q_perm.security = NULL;
13061         retval = security_msg_queue_alloc(msq);
13062 diff -NurpP --minimal linux-3.13.10/ipc/sem.c linux-3.13.10-vs2.3.6.11/ipc/sem.c
13063 --- linux-3.13.10/ipc/sem.c     2013-11-25 15:47:03.000000000 +0000
13064 +++ linux-3.13.10-vs2.3.6.11/ipc/sem.c  2014-01-31 20:38:03.000000000 +0000
13065 @@ -86,6 +86,8 @@
13066  #include <linux/rwsem.h>
13067  #include <linux/nsproxy.h>
13068  #include <linux/ipc_namespace.h>
13069 +#include <linux/vs_base.h>
13070 +#include <linux/vs_limit.h>
13071  
13072  #include <asm/uaccess.h>
13073  #include "util.h"
13074 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13075  
13076         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13077         sma->sem_perm.key = key;
13078 +       sma->sem_perm.xid = vx_current_xid();
13079  
13080         sma->sem_perm.security = NULL;
13081         retval = security_sem_alloc(sma);
13082 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13083                 return id;
13084         }
13085         ns->used_sems += nsems;
13086 +       /* FIXME: obsoleted? */
13087 +       vx_semary_inc(sma);
13088 +       vx_nsems_add(sma, nsems);
13089  
13090         sma->sem_base = (struct sem *) &sma[1];
13091  
13092 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13093  
13094         wake_up_sem_queue_do(&tasks);
13095         ns->used_sems -= sma->sem_nsems;
13096 +       /* FIXME: obsoleted? */
13097 +       vx_nsems_sub(sma, sma->sem_nsems);
13098 +       vx_semary_dec(sma);
13099         ipc_rcu_putref(sma, sem_rcu_free);
13100  }
13101  
13102 diff -NurpP --minimal linux-3.13.10/ipc/shm.c linux-3.13.10-vs2.3.6.11/ipc/shm.c
13103 --- linux-3.13.10/ipc/shm.c     2014-01-22 20:39:12.000000000 +0000
13104 +++ linux-3.13.10-vs2.3.6.11/ipc/shm.c  2014-01-31 20:38:03.000000000 +0000
13105 @@ -42,6 +42,8 @@
13106  #include <linux/nsproxy.h>
13107  #include <linux/mount.h>
13108  #include <linux/ipc_namespace.h>
13109 +#include <linux/vs_context.h>
13110 +#include <linux/vs_limit.h>
13111  
13112  #include <asm/uaccess.h>
13113  
13114 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13115  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13116  {
13117         struct file *shm_file;
13118 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13119 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13120  
13121         shm_file = shp->shm_file;
13122         shp->shm_file = NULL;
13123 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13124 +       vx_ipcshm_sub(vxi, shp, numpages);
13125 +       ns->shm_tot -= numpages;
13126 +
13127         shm_rmid(ns, shp);
13128         shm_unlock(shp);
13129         if (!is_file_hugepages(shm_file))
13130 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13131         else if (shp->mlock_user)
13132                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13133         fput(shm_file);
13134 +       put_vx_info(vxi);
13135         ipc_rcu_putref(shp, shm_rcu_free);
13136  }
13137  
13138 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13139         if (ns->shm_tot + numpages > ns->shm_ctlall)
13140                 return -ENOSPC;
13141  
13142 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13143 +               return -ENOSPC;
13144 +
13145         shp = ipc_rcu_alloc(sizeof(*shp));
13146         if (!shp)
13147                 return -ENOMEM;
13148  
13149         shp->shm_perm.key = key;
13150 +       shp->shm_perm.xid = vx_current_xid();
13151         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13152         shp->mlock_user = NULL;
13153  
13154 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13155  
13156         ipc_unlock_object(&shp->shm_perm);
13157         rcu_read_unlock();
13158 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13159         return error;
13160  
13161  no_id:
13162 diff -NurpP --minimal linux-3.13.10/kernel/Makefile linux-3.13.10-vs2.3.6.11/kernel/Makefile
13163 --- linux-3.13.10/kernel/Makefile       2014-01-22 20:39:12.000000000 +0000
13164 +++ linux-3.13.10-vs2.3.6.11/kernel/Makefile    2014-01-31 21:36:22.000000000 +0000
13165 @@ -25,6 +25,7 @@ obj-y += printk/
13166  obj-y += cpu/
13167  obj-y += irq/
13168  obj-y += rcu/
13169 +obj-y += vserver/
13170  
13171  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13172  obj-$(CONFIG_FREEZER) += freezer.o
13173 diff -NurpP --minimal linux-3.13.10/kernel/auditsc.c linux-3.13.10-vs2.3.6.11/kernel/auditsc.c
13174 --- linux-3.13.10/kernel/auditsc.c      2014-04-17 01:12:39.000000000 +0000
13175 +++ linux-3.13.10-vs2.3.6.11/kernel/auditsc.c   2014-04-17 01:17:11.000000000 +0000
13176 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13177         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13178                 return -EPERM;
13179         /* it is set, you need permission */
13180 -       if (!capable(CAP_AUDIT_CONTROL))
13181 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13182                 return -EPERM;
13183         /* reject if this is not an unset and we don't allow that */
13184         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13185 diff -NurpP --minimal linux-3.13.10/kernel/capability.c linux-3.13.10-vs2.3.6.11/kernel/capability.c
13186 --- linux-3.13.10/kernel/capability.c   2013-11-25 15:47:03.000000000 +0000
13187 +++ linux-3.13.10-vs2.3.6.11/kernel/capability.c        2014-01-31 20:38:03.000000000 +0000
13188 @@ -15,6 +15,7 @@
13189  #include <linux/syscalls.h>
13190  #include <linux/pid_namespace.h>
13191  #include <linux/user_namespace.h>
13192 +#include <linux/vs_context.h>
13193  #include <asm/uaccess.h>
13194  
13195  /*
13196 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13197         return 0;
13198  }
13199  
13200 +
13201  /*
13202   * The only thing that can change the capabilities of the current
13203   * process is the current process. As such, we can't be in this code
13204 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13205         return (ret == 0);
13206  }
13207  
13208 +#include <linux/vserver/base.h>
13209 +
13210  /**
13211   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13212   * initial user ns
13213 diff -NurpP --minimal linux-3.13.10/kernel/compat.c linux-3.13.10-vs2.3.6.11/kernel/compat.c
13214 --- linux-3.13.10/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13215 +++ linux-3.13.10-vs2.3.6.11/kernel/compat.c    2014-01-31 20:38:03.000000000 +0000
13216 @@ -27,6 +27,7 @@
13217  #include <linux/times.h>
13218  #include <linux/ptrace.h>
13219  #include <linux/gfp.h>
13220 +#include <linux/vs_time.h>
13221  
13222  #include <asm/uaccess.h>
13223  
13224 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13225         if (err)
13226                 return err;
13227  
13228 -       do_settimeofday(&tv);
13229 +       vx_settimeofday(&tv);
13230         return 0;
13231  }
13232  
13233 diff -NurpP --minimal linux-3.13.10/kernel/cred.c linux-3.13.10-vs2.3.6.11/kernel/cred.c
13234 --- linux-3.13.10/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13235 +++ linux-3.13.10-vs2.3.6.11/kernel/cred.c      2014-01-31 20:38:03.000000000 +0000
13236 @@ -56,31 +56,6 @@ struct cred init_cred = {
13237         .group_info             = &init_groups,
13238  };
13239  
13240 -static inline void set_cred_subscribers(struct cred *cred, int n)
13241 -{
13242 -#ifdef CONFIG_DEBUG_CREDENTIALS
13243 -       atomic_set(&cred->subscribers, n);
13244 -#endif
13245 -}
13246 -
13247 -static inline int read_cred_subscribers(const struct cred *cred)
13248 -{
13249 -#ifdef CONFIG_DEBUG_CREDENTIALS
13250 -       return atomic_read(&cred->subscribers);
13251 -#else
13252 -       return 0;
13253 -#endif
13254 -}
13255 -
13256 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13257 -{
13258 -#ifdef CONFIG_DEBUG_CREDENTIALS
13259 -       struct cred *cred = (struct cred *) _cred;
13260 -
13261 -       atomic_add(n, &cred->subscribers);
13262 -#endif
13263 -}
13264 -
13265  /*
13266   * The RCU callback to actually dispose of a set of credentials
13267   */
13268 @@ -232,21 +207,16 @@ error:
13269   *
13270   * Call commit_creds() or abort_creds() to clean up.
13271   */
13272 -struct cred *prepare_creds(void)
13273 +struct cred *__prepare_creds(const struct cred *old)
13274  {
13275 -       struct task_struct *task = current;
13276 -       const struct cred *old;
13277         struct cred *new;
13278  
13279 -       validate_process_creds();
13280 -
13281         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13282         if (!new)
13283                 return NULL;
13284  
13285         kdebug("prepare_creds() alloc %p", new);
13286  
13287 -       old = task->cred;
13288         memcpy(new, old, sizeof(struct cred));
13289  
13290         atomic_set(&new->usage, 1);
13291 @@ -275,6 +245,13 @@ error:
13292         abort_creds(new);
13293         return NULL;
13294  }
13295 +
13296 +struct cred *prepare_creds(void)
13297 +{
13298 +       validate_process_creds();
13299 +
13300 +       return __prepare_creds(current->cred);
13301 +}
13302  EXPORT_SYMBOL(prepare_creds);
13303  
13304  /*
13305 diff -NurpP --minimal linux-3.13.10/kernel/exit.c linux-3.13.10-vs2.3.6.11/kernel/exit.c
13306 --- linux-3.13.10/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13307 +++ linux-3.13.10-vs2.3.6.11/kernel/exit.c      2014-01-31 20:38:03.000000000 +0000
13308 @@ -48,6 +48,10 @@
13309  #include <linux/fs_struct.h>
13310  #include <linux/init_task.h>
13311  #include <linux/perf_event.h>
13312 +#include <linux/vs_limit.h>
13313 +#include <linux/vs_context.h>
13314 +#include <linux/vs_network.h>
13315 +#include <linux/vs_pid.h>
13316  #include <trace/events/sched.h>
13317  #include <linux/hw_breakpoint.h>
13318  #include <linux/oom.h>
13319 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13320         __acquires(&tasklist_lock)
13321  {
13322         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13323 -       struct task_struct *thread;
13324 +       struct vx_info *vxi = task_get_vx_info(father);
13325 +       struct task_struct *thread = father;
13326 +       struct task_struct *reaper;
13327  
13328 -       thread = father;
13329         while_each_thread(father, thread) {
13330                 if (thread->flags & PF_EXITING)
13331                         continue;
13332                 if (unlikely(pid_ns->child_reaper == father))
13333                         pid_ns->child_reaper = thread;
13334 -               return thread;
13335 +               reaper = thread;
13336 +               goto out_put;
13337 +       }
13338 +
13339 +       reaper = pid_ns->child_reaper;
13340 +       if (vxi) {
13341 +               BUG_ON(!vxi->vx_reaper);
13342 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13343 +                   vxi->vx_reaper != father)
13344 +                       reaper = vxi->vx_reaper;
13345         }
13346  
13347         if (unlikely(pid_ns->child_reaper == father)) {
13348 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13349                 }
13350         }
13351  
13352 -       return pid_ns->child_reaper;
13353 +out_put:
13354 +       put_vx_info(vxi);
13355 +       return reaper;
13356  }
13357  
13358  /*
13359 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13360         list_for_each_entry_safe(p, n, &father->children, sibling) {
13361                 struct task_struct *t = p;
13362                 do {
13363 -                       t->real_parent = reaper;
13364 +                       struct task_struct *new_parent = reaper;
13365 +
13366 +                       if (unlikely(p == reaper))
13367 +                               new_parent = task_active_pid_ns(p)->child_reaper;
13368 +
13369 +                       t->real_parent = new_parent;
13370                         if (t->parent == father) {
13371                                 BUG_ON(t->ptrace);
13372 -                               t->parent = t->real_parent;
13373 +                               t->parent = new_parent;
13374                         }
13375                         if (t->pdeath_signal)
13376                                 group_send_sig_info(t->pdeath_signal,
13377 @@ -810,6 +831,9 @@ void do_exit(long code)
13378          */
13379         flush_ptrace_hw_breakpoint(tsk);
13380  
13381 +       /* needs to stay before exit_notify() */
13382 +       exit_vx_info_early(tsk, code);
13383 +
13384         exit_notify(tsk, group_dead);
13385  #ifdef CONFIG_NUMA
13386         task_lock(tsk);
13387 @@ -863,10 +887,15 @@ void do_exit(long code)
13388         smp_mb();
13389         raw_spin_unlock_wait(&tsk->pi_lock);
13390  
13391 +       /* needs to stay after exit_notify() */
13392 +       exit_vx_info(tsk, code);
13393 +       exit_nx_info(tsk);
13394 +
13395         /* causes final put_task_struct in finish_task_switch(). */
13396         tsk->state = TASK_DEAD;
13397         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13398         schedule();
13399 +       printk("bad task: %p [%lx]\n", current, current->state);
13400         BUG();
13401         /* Avoid "noreturn function does return".  */
13402         for (;;)
13403 diff -NurpP --minimal linux-3.13.10/kernel/fork.c linux-3.13.10-vs2.3.6.11/kernel/fork.c
13404 --- linux-3.13.10/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13405 +++ linux-3.13.10-vs2.3.6.11/kernel/fork.c      2014-01-31 20:38:03.000000000 +0000
13406 @@ -71,6 +71,9 @@
13407  #include <linux/uprobes.h>
13408  #include <linux/aio.h>
13409  #include <linux/compiler.h>
13410 +#include <linux/vs_context.h>
13411 +#include <linux/vs_network.h>
13412 +#include <linux/vs_limit.h>
13413  
13414  #include <asm/pgtable.h>
13415  #include <asm/pgalloc.h>
13416 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13417         arch_release_thread_info(tsk->stack);
13418         free_thread_info(tsk->stack);
13419         rt_mutex_debug_task_free(tsk);
13420 +       clr_vx_info(&tsk->vx_info);
13421 +       clr_nx_info(&tsk->nx_info);
13422         ftrace_graph_exit_task(tsk);
13423         put_seccomp_filter(tsk);
13424         arch_release_task_struct(tsk);
13425 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13426         if (likely(!mm_alloc_pgd(mm))) {
13427                 mm->def_flags = 0;
13428                 mmu_notifier_mm_init(mm);
13429 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
13430                 return mm;
13431         }
13432  
13433 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13434         destroy_context(mm);
13435         mmu_notifier_mm_destroy(mm);
13436         check_mm(mm);
13437 +       clr_vx_info(&mm->mm_vx_info);
13438         free_mm(mm);
13439  }
13440  EXPORT_SYMBOL_GPL(__mmdrop);
13441 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13442                 goto fail_nomem;
13443  
13444         memcpy(mm, oldmm, sizeof(*mm));
13445 +       mm->mm_vx_info = NULL;
13446         mm_init_cpumask(mm);
13447  
13448  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13449 @@ -851,6 +859,7 @@ fail_nocontext:
13450          * If init_new_context() failed, we cannot use mmput() to free the mm
13451          * because it calls destroy_context()
13452          */
13453 +       clr_vx_info(&mm->mm_vx_info);
13454         mm_free_pgd(mm);
13455         free_mm(mm);
13456         return NULL;
13457 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13458  {
13459         int retval;
13460         struct task_struct *p;
13461 +       struct vx_info *vxi;
13462 +       struct nx_info *nxi;
13463  
13464         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13465                 return ERR_PTR(-EINVAL);
13466 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13467         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13468         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13469  #endif
13470 +       init_vx_info(&p->vx_info, current_vx_info());
13471 +       init_nx_info(&p->nx_info, current_nx_info());
13472 +
13473         retval = -EAGAIN;
13474 +       if (!vx_nproc_avail(1))
13475 +               goto bad_fork_free;
13476         if (atomic_read(&p->real_cred->user->processes) >=
13477                         task_rlimit(p, RLIMIT_NPROC)) {
13478                 if (p->real_cred->user != INIT_USER &&
13479 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13480  
13481         total_forks++;
13482         spin_unlock(&current->sighand->siglock);
13483 +
13484 +       /* p is copy of current */
13485 +       vxi = p->vx_info;
13486 +       if (vxi) {
13487 +               claim_vx_info(vxi, p);
13488 +               atomic_inc(&vxi->cvirt.nr_threads);
13489 +               atomic_inc(&vxi->cvirt.total_forks);
13490 +               vx_nproc_inc(p);
13491 +       }
13492 +       nxi = p->nx_info;
13493 +       if (nxi)
13494 +               claim_nx_info(nxi, p);
13495         write_unlock_irq(&tasklist_lock);
13496         proc_fork_connector(p);
13497         cgroup_post_fork(p);
13498 diff -NurpP --minimal linux-3.13.10/kernel/kthread.c linux-3.13.10-vs2.3.6.11/kernel/kthread.c
13499 --- linux-3.13.10/kernel/kthread.c      2014-01-22 20:39:13.000000000 +0000
13500 +++ linux-3.13.10-vs2.3.6.11/kernel/kthread.c   2014-01-31 20:38:03.000000000 +0000
13501 @@ -18,6 +18,7 @@
13502  #include <linux/freezer.h>
13503  #include <linux/ptrace.h>
13504  #include <linux/uaccess.h>
13505 +#include <linux/vs_pid.h>
13506  #include <trace/events/sched.h>
13507  
13508  static DEFINE_SPINLOCK(kthread_create_lock);
13509 diff -NurpP --minimal linux-3.13.10/kernel/nsproxy.c linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c
13510 --- linux-3.13.10/kernel/nsproxy.c      2013-11-25 15:47:03.000000000 +0000
13511 +++ linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c   2014-02-01 00:17:43.000000000 +0000
13512 @@ -20,11 +20,14 @@
13513  #include <linux/mnt_namespace.h>
13514  #include <linux/utsname.h>
13515  #include <linux/pid_namespace.h>
13516 +#include <linux/vserver/global.h>
13517 +#include <linux/vserver/debug.h>
13518  #include <net/net_namespace.h>
13519  #include <linux/ipc_namespace.h>
13520  #include <linux/proc_ns.h>
13521  #include <linux/file.h>
13522  #include <linux/syscalls.h>
13523 +#include "../fs/mount.h"
13524  
13525  static struct kmem_cache *nsproxy_cachep;
13526  
13527 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13528         struct nsproxy *nsproxy;
13529  
13530         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13531 -       if (nsproxy)
13532 +       if (nsproxy) {
13533                 atomic_set(&nsproxy->count, 1);
13534 +               atomic_inc(&vs_global_nsproxy);
13535 +       }
13536 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13537         return nsproxy;
13538  }
13539  
13540 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13541   * Return the newly created nsproxy.  Do not attach this to the task,
13542   * leave it to the caller to do proper locking and attach it to task.
13543   */
13544 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13545 -       struct task_struct *tsk, struct user_namespace *user_ns,
13546 -       struct fs_struct *new_fs)
13547 +static struct nsproxy *unshare_namespaces(
13548 +       unsigned long flags,
13549 +       struct nsproxy *orig,
13550 +       struct fs_struct *new_fs,
13551 +       struct user_namespace *new_user,
13552 +       struct pid_namespace *new_pid)
13553  {
13554         struct nsproxy *new_nsp;
13555         int err;
13556 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13557         if (!new_nsp)
13558                 return ERR_PTR(-ENOMEM);
13559  
13560 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13561 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13562         if (IS_ERR(new_nsp->mnt_ns)) {
13563                 err = PTR_ERR(new_nsp->mnt_ns);
13564                 goto out_ns;
13565         }
13566  
13567 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13568 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13569         if (IS_ERR(new_nsp->uts_ns)) {
13570                 err = PTR_ERR(new_nsp->uts_ns);
13571                 goto out_uts;
13572         }
13573  
13574 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13575 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13576         if (IS_ERR(new_nsp->ipc_ns)) {
13577                 err = PTR_ERR(new_nsp->ipc_ns);
13578                 goto out_ipc;
13579         }
13580  
13581 -       new_nsp->pid_ns_for_children =
13582 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13583 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13584         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13585                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13586                 goto out_pid;
13587         }
13588  
13589 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13590 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13591         if (IS_ERR(new_nsp->net_ns)) {
13592                 err = PTR_ERR(new_nsp->net_ns);
13593                 goto out_net;
13594 @@ -117,6 +125,41 @@ out_ns:
13595         return ERR_PTR(err);
13596  }
13597  
13598 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13599 +       struct task_struct *tsk, struct user_namespace *user_ns,
13600 +       struct fs_struct *new_fs)
13601 +
13602 +{
13603 +       return unshare_namespaces(flags, tsk->nsproxy,
13604 +               new_fs, user_ns, task_active_pid_ns(tsk));
13605 +}
13606 +
13607 +/*
13608 + * copies the nsproxy, setting refcount to 1, and grabbing a
13609 + * reference to all contained namespaces.
13610 + */
13611 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13612 +{
13613 +       struct nsproxy *ns = create_nsproxy();
13614 +
13615 +       if (ns) {
13616 +               memcpy(ns, orig, sizeof(struct nsproxy));
13617 +               atomic_set(&ns->count, 1);
13618 +
13619 +               if (ns->mnt_ns)
13620 +                       get_mnt_ns(ns->mnt_ns);
13621 +               if (ns->uts_ns)
13622 +                       get_uts_ns(ns->uts_ns);
13623 +               if (ns->ipc_ns)
13624 +                       get_ipc_ns(ns->ipc_ns);
13625 +               if (ns->pid_ns_for_children)
13626 +                       get_pid_ns(ns->pid_ns_for_children);
13627 +               if (ns->net_ns)
13628 +                       get_net(ns->net_ns);
13629 +       }
13630 +       return ns;
13631 +}
13632 +
13633  /*
13634   * called from clone.  This now handles copy for nsproxy and all
13635   * namespaces therein.
13636 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13637  {
13638         struct nsproxy *old_ns = tsk->nsproxy;
13639         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13640 -       struct nsproxy *new_ns;
13641 +       struct nsproxy *new_ns = NULL;
13642 +
13643 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13644 +               flags, tsk, old_ns);
13645  
13646         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13647                               CLONE_NEWPID | CLONE_NEWNET)))) {
13648 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13649                 return 0;
13650         }
13651  
13652 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13653 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13654                 return -EPERM;
13655  
13656         /*
13657 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13658                 return  PTR_ERR(new_ns);
13659  
13660         tsk->nsproxy = new_ns;
13661 +       vxdprintk(VXD_CBIT(space, 3),
13662 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13663 +               flags, tsk, old_ns, new_ns);
13664         return 0;
13665  }
13666  
13667 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13668                 put_ipc_ns(ns->ipc_ns);
13669         if (ns->pid_ns_for_children)
13670                 put_pid_ns(ns->pid_ns_for_children);
13671 -       put_net(ns->net_ns);
13672 +       if (ns->net_ns)
13673 +               put_net(ns->net_ns);
13674 +       atomic_dec(&vs_global_nsproxy);
13675         kmem_cache_free(nsproxy_cachep, ns);
13676  }
13677  
13678 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13679         struct user_namespace *user_ns;
13680         int err = 0;
13681  
13682 +       vxdprintk(VXD_CBIT(space, 4),
13683 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13684 +               unshare_flags, current->nsproxy);
13685 +
13686         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13687                                CLONE_NEWNET | CLONE_NEWPID)))
13688                 return 0;
13689  
13690         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13691 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13692 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13693                 return -EPERM;
13694  
13695         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13696 diff -NurpP --minimal linux-3.13.10/kernel/pid.c linux-3.13.10-vs2.3.6.11/kernel/pid.c
13697 --- linux-3.13.10/kernel/pid.c  2013-11-25 15:47:03.000000000 +0000
13698 +++ linux-3.13.10-vs2.3.6.11/kernel/pid.c       2014-01-31 20:38:03.000000000 +0000
13699 @@ -38,6 +38,7 @@
13700  #include <linux/syscalls.h>
13701  #include <linux/proc_ns.h>
13702  #include <linux/proc_fs.h>
13703 +#include <linux/vs_pid.h>
13704  
13705  #define pid_hashfn(nr, ns)     \
13706         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13707 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13708  
13709  struct pid *find_vpid(int nr)
13710  {
13711 -       return find_pid_ns(nr, task_active_pid_ns(current));
13712 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13713  }
13714  EXPORT_SYMBOL_GPL(find_vpid);
13715  
13716 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13717  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13718  {
13719         struct task_struct *result = NULL;
13720 +
13721 +       if (type == PIDTYPE_REALPID)
13722 +               type = PIDTYPE_PID;
13723         if (pid) {
13724                 struct hlist_node *first;
13725                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13726 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13727         rcu_lockdep_assert(rcu_read_lock_held(),
13728                            "find_task_by_pid_ns() needs rcu_read_lock()"
13729                            " protection");
13730 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13731 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13732  }
13733  
13734  struct task_struct *find_task_by_vpid(pid_t vnr)
13735 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13736  }
13737  EXPORT_SYMBOL_GPL(find_get_pid);
13738  
13739 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13740 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13741  {
13742         struct upid *upid;
13743         pid_t nr = 0;
13744 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13745  }
13746  EXPORT_SYMBOL_GPL(pid_nr_ns);
13747  
13748 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13749 +{
13750 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13751 +}
13752 +
13753  pid_t pid_vnr(struct pid *pid)
13754  {
13755         return pid_nr_ns(pid, task_active_pid_ns(current));
13756 diff -NurpP --minimal linux-3.13.10/kernel/pid_namespace.c linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c
13757 --- linux-3.13.10/kernel/pid_namespace.c        2014-01-22 20:39:13.000000000 +0000
13758 +++ linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c     2014-02-01 12:23:11.000000000 +0000
13759 @@ -18,6 +18,7 @@
13760  #include <linux/proc_ns.h>
13761  #include <linux/reboot.h>
13762  #include <linux/export.h>
13763 +#include <linux/vserver/global.h>
13764  
13765  struct pid_cache {
13766         int nr_ids;
13767 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13768                 goto out_free_map;
13769  
13770         kref_init(&ns->kref);
13771 +       atomic_inc(&vs_global_pid_ns);
13772         ns->level = level;
13773         ns->parent = get_pid_ns(parent_pid_ns);
13774         ns->user_ns = get_user_ns(user_ns);
13775 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13776  out_free_map:
13777         kfree(ns->pidmap[0].page);
13778  out_free:
13779 +       atomic_dec(&vs_global_pid_ns);
13780         kmem_cache_free(pid_ns_cachep, ns);
13781  out:
13782         return ERR_PTR(err);
13783 diff -NurpP --minimal linux-3.13.10/kernel/posix-timers.c linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c
13784 --- linux-3.13.10/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13785 +++ linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c      2014-01-31 20:38:03.000000000 +0000
13786 @@ -48,6 +48,7 @@
13787  #include <linux/workqueue.h>
13788  #include <linux/export.h>
13789  #include <linux/hashtable.h>
13790 +#include <linux/vs_context.h>
13791  
13792  /*
13793   * Management arrays for POSIX timers. Timers are now kept in static hash table
13794 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13795  {
13796         struct task_struct *task;
13797         int shared, ret = -1;
13798 +
13799         /*
13800          * FIXME: if ->sigq is queued we can race with
13801          * dequeue_signal()->do_schedule_next_timer().
13802 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13803         rcu_read_lock();
13804         task = pid_task(timr->it_pid, PIDTYPE_PID);
13805         if (task) {
13806 +               struct vx_info_save vxis;
13807 +               struct vx_info *vxi;
13808 +
13809 +               vxi = get_vx_info(task->vx_info);
13810 +               enter_vx_info(vxi, &vxis);
13811                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13812                 ret = send_sigqueue(timr->sigq, task, shared);
13813 +               leave_vx_info(&vxis);
13814 +               put_vx_info(vxi);
13815         }
13816         rcu_read_unlock();
13817 +
13818         /* If we failed to send the signal the timer stops. */
13819         return ret > 0;
13820  }
13821 diff -NurpP --minimal linux-3.13.10/kernel/printk/printk.c linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c
13822 --- linux-3.13.10/kernel/printk/printk.c        2014-04-17 01:12:39.000000000 +0000
13823 +++ linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c     2014-04-17 01:17:11.000000000 +0000
13824 @@ -45,6 +45,7 @@
13825  #include <linux/poll.h>
13826  #include <linux/irq_work.h>
13827  #include <linux/utsname.h>
13828 +#include <linux/vs_cvirt.h>
13829  
13830  #include <asm/uaccess.h>
13831  
13832 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13833                 return 0;
13834  
13835         if (syslog_action_restricted(type)) {
13836 -               if (capable(CAP_SYSLOG))
13837 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13838                         return 0;
13839                 /*
13840                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13841 @@ -1134,12 +1135,9 @@ int do_syslog(int type, char __user *buf
13842         if (error)
13843                 return error;
13844  
13845 -       switch (type) {
13846 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13847 -               break;
13848 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13849 -               break;
13850 -       case SYSLOG_ACTION_READ:        /* Read from log */
13851 +       if ((type == SYSLOG_ACTION_READ) ||
13852 +           (type == SYSLOG_ACTION_READ_ALL) ||
13853 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13854                 error = -EINVAL;
13855                 if (!buf || len < 0)
13856                         goto out;
13857 @@ -1150,6 +1148,16 @@ int do_syslog(int type, char __user *buf
13858                         error = -EFAULT;
13859                         goto out;
13860                 }
13861 +       }
13862 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13863 +               return vx_do_syslog(type, buf, len);
13864 +
13865 +       switch (type) {
13866 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13867 +               break;
13868 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13869 +               break;
13870 +       case SYSLOG_ACTION_READ:        /* Read from log */
13871                 error = wait_event_interruptible(log_wait,
13872                                                  syslog_seq != log_next_seq);
13873                 if (error)
13874 @@ -1162,16 +1170,6 @@ int do_syslog(int type, char __user *buf
13875                 /* FALL THRU */
13876         /* Read last kernel messages */
13877         case SYSLOG_ACTION_READ_ALL:
13878 -               error = -EINVAL;
13879 -               if (!buf || len < 0)
13880 -                       goto out;
13881 -               error = 0;
13882 -               if (!len)
13883 -                       goto out;
13884 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13885 -                       error = -EFAULT;
13886 -                       goto out;
13887 -               }
13888                 error = syslog_print_all(buf, len, clear);
13889                 break;
13890         /* Clear ring buffer */
13891 diff -NurpP --minimal linux-3.13.10/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/kernel/ptrace.c
13892 --- linux-3.13.10/kernel/ptrace.c       2014-01-22 20:39:13.000000000 +0000
13893 +++ linux-3.13.10-vs2.3.6.11/kernel/ptrace.c    2014-01-31 20:38:03.000000000 +0000
13894 @@ -23,6 +23,7 @@
13895  #include <linux/syscalls.h>
13896  #include <linux/uaccess.h>
13897  #include <linux/regset.h>
13898 +#include <linux/vs_context.h>
13899  #include <linux/hw_breakpoint.h>
13900  #include <linux/cn_proc.h>
13901  #include <linux/compat.h>
13902 @@ -264,6 +265,11 @@ ok:
13903         }
13904         rcu_read_unlock();
13905  
13906 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13907 +               return -EPERM;
13908 +       if (!vx_check(task->xid, VS_IDENT) &&
13909 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13910 +               return -EACCES;
13911         return security_ptrace_access_check(task, mode);
13912  }
13913  
13914 diff -NurpP --minimal linux-3.13.10/kernel/reboot.c linux-3.13.10-vs2.3.6.11/kernel/reboot.c
13915 --- linux-3.13.10/kernel/reboot.c       2014-01-22 20:39:13.000000000 +0000
13916 +++ linux-3.13.10-vs2.3.6.11/kernel/reboot.c    2014-02-01 00:19:40.000000000 +0000
13917 @@ -16,6 +16,7 @@
13918  #include <linux/syscalls.h>
13919  #include <linux/syscore_ops.h>
13920  #include <linux/uaccess.h>
13921 +#include <linux/vs_pid.h>
13922  
13923  /*
13924   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13925 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13926  
13927  static DEFINE_MUTEX(reboot_mutex);
13928  
13929 +long vs_reboot(unsigned int, void __user *);
13930 +
13931  /*
13932   * Reboot system call: for obvious reasons only root may call it,
13933   * and even root needs to set up some magic numbers in the registers
13934 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13935         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13936                 cmd = LINUX_REBOOT_CMD_HALT;
13937  
13938 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13939 +               return vs_reboot(cmd, arg);
13940 +
13941         mutex_lock(&reboot_mutex);
13942         switch (cmd) {
13943         case LINUX_REBOOT_CMD_RESTART:
13944 diff -NurpP --minimal linux-3.13.10/kernel/sched/core.c linux-3.13.10-vs2.3.6.11/kernel/sched/core.c
13945 --- linux-3.13.10/kernel/sched/core.c   2014-04-17 01:12:39.000000000 +0000
13946 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/core.c        2014-02-25 11:26:10.000000000 +0000
13947 @@ -73,6 +73,8 @@
13948  #include <linux/binfmts.h>
13949  #include <linux/context_tracking.h>
13950  #include <linux/compiler.h>
13951 +#include <linux/vs_sched.h>
13952 +#include <linux/vs_cvirt.h>
13953  
13954  #include <asm/switch_to.h>
13955  #include <asm/tlb.h>
13956 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13957                 nice = 19;
13958  
13959         if (increment < 0 && !can_nice(current, nice))
13960 -               return -EPERM;
13961 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13962  
13963         retval = security_task_setnice(current, nice);
13964         if (retval)
13965 diff -NurpP --minimal linux-3.13.10/kernel/sched/cputime.c linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c
13966 --- linux-3.13.10/kernel/sched/cputime.c        2013-11-25 15:47:03.000000000 +0000
13967 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c     2014-01-31 20:38:03.000000000 +0000
13968 @@ -4,6 +4,7 @@
13969  #include <linux/kernel_stat.h>
13970  #include <linux/static_key.h>
13971  #include <linux/context_tracking.h>
13972 +#include <linux/vs_sched.h>
13973  #include "sched.h"
13974  
13975  
13976 @@ -189,9 +193,12 @@ static inline
13977  void account_user_time(struct task_struct *p, cputime_t cputime,
13978                        cputime_t cputime_scaled)
13979  {
13980 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13981 +       int nice = (task_nice(p) > 0);
13982         int index;
13983  
13984         /* Add user time to process. */
13985         p->utime += cputime;
13986         p->utimescaled += cputime_scaled;
13987 +       vx_account_user(vxi, cputime, nice);
13988         account_group_user_time(p, cputime);
13989  
13990 -       index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
13991 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
13992  
13993         /* Add user time to cpustat. */
13994         task_group_account_field(p, index, (__force u64) cputime);
13995 @@ -215,14 +216,17 @@ static inline void task_group_account_fi
13996  void __account_system_time(struct task_struct *p, cputime_t cputime,
13997                         cputime_t cputime_scaled, int index)
13998  {
13999 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14000 +
14001         /* Add system time to process. */
14002         p->stime += cputime;
14003         p->stimescaled += cputime_scaled;
14004 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14005         account_group_system_time(p, cputime);
14006  
14007         /* Add system time to cpustat. */
14008 diff -NurpP --minimal linux-3.13.10/kernel/sched/fair.c linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c
14009 --- linux-3.13.10/kernel/sched/fair.c   2014-04-17 01:12:40.000000000 +0000
14010 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c        2014-04-17 01:17:11.000000000 +0000
14011 @@ -29,6 +29,7 @@
14012  #include <linux/mempolicy.h>
14013  #include <linux/migrate.h>
14014  #include <linux/task_work.h>
14015 +#include <linux/vs_cvirt.h>
14016  
14017  #include <trace/events/sched.h>
14018  
14019 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14020                 __enqueue_entity(cfs_rq, se);
14021         se->on_rq = 1;
14022  
14023 +       if (entity_is_task(se))
14024 +               vx_activate_task(task_of(se));
14025         if (cfs_rq->nr_running == 1) {
14026                 list_add_leaf_cfs_rq(cfs_rq);
14027                 check_enqueue_throttle(cfs_rq);
14028 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14029         if (se != cfs_rq->curr)
14030                 __dequeue_entity(cfs_rq, se);
14031         se->on_rq = 0;
14032 +       if (entity_is_task(se))
14033 +               vx_deactivate_task(task_of(se));
14034         account_entity_dequeue(cfs_rq, se);
14035  
14036         /*
14037 diff -NurpP --minimal linux-3.13.10/kernel/sched/proc.c linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c
14038 --- linux-3.13.10/kernel/sched/proc.c   2013-11-25 15:45:08.000000000 +0000
14039 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c        2014-01-31 21:22:36.000000000 +0000
14040 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14041   */
14042  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14043  {
14044 -       loads[0] = (avenrun[0] + offset) << shift;
14045 -       loads[1] = (avenrun[1] + offset) << shift;
14046 -       loads[2] = (avenrun[2] + offset) << shift;
14047 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14048 +               struct vx_info *vxi = current_vx_info();
14049 +
14050 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14051 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14052 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14053 +       } else {
14054 +               loads[0] = (avenrun[0] + offset) << shift;
14055 +               loads[1] = (avenrun[1] + offset) << shift;
14056 +               loads[2] = (avenrun[2] + offset) << shift;
14057 +       }
14058  }
14059  
14060  long calc_load_fold_active(struct rq *this_rq)
14061 diff -NurpP --minimal linux-3.13.10/kernel/signal.c linux-3.13.10-vs2.3.6.11/kernel/signal.c
14062 --- linux-3.13.10/kernel/signal.c       2014-01-22 20:39:13.000000000 +0000
14063 +++ linux-3.13.10-vs2.3.6.11/kernel/signal.c    2014-01-31 20:38:03.000000000 +0000
14064 @@ -33,6 +33,8 @@
14065  #include <linux/compat.h>
14066  #include <linux/cn_proc.h>
14067  #include <linux/compiler.h>
14068 +#include <linux/vs_context.h>
14069 +#include <linux/vs_pid.h>
14070  
14071  #define CREATE_TRACE_POINTS
14072  #include <trace/events/signal.h>
14073 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14074         struct pid *sid;
14075         int error;
14076  
14077 +       vxdprintk(VXD_CBIT(misc, 7),
14078 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14079 +               sig, info, t, vx_task_xid(t), t->pid);
14080 +
14081         if (!valid_signal(sig))
14082                 return -EINVAL;
14083  
14084 +/*     FIXME: needed? if so, why?
14085 +       if ((info != SEND_SIG_NOINFO) &&
14086 +               (is_si_special(info) || !si_fromuser(info)))
14087 +               goto skip;      */
14088 +
14089         if (!si_fromuser(info))
14090                 return 0;
14091  
14092 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14093                 }
14094         }
14095  
14096 +       error = -EPERM;
14097 +       if (t->pid == 1 && current->xid)
14098 +               return error;
14099 +
14100 +       error = -ESRCH;
14101 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14102 +                 loops, maybe ENOENT or EACCES? */
14103 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14104 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14105 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14106 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14107 +               return error;
14108 +       }
14109 +/* skip: */
14110         return security_task_kill(t, info, sig, 0);
14111  }
14112  
14113 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14114         rcu_read_lock();
14115  retry:
14116         p = pid_task(pid, PIDTYPE_PID);
14117 -       if (p) {
14118 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14119                 error = group_send_sig_info(sig, info, p);
14120                 if (unlikely(error == -ESRCH))
14121                         /*
14122 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14123  
14124         rcu_read_lock();
14125         p = pid_task(pid, PIDTYPE_PID);
14126 -       if (!p) {
14127 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14128                 ret = -ESRCH;
14129                 goto out_unlock;
14130         }
14131 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14132                 struct task_struct * p;
14133  
14134                 for_each_process(p) {
14135 -                       if (task_pid_vnr(p) > 1 &&
14136 -                                       !same_thread_group(p, current)) {
14137 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14138 +                               task_pid_vnr(p) > 1 &&
14139 +                               !same_thread_group(p, current) &&
14140 +                               !vx_current_initpid(p->pid)) {
14141                                 int err = group_send_sig_info(sig, info, p);
14142                                 ++count;
14143                                 if (err != -EPERM)
14144 @@ -2308,6 +2335,11 @@ relock:
14145                                 !sig_kernel_only(signr))
14146                         continue;
14147  
14148 +               /* virtual init is protected against user signals */
14149 +               if ((info->si_code == SI_USER) &&
14150 +                       vx_current_initpid(current->pid))
14151 +                       continue;
14152 +
14153                 if (sig_kernel_stop(signr)) {
14154                         /*
14155                          * The default action is to stop all threads in
14156 diff -NurpP --minimal linux-3.13.10/kernel/softirq.c linux-3.13.10-vs2.3.6.11/kernel/softirq.c
14157 --- linux-3.13.10/kernel/softirq.c      2014-01-22 20:39:13.000000000 +0000
14158 +++ linux-3.13.10-vs2.3.6.11/kernel/softirq.c   2014-01-31 20:38:03.000000000 +0000
14159 @@ -23,6 +23,7 @@
14160  #include <linux/smpboot.h>
14161  #include <linux/tick.h>
14162  #include <linux/irq.h>
14163 +#include <linux/vs_context.h>
14164  
14165  #define CREATE_TRACE_POINTS
14166  #include <trace/events/irq.h>
14167 diff -NurpP --minimal linux-3.13.10/kernel/sys.c linux-3.13.10-vs2.3.6.11/kernel/sys.c
14168 --- linux-3.13.10/kernel/sys.c  2014-01-22 20:39:13.000000000 +0000
14169 +++ linux-3.13.10-vs2.3.6.11/kernel/sys.c       2014-02-01 00:19:29.000000000 +0000
14170 @@ -54,6 +54,7 @@
14171  #include <linux/cred.h>
14172  
14173  #include <linux/kmsg_dump.h>
14174 +#include <linux/vs_pid.h>
14175  /* Move somewhere else to avoid recompiling? */
14176  #include <generated/utsrelease.h>
14177  
14178 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14179                 goto out;
14180         }
14181         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14182 -               error = -EACCES;
14183 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14184 +                       error = 0;
14185 +               else
14186 +                       error = -EACCES;
14187                 goto out;
14188         }
14189         no_nice = security_task_setnice(p, niceval);
14190 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14191                         else
14192                                 pgrp = task_pgrp(current);
14193                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14194 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14195 +                                       continue;
14196                                 error = set_one_prio(p, niceval, error);
14197                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14198                         break;
14199 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14200                         else
14201                                 pgrp = task_pgrp(current);
14202                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14203 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14204 +                                       continue;
14205                                 niceval = 20 - task_nice(p);
14206                                 if (niceval > retval)
14207                                         retval = niceval;
14208 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14209         int errno;
14210         char tmp[__NEW_UTS_LEN];
14211  
14212 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14213 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14214 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14215                 return -EPERM;
14216  
14217         if (len < 0 || len > __NEW_UTS_LEN)
14218 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14219         int errno;
14220         char tmp[__NEW_UTS_LEN];
14221  
14222 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14223 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14224 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14225                 return -EPERM;
14226         if (len < 0 || len > __NEW_UTS_LEN)
14227                 return -EINVAL;
14228 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14229                 /* Keep the capable check against init_user_ns until
14230                    cgroups can contain all limits */
14231                 if (new_rlim->rlim_max > rlim->rlim_max &&
14232 -                               !capable(CAP_SYS_RESOURCE))
14233 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14234                         retval = -EPERM;
14235                 if (!retval)
14236                         retval = security_task_setrlimit(tsk->group_leader,
14237 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14238             gid_eq(cred->gid, tcred->sgid) &&
14239             gid_eq(cred->gid, tcred->gid))
14240                 return 0;
14241 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14242 +       if (vx_ns_capable(tcred->user_ns,
14243 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14244                 return 0;
14245  
14246         return -EPERM;
14247 diff -NurpP --minimal linux-3.13.10/kernel/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/sysctl.c
14248 --- linux-3.13.10/kernel/sysctl.c       2014-04-17 01:12:40.000000000 +0000
14249 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl.c    2014-02-25 11:26:10.000000000 +0000
14250 @@ -83,6 +83,7 @@
14251  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14252  #include <linux/lockdep.h>
14253  #endif
14254 +extern char vshelper_path[];
14255  #ifdef CONFIG_CHR_DEV_SG
14256  #include <scsi/sg.h>
14257  #endif
14258 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14259                 .mode           = 0644,
14260                 .proc_handler   = proc_dostring,
14261         },
14262 +       {
14263 +               .procname       = "vshelper",
14264 +               .data           = &vshelper_path,
14265 +               .maxlen         = 256,
14266 +               .mode           = 0644,
14267 +               .proc_handler   = &proc_dostring,
14268 +       },
14269  
14270  #ifdef CONFIG_CHR_DEV_SG
14271         {
14272 diff -NurpP --minimal linux-3.13.10/kernel/sysctl_binary.c linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c
14273 --- linux-3.13.10/kernel/sysctl_binary.c        2014-01-22 20:39:13.000000000 +0000
14274 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c     2014-01-31 20:38:03.000000000 +0000
14275 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14276  
14277         { CTL_INT,      KERN_PANIC,                     "panic" },
14278         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14279 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14280  
14281         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14282         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14283 diff -NurpP --minimal linux-3.13.10/kernel/time/timekeeping.c linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c
14284 --- linux-3.13.10/kernel/time/timekeeping.c     2014-04-17 01:12:40.000000000 +0000
14285 +++ linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c  2014-02-25 11:26:10.000000000 +0000
14286 @@ -22,6 +22,7 @@
14287  #include <linux/stop_machine.h>
14288  #include <linux/pvclock_gtod.h>
14289  #include <linux/compiler.h>
14290 +#include <linux/vs_time.h>
14291  
14292  #include "tick-internal.h"
14293  #include "ntp_internal.h"
14294 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14295         } while (read_seqcount_retry(&timekeeper_seq, seq));
14296  
14297         timespec_add_ns(ts, nsecs);
14298 +       vx_adjust_timespec(ts);
14299  }
14300  EXPORT_SYMBOL(getrawmonotonic);
14301  
14302 diff -NurpP --minimal linux-3.13.10/kernel/time.c linux-3.13.10-vs2.3.6.11/kernel/time.c
14303 --- linux-3.13.10/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14304 +++ linux-3.13.10-vs2.3.6.11/kernel/time.c      2014-01-31 20:38:03.000000000 +0000
14305 @@ -37,6 +37,7 @@
14306  #include <linux/fs.h>
14307  #include <linux/math64.h>
14308  #include <linux/ptrace.h>
14309 +#include <linux/vs_time.h>
14310  
14311  #include <asm/uaccess.h>
14312  #include <asm/unistd.h>
14313 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14314         if (err)
14315                 return err;
14316  
14317 -       do_settimeofday(&tv);
14318 +       vx_settimeofday(&tv);
14319         return 0;
14320  }
14321  
14322 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14323                 }
14324         }
14325         if (tv)
14326 -               return do_settimeofday(tv);
14327 +               return vx_settimeofday(tv);
14328         return 0;
14329  }
14330  
14331 diff -NurpP --minimal linux-3.13.10/kernel/timer.c linux-3.13.10-vs2.3.6.11/kernel/timer.c
14332 --- linux-3.13.10/kernel/timer.c        2014-01-22 20:39:13.000000000 +0000
14333 +++ linux-3.13.10-vs2.3.6.11/kernel/timer.c     2014-01-31 20:38:03.000000000 +0000
14334 @@ -42,6 +42,10 @@
14335  #include <linux/sched/sysctl.h>
14336  #include <linux/slab.h>
14337  #include <linux/compat.h>
14338 +#include <linux/vs_base.h>
14339 +#include <linux/vs_cvirt.h>
14340 +#include <linux/vs_pid.h>
14341 +#include <linux/vserver/sched.h>
14342  
14343  #include <asm/uaccess.h>
14344  #include <asm/unistd.h>
14345 diff -NurpP --minimal linux-3.13.10/kernel/user_namespace.c linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c
14346 --- linux-3.13.10/kernel/user_namespace.c       2014-01-22 20:39:13.000000000 +0000
14347 +++ linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c    2014-01-31 20:38:03.000000000 +0000
14348 @@ -22,6 +22,7 @@
14349  #include <linux/ctype.h>
14350  #include <linux/projid.h>
14351  #include <linux/fs_struct.h>
14352 +#include <linux/vserver/global.h>
14353  
14354  static struct kmem_cache *user_ns_cachep __read_mostly;
14355  
14356 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14357  
14358         atomic_set(&ns->count, 1);
14359         /* Leave the new->user_ns reference with the new user namespace. */
14360 +       atomic_inc(&vs_global_user_ns);
14361         ns->parent = parent_ns;
14362         ns->level = parent_ns->level + 1;
14363         ns->owner = owner;
14364 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14365  
14366  static void userns_put(void *ns)
14367  {
14368 +       /* FIXME: maybe move into destroyer? */
14369 +       atomic_dec(&vs_global_user_ns);
14370         put_user_ns(ns);
14371  }
14372  
14373 diff -NurpP --minimal linux-3.13.10/kernel/utsname.c linux-3.13.10-vs2.3.6.11/kernel/utsname.c
14374 --- linux-3.13.10/kernel/utsname.c      2013-11-25 15:47:03.000000000 +0000
14375 +++ linux-3.13.10-vs2.3.6.11/kernel/utsname.c   2014-01-31 20:38:03.000000000 +0000
14376 @@ -16,14 +16,17 @@
14377  #include <linux/slab.h>
14378  #include <linux/user_namespace.h>
14379  #include <linux/proc_ns.h>
14380 +#include <linux/vserver/global.h>
14381  
14382  static struct uts_namespace *create_uts_ns(void)
14383  {
14384         struct uts_namespace *uts_ns;
14385  
14386         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14387 -       if (uts_ns)
14388 +       if (uts_ns) {
14389                 kref_init(&uts_ns->kref);
14390 +               atomic_inc(&vs_global_uts_ns);
14391 +       }
14392         return uts_ns;
14393  }
14394  
14395 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14396         ns = container_of(kref, struct uts_namespace, kref);
14397         put_user_ns(ns->user_ns);
14398         proc_free_inum(ns->proc_inum);
14399 +       atomic_dec(&vs_global_uts_ns);
14400         kfree(ns);
14401  }
14402  
14403 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Kconfig linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig
14404 --- linux-3.13.10/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14405 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig     2014-01-31 20:38:03.000000000 +0000
14406 @@ -0,0 +1,230 @@
14407 +#
14408 +# Linux VServer configuration
14409 +#
14410 +
14411 +menu "Linux VServer"
14412 +
14413 +config VSERVER_AUTO_LBACK
14414 +       bool    "Automatically Assign Loopback IP"
14415 +       default y
14416 +       help
14417 +         Automatically assign a guest specific loopback
14418 +         IP and add it to the kernel network stack on
14419 +         startup.
14420 +
14421 +config VSERVER_AUTO_SINGLE
14422 +       bool    "Automatic Single IP Special Casing"
14423 +       default n
14424 +       help
14425 +         This allows network contexts with a single IP to
14426 +         automatically remap 0.0.0.0 bindings to that IP,
14427 +         avoiding further network checks and improving
14428 +         performance.
14429 +
14430 +         (note: such guests do not allow to change the ip
14431 +          on the fly and do not show loopback addresses)
14432 +
14433 +config VSERVER_COWBL
14434 +       bool    "Enable COW Immutable Link Breaking"
14435 +       default y
14436 +       help
14437 +         This enables the COW (Copy-On-Write) link break code.
14438 +         It allows you to treat unified files like normal files
14439 +         when writing to them (which will implicitely break the
14440 +         link and create a copy of the unified file)
14441 +
14442 +config VSERVER_VTIME
14443 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14444 +       default n
14445 +       help
14446 +         This enables per guest time offsets to allow for
14447 +         adjusting the system clock individually per guest.
14448 +         this adds some overhead to the time functions and
14449 +         therefore should not be enabled without good reason.
14450 +
14451 +config VSERVER_DEVICE
14452 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14453 +       default n
14454 +       help
14455 +         This enables generic device remapping.
14456 +
14457 +config VSERVER_PROC_SECURE
14458 +       bool    "Enable Proc Security"
14459 +       depends on PROC_FS
14460 +       default y
14461 +       help
14462 +         This configures ProcFS security to initially hide
14463 +         non-process entries for all contexts except the main and
14464 +         spectator context (i.e. for all guests), which is a secure
14465 +         default.
14466 +
14467 +         (note: on 1.2x the entries were visible by default)
14468 +
14469 +choice
14470 +       prompt  "Persistent Inode Tagging"
14471 +       default TAGGING_ID24
14472 +       help
14473 +         This adds persistent context information to filesystems
14474 +         mounted with the tagxid option. Tagging is a requirement
14475 +         for per-context disk limits and per-context quota.
14476 +
14477 +
14478 +config TAGGING_NONE
14479 +       bool    "Disabled"
14480 +       help
14481 +         do not store per-context information in inodes.
14482 +
14483 +config TAGGING_UID16
14484 +       bool    "UID16/GID32"
14485 +       help
14486 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14487 +
14488 +config TAGGING_GID16
14489 +       bool    "UID32/GID16"
14490 +       help
14491 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14492 +
14493 +config TAGGING_ID24
14494 +       bool    "UID24/GID24"
14495 +       help
14496 +         uses the upper 8bit from UID and GID for XID tagging
14497 +         which leaves 24bit for UID/GID each, which should be
14498 +         more than sufficient for normal use.
14499 +
14500 +config TAGGING_INTERN
14501 +       bool    "UID32/GID32"
14502 +       help
14503 +         this uses otherwise reserved inode fields in the on
14504 +         disk representation, which limits the use to a few
14505 +         filesystems (currently ext2 and ext3)
14506 +
14507 +endchoice
14508 +
14509 +config TAG_NFSD
14510 +       bool    "Tag NFSD User Auth and Files"
14511 +       default n
14512 +       help
14513 +         Enable this if you do want the in-kernel NFS
14514 +         Server to use the tagging specified above.
14515 +         (will require patched clients too)
14516 +
14517 +config VSERVER_PRIVACY
14518 +       bool    "Honor Privacy Aspects of Guests"
14519 +       default n
14520 +       help
14521 +         When enabled, most context checks will disallow
14522 +         access to structures assigned to a specific context,
14523 +         like ptys or loop devices.
14524 +
14525 +config VSERVER_CONTEXTS
14526 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14527 +       range 1 65533
14528 +       default "768"   if 64BIT
14529 +       default "256"
14530 +       help
14531 +         This setting will optimize certain data structures
14532 +         and memory allocations according to the expected
14533 +         maximum.
14534 +
14535 +         note: this is not a strict upper limit.
14536 +
14537 +config VSERVER_WARN
14538 +       bool    "VServer Warnings"
14539 +       default y
14540 +       help
14541 +         This enables various runtime warnings, which will
14542 +         notify about potential manipulation attempts or
14543 +         resource shortage. It is generally considered to
14544 +         be a good idea to have that enabled.
14545 +
14546 +config VSERVER_WARN_DEVPTS
14547 +       bool    "VServer DevPTS Warnings"
14548 +       depends on VSERVER_WARN
14549 +       default y
14550 +       help
14551 +         This enables DevPTS related warnings, issued when a
14552 +         process inside a context tries to lookup or access
14553 +         a dynamic pts from the host or a different context.
14554 +
14555 +config VSERVER_DEBUG
14556 +       bool    "VServer Debugging Code"
14557 +       default n
14558 +       help
14559 +         Set this to yes if you want to be able to activate
14560 +         debugging output at runtime. It adds a very small
14561 +         overhead to all vserver related functions and
14562 +         increases the kernel size by about 20k.
14563 +
14564 +config VSERVER_HISTORY
14565 +       bool    "VServer History Tracing"
14566 +       depends on VSERVER_DEBUG
14567 +       default n
14568 +       help
14569 +         Set this to yes if you want to record the history of
14570 +         linux-vserver activities, so they can be replayed in
14571 +         the event of a kernel panic or oops.
14572 +
14573 +config VSERVER_HISTORY_SIZE
14574 +       int     "Per-CPU History Size (32-65536)"
14575 +       depends on VSERVER_HISTORY
14576 +       range 32 65536
14577 +       default 64
14578 +       help
14579 +         This allows you to specify the number of entries in
14580 +         the per-CPU history buffer.
14581 +
14582 +config VSERVER_EXTRA_MNT_CHECK
14583 +       bool    "Extra Checks for Reachability"
14584 +       default n
14585 +       help
14586 +         Set this to yes if you want to do extra checks for
14587 +         vfsmount reachability in the proc filesystem code.
14588 +         This shouldn't be required on any setup utilizing
14589 +         mnt namespaces.
14590 +
14591 +choice
14592 +       prompt  "Quotes used in debug and warn messages"
14593 +       default QUOTES_ISO8859
14594 +
14595 +config QUOTES_ISO8859
14596 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14597 +       help
14598 +         This uses the extended ASCII characters \xbb
14599 +         and \xab for quoting file and process names.
14600 +
14601 +config QUOTES_UTF8
14602 +       bool    "UTF-8 angle quotes"
14603 +       help
14604 +         This uses the the UTF-8 sequences for angle
14605 +         quotes to quote file and process names.
14606 +
14607 +config QUOTES_ASCII
14608 +       bool    "ASCII single quotes"
14609 +       help
14610 +         This uses the ASCII single quote character
14611 +         (\x27) to quote file and process names.
14612 +
14613 +endchoice
14614 +
14615 +endmenu
14616 +
14617 +
14618 +config VSERVER
14619 +       bool
14620 +       default y
14621 +       select NAMESPACES
14622 +       select UTS_NS
14623 +       select IPC_NS
14624 +#      select USER_NS
14625 +       select SYSVIPC
14626 +
14627 +config VSERVER_SECURITY
14628 +       bool
14629 +       depends on SECURITY
14630 +       default y
14631 +       select SECURITY_CAPABILITIES
14632 +
14633 +config VSERVER_DISABLED
14634 +       bool
14635 +       default n
14636 +
14637 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Makefile linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile
14638 --- linux-3.13.10/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14639 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile    2014-01-31 20:38:03.000000000 +0000
14640 @@ -0,0 +1,18 @@
14641 +#
14642 +# Makefile for the Linux vserver routines.
14643 +#
14644 +
14645 +
14646 +obj-y          += vserver.o
14647 +
14648 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14649 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14650 +                  dlimit.o tag.o
14651 +
14652 +vserver-$(CONFIG_INET) += inet.o
14653 +vserver-$(CONFIG_PROC_FS) += proc.o
14654 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14655 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14656 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14657 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14658 +
14659 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c
14660 --- linux-3.13.10/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14661 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c     2014-01-31 20:38:03.000000000 +0000
14662 @@ -0,0 +1,42 @@
14663 +/*
14664 + *  linux/kernel/vserver/cacct.c
14665 + *
14666 + *  Virtual Server: Context Accounting
14667 + *
14668 + *  Copyright (C) 2006-2007 Herbert Pötzl
14669 + *
14670 + *  V0.01  added accounting stats
14671 + *
14672 + */
14673 +
14674 +#include <linux/types.h>
14675 +#include <linux/vs_context.h>
14676 +#include <linux/vserver/cacct_cmd.h>
14677 +#include <linux/vserver/cacct_int.h>
14678 +
14679 +#include <asm/errno.h>
14680 +#include <asm/uaccess.h>
14681 +
14682 +
14683 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14684 +{
14685 +       struct vcmd_sock_stat_v0 vc_data;
14686 +       int j, field;
14687 +
14688 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14689 +               return -EFAULT;
14690 +
14691 +       field = vc_data.field;
14692 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14693 +               return -EINVAL;
14694 +
14695 +       for (j = 0; j < 3; j++) {
14696 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14697 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14698 +       }
14699 +
14700 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14701 +               return -EFAULT;
14702 +       return 0;
14703 +}
14704 +
14705 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
14706 --- linux-3.13.10/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14707 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h        2014-01-31 20:38:03.000000000 +0000
14708 @@ -0,0 +1,25 @@
14709 +
14710 +
14711 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14712 +{
14713 +       int i, j;
14714 +
14715 +
14716 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14717 +               for (j = 0; j < 3; j++) {
14718 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14719 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14720 +               }
14721 +       }
14722 +       for (i = 0; i < 8; i++)
14723 +               atomic_set(&cacct->slab[i], 0);
14724 +       for (i = 0; i < 5; i++)
14725 +               for (j = 0; j < 4; j++)
14726 +                       atomic_set(&cacct->page[i][j], 0);
14727 +}
14728 +
14729 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14730 +{
14731 +       return;
14732 +}
14733 +
14734 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
14735 --- linux-3.13.10/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14736 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h        2014-01-31 20:38:03.000000000 +0000
14737 @@ -0,0 +1,53 @@
14738 +#ifndef _VX_CACCT_PROC_H
14739 +#define _VX_CACCT_PROC_H
14740 +
14741 +#include <linux/vserver/cacct_int.h>
14742 +
14743 +
14744 +#define VX_SOCKA_TOP   \
14745 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14746 +
14747 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14748 +{
14749 +       int i, j, length = 0;
14750 +       static char *type[VXA_SOCK_SIZE] = {
14751 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14752 +       };
14753 +
14754 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14755 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14756 +               length += sprintf(buffer + length, "%s:", type[i]);
14757 +               for (j = 0; j < 3; j++) {
14758 +                       length += sprintf(buffer + length,
14759 +                               "\t%10lu/%-10lu",
14760 +                               vx_sock_count(cacct, i, j),
14761 +                               vx_sock_total(cacct, i, j));
14762 +               }
14763 +               buffer[length++] = '\n';
14764 +       }
14765 +
14766 +       length += sprintf(buffer + length, "\n");
14767 +       length += sprintf(buffer + length,
14768 +               "slab:\t %8u %8u %8u %8u\n",
14769 +               atomic_read(&cacct->slab[1]),
14770 +               atomic_read(&cacct->slab[4]),
14771 +               atomic_read(&cacct->slab[0]),
14772 +               atomic_read(&cacct->slab[2]));
14773 +
14774 +       length += sprintf(buffer + length, "\n");
14775 +       for (i = 0; i < 5; i++) {
14776 +               length += sprintf(buffer + length,
14777 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14778 +                       atomic_read(&cacct->page[i][0]),
14779 +                       atomic_read(&cacct->page[i][1]),
14780 +                       atomic_read(&cacct->page[i][2]),
14781 +                       atomic_read(&cacct->page[i][3]),
14782 +                       atomic_read(&cacct->page[i][4]),
14783 +                       atomic_read(&cacct->page[i][5]),
14784 +                       atomic_read(&cacct->page[i][6]),
14785 +                       atomic_read(&cacct->page[i][7]));
14786 +       }
14787 +       return length;
14788 +}
14789 +
14790 +#endif /* _VX_CACCT_PROC_H */
14791 diff -NurpP --minimal linux-3.13.10/kernel/vserver/context.c linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c
14792 --- linux-3.13.10/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14793 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c   2014-01-31 20:38:03.000000000 +0000
14794 @@ -0,0 +1,1119 @@
14795 +/*
14796 + *  linux/kernel/vserver/context.c
14797 + *
14798 + *  Virtual Server: Context Support
14799 + *
14800 + *  Copyright (C) 2003-2011  Herbert Pötzl
14801 + *
14802 + *  V0.01  context helper
14803 + *  V0.02  vx_ctx_kill syscall command
14804 + *  V0.03  replaced context_info calls
14805 + *  V0.04  redesign of struct (de)alloc
14806 + *  V0.05  rlimit basic implementation
14807 + *  V0.06  task_xid and info commands
14808 + *  V0.07  context flags and caps
14809 + *  V0.08  switch to RCU based hash
14810 + *  V0.09  revert to non RCU for now
14811 + *  V0.10  and back to working RCU hash
14812 + *  V0.11  and back to locking again
14813 + *  V0.12  referenced context store
14814 + *  V0.13  separate per cpu data
14815 + *  V0.14  changed vcmds to vxi arg
14816 + *  V0.15  added context stat
14817 + *  V0.16  have __create claim() the vxi
14818 + *  V0.17  removed older and legacy stuff
14819 + *  V0.18  added user credentials
14820 + *  V0.19  added warn mask
14821 + *
14822 + */
14823 +
14824 +#include <linux/slab.h>
14825 +#include <linux/types.h>
14826 +#include <linux/security.h>
14827 +#include <linux/pid_namespace.h>
14828 +#include <linux/capability.h>
14829 +
14830 +#include <linux/vserver/context.h>
14831 +#include <linux/vserver/network.h>
14832 +#include <linux/vserver/debug.h>
14833 +#include <linux/vserver/limit.h>
14834 +#include <linux/vserver/limit_int.h>
14835 +#include <linux/vserver/space.h>
14836 +#include <linux/init_task.h>
14837 +#include <linux/fs_struct.h>
14838 +#include <linux/cred.h>
14839 +
14840 +#include <linux/vs_context.h>
14841 +#include <linux/vs_limit.h>
14842 +#include <linux/vs_pid.h>
14843 +#include <linux/vserver/context_cmd.h>
14844 +
14845 +#include "cvirt_init.h"
14846 +#include "cacct_init.h"
14847 +#include "limit_init.h"
14848 +#include "sched_init.h"
14849 +
14850 +
14851 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14852 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14853 +
14854 +
14855 +/*     now inactive context structures */
14856 +
14857 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14858 +
14859 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14860 +
14861 +
14862 +/*     __alloc_vx_info()
14863 +
14864 +       * allocate an initialized vx_info struct
14865 +       * doesn't make it visible (hash)                        */
14866 +
14867 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14868 +{
14869 +       struct vx_info *new = NULL;
14870 +       int cpu, index;
14871 +
14872 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14873 +
14874 +       /* would this benefit from a slab cache? */
14875 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14876 +       if (!new)
14877 +               return 0;
14878 +
14879 +       memset(new, 0, sizeof(struct vx_info));
14880 +#ifdef CONFIG_SMP
14881 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14882 +       if (!new->ptr_pc)
14883 +               goto error;
14884 +#endif
14885 +       new->vx_id = xid;
14886 +       INIT_HLIST_NODE(&new->vx_hlist);
14887 +       atomic_set(&new->vx_usecnt, 0);
14888 +       atomic_set(&new->vx_tasks, 0);
14889 +       new->vx_parent = NULL;
14890 +       new->vx_state = 0;
14891 +       init_waitqueue_head(&new->vx_wait);
14892 +
14893 +       /* prepare reaper */
14894 +       get_task_struct(init_pid_ns.child_reaper);
14895 +       new->vx_reaper = init_pid_ns.child_reaper;
14896 +       new->vx_badness_bias = 0;
14897 +
14898 +       /* rest of init goes here */
14899 +       vx_info_init_limit(&new->limit);
14900 +       vx_info_init_sched(&new->sched);
14901 +       vx_info_init_cvirt(&new->cvirt);
14902 +       vx_info_init_cacct(&new->cacct);
14903 +
14904 +       /* per cpu data structures */
14905 +       for_each_possible_cpu(cpu) {
14906 +               vx_info_init_sched_pc(
14907 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14908 +               vx_info_init_cvirt_pc(
14909 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14910 +       }
14911 +
14912 +       new->vx_flags = VXF_INIT_SET;
14913 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14914 +       new->vx_ccaps = 0;
14915 +       new->vx_umask = 0;
14916 +       new->vx_wmask = 0;
14917 +
14918 +       new->reboot_cmd = 0;
14919 +       new->exit_code = 0;
14920 +
14921 +       // preconfig spaces
14922 +       for (index = 0; index < VX_SPACES; index++) {
14923 +               struct _vx_space *space = &new->space[index];
14924 +
14925 +               // filesystem
14926 +               spin_lock(&init_fs.lock);
14927 +               init_fs.users++;
14928 +               spin_unlock(&init_fs.lock);
14929 +               space->vx_fs = &init_fs;
14930 +
14931 +               /* FIXME: do we want defaults? */
14932 +               // space->vx_real_cred = 0;
14933 +               // space->vx_cred = 0;
14934 +       }
14935 +
14936 +
14937 +       vxdprintk(VXD_CBIT(xid, 0),
14938 +               "alloc_vx_info(%d) = %p", xid, new);
14939 +       vxh_alloc_vx_info(new);
14940 +       atomic_inc(&vx_global_ctotal);
14941 +       return new;
14942 +#ifdef CONFIG_SMP
14943 +error:
14944 +       kfree(new);
14945 +       return 0;
14946 +#endif
14947 +}
14948 +
14949 +/*     __dealloc_vx_info()
14950 +
14951 +       * final disposal of vx_info                             */
14952 +
14953 +static void __dealloc_vx_info(struct vx_info *vxi)
14954 +{
14955 +#ifdef CONFIG_VSERVER_WARN
14956 +       struct vx_info_save vxis;
14957 +       int cpu;
14958 +#endif
14959 +       vxdprintk(VXD_CBIT(xid, 0),
14960 +               "dealloc_vx_info(%p)", vxi);
14961 +       vxh_dealloc_vx_info(vxi);
14962 +
14963 +#ifdef CONFIG_VSERVER_WARN
14964 +       enter_vx_info(vxi, &vxis);
14965 +       vx_info_exit_limit(&vxi->limit);
14966 +       vx_info_exit_sched(&vxi->sched);
14967 +       vx_info_exit_cvirt(&vxi->cvirt);
14968 +       vx_info_exit_cacct(&vxi->cacct);
14969 +
14970 +       for_each_possible_cpu(cpu) {
14971 +               vx_info_exit_sched_pc(
14972 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14973 +               vx_info_exit_cvirt_pc(
14974 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14975 +       }
14976 +       leave_vx_info(&vxis);
14977 +#endif
14978 +
14979 +       vxi->vx_id = -1;
14980 +       vxi->vx_state |= VXS_RELEASED;
14981 +
14982 +#ifdef CONFIG_SMP
14983 +       free_percpu(vxi->ptr_pc);
14984 +#endif
14985 +       kfree(vxi);
14986 +       atomic_dec(&vx_global_ctotal);
14987 +}
14988 +
14989 +static void __shutdown_vx_info(struct vx_info *vxi)
14990 +{
14991 +       struct nsproxy *nsproxy;
14992 +       struct fs_struct *fs;
14993 +       struct cred *cred;
14994 +       int index, kill;
14995 +
14996 +       might_sleep();
14997 +
14998 +       vxi->vx_state |= VXS_SHUTDOWN;
14999 +       vs_state_change(vxi, VSC_SHUTDOWN);
15000 +
15001 +       for (index = 0; index < VX_SPACES; index++) {
15002 +               struct _vx_space *space = &vxi->space[index];
15003 +
15004 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15005 +               if (nsproxy)
15006 +                       put_nsproxy(nsproxy);
15007 +
15008 +               fs = xchg(&space->vx_fs, NULL);
15009 +               spin_lock(&fs->lock);
15010 +               kill = !--fs->users;
15011 +               spin_unlock(&fs->lock);
15012 +               if (kill)
15013 +                       free_fs_struct(fs);
15014 +
15015 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15016 +               if (cred)
15017 +                       abort_creds(cred);
15018 +       }
15019 +}
15020 +
15021 +/* exported stuff */
15022 +
15023 +void free_vx_info(struct vx_info *vxi)
15024 +{
15025 +       unsigned long flags;
15026 +       unsigned index;
15027 +
15028 +       /* check for reference counts first */
15029 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15030 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15031 +
15032 +       /* context must not be hashed */
15033 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15034 +
15035 +       /* context shutdown is mandatory */
15036 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15037 +
15038 +       /* spaces check */
15039 +       for (index = 0; index < VX_SPACES; index++) {
15040 +               struct _vx_space *space = &vxi->space[index];
15041 +
15042 +               BUG_ON(space->vx_nsproxy);
15043 +               BUG_ON(space->vx_fs);
15044 +               // BUG_ON(space->vx_real_cred);
15045 +               // BUG_ON(space->vx_cred);
15046 +       }
15047 +
15048 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15049 +       hlist_del(&vxi->vx_hlist);
15050 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15051 +
15052 +       __dealloc_vx_info(vxi);
15053 +}
15054 +
15055 +
15056 +/*     hash table for vx_info hash */
15057 +
15058 +#define VX_HASH_SIZE   13
15059 +
15060 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15061 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15062 +
15063 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15064 +
15065 +
15066 +static inline unsigned int __hashval(vxid_t xid)
15067 +{
15068 +       return (xid % VX_HASH_SIZE);
15069 +}
15070 +
15071 +
15072 +
15073 +/*     __hash_vx_info()
15074 +
15075 +       * add the vxi to the global hash table
15076 +       * requires the hash_lock to be held                     */
15077 +
15078 +static inline void __hash_vx_info(struct vx_info *vxi)
15079 +{
15080 +       struct hlist_head *head;
15081 +
15082 +       vxd_assert_lock(&vx_info_hash_lock);
15083 +       vxdprintk(VXD_CBIT(xid, 4),
15084 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15085 +       vxh_hash_vx_info(vxi);
15086 +
15087 +       /* context must not be hashed */
15088 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15089 +
15090 +       vxi->vx_state |= VXS_HASHED;
15091 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15092 +       hlist_add_head(&vxi->vx_hlist, head);
15093 +       atomic_inc(&vx_global_cactive);
15094 +}
15095 +
15096 +/*     __unhash_vx_info()
15097 +
15098 +       * remove the vxi from the global hash table
15099 +       * requires the hash_lock to be held                     */
15100 +
15101 +static inline void __unhash_vx_info(struct vx_info *vxi)
15102 +{
15103 +       unsigned long flags;
15104 +
15105 +       vxd_assert_lock(&vx_info_hash_lock);
15106 +       vxdprintk(VXD_CBIT(xid, 4),
15107 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15108 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15109 +       vxh_unhash_vx_info(vxi);
15110 +
15111 +       /* context must be hashed */
15112 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15113 +       /* but without tasks */
15114 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15115 +
15116 +       vxi->vx_state &= ~VXS_HASHED;
15117 +       hlist_del_init(&vxi->vx_hlist);
15118 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15119 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15120 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15121 +       atomic_dec(&vx_global_cactive);
15122 +}
15123 +
15124 +
15125 +/*     __lookup_vx_info()
15126 +
15127 +       * requires the hash_lock to be held
15128 +       * doesn't increment the vx_refcnt                       */
15129 +
15130 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15131 +{
15132 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15133 +       struct hlist_node *pos;
15134 +       struct vx_info *vxi;
15135 +
15136 +       vxd_assert_lock(&vx_info_hash_lock);
15137 +       hlist_for_each(pos, head) {
15138 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15139 +
15140 +               if (vxi->vx_id == xid)
15141 +                       goto found;
15142 +       }
15143 +       vxi = NULL;
15144 +found:
15145 +       vxdprintk(VXD_CBIT(xid, 0),
15146 +               "__lookup_vx_info(#%u): %p[#%u]",
15147 +               xid, vxi, vxi ? vxi->vx_id : 0);
15148 +       vxh_lookup_vx_info(vxi, xid);
15149 +       return vxi;
15150 +}
15151 +
15152 +
15153 +/*     __create_vx_info()
15154 +
15155 +       * create the requested context
15156 +       * get(), claim() and hash it                            */
15157 +
15158 +static struct vx_info *__create_vx_info(int id)
15159 +{
15160 +       struct vx_info *new, *vxi = NULL;
15161 +
15162 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15163 +
15164 +       if (!(new = __alloc_vx_info(id)))
15165 +               return ERR_PTR(-ENOMEM);
15166 +
15167 +       /* required to make dynamic xids unique */
15168 +       spin_lock(&vx_info_hash_lock);
15169 +
15170 +       /* static context requested */
15171 +       if ((vxi = __lookup_vx_info(id))) {
15172 +               vxdprintk(VXD_CBIT(xid, 0),
15173 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15174 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15175 +                       vxi = ERR_PTR(-EBUSY);
15176 +               else
15177 +                       vxi = ERR_PTR(-EEXIST);
15178 +               goto out_unlock;
15179 +       }
15180 +       /* new context */
15181 +       vxdprintk(VXD_CBIT(xid, 0),
15182 +               "create_vx_info(%d) = %p (new)", id, new);
15183 +       claim_vx_info(new, NULL);
15184 +       __hash_vx_info(get_vx_info(new));
15185 +       vxi = new, new = NULL;
15186 +
15187 +out_unlock:
15188 +       spin_unlock(&vx_info_hash_lock);
15189 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15190 +       if (new)
15191 +               __dealloc_vx_info(new);
15192 +       return vxi;
15193 +}
15194 +
15195 +
15196 +/*     exported stuff                                          */
15197 +
15198 +
15199 +void unhash_vx_info(struct vx_info *vxi)
15200 +{
15201 +       spin_lock(&vx_info_hash_lock);
15202 +       __unhash_vx_info(vxi);
15203 +       spin_unlock(&vx_info_hash_lock);
15204 +       __shutdown_vx_info(vxi);
15205 +       __wakeup_vx_info(vxi);
15206 +}
15207 +
15208 +
15209 +/*     lookup_vx_info()
15210 +
15211 +       * search for a vx_info and get() it
15212 +       * negative id means current                             */
15213 +
15214 +struct vx_info *lookup_vx_info(int id)
15215 +{
15216 +       struct vx_info *vxi = NULL;
15217 +
15218 +       if (id < 0) {
15219 +               vxi = get_vx_info(current_vx_info());
15220 +       } else if (id > 1) {
15221 +               spin_lock(&vx_info_hash_lock);
15222 +               vxi = get_vx_info(__lookup_vx_info(id));
15223 +               spin_unlock(&vx_info_hash_lock);
15224 +       }
15225 +       return vxi;
15226 +}
15227 +
15228 +/*     xid_is_hashed()
15229 +
15230 +       * verify that xid is still hashed                       */
15231 +
15232 +int xid_is_hashed(vxid_t xid)
15233 +{
15234 +       int hashed;
15235 +
15236 +       spin_lock(&vx_info_hash_lock);
15237 +       hashed = (__lookup_vx_info(xid) != NULL);
15238 +       spin_unlock(&vx_info_hash_lock);
15239 +       return hashed;
15240 +}
15241 +
15242 +#ifdef CONFIG_PROC_FS
15243 +
15244 +/*     get_xid_list()
15245 +
15246 +       * get a subset of hashed xids for proc
15247 +       * assumes size is at least one                          */
15248 +
15249 +int get_xid_list(int index, unsigned int *xids, int size)
15250 +{
15251 +       int hindex, nr_xids = 0;
15252 +
15253 +       /* only show current and children */
15254 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15255 +               if (index > 0)
15256 +                       return 0;
15257 +               xids[nr_xids] = vx_current_xid();
15258 +               return 1;
15259 +       }
15260 +
15261 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15262 +               struct hlist_head *head = &vx_info_hash[hindex];
15263 +               struct hlist_node *pos;
15264 +
15265 +               spin_lock(&vx_info_hash_lock);
15266 +               hlist_for_each(pos, head) {
15267 +                       struct vx_info *vxi;
15268 +
15269 +                       if (--index > 0)
15270 +                               continue;
15271 +
15272 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15273 +                       xids[nr_xids] = vxi->vx_id;
15274 +                       if (++nr_xids >= size) {
15275 +                               spin_unlock(&vx_info_hash_lock);
15276 +                               goto out;
15277 +                       }
15278 +               }
15279 +               /* keep the lock time short */
15280 +               spin_unlock(&vx_info_hash_lock);
15281 +       }
15282 +out:
15283 +       return nr_xids;
15284 +}
15285 +#endif
15286 +
15287 +#ifdef CONFIG_VSERVER_DEBUG
15288 +
15289 +void   dump_vx_info_inactive(int level)
15290 +{
15291 +       struct hlist_node *entry, *next;
15292 +
15293 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15294 +               struct vx_info *vxi =
15295 +                       list_entry(entry, struct vx_info, vx_hlist);
15296 +
15297 +               dump_vx_info(vxi, level);
15298 +       }
15299 +}
15300 +
15301 +#endif
15302 +
15303 +#if 0
15304 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15305 +{
15306 +       struct user_struct *new_user, *old_user;
15307 +
15308 +       if (!p || !vxi)
15309 +               BUG();
15310 +
15311 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15312 +               return -EACCES;
15313 +
15314 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15315 +       if (!new_user)
15316 +               return -ENOMEM;
15317 +
15318 +       old_user = p->user;
15319 +       if (new_user != old_user) {
15320 +               atomic_inc(&new_user->processes);
15321 +               atomic_dec(&old_user->processes);
15322 +               p->user = new_user;
15323 +       }
15324 +       free_uid(old_user);
15325 +       return 0;
15326 +}
15327 +#endif
15328 +
15329 +#if 0
15330 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15331 +{
15332 +       // p->cap_effective &= vxi->vx_cap_bset;
15333 +       p->cap_effective =
15334 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15335 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15336 +       p->cap_inheritable =
15337 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15338 +       // p->cap_permitted &= vxi->vx_cap_bset;
15339 +       p->cap_permitted =
15340 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15341 +}
15342 +#endif
15343 +
15344 +
15345 +#include <linux/file.h>
15346 +#include <linux/fdtable.h>
15347 +
15348 +static int vx_openfd_task(struct task_struct *tsk)
15349 +{
15350 +       struct files_struct *files = tsk->files;
15351 +       struct fdtable *fdt;
15352 +       const unsigned long *bptr;
15353 +       int count, total;
15354 +
15355 +       /* no rcu_read_lock() because of spin_lock() */
15356 +       spin_lock(&files->file_lock);
15357 +       fdt = files_fdtable(files);
15358 +       bptr = fdt->open_fds;
15359 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15360 +       for (total = 0; count > 0; count--) {
15361 +               if (*bptr)
15362 +                       total += hweight_long(*bptr);
15363 +               bptr++;
15364 +       }
15365 +       spin_unlock(&files->file_lock);
15366 +       return total;
15367 +}
15368 +
15369 +
15370 +/*     for *space compatibility */
15371 +
15372 +asmlinkage long sys_unshare(unsigned long);
15373 +
15374 +/*
15375 + *     migrate task to new context
15376 + *     gets vxi, puts old_vxi on change
15377 + *     optionally unshares namespaces (hack)
15378 + */
15379 +
15380 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15381 +{
15382 +       struct vx_info *old_vxi;
15383 +       int ret = 0;
15384 +
15385 +       if (!p || !vxi)
15386 +               BUG();
15387 +
15388 +       vxdprintk(VXD_CBIT(xid, 5),
15389 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15390 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15391 +
15392 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15393 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15394 +               return -EACCES;
15395 +
15396 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15397 +               return -EFAULT;
15398 +
15399 +       old_vxi = task_get_vx_info(p);
15400 +       if (old_vxi == vxi)
15401 +               goto out;
15402 +
15403 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15404 +       {
15405 +               int openfd;
15406 +
15407 +               task_lock(p);
15408 +               openfd = vx_openfd_task(p);
15409 +
15410 +               if (old_vxi) {
15411 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15412 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15413 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15414 +                       /* FIXME: what about the struct files here? */
15415 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15416 +                       /* account for the executable */
15417 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15418 +               }
15419 +               atomic_inc(&vxi->cvirt.nr_threads);
15420 +               atomic_inc(&vxi->cvirt.nr_running);
15421 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15422 +               /* FIXME: what about the struct files here? */
15423 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15424 +               /* account for the executable */
15425 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15426 +
15427 +               if (old_vxi) {
15428 +                       release_vx_info(old_vxi, p);
15429 +                       clr_vx_info(&p->vx_info);
15430 +               }
15431 +               claim_vx_info(vxi, p);
15432 +               set_vx_info(&p->vx_info, vxi);
15433 +               p->xid = vxi->vx_id;
15434 +
15435 +               vxdprintk(VXD_CBIT(xid, 5),
15436 +                       "moved task %p into vxi:%p[#%d]",
15437 +                       p, vxi, vxi->vx_id);
15438 +
15439 +               // vx_mask_cap_bset(vxi, p);
15440 +               task_unlock(p);
15441 +
15442 +               /* hack for *spaces to provide compatibility */
15443 +               if (unshare) {
15444 +                       struct nsproxy *old_nsp, *new_nsp;
15445 +
15446 +                       ret = unshare_nsproxy_namespaces(
15447 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15448 +                               &new_nsp, NULL, NULL);
15449 +                       if (ret)
15450 +                               goto out;
15451 +
15452 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15453 +                       vx_set_space(vxi,
15454 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15455 +                       put_nsproxy(old_nsp);
15456 +               }
15457 +       }
15458 +out:
15459 +       put_vx_info(old_vxi);
15460 +       return ret;
15461 +}
15462 +
15463 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15464 +{
15465 +       struct task_struct *old_reaper;
15466 +       struct vx_info *reaper_vxi;
15467 +
15468 +       if (!vxi)
15469 +               return -EINVAL;
15470 +
15471 +       vxdprintk(VXD_CBIT(xid, 6),
15472 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15473 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15474 +
15475 +       old_reaper = vxi->vx_reaper;
15476 +       if (old_reaper == p)
15477 +               return 0;
15478 +
15479 +       reaper_vxi = task_get_vx_info(p);
15480 +       if (reaper_vxi && reaper_vxi != vxi) {
15481 +               vxwprintk(1,
15482 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15483 +                       "for [xid #%u]",
15484 +                       p->comm, p->pid, p->xid, vx_current_xid());
15485 +               goto out;
15486 +       }
15487 +
15488 +       /* set new child reaper */
15489 +       get_task_struct(p);
15490 +       vxi->vx_reaper = p;
15491 +       put_task_struct(old_reaper);
15492 +out:
15493 +       put_vx_info(reaper_vxi);
15494 +       return 0;
15495 +}
15496 +
15497 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15498 +{
15499 +       if (!vxi)
15500 +               return -EINVAL;
15501 +
15502 +       vxdprintk(VXD_CBIT(xid, 6),
15503 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15504 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15505 +
15506 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15507 +       // vxi->vx_initpid = p->tgid;
15508 +       vxi->vx_initpid = p->pid;
15509 +       return 0;
15510 +}
15511 +
15512 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15513 +{
15514 +       vxdprintk(VXD_CBIT(xid, 6),
15515 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15516 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15517 +
15518 +       vxi->exit_code = code;
15519 +       vxi->vx_initpid = 0;
15520 +}
15521 +
15522 +
15523 +void vx_set_persistent(struct vx_info *vxi)
15524 +{
15525 +       vxdprintk(VXD_CBIT(xid, 6),
15526 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15527 +
15528 +       get_vx_info(vxi);
15529 +       claim_vx_info(vxi, NULL);
15530 +}
15531 +
15532 +void vx_clear_persistent(struct vx_info *vxi)
15533 +{
15534 +       vxdprintk(VXD_CBIT(xid, 6),
15535 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15536 +
15537 +       release_vx_info(vxi, NULL);
15538 +       put_vx_info(vxi);
15539 +}
15540 +
15541 +void vx_update_persistent(struct vx_info *vxi)
15542 +{
15543 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15544 +               vx_set_persistent(vxi);
15545 +       else
15546 +               vx_clear_persistent(vxi);
15547 +}
15548 +
15549 +
15550 +/*     task must be current or locked          */
15551 +
15552 +void   exit_vx_info(struct task_struct *p, int code)
15553 +{
15554 +       struct vx_info *vxi = p->vx_info;
15555 +
15556 +       if (vxi) {
15557 +               atomic_dec(&vxi->cvirt.nr_threads);
15558 +               vx_nproc_dec(p);
15559 +
15560 +               vxi->exit_code = code;
15561 +               release_vx_info(vxi, p);
15562 +       }
15563 +}
15564 +
15565 +void   exit_vx_info_early(struct task_struct *p, int code)
15566 +{
15567 +       struct vx_info *vxi = p->vx_info;
15568 +
15569 +       if (vxi) {
15570 +               if (vxi->vx_initpid == p->pid)
15571 +                       vx_exit_init(vxi, p, code);
15572 +               if (vxi->vx_reaper == p)
15573 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15574 +       }
15575 +}
15576 +
15577 +
15578 +/* vserver syscall commands below here */
15579 +
15580 +/* taks xid and vx_info functions */
15581 +
15582 +#include <asm/uaccess.h>
15583 +
15584 +
15585 +int vc_task_xid(uint32_t id)
15586 +{
15587 +       vxid_t xid;
15588 +
15589 +       if (id) {
15590 +               struct task_struct *tsk;
15591 +
15592 +               rcu_read_lock();
15593 +               tsk = find_task_by_real_pid(id);
15594 +               xid = (tsk) ? tsk->xid : -ESRCH;
15595 +               rcu_read_unlock();
15596 +       } else
15597 +               xid = vx_current_xid();
15598 +       return xid;
15599 +}
15600 +
15601 +
15602 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15603 +{
15604 +       struct vcmd_vx_info_v0 vc_data;
15605 +
15606 +       vc_data.xid = vxi->vx_id;
15607 +       vc_data.initpid = vxi->vx_initpid;
15608 +
15609 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15610 +               return -EFAULT;
15611 +       return 0;
15612 +}
15613 +
15614 +
15615 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15616 +{
15617 +       struct vcmd_ctx_stat_v0 vc_data;
15618 +
15619 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15620 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15621 +
15622 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15623 +               return -EFAULT;
15624 +       return 0;
15625 +}
15626 +
15627 +
15628 +/* context functions */
15629 +
15630 +int vc_ctx_create(uint32_t xid, void __user *data)
15631 +{
15632 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15633 +       struct vx_info *new_vxi;
15634 +       int ret;
15635 +
15636 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15637 +               return -EFAULT;
15638 +
15639 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15640 +               return -EINVAL;
15641 +
15642 +       new_vxi = __create_vx_info(xid);
15643 +       if (IS_ERR(new_vxi))
15644 +               return PTR_ERR(new_vxi);
15645 +
15646 +       /* initial flags */
15647 +       new_vxi->vx_flags = vc_data.flagword;
15648 +
15649 +       ret = -ENOEXEC;
15650 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15651 +               goto out;
15652 +
15653 +       ret = vx_migrate_task(current, new_vxi, (!data));
15654 +       if (ret)
15655 +               goto out;
15656 +
15657 +       /* return context id on success */
15658 +       ret = new_vxi->vx_id;
15659 +
15660 +       /* get a reference for persistent contexts */
15661 +       if ((vc_data.flagword & VXF_PERSISTENT))
15662 +               vx_set_persistent(new_vxi);
15663 +out:
15664 +       release_vx_info(new_vxi, NULL);
15665 +       put_vx_info(new_vxi);
15666 +       return ret;
15667 +}
15668 +
15669 +
15670 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15671 +{
15672 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15673 +       int ret;
15674 +
15675 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15676 +               return -EFAULT;
15677 +
15678 +       ret = vx_migrate_task(current, vxi, 0);
15679 +       if (ret)
15680 +               return ret;
15681 +       if (vc_data.flagword & VXM_SET_INIT)
15682 +               ret = vx_set_init(vxi, current);
15683 +       if (ret)
15684 +               return ret;
15685 +       if (vc_data.flagword & VXM_SET_REAPER)
15686 +               ret = vx_set_reaper(vxi, current);
15687 +       return ret;
15688 +}
15689 +
15690 +
15691 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15692 +{
15693 +       struct vcmd_ctx_flags_v0 vc_data;
15694 +
15695 +       vc_data.flagword = vxi->vx_flags;
15696 +
15697 +       /* special STATE flag handling */
15698 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15699 +
15700 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15701 +               return -EFAULT;
15702 +       return 0;
15703 +}
15704 +
15705 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15706 +{
15707 +       struct vcmd_ctx_flags_v0 vc_data;
15708 +       uint64_t mask, trigger;
15709 +
15710 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15711 +               return -EFAULT;
15712 +
15713 +       /* special STATE flag handling */
15714 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15715 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15716 +
15717 +       if (vxi == current_vx_info()) {
15718 +               /* if (trigger & VXF_STATE_SETUP)
15719 +                       vx_mask_cap_bset(vxi, current); */
15720 +               if (trigger & VXF_STATE_INIT) {
15721 +                       int ret;
15722 +
15723 +                       ret = vx_set_init(vxi, current);
15724 +                       if (ret)
15725 +                               return ret;
15726 +                       ret = vx_set_reaper(vxi, current);
15727 +                       if (ret)
15728 +                               return ret;
15729 +               }
15730 +       }
15731 +
15732 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15733 +               vc_data.flagword, mask);
15734 +       if (trigger & VXF_PERSISTENT)
15735 +               vx_update_persistent(vxi);
15736 +
15737 +       return 0;
15738 +}
15739 +
15740 +
15741 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15742 +{
15743 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15744 +
15745 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15746 +       return v;
15747 +}
15748 +
15749 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15750 +{
15751 +       kernel_cap_t c = __cap_empty_set;
15752 +
15753 +       c.cap[0] = v & 0xFFFFFFFF;
15754 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15755 +
15756 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15757 +       return c;
15758 +}
15759 +
15760 +
15761 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15762 +{
15763 +       if (bcaps)
15764 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15765 +       if (ccaps)
15766 +               *ccaps = vxi->vx_ccaps;
15767 +
15768 +       return 0;
15769 +}
15770 +
15771 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15772 +{
15773 +       struct vcmd_ctx_caps_v1 vc_data;
15774 +       int ret;
15775 +
15776 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15777 +       if (ret)
15778 +               return ret;
15779 +       vc_data.cmask = ~0ULL;
15780 +
15781 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15782 +               return -EFAULT;
15783 +       return 0;
15784 +}
15785 +
15786 +static int do_set_caps(struct vx_info *vxi,
15787 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15788 +{
15789 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15790 +
15791 +#if 0
15792 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15793 +               bcaps, bmask, ccaps, cmask);
15794 +#endif
15795 +       vxi->vx_bcaps = cap_t_from_caps(
15796 +               vs_mask_flags(bcold, bcaps, bmask));
15797 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15798 +
15799 +       return 0;
15800 +}
15801 +
15802 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15803 +{
15804 +       struct vcmd_ctx_caps_v1 vc_data;
15805 +
15806 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15807 +               return -EFAULT;
15808 +
15809 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15810 +}
15811 +
15812 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15813 +{
15814 +       struct vcmd_bcaps vc_data;
15815 +       int ret;
15816 +
15817 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15818 +       if (ret)
15819 +               return ret;
15820 +       vc_data.bmask = ~0ULL;
15821 +
15822 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15823 +               return -EFAULT;
15824 +       return 0;
15825 +}
15826 +
15827 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15828 +{
15829 +       struct vcmd_bcaps vc_data;
15830 +
15831 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15832 +               return -EFAULT;
15833 +
15834 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15835 +}
15836 +
15837 +
15838 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15839 +{
15840 +       struct vcmd_umask vc_data;
15841 +
15842 +       vc_data.umask = vxi->vx_umask;
15843 +       vc_data.mask = ~0ULL;
15844 +
15845 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15846 +               return -EFAULT;
15847 +       return 0;
15848 +}
15849 +
15850 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15851 +{
15852 +       struct vcmd_umask vc_data;
15853 +
15854 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15855 +               return -EFAULT;
15856 +
15857 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15858 +               vc_data.umask, vc_data.mask);
15859 +       return 0;
15860 +}
15861 +
15862 +
15863 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15864 +{
15865 +       struct vcmd_wmask vc_data;
15866 +
15867 +       vc_data.wmask = vxi->vx_wmask;
15868 +       vc_data.mask = ~0ULL;
15869 +
15870 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15871 +               return -EFAULT;
15872 +       return 0;
15873 +}
15874 +
15875 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15876 +{
15877 +       struct vcmd_wmask vc_data;
15878 +
15879 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15880 +               return -EFAULT;
15881 +
15882 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15883 +               vc_data.wmask, vc_data.mask);
15884 +       return 0;
15885 +}
15886 +
15887 +
15888 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15889 +{
15890 +       struct vcmd_badness_v0 vc_data;
15891 +
15892 +       vc_data.bias = vxi->vx_badness_bias;
15893 +
15894 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15895 +               return -EFAULT;
15896 +       return 0;
15897 +}
15898 +
15899 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15900 +{
15901 +       struct vcmd_badness_v0 vc_data;
15902 +
15903 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15904 +               return -EFAULT;
15905 +
15906 +       vxi->vx_badness_bias = vc_data.bias;
15907 +       return 0;
15908 +}
15909 +
15910 +#include <linux/module.h>
15911 +
15912 +EXPORT_SYMBOL_GPL(free_vx_info);
15913 +
15914 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c
15915 --- linux-3.13.10/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15916 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c     2014-01-31 20:38:04.000000000 +0000
15917 @@ -0,0 +1,313 @@
15918 +/*
15919 + *  linux/kernel/vserver/cvirt.c
15920 + *
15921 + *  Virtual Server: Context Virtualization
15922 + *
15923 + *  Copyright (C) 2004-2007  Herbert Pötzl
15924 + *
15925 + *  V0.01  broken out from limit.c
15926 + *  V0.02  added utsname stuff
15927 + *  V0.03  changed vcmds to vxi arg
15928 + *
15929 + */
15930 +
15931 +#include <linux/types.h>
15932 +#include <linux/utsname.h>
15933 +#include <linux/vs_cvirt.h>
15934 +#include <linux/vserver/switch.h>
15935 +#include <linux/vserver/cvirt_cmd.h>
15936 +
15937 +#include <asm/uaccess.h>
15938 +
15939 +
15940 +void vx_vsi_boottime(struct timespec *boottime)
15941 +{
15942 +       struct vx_info *vxi = current_vx_info();
15943 +
15944 +       set_normalized_timespec(boottime,
15945 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15946 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15947 +       return;
15948 +}
15949 +
15950 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15951 +{
15952 +       struct vx_info *vxi = current_vx_info();
15953 +
15954 +       set_normalized_timespec(uptime,
15955 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15956 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15957 +       if (!idle)
15958 +               return;
15959 +       set_normalized_timespec(idle,
15960 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15961 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15962 +       return;
15963 +}
15964 +
15965 +uint64_t vx_idle_jiffies(void)
15966 +{
15967 +       return init_task.utime + init_task.stime;
15968 +}
15969 +
15970 +
15971 +
15972 +static inline uint32_t __update_loadavg(uint32_t load,
15973 +       int wsize, int delta, int n)
15974 +{
15975 +       unsigned long long calc, prev;
15976 +
15977 +       /* just set it to n */
15978 +       if (unlikely(delta >= wsize))
15979 +               return (n << FSHIFT);
15980 +
15981 +       calc = delta * n;
15982 +       calc <<= FSHIFT;
15983 +       prev = (wsize - delta);
15984 +       prev *= load;
15985 +       calc += prev;
15986 +       do_div(calc, wsize);
15987 +       return calc;
15988 +}
15989 +
15990 +
15991 +void vx_update_load(struct vx_info *vxi)
15992 +{
15993 +       uint32_t now, last, delta;
15994 +       unsigned int nr_running, nr_uninterruptible;
15995 +       unsigned int total;
15996 +       unsigned long flags;
15997 +
15998 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
15999 +
16000 +       now = jiffies;
16001 +       last = vxi->cvirt.load_last;
16002 +       delta = now - last;
16003 +
16004 +       if (delta < 5*HZ)
16005 +               goto out;
16006 +
16007 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16008 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16009 +       total = nr_running + nr_uninterruptible;
16010 +
16011 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16012 +               60*HZ, delta, total);
16013 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16014 +               5*60*HZ, delta, total);
16015 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16016 +               15*60*HZ, delta, total);
16017 +
16018 +       vxi->cvirt.load_last = now;
16019 +out:
16020 +       atomic_inc(&vxi->cvirt.load_updates);
16021 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16022 +}
16023 +
16024 +
16025 +/*
16026 + * Commands to do_syslog:
16027 + *
16028 + *      0 -- Close the log.  Currently a NOP.
16029 + *      1 -- Open the log. Currently a NOP.
16030 + *      2 -- Read from the log.
16031 + *      3 -- Read all messages remaining in the ring buffer.
16032 + *      4 -- Read and clear all messages remaining in the ring buffer
16033 + *      5 -- Clear ring buffer.
16034 + *      6 -- Disable printk's to console
16035 + *      7 -- Enable printk's to console
16036 + *      8 -- Set level of messages printed to console
16037 + *      9 -- Return number of unread characters in the log buffer
16038 + *     10 -- Return size of the log buffer
16039 + */
16040 +int vx_do_syslog(int type, char __user *buf, int len)
16041 +{
16042 +       int error = 0;
16043 +       int do_clear = 0;
16044 +       struct vx_info *vxi = current_vx_info();
16045 +       struct _vx_syslog *log;
16046 +
16047 +       if (!vxi)
16048 +               return -EINVAL;
16049 +       log = &vxi->cvirt.syslog;
16050 +
16051 +       switch (type) {
16052 +       case 0:         /* Close log */
16053 +       case 1:         /* Open log */
16054 +               break;
16055 +       case 2:         /* Read from log */
16056 +               error = wait_event_interruptible(log->log_wait,
16057 +                       (log->log_start - log->log_end));
16058 +               if (error)
16059 +                       break;
16060 +               spin_lock_irq(&log->logbuf_lock);
16061 +               spin_unlock_irq(&log->logbuf_lock);
16062 +               break;
16063 +       case 4:         /* Read/clear last kernel messages */
16064 +               do_clear = 1;
16065 +               /* fall through */
16066 +       case 3:         /* Read last kernel messages */
16067 +               return 0;
16068 +
16069 +       case 5:         /* Clear ring buffer */
16070 +               return 0;
16071 +
16072 +       case 6:         /* Disable logging to console */
16073 +       case 7:         /* Enable logging to console */
16074 +       case 8:         /* Set level of messages printed to console */
16075 +               break;
16076 +
16077 +       case 9:         /* Number of chars in the log buffer */
16078 +               return 0;
16079 +       case 10:        /* Size of the log buffer */
16080 +               return 0;
16081 +       default:
16082 +               error = -EINVAL;
16083 +               break;
16084 +       }
16085 +       return error;
16086 +}
16087 +
16088 +
16089 +/* virtual host info names */
16090 +
16091 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16092 +{
16093 +       struct nsproxy *nsproxy;
16094 +       struct uts_namespace *uts;
16095 +
16096 +       if (id == VHIN_CONTEXT)
16097 +               return vxi->vx_name;
16098 +
16099 +       nsproxy = vxi->space[0].vx_nsproxy;
16100 +       if (!nsproxy)
16101 +               return NULL;
16102 +
16103 +       uts = nsproxy->uts_ns;
16104 +       if (!uts)
16105 +               return NULL;
16106 +
16107 +       switch (id) {
16108 +       case VHIN_SYSNAME:
16109 +               return uts->name.sysname;
16110 +       case VHIN_NODENAME:
16111 +               return uts->name.nodename;
16112 +       case VHIN_RELEASE:
16113 +               return uts->name.release;
16114 +       case VHIN_VERSION:
16115 +               return uts->name.version;
16116 +       case VHIN_MACHINE:
16117 +               return uts->name.machine;
16118 +       case VHIN_DOMAINNAME:
16119 +               return uts->name.domainname;
16120 +       default:
16121 +               return NULL;
16122 +       }
16123 +       return NULL;
16124 +}
16125 +
16126 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16127 +{
16128 +       struct vcmd_vhi_name_v0 vc_data;
16129 +       char *name;
16130 +
16131 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16132 +               return -EFAULT;
16133 +
16134 +       name = vx_vhi_name(vxi, vc_data.field);
16135 +       if (!name)
16136 +               return -EINVAL;
16137 +
16138 +       memcpy(name, vc_data.name, 65);
16139 +       return 0;
16140 +}
16141 +
16142 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16143 +{
16144 +       struct vcmd_vhi_name_v0 vc_data;
16145 +       char *name;
16146 +
16147 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16148 +               return -EFAULT;
16149 +
16150 +       name = vx_vhi_name(vxi, vc_data.field);
16151 +       if (!name)
16152 +               return -EINVAL;
16153 +
16154 +       memcpy(vc_data.name, name, 65);
16155 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16156 +               return -EFAULT;
16157 +       return 0;
16158 +}
16159 +
16160 +
16161 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16162 +{
16163 +       struct vcmd_virt_stat_v0 vc_data;
16164 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16165 +       struct timespec uptime;
16166 +
16167 +       do_posix_clock_monotonic_gettime(&uptime);
16168 +       set_normalized_timespec(&uptime,
16169 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16170 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16171 +
16172 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16173 +       vc_data.uptime = timespec_to_ns(&uptime);
16174 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16175 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16176 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16177 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16178 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16179 +       vc_data.load[0] = cvirt->load[0];
16180 +       vc_data.load[1] = cvirt->load[1];
16181 +       vc_data.load[2] = cvirt->load[2];
16182 +
16183 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16184 +               return -EFAULT;
16185 +       return 0;
16186 +}
16187 +
16188 +
16189 +#ifdef CONFIG_VSERVER_VTIME
16190 +
16191 +/* virtualized time base */
16192 +
16193 +void vx_adjust_timespec(struct timespec *ts)
16194 +{
16195 +       struct vx_info *vxi;
16196 +
16197 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16198 +               return;
16199 +
16200 +       vxi = current_vx_info();
16201 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16202 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16203 +
16204 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16205 +               ts->tv_sec++;
16206 +               ts->tv_nsec -= NSEC_PER_SEC;
16207 +       } else if (ts->tv_nsec < 0) {
16208 +               ts->tv_sec--;
16209 +               ts->tv_nsec += NSEC_PER_SEC;
16210 +       }
16211 +}
16212 +
16213 +int vx_settimeofday(const struct timespec *ts)
16214 +{
16215 +       struct timespec ats, delta;
16216 +       struct vx_info *vxi;
16217 +
16218 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16219 +               return do_settimeofday(ts);
16220 +
16221 +       getnstimeofday(&ats);
16222 +       delta = timespec_sub(*ts, ats);
16223 +
16224 +       vxi = current_vx_info();
16225 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16226 +       return 0;
16227 +}
16228 +
16229 +#endif
16230 +
16231 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
16232 --- linux-3.13.10/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16233 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h        2014-01-31 20:38:04.000000000 +0000
16234 @@ -0,0 +1,70 @@
16235 +
16236 +
16237 +extern uint64_t vx_idle_jiffies(void);
16238 +
16239 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16240 +{
16241 +       uint64_t idle_jiffies = vx_idle_jiffies();
16242 +       uint64_t nsuptime;
16243 +
16244 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16245 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16246 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16247 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16248 +       cvirt->bias_ts.tv_sec = 0;
16249 +       cvirt->bias_ts.tv_nsec = 0;
16250 +
16251 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16252 +       atomic_set(&cvirt->nr_threads, 0);
16253 +       atomic_set(&cvirt->nr_running, 0);
16254 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16255 +       atomic_set(&cvirt->nr_onhold, 0);
16256 +
16257 +       spin_lock_init(&cvirt->load_lock);
16258 +       cvirt->load_last = jiffies;
16259 +       atomic_set(&cvirt->load_updates, 0);
16260 +       cvirt->load[0] = 0;
16261 +       cvirt->load[1] = 0;
16262 +       cvirt->load[2] = 0;
16263 +       atomic_set(&cvirt->total_forks, 0);
16264 +
16265 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16266 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16267 +       cvirt->syslog.log_start = 0;
16268 +       cvirt->syslog.log_end = 0;
16269 +       cvirt->syslog.con_start = 0;
16270 +       cvirt->syslog.logged_chars = 0;
16271 +}
16272 +
16273 +static inline
16274 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16275 +{
16276 +       // cvirt_pc->cpustat = { 0 };
16277 +}
16278 +
16279 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16280 +{
16281 +#ifdef CONFIG_VSERVER_WARN
16282 +       int value;
16283 +#endif
16284 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16285 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16286 +               cvirt, value);
16287 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16288 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16289 +               cvirt, value);
16290 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16291 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16292 +               cvirt, value);
16293 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16294 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16295 +               cvirt, value);
16296 +       return;
16297 +}
16298 +
16299 +static inline
16300 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16301 +{
16302 +       return;
16303 +}
16304 +
16305 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
16306 --- linux-3.13.10/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
16307 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h        2014-01-31 20:38:04.000000000 +0000
16308 @@ -0,0 +1,123 @@
16309 +#ifndef _VX_CVIRT_PROC_H
16310 +#define _VX_CVIRT_PROC_H
16311 +
16312 +#include <linux/nsproxy.h>
16313 +#include <linux/mnt_namespace.h>
16314 +#include <linux/ipc_namespace.h>
16315 +#include <linux/utsname.h>
16316 +#include <linux/ipc.h>
16317 +
16318 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16319 +
16320 +static inline
16321 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16322 +{
16323 +       struct mnt_namespace *ns;
16324 +       struct uts_namespace *uts;
16325 +       struct ipc_namespace *ipc;
16326 +       int length = 0;
16327 +
16328 +       if (!nsproxy)
16329 +               goto out;
16330 +
16331 +       length += sprintf(buffer + length,
16332 +               "NSProxy:\t%p [%p,%p,%p]\n",
16333 +               nsproxy, nsproxy->mnt_ns,
16334 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16335 +
16336 +       ns = nsproxy->mnt_ns;
16337 +       if (!ns)
16338 +               goto skip_ns;
16339 +
16340 +       length += vx_info_mnt_namespace(ns, buffer + length);
16341 +
16342 +skip_ns:
16343 +
16344 +       uts = nsproxy->uts_ns;
16345 +       if (!uts)
16346 +               goto skip_uts;
16347 +
16348 +       length += sprintf(buffer + length,
16349 +               "SysName:\t%.*s\n"
16350 +               "NodeName:\t%.*s\n"
16351 +               "Release:\t%.*s\n"
16352 +               "Version:\t%.*s\n"
16353 +               "Machine:\t%.*s\n"
16354 +               "DomainName:\t%.*s\n",
16355 +               __NEW_UTS_LEN, uts->name.sysname,
16356 +               __NEW_UTS_LEN, uts->name.nodename,
16357 +               __NEW_UTS_LEN, uts->name.release,
16358 +               __NEW_UTS_LEN, uts->name.version,
16359 +               __NEW_UTS_LEN, uts->name.machine,
16360 +               __NEW_UTS_LEN, uts->name.domainname);
16361 +skip_uts:
16362 +
16363 +       ipc = nsproxy->ipc_ns;
16364 +       if (!ipc)
16365 +               goto skip_ipc;
16366 +
16367 +       length += sprintf(buffer + length,
16368 +               "SEMS:\t\t%d %d %d %d  %d\n"
16369 +               "MSG:\t\t%d %d %d\n"
16370 +               "SHM:\t\t%lu %lu  %d %ld\n",
16371 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16372 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16373 +               ipc->used_sems,
16374 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16375 +               (unsigned long)ipc->shm_ctlmax,
16376 +               (unsigned long)ipc->shm_ctlall,
16377 +               ipc->shm_ctlmni, ipc->shm_tot);
16378 +skip_ipc:
16379 +out:
16380 +       return length;
16381 +}
16382 +
16383 +
16384 +#include <linux/sched.h>
16385 +
16386 +#define LOAD_INT(x) ((x) >> FSHIFT)
16387 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16388 +
16389 +static inline
16390 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16391 +{
16392 +       int length = 0;
16393 +       int a, b, c;
16394 +
16395 +       length += sprintf(buffer + length,
16396 +               "BiasUptime:\t%lu.%02lu\n",
16397 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16398 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16399 +
16400 +       a = cvirt->load[0] + (FIXED_1 / 200);
16401 +       b = cvirt->load[1] + (FIXED_1 / 200);
16402 +       c = cvirt->load[2] + (FIXED_1 / 200);
16403 +       length += sprintf(buffer + length,
16404 +               "nr_threads:\t%d\n"
16405 +               "nr_running:\t%d\n"
16406 +               "nr_unintr:\t%d\n"
16407 +               "nr_onhold:\t%d\n"
16408 +               "load_updates:\t%d\n"
16409 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16410 +               "total_forks:\t%d\n",
16411 +               atomic_read(&cvirt->nr_threads),
16412 +               atomic_read(&cvirt->nr_running),
16413 +               atomic_read(&cvirt->nr_uninterruptible),
16414 +               atomic_read(&cvirt->nr_onhold),
16415 +               atomic_read(&cvirt->load_updates),
16416 +               LOAD_INT(a), LOAD_FRAC(a),
16417 +               LOAD_INT(b), LOAD_FRAC(b),
16418 +               LOAD_INT(c), LOAD_FRAC(c),
16419 +               atomic_read(&cvirt->total_forks));
16420 +       return length;
16421 +}
16422 +
16423 +static inline
16424 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16425 +       char *buffer, int cpu)
16426 +{
16427 +       int length = 0;
16428 +       return length;
16429 +}
16430 +
16431 +#endif /* _VX_CVIRT_PROC_H */
16432 diff -NurpP --minimal linux-3.13.10/kernel/vserver/debug.c linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c
16433 --- linux-3.13.10/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16434 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c     2014-01-31 20:38:04.000000000 +0000
16435 @@ -0,0 +1,32 @@
16436 +/*
16437 + *  kernel/vserver/debug.c
16438 + *
16439 + *  Copyright (C) 2005-2007 Herbert Pötzl
16440 + *
16441 + *  V0.01  vx_info dump support
16442 + *
16443 + */
16444 +
16445 +#include <linux/module.h>
16446 +
16447 +#include <linux/vserver/context.h>
16448 +
16449 +
16450 +void   dump_vx_info(struct vx_info *vxi, int level)
16451 +{
16452 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16453 +               atomic_read(&vxi->vx_usecnt),
16454 +               atomic_read(&vxi->vx_tasks),
16455 +               vxi->vx_state);
16456 +       if (level > 0) {
16457 +               __dump_vx_limit(&vxi->limit);
16458 +               __dump_vx_sched(&vxi->sched);
16459 +               __dump_vx_cvirt(&vxi->cvirt);
16460 +               __dump_vx_cacct(&vxi->cacct);
16461 +       }
16462 +       printk("---\n");
16463 +}
16464 +
16465 +
16466 +EXPORT_SYMBOL_GPL(dump_vx_info);
16467 +
16468 diff -NurpP --minimal linux-3.13.10/kernel/vserver/device.c linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c
16469 --- linux-3.13.10/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16470 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c    2014-01-31 20:38:04.000000000 +0000
16471 @@ -0,0 +1,443 @@
16472 +/*
16473 + *  linux/kernel/vserver/device.c
16474 + *
16475 + *  Linux-VServer: Device Support
16476 + *
16477 + *  Copyright (C) 2006  Herbert Pötzl
16478 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16479 + *
16480 + *  V0.01  device mapping basics
16481 + *  V0.02  added defaults
16482 + *
16483 + */
16484 +
16485 +#include <linux/slab.h>
16486 +#include <linux/rcupdate.h>
16487 +#include <linux/fs.h>
16488 +#include <linux/namei.h>
16489 +#include <linux/hash.h>
16490 +
16491 +#include <asm/errno.h>
16492 +#include <asm/uaccess.h>
16493 +#include <linux/vserver/base.h>
16494 +#include <linux/vserver/debug.h>
16495 +#include <linux/vserver/context.h>
16496 +#include <linux/vserver/device.h>
16497 +#include <linux/vserver/device_cmd.h>
16498 +
16499 +
16500 +#define DMAP_HASH_BITS 4
16501 +
16502 +
16503 +struct vs_mapping {
16504 +       union {
16505 +               struct hlist_node hlist;
16506 +               struct list_head list;
16507 +       } u;
16508 +#define dm_hlist       u.hlist
16509 +#define dm_list                u.list
16510 +       vxid_t xid;
16511 +       dev_t device;
16512 +       struct vx_dmap_target target;
16513 +};
16514 +
16515 +
16516 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16517 +
16518 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16519 +
16520 +static struct vx_dmap_target dmap_defaults[2] = {
16521 +       { .flags = DATTR_OPEN },
16522 +       { .flags = DATTR_OPEN },
16523 +};
16524 +
16525 +
16526 +struct kmem_cache *dmap_cachep __read_mostly;
16527 +
16528 +int __init dmap_cache_init(void)
16529 +{
16530 +       dmap_cachep = kmem_cache_create("dmap_cache",
16531 +               sizeof(struct vs_mapping), 0,
16532 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16533 +       return 0;
16534 +}
16535 +
16536 +__initcall(dmap_cache_init);
16537 +
16538 +
16539 +static inline unsigned int __hashval(dev_t dev, int bits)
16540 +{
16541 +       return hash_long((unsigned long)dev, bits);
16542 +}
16543 +
16544 +
16545 +/*     __hash_mapping()
16546 + *     add the mapping to the hash table
16547 + */
16548 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16549 +{
16550 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16551 +       struct hlist_head *head, *hash = dmap_main_hash;
16552 +       int device = vdm->device;
16553 +
16554 +       spin_lock(hash_lock);
16555 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16556 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16557 +
16558 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16559 +       hlist_add_head(&vdm->dm_hlist, head);
16560 +       spin_unlock(hash_lock);
16561 +}
16562 +
16563 +
16564 +static inline int __mode_to_default(umode_t mode)
16565 +{
16566 +       switch (mode) {
16567 +       case S_IFBLK:
16568 +               return 0;
16569 +       case S_IFCHR:
16570 +               return 1;
16571 +       default:
16572 +               BUG();
16573 +       }
16574 +}
16575 +
16576 +
16577 +/*     __set_default()
16578 + *     set a default
16579 + */
16580 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16581 +       struct vx_dmap_target *vdmt)
16582 +{
16583 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16584 +       spin_lock(hash_lock);
16585 +
16586 +       if (vxi)
16587 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16588 +       else
16589 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16590 +
16591 +
16592 +       spin_unlock(hash_lock);
16593 +
16594 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16595 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16596 +}
16597 +
16598 +
16599 +/*     __remove_default()
16600 + *     remove a default
16601 + */
16602 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16603 +{
16604 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16605 +       spin_lock(hash_lock);
16606 +
16607 +       if (vxi)
16608 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16609 +       else    /* remove == reset */
16610 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16611 +
16612 +       spin_unlock(hash_lock);
16613 +       return 0;
16614 +}
16615 +
16616 +
16617 +/*     __find_mapping()
16618 + *     find a mapping in the hash table
16619 + *
16620 + *     caller must hold hash_lock
16621 + */
16622 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16623 +       struct vs_mapping **local, struct vs_mapping **global)
16624 +{
16625 +       struct hlist_head *hash = dmap_main_hash;
16626 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16627 +       struct hlist_node *pos;
16628 +       struct vs_mapping *vdm;
16629 +
16630 +       *local = NULL;
16631 +       if (global)
16632 +               *global = NULL;
16633 +
16634 +       hlist_for_each(pos, head) {
16635 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16636 +
16637 +               if ((vdm->device == device) &&
16638 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16639 +                       if (vdm->xid == xid) {
16640 +                               *local = vdm;
16641 +                               return 1;
16642 +                       } else if (global && vdm->xid == 0)
16643 +                               *global = vdm;
16644 +               }
16645 +       }
16646 +
16647 +       if (global && *global)
16648 +               return 0;
16649 +       else
16650 +               return -ENOENT;
16651 +}
16652 +
16653 +
16654 +/*     __lookup_mapping()
16655 + *     find a mapping and store the result in target and flags
16656 + */
16657 +static inline int __lookup_mapping(struct vx_info *vxi,
16658 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16659 +{
16660 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16661 +       struct vs_mapping *vdm, *global;
16662 +       struct vx_dmap_target *vdmt;
16663 +       int ret = 0;
16664 +       vxid_t xid = vxi->vx_id;
16665 +       int index;
16666 +
16667 +       spin_lock(hash_lock);
16668 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16669 +               ret = 1;
16670 +               vdmt = &vdm->target;
16671 +               goto found;
16672 +       }
16673 +
16674 +       index = __mode_to_default(mode);
16675 +       if (vxi && vxi->dmap.targets[index].flags) {
16676 +               ret = 2;
16677 +               vdmt = &vxi->dmap.targets[index];
16678 +       } else if (global) {
16679 +               ret = 3;
16680 +               vdmt = &global->target;
16681 +               goto found;
16682 +       } else {
16683 +               ret = 4;
16684 +               vdmt = &dmap_defaults[index];
16685 +       }
16686 +
16687 +found:
16688 +       if (target && (vdmt->flags & DATTR_REMAP))
16689 +               *target = vdmt->target;
16690 +       else if (target)
16691 +               *target = device;
16692 +       if (flags)
16693 +               *flags = vdmt->flags;
16694 +
16695 +       spin_unlock(hash_lock);
16696 +
16697 +       return ret;
16698 +}
16699 +
16700 +
16701 +/*     __remove_mapping()
16702 + *     remove a mapping from the hash table
16703 + */
16704 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16705 +       umode_t mode)
16706 +{
16707 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16708 +       struct vs_mapping *vdm = NULL;
16709 +       int ret = 0;
16710 +
16711 +       spin_lock(hash_lock);
16712 +
16713 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16714 +               NULL);
16715 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16716 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16717 +       if (ret < 0)
16718 +               goto out;
16719 +       hlist_del(&vdm->dm_hlist);
16720 +
16721 +out:
16722 +       spin_unlock(hash_lock);
16723 +       if (vdm)
16724 +               kmem_cache_free(dmap_cachep, vdm);
16725 +       return ret;
16726 +}
16727 +
16728 +
16729 +
16730 +int vs_map_device(struct vx_info *vxi,
16731 +       dev_t device, dev_t *target, umode_t mode)
16732 +{
16733 +       int ret, flags = DATTR_MASK;
16734 +
16735 +       if (!vxi) {
16736 +               if (target)
16737 +                       *target = device;
16738 +               goto out;
16739 +       }
16740 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16741 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16742 +               device, target ? *target : 0, flags, mode, ret);
16743 +out:
16744 +       return (flags & DATTR_MASK);
16745 +}
16746 +
16747 +
16748 +
16749 +static int do_set_mapping(struct vx_info *vxi,
16750 +       dev_t device, dev_t target, int flags, umode_t mode)
16751 +{
16752 +       if (device) {
16753 +               struct vs_mapping *new;
16754 +
16755 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16756 +               if (!new)
16757 +                       return -ENOMEM;
16758 +
16759 +               INIT_HLIST_NODE(&new->dm_hlist);
16760 +               new->device = device;
16761 +               new->target.target = target;
16762 +               new->target.flags = flags | mode;
16763 +               new->xid = (vxi ? vxi->vx_id : 0);
16764 +
16765 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16766 +               __hash_mapping(vxi, new);
16767 +       } else {
16768 +               struct vx_dmap_target new = {
16769 +                       .target = target,
16770 +                       .flags = flags | mode,
16771 +               };
16772 +               __set_default(vxi, mode, &new);
16773 +       }
16774 +       return 0;
16775 +}
16776 +
16777 +
16778 +static int do_unset_mapping(struct vx_info *vxi,
16779 +       dev_t device, dev_t target, int flags, umode_t mode)
16780 +{
16781 +       int ret = -EINVAL;
16782 +
16783 +       if (device) {
16784 +               ret = __remove_mapping(vxi, device, mode);
16785 +               if (ret < 0)
16786 +                       goto out;
16787 +       } else {
16788 +               ret = __remove_default(vxi, mode);
16789 +               if (ret < 0)
16790 +                       goto out;
16791 +       }
16792 +
16793 +out:
16794 +       return ret;
16795 +}
16796 +
16797 +
16798 +static inline int __user_device(const char __user *name, dev_t *dev,
16799 +       umode_t *mode)
16800 +{
16801 +       struct nameidata nd;
16802 +       int ret;
16803 +
16804 +       if (!name) {
16805 +               *dev = 0;
16806 +               return 0;
16807 +       }
16808 +       ret = user_lpath(name, &nd.path);
16809 +       if (ret)
16810 +               return ret;
16811 +       if (nd.path.dentry->d_inode) {
16812 +               *dev = nd.path.dentry->d_inode->i_rdev;
16813 +               *mode = nd.path.dentry->d_inode->i_mode;
16814 +       }
16815 +       path_put(&nd.path);
16816 +       return 0;
16817 +}
16818 +
16819 +static inline int __mapping_mode(dev_t device, dev_t target,
16820 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16821 +{
16822 +       if (device)
16823 +               *mode = device_mode & S_IFMT;
16824 +       else if (target)
16825 +               *mode = target_mode & S_IFMT;
16826 +       else
16827 +               return -EINVAL;
16828 +
16829 +       /* if both given, device and target mode have to match */
16830 +       if (device && target &&
16831 +               ((device_mode ^ target_mode) & S_IFMT))
16832 +               return -EINVAL;
16833 +       return 0;
16834 +}
16835 +
16836 +
16837 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16838 +       const char __user *target_path, int flags, int set)
16839 +{
16840 +       dev_t device = ~0, target = ~0;
16841 +       umode_t device_mode = 0, target_mode = 0, mode;
16842 +       int ret;
16843 +
16844 +       ret = __user_device(device_path, &device, &device_mode);
16845 +       if (ret)
16846 +               return ret;
16847 +       ret = __user_device(target_path, &target, &target_mode);
16848 +       if (ret)
16849 +               return ret;
16850 +
16851 +       ret = __mapping_mode(device, target,
16852 +               device_mode, target_mode, &mode);
16853 +       if (ret)
16854 +               return ret;
16855 +
16856 +       if (set)
16857 +               return do_set_mapping(vxi, device, target,
16858 +                       flags, mode);
16859 +       else
16860 +               return do_unset_mapping(vxi, device, target,
16861 +                       flags, mode);
16862 +}
16863 +
16864 +
16865 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16866 +{
16867 +       struct vcmd_set_mapping_v0 vc_data;
16868 +
16869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16870 +               return -EFAULT;
16871 +
16872 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16873 +               vc_data.flags, 1);
16874 +}
16875 +
16876 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16877 +{
16878 +       struct vcmd_set_mapping_v0 vc_data;
16879 +
16880 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16881 +               return -EFAULT;
16882 +
16883 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16884 +               vc_data.flags, 0);
16885 +}
16886 +
16887 +
16888 +#ifdef CONFIG_COMPAT
16889 +
16890 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16891 +{
16892 +       struct vcmd_set_mapping_v0_x32 vc_data;
16893 +
16894 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16895 +               return -EFAULT;
16896 +
16897 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16898 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16899 +}
16900 +
16901 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16902 +{
16903 +       struct vcmd_set_mapping_v0_x32 vc_data;
16904 +
16905 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16906 +               return -EFAULT;
16907 +
16908 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16909 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16910 +}
16911 +
16912 +#endif /* CONFIG_COMPAT */
16913 +
16914 +
16915 diff -NurpP --minimal linux-3.13.10/kernel/vserver/dlimit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c
16916 --- linux-3.13.10/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16917 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c    2014-01-31 20:38:04.000000000 +0000
16918 @@ -0,0 +1,528 @@
16919 +/*
16920 + *  linux/kernel/vserver/dlimit.c
16921 + *
16922 + *  Virtual Server: Context Disk Limits
16923 + *
16924 + *  Copyright (C) 2004-2009  Herbert Pötzl
16925 + *
16926 + *  V0.01  initial version
16927 + *  V0.02  compat32 splitup
16928 + *  V0.03  extended interface
16929 + *
16930 + */
16931 +
16932 +#include <linux/statfs.h>
16933 +#include <linux/sched.h>
16934 +#include <linux/namei.h>
16935 +#include <linux/vs_tag.h>
16936 +#include <linux/vs_dlimit.h>
16937 +#include <linux/vserver/dlimit_cmd.h>
16938 +#include <linux/slab.h>
16939 +// #include <linux/gfp.h>
16940 +
16941 +#include <asm/uaccess.h>
16942 +
16943 +/*     __alloc_dl_info()
16944 +
16945 +       * allocate an initialized dl_info struct
16946 +       * doesn't make it visible (hash)                        */
16947 +
16948 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16949 +{
16950 +       struct dl_info *new = NULL;
16951 +
16952 +       vxdprintk(VXD_CBIT(dlim, 5),
16953 +               "alloc_dl_info(%p,%d)*", sb, tag);
16954 +
16955 +       /* would this benefit from a slab cache? */
16956 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16957 +       if (!new)
16958 +               return 0;
16959 +
16960 +       memset(new, 0, sizeof(struct dl_info));
16961 +       new->dl_tag = tag;
16962 +       new->dl_sb = sb;
16963 +       // INIT_RCU_HEAD(&new->dl_rcu);
16964 +       INIT_HLIST_NODE(&new->dl_hlist);
16965 +       spin_lock_init(&new->dl_lock);
16966 +       atomic_set(&new->dl_refcnt, 0);
16967 +       atomic_set(&new->dl_usecnt, 0);
16968 +
16969 +       /* rest of init goes here */
16970 +
16971 +       vxdprintk(VXD_CBIT(dlim, 4),
16972 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16973 +       return new;
16974 +}
16975 +
16976 +/*     __dealloc_dl_info()
16977 +
16978 +       * final disposal of dl_info                             */
16979 +
16980 +static void __dealloc_dl_info(struct dl_info *dli)
16981 +{
16982 +       vxdprintk(VXD_CBIT(dlim, 4),
16983 +               "dealloc_dl_info(%p)", dli);
16984 +
16985 +       dli->dl_hlist.next = LIST_POISON1;
16986 +       dli->dl_tag = -1;
16987 +       dli->dl_sb = 0;
16988 +
16989 +       BUG_ON(atomic_read(&dli->dl_usecnt));
16990 +       BUG_ON(atomic_read(&dli->dl_refcnt));
16991 +
16992 +       kfree(dli);
16993 +}
16994 +
16995 +
16996 +/*     hash table for dl_info hash */
16997 +
16998 +#define DL_HASH_SIZE   13
16999 +
17000 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17001 +
17002 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17003 +
17004 +
17005 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17006 +{
17007 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17008 +}
17009 +
17010 +
17011 +
17012 +/*     __hash_dl_info()
17013 +
17014 +       * add the dli to the global hash table
17015 +       * requires the hash_lock to be held                     */
17016 +
17017 +static inline void __hash_dl_info(struct dl_info *dli)
17018 +{
17019 +       struct hlist_head *head;
17020 +
17021 +       vxdprintk(VXD_CBIT(dlim, 6),
17022 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17023 +       get_dl_info(dli);
17024 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17025 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17026 +}
17027 +
17028 +/*     __unhash_dl_info()
17029 +
17030 +       * remove the dli from the global hash table
17031 +       * requires the hash_lock to be held                     */
17032 +
17033 +static inline void __unhash_dl_info(struct dl_info *dli)
17034 +{
17035 +       vxdprintk(VXD_CBIT(dlim, 6),
17036 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17037 +       hlist_del_rcu(&dli->dl_hlist);
17038 +       put_dl_info(dli);
17039 +}
17040 +
17041 +
17042 +/*     __lookup_dl_info()
17043 +
17044 +       * requires the rcu_read_lock()
17045 +       * doesn't increment the dl_refcnt                       */
17046 +
17047 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17048 +{
17049 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17050 +       struct dl_info *dli;
17051 +
17052 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17053 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17054 +                       return dli;
17055 +       }
17056 +       return NULL;
17057 +}
17058 +
17059 +
17060 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17061 +{
17062 +       struct dl_info *dli;
17063 +
17064 +       rcu_read_lock();
17065 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17066 +       vxdprintk(VXD_CBIT(dlim, 7),
17067 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17068 +       rcu_read_unlock();
17069 +       return dli;
17070 +}
17071 +
17072 +void rcu_free_dl_info(struct rcu_head *head)
17073 +{
17074 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17075 +       int usecnt, refcnt;
17076 +
17077 +       BUG_ON(!dli || !head);
17078 +
17079 +       usecnt = atomic_read(&dli->dl_usecnt);
17080 +       BUG_ON(usecnt < 0);
17081 +
17082 +       refcnt = atomic_read(&dli->dl_refcnt);
17083 +       BUG_ON(refcnt < 0);
17084 +
17085 +       vxdprintk(VXD_CBIT(dlim, 3),
17086 +               "rcu_free_dl_info(%p)", dli);
17087 +       if (!usecnt)
17088 +               __dealloc_dl_info(dli);
17089 +       else
17090 +               printk("!!! rcu didn't free\n");
17091 +}
17092 +
17093 +
17094 +
17095 +
17096 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17097 +       uint32_t flags, int add)
17098 +{
17099 +       struct path path;
17100 +       int ret;
17101 +
17102 +       ret = user_lpath(name, &path);
17103 +       if (!ret) {
17104 +               struct super_block *sb;
17105 +               struct dl_info *dli;
17106 +
17107 +               ret = -EINVAL;
17108 +               if (!path.dentry->d_inode)
17109 +                       goto out_release;
17110 +               if (!(sb = path.dentry->d_inode->i_sb))
17111 +                       goto out_release;
17112 +
17113 +               if (add) {
17114 +                       dli = __alloc_dl_info(sb, id);
17115 +                       spin_lock(&dl_info_hash_lock);
17116 +
17117 +                       ret = -EEXIST;
17118 +                       if (__lookup_dl_info(sb, id))
17119 +                               goto out_unlock;
17120 +                       __hash_dl_info(dli);
17121 +                       dli = NULL;
17122 +               } else {
17123 +                       spin_lock(&dl_info_hash_lock);
17124 +                       dli = __lookup_dl_info(sb, id);
17125 +
17126 +                       ret = -ESRCH;
17127 +                       if (!dli)
17128 +                               goto out_unlock;
17129 +                       __unhash_dl_info(dli);
17130 +               }
17131 +               ret = 0;
17132 +       out_unlock:
17133 +               spin_unlock(&dl_info_hash_lock);
17134 +               if (add && dli)
17135 +                       __dealloc_dl_info(dli);
17136 +       out_release:
17137 +               path_put(&path);
17138 +       }
17139 +       return ret;
17140 +}
17141 +
17142 +int vc_add_dlimit(uint32_t id, void __user *data)
17143 +{
17144 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17145 +
17146 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17147 +               return -EFAULT;
17148 +
17149 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17150 +}
17151 +
17152 +int vc_rem_dlimit(uint32_t id, void __user *data)
17153 +{
17154 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17155 +
17156 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17157 +               return -EFAULT;
17158 +
17159 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17160 +}
17161 +
17162 +#ifdef CONFIG_COMPAT
17163 +
17164 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17165 +{
17166 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17167 +
17168 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17169 +               return -EFAULT;
17170 +
17171 +       return do_addrem_dlimit(id,
17172 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17173 +}
17174 +
17175 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17176 +{
17177 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17178 +
17179 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17180 +               return -EFAULT;
17181 +
17182 +       return do_addrem_dlimit(id,
17183 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17184 +}
17185 +
17186 +#endif /* CONFIG_COMPAT */
17187 +
17188 +
17189 +static inline
17190 +int do_set_dlimit(uint32_t id, const char __user *name,
17191 +       uint32_t space_used, uint32_t space_total,
17192 +       uint32_t inodes_used, uint32_t inodes_total,
17193 +       uint32_t reserved, uint32_t flags)
17194 +{
17195 +       struct path path;
17196 +       int ret;
17197 +
17198 +       ret = user_lpath(name, &path);
17199 +       if (!ret) {
17200 +               struct super_block *sb;
17201 +               struct dl_info *dli;
17202 +
17203 +               ret = -EINVAL;
17204 +               if (!path.dentry->d_inode)
17205 +                       goto out_release;
17206 +               if (!(sb = path.dentry->d_inode->i_sb))
17207 +                       goto out_release;
17208 +
17209 +               /* sanity checks */
17210 +               if ((reserved != CDLIM_KEEP &&
17211 +                       reserved > 100) ||
17212 +                       (inodes_used != CDLIM_KEEP &&
17213 +                       inodes_used > inodes_total) ||
17214 +                       (space_used != CDLIM_KEEP &&
17215 +                       space_used > space_total))
17216 +                       goto out_release;
17217 +
17218 +               ret = -ESRCH;
17219 +               dli = locate_dl_info(sb, id);
17220 +               if (!dli)
17221 +                       goto out_release;
17222 +
17223 +               spin_lock(&dli->dl_lock);
17224 +
17225 +               if (inodes_used != CDLIM_KEEP)
17226 +                       dli->dl_inodes_used = inodes_used;
17227 +               if (inodes_total != CDLIM_KEEP)
17228 +                       dli->dl_inodes_total = inodes_total;
17229 +               if (space_used != CDLIM_KEEP)
17230 +                       dli->dl_space_used = dlimit_space_32to64(
17231 +                               space_used, flags, DLIMS_USED);
17232 +
17233 +               if (space_total == CDLIM_INFINITY)
17234 +                       dli->dl_space_total = DLIM_INFINITY;
17235 +               else if (space_total != CDLIM_KEEP)
17236 +                       dli->dl_space_total = dlimit_space_32to64(
17237 +                               space_total, flags, DLIMS_TOTAL);
17238 +
17239 +               if (reserved != CDLIM_KEEP)
17240 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17241 +
17242 +               spin_unlock(&dli->dl_lock);
17243 +
17244 +               put_dl_info(dli);
17245 +               ret = 0;
17246 +
17247 +       out_release:
17248 +               path_put(&path);
17249 +       }
17250 +       return ret;
17251 +}
17252 +
17253 +int vc_set_dlimit(uint32_t id, void __user *data)
17254 +{
17255 +       struct vcmd_ctx_dlimit_v0 vc_data;
17256 +
17257 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17258 +               return -EFAULT;
17259 +
17260 +       return do_set_dlimit(id, vc_data.name,
17261 +               vc_data.space_used, vc_data.space_total,
17262 +               vc_data.inodes_used, vc_data.inodes_total,
17263 +               vc_data.reserved, vc_data.flags);
17264 +}
17265 +
17266 +#ifdef CONFIG_COMPAT
17267 +
17268 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17269 +{
17270 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17271 +
17272 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17273 +               return -EFAULT;
17274 +
17275 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17276 +               vc_data.space_used, vc_data.space_total,
17277 +               vc_data.inodes_used, vc_data.inodes_total,
17278 +               vc_data.reserved, vc_data.flags);
17279 +}
17280 +
17281 +#endif /* CONFIG_COMPAT */
17282 +
17283 +
17284 +static inline
17285 +int do_get_dlimit(uint32_t id, const char __user *name,
17286 +       uint32_t *space_used, uint32_t *space_total,
17287 +       uint32_t *inodes_used, uint32_t *inodes_total,
17288 +       uint32_t *reserved, uint32_t *flags)
17289 +{
17290 +       struct path path;
17291 +       int ret;
17292 +
17293 +       ret = user_lpath(name, &path);
17294 +       if (!ret) {
17295 +               struct super_block *sb;
17296 +               struct dl_info *dli;
17297 +
17298 +               ret = -EINVAL;
17299 +               if (!path.dentry->d_inode)
17300 +                       goto out_release;
17301 +               if (!(sb = path.dentry->d_inode->i_sb))
17302 +                       goto out_release;
17303 +
17304 +               ret = -ESRCH;
17305 +               dli = locate_dl_info(sb, id);
17306 +               if (!dli)
17307 +                       goto out_release;
17308 +
17309 +               spin_lock(&dli->dl_lock);
17310 +               *inodes_used = dli->dl_inodes_used;
17311 +               *inodes_total = dli->dl_inodes_total;
17312 +
17313 +               *space_used = dlimit_space_64to32(
17314 +                       dli->dl_space_used, flags, DLIMS_USED);
17315 +
17316 +               if (dli->dl_space_total == DLIM_INFINITY)
17317 +                       *space_total = CDLIM_INFINITY;
17318 +               else
17319 +                       *space_total = dlimit_space_64to32(
17320 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17321 +
17322 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17323 +               spin_unlock(&dli->dl_lock);
17324 +
17325 +               put_dl_info(dli);
17326 +               ret = -EFAULT;
17327 +
17328 +               ret = 0;
17329 +       out_release:
17330 +               path_put(&path);
17331 +       }
17332 +       return ret;
17333 +}
17334 +
17335 +
17336 +int vc_get_dlimit(uint32_t id, void __user *data)
17337 +{
17338 +       struct vcmd_ctx_dlimit_v0 vc_data;
17339 +       int ret;
17340 +
17341 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17342 +               return -EFAULT;
17343 +
17344 +       ret = do_get_dlimit(id, vc_data.name,
17345 +               &vc_data.space_used, &vc_data.space_total,
17346 +               &vc_data.inodes_used, &vc_data.inodes_total,
17347 +               &vc_data.reserved, &vc_data.flags);
17348 +       if (ret)
17349 +               return ret;
17350 +
17351 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17352 +               return -EFAULT;
17353 +       return 0;
17354 +}
17355 +
17356 +#ifdef CONFIG_COMPAT
17357 +
17358 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17359 +{
17360 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17361 +       int ret;
17362 +
17363 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17364 +               return -EFAULT;
17365 +
17366 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17367 +               &vc_data.space_used, &vc_data.space_total,
17368 +               &vc_data.inodes_used, &vc_data.inodes_total,
17369 +               &vc_data.reserved, &vc_data.flags);
17370 +       if (ret)
17371 +               return ret;
17372 +
17373 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17374 +               return -EFAULT;
17375 +       return 0;
17376 +}
17377 +
17378 +#endif /* CONFIG_COMPAT */
17379 +
17380 +
17381 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17382 +{
17383 +       struct dl_info *dli;
17384 +       __u64 blimit, bfree, bavail;
17385 +       __u32 ifree;
17386 +
17387 +       dli = locate_dl_info(sb, dx_current_tag());
17388 +       if (!dli)
17389 +               return;
17390 +
17391 +       spin_lock(&dli->dl_lock);
17392 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17393 +               goto no_ilim;
17394 +
17395 +       /* reduce max inodes available to limit */
17396 +       if (buf->f_files > dli->dl_inodes_total)
17397 +               buf->f_files = dli->dl_inodes_total;
17398 +
17399 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17400 +       /* reduce free inodes to min */
17401 +       if (ifree < buf->f_ffree)
17402 +               buf->f_ffree = ifree;
17403 +
17404 +no_ilim:
17405 +       if (dli->dl_space_total == DLIM_INFINITY)
17406 +               goto no_blim;
17407 +
17408 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17409 +
17410 +       if (dli->dl_space_total < dli->dl_space_used)
17411 +               bfree = 0;
17412 +       else
17413 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17414 +                       >> sb->s_blocksize_bits;
17415 +
17416 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17417 +       if (bavail < dli->dl_space_used)
17418 +               bavail = 0;
17419 +       else
17420 +               bavail = (bavail - dli->dl_space_used)
17421 +                       >> sb->s_blocksize_bits;
17422 +
17423 +       /* reduce max space available to limit */
17424 +       if (buf->f_blocks > blimit)
17425 +               buf->f_blocks = blimit;
17426 +
17427 +       /* reduce free space to min */
17428 +       if (bfree < buf->f_bfree)
17429 +               buf->f_bfree = bfree;
17430 +
17431 +       /* reduce avail space to min */
17432 +       if (bavail < buf->f_bavail)
17433 +               buf->f_bavail = bavail;
17434 +
17435 +no_blim:
17436 +       spin_unlock(&dli->dl_lock);
17437 +       put_dl_info(dli);
17438 +
17439 +       return;
17440 +}
17441 +
17442 +#include <linux/module.h>
17443 +
17444 +EXPORT_SYMBOL_GPL(locate_dl_info);
17445 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17446 +
17447 diff -NurpP --minimal linux-3.13.10/kernel/vserver/helper.c linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c
17448 --- linux-3.13.10/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17449 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c    2014-01-31 20:38:04.000000000 +0000
17450 @@ -0,0 +1,242 @@
17451 +/*
17452 + *  linux/kernel/vserver/helper.c
17453 + *
17454 + *  Virtual Context Support
17455 + *
17456 + *  Copyright (C) 2004-2007  Herbert Pötzl
17457 + *
17458 + *  V0.01  basic helper
17459 + *
17460 + */
17461 +
17462 +#include <linux/kmod.h>
17463 +#include <linux/reboot.h>
17464 +#include <linux/vs_context.h>
17465 +#include <linux/vs_network.h>
17466 +#include <linux/vserver/signal.h>
17467 +
17468 +
17469 +char vshelper_path[255] = "/sbin/vshelper";
17470 +
17471 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17472 +{
17473 +       current->flags &= ~PF_NO_SETAFFINITY;
17474 +       return 0;
17475 +}
17476 +
17477 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17478 +{
17479 +       struct subprocess_info *info;
17480 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17481 +
17482 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17483 +                                        vshelper_init, NULL, NULL);
17484 +       if (info == NULL)
17485 +               return -ENOMEM;
17486 +
17487 +       return call_usermodehelper_exec(info, wait);
17488 +}
17489 +
17490 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17491 +{
17492 +       int ret;
17493 +
17494 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17495 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17496 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17497 +                       name, argv[1], argv[2],
17498 +                       sync ? "sync" : "async", ret);
17499 +       }
17500 +       vxdprintk(VXD_CBIT(switch, 4),
17501 +               "%s: (%s %s) returned %s with %d",
17502 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17503 +       return ret;
17504 +}
17505 +
17506 +/*
17507 + *      vshelper path is set via /proc/sys
17508 + *      invoked by vserver sys_reboot(), with
17509 + *      the following arguments
17510 + *
17511 + *      argv [0] = vshelper_path;
17512 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17513 + *      argv [2] = context identifier
17514 + *
17515 + *      envp [*] = type-specific parameters
17516 + */
17517 +
17518 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17519 +{
17520 +       char id_buf[8], cmd_buf[16];
17521 +       char uid_buf[16], pid_buf[16];
17522 +       int ret;
17523 +
17524 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17525 +       char *envp[] = {"HOME=/", "TERM=linux",
17526 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17527 +                       uid_buf, pid_buf, cmd_buf, 0};
17528 +
17529 +       if (vx_info_state(vxi, VXS_HELPER))
17530 +               return -EAGAIN;
17531 +       vxi->vx_state |= VXS_HELPER;
17532 +
17533 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17534 +
17535 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17536 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17537 +               from_kuid(&init_user_ns, current_uid()));
17538 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17539 +
17540 +       switch (cmd) {
17541 +       case LINUX_REBOOT_CMD_RESTART:
17542 +               argv[1] = "restart";
17543 +               break;
17544 +
17545 +       case LINUX_REBOOT_CMD_HALT:
17546 +               argv[1] = "halt";
17547 +               break;
17548 +
17549 +       case LINUX_REBOOT_CMD_POWER_OFF:
17550 +               argv[1] = "poweroff";
17551 +               break;
17552 +
17553 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17554 +               argv[1] = "swsusp";
17555 +               break;
17556 +
17557 +       case LINUX_REBOOT_CMD_OOM:
17558 +               argv[1] = "oom";
17559 +               break;
17560 +
17561 +       default:
17562 +               vxi->vx_state &= ~VXS_HELPER;
17563 +               return 0;
17564 +       }
17565 +
17566 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17567 +       vxi->vx_state &= ~VXS_HELPER;
17568 +       __wakeup_vx_info(vxi);
17569 +       return (ret) ? -EPERM : 0;
17570 +}
17571 +
17572 +
17573 +long vs_reboot(unsigned int cmd, void __user *arg)
17574 +{
17575 +       struct vx_info *vxi = current_vx_info();
17576 +       long ret = 0;
17577 +
17578 +       vxdprintk(VXD_CBIT(misc, 5),
17579 +               "vs_reboot(%p[#%d],%u)",
17580 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17581 +
17582 +       ret = vs_reboot_helper(vxi, cmd, arg);
17583 +       if (ret)
17584 +               return ret;
17585 +
17586 +       vxi->reboot_cmd = cmd;
17587 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17588 +               switch (cmd) {
17589 +               case LINUX_REBOOT_CMD_RESTART:
17590 +               case LINUX_REBOOT_CMD_HALT:
17591 +               case LINUX_REBOOT_CMD_POWER_OFF:
17592 +                       vx_info_kill(vxi, 0, SIGKILL);
17593 +                       vx_info_kill(vxi, 1, SIGKILL);
17594 +               default:
17595 +                       break;
17596 +               }
17597 +       }
17598 +       return 0;
17599 +}
17600 +
17601 +long vs_oom_action(unsigned int cmd)
17602 +{
17603 +       struct vx_info *vxi = current_vx_info();
17604 +       long ret = 0;
17605 +
17606 +       vxdprintk(VXD_CBIT(misc, 5),
17607 +               "vs_oom_action(%p[#%d],%u)",
17608 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17609 +
17610 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17611 +       if (ret)
17612 +               return ret;
17613 +
17614 +       vxi->reboot_cmd = cmd;
17615 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17616 +               vx_info_kill(vxi, 0, SIGKILL);
17617 +               vx_info_kill(vxi, 1, SIGKILL);
17618 +       }
17619 +       return 0;
17620 +}
17621 +
17622 +/*
17623 + *      argv [0] = vshelper_path;
17624 + *      argv [1] = action: "startup", "shutdown"
17625 + *      argv [2] = context identifier
17626 + *
17627 + *      envp [*] = type-specific parameters
17628 + */
17629 +
17630 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17631 +{
17632 +       char id_buf[8], cmd_buf[16];
17633 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17634 +       char *envp[] = {"HOME=/", "TERM=linux",
17635 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17636 +
17637 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17638 +               return 0;
17639 +
17640 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17641 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17642 +
17643 +       switch (cmd) {
17644 +       case VSC_STARTUP:
17645 +               argv[1] = "startup";
17646 +               break;
17647 +       case VSC_SHUTDOWN:
17648 +               argv[1] = "shutdown";
17649 +               break;
17650 +       default:
17651 +               return 0;
17652 +       }
17653 +
17654 +       return do_vshelper(vshelper_path, argv, envp, 1);
17655 +}
17656 +
17657 +
17658 +/*
17659 + *      argv [0] = vshelper_path;
17660 + *      argv [1] = action: "netup", "netdown"
17661 + *      argv [2] = context identifier
17662 + *
17663 + *      envp [*] = type-specific parameters
17664 + */
17665 +
17666 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17667 +{
17668 +       char id_buf[8], cmd_buf[16];
17669 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17670 +       char *envp[] = {"HOME=/", "TERM=linux",
17671 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17672 +
17673 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17674 +               return 0;
17675 +
17676 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17677 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17678 +
17679 +       switch (cmd) {
17680 +       case VSC_NETUP:
17681 +               argv[1] = "netup";
17682 +               break;
17683 +       case VSC_NETDOWN:
17684 +               argv[1] = "netdown";
17685 +               break;
17686 +       default:
17687 +               return 0;
17688 +       }
17689 +
17690 +       return do_vshelper(vshelper_path, argv, envp, 1);
17691 +}
17692 +
17693 diff -NurpP --minimal linux-3.13.10/kernel/vserver/history.c linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c
17694 --- linux-3.13.10/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17695 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c   2014-01-31 20:38:04.000000000 +0000
17696 @@ -0,0 +1,258 @@
17697 +/*
17698 + *  kernel/vserver/history.c
17699 + *
17700 + *  Virtual Context History Backtrace
17701 + *
17702 + *  Copyright (C) 2004-2007  Herbert Pötzl
17703 + *
17704 + *  V0.01  basic structure
17705 + *  V0.02  hash/unhash and trace
17706 + *  V0.03  preemption fixes
17707 + *
17708 + */
17709 +
17710 +#include <linux/module.h>
17711 +#include <asm/uaccess.h>
17712 +
17713 +#include <linux/vserver/context.h>
17714 +#include <linux/vserver/debug.h>
17715 +#include <linux/vserver/debug_cmd.h>
17716 +#include <linux/vserver/history.h>
17717 +
17718 +
17719 +#ifdef CONFIG_VSERVER_HISTORY
17720 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17721 +#else
17722 +#define VXH_SIZE       64
17723 +#endif
17724 +
17725 +struct _vx_history {
17726 +       unsigned int counter;
17727 +
17728 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17729 +};
17730 +
17731 +
17732 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17733 +
17734 +unsigned volatile int vxh_active = 1;
17735 +
17736 +static atomic_t sequence = ATOMIC_INIT(0);
17737 +
17738 +
17739 +/*     vxh_advance()
17740 +
17741 +       * requires disabled preemption                          */
17742 +
17743 +struct _vx_hist_entry *vxh_advance(void *loc)
17744 +{
17745 +       unsigned int cpu = smp_processor_id();
17746 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17747 +       struct _vx_hist_entry *entry;
17748 +       unsigned int index;
17749 +
17750 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17751 +       entry = &hist->entry[index];
17752 +
17753 +       entry->seq = atomic_inc_return(&sequence);
17754 +       entry->loc = loc;
17755 +       return entry;
17756 +}
17757 +
17758 +EXPORT_SYMBOL_GPL(vxh_advance);
17759 +
17760 +
17761 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17762 +
17763 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17764 +
17765 +
17766 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17767 +
17768 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17769 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17770 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17771 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17772 +
17773 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17774 +{
17775 +       switch (e->type) {
17776 +       case VXH_THROW_OOPS:
17777 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17778 +               break;
17779 +
17780 +       case VXH_GET_VX_INFO:
17781 +       case VXH_PUT_VX_INFO:
17782 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17783 +                       VXH_LOC_ARGS(e),
17784 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17785 +                       VXH_VXI_ARGS(e));
17786 +               break;
17787 +
17788 +       case VXH_INIT_VX_INFO:
17789 +       case VXH_SET_VX_INFO:
17790 +       case VXH_CLR_VX_INFO:
17791 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17792 +                       VXH_LOC_ARGS(e),
17793 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17794 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17795 +                       VXH_VXI_ARGS(e), e->sc.data);
17796 +               break;
17797 +
17798 +       case VXH_CLAIM_VX_INFO:
17799 +       case VXH_RELEASE_VX_INFO:
17800 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17801 +                       VXH_LOC_ARGS(e),
17802 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17803 +                       VXH_VXI_ARGS(e), e->sc.data);
17804 +               break;
17805 +
17806 +       case VXH_ALLOC_VX_INFO:
17807 +       case VXH_DEALLOC_VX_INFO:
17808 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17809 +                       VXH_LOC_ARGS(e),
17810 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17811 +                       VXH_VXI_ARGS(e));
17812 +               break;
17813 +
17814 +       case VXH_HASH_VX_INFO:
17815 +       case VXH_UNHASH_VX_INFO:
17816 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17817 +                       VXH_LOC_ARGS(e),
17818 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17819 +                       VXH_VXI_ARGS(e));
17820 +               break;
17821 +
17822 +       case VXH_LOC_VX_INFO:
17823 +       case VXH_LOOKUP_VX_INFO:
17824 +       case VXH_CREATE_VX_INFO:
17825 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17826 +                       VXH_LOC_ARGS(e),
17827 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17828 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17829 +                       e->ll.arg, VXH_VXI_ARGS(e));
17830 +               break;
17831 +       }
17832 +}
17833 +
17834 +static void __vxh_dump_history(void)
17835 +{
17836 +       unsigned int i, cpu;
17837 +
17838 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17839 +               atomic_read(&sequence), NR_CPUS);
17840 +
17841 +       for (i = 0; i < VXH_SIZE; i++) {
17842 +               for_each_online_cpu(cpu) {
17843 +                       struct _vx_history *hist =
17844 +                               &per_cpu(vx_history_buffer, cpu);
17845 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17846 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17847 +
17848 +                       vxh_dump_entry(entry, cpu);
17849 +               }
17850 +       }
17851 +}
17852 +
17853 +void   vxh_dump_history(void)
17854 +{
17855 +       vxh_active = 0;
17856 +#ifdef CONFIG_SMP
17857 +       local_irq_enable();
17858 +       smp_send_stop();
17859 +       local_irq_disable();
17860 +#endif
17861 +       __vxh_dump_history();
17862 +}
17863 +
17864 +
17865 +/* vserver syscall commands below here */
17866 +
17867 +
17868 +int vc_dump_history(uint32_t id)
17869 +{
17870 +       vxh_active = 0;
17871 +       __vxh_dump_history();
17872 +       vxh_active = 1;
17873 +
17874 +       return 0;
17875 +}
17876 +
17877 +
17878 +int do_read_history(struct __user _vx_hist_entry *data,
17879 +       int cpu, uint32_t *index, uint32_t *count)
17880 +{
17881 +       int pos, ret = 0;
17882 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17883 +       int end = hist->counter;
17884 +       int start = end - VXH_SIZE + 2;
17885 +       int idx = *index;
17886 +
17887 +       /* special case: get current pos */
17888 +       if (!*count) {
17889 +               *index = end;
17890 +               return 0;
17891 +       }
17892 +
17893 +       /* have we lost some data? */
17894 +       if (idx < start)
17895 +               idx = start;
17896 +
17897 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17898 +               struct _vx_hist_entry *entry =
17899 +                       &hist->entry[idx % VXH_SIZE];
17900 +
17901 +               /* send entry to userspace */
17902 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17903 +               if (ret)
17904 +                       break;
17905 +       }
17906 +       /* save new index and count */
17907 +       *index = idx;
17908 +       *count = pos;
17909 +       return ret ? ret : (*index < end);
17910 +}
17911 +
17912 +int vc_read_history(uint32_t id, void __user *data)
17913 +{
17914 +       struct vcmd_read_history_v0 vc_data;
17915 +       int ret;
17916 +
17917 +       if (id >= NR_CPUS)
17918 +               return -EINVAL;
17919 +
17920 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17921 +               return -EFAULT;
17922 +
17923 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17924 +               id, &vc_data.index, &vc_data.count);
17925 +
17926 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17927 +               return -EFAULT;
17928 +       return ret;
17929 +}
17930 +
17931 +#ifdef CONFIG_COMPAT
17932 +
17933 +int vc_read_history_x32(uint32_t id, void __user *data)
17934 +{
17935 +       struct vcmd_read_history_v0_x32 vc_data;
17936 +       int ret;
17937 +
17938 +       if (id >= NR_CPUS)
17939 +               return -EINVAL;
17940 +
17941 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17942 +               return -EFAULT;
17943 +
17944 +       ret = do_read_history((struct __user _vx_hist_entry *)
17945 +               compat_ptr(vc_data.data_ptr),
17946 +               id, &vc_data.index, &vc_data.count);
17947 +
17948 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17949 +               return -EFAULT;
17950 +       return ret;
17951 +}
17952 +
17953 +#endif /* CONFIG_COMPAT */
17954 +
17955 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inet.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c
17956 --- linux-3.13.10/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17957 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c      2014-02-01 00:26:40.000000000 +0000
17958 @@ -0,0 +1,236 @@
17959 +
17960 +#include <linux/in.h>
17961 +#include <linux/inetdevice.h>
17962 +#include <linux/export.h>
17963 +#include <linux/vs_inet.h>
17964 +#include <linux/vs_inet6.h>
17965 +#include <linux/vserver/debug.h>
17966 +#include <net/route.h>
17967 +#include <net/addrconf.h>
17968 +
17969 +
17970 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17971 +{
17972 +       int ret = 0;
17973 +
17974 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17975 +               ret = 1;
17976 +       else {
17977 +               struct nx_addr_v4 *ptr;
17978 +               unsigned long irqflags;
17979 +
17980 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17981 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17982 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17983 +                               ret = 1;
17984 +                               break;
17985 +                       }
17986 +               }
17987 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17988 +       }
17989 +
17990 +       vxdprintk(VXD_CBIT(net, 2),
17991 +               "nx_v4_addr_conflict(%p,%p): %d",
17992 +               nxi1, nxi2, ret);
17993 +
17994 +       return ret;
17995 +}
17996 +
17997 +
17998 +#ifdef CONFIG_IPV6
17999 +
18000 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18001 +{
18002 +       int ret = 0;
18003 +
18004 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18005 +               ret = 1;
18006 +       else {
18007 +               struct nx_addr_v6 *ptr;
18008 +               unsigned long irqflags;
18009 +
18010 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18011 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18012 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18013 +                               ret = 1;
18014 +                               break;
18015 +                       }
18016 +               }
18017 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18018 +       }
18019 +
18020 +       vxdprintk(VXD_CBIT(net, 2),
18021 +               "nx_v6_addr_conflict(%p,%p): %d",
18022 +               nxi1, nxi2, ret);
18023 +
18024 +       return ret;
18025 +}
18026 +
18027 +#endif
18028 +
18029 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18030 +{
18031 +       struct in_device *in_dev;
18032 +       struct in_ifaddr **ifap;
18033 +       struct in_ifaddr *ifa;
18034 +       int ret = 0;
18035 +
18036 +       if (!dev)
18037 +               goto out;
18038 +       in_dev = in_dev_get(dev);
18039 +       if (!in_dev)
18040 +               goto out;
18041 +
18042 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18043 +               ifap = &ifa->ifa_next) {
18044 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18045 +                       ret = 1;
18046 +                       break;
18047 +               }
18048 +       }
18049 +       in_dev_put(in_dev);
18050 +out:
18051 +       return ret;
18052 +}
18053 +
18054 +
18055 +#ifdef CONFIG_IPV6
18056 +
18057 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18058 +{
18059 +       struct inet6_dev *in_dev;
18060 +       struct inet6_ifaddr *ifa;
18061 +       int ret = 0;
18062 +
18063 +       if (!dev)
18064 +               goto out;
18065 +       in_dev = in6_dev_get(dev);
18066 +       if (!in_dev)
18067 +               goto out;
18068 +
18069 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18070 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18071 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18072 +                       ret = 1;
18073 +                       break;
18074 +               }
18075 +       }
18076 +       in6_dev_put(in_dev);
18077 +out:
18078 +       return ret;
18079 +}
18080 +
18081 +#endif
18082 +
18083 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18084 +{
18085 +       int ret = 1;
18086 +
18087 +       if (!nxi)
18088 +               goto out;
18089 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18090 +               goto out;
18091 +#ifdef CONFIG_IPV6
18092 +       ret = 2;
18093 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18094 +               goto out;
18095 +#endif
18096 +       ret = 0;
18097 +out:
18098 +       vxdprintk(VXD_CBIT(net, 3),
18099 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18100 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18101 +       return ret;
18102 +}
18103 +
18104 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18105 +       struct flowi4 *fl4)
18106 +{
18107 +       struct rtable *rt;
18108 +
18109 +       if (!nxi)
18110 +               return NULL;
18111 +
18112 +       /* FIXME: handle lback only case */
18113 +       if (!NX_IPV4(nxi))
18114 +               return ERR_PTR(-EPERM);
18115 +
18116 +       vxdprintk(VXD_CBIT(net, 4),
18117 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18118 +               nxi, nxi ? nxi->nx_id : 0,
18119 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18120 +
18121 +       /* single IP is unconditional */
18122 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18123 +               (fl4->saddr == INADDR_ANY))
18124 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18125 +
18126 +       if (fl4->saddr == INADDR_ANY) {
18127 +               struct nx_addr_v4 *ptr;
18128 +               __be32 found = 0;
18129 +
18130 +               rt = __ip_route_output_key(net, fl4);
18131 +               if (!IS_ERR(rt)) {
18132 +                       found = fl4->saddr;
18133 +                       ip_rt_put(rt);
18134 +                       vxdprintk(VXD_CBIT(net, 4),
18135 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18136 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18137 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18138 +                               goto found;
18139 +               }
18140 +
18141 +               WARN_ON_ONCE(in_irq());
18142 +               spin_lock_bh(&nxi->addr_lock);
18143 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18144 +                       __be32 primary = ptr->ip[0].s_addr;
18145 +                       __be32 mask = ptr->mask.s_addr;
18146 +                       __be32 neta = primary & mask;
18147 +
18148 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18149 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18150 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18151 +                               NIPQUAD(mask), NIPQUAD(neta));
18152 +                       if ((found & mask) != neta)
18153 +                               continue;
18154 +
18155 +                       fl4->saddr = primary;
18156 +                       rt = __ip_route_output_key(net, fl4);
18157 +                       vxdprintk(VXD_CBIT(net, 4),
18158 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18159 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18160 +                       if (!IS_ERR(rt)) {
18161 +                               found = fl4->saddr;
18162 +                               ip_rt_put(rt);
18163 +                               if (found == primary)
18164 +                                       goto found_unlock;
18165 +                       }
18166 +               }
18167 +               /* still no source ip? */
18168 +               found = ipv4_is_loopback(fl4->daddr)
18169 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18170 +       found_unlock:
18171 +               spin_unlock_bh(&nxi->addr_lock);
18172 +       found:
18173 +               /* assign src ip to flow */
18174 +               fl4->saddr = found;
18175 +
18176 +       } else {
18177 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18178 +                       return ERR_PTR(-EPERM);
18179 +       }
18180 +
18181 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18182 +               if (ipv4_is_loopback(fl4->daddr))
18183 +                       fl4->daddr = nxi->v4_lback.s_addr;
18184 +               if (ipv4_is_loopback(fl4->saddr))
18185 +                       fl4->saddr = nxi->v4_lback.s_addr;
18186 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18187 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18188 +               return ERR_PTR(-EPERM);
18189 +
18190 +       return NULL;
18191 +}
18192 +
18193 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18194 +
18195 diff -NurpP --minimal linux-3.13.10/kernel/vserver/init.c linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c
18196 --- linux-3.13.10/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18197 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c      2014-01-31 20:38:04.000000000 +0000
18198 @@ -0,0 +1,45 @@
18199 +/*
18200 + *  linux/kernel/init.c
18201 + *
18202 + *  Virtual Server Init
18203 + *
18204 + *  Copyright (C) 2004-2007  Herbert Pötzl
18205 + *
18206 + *  V0.01  basic structure
18207 + *
18208 + */
18209 +
18210 +#include <linux/init.h>
18211 +
18212 +int    vserver_register_sysctl(void);
18213 +void   vserver_unregister_sysctl(void);
18214 +
18215 +
18216 +static int __init init_vserver(void)
18217 +{
18218 +       int ret = 0;
18219 +
18220 +#ifdef CONFIG_VSERVER_DEBUG
18221 +       vserver_register_sysctl();
18222 +#endif
18223 +       return ret;
18224 +}
18225 +
18226 +
18227 +static void __exit exit_vserver(void)
18228 +{
18229 +
18230 +#ifdef CONFIG_VSERVER_DEBUG
18231 +       vserver_unregister_sysctl();
18232 +#endif
18233 +       return;
18234 +}
18235 +
18236 +/* FIXME: GFP_ZONETYPES gone
18237 +long vx_slab[GFP_ZONETYPES]; */
18238 +long vx_area;
18239 +
18240 +
18241 +module_init(init_vserver);
18242 +module_exit(exit_vserver);
18243 +
18244 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inode.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c
18245 --- linux-3.13.10/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18246 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c     2014-01-31 20:38:04.000000000 +0000
18247 @@ -0,0 +1,440 @@
18248 +/*
18249 + *  linux/kernel/vserver/inode.c
18250 + *
18251 + *  Virtual Server: File System Support
18252 + *
18253 + *  Copyright (C) 2004-2007  Herbert Pötzl
18254 + *
18255 + *  V0.01  separated from vcontext V0.05
18256 + *  V0.02  moved to tag (instead of xid)
18257 + *
18258 + */
18259 +
18260 +#include <linux/tty.h>
18261 +#include <linux/proc_fs.h>
18262 +#include <linux/devpts_fs.h>
18263 +#include <linux/fs.h>
18264 +#include <linux/file.h>
18265 +#include <linux/mount.h>
18266 +#include <linux/parser.h>
18267 +#include <linux/namei.h>
18268 +#include <linux/magic.h>
18269 +#include <linux/slab.h>
18270 +#include <linux/vserver/inode.h>
18271 +#include <linux/vserver/inode_cmd.h>
18272 +#include <linux/vs_base.h>
18273 +#include <linux/vs_tag.h>
18274 +
18275 +#include <asm/uaccess.h>
18276 +#include <../../fs/proc/internal.h>
18277 +
18278 +
18279 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18280 +{
18281 +       struct proc_dir_entry *entry;
18282 +
18283 +       if (!in || !in->i_sb)
18284 +               return -ESRCH;
18285 +
18286 +       *flags = IATTR_TAG
18287 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18288 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18289 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18290 +               | (IS_COW(in) ? IATTR_COW : 0);
18291 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18292 +
18293 +       if (S_ISDIR(in->i_mode))
18294 +               *mask |= IATTR_BARRIER;
18295 +
18296 +       if (IS_TAGGED(in)) {
18297 +               *tag = i_tag_read(in);
18298 +               *mask |= IATTR_TAG;
18299 +       }
18300 +
18301 +       switch (in->i_sb->s_magic) {
18302 +       case PROC_SUPER_MAGIC:
18303 +               entry = PROC_I(in)->pde;
18304 +
18305 +               /* check for specific inodes? */
18306 +               if (entry)
18307 +                       *mask |= IATTR_FLAGS;
18308 +               if (entry)
18309 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18310 +               else
18311 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18312 +               break;
18313 +
18314 +       case DEVPTS_SUPER_MAGIC:
18315 +               *tag = i_tag_read(in);
18316 +               *mask |= IATTR_TAG;
18317 +               break;
18318 +
18319 +       default:
18320 +               break;
18321 +       }
18322 +       return 0;
18323 +}
18324 +
18325 +int vc_get_iattr(void __user *data)
18326 +{
18327 +       struct path path;
18328 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18329 +       int ret;
18330 +
18331 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18332 +               return -EFAULT;
18333 +
18334 +       ret = user_lpath(vc_data.name, &path);
18335 +       if (!ret) {
18336 +               ret = __vc_get_iattr(path.dentry->d_inode,
18337 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18338 +               path_put(&path);
18339 +       }
18340 +       if (ret)
18341 +               return ret;
18342 +
18343 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18344 +               ret = -EFAULT;
18345 +       return ret;
18346 +}
18347 +
18348 +#ifdef CONFIG_COMPAT
18349 +
18350 +int vc_get_iattr_x32(void __user *data)
18351 +{
18352 +       struct path path;
18353 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18354 +       int ret;
18355 +
18356 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18357 +               return -EFAULT;
18358 +
18359 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18360 +       if (!ret) {
18361 +               ret = __vc_get_iattr(path.dentry->d_inode,
18362 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18363 +               path_put(&path);
18364 +       }
18365 +       if (ret)
18366 +               return ret;
18367 +
18368 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18369 +               ret = -EFAULT;
18370 +       return ret;
18371 +}
18372 +
18373 +#endif /* CONFIG_COMPAT */
18374 +
18375 +
18376 +int vc_fget_iattr(uint32_t fd, void __user *data)
18377 +{
18378 +       struct file *filp;
18379 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18380 +       int ret;
18381 +
18382 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18383 +               return -EFAULT;
18384 +
18385 +       filp = fget(fd);
18386 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18387 +               return -EBADF;
18388 +
18389 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
18390 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18391 +
18392 +       fput(filp);
18393 +
18394 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18395 +               ret = -EFAULT;
18396 +       return ret;
18397 +}
18398 +
18399 +
18400 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18401 +{
18402 +       struct inode *in = de->d_inode;
18403 +       int error = 0, is_proc = 0, has_tag = 0;
18404 +       struct iattr attr = { 0 };
18405 +
18406 +       if (!in || !in->i_sb)
18407 +               return -ESRCH;
18408 +
18409 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18410 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18411 +               return -EINVAL;
18412 +
18413 +       has_tag = IS_TAGGED(in) ||
18414 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18415 +       if ((*mask & IATTR_TAG) && !has_tag)
18416 +               return -EINVAL;
18417 +
18418 +       mutex_lock(&in->i_mutex);
18419 +       if (*mask & IATTR_TAG) {
18420 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18421 +               attr.ia_valid |= ATTR_TAG;
18422 +       }
18423 +
18424 +       if (*mask & IATTR_FLAGS) {
18425 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18426 +               unsigned int iflags = PROC_I(in)->vx_flags;
18427 +
18428 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18429 +                       | (*flags & IATTR_FLAGS);
18430 +               PROC_I(in)->vx_flags = iflags;
18431 +               if (entry)
18432 +                       entry->vx_flags = iflags;
18433 +       }
18434 +
18435 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18436 +               IATTR_BARRIER | IATTR_COW)) {
18437 +               int iflags = in->i_flags;
18438 +               int vflags = in->i_vflags;
18439 +
18440 +               if (*mask & IATTR_IMMUTABLE) {
18441 +                       if (*flags & IATTR_IMMUTABLE)
18442 +                               iflags |= S_IMMUTABLE;
18443 +                       else
18444 +                               iflags &= ~S_IMMUTABLE;
18445 +               }
18446 +               if (*mask & IATTR_IXUNLINK) {
18447 +                       if (*flags & IATTR_IXUNLINK)
18448 +                               iflags |= S_IXUNLINK;
18449 +                       else
18450 +                               iflags &= ~S_IXUNLINK;
18451 +               }
18452 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18453 +                       if (*flags & IATTR_BARRIER)
18454 +                               vflags |= V_BARRIER;
18455 +                       else
18456 +                               vflags &= ~V_BARRIER;
18457 +               }
18458 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18459 +                       if (*flags & IATTR_COW)
18460 +                               vflags |= V_COW;
18461 +                       else
18462 +                               vflags &= ~V_COW;
18463 +               }
18464 +               if (in->i_op && in->i_op->sync_flags) {
18465 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18466 +                       if (error)
18467 +                               goto out;
18468 +               }
18469 +       }
18470 +
18471 +       if (attr.ia_valid) {
18472 +               if (in->i_op && in->i_op->setattr)
18473 +                       error = in->i_op->setattr(de, &attr);
18474 +               else {
18475 +                       error = inode_change_ok(in, &attr);
18476 +                       if (!error) {
18477 +                               setattr_copy(in, &attr);
18478 +                               mark_inode_dirty(in);
18479 +                       }
18480 +               }
18481 +       }
18482 +
18483 +out:
18484 +       mutex_unlock(&in->i_mutex);
18485 +       return error;
18486 +}
18487 +
18488 +int vc_set_iattr(void __user *data)
18489 +{
18490 +       struct path path;
18491 +       struct vcmd_ctx_iattr_v1 vc_data;
18492 +       int ret;
18493 +
18494 +       if (!capable(CAP_LINUX_IMMUTABLE))
18495 +               return -EPERM;
18496 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18497 +               return -EFAULT;
18498 +
18499 +       ret = user_lpath(vc_data.name, &path);
18500 +       if (!ret) {
18501 +               ret = __vc_set_iattr(path.dentry,
18502 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18503 +               path_put(&path);
18504 +       }
18505 +
18506 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18507 +               ret = -EFAULT;
18508 +       return ret;
18509 +}
18510 +
18511 +#ifdef CONFIG_COMPAT
18512 +
18513 +int vc_set_iattr_x32(void __user *data)
18514 +{
18515 +       struct path path;
18516 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18517 +       int ret;
18518 +
18519 +       if (!capable(CAP_LINUX_IMMUTABLE))
18520 +               return -EPERM;
18521 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18522 +               return -EFAULT;
18523 +
18524 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18525 +       if (!ret) {
18526 +               ret = __vc_set_iattr(path.dentry,
18527 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18528 +               path_put(&path);
18529 +       }
18530 +
18531 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18532 +               ret = -EFAULT;
18533 +       return ret;
18534 +}
18535 +
18536 +#endif /* CONFIG_COMPAT */
18537 +
18538 +int vc_fset_iattr(uint32_t fd, void __user *data)
18539 +{
18540 +       struct file *filp;
18541 +       struct vcmd_ctx_fiattr_v0 vc_data;
18542 +       int ret;
18543 +
18544 +       if (!capable(CAP_LINUX_IMMUTABLE))
18545 +               return -EPERM;
18546 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18547 +               return -EFAULT;
18548 +
18549 +       filp = fget(fd);
18550 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18551 +               return -EBADF;
18552 +
18553 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18554 +               &vc_data.flags, &vc_data.mask);
18555 +
18556 +       fput(filp);
18557 +
18558 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18559 +               return -EFAULT;
18560 +       return ret;
18561 +}
18562 +
18563 +
18564 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18565 +
18566 +static match_table_t tokens = {
18567 +       {Opt_notagcheck, "notagcheck"},
18568 +#ifdef CONFIG_PROPAGATE
18569 +       {Opt_notag, "notag"},
18570 +       {Opt_tag, "tag"},
18571 +       {Opt_tagid, "tagid=%u"},
18572 +#endif
18573 +       {Opt_err, NULL}
18574 +};
18575 +
18576 +
18577 +static void __dx_parse_remove(char *string, char *opt)
18578 +{
18579 +       char *p = strstr(string, opt);
18580 +       char *q = p;
18581 +
18582 +       if (p) {
18583 +               while (*q != '\0' && *q != ',')
18584 +                       q++;
18585 +               while (*q)
18586 +                       *p++ = *q++;
18587 +               while (*p)
18588 +                       *p++ = '\0';
18589 +       }
18590 +}
18591 +
18592 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18593 +                unsigned long *flags)
18594 +{
18595 +       int set = 0;
18596 +       substring_t args[MAX_OPT_ARGS];
18597 +       int token;
18598 +       char *s, *p, *opts;
18599 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18600 +       int option = 0;
18601 +#endif
18602 +
18603 +       if (!string)
18604 +               return 0;
18605 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18606 +       if (!s)
18607 +               return 0;
18608 +
18609 +       opts = s;
18610 +       while ((p = strsep(&opts, ",")) != NULL) {
18611 +               token = match_token(p, tokens, args);
18612 +
18613 +               switch (token) {
18614 +#ifdef CONFIG_PROPAGATE
18615 +               case Opt_tag:
18616 +                       if (tag)
18617 +                               *tag = 0;
18618 +                       if (remove)
18619 +                               __dx_parse_remove(s, "tag");
18620 +                       *mnt_flags |= MNT_TAGID;
18621 +                       set |= MNT_TAGID;
18622 +                       break;
18623 +               case Opt_notag:
18624 +                       if (remove)
18625 +                               __dx_parse_remove(s, "notag");
18626 +                       *mnt_flags |= MNT_NOTAG;
18627 +                       set |= MNT_NOTAG;
18628 +                       break;
18629 +               case Opt_tagid:
18630 +                       if (tag && !match_int(args, &option))
18631 +                               *tag = option;
18632 +                       if (remove)
18633 +                               __dx_parse_remove(s, "tagid");
18634 +                       *mnt_flags |= MNT_TAGID;
18635 +                       set |= MNT_TAGID;
18636 +                       break;
18637 +#endif /* CONFIG_PROPAGATE */
18638 +               case Opt_notagcheck:
18639 +                       if (remove)
18640 +                               __dx_parse_remove(s, "notagcheck");
18641 +                       *flags |= MS_NOTAGCHECK;
18642 +                       set |= MS_NOTAGCHECK;
18643 +                       break;
18644 +               }
18645 +               vxdprintk(VXD_CBIT(tag, 7),
18646 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18647 +                       p, token, option);
18648 +       }
18649 +       if (set)
18650 +               strcpy(string, s);
18651 +       kfree(s);
18652 +       return set;
18653 +}
18654 +
18655 +#ifdef CONFIG_PROPAGATE
18656 +
18657 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18658 +{
18659 +       vtag_t new_tag = 0;
18660 +       struct vfsmount *mnt;
18661 +       int propagate;
18662 +
18663 +       if (!nd)
18664 +               return;
18665 +       mnt = nd->path.mnt;
18666 +       if (!mnt)
18667 +               return;
18668 +
18669 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18670 +       if (propagate)
18671 +               new_tag = mnt->mnt_tag;
18672 +
18673 +       vxdprintk(VXD_CBIT(tag, 7),
18674 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18675 +               inode, inode->i_ino, inode->i_tag,
18676 +               new_tag, (propagate) ? 1 : 0);
18677 +
18678 +       if (propagate)
18679 +               i_tag_write(inode, new_tag);
18680 +}
18681 +
18682 +#include <linux/module.h>
18683 +
18684 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18685 +
18686 +#endif /* CONFIG_PROPAGATE */
18687 +
18688 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c
18689 --- linux-3.13.10/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18690 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c     2014-02-01 00:22:08.000000000 +0000
18691 @@ -0,0 +1,345 @@
18692 +/*
18693 + *  linux/kernel/vserver/limit.c
18694 + *
18695 + *  Virtual Server: Context Limits
18696 + *
18697 + *  Copyright (C) 2004-2010  Herbert Pötzl
18698 + *
18699 + *  V0.01  broken out from vcontext V0.05
18700 + *  V0.02  changed vcmds to vxi arg
18701 + *  V0.03  added memory cgroup support
18702 + *
18703 + */
18704 +
18705 +#include <linux/sched.h>
18706 +#include <linux/module.h>
18707 +#include <linux/memcontrol.h>
18708 +#include <linux/res_counter.h>
18709 +#include <linux/vs_limit.h>
18710 +#include <linux/vserver/limit.h>
18711 +#include <linux/vserver/limit_cmd.h>
18712 +
18713 +#include <asm/uaccess.h>
18714 +
18715 +
18716 +const char *vlimit_name[NUM_LIMITS] = {
18717 +       [RLIMIT_CPU]            = "CPU",
18718 +       [RLIMIT_NPROC]          = "NPROC",
18719 +       [RLIMIT_NOFILE]         = "NOFILE",
18720 +       [RLIMIT_LOCKS]          = "LOCKS",
18721 +       [RLIMIT_SIGPENDING]     = "SIGP",
18722 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18723 +
18724 +       [VLIMIT_NSOCK]          = "NSOCK",
18725 +       [VLIMIT_OPENFD]         = "OPENFD",
18726 +       [VLIMIT_SHMEM]          = "SHMEM",
18727 +       [VLIMIT_DENTRY]         = "DENTRY",
18728 +};
18729 +
18730 +EXPORT_SYMBOL_GPL(vlimit_name);
18731 +
18732 +#define MASK_ENTRY(x)  (1 << (x))
18733 +
18734 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18735 +               /* minimum */
18736 +       0
18737 +       ,       /* softlimit */
18738 +       0
18739 +       ,       /* maximum */
18740 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18741 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18742 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18743 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18744 +
18745 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18746 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18747 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18748 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18749 +       0
18750 +};
18751 +               /* accounting only */
18752 +uint32_t account_mask =
18753 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18754 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18755 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18756 +       0;
18757 +
18758 +
18759 +static int is_valid_vlimit(int id)
18760 +{
18761 +       uint32_t mask = vlimit_mask.minimum |
18762 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18763 +       return mask & (1 << id);
18764 +}
18765 +
18766 +static int is_accounted_vlimit(int id)
18767 +{
18768 +       if (is_valid_vlimit(id))
18769 +               return 1;
18770 +       return account_mask & (1 << id);
18771 +}
18772 +
18773 +
18774 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18775 +{
18776 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18777 +       return VX_VLIM(limit);
18778 +}
18779 +
18780 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18781 +{
18782 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18783 +       return VX_VLIM(limit);
18784 +}
18785 +
18786 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18787 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18788 +{
18789 +       if (!is_valid_vlimit(id))
18790 +               return -EINVAL;
18791 +
18792 +       if (minimum)
18793 +               *minimum = CRLIM_UNSET;
18794 +       if (softlimit)
18795 +               *softlimit = vc_get_soft(vxi, id);
18796 +       if (maximum)
18797 +               *maximum = vc_get_hard(vxi, id);
18798 +       return 0;
18799 +}
18800 +
18801 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18802 +{
18803 +       struct vcmd_ctx_rlimit_v0 vc_data;
18804 +       int ret;
18805 +
18806 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18807 +               return -EFAULT;
18808 +
18809 +       ret = do_get_rlimit(vxi, vc_data.id,
18810 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18811 +       if (ret)
18812 +               return ret;
18813 +
18814 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18815 +               return -EFAULT;
18816 +       return 0;
18817 +}
18818 +
18819 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18820 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18821 +{
18822 +       if (!is_valid_vlimit(id))
18823 +               return -EINVAL;
18824 +
18825 +       if (maximum != CRLIM_KEEP)
18826 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18827 +       if (softlimit != CRLIM_KEEP)
18828 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18829 +
18830 +       /* clamp soft limit */
18831 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18832 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18833 +
18834 +       return 0;
18835 +}
18836 +
18837 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18838 +{
18839 +       struct vcmd_ctx_rlimit_v0 vc_data;
18840 +
18841 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18842 +               return -EFAULT;
18843 +
18844 +       return do_set_rlimit(vxi, vc_data.id,
18845 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18846 +}
18847 +
18848 +#ifdef CONFIG_IA32_EMULATION
18849 +
18850 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18851 +{
18852 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18853 +
18854 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18855 +               return -EFAULT;
18856 +
18857 +       return do_set_rlimit(vxi, vc_data.id,
18858 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18859 +}
18860 +
18861 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18862 +{
18863 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18864 +       int ret;
18865 +
18866 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18867 +               return -EFAULT;
18868 +
18869 +       ret = do_get_rlimit(vxi, vc_data.id,
18870 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18871 +       if (ret)
18872 +               return ret;
18873 +
18874 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18875 +               return -EFAULT;
18876 +       return 0;
18877 +}
18878 +
18879 +#endif /* CONFIG_IA32_EMULATION */
18880 +
18881 +
18882 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18883 +{
18884 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18885 +               return -EFAULT;
18886 +       return 0;
18887 +}
18888 +
18889 +
18890 +static inline void vx_reset_hits(struct _vx_limit *limit)
18891 +{
18892 +       int lim;
18893 +
18894 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18895 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18896 +       }
18897 +}
18898 +
18899 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18900 +{
18901 +       vx_reset_hits(&vxi->limit);
18902 +       return 0;
18903 +}
18904 +
18905 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18906 +{
18907 +       rlim_t value;
18908 +       int lim;
18909 +
18910 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18911 +               value = __rlim_get(limit, lim);
18912 +               __rlim_rmax(limit, lim) = value;
18913 +               __rlim_rmin(limit, lim) = value;
18914 +       }
18915 +}
18916 +
18917 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18918 +{
18919 +       vx_reset_minmax(&vxi->limit);
18920 +       return 0;
18921 +}
18922 +
18923 +
18924 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18925 +{
18926 +       struct vcmd_rlimit_stat_v0 vc_data;
18927 +       struct _vx_limit *limit = &vxi->limit;
18928 +       int id;
18929 +
18930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18931 +               return -EFAULT;
18932 +
18933 +       id = vc_data.id;
18934 +       if (!is_accounted_vlimit(id))
18935 +               return -EINVAL;
18936 +
18937 +       vx_limit_fixup(limit, id);
18938 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18939 +       vc_data.value = __rlim_get(limit, id);
18940 +       vc_data.minimum = __rlim_rmin(limit, id);
18941 +       vc_data.maximum = __rlim_rmax(limit, id);
18942 +
18943 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18944 +               return -EFAULT;
18945 +       return 0;
18946 +}
18947 +
18948 +
18949 +void vx_vsi_meminfo(struct sysinfo *val)
18950 +{
18951 +#ifdef CONFIG_MEMCG
18952 +       struct mem_cgroup *mcg;
18953 +       u64 res_limit, res_usage;
18954 +
18955 +       rcu_read_lock();
18956 +       mcg = mem_cgroup_from_task(current);
18957 +       rcu_read_unlock();
18958 +       if (!mcg)
18959 +               goto out;
18960 +
18961 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18962 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18963 +
18964 +       if (res_limit != RES_COUNTER_MAX)
18965 +               val->totalram = (res_limit >> PAGE_SHIFT);
18966 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
18967 +       val->bufferram = 0;
18968 +       val->totalhigh = 0;
18969 +       val->freehigh = 0;
18970 +out:
18971 +#endif /* CONFIG_MEMCG */
18972 +       return;
18973 +}
18974 +
18975 +void vx_vsi_swapinfo(struct sysinfo *val)
18976 +{
18977 +#ifdef CONFIG_MEMCG
18978 +#ifdef CONFIG_MEMCG_SWAP
18979 +       struct mem_cgroup *mcg;
18980 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
18981 +       s64 swap_limit, swap_usage;
18982 +
18983 +       rcu_read_lock();
18984 +       mcg = mem_cgroup_from_task(current);
18985 +       rcu_read_unlock();
18986 +       if (!mcg)
18987 +               goto out;
18988 +
18989 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18990 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18991 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
18992 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
18993 +
18994 +       /* memory unlimited */
18995 +       if (res_limit == RES_COUNTER_MAX)
18996 +               goto out;
18997 +
18998 +       swap_limit = memsw_limit - res_limit;
18999 +       /* we have a swap limit? */
19000 +       if (memsw_limit != RES_COUNTER_MAX)
19001 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19002 +
19003 +       /* calculate swap part */
19004 +       swap_usage = (memsw_usage > res_usage) ?
19005 +               memsw_usage - res_usage : 0;
19006 +
19007 +       /* total shown minus usage gives free swap */
19008 +       val->freeswap = (swap_usage < swap_limit) ?
19009 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19010 +out:
19011 +#else  /* !CONFIG_MEMCG_SWAP */
19012 +       val->totalswap = 0;
19013 +       val->freeswap = 0;
19014 +#endif /* !CONFIG_MEMCG_SWAP */
19015 +#endif /* CONFIG_MEMCG */
19016 +       return;
19017 +}
19018 +
19019 +long vx_vsi_cached(struct sysinfo *val)
19020 +{
19021 +       long cache = 0;
19022 +#ifdef CONFIG_MEMCG
19023 +       struct mem_cgroup *mcg;
19024 +
19025 +       rcu_read_lock();
19026 +       mcg = mem_cgroup_from_task(current);
19027 +       rcu_read_unlock();
19028 +       if (!mcg)
19029 +               goto out;
19030 +
19031 +       cache = mem_cgroup_stat_read_cache(mcg);
19032 +out:
19033 +#endif
19034 +       return cache;
19035 +}
19036 +
19037 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
19038 --- linux-3.13.10/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19039 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h        2014-01-31 20:38:04.000000000 +0000
19040 @@ -0,0 +1,31 @@
19041 +
19042 +
19043 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19044 +{
19045 +       int lim;
19046 +
19047 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19048 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19049 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19050 +               __rlim_set(limit, lim, 0);
19051 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19052 +               __rlim_rmin(limit, lim) = 0;
19053 +               __rlim_rmax(limit, lim) = 0;
19054 +       }
19055 +}
19056 +
19057 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19058 +{
19059 +       rlim_t value;
19060 +       int lim;
19061 +
19062 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19063 +               if ((1 << lim) & VLIM_NOCHECK)
19064 +                       continue;
19065 +               value = __rlim_get(limit, lim);
19066 +               vxwprintk_xid(value,
19067 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19068 +                       limit, vlimit_name[lim], lim, (long)value);
19069 +       }
19070 +}
19071 +
19072 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
19073 --- linux-3.13.10/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19074 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h        2014-01-31 20:38:04.000000000 +0000
19075 @@ -0,0 +1,57 @@
19076 +#ifndef _VX_LIMIT_PROC_H
19077 +#define _VX_LIMIT_PROC_H
19078 +
19079 +#include <linux/vserver/limit_int.h>
19080 +
19081 +
19082 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19083 +#define VX_LIMIT_TOP   \
19084 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19085 +
19086 +#define VX_LIMIT_ARG(r)                                \
19087 +       (unsigned long)__rlim_get(limit, r),    \
19088 +       (unsigned long)__rlim_rmin(limit, r),   \
19089 +       (unsigned long)__rlim_rmax(limit, r),   \
19090 +       VX_VLIM(__rlim_soft(limit, r)),         \
19091 +       VX_VLIM(__rlim_hard(limit, r)),         \
19092 +       atomic_read(&__rlim_lhit(limit, r))
19093 +
19094 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19095 +{
19096 +       vx_limit_fixup(limit, -1);
19097 +       return sprintf(buffer, VX_LIMIT_TOP
19098 +               "PROC"  VX_LIMIT_FMT
19099 +               "VM"    VX_LIMIT_FMT
19100 +               "VML"   VX_LIMIT_FMT
19101 +               "RSS"   VX_LIMIT_FMT
19102 +               "ANON"  VX_LIMIT_FMT
19103 +               "RMAP"  VX_LIMIT_FMT
19104 +               "FILES" VX_LIMIT_FMT
19105 +               "OFD"   VX_LIMIT_FMT
19106 +               "LOCKS" VX_LIMIT_FMT
19107 +               "SOCK"  VX_LIMIT_FMT
19108 +               "MSGQ"  VX_LIMIT_FMT
19109 +               "SHM"   VX_LIMIT_FMT
19110 +               "SEMA"  VX_LIMIT_FMT
19111 +               "SEMS"  VX_LIMIT_FMT
19112 +               "DENT"  VX_LIMIT_FMT,
19113 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19114 +               VX_LIMIT_ARG(RLIMIT_AS),
19115 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19116 +               VX_LIMIT_ARG(RLIMIT_RSS),
19117 +               VX_LIMIT_ARG(VLIMIT_ANON),
19118 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19119 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19120 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19121 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19122 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19123 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19124 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19125 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19126 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19127 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19128 +}
19129 +
19130 +#endif /* _VX_LIMIT_PROC_H */
19131 +
19132 +
19133 diff -NurpP --minimal linux-3.13.10/kernel/vserver/network.c linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c
19134 --- linux-3.13.10/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19135 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c   2014-01-31 20:38:04.000000000 +0000
19136 @@ -0,0 +1,1053 @@
19137 +/*
19138 + *  linux/kernel/vserver/network.c
19139 + *
19140 + *  Virtual Server: Network Support
19141 + *
19142 + *  Copyright (C) 2003-2007  Herbert Pötzl
19143 + *
19144 + *  V0.01  broken out from vcontext V0.05
19145 + *  V0.02  cleaned up implementation
19146 + *  V0.03  added equiv nx commands
19147 + *  V0.04  switch to RCU based hash
19148 + *  V0.05  and back to locking again
19149 + *  V0.06  changed vcmds to nxi arg
19150 + *  V0.07  have __create claim() the nxi
19151 + *
19152 + */
19153 +
19154 +#include <linux/err.h>
19155 +#include <linux/slab.h>
19156 +#include <linux/rcupdate.h>
19157 +#include <net/ipv6.h>
19158 +
19159 +#include <linux/vs_network.h>
19160 +#include <linux/vs_pid.h>
19161 +#include <linux/vserver/network_cmd.h>
19162 +
19163 +
19164 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19165 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19166 +
19167 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19168 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19169 +
19170 +
19171 +static int __init init_network(void)
19172 +{
19173 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19174 +               sizeof(struct nx_addr_v4), 0,
19175 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19176 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19177 +               sizeof(struct nx_addr_v6), 0,
19178 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19179 +       return 0;
19180 +}
19181 +
19182 +
19183 +/*     __alloc_nx_addr_v4()                                    */
19184 +
19185 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19186 +{
19187 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19188 +               nx_addr_v4_cachep, GFP_KERNEL);
19189 +
19190 +       if (!IS_ERR(nxa))
19191 +               memset(nxa, 0, sizeof(*nxa));
19192 +       return nxa;
19193 +}
19194 +
19195 +/*     __dealloc_nx_addr_v4()                                  */
19196 +
19197 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19198 +{
19199 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19200 +}
19201 +
19202 +/*     __dealloc_nx_addr_v4_all()                              */
19203 +
19204 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19205 +{
19206 +       while (nxa) {
19207 +               struct nx_addr_v4 *next = nxa->next;
19208 +
19209 +               __dealloc_nx_addr_v4(nxa);
19210 +               nxa = next;
19211 +       }
19212 +}
19213 +
19214 +
19215 +#ifdef CONFIG_IPV6
19216 +
19217 +/*     __alloc_nx_addr_v6()                                    */
19218 +
19219 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19220 +{
19221 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19222 +               nx_addr_v6_cachep, GFP_KERNEL);
19223 +
19224 +       if (!IS_ERR(nxa))
19225 +               memset(nxa, 0, sizeof(*nxa));
19226 +       return nxa;
19227 +}
19228 +
19229 +/*     __dealloc_nx_addr_v6()                                  */
19230 +
19231 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19232 +{
19233 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19234 +}
19235 +
19236 +/*     __dealloc_nx_addr_v6_all()                              */
19237 +
19238 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19239 +{
19240 +       while (nxa) {
19241 +               struct nx_addr_v6 *next = nxa->next;
19242 +
19243 +               __dealloc_nx_addr_v6(nxa);
19244 +               nxa = next;
19245 +       }
19246 +}
19247 +
19248 +#endif /* CONFIG_IPV6 */
19249 +
19250 +/*     __alloc_nx_info()
19251 +
19252 +       * allocate an initialized nx_info struct
19253 +       * doesn't make it visible (hash)                        */
19254 +
19255 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19256 +{
19257 +       struct nx_info *new = NULL;
19258 +
19259 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19260 +
19261 +       /* would this benefit from a slab cache? */
19262 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19263 +       if (!new)
19264 +               return 0;
19265 +
19266 +       memset(new, 0, sizeof(struct nx_info));
19267 +       new->nx_id = nid;
19268 +       INIT_HLIST_NODE(&new->nx_hlist);
19269 +       atomic_set(&new->nx_usecnt, 0);
19270 +       atomic_set(&new->nx_tasks, 0);
19271 +       spin_lock_init(&new->addr_lock);
19272 +       new->nx_state = 0;
19273 +
19274 +       new->nx_flags = NXF_INIT_SET;
19275 +
19276 +       /* rest of init goes here */
19277 +
19278 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19279 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19280 +
19281 +       vxdprintk(VXD_CBIT(nid, 0),
19282 +               "alloc_nx_info(%d) = %p", nid, new);
19283 +       atomic_inc(&nx_global_ctotal);
19284 +       return new;
19285 +}
19286 +
19287 +/*     __dealloc_nx_info()
19288 +
19289 +       * final disposal of nx_info                             */
19290 +
19291 +static void __dealloc_nx_info(struct nx_info *nxi)
19292 +{
19293 +       vxdprintk(VXD_CBIT(nid, 0),
19294 +               "dealloc_nx_info(%p)", nxi);
19295 +
19296 +       nxi->nx_hlist.next = LIST_POISON1;
19297 +       nxi->nx_id = -1;
19298 +
19299 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19300 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19301 +
19302 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19303 +#ifdef CONFIG_IPV6
19304 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19305 +#endif
19306 +
19307 +       nxi->nx_state |= NXS_RELEASED;
19308 +       kfree(nxi);
19309 +       atomic_dec(&nx_global_ctotal);
19310 +}
19311 +
19312 +static void __shutdown_nx_info(struct nx_info *nxi)
19313 +{
19314 +       nxi->nx_state |= NXS_SHUTDOWN;
19315 +       vs_net_change(nxi, VSC_NETDOWN);
19316 +}
19317 +
19318 +/*     exported stuff                                          */
19319 +
19320 +void free_nx_info(struct nx_info *nxi)
19321 +{
19322 +       /* context shutdown is mandatory */
19323 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19324 +
19325 +       /* context must not be hashed */
19326 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19327 +
19328 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19329 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19330 +
19331 +       __dealloc_nx_info(nxi);
19332 +}
19333 +
19334 +
19335 +void __nx_set_lback(struct nx_info *nxi)
19336 +{
19337 +       int nid = nxi->nx_id;
19338 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19339 +
19340 +       nxi->v4_lback.s_addr = lback;
19341 +}
19342 +
19343 +extern int __nx_inet_add_lback(__be32 addr);
19344 +extern int __nx_inet_del_lback(__be32 addr);
19345 +
19346 +
19347 +/*     hash table for nx_info hash */
19348 +
19349 +#define NX_HASH_SIZE   13
19350 +
19351 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19352 +
19353 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19354 +
19355 +
19356 +static inline unsigned int __hashval(vnid_t nid)
19357 +{
19358 +       return (nid % NX_HASH_SIZE);
19359 +}
19360 +
19361 +
19362 +
19363 +/*     __hash_nx_info()
19364 +
19365 +       * add the nxi to the global hash table
19366 +       * requires the hash_lock to be held                     */
19367 +
19368 +static inline void __hash_nx_info(struct nx_info *nxi)
19369 +{
19370 +       struct hlist_head *head;
19371 +
19372 +       vxd_assert_lock(&nx_info_hash_lock);
19373 +       vxdprintk(VXD_CBIT(nid, 4),
19374 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19375 +
19376 +       /* context must not be hashed */
19377 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19378 +
19379 +       nxi->nx_state |= NXS_HASHED;
19380 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19381 +       hlist_add_head(&nxi->nx_hlist, head);
19382 +       atomic_inc(&nx_global_cactive);
19383 +}
19384 +
19385 +/*     __unhash_nx_info()
19386 +
19387 +       * remove the nxi from the global hash table
19388 +       * requires the hash_lock to be held                     */
19389 +
19390 +static inline void __unhash_nx_info(struct nx_info *nxi)
19391 +{
19392 +       vxd_assert_lock(&nx_info_hash_lock);
19393 +       vxdprintk(VXD_CBIT(nid, 4),
19394 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19395 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19396 +
19397 +       /* context must be hashed */
19398 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19399 +       /* but without tasks */
19400 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19401 +
19402 +       nxi->nx_state &= ~NXS_HASHED;
19403 +       hlist_del(&nxi->nx_hlist);
19404 +       atomic_dec(&nx_global_cactive);
19405 +}
19406 +
19407 +
19408 +/*     __lookup_nx_info()
19409 +
19410 +       * requires the hash_lock to be held
19411 +       * doesn't increment the nx_refcnt                       */
19412 +
19413 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19414 +{
19415 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19416 +       struct hlist_node *pos;
19417 +       struct nx_info *nxi;
19418 +
19419 +       vxd_assert_lock(&nx_info_hash_lock);
19420 +       hlist_for_each(pos, head) {
19421 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19422 +
19423 +               if (nxi->nx_id == nid)
19424 +                       goto found;
19425 +       }
19426 +       nxi = NULL;
19427 +found:
19428 +       vxdprintk(VXD_CBIT(nid, 0),
19429 +               "__lookup_nx_info(#%u): %p[#%u]",
19430 +               nid, nxi, nxi ? nxi->nx_id : 0);
19431 +       return nxi;
19432 +}
19433 +
19434 +
19435 +/*     __create_nx_info()
19436 +
19437 +       * create the requested context
19438 +       * get(), claim() and hash it                            */
19439 +
19440 +static struct nx_info *__create_nx_info(int id)
19441 +{
19442 +       struct nx_info *new, *nxi = NULL;
19443 +
19444 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19445 +
19446 +       if (!(new = __alloc_nx_info(id)))
19447 +               return ERR_PTR(-ENOMEM);
19448 +
19449 +       /* required to make dynamic xids unique */
19450 +       spin_lock(&nx_info_hash_lock);
19451 +
19452 +       /* static context requested */
19453 +       if ((nxi = __lookup_nx_info(id))) {
19454 +               vxdprintk(VXD_CBIT(nid, 0),
19455 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19456 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19457 +                       nxi = ERR_PTR(-EBUSY);
19458 +               else
19459 +                       nxi = ERR_PTR(-EEXIST);
19460 +               goto out_unlock;
19461 +       }
19462 +       /* new context */
19463 +       vxdprintk(VXD_CBIT(nid, 0),
19464 +               "create_nx_info(%d) = %p (new)", id, new);
19465 +       claim_nx_info(new, NULL);
19466 +       __nx_set_lback(new);
19467 +       __hash_nx_info(get_nx_info(new));
19468 +       nxi = new, new = NULL;
19469 +
19470 +out_unlock:
19471 +       spin_unlock(&nx_info_hash_lock);
19472 +       if (new)
19473 +               __dealloc_nx_info(new);
19474 +       return nxi;
19475 +}
19476 +
19477 +
19478 +
19479 +/*     exported stuff                                          */
19480 +
19481 +
19482 +void unhash_nx_info(struct nx_info *nxi)
19483 +{
19484 +       __shutdown_nx_info(nxi);
19485 +       spin_lock(&nx_info_hash_lock);
19486 +       __unhash_nx_info(nxi);
19487 +       spin_unlock(&nx_info_hash_lock);
19488 +}
19489 +
19490 +/*     lookup_nx_info()
19491 +
19492 +       * search for a nx_info and get() it
19493 +       * negative id means current                             */
19494 +
19495 +struct nx_info *lookup_nx_info(int id)
19496 +{
19497 +       struct nx_info *nxi = NULL;
19498 +
19499 +       if (id < 0) {
19500 +               nxi = get_nx_info(current_nx_info());
19501 +       } else if (id > 1) {
19502 +               spin_lock(&nx_info_hash_lock);
19503 +               nxi = get_nx_info(__lookup_nx_info(id));
19504 +               spin_unlock(&nx_info_hash_lock);
19505 +       }
19506 +       return nxi;
19507 +}
19508 +
19509 +/*     nid_is_hashed()
19510 +
19511 +       * verify that nid is still hashed                       */
19512 +
19513 +int nid_is_hashed(vnid_t nid)
19514 +{
19515 +       int hashed;
19516 +
19517 +       spin_lock(&nx_info_hash_lock);
19518 +       hashed = (__lookup_nx_info(nid) != NULL);
19519 +       spin_unlock(&nx_info_hash_lock);
19520 +       return hashed;
19521 +}
19522 +
19523 +
19524 +#ifdef CONFIG_PROC_FS
19525 +
19526 +/*     get_nid_list()
19527 +
19528 +       * get a subset of hashed nids for proc
19529 +       * assumes size is at least one                          */
19530 +
19531 +int get_nid_list(int index, unsigned int *nids, int size)
19532 +{
19533 +       int hindex, nr_nids = 0;
19534 +
19535 +       /* only show current and children */
19536 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19537 +               if (index > 0)
19538 +                       return 0;
19539 +               nids[nr_nids] = nx_current_nid();
19540 +               return 1;
19541 +       }
19542 +
19543 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19544 +               struct hlist_head *head = &nx_info_hash[hindex];
19545 +               struct hlist_node *pos;
19546 +
19547 +               spin_lock(&nx_info_hash_lock);
19548 +               hlist_for_each(pos, head) {
19549 +                       struct nx_info *nxi;
19550 +
19551 +                       if (--index > 0)
19552 +                               continue;
19553 +
19554 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19555 +                       nids[nr_nids] = nxi->nx_id;
19556 +                       if (++nr_nids >= size) {
19557 +                               spin_unlock(&nx_info_hash_lock);
19558 +                               goto out;
19559 +                       }
19560 +               }
19561 +               /* keep the lock time short */
19562 +               spin_unlock(&nx_info_hash_lock);
19563 +       }
19564 +out:
19565 +       return nr_nids;
19566 +}
19567 +#endif
19568 +
19569 +
19570 +/*
19571 + *     migrate task to new network
19572 + *     gets nxi, puts old_nxi on change
19573 + */
19574 +
19575 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19576 +{
19577 +       struct nx_info *old_nxi;
19578 +       int ret = 0;
19579 +
19580 +       if (!p || !nxi)
19581 +               BUG();
19582 +
19583 +       vxdprintk(VXD_CBIT(nid, 5),
19584 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19585 +               p, nxi, nxi->nx_id,
19586 +               atomic_read(&nxi->nx_usecnt),
19587 +               atomic_read(&nxi->nx_tasks));
19588 +
19589 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19590 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19591 +               return -EACCES;
19592 +
19593 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19594 +               return -EFAULT;
19595 +
19596 +       /* maybe disallow this completely? */
19597 +       old_nxi = task_get_nx_info(p);
19598 +       if (old_nxi == nxi)
19599 +               goto out;
19600 +
19601 +       task_lock(p);
19602 +       if (old_nxi)
19603 +               clr_nx_info(&p->nx_info);
19604 +       claim_nx_info(nxi, p);
19605 +       set_nx_info(&p->nx_info, nxi);
19606 +       p->nid = nxi->nx_id;
19607 +       task_unlock(p);
19608 +
19609 +       vxdprintk(VXD_CBIT(nid, 5),
19610 +               "moved task %p into nxi:%p[#%d]",
19611 +               p, nxi, nxi->nx_id);
19612 +
19613 +       if (old_nxi)
19614 +               release_nx_info(old_nxi, p);
19615 +       ret = 0;
19616 +out:
19617 +       put_nx_info(old_nxi);
19618 +       return ret;
19619 +}
19620 +
19621 +
19622 +void nx_set_persistent(struct nx_info *nxi)
19623 +{
19624 +       vxdprintk(VXD_CBIT(nid, 6),
19625 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19626 +
19627 +       get_nx_info(nxi);
19628 +       claim_nx_info(nxi, NULL);
19629 +}
19630 +
19631 +void nx_clear_persistent(struct nx_info *nxi)
19632 +{
19633 +       vxdprintk(VXD_CBIT(nid, 6),
19634 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19635 +
19636 +       release_nx_info(nxi, NULL);
19637 +       put_nx_info(nxi);
19638 +}
19639 +
19640 +void nx_update_persistent(struct nx_info *nxi)
19641 +{
19642 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19643 +               nx_set_persistent(nxi);
19644 +       else
19645 +               nx_clear_persistent(nxi);
19646 +}
19647 +
19648 +/* vserver syscall commands below here */
19649 +
19650 +/* taks nid and nx_info functions */
19651 +
19652 +#include <asm/uaccess.h>
19653 +
19654 +
19655 +int vc_task_nid(uint32_t id)
19656 +{
19657 +       vnid_t nid;
19658 +
19659 +       if (id) {
19660 +               struct task_struct *tsk;
19661 +
19662 +               rcu_read_lock();
19663 +               tsk = find_task_by_real_pid(id);
19664 +               nid = (tsk) ? tsk->nid : -ESRCH;
19665 +               rcu_read_unlock();
19666 +       } else
19667 +               nid = nx_current_nid();
19668 +       return nid;
19669 +}
19670 +
19671 +
19672 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19673 +{
19674 +       struct vcmd_nx_info_v0 vc_data;
19675 +
19676 +       vc_data.nid = nxi->nx_id;
19677 +
19678 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19679 +               return -EFAULT;
19680 +       return 0;
19681 +}
19682 +
19683 +
19684 +/* network functions */
19685 +
19686 +int vc_net_create(uint32_t nid, void __user *data)
19687 +{
19688 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19689 +       struct nx_info *new_nxi;
19690 +       int ret;
19691 +
19692 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19693 +               return -EFAULT;
19694 +
19695 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19696 +               return -EINVAL;
19697 +
19698 +       new_nxi = __create_nx_info(nid);
19699 +       if (IS_ERR(new_nxi))
19700 +               return PTR_ERR(new_nxi);
19701 +
19702 +       /* initial flags */
19703 +       new_nxi->nx_flags = vc_data.flagword;
19704 +
19705 +       ret = -ENOEXEC;
19706 +       if (vs_net_change(new_nxi, VSC_NETUP))
19707 +               goto out;
19708 +
19709 +       ret = nx_migrate_task(current, new_nxi);
19710 +       if (ret)
19711 +               goto out;
19712 +
19713 +       /* return context id on success */
19714 +       ret = new_nxi->nx_id;
19715 +
19716 +       /* get a reference for persistent contexts */
19717 +       if ((vc_data.flagword & NXF_PERSISTENT))
19718 +               nx_set_persistent(new_nxi);
19719 +out:
19720 +       release_nx_info(new_nxi, NULL);
19721 +       put_nx_info(new_nxi);
19722 +       return ret;
19723 +}
19724 +
19725 +
19726 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19727 +{
19728 +       return nx_migrate_task(current, nxi);
19729 +}
19730 +
19731 +
19732 +static inline
19733 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19734 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19735 +       struct nx_addr_v4 **prev)
19736 +{
19737 +       struct nx_addr_v4 *nxa = &nxi->v4;
19738 +
19739 +       for (; nxa; nxa = nxa->next) {
19740 +               if ((nxa->ip[0].s_addr == ip) &&
19741 +                   (nxa->ip[1].s_addr == ip2) &&
19742 +                   (nxa->mask.s_addr == mask) &&
19743 +                   (nxa->type == type) &&
19744 +                   (nxa->flags == flags))
19745 +                   return nxa;
19746 +
19747 +               /* save previous entry */
19748 +               if (prev)
19749 +                       *prev = nxa;
19750 +       }
19751 +       return NULL;
19752 +}
19753 +
19754 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19755 +       uint16_t type, uint16_t flags)
19756 +{
19757 +       struct nx_addr_v4 *nxa = NULL;
19758 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19759 +       unsigned long irqflags;
19760 +       int ret = -EEXIST;
19761 +
19762 +       if (IS_ERR(new))
19763 +               return PTR_ERR(new);
19764 +
19765 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19766 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19767 +               goto out_unlock;
19768 +
19769 +       if (NX_IPV4(nxi)) {
19770 +               nxa->next = new;
19771 +               nxa = new;
19772 +               new = NULL;
19773 +
19774 +               /* remove single ip for ip list */
19775 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19776 +       }
19777 +
19778 +       nxa->ip[0].s_addr = ip;
19779 +       nxa->ip[1].s_addr = ip2;
19780 +       nxa->mask.s_addr = mask;
19781 +       nxa->type = type;
19782 +       nxa->flags = flags;
19783 +       ret = 0;
19784 +out_unlock:
19785 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19786 +       if (new)
19787 +               __dealloc_nx_addr_v4(new);
19788 +       return ret;
19789 +}
19790 +
19791 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19792 +       uint16_t type, uint16_t flags)
19793 +{
19794 +       struct nx_addr_v4 *nxa = NULL;
19795 +       struct nx_addr_v4 *old = NULL;
19796 +       unsigned long irqflags;
19797 +       int ret = 0;
19798 +
19799 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19800 +       switch (type) {
19801 +       case NXA_TYPE_ADDR:
19802 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19803 +               if (old) {
19804 +                       if (nxa) {
19805 +                               nxa->next = old->next;
19806 +                               old->next = NULL;
19807 +                       } else {
19808 +                               if (old->next) {
19809 +                                       nxa = old;
19810 +                                       old = old->next;
19811 +                                       *nxa = *old;
19812 +                                       old->next = NULL;
19813 +                               } else {
19814 +                                       memset(old, 0, sizeof(*old));
19815 +                                       old = NULL;
19816 +                               }
19817 +                       }
19818 +               } else
19819 +                       ret = -ESRCH;
19820 +               break;
19821 +
19822 +       case NXA_TYPE_ANY:
19823 +               nxa = &nxi->v4;
19824 +               old = nxa->next;
19825 +               memset(nxa, 0, sizeof(*nxa));
19826 +               break;
19827 +
19828 +       default:
19829 +               ret = -EINVAL;
19830 +       }
19831 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19832 +       __dealloc_nx_addr_v4_all(old);
19833 +       return ret;
19834 +}
19835 +
19836 +
19837 +int vc_net_add(struct nx_info *nxi, void __user *data)
19838 +{
19839 +       struct vcmd_net_addr_v0 vc_data;
19840 +       int index, ret = 0;
19841 +
19842 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19843 +               return -EFAULT;
19844 +
19845 +       switch (vc_data.type) {
19846 +       case NXA_TYPE_IPV4:
19847 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19848 +                       return -EINVAL;
19849 +
19850 +               index = 0;
19851 +               while (index < vc_data.count) {
19852 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19853 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19854 +                       if (ret)
19855 +                               return ret;
19856 +                       index++;
19857 +               }
19858 +               ret = index;
19859 +               break;
19860 +
19861 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19862 +               nxi->v4_bcast = vc_data.ip[0];
19863 +               ret = 1;
19864 +               break;
19865 +
19866 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19867 +               nxi->v4_lback = vc_data.ip[0];
19868 +               ret = 1;
19869 +               break;
19870 +
19871 +       default:
19872 +               ret = -EINVAL;
19873 +               break;
19874 +       }
19875 +       return ret;
19876 +}
19877 +
19878 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19879 +{
19880 +       struct vcmd_net_addr_v0 vc_data;
19881 +
19882 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19883 +               return -EFAULT;
19884 +
19885 +       switch (vc_data.type) {
19886 +       case NXA_TYPE_ANY:
19887 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19888 +       default:
19889 +               return -EINVAL;
19890 +       }
19891 +       return 0;
19892 +}
19893 +
19894 +
19895 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19896 +{
19897 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19898 +
19899 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19900 +               return -EFAULT;
19901 +
19902 +       switch (vc_data.type) {
19903 +       case NXA_TYPE_ADDR:
19904 +       case NXA_TYPE_MASK:
19905 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19906 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19907 +
19908 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19909 +               nxi->v4_bcast = vc_data.ip;
19910 +               break;
19911 +
19912 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19913 +               nxi->v4_lback = vc_data.ip;
19914 +               break;
19915 +
19916 +       default:
19917 +               return -EINVAL;
19918 +       }
19919 +       return 0;
19920 +}
19921 +
19922 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19923 +{
19924 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19925 +
19926 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19927 +               return -EFAULT;
19928 +
19929 +       switch (vc_data.type) {
19930 +       case NXA_TYPE_ADDR:
19931 +       case NXA_TYPE_MASK:
19932 +       case NXA_TYPE_RANGE:
19933 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19934 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19935 +
19936 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19937 +               nxi->v4_bcast = vc_data.ip;
19938 +               break;
19939 +
19940 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19941 +               nxi->v4_lback = vc_data.ip;
19942 +               break;
19943 +
19944 +       default:
19945 +               return -EINVAL;
19946 +       }
19947 +       return 0;
19948 +}
19949 +
19950 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19951 +{
19952 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19953 +
19954 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19955 +               return -EFAULT;
19956 +
19957 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19958 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19959 +}
19960 +
19961 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19962 +{
19963 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19964 +
19965 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19966 +               return -EFAULT;
19967 +
19968 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19969 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19970 +}
19971 +
19972 +#ifdef CONFIG_IPV6
19973 +
19974 +static inline
19975 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19976 +       struct in6_addr *ip, struct in6_addr *mask,
19977 +       uint32_t prefix, uint16_t type, uint16_t flags,
19978 +       struct nx_addr_v6 **prev)
19979 +{
19980 +       struct nx_addr_v6 *nxa = &nxi->v6;
19981 +
19982 +       for (; nxa; nxa = nxa->next) {
19983 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
19984 +                   ipv6_addr_equal(&nxa->mask, mask) &&
19985 +                   (nxa->prefix == prefix) &&
19986 +                   (nxa->type == type) &&
19987 +                   (nxa->flags == flags))
19988 +                   return nxa;
19989 +
19990 +               /* save previous entry */
19991 +               if (prev)
19992 +                       *prev = nxa;
19993 +       }
19994 +       return NULL;
19995 +}
19996 +
19997 +
19998 +int do_add_v6_addr(struct nx_info *nxi,
19999 +       struct in6_addr *ip, struct in6_addr *mask,
20000 +       uint32_t prefix, uint16_t type, uint16_t flags)
20001 +{
20002 +       struct nx_addr_v6 *nxa = NULL;
20003 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20004 +       unsigned long irqflags;
20005 +       int ret = -EEXIST;
20006 +
20007 +       if (IS_ERR(new))
20008 +               return PTR_ERR(new);
20009 +
20010 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20011 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20012 +               goto out_unlock;
20013 +
20014 +       if (NX_IPV6(nxi)) {
20015 +               nxa->next = new;
20016 +               nxa = new;
20017 +               new = NULL;
20018 +       }
20019 +
20020 +       nxa->ip = *ip;
20021 +       nxa->mask = *mask;
20022 +       nxa->prefix = prefix;
20023 +       nxa->type = type;
20024 +       nxa->flags = flags;
20025 +       ret = 0;
20026 +out_unlock:
20027 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20028 +       if (new)
20029 +               __dealloc_nx_addr_v6(new);
20030 +       return ret;
20031 +}
20032 +
20033 +int do_remove_v6_addr(struct nx_info *nxi,
20034 +       struct in6_addr *ip, struct in6_addr *mask,
20035 +       uint32_t prefix, uint16_t type, uint16_t flags)
20036 +{
20037 +       struct nx_addr_v6 *nxa = NULL;
20038 +       struct nx_addr_v6 *old = NULL;
20039 +       unsigned long irqflags;
20040 +       int ret = 0;
20041 +
20042 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20043 +       switch (type) {
20044 +       case NXA_TYPE_ADDR:
20045 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20046 +               if (old) {
20047 +                       if (nxa) {
20048 +                               nxa->next = old->next;
20049 +                               old->next = NULL;
20050 +                       } else {
20051 +                               if (old->next) {
20052 +                                       nxa = old;
20053 +                                       old = old->next;
20054 +                                       *nxa = *old;
20055 +                                       old->next = NULL;
20056 +                               } else {
20057 +                                       memset(old, 0, sizeof(*old));
20058 +                                       old = NULL;
20059 +                               }
20060 +                       }
20061 +               } else
20062 +                       ret = -ESRCH;
20063 +               break;
20064 +
20065 +       case NXA_TYPE_ANY:
20066 +               nxa = &nxi->v6;
20067 +               old = nxa->next;
20068 +               memset(nxa, 0, sizeof(*nxa));
20069 +               break;
20070 +
20071 +       default:
20072 +               ret = -EINVAL;
20073 +       }
20074 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20075 +       __dealloc_nx_addr_v6_all(old);
20076 +       return ret;
20077 +}
20078 +
20079 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20080 +{
20081 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20082 +
20083 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20084 +               return -EFAULT;
20085 +
20086 +       switch (vc_data.type) {
20087 +       case NXA_TYPE_ADDR:
20088 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20089 +               /* fallthrough */
20090 +       case NXA_TYPE_MASK:
20091 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20092 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20093 +       default:
20094 +               return -EINVAL;
20095 +       }
20096 +       return 0;
20097 +}
20098 +
20099 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20100 +{
20101 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20102 +
20103 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20104 +               return -EFAULT;
20105 +
20106 +       switch (vc_data.type) {
20107 +       case NXA_TYPE_ADDR:
20108 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20109 +               /* fallthrough */
20110 +       case NXA_TYPE_MASK:
20111 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20112 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20113 +       case NXA_TYPE_ANY:
20114 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20115 +       default:
20116 +               return -EINVAL;
20117 +       }
20118 +       return 0;
20119 +}
20120 +
20121 +#endif /* CONFIG_IPV6 */
20122 +
20123 +
20124 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20125 +{
20126 +       struct vcmd_net_flags_v0 vc_data;
20127 +
20128 +       vc_data.flagword = nxi->nx_flags;
20129 +
20130 +       /* special STATE flag handling */
20131 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20132 +
20133 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20134 +               return -EFAULT;
20135 +       return 0;
20136 +}
20137 +
20138 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20139 +{
20140 +       struct vcmd_net_flags_v0 vc_data;
20141 +       uint64_t mask, trigger;
20142 +
20143 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20144 +               return -EFAULT;
20145 +
20146 +       /* special STATE flag handling */
20147 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20148 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20149 +
20150 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20151 +               vc_data.flagword, mask);
20152 +       if (trigger & NXF_PERSISTENT)
20153 +               nx_update_persistent(nxi);
20154 +
20155 +       return 0;
20156 +}
20157 +
20158 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20159 +{
20160 +       struct vcmd_net_caps_v0 vc_data;
20161 +
20162 +       vc_data.ncaps = nxi->nx_ncaps;
20163 +       vc_data.cmask = ~0ULL;
20164 +
20165 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20166 +               return -EFAULT;
20167 +       return 0;
20168 +}
20169 +
20170 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20171 +{
20172 +       struct vcmd_net_caps_v0 vc_data;
20173 +
20174 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20175 +               return -EFAULT;
20176 +
20177 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20178 +               vc_data.ncaps, vc_data.cmask);
20179 +       return 0;
20180 +}
20181 +
20182 +
20183 +#include <linux/module.h>
20184 +
20185 +module_init(init_network);
20186 +
20187 +EXPORT_SYMBOL_GPL(free_nx_info);
20188 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20189 +
20190 diff -NurpP --minimal linux-3.13.10/kernel/vserver/proc.c linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c
20191 --- linux-3.13.10/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20192 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c      2014-02-01 01:21:49.000000000 +0000
20193 @@ -0,0 +1,1097 @@
20194 +/*
20195 + *  linux/kernel/vserver/proc.c
20196 + *
20197 + *  Virtual Context Support
20198 + *
20199 + *  Copyright (C) 2003-2011  Herbert Pötzl
20200 + *
20201 + *  V0.01  basic structure
20202 + *  V0.02  adaptation vs1.3.0
20203 + *  V0.03  proc permissions
20204 + *  V0.04  locking/generic
20205 + *  V0.05  next generation procfs
20206 + *  V0.06  inode validation
20207 + *  V0.07  generic rewrite vid
20208 + *  V0.08  remove inode type
20209 + *  V0.09  added u/wmask info
20210 + *
20211 + */
20212 +
20213 +#include <linux/proc_fs.h>
20214 +#include <linux/fs_struct.h>
20215 +#include <linux/mount.h>
20216 +#include <linux/namei.h>
20217 +#include <asm/unistd.h>
20218 +
20219 +#include <linux/vs_context.h>
20220 +#include <linux/vs_network.h>
20221 +#include <linux/vs_cvirt.h>
20222 +
20223 +#include <linux/in.h>
20224 +#include <linux/inetdevice.h>
20225 +#include <linux/vs_inet.h>
20226 +#include <linux/vs_inet6.h>
20227 +
20228 +#include <linux/vserver/global.h>
20229 +
20230 +#include "cvirt_proc.h"
20231 +#include "cacct_proc.h"
20232 +#include "limit_proc.h"
20233 +#include "sched_proc.h"
20234 +#include "vci_config.h"
20235 +
20236 +#include <../../fs/proc/internal.h>
20237 +
20238 +
20239 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20240 +{
20241 +       unsigned __capi;
20242 +
20243 +       CAP_FOR_EACH_U32(__capi) {
20244 +               buffer += sprintf(buffer, "%08x",
20245 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20246 +       }
20247 +       return buffer;
20248 +}
20249 +
20250 +
20251 +static struct proc_dir_entry *proc_virtual;
20252 +
20253 +static struct proc_dir_entry *proc_virtnet;
20254 +
20255 +
20256 +/* first the actual feeds */
20257 +
20258 +
20259 +static int proc_vci(char *buffer)
20260 +{
20261 +       return sprintf(buffer,
20262 +               "VCIVersion:\t%04x:%04x\n"
20263 +               "VCISyscall:\t%d\n"
20264 +               "VCIKernel:\t%08x\n",
20265 +               VCI_VERSION >> 16,
20266 +               VCI_VERSION & 0xFFFF,
20267 +               __NR_vserver,
20268 +               vci_kernel_config());
20269 +}
20270 +
20271 +static int proc_virtual_info(char *buffer)
20272 +{
20273 +       return proc_vci(buffer);
20274 +}
20275 +
20276 +static int proc_virtual_status(char *buffer)
20277 +{
20278 +       return sprintf(buffer,
20279 +               "#CTotal:\t%d\n"
20280 +               "#CActive:\t%d\n"
20281 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20282 +               "#InitTask:\t%d\t%d %d\n",
20283 +               atomic_read(&vx_global_ctotal),
20284 +               atomic_read(&vx_global_cactive),
20285 +               atomic_read(&vs_global_nsproxy),
20286 +               atomic_read(&vs_global_fs),
20287 +               atomic_read(&vs_global_mnt_ns),
20288 +               atomic_read(&vs_global_uts_ns),
20289 +               atomic_read(&nr_ipc_ns),
20290 +               atomic_read(&vs_global_user_ns),
20291 +               atomic_read(&vs_global_pid_ns),
20292 +               atomic_read(&init_task.usage),
20293 +               atomic_read(&init_task.nsproxy->count),
20294 +               init_task.fs->users);
20295 +}
20296 +
20297 +
20298 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20299 +{
20300 +       int length;
20301 +
20302 +       length = sprintf(buffer,
20303 +               "ID:\t%d\n"
20304 +               "Info:\t%p\n"
20305 +               "Init:\t%d\n"
20306 +               "OOM:\t%lld\n",
20307 +               vxi->vx_id,
20308 +               vxi,
20309 +               vxi->vx_initpid,
20310 +               vxi->vx_badness_bias);
20311 +       return length;
20312 +}
20313 +
20314 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20315 +{
20316 +       char *orig = buffer;
20317 +
20318 +       buffer += sprintf(buffer,
20319 +               "UseCnt:\t%d\n"
20320 +               "Tasks:\t%d\n"
20321 +               "Flags:\t%016llx\n",
20322 +               atomic_read(&vxi->vx_usecnt),
20323 +               atomic_read(&vxi->vx_tasks),
20324 +               (unsigned long long)vxi->vx_flags);
20325 +
20326 +       buffer += sprintf(buffer, "BCaps:\t");
20327 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20328 +       buffer += sprintf(buffer, "\n");
20329 +
20330 +       buffer += sprintf(buffer,
20331 +               "CCaps:\t%016llx\n"
20332 +               "Umask:\t%16llx\n"
20333 +               "Wmask:\t%16llx\n"
20334 +               "Spaces:\t%08lx %08lx\n",
20335 +               (unsigned long long)vxi->vx_ccaps,
20336 +               (unsigned long long)vxi->vx_umask,
20337 +               (unsigned long long)vxi->vx_wmask,
20338 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20339 +       return buffer - orig;
20340 +}
20341 +
20342 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20343 +{
20344 +       return vx_info_proc_limit(&vxi->limit, buffer);
20345 +}
20346 +
20347 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20348 +{
20349 +       int cpu, length;
20350 +
20351 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20352 +       for_each_online_cpu(cpu) {
20353 +               length += vx_info_proc_sched_pc(
20354 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20355 +                       buffer + length, cpu);
20356 +       }
20357 +       return length;
20358 +}
20359 +
20360 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20361 +{
20362 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20363 +}
20364 +
20365 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20366 +{
20367 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20368 +}
20369 +
20370 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20371 +{
20372 +       int cpu, length;
20373 +
20374 +       vx_update_load(vxi);
20375 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20376 +       for_each_online_cpu(cpu) {
20377 +               length += vx_info_proc_cvirt_pc(
20378 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20379 +                       buffer + length, cpu);
20380 +       }
20381 +       return length;
20382 +}
20383 +
20384 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20385 +{
20386 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20387 +}
20388 +
20389 +
20390 +static int proc_virtnet_info(char *buffer)
20391 +{
20392 +       return proc_vci(buffer);
20393 +}
20394 +
20395 +static int proc_virtnet_status(char *buffer)
20396 +{
20397 +       return sprintf(buffer,
20398 +               "#CTotal:\t%d\n"
20399 +               "#CActive:\t%d\n",
20400 +               atomic_read(&nx_global_ctotal),
20401 +               atomic_read(&nx_global_cactive));
20402 +}
20403 +
20404 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20405 +{
20406 +       struct nx_addr_v4 *v4a;
20407 +#ifdef CONFIG_IPV6
20408 +       struct nx_addr_v6 *v6a;
20409 +#endif
20410 +       int length, i;
20411 +
20412 +       length = sprintf(buffer,
20413 +               "ID:\t%d\n"
20414 +               "Info:\t%p\n"
20415 +               "Bcast:\t" NIPQUAD_FMT "\n"
20416 +               "Lback:\t" NIPQUAD_FMT "\n",
20417 +               nxi->nx_id,
20418 +               nxi,
20419 +               NIPQUAD(nxi->v4_bcast.s_addr),
20420 +               NIPQUAD(nxi->v4_lback.s_addr));
20421 +
20422 +       if (!NX_IPV4(nxi))
20423 +               goto skip_v4;
20424 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20425 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20426 +                       i, NXAV4(v4a));
20427 +skip_v4:
20428 +#ifdef CONFIG_IPV6
20429 +       if (!NX_IPV6(nxi))
20430 +               goto skip_v6;
20431 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20432 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20433 +                       i, NXAV6(v6a));
20434 +skip_v6:
20435 +#endif
20436 +       return length;
20437 +}
20438 +
20439 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20440 +{
20441 +       int length;
20442 +
20443 +       length = sprintf(buffer,
20444 +               "UseCnt:\t%d\n"
20445 +               "Tasks:\t%d\n"
20446 +               "Flags:\t%016llx\n"
20447 +               "NCaps:\t%016llx\n",
20448 +               atomic_read(&nxi->nx_usecnt),
20449 +               atomic_read(&nxi->nx_tasks),
20450 +               (unsigned long long)nxi->nx_flags,
20451 +               (unsigned long long)nxi->nx_ncaps);
20452 +       return length;
20453 +}
20454 +
20455 +
20456 +
20457 +/* here the inode helpers */
20458 +
20459 +struct vs_entry {
20460 +       int len;
20461 +       char *name;
20462 +       mode_t mode;
20463 +       struct inode_operations *iop;
20464 +       struct file_operations *fop;
20465 +       union proc_op op;
20466 +};
20467 +
20468 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20469 +{
20470 +       struct inode *inode = new_inode(sb);
20471 +
20472 +       if (!inode)
20473 +               goto out;
20474 +
20475 +       inode->i_mode = p->mode;
20476 +       if (p->iop)
20477 +               inode->i_op = p->iop;
20478 +       if (p->fop)
20479 +               inode->i_fop = p->fop;
20480 +
20481 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20482 +       inode->i_flags |= S_IMMUTABLE;
20483 +
20484 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20485 +
20486 +       i_uid_write(inode, 0);
20487 +       i_gid_write(inode, 0);
20488 +       i_tag_write(inode, 0);
20489 +out:
20490 +       return inode;
20491 +}
20492 +
20493 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20494 +       struct dentry *dentry, int id, void *ptr)
20495 +{
20496 +       struct vs_entry *p = ptr;
20497 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20498 +       struct dentry *error = ERR_PTR(-EINVAL);
20499 +
20500 +       if (!inode)
20501 +               goto out;
20502 +
20503 +       PROC_I(inode)->op = p->op;
20504 +       PROC_I(inode)->fd = id;
20505 +       d_add(dentry, inode);
20506 +       error = NULL;
20507 +out:
20508 +       return error;
20509 +}
20510 +
20511 +/* Lookups */
20512 +
20513 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20514 +
20515 +
20516 +/*
20517 + * Fill a directory entry.
20518 + *
20519 + * If possible create the dcache entry and derive our inode number and
20520 + * file type from dcache entry.
20521 + *
20522 + * Since all of the proc inode numbers are dynamically generated, the inode
20523 + * numbers do not exist until the inode is cache.  This means creating the
20524 + * the dcache entry in iterate is necessary to keep the inode numbers
20525 + * reported by iterate in sync with the inode numbers reported
20526 + * by stat.
20527 + */
20528 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20529 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20530 +{
20531 +       struct dentry *child, *dir = filp->f_dentry;
20532 +       struct inode *inode;
20533 +       struct qstr qname;
20534 +       ino_t ino = 0;
20535 +       unsigned type = DT_UNKNOWN;
20536 +
20537 +       qname.name = name;
20538 +       qname.len  = len;
20539 +       qname.hash = full_name_hash(name, len);
20540 +
20541 +       child = d_lookup(dir, &qname);
20542 +       if (!child) {
20543 +               struct dentry *new;
20544 +               new = d_alloc(dir, &qname);
20545 +               if (new) {
20546 +                       child = instantiate(dir->d_inode, new, id, ptr);
20547 +                       if (child)
20548 +                               dput(new);
20549 +                       else
20550 +                               child = new;
20551 +               }
20552 +       }
20553 +       if (!child || IS_ERR(child) || !child->d_inode)
20554 +               goto end_instantiate;
20555 +       inode = child->d_inode;
20556 +       if (inode) {
20557 +               ino = inode->i_ino;
20558 +               type = inode->i_mode >> 12;
20559 +       }
20560 +       dput(child);
20561 +end_instantiate:
20562 +       if (!ino)
20563 +               ino = 1;
20564 +       return !dir_emit(ctx, name, len, ino, type);
20565 +}
20566 +
20567 +
20568 +
20569 +/* get and revalidate vx_info/xid */
20570 +
20571 +static inline
20572 +struct vx_info *get_proc_vx_info(struct inode *inode)
20573 +{
20574 +       return lookup_vx_info(PROC_I(inode)->fd);
20575 +}
20576 +
20577 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20578 +{
20579 +       struct inode *inode = dentry->d_inode;
20580 +       vxid_t xid = PROC_I(inode)->fd;
20581 +
20582 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20583 +               return -ECHILD;
20584 +
20585 +       if (!xid || xid_is_hashed(xid))
20586 +               return 1;
20587 +       d_drop(dentry);
20588 +       return 0;
20589 +}
20590 +
20591 +
20592 +/* get and revalidate nx_info/nid */
20593 +
20594 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20595 +{
20596 +       struct inode *inode = dentry->d_inode;
20597 +       vnid_t nid = PROC_I(inode)->fd;
20598 +
20599 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20600 +               return -ECHILD;
20601 +
20602 +       if (!nid || nid_is_hashed(nid))
20603 +               return 1;
20604 +       d_drop(dentry);
20605 +       return 0;
20606 +}
20607 +
20608 +
20609 +
20610 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20611 +
20612 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20613 +                         size_t count, loff_t *ppos)
20614 +{
20615 +       struct inode *inode = file->f_dentry->d_inode;
20616 +       unsigned long page;
20617 +       ssize_t length = 0;
20618 +
20619 +       if (count > PROC_BLOCK_SIZE)
20620 +               count = PROC_BLOCK_SIZE;
20621 +
20622 +       /* fade that out as soon as stable */
20623 +       WARN_ON(PROC_I(inode)->fd);
20624 +
20625 +       if (!(page = __get_free_page(GFP_KERNEL)))
20626 +               return -ENOMEM;
20627 +
20628 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20629 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20630 +
20631 +       if (length >= 0)
20632 +               length = simple_read_from_buffer(buf, count, ppos,
20633 +                       (char *)page, length);
20634 +
20635 +       free_page(page);
20636 +       return length;
20637 +}
20638 +
20639 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20640 +                         size_t count, loff_t *ppos)
20641 +{
20642 +       struct inode *inode = file->f_dentry->d_inode;
20643 +       struct vx_info *vxi = NULL;
20644 +       vxid_t xid = PROC_I(inode)->fd;
20645 +       unsigned long page;
20646 +       ssize_t length = 0;
20647 +
20648 +       if (count > PROC_BLOCK_SIZE)
20649 +               count = PROC_BLOCK_SIZE;
20650 +
20651 +       /* fade that out as soon as stable */
20652 +       WARN_ON(!xid);
20653 +       vxi = lookup_vx_info(xid);
20654 +       if (!vxi)
20655 +               goto out;
20656 +
20657 +       length = -ENOMEM;
20658 +       if (!(page = __get_free_page(GFP_KERNEL)))
20659 +               goto out_put;
20660 +
20661 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20662 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20663 +
20664 +       if (length >= 0)
20665 +               length = simple_read_from_buffer(buf, count, ppos,
20666 +                       (char *)page, length);
20667 +
20668 +       free_page(page);
20669 +out_put:
20670 +       put_vx_info(vxi);
20671 +out:
20672 +       return length;
20673 +}
20674 +
20675 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20676 +                         size_t count, loff_t *ppos)
20677 +{
20678 +       struct inode *inode = file->f_dentry->d_inode;
20679 +       struct nx_info *nxi = NULL;
20680 +       vnid_t nid = PROC_I(inode)->fd;
20681 +       unsigned long page;
20682 +       ssize_t length = 0;
20683 +
20684 +       if (count > PROC_BLOCK_SIZE)
20685 +               count = PROC_BLOCK_SIZE;
20686 +
20687 +       /* fade that out as soon as stable */
20688 +       WARN_ON(!nid);
20689 +       nxi = lookup_nx_info(nid);
20690 +       if (!nxi)
20691 +               goto out;
20692 +
20693 +       length = -ENOMEM;
20694 +       if (!(page = __get_free_page(GFP_KERNEL)))
20695 +               goto out_put;
20696 +
20697 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20698 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20699 +
20700 +       if (length >= 0)
20701 +               length = simple_read_from_buffer(buf, count, ppos,
20702 +                       (char *)page, length);
20703 +
20704 +       free_page(page);
20705 +out_put:
20706 +       put_nx_info(nxi);
20707 +out:
20708 +       return length;
20709 +}
20710 +
20711 +
20712 +
20713 +/* here comes the lower level */
20714 +
20715 +
20716 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20717 +       .len  = sizeof(NAME) - 1,       \
20718 +       .name = (NAME),                 \
20719 +       .mode = MODE,                   \
20720 +       .iop  = IOP,                    \
20721 +       .fop  = FOP,                    \
20722 +       .op   = OP,                     \
20723 +}
20724 +
20725 +
20726 +#define DIR(NAME, MODE, OTYPE)                         \
20727 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20728 +               &proc_ ## OTYPE ## _inode_operations,   \
20729 +               &proc_ ## OTYPE ## _file_operations, { } )
20730 +
20731 +#define INF(NAME, MODE, OTYPE)                         \
20732 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20733 +               &proc_vs_info_file_operations,          \
20734 +               { .proc_vs_read = &proc_##OTYPE } )
20735 +
20736 +#define VINF(NAME, MODE, OTYPE)                                \
20737 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20738 +               &proc_vx_info_file_operations,          \
20739 +               { .proc_vxi_read = &proc_##OTYPE } )
20740 +
20741 +#define NINF(NAME, MODE, OTYPE)                                \
20742 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20743 +               &proc_nx_info_file_operations,          \
20744 +               { .proc_nxi_read = &proc_##OTYPE } )
20745 +
20746 +
20747 +static struct file_operations proc_vs_info_file_operations = {
20748 +       .read =         proc_vs_info_read,
20749 +};
20750 +
20751 +static struct file_operations proc_vx_info_file_operations = {
20752 +       .read =         proc_vx_info_read,
20753 +};
20754 +
20755 +static struct dentry_operations proc_xid_dentry_operations = {
20756 +       .d_revalidate = proc_xid_revalidate,
20757 +};
20758 +
20759 +static struct vs_entry vx_base_stuff[] = {
20760 +       VINF("info",    S_IRUGO, vxi_info),
20761 +       VINF("status",  S_IRUGO, vxi_status),
20762 +       VINF("limit",   S_IRUGO, vxi_limit),
20763 +       VINF("sched",   S_IRUGO, vxi_sched),
20764 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20765 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20766 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20767 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20768 +       {}
20769 +};
20770 +
20771 +
20772 +
20773 +
20774 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20775 +       struct dentry *dentry, int id, void *ptr)
20776 +{
20777 +       dentry->d_op = &proc_xid_dentry_operations;
20778 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20779 +}
20780 +
20781 +static struct dentry *proc_xid_lookup(struct inode *dir,
20782 +       struct dentry *dentry, unsigned int flags)
20783 +{
20784 +       struct vs_entry *p = vx_base_stuff;
20785 +       struct dentry *error = ERR_PTR(-ENOENT);
20786 +
20787 +       for (; p->name; p++) {
20788 +               if (p->len != dentry->d_name.len)
20789 +                       continue;
20790 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20791 +                       break;
20792 +       }
20793 +       if (!p->name)
20794 +               goto out;
20795 +
20796 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20797 +out:
20798 +       return error;
20799 +}
20800 +
20801 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20802 +{
20803 +       struct dentry *dentry = filp->f_dentry;
20804 +       struct inode *inode = dentry->d_inode;
20805 +       struct vs_entry *p = vx_base_stuff;
20806 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20807 +       int index;
20808 +       u64 ino;
20809 +
20810 +       switch (ctx->pos) {
20811 +       case 0:
20812 +               ino = inode->i_ino;
20813 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20814 +                       goto out;
20815 +               ctx->pos++;
20816 +               /* fall through */
20817 +       case 1:
20818 +               ino = parent_ino(dentry);
20819 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20820 +                       goto out;
20821 +               ctx->pos++;
20822 +               /* fall through */
20823 +       default:
20824 +               index = ctx->pos - 2;
20825 +               if (index >= size)
20826 +                       goto out;
20827 +               for (p += index; p->name; p++) {
20828 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20829 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20830 +                               goto out;
20831 +                       ctx->pos++;
20832 +               }
20833 +       }
20834 +out:
20835 +       return 1;
20836 +}
20837 +
20838 +
20839 +
20840 +static struct file_operations proc_nx_info_file_operations = {
20841 +       .read =         proc_nx_info_read,
20842 +};
20843 +
20844 +static struct dentry_operations proc_nid_dentry_operations = {
20845 +       .d_revalidate = proc_nid_revalidate,
20846 +};
20847 +
20848 +static struct vs_entry nx_base_stuff[] = {
20849 +       NINF("info",    S_IRUGO, nxi_info),
20850 +       NINF("status",  S_IRUGO, nxi_status),
20851 +       {}
20852 +};
20853 +
20854 +
20855 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20856 +       struct dentry *dentry, int id, void *ptr)
20857 +{
20858 +       dentry->d_op = &proc_nid_dentry_operations;
20859 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20860 +}
20861 +
20862 +static struct dentry *proc_nid_lookup(struct inode *dir,
20863 +       struct dentry *dentry, unsigned int flags)
20864 +{
20865 +       struct vs_entry *p = nx_base_stuff;
20866 +       struct dentry *error = ERR_PTR(-ENOENT);
20867 +
20868 +       for (; p->name; p++) {
20869 +               if (p->len != dentry->d_name.len)
20870 +                       continue;
20871 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20872 +                       break;
20873 +       }
20874 +       if (!p->name)
20875 +               goto out;
20876 +
20877 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20878 +out:
20879 +       return error;
20880 +}
20881 +
20882 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20883 +{
20884 +       struct dentry *dentry = filp->f_dentry;
20885 +       struct inode *inode = dentry->d_inode;
20886 +       struct vs_entry *p = nx_base_stuff;
20887 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20888 +       int index;
20889 +       u64 ino;
20890 +
20891 +       switch (ctx->pos) {
20892 +       case 0:
20893 +               ino = inode->i_ino;
20894 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20895 +                       goto out;
20896 +               ctx->pos++;
20897 +               /* fall through */
20898 +       case 1:
20899 +               ino = parent_ino(dentry);
20900 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20901 +                       goto out;
20902 +               ctx->pos++;
20903 +               /* fall through */
20904 +       default:
20905 +               index = ctx->pos - 2;
20906 +               if (index >= size)
20907 +                       goto out;
20908 +               for (p += index; p->name; p++) {
20909 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20910 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20911 +                               goto out;
20912 +                       ctx->pos++;
20913 +               }
20914 +       }
20915 +out:
20916 +       return 1;
20917 +}
20918 +
20919 +
20920 +#define MAX_MULBY10    ((~0U - 9) / 10)
20921 +
20922 +static inline int atovid(const char *str, int len)
20923 +{
20924 +       int vid, c;
20925 +
20926 +       vid = 0;
20927 +       while (len-- > 0) {
20928 +               c = *str - '0';
20929 +               str++;
20930 +               if (c > 9)
20931 +                       return -1;
20932 +               if (vid >= MAX_MULBY10)
20933 +                       return -1;
20934 +               vid *= 10;
20935 +               vid += c;
20936 +               if (!vid)
20937 +                       return -1;
20938 +       }
20939 +       return vid;
20940 +}
20941 +
20942 +/* now the upper level (virtual) */
20943 +
20944 +
20945 +static struct file_operations proc_xid_file_operations = {
20946 +       .read =         generic_read_dir,
20947 +       .iterate =      proc_xid_iterate,
20948 +};
20949 +
20950 +static struct inode_operations proc_xid_inode_operations = {
20951 +       .lookup =       proc_xid_lookup,
20952 +};
20953 +
20954 +static struct vs_entry vx_virtual_stuff[] = {
20955 +       INF("info",     S_IRUGO, virtual_info),
20956 +       INF("status",   S_IRUGO, virtual_status),
20957 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
20958 +};
20959 +
20960 +
20961 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20962 +       struct dentry *dentry, unsigned int flags)
20963 +{
20964 +       struct vs_entry *p = vx_virtual_stuff;
20965 +       struct dentry *error = ERR_PTR(-ENOENT);
20966 +       int id = 0;
20967 +
20968 +       for (; p->name; p++) {
20969 +               if (p->len != dentry->d_name.len)
20970 +                       continue;
20971 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20972 +                       break;
20973 +       }
20974 +       if (p->name)
20975 +               goto instantiate;
20976 +
20977 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20978 +       if ((id < 0) || !xid_is_hashed(id))
20979 +               goto out;
20980 +
20981 +instantiate:
20982 +       error = proc_xid_instantiate(dir, dentry, id, p);
20983 +out:
20984 +       return error;
20985 +}
20986 +
20987 +static struct file_operations proc_nid_file_operations = {
20988 +       .read =         generic_read_dir,
20989 +       .iterate =      proc_nid_iterate,
20990 +};
20991 +
20992 +static struct inode_operations proc_nid_inode_operations = {
20993 +       .lookup =       proc_nid_lookup,
20994 +};
20995 +
20996 +static struct vs_entry nx_virtnet_stuff[] = {
20997 +       INF("info",     S_IRUGO, virtnet_info),
20998 +       INF("status",   S_IRUGO, virtnet_status),
20999 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21000 +};
21001 +
21002 +
21003 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21004 +       struct dentry *dentry, unsigned int flags)
21005 +{
21006 +       struct vs_entry *p = nx_virtnet_stuff;
21007 +       struct dentry *error = ERR_PTR(-ENOENT);
21008 +       int id = 0;
21009 +
21010 +       for (; p->name; p++) {
21011 +               if (p->len != dentry->d_name.len)
21012 +                       continue;
21013 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21014 +                       break;
21015 +       }
21016 +       if (p->name)
21017 +               goto instantiate;
21018 +
21019 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21020 +       if ((id < 0) || !nid_is_hashed(id))
21021 +               goto out;
21022 +
21023 +instantiate:
21024 +       error = proc_nid_instantiate(dir, dentry, id, p);
21025 +out:
21026 +       return error;
21027 +}
21028 +
21029 +
21030 +#define PROC_MAXVIDS 32
21031 +
21032 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21033 +{
21034 +       struct dentry *dentry = filp->f_dentry;
21035 +       struct inode *inode = dentry->d_inode;
21036 +       struct vs_entry *p = vx_virtual_stuff;
21037 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21038 +       int index;
21039 +       unsigned int xid_array[PROC_MAXVIDS];
21040 +       char buf[PROC_NUMBUF];
21041 +       unsigned int nr_xids, i;
21042 +       u64 ino;
21043 +
21044 +       switch (ctx->pos) {
21045 +       case 0:
21046 +               ino = inode->i_ino;
21047 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21048 +                       goto out;
21049 +               ctx->pos++;
21050 +               /* fall through */
21051 +       case 1:
21052 +               ino = parent_ino(dentry);
21053 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21054 +                       goto out;
21055 +               ctx->pos++;
21056 +               /* fall through */
21057 +       default:
21058 +               index = ctx->pos - 2;
21059 +               if (index >= size)
21060 +                       goto entries;
21061 +               for (p += index; p->name; p++) {
21062 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21063 +                               vs_proc_instantiate, 0, p))
21064 +                               goto out;
21065 +                       ctx->pos++;
21066 +               }
21067 +       entries:
21068 +               index = ctx->pos - size;
21069 +               p = &vx_virtual_stuff[size - 1];
21070 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21071 +               for (i = 0; i < nr_xids; i++) {
21072 +                       int n, xid = xid_array[i];
21073 +                       unsigned int j = PROC_NUMBUF;
21074 +
21075 +                       n = xid;
21076 +                       do
21077 +                               buf[--j] = '0' + (n % 10);
21078 +                       while (n /= 10);
21079 +
21080 +                       if (vx_proc_fill_cache(filp, ctx,
21081 +                               buf + j, PROC_NUMBUF - j,
21082 +                               vs_proc_instantiate, xid, p))
21083 +                               goto out;
21084 +                       ctx->pos++;
21085 +               }
21086 +       }
21087 +out:
21088 +       return 0;
21089 +}
21090 +
21091 +static int proc_virtual_getattr(struct vfsmount *mnt,
21092 +       struct dentry *dentry, struct kstat *stat)
21093 +{
21094 +       struct inode *inode = dentry->d_inode;
21095 +
21096 +       generic_fillattr(inode, stat);
21097 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21098 +       return 0;
21099 +}
21100 +
21101 +static struct file_operations proc_virtual_dir_operations = {
21102 +       .read =         generic_read_dir,
21103 +       .iterate =      proc_virtual_iterate,
21104 +};
21105 +
21106 +static struct inode_operations proc_virtual_dir_inode_operations = {
21107 +       .getattr =      proc_virtual_getattr,
21108 +       .lookup =       proc_virtual_lookup,
21109 +};
21110 +
21111 +
21112 +
21113 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21114 +{
21115 +       struct dentry *dentry = filp->f_dentry;
21116 +       struct inode *inode = dentry->d_inode;
21117 +       struct vs_entry *p = nx_virtnet_stuff;
21118 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21119 +       int index;
21120 +       unsigned int nid_array[PROC_MAXVIDS];
21121 +       char buf[PROC_NUMBUF];
21122 +       unsigned int nr_nids, i;
21123 +       u64 ino;
21124 +
21125 +       switch (ctx->pos) {
21126 +       case 0:
21127 +               ino = inode->i_ino;
21128 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21129 +                       goto out;
21130 +               ctx->pos++;
21131 +               /* fall through */
21132 +       case 1:
21133 +               ino = parent_ino(dentry);
21134 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21135 +                       goto out;
21136 +               ctx->pos++;
21137 +               /* fall through */
21138 +       default:
21139 +               index = ctx->pos - 2;
21140 +               if (index >= size)
21141 +                       goto entries;
21142 +               for (p += index; p->name; p++) {
21143 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21144 +                               vs_proc_instantiate, 0, p))
21145 +                               goto out;
21146 +                       ctx->pos++;
21147 +               }
21148 +       entries:
21149 +               index = ctx->pos - size;
21150 +               p = &nx_virtnet_stuff[size - 1];
21151 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21152 +               for (i = 0; i < nr_nids; i++) {
21153 +                       int n, nid = nid_array[i];
21154 +                       unsigned int j = PROC_NUMBUF;
21155 +
21156 +                       n = nid;
21157 +                       do
21158 +                               buf[--j] = '0' + (n % 10);
21159 +                       while (n /= 10);
21160 +
21161 +                       if (vx_proc_fill_cache(filp, ctx,
21162 +                               buf + j, PROC_NUMBUF - j,
21163 +                               vs_proc_instantiate, nid, p))
21164 +                               goto out;
21165 +                       ctx->pos++;
21166 +               }
21167 +       }
21168 +out:
21169 +       return 0;
21170 +}
21171 +
21172 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21173 +       struct dentry *dentry, struct kstat *stat)
21174 +{
21175 +       struct inode *inode = dentry->d_inode;
21176 +
21177 +       generic_fillattr(inode, stat);
21178 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21179 +       return 0;
21180 +}
21181 +
21182 +static struct file_operations proc_virtnet_dir_operations = {
21183 +       .read =         generic_read_dir,
21184 +       .iterate =      proc_virtnet_iterate,
21185 +};
21186 +
21187 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21188 +       .getattr =      proc_virtnet_getattr,
21189 +       .lookup =       proc_virtnet_lookup,
21190 +};
21191 +
21192 +
21193 +
21194 +void proc_vx_init(void)
21195 +{
21196 +       struct proc_dir_entry *ent;
21197 +
21198 +       ent = proc_mkdir("virtual", 0);
21199 +       if (ent) {
21200 +               ent->proc_fops = &proc_virtual_dir_operations;
21201 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21202 +       }
21203 +       proc_virtual = ent;
21204 +
21205 +       ent = proc_mkdir("virtnet", 0);
21206 +       if (ent) {
21207 +               ent->proc_fops = &proc_virtnet_dir_operations;
21208 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21209 +       }
21210 +       proc_virtnet = ent;
21211 +}
21212 +
21213 +
21214 +
21215 +
21216 +/* per pid info */
21217 +
21218 +
21219 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21220 +{
21221 +       struct vx_info *vxi;
21222 +       char *orig = buffer;
21223 +
21224 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21225 +
21226 +       vxi = task_get_vx_info(p);
21227 +       if (!vxi)
21228 +               goto out;
21229 +
21230 +       buffer += sprintf(buffer, "BCaps:\t");
21231 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21232 +       buffer += sprintf(buffer, "\n");
21233 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21234 +               (unsigned long long)vxi->vx_ccaps);
21235 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21236 +               (unsigned long long)vxi->vx_flags);
21237 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21238 +
21239 +       put_vx_info(vxi);
21240 +out:
21241 +       return buffer - orig;
21242 +}
21243 +
21244 +
21245 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21246 +{
21247 +       struct nx_info *nxi;
21248 +       struct nx_addr_v4 *v4a;
21249 +#ifdef CONFIG_IPV6
21250 +       struct nx_addr_v6 *v6a;
21251 +#endif
21252 +       char *orig = buffer;
21253 +       int i;
21254 +
21255 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21256 +
21257 +       nxi = task_get_nx_info(p);
21258 +       if (!nxi)
21259 +               goto out;
21260 +
21261 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21262 +               (unsigned long long)nxi->nx_ncaps);
21263 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21264 +               (unsigned long long)nxi->nx_flags);
21265 +
21266 +       buffer += sprintf(buffer,
21267 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21268 +               NIPQUAD(nxi->v4_bcast.s_addr));
21269 +       buffer += sprintf (buffer,
21270 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21271 +               NIPQUAD(nxi->v4_lback.s_addr));
21272 +       if (!NX_IPV4(nxi))
21273 +               goto skip_v4;
21274 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21275 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21276 +                       i, NXAV4(v4a));
21277 +skip_v4:
21278 +#ifdef CONFIG_IPV6
21279 +       if (!NX_IPV6(nxi))
21280 +               goto skip_v6;
21281 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21282 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21283 +                       i, NXAV6(v6a));
21284 +skip_v6:
21285 +#endif
21286 +       put_nx_info(nxi);
21287 +out:
21288 +       return buffer - orig;
21289 +}
21290 +
21291 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c
21292 --- linux-3.13.10/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
21293 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c     2014-01-31 20:38:04.000000000 +0000
21294 @@ -0,0 +1,83 @@
21295 +/*
21296 + *  linux/kernel/vserver/sched.c
21297 + *
21298 + *  Virtual Server: Scheduler Support
21299 + *
21300 + *  Copyright (C) 2004-2010  Herbert Pötzl
21301 + *
21302 + *  V0.01  adapted Sam Vilains version to 2.6.3
21303 + *  V0.02  removed legacy interface
21304 + *  V0.03  changed vcmds to vxi arg
21305 + *  V0.04  removed older and legacy interfaces
21306 + *  V0.05  removed scheduler code/commands
21307 + *
21308 + */
21309 +
21310 +#include <linux/vs_context.h>
21311 +#include <linux/vs_sched.h>
21312 +#include <linux/cpumask.h>
21313 +#include <linux/vserver/sched_cmd.h>
21314 +
21315 +#include <asm/uaccess.h>
21316 +
21317 +
21318 +void vx_update_sched_param(struct _vx_sched *sched,
21319 +       struct _vx_sched_pc *sched_pc)
21320 +{
21321 +       sched_pc->prio_bias = sched->prio_bias;
21322 +}
21323 +
21324 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21325 +{
21326 +       int cpu;
21327 +
21328 +       if (data->prio_bias > MAX_PRIO_BIAS)
21329 +               data->prio_bias = MAX_PRIO_BIAS;
21330 +       if (data->prio_bias < MIN_PRIO_BIAS)
21331 +               data->prio_bias = MIN_PRIO_BIAS;
21332 +
21333 +       if (data->cpu_id != ~0) {
21334 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21335 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21336 +                       cpu_online_mask);
21337 +       } else
21338 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21339 +
21340 +       for_each_cpu_mask(cpu, vxi->sched.update)
21341 +               vx_update_sched_param(&vxi->sched,
21342 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21343 +       return 0;
21344 +}
21345 +
21346 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21347 +{
21348 +       struct vcmd_prio_bias vc_data;
21349 +
21350 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21351 +               return -EFAULT;
21352 +
21353 +       return do_set_prio_bias(vxi, &vc_data);
21354 +}
21355 +
21356 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21357 +{
21358 +       struct vcmd_prio_bias vc_data;
21359 +       struct _vx_sched_pc *pcd;
21360 +       int cpu;
21361 +
21362 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21363 +               return -EFAULT;
21364 +
21365 +       cpu = vc_data.cpu_id;
21366 +
21367 +       if (!cpu_possible(cpu))
21368 +               return -EINVAL;
21369 +
21370 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21371 +       vc_data.prio_bias = pcd->prio_bias;
21372 +
21373 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21374 +               return -EFAULT;
21375 +       return 0;
21376 +}
21377 +
21378 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
21379 --- linux-3.13.10/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21380 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h        2014-01-31 20:38:04.000000000 +0000
21381 @@ -0,0 +1,27 @@
21382 +
21383 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21384 +{
21385 +       /* scheduling; hard code starting values as constants */
21386 +       sched->prio_bias = 0;
21387 +}
21388 +
21389 +static inline
21390 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21391 +{
21392 +       sched_pc->prio_bias = 0;
21393 +
21394 +       sched_pc->user_ticks = 0;
21395 +       sched_pc->sys_ticks = 0;
21396 +       sched_pc->hold_ticks = 0;
21397 +}
21398 +
21399 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21400 +{
21401 +       return;
21402 +}
21403 +
21404 +static inline
21405 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21406 +{
21407 +       return;
21408 +}
21409 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
21410 --- linux-3.13.10/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21411 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h        2014-01-31 20:38:04.000000000 +0000
21412 @@ -0,0 +1,32 @@
21413 +#ifndef _VX_SCHED_PROC_H
21414 +#define _VX_SCHED_PROC_H
21415 +
21416 +
21417 +static inline
21418 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21419 +{
21420 +       int length = 0;
21421 +
21422 +       length += sprintf(buffer,
21423 +               "PrioBias:\t%8d\n",
21424 +               sched->prio_bias);
21425 +       return length;
21426 +}
21427 +
21428 +static inline
21429 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21430 +       char *buffer, int cpu)
21431 +{
21432 +       int length = 0;
21433 +
21434 +       length += sprintf(buffer + length,
21435 +               "cpu %d: %lld %lld %lld", cpu,
21436 +               (unsigned long long)sched_pc->user_ticks,
21437 +               (unsigned long long)sched_pc->sys_ticks,
21438 +               (unsigned long long)sched_pc->hold_ticks);
21439 +       length += sprintf(buffer + length,
21440 +               " %d\n", sched_pc->prio_bias);
21441 +       return length;
21442 +}
21443 +
21444 +#endif /* _VX_SCHED_PROC_H */
21445 diff -NurpP --minimal linux-3.13.10/kernel/vserver/signal.c linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c
21446 --- linux-3.13.10/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21447 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c    2014-01-31 20:38:04.000000000 +0000
21448 @@ -0,0 +1,134 @@
21449 +/*
21450 + *  linux/kernel/vserver/signal.c
21451 + *
21452 + *  Virtual Server: Signal Support
21453 + *
21454 + *  Copyright (C) 2003-2007  Herbert Pötzl
21455 + *
21456 + *  V0.01  broken out from vcontext V0.05
21457 + *  V0.02  changed vcmds to vxi arg
21458 + *  V0.03  adjusted siginfo for kill
21459 + *
21460 + */
21461 +
21462 +#include <asm/uaccess.h>
21463 +
21464 +#include <linux/vs_context.h>
21465 +#include <linux/vs_pid.h>
21466 +#include <linux/vserver/signal_cmd.h>
21467 +
21468 +
21469 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21470 +{
21471 +       int retval, count = 0;
21472 +       struct task_struct *p;
21473 +       struct siginfo *sip = SEND_SIG_PRIV;
21474 +
21475 +       retval = -ESRCH;
21476 +       vxdprintk(VXD_CBIT(misc, 4),
21477 +               "vx_info_kill(%p[#%d],%d,%d)*",
21478 +               vxi, vxi->vx_id, pid, sig);
21479 +       read_lock(&tasklist_lock);
21480 +       switch (pid) {
21481 +       case  0:
21482 +       case -1:
21483 +               for_each_process(p) {
21484 +                       int err = 0;
21485 +
21486 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21487 +                               (pid && vxi->vx_initpid == p->pid))
21488 +                               continue;
21489 +
21490 +                       err = group_send_sig_info(sig, sip, p);
21491 +                       ++count;
21492 +                       if (err != -EPERM)
21493 +                               retval = err;
21494 +               }
21495 +               break;
21496 +
21497 +       case 1:
21498 +               if (vxi->vx_initpid) {
21499 +                       pid = vxi->vx_initpid;
21500 +                       /* for now, only SIGINT to private init ... */
21501 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21502 +                               /* ... as long as there are tasks left */
21503 +                               (atomic_read(&vxi->vx_tasks) > 1))
21504 +                               sig = SIGINT;
21505 +               }
21506 +               /* fallthrough */
21507 +       default:
21508 +               rcu_read_lock();
21509 +               p = find_task_by_real_pid(pid);
21510 +               rcu_read_unlock();
21511 +               if (p) {
21512 +                       if (vx_task_xid(p) == vxi->vx_id)
21513 +                               retval = group_send_sig_info(sig, sip, p);
21514 +               }
21515 +               break;
21516 +       }
21517 +       read_unlock(&tasklist_lock);
21518 +       vxdprintk(VXD_CBIT(misc, 4),
21519 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21520 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21521 +       return retval;
21522 +}
21523 +
21524 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21525 +{
21526 +       struct vcmd_ctx_kill_v0 vc_data;
21527 +
21528 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21529 +               return -EFAULT;
21530 +
21531 +       /* special check to allow guest shutdown */
21532 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21533 +               /* forbid killall pid=0 when init is present */
21534 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21535 +               (vc_data.pid > 1)))
21536 +               return -EACCES;
21537 +
21538 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21539 +}
21540 +
21541 +
21542 +static int __wait_exit(struct vx_info *vxi)
21543 +{
21544 +       DECLARE_WAITQUEUE(wait, current);
21545 +       int ret = 0;
21546 +
21547 +       add_wait_queue(&vxi->vx_wait, &wait);
21548 +       set_current_state(TASK_INTERRUPTIBLE);
21549 +
21550 +wait:
21551 +       if (vx_info_state(vxi,
21552 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21553 +               goto out;
21554 +       if (signal_pending(current)) {
21555 +               ret = -ERESTARTSYS;
21556 +               goto out;
21557 +       }
21558 +       schedule();
21559 +       goto wait;
21560 +
21561 +out:
21562 +       set_current_state(TASK_RUNNING);
21563 +       remove_wait_queue(&vxi->vx_wait, &wait);
21564 +       return ret;
21565 +}
21566 +
21567 +
21568 +
21569 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21570 +{
21571 +       struct vcmd_wait_exit_v0 vc_data;
21572 +       int ret;
21573 +
21574 +       ret = __wait_exit(vxi);
21575 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21576 +       vc_data.exit_code = vxi->exit_code;
21577 +
21578 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21579 +               ret = -EFAULT;
21580 +       return ret;
21581 +}
21582 +
21583 diff -NurpP --minimal linux-3.13.10/kernel/vserver/space.c linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c
21584 --- linux-3.13.10/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21585 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c     2014-02-01 12:21:24.000000000 +0000
21586 @@ -0,0 +1,436 @@
21587 +/*
21588 + *  linux/kernel/vserver/space.c
21589 + *
21590 + *  Virtual Server: Context Space Support
21591 + *
21592 + *  Copyright (C) 2003-2010  Herbert Pötzl
21593 + *
21594 + *  V0.01  broken out from context.c 0.07
21595 + *  V0.02  added task locking for namespace
21596 + *  V0.03  broken out vx_enter_namespace
21597 + *  V0.04  added *space support and commands
21598 + *  V0.05  added credential support
21599 + *
21600 + */
21601 +
21602 +#include <linux/utsname.h>
21603 +#include <linux/nsproxy.h>
21604 +#include <linux/err.h>
21605 +#include <linux/fs_struct.h>
21606 +#include <linux/cred.h>
21607 +#include <asm/uaccess.h>
21608 +
21609 +#include <linux/vs_context.h>
21610 +#include <linux/vserver/space.h>
21611 +#include <linux/vserver/space_cmd.h>
21612 +
21613 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21614 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21615 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21616 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21617 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21618 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21619 +
21620 +
21621 +/* namespace functions */
21622 +
21623 +#include <linux/mnt_namespace.h>
21624 +#include <linux/user_namespace.h>
21625 +#include <linux/pid_namespace.h>
21626 +#include <linux/ipc_namespace.h>
21627 +#include <net/net_namespace.h>
21628 +#include "../fs/mount.h"
21629 +
21630 +
21631 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21632 +       .mask = CLONE_FS |
21633 +               CLONE_NEWNS |
21634 +#ifdef CONFIG_UTS_NS
21635 +               CLONE_NEWUTS |
21636 +#endif
21637 +#ifdef CONFIG_IPC_NS
21638 +               CLONE_NEWIPC |
21639 +#endif
21640 +#ifdef CONFIG_USER_NS
21641 +               CLONE_NEWUSER |
21642 +#endif
21643 +               0
21644 +};
21645 +
21646 +static const struct vcmd_space_mask_v1 space_mask = {
21647 +       .mask = CLONE_FS |
21648 +               CLONE_NEWNS |
21649 +#ifdef CONFIG_UTS_NS
21650 +               CLONE_NEWUTS |
21651 +#endif
21652 +#ifdef CONFIG_IPC_NS
21653 +               CLONE_NEWIPC |
21654 +#endif
21655 +#ifdef CONFIG_USER_NS
21656 +               CLONE_NEWUSER |
21657 +#endif
21658 +#ifdef CONFIG_PID_NS
21659 +               CLONE_NEWPID |
21660 +#endif
21661 +#ifdef CONFIG_NET_NS
21662 +               CLONE_NEWNET |
21663 +#endif
21664 +               0
21665 +};
21666 +
21667 +static const struct vcmd_space_mask_v1 default_space_mask = {
21668 +       .mask = CLONE_FS |
21669 +               CLONE_NEWNS |
21670 +#ifdef CONFIG_UTS_NS
21671 +               CLONE_NEWUTS |
21672 +#endif
21673 +#ifdef CONFIG_IPC_NS
21674 +               CLONE_NEWIPC |
21675 +#endif
21676 +#ifdef CONFIG_USER_NS
21677 +               CLONE_NEWUSER |
21678 +#endif
21679 +#ifdef CONFIG_PID_NS
21680 +//             CLONE_NEWPID |
21681 +#endif
21682 +               0
21683 +};
21684 +
21685 +/*
21686 + *     build a new nsproxy mix
21687 + *      assumes that both proxies are 'const'
21688 + *     does not touch nsproxy refcounts
21689 + *     will hold a reference on the result.
21690 + */
21691 +
21692 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21693 +       struct nsproxy *new_nsproxy, unsigned long mask)
21694 +{
21695 +       struct mnt_namespace *old_ns;
21696 +       struct uts_namespace *old_uts;
21697 +       struct ipc_namespace *old_ipc;
21698 +#ifdef CONFIG_PID_NS
21699 +       struct pid_namespace *old_pid;
21700 +#endif
21701 +#ifdef CONFIG_NET_NS
21702 +       struct net *old_net;
21703 +#endif
21704 +       struct nsproxy *nsproxy;
21705 +
21706 +       nsproxy = copy_nsproxy(old_nsproxy);
21707 +       if (!nsproxy)
21708 +               goto out;
21709 +
21710 +       if (mask & CLONE_NEWNS) {
21711 +               old_ns = nsproxy->mnt_ns;
21712 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21713 +               if (nsproxy->mnt_ns)
21714 +                       get_mnt_ns(nsproxy->mnt_ns);
21715 +       } else
21716 +               old_ns = NULL;
21717 +
21718 +       if (mask & CLONE_NEWUTS) {
21719 +               old_uts = nsproxy->uts_ns;
21720 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21721 +               if (nsproxy->uts_ns)
21722 +                       get_uts_ns(nsproxy->uts_ns);
21723 +       } else
21724 +               old_uts = NULL;
21725 +
21726 +       if (mask & CLONE_NEWIPC) {
21727 +               old_ipc = nsproxy->ipc_ns;
21728 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21729 +               if (nsproxy->ipc_ns)
21730 +                       get_ipc_ns(nsproxy->ipc_ns);
21731 +       } else
21732 +               old_ipc = NULL;
21733 +
21734 +#ifdef CONFIG_PID_NS
21735 +       if (mask & CLONE_NEWPID) {
21736 +               old_pid = nsproxy->pid_ns_for_children;
21737 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21738 +               if (nsproxy->pid_ns_for_children)
21739 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21740 +       } else
21741 +               old_pid = NULL;
21742 +#endif
21743 +#ifdef CONFIG_NET_NS
21744 +       if (mask & CLONE_NEWNET) {
21745 +               old_net = nsproxy->net_ns;
21746 +               nsproxy->net_ns = new_nsproxy->net_ns;
21747 +               if (nsproxy->net_ns)
21748 +                       get_net(nsproxy->net_ns);
21749 +       } else
21750 +               old_net = NULL;
21751 +#endif
21752 +       if (old_ns)
21753 +               put_mnt_ns(old_ns);
21754 +       if (old_uts)
21755 +               put_uts_ns(old_uts);
21756 +       if (old_ipc)
21757 +               put_ipc_ns(old_ipc);
21758 +#ifdef CONFIG_PID_NS
21759 +       if (old_pid)
21760 +               put_pid_ns(old_pid);
21761 +#endif
21762 +#ifdef CONFIG_NET_NS
21763 +       if (old_net)
21764 +               put_net(old_net);
21765 +#endif
21766 +out:
21767 +       return nsproxy;
21768 +}
21769 +
21770 +
21771 +/*
21772 + *     merge two nsproxy structs into a new one.
21773 + *     will hold a reference on the result.
21774 + */
21775 +
21776 +static inline
21777 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21778 +       struct nsproxy *proxy, unsigned long mask)
21779 +{
21780 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21781 +
21782 +       if (!proxy)
21783 +               return NULL;
21784 +
21785 +       if (mask) {
21786 +               /* vs_mix_nsproxy returns with reference */
21787 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21788 +                       proxy, mask);
21789 +       }
21790 +       get_nsproxy(proxy);
21791 +       return proxy;
21792 +}
21793 +
21794 +
21795 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21796 +{
21797 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21798 +       struct fs_struct *fs_cur, *fs = NULL;
21799 +       struct _vx_space *space;
21800 +       int ret, kill = 0;
21801 +
21802 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21803 +               vxi, vxi->vx_id, mask, index);
21804 +
21805 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21806 +               return -EACCES;
21807 +
21808 +       if (index >= VX_SPACES)
21809 +               return -EINVAL;
21810 +
21811 +       space = &vxi->space[index];
21812 +
21813 +       if (!mask)
21814 +               mask = space->vx_nsmask;
21815 +
21816 +       if ((mask & space->vx_nsmask) != mask)
21817 +               return -EINVAL;
21818 +
21819 +       if (mask & CLONE_FS) {
21820 +               fs = copy_fs_struct(space->vx_fs);
21821 +               if (!fs)
21822 +                       return -ENOMEM;
21823 +       }
21824 +       proxy = space->vx_nsproxy;
21825 +
21826 +       vxdprintk(VXD_CBIT(space, 9),
21827 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21828 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21829 +
21830 +       task_lock(current);
21831 +       fs_cur = current->fs;
21832 +
21833 +       if (mask & CLONE_FS) {
21834 +               spin_lock(&fs_cur->lock);
21835 +               current->fs = fs;
21836 +               kill = !--fs_cur->users;
21837 +               spin_unlock(&fs_cur->lock);
21838 +       }
21839 +
21840 +       proxy_cur = current->nsproxy;
21841 +       get_nsproxy(proxy_cur);
21842 +       task_unlock(current);
21843 +
21844 +       if (kill)
21845 +               free_fs_struct(fs_cur);
21846 +
21847 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21848 +       if (IS_ERR(proxy_new)) {
21849 +               ret = PTR_ERR(proxy_new);
21850 +               goto out_put;
21851 +       }
21852 +
21853 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21854 +
21855 +       if (mask & CLONE_NEWUSER) {
21856 +               struct cred *cred;
21857 +
21858 +               vxdprintk(VXD_CBIT(space, 10),
21859 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21860 +                       vxi, vxi->vx_id, space->vx_cred,
21861 +                       current->real_cred, current->cred);
21862 +
21863 +               if (space->vx_cred) {
21864 +                       cred = __prepare_creds(space->vx_cred);
21865 +                       if (cred)
21866 +                               commit_creds(cred);
21867 +               }
21868 +       }
21869 +
21870 +       ret = 0;
21871 +
21872 +       if (proxy_new)
21873 +               put_nsproxy(proxy_new);
21874 +out_put:
21875 +       if (proxy_cur)
21876 +               put_nsproxy(proxy_cur);
21877 +       return ret;
21878 +}
21879 +
21880 +
21881 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21882 +{
21883 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21884 +       struct fs_struct *fs_vxi, *fs = NULL;
21885 +       struct _vx_space *space;
21886 +       int ret, kill = 0;
21887 +
21888 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21889 +               vxi, vxi->vx_id, mask, index);
21890 +
21891 +       if ((mask & space_mask.mask) != mask)
21892 +               return -EINVAL;
21893 +
21894 +       if (index >= VX_SPACES)
21895 +               return -EINVAL;
21896 +
21897 +       space = &vxi->space[index];
21898 +
21899 +       proxy_vxi = space->vx_nsproxy;
21900 +       fs_vxi = space->vx_fs;
21901 +
21902 +       if (mask & CLONE_FS) {
21903 +               fs = copy_fs_struct(current->fs);
21904 +               if (!fs)
21905 +                       return -ENOMEM;
21906 +       }
21907 +
21908 +       task_lock(current);
21909 +
21910 +       if (mask & CLONE_FS) {
21911 +               spin_lock(&fs_vxi->lock);
21912 +               space->vx_fs = fs;
21913 +               kill = !--fs_vxi->users;
21914 +               spin_unlock(&fs_vxi->lock);
21915 +       }
21916 +
21917 +       proxy_cur = current->nsproxy;
21918 +       get_nsproxy(proxy_cur);
21919 +       task_unlock(current);
21920 +
21921 +       if (kill)
21922 +               free_fs_struct(fs_vxi);
21923 +
21924 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21925 +       if (IS_ERR(proxy_new)) {
21926 +               ret = PTR_ERR(proxy_new);
21927 +               goto out_put;
21928 +       }
21929 +
21930 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21931 +       space->vx_nsmask |= mask;
21932 +
21933 +       if (mask & CLONE_NEWUSER) {
21934 +               struct cred *cred;
21935 +
21936 +               vxdprintk(VXD_CBIT(space, 10),
21937 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21938 +                       vxi, vxi->vx_id, space->vx_cred,
21939 +                       current->real_cred, current->cred);
21940 +
21941 +               cred = prepare_creds();
21942 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21943 +               if (cred)
21944 +                       abort_creds(cred);
21945 +       }
21946 +
21947 +       ret = 0;
21948 +
21949 +       if (proxy_new)
21950 +               put_nsproxy(proxy_new);
21951 +out_put:
21952 +       if (proxy_cur)
21953 +               put_nsproxy(proxy_cur);
21954 +       return ret;
21955 +}
21956 +
21957 +
21958 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21959 +{
21960 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21961 +
21962 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21963 +               return -EFAULT;
21964 +
21965 +       return vx_enter_space(vxi, vc_data.mask, 0);
21966 +}
21967 +
21968 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21969 +{
21970 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21971 +
21972 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21973 +               return -EFAULT;
21974 +
21975 +       if (vc_data.index >= VX_SPACES)
21976 +               return -EINVAL;
21977 +
21978 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21979 +}
21980 +
21981 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21982 +{
21983 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21984 +
21985 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21986 +               return -EFAULT;
21987 +
21988 +       return vx_set_space(vxi, vc_data.mask, 0);
21989 +}
21990 +
21991 +int vc_set_space(struct vx_info *vxi, void __user *data)
21992 +{
21993 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21994 +
21995 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21996 +               return -EFAULT;
21997 +
21998 +       if (vc_data.index >= VX_SPACES)
21999 +               return -EINVAL;
22000 +
22001 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22002 +}
22003 +
22004 +int vc_get_space_mask(void __user *data, int type)
22005 +{
22006 +       const struct vcmd_space_mask_v1 *mask;
22007 +
22008 +       if (type == 0)
22009 +               mask = &space_mask_v0;
22010 +       else if (type == 1)
22011 +               mask = &space_mask;
22012 +       else
22013 +               mask = &default_space_mask;
22014 +
22015 +       vxdprintk(VXD_CBIT(space, 10),
22016 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22017 +
22018 +       if (copy_to_user(data, mask, sizeof(*mask)))
22019 +               return -EFAULT;
22020 +       return 0;
22021 +}
22022 +
22023 diff -NurpP --minimal linux-3.13.10/kernel/vserver/switch.c linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c
22024 --- linux-3.13.10/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22025 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c    2014-01-31 20:38:04.000000000 +0000
22026 @@ -0,0 +1,556 @@
22027 +/*
22028 + *  linux/kernel/vserver/switch.c
22029 + *
22030 + *  Virtual Server: Syscall Switch
22031 + *
22032 + *  Copyright (C) 2003-2011  Herbert Pötzl
22033 + *
22034 + *  V0.01  syscall switch
22035 + *  V0.02  added signal to context
22036 + *  V0.03  added rlimit functions
22037 + *  V0.04  added iattr, task/xid functions
22038 + *  V0.05  added debug/history stuff
22039 + *  V0.06  added compat32 layer
22040 + *  V0.07  vcmd args and perms
22041 + *  V0.08  added status commands
22042 + *  V0.09  added tag commands
22043 + *  V0.10  added oom bias
22044 + *  V0.11  added device commands
22045 + *  V0.12  added warn mask
22046 + *
22047 + */
22048 +
22049 +#include <linux/vs_context.h>
22050 +#include <linux/vs_network.h>
22051 +#include <linux/vserver/switch.h>
22052 +
22053 +#include "vci_config.h"
22054 +
22055 +
22056 +static inline
22057 +int vc_get_version(uint32_t id)
22058 +{
22059 +       return VCI_VERSION;
22060 +}
22061 +
22062 +static inline
22063 +int vc_get_vci(uint32_t id)
22064 +{
22065 +       return vci_kernel_config();
22066 +}
22067 +
22068 +#include <linux/vserver/context_cmd.h>
22069 +#include <linux/vserver/cvirt_cmd.h>
22070 +#include <linux/vserver/cacct_cmd.h>
22071 +#include <linux/vserver/limit_cmd.h>
22072 +#include <linux/vserver/network_cmd.h>
22073 +#include <linux/vserver/sched_cmd.h>
22074 +#include <linux/vserver/debug_cmd.h>
22075 +#include <linux/vserver/inode_cmd.h>
22076 +#include <linux/vserver/dlimit_cmd.h>
22077 +#include <linux/vserver/signal_cmd.h>
22078 +#include <linux/vserver/space_cmd.h>
22079 +#include <linux/vserver/tag_cmd.h>
22080 +#include <linux/vserver/device_cmd.h>
22081 +
22082 +#include <linux/vserver/inode.h>
22083 +#include <linux/vserver/dlimit.h>
22084 +
22085 +
22086 +#ifdef CONFIG_COMPAT
22087 +#define __COMPAT(name, id, data, compat)       \
22088 +       (compat) ? name ## _x32(id, data) : name(id, data)
22089 +#define __COMPAT_NO_ID(name, data, compat)     \
22090 +       (compat) ? name ## _x32(data) : name(data)
22091 +#else
22092 +#define __COMPAT(name, id, data, compat)       \
22093 +       name(id, data)
22094 +#define __COMPAT_NO_ID(name, data, compat)     \
22095 +       name(data)
22096 +#endif
22097 +
22098 +
22099 +static inline
22100 +long do_vcmd(uint32_t cmd, uint32_t id,
22101 +       struct vx_info *vxi, struct nx_info *nxi,
22102 +       void __user *data, int compat)
22103 +{
22104 +       switch (cmd) {
22105 +
22106 +       case VCMD_get_version:
22107 +               return vc_get_version(id);
22108 +       case VCMD_get_vci:
22109 +               return vc_get_vci(id);
22110 +
22111 +       case VCMD_task_xid:
22112 +               return vc_task_xid(id);
22113 +       case VCMD_vx_info:
22114 +               return vc_vx_info(vxi, data);
22115 +
22116 +       case VCMD_task_nid:
22117 +               return vc_task_nid(id);
22118 +       case VCMD_nx_info:
22119 +               return vc_nx_info(nxi, data);
22120 +
22121 +       case VCMD_task_tag:
22122 +               return vc_task_tag(id);
22123 +
22124 +       case VCMD_set_space_v1:
22125 +               return vc_set_space_v1(vxi, data);
22126 +       /* this is version 2 */
22127 +       case VCMD_set_space:
22128 +               return vc_set_space(vxi, data);
22129 +
22130 +       case VCMD_get_space_mask_v0:
22131 +               return vc_get_space_mask(data, 0);
22132 +       /* this is version 1 */
22133 +       case VCMD_get_space_mask:
22134 +               return vc_get_space_mask(data, 1);
22135 +
22136 +       case VCMD_get_space_default:
22137 +               return vc_get_space_mask(data, -1);
22138 +
22139 +       case VCMD_set_umask:
22140 +               return vc_set_umask(vxi, data);
22141 +
22142 +       case VCMD_get_umask:
22143 +               return vc_get_umask(vxi, data);
22144 +
22145 +       case VCMD_set_wmask:
22146 +               return vc_set_wmask(vxi, data);
22147 +
22148 +       case VCMD_get_wmask:
22149 +               return vc_get_wmask(vxi, data);
22150 +#ifdef CONFIG_IA32_EMULATION
22151 +       case VCMD_get_rlimit:
22152 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22153 +       case VCMD_set_rlimit:
22154 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22155 +#else
22156 +       case VCMD_get_rlimit:
22157 +               return vc_get_rlimit(vxi, data);
22158 +       case VCMD_set_rlimit:
22159 +               return vc_set_rlimit(vxi, data);
22160 +#endif
22161 +       case VCMD_get_rlimit_mask:
22162 +               return vc_get_rlimit_mask(id, data);
22163 +       case VCMD_reset_hits:
22164 +               return vc_reset_hits(vxi, data);
22165 +       case VCMD_reset_minmax:
22166 +               return vc_reset_minmax(vxi, data);
22167 +
22168 +       case VCMD_get_vhi_name:
22169 +               return vc_get_vhi_name(vxi, data);
22170 +       case VCMD_set_vhi_name:
22171 +               return vc_set_vhi_name(vxi, data);
22172 +
22173 +       case VCMD_ctx_stat:
22174 +               return vc_ctx_stat(vxi, data);
22175 +       case VCMD_virt_stat:
22176 +               return vc_virt_stat(vxi, data);
22177 +       case VCMD_sock_stat:
22178 +               return vc_sock_stat(vxi, data);
22179 +       case VCMD_rlimit_stat:
22180 +               return vc_rlimit_stat(vxi, data);
22181 +
22182 +       case VCMD_set_cflags:
22183 +               return vc_set_cflags(vxi, data);
22184 +       case VCMD_get_cflags:
22185 +               return vc_get_cflags(vxi, data);
22186 +
22187 +       /* this is version 1 */
22188 +       case VCMD_set_ccaps:
22189 +               return vc_set_ccaps(vxi, data);
22190 +       /* this is version 1 */
22191 +       case VCMD_get_ccaps:
22192 +               return vc_get_ccaps(vxi, data);
22193 +       case VCMD_set_bcaps:
22194 +               return vc_set_bcaps(vxi, data);
22195 +       case VCMD_get_bcaps:
22196 +               return vc_get_bcaps(vxi, data);
22197 +
22198 +       case VCMD_set_badness:
22199 +               return vc_set_badness(vxi, data);
22200 +       case VCMD_get_badness:
22201 +               return vc_get_badness(vxi, data);
22202 +
22203 +       case VCMD_set_nflags:
22204 +               return vc_set_nflags(nxi, data);
22205 +       case VCMD_get_nflags:
22206 +               return vc_get_nflags(nxi, data);
22207 +
22208 +       case VCMD_set_ncaps:
22209 +               return vc_set_ncaps(nxi, data);
22210 +       case VCMD_get_ncaps:
22211 +               return vc_get_ncaps(nxi, data);
22212 +
22213 +       case VCMD_set_prio_bias:
22214 +               return vc_set_prio_bias(vxi, data);
22215 +       case VCMD_get_prio_bias:
22216 +               return vc_get_prio_bias(vxi, data);
22217 +       case VCMD_add_dlimit:
22218 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22219 +       case VCMD_rem_dlimit:
22220 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22221 +       case VCMD_set_dlimit:
22222 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22223 +       case VCMD_get_dlimit:
22224 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22225 +
22226 +       case VCMD_ctx_kill:
22227 +               return vc_ctx_kill(vxi, data);
22228 +
22229 +       case VCMD_wait_exit:
22230 +               return vc_wait_exit(vxi, data);
22231 +
22232 +       case VCMD_get_iattr:
22233 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22234 +       case VCMD_set_iattr:
22235 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22236 +
22237 +       case VCMD_fget_iattr:
22238 +               return vc_fget_iattr(id, data);
22239 +       case VCMD_fset_iattr:
22240 +               return vc_fset_iattr(id, data);
22241 +
22242 +       case VCMD_enter_space_v0:
22243 +               return vc_enter_space_v1(vxi, NULL);
22244 +       case VCMD_enter_space_v1:
22245 +               return vc_enter_space_v1(vxi, data);
22246 +       /* this is version 2 */
22247 +       case VCMD_enter_space:
22248 +               return vc_enter_space(vxi, data);
22249 +
22250 +       case VCMD_ctx_create_v0:
22251 +               return vc_ctx_create(id, NULL);
22252 +       case VCMD_ctx_create:
22253 +               return vc_ctx_create(id, data);
22254 +       case VCMD_ctx_migrate_v0:
22255 +               return vc_ctx_migrate(vxi, NULL);
22256 +       case VCMD_ctx_migrate:
22257 +               return vc_ctx_migrate(vxi, data);
22258 +
22259 +       case VCMD_net_create_v0:
22260 +               return vc_net_create(id, NULL);
22261 +       case VCMD_net_create:
22262 +               return vc_net_create(id, data);
22263 +       case VCMD_net_migrate:
22264 +               return vc_net_migrate(nxi, data);
22265 +
22266 +       case VCMD_tag_migrate:
22267 +               return vc_tag_migrate(id);
22268 +
22269 +       case VCMD_net_add:
22270 +               return vc_net_add(nxi, data);
22271 +       case VCMD_net_remove:
22272 +               return vc_net_remove(nxi, data);
22273 +
22274 +       case VCMD_net_add_ipv4_v1:
22275 +               return vc_net_add_ipv4_v1(nxi, data);
22276 +       /* this is version 2 */
22277 +       case VCMD_net_add_ipv4:
22278 +               return vc_net_add_ipv4(nxi, data);
22279 +
22280 +       case VCMD_net_rem_ipv4_v1:
22281 +               return vc_net_rem_ipv4_v1(nxi, data);
22282 +       /* this is version 2 */
22283 +       case VCMD_net_rem_ipv4:
22284 +               return vc_net_rem_ipv4(nxi, data);
22285 +#ifdef CONFIG_IPV6
22286 +       case VCMD_net_add_ipv6:
22287 +               return vc_net_add_ipv6(nxi, data);
22288 +       case VCMD_net_remove_ipv6:
22289 +               return vc_net_remove_ipv6(nxi, data);
22290 +#endif
22291 +/*     case VCMD_add_match_ipv4:
22292 +               return vc_add_match_ipv4(nxi, data);
22293 +       case VCMD_get_match_ipv4:
22294 +               return vc_get_match_ipv4(nxi, data);
22295 +#ifdef CONFIG_IPV6
22296 +       case VCMD_add_match_ipv6:
22297 +               return vc_add_match_ipv6(nxi, data);
22298 +       case VCMD_get_match_ipv6:
22299 +               return vc_get_match_ipv6(nxi, data);
22300 +#endif */
22301 +
22302 +#ifdef CONFIG_VSERVER_DEVICE
22303 +       case VCMD_set_mapping:
22304 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22305 +       case VCMD_unset_mapping:
22306 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22307 +#endif
22308 +#ifdef CONFIG_VSERVER_HISTORY
22309 +       case VCMD_dump_history:
22310 +               return vc_dump_history(id);
22311 +       case VCMD_read_history:
22312 +               return __COMPAT(vc_read_history, id, data, compat);
22313 +#endif
22314 +       default:
22315 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22316 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22317 +       }
22318 +       return -ENOSYS;
22319 +}
22320 +
22321 +
22322 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22323 +       case VCMD_ ## vcmd: perm = _perm;               \
22324 +               args = _args; flags = _flags; break
22325 +
22326 +
22327 +#define VCA_NONE       0x00
22328 +#define VCA_VXI                0x01
22329 +#define VCA_NXI                0x02
22330 +
22331 +#define VCF_NONE       0x00
22332 +#define VCF_INFO       0x01
22333 +#define VCF_ADMIN      0x02
22334 +#define VCF_ARES       0x06    /* includes admin */
22335 +#define VCF_SETUP      0x08
22336 +
22337 +#define VCF_ZIDOK      0x10    /* zero id okay */
22338 +
22339 +
22340 +static inline
22341 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22342 +{
22343 +       long ret;
22344 +       int permit = -1, state = 0;
22345 +       int perm = -1, args = 0, flags = 0;
22346 +       struct vx_info *vxi = NULL;
22347 +       struct nx_info *nxi = NULL;
22348 +
22349 +       switch (cmd) {
22350 +       /* unpriviledged commands */
22351 +       __VCMD(get_version,      0, VCA_NONE,   0);
22352 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22353 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22354 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22355 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22356 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22357 +
22358 +       /* info commands */
22359 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22360 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22361 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22362 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22363 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22364 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22365 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22366 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22367 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22368 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22369 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22370 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22371 +
22372 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22373 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22374 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22375 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22376 +
22377 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22378 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22379 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22380 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22381 +
22382 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22383 +
22384 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22385 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22386 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22387 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22388 +
22389 +       /* lower admin commands */
22390 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22391 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22392 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22393 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22394 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22395 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22396 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22397 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22398 +
22399 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22400 +       __VCMD(net_create,       5, VCA_NONE,   0);
22401 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22402 +
22403 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22404 +
22405 +       /* higher admin commands */
22406 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22407 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22408 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22409 +
22410 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22411 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22412 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22413 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22414 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22415 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22416 +
22417 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22418 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22419 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22420 +
22421 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22422 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22423 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22424 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22425 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22426 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22427 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22428 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22429 +#ifdef CONFIG_IPV6
22430 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22431 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22432 +#endif
22433 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22434 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22435 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22436 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22437 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22438 +
22439 +#ifdef CONFIG_VSERVER_DEVICE
22440 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22441 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22442 +#endif
22443 +       /* debug level admin commands */
22444 +#ifdef CONFIG_VSERVER_HISTORY
22445 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22446 +       __VCMD(read_history,     9, VCA_NONE,   0);
22447 +#endif
22448 +
22449 +       default:
22450 +               perm = -1;
22451 +       }
22452 +
22453 +       vxdprintk(VXD_CBIT(switch, 0),
22454 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22455 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22456 +               VC_VERSION(cmd), id, data, compat,
22457 +               perm, args, flags);
22458 +
22459 +       ret = -ENOSYS;
22460 +       if (perm < 0)
22461 +               goto out;
22462 +
22463 +       state = 1;
22464 +       if (!capable(CAP_CONTEXT))
22465 +               goto out;
22466 +
22467 +       state = 2;
22468 +       /* moved here from the individual commands */
22469 +       ret = -EPERM;
22470 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22471 +               goto out;
22472 +
22473 +       state = 3;
22474 +       /* vcmd involves resource management  */
22475 +       ret = -EPERM;
22476 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22477 +               goto out;
22478 +
22479 +       state = 4;
22480 +       /* various legacy exceptions */
22481 +       switch (cmd) {
22482 +       /* will go away when spectator is a cap */
22483 +       case VCMD_ctx_migrate_v0:
22484 +       case VCMD_ctx_migrate:
22485 +               if (id == 1) {
22486 +                       current->xid = 1;
22487 +                       ret = 1;
22488 +                       goto out;
22489 +               }
22490 +               break;
22491 +
22492 +       /* will go away when spectator is a cap */
22493 +       case VCMD_net_migrate:
22494 +               if (id == 1) {
22495 +                       current->nid = 1;
22496 +                       ret = 1;
22497 +                       goto out;
22498 +               }
22499 +               break;
22500 +       }
22501 +
22502 +       /* vcmds are fine by default */
22503 +       permit = 1;
22504 +
22505 +       /* admin type vcmds require admin ... */
22506 +       if (flags & VCF_ADMIN)
22507 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22508 +
22509 +       /* ... but setup type vcmds override that */
22510 +       if (!permit && (flags & VCF_SETUP))
22511 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22512 +
22513 +       state = 5;
22514 +       ret = -EPERM;
22515 +       if (!permit)
22516 +               goto out;
22517 +
22518 +       state = 6;
22519 +       if (!id && (flags & VCF_ZIDOK))
22520 +               goto skip_id;
22521 +
22522 +       ret = -ESRCH;
22523 +       if (args & VCA_VXI) {
22524 +               vxi = lookup_vx_info(id);
22525 +               if (!vxi)
22526 +                       goto out;
22527 +
22528 +               if ((flags & VCF_ADMIN) &&
22529 +                       /* special case kill for shutdown */
22530 +                       (cmd != VCMD_ctx_kill) &&
22531 +                       /* can context be administrated? */
22532 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22533 +                       ret = -EACCES;
22534 +                       goto out_vxi;
22535 +               }
22536 +       }
22537 +       state = 7;
22538 +       if (args & VCA_NXI) {
22539 +               nxi = lookup_nx_info(id);
22540 +               if (!nxi)
22541 +                       goto out_vxi;
22542 +
22543 +               if ((flags & VCF_ADMIN) &&
22544 +                       /* can context be administrated? */
22545 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22546 +                       ret = -EACCES;
22547 +                       goto out_nxi;
22548 +               }
22549 +       }
22550 +skip_id:
22551 +       state = 8;
22552 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22553 +
22554 +out_nxi:
22555 +       if ((args & VCA_NXI) && nxi)
22556 +               put_nx_info(nxi);
22557 +out_vxi:
22558 +       if ((args & VCA_VXI) && vxi)
22559 +               put_vx_info(vxi);
22560 +out:
22561 +       vxdprintk(VXD_CBIT(switch, 1),
22562 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22563 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22564 +               VC_VERSION(cmd), ret, ret, state, permit);
22565 +       return ret;
22566 +}
22567 +
22568 +asmlinkage long
22569 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22570 +{
22571 +       return do_vserver(cmd, id, data, 0);
22572 +}
22573 +
22574 +#ifdef CONFIG_COMPAT
22575 +
22576 +asmlinkage long
22577 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22578 +{
22579 +       return do_vserver(cmd, id, data, 1);
22580 +}
22581 +
22582 +#endif /* CONFIG_COMPAT */
22583 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c
22584 --- linux-3.13.10/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22585 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c    2014-01-31 20:38:04.000000000 +0000
22586 @@ -0,0 +1,247 @@
22587 +/*
22588 + *  kernel/vserver/sysctl.c
22589 + *
22590 + *  Virtual Context Support
22591 + *
22592 + *  Copyright (C) 2004-2007  Herbert Pötzl
22593 + *
22594 + *  V0.01  basic structure
22595 + *
22596 + */
22597 +
22598 +#include <linux/module.h>
22599 +#include <linux/ctype.h>
22600 +#include <linux/sysctl.h>
22601 +#include <linux/parser.h>
22602 +#include <asm/uaccess.h>
22603 +
22604 +enum {
22605 +       CTL_DEBUG_ERROR         = 0,
22606 +       CTL_DEBUG_SWITCH        = 1,
22607 +       CTL_DEBUG_XID,
22608 +       CTL_DEBUG_NID,
22609 +       CTL_DEBUG_TAG,
22610 +       CTL_DEBUG_NET,
22611 +       CTL_DEBUG_LIMIT,
22612 +       CTL_DEBUG_CRES,
22613 +       CTL_DEBUG_DLIM,
22614 +       CTL_DEBUG_QUOTA,
22615 +       CTL_DEBUG_CVIRT,
22616 +       CTL_DEBUG_SPACE,
22617 +       CTL_DEBUG_PERM,
22618 +       CTL_DEBUG_MISC,
22619 +};
22620 +
22621 +
22622 +unsigned int vs_debug_switch   = 0;
22623 +unsigned int vs_debug_xid      = 0;
22624 +unsigned int vs_debug_nid      = 0;
22625 +unsigned int vs_debug_tag      = 0;
22626 +unsigned int vs_debug_net      = 0;
22627 +unsigned int vs_debug_limit    = 0;
22628 +unsigned int vs_debug_cres     = 0;
22629 +unsigned int vs_debug_dlim     = 0;
22630 +unsigned int vs_debug_quota    = 0;
22631 +unsigned int vs_debug_cvirt    = 0;
22632 +unsigned int vs_debug_space    = 0;
22633 +unsigned int vs_debug_perm     = 0;
22634 +unsigned int vs_debug_misc     = 0;
22635 +
22636 +
22637 +static struct ctl_table_header *vserver_table_header;
22638 +static ctl_table vserver_root_table[];
22639 +
22640 +
22641 +void vserver_register_sysctl(void)
22642 +{
22643 +       if (!vserver_table_header) {
22644 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22645 +       }
22646 +
22647 +}
22648 +
22649 +void vserver_unregister_sysctl(void)
22650 +{
22651 +       if (vserver_table_header) {
22652 +               unregister_sysctl_table(vserver_table_header);
22653 +               vserver_table_header = NULL;
22654 +       }
22655 +}
22656 +
22657 +
22658 +static int proc_dodebug(ctl_table *table, int write,
22659 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22660 +{
22661 +       char            tmpbuf[20], *p, c;
22662 +       unsigned int    value;
22663 +       size_t          left, len;
22664 +
22665 +       if ((*ppos && !write) || !*lenp) {
22666 +               *lenp = 0;
22667 +               return 0;
22668 +       }
22669 +
22670 +       left = *lenp;
22671 +
22672 +       if (write) {
22673 +               if (!access_ok(VERIFY_READ, buffer, left))
22674 +                       return -EFAULT;
22675 +               p = (char *)buffer;
22676 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22677 +                       left--, p++;
22678 +               if (!left)
22679 +                       goto done;
22680 +
22681 +               if (left > sizeof(tmpbuf) - 1)
22682 +                       return -EINVAL;
22683 +               if (copy_from_user(tmpbuf, p, left))
22684 +                       return -EFAULT;
22685 +               tmpbuf[left] = '\0';
22686 +
22687 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22688 +                       value = 10 * value + (*p - '0');
22689 +               if (*p && !isspace(*p))
22690 +                       return -EINVAL;
22691 +               while (left && isspace(*p))
22692 +                       left--, p++;
22693 +               *(unsigned int *)table->data = value;
22694 +       } else {
22695 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22696 +                       return -EFAULT;
22697 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22698 +               if (len > left)
22699 +                       len = left;
22700 +               if (__copy_to_user(buffer, tmpbuf, len))
22701 +                       return -EFAULT;
22702 +               if ((left -= len) > 0) {
22703 +                       if (put_user('\n', (char *)buffer + len))
22704 +                               return -EFAULT;
22705 +                       left--;
22706 +               }
22707 +       }
22708 +
22709 +done:
22710 +       *lenp -= left;
22711 +       *ppos += *lenp;
22712 +       return 0;
22713 +}
22714 +
22715 +static int zero;
22716 +
22717 +#define        CTL_ENTRY(ctl, name)                            \
22718 +       {                                               \
22719 +               .procname       = #name,                \
22720 +               .data           = &vs_ ## name,         \
22721 +               .maxlen         = sizeof(int),          \
22722 +               .mode           = 0644,                 \
22723 +               .proc_handler   = &proc_dodebug,        \
22724 +               .extra1         = &zero,                \
22725 +               .extra2         = &zero,                \
22726 +       }
22727 +
22728 +static ctl_table vserver_debug_table[] = {
22729 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22730 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22731 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22732 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22733 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22734 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22735 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22736 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22737 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22738 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22739 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22740 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22741 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22742 +       { 0 }
22743 +};
22744 +
22745 +static ctl_table vserver_root_table[] = {
22746 +       {
22747 +               .procname       = "vserver",
22748 +               .mode           = 0555,
22749 +               .child          = vserver_debug_table
22750 +       },
22751 +       { 0 }
22752 +};
22753 +
22754 +
22755 +static match_table_t tokens = {
22756 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22757 +       { CTL_DEBUG_XID,        "xid=%x"        },
22758 +       { CTL_DEBUG_NID,        "nid=%x"        },
22759 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22760 +       { CTL_DEBUG_NET,        "net=%x"        },
22761 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22762 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22763 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22764 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22765 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22766 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22767 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22768 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22769 +       { CTL_DEBUG_ERROR,      NULL            }
22770 +};
22771 +
22772 +#define        HANDLE_CASE(id, name, val)                              \
22773 +       case CTL_DEBUG_ ## id:                                  \
22774 +               vs_debug_ ## name = val;                        \
22775 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22776 +               break
22777 +
22778 +
22779 +static int __init vs_debug_setup(char *str)
22780 +{
22781 +       char *p;
22782 +       int token;
22783 +
22784 +       printk("vs_debug_setup(%s)\n", str);
22785 +       while ((p = strsep(&str, ",")) != NULL) {
22786 +               substring_t args[MAX_OPT_ARGS];
22787 +               unsigned int value;
22788 +
22789 +               if (!*p)
22790 +                       continue;
22791 +
22792 +               token = match_token(p, tokens, args);
22793 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22794 +
22795 +               switch (token) {
22796 +               HANDLE_CASE(SWITCH, switch, value);
22797 +               HANDLE_CASE(XID,    xid,    value);
22798 +               HANDLE_CASE(NID,    nid,    value);
22799 +               HANDLE_CASE(TAG,    tag,    value);
22800 +               HANDLE_CASE(NET,    net,    value);
22801 +               HANDLE_CASE(LIMIT,  limit,  value);
22802 +               HANDLE_CASE(CRES,   cres,   value);
22803 +               HANDLE_CASE(DLIM,   dlim,   value);
22804 +               HANDLE_CASE(QUOTA,  quota,  value);
22805 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22806 +               HANDLE_CASE(SPACE,  space,  value);
22807 +               HANDLE_CASE(PERM,   perm,   value);
22808 +               HANDLE_CASE(MISC,   misc,   value);
22809 +               default:
22810 +                       return -EINVAL;
22811 +                       break;
22812 +               }
22813 +       }
22814 +       return 1;
22815 +}
22816 +
22817 +__setup("vsdebug=", vs_debug_setup);
22818 +
22819 +
22820 +
22821 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22822 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22823 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22824 +EXPORT_SYMBOL_GPL(vs_debug_net);
22825 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22826 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22827 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22828 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22829 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22830 +EXPORT_SYMBOL_GPL(vs_debug_space);
22831 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22832 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22833 +
22834 diff -NurpP --minimal linux-3.13.10/kernel/vserver/tag.c linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c
22835 --- linux-3.13.10/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22836 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c       2014-01-31 20:38:04.000000000 +0000
22837 @@ -0,0 +1,63 @@
22838 +/*
22839 + *  linux/kernel/vserver/tag.c
22840 + *
22841 + *  Virtual Server: Shallow Tag Space
22842 + *
22843 + *  Copyright (C) 2007  Herbert Pötzl
22844 + *
22845 + *  V0.01  basic implementation
22846 + *
22847 + */
22848 +
22849 +#include <linux/sched.h>
22850 +#include <linux/vserver/debug.h>
22851 +#include <linux/vs_pid.h>
22852 +#include <linux/vs_tag.h>
22853 +
22854 +#include <linux/vserver/tag_cmd.h>
22855 +
22856 +
22857 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22858 +{
22859 +       if (!p)
22860 +               BUG();
22861 +
22862 +       vxdprintk(VXD_CBIT(tag, 5),
22863 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22864 +
22865 +       task_lock(p);
22866 +       p->tag = tag;
22867 +       task_unlock(p);
22868 +
22869 +       vxdprintk(VXD_CBIT(tag, 5),
22870 +               "moved task %p into [#%d]", p, tag);
22871 +       return 0;
22872 +}
22873 +
22874 +/* vserver syscall commands below here */
22875 +
22876 +/* taks xid and vx_info functions */
22877 +
22878 +
22879 +int vc_task_tag(uint32_t id)
22880 +{
22881 +       vtag_t tag;
22882 +
22883 +       if (id) {
22884 +               struct task_struct *tsk;
22885 +               rcu_read_lock();
22886 +               tsk = find_task_by_real_pid(id);
22887 +               tag = (tsk) ? tsk->tag : -ESRCH;
22888 +               rcu_read_unlock();
22889 +       } else
22890 +               tag = dx_current_tag();
22891 +       return tag;
22892 +}
22893 +
22894 +
22895 +int vc_tag_migrate(uint32_t tag)
22896 +{
22897 +       return dx_migrate_task(current, tag & 0xFFFF);
22898 +}
22899 +
22900 +
22901 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
22902 --- linux-3.13.10/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22903 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h        2014-01-31 20:38:04.000000000 +0000
22904 @@ -0,0 +1,80 @@
22905 +
22906 +/*  interface version */
22907 +
22908 +#define VCI_VERSION            0x00020308
22909 +
22910 +
22911 +enum {
22912 +       VCI_KCBIT_NO_DYNAMIC = 0,
22913 +
22914 +       VCI_KCBIT_PROC_SECURE = 4,
22915 +       /* VCI_KCBIT_HARDCPU = 5, */
22916 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22917 +       /* VCI_KCBIT_IDLETIME = 7, */
22918 +
22919 +       VCI_KCBIT_COWBL = 8,
22920 +       VCI_KCBIT_FULLCOWBL = 9,
22921 +       VCI_KCBIT_SPACES = 10,
22922 +       VCI_KCBIT_NETV2 = 11,
22923 +       VCI_KCBIT_MEMCG = 12,
22924 +       VCI_KCBIT_MEMCG_SWAP = 13,
22925 +
22926 +       VCI_KCBIT_DEBUG = 16,
22927 +       VCI_KCBIT_HISTORY = 20,
22928 +       VCI_KCBIT_TAGGED = 24,
22929 +       VCI_KCBIT_PPTAG = 28,
22930 +
22931 +       VCI_KCBIT_MORE = 31,
22932 +};
22933 +
22934 +
22935 +static inline uint32_t vci_kernel_config(void)
22936 +{
22937 +       return
22938 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22939 +
22940 +       /* configured features */
22941 +#ifdef CONFIG_VSERVER_PROC_SECURE
22942 +       (1 << VCI_KCBIT_PROC_SECURE) |
22943 +#endif
22944 +#ifdef CONFIG_VSERVER_COWBL
22945 +       (1 << VCI_KCBIT_COWBL) |
22946 +       (1 << VCI_KCBIT_FULLCOWBL) |
22947 +#endif
22948 +       (1 << VCI_KCBIT_SPACES) |
22949 +       (1 << VCI_KCBIT_NETV2) |
22950 +#ifdef CONFIG_MEMCG
22951 +       (1 << VCI_KCBIT_MEMCG) |
22952 +#endif
22953 +#ifdef CONFIG_MEMCG_SWAP
22954 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
22955 +#endif
22956 +
22957 +       /* debug options */
22958 +#ifdef CONFIG_VSERVER_DEBUG
22959 +       (1 << VCI_KCBIT_DEBUG) |
22960 +#endif
22961 +#ifdef CONFIG_VSERVER_HISTORY
22962 +       (1 << VCI_KCBIT_HISTORY) |
22963 +#endif
22964 +
22965 +       /* inode context tagging */
22966 +#if    defined(CONFIG_TAGGING_NONE)
22967 +       (0 << VCI_KCBIT_TAGGED) |
22968 +#elif  defined(CONFIG_TAGGING_UID16)
22969 +       (1 << VCI_KCBIT_TAGGED) |
22970 +#elif  defined(CONFIG_TAGGING_GID16)
22971 +       (2 << VCI_KCBIT_TAGGED) |
22972 +#elif  defined(CONFIG_TAGGING_ID24)
22973 +       (3 << VCI_KCBIT_TAGGED) |
22974 +#elif  defined(CONFIG_TAGGING_INTERN)
22975 +       (4 << VCI_KCBIT_TAGGED) |
22976 +#elif  defined(CONFIG_TAGGING_RUNTIME)
22977 +       (5 << VCI_KCBIT_TAGGED) |
22978 +#else
22979 +       (7 << VCI_KCBIT_TAGGED) |
22980 +#endif
22981 +       (1 << VCI_KCBIT_PPTAG) |
22982 +       0;
22983 +}
22984 +
22985 diff -NurpP --minimal linux-3.13.10/mm/memcontrol.c linux-3.13.10-vs2.3.6.11/mm/memcontrol.c
22986 --- linux-3.13.10/mm/memcontrol.c       2014-04-17 01:12:40.000000000 +0000
22987 +++ linux-3.13.10-vs2.3.6.11/mm/memcontrol.c    2014-04-17 01:17:11.000000000 +0000
22988 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
22989         return mem_cgroup_from_css(task_css(p, memory_cgrp_id));
22990  }
22991  
22992 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
22993 +{
22994 +       return res_counter_read_u64(&mem->res, member);
22995 +}
22996 +
22997 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
22998 +{
22999 +       return res_counter_read_u64(&mem->memsw, member);
23000 +}
23001 +
23002 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23003 +{
23004 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23005 +}
23006 +
23007 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23008 +{
23009 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23010 +}
23011 +
23012 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23013 +{
23014 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23015 +}
23016 +
23017  static struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
23018  {
23019         struct mem_cgroup *memcg = NULL;
23020 diff -NurpP --minimal linux-3.13.10/mm/oom_kill.c linux-3.13.10-vs2.3.6.11/mm/oom_kill.c
23021 --- linux-3.13.10/mm/oom_kill.c 2014-04-17 01:12:40.000000000 +0000
23022 +++ linux-3.13.10-vs2.3.6.11/mm/oom_kill.c      2014-02-25 11:26:10.000000000 +0000
23023 @@ -35,6 +35,8 @@
23024  #include <linux/freezer.h>
23025  #include <linux/ftrace.h>
23026  #include <linux/ratelimit.h>
23027 +#include <linux/reboot.h>
23028 +#include <linux/vs_context.h>
23029  
23030  #define CREATE_TRACE_POINTS
23031  #include <trace/events/oom.h>
23032 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23033  static bool oom_unkillable_task(struct task_struct *p,
23034                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23035  {
23036 -       if (is_global_init(p))
23037 +       unsigned xid = vx_current_xid();
23038 +
23039 +       /* skip the init task, global and per guest */
23040 +       if (task_is_init(p))
23041                 return true;
23042         if (p->flags & PF_KTHREAD)
23043                 return true;
23044  
23045 +       /* skip other guest and host processes if oom in guest */
23046 +       if (xid && vx_task_xid(p) != xid)
23047 +               return true;
23048 +
23049         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23050         if (memcg && !task_in_mem_cgroup(p, memcg))
23051                 return true;
23052 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23053                 dump_header(p, gfp_mask, order, memcg, nodemask);
23054  
23055         task_lock(p);
23056 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23057 -               message, task_pid_nr(p), p->comm, points);
23058 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23059 +               message, task_pid_nr(p), p->xid, p->comm, points);
23060         task_unlock(p);
23061  
23062         /*
23063 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23064  
23065         /* mm cannot safely be dereferenced after task_unlock(victim) */
23066         mm = victim->mm;
23067 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23068 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23069 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23070 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23071                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23072                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23073         task_unlock(victim);
23074 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23075  }
23076  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23077  
23078 +long vs_oom_action(unsigned int);
23079 +
23080  /*
23081   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23082   * if a parallel OOM killing is already taking place that includes a zone in
23083 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23084         /* Found nothing?!?! Either we hang forever, or we panic. */
23085         if (!p) {
23086                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23087 -               panic("Out of memory and no killable processes...\n");
23088 +
23089 +               /* avoid panic for guest OOM */
23090 +               if (vx_current_xid())
23091 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23092 +               else
23093 +                       panic("Out of memory and no killable processes...\n");
23094         }
23095         if (p != (void *)-1UL) {
23096                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23097 diff -NurpP --minimal linux-3.13.10/mm/page_alloc.c linux-3.13.10-vs2.3.6.11/mm/page_alloc.c
23098 --- linux-3.13.10/mm/page_alloc.c       2014-04-17 01:12:40.000000000 +0000
23099 +++ linux-3.13.10-vs2.3.6.11/mm/page_alloc.c    2014-04-17 01:17:11.000000000 +0000
23100 @@ -61,6 +61,8 @@
23101  #include <linux/page-debug-flags.h>
23102  #include <linux/hugetlb.h>
23103  #include <linux/sched/rt.h>
23104 +#include <linux/vs_base.h>
23105 +#include <linux/vs_limit.h>
23106  
23107  #include <asm/sections.h>
23108  #include <asm/tlbflush.h>
23109 @@ -2983,6 +2985,9 @@ void si_meminfo(struct sysinfo *val)
23110         val->totalhigh = totalhigh_pages;
23111         val->freehigh = nr_free_highpages();
23112         val->mem_unit = PAGE_SIZE;
23113 +
23114 +       if (vx_flags(VXF_VIRT_MEM, 0))
23115 +               vx_vsi_meminfo(val);
23116  }
23117  
23118  EXPORT_SYMBOL(si_meminfo);
23119 @@ -3007,6 +3012,9 @@ void si_meminfo_node(struct sysinfo *val
23120         val->freehigh = 0;
23121  #endif
23122         val->mem_unit = PAGE_SIZE;
23123 +
23124 +       if (vx_flags(VXF_VIRT_MEM, 0))
23125 +               vx_vsi_meminfo(val);
23126  }
23127  #endif
23128  
23129 diff -NurpP --minimal linux-3.13.10/mm/pgtable-generic.c linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c
23130 --- linux-3.13.10/mm/pgtable-generic.c  2014-01-22 20:39:14.000000000 +0000
23131 +++ linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c       2014-01-31 20:38:04.000000000 +0000
23132 @@ -6,6 +6,8 @@
23133   *  Copyright (C) 2010  Linus Torvalds
23134   */
23135  
23136 +#include <linux/mm.h>
23137 +
23138  #include <linux/pagemap.h>
23139  #include <asm/tlb.h>
23140  #include <asm-generic/pgtable.h>
23141 diff -NurpP --minimal linux-3.13.10/mm/shmem.c linux-3.13.10-vs2.3.6.11/mm/shmem.c
23142 --- linux-3.13.10/mm/shmem.c    2014-01-22 20:39:14.000000000 +0000
23143 +++ linux-3.13.10-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23144 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23145  {
23146         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23147  
23148 -       buf->f_type = TMPFS_MAGIC;
23149 +       buf->f_type = TMPFS_SUPER_MAGIC;
23150         buf->f_bsize = PAGE_CACHE_SIZE;
23151         buf->f_namelen = NAME_MAX;
23152         if (sbinfo->max_blocks) {
23153 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23154         sb->s_maxbytes = MAX_LFS_FILESIZE;
23155         sb->s_blocksize = PAGE_CACHE_SIZE;
23156         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23157 -       sb->s_magic = TMPFS_MAGIC;
23158 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23159         sb->s_op = &shmem_ops;
23160         sb->s_time_gran = 1;
23161  #ifdef CONFIG_TMPFS_XATTR
23162 diff -NurpP --minimal linux-3.13.10/mm/slab.c linux-3.13.10-vs2.3.6.11/mm/slab.c
23163 --- linux-3.13.10/mm/slab.c     2014-01-22 20:39:14.000000000 +0000
23164 +++ linux-3.13.10-vs2.3.6.11/mm/slab.c  2014-01-31 20:38:04.000000000 +0000
23165 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23166  #define STATS_INC_FREEMISS(x)  do { } while (0)
23167  #endif
23168  
23169 +#include "slab_vs.h"
23170 +
23171  #if DEBUG
23172  
23173  /*
23174 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23175         /* ___cache_alloc_node can fall back to other nodes */
23176         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23177    out:
23178 +       vx_slab_alloc(cachep, flags);
23179         local_irq_restore(save_flags);
23180         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23181         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23182 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23183         check_irq_off();
23184         kmemleak_free_recursive(objp, cachep->flags);
23185         objp = cache_free_debugcheck(cachep, objp, caller);
23186 +       vx_slab_free(cachep);
23187  
23188         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23189  
23190 diff -NurpP --minimal linux-3.13.10/mm/slab_vs.h linux-3.13.10-vs2.3.6.11/mm/slab_vs.h
23191 --- linux-3.13.10/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23192 +++ linux-3.13.10-vs2.3.6.11/mm/slab_vs.h       2014-01-31 20:38:04.000000000 +0000
23193 @@ -0,0 +1,29 @@
23194 +
23195 +#include <linux/vserver/context.h>
23196 +
23197 +#include <linux/vs_context.h>
23198 +
23199 +static inline
23200 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23201 +{
23202 +       int what = gfp_zone(cachep->allocflags);
23203 +       struct vx_info *vxi = current_vx_info();
23204 +
23205 +       if (!vxi)
23206 +               return;
23207 +
23208 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23209 +}
23210 +
23211 +static inline
23212 +void vx_slab_free(struct kmem_cache *cachep)
23213 +{
23214 +       int what = gfp_zone(cachep->allocflags);
23215 +       struct vx_info *vxi = current_vx_info();
23216 +
23217 +       if (!vxi)
23218 +               return;
23219 +
23220 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23221 +}
23222 +
23223 diff -NurpP --minimal linux-3.13.10/mm/swapfile.c linux-3.13.10-vs2.3.6.11/mm/swapfile.c
23224 --- linux-3.13.10/mm/swapfile.c 2014-04-17 01:12:40.000000000 +0000
23225 +++ linux-3.13.10-vs2.3.6.11/mm/swapfile.c      2014-02-25 11:26:10.000000000 +0000
23226 @@ -39,6 +39,7 @@
23227  #include <asm/tlbflush.h>
23228  #include <linux/swapops.h>
23229  #include <linux/page_cgroup.h>
23230 +#include <linux/vs_base.h>
23231  
23232  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23233                                  unsigned char);
23234 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23235  
23236         if (si == SEQ_START_TOKEN) {
23237                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23238 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23239 +                       struct sysinfo si;
23240 +
23241 +                       vx_vsi_swapinfo(&si);
23242 +                       if (si.totalswap < (1 << 10))
23243 +                               return 0;
23244 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23245 +                               "hdv0", "partition", si.totalswap >> 10,
23246 +                               (si.totalswap - si.freeswap) >> 10, -1);
23247 +               }
23248                 return 0;
23249         }
23250  
23251 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23252         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23253         val->totalswap = total_swap_pages + nr_to_be_unused;
23254         spin_unlock(&swap_lock);
23255 +       if (vx_flags(VXF_VIRT_MEM, 0))
23256 +               vx_vsi_swapinfo(val);
23257  }
23258  
23259  /*
23260 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
23261 --- linux-3.13.10/net/bridge/br_multicast.c     2014-04-17 01:12:40.000000000 +0000
23262 +++ linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c  2014-04-17 01:17:11.000000000 +0000
23263 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23264         ip6h->hop_limit = 1;
23265         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23266         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23267 -                              &ip6h->saddr)) {
23268 +                              &ip6h->saddr, NULL)) {
23269                 kfree_skb(skb);
23270                 return NULL;
23271         }
23272 diff -NurpP --minimal linux-3.13.10/net/core/dev.c linux-3.13.10-vs2.3.6.11/net/core/dev.c
23273 --- linux-3.13.10/net/core/dev.c        2014-04-17 01:12:41.000000000 +0000
23274 +++ linux-3.13.10-vs2.3.6.11/net/core/dev.c     2014-03-12 15:51:08.000000000 +0000
23275 @@ -122,6 +122,7 @@
23276  #include <linux/in.h>
23277  #include <linux/jhash.h>
23278  #include <linux/random.h>
23279 +#include <linux/vs_inet.h>
23280  #include <trace/events/napi.h>
23281  #include <trace/events/net.h>
23282  #include <trace/events/skb.h>
23283 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23284         struct hlist_head *head = dev_name_hash(net, name);
23285  
23286         hlist_for_each_entry(dev, head, name_hlist)
23287 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23288 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23289 +                   nx_dev_visible(current_nx_info(), dev))
23290                         return dev;
23291  
23292         return NULL;
23293 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23294         struct hlist_head *head = dev_name_hash(net, name);
23295  
23296         hlist_for_each_entry_rcu(dev, head, name_hlist)
23297 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23298 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23299 +                   nx_dev_visible(current_nx_info(), dev))
23300                         return dev;
23301  
23302         return NULL;
23303 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23304         struct hlist_head *head = dev_index_hash(net, ifindex);
23305  
23306         hlist_for_each_entry(dev, head, index_hlist)
23307 -               if (dev->ifindex == ifindex)
23308 +               if ((dev->ifindex == ifindex) &&
23309 +                   nx_dev_visible(current_nx_info(), dev))
23310                         return dev;
23311  
23312         return NULL;
23313 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23314   *     about locking. The caller must hold RCU lock.
23315   */
23316  
23317 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23318 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23319  {
23320         struct net_device *dev;
23321         struct hlist_head *head = dev_index_hash(net, ifindex);
23322 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23323  
23324         return NULL;
23325  }
23326 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23327 +
23328 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23329 +{
23330 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23331 +
23332 +       if (nx_dev_visible(current_nx_info(), dev))
23333 +               return dev;
23334 +       return NULL;
23335 +}
23336  EXPORT_SYMBOL(dev_get_by_index_rcu);
23337  
23338  
23339 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23340  
23341         for_each_netdev_rcu(net, dev)
23342                 if (dev->type == type &&
23343 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23344 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23345 +                   nx_dev_visible(current_nx_info(), dev))
23346                         return dev;
23347  
23348         return NULL;
23349 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23350         struct net_device *dev;
23351  
23352         ASSERT_RTNL();
23353 -       for_each_netdev(net, dev)
23354 -               if (dev->type == type)
23355 +       for_each_netdev(net, dev) {
23356 +               if ((dev->type == type) &&
23357 +                   nx_dev_visible(current_nx_info(), dev))
23358                         return dev;
23359 +       }
23360  
23361         return NULL;
23362  }
23363 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23364  
23365         rcu_read_lock();
23366         for_each_netdev_rcu(net, dev)
23367 -               if (dev->type == type) {
23368 +               if ((dev->type == type) &&
23369 +                   nx_dev_visible(current_nx_info(), dev)) {
23370                         dev_hold(dev);
23371                         ret = dev;
23372                         break;
23373 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23374  
23375         ret = NULL;
23376         for_each_netdev_rcu(net, dev) {
23377 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23378 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23379 +                       nx_dev_visible(current_nx_info(), dev)) {
23380                         ret = dev;
23381                         break;
23382                 }
23383 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23384                                 continue;
23385                         if (i < 0 || i >= max_netdevices)
23386                                 continue;
23387 +                       if (!nx_dev_visible(current_nx_info(), d))
23388 +                               continue;
23389  
23390                         /*  avoid cases where sscanf is not exact inverse of printf */
23391                         snprintf(buf, IFNAMSIZ, name, i);
23392 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
23393 --- linux-3.13.10/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23394 +++ linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c      2014-01-31 20:38:04.000000000 +0000
23395 @@ -1,6 +1,7 @@
23396  #include <linux/netdevice.h>
23397  #include <linux/proc_fs.h>
23398  #include <linux/seq_file.h>
23399 +#include <linux/vs_inet.h>
23400  #include <net/wext.h>
23401  
23402  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23403 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23404  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23405  {
23406         struct rtnl_link_stats64 temp;
23407 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23408 +       const struct rtnl_link_stats64 *stats;
23409 +
23410 +       /* device visible inside network context? */
23411 +       if (!nx_dev_visible(current_nx_info(), dev))
23412 +               return;
23413  
23414 +       stats = dev_get_stats(dev, &temp);
23415         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23416                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23417                    dev->name, stats->rx_bytes, stats->rx_packets,
23418 diff -NurpP --minimal linux-3.13.10/net/core/rtnetlink.c linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c
23419 --- linux-3.13.10/net/core/rtnetlink.c  2014-04-17 01:12:41.000000000 +0000
23420 +++ linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c       2014-04-17 01:17:11.000000000 +0000
23421 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23422                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23423                         if (idx < s_idx)
23424                                 goto cont;
23425 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23426 +                               continue;
23427                         err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23428                                                NETLINK_CB(cb->skb).portid,
23429                                                cb->nlh->nlmsg_seq, 0,
23430 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23431         int err = -ENOBUFS;
23432         size_t if_info_size;
23433  
23434 +       if (!nx_dev_visible(current_nx_info(), dev))
23435 +               return;
23436 +
23437         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23438         if (skb == NULL)
23439                 goto errout;
23440 diff -NurpP --minimal linux-3.13.10/net/core/sock.c linux-3.13.10-vs2.3.6.11/net/core/sock.c
23441 --- linux-3.13.10/net/core/sock.c       2014-04-17 01:12:41.000000000 +0000
23442 +++ linux-3.13.10-vs2.3.6.11/net/core/sock.c    2014-04-17 01:17:11.000000000 +0000
23443 @@ -133,6 +133,10 @@
23444  #include <net/netprio_cgroup.h>
23445  
23446  #include <linux/filter.h>
23447 +#include <linux/vs_socket.h>
23448 +#include <linux/vs_limit.h>
23449 +#include <linux/vs_context.h>
23450 +#include <linux/vs_network.h>
23451  
23452  #include <trace/events/sock.h>
23453  
23454 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23455                         goto out_free_sec;
23456                 sk_tx_queue_clear(sk);
23457         }
23458 +               sock_vx_init(sk);
23459 +               sock_nx_init(sk);
23460  
23461         return sk;
23462  
23463 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23464                 put_cred(sk->sk_peer_cred);
23465         put_pid(sk->sk_peer_pid);
23466         put_net(sock_net(sk));
23467 +       vx_sock_dec(sk);
23468 +       clr_vx_info(&sk->sk_vx_info);
23469 +       sk->sk_xid = -1;
23470 +       clr_nx_info(&sk->sk_nx_info);
23471 +       sk->sk_nid = -1;
23472         sk_prot_free(sk->sk_prot_creator, sk);
23473  }
23474  
23475 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23476  
23477                 /* SANITY */
23478                 get_net(sock_net(newsk));
23479 +               sock_vx_init(newsk);
23480 +               sock_nx_init(newsk);
23481                 sk_node_init(&newsk->sk_node);
23482                 sock_lock_init(newsk);
23483                 bh_lock_sock(newsk);
23484 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23485                 smp_wmb();
23486                 atomic_set(&newsk->sk_refcnt, 2);
23487  
23488 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23489 +               newsk->sk_xid = sk->sk_xid;
23490 +               vx_sock_inc(newsk);
23491 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23492 +               newsk->sk_nid = sk->sk_nid;
23493 +
23494                 /*
23495                  * Increment the counter in the same struct proto as the master
23496                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23497 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23498  
23499         sk->sk_stamp = ktime_set(-1L, 0);
23500  
23501 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23502 +       sk->sk_xid = vx_current_xid();
23503 +       vx_sock_inc(sk);
23504 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23505 +       sk->sk_nid = nx_current_nid();
23506 +
23507  #ifdef CONFIG_NET_RX_BUSY_POLL
23508         sk->sk_napi_id          =       0;
23509         sk->sk_ll_usec          =       sysctl_net_busy_read;
23510 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
23511 --- linux-3.13.10/net/ipv4/af_inet.c    2014-04-17 01:12:41.000000000 +0000
23512 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c 2014-04-17 01:17:11.000000000 +0000
23513 @@ -118,6 +118,7 @@
23514  #ifdef CONFIG_IP_MROUTE
23515  #include <linux/mroute.h>
23516  #endif
23517 +#include <linux/vs_limit.h>
23518  
23519  
23520  /* The inetsw table contains everything that inet_create needs to
23521 @@ -309,10 +310,13 @@ lookup_protocol:
23522         }
23523  
23524         err = -EPERM;
23525 +       if ((protocol == IPPROTO_ICMP) &&
23526 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23527 +               goto override;
23528         if (sock->type == SOCK_RAW && !kern &&
23529             !ns_capable(net->user_ns, CAP_NET_RAW))
23530                 goto out_rcu_unlock;
23531 -
23532 +override:
23533         sock->ops = answer->ops;
23534         answer_prot = answer->prot;
23535         answer_no_check = answer->no_check;
23536 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23537         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23538         struct sock *sk = sock->sk;
23539         struct inet_sock *inet = inet_sk(sk);
23540 +       struct nx_v4_sock_addr nsa;
23541         struct net *net = sock_net(sk);
23542         unsigned short snum;
23543         int chk_addr_ret;
23544 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23545                         goto out;
23546         }
23547  
23548 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23549 +       err = v4_map_sock_addr(inet, addr, &nsa);
23550 +       if (err)
23551 +               goto out;
23552 +
23553 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
23554  
23555         /* Not specified by any standard per-se, however it breaks too
23556          * many applications when removed.  It is unfortunate since
23557 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23558         err = -EADDRNOTAVAIL;
23559         if (!sysctl_ip_nonlocal_bind &&
23560             !(inet->freebind || inet->transparent) &&
23561 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23562 +           nsa.saddr != htonl(INADDR_ANY) &&
23563             chk_addr_ret != RTN_LOCAL &&
23564             chk_addr_ret != RTN_MULTICAST &&
23565             chk_addr_ret != RTN_BROADCAST)
23566 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23567         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23568                 goto out_release_sock;
23569  
23570 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23571 +       v4_set_sock_addr(inet, &nsa);
23572         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23573                 inet->inet_saddr = 0;  /* Use device */
23574  
23575 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23576                      peer == 1))
23577                         return -ENOTCONN;
23578                 sin->sin_port = inet->inet_dport;
23579 -               sin->sin_addr.s_addr = inet->inet_daddr;
23580 +               sin->sin_addr.s_addr =
23581 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23582         } else {
23583                 __be32 addr = inet->inet_rcv_saddr;
23584                 if (!addr)
23585                         addr = inet->inet_saddr;
23586 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23587                 sin->sin_port = inet->inet_sport;
23588                 sin->sin_addr.s_addr = addr;
23589         }
23590 diff -NurpP --minimal linux-3.13.10/net/ipv4/arp.c linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c
23591 --- linux-3.13.10/net/ipv4/arp.c        2013-11-25 15:47:06.000000000 +0000
23592 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c     2014-01-31 20:38:04.000000000 +0000
23593 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23594         struct net_device *dev = n->dev;
23595         int hatype = dev->type;
23596  
23597 +       /* FIXME: check for network context */
23598         read_lock(&n->lock);
23599         /* Convert hardware address to XX:XX:XX:XX ... form. */
23600  #if IS_ENABLED(CONFIG_AX25)
23601 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23602         int hatype = dev ? dev->type : 0;
23603         char tbuf[16];
23604  
23605 +       /* FIXME: check for network context */
23606         sprintf(tbuf, "%pI4", n->key);
23607         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23608                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23609 diff -NurpP --minimal linux-3.13.10/net/ipv4/devinet.c linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c
23610 --- linux-3.13.10/net/ipv4/devinet.c    2014-04-17 01:12:41.000000000 +0000
23611 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23612 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23613  }
23614  EXPORT_SYMBOL(inetdev_by_index);
23615  
23616 +
23617  /* Called only from RTNL semaphored context. No locks. */
23618  
23619  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23620 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23621  
23622         in_dev = __in_dev_get_rtnl(dev);
23623         if (in_dev) {
23624 +               struct nx_info *nxi = current_nx_info();
23625 +
23626                 if (tryaddrmatch) {
23627                         /* Matthias Andree */
23628                         /* compare label and address (4.4BSD style) */
23629 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23630                            This is checked above. */
23631                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23632                              ifap = &ifa->ifa_next) {
23633 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23634 +                                       continue;
23635                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23636                                     sin_orig.sin_addr.s_addr ==
23637                                                         ifa->ifa_local) {
23638 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23639                    comparing just the label */
23640                 if (!ifa) {
23641                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23642 -                            ifap = &ifa->ifa_next)
23643 +                            ifap = &ifa->ifa_next) {
23644 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23645 +                                       continue;
23646                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23647                                         break;
23648 +                       }
23649                 }
23650         }
23651  
23652 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23653                 goto out;
23654  
23655         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23656 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23657 +                       continue;
23658                 if (!buf) {
23659                         done += sizeof(ifr);
23660                         continue;
23661 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23662         struct net_device *dev;
23663         struct in_device *in_dev;
23664         struct in_ifaddr *ifa;
23665 +       struct sock *sk = skb->sk;
23666         struct hlist_head *head;
23667  
23668         s_h = cb->args[0];
23669 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23670  
23671                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23672                              ifa = ifa->ifa_next, ip_idx++) {
23673 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23674 +                               continue;
23675                                 if (ip_idx < s_ip_idx)
23676                                         continue;
23677                                 if (inet_fill_ifaddr(skb, ifa,
23678 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
23679 --- linux-3.13.10/net/ipv4/fib_trie.c   2014-01-22 20:39:15.000000000 +0000
23680 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c        2014-01-31 20:38:04.000000000 +0000
23681 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23682  
23683                         seq_setwidth(seq, 127);
23684  
23685 +                       /* FIXME: check for network context? */
23686                         if (fi)
23687                                 seq_printf(seq,
23688                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23689 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
23690 --- linux-3.13.10/net/ipv4/inet_connection_sock.c       2014-01-22 20:39:15.000000000 +0000
23691 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c    2014-02-01 00:33:11.000000000 +0000
23692 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23693  }
23694  EXPORT_SYMBOL(inet_get_local_port_range);
23695  
23696 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23697 +{
23698 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23699 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23700 +
23701 +       if (inet_v6_ipv6only(sk2))
23702 +               return 0;
23703 +
23704 +       if (sk1_rcv_saddr &&
23705 +           sk2_rcv_saddr &&
23706 +           sk1_rcv_saddr == sk2_rcv_saddr)
23707 +               return 1;
23708 +
23709 +       if (sk1_rcv_saddr &&
23710 +           !sk2_rcv_saddr &&
23711 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23712 +               return 1;
23713 +
23714 +       if (sk2_rcv_saddr &&
23715 +           !sk1_rcv_saddr &&
23716 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23717 +               return 1;
23718 +
23719 +       if (!sk1_rcv_saddr &&
23720 +           !sk2_rcv_saddr &&
23721 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23722 +               return 1;
23723 +
23724 +       return 0;
23725 +}
23726 +
23727  int inet_csk_bind_conflict(const struct sock *sk,
23728                            const struct inet_bind_bucket *tb, bool relax)
23729  {
23730 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23731                             (sk2->sk_state != TCP_TIME_WAIT &&
23732                              !uid_eq(uid, sock_i_uid(sk2))))) {
23733  
23734 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23735 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23736 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23737                                         break;
23738                         }
23739                         if (!relax && reuse && sk2->sk_reuse &&
23740                             sk2->sk_state != TCP_LISTEN) {
23741  
23742 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23743 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23744 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23745                                         break;
23746                         }
23747                 }
23748 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
23749 --- linux-3.13.10/net/ipv4/inet_diag.c  2014-02-01 02:17:51.000000000 +0000
23750 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c       2014-02-01 02:32:22.000000000 +0000
23751 @@ -31,6 +31,8 @@
23752  
23753  #include <linux/inet.h>
23754  #include <linux/stddef.h>
23755 +#include <linux/vs_network.h>
23756 +#include <linux/vs_inet.h>
23757  
23758  #include <linux/inet_diag.h>
23759  #include <linux/sock_diag.h>
23760 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23761         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23762         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23763  
23764 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
23765 -       r->id.idiag_dst[0] = inet->inet_daddr;
23766 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23767 +               inet->inet_rcv_saddr);
23768 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23769 +               inet->inet_daddr);
23770  
23771         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23772                 goto errout;
23773 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23774         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23775         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23776  
23777 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
23778 -       r->id.idiag_dst[0]    = tw->tw_daddr;
23779 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23780 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23781  
23782         r->idiag_state        = tw->tw_substate;
23783         r->idiag_timer        = 3;
23784 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23785  
23786         err = -EINVAL;
23787         if (req->sdiag_family == AF_INET) {
23788 +               /* TODO: lback */
23789                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23790                                  req->id.idiag_dport, req->id.idiag_src[0],
23791                                  req->id.idiag_sport, req->id.idiag_if);
23792         }
23793  #if IS_ENABLED(CONFIG_IPV6)
23794         else if (req->sdiag_family == AF_INET6) {
23795 +               /* TODO: lback */
23796                 sk = inet6_lookup(net, hashinfo,
23797                                   (struct in6_addr *)req->id.idiag_dst,
23798                                   req->id.idiag_dport,
23799 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23800         } else
23801  #endif
23802         {
23803 +                       /* TODO: lback */
23804                 entry.saddr = &inet->inet_rcv_saddr;
23805                 entry.daddr = &inet->inet_daddr;
23806         }
23807 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23808                 } else
23809  #endif
23810                 {
23811 +                       /* TODO: lback */
23812                         entry.saddr = &tw->tw_rcv_saddr;
23813                         entry.daddr = &tw->tw_daddr;
23814                 }
23815 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23816         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23817         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23818  
23819 -       r->id.idiag_src[0] = ireq->ir_loc_addr;
23820 -       r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23821 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23822 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23823  
23824         r->idiag_expires = jiffies_to_msecs(tmo);
23825         r->idiag_rqueue = 0;
23826 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23827                             r->id.idiag_dport)
23828                                 continue;
23829  
23830 +                       /* TODO: lback */
23831                         if (bc) {
23832                                 inet_diag_req_addrs(sk, req, &entry);
23833                                 entry.dport = ntohs(ireq->ir_rmt_port);
23834 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23835                                 if (!net_eq(sock_net(sk), net))
23836                                         continue;
23837  
23838 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23839 +                                       continue;
23840                                 if (num < s_num) {
23841                                         num++;
23842                                         continue;
23843 @@ -934,6 +945,8 @@ skip_listen_ht:
23844  
23845                         if (!net_eq(sock_net(sk), net))
23846                                 continue;
23847 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23848 +                               continue;
23849                         if (num < s_num)
23850                                 goto next_normal;
23851                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23852 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
23853 --- linux-3.13.10/net/ipv4/inet_hashtables.c    2014-01-22 20:39:15.000000000 +0000
23854 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23855 @@ -22,6 +22,7 @@
23856  #include <net/inet_connection_sock.h>
23857  #include <net/inet_hashtables.h>
23858  #include <net/secure_seq.h>
23859 +#include <net/route.h>
23860  #include <net/ip.h>
23861  
23862  static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23863 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23864                         if (rcv_saddr != daddr)
23865                                 return -1;
23866                         score += 4;
23867 +               } else {
23868 +                       /* block non nx_info ips */
23869 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23870 +                               daddr, NXA_MASK_BIND))
23871 +                               return -1;
23872                 }
23873                 if (sk->sk_bound_dev_if) {
23874                         if (sk->sk_bound_dev_if != dif)
23875 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23876   * wildcarded during the search since they can never be otherwise.
23877   */
23878  
23879 -
23880  struct sock *__inet_lookup_listener(struct net *net,
23881                                     struct inet_hashinfo *hashinfo,
23882                                     const __be32 saddr, __be16 sport,
23883 @@ -234,6 +239,7 @@ begin:
23884                         phash = next_pseudo_random32(phash);
23885                 }
23886         }
23887 +
23888         /*
23889          * if the nulls value we got at the end of this lookup is
23890          * not the expected one, we must restart lookup.
23891 diff -NurpP --minimal linux-3.13.10/net/ipv4/netfilter.c linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c
23892 --- linux-3.13.10/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
23893 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c       2014-01-31 20:38:04.000000000 +0000
23894 @@ -11,7 +11,7 @@
23895  #include <linux/skbuff.h>
23896  #include <linux/gfp.h>
23897  #include <linux/export.h>
23898 -#include <net/route.h>
23899 +// #include <net/route.h>
23900  #include <net/xfrm.h>
23901  #include <net/ip.h>
23902  #include <net/netfilter/nf_queue.h>
23903 diff -NurpP --minimal linux-3.13.10/net/ipv4/raw.c linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c
23904 --- linux-3.13.10/net/ipv4/raw.c        2014-01-22 20:39:15.000000000 +0000
23905 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c     2014-01-31 20:38:04.000000000 +0000
23906 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23907  
23908                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23909                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23910 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23911 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23912                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23913                         goto found; /* gotcha */
23914         }
23915 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23916                 icmp_out_count(net, ((struct icmphdr *)
23917                         skb_transport_header(skb))->type);
23918  
23919 +       err = -EPERM;
23920 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23921 +               sk->sk_nx_info &&
23922 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23923 +               goto error_free;
23924 +
23925         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23926                       rt->dst.dev, dst_output);
23927         if (err > 0)
23928 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23929                         goto done;
23930         }
23931  
23932 +       if (sk->sk_nx_info) {
23933 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23934 +               if (IS_ERR(rt)) {
23935 +                       err = PTR_ERR(rt);
23936 +                       rt = NULL;
23937 +                       goto done;
23938 +               }
23939 +               ip_rt_put(rt);
23940 +       }
23941 +
23942         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23943         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23944         if (IS_ERR(rt)) {
23945 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23946  {
23947         struct inet_sock *inet = inet_sk(sk);
23948         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23949 +       struct nx_v4_sock_addr nsa = { 0 };
23950         int ret = -EINVAL;
23951         int chk_addr_ret;
23952  
23953         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23954                 goto out;
23955 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23956 +       v4_map_sock_addr(inet, addr, &nsa);
23957 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23958         ret = -EADDRNOTAVAIL;
23959 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23960 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23961             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23962                 goto out;
23963 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23964 +       v4_set_sock_addr(inet, &nsa);
23965         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23966                 inet->inet_saddr = 0;  /* Use device */
23967         sk_dst_reset(sk);
23968 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
23969         /* Copy the address. */
23970         if (sin) {
23971                 sin->sin_family = AF_INET;
23972 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23973 +               sin->sin_addr.s_addr =
23974 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23975                 sin->sin_port = 0;
23976                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23977                 *addr_len = sizeof(*sin);
23978 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
23979         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23980                         ++state->bucket) {
23981                 sk_for_each(sk, &state->h->ht[state->bucket])
23982 -                       if (sock_net(sk) == seq_file_net(seq))
23983 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
23984 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23985                                 goto found;
23986         }
23987         sk = NULL;
23988 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
23989                 sk = sk_next(sk);
23990  try_again:
23991                 ;
23992 -       } while (sk && sock_net(sk) != seq_file_net(seq));
23993 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23994 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23995  
23996         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23997                 sk = sk_head(&state->h->ht[state->bucket]);
23998 diff -NurpP --minimal linux-3.13.10/net/ipv4/route.c linux-3.13.10-vs2.3.6.11/net/ipv4/route.c
23999 --- linux-3.13.10/net/ipv4/route.c      2014-04-17 01:12:41.000000000 +0000
24000 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/route.c   2014-03-12 15:51:08.000000000 +0000
24001 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24002  
24003  
24004         if (fl4->flowi4_oif) {
24005 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24006 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24007                 rth = ERR_PTR(-ENODEV);
24008                 if (dev_out == NULL)
24009                         goto out;
24010 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c
24011 --- linux-3.13.10/net/ipv4/tcp.c        2014-04-17 01:12:41.000000000 +0000
24012 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c     2014-04-17 01:17:11.000000000 +0000
24013 @@ -268,6 +268,7 @@
24014  #include <linux/crypto.h>
24015  #include <linux/time.h>
24016  #include <linux/slab.h>
24017 +#include <linux/in.h>
24018  
24019  #include <net/icmp.h>
24020  #include <net/inet_common.h>
24021 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
24022 --- linux-3.13.10/net/ipv4/tcp_ipv4.c   2014-04-17 01:12:41.000000000 +0000
24023 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c        2014-04-17 01:17:11.000000000 +0000
24024 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24025                 req = req->dl_next;
24026                 while (1) {
24027                         while (req) {
24028 +                               vxdprintk(VXD_CBIT(net, 6),
24029 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24030 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24031 +                               if (req->sk &&
24032 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24033 +                                       continue;
24034                                 if (req->rsk_ops->family == st->family) {
24035                                         cur = req;
24036                                         goto out;
24037 @@ -2251,6 +2257,10 @@ get_req:
24038         }
24039  get_sk:
24040         sk_nulls_for_each_from(sk, node) {
24041 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24042 +                       sk, sk->sk_nid, nx_current_nid());
24043 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24044 +                       continue;
24045                 if (!net_eq(sock_net(sk), net))
24046                         continue;
24047                 if (sk->sk_family == st->family) {
24048 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24049  
24050                 spin_lock_bh(lock);
24051                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24052 +                       vxdprintk(VXD_CBIT(net, 6),
24053 +                               "sk,egf: %p [#%d] (from %d)",
24054 +                               sk, sk->sk_nid, nx_current_nid());
24055 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24056 +                               continue;
24057                         if (sk->sk_family != st->family ||
24058                             !net_eq(sock_net(sk), net)) {
24059                                 continue;
24060 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24061         sk = sk_nulls_next(sk);
24062  
24063         sk_nulls_for_each_from(sk, node) {
24064 +               vxdprintk(VXD_CBIT(net, 6),
24065 +                       "sk,egn: %p [#%d] (from %d)",
24066 +                       sk, sk->sk_nid, nx_current_nid());
24067 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24068 +                       continue;
24069                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24070                         return sk;
24071         }
24072 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24073         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24074                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24075                 i,
24076 -               ireq->ir_loc_addr,
24077 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24078                 ntohs(inet_sk(sk)->inet_sport),
24079 -               ireq->ir_rmt_addr,
24080 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24081                 ntohs(ireq->ir_rmt_port),
24082                 TCP_SYN_RECV,
24083                 0, 0, /* could print option size, but that is af dependent. */
24084 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24085         const struct inet_connection_sock *icsk = inet_csk(sk);
24086         const struct inet_sock *inet = inet_sk(sk);
24087         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24088 -       __be32 dest = inet->inet_daddr;
24089 -       __be32 src = inet->inet_rcv_saddr;
24090 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24091 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24092         __u16 destp = ntohs(inet->inet_dport);
24093         __u16 srcp = ntohs(inet->inet_sport);
24094         int rx_queue;
24095 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24096         __u16 destp, srcp;
24097         s32 delta = tw->tw_ttd - inet_tw_time_stamp();
24098  
24099 -       dest  = tw->tw_daddr;
24100 -       src   = tw->tw_rcv_saddr;
24101 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24102 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24103         destp = ntohs(tw->tw_dport);
24104         srcp  = ntohs(tw->tw_sport);
24105  
24106 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
24107 --- linux-3.13.10/net/ipv4/tcp_minisocks.c      2014-01-22 20:39:15.000000000 +0000
24108 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c   2014-01-31 20:38:04.000000000 +0000
24109 @@ -23,6 +23,9 @@
24110  #include <linux/slab.h>
24111  #include <linux/sysctl.h>
24112  #include <linux/workqueue.h>
24113 +#include <linux/vs_limit.h>
24114 +#include <linux/vs_socket.h>
24115 +#include <linux/vs_context.h>
24116  #include <net/tcp.h>
24117  #include <net/inet_common.h>
24118  #include <net/xfrm.h>
24119 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24120                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24121                 tcptw->tw_ts_offset     = tp->tsoffset;
24122  
24123 +               tw->tw_xid              = sk->sk_xid;
24124 +               tw->tw_vx_info          = NULL;
24125 +               tw->tw_nid              = sk->sk_nid;
24126 +               tw->tw_nx_info          = NULL;
24127 +
24128  #if IS_ENABLED(CONFIG_IPV6)
24129                 if (tw->tw_family == PF_INET6) {
24130                         struct ipv6_pinfo *np = inet6_sk(sk);
24131 diff -NurpP --minimal linux-3.13.10/net/ipv4/udp.c linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c
24132 --- linux-3.13.10/net/ipv4/udp.c        2014-01-22 20:39:15.000000000 +0000
24133 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c     2014-01-31 22:20:27.000000000 +0000
24134 @@ -308,14 +308,7 @@ fail:
24135  }
24136  EXPORT_SYMBOL(udp_lib_get_port);
24137  
24138 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24139 -{
24140 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24141 -
24142 -       return  (!ipv6_only_sock(sk2)  &&
24143 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24144 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24145 -}
24146 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24147  
24148  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24149                                        unsigned int port)
24150 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24151                         if (inet->inet_rcv_saddr != daddr)
24152                                 return -1;
24153                         score += 4;
24154 +               } else {
24155 +                       /* block non nx_info ips */
24156 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24157 +                               daddr, NXA_MASK_BIND))
24158 +                               return -1;
24159                 }
24160                 if (inet->inet_daddr) {
24161                         if (inet->inet_daddr != saddr)
24162 @@ -472,6 +470,7 @@ begin:
24163         return result;
24164  }
24165  
24166 +
24167  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24168   * harder than this. -DaveM
24169   */
24170 @@ -518,6 +517,11 @@ begin:
24171         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24172                 score = compute_score(sk, net, saddr, hnum, sport,
24173                                       daddr, dport, dif);
24174 +               /* FIXME: disabled?
24175 +               if (score == 9) {
24176 +                       result = sk;
24177 +                       break;
24178 +               } else */
24179                 if (score > badness) {
24180                         result = sk;
24181                         badness = score;
24182 @@ -542,6 +546,7 @@ begin:
24183         if (get_nulls_value(node) != slot)
24184                 goto begin;
24185  
24186 +
24187         if (result) {
24188                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24189                         result = NULL;
24190 @@ -551,6 +556,7 @@ begin:
24191                         goto begin;
24192                 }
24193         }
24194 +
24195         rcu_read_unlock();
24196         return result;
24197  }
24198 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24199             udp_sk(sk)->udp_port_hash != hnum ||
24200             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24201             (inet->inet_dport != rmt_port && inet->inet_dport) ||
24202 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24203 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24204             ipv6_only_sock(sk) ||
24205             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24206                 return false;
24207 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24208                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24209                                    faddr, saddr, dport, inet->inet_sport);
24210  
24211 +               if (sk->sk_nx_info) {
24212 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24213 +                       if (IS_ERR(rt)) {
24214 +                               err = PTR_ERR(rt);
24215 +                               rt = NULL;
24216 +                               goto out;
24217 +                       }
24218 +                       ip_rt_put(rt);
24219 +               }
24220 +
24221                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24222                 rt = ip_route_output_flow(net, fl4, sk);
24223                 if (IS_ERR(rt)) {
24224 @@ -1293,7 +1309,8 @@ try_again:
24225         if (sin) {
24226                 sin->sin_family = AF_INET;
24227                 sin->sin_port = udp_hdr(skb)->source;
24228 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24229 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24230 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24231                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24232                 *addr_len = sizeof(*sin);
24233         }
24234 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24235                 sk_nulls_for_each(sk, node, &hslot->head) {
24236                         if (!net_eq(sock_net(sk), net))
24237                                 continue;
24238 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24239 +                               continue;
24240                         if (sk->sk_family == state->family)
24241                                 goto found;
24242                 }
24243 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24244  
24245         do {
24246                 sk = sk_nulls_next(sk);
24247 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24248 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24249 +               sk->sk_family != state->family ||
24250 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24251  
24252         if (!sk) {
24253                 if (state->bucket <= state->udp_table->mask)
24254 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24255                 int bucket)
24256  {
24257         struct inet_sock *inet = inet_sk(sp);
24258 -       __be32 dest = inet->inet_daddr;
24259 -       __be32 src  = inet->inet_rcv_saddr;
24260 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24261 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24262         __u16 destp       = ntohs(inet->inet_dport);
24263         __u16 srcp        = ntohs(inet->inet_sport);
24264  
24265 diff -NurpP --minimal linux-3.13.10/net/ipv6/Kconfig linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig
24266 --- linux-3.13.10/net/ipv6/Kconfig      2014-01-22 20:39:15.000000000 +0000
24267 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig   2014-01-31 20:38:04.000000000 +0000
24268 @@ -4,8 +4,8 @@
24269  
24270  #   IPv6 as module will cause a CRASH if you try to unload it
24271  menuconfig IPV6
24272 -       tristate "The IPv6 protocol"
24273 -       default m
24274 +       bool "The IPv6 protocol"
24275 +       default n
24276         ---help---
24277           This is complemental support for the IP version 6.
24278           You will still be able to do traditional IPv4 networking as well.
24279 diff -NurpP --minimal linux-3.13.10/net/ipv6/addrconf.c linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c
24280 --- linux-3.13.10/net/ipv6/addrconf.c   2014-04-17 01:12:41.000000000 +0000
24281 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c        2014-04-17 01:17:11.000000000 +0000
24282 @@ -90,6 +90,8 @@
24283  #include <linux/proc_fs.h>
24284  #include <linux/seq_file.h>
24285  #include <linux/export.h>
24286 +#include <linux/vs_network.h>
24287 +#include <linux/vs_inet6.h>
24288  
24289  /* Set to 3 to get tracing... */
24290  #define ACONF_DEBUG 2
24291 @@ -1284,7 +1286,7 @@ out:
24292  
24293  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24294                        const struct in6_addr *daddr, unsigned int prefs,
24295 -                      struct in6_addr *saddr)
24296 +                      struct in6_addr *saddr, struct nx_info *nxi)
24297  {
24298         struct ipv6_saddr_score scores[2],
24299                                 *score = &scores[0], *hiscore = &scores[1];
24300 @@ -1356,6 +1358,8 @@ int ipv6_dev_get_saddr(struct net *net,
24301                                                dev->name);
24302                                 continue;
24303                         }
24304 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24305 +                               continue;
24306  
24307                         score->rule = -1;
24308                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24309 @@ -3371,7 +3375,10 @@ static void if6_seq_stop(struct seq_file
24310  static int if6_seq_show(struct seq_file *seq, void *v)
24311  {
24312         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24313 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24314 +
24315 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24316 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24317 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24318                    &ifp->addr,
24319                    ifp->idev->dev->ifindex,
24320                    ifp->prefix_len,
24321 @@ -3892,6 +3899,11 @@ static int in6_dump_addrs(struct inet6_d
24322         struct ifacaddr6 *ifaca;
24323         int err = 1;
24324         int ip_idx = *p_ip_idx;
24325 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24326 +
24327 +       /* disable ipv6 on non v6 guests */
24328 +       if (nxi && !nx_info_has_v6(nxi))
24329 +               return skb->len;
24330  
24331         read_lock_bh(&idev->lock);
24332         switch (type) {
24333 @@ -3902,6 +3914,8 @@ static int in6_dump_addrs(struct inet6_d
24334                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24335                         if (++ip_idx < s_ip_idx)
24336                                 continue;
24337 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24338 +                                       continue;
24339                         err = inet6_fill_ifaddr(skb, ifa,
24340                                                 NETLINK_CB(cb->skb).portid,
24341                                                 cb->nlh->nlmsg_seq,
24342 @@ -3919,6 +3933,8 @@ static int in6_dump_addrs(struct inet6_d
24343                      ifmca = ifmca->next, ip_idx++) {
24344                         if (ip_idx < s_ip_idx)
24345                                 continue;
24346 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24347 +                                       continue;
24348                         err = inet6_fill_ifmcaddr(skb, ifmca,
24349                                                   NETLINK_CB(cb->skb).portid,
24350                                                   cb->nlh->nlmsg_seq,
24351 @@ -3934,6 +3950,8 @@ static int in6_dump_addrs(struct inet6_d
24352                      ifaca = ifaca->aca_next, ip_idx++) {
24353                         if (ip_idx < s_ip_idx)
24354                                 continue;
24355 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24356 +                                       continue;
24357                         err = inet6_fill_ifacaddr(skb, ifaca,
24358                                                   NETLINK_CB(cb->skb).portid,
24359                                                   cb->nlh->nlmsg_seq,
24360 @@ -3962,6 +3980,10 @@ static int inet6_dump_addr(struct sk_buf
24361         struct inet6_dev *idev;
24362         struct hlist_head *head;
24363  
24364 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24365 +       if (skb->sk && skb->sk->sk_vx_info)
24366 +               return skb->len; */
24367 +
24368         s_h = cb->args[0];
24369         s_idx = idx = cb->args[1];
24370         s_ip_idx = ip_idx = cb->args[2];
24371 @@ -4404,6 +4426,7 @@ static int inet6_dump_ifinfo(struct sk_b
24372         struct net_device *dev;
24373         struct inet6_dev *idev;
24374         struct hlist_head *head;
24375 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24376  
24377         s_h = cb->args[0];
24378         s_idx = cb->args[1];
24379 @@ -4415,6 +4438,8 @@ static int inet6_dump_ifinfo(struct sk_b
24380                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24381                         if (idx < s_idx)
24382                                 goto cont;
24383 +                       if (!v6_dev_in_nx_info(dev, nxi))
24384 +                               goto cont;
24385                         idev = __in6_dev_get(dev);
24386                         if (!idev)
24387                                 goto cont;
24388 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
24389 --- linux-3.13.10/net/ipv6/af_inet6.c   2014-01-22 20:39:15.000000000 +0000
24390 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c        2014-01-31 21:39:03.000000000 +0000
24391 @@ -43,6 +43,8 @@
24392  #include <linux/netdevice.h>
24393  #include <linux/icmpv6.h>
24394  #include <linux/netfilter_ipv6.h>
24395 +#include <linux/vs_inet.h>
24396 +#include <linux/vs_inet6.h>
24397  
24398  #include <net/ip.h>
24399  #include <net/ipv6.h>
24400 @@ -156,10 +158,13 @@ lookup_protocol:
24401         }
24402  
24403         err = -EPERM;
24404 +       if ((protocol == IPPROTO_ICMPV6) &&
24405 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24406 +               goto override;
24407         if (sock->type == SOCK_RAW && !kern &&
24408             !ns_capable(net->user_ns, CAP_NET_RAW))
24409                 goto out_rcu_unlock;
24410 -
24411 +override:
24412         sock->ops = answer->ops;
24413         answer_prot = answer->prot;
24414         answer_no_check = answer->no_check;
24415 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24416         struct inet_sock *inet = inet_sk(sk);
24417         struct ipv6_pinfo *np = inet6_sk(sk);
24418         struct net *net = sock_net(sk);
24419 +       struct nx_v6_sock_addr nsa;
24420         __be32 v4addr = 0;
24421         unsigned short snum;
24422         int addr_type = 0;
24423 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24424         if (addr->sin6_family != AF_INET6)
24425                 return -EAFNOSUPPORT;
24426  
24427 +       err = v6_map_sock_addr(inet, addr, &nsa);
24428 +       if (err)
24429 +               return err;
24430 +
24431         addr_type = ipv6_addr_type(&addr->sin6_addr);
24432         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24433                 return -EINVAL;
24434 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24435                 /* Reproduce AF_INET checks to make the bindings consistent */
24436                 v4addr = addr->sin6_addr.s6_addr32[3];
24437                 chk_addr_ret = inet_addr_type(net, v4addr);
24438 +
24439                 if (!sysctl_ip_nonlocal_bind &&
24440                     !(inet->freebind || inet->transparent) &&
24441                     v4addr != htonl(INADDR_ANY) &&
24442 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24443                         err = -EADDRNOTAVAIL;
24444                         goto out;
24445                 }
24446 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24447 +                       err = -EADDRNOTAVAIL;
24448 +                       goto out;
24449 +               }
24450         } else {
24451                 if (addr_type != IPV6_ADDR_ANY) {
24452                         struct net_device *dev = NULL;
24453 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24454                                 }
24455                         }
24456  
24457 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24458 +                               err = -EADDRNOTAVAIL;
24459 +                               goto out_unlock;
24460 +                       }
24461 +
24462                         /* ipv4 addr of the socket is invalid.  Only the
24463                          * unspecified and mapped address have a v4 equivalent.
24464                          */
24465 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24466                 }
24467         }
24468  
24469 +       /* what's that for? */
24470 +       v6_set_sock_addr(inet, &nsa);
24471 +
24472         inet->inet_rcv_saddr = v4addr;
24473         inet->inet_saddr = v4addr;
24474  
24475 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24476                         return -ENOTCONN;
24477                 sin->sin6_port = inet->inet_dport;
24478                 sin->sin6_addr = sk->sk_v6_daddr;
24479 +               /* FIXME: remap lback? */
24480                 if (np->sndflow)
24481                         sin->sin6_flowinfo = np->flow_label;
24482         } else {
24483 +               /* FIXME: remap lback? */
24484                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24485                         sin->sin6_addr = np->saddr;
24486                 else
24487 diff -NurpP --minimal linux-3.13.10/net/ipv6/datagram.c linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c
24488 --- linux-3.13.10/net/ipv6/datagram.c   2014-01-22 20:39:15.000000000 +0000
24489 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c        2014-01-31 20:38:04.000000000 +0000
24490 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24491  
24492                         rcu_read_lock();
24493                         if (fl6->flowi6_oif) {
24494 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24495 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24496                                 if (!dev) {
24497                                         rcu_read_unlock();
24498                                         return -ENODEV;
24499 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
24500 --- linux-3.13.10/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24501 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c      2014-01-31 20:38:04.000000000 +0000
24502 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24503                                                ip6_dst_idev(&rt->dst)->dev,
24504                                                &flp6->daddr,
24505                                                rt6_flags2srcprefs(flags),
24506 -                                              &saddr))
24507 +                                              &saddr, NULL))
24508                                 goto again;
24509                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24510                                                r->src.plen))
24511 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
24512 --- linux-3.13.10/net/ipv6/inet6_hashtables.c   2014-01-22 20:39:15.000000000 +0000
24513 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c        2014-01-31 20:38:04.000000000 +0000
24514 @@ -16,6 +16,7 @@
24515  
24516  #include <linux/module.h>
24517  #include <linux/random.h>
24518 +#include <linux/vs_inet6.h>
24519  
24520  #include <net/inet_connection_sock.h>
24521  #include <net/inet_hashtables.h>
24522 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24523         unsigned int slot = hash & hashinfo->ehash_mask;
24524         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24525  
24526 -
24527         rcu_read_lock();
24528  begin:
24529         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24530 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24531                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24532                                 return -1;
24533                         score++;
24534 +               } else {
24535 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24536 +                               return -1;
24537                 }
24538                 if (sk->sk_bound_dev_if) {
24539                         if (sk->sk_bound_dev_if != dif)
24540 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
24541 --- linux-3.13.10/net/ipv6/ip6_fib.c    2014-01-22 20:39:15.000000000 +0000
24542 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24543 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24544         struct rt6_info *rt = v;
24545         struct ipv6_route_iter *iter = seq->private;
24546  
24547 +       /* FIXME: check for network context? */
24548         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24549  
24550  #ifdef CONFIG_IPV6_SUBTREES
24551 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
24552 --- linux-3.13.10/net/ipv6/ip6_output.c 2014-04-17 01:12:41.000000000 +0000
24553 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c      2014-04-17 01:17:11.000000000 +0000
24554 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24555                 struct rt6_info *rt = (struct rt6_info *) *dst;
24556                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24557                                           sk ? inet6_sk(sk)->srcprefs : 0,
24558 -                                         &fl6->saddr);
24559 +                                         &fl6->saddr,
24560 +                                         sk ? sk->sk_nx_info : NULL);
24561                 if (err)
24562                         goto out_err_release;
24563         }
24564 diff -NurpP --minimal linux-3.13.10/net/ipv6/ndisc.c linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c
24565 --- linux-3.13.10/net/ipv6/ndisc.c      2014-01-22 20:39:15.000000000 +0000
24566 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c   2014-01-31 20:38:04.000000000 +0000
24567 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24568         } else {
24569                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24570                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24571 -                                      &tmpaddr))
24572 +                                      &tmpaddr, NULL))
24573                         return;
24574                 src_addr = &tmpaddr;
24575         }
24576 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
24577 --- linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-11-25 15:47:07.000000000 +0000
24578 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c       2014-01-31 20:38:04.000000000 +0000
24579 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24580                             ctinfo == IP_CT_RELATED_REPLY));
24581  
24582         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24583 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24584 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24585                 return NF_DROP;
24586  
24587         nfct_nat(ct)->masq_index = par->out->ifindex;
24588 diff -NurpP --minimal linux-3.13.10/net/ipv6/raw.c linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c
24589 --- linux-3.13.10/net/ipv6/raw.c        2014-01-22 20:39:15.000000000 +0000
24590 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c     2014-01-31 20:38:04.000000000 +0000
24591 @@ -30,6 +30,7 @@
24592  #include <linux/icmpv6.h>
24593  #include <linux/netfilter.h>
24594  #include <linux/netfilter_ipv6.h>
24595 +#include <linux/vs_inet6.h>
24596  #include <linux/skbuff.h>
24597  #include <linux/compat.h>
24598  #include <asm/uaccess.h>
24599 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24600                                 goto out_unlock;
24601                 }
24602  
24603 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24604 +                       err = -EADDRNOTAVAIL;
24605 +                       if (dev)
24606 +                               dev_put(dev);
24607 +                       goto out;
24608 +               }
24609 +
24610                 /* ipv4 addr of the socket is invalid.  Only the
24611                  * unspecified and mapped address have a v4 equivalent.
24612                  */
24613 diff -NurpP --minimal linux-3.13.10/net/ipv6/route.c linux-3.13.10-vs2.3.6.11/net/ipv6/route.c
24614 --- linux-3.13.10/net/ipv6/route.c      2014-04-17 01:12:41.000000000 +0000
24615 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/route.c   2014-04-17 01:17:11.000000000 +0000
24616 @@ -58,6 +58,7 @@
24617  #include <net/netevent.h>
24618  #include <net/netlink.h>
24619  #include <net/nexthop.h>
24620 +#include <linux/vs_inet6.h>
24621  
24622  #include <asm/uaccess.h>
24623  
24624 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24625                         struct rt6_info *rt,
24626                         const struct in6_addr *daddr,
24627                         unsigned int prefs,
24628 -                       struct in6_addr *saddr)
24629 +                       struct in6_addr *saddr,
24630 +                       struct nx_info *nxi)
24631  {
24632         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24633         int err = 0;
24634 -       if (rt->rt6i_prefsrc.plen)
24635 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
24636 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24637                 *saddr = rt->rt6i_prefsrc.addr;
24638         else
24639                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24640 -                                        daddr, prefs, saddr);
24641 +                                        daddr, prefs, saddr, nxi);
24642         return err;
24643  }
24644  
24645 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24646                                 goto nla_put_failure;
24647         } else if (dst) {
24648                 struct in6_addr saddr_buf;
24649 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24650 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24651 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24652                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24653                         goto nla_put_failure;
24654         }
24655 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
24656 --- linux-3.13.10/net/ipv6/tcp_ipv6.c   2014-01-22 20:39:15.000000000 +0000
24657 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c        2014-01-31 20:38:04.000000000 +0000
24658 @@ -72,6 +72,7 @@
24659  
24660  #include <linux/crypto.h>
24661  #include <linux/scatterlist.h>
24662 +#include <linux/vs_inet6.h>
24663  
24664  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24665  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24666 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24667          *      connect() to INADDR_ANY means loopback (BSD'ism).
24668          */
24669  
24670 -       if (ipv6_addr_any(&usin->sin6_addr))
24671 -               usin->sin6_addr.s6_addr[15] = 0x1;
24672 +       if (ipv6_addr_any(&usin->sin6_addr)) {
24673 +               struct nx_info *nxi =  sk->sk_nx_info;
24674 +
24675 +               if (nxi && nx_info_has_v6(nxi))
24676 +                       /* FIXME: remap lback? */
24677 +                       usin->sin6_addr = nxi->v6.ip;
24678 +               else
24679 +                       usin->sin6_addr.s6_addr[15] = 0x1;
24680 +       }
24681  
24682         addr_type = ipv6_addr_type(&usin->sin6_addr);
24683  
24684 diff -NurpP --minimal linux-3.13.10/net/ipv6/udp.c linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c
24685 --- linux-3.13.10/net/ipv6/udp.c        2014-01-22 20:39:15.000000000 +0000
24686 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c     2014-02-01 02:33:38.000000000 +0000
24687 @@ -47,6 +47,7 @@
24688  #include <net/xfrm.h>
24689  #include <net/inet6_hashtables.h>
24690  #include <net/busy_poll.h>
24691 +#include <linux/vs_inet6.h>
24692  
24693  #include <linux/proc_fs.h>
24694  #include <linux/seq_file.h>
24695 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24696                                udp_ipv6_hash_secret + net_hash_mix(net));
24697  }
24698  
24699 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24700 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24701  {
24702 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24703         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24704 -       int sk_ipv6only = ipv6_only_sock(sk);
24705 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24706 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24707 +       int sk1_ipv6only = ipv6_only_sock(sk1);
24708         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24709 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24710 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24711         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24712  
24713         /* if both are mapped, treat as IPv4 */
24714 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24715 -               return (!sk2_ipv6only &&
24716 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24717 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24718 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24719 +               if (!sk2_ipv6only &&
24720 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24721 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24722 +                       goto vs_v4;
24723 +               else
24724 +                       return 0;
24725 +       }
24726  
24727         if (addr_type2 == IPV6_ADDR_ANY &&
24728 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24729 -               return 1;
24730 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24731 +               goto vs;
24732  
24733 -       if (addr_type == IPV6_ADDR_ANY &&
24734 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24735 -               return 1;
24736 +       if (addr_type1 == IPV6_ADDR_ANY &&
24737 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24738 +               goto vs;
24739  
24740         if (sk2_rcv_saddr6 &&
24741 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24742 -               return 1;
24743 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24744 +               goto vs;
24745  
24746         return 0;
24747 +
24748 +vs_v4:
24749 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24750 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24751 +       if (!sk2_rcv_saddr)
24752 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24753 +       if (!sk1_rcv_saddr)
24754 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24755 +       return 1;
24756 +vs:
24757 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24758 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24759 +       else if (addr_type2 == IPV6_ADDR_ANY)
24760 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24761 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24762 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24763 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24764 +               else
24765 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24766 +       }
24767 +       return 1;
24768  }
24769  
24770  static unsigned int udp6_portaddr_hash(struct net *net,
24771 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24772                         if (inet->inet_dport != sport)
24773                                 return -1;
24774                         score++;
24775 +               } else {
24776 +                       /* block non nx_info ips */
24777 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24778 +                               return -1;
24779                 }
24780                 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24781                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24782 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
24783 --- linux-3.13.10/net/ipv6/xfrm6_policy.c       2014-01-22 20:39:15.000000000 +0000
24784 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c    2014-01-31 20:38:04.000000000 +0000
24785 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24786         dev = ip6_dst_idev(dst)->dev;
24787         ipv6_dev_get_saddr(dev_net(dev), dev,
24788                            (struct in6_addr *)&daddr->a6, 0,
24789 -                          (struct in6_addr *)&saddr->a6);
24790 +                          (struct in6_addr *)&saddr->a6, NULL);
24791         dst_release(dst);
24792         return 0;
24793  }
24794 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
24795 --- linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c       2013-11-25 15:47:07.000000000 +0000
24796 +++ linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c    2014-01-31 20:38:04.000000000 +0000
24797 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24798                 return dst;
24799         if (ipv6_addr_any(&fl6.saddr) &&
24800             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24801 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24802 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24803                 goto out_err;
24804         if (do_xfrm) {
24805                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24806 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
24807 --- linux-3.13.10/net/netlink/af_netlink.c      2014-01-22 20:39:16.000000000 +0000
24808 +++ linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c   2014-02-25 11:47:07.000000000 +0000
24809 @@ -58,6 +58,9 @@
24810  #include <linux/mutex.h>
24811  #include <linux/vmalloc.h>
24812  #include <linux/if_arp.h>
24813 +#include <linux/vs_context.h>
24814 +#include <linux/vs_network.h>
24815 +#include <linux/vs_limit.h>
24816  #include <asm/cacheflush.h>
24817  
24818  #include <net/net_namespace.h>
24819 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24820                         sk_for_each(s, &hash->table[j]) {
24821                                 if (sock_net(s) != seq_file_net(seq))
24822                                         continue;
24823 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24824 +                                       continue;
24825                                 if (off == pos) {
24826                                         iter->link = i;
24827                                         iter->hash_idx = j;
24828 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24829         s = v;
24830         do {
24831                 s = sk_next(s);
24832 -       } while (s && !nl_table[s->sk_protocol].compare(net, s));
24833 +       } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24834 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24835         if (s)
24836                 return s;
24837  
24838 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24839                 for (; j <= hash->mask; j++) {
24840                         s = sk_head(&hash->table[j]);
24841  
24842 -                       while (s && !nl_table[s->sk_protocol].compare(net, s))
24843 +                       while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24844 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24845                                 s = sk_next(s);
24846                         if (s) {
24847                                 iter->link = i;
24848 diff -NurpP --minimal linux-3.13.10/net/socket.c linux-3.13.10-vs2.3.6.11/net/socket.c
24849 --- linux-3.13.10/net/socket.c  2014-04-17 01:12:42.000000000 +0000
24850 +++ linux-3.13.10-vs2.3.6.11/net/socket.c       2014-04-17 01:17:11.000000000 +0000
24851 @@ -98,6 +98,9 @@
24852  
24853  #include <net/sock.h>
24854  #include <linux/netfilter.h>
24855 +#include <linux/vs_socket.h>
24856 +#include <linux/vs_inet.h>
24857 +#include <linux/vs_inet6.h>
24858  
24859  #include <linux/if_tun.h>
24860  #include <linux/ipv6_route.h>
24861 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24862                                        struct msghdr *msg, size_t size)
24863  {
24864         struct sock_iocb *si = kiocb_to_siocb(iocb);
24865 +       size_t len;
24866  
24867         si->sock = sock;
24868         si->scm = NULL;
24869         si->msg = msg;
24870         si->size = size;
24871  
24872 -       return sock->ops->sendmsg(iocb, sock, msg, size);
24873 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
24874 +       if (sock->sk) {
24875 +               if (len == size)
24876 +                       vx_sock_send(sock->sk, size);
24877 +               else
24878 +                       vx_sock_fail(sock->sk, size);
24879 +       }
24880 +       vxdprintk(VXD_CBIT(net, 7),
24881 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24882 +               sock, sock->sk,
24883 +               (sock->sk)?sock->sk->sk_nx_info:0,
24884 +               (sock->sk)?sock->sk->sk_vx_info:0,
24885 +               (sock->sk)?sock->sk->sk_xid:0,
24886 +               (sock->sk)?sock->sk->sk_nid:0,
24887 +               (unsigned int)size, len);
24888 +       return len;
24889  }
24890  
24891  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24892 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24893                                        struct msghdr *msg, size_t size, int flags)
24894  {
24895         struct sock_iocb *si = kiocb_to_siocb(iocb);
24896 +       int len;
24897  
24898         si->sock = sock;
24899         si->scm = NULL;
24900 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24901         si->size = size;
24902         si->flags = flags;
24903  
24904 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24905 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24906 +       if ((len >= 0) && sock->sk)
24907 +               vx_sock_recv(sock->sk, len);
24908 +       vxdprintk(VXD_CBIT(net, 7),
24909 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24910 +               sock, sock->sk,
24911 +               (sock->sk)?sock->sk->sk_nx_info:0,
24912 +               (sock->sk)?sock->sk->sk_vx_info:0,
24913 +               (sock->sk)?sock->sk->sk_xid:0,
24914 +               (sock->sk)?sock->sk->sk_nid:0,
24915 +               (unsigned int)size, len);
24916 +       return len;
24917  }
24918  
24919  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24920 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24921         if (type < 0 || type >= SOCK_MAX)
24922                 return -EINVAL;
24923  
24924 +       if (!nx_check(0, VS_ADMIN)) {
24925 +               if (family == PF_INET && !current_nx_info_has_v4())
24926 +                       return -EAFNOSUPPORT;
24927 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24928 +                       return -EAFNOSUPPORT;
24929 +       }
24930 +
24931         /* Compatibility.
24932  
24933            This uglymoron is moved from INET layer to here to avoid
24934 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24935         if (retval < 0)
24936                 goto out;
24937  
24938 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24939         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24940         if (retval < 0)
24941                 goto out_release;
24942 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24943         err = sock_create(family, type, protocol, &sock1);
24944         if (err < 0)
24945                 goto out;
24946 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24947  
24948         err = sock_create(family, type, protocol, &sock2);
24949         if (err < 0)
24950                 goto out_release_1;
24951 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
24952  
24953         err = sock1->ops->socketpair(sock1, sock2);
24954         if (err < 0)
24955 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c
24956 --- linux-3.13.10/net/sunrpc/auth.c     2013-11-25 15:47:08.000000000 +0000
24957 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c  2014-01-31 20:38:04.000000000 +0000
24958 @@ -15,6 +15,7 @@
24959  #include <linux/sunrpc/clnt.h>
24960  #include <linux/sunrpc/gss_api.h>
24961  #include <linux/spinlock.h>
24962 +#include <linux/vs_tag.h>
24963  
24964  #ifdef RPC_DEBUG
24965  # define RPCDBG_FACILITY       RPCDBG_AUTH
24966 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24967         memset(&acred, 0, sizeof(acred));
24968         acred.uid = cred->fsuid;
24969         acred.gid = cred->fsgid;
24970 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24971         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
24972  
24973         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24974 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24975         struct auth_cred acred = {
24976                 .uid = GLOBAL_ROOT_UID,
24977                 .gid = GLOBAL_ROOT_GID,
24978 +               .tag = KTAGT_INIT(dx_current_tag()),
24979         };
24980  
24981         dprintk("RPC: %5u looking up %s cred\n",
24982 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
24983 --- linux-3.13.10/net/sunrpc/auth_unix.c        2013-11-25 15:47:08.000000000 +0000
24984 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c     2014-01-31 20:38:04.000000000 +0000
24985 @@ -13,11 +13,13 @@
24986  #include <linux/sunrpc/clnt.h>
24987  #include <linux/sunrpc/auth.h>
24988  #include <linux/user_namespace.h>
24989 +#include <linux/vs_tag.h>
24990  
24991  #define NFS_NGROUPS    16
24992  
24993  struct unx_cred {
24994         struct rpc_cred         uc_base;
24995 +       ktag_t                  uc_tag;
24996         kgid_t                  uc_gid;
24997         kgid_t                  uc_gids[NFS_NGROUPS];
24998  };
24999 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25000                 groups = NFS_NGROUPS;
25001  
25002         cred->uc_gid = acred->gid;
25003 +       cred->uc_tag = acred->tag;
25004         for (i = 0; i < groups; i++)
25005                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25006         if (i < NFS_NGROUPS)
25007 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25008         unsigned int i;
25009  
25010  
25011 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25012 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25013 +           !gid_eq(cred->uc_gid, acred->gid) ||
25014 +           !tag_eq(cred->uc_tag, acred->tag))
25015                 return 0;
25016  
25017         if (acred->group_info != NULL)
25018 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25019         struct rpc_clnt *clnt = task->tk_client;
25020         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25021         __be32          *base, *hold;
25022 -       int             i;
25023 +       int             i, tag;
25024  
25025         *p++ = htonl(RPC_AUTH_UNIX);
25026         base = p++;
25027 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25028          */
25029         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25030  
25031 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25032 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25033 +       tag = task->tk_client->cl_tag;
25034 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25035 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25036 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25037 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25038         hold = p++;
25039         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25040                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25041 diff -NurpP --minimal linux-3.13.10/net/sunrpc/clnt.c linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c
25042 --- linux-3.13.10/net/sunrpc/clnt.c     2014-04-17 01:12:42.000000000 +0000
25043 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c  2014-02-25 11:26:10.000000000 +0000
25044 @@ -31,6 +31,7 @@
25045  #include <linux/in.h>
25046  #include <linux/in6.h>
25047  #include <linux/un.h>
25048 +#include <linux/vs_cvirt.h>
25049  
25050  #include <linux/sunrpc/clnt.h>
25051  #include <linux/sunrpc/addr.h>
25052 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25053         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25054                 clnt->cl_chatty = 1;
25055  
25056 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25057 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25058 +               clnt->cl_tag = 1; */
25059         return clnt;
25060  }
25061  EXPORT_SYMBOL_GPL(rpc_create);
25062 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
25063 --- linux-3.13.10/net/unix/af_unix.c    2014-04-17 01:12:42.000000000 +0000
25064 +++ linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c 2014-04-17 01:17:11.000000000 +0000
25065 @@ -115,6 +115,8 @@
25066  #include <net/checksum.h>
25067  #include <linux/security.h>
25068  #include <linux/freezer.h>
25069 +#include <linux/vs_context.h>
25070 +#include <linux/vs_limit.h>
25071  
25072  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25073  EXPORT_SYMBOL_GPL(unix_socket_table);
25074 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25075                 if (!net_eq(sock_net(s), net))
25076                         continue;
25077  
25078 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25079 +                       continue;
25080                 if (u->addr->len == len &&
25081                     !memcmp(u->addr->name, sunname, len))
25082                         goto found;
25083 @@ -2275,6 +2279,8 @@ static struct sock *unix_from_bucket(str
25084         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25085                 if (sock_net(sk) != seq_file_net(seq))
25086                         continue;
25087 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25088 +                       continue;
25089                 if (++count == offset)
25090                         break;
25091         }
25092 @@ -2292,6 +2298,8 @@ static struct sock *unix_next_socket(str
25093                 sk = sk_next(sk);
25094                 if (!sk)
25095                         goto next_bucket;
25096 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25097 +                       continue;
25098                 if (sock_net(sk) == seq_file_net(seq))
25099                         return sk;
25100         }
25101 diff -NurpP --minimal linux-3.13.10/scripts/checksyscalls.sh linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh
25102 --- linux-3.13.10/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25103 +++ linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh   2014-01-31 20:38:04.000000000 +0000
25104 @@ -193,7 +193,6 @@ cat << EOF
25105  #define __IGNORE_afs_syscall
25106  #define __IGNORE_getpmsg
25107  #define __IGNORE_putpmsg
25108 -#define __IGNORE_vserver
25109  EOF
25110  }
25111  
25112 diff -NurpP --minimal linux-3.13.10/security/commoncap.c linux-3.13.10-vs2.3.6.11/security/commoncap.c
25113 --- linux-3.13.10/security/commoncap.c  2013-11-25 15:47:08.000000000 +0000
25114 +++ linux-3.13.10-vs2.3.6.11/security/commoncap.c       2014-01-31 20:38:04.000000000 +0000
25115 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25116  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25117                 int cap, int audit)
25118  {
25119 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25120         struct user_namespace *ns = targ_ns;
25121  
25122         /* See if cred has the capability in the target user namespace
25123 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25124          */
25125         for (;;) {
25126                 /* Do we have the necessary capabilities? */
25127 -               if (ns == cred->user_ns)
25128 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25129 +               if (ns == cred->user_ns) {
25130 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25131 +                           cap_raised(cred->cap_effective, cap))
25132 +                               return 0;
25133 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25134 +               }
25135  
25136                 /* Have we tried all of the parent namespaces? */
25137                 if (ns == &init_user_ns)
25138 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25139  
25140         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25141                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25142 -           !capable(CAP_SYS_ADMIN))
25143 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25144                 return -EPERM;
25145         return 0;
25146  }
25147 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25148  
25149         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25150                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25151 -           !capable(CAP_SYS_ADMIN))
25152 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25153                 return -EPERM;
25154         return 0;
25155  }
25156 diff -NurpP --minimal linux-3.13.10/security/selinux/hooks.c linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c
25157 --- linux-3.13.10/security/selinux/hooks.c      2014-04-17 01:12:42.000000000 +0000
25158 +++ linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c   2014-04-17 01:17:11.000000000 +0000
25159 @@ -68,7 +68,6 @@
25160  #include <linux/dccp.h>
25161  #include <linux/quota.h>
25162  #include <linux/un.h>          /* for Unix socket types */
25163 -#include <net/af_unix.h>       /* for Unix socket types */
25164  #include <linux/parser.h>
25165  #include <linux/nfs_mount.h>
25166  #include <net/ipv6.h>
This page took 2.565979 seconds and 2 git commands to generate.